@dexhq/canvas 0.15.0 → 0.16.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 +34 -0
- package/app/canvas/activity-parts.tsx +50 -6
- package/app/canvas/activity.tsx +2 -3
- package/app/canvas/agent-changes.ts +18 -8
- package/app/canvas/anchoring.ts +13 -3
- package/app/canvas/canvas-context.tsx +6 -2
- package/app/canvas/canvas-input.ts +35 -0
- package/app/canvas/canvas-model.ts +2 -2
- package/app/canvas/canvas-scene.ts +243 -24
- package/app/canvas/canvas-ui.ts +11 -2
- package/app/canvas/canvas.css +86 -3
- package/app/canvas/comments.tsx +66 -29
- package/app/canvas/element-link.ts +135 -0
- package/app/canvas/element-picker.ts +23 -0
- package/app/canvas/export-dialog.tsx +265 -0
- package/app/canvas/flow-canvas.tsx +65 -14
- package/app/canvas/frame-context-menu.tsx +61 -7
- package/app/canvas/frame-node.tsx +10 -11
- package/app/canvas/layout.ts +41 -22
- package/app/canvas/linked-element.tsx +196 -0
- package/app/canvas/live-page.ts +14 -0
- package/app/canvas/mentions.tsx +209 -0
- package/app/canvas/picked-box.tsx +21 -0
- package/app/canvas/removed-views-panel.tsx +4 -4
- package/app/canvas/request-node.tsx +151 -0
- package/app/canvas/review-panel.tsx +8 -3
- package/app/canvas/section-node.tsx +4 -133
- package/app/canvas/spec-margin.tsx +4 -1
- package/app/canvas/teammates-layer.tsx +205 -0
- package/app/canvas/text-layer.tsx +103 -17
- package/app/canvas/tool-cursors.ts +7 -6
- package/app/canvas/tool-icons.tsx +24 -56
- package/app/canvas/typing.ts +12 -0
- package/app/canvas/use-agent-changes.tsx +6 -2
- package/app/canvas/use-canvas-editor.ts +4 -2
- package/app/export/player-model.ts +159 -0
- package/app/export/player.tsx +198 -0
- package/app/export.html +31 -0
- package/app/export.tsx +9 -0
- package/app/frame/announce-refreshes.ts +21 -0
- package/app/frame/start-frame.tsx +50 -0
- package/app/frame/view-loads.ts +161 -0
- package/app/frame/views.ts +13 -49
- package/app/frame.tsx +2 -38
- package/app/i18n/locales/en/messages.po +145 -6
- package/app/i18n/locales/en/messages.ts +1 -1
- package/app/i18n/locales/pseudo/messages.po +144 -5
- package/app/i18n/locales/pseudo/messages.ts +1 -1
- package/app/icons/dex-glyphs.tsx +219 -0
- package/app/icons/glyphs.tsx +76 -80
- package/app/kit/use-flow.ts +2 -1
- package/app/live/canvas-teammates.ts +90 -0
- package/app/live/studio-api.ts +30 -20
- package/app/pages/canvas.tsx +18 -6
- package/app/pages/commands-settings.tsx +1 -1
- package/app/pages/render.tsx +39 -11
- package/app/shell/bell.tsx +15 -5
- package/app/shell/presence.tsx +123 -26
- package/app/shell/thread-list.tsx +25 -8
- package/app/shell/working-on.tsx +35 -3
- package/app/ui/prompt-editor.tsx +39 -11
- package/app/ui/reference.tsx +21 -8
- package/bin/sudio.mjs +1 -1
- package/dist/cli/commands/create.d.mts +5 -5
- package/dist/cli/commands/create.mjs +4 -4
- package/dist/cli/commands/export.d.mts +40 -0
- package/dist/cli/commands/export.mjs +66 -0
- package/dist/cli/commands/init.d.mts +2 -2
- package/dist/cli/commands/upgrade.mjs +1 -1
- package/dist/cli/help.d.mts +1 -1
- package/dist/cli/help.mjs +13 -7
- package/dist/cli/main.d.mts +42 -5
- package/dist/cli/main.mjs +1 -0
- package/dist/config/load.mjs +14 -2
- package/dist/config/project-files.d.mts +5 -0
- package/dist/config/project-files.mjs +10 -1
- package/dist/config/renamed.d.mts +7 -0
- package/dist/config/renamed.mjs +13 -1
- package/dist/content/commands.d.mts +11 -9
- package/dist/content/commands.mjs +22 -16
- package/dist/content/comments-log.mjs +2 -1
- package/dist/content/content.d.mts +11 -3
- package/dist/content/content.mjs +49 -15
- package/dist/content/element-words.d.mts +42 -0
- package/dist/content/element-words.mjs +112 -0
- package/dist/content/hosted-person.d.mts +31 -0
- package/dist/content/hosted-person.mjs +68 -0
- package/dist/content/merge-rules.d.mts +5 -0
- package/dist/content/merge-rules.mjs +17 -1
- package/dist/content/screenshot.mjs +9 -0
- package/dist/content/text-edit.d.mts +24 -14
- package/dist/content/text-edit.mjs +92 -81
- package/dist/content/text-replace.mjs +2 -26
- package/dist/content/thread-module.d.mts +2 -4
- package/dist/content/thread-module.mjs +4 -5
- package/dist/server/agents.d.mts +10 -0
- package/dist/server/agents.mjs +21 -6
- package/dist/server/canvas-presence.d.mts +22 -0
- package/dist/server/canvas-presence.mjs +160 -0
- package/dist/server/command-settings.mjs +1 -1
- package/dist/server/comments/actions.d.mts +0 -8
- package/dist/server/comments/actions.mjs +1 -9
- package/dist/server/comments/routes.mjs +10 -31
- package/dist/server/dev-server.mjs +35 -13
- package/dist/server/export/build.d.mts +15 -0
- package/dist/server/export/build.mjs +220 -0
- package/dist/server/export/page.d.mts +25 -0
- package/dist/server/export/page.mjs +40 -0
- package/dist/server/export/plugin.d.mts +31 -0
- package/dist/server/export/plugin.mjs +69 -0
- package/dist/server/export/run.d.mts +9 -0
- package/dist/server/export/run.mjs +61 -0
- package/dist/server/export/save.d.mts +7 -0
- package/dist/server/export/save.mjs +29 -0
- package/dist/server/hosted.d.mts +8 -0
- package/dist/server/hosted.mjs +78 -0
- package/dist/server/live-mirror.mjs +66 -10
- package/dist/server/live.mjs +28 -1
- package/dist/server/mcp.mjs +2 -0
- package/dist/server/me.d.mts +2 -0
- package/dist/server/me.mjs +8 -2
- package/dist/server/notices.d.mts +1 -1
- package/dist/server/notices.mjs +1 -1
- package/dist/server/own-copies.mjs +1 -1
- package/dist/server/people.d.mts +7 -2
- package/dist/server/people.mjs +6 -2
- package/dist/server/pictures.d.mts +1 -1
- package/dist/server/pictures.mjs +2 -2
- package/dist/server/prebundle.d.mts +32 -0
- package/dist/server/prebundle.mjs +115 -0
- package/dist/server/problems.d.mts +8 -0
- package/dist/server/problems.mjs +13 -0
- package/dist/server/requests.mjs +43 -30
- package/dist/server/source-stamp.d.mts +4 -3
- package/dist/server/source-stamp.mjs +60 -31
- package/dist/server/state.d.mts +19 -10
- package/dist/server/state.mjs +27 -18
- package/dist/server/thread-source.d.mts +8 -0
- package/dist/server/thread-source.mjs +24 -5
- package/dist/server/tools/export.d.mts +5 -0
- package/dist/server/tools/export.mjs +35 -0
- package/dist/server/tools/place-frame.mjs +16 -16
- package/dist/server/tools/thread-list.mjs +1 -1
- package/dist/server/vite.d.mts +9 -4
- package/dist/server/vite.mjs +63 -61
- package/dist/server/welcome.mjs +2 -1
- package/dist/setup/apply.d.mts +4 -0
- package/dist/setup/apply.mjs +5 -4
- package/dist/setup/create.mjs +5 -5
- package/dist/setup/design-system-checks.mjs +1 -6
- package/dist/setup/detect/workspace.d.mts +10 -10
- package/dist/setup/detect/workspace.mjs +10 -12
- package/dist/setup/doctor.d.mts +4 -1
- package/dist/setup/doctor.mjs +7 -5
- package/dist/setup/migrate/dex-folder.d.mts +61 -0
- package/dist/setup/migrate/dex-folder.mjs +544 -0
- package/dist/setup/migrate/files-folder.mjs +1 -1
- package/dist/setup/migrate/guides.mjs +1 -1
- package/dist/setup/migrate/migrations.mjs +4 -0
- package/dist/setup/migrate/setup-files.d.mts +5 -0
- package/dist/setup/migrate/setup-files.mjs +115 -0
- package/dist/setup/migrate/studio-state.d.mts +2 -2
- package/dist/setup/migrate/studio-state.mjs +4 -4
- package/dist/setup/placement.d.mts +1 -1
- package/dist/setup/placement.mjs +5 -4
- package/dist/setup/plan.d.mts +5 -5
- package/dist/setup/plan.mjs +8 -12
- package/dist/setup/project.mjs +1 -1
- package/dist/setup/prompts.d.mts +2 -1
- package/dist/setup/prompts.mjs +4 -3
- package/dist/setup/questions.mjs +3 -2
- package/dist/setup/starters.d.mts +1 -1
- package/dist/setup/starters.mjs +2 -2
- package/dist/setup/write.d.mts +15 -3
- package/dist/setup/write.mjs +23 -3
- package/dist/shared/canvas-core.d.mts +22 -7
- package/dist/shared/canvas-core.mjs +38 -10
- package/dist/shared/comments/routes.d.mts +3 -1
- package/dist/shared/comments/routes.mjs +4 -2
- package/dist/shared/export-core.d.mts +62 -0
- package/dist/shared/export-core.mjs +101 -0
- package/dist/shared/live-core.d.mts +2 -0
- package/dist/shared/live-core.mjs +6 -1
- package/dist/shared/live-presence.d.mts +57 -2
- package/dist/shared/live-presence.mjs +90 -4
- package/dist/shared/page-messages.d.mts +14 -1
- package/dist/shared/page-messages.mjs +30 -3
- package/dist/shared/people-core.d.mts +28 -0
- package/dist/shared/people-core.mjs +27 -1
- package/dist/shared/presence-core.d.mts +2 -0
- package/dist/shared/references-core.d.mts +4 -0
- package/dist/shared/references-core.mjs +12 -4
- package/dist/shared/studio-files.d.mts +9 -0
- package/dist/shared/studio-files.mjs +11 -2
- package/dist/shared/studio-routes.d.mts +13 -1
- package/dist/shared/threads-core.d.mts +27 -4
- package/dist/shared/threads-core.mjs +67 -12
- package/extension/dist/feedback.js +104 -294
- package/extension/dist/manifest.json +1 -1
- package/extension/dist/picker.js +104 -294
- package/package.json +2 -2
- package/src/cli/commands/create.ts +4 -4
- package/src/cli/commands/export.ts +78 -0
- package/src/cli/commands/upgrade.ts +1 -1
- package/src/cli/help.ts +13 -7
- package/src/cli/main.ts +1 -0
- package/src/config/load.ts +26 -2
- package/src/config/project-files.ts +15 -0
- package/src/config/renamed.ts +19 -1
- package/src/content/commands.ts +30 -18
- package/src/content/comments-log.ts +4 -1
- package/src/content/content.ts +64 -16
- package/src/content/element-words.ts +175 -0
- package/src/content/hosted-person.ts +107 -0
- package/src/content/merge-rules.ts +29 -0
- package/src/content/screenshot.ts +14 -0
- package/src/content/text-edit.ts +172 -105
- package/src/content/text-replace.ts +3 -32
- package/src/content/thread-module.ts +2 -4
- package/src/content/trash.ts +1 -1
- package/src/server/agents.ts +48 -17
- package/src/server/canvas-presence.ts +237 -0
- package/src/server/channel.ts +1 -1
- package/src/server/command-settings.ts +1 -1
- package/src/server/comments/actions.ts +0 -19
- package/src/server/comments/routes.ts +9 -54
- package/src/server/dev-server.ts +66 -26
- package/src/server/export/build.ts +310 -0
- package/src/server/export/page.ts +85 -0
- package/src/server/export/plugin.ts +138 -0
- package/src/server/export/run.ts +79 -0
- package/src/server/export/save.ts +38 -0
- package/src/server/hosted.ts +113 -0
- package/src/server/live-mirror.ts +93 -8
- package/src/server/live.ts +46 -1
- package/src/server/machine-update.ts +3 -3
- package/src/server/mcp.ts +2 -0
- package/src/server/me.ts +10 -1
- package/src/server/notices.ts +2 -2
- package/src/server/people.ts +11 -2
- package/src/server/pictures.ts +2 -2
- package/src/server/prebundle.ts +230 -0
- package/src/server/presence.ts +1 -1
- package/src/server/problems.ts +11 -0
- package/src/server/requests.ts +55 -40
- package/src/server/roster.ts +1 -1
- package/src/server/saved.ts +1 -1
- package/src/server/source-stamp.ts +118 -37
- package/src/server/state.ts +53 -31
- package/src/server/thread-source.ts +35 -3
- package/src/server/tools/export.ts +56 -0
- package/src/server/tools/place-frame.ts +23 -15
- package/src/server/tools/thread-list.ts +1 -1
- package/src/server/updates.ts +2 -2
- package/src/server/vite.ts +106 -110
- package/src/server/welcome.ts +3 -1
- package/src/setup/apply.ts +8 -5
- package/src/setup/create.ts +10 -10
- package/src/setup/design-system-checks.ts +1 -6
- package/src/setup/detect/workspace.ts +20 -21
- package/src/setup/doctor.ts +13 -6
- package/src/setup/migrate/dex-folder.ts +842 -0
- package/src/setup/migrate/files-folder.ts +1 -1
- package/src/setup/migrate/guides.ts +3 -1
- package/src/setup/migrate/migrations.ts +8 -2
- package/src/setup/migrate/setup-files.ts +198 -0
- package/src/setup/migrate/studio-state.ts +12 -10
- package/src/setup/own-app.ts +1 -1
- package/src/setup/placement.ts +7 -6
- package/src/setup/plan.ts +13 -18
- package/src/setup/project.ts +2 -2
- package/src/setup/prompts.ts +5 -4
- package/src/setup/questions.ts +6 -3
- package/src/setup/starters.ts +3 -3
- package/src/setup/write.ts +34 -3
- package/src/shared/canvas-core.ts +48 -9
- package/src/shared/comments/routes.ts +3 -1
- package/src/shared/export-core.ts +198 -0
- package/src/shared/live-core.ts +8 -0
- package/src/shared/live-presence.ts +171 -2
- package/src/shared/page-messages.ts +38 -2
- package/src/shared/people-core.ts +44 -0
- package/src/shared/presence-core.ts +2 -0
- package/src/shared/references-core.ts +22 -3
- package/src/shared/studio-files.ts +15 -1
- package/src/shared/studio-routes.ts +11 -1
- package/src/shared/threads-core.ts +132 -10
- package/templates/methods/explore.md +1 -1
- package/templates/methods/handoff.md +1 -1
- package/templates/methods/review.md +2 -1
- package/templates/rules/canvas-frames.md +6 -3
- package/templates/rules/commands.md +1 -0
- package/templates/rules/prototypes.md +1 -1
- package/templates/rules/studio.md +17 -11
- package/templates/skills/comprehend/SKILL.md +56 -0
- package/templates/skills/distill/SKILL.md +172 -0
- package/templates/skills/export-prototype/SKILL.md +35 -0
- package/templates/skills/riff/SKILL.md +21 -0
- package/templates/skills/riff-deep/SKILL.md +40 -0
- package/templates/skills/riff-max/SKILL.md +46 -0
- package/templates/skills/riff-state/SKILL.md +45 -0
- package/templates/skills/riff-up/SKILL.md +38 -0
- package/templates/skills/riff-wide/SKILL.md +40 -0
- package/templates/starters/standalone/README.md +1 -1
- package/templates/starters/turborepo/README.md +2 -2
- package/templates/starters/turborepo/apps/web/src/app.tsx +2 -2
- package/templates/starters/vite/README.md +1 -1
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
type SnapGuide,
|
|
39
39
|
useCanvasView,
|
|
40
40
|
} from "./engine/canvas-view";
|
|
41
|
+
import { ExportDialogHost } from "./export-dialog";
|
|
41
42
|
import { FrameContextMenu, type MenuFrame } from "./frame-context-menu";
|
|
42
43
|
import {
|
|
43
44
|
dropCopiesFree,
|
|
@@ -51,6 +52,7 @@ import { frameSource } from "./frame-source";
|
|
|
51
52
|
import { InsertHint } from "./insert-hint";
|
|
52
53
|
import { type Box, type DropMark, type Gap, sectionNamesZoom } from "./layout";
|
|
53
54
|
import { usePlaceNote } from "./note-placing";
|
|
55
|
+
import { RequestNode } from "./request-node";
|
|
54
56
|
import { RowNode } from "./row-node";
|
|
55
57
|
import { useCanvasScene } from "./scene-context";
|
|
56
58
|
import { SectionNode } from "./section-node";
|
|
@@ -58,6 +60,7 @@ import { snapBox, snapPlan, snapReach } from "./snapping";
|
|
|
58
60
|
import { SpotPins } from "./spot-pins";
|
|
59
61
|
import { StackNode, type StackNodeData } from "./stack-node";
|
|
60
62
|
import { storedViewport, storeViewport } from "./stored-viewport";
|
|
63
|
+
import { TeammatesOnCanvas, useShareCanvasPlace } from "./teammates-layer";
|
|
61
64
|
import { surfaceCursor } from "./tool-cursors";
|
|
62
65
|
import { useSpecCopiesApart } from "./use-spec-copies";
|
|
63
66
|
|
|
@@ -87,6 +90,9 @@ const renderItem = (item: CanvasViewItem<unknown>, selected: boolean) => {
|
|
|
87
90
|
if (node.type === "stack") {
|
|
88
91
|
return <StackNode data={node.data} />;
|
|
89
92
|
}
|
|
93
|
+
if (node.type === "request") {
|
|
94
|
+
return <RequestNode data={node.data} />;
|
|
95
|
+
}
|
|
90
96
|
return <SectionNode data={node.data} selected={selected} />;
|
|
91
97
|
};
|
|
92
98
|
/** How far from the pointer a comment's card opens, as on a frame. */
|
|
@@ -274,6 +280,37 @@ const dropSections = (
|
|
|
274
280
|
canvas
|
|
275
281
|
);
|
|
276
282
|
|
|
283
|
+
/**
|
|
284
|
+
* Where a row, a stack or a request held would drop, and how that shows;
|
|
285
|
+
* none for frames (framesDrop). A row goes among its section's rows by
|
|
286
|
+
* where its middle is; a stack where the pointer is, its frames no place to
|
|
287
|
+
* drop it; a request in the cell the pointer is over, its own place marked.
|
|
288
|
+
*/
|
|
289
|
+
const heldDrop = (
|
|
290
|
+
scene: CanvasScene,
|
|
291
|
+
{ items, lead, pointer, zoom }: Drag<unknown>
|
|
292
|
+
): Partial<Drop> | undefined => {
|
|
293
|
+
const node = sceneItem(lead);
|
|
294
|
+
switch (node.type) {
|
|
295
|
+
case "row": {
|
|
296
|
+
const { row, section } = node.data;
|
|
297
|
+
const to = scene.rowDrop(section, row, lead.y + lead.height / 2);
|
|
298
|
+
const cell = to && { section, above: to.above, step: 1 };
|
|
299
|
+
return { cell, mark: cell && scene.dropMark(cell, lead) };
|
|
300
|
+
}
|
|
301
|
+
case "stack":
|
|
302
|
+
return stackDrop(scene, node.data, items, pointer, zoom);
|
|
303
|
+
case "request": {
|
|
304
|
+
const { id } = node.data.thread;
|
|
305
|
+
const was = scene.layout.pending.get(id);
|
|
306
|
+
const drop = scene.requestDrop(id, heldAt(lead, pointer), lead);
|
|
307
|
+
return { origins: was ? [was] : [], mark: drop && { slot: drop.box } };
|
|
308
|
+
}
|
|
309
|
+
default:
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
|
|
277
314
|
/** A thin line where what is dragged lines up with something. */
|
|
278
315
|
const SnapGuideLine = ({ guide }: { guide: SnapGuide }) => {
|
|
279
316
|
const across = guide.axis === "x";
|
|
@@ -323,7 +360,7 @@ export const FlowCanvas = ({
|
|
|
323
360
|
selection: ReadonlySet<string>;
|
|
324
361
|
setSelection: Dispatch<SetStateAction<ReadonlySet<string>>>;
|
|
325
362
|
}) => {
|
|
326
|
-
const { editor, me, prototype, say } = useCanvas();
|
|
363
|
+
const { editor, me, prototype, say, threads } = useCanvas();
|
|
327
364
|
const ui = useCanvasUiStore();
|
|
328
365
|
const tool = useCanvasUi((state) => state.tool);
|
|
329
366
|
const { apply } = editor;
|
|
@@ -336,6 +373,7 @@ export const FlowCanvas = ({
|
|
|
336
373
|
const [initialViewport] = useState(() => storedViewport(prototype.href));
|
|
337
374
|
const view = useCanvasView();
|
|
338
375
|
const { t } = useLingui();
|
|
376
|
+
useShareCanvasPlace(prototype.slug, selection, surface);
|
|
339
377
|
|
|
340
378
|
// A snapshot just captured into this prototype, or a frame an agent asked
|
|
341
379
|
// to show: zoom to it once its frame is on the canvas, whether it arrives
|
|
@@ -545,18 +583,9 @@ export const FlowCanvas = ({
|
|
|
545
583
|
show({ origins, into: scene.frame(slide) });
|
|
546
584
|
return;
|
|
547
585
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
const { row, section } = node.data;
|
|
552
|
-
const to = scene.rowDrop(section, row, lead.y + lead.height / 2);
|
|
553
|
-
const cell = to && { section, above: to.above, step: 1 };
|
|
554
|
-
show({ origins, cell, mark: cell && scene.dropMark(cell, lead) });
|
|
555
|
-
return;
|
|
556
|
-
}
|
|
557
|
-
// A stack goes where the pointer is, its frames no place to drop it.
|
|
558
|
-
if (node.type === "stack") {
|
|
559
|
-
show({ origins, ...stackDrop(scene, node.data, items, pointer, zoom) });
|
|
586
|
+
const held = heldDrop(scene, drag);
|
|
587
|
+
if (held) {
|
|
588
|
+
show({ origins, ...held });
|
|
560
589
|
return;
|
|
561
590
|
}
|
|
562
591
|
if (dropsFree(lead)) {
|
|
@@ -608,6 +637,22 @@ export const FlowCanvas = ({
|
|
|
608
637
|
[editor.canvas, prototype, say, scene, t]
|
|
609
638
|
);
|
|
610
639
|
|
|
640
|
+
/** A request dropped waits in its new cell: its thread keeps the cell. */
|
|
641
|
+
const dropRequest = useCallback(
|
|
642
|
+
async (thread: string, point: Point, held: Box) => {
|
|
643
|
+
const drop = scene.requestDrop(thread, point, held);
|
|
644
|
+
if (!drop) {
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
try {
|
|
648
|
+
await threads.send(thread, { target: drop.target });
|
|
649
|
+
} catch {
|
|
650
|
+
say(t`The request was not moved. Try again.`);
|
|
651
|
+
}
|
|
652
|
+
},
|
|
653
|
+
[say, scene, t, threads]
|
|
654
|
+
);
|
|
655
|
+
|
|
611
656
|
// A drop that changes nothing leaves the items where the layout has them:
|
|
612
657
|
// the engine puts them back.
|
|
613
658
|
const onDragEnd = useCallback(
|
|
@@ -634,6 +679,10 @@ export const FlowCanvas = ({
|
|
|
634
679
|
apply((current) => droppedStack(current, node.data, target));
|
|
635
680
|
return;
|
|
636
681
|
}
|
|
682
|
+
if (node.type === "request") {
|
|
683
|
+
dropRequest(node.data.thread.id, heldAt(dropped, pointer), dropped);
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
637
686
|
const frames = items
|
|
638
687
|
.filter((item) => isFrameNode(item.id))
|
|
639
688
|
.sort((a, b) => a.x - b.x);
|
|
@@ -685,7 +734,7 @@ export const FlowCanvas = ({
|
|
|
685
734
|
return scene.keepSizes(current, dropped.canvas);
|
|
686
735
|
}, touched);
|
|
687
736
|
},
|
|
688
|
-
[apply, intoSlide, me, scene, dropsFree]
|
|
737
|
+
[apply, intoSlide, me, dropRequest, scene, dropsFree]
|
|
689
738
|
);
|
|
690
739
|
|
|
691
740
|
// With the comment tool, a click on the empty canvas comments there: on
|
|
@@ -770,6 +819,7 @@ export const FlowCanvas = ({
|
|
|
770
819
|
takesWheel={canvasTakesWheel}
|
|
771
820
|
>
|
|
772
821
|
<SpotPins />
|
|
822
|
+
<TeammatesOnCanvas slug={prototype.slug} />
|
|
773
823
|
{drop?.origins.map((box) => (
|
|
774
824
|
<div
|
|
775
825
|
className="studio-drag-origin"
|
|
@@ -811,6 +861,7 @@ export const FlowCanvas = ({
|
|
|
811
861
|
onClose={() => setMenu(undefined)}
|
|
812
862
|
/>
|
|
813
863
|
) : null}
|
|
864
|
+
<ExportDialogHost />
|
|
814
865
|
{canvasMenu ? (
|
|
815
866
|
<CanvasContextMenu
|
|
816
867
|
at={canvasMenu}
|
|
@@ -36,7 +36,7 @@ import { CAN_WRITE } from "../live/studio-api";
|
|
|
36
36
|
import { changeCover } from "../shell/prototype-menu";
|
|
37
37
|
import type { Frame } from "../types";
|
|
38
38
|
import { addToSpec, type SpecChoice, specsFor } from "./add-to-spec";
|
|
39
|
-
import { frameTarget } from "./anchoring";
|
|
39
|
+
import { elementTarget, frameTarget } from "./anchoring";
|
|
40
40
|
import { type ScreenPoint, useCanvas } from "./canvas-context";
|
|
41
41
|
import { rebuildRequest } from "./canvas-menus";
|
|
42
42
|
import {
|
|
@@ -49,7 +49,11 @@ import {
|
|
|
49
49
|
updateFrame,
|
|
50
50
|
} from "./canvas-model";
|
|
51
51
|
import { deviceIcon } from "./device-icons";
|
|
52
|
+
import { elementLink, placeToLink } from "./element-link";
|
|
53
|
+
import { describeElement } from "./element-picker";
|
|
54
|
+
import { openExport } from "./export-dialog";
|
|
52
55
|
import { atDevice, frameSource } from "./frame-source";
|
|
56
|
+
import { framePages } from "./live-page";
|
|
53
57
|
import { PointMenu } from "./point-menu";
|
|
54
58
|
import { useCanvasScene } from "./scene-context";
|
|
55
59
|
import { slideLayoutOf } from "./slide-page";
|
|
@@ -135,9 +139,27 @@ const SLIDE_LAYOUT_ITEMS: {
|
|
|
135
139
|
];
|
|
136
140
|
|
|
137
141
|
/**
|
|
138
|
-
* What
|
|
139
|
-
*
|
|
140
|
-
*
|
|
142
|
+
* What a link from a frame's menu goes to: the element right-clicked on it,
|
|
143
|
+
* as its page draws it there; the whole frame when it is on none, or its
|
|
144
|
+
* page isn't live.
|
|
145
|
+
*/
|
|
146
|
+
const linkAt = (key: string, frame: Frame, at: ScreenPoint) => {
|
|
147
|
+
const view = viewOf(frame);
|
|
148
|
+
const picked = view
|
|
149
|
+
? framePages.get(key)?.elementAtScreen(at.left, at.top)
|
|
150
|
+
: undefined;
|
|
151
|
+
const place = placeToLink(
|
|
152
|
+
view && picked
|
|
153
|
+
? elementTarget(key, view, [describeElement(picked.element)])
|
|
154
|
+
: frameTarget(key, frame)
|
|
155
|
+
);
|
|
156
|
+
return place && { place, onElement: picked !== undefined };
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* What only one frame can do: play the section from it, open it, copy a link
|
|
161
|
+
* to it or the element right-clicked, comment on it, rebuild a snapshot, give
|
|
162
|
+
* each state its own row, and change its viewport.
|
|
141
163
|
*/
|
|
142
164
|
const OneFrameItems = ({
|
|
143
165
|
at,
|
|
@@ -152,7 +174,7 @@ const OneFrameItems = ({
|
|
|
152
174
|
run: (action: () => void) => () => void;
|
|
153
175
|
}) => {
|
|
154
176
|
const { i18n, t } = useLingui();
|
|
155
|
-
const { compose, devices, editor, prototype, threads } = useCanvas();
|
|
177
|
+
const { compose, devices, editor, prototype, say, threads } = useCanvas();
|
|
156
178
|
const [, navigate] = useLocation();
|
|
157
179
|
const { frame, key } = entry;
|
|
158
180
|
const address = parseFrameKey(key);
|
|
@@ -165,6 +187,25 @@ const OneFrameItems = ({
|
|
|
165
187
|
const { href } = frameSource(prototype, frame);
|
|
166
188
|
const controls = Object.entries(frameControls.get(key) ?? {});
|
|
167
189
|
const editable = editor.editable;
|
|
190
|
+
const copyLink = async () => {
|
|
191
|
+
const link = linkAt(key, frame, at);
|
|
192
|
+
if (!link) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
// No clipboard at all (an address that isn't secure) throws here too.
|
|
196
|
+
try {
|
|
197
|
+
await navigator.clipboard.writeText(
|
|
198
|
+
elementLink(link.place, window.location.href)
|
|
199
|
+
);
|
|
200
|
+
say(
|
|
201
|
+
link.onElement
|
|
202
|
+
? t`Copied a link to this element.`
|
|
203
|
+
: t`Copied a link to this frame.`
|
|
204
|
+
);
|
|
205
|
+
} catch {
|
|
206
|
+
say(t`The link was not copied. Try again.`);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
168
209
|
return (
|
|
169
210
|
<>
|
|
170
211
|
{divided ? <DropdownMenuSeparator /> : null}
|
|
@@ -187,6 +228,9 @@ const OneFrameItems = ({
|
|
|
187
228
|
<Trans>Open</Trans>
|
|
188
229
|
</Item>
|
|
189
230
|
) : null}
|
|
231
|
+
<Item icon="Link" onSelect={run(copyLink)}>
|
|
232
|
+
<Trans>Copy link</Trans>
|
|
233
|
+
</Item>
|
|
190
234
|
{CAN_WRITE ? (
|
|
191
235
|
<Item
|
|
192
236
|
icon={<CommentIcon />}
|
|
@@ -412,12 +456,17 @@ const ClipboardItems = ({
|
|
|
412
456
|
);
|
|
413
457
|
};
|
|
414
458
|
|
|
415
|
-
/**
|
|
459
|
+
/**
|
|
460
|
+
* Copy or download the views as PNGs, the slides as a PDF, and export the
|
|
461
|
+
* frames to open anywhere (export-dialog.tsx).
|
|
462
|
+
*/
|
|
416
463
|
const ExportItems = ({
|
|
464
|
+
frames,
|
|
417
465
|
run,
|
|
418
466
|
shots,
|
|
419
467
|
slides,
|
|
420
468
|
}: {
|
|
469
|
+
frames: MenuFrame[];
|
|
421
470
|
run: (action: () => void) => () => void;
|
|
422
471
|
shots: { frame: Frame; title: string }[];
|
|
423
472
|
slides: MenuFrame[];
|
|
@@ -451,6 +500,11 @@ const ExportItems = ({
|
|
|
451
500
|
)}
|
|
452
501
|
</Item>
|
|
453
502
|
) : null}
|
|
503
|
+
{shots.length > 0 ? (
|
|
504
|
+
<Item icon="Archive" onSelect={run(() => openExport(frames))}>
|
|
505
|
+
<Trans>Export…</Trans>
|
|
506
|
+
</Item>
|
|
507
|
+
) : null}
|
|
454
508
|
</DropdownMenuGroup>
|
|
455
509
|
);
|
|
456
510
|
};
|
|
@@ -506,7 +560,7 @@ export const FrameContextMenu = ({
|
|
|
506
560
|
run={run}
|
|
507
561
|
/>
|
|
508
562
|
{exporting ? (
|
|
509
|
-
<ExportItems run={run} shots={shots} slides={slides} />
|
|
563
|
+
<ExportItems frames={frames} run={run} shots={shots} slides={slides} />
|
|
510
564
|
) : null}
|
|
511
565
|
{picking ? (
|
|
512
566
|
<PickItems
|
|
@@ -93,6 +93,7 @@ import { GridOverlay } from "./grid-overlay";
|
|
|
93
93
|
import { InspectLayer } from "./inspect-layer";
|
|
94
94
|
import { LabelAction } from "./label-action";
|
|
95
95
|
import { COLUMN_GAP, DOC_SIZE, frameSize } from "./layout";
|
|
96
|
+
import { LinkedOutline, linkedBoxes, useLinkedOn } from "./linked-element";
|
|
96
97
|
import {
|
|
97
98
|
type Box,
|
|
98
99
|
type LivePage,
|
|
@@ -109,6 +110,7 @@ import {
|
|
|
109
110
|
useKeptMeasures,
|
|
110
111
|
useReportPageHeight,
|
|
111
112
|
} from "./page-heights";
|
|
113
|
+
import { boxKey, PickedBox } from "./picked-box";
|
|
112
114
|
import { useCanvasScene } from "./scene-context";
|
|
113
115
|
import { SketchPage } from "./sketch-boxes";
|
|
114
116
|
import { SketchCopyOffer, SketchLayer } from "./sketch-layer";
|
|
@@ -120,6 +122,7 @@ import { specFilePath } from "./spec-full-screen";
|
|
|
120
122
|
import { useSpecMarks } from "./spec-threads";
|
|
121
123
|
import { useStateOf } from "./state-store";
|
|
122
124
|
import { StylesLayer } from "./styles-layer";
|
|
125
|
+
import { TeammatesAtWork } from "./teammates-layer";
|
|
123
126
|
import { TextLayer } from "./text-layer";
|
|
124
127
|
import { Tip, TipGroup } from "./tip";
|
|
125
128
|
import { UnknownFrame } from "./unknown-frame";
|
|
@@ -416,14 +419,18 @@ const FramePins = ({
|
|
|
416
419
|
const placed = landedOn(thread, editor.canvas);
|
|
417
420
|
return placed?.key === key ? [{ thread, place: placed.place }] : [];
|
|
418
421
|
});
|
|
422
|
+
// The element a link opened the canvas on, if it is on this frame.
|
|
423
|
+
const linkedPlace = useLinkedOn(key);
|
|
419
424
|
const boxes = useSelectorBoxes(
|
|
420
425
|
page,
|
|
421
426
|
[
|
|
422
427
|
...pins.flatMap((thread) => locatorsOf(thread.target)),
|
|
423
428
|
...landed.flatMap(({ place }) => locatorsOf(place)),
|
|
429
|
+
...(linkedPlace ? locatorsOf(linkedPlace) : []),
|
|
424
430
|
],
|
|
425
431
|
height
|
|
426
432
|
);
|
|
433
|
+
const linkedOn = linkedPlace ? linkedBoxes(linkedPlace, boxes) : [];
|
|
427
434
|
const draftPoint = draft
|
|
428
435
|
? pinPoint(draft, boxes, width, { drafting: true })
|
|
429
436
|
: undefined;
|
|
@@ -443,17 +450,7 @@ const FramePins = ({
|
|
|
443
450
|
return (
|
|
444
451
|
<Fragment key={thread.id}>
|
|
445
452
|
{outlined.map((entry) => (
|
|
446
|
-
<
|
|
447
|
-
className="studio-pick z-20"
|
|
448
|
-
data-picked
|
|
449
|
-
key={`${entry.x},${entry.y},${entry.width}`}
|
|
450
|
-
style={{
|
|
451
|
-
left: entry.x,
|
|
452
|
-
top: entry.y,
|
|
453
|
-
width: entry.width,
|
|
454
|
-
height: entry.height,
|
|
455
|
-
}}
|
|
456
|
-
/>
|
|
453
|
+
<PickedBox box={entry} key={boxKey(entry)} />
|
|
457
454
|
))}
|
|
458
455
|
<div
|
|
459
456
|
className="studio-screen absolute z-30 origin-top-left"
|
|
@@ -488,6 +485,7 @@ const FramePins = ({
|
|
|
488
485
|
});
|
|
489
486
|
return (
|
|
490
487
|
<>
|
|
488
|
+
{linkedOn.length > 0 ? <LinkedOutline boxes={linkedOn} /> : null}
|
|
491
489
|
{placed}
|
|
492
490
|
{agentPins}
|
|
493
491
|
{draftPoint ? (
|
|
@@ -970,6 +968,7 @@ const FrameLabel = ({
|
|
|
970
968
|
value={source.title}
|
|
971
969
|
/>
|
|
972
970
|
</span>
|
|
971
|
+
<TeammatesAtWork entries={working} />
|
|
973
972
|
{by ? (
|
|
974
973
|
// Whose row it is gives way first: the frame's name stays readable.
|
|
975
974
|
<span className="flex min-w-0 shrink-[100] items-center gap-1.5 text-muted-foreground/70">
|
package/app/canvas/layout.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
isSlidePath,
|
|
6
6
|
kinded,
|
|
7
7
|
NOTE_SIZE,
|
|
8
|
+
type PageSize,
|
|
8
9
|
placedAt,
|
|
9
10
|
SLIDE_SIZE,
|
|
10
11
|
SPEC_SIZE,
|
|
@@ -114,11 +115,13 @@ export interface PlacedFrame extends Box {
|
|
|
114
115
|
/** A request for a new view, waiting in the cell it will fill. */
|
|
115
116
|
export interface PendingCell extends Cell {
|
|
116
117
|
id: string;
|
|
118
|
+
/** The size the person gave it; else the frame's before it. */
|
|
119
|
+
size?: PageSize;
|
|
117
120
|
}
|
|
118
121
|
|
|
119
122
|
/** A pending request where it waits: the step it took, which may be later. */
|
|
120
123
|
export interface PlacedPending extends Box {
|
|
121
|
-
/** None when it waits for a new row, below
|
|
124
|
+
/** None when it waits for a new row: above the row it names, or below all. */
|
|
122
125
|
row?: string;
|
|
123
126
|
section: string;
|
|
124
127
|
step: number;
|
|
@@ -397,6 +400,36 @@ const rowColumnsX = (
|
|
|
397
400
|
return (step: number) => xs.get(step) ?? columnX(step);
|
|
398
401
|
};
|
|
399
402
|
|
|
403
|
+
/**
|
|
404
|
+
* Give each request for a new row a place of its own among a section's rows'
|
|
405
|
+
* cells: right above the row it names, as the + on the line between two rows
|
|
406
|
+
* asks, or below the rows.
|
|
407
|
+
*/
|
|
408
|
+
const placeNewRowRequests = (
|
|
409
|
+
rowCells: { cells: RowCell[]; row?: Row }[],
|
|
410
|
+
rows: readonly Row[],
|
|
411
|
+
pending: readonly PendingCell[]
|
|
412
|
+
) => {
|
|
413
|
+
for (const request of pending.filter(
|
|
414
|
+
(entry) => !(entry.row && rows.some((row) => row.id === entry.row))
|
|
415
|
+
)) {
|
|
416
|
+
const above = rowCells.findIndex(
|
|
417
|
+
({ row }) => row !== undefined && row.id === request.above
|
|
418
|
+
);
|
|
419
|
+
rowCells.splice(above < 0 ? rowCells.length : above, 0, {
|
|
420
|
+
cells: [
|
|
421
|
+
{
|
|
422
|
+
...(request.size ?? pageSize()),
|
|
423
|
+
key: request.id,
|
|
424
|
+
kind: "pending",
|
|
425
|
+
step: request.step,
|
|
426
|
+
top: 0,
|
|
427
|
+
},
|
|
428
|
+
],
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
|
|
400
433
|
function layOutSection(
|
|
401
434
|
section: Section,
|
|
402
435
|
origin: { x: number; y: number },
|
|
@@ -434,7 +467,7 @@ function layOutSection(
|
|
|
434
467
|
}
|
|
435
468
|
taken.add(step);
|
|
436
469
|
cells.push({
|
|
437
|
-
...pendingSize(cells, row.frames, step),
|
|
470
|
+
...(request.size ?? pendingSize(cells, row.frames, step)),
|
|
438
471
|
key: request.id,
|
|
439
472
|
kind: "pending",
|
|
440
473
|
step,
|
|
@@ -443,22 +476,7 @@ function layOutSection(
|
|
|
443
476
|
return { row, cells: stackColumns(cells) };
|
|
444
477
|
}
|
|
445
478
|
);
|
|
446
|
-
|
|
447
|
-
for (const request of pending.filter(
|
|
448
|
-
(entry) => !(entry.row && section.rows.some((row) => row.id === entry.row))
|
|
449
|
-
)) {
|
|
450
|
-
rowCells.push({
|
|
451
|
-
cells: [
|
|
452
|
-
{
|
|
453
|
-
...pageSize(),
|
|
454
|
-
key: request.id,
|
|
455
|
-
kind: "pending",
|
|
456
|
-
step: request.step,
|
|
457
|
-
top: 0,
|
|
458
|
-
},
|
|
459
|
-
],
|
|
460
|
-
});
|
|
461
|
-
}
|
|
479
|
+
placeNewRowRequests(rowCells, section.rows, pending);
|
|
462
480
|
|
|
463
481
|
const stepCount = Math.max(
|
|
464
482
|
0,
|
|
@@ -948,9 +966,10 @@ const rowSpan = (section: PlacedSection) => ({
|
|
|
948
966
|
});
|
|
949
967
|
|
|
950
968
|
/**
|
|
951
|
-
* How far down the canvas the line for a new row is: halfway
|
|
952
|
-
*
|
|
953
|
-
*
|
|
969
|
+
* How far down the canvas the line for a new row is: halfway down the gap
|
|
970
|
+
* under the row before the one it goes above, so clear of a request waiting
|
|
971
|
+
* there, or as far outside a section's first or last row as the section's
|
|
972
|
+
* surface has room for. None in a section with no rows.
|
|
954
973
|
*/
|
|
955
974
|
const rowGapY = (section: PlacedSection, above?: string) => {
|
|
956
975
|
const at = section.rows.findIndex((row) => row.id === above);
|
|
@@ -958,7 +977,7 @@ const rowGapY = (section: PlacedSection, above?: string) => {
|
|
|
958
977
|
const before = section.rows[index - 1];
|
|
959
978
|
const after = section.rows[index];
|
|
960
979
|
if (before && after) {
|
|
961
|
-
return
|
|
980
|
+
return before.y + before.height + ROW_GAP / 2;
|
|
962
981
|
}
|
|
963
982
|
if (after) {
|
|
964
983
|
return after.y - SECTION_PADDING / 2;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { useLingui } from "@lingui/react/macro";
|
|
2
|
+
import { useEffect, useLayoutEffect, useRef } from "react";
|
|
3
|
+
import type { ChangePlace } from "../../src/shared/threads-core.ts";
|
|
4
|
+
import type { Canvas } from "../types";
|
|
5
|
+
import { boxOf, frameOfTarget } from "./anchoring";
|
|
6
|
+
import { type CanvasUi, useCanvasUi, useCanvasUiStore } from "./canvas-ui";
|
|
7
|
+
import { placeFromAddress, withoutLink } from "./element-link";
|
|
8
|
+
import { useCanvasView } from "./engine/canvas-view";
|
|
9
|
+
import { type Box, boundsOf } from "./layout";
|
|
10
|
+
import { boxKey, boxStyle, PickedBox } from "./picked-box";
|
|
11
|
+
import { useStateOf } from "./state-store";
|
|
12
|
+
import { FOCUS_MS, FOCUS_PADDING } from "./thread-focus";
|
|
13
|
+
|
|
14
|
+
// Opening a link to elements (element-link.ts): the canvas moves to their
|
|
15
|
+
// frame, then, once its page has drawn them, to the elements themselves,
|
|
16
|
+
// outlined for a moment. One in a menu or dialog that is closed is shown by
|
|
17
|
+
// what opens it, as its comment's pin would be.
|
|
18
|
+
|
|
19
|
+
/** How long the elements a link opened on stay outlined. */
|
|
20
|
+
const LINKED_OUTLINE_MS = 2400;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* How long the canvas waits for a frame's page to draw what a link is to
|
|
24
|
+
* before letting go of it: it may be gone, or in a state the page isn't in.
|
|
25
|
+
*/
|
|
26
|
+
const LINKED_WAIT_MS = 10_000;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* At most actual size, or as near as the frame already is: a link to a
|
|
30
|
+
* button shows it in its page, not filling the screen.
|
|
31
|
+
*/
|
|
32
|
+
const LINKED_MAX_ZOOM = 1;
|
|
33
|
+
|
|
34
|
+
type ElementPlace = Extract<ChangePlace, { kind: "element" }>;
|
|
35
|
+
|
|
36
|
+
/** The elements a link opened the canvas on: their frame, and where on it. */
|
|
37
|
+
export interface LinkedElement {
|
|
38
|
+
/** Its frame's page has drawn them, so the canvas went to them. */
|
|
39
|
+
found?: true;
|
|
40
|
+
key: string;
|
|
41
|
+
place: ElementPlace;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Open the canvas where its address links to: its frame once the canvas has
|
|
46
|
+
* laid it out, and its elements (FramePins) once the frame's page draws
|
|
47
|
+
* them. The link leaves the address once it has opened, so a reload stays
|
|
48
|
+
* where you are; one to a frame no longer on the canvas says so.
|
|
49
|
+
*/
|
|
50
|
+
export function useElementLink(
|
|
51
|
+
canvas: Canvas,
|
|
52
|
+
{ say, ui }: { say: (text: string) => void; ui: CanvasUi }
|
|
53
|
+
) {
|
|
54
|
+
const { t } = useLingui();
|
|
55
|
+
const view = useCanvasView();
|
|
56
|
+
const pending = useRef(placeFromAddress(window.location.search));
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
const place = pending.current;
|
|
59
|
+
if (!place) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const key = frameOfTarget(place, canvas);
|
|
63
|
+
if (key && !view.getItem(key)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// As a linked thread waits: the canvas lays out first. The link is
|
|
67
|
+
// spent only once it moves; a new canvas in the wait starts it again.
|
|
68
|
+
const timer = window.setTimeout(() => {
|
|
69
|
+
pending.current = undefined;
|
|
70
|
+
window.history.replaceState(
|
|
71
|
+
window.history.state,
|
|
72
|
+
"",
|
|
73
|
+
withoutLink(window.location.href)
|
|
74
|
+
);
|
|
75
|
+
if (!key) {
|
|
76
|
+
say(t`The frame that link goes to isn't on this canvas any more.`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
view.fitView({
|
|
80
|
+
nodes: [{ id: key }],
|
|
81
|
+
padding: FOCUS_PADDING,
|
|
82
|
+
duration: FOCUS_MS,
|
|
83
|
+
});
|
|
84
|
+
if (place.kind === "element") {
|
|
85
|
+
ui.setLinked({ key, place });
|
|
86
|
+
}
|
|
87
|
+
}, FOCUS_MS);
|
|
88
|
+
return () => window.clearTimeout(timer);
|
|
89
|
+
}, [canvas, view, ui, say, t]);
|
|
90
|
+
|
|
91
|
+
// Let go of what a link is to if its page never draws it, and say so.
|
|
92
|
+
// The page holds the store, above its provider: read from it directly.
|
|
93
|
+
const waiting = useStateOf(ui, (state) =>
|
|
94
|
+
state.linked && !state.linked.found ? state.linked : undefined
|
|
95
|
+
);
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (!waiting) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const timer = window.setTimeout(() => {
|
|
101
|
+
if (ui.get().linked === waiting) {
|
|
102
|
+
ui.setLinked();
|
|
103
|
+
say(t`What that link goes to isn't showing on its frame.`);
|
|
104
|
+
}
|
|
105
|
+
}, LINKED_WAIT_MS);
|
|
106
|
+
return () => window.clearTimeout(timer);
|
|
107
|
+
}, [waiting, ui, say, t]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Where on a frame the elements a link opened on are, if it is that frame. */
|
|
111
|
+
export const useLinkedOn = (key: string): ElementPlace | undefined =>
|
|
112
|
+
useCanvasUi((state) =>
|
|
113
|
+
state.linked?.key === key ? state.linked.place : undefined
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The boxes of a link's elements on their page: the first, or what opens it
|
|
118
|
+
* while it is closed, then any more that show.
|
|
119
|
+
*/
|
|
120
|
+
export const linkedBoxes = (
|
|
121
|
+
place: ElementPlace,
|
|
122
|
+
boxes: ReadonlyMap<string, Box>
|
|
123
|
+
): Box[] => {
|
|
124
|
+
const first =
|
|
125
|
+
boxOf(boxes, place) ??
|
|
126
|
+
place.openers
|
|
127
|
+
?.map((opener) => boxOf(boxes, opener))
|
|
128
|
+
.find((box) => box !== undefined);
|
|
129
|
+
const more = (place.also ?? []).flatMap((entry) => boxOf(boxes, entry) ?? []);
|
|
130
|
+
return first ? [first, ...more] : more;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The elements a link opened on, outlined where their frame's page drew
|
|
135
|
+
* them: the canvas moves to them as they show, and again if the page moves
|
|
136
|
+
* them while they are outlined; the outline goes after a moment.
|
|
137
|
+
*/
|
|
138
|
+
export const LinkedOutline = ({ boxes }: { boxes: readonly Box[] }) => {
|
|
139
|
+
const all = useRef<HTMLDivElement>(null);
|
|
140
|
+
const view = useCanvasView();
|
|
141
|
+
const ui = useCanvasUiStore();
|
|
142
|
+
// Only drawn with a box, so there is always one around them.
|
|
143
|
+
const { x, y, width, height } = boundsOf(boxes) ?? boxes[0];
|
|
144
|
+
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
const now = ui.get().linked;
|
|
147
|
+
if (!now) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const found = { ...now, found: true as const };
|
|
151
|
+
ui.setLinked(found);
|
|
152
|
+
// Lets go of this link only: another opened meanwhile stays.
|
|
153
|
+
const timer = window.setTimeout(() => {
|
|
154
|
+
if (ui.get().linked === found) {
|
|
155
|
+
ui.setLinked();
|
|
156
|
+
}
|
|
157
|
+
}, LINKED_OUTLINE_MS);
|
|
158
|
+
return () => window.clearTimeout(timer);
|
|
159
|
+
}, [ui]);
|
|
160
|
+
|
|
161
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: fits again when the page moves them
|
|
162
|
+
useLayoutEffect(() => {
|
|
163
|
+
const element = all.current;
|
|
164
|
+
if (!element) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
// Where they are on screen, with the canvas painted where it is now
|
|
168
|
+
// (moving to the frame still), then where that is on the canvas.
|
|
169
|
+
view.paintNow();
|
|
170
|
+
const rect = element.getBoundingClientRect();
|
|
171
|
+
const from = view.screenToCanvas({ x: rect.left, y: rect.top });
|
|
172
|
+
const to = view.screenToCanvas({ x: rect.right, y: rect.bottom });
|
|
173
|
+
view.fitBounds(
|
|
174
|
+
{ x: from.x, y: from.y, width: to.x - from.x, height: to.y - from.y },
|
|
175
|
+
{
|
|
176
|
+
padding: FOCUS_PADDING,
|
|
177
|
+
duration: FOCUS_MS,
|
|
178
|
+
maxZoom: Math.max(LINKED_MAX_ZOOM, view.getZoom()),
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
}, [view, x, y, width, height]);
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<>
|
|
185
|
+
<div
|
|
186
|
+
aria-hidden
|
|
187
|
+
className="pointer-events-none absolute"
|
|
188
|
+
ref={all}
|
|
189
|
+
style={boxStyle({ x, y, width, height })}
|
|
190
|
+
/>
|
|
191
|
+
{boxes.map((box) => (
|
|
192
|
+
<PickedBox box={box} key={boxKey(box)} />
|
|
193
|
+
))}
|
|
194
|
+
</>
|
|
195
|
+
);
|
|
196
|
+
};
|