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