From 968dcefc284a673e8027c67af6218fc498882380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Tue, 23 May 2023 16:46:33 +0200 Subject: [PATCH] :bug: Maintain ids of main shapes to keep existing copies in sync --- common/src/app/common/types/container.cljc | 7 ++++--- common/src/app/common/types/file.cljc | 3 ++- common/src/app/common/types/shape_tree.cljc | 14 ++++++++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index f61756da5..da5e527d2 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -173,8 +173,8 @@ (make-component-instance container component library-data position components-v2 {})) ([container component library-data position components-v2 - {:keys [main-instance? force-id force-frame-id] - :or {main-instance? false force-id nil force-frame-id nil}}] + {:keys [main-instance? force-id force-frame-id keep-ids?] + :or {main-instance? false force-id nil force-frame-id nil keep-ids? false}}] (let [component-page (when components-v2 (ctpl/get-page library-data (:main-instance-page component))) component-shape (if components-v2 @@ -237,7 +237,8 @@ (if components-v2 (:objects component-page) (:objects component)) update-new-shape (fn [object _] object) - force-id) + force-id + keep-ids?) ;; If frame-id points to a shape inside the component, remap it to the ;; corresponding new frame shape. If not, set it to the destination frame. diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index 4ca0da824..22d2a7bda 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -347,7 +347,8 @@ position false {:main-instance? true - :force-frame-id uuid/zero}) + :force-frame-id uuid/zero + :keep-ids? true}) add-shapes (fn [page] diff --git a/common/src/app/common/types/shape_tree.cljc b/common/src/app/common/types/shape_tree.cljc index 9b10e3b03..d0b911c06 100644 --- a/common/src/app/common/types/shape_tree.cljc +++ b/common/src/app/common/types/shape_tree.cljc @@ -329,13 +329,19 @@ the order of the children of each parent." ([object parent-id objects update-new-object] - (clone-object object parent-id objects update-new-object (fn [object _] object) nil)) + (clone-object object parent-id objects update-new-object (fn [object _] object) nil false)) ([object parent-id objects update-new-object update-original-object] - (clone-object object parent-id objects update-new-object update-original-object nil)) + (clone-object object parent-id objects update-new-object update-original-object nil false)) ([object parent-id objects update-new-object update-original-object force-id] - (let [new-id (or force-id (uuid/next))] + (clone-object object parent-id objects update-new-object update-original-object force-id false)) + + ([object parent-id objects update-new-object update-original-object force-id keep-ids?] + (let [new-id (cond + (some? force-id) force-id + keep-ids? (:id object) + :else (uuid/next))] (loop [child-ids (seq (:shapes object)) new-direct-children [] new-children [] @@ -365,7 +371,7 @@ _ (dm/assert! (some? child)) [new-child new-child-objects updated-child-objects] - (clone-object child new-id objects update-new-object update-original-object)] + (clone-object child new-id objects update-new-object update-original-object nil keep-ids?)] (recur (next child-ids)