@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
@@ -11,8 +11,7 @@ import { useCanvasUiStore } from "./canvas-ui";
11
11
  import { drawnFrameCell } from "./draw-model";
12
12
  import { type Point, visibleRect } from "./engine/camera";
13
13
  import { useCanvasView } from "./engine/canvas-view";
14
- import { headerTop, type Layout } from "./layout";
15
- import { placeHeaderFrame, placeNoteFrame } from "./new-frame";
14
+ import { placeNoteFrame } from "./new-frame";
16
15
  import { useCanvasScene } from "./scene-context";
17
16
  import { EMPTY_PAGE, writeMarkdown } from "./spec-placing";
18
17
  import type { NoteTool } from "./tools";
@@ -24,9 +23,10 @@ import type { NoteTool } from "./tools";
24
23
  // opens ready to write in. A copy of one gets a file of its own too
25
24
  // (spec-copies.ts).
26
25
  //
27
- // A section header, placed with ⇧T, is a note too, marked `header`: it
28
- // always stands on its own, and the layout draws it as a band across the
29
- // canvas where you clicked, splitting it into parts (layout.ts).
26
+ // A section header, placed with ⇧T, is a note too, marked `header`, and
27
+ // goes where a note would: in a cell of a section of yours, or on its own.
28
+ // The layout has it fill what it is in, its section or, on its own, the
29
+ // canvas's content, which it splits into parts (layout.ts).
30
30
 
31
31
  /**
32
32
  * A new note file of the person's, with `source` in it, named `base`, then
@@ -79,53 +79,57 @@ const showPlaced = (view: ReturnType<typeof useCanvasView>, key: string) => {
79
79
  });
80
80
  };
81
81
 
82
- /** What a placing tool does: where its note goes, and how it is said. */
82
+ /** What a placing tool makes, and how it is said. */
83
83
  interface Placing {
84
84
  /** The note's file name to start from. */
85
85
  base: string;
86
86
  /** Said when it could not be placed. */
87
87
  failed: MessageDescriptor;
88
+ /** Said when it is put in someone else's section. */
89
+ othersSection: MessageDescriptor;
88
90
  /**
89
- * The canvas with the note's frame placed, and its key; none, saying why,
90
- * when it cannot go there.
91
+ * The tool that placed it, back to try again if it could not be: Section
92
+ * header's makes a section header.
91
93
  */
92
- place: (
93
- canvas: Canvas,
94
- note: string,
95
- at: Point,
96
- layout: Layout
97
- ) => { canvas: Canvas; frame: string } | undefined;
98
- /** The tool that placed it, back to try again if it could not be. */
99
94
  tool: NoteTool;
100
95
  }
101
96
 
102
97
  /**
103
- * Places a note at a point on the canvas, saying why when it cannot: the
104
- * note's file is written, then its frame placed, ready to write in.
98
+ * Places a note at a point on the canvas, saying why when it cannot: in a
99
+ * cell of a section of yours, or on its own outside any section. The note's
100
+ * file is written, then its frame placed, ready to write in.
105
101
  */
