From cfec023585758f5a5ef6944bdfb0d31355ebed5d Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Mon, 7 Jul 2025 11:05:10 +0200 Subject: [PATCH] :recycle: Rename flag :component-swap to :allow-altering-copies --- common/src/app/common/files/changes.cljc | 6 +++--- common/src/app/common/files/changes_builder.cljc | 8 ++++---- common/src/app/common/files/repair.cljc | 4 ++-- common/src/app/common/logic/libraries.cljc | 8 ++++---- common/src/app/common/logic/shapes.cljc | 12 +++++++----- common/src/app/common/logic/variants.cljc | 6 +++--- frontend/src/app/main/data/workspace/shapes.cljs | 2 +- 7 files changed, 24 insertions(+), 22 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 278f4eb15a..d9965ce556 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -241,7 +241,7 @@ [:shapes ::sm/any] [:index {:optional true} [:maybe :int]] [:after-shape {:optional true} ::sm/any] - [:component-swap {:optional true} :boolean]]] + [:allow-altering-copies {:optional true} :boolean]]] [:reorder-children [:map {:title "ReorderChildrenChange"} @@ -761,7 +761,7 @@ (d/update-in-when data [:components component-id :objects] reg-objects)))) (defmethod process-change :mov-objects - [data {:keys [parent-id shapes index page-id component-id ignore-touched after-shape component-swap syncing]}] + [data {:keys [parent-id shapes index page-id component-id ignore-touched after-shape allow-altering-copies syncing]}] (letfn [(calculate-invalid-targets [objects shape-id] (let [reduce-fn #(into %1 (calculate-invalid-targets objects %2))] (->> (get-in objects [shape-id :shapes]) @@ -776,7 +776,7 @@ (and shape (not (invalid-targets parent-id)) (not (cfh/components-nesting-loop? objects shape-id parent-id)) - (or component-swap ;; On a component swap it's allowed to change the structure of a copy + (or allow-altering-copies ;; In some cases (like a component swap) it's allowed to change the structure of a copy syncing ;; If we are syncing the changes of a main component, it's allowed to change the structure of a copy (and (not (ctk/in-component-copy? (get objects (:parent-id shape)))) ;; We don't want to change the structure of component copies diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index 5cf97c7a62..35f95a78fe 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -464,8 +464,8 @@ (some? index) (assoc :index index) - (:component-swap options) - (assoc :component-swap true) + (:allow-altering-copies options) + (assoc :allow-altering-copies true) (:ignore-touched options) (assoc :ignore-touched true)) @@ -479,8 +479,8 @@ :shapes [(:id shape)] :after-shape prev-sibling :index 0} ; index is used in case there is no after-shape (moving bottom shapes) - (:component-swap options) - (assoc :component-swap true))))) + (:allow-altering-copies options) + (assoc :allow-altering-copies true))))) restore-touched-change {:type :mod-obj diff --git a/common/src/app/common/files/repair.cljc b/common/src/app/common/files/repair.cljc index d75b1aea46..1d638586ee 100644 --- a/common/src/app/common/files/repair.cljc +++ b/common/src/app/common/files/repair.cljc @@ -96,7 +96,7 @@ (log/dbg :hint "repairing shape :invalid-parent" :id (:id shape) :name (:name shape) :page-id page-id) (-> (pcb/empty-changes nil page-id) (pcb/with-file-data file-data) - (pcb/change-parent (:parent-id args) [shape] nil {:component-swap true}))) + (pcb/change-parent (:parent-id args) [shape] nil {:allow-altering-copies true}))) (defmethod repair-error :frame-not-found [_ {:keys [shape page-id] :as error} file-data _] @@ -387,7 +387,7 @@ (-> (pcb/empty-changes nil page-id) (pcb/with-file-data file-data) (pcb/update-shapes [(:id shape)] repair-shape) - (pcb/change-parent uuid/zero [shape] nil {:component-swap true})))) + (pcb/change-parent uuid/zero [shape] nil {:allow-altering-copies true})))) (defmethod repair-error :root-copy-not-allowed [_ {:keys [shape page-id] :as error} file-data _] diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 582b8ab4cf..b7264b7639 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -2249,7 +2249,7 @@ (pcb/update-shapes [(:id new-shape)] #(d/patch-object % keep-props-values)) ;; We need to set the same index as the original shape - (pcb/change-parent (:parent-id shape) [new-shape] index {:component-swap true + (pcb/change-parent (:parent-id shape) [new-shape] index {:allow-altering-copies true :ignore-touched true}) (change-touched new-shape shape @@ -2258,11 +2258,11 @@ (defn generate-component-swap [changes objects shape file page libraries id-new-component - index target-cell keep-props-values keep-touched] + index target-cell keep-props-values ignore-swapped?] (let [;; When we keep the touched properties, we can't delete the ;; swapped children (we will keep them too) ignore-swapped-fn - (if keep-touched + (if ignore-swapped? #(-> (get objects %) (ctk/get-swap-slot)) (constantly false)) @@ -2271,7 +2271,7 @@ (-> changes (cls/generate-delete-shapes file page objects (d/ordered-set (:id shape)) - {:component-swap true :ignore-children-fn ignore-swapped-fn})) + {:allow-altering-copies true :ignore-children-fn ignore-swapped-fn})) [new-shape changes] (-> changes (generate-new-shape-for-swap shape file page libraries id-new-component index target-cell keep-props-values))] diff --git a/common/src/app/common/logic/shapes.cljc b/common/src/app/common/logic/shapes.cljc index 39fc560220..6590c7bed8 100644 --- a/common/src/app/common/logic/shapes.cljc +++ b/common/src/app/common/logic/shapes.cljc @@ -100,7 +100,7 @@ ids options)) ([changes ids {:keys [ignore-touched - component-swap + allow-altering-copies ;; We will delete the shapes and its descendants. ;; ignore-children-fn is used to ignore some descendants ;; on the deletion process. It should receive a shape and @@ -119,11 +119,12 @@ ;; Look for shapes that are inside a component copy, but are ;; not the root. In this case, they must not be deleted, ;; but hidden (to be able to recover them more easily). - ;; Unless we are doing a component swap, in which case we want + ;; If we want to specifically allow altering the copies, this is + ;; a special case, like a component swap, in which case we want ;; to delete the old shape (let [shape (get objects shape-id)] (and (ctn/has-any-copy-parent? objects shape) - (not component-swap)))) + (not allow-altering-copies)))) [ids-to-delete ids-to-hide] (loop [ids-seq (seq ids) @@ -212,9 +213,10 @@ empty-parents ;; Any parent whose children are all deleted, must be deleted too. - ;; Unless we are during a component swap: in this case we are replacing a shape by + ;; If we want to specifically allow altering the copies, this is a special case, + ;; for example during a component swap. in this case we are replacing a shape by ;; other one, so must not delete empty parents. - (if-not component-swap + (if-not allow-altering-copies (into (d/ordered-set) (find-all-empty-parents #{})) #{}) diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 054bf0103f..12238a1b73 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -79,7 +79,7 @@ before-changes (-> (pcb/empty-changes) (pcb/with-page page) (pcb/with-objects (:objects page)) - (pcb/change-parent uuid/zero [orig-swapped-child] 0 {:component-swap true})) + (pcb/change-parent uuid/zero [orig-swapped-child] 0 {:allow-altering-copies true})) objects (pcb/get-objects changes) prev-swap-slot (ctk/get-swap-slot orig-swapped-child) @@ -90,7 +90,7 @@ (-> (pcb/concat-changes before-changes changes) ;; Move the previous shape to the new parent - (pcb/change-parent (:parent-id related-shape-in-new) [orig-swapped-child] pos {:component-swap true}) + (pcb/change-parent (:parent-id related-shape-in-new) [orig-swapped-child] pos {:allow-altering-copies true}) ;; We need to update the swap slot only when it pointed ;; to the swap-ref-id. Oterwise this is a swapped item @@ -102,7 +102,7 @@ #(ctk/set-swap-slot % (:shape-ref related-shape-in-new)))) ;; Delete new non-swapped item - (cls/generate-delete-shapes ldata page objects (d/ordered-set (:id related-shape-in-new)) {:component-swap true}) + (cls/generate-delete-shapes ldata page objects (d/ordered-set (:id related-shape-in-new)) {:allow-altering-copies true}) second))) (defn- child-of-swapped? diff --git a/frontend/src/app/main/data/workspace/shapes.cljs b/frontend/src/app/main/data/workspace/shapes.cljs index ad2bd88379..3f8eb1c9cd 100644 --- a/frontend/src/app/main/data/workspace/shapes.cljs +++ b/frontend/src/app/main/data/workspace/shapes.cljs @@ -198,7 +198,7 @@ undo-id (or (:undo-id options) (js/Symbol)) [all-parents changes] (-> (pcb/empty-changes it (:id page)) (cls/generate-delete-shapes fdata page objects ids - {:ignore-touched (:component-swap options) + {:ignore-touched (:allow-altering-copies options) :undo-group (:undo-group options) :undo-id undo-id}))]