@sixb/app 0.2.3 → 0.2.4
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/dist/agent/activity-label.d.ts.map +1 -1
- package/dist/agent/agent-chat.d.ts.map +1 -1
- package/dist/agent/background/background-tool-row.d.ts.map +1 -1
- package/dist/agent/background/interpret.d.ts +1 -1
- package/dist/agent/background/interpret.d.ts.map +1 -1
- package/dist/agent/components/conversation-panel.d.ts +4 -1
- package/dist/agent/components/conversation-panel.d.ts.map +1 -1
- package/dist/agent/components/message-parts.d.ts.map +1 -1
- package/dist/agent/components/transcript.d.ts +5 -0
- package/dist/agent/components/transcript.d.ts.map +1 -1
- package/dist/agent/delegation/agent-exchange.d.ts +16 -0
- package/dist/agent/delegation/agent-exchange.d.ts.map +1 -0
- package/dist/agent/delegation/child-card.d.ts +3 -3
- package/dist/agent/delegation/child-card.d.ts.map +1 -1
- package/dist/agent/delegation/child-parts.d.ts +1 -10
- package/dist/agent/delegation/child-parts.d.ts.map +1 -1
- package/dist/agent/delegation/child-work.d.ts.map +1 -1
- package/dist/agent/delegation/interpret.d.ts +4 -10
- package/dist/agent/delegation/interpret.d.ts.map +1 -1
- package/dist/agent/file-edits/file-edit-tool-view.d.ts +10 -0
- package/dist/agent/file-edits/file-edit-tool-view.d.ts.map +1 -0
- package/dist/agent/file-edits/interpret.d.ts +25 -0
- package/dist/agent/file-edits/interpret.d.ts.map +1 -0
- package/dist/agent/hooks/use-agent-conversation.d.ts +6 -0
- package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
- package/dist/agent/i18n/en.d.ts +46 -5
- package/dist/agent/i18n/en.d.ts.map +1 -1
- package/dist/agent/i18n/fr.d.ts.map +1 -1
- package/dist/agent/i18n/index.d.ts +76 -8
- package/dist/agent/i18n/index.d.ts.map +1 -1
- package/dist/agent/message-agent/interpret.d.ts +2 -2
- package/dist/agent/message-agent/interpret.d.ts.map +1 -1
- package/dist/agent/publish-artifact/interpret.d.ts +1 -1
- package/dist/agent/publish-artifact/interpret.d.ts.map +1 -1
- package/dist/agent/questions/interpret.d.ts +31 -0
- package/dist/agent/questions/interpret.d.ts.map +1 -0
- package/dist/agent/questions/question-card.d.ts +16 -0
- package/dist/agent/questions/question-card.d.ts.map +1 -0
- package/dist/agent/questions/question-composer.d.ts +15 -0
- package/dist/agent/questions/question-composer.d.ts.map +1 -0
- package/dist/agent/read/interpret.d.ts +8 -1
- package/dist/agent/read/interpret.d.ts.map +1 -1
- package/dist/agent/read/read-tool-view.d.ts.map +1 -1
- package/dist/agent/tool-views/built-in.d.ts.map +1 -1
- package/dist/agent/waits.d.ts +14 -0
- package/dist/agent/waits.d.ts.map +1 -0
- package/dist/artifacts/edit-session.d.ts +11 -1
- package/dist/artifacts/edit-session.d.ts.map +1 -1
- package/dist/artifacts/frame.d.ts.map +1 -1
- package/dist/artifacts/messages.d.ts +52 -0
- package/dist/artifacts/messages.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/board-editor.d.ts +11 -4
- package/dist/artifacts/renderers/canvas/board-editor.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/board.d.ts +14 -2
- package/dist/artifacts/renderers/canvas/board.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/canvas.d.ts +4 -3
- package/dist/artifacts/renderers/canvas/canvas.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/controls.d.ts +15 -4
- package/dist/artifacts/renderers/canvas/controls.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/focus.d.ts +19 -5
- package/dist/artifacts/renderers/canvas/focus.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/gestures.d.ts +46 -0
- package/dist/artifacts/renderers/canvas/gestures.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-resize.d.ts +21 -0
- package/dist/artifacts/renderers/canvas/page-resize.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-size-controls.d.ts +21 -0
- package/dist/artifacts/renderers/canvas/page-size-controls.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-size.d.ts +93 -0
- package/dist/artifacts/renderers/canvas/page-size.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/page-zoom.d.ts +64 -0
- package/dist/artifacts/renderers/canvas/page-zoom.d.ts.map +1 -0
- package/dist/artifacts/renderers/canvas/shown-size.d.ts +26 -0
- package/dist/artifacts/renderers/canvas/shown-size.d.ts.map +1 -0
- package/dist/{chunk-kes4ygmz.js → chunk-970s5nkn.js} +1 -1
- package/dist/{chunk-001c4gnk.js → chunk-kymx9y5e.js} +3117 -2363
- package/dist/{chunk-001c4gnk.js.map → chunk-kymx9y5e.js.map} +36 -29
- package/dist/{chunk-fwb9mxwm.js → chunk-pxd07kvx.js} +1 -1
- package/dist/{chunk-5crvhjp2.js → chunk-yrcm1pbg.js} +1504 -233
- package/dist/chunk-yrcm1pbg.js.map +34 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +3 -3
- package/dist/pages.js +2 -2
- package/package.json +2 -2
- package/src/agent/activity-label.ts +6 -1
- package/src/agent/agent-chat.tsx +1 -0
- package/src/agent/background/background-tool-row.tsx +24 -10
- package/src/agent/background/interpret.ts +60 -51
- package/src/agent/components/conversation-panel.tsx +27 -8
- package/src/agent/components/message-parts.tsx +23 -5
- package/src/agent/components/transcript.tsx +45 -27
- package/src/agent/delegation/agent-exchange.tsx +53 -0
- package/src/agent/delegation/child-card.tsx +6 -40
- package/src/agent/delegation/child-parts.tsx +1 -84
- package/src/agent/delegation/child-work.tsx +19 -5
- package/src/agent/delegation/interpret.ts +33 -54
- package/src/agent/delegation/model.ts +1 -1
- package/src/agent/file-edits/file-edit-tool-view.tsx +126 -0
- package/src/agent/file-edits/interpret.ts +120 -0
- package/src/agent/hooks/use-agent-conversation.ts +20 -0
- package/src/agent/i18n/en.ts +47 -5
- package/src/agent/i18n/fr.ts +39 -4
- package/src/agent/message-agent/interpret.ts +4 -3
- package/src/agent/publish-artifact/interpret.ts +14 -5
- package/src/agent/publish-artifact/publish-artifact-tool-view.tsx +2 -2
- package/src/agent/questions/interpret.ts +90 -0
- package/src/agent/questions/question-card.tsx +57 -0
- package/src/agent/questions/question-composer.tsx +257 -0
- package/src/agent/read/interpret.ts +34 -1
- package/src/agent/read/read-tool-view.tsx +20 -4
- package/src/agent/tool-views/built-in.tsx +19 -8
- package/src/agent/waits.ts +50 -0
- package/src/artifacts/artifacts.css +36 -0
- package/src/artifacts/edit-session.tsx +15 -1
- package/src/artifacts/frame.tsx +3 -2
- package/src/artifacts/messages.ts +54 -0
- package/src/artifacts/renderers/canvas/board-editor.tsx +37 -15
- package/src/artifacts/renderers/canvas/board.tsx +70 -8
- package/src/artifacts/renderers/canvas/canvas.tsx +66 -15
- package/src/artifacts/renderers/canvas/controls.tsx +64 -30
- package/src/artifacts/renderers/canvas/focus.tsx +200 -56
- package/src/artifacts/renderers/canvas/gestures.ts +265 -0
- package/src/artifacts/renderers/canvas/page-resize.tsx +542 -0
- package/src/artifacts/renderers/canvas/page-size-controls.tsx +193 -0
- package/src/artifacts/renderers/canvas/page-size.ts +218 -0
- package/src/artifacts/renderers/canvas/page-zoom.ts +280 -0
- package/src/artifacts/renderers/canvas/shown-size.ts +105 -0
- package/src/artifacts/viewer.tsx +15 -1
- package/src/index.ts +2 -0
- package/dist/chunk-5crvhjp2.js.map +0 -28
- /package/dist/{chunk-kes4ygmz.js.map → chunk-970s5nkn.js.map} +0 -0
- /package/dist/{chunk-fwb9mxwm.js.map → chunk-pxd07kvx.js.map} +0 -0
|
@@ -206,6 +206,42 @@
|
|
|
206
206
|
display: none;
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
/*
|
|
210
|
+
* A board the reader uses in place, running while they read the canvas (renderers/canvas/board.tsx):
|
|
211
|
+
* a soft ring while the pointer is over it, the page's own cursor inside. Holding Space, a drag
|
|
212
|
+
* across its page pans, as anywhere on the canvas.
|
|
213
|
+
*/
|
|
214
|
+
.sixb-artboard .react-flow__node-board .sixb-canvas-surface {
|
|
215
|
+
transition: box-shadow 160ms ease-out;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.sixb-artboard .sixb-canvas-surface:has(> [data-interactive]:hover) {
|
|
219
|
+
box-shadow:
|
|
220
|
+
0 0 0 calc(1.5px * var(--sixb-name-scale, 1)) color-mix(in oklab, var(--primary) 24%, transparent),
|
|
221
|
+
0 1px 2px rgb(0 0 0 / 0.05),
|
|
222
|
+
0 20px 44px -28px rgb(0 0 0 / 0.35);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/* A pan dragged across a page keeps going: the page under the pointer takes none of it. */
|
|
226
|
+
.sixb-artboard[data-panning] [data-interactive] iframe,
|
|
227
|
+
.sixb-artboard:has(.react-flow__pane.dragging) [data-interactive] iframe {
|
|
228
|
+
pointer-events: none;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.sixb-artboard[data-panning] :is(.react-flow__pane, .react-flow__node) {
|
|
232
|
+
cursor: grab;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.sixb-artboard[data-panning] :is(.react-flow__pane, .react-flow__node):active {
|
|
236
|
+
cursor: grabbing;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
@media (prefers-reduced-motion: reduce) {
|
|
240
|
+
.sixb-artboard .react-flow__node-board .sixb-canvas-surface {
|
|
241
|
+
transition: none;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
209
245
|
/* A board takes focus from the keyboard, to open it; the ring shows where focus is. */
|
|
210
246
|
.sixb-artboard .react-flow__node:focus-visible {
|
|
211
247
|
outline: 2px solid var(--ring);
|
|
@@ -21,6 +21,11 @@ interface EditSession {
|
|
|
21
21
|
/** Whether the reader is editing the version shown. */
|
|
22
22
|
readonly editing: boolean
|
|
23
23
|
readonly report: (draft: ArtifactDraft | null) => void
|
|
24
|
+
/**
|
|
25
|
+
* Starts editing, as the header's Edit does: absent while the reader edits already, or may not
|
|
26
|
+
* change the artifact.
|
|
27
|
+
*/
|
|
28
|
+
readonly start?: (() => void) | undefined
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
const EditSessionContext = createContext<EditSession>({ editing: false, report: () => {} })
|
|
@@ -28,10 +33,11 @@ const EditSessionContext = createContext<EditSession>({ editing: false, report:
|
|
|
28
33
|
export function EditSessionProvider({
|
|
29
34
|
editing,
|
|
30
35
|
report,
|
|
36
|
+
start,
|
|
31
37
|
children,
|
|
32
38
|
}: EditSession & { readonly children: ReactNode }) {
|
|
33
39
|
return (
|
|
34
|
-
<EditSessionContext.Provider value={{ editing, report }}>
|
|
40
|
+
<EditSessionContext.Provider value={{ editing, report, start }}>
|
|
35
41
|
{children}
|
|
36
42
|
</EditSessionContext.Provider>
|
|
37
43
|
)
|
|
@@ -42,6 +48,14 @@ export function useArtifactEditing(): boolean {
|
|
|
42
48
|
return useContext(EditSessionContext).editing
|
|
43
49
|
}
|
|
44
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Starts editing from within the artifact, as the header's Edit does, for a change the reader
|
|
53
|
+
* makes there; null while they edit already, or may not change it.
|
|
54
|
+
*/
|
|
55
|
+
export function useStartEditing(): (() => void) | null {
|
|
56
|
+
return useContext(EditSessionContext).start ?? null
|
|
57
|
+
}
|
|
58
|
+
|
|
45
59
|
/** Tells the viewer what the renderer's draft holds, for the header's Save. */
|
|
46
60
|
export function useReportDraft(draft: ArtifactDraft | null): void {
|
|
47
61
|
const { report } = useContext(EditSessionContext)
|
package/src/artifacts/frame.tsx
CHANGED
|
@@ -308,11 +308,12 @@ export function ArtifactFrame({
|
|
|
308
308
|
}, [artifactTheme, isReady, sendTheme])
|
|
309
309
|
|
|
310
310
|
// A picture of the deck takes no focus, and neither does what it holds: `tabIndex` alone would
|
|
311
|
-
// leave its links in the page's tab order.
|
|
311
|
+
// leave its links in the page's tab order. A canvas's board becomes one, and stops being one,
|
|
312
|
+
// without loading again.
|
|
312
313
|
const attach = useCallback(
|
|
313
314
|
(element: HTMLIFrameElement | null) => {
|
|
314
315
|
iframe.current = element
|
|
315
|
-
if (element
|
|
316
|
+
if (element) element.inert = decorative
|
|
316
317
|
},
|
|
317
318
|
[decorative]
|
|
318
319
|
)
|
|
@@ -230,6 +230,33 @@ export const en = {
|
|
|
230
230
|
previousBoard: "Previous board",
|
|
231
231
|
nextBoard: "Next board",
|
|
232
232
|
boardFailed: "This board's page could not be opened.",
|
|
233
|
+
fitPage: "Fit the whole page",
|
|
234
|
+
size: {
|
|
235
|
+
label: "Size",
|
|
236
|
+
menu: "Page size",
|
|
237
|
+
names: {
|
|
238
|
+
board: "Board size",
|
|
239
|
+
full: "Full page",
|
|
240
|
+
phone: "Phone",
|
|
241
|
+
tablet: "Tablet",
|
|
242
|
+
laptop: "Laptop",
|
|
243
|
+
desktop: "Desktop",
|
|
244
|
+
},
|
|
245
|
+
dimensions: (w: number, h: number) => `${w} × ${h}`,
|
|
246
|
+
dimension: (w?: number, h?: number) =>
|
|
247
|
+
w !== undefined && h !== undefined ? `${w} × ${h}` : String(w ?? h ?? ""),
|
|
248
|
+
measuring: "Measuring…",
|
|
249
|
+
yoursOnly: "Only you see this size.",
|
|
250
|
+
yoursUntilKept: "Only you see this size until you keep it.",
|
|
251
|
+
reset: "Back to board size",
|
|
252
|
+
keep: "Keep this size",
|
|
253
|
+
kept: (w: number, h: number) => `Board is now ${w} × ${h}`,
|
|
254
|
+
resizeWidth: "Page width",
|
|
255
|
+
resizeHeight: "Page height",
|
|
256
|
+
resizeBoth: "Page size",
|
|
257
|
+
bottomHint: "Page height · double-click for the full page",
|
|
258
|
+
suggestions: "Suggested sizes",
|
|
259
|
+
},
|
|
233
260
|
live: {
|
|
234
261
|
agentChanging: "Agent is changing this board",
|
|
235
262
|
},
|
|
@@ -859,6 +886,33 @@ export const fr: Translation<ArtifactMessages> = {
|
|
|
859
886
|
previousBoard: "Planche précédente",
|
|
860
887
|
nextBoard: "Planche suivante",
|
|
861
888
|
boardFailed: "La page de cette planche n’a pas pu s’ouvrir.",
|
|
889
|
+
fitPage: "Afficher toute la page",
|
|
890
|
+
size: {
|
|
891
|
+
label: "Taille",
|
|
892
|
+
menu: "Taille de la page",
|
|
893
|
+
names: {
|
|
894
|
+
board: "Taille de la planche",
|
|
895
|
+
full: "Page entière",
|
|
896
|
+
phone: "Téléphone",
|
|
897
|
+
tablet: "Tablette",
|
|
898
|
+
laptop: "Portable",
|
|
899
|
+
desktop: "Ordinateur",
|
|
900
|
+
},
|
|
901
|
+
dimensions: (w, h) => `${w} × ${h}`,
|
|
902
|
+
dimension: (w, h) =>
|
|
903
|
+
w !== undefined && h !== undefined ? `${w} × ${h}` : String(w ?? h ?? ""),
|
|
904
|
+
measuring: "Mesure…",
|
|
905
|
+
yoursOnly: "Cette taille n’est visible que par vous.",
|
|
906
|
+
yoursUntilKept: "Cette taille n’est visible que par vous, tant que vous ne la gardez pas.",
|
|
907
|
+
reset: "Revenir à la taille de la planche",
|
|
908
|
+
keep: "Garder cette taille",
|
|
909
|
+
kept: (w, h) => `La planche fait maintenant ${w} × ${h}`,
|
|
910
|
+
resizeWidth: "Largeur de la page",
|
|
911
|
+
resizeHeight: "Hauteur de la page",
|
|
912
|
+
resizeBoth: "Taille de la page",
|
|
913
|
+
bottomHint: "Hauteur de la page · double-cliquez pour la page entière",
|
|
914
|
+
suggestions: "Tailles suggérées",
|
|
915
|
+
},
|
|
862
916
|
live: {
|
|
863
917
|
agentChanging: "L’agent modifie cette planche",
|
|
864
918
|
},
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
type CanvasBoard,
|
|
5
5
|
type FrameEditTarget,
|
|
6
6
|
type FrameEvent,
|
|
7
|
+
type FrameZoom,
|
|
7
8
|
parseFrameEvent,
|
|
8
9
|
} from "@sixb/core/artifacts"
|
|
9
10
|
import {
|
|
@@ -51,6 +52,7 @@ import {
|
|
|
51
52
|
type PinPlace,
|
|
52
53
|
pinPoint,
|
|
53
54
|
} from "./comment-pins"
|
|
55
|
+
import type { PageSize } from "./page-size"
|
|
54
56
|
|
|
55
57
|
// A board opened over the canvas, as its page runs in its frame, and what the reader does on it:
|
|
56
58
|
// read it, edit what it shows, or pick what to comment on.
|
|
@@ -63,6 +65,7 @@ import {
|
|
|
63
65
|
//
|
|
64
66
|
// frame ── edit.select ──▶ the element picked, its toolbar (the reader's own click)
|
|
65
67
|
// ── edit.text ───▶ mergeBoardText → the board's Y.Text (only for the element picked)
|
|
68
|
+
// ── zoom ────────▶ the opened board zoomed, not the browser (the reader's own gesture)
|
|
66
69
|
// ◀─ edit.patch ── what the document changed since the frame's version
|
|
67
70
|
|
|
68
71
|
/** What edits a board's elements: the live canvas, under the reader's own undo. */
|
|
@@ -167,12 +170,13 @@ function useBoardFrame({
|
|
|
167
170
|
}
|
|
168
171
|
|
|
169
172
|
/**
|
|
170
|
-
* An opened board at its size on screen: its page in its frame,
|
|
171
|
-
* ready, comments' pins over it, and, editing, the picked element's tools.
|
|
173
|
+
* An opened board at its size on screen: its page in its frame, laid out at `size`, the picture
|
|
174
|
+
* under it until it is ready, comments' pins over it, and, editing, the picked element's tools.
|
|
172
175
|
*/
|
|
173
176
|
export function BoardStage({
|
|
174
177
|
version,
|
|
175
178
|
board,
|
|
179
|
+
size,
|
|
176
180
|
title,
|
|
177
181
|
scale,
|
|
178
182
|
live,
|
|
@@ -188,9 +192,13 @@ export function BoardStage({
|
|
|
188
192
|
onOpenPin,
|
|
189
193
|
onSubmitDraft,
|
|
190
194
|
onCancelDraft,
|
|
195
|
+
onContentHeight,
|
|
196
|
+
onZoom,
|
|
191
197
|
}: {
|
|
192
198
|
readonly version: ArtifactVersion
|
|
193
199
|
readonly board: CanvasBoard
|
|
200
|
+
/** The size the page is laid out at: the board's, or the one the reader chose to see it at. */
|
|
201
|
+
readonly size: PageSize
|
|
194
202
|
readonly title: string
|
|
195
203
|
readonly scale: number
|
|
196
204
|
/** The canvas held live, whose document the board is patched from. */
|
|
@@ -208,6 +216,10 @@ export function BoardStage({
|
|
|
208
216
|
readonly onOpenPin: (id: string) => void
|
|
209
217
|
readonly onSubmitDraft: (body: string) => Promise<void>
|
|
210
218
|
readonly onCancelDraft: () => void
|
|
219
|
+
/** The page's height as laid out at its width, as the frame reports it. */
|
|
220
|
+
readonly onContentHeight?: (height: number) => void
|
|
221
|
+
/** The reader zoomed over the page: the frame passes it on instead of the browser zooming. */
|
|
222
|
+
readonly onZoom?: (zoom: FrameZoom) => void
|
|
211
223
|
}) {
|
|
212
224
|
const messages = useArtifactMessages().canvas
|
|
213
225
|
const frame = useBoardFrame({ version, board, live })
|
|
@@ -252,12 +264,15 @@ export function BoardStage({
|
|
|
252
264
|
// post too.
|
|
253
265
|
const port = useRef<{ readonly mine: MessagePort; handed: MessagePort | null } | null>(null)
|
|
254
266
|
const onEditRef = useRef<(event: FrameEvent) => void>(() => {})
|
|
267
|
+
const onZoomRef = useRef(onZoom)
|
|
268
|
+
onZoomRef.current = onZoom
|
|
255
269
|
useEffect(() => {
|
|
256
270
|
if (frame.loads === 0) return
|
|
257
271
|
const channel = new MessageChannel()
|
|
258
272
|
channel.port1.onmessage = (message: MessageEvent) => {
|
|
259
273
|
const event = parseFrameEvent(message.data)
|
|
260
|
-
if (event?.event
|
|
274
|
+
if (event?.event === "zoom") onZoomRef.current?.(event.params)
|
|
275
|
+
else if (event?.event.startsWith("edit.")) onEditRef.current(event)
|
|
261
276
|
}
|
|
262
277
|
port.current = { mine: channel.port1, handed: channel.port2 }
|
|
263
278
|
return () => channel.port1.close()
|
|
@@ -284,11 +299,11 @@ export function BoardStage({
|
|
|
284
299
|
const x = at?.x ?? rect.x + rect.width
|
|
285
300
|
const y = at?.y ?? rect.y
|
|
286
301
|
return {
|
|
287
|
-
x: Math.min(1, Math.max(0, x /
|
|
288
|
-
y: Math.min(1, Math.max(0, y /
|
|
302
|
+
x: Math.min(1, Math.max(0, x / size.w)),
|
|
303
|
+
y: Math.min(1, Math.max(0, y / size.h)),
|
|
289
304
|
}
|
|
290
305
|
},
|
|
291
|
-
[
|
|
306
|
+
[size.w, size.h]
|
|
292
307
|
)
|
|
293
308
|
|
|
294
309
|
const onEvent = useCallback(
|
|
@@ -301,9 +316,11 @@ export function BoardStage({
|
|
|
301
316
|
frame.ready()
|
|
302
317
|
} else if (event.event === "press") {
|
|
303
318
|
onPress(event.params.text)
|
|
319
|
+
} else if (event.event === "size") {
|
|
320
|
+
onContentHeight?.(event.params.height)
|
|
304
321
|
}
|
|
305
322
|
},
|
|
306
|
-
[frame, onPress]
|
|
323
|
+
[frame, onPress, onContentHeight]
|
|
307
324
|
)
|
|
308
325
|
|
|
309
326
|
onEditRef.current = (event: FrameEvent) => {
|
|
@@ -326,7 +343,7 @@ export function BoardStage({
|
|
|
326
343
|
// The page's body is the whole board, named by its title.
|
|
327
344
|
...(target.address === "body" ? { anchor: title } : {}),
|
|
328
345
|
point: point(at, target.rect),
|
|
329
|
-
under: Math.min(1, (target.rect.y + target.rect.height) /
|
|
346
|
+
under: Math.min(1, (target.rect.y + target.rect.height) / size.h),
|
|
330
347
|
})
|
|
331
348
|
return
|
|
332
349
|
}
|
|
@@ -361,7 +378,7 @@ export function BoardStage({
|
|
|
361
378
|
<div className="absolute inset-0 overflow-hidden rounded-[inherit]">
|
|
362
379
|
<div
|
|
363
380
|
className="absolute top-0 left-0 origin-top-left"
|
|
364
|
-
style={{ width:
|
|
381
|
+
style={{ width: size.w, height: size.h, transform: `scale(${scale})` }}
|
|
365
382
|
>
|
|
366
383
|
<ArtifactFrame
|
|
367
384
|
key={board.id}
|
|
@@ -378,14 +395,15 @@ export function BoardStage({
|
|
|
378
395
|
</div>
|
|
379
396
|
</div>
|
|
380
397
|
|
|
381
|
-
|
|
398
|
+
{/* Over the page's resize handles: a pin at the page's edge stays pressable. */}
|
|
399
|
+
<div className="pointer-events-none absolute inset-0 z-10" data-board-overlay="">
|
|
382
400
|
{pins.map((pin, index) => {
|
|
383
401
|
const at = pinPoint(pin, pin.point ? 0 : index)
|
|
384
402
|
return (
|
|
385
403
|
<div
|
|
386
404
|
key={pin.id}
|
|
387
405
|
className="absolute"
|
|
388
|
-
style={{ left: at.x *
|
|
406
|
+
style={{ left: at.x * size.w * scale, top: at.y * size.h * scale }}
|
|
389
407
|
>
|
|
390
408
|
<CommentPin
|
|
391
409
|
number={pin.number}
|
|
@@ -403,13 +421,13 @@ export function BoardStage({
|
|
|
403
421
|
{draft ? (
|
|
404
422
|
<div
|
|
405
423
|
className="absolute"
|
|
406
|
-
style={{ left: draft.point.x *
|
|
424
|
+
style={{ left: draft.point.x * size.w * scale, top: draft.point.y * size.h * scale }}
|
|
407
425
|
>
|
|
408
426
|
<CommentPin label={messages.comments.newPin} active resolved={false} draft />
|
|
409
427
|
<div
|
|
410
428
|
className={cn("absolute", draftAbove(draft) ? "bottom-9" : null)}
|
|
411
429
|
style={{
|
|
412
|
-
...cardPlace(draft.point.x *
|
|
430
|
+
...cardPlace(draft.point.x * size.w * scale, size.w * scale),
|
|
413
431
|
// Under what it is about, so the words it points at stay in view.
|
|
414
432
|
...(draftAbove(draft)
|
|
415
433
|
? {}
|
|
@@ -417,7 +435,7 @@ export function BoardStage({
|
|
|
417
435
|
top:
|
|
418
436
|
Math.max(
|
|
419
437
|
0,
|
|
420
|
-
((draft.under ?? draft.point.y) - draft.point.y) *
|
|
438
|
+
((draft.under ?? draft.point.y) - draft.point.y) * size.h * scale
|
|
421
439
|
) + 10,
|
|
422
440
|
}),
|
|
423
441
|
}}
|
|
@@ -436,6 +454,7 @@ export function BoardStage({
|
|
|
436
454
|
key={selected.address ?? "scripted"}
|
|
437
455
|
target={selected}
|
|
438
456
|
scale={scale}
|
|
457
|
+
width={size.w}
|
|
439
458
|
board={board}
|
|
440
459
|
version={version}
|
|
441
460
|
live={live}
|
|
@@ -514,6 +533,7 @@ function HoverTag({ target, scale }: { readonly target: FrameEditTarget; readonl
|
|
|
514
533
|
function ElementTools({
|
|
515
534
|
target,
|
|
516
535
|
scale,
|
|
536
|
+
width: pageWidth,
|
|
517
537
|
board,
|
|
518
538
|
version,
|
|
519
539
|
live,
|
|
@@ -524,6 +544,8 @@ function ElementTools({
|
|
|
524
544
|
}: {
|
|
525
545
|
readonly target: FrameEditTarget
|
|
526
546
|
readonly scale: number
|
|
547
|
+
/** The page's width as laid out. */
|
|
548
|
+
readonly width: number
|
|
527
549
|
readonly board: CanvasBoard
|
|
528
550
|
readonly version: ArtifactVersion
|
|
529
551
|
readonly live: LiveArtifact | null
|
|
@@ -542,7 +564,7 @@ function ElementTools({
|
|
|
542
564
|
useLayoutEffect(() => {
|
|
543
565
|
setWidth(toolbar.current?.offsetWidth ?? 0)
|
|
544
566
|
})
|
|
545
|
-
const left = Math.max(4, Math.min(rect.x * scale,
|
|
567
|
+
const left = Math.max(4, Math.min(rect.x * scale, pageWidth * scale - width - 4))
|
|
546
568
|
const above = rect.y * scale >= 44
|
|
547
569
|
const top = above ? rect.y * scale - 40 : (rect.y + rect.height) * scale + 8
|
|
548
570
|
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { CANVAS_FILE } from "@sixb/core/artifacts"
|
|
1
|
+
import { CANVAS_FILE, parseFrameEvent } from "@sixb/core/artifacts"
|
|
2
2
|
import { cn } from "@sixb/ui/lib/utils"
|
|
3
3
|
import { useStoreApi } from "@xyflow/react"
|
|
4
4
|
import type { LucideIcon } from "lucide-react"
|
|
5
5
|
import {
|
|
6
6
|
createContext,
|
|
7
7
|
type ReactNode,
|
|
8
|
+
type RefObject,
|
|
8
9
|
useContext,
|
|
9
10
|
useEffect,
|
|
10
11
|
useRef,
|
|
11
12
|
useState,
|
|
12
13
|
useSyncExternalStore,
|
|
13
14
|
} from "react"
|
|
14
|
-
import { ArtifactFrame } from "../../frame"
|
|
15
|
+
import { ArtifactFrame, type ArtifactFrameHandle } from "../../frame"
|
|
15
16
|
import type { ArtifactVersion } from "../../queries"
|
|
17
|
+
import type { BoardGestures } from "./gestures"
|
|
16
18
|
import type { BoardPreviews } from "./previews"
|
|
17
19
|
|
|
18
20
|
/** The most boards and embeds live at once: each board is a page running in its own frame. */
|
|
@@ -157,6 +159,13 @@ interface LiveBoards {
|
|
|
157
159
|
readonly mode: "light" | "dark"
|
|
158
160
|
/** Opens a board over the canvas. */
|
|
159
161
|
readonly open?: (id: string) => void
|
|
162
|
+
/**
|
|
163
|
+
* Whether the reader uses the running boards' pages in place: while they read the canvas, not
|
|
164
|
+
* while they edit it or place a comment.
|
|
165
|
+
*/
|
|
166
|
+
readonly interactive?: boolean
|
|
167
|
+
/** What the canvas does with what a running board's page hands it. */
|
|
168
|
+
readonly gestures?: BoardGestures | null
|
|
160
169
|
}
|
|
161
170
|
|
|
162
171
|
const LiveBoardsContext = createContext<LiveBoards>({
|
|
@@ -340,8 +349,12 @@ function usePagesVersion(version: ArtifactVersion | null): ArtifactVersion | nul
|
|
|
340
349
|
* A board's page, running, when the view shows it large enough, over its tile: the tile stays
|
|
341
350
|
* under the frame while it fades in, once its page is ready, so a board never flashes blank as it
|
|
342
351
|
* starts or stops; then the tile goes, so nothing of it shows through a page drawn on the board's
|
|
343
|
-
* own surface.
|
|
344
|
-
*
|
|
352
|
+
* own surface.
|
|
353
|
+
*
|
|
354
|
+
* While the reader reads the canvas, a running page is theirs to use in place: its clicks, keys,
|
|
355
|
+
* text and cursor are its own, and its frame hands the canvas what moves it, as `gestures.ts`
|
|
356
|
+
* says. Editing the canvas or placing a comment, or until it runs, it takes no clicks: a drag
|
|
357
|
+
* across it pans, as across its picture.
|
|
345
358
|
*/
|
|
346
359
|
export function LiveBoard({
|
|
347
360
|
id,
|
|
@@ -354,15 +367,28 @@ export function LiveBoard({
|
|
|
354
367
|
readonly title: string
|
|
355
368
|
readonly tile: ReactNode
|
|
356
369
|
}) {
|
|
357
|
-
const { version } = useContext(LiveBoardsContext)
|
|
370
|
+
const { version, interactive = false, gestures = null } = useContext(LiveBoardsContext)
|
|
358
371
|
const live = useLive(id)
|
|
359
372
|
const pages = usePagesVersion(version)
|
|
360
373
|
// The pages whose frame said it is ready: a frame that runs other pages, or stops, shows the
|
|
361
374
|
// tile again until it is.
|
|
362
375
|
const [ready, setReady] = useState<ArtifactVersion | null>(null)
|
|
363
376
|
const running = live && pages !== null && ready === pages
|
|
377
|
+
const usable = running && interactive
|
|
378
|
+
|
|
379
|
+
const page = useRef<HTMLDivElement | null>(null)
|
|
380
|
+
const handle = useRef<ArtifactFrameHandle | null>(null)
|
|
381
|
+
/** Each load the frame said it is ready, for its port to be handed over again. */
|
|
382
|
+
const [loads, setLoads] = useState(0)
|
|
383
|
+
useCanvasPort(id, gestures, handle, loads, page)
|
|
384
|
+
|
|
364
385
|
return (
|
|
365
|
-
<div
|
|
386
|
+
<div
|
|
387
|
+
ref={page}
|
|
388
|
+
className="group/board relative size-full"
|
|
389
|
+
data-running={running ? "" : undefined}
|
|
390
|
+
data-interactive={usable ? "" : undefined}
|
|
391
|
+
>
|
|
366
392
|
{/* Gone once the frame has faded in over it: as long as the fade, then not drawn at all. */}
|
|
367
393
|
<div className="size-full transition-[visibility] delay-300 group-data-[running]/board:invisible">
|
|
368
394
|
{tile}
|
|
@@ -372,13 +398,49 @@ export function LiveBoard({
|
|
|
372
398
|
version={pages}
|
|
373
399
|
entry={file}
|
|
374
400
|
title={title}
|
|
375
|
-
decorative
|
|
401
|
+
decorative={!usable}
|
|
402
|
+
handle={handle}
|
|
376
403
|
className="absolute inset-0 overflow-hidden rounded-[10px]"
|
|
377
404
|
onEvent={(event) => {
|
|
378
|
-
if (event.event
|
|
405
|
+
if (event.event !== "ready") return
|
|
406
|
+
setReady(pages)
|
|
407
|
+
setLoads((count) => count + 1)
|
|
379
408
|
}}
|
|
380
409
|
/>
|
|
381
410
|
) : null}
|
|
382
411
|
</div>
|
|
383
412
|
)
|
|
384
413
|
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Each load of a running board's frame, a port of its own, handed over with its first `canvas`
|
|
417
|
+
* request: what moves the canvas comes through it alone, never through the window, where the
|
|
418
|
+
* page's scripts post too. The frame hears from then on whether the canvas pans by the wheel.
|
|
419
|
+
*/
|
|
420
|
+
function useCanvasPort(
|
|
421
|
+
id: string,
|
|
422
|
+
gestures: BoardGestures | null,
|
|
423
|
+
handle: RefObject<ArtifactFrameHandle | null>,
|
|
424
|
+
loads: number,
|
|
425
|
+
page: RefObject<HTMLElement | null>
|
|
426
|
+
): void {
|
|
427
|
+
useEffect(() => {
|
|
428
|
+
if (loads === 0 || !gestures) return
|
|
429
|
+
|
|
430
|
+
const channel = new MessageChannel()
|
|
431
|
+
channel.port1.onmessage = (message: MessageEvent) => {
|
|
432
|
+
const event = parseFrameEvent(message.data)
|
|
433
|
+
if (event) gestures.receive(id, event, page.current)
|
|
434
|
+
}
|
|
435
|
+
const tell = (moving: boolean, transfer: Transferable[] = []) => {
|
|
436
|
+
handle.current?.send("canvas", { moving }, transfer).catch(() => {})
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
tell(gestures.moving(), [channel.port2])
|
|
440
|
+
const stop = gestures.onMoving((moving) => tell(moving))
|
|
441
|
+
return () => {
|
|
442
|
+
stop()
|
|
443
|
+
channel.port1.close()
|
|
444
|
+
}
|
|
445
|
+
}, [id, gestures, handle, loads, page])
|
|
446
|
+
}
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
useRef,
|
|
27
27
|
useState,
|
|
28
28
|
} from "react"
|
|
29
|
+
import { useStartEditing } from "../../edit-session"
|
|
29
30
|
import type { LiveArtifact } from "../../live/session"
|
|
30
31
|
import { useArtifactMessages } from "../../messages"
|
|
31
32
|
import type { ArtifactVersion } from "../../queries"
|
|
@@ -38,18 +39,21 @@ import { CanvasCommentPins } from "./comment-pins"
|
|
|
38
39
|
import { CommentModeHint, CommentTools, useCanvasCommenting } from "./commenting"
|
|
39
40
|
import { CommentsPanel } from "./comments-panel"
|
|
40
41
|
import { CanvasControls } from "./controls"
|
|
42
|
+
import type { Box } from "./draft"
|
|
41
43
|
import { type CanvasEditor, useBoardEditing } from "./edit-mode"
|
|
42
|
-
import { CanvasEditingProvider } from "./editing"
|
|
43
|
-
import { BoardFocus } from "./focus"
|
|
44
|
+
import { CanvasEditingProvider, type CanvasItemEditing } from "./editing"
|
|
45
|
+
import { BoardFocus, followedArrow } from "./focus"
|
|
46
|
+
import { useBoardGestures } from "./gestures"
|
|
44
47
|
import { CANVAS_NODE_TYPES, NAME_SCALE, zoomMarks } from "./items"
|
|
45
48
|
import { PresenceLayer } from "./presence"
|
|
46
49
|
import { boardPreviewUrl, useBoardPreviews } from "./previews"
|
|
47
50
|
|
|
48
51
|
/**
|
|
49
52
|
* A canvas on an endless board: drag or scroll to pan, pinch or ⌘-scroll to zoom, the zoom
|
|
50
|
-
* controls in a corner. Boards and embeds run live once the view shows them large enough
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
+
* controls in a corner. Boards and embeds run live once the view shows them large enough, and a
|
|
54
|
+
* running board's page is the reader's to use in place while they read; double-click a board,
|
|
55
|
+
* press Enter on it, or press its Open to open it over the canvas. It opens on the item an
|
|
56
|
+
* address named, else fitted to everything. Given an editor, its items are
|
|
53
57
|
* selected, moved, resized, connected, and typed into, with a toolbar to add more.
|
|
54
58
|
*/
|
|
55
59
|
export default memo(function CanvasBoard({
|
|
@@ -157,16 +161,6 @@ function Board({
|
|
|
157
161
|
|
|
158
162
|
void fitView({ nodes: [{ id }], padding: CANVAS_FIT_PADDING, maxZoom: 1, duration: 220 })
|
|
159
163
|
}, [opened, fitView])
|
|
160
|
-
const live = useMemo(
|
|
161
|
-
() => ({
|
|
162
|
-
version: version ?? null,
|
|
163
|
-
live: running,
|
|
164
|
-
previews,
|
|
165
|
-
mode,
|
|
166
|
-
...(version ? { open: setOpened } : {}),
|
|
167
|
-
}),
|
|
168
|
-
[version, running, previews, mode]
|
|
169
|
-
)
|
|
170
164
|
// An opened board's picture, at its own size, under its page until the page is ready.
|
|
171
165
|
const pictureOf = useCallback(
|
|
172
166
|
(id: string) =>
|
|
@@ -175,6 +169,7 @@ function Board({
|
|
|
175
169
|
)
|
|
176
170
|
|
|
177
171
|
const board = useBoardEditing(canvas, edit, version ? setOpened : undefined)
|
|
172
|
+
const resizeBoard = useResizeBoard(board.editing ? board.items : null)
|
|
178
173
|
// What edits a board's elements in place: the live canvas, while the reader edits it.
|
|
179
174
|
const editBoard = edit?.live?.editBoard
|
|
180
175
|
const stopCapturing = edit?.live?.stopCapturing
|
|
@@ -275,6 +270,36 @@ function Board({
|
|
|
275
270
|
[commenting, boards, opened, fitView]
|
|
276
271
|
)
|
|
277
272
|
|
|
273
|
+
// Read, the running boards' pages are the reader's to use in place, and a button or a link in one
|
|
274
|
+
// that reads as the label of an arrow leaving it glides the canvas to the board it points to.
|
|
275
|
+
const reads = !board.editing && !commenting.commenting && opened === null
|
|
276
|
+
const follow = useRef<(from: string, text: string) => void>(() => {})
|
|
277
|
+
const gestures = useBoardGestures({
|
|
278
|
+
root: board.root,
|
|
279
|
+
pointed,
|
|
280
|
+
reading: reads,
|
|
281
|
+
opened: opened !== null,
|
|
282
|
+
padding: CANVAS_FIT_PADDING,
|
|
283
|
+
onPress: (from, text) => follow.current(from, text),
|
|
284
|
+
})
|
|
285
|
+
follow.current = (from, text) => {
|
|
286
|
+
const to = followedArrow(arrows, boards, from, text)
|
|
287
|
+
const target = boards.find((each) => each.id === to)
|
|
288
|
+
if (target) gestures.glide(target)
|
|
289
|
+
}
|
|
290
|
+
const live = useMemo(
|
|
291
|
+
() => ({
|
|
292
|
+
version: version ?? null,
|
|
293
|
+
live: running,
|
|
294
|
+
previews,
|
|
295
|
+
mode,
|
|
296
|
+
interactive: reads && version !== undefined,
|
|
297
|
+
gestures,
|
|
298
|
+
...(version ? { open: setOpened } : {}),
|
|
299
|
+
}),
|
|
300
|
+
[version, running, previews, mode, reads, gestures]
|
|
301
|
+
)
|
|
302
|
+
|
|
278
303
|
// Read, the board's handlers stay the same from one draw to the next, so React Flow doesn't
|
|
279
304
|
// draw every item again when the board does.
|
|
280
305
|
const open = live.open
|
|
@@ -416,6 +441,8 @@ function Board({
|
|
|
416
441
|
live={liveArtifact ?? null}
|
|
417
442
|
canvas={boardEditor}
|
|
418
443
|
mode={commenting.commenting ? "comment" : boardEditor ? "edit" : "read"}
|
|
444
|
+
// Keep this size resizes the board as its handles on the canvas do.
|
|
445
|
+
{...(resizeBoard ? { onResizeBoard: resizeBoard } : {})}
|
|
419
446
|
{...(commenting.enabled
|
|
420
447
|
? {
|
|
421
448
|
pins: commenting.pins,
|
|
@@ -468,6 +495,30 @@ function Board({
|
|
|
468
495
|
)
|
|
469
496
|
}
|
|
470
497
|
|
|
498
|
+
/**
|
|
499
|
+
* Keep this size: a board resized as its handles on the canvas resize it, while the canvas is
|
|
500
|
+
* edited. Outside editing, for whoever may change the canvas, it starts editing and resizes the
|
|
501
|
+
* board once editing is on, as if they had resized it there: the header's Undo takes it back.
|
|
502
|
+
* Null for whoever may not change the canvas.
|
|
503
|
+
*/
|
|
504
|
+
function useResizeBoard(items: CanvasItemEditing | null): ((id: string, box: Box) => void) | null {
|
|
505
|
+
const start = useStartEditing()
|
|
506
|
+
const [waiting, setWaiting] = useState<{ readonly id: string; readonly box: Box } | null>(null)
|
|
507
|
+
|
|
508
|
+
useEffect(() => {
|
|
509
|
+
if (!waiting || !items) return
|
|
510
|
+
items.resize(waiting.id, waiting.box)
|
|
511
|
+
setWaiting(null)
|
|
512
|
+
}, [waiting, items])
|
|
513
|
+
|
|
514
|
+
if (items) return items.resize
|
|
515
|
+
if (!start) return null
|
|
516
|
+
return (id, box) => {
|
|
517
|
+
setWaiting({ id, box })
|
|
518
|
+
start()
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
471
522
|
/** What belongs to the comments: their panel, their pins, and a board's element tools. */
|
|
472
523
|
const COMMENTS = "[data-comments-panel], [data-comment-pin], [data-board-tools]"
|
|
473
524
|
|