@marver-design/marver 0.30.1 → 0.31.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.
Files changed (107) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +11 -7
  3. package/dist/{anchor-check-Bv4o-R2T.mjs → anchor-check-B92s9tVv.mjs} +1 -1
  4. package/dist/{board-tree-BXR8dw4b.mjs → board-tree-DGj0HhEE.mjs} +6 -2
  5. package/dist/{boards-EH2onUXM.mjs → boards-Cim1GTKc.mjs} +32 -2
  6. package/dist/{boards-BeWtjGUM.mjs → boards-OlAhZ87x.mjs} +7 -7
  7. package/dist/{build-zWGXSzly.mjs → build-BNssmbqd.mjs} +14 -17
  8. package/dist/{capture-DEtM4qm5.mjs → capture-HaS-1or8.mjs} +1 -1
  9. package/dist/cli.mjs +38 -20
  10. package/dist/{collab-BEAcXrBb.mjs → collab-D2NcrOB8.mjs} +53 -14
  11. package/dist/comment-actions-Bxf9Ld4g.mjs +351 -0
  12. package/dist/{comments-XNhMmSSu.mjs → comments-BakJQwaf.mjs} +85 -10
  13. package/dist/config-B0YcFtqS.mjs +510 -0
  14. package/dist/{context-BUnFiyA3.mjs → context-Cj2TcC0H.mjs} +3 -3
  15. package/dist/{daemon-CChgWJNq.mjs → daemon-MxoEQajX.mjs} +222 -23
  16. package/dist/deep-link-DYtuT740.mjs +163 -0
  17. package/dist/{dev-DOgIITpT.mjs → dev-BBZe_brH.mjs} +23 -16
  18. package/dist/devices-uJZ2inMq.mjs +155 -0
  19. package/dist/{events-CLH4ijKP.mjs → events-Dieo1482.mjs} +49 -4
  20. package/dist/{init-CYlFaRzG.mjs → init-BgusplYn.mjs} +40 -10
  21. package/dist/{jam-Cj5gBvwD.mjs → jam-CkuLL8A8.mjs} +1 -1
  22. package/dist/{link-BFFRgrMt.mjs → link-Cmt9Xy4X.mjs} +54 -7
  23. package/dist/{logo-CXY-1yrn.mjs → logo-C9s7-Cy9.mjs} +89 -66
  24. package/dist/{ls-NqmePKOf.mjs → ls-DGVIW-Io.mjs} +1 -1
  25. package/dist/{manifest-DPZ3WNg_.mjs → manifest-CK8Qh4Nq.mjs} +255 -13
  26. package/dist/{marks-BnNANic9.mjs → marks-C8oX8kbE.mjs} +3 -3
  27. package/dist/{marks-DBp3h1Mc.mjs → marks-Dt-5JXCp.mjs} +18 -5
  28. package/dist/{marver-id-gate-vBLb_Icb.mjs → marver-id-gate-BAeuMeaU.mjs} +11 -7
  29. package/dist/md-B9_13Q0R.mjs +105 -0
  30. package/dist/notes-CRAX4wgk.mjs +148 -0
  31. package/dist/own-C8Mq0Hnf.mjs +128 -0
  32. package/dist/pdf-0m721FFn.mjs +117 -0
  33. package/dist/pdf-CZENT6t3.mjs +2299 -0
  34. package/dist/{perf-BCxAo0IS.mjs → perf-BB0XNt1M.mjs} +1 -1
  35. package/dist/{perf-6MOTHxay.mjs → perf-CIMijND6.mjs} +5 -5
  36. package/dist/{plugin-CFWBcAba.mjs → plugin-CL8_wL7a.mjs} +460 -83
  37. package/dist/{poster-DPPpQiva.mjs → poster-B7uSjlEP.mjs} +1 -1
  38. package/dist/{profile-B1FKOM1e.mjs → profile-cdmSer1k.mjs} +1 -1
  39. package/dist/{publish-bakes-_Zx8crP3.mjs → publish-bakes-BjgDNeyS.mjs} +3 -3
  40. package/dist/{queue-DeSQm24g.mjs → queue-BLLfdlDw.mjs} +156 -11
  41. package/dist/{recover-mDUVsnPd.mjs → recover-ByuFQOF9.mjs} +2 -2
  42. package/dist/{serve-DQv3Ti6X.mjs → serve-kcF6-H8V.mjs} +4 -4
  43. package/dist/{session-VDJfXEEm.mjs → session-DBF-nQvq.mjs} +29 -3
  44. package/dist/{share-Bu_kuOKL.mjs → share-CS2mg27O.mjs} +1 -1
  45. package/dist/{shot-d4h_hJi9.mjs → shot-BqwkdtKn.mjs} +4 -4
  46. package/dist/{shot-DBWN8hPP.mjs → shot-D2TQGo2V.mjs} +1 -1
  47. package/dist/show-B1u3DiJw.mjs +101 -0
  48. package/dist/{sizes-wjXDev3b.mjs → sizes-BckcL4Zz.mjs} +1 -1
  49. package/dist/{slots-Dn4Onb0V.mjs → slots-BOcfIqxy.mjs} +15 -3
  50. package/dist/{summary-Y8MY1Wuc.mjs → summary-cPmRDGpX.mjs} +1 -1
  51. package/dist/{sync-CMozOwZ0.mjs → sync-BNWwh8OF.mjs} +205 -7
  52. package/dist/{work-BYWD_1Zf.mjs → work-DRdzXPvg.mjs} +3 -3
  53. package/dist/{work-DJxH7cCX.mjs → work-Nv-n2_Un.mjs} +1 -1
  54. package/docs/app.md +49 -0
  55. package/docs/boards-and-folders.md +37 -6
  56. package/docs/jam-session.md +5 -0
  57. package/docs/live-jam.md +9 -0
  58. package/docs/pdf.md +108 -0
  59. package/docs/publish.md +9 -9
  60. package/docs/sharing.md +11 -0
  61. package/docs/slides.md +9 -0
  62. package/package.json +3 -1
  63. package/src/client/content/index.tsx +4 -2
  64. package/src/client/frame-host/main.tsx +3 -0
  65. package/src/client/shell/App.tsx +71 -24
  66. package/src/client/shell/BoardList.tsx +16 -7
  67. package/src/client/shell/Comments.tsx +77 -16
  68. package/src/client/shell/Play.tsx +24 -22
  69. package/src/client/shell/Toolbar.tsx +4 -3
  70. package/src/client/shell/app-bridge.ts +32 -5
  71. package/src/client/shell/canvas/Canvas.tsx +30 -8
  72. package/src/client/shell/canvas/FrameNode.tsx +3 -1
  73. package/src/client/shell/canvas/ctl.ts +16 -0
  74. package/src/client/shell/commands.ts +20 -0
  75. package/src/client/shell/comments-store.ts +81 -2
  76. package/src/client/shell/devices.tsx +42 -0
  77. package/src/client/shell/goto.ts +56 -9
  78. package/src/client/shell/icons.tsx +11 -4
  79. package/src/client/shell/jam-lines.ts +5 -3
  80. package/src/client/shell/jam-panel.tsx +17 -5
  81. package/src/client/shell/marks-ui.tsx +54 -0
  82. package/src/client/shell/notes.ts +21 -0
  83. package/src/client/shell/pdf-export.tsx +154 -0
  84. package/src/client/shell/pdf-notes.ts +20 -0
  85. package/src/client/shell/show.ts +250 -0
  86. package/src/client/shell/store.ts +23 -38
  87. package/src/client/shell/styles.css +43 -0
  88. package/src/shared/app-api.ts +49 -4
  89. package/src/shared/auto-place.ts +32 -0
  90. package/src/shared/board-tree.ts +3 -0
  91. package/src/shared/board-types.ts +6 -2
  92. package/src/shared/deep-link.ts +212 -0
  93. package/src/shared/devices.ts +89 -0
  94. package/src/shared/events.ts +48 -5
  95. package/src/shared/export-plan.ts +98 -0
  96. package/templates/AGENTS-embedded.md +76 -12
  97. package/templates/AGENTS-studio.md +76 -12
  98. package/templates/instructions/boards.md +6 -5
  99. package/templates/instructions/configure.md +32 -2
  100. package/templates/instructions/iterate.md +8 -0
  101. package/templates/instructions/jam.md +9 -0
  102. package/templates/instructions/publish.md +14 -4
  103. package/templates/instructions/review.md +4 -0
  104. package/templates/instructions/slides.md +67 -1
  105. package/templates/instructions/welcome.md +9 -5
  106. package/templates/playbooks/publish-canvas/PLAYBOOK.md +1 -1
  107. package/dist/config-BezZTiov.mjs +0 -182
