diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index 676db6dc7..a060fe634 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -215,6 +215,15 @@ (some find-ref-shape-in-head (ctn/get-parent-heads (:objects container) shape)))) +(defn find-original-ref-shape + "Recursively call to find-ref-shape until find the original shape of the original component" + [file container libraries shape & options] + (let [ref-shape (find-ref-shape file container libraries shape options)] + (if (nil? (:shape-ref ref-shape)) + ref-shape + (find-original-ref-shape file container libraries ref-shape options)))) + + (defn find-ref-component "Locate the nearest component in the local file or libraries that is referenced by the instance shape." @@ -303,7 +312,7 @@ (vals (:objects component))))) ;; Return true if the object is a component that exists on the file or its libraries (even a deleted one) -(defn is-known-component? +(defn is-main-of-known-component? [shape libraries] (let [main-instance? (ctk/main-instance? shape) component-id (:component-id shape) diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index 15d3d5ab4..7f4cc84ca 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -466,7 +466,7 @@ (nil? obj) changes - (ctf/is-known-component? obj libraries) + (ctf/is-main-of-known-component? obj libraries) (prepare-duplicate-component-change changes objects page obj parent-id frame-id delta libraries library-data it) :else @@ -484,6 +484,9 @@ (ctk/instance-root? obj)) duplicating-component? (or duplicating-component? (ctk/instance-head? obj)) is-component-main? (ctk/main-instance? obj) + + original-ref-shape (-> (ctf/find-original-ref-shape nil page libraries obj {:include-deleted? true}) + :id) into-component? (and duplicating-component? (ctn/in-any-component? objects parent)) @@ -514,6 +517,10 @@ (cond-> (or frame? group? bool?) (assoc :shapes [])) + (cond-> (and (some? original-ref-shape) + (not= original-ref-shape (:shape-ref obj))) + (assoc :shape-ref original-ref-shape)) + (gsh/move delta) (d/update-when :interactions #(ctsi/remap-interactions % ids-map objects))