mirror of
https://github.com/penpot/penpot.git
synced 2025-06-08 13:52:57 +02:00
🐛 Fix problem with swap component
This commit is contained in:
parent
b7b7b9d580
commit
9e40b4551d
3 changed files with 19 additions and 9 deletions
|
@ -20,6 +20,7 @@
|
||||||
[app.common.types.components-list :as ctkl]
|
[app.common.types.components-list :as ctkl]
|
||||||
[app.common.types.container :as ctn]
|
[app.common.types.container :as ctn]
|
||||||
[app.common.types.file :as ctf]
|
[app.common.types.file :as ctf]
|
||||||
|
[app.common.types.shape.layout :as ctl]
|
||||||
[app.common.types.typography :as ctt]
|
[app.common.types.typography :as ctt]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.events :as ev]
|
[app.main.data.events :as ev]
|
||||||
|
@ -826,7 +827,7 @@
|
||||||
0)))))
|
0)))))
|
||||||
|
|
||||||
(defn- add-component-for-swap
|
(defn- add-component-for-swap
|
||||||
[shape file-id id-new-component]
|
[shape file-id id-new-component target-cell]
|
||||||
(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
|
||||||
|
@ -840,6 +841,7 @@
|
||||||
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/with-objects objects))
|
(pcb/with-objects objects))
|
||||||
|
position (-> position (with-meta {:cell target-cell}))
|
||||||
|
|
||||||
[new-shape changes]
|
[new-shape changes]
|
||||||
(dwlh/generate-instantiate-component changes
|
(dwlh/generate-instantiate-component changes
|
||||||
|
@ -867,12 +869,18 @@
|
||||||
(dm/assert! (uuid? file-id))
|
(dm/assert! (uuid? file-id))
|
||||||
(ptk/reify ::component-swap
|
(ptk/reify ::component-swap
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ state _]
|
||||||
;; First delete shapes so we have space in the layout otherwise we can have problems
|
;; 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
|
;; in the grid creating new rows/columns to make space
|
||||||
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
|
parent (get objects (:parent-id shape))
|
||||||
|
|
||||||
|
;; If the target parent is a grid layout we need to pass the target cell
|
||||||
|
target-cell (when (ctl/grid-layout? parent)
|
||||||
|
(ctl/get-cell-by-shape-id parent (:id shape)))]
|
||||||
(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)
|
(add-component-for-swap shape file-id id-new-component target-cell)
|
||||||
(ptk/data-event :layout/update [(:parent-id shape)])))))
|
(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"
|
||||||
|
|
|
@ -177,7 +177,11 @@
|
||||||
|
|
||||||
changes
|
changes
|
||||||
(if (ctl/grid-layout? objects (:parent-id first-shape))
|
(if (ctl/grid-layout? objects (:parent-id first-shape))
|
||||||
(let [[row column] (gslg/get-drop-cell (:parent-id first-shape) objects position)]
|
(let [target-cell (-> position meta :cell)
|
||||||
|
[row column]
|
||||||
|
(if (some? target-cell)
|
||||||
|
[(:row target-cell) (:column target-cell)]
|
||||||
|
(gslg/get-drop-cell (:parent-id first-shape) objects position))]
|
||||||
(-> changes
|
(-> changes
|
||||||
(pcb/update-shapes
|
(pcb/update-shapes
|
||||||
[(:parent-id first-shape)]
|
[(:parent-id first-shape)]
|
||||||
|
|
|
@ -55,9 +55,7 @@
|
||||||
(mf/use-fn #(st/emit! (dw/toggle-layout-flag :collapse-left-sidebar)))
|
(mf/use-fn #(st/emit! (dw/toggle-layout-flag :collapse-left-sidebar)))
|
||||||
|
|
||||||
on-tab-change
|
on-tab-change
|
||||||
(mf/use-fn #(do
|
(mf/use-fn #(st/emit! (dw/go-to-layout %)))]
|
||||||
(prn "on-tab-change" %)
|
|
||||||
(st/emit! (dw/go-to-layout %))))]
|
|
||||||
|
|
||||||
[:aside {:ref parent-ref
|
[:aside {:ref parent-ref
|
||||||
:id "left-sidebar-aside"
|
:id "left-sidebar-aside"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue