0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-12 07:41:43 -05:00

🐛 Fix impossible to swap component which is located into board

This commit is contained in:
Pablo Alba 2023-11-20 12:16:52 +01:00 committed by Andrey Antukh
parent 5285e1a4dd
commit a40ddd6959
2 changed files with 12 additions and 2 deletions

View file

@ -817,7 +817,10 @@
id-new-component id-new-component
position position
page page
libraries) libraries
nil
(:parent-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})] changes (pcb/change-parent changes (:parent-id shape) [new-shape] index {:component-swap true})]
(rx/of (dch/commit-changes changes) (rx/of (dch/commit-changes changes)
(ptk/data-event :layout/update [(:id new-shape)]) (ptk/data-event :layout/update [(:id new-shape)])

View file

@ -148,6 +148,7 @@
([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]
(let [component (ctf/get-component libraries file-id component-id) (let [component (ctf/get-component libraries file-id component-id)
parent (when parent-id (get objects parent-id))
library (get libraries file-id) library (get libraries file-id)
components-v2 (dm/get-in library [:data :options :components-v2]) components-v2 (dm/get-in library [:data :options :components-v2])
@ -161,7 +162,13 @@
first-shape (cond-> (first new-shapes) first-shape (cond-> (first new-shapes)
(not (nil? parent-id)) (not (nil? parent-id))
(assoc :parent-id parent-id)) (assoc :parent-id parent-id)
(and (not (nil? parent)) (= :frame (:type parent)))
(assoc :frame-id (:id parent))
(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))
;; on copy/paste old id is used later to reorder the paster layers ;; on copy/paste old id is used later to reorder the paster layers
changes (cond-> (pcb/add-object changes first-shape {:ignore-touched true}) changes (cond-> (pcb/add-object changes first-shape {:ignore-touched true})