@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.
- package/CHANGELOG.md +31 -0
- package/app/canvas/canvas-commands.ts +2 -10
- package/app/canvas/canvas-context.tsx +11 -2
- package/app/canvas/canvas-document.ts +5 -1
- package/app/canvas/canvas-keys.ts +1 -1
- package/app/canvas/canvas-model.ts +195 -20
- package/app/canvas/canvas-scene.ts +176 -171
- package/app/canvas/canvas-ui.ts +4 -11
- package/app/canvas/canvas.css +159 -179
- package/app/canvas/change-pictures.tsx +156 -0
- package/app/canvas/comment-drafts.ts +31 -0
- package/app/canvas/comment-layer.tsx +125 -71
- package/app/canvas/comments.tsx +38 -2
- package/app/canvas/element-picker.ts +20 -0
- package/app/canvas/engine/canvas-gestures.ts +15 -3
- package/app/canvas/engine/canvas-store.ts +5 -0
- package/app/canvas/engine/canvas-view.tsx +22 -5
- package/app/canvas/find-bar.tsx +57 -41
- package/app/canvas/flow-canvas.tsx +147 -272
- package/app/canvas/frame-copies.ts +14 -17
- package/app/canvas/frame-drops.ts +15 -7
- package/app/canvas/frame-inspector.ts +192 -41
- package/app/canvas/frame-node.tsx +123 -75
- package/app/canvas/frame-resize.tsx +321 -83
- package/app/canvas/insert-hint.tsx +5 -15
- package/app/canvas/inspect-layer.tsx +73 -19
- package/app/canvas/label-action.tsx +13 -2
- package/app/canvas/layout.ts +233 -98
- package/app/canvas/live-page.ts +5 -0
- package/app/canvas/new-frame.ts +10 -25
- package/app/canvas/note-placing.ts +55 -84
- package/app/canvas/picked-box.tsx +5 -0
- package/app/canvas/picks-menu.tsx +3 -9
- package/app/canvas/readable-colour.ts +52 -0
- package/app/canvas/request-node.tsx +19 -10
- package/app/canvas/scrolling-page.ts +45 -0
- package/app/canvas/section-node.tsx +36 -53
- package/app/canvas/settle.ts +21 -0
- package/app/canvas/snapping.ts +96 -8
- package/app/canvas/spec-frame.tsx +8 -5
- package/app/canvas/spot-pins.tsx +15 -3
- package/app/canvas/stack-frame.tsx +13 -57
- package/app/canvas/stack-model.ts +5 -0
- package/app/canvas/stack-toggle.tsx +89 -0
- package/app/canvas/styles-layer.tsx +23 -43
- package/app/canvas/text-layer.tsx +26 -10
- package/app/canvas/thread-focus.tsx +18 -1
- package/app/canvas/tool-cursors.ts +2 -2
- package/app/canvas/toolbar-parts.tsx +48 -8
- package/app/canvas/toolbar.tsx +12 -10
- package/app/canvas/use-canvas-clipboard.tsx +13 -5
- package/app/canvas/use-reveal.ts +86 -0
- package/app/editor/extensions.ts +2 -0
- package/app/editor/line-break-caret.ts +57 -0
- package/app/git/branch-panel.tsx +61 -20
- package/app/i18n/locales/en/messages.po +64 -17
- package/app/i18n/locales/en/messages.ts +1 -1
- package/app/i18n/locales/pseudo/messages.po +64 -17
- package/app/i18n/locales/pseudo/messages.ts +1 -1
- package/app/icons/glyphs.tsx +2 -0
- package/app/live/studio-live.ts +29 -9
- package/app/pages/canvas.tsx +1 -1
- package/app/pages/commands-settings.tsx +70 -76
- package/app/pages/play-bar.tsx +6 -11
- package/app/pages/play.tsx +52 -33
- package/app/shell/feedback-form.tsx +29 -5
- package/app/ui/prompt-editor.tsx +2 -0
- package/app/ui/use-field-list.ts +90 -0
- package/dist/cli/commands/mcp.mjs +6 -4
- package/dist/cli/mcp-relay.mjs +10 -6
- package/dist/content/content.d.mts +26 -9
- package/dist/content/content.mjs +65 -8
- package/dist/content/screenshot.d.mts +2 -0
- package/dist/content/screenshot.mjs +3 -0
- package/dist/content/snapshot-client.d.mts +2 -0
- package/dist/content/snapshot-client.mjs +12 -1
- package/dist/inspector.js +96 -19
- package/dist/paste/paste.d.mts +5 -0
- package/dist/paste/paste.mjs +7 -2
- package/dist/server/agent-tools.d.mts +1 -0
- package/dist/server/agent-tools.mjs +4 -3
- package/dist/server/change-picture-store.d.mts +13 -0
- package/dist/server/change-picture-store.mjs +42 -0
- package/dist/server/change-pictures.d.mts +25 -0
- package/dist/server/change-pictures.mjs +104 -0
- package/dist/server/close-check.d.mts +11 -0
- package/dist/server/close-check.mjs +37 -5
- package/dist/server/comments/agent-actions.d.mts +8 -4
- package/dist/server/comments/agent-actions.mjs +16 -7
- package/dist/server/comments/close-tools.mjs +7 -5
- package/dist/server/comments/files.d.mts +5 -1
- package/dist/server/comments/hand-out.d.mts +1 -1
- package/dist/server/comments/hand-out.mjs +4 -1
- package/dist/server/comments/push.d.mts +19 -10
- package/dist/server/comments/push.mjs +45 -30
- package/dist/server/comments/studio-files.d.mts +14 -1
- package/dist/server/comments/studio-files.mjs +44 -31
- package/dist/server/comments/tools.d.mts +1 -1
- package/dist/server/comments/workspace.mjs +1 -0
- package/dist/server/dev-server.mjs +34 -0
- package/dist/server/own-copies.mjs +4 -23
- package/dist/server/requests.mjs +57 -3
- package/dist/server/response-budget.d.mts +2 -1
- package/dist/server/response-budget.mjs +4 -3
- package/dist/server/roster.d.mts +19 -8
- package/dist/server/roster.mjs +50 -22
- package/dist/server/studio-for.d.mts +7 -0
- package/dist/server/studio-for.mjs +23 -7
- package/dist/server/thread-forms.d.mts +3 -0
- package/dist/server/thread-forms.mjs +21 -1
- package/dist/server/tools/place-frame.d.mts +1 -0
- package/dist/server/tools/place-frame.mjs +33 -9
- package/dist/server/tools/result.mjs +2 -2
- package/dist/server/tools/snapshot.d.mts +1 -1
- package/dist/server/tools/snapshot.mjs +2 -1
- package/dist/server/tools/studio-context.d.mts +2 -1
- package/dist/server/tools/studio-context.mjs +2 -1
- package/dist/server/tools/watch.mjs +29 -12
- package/dist/server/work-groups.mjs +1 -1
- package/dist/shared/canvas-core.d.mts +39 -5
- package/dist/shared/canvas-core.mjs +60 -15
- package/dist/shared/canvas-file.d.mts +7 -4
- package/dist/shared/change-pictures-core.d.mts +6 -0
- package/dist/shared/change-pictures-core.mjs +5 -0
- package/dist/shared/page-looks.d.mts +12 -0
- package/dist/shared/page-looks.mjs +49 -0
- package/dist/shared/snapshot-clipboard.d.mts +6 -0
- package/dist/shared/studio-routes.d.mts +11 -0
- package/extension/dist/manifest.json +1 -1
- package/extension/dist/picker.js +114 -108
- package/package.json +4 -3
- package/src/cli/commands/mcp.ts +18 -8
- package/src/cli/mcp-relay.ts +13 -6
- package/src/content/content.ts +90 -16
- package/src/content/screenshot.ts +9 -1
- package/src/content/snapshot-client.ts +17 -0
- package/src/paste/paste.ts +18 -1
- package/src/server/agent-tools.ts +5 -4
- package/src/server/change-picture-store.ts +71 -0
- package/src/server/change-pictures.ts +244 -0
- package/src/server/close-check.ts +69 -6
- package/src/server/comments/agent-actions.ts +51 -12
- package/src/server/comments/close-tools.ts +20 -10
- package/src/server/comments/files.ts +10 -2
- package/src/server/comments/hand-out.ts +2 -2
- package/src/server/comments/push.ts +94 -46
- package/src/server/comments/studio-files.ts +77 -46
- package/src/server/comments/workspace.ts +1 -0
- package/src/server/dev-server.ts +70 -0
- package/src/server/own-copies.ts +5 -33
- package/src/server/requests.ts +84 -4
- package/src/server/response-budget.ts +5 -3
- package/src/server/roster.ts +78 -28
- package/src/server/studio-for.ts +32 -7
- package/src/server/thread-forms.ts +41 -1
- package/src/server/tools/place-frame.ts +71 -14
- package/src/server/tools/result.ts +2 -2
- package/src/server/tools/snapshot.ts +2 -1
- package/src/server/tools/studio-context.ts +24 -14
- package/src/server/tools/watch.ts +38 -13
- package/src/server/work-groups.ts +1 -1
- package/src/shared/canvas-core.ts +119 -27
- package/src/shared/canvas-file.ts +7 -4
- package/src/shared/change-pictures-core.ts +8 -0
- package/src/shared/page-looks.ts +133 -0
- package/src/shared/snapshot-clipboard.ts +6 -0
- package/src/shared/studio-routes.ts +7 -1
- package/templates/agents/dex-worker.md +9 -7
- package/templates/feedback-workflow.md +1 -1
- package/templates/methods/review.md +7 -6
- package/templates/rules/canvas-frames.md +8 -7
- package/templates/rules/canvas.md +10 -8
- package/templates/rules/prototypes.md +5 -3
- package/app/canvas/stack-node.tsx +0 -100
|
@@ -13,10 +13,12 @@ import type { Canvas, Thread, ThreadTarget } from "../types";
|
|
|
13
13
|
import { frameOfTarget, pendingCells } from "./anchoring.ts";
|
|
14
14
|
import {
|
|
15
15
|
type Cell,
|
|
16
|
+
cellKeys,
|
|
16
17
|
frameKey,
|
|
17
18
|
moveFrame,
|
|
18
19
|
moveOwnFrames,
|
|
19
20
|
moveRow,
|
|
21
|
+
moveStack,
|
|
20
22
|
type PlacedFrames,
|
|
21
23
|
parseFrameKey,
|
|
22
24
|
placeSection,
|
|
@@ -53,8 +55,12 @@ import type { RequestNodeData } from "./request-node";
|
|
|
53
55
|
import type { RowNodeData } from "./row-node";
|
|
54
56
|
import type { SectionNodeData, SectionSurfaceData } from "./section-node";
|
|
55
57
|
import type { StackRole } from "./stack-frame";
|
|
56
|
-
import {
|
|
57
|
-
|
|
58
|
+
import {
|
|
59
|
+
fannedOut,
|
|
60
|
+
type OpenStack,
|
|
61
|
+
type Stack,
|
|
62
|
+
stacksOf,
|
|
63
|
+
} from "./stack-model.ts";
|
|
58
64
|
|
|
59
65
|
// The canvas scene: the canvas laid out once, from canvas.json, the heights
|
|
60
66
|
// pages report and the requests for new views waiting in their cells. The
|
|
@@ -86,33 +92,22 @@ export type SurfaceItem = CanvasViewItem<SectionSurfaceData> & {
|
|
|
86
92
|
/** A row's handle, at its left: what it is dragged by. */
|
|
87
93
|
export type RowItem = CanvasViewItem<RowNodeData> & { type: "row" };
|
|
88
94
|
|
|
89
|
-
/** A stack's handle, above its first frame: what the stack is dragged by. */
|
|
90
|
-
export type StackItem = CanvasViewItem<StackNodeData> & { type: "stack" };
|
|
91
|
-
|
|
92
95
|
export type CanvasNode =
|
|
93
96
|
| FrameItem
|
|
94
97
|
| RequestItem
|
|
95
98
|
| RowItem
|
|
96
99
|
| SectionItem
|
|
97
|
-
| StackItem
|
|
98
100
|
| SurfaceItem;
|
|
99
101
|
|
|
100
102
|
const SECTION_PREFIX = "section:";
|
|
101
103
|
const SURFACE_PREFIX = "surface:";
|
|
102
104
|
const ROW_PREFIX = "row:";
|
|
103
|
-
const STACK_PREFIX = "stack:";
|
|
104
105
|
const REQUEST_PREFIX = "request:";
|
|
105
106
|
|
|
106
107
|
/** A request's item on the canvas, by its thread. */
|
|
107
108
|
export const requestNodeId = (thread: string) => `${REQUEST_PREFIX}${thread}`;
|
|
108
109
|
export const isRequestNode = (id: string) => id.startsWith(REQUEST_PREFIX);
|
|
109
110
|
|
|
110
|
-
/** A stack's item on the canvas, by its row and its first frame. */
|
|
111
|
-
export const stackNodeId = (section: string, row: string, first: string) =>
|
|
112
|
-
`${STACK_PREFIX}${section}/${row}/${first}`;
|
|
113
|
-
|
|
114
|
-
export const isStackNode = (id: string) => id.startsWith(STACK_PREFIX);
|
|
115
|
-
|
|
116
111
|
/** A row's item on the canvas. */
|
|
117
112
|
export const rowNodeId = (section: string, row: string) =>
|
|
118
113
|
`${ROW_PREFIX}${section}/${row}`;
|
|
@@ -132,7 +127,6 @@ export const isFrameNode = (id: string) =>
|
|
|
132
127
|
isSectionNode(id) ||
|
|
133
128
|
isSurfaceNode(id) ||
|
|
134
129
|
isRowNode(id) ||
|
|
135
|
-
isStackNode(id) ||
|
|
136
130
|
isRequestNode(id)
|
|
137
131
|
);
|
|
138
132
|
|
|
@@ -215,7 +209,8 @@ export interface CanvasScene {
|
|
|
215
209
|
* gives the next free step in its row. With `between`, as a drag asks,
|
|
216
210
|
* where a drag drops: onto a stack, a new column or a new row (words,
|
|
217
211
|
* `text`, by their own rules). With `inReach`, none for a point out of
|
|
218
|
-
* reach of every section.
|
|
212
|
+
* reach of every section. The frames `moving` (by key) are no place to
|
|
213
|
+
* drop them: a closed stack's top carries its cell (carried).
|
|
219
214
|
*/
|
|
220
215
|
cellAt: (
|
|
221
216
|
point: { x: number; y: number },
|
|
@@ -233,14 +228,26 @@ export interface CanvasScene {
|
|
|
233
228
|
) => Box | undefined;
|
|
234
229
|
/**
|
|
235
230
|
* The frames that travel with an item dragged, a section's or a row's, and
|
|
236
|
-
* the requests waiting in it.
|
|
231
|
+
* the requests waiting in it; a closed stack's, the words in its cell.
|
|
237
232
|
*/
|
|
238
233
|
dragWith: (id: string) => string[];
|
|
234
|
+
/**
|
|
235
|
+
* The frames a drag of these takes, by key, each once, in groups: a closed
|
|
236
|
+
* stack's top takes its cell, its stack and any words in it, in their
|
|
237
|
+
* order; any other frame goes as itself.
|
|
238
|
+
*/
|
|
239
|
+
carried: (keys: Iterable<string>) => string[][];
|
|
240
|
+
/**
|
|
241
|
+
* Whether a frame dragged is the top of a stack drawn closed, which moves
|
|
242
|
+
* its whole cell: it goes in a cell, its frames still stacked.
|
|
243
|
+
*/
|
|
244
|
+
carriesStack: (key: string) => boolean;
|
|
239
245
|
/**
|
|
240
246
|
* `canvas` with frames dropped into a cell: `lead`, the one dragged, goes
|
|
241
247
|
* in it, and the others keep their spacing in steps from it, as this scene
|
|
242
|
-
* has them. `frames` are their keys, left to right
|
|
243
|
-
*
|
|
248
|
+
* has them. `frames` are their keys, left to right; a closed stack's top
|
|
249
|
+
* takes its cell with it (carried). The same canvas when they land where
|
|
250
|
+
* they were. `keys` are the keys they land at, a cell's every frame.
|
|
244
251
|
*/
|
|
245
252
|
dropFrames: (
|
|
246
253
|
canvas: Canvas,
|
|
@@ -252,7 +259,7 @@ export interface CanvasScene {
|
|
|
252
259
|
* How a cell shows as the place frames `moving` (by key) would drop, the
|
|
253
260
|
* one held of this `size`: a line where frames make room, words go or a
|
|
254
261
|
* new row goes, or the slot it takes in a cell nothing is in or on top of
|
|
255
|
-
* a stack.
|
|
262
|
+
* a stack. A closed stack's top carries its cell, as in cellAt.
|
|
256
263
|
*/
|
|
257
264
|
dropMark: (
|
|
258
265
|
cell: Cell,
|
|
@@ -292,11 +299,19 @@ export interface CanvasScene {
|
|
|
292
299
|
* shows: a frame by its key, or a section by its item.
|
|
293
300
|
*/
|
|
294
301
|
hides: (id: string) => boolean;
|
|
302
|
+
/**
|
|
303
|
+
* Whether frames dragged by `lead`, let go with the pointer at `pointer`,
|
|
304
|
+
* stay where they are put, each a frame of its own: a frame of its own
|
|
305
|
+
* held outside every section, or a frame of a section held out of reach
|
|
306
|
+
* of every section. A closed stack never does: a stack is only ever in a
|
|
307
|
+
* cell, so it goes in the nearest one.
|
|
308
|
+
*/
|
|
309
|
+
dropsFree: (lead: Box & { id: string }, pointer: Point) => boolean;
|
|
295
310
|
/** Whether a frame is a frame of its own, in no section. */
|
|
296
311
|
isOwnFrame: (key: string) => boolean;
|
|
297
312
|
/**
|
|
298
313
|
* What the engine draws: each section's surface, each row's handle, each
|
|
299
|
-
* frame, each request,
|
|
314
|
+
* frame, each request, then each section.
|
|
300
315
|
*/
|
|
301
316
|
items: CanvasNode[];
|
|
302
317
|
/**
|
|
@@ -356,11 +371,6 @@ export interface CanvasScene {
|
|
|
356
371
|
row: string,
|
|
357
372
|
middle: number
|
|
358
373
|
) => { above?: string } | undefined;
|
|
359
|
-
/** The item of the stack a point is over, or just above, where its handle is. */
|
|
360
|
-
stackAt: (
|
|
361
|
-
point: { x: number; y: number },
|
|
362
|
-
reach?: number
|
|
363
|
-
) => string | undefined;
|
|
364
374
|
/** Whether dropping the frame `key` in a cell leaves it where it is. */
|
|
365
375
|
staysPut: (key: string, cell: Cell) => boolean;
|
|
366
376
|
}
|
|
@@ -371,6 +381,7 @@ const EMPTY_SECTION: PlacedSection = {
|
|
|
371
381
|
width: 0,
|
|
372
382
|
height: 0,
|
|
373
383
|
columns: [],
|
|
384
|
+
least: { width: 0, height: 0 },
|
|
374
385
|
rows: [],
|
|
375
386
|
newRow: { x: 0, y: 0, width: 0, height: 0 },
|
|
376
387
|
};
|
|
@@ -378,6 +389,31 @@ const EMPTY_SECTION: PlacedSection = {
|
|
|
378
389
|
/** Fanned out, a stack's frames sit over everything else on the canvas. */
|
|
379
390
|
const OPEN_STACK_Z = 50;
|
|
380
391
|
|
|
392
|
+
/**
|
|
393
|
+
* Whether a frame is the top of a stack drawn closed, which stands for its
|
|
394
|
+
* cell: dragged, it moves the whole cell, its frames still stacked.
|
|
395
|
+
*/
|
|
396
|
+
const isClosedTop = (role?: StackRole) => role?.index === 0 && !fannedOut(role);
|
|
397
|
+
|
|
398
|
+
/** A frame's item's dragging, picking and drawing, by its part in a stack. */
|
|
399
|
+
const frameItemProps = (editable: boolean, role?: StackRole) => {
|
|
400
|
+
const open = role !== undefined && fannedOut(role);
|
|
401
|
+
|
|
402
|
+
return {
|
|
403
|
+
// A live frame moves by its name; its page keeps the pointer. A closed
|
|
404
|
+
// stack moves as a frame does, by its top, and takes its cell with it
|
|
405
|
+
// (carried); fanned out, each of its frames moves by its name, out of it
|
|
406
|
+
// or to its top.
|
|
407
|
+
draggable: editable && (!role || open || isClosedTop(role)),
|
|
408
|
+
copyable: editable,
|
|
409
|
+
// A click on a closed stack fans it out, as on a macOS stack, rather
|
|
410
|
+
// than picking its top; its menu is still a right click.
|
|
411
|
+
selectable: !role || open,
|
|
412
|
+
// Fanned out, over the rest; the top over the frames from under it.
|
|
413
|
+
zIndex: role?.open ? OPEN_STACK_Z + role.count - role.index : 2,
|
|
414
|
+
};
|
|
415
|
+
};
|
|
416
|
+
|
|
381
417
|
/**
|
|
382
418
|
* Where a stack's frames go when it fans out: down from its top, one under
|
|
383
419
|
* another in reading order, as Sonner lists its toasts, each its own size
|
|
@@ -587,7 +623,14 @@ function sceneItems(
|
|
|
587
623
|
zIndex: -1,
|
|
588
624
|
}));
|
|
589
625
|
|
|
590
|
-
|
|
626
|
+
// Sections share a layer, where the later item is drawn over. A name sits
|
|
627
|
+
// above its section and far out reaches over the section above and its
|
|
628
|
+
// bottom resize edge, so a section lower on the canvas comes later: one
|
|
629
|
+
// placed by hand below a section listed after it keeps its name on top,
|
|
630
|
+
// and the press on it (SUD-99).
|
|
631
|
+
const topDown = drawn.toSorted((a, b) => a.box.y - b.box.y);
|
|
632
|
+
|
|
633
|
+
const sections: CanvasNode[] = topDown.map(({ box, index, section }) => ({
|
|
591
634
|
id: sectionNodeId(section.id),
|
|
592
635
|
type: "section" as const,
|
|
593
636
|
// The area it draws, which a box round it holds: its place in the
|
|
@@ -605,11 +648,16 @@ function sceneItems(
|
|
|
605
648
|
dragHandle: ".studio-section-handle",
|
|
606
649
|
// Picked by its name, as a frame is by itself, or by a box drawn round
|
|
607
650
|
// all of it; a box within it picks the frames there.
|
|
608
|
-
// Its name and edges are drawn over
|
|
609
|
-
//
|
|
610
|
-
//
|
|
611
|
-
//
|
|
651
|
+
// Its name and edges are drawn over frames: they are the same size on
|
|
652
|
+
// screen at any zoom, while the gap above it and its padding are canvas
|
|
653
|
+
// pixels, so far out what was drawn over them (its own frames, and the
|
|
654
|
+
// section above's under its name) would cover them and take their
|
|
655
|
+
// presses (SUD-66).
|
|
612
656
|
zIndex: 4,
|
|
657
|
+
// Picked, it stays in that layer, in its place top to bottom: lifted
|
|
658
|
+
// over the rest, far out its bottom edge would cover the name of the
|
|
659
|
+
// section below, the next one often pressed (SUD-99).
|
|
660
|
+
keepsLayer: true,
|
|
613
661
|
// Only its names and buttons take the pointer.
|
|
614
662
|
passThrough: true,
|
|
615
663
|
}));
|
|
@@ -635,8 +683,6 @@ function sceneItems(
|
|
|
635
683
|
return [];
|
|
636
684
|
}
|
|
637
685
|
|
|
638
|
-
const open = stack?.role.open === true && !stack.role.closing;
|
|
639
|
-
|
|
640
686
|
return {
|
|
641
687
|
id: key,
|
|
642
688
|
type: "frame" as const,
|
|
@@ -647,7 +693,7 @@ function sceneItems(
|
|
|
647
693
|
data: {
|
|
648
694
|
// A step goes after it only in a row the person may change, and
|
|
649
695
|
// never from a stack fanned out, nor after a section header,
|
|
650
|
-
// which
|
|
696
|
+
// which reaches across the columns after its own.
|
|
651
697
|
addable:
|
|
652
698
|
editable &&
|
|
653
699
|
!stack?.role.open &&
|
|
@@ -661,18 +707,7 @@ function sceneItems(
|
|
|
661
707
|
step: steps[index] ?? index + 1,
|
|
662
708
|
width: placed.width,
|
|
663
709
|
},
|
|
664
|
-
|
|
665
|
-
// closed stack moves by its handle (stack-node.tsx); fanned out,
|
|
666
|
-
// each of its frames moves by its name, out of it or to its top.
|
|
667
|
-
draggable: editable && (!stack || open),
|
|
668
|
-
copyable: editable,
|
|
669
|
-
// A click on a closed stack fans it out, as on a macOS stack,
|
|
670
|
-
// rather than picking its top; its menu is still a right click.
|
|
671
|
-
selectable: !(stack && (!stack.role.open || stack.role.closing)),
|
|
672
|
-
// Fanned out, over the rest; the top over the frames from under it.
|
|
673
|
-
zIndex: stack?.role.open
|
|
674
|
-
? OPEN_STACK_Z + stack.role.count - stack.role.index
|
|
675
|
-
: 2,
|
|
710
|
+
...frameItemProps(editable, stack?.role),
|
|
676
711
|
};
|
|
677
712
|
});
|
|
678
713
|
})
|
|
@@ -716,12 +751,11 @@ function sceneItems(
|
|
|
716
751
|
});
|
|
717
752
|
});
|
|
718
753
|
|
|
719
|
-
const stacks = editable ? stackItems(canvas, layout, me) : [];
|
|
720
754
|
const requests = requestItems(canvas, layout, threads, editable, me);
|
|
721
755
|
|
|
722
756
|
// Sections after their frames, so a section dragged (its frames with it,
|
|
723
757
|
// all lifted alike) still shows its name over them.
|
|
724
|
-
return [...surfaces, ...rows, ...frames, ...requests, ...sections
|
|
758
|
+
return [...surfaces, ...rows, ...frames, ...requests, ...sections];
|
|
725
759
|
}
|
|
726
760
|
|
|
727
761
|
/**
|
|
@@ -779,82 +813,6 @@ const requestItems = (
|
|
|
779
813
|
};
|
|
780
814
|
});
|
|
781
815
|
|
|
782
|
-
/**
|
|
783
|
-
* A handle for each stack of two or more frames, in rows the person may
|
|
784
|
-
* rearrange: above its cell's first frame, the cell's frames (its stack, and
|
|
785
|
-
* any words in it) listed for dragging. A frame alone moves by itself.
|
|
786
|
-
*/
|
|
787
|
-
const stackItems = (
|
|
788
|
-
canvas: Canvas,
|
|
789
|
-
layout: Layout,
|
|
790
|
-
me: string | undefined
|
|
791
|
-
): CanvasNode[] =>
|
|
792
|
-
canvas.sections.flatMap((section) => {
|
|
793
|
-
if (layout.sections.get(section.id)?.own) {
|
|
794
|
-
return [];
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
return section.rows.flatMap((row) => {
|
|
798
|
-
if (isOthersRow(section, row, me)) {
|
|
799
|
-
return [];
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
const steps = stepsOf(row.frames);
|
|
803
|
-
const columns = new Map<number, string[]>();
|
|
804
|
-
|
|
805
|
-
for (const [index, frame] of row.frames.entries()) {
|
|
806
|
-
const step = steps[index] ?? index + 1;
|
|
807
|
-
const cell = columns.get(step);
|
|
808
|
-
|
|
809
|
-
if (cell) {
|
|
810
|
-
cell.push(frame.id);
|
|
811
|
-
} else {
|
|
812
|
-
columns.set(step, [frame.id]);
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
const keyOf = (frame: string) =>
|
|
817
|
-
frameKey({ section: section.id, row: row.id, frame });
|
|
818
|
-
|
|
819
|
-
const heads = [...columns.entries()].toSorted(([a], [b]) => a - b);
|
|
820
|
-
|
|
821
|
-
return heads.flatMap(([step, frames], index) => {
|
|
822
|
-
const [first] = frames;
|
|
823
|
-
const placed = first ? layout.frames.get(keyOf(first)) : undefined;
|
|
824
|
-
// A stack folds the frames under its top: a cell with none is none.
|
|
825
|
-
const stacked = frames.some((frame) => layout.folded.has(keyOf(frame)));
|
|
826
|
-
|
|
827
|
-
if (!(first && placed && stacked)) {
|
|
828
|
-
return [];
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
return {
|
|
832
|
-
id: stackNodeId(section.id, row.id, first),
|
|
833
|
-
type: "stack" as const,
|
|
834
|
-
x: placed.x,
|
|
835
|
-
y: placed.y,
|
|
836
|
-
width: placed.width,
|
|
837
|
-
height: 0,
|
|
838
|
-
data: {
|
|
839
|
-
frames,
|
|
840
|
-
next: heads[index + 1]?.[1][0],
|
|
841
|
-
row: row.id,
|
|
842
|
-
section: section.id,
|
|
843
|
-
step,
|
|
844
|
-
width: placed.width,
|
|
845
|
-
},
|
|
846
|
-
draggable: true,
|
|
847
|
-
dragHandle: ".studio-stack-handle",
|
|
848
|
-
selectable: false,
|
|
849
|
-
// Only its handle takes the pointer.
|
|
850
|
-
passThrough: true,
|
|
851
|
-
// Above the frames, whose names it sits over.
|
|
852
|
-
zIndex: 3,
|
|
853
|
-
};
|
|
854
|
-
});
|
|
855
|
-
});
|
|
856
|
-
});
|
|
857
|
-
|
|
858
816
|
/**
|
|
859
817
|
* Whether a request waits in the section or row of an item dragged, by the
|
|
860
818
|
* item's id: it goes with them, as their frames do. One waiting in a new row
|
|
@@ -1136,6 +1094,15 @@ const requestDropper = (
|
|
|
1136
1094
|
};
|
|
1137
1095
|
};
|
|
1138
1096
|
|
|
1097
|
+
/**
|
|
1098
|
+
* Where a frame dropped is: the middle of its box, or for a long one, as far
|
|
1099
|
+
* down as a tall page's first screen.
|
|
1100
|
+
*/
|
|
1101
|
+
const middleOf = (box: Box) => ({
|
|
1102
|
+
x: box.x + box.width / 2,
|
|
1103
|
+
y: box.y + Math.min(box.height / 2, 400),
|
|
1104
|
+
});
|
|
1105
|
+
|
|
1139
1106
|
export function canvasScene(input: SceneInput): CanvasScene {
|
|
1140
1107
|
const {
|
|
1141
1108
|
canvas,
|
|
@@ -1157,6 +1124,45 @@ export function canvasScene(input: SceneInput): CanvasScene {
|
|
|
1157
1124
|
const layout = shown === canvas ? whole : shownLayout(whole, shown);
|
|
1158
1125
|
const roles = stackRoles(shown, layout, openStack, pageHeights);
|
|
1159
1126
|
|
|
1127
|
+
// The tops of the stacks drawn closed: each stands for its cell.
|
|
1128
|
+
const tops = new Set(
|
|
1129
|
+
[...roles].flatMap(([key, { role }]) => (isClosedTop(role) ? [key] : []))
|
|
1130
|
+
);
|
|
1131
|
+
|
|
1132
|
+
/** A closed stack's cell, by its top's key, its first frame first. */
|
|
1133
|
+
const cellOf = (top: string) => cellKeys(canvas, parseFrameKey(top));
|
|
1134
|
+
|
|
1135
|
+
const carried = (keys: Iterable<string>): string[][] => {
|
|
1136
|
+
const list = [...keys];
|
|
1137
|
+
|
|
1138
|
+
const byTop = new Map(
|
|
1139
|
+
list.flatMap((key) =>
|
|
1140
|
+
tops.has(key) ? [[key, cellOf(key)] as const] : []
|
|
1141
|
+
)
|
|
1142
|
+
);
|
|
1143
|
+
|
|
1144
|
+
// The words a closed stack lifted go in its cell, not on their own.
|
|
1145
|
+
const inCells = new Set([...byTop.values()].flat());
|
|
1146
|
+
|
|
1147
|
+
return list.flatMap((key) => {
|
|
1148
|
+
const cell = byTop.get(key);
|
|
1149
|
+
|
|
1150
|
+
if (cell) {
|
|
1151
|
+
return [cell];
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
return inCells.has(key) ? [] : [[key]];
|
|
1155
|
+
});
|
|
1156
|
+
};
|
|
1157
|
+
|
|
1158
|
+
/** The frames moving in a drag, by key: never a place to drop them. */
|
|
1159
|
+
const movingSet = (moving: ReadonlySet<string>) =>
|
|
1160
|
+
new Set(carried(moving).flat());
|
|
1161
|
+
|
|
1162
|
+
/** Where a frame dragged moves from: a closed stack's cell, its first. */
|
|
1163
|
+
const movedFrom = (key: string) =>
|
|
1164
|
+
parseFrameKey(tops.has(key) ? (cellOf(key)[0] ?? key) : key);
|
|
1165
|
+
|
|
1160
1166
|
const items = keepItems(
|
|
1161
1167
|
sceneItems(shown, layout, threads, editable, me, roles),
|
|
1162
1168
|
previous
|
|
@@ -1170,6 +1176,22 @@ export function canvasScene(input: SceneInput): CanvasScene {
|
|
|
1170
1176
|
return {
|
|
1171
1177
|
items,
|
|
1172
1178
|
layout,
|
|
1179
|
+
dropsFree: (lead, pointer) => {
|
|
1180
|
+
if (tops.has(lead.id)) {
|
|
1181
|
+
return false;
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
if (!isOwnFrame(lead.id)) {
|
|
1185
|
+
return !nearFlow(layout, lead);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
// A section header on its own is drawn across the canvas's content,
|
|
1189
|
+
// not where it was put: where it is held says where it goes.
|
|
1190
|
+
const placed = layout.frames.get(lead.id);
|
|
1191
|
+
const header = placed !== undefined && isHeaderFrame(placed.frame);
|
|
1192
|
+
|
|
1193
|
+
return !flowAt(layout, header ? pointer : middleOf(lead));
|
|
1194
|
+
},
|
|
1173
1195
|
frame: (key) => layout.frames.get(key),
|
|
1174
1196
|
flowAt: (point) => flowAt(layout, point),
|
|
1175
1197
|
nearFlow: (box) => nearFlow(layout, box),
|
|
@@ -1194,32 +1216,29 @@ export function canvasScene(input: SceneInput): CanvasScene {
|
|
|
1194
1216
|
});
|
|
1195
1217
|
},
|
|
1196
1218
|
cellAt: (point, options) => {
|
|
1197
|
-
const
|
|
1219
|
+
const moving = options?.moving && movingSet(options.moving);
|
|
1220
|
+
const cell = cellAt(layout, point, { ...options, moving });
|
|
1198
1221
|
|
|
1199
1222
|
return cell ? freeCell(layout, cell) : undefined;
|
|
1200
1223
|
},
|
|
1201
1224
|
cellBox: (cell, size) => cellBox(layout, cell, size),
|
|
1225
|
+
carried,
|
|
1226
|
+
carriesStack: (key) => tops.has(key),
|
|
1202
1227
|
dragWith: (id) => {
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
)
|
|
1228
|
+
// A closed stack lifts the words in its cell with it: they go where it
|
|
1229
|
+
// goes.
|
|
1230
|
+
if (tops.has(id)) {
|
|
1231
|
+
const drawn = new Set(items.map((item) => item.id));
|
|
1232
|
+
|
|
1233
|
+
return cellOf(id).filter((key) => key !== id && drawn.has(key));
|
|
1234
|
+
}
|
|
1206
1235
|
|
|
1207
1236
|
const frames = items.flatMap((item) => {
|
|
1208
1237
|
if (item.type !== "frame") {
|
|
1209
1238
|
return [];
|
|
1210
1239
|
}
|
|
1211
1240
|
|
|
1212
|
-
const {
|
|
1213
|
-
|
|
1214
|
-
if (stack) {
|
|
1215
|
-
const { data } = stack;
|
|
1216
|
-
|
|
1217
|
-
return data.section === section &&
|
|
1218
|
-
data.row === row &&
|
|
1219
|
-
data.frames.includes(frame)
|
|
1220
|
-
? [item.id]
|
|
1221
|
-
: [];
|
|
1222
|
-
}
|
|
1241
|
+
const { row, section } = item.data.address;
|
|
1223
1242
|
|
|
1224
1243
|
return sectionNodeId(section) === id || rowNodeId(section, row) === id
|
|
1225
1244
|
? [item.id]
|
|
@@ -1231,34 +1250,9 @@ export function canvasScene(input: SceneInput): CanvasScene {
|
|
|
1231
1250
|
|
|
1232
1251
|
return [...surface, ...frames, ...requestsIn(items, id)];
|
|
1233
1252
|
},
|
|
1234
|
-
staysPut: (key, cell) => staysPut(canvas,
|
|
1235
|
-
stackAt: (point, reach = 0) =>
|
|
1236
|
-
items.find((item) => {
|
|
1237
|
-
if (item.type !== "stack") {
|
|
1238
|
-
return false;
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
const { data } = item;
|
|
1242
|
-
|
|
1243
|
-
const boxes = data.frames.flatMap(
|
|
1244
|
-
(frame) =>
|
|
1245
|
-
layout.frames.get(
|
|
1246
|
-
frameKey({ section: data.section, row: data.row, frame })
|
|
1247
|
-
) ?? []
|
|
1248
|
-
);
|
|
1249
|
-
|
|
1250
|
-
const top = Math.min(...boxes.map((box) => box.y)) - reach;
|
|
1251
|
-
const bottom = Math.max(...boxes.map((box) => box.y + box.height));
|
|
1252
|
-
|
|
1253
|
-
return (
|
|
1254
|
-
point.x >= item.x &&
|
|
1255
|
-
point.x <= item.x + data.width &&
|
|
1256
|
-
point.y >= top &&
|
|
1257
|
-
point.y <= bottom
|
|
1258
|
-
);
|
|
1259
|
-
})?.id,
|
|
1253
|
+
staysPut: (key, cell) => staysPut(canvas, movedFrom(key), cell),
|
|
1260
1254
|
dropMark: (cell, size, moving, text) =>
|
|
1261
|
-
dropMark(layout, cell, size, moving, text),
|
|
1255
|
+
dropMark(layout, cell, size, moving && movingSet(moving), text),
|
|
1262
1256
|
dropRow: (current, section, row, middle) => {
|
|
1263
1257
|
const index = rowDropIndex(layout, section, row, middle);
|
|
1264
1258
|
|
|
@@ -1301,14 +1295,23 @@ export function canvasScene(input: SceneInput): CanvasScene {
|
|
|
1301
1295
|
let dropped = current;
|
|
1302
1296
|
// Frames dropped on a new row share it: the first makes it. Frames
|
|
1303
1297
|
// dropped in a cell (onto a stack) go in it in order, each under the
|
|
1304
|
-
// one before.
|
|
1298
|
+
// one before. A closed stack's top takes its cell with it, stacked:
|
|
1299
|
+
// the words it lifted go with it, not on their own.
|
|
1305
1300
|
const inCell = target.under !== undefined || target.over !== undefined;
|
|
1301
|
+
|
|
1302
|
+
const taken = new Set(
|
|
1303
|
+
frames.flatMap((key) =>
|
|
1304
|
+
tops.has(key) ? cellOf(key).filter((each) => each !== key) : []
|
|
1305
|
+
)
|
|
1306
|
+
);
|
|
1307
|
+
|
|
1306
1308
|
let into = target;
|
|
1307
1309
|
|
|
1308
|
-
for (const key of frames) {
|
|
1310
|
+
for (const key of frames.filter((each) => !taken.has(each))) {
|
|
1309
1311
|
const step = layout.frames.get(key)?.step ?? leadStep;
|
|
1312
|
+
const move = tops.has(key) ? moveStack : moveFrame;
|
|
1310
1313
|
|
|
1311
|
-
const moved =
|
|
1314
|
+
const moved = move(dropped, movedFrom(key), {
|
|
1312
1315
|
...into,
|
|
1313
1316
|
step: inCell
|
|
1314
1317
|
? target.step
|
|
@@ -1316,10 +1319,12 @@ export function canvasScene(input: SceneInput): CanvasScene {
|
|
|
1316
1319
|
});
|
|
1317
1320
|
|
|
1318
1321
|
dropped = moved.canvas;
|
|
1322
|
+
const landed = moved.keys ?? [];
|
|
1323
|
+
const last = landed.at(-1);
|
|
1319
1324
|
|
|
1320
|
-
if (
|
|
1321
|
-
keys.push(
|
|
1322
|
-
const { frame, row } = parseFrameKey(
|
|
1325
|
+
if (last) {
|
|
1326
|
+
keys.push(...landed);
|
|
1327
|
+
const { frame, row } = parseFrameKey(last);
|
|
1323
1328
|
into = inCell
|
|
1324
1329
|
? { section: target.section, row, step: target.step, under: frame }
|
|
1325
1330
|
: { ...target, row };
|
package/app/canvas/canvas-ui.ts
CHANGED
|
@@ -4,13 +4,13 @@ import type { InspectBox } from "../kit/inspect-runtime";
|
|
|
4
4
|
import type { ThreadTarget } from "../types";
|
|
5
5
|
import type {
|
|
6
6
|
CanvasTool,
|
|
7
|
+
ComposeOptions,
|
|
7
8
|
Inspected,
|
|
8
9
|
ScreenPoint,
|
|
9
10
|
ViewRequestCell,
|
|
10
11
|
} from "./canvas-context";
|
|
11
12
|
import type { FloatingComment } from "./comments";
|
|
12
13
|
import type { NamingRequest } from "./flow-naming";
|
|
13
|
-
import type { Size } from "./frame-resize";
|
|
14
14
|
import type { LinkedElement } from "./linked-element";
|
|
15
15
|
import type { OpenStack, StackBox } from "./stack-model";
|
|
16
16
|
import { createStateStore, useStateOf } from "./state-store";
|
|
@@ -40,12 +40,6 @@ export interface CanvasUiState {
|
|
|
40
40
|
* gone on a reload.
|
|
41
41
|
*/
|
|
42
42
|
othersHidden?: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* The area a section is being resized to, as its edge is dragged: its name
|
|
45
|
-
* and edges, drawn over its frames, and its surface, under them, both show
|
|
46
|
-
* it.
|
|
47
|
-
*/
|
|
48
|
-
sectionDraft?: { section: string; size: Size };
|
|
49
43
|
/**
|
|
50
44
|
* The spec thread open beside its spec: shown there, never as a floating
|
|
51
45
|
* card over the canvas.
|
|
@@ -70,14 +64,15 @@ export const createCanvasUi = (initial: Partial<CanvasUiState> = {}) => {
|
|
|
70
64
|
compose: (
|
|
71
65
|
target: ThreadTarget,
|
|
72
66
|
at: ScreenPoint,
|
|
73
|
-
|
|
67
|
+
{ onPosted, quick }: ComposeOptions = {}
|
|
74
68
|
) =>
|
|
75
69
|
set({
|
|
76
70
|
floating: {
|
|
77
71
|
kind: "compose",
|
|
78
72
|
target,
|
|
79
73
|
at,
|
|
80
|
-
...(
|
|
74
|
+
...(quick ? { quick: true } : undefined),
|
|
75
|
+
...(onPosted ? { onPosted } : undefined),
|
|
81
76
|
},
|
|
82
77
|
}),
|
|
83
78
|
/** Open a thread's card at `at`; left out, at its pin. */
|
|
@@ -150,8 +145,6 @@ export const createCanvasUi = (initial: Partial<CanvasUiState> = {}) => {
|
|
|
150
145
|
},
|
|
151
146
|
/** Hide everyone else's work, or show it again. */
|
|
152
147
|
setOthersHidden: (othersHidden: boolean) => set({ othersHidden }),
|
|
153
|
-
setSectionDraft: (sectionDraft?: CanvasUiState["sectionDraft"]) =>
|
|
154
|
-
set({ sectionDraft }),
|
|
155
148
|
/** Leaving Inspect lets go of the component it picked. */
|
|
156
149
|
setTool: (tool: CanvasTool) =>
|
|
157
150
|
set(tool === "inspect" ? { tool } : { tool, inspected: undefined }),
|