@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
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
appendOwnFrame,
|
|
3
3
|
type CanvasPoint,
|
|
4
|
-
isHeaderFrame,
|
|
5
4
|
placedAt,
|
|
6
5
|
} from "../../src/shared/canvas-core.ts";
|
|
7
6
|
import { isRecord } from "../../src/shared/checks.ts";
|
|
@@ -235,6 +234,8 @@ export const ownCopies = (
|
|
|
235
234
|
export interface SteppedCopy {
|
|
236
235
|
frame: Frame;
|
|
237
236
|
step: number;
|
|
237
|
+
/** It goes under the copy before it, in its cell: a stack stays one. */
|
|
238
|
+
under?: boolean;
|
|
238
239
|
}
|
|
239
240
|
|
|
240
241
|
/** Copies in a row of a section, each on its step, the frames after making room. */
|
|
@@ -249,14 +250,19 @@ export const copiesFrom = (
|
|
|
249
250
|
// Copies put on a stack all go in it, in order, each under the one before.
|
|
250
251
|
const inCell = cell.over !== undefined || cell.under !== undefined;
|
|
251
252
|
|
|
252
|
-
|
|
253
|
-
|
|
253
|
+
let last: string | undefined;
|
|
254
|
+
|
|
255
|
+
for (const { frame, step, under } of copies) {
|
|
256
|
+
// One copied with the frame it was under goes under that one's copy.
|
|
257
|
+
const at = under && last ? { ...into, under: last } : into;
|
|
258
|
+
const added = addFrameAt(next, { ...at, step }, frame);
|
|
254
259
|
next = added.canvas;
|
|
255
260
|
|
|
256
261
|
if (added.key) {
|
|
257
262
|
keys.push(added.key);
|
|
258
263
|
// The first copy into a new row makes it; the rest share it.
|
|
259
264
|
const { frame: id, row } = parseFrameKey(added.key);
|
|
265
|
+
last = id;
|
|
260
266
|
into = inCell
|
|
261
267
|
? { section: cell.section, row, under: id }
|
|
262
268
|
: { section: cell.section, row };
|
|
@@ -578,23 +584,14 @@ export const pasteClip = (
|
|
|
578
584
|
const step = target && stepOfFrame(canvas, target);
|
|
579
585
|
|
|
580
586
|
if (target && section && !placedAt(section) && step !== undefined) {
|
|
581
|
-
|
|
582
|
-
const headers = clip.frames.filter((each) => isHeaderFrame(each.frame));
|
|
583
|
-
|
|
584
|
-
const inRow = copiesFrom(
|
|
587
|
+
return copiesFrom(
|
|
585
588
|
canvas,
|
|
586
589
|
{ section: target.section, row: target.row },
|
|
587
|
-
clip.frames
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
step: step + 1 + index,
|
|
592
|
-
}))
|
|
590
|
+
clip.frames.map((each, index) => ({
|
|
591
|
+
frame: copyOf(each),
|
|
592
|
+
step: step + 1 + index,
|
|
593
|
+
}))
|
|
593
594
|
);
|
|
594
|
-
|
|
595
|
-
return headers.length > 0
|
|
596
|
-
? joined(inRow, ownInPlace(inRow.canvas, headers, copyOf))
|
|
597
|
-
: inRow;
|
|
598
595
|
}
|
|
599
596
|
|
|
600
597
|
const flows = flowCopies(canvas, clip.flows, restores, present);
|
|
@@ -104,29 +104,37 @@ export const dropFree = (
|
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* Copies of frames ⌥-dragged into a section, the frames staying where they
|
|
107
|
-
* were: from the cell the one held is over, keeping their steps apart.
|
|
107
|
+
* were: from the cell the one held is over, keeping their steps apart. The
|
|
108
|
+
* frames come in groups (the scene's `carried`): a closed stack's cell is
|
|
109
|
+
* one, copied still stacked, each copy under the one before; any other
|
|
110
|
+
* frame is one of its own.
|
|
108
111
|
*/
|
|
109
112
|
export const dropCopiesInFlow = (
|
|
110
113
|
canvas: Canvas,
|
|
111
|
-
|
|
114
|
+
groups: readonly (readonly string[])[],
|
|
112
115
|
lead: string,
|
|
113
116
|
cell: Cell
|
|
114
117
|
): PlacedFrames => {
|
|
115
118
|
const stepOf = (key: string) => stepOfFrame(canvas, parseFrameKey(key)) ?? 1;
|
|
116
119
|
const leadStep = stepOf(lead);
|
|
117
120
|
|
|
118
|
-
const frames =
|
|
119
|
-
|
|
121
|
+
const frames = groups.flatMap((group) =>
|
|
122
|
+
group.flatMap((key, index) => {
|
|
123
|
+
const frame = frameAt(canvas, key);
|
|
120
124
|
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
return frame
|
|
126
|
+
? [{ frame: copyOfFrame(frame), key, under: index > 0 }]
|
|
127
|
+
: [];
|
|
128
|
+
})
|
|
129
|
+
);
|
|
123
130
|
|
|
124
131
|
return copiesFrom(
|
|
125
132
|
canvas,
|
|
126
133
|
cell,
|
|
127
|
-
frames.map(({ frame, key }) => ({
|
|
134
|
+
frames.map(({ frame, key, under }) => ({
|
|
128
135
|
frame,
|
|
129
136
|
step: Math.max(1, cell.step + stepOf(key) - leadStep),
|
|
137
|
+
under,
|
|
130
138
|
}))
|
|
131
139
|
);
|
|
132
140
|
};
|
|
@@ -2,8 +2,15 @@ import {
|
|
|
2
2
|
type Inspector,
|
|
3
3
|
type InspectorOptions,
|
|
4
4
|
inspector,
|
|
5
|
+
isDeepSelect,
|
|
5
6
|
} from "@dexhq/inspector";
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
useEffect,
|
|
9
|
+
useLayoutEffect,
|
|
10
|
+
useMemo,
|
|
11
|
+
useRef,
|
|
12
|
+
useSyncExternalStore,
|
|
13
|
+
} from "react";
|
|
7
14
|
|
|
8
15
|
import type { Point } from "./anchoring";
|
|
9
16
|
import { takeKeyboardFrom } from "./canvas-input";
|
|
@@ -12,75 +19,216 @@ import {
|
|
|
12
19
|
type InspectorKey,
|
|
13
20
|
inspectorKey,
|
|
14
21
|
} from "./canvas-keys";
|
|
22
|
+
import { useCanvasUi } from "./canvas-ui";
|
|
23
|
+
import { pointOnPage } from "./element-picker";
|
|
15
24
|
import type { LivePage } from "./live-page";
|
|
16
25
|
import { isTyping } from "./typing";
|
|
17
26
|
|
|
18
|
-
// The inspector (@dexhq/inspector) on a frame's live page,
|
|
19
|
-
// that chooses one element on it: Comment, Inspect styles
|
|
20
|
-
// props. Each tool's layer
|
|
21
|
-
//
|
|
22
|
-
//
|
|
27
|
+
// The inspector (@dexhq/inspector) on a frame's live page, shared by every
|
|
28
|
+
// canvas tool that chooses one element on it: Comment, Inspect styles,
|
|
29
|
+
// Inspect props and Text (ADR 0009). Each tool's layer is a view on it, so
|
|
30
|
+
// switching keeps the element chosen, what is outlined and the way back
|
|
31
|
+
// down. Each layer turns the pointer into a point on the page, in its CSS
|
|
32
|
+
// pixels (pointOnPage: the canvas's zoom undone), and hands the keys to it
|
|
33
|
+
// with useInspectorKeys.
|
|
34
|
+
|
|
35
|
+
export const FRAME_EDGE = 6;
|
|
36
|
+
|
|
37
|
+
export interface FramePoint extends Point {
|
|
38
|
+
deep?: boolean;
|
|
39
|
+
onFrameEdge?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const isOnLayerEdge = (
|
|
43
|
+
event: Pick<MouseEvent, "clientX" | "clientY"> & { currentTarget: Element }
|
|
44
|
+
) => {
|
|
45
|
+
const { bottom, left, right, top } =
|
|
46
|
+
event.currentTarget.getBoundingClientRect();
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
Math.min(
|
|
50
|
+
event.clientX - left,
|
|
51
|
+
right - event.clientX,
|
|
52
|
+
event.clientY - top,
|
|
53
|
+
bottom - event.clientY
|
|
54
|
+
) < FRAME_EDGE
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const framePoint = (
|
|
59
|
+
event: Pick<MouseEvent, "clientX" | "clientY" | "ctrlKey" | "metaKey"> & {
|
|
60
|
+
currentTarget: Element;
|
|
61
|
+
},
|
|
62
|
+
width: number
|
|
63
|
+
): FramePoint => ({
|
|
64
|
+
...pointOnPage(event, width),
|
|
65
|
+
deep: isDeepSelect(event),
|
|
66
|
+
onFrameEdge: isOnLayerEdge(event),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export const isWholeFrame = (element: Element | undefined) =>
|
|
70
|
+
element !== undefined && element === element.ownerDocument.documentElement;
|
|
23
71
|
|
|
24
72
|
export interface FrameInspectorOptions extends Pick<
|
|
25
|
-
InspectorOptions<
|
|
73
|
+
InspectorOptions<FramePoint>,
|
|
26
74
|
"skip"
|
|
27
75
|
> {
|
|
28
76
|
/** The element at a point: the page's own (LivePage.elementAt) unless given. */
|
|
29
|
-
elementAt?: (point:
|
|
77
|
+
elementAt?: (point: FramePoint) => Element | undefined;
|
|
30
78
|
/** Each time what is chosen changes. */
|
|
31
79
|
onChoose?: (element: Element | undefined) => void;
|
|
32
80
|
}
|
|
33
81
|
|
|
82
|
+
/** The options of a tool's layer, as of its last render. */
|
|
83
|
+
interface ToolOptions {
|
|
84
|
+
readonly current: FrameInspectorOptions;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A page's inspector, the tool on it now, and who redraws. */
|
|
88
|
+
interface PageInspector {
|
|
89
|
+
inspecting: Inspector<FramePoint>;
|
|
90
|
+
/** The tool on the page now: the layer drawn last. */
|
|
91
|
+
setTool: (tool: ToolOptions) => void;
|
|
92
|
+
/** Changes each time what the inspector holds does. */
|
|
93
|
+
version: () => number;
|
|
94
|
+
subscribe: (redraw: () => void) => () => void;
|
|
95
|
+
}
|
|
96
|
+
|
|
34
97
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
98
|
+
* Whether an element is on its page now: a page loaded again leaves the
|
|
99
|
+
* last one's elements connected to a document with no window.
|
|
37
100
|
*/
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
101
|
+
const isOnPage = (element: Element): boolean =>
|
|
102
|
+
element.isConnected && element.ownerDocument.defaultView !== null;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The element chosen, while it is on the page: one the page has since taken
|
|
106
|
+
* away is chosen no longer, and a click chooses anew.
|
|
107
|
+
*/
|
|
108
|
+
export const chosenOnPage = (
|
|
109
|
+
inspecting: Inspector<FramePoint>
|
|
110
|
+
): Element | undefined => {
|
|
111
|
+
const { chosen } = inspecting;
|
|
112
|
+
|
|
113
|
+
return chosen && isOnPage(chosen) ? chosen : undefined;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** An inspector on a page, reading the options of the tool on it now. */
|
|
117
|
+
const pageInspector = (page: LivePage | null): PageInspector => {
|
|
118
|
+
let tool: ToolOptions = { current: {} };
|
|
119
|
+
const redraws = new Set<() => void>();
|
|
120
|
+
let version = 0;
|
|
43
121
|
let chosen: Element | undefined;
|
|
44
122
|
|
|
45
|
-
const
|
|
46
|
-
elementAt: (point) =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
123
|
+
const inspecting = inspector<FramePoint>({
|
|
124
|
+
elementAt: (point) => {
|
|
125
|
+
if (point.onFrameEdge) {
|
|
126
|
+
return page?.root();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return tool.current.elementAt
|
|
130
|
+
? tool.current.elementAt(point)
|
|
131
|
+
: page?.elementAt(point.x, point.y)?.element;
|
|
132
|
+
},
|
|
133
|
+
elementsAt: (point) => page?.elementsAt(point.x, point.y) ?? [],
|
|
134
|
+
deep: (point) => point.deep === true,
|
|
135
|
+
wholePage: true,
|
|
136
|
+
skip: (element) => tool.current.skip?.(element) ?? false,
|
|
51
137
|
onChange: () => {
|
|
52
|
-
if (
|
|
53
|
-
chosen =
|
|
54
|
-
|
|
138
|
+
if (inspecting.chosen !== chosen) {
|
|
139
|
+
({ chosen } = inspecting);
|
|
140
|
+
tool.current.onChoose?.(chosen);
|
|
55
141
|
}
|
|
56
142
|
|
|
57
|
-
|
|
143
|
+
version += 1;
|
|
144
|
+
|
|
145
|
+
for (const redraw of redraws) {
|
|
146
|
+
redraw();
|
|
147
|
+
}
|
|
58
148
|
},
|
|
59
149
|
});
|
|
60
150
|
|
|
151
|
+
return {
|
|
152
|
+
inspecting,
|
|
153
|
+
setTool: (next) => {
|
|
154
|
+
tool = next;
|
|
155
|
+
},
|
|
156
|
+
version: () => version,
|
|
157
|
+
subscribe: (redraw) => {
|
|
158
|
+
redraws.add(redraw);
|
|
159
|
+
|
|
160
|
+
return () => {
|
|
161
|
+
redraws.delete(redraw);
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Each page's one inspector, made the first time a tool asks for it, and
|
|
169
|
+
* gone with the page.
|
|
170
|
+
*/
|
|
171
|
+
const inspectors = new WeakMap<LivePage, PageInspector>();
|
|
172
|
+
|
|
173
|
+
const inspectorOn = (page: LivePage | null) => {
|
|
174
|
+
// With no page (a slide's own words), nothing is chosen to share.
|
|
175
|
+
if (!page) {
|
|
176
|
+
return pageInspector(page);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const made = inspectors.get(page) ?? pageInspector(page);
|
|
180
|
+
inspectors.set(page, made);
|
|
181
|
+
|
|
61
182
|
return made;
|
|
62
183
|
};
|
|
63
184
|
|
|
64
185
|
/**
|
|
65
|
-
* The inspector on a frame's page,
|
|
66
|
-
*
|
|
186
|
+
* The inspector on a frame's page, shared by every canvas tool on it, the
|
|
187
|
+
* layer drawn again as it changes. It reads the options of the layer drawn
|
|
188
|
+
* last: the tool on the page now. A page loaded again lets go of what the
|
|
189
|
+
* last one held.
|
|
67
190
|
*/
|
|
68
191
|
export const useFrameInspector = (
|
|
69
192
|
page: LivePage | null,
|
|
70
193
|
options: FrameInspectorOptions = {}
|
|
71
|
-
): Inspector<
|
|
72
|
-
const [, redraw] = useReducer((count: number) => count + 1, 0);
|
|
194
|
+
): Inspector<FramePoint> => {
|
|
73
195
|
const latest = useRef(options);
|
|
74
196
|
// oxlint-disable-next-line react/refs -- read as the pointer and keys move the inspector, after render
|
|
75
197
|
latest.current = options;
|
|
198
|
+
const shared = useMemo(() => inspectorOn(page), [page]);
|
|
199
|
+
useLayoutEffect(() => shared.setTool(latest), [shared]);
|
|
200
|
+
useSyncExternalStore(shared.subscribe, shared.version, shared.version);
|
|
201
|
+
|
|
202
|
+
useEffect(
|
|
203
|
+
() =>
|
|
204
|
+
page?.onPainted(() => {
|
|
205
|
+
const { chosen, current } = shared.inspecting;
|
|
76
206
|
|
|
77
|
-
|
|
78
|
-
|
|
207
|
+
if (chosen && !isOnPage(chosen)) {
|
|
208
|
+
shared.inspecting.release();
|
|
209
|
+
} else if (current && !isOnPage(current)) {
|
|
210
|
+
shared.inspecting.hover();
|
|
211
|
+
}
|
|
212
|
+
}),
|
|
213
|
+
[page, shared]
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
return shared.inspecting;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
/** The keyboard back out of a frame's page, if one has it. */
|
|
220
|
+
const takeKeyboard = () => {
|
|
221
|
+
const focused = document.activeElement;
|
|
222
|
+
|
|
223
|
+
if (focused instanceof HTMLIFrameElement) {
|
|
224
|
+
takeKeyboardFrom(focused);
|
|
225
|
+
}
|
|
79
226
|
};
|
|
80
227
|
|
|
81
228
|
/** The steps, as the keys take them. */
|
|
82
|
-
const steps = (inspecting: Inspector<
|
|
229
|
+
const steps = (inspecting: Inspector<FramePoint>) => ({
|
|
83
230
|
up: () => inspecting.step("up"),
|
|
231
|
+
top: () => inspecting.step("top"),
|
|
84
232
|
down: () => inspecting.step("down"),
|
|
85
233
|
previous: () => inspecting.step("previous"),
|
|
86
234
|
next: () => inspecting.step("next"),
|
|
@@ -93,22 +241,25 @@ const steps = (inspecting: Inspector<Point>) => ({
|
|
|
93
241
|
* Enter does what the tool has for it (`actions`), even on a focused
|
|
94
242
|
* button: the pointer is over the frame, and a button keeps the keyboard
|
|
95
243
|
* after a click, as the tool's own button does. While it has one chosen,
|
|
96
|
-
* Escape lets go of it, and only then
|
|
97
|
-
*
|
|
98
|
-
*
|
|
244
|
+
* Escape lets go of it, and only then: a comment's card open over the
|
|
245
|
+
* canvas takes Escape first, as Escape steps back one thing a press. The
|
|
246
|
+
* tool's layer covers the frame's page, which passes only its zoom keys,
|
|
247
|
+
* Escape, C and V on to the canvas, so the keyboard comes back out of a
|
|
248
|
+
* page as the tool starts and as something is outlined: C, I and T then
|
|
249
|
+
* switch tools from any of them.
|
|
99
250
|
*/
|
|
100
251
|
export const useInspectorKeys = (
|
|
101
|
-
inspecting: Inspector<
|
|
252
|
+
inspecting: Inspector<FramePoint>,
|
|
102
253
|
actions: Partial<Record<InspectorAction, () => void>> = {}
|
|
103
254
|
) => {
|
|
104
255
|
const outlined = inspecting.current !== undefined;
|
|
105
256
|
const chosen = inspecting.chosen !== undefined;
|
|
257
|
+
const cardOpen = useCanvasUi((state) => state.floating !== undefined);
|
|
106
258
|
|
|
259
|
+
useEffect(takeKeyboard, []);
|
|
107
260
|
useEffect(() => {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (outlined && focused instanceof HTMLIFrameElement) {
|
|
111
|
-
takeKeyboardFrom(focused);
|
|
261
|
+
if (outlined) {
|
|
262
|
+
takeKeyboard();
|
|
112
263
|
}
|
|
113
264
|
}, [outlined]);
|
|
114
265
|
|
|
@@ -129,7 +280,7 @@ export const useInspectorKeys = (
|
|
|
129
280
|
}
|
|
130
281
|
|
|
131
282
|
if (event.key === "Escape") {
|
|
132
|
-
if (inspecting.chosen) {
|
|
283
|
+
if (inspecting.chosen && !cardOpen) {
|
|
133
284
|
event.stopPropagation();
|
|
134
285
|
inspecting.release();
|
|
135
286
|
}
|