@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
@@ -1,39 +1,92 @@
1
1
  import type { MessageDescriptor } from "@lingui/core";
2
2
  import { msg } from "@lingui/core/macro";
3
3
  import { useLingui } from "@lingui/react/macro";
4
- import { type PointerEvent, useEffect, useRef } from "react";
4
+ import {
5
+ createContext,
6
+ type CSSProperties,
7
+ type PointerEvent,
8
+ useContext,
9
+ useEffect,
10
+ useRef,
11
+ useState,
12
+ } from "react";
5
13
 
6
14
  import type { Point } from "./engine/camera";
7
- import { useCanvasView } from "./engine/canvas-view";
15
+ import { type SnapGuide, useCanvasView } from "./engine/canvas-view";
16
+ import type { Box } from "./layout";
17
+ import { settle } from "./settle";
18
+ import {
19
+ type ResizeSide,
20
+ type ResizeSides,
21
+ snapReach,
22
+ snapResize,
23
+ } from "./snapping";
8
24
 
9
- // Resizing a frame by its right edge, bottom edge or corner. The width is the
10
- // page's width, so the page reflows as you drag; the height is its viewport
11
- // height, the least the frame shows (a longer page still shows in full).
12
- // Double-click a handle to go back to the viewport's own size.
25
+ /** Shows the lines a resize lines up on, on the canvas: none to clear them. */
26
+ export const ShowSnapGuides = createContext<
27
+ (guides: readonly SnapGuide[]) => void
28
+ >(() => undefined);
29
+
30
+ /** What a resize lines up with: the frame's top left, and other boxes. */
31
+ export interface LineUp {
32
+ at: Point;
33
+ keepsTopLeft?: boolean;
34
+ with: readonly Box[];
35
+ }
13
36
 
14
37
  export interface Size {
15
38
  height: number;
16
39
  width: number;
17
40
  }
18
41
 
19
- type Edge = "right" | "bottom" | "corner";
42
+ export interface Resized {
43
+ size: Size;
44
+ topLeftMovedBy: Point;
45
+ }
46
+
47
+ const HANDLES = [
48
+ { edge: "top", sides: { y: "start" } },
49
+ { edge: "right", sides: { x: "end" } },
50
+ { edge: "bottom", sides: { y: "end" } },
51
+ { edge: "left", sides: { x: "start" } },
52
+ { edge: "top-left", sides: { x: "start", y: "start" } },
53
+ { edge: "top-right", sides: { x: "end", y: "start" } },
54
+ { edge: "bottom-right", sides: { x: "end", y: "end" } },
55
+ { edge: "bottom-left", sides: { x: "start", y: "end" } },
56
+ ] as const satisfies readonly { edge: string; sides: ResizeSides }[];
20
57
 
21
58
  const MIN_SIZE: Size = { width: 120, height: 80 };
22
- const EDGES: Edge[] = ["right", "bottom", "corner"];
23
59
 
