diff --git a/common/src/app/common/schema.cljc b/common/src/app/common/schema.cljc index cb84052d0..23d32e3e7 100644 --- a/common/src/app/common/schema.cljc +++ b/common/src/app/common/schema.cljc @@ -392,17 +392,20 @@ (defn- parse-uuid [s] - (if (str/empty? s) - nil - (try - (uuid/parse s) - (catch #?(:clj Exception :cljs :default) _cause - s)))) + (if (uuid? s) + s + (if (str/empty? s) + nil + (try + (uuid/parse s) + (catch #?(:clj Exception :cljs :default) _cause + s))))) (defn- encode-uuid [v] - (when (uuid? v) - (str v))) + (if (uuid? v) + (str v) + v)) (register! {:type ::uuid diff --git a/common/src/app/common/types/shape/interactions.cljc b/common/src/app/common/types/shape/interactions.cljc index 111bba5cb..2547f5528 100644 --- a/common/src/app/common/types/shape/interactions.cljc +++ b/common/src/app/common/types/shape/interactions.cljc @@ -109,13 +109,27 @@ (def check-animation! (sm/check-fn schema:animation)) +(def schema:interaction-attrs + [:map {:title "InteractionAttrs"} + [:action-type {:optional true} [::sm/one-of action-types]] + [:event-type {:optional true} [::sm/one-of event-types]] + [:destination {:optional true} [:maybe ::sm/uuid]] + [:preserve-scroll {:optional true} :boolean] + [:animation {:optional true} schema:animation] + [:overlay-position {:optional true} ::gpt/point] + [:overlay-pos-type {:optional true} [::sm/one-of overlay-positioning-types]] + [:close-click-outside {:optional true} :boolean] + [:background-overlay {:optional true} :boolean] + [:position-relative-to {:optional true} [:maybe ::sm/uuid]] + [:url {:optional true} :string]]) + (def schema:navigate-interaction [:map [:action-type [:= :navigate]] [:event-type [::sm/one-of event-types]] [:destination {:optional true} [:maybe ::sm/uuid]] [:preserve-scroll {:optional true} :boolean] - [:animation {:optional true} ::animation]]) + [:animation {:optional true} schema:animation]]) (def schema:open-overlay-interaction [:map @@ -126,7 +140,7 @@ [:destination {:optional true} [:maybe ::sm/uuid]] [:close-click-outside {:optional true} :boolean] [:background-overlay {:optional true} :boolean] - [:animation {:optional true} ::animation] + [:animation {:optional true} schema:animation] [:position-relative-to {:optional true} [:maybe ::sm/uuid]]]) (def schema:toggle-overlay-interaction @@ -138,7 +152,7 @@ [:destination {:optional true} [:maybe ::sm/uuid]] [:close-click-outside {:optional true} :boolean] [:background-overlay {:optional true} :boolean] - [:animation {:optional true} ::animation] + [:animation {:optional true} schema:animation] [:position-relative-to {:optional true} [:maybe ::sm/uuid]]]) (def schema:close-overlay-interaction @@ -146,7 +160,7 @@ [:action-type [:= :close-overlay]] [:event-type [::sm/one-of event-types]] [:destination {:optional true} [:maybe ::sm/uuid]] - [:animation {:optional true} ::animation] + [:animation {:optional true} schema:animation] [:position-relative-to {:optional true} [:maybe ::sm/uuid]]]) (def schema:prev-scren-interaction @@ -161,21 +175,21 @@ [:url :string]]) (def schema:interaction - [:multi {:dispatch :action-type - :title "Interaction" - :gen/gen (sg/one-of (sg/generator schema:navigate-interaction) - (sg/generator schema:open-overlay-interaction) - (sg/generator schema:close-overlay-interaction) - (sg/generator schema:toggle-overlay-interaction) - (sg/generator schema:prev-scren-interaction) - (sg/generator schema:open-url-interaction)) - :decode/json #(update % :action-type keyword)} - [:navigate schema:navigate-interaction] - [:open-overlay schema:open-overlay-interaction] - [:toggle-overlay schema:toggle-overlay-interaction] - [:close-overlay schema:close-overlay-interaction] - [:prev-screen schema:prev-scren-interaction] - [:open-url schema:open-url-interaction]]) + [:and {:title "Interaction" + :gen/gen (sg/one-of (sg/generator schema:navigate-interaction) + (sg/generator schema:open-overlay-interaction) + (sg/generator schema:close-overlay-interaction) + (sg/generator schema:toggle-overlay-interaction) + (sg/generator schema:prev-scren-interaction) + (sg/generator schema:open-url-interaction))} + schema:interaction-attrs + [:multi {:dispatch :action-type} + [:navigate schema:navigate-interaction] + [:open-overlay schema:open-overlay-interaction] + [:toggle-overlay schema:toggle-overlay-interaction] + [:close-overlay schema:close-overlay-interaction] + [:prev-screen schema:prev-scren-interaction] + [:open-url schema:open-url-interaction]]]) (sm/register! ::interaction schema:interaction)