Merge remote-tracking branch 'origin/staging' into develop

This commit is contained in:
alonso.torres 2025-03-06 16:05:12 +01:00
commit e01dfd76e8
3 changed files with 96 additions and 78 deletions

View file

@ -154,7 +154,7 @@
(let [data (::file-data (meta changes))] (let [data (::file-data (meta changes))]
(dm/get-in data [:pages-index uuid/zero :objects]))) (dm/get-in data [:pages-index uuid/zero :objects])))
(defn- apply-changes-local (defn apply-changes-local
[changes & {:keys [apply-to-library?]}] [changes & {:keys [apply-to-library?]}]
(dm/assert! (dm/assert!
"expected valid changes" "expected valid changes"

View file

@ -794,42 +794,35 @@
(let [omit-touched? (not reset?) (let [omit-touched? (not reset?)
clear-remote-synced? (and initial-root? reset?) clear-remote-synced? (and initial-root? reset?)
set-remote-synced? (and (not initial-root?) reset?) set-remote-synced? (and (not initial-root?) reset?)
changes (cond-> changes changes
:always (cond-> changes
(update-attrs shape-inst :always
shape-main (update-attrs shape-inst
root-inst shape-main
root-main root-inst
container root-main
omit-touched?) container
omit-touched?)
(ctl/flex-layout? shape-main) (ctl/flex-layout? shape-main)
(update-flex-child-copy-attrs shape-main (update-flex-child-copy-attrs shape-main
shape-inst shape-inst
library library
component component
container container
omit-touched?) omit-touched?)
(ctl/grid-layout? shape-main) reset?
(update-grid-copy-attrs shape-main (change-touched shape-inst
shape-inst shape-main
library container
component {:reset-touched? true})
container
omit-touched?)
reset? clear-remote-synced?
(change-touched shape-inst (change-remote-synced shape-inst container nil)
shape-main
container
{:reset-touched? true})
clear-remote-synced? set-remote-synced?
(change-remote-synced shape-inst container nil) (change-remote-synced shape-inst container true))
set-remote-synced?
(change-remote-synced shape-inst container true))
component-container (find-main-container container shape-inst shape-main library component) component-container (find-main-container container shape-inst shape-main library component)
@ -911,24 +904,37 @@
(d/index-of children-inst child-inst) (d/index-of children-inst child-inst)
(d/index-of children-main child-main) (d/index-of children-main child-main)
container container
omit-touched?))] omit-touched?))
(compare-children changes changes
shape-inst (compare-children changes
children-inst shape-inst
children-main children-inst
container children-main
component-container container
file component-container
libraries file
only-inst libraries
only-main only-inst
both only-main
swapped both
moved swapped
false moved
reset? false
components-v2)))) reset?
components-v2)
changes
(cond-> changes
(ctl/grid-layout? shape-inst)
(update-grid-copy-attrs
(:id shape-inst)
shape-main
library
component
omit-touched?))]
changes)))
(defn generate-rename-component (defn generate-rename-component
"Generate the changes for rename the component with the given id, in the current file library." "Generate the changes for rename the component with the given id, in the current file library."
@ -1774,30 +1780,36 @@
(defn- update-grid-copy-attrs (defn- update-grid-copy-attrs
"Synchronizes the `layout-grid-cells` property from the main shape to the copies" "Synchronizes the `layout-grid-cells` property from the main shape to the copies"
[changes shape-main shape-copy main-container main-component copy-container omit-touched?] [changes shape-copy-id shape-main main-container main-component omit-touched?]
(let [ids-map (-> changes
(into {} (pcb/apply-changes-local)
(comp (pcb/update-shapes
(map #(dm/get-in copy-container [:objects %])) [shape-copy-id]
(keep (fn [shape-copy objects]
(fn [copy-shape] (let [ids-map
(let [main-shape (ctf/get-ref-shape main-container main-component copy-shape)] (into {}
[(:id main-shape) (:id copy-shape)])))) (comp
(:shapes shape-copy)) (map #(get objects %))
(keep
(fn [copy-shape]
(let [main-shape (ctf/get-ref-shape main-container main-component copy-shape)]
[(:id main-shape) (:id copy-shape)]))))
(:shapes shape-copy))
new-changes remove-orphan-cells
(-> (pcb/empty-changes) (fn [cells {:keys [shapes]}]
(pcb/with-container copy-container) (let [child? (set shapes)]
(pcb/with-objects (:objects copy-container)) (-> cells
(pcb/update-shapes (update-vals
[(:id shape-copy)] (fn [cell]
(fn [shape-copy] (update cell :shapes #(filterv child? %)))))))
;; Take cells from main and remap the shapes to assign it to the copy ;; Take cells from main and remap the shapes to assign it to the copy
(let [copy-cells (:layout-grid-cells shape-copy) copy-cells (-> shape-copy :layout-grid-cells (remove-orphan-cells shape-copy))
main-cells (-> (ctl/remap-grid-cells shape-main ids-map) :layout-grid-cells)] main-cells (-> shape-main (ctl/remap-grid-cells ids-map) :layout-grid-cells)]
(assoc shape-copy :layout-grid-cells (ctl/merge-cells copy-cells main-cells omit-touched?)))) (-> shape-copy
{:ignore-touched true}))] (assoc :layout-grid-cells
(pcb/concat-changes changes new-changes))) (ctl/merge-cells copy-cells main-cells omit-touched?)))))
{:ignore-touched true :with-objects? true})))
(defn- update-grid-main-attrs (defn- update-grid-main-attrs
"Synchronizes the `layout-grid-cells` property from the copy to the main shape" "Synchronizes the `layout-grid-cells` property from the copy to the main shape"

View file

@ -1642,11 +1642,16 @@
"Given target cells update with source cells while trying to keep target as "Given target cells update with source cells while trying to keep target as
untouched as possible" untouched as possible"
[target-cells source-cells omit-touched?] [target-cells source-cells omit-touched?]
(if (not omit-touched?) (if omit-touched?
source-cells
(letfn [(get-data [cells id] (letfn [(get-data [cells id]
(dissoc (get cells id) :shapes :row :column :row-span :column-span))] (dissoc (get cells id) :row :column :row-span :column-span))
(merge-cells [source-cell target-cell]
(-> source-cell
(d/patch-object
(dissoc target-cell :shapes :row :column :row-span :column-span))
(cond-> (d/not-empty? (:shapes target-cell))
(assoc :shapes (:shapes target-cell)))))]
(let [deleted-cells (let [deleted-cells
(into #{} (into #{}
(filter #(not (contains? source-cells %))) (filter #(not (contains? source-cells %)))
@ -1664,8 +1669,9 @@
(reduce (reduce
(fn [cells id] (fn [cells id]
(-> cells (-> cells
(d/update-when id d/patch-object (get-data target-cells id)))) (d/update-when id merge-cells (get target-cells id))))
source-cells)))))) source-cells))))
source-cells))
(defn toggle-fix-if-auto (defn toggle-fix-if-auto
"Changes the sizing to fix if it's fill" "Changes the sizing to fix if it's fill"