mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 00:10:11 -05:00
🐛 Remove root when creating nested components
This commit is contained in:
parent
65cc025994
commit
e8aab8b0bf
2 changed files with 34 additions and 21 deletions
|
@ -96,33 +96,46 @@
|
|||
[it shapes objects page-id file-id components-v2 prepare-create-group prepare-create-board]
|
||||
(let [changes (pcb/empty-changes it page-id)
|
||||
|
||||
[root changes]
|
||||
[root changes old-root-ids]
|
||||
(if (and (= (count shapes) 1)
|
||||
(or (and (= (:type (first shapes)) :group) (not components-v2))
|
||||
(= (:type (first shapes)) :frame))
|
||||
(not (ctk/instance-head? (first shapes))))
|
||||
[(first shapes) (-> (pcb/empty-changes it page-id)
|
||||
(pcb/with-objects objects))]
|
||||
|
||||
[(first shapes)
|
||||
(-> (pcb/empty-changes it page-id)
|
||||
(pcb/with-objects objects))
|
||||
(:shapes (first shapes))]
|
||||
|
||||
(let [root-name (if (= 1 (count shapes))
|
||||
(:name (first shapes))
|
||||
"Component 1")]
|
||||
(if-not components-v2
|
||||
(prepare-create-group it ; These functions needs to be passed as argument
|
||||
objects ; to avoid a circular dependence
|
||||
page-id
|
||||
shapes
|
||||
root-name
|
||||
(not (ctk/instance-head? (first shapes))))
|
||||
(prepare-create-board changes
|
||||
(uuid/next)
|
||||
(:parent-id (first shapes))
|
||||
objects
|
||||
(map :id shapes)
|
||||
nil
|
||||
root-name
|
||||
true))))
|
||||
"Component 1")
|
||||
|
||||
[root changes] (if-not components-v2
|
||||
(prepare-create-group it ; These functions needs to be passed as argument
|
||||
objects ; to avoid a circular dependence
|
||||
page-id
|
||||
shapes
|
||||
root-name
|
||||
(not (ctk/instance-head? (first shapes))))
|
||||
(prepare-create-board changes
|
||||
(uuid/next)
|
||||
(:parent-id (first shapes))
|
||||
objects
|
||||
(map :id shapes)
|
||||
nil
|
||||
root-name
|
||||
true))]
|
||||
|
||||
[root changes (map :id shapes)]))
|
||||
|
||||
[root-shape changes] (generate-add-component-changes changes root objects file-id page-id components-v2)
|
||||
|
||||
changes (pcb/update-shapes changes
|
||||
old-root-ids
|
||||
#(dissoc % :component-root)
|
||||
[:component-root])]
|
||||
|
||||
[root-shape changes] (generate-add-component-changes changes root objects file-id page-id components-v2)]
|
||||
[root (:id root-shape) changes]))
|
||||
|
||||
(defn duplicate-component
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
(defn is-main-instance-subroot
|
||||
[shape]
|
||||
(t/is (some? (:component-id shape))) ; shape-ref may or may be not nil
|
||||
(t/is (= (:component-root shape) true)))
|
||||
(t/is (nil? (:component-root shape))))
|
||||
|
||||
(defn is-main-instance-child
|
||||
[shape]
|
||||
|
|
Loading…
Reference in a new issue