@marver-design/marver 0.24.0 → 0.25.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 (80) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +1 -1
  3. package/dist/anchor-DVV732zR.mjs +33 -0
  4. package/dist/anchor-check-BE5VVN6Q.mjs +135 -0
  5. package/dist/{bake-ZhXq-X9f.mjs → bake-D8byeRzB.mjs} +1 -1
  6. package/dist/{boards-BRLnoTC3.mjs → board-tree-DRioF94d.mjs} +21 -277
  7. package/dist/boards-CGg6piKF.mjs +342 -0
  8. package/dist/{boards-Dv-Ipd8G.mjs → boards-Csxj2WJn.mjs} +23 -9
  9. package/dist/{build-ckcinlWH.mjs → build-BHoWLvSj.mjs} +63 -37
  10. package/dist/cli.mjs +31 -17
  11. package/dist/{collab-mAiNZlDj.mjs → collab-gqNdScUE.mjs} +39 -9
  12. package/dist/{comments-DZyobpxG.mjs → comments-Zoch254k.mjs} +19 -1
  13. package/dist/{comments-Dx1hCVOT.mjs → comments-pTLlhjh4.mjs} +150 -20
  14. package/dist/{config-BUKprFAp.mjs → config-cKgZBRj0.mjs} +1 -1
  15. package/dist/{context-BncTXjLB.mjs → context-D2ugHqwO.mjs} +17 -123
  16. package/dist/{daemon-CQv73-jM.mjs → daemon-Cl8KXGW4.mjs} +146 -64
  17. package/dist/{dev-gv4NS6Fk.mjs → dev-DJdgow47.mjs} +23 -11
  18. package/dist/{events-B3LBn74P.mjs → events-DnK_AnrW.mjs} +13 -15
  19. package/dist/imports-WBSnnHLb.mjs +143 -0
  20. package/dist/{init--3Moc4J7.mjs → init-DO4DhUt_.mjs} +28 -6
  21. package/dist/link-C-qUIuKU.mjs +160 -0
  22. package/dist/{board-status-BZSzc9Hp.mjs → manifest-DnAte_fB.mjs} +537 -13
  23. package/dist/marks-DFuintmJ.mjs +50 -0
  24. package/dist/marks-koRsbHfe.mjs +397 -0
  25. package/dist/{marver-id-gate-B_idGdHm.mjs → marver-id-gate-DGANtVyC.mjs} +2 -2
  26. package/dist/perf-CCisg-ny.mjs +49 -0
  27. package/dist/perf-QJIWtTw1.mjs +68 -0
  28. package/dist/{plugin-Sa08E7wO.mjs → plugin-CTyhjwoJ.mjs} +424 -207
  29. package/dist/{poster-B2QPvKOq.mjs → poster-D0cbV7hi.mjs} +1 -1
  30. package/dist/{profile-CrZohD6g.mjs → profile-Do0nGkXO.mjs} +1 -1
  31. package/dist/{publish-bakes-BJR3huhu.mjs → publish-bakes--l8ot2eQ.mjs} +9 -9
  32. package/dist/{serve-z5qtj_wJ.mjs → serve-wv2QWdxB.mjs} +6 -6
  33. package/dist/{share-BD-wcDQq.mjs → share-ScamJcks.mjs} +1 -1
  34. package/dist/{shot-Cw96h5Kk.mjs → shot-CckrGW-J.mjs} +19 -11
  35. package/dist/{shot-Dh6fV1Lm.mjs → shot-jdO_B6Qw.mjs} +1 -1
  36. package/dist/{summary-C7CAypbB.mjs → summary-CrW88e3q.mjs} +1 -1
  37. package/dist/{sync-DoA1vf4u.mjs → sync-C3035OnJ.mjs} +18 -8
  38. package/dist/{work-CBUfsOOT.mjs → work-CpJn1gwY.mjs} +8 -4
  39. package/dist/{work-ayuL_9Kk.mjs → work-GE88wb_3.mjs} +4 -4
  40. package/docs/boards-and-folders.md +62 -21
  41. package/docs/live-jam.md +10 -5
  42. package/package.json +1 -1
  43. package/src/client/frame-host/bridge.js +2 -1
  44. package/src/client/frame-host/inspect.js +195 -84
  45. package/src/client/frame-host/main.tsx +7 -2
  46. package/src/client/frame-host/registry.ts +5 -5
  47. package/src/client/shell/App.tsx +66 -22
  48. package/src/client/shell/BoardList.tsx +54 -11
  49. package/src/client/shell/Comments.tsx +79 -34
  50. package/src/client/shell/ContextMenu.tsx +5 -2
  51. package/src/client/shell/LockedApp.tsx +45 -12
  52. package/src/client/shell/Play.tsx +35 -34
  53. package/src/client/shell/Toolbar.tsx +3 -1
  54. package/src/client/shell/canvas/Canvas.tsx +1 -1
  55. package/src/client/shell/canvas/FrameNode.tsx +10 -5
  56. package/src/client/shell/canvas/sleep.ts +4 -3
  57. package/src/client/shell/canvas/updates.ts +55 -0
  58. package/src/client/shell/comments-store.ts +48 -19
  59. package/src/client/shell/goto.ts +11 -14
  60. package/src/client/shell/hash.ts +12 -5
  61. package/src/client/shell/icons.tsx +1 -2
  62. package/src/client/shell/legacy-links.ts +67 -0
  63. package/src/client/shell/marks-ui.tsx +17 -19
  64. package/src/client/shell/pin-layout.ts +37 -0
  65. package/src/client/shell/store.ts +312 -92
  66. package/src/client/shell/styles.css +10 -8
  67. package/src/client/stage/main.tsx +19 -2
  68. package/src/shared/anchor.ts +57 -0
  69. package/src/shared/board-tree.ts +27 -10
  70. package/src/shared/events.ts +19 -10
  71. package/src/shared/marks.ts +17 -12
  72. package/templates/AGENTS-embedded.md +34 -15
  73. package/templates/AGENTS-studio.md +34 -15
  74. package/templates/instructions/boards.md +9 -5
  75. package/templates/instructions/iterate.md +20 -10
  76. package/templates/instructions/jam.md +13 -4
  77. package/templates/instructions/publish.md +2 -1
  78. package/templates/instructions/reference/deck-story.md +2 -2
  79. package/dist/link-vXjxMHTG.mjs +0 -132
  80. package/dist/manifest-cyG3kbhk.mjs +0 -528
