diff --git a/common/src/app/common/pages/changes_builder.cljc b/common/src/app/common/pages/changes_builder.cljc index 03b8e1ca4..3652bed1c 100644 --- a/common/src/app/common/pages/changes_builder.cljc +++ b/common/src/app/common/pages/changes_builder.cljc @@ -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)} diff --git a/common/src/app/common/pages/migrations.cljc b/common/src/app/common/pages/migrations.cljc index c9f288168..d7cb9a863 100644 --- a/common/src/app/common/pages/migrations.cljc +++ b/common/src/app/common/pages/migrations.cljc @@ -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] diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index 266aac703..a0f63f0f1 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -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?)))) diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index c6015374a..fb51d9fb7 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -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 diff --git a/common/test/app/common/test_helpers/files.cljc b/common/test/app/common/test_helpers/files.cljc index d6728d368..d6b684d25 100644 --- a/common/test/app/common/test_helpers/files.cljc +++ b/common/test/app/common/test_helpers/files.cljc @@ -91,10 +91,11 @@ file (fn [file-data] (let [[instance-shape instance-shapes] - (ctn/instantiate-component (ctpl/get-page file-data page-id) - (ctkl/get-component (:data library) component-id) - (:id library) - (gpt/point 0 0))] + (ctn/make-component-instance (ctpl/get-page file-data page-id) + (ctkl/get-component (:data library) component-id) + (:id library) + (gpt/point 0 0) + false)] (swap! idmap assoc label (:id instance-shape)) (-> file-data diff --git a/frontend/src/app/main/data/workspace/libraries_helpers.cljs b/frontend/src/app/main/data/workspace/libraries_helpers.cljs index 4103e8137..41a29f64e 100644 --- a/frontend/src/app/main/data/workspace/libraries_helpers.cljs +++ b/frontend/src/app/main/data/workspace/libraries_helpers.cljs @@ -106,12 +106,13 @@ [new-instance-shape new-instance-shapes] - (ctn/instantiate-component main-instance-page - {:id (:id new-component-shape) - :name (:name new-component-shape) - :objects (d/index-by :id new-component-shapes)} - (:component-file main-instance-shape) - position)] + (ctn/make-component-instance main-instance-page + {:id (:id new-component-shape) + :name (:name new-component-shape) + :objects (d/index-by :id new-component-shapes)} + (:component-file main-instance-shape) + position + false)] [new-component-shape new-component-shapes new-instance-shape new-instance-shapes])) @@ -122,7 +123,7 @@ (let [component (cph/get-component libraries file-id component-id) [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}) (pcb/empty-changes it (:id page))