mirror of
https://github.com/penpot/penpot.git
synced 2025-04-01 01:21:21 -05:00
🐛 Fix keep layout-item properties after swap
This commit is contained in:
parent
800d35a42c
commit
4c7e565f6a
2 changed files with 25 additions and 16 deletions
|
@ -83,18 +83,19 @@
|
||||||
:layout-grid-dir :layout-container
|
:layout-grid-dir :layout-container
|
||||||
:layout-grid-rows :layout-container
|
:layout-grid-rows :layout-container
|
||||||
:layout-grid-columns :layout-container
|
:layout-grid-columns :layout-container
|
||||||
:layout-grid-cells :layout-container
|
:layout-grid-cells :layout-container})
|
||||||
|
|
||||||
:layout-item-margin :layout-item
|
|
||||||
:layout-item-margin-type :layout-item
|
|
||||||
:layout-item-h-sizing :layout-item
|
|
||||||
:layout-item-v-sizing :layout-item
|
|
||||||
:layout-item-max-h :layout-item
|
|
||||||
:layout-item-min-h :layout-item
|
|
||||||
:layout-item-max-w :layout-item
|
|
||||||
:layout-item-min-w :layout-item
|
|
||||||
:layout-item-align-self :layout-item})
|
|
||||||
|
|
||||||
|
(def swap-keep-attrs
|
||||||
|
[:layout-item-margin
|
||||||
|
:layout-item-margin-type
|
||||||
|
:layout-item-h-sizing
|
||||||
|
:layout-item-v-sizing
|
||||||
|
:layout-item-max-h
|
||||||
|
:layout-item-min-h
|
||||||
|
:layout-item-max-w
|
||||||
|
:layout-item-min-w
|
||||||
|
:layout-item-absolute
|
||||||
|
:layout-item-z-index])
|
||||||
|
|
||||||
(defn instance-root?
|
(defn instance-root?
|
||||||
"Check if this shape is the head of a top instance."
|
"Check if this shape is the head of a top instance."
|
||||||
|
|
|
@ -829,7 +829,7 @@
|
||||||
0)))))
|
0)))))
|
||||||
|
|
||||||
(defn- add-component-for-swap
|
(defn- add-component-for-swap
|
||||||
[shape file-id id-new-component index target-cell]
|
[shape file-id id-new-component index target-cell keep-props-values]
|
||||||
(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
|
||||||
|
@ -856,8 +856,13 @@
|
||||||
(:parent-id shape)
|
(:parent-id shape)
|
||||||
(:frame-id shape))
|
(:frame-id shape))
|
||||||
|
|
||||||
;; We need to set the same index as the original shape
|
changes
|
||||||
changes (pcb/change-parent changes (:parent-id shape) [new-shape] index {:component-swap true})]
|
(-> changes
|
||||||
|
;; Restore the properties
|
||||||
|
(pcb/update-shapes [(:id new-shape)] #(d/patch-object % keep-props-values))
|
||||||
|
|
||||||
|
;; We need to set the same index as the original shape
|
||||||
|
(pcb/change-parent (:parent-id shape) [new-shape] index {:component-swap true}))]
|
||||||
|
|
||||||
;; First delete so we don't break the grid layout cells
|
;; First delete so we don't break the grid layout cells
|
||||||
(rx/of (dch/commit-changes changes)
|
(rx/of (dch/commit-changes changes)
|
||||||
|
@ -880,9 +885,12 @@
|
||||||
target-cell (when (ctl/grid-layout? parent)
|
target-cell (when (ctl/grid-layout? parent)
|
||||||
(ctl/get-cell-by-shape-id parent (:id shape)))
|
(ctl/get-cell-by-shape-id parent (:id shape)))
|
||||||
|
|
||||||
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
|
||||||
|
keep-props-values (select-keys shape ctk/swap-keep-attrs)]
|
||||||
(rx/of (dwsh/delete-shapes nil (d/ordered-set (:id shape)) {:component-swap true})
|
(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)
|
(add-component-for-swap shape file-id id-new-component index target-cell keep-props-values)
|
||||||
(ptk/data-event :layout/update [(:parent-id shape)]))))))
|
(ptk/data-event :layout/update [(:parent-id shape)]))))))
|
||||||
|
|
||||||
(defn component-multi-swap
|
(defn component-multi-swap
|
||||||
|
|
Loading…
Add table
Reference in a new issue