@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
package/app/canvas/layout.ts
CHANGED
|
@@ -38,7 +38,10 @@ import { VIEWPORTS } from "./viewports.ts";
|
|
|
38
38
|
// it can hide. A section someone drew or dragged (`position`) sits there;
|
|
39
39
|
// the others stack top to bottom. A frame of its own (a section with `at`)
|
|
40
40
|
// sits where it was drawn, with no section around it. A section header (a
|
|
41
|
-
// note marked `header`)
|
|
41
|
+
// note marked `header`) goes where a note goes: in a cell, it reaches from
|
|
42
|
+
// its column across the columns after it, to the section's frames' right
|
|
43
|
+
// edge until resized, and what they hold keeps clear of it (stackColumns);
|
|
44
|
+
// standing on its own, it is a band across all of that: see placeAround and
|
|
42
45
|
// resolveLayout.
|
|
43
46
|
|
|
44
47
|
export const DOC_SIZE = { width: 640, height: 900 } as const;
|
|
@@ -62,23 +65,22 @@ export const SECTION_NAME_REMS = 1.625;
|
|
|
62
65
|
|
|
63
66
|
/**
|
|
64
67
|
* How far past a frame or a section its resize handles reach on screen, at
|
|
65
|
-
* any zoom: the corner's, the furthest (canvas.css
|
|
66
|
-
* .studio-resize[data-edge="corner"]).
|
|
68
|
+
* any zoom: the corner's, the furthest (canvas.css).
|
|
67
69
|
*/
|
|
68
70
|
export const RESIZE_REACH = 6;
|
|
69
71
|
|
|
70
72
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* the gap is shorter than the name
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* (canvas-scene), it
|
|
78
|
-
*
|
|
73
|
+
* Whether sections' names fit above them at a zoom, with a root font this
|
|
74
|
+
* many pixels tall. A name sits right on its section's top at every zoom,
|
|
75
|
+
* as tall on screen, while the gap above it, SECTION_GAP, is canvas pixels:
|
|
76
|
+
* far out, the gap is shorter than the name and the resize handles reaching
|
|
77
|
+
* down from the section above, and the name goes over them, on a pill of
|
|
78
|
+
* its own so it reads over what is there (canvas.css). Drawn over that
|
|
79
|
+
* section (canvas-scene), it keeps its presses. A section placed by hand
|
|
80
|
+
* closer than the gap has its name over the one above sooner.
|
|
79
81
|
*/
|
|
80
|
-
export const
|
|
81
|
-
|
|
82
|
+
export const sectionNamesFit = (zoom: number, remPx: number) =>
|
|
83
|
+
SECTION_NAME_REMS * remPx + RESIZE_REACH <= SECTION_GAP * zoom;
|
|
82
84
|
|
|
83
85
|
/**
|
|
84
86
|
* The area a section of this size shows: a column's gap narrower, as a
|
|
@@ -170,6 +172,7 @@ export interface PlacedRow extends Box {
|
|
|
170
172
|
export interface PlacedSection extends Box {
|
|
171
173
|
/** Each column's left edge and width, step 1 first. */
|
|
172
174
|
columns: { width: number; x: number }[];
|
|
175
|
+
least: { height: number; width: number };
|
|
173
176
|
/** Where a new row would start, below the others. */
|
|
174
177
|
newRow: Box;
|
|
175
178
|
/**
|
|
@@ -211,7 +214,7 @@ export const frameSize = (frame: Frame, pageHeight?: number) => {
|
|
|
211
214
|
}
|
|
212
215
|
|
|
213
216
|
if (isHeaderFrame(it.frame)) {
|
|
214
|
-
return headerSize(pageHeight);
|
|
217
|
+
return headerSize(it.frame.size, pageHeight);
|
|
215
218
|
}
|
|
216
219
|
|
|
217
220
|
return isNotePath(it.frame.spec)
|
|
@@ -245,13 +248,27 @@ const slideSize = (size: { height?: number; width: number } | undefined) => ({
|
|
|
245
248
|
|
|
246
249
|
/**
|
|
247
250
|
* A section header: as tall as its words and their padding, once measured;
|
|
248
|
-
* as wide as
|
|
251
|
+
* as wide as it was resized to, else as what it fills, which the layout
|
|
252
|
+
* gives it: its section (layOutSection), or standing on its own, the
|
|
253
|
+
* canvas's content (spanContent).
|
|
249
254
|
*/
|
|
250
|
-
const headerSize = (
|
|
251
|
-
width:
|
|
255
|
+
const headerSize = (
|
|
256
|
+
size: { width: number } | undefined,
|
|
257
|
+
wordsHeight?: number
|
|
258
|
+
) => ({
|
|
259
|
+
width: size?.width ?? HEADER_MIN_WIDTH,
|
|
252
260
|
height: Math.max(HEADER_MIN_HEIGHT, Math.ceil(wordsHeight ?? 0)),
|
|
253
261
|
});
|
|
254
262
|
|
|
263
|
+
/** The width a section header was resized to, if it was: else it fills. */
|
|
264
|
+
const ownHeaderWidth = (frame: Frame): number | undefined => {
|
|
265
|
+
const it = kinded(frame);
|
|
266
|
+
|
|
267
|
+
return it.kind === "spec" && isHeaderFrame(it.frame)
|
|
268
|
+
? it.frame.size?.width
|
|
269
|
+
: undefined;
|
|
270
|
+
};
|
|
271
|
+
|
|
255
272
|
/** The least a note is tall: a line of words, before they are measured. */
|
|
256
273
|
export const NOTE_MIN_HEIGHT = 40;
|
|
257
274
|
|
|
@@ -317,6 +334,14 @@ interface RowCell {
|
|
|
317
334
|
/** Under a stack's top: it takes no room, and is not drawn. */
|
|
318
335
|
folded?: boolean;
|
|
319
336
|
height: number;
|
|
337
|
+
/**
|
|
338
|
+
* A section header: across, it takes none of its column's room, as it
|
|
339
|
+
* reaches over the columns after its own, as far as the width it was
|
|
340
|
+
* resized to (`width`), else to the right edge of the section's frames
|
|
341
|
+
* (layOutSection). What those columns hold keeps clear of it
|
|
342
|
+
* (stackColumns).
|
|
343
|
+
*/
|
|
344
|
+
header?: { width?: number };
|
|
320
345
|
/** Its frame's id; none for a pending view. */
|
|
321
346
|
id?: string;
|
|
322
347
|
key: string;
|
|
@@ -331,13 +356,36 @@ interface RowCell {
|
|
|
331
356
|
width: number;
|
|
332
357
|
}
|
|
333
358
|
|
|
359
|
+
/** A cell before stackColumns has put it down its column. */
|
|
360
|
+
type UnstackedCell = Omit<RowCell, "top">;
|
|
361
|
+
|
|
334
362
|
/** How far a cell moves the next one in its column down: none when folded. */
|
|
335
|
-
const roomOf = (cell:
|
|
363
|
+
const roomOf = (cell: UnstackedCell) =>
|
|
336
364
|
cell.folded ? 0 : cell.height + STACK_GAP;
|
|
337
365
|
|
|
338
|
-
/**
|
|
339
|
-
|
|
340
|
-
|
|
366
|
+
/**
|
|
367
|
+
* The cells of a column that sit over its row's top line: the notes before
|
|
368
|
+
* its first frame. In a column of words alone, a section header that
|
|
369
|
+
* reaches over columns after it (`reaches`) and the words before it, as it
|
|
370
|
+
* heads the row there as it would over a frame; other words alone start at
|
|
371
|
+
* the line, as a header that reaches nothing does.
|
|
372
|
+
*/
|
|
373
|
+
const overLine = (
|
|
374
|
+
column: readonly UnstackedCell[],
|
|
375
|
+
reaches: (cell: UnstackedCell) => readonly number[]
|
|
376
|
+
) => {
|
|
377
|
+
const first = column.findIndex((cell) => !cell.note);
|
|
378
|
+
|
|
379
|
+
if (first !== -1) {
|
|
380
|
+
return column.slice(0, first);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const heading = column.findLastIndex(
|
|
384
|
+
(cell) => cell.header !== undefined && reaches(cell).length > 0
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
return column.slice(0, heading + 1);
|
|
388
|
+
};
|
|
341
389
|
|
|
342
390
|
/**
|
|
343
391
|
* Put each column's cells top to bottom, in order: each one's `top`. A
|
|
@@ -345,36 +393,81 @@ const stackHeight = (cells: readonly Omit<RowCell, "top">[]) =>
|
|
|
345
393
|
* first frame sit over that line, and the line comes down to make room for
|
|
346
394
|
* the most any column has: so a note above a frame moves the whole row
|
|
347
395
|
* down, and one below moves only its column.
|
|
396
|
+
*
|
|
397
|
+
* A section header reaches over the columns after its own (`reaches`, their
|
|
398
|
+
* steps), so it keeps clear of them: over the line, it goes above all they
|
|
399
|
+
* have over it; under the line, below all they have under it.
|
|
348
400
|
*/
|
|
349
|
-
const stackColumns = (
|
|
350
|
-
|
|
401
|
+
const stackColumns = (
|
|
402
|
+
cells: UnstackedCell[],
|
|
403
|
+
reaches: (cell: UnstackedCell) => readonly number[]
|
|
404
|
+
): RowCell[] => {
|
|
405
|
+
const columns = new Map<number, UnstackedCell[]>();
|
|
351
406
|
|
|
352
407
|
for (const cell of [...cells].toSorted((a, b) => a.step - b.step)) {
|
|
353
408
|
columns.set(cell.step, [...(columns.get(cell.step) ?? []), cell]);
|
|
354
409
|
}
|
|
355
410
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
411
|
+
// Right to left, as a header is placed by the columns after its own.
|
|
412
|
+
const steps = [...columns.keys()].toSorted((a, b) => b - a);
|
|
413
|
+
// How far over the line each cell over it starts, and how much room each
|
|
414
|
+
// column takes over the line.
|
|
415
|
+
const overBy = new Map<UnstackedCell, number>();
|
|
416
|
+
const above = new Map<number, number>();
|
|
417
|
+
|
|
418
|
+
// How far from the line a header must be to clear the columns it reaches,
|
|
419
|
+
// by how far each takes (`taken`): never less than `least`.
|
|
420
|
+
const clearing = (
|
|
421
|
+
header: UnstackedCell,
|
|
422
|
+
taken: ReadonlyMap<number, number>,
|
|
423
|
+
least: number
|
|
424
|
+
) =>
|
|
425
|
+
Math.max(least, ...reaches(header).map((step) => taken.get(step) ?? least));
|
|
426
|
+
|
|
427
|
+
for (const step of steps) {
|
|
428
|
+
let room = 0;
|
|
429
|
+
|
|
430
|
+
for (const cell of overLine(
|
|
431
|
+
columns.get(step) ?? [],
|
|
432
|
+
reaches
|
|
433
|
+
).toReversed()) {
|
|
434
|
+
if (cell.header) {
|
|
435
|
+
room = clearing(cell, above, room);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
room += roomOf(cell);
|
|
439
|
+
overBy.set(cell, room);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
above.set(step, room);
|
|
443
|
+
}
|
|
366
444
|
|
|
367
445
|
// The row's top line: low enough for the notes above every column.
|
|
368
|
-
const line = Math.max(0, ...
|
|
369
|
-
const tops = new Map<
|
|
446
|
+
const line = Math.max(0, ...above.values());
|
|
447
|
+
const tops = new Map<UnstackedCell, number>();
|
|
448
|
+
// Where each column's cells under the line end.
|
|
449
|
+
const ends = new Map<number, number>();
|
|
370
450
|
|
|
371
|
-
for (const
|
|
372
|
-
let top = line
|
|
451
|
+
for (const step of steps) {
|
|
452
|
+
let top = line;
|
|
453
|
+
|
|
454
|
+
for (const cell of columns.get(step) ?? []) {
|
|
455
|
+
const over = overBy.get(cell);
|
|
456
|
+
|
|
457
|
+
if (over !== undefined) {
|
|
458
|
+
tops.set(cell, line - over);
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
if (cell.header) {
|
|
463
|
+
top = clearing(cell, ends, top);
|
|
464
|
+
}
|
|
373
465
|
|
|
374
|
-
for (const cell of column) {
|
|
375
466
|
tops.set(cell, top);
|
|
376
467
|
top += roomOf(cell);
|
|
377
468
|
}
|
|
469
|
+
|
|
470
|
+
ends.set(step, top);
|
|
378
471
|
}
|
|
379
472
|
|
|
380
473
|
return cells.map((cell) => ({ ...cell, top: tops.get(cell) ?? 0 }));
|
|
@@ -429,10 +522,10 @@ const sectionStepStart = (section: PlacedSection, step: number): number =>
|
|
|
429
522
|
* section's column, so nothing after it moves.
|
|
430
523
|
*/
|
|
431
524
|
const rowColumnsX = (
|
|
432
|
-
cells: readonly
|
|
525
|
+
cells: readonly UnstackedCell[],
|
|
433
526
|
columnX: (step: number) => number
|
|
434
527
|
) => {
|
|
435
|
-
const byStep = new Map<number,
|
|
528
|
+
const byStep = new Map<number, UnstackedCell[]>();
|
|
436
529
|
|
|
437
530
|
for (const cell of cells.filter((each) => !each.folded)) {
|
|
438
531
|
const column = byStep.get(cell.step);
|
|
@@ -470,7 +563,7 @@ const rowColumnsX = (
|
|
|
470
563
|
* asks, or below the rows.
|
|
471
564
|
*/
|
|
472
565
|
const placeNewRowRequests = (
|
|
473
|
-
rowCells: { cells:
|
|
566
|
+
rowCells: { cells: UnstackedCell[]; row?: Row }[],
|
|
474
567
|
rows: readonly Row[],
|
|
475
568
|
pending: readonly PendingCell[]
|
|
476
569
|
) => {
|
|
@@ -488,7 +581,6 @@ const placeNewRowRequests = (
|
|
|
488
581
|
key: request.id,
|
|
489
582
|
kind: "pending",
|
|
490
583
|
step: request.step,
|
|
491
|
-
top: 0,
|
|
492
584
|
},
|
|
493
585
|
],
|
|
494
586
|
});
|
|
@@ -508,7 +600,7 @@ const rowHeight = (cells: readonly RowCell[]): number =>
|
|
|
508
600
|
* gap reads as a gap.
|
|
509
601
|
*/
|
|
510
602
|
const sectionColumns = (
|
|
511
|
-
rows: readonly (readonly
|
|
603
|
+
rows: readonly (readonly UnstackedCell[])[],
|
|
512
604
|
start: number
|
|
513
605
|
): { width: number; x: number }[] => {
|
|
514
606
|
const cells = rows.flat();
|
|
@@ -542,19 +634,26 @@ function layOutSection(
|
|
|
542
634
|
folded: ReadonlyMap<string, string>
|
|
543
635
|
): PlacedSection {
|
|
544
636
|
// Each row's cells: its frames on their steps, then any pending views.
|
|
545
|
-
const rowCells: { cells:
|
|
637
|
+
const rowCells: { cells: UnstackedCell[]; row?: Row }[] = section.rows.map(
|
|
546
638
|
(row) => {
|
|
547
639
|
const steps = stepsOf(row.frames);
|
|
548
640
|
|
|
549
|
-
const cells:
|
|
641
|
+
const cells: UnstackedCell[] = row.frames.map((frame, index) => {
|
|
550
642
|
const key = frameKey({
|
|
551
643
|
section: section.id,
|
|
552
644
|
row: row.id,
|
|
553
645
|
frame: frame.id,
|
|
554
646
|
});
|
|
555
647
|
|
|
648
|
+
const size = frameSize(frame, pageHeights.get(key));
|
|
649
|
+
const header = isHeaderFrame(frame);
|
|
650
|
+
|
|
556
651
|
return {
|
|
557
|
-
...
|
|
652
|
+
...size,
|
|
653
|
+
// A header takes none of its column's room: it reaches over it.
|
|
654
|
+
...(header
|
|
655
|
+
? { header: { width: ownHeaderWidth(frame) }, width: 0 }
|
|
656
|
+
: undefined),
|
|
558
657
|
folded: folded.has(key),
|
|
559
658
|
id: frame.id,
|
|
560
659
|
key,
|
|
@@ -584,7 +683,7 @@ function layOutSection(
|
|
|
584
683
|
});
|
|
585
684
|
}
|
|
586
685
|
|
|
587
|
-
return { row, cells
|
|
686
|
+
return { row, cells };
|
|
588
687
|
}
|
|
589
688
|
);
|
|
590
689
|
|
|
@@ -597,21 +696,76 @@ function layOutSection(
|
|
|
597
696
|
|
|
598
697
|
const columnX = (step: number) => stepStart(columns, origin.x, step);
|
|
599
698
|
|
|
699
|
+
// Across first, as nothing across depends on how tall anything is: where
|
|
700
|
+
// each row's columns start, and how far right its frames reach.
|
|
701
|
+
const rowsAcross = rowCells.map(({ row, cells }) => {
|
|
702
|
+
const cellX = rowColumnsX(cells, columnX);
|
|
703
|
+
|
|
704
|
+
// A header nobody sized reaches at least across its column.
|
|
705
|
+
const rightOf = (cell: UnstackedCell) =>
|
|
706
|
+
cellX(cell.step) +
|
|
707
|
+
(cell.header
|
|
708
|
+
? (cell.header.width ??
|
|
709
|
+
columns[cell.step - 1]?.width ??
|
|
710
|
+
SLOT_SIZE.width)
|
|
711
|
+
: cell.width);
|
|
712
|
+
|
|
713
|
+
const right = Math.max(
|
|
714
|
+
origin.x,
|
|
715
|
+
...cells.flatMap((cell) =>
|
|
716
|
+
cell.folded ? [] : [rightOf(cell) + COLUMN_GAP]
|
|
717
|
+
)
|
|
718
|
+
);
|
|
719
|
+
|
|
720
|
+
return { cellX, cells, right, row };
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
// The widest row, a column's gap past its last frame.
|
|
724
|
+
const widest = Math.max(
|
|
725
|
+
SLOT_SIZE.width,
|
|
726
|
+
...rowsAcross.map(({ right }) => right - origin.x)
|
|
727
|
+
);
|
|
728
|
+
|
|
729
|
+
// The widest row ends where its next step would start, a column's gap
|
|
730
|
+
// after its last frame; the section ends the same gap after that. A section
|
|
731
|
+
// draws a gap narrower (section-node).
|
|
732
|
+
// A section someone sized, or that frames left, keeps at least that size.
|
|
733
|
+
const leastWidth = SECTION_PADDING + widest + COLUMN_GAP;
|
|
734
|
+
const width = Math.max(leastWidth, section.size?.width ?? 0);
|
|
735
|
+
|
|
736
|
+
// Where a header nobody sized fills to: the right edge of the section's
|
|
737
|
+
// frames, or of the rows of a section sized wider (rowSpan).
|
|
738
|
+
const fillsTo = origin.x - SECTION_PADDING + width - COLUMN_GAP * 2;
|
|
739
|
+
|
|
600
740
|
const rows: PlacedRow[] = [];
|
|
601
741
|
let { y } = origin;
|
|
602
|
-
// The widest row, a column's gap past its last frame.
|
|
603
|
-
let widest: number = SLOT_SIZE.width;
|
|
604
742
|
|
|
605
|
-
for (const {
|
|
606
|
-
const
|
|
743
|
+
for (const { cellX, cells: unstacked, right, row } of rowsAcross) {
|
|
744
|
+
const headerRight = (cell: UnstackedCell) =>
|
|
745
|
+
cell.header?.width === undefined
|
|
746
|
+
? fillsTo
|
|
747
|
+
: cellX(cell.step) + cell.header.width;
|
|
748
|
+
|
|
749
|
+
// The columns a header reaches over, after its own.
|
|
750
|
+
const steps = [...new Set(unstacked.map((cell) => cell.step))];
|
|
751
|
+
|
|
752
|
+
const reaches = (cell: UnstackedCell) =>
|
|
753
|
+
cell.header
|
|
754
|
+
? steps.filter(
|
|
755
|
+
(step) => step > cell.step && cellX(step) < headerRight(cell)
|
|
756
|
+
)
|
|
757
|
+
: [];
|
|
758
|
+
|
|
759
|
+
const cells = stackColumns(unstacked, reaches);
|
|
607
760
|
const height = rowHeight(cells);
|
|
608
|
-
const cellX = rowColumnsX(cells, columnX);
|
|
609
761
|
|
|
610
762
|
for (const cell of cells) {
|
|
763
|
+
const x = cellX(cell.step);
|
|
764
|
+
|
|
611
765
|
const box = {
|
|
612
|
-
x
|
|
766
|
+
x,
|
|
613
767
|
y: y + cell.top,
|
|
614
|
-
width: cell.width,
|
|
768
|
+
width: cell.header ? headerRight(cell) - x : cell.width,
|
|
615
769
|
height: cell.height,
|
|
616
770
|
};
|
|
617
771
|
|
|
@@ -638,13 +792,6 @@ function layOutSection(
|
|
|
638
792
|
}
|
|
639
793
|
}
|
|
640
794
|
|
|
641
|
-
const right = Math.max(
|
|
642
|
-
origin.x,
|
|
643
|
-
...shown.map((cell) => cellX(cell.step) + cell.width + COLUMN_GAP)
|
|
644
|
-
);
|
|
645
|
-
|
|
646
|
-
widest = Math.max(widest, right - origin.x);
|
|
647
|
-
|
|
648
795
|
if (row) {
|
|
649
796
|
rows.push({
|
|
650
797
|
columns: columns.map((column, index) => {
|
|
@@ -679,22 +826,18 @@ function layOutSection(
|
|
|
679
826
|
// A section ends at its last row; an empty one keeps room for its first step.
|
|
680
827
|
const bottom = y > origin.y ? y - ROW_GAP : newRow.y + newRow.height;
|
|
681
828
|
|
|
829
|
+
const least = {
|
|
830
|
+
width: leastWidth,
|
|
831
|
+
height: bottom - origin.y + SECTION_PADDING * 2,
|
|
832
|
+
};
|
|
833
|
+
|
|
682
834
|
return {
|
|
683
835
|
x: origin.x - SECTION_PADDING,
|
|
684
836
|
y: origin.y - SECTION_PADDING,
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
// draws a gap narrower (section-node).
|
|
688
|
-
// A section someone sized, or that frames left, keeps at least that size.
|
|
689
|
-
width: Math.max(
|
|
690
|
-
SECTION_PADDING + widest + COLUMN_GAP,
|
|
691
|
-
section.size?.width ?? 0
|
|
692
|
-
),
|
|
693
|
-
height: Math.max(
|
|
694
|
-
bottom - origin.y + SECTION_PADDING * 2,
|
|
695
|
-
section.size?.height ?? 0
|
|
696
|
-
),
|
|
837
|
+
width,
|
|
838
|
+
height: Math.max(least.height, section.size?.height ?? 0),
|
|
697
839
|
columns,
|
|
840
|
+
least,
|
|
698
841
|
newRow,
|
|
699
842
|
rows,
|
|
700
843
|
};
|
|
@@ -705,7 +848,7 @@ function layOutSection(
|
|
|
705
848
|
* among them, or a section drawn or dragged there.
|
|
706
849
|
*/
|
|
707
850
|
interface PutSomewhere {
|
|
708
|
-
/** A section header: a band across everything else. */
|
|
851
|
+
/** A section header on its own: a band across everything else. */
|
|
709
852
|
header: boolean;
|
|
710
853
|
/** Lays it out with its top at `y`: where it was put, or lower. */
|
|
711
854
|
place: (y: number) => PlacedSection;
|
|
@@ -935,10 +1078,11 @@ export function resolveLayout(
|
|
|
935
1078
|
}
|
|
936
1079
|
|
|
937
1080
|
/**
|
|
938
|
-
* Each section header across the canvas's content: from
|
|
939
|
-
* everything else on it to the right edge, as drawn (a
|
|
940
|
-
* column's gap narrower than its box), however that grows as
|
|
941
|
-
* sections come and go, and never narrower than HEADER_MIN_WIDTH.
|
|
1081
|
+
* Each section header standing on its own across the canvas's content: from
|
|
1082
|
+
* the left edge of everything else on it to the right edge, as drawn (a
|
|
1083
|
+
* section draws a column's gap narrower than its box), however that grows as
|
|
1084
|
+
* frames and sections come and go, and never narrower than HEADER_MIN_WIDTH.
|
|
1085
|
+
* One resized keeps its width, from the same left edge.
|
|
942
1086
|
*/
|
|
943
1087
|
const spanContent = (
|
|
944
1088
|
layout: Layout,
|
|
@@ -962,17 +1106,23 @@ const spanContent = (
|
|
|
962
1106
|
continue;
|
|
963
1107
|
}
|
|
964
1108
|
|
|
1109
|
+
const frames = [...layout.frames].filter(
|
|
1110
|
+
([, frame]) => frame.section === id
|
|
1111
|
+
);
|
|
1112
|
+
|
|
1113
|
+
const resized = frames
|
|
1114
|
+
.map(([, frame]) => ownHeaderWidth(frame.frame))
|
|
1115
|
+
.find((width) => width !== undefined);
|
|
1116
|
+
|
|
965
1117
|
const across = {
|
|
966
1118
|
x: content?.x ?? box.x,
|
|
967
|
-
width: Math.max(HEADER_MIN_WIDTH, content?.width ?? 0),
|
|
1119
|
+
width: resized ?? Math.max(HEADER_MIN_WIDTH, content?.width ?? 0),
|
|
968
1120
|
};
|
|
969
1121
|
|
|
970
1122
|
boxes.set(id, { ...box, ...across });
|
|
971
1123
|
|
|
972
|
-
for (const [key, frame] of
|
|
973
|
-
|
|
974
|
-
layout.frames.set(key, { ...frame, ...across });
|
|
975
|
-
}
|
|
1124
|
+
for (const [key, frame] of frames) {
|
|
1125
|
+
layout.frames.set(key, { ...frame, ...across });
|
|
976
1126
|
}
|
|
977
1127
|
}
|
|
978
1128
|
};
|
|
@@ -1042,21 +1192,6 @@ export const nearFlow = (layout: Layout, box: Box): boolean =>
|
|
|
1042
1192
|
box.y + box.height > section.y - COLUMN_GAP
|
|
1043
1193
|
);
|
|
1044
1194
|
|
|
1045
|
-
/**
|
|
1046
|
-
* Where a click puts a section header's top: where it is, so the header goes
|
|
1047
|
-
* there and whatever it lands on goes above or below it (placeAround); on
|
|
1048
|
-
* the upper half of a section or a frame, at its top, so the header goes
|
|
1049
|
-
* above it rather than below.
|
|
1050
|
-
*/
|
|
1051
|
-
export const headerTop = (
|
|
1052
|
-
layout: Layout,
|
|
1053
|
-
point: { x: number; y: number }
|
|
1054
|
-
): number => {
|
|
1055
|
-
const on = [...layout.sections.values()].find((box) => inside(box, point));
|
|
1056
|
-
|
|
1057
|
-
return on && point.y < on.y + on.height / 2 ? on.y : point.y;
|
|
1058
|
-
};
|
|
1059
|
-
|
|
1060
1195
|
const ORIGIN = { x: 0, y: 0 } as const;
|
|
1061
1196
|
|
|
1062
1197
|
/**
|
package/app/canvas/live-page.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
type ElementLocator,
|
|
16
16
|
editableTextAt,
|
|
17
17
|
elementAt,
|
|
18
|
+
elementsAt,
|
|
18
19
|
elementsIn,
|
|
19
20
|
locate,
|
|
20
21
|
locatorKey,
|
|
@@ -67,12 +68,14 @@ export interface LivePage {
|
|
|
67
68
|
* where the canvas shows the page, however far it is zoomed.
|
|
68
69
|
*/
|
|
69
70
|
elementAtScreen: (x: number, y: number) => PickedElement | undefined;
|
|
71
|
+
elementsAt: (x: number, y: number) => Element[];
|
|
70
72
|
/** The elements a dragged area holds (see elementsIn). */
|
|
71
73
|
elementsIn: (area: Box) => PickedElement[];
|
|
72
74
|
/** The design-system component at a point, through the inspect runtime. */
|
|
73
75
|
inspectAt: (x: number, y: number) => PickedComponent | undefined;
|
|
74
76
|
/** The page's inspect runtime, to try and save props with. */
|
|
75
77
|
inspector: () => StudioInspect | undefined;
|
|
78
|
+
root: () => Element | undefined;
|
|
76
79
|
/**
|
|
77
80
|
* The view's markup as the page renders it now, without Dex's own
|
|
78
81
|
* attributes (viewMarkup); none until it has rendered.
|
|
@@ -366,6 +369,7 @@ export const iframePage = (
|
|
|
366
369
|
|
|
367
370
|
return elementAt(doc(), (x - rect.left) / scale, (y - rect.top) / scale);
|
|
368
371
|
},
|
|
372
|
+
elementsAt: (x, y) => elementsAt(doc(), x, y),
|
|
369
373
|
elementsIn: (area) => elementsIn(doc(), area),
|
|
370
374
|
markup: () => viewMarkup(doc()),
|
|
371
375
|
texts: () => {
|
|
@@ -380,6 +384,7 @@ export const iframePage = (
|
|
|
380
384
|
return picked && found ? { element: picked.element, found } : undefined;
|
|
381
385
|
},
|
|
382
386
|
inspector: () => view()?.__studioInspect,
|
|
387
|
+
root: () => doc()?.documentElement ?? undefined,
|
|
383
388
|
nextFrame: (paint) => {
|
|
384
389
|
view()?.requestAnimationFrame(paint);
|
|
385
390
|
},
|
package/app/canvas/new-frame.ts
CHANGED
|
@@ -210,15 +210,21 @@ export const newSpecId = () => `spec-${crypto.randomUUID().slice(0, 8)}`;
|
|
|
210
210
|
|
|
211
211
|
/**
|
|
212
212
|
* A note's frame: in a cell of a section of the person's, stacked as a drop
|
|
213
|
-
* there would be, or a frame of its own at a point.
|
|
214
|
-
*
|
|
213
|
+
* there would be, or a frame of its own at a point. A section header is a
|
|
214
|
+
* note marked `header`, placed by the same rules: the layout has it fill
|
|
215
|
+
* what it is in (layout.ts). Gives the canvas with it and its key.
|
|
215
216
|
*/
|
|
216
217
|
export const placeNoteFrame = (
|
|
217
218
|
canvas: Canvas,
|
|
218
219
|
note: string,
|
|
219
|
-
where: { at: CanvasPoint; cell?: Cell }
|
|
220
|
+
where: { at: CanvasPoint; cell?: Cell },
|
|
221
|
+
{ header = false }: { header?: boolean } = {}
|
|
220
222
|
): MadeFrame | undefined => {
|
|
221
|
-
const
|
|
223
|
+
const id = `${header ? "header" : "note"}-${crypto.randomUUID().slice(0, 8)}`;
|
|
224
|
+
|
|
225
|
+
const frame = header
|
|
226
|
+
? { id, spec: note, header: true as const }
|
|
227
|
+
: { id, spec: note };
|
|
222
228
|
|
|
223
229
|
if (!where.cell) {
|
|
224
230
|
const made = ownFrameFor(canvas, frame, where.at);
|
|
@@ -231,27 +237,6 @@ export const placeNoteFrame = (
|
|
|
231
237
|
return placed.key ? { canvas: placed.canvas, frame: placed.key } : undefined;
|
|
232
238
|
};
|
|
233
239
|
|
|
234
|
-
/**
|
|
235
|
-
* A section header's frame: a note marked `header`, standing on its own with
|
|
236
|
-
* its top left corner at a point. The layout draws it across the canvas's
|
|
237
|
-
* content, so only its height down the canvas matters (layout.ts).
|
|
238
|
-
*/
|
|
239
|
-
export const placeHeaderFrame = (
|
|
240
|
-
canvas: Canvas,
|
|
241
|
-
note: string,
|
|
242
|
-
at: CanvasPoint
|
|
243
|
-
): MadeFrame => {
|
|
244
|
-
const frame = {
|
|
245
|
-
id: `header-${crypto.randomUUID().slice(0, 8)}`,
|
|
246
|
-
spec: note,
|
|
247
|
-
header: true as const,
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
const made = ownFrameFor(canvas, frame, at);
|
|
251
|
-
|
|
252
|
-
return { canvas: made.canvas, frame: made.key };
|
|
253
|
-
};
|
|
254
|
-
|
|
255
240
|
/**
|
|
256
241
|
* A spec's frame: in a cell of a section of the person's, where it is that
|
|
257
242
|
* section's spec, or a frame of its own at a point. Gives the canvas with it
|