@@ -19,6 +19,8 @@ import { JamButton } from './jam-session.tsx'
19
19
  import { useEffect, useRef, useState } from 'react'
20
20
  import { useStore, BOARD_POLICY, BRANDING, CONFIG, PUBLISHED, SOURCE_REVEALED, boardLabel, boardLocked, cap, fetchBoardNames, modeAllowed, playsAsSlides, SLIDE_INTRINSIC, stoppedFor, type Node } from './store.ts'
21
21
  import { deckOrder } from './play-order.ts'
22
+ import { boardOrder, presentDevice } from '../../shared/export-plan.ts'
23
+ import { exportPdf } from './pdf-export.tsx'
22
24
  import { NO_COMMENTS_HERE, useComments } from './comments-store.ts'
23
25
  import { UNPLACED } from './hash.ts'
24
26
  import { isNoteAnchor } from './notes.ts'
@@ -29,12 +31,13 @@ import { canvasCtl } from './canvas/ctl.ts'
29
31
  import { recorder } from './recorder.ts'
30
32
  import { perfSeams } from './recorder-seams.ts'
31
33
  import { cmd, endAfterFrames, endOnStage, keysOf, type CmdHandle, type CmdOpts, type CmdName } from './commands.ts'
32
- import { revealFrame, switchFor } from './goto.ts'
34
+ import { navigatedByHand, revealFrame, switchFor } from './goto.ts'
33
35
  import { Tip } from './Tip.tsx'
34
36
  import { keyAllowed } from '../frame-host/keys.js'
35
37
  import { CommentButton, DevicePicker, HideUIButton, isHideUI, LaserButton, Popover, ThemePicker, toggleHideUI, usePopover } from './Toolbar.tsx'
36
- import { DraftComposer, Pins, placePins, ThreadCard } from './Comments.tsx'
37
- import { ArrowLeftIcon, ArrowRightIcon, BrowsersIcon, CaretIcon, CheckIcon, GridIcon, PanelFilledIcon, PanelHollowIcon, ParallelogramDuoIcon, ReloadIcon, SpecDocIcon } from './icons.tsx'
38
+ import { cardSelectAll, DraftComposer, Pins, placePins, ThreadCard } from './Comments.tsx'
39
+ import { ArrowLeftIcon, ArrowRightIcon, BrowsersIcon, CaretIcon, CheckIcon, ExportIcon, GridIcon, PanelFilledIcon, PanelHollowIcon, ParallelogramDuoIcon, ReloadIcon, SpecDocIcon } from './icons.tsx'
40
+ import { deviceLabel } from './devices.tsx'
38
41
 
39
42
  const commentsStore = () => useComments.getState()
40
43
 
@@ -42,16 +45,8 @@ const commentsStore = () => useComments.getState()
42
45
  * documents and cannot mount into the persistent chain), deduped. */
43
46
  function playList(): string[] {
44
47
  const s = useStore.getState()
45
- const seen = new Set<string>()
46
- const out: string[] = []
47
- for (const n of s.nodes) {
48
- if (n.missing || seen.has(n.frame)) continue
49
- const f = s.frameFor(n)
50
- if (!f || f.kind !== 'tsx') continue
51
- seen.add(n.frame)
52
- out.push(n.frame)
53
- }
54
- return out
48
+ // the export plan's board order (spec 31 #2): the PDF prints the same list, html frames included
49
+ return boardOrder(s.nodes, (n) => s.frameFor(n), { html: false }).map((n) => n.frame)
55
50
  }
56
51
 
