mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 17:00:36 -05:00
♻️ Simplify add container id to changes
This commit is contained in:
parent
fe7faf0d0d
commit
091ea785e5
2 changed files with 158 additions and 172 deletions
|
@ -127,7 +127,7 @@
|
||||||
(d/update-in-when data [:pages-index page-id :objects] delete-object id)
|
(d/update-in-when data [:pages-index page-id :objects] delete-object id)
|
||||||
(d/update-in-when data [:components component-id :objects] delete-object id))))
|
(d/update-in-when data [:components component-id :objects] delete-object id))))
|
||||||
|
|
||||||
;; reg-objects operation "regenerates" the values for the parent groups
|
;; reg-objects operation "regenerates" the geometry and selrect of the parent groups
|
||||||
(defmethod process-change :reg-objects
|
(defmethod process-change :reg-objects
|
||||||
[data {:keys [page-id component-id shapes]}]
|
[data {:keys [page-id component-id shapes]}]
|
||||||
(letfn [(reg-objects [objects]
|
(letfn [(reg-objects [objects]
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
(declare change-remote-synced)
|
(declare change-remote-synced)
|
||||||
(declare update-attrs)
|
(declare update-attrs)
|
||||||
(declare reposition-shape)
|
(declare reposition-shape)
|
||||||
|
(declare make-change)
|
||||||
|
|
||||||
(defn concat-changes
|
(defn concat-changes
|
||||||
[[rchanges1 uchanges1] [rchanges2 uchanges2]]
|
[[rchanges1 uchanges1] [rchanges2 uchanges2]]
|
||||||
|
@ -268,22 +269,20 @@
|
||||||
[shape container update-node]
|
[shape container update-node]
|
||||||
(let [old-content (:content shape)
|
(let [old-content (:content shape)
|
||||||
new-content (ut/map-node update-node old-content)
|
new-content (ut/map-node update-node old-content)
|
||||||
rchanges [(as-> {:type :mod-obj
|
rchanges [(make-change
|
||||||
|
container
|
||||||
|
{:type :mod-obj
|
||||||
:id (:id shape)
|
:id (:id shape)
|
||||||
:operations [{:type :set
|
:operations [{:type :set
|
||||||
:attr :content
|
:attr :content
|
||||||
:val new-content}]} $
|
:val new-content}]})]
|
||||||
(if (cp/page? container)
|
uchanges [(make-change
|
||||||
(assoc $ :page-id (:id container))
|
container
|
||||||
(assoc $ :component-id (:id container))))]
|
{:type :mod-obj
|
||||||
uchanges [(as-> {:type :mod-obj
|
|
||||||
:id (:id shape)
|
:id (:id shape)
|
||||||
:operations [{:type :set
|
:operations [{:type :set
|
||||||
:attr :content
|
:attr :content
|
||||||
:val old-content}]} $
|
:val old-content}]})]]
|
||||||
(if (cp/page? container)
|
|
||||||
(assoc $ :page-id (:id container))
|
|
||||||
(assoc $ :component-id (:id container))))]]
|
|
||||||
|
|
||||||
(if (= new-content old-content)
|
(if (= new-content old-content)
|
||||||
empty-changes
|
empty-changes
|
||||||
|
@ -312,18 +311,16 @@
|
||||||
(if (nil? attr)
|
(if (nil? attr)
|
||||||
(if (empty? roperations)
|
(if (empty? roperations)
|
||||||
empty-changes
|
empty-changes
|
||||||
(let [rchanges [(as-> {:type :mod-obj
|
(let [rchanges [(make-change
|
||||||
|
container
|
||||||
|
{:type :mod-obj
|
||||||
:id (:id shape)
|
:id (:id shape)
|
||||||
:operations roperations} $
|
:operations roperations})]
|
||||||
(if (cp/page? container)
|
uchanges [(make-change
|
||||||
(assoc $ :page-id (:id container))
|
container
|
||||||
(assoc $ :component-id (:id container))))]
|
{:type :mod-obj
|
||||||
uchanges [(as-> {:type :mod-obj
|
|
||||||
:id (:id shape)
|
:id (:id shape)
|
||||||
:operations uoperations} $
|
:operations uoperations})]]
|
||||||
(if (cp/page? container)
|
|
||||||
(assoc $ :page-id (:id container))
|
|
||||||
(assoc $ :component-id (:id container))))]]
|
|
||||||
[rchanges uchanges]))
|
[rchanges uchanges]))
|
||||||
(if-not (contains? shape attr-ref-id)
|
(if-not (contains? shape attr-ref-id)
|
||||||
(recur (next attrs)
|
(recur (next attrs)
|
||||||
|
@ -793,6 +790,8 @@
|
||||||
|
|
||||||
rchanges (d/concat
|
rchanges (d/concat
|
||||||
(mapv (fn [shape']
|
(mapv (fn [shape']
|
||||||
|
(make-change
|
||||||
|
container
|
||||||
(as-> {:type :add-obj
|
(as-> {:type :add-obj
|
||||||
:id (:id shape')
|
:id (:id shape')
|
||||||
:parent-id (:parent-id shape')
|
:parent-id (:parent-id shape')
|
||||||
|
@ -800,25 +799,20 @@
|
||||||
:obj shape'} $
|
:obj shape'} $
|
||||||
(cond-> $
|
(cond-> $
|
||||||
(:frame-id shape')
|
(:frame-id shape')
|
||||||
(assoc :frame-id (:frame-id shape')))
|
(assoc :frame-id (:frame-id shape'))))))
|
||||||
(if (cp/page? container)
|
|
||||||
(assoc $ :page-id (:id container))
|
|
||||||
(assoc $ :component-id (:id container)))))
|
|
||||||
new-shapes)
|
new-shapes)
|
||||||
[(as-> {:type :reg-objects
|
[(make-change
|
||||||
:shapes all-parents} $
|
container
|
||||||
(if (cp/page? container)
|
{:type :reg-objects
|
||||||
(assoc $ :page-id (:id container))
|
:shapes all-parents})])
|
||||||
(assoc $ :component-id (:id container))))])
|
|
||||||
|
|
||||||
uchanges (d/concat
|
uchanges (d/concat
|
||||||
(mapv (fn [shape']
|
(mapv (fn [shape']
|
||||||
(as-> {:type :del-obj
|
(make-change
|
||||||
|
container
|
||||||
|
{:type :del-obj
|
||||||
:id (:id shape')
|
:id (:id shape')
|
||||||
:ignore-touched true} $
|
:ignore-touched true}))
|
||||||
(if (cp/page? container)
|
|
||||||
(assoc $ :page-id (:id container))
|
|
||||||
(assoc $ :component-id (:id container)))))
|
|
||||||
new-shapes))]
|
new-shapes))]
|
||||||
|
|
||||||
(if (and (cp/touched-group? parent-shape :shapes-group) omit-touched?)
|
(if (and (cp/touched-group? parent-shape :shapes-group) omit-touched?)
|
||||||
|
@ -907,15 +901,16 @@
|
||||||
parent (first parents)
|
parent (first parents)
|
||||||
children (cp/get-children (:id shape) objects)
|
children (cp/get-children (:id shape) objects)
|
||||||
|
|
||||||
rchanges [(as-> {:type :del-obj
|
rchanges [(make-change
|
||||||
|
container
|
||||||
|
{:type :del-obj
|
||||||
:id (:id shape)
|
:id (:id shape)
|
||||||
:ignore-touched true} $
|
:ignore-touched true})]
|
||||||
(if (cp/page? container)
|
|
||||||
(assoc $ :page-id (:id container))
|
|
||||||
(assoc $ :component-id (:id container))))]
|
|
||||||
|
|
||||||
add-change (fn [id]
|
add-change (fn [id]
|
||||||
(let [shape' (get objects id)]
|
(let [shape' (get objects id)]
|
||||||
|
(make-change
|
||||||
|
container
|
||||||
(as-> {:type :add-obj
|
(as-> {:type :add-obj
|
||||||
:id id
|
:id id
|
||||||
:index (cp/position-on-parent id objects)
|
:index (cp/position-on-parent id objects)
|
||||||
|
@ -924,19 +919,15 @@
|
||||||
:obj shape'} $
|
:obj shape'} $
|
||||||
(cond-> $
|
(cond-> $
|
||||||
(:frame-id shape')
|
(:frame-id shape')
|
||||||
(assoc :frame-id (:frame-id shape')))
|
(assoc :frame-id (:frame-id shape')))))))
|
||||||
(if (cp/page? container)
|
|
||||||
(assoc $ :page-id (:id container))
|
|
||||||
(assoc $ :component-id (:id container))))))
|
|
||||||
|
|
||||||
uchanges (d/concat
|
uchanges (d/concat
|
||||||
[(add-change (:id shape))]
|
[(add-change (:id shape))]
|
||||||
(map add-change children)
|
(map add-change children)
|
||||||
[(as-> {:type :reg-objects
|
[(make-change
|
||||||
:shapes (vec parents)} $
|
container
|
||||||
(if (cp/page? container)
|
{:type :reg-objects
|
||||||
(assoc $ :page-id (:id container))
|
:shapes (vec parents)})])]
|
||||||
(assoc $ :component-id (:id container))))])]
|
|
||||||
|
|
||||||
(if (and (cp/touched-group? parent :shapes-group) omit-touched?)
|
(if (and (cp/touched-group? parent :shapes-group) omit-touched?)
|
||||||
empty-changes
|
empty-changes
|
||||||
|
@ -953,22 +944,20 @@
|
||||||
index-after))
|
index-after))
|
||||||
(let [parent (cp/get-shape container (:parent-id shape))
|
(let [parent (cp/get-shape container (:parent-id shape))
|
||||||
|
|
||||||
rchanges [(as-> {:type :mov-objects
|
rchanges [(make-change
|
||||||
|
container
|
||||||
|
{:type :mov-objects
|
||||||
:parent-id (:parent-id shape)
|
:parent-id (:parent-id shape)
|
||||||
:shapes [(:id shape)]
|
:shapes [(:id shape)]
|
||||||
:index index-after
|
:index index-after
|
||||||
:ignore-touched true} $
|
:ignore-touched true})]
|
||||||
(if (cp/page? container)
|
uchanges [(make-change
|
||||||
(assoc $ :page-id (:id container))
|
container
|
||||||
(assoc $ :component-id (:id container))))]
|
{:type :mov-objects
|
||||||
uchanges [(as-> {:type :mov-objects
|
|
||||||
:parent-id (:parent-id shape)
|
:parent-id (:parent-id shape)
|
||||||
:shapes [(:id shape)]
|
:shapes [(:id shape)]
|
||||||
:index index-before
|
:index index-before
|
||||||
:ignore-touched true} $
|
:ignore-touched true})]]
|
||||||
(if (cp/page? container)
|
|
||||||
(assoc $ :page-id (:id container))
|
|
||||||
(assoc $ :component-id (:id container))))]]
|
|
||||||
|
|
||||||
(if (and (cp/touched-group? parent :shapes-group) omit-touched?)
|
(if (and (cp/touched-group? parent :shapes-group) omit-touched?)
|
||||||
empty-changes
|
empty-changes
|
||||||
|
@ -985,12 +974,7 @@
|
||||||
(if (cp/page? container) "[P] " "[C] ")
|
(if (cp/page? container) "[P] " "[C] ")
|
||||||
(:name dest-shape))
|
(:name dest-shape))
|
||||||
:options options)
|
:options options)
|
||||||
(let [rchanges [(as-> {:type :mod-obj
|
(let [new-touched (cond
|
||||||
:id (:id dest-shape)
|
|
||||||
:operations
|
|
||||||
[{:type :set-touched
|
|
||||||
:touched
|
|
||||||
(cond
|
|
||||||
reset-touched?
|
reset-touched?
|
||||||
nil
|
nil
|
||||||
copy-touched?
|
copy-touched?
|
||||||
|
@ -998,19 +982,23 @@
|
||||||
nil
|
nil
|
||||||
(set/union
|
(set/union
|
||||||
(:touched dest-shape)
|
(:touched dest-shape)
|
||||||
(:touched origin-shape))))}]} $
|
(:touched origin-shape))))
|
||||||
(if (cp/page? container)
|
|
||||||
(assoc $ :page-id (:id container))
|
|
||||||
(assoc $ :component-id (:id container))))]
|
|
||||||
|
|
||||||
uchanges [(as-> {:type :mod-obj
|
rchanges [(make-change
|
||||||
|
container
|
||||||
|
{:type :mod-obj
|
||||||
:id (:id dest-shape)
|
:id (:id dest-shape)
|
||||||
:operations
|
:operations
|
||||||
[{:type :set-touched
|
[{:type :set-touched
|
||||||
:touched (:touched dest-shape)}]} $
|
:touched new-touched}]})]
|
||||||
(if (cp/page? container)
|
|
||||||
(assoc $ :page-id (:id container))
|
uchanges [(make-change
|
||||||
(assoc $ :component-id (:id container))))]]
|
container
|
||||||
|
{:type :mod-obj
|
||||||
|
:id (:id dest-shape)
|
||||||
|
:operations
|
||||||
|
[{:type :set-touched
|
||||||
|
:touched (:touched dest-shape)}]})]]
|
||||||
[rchanges uchanges]))))
|
[rchanges uchanges]))))
|
||||||
|
|
||||||
(defn- change-remote-synced
|
(defn- change-remote-synced
|
||||||
|
@ -1022,23 +1010,21 @@
|
||||||
(if (cp/page? container) "[P] " "[C] ")
|
(if (cp/page? container) "[P] " "[C] ")
|
||||||
(:name shape))
|
(:name shape))
|
||||||
:remote-synced? remote-synced?)
|
:remote-synced? remote-synced?)
|
||||||
(let [rchanges [(as-> {:type :mod-obj
|
(let [rchanges [(make-change
|
||||||
|
container
|
||||||
|
{:type :mod-obj
|
||||||
:id (:id shape)
|
:id (:id shape)
|
||||||
:operations
|
:operations
|
||||||
[{:type :set-remote-synced
|
[{:type :set-remote-synced
|
||||||
:remote-synced? remote-synced?}]} $
|
:remote-synced? remote-synced?}]})]
|
||||||
(if (cp/page? container)
|
|
||||||
(assoc $ :page-id (:id container))
|
|
||||||
(assoc $ :component-id (:id container))))]
|
|
||||||
|
|
||||||
uchanges [(as-> {:type :mod-obj
|
uchanges [(make-change
|
||||||
|
container
|
||||||
|
{:type :mod-obj
|
||||||
:id (:id shape)
|
:id (:id shape)
|
||||||
:operations
|
:operations
|
||||||
[{:type :set-remote-synced
|
[{:type :set-remote-synced
|
||||||
:remote-synced? (:remote-synced? shape)}]} $
|
:remote-synced? (:remote-synced? shape)}]})]]
|
||||||
(if (cp/page? container)
|
|
||||||
(assoc $ :page-id (:id container))
|
|
||||||
(assoc $ :component-id (:id container))))]]
|
|
||||||
[rchanges uchanges]))))
|
[rchanges uchanges]))))
|
||||||
|
|
||||||
(defn- set-touched-shapes-group
|
(defn- set-touched-shapes-group
|
||||||
|
@ -1049,25 +1035,23 @@
|
||||||
(log/info :msg (str "SET-TOUCHED-SHAPES-GROUP "
|
(log/info :msg (str "SET-TOUCHED-SHAPES-GROUP "
|
||||||
(if (cp/page? container) "[P] " "[C] ")
|
(if (cp/page? container) "[P] " "[C] ")
|
||||||
(:name shape)))
|
(:name shape)))
|
||||||
(let [rchanges [(as-> {:type :mod-obj
|
(let [rchanges [(make-change
|
||||||
|
container
|
||||||
|
{:type :mod-obj
|
||||||
:id (:id shape)
|
:id (:id shape)
|
||||||
:operations
|
:operations
|
||||||
[{:type :set-touched
|
[{:type :set-touched
|
||||||
:touched (cp/set-touched-group
|
:touched (cp/set-touched-group
|
||||||
(:touched shape)
|
(:touched shape)
|
||||||
:shapes-group)}]} $
|
:shapes-group)}]})]
|
||||||
(if (cp/page? container)
|
|
||||||
(assoc $ :page-id (:id container))
|
|
||||||
(assoc $ :component-id (:id container))))]
|
|
||||||
|
|
||||||
uchanges [(as-> {:type :mod-obj
|
uchanges [(make-change
|
||||||
|
container
|
||||||
|
{:type :mod-obj
|
||||||
:id (:id shape)
|
:id (:id shape)
|
||||||
:operations
|
:operations
|
||||||
[{:type :set-touched
|
[{:type :set-touched
|
||||||
:touched (:touched shape)}]} $
|
:touched (:touched shape)}]})]]
|
||||||
(if (cp/page? container)
|
|
||||||
(assoc $ :page-id (:id container))
|
|
||||||
(assoc $ :component-id (:id container))))]]
|
|
||||||
[rchanges uchanges]))))
|
[rchanges uchanges]))))
|
||||||
|
|
||||||
(defn- update-attrs
|
(defn- update-attrs
|
||||||
|
@ -1100,29 +1084,24 @@
|
||||||
(if (nil? attr)
|
(if (nil? attr)
|
||||||
(let [all-parents (vec (or (cp/get-parents (:id dest-shape)
|
(let [all-parents (vec (or (cp/get-parents (:id dest-shape)
|
||||||
(:objects container)) []))
|
(:objects container)) []))
|
||||||
|
rchanges [(make-change
|
||||||
rchanges [(as-> {:type :mod-obj
|
container
|
||||||
|
{:type :mod-obj
|
||||||
:id (:id dest-shape)
|
:id (:id dest-shape)
|
||||||
:operations roperations} $
|
:operations roperations})
|
||||||
(if (cp/page? container)
|
(make-change
|
||||||
(assoc $ :page-id (:id container))
|
container
|
||||||
(assoc $ :component-id (:id container))))
|
{:type :reg-objects
|
||||||
(as-> {:type :reg-objects
|
:shapes all-parents})]
|
||||||
:shapes all-parents} $
|
uchanges [(make-change
|
||||||
(if (cp/page? container)
|
container
|
||||||
(assoc $ :page-id (:id container))
|
{:type :mod-obj
|
||||||
(assoc $ :component-id (:id container))))]
|
|
||||||
uchanges [(as-> {:type :mod-obj
|
|
||||||
:id (:id dest-shape)
|
:id (:id dest-shape)
|
||||||
:operations uoperations} $
|
:operations uoperations})
|
||||||
(if (cp/page? container)
|
(make-change
|
||||||
(assoc $ :page-id (:id container))
|
container
|
||||||
(assoc $ :component-id (:id container))))
|
{:type :reg-objects
|
||||||
(as-> {:type :reg-objects
|
:shapes all-parents})]]
|
||||||
:shapes all-parents} $
|
|
||||||
(if (cp/page? container)
|
|
||||||
(assoc $ :page-id (:id container))
|
|
||||||
(assoc $ :component-id (:id container))))]]
|
|
||||||
(if (seq roperations)
|
(if (seq roperations)
|
||||||
[rchanges uchanges]
|
[rchanges uchanges]
|
||||||
empty-changes))
|
empty-changes))
|
||||||
|
@ -1156,3 +1135,10 @@
|
||||||
dest-root-pos (shape-pos dest-root)
|
dest-root-pos (shape-pos dest-root)
|
||||||
delta (gpt/subtract dest-root-pos origin-root-pos)]
|
delta (gpt/subtract dest-root-pos origin-root-pos)]
|
||||||
(geom/move shape delta)))
|
(geom/move shape delta)))
|
||||||
|
|
||||||
|
(defn- make-change
|
||||||
|
[container change]
|
||||||
|
(if (cp/page? container)
|
||||||
|
(assoc change :page-id (:id container))
|
||||||
|
(assoc change :component-id (:id container))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue