mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
📎 Model the sidebar's sizing fixes and the reflow's placement settle
Two turned-shape programs of the frontend replay differed from the composable model: - Setting a turned variant to fill in its hugging variant board: the sidebar fixes the board's width first, the model's property edit did not, and a layout pass of a fill child in a hugging row collapses a turned child before growing it, which left it a singular transform. The model's edit of a layout child now applies the same sizing fixes (`cls/fix-child-sizing`, `cls/fix-parent-sizing`). - A swapped head turned with its main, filling a row: the frontend's layout update settles the placement of the copy shapes it moves, which gives the head its main's unskewed turn; the model's reflow did not, and kept the layout's skew. The model's reflow settles them too (`cll/generate-sync-transformed-placement`). Both programs now pass in the frontend replay with WASM off (frontend generated tests). Harness only; the benchmark is not run. Also in this commit: - Log each shape's parent id in the WASM replay's debug output. The debug log named each shape's parent, which copies and their mains share; it now gives the parent's id too, so a subtree can be told apart from its copies'. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
e895047c16
commit
b6956ea033
@ -183,22 +183,34 @@
|
||||
(::layout-reflow? changes))
|
||||
|
||||
(defn get-layout-reflow-changes
|
||||
"Derived layout changes on the current file's pages, after copy inputs sync."
|
||||
"Derived layout changes on the current file's pages, after copy inputs sync.
|
||||
As the frontend's layout update applies them, the copy shapes they move
|
||||
then settle their placement."
|
||||
[situation]
|
||||
(reduce (fn [changes [_ page]]
|
||||
(let [ids (into [] (keep #(when (:layout %) (:id %))) (vals (:objects page)))]
|
||||
(if (empty? ids)
|
||||
changes
|
||||
(let [tree (gm/set-objects-modifiers
|
||||
(into {} (map #(vector % {:modifiers (ctm/reflow-modifiers)})) ids)
|
||||
(:objects page))
|
||||
next (cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page)) (keys tree)
|
||||
(clp/modifiers-transform tree) (:objects page)
|
||||
{:ignore-touched true :attrs clp/transform-attrs})]
|
||||
(pcb/concat-changes changes next)))))
|
||||
(pcb/empty-changes)
|
||||
(get-in (tm/file situation) [:data :pages-index])))
|
||||
(let [file (tm/file situation)]
|
||||
(reduce (fn [changes [_ page]]
|
||||
(let [ids (into [] (keep #(when (:layout %) (:id %))) (vals (:objects page)))]
|
||||
(if (empty? ids)
|
||||
changes
|
||||
(let [tree (gm/set-objects-modifiers
|
||||
(into {} (map #(vector % {:modifiers (ctm/reflow-modifiers)})) ids)
|
||||
(:objects page))
|
||||
next (-> (cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page)) (keys tree)
|
||||
(clp/modifiers-transform tree) (:objects page)
|
||||
{:ignore-touched true :attrs clp/transform-attrs})
|
||||
(cll/generate-sync-transformed-placement file (cf/libraries situation)
|
||||
page (:objects page) (keys tree)))]
|
||||
(pcb/concat-changes changes next)))))
|
||||
(pcb/empty-changes)
|
||||
(get-in file [:data :pages-index]))))
|
||||
|
||||
(def ^:private sidebar-layout-child-properties
|
||||
"The properties the sidebar edits as a layout child (`update-layout-child`
|
||||
on the frontend)."
|
||||
#{:margin :layout-item-margin :layout-item-margin-type :layout-item-align-self
|
||||
:layout-item-h-sizing :layout-item-v-sizing :layout-item-min-w :layout-item-max-w
|
||||
:layout-item-min-h :layout-item-max-h :layout-item-absolute :layout-item-z-index})
|
||||
|
||||
(defrecord ChangeProperty [target property value]
|
||||
IComponentOperation
|
||||
@ -227,6 +239,22 @@
|
||||
(cll/generate-author-constraint-places (ctn/make-container page :page)
|
||||
(cf/libraries situation)
|
||||
(:objects page) #{shape-id})
|
||||
|
||||
;; as the sidebar's layout child edit: the children and the
|
||||
;; parent take the sizing a hugging layout allows
|
||||
(contains? sidebar-layout-child-properties property)
|
||||
(as-> changes
|
||||
(let [attrs (set-property {} property value')
|
||||
parent (get-in page [:objects (:parent-id shape)])]
|
||||
(-> changes
|
||||
(cls/generate-update-shapes (cfh/get-children-ids (:objects page) shape-id)
|
||||
(partial cls/fix-child-sizing (:objects page) attrs)
|
||||
(:objects page) {})
|
||||
(cls/generate-update-shapes [(:id parent)]
|
||||
(fn [parent objects]
|
||||
(cls/fix-parent-sizing parent objects #{shape-id} attrs))
|
||||
(:objects page)
|
||||
{:with-objects? true :skip-grid-reassignment? true}))))
|
||||
(and (= :layout-item-absolute property)
|
||||
(ctl/grid-layout? (get-in page [:objects layout-id])))
|
||||
(pcb/update-shapes [layout-id] ctl/assign-cells
|
||||
|
||||
@ -1118,6 +1118,23 @@
|
||||
:ops [[:rotate 16 0 7 0] [:grid-direction 0 0 0 1] [:grid-cell 0 10 0 1] [:add-child 0]
|
||||
[:structure 3 6 15] [:grid-direction 0 0 0 1] [:grid-cell 0 4 2 1]]})))
|
||||
|
||||
(t/deftest ^:async generated-a-turned-variant-set-to-fill-in-a-hugging-board-keeps-its-turn
|
||||
;; the sidebar fixes the hugging variant board before the turned variant
|
||||
;; fills it, as the model does
|
||||
(await (replay {:world [3 2 {:variants true :text-styles true :layout nil :variant-diff false
|
||||
:layout-item-margins false :grid-square false :rich-variants true
|
||||
:layout-children false :grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:rotate 7 0 0 0] [:update-main 0 0 0 0] [:make-variant 19 0 0 0] [:style 0 29 4 0]]})))
|
||||
|
||||
(t/deftest ^:async generated-a-turned-fill-swap-settles-like-its-main-after-the-layout
|
||||
;; the layout of a row fills a swapped head turned with its main, which
|
||||
;; then settles its placement as the main's
|
||||
(await (replay {:world [2 2 {:variants true :layout :flex :rich-variants true :layout-copies true :text true}]
|
||||
:ops [[:delete 0] [:restore 0] [:add-variant 0 0 0 0] [:swap 6 0 0 0] [:combine 5 0 0 0]
|
||||
[:delete 12 0 0 0] [:combine 9 0 0 0] [:nest 0 0 0 0] [:restore 0 0 0 0] [:combine 8]
|
||||
[:switch 3] [:style 0 30 1] [:detach 1 0 0 0] [:combine 0] [:switch 7] [:nest 4 0 0 0]
|
||||
[:rotate 2 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async generated-an-ungroup-in-a-grid-main-undoes-in-one-step
|
||||
;; the copies' repositioning, synced from the layout update after the
|
||||
;; ungroup, undoes with the ungroup
|
||||
|
||||
@ -144,7 +144,7 @@
|
||||
|
||||
(defn- log-shapes!
|
||||
"Log the shapes of the current page at the end of a program when the page
|
||||
names the `debug` query parameter: name, type, id, parent, rectangle,
|
||||
names the `debug` query parameter: name, type, id, parent name and id, rectangle,
|
||||
transform, touched groups, shape ref, layout, and a text's characters and
|
||||
font weights."
|
||||
[]
|
||||
@ -153,7 +153,7 @@
|
||||
(doseq [shape (sort-by :name (vals objects))]
|
||||
(js/console.log "WASM-REPLAY shape"
|
||||
(pr-str [(:name shape) (:type shape) (:id shape)
|
||||
(:name (get objects (:parent-id shape)))
|
||||
(:name (get objects (:parent-id shape))) (:parent-id shape)
|
||||
(some-> (:selrect shape) (select-keys [:x :y :width :height]))
|
||||
(:transform shape) (:touched shape)
|
||||
(:shape-ref shape) (:layout shape)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user