♻️ Rename flag :component-swap to :allow-altering-copies

This commit is contained in:
Pablo Alba 2025-07-07 11:05:10 +02:00 committed by Pablo Alba
parent 469d47eaf3
commit cfec023585
7 changed files with 24 additions and 22 deletions

View file

@ -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

View file

@ -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

View file

@ -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 _]

View file

@ -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))]

View file

@ -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 #{}))
#{})

View file

@ -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?

View file

@ -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}))]