@marver-design/marver 0.27.0 → 0.28.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 +195 -0
- package/README.md +9 -4
- package/dist/{anchor-check-ChdDqL5z.mjs → anchor-check-PHUOFj1N.mjs} +1 -1
- package/dist/{audio-Dw1lfMdb.mjs → audio-DX4POHAj.mjs} +39 -4
- package/dist/{board-tree-DRioF94d.mjs → board-tree-BXR8dw4b.mjs} +3 -1
- package/dist/{boards-DlTcpF47.mjs → boards-BeWtjGUM.mjs} +50 -5
- package/dist/boards-EH2onUXM.mjs +995 -0
- package/dist/{build-DZnFysGU.mjs → build-BsAyLMT1.mjs} +9 -22
- package/dist/{capture-vadKjuCo.mjs → capture-DdZ6xgoz.mjs} +92 -30
- package/dist/cli.mjs +56 -21
- package/dist/{collab-Dxg2trOK.mjs → collab-BEAcXrBb.mjs} +1 -1
- package/dist/{comments-DxOkCSNE.mjs → comments-CrBHPEQl.mjs} +4 -4
- package/dist/config-BezZTiov.mjs +182 -0
- package/dist/conn-BMiHS42T.mjs +222 -0
- package/dist/connectors-MR9d-EBP.mjs +290 -0
- package/dist/{context-HQ4Giw58.mjs → context-BUnFiyA3.mjs} +3 -3
- package/dist/{daemon-BSA0lV8d.mjs → daemon-C5dg2R-V.mjs} +2188 -183
- package/dist/{dev-eQJhWsqg.mjs → dev-D7YS7iT2.mjs} +25 -14
- package/dist/{init-COD0x48i.mjs → init-WE5lQkQL.mjs} +8 -3
- package/dist/jam-Cj5gBvwD.mjs +373 -0
- package/dist/{link-DDXZVGtv.mjs → link-BFFRgrMt.mjs} +4 -4
- package/dist/listener-DdLEM79A.mjs +80 -0
- package/dist/{ls-D7O1G505.mjs → ls-BZ5TAtd5.mjs} +1 -1
- package/dist/{manifest-Nl3KSVOk.mjs → manifest-DPZ3WNg_.mjs} +2 -2
- package/dist/{marks-CWM3WJjc.mjs → marks-Dyn6tmjp.mjs} +3 -3
- package/dist/{marks-CKgzucHZ.mjs → marks-Kmdab_5w.mjs} +3 -3
- package/dist/{marver-id-gate-BjF6v4bT.mjs → marver-id-gate-D-R0hSt_.mjs} +1 -1
- package/dist/perf-Cn5LiRaY.mjs +1319 -0
- package/dist/perf-jam-QxD_UnzN.mjs +635 -0
- package/dist/permit-DDa6wqOs.mjs +187 -0
- package/dist/plugin-C_0yb-Fq.mjs +5089 -0
- package/dist/{poster-Bx83ZYVK.mjs → poster-DHi6I1fO.mjs} +1 -1
- package/dist/{profile-Bh5Y5zpW.mjs → profile-jIS6BcAs.mjs} +1 -1
- package/dist/{publish-bakes-aljgm45S.mjs → publish-bakes-r4PEZuPl.mjs} +3 -3
- package/dist/{queue-CAM_vNmX.mjs → queue-c-6aTHEz.mjs} +164 -25
- package/dist/{recover-t9Pno3u9.mjs → recover-nrLEVLyJ.mjs} +2 -2
- package/dist/{serve-C8rVheYk.mjs → serve-Dp3nHstu.mjs} +3 -3
- package/dist/{session-BAaJsK5c.mjs → session-DyVE7cCk.mjs} +1 -1
- package/dist/{share-W5H3BNvP.mjs → share-Ce4tP7ji.mjs} +1 -1
- package/dist/{shot-LFhC-WYD.mjs → shot-BrRtqaiS.mjs} +34 -8
- package/dist/{shot-DoHLl6ig.mjs → shot-DBWN8hPP.mjs} +1 -1
- package/dist/sizes-wjXDev3b.mjs +139 -0
- package/dist/{slots-DCDo3N0x.mjs → slots-CFNnegCc.mjs} +8 -1
- package/dist/speech-worker.mjs +23 -3
- package/dist/{sync-BQVlHZpx.mjs → sync-CQdGARJ9.mjs} +1 -1
- package/dist/transport-C5FnY9ni.mjs +203 -0
- package/dist/{work-BroFwnup.mjs → work-BYWD_1Zf.mjs} +3 -3
- package/dist/{work-Bp1p39kq.mjs → work-DJxH7cCX.mjs} +1 -1
- package/docs/jam-session.md +42 -16
- package/docs/live-jam.md +92 -10
- package/docs/performance.md +197 -35
- package/package.json +1 -1
- package/src/client/content/video.tsx +10 -2
- package/src/client/shell/App.tsx +10 -3
- package/src/client/shell/Comments.tsx +5 -3
- package/src/client/shell/ContextMenu.tsx +5 -3
- package/src/client/shell/JamSurface.tsx +56 -21
- package/src/client/shell/LockedApp.tsx +3 -0
- package/src/client/shell/Play.tsx +4 -2
- package/src/client/shell/Tip.tsx +3 -1
- package/src/client/shell/api.ts +47 -20
- package/src/client/shell/app-bridge.ts +254 -0
- package/src/client/shell/app-perf.ts +92 -0
- package/src/client/shell/canvas/Canvas.tsx +115 -22
- package/src/client/shell/canvas/FrameNode.tsx +10 -6
- package/src/client/shell/canvas/admission.ts +23 -8
- package/src/client/shell/canvas/ctl.ts +6 -0
- package/src/client/shell/canvas/sleep.ts +57 -17
- package/src/client/shell/canvas/updates.ts +2 -1
- package/src/client/shell/icons.tsx +1 -0
- package/src/client/shell/inset.ts +44 -0
- package/src/client/shell/jam-capture.ts +113 -33
- package/src/client/shell/jam-keys.ts +40 -9
- package/src/client/shell/jam-lane.tsx +14 -5
- package/src/client/shell/jam-lines.ts +66 -9
- package/src/client/shell/jam-panel.tsx +61 -6
- package/src/client/shell/jam-queue.ts +50 -8
- package/src/client/shell/jam-session.tsx +53 -4
- package/src/client/shell/jam-surface-parts.tsx +6 -3
- package/src/client/shell/jam-ui.tsx +6 -1
- package/src/client/shell/jam-voice-wait.ts +21 -0
- package/src/client/shell/jam-voice.ts +62 -15
- package/src/client/shell/main.tsx +14 -1
- package/src/client/shell/marks-ui.tsx +5 -3
- package/src/client/shell/marver-app.ts +21 -0
- package/src/client/shell/perf-run-probe.ts +34 -0
- package/src/client/shell/perf-run.ts +70 -0
- package/src/client/shell/perf.ts +11 -0
- package/src/client/shell/recorder.ts +45 -3
- package/src/client/shell/store.ts +52 -24
- package/src/client/shell/styles.css +65 -17
- package/src/client/shell/tidy.ts +3 -2
- package/src/client/shell/unsaved.ts +81 -0
- package/src/client/shell/whiteout-probes.ts +141 -0
- package/src/shared/app-api.ts +205 -0
- package/src/shared/app-perf.ts +308 -0
- package/src/shared/approval.ts +20 -0
- package/src/shared/events.ts +1 -1
- package/src/shared/logo-sniff.ts +86 -0
- package/src/shared/machine.ts +132 -0
- package/src/shared/perf-run.ts +177 -0
- package/templates/AGENTS-embedded.md +31 -1
- package/templates/AGENTS-studio.md +31 -1
- package/templates/instructions/boards.md +10 -2
- package/templates/instructions/jam.md +90 -0
- package/dist/bake-DM_uWgAA.mjs +0 -786
- package/dist/boards-CGg6piKF.mjs +0 -342
- package/dist/perf-BWzQwZqj.mjs +0 -369
- package/dist/perf-BoDSkbEb.mjs +0 -429
- package/dist/perf-jam-D55U3FZK.mjs +0 -242
- package/dist/plugin-C-E7omsh.mjs +0 -2762
|
@@ -7,18 +7,18 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
|
9
9
|
import { ROUTE } from '../const.ts'
|
|
10
|
-
import { captureCounts, useJamCapture } from './jam-capture.ts'
|
|
10
|
+
import { captureCounts, endedToReview, useJamCapture } from './jam-capture.ts'
|
|
11
11
|
import { useJamVoice, voiceSession, voiceSessionEnd, voiceSessionId, type Heard } from './jam-voice.ts'
|
|
12
12
|
import { holdsSessionMic, PlayCounter, RecordDetail, StartSheet, WrapSheet } from './jam-session.tsx'
|
|
13
13
|
import { FocusPanel, VoiceAsk } from './jam-panel.tsx'
|
|
14
14
|
import { addNote, decideDraft, laneCards, openThread, openTile, pendingEdit, resumeDraft, reveal, saveEdit, shownLane, startCapture } from './jam-keys.ts'
|
|
15
15
|
import { ContextMenu, useContextMenu, type MenuItem } from './ContextMenu.tsx'
|
|
16
16
|
import { ArrowBendUpLeftIcon, ArrowLineUpIcon, ArrowUpIcon, CheckSquareOffsetIcon, CommentIcon, EyeIcon, NotebookIcon, PencilSimpleIcon, PlayIcon, ReloadIcon, XIcon } from './icons.tsx'
|
|
17
|
-
import { laneLine, timelineLines } from './jam-lines.ts'
|
|
17
|
+
import { laneLine, laneTip, timelineLines } from './jam-lines.ts'
|
|
18
18
|
import { changedShots, useJamQueue, type JamCard } from './jam-queue.ts'
|
|
19
19
|
import { DONE_GROUP, doneFold, letGoOfTile, useJamUi } from './jam-state.ts'
|
|
20
20
|
import { CaptureLaneRow, FocusPanelView } from './jam-surface-parts.tsx'
|
|
21
|
-
import { clearMoreDraft, EdgeRing } from './jam-panel.tsx'
|
|
21
|
+
import { clearMoreDraft, EdgeRing, preloadShots } from './jam-panel.tsx'
|
|
22
22
|
import { useComments } from './comments-store.ts'
|
|
23
23
|
import { HARNESS } from './Comments.tsx'
|
|
24
24
|
import { PUBLISHED, useStore } from './store.ts'
|
|
@@ -68,22 +68,38 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
|
|
|
68
68
|
useEffect(() => { const t = setInterval(() => setTick((n) => n + 1), 1000); return () => clearInterval(t) }, [])
|
|
69
69
|
// a new capture or a new draft brings the lane back to its right end
|
|
70
70
|
useEffect(() => { ui.follow() }, [cap.current, cards?.filter((c) => c.kind === 'capture').length])
|
|
71
|
-
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
71
|
+
const made = (id: string) => Number(/^cap-(\d+)-/.exec(id)?.[1] ?? 0)
|
|
72
|
+
// the read-back of the capture stopped TO REVIEW last (⇧E, or J's wrap-up) opens when capturing stops - over a
|
|
73
|
+
// review too (a capture made during a review is confirmed in its read-back; the review it follows stays bound in
|
|
74
|
+
// its record). It waits for that capture's own card: a resumed one replaces its draft, which must not open instead.
|
|
75
|
+
// The one ENDED last among them, not the one that sealed last (pictures can keep an earlier one sealing longer) -
|
|
76
|
+
// one capture records at a time, so that is the one started last. A capture stopped with E after it, before it
|
|
77
|
+
// had finished, never takes its place; and one stopped with E never opens, selects or moves anything - not even
|
|
78
|
+
// when the queue left it a draft (Nic, 27 Oct: "only when the user says Stop and Review should we have the To
|
|
79
|
+
// confirm state and open the capture card")
|
|
75
80
|
const [shownFor, setShownFor] = useState<string | null>(null)
|
|
76
81
|
useEffect(() => {
|
|
77
|
-
if (cap.current
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
if (cap.current) return
|
|
83
|
+
const toReview = cap.sealed.filter((x) => x.review).reduce<(typeof cap.sealed)[number] | undefined>((a, x) => (!a || made(x.id) > made(a.id) ? x : a), undefined)
|
|
84
|
+
// one stopped to review after it that is still finishing is the one to open: wait for it, never open the older
|
|
85
|
+
if (Object.values(cap.caps).some((c) => c.review && c.id !== toReview?.id && made(c.id) > (toReview ? made(toReview.id) : 0))) return
|
|
86
|
+
if (!toReview?.card || toReview.id === shownFor) return
|
|
87
|
+
const draft = cards?.find((c) => c.id === toReview.card!.id && c.state === 'draft')
|
|
81
88
|
if (!draft) return
|
|
82
|
-
setShownFor(
|
|
89
|
+
setShownFor(toReview.id)
|
|
83
90
|
if (ui.panel?.kind === 'capture' && ui.panel.id === draft.id) return
|
|
84
91
|
ui.open({ kind: 'capture', id: draft.id })
|
|
85
92
|
reveal(draft)
|
|
86
|
-
}, [cap.current, cap.sealed,
|
|
93
|
+
}, [cap.current, cap.sealed, cards])
|
|
94
|
+
|
|
95
|
+
// a review whose card left review under it - a capture made over it and stopped with E took it as More work, or
|
|
96
|
+
// another tab decided it: its panel closes (its verdicts would only fail now); nothing else opens or moves
|
|
97
|
+
const reviewing = ui.panel?.kind === 'review' ? cards?.find((c) => c.id === ui.panel!.id)?.state : undefined
|
|
98
|
+
const wasReviewing = useRef(reviewing)
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (wasReviewing.current === 'review' && reviewing && reviewing !== 'review' && useJamUi.getState().panel?.kind === 'review') ui.close()
|
|
101
|
+
wasReviewing.current = reviewing
|
|
102
|
+
}, [reviewing, ui.panel?.id])
|
|
87
103
|
|
|
88
104
|
// the session as the server holds it: a page opened (or reloaded) during one hears its talk again; one
|
|
89
105
|
// ended elsewhere (another tab) stops the talk here
|
|
@@ -119,13 +135,15 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
|
|
|
119
135
|
const sel = useJamQueue.getState().cards?.find((c) => c.id === st.selected)
|
|
120
136
|
if (sel?.thread === s.active) { if (st.panel) st.close() } else letGoOfTile()
|
|
121
137
|
}), [])
|
|
122
|
-
const
|
|
123
|
-
const withMade = list.map((c) => ({ made: c.made, tile: { id: c.id, state: c.state, title: c.title ?? 'Capture', line: laneLine(c), ...(c.exclusive ? { exclusive: true } : {}), ...(c.state === 'done' && c.shots?.some((x) => !x.same) ? { frames: c.shots.filter((x) => !x.same).map((x) => x.frame) } : {}), ...(c.kind === 'wrapup' ? { record: true } : {}) } as { id: string; state: JamCard['state']; title: string; line: string; exclusive?: boolean; frames?: string[]; record?: boolean } })
|
|
138
|
+
const tool = (a: string): string | undefined => HARNESS[a]
|
|
139
|
+
const withMade = list.map((c) => { const tip = laneTip(c, tool); return { made: c.made, tile: { id: c.id, state: c.state, title: c.title ?? 'Capture', line: laneLine(c, Date.now(), tool), ...(tip ? { tip } : {}), ...(c.exclusive ? { exclusive: true } : {}), ...(c.state === 'done' && c.shots?.some((x) => !x.same) ? { frames: c.shots.filter((x) => !x.same).map((x) => x.frame) } : {}), ...(c.kind === 'wrapup' ? { record: true } : {}) } as { id: string; state: JamCard['state']; title: string; line: string; tip?: string; exclusive?: boolean; frames?: string[]; record?: boolean } } })
|
|
124
140
|
// captures the server does not hold yet: sealing (pictures and flushes still out) or waiting to send -
|
|
125
|
-
// each in its place by when it started, so one sealing late never swaps with a newer one
|
|
141
|
+
// each in its place by when it started, so one sealing late never swaps with a newer one. Stopped with E it is
|
|
142
|
+
// being sent to the queue ("Sending", the spinning glyph of work under way - never To confirm); stopped to review
|
|
143
|
+
// (⇧E) it is finishing for its read-back
|
|
126
144
|
const known = new Set(list.map((c) => c.id))
|
|
127
|
-
for (const c of Object.values(cap.caps)) if (c.state === 'draining' && !known.has(c.id)) withMade.push({ made: made(c.id), tile: { id: c.id, state: 'confirming', title: 'Capture', line: 'Finishing' } })
|
|
128
|
-
for (const id of cap.unsent) if (!known.has(id) && !cap.caps[id]) withMade.push({ made: made(id), tile: { id, state: 'confirming', title: 'Capture', line: 'Waiting to send' } })
|
|
145
|
+
for (const c of Object.values(cap.caps)) if (c.state === 'draining' && !known.has(c.id)) withMade.push({ made: made(c.id), tile: { id: c.id, state: 'confirming', title: 'Capture', line: c.review ? 'Finishing' : 'Sending' } })
|
|
146
|
+
for (const id of cap.unsent) if (!known.has(id) && !cap.caps[id]) withMade.push({ made: made(id), tile: { id, state: 'confirming', title: 'Capture', line: cap.away ? 'Waiting to send' : endedToReview(id) ? 'Finishing' : 'Sending' } })
|
|
129
147
|
const tiles = withMade.sort((a, b) => a.made - b.made).map((x) => x.tile)
|
|
130
148
|
// a selected tile that became done while the Done group is folded: the group holds the selection now
|
|
131
149
|
const doneNow = doneFold(tiles, ui.doneOpen)
|
|
@@ -137,7 +155,7 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
|
|
|
137
155
|
const counts = captureCounts(c)
|
|
138
156
|
const steps = (c?.steps ?? []).filter((x) => ['select', 'device', 'theme', 'copied', 'interact'].includes(x.event)).length
|
|
139
157
|
return { time: counts.time, points: c?.points.length ?? 0, pictures: c?.pictures.length ?? 0, picturesMax: (c?.pictures.length ?? 0) >= 12, steps,
|
|
140
|
-
notes: counts.notes, noteOn: cap.noteOpen, onNote: () => cap.setNoteOpen(!cap.noteOpen), onStop: () => cap.end(),
|
|
158
|
+
notes: counts.notes, noteOn: cap.noteOpen, onNote: () => cap.setNoteOpen(!cap.noteOpen), onStop: () => cap.end(), onStopReview: () => cap.end(true),
|
|
141
159
|
// the microphone: on while it hears this capture; off once you were asked (a click asks again)
|
|
142
160
|
...(voice.hearing === cap.current ? { mic: 'on' as const } : voice.choice !== null || voice.denied ? { mic: 'off' as const, onMic: () => useJamVoice.setState({ asking: true, choice: null }) } : {}) }
|
|
143
161
|
})() : undefined
|
|
@@ -149,10 +167,14 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
|
|
|
149
167
|
} : undefined
|
|
150
168
|
|
|
151
169
|
const panelCard = ui.panel ? cards?.find((c) => c.id === ui.panel!.id) : undefined
|
|
170
|
+
// a card ready to review, and the one whose review is open: its pictures load now, every frame's - its review opens
|
|
171
|
+
// at their size and moves between frames without waiting (each URL once; never a card that is not in review)
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
for (const c of cards ?? []) if (c.state === 'review' || (ui.panel?.kind === 'review' && c.id === ui.panel.id)) preloadShots(changedShots(c.shots).flatMap((x) => [picture(x.before), picture(x.after)]))
|
|
174
|
+
}, [cards, ui.panel])
|
|
152
175
|
const rec = useRecord(ui.panel?.kind === 'capture' || ui.panel?.kind === 'review' ? ui.panel.id : undefined)
|
|
153
176
|
const agentName = agent ? HARNESS[agent] ?? agent : 'your agent'
|
|
154
177
|
const act = (c: JamCard | undefined, action: Parameters<ReturnType<typeof useJamQueue.getState>['act']>[1], body?: string) => (c ? useJamQueue.getState().act(c, action, body) : Promise.resolve(false))
|
|
155
|
-
const openThread = (c?: JamCard) => { if (c?.thread) useComments.getState().setActive(c.thread) }
|
|
156
178
|
/** The panel's arrows: the previous or next card of the same kind on the lane (reviews among reviews). */
|
|
157
179
|
const step = (d: number) => {
|
|
158
180
|
if (!ui.panel || !panelCard) return undefined
|
|
@@ -238,6 +260,12 @@ export function JamSurface({ sidebarRight }: { sidebarRight: number }) {
|
|
|
238
260
|
})()}
|
|
239
261
|
onLater={() => { void act(panelCard, 'later'); ui.close() }}
|
|
240
262
|
onOpenThread={() => openThread(panelCard)}
|
|
263
|
+
asks={panelCard.thread ? { question: replyText(panelCard), onAnswer: async (text) => {
|
|
264
|
+
const ok = await useComments.getState().replyOk(panelCard.thread!, /@marver\b/i.test(text) ? text : `@marver ${text}`)
|
|
265
|
+
if (!ok) useStore.getState().toast('your answer was not sent - try again')
|
|
266
|
+
else ui.close()
|
|
267
|
+
return ok
|
|
268
|
+
} } : undefined}
|
|
241
269
|
onPrev={step(-1)} onNext={step(1)} pending={pendingEdit(panelCard.id)} locked={cap.settling === panelCard.id}
|
|
242
270
|
onRetry={() => void (async () => { if (await act(useJamQueue.getState().cards?.find((x) => x.id === panelCard.id), 'retry')) ui.close(); else useStore.getState().toast('the capture could not be retried - look again') })()}
|
|
243
271
|
/>
|
|
@@ -283,7 +311,8 @@ function replyIn(c: JamCard) {
|
|
|
283
311
|
// once the thread's card has drawn (on another board, once that board has loaded)
|
|
284
312
|
const until = performance.now() + 3_000
|
|
285
313
|
const focus = () => {
|
|
286
|
-
const el = useComments.getState().active === c.thread ? document.querySelector<HTMLTextAreaElement>('.cm-card textarea')
|
|
314
|
+
const el = useComments.getState().active === c.thread ? document.querySelector<HTMLTextAreaElement>('.cm-card textarea')
|
|
315
|
+
: useJamUi.getState().panel?.id === c.id ? document.querySelector<HTMLTextAreaElement>('.jm-asks textarea') : null
|
|
287
316
|
if (el) { el.focus(); el.setSelectionRange(el.value.length, el.value.length) } else if (performance.now() < until) requestAnimationFrame(focus)
|
|
288
317
|
}
|
|
289
318
|
requestAnimationFrame(focus)
|
|
@@ -310,6 +339,12 @@ function tileMenu(c: JamCard): MenuItem[] {
|
|
|
310
339
|
case 'review': return [open, ...reply, ...thread, rename]
|
|
311
340
|
case 'asks': return [...reply, open, rename]
|
|
312
341
|
case 'failed': return [item('Retry', <ReloadIcon size={14} />, () => act('retry')), open, ...thread, item('Drop', <XIcon size={14} />, () => act('drop'))]
|
|
342
|
+
case 'working': {
|
|
343
|
+
// a run your session went quiet on (spec 29b): give it back, run it in the background, or drop it
|
|
344
|
+
if (c.runner?.kind !== 'session' || c.runner.state !== 'stalled') return [open, ...reply, ...thread, rename]
|
|
345
|
+
const run = (a: 'again' | 'background' | 'drop') => () => { const fresh = useJamQueue.getState().cards?.find((x) => x.id === c.id); if (fresh) void useJamQueue.getState().runAct(fresh, a) }
|
|
346
|
+
return [item('Give it back to your session', <ReloadIcon size={14} />, run('again')), item('Run it in the background', <ArrowUpIcon size={14} />, run('background')), open, ...thread, item('Drop it', <XIcon size={14} />, run('drop'))]
|
|
347
|
+
}
|
|
313
348
|
default: return [open, ...reply, ...thread, rename]
|
|
314
349
|
}
|
|
315
350
|
}
|
|
@@ -17,6 +17,9 @@ import { isLegacyLink, landLegacy } from './legacy-links.ts'
|
|
|
17
17
|
import { useComments } from './comments-store.ts'
|
|
18
18
|
import { isLatest, navigated, switchFor } from './goto.ts'
|
|
19
19
|
|
|
20
|
+
/** App.tsx's headless-run probe (perf-run-probe.ts): a run's page is always a dev canvas, never a locked bundle. */
|
|
21
|
+
export function startPerfRunProbe(): void {}
|
|
22
|
+
|
|
20
23
|
export class ShellBoundary extends Component<{ children: ReactNode }, { err: Error | null }> {
|
|
21
24
|
state = { err: null as Error | null }
|
|
22
25
|
static getDerivedStateFromError(err: Error) { return { err } }
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* next) stays prototype-only.
|
|
12
12
|
*/
|
|
13
13
|
import { setStageSize } from './stage-size.ts'
|
|
14
|
+
import { usable } from './inset.ts'
|
|
14
15
|
import { frameLoaded, frameReady, onFrameMessage, stageNavigated } from './jam-capture.ts'
|
|
15
16
|
import { jamKey } from './jam-keys.ts'
|
|
16
17
|
import { letGoOfTile } from './jam-state.ts'
|
|
@@ -310,7 +311,8 @@ function PlayInner() {
|
|
|
310
311
|
: ''
|
|
311
312
|
// the stage runs the project's frames: its URL names the workspace like a frame's (A1.11)
|
|
312
313
|
const src = useRef(play ? withWs(`${ROUTE}/stage/?at=${encodeURIComponent(play.at)}&theme=${encodeURIComponent(play.theme)}${slParams(play)}`) : '')
|
|
313
|
-
|
|
314
|
+
// the view below the Mac app's strip when the shell took the inset (inset.ts): fill, the doc preset and every fit
|
|
315
|
+
const [win, setWin] = useState(() => { const u = usable(); return { w: u.width, h: u.height } })
|
|
314
316
|
const [pillOpen, setPillOpen] = useState(true) // collapse (pill -> re-open fab), like the canvas
|
|
315
317
|
const [stageReady, setStageReady] = useState(0) // bumps on each sh:stage-ready (reload) - re-drives the highlight
|
|
316
318
|
const [away, setAway] = useState(false) // the stage shows another project's "another canvas" page (A1.11)
|
|
@@ -581,7 +583,7 @@ function PlayInner() {
|
|
|
581
583
|
}, [])
|
|
582
584
|
|
|
583
585
|
useEffect(() => {
|
|
584
|
-
const onResize = () => setWin({ w:
|
|
586
|
+
const onResize = () => { const u = usable(); setWin({ w: u.width, h: u.height }) }
|
|
585
587
|
window.addEventListener('resize', onResize)
|
|
586
588
|
return () => window.removeEventListener('resize', onResize)
|
|
587
589
|
}, [])
|
package/src/client/shell/Tip.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { cloneElement, useLayoutEffect, useRef, useState, type ReactElement, type ReactNode } from 'react'
|
|
2
2
|
import { createPortal } from 'react-dom'
|
|
3
|
+
import { TOP } from './inset.ts'
|
|
3
4
|
|
|
4
5
|
/** shadcn-style tooltip: snappy (150ms in, instant out), contrast-flipped, zoom-fade.
|
|
5
6
|
* Portaled to the app root - glass never nests, and neither do overlays. `inv` pins the
|
|
@@ -37,9 +38,10 @@ export function Tip({ label, side = 'top', inv = false, only, children }: { labe
|
|
|
37
38
|
if (over > 0) el.style.marginLeft = `${-over}px`
|
|
38
39
|
else if (r.left < 8) el.style.marginLeft = `${8 - r.left}px`
|
|
39
40
|
// and up and down: a tall tip beside a row near the bottom (a status and its evidence) stays whole
|
|
41
|
+
// never under the Mac app's strip (TOP 44 when the shell took the inset: 52 px)
|
|
40
42
|
const below = r.bottom - (window.innerHeight - 8)
|
|
41
43
|
if (below > 0) el.style.marginTop = `${-below}px`
|
|
42
|
-
else if (r.top < 8) el.style.marginTop = `${8 - r.top}px`
|
|
44
|
+
else if (r.top < TOP + 8) el.style.marginTop = `${TOP + 8 - r.top}px`
|
|
43
45
|
}, [pos])
|
|
44
46
|
// a tip is placed once, where its trigger was: anything that scrolls under it puts it away
|
|
45
47
|
useLayoutEffect(() => {
|
package/src/client/shell/api.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { create } from 'zustand'
|
|
10
10
|
import { ROUTE } from '../const.ts'
|
|
11
|
+
import { guardLeaving, leaveNow, unsavedWhen, workChanged } from './unsaved.ts'
|
|
12
|
+
import { PERF_RUN, perfRunGate, RUN_HEADER, RUN_PARAM } from './perf-run.ts'
|
|
11
13
|
// @ts-expect-error virtual module provided by the plugin
|
|
12
14
|
import shConfig from 'virtual:sh-config'
|
|
13
15
|
// @ts-expect-error virtual module: null in dev; a published build inlines manifest+boards
|
|
@@ -18,8 +20,15 @@ export const WS: string = shData === null && typeof shConfig?.workspace === 'str
|
|
|
18
20
|
|
|
19
21
|
/** A per-viewer preference kept per canvas (A1.6): `<key>:<workspace>` in dev, the bare key when published. */
|
|
20
22
|
export const scoped = (key: string) => (WS ? `${key}:${WS}` : key)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
const param = (url: string, k: string, v: string) => `${url}${url.includes('?') ? '&' : '?'}${k}=${v}`
|
|
24
|
+
/** A URL a document or an <img> loads, naming the workspace (frames, the stage, Jam pictures) - and, in a headless
|
|
25
|
+
* perf run, the run (spec 28 A3.8 #17): a frame's own writes are refused by its Referer, its Video asks no poster. */
|
|
26
|
+
export const withWs = (url: string) => {
|
|
27
|
+
const u = WS ? param(url, 'ws', WS) : url
|
|
28
|
+
return PERF_RUN ? param(u, RUN_PARAM, PERF_RUN.id) : u
|
|
29
|
+
}
|
|
30
|
+
/** The headers every request of this page carries: its workspace, and its perf run's id. */
|
|
31
|
+
const named = (h: Record<string, string> | undefined): Record<string, string> => ({ ...h, ...(WS ? { 'x-mv-ws': WS } : {}), ...(PERF_RUN ? { [RUN_HEADER]: PERF_RUN.id } : {}) })
|
|
23
32
|
|
|
24
33
|
/** live; checking (the live socket dropped, the first answer not in); down (nothing, or not this canvas,
|
|
25
34
|
* answers); elsewhere (another canvas answers here); resuming (this canvas answered: saving, then reload). */
|
|
@@ -41,10 +50,13 @@ const stoppedAnswer = () => new Response('{"error":"this canvas stopped"}', { st
|
|
|
41
50
|
|
|
42
51
|
/** Any request to this page's dev server. `fetch` is looked up at call time (tests patch window.fetch)
|
|
43
52
|
* and called before any await, so a `keepalive` request made in `pagehide` still goes out. Callers pass
|
|
44
|
-
* plain-object headers; a GET keeps its init without a method.
|
|
53
|
+
* plain-object headers; a GET keeps its init without a method. In a headless perf run the barrier comes first
|
|
54
|
+
* (perf-run.ts): a write the run may not make is answered 403 here, never sent, and never stops the page. */
|
|
45
55
|
export function mvFetch(url: string, init: RequestInit = {}): Promise<Response> {
|
|
56
|
+
const refused = perfRunGate(url, init)
|
|
57
|
+
if (refused) return Promise.resolve(refused)
|
|
46
58
|
if (WS && canvasStopped()) return Promise.resolve(stoppedAnswer())
|
|
47
|
-
const sent = fetch(url, WS ? { ...init, headers:
|
|
59
|
+
const sent = fetch(url, WS || PERF_RUN ? { ...init, headers: named(init.headers as Record<string, string> | undefined) } : init)
|
|
48
60
|
if (!WS) return sent
|
|
49
61
|
// the server's refusal is told apart here, before any caller's own 409 (a board conflict, a stale tree)
|
|
50
62
|
return sent.then((r) => {
|
|
@@ -67,8 +79,8 @@ export const api = (path: string, init?: RequestInit) => mvFetch(`${ROUTE}/api/$
|
|
|
67
79
|
* nothing to do. */
|
|
68
80
|
const flushers = new Set<() => Promise<boolean>>()
|
|
69
81
|
export const beforeResume = (fn: () => Promise<boolean>) => { flushers.add(fn); return () => { flushers.delete(fn) } }
|
|
70
|
-
/** What holds a reload while it answers true: an edit not saved, a capture recording,
|
|
71
|
-
* sent. Synchronous, and asked right before the reload, after every flusher has finished - so what a person
|
|
82
|
+
/** What holds a reload while it answers true: an edit not saved, heights not in the file yet, a capture recording,
|
|
83
|
+
* words typed and not sent. Synchronous, and asked right before the reload, after every flusher has finished - so what a person
|
|
72
84
|
* does while the flushers wait on the server holds it as surely as what was there before they began. */
|
|
73
85
|
const holds = new Set<() => boolean>()
|
|
74
86
|
export const holdsReload = (fn: () => boolean) => { holds.add(fn); return () => { holds.delete(fn) } }
|
|
@@ -88,6 +100,7 @@ let hmrLost = false
|
|
|
88
100
|
let probeTimer: ReturnType<typeof setTimeout> | null = null
|
|
89
101
|
|
|
90
102
|
function lost(why: 'down' | 'elsewhere') {
|
|
103
|
+
owed = true
|
|
91
104
|
noteUnsaved()
|
|
92
105
|
if (why === 'elsewhere') useLink.setState({ link: 'elsewhere', shown: true })
|
|
93
106
|
else if (!canvasStopped()) useLink.setState({ link: 'checking' })
|
|
@@ -98,7 +111,7 @@ function lost(why: 'down' | 'elsewhere') {
|
|
|
98
111
|
async function probe() {
|
|
99
112
|
let r: Response | null = null
|
|
100
113
|
// a server that takes the connection and never answers (half up, hung, paused) is no answer: a miss
|
|
101
|
-
try { r = await fetch(`${ROUTE}/api/hello`, { headers: {
|
|
114
|
+
try { r = await fetch(`${ROUTE}/api/hello`, { headers: named({}), cache: 'no-store', signal: AbortSignal.timeout(2000) }) } catch { r = null }
|
|
102
115
|
const ours = !!r?.ok && (await r.json().catch(() => null))?.ws === WS
|
|
103
116
|
probeTimer = null
|
|
104
117
|
if (ours) return void resume()
|
|
@@ -113,8 +126,7 @@ async function resume() {
|
|
|
113
126
|
const back = useLink.getState().link !== 'live' // from a stop; 'live' is a page that owes a reload
|
|
114
127
|
if (back) useLink.setState({ link: 'resuming' }) // requests flow again: the flushers use them
|
|
115
128
|
let ok = true
|
|
116
|
-
|
|
117
|
-
try { for (const fn of flushers) ok = (await fn().catch(() => false)) && ok } finally { flushing = false }
|
|
129
|
+
for (const fn of flushers) ok = (await fn().catch(() => false)) && ok
|
|
118
130
|
const now = useLink.getState().link
|
|
119
131
|
if (now !== 'resuming' && now !== 'live') return // lost again while saving: the probe goes on
|
|
120
132
|
// asked here, with nothing awaited between the answer and the reload: words typed or an edit made while a
|
|
@@ -122,10 +134,11 @@ async function resume() {
|
|
|
122
134
|
if (ok && held()) ok = false
|
|
123
135
|
// a fresh document on the canvas that answered: live updates again - and the next page says what the resumes came to,
|
|
124
136
|
// this one's and those this reload waited after (a draft, a capture), whose toasts go with this page
|
|
125
|
-
|
|
137
|
+
// its own guard lets this reload through: what it held is saved, and nothing holds it (A2.14 #17)
|
|
138
|
+
if (hmrLost && ok) { keepOverReload(lostOnResume ?? (savedOnResume ? 'saved' : null)); return void leaveNow(() => location.reload()) }
|
|
126
139
|
if (back || useLink.getState().shown) useLink.setState({ link: 'live', shown: false })
|
|
127
140
|
// no reload owed (Vite's socket held): the page goes on as it is, and what this resume came to was said on it
|
|
128
|
-
if (!hmrLost) { lostOnResume = null; savedOnResume = false; return }
|
|
141
|
+
if (!hmrLost) { owed = false; lostOnResume = null; savedOnResume = false; return }
|
|
129
142
|
// Vite's socket never comes back (its client waits on the listener below), so this page owes a reload:
|
|
130
143
|
// until nothing holds it (a capture recording, words not sent) it works as live, keeps asking - a stop
|
|
131
144
|
// is seen again - and reloads the moment it may
|
|
@@ -150,18 +163,22 @@ export function stranded(f: HTMLIFrameElement | null): boolean {
|
|
|
150
163
|
* reached the disk; 'disk' - the board's file changed on disk meanwhile and won, the tab's board edits dropped; 'gone' - the board
|
|
151
164
|
* was renamed or removed meanwhile and is not created again; null - there was nothing to save. */
|
|
152
165
|
export type ResumeOutcome = 'saved' | 'disk' | 'gone' | null
|
|
153
|
-
|
|
166
|
+
/** A resume is owed from the stop until the page's own reload - or, Vite's socket held, until the resume that needs
|
|
167
|
+
* none. Every board save that answers meanwhile is what the resumes came to: the resume's own, and as often the
|
|
168
|
+
* ordinary autosave (store.ts, 500 ms after an edit), which can land before any flusher runs - a pass held by a
|
|
169
|
+
* frame in the hand, then the drop's save - and leave the flushers nothing to save. */
|
|
170
|
+
let owed = false
|
|
154
171
|
/** What the resumes came to - the board save's own word, lost or saved - kept until the reload that carries it: a
|
|
155
172
|
* resume whose reload is held (a draft, a capture) is not the last one, and the one that reloads at last may have
|
|
156
|
-
* nothing left to save. Each later
|
|
173
|
+
* nothing left to save. Each later save only adds to it - the first loss stays, and a loss outranks a save. A resume
|
|
157
174
|
* that owes no reload (Vite's socket held) ends it. */
|
|
158
175
|
let lostOnResume: 'disk' | 'gone' | null = null
|
|
159
176
|
let savedOnResume = false
|
|
160
|
-
/**
|
|
161
|
-
*
|
|
162
|
-
export function lostInResume(why: 'disk' | 'gone') { if (
|
|
163
|
-
/**
|
|
164
|
-
export function savedInResume() { if (
|
|
177
|
+
/** A board save, while a resume is owed: what this tab held did not reach the disk (store.ts) - the page after the
|
|
178
|
+
* reload says what happened instead, never that the edits were saved. */
|
|
179
|
+
export function lostInResume(why: 'disk' | 'gone') { if (owed) lostOnResume ??= why }
|
|
180
|
+
/** A board save, while a resume is owed - the resume's or the autosave's: what this tab held reached the disk (store.ts). */
|
|
181
|
+
export function savedInResume() { if (owed) savedOnResume = true }
|
|
165
182
|
|
|
166
183
|
const RESUMED = 'mv-resumed'
|
|
167
184
|
const keepers = new Set<() => Record<string, unknown>>()
|
|
@@ -191,10 +208,18 @@ export const resumed: { outcome: ResumeOutcome; board?: string; camera?: { x: nu
|
|
|
191
208
|
const typed = new WeakSet<EventTarget>()
|
|
192
209
|
const TEXT_FIELDS = 'textarea, input:not([type]), input[type=text], input[type=search], input[type=email], input[type=url], input[type=password]'
|
|
193
210
|
if (WS) {
|
|
194
|
-
document.addEventListener('input', (e) => { if (e.target) typed.add(e.target); if (canvasStopped()) noteUnsaved() }, true)
|
|
195
|
-
|
|
211
|
+
document.addEventListener('input', (e) => { if (e.target) typed.add(e.target); if (canvasStopped()) noteUnsaved(); workChanged() }, true)
|
|
212
|
+
const typedWords = () => [...document.querySelectorAll<HTMLInputElement | HTMLTextAreaElement>(TEXT_FIELDS)].some((el) => typed.has(el) && el.value.trim() !== '')
|
|
213
|
+
holdsReload(typedWords)
|
|
214
|
+
// and leaving the page asks first (spec 28 A2.9): the words are only here
|
|
215
|
+
unsavedWhen('typing', typedWords)
|
|
196
216
|
}
|
|
197
217
|
|
|
218
|
+
// one question before this page goes, whatever it holds that the server does not have (unsaved.ts): a capture, a
|
|
219
|
+
// board edit, heights, words - in every browser, and the Mac app reads the same reasons. Never in a headless perf run
|
|
220
|
+
// (spec 28 A3.8 #17): its writes are refused, so `heights` would hold for good and block the context's end
|
|
221
|
+
if (typeof window !== 'undefined' && !PERF_RUN) guardLeaving(window)
|
|
222
|
+
|
|
198
223
|
// Vite's client awaits every `vite:ws:disconnect` listener before it pings the server and reloads the
|
|
199
224
|
// page (vite/dist/client/client.mjs, Vite 8). This one never settles: the canvas page is never reloaded by
|
|
200
225
|
// Vite - not into another project that took the port, and not into this one's next run before it has
|
|
@@ -204,3 +229,5 @@ if (WS && import.meta.hot) import.meta.hot.on('vite:ws:disconnect', () => { hmrL
|
|
|
204
229
|
|
|
205
230
|
// dev-only inspection hook for tests (never installed in published builds)
|
|
206
231
|
if (WS && import.meta.env.DEV) (window as unknown as { __mvLink: unknown }).__mvLink = useLink
|
|
232
|
+
// and, in a headless perf run only, the page's own way out: a test sends through the barrier as the shell does
|
|
233
|
+
if (PERF_RUN && import.meta.env.DEV) (window as unknown as { __mvApi: unknown }).__mvApi = { api, withWs }
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shell's side of the Mac app (spec 28 A2.9; A2.14 #9, #13, #18, #26; v1.12 r1 #1, v1.13 r2 #1): what the canvas
|
|
3
|
+
* tells the app through `window.marverApp`, and what it does when the app speaks. Inert anywhere else - in Chrome, on
|
|
4
|
+
* a published canvas, under `marver shot` there is no `window.marverApp` (marver-app.ts), and nothing here listens,
|
|
5
|
+
* sends or runs a timer.
|
|
6
|
+
*
|
|
7
|
+
* What the shell owes the app is A2.9's order and whole states: `mv:hello` first (its version, the board its link
|
|
8
|
+
* names, and its `PAGE_ID`, the id the recorder stamps on every record), then `mv:theme`, `mv:busy` and `mv:menu`, each
|
|
9
|
+
* sent whole and again whenever it changes. The admission - the app binding a document at its trusted commit and the
|
|
10
|
+
* preload holding what the page said until then, replaying the latest of each, hello first (v1.12 r1 #1) - is the
|
|
11
|
+
* preload's: `window.marverApp` is the same before and after, and the shell never sees a `doc`.
|
|
12
|
+
*
|
|
13
|
+
* - `mv:busy` is `{ busy, unsaved, why }` from unsaved.ts's reasons: sent once at boot, so the app's record of a page
|
|
14
|
+
* that runs is unknown for one turn at most (v1.13 r2 #1), then on every change of either;
|
|
15
|
+
* - `mv:theme` is the ground under the strip: `play || viewTheme === 'dark'` (A2.14 #26; slides are play);
|
|
16
|
+
* - `mv:menu` is the canvas's View and Jam items, each with its key as its `hint` - the app shows it in the item's
|
|
17
|
+
* name, never as an accelerator, so the key stays the page's (A2.7); a click replays that key, so the menu does
|
|
18
|
+
* exactly what the key does;
|
|
19
|
+
* - `mv:app-state`: `shown` runs a resume reconcile, `untrusted` stops every microphone track the page holds (A2.14
|
|
20
|
+
* #13), `hidden` changes nothing (a hidden tab keeps running, A2.6).
|
|
21
|
+
*
|
|
22
|
+
* The one ground (0.27.2, A3.8 #27, #31): `mv:hello` says the inset the shell applied (inset.ts's `TOP`: 44 only when
|
|
23
|
+
* the app said so and gave the whole presentation contract), and each `mv:present { epoch, w, h, frames }` is answered
|
|
24
|
+
* once the viewport has that size (500 ms at most) and `frames` animation frames have passed, with the size it was
|
|
25
|
+
* answered at - a newer request cancels an older wait, which is never answered. A request that never fits is answered
|
|
26
|
+
* at the size found; main refuses it and the tab stays covered. rAF does not run in a hidden page, so a request to a
|
|
27
|
+
* page nobody sees waits by itself. App 0.1 says no inset and asks nothing: none of it runs there.
|
|
28
|
+
*/
|
|
29
|
+
import { BOUNDS, type AppState, type Busy, type Hello, type MarverAppV1, type MenuItem, type Present } from '../../shared/app-api.ts'
|
|
30
|
+
import { APP } from './marver-app.ts'
|
|
31
|
+
import { TOP } from './inset.ts'
|
|
32
|
+
import { api, canvasStopped } from './api.ts'
|
|
33
|
+
import { asksBeforeLeaving, busyWhen, busyWhy, isUnsaved, leaveNow, onWorkChange, workChanged } from './unsaved.ts'
|
|
34
|
+
import { CONFIG, PUBLISHED, SOURCE_REVEALED, useStore } from './store.ts'
|
|
35
|
+
import { PAGE_ID } from './recorder.ts'
|
|
36
|
+
import { bootHash, UNPLACED } from './hash.ts'
|
|
37
|
+
import { useComments } from './comments-store.ts'
|
|
38
|
+
import { useNotes } from './notes.ts'
|
|
39
|
+
import { useJamCapture } from './jam-capture.ts'
|
|
40
|
+
import { useJamQueue } from './jam-queue.ts'
|
|
41
|
+
import { useJamUi } from './jam-state.ts'
|
|
42
|
+
import { useJamVoice, voiceUntrusted } from './jam-voice.ts'
|
|
43
|
+
|
|
44
|
+
/** The ground under the strip (A2.14 #26): the shell's own - never a frame's pinned theme. */
|
|
45
|
+
export const shellDark = (): boolean => { const s = useStore.getState(); return !!s.play || s.viewTheme === 'dark' }
|
|
46
|
+
|
|
47
|
+
/** `mv:hello`: within the contract's bounds, or the honest fallback (an unknown version, no board). */
|
|
48
|
+
export function helloNow(): Hello {
|
|
49
|
+
const v = CONFIG.version
|
|
50
|
+
const version = typeof v === 'string' && v.length <= BOUNDS.version && BOUNDS.versionChars.test(v) ? v : '0.0.0'
|
|
51
|
+
const b = bootHash.board
|
|
52
|
+
return { version, board: typeof b === 'string' && b.length <= BOUNDS.board ? b : null, page: PAGE_ID, inset: TOP }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** How long the shell waits for its viewport to reach a request's size before it answers with the size it has. */
|
|
56
|
+
export const PRESENT_FIT_MS = 500
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The presentation's answer (A3.8 #27): one request at a time - a newer one cancels the wait of an older, which is
|
|
60
|
+
* never answered. Wait for the asked viewport (1 px either way), then `frames` animation frames (1-8), then answer
|
|
61
|
+
* with the viewport as it is. Exported for the browser tests' fake bridge; startAppBridge installs it.
|
|
62
|
+
*/
|
|
63
|
+
export function answerPresents(app: Pick<MarverAppV1, 'onPresent' | 'presented'>, call: (fn: () => void) => void = (fn) => fn()): () => void {
|
|
64
|
+
if (typeof app.onPresent !== 'function' || typeof app.presented !== 'function') return () => {}
|
|
65
|
+
let want = -1
|
|
66
|
+
return app.onPresent((r: Present) => {
|
|
67
|
+
if (!r || typeof r.epoch !== 'number') return
|
|
68
|
+
want = r.epoch
|
|
69
|
+
const since = performance.now()
|
|
70
|
+
const frames = Math.min(BOUNDS.frames, Math.max(1, r.frames | 0))
|
|
71
|
+
const step = (left: number) => requestAnimationFrame(() => {
|
|
72
|
+
if (want !== r.epoch) return // superseded: never answered
|
|
73
|
+
const fits = Math.abs(innerWidth - r.w) <= 1 && Math.abs(innerHeight - r.h) <= 1
|
|
74
|
+
if (!fits && performance.now() - since < PRESENT_FIT_MS) return step(left) // the resize has not reached this document yet
|
|
75
|
+
if (fits && left > 1) return step(left - 1)
|
|
76
|
+
call(() => app.presented!({ epoch: r.epoch, w: innerWidth, h: innerHeight }))
|
|
77
|
+
})
|
|
78
|
+
step(frames)
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** `mv:busy` now. */
|
|
83
|
+
export function busyNow(): Busy {
|
|
84
|
+
const why = busyWhy()
|
|
85
|
+
return { busy: why.length > 0, unsaved: why.some(isUnsaved), why }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ---- the menu (A2.7: the View and Jam items, today's keys) --------------------------------------------------
|
|
89
|
+
|
|
90
|
+
interface Item {
|
|
91
|
+
id: string
|
|
92
|
+
group: MenuItem['group']
|
|
93
|
+
label: string
|
|
94
|
+
hint: string
|
|
95
|
+
/** the key a click replays - what App.tsx, Play.tsx and jamKey read: key, code and the modifiers */
|
|
96
|
+
key: KeyboardEventInit
|
|
97
|
+
/** a checkbox item: its mark is the page's state */
|
|
98
|
+
checked?: () => boolean
|
|
99
|
+
/** offered only while this answers true */
|
|
100
|
+
when?: () => boolean
|
|
101
|
+
}
|
|
102
|
+
const jamOn = () => !PUBLISHED && !!CONFIG.jam
|
|
103
|
+
const laser = (inspect: boolean) => () => { const s = useStore.getState(); return s.laser && s.laserInspect === inspect }
|
|
104
|
+
const ITEMS: readonly Item[] = [
|
|
105
|
+
{ id: 'fit-all', group: 'view', label: 'Fit All', hint: '⇧1', key: { key: '!', code: 'Digit1', shiftKey: true } },
|
|
106
|
+
{ id: 'fit-selection', group: 'view', label: 'Fit Selection', hint: '⇧2', key: { key: '@', code: 'Digit2', shiftKey: true } },
|
|
107
|
+
{ id: 'actual-size', group: 'view', label: 'Actual Size', hint: '⇧0', key: { key: ')', code: 'Digit0', shiftKey: true } },
|
|
108
|
+
{ id: 'play', group: 'view', label: 'Play', hint: 'P', key: { key: 'p', code: 'KeyP' } },
|
|
109
|
+
{ id: 'hide-ui', group: 'view', label: 'Hide UI', hint: 'H', key: { key: 'h', code: 'KeyH' }, checked: () => document.body.classList.contains('sh-hide-ui') },
|
|
110
|
+
{ id: 'tidy', group: 'view', label: 'Tidy', hint: 'T', key: { key: 't', code: 'KeyT' } },
|
|
111
|
+
{ id: 'comments', group: 'view', label: 'Comments', hint: 'C', key: { key: 'c', code: 'KeyC' }, checked: () => useComments.getState().commentMode },
|
|
112
|
+
{ id: 'pins', group: 'view', label: 'Pins', hint: '⇧C', key: { key: 'C', code: 'KeyC', shiftKey: true }, checked: () => useComments.getState().show },
|
|
113
|
+
{ id: 'notes', group: 'view', label: 'Notes', hint: 'N', key: { key: 'n', code: 'KeyN' }, checked: () => useNotes.getState().all },
|
|
114
|
+
{ id: 'laser', group: 'view', label: 'Laser', hint: 'L', key: { key: 'l', code: 'KeyL' }, checked: laser(false), when: () => SOURCE_REVEALED },
|
|
115
|
+
// with Option a Mac types a symbol (⌥L is "¬"): the shell names an Alt shortcut by the key pressed
|
|
116
|
+
{ id: 'inspect', group: 'view', label: 'Inspect', hint: '⌥L', key: { key: '¬', code: 'KeyL', altKey: true }, checked: laser(true), when: () => SOURCE_REVEALED },
|
|
117
|
+
// D cycles the themes: a plain item, no mark (A2.14 #19)
|
|
118
|
+
{ id: 'theme', group: 'view', label: 'Theme', hint: 'D', key: { key: 'd', code: 'KeyD' }, when: () => CONFIG.themes.length > 1 },
|
|
119
|
+
{ id: 'session', group: 'jam', label: 'Session', hint: 'J', key: { key: 'j', code: 'KeyJ' }, checked: () => !!useJamQueue.getState().session, when: jamOn },
|
|
120
|
+
{ id: 'capture', group: 'jam', label: 'Capture', hint: 'S', key: { key: 's', code: 'KeyS' }, checked: () => !!useJamCapture.getState().current, when: jamOn },
|
|
121
|
+
{ id: 'lane', group: 'jam', label: 'The Lane', hint: 'Q', key: { key: 'q', code: 'KeyQ' }, checked: () => useJamUi.getState().laneKeys, when: jamOn },
|
|
122
|
+
{ id: 'next-review', group: 'jam', label: 'Next to Review', hint: 'V', key: { key: 'v', code: 'KeyV' }, when: jamOn },
|
|
123
|
+
]
|
|
124
|
+
const offered = (it: Item) => { try { return it.when?.() ?? true } catch { return false } }
|
|
125
|
+
|
|
126
|
+
/** `mv:menu` now: at most 40 items, ids, labels and hints within the contract's bounds. */
|
|
127
|
+
export function menuNow(): MenuItem[] {
|
|
128
|
+
return ITEMS.filter(offered).slice(0, BOUNDS.menuItems).map((it) => ({
|
|
129
|
+
id: it.id, group: it.group, label: it.label, hint: it.hint,
|
|
130
|
+
...(it.checked ? { checked: (() => { try { return !!it.checked!() } catch { return false } })() } : {}),
|
|
131
|
+
}))
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** A menu item chosen in the app: its key, replayed on the shell's window - the same handlers, the same rules (a
|
|
135
|
+
* text field holding the focus does not stop it: the person chose the item). An id the page does not offer now
|
|
136
|
+
* does nothing. One id is the app's own, never in the menu: the tab's right-click Mark All as Seen clears every
|
|
137
|
+
* frame's "new" in this canvas, here and on disk, as the sidebar's Mark all as seen does for a board. */
|
|
138
|
+
export function runMenuItem(id: string): void {
|
|
139
|
+
if (id === 'mark-all-seen') {
|
|
140
|
+
const s = useStore.getState()
|
|
141
|
+
if (!PUBLISHED && s.marks) s.markSeen(Object.keys(s.marks.changed))
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
const it = ITEMS.find((x) => x.id === id)
|
|
145
|
+
if (!it || !offered(it)) return
|
|
146
|
+
window.dispatchEvent(new KeyboardEvent('keydown', { ...it.key, bubbles: true, cancelable: true }))
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ---- coming back into view ----------------------------------------------------------------------------------
|
|
150
|
+
|
|
151
|
+
let reconciling = false
|
|
152
|
+
/** The tab is shown again (`mv:app-state shown`, Codex r1 #14): the marks, the working state and the Jam queue are
|
|
153
|
+
* read again, and the board's file hash - a board changed on disk meanwhile is loaded again, never over an edit
|
|
154
|
+
* this page holds. One at a time: a `shown` while one runs is dropped. */
|
|
155
|
+
export async function resumeReconcile(): Promise<void> {
|
|
156
|
+
if (reconciling || PUBLISHED || canvasStopped()) return
|
|
157
|
+
reconciling = true
|
|
158
|
+
try {
|
|
159
|
+
const s = useStore.getState()
|
|
160
|
+
void s.syncMarks()
|
|
161
|
+
void s.syncWorking()
|
|
162
|
+
if (jamOn()) void useJamQueue.getState().load()
|
|
163
|
+
const board = s.board
|
|
164
|
+
if (!s.manifest || board === UNPLACED || s.dirty || s.gesture) return
|
|
165
|
+
const r = await api(`boards/${board}`)
|
|
166
|
+
if (!r.ok) return
|
|
167
|
+
const body = await r.json().catch(() => null) as { sha256?: unknown } | null
|
|
168
|
+
const now = useStore.getState()
|
|
169
|
+
if (now.board !== board || now.dirty || now.gesture) return
|
|
170
|
+
const disk = typeof body?.sha256 === 'string' ? body.sha256 : null
|
|
171
|
+
if (disk !== now.boardHash) await now.boot()
|
|
172
|
+
} catch { /* the next shown, or the live socket, heals it */ } finally { reconciling = false }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function onAppState(s: AppState): void {
|
|
176
|
+
if (s === 'shown') void resumeReconcile()
|
|
177
|
+
else if (s === 'untrusted') voiceUntrusted()
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ---- the bridge ---------------------------------------------------------------------------------------------
|
|
181
|
+
|
|
182
|
+
let started = false
|
|
183
|
+
|
|
184
|
+
/** main.tsx, before the first render: hello, theme, busy, menu - then each again on its change. Nothing without
|
|
185
|
+
* `window.marverApp`. */
|
|
186
|
+
export function startAppBridge(): void {
|
|
187
|
+
const app = APP
|
|
188
|
+
if (!app || started) return
|
|
189
|
+
started = true
|
|
190
|
+
/** a bridge call that throws (the app went away under the page) never breaks the page */
|
|
191
|
+
const call = (fn: () => void) => { try { fn() } catch { /* the page goes on */ } }
|
|
192
|
+
|
|
193
|
+
// what the app says, listened for before the page says anything
|
|
194
|
+
call(() => app.onAppState((s) => onAppState(s)))
|
|
195
|
+
call(() => app.onMenuClick((p) => runMenuItem(typeof p?.id === 'string' ? p.id : '')))
|
|
196
|
+
// the one ground's presentation requests (0.27.2): answered only when the shell took the inset - a shell that did
|
|
197
|
+
// not is placed below the strip and never asked (A3.8 #31)
|
|
198
|
+
if (TOP) call(() => { answerPresents(app, call) })
|
|
199
|
+
|
|
200
|
+
// 1. hello, first (A2.14 #9)
|
|
201
|
+
call(() => app.hello(helloNow()))
|
|
202
|
+
|
|
203
|
+
// 2. the theme, at boot and on its change
|
|
204
|
+
let lastDark: boolean | null = null
|
|
205
|
+
const sendTheme = () => { const dark = shellDark(); if (dark === lastDark) return; lastDark = dark; call(() => app.theme({ dark })) }
|
|
206
|
+
sendTheme()
|
|
207
|
+
useStore.subscribe((s, p) => { if (!!s.play !== !!p.play || s.viewTheme !== p.viewTheme) sendTheme() })
|
|
208
|
+
|
|
209
|
+
// 3. busy: the unsaved reasons every browser registers, and the three only the app hears
|
|
210
|
+
busyWhen('jam-session', () => !!useJamQueue.getState().session)
|
|
211
|
+
busyWhen('microphone', () => useJamVoice.getState().live)
|
|
212
|
+
busyWhen('agent', () => useStore.getState().working.length > 0)
|
|
213
|
+
useJamQueue.subscribe((s, p) => { if (!!s.session !== !!p.session) workChanged() })
|
|
214
|
+
useJamVoice.subscribe((s, p) => { if (s.live !== p.live) workChanged() })
|
|
215
|
+
useStore.subscribe((s, p) => { if ((s.working.length > 0) !== (p.working.length > 0)) workChanged() })
|
|
216
|
+
let lastBusy = ''
|
|
217
|
+
let again: ReturnType<typeof setTimeout> | undefined
|
|
218
|
+
const sendBusy = () => {
|
|
219
|
+
const b = busyNow()
|
|
220
|
+
const k = JSON.stringify(b)
|
|
221
|
+
if (k !== lastBusy) { lastBusy = k; call(() => app.busy(b)) }
|
|
222
|
+
// while busy, looked at again each second: a reason with no hook of its own going away (a field emptied by
|
|
223
|
+
// sending its words, a field removed) is told within a second; at rest, no timer
|
|
224
|
+
clearTimeout(again)
|
|
225
|
+
again = b.busy ? setTimeout(sendBusy, 1000) : undefined
|
|
226
|
+
}
|
|
227
|
+
onWorkChange(sendBusy)
|
|
228
|
+
sendBusy() // the first mv:busy, at boot (v1.13 r2 #1)
|
|
229
|
+
|
|
230
|
+
// 4. the menu, on any change of what it shows
|
|
231
|
+
let lastMenu = ''
|
|
232
|
+
let menuQueued = false
|
|
233
|
+
const sendMenu = () => {
|
|
234
|
+
menuQueued = false
|
|
235
|
+
const items = menuNow()
|
|
236
|
+
const k = JSON.stringify(items)
|
|
237
|
+
if (k !== lastMenu) { lastMenu = k; call(() => app.menu(items)) }
|
|
238
|
+
}
|
|
239
|
+
const menuChanged = () => { if (menuQueued) return; menuQueued = true; queueMicrotask(sendMenu) }
|
|
240
|
+
sendMenu()
|
|
241
|
+
useStore.subscribe((s, p) => { if (s.laser !== p.laser || s.laserInspect !== p.laserInspect) menuChanged() })
|
|
242
|
+
useComments.subscribe((s, p) => { if (s.commentMode !== p.commentMode || s.show !== p.show) menuChanged() })
|
|
243
|
+
useNotes.subscribe((s, p) => { if (s.all !== p.all) menuChanged() })
|
|
244
|
+
useJamQueue.subscribe((s, p) => { if (!!s.session !== !!p.session) menuChanged() })
|
|
245
|
+
useJamCapture.subscribe((s, p) => { if (!!s.current !== !!p.current) menuChanged() })
|
|
246
|
+
useJamUi.subscribe((s, p) => { if (s.laneKeys !== p.laneKeys) menuChanged() })
|
|
247
|
+
// Hide UI is a class on the body (Toolbar.tsx): its one source of truth
|
|
248
|
+
new MutationObserver(menuChanged).observe(document.body, { attributes: true, attributeFilter: ['class'] })
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// dev-only inspection hook for tests (never installed in published builds)
|
|
252
|
+
if (typeof window !== 'undefined' && import.meta.env.DEV) {
|
|
253
|
+
(window as unknown as { __mvApp: unknown }).__mvApp = { active: !!APP, busy: busyNow, menu: menuNow, asks: asksBeforeLeaving, leaveNow, page: PAGE_ID }
|
|
254
|
+
}
|