mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 02:28:18 -05:00
bug: Fix component-root in nested instances when creating new component
This commit is contained in:
parent
146cd56ba5
commit
c69cc9d298
2 changed files with 18 additions and 8 deletions
|
@ -192,6 +192,23 @@
|
|||
(ctk/instance-head? shape)
|
||||
(inside-component-main? objects shape)))
|
||||
|
||||
(defn convert-shape-in-component
|
||||
"Set the shape as a main root instance, pointing to a new component.
|
||||
Also remove component-root of all children. Return the same structure
|
||||
as make-component-shape."
|
||||
[root objects file-id]
|
||||
(let [new-id (uuid/next)
|
||||
new-root (assoc root
|
||||
:component-id new-id
|
||||
:component-file file-id
|
||||
:component-root true
|
||||
:main-instance true)
|
||||
new-children (->> (cph/get-children objects (:id root))
|
||||
(map #(dissoc % :component-root)))]
|
||||
[(assoc new-root :id new-id)
|
||||
nil
|
||||
(into [new-root] new-children)]))
|
||||
|
||||
(defn make-component-shape
|
||||
"Clone the shape and all children. Generate new ids and detach
|
||||
from parent and frame. Update the original shapes to have links
|
||||
|
|
|
@ -70,14 +70,7 @@
|
|||
[root-shape new-shapes updated-shapes]
|
||||
(if-not components-v2
|
||||
(ctn/make-component-shape root objects file-id components-v2)
|
||||
(let [new-id (uuid/next)]
|
||||
[(assoc root :id new-id)
|
||||
nil
|
||||
[(assoc root
|
||||
:component-id new-id
|
||||
:component-file file-id
|
||||
:component-root true
|
||||
:main-instance true)]]))
|
||||
(ctn/convert-shape-in-component root objects file-id))
|
||||
|
||||
changes (-> changes
|
||||
(pcb/add-component (:id root-shape)
|
||||
|
|
Loading…
Add table
Reference in a new issue