0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 00:40:30 -05:00

🐛 Fix internal error when duplicating board which contains components

This commit is contained in:
Alejandro Alonso 2023-11-20 09:55:05 +01:00 committed by Andrés Moya
parent 016ead108d
commit c10b8c81fd
3 changed files with 12 additions and 7 deletions

View file

@ -819,7 +819,9 @@
page
libraries
nil
(:parent-id shape))
(:parent-id shape)
(:frame-id 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})]
(rx/of (dch/commit-changes changes)

View file

@ -144,9 +144,9 @@
(defn generate-instantiate-component
"Generate changes to create a new instance from a component."
([changes objects file-id component-id position page libraries]
(generate-instantiate-component changes objects file-id component-id position page libraries nil nil))
(generate-instantiate-component changes objects file-id component-id position page libraries nil nil nil))
([changes objects file-id component-id position page libraries old-id parent-id]
([changes objects file-id component-id position page libraries old-id parent-id frame-id]
(let [component (ctf/get-component libraries file-id component-id)
parent (when parent-id (get objects parent-id))
library (get libraries file-id)
@ -168,7 +168,9 @@
(and (not (nil? parent)) (not= :frame (:type parent)))
(assoc :frame-id (:frame-id parent))
(and (not (nil? parent)) (ctn/in-any-component? objects parent))
(dissoc :component-root))
(dissoc :component-root)
(and (nil? parent) (not (nil? frame-id)))
(assoc :frame-id frame-id))
;; on copy/paste old id is used later to reorder the paster layers
changes (cond-> (pcb/add-object changes first-shape {:ignore-touched true})

View file

@ -380,7 +380,7 @@
(prepare-duplicate-guides shapes page ids-map delta)))))
(defn- prepare-duplicate-component-change
[changes objects page component-root parent-id delta libraries library-data it]
[changes objects page component-root parent-id frame-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)
@ -396,7 +396,8 @@
page
libraries
(:id component-root)
parent-id)
parent-id
frame-id)
restore-component
#(let [restore (dwlh/prepare-restore-component changes library-data (:component-id component-root) it page delta (:id component-root) parent-id)]
@ -419,7 +420,7 @@
changes
(ctf/is-known-component? obj libraries)
(prepare-duplicate-component-change changes objects page obj parent-id delta libraries library-data it)
(prepare-duplicate-component-change changes objects page obj parent-id frame-id delta libraries library-data it)
:else
(let [frame? (cfh/frame-shape? obj)