24
- const LABELS: Record<"frame" | "flow", Record<Edge, MessageDescriptor>> = {
60
+ const resizes = (sides: ResizeSides) => {
61
+ if (sides.x && sides.y) {
62
+ return "both";
63
+ }
64
+
65
+ return sides.x ? "width" : "height";
66
+ };
67
+
68
+ const LABELS: Record<
69
+ "frame" | "flow",
70
+ Record<"width" | "height" | "both", MessageDescriptor>
71
+ > = {
25
72
  frame: {
26
- right: msg`Resize the frame's width`,
27
- bottom: msg`Resize the frame's height`,
28
- corner: msg`Resize the frame`,
73
+ width: msg`Resize the frame's width`,
74
+ height: msg`Resize the frame's height`,
75
+ both: msg`Resize the frame`,
29
76
  },
30
77
  flow: {
31
- right: msg`Resize the section's width`,
32
- bottom: msg`Resize the section's height`,
33
- corner: msg`Resize the section`,
78
+ width: msg`Resize the section's width`,
79
+ height: msg`Resize the section's height`,
80
+ both: msg`Resize the section`,
34
81
  },
35
82
  };
36
83
 
84
+ /** The canvas's zoom, as a frame shows: its laid-out width is before it. */
85
+ const zoomOf = (frame: HTMLElement) =>
86
+ frame.offsetWidth > 0
87
+ ? frame.getBoundingClientRect().width / frame.offsetWidth
88
+ : 1;
89
+
37
90
  /**
38
91
  * Where the pointer is on a frame, in the frame's own pixels from its top
39
92
  * left: the canvas's pixels, at any zoom. Measured at every event, since the
@@ -42,8 +95,7 @@ const LABELS: Record<"frame" | "flow", Record<Edge, MessageDescriptor>> = {
42
95
  */
43
96
  const pointOnFrame = (pointer: ClientPoint, frame: HTMLElement): Point => {
44
97
  const shown = frame.getBoundingClientRect();
45
- // Its laid-out width is before the canvas's transform: the ratio is the zoom.
46
- const zoom = frame.offsetWidth > 0 ? shown.width / frame.offsetWidth : 1;
98
+ const zoom = zoomOf(frame);
47
99
 
48
100
  return {
49
101
  x: (pointer.clientX - shown.left) / zoom,
@@ -59,65 +111,203 @@ interface ClientPoint {
59
111
  /** A drag of a handle: where it started, on the frame, and the pointer now. */
60
112
  interface Held {
61
113
  at: Point;
62
- edge: Edge;
63
114
  frame: HTMLElement;
64
115
  /** On the page, as the last pointer event had it. */
65
116
  pointer: ClientPoint;
117
+ shown: Size;
118
+ sides: ResizeSides;
66
119
  size: Size;
67
120
  }
68
121
 
69
- /** The size a drag of `edge` gives, from where it started to `at`. */
70
- const resized = (
71
- edge: Edge,
72
- from: { at: Point; size: Size },
73
- at: Point
74
- ): Size => ({
75
- width:
76
- edge === "bottom"
77
- ? from.size.width
78
- : Math.max(
79
- MIN_SIZE.width,
80
- Math.round(from.size.width + at.x - from.at.x)
81
- ),
82
- height:
83
- edge === "right"
84
- ? from.size.height
85
- : Math.max(
86
- MIN_SIZE.height,
87
- Math.round(from.size.height + at.y - from.at.y)
88
- ),
122
+ interface DragAxis {
123
+ setLength: number;
124
+ shownFrom: number;
125
+ shownLength: number;
126
+ }
127
+
128
+ interface Drag {
129
+ x: DragAxis;
130
+ y: DragAxis;
131
+ }
132
+
133
+ const dragAxis = (
134
+ side: ResizeSide | undefined,
135
+ {
136
+ least,
137
+ pointerMoved,
138
+ set,
139
+ shown,
140
+ }: { least: number; pointerMoved: number; set: number; shown: number }
141
+ ): DragAxis => {
142
+ if (!side) {
143
+ return { setLength: set, shownFrom: 0, shownLength: shown };
144
+ }
145
+
146
+ const setLength = Math.max(
147
+ least,
148
+ Math.round(side === "start" ? set - pointerMoved : set + pointerMoved)
149
+ );
150
+
151
+ const pageLongerThanSet = shown > set;
152
+
153
+ const shownLength = pageLongerThanSet
154
+ ? Math.max(setLength, shown)
155
+ : setLength;
156
+
157
+ return {
158
+ setLength,
159
+ shownFrom: side === "start" ? shown - shownLength : 0,
160
+ shownLength,
161
+ };
162
+ };
163
+
164
+ const dragOf = (held: Held, least: Size): Drag => {
165
+ const at = pointOnFrame(held.pointer, held.frame);
166
+ const { shown, sides, size } = held;
167
+
168
+ return {
169
+ x: dragAxis(sides.x, {
170
+ least: least.width,
171
+ pointerMoved: at.x - held.at.x,
172
+ set: size.width,
173
+ shown: shown.width,
174
+ }),
175
+ y: dragAxis(sides.y, {
176
+ least: least.height,
177
+ pointerMoved: at.y - held.at.y,
178
+ set: size.height,
179
+ shown: shown.height,
180
+ }),
181
+ };
182
+ };
183
+
184
+ const ghostOf = ({ x, y }: Drag): Box => ({
185
+ x: x.shownFrom,
186
+ y: y.shownFrom,
187
+ width: x.shownLength,
188
+ height: y.shownLength,
89
189
  });
90
190
 
91
- /** The size a held edge gives with the pointer and the camera as they are now. */
92
- const followed = (held: Held): Size =>
93
- resized(held.edge, held, pointOnFrame(held.pointer, held.frame));
191
+ const sidesThatLineUp = (
192
+ held: Held,
193
+ drag: Drag,
194
+ lineUp: LineUp
195
+ ): ResizeSides => {
196
+ const linesUp = (side: ResizeSide | undefined, axis: DragAxis) => {
197
+ const edgeIsAtPointer = axis.shownLength === axis.setLength;
198
+ const edgeMayMove = side === "end" || !lineUp.keepsTopLeft;
199
+
200
+ return side && edgeIsAtPointer && edgeMayMove ? side : undefined;
201
+ };
202
+
203
+ return {
204
+ x: linesUp(held.sides.x, drag.x),
205
+ y: linesUp(held.sides.y, drag.y),
206
+ };
207
+ };
208
+
209
+ const followed = (held: Held, least: Size, lineUp: LineUp | undefined) => {
210
+ const drag = dragOf(held, least);
211
+
212
+ if (!lineUp) {
213
+ return { drag, guides: [] };
214
+ }
215
+
216
+ const ghost = ghostOf(drag);
217
+ const sides = sidesThatLineUp(held, drag, lineUp);
218
+
219
+ const snap = snapResize(
220
+ { ...ghost, x: lineUp.at.x + ghost.x, y: lineUp.at.y + ghost.y },
221
+ sides,
222
+ lineUp.with,
223
+ snapReach(zoomOf(held.frame))
224
+ );
225
+
226
+ const x = Math.round(snap.box.x - lineUp.at.x);
227
+ const y = Math.round(snap.box.y - lineUp.at.y);
228
+ const width = Math.round(snap.box.width);
229
+ const height = Math.round(snap.box.height);
230
+
231
+ const snapGoesUnderLeast = width < least.width || height < least.height;
232
+
233
+ if (snapGoesUnderLeast) {
234
+ return { drag, guides: [] };
235
+ }
236
+
237
+ return {
238
+ drag: {
239
+ x: sides.x
240
+ ? { setLength: width, shownFrom: x, shownLength: width }
241
+ : drag.x,
242
+ y: sides.y
243
+ ? { setLength: height, shownFrom: y, shownLength: height }
244
+ : drag.y,
245
+ },
246
+ guides: snap.guides,
247
+ };
248
+ };
249
+
250
+ const Ghost = ({ box }: { box: Box }) => (
251
+ <div
252
+ aria-hidden
253
+ className="studio-resize-ghost"
254
+ // SAFETY: custom properties, which CSSProperties does not list.
255
+ style={
256
+ {
257
+ "--studio-ghost-x": `${box.x}px`,
258
+ "--studio-ghost-y": `${box.y}px`,
259
+ "--studio-ghost-width": `${box.width}px`,
260
+ "--studio-ghost-height": `${box.height}px`,
261
+ } as CSSProperties
262
+ }
263
+ />
264
+ );
94
265
 
95
266
  export const ResizeHandles = ({
267
+ least = MIN_SIZE,
268
+ lineUp,
96
269
  onDraft,
97
270
  onReset,
98
271
  onResize,
272
+ shown,
99
273
  size,
100
274
  what = "frame",
101
275
  }: {
276
+ least?: Size;
277
+ /** What its edges line up with, asked as it is dragged: none lines up. */
278
+ lineUp?: () => LineUp | undefined;
102
279
  /**
103
280
  * The size while dragging, or undefined when a drag changes nothing. A
104
281
  * drag that does keeps its size until the frame has it (see onResize).
105
282
  */
106
- onDraft: (size: Size | undefined) => void;
283
+ onDraft?: (size: Size | undefined) => void;
107
284
  onReset?: () => void;
108
- /** The size a drag ends on; the frame drops its draft once it has it. */
109
- onResize: (size: Size) => void;
285
+ onResize: (resized: Resized) => Promise<void> | void;
286
+ shown?: Size;
110
287
  size: Size;
111
288
  /** What resizes: a frame, or a section's area. */
112
289
  what?: "frame" | "flow";
113
290
  }) => {
114
291
  const { t, i18n } = useLingui();
115
292
  const view = useCanvasView();
293
+ const showGuides = useContext(ShowSnapGuides);
116
294
  const start = useRef<Held | undefined>(undefined);
117
- const latest = useRef<Size | undefined>(undefined);
118
- const draft = useRef(onDraft);
295
+ const latest = useRef<Drag | undefined>(undefined);
296
+ const dragsStarted = useRef(0);
297
+ const [ghost, setGhost] = useState<Box>();
298
+ /** The held edge to where the pointer and the camera take it now. */
299
+ const follow = useRef<(held: Held) => void>(undefined);
119
300
  // oxlint-disable-next-line react/refs -- read by the pointer handlers as they run, after render
120
- draft.current = onDraft;
301
+ follow.current = (held: Held) => {
302
+ const next = followed(held, least, lineUp?.());
303
+ latest.current = next.drag;
304
+ showGuides(next.guides);
305
+ setGhost(ghostOf(next.drag));
306
+ onDraft?.({
307
+ width: next.drag.x.setLength,
308
+ height: next.drag.y.setLength,
309
+ });
310
+ };
121
311
 
122
312
  // The camera can move while the pointer holds still (a zoom key, the zoom
123
313
  // menu): the edge follows it to the pointer all the same.
@@ -127,14 +317,13 @@ export const ResizeHandles = ({
127
317
  const held = start.current;
128
318
 
129
319
  if (held) {
130
- latest.current = followed(held);
131
- draft.current(latest.current);
320
+ follow.current?.(held);
132
321
  }
133
322
  }),
134
323
  [view]
135
324
  );
136
325
 
137
- const down = (edge: Edge) => (event: PointerEvent<HTMLElement>) => {
326
+ const down = (sides: ResizeSides) => (event: PointerEvent<HTMLElement>) => {
138
327
  // The left button resizes; a middle drag pans the canvas, as anywhere.
139
328
  if (event.button !== 0) {
140
329
  return;
@@ -148,11 +337,13 @@ export const ResizeHandles = ({
148
337
  }
149
338
 
150
339
  const pointer = { clientX: event.clientX, clientY: event.clientY };
340
+ dragsStarted.current += 1;
151
341
  start.current = {
152
342
  at: pointOnFrame(pointer, frame),
153
- edge,
154
343
  frame,
155
344
  pointer,
345
+ shown: shown ?? size,
346
+ sides,
156
347
  size,
157
348
  };
158
349
  event.currentTarget.setPointerCapture(event.pointerId);
@@ -166,45 +357,92 @@ export const ResizeHandles = ({
166
357
  }
167
358
 
168
359
  held.pointer = { clientX: event.clientX, clientY: event.clientY };
169
- latest.current = followed(held);
170
- onDraft(latest.current);
360
+ follow.current?.(held);
171
361
  };
172
362
 
173
- const up = () => {
174
- const from = start.current?.size;
175
- const done = latest.current;
363
+ const letGo = () => {
364
+ setGhost(undefined);
365
+ onDraft?.(undefined);
366
+ };
367
+
368
+ const end = () => {
369
+ const held = start.current;
370
+ const drag = latest.current;
176
371
  start.current = undefined;
177
372
  latest.current = undefined;
373
+ showGuides([]);
178
374
 
179
- const changed =
180
- done && (done.width !== from?.width || done.height !== from?.height);
375
+ return held && drag ? { drag, held } : undefined;
376
+ };
181
377
 
182
- if (changed) {
183
- onResize(done);
184
- } else {
185
- onDraft(undefined);
378
+ const cancel = () => {
379
+ end();
380
+ letGo();
381
+ };
382
+
383
+ const up = () => {
384
+ const ended = end();
385
+
386
+ if (
387
+ !ended ||
388
+ (ended.drag.x.setLength === ended.held.size.width &&
389
+ ended.drag.y.setLength === ended.held.size.height)
390
+ ) {
391
+ letGo();
392
+
393
+ return;
186
394
  }
395
+
396
+ const { drag, held } = ended;
397
+ settle(held.frame);
398
+
399
+ const pending = onResize({
400
+ size: { width: drag.x.setLength, height: drag.y.setLength },
401
+ topLeftMovedBy: { x: drag.x.shownFrom, y: drag.y.shownFrom },
402
+ });
403
+
404
+ if (!pending) {
405
+ letGo();
406
+
407
+ return;
408
+ }
409
+
410
+ const thisDrag = dragsStarted.current;
411
+ pending
412
+ .finally(() => {
413
+ const noDragStartedSince = dragsStarted.current === thisDrag;
414
+
415
+ if (noDragStartedSince) {
416
+ letGo();
417
+ }
418
+ })
419
+ .catch(() => undefined);
187
420
  };
188
421
 
189
- return EDGES.map((edge) => {
190
- const label = i18n._(LABELS[what][edge]);
191
-
192
- return (
193
- <div
194
- aria-hidden
195
- className="studio-resize nodrag nopan"
196
- data-edge={edge}
197
- key={edge}
198
- onDoubleClick={(event) => {
199
- event.stopPropagation();
200
- onReset?.();
201
- }}
202
- onPointerCancel={up}
203
- onPointerDown={down(edge)}
204
- onPointerMove={move}
205
- onPointerUp={up}
206
- title={onReset ? t`${label}. Double-click to reset.` : label}
207
- />
208
- );
209
- });
422
+ return (
423
+ <>
424
+ {ghost ? <Ghost box={ghost} /> : null}
425
+ {HANDLES.map(({ edge, sides }) => {
426
+ const label = i18n._(LABELS[what][resizes(sides)]);
427
+
428
+ return (
429
+ <div
430
+ aria-hidden
431
+ className="studio-resize nodrag nopan"
432
+ data-edge={edge}
433
+ key={edge}
434
+ onDoubleClick={(event) => {
435
+ event.stopPropagation();
436
+ onReset?.();
437
+ }}
438
+ onPointerCancel={cancel}
439
+ onPointerDown={down(sides)}
440
+ onPointerMove={move}
441
+ onPointerUp={up}
442
+ title={onReset ? t`${label}. Double-click to reset.` : label}
443
+ />
444
+ );
445
+ })}
446
+ </>
447
+ );
210
448
  };
@@ -21,8 +21,6 @@ const REACH = 20;
21
21
  /** How far left of a section a row's handle can be, in screen pixels. */
22
22
  const HANDLE_REACH = 56;
23
23
 
24
- /** How far above a stack its handle can be, in screen pixels. */
25
- const STACK_HANDLE_REACH = 88;
26
24
  const HINT = ".studio-insert";
27
25
  const ROW_HOVER = "data-hover";
28
26
 
@@ -51,7 +49,6 @@ export const InsertHint = ({
51
49
  /** Its + has its menu open: it stays where it is until that closes. */
52
50
  const held = useRef(false);
53
51
  const row = useRef<Element>(null);
54
- const stack = useRef<Element>(null);
55
52
  const latest = useRef({ scene, skip });
56
53
  // oxlint-disable-next-line react/refs -- read by the pointer listeners as they run, after render
57
54
  latest.current = { scene, skip };
@@ -63,29 +60,25 @@ export const InsertHint = ({
63
60
  return;
64
61
  }
65
62
 
66
- // The handle of a row, or of a stack, the pointer is near shows.
67
- const hover = (shown: { current: Element | null }, id?: string) => {
63
+ // The handle of the row the pointer is near shows.
64
+ const hoverRow = (id?: string) => {
68
65
  const next = id
69
66
  ? element.querySelector(`[data-canvas-item="${CSS.escape(id)}"]`)
70
67
  : null;
71
68
 
72
- if (next !== shown.current) {
73
- shown.current?.removeAttribute(ROW_HOVER);
69
+ if (next !== row.current) {
70
+ row.current?.removeAttribute(ROW_HOVER);
74
71
  next?.setAttribute(ROW_HOVER, "true");
75
- shown.current = next;
72
+ row.current = next;
76
73
  }
77
74
  };
78
75
 
79
- const hoverRow = (id?: string) => hover(row, id);
80
- const hoverStack = (id?: string) => hover(stack, id);
81
-
82
76
  const clear = () => {
83
77
  if (!held.current) {
84
78
  setGap(undefined);
85
79
  }
86
80
 
87
81
  hoverRow();
88
- hoverStack();
89
82
  };
90
83
 
91
84
  /** The gap the pointer is in, when its + shows there. */
@@ -123,9 +116,6 @@ export const InsertHint = ({
123
116
  const zoom = view.getZoom();
124
117
  const point = view.screenToCanvas({ x: event.clientX, y: event.clientY });
125
118
  hoverRow(latest.current.scene.rowAt(point, HANDLE_REACH / zoom));
126
- hoverStack(
127
- latest.current.scene.stackAt(point, STACK_HANDLE_REACH / zoom)
128
- );
129
119
  const next = gapUnder(target, point, zoom);
130
120
  setGap((current) => (sameGap(current, next) ? current : next));
131
121
  };