mirror of
https://github.com/penpot/penpot.git
synced 2025-05-20 22:06:10 +02: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)
|
second)
|
||||||
0)))))
|
0)))))
|
||||||
|
|
||||||
(defn- component-swap
|
(defn- add-component-for-swap
|
||||||
"Swaps a component with another one"
|
|
||||||
[shape file-id id-new-component]
|
[shape file-id id-new-component]
|
||||||
(dm/assert! (uuid? id-new-component))
|
(dm/assert! (uuid? id-new-component))
|
||||||
(dm/assert! (uuid? file-id))
|
(dm/assert! (uuid? file-id))
|
||||||
(ptk/reify ::component-swap
|
(ptk/reify ::add-component-for-swap
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [page (wsh/lookup-page state)
|
(let [page (wsh/lookup-page state)
|
||||||
|
@ -856,12 +855,24 @@
|
||||||
|
|
||||||
;; We need to set the same index as the original shape
|
;; 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})]
|
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)
|
(rx/of (dch/commit-changes changes)
|
||||||
(ptk/data-event :layout/update [(:id new-shape)])
|
(dws/select-shape (:id new-shape) true))))))
|
||||||
(dws/select-shape (:id new-shape) true)
|
|
||||||
(dwsh/delete-shapes nil (d/ordered-set (:id shape)) {:component-swap 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
|
(defn component-multi-swap
|
||||||
"Swaps several components with another one"
|
"Swaps several components with another one"
|
||||||
|
|
|
@ -213,6 +213,7 @@
|
||||||
.component-list-empty {
|
.component-list-empty {
|
||||||
@include titleTipography;
|
@include titleTipography;
|
||||||
margin: 0 $s-4 0 $s-8;
|
margin: 0 $s-4 0 $s-8;
|
||||||
|
color: $df-secondary;
|
||||||
}
|
}
|
||||||
|
|
||||||
.component-list {
|
.component-list {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue