@marver-design/marver 0.26.0 → 0.27.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 +158 -0
- package/README.md +10 -5
- package/dist/{anchor-check-Dg5xpNnU.mjs → anchor-check-ChdDqL5z.mjs} +1 -1
- package/dist/{audio-CmSRYFEs.mjs → audio-Dw1lfMdb.mjs} +14 -0
- package/dist/{bake-DtVlm0_F.mjs → bake-DM_uWgAA.mjs} +1 -1
- package/dist/{boards-DYG22tOe.mjs → boards-DlTcpF47.mjs} +1 -1
- package/dist/{build-C_gUgcdC.mjs → build-DZnFysGU.mjs} +4 -4
- package/dist/{capture-CrqvU_jh.mjs → capture-vadKjuCo.mjs} +2 -1
- package/dist/cli.mjs +28 -16
- package/dist/{comments-BqXua-XL.mjs → comments-DxOkCSNE.mjs} +4 -4
- package/dist/{daemon-DZo6o3rU.mjs → daemon-BSA0lV8d.mjs} +400 -274
- package/dist/detect-C0wpaePX.mjs +125 -0
- package/dist/dev-eQJhWsqg.mjs +1273 -0
- package/dist/dev-lock-C_FC70Mu.mjs +65 -0
- package/dist/exclusive-B1RtpeeP.mjs +150 -0
- package/dist/{init-D8DtrK_F.mjs → init-COD0x48i.mjs} +5 -3
- package/dist/{link-BNzLvdhI.mjs → link-DDXZVGtv.mjs} +20 -8
- package/dist/ls-D7O1G505.mjs +38 -0
- package/dist/{marks-NQi0wZJ4.mjs → marks-CWM3WJjc.mjs} +1 -1
- package/dist/perf-BWzQwZqj.mjs +369 -0
- package/dist/perf-BoDSkbEb.mjs +429 -0
- package/dist/perf-jam-D55U3FZK.mjs +242 -0
- package/dist/{plugin-CTD0rydA.mjs → plugin-C-E7omsh.mjs} +425 -66
- package/dist/{poster-ChjXGTS5.mjs → poster-Bx83ZYVK.mjs} +2 -1
- package/dist/{profile-WU9qcbIo.mjs → profile-Bh5Y5zpW.mjs} +1 -1
- package/dist/{publish-bakes-CEP_2NRc.mjs → publish-bakes-aljgm45S.mjs} +2 -2
- package/dist/{queue-BuiCKSX1.mjs → queue-CAM_vNmX.mjs} +3 -3
- package/dist/recover-t9Pno3u9.mjs +66 -0
- package/dist/{session-qZWKt_VA.mjs → session-BAaJsK5c.mjs} +1 -1
- package/dist/{share--oFJ1bCI.mjs → share-W5H3BNvP.mjs} +1 -1
- package/dist/shot-DoHLl6ig.mjs +139 -0
- package/dist/{shot-DqcxJibP.mjs → shot-LFhC-WYD.mjs} +343 -19
- package/dist/slots-DCDo3N0x.mjs +471 -0
- package/dist/speech-worker.mjs +40 -5
- package/dist/{sync-DKk-yT1V.mjs → sync-BQVlHZpx.mjs} +4 -3
- package/dist/{work-F5u-twpJ.mjs → work-Bp1p39kq.mjs} +4 -2
- package/dist/{work-VvX_JIgl.mjs → work-BroFwnup.mjs} +4 -2
- package/docs/boards-and-folders.md +3 -1
- package/docs/jam-session.md +78 -7
- package/docs/live-jam.md +8 -0
- package/docs/performance.md +262 -0
- package/package.json +2 -2
- package/src/client/content/index.tsx +3 -0
- package/src/client/content/video.tsx +6 -2
- package/src/client/frame-host/bridge.js +22 -6
- package/src/client/frame-host/inspect.js +8 -3
- package/src/client/frame-host/keys.js +6 -2
- package/src/client/frame-host/main.tsx +17 -5
- package/src/client/shell/App.tsx +188 -29
- package/src/client/shell/BoardList.tsx +5 -5
- package/src/client/shell/Comments.tsx +3 -2
- package/src/client/shell/JamSurface.tsx +13 -5
- package/src/client/shell/LockedApp.tsx +5 -5
- package/src/client/shell/Play.tsx +27 -15
- package/src/client/shell/Toolbar.tsx +17 -5
- package/src/client/shell/api.ts +206 -0
- package/src/client/shell/canvas/Canvas.tsx +30 -3
- package/src/client/shell/canvas/FrameNode.tsx +15 -5
- package/src/client/shell/canvas/admission.ts +8 -1
- package/src/client/shell/canvas/camera-broadcast.ts +15 -5
- package/src/client/shell/canvas/ctl.ts +2 -0
- package/src/client/shell/canvas/frame-registry.ts +28 -2
- package/src/client/shell/canvas/sleep.ts +4 -1
- package/src/client/shell/comments-store.ts +12 -4
- package/src/client/shell/goto.ts +22 -10
- package/src/client/shell/icons.tsx +2 -0
- package/src/client/shell/jam-capture.ts +96 -16
- package/src/client/shell/jam-keys.ts +51 -18
- package/src/client/shell/jam-lane.tsx +46 -5
- package/src/client/shell/jam-panel.tsx +66 -13
- package/src/client/shell/jam-queue.ts +3 -3
- package/src/client/shell/jam-session.tsx +14 -8
- package/src/client/shell/jam-state.ts +48 -6
- package/src/client/shell/jam-surface-parts.tsx +10 -6
- package/src/client/shell/jam-voice.ts +7 -5
- package/src/client/shell/legacy-links.ts +2 -2
- package/src/client/shell/main.tsx +4 -0
- package/src/client/shell/notes.ts +8 -1
- package/src/client/shell/perf.ts +69 -58
- package/src/client/shell/recorder-core.ts +183 -0
- package/src/client/shell/recorder.ts +565 -0
- package/src/client/shell/store.ts +268 -103
- package/src/client/shell/styles.css +54 -9
- package/src/client/stage/main.tsx +2 -0
- package/templates/AGENTS-embedded.md +22 -4
- package/templates/AGENTS-studio.md +22 -4
- package/templates/demo/dark.tsx +1 -1
- package/templates/demo/welcome.tsx +1 -1
- package/templates/instructions/jam.md +5 -3
- package/templates/instructions/welcome.md +6 -3
- package/dist/config-Cf7EjAMf.mjs +0 -292
- package/dist/dev-_Nlsc6v9.mjs +0 -742
- package/dist/dev-lock-DWSpa6nj.mjs +0 -179
- package/dist/perf-D6VmmJ2q.mjs +0 -68
- package/dist/perf-DPbLGhhO.mjs +0 -49
- package/dist/shot-CNbHoZ6H.mjs +0 -86
|
@@ -11,8 +11,34 @@
|
|
|
11
11
|
export interface FrameReg { key: string; iframe: HTMLIFrameElement }
|
|
12
12
|
|
|
13
13
|
const byWindow = new WeakMap<WindowProxy, FrameReg>()
|
|
14
|
+
const byKey = new Map<string, HTMLIFrameElement>()
|
|
14
15
|
|
|
15
|
-
export const registerFrame = (win: WindowProxy, reg: FrameReg): void => { byWindow.set(win, reg) }
|
|
16
|
-
export const unregisterFrame = (win: WindowProxy): void => {
|
|
16
|
+
export const registerFrame = (win: WindowProxy, reg: FrameReg): void => { byWindow.set(win, reg); byKey.set(reg.key, reg.iframe) }
|
|
17
|
+
export const unregisterFrame = (win: WindowProxy): void => {
|
|
18
|
+
const reg = byWindow.get(win)
|
|
19
|
+
byWindow.delete(win)
|
|
20
|
+
if (reg && byKey.get(reg.key) === reg.iframe) byKey.delete(reg.key)
|
|
21
|
+
}
|
|
22
|
+
/** The iframe a node shows now - the recorder reads its live document's id off it (spec 28 A1.7). */
|
|
23
|
+
export const iframeOf = (key: string): HTMLIFrameElement | undefined => byKey.get(key)
|
|
17
24
|
export const frameByWindow = (win: unknown): FrameReg | undefined =>
|
|
18
25
|
win ? byWindow.get(win as WindowProxy) : undefined
|
|
26
|
+
|
|
27
|
+
/** The id of the document an iframe shows now, as its frame bridge set it (`__mvBoot`, spec 28 A1.7) - absent while a
|
|
28
|
+
* new document has not run its bridge yet, or when the frame was navigated off this origin (the read throws). */
|
|
29
|
+
export function bootOf(iframe: HTMLIFrameElement | undefined): string | undefined {
|
|
30
|
+
try {
|
|
31
|
+
const b = (iframe?.contentWindow as { __mvBoot?: unknown } | null | undefined)?.__mvBoot
|
|
32
|
+
return typeof b === 'string' ? b : undefined
|
|
33
|
+
} catch { return undefined }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A frame's message comes from the document its iframe shows now: the URL revision the shell gave that document
|
|
37
|
+
* (`gen`, against the iframe's src) and the document's own id (`boot`, against the live one). A WindowProxy survives
|
|
38
|
+
* navigation, and a same-URL reload keeps `gen`, so only both tell the document there now from one since replaced
|
|
39
|
+
* whose message was still on its way. Asked before a message changes anything. */
|
|
40
|
+
export function fromLiveDocument(iframe: HTMLIFrameElement, data: { gen?: unknown; boot?: unknown }): boolean {
|
|
41
|
+
const gen = iframe.src.match(/[?&]r=(\d+)/)?.[1] ?? ''
|
|
42
|
+
if (String(data.gen ?? '') !== gen) return false
|
|
43
|
+
return typeof data.boot === 'string' && data.boot !== '' && data.boot === bootOf(iframe)
|
|
44
|
+
}
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
*/
|
|
28
28
|
import { ROUTE } from '../../const.ts'
|
|
29
29
|
import { BAKES, PUBLISHED } from '../store.ts'
|
|
30
|
+
import { api } from '../api.ts'
|
|
30
31
|
import { readOwn, sleepRule } from '../../../shared/sleep-rule.ts'
|
|
31
32
|
|
|
32
33
|
/** `doc`: the revision the document shows (spec 26) - the compiler refuses a document behind its frame */
|
|
@@ -48,6 +49,8 @@ const keyOf = (k: SleepKey) => `${k.frame}|${k.theme}|${Math.round(k.w)}|${Math.
|
|
|
48
49
|
|
|
49
50
|
/** What a node's DOCUMENT is asleep under, published only once its override is INSTALLED. */
|
|
50
51
|
const asleep = new Map<string, { key: string; doc: Document }>()
|
|
52
|
+
/** How many frames are asleep now (the recorder's weight of a settled load, spec 28 A1.7). */
|
|
53
|
+
export const sleepingCount = (): number => asleep.size
|
|
51
54
|
/** The node's current request, so a stale answer (a newer sleep, a wake in between) is dropped. */
|
|
52
55
|
const pending = new Map<string, number>()
|
|
53
56
|
let seq = 0
|
|
@@ -95,7 +98,7 @@ function ask(key: SleepKey): Promise<Answer> {
|
|
|
95
98
|
const index = PUBLISHED ? await staticAnswers() : null
|
|
96
99
|
if (!index) {
|
|
97
100
|
try {
|
|
98
|
-
const r = await
|
|
101
|
+
const r = await api('bakes', { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() }, body: JSON.stringify({ asks }) })
|
|
99
102
|
data = r.ok ? await r.json() : null
|
|
100
103
|
} catch { data = null }
|
|
101
104
|
}
|
|
@@ -11,6 +11,7 @@ import { playPing } from './sound.ts'
|
|
|
11
11
|
import { ROUTE } from '../const.ts'
|
|
12
12
|
import { ALL_SCENES } from '../../shared/board-tree.ts'
|
|
13
13
|
import { UNPLACED } from './hash.ts'
|
|
14
|
+
import { api as request, canvasStopped, scoped, stoppedLink, useLink } from './api.ts'
|
|
14
15
|
|
|
15
16
|
/** What the Not on a board view says when asked for a comment: a note needs a board to live on. */
|
|
16
17
|
export const NO_COMMENTS_HERE = 'pin it on a board to comment'
|
|
@@ -81,11 +82,11 @@ interface CommentsState {
|
|
|
81
82
|
|
|
82
83
|
const uuid = () => crypto.randomUUID()
|
|
83
84
|
const loadMentionSeen = (): Record<string, number> => {
|
|
84
|
-
try { return JSON.parse(localStorage.getItem('mv-mention-seen') ?? '{}') } catch { return {} }
|
|
85
|
+
try { return JSON.parse(localStorage.getItem(scoped('mv-mention-seen')) ?? '{}') } catch { return {} }
|
|
85
86
|
}
|
|
86
87
|
const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
|
|
87
88
|
const api = async (path: string, body?: unknown) => {
|
|
88
|
-
const res = await
|
|
89
|
+
const res = await request(path, body === undefined ? undefined : {
|
|
89
90
|
method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() },
|
|
90
91
|
body: JSON.stringify(body),
|
|
91
92
|
})
|
|
@@ -360,14 +361,15 @@ export const useComments = create<CommentsState>((set, get) => {
|
|
|
360
361
|
},
|
|
361
362
|
|
|
362
363
|
// the Not on a board view shows threads but takes no new ones (spec 26): a note needs a board
|
|
363
|
-
|
|
364
|
+
// never on while the canvas is stopped (spec 28 A1.11): a comment picked could not be sent
|
|
365
|
+
setMode(on) { if (on && (get().board === UNPLACED || canvasStopped())) return; set({ commentMode: on, ...(on ? { show: true } : { draft: null }) }) },
|
|
364
366
|
setShow(show) { set({ show }) },
|
|
365
367
|
setShowAnchor(showAnchor) { set({ showAnchor }) },
|
|
366
368
|
setActive(active) {
|
|
367
369
|
// opening a thread is SEEING it - the mention pulse for it stops here
|
|
368
370
|
if (active) {
|
|
369
371
|
const mentionSeen = { ...get().mentionSeen, [active]: Date.now() }
|
|
370
|
-
try { localStorage.setItem('mv-mention-seen', JSON.stringify(mentionSeen)) } catch { /* private mode */ }
|
|
372
|
+
try { localStorage.setItem(scoped('mv-mention-seen'), JSON.stringify(mentionSeen)) } catch { /* private mode */ }
|
|
371
373
|
set({ active, mentionSeen })
|
|
372
374
|
} else set({ active })
|
|
373
375
|
},
|
|
@@ -403,6 +405,12 @@ export const useComments = create<CommentsState>((set, get) => {
|
|
|
403
405
|
}
|
|
404
406
|
})
|
|
405
407
|
|
|
408
|
+
// the canvas stopped (spec 28 A1.11): comment mode goes off - a pick could open only a comment that cannot be
|
|
409
|
+
// sent. A comment being written stays, words and all.
|
|
410
|
+
useLink.subscribe((l, p) => {
|
|
411
|
+
if (stoppedLink(l.link) && !stoppedLink(p.link) && useComments.getState().commentMode && !useComments.getState().draft) useComments.getState().setMode(false)
|
|
412
|
+
})
|
|
413
|
+
|
|
406
414
|
// dev-only debug handle - the canvas store exposes the same
|
|
407
415
|
if (typeof window !== 'undefined' && (import.meta as any).env?.DEV) (window as any).__mvComments = useComments
|
|
408
416
|
|
package/src/client/shell/goto.ts
CHANGED
|
@@ -13,10 +13,10 @@ export function goTo(target: string, carry = false): void {
|
|
|
13
13
|
const s = useStore.getState()
|
|
14
14
|
const existing = s.nodes.find((n) => n.frame === target && !n.missing)
|
|
15
15
|
if (existing) {
|
|
16
|
-
navigated()
|
|
16
|
+
const seq = navigated() // a local goto supersedes any cross-board one in flight
|
|
17
17
|
s.select(existing.key)
|
|
18
18
|
if (carry) s.setInteract(existing.key)
|
|
19
|
-
|
|
19
|
+
fitLater(existing.key, seq)
|
|
20
20
|
} else void gotoAcrossBoards(target, carry)
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -50,7 +50,7 @@ async function gotoAcrossBoards(target: string, carry: boolean) {
|
|
|
50
50
|
if (!node) return st.toast(`unknown goto target "${target}"`)
|
|
51
51
|
st.select(node.key)
|
|
52
52
|
if (carry) st.setInteract(node.key)
|
|
53
|
-
|
|
53
|
+
fitLater(node.key, seq)
|
|
54
54
|
return
|
|
55
55
|
}
|
|
56
56
|
await landOn(home, target, carry, seq, from)
|
|
@@ -59,7 +59,8 @@ async function gotoAcrossBoards(target: string, carry: boolean) {
|
|
|
59
59
|
/** Navigation supersedes any goto or reveal still on its way - its board lookup (gotoSeq) AND a board
|
|
60
60
|
* switch it already started (a switch to the board on screen cancels any pending one: store.ts) - so
|
|
61
61
|
* a slow lookup can never yank the view away from where the human has gone since. Every entry point
|
|
62
|
-
* calls it: a pasted link, back/forward, a goto, a reveal, a board picked in
|
|
62
|
+
* calls it, the published shell's too: a pasted link, back/forward, a goto, a reveal, a board picked in
|
|
63
|
+
* the sidebar or the play pill, a notification's View - and switches boards only through switchFor. */
|
|
63
64
|
export function navigated(): number {
|
|
64
65
|
const s = useStore.getState()
|
|
65
66
|
if (s.board) void s.switchBoard(s.board)
|
|
@@ -67,12 +68,23 @@ export function navigated(): number {
|
|
|
67
68
|
}
|
|
68
69
|
/** Is this still the latest navigation - nothing newer since `navigated()` handed it out? */
|
|
69
70
|
export const isLatest = (seq: number): boolean => seq === gotoSeq
|
|
71
|
+
/** The one way a navigation changes boards - a link, a goto, a reveal, a board picked in the sidebar or the play pill, a
|
|
72
|
+
* notification's View: the switch is navigation `nav`'s (a new one, unless the caller took it at its own start, before
|
|
73
|
+
* a lookup), and true only once it landed with nothing newer since. What the caller does on the board - select, set a
|
|
74
|
+
* mode, enter play, move the camera - waits for true: a switch a newer navigation cancelled comes back too, and may
|
|
75
|
+
* find the board it asked for, the newer one's by then. */
|
|
76
|
+
export async function switchFor(board: string, nav: number = navigated()): Promise<boolean> {
|
|
77
|
+
await useStore.getState().switchBoard(board)
|
|
78
|
+
return isLatest(nav) && useStore.getState().board === board
|
|
79
|
+
}
|
|
80
|
+
/** The camera to a node once it is drawn - unless a newer navigation has it by then. */
|
|
81
|
+
const fitLater = (key: string, seq: number) => setTimeout(() => { if (isLatest(seq)) canvasCtl.fitNode(key) }, 50)
|
|
70
82
|
|
|
71
83
|
/** Switch to `home` and select + fit `target` there once the board commits - unless the human has
|
|
72
84
|
* moved on: newer navigation, or a board they switched to themselves while the lookup ran. */
|
|
73
85
|
async function landOn(home: string, target: string, carry: boolean, seq: number, from: string) {
|
|
74
86
|
if (seq !== gotoSeq || useStore.getState().board !== from) return
|
|
75
|
-
await
|
|
87
|
+
if (!await switchFor(home, seq)) return
|
|
76
88
|
for (let i = 0; i < 12; i++) { // the board commits async - retry like viewNote
|
|
77
89
|
if (seq !== gotoSeq) return
|
|
78
90
|
const st = useStore.getState()
|
|
@@ -81,7 +93,7 @@ async function landOn(home: string, target: string, carry: boolean, seq: number,
|
|
|
81
93
|
if (node) {
|
|
82
94
|
st.select(node.key)
|
|
83
95
|
if (carry) st.setInteract(node.key)
|
|
84
|
-
|
|
96
|
+
fitLater(node.key, seq)
|
|
85
97
|
return
|
|
86
98
|
}
|
|
87
99
|
}
|
|
@@ -93,17 +105,17 @@ async function landOn(home: string, target: string, carry: boolean, seq: number,
|
|
|
93
105
|
* not show, the way back from a focus link): this board, else the first board that shows it
|
|
94
106
|
* (archive boards last), else - a frame on no board - the Not on a board view. Unlike a goto it
|
|
95
107
|
* never spawns - opening a link must not edit a board. */
|
|
96
|
-
export async function revealFrame(target: string): Promise<void> {
|
|
108
|
+
export async function revealFrame(target: string, nav?: number): Promise<void> { // `nav`: a caller's navigation, else its own
|
|
97
109
|
const s = useStore.getState()
|
|
98
110
|
const here = s.nodes.find((n) => n.frame === target && !n.missing)
|
|
99
111
|
if (here) {
|
|
100
|
-
navigated()
|
|
112
|
+
const seq = nav ?? navigated()
|
|
101
113
|
s.select(here.key)
|
|
102
|
-
|
|
114
|
+
fitLater(here.key, seq)
|
|
103
115
|
return
|
|
104
116
|
}
|
|
105
117
|
if (!s.manifest?.frames.some((f) => f.id === target)) return s.toast(`no frame "${target}" on this canvas`)
|
|
106
|
-
const seq = navigated()
|
|
118
|
+
const seq = nav ?? navigated()
|
|
107
119
|
const from = s.board
|
|
108
120
|
let home: string | null = null
|
|
109
121
|
try {
|
|
@@ -20,6 +20,8 @@ const icon = (children: ReactNode) =>
|
|
|
20
20
|
export const SunIcon = icon(<path d="M120,40V16a8,8,0,0,1,16,0V40a8,8,0,0,1-16,0Zm72,88a64,64,0,1,1-64-64A64.07,64.07,0,0,1,192,128Zm-16,0a48,48,0,1,0-48,48A48.05,48.05,0,0,0,176,128ZM58.34,69.66A8,8,0,0,0,69.66,58.34l-16-16A8,8,0,0,0,42.34,53.66Zm0,116.68-16,16a8,8,0,0,0,11.32,11.32l16-16a8,8,0,0,0-11.32-11.32ZM192,72a8,8,0,0,0,5.66-2.34l16-16a8,8,0,0,0-11.32-11.32l-16,16A8,8,0,0,0,192,72Zm5.66,114.34a8,8,0,0,0-11.32,11.32l16,16a8,8,0,0,0,11.32-11.32ZM48,128a8,8,0,0,0-8-8H16a8,8,0,0,0,0,16H40A8,8,0,0,0,48,128Zm80,80a8,8,0,0,0-8,8v24a8,8,0,0,0,16,0V216A8,8,0,0,0,128,208Zm112-88H216a8,8,0,0,0,0,16h24a8,8,0,0,0,0-16Z" />)
|
|
21
21
|
export const MoonIcon = icon(<path d="M233.54,142.23a8,8,0,0,0-8-2,88.08,88.08,0,0,1-109.8-109.8,8,8,0,0,0-10-10,104.84,104.84,0,0,0-52.91,37A104,104,0,0,0,136,224a103.09,103.09,0,0,0,62.52-20.88,104.84,104.84,0,0,0,37-52.91A8,8,0,0,0,233.54,142.23ZM188.9,190.34A88,88,0,0,1,65.66,67.11a89,89,0,0,1,31.4-26A106,106,0,0,0,96,56,104.11,104.11,0,0,0,200,160a106,106,0,0,0,14.92-1.06A89,89,0,0,1,188.9,190.34Z" />)
|
|
22
22
|
export const CaretIcon = icon(<path d="M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z" />)
|
|
23
|
+
/** arrows-in-line-horizontal: fold a row in on itself (the lane's Done tiles) */
|
|
24
|
+
export const ArrowsInLineHorizontalIcon = icon(<path d="M136,40V216a8,8,0,0,1-16,0V40a8,8,0,0,1,16,0ZM69.66,90.34a8,8,0,0,0-11.32,11.32L76.69,120H16a8,8,0,0,0,0,16H76.69L58.34,154.34a8,8,0,0,0,11.32,11.32l32-32a8,8,0,0,0,0-11.32ZM240,120H179.31l18.35-18.34a8,8,0,0,0-11.32-11.32l-32,32a8,8,0,0,0,0,11.32l32,32a8,8,0,0,0,11.32-11.32L179.31,136H240a8,8,0,0,0,0-16Z" />)
|
|
23
25
|
export const PlayIcon = icon(<path d="M232.4,114.49,88.32,26.35a16,16,0,0,0-16.2-.3A15.86,15.86,0,0,0,64,39.87V216.13A15.94,15.94,0,0,0,80,232a16.07,16.07,0,0,0,8.36-2.35L232.4,141.51a15.81,15.81,0,0,0,0-27ZM80,215.94V40l143.83,88Z" />)
|
|
24
26
|
export const GridIcon = icon(<path d="M104,40H56A16,16,0,0,0,40,56v48a16,16,0,0,0,16,16h48a16,16,0,0,0,16-16V56A16,16,0,0,0,104,40Zm0,64H56V56h48v48Zm96-64H152a16,16,0,0,0-16,16v48a16,16,0,0,0,16,16h48a16,16,0,0,0,16-16V56A16,16,0,0,0,200,40Zm0,64H152V56h48v48Zm-96,32H56a16,16,0,0,0-16,16v48a16,16,0,0,0,16,16h48a16,16,0,0,0,16-16V152A16,16,0,0,0,104,136Zm0,64H56V152h48v48Zm96-64H152a16,16,0,0,0-16,16v48a16,16,0,0,0,16,16h48a16,16,0,0,0,16-16V152A16,16,0,0,0,200,136Zm0,64H152V152h48v48Z" />)
|
|
25
27
|
export const CopyIcon = icon(<path d="M216,32H88a8,8,0,0,0-8,8V80H40a8,8,0,0,0-8,8V216a8,8,0,0,0,8,8H168a8,8,0,0,0,8-8V176h40a8,8,0,0,0,8-8V40A8,8,0,0,0,216,32ZM160,208H48V96H160Zm48-48H176V88a8,8,0,0,0-8-8H96V48H208Z" />)
|
|
@@ -14,13 +14,15 @@
|
|
|
14
14
|
* id it carries.
|
|
15
15
|
*/
|
|
16
16
|
import { create } from 'zustand'
|
|
17
|
-
import {
|
|
18
|
-
import { CONFIG, SLIDE_INTRINSIC, useStore, type Node } from './store.ts'
|
|
17
|
+
import { slideSize } from '../const.ts'
|
|
18
|
+
import { CONFIG, SLIDE_INTRINSIC, stoppedFor, useStore, type Node } from './store.ts'
|
|
19
19
|
import { UNPLACED } from './hash.ts'
|
|
20
20
|
import type { Bundle, CaptureRecord, Step, View } from '../../server/jam/types.ts'
|
|
21
21
|
import { forgetHeard, RATE, setWordsListener, voiceBegin, voiceDrop, voiceEnd } from './jam-voice.ts'
|
|
22
22
|
import { touchedFrames } from '../../shared/capture-frames.ts'
|
|
23
23
|
import { onStageSize, stageSize } from './stage-size.ts'
|
|
24
|
+
import { api, holdsReload } from './api.ts'
|
|
25
|
+
import { bytesOf } from './recorder-core.ts'
|
|
24
26
|
|
|
25
27
|
const csrf = () => /(?:^|;\s*)mv_c=([\w-]+)/.exec(document.cookie)?.[1] ?? ''
|
|
26
28
|
const now = () => performance.timeOrigin + performance.now()
|
|
@@ -90,6 +92,8 @@ interface Cap {
|
|
|
90
92
|
pictures: string[]
|
|
91
93
|
probes: number // probe answers still out
|
|
92
94
|
shots: number // picture requests still out
|
|
95
|
+
/** its timing (spec 27a Part D): when E was pressed, the wait for its last words, each picture's time, the missing ones */
|
|
96
|
+
timing?: { endAt?: number; wordsMs?: number; pics: number[]; late: number; failed: number }
|
|
93
97
|
shotFrames: string[] // frames pictured (or being pictured) in it: an automatic picture is taken once per frame
|
|
94
98
|
endShot?: boolean // its end pictures were asked for (once its steps were all in)
|
|
95
99
|
inherited?: string[] // Resume: the frames the capture it continues was about (its card's)
|
|
@@ -530,11 +534,14 @@ function shoot(id: string, frame: string, why: 'key' | 'pick' | 'end', key?: str
|
|
|
530
534
|
const size = atEnd ? { width: atEnd.w, height: atEnd.h } : onStage ? { width: onStage.w, height: onStage.h } : seen?.play && why !== 'key' ? { width: seen.w, height: seen.h } : n ? { width: n.w, height: n.h } : undefined
|
|
531
535
|
const theme = st.play && st.play.at === frame ? st.play.theme : n?.theme ?? st.viewTheme
|
|
532
536
|
mutate((s) => { const x = s.caps[id]; if (x) x.shots += 1 })
|
|
537
|
+
const t0 = performance.now()
|
|
533
538
|
const done = (pid: string | null, late: boolean) => {
|
|
534
539
|
mutate((s) => {
|
|
535
540
|
const x = s.caps[id]
|
|
536
541
|
if (!x) return
|
|
537
542
|
x.shots -= 1
|
|
543
|
+
const tm = (x.timing ??= { pics: [], late: 0, failed: 0 })
|
|
544
|
+
if (pid) tm.pics.push(Math.round(performance.now() - t0)); else if (late) tm.late++; else tm.failed++
|
|
538
545
|
if (pid) { x.pictures.push(pid); x.steps.push({ at, frame, event: 'picture', id: pid, why }) }
|
|
539
546
|
else x.steps.push({ at, frame, event: 'missing', what: `no picture of ${frame} - ${late ? `it took over ${PICTURE_MS / 1000} s` : 'the render failed'}` })
|
|
540
547
|
})
|
|
@@ -545,7 +552,7 @@ function shoot(id: string, frame: string, why: 'key' | 'pick' | 'end', key?: str
|
|
|
545
552
|
// settled exactly once - a picture, or a missing one - whatever fails: the request, its body, the abort
|
|
546
553
|
let settled = false
|
|
547
554
|
const finish = (pid: string | null) => { if (settled) return; settled = true; clearTimeout(timer); done(pid, ctl.signal.aborted) }
|
|
548
|
-
|
|
555
|
+
api('jam/picture', {
|
|
549
556
|
method: 'POST', signal: ctl.signal, headers: { 'content-type': 'application/json', 'x-mv-c': csrf() },
|
|
550
557
|
body: JSON.stringify({ capture: id, frame, theme, ...(size ? { w: Math.round(size.width), h: Math.round(size.height) } : {}) }),
|
|
551
558
|
}).then(async (r) => (r.ok ? ((await r.json()) as { id?: string }).id ?? null : null))
|
|
@@ -565,7 +572,7 @@ export const setSessionEnding = (on: boolean) => { sessionEnding = on }
|
|
|
565
572
|
* that every 20 s until it lands or is dropped: the session's record waits for it, whatever tab ends it. */
|
|
566
573
|
const openOnServer = new Map<string, { session: string; timer: ReturnType<typeof setInterval> }>()
|
|
567
574
|
const tellOpen = (capture: string, session: string, on: boolean) => {
|
|
568
|
-
void
|
|
575
|
+
void api('jam/capture-open', { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() }, body: JSON.stringify({ capture, session, on }) })
|
|
569
576
|
.then(async (r) => { if (on && r.status === 409 && (await r.json().catch(() => null))?.ended) leftOutOfSession(capture) }, () => {})
|
|
570
577
|
}
|
|
571
578
|
/** The server had already written the session's record (in another tab) when it heard of this capture: it is
|
|
@@ -664,6 +671,7 @@ function drain(id: string) {
|
|
|
664
671
|
const x = st.caps[id]
|
|
665
672
|
if (!x) return
|
|
666
673
|
x.state = 'draining'
|
|
674
|
+
;(x.timing ??= { pics: [], late: 0, failed: 0 }).endAt = performance.now()
|
|
667
675
|
// its frames' sizes as they are at E - a resize while it finishes is not part of it; and every instance as it
|
|
668
676
|
// is at E, for a step that answers late (a hover still in flight names a frame then)
|
|
669
677
|
x.endSizes = framesSizes(x)
|
|
@@ -680,11 +688,13 @@ function drain(id: string) {
|
|
|
680
688
|
broadcast({ type: 'sh:capture', id, on: false })
|
|
681
689
|
// the audio is cut at the key press, then its last words are awaited (3 s at most)
|
|
682
690
|
mutate((st) => { const x = st.caps[id]; if (x) x.hearing = true })
|
|
691
|
+
const tWords = performance.now()
|
|
683
692
|
void voiceEnd(id).then((complete) => {
|
|
684
693
|
mutate((st) => {
|
|
685
694
|
const x = st.caps[id]
|
|
686
695
|
if (!x) return
|
|
687
696
|
x.hearing = false
|
|
697
|
+
;(x.timing ??= { pics: [], late: 0, failed: 0 }).wordsMs = Math.round(performance.now() - tWords)
|
|
688
698
|
if (!complete) x.steps.push({ at: now(), event: 'missing', what: 'words may be incomplete' })
|
|
689
699
|
})
|
|
690
700
|
trySeal(id)
|
|
@@ -751,6 +761,31 @@ function sealedSizes(c: Cap): Record<string, { w: number; h: number; play?: true
|
|
|
751
761
|
return out
|
|
752
762
|
}
|
|
753
763
|
|
|
764
|
+
/** Jam timings (spec 27a Part D): numbers only, to the dev server's local log - best effort, never in the way. */
|
|
765
|
+
const perf = (body: Record<string, unknown>, keepalive = false) => {
|
|
766
|
+
try { void api('perf/jam', { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() }, body: JSON.stringify(body), ...(keepalive ? { keepalive: true } : {}) }).catch(() => {}) } catch { /* never in the way */ }
|
|
767
|
+
}
|
|
768
|
+
/** A capture's timing as it seals: E to sealed (none when the page sealed it), the wait for its words, its pictures. */
|
|
769
|
+
function timeCapture(c: Cap, interrupted: boolean) {
|
|
770
|
+
const t = c.timing
|
|
771
|
+
perf({ kind: 'capture', capture: c.id, ...(t?.endAt !== undefined && !interrupted ? { sealMs: performance.now() - t.endAt } : {}),
|
|
772
|
+
...(t?.wordsMs !== undefined ? { wordsWaitMs: t.wordsMs } : {}),
|
|
773
|
+
pictures: { count: t?.pics.length ?? 0, ms: t?.pics ?? [], late: t?.late ?? 0, failed: t?.failed ?? 0 }, ...(interrupted ? { interrupted: true } : {}) }, interrupted)
|
|
774
|
+
}
|
|
775
|
+
const uploadTries = new Map<string, number>()
|
|
776
|
+
|
|
777
|
+
/** A capture's sealed record: its steps in time order, internal fields stripped, its context, view, pictures and
|
|
778
|
+
* sizes. `interrupted`: sealed by its page leaving, as it stood. */
|
|
779
|
+
function buildRecord(c: Cap, steps: Cap['steps'], interrupted = false): CaptureRecord {
|
|
780
|
+
const timeline = [...steps].sort((a, b) => a.at - b.at || (a.seq ?? 0) - (b.seq ?? 0)).map(({ seq: _s, src: _k, ...step }) => step as Step)
|
|
781
|
+
return {
|
|
782
|
+
format: 'marver.jam.capture', v: 1, id: c.id,
|
|
783
|
+
context: { canvas: location.host, board: c.board, ...(c.session ? { session: c.session } : {}), ...(c.reviewing ? { reviewing: c.reviewing } : {}), ...(c.resumes ? { resumes: c.resumes } : {}), ...(interrupted ? { interrupted: true as const } : {}) },
|
|
784
|
+
view: (timeline.find((x) => x.event === 'view') as Extract<Step, { event: 'view' }> | undefined)?.view ?? {},
|
|
785
|
+
timeline, pictures: c.pictures, ...(() => { const sizes = sealedSizes(c); return Object.keys(sizes).length ? { sizes } : {} })(),
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
754
789
|
function trySeal(id: string) {
|
|
755
790
|
const c = capOf(id)
|
|
756
791
|
if (!c || c.state !== 'draining' || c.flushWait.size || c.probes > 0) return
|
|
@@ -759,13 +794,8 @@ function trySeal(id: string) {
|
|
|
759
794
|
if (!c.endShot) endPictures(id)
|
|
760
795
|
const c2 = capOf(id)
|
|
761
796
|
if (!c2 || c2.shots > 0 || c2.hearing) return
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
format: 'marver.jam.capture', v: 1, id,
|
|
765
|
-
context: { canvas: location.host, board: c.board, ...(c.session ? { session: c.session } : {}), ...(c.reviewing ? { reviewing: c.reviewing } : {}), ...(c.resumes ? { resumes: c.resumes } : {}) },
|
|
766
|
-
view: (timeline.find((x) => x.event === 'view') as Extract<Step, { event: 'view' }> | undefined)?.view ?? {},
|
|
767
|
-
timeline, pictures: c2.pictures, ...(() => { const sizes = sealedSizes(c2); return Object.keys(sizes).length ? { sizes } : {} })(),
|
|
768
|
-
}
|
|
797
|
+
const record = buildRecord(c2, c2.steps)
|
|
798
|
+
timeCapture(c2, false)
|
|
769
799
|
// sealed: drop everything for this id that arrives later
|
|
770
800
|
useJamCapture.setState((st) => { const caps = { ...st.caps }; delete caps[id]; return { caps, tick: st.tick + 1, sealed: [...st.sealed, { id }] } })
|
|
771
801
|
forgetHeard(id)
|
|
@@ -778,24 +808,34 @@ function trySeal(id: string) {
|
|
|
778
808
|
/** Kept per workspace: another project served later on the same port never receives this one's captures. */
|
|
779
809
|
const KEPT = `mv-jam-sealed:${CONFIG.workspace ?? 'unknown'}`
|
|
780
810
|
const syncUnsent = () => useJamCapture.setState({ unsent: [...pendingUploads.keys()] })
|
|
811
|
+
/** A capture is still open (a page that goes seals and sends it), or sealed and not taken by the server yet (waiting,
|
|
812
|
+
* or on its way): the recorder leaves a page's keepalive allowance to it (spec 28 A1.7). By state, not by the order
|
|
813
|
+
* the pagehide listeners run in. */
|
|
814
|
+
export const capturesPending = (): boolean => { const s = useJamCapture.getState(); return s.unsent.length > 0 || Object.keys(s.caps).length > 0 }
|
|
781
815
|
const keepSealed = (r: CaptureRecord) => { try { const all = JSON.parse(localStorage.getItem(KEPT) ?? '{}'); all[r.id] = r; localStorage.setItem(KEPT, JSON.stringify(all)) } catch { /* memory only */ } pendingUploads.set(r.id, r); syncUnsent() }
|
|
782
816
|
const forgetSealed = (id: string) => { pendingUploads.delete(id); syncUnsent(); try { const all = JSON.parse(localStorage.getItem(KEPT) ?? '{}'); delete all[id]; localStorage.setItem(KEPT, JSON.stringify(all)) } catch { /* memory only */ } }
|
|
783
817
|
const pendingUploads = new Map<string, CaptureRecord>()
|
|
784
818
|
let retryTimer: ReturnType<typeof setTimeout> | null = null
|
|
785
819
|
/** Post a sealed record - the same id, idempotent on the server - until it takes. A refusal about the
|
|
786
820
|
* record itself (not the network) is final and said once; a dev server that is away is waited for. */
|
|
787
|
-
async function upload(record: CaptureRecord): Promise<void> {
|
|
821
|
+
async function upload(record: CaptureRecord, leaving = false): Promise<void> {
|
|
788
822
|
type Verdict = { ok?: boolean; card?: { id: string; rev: number }; error?: string; outside?: boolean }
|
|
789
823
|
let r: Verdict | null = null
|
|
790
824
|
try {
|
|
791
825
|
// the workspace it was made in travels with it: another project served on this port refuses it
|
|
792
|
-
|
|
826
|
+
uploadTries.set(record.id, (uploadTries.get(record.id) ?? 0) + 1)
|
|
827
|
+
const tUp = performance.now()
|
|
828
|
+
const payload = JSON.stringify({ record, workspace: CONFIG.workspace })
|
|
829
|
+
// a page that is going sends with keepalive (64 kB at most, counted in UTF-8 bytes as the body carries it - not
|
|
830
|
+
// `.length`: notes in another script are wider) so the request outlives it; a bigger one, the next page
|
|
831
|
+
const res = await api('jam/capture', { method: 'POST', headers: { 'content-type': 'application/json', 'x-mv-c': csrf() }, body: payload, ...(leaving && bytesOf(payload) < 60_000 ? { keepalive: true } : {}) })
|
|
793
832
|
const body = (await res.json().catch(() => null)) as Verdict | null
|
|
794
833
|
// only an explicit verdict on THIS record is final: taken (200, naming its card) or refused as a
|
|
795
834
|
// record (400, saying why). Anything else - jam not running yet, another workspace, an unreadable
|
|
796
835
|
// answer, a gate, a server error - is the server being away: keep it and try again
|
|
797
836
|
r = res.ok && body?.ok === true && body.card?.id === record.id ? body
|
|
798
837
|
: res.status === 400 && body && typeof body.error === 'string' ? body : null
|
|
838
|
+
if (r?.ok) { perf({ kind: 'upload', capture: record.id, ms: performance.now() - tUp, tries: uploadTries.get(record.id) ?? 1 }, leaving); uploadTries.delete(record.id) }
|
|
799
839
|
} catch { r = null }
|
|
800
840
|
if (!r) {
|
|
801
841
|
if (!retryTimer) useStore.getState().toast('the capture is kept here and will be sent when marver dev answers')
|
|
@@ -813,8 +853,12 @@ async function upload(record: CaptureRecord): Promise<void> {
|
|
|
813
853
|
else if (r.outside) leftOutOfSession(record.id)
|
|
814
854
|
}
|
|
815
855
|
|
|
816
|
-
/** A capture still recording, or finishing (its pictures and words coming in), lives only in this page
|
|
817
|
-
*
|
|
856
|
+
/** A capture still recording, or finishing (its pictures and last words coming in), lives only in this page until it
|
|
857
|
+
* seals; a sealed one is kept in localStorage until it lands. Leaving the page asks first - and if you leave anyway
|
|
858
|
+
* (`pagehide`: a close, a reload, a navigation, the back-forward cache alike), every capture not sealed yet is sealed
|
|
859
|
+
* at once, as it stood, for good: a missing step says so, the server keeps it as a draft, and it goes out like any
|
|
860
|
+
* sealed record not sent yet - from the next page, or this one if it comes back. Carrying on is Resume, with a new id.
|
|
861
|
+
* Best effort: a crash or a killed process fires nothing. */
|
|
818
862
|
let guarded = false
|
|
819
863
|
function guardUnload() {
|
|
820
864
|
if (guarded || typeof window === 'undefined') return
|
|
@@ -824,6 +868,35 @@ function guardUnload() {
|
|
|
824
868
|
e.preventDefault()
|
|
825
869
|
e.returnValue = ''
|
|
826
870
|
})
|
|
871
|
+
window.addEventListener('pagehide', () => sealOnLeave())
|
|
872
|
+
// back from the back-forward cache: what was kept goes out now (never amended, never dropped)
|
|
873
|
+
window.addEventListener('pageshow', (e) => { if (e.persisted) for (const r of pendingUploads.values()) void upload(r) })
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/** Seal every capture not sealed yet, as it stands, and tear it down as a drop does - synchronously: the page is going. */
|
|
877
|
+
export function sealOnLeave() {
|
|
878
|
+
const s = useJamCapture.getState()
|
|
879
|
+
const caps = Object.values(s.caps)
|
|
880
|
+
if (!caps.length) return
|
|
881
|
+
const draft = s.noteDraft.trim()
|
|
882
|
+
const records: CaptureRecord[] = []
|
|
883
|
+
for (const c of caps) {
|
|
884
|
+
const at = now()
|
|
885
|
+
const steps = [...c.steps]
|
|
886
|
+
// text written in the notes card and never added is the capture's last note, as at E
|
|
887
|
+
if (c.id === s.current && draft) steps.push({ at, event: 'note', text: draft })
|
|
888
|
+
steps.push({ at, event: 'missing', what: c.state === 'recording' ? 'the page closed while it recorded' : 'the page closed before it finished' })
|
|
889
|
+
records.push(buildRecord(c, steps, true))
|
|
890
|
+
timeCapture(c, true)
|
|
891
|
+
// its frames stop recording, its microphone is let go; a late picture or word finds nothing to change
|
|
892
|
+
broadcast({ type: 'sh:capture', id: c.id, on: false })
|
|
893
|
+
voiceDrop(c.id)
|
|
894
|
+
forgetHeard(c.id)
|
|
895
|
+
}
|
|
896
|
+
cancelDwell()
|
|
897
|
+
unwatch?.(); unwatch = null
|
|
898
|
+
useJamCapture.setState((st) => ({ current: null, caps: {}, noteOpen: false, noteDraft: '', tick: st.tick + 1, sealed: [...st.sealed, ...records.map((r) => ({ id: r.id }))] }))
|
|
899
|
+
for (const r of records) { keepSealed(r); void upload(r, true) }
|
|
827
900
|
}
|
|
828
901
|
|
|
829
902
|
/** Records sealed in an earlier page that never reached the server: sent again at boot. */
|
|
@@ -840,11 +913,15 @@ export function resendSealed() {
|
|
|
840
913
|
} catch { /* none */ }
|
|
841
914
|
}
|
|
842
915
|
|
|
916
|
+
// the canvas answered again after it stopped (spec 28 A1.11): the page reloads only when no capture is
|
|
917
|
+
// recording or finishing - a sealed one waits in localStorage and goes out from the next page
|
|
918
|
+
holdsReload(() => capturesPending())
|
|
919
|
+
|
|
843
920
|
/** Resume's work, while the caller holds `settling`: load the record, let the caller settle, start. */
|
|
844
921
|
async function resumeNow(draft: string, ready?: () => Promise<boolean>): Promise<boolean> {
|
|
845
922
|
let rec: CaptureRecord | null = null
|
|
846
923
|
try {
|
|
847
|
-
const r = await
|
|
924
|
+
const r = await api(`jam/capture?id=${encodeURIComponent(draft)}`, { headers: { 'x-mv-c': csrf() } })
|
|
848
925
|
const body = r.ok ? ((await r.json()) as { record?: CaptureRecord; sealed?: boolean }) : null
|
|
849
926
|
if (body?.record && body.sealed !== true) { useStore.getState().toast('the capture changed after it was sealed - it cannot be resumed'); return false }
|
|
850
927
|
rec = body?.record ?? null
|
|
@@ -872,11 +949,14 @@ export const useJamCapture = create<CaptureState>((set, get) => ({
|
|
|
872
949
|
lastEnded: null,
|
|
873
950
|
settling: null,
|
|
874
951
|
async resume(draft, ready) {
|
|
952
|
+
if (stoppedFor('Jam needs the canvas running')) return false // spec 28 A1.11: nothing to take it
|
|
875
953
|
if (get().current) { useStore.getState().toast('a capture is recording - press E to end it first'); return false }
|
|
876
954
|
if (sessionEnding) { useStore.getState().toast('the session is being wrapped up - a moment'); return false }
|
|
877
955
|
return resumeNow(draft, ready)
|
|
878
956
|
},
|
|
879
957
|
start(reviewing, session) {
|
|
958
|
+
// the canvas stopped (spec 28 A1.11): a new capture waits for it - one recording goes on, and is kept
|
|
959
|
+
if (!get().current && stoppedFor('Jam needs the canvas running')) return
|
|
880
960
|
// one capture at a time: the one recording is ended or dropped first
|
|
881
961
|
if (get().current) { useStore.getState().toast('a capture is recording - press E to end it first'); return }
|
|
882
962
|
if (sessionEnding) { useStore.getState().toast('the session is being wrapped up - a moment'); return }
|
|
@@ -18,10 +18,11 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { useJamCapture, setOwnedKeys } from './jam-capture.ts'
|
|
20
20
|
import { changedShots, useJamQueue, type JamCard } from './jam-queue.ts'
|
|
21
|
-
import { useJamUi } from './jam-state.ts'
|
|
21
|
+
import { DONE_CLOSE, DONE_GROUP, doneFold, useJamUi } from './jam-state.ts'
|
|
22
22
|
import { pressJ, startSession, wrapWrite } from './jam-session.tsx'
|
|
23
23
|
import { clearMoreDraft } from './jam-panel.tsx'
|
|
24
|
-
import { CONFIG, PUBLISHED, useStore } from './store.ts'
|
|
24
|
+
import { CONFIG, PUBLISHED, SOURCE_REVEALED, useStore } from './store.ts'
|
|
25
|
+
import { holdsReload } from './api.ts'
|
|
25
26
|
|
|
26
27
|
export interface KeyIn { key: string; shift?: boolean; alt?: boolean; meta?: boolean; ctrl?: boolean }
|
|
27
28
|
/** `[Ctrl+][Meta+][Alt+][Shift+]key`, a letter lowercase - the frames' descriptor (keys.js). */
|
|
@@ -70,6 +71,9 @@ export function saveEdit(c: JamCard, text: string) {
|
|
|
70
71
|
* keeps a note once, whatever answer was lost; a different note never takes a failed one's place. */
|
|
71
72
|
type PendingNote = { id: string; text: string; failed: boolean; order: number }
|
|
72
73
|
const unsavedNotes = new Map<string, PendingNote[]>()
|
|
74
|
+
// spec 28 A1.11: a page whose canvas came back reloads only once every edit and note of a read-back has saved -
|
|
75
|
+
// one that failed while the canvas was away waits for the read-back's own retry (a decision saves it first)
|
|
76
|
+
holdsReload(() => unsaved.size > 0 || unsavedNotes.size > 0)
|
|
73
77
|
const sendNote = (c: JamCard, n: PendingNote): Promise<boolean> => {
|
|
74
78
|
n.failed = false
|
|
75
79
|
const before = saving.get(c.id) ?? Promise.resolve(true)
|
|
@@ -209,15 +213,32 @@ function reviewNow(): { card: string; batch: string; rev: number } | undefined {
|
|
|
209
213
|
return ui.panel?.kind === 'review' && c?.kind === 'capture' && c.batch ? { card: c.id, batch: c.batch, rev: c.rev } : undefined
|
|
210
214
|
}
|
|
211
215
|
|
|
216
|
+
/** Esc while a laser (pointer or inspect) is on turns it off, and that is all it does. */
|
|
217
|
+
const laserOff = (): boolean => { const st = useStore.getState(); if (!st.laser) return false; st.setLaser(false); return true }
|
|
218
|
+
|
|
212
219
|
/** Start a capture, as S does: one made while a capture's review is open follows that review (its run).
|
|
213
220
|
* `session`: the session it belongs to when the queue may not show it yet (a session's Start). */
|
|
214
221
|
export const startCapture = (session?: string) => useJamCapture.getState().start(reviewNow(), session)
|
|
215
222
|
|
|
223
|
+
/** A laser on (pointer or inspect): its keys come first - Esc turns it off before it closes, drops or leaves anything -
|
|
224
|
+
* and are owned, so they work from inside a frame too (a laser click puts the focus there). The one row a published
|
|
225
|
+
* canvas has (where its source is revealed - the only place a laser exists there). */
|
|
226
|
+
const laserRow: Row = {
|
|
227
|
+
on: () => useStore.getState().laser,
|
|
228
|
+
keys: {
|
|
229
|
+
l: () => useStore.getState().toggleLaser(false),
|
|
230
|
+
'Alt+l': () => useStore.getState().toggleLaser(true),
|
|
231
|
+
Escape: () => useStore.getState().setLaser(false),
|
|
232
|
+
},
|
|
233
|
+
}
|
|
234
|
+
const rowsNow = (): Row[] => (PUBLISHED ? (SOURCE_REVEALED ? [laserRow] : []) : rows())
|
|
235
|
+
|
|
216
236
|
const rows = (): Row[] => {
|
|
217
237
|
const cap = useJamCapture.getState()
|
|
218
238
|
const ui = useJamUi.getState()
|
|
219
239
|
const panelCard = cardById(ui.panel?.id)
|
|
220
240
|
return [
|
|
241
|
+
laserRow,
|
|
221
242
|
{ // a session sheet open: the start sheet's ⏎ starts; Esc closes either (the wrap-up's field keeps its own keys)
|
|
222
243
|
on: () => ui.sheet === 'start' || ui.sheet === 'wrap',
|
|
223
244
|
keys: {
|
|
@@ -233,7 +254,8 @@ const rows = (): Row[] => {
|
|
|
233
254
|
Enter: () => void decideDraft(panelCard!.id, 'confirm'),
|
|
234
255
|
k: () => void decideDraft(panelCard!.id, 'keep'),
|
|
235
256
|
r: () => void resumeDraft(panelCard!.id),
|
|
236
|
-
|
|
257
|
+
// a laser on: Esc turns it off first - never a drop by the way
|
|
258
|
+
Escape: () => { if (laserOff()) return; void decideDraft(panelCard!.id, 'drop') },
|
|
237
259
|
},
|
|
238
260
|
},
|
|
239
261
|
{ // the notes card open (in its field, the field handles its own keys)
|
|
@@ -249,10 +271,13 @@ const rows = (): Row[] => {
|
|
|
249
271
|
e: () => cap.end(),
|
|
250
272
|
s: () => cap.start(), // one at a time: it says to end this one first
|
|
251
273
|
// L: laser picks - a pick inside a capture is its pick (frames forward it while interacting)
|
|
252
|
-
|
|
274
|
+
// L: the pointer laser; ⌥L: inspect - a laser click inside a capture is its pick either way
|
|
275
|
+
l: () => { void import('./comments-store.ts').then(({ useComments }) => useComments.getState().setMode(false)); useStore.getState().toggleLaser(false) },
|
|
276
|
+
'Alt+l': () => { void import('./comments-store.ts').then(({ useComments }) => useComments.getState().setMode(false)); useStore.getState().toggleLaser(true) },
|
|
253
277
|
n: () => { cap.setNoteOpen(true); window.dispatchEvent(new CustomEvent('mv-jam-note-focus')) },
|
|
254
278
|
i: () => cap.picture(),
|
|
255
|
-
|
|
279
|
+
// a laser on: Esc turns it off first - the recording goes on
|
|
280
|
+
Escape: () => { if (laserOff()) return; cap.drop() },
|
|
256
281
|
},
|
|
257
282
|
},
|
|
258
283
|
{ // a review open
|
|
@@ -272,13 +297,19 @@ const rows = (): Row[] => {
|
|
|
272
297
|
on: () => ui.laneKeys,
|
|
273
298
|
keys: (() => {
|
|
274
299
|
const list = lane()
|
|
300
|
+
// the stops as the lane shows them: done tiles folded into one group (two or more), or led by the collapse tile
|
|
301
|
+
const { stops, done } = doneFold(list, ui.doneOpen)
|
|
275
302
|
// acting keys act only on the tile you can see selected - never on a fallback
|
|
276
|
-
const i =
|
|
277
|
-
const sel = i >= 0 ? list[i] : undefined
|
|
278
|
-
const move = (d: number) => { const n = i < 0 ?
|
|
303
|
+
const i = ui.selected ? stops.indexOf(ui.selected) : -1
|
|
304
|
+
const sel = i >= 0 ? list.find((c) => c.id === stops[i]) : undefined
|
|
305
|
+
const move = (d: number) => { const n = i < 0 ? stops[stops.length - 1] : stops[Math.min(stops.length - 1, Math.max(0, i + d))]; if (n) ui.select(n) }
|
|
279
306
|
return {
|
|
280
307
|
ArrowLeft: () => move(-1), ArrowRight: () => move(1),
|
|
281
|
-
Enter: () => {
|
|
308
|
+
Enter: () => {
|
|
309
|
+
if (stops[i] === DONE_GROUP) ui.setDoneOpen(true, done.map((c) => c.id))
|
|
310
|
+
else if (stops[i] === DONE_CLOSE) ui.setDoneOpen(false, done.map((c) => c.id))
|
|
311
|
+
else if (sel) openTile(sel.id)
|
|
312
|
+
},
|
|
282
313
|
'Meta+Enter': () => { if (sel?.state === 'queued') void act(sel, 'first') },
|
|
283
314
|
k: () => { if (sel?.state === 'draft') void decideDraft(sel.id, 'keep'); else if (sel?.state === 'queued') void act(sel, 'keep') },
|
|
284
315
|
Backspace: () => { if (sel) void act(sel, 'drop') },
|
|
@@ -301,9 +332,8 @@ const rows = (): Row[] => {
|
|
|
301
332
|
|
|
302
333
|
/** Apply Jam's key if a state takes it. True when it did - the caller stops there. */
|
|
303
334
|
export function jamKey(k: KeyIn): boolean {
|
|
304
|
-
if (PUBLISHED) return false
|
|
305
335
|
const d = descriptor(k)
|
|
306
|
-
for (const row of
|
|
336
|
+
for (const row of rowsNow()) {
|
|
307
337
|
if (!row.on()) continue
|
|
308
338
|
const f = row.keys[d] ?? (d.length === 1 ? row.keys[d] : undefined)
|
|
309
339
|
if (f) { f(); syncOwned(); return true }
|
|
@@ -313,17 +343,20 @@ export function jamKey(k: KeyIn): boolean {
|
|
|
313
343
|
|
|
314
344
|
/** Mirror the keys owned right now into the frames. Called whenever a state may have changed. */
|
|
315
345
|
export function syncOwned() {
|
|
316
|
-
if (PUBLISHED) return
|
|
317
346
|
const owned = new Set<string>()
|
|
318
|
-
for (const row of
|
|
347
|
+
for (const row of rowsNow()) if (row.on()) for (const k of Object.keys(row.keys)) owned.add(k)
|
|
319
348
|
setOwnedKeys([...owned])
|
|
320
349
|
}
|
|
321
350
|
|
|
322
351
|
if (typeof window !== 'undefined' && (import.meta as any).env?.DEV) void import('./canvas/ctl.ts').then(({ canvasCtl }) => { (window as any).__mvJamCanvas = canvasCtl })
|
|
323
352
|
|
|
324
|
-
if (typeof window !== 'undefined'
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
353
|
+
if (typeof window !== 'undefined') {
|
|
354
|
+
if (!PUBLISHED) {
|
|
355
|
+
// the states live in three stores: any change may change what is owned
|
|
356
|
+
useJamCapture.subscribe(syncOwned)
|
|
357
|
+
useJamUi.subscribe(syncOwned)
|
|
358
|
+
useJamQueue.subscribe(syncOwned)
|
|
359
|
+
}
|
|
360
|
+
// and the laser (its keys are owned while it is on - on a published canvas too)
|
|
361
|
+
useStore.subscribe((s, p) => { if (s.laser !== p.laser || s.laserInspect !== p.laserInspect) syncOwned() })
|
|
329
362
|
}
|