diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index 60606932b..fe1d14d90 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -5,6 +5,7 @@ promesa.exec.csp/go-loop clojure.core/loop rumext.v2/defc clojure.core/defn promesa.util/with-open clojure.core/with-open + app.common.schema.generators/let clojure.core/let app.common.data/export clojure.core/def app.common.data.macros/get-in clojure.core/get-in app.common.data.macros/with-open clojure.core/with-open diff --git a/common/src/app/common/files/defaults.cljc b/common/src/app/common/files/defaults.cljc index 327414f4e..bb448f997 100644 --- a/common/src/app/common/files/defaults.cljc +++ b/common/src/app/common/files/defaults.cljc @@ -6,4 +6,4 @@ (ns app.common.files.defaults) -(def version 41) +(def version 42) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 499ec2008..982d5b10d 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -577,21 +577,6 @@ (update :pages-index update-vals update-container) (update :components update-vals update-container)))) -(defmethod migrate 30 - [data] - (letfn [(update-object [object] - (if (and (cfh/frame-shape? object) - (not (:shapes object))) - (assoc object :shapes []) - object)) - - (update-container [container] - (d/update-when container :objects update-vals update-object))] - - (-> data - (update :pages-index update-vals update-container) - (update :components update-vals update-container)))) - (defmethod migrate 31 [data] (letfn [(update-object [object] @@ -778,3 +763,22 @@ (-> data (update :pages-index update-vals update-container) (update :components update-vals update-container)))) + +(defmethod migrate 42 + [data] + (letfn [(update-object [object] + (if (and (or (cfh/frame-shape? object) + (cfh/group-shape? object) + (cfh/bool-shape? object)) + (not (:shapes object))) + (assoc object :shapes []) + object)) + + (update-container [container] + (d/update-when container :objects update-vals update-object))] + + (-> data + (update :pages-index update-vals update-container) + (update :components update-vals update-container)))) + + diff --git a/common/src/app/common/schema/generators.cljc b/common/src/app/common/schema/generators.cljc index f1aa8c90f..83e00bfd8 100644 --- a/common/src/app/common/schema/generators.cljc +++ b/common/src/app/common/schema/generators.cljc @@ -5,7 +5,7 @@ ;; Copyright (c) KALEIDOS INC (ns app.common.schema.generators - (:refer-clojure :exclude [set subseq uuid for filter map]) + (:refer-clojure :exclude [set subseq uuid for filter map let]) #?(:cljs (:require-macros [app.common.schema.generators])) (:require [app.common.schema.registry :as sr] @@ -37,6 +37,10 @@ [& params] `(tp/for-all ~@params)) +(defmacro let + [& params] + `(tg/let ~@params)) + (defn check! [p & {:keys [num] :or {num 20} :as options}] (tc/quick-check num p (assoc options :reporter-fn default-reporter-fn :max-size 50))) @@ -124,6 +128,10 @@ [f g] (tg/fmap f g)) +(defn mcat + [f g] + (tg/bind g f)) + (defn tuple [& opts] (apply tg/tuple opts)) diff --git a/common/src/app/common/types/shape.cljc b/common/src/app/common/types/shape.cljc index 2397d5845..4f347e9ff 100644 --- a/common/src/app/common/types/shape.cljc +++ b/common/src/app/common/types/shape.cljc @@ -46,6 +46,7 @@ :bool :rect :path + :text :circle :svg-raw :image}) @@ -199,7 +200,7 @@ (sm/define! ::group-attrs [:map {:title "GroupAttrs"} [:type [:= :group]] - [:shapes {:optional true} [:maybe [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]]]) + [:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]]) (sm/define! ::frame-attrs [:map {:title "FrameAttrs"} @@ -212,7 +213,7 @@ (sm/define! ::bool-attrs [:map {:title "BoolAttrs"} [:type [:= :bool]] - [:shapes {:optional true} [:maybe [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]] + [:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]] ;; FIXME: improve this schema [:bool-type :keyword] @@ -271,63 +272,63 @@ (sm/define! ::shape-map [:multi {:dispatch :type :title "Shape"} [:group - [:merge {:title "GroupShape"} + [:and {:title "GroupShape"} ::shape-attrs ::minimal-shape-attrs ::group-attrs ::ctsl/layout-child-attrs]] [:frame - [:merge {:title "FrameShape"} + [:and {:title "FrameShape"} ::minimal-shape-attrs ::frame-attrs ::ctsl/layout-attrs ::ctsl/layout-child-attrs]] [:bool - [:merge {:title "BoolShape"} + [:and {:title "BoolShape"} ::shape-attrs ::minimal-shape-attrs ::bool-attrs ::ctsl/layout-child-attrs]] [:rect - [:merge {:title "RectShape"} + [:and {:title "RectShape"} ::shape-attrs ::minimal-shape-attrs ::rect-attrs ::ctsl/layout-child-attrs]] [:circle - [:merge {:title "CircleShape"} + [:and {:title "CircleShape"} ::shape-attrs ::minimal-shape-attrs ::circle-attrs ::ctsl/layout-child-attrs]] [:image - [:merge {:title "ImageShape"} + [:and {:title "ImageShape"} ::shape-attrs ::minimal-shape-attrs ::image-attrs ::ctsl/layout-child-attrs]] [:svg-raw - [:merge {:title "SvgRawShape"} + [:and {:title "SvgRawShape"} ::shape-attrs ::minimal-shape-attrs ::svg-raw-attrs ::ctsl/layout-child-attrs]] [:path - [:merge {:title "PathShape"} + [:and {:title "PathShape"} ::shape-attrs ::minimal-shape-attrs ::path-attrs ::ctsl/layout-child-attrs]] [:text - [:merge {:title "TextShape"} + [:and {:title "TextShape"} ::shape-attrs ::minimal-shape-attrs ::text-attrs @@ -336,7 +337,20 @@ (sm/define! ::shape [:and {:title "Shape" - :gen/gen (->> (sg/generator ::shape-map) + :gen/gen (->> (sg/generator ::minimal-shape-attrs) + (sg/mcat (fn [{:keys [type] :as shape}] + (sg/let [attrs1 (sg/generator ::shape-attrs) + attrs2 (case type + :text (sg/generator ::text-attrs) + :path (sg/generator ::path-attrs) + :svg-raw (sg/generator ::svg-raw-attrs) + :image (sg/generator ::image-attrs) + :circle (sg/generator ::circle-attrs) + :rect (sg/generator ::rect-attrs) + :bool (sg/generator ::bool-attrs) + :group (sg/generator ::group-attrs) + :frame (sg/generator ::frame-attrs))] + (merge attrs1 shape attrs2)))) (sg/fmap map->Shape))} ::shape-map [:fn shape?]])