mirror of
https://github.com/penpot/penpot.git
synced 2025-05-29 06:26:12 +02:00
✨ 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:
parent
3cf823ffb3
commit
ebf3730454
10 changed files with 50 additions and 31 deletions
|
@ -283,14 +283,14 @@
|
|||
|
||||
:else
|
||||
(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)]
|
||||
(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}
|
||||
|
|
|
@ -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"]))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"}])
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
shape (cond-> shape
|
||||
^boolean child-sel?
|
||||
(dissoc :bool-content))]
|
||||
(dissoc :content))]
|
||||
|
||||
[:> shape-container {:shape shape}
|
||||
[:& bool-shape {:shape shape
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue