mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
✨ Generate and check random component histories
The Phase 4 bug hunt: random component programs, an independent model of what they should leave, and the regression programs of what they found. The production fixes they found are the commits before this one, each with its regression programs; this commit holds the test harness, the rest of the tests and the memories they grew with. A regression program that needs the harness runs once this commit is in. - Generation (composable gen): worlds of components, nested copies, variants, libraries (stale and dependent), flex and grid layouts and texts; operations for structure, geometry, styles, texts, layout items, grid tracks and cells, swaps, variant switches, update main, reset, detach, library edits and syncs, undo and redo; shrinking, coverage accounting per operation kind, and PENPOT_GEN_SEED, PENPOT_GEN_NUM and PENPOT_GEN_HISTORIES to choose the seed, the number of programs and their length. - The oracle: invariants on touched groups, overrides, refs, settled versus full sync, design snapshots and the model values, with its own model of authored intent (shadow, geometry, grid and variant rules) instead of production's results. - The frontend replays generated programs through the workspace events and the completion contract, with undo and redo checks. - The oracle unit tests, the test runners' registrations, the golden masters recorded again where a fix changed them, and the memories of the component sync contract and its tests. Harness only; the benchmark is not run. Also in this commit: - Adapt develop's variant set and reload tests to this branch. Develop's tests of transforming a component into a variant set call the event with the set's id and expect the defining commit to hold only the main. Here the transform builds the whole set, its second member included, in one commit: transform-in-variant takes an optional variant id, and the tests expect both members in that commit. - Restore the requires and test wiring the rebase merges dropped. - Generate variant property edits and added variants. The random programs switched between the members of a variant set but never changed the set. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
03f880979a
commit
3e6c98c01a
@ -36,4 +36,37 @@ For component touched semantics and sync groups, read `mem:common/component-data
|
||||
|
||||
## Inspection
|
||||
|
||||
To inspect what a UI action emitted, use `mem:frontend/cljs-repl` with the snippets in `mem:common/component-debugging-recipes` rather than adding temporary source instrumentation.
|
||||
To inspect what a UI action emitted, use `mem:frontend/cljs-repl` with the snippets in `mem:common/component-debugging-recipes` rather than adding temporary source instrumentation.
|
||||
|
||||
- Structural add/remove and change-parent inverses restore the copy parent's
|
||||
`:remote-synced` as well as `:touched`. Removing or adding a child clears
|
||||
the former even when touched groups do not change; restoring only the
|
||||
groups loses prior state on undo (F157).
|
||||
|
||||
- Undo of bulk removals moves restored siblings in original sibling order.
|
||||
Component sync records each removal's current index from builder objects;
|
||||
indexes in the original container become stale after earlier removals.
|
||||
When the builder lacks a main's container (inverse sync), use that main
|
||||
container's original index. Both rules preserve order after several
|
||||
siblings disappear (F158).
|
||||
|
||||
- A move inverse can restore component nesting that existed before the
|
||||
move, even when the normal component-loop check would reject creating
|
||||
it now (F177). `change-parent` records `:restore-component-nesting` on
|
||||
the inverse only when the original position already repeats a component.
|
||||
The change applier still rejects object-tree cycles and copy-structure
|
||||
edits. Normal forward moves keep the component-loop guard.
|
||||
|
||||
Normal duplication checks the component nesting guard too (F181). A finite
|
||||
repeated component tree can use a swapped child to cut recursion; adding
|
||||
another child in its main can open an expanding branch. cld/allow-duplicate?
|
||||
combines copy-structure and nesting guards for normal frontend/pure nodes.
|
||||
The duplicate builder checks the actual destination after ALT placement;
|
||||
a duplicate at the page root remains allowed. Undo still restores existing
|
||||
nesting through its explicit inverse flag, not through a forward bypass.
|
||||
|
||||
Component restoration reports its component id from components-changed
|
||||
(F183). Its main does not exist in the old page objects, so add/mod-object
|
||||
detection cannot find it. Restore can rename a variant when its container
|
||||
has gone; the restored component and its dependents must sync in that same
|
||||
undo group.
|
||||
|
||||
@ -30,7 +30,7 @@ Masters are not normally touched through `set-shape-attr`, but touched flags can
|
||||
|
||||
- A copy sub-head the user SWAPPED to another component keeps `:shape-ref` on the near-main child it replaces (its *position*); `:component-id`/`:component-file` name the component its *content* comes from; the touched group `:swap-group` marks the swap. Its children refer into its own component's main.
|
||||
- So for a swapped head the position shape (`find-ref-shape`, X in the near main) and the content shape (its component's main root) differ. `ctf/find-ref-shape` gives position (parent heads are tried outermost first); code that needs the content of a swapped head goes through the content helper, never through `get-ref-shape` with the head's own component.
|
||||
- A copy sub-head whose component differs from its near main's component must have `:swap-group`; one that matches must not.
|
||||
- A copy sub-head whose component differs from its near main's component must have `:swap-group`. An authored swap keeps this group if a later main edit chooses the same component: equal does not mean untouched. Only an explicit swap back clears it.
|
||||
- A head takes a position only through `ctf/take-position` (swap in a copy, keep-touched switch, update-main into a copy, the `:ref-not-in-near-main` repair): it refers to the position, is swapped iff its component differs, and otherwise its descendants are remapped to the position's descendants. Setting `:shape-ref`/`:swap-group` by hand leaves the children referring to the wrong main, which validation does not catch and the next sync turns into delete + re-add.
|
||||
- Copy children are paired to main children by `shape-ref` (`is-main-of?`, seek, not index), swapped or not. `find-near-match` (positional) is only a validator/repair heuristic; validity requires membership of the ref among the near-main parent's children, not index equality (`mem:common/file-change-validation-migration-subtleties`).
|
||||
- Copy child ORDER converges to the main's via the async sync (`moved` branch of `compare-children`); local code must never reorder copy children directly (guards in `:mov-objects`/`:reorder-children`).
|
||||
@ -40,6 +40,16 @@ Masters are not normally touched through `set-shape-attr`, but touched flags can
|
||||
|
||||
`make-component-instance` in `app.common.types.container` produces a clean component copy through `update-new-shape`, dissociating attrs such as `:touched`, `:remote-synced`, `:variant-id`, and `:variant-name` on cloned shapes.
|
||||
|
||||
With `:main-instance? true` (library absorption), nested copies keep their
|
||||
`:touched` and `:remote-synced`; they remain copies inside the new main.
|
||||
|
||||
`:content-scale` is an optional positive shape number (absent means 1),
|
||||
accumulated by scale-content transforms on both renderers. It belongs to
|
||||
`:geometry-group`, survives clone/serialization, and leaves the data when
|
||||
the accumulated scale returns to 1. Sync derives styles from the ratio of
|
||||
the copy's scale to its main's, separately from constraint resizing.
|
||||
Old files default to 1; historical scale gestures cannot be reconstructed.
|
||||
|
||||
`duplicate-component` in `app.common.logic.duplicate` creates a new component master by cloning existing component shapes, setting component metadata, and applying a position delta. It does not have the same clean-copy semantics as `make-component-instance`, so inherited attrs on the source can matter.
|
||||
|
||||
When a bug depends on touched state, identify which cloning path produced the shape before changing sync logic.
|
||||
@ -50,4 +60,36 @@ A variant container is a frame with `:is-variant-container true`. Its children a
|
||||
|
||||
Predicates are broad: `ctk/is-variant?` checks `:variant-id` and applies to both variant master shapes and component rows; `ctk/is-variant-container?` checks the container shape flag.
|
||||
|
||||
Moving/dropping a shape into a variant container through the move-to-frame path can auto-convert it into a variant via `generate-make-shapes-variant`, which may duplicate the underlying component. Treat drag/drop into variant containers as a component/variant operation, not a plain reparent.
|
||||
Moving/dropping a shape into a variant container through the move-to-frame path can auto-convert it into a variant via `generate-make-shapes-variant`, which may duplicate the underlying component. Treat drag/drop into variant containers as a component/variant operation, not a plain reparent.
|
||||
|
||||
- `ctk/remove-swap-group` removes `:touched` when it removes the final group.
|
||||
New main clones must use the same empty-state representation as
|
||||
`process-operation :set-touched`; otherwise a later move+undo changes
|
||||
`:touched #{}` to a missing field and cannot restore the exact state (F156).
|
||||
|
||||
Content ref chains (get-ref-chain-until-target-ref, including touched walks)
|
||||
take find-content-ref-shape at every link. A swapped intermediate head
|
||||
follows its own main; collecting its replaced position's content overrides
|
||||
creates phantom groups in copies of that swap (F165). Position advancement
|
||||
still uses advance-shape-ref and find-ref-shape.
|
||||
|
||||
A swapped head pushed into a main can become a plain nested copy of its own
|
||||
component. If the old position supplied rotation or flips that differ from
|
||||
that component's expected parent placement, the new nested copy needs a
|
||||
geometry-group override. Otherwise a later sync discards the orientation
|
||||
that update-main just pushed (F168). The source copy clears its overrides.
|
||||
Compare against the parent's pushed frame: the inverse sync has already
|
||||
written its new rotation, while the original container still has the old
|
||||
one. Using that old frame creates phantom geometry overrides (F172).
|
||||
|
||||
Pushing a swapped subtree into a nested copy can remap it to an ordinary
|
||||
position with the same component. Content differences against that new
|
||||
reference become authored overrides on the promoted head and descendants;
|
||||
otherwise a later full sync discards the values update-main just pushed
|
||||
(F174). The source copy clears its overrides and follows the new subtree.
|
||||
|
||||
When sync turns a parent, its subtree moves with that turn before the child
|
||||
walk continues (F179). This includes ordinary and swapped children with
|
||||
authored geometry. Normalize parent axis directions for the turn: resize
|
||||
already runs through dimensions and constraints. Refresh the walk from
|
||||
current builder objects so later direct syncs do not turn stale records.
|
||||
|
||||
@ -39,4 +39,22 @@ The generic fallback branch copies from `previous-shape`. It represents the inte
|
||||
|
||||
`common/src/app/common/test_helpers/compositions.cljc` has `swap-component-in-shape`, which drives `generate-component-swap` plus `generate-keep-touched` with the production `keep-touched?` flag. Use it for focused common tests of variant-switch behavior.
|
||||
|
||||
`common/test/common_tests/logic/variants_switch_test.cljc` is the canonical reference suite for swap+touched scenarios. Read nearby tests before adding another case.
|
||||
`common/test/common_tests/logic/variants_switch_test.cljc` is the canonical reference suite for swap+touched scenarios. Read nearby tests before adding another case.
|
||||
|
||||
## Variant geometry comparison
|
||||
|
||||
Switch carry compares the two mains' geometry with `gsh/close-attrs?`.
|
||||
The clean target already has the copy's rotation, which can turn 100 into
|
||||
99.99999999999994. Exact dimension equality drops valid resize overrides
|
||||
(F160). Fixed layout sizes and composite geometry use the same tolerance;
|
||||
nongeometry scalar attributes still compare exactly.
|
||||
|
||||
After carrying geometry, the switch syncs its new subtree once from the
|
||||
updated builder objects. Untouched children must follow a retained root
|
||||
size through constraints; copying only root attrs leaves them in the old
|
||||
frame (F162). The direct sync keeps carried groups and child swaps.
|
||||
|
||||
Variant carry must collect groups and match children through deleted near
|
||||
mains too (F180). Copies keep those values after deletion. Both the content
|
||||
ref-chain walk and find-shape-ref-child-of include deleted component data;
|
||||
otherwise a switch loses inherited size, rotation groups and child fills.
|
||||
|
||||
@ -22,33 +22,50 @@ Intended semantics of copies, `:touched` and component sync. This is the spec: w
|
||||
- Edit on a copy shape (authored): sets the attr's group (text content: `:content-group` + the text groups it changes), clears `:remote-synced`. Descendants moved/resized only because of it stay untouched.
|
||||
- Rename: an explicit rename touches `:name-group` on root or child. Automatic renames (text name following its content) are derived: the editors write the name with `:ignore-touched #{:name}`, and sync gives an untouched copy text the name of its own letters when the main's name is automatic. Untouched names sync from the near main; a touched root name on update-main renames the component.
|
||||
- Edit on a main: no touched change on the main; triggers sync.
|
||||
- Sync main→copy: every untouched group gets the near main's value (geometry: expected geometry); touched groups keep their values; never sets or clears `:touched`. Main child added → added clean to copies. Main child deleted → copy child removed, overrides or not. Main reorder → copies follow. A swapped sub-head pairs with the main child it replaces (its `:shape-ref`) and takes only that child's placement (position, rotation, flips, constraints, `layout-item-*`); everything else syncs from its own component's main. A main child deleted → its swapped copies go with it. A swap made in the main reaches copies without `:swap-group` and spares those with it.
|
||||
- Sync main→copy: every untouched group gets the near main's value (geometry: expected geometry); touched groups keep their values; never sets or clears `:touched` during attribute sync. If a main detaches a nested head, its images become ordinary shapes and lose their now-invalid `:swap-group`. Main child added → added clean to copies. Main child deleted → copy child removed, overrides or not. Main reorder → copies follow. A swapped sub-head pairs with the main child it replaces (its `:shape-ref`) and takes only that child's placement (position, rotation, flips, constraints, `layout-item-*`); everything else syncs from its own component's main. A main child deleted → its swapped copies go with it. A swap made in the main reaches copies without `:swap-group` and spares those with it.
|
||||
- Sync cascade is eager: one sync runs to a fixpoint in memory (copies of A, including the A copy in B's main → copies of B → …) and commits once in the triggering op's undo group. The file is never left partly synced. Syncing only the components reported as changed equals a full-file sync. Code: `cll/generate-sync-file-cascade` (first pass as `generate-sync-file-changes`, then `generate-sync-components-cascade` over `cll/changed-components` of each pass); the frontend `sync-file` commits it to the synced file, and a library file's sync then syncs the current file's copies of the library components its cascade changed.
|
||||
- Reset: the selected head's subtree becomes equal to its near main (expected geometry); all its touched groups cleared, `:swap-group` included: a swapped head turns back into the near main's component in place, keeping its id. Nothing outside that subtree changes.
|
||||
- Update main (from a top copy head): the copy's differing values go to the main; the copy's touched cleared; other copies then sync and keep their own overrides. A swapped child replaces the main child it stands for, and neither keeps `:swap-group`.
|
||||
- Update main (from a top copy head): the copy's differing values go to the main; the copy's touched cleared; other copies then sync and keep their own overrides. A swapped child replaces the main child it stands for, and neither keeps `:swap-group`. The main's authored groups are unioned with the copy's even on a repeated update; `:remote-synced` records an earlier update and must never clear those groups (F114).
|
||||
- Detach: the subtree loses component links, `:touched`, `:remote-synced`. First-level nested heads stay copies, move one nesting level up and inherit the near main's touched groups, so values their old near main overrode become overrides. A swapped head left with no enclosing copy becomes a plain copy of its own component (`:shape-ref` = its main root, no `:swap-group`).
|
||||
- Direct content sync of a swapped head leaves its placement attributes and their tokens alone (F216). The enclosing main supplies constraints, fixed-scroll and layout item attributes; syncing either source first must give the same result.
|
||||
- Reheading a swapped child on detach or clipboard copy retains placement that differs from its own content main as placement overrides (F217). Compare constraints with implicit defaults in the destination context, and fixed-scroll as a boolean; equal placement does not create groups.
|
||||
- Instantiate / nest a copy: the new subtree has no touched groups.
|
||||
- Relocate into a blocked parent: the move also locks each moved root (`generate-relocate`). A copy root whose blocked value changes gains `:modifiable-group`; predict this from the destination before the move, rather than reading the resulting touched set.
|
||||
- Duplicate a copy: the new subtree keeps the source's values and touched; if its nesting level changes, touched is inherited as in detach. Paste and move out of a copy follow the same rule.
|
||||
- Swap without keep-touched: the new subtree is clean and keeps `swap-keep-attrs` values; the new head keeps the old shape's id. Inside a copy it keeps the old `:shape-ref` and gets `:swap-group` (none when the new component is the near main's); inside a main it is a plain nested copy.
|
||||
- Variant switch with keep-touched: an attr is carried from the old copy only when its group is touched and the old and new mains hold the same value for it. Resulting touched = groups of carried attrs (+ `:swap-group` when the head is inside a copy). A value equal to the new main is not carried and not touched. Texts: the same per text group (letters carried only when both mains have the same letters; a style group when both mains agree on it once placed on each other's letters).
|
||||
- Swap without keep-touched: the new subtree keeps `swap-keep-attrs` values; the new head keeps the old shape's id. A retained rotation or flip that differs from the new component's expected placement becomes a `:geometry-group` override so later sync preserves it, including orientation inherited from the old component. The swap authors that choice. Size-only overrides clear. Orientation inherited from the position source or
|
||||
the parent stays untouched, including references into deleted mains (F154). Other content overrides clear. Inside a copy it keeps the old `:shape-ref` and gets `:swap-group` (none when the new component is the near main's); inside a main it is a plain nested copy. Swapping back produces a clean copy of the near position, including its content overrides, without authoring new groups (F176). Sync through the enclosing copy that owns the new refs; direct sync from the chosen component skips those indirect refs.
|
||||
- Variant switch with keep-touched: an attr is carried from the old copy only when its group is touched and the old and new mains hold the same value for it. Resulting touched = groups of carried attrs (+ `:swap-group` when the head is inside a copy). The root also keeps a retained rotation or flip as a geometry override when it differs from the new expected placement, including orientation supplied by the old component (F146, F175). Placement still supplied by an enclosing copy remains inherited when no root geometry override was carried. A value equal to the new main is not carried and not touched. Texts: the same per text group (letters carried only when both mains have the same letters; a style group when both mains agree on it once placed on each other's letters).
|
||||
- Delete component: copies keep their data. The deleted main cannot be edited, so it starts no sync, but changes from components nested in it still pass through: sync updates its stored shapes (`:objects` of the deleted component), its copies, and the components that nest it. Restore brings back an up-to-date main.
|
||||
- Undo/redo: restores the exact prior state, `:touched` and `:remote-synced` included, of the op and the sync it caused together (same undo group, one step). Undo never needs a re-sync.
|
||||
- Sync skips exactly equal numeric values, including integer/float forms
|
||||
inside points and selection rectangles (F187). Representation alone must
|
||||
not create changes or undo entries. This comparison has no tolerance:
|
||||
a real subpixel difference still syncs.
|
||||
|
||||
## Text overrides
|
||||
|
||||
- A text is letters (with line breaks) and a style per letter, all in `:content`. Its groups: `:text-content-text` (letters and line breaks) and one per style unit: `-family` (family, font id), `-weight` (weight, style, variant id), `-size`, `-line-height`, `-spacing`, `-decoration`, `-case`, `-fills`, `-typography` (typography reference), `-align`, `-direction` (paragraphs), `-valign` (root). Any of them implies `:content-group`. Splitting runs by styling is a style change, never a text override; an override covers the whole text, not single letters.
|
||||
- Touch: compare old and new content. Letters differ -> `:text-content-text`. A style unit is touched when a shared letter changes its value or, if the letters changed, when a value appears that the text did not have (typed letters take a neighbour's style and touch nothing). A token on the copy touches the units of the attributes it sets.
|
||||
- Merge (sync, and switch with the carried units): letters from the copy if overridden, else from the main. Each unit from the copy if overridden, else from the main (the source), placed on the result letters: (1) a source with one value across the text applies to every letter; (2) else letters both texts share (stretches of 3+ equal letters, by a letter diff) take the source's value; (3) else the value of the letter before, across line breaks; letters at the start take the first shared letter after them; with nothing shared, the source's first letter. Paragraph units follow the paragraph of the first shared letter, else the paragraph before. Adjacent runs with equal styles join.
|
||||
- Typography reference: kept on the result only when every unit the typography sets comes from the same side as the reference; a run that loses it still follows typography updates through its main.
|
||||
- Typography reference: kept on the result only when every unit the typography sets comes from the same side as the reference; a run that loses it still follows typography updates through its main. Applying a typography explicitly authors its reference and all six style units (family, weight, size, line height, spacing, case), including equal values and reapplication of an inherited asset. This differs from a raw content edit, which touches only changed units.
|
||||
- Family and weight from different sides: sync keeps the weight side's variant id; the frontend then picks the closest variant of the family.
|
||||
- Library color and typography syncs are derived writes: they never touch.
|
||||
|
||||
## Geometry ownership
|
||||
|
||||
- Copy root: position is its own; rotation/flip belong to it only when its `:geometry-group` is touched. Resizing it touches the root only.
|
||||
- Content scaling is distinct from constraint resize. `:content-scale`
|
||||
stores the accumulated scale (default 1); expected placement scales
|
||||
styles by copy/main scale before syncing. Descendants remain untouched;
|
||||
later main style edits still reach them at that scale. Reset restores
|
||||
the near main's scale together with its geometry and styles.
|
||||
- Children of a resized or transformed shape: derived (expected geometry), untouched, and still follow later main edits. Code: a transform touches only the shapes the user transformed (`clp/calculate-ignore-tree` takes their ids; the frontend keeps them in `:workspace-modifiers-ids`); sync places the main subtree of a copy shape with its own geometry like that shape before walking its children.
|
||||
- Layout-owned (never touched; sync writes, then reflow): x/y of non-absolute children of flex/grid frames; width/height on axes sized fill, or auto on a layout frame.
|
||||
- Grid copy cell overrides do not own untouched track lists. Inherit shrinking track counts, move or shorten affected cells, preserve their other metadata, and retain explicit track-list overrides (user decision, F247). Do not retain extra tracks solely to keep out-of-bounds cell coordinates; the existing minimum-track rule for participating children still applies.
|
||||
- Grow-owned (never touched; sync writes, then re-measure on SVG and WASM): width+height of auto-width text, height of auto-height text. Every editor and resize path writes the measured size as derived; on WASM `sync-file` re-measures the auto-grow texts of the current page it wrote (texts on other pages keep the synced size until measured).
|
||||
- Transform settlement corrects geometry on the existing copy subtree
|
||||
(F223). Its sync proposal must not pull pending library content, styles
|
||||
or structure. Path content can carry geometry; text content cannot.
|
||||
- `set-shape-attr`'s `ignore-geometry` does not cover `:width`/`:height`; a derived size write needs `ignore-touched` (transforms get it from the ignore tree).
|
||||
- Repairs are not overrides: `files/repair` writes with `ignore-touched`; only the text repairs set groups, explicitly.
|
||||
|
||||
@ -60,3 +77,28 @@ Intended semantics of copies, `:touched` and component sync. This is the spec: w
|
||||
|
||||
- `{:type :set-touched}` replaces `:touched` wholesale and only on copies (an empty set is dropped). The builders write only it (`pcb/update-shapes` turns a `:touched` change into it); `{:type :set :attr :touched}`, a raw assoc with no copy guard, is still applied for stored changes.
|
||||
- Builders that write to copies must emit the inverse `:set-touched` in undo (as `pcb/update-shapes` does).
|
||||
|
||||
A parent turn settles swapped descendant placement in the transform's
|
||||
change builder (F182). Its content and position reference can have different
|
||||
sizes, so rotating the content rigidly can leave its untransformed anchor
|
||||
different from full sync. Keep the swapped head/children untouched and put
|
||||
the derived correction in the same undo group. Authored geometry stays.
|
||||
|
||||
Reset drops the root's geometry override from the whole sync context
|
||||
(F185), including the branch that clones replacement children. Clearing it
|
||||
only while updating existing shapes can turn a newly added child by the
|
||||
old override after its parent has already reset. The reset and replacement
|
||||
children share one undo group and stay stable through later sync.
|
||||
|
||||
Update-main also settles untouched swapped heads carried through a parent
|
||||
turn in the updated main (F186). A rigid rotation can leave the wrong
|
||||
anchor when the replaced position and swap content have different sizes.
|
||||
Apply the main's nonlocal changes to its own file, settle changed placement,
|
||||
and append those changes to the same inverse-sync group. Keep the source
|
||||
copy's local changes routed separately, including for linked libraries.
|
||||
|
||||
Detach settles inherited placement for surviving swapped heads whose
|
||||
position references advance to another frame (F219). A rotated head's old
|
||||
and new position frames can have different dimensions. Correct the head
|
||||
and children in detach's own undo group, without pulling content from the
|
||||
new reference or creating a geometry override. Authored geometry stays.
|
||||
|
||||
@ -20,6 +20,14 @@ After a geometric mutation, equivalent fields such as `:y`, `(:y :selrect)`, and
|
||||
- `gsh/transform-shape`: applies a full transform.
|
||||
- `cts/setup-shape`: initializes geometry for new shapes; variant test helpers such as `thv/add-variant-with-child` use it.
|
||||
|
||||
## Flip flags through parent placement
|
||||
|
||||
When composing a parent's orientation onto content, compose flip flags from
|
||||
the source shape and the origin/target parent frames. Matrix decomposition
|
||||
can set both flags during a large rotation, even when several smaller
|
||||
rotations authored neither flip (F170). Keep the original nil/false value
|
||||
when the parent frames do not change that axis's flip.
|
||||
|
||||
## Edits that break the invariant
|
||||
|
||||
- `(assoc shape :x ...)` or `(assoc shape :y ...)`: updates only one field and leaves `:selrect` / `:points` stale.
|
||||
@ -45,4 +53,4 @@ Using `(ths/update-shape file label :y 101)` leaves `:selrect.y` stale. Downstre
|
||||
|
||||
When a copy shape changes geometry through the proper pipeline (`set-shape-attr` via `process-operation :set`), `:touched` gains `:geometry-group` unless ignored. Tests can either drive the production update with `cls/generate-update-shapes`, or inject `(assoc shape :touched #{:geometry-group})` when only touched state matters.
|
||||
|
||||
If a test needs both a new position and touched state, move the shape first with geometry-preserving helpers, then inject or assert touched state.
|
||||
If a test needs both a new position and touched state, move the shape first with geometry-preserving helpers, then inject or assert touched state.
|
||||
|
||||
@ -5,6 +5,13 @@
|
||||
- Layout container data and child layout-item data are removed by different helpers. Do not assume clearing a layout frame also clears all child layout metadata.
|
||||
- Layout data can affect both container attrs and immediate child attrs; validate behavior for both sides when changing cleanup or propagation.
|
||||
|
||||
## Empty flex layouts
|
||||
|
||||
- No children means no layout lines. Skip stretch-per-line division and
|
||||
baseline placement when the line count is zero. Both row and column
|
||||
layouts can become empty after component sync; resizing them must still
|
||||
return valid layout data (F169).
|
||||
|
||||
## Grid assignment
|
||||
|
||||
- Grid `assign-cells` ensures at least one column and row, skips absolute-position children, creates non-tracked rows/cols when children exceed tracked cells, and asserts that assigned cells do not overlap.
|
||||
@ -13,4 +20,4 @@
|
||||
- The `:reorder-children` change it emits is refused on parents inside component copies unless `allow-altering-copies` (same rule as `:mov-objects`); `pcb/reorder-grid-children` also skips copy grids producer-side. Copy child order is owned by the component sync engine.
|
||||
- Grid deassignment removes cells for shapes that are no longer direct children or have become absolute-positioned.
|
||||
- Auto-positioning is not just sorting: some auto cells are converted to manual when empty/manual/span state would break the auto sequence, then auto single-span items can be compacted.
|
||||
- `fix-overlaps` is marked dev-only and removes one overlapping cell, preferring empty cells first. Avoid depending on it as normal production repair.
|
||||
- `fix-overlaps` is marked dev-only and removes one overlapping cell, preferring empty cells first. Avoid depending on it as normal production repair.
|
||||
|
||||
@ -97,3 +97,130 @@ For geometry-sensitive tests, read `mem:common/geometry-invariants` before posit
|
||||
## Debugging
|
||||
|
||||
Use `mem:common/component-debugging-recipes` for shape-tree dumps, undo/change inspection, and temporary live instrumentation recipes.
|
||||
|
||||
## Composable undo comparison
|
||||
|
||||
`comp/undo-check` keeps normalized snapshots exact, including `:touched` and
|
||||
`:remote-synced`. Comparison permits only absolute floating noise below 1e-10
|
||||
inside shape geometry: x/y, width/height, rotation, points, selrect and transform
|
||||
matrices. Reflow can recompute 0.01 as 0.010000000000005116 after undo (F130).
|
||||
This tolerance does not apply to opacity, other authored attrs or touched groups.
|
||||
The regression rejects a 1e-5 height change and a 5e-15 opacity change.
|
||||
|
||||
|
||||
## Generated component programs
|
||||
|
||||
`composable/gen` builds seeded EDN programs and resolves targets from current
|
||||
shape-tree order. Run `common-tests.logic.composable-gen-test`; set
|
||||
`PENPOT_GEN_NUM` and `PENPOT_GEN_SEED` to replay a count and seed. Before merge,
|
||||
Phase 4 requires 5000 scenarios per property. `cg/run` accepts the printed
|
||||
program and an optional expected trace; changed targets or skips fail replay.
|
||||
Use separate fresh JVMs for concurrent checks: `world` resets the global test
|
||||
label map, so concurrent futures in one JVM corrupt each other's fixtures.
|
||||
|
||||
The independent shadow tracks authored groups and values; the oracle checks
|
||||
validation, touched membership, retained values, propagation and geometry.
|
||||
Settlement also checks partial/full sync equivalence, idempotence and exact
|
||||
undo/redo snapshots. Library routing in `comp/files` applies both the working
|
||||
file and auxiliary file changes, then cascades both in the same undo group.
|
||||
|
||||
Stale-library and dependency generation includes source transforms on main
|
||||
roots/children, letters and all twelve text style units. `:library-text true`
|
||||
adds a separate source text component without reusing consumer shape IDs.
|
||||
Source edits keep consumer history separate and copies stale until an
|
||||
acceptance or command that explicitly refreshes that subtree. Requested
|
||||
source geometry/text checks use the source editor's before-state and intent;
|
||||
dropped source edits must fail I9. `common-tests.logic.source-gen-test`
|
||||
covers the action matrix and independent source/consumer undo histories.
|
||||
|
||||
Backend parity uses `oracle/canonical` and `oracle/equivalent?`: IDs become
|
||||
file/page/tree paths, flip
|
||||
nil/false values become booleans, and derived layout/text dimensions and text
|
||||
run splitting are omitted. Free copy-head placement after leaving a layout is
|
||||
also omitted: pure execution has no reflow history. Each backend still checks
|
||||
child offsets and propagation; a changed child offset fails the comparison.
|
||||
These exclusions do not apply to undo snapshots or authored scalar values.
|
||||
Swapped-head constraints and layout-item inputs use the position reference;
|
||||
content inputs use the component's content main.
|
||||
|
||||
|
||||
For long generated JVM checks, bound heap growth with -J-Xmx1536m (adjust
|
||||
only if a run reports a real heap limit failure). Several uncapped JVMs can
|
||||
fill host RAM and swap and make browser checks time out before tests start.
|
||||
Keep concurrency low; use fresh processes for test-label isolation.
|
||||
|
||||
Canonical design data keeps unrounded geometry. Matrices are represented
|
||||
by their effect on local shape bounds, so their tolerance has pixel units
|
||||
rather than comparing dimensionless coefficients (F153). Undo snapshots
|
||||
and golden masters keep raw matrices. Use oracle/equivalent? to compare
|
||||
it: the absolute 0.01 tolerance applies only inside shape geometry. Rounding
|
||||
first can split two positions 7e-7 px apart across a 0.005 boundary (F150).
|
||||
Scalar values and touched stay exact. comp/undo-check/same-state? supplies
|
||||
the shared comparison; its undo default remains 1e-10.
|
||||
|
||||
Measured auto-width/auto-height text compares its oriented first corner,
|
||||
not the unrotated selrect x/y, which can move as height/width changes
|
||||
(F220). Canonical comparison and requested geometry both retain that
|
||||
anchor at the existing 0.01 tolerance. Layout-owned positions remain
|
||||
derived; fixed text dimensions and raw undo geometry remain checked.
|
||||
|
||||
Swapped-head dimensions use the content main; position, rotation, flips,
|
||||
constraints and layout-item inputs use the position source (F151).
|
||||
When sizes differ, expected geometry keeps the position source's
|
||||
untransformed top-left anchor after resizing. Resizing around a rotated
|
||||
corner shifts that anchor and creates a false I4 failure (F167).
|
||||
A detached swapped head that becomes a plain copy loses swap-group without
|
||||
inheriting its former position's groups. Descendants whose refs do not change
|
||||
keep their existing shadow groups (F155).
|
||||
|
||||
For free copy-head placement, expected geometry keeps the placement matrix
|
||||
it applied. Re-decomposing a 0.01px frame can add scale noise that becomes
|
||||
a .011px error in its larger children (F161). Child geometry, scalar values
|
||||
and undo comparisons remain checked; this does not widen their tolerance.
|
||||
|
||||
Detach's shadow expresses inherited geometry in the surviving copy's frame
|
||||
before merging groups (F163). Compute orientation from the source and copy
|
||||
before detaching, never from the resulting child, whose geometry is checked.
|
||||
|
||||
The switch shadow compares numeric geometry of the two mains with float
|
||||
tolerance too (F164). A 1e-12 size difference must keep a resize override;
|
||||
a 1px difference must discard it. Nongeometry values remain exact.
|
||||
|
||||
Expected child placement takes unit axis directions from the parent
|
||||
matrices. Resize already runs through dimensions and constraints; a
|
||||
minimum-size clamp can leave residual matrix scale that must not resize
|
||||
fixed children again (F173). Canonical matrices and undo remain raw. The
|
||||
fixture still rejects a real100→80px fixed-child height change.
|
||||
|
||||
Update-main's shadow uses the source values and the new near reference to
|
||||
predict content overrides when a pushed swap becomes an ordinary nested
|
||||
copy (F174). Read the reference id from the new shape for correspondence,
|
||||
but never read its resulting values or touched groups to decide what the
|
||||
user authored. The negative control corrupts both promoted head and child
|
||||
fills and still predicts the source fills.
|
||||
|
||||
A switch retains orientation supplied by the old component even when the
|
||||
old copy has no geometry override (F175). Predict this choice from the old
|
||||
root and the new expected parent placement. A negative control removes the
|
||||
new root's rotation; the shadow must still expect the old angle. Ordinary
|
||||
position inheritance after swapping back must sync without creating new
|
||||
groups (F176); the same shrunk program runs through the pure and async
|
||||
frontend paths.
|
||||
|
||||
Retained orientation must merge into a geometry group that already carries
|
||||
size (F178). Its presence does not mean the angle was carried: the two
|
||||
variant mains can agree on size and disagree on rotation. The control keeps
|
||||
the expected80px height and90deg angle even if the result loses its angle.
|
||||
|
||||
Duplicate candidates and pure Duplicate nodes use cld/allow-duplicate?, the
|
||||
normal frontend eligibility guard (F181). Finite repeated component nesting
|
||||
can still be unsafe to duplicate inside its main; the portable regression
|
||||
checks refusal, mixed batches and allowed ALT duplication at the page root.
|
||||
This is an operation precondition, not an oracle exception.
|
||||
|
||||
The switch shadow follows an authored swapped near head to its content
|
||||
main, using the model's swap group and component identity (F184). Following
|
||||
the replaced position instead can lose an inherited fill override. Keep
|
||||
these choices independent of the resulting touched set and values. The
|
||||
negative control ignores a different fill on the replaced position and
|
||||
still expects the authored fill if the switch result is corrupted.
|
||||
|
||||
@ -76,8 +76,8 @@ Layout:
|
||||
real frontend), `comp/sync_test.cljs` (one `t/async` deftest per shared case; registered in
|
||||
`frontend_tests/runner.cljs`).
|
||||
- JVM/JS: `common-tests.logic.composable-sync-test` runs the shared cases through the pure
|
||||
runner; all except those that need frontend code: N, Z, AI and the rotation case (placement
|
||||
step), X (pending sync), AJ (reflow), AT, AU, AV, AX (variant action events).
|
||||
runner; all except those that need frontend code: Z and AI (layout reflow), X (pending sync), AJ (reflow), AT, AU, AV, AX
|
||||
(variant action events). N and the rotation case also run on the JVM.
|
||||
|
||||
Judging (both runners): each variant is judged before the next one runs (`r/run-each`, and the
|
||||
interpreter's `check`), while the label map still names its shapes; a variant whose inline
|
||||
@ -109,15 +109,17 @@ Two pure runners (no store, JVM + CLJS):
|
||||
between cascade passes, where an outer copy still points at the component its main dropped
|
||||
(`:component-id-mismatch`), nor with `{:sync? false}`. Assembly ops (create/instantiate/nest/variant
|
||||
container): no sync, no undo group. `n/reset` (`reset-copy-instance` resets a lineage's latest copy) is a user op (sync +
|
||||
undo); the interpreter sends `dwl/reset-component`. `{:sync? false}` disables sync. `Rotate`/`ChangeHeight`/`MoveShape`
|
||||
are `:frontend-only` and throw `::runner/frontend-only` (their modifiers come from frontend events; the placement step itself is common, `app.common.logic.placement`). Swap and switch nodes use the production
|
||||
undo); the interpreter sends `dwl/reset-component`. `{:sync? false}` disables sync.
|
||||
`Rotate` and `ChangeHeight` are shared user operations. Their pure modifiers
|
||||
use CLJC constraints and `app.common.logic.placement`; the frontend interpreter
|
||||
still drives the workspace events. `MoveShape` remains frontend-only. Swap and switch nodes use the production
|
||||
`clv/generate-component-swap-in-place` (+ `clv/find-switch-target` for switch), the same code the
|
||||
frontend events call. Not modelled: the `:modified-at` bump, and the swap/switch event follow-ups
|
||||
(token propagation, WASM text resize, layout update). Tests:
|
||||
`common-tests.logic.composable-runner-test`.
|
||||
- Undo/redo round trip (`comp/undo_check.cljc`, alias `uc`), on by default in the pure runner
|
||||
(`:undo-check?`): after each `:user` step that pushed a group, undo must give back the
|
||||
normalized file before it and redo the file after it (the variant continues from the redone
|
||||
normalized files before it and redo the files after it (the variant continues from the redone
|
||||
file); a user step that pushed nothing must change nothing (`:no-undo-entry`); at the end,
|
||||
undo back to the last assembly step (the baseline; a case's own undo below it moves it) and
|
||||
redo all. Files compare through `app.common.test-helpers.normalize` (`thn/normalize-file`:
|
||||
@ -137,6 +139,11 @@ Two pure runners (no store, JVM + CLJS):
|
||||
workspace undo index (`:undo-index`/`:redo-index` phases): a step must add exactly one undo
|
||||
entry or group. File installs (assembly ops) are its baselines; a skipped optional and an inline `Test` are not. The interpreter
|
||||
empties `:workspace-undo` per variant. Frontend snapshots drop `:position-data` under WASM.
|
||||
Both runners use `uc/snapshot-files` for the current file and every
|
||||
auxiliary/library file. File differences prefix signatures with
|
||||
`[:file <label> ...]`. Normalization also drops library `:synced-at`,
|
||||
a server status stamp rather than design data. `ftm/snapshot` exposes
|
||||
the same snapshot to cross-file undo regressions.
|
||||
Undo groups get lost in derived work: `initialize-shape-layout` buffers `:layout/update`
|
||||
without its `:undo-group` (F43), so a swap's reflow lands in entries of its own. Match
|
||||
steps by node identity, never by record type or rendered name: `n/MoveChild` does not resolve
|
||||
@ -245,9 +252,7 @@ synchronously); an async hop without a pending task makes steps resolve early. T
|
||||
`frontend-tests.composable-tests.completion-contract-test` (slowed-down sync via a mocked
|
||||
`dwl/sync-file`), `frontend-tests.data.workspace-sync-barrier-test`. Re-reads `:file` each step
|
||||
so the shared accessors keep working.
|
||||
WASM-SHAPE IMMUNITY: a test that starts the WASM renderer leaves `cts/wasm-enabled?` on, which
|
||||
makes every later shape a proxy that leaves out nil and false attributes; `fixture` turns it off
|
||||
for the composable tests and restores it after, so they run on records in any order.
|
||||
WASM-SHAPE IMMUNITY: renderer tests can leave `cts/wasm-enabled?` on; `fixture` disables it and restores it afterward, so composable cases use records in any order. Proxy boundary tests opt in explicitly. Fresh proxies retain every Shape base field, including nil flips, matching record construction/dissoc and preserving exact undo (F203).
|
||||
STORE-SWAP IMMUNITY: other test namespaces `set!` `st/state`/`st/stream` and never restore, while
|
||||
the `app.main.refs` lenses stay bound to the ORIGINAL atoms — propagation then dies silently. The
|
||||
interpreter captures the atoms at namespace-load time and re-`set!`s them per variant.
|
||||
@ -275,8 +280,8 @@ reproduce what the real measurement commits (F37: `commit-position-data`).
|
||||
as an error of its case and the next variant runs. `(optional (in-sequence …))` is not flattened for the interpreter — use
|
||||
independent optionals (nested choices are fine). The Serena/clj-kondo cache for `nodes.cljc` goes stale (phantom symbols) —
|
||||
trust the build. Cross-namespace global-state leaks land in this suite first; suspect them before
|
||||
the framework on inexplicable full-run-only failures. Case H's `sync-file` schedules a delayed RPC
|
||||
that fails headless (benign; absorbed by per-op grace).
|
||||
the framework on inexplicable full-run-only failures. Case H's `sync-file` schedules a delayed library-status RPC. Fixed and generated
|
||||
cases mock RPC and the delay timer for the whole async replay.
|
||||
|
||||
---
|
||||
|
||||
@ -308,7 +313,9 @@ Distinguishing abstractions (the OOP articulation of the shared principles):
|
||||
each other. `OpCreateNestableComponent(strategy, name)` prefixes its roles with `name`; give
|
||||
every extra lineage in a case a name.
|
||||
- `OpDetach`/`OpSwap`/`OpReset` wait for pending propagation before acting (a script could
|
||||
otherwise act inside the sync window, which no user can). `swapComponent` keeps touched (F33).
|
||||
otherwise act inside the sync window, which no user can). `swapComponent` follows the UI:
|
||||
ordinary swaps clear content overrides and retain orientation; switches
|
||||
within one variant set carry matching overrides.
|
||||
The suite pins published `@penpot/plugin-types` 1.4.2, which lacks `resetOverrides` (typed cast).
|
||||
- Known bugs: `Assert.knownFailure(bug, expected, pinned, actual, equals)` (same order as `tm/known-failure`), the counterpart of
|
||||
`tm/known-failure`.
|
||||
@ -330,3 +337,37 @@ Details: README, "Running in CI".
|
||||
## Substrate
|
||||
`mem:common/testing`, `mem:common/component-data-model`, `mem:common/component-swap-pipeline`,
|
||||
`mem:frontend/testing`.
|
||||
|
||||
|
||||
## Seeded random replay
|
||||
|
||||
`common-tests.logic.composable-gen-test` checks EDN programs through common.
|
||||
`frontend-tests.composable-tests.generated-test/replay` accepts the same EDN
|
||||
(including a shrunk failure), checks target/skip traces, and drives real events
|
||||
with per-step barriers and undo/redo. Its independent model maps shapes between
|
||||
backends by file/page/tree path, including auxiliary library files. UpdateMain
|
||||
passes the target shape's component-file to update-component-sync. Refresh both
|
||||
the working file and libraries after each step; strip installed library-of
|
||||
metadata only from the portable situation, never from undo snapshots.
|
||||
|
||||
Plugin `RandomCompositions` uses the real Plugin API and its own visible fill
|
||||
and opacity model. It waits for waitForLayoutUpdate with a hard deadline;
|
||||
there is no fixed-delay fallback. Live WASM checks use ws1 and enable plugin
|
||||
flags naturalChildOrdering and throwValidationErrors. When browser automation
|
||||
runs in a background tab, foreground it (and use CDP focus emulation if needed)
|
||||
before diagnosing a timeout: background timers can wait a minute per step.
|
||||
Verify initialized WASM, no workspace exception and empty pending reflow.
|
||||
|
||||
Rotate nodes take a delta angle. The interpreter must pass delta?true to
|
||||
increase-rotation; its default sets an absolute angle. A45deg turn followed
|
||||
by90deg must end135deg on both backends (F171).
|
||||
|
||||
## Suite choice after Phase 4
|
||||
|
||||
Keep CLJS replay as the composable regression suite, backed by shared common
|
||||
generation and test.check shrinking. Keep the plugin for public API, WASM,
|
||||
font loading and measured-text smoke checks. Retain its fixed cases until
|
||||
equivalent coverage replaces them; do not build a third full random model
|
||||
for parity. Pure common checks cannot expose async undo/measurement order
|
||||
errors such as F137/F152. Compare coverage and CI cost separately: timings
|
||||
collected during stress runs do not prove either suite is faster.
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -18,4 +18,14 @@
|
||||
|
||||
- WASM modifier updates set plugin/local props with parsed geometry/structure modifiers rather than directly mutating file data.
|
||||
- The position-data recomputation watcher ignores commits tagged `:position-data`; keep that tag when adding derived position-data commits.
|
||||
- Rotation has separate WASM and non-WASM event paths. Check both when changing rotation modifier semantics.
|
||||
- Rotation has separate WASM and non-WASM event paths. Check both when changing rotation modifier semantics.
|
||||
|
||||
## Settling swapped placement after a parent turn
|
||||
|
||||
Both modifier commit paths set settle-component-placement? (F182). The
|
||||
update-shapes builder settles untouched swapped heads after parent bounds
|
||||
update, before the single commit. A swapped head can keep its content size
|
||||
while its position reference has another size; a rigid turn alone then
|
||||
leaves placement different from full sync. Preserve authored geometry and
|
||||
join derived placement to the transform's undo group. The common helper
|
||||
compares matrix axes as well as rotation/flip metadata for the WASM path.
|
||||
|
||||
@ -67,8 +67,8 @@
|
||||
removal too; a copy's own token survives.
|
||||
AZ — a nested copy pasted out of its main keeps the overrides the main
|
||||
gave it (F17).
|
||||
N — main edits reach rotated copies (frontend only).
|
||||
Rotation — a touched copy child survives a main rotation (frontend only too)."
|
||||
N — main edits reach rotated copies.
|
||||
Rotation — a touched copy child survives a main rotation."
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.files.helpers :as cfh]
|
||||
@ -1614,7 +1614,7 @@
|
||||
(t/is (empty? (:touched copy))))))))}))
|
||||
|
||||
(defn geometry-sync-with-rotated-instances
|
||||
"Case N (frontend only). Optionally the copy rotates, optionally the main
|
||||
"Case N. Optionally the copy rotates, optionally the main
|
||||
rotates, then the main child changes its fill or its height. The change
|
||||
reaches the copy child. A copy root's rotation is inherited content that a
|
||||
copy may override: the copy shows its own rotation, else the main's, else
|
||||
@ -1676,7 +1676,7 @@
|
||||
(t/is (empty? (:touched (setup/copy-root s))))))}))
|
||||
|
||||
(defn touched-copy-child-survives-main-rotation
|
||||
"Frontend only. A copy rotates its root and resizes its child, then the
|
||||
"A copy rotates its root and resizes its child, then the
|
||||
main rotates. The child's touched :geometry-group shields it: its height
|
||||
and its position relative to the copy root do not change."
|
||||
[]
|
||||
|
||||
298
common/src/app/common/test_helpers/composable/comp/files.cljc
Normal file
298
common/src/app/common/test_helpers/composable/comp/files.cljc
Normal file
@ -0,0 +1,298 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns app.common.test-helpers.composable.comp.files
|
||||
"File routing for the pure composable runner, including library inverses."
|
||||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.test-helpers.composable.core :as tm]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.file :as ctf]))
|
||||
|
||||
(defn all-files
|
||||
[situation]
|
||||
(assoc (tm/aux-files situation) (:id (tm/file situation)) (tm/file situation)))
|
||||
|
||||
(defn libraries
|
||||
"Loaded library data, including unaccepted updates, as in the editor."
|
||||
[situation]
|
||||
(all-files situation))
|
||||
|
||||
(defn reference-libraries
|
||||
"Oracle inputs last used by this copy. Reset/swap can refresh one subtree
|
||||
while other copies still reflect an older library version. These inputs
|
||||
never replace the loaded data supplied to production operations."
|
||||
([situation shape]
|
||||
(reference-libraries situation (:id (tm/file situation)) (:id shape)))
|
||||
([situation file-id shape-id]
|
||||
(let [files (all-files situation)]
|
||||
(assoc (merge files
|
||||
(get-in situation [:accepted-libraries file-id])
|
||||
(get-in situation [:shape-libraries file-id shape-id]))
|
||||
file-id (get files file-id)))))
|
||||
|
||||
(defn object-trees
|
||||
[file]
|
||||
(concat (map :objects (vals (get-in file [:data :pages-index])))
|
||||
(keep (fn [component] (when (:deleted component) (:objects component)))
|
||||
(vals (get-in file [:data :components])))))
|
||||
|
||||
(defn component-shapes
|
||||
[file component]
|
||||
(let [objects (if (:deleted component) (:objects component)
|
||||
(get-in file [:data :pages-index (:main-instance-page component) :objects]))]
|
||||
(cfh/get-children-with-self objects (:main-instance-id component))))
|
||||
|
||||
(defn dependent-components
|
||||
[file source-id component-ids]
|
||||
(into #{}
|
||||
(keep (fn [component]
|
||||
(when (some #(and (:shape-ref %) (= source-id (:component-file %))
|
||||
(contains? component-ids (:component-id %)))
|
||||
(component-shapes file component))
|
||||
(:id component))))
|
||||
(vals (get-in file [:data :components]))))
|
||||
|
||||
(defn affected-components
|
||||
"Same-file dependents, predicted from definitions before running sync."
|
||||
[file component-ids]
|
||||
(loop [ids (set component-ids)]
|
||||
(let [next-ids (into ids (dependent-components file (:id file) ids))]
|
||||
(if (= ids next-ids) ids (recur next-ids)))))
|
||||
|
||||
(defn remember-subtree
|
||||
[situation file-id root-id inputs]
|
||||
(if-not (:accepted-libraries situation)
|
||||
situation
|
||||
(let [file (get (all-files situation) file-id)
|
||||
objects (first (filter #(contains? % root-id) (object-trees file)))
|
||||
container (ctn/make-container {:objects objects} :page)
|
||||
shapes (cfh/get-children-with-self objects root-id)
|
||||
source-id (:component-file (get objects root-id))
|
||||
inputs (assoc inputs file-id file)
|
||||
retained (into {}
|
||||
(mapcat (fn [shape]
|
||||
(when (and (not= root-id (:id shape)) (ctk/swapped? shape))
|
||||
(when-let [prior (get-in situation [:shape-libraries file-id (:id shape)])]
|
||||
;; a reset inside the swap may have refreshed a descendant's own
|
||||
(map #(vector (:id %) (get-in situation [:shape-libraries file-id (:id %)] prior))
|
||||
(cfh/get-children-with-self objects (:id shape)))))))
|
||||
shapes)]
|
||||
(reduce (fn [situation shape]
|
||||
(if-not (:shape-ref shape)
|
||||
situation
|
||||
(let [source (when-not (ctk/swapped? shape)
|
||||
(ctf/find-ref-shape file container inputs shape
|
||||
:include-deleted? true :with-context? true))
|
||||
inherited (when (:shape-ref source)
|
||||
(reference-libraries situation (get-in (meta source) [:file :id]) (:id source)))
|
||||
;; Retained swaps keep their content inputs. Ordinary
|
||||
;; images inherit their near copy's accepted inputs.
|
||||
;; This pull refreshes only its own source boundary.
|
||||
sources (-> (merge inputs inherited (get retained (:id shape)))
|
||||
(assoc source-id (get inputs source-id))
|
||||
(dissoc file-id))]
|
||||
(assoc-in situation [:shape-libraries file-id (:id shape)] sources))))
|
||||
situation shapes))))
|
||||
|
||||
(defn inherit-references
|
||||
"Give the subtree of `to-id`, a duplicate of the subtree of `from-id` in
|
||||
file `file-id`, the oracle inputs of the shapes it copies: a duplicate of a
|
||||
stale copy holds that copy's values."
|
||||
[situation file-id from-id to-id]
|
||||
(if-not (:accepted-libraries situation)
|
||||
situation
|
||||
(let [objects (first (filter #(contains? % to-id) (object-trees (get (all-files situation) file-id))))
|
||||
pairs (fn pairs [from to]
|
||||
(cons [from to]
|
||||
(mapcat pairs (:shapes (get objects from)) (:shapes (get objects to)))))]
|
||||
(reduce (fn [situation [from to]]
|
||||
(if (:shape-ref (get objects to))
|
||||
(assoc-in situation [:shape-libraries file-id to]
|
||||
(dissoc (reference-libraries situation file-id from) file-id))
|
||||
situation))
|
||||
situation (pairs from-id to-id)))))
|
||||
|
||||
(defn remember-copies
|
||||
[situation file-id source-id component-ids inputs]
|
||||
(if-not (:accepted-libraries situation)
|
||||
situation
|
||||
(let [source (get inputs source-id)
|
||||
source-shape-ids (into {}
|
||||
(map (fn [id]
|
||||
[id (into #{} (map :id)
|
||||
(component-shapes source (get-in source [:data :components id])))]))
|
||||
component-ids)]
|
||||
(reduce (fn [situation shape]
|
||||
(if (and (:shape-ref shape) (= source-id (:component-file shape))
|
||||
(contains? component-ids (:component-id shape))
|
||||
;; Normal sync refreshes direct copies. An indirect
|
||||
;; image still follows its enclosing component's
|
||||
;; accepted definition, even if this source is newer.
|
||||
(or (ctk/swapped? shape)
|
||||
(contains? (get source-shape-ids (:component-id shape)) (:shape-ref shape))))
|
||||
(remember-subtree situation file-id (:id shape) inputs)
|
||||
situation))
|
||||
situation (mapcat vals (object-trees (get (all-files situation) file-id)))))))
|
||||
|
||||
(defn freeze-libraries
|
||||
"Remember initial oracle baselines without hiding loaded library data."
|
||||
[situation]
|
||||
(let [files (all-files situation)]
|
||||
(assoc situation :accepted-libraries
|
||||
(into {} (map (fn [id] [id (dissoc files id)])) (keys files)))))
|
||||
|
||||
(defn accept-library
|
||||
[situation library-id]
|
||||
(if (:accepted-libraries situation)
|
||||
(assoc-in situation [:accepted-libraries (:id (tm/file situation)) library-id]
|
||||
(get (all-files situation) library-id))
|
||||
situation))
|
||||
|
||||
(defn- with-files
|
||||
[situation files]
|
||||
(let [id (:id (tm/file situation))]
|
||||
(-> situation
|
||||
(tm/with-file (get files id))
|
||||
(tm/with-aux-files (dissoc files id)))))
|
||||
|
||||
(defn route
|
||||
"Tag changes destined for another file, preserving their original order."
|
||||
[changes file-id]
|
||||
(let [tag #(mapv (fn [change]
|
||||
(cond-> change (nil? (::destination change)) (assoc ::destination file-id))) %)]
|
||||
(-> changes (update :redo-changes tag) (update :undo-changes tag))))
|
||||
|
||||
(defn route-update-main
|
||||
[changes current-id main-id]
|
||||
(let [tag (fn [change]
|
||||
(cond-> (dissoc change :local-change?)
|
||||
(and (not (:local-change? change)) (not= current-id main-id))
|
||||
(assoc ::destination main-id)))
|
||||
tag-all #(mapv tag %)]
|
||||
(-> changes (update :redo-changes tag-all) (update :undo-changes tag-all))))
|
||||
|
||||
(defn apply-changes
|
||||
"Apply each consecutive run to its file, stripping runner routing metadata."
|
||||
([situation changes] (apply-changes situation changes :redo-changes))
|
||||
([situation changes side]
|
||||
(let [current-id (:id (tm/file situation))]
|
||||
(with-files situation
|
||||
(reduce (fn [files group]
|
||||
(let [id (or (::destination (first group)) current-id)
|
||||
file (get files id)]
|
||||
(when-not file
|
||||
(throw (ex-info "Missing composable change destination" {:file-id id})))
|
||||
(assoc files id
|
||||
(thf/apply-changes file
|
||||
{:redo-changes (mapv #(dissoc % ::destination) group)}
|
||||
:validate? false))))
|
||||
(all-files situation)
|
||||
(partition-by #(or (::destination %) current-id) (get changes side)))))))
|
||||
|
||||
(defn changed-components
|
||||
([before changes]
|
||||
(let [current-id (:id (tm/file before))
|
||||
files (all-files before)]
|
||||
(into #{}
|
||||
(mapcat (fn [[id group]]
|
||||
(let [data (:data (get files id))]
|
||||
;; The editor syncs the changed components its file owns.
|
||||
(filter #(contains? (:components data) %)
|
||||
(cll/changed-components data {:redo-changes group})))))
|
||||
(group-by #(or (::destination %) current-id) (:redo-changes changes)))))
|
||||
([before after changes]
|
||||
(into (changed-components before changes)
|
||||
(mapcat (fn [libraries] (mapcat val libraries)))
|
||||
(vals (:library-pulls after)))))
|
||||
|
||||
(defn- sync-local
|
||||
[situation file-id ids]
|
||||
(let [files (all-files situation)
|
||||
context (-> situation
|
||||
(tm/with-file (get files file-id))
|
||||
(tm/with-aux-files (dissoc files file-id)))
|
||||
result (cll/generate-sync-components-cascade (pcb/empty-changes) file-id ids (libraries context)
|
||||
(:id (tm/file situation)))
|
||||
changes (route (:changes result) file-id)]
|
||||
{:situation (-> (with-files situation (assoc-in files [file-id :data] (:data result)))
|
||||
(remember-copies file-id file-id
|
||||
(affected-components (get files file-id) ids) files))
|
||||
:component-ids (affected-components (get files file-id) ids)
|
||||
:syncs (if (seq (:redo-changes changes)) [changes] [])}))
|
||||
|
||||
(defn- pull-components
|
||||
[situation consumer-id library-id component-ids]
|
||||
(reduce (fn [{:keys [situation syncs]} component-id]
|
||||
(let [inputs (all-files situation)
|
||||
consumer (get inputs consumer-id)
|
||||
result (cll/generate-sync-file-cascade
|
||||
(pcb/empty-changes) nil :components consumer-id component-id library-id
|
||||
inputs (:id (tm/file situation)))
|
||||
changes (route (:changes result) consumer-id)
|
||||
dependents (affected-components consumer
|
||||
(dependent-components consumer library-id #{component-id}))
|
||||
updated (-> (apply-changes situation changes)
|
||||
(remember-copies consumer-id library-id #{component-id} inputs)
|
||||
(remember-copies consumer-id consumer-id dependents inputs))]
|
||||
{:situation updated
|
||||
:syncs (cond-> syncs (seq (:redo-changes changes)) (conj changes))}))
|
||||
{:situation situation :syncs []} (sort-by str component-ids)))
|
||||
|
||||
(defn- sync-independent-world
|
||||
[situation component-ids]
|
||||
(let [files (all-files situation)
|
||||
owners (into {} (mapcat (fn [[id file]]
|
||||
(map #(vector % id) (keys (get-in file [:data :components]))))) files)]
|
||||
(reduce
|
||||
(fn [{:keys [situation syncs]} [file-id ids]]
|
||||
(let [settled (sync-local situation file-id ids)]
|
||||
(reduce (fn [{:keys [situation syncs]} [consumer-id requests]]
|
||||
(let [requested (get requests file-id #{})
|
||||
accepted (into #{} (filter requested) (:component-ids settled))
|
||||
pulled (pull-components situation consumer-id file-id
|
||||
(affected-components (get (all-files situation) file-id)
|
||||
accepted))]
|
||||
{:situation (update-in (:situation pulled) [:library-pulls consumer-id file-id]
|
||||
#(apply disj (or % #{}) accepted))
|
||||
:syncs (into syncs (:syncs pulled))}))
|
||||
{:situation (:situation settled) :syncs (into syncs (:syncs settled))}
|
||||
(:library-pulls (:situation settled)))))
|
||||
{:situation situation :syncs []}
|
||||
(sort-by (comp str key) (group-by owners component-ids)))))
|
||||
|
||||
(defn sync-world
|
||||
"Settle changed mains in their source files, then local inputs. Legacy
|
||||
worlds pull library changes immediately; snapshot worlds keep consumers
|
||||
stale until explicit acceptance. Cascades join their user's undo group."
|
||||
[situation component-ids]
|
||||
(if (:accepted-libraries situation)
|
||||
(sync-independent-world situation component-ids)
|
||||
(let [current-id (:id (tm/file situation))
|
||||
owners (into {} (mapcat (fn [[id file]]
|
||||
(map #(vector % id) (keys (get-in file [:data :components])))))
|
||||
(all-files situation))
|
||||
by-file (group-by owners component-ids)
|
||||
foreign (sort-by (comp str key) (dissoc by-file current-id))
|
||||
result
|
||||
(reduce (fn [{:keys [situation syncs]} [library-id ids]]
|
||||
(let [settled (sync-local situation library-id ids)
|
||||
situation (:situation settled)
|
||||
pulled (cll/generate-sync-file-cascade
|
||||
(pcb/empty-changes) nil :components current-id nil library-id
|
||||
(libraries situation) current-id)
|
||||
changes (:changes pulled)]
|
||||
{:situation (apply-changes situation changes)
|
||||
:syncs (cond-> (into syncs (:syncs settled))
|
||||
(seq (:redo-changes changes)) (conj changes))}))
|
||||
{:situation situation :syncs []} foreign)
|
||||
local (sync-local (:situation result) current-id (get by-file current-id []))]
|
||||
{:situation (:situation local)
|
||||
:syncs (into (:syncs result) (:syncs local))})))
|
||||
@ -15,17 +15,21 @@
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.files.shapes-helpers :as cfsh]
|
||||
[app.common.files.tokens :as cfo]
|
||||
[app.common.geom.modifiers :as gm]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.rect :as grc]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.logic.duplicate :as cld]
|
||||
[app.common.logic.instances :as cli]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.logic.placement :as clp]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[app.common.logic.variant-properties :as clvp]
|
||||
[app.common.logic.variants :as clv]
|
||||
[app.common.math :as mth]
|
||||
[app.common.path-names :as cpn]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.composable.comp.files :as cf]
|
||||
[app.common.test-helpers.composable.core :as tm]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
@ -87,6 +91,17 @@
|
||||
;; one clause in each.
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(def scalar-properties
|
||||
#{:strokes :shadow :blur :background-blur :hidden :blocked :r1 :r2 :r3 :r4
|
||||
:blend-mode :hide-fill-on-export :show-content
|
||||
:fixed-scroll :constraints-h :constraints-v :layout-item-margin
|
||||
:layout-gap :layout-padding :layout-align-items :layout-flex-dir
|
||||
:layout-wrap-type :layout-justify-content :layout-align-content
|
||||
:layout-gap-type :layout-padding-type :layout-justify-items
|
||||
: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})
|
||||
|
||||
(defn set-property
|
||||
"`shape` with `property` set to `value`. Public so the frontend interpreter
|
||||
makes the same edit."
|
||||
@ -98,9 +113,11 @@
|
||||
:margin (assoc shape
|
||||
:layout-item-margin-type :simple
|
||||
:layout-item-margin {:m1 value :m2 value :m3 value :m4 value})
|
||||
(throw (ex-info (str "set-property: unsupported property " (pr-str property)
|
||||
" (supported: :fills, :opacity, :name, :margin)")
|
||||
{:property property}))))
|
||||
(if (contains? scalar-properties property)
|
||||
(assoc shape property value)
|
||||
(throw (ex-info (str "set-property: unsupported property " (pr-str property)
|
||||
" (supported: :fills, :opacity, :name, :margin)")
|
||||
{:property property})))))
|
||||
|
||||
(defn- read-property
|
||||
"The comparable value of `property` in `shape`."
|
||||
@ -112,9 +129,11 @@
|
||||
:margin (when (= :simple (:layout-item-margin-type shape))
|
||||
(let [{:keys [m1 m2 m3 m4]} (:layout-item-margin shape)]
|
||||
(when (= m1 m2 m3 m4) m1)))
|
||||
(throw (ex-info (str "read-property: unsupported property " (pr-str property)
|
||||
" (supported: :fills, :opacity, :name, :margin)")
|
||||
{:property property}))))
|
||||
(if (contains? scalar-properties property)
|
||||
(get shape property)
|
||||
(throw (ex-info (str "read-property: unsupported property " (pr-str property)
|
||||
" (supported: :fills, :opacity, :name, :margin)")
|
||||
{:property property})))))
|
||||
|
||||
(defn- applied-value*
|
||||
"The value a change of `property` to `value` leaves: a rename cleans the
|
||||
@ -122,27 +141,87 @@
|
||||
[property value]
|
||||
(if (= :name property) (cpn/clean-path value) value))
|
||||
|
||||
(def ^:private layout-container-properties
|
||||
#{:layout-gap :layout-padding :layout-align-items :layout-flex-dir
|
||||
:layout-wrap-type :layout-justify-content :layout-align-content
|
||||
:layout-gap-type :layout-padding-type :layout-justify-items})
|
||||
|
||||
(defn- with-layout-reflow
|
||||
[changes id]
|
||||
(let [objects (pcb/get-objects changes)
|
||||
tree (gm/set-objects-modifiers {id {:modifiers (ctm/reflow-modifiers)}} objects)
|
||||
transform (clp/modifiers-transform tree)]
|
||||
(cls/generate-update-shapes changes (keys tree) transform objects
|
||||
{:ignore-touched true :attrs clp/transform-attrs})))
|
||||
|
||||
(defn- with-layouts-reflow
|
||||
"Reflow the layouts among `ids`, as the frontend's :layout/update does
|
||||
after a structural change, marking `changes` for a layout pass after sync."
|
||||
[changes ids]
|
||||
(let [objects (pcb/get-objects changes)
|
||||
layout-ids (filter #(:layout (get objects %)) ids)]
|
||||
(if (empty? layout-ids)
|
||||
changes
|
||||
(-> (reduce with-layout-reflow changes layout-ids)
|
||||
(assoc ::layout-reflow? true)))))
|
||||
|
||||
(defn layout-reflow?
|
||||
"Whether a property operation requires layout after its component sync."
|
||||
[changes]
|
||||
(::layout-reflow? changes))
|
||||
|
||||
(defn get-layout-reflow-changes
|
||||
"Derived layout changes on the current file's pages, after copy inputs sync."
|
||||
[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])))
|
||||
|
||||
(defrecord ChangeProperty [target property value]
|
||||
IComponentOperation
|
||||
(op-kind [_] :user)
|
||||
|
||||
tm/IOperation
|
||||
(apply-to [this situation]
|
||||
(let [the-file (tm/file situation)
|
||||
shape-id (tm/target-shape-id situation target)
|
||||
page (thf/current-page the-file)
|
||||
shape (get-in page [:objects shape-id])
|
||||
value' (applied-value* property value)
|
||||
changes (cond-> (cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page))
|
||||
#{shape-id}
|
||||
(fn [shape] (set-property shape property value'))
|
||||
(:objects page)
|
||||
{})
|
||||
;; renaming a main root renames its component too
|
||||
(and (= :name property) (ctk/main-instance? shape))
|
||||
(cll/generate-rename-component (:component-id shape) value' (:data the-file)))
|
||||
file' (thf/apply-changes the-file changes)]
|
||||
(let [the-file (tm/file situation)
|
||||
shape-id (tm/target-shape-id situation target)
|
||||
page (thf/current-page the-file)
|
||||
shape (get-in page [:objects shape-id])
|
||||
value' (applied-value* property value)
|
||||
layout-id (cond
|
||||
(and (:layout shape) (contains? layout-container-properties property)) shape-id
|
||||
(and (contains? ctl/layout-child-attrs property)
|
||||
(:layout (get-in page [:objects (:parent-id shape)]))) (:parent-id shape))
|
||||
changes (cond-> (cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page))
|
||||
#{shape-id}
|
||||
(fn [shape] (set-property shape property value'))
|
||||
(:objects page)
|
||||
{})
|
||||
(and (= :layout-item-absolute property)
|
||||
(ctl/grid-layout? (get-in page [:objects layout-id])))
|
||||
(pcb/update-shapes [layout-id] ctl/assign-cells
|
||||
{:with-objects? true :ignore-touched true})
|
||||
|
||||
layout-id
|
||||
(-> (with-layout-reflow layout-id)
|
||||
(assoc ::layout-reflow? true))
|
||||
|
||||
;; renaming a main root renames its component too
|
||||
(and (= :name property) (ctk/main-instance? shape))
|
||||
(cll/generate-rename-component (:component-id shape) value' (:data the-file)))
|
||||
file' (thf/apply-changes the-file changes)]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
(record-changes changes)
|
||||
@ -154,6 +233,49 @@
|
||||
[target property value]
|
||||
(tm/assign-id (->ChangeProperty target property value)))
|
||||
|
||||
(declare libraries)
|
||||
|
||||
(defrecord EditGrid [target action value]
|
||||
IComponentOperation
|
||||
(op-kind [_] :user)
|
||||
|
||||
tm/IOperation
|
||||
(apply-to [this situation]
|
||||
(let [file (tm/file situation)
|
||||
page (thf/current-page file)
|
||||
id (tm/target-shape-id situation target)
|
||||
edit (fn [shape]
|
||||
(update shape :layout-grid-cells
|
||||
(fn [cells]
|
||||
(update-vals cells #(if (= [(:row value) (:column value)] [(:row %) (:column %)])
|
||||
(merge % (:props value)) %)))))
|
||||
;; as the frontend's change-grid-direction: the cells for the new
|
||||
;; direction, then the direction, the only override it makes
|
||||
changes (if (= action :direction)
|
||||
(as-> (pcb/empty-changes nil (:id page)) changes
|
||||
(cls/generate-update-shapes changes [id]
|
||||
(cll/grid-direction-cells file page (libraries situation) value)
|
||||
(:objects page)
|
||||
{:attrs #{:layout-grid-cells :touched} :ignore-touched true
|
||||
:skip-grid-reassignment? true})
|
||||
(cls/generate-update-shapes changes [id]
|
||||
#(assoc % :layout-grid-dir value)
|
||||
(:objects page)
|
||||
{:attrs #{:layout-grid-dir} :skip-grid-reassignment? true}))
|
||||
(cls/generate-update-shapes (pcb/empty-changes nil (:id page)) [id]
|
||||
edit (:objects page) {}))
|
||||
changes (-> changes
|
||||
(with-layout-reflow id)
|
||||
(assoc ::layout-reflow? true))]
|
||||
(-> situation
|
||||
(tm/with-file (thf/apply-changes file changes))
|
||||
(record-changes changes)
|
||||
(tm/record-application this {:target target :action action :value value})))))
|
||||
|
||||
(defn edit-grid
|
||||
[target action value]
|
||||
(tm/assign-id (->EditGrid target action value)))
|
||||
|
||||
(defprotocol IPropertyCheck
|
||||
"The check dual of an operation that changes a property: whether a shape the
|
||||
test supplies holds the value the operation set."
|
||||
@ -258,7 +380,9 @@
|
||||
;; derived write
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
#{shape-id}
|
||||
#(edit-text-content % edit value)
|
||||
(fn [shape]
|
||||
(cond-> (edit-text-content shape edit value)
|
||||
(:typography this) cls/touch-text-typography))
|
||||
(:objects page)
|
||||
{:ignore-touched #{:name}})
|
||||
file' (thf/apply-changes the-file changes)]
|
||||
@ -271,21 +395,37 @@
|
||||
"Constructor for the text edit operation: set the `edit` (see
|
||||
`text-edits`) of the text bound to `target` to `value`. On the frontend it
|
||||
dispatches the real `v2-update-text-shape-content`."
|
||||
[target edit value]
|
||||
(tm/assign-id (->EditText target edit value)))
|
||||
([target edit value]
|
||||
(edit-text target edit value nil))
|
||||
([target edit value {:keys [typography]}]
|
||||
(cond-> (tm/assign-id (->EditText target edit value))
|
||||
typography (assoc :typography typography))))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; Geometry operations
|
||||
;;
|
||||
;; The frontend interpreter dispatches the real sidebar events: they build
|
||||
;; the modifiers (frontend code: constraints, pixel snap) and the placement
|
||||
;; step (`clp/calculate-ignore-tree`) decides which copy shapes the change
|
||||
;; touches. Their `apply-to` makes the same transform without either, so the
|
||||
;; pure runner rejects them.
|
||||
;; The frontend interpreter dispatches the sidebar events. The pure runner
|
||||
;; uses the same constraints and placement logic for resize and rotation.
|
||||
;; MoveShape still needs the frontend position event.
|
||||
|
||||
(defn transform-changes
|
||||
"Apply a transform through constraints and the shared placement step."
|
||||
([page shape modifiers]
|
||||
(transform-changes page shape modifiers nil))
|
||||
([page shape modifiers {:keys [file libraries]}]
|
||||
(let [objects (:objects page)
|
||||
tree (gm/set-objects-modifiers {(:id shape) {:modifiers modifiers}} objects)
|
||||
transform (clp/modifiers-transform tree)
|
||||
changes (cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page)) (keys tree) transform objects
|
||||
{:ignore-tree (clp/calculate-ignore-tree objects (keys tree) transform #{(:id shape)})
|
||||
:attrs clp/transform-attrs})]
|
||||
(cond-> changes
|
||||
file (cll/generate-sync-transformed-placement file libraries page objects (keys tree))))))
|
||||
|
||||
(defrecord Rotate [target angle]
|
||||
IComponentOperation
|
||||
(op-kind [_] :frontend-only)
|
||||
(op-kind [_] :user)
|
||||
|
||||
tm/IOperation
|
||||
(apply-to [this situation]
|
||||
@ -294,15 +434,9 @@
|
||||
page (thf/current-page the-file)
|
||||
objects (:objects page)
|
||||
shape (get objects shape-id)
|
||||
;; the whole subtree rotates, as with the real event
|
||||
ids (into #{shape-id} (cfh/get-children-ids objects shape-id))
|
||||
center (gsh/shape->center shape)
|
||||
rotate1 (fn [s] (gsh/transform-shape s (ctm/rotation-modifiers s center angle)))
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
ids
|
||||
rotate1
|
||||
objects
|
||||
{})
|
||||
changes (transform-changes page shape (ctm/rotation-modifiers shape center angle)
|
||||
{:file the-file :libraries (cf/libraries situation)})
|
||||
file' (thf/apply-changes the-file changes)]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
@ -318,7 +452,7 @@
|
||||
|
||||
(defrecord ChangeHeight [target value]
|
||||
IComponentOperation
|
||||
(op-kind [_] :frontend-only)
|
||||
(op-kind [_] :user)
|
||||
|
||||
tm/IOperation
|
||||
(apply-to [this situation]
|
||||
@ -327,21 +461,44 @@
|
||||
page (thf/current-page the-file)
|
||||
objects (:objects page)
|
||||
shape (get objects shape-id)
|
||||
resize1 (fn [s] (gsh/transform-shape
|
||||
s
|
||||
(ctm/resize-modifiers (gpt/point 1 (/ value (:height s)))
|
||||
(gpt/point (:x s) (:y s)))))
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
#{(:id shape)}
|
||||
resize1
|
||||
objects
|
||||
{})
|
||||
changes (transform-changes page shape (ctm/change-size shape nil value)
|
||||
{:file the-file :libraries (cf/libraries situation)})
|
||||
file' (thf/apply-changes the-file changes)]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
(record-changes changes)
|
||||
(tm/record-application this {:target target :value value})))))
|
||||
|
||||
(defn geometry-modifiers
|
||||
[shape action value]
|
||||
(case action
|
||||
:move (ctm/move-modifiers (apply gpt/point value))
|
||||
:width (ctm/change-dimensions-modifiers shape :width value)
|
||||
:height (ctm/change-dimensions-modifiers shape :height value)
|
||||
:rotate (ctm/rotation-modifiers shape (gsh/shape->center shape) value)
|
||||
:flip-x (ctm/resize-modifiers (gpt/point -1 1) (gsh/shape->center shape))
|
||||
:flip-y (ctm/resize-modifiers (gpt/point 1 -1) (gsh/shape->center shape))))
|
||||
|
||||
(defrecord TransformShape [target action value]
|
||||
IComponentOperation
|
||||
(op-kind [_] :user)
|
||||
|
||||
tm/IOperation
|
||||
(apply-to [this situation]
|
||||
(let [file (tm/file situation)
|
||||
page (thf/current-page file)
|
||||
shape (get (:objects page) (tm/target-shape-id situation target))
|
||||
modifiers (geometry-modifiers shape action value)
|
||||
changes (transform-changes page shape modifiers {:file file :libraries (cf/libraries situation)})]
|
||||
(-> situation
|
||||
(tm/with-file (thf/apply-changes file changes))
|
||||
(record-changes changes)
|
||||
(tm/record-application this {:target target :action action :value value})))))
|
||||
|
||||
(defn transform-shape
|
||||
[target action value]
|
||||
(tm/assign-id (->TransformShape target action value)))
|
||||
|
||||
(defrecord MoveShape [target dx dy]
|
||||
IComponentOperation
|
||||
(op-kind [_] :frontend-only)
|
||||
@ -749,10 +906,9 @@
|
||||
(tm/assign-id (->InstantiateCopy name)))
|
||||
|
||||
(defn- libraries
|
||||
"The situation's files by id: the current one and the auxiliary ones."
|
||||
"The current file and its loaded library versions."
|
||||
[situation]
|
||||
(let [the-file (tm/file situation)]
|
||||
(assoc (tm/aux-files situation) (:id the-file) the-file)))
|
||||
(cf/libraries situation))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; reset — reset the overrides of a copy head
|
||||
@ -779,6 +935,7 @@
|
||||
file' (thf/apply-changes the-file changes :validate? false)]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
(cf/remember-subtree (:id the-file) shape-id (cf/all-files situation))
|
||||
(record-changes changes)
|
||||
(tm/record-application this {:target target :reset shape-id})))))
|
||||
|
||||
@ -815,9 +972,15 @@
|
||||
(:data the-file)
|
||||
(:id page)
|
||||
(libraries situation))
|
||||
file' (thf/apply-changes the-file changes :validate? false)]
|
||||
file' (thf/apply-changes the-file changes :validate? false)
|
||||
objects (:objects (thf/current-page file'))
|
||||
;; copy children whose main the loaded library no longer has
|
||||
unlinked (filter #(and (nil? (get-in objects [% :shape-ref]))
|
||||
(some? (get-in objects [(get-in objects [% :parent-id]) :shape-ref])))
|
||||
(cfh/get-children-ids objects shape-id))]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
(update ::unlinked-children (fnil into #{}) unlinked)
|
||||
(record-changes changes)
|
||||
(tm/record-application this {:target target :detached shape-id})))))
|
||||
|
||||
@ -827,6 +990,13 @@
|
||||
[target]
|
||||
(tm/assign-id (->Detach target)))
|
||||
|
||||
(defn unlinked-children
|
||||
"The ids of the copy children a detach left as plain shapes, because the
|
||||
loaded library had removed their mains. Accepting the library replaces
|
||||
them with linked shapes."
|
||||
[situation]
|
||||
(get situation ::unlinked-children #{}))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; update-main — push a copy's overrides to its main
|
||||
;;
|
||||
@ -836,13 +1006,6 @@
|
||||
;; the order the sync built them.
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defn- strip-local-change
|
||||
[changes]
|
||||
(let [strip (partial mapv #(dissoc % :local-change?))]
|
||||
(-> changes
|
||||
(update :redo-changes strip)
|
||||
(update :undo-changes strip))))
|
||||
|
||||
(defrecord UpdateMain [target]
|
||||
IComponentOperation
|
||||
(op-kind [_] :user)
|
||||
@ -858,10 +1021,14 @@
|
||||
(cll/generate-sync-shape-inverse (libraries situation)
|
||||
container
|
||||
shape-id)
|
||||
(strip-local-change))
|
||||
file' (thf/apply-changes the-file changes :validate? false)]
|
||||
(cf/route-update-main (:id the-file) (:component-file (get-in page [:objects shape-id]))))
|
||||
shape (get-in page [:objects shape-id])
|
||||
situation (cf/apply-changes situation changes)]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
(cond-> (and (:accepted-libraries situation)
|
||||
(not= (:id the-file) (:component-file shape)))
|
||||
(update-in [:library-pulls (:id the-file) (:component-file shape)]
|
||||
(fnil conj #{}) (:component-id shape)))
|
||||
(record-changes (when (seq (:redo-changes changes)) changes))
|
||||
(tm/record-application this {:target target :updated shape-id})))))
|
||||
|
||||
@ -969,13 +1136,15 @@
|
||||
|
||||
(defn- new-subtree-head
|
||||
"The id of the shape in `page-after` that is not in `page-before` but whose
|
||||
parent is: the head of the one subtree added between them. Throws when
|
||||
there is not exactly one, as when the sync also added children to copies."
|
||||
parent is, outside component copies. Sync can add matching subtrees in
|
||||
copies too; only the user's new subtree identifies the duplicate."
|
||||
[page-before page-after]
|
||||
(let [before (:objects page-before)
|
||||
heads (->> (vals (:objects page-after))
|
||||
(filter #(and (not (contains? before (:id %)))
|
||||
(contains? before (:parent-id %))))
|
||||
(contains? before (:parent-id %))
|
||||
(empty? (ctn/get-parent-copy-heads (:objects page-after)
|
||||
(get-in page-after [:objects (:parent-id %)])))))
|
||||
(map :id))]
|
||||
(when-not (= 1 (count heads))
|
||||
(throw (ex-info (str "Expected one new subtree, found " (count heads))
|
||||
@ -997,9 +1166,9 @@
|
||||
shape-id (tm/target-shape-id situation target)
|
||||
page (thf/current-page the-file)
|
||||
objects (:objects page)
|
||||
_ (when-not (ctk/allow-duplicate? objects (get objects shape-id))
|
||||
_ (when-not (cld/allow-duplicate? objects (get objects shape-id))
|
||||
;; the frontend's `duplicate-shapes` drops it and does nothing
|
||||
(throw (ex-info "The shape cannot be duplicated (inside a copy)"
|
||||
(throw (ex-info "The shape cannot be duplicated in its current parent"
|
||||
{:type ::duplicate-refused :target target})))
|
||||
changes (-> (pcb/empty-changes nil)
|
||||
(cld/generate-duplicate-changes objects
|
||||
@ -1010,12 +1179,13 @@
|
||||
(:data the-file)
|
||||
(:id the-file))
|
||||
(cld/generate-duplicate-changes-update-indices objects #{shape-id}))
|
||||
file' (thf/apply-changes the-file changes :validate? false)]
|
||||
file' (thf/apply-changes the-file changes :validate? false)
|
||||
result (applied-result this the-file file')]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
(cf/inherit-references (:id the-file) shape-id (:new-head result))
|
||||
(record-changes changes)
|
||||
(tm/record-application this (merge {:target target}
|
||||
(applied-result this the-file file')))))))
|
||||
(tm/record-application this (merge {:target target} result))))))
|
||||
|
||||
(defn duplicate
|
||||
"Constructor for the duplicate operation: duplicate the shape `target`
|
||||
@ -1119,6 +1289,7 @@
|
||||
(nest-target-index situation parent-id)
|
||||
#{copy-id}
|
||||
:cell cell)
|
||||
changes (with-layouts-reflow changes [parent-id (get-in page [:objects copy-id :parent-id])])
|
||||
file' (thf/apply-changes the-file changes :validate? false)]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
@ -1141,12 +1312,19 @@
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defn swap-target-id
|
||||
"The component id `swap-shape`'s `to` names: a lineage name (a string) or a
|
||||
component label (a keyword)."
|
||||
"Resolve a lineage name, component label, or situation-to-component fn."
|
||||
[situation to]
|
||||
(if (keyword? to)
|
||||
(thi/id to)
|
||||
(lineage-component-id situation to)))
|
||||
(cond
|
||||
(fn? to) (to situation)
|
||||
(keyword? to) (thi/id to)
|
||||
:else (lineage-component-id situation to)))
|
||||
|
||||
(defn swap-target-file-id
|
||||
"The loaded file that owns the requested swap destination."
|
||||
[situation to]
|
||||
(let [component-id (swap-target-id situation to)]
|
||||
(some (fn [[id file]] (when (get-in file [:data :components component-id]) id))
|
||||
(libraries situation))))
|
||||
|
||||
(defrecord SwapShape [target to keep-touched?]
|
||||
IComponentOperation
|
||||
@ -1160,13 +1338,14 @@
|
||||
[_ changes _] (clv/generate-component-swap-in-place (pcb/empty-changes nil (:id page))
|
||||
page
|
||||
(libraries situation)
|
||||
(:data the-file)
|
||||
(:data (get (libraries situation) (swap-target-file-id situation to)))
|
||||
shape
|
||||
(swap-target-id situation to)
|
||||
(boolean keep-touched?))
|
||||
file' (thf/apply-changes the-file changes :validate? false)]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
(cf/remember-subtree (:id the-file) (:id shape) (cf/all-files situation))
|
||||
(record-changes changes)
|
||||
(tm/record-application this {:target target :to to :keep-touched? keep-touched?})))))
|
||||
|
||||
@ -1264,9 +1443,12 @@
|
||||
{:set set-name :value value :count (count matches)})))))
|
||||
|
||||
(defn variant-member-component-id
|
||||
"The component id of set `set-name`'s member with value `value`."
|
||||
"The component id of set `set-name`'s member with value `value`. With no
|
||||
`set-name`, `value` is the component id."
|
||||
[situation set-name value]
|
||||
(:component-id (variant-member situation set-name value)))
|
||||
(if (some? set-name)
|
||||
(:component-id (variant-member situation set-name value))
|
||||
value))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; make-variant-container — build a variant set
|
||||
@ -1429,6 +1611,7 @@
|
||||
file' (thf/apply-changes the-file changes :validate? false)]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
(cf/remember-subtree (:id the-file) (:id shape) (cf/all-files situation))
|
||||
(record-changes changes)
|
||||
(tm/record-application this {:target-component (:id component)})))))))
|
||||
|
||||
@ -1478,15 +1661,19 @@
|
||||
(component-properties situation (variant-member-component-id situation set-name value)))
|
||||
|
||||
(defn member-root
|
||||
"The main root of set `set-name`'s member built with value `value`."
|
||||
"The main root of set `set-name`'s member built with value `value`, or with
|
||||
no `set-name`, of the component `value`."
|
||||
[situation set-name value]
|
||||
(tm/shape-by-id situation (thi/id (:root-label (variant-member situation set-name value)))))
|
||||
(tm/shape-by-id situation
|
||||
(if (some? set-name)
|
||||
(thi/id (:root-label (variant-member situation set-name value)))
|
||||
(:main-instance-id (member-component situation nil value)))))
|
||||
|
||||
(defn variant-property-call
|
||||
"The edit of `op` as `[edit & args]`, the arguments the generator and the
|
||||
frontend event of `edit` take after the changes."
|
||||
[situation {:keys [set-name edit params]}]
|
||||
(let [variant-id (variant-set-id situation set-name)]
|
||||
(let [variant-id (or (:variant-id params) (variant-set-id situation set-name))]
|
||||
(case edit
|
||||
:add [:add variant-id (select-keys params [:property-name :property-value])]
|
||||
:remove [:remove variant-id (:pos params)]
|
||||
@ -1536,6 +1723,12 @@
|
||||
(record-changes (when (seq (:redo-changes changes)) changes))
|
||||
(tm/record-application this {:set-name set-name :edit edit :params params})))))
|
||||
|
||||
(defn edit-variant-set
|
||||
"The edit `edit` of `variant-property-call` on the variant set `variant-id`,
|
||||
whose `params` name members by component id."
|
||||
[variant-id edit params]
|
||||
(tm/assign-id (->EditVariantProperty nil edit (assoc params :variant-id variant-id))))
|
||||
|
||||
(defn add-variant-property
|
||||
"Add a property `:name` to set `set-name`, with value `:value` on every
|
||||
member (empty when not given)."
|
||||
@ -1609,6 +1802,28 @@
|
||||
(remove before)
|
||||
(first))))
|
||||
|
||||
(defn- place-added-variant
|
||||
"The file and changes after the placement `add-new-variant` gives a member
|
||||
added to a container with no layout: the container grows by the member's
|
||||
width and a gap, and the member moves to the container's right end."
|
||||
[file libraries shape-id]
|
||||
(let [page (thf/current-page file)
|
||||
shape (get (:objects page) shape-id)
|
||||
container (get (:objects page) (:parent-id shape))
|
||||
width (+ (:width container) (:width shape) 20)
|
||||
x (- width (+ (:width shape) 30))
|
||||
resize (transform-changes page container (geometry-modifiers container :width width)
|
||||
{:file file :libraries libraries})
|
||||
file (thf/apply-changes file resize :validate? false)
|
||||
page (thf/current-page file)
|
||||
shape (get (:objects page) shape-id)
|
||||
frame (cfh/get-parent-frame (:objects page) shape)
|
||||
bbox (grc/points->rect (:points shape))
|
||||
move (transform-changes page shape
|
||||
(geometry-modifiers shape :move [(- (+ (:x frame) x) (:x bbox)) 0])
|
||||
{:file file :libraries libraries})]
|
||||
[(thf/apply-changes file move :validate? false) (pcb/concat-changes resize move)]))
|
||||
|
||||
(defrecord AddVariant [set-name member]
|
||||
IComponentOperation
|
||||
(op-kind [_] :user)
|
||||
@ -1623,15 +1838,20 @@
|
||||
page (thf/current-page the-file)
|
||||
root (member-root situation set-name member)
|
||||
component (member-component situation set-name member)
|
||||
shape-id (uuid/next)
|
||||
changes (-> (pcb/empty-changes nil (:id page))
|
||||
(pcb/with-library-data (:data the-file))
|
||||
(pcb/with-objects (:objects page))
|
||||
(clv/generate-add-new-variant root
|
||||
(:variant-id component)
|
||||
(uuid/next)
|
||||
(uuid/next)
|
||||
shape-id
|
||||
(dec (count (:variant-properties component)))))
|
||||
file' (thf/apply-changes the-file changes :validate? false)]
|
||||
file' (thf/apply-changes the-file changes :validate? false)
|
||||
[file' changes] (if (ctl/any-layout? (get (:objects page) (:parent-id root)))
|
||||
[file' changes]
|
||||
(let [[file' placement] (place-added-variant file' (libraries situation) shape-id)]
|
||||
[file' (pcb/concat-changes changes placement)]))]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
(record-changes changes)
|
||||
@ -1640,7 +1860,7 @@
|
||||
|
||||
(defn add-variant
|
||||
"Add a member to set `set-name`, a duplicate of its member built with value
|
||||
`member`."
|
||||
`member`, or with no `set-name`, of the component `member`."
|
||||
[set-name member]
|
||||
(tm/assign-id (->AddVariant set-name member)))
|
||||
|
||||
@ -1731,7 +1951,7 @@
|
||||
[situation]
|
||||
(-> situation tm/aux-files keys first))
|
||||
|
||||
(defrecord SyncFromLibrary []
|
||||
(defrecord SyncFromLibrary [source]
|
||||
IComponentOperation
|
||||
(op-kind [_] :user)
|
||||
|
||||
@ -1739,7 +1959,7 @@
|
||||
(apply-to [this situation]
|
||||
(let [the-file (tm/file situation)
|
||||
file-id (:id the-file)
|
||||
lib-id (library-id situation)
|
||||
lib-id (or source (library-id situation))
|
||||
changes (-> (pcb/empty-changes)
|
||||
(cll/generate-sync-file-changes nil
|
||||
:components
|
||||
@ -1748,17 +1968,24 @@
|
||||
lib-id
|
||||
(libraries situation)
|
||||
file-id))
|
||||
file' (thf/apply-changes the-file changes :validate? false)]
|
||||
(-> situation
|
||||
file' (thf/apply-changes the-file changes :validate? false)
|
||||
accepted (cf/accept-library situation lib-id)]
|
||||
(-> accepted
|
||||
(tm/with-file file')
|
||||
;; the copies take this library as loaded and keep the versions
|
||||
;; of the others they had accepted
|
||||
(cf/remember-copies file-id lib-id
|
||||
(set (keys (get-in (libraries situation) [lib-id :data :components])))
|
||||
(merge (cf/all-files situation)
|
||||
(get-in accepted [:accepted-libraries file-id])))
|
||||
(record-changes changes)
|
||||
(tm/record-application this {:library-id lib-id})))))
|
||||
|
||||
(defn sync-from-library
|
||||
"Constructor for the library update of the current file from the
|
||||
situation's library."
|
||||
[]
|
||||
(tm/assign-id (->SyncFromLibrary)))
|
||||
([] (sync-from-library nil))
|
||||
([source] (tm/assign-id (->SyncFromLibrary source))))
|
||||
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
@ -1860,7 +2087,7 @@
|
||||
tm/IOperation
|
||||
(apply-to [this situation]
|
||||
(let [the-file (tm/file situation)
|
||||
parent-id (tm/resolve-shape-id situation parent)
|
||||
parent-id (tm/target-shape-id situation parent)
|
||||
page (thf/current-page the-file)
|
||||
objects (:objects page)
|
||||
;; registers `new-label`
|
||||
@ -1868,6 +2095,11 @@
|
||||
[_ changes] (cfsh/prepare-add-shape (pcb/empty-changes nil (:id page))
|
||||
shape
|
||||
objects)
|
||||
;; a layout places the new child, and its copies after sync
|
||||
changes (cond-> changes
|
||||
(:layout (get objects parent-id))
|
||||
(-> (with-layout-reflow parent-id)
|
||||
(assoc ::layout-reflow? true)))
|
||||
file' (thf/apply-changes the-file changes)]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
@ -1895,15 +2127,16 @@
|
||||
tm/IOperation
|
||||
(apply-to [this situation]
|
||||
(let [the-file (tm/file situation)
|
||||
shape-id (tm/resolve-shape-id situation target)
|
||||
shape-id (tm/target-shape-id situation target)
|
||||
page (thf/current-page the-file)
|
||||
[_all-parents changes]
|
||||
[all-parents changes]
|
||||
(cls/generate-delete-shapes (pcb/empty-changes)
|
||||
(:data the-file)
|
||||
page
|
||||
(:objects page)
|
||||
#{shape-id}
|
||||
{})
|
||||
changes (with-layouts-reflow changes all-parents)
|
||||
file' (thf/apply-changes the-file changes)]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
@ -1942,6 +2175,7 @@
|
||||
parent-id
|
||||
to-index
|
||||
#{shape-id})
|
||||
changes (with-layouts-reflow changes [parent-id (get-in page [:objects shape-id :parent-id])])
|
||||
file' (thf/apply-changes the-file changes)]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
|
||||
@ -33,6 +33,7 @@
|
||||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.test-helpers.composable.comp.files :as cf]
|
||||
[app.common.test-helpers.composable.comp.nodes :as n]
|
||||
[app.common.test-helpers.composable.comp.undo-check :as uc]
|
||||
[app.common.test-helpers.composable.core :as tm]
|
||||
@ -46,19 +47,17 @@
|
||||
`old-data`, the file data before `changes` applied."
|
||||
cll/changed-components)
|
||||
|
||||
(defn- libraries
|
||||
"The situation's files by id, with `file` as its current file."
|
||||
[situation file]
|
||||
(assoc (tm/aux-files situation) (:id file) file))
|
||||
|
||||
(defn- validate-settled!
|
||||
"Validate the situation's file, resolving components against its other
|
||||
files. Only a settled file is valid: between two passes of a sync cascade,
|
||||
an outer copy can still point at the component its main no longer uses.
|
||||
Throws when the file is invalid."
|
||||
[situation]
|
||||
(let [file (tm/file situation)]
|
||||
(thf/validate-file! file (libraries situation file))
|
||||
(let [files (cf/all-files situation)]
|
||||
(doseq [[id file] files]
|
||||
(thf/validate-file! file (cf/libraries (-> situation
|
||||
(tm/with-file file)
|
||||
(tm/with-aux-files (dissoc files id))))))
|
||||
situation))
|
||||
|
||||
(defn sync-cascade
|
||||
@ -79,15 +78,37 @@
|
||||
:syncs (if (seq (:redo-changes changes)) [changes] [])
|
||||
:passes passes}))
|
||||
|
||||
(defn- sync-with-layout
|
||||
"Layout property edits, and syncs that change shapes, reflow the layouts
|
||||
after sync. Keep each derived pass so the primary action owns its full
|
||||
inverse."
|
||||
[situation component-ids reflow?]
|
||||
(loop [situation situation component-ids component-ids syncs [] passes 0]
|
||||
(let [synced (cf/sync-world situation component-ids)
|
||||
before (:situation synced)
|
||||
syncs (into syncs (:syncs synced))
|
||||
;; the frontend reflows the layouts a sync changes, as after a restore
|
||||
changes (when (or reflow? (some (comp seq :redo-changes) (:syncs synced)))
|
||||
(n/get-layout-reflow-changes before))]
|
||||
(if (empty? (:redo-changes changes))
|
||||
{:situation before :syncs syncs}
|
||||
(let [after (cf/apply-changes before changes)]
|
||||
;; Grid order writers may record an already-correct order.
|
||||
(if (= (:data (tm/file before)) (:data (tm/file after)))
|
||||
{:situation before :syncs syncs}
|
||||
(do
|
||||
(when (>= passes 20)
|
||||
(throw (ex-info "Layout did not settle after component sync"
|
||||
{:type ::layout-not-settled})))
|
||||
(recur after (cf/changed-components before after changes)
|
||||
(conj syncs changes) (inc passes)))))))))
|
||||
|
||||
(defn- sync-file
|
||||
"Sync `situation`'s file, starting from the components that `changes`
|
||||
modified (judged against `old-data`), and validate the result. Returns
|
||||
`[situation syncs]`, with `syncs` the applied sync changes in order."
|
||||
[situation old-data changes]
|
||||
(let [{:keys [file syncs]} (sync-cascade (tm/file situation)
|
||||
(tm/aux-files situation)
|
||||
(changed-components old-data changes))]
|
||||
[(validate-settled! (tm/with-file situation file)) syncs]))
|
||||
[situation before changes]
|
||||
(let [{:keys [situation syncs]}
|
||||
(sync-with-layout situation (cf/changed-components before situation changes)
|
||||
(n/layout-reflow? changes))]
|
||||
[(validate-settled! situation) syncs]))
|
||||
|
||||
(defn- push-undo-group
|
||||
"Add `group`, the changes of one user operation and its syncs in order, to
|
||||
@ -101,19 +122,9 @@
|
||||
(assoc ::redo-stack [])))))
|
||||
|
||||
(defn- apply-group
|
||||
"Apply to the situation's file the `side` changes (`:undo-changes` or
|
||||
`:redo-changes`) of each changes in `group`, in order, and validate the
|
||||
result."
|
||||
[situation side group]
|
||||
(let [file (reduce (fn [file changes]
|
||||
(thf/apply-changes file
|
||||
{:redo-changes (get changes side)}
|
||||
:validate? false))
|
||||
(tm/file situation)
|
||||
group)]
|
||||
(-> situation
|
||||
(tm/with-file file)
|
||||
(validate-settled!))))
|
||||
(validate-settled!
|
||||
(reduce #(cf/apply-changes %1 %2 side) situation group)))
|
||||
|
||||
(defn- move-group
|
||||
"Move the latest group of the `from` stack to the `to` stack, applying its
|
||||
@ -211,9 +222,19 @@
|
||||
[situation]
|
||||
(count (get situation ::redo-stack)))
|
||||
|
||||
(defn history
|
||||
"The undo/redo state of one editor, without its loaded file snapshots."
|
||||
[situation]
|
||||
(select-keys situation [::undo-stack ::redo-stack]))
|
||||
|
||||
(defn with-history
|
||||
[situation history]
|
||||
(merge (dissoc situation ::undo-stack ::redo-stack) history))
|
||||
|
||||
(defn- snapshot
|
||||
[situation]
|
||||
(uc/snapshot (tm/file situation)))
|
||||
(let [file (tm/file situation)]
|
||||
(uc/snapshot-files (assoc (tm/aux-files situation) (:id file) file))))
|
||||
|
||||
(defn- attempt
|
||||
"`[(f) nil]`, or `[nil error]` when `f` throws."
|
||||
@ -289,7 +310,7 @@
|
||||
(when `:sync?`), pushes its undo group, and gets its round trip (when
|
||||
`:undo-check?`). An assembly operation moves the round trip's baseline."
|
||||
[situation op kind {:keys [sync? undo-check?]}]
|
||||
(let [old-data (:data (tm/file situation))
|
||||
(let [before-situation situation
|
||||
before (when undo-check? (snapshot situation))
|
||||
depth (undo-depth situation)
|
||||
[recorded? changes situation] (n/take-changes (tm/apply-to op situation))]
|
||||
@ -297,9 +318,15 @@
|
||||
(cond-> (if (nil? changes)
|
||||
situation
|
||||
(let [[situation syncs] (if sync?
|
||||
(sync-file situation old-data changes)
|
||||
(sync-file situation before-situation changes)
|
||||
[situation []])]
|
||||
(push-undo-group situation (into [changes] syncs))))
|
||||
(cond-> (push-undo-group situation (into [changes] syncs))
|
||||
(and (not sync?) (n/layout-reflow? changes))
|
||||
(assoc ::pending-layout? true)
|
||||
|
||||
(not sync?)
|
||||
(update ::pending-components (fnil into #{})
|
||||
(cf/changed-components before-situation situation changes)))))
|
||||
(and undo-check? (= kind :user))
|
||||
(check-step op before depth)
|
||||
|
||||
@ -370,6 +397,34 @@
|
||||
;; validated on their own
|
||||
(:sync? opts) (validate-settled!)))))
|
||||
|
||||
(defn step
|
||||
"Run a resolved random operation, retaining the runner's undo stacks.
|
||||
The harness checks each settled group's inverse itself."
|
||||
[situation op]
|
||||
(run-op situation op {:sync? false :undo-check? false}))
|
||||
|
||||
(defn pending-components
|
||||
[situation]
|
||||
(get situation ::pending-components #{}))
|
||||
|
||||
(defn settle
|
||||
"Sync selected pending components in the latest user's undo group."
|
||||
([situation] (settle situation (pending-components situation)))
|
||||
([situation component-ids]
|
||||
(let [{:keys [situation syncs]} (sync-with-layout situation component-ids (::pending-layout? situation))
|
||||
stack (get situation ::undo-stack [])]
|
||||
(cond-> (-> situation
|
||||
(dissoc ::pending-layout?)
|
||||
(update ::pending-components #(apply disj (or % #{}) component-ids)))
|
||||
(and (seq syncs) (seq stack))
|
||||
(assoc ::undo-stack (conj (pop stack) (into (peek stack) syncs)))))))
|
||||
|
||||
(defn settle-layout
|
||||
"Reflow every layout of the current file and sync the components it
|
||||
changes until both settle, outside any undo history."
|
||||
[situation]
|
||||
(:situation (sync-with-layout situation [] true)))
|
||||
|
||||
(defn run-all
|
||||
"Enumerate `operation` into its concrete variants and run each with
|
||||
`run-variant`, resetting the label map before each setup. Returns the
|
||||
|
||||
@ -34,6 +34,9 @@
|
||||
a pinned phase that does not fail fails the case, so the mark goes
|
||||
only with the fix."
|
||||
(:require
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.math :as mth]
|
||||
[app.common.test-helpers.composable.core :as tm]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.normalize :as thn]
|
||||
@ -56,6 +59,12 @@
|
||||
([file] (snapshot file {}))
|
||||
([file opts] (thn/normalize-file file opts)))
|
||||
|
||||
(defn snapshot-files
|
||||
"The normalized files affected by a step, including linked libraries."
|
||||
([files] (snapshot-files files {}))
|
||||
([files opts]
|
||||
{:files (into {} (map (fn [[id file]] [id (snapshot file opts)])) files)}))
|
||||
|
||||
(defn mark-baseline
|
||||
"Record the state the end-of-variant round trip undoes back to: the
|
||||
normalized file `snap` with `depth` undo groups on the stack."
|
||||
@ -141,17 +150,55 @@
|
||||
`[:data key]` / `[:file key]` for anything else. Shapes without a test
|
||||
label are `:unlabelled`."
|
||||
[expected actual]
|
||||
(let [ed (:data expected)
|
||||
ad (:data actual)]
|
||||
(-> #{}
|
||||
(into (map #(vector :file %)) (differing-keys expected actual #{:data}))
|
||||
(into (map #(vector :data %)) (differing-keys ed ad #{:pages-index :components}))
|
||||
(into (entities-signature :page (:pages-index ed) (:pages-index ad) #{:objects}
|
||||
(fn [e a]
|
||||
(entities-signature :object (:objects e) (:objects a)
|
||||
#{} (constantly nil)))))
|
||||
(into (entities-signature :component (:components ed) (:components ad)
|
||||
#{} (constantly nil))))))
|
||||
(if (or (contains? expected :files) (contains? actual :files))
|
||||
(into #{}
|
||||
(mapcat (fn [id]
|
||||
(map #(into [:file (label-of id)] %)
|
||||
(signature (get-in expected [:files id])
|
||||
(get-in actual [:files id])))))
|
||||
(into (set (keys (:files expected))) (keys (:files actual))))
|
||||
(let [ed (:data expected)
|
||||
ad (:data actual)]
|
||||
(-> #{}
|
||||
(into (map #(vector :file %)) (differing-keys expected actual #{:data}))
|
||||
(into (map #(vector :data %)) (differing-keys ed ad #{:pages-index :components}))
|
||||
(into (entities-signature :page (:pages-index ed) (:pages-index ad) #{:objects}
|
||||
(fn [e a]
|
||||
(entities-signature :object (:objects e) (:objects a)
|
||||
#{} (constantly nil)))))
|
||||
(into (entities-signature :component (:components ed) (:components ad)
|
||||
#{} (constantly nil)))))))
|
||||
|
||||
(defn same-state?
|
||||
"Compare exact data with an absolute tolerance only in shape geometry.
|
||||
Undo defaults to 1e-10; design equivalence can supply its own tolerance."
|
||||
([expected actual] (same-state? expected actual 1e-10 false))
|
||||
([expected actual tolerance] (same-state? expected actual tolerance false))
|
||||
([expected actual tolerance geometry?]
|
||||
(or (= expected actual)
|
||||
(cond
|
||||
(and geometry? (number? expected) (number? actual))
|
||||
(mth/close? expected actual tolerance)
|
||||
|
||||
(and geometry? (gmt/matrix? expected) (gmt/matrix? actual))
|
||||
(every? #(same-state? (get expected %) (get actual %) tolerance true) [:a :b :c :d :e :f])
|
||||
|
||||
(and geometry? (gpt/point? expected) (gpt/point? actual))
|
||||
(every? #(same-state? (get expected %) (get actual %) tolerance true) [:x :y])
|
||||
|
||||
(and (map? expected) (map? actual) (= (set (keys expected)) (set (keys actual))))
|
||||
(every? (fn [key]
|
||||
(same-state? (get expected key) (get actual key) tolerance
|
||||
(or geometry?
|
||||
(and (contains? expected :parent-id)
|
||||
(contains? #{:x :y :width :height :rotation :points
|
||||
:selrect :transform :transform-inverse} key)))))
|
||||
(keys expected))
|
||||
|
||||
(and (sequential? expected) (sequential? actual) (= (count expected) (count actual)))
|
||||
(every? true? (map #(same-state? %1 %2 tolerance geometry?) expected actual))
|
||||
|
||||
:else false))))
|
||||
|
||||
(defn compare-states
|
||||
"Record a failure of `phase` at `step` unless the normalized files
|
||||
@ -159,7 +206,7 @@
|
||||
`:no-undo-entry` (a step that added no entry changed the file),
|
||||
`:variant-undo` and `:variant-redo`."
|
||||
[situation step phase expected actual]
|
||||
(if (= expected actual)
|
||||
(if (same-state? expected actual)
|
||||
situation
|
||||
(add-failure situation {:phase phase
|
||||
:step step
|
||||
|
||||
@ -251,7 +251,7 @@
|
||||
(when (nil? shape)
|
||||
(let [present (->> (vals (:objects page))
|
||||
(map (comp thi/label :id))
|
||||
(sort)
|
||||
(sort-by str)
|
||||
(vec))]
|
||||
(throw (ex-info (str "Unbound shape name: " (pr-str name)
|
||||
". Shapes present in current page: " (pr-str present))
|
||||
|
||||
1330
common/src/app/common/test_helpers/composable/gen.cljc
Normal file
1330
common/src/app/common/test_helpers/composable/gen.cljc
Normal file
File diff suppressed because it is too large
Load Diff
154
common/src/app/common/test_helpers/composable/geometry.cljc
Normal file
154
common/src/app/common/test_helpers/composable/geometry.cljc
Normal file
@ -0,0 +1,154 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns app.common.test-helpers.composable.geometry
|
||||
"Expected geometry from authored inputs and parent frames. Only primitive
|
||||
constraint and transform math is shared with production."
|
||||
(:require
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.modifiers :as gm]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.math :as mth]
|
||||
[app.common.types.modifiers :as ctm]))
|
||||
|
||||
(defn- orientation-matrix
|
||||
"Resize uses constraints and dimensions. Parent placement supplies axis
|
||||
directions, without applying residual minimum-size scale a second time."
|
||||
[shape]
|
||||
(let [{:keys [a b c d]} (or (:transform shape) (gmt/matrix))
|
||||
horizontal (gpt/unit (gpt/point a b))
|
||||
vertical (gpt/unit (gpt/point c d))]
|
||||
(gmt/matrix (:x horizontal) (:y horizontal) (:x vertical) (:y vertical) 0 0)))
|
||||
|
||||
(defn turn-sign
|
||||
"-1 when `shape` is a mirror whose rotation is only the opposite of the
|
||||
turn its transform holds, so it stores a turn of its subtree subtracted;
|
||||
1 otherwise."
|
||||
[shape]
|
||||
(let [{:keys [a b]} (:transform shape)
|
||||
mirrored (not= (boolean (:flip-x shape)) (boolean (:flip-y shape)))
|
||||
sign (if (:flip-x shape) -1 1)
|
||||
rotation (or (:rotation shape) 0)
|
||||
same? #(mth/close? (mod (- %1 %2 -180) 360) 180 0.01)]
|
||||
(if (and mirrored (number? a) (number? b))
|
||||
(let [turn (mth/degrees (mth/atan2 (* sign b) (* sign a)))]
|
||||
(if (and (not (same? rotation turn)) (same? rotation (- turn))) -1 1))
|
||||
1)))
|
||||
|
||||
(defn- same-turn?
|
||||
[a b]
|
||||
(let [difference (mod (- a b) 360)]
|
||||
(or (< difference 0.01) (> difference 359.99))))
|
||||
|
||||
(defn rigid?
|
||||
"Whether the transform of `shape` turns and mirrors it without skew: its
|
||||
axes stay perpendicular."
|
||||
[shape]
|
||||
(let [{:keys [a b c d]} (or (:transform shape) (gmt/matrix))
|
||||
horizontal (gpt/point a b)
|
||||
vertical (gpt/point c d)]
|
||||
(and (not (mth/almost-zero? (gpt/length horizontal)))
|
||||
(not (mth/almost-zero? (gpt/length vertical)))
|
||||
(mth/close? (gpt/dot (gpt/unit horizontal) (gpt/unit vertical)) 0 0.001))))
|
||||
|
||||
(defn decomposes?
|
||||
"Whether the rotation and flip flags of `shape` compose its transform,
|
||||
turning before or after the flip."
|
||||
[shape]
|
||||
(let [{:keys [a b c d]} (or (:transform shape) (gmt/matrix))
|
||||
mirrored (not= (boolean (:flip-x shape)) (boolean (:flip-y shape)))
|
||||
sign (if (:flip-x shape) -1 1)
|
||||
turn (mth/degrees (mth/atan2 (* sign b) (* sign a)))
|
||||
rotation (or (:rotation shape) 0)]
|
||||
(and (= mirrored (neg? (- (* a d) (* b c))))
|
||||
(or (same-turn? rotation turn)
|
||||
(and mirrored (same-turn? rotation (- turn)))
|
||||
;; Both flags may record a half turn the rotation already counts.
|
||||
(and (:flip-x shape) (:flip-y shape) (same-turn? rotation (+ turn 180)))))))
|
||||
|
||||
(defn- orientation
|
||||
"R(`turn`)·Sx^`flip-x`·Sy^`flip-y` as `[angle mirror?]`, standing for
|
||||
R(angle)·Sx^mirror?: Sy is R(180)·Sx."
|
||||
[turn flip-x flip-y]
|
||||
[(cond-> turn flip-y (+ 180)) (not= (boolean flip-x) (boolean flip-y))])
|
||||
|
||||
(defn- compose
|
||||
[[a1 m1] [a2 m2]]
|
||||
[(+ a1 (if m1 (- a2) a2)) (not= m1 m2)])
|
||||
|
||||
(defn- inverse
|
||||
[[angle mirror?]]
|
||||
[(if mirror? angle (- angle)) mirror?])
|
||||
|
||||
(defn- shape-orientation
|
||||
[shape]
|
||||
(orientation (* (turn-sign shape) (or (:rotation shape) 0)) (:flip-x shape) (:flip-y shape)))
|
||||
|
||||
(defn reoriented-rotation
|
||||
"The rotation a shape with `values` (rotation and flips) stores once its
|
||||
parent goes from `source` to `target` and its flips become `flips'`.
|
||||
`sign` (`turn-sign`) tells which way its rotation stores its turn: a
|
||||
mirror keeps that way, and a shape that becomes one stores the opposite
|
||||
of its transform's turn."
|
||||
[values sign source target flips']
|
||||
(let [[angle _] (compose (compose (shape-orientation target) (inverse (shape-orientation source)))
|
||||
(orientation (* sign (or (:rotation values) 0)) (:flip-x values) (:flip-y values)))
|
||||
turn (cond-> angle (:flip-y flips') (- 180))
|
||||
mirror? #(not= (boolean (:flip-x %)) (boolean (:flip-y %)))]
|
||||
(mod (if (and (mirror? flips') (or (= sign -1) (not (mirror? values)))) (- turn) turn) 360)))
|
||||
|
||||
(defn child-placement
|
||||
"Place a main child against its expected copy parent. Only lower-level
|
||||
constraint and matrix math is shared with production, not sync code."
|
||||
[main main-parent parent objects]
|
||||
(let [resized (if (and (mth/close? (:width main-parent) (:width parent) 0.01)
|
||||
(mth/close? (:height main-parent) (:height parent) 0.01))
|
||||
objects
|
||||
;; a layout owns a filling or hugging parent's size and would drop
|
||||
;; the resize, so the parent takes it as a fixed size
|
||||
(let [tree (gm/set-objects-modifiers
|
||||
{(:id main-parent)
|
||||
{:modifiers (ctm/change-size main-parent (:width parent) (:height parent))}}
|
||||
(update objects (:id main-parent) assoc
|
||||
:layout-item-h-sizing :fix :layout-item-v-sizing :fix))]
|
||||
(reduce-kv (fn [objects id {:keys [modifiers]}]
|
||||
(update objects id gsh/transform-shape modifiers)) objects tree)))
|
||||
main (get resized (:id main))
|
||||
main-parent (get resized (:id main-parent))
|
||||
center (gsh/shape->center main-parent)
|
||||
turn (gmt/multiply (orientation-matrix parent)
|
||||
(gmt/inverse (orientation-matrix main-parent)))
|
||||
placed (if (gmt/unit? turn) main
|
||||
(gsh/apply-transform main (gmt/transform-in center turn)))
|
||||
;; Flip flags follow the parent's composition history. A single
|
||||
;; large turn can toggle both flags where several small turns do not.
|
||||
flipped? (fn [key]
|
||||
(odd? (count (filter identity [(get main key) (get main-parent key)
|
||||
(get parent key)]))))]
|
||||
(let [flips {:flip-x (flipped? :flip-x) :flip-y (flipped? :flip-y)}]
|
||||
(-> placed
|
||||
(gsh/move (gpt/subtract (gsh/shape->center parent) center))
|
||||
(merge flips)
|
||||
(assoc :rotation (reoriented-rotation main (turn-sign main) main-parent parent flips))))))
|
||||
|
||||
(defn follow-parent-size
|
||||
"`child` resized through its own constraints as its parent goes from
|
||||
`parent` to `parent'`. A parent with a layout, of the same size or
|
||||
without a selrect leaves it as it is."
|
||||
[child parent parent']
|
||||
(let [sr (:selrect parent)
|
||||
sr' (:selrect parent')
|
||||
sx (when (and sr sr') (/ (:width sr') (max 0.01 (:width sr))))
|
||||
sy (when (and sr sr') (/ (:height sr') (max 0.01 (:height sr))))]
|
||||
(if (or (nil? sx) (and (mth/close? sx 1) (mth/close? sy 1)))
|
||||
child
|
||||
(let [modifiers (ctm/resize (ctm/empty) (gpt/point sx sy) (first (:points parent))
|
||||
(:transform parent) (:transform-inverse parent))
|
||||
resized (gsh/transform-shape parent modifiers)]
|
||||
(gsh/transform-shape child (gsh/calc-child-modifiers parent child modifiers false
|
||||
(:points child) (:points parent)
|
||||
(delay (:points resized))))))))
|
||||
202
common/src/app/common/test_helpers/composable/grid.cljc
Normal file
202
common/src/app/common/test_helpers/composable/grid.cljc
Normal file
@ -0,0 +1,202 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns app.common.test-helpers.composable.grid
|
||||
"Independent cell expectations. No production grid assignment or direction
|
||||
helper supplies expected values.")
|
||||
|
||||
(defn get-context
|
||||
[shape]
|
||||
{:rows (count (:layout-grid-rows shape))
|
||||
:columns (count (:layout-grid-columns shape))
|
||||
:direction (or (:layout-grid-dir shape) :row)})
|
||||
|
||||
(defn get-cells
|
||||
[shape]
|
||||
(with-meta (->> (vals (:layout-grid-cells shape))
|
||||
(sort-by (juxt :row :column))
|
||||
(mapv #(dissoc % :id)))
|
||||
{::context (get-context shape)}))
|
||||
|
||||
(defn remap-groups
|
||||
[groups ids-map]
|
||||
(cond-> groups
|
||||
(:layout-grid-cells groups)
|
||||
(update-in [:layout-grid-cells :layout-grid-cells]
|
||||
(fn [cells]
|
||||
(with-meta (mapv #(update % :shapes (fn [ids] (mapv (fn [id] (get ids-map id id)) ids))) cells)
|
||||
(meta cells))))))
|
||||
|
||||
(defn get-child-map
|
||||
"Pair identities through refs, never through resulting cell membership."
|
||||
[objects source target]
|
||||
(let [source-ids (set (:shapes source))
|
||||
target-ids (set (:shapes target))
|
||||
find-ref (fn [ids id]
|
||||
(loop [candidate id seen #{}]
|
||||
(cond
|
||||
(contains? ids candidate) candidate
|
||||
(or (nil? candidate) (contains? seen candidate)) nil
|
||||
:else (recur (:shape-ref (get objects candidate)) (conj seen candidate)))))
|
||||
forward (into {} (keep #(when-let [id (find-ref target-ids %)] [% id])) (:shapes source))
|
||||
backward (into {} (keep #(when-let [id (find-ref source-ids %)] [id %])) (:shapes target))]
|
||||
(merge forward backward)))
|
||||
|
||||
(defn- flow-order
|
||||
"The order in which a grid of `direction` flows its auto cells."
|
||||
[direction]
|
||||
(if (= direction :column) (juxt :column :row) (juxt :row :column)))
|
||||
|
||||
(defn- fix-after-gap
|
||||
"`cells`, in flow order, with each auto cell that holds a shape after an
|
||||
empty, manual or spanning one made manual, as the layout keeps it."
|
||||
[cells]
|
||||
(second
|
||||
(reduce (fn [[ended result] cell]
|
||||
(let [manual (or (= :manual (:position cell))
|
||||
(not= 1 (:row-span cell) (:column-span cell))
|
||||
(and ended (seq (:shapes cell)) (= :auto (:position cell))))]
|
||||
[(or ended manual (empty? (:shapes cell)))
|
||||
(conj result (cond-> cell
|
||||
(and manual (= :auto (:position cell))) (assoc :position :manual)))]))
|
||||
[false []] cells)))
|
||||
|
||||
(defn direction-cells
|
||||
[shape direction]
|
||||
(let [cells (get-cells shape)
|
||||
eligible (fn [cell] (and (= :auto (:position cell)) (= 1 (:row-span cell) (:column-span cell))))
|
||||
old (filter eligible (sort-by (flow-order (:layout-grid-dir shape)) cells))
|
||||
new (filter eligible (sort-by (flow-order direction) cells))
|
||||
members (vec (mapcat :shapes old))
|
||||
by-cell (into {} (map-indexed (fn [index cell]
|
||||
[[(:row cell) (:column cell)]
|
||||
(if-let [id (nth members index nil)] [id] [])]) new))]
|
||||
(if (= (or (:layout-grid-dir shape) :row) direction)
|
||||
cells
|
||||
(with-meta (mapv (fn [cell]
|
||||
(if-let [ids (get by-cell [(:row cell) (:column cell)])]
|
||||
(assoc cell :shapes ids)
|
||||
cell)) cells)
|
||||
(meta cells)))))
|
||||
|
||||
(defn get-intended-values
|
||||
[shape action value]
|
||||
(let [before (get-cells shape)
|
||||
cells (case action
|
||||
:direction (direction-cells shape value)
|
||||
:cell (mapv #(if (= [(:row value) (:column value)] [(:row %) (:column %)])
|
||||
(merge % (:props value)) %) before))
|
||||
;; the edit reflows the grid, which keeps cells after a gap in place
|
||||
cells (->> cells
|
||||
(sort-by (flow-order (if (= action :direction) value (:layout-grid-dir shape))))
|
||||
fix-after-gap
|
||||
(sort-by (juxt :row :column))
|
||||
vec)]
|
||||
(cond-> {:layout-grid-cells (with-meta cells
|
||||
{::context (cond-> (get-context shape)
|
||||
(= action :direction) (assoc :direction value))})}
|
||||
(= action :direction) (assoc :layout-grid-dir value))))
|
||||
|
||||
(defn edit
|
||||
[model shape action value]
|
||||
(if (:shape-ref shape)
|
||||
(let [intended (get-intended-values shape action value)
|
||||
;; a direction change authors the cells only when it moves auto
|
||||
;; items itself; the reflow after it derives the rest
|
||||
derived? (and (= action :direction)
|
||||
(= (direction-cells shape value) (get-cells shape)))]
|
||||
(reduce-kv (fn [model key value]
|
||||
(if (= value (if (= key :layout-grid-cells) (get-cells shape) (get shape key)))
|
||||
model
|
||||
(assoc-in model [(:id shape) key] {key value})))
|
||||
model (cond-> intended derived? (dissoc :layout-grid-cells))))
|
||||
model))
|
||||
|
||||
(defn- extend-cells
|
||||
[cells before after]
|
||||
(into cells
|
||||
(for [row (range 1 (inc (:rows after)))
|
||||
column (range 1 (inc (:columns after)))
|
||||
:when (or (> row (:rows before)) (> column (:columns before)))
|
||||
:when (not-any? #(and (<= (:row %) row (+ (:row %) (:row-span %) -1))
|
||||
(<= (:column %) column (+ (:column %) (:column-span %) -1))) cells)]
|
||||
{:row row :column column :row-span 1 :column-span 1 :position :auto
|
||||
:align-self :auto :justify-self :auto :shapes []})))
|
||||
|
||||
(defn flow-shapes
|
||||
"The children of the grid `shape` as `:shapes` lists a grid that orders
|
||||
them by the flow of its cells: in reverse flow order, with hidden and
|
||||
absolute children, which hold no cell, in their places."
|
||||
[shape]
|
||||
(let [in-cell (into [] (comp (keep (comp first :shapes))
|
||||
(filter (set (:shapes shape)))
|
||||
(distinct))
|
||||
(sort-by (flow-order (:layout-grid-dir shape)) (vals (:layout-grid-cells shape))))
|
||||
placed (set in-cell)]
|
||||
(first (reduce (fn [[result pending] id]
|
||||
(if (contains? placed id)
|
||||
[(conj result (first pending)) (rest pending)]
|
||||
[(conj result id) pending]))
|
||||
[[] (reverse in-cell)]
|
||||
(:shapes shape)))))
|
||||
|
||||
(defn matches-context?
|
||||
[shape cells]
|
||||
(if-let [{:keys [rows columns] :as context} (::context (meta cells))]
|
||||
(and (= context (get-context shape))
|
||||
(every? #(and (<= 1 (:row %) (+ (:row %) (:row-span %) -1) rows)
|
||||
(<= 1 (:column %) (+ (:column %) (:column-span %) -1) columns)) cells))
|
||||
true))
|
||||
|
||||
(defn settle-cells
|
||||
"Predict inherited and automatic track growth from prior cells, reference
|
||||
context and child identities. Result cell values never supply expectations.
|
||||
Children without a cell take free cells in the order of their main shapes
|
||||
in `source`, as sync adds them, whatever order the copy gives them after."
|
||||
([cells shape objects] (settle-cells cells shape objects nil nil))
|
||||
([cells shape objects reference] (settle-cells cells shape objects reference nil))
|
||||
([cells shape objects reference source]
|
||||
(let [prior (::context (meta cells))
|
||||
participating (filterv #(let [child (get objects %)]
|
||||
(not (or (:hidden child) (:layout-item-absolute child)))) (:shapes shape))
|
||||
members (set participating)
|
||||
trimmed (mapv #(update % :shapes (fn [ids] (filterv members ids))) cells)
|
||||
assigned (set (mapcat :shapes trimmed))
|
||||
missing (remove assigned participating)
|
||||
;; A pending/unaccepted source can be ahead of this copy. Use its
|
||||
;; context once track writes or added children have reached the copy.
|
||||
context (if (and prior reference
|
||||
(or (not= prior (get-context shape))
|
||||
(> (count missing) (count (filter #(empty? (:shapes %)) trimmed)))))
|
||||
reference prior)
|
||||
cells (if context (extend-cells trimmed prior context) trimmed)
|
||||
order (flow-order (or (:direction context) (:layout-grid-dir shape)))
|
||||
cells (->> cells (sort-by order) fix-after-gap)
|
||||
assigned (set (mapcat :shapes cells))
|
||||
rank (into {} (map-indexed (fn [i id] [id i])) (:shapes source))
|
||||
missing (sort-by #(get rank (:shape-ref (get objects %)) ##Inf)
|
||||
(remove assigned participating))
|
||||
free (count (filter #(empty? (:shapes %)) cells))
|
||||
minimum (when context (cond-> context
|
||||
(> (count missing) free)
|
||||
(-> (update :rows max 1) (update :columns max 1))))
|
||||
cells (if minimum (extend-cells cells context minimum) cells)
|
||||
free (count (filter #(empty? (:shapes %)) cells))
|
||||
deficit (- (count missing) free)
|
||||
grown (when minimum
|
||||
(cond-> minimum
|
||||
(and (pos? deficit) (= :row (:direction minimum)))
|
||||
(update :columns + (quot (+ deficit (:rows minimum) -1) (:rows minimum)))
|
||||
(and (pos? deficit) (= :column (:direction minimum)))
|
||||
(update :rows + (quot (+ deficit (:columns minimum) -1) (:columns minimum)))))
|
||||
cells (if grown (extend-cells cells minimum grown) cells)
|
||||
[cells _] (reduce (fn [[result pending] cell]
|
||||
(if (and (seq pending) (empty? (:shapes cell)))
|
||||
[(conj result (assoc cell :position :auto :shapes [(first pending)])) (rest pending)]
|
||||
[(conj result cell) pending]))
|
||||
[[] missing] (sort-by order cells))]
|
||||
(with-meta (->> cells fix-after-gap (sort-by (juxt :row :column)) vec)
|
||||
(cond-> (meta cells) grown (assoc ::context grown))))))
|
||||
736
common/src/app/common/test_helpers/composable/oracle.cljc
Normal file
736
common/src/app/common/test_helpers/composable/oracle.cljc
Normal file
@ -0,0 +1,736 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns app.common.test-helpers.composable.oracle
|
||||
"Checks authored overrides against actual copies. Expected values come
|
||||
from the shadow and near main, never from the sync implementation."
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.math :as mth]
|
||||
[app.common.test-helpers.composable.comp.files :as cf]
|
||||
[app.common.test-helpers.composable.comp.nodes :as n]
|
||||
[app.common.test-helpers.composable.comp.undo-check :as uc]
|
||||
[app.common.test-helpers.composable.core :as tm]
|
||||
[app.common.test-helpers.composable.geometry :as geom]
|
||||
[app.common.test-helpers.composable.grid :as grid]
|
||||
[app.common.test-helpers.composable.shadow :as shadow]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.normalize :as thn]
|
||||
[app.common.test-helpers.texts :as thtx]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.common.types.text :as txt]
|
||||
[clojure.walk :as walk]))
|
||||
|
||||
(defn fail
|
||||
[invariant details]
|
||||
(throw (ex-info (str "Component invariant " (name invariant) " failed")
|
||||
(assoc details :invariant invariant))))
|
||||
|
||||
(defn check-requested-grid
|
||||
"The grid edit `action` gave `shape` the values it asked for. A direction
|
||||
change that moves no item of a copy that takes its cells from its main
|
||||
leaves the cells its main gives, which I4 checks against the main."
|
||||
[shape before action value]
|
||||
(let [main-cells? (and (= action :direction) (:shape-ref before)
|
||||
(not (contains? (:touched before) :layout-grid-cells))
|
||||
(= (grid/direction-cells before value) (grid/get-cells before)))
|
||||
expected (cond-> (grid/get-intended-values before action value)
|
||||
main-cells? (dissoc :layout-grid-cells))
|
||||
actual (cond-> {:layout-grid-cells (grid/get-cells shape)}
|
||||
main-cells? (dissoc :layout-grid-cells)
|
||||
(= action :direction) (assoc :layout-grid-dir (:layout-grid-dir shape)))]
|
||||
(when-not (= expected actual)
|
||||
(fail :I9 {:phase :requested-grid :expected expected :actual actual}))))
|
||||
|
||||
(defn snapshot
|
||||
[situation]
|
||||
(into {} (map (fn [[id file]]
|
||||
[id (thn/normalize-file file {:position-data? false})]))
|
||||
(assoc (tm/aux-files situation) (:id (tm/file situation)) (tm/file situation))))
|
||||
|
||||
(defn derived-attributes
|
||||
[objects shape]
|
||||
(let [layout-child (and (ctl/any-layout-immediate-child? objects shape)
|
||||
(not (ctl/position-absolute? shape)))
|
||||
text (= :text (:type shape))
|
||||
auto-width (and text (= :auto-width (:grow-type shape)))
|
||||
auto-height (and text (#{:auto-width :auto-height} (:grow-type shape)))
|
||||
width-owned (or auto-width (and (or layout-child (ctl/any-layout? shape))
|
||||
(#{:fill :auto} (:layout-item-h-sizing shape))))
|
||||
height-owned (or auto-height (and (or layout-child (ctl/any-layout? shape))
|
||||
(#{:fill :auto} (:layout-item-v-sizing shape))))
|
||||
;; a layout resizes a turned child along its parent's axes, so both sizes;
|
||||
;; a skewed transform is turned whichever rotation the shape stores
|
||||
{:keys [b c]} (or (:transform shape) (gmt/matrix))
|
||||
turned (and layout-child (or width-owned height-owned)
|
||||
(or (not (mth/close? (mod (or (:rotation shape) 0) 360) 0))
|
||||
(not (mth/close? (or b 0) 0 1e-6))
|
||||
(not (mth/close? (or c 0) 0 1e-6))))
|
||||
width-owned (or width-owned turned)
|
||||
height-owned (or height-owned turned)]
|
||||
(cond-> #{}
|
||||
layout-child (into #{:x :y})
|
||||
width-owned (conj :width)
|
||||
height-owned (conj :height)
|
||||
(or layout-child width-owned height-owned) (into #{:points :selrect}))))
|
||||
|
||||
(defn- matrix-effect
|
||||
"Matrix coefficients have no pixel unit. Compare their effect over the
|
||||
shape's local bounds. Keep the inputs for paired derived-axis comparison."
|
||||
[shape matrix derived]
|
||||
(let [bounds (select-keys shape [:width :height])
|
||||
half-width (/ (:width bounds) 2)
|
||||
half-height (/ (:height bounds) 2)]
|
||||
(with-meta
|
||||
(mapv #(gpt/transform % (or matrix (gmt/matrix)))
|
||||
[(gpt/point (- half-width) (- half-height))
|
||||
(gpt/point half-width (- half-height))
|
||||
(gpt/point half-width half-height)
|
||||
(gpt/point (- half-width) half-height)])
|
||||
{::matrix matrix ::bounds bounds ::derived derived})))
|
||||
|
||||
(declare get-derived-reference-origins)
|
||||
|
||||
(defn untracked-position?
|
||||
"Whether `shape` is hidden inside a layout: out of its flow and invisible,
|
||||
its position is nobody's to keep, and the layout places it once shown."
|
||||
[objects shape]
|
||||
(and (:hidden shape)
|
||||
(ctl/any-layout-immediate-child? objects shape)))
|
||||
|
||||
(defn- canonical-variants
|
||||
"`content` with the variant id of each numeric weight the one the notation
|
||||
gives its family, weight and style: weights are told apart by weight and
|
||||
style, and the renderer picks the variant closest to them."
|
||||
[content]
|
||||
(walk/postwalk
|
||||
(fn [node]
|
||||
(if-let [weight (and (map? node)
|
||||
(contains? node :font-variant-id)
|
||||
(d/parse-integer (str (:font-weight node))))]
|
||||
(assoc node :font-variant-id
|
||||
(thtx/variant-id (:font-family node) weight (= "italic" (:font-style node))))
|
||||
node))
|
||||
content))
|
||||
|
||||
(defn design-snapshot
|
||||
"Design inputs without derived placement, dimensions and bookkeeping.
|
||||
Geometry remains unrounded; equivalent? applies its tolerance directly."
|
||||
([situation] (design-snapshot situation {}))
|
||||
([situation {:keys [free-head-placement relative-free-head-placement]
|
||||
:or {free-head-placement true}}]
|
||||
(let [origins (when (and free-head-placement relative-free-head-placement)
|
||||
(get-derived-reference-origins situation))]
|
||||
(walk/postwalk
|
||||
(fn [value]
|
||||
(if (and (map? value) (contains? value :parent-id))
|
||||
(cond-> (-> value
|
||||
(dissoc :remote-synced)
|
||||
;; with the transform, the flips only add whether it mirrors:
|
||||
;; one flip or the other is the same mirror turned half a turn
|
||||
(assoc :flip-x (not= (boolean (:flip-x value)) (boolean (:flip-y value)))
|
||||
:flip-y false)
|
||||
(update :fixed-scroll boolean))
|
||||
(= :text (:type value)) (update :content (comp thtx/view canonical-variants))
|
||||
;; the transform carries the turn, whichever rotation the shape
|
||||
;; stores for it
|
||||
:always (dissoc :rotation))
|
||||
value))
|
||||
(walk/postwalk
|
||||
(fn [value]
|
||||
(if (and (map? value) (:objects value))
|
||||
(update value :objects
|
||||
(fn [objects]
|
||||
(into {} (map (fn [[id shape]]
|
||||
[id (-> (gsh/move shape
|
||||
(gpt/negate
|
||||
(or (get origins id)
|
||||
(gpt/point (get-in objects [(:parent-id shape) :x] 0)
|
||||
(get-in objects [(:parent-id shape) :y] 0)))))
|
||||
(as-> moved (let [derived (derived-attributes objects shape)]
|
||||
(assoc moved
|
||||
:transform (matrix-effect shape (:transform moved) derived)
|
||||
;; what the inverse undoes of the transform: its own effect magnifies a squashed axis
|
||||
:transform-inverse (matrix-effect shape (gmt/multiply (or (:transform-inverse moved) (gmt/matrix))
|
||||
(or (:transform moved) (gmt/matrix)))
|
||||
derived))))
|
||||
;; Measurement preserves the oriented first
|
||||
;; corner, not the unrotated rectangle's x/y.
|
||||
(cond-> (and (= :text (:type shape))
|
||||
(#{:auto-width :auto-height} (:grow-type shape)))
|
||||
(as-> moved (assoc moved :x (:x (first (:points moved)))
|
||||
:y (:y (first (:points moved))))))
|
||||
(as-> snapshot (apply dissoc snapshot
|
||||
(cond-> (derived-attributes objects shape)
|
||||
(or (untracked-position? objects shape)
|
||||
(and free-head-placement (:component-id shape) (:shape-ref shape)
|
||||
(= 1 (count (ctn/get-parent-copy-heads objects shape)))))
|
||||
(into #{:x :y :points :selrect}))))
|
||||
(update :constraints-h #(or % (gsh/default-constraints-h shape)))
|
||||
(update :constraints-v #(or % (gsh/default-constraints-v shape)))
|
||||
;; a deleted component keeps its objects as stored, and sync
|
||||
;; does not lay them out again: the geometry a layout gave a
|
||||
;; shape, or one below it, is not part of its design
|
||||
(cond-> (and (:deleted value)
|
||||
(some #(seq (derived-attributes objects (get objects %)))
|
||||
(cons (:id shape) (cfh/get-parent-ids objects (:id shape)))))
|
||||
(dissoc :x :y :width :height :points :selrect :transform :transform-inverse)))])) objects)))
|
||||
value))
|
||||
(snapshot situation))))))
|
||||
|
||||
(defn canonical
|
||||
"Design data with shape, component and grid-cell IDs named by tree path.
|
||||
Pure and frontend backends allocate different IDs for the same action.
|
||||
Missing references use retained source paths; live names take precedence."
|
||||
([situation] (canonical situation {}))
|
||||
([situation opts]
|
||||
(let [files (sort-by (comp str key) (snapshot situation))
|
||||
ids (atom {#uuid "00000000-0000-0000-0000-000000000000" :root})]
|
||||
(letfn [(name-tree [names objects id path]
|
||||
(when-let [shape (get objects id)]
|
||||
(swap! names assoc id path)
|
||||
(doseq [[cell-id cell] (:layout-grid-cells shape)]
|
||||
(swap! names assoc cell-id [path :cell (:row cell) (:column cell)]))
|
||||
(doseq [[index child] (map-indexed vector (:shapes shape))]
|
||||
(name-tree names objects child (conj path index)))))
|
||||
(name-file [names file path]
|
||||
(swap! names assoc (:id file) path)
|
||||
(doseq [[page-index page-id] (map-indexed vector (get-in file [:data :pages]))
|
||||
:let [page (get-in file [:data :pages-index page-id])
|
||||
path (conj path :page page-index)]]
|
||||
(swap! names assoc page-id path)
|
||||
(doseq [[index child] (map-indexed vector (get-in page [:objects #uuid "00000000-0000-0000-0000-000000000000" :shapes]))]
|
||||
(name-tree names (:objects page) child (conj path index))))
|
||||
(doseq [[index [component-id component]]
|
||||
(map-indexed vector (sort-by (comp str key) (get-in file [:data :components])))
|
||||
:let [path (conj path :component index)]]
|
||||
(swap! names assoc component-id path)
|
||||
(when (:objects component)
|
||||
(name-tree names (:objects component) (:main-instance-id component) (conj path :main)))))]
|
||||
(doseq [[file-index [_ file]] (map-indexed vector files)]
|
||||
(name-file ids file [:file file-index]))
|
||||
(when (:accepted-libraries situation)
|
||||
(doseq [[file-id file objects shape]
|
||||
(sort-by #(pr-str (get @ids (:id (nth % 3))))
|
||||
(for [[file-id file] files
|
||||
objects (cf/object-trees file)
|
||||
shape (vals objects)
|
||||
:when (and (:shape-ref shape) (contains? @ids (:id shape)))]
|
||||
[file-id file objects shape]))
|
||||
:when (not (contains? @ids (:shape-ref shape)))]
|
||||
(let [libraries (cf/reference-libraries situation file-id (:id shape))
|
||||
container (ctn/make-container {:objects objects} :page)]
|
||||
(when-let [reference (ctf/find-ref-shape file container libraries shape
|
||||
:include-deleted? true :with-context? true)]
|
||||
(let [source (:file (meta reference))]
|
||||
(when-let [source-path (get @ids (:id source))]
|
||||
(let [names (atom {})]
|
||||
(name-file names source source-path)
|
||||
(when-let [path (get @names (:shape-ref shape))]
|
||||
(swap! ids assoc (:shape-ref shape) [:retained-ref (get @ids (:id shape)) path])))))))))
|
||||
(walk/postwalk #(if (uuid? %) (get @ids % %) %) (design-snapshot situation opts))))))
|
||||
|
||||
(defn- paired-matrix-effects
|
||||
[shape other]
|
||||
(reduce
|
||||
(fn [shape attr]
|
||||
(let [{:keys [::matrix ::bounds ::derived]} (meta (get shape attr))
|
||||
other-bounds (::bounds (meta (get other attr)))]
|
||||
(if (or (nil? other-bounds) (not-any? derived [:width :height]) (= bounds other-bounds))
|
||||
shape
|
||||
(let [bounds (reduce (fn [bounds axis]
|
||||
(cond-> bounds
|
||||
(contains? derived axis)
|
||||
(assoc axis (max (get bounds axis) (get other-bounds axis)))))
|
||||
bounds [:width :height])]
|
||||
(assoc shape attr (matrix-effect bounds matrix derived))))))
|
||||
shape [:transform :transform-inverse]))
|
||||
|
||||
(defn equivalent?
|
||||
"Compare design data, allowing 0.01 only within shape geometry. Compare
|
||||
matrices over common derived dimensions, retaining each fixed dimension."
|
||||
[expected actual]
|
||||
(if (and (map? expected) (map? actual))
|
||||
(and (= (set (keys expected)) (set (keys actual)))
|
||||
(if (and (contains? expected :parent-id) (contains? actual :parent-id))
|
||||
(uc/same-state? (paired-matrix-effects expected actual)
|
||||
(paired-matrix-effects actual expected) 0.01)
|
||||
(every? #(equivalent? (get expected %) (get actual %)) (keys expected))))
|
||||
(uc/same-state? expected actual 0.01)))
|
||||
|
||||
(defn- constraint-derived-attributes
|
||||
"The dimensions a constraint ties to the parent. Under a plain parent the
|
||||
parent's resize history is unknown, and such a resize is not an override."
|
||||
[shape]
|
||||
(cond-> #{}
|
||||
(#{:scale :leftright} (:constraints-h shape)) (conj :width)
|
||||
(#{:scale :topbottom} (:constraints-v shape)) (conj :height)))
|
||||
|
||||
(defn- with-derived-geometry
|
||||
"Derived dimensions and positions come from the shape. A placement centred
|
||||
on the copy (`centred?`) assumed the main's size, so a derived resize keeps
|
||||
the shape's first corner, as a layout resize does."
|
||||
[objects shape expected centred?]
|
||||
(let [derived (cond-> (derived-attributes objects shape)
|
||||
centred? (into (constraint-derived-attributes shape)))
|
||||
width (if (contains? derived :width) (:width shape) (:width expected))
|
||||
height (if (contains? derived :height) (:height shape) (:height expected))
|
||||
resized? (not (and (mth/close? width (:width expected) 0.01)
|
||||
(mth/close? height (:height expected) 0.01)))
|
||||
expected (cond-> expected
|
||||
resized? (gsh/transform-shape (ctm/change-size expected width height)))
|
||||
expected (cond-> expected
|
||||
(and resized? centred?)
|
||||
(gsh/move (gpt/subtract (first (:points shape)) (first (:points expected)))))]
|
||||
(if (every? derived [:x :y :width :height])
|
||||
;; the layout gives the whole geometry, with the skew of a turned child
|
||||
(merge expected (select-keys shape [:x :y :width :height :points :selrect
|
||||
:transform :transform-inverse]))
|
||||
(gsh/move expected
|
||||
(gpt/point (if (contains? derived :x) (- (:x shape) (:x expected)) 0)
|
||||
(if (contains? derived :y) (- (:y shape) (:y expected)) 0))))))
|
||||
|
||||
(declare same-turn?)
|
||||
|
||||
(defn- same-orientation?
|
||||
[shape other]
|
||||
(and (same-turn? (or (:rotation shape) 0) (or (:rotation other) 0))
|
||||
(= (boolean (:flip-x shape)) (boolean (:flip-x other)))
|
||||
(= (boolean (:flip-y shape)) (boolean (:flip-y other)))))
|
||||
|
||||
(defn- in-parent-orientation
|
||||
"`main` turned by its parent `main-parent`'s difference to `parent`,
|
||||
about its own centre, with the top-left corner of `shape`."
|
||||
[main main-parent parent shape]
|
||||
(let [relative (gmt/multiply (or (:transform parent) (gmt/matrix))
|
||||
(or (:transform-inverse main-parent) (gmt/matrix)))
|
||||
flip (fn [key]
|
||||
(cond-> (boolean (get main key))
|
||||
(not= (boolean (get main-parent key)) (boolean (get parent key))) not))
|
||||
turned (cond-> main
|
||||
(not (gmt/unit? relative))
|
||||
(gsh/apply-transform (gmt/transform-in (gsh/shape->center main) relative)))]
|
||||
(-> turned
|
||||
(gsh/move (gpt/subtract (gpt/point (-> shape :selrect :x) (-> shape :selrect :y))
|
||||
(gpt/point (-> turned :selrect :x) (-> turned :selrect :y))))
|
||||
(assoc :rotation (mod (+ (or (:rotation main) 0)
|
||||
(- (or (:rotation parent) 0) (or (:rotation main-parent) 0)))
|
||||
360)
|
||||
:flip-x (flip :flip-x)
|
||||
:flip-y (flip :flip-y)))))
|
||||
|
||||
(defn expected-geometry
|
||||
([file container libraries shape]
|
||||
(expected-geometry file container libraries shape (constantly libraries)))
|
||||
([file container libraries shape libraries-for-shape]
|
||||
(let [objects (:objects container)]
|
||||
(letfn [(expected [shape visited]
|
||||
(when (contains? visited (:id shape))
|
||||
(fail :I1 {:shape (:name shape) :reason :parent-cycle}))
|
||||
(if (or (contains? (:touched shape) :geometry-group)
|
||||
;; a constraint the copy authors applies to later resizes only
|
||||
(and (contains? (:touched shape) :constraints-group)
|
||||
(seq (constraint-derived-attributes shape))
|
||||
(:shape-ref (get objects (:parent-id shape)))))
|
||||
shape
|
||||
(let [libraries (libraries-for-shape shape)
|
||||
main (ctf/find-ref-shape file container libraries shape :include-deleted? true :with-context? true)
|
||||
parent (get objects (:parent-id shape))
|
||||
;; A parent resize reaches the child through the child's own
|
||||
;; constraints once the copy authors them.
|
||||
main-objects (cond-> (get-in (meta main) [:container :objects])
|
||||
(and main (contains? (:touched shape) :constraints-group))
|
||||
(update (:id main) merge
|
||||
(d/without-nils (select-keys shape [:constraints-h :constraints-v]))))
|
||||
main-parent (get main-objects (:parent-id main))
|
||||
;; a reset refreshes its subtree from the loaded library while
|
||||
;; the parent keeps the version it accepted, which may lack a turn;
|
||||
;; a swapped parent holds the child in the main of its content
|
||||
parent-main (when (and main-parent (:shape-ref parent)
|
||||
(not (contains? (:touched parent) :geometry-group)))
|
||||
(ctf/find-content-ref-shape file container (libraries-for-shape parent) parent
|
||||
:include-deleted? true))
|
||||
pending-turn? (and (some? parent-main)
|
||||
(not (same-orientation? parent-main main-parent)))
|
||||
centred? (and (some? main) (not (and (:shape-ref parent) main-parent)))
|
||||
placed (cond
|
||||
(nil? main) shape
|
||||
|
||||
;; the head takes its main's size in the parent's
|
||||
;; orientation, from its own corner
|
||||
pending-turn?
|
||||
(in-parent-orientation main main-parent parent shape)
|
||||
|
||||
(and (:shape-ref parent) main-parent)
|
||||
(geom/child-placement main main-parent (expected parent (conj visited (:id shape)))
|
||||
main-objects)
|
||||
:else
|
||||
;; Ordinary parents left by detach still place their nested copies.
|
||||
(let [turn (gmt/multiply (or (:transform shape) (gmt/matrix))
|
||||
(or (:transform-inverse main) (gmt/matrix)))
|
||||
placed (if (gmt/unit? turn) main
|
||||
(gsh/apply-transform main (gmt/transform-in (gsh/shape->center main) turn)))]
|
||||
(-> placed
|
||||
(gsh/move (gpt/subtract (gsh/shape->center shape) (gsh/shape->center placed)))
|
||||
;; This is the placement matrix just applied.
|
||||
;; Re-decomposing a .01px frame can add scale
|
||||
;; noise that grows in its larger children.
|
||||
(assoc :transform (:transform shape)
|
||||
:transform-inverse (:transform-inverse shape)
|
||||
:rotation (:rotation shape)
|
||||
:flip-x (:flip-x shape) :flip-y (:flip-y shape)))))
|
||||
content (when (ctk/swapped? shape)
|
||||
(ctf/find-content-ref-shape file container libraries shape :include-deleted? true))
|
||||
placed (if content
|
||||
;; Content supplies size about the first corner,
|
||||
;; which a turned or flipped head keeps; an
|
||||
;; unturned one keeps its untransformed top-left.
|
||||
(cond-> (gsh/transform-shape
|
||||
placed (ctm/change-size placed (:width content) (:height content)))
|
||||
(gmt/unit? (or (:transform placed) (gmt/matrix)))
|
||||
(gsh/absolute-move (gpt/point (get-in placed [:selrect :x])
|
||||
(get-in placed [:selrect :y]))))
|
||||
placed)]
|
||||
(with-derived-geometry objects shape placed centred?))))]
|
||||
(expected shape #{})))))
|
||||
|
||||
(defn- get-derived-reference-origins
|
||||
"Backend parity permits source placement derived by reflow to differ.
|
||||
Untouched images compare offsets from their expected source frame,
|
||||
including hidden/absolute children of visible layout sources. Inherited
|
||||
placement can differ while a drifted image still fails.
|
||||
Strict same-run sync comparison never uses these origins."
|
||||
[situation]
|
||||
(into {}
|
||||
(for [[file-id file] (cf/all-files situation)
|
||||
page (vals (get-in file [:data :pages-index]))
|
||||
[id shape] (:objects page)
|
||||
:when (and (:shape-ref shape)
|
||||
(not (ctk/touched-group? shape :geometry-group)))
|
||||
:let [libraries (cf/reference-libraries situation file-id id)
|
||||
source (ctf/find-ref-shape file page libraries shape
|
||||
:include-deleted? true :with-context? true)
|
||||
source-objects (get-in (meta source) [:container :objects])]
|
||||
:when (or (and (:component-id shape)
|
||||
(> (count (ctn/get-parent-copy-heads (:objects page) shape)) 1)
|
||||
(:component-id source) (:shape-ref source)
|
||||
(= 1 (count (ctn/get-parent-copy-heads source-objects source))))
|
||||
(and (not (contains? (derived-attributes (:objects page) shape) :x))
|
||||
(contains? (derived-attributes source-objects source) :x)))
|
||||
:let [expected (expected-geometry file page libraries shape
|
||||
#(cf/reference-libraries situation file-id (:id %)))]]
|
||||
[id (gpt/point (:x expected) (:y expected))])))
|
||||
|
||||
(defn- same-turn?
|
||||
"Whether two rotations in degrees describe the same turn."
|
||||
[a b]
|
||||
(let [difference (mod (- a b) 360)]
|
||||
(or (< difference 0.01) (> difference 359.99))))
|
||||
|
||||
(defn- geometry-differences
|
||||
([objects shape expected] (geometry-differences objects shape expected shape))
|
||||
([objects shape expected ownership]
|
||||
(let [rotation (or (:rotation shape) 0)
|
||||
exp-rotation (or (:rotation expected) 0)
|
||||
;; Under one flip, either order of turn and flip stores the opposite turn.
|
||||
mirrored (not= (boolean (:flip-x shape)) (boolean (:flip-y shape)))
|
||||
layout-child (and (ctl/any-layout-immediate-child? objects ownership)
|
||||
(not (ctl/position-absolute? ownership)))
|
||||
auto-width (and (= :text (:type ownership)) (= :auto-width (:grow-type ownership)))
|
||||
auto-height (and (= :text (:type ownership)) (#{:auto-width :auto-height} (:grow-type ownership)))
|
||||
derived (derived-attributes objects ownership)
|
||||
width-owned (contains? derived :width)
|
||||
height-owned (contains? derived :height)
|
||||
;; Both flags and a half turn decompose the transform neither does.
|
||||
both-flipped (and (not= (boolean (:flip-x shape)) (boolean (:flip-x expected)))
|
||||
(not= (boolean (:flip-y shape)) (boolean (:flip-y expected)))
|
||||
(geom/decomposes? shape))]
|
||||
(cond-> #{}
|
||||
;; Parents may store equivalent decompositions, so a rotation that
|
||||
;; decomposes the shape's own transform is its expected turn too, as
|
||||
;; is any rotation of a shape at its expected corners.
|
||||
(not (or (same-turn? rotation exp-rotation)
|
||||
(and mirrored (same-turn? rotation (- exp-rotation)))
|
||||
(geom/decomposes? shape)
|
||||
(gsh/close-attrs? :points (:points shape) (:points expected) 0.01))) (conj :rotation)
|
||||
(and (not both-flipped) (not= (boolean (:flip-x shape)) (boolean (:flip-x expected)))) (conj :flip-x)
|
||||
(and (not both-flipped) (not= (boolean (:flip-y shape)) (boolean (:flip-y expected)))) (conj :flip-y)
|
||||
(and (not width-owned) (not (mth/close? (:width shape) (:width expected) 0.01))) (conj :width)
|
||||
(and (not height-owned) (not (mth/close? (:height shape) (:height expected) 0.01))) (conj :height)
|
||||
(and (not layout-child) auto-height
|
||||
(not (gsh/close-attrs? :points [(first (:points shape))]
|
||||
[(first (:points expected))] 0.01))) (conj :position)
|
||||
(and (not layout-child) (not auto-width) (not auto-height)
|
||||
(not (gsh/close-attrs? :points (:points shape) (:points expected) 0.01))) (conj :points)))))
|
||||
|
||||
(defn check-requested-geometry
|
||||
[objects actual expected]
|
||||
(when-let [attrs (seq (geometry-differences objects actual expected))]
|
||||
(fail :I9 {:phase :requested-geometry :attrs (set attrs)
|
||||
:shape (:name actual) :expected expected :actual actual})))
|
||||
|
||||
(defn- comparable-values
|
||||
[shape context group]
|
||||
(let [shape (if (= group :constraints-group)
|
||||
(cond-> (update shape :fixed-scroll boolean)
|
||||
(nil? (:constraints-h shape)) (assoc :constraints-h (gsh/default-constraints-h context))
|
||||
(nil? (:constraints-v shape)) (assoc :constraints-v (gsh/default-constraints-v context)))
|
||||
shape)]
|
||||
(shadow/values shape group)))
|
||||
|
||||
(defn- get-world-objects
|
||||
[situation]
|
||||
(into {} (mapcat cf/object-trees) (vals (cf/all-files situation))))
|
||||
|
||||
(defn check-requested-update-main
|
||||
"Keep authored intent after the shadow clears the source copy's groups.
|
||||
Only identities come from the result; expected values come from before."
|
||||
[before after model root-id]
|
||||
(let [source-objects (get-world-objects before)
|
||||
objects (get-world-objects after)
|
||||
root (get source-objects root-id)
|
||||
main-id (:shape-ref root)
|
||||
subtree (fn subtree [objects id]
|
||||
(cons id (mapcat #(subtree objects %) (:shapes (get objects id)))))
|
||||
destination (set (subtree objects main-id))
|
||||
mismatch (fn [id group expected actual]
|
||||
(fail :I9 {:phase :requested-update-main :shape-id id :group group
|
||||
:expected expected :actual actual}))]
|
||||
(doseq [id (subtree source-objects root-id)
|
||||
:let [source (get source-objects id)
|
||||
kept (get objects id)
|
||||
target (get objects (if (= id root-id) main-id (:shape-ref kept)))]
|
||||
group (keys (get model id))]
|
||||
(when-not (and kept target (contains? destination (:id target)))
|
||||
(mismatch id group :destination-main (:id target)))
|
||||
(cond
|
||||
(= group :geometry-group)
|
||||
;; The source copy stays in its own frame. Existing geometry ownership
|
||||
;; and tolerance apply; I4 then checks its placement against the main.
|
||||
(let [attrs (geometry-differences source-objects kept source source)]
|
||||
(when (or (seq attrs)
|
||||
(not= (or (:content-scale source) 1) (or (:content-scale kept) 1)))
|
||||
(mismatch id group (shadow/values source group) (shadow/values kept group))))
|
||||
|
||||
(= group :swap-group)
|
||||
(when-not (= (select-keys source [:component-id :component-file])
|
||||
(select-keys target [:component-id :component-file]))
|
||||
(mismatch id group (select-keys source [:component-id :component-file])
|
||||
(select-keys target [:component-id :component-file])))
|
||||
|
||||
:else
|
||||
(let [source-parent (get source-objects (:parent-id source))
|
||||
item-group (.startsWith (name group) "layout-item-")
|
||||
intrinsic (and (:layout source)
|
||||
(#{:layout-item-h-sizing :layout-item-v-sizing} group)
|
||||
(#{:fix :auto} (get source group)))
|
||||
push-item (or intrinsic
|
||||
(and (not= id root-id) (:layout source-parent)))
|
||||
target (if (and item-group (not push-item)) kept target)
|
||||
expected (if (= group :layout-grid-cells)
|
||||
(get (grid/remap-groups {group (shadow/values source group)}
|
||||
(grid/get-child-map objects source target)) group)
|
||||
(comparable-values source target group))
|
||||
actual (comparable-values target target group)]
|
||||
(when-not (if (contains? shadow/text-groups group)
|
||||
(shadow/same-value? target group expected)
|
||||
(= expected actual))
|
||||
(mismatch id group expected actual)))))))
|
||||
|
||||
(defn- grid-cells
|
||||
[shape]
|
||||
(let [indices (zipmap (:shapes shape) (range))]
|
||||
(->> (vals (:layout-grid-cells shape))
|
||||
(map #(-> % (dissoc :id) (update :shapes (fn [ids] (mapv indices ids)))))
|
||||
(sort-by (juxt :row :column))
|
||||
vec)))
|
||||
|
||||
(defn- expected-grid-cells
|
||||
"Source cells with the copy's hidden/absolute children removed. A gap,
|
||||
manual cell or span ends the automatic prefix of the copy's own flow;
|
||||
visible children without a source cell take free cells in that order.
|
||||
No production assignment helper supplies these expectations."
|
||||
[objects shape main]
|
||||
(let [flow-order (if (= :column (:layout-grid-dir shape))
|
||||
(juxt :column :row)
|
||||
(juxt :row :column))
|
||||
participating (into #{}
|
||||
(keep-indexed (fn [index id]
|
||||
(let [child (get objects id)]
|
||||
(when-not (or (:hidden child) (:layout-item-absolute child))
|
||||
index))))
|
||||
(:shapes shape))
|
||||
end-auto-prefix
|
||||
(fn [cells]
|
||||
(second
|
||||
(reduce (fn [[ended result] cell]
|
||||
(let [span (or (not= 1 (:row-span cell)) (not= 1 (:column-span cell)))
|
||||
occupied (seq (:shapes cell))
|
||||
manual (or (= :manual (:position cell)) span
|
||||
(and ended occupied (= :auto (:position cell))))]
|
||||
[(or ended manual (not occupied))
|
||||
(conj result (cond-> cell
|
||||
(and manual (= :auto (:position cell)))
|
||||
(assoc :position :manual)))]))
|
||||
[false []] cells)))
|
||||
cells (->> (grid-cells main)
|
||||
(sort-by flow-order)
|
||||
(mapv #(update % :shapes (fn [ids] (filterv participating ids))))
|
||||
end-auto-prefix)
|
||||
assigned (into #{} (mapcat :shapes) cells)
|
||||
missing (remove assigned (sort participating))
|
||||
[cells _] (reduce (fn [[result pending] cell]
|
||||
(if (and (seq pending) (empty? (:shapes cell)))
|
||||
[(conj result (assoc cell :position :auto :shapes [(first pending)]))
|
||||
(rest pending)]
|
||||
[(conj result cell) pending]))
|
||||
[[] missing] cells)]
|
||||
(->> cells end-auto-prefix (sort-by (juxt :row :column)) vec)))
|
||||
|
||||
(defn- loaded-shape?
|
||||
[libraries id]
|
||||
(some (fn [file] (some #(contains? (:objects %) id) (vals (get-in file [:data :pages-index]))))
|
||||
(vals libraries)))
|
||||
|
||||
(defn- check-structure
|
||||
"A child with no ref stands for a main child the loaded library has
|
||||
removed, or had removed when a detach left it (`unlinked`): detaching
|
||||
around a stale copy leaves it as a plain shape, which accepting the
|
||||
library replaces. A grid copy with its own cells holds the main's
|
||||
children in the flow of those cells."
|
||||
[objects shape main authored loaded unlinked]
|
||||
(let [refs (mapv (fn [id main-id]
|
||||
(let [ref (get-in objects [id :shape-ref])]
|
||||
(if (and (nil? ref) (some? main-id)
|
||||
(or (not (loaded-shape? loaded main-id)) (contains? unlinked id)))
|
||||
main-id
|
||||
ref)))
|
||||
(:shapes shape)
|
||||
(concat (:shapes main) (repeat nil)))
|
||||
own-flow? (and (= :grid (:layout shape)) (contains? authored :layout-grid-cells))]
|
||||
(when-not (if own-flow?
|
||||
(and (= (frequencies (:shapes main)) (frequencies refs))
|
||||
(= (vec (:shapes shape)) (grid/flow-shapes shape)))
|
||||
(= (vec (:shapes main)) refs))
|
||||
(fail :I4 {:shape (:name shape) :group :structure
|
||||
:expected (:shapes main) :actual refs}))
|
||||
;; Authored cells have already been checked against independent intent
|
||||
;; by I9. Child structure still follows the main in every case.
|
||||
(when (and (= :grid (:layout main)) (not (contains? authored :layout-grid-cells)))
|
||||
(let [expected (expected-grid-cells objects shape main)
|
||||
actual (grid-cells shape)]
|
||||
(when-not (= expected actual)
|
||||
(fail :I4 {:shape (:name shape) :group :layout-grid-cells
|
||||
:expected expected :actual actual}))))))
|
||||
|
||||
(defn- inherited-layout-item?
|
||||
"A root's placement in an unrelated flex/grid belongs to that placement.
|
||||
Layout child attrs inherit only through corresponding layout parents;
|
||||
intrinsic fix/auto sizing also belongs to the component itself."
|
||||
[file container libraries shape group]
|
||||
(let [source (ctf/find-ref-shape file container libraries shape :include-deleted? true :with-context? true)
|
||||
source-objects (get-in (meta source) [:container :objects])
|
||||
parent (get (:objects container) (:parent-id shape))
|
||||
source-parent (get source-objects (:parent-id source))]
|
||||
(or (ctk/swapped? shape)
|
||||
(and (#{:layout-item-h-sizing :layout-item-v-sizing} group)
|
||||
(#{:auto :fix} (get source group)))
|
||||
(and (:layout source-parent) (:layout parent)
|
||||
(= (:id source-parent) (:shape-ref parent))))))
|
||||
|
||||
(defn- mixed-typography-ownership?
|
||||
"A reference cannot describe styles split between the copy and main."
|
||||
[touched]
|
||||
(let [copy-reference? (contains? touched :text-content-typography)]
|
||||
(boolean
|
||||
(some #(not= copy-reference? (contains? touched %))
|
||||
[:text-content-family :text-content-weight :text-content-size
|
||||
:text-content-line-height :text-content-spacing :text-content-case]))))
|
||||
|
||||
(defn- check-file
|
||||
"I1–I4 and I9. Before settlement only authored groups/values are checked;
|
||||
pending main changes may legitimately leave copies stale."
|
||||
([situation model] (check-file situation model true))
|
||||
([situation model settled]
|
||||
(let [file (tm/file situation)
|
||||
libraries (cf/libraries situation)
|
||||
;; the shape loop rebinds libraries to each copy's reference inputs
|
||||
loaded libraries]
|
||||
(when settled (thf/validate-file! file libraries))
|
||||
(doseq [page (vals (get-in file [:data :pages-index]))
|
||||
:let [container (ctn/make-container page :page)]
|
||||
shape (vals (:objects page))
|
||||
:let [libraries (cf/reference-libraries situation shape)
|
||||
expected (if (:shape-ref shape) (get model (:id shape) {}) {})
|
||||
touched (set (:touched shape))]]
|
||||
(when-not (= (set (keys expected)) touched)
|
||||
(fail (if (some #(not (contains? expected %)) touched) :I2 :I3)
|
||||
{:shape (:name shape) :expected (set (keys expected)) :actual touched}))
|
||||
(doseq [[group value] expected]
|
||||
(when-not (and (shadow/same-value? shape group value (:objects page))
|
||||
(or (not= group :layout-grid-cells)
|
||||
(grid/matches-context? shape (:layout-grid-cells value))))
|
||||
(fail :I9 {:shape (:name shape) :group group
|
||||
:expected value :actual (shadow/values shape group)})))
|
||||
(when (and settled (:shape-ref shape))
|
||||
(when-let [main (ctf/find-content-ref-shape file container libraries shape :include-deleted? true)]
|
||||
(check-structure (:objects page) shape main expected loaded (n/unlinked-children situation))
|
||||
(doseq [group (keys shadow/attributes)
|
||||
:when (and (not= group :geometry-group) (not (contains? touched group)))
|
||||
:when (not (and (= group :name-group) (= :text (:type shape))
|
||||
(= (:name main) (txt/generate-shape-name (txt/content->text (:content main))))))
|
||||
:when (or (not (.startsWith (name group) "layout-item-"))
|
||||
(inherited-layout-item? file container libraries shape group))
|
||||
;; A copy root's name follows component renaming too.
|
||||
:let [source (if (or (= group :constraints-group)
|
||||
(.startsWith (name group) "layout-item-"))
|
||||
(or (ctf/find-ref-shape file container libraries shape :include-deleted? true) main)
|
||||
main)
|
||||
expected (comparable-values source shape group)
|
||||
actual (comparable-values shape shape group)]]
|
||||
(when-not (= expected actual)
|
||||
(fail :I4 {:shape (:name shape) :group group
|
||||
:expected expected :actual actual})))
|
||||
(when (= :text (:type shape))
|
||||
(let [drop-reference? (mixed-typography-ownership? touched)]
|
||||
(when (and drop-reference?
|
||||
(some #(or (:typography-ref-id %) (:typography-ref-file %))
|
||||
(tree-seq map? :children (:content shape))))
|
||||
(fail :I4 {:shape (:name shape) :group :text-content-typography
|
||||
:unit :typography :expected nil}))
|
||||
(doseq [unit (thtx/override-units (:content main) (:content shape))
|
||||
:when (not (and drop-reference? (= :typography unit)))
|
||||
:let [group (some (fn [[group candidate]] (when (= unit candidate) group)) shadow/text-groups)]
|
||||
:when (not (contains? touched group))]
|
||||
(fail :I4 {:shape (:name shape) :group group :unit unit})))))
|
||||
(when-not (contains? touched :geometry-group)
|
||||
(let [expected (expected-geometry file container libraries shape
|
||||
#(cf/reference-libraries situation %))
|
||||
attrs (cond-> (geometry-differences (:objects page) shape expected)
|
||||
(untracked-position? (:objects page) shape) (disj :points :position))]
|
||||
(when (seq attrs)
|
||||
(fail :I4 {:shape (:name shape) :group :geometry-group :attrs attrs
|
||||
:expected (select-keys expected [:width :height :points])
|
||||
:actual (select-keys shape [:width :height :points])}))))))
|
||||
nil)))
|
||||
|
||||
(defn check
|
||||
"Check both the working file and every library in the generated world."
|
||||
([situation model] (check situation model true))
|
||||
([situation model settled]
|
||||
(let [files (cf/all-files situation)]
|
||||
(doseq [[id file] files]
|
||||
(check-file (-> situation (tm/with-file file) (tm/with-aux-files (dissoc files id)))
|
||||
model settled)))
|
||||
nil))
|
||||
765
common/src/app/common/test_helpers/composable/shadow.cljc
Normal file
765
common/src/app/common/test_helpers/composable/shadow.cljc
Normal file
@ -0,0 +1,765 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns app.common.test-helpers.composable.shadow
|
||||
"Authored overrides, kept independently of production touched writes.
|
||||
Each shape id maps groups to the attribute values the user authored."
|
||||
(:require
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.math :as mth]
|
||||
[app.common.test-helpers.composable.comp.nodes :as n]
|
||||
[app.common.test-helpers.composable.geometry :as geom]
|
||||
[app.common.test-helpers.composable.grid :as grid]
|
||||
[app.common.test-helpers.texts :as thtx]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[app.common.types.shape.layout :as ctl]))
|
||||
|
||||
;; This table is a specification, deliberately not ctk/sync-attrs.
|
||||
(def groups
|
||||
{:fills :fill-group :opacity :layer-effects-group :name :name-group
|
||||
:strokes :stroke-group :hidden :visibility-group :blocked :modifiable-group
|
||||
:r1 :radius-group :r2 :radius-group :r3 :radius-group :r4 :radius-group
|
||||
:shadow :shadow-group :blur :blur-group :background-blur :blur-group
|
||||
:blend-mode :layer-effects-group :hide-fill-on-export :fill-group
|
||||
:show-content :show-content :fixed-scroll :constraints-group
|
||||
:constraints-h :constraints-group :constraints-v :constraints-group
|
||||
:layout-item-margin :layout-item-margin :layout-gap :layout-gap
|
||||
:layout-padding :layout-padding :layout-align-items :layout-align-items
|
||||
:layout-flex-dir :layout-flex-dir :layout-wrap-type :layout-wrap-type
|
||||
:layout-justify-content :layout-justify-content :layout-align-content :layout-align-content
|
||||
:layout-gap-type :layout-gap :layout-padding-type :layout-padding
|
||||
:layout-justify-items :layout-justify-items
|
||||
:layout-item-margin-type :layout-item-margin
|
||||
:layout-item-align-self :layout-item-align-self
|
||||
:layout-item-h-sizing :layout-item-h-sizing :layout-item-v-sizing :layout-item-v-sizing
|
||||
:layout-item-min-w :layout-item-min-w :layout-item-max-w :layout-item-max-w
|
||||
:layout-item-min-h :layout-item-min-h :layout-item-max-h :layout-item-max-h
|
||||
:layout-item-absolute :layout-item-absolute :layout-item-z-index :layout-item-z-index})
|
||||
|
||||
(defn attribute-applicable?
|
||||
"The clipping and background-export controls belong to frames."
|
||||
[shape attr]
|
||||
(case attr
|
||||
(:show-content :hide-fill-on-export) (= :frame (:type shape))
|
||||
true))
|
||||
|
||||
(def attributes
|
||||
{:fill-group [:fills :hide-fill-on-export]
|
||||
:layer-effects-group [:opacity :blend-mode]
|
||||
:name-group [:name]
|
||||
:stroke-group [:strokes]
|
||||
:radius-group [:r1 :r2 :r3 :r4]
|
||||
:visibility-group [:hidden]
|
||||
:modifiable-group [:blocked]
|
||||
:shadow-group [:shadow]
|
||||
:blur-group [:blur :background-blur]
|
||||
:mask-group [:masked-group]
|
||||
:exports-group [:exports]
|
||||
:grids-group [:grids]
|
||||
:show-content [:show-content]
|
||||
:content-group [:bool-type :bool-content]
|
||||
:geometry-group [:width :height :rotation :flip-x :flip-y :content-scale]
|
||||
:text-font-group [:grow-type :font-family :font-size :font-style :font-weight]
|
||||
:text-display-group [:letter-spacing :line-height :text-align]
|
||||
:constraints-group [:constraints-h :constraints-v :fixed-scroll]
|
||||
:layout-container [:layout]
|
||||
:layout-grid-dir [:layout-grid-dir]
|
||||
:layout-grid-rows [:layout-grid-rows]
|
||||
:layout-grid-columns [:layout-grid-columns]
|
||||
:layout-align-content [:layout-align-content]
|
||||
:layout-justify-items [:layout-justify-items]
|
||||
:layout-wrap-type [:layout-wrap-type]
|
||||
:layout-gap [:layout-gap :layout-gap-type]
|
||||
:layout-padding [:layout-padding :layout-padding-type]
|
||||
:layout-flex-dir [:layout-flex-dir]
|
||||
:layout-align-items [:layout-align-items]
|
||||
:layout-justify-content [:layout-justify-content]
|
||||
:layout-item-margin [:layout-item-margin :layout-item-margin-type]
|
||||
:layout-item-max-h [:layout-item-max-h]
|
||||
:layout-item-min-h [:layout-item-min-h]
|
||||
:layout-item-max-w [:layout-item-max-w]
|
||||
:layout-item-min-w [:layout-item-min-w]
|
||||
:layout-item-h-sizing [:layout-item-h-sizing]
|
||||
:layout-item-v-sizing [:layout-item-v-sizing]
|
||||
:layout-item-absolute [:layout-item-absolute]
|
||||
:layout-item-z-index [:layout-item-z-index]
|
||||
:layout-item-align-self [:layout-item-align-self]})
|
||||
|
||||
;; These fields need geometry, content or cell-reference comparisons instead
|
||||
;; of raw equality. Keep the inventory explicit so new production attrs cannot
|
||||
;; silently fall outside the oracle's specification.
|
||||
(def specialized-attributes
|
||||
{:geometry-group [:type :selrect :points :locked :proportion :proportion-lock
|
||||
:x :y :transform :transform-inverse :content]
|
||||
:content-group [:content :position-data]
|
||||
:layout-grid-cells [:layout-grid-cells]})
|
||||
|
||||
(def text-groups
|
||||
{:text-content-text :letters :text-content-family :family :text-content-weight :weight
|
||||
:text-content-size :size :text-content-line-height :line-height :text-content-spacing :spacing
|
||||
:text-content-decoration :decoration :text-content-case :case :text-content-fills :fills
|
||||
:text-content-typography :typography :text-content-align :align :text-content-direction :direction
|
||||
:text-content-valign :valign})
|
||||
|
||||
(defn values
|
||||
[shape group]
|
||||
(cond
|
||||
(= group :layout-grid-cells) {:layout-grid-cells (grid/get-cells shape)}
|
||||
(contains? text-groups group)
|
||||
{:content (:content shape)}
|
||||
:else (into {} (map #(vector % (get shape %))) (get attributes group))))
|
||||
|
||||
(defn author-geometry
|
||||
"The geometry `shape` authors, with the `parent` it is placed in, which
|
||||
later resizes of that parent move and size it through. With `sized?`,
|
||||
only its size is authored: its place in a plain parent is not an
|
||||
override."
|
||||
([shape parent] (author-geometry shape parent false))
|
||||
([shape parent sized?]
|
||||
(cond-> (values shape :geometry-group)
|
||||
parent (with-meta {::position {:shape shape :parent parent :sized? sized?}}))))
|
||||
|
||||
(defn- authored-placement
|
||||
"Where the shape `expected` records it authored sits in `parent`, resized
|
||||
through the constraints of `current` when given (they apply to the
|
||||
resizes after them), else those it had."
|
||||
([expected parent] (authored-placement expected parent nil))
|
||||
([expected parent current]
|
||||
(when-let [{authored :shape origin :parent} (::position (meta expected))]
|
||||
(let [authored (cond-> authored
|
||||
current (merge (select-keys current [:constraints-h :constraints-v])))]
|
||||
;; Placement of this child does not depend on its siblings' identities.
|
||||
;; Keep the expected tree self-contained across frontend ID allocation.
|
||||
(geom/child-placement authored origin parent
|
||||
{(:id authored) (assoc authored :parent-id (:id origin) :shapes [])
|
||||
(:id origin) (assoc origin :shapes [(:id authored)])})))))
|
||||
|
||||
(defn- layout-sized
|
||||
"The sizes a layout gives `shape`: its fill or auto axes, and both once it
|
||||
is turned, since the layout resizes it along its parent's axes."
|
||||
[shape objects]
|
||||
(let [child? (and (ctl/any-layout-immediate-child? objects shape)
|
||||
(not (ctl/position-absolute? shape)))
|
||||
owned? #(and (or child? (ctl/any-layout? shape)) (#{:fill :auto} %))
|
||||
sized (cond-> #{}
|
||||
(owned? (:layout-item-h-sizing shape)) (conj :width)
|
||||
(owned? (:layout-item-v-sizing shape)) (conj :height))]
|
||||
(if (and child? (seq sized) (not (mth/close? (mod (or (:rotation shape) 0) 360) 0)))
|
||||
#{:width :height}
|
||||
sized)))
|
||||
|
||||
(defn same-value?
|
||||
([shape group expected] (same-value? shape group expected nil))
|
||||
([shape group expected objects]
|
||||
(if (and (= :text (:type shape)) (= :content-group group))
|
||||
;; Text values are checked per style/letter unit. The parent group is
|
||||
;; only a marker; boolean content uses the ordinary attribute table.
|
||||
true
|
||||
(if-let [unit (get text-groups group)]
|
||||
(not (contains? (thtx/override-units (:content expected) (:content shape)) unit))
|
||||
(if (= group :geometry-group)
|
||||
(let [sized (if objects (layout-sized shape objects) #{})
|
||||
placed (when (and objects (not (:sized? (::position (meta expected)))))
|
||||
(authored-placement expected (get objects (:parent-id shape)) shape))
|
||||
;; an unskewed transform carries the turn and the mirror: an
|
||||
;; expected rotation and flips match when they decompose it,
|
||||
;; whichever rotation and flips the shape stores for it
|
||||
oriented (when (and (not placed) (:transform shape) (geom/rigid? shape)
|
||||
(number? (:rotation expected))
|
||||
(contains? expected :flip-x) (contains? expected :flip-y))
|
||||
(geom/decomposes? (merge shape (select-keys expected [:rotation :flip-x :flip-y]))))
|
||||
;; flipping both axes is a half turn, so a shape storing both
|
||||
;; flips the other way stores the same transform turned by 180
|
||||
expected (if (and (number? (:rotation expected))
|
||||
(contains? expected :flip-x) (contains? expected :flip-y)
|
||||
(not= (boolean (:flip-x expected)) (boolean (:flip-x shape)))
|
||||
(not= (boolean (:flip-y expected)) (boolean (:flip-y shape))))
|
||||
(-> expected
|
||||
(update :flip-x not)
|
||||
(update :flip-y not)
|
||||
(update :rotation + 180))
|
||||
expected)]
|
||||
(and (if placed
|
||||
(gsh/close-attrs? :points (:points shape) (:points placed) 0.01)
|
||||
true)
|
||||
(if (some? oriented) oriented true)
|
||||
(every? (fn [[key value]]
|
||||
(let [actual (get shape key)]
|
||||
(cond
|
||||
(contains? sized key) true
|
||||
(and (some? oriented) (#{:rotation :flip-x :flip-y} key)) true
|
||||
;; ordered corners fix the transform, whichever
|
||||
;; rotation the shape stores for it
|
||||
(and (= :rotation key) placed) true
|
||||
;; a recorded place sizes it through its constraints as its parent resizes
|
||||
(and (#{:width :height} key) placed (number? actual))
|
||||
(mth/close? (get placed key) actual 0.01)
|
||||
(#{:flip-x :flip-y} key) (= (boolean value) (boolean actual))
|
||||
;; under one flip, either order of turn and flip stores the opposite turn
|
||||
(and (= :rotation key) (number? value) (number? actual)
|
||||
(not= (boolean (:flip-x shape)) (boolean (:flip-y shape))))
|
||||
(or (mth/close? (mod value 360) (mod actual 360) 1e-10)
|
||||
(mth/close? (mod (- value) 360) (mod actual 360) 1e-10))
|
||||
;; Sizes are pixels, like the oracle's other geometry checks.
|
||||
(and (#{:width :height} key) (number? value) (number? actual)) (mth/close? value actual 0.01)
|
||||
(and (number? value) (number? actual)) (mth/close? value actual 1e-10)
|
||||
:else (= value actual)))) expected)))
|
||||
(= expected (values shape group)))))))
|
||||
|
||||
(defn edit-text
|
||||
([model before content] (edit-text model before content false))
|
||||
([model before content typography]
|
||||
(if (:shape-ref before)
|
||||
(let [units (cond-> (thtx/override-units (:content before) content)
|
||||
typography (into #{:family :weight :size :line-height :spacing :case :typography}))]
|
||||
(reduce (fn [model [group unit]]
|
||||
(cond-> model
|
||||
(contains? units unit)
|
||||
(assoc-in [(:id before) group] {:content content})))
|
||||
(cond-> model (seq units) (assoc-in [(:id before) :content-group] {}))
|
||||
text-groups))
|
||||
model)))
|
||||
|
||||
(defn duplicate
|
||||
[model before source-id after copy-id]
|
||||
(letfn [(copy-groups [result source-id copy-id]
|
||||
(let [groups (grid/remap-groups (get model source-id)
|
||||
(zipmap (:shapes (get before source-id)) (:shapes (get after copy-id))))
|
||||
result (cond-> result (seq groups) (assoc copy-id groups))]
|
||||
(reduce (fn [result [source child]] (copy-groups result source child)) result
|
||||
(map vector (:shapes (get before source-id)) (:shapes (get after copy-id))))))]
|
||||
(copy-groups model source-id copy-id)))
|
||||
|
||||
(defn edit
|
||||
[model before property value]
|
||||
(let [after (n/set-property before property value)
|
||||
group (get groups property)]
|
||||
(if (and (:shape-ref before) (not= (get before property) (get after property)))
|
||||
(assoc-in model [(:id before) group] (values after group))
|
||||
model)))
|
||||
|
||||
(defn clear-subtree
|
||||
[model objects root-id]
|
||||
(letfn [(clear [model id]
|
||||
(reduce clear (dissoc model id) (:shapes (get objects id))))]
|
||||
(clear model root-id)))
|
||||
|
||||
(defn- in-orientation
|
||||
"`values` turned and flipped from the frame of `source` to that of
|
||||
`target`; `sign` (`geom/turn-sign`) tells which way the rotation stores it."
|
||||
([values source target] (in-orientation values source target 1))
|
||||
([values source target sign]
|
||||
(let [flipped (reduce (fn [values key]
|
||||
(cond-> values
|
||||
(not= (boolean (get source key)) (boolean (get target key)))
|
||||
(update key not)))
|
||||
values
|
||||
[:flip-x :flip-y])]
|
||||
(assoc flipped :rotation (geom/reoriented-rotation values sign source target flipped)))))
|
||||
|
||||
(defn detach
|
||||
"A detached outer head loses its groups. Surviving nested copies inherit
|
||||
the authored groups of the near-main links the detach skips."
|
||||
[model before after root-id]
|
||||
(letfn [(inherit [shape]
|
||||
(let [original shape
|
||||
new-ref (:shape-ref (get after (:id shape)))
|
||||
swapped? (contains? (get model (:id shape)) :swap-group)]
|
||||
(loop [shape shape groups (get model (:id shape)) seen #{}]
|
||||
(let [ref (:shape-ref shape)
|
||||
source (get before ref)
|
||||
inherited (grid/remap-groups (get model ref) (grid/get-child-map before source original))
|
||||
inherited (cond-> inherited
|
||||
(:geometry-group inherited)
|
||||
(update :geometry-group in-orientation source original))]
|
||||
(if (or (nil? ref) (contains? seen ref) (= ref new-ref))
|
||||
;; the detach keeps the text the copy shows, which may
|
||||
;; have dropped a typography of a skipped link
|
||||
(reduce (fn [groups group]
|
||||
(cond-> groups
|
||||
(and (contains? text-groups group)
|
||||
(not (contains? (get model (:id original)) group)))
|
||||
(assoc group {:content (:content (get after (:id original)))})))
|
||||
groups (keys groups))
|
||||
(recur source
|
||||
(merge (if swapped?
|
||||
(cond-> (select-keys inherited
|
||||
(filter #(or (#{:geometry-group :constraints-group} %)
|
||||
(.startsWith (name %) "layout-item-"))
|
||||
(keys inherited)))
|
||||
(:geometry-group inherited)
|
||||
(update :geometry-group own-size original))
|
||||
(cond-> inherited
|
||||
(and (:geometry-group inherited) (constraint-sized? original))
|
||||
(update :geometry-group own-size original))) groups)
|
||||
(conj seen ref)))))))
|
||||
;; a copy shape that keeps its size through a constraint it authors
|
||||
;; shows that size, not its link's
|
||||
(constraint-sized? [shape]
|
||||
(let [groups (get model (:id shape))]
|
||||
(and (contains? groups :constraints-group)
|
||||
(not (contains? groups :geometry-group))
|
||||
(or (#{:scale :leftright} (:constraints-h shape))
|
||||
(#{:scale :topbottom} (:constraints-v shape))))))
|
||||
;; a swapped head takes a link's placement with the size of its own
|
||||
;; content, about the placement's first corner
|
||||
(own-size [value head]
|
||||
(let [{authored :shape} (::position (meta value))
|
||||
sized (when authored
|
||||
(gsh/transform-shape authored (ctm/change-size authored (:width head) (:height head))))]
|
||||
(cond-> (assoc value :width (:width head) :height (:height head))
|
||||
sized (vary-meta assoc-in [::position :shape] sized))))
|
||||
;; a nested copy that its new main would place elsewhere keeps its
|
||||
;; place as its own geometry, and one under a plain parent keeps an
|
||||
;; orientation or size its main lacks; a swapped head takes its new place
|
||||
(kept-in-place [groups shape]
|
||||
(let [parent (get after (:parent-id shape))
|
||||
main (get after (:shape-ref shape))
|
||||
main-parent (get after (:parent-id main))
|
||||
objects (cond-> after
|
||||
(and main (contains? groups :constraints-group))
|
||||
(update (:id main) merge
|
||||
(into {} (filter val) (select-keys shape [:constraints-h :constraints-v]))))]
|
||||
(cond
|
||||
(or (contains? groups :geometry-group) (contains? groups :swap-group) (nil? main))
|
||||
groups
|
||||
|
||||
(nil? (:shape-ref parent))
|
||||
(kept-orientation groups shape)
|
||||
|
||||
(or (nil? main-parent)
|
||||
(gsh/close-attrs? :points (:points shape)
|
||||
(:points (geom/child-placement main main-parent parent objects)) 0.01))
|
||||
groups
|
||||
|
||||
;; the kept place sits in the copy parent, whose later resizes
|
||||
;; move and size it through its constraints unless a layout places it
|
||||
:else
|
||||
(assoc groups :geometry-group
|
||||
(author-geometry shape (when-not (and (ctl/any-layout-immediate-child? after shape)
|
||||
(not (ctl/position-absolute? shape)))
|
||||
parent))))))
|
||||
;; under a plain parent a copy is placed freely, and only its
|
||||
;; orientation and size follow its main, turned like that parent
|
||||
(kept-orientation [groups shape]
|
||||
(let [main (get after (:shape-ref shape))
|
||||
parent (get after (:parent-id shape))
|
||||
;; a main at the root of its page has an unturned parent
|
||||
main-parent (get after (:parent-id main) {})
|
||||
expected (cond-> (values main :geometry-group)
|
||||
parent (in-orientation main-parent parent))]
|
||||
(cond-> groups
|
||||
(and main
|
||||
(nil? (:shape-ref parent))
|
||||
(not (contains? groups :geometry-group))
|
||||
(not (same-value? shape :geometry-group expected)))
|
||||
(assoc :geometry-group (author-geometry shape nil)))))
|
||||
(visit [result id]
|
||||
(let [shape (get after id)
|
||||
groups (when (:shape-ref shape)
|
||||
(cond
|
||||
(= (:shape-ref shape) (:shape-ref (get before id)))
|
||||
(get model id)
|
||||
(and (contains? (get model id) :swap-group)
|
||||
(= 1 (count (ctn/get-parent-copy-heads after shape)))
|
||||
(= (:component-id shape)
|
||||
(:component-id (get after (:shape-ref shape)))))
|
||||
;; The old position no longer supplies placement.
|
||||
;; Predict retained ownership from the before-state.
|
||||
(let [old (get before id)
|
||||
main (get before (:shape-ref shape))
|
||||
normalized (fn [source]
|
||||
(-> source
|
||||
(update :constraints-h #(or % (gsh/default-constraints-h old)))
|
||||
(update :constraints-v #(or % (gsh/default-constraints-v old)))
|
||||
(update :fixed-scroll boolean)))]
|
||||
(-> (reduce (fn [groups group]
|
||||
(if (= (values (normalized old) group)
|
||||
(values (normalized main) group))
|
||||
groups
|
||||
(assoc groups group (values old group))))
|
||||
(dissoc (get model id) :swap-group)
|
||||
(filter #(or (= :constraints-group %)
|
||||
(.startsWith (name %) "layout-item-"))
|
||||
(keys attributes)))
|
||||
(kept-orientation shape)))
|
||||
:else (kept-in-place (inherit (get before id)) shape)))
|
||||
result (cond-> (dissoc result id) (seq groups) (assoc id groups))]
|
||||
(reduce visit result (:shapes (get before id)))))]
|
||||
(visit model root-id)))
|
||||
|
||||
(defn update-main
|
||||
"Pushing overrides into a nested copy in a main makes them authored at
|
||||
that level. Ordinary main shapes do not have touched groups."
|
||||
[model before after root-id]
|
||||
(letfn [(content-overrides [shape reference]
|
||||
(when reference
|
||||
(let [content-groups (remove #(or (#{:geometry-group :constraints-group} %)
|
||||
(.startsWith (name %) "layout-item-"))
|
||||
(keys attributes))
|
||||
groups (into {}
|
||||
(keep (fn [group]
|
||||
(let [expected (values reference group)]
|
||||
(when-not (same-value? shape group expected)
|
||||
[group (values shape group)]))))
|
||||
content-groups)
|
||||
units (when (= :text (:type shape))
|
||||
(thtx/override-units (:content reference) (:content shape)))]
|
||||
(reduce (fn [groups [group unit]]
|
||||
(cond-> groups
|
||||
(contains? units unit)
|
||||
(assoc group {:content (:content shape)})))
|
||||
(cond-> groups (seq units) (assoc :content-group {}))
|
||||
text-groups))))
|
||||
(push [result id content?]
|
||||
(let [shape (get before id)
|
||||
updated (get after id)
|
||||
ref (get after (:shape-ref updated))
|
||||
groups (get model id)
|
||||
content-main (get before (:shape-ref ref))
|
||||
pushed-swap? (and content-main (contains? groups :swap-group)
|
||||
(= (:component-id ref) (:component-id content-main)))
|
||||
content? (or content? pushed-swap?)
|
||||
groups (merge (when (and content?
|
||||
(= (:component-id ref) (:component-id content-main)))
|
||||
(content-overrides shape content-main))
|
||||
groups)
|
||||
root (get before root-id)
|
||||
main-root (get before (:shape-ref root))
|
||||
root-parent (get before (:parent-id root))
|
||||
main-parent (get before (:parent-id main-root) {})
|
||||
;; the turn the copy root inherits places it and is not pushed
|
||||
geometry (cond-> (values shape :geometry-group)
|
||||
(and (:component-root root) (not (get-in model [root-id :geometry-group])))
|
||||
(in-orientation root main-root)
|
||||
|
||||
(and (not (:component-root root)) root-parent)
|
||||
(in-orientation root-parent main-parent))
|
||||
replaced (when (and (contains? groups :swap-group)
|
||||
(not= (:shape-ref shape) (:shape-ref updated)))
|
||||
(get before (:shape-ref shape)))
|
||||
;; a head pushed in place of a copy child takes the placement that child authored
|
||||
placement (when (:shape-ref (get before (:parent-id replaced)))
|
||||
(filter #(or (#{:geometry-group :constraints-group} %)
|
||||
(.startsWith (name %) "layout-item-"))
|
||||
(keys (get model (:id replaced)))))
|
||||
expected (when pushed-swap?
|
||||
(in-orientation (values content-main :geometry-group)
|
||||
(get before (:parent-id content-main))
|
||||
(get after (:parent-id ref))))
|
||||
groups (cond-> groups
|
||||
(and pushed-swap?
|
||||
(not (same-value? geometry :geometry-group
|
||||
(select-keys expected [:rotation :flip-x :flip-y]))))
|
||||
(assoc :geometry-group geometry)
|
||||
|
||||
(and pushed-swap?
|
||||
(not (same-value? shape :constraints-group (values content-main :constraints-group))))
|
||||
(assoc :constraints-group (values shape :constraints-group))
|
||||
|
||||
(seq placement)
|
||||
(merge (into {} (map (fn [group]
|
||||
[group (if (= :geometry-group group) geometry (values shape group))]))
|
||||
placement))
|
||||
|
||||
;; a main shape the push keeps turns with its main afterwards;
|
||||
;; its pushed geometry leaves out the turn its copy parent shows
|
||||
;; against its main parent (the root's, against its main)
|
||||
(and (:geometry-group groups) (not pushed-swap?) (contains? before (:id ref)))
|
||||
(update :geometry-group
|
||||
(fn [geometry]
|
||||
(if (= (:id shape) root-id)
|
||||
(in-orientation geometry root main-root)
|
||||
(in-orientation geometry (get before (:parent-id shape))
|
||||
(get before (:parent-id ref)))))))
|
||||
result (cond-> (dissoc result id)
|
||||
(and (contains? groups :swap-group)
|
||||
(not= (:component-id updated) (:component-id ref)))
|
||||
(assoc id {:swap-group {}})
|
||||
(and (:shape-ref ref) (seq groups))
|
||||
(update (:id ref) merge
|
||||
(cond-> (grid/remap-groups groups (grid/get-child-map after shape ref))
|
||||
(= (:component-id ref)
|
||||
(:component-id (get after (:shape-ref ref))))
|
||||
(dissoc :swap-group))))]
|
||||
(reduce #(push %1 %2 content?) result (:shapes shape))))]
|
||||
(push model root-id false)))
|
||||
|
||||
(defn layout-released
|
||||
"A layout writes the sizes it gives a shape into it, so a shape it stops
|
||||
sizing keeps them: each recorded geometry takes the dimensions its layout
|
||||
sized `before` and no longer sizes `after`."
|
||||
[model before after]
|
||||
(reduce-kv
|
||||
(fn [model id groups]
|
||||
(let [shape-before (get before id)
|
||||
shape-after (get after id)
|
||||
released (when (and shape-before shape-after (contains? groups :geometry-group))
|
||||
(remove (layout-sized shape-after after) (layout-sized shape-before before)))]
|
||||
(reduce #(assoc-in %1 [id :geometry-group %2] (get shape-after %2)) model released)))
|
||||
model
|
||||
model))
|
||||
|
||||
(defn parent-orientation
|
||||
"Authored child geometry moves with its parent's orientation. Compare the
|
||||
parent frames, without reading the child's resulting geometry."
|
||||
[model before after]
|
||||
(reduce-kv
|
||||
(fn [result id groups]
|
||||
(let [old (get before id)
|
||||
shape (get after id)
|
||||
parent (get before (:parent-id old))
|
||||
new-parent (get after (:parent-id shape))]
|
||||
(if (and (:geometry-group groups) old shape
|
||||
(= (:parent-id old) (:parent-id shape)) parent new-parent)
|
||||
(if-let [expected (authored-placement (:geometry-group groups) new-parent)]
|
||||
(assoc-in result [id :geometry-group]
|
||||
(with-meta (values expected :geometry-group) (meta (:geometry-group groups))))
|
||||
(update-in result [id :geometry-group] in-orientation parent new-parent (geom/turn-sign old)))
|
||||
result)))
|
||||
model model))
|
||||
|
||||
(defn settle
|
||||
"A detached position turns its copies into ordinary shapes. Their former
|
||||
component choice stops applying; other authored groups stay in place.
|
||||
Once synced (`synced?`, or the copy itself has no grid left), cells carry
|
||||
only between grids: a copy whose main has none, and that follows its
|
||||
main's layout, drops its own."
|
||||
([model objects] (settle model objects {} false))
|
||||
([model objects references] (settle model objects references true))
|
||||
([model objects references synced?]
|
||||
(reduce-kv
|
||||
(fn [result id groups]
|
||||
(let [shape (get objects id)
|
||||
position (get objects (:shape-ref shape))
|
||||
ordinary? (and shape position
|
||||
(nil? (:component-id shape))
|
||||
(nil? (:component-id position)))
|
||||
source (get references id)
|
||||
context (when source
|
||||
(grid/get-context (merge source (:layout-grid-rows groups)
|
||||
(:layout-grid-columns groups) (:layout-grid-dir groups))))
|
||||
;; a copy already synced to a gridless main has no grid left either
|
||||
gridless? (and source (not= :grid (:layout source))
|
||||
(or synced? (not= :grid (:layout shape)))
|
||||
(not (contains? groups :layout-container)))
|
||||
groups (cond-> groups
|
||||
ordinary? (dissoc :swap-group)
|
||||
gridless? (dissoc :layout-grid-cells)
|
||||
(and (:layout-grid-cells groups) (not gridless?))
|
||||
(update-in [:layout-grid-cells :layout-grid-cells] grid/settle-cells shape objects context source))]
|
||||
(if (seq groups) (assoc result id groups) (dissoc result id))))
|
||||
model model)))
|
||||
|
||||
(defn- subtree-shapes
|
||||
[objects id]
|
||||
(cons (get objects id) (mapcat #(subtree-shapes objects %) (:shapes (get objects id)))))
|
||||
|
||||
(defn- variant-paths
|
||||
[objects root-id]
|
||||
(letfn [(path [shape]
|
||||
(when-not (= root-id (:id shape))
|
||||
(conj (vec (path (get objects (:parent-id shape))))
|
||||
[(:name shape) (case (:type shape)
|
||||
(:frame :group) :container
|
||||
(:rect :circle :bool :path) :shape
|
||||
(:type shape))])))]
|
||||
(first
|
||||
(reduce (fn [[result counts] shape]
|
||||
(let [p (path shape)
|
||||
ordinal (get counts p 0)]
|
||||
[(assoc result (:id shape) [p ordinal]) (update counts p (fnil inc 0))]))
|
||||
[{} {}] (reverse (subtree-shapes objects root-id))))))
|
||||
|
||||
(defn swap
|
||||
"Predict switch carry from authored groups and the two mains. Matching
|
||||
uses main names and ancestor kinds; copy renames never change a match."
|
||||
[model before after root-id old-main-id new-main-id keep?]
|
||||
(let [old-paths (variant-paths before old-main-id)
|
||||
new-paths (variant-paths after new-main-id)
|
||||
old-by-path (into {} (map (fn [[id path]] [path (get before id)])) old-paths)
|
||||
source (fn [objects paths main-id original]
|
||||
(let [mains (into {} (keep (fn [shape]
|
||||
(when (:main-instance shape)
|
||||
[[(:component-file shape) (:component-id shape)] shape])))
|
||||
(vals objects))]
|
||||
(or
|
||||
(loop [shape original groups {} seen #{}]
|
||||
(cond
|
||||
(contains? paths (:id shape)) [shape groups]
|
||||
(or (nil? shape) (contains? seen (:id shape))) nil
|
||||
:else (recur (if (contains? (get model (:id shape)) :swap-group)
|
||||
(get mains [(:component-file shape) (:component-id shape)])
|
||||
(get objects (:shape-ref shape)))
|
||||
(merge (get model (:id shape)) groups)
|
||||
(conj seen (:id shape)))))
|
||||
;; A swapped root refers to its position, while its content
|
||||
;; and authored overrides belong to its own component.
|
||||
(when (= root-id (:id original))
|
||||
[(get objects main-id) (get model root-id)]))))
|
||||
old-copies (into {} (keep (fn [shape]
|
||||
(when-let [[main groups] (source before old-paths old-main-id shape)]
|
||||
[(get old-paths (:id main)) [shape main groups]])))
|
||||
(subtree-shapes before root-id))
|
||||
;; the rotation a clean copy of the new main takes in the root's parent
|
||||
placed-rotation (let [main (get after new-main-id)]
|
||||
(mod (+ (or (:rotation main) 0)
|
||||
(- (or (:rotation (get after (:parent-id (get after root-id)))) 0)
|
||||
(or (:rotation (get after (:parent-id main))) 0)))
|
||||
360))
|
||||
;; the rotation a clean copy of the old main takes in the root's parent
|
||||
old-placed-rotation (let [main (get before old-main-id)]
|
||||
(mod (+ (or (:rotation main) 0)
|
||||
(- (or (:rotation (get before (:parent-id (get before root-id)))) 0)
|
||||
(or (:rotation (get before (:parent-id main))) 0)))
|
||||
360))
|
||||
;; the flips a clean copy of `main`, in `main-parent`, takes in `parent`
|
||||
placed-flips (fn [main main-parent parent]
|
||||
(into {} (map (fn [key]
|
||||
[key (when (odd? (count (filter key [main main-parent parent]))) true)]))
|
||||
[:flip-x :flip-y]))
|
||||
;; the turn and flips a head in a copy takes from its position, the main
|
||||
;; shape it refers to; nil for a head outside a copy
|
||||
position-orientation (let [root (get after root-id)
|
||||
parent (get after (:parent-id root))
|
||||
position (when (:shape-ref parent) (get after (:shape-ref root)))
|
||||
position-parent (get after (:parent-id position))]
|
||||
(when position
|
||||
(merge {:rotation (mod (+ (or (:rotation position) 0)
|
||||
(- (or (:rotation parent) 0)
|
||||
(or (:rotation position-parent) 0)))
|
||||
360)}
|
||||
(placed-flips position position-parent parent))))
|
||||
cleared (clear-subtree model before root-id)
|
||||
result
|
||||
(if-not keep?
|
||||
cleared
|
||||
(reduce
|
||||
(fn [result shape]
|
||||
(if (and (not= root-id (:id shape)) (contains? before (:id shape)))
|
||||
;; A switch keeps an authored swapped subtree with its ids.
|
||||
(cond-> result (seq (get model (:id shape)))
|
||||
(assoc (:id shape) (get model (:id shape))))
|
||||
(if-let [[main _] (source after new-paths new-main-id shape)]
|
||||
(let [path (get new-paths (:id main))
|
||||
[old old-main groups] (get old-copies path)
|
||||
old-main (or old-main (get old-by-path path))
|
||||
old-parent (get before (:parent-id old))
|
||||
new-parent (get after (:parent-id shape))
|
||||
;; the old copy shape as its constraints take it into the new parent
|
||||
old-resized (if (and old old-parent new-parent)
|
||||
(geom/follow-parent-size old old-parent new-parent)
|
||||
old)
|
||||
text-differences (when (= :text (:type main))
|
||||
(thtx/override-units (:content old-main) (:content main)))
|
||||
carried-text-units (into #{}
|
||||
(keep (fn [[group unit]]
|
||||
(when (and (contains? groups group)
|
||||
(not (contains? text-differences unit)))
|
||||
unit)))
|
||||
text-groups)
|
||||
mixed-typography? (some #(not= (contains? carried-text-units :typography)
|
||||
(contains? carried-text-units %))
|
||||
[:family :weight :size :line-height :spacing :case])]
|
||||
(reduce-kv
|
||||
(fn [result group _]
|
||||
(if-let [unit (get text-groups group)]
|
||||
(cond-> result
|
||||
(and (not (and (= unit :typography) mixed-typography?))
|
||||
(not (contains? text-differences unit))
|
||||
(not (same-value? main group {:content (:content old)})))
|
||||
(-> (assoc-in [(:id shape) group] {:content (:content old)})
|
||||
(assoc-in [(:id shape) :content-group] {})))
|
||||
(let [attrs (get attributes group)
|
||||
same? (fn [a b]
|
||||
(cond
|
||||
(not= group :geometry-group) (= a b)
|
||||
(and (number? a) (number? b)) (mth/close? a b)
|
||||
(or (boolean? a) (boolean? b)) (= (boolean a) (boolean b))
|
||||
:else (= a b)))
|
||||
root? (= root-id (:id shape))
|
||||
;; the new main as the new copy shows it: a child turns
|
||||
;; with the orientation its new parent shows
|
||||
placed (cond-> (values main group)
|
||||
(and root? (= :geometry-group group))
|
||||
(merge {:rotation placed-rotation}
|
||||
(placed-flips main (get after (:parent-id main)) new-parent))
|
||||
(and (not root?) (= :geometry-group group) new-parent)
|
||||
(in-orientation (get after (:parent-id main)) new-parent))
|
||||
old-placed (cond-> old-main
|
||||
(and root? (= :geometry-group group))
|
||||
(merge {:rotation old-placed-rotation}
|
||||
(placed-flips old-main (get before (:parent-id old-main)) old-parent)))
|
||||
old (if (= :geometry-group group) old-resized old)
|
||||
orientation #{:rotation :flip-x :flip-y}
|
||||
;; the head's turn and flips carry as one: only where the
|
||||
;; mains share all of them
|
||||
agrees? (fn [attr]
|
||||
(if (and root? (contains? orientation attr))
|
||||
(every? #(same? (get old-placed %) (get placed %)) orientation)
|
||||
(same? (get old-placed attr) (get placed attr))))
|
||||
carried (filter (fn [attr]
|
||||
(let [new-value (get placed attr)]
|
||||
(and (attribute-applicable? main attr)
|
||||
(agrees? attr)
|
||||
(not (same? (get old attr) new-value))))) attrs)]
|
||||
(cond-> result
|
||||
(seq carried)
|
||||
(assoc-in [(:id shape) group]
|
||||
(merge placed
|
||||
(when (and root? (= :geometry-group group)) position-orientation)
|
||||
(select-keys old carried)))))))
|
||||
result (cond->> (dissoc groups :swap-group)
|
||||
;; the head carries only its own layout item overrides
|
||||
(= root-id (:id shape))
|
||||
(into {} (remove #(.startsWith (name (key %)) "layout-item-"))))))
|
||||
result)))
|
||||
cleared (subtree-shapes after root-id)))
|
||||
root (get after root-id)
|
||||
old-root (get before root-id)
|
||||
parent (get after (:parent-id root))
|
||||
position (get after (:shape-ref root))
|
||||
main (get after new-main-id)
|
||||
main-parent (get after (:parent-id main))
|
||||
baseline (if (:shape-ref parent) position main)
|
||||
baseline-parent (if (:shape-ref parent)
|
||||
(get after (:parent-id position)) main-parent)
|
||||
rotation (mod (+ (or (:rotation baseline) 0)
|
||||
(- (or (:rotation parent) 0) (or (:rotation baseline-parent) 0))) 360)
|
||||
flip (fn [key]
|
||||
(odd? (count (filter identity [(get baseline key) (get parent key)
|
||||
(get baseline-parent key)]))))
|
||||
retained-orientation? (or (not (mth/close? (mod (or (:rotation old-root) 0) 360) rotation 0.01))
|
||||
(not= (boolean (:flip-x old-root)) (flip :flip-x))
|
||||
(not= (boolean (:flip-y old-root)) (flip :flip-y)))
|
||||
;; a switch keeps the old head's layout item values, and their overrides
|
||||
layout-items (when keep?
|
||||
(into {} (filter #(.startsWith (name (key %)) "layout-item-")) (get model root-id)))
|
||||
;; a swap in a copy keeps an authored place its position does not give,
|
||||
;; unless a layout places the head
|
||||
kept-place? (and (:shape-ref parent) position
|
||||
(not (and (ctl/any-layout-immediate-child? after root)
|
||||
(not (ctl/position-absolute? root))))
|
||||
(contains? (get model root-id) :geometry-group)
|
||||
(not (gpt/close? (first (:points root))
|
||||
(first (:points (geom/child-placement position (get after (:parent-id position))
|
||||
parent after))))))]
|
||||
(cond-> result
|
||||
retained-orientation?
|
||||
(assoc-in [root-id :geometry-group]
|
||||
(merge (or (get-in result [root-id :geometry-group]) (values main :geometry-group))
|
||||
(select-keys old-root [:rotation :flip-x :flip-y])))
|
||||
|
||||
kept-place?
|
||||
(assoc-in [root-id :geometry-group] (author-geometry root parent))
|
||||
|
||||
(seq layout-items)
|
||||
(update root-id merge layout-items)
|
||||
|
||||
(and (:shape-ref parent) (not= (:component-id root) (:component-id position)))
|
||||
(assoc-in [root-id :swap-group] {}))))
|
||||
185
common/src/app/common/test_helpers/composable/variants.cljc
Normal file
185
common/src/app/common/test_helpers/composable/variants.cljc
Normal file
@ -0,0 +1,185 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns app.common.test-helpers.composable.variants
|
||||
"Variant fixture diversity and an independent nearest-member prediction."
|
||||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.composable.comp.nodes :as n]
|
||||
[app.common.test-helpers.composable.core :as tm]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[app.common.test-helpers.texts :as thtx]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(defn members
|
||||
[color rich? differ?]
|
||||
(cond-> [["a" color] ["b" (if differ? "#ff0000" color)]]
|
||||
rich? (into [["c" "#00ff00"] ["d" color]])))
|
||||
|
||||
(defn diversify
|
||||
"Build four members before any copies exist: varied bounds, a missing,
|
||||
extra or renamed icon, shared/different text, and three properties."
|
||||
[situation set-name]
|
||||
(let [members (:members (n/variant-set situation set-name))
|
||||
properties [["Small" "Idle" "Light"] ["Large" "Idle" "Dark"]
|
||||
["Small" "Pressed" "Dark"] ["Large" "Pressed" "Light"]]]
|
||||
(tm/with-file situation
|
||||
(thf/validate-file!
|
||||
(reduce
|
||||
(fn [file [index {:keys [component-label root-label rect-label]}]]
|
||||
(let [root-id (thi/id root-label)
|
||||
page (thf/current-page file)
|
||||
size (nth [[100 100] [140 100] [120 140] [80 100]] index)
|
||||
changes (cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page)) [root-id]
|
||||
#(gsh/transform-shape % (apply ctm/change-size % size))
|
||||
(:objects page) {})
|
||||
props (mapv (fn [name value] {:name name :value value})
|
||||
["Size" "State" "Theme"] (nth properties index))
|
||||
file (-> (thf/apply-changes file changes :validate? false)
|
||||
(thc/update-component component-label {:variant-properties props})
|
||||
(ths/update-shape root-label :variant-name (str/join ", " (map :value props)))
|
||||
(ths/update-shape rect-label :name (if (= index 2) "Glyph" "Icon"))
|
||||
(ths/update-shape rect-label :constraints-h (nth [:left :leftright :scale :center] index)))
|
||||
file (if (= index 3)
|
||||
(let [page (thf/current-page file)]
|
||||
(thf/apply-changes file
|
||||
(second (cls/generate-delete-shapes (pcb/empty-changes nil (:id page))
|
||||
(:data file) page (:objects page) #{(thi/id rect-label)} {}))
|
||||
:validate? false))
|
||||
file)
|
||||
text-label (keyword (str (name root-label) "-caption"))
|
||||
text (if (= index 2) "Other text" "Same text")
|
||||
content (thtx/content [[[text {:size (if (= index 2) 22 14)}]]])]
|
||||
(cond-> (ths/add-sample-shape file text-label :type :text :name "Caption"
|
||||
:parent-label root-label :width 70 :height 25
|
||||
:grow-type :auto-height :content content)
|
||||
(= index 1)
|
||||
(ths/add-sample-shape (keyword (str (name root-label) "-badge"))
|
||||
:type :rect :name "Badge" :width 12 :height 12 :parent-label root-label))))
|
||||
(tm/file situation) (map-indexed vector members))))))
|
||||
|
||||
(defn nearest
|
||||
"Prefer matches in earlier unchanged properties, then container order.
|
||||
This predicts the contract without calling the production distance or
|
||||
target-selection functions."
|
||||
[library shape pos value]
|
||||
(let [data (:data library)
|
||||
origin (get-in data [:components (:component-id shape)])
|
||||
properties (:variant-properties origin)
|
||||
objects (get-in data [:pages-index (:main-instance-page origin) :objects])
|
||||
roots (get-in objects [(:variant-id origin) :shapes])
|
||||
members (keep #(get-in data [:components (get-in objects [% :component-id])]) roots)]
|
||||
(when (not= value (get-in properties [pos :value]))
|
||||
(first
|
||||
(sort-by (fn [candidate]
|
||||
(mapv (fn [index property]
|
||||
(if (or (= index pos) (= property (nth (:variant-properties candidate) index))) 0 1))
|
||||
(range) properties))
|
||||
(filter #(and (not (:deleted %)) (= value (get-in % [:variant-properties pos :value]))) members))))))
|
||||
|
||||
(defn set-components
|
||||
"The live components of the variant set `variant-id` of `file`, in the
|
||||
order of its container's children."
|
||||
[file variant-id]
|
||||
(let [data (:data file)
|
||||
objects (:objects (thf/current-page file))]
|
||||
(->> (get-in objects [variant-id :shapes])
|
||||
(keep #(get-in data [:components (get-in objects [% :component-id])]))
|
||||
(remove :deleted)
|
||||
(filter #(= variant-id (:variant-id %)))
|
||||
vec)))
|
||||
|
||||
(defn- reorder
|
||||
"`items` with the one at `from` moved to the gap before position `to`."
|
||||
[items from to]
|
||||
(let [item (nth items from)
|
||||
rest (into (subvec items 0 from) (subvec items (inc from)))
|
||||
at (if (> to from) (dec to) to)]
|
||||
(into (conj (subvec rest 0 at) item) (subvec rest at))))
|
||||
|
||||
(defn- remove-at
|
||||
[items pos]
|
||||
(into (subvec items 0 pos) (subvec items (inc pos))))
|
||||
|
||||
(defn property-edit
|
||||
"A property edit of the set of `components` chosen by the natural numbers
|
||||
`selector`, `choice` and `other`: `{:edit :params :expected}`, where
|
||||
`:expected` maps each component id to its properties after the edit. A
|
||||
name in `:expected` is a string, `{:base name}` for a requested name that
|
||||
may take a ` (n)` suffix to stay unique, or `:generated` for a
|
||||
`Property n` name. Nil when the set has no property the edit needs."
|
||||
[components selector choice other]
|
||||
(let [props (vec (:variant-properties (first components)))
|
||||
n (count props)
|
||||
edit (nth [:add :remove :rename :reorder :set-value] (mod selector 5))
|
||||
pos (when (pos? n) (mod choice n))
|
||||
by-component (fn [f] (into {} (map (juxt :id #(f (vec (:variant-properties %))))) components))]
|
||||
(case edit
|
||||
:add
|
||||
(let [name (nth [nil "Size" "Mode"] (mod choice 3))
|
||||
value (nth [nil "On"] (mod other 2))]
|
||||
{:edit :add
|
||||
:params (cond-> {} name (assoc :property-name name) value (assoc :property-value value))
|
||||
:expected (by-component #(conj % {:name (if name {:base name} :generated) :value (or value "")}))})
|
||||
|
||||
:remove
|
||||
(when (> n 1)
|
||||
{:edit :remove :params {:pos pos}
|
||||
:expected (by-component #(remove-at % pos))})
|
||||
|
||||
:rename
|
||||
(when pos
|
||||
(let [name (nth [(:name (nth props (mod (inc pos) n))) "Kind" "Size"] (mod other 3))]
|
||||
{:edit :rename :params {:pos pos :name name}
|
||||
:expected (by-component #(assoc-in % [pos :name] {:base name}))}))
|
||||
|
||||
:reorder
|
||||
(when (> n 1)
|
||||
(let [to (mod other (inc n))]
|
||||
{:edit :reorder :params {:from pos :to to}
|
||||
:expected (by-component #(reorder % pos to))}))
|
||||
|
||||
:set-value
|
||||
(when pos
|
||||
(let [component (nth components (mod other (count components)))
|
||||
others (remove #(= (:id %) (:id component)) components)
|
||||
value (nth [(get-in (vec (:variant-properties (first others))) [pos :value]) "On" ""]
|
||||
(mod (quot choice n) 3))
|
||||
value (or value "On")]
|
||||
{:edit :set-value :params {:member (:id component) :pos pos :value value}
|
||||
:expected (assoc (by-component identity)
|
||||
(:id component)
|
||||
(assoc-in (vec (:variant-properties component)) [pos :value] value))})))))
|
||||
|
||||
(defn- name-matches?
|
||||
[expected actual]
|
||||
(cond
|
||||
(string? expected) (= expected actual)
|
||||
(= :generated expected) (some? (re-matches #"Property \d+" actual))
|
||||
:else (let [requested (:base expected)
|
||||
base (str/replace requested #" \(\d+\)$" "")]
|
||||
(or (= requested actual)
|
||||
(and (str/starts-with? actual (str base " ("))
|
||||
(str/ends-with? actual ")")
|
||||
(some? (re-matches #"\d+" (subs actual (+ 2 (count base)) (dec (count actual))))))))))
|
||||
|
||||
(defn properties-match?
|
||||
"Whether the properties `actual` are the `expected` of `property-edit`,
|
||||
with distinct names."
|
||||
[expected actual]
|
||||
(and (= (count expected) (count actual))
|
||||
(every? true? (map (fn [e a]
|
||||
(and (= (:value e) (:value a))
|
||||
(name-matches? (:name e) (:name a))))
|
||||
expected actual))
|
||||
(or (empty? actual) (apply distinct? (map :name actual)))))
|
||||
@ -12,6 +12,8 @@
|
||||
are the same for the user:
|
||||
- `:modified-at` of the file and of each component, bumped by every
|
||||
change, undo and redo included;
|
||||
- a linked file's `:synced-at`, the server sync status rather than
|
||||
authored design data;
|
||||
- with `{:position-data? false}`, the shapes' `:position-data`, the text
|
||||
layout that WASM measurement regenerates.
|
||||
Shapes and the maps that hold them become plain maps, so a shape record
|
||||
@ -54,7 +56,7 @@
|
||||
([file opts]
|
||||
(let [opts (merge {:position-data? true} opts)]
|
||||
(-> file
|
||||
(dissoc :modified-at)
|
||||
(dissoc :modified-at :synced-at)
|
||||
(update :data
|
||||
(fn [data]
|
||||
(-> data
|
||||
|
||||
@ -327,15 +327,23 @@
|
||||
the design panel does before changing it."
|
||||
[runs k]
|
||||
(if (contains? typography-styles k)
|
||||
(map (fn [[letters style]] [letters (dissoc style :typography)]) runs)
|
||||
(map (fn [[letters style]] [letters (dissoc style :typography :typography-ref-file)]) runs)
|
||||
runs))
|
||||
|
||||
(defn restyle
|
||||
"Set the run style `k` to `v` on every run of `text`."
|
||||
"Set the run style `k` to `v` on every run of `text`.
|
||||
Named colors and explicit fills replace each other. Font edits replace
|
||||
stale raw identities while preserving the other font unit."
|
||||
[text k v]
|
||||
(update-paragraphs text
|
||||
(fn [[style runs]]
|
||||
[style (map (fn [[letters run-style]] [letters (assoc run-style k v)])
|
||||
[style (map (fn [[letters run-style]]
|
||||
[letters (cond-> (assoc run-style k v)
|
||||
(= k :color) (dissoc :fills)
|
||||
(= k :fills) (dissoc :color)
|
||||
(= k :family) (dissoc :font-family :font-id)
|
||||
(= k :weight) (dissoc :font-weight :font-variant-id)
|
||||
(= k :italic) (dissoc :font-style :font-variant-id))])
|
||||
(detach-typography runs k))])))
|
||||
|
||||
(defn restyle-paragraphs
|
||||
@ -399,9 +407,10 @@
|
||||
(def min-shared-stretch 3)
|
||||
|
||||
(def run-units
|
||||
"Style unit -> the run attributes it covers."
|
||||
"Style unit -> the run attributes that tell its styles apart. The variant
|
||||
id follows from the family, weight and style, so it tells none apart."
|
||||
{:family [:font-family :font-id]
|
||||
:weight [:font-weight :font-style :font-variant-id]
|
||||
:weight [:font-weight :font-style]
|
||||
:size [:font-size]
|
||||
:spacing [:letter-spacing]
|
||||
:decoration [:text-decoration]
|
||||
@ -466,7 +475,12 @@
|
||||
|
||||
(defn- unit-value
|
||||
[node attrs]
|
||||
(let [v (select-keys node attrs)]
|
||||
(let [v (reduce (fn [value attr]
|
||||
(if (and (#{:typography-ref-id :typography-ref-file} attr)
|
||||
(nil? (get value attr)))
|
||||
(dissoc value attr)
|
||||
value))
|
||||
(select-keys node attrs) attrs)]
|
||||
;; a default the editors leave out is the same as the default written
|
||||
(cond-> v
|
||||
(and (contains? (set attrs) :fills) (nil? (:fills v))) (assoc :fills nil))))
|
||||
|
||||
@ -437,6 +437,61 @@
|
||||
(t/is (= (flips shape) (flips after)))
|
||||
(t/is (gsh/close-attrs? :points (:points shape) (:points after) 0.001))))))
|
||||
|
||||
(t/deftest a-mirrored-copy-child-may-store-either-sign-of-its-turn
|
||||
(let [situation (-> (setup/nested-component-with-copy)
|
||||
(r/step (n/rotate :main2-nested-head 90)) r/settle
|
||||
(r/step (n/transform-shape :copy-root :flip-x nil)) r/settle)
|
||||
file (tm/file situation)
|
||||
page (thf/current-page file)
|
||||
child (tm/role-shape situation :copy-instance)
|
||||
expected (oracle/expected-geometry file (ctn/make-container page :page)
|
||||
(cf/libraries situation) child)
|
||||
flagged (fn [shape expected]
|
||||
(try (oracle/check-requested-geometry (:objects page) shape expected) nil
|
||||
(catch #?(:clj Throwable :cljs :default) cause (:attrs (ex-data cause)))))
|
||||
unflipped #(assoc % :flip-x false)]
|
||||
(t/is (empty? (:touched child)))
|
||||
(t/is (:flip-x child))
|
||||
;; the flip stores the turn that decomposes the child's transform
|
||||
(t/is (mth/close? 90 (:rotation child)))
|
||||
(t/is (mth/close? 90 (:rotation expected)))
|
||||
(t/is (nil? (flagged child expected)))
|
||||
(t/is (nil? (flagged (assoc child :rotation 270) expected)))
|
||||
;; any rotation the child stores at its expected corners
|
||||
(t/is (nil? (flagged (assoc child :rotation 45) expected)))
|
||||
(t/is (nil? (flagged (unflipped (assoc child :rotation 270)) (unflipped expected))))))
|
||||
|
||||
(t/deftest a-copy-child-turn-that-decomposes-its-own-transform-is-accepted
|
||||
;; Parents with equivalent decompositions can add up to another turn.
|
||||
(let [shape (cts/setup-shape {:type :rect :x 10 :y 10 :width 20 :height 20})
|
||||
flagged (fn [shape expected]
|
||||
(try (oracle/check-requested-geometry {(:id shape) shape} shape expected) nil
|
||||
(catch #?(:clj Throwable :cljs :default) cause (:attrs (ex-data cause)))))]
|
||||
(t/is (nil? (flagged shape (assoc shape :rotation 270))))
|
||||
(t/is (nil? (flagged (assoc shape :rotation 90) (assoc shape :rotation 270))))
|
||||
;; the turn itself is checked through the corners
|
||||
(t/is (contains? (flagged (gsh/transform-shape shape (ctm/rotation-modifiers shape (gsh/shape->center shape) 45))
|
||||
shape)
|
||||
:points))
|
||||
(t/is (map? (cg/run {:world [2 2 {:variants true :rich-variants true :text true :text-styles true
|
||||
:layout nil :layout-copies true}]
|
||||
:ops [[:rotate 0 0 0 0] [:switch 1 0 0 0] [:transform 0 4 0 4]
|
||||
[:update-main 0 0 0 0] [:swap 0 0 0 0] [:nest 2 0 0 0]]})))))
|
||||
|
||||
(t/deftest both-flags-may-record-a-half-turn-the-rotation-counts
|
||||
(let [shape (cts/setup-shape {:type :rect :x 10 :y 10 :width 20 :height 20})
|
||||
turned (-> (gsh/transform-shape shape (ctm/rotation-modifiers shape (gsh/shape->center shape) 225))
|
||||
(assoc :flip-x true :flip-y true))
|
||||
flagged (fn [shape expected]
|
||||
(try (oracle/check-requested-geometry {(:id shape) shape} shape expected) nil
|
||||
(catch #?(:clj Throwable :cljs :default) cause (:attrs (ex-data cause)))))]
|
||||
(t/is (mth/close? 225 (:rotation turned)))
|
||||
(t/is (nil? (flagged turned (assoc turned :rotation 135))))
|
||||
(t/is (nil? (flagged (assoc turned :rotation 90) (assoc turned :rotation 135))))
|
||||
(t/is (map? (cg/run {:world [2 2 {:variants true :rich-variants true :text true :text-styles true
|
||||
:layout nil :layout-copies true}]
|
||||
:ops [[:transform 0 4 0 2] [:transform 3 4 0 3] [:rotate 0 0 2 0]]})))))
|
||||
|
||||
(t/deftest a-copy-keeps-the-size-a-plain-boards-constraint-gave-it
|
||||
;; A resize through constraints is derived, never an override, and the
|
||||
;; next sync of the copy's own component keeps it.
|
||||
@ -485,6 +540,27 @@
|
||||
(t/is (map? (cg/run {:world [2 0 {:text true :text-styles true}]
|
||||
:ops [[:add-child 0 0 0 0] [:resize 0 0 0 0] [:delete 0 0 0 0] [:style 1 9 1]]}))))
|
||||
|
||||
(t/deftest a-constraint-resize-under-a-plain-parent-is-not-an-override
|
||||
;; Update main shrinks the main root, and a nested copy inside it follows
|
||||
;; through its scale constraint without being touched.
|
||||
(t/is (map? (cg/run {:world [2 0 {:variants true :rich-variants true :text true :text-styles true
|
||||
:library true :layout-copies true}]
|
||||
:ops [[:resize 2 0 0 0] [:edit 7 5 0 0] [:style 15 9 1] [:edit 8 0 1 1]
|
||||
[:update-main 8]]}))))
|
||||
|
||||
(t/deftest both-flags-and-a-half-turn-equal-neither
|
||||
(let [shape (cts/setup-shape {:type :rect :x 10 :y 10 :width 20 :height 20})
|
||||
flagged (fn [shape expected]
|
||||
(try (oracle/check-requested-geometry {(:id shape) shape} shape expected) nil
|
||||
(catch #?(:clj Throwable :cljs :default) cause (:attrs (ex-data cause)))))
|
||||
both #(assoc % :flip-x true :flip-y true)]
|
||||
(t/is (nil? (flagged (assoc (both shape) :rotation 180) shape)))
|
||||
(t/is (= #{:flip-x :flip-y} (flagged (assoc (both shape) :rotation 90) shape)))
|
||||
(t/is (map? (cg/run {:world [2 0 {:library true :stale-libraries true
|
||||
:library-dependency true :library-text true}]
|
||||
:ops [[:library-transform 0 5 4 0] [:library-transform 0 3 3 0]
|
||||
[:library-remove-child 3 0 0 0] [:library-transform 0 4 4 0]]})))))
|
||||
|
||||
(t/deftest a-resized-turned-main-keeps-its-copies-at-their-first-corner
|
||||
;; a width change keeps a shape's first corner; a copy oriented like its
|
||||
;; main keeps its own first corner, whether the turn or flip is the main's
|
||||
|
||||
@ -132,7 +132,8 @@
|
||||
objects (:objects (thf/current-page (tm/file grown)))
|
||||
main-ids (set (:shapes (first shapes)))
|
||||
component (:component-id (first shapes))
|
||||
synced (r/settle grown #{component})]
|
||||
;; a sync of the copies lays them out again, as in the editor
|
||||
synced (-> grown (r/settle #{component}) r/settle-layout)]
|
||||
(doseq [shape shapes]
|
||||
(t/is (= dims (mapv #(count (get shape %)) [:layout-grid-rows :layout-grid-columns])))
|
||||
(t/is (= coords (set (map (juxt :row :column) (vals (:layout-grid-cells shape))))))
|
||||
@ -927,10 +928,13 @@
|
||||
(t/is (= (geometry copy-group) (geometry copy-group'')))))
|
||||
|
||||
(t/deftest test-sync-undo-group-after-add-and-update
|
||||
;; This group follows the main's bounds; its children keep their geometry.
|
||||
;; The next case checks a group that keeps its own frame instead.
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(add-group-component-with-copy)
|
||||
(touch-copy-group-geometry)
|
||||
(ths/update-shape :copy-child1 :touched #{:geometry-group})
|
||||
(ths/update-shape :copy-child2 :touched #{:geometry-group})
|
||||
(ths/add-sample-shape :free-shape :x 60 :y 60 :width 10 :height 10))
|
||||
page (thf/current-page file)
|
||||
copy-group (ths/get-shape file :copy-group)
|
||||
@ -1003,18 +1007,20 @@
|
||||
copy-group (ths/get-shape file :copy-group)
|
||||
|
||||
;; ==== Action
|
||||
;; The removed shape is the first one in the group, so the sync
|
||||
;; handles it before the updated sibling. Remove it only from the
|
||||
;; main, as a library update does, so that the sync removes it from
|
||||
;; the copy.
|
||||
;; The removed shape precedes the updated sibling. Generate sync
|
||||
;; from the intermediate main-only deletion, but validate and undo
|
||||
;; the complete local edit and its propagation as one group.
|
||||
changes1 (-> (pcb/empty-changes nil (:id page))
|
||||
(pcb/with-objects (:objects page))
|
||||
(pcb/remove-objects #{(thi/id :main-child1)}))
|
||||
updated-file (-> (thf/apply-changes file changes1)
|
||||
(update-fill :main-child2 "#fabada"))
|
||||
(pcb/remove-objects #{(thi/id :main-child1)})
|
||||
(pcb/update-shapes #{(thi/id :main-child2)}
|
||||
#(assoc % :fills (ths/sample-fills-color :fill-color "#fabada"))))
|
||||
updated-file (thf/apply-changes file changes1 :validate? false)
|
||||
changes2 (sync-file-changes updated-file)
|
||||
file' (thf/apply-changes updated-file changes2)
|
||||
file'' (thf/apply-undo-changes file' changes2)
|
||||
changes (pcb/concat-changes changes1 changes2)
|
||||
file' (thf/apply-changes file changes)
|
||||
file'' (thf/apply-undo-changes file' changes)
|
||||
redone (thf/apply-changes file'' changes)
|
||||
|
||||
;; ==== Get
|
||||
copy-group' (ths/get-shape file' :copy-group)
|
||||
@ -1024,7 +1030,11 @@
|
||||
(t/is (= 1 (count (:shapes copy-group'))))
|
||||
(t/is (not= (geometry copy-group) (geometry copy-group')))
|
||||
(t/is (= (:shapes copy-group) (:shapes copy-group'')))
|
||||
(t/is (= (geometry copy-group) (geometry copy-group'')))))
|
||||
(t/is (= (geometry copy-group) (geometry copy-group'')))
|
||||
(t/is (= "#fabada" (get-in (ths/get-shape file' :main-child2) [:fills 0 :fill-color])))
|
||||
(t/is (= "#fabada" (get-in (ths/get-shape file' :copy-child2) [:fills 0 :fill-color])))
|
||||
(t/is (uc/same-state? (uc/snapshot file) (uc/snapshot file'')))
|
||||
(t/is (uc/same-state? (uc/snapshot file') (uc/snapshot redone)))))
|
||||
|
||||
(t/deftest test-sync-inverse-undo-group-after-add-and-update
|
||||
(let [;; ==== Setup
|
||||
@ -1047,8 +1057,7 @@
|
||||
container (ctn/make-container page :page)
|
||||
changes (-> (pcb/empty-changes)
|
||||
(pcb/with-container container)
|
||||
(cll/generate-sync-shape-inverse (:data updated-file)
|
||||
{(:id updated-file) updated-file}
|
||||
(cll/generate-sync-shape-inverse {(:id updated-file) updated-file}
|
||||
container
|
||||
(thi/id :copy-root)))
|
||||
file' (thf/apply-changes updated-file changes)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,9 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns common-tests.logic.composable-oracle-test
|
||||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
@ -89,6 +95,36 @@
|
||||
(t/is (not (oracle/equivalent? (oracle/canonical initial strict) (oracle/canonical inherited strict))))
|
||||
(t/is (not (oracle/equivalent? (oracle/canonical initial) (oracle/canonical inherited))))))
|
||||
|
||||
(t/deftest hidden-layout-children-have-no-tracked-position
|
||||
;; out of the flow and invisible, a hidden layout child's position is
|
||||
;; nobody's to keep: the layout places it once shown
|
||||
(let [base (setup/simple-component-with-labeled-copy)
|
||||
file (-> (tm/file base)
|
||||
(ths/update-shape :main-root :layout :flex)
|
||||
(ths/update-shape :copy-root :layout :flex)
|
||||
(ths/update-shape :copy-root :touched nil))
|
||||
initial (-> (tm/with-file base file)
|
||||
(r/step (n/change-property :copy-child :hidden true)) r/settle)
|
||||
move (fn [situation labels]
|
||||
(let [file (tm/file situation)
|
||||
page (thf/current-page file)]
|
||||
(tm/with-file situation
|
||||
(thf/apply-changes file
|
||||
(cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page))
|
||||
(map thi/id labels)
|
||||
#(gsh/move % (gpt/point 30 0))
|
||||
(:objects page) {:ignore-touched true})))))
|
||||
drifted (move initial [:copy-child])
|
||||
resized (tm/with-file initial (ths/update-shape (tm/file initial) :copy-child :width 7))
|
||||
parity {:relative-free-head-placement true}
|
||||
strict {:free-head-placement false}]
|
||||
(t/is (oracle/equivalent? (oracle/canonical initial parity) (oracle/canonical drifted parity)))
|
||||
(t/is (oracle/equivalent? (oracle/canonical initial strict) (oracle/canonical drifted strict)))
|
||||
(t/is (nil? (oracle/check drifted {(thi/id :copy-child) {:visibility-group {:hidden true}}})))
|
||||
(t/testing "its size stays tracked"
|
||||
(t/is (not (oracle/equivalent? (oracle/canonical initial parity) (oracle/canonical resized parity)))))))
|
||||
|
||||
(t/deftest oracle-rejects-unmarked-differences-in-all-scalar-groups
|
||||
(let [situation (setup/simple-component-with-labeled-copy)
|
||||
file (tm/file situation)]
|
||||
@ -124,6 +160,128 @@
|
||||
(t/is (thrown? #?(:clj Exception :cljs js/Error)
|
||||
(oracle/check (tm/with-file situation broken) {} false)))))))
|
||||
|
||||
(t/deftest sync-equivalence-compares-geometry-without-rounding-boundaries
|
||||
(let [initial (setup/simple-component-with-labeled-copy)
|
||||
file (ths/update-shape (tm/file initial) :copy-child :opacity 0.4)
|
||||
page (thf/current-page file)
|
||||
id (thi/id :copy-child)
|
||||
move-to (fn [x]
|
||||
(tm/with-file initial
|
||||
(thf/apply-changes file
|
||||
(cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page)) [id]
|
||||
#(gsh/absolute-move % (gpt/point x (:y %)))
|
||||
(:objects page) {:ignore-touched true}))))
|
||||
before (move-to (- 103.005 1e-6))
|
||||
after (move-to (+ 103.005 1e-6))
|
||||
scalar (tm/with-file before
|
||||
(assoc-in (tm/file before) [:data :pages-index (:id page) :objects id :opacity]
|
||||
(+ 0.4 1e-15)))]
|
||||
(t/is (oracle/equivalent? (oracle/canonical before) (oracle/canonical after)))
|
||||
(t/is (not (oracle/equivalent? (oracle/canonical before) (oracle/canonical (move-to 101)))))
|
||||
(t/is (not (oracle/equivalent? (oracle/canonical before) (oracle/canonical scalar))))))
|
||||
|
||||
(t/deftest swapped-head-inputs-follow-position-and-content-separately
|
||||
(let [file (-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component :a :a-root :a-child
|
||||
:root-params {:height 120})
|
||||
(tho/add-simple-component :b :b-root :b-child
|
||||
:root-params {:constraints-h :right
|
||||
:layout-item-margin {:m1 9 :m2 9 :m3 9 :m4 9}})
|
||||
(tho/add-frame :outer-root)
|
||||
(thc/instantiate-component :a :position :parent-label :outer-root)
|
||||
(thc/make-component :outer :outer-root)
|
||||
(thc/instantiate-component :outer :copy-root :children-labels [:swapped])
|
||||
(tho/swap-component-in-shape :swapped :b))
|
||||
file (:file (r/sync-cascade file {} (keys (get-in file [:data :components]))))
|
||||
model {(thi/id :swapped) {:swap-group {}}}]
|
||||
(t/is (nil? (oracle/check (tm/make-situation file) model)))
|
||||
(doseq [[attr value] [[:width 101]
|
||||
[:constraints-h :right]
|
||||
[:layout-item-margin {:m1 9 :m2 9 :m3 9 :m4 9}]]]
|
||||
(let [broken (assoc-in file [:data :pages-index (:id (thf/current-page file))
|
||||
:objects (thi/id :swapped) attr] value)]
|
||||
(t/is (thrown? #?(:clj Exception :cljs js/Error)
|
||||
(oracle/check (tm/make-situation broken) model)))))))
|
||||
|
||||
(t/deftest detached-rotated-parent-still-places-its-nested-copy
|
||||
(let [detached (-> (setup/nested-component-with-copy)
|
||||
(r/step (n/rotate :copy-root 90)) r/settle
|
||||
(r/step (n/detach :copy-root)) r/settle)]
|
||||
(t/is (nil? (oracle/check detached {})))
|
||||
(let [file (tm/file detached)
|
||||
page (thf/current-page file)
|
||||
head (tm/role-shape detached :copy-instance)
|
||||
id (first (:shapes head))
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page)) [id]
|
||||
#(gsh/move % (gpt/point 10 0)) (:objects page)
|
||||
{:ignore-touched true})
|
||||
broken (tm/with-file detached (thf/apply-changes file changes))]
|
||||
(t/is (thrown? #?(:clj Exception :cljs js/Error) (oracle/check broken {}))))))
|
||||
|
||||
(defn- sample
|
||||
[constraint]
|
||||
(-> (thf/sample-file :file1)
|
||||
(tho/add-frame :main-root {:width 100 :height 100})
|
||||
(tho/add-rect :main-child {:parent-label :main-root :x 20 :y 10
|
||||
:width 30 :height 20
|
||||
:constraints-h constraint :constraints-v :top})
|
||||
(thc/make-component :component1 :main-root)
|
||||
(thc/instantiate-component :component1 :copy-root :children-labels [:copy-child])))
|
||||
|
||||
(defn- transform
|
||||
[file label modifiers]
|
||||
(let [page (thf/current-page file)
|
||||
objects (:objects page)
|
||||
id (thi/id label)
|
||||
tree (gm/set-objects-modifiers {id {:modifiers modifiers}} objects)
|
||||
change (clp/modifiers-transform tree)]
|
||||
(thf/apply-changes file
|
||||
(cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page)) (keys tree) change objects
|
||||
{:ignore-tree (clp/calculate-ignore-tree objects (keys tree) change #{id})
|
||||
:attrs clp/transform-attrs}))))
|
||||
|
||||
(defn- geometry-model
|
||||
[file]
|
||||
{(thi/id :copy-root) {:geometry-group (shadow/values (ths/get-shape file :copy-root)
|
||||
:geometry-group)}})
|
||||
|
||||
(t/deftest oracle-accepts-placement-and-constraint-resize
|
||||
(doseq [constraint [:scale :leftright :left :center]]
|
||||
(let [file (sample constraint)
|
||||
root (ths/get-shape file :copy-root)
|
||||
resized (transform file :copy-root (ctm/change-size root 200 100))
|
||||
rotated (transform resized :copy-root
|
||||
(ctm/rotation-modifiers (ths/get-shape resized :copy-root)
|
||||
(gsh/shape->center (ths/get-shape resized :copy-root))
|
||||
90))]
|
||||
(t/is (nil? (oracle/check (tm/make-situation file) {})))
|
||||
(t/is (nil? (oracle/check (tm/make-situation resized) (geometry-model resized))))
|
||||
(t/is (nil? (oracle/check (tm/make-situation rotated) (geometry-model rotated)))))))
|
||||
|
||||
(t/deftest oracle-rejects-wrong-child-position-and-size
|
||||
(let [file (sample :left)
|
||||
page (thf/current-page file)
|
||||
change (fn [f]
|
||||
(thf/apply-changes
|
||||
file (cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page)) #{(thi/id :copy-child)}
|
||||
f (:objects page) {:ignore-touched true})))
|
||||
moved (change #(gsh/move % (gpt/point 5 0)))
|
||||
resized (change #(gsh/transform-shape % (ctm/change-size % 40 20)))]
|
||||
(t/is (thrown? #?(:clj Exception :cljs js/Error)
|
||||
(oracle/check (tm/make-situation moved) {})))
|
||||
(t/is (thrown? #?(:clj Exception :cljs js/Error)
|
||||
(oracle/check (tm/make-situation resized) {})))))
|
||||
|
||||
(t/deftest oracle-rejects-unmarked-constraint-differences
|
||||
(let [file (-> (sample :left)
|
||||
(ths/update-shape :copy-child :constraints-h :right)
|
||||
(ths/update-shape :copy-child :touched nil))]
|
||||
(t/is (thrown? #?(:clj Exception :cljs js/Error)
|
||||
(oracle/check (tm/make-situation file) {})))))
|
||||
|
||||
(t/deftest grid-visibility-expectations-still-reject-cell-corruption
|
||||
(let [file (-> (thf/sample-file :file1)
|
||||
(tho/add-frame :main-root (merge cls/initial-grid-layout {:width 300 :height 100}))
|
||||
@ -225,8 +383,98 @@
|
||||
(:objects (thf/current-page file)) {:ignore-touched true})))
|
||||
moved (move file #{(thi/id :copy-root) (thi/id :copy-child)} 50)
|
||||
bad (move moved #{(thi/id :copy-child)} 5)]
|
||||
(t/is (= (oracle/canonical situation) (oracle/canonical (tm/with-file situation moved))))
|
||||
(t/is (not= (oracle/canonical situation) (oracle/canonical (tm/with-file situation bad))))))
|
||||
(t/is (oracle/equivalent? (oracle/canonical situation) (oracle/canonical (tm/with-file situation moved))))
|
||||
(t/is (not (oracle/equivalent? (oracle/canonical situation) (oracle/canonical (tm/with-file situation bad)))))))
|
||||
|
||||
(t/deftest sync-comparison-treats-nil-and-false-flips-as-the-same-orientation
|
||||
(let [situation (setup/simple-component-with-labeled-copy)
|
||||
file (tm/file situation)
|
||||
unflipped (tm/with-file situation (-> file (ths/update-shape :copy-root :flip-x false) (ths/update-shape :copy-root :touched nil)))
|
||||
flipped (tm/with-file situation (-> file (ths/update-shape :copy-root :flip-x true) (ths/update-shape :copy-root :touched nil)))]
|
||||
(t/is (oracle/equivalent? (oracle/canonical situation) (oracle/canonical unflipped)))
|
||||
(t/is (not (oracle/equivalent? (oracle/canonical situation) (oracle/canonical flipped))))))
|
||||
|
||||
(t/deftest expected-child-flips-follow-successive-parent-rotations
|
||||
(let [file (sample :left)
|
||||
turn (fn [file]
|
||||
(let [root (ths/get-shape file :copy-root)]
|
||||
(transform file :copy-root
|
||||
(ctm/rotation-modifiers root (gsh/shape->center root) 45))))
|
||||
rotated (-> file turn turn)]
|
||||
(t/is (nil? (oracle/check (tm/make-situation rotated) (geometry-model rotated))))))
|
||||
|
||||
(t/deftest backend-comparison-allows-instance-placement-after-leaving-a-layout
|
||||
(let [situation (setup/nested-component-with-copy)
|
||||
file (tm/file situation)
|
||||
page (thf/current-page file)
|
||||
head (tm/resolve-shape situation :main2-nested-head)
|
||||
child (first (:shapes head))
|
||||
move (fn [ids]
|
||||
(thf/apply-changes
|
||||
file (cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page)) ids
|
||||
#(gsh/move % (gpt/point 30 0)) (:objects page)
|
||||
{:ignore-touched true})))
|
||||
placed (tm/with-file situation (move [(:id head) child]))
|
||||
broken (tm/with-file situation (move [child]))]
|
||||
(t/is (oracle/equivalent? (oracle/canonical situation) (oracle/canonical placed)))
|
||||
(t/is (not (oracle/equivalent? (oracle/canonical situation) (oracle/canonical broken))))))
|
||||
|
||||
(t/deftest nested-copy-child-flips-follow-successive-root-rotations
|
||||
(let [result (cg/run
|
||||
{:world [2 1 {:text true}]
|
||||
:ops [[:add-child 0] [:remove-child 0] [:duplicate 0] [:nest 0]
|
||||
[:delete 0] [:restore 0] [:text 0 0 1] [:text 1 1 1]
|
||||
[:resize 0 0 2] [:rotate 0 0 0] [:reset 0]
|
||||
[:edit 0 0 1 1] [:update-main 0] [:sync 1]
|
||||
[:detach 0] [:undo] [:redo]
|
||||
[:rotate 4 0 0 0] [:rotate 4 0 5 0]]})]
|
||||
(t/is (= 3 (get-in result [:executed :rotate])))))
|
||||
|
||||
(t/deftest matrix-equivalence-measures-its-effect-in-pixels
|
||||
(doseq [[size equal?] [[0.01 true] [100 false]]]
|
||||
(let [file (-> (thf/sample-file :file1)
|
||||
(tho/add-rect :rect {:width size :height size}))
|
||||
changed (ths/update-shape file :rect :transform (gmt/matrix 0.8 0 0 1 0 0))]
|
||||
(t/is (= equal? (oracle/equivalent? (oracle/canonical (tm/make-situation file))
|
||||
(oracle/canonical (tm/make-situation changed))))))))
|
||||
|
||||
(t/deftest measured-text-comparison-keeps-the-oriented-first-corner
|
||||
(doseq [grow-type [:auto-height :auto-width]
|
||||
angle [0 45 90 135]
|
||||
reflected? [false true]]
|
||||
(let [file (-> (thf/sample-file :file)
|
||||
(ths/add-sample-shape :text :type :text :grow-type grow-type
|
||||
:width 70 :height 25))
|
||||
page-id (:id (thf/current-page file))
|
||||
path [:data :pages-index page-id :objects (thi/id :text)]
|
||||
orient (fn [shape]
|
||||
(cond-> (gsh/transform-shape shape (n/geometry-modifiers shape :rotate angle))
|
||||
reflected? (as-> shape (gsh/transform-shape shape (n/geometry-modifiers shape :flip-x nil)))))
|
||||
file (update-in file path orient)
|
||||
original (get-in file path)
|
||||
measured (update-in file path
|
||||
(fn [shape]
|
||||
(let [resized (gsh/transform-shape
|
||||
shape (ctm/change-size shape
|
||||
(if (= :auto-width grow-type) 55 70) 17))]
|
||||
(gsh/move resized (gpt/subtract (first (:points shape))
|
||||
(first (:points resized)))))))
|
||||
shifted (update-in measured path gsh/move (gpt/point 1 0))
|
||||
wrong-width (assoc-in measured (conj path :width) 60)
|
||||
design #(oracle/canonical (tm/make-situation %) {:free-head-placement false})]
|
||||
(t/testing (str grow-type ", angle " angle ", reflected " reflected?)
|
||||
(t/is (oracle/equivalent? (design file) (design measured))))
|
||||
(t/is (not (oracle/equivalent? (design file) (design shifted))))
|
||||
(t/is (not= (oracle/snapshot (tm/make-situation file))
|
||||
(oracle/snapshot (tm/make-situation measured))))
|
||||
(t/is (nil? (oracle/check-requested-geometry (:objects (thf/current-page measured))
|
||||
(get-in measured path) original)))
|
||||
(t/is (thrown? #?(:clj Exception :cljs js/Error)
|
||||
(oracle/check-requested-geometry (:objects (thf/current-page shifted))
|
||||
(get-in shifted path) original)))
|
||||
(when (= :auto-height grow-type)
|
||||
(t/is (not (oracle/equivalent? (design file) (design wrong-width))))))))
|
||||
|
||||
(t/deftest matrix-comparison-does-not-reintroduce-derived-text-dimensions
|
||||
(doseq [grow-type [:auto-height :auto-width]]
|
||||
@ -242,8 +490,10 @@
|
||||
changed (assoc-in measured (conj path :transform) (gmt/matrix 1 0 0 1 2 0))
|
||||
stretched (assoc-in measured (conj path :transform) (gmt/matrix 1 0 0 1.1 0 0))
|
||||
fixed-width (assoc-in measured (conj path :width) 60)
|
||||
turn #(gsh/absolute-move (gsh/transform-shape % (n/geometry-modifiers % :rotate 45))
|
||||
(gpt/point 0 0))
|
||||
;; Both measured versions use the renderer's oriented corner anchor.
|
||||
turn (fn [shape]
|
||||
(let [turned (gsh/transform-shape shape (n/geometry-modifiers shape :rotate 45))]
|
||||
(gsh/move turned (gpt/negate (first (:points turned))))))
|
||||
rotated (update-in file path turn)
|
||||
rotated-measured (update-in measured path turn)
|
||||
design #(oracle/canonical (tm/make-situation %))]
|
||||
@ -255,3 +505,74 @@
|
||||
(oracle/snapshot (tm/make-situation measured))))
|
||||
(when (= grow-type :auto-height)
|
||||
(t/is (not (oracle/equivalent? (design file) (design fixed-width))))))))
|
||||
|
||||
(t/deftest authored-child-orientation-follows-the-parent-frame
|
||||
(let [model {:child {:geometry-group {:width 20 :height 30 :rotation 90}}}
|
||||
before {:child {:id :child :parent-id :parent}
|
||||
:parent {:rotation 45}}
|
||||
after {:child {:id :child :parent-id :parent :rotation 0 :width 20 :height 30}
|
||||
:parent {:rotation 135 :flip-x true :flip-y true}}
|
||||
expected (get-in (shadow/parent-orientation model before after) [:child :geometry-group])]
|
||||
(t/is (= {:width 20 :height 30 :rotation 180 :flip-x true :flip-y true} expected))
|
||||
(t/is (not (shadow/same-value? (:child after) :geometry-group expected)))))
|
||||
|
||||
(t/deftest swapped-head-content-size-keeps-the-position-anchor-after-rotation
|
||||
(let [file (-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component :a :a-root :a-child
|
||||
:root-params {:width 100 :height 100}
|
||||
:child-params {:width 20 :height 20})
|
||||
(tho/add-simple-component :b :b-root :b-child
|
||||
:root-params {:width 100 :height 100}
|
||||
:child-params {:width 20 :height 20})
|
||||
(tho/add-frame :outer-root)
|
||||
(thc/instantiate-component :a :position :parent-label :outer-root))
|
||||
root (ths/get-shape file :position)
|
||||
file (transform file :position (ctm/change-size root 100 80))
|
||||
root (ths/get-shape file :position)
|
||||
file (-> (transform file :position
|
||||
(ctm/rotation-modifiers root (gsh/shape->center root) 45))
|
||||
(thc/make-component :outer :outer-root)
|
||||
(thc/instantiate-component :outer :copy-root :children-labels [:swapped])
|
||||
(tho/swap-component-in-shape :swapped :b))
|
||||
file (:file (r/sync-cascade file {} (keys (get-in file [:data :components]))))
|
||||
model {(thi/id :position) {:geometry-group (shadow/values (ths/get-shape file :position)
|
||||
:geometry-group)}
|
||||
(thi/id :swapped) {:swap-group {}}}
|
||||
page (thf/current-page file)
|
||||
moved (thf/apply-changes
|
||||
file (cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page)) [(thi/id :swapped)]
|
||||
#(gsh/move % (gpt/point 5 0)) (:objects page)
|
||||
{:ignore-touched true}))]
|
||||
(t/is (nil? (oracle/check (tm/make-situation file) model)))
|
||||
(t/is (thrown? #?(:clj Exception :cljs js/Error)
|
||||
(oracle/check (tm/make-situation moved) model)))))
|
||||
|
||||
(t/deftest minimum-size-parent-placement-keeps-fixed-child-dimensions
|
||||
(let [result (cg/run {:world [2 0 {:text true :layout nil}]
|
||||
:ops [[:add-child 0] [:remove-child 0] [:duplicate 0] [:nest 0]
|
||||
[:delete 0] [:restore 0] [:text 0 0 1] [:text 1 1 1]
|
||||
[:resize 0 0 2] [:rotate 0 0 0] [:reset 0]
|
||||
[:edit 0 0 1 1] [:update-main 0] [:sync 1]
|
||||
[:detach 0] [:undo] [:redo] [:resize 1 0 0 0]
|
||||
[:nest 2 0 0 0] [:rotate 0 0 3 0] [:edit 0 0 0 0]]})
|
||||
situation (:situation result)
|
||||
file (tm/file situation)
|
||||
page (thf/current-page file)
|
||||
objects (:objects page)
|
||||
child (first (filter (fn [shape]
|
||||
(let [parent (get objects (:parent-id shape))]
|
||||
(and (= :frame (:type shape)) (:component-id shape)
|
||||
(:shape-ref shape) (empty? (:touched shape))
|
||||
(> (:height shape) 1)
|
||||
(< (:width parent 1) 0.02)
|
||||
(< (:height parent 1) 0.02))))
|
||||
(vals objects)))
|
||||
changed (thf/apply-changes
|
||||
file (cls/generate-update-shapes
|
||||
(pcb/empty-changes nil (:id page)) [(:id child)]
|
||||
#(gsh/transform-shape % (ctm/change-size % nil 80)) objects
|
||||
{:ignore-touched true}))]
|
||||
(t/is (some? child))
|
||||
(t/is (thrown? #?(:clj Exception :cljs js/Error)
|
||||
(oracle/check (tm/with-file situation changed) (:model result))))))
|
||||
|
||||
@ -23,6 +23,20 @@
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
(t/deftest undo-comparison-allows-only-negligible-geometry-noise
|
||||
(let [situation (setup/simple-component-with-labeled-copy)
|
||||
file (tm/file situation)
|
||||
id (:id (tm/role-shape situation :copy-instance))
|
||||
path [:data :pages-index (:id (thf/current-page file)) :objects id]
|
||||
before (-> (uc/snapshot file)
|
||||
(assoc-in (conj path :height) 0.01)
|
||||
(assoc-in (conj path :opacity) 0.4))
|
||||
failures #(uc/failures (uc/compare-states {} nil :undo before %))]
|
||||
(t/is (empty? (failures (assoc-in before (conj path :height) 0.010000000000005116))))
|
||||
(t/is (seq (failures (assoc-in before (conj path :height) 0.01001))))
|
||||
(t/is (seq (failures (assoc-in before (conj path :opacity) (+ 0.4 5e-15)))))
|
||||
(t/is (seq (failures (assoc-in before (conj path :touched) #{:geometry-group}))))))
|
||||
|
||||
(t/deftest undo-main-child-structure-restores-remote-sync-state
|
||||
(let [initial (setup/nested-component-with-copy)
|
||||
updated (-> initial
|
||||
@ -210,8 +224,8 @@
|
||||
(:type (ex-data e)))))
|
||||
|
||||
(t/deftest frontend-only-operations-are-rejected
|
||||
(t/is (= ::r/frontend-only (error-type (n/rotate :main-root 45))))
|
||||
(t/is (= ::r/frontend-only (error-type (n/change-height :main-root 50)))))
|
||||
(t/is (= ::r/frontend-only (error-type (n/move-shape :main-root 20 0))))
|
||||
(t/is (= ::r/frontend-only (error-type (n/undo-before-sync :main-child :fills red)))))
|
||||
|
||||
;; A user operation that forgets to record its changes.
|
||||
(defrecord UnrecordedEdit []
|
||||
@ -586,6 +600,26 @@
|
||||
(reset! counted @made))))
|
||||
(t/is (= 2 @counted))))
|
||||
|
||||
(t/deftest duplicate-result-finds-the-user-subtree-after-propagation
|
||||
(let [before (r/run-variant
|
||||
{:setup setup/empty-situation
|
||||
:operation (tm/in-sequence [(n/create-component "a" original :size 100)
|
||||
(n/make-nested-component "a" 1)
|
||||
(n/instantiate-copy "a")
|
||||
(n/instantiate-copy "a")])})
|
||||
duplicate (n/duplicate (n/nested-head-of "a" 0))
|
||||
after (r/settle (r/step before duplicate))
|
||||
result (n/applied-result duplicate (tm/file before) (tm/file after))
|
||||
new-head (tm/shape-by-id after (:new-head result))]
|
||||
(t/is (= ((n/main-head-of "a") before) (:parent-id new-head)))))
|
||||
|
||||
(t/deftest missing-shape-diagnostics-accept-mixed-label-types
|
||||
(let [situation (setup/simple-component-with-labeled-copy)
|
||||
error (try (tm/resolve-shape situation :missing)
|
||||
(catch #?(:clj Exception :cljs js/Error) error error))]
|
||||
(t/is (= ::tm/unbound-shape-name (:type (ex-data error))))
|
||||
(t/is (some #{:copy-child} (:present (ex-data error))))))
|
||||
|
||||
(t/deftest library-update-main-routes-both-files-and-undoes-the-cascade
|
||||
(let [initial (setup/cross-file-component-with-copy setup/labeled-fill)
|
||||
library (first (vals (tm/aux-files initial)))
|
||||
|
||||
@ -9,33 +9,33 @@
|
||||
:ac
|
||||
[{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-variant-container {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 3}\n make-nested-component-with-variant {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n change-property {:target #fn, :property :opacity, :value 0.5}\n switch-variant {:target-component sync-vset-v1-component}\n test\n switch-variant {:target-component sync-vset-v2-component}", :states ["9f9ac61ce3c54295" "5bd9620c6fc0cf6e" "387d74ba1c75e52f" "62a55a068ebd6043"]}]
|
||||
:ad
|
||||
[{:transcript "create-component {:component \"main\", :id sync-main-component}\n create-component {:component \"s1\", :id sync-s1-component}\n make-nested-component {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-1}\n swap-shape {:target #fn, :to \"s1\", :keep-touched? false}\n update-main {:target #fn, :updated sync-main-copyhead-0}", :states ["9835a328e680007d" "8cc31cfc15b28449" "40c27ac7ca18d972"]}]
|
||||
[{:transcript "create-component {:component \"main\", :id sync-main-component}\n create-component {:component \"s1\", :id sync-s1-component}\n make-nested-component {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-1}\n swap-shape {:target #fn, :to \"s1\", :keep-touched? false}\n update-main {:target #fn, :updated sync-main-copyhead-0}", :states ["9835a328e680007d" "cb25044bb21b9f5f" "f1af8a77852eb4e6"]}]
|
||||
:ae
|
||||
[{:transcript "create-component {:component \"main\", :id sync-main-component}\n create-component {:component \"s1\", :id sync-s1-component}\n make-nested-component {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n swap-shape {:target #fn, :to \"s1\", :keep-touched? false}\n detach {:target #fn, :detached sync-main-copyhead-0}\n change-property {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["a3cb16fb335bc929" "e10b1283627fbeb6" "9be2dfab826240b0" "1fc0e554196dfd2b"]}
|
||||
{:transcript "create-component {:component \"main\", :id sync-main-component}\n create-component {:component \"s1\", :id sync-s1-component}\n make-nested-component {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n swap-shape {:target #fn, :to \"s1\", :keep-touched? false}\n duplicate {:target #fn, :new-head 5}\n change-property {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["a3cb16fb335bc929" "d291c9ca9a187b1b" "99bb6214c05d575b" "0694d4feab3cb633"]}]
|
||||
:af
|
||||
[{:transcript "swap-shape {:target :copy-child, :to :other, :keep-touched? false}\n move-to-cell {:board :main-root, :child :main-child, :row 1, :column 3}", :states ["a3bca1c5fd1b9b29" "8a7fa3fde8815d35" "1c786eab89f462da"]}
|
||||
{:transcript "one-of -> skip\n move-to-cell {:board :main-root, :child :main-child, :row 1, :column 3}", :states ["7f1f0be7424c543f" "7c9214e430ebb4e8"]}]
|
||||
[{:transcript "swap-shape {:target :copy-child, :to :other, :keep-touched? false}\n move-to-cell {:board :main-root, :child :main-child, :row 1, :column 3}", :states ["0ad5feb2c5e1a843" "9d4bf4912c552f43" "317588029f30f1ef"]}
|
||||
{:transcript "one-of -> skip\n move-to-cell {:board :main-root, :child :main-child, :row 1, :column 3}", :states ["92614cf6d7575ad8" "00312b9131f4fec6"]}]
|
||||
:ag
|
||||
[{:transcript "move-child {:target :sub1, :parent :row-root, :to-index 3}", :states ["7a572aaeec3d11c7" "e6899eae694479cf"]}]
|
||||
[{:transcript "move-child {:target :sub1, :parent :row-root, :to-index 3}", :states ["b8a611163a069cb1" "7b199a2abaca4eeb"]}]
|
||||
:ah
|
||||
[{:transcript "one-of -> recorded-choice\n remove-child {:target :copy-sub1}", :states ["3043434871927bf0" "c5acd77993218759"]}
|
||||
{:transcript "one-of -> recorded-choice\n remove-child {:target :copy-sub3}", :states ["fdddae12ff7dd7bc" "7efeb83144959be0"]}
|
||||
[{:transcript "one-of -> recorded-choice\n remove-child {:target :copy-sub1}", :states ["b7bc2738237657c2" "cc2ba3235bac195f"]}
|
||||
{:transcript "one-of -> recorded-choice\n remove-child {:target :copy-sub3}", :states ["e2e4320b1a62202d" "44788f4405295d27"]}
|
||||
{:transcript "one-of -> skip", :states ["4f8193bba8dbfb0d"]}]
|
||||
:ak
|
||||
[{:transcript "swap-shape {:target :copy-child, :to :other, :keep-touched? false}\n move-to-cell {:board :copy-root, :child :copy-child, :row 1, :column 3}\n update-main {:target :copy-root, :updated grid-copy}", :states ["a3bca1c5fd1b9b29" "246adb9d062e7222" "725449d340ed4db7" "f7c72fa8b8699165"]}
|
||||
[{:transcript "swap-shape {:target :copy-child, :to :other, :keep-touched? false}\n move-to-cell {:board :copy-root, :child :copy-child, :row 1, :column 3}\n update-main {:target :copy-root, :updated grid-copy}", :states ["0ad5feb2c5e1a843" "7e8833e5c26e234c" "2508613c0f17bc78" "f3d331b4689dd5b9"]}
|
||||
{:transcript "one-of -> skip\n move-to-cell {:board :copy-root, :child :copy-child, :row 1, :column 3}\n update-main {:target :copy-root, :updated grid-copy}", :states ["8aad596633c254fd" "7f1f0be7424c543f" "7c9214e430ebb4e8"]}]
|
||||
:al
|
||||
[{:transcript "change-property {:target :copy-root, :property :name, :value \"Renamed\"}\n change-property {:target :copy-instance, :property :name, :value \"Renamed child\"}\n update-main {:target :copy-root, :updated copy-root}", :states ["0166c98332ed23a7" "6c0c864aa286702f" "af3a00259b74b965" "6598d0729b91c5b3"]}
|
||||
{:transcript "change-property {:target :copy-root, :property :name, :value \"Renamed\"}\n one-of -> skip\n update-main {:target :copy-root, :updated copy-root}", :states ["0166c98332ed23a7" "e2849db0c0174bfc" "c307f8e2c66e8760"]}]
|
||||
:am
|
||||
[{:transcript "swap-shape {:target :copy-child, :to :other, :keep-touched? false}\n update-main {:target :copy-root, :updated grouped-copy}", :states ["606d0e9ed09ebe9b" "c96014db9eb364e5" "bc48794035d17e6f"]}]
|
||||
[{:transcript "swap-shape {:target :copy-child, :to :other, :keep-touched? false}\n update-main {:target :copy-root, :updated grouped-copy}", :states ["6368e4cd1a81c4ef" "4d123aef894febce" "d9e8add6ec7ad890"]}]
|
||||
:an
|
||||
[{:transcript "change-property {:target :copy-instance, :property :margin, :value 8}\n change-property {:target :main-instance, :property :margin, :value 20}", :states ["4087468201a18ebc" "04328fe58e252ee9" "85db26a4ea6a899c"]}
|
||||
{:transcript "change-property {:target :copy-instance, :property :margin, :value 8}\n reset-overrides {:target :copy-root, :reset copy-root}", :states ["4087468201a18ebc" "cb5b3ab586333d10" "054cd426071de8e3"]}
|
||||
{:transcript "change-property {:target :copy-instance, :property :margin, :value 8}\n update-main {:target :copy-root, :updated copy-root}", :states ["4087468201a18ebc" "6b82a7e5bb516fc5" "8d389cd790e5cfb3"]}]
|
||||
:ao
|
||||
[{:transcript "nest-copy {:copy :loose, :into :main-root, :cell [1 3]}", :states ["6e7144142468b3ea" "16834d9e0ad8afe0"]}]
|
||||
[{:transcript "nest-copy {:copy :loose, :into :main-root, :cell [1 3]}", :states ["e251b9e8b2af66b2" "bcd9631b600bc24a"]}]
|
||||
:ap
|
||||
[{:transcript "sync-from-library {:library-id library}", :states ["3550b8df58ff0c95" "3872af2b94d47dea"]}]
|
||||
:aq
|
||||
@ -47,8 +47,8 @@
|
||||
{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-variant-container {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n make-nested-component-with-variant {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n edit-variant-property {:set-name \"vset\", :edit :add, :params {:property-name \"Size\", :property-value \"S\"}}\n edit-variant-property {:set-name \"vset\", :edit :reorder, :params {:from 1, :to 0}}\n test\n switch-variant {:target-component sync-vset-v1-component}", :states ["1247c1fd53a5de3f" "145adc849fab1a7f" "fb07de11459bfd4a" "336e2d434593f2f7" "c587b6e374b11811"]}
|
||||
{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-variant-container {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n make-nested-component-with-variant {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n edit-variant-property {:set-name \"vset\", :edit :add, :params {:property-name \"Size\", :property-value \"S\"}}\n edit-variant-property {:set-name \"vset\", :edit :remove, :params {:pos 1}}\n test\n switch-variant {:target-component sync-vset-v1-component}", :states ["1247c1fd53a5de3f" "145adc849fab1a7f" "1247c1fd53a5de3f" "45d0fe0a073fbada" "9a8e3d09e48af9fe"]}]
|
||||
:as
|
||||
[{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-variant-container {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n make-nested-component-with-variant {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n add-variant {:set-name \"vset\", :member \"a\", :component-id 7}\n test\n switch-variant {:target-component 7}", :states ["1247c1fd53a5de3f" "7e0e395e3d0660a0" "1dfa6bfdd7b29e26" "fa90e52391b5ae7f"]}
|
||||
{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-variant-container {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n make-nested-component-with-variant {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n add-variant {:set-name \"vset\", :member \"b\", :component-id 7}\n test\n switch-variant {:target-component 7}", :states ["1247c1fd53a5de3f" "f4146efd3687f0bf" "02f3dd834cc6a5cb" "fb72fa0de22456bd"]}]
|
||||
[{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-variant-container {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n make-nested-component-with-variant {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n add-variant {:set-name \"vset\", :member \"a\", :component-id 7}\n test\n switch-variant {:target-component 7}", :states ["1247c1fd53a5de3f" "bcbe099789a5e1ad" "e072246cf33079b4" "b0962457e219be49"]}
|
||||
{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-variant-container {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n make-nested-component-with-variant {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n add-variant {:set-name \"vset\", :member \"b\", :component-id 7}\n test\n switch-variant {:target-component 7}", :states ["1247c1fd53a5de3f" "2ce5fcb610cd4a9f" "9455487ba49a2cef" "d7d5d58af75e8bd3"]}]
|
||||
:aw
|
||||
[{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-variant-container {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n make-nested-component-with-variant {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n edit-variant-property {:set-name \"vset\", :edit :rename-in-layers, :params {:member \"a\", :name \"Property 1=a2, Size=S\"}}\n test\n edit-variant-property {:set-name \"vset\", :edit :add, :params {:property-name \"Empty\"}}\n edit-variant-property {:set-name \"vset\", :edit :remove-empty, :params {}}\n test\n edit-variant-property {:set-name \"vset\", :edit :rename-in-layers, :params {:member \"a\", :name \"Property 1=a2\"}}\n test\n edit-variant-property {:set-name \"vset\", :edit :error, :params {:member \"b\", :value \"Duplicated\"}}\n test\n edit-variant-property {:set-name \"vset\", :edit :error, :params {:member \"b\", :value nil}}\n test\n switch-variant {:target-component sync-vset-v1-component}", :states ["1247c1fd53a5de3f" "6fdf7a1f1ec406b9" "8c9e9ff80c81a9c2" "6fdf7a1f1ec406b9" "2282ac416e81ba91" "ac2b1a3ccb8fc65c" "2282ac416e81ba91" "c18d55a87e1dcc61" "bd2d896527a50108"]}]
|
||||
:ay
|
||||
@ -145,14 +145,14 @@
|
||||
:main-edit-into-1000-copies
|
||||
[{:transcript "main-edit-into-1000-copies", :states ["b6994497085bc07f"]}]
|
||||
:n
|
||||
[{:transcript "rotate {:target :copy-root, :angle 45}\n rotate {:target :main-root, :angle 30}\n change-property {:target :main-instance, :property :fills, :value \"#ff0000\"}", :states ["8208735a98e4c105" "f9a383ec6e3b0bb3" "e1975cf2f47c5763" "9a89ace89a9faec9"]}
|
||||
{:transcript "rotate {:target :copy-root, :angle 45}\n rotate {:target :main-root, :angle 30}\n change-height {:target :main-instance, :value 80}", :states ["8208735a98e4c105" "f9a383ec6e3b0bb3" "7e9afa9fd32338bd" "15ad444e53bca81b"]}
|
||||
{:transcript "rotate {:target :copy-root, :angle 45}\n one-of -> skip\n change-property {:target :main-instance, :property :fills, :value \"#ff0000\"}", :states ["8208735a98e4c105" "aa9f6c1b6a87ac0f" "38265afaa05640e8"]}
|
||||
{:transcript "rotate {:target :copy-root, :angle 45}\n one-of -> skip\n change-height {:target :main-instance, :value 80}", :states ["8208735a98e4c105" "e92b0483129edb9c" "afd213908fee2f38"]}
|
||||
{:transcript "one-of -> skip\n rotate {:target :main-root, :angle 30}\n change-property {:target :main-instance, :property :fills, :value \"#ff0000\"}", :states ["ceecd80f347920c9" "f5c326161b425dca" "049a41b4774ab16d"]}
|
||||
{:transcript "one-of -> skip\n rotate {:target :main-root, :angle 30}\n change-height {:target :main-instance, :value 80}", :states ["ceecd80f347920c9" "b23260b0f15be83b" "65e4a3e632ab0e48"]}
|
||||
[{:transcript "rotate {:target :copy-root, :angle 45}\n rotate {:target :main-root, :angle 30}\n change-property {:target :main-instance, :property :fills, :value \"#ff0000\"}", :states ["8208735a98e4c105" "176aa8aafb47dea2" "3ae38d688dd976ee" "7b321770b5da7e13"]}
|
||||
{:transcript "rotate {:target :copy-root, :angle 45}\n rotate {:target :main-root, :angle 30}\n change-height {:target :main-instance, :value 80}", :states ["8208735a98e4c105" "176aa8aafb47dea2" "3297f52b31a7440b" "3083c3b3c5d0c276"]}
|
||||
{:transcript "rotate {:target :copy-root, :angle 45}\n one-of -> skip\n change-property {:target :main-instance, :property :fills, :value \"#ff0000\"}", :states ["8208735a98e4c105" "7c17bc5eec6f809f" "7fefd009f1c76716"]}
|
||||
{:transcript "rotate {:target :copy-root, :angle 45}\n one-of -> skip\n change-height {:target :main-instance, :value 80}", :states ["8208735a98e4c105" "50a68a02a5ab9a00" "ad4f7795e41b1d63"]}
|
||||
{:transcript "one-of -> skip\n rotate {:target :main-root, :angle 30}\n change-property {:target :main-instance, :property :fills, :value \"#ff0000\"}", :states ["144339de3f79f0c9" "dfbdf08b9dabae5a" "f1bd4da0fd31db22"]}
|
||||
{:transcript "one-of -> skip\n rotate {:target :main-root, :angle 30}\n change-height {:target :main-instance, :value 80}", :states ["144339de3f79f0c9" "3afe54402183c41f" "1b64e8013665d73a"]}
|
||||
{:transcript "one-of -> skip\n one-of -> skip\n change-property {:target :main-instance, :property :fills, :value \"#ff0000\"}", :states ["17b5ce28aeffa62e" "8f31b06c3ab1921b"]}
|
||||
{:transcript "one-of -> skip\n one-of -> skip\n change-height {:target :main-instance, :value 80}", :states ["928074db7743f484" "d54aee2c77882202"]}]
|
||||
{:transcript "one-of -> skip\n one-of -> skip\n change-height {:target :main-instance, :value 80}", :states ["c30da30e06aa190f" "4bdc1cd2f25762e2"]}]
|
||||
:o
|
||||
[{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-variant-container {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n make-nested-component-with-variant {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n switch-variant {:target-component sync-vset-v1-component}", :states ["9a1a3735f1009290" "b00ea3774a618f8e" "d15895a5c5a7e993"]}
|
||||
{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-variant-container {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n make-nested-component-with-variant {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n switch-variant {:target-component sync-vset-v1-component}", :states ["1247c1fd53a5de3f" "45d0fe0a073fbada" "9a8e3d09e48af9fe"]}]
|
||||
@ -173,7 +173,7 @@
|
||||
{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-nested-component {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n make-nested-component {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-1}\n change-property {:target #fn, :property :fills, :value \"#0000ff\"}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n update-main {:target #fn, :updated sync-main-copyhead-0}", :states ["dd907ef11d9e4851" "481d62dd7e471206" "046525ebd0ffe008" "682e0ba7926cc177"]}
|
||||
{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-nested-component {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n make-nested-component {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-1}\n one-of -> skip\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n update-main {:target #fn, :updated sync-main-copyhead-0}", :states ["af30a8074415ea47" "0292c4761cadebad" "8c3b12b00c20dd24"]}]
|
||||
:rotation
|
||||
[{:transcript "rotate {:target :copy-root, :angle 30}\n change-height {:target :copy-instance, :value 60}\n test\n rotate {:target :main-root, :angle 40}", :states ["f54075611f2456da" "dcfc7d5c6f4bec2a" "1f948e0492586197" "46492bbe943d1366"]}]
|
||||
[{:transcript "rotate {:target :copy-root, :angle 30}\n change-height {:target :copy-instance, :value 60}\n test\n rotate {:target :main-root, :angle 40}", :states ["d12dd9fffaf38df9" "54f0852878f4edfa" "8759a8056147e49e" "3680cabdfe765e60"]}]
|
||||
:s
|
||||
[{:transcript "change-property {:target :copy-instance, :property :fills, :value \"#00ff00\"}\n change-property {:target :main-instance, :property :fills, :value \"#ff0000\"}\n delete-component {:target :main-root, :component-id component1}\n test\n restore-component {:component-id component1}\n change-property {:target :main-instance, :property :fills, :value \"#0000ff\"}", :states ["93c77f92c889307b" "0c2ac66ca5452745" "11bd55106f98bebc" "6a0d75c08f6b08b8" "bccb7c6434c8de28" "9da4088c9b6c2b45"]}
|
||||
{:transcript "one-of -> skip\n change-property {:target :main-instance, :property :fills, :value \"#ff0000\"}\n delete-component {:target :main-root, :component-id component1}\n test\n restore-component {:component-id component1}\n change-property {:target :main-instance, :property :fills, :value \"#0000ff\"}", :states ["8c5be47002e73694" "323f1f1ed8b35e4d" "eb7c91cf5e08a6c3" "86c4d8c4352a04db" "ddbdea68968e3988"]}]
|
||||
@ -185,12 +185,12 @@
|
||||
{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-nested-component {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n make-nested-component {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n duplicate {:target #fn, :new-head 8}\n change-property {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["083c91e86a50fc3d" "f5f413ad5bea79a4" "0dba6a2c453b5250" "9857e951ca902581"]}
|
||||
{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-nested-component {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n make-nested-component {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n one-of -> skip\n duplicate {:target #fn, :new-head 8}\n change-property {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["ba24e834d0767879" "e97c69b1e46ffe5d" "ec75501d3a176eef"]}]
|
||||
:u
|
||||
[{:transcript "create-component {:component \"outer\", :id sync-outer-component}\n create-component {:component \"inner\", :id sync-inner-component}\n instantiate-copy {:component \"outer\", :copy sync-outer-copyhead-0}\n instantiate-copy {:component \"inner\", :copy sync-inner-copyhead-0}\n nest-copy {:copy #fn, :into #fn, :cell nil}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n change-property {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["787b17b227cfdb85" "f6490ae9fe96d3e4" "bd40aa51b1ec2fd1" "53c3ace2c3feb6d6"]}
|
||||
{:transcript "create-component {:component \"outer\", :id sync-outer-component}\n create-component {:component \"inner\", :id sync-inner-component}\n instantiate-copy {:component \"outer\", :copy sync-outer-copyhead-0}\n instantiate-copy {:component \"inner\", :copy sync-inner-copyhead-0}\n nest-copy {:copy #fn, :into #fn, :cell nil}\n one-of -> skip\n change-property {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["787b17b227cfdb85" "e662ae31e1675fa9" "435dd5416b94f48f"]}]
|
||||
[{:transcript "create-component {:component \"outer\", :id sync-outer-component}\n create-component {:component \"inner\", :id sync-inner-component}\n instantiate-copy {:component \"outer\", :copy sync-outer-copyhead-0}\n instantiate-copy {:component \"inner\", :copy sync-inner-copyhead-0}\n nest-copy {:copy #fn, :into #fn, :cell nil}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n change-property {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["83fec2239ffc4df8" "2bf9ec1fdeaa05ed" "bd40aa51b1ec2fd1" "53c3ace2c3feb6d6"]}
|
||||
{:transcript "create-component {:component \"outer\", :id sync-outer-component}\n create-component {:component \"inner\", :id sync-inner-component}\n instantiate-copy {:component \"outer\", :copy sync-outer-copyhead-0}\n instantiate-copy {:component \"inner\", :copy sync-inner-copyhead-0}\n nest-copy {:copy #fn, :into #fn, :cell nil}\n one-of -> skip\n change-property {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["83fec2239ffc4df8" "e662ae31e1675fa9" "435dd5416b94f48f"]}]
|
||||
:v
|
||||
[{:transcript "change-property {:target :main-instance, :property :fills, :value \"#ff0000\"}\n undo {:undone 2}\n change-property {:target :main-instance, :property :fills, :value \"#00ff00\"}\n undo {:undone 2}\n redo {:redone 2}\n redo {:redone 0}", :states ["17b5ce28aeffa62e" "e60c9f0fd46b2310" "a30b6f606aaa5f66" "e60c9f0fd46b2310" "a30b6f606aaa5f66" "a30b6f606aaa5f66" "0ba2151cc54b42fa"]}]
|
||||
:variant-switch-into-copies
|
||||
[{:transcript "variant-switch-into-copies", :states ["6cdf94ad6bd691c5"]}]
|
||||
[{:transcript "variant-switch-into-copies", :states ["540f8ef5f8ad96ea"]}]
|
||||
:w
|
||||
[{:transcript "create-component {:component \"main\", :id sync-main-component}\n one-of -> skip\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n change-property {:target #fn, :property :fills, :value \"#0000ff\"}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n change-property {:target #fn, :property :fills, :value \"#aaaaaa\"}\n undo {:undone 5}", :states ["f06eb554db2a667d" "906c1b936c948e9c" "8e29f79b473c1a0b" "0072b33980dae904" "bd57e8070d829bdf"]}
|
||||
{:transcript "create-component {:component \"main\", :id sync-main-component}\n make-nested-component {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n instantiate-copy {:component \"main\", :copy sync-main-copyhead-0}\n change-property {:target #fn, :property :fills, :value \"#0000ff\"}\n change-property {:target #fn, :property :fills, :value \"#00ff00\"}\n change-property {:target #fn, :property :fills, :value \"#aaaaaa\"}\n undo {:undone 5}", :states ["1de51816cdc0ad11" "ed2117b3a6ae1dd6" "c90876e1b44d00fb" "a5b1e4b00086c891" "f09bed0fa67d711c"]}
|
||||
|
||||
@ -22,6 +22,143 @@
|
||||
(def source-world
|
||||
[2 1 {:library true :stale-libraries true :library-text true :text true :text-styles true}])
|
||||
|
||||
(def dependency-text-world
|
||||
[2 0 {:library true :stale-libraries true :library-dependency true :library-text true}])
|
||||
|
||||
(t/deftest dependency-text-fixture-links-source-through-the-dependent-main
|
||||
(let [situation (cg/world dependency-text-world)
|
||||
{:keys [source-id dependent-id source-text-id dependent-head-id dependent-text-id
|
||||
consumer-root-ids consumer-text-ids direct-text-ids]}
|
||||
(cg/get-library-text-chain situation)
|
||||
dependent (get (tm/aux-files situation) dependent-id)
|
||||
head (tm/shape-by-id (tm/with-file situation dependent) dependent-head-id)
|
||||
text (tm/shape-by-id (tm/with-file situation dependent) dependent-text-id)
|
||||
main (ths/get-shape dependent :sync-library-dependent-head)
|
||||
ids (map (comp :id :shape) (cg/forest situation))]
|
||||
(t/is (some? head))
|
||||
(t/is (= source-id (:component-file head)))
|
||||
(t/is (some #{dependent-head-id} (:shapes main)))
|
||||
(t/is (= source-text-id (:shape-ref text)))
|
||||
(t/is (= 2 (count consumer-root-ids)))
|
||||
(t/is (= 2 (count consumer-text-ids)))
|
||||
(t/is (= 2 (count direct-text-ids)))
|
||||
(t/is (not-any? (set direct-text-ids) consumer-text-ids))
|
||||
(t/is (= (count ids) (count (set ids))))))
|
||||
|
||||
(defn- get-text
|
||||
[state file-id shape-id]
|
||||
(let [situation (:situation state)
|
||||
file (get (cf/all-files situation) file-id)]
|
||||
(thtx/view (:content (tm/shape-by-id (tm/with-file situation file) shape-id)))))
|
||||
|
||||
(defn- get-history-depth
|
||||
[state file-id]
|
||||
(count (get-in state [:situation :library-histories file-id :undo])))
|
||||
|
||||
(t/deftest transitive-text-waits-for-both-library-acceptances
|
||||
(doseq [tuple (into [[:library-text 0 0 1]]
|
||||
(map #(vector :library-text-style 0 % 1) (range 12)))]
|
||||
(t/testing (str tuple)
|
||||
(let [initial (cg/initial-state dependency-text-world)
|
||||
situation (:situation initial)
|
||||
{:keys [source-id dependent-id source-text-id dependent-text-id
|
||||
consumer-text-ids direct-text-ids]} (cg/get-library-text-chain situation)
|
||||
current-id (:id (tm/file situation))
|
||||
expected (thtx/normalize (:value (:op (cg/resolve-op situation {} tuple))))
|
||||
original (get-text initial source-id source-text-id)
|
||||
edited (-> initial (cg/step tuple) cg/settle-state)
|
||||
early-accept (-> edited (cg/step [:library-sync 0]) cg/settle-state)
|
||||
upstream (-> early-accept (cg/step [:library-accept 0]) cg/settle-state)
|
||||
accepted (-> upstream (cg/step [:library-sync 0]) cg/settle-state)]
|
||||
(t/is (not= original expected) "the requested source edit changes text")
|
||||
(t/is (= expected (get-text edited source-id source-text-id)))
|
||||
(t/is (= (dissoc (oracle/snapshot situation) source-id)
|
||||
(dissoc (oracle/snapshot (:situation edited)) source-id))
|
||||
"a source edit changes neither dependent nor consumer files")
|
||||
(t/is (= (oracle/snapshot (:situation edited))
|
||||
(oracle/snapshot (:situation early-accept)))
|
||||
"accepting a still-stale dependent cannot pull the upstream text")
|
||||
(t/is (zero? (r/undo-depth (:situation early-accept))))
|
||||
(t/is (= original (get-text early-accept dependent-id dependent-text-id)))
|
||||
(t/is (= expected (get-text upstream dependent-id dependent-text-id)))
|
||||
(t/is (= (dissoc (oracle/snapshot (:situation early-accept)) dependent-id)
|
||||
(dissoc (oracle/snapshot (:situation upstream)) dependent-id))
|
||||
"upstream acceptance changes only the dependent editor's file")
|
||||
(t/is (= (repeat 2 original) (map #(get-text upstream current-id %) consumer-text-ids)))
|
||||
(t/is (zero? (r/undo-depth (:situation upstream))))
|
||||
(t/is (= 1 (get-history-depth upstream source-id)))
|
||||
(t/is (= 1 (get-history-depth upstream dependent-id)))
|
||||
(t/is (= (repeat 2 expected) (map #(get-text accepted current-id %) consumer-text-ids)))
|
||||
(t/is (= (repeat 2 original) (map #(get-text accepted current-id %) direct-text-ids))
|
||||
"accepting the dependent does not accept direct source copies")
|
||||
(t/is (= (dissoc (oracle/snapshot (:situation upstream)) current-id)
|
||||
(dissoc (oracle/snapshot (:situation accepted)) current-id)))
|
||||
(t/is (= 1 (r/undo-depth (:situation accepted))))
|
||||
(t/is (map? (cg/run {:world dependency-text-world
|
||||
:ops [tuple [:library-sync 0] [:library-accept 0] [:library-sync 0]
|
||||
[:undo] [:redo] [:library-undo 1] [:library-redo 1]
|
||||
[:library-undo 0] [:library-redo 0]]})))))))
|
||||
|
||||
(t/deftest transitive-text-editors-undo-only-their-own-files
|
||||
(let [initial (cg/initial-state dependency-text-world)
|
||||
{:keys [source-id dependent-id]} (cg/get-library-text-chain (:situation initial))
|
||||
accepted (-> initial (cg/step [:library-text-style 0 2 1]) cg/settle-state
|
||||
(cg/step [:library-accept 0]) cg/settle-state
|
||||
(cg/step [:library-sync 0]) cg/settle-state)
|
||||
current-id (:id (tm/file (:situation accepted)))
|
||||
before (oracle/snapshot (:situation accepted))]
|
||||
(doseq [[owner undo redo] [[current-id [:undo] [:redo]]
|
||||
[source-id [:library-undo 1] [:library-redo 1]]
|
||||
[dependent-id [:library-undo 0] [:library-redo 0]]]]
|
||||
(t/testing (str owner)
|
||||
(let [undone (-> accepted (cg/step undo) cg/settle-state)
|
||||
redone (-> undone (cg/step redo) cg/settle-state)
|
||||
after (oracle/snapshot (:situation undone))]
|
||||
(t/is (not= (get before owner) (get after owner)))
|
||||
(t/is (= (dissoc before owner) (dissoc after owner)))
|
||||
(t/is (= before (oracle/snapshot (:situation redone)))))))))
|
||||
|
||||
(defn- get-invariant
|
||||
[situation model]
|
||||
(try (oracle/check situation model) nil
|
||||
(catch #?(:clj Exception :cljs js/Error) error
|
||||
(:invariant (ex-data error)))))
|
||||
|
||||
(t/deftest transitive-text-checks-reject-premature-reference-advancement-and-corrupt-results
|
||||
(let [initial (cg/initial-state dependency-text-world)
|
||||
{:keys [source-id dependent-id source-text-id dependent-head-id dependent-text-id
|
||||
consumer-root-ids consumer-text-ids direct-text-ids]}
|
||||
(cg/get-library-text-chain (:situation initial))
|
||||
current-id (:id (tm/file (:situation initial)))
|
||||
original (:content (tm/shape-by-id (tm/with-file (:situation initial)
|
||||
(get (cf/all-files (:situation initial)) source-id))
|
||||
source-text-id))
|
||||
edited (-> initial (cg/step [:library-text-style 0 2 1]) cg/settle-state)
|
||||
upstream (-> edited (cg/step [:library-accept 0]) cg/settle-state)
|
||||
accepted (-> upstream (cg/step [:library-sync 0]) cg/settle-state)
|
||||
new-content (:content (tm/shape-by-id (tm/with-file (:situation edited)
|
||||
(get (cf/all-files (:situation edited)) source-id))
|
||||
source-text-id))]
|
||||
(doseq [[state owner root] [[edited dependent-id dependent-head-id]
|
||||
[upstream current-id (first consumer-root-ids)]]]
|
||||
(let [situation (:situation state)
|
||||
advanced (cf/remember-subtree situation owner root (cf/all-files situation))]
|
||||
(t/is (= :I4 (get-invariant advanced (:model state)))
|
||||
"a newer reference cannot explain away a stale copy")))
|
||||
(doseq [[owner id content] (concat [[dependent-id dependent-text-id original]]
|
||||
(map #(vector current-id % original) consumer-text-ids)
|
||||
(map #(vector current-id % new-content) direct-text-ids))]
|
||||
(let [situation (:situation accepted)
|
||||
files (cf/all-files situation)
|
||||
file (get files owner)
|
||||
path [:data :pages-index (thf/current-page-id file) :objects id :content]
|
||||
corrupted (assoc-in file path content)
|
||||
situation (if (= owner current-id)
|
||||
(tm/with-file situation corrupted)
|
||||
(tm/with-aux-files situation (assoc (tm/aux-files situation) owner corrupted)))]
|
||||
(t/is (= :I4 (get-invariant situation (:model accepted)))
|
||||
"dropped propagation and premature direct acceptance both fail")))))
|
||||
|
||||
(t/deftest a-transform-does-not-accept-pending-library-content-or-structure
|
||||
(doseq [[edit index] [[[:library-text 0 1 1] 8]
|
||||
[[:library-text 0 0 1] 8]
|
||||
@ -47,6 +184,14 @@
|
||||
:ops [[:library-remove-child 0 0 0 0] [:library-transform 0 4 4 1]
|
||||
[:library-transform 0 4 4 0] [:library-undo] [:library-redo]]}))))
|
||||
|
||||
(t/deftest a-consumer-move-of-a-library-copy-does-not-sync-the-library
|
||||
;; The swap moves a copy of a library component in the working file only.
|
||||
(t/is (map? (cg/run {:world [2 0 {:library true :stale-libraries true
|
||||
:library-dependency true :library-text true}]
|
||||
:ops [[:library-delete 0 0 0 0] [:library-delete 3] [:library-sync]
|
||||
[:library-restore 3] [:library-sync] [:library-transform 0 3 4 0]
|
||||
[:swap 16 0 0 0]]}))))
|
||||
|
||||
(t/deftest source-transforms-keep-consumers-stale-until-acceptance
|
||||
(doseq [action (range 6) scope [0 1]]
|
||||
(let [initial (cg/initial-state source-world)
|
||||
@ -78,6 +223,9 @@
|
||||
(let [edited (-> initial (cg/step tuple) cg/settle-state)]
|
||||
(t/is (not= (get (oracle/snapshot situation) owner)
|
||||
(get (oracle/snapshot (:situation edited)) owner)))
|
||||
(t/is (not= (thtx/view (:content (:shape resolved)))
|
||||
(thtx/normalize (:value (:op resolved))))
|
||||
(str "meaningful source text action " tuple))
|
||||
(t/is (= (dissoc (oracle/snapshot situation) owner)
|
||||
(dissoc (oracle/snapshot (:situation edited)) owner)))
|
||||
(t/is (zero? (r/undo-depth (:situation edited))))
|
||||
|
||||
@ -16,6 +16,74 @@
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
(t/deftest setting-a-named-color-replaces-explicit-fills
|
||||
(doseq [fills [nil [] [{:fill-color "#123456" :fill-opacity 0.5}]]]
|
||||
(let [text [[["Library text" {:fills fills :size 18}]]]
|
||||
styled (thtx/restyle text :color :red)]
|
||||
(t/is (= [[["Library text" {:color :red :size 18}]]]
|
||||
(thtx/normalize styled)))
|
||||
(t/is (= [{:fill-color "#FF0000" :fill-opacity 1}]
|
||||
(get-in (thtx/content styled) [:children 0 :children 0 :children 0 :fills]))))))
|
||||
|
||||
(t/deftest setting-explicit-fills-replaces-a-named-color
|
||||
(let [styled (thtx/restyle [[["Library text" {:color :red :size 18}]]] :fills nil)]
|
||||
(t/is (= [[["Library text" {:fills nil :size 18}]]] styled))
|
||||
(t/is (nil? (get-in (thtx/content styled) [:children 0 :children 0 :children 0 :fills])))))
|
||||
|
||||
(defn- get-run
|
||||
[text]
|
||||
(first (txt/node-seq txt/is-text-node? (thtx/content text))))
|
||||
|
||||
(t/deftest font-family-edit-replaces-the-raw-family-identity
|
||||
(let [text (thtx/normalize [[["Custom font" {:family "Roboto" :font-id "custom-font"
|
||||
:weight 700 :font-style "oblique"
|
||||
:font-variant-id "opaque-variant" :size 18 :color :blue}]]])
|
||||
before (get-run text)
|
||||
after (get-run (thtx/restyle text :family "Inter"))]
|
||||
(t/is (= {:font-family "Inter" :font-id "gfont-inter"}
|
||||
(select-keys after [:font-family :font-id])))
|
||||
(t/is (= (select-keys before [:font-weight :font-style :font-variant-id])
|
||||
(select-keys after [:font-weight :font-style :font-variant-id]))
|
||||
"a family edit preserves the weight unit's opaque identity")
|
||||
(t/is (= (select-keys before [:text :font-size :fills])
|
||||
(select-keys after [:text :font-size :fills])))))
|
||||
|
||||
(t/deftest font-weight-edit-replaces-the-raw-variant-identity
|
||||
(let [text (thtx/normalize [[["Custom font" {:family "Roboto" :font-id "custom-font"
|
||||
:font-variant-id "opaque-variant" :italic true
|
||||
:size 18 :color :blue}]]])
|
||||
before (get-run text)
|
||||
after (get-run (thtx/restyle text :weight 700))]
|
||||
(t/is (= {:font-weight "700" :font-style "italic" :font-variant-id "700italic"}
|
||||
(select-keys after [:font-weight :font-style :font-variant-id])))
|
||||
(t/is (= (select-keys before [:font-family :font-id])
|
||||
(select-keys after [:font-family :font-id])))
|
||||
(t/is (= (select-keys before [:text :font-size :fills])
|
||||
(select-keys after [:text :font-size :fills])))))
|
||||
|
||||
(t/deftest font-style-edit-replaces-the-raw-style-and-variant-identities
|
||||
(doseq [[italic style variant] [[true "italic" "700italic"] [false "normal" "700"]]]
|
||||
(let [text (thtx/normalize [[["Custom font" {:family "Roboto" :font-id "custom-font"
|
||||
:weight 700 :font-style "oblique"
|
||||
:font-variant-id "opaque-variant" :size 18 :color :blue}]]])
|
||||
before (get-run text)
|
||||
after (get-run (thtx/restyle text :italic italic))]
|
||||
(t/is (= {:font-weight "700" :font-style style :font-variant-id variant}
|
||||
(select-keys after [:font-weight :font-style :font-variant-id])))
|
||||
(t/is (= (select-keys before [:font-family :font-id])
|
||||
(select-keys after [:font-family :font-id])))
|
||||
(t/is (= (select-keys before [:text :font-size :fills])
|
||||
(select-keys after [:text :font-size :fills]))))))
|
||||
|
||||
(t/deftest other-text-edits-keep-opaque-font-identities
|
||||
(let [text (thtx/normalize [[["Custom font" {:family "Roboto" :font-id "custom-font"
|
||||
:weight 700 :font-style "oblique"
|
||||
:font-variant-id "opaque-variant" :size 18 :color :blue}]]])
|
||||
before (get-run text)
|
||||
after (get-run (thtx/restyle text :size 24))]
|
||||
(t/is (= "24" (:font-size after)))
|
||||
(t/is (= (dissoc before :font-size) (dissoc after :font-size)))))
|
||||
|
||||
(t/deftest content-is-written-as-the-editors-write-it
|
||||
(let [content (thtx/content [[["Price: "] ["$10" {:weight 700 :color :red}]]])
|
||||
paragraph (first (txt/node-seq txt/is-paragraph-node? content))
|
||||
|
||||
@ -15,6 +15,25 @@
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
(t/deftest absent-and-nil-typography-fields-do-not-author-a-reference
|
||||
(let [base (thtx/content [[["Hello world"]]])
|
||||
path [:children 0 :children 0 :children 0]
|
||||
id (thi/new-id! :typography)
|
||||
file (thi/new-id! :file)
|
||||
refs {:typography-ref-id id :typography-ref-file file}]
|
||||
(doseq [[left right expected]
|
||||
[[{} {:typography-ref-id nil :typography-ref-file nil} #{}]
|
||||
[{:typography-ref-id nil :typography-ref-file nil} {} #{}]
|
||||
[refs {} #{:typography}]
|
||||
[refs (assoc refs :typography-ref-id (thi/new-id! :other-typography)) #{:typography}]
|
||||
[refs (assoc refs :typography-ref-file (thi/new-id! :other-file)) #{:typography}]]]
|
||||
(let [clear #(dissoc % :typography-ref-id :typography-ref-file)
|
||||
main (update-in base path #(merge (clear %) left))
|
||||
copy (update-in base path #(merge (clear %) right))]
|
||||
(t/is (= expected (thtx/override-units main copy)))
|
||||
(t/is (= (if (seq expected) #{:text-content-typography} #{})
|
||||
(txt/override-groups main copy)))))))
|
||||
|
||||
(defn- overrides
|
||||
"The overrides of `copy` against `main` by the reference rule, checked
|
||||
against the production one (`txt/override-groups`)."
|
||||
@ -61,6 +80,12 @@
|
||||
:line-height [[{:line-height 1.5} ["Hello world"]]]
|
||||
:valign [{:valign "bottom"} [["Hello world"]]]}]
|
||||
(t/is (= #{unit} (overrides [[["Hello world"]]] copy)) (str unit))))
|
||||
(t/testing "a family change keeps the weight though the family names its variants otherwise"
|
||||
(let [main [[["Hello world" {:weight 700}]]]
|
||||
copy [[["Hello world" {:family "Roboto" :weight 700}]]]]
|
||||
(t/is (not= (get-in (thtx/content main) [:children 0 :children 0 :children 0 :font-variant-id])
|
||||
(get-in (thtx/content copy) [:children 0 :children 0 :children 0 :font-variant-id])))
|
||||
(t/is (= #{:family} (overrides main copy)))))
|
||||
(t/testing "a typography sets each unit it changes, and its reference"
|
||||
(thi/new-id! :file1)
|
||||
(thi/new-id! :heading)
|
||||
|
||||
@ -75,6 +75,8 @@
|
||||
[common-tests.logic.comp-sync-layout-items-test]
|
||||
[common-tests.logic.comp-sync-test]
|
||||
[common-tests.logic.comp-touched-test]
|
||||
[common-tests.logic.composable-gen-test]
|
||||
[common-tests.logic.composable-oracle-test]
|
||||
[common-tests.logic.composable-runner-test]
|
||||
[common-tests.logic.composable-sync-test]
|
||||
[common-tests.logic.copying-and-duplicating-test]
|
||||
@ -208,10 +210,13 @@
|
||||
'common-tests.logic.comp-flex-interactions-test
|
||||
'common-tests.logic.comp-main-edit-breaks-copy-slots-test
|
||||
'common-tests.logic.comp-move-swapped-copies-test
|
||||
'common-tests.logic.comp-remote-synced-test
|
||||
'common-tests.logic.comp-reset-test
|
||||
'common-tests.logic.comp-sync-layout-items-test
|
||||
'common-tests.logic.comp-sync-test
|
||||
'common-tests.logic.comp-touched-test
|
||||
'common-tests.logic.composable-gen-test
|
||||
'common-tests.logic.composable-oracle-test
|
||||
'common-tests.logic.composable-runner-test
|
||||
'common-tests.logic.composable-sync-test
|
||||
'common-tests.logic.copying-and-duplicating-test
|
||||
@ -248,6 +253,7 @@
|
||||
'common-tests.path-names-tree-test
|
||||
'common-tests.record-test
|
||||
'common-tests.schema-test
|
||||
'common-tests.schema-check-test
|
||||
'common-tests.spec-test
|
||||
'common-tests.svg-path-test
|
||||
'common-tests.svg-test
|
||||
|
||||
@ -58,6 +58,7 @@
|
||||
[app.main.features :as features]
|
||||
[app.main.features.pointer-map :as fpmap]
|
||||
[app.main.fonts :as fonts]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.repo :as rp]
|
||||
[app.main.router :as rt]
|
||||
[app.main.store :as st]
|
||||
|
||||
@ -286,24 +286,26 @@
|
||||
|
||||
(defn transform-in-variant
|
||||
"Given the id of a main shape of a component, creates a variant structure for
|
||||
that component, with a second member (`clv/generate-transform-in-variant`)."
|
||||
[main-instance-id]
|
||||
(ptk/reify ::transform-in-variant
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [variant-id (uuid/next)
|
||||
new-shape-id (uuid/next)
|
||||
changes (-> (variant-changes it state)
|
||||
(clv/generate-transform-in-variant main-instance-id variant-id
|
||||
{:layout? true
|
||||
:new-component-id (uuid/next)
|
||||
:new-shape-id new-shape-id}))]
|
||||
(rx/concat
|
||||
(rx/of (dch/commit-changes changes)
|
||||
(ptk/data-event :layout/update {:ids [variant-id]})
|
||||
(dws/select-shape new-shape-id))
|
||||
(->> (rx/of (focus-property variant-id))
|
||||
(rx/delay 250)))))))
|
||||
that component, with a second member (`clv/generate-transform-in-variant`).
|
||||
The variant set takes `variant-id`, or a new id."
|
||||
([main-instance-id]
|
||||
(transform-in-variant main-instance-id (uuid/next)))
|
||||
([main-instance-id variant-id]
|
||||
(ptk/reify ::transform-in-variant
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [new-shape-id (uuid/next)
|
||||
changes (-> (variant-changes it state)
|
||||
(clv/generate-transform-in-variant main-instance-id variant-id
|
||||
{:layout? true
|
||||
:new-component-id (uuid/next)
|
||||
:new-shape-id new-shape-id}))]
|
||||
(rx/concat
|
||||
(rx/of (dch/commit-changes changes)
|
||||
(ptk/data-event :layout/update {:ids [variant-id]})
|
||||
(dws/select-shape new-shape-id))
|
||||
(->> (rx/of (focus-property variant-id))
|
||||
(rx/delay 250))))))))
|
||||
|
||||
(defn add-component-or-variant
|
||||
"Manage the shared shortcut, and do the pertinent action"
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
[app.common.logic.shapes :as cls]
|
||||
[app.common.math :as mth]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.composable.comp.files :as cf]
|
||||
[app.common.test-helpers.composable.comp.nodes :as n]
|
||||
[app.common.test-helpers.composable.comp.runner :as r]
|
||||
[app.common.test-helpers.composable.comp.setups :as setup]
|
||||
@ -158,7 +159,8 @@
|
||||
(t/is (= :settled (await (ftm/await-step [(dwsl/update-layout-child [child-id] {:layout-item-absolute true})]))))
|
||||
(let [after (ftm/snapshot)
|
||||
file (ftm/current-file)]
|
||||
(t/is (= #{:layout-item-absolute} (:touched (ths/get-shape-by-id file child-id))))
|
||||
;; out of the flow it keeps the place the layout gave it
|
||||
(t/is (= #{:layout-item-absolute :geometry-group} (:touched (ths/get-shape-by-id file child-id))))
|
||||
(t/is (empty? (:touched (ths/get-shape-by-id file copy-id))))
|
||||
(t/is (nil? (get-cell (ths/get-shape-by-id file copy-id) child-id)))
|
||||
(t/is (= :settled (await (ftm/await-step [dwu/undo]))))
|
||||
@ -215,6 +217,57 @@
|
||||
(t/is (= :settled (await (ftm/await-step [dwu/redo]))))
|
||||
(t/is (uc/same-state? after (ftm/snapshot)) (str "one redo restores " mode)))))))))
|
||||
|
||||
(t/deftest ^:async capped-history-keeps-a-primary-and-layout-entry-together
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(let [initial (ftm/start-generated (cg/world [1 0 {:layout :flex :layout-children true}]))
|
||||
filled (loop [situation initial index 0]
|
||||
(if (< index (dec dwu/MAX-UNDO-SIZE))
|
||||
(recur (await (ftm/run-generated-step
|
||||
situation
|
||||
(n/change-property :sync-random-0-copyhead-0 :opacity
|
||||
(if (even? index) 0.4 0.7))))
|
||||
(inc index))
|
||||
situation))
|
||||
capped (await (ftm/run-generated-step filled (n/remove-child :random-0-layout-item-1)))
|
||||
before (ftm/snapshot)
|
||||
checked (await (ftm/finish-generated capped))]
|
||||
(t/is (empty? (uc/failures filled)))
|
||||
(t/is (= dwu/MAX-UNDO-SIZE (count (get-in @st/state [:workspace-undo :items]))))
|
||||
(t/is (empty? (uc/failures capped)))
|
||||
(t/is (empty? (uc/failures checked)))
|
||||
(t/is (uc/same-state? before (ftm/snapshot)))))))
|
||||
|
||||
(t/deftest ^:async capped-history-keeps-checking-steps-and-rejects-missing-undo
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(let [initial (ftm/start-generated (setup/simple-component-with-labeled-copy))
|
||||
filled (loop [situation initial index 0]
|
||||
(if (< index dwu/MAX-UNDO-SIZE)
|
||||
(let [next (await (ftm/run-generated-step situation
|
||||
(n/change-property :copy-root :opacity
|
||||
(if (even? index) 0.4 0.7))))]
|
||||
(t/is (empty? (uc/failures next)))
|
||||
(recur next (inc index)))
|
||||
situation))
|
||||
capped (await (ftm/run-generated-step filled (n/detach :copy-root)))
|
||||
before (ftm/snapshot)
|
||||
checked (await (ftm/finish-generated capped))]
|
||||
(t/is (= dwu/MAX-UNDO-SIZE (count (get-in @st/state [:workspace-undo :items]))))
|
||||
(t/is (empty? (uc/failures capped)))
|
||||
(t/is (empty? (uc/failures checked)))
|
||||
(t/is (uc/same-state? before (ftm/snapshot)))
|
||||
(let [update-shapes dwsh/update-shapes
|
||||
missing (await
|
||||
(mock/with-mocks*
|
||||
{dwsh/update-shapes (mock/stub
|
||||
(fn [ids update-fn & [options]]
|
||||
(update-shapes ids update-fn (assoc options :save-undo? false))))}
|
||||
(await (ftm/run-generated-step checked (n/change-property :copy-root :opacity 0.2)))))]
|
||||
(t/is (= 0.2 (:opacity (ths/get-shape (ftm/current-file) :copy-root))))
|
||||
(t/is (= :no-undo-entry (:phase (peek (uc/failures missing)))))
|
||||
(t/is (= (inc (count (uc/failures checked))) (count (uc/failures missing)))))))))
|
||||
|
||||
(t/deftest ^:async swapping-growing-text-undoes-with-the-component-choice
|
||||
(let [features (:features @st/state)]
|
||||
(thw/setup-wasm-mocks!)
|
||||
@ -409,6 +462,14 @@
|
||||
(thw/teardown-wasm-mocks!)
|
||||
(st/emit! #(assoc % :features features)))))))
|
||||
|
||||
(t/deftest ^:async rotation-nodes-compose-successive-turns
|
||||
(let [initial (ftm/start-generated (setup/simple-component-with-labeled-copy))
|
||||
first-turn (await (ftm/run-generated-step initial (n/rotate :copy-root 45)))
|
||||
second-turn (await (ftm/run-generated-step first-turn (n/rotate :copy-root 90)))
|
||||
shape (ths/get-shape (ftm/current-file) :copy-root)]
|
||||
(t/is (mth/close? 135 (:rotation shape) 0.01))
|
||||
(t/is (empty? (uc/failures second-turn)))))
|
||||
|
||||
(t/deftest ^:async hiding-a-grid-main-child-then-moving-its-main-stays-synced
|
||||
(loop [live (ftm/start-generated (cg/world [2 1 {:text true :text-styles true :layout :grid}]))
|
||||
tuples [[:style 3 1 3 0] [:transform 0 0 0 0]]]
|
||||
@ -556,7 +617,8 @@
|
||||
[tuple transform-tuple]
|
||||
(let [initial (cg/initial-state [2 1 {:library true :stale-libraries true :library-text true}])
|
||||
situation (:situation initial)
|
||||
owner (:library-id (cg/resolve-op situation {} tuple))
|
||||
resolved (cg/resolve-op situation {} tuple)
|
||||
owner (:library-id resolved)
|
||||
transform-tuple (when transform-tuple
|
||||
(assoc transform-tuple 1
|
||||
(first (keep-indexed
|
||||
@ -574,6 +636,10 @@
|
||||
current-id (:id (tm/file situation))
|
||||
before (get-in (ftm/snapshot) [:files current-id])]
|
||||
(t/is (seq changes) (str "source edit changes " tuple))
|
||||
(when (#{:library-text :library-text-style} (first tuple))
|
||||
(t/is (not= (thtx/view (:content (:shape resolved)))
|
||||
(thtx/normalize (:value (:op resolved))))
|
||||
(str "meaningful source text action " tuple)))
|
||||
(t/is (= :settled (await (ftm/await-step [(dwl/ext-library-changed owner (ct/now) 1 changes)]))))
|
||||
(t/is (= before (get-in (ftm/snapshot) [:files current-id])) "notification keeps consumer copies stale")
|
||||
(t/is (empty? (get-in @st/state [:workspace-undo :items])) "notification creates no consumer history")
|
||||
@ -621,6 +687,91 @@
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(await (source-acceptance-history [:library-text 0 1 1] [:transform 8 3 3 4])))))
|
||||
|
||||
(defn- get-editor-situation
|
||||
[situation owner]
|
||||
(let [files (cf/all-files situation)]
|
||||
(-> situation
|
||||
(tm/with-file (get files owner))
|
||||
(tm/with-aux-files (dissoc files owner)))))
|
||||
|
||||
(defn- get-live-text
|
||||
[owner shape-id]
|
||||
(thtx/view (:content (tm/shape-by-id (tm/make-situation (get-in @st/state [:files owner])) shape-id))))
|
||||
|
||||
(defn- ^:async transitive-text-acceptance-history
|
||||
[tuple]
|
||||
(let [initial (cg/initial-state [2 0 {:library true :stale-libraries true
|
||||
:library-dependency true :library-text true}])
|
||||
situation (:situation initial)
|
||||
{:keys [source-id dependent-id source-text-id dependent-text-id
|
||||
consumer-text-ids direct-text-ids]} (cg/get-library-text-chain situation)
|
||||
current-id (:id (tm/file situation))
|
||||
source (get (tm/aux-files situation) source-id)
|
||||
original (thtx/view (:content (tm/shape-by-id (tm/make-situation source) source-text-id)))
|
||||
expected (thtx/normalize (:value (:op (cg/resolve-op situation {} tuple))))
|
||||
edited (-> initial (cg/step tuple) cg/settle-state)
|
||||
source-group (peek (get-in edited [:situation :library-histories source-id :runner ::r/undo-stack]))
|
||||
source-changes (vec (mapcat :redo-changes source-group))
|
||||
upstream (-> edited (cg/step [:library-accept 0]) cg/settle-state)
|
||||
accepted (-> upstream (cg/step [:library-sync 0]) cg/settle-state)
|
||||
dependent-context (get-editor-situation situation dependent-id)
|
||||
_ (ftm/start-generated dependent-context)
|
||||
before-source-notification (ftm/snapshot)]
|
||||
(t/is (not= original expected) (str "meaningful source action " tuple))
|
||||
(t/is (seq source-changes))
|
||||
(t/is (= :settled (await (ftm/await-step [(dwl/ext-library-changed source-id (ct/now) 1 source-changes)]))))
|
||||
(t/is (= (dissoc (:files before-source-notification) source-id)
|
||||
(dissoc (:files (ftm/snapshot)) source-id))
|
||||
"upstream notification changes only the loaded source")
|
||||
(t/is (empty? (get-in @st/state [:workspace-undo :items])))
|
||||
(t/is (= expected (get-live-text source-id source-text-id)))
|
||||
(t/is (= original (get-live-text dependent-id dependent-text-id)))
|
||||
(let [before (ftm/snapshot)]
|
||||
(t/is (= :settled (await (ftm/await-step [(dwl/sync-file dependent-id source-id)]))))
|
||||
(t/is (= expected (get-live-text dependent-id dependent-text-id)))
|
||||
(t/is (= (repeat 2 original) (map #(get-live-text current-id %) consumer-text-ids)))
|
||||
(t/is (= (dissoc (:files before) dependent-id) (dissoc (:files (ftm/snapshot)) dependent-id)))
|
||||
(let [after (ftm/snapshot)
|
||||
actual (ftm/refresh-generated (get-editor-situation (:situation upstream) dependent-id))
|
||||
dependent-changes (:redo-changes (peek (get-in @st/state [:workspace-undo :items])))]
|
||||
(t/is (seq dependent-changes))
|
||||
(t/is (nil? (oracle/check actual (:model upstream))))
|
||||
(t/is (= :settled (await (ftm/await-step [dwu/undo]))))
|
||||
(t/is (uc/same-state? before (ftm/snapshot)) "dependent undo retains the loaded source")
|
||||
(t/is (= :settled (await (ftm/await-step [dwu/redo]))))
|
||||
(t/is (uc/same-state? after (ftm/snapshot)) "dependent redo restores accepted text")
|
||||
;; Install the separate consumer editor with its original stale data.
|
||||
;; Deliver the real dependent acceptance changes as its notification.
|
||||
(ftm/start-generated situation)
|
||||
(let [before-notifications (get-in (ftm/snapshot) [:files current-id])]
|
||||
(t/is (= :settled (await (ftm/await-step [(dwl/ext-library-changed source-id (ct/now) 1 source-changes)]))))
|
||||
(t/is (= :settled (await (ftm/await-step [(dwl/ext-library-changed dependent-id (ct/now) 1 dependent-changes)]))))
|
||||
(t/is (= before-notifications (get-in (ftm/snapshot) [:files current-id])))
|
||||
(t/is (empty? (get-in @st/state [:workspace-undo :items])))
|
||||
(t/is (= expected (get-live-text source-id source-text-id)))
|
||||
(t/is (= expected (get-live-text dependent-id dependent-text-id)))
|
||||
(t/is (= (repeat 2 original) (map #(get-live-text current-id %) consumer-text-ids))))
|
||||
(let [before (ftm/snapshot)]
|
||||
(t/is (= :settled (await (ftm/await-step [(dwl/sync-file current-id dependent-id)]))))
|
||||
(t/is (= (repeat 2 expected) (map #(get-live-text current-id %) consumer-text-ids)))
|
||||
(t/is (= (repeat 2 original) (map #(get-live-text current-id %) direct-text-ids))
|
||||
"accepting the dependent leaves direct source copies stale")
|
||||
(t/is (= (dissoc (:files before) current-id) (dissoc (:files (ftm/snapshot)) current-id)))
|
||||
(let [after (ftm/snapshot)
|
||||
actual (ftm/refresh-generated (:situation accepted))]
|
||||
(t/is (nil? (oracle/check actual (:model accepted))))
|
||||
(t/is (= :settled (await (ftm/await-step [dwu/undo]))))
|
||||
(t/is (uc/same-state? before (ftm/snapshot)) "consumer undo retains both loaded libraries")
|
||||
(t/is (= :settled (await (ftm/await-step [dwu/redo]))))
|
||||
(t/is (uc/same-state? after (ftm/snapshot)) "consumer redo restores accepted text")))))))
|
||||
|
||||
(t/deftest ^:async transitive-text-waits-for-both-library-acceptances
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(doseq [tuple (into [[:library-text 0 0 1]]
|
||||
(map #(vector :library-text-style 0 % 1) (range 12)))]
|
||||
(await (transitive-text-acceptance-history tuple))))))
|
||||
|
||||
(t/deftest ^:async edit-step-waits-for-slow-sync
|
||||
(let [sync-file dwl/sync-file]
|
||||
(await
|
||||
|
||||
@ -6,13 +6,20 @@
|
||||
|
||||
(ns frontend-tests.composable-tests.generated-test
|
||||
(:require
|
||||
[app.common.test-helpers.composable.comp.files :as cf]
|
||||
[app.common.test-helpers.composable.comp.nodes :as n]
|
||||
[app.common.test-helpers.composable.comp.undo-check :as uc]
|
||||
[app.common.test-helpers.composable.core :as tm]
|
||||
[app.common.test-helpers.composable.gen :as cg]
|
||||
[app.common.test-helpers.composable.grid :as grid]
|
||||
[app.common.test-helpers.composable.oracle :as oracle]
|
||||
[app.common.test-helpers.files :as cthf]
|
||||
[app.common.test-helpers.normalize :as thn]
|
||||
[app.common.test-helpers.shapes :as cths]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.undo :as dwu]
|
||||
[app.main.repo :as rp]
|
||||
[app.main.store :as st]
|
||||
[beicon.v2.core :as rx]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[clojure.test.check.generators :as gen]
|
||||
@ -21,6 +28,18 @@
|
||||
|
||||
(t/use-fixtures :each ftm/fixture)
|
||||
|
||||
(defn- live-model
|
||||
[state live]
|
||||
(let [by-path (into {} (map (juxt :path (comp :id :shape))) (cg/forest live))
|
||||
ids-map (into {} (keep (fn [{:keys [path shape]}]
|
||||
(when-let [id (get by-path path)] [(:id shape) id])))
|
||||
(cg/forest (:situation state)))]
|
||||
(into {}
|
||||
(keep (fn [{:keys [path shape]}]
|
||||
(when-let [groups (get (:model state) (:id shape))]
|
||||
(when-let [id (get by-path path)] [id (grid/remap-groups groups ids-map)]))))
|
||||
(cg/forest (:situation state)))))
|
||||
|
||||
(defn- ^:async replay-program
|
||||
"Replay a JVM-shrunk EDN program against the async frontend. The pure
|
||||
runner chooses targets independently and both must make the same choices."
|
||||
@ -35,28 +54,40 @@
|
||||
pure (:situation state)
|
||||
live (ftm/refresh-generated live)
|
||||
expected (cg/resolve-op pure (:model state) tuple)
|
||||
actual (if (#{:undo :redo} (first tuple))
|
||||
actual (if (#{:undo :redo :library-undo :library-redo} (first tuple))
|
||||
expected
|
||||
(cg/resolve-op live (live-model state live) tuple))]
|
||||
(t/is (= (:trace expected) (:trace actual)) (str "Replay changed a target: " tuple))
|
||||
(let [next-live (if-let [op (:op actual)]
|
||||
(await (ftm/run-generated-step live op))
|
||||
(do
|
||||
(t/is (= :settled (await (ftm/await-step []))))
|
||||
(ftm/refresh-generated live)))
|
||||
(let [next-live (try (if-let [op (:op actual)]
|
||||
(if-let [owner (:library-id actual)]
|
||||
(await (ftm/run-generated-source-step live owner op))
|
||||
(await (ftm/run-generated-step live op)))
|
||||
(do
|
||||
(t/is (= :settled (await (ftm/await-step []))))
|
||||
(ftm/refresh-generated live)))
|
||||
(catch :default error
|
||||
(throw (ex-info (ex-message error)
|
||||
(assoc (ex-data error) :replay-tuple tuple) error))))
|
||||
next-state (-> state (cg/step tuple) (cg/settle-state))]
|
||||
(when-not next-live
|
||||
(throw (ex-info "Frontend step failed" {:program program :tuple tuple})))
|
||||
(when (and (:op actual) (= :update-main (first tuple)))
|
||||
(oracle/check-requested-update-main live next-live (live-model state live)
|
||||
(get-in actual [:shape :id])))
|
||||
(when (and (:op actual) (#{:resize :rotate :transform} (first tuple)))
|
||||
(oracle/check-requested-geometry
|
||||
(:objects (cthf/current-page (tm/file next-live)))
|
||||
(tm/shape-by-id next-live (get-in actual [:shape :id]))
|
||||
(cg/requested-geometry live actual (first tuple))))
|
||||
(when (and (:op actual) (#{:grid-cell :grid-direction} (first tuple)))
|
||||
(oracle/check-requested-grid
|
||||
(tm/shape-by-id next-live (get-in actual [:shape :id])) (:shape actual)
|
||||
(get-in actual [:op :action]) (get-in actual [:op :value])))
|
||||
(try
|
||||
(oracle/check next-live (live-model next-state next-live))
|
||||
(catch :default error
|
||||
(throw (ex-info (str "Frontend oracle at " tuple ": " (ex-message error))
|
||||
(ex-data error) error))))
|
||||
(assoc (ex-data error) :replay-tuple tuple) error))))
|
||||
(let [parity {:relative-free-head-placement true}
|
||||
expected (oracle/canonical (:situation next-state) parity)
|
||||
actual (oracle/canonical next-live parity)]
|
||||
@ -70,63 +101,666 @@
|
||||
(ftm/uninstall!)))))
|
||||
(catch :default error
|
||||
(ftm/uninstall!)
|
||||
(t/is false (str (ex-message error) "\nReplay: " (pr-str program)
|
||||
"\nDetails: " (pr-str (ex-data error)))))))
|
||||
|
||||
(defn- live-model
|
||||
[state live]
|
||||
(let [by-path (into {} (map (juxt :path (comp :id :shape))) (cg/tree live))]
|
||||
(into {}
|
||||
(keep (fn [{:keys [path shape]}]
|
||||
(when-let [groups (get (:model state) (:id shape))]
|
||||
(when-let [id (get by-path path)] [id groups]))))
|
||||
(cg/tree (:situation state)))))
|
||||
(throw error))))
|
||||
|
||||
(defn ^:async replay
|
||||
"Replay a JVM-shrunk EDN program against the async frontend. The pure
|
||||
runner chooses targets independently and both must make the same choices."
|
||||
[{:keys [world ops] :as program}]
|
||||
(try
|
||||
(let [initial (cg/initial-state world)]
|
||||
(loop [state initial
|
||||
live (ftm/start-generated (:situation initial))
|
||||
tuples ops]
|
||||
(if-let [tuple (first tuples)]
|
||||
(let [state (cg/settle-state state)
|
||||
pure (:situation state)
|
||||
live (tm/with-file live (ftm/current-file))
|
||||
expected (cg/resolve-op pure (:model state) tuple)
|
||||
actual (if (#{:undo :redo} (first tuple))
|
||||
expected
|
||||
(cg/resolve-op live (live-model state live) tuple))]
|
||||
(t/is (= (:trace expected) (:trace actual)) (str "Replay changed a target: " tuple))
|
||||
(let [next-live (if-let [op (:op actual)]
|
||||
(await (ftm/run-generated-step live op))
|
||||
(do
|
||||
(t/is (= :settled (await (ftm/await-step []))))
|
||||
(tm/with-file live (ftm/current-file))))
|
||||
next-state (-> state (cg/step tuple) (cg/settle-state))]
|
||||
(when-not next-live
|
||||
(throw (ex-info "Frontend step failed" {:program program :tuple tuple})))
|
||||
(try
|
||||
(oracle/check next-live (live-model next-state next-live))
|
||||
[program]
|
||||
(await (mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock
|
||||
rx/timer mock/timer-mock}
|
||||
(try (await (replay-program program))
|
||||
(catch :default error
|
||||
(throw (ex-info (str "Frontend oracle at " tuple ": " (ex-message error))
|
||||
(ex-data error) error))))
|
||||
(let [expected (oracle/canonical (:situation next-state))
|
||||
actual (oracle/canonical next-live)]
|
||||
(t/is (true? (= expected actual))
|
||||
(str "Backend mismatch at " tuple "; replay " (pr-str program)
|
||||
"; diff " (pr-str (thn/diff expected actual)))))
|
||||
(t/is (empty? (uc/failures next-live)) (pr-str (uc/failures next-live)))
|
||||
(recur next-state next-live (rest tuples))))
|
||||
(let [checked (await (ftm/finish-generated live))]
|
||||
(t/is (empty? (uc/failures checked)) (pr-str (uc/failures checked)))
|
||||
(ftm/uninstall!)))))
|
||||
(catch :default error
|
||||
(ftm/uninstall!)
|
||||
(t/is false (str (ex-message error) "\nReplay: " (pr-str program)
|
||||
"\nDetails: " (pr-str (ex-data error)))))))
|
||||
(t/is false (str (ex-message error) "\nReplay: " (pr-str program)
|
||||
"\nDetails: " (pr-str (ex-data error)))))))))
|
||||
|
||||
(defn- ^:async replay-library-grid-with-source-control
|
||||
[program]
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(t/is (map? (cg/run program)))
|
||||
;; The same source edits are valid when the source owns the editor.
|
||||
(let [situation (cg/world (:world program))
|
||||
files (cf/all-files situation)
|
||||
owner (first (keys (tm/aux-files situation)))
|
||||
parent-id (get-in (cg/resolve-op situation {} [:library-add-child 0]) [:shape :id])
|
||||
editor (-> situation (tm/with-file (get files owner)) (tm/with-aux-files (dissoc files owner)))
|
||||
initial (ftm/start-generated editor)
|
||||
before (ftm/snapshot)
|
||||
first (await (ftm/run-generated-step initial (n/add-child (constantly parent-id) :source-a :width 20 :height 20)))
|
||||
second (await (ftm/run-generated-step first (n/add-child (constantly parent-id) :source-b :width 20 :height 20)))
|
||||
shape (tm/shape-by-id second parent-id)]
|
||||
(t/is (= 5 (count (:shapes shape))))
|
||||
(t/is (= [2 3] (mapv #(count (get shape %)) [:layout-grid-rows :layout-grid-columns])))
|
||||
(t/is (= (dissoc (:files before) owner) (dissoc (:files (ftm/snapshot)) owner)))
|
||||
(t/is (empty? (uc/failures (await (ftm/finish-generated second)))))
|
||||
(ftm/uninstall!))
|
||||
(await (replay-program program)))))
|
||||
|
||||
(def update-main-intent-programs
|
||||
[{:world [1 0] :ops [[:edit 0 0 1 1] [:update-main 0] [:undo] [:redo]]}
|
||||
{:world [1 0 {:library true}] :ops [[:edit 0 0 1 2] [:update-main 0] [:undo] [:redo]]}
|
||||
{:world [1 0 {:library true :stale-libraries true}]
|
||||
:ops [[:edit 0 0 1 2] [:update-main 0] [:undo] [:redo]]}
|
||||
{:world [1 0 {:layout :grid :layout-children true :grid-square true}]
|
||||
:ops [[:grid-cell 0 0 0 1] [:update-main 0] [:undo] [:redo]]}
|
||||
{:world [1 0 {:library true :library-depth 0 :library-grid true}]
|
||||
:ops [[:grid-cell 0 0 0 2] [:update-main 0] [:undo] [:redo]]}
|
||||
{:world [1 0 {:library true :library-depth 0 :library-grid true :stale-libraries true}]
|
||||
:ops [[:grid-cell 0 0 0 2] [:update-main 0] [:undo] [:redo]]}
|
||||
{:world [1 0 {:text true :text-styles true}]
|
||||
:ops [[:text-style 1 2 1] [:update-main 0] [:undo] [:redo]]}
|
||||
{:world [1 0] :ops [[:transform 0 3 2 4] [:update-main 0] [:undo] [:redo]]}])
|
||||
|
||||
(t/deftest ^:async update-main-preserves-authored-intent-in-the-destination
|
||||
(doseq [program update-main-intent-programs]
|
||||
(await (replay program))))
|
||||
|
||||
(t/deftest ^:async update-main-intent-rejects-a-reset-dispatched-by-the-editor
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(doseq [{:keys [world ops]} update-main-intent-programs]
|
||||
(let [state (cg/initial-state world)
|
||||
live (ftm/start-generated (:situation state))
|
||||
edit (first ops)
|
||||
edited (await (ftm/run-generated-step live (:op (cg/resolve-op live {} edit))))
|
||||
state (-> state (cg/step edit) cg/settle-state)
|
||||
model (live-model state edited)
|
||||
request (cg/resolve-op edited model [:update-main 0])
|
||||
result (await (mock/with-mocks* {dwl/update-component-sync (fn ([id _] (dwl/reset-component id)) ([id _ _] (dwl/reset-component id)))}
|
||||
(await (ftm/run-generated-step edited (:op request)))))
|
||||
settled (try (oracle/check result {}) nil
|
||||
(catch :default error (ex-data error)))
|
||||
failure (try (oracle/check-requested-update-main edited result model (get-in request [:shape :id])) nil
|
||||
(catch :default error (ex-data error)))]
|
||||
(t/is (nil? settled) "The wrong main and every copy agree")
|
||||
(t/is (= :I9 (:invariant failure)) (pr-str failure))
|
||||
(t/is (= :requested-update-main (:phase failure)) (pr-str failure))
|
||||
(let [checked (await (ftm/finish-generated result))]
|
||||
(t/is (empty? (uc/failures checked)) (pr-str (uc/failures checked))))
|
||||
(ftm/uninstall!)
|
||||
(let [failure (await (mock/with-mocks* {dwl/update-component-sync (fn ([id _] (dwl/reset-component id)) ([id _ _] (dwl/reset-component id)))}
|
||||
(try (await (replay-program {:world world :ops ops})) nil
|
||||
(catch :default error (ex-data error)))))]
|
||||
(t/is (= :I9 (:invariant failure)) (pr-str failure))
|
||||
(t/is (= :requested-update-main (:phase failure)) (pr-str failure))))))))
|
||||
|
||||
(t/deftest ^:async empty-grid-direction-edits-replay-through-the-frontend
|
||||
(doseq [depth [0 1]
|
||||
scope [nil 1]]
|
||||
(await (replay {:world [1 depth {:layout :grid :grid-empty true}]
|
||||
:ops [[:grid-cell 0 0 0 scope] [:grid-direction 0 0 1 scope]
|
||||
[:undo] [:redo]]}))))
|
||||
|
||||
(t/deftest ^:async empty-grid-direction-histories-replay-through-the-frontend
|
||||
(doseq [depth [0 1]
|
||||
tail [[[:grid-direction 0 0 0 1]] [[:update-main 0]] [[:reset 0]]
|
||||
[[:duplicate 0]] [[:detach 0]] [[:add-child 0]]]]
|
||||
(await (replay {:world [1 depth {:layout :grid :grid-empty true}]
|
||||
:ops (into [[:grid-direction 0 0 1 1]] (concat tail [[:sync] [:undo] [:redo]]))}))))
|
||||
|
||||
(t/deftest ^:async grid-growth-replays-with-independent-cell-expectations
|
||||
(doseq [direction [:row :column]
|
||||
turn-copy? [false true]]
|
||||
(await (replay {:world [1 0 {:layout :grid :layout-children true :grid-square true}]
|
||||
:ops (vec (concat (when (= direction :column) [[:grid-direction 0 0 1 0]])
|
||||
[[:grid-cell 0 0 0 1]]
|
||||
(when turn-copy? [[:grid-direction 0 0 (if (= direction :row) 1 0) 1]])
|
||||
[[:add-child 0] [:add-child 0] [:sync] [:undo] [:redo]]))}))))
|
||||
|
||||
(t/deftest ^:async grid-growth-context-replays-through-structural-and-library-operations
|
||||
(doseq [program
|
||||
(concat
|
||||
(for [tail [[[:duplicate 0] [:undo] [:redo]] [[:update-main 0] [:undo] [:redo]]
|
||||
[[:reset 0] [:undo] [:redo]] [[:detach 0] [:undo] [:redo]]]]
|
||||
{:world [1 0 {:layout :grid :layout-children true :grid-square true}]
|
||||
:ops (into [[:grid-cell 0 0 0 1] [:add-child 0] [:add-child 0] [:sync 1]] tail)})
|
||||
[{:world [1 1 {:layout :grid :layout-children true :grid-square true}]
|
||||
:ops [[:grid-cell 0 0 0 1] [:add-child 0] [:add-child 0] [:sync 1] [:detach 0] [:undo] [:redo]]}
|
||||
{:world [1 0 {:library true :library-depth 0 :library-grid true :stale-libraries true}]
|
||||
:ops [[:grid-cell 0 0 0 2] [:library-add-child 0] [:library-add-child 0]
|
||||
[:edit 0 1 1 2] [:library-sync] [:undo] [:redo]]}])]
|
||||
(if (get-in program [:world 2 :stale-libraries])
|
||||
(await (replay-library-grid-with-source-control program))
|
||||
(await (replay program)))))
|
||||
|
||||
(t/deftest ^:async source-grid-additions-replay-without-accepting-the-library
|
||||
(await (replay {:world [1 0 {:library true :library-depth 0 :library-grid true :stale-libraries true}]
|
||||
:ops [[:grid-cell 0 0 0 2] [:library-add-child 0] [:library-add-child 0]
|
||||
[:edit 0 1 1 2] [:undo] [:redo]]})))
|
||||
|
||||
(t/deftest ^:async accepting-source-grid-growth-keeps-oracle-references-through-undo
|
||||
(await (replay {:world [1 0 {:library true :library-depth 0 :library-grid true :stale-libraries true}]
|
||||
:ops [[:grid-cell 0 0 0 2] [:library-add-child 0] [:library-add-child 0]
|
||||
[:edit 0 1 1 2] [:library-sync] [:undo] [:redo]]})))
|
||||
|
||||
(t/deftest ^:async accepted-reference-history-keeps-newer-loaded-sources-independent
|
||||
(doseq [ops [[[:library-add-child 0] [:library-sync] [:library-add-child 0]
|
||||
[:library-sync] [:undo] [:undo] [:redo] [:redo]]
|
||||
[[:library-add-child 0] [:library-sync] [:edit 0 1 1 2]
|
||||
[:undo] [:undo] [:redo] [:redo]]
|
||||
[[:library-edit 0 0 1] [:library-sync] [:library-edit 0 0 2]
|
||||
[:undo] [:redo]]]]
|
||||
(await (replay {:world [0 0 {:library true :library-depth 0 :library-grid true :stale-libraries true}]
|
||||
:ops ops}))))
|
||||
|
||||
(t/deftest ^:async selective-library-pulls-retain-independent-reference-histories
|
||||
(doseq [kind [:reset :swap :switch]]
|
||||
(t/testing (name kind)
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(let [initial (cg/world [0 0 {:library true :library-depth 0 :library-variants true :stale-libraries true}])
|
||||
resolved (cg/resolve-op initial {} [kind 0])
|
||||
target (get-in resolved [:shape :id])
|
||||
main (if (= kind :reset)
|
||||
(get-in resolved [:shape :shape-ref])
|
||||
(get-in resolved [:destination :id]))
|
||||
owner (get-in resolved [:shape :component-file])
|
||||
source (get (cf/all-files initial) owner)
|
||||
child (first (:shapes (tm/shape-by-id (tm/with-file initial source) main)))
|
||||
control (first (for [{:keys [shape]} (cg/tree initial)
|
||||
:when (and (= main (:shape-ref shape)) (not= target (:id shape)))]
|
||||
(:id shape)))
|
||||
old-fill (get-in (tm/shape-by-id (tm/with-file initial source) child) [:fills 0 :fill-color])
|
||||
live (ftm/start-generated initial)
|
||||
live (await (ftm/run-generated-source-step live owner
|
||||
(n/change-property (constantly child) :fills "#00ff00")))
|
||||
loaded (get (cf/all-files live) owner)
|
||||
before (tm/file live)
|
||||
prior (get (cf/reference-libraries live (tm/shape-by-id live target)) owner)
|
||||
live (await (ftm/run-generated-step live (:op resolved)))
|
||||
after (tm/file live)
|
||||
head (tm/shape-by-id live target)
|
||||
pulled (tm/shape-by-id live (first (:shapes head)))
|
||||
stale (tm/shape-by-id live (first (:shapes (tm/shape-by-id live control))))]
|
||||
(t/is (some? control))
|
||||
(t/is (= "#00ff00" (get-in pulled [:fills 0 :fill-color])))
|
||||
(t/is (= old-fill (get-in stale [:fills 0 :fill-color])))
|
||||
(t/is (= (:data loaded) (:data (get (cf/reference-libraries live head) owner))))
|
||||
(t/is (= (:data source) (:data (get (cf/reference-libraries live (tm/shape-by-id live control)) owner))))
|
||||
(t/is (nil? (oracle/check live {})))
|
||||
(let [live (await (ftm/run-generated-step live (n/undo)))]
|
||||
(t/is (= before (tm/file live)))
|
||||
(t/is (= (:data prior) (:data (get (cf/reference-libraries live (tm/shape-by-id live target)) owner))))
|
||||
(t/is (= (:data loaded) (:data (get (cf/all-files live) owner))))
|
||||
(t/is (nil? (oracle/check live {})))
|
||||
(let [live (await (ftm/run-generated-step live (n/redo)))]
|
||||
(t/is (= after (tm/file live)))
|
||||
(t/is (= (:data loaded) (:data (get (cf/reference-libraries live (tm/shape-by-id live target)) owner))))
|
||||
(t/is (= old-fill (get-in (tm/shape-by-id live (first (:shapes (tm/shape-by-id live control)))) [:fills 0 :fill-color])))
|
||||
(t/is (nil? (oracle/check live {})))
|
||||
(t/is (empty? (uc/failures (await (ftm/finish-generated live)))))))
|
||||
(ftm/uninstall!)))))))
|
||||
|
||||
(t/deftest ^:async selective-library-reset-replays-through-undo-and-redo
|
||||
(await (replay {:world [0 0 {:library true :library-depth 0 :stale-libraries true}]
|
||||
:ops [[:library-edit 0 0 1] [:reset 0] [:undo] [:redo]]})))
|
||||
|
||||
(t/deftest ^:async selective-library-swap-and-switch-replay-through-undo-and-redo
|
||||
(doseq [kind [:swap :switch]]
|
||||
(let [world [0 0 {:library true :library-depth 0 :library-variants true :stale-libraries true}]
|
||||
initial (cg/world world)
|
||||
resolved (cg/resolve-op initial {} [kind 0])
|
||||
main (get-in resolved [:destination :id])
|
||||
index (first (filter #(= main (get-in (cg/resolve-op initial {} [:library-edit % 0 2]) [:shape :parent-id]))
|
||||
(range 3)))]
|
||||
(t/is (some? index))
|
||||
(await (replay {:world world
|
||||
:ops [[:library-edit index 0 2] [kind 0] [:undo] [:redo]]})))))
|
||||
|
||||
(t/deftest ^:async a-selective-library-reset-in-a-main-refreshes-its-local-images
|
||||
(let [world [1 0 {:library true :library-depth 0 :stale-libraries true}]
|
||||
state (-> (cg/initial-state world) (cg/step [:nest 0]) cg/settle-state)
|
||||
initial (:situation state)
|
||||
owner (:library-id (cg/resolve-op initial {} [:library-edit 0 0 1]))
|
||||
count (:opportunities (cg/resolve-op initial {} [:reset 0]))
|
||||
index (first (filter (fn [index]
|
||||
(let [shape (:shape (cg/resolve-op initial {} [:reset index]))]
|
||||
(and (= owner (:component-file shape))
|
||||
(:main-instance (tm/shape-by-id initial (:parent-id shape))))))
|
||||
(range count)))]
|
||||
(t/is (some? index))
|
||||
(await (replay {:world world
|
||||
:ops [[:nest 0] [:library-edit 0 0 1] [:reset index] [:undo] [:redo]]}))))
|
||||
|
||||
(t/deftest ^:async no-op-variant-requests-keep-stale-reference-inputs
|
||||
(doseq [request [:current :missing]]
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(let [initial (cg/world [0 0 {:library true :library-depth 0 :library-variants true :stale-libraries true}])
|
||||
resolved (cg/resolve-op initial {} [:switch 0])
|
||||
shape (:shape resolved)
|
||||
target (:id shape)
|
||||
owner (:component-file shape)
|
||||
source (get (cf/all-files initial) owner)
|
||||
main (tm/shape-by-id (tm/with-file initial source) (:shape-ref shape))
|
||||
child (first (:shapes main))
|
||||
value (if (= request :current)
|
||||
(get-in source [:data :components (:component-id shape) :variant-properties 0 :value])
|
||||
"missing-variant-value")
|
||||
live (ftm/start-generated initial)
|
||||
live (await (ftm/run-generated-source-step live owner
|
||||
(n/change-property (constantly child) :fills "#00ff00")))
|
||||
before (tm/file live)
|
||||
inputs (cf/reference-libraries live (tm/shape-by-id live target))
|
||||
live (await (ftm/run-generated-step live (n/switch-variant (constantly target) value)))]
|
||||
(t/is (= before (tm/file live)))
|
||||
(t/is (= inputs (cf/reference-libraries live (tm/shape-by-id live target))))
|
||||
(t/is (nil? (oracle/check live {})))
|
||||
(t/is (empty? (uc/failures (await (ftm/finish-generated live)))))
|
||||
(ftm/uninstall!))))))
|
||||
|
||||
(t/deftest ^:async reference-only-library-acceptance-keeps-the-older-undo-journal
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(let [initial (cg/world [0 0 {:library true :library-depth 0 :stale-libraries true}])
|
||||
owner (n/library-id initial)
|
||||
source (cths/add-sample-shape (get (cf/all-files initial) owner) :journal-unrelated)
|
||||
extra (:id (cths/get-shape source :journal-unrelated))
|
||||
initial (-> initial
|
||||
(tm/with-file (cths/add-sample-shape (tm/file initial) :journal-local))
|
||||
(tm/with-aux-files {owner source})
|
||||
cf/freeze-libraries)
|
||||
local (:id (cths/get-shape (tm/file initial) :journal-local))
|
||||
copy (first (for [{:keys [shape]} (cg/tree initial)
|
||||
:when (= owner (:component-file shape))]
|
||||
(:id shape)))
|
||||
live (ftm/start-generated initial)
|
||||
live (await (ftm/run-generated-step live (n/change-property (constantly local) :opacity 0.4)))
|
||||
live (await (ftm/run-generated-source-step live owner
|
||||
(n/change-property (constantly extra) :opacity 0.7)))
|
||||
loaded (get (cf/all-files live) owner)
|
||||
before (tm/file live)
|
||||
history (:workspace-undo @st/state)
|
||||
journal (::ftm/reference-history live)
|
||||
live (await (ftm/run-generated-step live (n/sync-from-library owner)))]
|
||||
(t/is (some? local))
|
||||
(t/is (some? copy))
|
||||
(t/is (not= (:data source) (:data loaded)))
|
||||
(t/is (= before (tm/file live)))
|
||||
(t/is (= history (:workspace-undo @st/state)))
|
||||
(t/is (= journal (::ftm/reference-history live)))
|
||||
(t/is (= (:data loaded) (:data (get (cf/reference-libraries live (tm/shape-by-id live copy)) owner))))
|
||||
(let [live (await (ftm/run-generated-step live (n/undo)))]
|
||||
(t/is (nil? (:opacity (tm/shape-by-id live local))))
|
||||
(t/is (= (:data loaded) (:data (get (cf/reference-libraries live (tm/shape-by-id live copy)) owner))))
|
||||
(let [live (await (ftm/run-generated-step live (n/redo)))]
|
||||
(t/is (= before (tm/file live)))
|
||||
(t/is (= (:data loaded) (:data (get (cf/reference-libraries live (tm/shape-by-id live copy)) owner))))
|
||||
(t/is (nil? (oracle/check live {})))
|
||||
(t/is (empty? (uc/failures (await (ftm/finish-generated live)))))))
|
||||
(ftm/uninstall!)))))
|
||||
|
||||
(t/deftest ^:async library-acceptance-at-the-history-limit-keeps-its-reference-journal
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock dwu/MAX-UNDO-SIZE 2}
|
||||
(let [initial (cg/world [0 0 {:library true :library-depth 0 :stale-libraries true}])
|
||||
initial (tm/with-file initial (cths/add-sample-shape (tm/file initial) :journal-local))
|
||||
edit (cg/resolve-op initial {} [:library-edit 0 0 1])
|
||||
owner (:library-id edit)
|
||||
source (get (cf/all-files initial) owner)
|
||||
local (:id (cths/get-shape (tm/file initial) :journal-local))
|
||||
copy (first (for [{:keys [shape]} (cg/tree initial)
|
||||
:when (= owner (:component-file shape))]
|
||||
(:id shape)))
|
||||
live (ftm/start-generated initial)
|
||||
live (await (ftm/run-generated-step live (n/change-property (constantly local) :opacity 0.2)))
|
||||
live (await (ftm/run-generated-step live (n/change-property (constantly local) :opacity 0.4)))
|
||||
live (await (ftm/run-generated-source-step live owner (:op edit)))
|
||||
loaded (get (cf/all-files live) owner)
|
||||
before (tm/file live)
|
||||
history (:workspace-undo @st/state)
|
||||
live (await (ftm/run-generated-step live (n/sync-from-library owner)))
|
||||
after (tm/file live)
|
||||
current (:workspace-undo @st/state)]
|
||||
(t/is (= 2 (count (:items history)) (count (:items current))))
|
||||
(t/is (= (:index history) (:index current)))
|
||||
(t/is (not= (:undo-group (peek (:items history))) (:undo-group (peek (:items current)))))
|
||||
(t/is (not= (:data before) (:data after)))
|
||||
(t/is (= (:data loaded) (:data (get (cf/reference-libraries live (tm/shape-by-id live copy)) owner))))
|
||||
(let [live (await (ftm/run-generated-step live (n/undo)))]
|
||||
(t/is (= before (tm/file live)))
|
||||
(t/is (= (:data source) (:data (get (cf/reference-libraries live (tm/shape-by-id live copy)) owner))))
|
||||
(let [live (await (ftm/run-generated-step live (n/redo)))]
|
||||
(t/is (= after (tm/file live)))
|
||||
(t/is (= (:data loaded) (:data (get (cf/reference-libraries live (tm/shape-by-id live copy)) owner))))
|
||||
(t/is (nil? (oracle/check live {})))
|
||||
(t/is (empty? (uc/failures (await (ftm/finish-generated live)))))))
|
||||
(ftm/uninstall!)))))
|
||||
|
||||
(t/deftest ^:async accepted-source-child-undo-keeps-backend-parity
|
||||
(await (replay {:world [0 0 {:library true :library-depth 0 :library-grid true :stale-libraries true}]
|
||||
:ops [[:library-add-child 0] [:library-add-child 0] [:library-sync]
|
||||
[:library-undo 0] [:undo] [:library-redo 0] [:redo]]})))
|
||||
|
||||
(t/deftest ^:async transitive-library-acceptance-keeps-each-editors-reference-history
|
||||
(await (replay {:world [0 0 {:library true :library-depth 0 :library-dependency true :stale-libraries true}]
|
||||
:ops [[:library-edit 1 0 1] [:library-sync 0] [:library-accept 0]
|
||||
[:library-sync 0] [:library-undo 0] [:undo]
|
||||
[:library-redo 0] [:redo]]})))
|
||||
|
||||
(t/deftest ^:async a-source-undo-retains-the-consumers-accepted-child-reference
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(let [world [0 0 {:library true :library-depth 0 :library-grid true :stale-libraries true}]
|
||||
ops [[:library-add-child 0] [:library-add-child 0] [:library-sync]]
|
||||
initial (cg/world world)
|
||||
resolved (cg/resolve-op initial {} (first ops))
|
||||
owner (:library-id resolved)
|
||||
main-id (get-in resolved [:shape :id])
|
||||
live (loop [live (ftm/start-generated initial) tuples ops]
|
||||
(if-let [tuple (first tuples)]
|
||||
(let [{:keys [op library-id]} (cg/resolve-op live {} tuple)]
|
||||
(recur (if library-id
|
||||
(await (ftm/run-generated-source-step live library-id op))
|
||||
(await (ftm/run-generated-step live op)))
|
||||
(rest tuples)))
|
||||
live))
|
||||
source (get (cf/all-files live) owner)
|
||||
ids (:shapes (tm/shape-by-id (tm/with-file live source) main-id))
|
||||
before (tm/file live)
|
||||
live (await (ftm/run-generated-source-step live owner (n/undo)))
|
||||
source (get (cf/all-files live) owner)
|
||||
current (:shapes (tm/shape-by-id (tm/with-file live source) main-id))]
|
||||
(t/is (= 5 (count ids)))
|
||||
(t/is (= 4 (count current)))
|
||||
(t/is (= before (tm/file live)))
|
||||
(doseq [{:keys [shape]} (cg/tree live) :when (= main-id (:shape-ref shape))]
|
||||
(let [accepted (get (cf/reference-libraries live shape) owner)]
|
||||
(t/is (= ids (:shapes (tm/shape-by-id (tm/with-file live accepted) main-id))))))
|
||||
(t/is (nil? (oracle/check live {})))
|
||||
(t/is (= [] (vec (for [file (vals (oracle/canonical live))
|
||||
objects (cf/object-trees file)
|
||||
shape (vals objects)
|
||||
:when (uuid? (:shape-ref shape))]
|
||||
(:shape-ref shape)))))
|
||||
(t/is (empty? (uc/failures (await (ftm/finish-generated live)))))
|
||||
(ftm/uninstall!)))))
|
||||
|
||||
(t/deftest ^:async update-main-refreshes-library-reference-inputs-through-undo-and-redo
|
||||
(await (replay {:world [0 0 {:library true :library-depth 0 :stale-libraries true}]
|
||||
:ops [[:edit 0 1 1 2] [:update-main 0] [:undo] [:redo]]})))
|
||||
|
||||
(t/deftest ^:async update-main-reference-history-follows-source-and-consumer-edits
|
||||
(doseq [depth [0 1]
|
||||
grid [false true]
|
||||
accept [false true]]
|
||||
(await (replay {:world [1 0 {:library true :library-depth depth :library-grid grid :stale-libraries true}]
|
||||
:ops (vec (concat [[:library-edit 0 0 1]]
|
||||
(when accept [[:library-sync]])
|
||||
[[:edit 0 1 1 2] [:update-main 0] [:undo] [:redo]
|
||||
[:library-edit 0 0 2] [:library-undo 0] [:library-redo 0]]))}))))
|
||||
|
||||
(t/deftest ^:async update-main-keeps-unrelated-library-components-stale
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(let [initial (cg/world [0 0 {:library true :library-depth 0 :library-variants true :stale-libraries true}])
|
||||
target (get-in (cg/resolve-op initial {} [:edit 0 1 1 2]) [:shape :id])
|
||||
head (tm/shape-by-id initial target)
|
||||
owner (:component-file head)
|
||||
source (get (cf/all-files initial) owner)
|
||||
main (:shape-ref head)
|
||||
sibling (first (for [{:keys [shape]} (cg/tree initial)
|
||||
:when (and (= main (:shape-ref shape)) (not= target (:id shape)))]
|
||||
(:id shape)))
|
||||
unrelated (first (for [{:keys [shape]} (cg/tree (tm/with-file initial source))
|
||||
:when (and (:main-instance shape) (not= main (:id shape)))]
|
||||
(:id shape)))
|
||||
control (first (for [{:keys [shape]} (cg/tree initial)
|
||||
:when (= unrelated (:shape-ref shape))]
|
||||
(:id shape)))
|
||||
child (first (:shapes (tm/shape-by-id (tm/with-file initial source) unrelated)))
|
||||
old-fill (get-in (tm/shape-by-id initial (first (:shapes (tm/shape-by-id initial control))))
|
||||
[:fills 0 :fill-color])
|
||||
live (ftm/start-generated initial)
|
||||
live (await (ftm/run-generated-source-step live owner
|
||||
(n/change-property (constantly child) :fills "#00ff00")))
|
||||
live (await (ftm/run-generated-step live (n/change-property (constantly target) :opacity 0.4)))
|
||||
before (ftm/snapshot)
|
||||
prior (cf/reference-libraries live (tm/shape-by-id live target))
|
||||
live (await (ftm/run-generated-step live (n/update-main (constantly target))))
|
||||
after (ftm/snapshot)
|
||||
updated (get (cf/all-files live) owner)]
|
||||
(t/is (some? sibling))
|
||||
(t/is (some? control))
|
||||
(t/is (= 0.4 (:opacity (tm/shape-by-id (tm/with-file live updated) main))))
|
||||
(doseq [id [target sibling]]
|
||||
(t/is (= 0.4 (:opacity (tm/shape-by-id live id))))
|
||||
(t/is (= (:data updated) (:data (get (cf/reference-libraries live (tm/shape-by-id live id)) owner)))))
|
||||
(t/is (= "#00ff00" (get-in (tm/shape-by-id (tm/with-file live updated) child) [:fills 0 :fill-color])))
|
||||
(t/is (= old-fill (get-in (tm/shape-by-id live (first (:shapes (tm/shape-by-id live control)))) [:fills 0 :fill-color])))
|
||||
(t/is (= (:data source) (:data (get (cf/reference-libraries live (tm/shape-by-id live control)) owner))))
|
||||
(t/is (nil? (oracle/check live {})))
|
||||
(let [live (await (ftm/run-generated-step live (n/undo)))]
|
||||
(t/is (= before (ftm/snapshot)))
|
||||
(doseq [id [target sibling]]
|
||||
(t/is (= (:data (get prior owner))
|
||||
(:data (get (cf/reference-libraries live (tm/shape-by-id live id)) owner)))))
|
||||
;; The source copy regains its authored opacity on undo.
|
||||
(t/is (nil? (oracle/check live {target {:layer-effects-group {:opacity 0.4 :blend-mode nil}}})))
|
||||
(let [live (await (ftm/run-generated-step live (n/redo)))]
|
||||
(t/is (= after (ftm/snapshot)))
|
||||
(doseq [id [target sibling]]
|
||||
(t/is (= (:data updated) (:data (get (cf/reference-libraries live (tm/shape-by-id live id)) owner)))))
|
||||
(t/is (= (:data source) (:data (get (cf/reference-libraries live (tm/shape-by-id live control)) owner))))
|
||||
(t/is (nil? (oracle/check live {})))
|
||||
(t/is (empty? (uc/failures (await (ftm/finish-generated live)))))))
|
||||
(ftm/uninstall!)))))
|
||||
|
||||
(t/deftest ^:async source-history-checkpoints-legitimate-consumer-writes
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(t/is (map? (cg/run {:world [0 0 {:library true :library-depth 0 :stale-libraries true}]
|
||||
:ops [[:library-edit 0 0 1] [:library-sync] [:edit 0 1 1 2]
|
||||
[:update-main 0] [:library-edit 0 0 2]]})))
|
||||
(let [initial (cg/world [0 0 {:library true :library-depth 0 :stale-libraries true}])
|
||||
edit (cg/resolve-op initial {} [:library-edit 0 0 1])
|
||||
owner (:library-id edit)
|
||||
child (get-in edit [:shape :id])
|
||||
main (get-in edit [:shape :parent-id])
|
||||
copy (get-in (cg/resolve-op initial {} [:edit 0 1 1 2]) [:shape :id])
|
||||
page-id (cthf/current-page-id (get (cf/all-files initial) owner))
|
||||
live (ftm/start-generated initial)
|
||||
live (await (ftm/run-generated-source-step live owner (:op edit)))
|
||||
entry (get-in live [::ftm/source-editors owner :undo :items 0])
|
||||
live (await (ftm/run-generated-step live (n/sync-from-library owner)))
|
||||
live (await (ftm/run-generated-step live (n/change-property (constantly copy) :opacity 0.4)))
|
||||
live (await (ftm/run-generated-step live (n/update-main (constantly copy))))
|
||||
source (get (cf/all-files live) owner)
|
||||
_ (t/is (= 0.4 (:opacity (tm/shape-by-id (tm/with-file live source) main))))
|
||||
live (await (ftm/run-generated-source-step live owner
|
||||
(n/change-property (constantly child) :fills "#00ff00")))
|
||||
editor (get-in live [::ftm/source-editors owner])
|
||||
base (uc/baseline (:situation editor))
|
||||
source (get (cf/all-files live) owner)]
|
||||
(t/is (= "#00ff00" (get-in (tm/shape-by-id (tm/with-file live source) child) [:fills 0 :fill-color])))
|
||||
(t/is (= 0.4 (:opacity (tm/shape-by-id (tm/with-file live source) main))))
|
||||
(t/is (= entry (get-in editor [:undo :items 0])))
|
||||
(t/is (= 2 (count (get-in editor [:undo :items]))))
|
||||
(t/is (= 0 (:depth base)))
|
||||
(t/is (= 0.4 (get-in base [:snapshot :files owner :data :pages-index page-id :objects main :opacity])))
|
||||
(t/is (= "#ff0000" (get-in base [:snapshot :files owner :data :pages-index page-id :objects child :fills 0 :fill-color])))
|
||||
(t/is (empty? (uc/failures (await (ftm/finish-generated live)))))
|
||||
(ftm/uninstall!)))))
|
||||
|
||||
(t/deftest ^:async source-history-checkpoints-preserve-no-ops-and-older-entries
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(let [initial (cg/world [0 0 {:library true :library-depth 0 :stale-libraries true}])
|
||||
edit (cg/resolve-op initial {} [:library-edit 0 0 1])
|
||||
owner (:library-id edit)
|
||||
child (get-in edit [:shape :id])
|
||||
main (get-in edit [:shape :parent-id])
|
||||
copy (get-in (cg/resolve-op initial {} [:edit 0 1 1 2]) [:shape :id])
|
||||
live (ftm/start-generated initial)
|
||||
live (await (ftm/run-generated-source-step live owner (:op edit)))
|
||||
live (await (ftm/run-generated-source-step live owner
|
||||
(n/change-property (constantly child) :fills "#00ff00")))
|
||||
editor (get-in live [::ftm/source-editors owner])
|
||||
_ (t/is (= -1 (:depth (uc/baseline (:situation editor)))))
|
||||
entries (:items (:undo editor))
|
||||
live (await (ftm/run-generated-step live (n/sync-from-library owner)))
|
||||
live (await (ftm/run-generated-step live (n/change-property (constantly copy) :opacity 0.4)))
|
||||
live (await (ftm/run-generated-step live (n/update-main (constantly copy))))
|
||||
base (uc/baseline live)
|
||||
live (await (ftm/run-generated-source-step live owner
|
||||
(n/change-property (constantly child) :fills "#00ff00")))
|
||||
editor (get-in live [::ftm/source-editors owner])]
|
||||
(t/is (= base (uc/baseline live)))
|
||||
(t/is (= 1 (:depth (uc/baseline (:situation editor)))))
|
||||
(t/is (= entries (:items (:undo editor))))
|
||||
(t/is (empty? (uc/failures (await (ftm/finish-generated live)))))
|
||||
(let [live (loop [live live steps [[(n/undo) "#ff0000"] [(n/undo) "#abcdef"]
|
||||
[(n/redo) "#ff0000"] [(n/redo) "#00ff00"]]]
|
||||
(if-let [[op fill] (first steps)]
|
||||
(let [live (await (ftm/run-generated-source-step live owner op))
|
||||
source (tm/with-file live (get (cf/all-files live) owner))]
|
||||
(t/is (= fill (get-in (tm/shape-by-id source child) [:fills 0 :fill-color])))
|
||||
(t/is (= 0.4 (:opacity (tm/shape-by-id source main))))
|
||||
(recur live (rest steps)))
|
||||
live))
|
||||
live (await (ftm/run-generated-step live (n/undo)))
|
||||
_ (t/is (nil? (:opacity (tm/shape-by-id (tm/with-file live (get (cf/all-files live) owner)) main))))
|
||||
live (await (ftm/run-generated-step live (n/redo)))
|
||||
file (tm/with-file live (get (cf/all-files live) owner))]
|
||||
(t/is (= 0.4 (:opacity (tm/shape-by-id file main))))
|
||||
(t/is (= "#00ff00" (get-in (tm/shape-by-id file child) [:fills 0 :fill-color])))
|
||||
(t/is (empty? (uc/failures (await (ftm/finish-generated live))))))
|
||||
(ftm/uninstall!)))))
|
||||
|
||||
(t/deftest ^:async source-handoff-reports-and-retains-a-broken-consumer-segment
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(let [initial (cg/world [0 0 {:library true :library-depth 0 :stale-libraries true}])
|
||||
edit (cg/resolve-op initial {} [:library-edit 0 0 1])
|
||||
owner (:library-id edit)
|
||||
copy (get-in (cg/resolve-op initial {} [:edit 0 1 1 2]) [:shape :id])
|
||||
file-id (:id (tm/file initial))
|
||||
page-id (cthf/current-page-id (tm/file initial))
|
||||
live (ftm/start-generated initial)
|
||||
live (await (ftm/run-generated-step live (n/change-property (constantly copy) :opacity 0.4)))
|
||||
base (uc/baseline live)
|
||||
;; Corrupt the expected pre-edit state. Handoff must report this
|
||||
;; whole-segment failure before a source edit advances the baseline.
|
||||
live (uc/mark-baseline live (:depth base)
|
||||
(assoc-in (:snapshot base)
|
||||
[:files file-id :data :pages-index page-id :objects copy :opacity] 0.9))
|
||||
reports (atom [])
|
||||
live (await (mock/with-mocks* {t/report #(swap! reports conj %)}
|
||||
(ftm/run-generated-source-step live owner (:op edit))))
|
||||
failed (filter #(= :fail (:type %)) @reports)
|
||||
errors (filter #(= :error (:type %)) @reports)]
|
||||
(t/is (= 1 (count failed)))
|
||||
(t/is (empty? errors))
|
||||
(t/is (= [:variant-undo] (mapv :phase (uc/failures live))))
|
||||
(t/is (= #{[:file :file1 :object :random-library-copy-0-0 :opacity]}
|
||||
(:signature (first (uc/failures live)))))
|
||||
(t/is (= 0 (:depth (uc/baseline live))))
|
||||
(ftm/uninstall!)))))
|
||||
|
||||
(t/deftest ^:async source-editors-retain-their-own-undo-and-redo-histories
|
||||
(doseq [ops [[[:library-add-child 0] [:library-add-child 0] [:library-undo 0]
|
||||
[:edit 0 1 1 2] [:library-redo 0] [:undo] [:redo]]
|
||||
[[:edit 0 1 1 2] [:library-edit 0 0 1] [:undo]
|
||||
[:library-undo 0] [:redo] [:library-redo 0]]
|
||||
[[:library-transform 0 0 1 0] [:edit 0 1 1 2]
|
||||
[:library-undo 0] [:undo] [:library-redo 0] [:redo]]]]
|
||||
(await (replay {:world [1 0 {:library true :library-depth 0 :library-grid true :stale-libraries true}]
|
||||
:ops ops}))))
|
||||
|
||||
(t/deftest ^:async two-source-editors-keep-their-histories-separate
|
||||
(await (replay {:world [1 0 {:library true :library-depth 0 :library-dependency true :stale-libraries true}]
|
||||
:ops [[:library-edit 0 0 1] [:library-edit 1 0 2]
|
||||
[:library-undo 0] [:library-undo 1]
|
||||
[:library-redo 0] [:library-redo 1]]})))
|
||||
|
||||
(t/deftest ^:async source-grid-acceptance-preserves-authored-cells-and-undo
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(let [initial (cg/world [1 0 {:library true :library-depth 0 :library-grid true :stale-libraries true}])
|
||||
edit (cg/resolve-op initial {} [:grid-cell 0 0 0 2])
|
||||
id (get-in edit [:shape :id])
|
||||
props (get-in edit [:op :value :props])
|
||||
live (ftm/start-generated initial)
|
||||
live (await (ftm/run-generated-step live (:op edit)))
|
||||
live (loop [live live tuples [[:library-add-child 0] [:library-add-child 0] [:edit 0 1 1 2]]]
|
||||
(if-let [tuple (first tuples)]
|
||||
(let [{:keys [op library-id]} (cg/resolve-op live {} tuple)
|
||||
after (if library-id
|
||||
(await (ftm/run-generated-source-step live library-id op))
|
||||
(await (ftm/run-generated-step live op)))]
|
||||
(recur after (rest tuples)))
|
||||
live))
|
||||
live (await (ftm/run-generated-step live (:op (cg/resolve-op live {} [:library-sync]))))
|
||||
shape (tm/shape-by-id live id)
|
||||
cell (first (filter #(= [1 1] [(:row %) (:column %)]) (vals (:layout-grid-cells shape))))]
|
||||
(t/is (some? (cthf/validate-file! (tm/file live) (cf/libraries live))))
|
||||
(t/is (= 5 (count (:shapes shape))))
|
||||
(t/is (= [2 3] (mapv #(count (get shape %)) [:layout-grid-rows :layout-grid-columns])))
|
||||
(t/is (= props (select-keys cell (keys props))))
|
||||
(t/is (empty? (uc/failures (await (ftm/finish-generated live)))))
|
||||
(ftm/uninstall!)))))
|
||||
|
||||
(t/deftest ^:async authored-grid-histories-use-independent-cell-expectations
|
||||
(doseq [ops [[[:grid-direction 0 0 1 1] [:grid-direction 0 0 1 0]
|
||||
[:grid-direction 0 0 0 0] [:update-main 0]
|
||||
[:grid-direction 0 0 0 1] [:reset 0] [:undo] [:redo]]
|
||||
[[:grid-cell 0 0 0 1] [:grid-cell 0 1 1 0] [:grid-cell 0 0 2 0]
|
||||
[:update-main 0] [:grid-cell 0 1 2 1] [:reset 0] [:undo] [:redo]]
|
||||
[[:grid-cell 0 0 0 1] [:duplicate 0] [:undo] [:redo] [:update-main 0]]
|
||||
[[:grid-direction 0 0 1 1] [:add-child 0] [:undo] [:redo]]
|
||||
[[:grid-cell 0 0 0 1] [:remove-child 0] [:undo] [:redo]]
|
||||
[[:grid-cell 0 0 0 1] [:detach 0] [:undo] [:redo]]]]
|
||||
(await (replay {:world [1 0 {:layout :grid :layout-children true :grid-square true}] :ops ops}))))
|
||||
|
||||
(t/deftest ^:async detaching-an-outer-copy-remaps-inherited-grid-cell-intent
|
||||
(await (replay {:world [1 1 {:layout :grid :layout-children true :grid-square true}]
|
||||
:ops [[:grid-cell 0 0 0 1] [:detach 0] [:undo] [:redo]]})))
|
||||
|
||||
(t/deftest ^:async layout-container-histories-survive-component-operations
|
||||
(doseq [[property layouts] [[20 [:flex]] [21 [:flex]] [22 [:flex :grid]] [23 [:flex :grid]]
|
||||
[24 [:flex :grid]] [25 [:flex :grid]] [26 [:grid]]]
|
||||
layout layouts]
|
||||
(await (replay {:world [1 0 {:layout layout :layout-children true}]
|
||||
:ops [[:style 0 property 1 1] [:style 0 property 1 0]
|
||||
[:style 0 property 0 0] [:undo] [:redo] [:update-main 0]
|
||||
[:style 0 property 0 1] [:reset 0]
|
||||
[:style 0 property 0 1] [:detach 0] [:undo] [:redo]]}))))
|
||||
|
||||
(t/deftest ^:async layout-item-histories-survive-component-operations
|
||||
(doseq [property (range 27 37)
|
||||
layout (if (= property 28) [:flex] [:flex :grid])]
|
||||
(let [authored (if (= property 27) 0 1)
|
||||
other (if (= property 27) 1 0)]
|
||||
(await (replay {:world [1 0 {:layout layout :layout-children true :layout-item-margins true}]
|
||||
:ops [[:style 0 property authored 1] [:style 0 property authored 0]
|
||||
[:style 0 property other 0] [:undo] [:redo] [:update-main 0]
|
||||
[:style 0 property other 1] [:reset 0]
|
||||
[:style 0 property other 1] [:detach 0] [:undo] [:redo]]})))))
|
||||
|
||||
(t/deftest ^:async hug-sizing-histories-survive-component-operations
|
||||
(doseq [property [29 30] layout [:flex :grid]]
|
||||
(await (replay {:world [1 0 {:layout layout :layout-children true :layout-copies true}]
|
||||
:ops [[:style 0 property 2 1] [:style 0 property 2 0] [:undo] [:redo]
|
||||
[:style 0 property 0 0] [:update-main 0]
|
||||
[:style 0 property 2 1] [:reset 0]
|
||||
[:style 0 property 2 1] [:detach 0] [:undo] [:redo]]}))))
|
||||
|
||||
(t/deftest ^:async adding-a-flex-child-before-making-a-copy-child-absolute-stays-settled
|
||||
(await (replay {:world [1 0 {:layout :flex :layout-children true}]
|
||||
:ops [[:add-child 0] [:style 2 35 1 1] [:undo] [:redo]]})))
|
||||
|
||||
(t/deftest ^:async nesting-a-copy-alongside-a-hidden-layout-child-stays-settled
|
||||
(await (replay {:world [3 0 {:text true :text-styles true :layout :flex}]
|
||||
:ops [[:delete 9 9 1 2] [:text 5 9 1 3] [:style 3 1 1]
|
||||
[:restore 5 8 1 6] [:nest 5 6 0 2] [:undo] [:redo]]})))
|
||||
|
||||
(t/deftest ^:async generated-effects-and-corners-survive-component-operations
|
||||
(doseq [property (range 14 20)]
|
||||
(await (replay {:world [2 1 {:variants true :rich-variants true}]
|
||||
:ops [[:style 0 property 1 1] [:style 1 property 1 0]
|
||||
[:undo] [:redo] [:update-main 0]
|
||||
[:style 0 property 0 1] [:reset 0]
|
||||
[:style 0 property 1 1] [:detach 0]
|
||||
[:undo] [:redo]]}))))
|
||||
|
||||
(t/deftest ^:async swapping-a-copy-with-authored-position-constraints-stays-settled
|
||||
(await (replay {:world [2 1 {:library true :variants true :rich-variants true
|
||||
@ -208,6 +842,14 @@
|
||||
(t/deftest ^:async nesting-restores-default-constraints-on-undo
|
||||
(await (replay {:world [2 0] :ops [[:nest 0]]})))
|
||||
|
||||
(t/deftest ^:async swap-programs-replay-through-the-frontend
|
||||
(doseq [seed [712 20261022]]
|
||||
(await (replay (gen/generate cg/swap-program-gen 5 seed)))))
|
||||
|
||||
(t/deftest ^:async variant-programs-replay-through-the-frontend
|
||||
(doseq [seed [712 20261022]]
|
||||
(await (replay (gen/generate cg/variant-program-gen 5 seed)))))
|
||||
|
||||
(t/deftest ^:async library-programs-replay-through-the-frontend
|
||||
(await (replay {:world [2 1 {:library true :variants true}]
|
||||
:ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync]
|
||||
@ -233,12 +875,44 @@
|
||||
[:undo] [:redo] [:reset 0] [:sync 1]
|
||||
[:switch 1 0 0 0] [:detach 0 0 0 0] [:delete 0 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async partial-sync-geometry-boundary-shrunk-regression
|
||||
(await (replay {:world [2 0 {:text true :layout nil}]
|
||||
:ops [[:add-child 0] [:remove-child 0] [:duplicate 0] [:nest 0]
|
||||
[:delete 0] [:restore 0] [:text 0 0 1] [:text 1 1 1]
|
||||
[:resize 0 0 2] [:rotate 0 0 0] [:reset 0]
|
||||
[:edit 0 0 1 1] [:update-main 0] [:sync 1]
|
||||
[:detach 0] [:undo] [:redo] [:undo 0 0 0 0]
|
||||
[:add-child 17 0 0 0] [:rotate 19 0 0 0] [:undo 0 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async update-main-after-nesting-a-rotated-text-copy-undoes-together
|
||||
(await (replay {:world [2 0 {:text true}]
|
||||
:ops [[:duplicate 0] [:nest 0] [:rotate 0 0 0]
|
||||
[:edit 0 0 1 1] [:update-main 0]]})))
|
||||
|
||||
(t/deftest ^:async updating-main-then-swapping-a-child-restores-parent-state
|
||||
(await (replay {:world [2 1 {:library true :variants true}]
|
||||
:ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync]
|
||||
[:undo] [:redo] [:reset 0] [:sync 1]
|
||||
[:switch 5 0 0 0] [:update-main 0 0 0 0] [:swap 13 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async swapping-main-subtrees-with-several-children-undoes-their-order
|
||||
(await (replay {:world [2 2 {:variants true :variant-diff false}]
|
||||
:ops [[:edit 0 0 1 1] [:switch 0] [:switch 0] [:swap 0]
|
||||
[:undo] [:redo] [:reset 0] [:edit 0 1 1 1]
|
||||
[:update-main 0] [:sync 1] [:add-child 1 0 0 0]
|
||||
[:add-child 1 0 0 0] [:add-child 1 0 0 0]
|
||||
[:swap 0 0 0 0] [:swap 0 0 0 0] [:text 0 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async updating-a-rotated-outer-main-composes-authored-child-orientation
|
||||
(await (replay {:world [2 0 {:text true :layout nil}]
|
||||
:ops [[:add-child 0] [:remove-child 0] [:duplicate 0] [:nest 0]
|
||||
[:delete 0] [:restore 0] [:text 0 0 1] [:text 1 1 1]
|
||||
[:resize 0 0 2] [:rotate 0 0 0] [:reset 0]
|
||||
[:edit 0 0 1 1] [:update-main 0] [:sync 1]
|
||||
[:detach 0] [:undo] [:redo] [:duplicate 0 0 0 0]
|
||||
[:resize 0 0 0 0] [:nest 0 0 0 0] [:rotate 4 0 0 0]
|
||||
[:detach 3 0 0 0] [:update-main 4 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async updating-a-duplicated-switched-copy-restores-the-main-order
|
||||
(await (replay {:world [2 1 {:library true :variants true}]
|
||||
:ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync]
|
||||
@ -253,24 +927,71 @@
|
||||
[:rotate 1 0 0 0] [:detach 1 0 0 0]
|
||||
[:detach 2 0 0 0] [:resize 2 0 0 0] [:switch 2 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async minimum-size-parent-orientation-does-not-amplify-oracle-drift
|
||||
(await (replay {:world [3 0 {:text true :layout nil}]
|
||||
:ops [[:add-child 0] [:remove-child 0] [:duplicate 0] [:nest 0]
|
||||
[:delete 0] [:restore 0] [:text 0 0 1] [:text 1 1 1]
|
||||
[:resize 0 0 2] [:rotate 0 0 0] [:reset 0]
|
||||
[:edit 0 0 1 1] [:update-main 0] [:sync 1]
|
||||
[:detach 0] [:undo] [:redo] [:edit 4 0 0 0]
|
||||
[:duplicate 3 0 0 0] [:nest 10 0 0 0] [:rotate 9 0 0 0]
|
||||
[:update-main 7 0 0 0] [:delete 0 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async detaching-a-rotated-parent-inherits-geometry-in-the-copy-frame
|
||||
(await (replay {:world [2 0 {:text true :layout nil}]
|
||||
:ops [[:add-child 0] [:remove-child 0] [:duplicate 0] [:nest 0]
|
||||
[:delete 0] [:restore 0] [:text 0 0 1] [:text 1 1 1]
|
||||
[:resize 0 0 2] [:rotate 0 0 0] [:reset 0]
|
||||
[:edit 0 0 1 1] [:update-main 0] [:sync 1]
|
||||
[:detach 0] [:undo] [:redo] [:resize 0 0 0 0]
|
||||
[:delete 0 0 0 0] [:rotate 0 0 0 0] [:detach 0 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async switching-a-copy-of-a-swap-keeps-position-overrides-inherited
|
||||
(await (replay {:world [2 1 {:library true :variants true}]
|
||||
:ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync]
|
||||
[:undo] [:redo] [:reset 0] [:sync 1]
|
||||
[:switch 13 0 0 0] [:rotate 0 0 0 0] [:switch 2 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async rotated-swapped-head-keeps-its-position-anchor-with-a-different-content-size
|
||||
(await (replay {:world [2 2 {:variants true :variant-diff false}]
|
||||
:ops [[:edit 0 0 1 1] [:switch 0] [:switch 0] [:swap 0]
|
||||
[:undo] [:redo] [:reset 0] [:edit 0 1 1 1] [:update-main 0]
|
||||
[:sync 1] [:swap 17 0 0 0] [:resize 0 0 0 0] [:rotate 0 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async pushing-a-swap-keeps-the-orientation-inherited-from-its-position
|
||||
(await (replay {:world [2 1 {:library true :variants true}]
|
||||
:ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync]
|
||||
[:undo] [:redo] [:reset 0] [:sync 1]
|
||||
[:rotate 0 0 0 0] [:swap 13 0 0 0] [:update-main 1 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async resizing-a-copy-of-an-empty-flex-main-keeps-layout-valid
|
||||
(await (replay {:world [3 0 {:text true :layout :flex}]
|
||||
:ops [[:add-child 0] [:remove-child 0] [:duplicate 0] [:nest 0]
|
||||
[:delete 0] [:restore 0] [:text 0 0 1] [:text 1 1 1]
|
||||
[:resize 0 0 2] [:rotate 0 0 0] [:reset 0]
|
||||
[:edit 0 0 1 1] [:update-main 0] [:sync 1]
|
||||
[:detach 0] [:undo] [:redo] [:remove-child 0 0 0 0]
|
||||
[:reset 0 0 0 0] [:nest 0 0 0 0] [:resize 0 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async updating-a-main-after-successive-rotations-keeps-child-flips
|
||||
(await (replay {:world [2 1]
|
||||
:ops [[:rotate 1 0 0 0] [:rotate 1 0 1 0] [:update-main 0 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async pushing-a-switched-child-uses-its-parents-pushed-frame
|
||||
(await (replay {:world [2 1 {:library true :variants true}]
|
||||
:ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync]
|
||||
[:undo] [:redo] [:reset 0] [:sync 1]
|
||||
[:switch 5 0 0 0] [:rotate 1 0 0 0] [:update-main 0 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async minimum-size-parent-placement-keeps-fixed-child-dimensions
|
||||
(await (replay {:world [2 0 {:text true :layout nil}]
|
||||
:ops [[:add-child 0] [:remove-child 0] [:duplicate 0] [:nest 0]
|
||||
[:delete 0] [:restore 0] [:text 0 0 1] [:text 1 1 1]
|
||||
[:resize 0 0 2] [:rotate 0 0 0] [:reset 0]
|
||||
[:edit 0 0 1 1] [:update-main 0] [:sync 1]
|
||||
[:detach 0] [:undo] [:redo] [:resize 1 0 0 0]
|
||||
[:nest 2 0 0 0] [:rotate 0 0 3 0] [:edit 0 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async generated-library-pushed-swap-authors-content-against-its-new-position
|
||||
(await (replay {:world [2 1 {:library true :variants true}]
|
||||
:ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync]
|
||||
@ -305,6 +1026,12 @@
|
||||
:ops [[:swap 0 0 0 0] [:text 23 3 1 0] [:text-style 22 8 1]
|
||||
[:undo] [:undo] [:undo] [:redo] [:redo] [:redo]]})))
|
||||
|
||||
(t/deftest ^:async typography-ownership-stays-consistent-when-a-variant-changes-size
|
||||
(await (replay {:world [2 0 {:library true :variants true :rich-variants true
|
||||
:text true :text-styles true :layout nil :layout-copies true}]
|
||||
:ops [[:text-style 4 8 1] [:switch 1 0 0 0]
|
||||
[:undo] [:undo] [:redo] [:redo]]})))
|
||||
|
||||
(t/deftest ^:async detaching-after-a-nested-switch-keeps-placement-stable-through-sync
|
||||
(await (replay {:world [2 2 {:library true :variants true :rich-variants true
|
||||
:text true :text-styles true :layout :flex :layout-copies true}]
|
||||
@ -318,6 +1045,22 @@
|
||||
[:delete 0 0 0 0] [:delete 3 0 0 0] [:resize 0 0 0 0]
|
||||
[:delete 9 0 0 0] [:switch 0 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async switching-an-untouched-rotated-copy-survives-full-sync
|
||||
(await (replay {:world [3 2 {:variants true :variant-diff false}]
|
||||
:ops [[:edit 0 0 1 1] [:switch 0] [:switch 0] [:swap 0] [:undo] [:redo]
|
||||
[:reset 0] [:edit 0 1 1 1] [:update-main 0] [:sync 1]
|
||||
[:edit 11 0 0 0] [:rotate 2 0 0 0] [:nest 3 0 0 0] [:resize 3 0 0 0]
|
||||
[:nest 3 0 0 0] [:swap 10 0 0 0] [:resize 3 0 0 0]
|
||||
[:update-main 5 0 0 0] [:switch 0 0 0 0] [:detach 0 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async switch-keeps-retained-orientation-together-with-carried-size
|
||||
(await (replay {:world [2 2 {:variants true :variant-diff false}]
|
||||
:ops [[:edit 0 0 1 1] [:switch 0] [:switch 0] [:swap 0] [:undo] [:redo]
|
||||
[:reset 0] [:edit 0 1 1 1] [:update-main 0] [:sync 1]
|
||||
[:swap 0 0 0 0] [:delete 0 0 0 0] [:rotate 0 0 0 0]
|
||||
[:nest 0 0 0 0] [:detach 0 0 0 0] [:update-main 0 0 0 0]
|
||||
[:switch 0 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async generated-library-duplicate-refuses-an-expanding-component-branch
|
||||
(await (replay {:world [2 1 {:library true :variants true}]
|
||||
:ops [[:edit 0 0 1 2] [:update-main 0] [:library-sync]
|
||||
@ -350,3 +1093,11 @@
|
||||
[:undo] [:redo] [:reset 0] [:sync 1]
|
||||
[:switch 1 0 0 0] [:rotate 1 0 0 0] [:duplicate 0 0 0 0]
|
||||
[:reset 2 0 0 0] [:redo 0 0 0 0]]})))
|
||||
|
||||
(t/deftest ^:async generated-update-main-settles-a-turned-swapped-position
|
||||
(await (replay {:world [2 2 {:variants true :variant-diff false}]
|
||||
:ops [[:edit 0 0 1 1] [:switch 0] [:switch 0] [:swap 0] [:undo] [:redo]
|
||||
[:reset 0] [:edit 0 1 1 1] [:update-main 0] [:sync 1]
|
||||
[:delete 8 0 0 0] [:swap 15 0 0 0] [:edit 14 0 0 0]
|
||||
[:resize 4 0 0 0] [:resize 0 0 0 0] [:nest 4 0 0 0]
|
||||
[:rotate 5 0 0 0] [:update-main 14 0 0 0] [:duplicate 0 0 0 0]]})))
|
||||
|
||||
@ -9,42 +9,42 @@
|
||||
:case-ac-second-variant-switch-keeps-root-overrides
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 3}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :opacity, :value 0.5}\n {:target #fn, :value \"b\", :pos 0}\n \n {:target #fn, :value \"c\", :pos 0}", :states ["45b82e3d3433e503" "6aa8b050f6e60b75" "2464ce46aa6d70f8" "83ae3b7689a44277"]}]
|
||||
:case-ad-update-main-pushes-a-swapped-child
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"s1\", :id sync-s1-component}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:component \"main\", :copy sync-main-copyhead-1}\n {:target #fn, :to \"s1\", :keep-touched? false}\n {:target #fn}", :states ["70154c2f90c4d94f" "8276a39e105869aa" "60ae4e382dab157a"]}]
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"s1\", :id sync-s1-component}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:component \"main\", :copy sync-main-copyhead-1}\n {:target #fn, :to \"s1\", :keep-touched? false}\n {:target #fn}", :states ["70154c2f90c4d94f" "81f3d357f0dbb315" "c88064e53602169d"]}]
|
||||
:case-ae-detached-or-duplicated-swapped-copy-follows-its-component
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"s1\", :id sync-s1-component}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :to \"s1\", :keep-touched? false}\n {:target #fn}\n {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["d74e87bca3fa2eb9" "ffc66442a5849acd" "ad43d75dcc79bc8a" "6fa02ad66793cf43"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"s1\", :id sync-s1-component}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :to \"s1\", :keep-touched? false}\n {:target #fn, :new-head 5}\n {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["d74e87bca3fa2eb9" "e2162174653b4d7b" "0bd8763796243e1f" "f612d9fde86170a6"]}]
|
||||
:case-af-grid-cell-move-reaches-a-swapped-copy-child
|
||||
[{:transcript " {:target :copy-child, :to :other, :keep-touched? false}\n {:board :main-root, :child :main-child, :row 1, :column 3}", :states ["5a6af6c0b8f86ac3" "ec2294c072f52ae5" "8cd63b096547fb1b"]}
|
||||
[{:transcript " {:target :copy-child, :to :other, :keep-touched? false}\n {:board :main-root, :child :main-child, :row 1, :column 3}", :states ["66a66d6e7afac79f" "72c68fd299002108" "a8170f02220c56c3"]}
|
||||
{:transcript "one-of -> \n {:board :main-root, :child :main-child, :row 1, :column 3}", :states ["ab911a9c4ef389ba" "56df09285036aa60"]}]
|
||||
:case-ag-main-reorder-keeps-copy-sub-heads-aligned
|
||||
[{:transcript " {:target :sub1, :parent :row-root, :to-index 3}", :states ["8118be0e3d318e30" "e0d17dd4c27d652c"]}]
|
||||
[{:transcript " {:target :sub1, :parent :row-root, :to-index 3}", :states ["598fcda0ce7604ff" "bf7fbe3947f98e57"]}]
|
||||
:case-ah-copy-sub-head-delete-keeps-others-aligned
|
||||
[{:transcript "one-of -> \n {:target :copy-sub1}", :states ["fff37cf722a40e61" "6fd3a8bad999968b"]}
|
||||
{:transcript "one-of -> \n {:target :copy-sub3}", :states ["efada86db353920f" "3364b0fbfb76067a"]}
|
||||
[{:transcript "one-of -> \n {:target :copy-sub1}", :states ["8cce96ea845f126a" "9fbdeb6913ed25c7"]}
|
||||
{:transcript "one-of -> \n {:target :copy-sub3}", :states ["2fb52dd7ebffcfc2" "6daed3c2ff997a9f"]}
|
||||
{:transcript "one-of -> ", :states ["94318a628db305b6"]}]
|
||||
:case-ai-copy-sub-head-delete-and-reflow-keeps-others-aligned
|
||||
[{:transcript "one-of -> \n {:target :copy-sub1}\n {:target :copy-root, :value 500}", :states ["fff37cf722a40e61" "738377a4c5ef9f3c" "f23a64d143d27dba"]}
|
||||
{:transcript "one-of -> \n {:target :copy-sub1}\n one-of -> ", :states ["fff37cf722a40e61" "6fd3a8bad999968b"]}
|
||||
{:transcript "one-of -> \n {:target :copy-sub3}\n {:target :copy-root, :value 500}", :states ["efada86db353920f" "701edc575ad9c0c6" "91db7f5306659911"]}
|
||||
{:transcript "one-of -> \n {:target :copy-sub3}\n one-of -> ", :states ["efada86db353920f" "3364b0fbfb76067a"]}
|
||||
[{:transcript "one-of -> \n {:target :copy-sub1}\n {:target :copy-root, :value 500}", :states ["8cce96ea845f126a" "259a2b096309de89" "57cee31291838076"]}
|
||||
{:transcript "one-of -> \n {:target :copy-sub1}\n one-of -> ", :states ["8cce96ea845f126a" "9fbdeb6913ed25c7"]}
|
||||
{:transcript "one-of -> \n {:target :copy-sub3}\n {:target :copy-root, :value 500}", :states ["2fb52dd7ebffcfc2" "4a9ca18246cd24c1" "d7816b420adf634f"]}
|
||||
{:transcript "one-of -> \n {:target :copy-sub3}\n one-of -> ", :states ["2fb52dd7ebffcfc2" "6daed3c2ff997a9f"]}
|
||||
{:transcript "one-of -> \n {:target :copy-root, :value 500}", :states ["000943ecb6c266ee" "209fe67d76a27a9b"]}
|
||||
{:transcript "one-of -> \n one-of -> ", :states ["94318a628db305b6"]}]
|
||||
: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" "ce4ef0e73faa0894" "ef4de3d8d773582c"]}]
|
||||
[{: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 ["5a6af6c0b8f86ac3" "278e4ff6bf0df746" "322e03c88f4a9dce" "432cfef7e9b05164"]}
|
||||
[{: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"]}]
|
||||
: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"]}]
|
||||
:case-am-update-main-pushes-a-swap-inside-a-group
|
||||
[{:transcript " {:target :copy-child, :to :other, :keep-touched? false}\n {:target :copy-root}", :states ["b4f808a12f723283" "9b695fc212f26b53" "32b94deb961ac763"]}]
|
||||
[{:transcript " {:target :copy-child, :to :other, :keep-touched? false}\n {:target :copy-root}", :states ["4557971332d8f7c5" "48ecf8dc450dbc1f" "b02f397b60c6c6ca"]}]
|
||||
:case-an-flex-child-override-follows-sync-reset-and-update-main
|
||||
[{:transcript " {:target :copy-instance, :property :margin, :value 8}\n {:target :main-instance, :property :margin, :value 20}", :states ["234a21e54bf21bd5" "03664b1e6eb74856" "820db97e4e4b43dc"]}
|
||||
{:transcript " {:target :copy-instance, :property :margin, :value 8}\n {:target :copy-root}", :states ["234a21e54bf21bd5" "1f92f9b4d2e50598" "a09954797e57930c"]}
|
||||
{:transcript " {:target :copy-instance, :property :margin, :value 8}\n {:target :copy-root}", :states ["234a21e54bf21bd5" "ace1e76c1da2c443" "8f3452e82544f1ad"]}]
|
||||
:case-ao-copy-dropped-into-a-grid-cell-reaches-copies
|
||||
[{:transcript " {:copy :loose, :into :main-root, :cell [1 3]}", :states ["abc6e41a291516a2" "571d314ba8917a08"]}]
|
||||
[{:transcript " {:copy :loose, :into :main-root, :cell [1 3]}", :states ["85c7e7a4f4289716" "a00c83f43550909b"]}]
|
||||
:case-ap-library-main-child-removal-reaches-copy
|
||||
[{:transcript "", :states ["dd877acf0d7f120c" "0a472792b8a73e33"]}]
|
||||
:case-aq-main-change-reaches-a-copy-nested-in-a-sub-board
|
||||
@ -56,8 +56,8 @@
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:set-name \"vset\", :edit :add, :params {:property-name \"Size\", :property-value \"S\"}}\n {:set-name \"vset\", :edit :reorder, :params {:from 1, :to 0}}\n \n {:target #fn, :value \"b\", :pos #fn}", :states ["df9a042b9d59d699" "c4f5353ee8eb5822" "20e7c6031f77998f" "4b387428cd241ed1" "a79933f2d6da95da"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:set-name \"vset\", :edit :add, :params {:property-name \"Size\", :property-value \"S\"}}\n {:set-name \"vset\", :edit :remove, :params {:pos 1}}\n \n {:target #fn, :value \"b\", :pos #fn}", :states ["df9a042b9d59d699" "c4f5353ee8eb5822" "df9a042b9d59d699" "ef6a99bd8579dc7f" "3b1bfc8427b3963d"]}]
|
||||
:case-as-added-variant-is-a-switch-target
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:set-name \"vset\", :member \"a\", :component-id 7}\n \n {:target #fn, :value \"Value 3\", :pos 0}", :states ["df9a042b9d59d699" "00b4a79bae39f703" "0b85fa1611096bb7" "542884fb9e0b082e"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:set-name \"vset\", :member \"b\", :component-id 7}\n \n {:target #fn, :value \"Value 3\", :pos 0}", :states ["df9a042b9d59d699" "73a3942a18403d5e" "3234ee274caa5b9e" "0fd372565af6eae2"]}]
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:set-name \"vset\", :member \"a\", :component-id 7}\n \n {:target #fn, :value \"Value 3\", :pos 0}", :states ["df9a042b9d59d699" "43d53bfb72ea0e0c" "6d809ac935ee93e1" "144104054c2e6b3e"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:set-name \"vset\", :member \"b\", :component-id 7}\n \n {:target #fn, :value \"Value 3\", :pos 0}", :states ["df9a042b9d59d699" "06e9af57624cd581" "55609c964d15c784" "c8d9eaf05aa22931"]}]
|
||||
:case-at-transformed-component-keeps-its-copies
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:target #fn, :property :name, :value \"Button/Primary\"}\n {:action :transform, :params {:target #fn}}\n \n {:target #fn, :value \"Value 2\", :pos 0}", :states ["19168567c3f4c8b1" "865741f5dae8819e" "7f7bd28b4563fabd" "bca3e99455b8e931" "f8be77e905b63d2f"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:target #fn, :property :name, :value \"Button/Primary\"}\n {:action :shortcut, :params {:kind :create-component, :targets [#fn]}}\n \n {:target #fn, :value \"Value 2\", :pos 0}", :states ["19168567c3f4c8b1" "865741f5dae8819e" "7f7bd28b4563fabd" "bca3e99455b8e931" "f8be77e905b63d2f"]}
|
||||
@ -72,10 +72,10 @@
|
||||
:case-aw-variant-layer-rename-and-cleanup
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:set-name \"vset\", :edit :rename-in-layers, :params {:member \"a\", :name \"Property 1=a2, Size=S\"}}\n \n {:set-name \"vset\", :edit :add, :params {:property-name \"Empty\"}}\n {:set-name \"vset\", :edit :remove-empty, :params {}}\n \n {:set-name \"vset\", :edit :rename-in-layers, :params {:member \"a\", :name \"Property 1=a2\"}}\n \n {:set-name \"vset\", :edit :error, :params {:member \"b\", :value \"Duplicated\"}}\n \n {:set-name \"vset\", :edit :error, :params {:member \"b\", :value nil}}\n \n {:target #fn, :value \"b\", :pos 0}", :states ["df9a042b9d59d699" "4b53486972986d97" "8553f89a9ebbcf54" "4b53486972986d97" "d65ad905aa97d661" "6daf5f692c6595f1" "d65ad905aa97d661" "cc7d2dfd618fc8cb" "6390b4d83995b629"]}]
|
||||
:case-ax-variant-shortcuts-add-members
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :create-component, :targets [#fn]}}", :states ["df9a042b9d59d699" "00b4a79bae39f703" "3c821d5f87436799"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :duplicate, :targets [#fn]}}", :states ["df9a042b9d59d699" "00b4a79bae39f703" "3c821d5f87436799"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :create-component, :targets [#fn #fn]}}", :states ["df9a042b9d59d699" "07e820c7c676a7b0" "d3972300b9f78ab6"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :duplicate, :targets [#fn #fn]}}", :states ["df9a042b9d59d699" "07e820c7c676a7b0" "d3972300b9f78ab6"]}]
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :create-component, :targets [#fn]}}", :states ["df9a042b9d59d699" "43d53bfb72ea0e0c" "419f9e2fc8ad2835"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :duplicate, :targets [#fn]}}", :states ["df9a042b9d59d699" "43d53bfb72ea0e0c" "419f9e2fc8ad2835"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :create-component, :targets [#fn #fn]}}", :states ["df9a042b9d59d699" "cc394d17823fd4a0" "c3e08163f30218ee"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :duplicate, :targets [#fn #fn]}}", :states ["df9a042b9d59d699" "cc394d17823fd4a0" "c3e08163f30218ee"]}]
|
||||
:case-ay-token-on-a-main-reaches-copies
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:tokens [[\"radius.s\" 10] [\"radius.l\" 30]]}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :token-name \"radius.s\", :value 10}\n {:target #fn, :token-name \"radius.l\", :value 30}\n \n {:target #fn, :token-name \"radius.l\"}", :states ["04cddffca776d7fb" "24756b13d210f3a5" "8e8c0c21d4a0638b" "f656f9c8188793cf"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:tokens [[\"radius.s\" 10] [\"radius.l\" 30]]}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :token-name \"radius.s\", :value 10}\n {:target #fn, :token-name \"radius.l\", :value 30}\n \n one-of -> ", :states ["04cddffca776d7fb" "24756b13d210f3a5" "8fb17ce46cb883c8"]}
|
||||
@ -156,12 +156,12 @@
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 4}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n {:component \"main\", :level 2, :outer sync-main-outercomp-2}\n one-of -> \n one-of -> \n {:target #fn, :value \"v3\", :pos 0}\n ", :states ["5465856887185ca0" "72519cdcd7188cc4"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 4}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n {:component \"main\", :level 2, :outer sync-main-outercomp-2}\n one-of -> \n one-of -> \n one-of -> \n ", :states ["0873995f173d4a79"]}]
|
||||
:case-n-geometry-sync-with-rotated-instances
|
||||
[{:transcript " {:target :copy-root, :angle 45}\n {:target :main-root, :angle 30}\n {:target :main-instance, :property :fills, :value \"#ff0000\"}", :states ["ba9a6dac13f812ea" "53df1008cfc253d9" "5209d5674c0f3d7d" "25decd78552afde5"]}
|
||||
{:transcript " {:target :copy-root, :angle 45}\n {:target :main-root, :angle 30}\n {:target :main-instance, :value 80}", :states ["ba9a6dac13f812ea" "53df1008cfc253d9" "3770b3227c55f2e3" "3e932096c59afd2a"]}
|
||||
{:transcript " {:target :copy-root, :angle 45}\n one-of -> \n {:target :main-instance, :property :fills, :value \"#ff0000\"}", :states ["ba9a6dac13f812ea" "65ca84670680dd3f" "a920758fa5650950"]}
|
||||
{:transcript " {:target :copy-root, :angle 45}\n one-of -> \n {:target :main-instance, :value 80}", :states ["ba9a6dac13f812ea" "3f78d8893ed44646" "ca1b4068acd4cf89"]}
|
||||
{:transcript "one-of -> \n {:target :main-root, :angle 30}\n {:target :main-instance, :property :fills, :value \"#ff0000\"}", :states ["9209eb7b4ee877fa" "594405b1ecce4064" "9db6f380604b2fea"]}
|
||||
{:transcript "one-of -> \n {:target :main-root, :angle 30}\n {:target :main-instance, :value 80}", :states ["9209eb7b4ee877fa" "1834062b7878fd2f" "85d3c98c7713553c"]}
|
||||
[{:transcript " {:target :copy-root, :angle 45}\n {:target :main-root, :angle 30}\n {:target :main-instance, :property :fills, :value \"#ff0000\"}", :states ["ba9a6dac13f812ea" "f9c9816d219be30f" "1da4ef3fd7539967" "e97f83d8765a6827"]}
|
||||
{:transcript " {:target :copy-root, :angle 45}\n {:target :main-root, :angle 30}\n {:target :main-instance, :value 80}", :states ["ba9a6dac13f812ea" "f9c9816d219be30f" "f52c95e4327e5574" "16d5d8c4d1e8814d"]}
|
||||
{:transcript " {:target :copy-root, :angle 45}\n one-of -> \n {:target :main-instance, :property :fills, :value \"#ff0000\"}", :states ["ba9a6dac13f812ea" "7cc176e75ac6ab1f" "b68a7fecbc6cd3cc"]}
|
||||
{:transcript " {:target :copy-root, :angle 45}\n one-of -> \n {:target :main-instance, :value 80}", :states ["ba9a6dac13f812ea" "4e32cd4839852407" "c5f366418f7f4cdf"]}
|
||||
{:transcript "one-of -> \n {:target :main-root, :angle 30}\n {:target :main-instance, :property :fills, :value \"#ff0000\"}", :states ["483eb80a902eacfa" "e114d8a40d0ce273" "bb70b68365bdacc0"]}
|
||||
{:transcript "one-of -> \n {:target :main-root, :angle 30}\n {:target :main-instance, :value 80}", :states ["483eb80a902eacfa" "a7012e0e406ede72" "dcc10b7c43621315"]}
|
||||
{:transcript "one-of -> \n one-of -> \n {:target :main-instance, :property :fills, :value \"#ff0000\"}", :states ["386e940ac63af4b1" "8f48f693ee787fec"]}
|
||||
{:transcript "one-of -> \n one-of -> \n {:target :main-instance, :value 80}", :states ["a41078de929e10aa" "76237d559c31a37e"]}]
|
||||
:case-o-variant-switch-keeps-override-only-where-mains-agree
|
||||
@ -194,10 +194,10 @@
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:target #fn, :new-head 8}\n {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["170f05fe60d794fb" "6f95a0e52dbc58f3" "1682e155232c79ff" "7e41824902c17537"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n {:component \"main\", :level 1, :outer sync-main-outercomp-1}\n {:component \"main\", :copy sync-main-copyhead-0}\n one-of -> \n {:target #fn, :new-head 8}\n {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["e09ce2b9958878d1" "59617d71e336c70c" "4f37d9c4a6c72163"]}]
|
||||
:case-touched-copy-child-survives-main-rotation
|
||||
[{:transcript " {:target :copy-root, :angle 30}\n {:target :copy-instance, :value 60}\n \n {:target :main-root, :angle 40}", :states ["4b1199b00726b9ad" "cfb4d7484a4abd78" "f4cf8a16c5457089" "fa0aab3b284e3448"]}]
|
||||
[{:transcript " {:target :copy-root, :angle 30}\n {:target :copy-instance, :value 60}\n \n {:target :main-root, :angle 40}", :states ["e5382e7917232740" "b210314af79df750" "81f04c0e4b057fdf" "c54b585f599dc249"]}]
|
||||
:case-u-nested-copy-reaches-copies-of-the-receiving-main
|
||||
[{:transcript " {:component \"outer\", :id sync-outer-component}\n {:component \"inner\", :id sync-inner-component}\n {:component \"outer\", :copy sync-outer-copyhead-0}\n {:component \"inner\", :copy sync-inner-copyhead-0}\n {:copy #fn, :into #fn, :cell nil}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["3e741919b165a9b1" "3b36d2a788757ccf" "13cc7bde13f6db61" "d2df2363c6fd87ee"]}
|
||||
{:transcript " {:component \"outer\", :id sync-outer-component}\n {:component \"inner\", :id sync-inner-component}\n {:component \"outer\", :copy sync-outer-copyhead-0}\n {:component \"inner\", :copy sync-inner-copyhead-0}\n {:copy #fn, :into #fn, :cell nil}\n one-of -> \n {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["3e741919b165a9b1" "20ac8b615e23f0ea" "3b80647668a43256"]}]
|
||||
[{:transcript " {:component \"outer\", :id sync-outer-component}\n {:component \"inner\", :id sync-inner-component}\n {:component \"outer\", :copy sync-outer-copyhead-0}\n {:component \"inner\", :copy sync-inner-copyhead-0}\n {:copy #fn, :into #fn, :cell nil}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["9e0426e1dc456cde" "eb401f2227844ad7" "13cc7bde13f6db61" "d2df2363c6fd87ee"]}
|
||||
{:transcript " {:component \"outer\", :id sync-outer-component}\n {:component \"inner\", :id sync-inner-component}\n {:component \"outer\", :copy sync-outer-copyhead-0}\n {:component \"inner\", :copy sync-inner-copyhead-0}\n {:copy #fn, :into #fn, :cell nil}\n one-of -> \n {:target #fn, :property :fills, :value \"#0000ff\"}", :states ["9e0426e1dc456cde" "20ac8b615e23f0ea" "3b80647668a43256"]}]
|
||||
:case-v-new-edit-after-undo-clears-redo
|
||||
[{:transcript " {:target :main-instance, :property :fills, :value \"#ff0000\"}\n {:times 1}\n {:target :main-instance, :property :fills, :value \"#00ff00\"}\n {:times 1}\n \n ", :states ["386e940ac63af4b1" "734ec524d88eb6bb" "2249ff7b4eb6cdaa" "734ec524d88eb6bb" "2249ff7b4eb6cdaa" "2249ff7b4eb6cdaa" "fb1a35e87f575e72"]}]
|
||||
:case-w-undo-several-steps-over-nested-cascades
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
(ns frontend-tests.composable-tests.grid-layout-test
|
||||
(:require
|
||||
[app.common.logic.shapes :as cls]
|
||||
@ -44,6 +50,45 @@
|
||||
(thc/instantiate-component :component :copy)
|
||||
(thc/instantiate-component :component :other))))
|
||||
|
||||
(defn- get-shape
|
||||
[label]
|
||||
(ths/get-shape (ftm/current-file) label))
|
||||
|
||||
(defn- get-cells
|
||||
"Compare placements through source identities, without the production grid helpers."
|
||||
[label]
|
||||
(let [file (ftm/current-file)]
|
||||
(->> (:layout-grid-cells (ths/get-shape file label))
|
||||
vals
|
||||
(sort-by (juxt :row :column))
|
||||
(mapv (fn [cell]
|
||||
(-> cell
|
||||
(dissoc :id)
|
||||
(update :shapes #(mapv (fn [id]
|
||||
(or (:shape-ref (ths/get-shape-by-id file id)) id)) %))))))))
|
||||
|
||||
(defn- get-cell-ids
|
||||
[label]
|
||||
(->> (:layout-grid-cells (get-shape label)) vals (sort-by (juxt :row :column)) (mapv :id)))
|
||||
|
||||
(defn- check-clean-children
|
||||
[label]
|
||||
(let [file (ftm/current-file)]
|
||||
(doseq [id (:shapes (get-shape label))]
|
||||
(t/is (empty? (:touched (ths/get-shape-by-id file id)))))))
|
||||
|
||||
(defn- ^:async apply-step
|
||||
"Every user event and its derived work must undo and redo in one exact step."
|
||||
[event]
|
||||
(let [before (ftm/snapshot)]
|
||||
(t/is (= :settled (await (ftm/await-step [event]))))
|
||||
(let [after (ftm/snapshot)]
|
||||
(t/is (not (uc/same-state? before after)) "The user action must change the file")
|
||||
(t/is (= :settled (await (ftm/await-step [dwu/undo]))))
|
||||
(t/is (uc/same-state? before (ftm/snapshot)))
|
||||
(t/is (= :settled (await (ftm/await-step [dwu/redo]))))
|
||||
(t/is (uc/same-state? after (ftm/snapshot))))))
|
||||
|
||||
(defn- ^:async install-grid
|
||||
([]
|
||||
(await (install-grid cls/initial-grid-layout)))
|
||||
@ -125,3 +170,85 @@
|
||||
(t/is (uc/same-state? before (ftm/snapshot))))
|
||||
(t/is (empty? (uc/failures (await (ftm/finish-generated (ftm/refresh-generated grown))))))
|
||||
(ftm/uninstall!))))))
|
||||
|
||||
(t/deftest ^:async grid-direction-overrides-survive-main-edits-update-main-and-reset
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(await (install-grid))
|
||||
(let [row-cells (get-cells :main)
|
||||
column-cells (mapv #(assoc %1 :shapes [(thi/id %2)]) row-cells [:a :c :b :d])
|
||||
main-order (:shapes (get-shape :main))
|
||||
copy-order (:shapes (get-shape :copy))
|
||||
other-order (:shapes (get-shape :other))]
|
||||
(t/is (= (mapv #(vector (thi/id %)) [:a :b :c :d]) (mapv :shapes row-cells)))
|
||||
(await (apply-step (dwsl/change-grid-direction [(thi/id :copy)] :column)))
|
||||
(t/is (= :column (:layout-grid-dir (get-shape :copy))))
|
||||
(t/is (= column-cells (get-cells :copy)))
|
||||
(t/is (= row-cells (get-cells :main) (get-cells :other)))
|
||||
(t/is (= #{:layout-grid-dir :layout-grid-cells} (:touched (get-shape :copy))))
|
||||
(check-clean-children :copy)
|
||||
|
||||
(await (apply-step (dwsl/change-grid-direction [(thi/id :main)] :column)))
|
||||
(t/is (= column-cells (get-cells :main) (get-cells :copy) (get-cells :other)))
|
||||
(t/is (= :column (:layout-grid-dir (get-shape :other))))
|
||||
(t/is (= #{:layout-grid-dir :layout-grid-cells} (:touched (get-shape :copy))))
|
||||
(t/is (empty? (:touched (get-shape :other))))
|
||||
|
||||
(await (apply-step (dwsl/change-grid-direction [(thi/id :main)] :row)))
|
||||
(t/is (= row-cells (get-cells :main) (get-cells :other)))
|
||||
(t/is (= column-cells (get-cells :copy)))
|
||||
(t/is (= :column (:layout-grid-dir (get-shape :copy))))
|
||||
|
||||
(await (apply-step (dwl/update-component-sync (thi/id :copy) (:id (ftm/current-file)))))
|
||||
(t/is (= column-cells (get-cells :main) (get-cells :copy) (get-cells :other)))
|
||||
(t/is (= [:column :column :column] (mapv #(:layout-grid-dir (get-shape %)) [:main :copy :other])))
|
||||
(t/is (empty? (:touched (get-shape :copy))))
|
||||
|
||||
(await (apply-step (dwsl/change-grid-direction [(thi/id :copy)] :row)))
|
||||
(t/is (= row-cells (get-cells :copy)))
|
||||
(await (apply-step (dwl/reset-component (thi/id :copy))))
|
||||
(t/is (= column-cells (get-cells :copy)))
|
||||
(t/is (= :column (:layout-grid-dir (get-shape :copy))))
|
||||
(t/is (empty? (:touched (get-shape :copy))))
|
||||
(t/is (= main-order (:shapes (get-shape :main))))
|
||||
(t/is (= copy-order (:shapes (get-shape :copy))))
|
||||
(t/is (= other-order (:shapes (get-shape :other))))
|
||||
(check-clean-children :main)
|
||||
(check-clean-children :copy)
|
||||
(check-clean-children :other)))))
|
||||
|
||||
(t/deftest ^:async grid-cell-overrides-retain-the-whole-group-through-main-edits-and-update-main
|
||||
(await
|
||||
(mock/with-mocks* {rp/cmd! mock/rpc-cmd-mock rx/timer mock/timer-mock}
|
||||
(await (install-grid))
|
||||
(let [initial (get-cells :main)
|
||||
authored (-> initial (assoc-in [0 :align-self] :end) (assoc-in [0 :justify-self] :center))
|
||||
inherited (-> initial (assoc-in [0 :align-self] :start) (assoc-in [1 :justify-self] :end))]
|
||||
(await (apply-step (dwsl/update-grid-cells (thi/id :copy) [(first (get-cell-ids :copy))]
|
||||
{:align-self :end :justify-self :center})))
|
||||
(t/is (= authored (get-cells :copy)))
|
||||
(t/is (= #{:layout-grid-cells} (:touched (get-shape :copy))))
|
||||
(await (apply-step (dwsl/update-grid-cells (thi/id :main) [(first (get-cell-ids :main))] {:align-self :start})))
|
||||
(await (apply-step (dwsl/update-grid-cells (thi/id :main) [(second (get-cell-ids :main))] {:justify-self :end})))
|
||||
(t/is (= authored (get-cells :copy)))
|
||||
(t/is (= inherited (get-cells :main) (get-cells :other)))
|
||||
(t/is (empty? (:touched (get-shape :other))))
|
||||
(check-clean-children :copy)
|
||||
(check-clean-children :other)
|
||||
|
||||
(await (apply-step (dwl/reset-component (thi/id :copy))))
|
||||
(t/is (= inherited (get-cells :copy)))
|
||||
(t/is (empty? (:touched (get-shape :copy))))
|
||||
(await (apply-step (dwsl/update-grid-cells (thi/id :other) [(first (get-cell-ids :other))] {:align-self :center})))
|
||||
(await (apply-step (dwsl/update-grid-cells (thi/id :copy) [(second (get-cell-ids :copy))]
|
||||
{:align-self :end :justify-self :center})))
|
||||
(let [pushed (-> inherited (assoc-in [1 :align-self] :end) (assoc-in [1 :justify-self] :center))
|
||||
retained (assoc-in inherited [0 :align-self] :center)]
|
||||
(await (apply-step (dwl/update-component-sync (thi/id :copy) (:id (ftm/current-file)))))
|
||||
(t/is (= pushed (get-cells :main) (get-cells :copy)))
|
||||
(t/is (= retained (get-cells :other)))
|
||||
(t/is (empty? (:touched (get-shape :copy))))
|
||||
(t/is (= #{:layout-grid-cells} (:touched (get-shape :other))))
|
||||
(check-clean-children :main)
|
||||
(check-clean-children :copy)
|
||||
(check-clean-children :other))))))
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
[app.common.files.tokens :as cfo]
|
||||
[app.common.geom.rect :as grc]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[app.common.logic.variants :as clv]
|
||||
[app.common.test-helpers.composable.comp.files :as cf]
|
||||
[app.common.test-helpers.composable.comp.nodes :as n]
|
||||
[app.common.test-helpers.composable.comp.undo-check :as uc]
|
||||
@ -140,6 +141,16 @@
|
||||
built from `situation` and from the same helpers the common node uses."
|
||||
[op situation]
|
||||
(cond
|
||||
(instance? n/EditGrid op)
|
||||
(let [{:keys [target action value]} op
|
||||
id (tm/target-shape-id situation target)
|
||||
shape (tm/shape-by-id situation id)]
|
||||
(case action
|
||||
:direction [(dwsl/change-grid-direction [id] value)]
|
||||
:cell (let [cell (first (filter #(= [(:row value) (:column value)] [(:row %) (:column %)])
|
||||
(vals (:layout-grid-cells shape))))]
|
||||
[(dwsl/update-grid-cells id [(:id cell)] (:props value))])))
|
||||
|
||||
(instance? n/ChangeProperty op)
|
||||
(let [{:keys [target property value]} op
|
||||
id (tm/target-shape-id situation target)]
|
||||
@ -150,10 +161,22 @@
|
||||
[(dwsl/update-layout-child [id] (select-keys shape [:layout-item-margin
|
||||
:layout-item-margin-type]))])
|
||||
|
||||
(: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)
|
||||
[(dwsl/update-layout-child [id] {property value})]
|
||||
|
||||
;; the layers panel's rename, which renames a main's component too
|
||||
:name
|
||||
[(dw/end-rename-shape id value)]
|
||||
|
||||
;; Container controls use the sidebar transaction and reflow event.
|
||||
(:layout-flex-dir :layout-wrap-type :layout-justify-content
|
||||
:layout-align-content :layout-gap-type :layout-padding-type :layout-justify-items)
|
||||
[(dwsl/update-layout [id] {property value})]
|
||||
|
||||
[(dwsh/update-shapes #{id} (fn [shape] (n/set-property shape property value)))]))
|
||||
|
||||
(instance? n/EditText op)
|
||||
@ -174,9 +197,9 @@
|
||||
:original-content (:content shape))]))
|
||||
|
||||
(instance? n/Rotate op)
|
||||
;; the sidebar rotation, which decides what it touches in copies (check-delta)
|
||||
;; A node turns by its angle, including after an earlier rotation.
|
||||
(let [{:keys [target angle]} op]
|
||||
[(dwt/increase-rotation [(tm/target-shape-id situation target)] angle)])
|
||||
[(dwt/increase-rotation [(tm/target-shape-id situation target)] angle {:delta? true})])
|
||||
|
||||
(instance? n/MoveShape op)
|
||||
;; the sidebar position, in page coordinates
|
||||
@ -274,8 +297,9 @@
|
||||
[(dwl/reset-component (tm/target-shape-id situation (:target op)))]
|
||||
|
||||
(instance? n/UpdateMain op)
|
||||
[(dwl/update-component-sync (tm/target-shape-id situation (:target op))
|
||||
(:id (tm/file situation)))]
|
||||
(let [id (tm/target-shape-id situation (:target op))
|
||||
shape (tm/shape-by-id situation id)]
|
||||
[(dwl/update-component-sync id (:component-file shape))])
|
||||
|
||||
(instance? n/DeleteComponent op)
|
||||
(let [root (tm/shape-by-id situation (tm/target-shape-id situation (:target op)))]
|
||||
@ -376,6 +400,17 @@
|
||||
(let [st @st/state]
|
||||
(get-in st [:files (:current-file-id st)])))
|
||||
|
||||
(defn refresh-generated
|
||||
"Read every generated file after events, keeping library installation
|
||||
metadata out of the portable situation. Undo snapshots still keep it."
|
||||
[situation]
|
||||
(-> situation
|
||||
(tm/with-file (current-file))
|
||||
(tm/with-aux-files
|
||||
(into {} (map (fn [[id _]]
|
||||
[id (dissoc (get-in @st/state [:files id]) :library-of)]))
|
||||
(tm/aux-files situation)))))
|
||||
|
||||
(defn fill-of
|
||||
"The fill color of the shape `label` in the live file."
|
||||
[label]
|
||||
@ -469,24 +504,6 @@
|
||||
(merge (n/applied-result op before (tm/file situation))))]
|
||||
(tm/record-application situation op record)))
|
||||
|
||||
(defn- record-op
|
||||
"`situation` with the live file and the application of the settled op unit
|
||||
`op`: its choices first, then the op's own fields and its
|
||||
`n/applied-result`, if any."
|
||||
[situation op]
|
||||
(let [before (tm/file situation)
|
||||
situation (-> situation
|
||||
(tm/with-file (current-file))
|
||||
(record-choices op))
|
||||
op (unwrap op)
|
||||
record (cond-> (dissoc (into {} op) ::tm/id)
|
||||
(and (instance? n/SyncFromLibrary op) (nil? (:source op)))
|
||||
(dissoc :source)
|
||||
|
||||
(satisfies? n/IAppliedResult op)
|
||||
(merge (n/applied-result op before (tm/file situation))))]
|
||||
(tm/record-application situation op record)))
|
||||
|
||||
(defn- op-events
|
||||
"The workspace events of the op unit `op` (for a choice, of the chosen op)."
|
||||
[op situation]
|
||||
@ -556,14 +573,28 @@
|
||||
|
||||
(defn- check-step
|
||||
"The round trip of user step `op`, given the snapshot `before` and the undo
|
||||
index `index-before` taken before it. Resolves with the situation."
|
||||
[situation op before index-before]
|
||||
(let [step (uc/step situation op)
|
||||
history taken before it. Account for entries dropped by the history cap."
|
||||
[situation op before index-before items-before]
|
||||
(let [items-after (get-in @st/state [:workspace-undo :items])
|
||||
evicted (or (first (keep-indexed (fn [index item]
|
||||
(when (= item (first items-after)) index))
|
||||
(take (inc index-before) items-before)))
|
||||
0)
|
||||
step (uc/step situation op)
|
||||
baseline (uc/baseline situation)
|
||||
situation (cond-> situation
|
||||
(pos? evicted)
|
||||
(uc/mark-baseline (- (:depth baseline) evicted) (:snapshot baseline))
|
||||
(> evicted (inc (:depth baseline)))
|
||||
(uc/add-error step :expired-baseline "Undo entries expired before the segment was checked"))
|
||||
after (snapshot)
|
||||
index-after (undo-index)]
|
||||
(if (= index-before index-after)
|
||||
(if (and (= index-before index-after)
|
||||
(zero? evicted)
|
||||
(= (:undo-group (get items-before index-before))
|
||||
(:undo-group (get items-after index-after))))
|
||||
(js/Promise.resolve (uc/compare-states situation step :no-undo-entry before after))
|
||||
(.then (round-trip-move situation dwu/undo step :undo before index-before)
|
||||
(.then (round-trip-move situation dwu/undo step :undo before (- index-before evicted))
|
||||
(fn [[situation settled?]]
|
||||
(if settled?
|
||||
(.then (round-trip-move situation dwu/redo step :redo after index-after)
|
||||
@ -586,8 +617,8 @@
|
||||
(step 0)))
|
||||
|
||||
(defn- check-variant
|
||||
"The end-of-variant round trip: undo back to the baseline, then redo as many
|
||||
times. Resolves with the situation."
|
||||
"Undo the retained history segment back to its baseline, then redo it.
|
||||
Also runs before the cap drops entries, so every segment gets checked."
|
||||
[situation]
|
||||
(let [{:keys [depth] :as baseline} (uc/baseline situation)
|
||||
final (snapshot)
|
||||
@ -713,12 +744,22 @@
|
||||
check-step? (and (::undo-check? situation)
|
||||
(contains? #{:user :frontend-only} kind))
|
||||
before (when check-step? (snapshot))
|
||||
index-before (undo-index)]
|
||||
(if (sync-op? op)
|
||||
index-before (undo-index)
|
||||
items-before (when check-step? (get-in @st/state [:workspace-undo :items]))]
|
||||
(cond
|
||||
;; Check the complete segment while its baseline is still reachable.
|
||||
;; Leave room for a primary commit and its delayed layout entry.
|
||||
(and check-step?
|
||||
(>= index-before (- dwu/MAX-UNDO-SIZE 2))
|
||||
(< (:depth (uc/baseline situation)) index-before))
|
||||
(.then (check-variant situation) #(run-ops (mark-baseline %) ops))
|
||||
|
||||
(sync-op? op)
|
||||
(let [situation (run-sync-op situation op)]
|
||||
(when (and (not (::generated situation)) (contains? golden-kinds kind))
|
||||
(observe-golden-step!))
|
||||
(run-ops situation (rest ops)))
|
||||
:else
|
||||
(do
|
||||
(reset! step-errors [])
|
||||
(.then (await-step (op-events op situation) step-timeout-ms)
|
||||
@ -745,8 +786,8 @@
|
||||
(cond
|
||||
check-step?
|
||||
;; go on from the redone file, as the pure runner does
|
||||
(.then (check-step situation (unwrap op) before index-before)
|
||||
#(run-ops (tm/with-file % (current-file)) (rest ops)))
|
||||
(.then (check-step situation (unwrap op) before index-before items-before)
|
||||
#(run-ops (refresh-generated %) (rest ops)))
|
||||
|
||||
;; never undo past the state a case's own undo went back to
|
||||
(and (::undo-check? situation)
|
||||
@ -827,10 +868,176 @@
|
||||
(install!)
|
||||
(mark-baseline)))
|
||||
|
||||
(defn run-generated-step
|
||||
(defn- get-generated-references
|
||||
[situation]
|
||||
(into {} (for [[file-id file] (cf/all-files situation)
|
||||
objects (cf/object-trees file)
|
||||
[id shape] objects
|
||||
:when (:shape-ref shape)]
|
||||
[[file-id id] {:shape shape
|
||||
:sources (dissoc (cf/reference-libraries situation file-id id) file-id)}])))
|
||||
|
||||
(defn- get-reference-patches
|
||||
[before after]
|
||||
(reduce (fn [patches key]
|
||||
(if (= (get before key) (get after key))
|
||||
patches
|
||||
(-> patches
|
||||
(assoc-in [:before key] (get-in before [key :sources]))
|
||||
(assoc-in [:after key] (get-in after [key :sources])))))
|
||||
{} (into (set (keys before)) (keys after))))
|
||||
|
||||
(defn- restore-generated-references
|
||||
[situation patches]
|
||||
(reduce-kv (fn [situation [file-id id] sources]
|
||||
(if sources
|
||||
(assoc-in situation [:shape-libraries file-id id] sources)
|
||||
(update-in situation [:shape-libraries file-id] dissoc id)))
|
||||
situation (or patches {})))
|
||||
|
||||
(defn ^:async run-generated-step
|
||||
"Drive a resolved node through real events, settlement and undo/redo."
|
||||
[situation op]
|
||||
(run-ops situation [op]))
|
||||
(let [index-before (undo-index)
|
||||
items-before (get-in @st/state [:workspace-undo :items])
|
||||
after (await (run-ops situation [op]))]
|
||||
(if-not (and after (:accepted-libraries situation))
|
||||
after
|
||||
(let [index-after (undo-index)
|
||||
items (get-in @st/state [:workspace-undo :items])]
|
||||
(cond
|
||||
(instance? n/Undo op)
|
||||
(reduce (fn [s index]
|
||||
(restore-generated-references s
|
||||
(get-in situation [::reference-history (:undo-group (get items-before index)) :before])))
|
||||
after (range index-before index-after -1))
|
||||
|
||||
(instance? n/Redo op)
|
||||
(reduce (fn [s index]
|
||||
(restore-generated-references s
|
||||
(get-in situation [::reference-history (:undo-group (get items index)) :after])))
|
||||
after (range (inc index-before) (inc index-after)))
|
||||
|
||||
:else
|
||||
(let [file-id (:id (tm/file situation))
|
||||
inputs (cf/all-files situation)
|
||||
;; Pull requests use the loaded before-state. Update-main
|
||||
;; authors the source itself; its independent intent check
|
||||
;; still compares that source against the copy's before-state.
|
||||
after (cond
|
||||
(instance? n/UpdateMain op)
|
||||
(let [shape (tm/shape-by-id situation (tm/target-shape-id situation (:target op)))
|
||||
source (:component-file shape)
|
||||
components (cf/affected-components (get inputs source) #{(:component-id shape)})
|
||||
dependents (cf/affected-components (get inputs file-id)
|
||||
(cf/dependent-components (get inputs file-id) source components))
|
||||
authored (cf/all-files after)]
|
||||
(-> after
|
||||
(cf/remember-copies source source components authored)
|
||||
(cf/remember-copies file-id source components authored)
|
||||
(cf/remember-copies file-id file-id dependents authored)))
|
||||
|
||||
(instance? n/SyncFromLibrary op)
|
||||
(let [source (or (:source op) (n/library-id situation))]
|
||||
(-> after
|
||||
(assoc-in [:accepted-libraries file-id source] (get inputs source))
|
||||
(cf/remember-copies file-id source
|
||||
(set (keys (get-in inputs [source :data :components]))) inputs)))
|
||||
|
||||
(or (instance? n/ResetOverrides op)
|
||||
(instance? n/SwapShape op)
|
||||
(and (instance? n/SwitchVariant op)
|
||||
(clv/find-switch-target inputs
|
||||
(tm/shape-by-id situation (tm/target-shape-id situation (:target op)))
|
||||
(n/switch-pos situation op)
|
||||
(n/switch-value situation op))))
|
||||
(cf/remember-subtree after file-id (tm/target-shape-id situation (:target op)) inputs)
|
||||
|
||||
:else after)
|
||||
patches (get-reference-patches (get-generated-references situation) (get-generated-references after))
|
||||
item (get items index-after)
|
||||
group (:undo-group item)]
|
||||
(cond-> after
|
||||
;; A no-entry request must not extend the preceding action.
|
||||
;; Compare entries: capped history can replace its last item
|
||||
;; without advancing its index.
|
||||
(and group (not= item (get items-before index-before)) (seq (:before patches)))
|
||||
(update-in [::reference-history group]
|
||||
(fn [prior]
|
||||
{:before (merge (:before patches) (:before prior))
|
||||
:after (merge (:after prior) (:after patches))})))))))))
|
||||
|
||||
(defn- get-generated-editor
|
||||
[situation]
|
||||
{:situation (dissoc (refresh-generated situation) ::source-editors)
|
||||
:undo (:workspace-undo @st/state)})
|
||||
|
||||
(defn- resume-generated-editor
|
||||
[{:keys [situation undo]}]
|
||||
(let [file (tm/file situation)]
|
||||
(uninstall!)
|
||||
(st/emit! (ptk/reify ::resume-generated-editor
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(assoc state :current-file-id (:id file)
|
||||
:current-page-id (cthf/current-page-id file)
|
||||
:workspace-undo undo)))
|
||||
(dw/initialize-edit-watchers)
|
||||
(dwl/watch-library-changes)
|
||||
(headless-text-measurement))
|
||||
(let [situation (refresh-generated situation)
|
||||
baseline (uc/baseline situation)
|
||||
current (snapshot)]
|
||||
(if (and baseline
|
||||
(= (uc/snapshot (dissoc file :library-of)
|
||||
{:position-data? (not (features/active-feature? @st/state "render-wasm/v1"))})
|
||||
(dissoc (get-in current [:files (:id file)]) :library-of)))
|
||||
;; Keep the verified segment while only foreign inputs changed.
|
||||
(uc/mark-baseline situation (:depth baseline)
|
||||
(assoc current :files
|
||||
(assoc (:files current) (:id file)
|
||||
(get-in baseline [:snapshot :files (:id file)]))))
|
||||
;; A foreign editor wrote this file after its last verified segment.
|
||||
;; Retain its undo entries, but start the next segment at this state.
|
||||
(mark-baseline situation)))))
|
||||
|
||||
(defn ^:async run-generated-source-step
|
||||
"Run a source edit in its owning editor and retain both undo histories.
|
||||
Returning to the consumer loads source data without accepting it."
|
||||
[situation owner op]
|
||||
(let [situation (await (check-variant situation))
|
||||
_ (t/is (empty? (uc/failures situation)) (pr-str (uc/failures situation)))
|
||||
consumer (get-generated-editor situation)
|
||||
files (cf/all-files situation)
|
||||
editor (or (get-in situation [::source-editors owner])
|
||||
{:situation (-> (tm/make-situation (get files owner))
|
||||
(tm/with-aux-files (dissoc files owner))
|
||||
(assoc ::undo-check? true ::generated true)
|
||||
(uc/with-runner :frontend))
|
||||
:undo {}})
|
||||
editor (update editor :situation merge (select-keys situation [:accepted-libraries :shape-libraries]))
|
||||
source (resume-generated-editor editor)
|
||||
before (snapshot)
|
||||
source (await (run-generated-step source op))]
|
||||
(when-not source
|
||||
(throw (ex-info "Source editor step failed" {:owner owner})))
|
||||
(t/is (= (dissoc (:files before) owner) (dissoc (:files (snapshot)) owner))
|
||||
"A source editor must not write another file")
|
||||
(let [changed? (not= before (snapshot))
|
||||
source (await (check-variant source))
|
||||
editor (get-generated-editor source)
|
||||
consumer (update consumer :situation merge (select-keys source [:accepted-libraries :shape-libraries]))
|
||||
baseline (uc/baseline (:situation consumer))
|
||||
live (resume-generated-editor consumer)
|
||||
;; The consumer's verified history can itself write the source.
|
||||
;; A real source edit closes that segment; a no-op keeps it exact.
|
||||
live (if changed?
|
||||
(mark-baseline live)
|
||||
(uc/mark-baseline live (:depth baseline) (:snapshot baseline)))]
|
||||
(t/is (empty? (uc/failures source)) (pr-str (uc/failures source)))
|
||||
(-> live
|
||||
(assoc ::source-editors (assoc (::source-editors situation) owner editor))
|
||||
(tm/record-application op {:library-id owner})))))
|
||||
|
||||
(defn finish-generated
|
||||
[situation]
|
||||
|
||||
@ -66,9 +66,10 @@
|
||||
(cthtx/set-text :copy-child [[["Price: " (assoc in-test-font :font-variant-id "400")]
|
||||
["$10" (assoc in-test-font :weight 700 :font-variant-id "700")]]]))))
|
||||
(t/is (= [["Price: " "400"] ["$10" "700"]] (run-variants :copy-child)))
|
||||
;; the main makes all of it bold: the weight comes from the main, with a
|
||||
;; variant of the main's family ("bold")
|
||||
;; the main makes all of it bold: "$10" keeps its family's bold, and the
|
||||
;; rest takes the main's weight with a variant of the main's family
|
||||
;; ("bold"), which the frontend turns into the family's closest
|
||||
(t/is (= :settled (await (ftm/await-step [(dwsh/update-shapes #{(cthi/id :main-child)}
|
||||
#(assoc % :content (cthtx/content [[["Price: " {:weight 700}]
|
||||
["$10" {:weight 700}]]])))]))))
|
||||
(t/is (= [["Price: $10" "700"]] (run-variants :copy-child))))
|
||||
(t/is (= [["Price: " "700"] ["$10" "700"]] (run-variants :copy-child))))
|
||||
|
||||
@ -245,9 +245,10 @@
|
||||
|
||||
;; Scenario: the workspace opens and then reloads twice (a peer's restore,
|
||||
;; the rollback fallback), each reload running `initialize-workspace` again
|
||||
;; without leaving the workspace; then one commit is made. Proves: each
|
||||
;; reload replaces the workspace streams, so the commit adds one undo entry,
|
||||
;; not one per reload.
|
||||
;; without leaving the workspace, and each loaded file starting the edit
|
||||
;; watchers that record undo entries (the file load is mocked, so the test
|
||||
;; starts them); then one commit is made. Proves: each reload replaces the
|
||||
;; workspace streams, so the commit adds one undo entry, not one per reload.
|
||||
(t/deftest ^:async a-workspace-reload-adds-one-undo-entry-per-commit
|
||||
(let [file (cthf/sample-file :file1 :page-label :page1)
|
||||
team-id (uuid/next)
|
||||
@ -263,8 +264,11 @@
|
||||
(ptk/emit! store
|
||||
#(assoc % :current-team-id team-id)
|
||||
(dw/initialize-workspace team-id (:id file))
|
||||
(dw/initialize-edit-watchers)
|
||||
(ptk/event ::dw/reload-current-file)
|
||||
(ptk/event ::dw/reload-current-file))
|
||||
(dw/initialize-edit-watchers)
|
||||
(ptk/event ::dw/reload-current-file)
|
||||
(dw/initialize-edit-watchers))
|
||||
(await (async/settle))
|
||||
(ptk/emit! store (rename-page (cthf/current-page-id file) "Renamed"))
|
||||
(await (async/wait-for #(seq (get-in @store [:workspace-undo :items]))
|
||||
|
||||
@ -188,17 +188,17 @@
|
||||
[]
|
||||
(-> (cthf/sample-file :file1)
|
||||
(ctho/add-simple-component :c01 :m01 :r01
|
||||
:root-params {:name "Alpha" :x 0 :y 0 :width 100 :height 80})
|
||||
:root-params {:name "Alpha" :x 0 :y 0 :width 100 :height 80})
|
||||
(ctho/add-simple-component :c02 :m02 :r02
|
||||
:root-params {:name "Beta" :x 150 :y 0 :width 100 :height 80})))
|
||||
:root-params {:name "Beta" :x 150 :y 0 :width 100 :height 80})))
|
||||
|
||||
(defn- two-mains-shared-prefix-file
|
||||
[]
|
||||
(-> (cthf/sample-file :file1)
|
||||
(ctho/add-simple-component :c01 :m01 :r01
|
||||
:root-params {:name "UI / Alpha" :x 0 :y 0 :width 100 :height 80})
|
||||
:root-params {:name "UI / Alpha" :x 0 :y 0 :width 100 :height 80})
|
||||
(ctho/add-simple-component :c02 :m02 :r02
|
||||
:root-params {:name "UI / Beta" :x 150 :y 0 :width 100 :height 80})))
|
||||
:root-params {:name "UI / Beta" :x 150 :y 0 :width 100 :height 80})))
|
||||
|
||||
(defn- three-same-name-mains-file
|
||||
[]
|
||||
@ -214,16 +214,16 @@
|
||||
[]
|
||||
(-> (cthf/sample-file :file1)
|
||||
(ctho/add-simple-component :c01 :m01 :r01
|
||||
:root-params {:name "Group / Button"})))
|
||||
:root-params {:name "Group / Button"})))
|
||||
|
||||
(defn- two-mains-on-page1-with-page2
|
||||
"Two mains on :page1; the open page is :page2 (Assets combine while elsewhere)."
|
||||
[]
|
||||
(-> (cthf/sample-file :file1 :page-label :page1)
|
||||
(ctho/add-simple-component :c01 :m01 :r01
|
||||
:root-params {:name "Alpha" :x 0 :y 0 :width 100 :height 80})
|
||||
:root-params {:name "Alpha" :x 0 :y 0 :width 100 :height 80})
|
||||
(ctho/add-simple-component :c02 :m02 :r02
|
||||
:root-params {:name "Beta" :x 150 :y 0 :width 100 :height 80})
|
||||
:root-params {:name "Beta" :x 150 :y 0 :width 100 :height 80})
|
||||
(cthf/add-sample-page :page2)
|
||||
(cthf/switch-to-page :page2)))
|
||||
|
||||
@ -234,7 +234,7 @@
|
||||
(-> (cthf/sample-file :file1)
|
||||
(ctho/add-frame :v01 {:name "Set"})
|
||||
(ctho/add-simple-component :c01 :m01 :r01
|
||||
:root-params {:parent-label :v01 :name "Set"})))
|
||||
:root-params {:parent-label :v01 :name "Set"})))
|
||||
|
||||
(defn- component-full-name
|
||||
[component]
|
||||
@ -324,7 +324,7 @@
|
||||
(ths/run-store
|
||||
store
|
||||
done
|
||||
[(dwv/transform-in-variant main-id variant-id nil [] false true true)]
|
||||
[(dwv/transform-in-variant main-id variant-id)]
|
||||
(fn [state]
|
||||
(let [snaps @snapshots
|
||||
flagged (first-flagged snaps variant-id)
|
||||
@ -348,7 +348,9 @@
|
||||
fcont (get fobjs variant-id)
|
||||
fmain (get fobjs main-id)
|
||||
fcomp (cthc/get-component ffile :c01)]
|
||||
(t/is (= [main-id] (:shapes fcont)))
|
||||
;; the commit that defines the set adds its second member too
|
||||
(t/is (= main-id (last (:shapes fcont))))
|
||||
(t/is (= 2 (count (:shapes fcont))))
|
||||
(t/is (ctk/main-instance? fmain))
|
||||
(t/is (= variant-id (:variant-id fmain)))
|
||||
(t/is (= variant-id (:variant-id fcomp)))
|
||||
@ -371,7 +373,7 @@
|
||||
(ths/run-store
|
||||
store
|
||||
done
|
||||
[(dwv/transform-in-variant main-id variant-id nil [] false true true)]
|
||||
[(dwv/transform-in-variant main-id variant-id)]
|
||||
(fn [state]
|
||||
(let [snaps @snapshots
|
||||
flagged (first-flagged snaps variant-id)
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
[app.main.data.workspace.pages :as dwpg]
|
||||
[app.main.data.workspace.shapes :as dwsh]
|
||||
[app.main.data.workspace.thumbnails-wasm :as dwt.wasm]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
[beicon.v2.core :as rx]
|
||||
[cljs.test :as t :include-macros true]
|
||||
@ -26,6 +27,7 @@
|
||||
[frontend-tests.helpers.pages :as thp]
|
||||
[frontend-tests.helpers.state :as ths]
|
||||
[frontend-tests.helpers.wasm :as thw]
|
||||
[okulary.core :as l]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
(t/use-fixtures :each
|
||||
|
||||
@ -398,7 +398,7 @@
|
||||
(with-redefs [r/check-permission (constantly true)
|
||||
u/not-valid (mock/stub (fn [pid prop msg] (swap! errors conj [pid prop msg])))
|
||||
library/get-variant-components (constantly [{:main-instance-page page-id
|
||||
:variant-properties [{:name "color" :value "red"}]}])
|
||||
:variant-properties [{:name "color" :value "red"}]}])
|
||||
dwv/update-property-name (fn [vid pos name opts]
|
||||
(reset! renamed {:id vid :pos pos :name name :opts opts})
|
||||
::rename-event)
|
||||
@ -422,7 +422,7 @@
|
||||
(with-redefs [r/check-permission (constantly true)
|
||||
u/not-valid (mock/stub (fn [pid prop msg] (swap! errors conj [pid prop msg])))
|
||||
u/locate-library-component (constantly {:id id :main-instance-page page-id
|
||||
:variant-properties [{:name "color"}]})
|
||||
:variant-properties [{:name "color"}]})
|
||||
dwv/update-property-value (fn [cid pos value]
|
||||
(reset! updated {:id cid :pos pos :value value})
|
||||
::value-event)
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
[frontend-tests.composable-tests.comp.sync-test]
|
||||
[frontend-tests.composable-tests.completion-contract-test]
|
||||
[frontend-tests.composable-tests.generated-test]
|
||||
[frontend-tests.composable-tests.grid-layout-test]
|
||||
[frontend-tests.copy-as-svg-test]
|
||||
[frontend-tests.data.auth-test]
|
||||
[frontend-tests.data.changes-test]
|
||||
@ -85,7 +86,6 @@
|
||||
[frontend-tests.logic.drag-on-save-failure-test]
|
||||
[frontend-tests.logic.frame-guides-test]
|
||||
[frontend-tests.logic.groups-test]
|
||||
[frontend-tests.logic.ignore-tree-test]
|
||||
[frontend-tests.logic.move-shapes-to-frame-test]
|
||||
[frontend-tests.logic.multi-variant-switch-test]
|
||||
[frontend-tests.logic.nudge-selected-shapes-test]
|
||||
@ -230,6 +230,7 @@
|
||||
'frontend-tests.composable-tests.comp.sync-test
|
||||
'frontend-tests.composable-tests.completion-contract-test
|
||||
'frontend-tests.composable-tests.generated-test
|
||||
'frontend-tests.composable-tests.grid-layout-test
|
||||
'frontend-tests.copy-as-svg-test
|
||||
'frontend-tests.data.auth-test
|
||||
'frontend-tests.data.changes-test
|
||||
@ -309,7 +310,6 @@
|
||||
'frontend-tests.logic.drag-on-save-failure-test
|
||||
'frontend-tests.logic.frame-guides-test
|
||||
'frontend-tests.logic.groups-test
|
||||
'frontend-tests.logic.ignore-tree-test
|
||||
'frontend-tests.logic.move-shapes-to-frame-test
|
||||
'frontend-tests.logic.multi-variant-switch-test
|
||||
'frontend-tests.logic.nudge-selected-shapes-test
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user