@dexhq/canvas 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/app/canvas/canvas-commands.ts +2 -10
  3. package/app/canvas/canvas-context.tsx +11 -2
  4. package/app/canvas/canvas-document.ts +5 -1
  5. package/app/canvas/canvas-keys.ts +1 -1
  6. package/app/canvas/canvas-model.ts +195 -20
  7. package/app/canvas/canvas-scene.ts +176 -171
  8. package/app/canvas/canvas-ui.ts +4 -11
  9. package/app/canvas/canvas.css +159 -179
  10. package/app/canvas/change-pictures.tsx +156 -0
  11. package/app/canvas/comment-drafts.ts +31 -0
  12. package/app/canvas/comment-layer.tsx +125 -71
  13. package/app/canvas/comments.tsx +38 -2
  14. package/app/canvas/element-picker.ts +20 -0
  15. package/app/canvas/engine/canvas-gestures.ts +15 -3
  16. package/app/canvas/engine/canvas-store.ts +5 -0
  17. package/app/canvas/engine/canvas-view.tsx +22 -5
  18. package/app/canvas/find-bar.tsx +57 -41
  19. package/app/canvas/flow-canvas.tsx +147 -272
  20. package/app/canvas/frame-copies.ts +14 -17
  21. package/app/canvas/frame-drops.ts +15 -7
  22. package/app/canvas/frame-inspector.ts +192 -41
  23. package/app/canvas/frame-node.tsx +123 -75
  24. package/app/canvas/frame-resize.tsx +321 -83
  25. package/app/canvas/insert-hint.tsx +5 -15
  26. package/app/canvas/inspect-layer.tsx +73 -19
  27. package/app/canvas/label-action.tsx +13 -2
  28. package/app/canvas/layout.ts +233 -98
  29. package/app/canvas/live-page.ts +5 -0
  30. package/app/canvas/new-frame.ts +10 -25
  31. package/app/canvas/note-placing.ts +55 -84
  32. package/app/canvas/picked-box.tsx +5 -0
  33. package/app/canvas/picks-menu.tsx +3 -9
  34. package/app/canvas/readable-colour.ts +52 -0
  35. package/app/canvas/request-node.tsx +19 -10
  36. package/app/canvas/scrolling-page.ts +45 -0
  37. package/app/canvas/section-node.tsx +36 -53
  38. package/app/canvas/settle.ts +21 -0
  39. package/app/canvas/snapping.ts +96 -8
  40. package/app/canvas/spec-frame.tsx +8 -5
  41. package/app/canvas/spot-pins.tsx +15 -3
  42. package/app/canvas/stack-frame.tsx +13 -57
  43. package/app/canvas/stack-model.ts +5 -0
  44. package/app/canvas/stack-toggle.tsx +89 -0
  45. package/app/canvas/styles-layer.tsx +23 -43
  46. package/app/canvas/text-layer.tsx +26 -10
  47. package/app/canvas/thread-focus.tsx +18 -1
  48. package/app/canvas/tool-cursors.ts +2 -2
  49. package/app/canvas/toolbar-parts.tsx +48 -8
  50. package/app/canvas/toolbar.tsx +12 -10
  51. package/app/canvas/use-canvas-clipboard.tsx +13 -5
  52. package/app/canvas/use-reveal.ts +86 -0
  53. package/app/editor/extensions.ts +2 -0
  54. package/app/editor/line-break-caret.ts +57 -0
  55. package/app/git/branch-panel.tsx +61 -20
  56. package/app/i18n/locales/en/messages.po +64 -17
  57. package/app/i18n/locales/en/messages.ts +1 -1
  58. package/app/i18n/locales/pseudo/messages.po +64 -17
  59. package/app/i18n/locales/pseudo/messages.ts +1 -1
  60. package/app/icons/glyphs.tsx +2 -0
  61. package/app/live/studio-live.ts +29 -9
  62. package/app/pages/canvas.tsx +1 -1
  63. package/app/pages/commands-settings.tsx +70 -76
  64. package/app/pages/play-bar.tsx +6 -11
  65. package/app/pages/play.tsx +52 -33
  66. package/app/shell/feedback-form.tsx +29 -5
  67. package/app/ui/prompt-editor.tsx +2 -0
  68. package/app/ui/use-field-list.ts +90 -0
  69. package/dist/cli/commands/mcp.mjs +6 -4
  70. package/dist/cli/mcp-relay.mjs +10 -6
  71. package/dist/content/content.d.mts +26 -9
  72. package/dist/content/content.mjs +65 -8
  73. package/dist/content/screenshot.d.mts +2 -0
  74. package/dist/content/screenshot.mjs +3 -0
  75. package/dist/content/snapshot-client.d.mts +2 -0
  76. package/dist/content/snapshot-client.mjs +12 -1
  77. package/dist/inspector.js +96 -19
  78. package/dist/paste/paste.d.mts +5 -0
  79. package/dist/paste/paste.mjs +7 -2
  80. package/dist/server/agent-tools.d.mts +1 -0
  81. package/dist/server/agent-tools.mjs +4 -3
  82. package/dist/server/change-picture-store.d.mts +13 -0
  83. package/dist/server/change-picture-store.mjs +42 -0
  84. package/dist/server/change-pictures.d.mts +25 -0
  85. package/dist/server/change-pictures.mjs +104 -0
  86. package/dist/server/close-check.d.mts +11 -0
  87. package/dist/server/close-check.mjs +37 -5
  88. package/dist/server/comments/agent-actions.d.mts +8 -4
  89. package/dist/server/comments/agent-actions.mjs +16 -7
  90. package/dist/server/comments/close-tools.mjs +7 -5
  91. package/dist/server/comments/files.d.mts +5 -1
  92. package/dist/server/comments/hand-out.d.mts +1 -1
  93. package/dist/server/comments/hand-out.mjs +4 -1
  94. package/dist/server/comments/push.d.mts +19 -10
  95. package/dist/server/comments/push.mjs +45 -30
  96. package/dist/server/comments/studio-files.d.mts +14 -1
  97. package/dist/server/comments/studio-files.mjs +44 -31
  98. package/dist/server/comments/tools.d.mts +1 -1
  99. package/dist/server/comments/workspace.mjs +1 -0
  100. package/dist/server/dev-server.mjs +34 -0
  101. package/dist/server/own-copies.mjs +4 -23
  102. package/dist/server/requests.mjs +57 -3
  103. package/dist/server/response-budget.d.mts +2 -1
  104. package/dist/server/response-budget.mjs +4 -3
  105. package/dist/server/roster.d.mts +19 -8
  106. package/dist/server/roster.mjs +50 -22
  107. package/dist/server/studio-for.d.mts +7 -0
  108. package/dist/server/studio-for.mjs +23 -7
  109. package/dist/server/thread-forms.d.mts +3 -0
  110. package/dist/server/thread-forms.mjs +21 -1
  111. package/dist/server/tools/place-frame.d.mts +1 -0
  112. package/dist/server/tools/place-frame.mjs +33 -9
  113. package/dist/server/tools/result.mjs +2 -2
  114. package/dist/server/tools/snapshot.d.mts +1 -1
  115. package/dist/server/tools/snapshot.mjs +2 -1
  116. package/dist/server/tools/studio-context.d.mts +2 -1
  117. package/dist/server/tools/studio-context.mjs +2 -1
  118. package/dist/server/tools/watch.mjs +29 -12
  119. package/dist/server/work-groups.mjs +1 -1
  120. package/dist/shared/canvas-core.d.mts +39 -5
  121. package/dist/shared/canvas-core.mjs +60 -15
  122. package/dist/shared/canvas-file.d.mts +7 -4
  123. package/dist/shared/change-pictures-core.d.mts +6 -0
  124. package/dist/shared/change-pictures-core.mjs +5 -0
  125. package/dist/shared/page-looks.d.mts +12 -0
  126. package/dist/shared/page-looks.mjs +49 -0
  127. package/dist/shared/snapshot-clipboard.d.mts +6 -0
  128. package/dist/shared/studio-routes.d.mts +11 -0
  129. package/extension/dist/manifest.json +1 -1
  130. package/extension/dist/picker.js +114 -108
  131. package/package.json +4 -3
  132. package/src/cli/commands/mcp.ts +18 -8
  133. package/src/cli/mcp-relay.ts +13 -6
  134. package/src/content/content.ts +90 -16
  135. package/src/content/screenshot.ts +9 -1
  136. package/src/content/snapshot-client.ts +17 -0
  137. package/src/paste/paste.ts +18 -1
  138. package/src/server/agent-tools.ts +5 -4
  139. package/src/server/change-picture-store.ts +71 -0
  140. package/src/server/change-pictures.ts +244 -0
  141. package/src/server/close-check.ts +69 -6
  142. package/src/server/comments/agent-actions.ts +51 -12
  143. package/src/server/comments/close-tools.ts +20 -10
  144. package/src/server/comments/files.ts +10 -2
  145. package/src/server/comments/hand-out.ts +2 -2
  146. package/src/server/comments/push.ts +94 -46
  147. package/src/server/comments/studio-files.ts +77 -46
  148. package/src/server/comments/workspace.ts +1 -0
  149. package/src/server/dev-server.ts +70 -0
  150. package/src/server/own-copies.ts +5 -33
  151. package/src/server/requests.ts +84 -4
  152. package/src/server/response-budget.ts +5 -3
  153. package/src/server/roster.ts +78 -28
  154. package/src/server/studio-for.ts +32 -7
  155. package/src/server/thread-forms.ts +41 -1
  156. package/src/server/tools/place-frame.ts +71 -14
  157. package/src/server/tools/result.ts +2 -2
  158. package/src/server/tools/snapshot.ts +2 -1
  159. package/src/server/tools/studio-context.ts +24 -14
  160. package/src/server/tools/watch.ts +38 -13
  161. package/src/server/work-groups.ts +1 -1
  162. package/src/shared/canvas-core.ts +119 -27
  163. package/src/shared/canvas-file.ts +7 -4
  164. package/src/shared/change-pictures-core.ts +8 -0
  165. package/src/shared/page-looks.ts +133 -0
  166. package/src/shared/snapshot-clipboard.ts +6 -0
  167. package/src/shared/studio-routes.ts +7 -1
  168. package/templates/agents/dex-worker.md +9 -7
  169. package/templates/feedback-workflow.md +1 -1
  170. package/templates/methods/review.md +7 -6
  171. package/templates/rules/canvas-frames.md +8 -7
  172. package/templates/rules/canvas.md +10 -8
  173. package/templates/rules/prototypes.md +5 -3
  174. package/app/canvas/stack-node.tsx +0 -100
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @dexhq/canvas
2
2
 
