mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 08:20:45 -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]
|
[it shapes objects page-id file-id components-v2 prepare-create-group prepare-create-board]
|
||||||
(let [changes (pcb/empty-changes it page-id)
|
(let [changes (pcb/empty-changes it page-id)
|
||||||
|
|
||||||
[root changes]
|
[root changes old-root-ids]
|
||||||
(if (and (= (count shapes) 1)
|
(if (and (= (count shapes) 1)
|
||||||
(or (and (= (:type (first shapes)) :group) (not components-v2))
|
(or (and (= (:type (first shapes)) :group) (not components-v2))
|
||||||
(= (:type (first shapes)) :frame))
|
(= (:type (first shapes)) :frame))
|
||||||
(not (ctk/instance-head? (first shapes))))
|
(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))
|
(let [root-name (if (= 1 (count shapes))
|
||||||
(:name (first shapes))
|
(:name (first shapes))
|
||||||
"Component 1")]
|
"Component 1")
|
||||||
(if-not components-v2
|
|
||||||
(prepare-create-group it ; These functions needs to be passed as argument
|
[root changes] (if-not components-v2
|
||||||
objects ; to avoid a circular dependence
|
(prepare-create-group it ; These functions needs to be passed as argument
|
||||||
page-id
|
objects ; to avoid a circular dependence
|
||||||
shapes
|
page-id
|
||||||
root-name
|
shapes
|
||||||
(not (ctk/instance-head? (first shapes))))
|
root-name
|
||||||
(prepare-create-board changes
|
(not (ctk/instance-head? (first shapes))))
|
||||||
(uuid/next)
|
(prepare-create-board changes
|
||||||
(:parent-id (first shapes))
|
(uuid/next)
|
||||||
objects
|
(:parent-id (first shapes))
|
||||||
(map :id shapes)
|
objects
|
||||||
nil
|
(map :id shapes)
|
||||||
root-name
|
nil
|
||||||
true))))
|
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]))
|
[root (:id root-shape) changes]))
|
||||||
|
|
||||||
(defn duplicate-component
|
(defn duplicate-component
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
(defn is-main-instance-subroot
|
(defn is-main-instance-subroot
|
||||||
[shape]
|
[shape]
|
||||||
(t/is (some? (:component-id shape))) ; shape-ref may or may be not nil
|
(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
|
(defn is-main-instance-child
|
||||||
[shape]
|
[shape]
|
||||||
|
|
Loading…
Reference in a new issue