0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 06:32:38 -05:00

🐛 Fix validation error detaching copy inside main

This commit is contained in:
Pablo Alba 2023-12-05 23:50:01 +01:00 committed by Andrey Antukh
parent fd43091d3a
commit cc9e517720

View file

@ -201,18 +201,23 @@
"Generate changes to remove the links between a shape and all its children
with a component."
[changes container shape-id]
(log/debug :msg "Detach instance" :shape-id shape-id :container (:id container))
(generate-detach-recursive changes container shape-id true))
(let [shape (ctn/get-shape container shape-id)]
(log/debug :msg "Detach instance" :shape-id shape-id :container (:id container))
(generate-detach-recursive changes container shape-id true (true? (:component-root shape)))))
(defn- generate-detach-recursive
[changes container shape-id first]
[changes container shape-id first component-root?]
(let [shape (ctn/get-shape container shape-id)]
(if (and (ctk/instance-head? shape) (not first))
;; Subinstances are not detached, but converted in top instances
(pcb/update-shapes changes [(:id shape)] #(assoc % :component-root true))
;; Subinstances are not detached
(if component-root?
;; if the original shape was component-root, the subinstances are converted in top instances
(pcb/update-shapes changes [(:id shape)] #(assoc % :component-root true))
changes)
;; Otherwise, detach the shape and all children
(let [children-ids (:shapes shape)]
(reduce #(generate-detach-recursive %1 container %2 false)
(reduce #(generate-detach-recursive %1 container %2 false component-root?)
(pcb/update-shapes changes [(:id shape)] ctk/detach-shape)
children-ids)))))