3
+ ## 0.18.0
4
+
5
+ ### Minor Changes
6
+
7
+ - eabde35: When an agent closes a comment, Dex looks at the comment's frame, and a view that shows an error or renders nothing keeps the comment open. The closed comment shows no pictures unless someone asks: "Show the change" opens the frame before and after, for as long as Dex runs.
8
+ - 33a4ee2: Hold ⌘ (Ctrl off a Mac) and click, as in Figma, to choose the element under whatever covers it, such as an overlay or a link stretched over a card: Dex takes the smallest element under the pointer, and each ⌘-click in the same spot takes the next one down, in Comment, Inspect, Markup and the extension. Holding ⌘ outlines what a ⌘-click will take. The frame itself is easy to choose: click just inside its edge, or press ⌘↑ from any element (↓ comes back), and ⌘Enter still comments on it; with the cursor, a click just outside its outline, past the edge that resizes it, selects it and a drag moves it, even while you use its page.
9
+ - dbbdc74: Comments an agent takes together say once what they share: `watch` puts the file, frame, spec and device its group's threads have in common in the group's `shared`, and no thread repeats its file's name and title or that it is for the agent and taken. The channel's event does the same under each group's heading. Five comments on one view come to 6,946 bytes instead of 8,238.
10
+ - 080bd1d: Frames and sections resize from all four edges and all four corners. While you drag, a ghost outline shows the new size and nothing else moves; let go and the canvas makes room. A free frame or a section keeps its opposite edges where they were, a frame in a section keeps its cell's top left, and the edges you drag line up with other frames' (or sections') edges.
11
+ - 6a56dcd: A section header goes wherever a note goes, such as into a section just above a frame, where it fills the section's width; drag its right edge to resize it, and it lines up with other frames' edges as it does (double-click the edge to fill again).
12
+ - 3c68c30: Product feedback can go one after another: once it's sent, Add more beside Done opens the form again for the next, without closing it. The description and attachments are cleared and the description is ready to type in; the category, the email and the choice to add information stay as they were.
13
+ - 9de55fc: A stack shows how many frames it holds before its top frame's name, beside the label's other actions, in place of the count at its corner. Press it to fan the stack out, and again to fold it back; the bar over a fanned-out stack is gone, and Unstack stays in the frame's menu (⇧⌘G).
14
+
15
+ ### Patch Changes
16
+
17
+ - 0bec813: Leaving Play puts the canvas back where you left it, and a long spec or document that was scrolled keeps its place, after Play or when panned off screen and back. Only when you stepped to a frame that is off screen does the canvas move, to show it.
18
+ - 27582e4: Comments Dex sends straight to a Claude Code session (`npx dex claude`) now name their section's spec for the agent to read first, as comments taken with `watch` or `threads` already do. The channel and the comment tools describe a comment in one place now, so they can't drift apart again.
19
+ - 76c2747: Dex's tools answer in compact JSON, not indented: a comment from `watch` costs an agent 85 to 160 fewer tokens, and each budget holds more.
20
+ - 649851a: A stack drags like a frame: press anywhere on it and drop it in a new column, a new row or onto another stack, and its frames, and any notes in its cell, stay together. With ⌥ it leaves a copy of the whole stack.
21
+ - 65bbac4: In ⌘F's find bar, ↓ and ↑ move through the matches, and a screen reader hears which one you're on. Settings' skill search and All branches work the same way, and Enter there picks the one you're on.
22
+ - 760577c: Inspect styles shows an element's colour as the design system wrote it: `oklch(…)`, `lab(…)` or `color(display-p3 …)`, its numbers rounded to three places, where it showed the hex of another colour (shadcn's white text came out as `#010000`, nearly black). Hex, named and `hsl()` colours are still shown as hex.
23
+ - 59824ae: On Linux and Windows, Dex hears of what is written into a folder that has only just appeared, such as a new file's `file.json`, a new person's canvas or a component in a new folder, instead of missing it until something else in that folder changes.
24
+ - c0b7719: A new line on an empty line draws one caret, on the new line, in Safari and the Dex app too: Shift+Enter in a comment box, a spec or a doc, and Enter in a code block. The caret used to stay drawn a line up while the next letter went on the new line.
25
+ - 62041c3: An agent asked to put a frame right of another now lands it there, even after the person moved that frame: `place_frame` takes `rightOf` (a frame's uid or key) and finds the frame where it is when it places. A frame given no step goes in the free step at the end of its row (with no row either, at the end of the section's main path), not at the row's start; asking again adds nothing. Each answer says the frame's step and the frame on its left.
26
+ - 0c4fa7a: A link in a view you're playing now takes Play to the frame that shows the linked view, even in another row or section, so the bar names it, comments go on it, and Escape brings you back to it on the canvas. A view with no frame still leaves Play on the step it was on.
27
+ - cffe2ef: Zoomed out, a section's name stays above its section instead of sliding into it over its frames. Where it runs over the section above, it sits on a small rounded pill so it stays readable, and pressing it still picks and drags its own section, even one placed by hand under another.
28
+ - 9bdd7ab: An agent's snapshots find Dex again when it was started from a terminal in another time zone or language, instead of saying it is restarting; and an update moves an agent's `dex mcp` to the new Dex once, instead of restarting its server several times over.
29
+ - 5e2218f: A snapshot keeps its page's breakpoints, so it stays responsive when its frame is resized or shown at another device's size. When part of it was sized by the page's scripts, the paste says that part keeps its size.
30
+ - dc1beb2: A link to a comment, such as one opened from the bell, now opens the comment once and then leaves the address. Before, it stayed, so every later reload of the page (Dex restarting after an agent's edits, say) opened that comment again: the canvas moved to it, and a comment on a spec or slide opened it full screen, over whatever you were doing.
31
+ - 093132c: The canvas's tools and Play's bar are easier to hit: every button on them is 32px tall, and a split button's chevron (Frame or section, Text or section header, Spec or slide) is 26px wide where it was 16, so every control meets WCAG 2.2's 24 by 24 pixel target size at 100%, with Dex's own buttons or a project's (`ui.primitives`).
32
+ - 19822b7: C, I and T switch between Comment, Inspect styles and Text from any of them, and keep the element you chose on a frame, and a comment's words come back when you open it again before posting.
33
+
3
34
  ## 0.17.0
4
35
 
5
36
  ### Minor Changes
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  canvasFrames,
3
- isHeaderFrame,
4
3
  isNoteFrame,
5
4
  type PageSize,
6
5
  } from "../../src/shared/canvas-core.ts";
