🐛 Reflow the layouts an update main changes

Pushing a grid copy's column direction to its main left the main's
children in their row order, and pushing a copy's grid cells left the
main's children where they were before, outside the cells they took. A
sync reflows the layouts of the copies it changes, but `update-component`
reflowed none, so the main never laid out again.

It now emits a layout update for the frames its changes touch in the
current file, the main's among them when its component is local, in the
undo group of the update.

Test: frontend generated
`generated-an-update-main-of-a-grid-direction-orders-the-main-by-it`.
The frontend golden master of `case-ak-update-main-pushes-grid-cells` is
recorded again: its main and copy children now sit at their cells, where
they were left stacked outside their boards.

ClojureScript only; the benchmark covers JVM code and is not run.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-15 18:38:48 +01:00
parent 57c2cff1e1
commit 4b404af324
3 changed files with 31 additions and 9 deletions

View File

@ -895,13 +895,28 @@
(:redo-changes nonlocal-changes)
fdata))
(rx/of
(when (seq (:redo-changes local-changes))
(dch/commit-changes (assoc local-changes
:file-id (:id file))))
(when (seq (:redo-changes nonlocal-changes))
(dch/commit-changes (assoc nonlocal-changes
:file-id (:component-file shape))))))))))))
(rx/concat
(rx/of
(when (seq (:redo-changes local-changes))
(dch/commit-changes (assoc local-changes
:file-id (:id file))))
(when (seq (:redo-changes nonlocal-changes))
(dch/commit-changes (assoc nonlocal-changes
:file-id (:component-file shape)))))
;; the layouts it changes in this file, the main's among them
;; when its component is local, reflow as those of the copies
;; a sync changes
(->> (cond-> (:redo-changes local-changes)
(= (:component-file shape) (:id file))
(into (:redo-changes nonlocal-changes)))
(mapcat #(map (fn [frame] [(:page-id %) (:id frame)]) (ch/frames-changed fdata %)))
(distinct)
(group-by first)
(map (fn [[page-id frames]]
(ptk/data-event :layout/update {:page-id page-id
:ids (mapv second frames)
:undo-group undo-group})))
(rx/from))))))))))
(defn- update-component-thumbnail-sync
[state component-id file-id tag]

View File

@ -1124,6 +1124,13 @@
(await (replay {:world [2 2 {:variants true :text true :layout :grid :layout-copies true}]
:ops [[:detach 6 0 0 0] [:structure 0 2 0]]})))
(t/deftest ^:async generated-an-update-main-of-a-grid-direction-orders-the-main-by-it
;; the main takes the copy's column direction and its layout reflows,
;; ordering its children by their cells in that direction
(await (replay {:world [3 2 {:variants true :layout :grid :grid-square true :layout-children true :text true}]
:ops [[:make-variant] [:make-variant 6] [:combine] [:make-variant 11] [:combine]
[:remove-child 9] [:grid-direction 0 0 13] [:update-main]]})))
(t/deftest ^:async generated-a-detach-under-an-unaccepted-child-removal-leaves-it-plain
;; the loaded library no longer has the nested copy's child main, so the
;; detach leaves that child plain until the consumer accepts the library

View File

@ -32,8 +32,8 @@
:case-aj-reflow-after-nested-sync-is-its-own-undo-step
[{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#0000ff\"}\n {:times 1}", :states ["43ca8b2de80a51fc" "32b45a5ac7536b08" "7104bfaccd42cd3b"]}]
:case-ak-update-main-pushes-grid-cells
[{:transcript " {:target :copy-child, :to :other, :keep-touched? false}\n {:board :copy-root, :child :copy-child, :row 1, :column 3}\n {:target :copy-root}", :states ["66a66d6e7afac79f" "9865d4f8003e91ef" "2d73539548abb75a" "5e5d65dc5416e495"]}
{:transcript "one-of -> \n {:board :copy-root, :child :copy-child, :row 1, :column 3}\n {:target :copy-root}", :states ["9900a7f71dc0cb5f" "de66ab1c3d4cc157" "6b5ff9fd86e2aa87"]}]
[{:transcript " {:target :copy-child, :to :other, :keep-touched? false}\n {:board :copy-root, :child :copy-child, :row 1, :column 3}\n {:target :copy-root}", :states ["66a66d6e7afac79f" "9865d4f8003e91ef" "0cc5767e36a94c5f" "651536b251bb091e"]}
{:transcript "one-of -> \n {:board :copy-root, :child :copy-child, :row 1, :column 3}\n {:target :copy-root}", :states ["9900a7f71dc0cb5f" "81db7be5574979e3" "980b0668f5421831"]}]
:case-al-update-main-renames-the-component
[{:transcript " {:target :copy-root, :property :name, :value \"Renamed\"}\n {:target :copy-instance, :property :name, :value \"Renamed child\"}\n {:target :copy-root}", :states ["d4e11348047fc1e1" "0021aeab497d25e6" "c0aa5a2b915a7542" "ca23729038aec91f"]}
{:transcript " {:target :copy-root, :property :name, :value \"Renamed\"}\n one-of -> \n {:target :copy-root}", :states ["d4e11348047fc1e1" "409795fc3e2bb3a7" "6a882f51aaf16306"]}]