♻️ Use main-instance? attribute

This commit is contained in:
Andrés Moya
2022-07-08 12:09:28 +02:00
parent dcf18b3aee
commit eebd596fca
6 changed files with 33 additions and 22 deletions

View File

@@ -564,6 +564,9 @@
{:type :set
:attr :component-root?
:val (:component-root? shape)}
{:type :set
:attr :main-instance?
:val (:main-instance? shape)}
{:type :set
:attr :shape-ref
:val (:shape-ref shape)}

View File

@@ -455,10 +455,11 @@
(let [page (ctpl/get-page data page-id)
[new-shape new-shapes]
(ctn/instantiate-component page
component
(:id data)
position)
(ctn/make-component-instance page
component
(:id data)
position
true)
add-shapes
(fn [page]

View File

@@ -94,15 +94,16 @@
(nil? (:parent-id new-shape))
(assoc :component-id (:id new-shape)
:component-file file-id
:component-root? true)
:component-root? true
:main-instance? true)
(some? (:parent-id new-shape))
(dissoc :component-root?)))]
(ctst/clone-object shape nil objects update-new-shape update-original-shape)))
(defn instantiate-component
[container component component-file-id position]
(defn make-component-instance
[container component component-file-id position main-instance?]
(let [component-shape (get-shape component (:id component))
orig-pos (gpt/point (:x component-shape) (:y component-shape))
@@ -138,6 +139,9 @@
:component-root? true
:name new-name)
(and (nil? (:parent-id original-shape)) main-instance?)
(assoc :main-instance? true)
(some? (:parent-id original-shape))
(dissoc :component-root?))))

View File

@@ -194,10 +194,11 @@
; Make a new main instance for the component
[main-instance-shape main-instance-shapes]
(ctn/instantiate-component page
component
(:id file-data)
position)
(ctn/make-component-instance page
component
(:id file-data)
position
true)
; Add all shapes of the main instance to the library page
add-main-instance-shapes