57
52
  /** Slides mode (v1.5): the deck's play order is the BOARD's reading order -
@@ -108,11 +103,10 @@ export function enterPlay(over?: { at?: string; device?: string; theme?: string
108
103
  ?? (overAt ? undefined : selNode ?? s.nodes.find((n) => list.includes(n.frame)))
109
104
  const at = overAt ?? node!.frame
110
105
  const frame = s.manifest?.frames.find((f) => f.id === at)
111
- // device: the link's; else the node's width names it; else the frame's declared viewport
112
- const names = Object.keys(CONFIG.viewports)
106
+ // device: the link's; else the export plan's rule (spec 31 #2) - the node's width names it, else the frame's
107
+ // declared viewport, else the first
113
108
  const device = (over?.device && (CONFIG.viewports[over.device] || over.device === 'fill') ? over.device : undefined)
114
- ?? (node ? names.find((v) => CONFIG.viewports[v].width === node.w) : undefined)
115
- ?? (frame?.viewport && CONFIG.viewports[frame.viewport] ? frame.viewport : names[0])
109
+ ?? presentDevice(node, frame, CONFIG.viewports)!
116
110
  const theme = (over?.theme && CONFIG.themes.includes(over.theme) ? over.theme : undefined)
117
111
  ?? node?.theme ?? frame?.theme ?? s.viewTheme
118
112
  s.setPlay({ at, device, theme })
@@ -137,10 +131,8 @@ export function enterFocus(at?: string, over?: { device?: string; theme?: string
137
131
  if (!target) { s.toast('nothing to focus here'); return }
138
132
  const frame = s.manifest?.frames.find((f) => f.id === target)
139
133
  const node = s.nodes.find((n) => n.frame === target && !n.missing)
140
- const names = Object.keys(CONFIG.viewports)
141
134
  const device = (over?.device && (CONFIG.viewports[over.device] || over.device === 'fill') ? over.device : undefined)
142
- ?? (node ? names.find((v) => CONFIG.viewports[v].width === node.w) : undefined)
143
- ?? (frame?.viewport && CONFIG.viewports[frame.viewport] ? frame.viewport : names[0])
135
+ ?? presentDevice(node, frame, CONFIG.viewports)!
144
136
  const theme = (over?.theme && CONFIG.themes.includes(over.theme) ? over.theme : undefined)
145
137
  ?? node?.theme ?? frame?.theme ?? s.viewTheme
146
138
  s.setPlay({ at: target, device, theme, focus: true, ...(over?.deep ? { deep: true } : {}) })
@@ -490,7 +482,8 @@ function PlayInner() {
490
482
  perfSeams.stageMessage.emit(data)
491
483
  // Jam (spec 27): the stage records like a frame; a key the shell owns comes back as sh:key
492
484
  if (onFrameMessage('stage', data)) return
493
- if (data.type === 'sh:key') { if (typeof data.key === 'string') jamKey({ key: data.key, shift: !!data.shift, alt: !!data.alt, meta: !!data.meta, ctrl: !!data.ctrl }, 'stage'); return }
485
+ // a key the stage forwards: the person's, so a show or link still loading gives way (spec 31 D3)
486
+ if (data.type === 'sh:key') { if (typeof data.key === 'string') { navigatedByHand(); jamKey({ key: data.key, shift: !!data.shift, alt: !!data.alt, meta: !!data.meta, ctrl: !!data.ctrl }, 'stage') } return }
494
487
  if (data.type === 'sh:stage-ready') {
495
488
  frameReady('stage')
496
489
  // an iframe reload (registry HMR invalidation) boots at the frozen initial src -
@@ -525,6 +518,7 @@ function PlayInner() {
525
518
  if (s.playNav && !s.stageShown) useStore.setState({ playUpdateRevision: 'retry' }) // an Update that failed: offer it again
526
519
  }
527
520
  } else if (data.type === 'sh:stage-key') {
521
+ navigatedByHand() // the person's key or click on the stage (spec 31 D3)
528
522
  if (data.meta && data.key === '/') { cmd('toolbar', { via: 'key', in: 'stage', keys: 'Meta+/' }); toggleCollapse() }
529
523
  // the stage's background click, posted as Space, says so (#50)
530
524
  else handleKey(String(data.key), String(data.code), !!data.alt, data.origin === 'click' ? { via: 'click', in: 'stage' } : { via: 'key', in: 'stage', keys: keysOf({ key: String(data.key), alt: !!data.alt }) })
@@ -623,6 +617,8 @@ function PlayInner() {
623
617
  const key = e.altKey && /^Key[A-Z]$/.test(e.code) ? e.code.slice(3).toLowerCase() : e.key
624
618
  if (!e.repeat && jamKey({ key, shift: e.shiftKey, alt: e.altKey, meta: e.metaKey, ctrl: e.ctrlKey })) { e.preventDefault(); return }
625
619
  if ((e.metaKey || e.ctrlKey) && e.key === '/') { e.preventDefault(); cmd('toolbar', { via: 'key', in: 'shell', keys: keysOf(e) }); toggleCollapse(); return }
620
+ // ⌘A in the open thread's card selects its words, never the whole page (spec 31 C.1)
621
+ if ((e.metaKey || e.ctrlKey) && e.key === 'a' && cardSelectAll()) { e.preventDefault(); cmd('thread-select-all', { via: 'key', in: 'shell', keys: keysOf(e) }); return }
626
622
  if (e.metaKey || e.ctrlKey) return
627
623
  handleKey(key, e.code, e.altKey, { via: 'key', in: 'shell', keys: keysOf(e, key) })
628
624
  }
@@ -671,7 +667,7 @@ function PlayInner() {
671
667
  const dw = Math.round(vp.width * scale)
672
668
  const dh = Math.round(vp.height * scale)
673
669
  const deviceHint = stage ? `${vp.width} × ${vp.height} stage · ${fill ? 'edge to edge' : 'fit to the window'}`
674
- : fill ? 'Fill window' : `${vp.width} × ${vp.height} · keys 1-${names.length + 1}`
670
+ : fill ? 'Fill window' : `${CONFIG.viewports[play.device] ? `${deviceLabel(play.device)} · ` : ''}${vp.width} × ${vp.height} · keys 1-${names.length + 1}`
675
671
 
676
672
  return (
677
673
  <div className={`sh-play${fill || docPreset ? ' fill' : ''}${docPreset ? ` doc t-${play.theme}` : ''}`}>
@@ -768,6 +764,12 @@ function PlayInner() {
768
764
  </button>
769
765
  </Tip>
770
766
  </>}
767
+ {/* spec 31: the deck (or the present board) as a PDF, in the theme the stage shows - a dev canvas only */}
768
+ {!focus && !PUBLISHED && (
769
+ <Tip side="bottom" label={<><b>Export PDF</b><span>this board, one page per {slides ? 'slide' : 'frame'}</span></>}>
770
+ <button className="sh-pill-btn" aria-label="Export PDF" onClick={() => void exportPdf(board, { theme: play.theme }, { via: 'click', in: 'pill' })}><ExportIcon size={15} /></button>
771
+ </Tip>
772
+ )}
771
773
  {/* the canvas door: absent on a locked board (policy) and on a frame
772
774
  deep link (the link's chrome) - not hidden, not rendered */}
