mirror of
https://github.com/penpot/penpot.git
synced 2025-02-10 17:18:21 -05:00
Fix restore and instanciate (in copy and paste) components with parent
This commit is contained in:
parent
4f471f39da
commit
a7015f2517
2 changed files with 18 additions and 10 deletions
|
@ -163,9 +163,9 @@
|
|||
(defn generate-instantiate-component
|
||||
"Generate changes to create a new instance from a component."
|
||||
([changes file-id component-id position page libraries]
|
||||
(generate-instantiate-component changes file-id component-id position page libraries nil))
|
||||
(generate-instantiate-component changes file-id component-id position page libraries nil nil))
|
||||
|
||||
([changes file-id component-id position page libraries old-id]
|
||||
([changes file-id component-id position page libraries old-id parent-id]
|
||||
(let [component (ctf/get-component libraries file-id component-id)
|
||||
library (get libraries file-id)
|
||||
|
||||
|
@ -178,7 +178,11 @@
|
|||
position
|
||||
components-v2)
|
||||
|
||||
changes (cond-> (pcb/add-object changes (first new-shapes) {:ignore-touched true})
|
||||
first-shape (cond-> (first new-shapes)
|
||||
(not (nil? parent-id))
|
||||
(assoc :parent-id parent-id))
|
||||
|
||||
changes (cond-> (pcb/add-object changes first-shape {:ignore-touched true})
|
||||
(some? old-id) (pcb/amend-last-change #(assoc % :old-id old-id))) ; on copy/paste old id is used later to reorder the paster layers
|
||||
|
||||
changes (reduce #(pcb/add-object %1 %2 {:ignore-touched true})
|
||||
|
@ -212,17 +216,20 @@
|
|||
([library-data component-id it]
|
||||
(let [component (ctkl/get-deleted-component library-data component-id)
|
||||
page (ctf/get-component-page library-data component)]
|
||||
(prepare-restore-component 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)))
|
||||
|
||||
([library-data component-id it page delta old-id changes]
|
||||
([changes library-data component-id it page delta old-id parent-id]
|
||||
(let [component (ctkl/get-deleted-component library-data component-id)
|
||||
|
||||
shapes (cph/get-children-with-self (:objects component) (:main-instance-id component))
|
||||
shapes (map #(gsh/move % delta) shapes)
|
||||
first-shape (cond-> (first shapes)
|
||||
(not (nil? parent-id))
|
||||
(assoc :parent-id parent-id))
|
||||
changes (-> (or changes (pcb/empty-changes it))
|
||||
(pcb/with-page page)
|
||||
(pcb/with-library-data library-data))
|
||||
changes (cond-> (pcb/add-object changes (first shapes) {:ignore-touched true})
|
||||
changes (cond-> (pcb/add-object changes first-shape {:ignore-touched true})
|
||||
(some? old-id) (pcb/amend-last-change #(assoc % :old-id old-id))) ; on copy/paste old id is used later to reorder the paster layers
|
||||
changes (reduce #(pcb/add-object %1 %2 {:ignore-touched true})
|
||||
changes
|
||||
|
|
|
@ -368,7 +368,7 @@
|
|||
(prepare-duplicate-guides shapes page ids-map delta)))))
|
||||
|
||||
(defn- prepare-duplicate-component-change
|
||||
[changes page component-root delta libraries library-data it]
|
||||
[changes page component-root parent-id delta libraries library-data it]
|
||||
(let [component-id (:component-id component-root)
|
||||
file-id (:component-file component-root)
|
||||
main-component (ctf/get-component libraries file-id component-id)
|
||||
|
@ -382,10 +382,11 @@
|
|||
pos
|
||||
page
|
||||
libraries
|
||||
(:id component-root))
|
||||
(:id component-root)
|
||||
parent-id)
|
||||
|
||||
restore-component
|
||||
#(let [restore (dwlh/prepare-restore-component library-data (:component-id component-root) it page delta (:id component-root) changes)]
|
||||
#(let [restore (dwlh/prepare-restore-component changes library-data (:component-id component-root) it page delta (:id component-root) parent-id)]
|
||||
[(:shape restore) (:changes restore)])
|
||||
|
||||
[_shape changes]
|
||||
|
@ -404,7 +405,7 @@
|
|||
changes
|
||||
|
||||
(ctf/is-known-component? obj libraries)
|
||||
(prepare-duplicate-component-change changes page obj delta libraries library-data it)
|
||||
(prepare-duplicate-component-change changes page obj parent-id delta libraries library-data it)
|
||||
|
||||
:else
|
||||
(let [frame? (cph/frame-shape? obj)
|
||||
|
|
Loading…
Add table
Reference in a new issue