From 66ee9edaf840fd9575b741ff7b677280009e6bef Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 7 May 2025 11:32:46 +0200 Subject: [PATCH] :sparkles: Add minor enhacements and naming fixes on schemas --- common/src/app/common/geom/matrix.cljc | 29 ++- common/src/app/common/geom/point.cljc | 32 ++- common/src/app/common/types/color.cljc | 43 ++-- common/src/app/common/types/component.cljc | 26 +- common/src/app/common/types/container.cljc | 18 +- common/src/app/common/types/file.cljc | 11 +- common/src/app/common/types/page.cljc | 11 +- common/src/app/common/types/plugins.cljc | 13 +- common/src/app/common/types/shape.cljc | 233 +++++++++--------- common/src/app/common/types/shape/layout.cljc | 37 ++- common/src/app/common/types/shape_tree.cljc | 2 + common/src/app/common/types/typography.cljc | 36 +-- common/src/app/common/types/variant.cljc | 9 +- frontend/src/app/main/data/workspace.cljs | 19 +- .../app/main/data/workspace/libraries.cljs | 51 ++-- .../src/app/main/data/workspace/shapes.cljs | 46 ++-- .../data/workspace/tokens/library_edit.cljs | 14 +- frontend/src/app/main/fonts.cljs | 6 +- 18 files changed, 312 insertions(+), 324 deletions(-) diff --git a/common/src/app/common/geom/matrix.cljc b/common/src/app/common/geom/matrix.cljc index d6e545cd90..7fcabd192b 100644 --- a/common/src/app/common/geom/matrix.cljc +++ b/common/src/app/common/geom/matrix.cljc @@ -126,21 +126,20 @@ o))) (def schema:matrix - {:type :map - :pred valid-matrix? - :type-properties - {:title "matrix" - :description "Matrix instance" - :error/message "expected a valid matrix instance" - :gen/gen (matrix-generator) - :decode/json decode-matrix - :decode/string decode-matrix - :encode/json matrix->json - :encode/string matrix->str - ::oapi/type "string" - ::oapi/format "matrix"}}) - -(sm/register! ::matrix schema:matrix) + (sm/register! + {:type ::matrix + :pred valid-matrix? + :type-properties + {:title "matrix" + :description "Matrix instance" + :error/message "expected a valid matrix instance" + :gen/gen (matrix-generator) + :decode/json decode-matrix + :decode/string decode-matrix + :encode/json matrix->json + :encode/string matrix->str + ::oapi/type "string" + ::oapi/format "matrix"}})) ;; FIXME: deprecated (s/def ::a ::us/safe-float) diff --git a/common/src/app/common/geom/point.cljc b/common/src/app/common/geom/point.cljc index a7cf2d412c..eb9b3b90ac 100644 --- a/common/src/app/common/geom/point.cljc +++ b/common/src/app/common/geom/point.cljc @@ -85,24 +85,22 @@ (into {} p) p)) -;; FIXME: make like matrix (def schema:point - {:type ::point - :pred valid-point? - :type-properties - {:title "point" - :description "Point" - :error/message "expected a valid point" - :gen/gen (->> (sg/tuple (sg/small-int) (sg/small-int)) - (sg/fmap #(apply pos->Point %))) - ::oapi/type "string" - ::oapi/format "point" - :decode/json decode-point - :decode/string decode-point - :encode/json point->json - :encode/string point->str}}) - -(sm/register! schema:point) + (sm/register! + {:type ::point + :pred valid-point? + :type-properties + {:title "point" + :description "Point" + :error/message "expected a valid point" + :gen/gen (->> (sg/tuple (sg/small-int) (sg/small-int)) + (sg/fmap #(apply pos->Point %))) + ::oapi/type "string" + ::oapi/format "point" + :decode/json decode-point + :decode/string decode-point + :encode/json point->json + :encode/string point->str}})) (defn point-like? [{:keys [x y] :as v}] diff --git a/common/src/app/common/types/color.cljc b/common/src/app/common/types/color.cljc index f93f756174..eb2018fad7 100644 --- a/common/src/app/common/types/color.cljc +++ b/common/src/app/common/types/color.cljc @@ -41,17 +41,18 @@ [o] (and (string? o) (some? (re-matches rgb-color-re o)))) -(def ^:private type:rgb-color - {:type :string - :pred rgb-color-string? - :type-properties - {:title "rgb-color" - :description "RGB Color String" - :error/message "expected a valid RGB color" - :error/code "errors.invalid-rgb-color" - :gen/gen (generate-rgb-color) - ::oapi/type "integer" - ::oapi/format "int64"}}) +(def schema:rgb-color + (sm/register! + {:type ::rgb-color + :pred rgb-color-string? + :type-properties + {:title "rgb-color" + :description "RGB Color String" + :error/message "expected a valid RGB color" + :error/code "errors.invalid-rgb-color" + :gen/gen (generate-rgb-color) + ::oapi/type "integer" + ::oapi/format "int64"}})) (def schema:image-color [:map {:title "ImageColor"} @@ -76,7 +77,7 @@ [:stops [:vector {:min 1 :gen/max 2} [:map {:title "GradientStop"} - [:color ::rgb-color] + [:color schema:rgb-color] [:opacity {:optional true} [:maybe ::sm/safe-number]] [:offset ::sm/safe-number]]]]]) @@ -86,7 +87,7 @@ [:name {:optional true} :string] [:path {:optional true} [:maybe :string]] [:value {:optional true} [:maybe :string]] - [:color {:optional true} [:maybe ::rgb-color]] + [:color {:optional true} [:maybe schema:rgb-color]] [:opacity {:optional true} [:maybe ::sm/safe-number]] [:modified-at {:optional true} ::sm/inst] [:ref-id {:optional true} ::sm/uuid] @@ -103,12 +104,17 @@ [:and [:map {:title "RecentColor"} [:opacity {:optional true} [:maybe ::sm/safe-number]] - [:color {:optional true} [:maybe ::rgb-color]] + [:color {:optional true} [:maybe schema:rgb-color]] [:gradient {:optional true} [:maybe schema:gradient]] [:image {:optional true} [:maybe schema:image-color]]] [::sm/contains-any {:strict true} [:color :gradient :image]]]) -(sm/register! ::rgb-color type:rgb-color) +;; Same as color but with :id prop required +(def schema:library-color + [:and + (sm/required-keys schema:color-attrs [:id]) + [::sm/contains-any {:strict true} [:color :gradient :image]]]) + (sm/register! ::color schema:color) (sm/register! ::gradient schema:gradient) (sm/register! ::image-color schema:image-color) @@ -119,10 +125,13 @@ (sm/lazy-validator schema:color)) (def check-color - (sm/check-fn schema:color :hint "expected valid color struct")) + (sm/check-fn schema:color :hint "expected valid color")) + +(def check-library-color + (sm/check-fn schema:library-color :hint "expected valid library color")) (def check-recent-color - (sm/check-fn schema:recent-color)) + (sm/check-fn schema:recent-color :hint "expected valid recent color")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; HELPERS diff --git a/common/src/app/common/types/component.cljc b/common/src/app/common/types/component.cljc index 93fabc973f..2ffbc70d25 100644 --- a/common/src/app/common/types/component.cljc +++ b/common/src/app/common/types/component.cljc @@ -18,19 +18,19 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (def schema:component - [:merge - [:map - [:id ::sm/uuid] - [:name :string] - [:path {:optional true} [:maybe :string]] - [:modified-at {:optional true} ::sm/inst] - [:objects {:gen/max 10 :optional true} ::ctp/objects] - [:main-instance-id ::sm/uuid] - [:main-instance-page ::sm/uuid] - [:plugin-data {:optional true} ::ctpg/plugin-data]] - ::ctv/variant-component]) - -(sm/register! ::component schema:component) + (sm/register! + ^{::sm/type ::component} + [:merge + [:map + [:id ::sm/uuid] + [:name :string] + [:path {:optional true} [:maybe :string]] + [:modified-at {:optional true} ::sm/inst] + [:objects {:gen/max 10 :optional true} ctp/schema:objects] + [:main-instance-id ::sm/uuid] + [:main-instance-page ::sm/uuid] + [:plugin-data {:optional true} ctpg/schema:plugin-data]] + ctv/schema:variant-component])) (def check-component (sm/check-fn schema:component)) diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index bfb6d09e2e..f087088a66 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -41,7 +41,7 @@ [:map-of {:gen/max 10} ::sm/uuid :map]] [:plugin-data {:optional true} ::ctpg/plugin-data]]) -(def check-container! +(def check-container (sm/check-fn ::container)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -62,9 +62,9 @@ (defn get-container [file type id] - (dm/assert! (map? file)) - (dm/assert! (contains? valid-container-types type)) - (dm/assert! (uuid? id)) + (assert (map? file)) + (assert (contains? valid-container-types type)) + (assert (uuid? id)) (-> (if (= type :page) (ctpl/get-page file id) @@ -74,13 +74,9 @@ (defn get-shape [container shape-id] - (dm/assert! - "expected valid container" - (check-container! container)) - - (dm/assert! - "expected valid uuid for `shape-id`" - (uuid? shape-id)) + (assert (check-container container)) + (assert (uuid? shape-id) + "expected valid uuid for `shape-id`") (-> container (get :objects) diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index 55725bb69f..93e41924d6 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -83,6 +83,7 @@ because sometimes we want to validate file without the data." [:map {:title "file"} [:id ::sm/uuid] + [:name :string] [:revn {:optional true} :int] [:vern {:optional true} :int] [:created-at {:optional true} ::sm/inst] @@ -101,13 +102,15 @@ (sm/register! ::media schema:media) (sm/register! ::colors schema:colors) (sm/register! ::typographies schema:typographies) - (sm/register! ::media-object schema:media) -(def check-file-data! - (sm/check-fn ::data)) +(def check-file + (sm/check-fn schema:file :hint "check error on validating file")) -(def check-media-object! +(def check-file-data + (sm/check-fn schema:data)) + +(def check-media-object (sm/check-fn schema:media)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/common/src/app/common/types/page.cljc b/common/src/app/common/types/page.cljc index cb0d0e9e0b..85bb02bb0f 100644 --- a/common/src/app/common/types/page.cljc +++ b/common/src/app/common/types/page.cljc @@ -70,7 +70,7 @@ (def valid-guide? (sm/lazy-validator schema:guide)) -(def check-page! +(def check-page (sm/check-fn schema:page)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -82,8 +82,7 @@ (def root uuid/zero) (def empty-page-data - {:options {} - :objects {root + {:objects {root (cts/setup-shape {:id root :type :frame :parent-id root @@ -91,10 +90,12 @@ :name "Root Frame"})}}) (defn make-empty-page - [{:keys [id name]}] + [{:keys [id name background]}] (-> empty-page-data (assoc :id (or id (uuid/next))) - (assoc :name (or name "Page 1")))) + (assoc :name (d/nilv name "Page 1")) + (cond-> background + (assoc :background background)))) (defn get-frame-flow [flows frame-id] diff --git a/common/src/app/common/types/plugins.cljc b/common/src/app/common/types/plugins.cljc index 128c90f7d7..c4402591a9 100644 --- a/common/src/app/common/types/plugins.cljc +++ b/common/src/app/common/types/plugins.cljc @@ -22,14 +22,13 @@ :keyword]) (def schema:plugin-data - [:map-of {:gen/max 5} - schema:keyword + (sm/register! + ^{::sm/type ::plugin-data} [:map-of {:gen/max 5} - schema:string - schema:string]]) - -(sm/register! ::plugin-data schema:plugin-data) - + schema:keyword + [:map-of {:gen/max 5} + schema:string + schema:string]])) (def ^:private schema:registry-entry [:map diff --git a/common/src/app/common/types/shape.cljc b/common/src/app/common/types/shape.cljc index c367d22ef1..63caf358f2 100644 --- a/common/src/app/common/types/shape.cljc +++ b/common/src/app/common/types/shape.cljc @@ -120,35 +120,35 @@ [:vector {:gen/max 4 :gen/min 4} ::gpt/point]) (def schema:fill - [:map {:title "Fill"} - [:fill-color {:optional true} ::ctc/rgb-color] - [:fill-opacity {:optional true} ::sm/safe-number] - [:fill-color-gradient {:optional true} [:maybe ::ctc/gradient]] - [:fill-color-ref-file {:optional true} [:maybe ::sm/uuid]] - [:fill-color-ref-id {:optional true} [:maybe ::sm/uuid]] - [:fill-image {:optional true} ::ctc/image-color]]) + (sm/register! + ^{::sm/type ::fill} + [:map {:title "Fill"} + [:fill-color {:optional true} ::ctc/rgb-color] + [:fill-opacity {:optional true} ::sm/safe-number] + [:fill-color-gradient {:optional true} [:maybe ::ctc/gradient]] + [:fill-color-ref-file {:optional true} [:maybe ::sm/uuid]] + [:fill-color-ref-id {:optional true} [:maybe ::sm/uuid]] + [:fill-image {:optional true} ::ctc/image-color]])) -(sm/register! ::fill schema:fill) - -(def ^:private schema:stroke - [:map {:title "Stroke"} - [:stroke-color {:optional true} :string] - [:stroke-color-ref-file {:optional true} ::sm/uuid] - [:stroke-color-ref-id {:optional true} ::sm/uuid] - [:stroke-opacity {:optional true} ::sm/safe-number] - [:stroke-style {:optional true} - [::sm/one-of #{:solid :dotted :dashed :mixed :none :svg}]] - [:stroke-width {:optional true} ::sm/safe-number] - [:stroke-alignment {:optional true} - [::sm/one-of #{:center :inner :outer}]] - [:stroke-cap-start {:optional true} - [::sm/one-of stroke-caps]] - [:stroke-cap-end {:optional true} - [::sm/one-of stroke-caps]] - [:stroke-color-gradient {:optional true} ::ctc/gradient] - [:stroke-image {:optional true} ::ctc/image-color]]) - -(sm/register! ::stroke schema:stroke) +(def schema:stroke + (sm/register! + ^{::sm/type ::stroke} + [:map {:title "Stroke"} + [:stroke-color {:optional true} :string] + [:stroke-color-ref-file {:optional true} ::sm/uuid] + [:stroke-color-ref-id {:optional true} ::sm/uuid] + [:stroke-opacity {:optional true} ::sm/safe-number] + [:stroke-style {:optional true} + [::sm/one-of #{:solid :dotted :dashed :mixed :none :svg}]] + [:stroke-width {:optional true} ::sm/safe-number] + [:stroke-alignment {:optional true} + [::sm/one-of #{:center :inner :outer}]] + [:stroke-cap-start {:optional true} + [::sm/one-of stroke-caps]] + [:stroke-cap-end {:optional true} + [::sm/one-of stroke-caps]] + [:stroke-color-gradient {:optional true} ::ctc/gradient] + [:stroke-image {:optional true} ::ctc/image-color]])) (def check-stroke (sm/check-fn schema:stroke)) @@ -172,8 +172,7 @@ [:width ::sm/safe-number] [:height ::sm/safe-number]]) -;; FIXME: rename to shape-generic-attrs -(def schema:shape-attrs +(def schema:shape-generic-attrs [:map {:title "ShapeAttrs"} [:page-id {:optional true} ::sm/uuid] [:component-id {:optional true} ::sm/uuid] @@ -277,7 +276,7 @@ [] (->> (sg/generator schema:shape-base-attrs) (sg/mcat (fn [{:keys [type] :as shape}] - (sg/let [attrs1 (sg/generator schema:shape-attrs) + (sg/let [attrs1 (sg/generator schema:shape-generic-attrs) attrs2 (sg/generator schema:shape-geom-attrs) attrs3 (case type :text (sg/generator schema:text-attrs) @@ -295,94 +294,100 @@ (merge attrs1 shape attrs2 attrs3))))) (sg/fmap create-shape))) +(def schema:shape-attrs + [:multi {:dispatch :type + :decode/json (fn [shape] + (update shape :type keyword)) + :title "Shape"} + [:group + [:merge {:title "GroupShape"} + ctsl/schema:layout-attrs + schema:group-attrs + schema:shape-generic-attrs + schema:shape-geom-attrs + schema:shape-base-attrs]] + + [:frame + [:merge {:title "FrameShape"} + ctsl/schema:layout-attrs + ::ctsl/layout-attrs + schema:frame-attrs + schema:shape-generic-attrs + schema:shape-geom-attrs + schema:shape-base-attrs + ::ctv/variant-shape + ::ctv/variant-container]] + + [:bool + [:merge {:title "BoolShape"} + ctsl/schema:layout-attrs + schema:bool-attrs + schema:shape-generic-attrs + schema:shape-base-attrs]] + + [:rect + [:merge {:title "RectShape"} + ctsl/schema:layout-attrs + schema:rect-attrs + schema:shape-generic-attrs + schema:shape-geom-attrs + schema:shape-base-attrs]] + + [:circle + [:merge {:title "CircleShape"} + ctsl/schema:layout-attrs + schema:circle-attrs + schema:shape-generic-attrs + schema:shape-geom-attrs + schema:shape-base-attrs]] + + [:image + [:merge {:title "ImageShape"} + ctsl/schema:layout-attrs + schema:image-attrs + schema:shape-generic-attrs + schema:shape-geom-attrs + schema:shape-base-attrs]] + + [:svg-raw + [:merge {:title "SvgRawShape"} + ctsl/schema:layout-attrs + schema:svg-raw-attrs + schema:shape-generic-attrs + schema:shape-geom-attrs + schema:shape-base-attrs]] + + [:path + [:merge {:title "PathShape"} + ctsl/schema:layout-attrs + schema:path-attrs + schema:shape-generic-attrs + schema:shape-base-attrs]] + + [:text + [:merge {:title "TextShape"} + ctsl/schema:layout-attrs + schema:text-attrs + schema:shape-generic-attrs + schema:shape-geom-attrs + schema:shape-base-attrs]]]) + (def schema:shape - [:and {:title "Shape" - :gen/gen (shape-generator) - :decode/json {:leave decode-shape}} - [:fn shape?] - [:multi {:dispatch :type - :decode/json (fn [shape] - (update shape :type keyword)) - :title "Shape"} - [:group - [:merge {:title "GroupShape"} - ::ctsl/layout-child-attrs - schema:group-attrs - schema:shape-attrs - schema:shape-geom-attrs - schema:shape-base-attrs]] + (sm/register! + ^{::sm/type ::shape} + [:and {:title "Shape" + :gen/gen (shape-generator) + :decode/json {:leave decode-shape}} + [:fn shape?] + schema:shape-attrs])) - [:frame - [:merge {:title "FrameShape"} - ::ctsl/layout-child-attrs - ::ctsl/layout-attrs - schema:frame-attrs - schema:shape-attrs - schema:shape-geom-attrs - schema:shape-base-attrs - ::ctv/variant-shape - ::ctv/variant-container]] +(def check-shape-generic-attrs + (sm/check-fn schema:shape-generic-attrs)) - [:bool - [:merge {:title "BoolShape"} - ::ctsl/layout-child-attrs - schema:bool-attrs - schema:shape-attrs - schema:shape-base-attrs]] - - [:rect - [:merge {:title "RectShape"} - ::ctsl/layout-child-attrs - schema:rect-attrs - schema:shape-attrs - schema:shape-geom-attrs - schema:shape-base-attrs]] - - [:circle - [:merge {:title "CircleShape"} - ::ctsl/layout-child-attrs - schema:circle-attrs - schema:shape-attrs - schema:shape-geom-attrs - schema:shape-base-attrs]] - - [:image - [:merge {:title "ImageShape"} - ::ctsl/layout-child-attrs - schema:image-attrs - schema:shape-attrs - schema:shape-geom-attrs - schema:shape-base-attrs]] - - [:svg-raw - [:merge {:title "SvgRawShape"} - ::ctsl/layout-child-attrs - schema:svg-raw-attrs - schema:shape-attrs - schema:shape-geom-attrs - schema:shape-base-attrs]] - - [:path - [:merge {:title "PathShape"} - ::ctsl/layout-child-attrs - schema:path-attrs - schema:shape-attrs - schema:shape-base-attrs]] - - [:text - [:merge {:title "TextShape"} - ::ctsl/layout-child-attrs - schema:text-attrs - schema:shape-attrs - schema:shape-geom-attrs - schema:shape-base-attrs]]]]) - -(sm/register! ::shape schema:shape) - -(def check-shape-attrs! +(def check-shape-attrs (sm/check-fn schema:shape-attrs)) -(def check-shape! +(def check-shape (sm/check-fn schema:shape :hint "expected valid shape")) diff --git a/common/src/app/common/types/shape/layout.cljc b/common/src/app/common/types/shape/layout.cljc index 6803b2a60c..e66016502f 100644 --- a/common/src/app/common/types/shape/layout.cljc +++ b/common/src/app/common/types/shape/layout.cljc @@ -168,25 +168,24 @@ (def item-align-self-types #{:start :end :center :stretch}) -(sm/register! - ^{::sm/type ::layout-child-attrs} - [:map {:title "LayoutChildAttrs"} - [:layout-item-margin-type {:optional true} [::sm/one-of item-margin-types]] - [:layout-item-margin {:optional true} - [:map - [:m1 {:optional true} ::sm/safe-number] - [:m2 {:optional true} ::sm/safe-number] - [:m3 {:optional true} ::sm/safe-number] - [:m4 {:optional true} ::sm/safe-number]]] - [:layout-item-max-h {:optional true} ::sm/safe-number] - [:layout-item-min-h {:optional true} ::sm/safe-number] - [:layout-item-max-w {:optional true} ::sm/safe-number] - [:layout-item-min-w {:optional true} ::sm/safe-number] - [:layout-item-h-sizing {:optional true} [::sm/one-of item-h-sizing-types]] - [:layout-item-v-sizing {:optional true} [::sm/one-of item-v-sizing-types]] - [:layout-item-align-self {:optional true} [::sm/one-of item-align-self-types]] - [:layout-item-absolute {:optional true} :boolean] - [:layout-item-z-index {:optional true} ::sm/safe-number]]) +(def schema:layout-attrs + [:map {:title "LayoutChildAttrs"} + [:layout-item-margin-type {:optional true} [::sm/one-of item-margin-types]] + [:layout-item-margin {:optional true} + [:map + [:m1 {:optional true} ::sm/safe-number] + [:m2 {:optional true} ::sm/safe-number] + [:m3 {:optional true} ::sm/safe-number] + [:m4 {:optional true} ::sm/safe-number]]] + [:layout-item-max-h {:optional true} ::sm/safe-number] + [:layout-item-min-h {:optional true} ::sm/safe-number] + [:layout-item-max-w {:optional true} ::sm/safe-number] + [:layout-item-min-w {:optional true} ::sm/safe-number] + [:layout-item-h-sizing {:optional true} [::sm/one-of item-h-sizing-types]] + [:layout-item-v-sizing {:optional true} [::sm/one-of item-v-sizing-types]] + [:layout-item-align-self {:optional true} [::sm/one-of item-align-self-types]] + [:layout-item-absolute {:optional true} :boolean] + [:layout-item-z-index {:optional true} ::sm/safe-number]]) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; SCHEMAS diff --git a/common/src/app/common/types/shape_tree.cljc b/common/src/app/common/types/shape_tree.cljc index c7a301ca4c..492699ea34 100644 --- a/common/src/app/common/types/shape_tree.cljc +++ b/common/src/app/common/types/shape_tree.cljc @@ -16,6 +16,8 @@ [app.common.types.shape.layout :as ctl] [app.common.uuid :as uuid])) + +;; FIXME: the order of arguments seems arbitrary, container should be a first artgument (defn add-shape "Insert a shape in the tree, at the given index below the given parent or frame. Update the parent as needed." diff --git a/common/src/app/common/types/typography.cljc b/common/src/app/common/types/typography.cljc index 74f66b4e32..155c958b10 100644 --- a/common/src/app/common/types/typography.cljc +++ b/common/src/app/common/types/typography.cljc @@ -17,25 +17,25 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (def schema:typography - [:map {:title "Typography"} - [:id ::sm/uuid] - [:name :string] - [:font-id :string] - [:font-family :string] - [:font-variant-id :string] - [:font-size :string] - [:font-weight :string] - [:font-style :string] - [:line-height :string] - [:letter-spacing :string] - [:text-transform :string] - [:modified-at {:optional true} ::sm/inst] - [:path {:optional true} [:maybe :string]] - [:plugin-data {:optional true} ::ctpg/plugin-data]]) + (sm/register! + ^{::sm/type ::typography} + [:map {:title "Typography"} + [:id ::sm/uuid] + [:name :string] + [:font-id :string] + [:font-family :string] + [:font-variant-id :string] + [:font-size :string] + [:font-weight :string] + [:font-style :string] + [:line-height :string] + [:letter-spacing :string] + [:text-transform :string] + [:modified-at {:optional true} ::sm/inst] + [:path {:optional true} [:maybe :string]] + [:plugin-data {:optional true} ::ctpg/plugin-data]])) -(sm/register! ::typography schema:typography) - -(def check-typography! +(def check-typography (sm/check-fn ::typography)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/common/src/app/common/types/variant.cljc b/common/src/app/common/types/variant.cljc index 3fe90b92e7..552449eda0 100644 --- a/common/src/app/common/types/variant.cljc +++ b/common/src/app/common/types/variant.cljc @@ -23,9 +23,11 @@ (def schema:variant-component ;; A component that is part of a variant set. - [:map - [:variant-id {:optional true} ::sm/uuid] - [:variant-properties {:optional true} [:vector schema:variant-property]]]) + (sm/register! + ^{::sm/type ::variant-component} + [:map + [:variant-id {:optional true} ::sm/uuid] + [:variant-properties {:optional true} [:vector schema:variant-property]]])) (def schema:variant-shape ;; The root shape of the main instance of a variant component. @@ -40,7 +42,6 @@ [:is-variant-container {:optional true} :boolean]]) (sm/register! ::variant-property schema:variant-property) -(sm/register! ::variant-component schema:variant-component) (sm/register! ::variant-shape schema:variant-shape) (sm/register! ::variant-container schema:variant-container) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index d380e7bbea..9221356ece 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -771,17 +771,16 @@ ;; --- Update Shape Attrs +;; FIXME: revisit this before merge (defn update-shape [id attrs] - (dm/assert! - "expected valid parameters" - (and (cts/check-shape-attrs! attrs) - (uuid? id))) + (assert (uuid? id) "expected valid uuid for `id`") - (ptk/reify ::update-shape - ptk/WatchEvent - (watch [_ _ _] - (rx/of (dwsh/update-shapes [id] #(merge % attrs)))))) + (let [attrs (cts/check-shape-attrs attrs)] + (ptk/reify ::update-shape + ptk/WatchEvent + (watch [_ _ _] + (rx/of (dwsh/update-shapes [id] #(merge % attrs))))))) (defn start-rename-shape "Start shape renaming process" @@ -832,10 +831,6 @@ (defn update-selected-shapes [attrs] - (dm/assert! - "expected valid shape attrs" - (cts/check-shape-attrs! attrs)) - (ptk/reify ::update-selected-shapes ptk/WatchEvent (watch [_ state _] diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 777c63b11f..09c815da08 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -254,20 +254,17 @@ (defn add-media [media] - (dm/assert! - "expected valid media object" - (ctf/check-media-object! media)) + (let [media (ctf/check-media-object media)] + (ptk/reify ::add-media + ev/Event + (-data [_] media) - (ptk/reify ::add-media - ev/Event - (-data [_] media) - - ptk/WatchEvent - (watch [it _ _] - (let [obj (select-keys media [:id :name :width :height :mtype]) - changes (-> (pcb/empty-changes it) - (pcb/add-media obj))] - (rx/of (dch/commit-changes changes)))))) + ptk/WatchEvent + (watch [it _ _] + (let [obj (select-keys media [:id :name :width :height :mtype]) + changes (-> (pcb/empty-changes it) + (pcb/add-media obj))] + (rx/of (dch/commit-changes changes))))))) (defn rename-media [id new-name] @@ -297,10 +294,7 @@ (defn delete-media [{:keys [id]}] - (dm/assert! - "expected valid uuid for `id`" - (uuid? id)) - + (assert (uuid? id) "expected valid uuid for `id`") (ptk/reify ::delete-media ev/Event (-data [_] {:id id}) @@ -316,11 +310,8 @@ (defn add-typography ([typography] (add-typography typography true)) ([typography edit?] - (let [typography (update typography :id #(or % (uuid/next)))] - (dm/assert! - "expected valid typography" - (ctt/check-typography! typography)) - + (let [typography (-> (update typography :id #(or % (uuid/next))) + (ctt/check-typography))] (ptk/reify ::add-typography ev/Event (-data [_] typography) @@ -349,16 +340,12 @@ (defn update-typography [typography file-id] - - (dm/assert! - "expected valid typography and file-id" - (and (ctt/check-typography! typography) - (uuid? file-id))) - - (ptk/reify ::update-typography - ptk/WatchEvent - (watch [it state _] - (do-update-tipography it state typography file-id)))) + (assert (uuid? file-id) "expected valid uuid for `file-id`") + (let [typography (ctt/check-typography typography)] + (ptk/reify ::update-typography + ptk/WatchEvent + (watch [it state _] + (do-update-tipography it state typography file-id))))) (defn rename-typography [file-id id new-name] diff --git a/frontend/src/app/main/data/workspace/shapes.cljs b/frontend/src/app/main/data/workspace/shapes.cljs index d70a0b30bd..27cb972a64 100644 --- a/frontend/src/app/main/data/workspace/shapes.cljs +++ b/frontend/src/app/main/data/workspace/shapes.cljs @@ -110,9 +110,7 @@ (add-shape shape {})) ([shape {:keys [no-select? no-update-layout?]}] - (dm/assert! - "expected valid shape" - (cts/check-shape! shape)) + (cts/check-shape shape) (ptk/reify ::add-shape ptk/WatchEvent @@ -293,30 +291,28 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defn update-shape-flags - [ids {:keys [blocked hidden undo-group] :as flags}] - (dm/assert! - "expected valid coll of uuids" - (every? uuid? ids)) + [ids flags] + (assert (every? uuid? ids) + "expected valid coll of uuids") - (dm/assert! - "expected valid shape-attrs value for `flags`" - (cts/check-shape-attrs! flags)) + (let [{:keys [blocked hidden undo-group]} + (cts/check-shape-generic-attrs flags)] - (ptk/reify ::update-shape-flags - ptk/WatchEvent - (watch [_ state _] - (let [update-fn - (fn [obj] - (cond-> obj - (boolean? blocked) (assoc :blocked blocked) - (boolean? hidden) (assoc :hidden hidden))) - objects (dsh/lookup-page-objects state) - ;; We have change only the hidden behaviour, to hide only the - ;; selected shape, block behaviour remains the same. - ids (if (boolean? blocked) - (into ids (->> ids (mapcat #(cfh/get-children-ids objects %)))) - ids)] - (rx/of (update-shapes ids update-fn {:attrs #{:blocked :hidden} :undo-group undo-group})))))) + (ptk/reify ::update-shape-flags + ptk/WatchEvent + (watch [_ state _] + (let [update-fn + (fn [obj] + (cond-> obj + (boolean? blocked) (assoc :blocked blocked) + (boolean? hidden) (assoc :hidden hidden))) + objects (dsh/lookup-page-objects state) + ;; We have change only the hidden behaviour, to hide only the + ;; selected shape, block behaviour remains the same. + ids (if (boolean? blocked) + (into ids (->> ids (mapcat #(cfh/get-children-ids objects %)))) + ids)] + (rx/of (update-shapes ids update-fn {:attrs #{:blocked :hidden} :undo-group undo-group}))))))) (defn toggle-visibility-selected [] diff --git a/frontend/src/app/main/data/workspace/tokens/library_edit.cljs b/frontend/src/app/main/data/workspace/tokens/library_edit.cljs index cc3a345cf3..67c410431b 100644 --- a/frontend/src/app/main/data/workspace/tokens/library_edit.cljs +++ b/frontend/src/app/main/data/workspace/tokens/library_edit.cljs @@ -51,15 +51,13 @@ ;; TODO HYMA: Copied over from workspace.cljs (defn update-shape [id attrs] - (dm/assert! - "expected valid parameters" - (and (cts/check-shape-attrs! attrs) - (uuid? id))) + (assert (uuid? id) "expected valid uuid for `id`") - (ptk/reify ::update-shape - ptk/WatchEvent - (watch [_ _ _] - (rx/of (dwsh/update-shapes [id] #(merge % attrs)))))) + (let [attrs (cts/check-shape-attrs attrs)] + (ptk/reify ::update-shape + ptk/WatchEvent + (watch [_ _ _] + (rx/of (dwsh/update-shapes [id] #(merge % attrs))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; TOKENS Actions diff --git a/frontend/src/app/main/fonts.cljs b/frontend/src/app/main/fonts.cljs index 4ee3c80b39..13c7f0cc19 100644 --- a/frontend/src/app/main/fonts.cljs +++ b/frontend/src/app/main/fonts.cljs @@ -214,15 +214,15 @@ (nil? font) (p/resolved font-id) - ;; Font already loaded, we just continue + ;; Font already loaded, we just continue (contains? @loaded font-id) (p/resolved font-id) - ;; Font is currently downloading. We attach the caller to the promise + ;; Font is currently downloading. We attach the caller to the promise (contains? @loading font-id) (get @loading font-id) - ;; First caller, we create the promise and then wait + ;; First caller, we create the promise and then wait :else (let [on-load (fn [resolve] (swap! loaded conj font-id)