773
775
  {!noDoor && (
@@ -8,13 +8,14 @@
8
8
  */
9
9
  import { createPortal } from 'react-dom'
10
10
  import { useEffect, useRef, useState, type ReactNode } from 'react'
11
- import { useStore, CONFIG, SOURCE_REVEALED, cap, stoppedFor } from './store.ts'
11
+ import { useStore, CONFIG, SOURCE_REVEALED, stoppedFor } from './store.ts'
12
12
  import { STOPPED_TIP, useStopped } from './api.ts'
13
13
  import { NO_COMMENTS_HERE, useComments } from './comments-store.ts'
14
14
  import { UNPLACED } from './hash.ts'
15
15
  import { Tip } from './Tip.tsx'
16
16
  import { cmd } from './commands.ts'
17
- import { CaretIcon, CheckIcon, CommentIcon, DevicesIcon, EyeSlashIcon, FrameCornersIcon, LaserIcon, MoonIcon, SlideFrameIcon, SunIcon, deviceIcon } from './icons.tsx'
17
+ import { CaretIcon, CheckIcon, CommentIcon, DevicesIcon, EyeSlashIcon, FrameCornersIcon, LaserIcon, MoonIcon, SlideFrameIcon, SunIcon } from './icons.tsx'
18
+ import { deviceIcon, deviceLabel } from './devices.tsx'
18
19
 
19
20
  const commentsStore = () => useComments.getState()
20
21
 
@@ -216,7 +217,7 @@ export function DevicePicker({ value, onSelect, includeDefault, includeFill, inc
216
217
  </>}
217
218
  {entries.map(([name, vp], i) => (
218
219
  <button key={name} onClick={() => pick(name)} title={`${vp.width} × ${vp.height}`}>
219
- {deviceIcon(name)}<span>{cap(name)}</span><kbd>{i < 9 ? i + 1 : ''}</kbd>
220
+ {deviceIcon(name)}<span className="dev-label">{deviceLabel(name)}</span><kbd>{i < 9 ? i + 1 : ''}</kbd>
220
221
  {value === name && <CheckIcon size={13} className="chk" />}
221
222
  </button>
222
223
  ))}
@@ -21,6 +21,8 @@
21
21
  * hand (A4.6 #30);
22
22
  * - `mv:open` (app 0.3, A4.6 #29, #30): a notice's click, opened by open-item.ts and answered as `mv:opened`. An app
23
23
  * without `onOpen` never sends one, and nothing here waits for it.
24
+ * - `mv:show` (app 1.1, spec 31 D1): a `marver://` link into this tab, shown by show.ts as `marver show` is; and
25
+ * show.ts asks `front()` once it showed a `marver show`.
24
26
  *
25
27
  * 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
26
28
  * the app said so and gave the whole presentation contract), and each `mv:present { epoch, w, h, frames }` is answered
@@ -32,7 +34,8 @@
32
34
  import { BOUNDS, MENU_IN, type AppState, type Busy, type Hello, type MarverAppV1, type MenuIn, type MenuItem, type Present } from '../../shared/app-api.ts'
33
35
  import type { CmdIn } from '../../shared/perf-records.ts'
34
36
  import { relayed } from './commands.ts'
35
- import { markSeenFrom } from './marks-ui.tsx'
37
+ import { markSeenFrom, resolveAllFrom } from './marks-ui.tsx'
38
+ import { canExportPdf, exportPdf } from './pdf-export.tsx'
36
39
  import { APP } from './marver-app.ts'
37
40
  import { TOP } from './inset.ts'
38
41
  import { api, canvasStopped } from './api.ts'
@@ -47,6 +50,8 @@ import { useJamQueue } from './jam-queue.ts'
47
50
  import { useJamUi } from './jam-state.ts'
48
51
  import { useJamVoice, voiceUntrusted } from './jam-voice.ts'
49
52
  import { endOpen, openLiveItem } from './open-item.ts'
53
+ import { showTarget } from './show.ts'
54
+ import { navigatedByHand } from './goto.ts'
50
55
 
51
56
  /** The ground under the strip (A2.14 #26): the shell's own - never a frame's pinned theme. */
52
57
  export const shellDark = (): boolean => { const s = useStore.getState(); return !!s.play || s.viewTheme === 'dark' }
@@ -130,28 +135,47 @@ const ITEMS: readonly Item[] = [
130
135
  ]
131
136
  const offered = (it: Item) => { try { return it.when?.() ?? true } catch { return false } }
132
137
 
138
+ /** File > Export PDF… (spec 31): the open board, offered only to an app that saves PDFs (`exportPdf`, app 1.1) - an
139
+ * older app refuses a menu naming the `file` group - and on a dev canvas with a board open. */
140
+ const pdfOffered = () => !!APP?.exportPdf && canExportPdf() && useStore.getState().board !== UNPLACED
141
+
133
142
  /** `mv:menu` now: at most 40 items, ids, labels and hints within the contract's bounds. */
134
143
  export function menuNow(): MenuItem[] {
135
- return ITEMS.filter(offered).slice(0, BOUNDS.menuItems).map((it) => ({
144
+ const items: MenuItem[] = ITEMS.filter(offered).map((it) => ({
136
145
  id: it.id, group: it.group, label: it.label, hint: it.hint,
137
146
  ...(it.checked ? { checked: (() => { try { return !!it.checked!() } catch { return false } })() } : {}),
138
147
  }))
148
+ if (pdfOffered()) items.unshift({ id: 'export-pdf', group: 'file', label: 'Export PDF…' })
149
+ return items.slice(0, BOUNDS.menuItems)
139
150
  }
140
151
 
141
152
  /** A menu item chosen in the app: its key, replayed on the shell's window - the same handlers, the same rules (a
142
153
  * text field holding the focus does not stop it: the person chose the item). An id the page does not offer now
143
154
  * does nothing. One id is the app's own, never in the menu: the tab's right-click Mark All as Seen clears every
144
- * frame's "new" in this canvas, here and on disk, as the sidebar's Mark all as seen does for a board. */
155
+ * frame's "new" in this canvas, here and on disk, as the sidebar's Mark all as seen does for a board; another, Resolve All
156
+ * Comments, resolves every open thread on the canvas (spec 31). */
145
157
  export function runMenuItem(id: string, from?: unknown): void {
146
158
  // spec 30 #51: the menu it came from, as app 1.0.1 says; app 1.0.0 says nothing, so `app`
147
159
  const where: CmdIn = (MENU_IN as readonly unknown[]).includes(from) ? from as MenuIn : 'app'
148
160
  if (id === 'mark-all-seen') {
149
161
  const s = useStore.getState()
150
- if (!PUBLISHED && s.marks) markSeenFrom({ via: 'relay', in: where }, Object.keys(s.marks.changed))
162
+ // each of the app's own items, once it acts, is the person's input: a show or link still loading gives way (spec 31 D3)
163
+ if (!PUBLISHED && s.marks) { navigatedByHand(); markSeenFrom({ via: 'relay', in: where }, Object.keys(s.marks.changed)) }
164
+ return
165
+ }
166
+ // the tab's Resolve All Comments (spec 31 B.1): every open thread on the canvas, as the sidebar's does for a board
167
+ if (id === 'resolve-all-comments') {
168
+ if (!PUBLISHED) { navigatedByHand(); void resolveAllFrom({ via: 'relay', in: where }, { canvas: true }) }
169
+ return
170
+ }
171
+ if (id === 'export-pdf') {
172
+ if (pdfOffered()) { navigatedByHand(); const s = useStore.getState(); void exportPdf(s.board, s.play ? { theme: s.play.theme } : {}, { via: 'relay', in: where }) }
151
173
  return
152
174
  }
153
175
  const it = ITEMS.find((x) => x.id === id)
154
176
  if (!it || !offered(it)) return
177
+ // the person chose it in the app's menu: a show or link still loading gives way (spec 31 D3; its key is untrusted)
178
+ navigatedByHand()
155
179
  // recorded by the key handler that runs it, once, as the relay it is (`cmd()` reads `relayed`)
156
180
  relayed(where, () => window.dispatchEvent(new KeyboardEvent('keydown', { ...it.key, bubbles: true, cancelable: true })))
157
181
  }
@@ -207,6 +231,9 @@ export function startAppBridge(): void {
207
231
  call(() => app.onMenuClick((p) => runMenuItem(typeof p?.id === 'string' ? p.id : '', p?.in)))
208
232
  // a notice's click (A4.6 #29, #30): the exact item, resolved against fresh reads and answered
209
233
  if (typeof app.onOpen === 'function') call(() => { app.onOpen!((p) => openLiveItem(p)) })
234
+ // a `marver://` link into this open tab (spec 31 D1): the same navigation command `marver show` sends - moved to, or
235
+ // a notice over unsent words; never a reload or a hash replaced under the page
236
+ if (typeof app.onShow === 'function') call(() => { app.onShow!((t) => { void showTarget(t, 'app') }) })
210
237
  // the one ground's presentation requests (0.27.2): answered only when the shell took the inset - a shell that did
211
238
  // not is placed below the strip and never asked (A3.8 #31)
212
239
  if (TOP) call(() => { answerPresents(app, call) })
@@ -252,7 +279,7 @@ export function startAppBridge(): void {
252
279
  }
253
280
  const menuChanged = () => { if (menuQueued) return; menuQueued = true; queueMicrotask(sendMenu) }
254
281
  sendMenu()
255
- useStore.subscribe((s, p) => { if (s.laser !== p.laser || s.laserInspect !== p.laserInspect) menuChanged() })
282
+ useStore.subscribe((s, p) => { if (s.laser !== p.laser || s.laserInspect !== p.laserInspect || (s.board === UNPLACED) !== (p.board === UNPLACED)) menuChanged() })
256
283
  useComments.subscribe((s, p) => { if (s.commentMode !== p.commentMode || s.show !== p.show) menuChanged() })
257
284
  useNotes.subscribe((s, p) => { if (s.all !== p.all) menuChanged() })
258
285
  useJamQueue.subscribe((s, p) => { if (!!s.session !== !!p.session) menuChanged() })
@@ -3,7 +3,7 @@ import { TransformWrapper, TransformComponent, type ReactZoomPanPinchContentRef
3
3
  import { CONFIG, useStore } from '../store.ts'
4
4
  import { letGoOfTile } from '../jam-state.ts'
5
5
  import { bootHash, linkTargets } from '../hash.ts'
6
- import { revealFrame } from '../goto.ts'
6
+ import { isLatest, navigated, navigatedByHand, navNow, revealFrame } from '../goto.ts'
7
7
  import { noteGestureCmd, startPerf } from '../perf.ts'
8
8
  import { FrameNode, HEADER } from './FrameNode.tsx'
9
9
  import { NOTE_GAP } from '../notes.ts'
@@ -61,6 +61,8 @@ let keepTimer: ReturnType<typeof setTimeout> | undefined
61
61
  let keepPending: (() => void) | undefined
62
62
  /** Where the camera's flight lands (a fit, a zoom), for canvasCtl.landing: read only while rzpp animates. */
63
63
  let flight: Camera | null = null
64
+ /** Each flight's number: a background tab's landing re-applies itself only while it is still the newest */
65
+ let flyGen = 0
64
66
  function keepCamera(x: number, y: number, scale: number) {
65
67
  if (!WS) return
66
68
  const board = useStore.getState().board
@@ -163,7 +165,7 @@ export function animateLayout(ms = 360) {
163
165
  // the control channel lives in ctl.ts so play/focus can import it without
164
166
  // dragging the canvas into a locked-shell bundle; Canvas assigns the real
165
167
  // implementations below when it mounts
166
- import { canvasCtl, type CanvasWheelInput } from './ctl.ts'
168
+ import { bootCancelled, canvasCtl, markBootLanded, type CanvasWheelInput } from './ctl.ts'
167
169
  import { cmd, type CmdHandle } from '../commands.ts'
168
170
  export { canvasCtl, type CanvasWheelInput }
169
171
  import { anchorNode, anchoredCamera, type Held } from './anchor.ts'
@@ -197,7 +199,7 @@ function GroupCaptions() {
197
199
  style={{ transform: `translate(${g.x}px, ${g.y}px) translateY(calc(-100% - clamp(4px, 8px * var(--sh-inv, 1), 40px)))` }}
198
200
  title="Select all variants"
199
201
  onPointerDown={(e) => e.stopPropagation()}
200
- onClick={() => { cmd('group-fit', { via: 'click', in: 'shell', frames: g.keys.length }); useStore.getState().selectMany(g.keys); canvasCtl.fitNodes(g.keys) }}>
202
+ onClick={() => { cmd('group-fit', { via: 'click', in: 'shell', frames: g.keys.length }); navigated(); useStore.getState().selectMany(g.keys); canvasCtl.fitNodes(g.keys) }}>
201
203
  {id.split('/').map((s) => s[0].toUpperCase() + s.slice(1)).join(' / ')} · {g.ids.size} variants
202
204
  </div>
203
205
  )
@@ -214,9 +216,19 @@ export function Canvas() {
214
216
  const ref = useRef<ReactZoomPanPinchContentRef>(null)
215
217
  // every camera move the canvas aims (a fit, a zoom, a camera restored): where it lands, while rzpp flies there, and the
216
218
  // boot queue told - the first frame of a board starts now, ranked on that view, not once the flight is over
217
- const fly = (x: number, y: number, scale: number, ms: number) => {
219
+ const fly = (x: number, y: number, scale: number, msAsked: number) => {
220
+ // a tab in the background draws no frames: its camera lands at once, where a flight nobody sees would wait for it
221
+ // to come forward (`marver show` to a background tab, spec 31 D3)
222
+ const hidden = document.visibilityState === 'hidden'
223
+ const ms = hidden ? 0 : msAsked
224
+ const gen = ++flyGen
218
225
  flight = ms ? { x, y, scale } : null
226
+ // an older flight still in the air no longer counts: the camera is landed now
227
+ if (hidden && ref.current) ref.current.instance.animation = null
219
228
  ref.current?.setTransform(x, y, scale, ms, 'easeOut')
229
+ // ...but its frame queued before the tab went to the background still lands its own end when frames resume (the
230
+ // library cannot cancel it): this landing goes again right after it, unless a newer flight came since
231
+ if (hidden) requestAnimationFrame(() => { if (gen === flyGen) ref.current?.setTransform(x, y, scale, 0) })
220
232
  aimed()
221
233
  }
222
234
  const scaleTimer = useRef(0)
@@ -340,7 +352,8 @@ export function Canvas() {
340
352
  // refit through their own path.
341
353
  const booted = useRef(false)
342
354
  useEffect(() => {
343
- if (booted.current || nodes.length === 0) return
355
+ // the boot's camera, once: never for a later board load once the boot is over (an empty board boots with none)
356
+ if (booted.current || nodes.length === 0 || bootCancelled()) return
344
357
  let revealed = false
345
358
  booted.current = true
346
359
  // the page before this one reloaded itself when its canvas came back: its camera, on the board it showed
@@ -350,7 +363,10 @@ export function Canvas() {
350
363
  // reloaded this tab after a crash
351
364
  const named = !!(bootHash.n?.length || bootHash.f?.length || bootHash.s?.length)
352
365
  const cam = carried ?? (!named || APP_REOPEN ? savedCamera(board) : null)
366
+ // a navigation after this point (a person's, a show's) owns the camera: the boot's fit gives way to it
367
+ const nav = navNow()
353
368
  const fit = () => {
369
+ if (!isLatest(nav) || bootCancelled()) return
354
370
  const keys = linkTargets(bootHash, useStore.getState().nodes)
355
371
  if (keys.length) {
356
372
  useStore.setState({ selection: keys })
@@ -366,16 +382,20 @@ export function Canvas() {
366
382
  } else {
367
383
  canvasCtl.fitAll()
368
384
  // a link naming a frame this board does not show follows the frame where it lives
369
- if (bootHash.f?.length && !revealed) { revealed = true; void revealFrame(bootHash.f[0]) }
385
+ // under the boot's own navigation (no new one: a person's, or an applied show, supersedes it)
386
+ if (bootHash.f?.length && !revealed) { revealed = true; void revealFrame(bootHash.f[0], nav, () => !bootCancelled()) }
370
387
  }
371
388
  }
372
- requestAnimationFrame(() => {
389
+ // a frame, or at once in a tab in the background (it draws none until it comes forward)
390
+ const soon = (fn: () => void) => { if (document.visibilityState === 'hidden') setTimeout(fn, 0); else requestAnimationFrame(fn) }
391
+ soon(() => {
373
392
  fit()
374
393
  // published builds boot fast enough that rzpp's own init can land AFTER this fit
375
394
  // and stomp it back to the identity transform - one verification pass re-fits
376
395
  setTimeout(() => {
377
396
  const st = ref.current?.instance.transformState
378
397
  if (st && st.scale === 1 && st.positionX === 0 && st.positionY === 0) fit()
398
+ markBootLanded() // spec 31 D3: a show waits for this
379
399
  }, 150)
380
400
  })
381
401
  }, [nodes])
@@ -427,6 +447,7 @@ export function Canvas() {
427
447
  if (!app || !canvas) return
428
448
  let settle = 0
429
449
  const beginGesture = (panning: boolean) => {
450
+ navigatedByHand() // a person's pan or zoom: a show or link still loading gives way (spec 31 D3)
430
451
  // sh-camera = a CANVAS pan/zoom (the image-LOD freeze signal); sh-gesturing also drops iframe
431
452
  // pointer-events. A frame click/drag sets only sh-gesturing.
432
453
  document.getElementById('sh-world')?.classList.add('sh-gesturing', 'sh-camera')
@@ -494,13 +515,14 @@ export function Canvas() {
494
515
  document.getElementById('sh-world')?.classList[on ? 'add' : 'remove']('sh-gesturing', 'sh-camera')
495
516
  }
496
517
  const pan = (on: boolean) => () => {
518
+ if (on) navigatedByHand() // a person's drag-pan (spec 31 D3)
497
519
  camera(on)
498
520
  document.body.classList[on ? 'add' : 'remove']('sh-panning')
499
521
  const sp = spacePan.current
500
522
  if (sp && on) sp.panned = true
501
523
  else if (sp?.panned) { sp.h.done(); spacePan.current = null }
502
524
  }
503
- const zoom = (on: boolean) => () => camera(on)
525
+ const zoom = (on: boolean) => () => { if (on) navigatedByHand(); camera(on) } // a person's pinch (spec 31 D3)
504
526
 
505
527
  // no initialPosition props on the wrapper: rzpp applies them ASYNC after mount and
506
528
  // stomps the boot fit when data is inlined (published builds) - the boot fit owns
@@ -1,3 +1,4 @@
1
+ import { navigatedByHand } from '../goto.ts'
1
2
  import { memo, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
2
3
  import { cap, frameUrl, shownRev, useStore, CONFIG, type Node } from '../store.ts'
3
4
  import { admit, release } from './admission.ts'
@@ -300,6 +301,7 @@ export const FrameNode = memo(function FrameNode({ node }: { node: Node }) {
300
301
  const drag = (e: React.PointerEvent, mode: 'move' | 'e' | 's' | 'se') => {
301
302
  e.stopPropagation()
302
303
  if (e.button !== 0) return
304
+ navigatedByHand() // the person's own selection: a show or link still loading gives way (spec 31 D3)
303
305
  // shift-click toggles multi-selection instead of dragging (Figma convention)
304
306
  if (e.shiftKey && mode === 'move') { cmd('select', { via: 'click', in: 'shell', frame: node.frame }); select(node.key, true); return }
305
307
  if (mode === 'move') cmd('select', { via: 'click', in: 'shell', frame: node.frame })
@@ -423,7 +425,7 @@ export const FrameNode = memo(function FrameNode({ node }: { node: Node }) {
423
425
  {frame.variantGroup && (
424
426
  <div className="sh-vbadge sh-no-pan" title={`${frame.variantGroup} · variant ${frame.variant?.toUpperCase()} - click to select`}
425
427
  onPointerDown={(e) => e.stopPropagation()}
426
- onClick={(e) => { cmd('select', { via: 'click', in: 'shell', frame: node.frame }); select(node.key, e.shiftKey) }}>
428
+ onClick={(e) => { cmd('select', { via: 'click', in: 'shell', frame: node.frame }); navigatedByHand(); select(node.key, e.shiftKey) }}>
427
429
  <b>{frame.variant?.toUpperCase()}</b>
428
430
  <span>{variantName}</span>
429
431
  </div>
@@ -16,6 +16,22 @@ export interface CanvasWheelInput {
16
16
  ctrlKey: boolean; metaKey: boolean; clientX: number; clientY: number
17
17
  }
18
18
 
19
+ /** The board's first camera - its boot fit or restored camera (Canvas.tsx) - has been applied: a `marver show` that came
20
+ * during the boot waits for it (show.ts), so it never races the boot (spec 31 D3). */
21
+ let bootLandedNow: () => void = () => {}
22
+ export const bootLanded = new Promise<void>((r) => { bootLandedNow = r })
23
+ export function markBootLanded(): void { bootLandedNow() }
24
+
25
+ /**
26
+ * A show applied (spec 31 D3): every boot reveal still to come gives way to it - the boot camera (Canvas.tsx), the boot
27
+ * link's frame fallback (Canvas.tsx, App.tsx) and its thread (Comments.tsx) each read this before they act. One flag,
28
+ * never reset: from here on the camera is the show's, and later board loads never restore the boot link's place - after
29
+ * a failed boot too, even when the show's own board then fails (a failed board load like any other: accepted).
30
+ */
31
+ let bootCancelledFlag = false
32
+ export function cancelBoot(): void { bootCancelledFlag = true }
33
+ export const bootCancelled = (): boolean => bootCancelledFlag
34
+
19
35
  export const canvasCtl = {
20
36
  fitNode(_key: string) {},
21
37
  fitNodes(_keys: string[]) {},
@@ -137,9 +137,21 @@ export const COMMANDS = {
137
137
  'board-status': se('answer', { deadlineMs: S30, cancelled: true, failed: ['api'] }),
138
138
  // `nothing-new` (not in R12's table): no write goes, so no answer can come
139
139
  'mark-seen': se('answer', { noop: ['nothing-new'], failed: ['api'] }),
140
+ // spec 31 B: resolve every open thread in a scope; its notice's Undo. `nothing-open` (not in R12's table): no thread
141
+ // to resolve, or every one is Jam's work in progress
142
+ 'resolve-all': se('answer', { deadlineMs: S30, noop: ['nothing-open', 'published'], failed: ['api'] }),
143
+ 'resolve-undo': se('answer', { deadlineMs: S30, failed: ['api'] }),
144
+ // spec 31: a deck PDF - ends when the server takes the job (its progress is the notice's); `busy` - one is being made
145
+ 'export-pdf': se('answer', { deadlineMs: S30, noop: ['busy'], failed: ['api'] }),
146
+ 'export-pdf-cancel': se('answer', { failed: ['api'] }),
147
+ // an app with no exportPdf (1.0.1): the notice's Download of the file it holds; `nothing-ready` - none waits
148
+ 'export-pdf-download': se('answer', { noop: ['nothing-ready'] }),
140
149
  'add-to-board': se('answer', { failed: ['api'] }),
141
150
  'update-copy': se('clipboard', { failed: CLIP }),
142
151
  'update-dismiss': se('2raf'),
152
+ // `marver show` over unsent words (spec 31 D3): the notice's Go moves the tab (the camera lands), × leaves it be
153
+ 'show-go': se('camera', { cancelled: true }),
154
+ 'show-dismiss': se('2raf'),
143
155
  'notice-view': se('thread', { failed: ['missing'] }),
144
156
  'notice-retry': se('answer', { deadlineMs: S30, failed: ['refused', 'missing'] }),
145
157
  'notice-dismiss': se('2raf'),
@@ -154,6 +166,13 @@ export const COMMANDS = {
154
166
  'comment-reply': se('answer', { deadlineMs: S30, failed: ['send-failed', 'signed-out'] }),
155
167
  'draft-discard': se('2raf'),
156
168
  'comment-resolve': se('answer', { deadlineMs: S30, failed: ['send-failed'] }),
169
+ // spec 31 C: your own message - open its editor, save the words, delete it (asked first, then for real); ⌘A in a card
170
+ 'comment-edit': se('2raf'),
171
+ 'comment-edit-save': se('answer', { deadlineMs: S30, failed: ['send-failed', 'signed-out'] }),
172
+ 'comment-delete-cancel': se('2raf'),
173
+ 'comment-delete-ask': se('2raf'),
174
+ 'comment-delete': se('answer', { deadlineMs: S30, failed: ['send-failed', 'signed-out'] }),
175
+ 'thread-select-all': se('selection'),
157
176
  'mention-pick': once(),
158
177
  'mention-dismiss': once(),
159
178
  'thread-open': se('2raf'),
@@ -762,4 +781,5 @@ export const RELAYS: readonly Relay[] = [
762
781
  { from: "the stage's post({ type }) (stage/main.tsx)", owner: "Play.tsx's stage message branch for that type", why: 'the shell executes it' },
763
782
  { from: 'app-bridge.ts runMenuItem (a synthetic keydown)', owner: "App.tsx's key handler branch", why: "#51: via 'relay', in 'menu', 'tab-menu' or 'app'" },
764
783
  { from: "app-bridge.ts runMenuItem('mark-all-seen')", owner: 'mark-seen', why: "#51: via 'relay', in 'tab-menu'" },
784
+ { from: "app-bridge.ts runMenuItem('resolve-all-comments')", owner: 'resolve-all', why: "#51: via 'relay', in 'tab-menu' (spec 31 B.1)" },
765
785
  ]
@@ -5,7 +5,7 @@
5
5
  * on which one it is beyond capability flags the endpoints themselves report.
6
6
  */
7
7
  import { create } from 'zustand'
8
- import { asks, replay, type CommentEvent, type Thread } from '../../shared/events.ts'
8
+ import { asks, asSentBy, replay, type CommentEvent, type Thread } from '../../shared/events.ts'
9
9
  import { mentionPeople, mentionsIn } from './mentions.ts'
10
10
  import { playPing } from './sound.ts'
11
11
  import { ROUTE } from '../const.ts'
@@ -53,6 +53,11 @@ interface CommentsState {
53
53
  draft: { nodeKey: string; frame: string; anchor: unknown; board?: string } | null
54
54
  needsIdentity: boolean // published viewer tried to comment while signed out
55
55
  inviteToken: string | null // arrived via an invite link - claim flow, token known
56
+ /** dev (spec 31 C.2): the messages this machine's human wrote, per board - the server's record (own.json), never
57
+ * the email. null until read (or on a published canvas, where the opaque author id decides) */
58
+ ownership: Record<string, Set<string>> | null
59
+ /** what the server's comment API takes (spec 31 C.6): an older published server has no `delete` - the shell hides it */
60
+ caps: { delete: boolean }
56
61
 
57
62
  load(board: string): Promise<void>
58
63
  live(board: string): () => void
@@ -72,6 +77,15 @@ interface CommentsState {
72
77
  reply(threadId: string, body: string): Promise<void>
73
78
  replyOk(threadId: string, body: string, h?: CmdHandle): Promise<boolean>
74
79
  resolve(threadId: string, reopen?: boolean, h?: CmdHandle): Promise<void>
80
+ /** Is this message mine to edit or delete (spec 31 C.2)? Never an agent's; locally the server's record decides, on a
81
+ * published canvas the original message's opaque author id against /me's. */
82
+ isMine(board: string | undefined, msg: { id: string; author?: { id?: string }; agent?: boolean }): boolean
83
+ /** Edit one of my messages (spec 31 C.3): an `edit` event with the new words, to the thread's own log. */
84
+ edit(threadId: string, msgId: string, body: string, h?: CmdHandle): Promise<boolean>
85
+ /** Delete one of my messages (spec 31 C.4): a `delete` tombstone, to the thread's own log. */
86
+ remove(threadId: string, msgId: string, h?: CmdHandle): Promise<boolean>
87
+ /** One sweep of every board's log now (after a resolve-all or its Undo). */
88
+ sweep(): Promise<void>
75
89
  setMode(on: boolean): void
76
90
  setShow(show: boolean): void
77
91
  setShowAnchor(on: boolean): void
@@ -250,12 +264,38 @@ export const useComments = create<CommentsState>((set, get) => {
250
264
  })))
251
265
  union(results.flatMap((evs) => evs ?? []))
252
266
  names.forEach((n, i) => { if (results[i] !== null) baselinedBoards.add(n) })
267
+ if (get().local) await readOwnership()
268
+ }
269
+ /** dev: the messages this machine's human wrote (spec 31 C.2) - read with each sweep; a 404 (an older server) leaves
270
+ * none mine, so nothing offers an edit the server would refuse */
271
+ const readOwnership = async () => {
272
+ try {
273
+ const r = await request('comment-ownership', { headers: { 'x-mv-c': csrf() } })
274
+ if (!r.ok) return
275
+ const b = await r.json() as { boards?: Record<string, string[]> }
276
+ // (no prototype: a board may be called `constructor`)
277
+ const next: Record<string, Set<string>> = Object.create(null)
278
+ for (const [k, ids] of Object.entries(b.boards ?? {})) if (Array.isArray(ids)) next[k] = new Set(ids)
279
+ // what this page wrote since stays mine (its sweep may have read the file a moment before the write)
280
+ for (const [k, ids] of Object.entries(get().ownership ?? {})) for (const id of ids) (Object.hasOwn(next, k) ? next[k] : (next[k] = new Set())).add(id)
281
+ set({ ownership: next })
282
+ } catch { /* the next sweep */ }
283
+ }
284
+ /** The server's capabilities (spec 31 C.6): only a JSON answer that says `delete` counts - an older server's 404 or
285
+ * gate page is an older server. */
286
+ const readCaps = async () => {
287
+ try {
288
+ const r = await request('capabilities')
289
+ const b = r.ok && (r.headers.get('content-type') ?? '').includes('application/json') ? await r.json() as { delete?: unknown } : null
290
+ set({ caps: { delete: b?.delete === true } })
291
+ } catch { /* keep what we have */ }
253
292
  }
254
293
 
255
294
  return {
256
295
  events: [], threads: [], board: null, me: null, myBoards: null, local: false, connected: false,
257
296
  mentionSeen: loadMentionSeen(),
258
297
  commentMode: false, show: true, showAnchor: true, active: null, draft: null, needsIdentity: false, inviteToken: null,
298
+ ownership: null, caps: { delete: false },
259
299
 
260
300
  poke(board) {
261
301
  const b = board ?? get().board
@@ -290,6 +330,7 @@ export const useComments = create<CommentsState>((set, get) => {
290
330
  myBoards: me.data.boards && typeof me.data.boards === 'object' ? me.data.boards : null,
291
331
  local: !!me.data.local, connected: !!me.data.connected,
292
332
  })
333
+ await readCaps()
293
334
  await fetchAll()
294
335
  // mark-seen: the board was actually PRESENTED (load runs on open, never
295
336
  // from the background poll), so the viewer's unread mark advances - the
@@ -346,7 +387,21 @@ export const useComments = create<CommentsState>((set, get) => {
346
387
  // union only what the server took - a rejected send must not leave phantoms; the
347
388
  // store is global now, so an accepted write lands regardless of the viewed board
348
389
  // (client ids keep the eventual SSE/poll echo idempotent)
349
- if (res.ok) { union(stamped); h?.done() }
390
+ if (res.ok) {
391
+ // published: the copy kept here wears my opaque id, as the server's projection of it will (spec 31 C.2, Codex
392
+ // r2) - the echo is a duplicate by id and dropped, so without it this message would not be mine until a reload
393
+ union(get().local ? stamped : asSentBy(stamped, get().me?.id))
394
+ // a message this page just wrote is mine (spec 31 C.2) - the server recorded it with the write
395
+ if (get().local) {
396
+ const mine = stamped.filter((e) => (e.type === 'create' || e.type === 'reply') && e.commentId)
397
+ if (mine.length) {
398
+ const own: Record<string, Set<string>> = Object.assign(Object.create(null), get().ownership ?? {})
399
+ own[target] = new Set([...(Object.hasOwn(own, target) ? own[target] : []), ...mine.map((e) => e.commentId!)])
400
+ set({ ownership: own })
401
+ }
402
+ }
403
+ h?.done()
404
+ }
350
405
  return res.ok
351
406
  },
352
407
 
@@ -384,6 +439,30 @@ export const useComments = create<CommentsState>((set, get) => {
384
439
  if (sent) h?.done(); else h?.fail('send-failed')
385
440
  },
386
441
 
442
+ isMine(board, msg) {
443
+ if (msg.agent) return false
444
+ const { local, ownership, me } = get()
445
+ if (local) return !!board && !!ownership && Object.hasOwn(ownership, board) && ownership[board].has(msg.id)
446
+ return !!me?.id && !!msg.author?.id && msg.author.id === me.id
447
+ },
448
+
449
+ async edit(threadId, msgId, body, h) {
450
+ const words = body.trim()
451
+ if (!words) { h?.fail('send-failed'); return false }
452
+ const origin = get().threads.find((t) => t.id === threadId)?.board
453
+ return get().send([{ id: uuid(), ts: Date.now(), type: 'edit', commentId: msgId, author: postAuthor(get().me), body: words }], origin, h)
454
+ },
455
+
456
+ async remove(threadId, msgId, h) {
457
+ const origin = get().threads.find((t) => t.id === threadId)?.board
458
+ const ok = await get().send([{ id: uuid(), ts: Date.now(), type: 'delete', commentId: msgId, author: postAuthor(get().me) }], origin, h)
459
+ // a deleted first comment with nothing under it is gone: its card closes
460
+ if (ok && get().active === threadId && !get().threads.some((t) => t.id === threadId)) set({ active: null })
461
+ return ok
462
+ },
463
+
464
+ async sweep() { await fetchAll() },
465
+
387
466
  async findThread(id) {
388
467
  if (!get().threads.some((t) => t.id === id)) await fetchAll()
389
468
  return get().threads.find((t) => t.id === id) ?? null
@@ -0,0 +1,42 @@
1
+ /**
2
+ * How a device shows in the shell (spec 31 Part F): its label and its icon, wherever a device name shows - the frame
3
+ * toolbar, the device menu, Play, the Jam panel. The server resolved each configured viewport's look once
4
+ * (device-icons.ts, `CONFIG.devices`); a name it did not resolve (a Jam step recorded under an older config) takes the
5
+ * same rules from its name (src/shared/devices.ts).
6
+ *
7
+ * A device's own SVG is drawn as a CSS `mask-image` filled with the ink (`currentColor`): an image, never DOM, so
8
+ * nothing in it can run or restyle the page. Only a base64 SVG data URI is ever drawn - anything else is the glyph.
9
+ */
10
+ import type { CSSProperties } from 'react'
11
+ import { lookFromName, type DeviceLook } from '../../shared/devices.ts'
12
+ import { DEVICE_GLYPH_ICONS, DevicesIcon } from './icons.tsx'
13
+ import { CONFIG } from './store.ts'
14
+
15
+ /** The only mask a device wears: a base64 SVG data URI, as the server writes it (nothing can close the `url()`). */
16
+ export const SAFE_MASK = /^data:image\/svg\+xml;base64,[A-Za-z0-9+/]+={0,2}$/
17
+
18
+ /** A device's look: the server's, else its name's. */
19
+ export function deviceLook(name: string): DeviceLook {
20
+ const d = CONFIG.devices
21
+ return d && Object.hasOwn(d, name) ? d[name] : lookFromName(name)
22
+ }
23
+
24
+ /** A device's label ("iPad landscape"). */
25
+ export const deviceLabel = (name: string): string => deviceLook(name).label
26
+
27
+ /** A look's icon at `size` px. */
28
+ export function DeviceGlyph({ look, size = 14 }: { look: DeviceLook; size?: number }) {
29
+ if (look.mask && SAFE_MASK.test(look.mask)) {
30
+ const url = `url("${look.mask}")`
31
+ const style: CSSProperties = { width: size, height: size, WebkitMaskImage: url, maskImage: url }
32
+ // an <i>, not a <span>: menu rules that stretch and capitalise a button's span are for its words
33
+ return <i className="sh-dev-mask" aria-hidden data-mv-device-mask="" style={style} />
34
+ }
35
+ const I = (look.glyph && DEVICE_GLYPH_ICONS[look.glyph]) || DevicesIcon
36
+ return <I size={size} style={look.rotate ? { transform: 'rotate(90deg)' } : undefined} />
37
+ }
38
+
39
+ /** A device name's icon; null (no device: the default view) is the generic Devices glyph. */
40
+ export function deviceIcon(name: string | null, size = 14) {
41
+ return name ? <DeviceGlyph look={deviceLook(name)} size={size} /> : <DevicesIcon size={size} />
42
+ }