106
- const usePlaceNoteAs = (
107
- /** Whether it can go there: why not, when it cannot. */
108
- refuse: (at: Point) => string | undefined,
109
- { base, failed, place: placeFrame, tool }: Placing
110
- ) => {
111
- const { i18n, t } = useLingui();
102
+ const usePlaceNoteAs = ({ base, failed, othersSection, tool }: Placing) => {
103
+ const { i18n } = useLingui();
112
104
  const { editor, me, prototype, say } = useCanvas();
113
105
  const ui = useCanvasUiStore();
114
106
  const view = useCanvasView();
115
107
  const scene = useCanvasScene();
116
108
 
109
+ const cellOf = useCallback(
110
+ (at: Point) =>
111
+ scene.flowAt(at)
112
+ ? scene.cellAt(at, { between: true, text: true })
113
+ : undefined,
114
+ [scene]
115
+ );
116
+
117
117
  const place = useCallback(
118
118
  async (at: Point) => {
119
119
  if (!me) {
120
- say(t`Dex can’t tell who you are yet: a note is kept in your folder.`);
120
+ say(
121
+ i18n._(
122
+ msg`Dex can’t tell who you are yet: a note is kept in your folder.`
123
+ )
124
+ );
121
125
 
122
126
  return;
123
127
  }
124
128
 
125
- const why = refuse(at);
129
+ const cell = cellOf(at);
126
130
 
127
- if (why) {
128
- say(why);
131
+ if (cell && !drawnFrameCell(editor.canvas, cell, me)) {
132
+ say(i18n._(othersSection));
129
133
 
130
134
  return;
131
135
  }
@@ -146,7 +150,15 @@ const usePlaceNoteAs = (
146
150
  );
147
151
 
148
152
  editor.apply((canvas) => {
149
- const placed = placeFrame(canvas, note, at, scene.layout);
153
+ const into = drawnFrameCell(canvas, cellOf(at), me);
154
+
155
+ const placed = placeNoteFrame(
156
+ canvas,
157
+ note,
158
+ into ? { at, cell: into } : { at },
159
+ { header: tool === "header" }
160
+ );
161
+
150
162
  key = placed?.frame;
151
163
 
152
164
  return placed?.canvas ?? canvas;
@@ -175,14 +187,13 @@ const usePlaceNoteAs = (
175
187
  },
176
188
  [
177
189
  base,
190
+ cellOf,
178
191
  editor,
192
+ i18n,
179
193
  me,
180
- placeFrame,
194
+ othersSection,
181
195
  prototype,
182
- refuse,
183
196
  say,
184
- scene,
185
- t,
186
197
  tool,
187
198
  ui,
188
199
  view,
@@ -199,68 +210,28 @@ const usePlaceNoteAs = (
199
210
  );
200
211
  };
201
212
 
202
- const NOTE: Omit<Placing, "place"> = {
213
+ const NOTE: Placing = {
203
214
  base: "note",
204
215
  failed: msg`The note could not be placed.`,
216
+ othersSection: msg`That section is someone else's: place the note on one of yours, or outside any section.`,
205
217
  tool: "text",
206
218
  };
207
219
 
208
- /**
209
- * Places a note at a point on the canvas: in a cell of a section of yours,
210
- * or on its own outside any section.
211
- */
212
- export const usePlaceNote = () => {
213
- const { t } = useLingui();
214
- const { editor, me } = useCanvas();
215
- const scene = useCanvasScene();
216
-
217
- const cellOf = useCallback(
218
- (at: Point) =>
219
- scene.flowAt(at)
220
- ? scene.cellAt(at, { between: true, text: true })
221
- : undefined,
222
- [scene]
223
- );
224
-
225
- const refuse = useCallback(
226
- (at: Point) => {
227
- const cell = cellOf(at);
228
-
229
- return cell && !drawnFrameCell(editor.canvas, cell, me)
230
- ? t`That section is someone else's: place the note on one of yours, or outside any section.`
231
- : undefined;
232
- },
233
- [cellOf, editor.canvas, me, t]
234
- );
235
-
236
- const place = useCallback<Placing["place"]>(
237
- (canvas, note, at) => {
238
- const into = drawnFrameCell(canvas, cellOf(at), me);
239
-
240
- return placeNoteFrame(canvas, note, into ? { at, cell: into } : { at });
241
- },
242
- [cellOf, me]
243
- );
244
-
245
- return usePlaceNoteAs(refuse, { ...NOTE, place });
246
- };
247
-
248
- /** A header may go anywhere: it is a note of its own, standing on its own. */
249
- const anywhere = () => undefined;
250
-
251
- /** A section header, where a click puts it (headerTop). */
252
- const placeHeader: Placing["place"] = (canvas, note, at, layout) =>
253
- placeHeaderFrame(canvas, note, { x: at.x, y: headerTop(layout, at) });
254
-
255
220
  const HEADER: Placing = {
256
221
  base: "header",
257
222
  failed: msg`The section header could not be placed.`,
258
- place: placeHeader,
223
+ othersSection: msg`That section is someone else's: place the section header on one of yours, or outside any section.`,
259
224
  tool: "header",
260
225
  };
261
226
 
262
227
  /**
263
- * Places a section header across the canvas where a click is: anyone may,
264
- * anywhere, as it is a note of their own that stands on its own.
228
+ * Places a note at a point on the canvas: in a cell of a section of yours,
229
+ * or on its own outside any section.
230
+ */
231
+ export const usePlaceNote = () => usePlaceNoteAs(NOTE);
232
+
233
+ /**
234
+ * Places a section header at a point on the canvas, where a note would go:
235
+ * in a cell of a section of yours, or on its own outside any section.
265
236
  */
266
- export const usePlaceHeader = () => usePlaceNoteAs(anywhere, HEADER);
237
+ export const usePlaceHeader = () => usePlaceNoteAs(HEADER);
@@ -17,6 +17,11 @@ export const PickedBox = ({ box }: { box: Box }) => (
17
17
  <div className="studio-pick z-20" data-picked style={boxStyle(box)} />
18
18
  );
19
19
 
20
+ /** The whole frame outlined, for a comment on all of it. */
21
+ export const FrameOutline = ({ picked }: { picked?: boolean }) => (
22
+ <div className="studio-pick inset-0" data-picked={picked} />
23
+ );
24
+
20
25
  /** A key for a box among others on a page. */
21
26
  export const boxKey = ({ x, y, width, height }: Box) =>
22
27
  `${x},${y},${width},${height}`;
@@ -1,6 +1,5 @@
1
1
  import { Trans, useLingui } from "@lingui/react/macro";
2
2
  import { Icon } from "@studio/icons";
3
- import { Button } from "@studio/ui/shadcn/button";
4
3
  import {
5
4
  DropdownMenu,
6
5
  DropdownMenuContent,
@@ -26,7 +25,7 @@ import {
26
25
  import { frameSource } from "./frame-source";
27
26
  import type { Reveal } from "./thread-focus";
28
27
  import { Tip } from "./tip";
29
- import { ToolbarControl } from "./toolbar-parts";
28
+ import { ToolbarControl, ToolbarMenuButton } from "./toolbar-parts";
30
29
  import { useCanvasClipboard } from "./use-canvas-clipboard";
31
30
 
32
31
  // Your picks, from the toolbar: each picked frame by its section, as Play's
@@ -131,19 +130,14 @@ export const PicksMenu = ({
131
130
  render={
132
131
  <DropdownMenuTrigger
133
132
  render={
134
- <Button
135
- aria-label={t`Picks`}
136
- className="hover:bg-studio-hover aria-expanded:bg-studio-hover aria-pressed:bg-studio-pressed aria-pressed:hover:bg-studio-pressed h-7 gap-0.5 px-1.5"
137
- size="sm"
138
- variant="ghost"
139
- >
133
+ <ToolbarMenuButton aria-label={t`Picks`}>
140
134
  <Icon name="CircleCheck" />
141
135
  <Icon
142
136
  className="text-muted-foreground size-3"
143
137
  name="ChevronDown"
144
138
  size={12}
145
139
  />
146
- </Button>
140
+ </ToolbarMenuButton>
147
141
  }
148
142
  />
149
143
  }
@@ -0,0 +1,52 @@
1
+ // A colour as Inspect styles shows it, from the browser's computed value.
2
+ // Browsers compute hex, named and hsl() colours to rgb() or rgba(), all
3
+ // sRGB, so those are shown as hex. Any other colour (oklch(), lab(),
4
+ // color(display-p3 …)) keeps its own space, as the design system wrote it:
5
+ // its channels aren't 0–255 red, green and blue, and as hex it would be
6
+ // another colour, or one hex can't hold.
7
+
8
+ /** rgb() or rgba(), as browsers compute them: "rgba(17, 17, 17, 0.5)". */
9
+ const RGB_RE =
10
+ /^rgba?\((?<r>[\d.]+), (?<g>[\d.]+), (?<b>[\d.]+)(?:, (?<a>[\d.]+))?\)$/u;
11
+
12
+ /**
13
+ * A number in a colour, not one in its space's name (display-p3, xyz-d65),
14
+ * written plainly or as Chromium writes tiny ones (1.00000e-7).
15
+ */
16
+ const NUMBER_RE = /(?<![\w.-])-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/giu;
17
+
18
+ /**
19
+ * Three places: enough to tell colours apart, and what design systems write
20
+ * (0.577 0.245 27.325).
21
+ */
22
+ const ROUNDING = 1000;
23
+ const HEX_BASE = 16;
24
+ const MAX_BYTE = 255;
25
+
26
+ const hexByte = (value: number) =>
27
+ Math.round(value).toString(HEX_BASE).padStart(2, "0");
28
+
29
+ /**
30
+ * "27.325001" → "27.325"; "1.00000e-7" → "0"; "52.2345" → "52.235", as it
31
+ * reads (toFixed gives 52.234, from the float nearest it).
32
+ */
33
+ const rounded = (written: string) =>
34
+ // Adding 0 turns -0 into 0.
35
+ String(Math.round(Number(written) * ROUNDING) / ROUNDING + 0);
36
+
37
+ /**
38
+ * "rgb(17, 17, 17)" → "#111111"; "oklch(0.577 0.245 27.325001)" →
39
+ * "oklch(0.577 0.245 27.325)".
40
+ */
41
+ export const readableColour = (computed: string): string => {
42
+ const rgb = RGB_RE.exec(computed)?.groups;
43
+
44
+ if (!rgb) {
45
+ return computed.replaceAll(NUMBER_RE, rounded);
46
+ }
47
+
48
+ const hex = [rgb.r, rgb.g, rgb.b].map((channel) => hexByte(Number(channel)));
49
+ const alpha = Number(rgb.a ?? 1);
50
+
51
+ return `#${hex.join("")}${alpha < 1 ? hexByte(alpha * MAX_BYTE) : ""}`;
52
+ };
@@ -1,6 +1,6 @@
1
1
  import { Trans, useLingui } from "@lingui/react/macro";
2
2
  import { Button } from "@studio/ui/shadcn/button";
3
- import { memo, useMemo, useState } from "react";
3
+ import { memo, useMemo } from "react";
4
4
 
5
5
  import { commentState, threadState } from "../../src/shared/threads-core.ts";
6
6
  import { STATE_LABELS } from "../live/thread-state";
@@ -15,7 +15,9 @@ import { useCanvas } from "./canvas-context";
15
15
  import { useCanvasUi } from "./canvas-ui";
16
16
  import { ResizeHandles, type Size } from "./frame-resize";
17
17
  import { MessageWords } from "./mentions";
18
+ import { useCanvasScene } from "./scene-context";
18
19
  import { SketchPage } from "./sketch-boxes";
20
+ import { resizeTargets } from "./snapping";
19
21
 
20
22
  export interface RequestNodeData {
21
23
  height: number;
@@ -58,10 +60,8 @@ export const RequestNode = memo(({ data }: { data: RequestNodeData }) => {
58
60
  const { movable, thread } = data;
59
61
  // Resized with the cursor, as a frame is.
60
62
  const resizable = useCanvasUi((state) => state.tool === "select") && movable;
61
- const [draft, setDraft] = useState<Size>();
62
- const shown = { width: data.width, height: data.height };
63
- // oxlint-disable-next-line shadcn/no-inline-styles -- computed at runtime: the request's size, as drawn or measured
64
- const size = draft ?? shown;
63
+ const size = { width: data.width, height: data.height };
64
+ const scene = useCanvasScene();
65
65
  const latest = thread.messages.at(-1);
66
66
  const author = latest?.agent ? latest.author : undefined;
67
67
  // Waiting until an agent is on it: a claim that ran out is none.
@@ -98,12 +98,11 @@ export const RequestNode = memo(({ data }: { data: RequestNodeData }) => {
98
98
  });
99
99
  } catch {
100
100
  say(t`The request was not resized. Try again.`);
101
- } finally {
102
- setDraft(undefined);
103
101
  }
104
102
  };
105
103
 
106
104
  return (
105
+ // oxlint-disable-next-line shadcn/no-inline-styles -- computed at runtime: the request's size, as drawn or measured
107
106
  <div className="studio-request relative" style={size}>
108
107
  <div
109
108
  className="studio-screen absolute bottom-full left-0 origin-bottom-left pb-1.5"
@@ -150,12 +149,22 @@ export const RequestNode = memo(({ data }: { data: RequestNodeData }) => {
150
149
  </div>
151
150
  {resizable ? (
152
151
  <ResizeHandles
153
- onDraft={setDraft}
152
+ lineUp={() => {
153
+ const placed = scene.layout.pending.get(thread.id);
154
+
155
+ return placed
156
+ ? {
157
+ at: placed,
158
+ keepsTopLeft: true,
159
+ with: resizeTargets(scene.layout, thread.id),
160
+ }
161
+ : undefined;
162
+ }}
154
163
  onReset={
155
164
  target.kind === "view" && target.size ? () => resize() : undefined
156
165
  }
157
- onResize={resize}
158
- size={shown}
166
+ onResize={({ size: next }) => resize(next)}
167
+ size={size}
159
168
  />
160
169
  ) : null}
161
170
  </div>
@@ -0,0 +1,45 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ import { useCanvas } from "./canvas-context";
4
+ import { keepPageWheel } from "./canvas-input";
5
+
6
+ // Where each frame's own page was scrolled to: a spec's or a document's
7
+ // words, longer than their frame. The page's element alone knew, and it is
8
+ // made afresh whenever the frame is drawn again: back in view after a pan
9
+ // took it off screen, or on the canvas again after Play. Kept here instead,
10
+ // by file and frame, while the studio is open, as the canvas keeps its camera.
11
+
12
+ const kept = new Map<string, number>();
13
+
14
+ /**
15
+ * A frame's own page that scrolls, as a spec's or a document's words do in a
16
+ * frame shorter than them: a wheel over it scrolls it, not the canvas
17
+ * (keepPageWheel), and drawn again it opens where it was scrolled to, once
18
+ * its words are in (`ready`), since until then it is not as tall as they make
19
+ * it. Returns the page, and the ref that gives it.
20
+ */
21
+ export const useScrollingPage = (frameKey: string, ready: boolean) => {
22
+ const { prototype } = useCanvas();
23
+ const at = `${prototype.slug}/${frameKey}`;
24
+ const [page, setPage] = useState<HTMLDivElement | null>(null);
25
+ useEffect(() => (page ? keepPageWheel(page) : undefined), [page]);
26
+ useEffect(() => {
27
+ if (!(page && ready)) {
28
+ return;
29
+ }
30
+
31
+ const top = kept.get(at);
32
+
33
+ if (top !== undefined) {
34
+ // oxlint-disable-next-line react/immutability -- scrolls the page, an element that is the browser's to scroll, not React's state
35
+ page.scrollTop = top;
36
+ }
37
+
38
+ const keep = () => kept.set(at, page.scrollTop);
39
+ page.addEventListener("scroll", keep, { passive: true });
40
+
41
+ return () => page.removeEventListener("scroll", keep);
42
+ }, [at, page, ready]);
43
+
44
+ return [page, setPage] as const;
45
+ };
@@ -5,14 +5,16 @@ import { memo, useEffect } from "react";
5
5
  import { isOthers } from "../../src/shared/people-core.ts";
6
6
  import type { Section } from "../types";
7
7
  import { useCanvas } from "./canvas-context";
8
- import { stepFrame, updateSection } from "./canvas-model";
8
+ import { resizeSection, stepFrame, updateSection } from "./canvas-model";
9
9
  import { useCanvasUi, useCanvasUiStore } from "./canvas-ui";
10
10
  import { EditableText } from "./editable-text";
11
11
  import { namesNow } from "./flow-naming";
12
12
  import { resolveRenameTo, suggestRename } from "./flow-renames";
13
- import { ResizeHandles, type Size } from "./frame-resize";
13
+ import { type Resized, ResizeHandles } from "./frame-resize";
14
14
  import { LabelAction } from "./label-action";
15
15
  import { type PlacedSection, sectionArea, sectionSizeShowing } from "./layout";
16
+ import { useCanvasScene } from "./scene-context";
17
+ import { sectionResizeTargets } from "./snapping";
16
18
  import { playHref } from "./viewports";
17
19
 
18
20
  export interface SectionNodeData {
@@ -27,27 +29,14 @@ export interface SectionSurfaceData {
27
29
  section: string;
28
30
  }
29
31
 
30
- /** The area a section shows: the size its edge is being dragged to, if it is. */
31
- const useSectionArea = (section: string, layout: PlacedSection) => {
32
- const draft = useCanvasUi((state) =>
33
- state.sectionDraft?.section === section
34
- ? state.sectionDraft.size
35
- : undefined
36
- );
37
-
38
- return draft ?? sectionArea(layout);
39
- };
40
-
41
32
  /**
42
33
  * The surface a section is drawn on, a shade off the canvas's, under its
43
34
  * frames: its own item, as the section's name and edges are drawn over them.
44
35
  */
45
- export const SectionSurface = memo(({ data }: { data: SectionSurfaceData }) => {
46
- const area = useSectionArea(data.section, data.layout);
47
-
36
+ export const SectionSurface = memo(({ data }: { data: SectionSurfaceData }) => (
48
37
  // oxlint-disable-next-line shadcn/no-inline-styles -- computed at runtime: the section's area, from the canvas's layout
49
- return <div className="studio-section-surface" style={area} />;
50
- });
38
+ <div className="studio-section-surface" style={sectionArea(data.layout)} />
39
+ ));
51
40
 
52
41
  SectionSurface.displayName = "SectionSurface";
53
42
 
@@ -98,8 +87,8 @@ export const SectionNode = memo(
98
87
  selected?: boolean;
99
88
  }) => {
100
89
  const { prototype, editor: canvas } = useCanvas();
101
- const ui = useCanvasUiStore();
102
- const { setNaming, setSectionDraft } = ui;
90
+ const { setNaming } = useCanvasUiStore();
91
+ const scene = useCanvasScene();
103
92
 
104
93
  // Only the section being named renders as its name is asked for.
105
94
  const naming = useCanvasUi((state) =>
@@ -119,24 +108,25 @@ export const SectionNode = memo(
119
108
  const asked = naming?.section === section.id;
120
109
  // oxlint-disable-next-line react/purity -- whether naming is still under way, as of this render
121
110
  const editNow = namesNow(naming, section.id, Date.now());
122
- // A section's area resizes by its right edge, bottom edge or corner; its
123
- // frames still grow it. Double-click a handle to fit it to its frames.
124
- const shown = sectionArea(layout);
125
- const area = useSectionArea(section.id, layout);
126
-
127
- const setDraft = (size?: Size) =>
128
- setSectionDraft(size && { section: section.id, size });
129
-
130
- // A section gone mid-resize (off screen, or removed by someone else)
131
- // leaves no size behind for its surface.
132
- useEffect(
133
- () => () => {
134
- if (ui.get().sectionDraft?.section === section.id) {
135
- ui.setSectionDraft(undefined);
136
- }
137
- },
138
- [section.id, ui]
139
- );
111
+ const area = sectionArea(layout);
112
+
113
+ const lineUp = () => ({
114
+ at: { x: layout.x, y: layout.y },
115
+ with: sectionResizeTargets(scene.layout, section.id),
116
+ });
117
+
118
+ const resized = ({ size, topLeftMovedBy: by }: Resized) => {
119
+ const topLeftMoved = by.x !== 0 || by.y !== 0;
120
+ editor.apply((current) =>
121
+ resizeSection(
122
+ current,
123
+ section.id,
124
+ sectionSizeShowing(size),
125
+ topLeftMoved ? { x: layout.x + by.x, y: layout.y + by.y } : undefined
126
+ )
127
+ );
128
+ };
129
+
140
130
  useEffect(() => {
141
131
  if (asked) {
142
132
  setNaming(undefined);
@@ -154,14 +144,14 @@ export const SectionNode = memo(
154
144
  style={area}
155
145
  >
156
146
  <div
157
- className="studio-screen studio-section-name absolute bottom-full left-0 flex origin-bottom-left flex-col"
147
+ className="studio-screen absolute bottom-full left-0 flex origin-bottom-left flex-col"
158
148
  // oxlint-disable-next-line shadcn/no-inline-styles -- computed at runtime: the section's area, from the canvas's layout
159
149
  style={{ width: `calc(${layout.width}px * var(--zoom))` }}
160
150
  >
161
151
  {/* As tall as layout's SECTION_NAME_REMS: Play's line, taller than
162
- the name's, and mb-2 (py-1 far out, inside its section). Only
163
- as wide as its words, and the space under them a margin: drawn
164
- over the frames, it takes a press only where it shows. */}
152
+ the name's, and mb-2, at every zoom (far out, on its pill).
153
+ Only as wide as its words, and the space under them a margin:
154
+ drawn over the frames, it takes a press only where it shows. */}
165
155
  <div className="studio-reveal-group studio-section-handle pointer-events-auto mb-2 flex items-center gap-1 self-start whitespace-nowrap select-none">
166
156
  <span className="studio-label shrink-0">
167
157
  <EditableText
@@ -183,22 +173,15 @@ export const SectionNode = memo(
183
173
 
184
174
  {editor.editable ? (
185
175
  <ResizeHandles
186
- onDraft={setDraft}
176
+ least={sectionArea(layout.least)}
177
+ lineUp={lineUp}
187
178
  onReset={() =>
188
179
  editor.apply((current) =>
189
180
  updateSection(current, section.id, { size: undefined })
190
181
  )
191
182
  }
192
- onResize={(size) => {
193
- // The section lays out again at its new size as the draft goes.
194
- editor.apply((current) =>
195
- updateSection(current, section.id, {
196
- size: sectionSizeShowing(size),
197
- })
198
- );
199
- setDraft(undefined);
200
- }}
201
- size={shown}
183
+ onResize={resized}
184
+ size={area}
202
185
  what="flow"
203
186
  />
204
187
  ) : null}
@@ -0,0 +1,21 @@
1
+ const SETTLE_MS = 320;
2
+ let settling: number | undefined;
3
+
4
+ /**
5
+ * Let the canvas ease into its next layout, once: a frame grows or shrinks to
6
+ * its new size and the frames around it make room, or dropped frames go to
7
+ * where the drop leaves them. Dragging stays immediate.
8
+ */
9
+ export const settle = (from: Element | null) => {
10
+ const canvas = from?.closest<HTMLElement>(".studio-canvas");
11
+
12
+ if (!canvas) {
13
+ return;
14
+ }
15
+
16
+ canvas.dataset.settling = "true";
17
+ window.clearTimeout(settling);
18
+ settling = window.setTimeout(() => {
19
+ delete canvas.dataset.settling;
20
+ }, SETTLE_MS);
21
+ };