mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 08:50:57 -05:00
🐛 Pack swap component in a single transaction and undo group
This commit is contained in:
parent
150fa394ff
commit
d3dd9ffd9b
2 changed files with 34 additions and 14 deletions
|
@ -865,7 +865,7 @@
|
|||
0)))))
|
||||
|
||||
(defn- add-component-for-swap
|
||||
[shape file-id id-new-component index target-cell keep-props-values]
|
||||
[shape file-id id-new-component index target-cell keep-props-values {:keys [undo-group]}]
|
||||
(dm/assert! (uuid? id-new-component))
|
||||
(dm/assert! (uuid? file-id))
|
||||
(ptk/reify ::add-component-for-swap
|
||||
|
@ -877,6 +877,7 @@
|
|||
objects (:objects page)
|
||||
position (gpt/point (:x shape) (:y shape))
|
||||
changes (-> (pcb/empty-changes it (:id page))
|
||||
(pcb/set-undo-group undo-group)
|
||||
(pcb/with-objects objects))
|
||||
position (-> position (with-meta {:cell target-cell}))
|
||||
|
||||
|
@ -925,10 +926,20 @@
|
|||
index (find-shape-index objects (:parent-id shape) (:id shape))
|
||||
|
||||
;; Store the properties that need to be maintained when the component is swapped
|
||||
keep-props-values (select-keys shape ctk/swap-keep-attrs)]
|
||||
(rx/of (dwsh/delete-shapes nil (d/ordered-set (:id shape)) {:component-swap true})
|
||||
(add-component-for-swap shape file-id id-new-component index target-cell keep-props-values)
|
||||
(ptk/data-event :layout/update [(:parent-id shape)]))))))
|
||||
keep-props-values (select-keys shape ctk/swap-keep-attrs)
|
||||
|
||||
undo-id (js/Symbol)
|
||||
undo-group (uuid/next)]
|
||||
|
||||
(rx/of
|
||||
(dwu/start-undo-transaction undo-id)
|
||||
(dwsh/delete-shapes nil (d/ordered-set (:id shape)) {:component-swap true
|
||||
:undo-id undo-id
|
||||
:undo-group undo-group})
|
||||
(add-component-for-swap shape file-id id-new-component index target-cell keep-props-values
|
||||
{:undo-group undo-group})
|
||||
(ptk/data-event :layout/update [(:parent-id shape)])
|
||||
(dwu/commit-undo-transaction undo-id))))))
|
||||
|
||||
(defn component-multi-swap
|
||||
"Swaps several components with another one"
|
||||
|
@ -946,7 +957,6 @@
|
|||
(rx/of (dwu/commit-undo-transaction undo-id))
|
||||
(rx/of (dwsp/open-specialized-panel :component-swap)))))))
|
||||
|
||||
|
||||
(def valid-asset-types
|
||||
#{:colors :components :typographies})
|
||||
|
||||
|
|
|
@ -137,22 +137,25 @@
|
|||
ids-to-hide)))))
|
||||
[ids []])
|
||||
|
||||
undo-id (js/Symbol)]
|
||||
undo-id (or (:undo-id options) (js/Symbol))]
|
||||
|
||||
(rx/concat
|
||||
(rx/of (dwu/start-undo-transaction undo-id)
|
||||
(update-shape-flags ids-to-hide {:hidden true}))
|
||||
(real-delete-shapes file page objects ids-to-delete it components-v2 (:component-swap options))
|
||||
(real-delete-shapes file page objects ids-to-delete it {:components-v2 components-v2
|
||||
:ignore-touched (:component-swap options)
|
||||
:undo-group (:undo-group options)})
|
||||
(rx/of (dwu/commit-undo-transaction undo-id))))))))
|
||||
|
||||
(defn- real-delete-shapes-changes
|
||||
([file page objects ids it components-v2 ignore-touched]
|
||||
([file page objects ids it {:keys [undo-group] :as options}]
|
||||
(let [changes (-> (pcb/empty-changes it (:id page))
|
||||
(pcb/set-undo-group undo-group)
|
||||
(pcb/with-page page)
|
||||
(pcb/with-objects objects)
|
||||
(pcb/with-library-data file))]
|
||||
(real-delete-shapes-changes changes file page objects ids it components-v2 ignore-touched)))
|
||||
([changes file page objects ids _it components-v2 ignore-touched]
|
||||
(real-delete-shapes-changes changes file page objects ids it options)))
|
||||
([changes file page objects ids _it {:keys [components-v2 ignore-touched]}]
|
||||
(let [lookup (d/getf objects)
|
||||
groups-to-unmask
|
||||
(reduce (fn [group-ids id]
|
||||
|
@ -275,12 +278,19 @@
|
|||
|
||||
(defn delete-shapes-changes
|
||||
[changes file page objects ids it components-v2 ignore-touched]
|
||||
(let [[changes _all-parents] (real-delete-shapes-changes changes file page objects ids it components-v2 ignore-touched)]
|
||||
(let [[changes _all-parents] (real-delete-shapes-changes changes
|
||||
file
|
||||
page
|
||||
objects
|
||||
ids
|
||||
it
|
||||
{:components-v2 components-v2
|
||||
:ignore-touched ignore-touched})]
|
||||
changes))
|
||||
|
||||
(defn- real-delete-shapes
|
||||
[file page objects ids it components-v2 ignore-touched]
|
||||
(let [[changes all-parents] (real-delete-shapes-changes file page objects ids it components-v2 ignore-touched)
|
||||
[file page objects ids it options]
|
||||
(let [[changes all-parents] (real-delete-shapes-changes file page objects ids it options)
|
||||
undo-id (js/Symbol)]
|
||||
(rx/of (dwu/start-undo-transaction undo-id)
|
||||
(dc/detach-comment-thread ids)
|
||||
|
|
Loading…
Reference in a new issue