diff --git a/backend/src/app/features/components_v2.clj b/backend/src/app/features/components_v2.clj index 05cd1a084..452b83bc5 100644 --- a/backend/src/app/features/components_v2.clj +++ b/backend/src/app/features/components_v2.clj @@ -1450,16 +1450,15 @@ page (cons shape children)) - [_ _ changes2] - (cflh/generate-add-component nil + [_ _ changes] + (cflh/generate-add-component changes [shape] (:objects page) (:id page) file-id true nil - cfsh/prepare-create-artboard-from-selection) - changes (fcb/concat-changes changes changes2)] + cfsh/prepare-create-artboard-from-selection)] (shape-cb shape) (:redo-changes changes))) diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index b0ab2b5bd..7d693c370 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -69,6 +69,11 @@ ::page page ::page-id (:id page))) +(defn with-page-id + [changes page-id] + (vary-meta changes assoc + ::page-id page-id)) + (defn with-container [changes container] (if (cfh/page? container) diff --git a/common/src/app/common/files/libraries_helpers.cljc b/common/src/app/common/files/libraries_helpers.cljc index 8c195e7f7..77ffcbe87 100644 --- a/common/src/app/common/files/libraries_helpers.cljc +++ b/common/src/app/common/files/libraries_helpers.cljc @@ -338,7 +338,7 @@ If an asset id is given, only shapes linked to this particular asset will be synchronized." - [it file-id asset-type asset-id library-id libraries current-file-id] + [changes file-id asset-type asset-id library-id libraries current-file-id] (s/assert #{:colors :components :typographies} asset-type) (s/assert (s/nilable ::us/uuid) asset-id) (s/assert ::us/uuid file-id) @@ -353,13 +353,13 @@ (let [file (get-in libraries [file-id :data]) components-v2 (get-in file [:options :components-v2])] (loop [containers (ctf/object-containers-seq file) - changes (pcb/empty-changes it)] + changes changes] (if-let [container (first containers)] (do (recur (next containers) - (pcb/concat-changes + (pcb/concat-changes ;;TODO Remove concat changes changes - (generate-sync-container it + (generate-sync-container (pcb/empty-changes nil) asset-type asset-id library-id @@ -376,7 +376,7 @@ If an asset id is given, only shapes linked to this particular asset will be synchronized." - [it file-id asset-type asset-id library-id libraries current-file-id] + [changes file-id asset-type asset-id library-id libraries current-file-id] (s/assert #{:colors :components :typographies} asset-type) (s/assert (s/nilable ::us/uuid) asset-id) (s/assert ::us/uuid file-id) @@ -391,25 +391,25 @@ (let [file (get-in libraries [file-id :data]) components-v2 (get-in file [:options :components-v2])] (loop [local-components (ctkl/components-seq file) - changes (pcb/empty-changes it)] + changes changes] (if-let [local-component (first local-components)] (recur (next local-components) - (pcb/concat-changes + (pcb/concat-changes ;;TODO Remove concat changes changes - (generate-sync-container it - asset-type - asset-id - library-id - (cfh/make-container local-component :component) - components-v2 - libraries - current-file-id))) + (generate-sync-container (pcb/empty-changes nil) + asset-type + asset-id + library-id + (cfh/make-container local-component :component) + components-v2 + libraries + current-file-id))) changes)))) (defn- generate-sync-container "Generate changes to synchronize all shapes in a particular container (a page or a component) that use assets of the given type in the given library." - [it asset-type asset-id library-id container components-v2 libraries current-file-id] + [changes asset-type asset-id library-id container components-v2 libraries current-file-id] (if (cfh/page? container) (log/debug :msg "Sync page in local file" :page-id (:id container)) @@ -418,7 +418,7 @@ (let [linked-shapes (->> (vals (:objects container)) (filter #(uses-assets? asset-type asset-id % library-id)))] (loop [shapes (seq linked-shapes) - changes (-> (pcb/empty-changes it) + changes (-> changes (pcb/with-container container) (pcb/with-objects (:objects container)))] (if-let [shape (first shapes)] @@ -1727,9 +1727,9 @@ "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] + [changes shapes objects page-id file-id components-v2 prepare-create-group prepare-create-board] - (let [changes (pcb/empty-changes it page-id) + (let [changes (pcb/with-page-id changes page-id) shapes-count (count shapes) first-shape (first shapes) @@ -1744,7 +1744,8 @@ (cfh/frame-shape? first-shape)) (not (ctk/instance-head? first-shape))) [first-shape - (-> (pcb/empty-changes it page-id) + (-> changes + (pcb/with-page-id page-id) (pcb/with-objects objects)) (:shapes first-shape)] @@ -1756,7 +1757,7 @@ [root changes] (if-not components-v2 - (prepare-create-group it ; These functions needs to be passed as argument + (prepare-create-group changes ; These functions needs to be passed as argument objects ; to avoid a circular dependence page-id shapes diff --git a/frontend/src/app/main/data/workspace/groups.cljs b/frontend/src/app/main/data/workspace/groups.cljs index c3a403269..39ab2481b 100644 --- a/frontend/src/app/main/data/workspace/groups.cljs +++ b/frontend/src/app/main/data/workspace/groups.cljs @@ -68,7 +68,7 @@ result))))))) (defn prepare-create-group - [it objects page-id shapes base-name keep-name?] + [changes objects page-id shapes base-name keep-name?] (let [frame-id (:frame-id (first shapes)) parent-id (:parent-id (first shapes)) gname (if (and keep-name? @@ -114,7 +114,8 @@ (filter (partial ctl/grid-layout? objects))) shapes) - changes (-> (pcb/empty-changes it page-id) + changes (-> changes + (pcb/with-page-id page-id) (pcb/with-objects objects) (pcb/add-object group {:index group-idx}) (pcb/update-shapes (map :id shapes) ctl/remove-layout-item-data) @@ -191,7 +192,7 @@ parents (into #{} (map :parent-id) shapes)] (when-not (empty? shapes) (let [[group changes] - (prepare-create-group it objects page-id shapes "Group" false)] + (prepare-create-group (pcb/empty-changes it) objects page-id shapes "Group" false)] (rx/of (dch/commit-changes changes) (dws/select-shapes (d/ordered-set (:id group))) (ptk/data-event :layout/update {:ids parents})))))))) @@ -267,7 +268,7 @@ (= (:type (first shapes)) :group)) [first-shape (-> (pcb/empty-changes it page-id) (pcb/with-objects objects))] - (prepare-create-group it objects page-id shapes "Mask" true)) + (prepare-create-group (pcb/empty-changes it) objects page-id shapes "Mask" true)) changes (-> changes (pcb/update-shapes (:shapes group) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index c3981cf1d..ad2e37a7d 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -351,7 +351,7 @@ parents (into #{} (map :parent-id) shapes)] (when-not (empty? shapes) (let [[root _ changes] - (cflh/generate-add-component it shapes objects page-id file-id components-v2 + (cflh/generate-add-component (pcb/empty-changes it) shapes objects page-id file-id components-v2 dwg/prepare-create-group cfsh/prepare-create-artboard-from-selection)] (when-not (empty? (:redo-changes changes)) @@ -1024,22 +1024,22 @@ (-> (pcb/empty-changes it) (pcb/set-undo-group undo-group)) [(when sync-components? - (cflh/generate-sync-library it file-id :components asset-id library-id libraries current-file-id)) + (cflh/generate-sync-library (pcb/empty-changes it) file-id :components asset-id library-id libraries current-file-id)) (when sync-colors? - (cflh/generate-sync-library it file-id :colors asset-id library-id libraries current-file-id)) + (cflh/generate-sync-library (pcb/empty-changes it) file-id :colors asset-id library-id libraries current-file-id)) (when sync-typographies? - (cflh/generate-sync-library it file-id :typographies asset-id library-id libraries current-file-id))]) + (cflh/generate-sync-library (pcb/empty-changes it) file-id :typographies asset-id library-id libraries current-file-id))]) file-changes (reduce pcb/concat-changes (-> (pcb/empty-changes it) (pcb/set-undo-group undo-group)) [(when sync-components? - (cflh/generate-sync-file it file-id :components asset-id library-id libraries current-file-id)) + (cflh/generate-sync-file (pcb/empty-changes it) file-id :components asset-id library-id libraries current-file-id)) (when sync-colors? - (cflh/generate-sync-file it file-id :colors asset-id library-id libraries current-file-id)) + (cflh/generate-sync-file (pcb/empty-changes it) file-id :colors asset-id library-id libraries current-file-id)) (when sync-typographies? - (cflh/generate-sync-file it file-id :typographies asset-id library-id libraries current-file-id))]) + (cflh/generate-sync-file (pcb/empty-changes it) file-id :typographies asset-id library-id libraries current-file-id))]) changes (pcb/concat-changes library-changes file-changes) diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index 8461da54e..d13921687 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -422,7 +422,7 @@ (prepare-duplicate-guides shapes page ids-map delta))))) (defn- prepare-duplicate-component-change - [changes objects page component-root parent-id frame-id delta libraries library-data it] + [changes objects page component-root parent-id frame-id delta libraries library-data] (let [component-id (:component-id component-root) file-id (:component-file component-root) main-component (ctf/get-component libraries file-id component-id) @@ -467,7 +467,7 @@ changes (ctf/is-main-of-known-component? obj libraries) - (prepare-duplicate-component-change changes objects page obj parent-id frame-id delta libraries library-data it) + (prepare-duplicate-component-change changes objects page obj parent-id frame-id delta libraries library-data) :else (let [frame? (cfh/frame-shape? obj) diff --git a/frontend/test/frontend_tests/helpers/pages.cljs b/frontend/test/frontend_tests/helpers/pages.cljs index cb5a080cc..e650c3d28 100644 --- a/frontend/test/frontend_tests/helpers/pages.cljs +++ b/frontend/test/frontend_tests/helpers/pages.cljs @@ -132,7 +132,7 @@ shapes (dwg/shapes-for-grouping objects shape-ids) [group component-id changes] - (cflh/generate-add-component nil + (cflh/generate-add-component (pcb/empty-changes nil) shapes (:objects page) (:id page)