mirror of
https://github.com/penpot/penpot.git
synced 2025-06-09 00:31:38 +02:00
🐛 Fix delete page with components
This commit is contained in:
parent
a1c09057c1
commit
65c695e830
3 changed files with 30 additions and 6 deletions
|
@ -478,17 +478,39 @@
|
||||||
(declare purge-page)
|
(declare purge-page)
|
||||||
(declare go-to-file)
|
(declare go-to-file)
|
||||||
|
|
||||||
|
(defn- delete-page-components
|
||||||
|
[changes page]
|
||||||
|
(let [components-to-delete (->> page
|
||||||
|
:objects
|
||||||
|
vals
|
||||||
|
(filter #(true? (:main-instance? %)))
|
||||||
|
(map :component-id))
|
||||||
|
|
||||||
|
changes (reduce (fn [changes component-id]
|
||||||
|
(pcb/delete-component changes component-id))
|
||||||
|
changes
|
||||||
|
components-to-delete)]
|
||||||
|
changes))
|
||||||
|
|
||||||
(defn delete-page
|
(defn delete-page
|
||||||
[id]
|
[id]
|
||||||
(ptk/reify ::delete-page
|
(ptk/reify ::delete-page
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [pages (get-in state [:workspace-data :pages])
|
(let [components-v2 (features/active-feature? state :components-v2)
|
||||||
|
file-id (:current-file-id state)
|
||||||
|
file (wsh/get-file state file-id)
|
||||||
|
pages (get-in state [:workspace-data :pages])
|
||||||
index (d/index-of pages id)
|
index (d/index-of pages id)
|
||||||
page (get-in state [:workspace-data :pages-index id])
|
page (get-in state [:workspace-data :pages-index id])
|
||||||
page (assoc page :index index)
|
page (assoc page :index index)
|
||||||
|
|
||||||
changes (-> (pcb/empty-changes it)
|
changes (cond-> (pcb/empty-changes it)
|
||||||
|
components-v2
|
||||||
|
(pcb/with-library-data file)
|
||||||
|
components-v2
|
||||||
|
(delete-page-components page)
|
||||||
|
:always
|
||||||
(pcb/del-page page))]
|
(pcb/del-page page))]
|
||||||
|
|
||||||
(rx/of (dch/commit-changes changes)
|
(rx/of (dch/commit-changes changes)
|
||||||
|
|
|
@ -435,9 +435,10 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
|
current-page (dm/get-in state [:workspace-data :pages-index page-id])
|
||||||
objects (wsh/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
library-data (wsh/get-file state library-id)
|
library-data (wsh/get-file state library-id)
|
||||||
{:keys [changes shape]} (dwlh/prepare-restore-component library-data component-id it)
|
{:keys [changes shape]} (dwlh/prepare-restore-component library-data component-id current-page it)
|
||||||
parent-id (:parent-id shape)
|
parent-id (:parent-id shape)
|
||||||
objects (cond-> (assoc objects (:id shape) shape)
|
objects (cond-> (assoc objects (:id shape) shape)
|
||||||
(not (nil? parent-id))
|
(not (nil? parent-id))
|
||||||
|
|
|
@ -213,9 +213,10 @@
|
||||||
children-ids)))))
|
children-ids)))))
|
||||||
|
|
||||||
(defn prepare-restore-component
|
(defn prepare-restore-component
|
||||||
([library-data component-id it]
|
([library-data component-id current-page it]
|
||||||
(let [component (ctkl/get-deleted-component library-data component-id)
|
(let [component (ctkl/get-deleted-component library-data component-id)
|
||||||
page (ctf/get-component-page library-data component)]
|
page (or (ctf/get-component-page library-data component)
|
||||||
|
current-page)]
|
||||||
(prepare-restore-component nil library-data component-id it page (gpt/point 0 0) nil nil)))
|
(prepare-restore-component nil library-data component-id it page (gpt/point 0 0) nil nil)))
|
||||||
|
|
||||||
([changes library-data component-id it page delta old-id parent-id]
|
([changes library-data component-id it page delta old-id parent-id]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue