mirror of
https://github.com/penpot/penpot.git
synced 2025-02-23 23:35:58 -05:00
🐛 Fix swap component breaks grid layout
This commit is contained in:
parent
5c3ea37bbe
commit
a4796e8db8
2 changed files with 19 additions and 7 deletions
|
@ -825,12 +825,11 @@
|
|||
second)
|
||||
0)))))
|
||||
|
||||
(defn- component-swap
|
||||
"Swaps a component with another one"
|
||||
(defn- add-component-for-swap
|
||||
[shape file-id id-new-component]
|
||||
(dm/assert! (uuid? id-new-component))
|
||||
(dm/assert! (uuid? file-id))
|
||||
(ptk/reify ::component-swap
|
||||
(ptk/reify ::add-component-for-swap
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [page (wsh/lookup-page state)
|
||||
|
@ -856,12 +855,24 @@
|
|||
|
||||
;; We need to set the same index as the original shape
|
||||
changes (pcb/change-parent changes (:parent-id shape) [new-shape] index {:component-swap true})]
|
||||
|
||||
;; First delete so we don't break the grid layout cells
|
||||
(rx/of (dch/commit-changes changes)
|
||||
(ptk/data-event :layout/update [(:id new-shape)])
|
||||
(dws/select-shape (:id new-shape) true)
|
||||
(dwsh/delete-shapes nil (d/ordered-set (:id shape)) {:component-swap true}))))))
|
||||
|
||||
(dws/select-shape (:id new-shape) true))))))
|
||||
|
||||
(defn- component-swap
|
||||
"Swaps a component with another one"
|
||||
[shape file-id id-new-component]
|
||||
(dm/assert! (uuid? id-new-component))
|
||||
(dm/assert! (uuid? file-id))
|
||||
(ptk/reify ::component-swap
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
;; First delete shapes so we have space in the layout otherwise we can have problems
|
||||
;; in the grid creating new rows/columns to make space
|
||||
(rx/of (dwsh/delete-shapes nil (d/ordered-set (:id shape)) {:component-swap true})
|
||||
(add-component-for-swap shape file-id id-new-component)
|
||||
(ptk/data-event :layout/update [(:parent-id shape)])))))
|
||||
|
||||
(defn component-multi-swap
|
||||
"Swaps several components with another one"
|
||||
|
|
|
@ -213,6 +213,7 @@
|
|||
.component-list-empty {
|
||||
@include titleTipography;
|
||||
margin: 0 $s-4 0 $s-8;
|
||||
color: $df-secondary;
|
||||
}
|
||||
|
||||
.component-list {
|
||||
|
|
Loading…
Add table
Reference in a new issue