@@ -1,15 +1,17 @@
1
1
  import { useEffect, useRef, useState, type CSSProperties, type MouseEvent as ReactMouseEvent, type PointerEvent as ReactPointerEvent, type ReactNode } from 'react'
2
- import { useStore, HAS_ALL_SCENES, PUBLISHED, STATUS_AS_OF, fetchBoardTree, rememberMeta, rememberTitles, type BoardMeta, type TreeBase } from './store.ts'
2
+ import { useStore, PUBLISHED, STATUS_AS_OF, addToBoard, boardLabel, fetchBoardNames, fetchBoardTree, fetchMembership, rememberMeta, rememberTitles, type BoardMeta, type TreeBase } from './store.ts'
3
+ import { UNPLACED } from './hash.ts'
3
4
  import { LiveIcon, StatusIcon, TypeIcon } from './board-icons.tsx'
4
5
  import { StatusPicker } from './StatusPicker.tsx'
5
6
  import type { StatusWord } from '../../shared/board-types.ts'
6
7
  import { PHASE_LABEL, STATUS_LABEL } from '../../shared/status.ts'
7
8
  import { canvasCtl } from './canvas/Canvas.tsx'
9
+ import { navigated } from './goto.ts'
8
10
  import { rollup } from '../../shared/marks.ts'
9
11
  import { Bubble, useAsks } from './marks-ui.tsx'
10
12
  import { Tip } from './Tip.tsx'
11
13
  import { copyToClipboard, type MenuItem, type MenuOpener } from './ContextMenu.tsx'
