From b5af51b751cf33e39e4ade68c743a9594289a0b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Thu, 23 Nov 2023 10:29:48 +0100 Subject: [PATCH 1/3] :bug: Fix propagation when adding a shape to a component --- common/src/app/common/files/changes.cljc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 1c5d01e6ef..9df8792aca 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -770,6 +770,16 @@ (check-shape parent-id [parent-id]) shapes)))) +(defmethod components-changed :add-obj + [file-data {:keys [parent-id page-id _component-id] :as change}] + (when page-id + (let [page (ctpl/get-page file-data page-id) + parents (map (partial ctn/get-shape page) + (cons parent-id (cfh/get-parent-ids (:objects page) parent-id))) + xform (comp (filter :main-instance) + (map :component-id))] + (into #{} xform parents)))) + (defmethod components-changed :del-obj [file-data {:keys [id page-id _component-id] :as change}] (when page-id From 51e50ac301a10e249a1d6c257d4c14f1b6026ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Thu, 23 Nov 2023 11:25:14 +0100 Subject: [PATCH 2/3] :bug: Fix validation when pasting a copy into a component --- .../app/main/data/workspace/selection.cljs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index 1055985030..ee774bbd82 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -17,6 +17,7 @@ [app.common.geom.shapes :as gsh] [app.common.record :as cr] [app.common.types.component :as ctk] + [app.common.types.container :as ctn] [app.common.types.file :as ctf] [app.common.types.page :as ctp] [app.common.types.shape.interactions :as ctsi] @@ -428,14 +429,18 @@ bool? (cfh/bool-shape? obj) new-id (ids-map (:id obj)) parent-id (or parent-id frame-id) + parent (get objects parent-id) name (:name obj) - is-component-root? (or (:saved-component-root obj) - ;; Backward compatibility - (:saved-component-root? obj) - (ctk/instance-root? obj)) + is-component-root? (or (:saved-component-root obj) + ;; Backward compatibility + (:saved-component-root? obj) + (ctk/instance-root? obj)) duplicating-component? (or duplicating-component? (ctk/instance-head? obj)) - is-component-main? (ctk/main-instance? obj) + is-component-main? (ctk/main-instance? obj) + into-component? (and duplicating-component? + (ctn/in-any-component? objects parent)) + regenerate-component (fn [changes shape] (let [components-v2 (dm/get-in library-data [:options :components-v2]) @@ -453,8 +458,10 @@ :main-instance :use-for-thumbnail) - (cond-> - (or frame? group? bool?) + (cond-> into-component? + (dissoc :component-root)) + + (cond-> (or frame? group? bool?) (assoc :shapes [])) (gsh/move delta) From 8d5af748dab4996bd7cf721232749f0923b2f474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Wed, 22 Nov 2023 16:14:50 +0100 Subject: [PATCH 3/3] :bug: Fix creation of a copy inside a board --- common/src/app/common/types/container.cljc | 5 +--- common/src/app/common/types/shape_tree.cljc | 29 ++++++++++--------- .../data/workspace/libraries_helpers.cljs | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index e99eb6d5d8..9669fc9e1f 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -345,13 +345,10 @@ 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. - ;; Also fix empty parent-id. + ;; Fix empty parent-id and remap all grid cells to the new ids. remap-ids (fn [shape] (as-> shape $ - (update $ :frame-id #(get @ids-map % frame-id)) (update $ :parent-id #(or % (:frame-id $))) (cond-> $ (ctl/grid-layout? shape) diff --git a/common/src/app/common/types/shape_tree.cljc b/common/src/app/common/types/shape_tree.cljc index e8a63044b8..3f66428743 100644 --- a/common/src/app/common/types/shape_tree.cljc +++ b/common/src/app/common/types/shape_tree.cljc @@ -354,21 +354,21 @@ the order of the children of each parent." ([object parent-id objects] - (clone-object object parent-id objects (fn [object _] object) (fn [object _] object) nil false true)) + (clone-object object parent-id objects (fn [object _] object) (fn [object _] object) nil false nil)) ([object parent-id objects update-new-object] - (clone-object object parent-id objects update-new-object (fn [object _] object) nil false true)) + (clone-object object parent-id objects update-new-object (fn [object _] object) nil false nil)) ([object parent-id objects update-new-object update-original-object] - (clone-object object parent-id objects update-new-object update-original-object nil false true)) + (clone-object object parent-id objects update-new-object update-original-object nil false nil)) ([object parent-id objects update-new-object update-original-object force-id] - (clone-object object parent-id objects update-new-object update-original-object force-id false true)) + (clone-object object parent-id objects update-new-object update-original-object force-id false nil)) ([object parent-id objects update-new-object update-original-object force-id keep-ids?] - (clone-object object parent-id objects update-new-object update-original-object force-id keep-ids? true)) + (clone-object object parent-id objects update-new-object update-original-object force-id keep-ids? nil)) - ([object parent-id objects update-new-object update-original-object force-id keep-ids? calc-frame?] + ([object parent-id objects update-new-object update-original-object force-id keep-ids? frame-id] (let [new-id (cond (some? force-id) force-id keep-ids? (:id object) @@ -378,14 +378,14 @@ ;; or the parent's frame-id otherwise. Only for the first cloned shapes. In recursive calls ;; this is not needed. frame-id (cond - (and calc-frame? (cfh/frame-shape? objects parent-id)) + (and (nil? frame-id) (cfh/frame-shape? objects parent-id)) parent-id - calc-frame? + (nil? frame-id) (dm/get-in objects [parent-id :frame-id]) :else - (:frame-id object))] + frame-id)] (loop [child-ids (seq (:shapes object)) new-direct-children [] @@ -412,12 +412,15 @@ [new-object new-objects updated-objects]) - (let [child-id (first child-ids) - child (get objects child-id) - _ (dm/assert! (some? child)) + (let [child-id (first child-ids) + child (get objects child-id) + _ (dm/assert! (some? child)) + frame-id-child (if (cfh/frame-shape? object) + new-id + (:frame-id object)) [new-child new-child-objects updated-child-objects] - (clone-object child new-id objects update-new-object update-original-object nil keep-ids? false)] + (clone-object child new-id objects update-new-object update-original-object nil keep-ids? frame-id-child)] (recur (next child-ids) diff --git a/frontend/src/app/main/data/workspace/libraries_helpers.cljs b/frontend/src/app/main/data/workspace/libraries_helpers.cljs index b7aaa379e6..ecb34649e7 100644 --- a/frontend/src/app/main/data/workspace/libraries_helpers.cljs +++ b/frontend/src/app/main/data/workspace/libraries_helpers.cljs @@ -904,7 +904,7 @@ root-main root-instance)] (cond-> new-shape - :always + (= (:id original-shape) (:id component-shape)) (assoc :frame-id (if (= (:type parent-shape) :frame) (:id parent-shape) (:frame-id parent-shape)))