♻️ 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 {:type :set
:attr :component-root? :attr :component-root?
:val (:component-root? shape)} :val (:component-root? shape)}
{:type :set
:attr :main-instance?
:val (:main-instance? shape)}
{:type :set {:type :set
:attr :shape-ref :attr :shape-ref
:val (:shape-ref shape)} :val (:shape-ref shape)}

View file

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

View file

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

View file

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

View file

@ -91,10 +91,11 @@
file file
(fn [file-data] (fn [file-data]
(let [[instance-shape instance-shapes] (let [[instance-shape instance-shapes]
(ctn/instantiate-component (ctpl/get-page file-data page-id) (ctn/make-component-instance (ctpl/get-page file-data page-id)
(ctkl/get-component (:data library) component-id) (ctkl/get-component (:data library) component-id)
(:id library) (:id library)
(gpt/point 0 0))] (gpt/point 0 0)
false)]
(swap! idmap assoc label (:id instance-shape)) (swap! idmap assoc label (:id instance-shape))
(-> file-data (-> file-data

View file

@ -106,12 +106,13 @@
[new-instance-shape new-instance-shapes] [new-instance-shape new-instance-shapes]
(ctn/instantiate-component main-instance-page (ctn/make-component-instance main-instance-page
{:id (:id new-component-shape) {:id (:id new-component-shape)
:name (:name new-component-shape) :name (:name new-component-shape)
:objects (d/index-by :id new-component-shapes)} :objects (d/index-by :id new-component-shapes)}
(:component-file main-instance-shape) (:component-file main-instance-shape)
position)] position
false)]
[new-component-shape new-component-shapes [new-component-shape new-component-shapes
new-instance-shape new-instance-shapes])) new-instance-shape new-instance-shapes]))
@ -122,7 +123,7 @@
(let [component (cph/get-component libraries file-id component-id) (let [component (cph/get-component libraries file-id component-id)
[new-shape new-shapes] [new-shape new-shapes]
(ctn/instantiate-component page component file-id position) (ctn/make-component-instance page component file-id position false)
changes (reduce #(pcb/add-object %1 %2 {:ignore-touched true}) changes (reduce #(pcb/add-object %1 %2 {:ignore-touched true})
(pcb/empty-changes it (:id page)) (pcb/empty-changes it (:id page))