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