From 19379fdd2c82f464812b64442b4506f73692a72e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 3 Nov 2023 11:11:28 +0100 Subject: [PATCH] :bug: Fix component-root when createing new component --- .../app/common/files/libraries_helpers.cljc | 21 +++++++------------ .../src/app/common/files/shapes_helpers.cljc | 3 ++- frontend/src/app/main/data/workspace.cljs | 1 + 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/common/src/app/common/files/libraries_helpers.cljc b/common/src/app/common/files/libraries_helpers.cljc index bdac7d903..8aabda87a 100644 --- a/common/src/app/common/files/libraries_helpers.cljc +++ b/common/src/app/common/files/libraries_helpers.cljc @@ -20,14 +20,7 @@ [root-shape new-shapes updated-shapes] (if-not components-v2 (ctn/make-component-shape root objects file-id components-v2) - (let [new-id (uuid/next)] - [(assoc root :id new-id) - nil - [(assoc root - :component-id new-id - :component-file file-id - :component-root true - :main-instance true)]])) + (ctn/convert-shape-in-component root objects file-id)) changes (-> changes (pcb/add-component (:id root-shape) @@ -39,12 +32,10 @@ page-id))] [root-shape changes])) - (defn generate-add-component - "If there is exactly one id, and it's a frame (or a group in v1), and not already a - component, use it as root. Otherwise, create a frame (v2) or group (v1) that contains - all ids. Then, make a component with it, and link all shapes to their corresponding one - in the component." + "If there is exactly one id, and it's a frame (or a group in v1), and not already a component, + use it as root. Otherwise, create a frame (v2) or group (v1) that contains all ids. Then, make a + component with it, and link all shapes to their corresponding one in the component." [it shapes objects page-id file-id components-v2 prepare-create-group prepare-create-board] (let [changes (pcb/empty-changes it page-id) @@ -81,7 +72,9 @@ [root changes (map :id shapes)])) - [root-shape changes] (generate-add-component-changes changes root objects file-id page-id components-v2) + objects' (assoc objects (:id root) root) + + [root-shape changes] (generate-add-component-changes changes root objects' file-id page-id components-v2) changes (pcb/update-shapes changes old-root-ids diff --git a/common/src/app/common/files/shapes_helpers.cljc b/common/src/app/common/files/shapes_helpers.cljc index 6b4bf2e5e..2b6de6b25 100644 --- a/common/src/app/common/files/shapes_helpers.cljc +++ b/common/src/app/common/files/shapes_helpers.cljc @@ -86,7 +86,8 @@ :always (assoc :frame-id frame-id - :parent-id parent-id) + :parent-id parent-id + :shapes (into [] selected)) :always (with-meta {:index new-index}) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index da98bad08..cf26ed78e 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1604,6 +1604,7 @@ (watch [_ _ _] (try (let [clipboard-str (wapi/read-from-clipboard) + paste-transit-str (->> clipboard-str (rx/filter t/transit?)