Normalize the content prop from bool type (#6162)

Make it the same as path shape, because they are essentially the
same data type
This commit is contained in:
Andrey Antukh 2025-03-27 11:15:48 +01:00 committed by GitHub
parent 3cf823ffb3
commit ebf3730454
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 50 additions and 31 deletions

View file

@ -283,14 +283,14 @@
:else :else
(let [objects (lookup-objects file) (let [objects (lookup-objects file)
bool-content (gsh/calc-bool-content bool objects) content (gsh/calc-bool-content bool objects)
bool' (gsh/update-bool-selrect bool children objects)] bool' (gsh/update-bool-selrect bool children objects)]
(commit-change (commit-change
file file
{:type :mod-obj {:type :mod-obj
:id bool-id :id bool-id
:operations :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 :selrect :val (:selrect bool') :ignore-touched true}
{:type :set :attr :points :val (:points 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} {:type :set :attr :x :val (-> bool' :selrect :x) :ignore-touched true}

View file

@ -1240,6 +1240,24 @@
(d/update-when page :objects update-vals update-object))] (d/update-when page :objects update-vals update-object))]
(update data :pages-index update-vals update-page))) (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 (def available-migrations
(into (d/ordered-set) (into (d/ordered-set)
["legacy-2" ["legacy-2"
@ -1294,4 +1312,5 @@
"legacy-65" "legacy-65"
"legacy-66" "legacy-66"
"legacy-67" "legacy-67"
"0001-remove-tokens-from-groups"])) "0001-remove-tokens-from-groups"
"0002-normalize-bool-content"]))

View file

@ -95,8 +95,8 @@
(d/update-when :x d/safe+ dx) (d/update-when :x d/safe+ dx)
(d/update-when :y d/safe+ dy) (d/update-when :y d/safe+ dy)
(d/update-when :position-data move-position-data mvec) (d/update-when :position-data move-position-data mvec)
(cond-> (= :bool type) (update :bool-content gpa/move-content mvec)) (cond-> (or (= :bool type) (= :path type))
(cond-> (= :path type) (update :content gpa/move-content mvec))))) (update :content gpa/move-content mvec)))))
;; --- Absolute Movement ;; --- Absolute Movement
@ -317,13 +317,10 @@
points (gco/transform-points (dm/get-prop shape :points) transform-mtx) points (gco/transform-points (dm/get-prop shape :points) transform-mtx)
selrect (gco/transform-selrect (dm/get-prop shape :selrect) 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) shape (if (= type :text)
(update shape :position-data transform-position-data transform-mtx) (update shape :position-data transform-position-data transform-mtx)
shape) shape)
shape (if (= type :path) shape (if (or (= type :path) (= type :bool))
(update shape :content gpa/transform-content transform-mtx) (update shape :content gpa/transform-content transform-mtx)
(assoc shape (assoc shape
:x (dm/get-prop selrect :x) :x (dm/get-prop selrect :x)
@ -355,11 +352,8 @@
rotation (mod (+ (d/nilv (:rotation shape) 0) rotation (mod (+ (d/nilv (:rotation shape) 0)
(d/nilv (dm/get-in shape [:modifiers :rotation]) 0)) (d/nilv (dm/get-in shape [:modifiers :rotation]) 0))
360) 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) (update shape :content gpa/transform-content transform-mtx)
(assoc shape (assoc shape
:x (dm/get-prop selrect :x) :x (dm/get-prop selrect :x)
@ -454,9 +448,14 @@
"Calculates the selrect+points for the boolean shape" "Calculates the selrect+points for the boolean shape"
[shape children objects] [shape children objects]
(let [bool-content (gshb/calc-bool-content shape objects) (let [content
shape (assoc shape :bool-content bool-content) (gshb/calc-bool-content shape objects)
[points selrect] (gpa/content->points+selrect shape bool-content)]
shape
(assoc shape :content content)
[points selrect]
(gpa/content->points+selrect shape content)]
(if (and (some? selrect) (d/not-empty? points)) (if (and (some? selrect) (d/not-empty? points))
(-> shape (-> shape

View file

@ -312,14 +312,14 @@
content-a-split (->> content-a-split add-previous (filter is-segment?)) content-a-split (->> content-a-split add-previous (filter is-segment?))
content-b-split (->> content-b-split add-previous (filter is-segment?)) content-b-split (->> content-b-split add-previous (filter is-segment?))
bool-content content
(case bool-type (case bool-type
:union (create-union content-a content-a-split content-b content-b-split sr-a sr-b) :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) :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) :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))] :exclude (create-exclusion content-a-split content-b-split))]
(->> (fix-move-to bool-content) (->> (fix-move-to content)
(ups/close-subpaths)))) (ups/close-subpaths))))
(defn content-bool (defn content-bool

View file

@ -93,8 +93,8 @@
:constraints-h :constraints-group :constraints-h :constraints-group
:constraints-v :constraints-group :constraints-v :constraints-group
:fixed-scroll :constraints-group :fixed-scroll :constraints-group
:bool-type :bool-group :bool-type :content-group
:bool-content :bool-group :bool-content :content-group
:exports :exports-group :exports :exports-group
:grids :grids-group :grids :grids-group

View file

@ -234,7 +234,7 @@
[:map {:title "BoolAttrs"} [:map {:title "BoolAttrs"}
[:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]] [:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]
[:bool-type [::sm/one-of bool-types]] [:bool-type [::sm/one-of bool-types]]
[:bool-content ::ctsp/content]]) [:content ::ctsp/content]])
(def ^:private schema:rect-attrs (def ^:private schema:rect-attrs
[:map {:title "RectAttrs"}]) [:map {:title "RectAttrs"}])

View file

@ -24,7 +24,7 @@
metadata? (mf/use-ctx use/include-metadata-ctx) metadata? (mf/use-ctx use/include-metadata-ctx)
content (mf/with-memo [shape child-objs] content (mf/with-memo [shape child-objs]
(let [content (:bool-content shape)] (let [content (:content shape)]
(cond (cond
(some? content) (some? content)
content content

View file

@ -35,7 +35,7 @@
shape (cond-> shape shape (cond-> shape
^boolean child-sel? ^boolean child-sel?
(dissoc :bool-content))] (dissoc :content))]
[:> shape-container {:shape shape} [:> shape-container {:shape shape}
[:& bool-shape {:shape shape [:& bool-shape {:shape shape

View file

@ -420,9 +420,11 @@
[bool-type] [bool-type]
(h/call internal-module "_set_shape_bool_type" (sr/translate-bool-type bool-type))) (h/call internal-module "_set_shape_bool_type" (sr/translate-bool-type bool-type)))
(defn set-shape-bool-content (defn- translate-blur-type
[content] [blur-type]
(set-shape-path-content content)) (case blur-type
:layer-blur 1
0))
(defn set-shape-blur (defn set-shape-blur
[blur] [blur]
@ -800,7 +802,6 @@
(dm/get-prop shape :r2) (dm/get-prop shape :r2)
(dm/get-prop shape :r3) (dm/get-prop shape :r3)
(dm/get-prop shape :r4)]) (dm/get-prop shape :r4)])
bool-content (dm/get-prop shape :bool-content)
svg-attrs (dm/get-prop shape :svg-attrs) svg-attrs (dm/get-prop shape :svg-attrs)
shadows (dm/get-prop shape :shadow)] shadows (dm/get-prop shape :shadow)]
@ -821,12 +822,13 @@
(set-masked masked)) (set-masked masked))
(when (some? blur) (when (some? blur)
(set-shape-blur 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-attrs svg-attrs)
(set-shape-path-content content)) (set-shape-path-content content))
(when (and (some? content) (= type :svg-raw)) (when (and (some? content) (= type :svg-raw))
(set-shape-svg-raw-content (get-static-markup shape))) (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? corners) (set-shape-corners corners))
(when (some? shadows) (set-shape-shadows shadows)) (when (some? shadows) (set-shape-shadows shadows))
(when (and (= type :text) (some? content)) (when (and (= type :text) (some? content))

View file

@ -114,7 +114,6 @@
:parent-id (api/set-parent-id v) :parent-id (api/set-parent-id v)
:type (api/set-shape-type v) :type (api/set-shape-type v)
:bool-type (api/set-shape-bool-type v) :bool-type (api/set-shape-bool-type v)
:bool-content (api/set-shape-bool-content v)
:selrect (api/set-shape-selrect v) :selrect (api/set-shape-selrect v)
:show-content (if (= (:type self) :frame) :show-content (if (= (:type self) :frame)
(api/set-shape-clip-content (not v)) (api/set-shape-clip-content (not v))