12
- import { ArrowLineUpIcon, CardsIcon, CheckIcon, CardsThreeIcon, FolderIcon, FolderMinusIcon, FolderOpenIcon, FolderPlusIcon, PencilSimpleIcon, SignpostIcon } from './icons.tsx'
14
+ import { ArrowLineUpIcon, CardsIcon, CheckIcon, FolderIcon, FrameCornersIcon, FolderMinusIcon, FolderOpenIcon, FolderPlusIcon, PencilSimpleIcon, SignpostIcon } from './icons.tsx'
13
15
  import {
14
16
  applyDrop, boardsIn, createFolder, deleteFolder, depthOf, folderEntries, folderIn, folderOf, foldersIn, holdsFolders, humanize, INDENT, isOwnSlot, labelOf, listIn, moveBoard, moveFolderToRoot, newFolderSlot, parentOf, readTitle,
15
17
  resolveDrop, retitleFolder, rootIndex, slugFor,
@@ -47,6 +49,16 @@ function StatusTipLabel({ m }: { m: BoardMeta }) {
47
49
  return <div className="sh-tip-lines"><b>{head}</b>{rest.map((l, i) => <small key={i}>{l}</small>)}</div>
48
50
  }
49
51
 
52
+ /** Add to board… - a frame's menu in the Not on a board view (spec 26): every board, in sidebar
53
+ * order; one click pins the frame there, as `marver boards pin` does. */
54
+ export function AddToBoard({ frame, close }: { frame: string; close: () => void }) {
55
+ const [names, setNames] = useState<string[] | null>(null)
56
+ useEffect(() => { fetchBoardNames().then(setNames, () => setNames([])) }, [])
57
+ if (!names) return null
58
+ if (!names.length) return <div className="sub dim">No boards yet - ask your agent to make one</div>
59
+ return <>{names.map((n) => <button key={n} data-add-to={n} onClick={() => { close(); void addToBoard(n, [frame]) }}><CardsIcon size={15} /><span>{boardLabel(n)}</span></button>)}</>
60
+ }
61
+
50
62
  type Naming = { kind: 'board' | 'folder'; name: string } | { kind: 'new'; index: number; board?: string; parent: string | null }
51
63
  /** A mutation as intent: applied to whichever tree is current, so a 409 can replay it. */
52
64
  type Intent = (tree: TreeItem[]) => TreeItem[] | null
@@ -60,9 +72,10 @@ export function BoardList({ onMenu }: { onMenu: MenuOpener }) {
60
72
  const marks = useStore((s) => s.marks)
61
73
  const asks = useAsks()
62
74
  const framesOf = (boards: string[]) => boards.flatMap((b) => marks?.boards[b] ?? [])
63
- const seeAll = (boards: string[]): MenuItem[] => (!PUBLISHED ? [{ label: 'Mark all as seen', icon: <CheckIcon size={15} />, onClick: () => useStore.getState().markSeen(framesOf(boards), true) }] : []) // board slug → type and status (spec 20)
75
+ const seeAll = (boards: string[]): MenuItem[] => (!PUBLISHED ? [{ label: 'Mark all as seen', icon: <CheckIcon size={15} />, onClick: () => useStore.getState().markSeen(framesOf(boards)) }] : []) // board slug → type and status (spec 20)
64
76
  const label = (n: string) => labelOf(n, titles[n]) // a board's label; a folder's is labelOf(name, item.title)
65
77
  const [tree, setTree] = useState<TreeItem[]>([])
78
+ const [read, setRead] = useState(false) // the first tree read has answered
66
79
  const [naming, setNaming] = useState<Naming | null>(null)
67
80
  const [closed, setClosed] = useState<Record<string, true>>(readClosed)
68
81
  const [drag, setDrag] = useState<Drag | null>(null)
@@ -105,6 +118,7 @@ export function BoardList({ onMenu }: { onMenu: MenuOpener }) {
105
118
  rememberMeta(snap.meta) // ...and so do types and statuses (spec 20)
106
119
  lastErr.current = ''
107
120
  show()
121
+ setRead(true)
108
122
  return true
109
123
  } catch (e) {
110
124
  // a server-side error (a malformed registry, a symlinked boards dir) is worth saying
@@ -129,6 +143,24 @@ export function BoardList({ onMenu }: { onMenu: MenuOpener }) {
129
143
  // eslint-disable-next-line react-hooks/exhaustive-deps
130
144
  }, [])
131
145
 
146
+ // spec 26: the frames on no board - the Not on a board entry, there only when some exist (dev). Read
147
+ // again whenever the boards or the frames change; the open view follows what it lists
148
+ const [unplaced, setUnplaced] = useState<string[]>([])
149
+ const listed = useRef<string | null>(null) // the list last read (null = not yet)
150
+ const manifest = useStore((s) => s.manifest)
151
+ useEffect(() => {
152
+ if (PUBLISHED) return
153
+ let current = true
154
+ fetchMembership().then((m) => {
155
+ const key = m.unplaced.join()
156
+ if (!current || key === listed.current) return
157
+ if (listed.current !== null) useStore.getState().syncUnplaced(m.unplaced) // the open view follows, in place
158
+ listed.current = key
159
+ setUnplaced(m.unplaced)
160
+ }).catch(() => { /* keep the last list */ })
161
+ return () => { current = false }
162
+ }, [tree, manifest])
163
+
132
164
  const setOpen = (folder: string, open: boolean) => {
133
165
  setClosed((c) => {
134
166
  const next = { ...c }
@@ -139,6 +171,7 @@ export function BoardList({ onMenu }: { onMenu: MenuOpener }) {
139
171
  }
140
172
  const pick = async (name: string) => {
141
173
  if (name === useStore.getState().board) return
174
+ navigated() // a link still finding its board gives way
142
175
  await useStore.getState().switchBoard(name)
143
176
  setTimeout(() => canvasCtl.fitAll(), 60)
144
177
  }
@@ -208,7 +241,7 @@ export function BoardList({ onMenu }: { onMenu: MenuOpener }) {
208
241
  const stored = (slug: string) => (title === humanize(slug) ? '' : title)
209
242
  if (n.kind === 'board') {
210
243
  if (title === label(n.name)) { setNaming(null); return }
211
- if (boardsIn(tree).some((b) => b !== n.name && label(b) === title) || (HAS_ALL_SCENES && label('all-scenes') === title)) { taken('board'); return }
244
+ if (boardsIn(tree).some((b) => b !== n.name && label(b) === title)) { taken('board'); return }
212
245
  let r = await useStore.getState().renameBoard(n.name, stored(n.name), baseRef.current.boards[n.name])
213
246
  if (!r.ok && r.stale && await load()) r = await useStore.getState().renameBoard(n.name, stored(n.name), baseRef.current.boards[n.name]) // the file moved on (a drag just before, an agent): re-read, once more
214
247
  if (!r.ok) { useStore.getState().toast(r.error ?? 'rename failed'); return } // stay editing
@@ -337,7 +370,7 @@ export function BoardList({ onMenu }: { onMenu: MenuOpener }) {
337
370
  }
338
371
  const boardMenu = (n: string, parent: string | null): MenuItem[] => {
339
372
  const items: MenuItem[] = [{ label: 'Copy path', icon: <SignpostIcon size={15} />, onClick: () => copyToClipboard(`board: ${n}`, 'path copied') }, ...seeAll([n])]
340
- if (PUBLISHED || n === 'all-scenes') return items
373
+ if (PUBLISHED) return items
341
374
  // a feature or project board: its status first, as Linear puts it - the picker opens in place
342
375
  const m = useStore.getState().boardMeta[n]
343
376
  if (m?.status && m.settable?.length) items.unshift({
@@ -425,7 +458,7 @@ export function BoardList({ onMenu }: { onMenu: MenuOpener }) {
425
458
  // ONE seam per gap, overlaid (::after, no layout shift) on the row the gap touches: before the
426
459
  // first row of the item AT the index, or after the last row of a list's last item at its end.
427
460
  // Its left edge follows the indent of the list it lands in, so "inside" and "outside" never
428
- // draw alike. The root end draws before the pinned all-scenes row. An open EMPTY folder has no
461
+ // draw alike. The root end draws after the last row. An open EMPTY folder has no
429
462
  // row to draw on: its header draws the indented seam under itself (drop-in).
430
463
  const seam = ((): { row: string; where: 'before' | 'after'; depth: number } | null => {
431
464
  if (!drag || !drop || 'into' in drop) return null
@@ -433,7 +466,6 @@ export function BoardList({ onMenu }: { onMenu: MenuOpener }) {
433
466
  if (!items) return null
434
467
  const depth = depthOf(tree, drop.list)
435
468
  if (drop.index < items.length) return { row: key(items[drop.index]!), where: 'before', depth }
436
- if (drop.list === null && HAS_ALL_SCENES) return { row: 'b:all-scenes', where: 'before', depth: 0 }
437
469
  return items.length ? { row: lastRow(items[items.length - 1]!), where: 'after', depth } : null
438
470
  })()
439
471
  // a nested seam starts where that list's rows start: the row's own 8px padding plus its indent
@@ -449,7 +481,7 @@ export function BoardList({ onMenu }: { onMenu: MenuOpener }) {
449
481
  if (naming?.kind === 'board' && naming.name === n) return (
450
482
  <div key={`b:${n}`} data-board-row data-board={n} data-folder={parent ?? undefined} data-depth={depth} className={`it board editing${indent(depth)}${s.cls}`} style={s.style}><CardsIcon size={14} />{input(label(n))}</div>
451
483
  )
452
- const canDrag = !PUBLISHED && n !== 'all-scenes'
484
+ const canDrag = !PUBLISHED
453
485
  const item: Drag = { kind: 'board', name: n }
454
486
  // the board you are on shows nothing: its rows below speak for themselves
455
487
  const r = n === board ? { asks: 0, fresh: 0 } : rollup(marks, asks, framesOf([n]))
@@ -458,7 +490,7 @@ export function BoardList({ onMenu }: { onMenu: MenuOpener }) {
458
490
  className={`it board${indent(depth)}${n === board ? ' cur' : ''}${r.asks ? ' mk-ask' : r.fresh ? ' mk-new' : ''}${dragging ? ' dragging' : ''}${s.cls}`} style={s.style}
459
491
  // draggable rows switch on the pointer tap (onPointerUp), so their trailing mouse
460
492
  // click (detail >= 1) must be ignored to avoid a double switch; keyboard clicks
461
- // (detail === 0) and non-draggable rows (all-scenes, published) switch here as normal
493
+ // (detail === 0) and non-draggable rows (published) switch here as normal
462
494
  onClick={(e) => { if (!canDrag || e.detail === 0) void pick(n) }}
463
495
  onContextMenu={(e) => onMenu(e, boardMenu(n, parent))}
464
496
  onPointerDown={canDrag ? (e) => onPointerDown(e, item) : undefined}
@@ -466,7 +498,7 @@ export function BoardList({ onMenu }: { onMenu: MenuOpener }) {
466
498
  onPointerUp={canDrag ? onPointerUp : undefined}
467
499
  onPointerCancel={canDrag ? () => resetPointer() : undefined}
468
500
  onLostPointerCapture={canDrag ? (e) => { if (gestureRef.current?.pointerId === e.pointerId) resetPointer() } : undefined}>
469
- <LiveIcon live={working.includes(n)}>{n === 'all-scenes' ? <CardsThreeIcon size={14} /> : meta[n]?.type ? <TypeIcon type={meta[n].type!} /> : <CardsIcon size={14} />}</LiveIcon>
501
+ <LiveIcon live={working.includes(n)}>{meta[n]?.type ? <TypeIcon type={meta[n].type!} /> : <CardsIcon size={14} />}</LiveIcon>
470
502
  <span>{label(n)}</span>
471
503
  {/* the status for a screen reader, part of the board button's own name: the glyph is the eye's */}
472
504
  {meta[n]?.status && <span className="sh-sr" data-status-text>{`, ${statusTip(meta[n]).replace(/\n/g, '; ')}`}</span>}
@@ -542,7 +574,18 @@ export function BoardList({ onMenu }: { onMenu: MenuOpener }) {
542
574
  }
543
575
 
544
576
  const rows: ReactNode[] = listRows(tree, null, 0)
545
- if (HAS_ALL_SCENES) rows.push(boardRow('all-scenes', null, 0)) // a published bundle without it shows none
577
+ // no boards yet: say what to do (a fresh `--no-demo` canvas) - once the first read has answered
578
+ if (read && !boardsIn(tree).length && !naming) rows.push(<div key="empty" className="sub dim" data-no-boards>No boards yet - ask your agent to make one</div>)
579
+ // the frames on no board (spec 26), apart from the tree - never a drop target, never dragged
580
+ if (unplaced.length) {
581
+ const r = board === UNPLACED ? { asks: 0, fresh: 0 } : rollup(marks, asks, unplaced)
582
+ rows.push(
583
+ <button key="unplaced" data-unplaced className={`it board${board === UNPLACED ? ' cur' : ''}${r.asks ? ' mk-ask' : r.fresh ? ' mk-new' : ''}`} onClick={() => void pick(UNPLACED)}>
584
+ <FrameCornersIcon size={14} /><span>Not on a board</span>
585
+ {r.asks ? <i className="st"><Bubble n={r.asks} /></i> : <small>{unplaced.length}</small>}
586
+ </button>,
587
+ )
588
+ }
546
589
  return (
547
590
  <div className="sh-boards" ref={rootRef} onContextMenu={(e: ReactMouseEvent) => blankMenu(e)}>
548
591
  <div className="hd">
@@ -2,7 +2,8 @@
2
2
  * Comment surfaces on the canvas. Canvas-first: pins live ON the frame
3
3
  * at their anchored elements; an inactive frame collapses its open threads into a
4
4
  * top-right stack; the thread card opens beside its pin. Pins keep a screen-space
5
- * size via --sh-inv (the vbadge pattern) so zoom never shrinks them away.
5
+ * size via --sh-inv (the vbadge pattern) so zoom never shrinks them away, and never
6
+ * overlap (pin-layout.ts places them).
6
7
  */
7
8
  import { useEffect, useMemo, useRef, useState } from 'react'
8
9
  import { createPortal } from 'react-dom'
@@ -11,7 +12,9 @@ import { CONFIG, useStore, type Node } from './store.ts'
11
12
  import { threadHostKey } from './keys.ts'
12
13
  import { isNoteAnchor, resolveNoteAnchor, useNotes } from './notes.ts'
13
14
  import { canvasCtl } from './canvas/ctl.ts'
15
+ import { MARKER, placeMarkers, type Placed } from './pin-layout.ts'
14
16
  import { bootHash, buildHash, parseHash, writeHash } from './hash.ts'
17
+ import { isLegacyLink } from './legacy-links.ts'
15
18
  import { ArrowUpIcon, CheckIcon, CheckSquareOffsetIcon, LinkIcon, ParallelogramFillIcon, PencilSimpleIcon, PlusIcon, XIcon } from './icons.tsx'
16
19
  import { Tip } from './Tip.tsx'
17
20
  import { mentionAlerts, mentionPeople, mentionQueryAt, parseBody, type MentionPerson } from './mentions.ts'
@@ -115,6 +118,44 @@ export function MarkerFace({ threads, max = 3 }: { threads: Thread[]; max?: numb
115
118
  )
116
119
  }
117
120
 
121
+ type Point = { x: number; y: number }
122
+
123
+ /** Open threads in creation order - the order markers are placed in, so a newer one moves, never
124
+ * an older one. */
125
+ export const byCreation = (threads: Thread[]): Thread[] => [...threads].sort((a, b) => a.ts - b.ts || (a.id < b.id ? -1 : 1))
126
+
127
+ /** Place one surface's markers - a canvas frame (node px) or the stage (screen px, inv 1): fixed
128
+ * points, a fixed marker size, the column for threads with no point. It reads nothing a selection
129
+ * or an open card changes, so neither ever moves a marker. */
130
+ export const placePins = (threads: Thread[], points: Map<string, Point | null>, frameW: number, inv: number) =>
131
+ placeMarkers(byCreation(threads).map((t) => ({ id: t.id, point: points.get(t.id) ?? null })), frameW, inv)
132
+
133
+ /** The placed markers, with a thin line from each one that had to move to its point. */
134
+ export function Pins({ threads, placed, orphans, inv, active, alertIds }: {
135
+ threads: Thread[]; placed: Map<string, Placed>; orphans: Set<string>
136
+ inv: number; active: string | null; alertIds?: Set<string>
137
+ }) {
138
+ const { setActive } = useComments.getState()
139
+ return (
140
+ <>
141
+ {threads.map((t) => {
142
+ const p = placed.get(t.id)!
143
+ const orphan = orphans.has(t.id)
144
+ return [
145
+ p.lead && <i key={`${t.id}-lead`} data-lead={t.id} className="cm-lead" aria-hidden style={{ left: p.lead.x, top: p.lead.y, height: p.y - MARKER.h * inv - p.lead.y }} />,
146
+ <div key={t.id} data-thread={t.id} className={`cm-pin sh-no-pan${t.id === active ? ' on' : ''}${orphan ? ' orphan' : ''}${alertIds?.has(t.id) ? ' mention' : ''}`}
147
+ style={{ left: p.x, top: p.y, ...hueVars(anchorHue(t.anchor)) }}
148
+ onPointerDown={(e) => e.stopPropagation()}
149
+ onClick={(e) => { e.stopPropagation(); setActive(t.id === active ? null : t.id) }}
150
+ title={orphan ? 'the anchored element is gone - comment parked' : undefined}>
151
+ <MarkerFace threads={[t]} max={2} />
152
+ </div>,
153
+ ]
154
+ })}
155
+ </>
156
+ )
157
+ }
158
+
118
159
  /** Lives inside FrameNode's body, over the iframe. Owns anchor resolution for its frame. */
119
160
  export function CommentLayer({ node, frameId, iframe }: { node: Node; frameId: string; iframe: React.RefObject<HTMLIFrameElement | null> }) {
120
161
  const show = useComments((s) => s.show)
@@ -131,7 +172,11 @@ export function CommentLayer({ node, frameId, iframe }: { node: Node; frameId: s
131
172
  const threads = allThreads.filter((t) => t.frame === frameId && threadHostKey(t, allNodes) === node.key)
132
173
  const selected = useStore((s) => s.selection.includes(node.key))
133
174
  const { setActive } = useComments.getState()
134
- const [rects, setRects] = useState<Record<string, { x: number; y: number; w: number; h: number } | null>>({})
175
+ // each in-frame thread's attach point, in the frame's px - null when its element is gone
176
+ const [framePoints, setFramePoints] = useState<Record<string, Point | null>>({})
177
+ // the zoom markers are placed at: the store commits it once a zoom settles, never mid-gesture,
178
+ // so markers hold still while you zoom and land once
179
+ const scale = useStore((s) => s.scale)
135
180
  // a slide renders at its stage and the node scales it (FrameNode): rects the frame reports are
136
181
  // in stage px, so they map through the same fit into the node's coordinates
137
182
  const frameEntry = useStore((s) => s.frameFor(node))
@@ -139,6 +184,7 @@ export function CommentLayer({ node, frameId, iframe }: { node: Node; frameId: s
139
184
  const fit = stage ? stageFit(stage, { w: node.w, h: node.h }) : null
140
185
  const inNode = <R extends { x: number; y: number; w: number; h: number }>(r: R): R =>
141
186
  fit ? { ...r, x: fit.ox + r.x * fit.k, y: fit.oy + r.y * fit.k, w: r.w * fit.k, h: r.h * fit.k } : r
187
+ const pointInNode = (p: Point): Point => (fit ? { x: fit.ox + p.x * fit.k, y: fit.oy + p.y * fit.k } : p)
142
188
 
143
189
  const open = threads.filter((t) => !t.resolved)
144
190
  const anchored = open.filter((t) => (t.anchor as any)?.el)
@@ -150,28 +196,29 @@ export function CommentLayer({ node, frameId, iframe }: { node: Node; frameId: s
150
196
  // postMessage) or on a sticky note (spec 18: shell DOM, resolved right here)
151
197
  const inFrame = anchored.filter((t) => !isNoteAnchor(t.anchor))
152
198
  const onNote = anchored.filter((t) => isNoteAnchor(t.anchor))
153
- // resolve anchors against the live frame whenever threads or the document change
199
+ // resolve anchors against the live frame whenever threads, their anchors (a re-pin) or the
200
+ // document change
154
201
  useEffect(() => {
155
202
  const win = iframe.current?.contentWindow
156
203
  if (!win || node.status !== 'ready' || !inFrame.length) return
157
204
  const ask = () => win.postMessage({ type: 'sh:resolve-anchors', anchors: inFrame.map((t) => ({ key: t.id, anchor: t.anchor })) }, location.origin)
158
205
  const onMsg = (e: MessageEvent) => {
159
206
  if (e.source !== win || e.origin !== location.origin || e.data?.type !== 'sh:anchor-rects') return
160
- const next: typeof rects = {}
161
- for (const r of e.data.rects ?? []) next[r.key] = r.orphan ? null : r.rect
162
- setRects(next)
207
+ const next: typeof framePoints = {}
208
+ for (const r of e.data.rects ?? []) next[r.key] = r.orphan ? null : r.point
209
+ setFramePoints((cur) => (JSON.stringify(cur) === JSON.stringify(next) ? cur : next))
163
210
  }
164
211
  window.addEventListener('message', onMsg)
165
212
  ask()
166
213
  const iv = setInterval(ask, 4000) // re-renders, scroll, hot reloads - cheap to re-ask
167
214
  return () => { clearInterval(iv); window.removeEventListener('message', onMsg) }
168
- }, [node.status, inFrame.map((t) => t.id).join(','), iframe])
215
+ }, [node.status, inFrame.map((t) => `${t.id}:${JSON.stringify(t.anchor)}`).join(','), iframe])
169
216
  // note anchors: their own map, measured in the shell, in node-body coordinates (negative x -
170
217
  // the note is left of the frame). The composing draft is measured too (key 'draft'), so it
171
218
  // follows a fold like a saved pin. A folded column parks pins on the fold; a note whose file
172
219
  // is gone, or whose element the markdown no longer has, parks like an orphan. Re-measured on
173
220
  // every fold/unfold (twice: at once and past the transition) and on the same 4 s beat.
174
- const [noteRects, setNoteRects] = useState<typeof rects>({})
221
+ const [noteRects, setNoteRects] = useState<Record<string, { x: number; y: number; w: number; h: number } | null>>({})
175
222
  const notesState = useNotes()
176
223
  const draftOnNote = draft?.nodeKey === node.key && isNoteAnchor(draft.anchor) ? draft.anchor : null
177
224
  useEffect(() => {
@@ -191,7 +238,7 @@ export function CommentLayer({ node, frameId, iframe }: { node: Node; frameId: s
191
238
  const el = resolveNoteAnchor(a, body)
192
239
  return el ? toBody(el.getBoundingClientRect()) : null
193
240
  }
194
- const next: typeof rects = {}
241
+ const next: typeof noteRects = {}
195
242
  for (const t of onNote) next[t.id] = place(t.anchor)
196
243
  if (draftOnNote) next.draft = place(draftOnNote)
197
244
  setNoteRects(next)
@@ -226,8 +273,9 @@ export function CommentLayer({ node, frameId, iframe }: { node: Node; frameId: s
226
273
  const el = body && resolveNoteAnchor(anchor, body)
227
274
  if (el) el.setAttribute('data-sh-lock', '')
228
275
  }
229
- // active/draft/show/showAnchor/activeShown are the triggers; `open` is read fresh from the closure
230
- }, [active, draft, show, showAnchor, activeShown, node.status, node.key, frameId, iframe])
276
+ // active/draft/show/showAnchor/activeShown and the active anchor (a re-pin) are the triggers;
277
+ // `open` is read fresh from the closure
278
+ }, [active, draft, show, showAnchor, activeShown, JSON.stringify(open.find((t) => t.id === active)?.anchor ?? null), node.status, node.key, frameId, iframe])
231
279
 
232
280
  // the open card's frozen side (D3) - a HOOK, so it must live above the early returns; and the
233
281
  // reset must too: a card can close via the inactive-frame early return (clicking another frame),
@@ -254,15 +302,22 @@ export function CommentLayer({ node, frameId, iframe }: { node: Node; frameId: s
254
302
  )
255
303
  }
256
304
 
257
- const pinPos = (t: Thread) => {
305
+ // each open thread's attach point in node px: a note's where it was clicked on the note, a
306
+ // frame's where the frame says; none (the column) for a legacy frame-level pin, an orphan, or
307
+ // an anchor not resolved yet
308
+ const points = new Map<string, Point | null>()
309
+ const orphans = new Set<string>()
310
+ for (const t of open) {
258
311
  const a = t.anchor as any
259
- const fr = rects[t.id]
260
- const r = isNoteAnchor(a) ? noteRects[t.id] : fr && inNode(fr)
261
- if (a?.el && r) return { x: r.x + (a.pos?.fx ?? 0.5) * r.w, y: r.y + (a.pos?.fy ?? 0.5) * r.h, orphan: false }
262
- if (a?.el && r === null) return { x: node.w - 16, y: 16, orphan: true } // orphan parks top-right
263
- const p = a?.pos // frame-level: stored fraction of the frame
264
- return { x: (p?.fx ?? 0.94) * node.w, y: (p?.fy ?? 0.06) * node.h, orphan: false }
312
+ if (!a?.el) continue
313
+ const r = isNoteAnchor(a) ? noteRects[t.id] : undefined
314
+ const p = isNoteAnchor(a) ? (r ? { x: r.x + (a.pos?.fx ?? 0.5) * r.w, y: r.y + (a.pos?.fy ?? 0.5) * r.h } : r) : framePoints[t.id] && pointInNode(framePoints[t.id]!)
315
+ if (p === null) orphans.add(t.id)
316
+ points.set(t.id, p ?? null)
265
317
  }
318
+ const inv = 1 / Math.max(0.01, scale)
319
+ const placed = placePins(open, points, node.w, inv)
320
+ const pinAt = (t: Thread): Placed => placed.get(t.id)!
266
321
 
267
322
  // The card's SIDE, chosen ONCE per open and frozen (D3 - never switches mid-read): the pin's
268
323
  // side of the frame first, skipping a side another frame's screen rect occupies, then wherever
@@ -290,7 +345,7 @@ export function CommentLayer({ node, frameId, iframe }: { node: Node; frameId: s
290
345
  // panel is a card nobody can read (a note's gutter makes that reach likelier)
291
346
  const panelRight = document.querySelector('.sh-panel:not(.closed)')?.getBoundingClientRect().right ?? 0
292
347
  const room = (s: 'l' | 'r') => (s === 'r' ? window.innerWidth - rect.right : rect.left - gutter - panelRight) >= W + GAP
293
- const prefer: ('l' | 'r')[] = pinPos(activeThread2).x < node.w / 2 ? ['l', 'r'] : ['r', 'l']
348
+ const prefer: ('l' | 'r')[] = pinAt(activeThread2).x < node.w / 2 ? ['l', 'r'] : ['r', 'l']
294
349
  return prefer.find((s) => room(s) && !occupied(s)) ?? prefer.find(room) ?? prefer[0]
295
350
  }
296
351
  sideRef.current = { id: activeThread2.id, side: compute() }
@@ -299,21 +354,9 @@ export function CommentLayer({ node, frameId, iframe }: { node: Node; frameId: s
299
354
 
300
355
  return (
301
356
  <>
302
- {open.map((t) => {
303
- const { x, y, orphan } = pinPos(t)
304
- const isActive = t.id === active
305
- return (
306
- <div key={t.id} className={`cm-pin sh-no-pan${isActive ? ' on' : ''}${isActive && cardSide === 'r' ? ' tail-r' : ''}${orphan ? ' orphan' : ''}${alertIds.has(t.id) ? ' mention' : ''}`}
307
- style={{ left: x, top: y, ...hueVars(anchorHue(t.anchor)) }}
308
- onPointerDown={(e) => e.stopPropagation()}
309
- onClick={(e) => { e.stopPropagation(); setActive(t.id === active ? null : t.id) }}
310
- title={orphan ? 'the anchored element is gone - comment parked' : undefined}>
311
- <MarkerFace threads={[t]} />
312
- </div>
313
- )
314
- })}
357
+ <Pins threads={open} placed={placed} orphans={orphans} inv={inv} active={active} alertIds={alertIds} />
315
358
  {activeThread2 && (
316
- <ThreadCard key={active} thread={activeThread2} at={pinPos(activeThread2)} bounds={{ w: node.w, h: node.h }} nodeKey={node.key} side={cardSide}
359
+ <ThreadCard key={active} thread={activeThread2} at={pinAt(activeThread2)} bounds={{ w: node.w, h: node.h }} nodeKey={node.key} side={cardSide}
317
360
  flank={cardSide === 'l' ? (noteColumn() ? 'note' : flankBadge ? 'badge' : flankShim ? 'shim' : null) : null} />
318
361
  )}
319
362
  {draft?.nodeKey === node.key && (() => {
@@ -943,6 +986,8 @@ export function revealThread(c: string): boolean {
943
986
  /** Board-level comment wiring: load + liveness + mode broadcast, one instance in App. */
944
987
  let bootThreadConsumed = false
945
988
  let pendingThread: string | null = null // cross-board deep link awaiting its board's comments
989
+ /** Open this thread once the board just switched to has loaded its comments (an old link, App.tsx). */
990
+ export const parkThread = (id: string) => { pendingThread = id }
946
991
  export function CommentsController() {
947
992
  const ctlShowAnchor = useComments((s) => s.showAnchor)
948
993
  const board = useStore((s) => s.board)
@@ -999,7 +1044,7 @@ export function CommentsController() {
999
1044
  if (!s.local && !s.me) useComments.setState({ inviteToken: h.invite, needsIdentity: true })
1000
1045
  return
1001
1046
  }
1002
- if (!h.c) return
1047
+ if (!h.c || isLegacyLink(h)) return // an old All Scenes link: App.tsx finds its board first
1003
1048
  if (!revealThread(h.c)) pendingThread = h.c
1004
1049
  }
1005
1050
  window.addEventListener('hashchange', onHash)
@@ -1,6 +1,7 @@
1
1
  import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 'react'
2
2
  import { createPortal } from 'react-dom'
3
3
  import { useStore, SOURCE_REVEALED } from './store.ts'
4
+ import { UNPLACED } from './hash.ts'
4
5
 
5
6
  /** Copy text to the clipboard, toasting the outcome. Success is confirmed out loud; a
6
7
  * blocked clipboard (no user gesture / permission) says so instead of failing silently. */
@@ -13,8 +14,10 @@ export function copyToClipboard(text: string, okMsg: string) {
13
14
  * toolbar, and ⇧P: the board it sits on, the frame id, and its file. */
14
15
  // stripped build: the file column would only show the opaque token, so the
15
16
  // copy keeps what is still honest - the board and the frame id
16
- export const framePath = (board: string, f: { id: string; file: string }) =>
17
- SOURCE_REVEALED ? `board: ${board} · frame: ${f.id} (${f.file})` : `board: ${board} · frame: ${f.id}`
17
+ export const framePath = (board: string, f: { id: string; file: string }) => {
18
+ const where = board === UNPLACED ? 'not on a board' : `board: ${board}`
19
+ return SOURCE_REVEALED ? `${where} · frame: ${f.id} (${f.file})` : `${where} · frame: ${f.id}`
20
+ }
18
21
 
19
22
  /** A menu row. `panel` makes it open a panel IN PLACE of the menu (a picker - the board's status),
20
23
  * drawn by the caller and handed `close`; `onClick` then is not called. */
@@ -10,9 +10,10 @@
10
10
  * within what the lock allows.
11
11
  */
12
12
  import { Component, useEffect, useRef, type ReactNode } from 'react'
13
- import { useStore, landingMode, tabTitle } from './store.ts'
13
+ import { useStore, landingBoard, landingMode, tabTitle } from './store.ts'
14
14
  import { enterFocus, enterPlay, enterSlides, PlayOverlay, playCtl } from './Play.tsx'
15
- import { bootHash, parseHash, writeHash } from './hash.ts'
15
+ import { UNPLACED, bootHash, parseHash, retargetBoot, writeHash } from './hash.ts'
16
+ import { isLegacyLink, landLegacy } from './legacy-links.ts'
16
17
  import { useComments } from './comments-store.ts'
17
18
 
18
19
  export class ShellBoundary extends Component<{ children: ReactNode }, { err: Error | null }> {
@@ -31,6 +32,15 @@ export class ShellBoundary extends Component<{ children: ReactNode }, { err: Err
31
32
  }
32
33
 
33
34
  let booted = false
35
+ /** A thread a link names: opened on the stage once the comments are on its board (a board's load
36
+ * closes the open thread, so never before - the effect below opens it after). */
37
+ let pendingThread: string | null = null
38
+ const openPending = () => {
39
+ const c = useComments.getState()
40
+ if (!pendingThread || c.board !== useStore.getState().board || !c.threads.some((t) => t.id === pendingThread)) return
41
+ c.setActive(pendingThread)
42
+ pendingThread = null
43
+ }
34
44
 
35
45
  export function App() {
36
46
  const toasts = useStore((s) => s.toasts)
@@ -38,19 +48,24 @@ export function App() {
38
48
 
39
49
  /** The landing rule, enforced: the mode the lock pinned, entered on boot and
40
50
  * re-entered if anything ever drops the overlay - there is no other surface. */
41
- const land = () => {
51
+ const land = (at?: string) => {
42
52
  const s = useStore.getState()
43
53
  if (s.play) return
44
54
  const mode = landingMode(s.board)
45
- if (mode === 'focus') enterFocus()
46
- else if (mode === 'slides') enterSlides()
47
- else enterPlay()
55
+ if (mode === 'focus') enterFocus(at)
56
+ else if (mode === 'slides') enterSlides(at ? { at } : undefined)
57
+ else enterPlay(at ? { at } : undefined)
48
58
  }
49
59
 
50
60
  useEffect(() => {
51
61
  if (booted) return
52
62
  booted = true
53
63
  const start = async () => {
64
+ // an old All Scenes link: a real board, at the frame it names, with what to say about it
65
+ let notice: string | null = null
66
+ if (isLegacyLink(bootHash)) { const r = await landLegacy(bootHash); retargetBoot(r.hash); notice = r.notice }
67
+ // the Not on a board view is dev's: a published canvas opens its default board instead
68
+ if (bootHash.board === UNPLACED) retargetBoot({})
54
69
  if (bootHash.board && bootHash.board !== useStore.getState().board)
55
70
  useStore.setState({ board: bootHash.board, boardAuto: false })
56
71
  const ok = await boot()
@@ -59,7 +74,9 @@ export function App() {
59
74
  if (bootHash.focus) enterFocus(bootHash.focus.at, { ...bootHash.focus, deep: true })
60
75
  else if (bootHash.play?.slides) enterSlides(bootHash.play)
61
76
  else if (bootHash.play) enterPlay(bootHash.play)
62
- else land()
77
+ else land(bootHash.f?.[0])
78
+ if (notice) useStore.getState().toast(notice)
79
+ if (bootHash.c) { pendingThread = bootHash.c; openPending() }
63
80
  }
64
81
  const boot = useStore.getState().boot
65
82
  void start()
@@ -79,14 +96,30 @@ export function App() {
79
96
 
80
97
  // back/forward + pasted links, within what the lock allows
81
98
  useEffect(() => {
99
+ let popSeq = 0
82
100
  const onPop = async () => {
83
- const h = parseHash()
101
+ // a lookup newer navigation overtook - a link, a step on the stage - is dropped
102
+ const mine = ++popSeq, was = useStore.getState()
103
+ const parsed = parseHash()
104
+ const raw = parsed.board === UNPLACED ? {} : parsed // dev's view, and what it names: not here
105
+ // an old All Scenes link lands on a real board; it, and the bare #/, with no board: the landing one
106
+ const r = isLegacyLink(raw) ? await landLegacy(raw) : { hash: raw, notice: null }
107
+ const h = r.hash
108
+ const board = h.board ?? (h.focus ? undefined : await landingBoard())
84
109
  const s = useStore.getState()
85
- if (h.board && h.board !== s.board) {
86
- await s.switchBoard(h.board)
87
- land()
110
+ if (mine !== popSeq || s.board !== was.board || s.play?.at !== was.play?.at) return
111
+ if (r.notice) s.toast(r.notice)
112
+ if (h.c) pendingThread = h.c
113
+ if (board && board !== s.board) {
114
+ await s.switchBoard(board)
115
+ useStore.getState().setPlay(null) // the stage restarts on the board the link names, at its frame
116
+ if (h.play?.slides) enterSlides(h.play)
117
+ else if (h.play) enterPlay(h.play)
118
+ else land(h.f?.[0])
88
119
  return
89
120
  }
121
+ openPending() // same board: its comments are here already
122
+ if (h.f?.length && s.play) return playCtl.setAt(h.f[0]) // the stage on screen steps to the frame named
90
123
  if (h.focus) enterFocus(h.focus.at, { ...h.focus, deep: true })
91
124
  // sync only holds WITHIN a mode: same-mode restores drive the MOUNTED
92
125
  // stage (sh:stage-set); crossing present↔slides re-enters and remounts
@@ -103,7 +136,7 @@ export function App() {
103
136
  useEffect(() => {
104
137
  if (!board) return
105
138
  const c = useComments.getState()
106
- void c.load(board)
139
+ void c.load(board).then(openPending)
107
140
  return c.live(board)
108
141
  }, [board])
109
142