@marver-design/marver 0.27.0 → 0.27.2
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 +94 -0
- package/README.md +5 -2
- package/dist/{anchor-check-ChdDqL5z.mjs → anchor-check-gkxkPAIv.mjs} +1 -1
- package/dist/{board-tree-DRioF94d.mjs → board-tree-BXR8dw4b.mjs} +3 -1
- package/dist/{boards-CGg6piKF.mjs → boards-BHKP5yhI.mjs} +1 -1
- package/dist/{boards-DlTcpF47.mjs → boards-BqUqKNW8.mjs} +4 -4
- package/dist/{build-DZnFysGU.mjs → build-VgNg4rr8.mjs} +7 -22
- package/dist/cli.mjs +32 -18
- package/dist/{collab-Dxg2trOK.mjs → collab-BEAcXrBb.mjs} +1 -1
- package/dist/{comments-DxOkCSNE.mjs → comments-YEU1Zhv9.mjs} +4 -4
- package/dist/{context-HQ4Giw58.mjs → context-Ccjrhr1J.mjs} +3 -3
- package/dist/{daemon-BSA0lV8d.mjs → daemon-Dc9AH0M3.mjs} +4 -4
- package/dist/{dev-eQJhWsqg.mjs → dev-ri6nAlRp.mjs} +11 -11
- package/dist/{init-COD0x48i.mjs → init-W0nxR1OY.mjs} +3 -3
- package/dist/{link-DDXZVGtv.mjs → link-CdTgn94Y.mjs} +4 -4
- package/dist/{ls-D7O1G505.mjs → ls-BZ5TAtd5.mjs} +1 -1
- package/dist/{manifest-Nl3KSVOk.mjs → manifest-aFyDmL8C.mjs} +2 -2
- package/dist/{marks-CWM3WJjc.mjs → marks-BF9pNEgH.mjs} +2 -2
- package/dist/{marks-CKgzucHZ.mjs → marks-CnCCfAbD.mjs} +3 -3
- package/dist/{marver-id-gate-BjF6v4bT.mjs → marver-id-gate-D-R0hSt_.mjs} +1 -1
- package/dist/perf-DkAUFT6W.mjs +1319 -0
- package/dist/perf-jam-BaH3Lg0m.mjs +635 -0
- package/dist/{plugin-C-E7omsh.mjs → plugin-B8UghYuF.mjs} +2592 -112
- package/dist/{poster-Bx83ZYVK.mjs → poster-BNgafWMK.mjs} +1 -1
- package/dist/{profile-Bh5Y5zpW.mjs → profile-jIS6BcAs.mjs} +1 -1
- package/dist/{publish-bakes-aljgm45S.mjs → publish-bakes-38Nja78p.mjs} +3 -3
- package/dist/{recover-t9Pno3u9.mjs → recover-B8AiI29B.mjs} +2 -2
- package/dist/{serve-C8rVheYk.mjs → serve-Dp3nHstu.mjs} +3 -3
- package/dist/{share-W5H3BNvP.mjs → share-Ce4tP7ji.mjs} +1 -1
- package/dist/{shot-DoHLl6ig.mjs → shot-CMQgMVZm.mjs} +1 -1
- package/dist/{shot-LFhC-WYD.mjs → shot-Ch24tiMO.mjs} +30 -5
- package/dist/{slots-DCDo3N0x.mjs → slots-CFNnegCc.mjs} +8 -1
- package/dist/{sync-BQVlHZpx.mjs → sync-CQdGARJ9.mjs} +1 -1
- package/dist/{work-BroFwnup.mjs → work-Bxz-ObF3.mjs} +3 -3
- package/dist/{work-Bp1p39kq.mjs → work-CNhFF9pU.mjs} +1 -1
- package/docs/jam-session.md +2 -1
- 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/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/inset.ts +44 -0
- package/src/client/shell/jam-capture.ts +19 -14
- package/src/client/shell/jam-keys.ts +8 -3
- package/src/client/shell/jam-panel.tsx +6 -3
- package/src/client/shell/jam-voice.ts +48 -10
- 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 +47 -15
- 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/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 +3 -0
- package/templates/AGENTS-studio.md +3 -0
- package/templates/instructions/boards.md +3 -1
- package/dist/bake-DM_uWgAA.mjs +0 -786
- package/dist/perf-BWzQwZqj.mjs +0 -369
- package/dist/perf-BoDSkbEb.mjs +0 -429
- package/dist/perf-jam-D55U3FZK.mjs +0 -242
package/src/client/shell/App.tsx
CHANGED
|
@@ -9,6 +9,9 @@ import { Component, useEffect, useLayoutEffect, useRef, useState, type MouseEven
|
|
|
9
9
|
import { useStore, BOARD_GONE, CONFIG, CANVAS_NAME, DISK_WON, LOCKED_SHELL, PUBLISHED, SOURCE_REVEALED, stoppedFor, logReload, takeReloadCause, addToBoard, boardLabel, cap, humanize, fetchBoardNames, landingBoard, tabTitle, hydrateBoardPolicy, landingMode, playsAsSlides, sceneLabel, switchCount, type FrameEntry } from './store.ts'
|
|
10
10
|
import { AddToBoard, BoardList } from './BoardList.tsx'
|
|
11
11
|
import { ContextMenu, copyToClipboard, framePath, useContextMenu, type MenuItem } from './ContextMenu.tsx'
|
|
12
|
+
import { TOP } from './inset.ts'
|
|
13
|
+
// a headless run's probe (main.tsx): canvas code, so it comes through this module, never into a locked bundle
|
|
14
|
+
export { startPerfRunProbe } from './perf-run-probe.ts'
|
|
12
15
|
import { Tip } from './Tip.tsx'
|
|
13
16
|
import { PKG, ROUTE } from '../const.ts'
|
|
14
17
|
import { api, resumed, scoped, useLink } from './api.ts'
|
|
@@ -170,7 +173,8 @@ function SelectionBar() {
|
|
|
170
173
|
left: barW
|
|
171
174
|
? `clamp(8px, calc(${centerX} - ${Math.round(barW / 2)}px), calc(100vw - ${barW + 8}px))`
|
|
172
175
|
: centerX,
|
|
173
|
-
|
|
176
|
+
// below the Mac app's strip and its scroll edge when the shell took the inset (TOP 44: 52 px; else 8)
|
|
177
|
+
top: `clamp(${TOP + 8}px, ${rawTop}, calc(100vh - 52px))`,
|
|
174
178
|
transform: barW ? undefined : 'translateX(-50%)',
|
|
175
179
|
}}
|
|
176
180
|
>
|
|
@@ -916,6 +920,8 @@ export function App() {
|
|
|
916
920
|
return (
|
|
917
921
|
<div ref={appRef} tabIndex={-1} className={`sh-app${dark ? ' dark' : ''}${interacting ? ' interacting' : ''}${laneLift}`}>
|
|
918
922
|
<Canvas />
|
|
923
|
+
{/* the scroll edge under the Mac app's transparent strip (0.27.2, A3.8 #31): over the world, under the chrome */}
|
|
924
|
+
{TOP ? <div className="sh-edge" aria-hidden="true" /> : null}
|
|
919
925
|
<SelectionBar />
|
|
920
926
|
|
|
921
927
|
{/* floating pill panel (no top bar - spec); panel and fab are both always
|
|
@@ -1182,8 +1188,9 @@ function placeBanner(el: HTMLElement) {
|
|
|
1182
1188
|
// the toolbar row: its centre line, and its foot - the sidebar runs down the page, so it is no part of the row
|
|
1183
1189
|
const tall = !!left && left.bottom - left.top > 64
|
|
1184
1190
|
const row = [right, tall ? null : left].filter((b): b is NonNullable<typeof b> => !!b)
|
|
1185
|
-
|
|
1186
|
-
const
|
|
1191
|
+
// with no row to measure: the toolbar's line, below the Mac app's strip when the shell took the inset
|
|
1192
|
+
const mid = row.length ? Math.max(...row.map((b) => (b.top + b.bottom) / 2)) : TOP + edge + 23
|
|
1193
|
+
const foot = Math.max(TOP + edge + 46, ...row.map((b) => b.bottom))
|
|
1187
1194
|
const W = app.clientWidth
|
|
1188
1195
|
const from = left ? left.right + BANNER_GAP : edge, to = right ? right.left - BANNER_GAP : W - edge
|
|
1189
1196
|
const at = (where: 'row' | 'stack' | 'below', x0: number, x1: number, top?: number) => {
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* size via --sh-inv (the vbadge pattern) so zoom never shrinks them away, and never
|
|
6
6
|
* overlap (pin-layout.ts places them).
|
|
7
7
|
*/
|
|
8
|
+
import { TOP } from './inset.ts'
|
|
8
9
|
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
9
10
|
import { createPortal } from 'react-dom'
|
|
10
11
|
import { avatarFallback, useComments } from './comments-store.ts'
|
|
@@ -729,15 +730,16 @@ export function ThreadCard({ thread, at, bounds, nodeKey, side = 'r', flank, sta
|
|
|
729
730
|
// a device/theme switch resizes .sh-play-stage and a window resize shifts it.
|
|
730
731
|
const computeStagePos = (): React.CSSProperties | null => {
|
|
731
732
|
if (!stage) return null
|
|
732
|
-
|
|
733
|
+
// the view below the Mac app's strip when the shell took the inset (TOP 44)
|
|
734
|
+
const W = 320, M = 12, maxH = Math.min(660, window.innerHeight - TOP - 2 * M)
|
|
733
735
|
const rect = document.querySelector('.sh-play-stage')?.getBoundingClientRect()
|
|
734
|
-
if (!rect) return { position: 'fixed', left: M, top: 72, maxHeight: maxH }
|
|
736
|
+
if (!rect) return { position: 'fixed', left: M, top: TOP + 72, maxHeight: maxH }
|
|
735
737
|
const roomR = window.innerWidth - rect.right >= W + 30
|
|
736
738
|
const roomL = rect.left >= W + 30
|
|
737
739
|
const s: 'l' | 'r' = at.x < bounds.w / 2 ? (roomL ? 'l' : 'r') : (roomR ? 'r' : 'l')
|
|
738
740
|
const x = Math.min(Math.max(s === 'r' ? rect.right + 18 : rect.left - 18 - W, M), window.innerWidth - W - M)
|
|
739
741
|
// worst-case clamp (content = maxH): even a full-height thread keeps its composer on screen
|
|
740
|
-
const y = Math.min(Math.max(rect.top + at.y - 36, M), Math.max(M, window.innerHeight - maxH - M))
|
|
742
|
+
const y = Math.min(Math.max(rect.top + at.y - 36, TOP + M), Math.max(TOP + M, window.innerHeight - maxH - M))
|
|
741
743
|
return { position: 'fixed', left: x, top: y, maxHeight: maxH }
|
|
742
744
|
}
|
|
743
745
|
const [stagePos, setStagePos] = useState<React.CSSProperties | null>(computeStagePos)
|
|
@@ -2,6 +2,7 @@ import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 're
|
|
|
2
2
|
import { createPortal } from 'react-dom'
|
|
3
3
|
import { useStore, SOURCE_REVEALED } from './store.ts'
|
|
4
4
|
import { UNPLACED } from './hash.ts'
|
|
5
|
+
import { TOP } from './inset.ts'
|
|
5
6
|
|
|
6
7
|
/** Copy text to the clipboard, toasting the outcome. Success is confirmed out loud; a
|
|
7
8
|
* blocked clipboard (no user gesture / permission) says so instead of failing silently. */
|
|
@@ -35,8 +36,9 @@ export function useContextMenu() {
|
|
|
35
36
|
e.preventDefault()
|
|
36
37
|
const MENU_W = 240 // the CSS max-width; labels ellipsize inside it
|
|
37
38
|
// a menu taller than the window (many "Move to …" folders) pins to the top edge and scrolls
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
// ...and never under the Mac app's strip (TOP 44 when the shell took the inset)
|
|
40
|
+
const h = Math.min(items.length * 32 + 12, window.innerHeight - 16 - TOP)
|
|
41
|
+
setMenu({ x: Math.max(8, Math.min(e.clientX, window.innerWidth - MENU_W - 8)), y: Math.max(TOP + 8, Math.min(e.clientY, window.innerHeight - h - 8)), items })
|
|
40
42
|
}
|
|
41
43
|
return { menu, open, close: () => setMenu(null) }
|
|
42
44
|
}
|
|
@@ -50,7 +52,7 @@ export function ContextMenu({ menu, close }: { menu: MenuState | null; close: ()
|
|
|
50
52
|
useLayoutEffect(() => {
|
|
51
53
|
if (!menu || !ref.current) return
|
|
52
54
|
const h = ref.current.getBoundingClientRect().height
|
|
53
|
-
setTop(Math.max(8, Math.min(menu.y, window.innerHeight - h - 8)))
|
|
55
|
+
setTop(Math.max(TOP + 8, Math.min(menu.y, window.innerHeight - h - 8)))
|
|
54
56
|
}, [menu, panel])
|
|
55
57
|
useEffect(() => {
|
|
56
58
|
if (!menu) return
|
|
@@ -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
|
+
}
|