From ebf37304544c1519721fa63c8c54ba21e390503a Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 27 Mar 2025 11:15:48 +0100 Subject: [PATCH] :sparkles: Normalize the content prop from bool type (#6162) Make it the same as path shape, because they are essentially the same data type --- common/src/app/common/files/builder.cljc | 6 ++--- common/src/app/common/files/migrations.cljc | 21 +++++++++++++++- .../app/common/geom/shapes/transforms.cljc | 25 +++++++++---------- common/src/app/common/svg/path/bool.cljc | 4 +-- common/src/app/common/types/component.cljc | 4 +-- common/src/app/common/types/shape.cljc | 2 +- frontend/src/app/main/ui/shapes/bool.cljs | 2 +- .../app/main/ui/workspace/shapes/bool.cljs | 2 +- frontend/src/app/render_wasm/api.cljs | 14 ++++++----- frontend/src/app/render_wasm/shape.cljs | 1 - 10 files changed, 50 insertions(+), 31 deletions(-) diff --git a/common/src/app/common/files/builder.cljc b/common/src/app/common/files/builder.cljc index 5d93c515f8..816b2a4e68 100644 --- a/common/src/app/common/files/builder.cljc +++ b/common/src/app/common/files/builder.cljc @@ -283,14 +283,14 @@ :else (let [objects (lookup-objects file) - bool-content (gsh/calc-bool-content bool objects) - bool' (gsh/update-bool-selrect bool children objects)] + content (gsh/calc-bool-content bool objects) + bool' (gsh/update-bool-selrect bool children objects)] (commit-change file {:type :mod-obj :id bool-id :operations - [{:type :set :attr :bool-content :val bool-content :ignore-touched true} + [{:type :set :attr :content :val content :ignore-touched true} {:type :set :attr :selrect :val (:selrect bool') :ignore-touched true} {:type :set :attr :points :val (:points bool') :ignore-touched true} {:type :set :attr :x :val (-> bool' :selrect :x) :ignore-touched true} diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 734b3e4299..90e2f01a7f 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -1240,6 +1240,24 @@ (d/update-when page :objects update-vals update-object))] (update data :pages-index update-vals update-page))) +(defmethod migrate-data "0002-normalize-bool-content" + [data _] + (letfn [(update-object [object] + ;; NOTE: we still preserve the previous value for possible + ;; rollback, we still need to perform an other migration + ;; for properly delete the bool-content prop from shapes + ;; once the know the migration was OK + (if-let [content (:bool-content object)] + (assoc object :content content) + 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)))) + (def available-migrations (into (d/ordered-set) ["legacy-2" @@ -1294,4 +1312,5 @@ "legacy-65" "legacy-66" "legacy-67" - "0001-remove-tokens-from-groups"])) + "0001-remove-tokens-from-groups" + "0002-normalize-bool-content"])) diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index af52ac238e..50a41e06f3 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -95,8 +95,8 @@ (d/update-when :x d/safe+ dx) (d/update-when :y d/safe+ dy) (d/update-when :position-data move-position-data mvec) - (cond-> (= :bool type) (update :bool-content gpa/move-content mvec)) - (cond-> (= :path type) (update :content gpa/move-content mvec))))) + (cond-> (or (= :bool type) (= :path type)) + (update :content gpa/move-content mvec))))) ;; --- Absolute Movement @@ -317,13 +317,10 @@ points (gco/transform-points (dm/get-prop shape :points) transform-mtx) selrect (gco/transform-selrect (dm/get-prop shape :selrect) transform-mtx) - shape (if (= type :bool) - (update shape :bool-content gpa/transform-content transform-mtx) - shape) shape (if (= type :text) (update shape :position-data transform-position-data transform-mtx) shape) - shape (if (= type :path) + shape (if (or (= type :path) (= type :bool)) (update shape :content gpa/transform-content transform-mtx) (assoc shape :x (dm/get-prop selrect :x) @@ -355,11 +352,8 @@ rotation (mod (+ (d/nilv (:rotation shape) 0) (d/nilv (dm/get-in shape [:modifiers :rotation]) 0)) 360) - shape (if (= type :bool) - (update shape :bool-content gpa/transform-content transform-mtx) - shape) - shape (if (= type :path) + shape (if (or (= type :path) (= type :bool)) (update shape :content gpa/transform-content transform-mtx) (assoc shape :x (dm/get-prop selrect :x) @@ -454,9 +448,14 @@ "Calculates the selrect+points for the boolean shape" [shape children objects] - (let [bool-content (gshb/calc-bool-content shape objects) - shape (assoc shape :bool-content bool-content) - [points selrect] (gpa/content->points+selrect shape bool-content)] + (let [content + (gshb/calc-bool-content shape objects) + + shape + (assoc shape :content content) + + [points selrect] + (gpa/content->points+selrect shape content)] (if (and (some? selrect) (d/not-empty? points)) (-> shape diff --git a/common/src/app/common/svg/path/bool.cljc b/common/src/app/common/svg/path/bool.cljc index 11fe314a83..438aeeb598 100644 --- a/common/src/app/common/svg/path/bool.cljc +++ b/common/src/app/common/svg/path/bool.cljc @@ -312,14 +312,14 @@ content-a-split (->> content-a-split add-previous (filter is-segment?)) content-b-split (->> content-b-split add-previous (filter is-segment?)) - bool-content + content (case bool-type :union (create-union content-a content-a-split content-b content-b-split sr-a sr-b) :difference (create-difference content-a content-a-split content-b content-b-split sr-a sr-b) :intersection (create-intersection content-a content-a-split content-b content-b-split sr-a sr-b) :exclude (create-exclusion content-a-split content-b-split))] - (->> (fix-move-to bool-content) + (->> (fix-move-to content) (ups/close-subpaths)))) (defn content-bool diff --git a/common/src/app/common/types/component.cljc b/common/src/app/common/types/component.cljc index dc5c85558e..6eea62b462 100644 --- a/common/src/app/common/types/component.cljc +++ b/common/src/app/common/types/component.cljc @@ -93,8 +93,8 @@ :constraints-h :constraints-group :constraints-v :constraints-group :fixed-scroll :constraints-group - :bool-type :bool-group - :bool-content :bool-group + :bool-type :content-group + :bool-content :content-group :exports :exports-group :grids :grids-group diff --git a/common/src/app/common/types/shape.cljc b/common/src/app/common/types/shape.cljc index 0f11a1805e..d6172db8b0 100644 --- a/common/src/app/common/types/shape.cljc +++ b/common/src/app/common/types/shape.cljc @@ -234,7 +234,7 @@ [:map {:title "BoolAttrs"} [:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]] [:bool-type [::sm/one-of bool-types]] - [:bool-content ::ctsp/content]]) + [:content ::ctsp/content]]) (def ^:private schema:rect-attrs [:map {:title "RectAttrs"}]) diff --git a/frontend/src/app/main/ui/shapes/bool.cljs b/frontend/src/app/main/ui/shapes/bool.cljs index 29308eebab..87b5b6afb0 100644 --- a/frontend/src/app/main/ui/shapes/bool.cljs +++ b/frontend/src/app/main/ui/shapes/bool.cljs @@ -24,7 +24,7 @@ metadata? (mf/use-ctx use/include-metadata-ctx) content (mf/with-memo [shape child-objs] - (let [content (:bool-content shape)] + (let [content (:content shape)] (cond (some? content) content diff --git a/frontend/src/app/main/ui/workspace/shapes/bool.cljs b/frontend/src/app/main/ui/workspace/shapes/bool.cljs index a3080b704e..536bd7fe68 100644 --- a/frontend/src/app/main/ui/workspace/shapes/bool.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/bool.cljs @@ -35,7 +35,7 @@ shape (cond-> shape ^boolean child-sel? - (dissoc :bool-content))] + (dissoc :content))] [:> shape-container {:shape shape} [:& bool-shape {:shape shape diff --git a/frontend/src/app/render_wasm/api.cljs b/frontend/src/app/render_wasm/api.cljs index b858cce9f5..c5fcd50f86 100644 --- a/frontend/src/app/render_wasm/api.cljs +++ b/frontend/src/app/render_wasm/api.cljs @@ -420,9 +420,11 @@ [bool-type] (h/call internal-module "_set_shape_bool_type" (sr/translate-bool-type bool-type))) -(defn set-shape-bool-content - [content] - (set-shape-path-content content)) +(defn- translate-blur-type + [blur-type] + (case blur-type + :layer-blur 1 + 0)) (defn set-shape-blur [blur] @@ -800,7 +802,6 @@ (dm/get-prop shape :r2) (dm/get-prop shape :r3) (dm/get-prop shape :r4)]) - bool-content (dm/get-prop shape :bool-content) svg-attrs (dm/get-prop shape :svg-attrs) shadows (dm/get-prop shape :shadow)] @@ -821,12 +822,13 @@ (set-masked masked)) (when (some? blur) (set-shape-blur blur)) - (when (and (some? content) (= type :path)) + (when (and (some? content) + (or (= type :path) + (= type :bool))) (set-shape-path-attrs svg-attrs) (set-shape-path-content content)) (when (and (some? content) (= type :svg-raw)) (set-shape-svg-raw-content (get-static-markup shape))) - (when (some? bool-content) (set-shape-bool-content bool-content)) (when (some? corners) (set-shape-corners corners)) (when (some? shadows) (set-shape-shadows shadows)) (when (and (= type :text) (some? content)) diff --git a/frontend/src/app/render_wasm/shape.cljs b/frontend/src/app/render_wasm/shape.cljs index 0824a507ce..d8812487a7 100644 --- a/frontend/src/app/render_wasm/shape.cljs +++ b/frontend/src/app/render_wasm/shape.cljs @@ -114,7 +114,6 @@ :parent-id (api/set-parent-id v) :type (api/set-shape-type v) :bool-type (api/set-shape-bool-type v) - :bool-content (api/set-shape-bool-content v) :selrect (api/set-shape-selrect v) :show-content (if (= (:type self) :frame) (api/set-shape-clip-content (not v))