@@ -384,18 +383,11 @@ export function createCanvasCommands({
384
383
  return;
385
384
  }
386
385
 
387
- // A section header stays a band across the canvas, never a section's.
388
- const frames = chosen.filter((address) => {
389
- const frame = getFrame(before, address);
390
-
391
- return !(frame && isHeaderFrame(frame));
392
- });
393
-
394
386
  change(
395
387
  (current) => {
396
388
  const made =
397
- frames.length > 0
398
- ? groupIntoSection(current, frames)
389
+ chosen.length > 0
390
+ ? groupIntoSection(current, chosen)
399
391
  : addSection(current);
400
392
 
401
393
  const canvas = drawn
@@ -28,6 +28,14 @@ export type CanvasTool =
28
28
  | "styles"
29
29
  | "inspect";
30
30
 
31
+ /** How a new comment's card opens, and what is told once it is posted. */
32
+ export interface ComposeOptions {
33
+ /** The quick bar's commands first. */
34
+ quick?: boolean;
35
+ /** Once the comment is posted, not when its card closes otherwise. */
36
+ onPosted?: () => void;
37
+ }
38
+
31
39
  /** Where on screen to open a thread or a new comment. */
32
40
  export interface ScreenPoint {
33
41
  left: number;
@@ -63,12 +71,13 @@ export interface CanvasContextValue {
63
71
  capture: (shot: Shot) => void;
64
72
  /**
65
73
  * Start a comment on a target, with its composer at a point on screen;
66
- * `quick` offers the quick bar's commands there first.
74
+ * `quick` offers the quick bar's commands there first, and `onPosted` is
75
+ * called once it is posted.
67
76
  */
68
77
  compose: (
69
78
  target: ThreadTarget,
70
79
  at: ScreenPoint,
71
- options?: { quick?: boolean }
80
+ options?: ComposeOptions
72
81
  ) => void;
73
82
  /** The team's devices and layout guides (devices.json). */
74
83
  devices: Devices;
@@ -60,11 +60,15 @@ export type Clipboard = { cell?: Cell } & (
60
60
  | { images: PastedImage[] }
61
61
  );
62
62
 
63
- /** What a paste made: where it came from, its frames and images missed. */
63
+ /**
64
+ * What a paste made: where it came from, its frames, images missed, and
65
+ * parts its page's scripts sized, which won't reflow.
66
+ */
64
67
  export interface Pasted {
65
68
  from: PasteSource;
66
69
  images: number;
67
70
  saved: { frame: string }[];
71
+ sizedByScripts?: number;
68
72
  }
69
73
 
70
74
  /** A write the server made, with its answer, or the problems why not. */
@@ -462,5 +462,5 @@ export const inspectorKey = (
462
462
  }
463
463
 
464
464
  // With Shift too, so no arrow pans while something is outlined.
465
- return command ? undefined : stepOf(key.key);
465
+ return stepOf(key);
466
466
  };
@@ -89,6 +89,11 @@ export interface PlacedFrames {
89
89
  export interface PlacedFrame {
90
90
  canvas: Canvas;
91
91
  key?: string;
92
+ /**
93
+ * Moved, the key each frame that went ends at, `key` first: a stack's
94
+ * frames under it too (moveStack).
95
+ */
96
+ keys?: string[];
92
97
  }
93
98
 
94
99
  /** The canvas with a new section, and the section's id. */
@@ -169,11 +174,33 @@ export const moveOwnFrames = (
169
174
  };
170
175
  };
171
176
 
177
+ export const resizeFrame = (
178
+ canvas: Canvas,
179
+ address: FrameAddress,
180
+ patch: FramePatch,
181
+ topLeftMovedBy: { x: number; y: number }
182
+ ): Canvas =>
183
+ moveOwnFrames(
184
+ updateFrame(canvas, address, patch),
185
+ new Set([address.section]),
186
+ topLeftMovedBy
187
+ );
188
+
189
+ /**
190
+ * Whether a row's frame at `index` is stacked under the frame before it, in
191
+ * its cell: on the same step, as stepsOf resolves them. A frame marked
192
+ * `under` that starts a column of its own (the frame it was under is gone)
193
+ * is not.
194
+ */
195
+ const stackedUnder = (steps: readonly number[], index: number) =>
196
+ index > 0 && steps[index] === steps[index - 1];
197
+
172
198
  /** A cell of a row, from its first frame: it and the frames under it. */
173
199
  const cellFrom = (frames: Frame[], index: number): Frame[] => {
200
+ const steps = stepsOf(frames);
174
201
  let end = index + 1;
175
202
 
176
- while (frames[end]?.under) {
203
+ while (end < frames.length && stackedUnder(steps, end)) {
177
204
  end += 1;
178
205
  }
179
206
 
@@ -263,7 +290,8 @@ export const moveFrame = (
263
290
 
264
291
  /**
265
292
  * A cell's frames moved to another cell, from its first frame: its stack
266
- * and any words in it, in order, with the key its first frame ends at.
293
+ * and any words in it, in order, with the key its first frame ends at, and
294
+ * the key each of them ends at (`keys`).
267
295
  */
268
296
  export const moveStack = (
269
297
  canvas: Canvas,
@@ -294,11 +322,19 @@ function relocate(
294
322
  const ids = new Set(moving.map((frame) => frame.id));
295
323
 
296
324
  const inside = [to.under, to.over].some(
297
- (id) => id !== undefined && ids.has(id) && to.row === from.row
325
+ (id) =>
326
+ id !== undefined &&
327
+ ids.has(id) &&
328
+ to.section === from.section &&
329
+ to.row === from.row
298
330
  );
299
331
 
300
332
  if (inside || staysPut(canvas, from, to)) {
301
- return { canvas, key: frameKey(from) };
333
+ return {
334
+ canvas,
335
+ key: frameKey(from),
336
+ keys: moving.map((frame) => frameKey({ ...from, frame: frame.id })),
337
+ };
302
338
  }
303
339
 
304
340
  const next = clone(canvas);
@@ -325,18 +361,106 @@ function relocate(
325
361
  }
326
362
 
327
363
  const headId = insertInCell(row, first, to);
364
+ const landed = [headId];
328
365
  let above = headId;
329
366
 
330
367
  for (const frame of under) {
331
- above = insertUnder(row, frame, above) ?? above;
368
+ const id = insertUnder(row, frame, above);
369
+
370
+ if (id) {
371
+ landed.push(id);
372
+ above = id;
373
+ }
332
374
  }
333
375
 
334
- return {
335
- canvas: tidy(next),
336
- key: frameKey({ section: section.id, row: row.id, frame: headId }),
337
- };
376
+ const keyOf = (id: string) =>
377
+ frameKey({ section: section.id, row: row.id, frame: id });
378
+
379
+ return { canvas: tidy(next), key: keyOf(headId), keys: landed.map(keyOf) };
338
380
  }
339
381
 
382
+ /** The index of the first frame of the cell a row's frame at `index` is in. */
383
+ const cellStart = (frames: Frame[], index: number): number => {
384
+ const steps = stepsOf(frames);
385
+ let start = index;
386
+
387
+ while (stackedUnder(steps, start)) {
388
+ start -= 1;
389
+ }
390
+
391
+ return start;
392
+ };
393
+
394
+ /**
395
+ * A frame's cell, by key, its first frame first: the frames moveStack moves
396
+ * from there, the frame's stack and any words in it. None when there is no
397
+ * such frame.
398
+ */
399
+ export const cellKeys = (canvas: Canvas, address: FrameAddress): string[] => {
400
+ const frames = findRow(canvas, address.section, address.row)?.frames ?? [];
401
+ const index = frames.findIndex((frame) => frame.id === address.frame);
402
+
403
+ return index === -1
404
+ ? []
405
+ : cellFrom(frames, cellStart(frames, index)).map((frame) =>
406
+ frameKey({ ...address, frame: frame.id })
407
+ );
408
+ };
409
+
410
+ /** A step along a row: left, or right. */
411
+ export type Nudge = -1 | 1;
412
+
413
+ /**
414
+ * A frame's cell moved a step along its row, whole, as moveStack moves it
415
+ * (the arrow keys on a closed stack): left, before the column to its left,
416
+ * which moves right to make room; right, after the column to its right,
417
+ * which comes before it. The same canvas at its row's end, or when there is
418
+ * no such frame.
419
+ */
420
+ export const nudgeCell = (
421
+ canvas: Canvas,
422
+ address: FrameAddress,
423
+ by: Nudge
424
+ ): Canvas => {
425
+ const frames = findRow(canvas, address.section, address.row)?.frames ?? [];
426
+ const index = frames.findIndex((frame) => frame.id === address.frame);
427
+ const head = frames[cellStart(frames, index)];
428
+
429
+ if (index === -1 || !head) {
430
+ return canvas;
431
+ }
432
+
433
+ const steps = stepsOf(frames);
434
+
435
+ const columns = frames.map((frame, at) => ({
436
+ frame,
437
+ step: steps[at] ?? at + 1,
438
+ }));
439
+
440
+ const step = columns.find((column) => column.frame === head)?.step ?? 1;
441
+ const cell = { section: address.section, row: address.row };
442
+
443
+ if (by < 0) {
444
+ return step > 1
445
+ ? moveStack(
446
+ canvas,
447
+ { ...cell, frame: head.id },
448
+ { ...cell, step: step - 1 }
449
+ ).canvas
450
+ : canvas;
451
+ }
452
+
453
+ // The first frame of the next column to its right.
454
+ const next = columns
455
+ .filter((column) => column.step > step)
456
+ .toSorted((a, b) => a.step - b.step)[0];
457
+
458
+ return next
459
+ ? moveStack(canvas, { ...cell, frame: next.frame.id }, { ...cell, step })
460
+ .canvas
461
+ : canvas;
462
+ };
463
+
340
464
  /**
341
465
  * A frame put in a cell as it is (a copy, say), the frames after it making
342
466
  * room, with the key it ends at. No key when the cell's section is not there.
@@ -384,17 +508,17 @@ export const staysPut = (
384
508
  return true;
385
509
  }
386
510
 
511
+ const steps = stepsOf(frames);
512
+
387
513
  if (to.under !== undefined) {
388
- return Boolean(frame.under) && frames[index - 1]?.id === to.under;
514
+ return stackedUnder(steps, index) && frames[index - 1]?.id === to.under;
389
515
  }
390
516
 
391
517
  if (to.over !== undefined) {
392
- const next = frames[index + 1];
393
-
394
- return next?.id === to.over && Boolean(next.under);
518
+ return frames[index + 1]?.id === to.over && stackedUnder(steps, index + 1);
395
519
  }
396
520
 
397
- return stepOfFrame(canvas, from) === to.step && !frame.under;
521
+ return steps[index] === to.step && !stackedUnder(steps, index);
398
522
  };
399
523
 
400
524
  /** The step a frame is on. */
@@ -809,6 +933,21 @@ export const placeDrawnSection = (
809
933
  : placed;
810
934
  };
811
935
 
936
+ export const resizeSection = (
937
+ canvas: Canvas,
938
+ sectionId: string,
939
+ sizeShowingArea: { height: number; width: number },
940
+ topLeftAt?: { x: number; y: number }
941
+ ): Canvas =>
942
+ topLeftAt
943
+ ? placeDrawnSection(canvas, sectionId, { ...topLeftAt, ...sizeShowingArea })
944
+ : updateSection(canvas, sectionId, {
945
+ size: {
946
+ width: Math.round(sizeShowingArea.width),
947
+ height: Math.round(sizeShowingArea.height),
948
+ },
949
+ });
950
+
812
951
  export function updateSection(
813
952
  canvas: Canvas,
814
953
  sectionId: string,
@@ -994,6 +1133,15 @@ export interface PlayAt {
994
1133
  export const rowStart = (section: Section, row?: string): number =>
995
1134
  playFrames(section).find((frame) => frame.row === row)?.step ?? 1;
996
1135
 
1136
+ /** Every row with a frame that plays, as the canvas reads, top to bottom. */
1137
+ const playedRows = (canvas: Canvas) =>
1138
+ canvas.sections.flatMap((section) =>
1139
+ [...new Set(playFrames(section).map((frame) => frame.row))].map((row) => ({
1140
+ row,
1141
+ section,
1142
+ }))
1143
+ );
1144
+
997
1145
  /**
998
1146
  * Where stepping past either end of a row goes, so Play runs through the
999
1147
  * whole canvas as it reads, left to right and top to bottom: on to where the
@@ -1005,12 +1153,7 @@ export const adjacentRow = (
1005
1153
  playing: { row?: string; section: string },
1006
1154
  direction: "back" | "next"
1007
1155
  ): PlayAt | undefined => {
1008
- const rows = canvas.sections.flatMap((section) =>
1009
- [...new Set(playFrames(section).map((frame) => frame.row))].map((row) => ({
1010
- row,
1011
- section,
1012
- }))
1013
- );
1156
+ const rows = playedRows(canvas);
1014
1157
 
1015
1158
  const at = rows.findIndex(
1016
1159
  (entry) => entry.section.id === playing.section && entry.row === playing.row
@@ -1031,6 +1174,38 @@ export const adjacentRow = (
1031
1174
  return step === undefined ? undefined : { ...target, step };
1032
1175
  };
1033
1176
 
1177
+ /**
1178
+ * Where Play goes when a view links to another view: to the step that shows
1179
+ * it in the row playing, else in the first row that has one, as the canvas
1180
+ * reads. None when no step shows it: no frame does, or only one stacked under
1181
+ * another, whose step plays the frame on top.
1182
+ */
1183
+ export const linkedStep = (
1184
+ canvas: Canvas,
1185
+ playing: { row?: string; section: string },
1186
+ view: string
1187
+ ): PlayAt | undefined => {
1188
+ const rows = playedRows(canvas);
1189
+
1190
+ const ordered = [
1191
+ ...rows.filter(
1192
+ (entry) =>
1193
+ entry.section.id === playing.section && entry.row === playing.row
1194
+ ),
1195
+ ...rows,
1196
+ ];
1197
+
1198
+ for (const { row, section } of ordered) {
1199
+ const shown = playSteps(section, row).find(
1200
+ (entry) => entry.frame.view === view
1201
+ );
1202
+
1203
+ if (shown) {
1204
+ return { section, row, step: shown.step };
1205
+ }
1206
+ }
1207
+ };
1208
+
1034
1209
  /**
1035
1210
  * What the canvas's Play button presents: the section and row of the first
1036
1211
  * selected frame that plays, else the first section with a frame that plays.