@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
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import type { FrameEvent, FramePan, FramePoint, FrameZoomStep } from "@sixb/core/artifacts"
|
|
2
|
+
import { useReactFlow, useStoreApi } from "@xyflow/react"
|
|
3
|
+
import { type RefObject, useEffect, useMemo, useRef } from "react"
|
|
4
|
+
import { LIVE_FROM_SCALE } from "./board"
|
|
5
|
+
import type { Box } from "./draft"
|
|
6
|
+
import { zoomKey } from "./focus"
|
|
7
|
+
|
|
8
|
+
// A board running on the canvas is a page the reader uses in place, in read mode. Its frame takes
|
|
9
|
+
// the reader's clicks, keys and text, and hands the canvas, through the port each load is given,
|
|
10
|
+
// what moves it:
|
|
11
|
+
//
|
|
12
|
+
// frame ── pan ────▶ the canvas pans: the wheel unless the page scrolls it, or a finger's drag
|
|
13
|
+
// ── zoom ───▶ the canvas zooms around the pointer, or by a step
|
|
14
|
+
// ── space ──▶ Space held: a drag anywhere pans, the boards' pages let it through
|
|
15
|
+
// ── press ──▶ the canvas glides to the board an arrow with those words leads to
|
|
16
|
+
// ◀─ canvas ── whether the canvas is panning by the wheel, so a page coming under a still
|
|
17
|
+
// pointer keeps panning it instead of scrolling itself
|
|
18
|
+
|
|
19
|
+
/** How far a wheel's turn pans the canvas over a board, as React Flow's `panOnScrollSpeed` does. */
|
|
20
|
+
const WHEEL_PAN_SPEED = 0.5
|
|
21
|
+
|
|
22
|
+
/** How long after its last wheel turn the canvas still pans: React Flow's own pause. */
|
|
23
|
+
const WHEEL_PAUSE_MS = 150
|
|
24
|
+
|
|
25
|
+
/** How long the canvas takes to glide to the board an arrow leads to. */
|
|
26
|
+
const GLIDE_MS = 420
|
|
27
|
+
|
|
28
|
+
/** How long a zoom step takes, as the zoom bar's. */
|
|
29
|
+
const STEP_MS = 220
|
|
30
|
+
|
|
31
|
+
/** What a glide leaves above and beside a board too large for the view. */
|
|
32
|
+
const GLIDE_MARGIN = 32
|
|
33
|
+
|
|
34
|
+
/** What takes Space itself in the app: a field types it, a control presses. */
|
|
35
|
+
const KEYED = "input, textarea, select, button, a[href], [contenteditable], [role=menu]"
|
|
36
|
+
|
|
37
|
+
/** What the canvas does with what its running boards hand it. */
|
|
38
|
+
export interface BoardGestures {
|
|
39
|
+
/** Whether the canvas is panning by the wheel now. */
|
|
40
|
+
readonly moving: () => boolean
|
|
41
|
+
/** Tells `listener` each time the canvas starts or stops panning by the wheel. */
|
|
42
|
+
readonly onMoving: (listener: (moving: boolean) => void) => () => void
|
|
43
|
+
/** What `board`'s frame sent through its port; `page` is where its page is drawn. */
|
|
44
|
+
readonly receive: (board: string, event: FrameEvent, page: Element | null) => void
|
|
45
|
+
/** Glides the canvas to show `box`, as a press on an arrow's label does. */
|
|
46
|
+
readonly glide: (box: Box) => void
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Where the view goes to show `box` in a `view` this large, from `zoom`: centered, never closer
|
|
51
|
+
* than the reader is, and further only as far as it takes to fit, though never so far the board
|
|
52
|
+
* stops running, unless the reader is further already. A board still too large starts at the
|
|
53
|
+
* view's top left, as a page is read.
|
|
54
|
+
*/
|
|
55
|
+
export function glideView(
|
|
56
|
+
box: Box,
|
|
57
|
+
view: { readonly width: number; readonly height: number },
|
|
58
|
+
zoom: number,
|
|
59
|
+
padding: number
|
|
60
|
+
): { readonly x: number; readonly y: number; readonly zoom: number } {
|
|
61
|
+
const fit = Math.min(view.width / (box.w * (1 + padding)), view.height / (box.h * (1 + padding)))
|
|
62
|
+
const next = Math.min(zoom, Math.max(fit, Math.min(zoom, LIVE_FROM_SCALE)))
|
|
63
|
+
|
|
64
|
+
const width = box.w * next
|
|
65
|
+
const height = box.h * next
|
|
66
|
+
const left = width <= view.width ? (view.width - width) / 2 : GLIDE_MARGIN
|
|
67
|
+
const top = height <= view.height ? (view.height - height) / 2 : GLIDE_MARGIN
|
|
68
|
+
return { x: left - box.x * next, y: top - box.y * next, zoom: next }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The canvas's side of its running boards' gestures, and of its own keys while it is read: Space
|
|
73
|
+
* held over it lets a drag pan across the boards' pages, and ⌘ +, − and 0 zoom it, never the
|
|
74
|
+
* browser, while it has the pointer or the focus and no board is opened.
|
|
75
|
+
*/
|
|
76
|
+
export function useBoardGestures({
|
|
77
|
+
root,
|
|
78
|
+
pointed,
|
|
79
|
+
reading,
|
|
80
|
+
opened,
|
|
81
|
+
padding,
|
|
82
|
+
onPress,
|
|
83
|
+
}: {
|
|
84
|
+
readonly root: RefObject<HTMLElement | null>
|
|
85
|
+
/** Whether the pointer is over the canvas. */
|
|
86
|
+
readonly pointed: RefObject<boolean>
|
|
87
|
+
/** Whether the reader reads the canvas: neither editing it nor placing a comment. */
|
|
88
|
+
readonly reading: boolean
|
|
89
|
+
/** Whether a board is opened over the canvas, which takes the keys itself. */
|
|
90
|
+
readonly opened: boolean
|
|
91
|
+
readonly padding: number
|
|
92
|
+
/** The reader pressed `text` in `board`'s page. */
|
|
93
|
+
readonly onPress: (board: string, text: string) => void
|
|
94
|
+
}): BoardGestures {
|
|
95
|
+
const store = useStoreApi()
|
|
96
|
+
const { setViewport, zoomIn, zoomOut, zoomTo } = useReactFlow()
|
|
97
|
+
const pressRef = useRef(onPress)
|
|
98
|
+
pressRef.current = onPress
|
|
99
|
+
|
|
100
|
+
const gestures = useMemo(() => {
|
|
101
|
+
let moving = false
|
|
102
|
+
let pause: ReturnType<typeof setTimeout> | undefined
|
|
103
|
+
const listeners = new Set<(moving: boolean) => void>()
|
|
104
|
+
const tell = (next: boolean) => {
|
|
105
|
+
if (moving === next) return
|
|
106
|
+
moving = next
|
|
107
|
+
for (const listener of listeners) listener(next)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The canvas panned by the wheel: it is panning until the wheel pauses. */
|
|
111
|
+
const wheeled = () => {
|
|
112
|
+
tell(true)
|
|
113
|
+
clearTimeout(pause)
|
|
114
|
+
pause = setTimeout(() => tell(false), WHEEL_PAUSE_MS)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const view = () => {
|
|
118
|
+
const [x, y, zoom] = store.getState().transform
|
|
119
|
+
return { x, y, zoom }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Zooms by `factor` around a point on screen, which stays where it is. */
|
|
123
|
+
const zoomAround = (factor: number, at: FramePoint) => {
|
|
124
|
+
const { minZoom, maxZoom, domNode } = store.getState()
|
|
125
|
+
const bounds = domNode?.getBoundingClientRect()
|
|
126
|
+
if (!bounds) return
|
|
127
|
+
|
|
128
|
+
const { x, y, zoom } = view()
|
|
129
|
+
const next = Math.min(maxZoom, Math.max(minZoom, zoom * factor))
|
|
130
|
+
const left = at.x - bounds.left
|
|
131
|
+
const top = at.y - bounds.top
|
|
132
|
+
void setViewport({
|
|
133
|
+
x: left - ((left - x) * next) / zoom,
|
|
134
|
+
y: top - ((top - y) * next) / zoom,
|
|
135
|
+
zoom: next,
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const pan = ({ x: right, y: down, by }: FramePan) => {
|
|
140
|
+
const speed = by === "wheel" ? WHEEL_PAN_SPEED : 1
|
|
141
|
+
const { x, y, zoom } = view()
|
|
142
|
+
void setViewport({ x: x - right * speed, y: y - down * speed, zoom })
|
|
143
|
+
if (by === "wheel") wheeled()
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const step = (to: FrameZoomStep) => {
|
|
147
|
+
if (to === "in") void zoomIn({ duration: STEP_MS })
|
|
148
|
+
else if (to === "out") void zoomOut({ duration: STEP_MS })
|
|
149
|
+
else void zoomTo(1, { duration: STEP_MS })
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** While Space is held, a drag across a board's page pans, as anywhere on the canvas. */
|
|
153
|
+
const hold = (down: boolean) => {
|
|
154
|
+
root.current?.toggleAttribute("data-panning", down)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
wheeled,
|
|
159
|
+
step,
|
|
160
|
+
hold,
|
|
161
|
+
moving: () => moving,
|
|
162
|
+
onMoving: (listener: (moving: boolean) => void) => {
|
|
163
|
+
listeners.add(listener)
|
|
164
|
+
return () => {
|
|
165
|
+
listeners.delete(listener)
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
receive: (board: string, event: FrameEvent, page: Element | null) => {
|
|
169
|
+
switch (event.event) {
|
|
170
|
+
case "zoom": {
|
|
171
|
+
if ("step" in event.params) {
|
|
172
|
+
step(event.params.step)
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
// The frame's pixels are the canvas's, drawn at its zoom.
|
|
176
|
+
const bounds = page?.getBoundingClientRect()
|
|
177
|
+
if (!bounds) return
|
|
178
|
+
const { zoom } = view()
|
|
179
|
+
const { factor, at } = event.params
|
|
180
|
+
zoomAround(factor, { x: bounds.left + at.x * zoom, y: bounds.top + at.y * zoom })
|
|
181
|
+
return
|
|
182
|
+
}
|
|
183
|
+
case "pan":
|
|
184
|
+
pan(event.params)
|
|
185
|
+
return
|
|
186
|
+
case "space":
|
|
187
|
+
hold(event.params.down)
|
|
188
|
+
return
|
|
189
|
+
case "press":
|
|
190
|
+
pressRef.current(board, event.params.text)
|
|
191
|
+
return
|
|
192
|
+
default:
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
glide: (box: Box) => {
|
|
197
|
+
const { width, height } = store.getState()
|
|
198
|
+
const still = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false
|
|
199
|
+
void setViewport(glideView(box, { width, height }, view().zoom, padding), {
|
|
200
|
+
duration: still ? 0 : GLIDE_MS,
|
|
201
|
+
})
|
|
202
|
+
},
|
|
203
|
+
stop: () => {
|
|
204
|
+
clearTimeout(pause)
|
|
205
|
+
tell(false)
|
|
206
|
+
},
|
|
207
|
+
}
|
|
208
|
+
}, [store, setViewport, zoomIn, zoomOut, zoomTo, root, padding])
|
|
209
|
+
|
|
210
|
+
useEffect(() => gestures.stop, [gestures])
|
|
211
|
+
|
|
212
|
+
// A wheel turned over the canvas itself pans it: a board coming under the pointer goes on
|
|
213
|
+
// panning it.
|
|
214
|
+
useEffect(() => {
|
|
215
|
+
const here = root.current
|
|
216
|
+
if (!here) return
|
|
217
|
+
|
|
218
|
+
const onWheel = (event: WheelEvent) => {
|
|
219
|
+
if (event.target instanceof Element && event.target.closest(".react-flow")) gestures.wheeled()
|
|
220
|
+
}
|
|
221
|
+
here.addEventListener("wheel", onWheel, { capture: true, passive: true })
|
|
222
|
+
return () => here.removeEventListener("wheel", onWheel, { capture: true })
|
|
223
|
+
}, [root, gestures])
|
|
224
|
+
|
|
225
|
+
// The canvas's own keys, while it has the pointer or the focus: a board's page sends its own
|
|
226
|
+
// through the port.
|
|
227
|
+
useEffect(() => {
|
|
228
|
+
if (opened) return
|
|
229
|
+
|
|
230
|
+
const here = () => {
|
|
231
|
+
const canvas = root.current
|
|
232
|
+
return canvas !== null && (pointed.current || canvas.contains(document.activeElement))
|
|
233
|
+
}
|
|
234
|
+
const onKey = (event: KeyboardEvent) => {
|
|
235
|
+
if (event.metaKey || event.ctrlKey) {
|
|
236
|
+
const to = event.type === "keydown" ? zoomKey(event) : null
|
|
237
|
+
if (!to || !here()) return
|
|
238
|
+
event.preventDefault()
|
|
239
|
+
gestures.step(to)
|
|
240
|
+
return
|
|
241
|
+
}
|
|
242
|
+
if (!reading || event.key !== " " || event.altKey) return
|
|
243
|
+
|
|
244
|
+
const down = event.type === "keydown"
|
|
245
|
+
if (down) {
|
|
246
|
+
if (!here() || (event.target instanceof Element && event.target.closest(KEYED))) return
|
|
247
|
+
event.preventDefault()
|
|
248
|
+
}
|
|
249
|
+
gestures.hold(down)
|
|
250
|
+
}
|
|
251
|
+
const release = () => gestures.hold(false)
|
|
252
|
+
|
|
253
|
+
window.addEventListener("keydown", onKey)
|
|
254
|
+
window.addEventListener("keyup", onKey)
|
|
255
|
+
window.addEventListener("blur", release)
|
|
256
|
+
return () => {
|
|
257
|
+
window.removeEventListener("keydown", onKey)
|
|
258
|
+
window.removeEventListener("keyup", onKey)
|
|
259
|
+
window.removeEventListener("blur", release)
|
|
260
|
+
release()
|
|
261
|
+
}
|
|
262
|
+
}, [opened, reading, root, pointed, gestures])
|
|
263
|
+
|
|
264
|
+
return gestures
|
|
265
|
+
}
|