@marver-design/marver 0.30.0 → 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.
- package/CHANGELOG.md +74 -0
- package/README.md +11 -7
- package/dist/{anchor-check-c52IDkiQ.mjs → anchor-check-B92s9tVv.mjs} +1 -1
- package/dist/{board-tree-BXR8dw4b.mjs → board-tree-DGj0HhEE.mjs} +6 -2
- package/dist/{boards-EH2onUXM.mjs → boards-Cim1GTKc.mjs} +32 -2
- package/dist/{boards-BeWtjGUM.mjs → boards-OlAhZ87x.mjs} +7 -7
- package/dist/{build-C3mUtjEn.mjs → build-BNssmbqd.mjs} +14 -17
- package/dist/{capture-DEtM4qm5.mjs → capture-HaS-1or8.mjs} +1 -1
- package/dist/cli.mjs +38 -20
- package/dist/{collab-BEAcXrBb.mjs → collab-D2NcrOB8.mjs} +53 -14
- package/dist/comment-actions-Bxf9Ld4g.mjs +351 -0
- package/dist/{comments-XNhMmSSu.mjs → comments-BakJQwaf.mjs} +85 -10
- package/dist/config-B0YcFtqS.mjs +510 -0
- package/dist/{context-BUnFiyA3.mjs → context-Cj2TcC0H.mjs} +3 -3
- package/dist/{daemon-B0Wi1OQ3.mjs → daemon-MxoEQajX.mjs} +223 -26
- package/dist/deep-link-DYtuT740.mjs +163 -0
- package/dist/{dev-5dlxoW28.mjs → dev-BBZe_brH.mjs} +23 -16
- package/dist/devices-uJZ2inMq.mjs +155 -0
- package/dist/{events-CLH4ijKP.mjs → events-Dieo1482.mjs} +49 -4
- package/dist/{init-CYlFaRzG.mjs → init-BgusplYn.mjs} +40 -10
- package/dist/{jam-Cj5gBvwD.mjs → jam-CkuLL8A8.mjs} +1 -1
- package/dist/{link-BFFRgrMt.mjs → link-Cmt9Xy4X.mjs} +54 -7
- package/dist/{logo-CXY-1yrn.mjs → logo-C9s7-Cy9.mjs} +89 -66
- package/dist/{ls-NqmePKOf.mjs → ls-DGVIW-Io.mjs} +1 -1
- package/dist/{manifest-DPZ3WNg_.mjs → manifest-CK8Qh4Nq.mjs} +255 -13
- package/dist/{marks-BnNANic9.mjs → marks-C8oX8kbE.mjs} +3 -3
- package/dist/{marks-DBp3h1Mc.mjs → marks-Dt-5JXCp.mjs} +18 -5
- package/dist/{marver-id-gate-vBLb_Icb.mjs → marver-id-gate-BAeuMeaU.mjs} +11 -7
- package/dist/md-B9_13Q0R.mjs +105 -0
- package/dist/notes-CRAX4wgk.mjs +148 -0
- package/dist/own-C8Mq0Hnf.mjs +128 -0
- package/dist/pdf-0m721FFn.mjs +117 -0
- package/dist/pdf-CZENT6t3.mjs +2299 -0
- package/dist/{perf-BCxAo0IS.mjs → perf-BB0XNt1M.mjs} +1 -1
- package/dist/{perf-6MOTHxay.mjs → perf-CIMijND6.mjs} +5 -5
- package/dist/{plugin-CXRoMA8g.mjs → plugin-CL8_wL7a.mjs} +519 -112
- package/dist/{poster-CYmCa00B.mjs → poster-B7uSjlEP.mjs} +1 -1
- package/dist/{profile-B1FKOM1e.mjs → profile-cdmSer1k.mjs} +1 -1
- package/dist/{publish-bakes-C_2ZtHou.mjs → publish-bakes-BjgDNeyS.mjs} +3 -3
- package/dist/{queue-DeSQm24g.mjs → queue-BLLfdlDw.mjs} +156 -11
- package/dist/{recover-XD8iXJOj.mjs → recover-ByuFQOF9.mjs} +2 -2
- package/dist/{serve-DQv3Ti6X.mjs → serve-kcF6-H8V.mjs} +4 -4
- package/dist/{session-VDJfXEEm.mjs → session-DBF-nQvq.mjs} +29 -3
- package/dist/{share-Bu_kuOKL.mjs → share-CS2mg27O.mjs} +1 -1
- package/dist/{shot-CRRGgxru.mjs → shot-BqwkdtKn.mjs} +4 -4
- package/dist/{shot-DBWN8hPP.mjs → shot-D2TQGo2V.mjs} +1 -1
- package/dist/show-B1u3DiJw.mjs +101 -0
- package/dist/{sizes-wjXDev3b.mjs → sizes-BckcL4Zz.mjs} +1 -1
- package/dist/{slots-Dn4Onb0V.mjs → slots-BOcfIqxy.mjs} +15 -3
- package/dist/{summary-Y8MY1Wuc.mjs → summary-cPmRDGpX.mjs} +1 -1
- package/dist/{sync-CMozOwZ0.mjs → sync-BNWwh8OF.mjs} +205 -7
- package/dist/{work-BYWD_1Zf.mjs → work-DRdzXPvg.mjs} +3 -3
- package/dist/{work-DJxH7cCX.mjs → work-Nv-n2_Un.mjs} +1 -1
- package/docs/app.md +49 -0
- package/docs/boards-and-folders.md +37 -6
- package/docs/jam-session.md +5 -0
- package/docs/live-jam.md +9 -0
- package/docs/pdf.md +108 -0
- package/docs/performance.md +2 -1
- package/docs/publish.md +9 -9
- package/docs/sharing.md +11 -0
- package/docs/slides.md +9 -0
- package/package.json +3 -1
- package/src/client/content/index.tsx +4 -2
- package/src/client/frame-host/main.tsx +3 -0
- package/src/client/shell/App.tsx +71 -24
- package/src/client/shell/BoardList.tsx +16 -7
- package/src/client/shell/Comments.tsx +77 -16
- package/src/client/shell/Play.tsx +24 -22
- package/src/client/shell/Toolbar.tsx +4 -3
- package/src/client/shell/app-bridge.ts +32 -5
- package/src/client/shell/canvas/Canvas.tsx +30 -8
- package/src/client/shell/canvas/FrameNode.tsx +3 -1
- package/src/client/shell/canvas/ctl.ts +16 -0
- package/src/client/shell/commands.ts +20 -0
- package/src/client/shell/comments-store.ts +81 -2
- package/src/client/shell/devices.tsx +42 -0
- package/src/client/shell/goto.ts +56 -9
- package/src/client/shell/icons.tsx +11 -4
- package/src/client/shell/jam-lines.ts +5 -3
- package/src/client/shell/jam-panel.tsx +17 -5
- package/src/client/shell/marks-ui.tsx +54 -0
- package/src/client/shell/notes.ts +21 -0
- package/src/client/shell/pdf-export.tsx +154 -0
- package/src/client/shell/pdf-notes.ts +20 -0
- package/src/client/shell/recorder.ts +3 -2
- package/src/client/shell/show.ts +250 -0
- package/src/client/shell/store.ts +79 -48
- package/src/client/shell/styles.css +43 -0
- package/src/shared/app-api.ts +49 -4
- package/src/shared/auto-place.ts +32 -0
- package/src/shared/board-tree.ts +3 -0
- package/src/shared/board-types.ts +6 -2
- package/src/shared/deep-link.ts +212 -0
- package/src/shared/devices.ts +89 -0
- package/src/shared/events.ts +48 -5
- package/src/shared/export-plan.ts +98 -0
- package/templates/AGENTS-embedded.md +76 -12
- package/templates/AGENTS-studio.md +76 -12
- package/templates/instructions/boards.md +6 -5
- package/templates/instructions/configure.md +32 -2
- package/templates/instructions/iterate.md +8 -0
- package/templates/instructions/jam.md +9 -0
- package/templates/instructions/publish.md +14 -4
- package/templates/instructions/review.md +4 -0
- package/templates/instructions/slides.md +67 -1
- package/templates/instructions/welcome.md +9 -5
- package/templates/playbooks/publish-canvas/PLAYBOOK.md +1 -1
- package/dist/config-BezZTiov.mjs +0 -182
package/src/shared/app-api.ts
CHANGED
|
@@ -51,7 +51,9 @@ export interface Busy { busy: boolean; unsaved: boolean; why: Why[] }
|
|
|
51
51
|
/** `mv:theme` - the shell's `play || slides || viewTheme === 'dark'` (A2.14 #26). */
|
|
52
52
|
export interface Theme { dark: boolean }
|
|
53
53
|
/** `mv:menu` - at most 40, no separators in 0.1 (A2.7). */
|
|
54
|
-
|
|
54
|
+
/** `group: 'file'` (app 1.1, spec 31): an item for the File menu under the canvas's name - a shell offers one only to an
|
|
55
|
+
* app that has `exportPdf` (an older app refuses a menu naming a group it does not know). */
|
|
56
|
+
export interface MenuItem { id: string; group: 'view' | 'jam' | 'file'; label: string; hint?: string; checked?: boolean }
|
|
55
57
|
/** `mv:app-state` (main to canvas). `untrusted`: stop every microphone track (A2.14 #13). A4 adds `mv:open` and
|
|
56
58
|
* `mv:capture`; this stays these three (A4.6 #29). */
|
|
57
59
|
export type AppState = 'shown' | 'hidden' | 'untrusted'
|
|
@@ -71,10 +73,11 @@ export type MenuIn = (typeof MENU_IN)[number]
|
|
|
71
73
|
export interface MenuClick { id: string; in?: MenuIn }
|
|
72
74
|
/**
|
|
73
75
|
* The ids main sends of its own, never in the page's `mv:menu`: the tab's right-click Mark All as Seen (A2.4's
|
|
74
|
-
* channels table: "Mark all as seen sends `mv:menu-click mark-all-seen` to the canvas")
|
|
75
|
-
*
|
|
76
|
+
* channels table: "Mark all as seen sends `mv:menu-click mark-all-seen` to the canvas") and Resolve All Comments
|
|
77
|
+
* (0.31, spec 31 B.1: sent only to a canvas whose features list `resolve-all`). A shell that does not know one does
|
|
78
|
+
* nothing with it.
|
|
76
79
|
*/
|
|
77
|
-
export const APP_MENU_IDS = ['mark-all-seen'] as const
|
|
80
|
+
export const APP_MENU_IDS = ['mark-all-seen', 'resolve-all-comments'] as const
|
|
78
81
|
|
|
79
82
|
/**
|
|
80
83
|
* `mv:present` (main to canvas; on the wire `{ doc, ...Present }`, stamped by main like `mv:app-state`): show the
|
|
@@ -157,6 +160,12 @@ export const CANVAS_CHANNELS = {
|
|
|
157
160
|
opened: 'mv:opened',
|
|
158
161
|
/** A4: a live picture of the document's own view - an invoke (A4.6 #35) */
|
|
159
162
|
capture: 'mv:capture',
|
|
163
|
+
/** spec 31 D1: a `marver://` link into a tab already open - the navigation command (main to canvas), never a reload */
|
|
164
|
+
show: 'mv:show',
|
|
165
|
+
/** spec 31 D3: the shell showed what `marver show` asked - its tab to the front of the window (canvas to main) */
|
|
166
|
+
front: 'mv:front',
|
|
167
|
+
/** app 1.1 (spec 31): a finished deck PDF saved where the person says - an invoke carrying only the job id */
|
|
168
|
+
exportPdf: 'mv:export-pdf',
|
|
160
169
|
} as const
|
|
161
170
|
|
|
162
171
|
/** Bounds main checks again (A2.14 #19): unknown fields are stripped, a known one of the wrong type or past its bound refuses the message. */
|
|
@@ -216,6 +225,14 @@ export const FEATURE = {
|
|
|
216
225
|
open: 'open',
|
|
217
226
|
/** 0.29.0 (A4.6 #33-#37): the shell asks `mv:capture` for live pictures and the server takes `POST /api/jam/picture/live` */
|
|
218
227
|
capture: 'capture',
|
|
228
|
+
/** 0.31.0 (spec 31 D1, D3): the shell takes `mv:show` (a deep link's place, moved to or noticed over unsent words)
|
|
229
|
+
* and asks `mv:front` once it showed a `marver show` */
|
|
230
|
+
show: 'show',
|
|
231
|
+
/** 0.31.0 (spec 31 B.1): the shell handles `mv:menu-click resolve-all-comments` - every open thread on the canvas resolved,
|
|
232
|
+
* but what Jam is at work on, with its Undo. The app offers the tab menu's Resolve All Comments only to a canvas that says so */
|
|
233
|
+
resolveAll: 'resolve-all',
|
|
234
|
+
/** 0.31.0 (spec 31 Part A): the server makes deck PDFs (`/__mv/api/pdf`) and the shell asks `mv:export-pdf` to save one */
|
|
235
|
+
pdf: 'pdf',
|
|
219
236
|
} as const
|
|
220
237
|
export type Feature = (typeof FEATURE)[keyof typeof FEATURE]
|
|
221
238
|
|
|
@@ -339,6 +356,19 @@ export type CaptureWhy = (typeof CAPTURE_WHY)[number]
|
|
|
339
356
|
* size in device pixels, its long side at most `BOUNDS.captureLong`. */
|
|
340
357
|
export type CaptureAnswer = { ok: true; png: Uint8Array; width: number; height: number } | { ok: false; why: CaptureWhy }
|
|
341
358
|
|
|
359
|
+
/** A deck PDF job's id (src/server/pdf.ts JOB_ID): 128 random bits, base64url. */
|
|
360
|
+
export const PDF_JOB = /^[A-Za-z0-9_-]{22}$/
|
|
361
|
+
/** The largest PDF main fetches and writes (spec 31: 200 MB). */
|
|
362
|
+
export const PDF_MAX = 200 * 2 ** 20
|
|
363
|
+
/** `mv:export-pdf` (canvas to main, an invoke; on the wire `{ doc, p }`): the finished job to save. */
|
|
364
|
+
export interface ExportPdfAsk { job: string }
|
|
365
|
+
/** Why nothing was saved: `cancelled` - the person closed the save panel; `untrusted` - the document is not the admitted,
|
|
366
|
+
* trusted one (before the panel or after it); `bad-job` - no such finished job on this canvas; `too-large` - past
|
|
367
|
+
* `PDF_MAX`; `failed` - the fetch or the write failed. */
|
|
368
|
+
export const EXPORT_PDF_WHY = ['cancelled', 'untrusted', 'bad-job', 'too-large', 'failed'] as const
|
|
369
|
+
export type ExportPdfWhy = (typeof EXPORT_PDF_WHY)[number]
|
|
370
|
+
export type ExportPdfAnswer = { ok: true } | { ok: false; why: ExportPdfWhy }
|
|
371
|
+
|
|
342
372
|
/**
|
|
343
373
|
* `window.marverApp`, exposed by the canvas preload to verified local canvases. Typed methods only: a page never
|
|
344
374
|
* names a channel. The six methods of 0.1 are required (marver-app.ts checks them); every A3 and A4 one is optional.
|
|
@@ -382,8 +412,23 @@ export interface MarverAppV1 {
|
|
|
382
412
|
* answers `untrusted` with no IPC; main answers `hidden`, `busy`, `bounds`, `empty`, `timeout` or `stale` otherwise
|
|
383
413
|
*/
|
|
384
414
|
capture?(a: CaptureAsk): Promise<CaptureAnswer>
|
|
415
|
+
/**
|
|
416
|
+
* spec 31 D1 (app 1.1): main's navigation command for a `marver://` link into this tab - the hash's own targets
|
|
417
|
+
* (shared/deep-link.ts `ShowTarget`), checked by the preload - null for the canvas's own board (a link whose place
|
|
418
|
+
* the app could not take); never a reload or a hash replaced under the page
|
|
419
|
+
*/
|
|
420
|
+
onShow?(fn: (t: ShowTarget | null) => void): () => void
|
|
421
|
+
/** spec 31 D3 (app 1.1): this document showed a `marver show` - main brings its tab and the window forward */
|
|
422
|
+
front?(): void
|
|
423
|
+
/**
|
|
424
|
+
* app 1.1 (spec 31): save a finished deck PDF. Only the job id crosses: main fetches the file itself from the admitted
|
|
425
|
+
* canvas origin, shows the save panel, checks the document again, and writes the file where the panel says
|
|
426
|
+
*/
|
|
427
|
+
exportPdf?(a: ExportPdfAsk): Promise<ExportPdfAnswer>
|
|
385
428
|
}
|
|
386
429
|
|
|
430
|
+
import type { ShowTarget } from './deep-link.ts'
|
|
431
|
+
|
|
387
432
|
/** Main's words for a reason (the hang sheet, the unsaved pill); `heights` is never named (A2.14 #18). */
|
|
388
433
|
export const WHY_WORDS: Record<Why, string | null> = {
|
|
389
434
|
'capture-recording': 'a capture being recorded',
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an auto board puts the frames it has not placed yet (friction log #15), one rule for the canvas (store.ts, as it
|
|
3
|
+
* loads a board) and the deck PDF's plan (pdf.ts), so a PDF's reading order is the one Play walks (spec 31 #2).
|
|
4
|
+
*
|
|
5
|
+
* Saved positions are kept. A grouped newcomer lands right of its variant group's rightmost node, on its row; any other
|
|
6
|
+
* goes past the board's right edge, on the top row - never at (0, 0) over a frame already there (the old published
|
|
7
|
+
* everything-board bug). Pure: the caller says each frame's size and builds its node.
|
|
8
|
+
*/
|
|
9
|
+
export interface PlacedNode { frame: string; x: number; y: number; w: number }
|
|
10
|
+
export interface NewcomerFrame { id: string; variantGroup?: string }
|
|
11
|
+
|
|
12
|
+
/** Append a node for every frame in `frames` not on `nodes` yet, in `frames`' order. Mutates and returns `nodes`. */
|
|
13
|
+
export function placeNewcomers<N extends PlacedNode, F extends NewcomerFrame>(
|
|
14
|
+
nodes: N[], frames: readonly F[], size: (f: F) => { w: number; h: number }, make: (f: F, x: number, y: number, w: number, h: number) => N,
|
|
15
|
+
): N[] {
|
|
16
|
+
const placed = new Set(nodes.map((n) => n.frame))
|
|
17
|
+
const groupOf = new Map(frames.map((f) => [f.id, f.variantGroup]))
|
|
18
|
+
let maxX = nodes.reduce((a, n) => Math.max(a, n.x + n.w), 0)
|
|
19
|
+
for (const f of frames) {
|
|
20
|
+
if (placed.has(f.id)) continue
|
|
21
|
+
placed.add(f.id)
|
|
22
|
+
const { w, h } = size(f)
|
|
23
|
+
const sibling = f.variantGroup
|
|
24
|
+
? nodes.filter((n) => groupOf.get(n.frame) === f.variantGroup).reduce<N | null>((a, n) => (!a || n.x + n.w > a.x + a.w ? n : a), null)
|
|
25
|
+
: null
|
|
26
|
+
const x = sibling ? sibling.x + sibling.w + Math.max(140, sibling.w * 0.12) : nodes.length ? maxX + 96 : 0
|
|
27
|
+
const y = sibling ? sibling.y : 0
|
|
28
|
+
nodes.push(make(f, x, y, w, h))
|
|
29
|
+
maxX = Math.max(maxX, x + w)
|
|
30
|
+
}
|
|
31
|
+
return nodes
|
|
32
|
+
}
|
package/src/shared/board-tree.ts
CHANGED
|
@@ -66,6 +66,9 @@ export const readTitle = (v: unknown): string | undefined => {
|
|
|
66
66
|
}
|
|
67
67
|
/** Title Case off a slug - the display when no title is set ("old-stuff" → "Old Stuff"). */
|
|
68
68
|
export const humanize = (s: string): string => s.replace(/-/g, ' ').replace(/(^|\s)\S/g, (c) => c.toUpperCase())
|
|
69
|
+
/** The canvas's name on screen: a name someone wrote (a capital or a space in it - `name: "iPad Lab"`) stays exactly as
|
|
70
|
+
* written; a slug-like one (a folder's name, `my-repo`) is humanized ("My Repo") (spec 31 G). */
|
|
71
|
+
export const canvasLabel = (name: string): string => (/[A-Z\s]/.test(name) ? name : humanize(name))
|
|
69
72
|
/** What a board, folder or scene is called on screen: its title, else its humanized slug. */
|
|
70
73
|
export const labelOf = (name: string, title?: string): string => title ?? humanize(name)
|
|
71
74
|
|
|
@@ -30,6 +30,10 @@ export const TYPE_ROLES: Record<BoardType, string> = {
|
|
|
30
30
|
export const TYPE_GRAMMAR = /^[a-z][a-z-]{0,31}$/
|
|
31
31
|
/** A type off a file: the word when it is on-grammar, else absent. */
|
|
32
32
|
export const readType = (v: unknown): string | undefined => (typeof v === 'string' && TYPE_GRAMMAR.test(v) ? v : undefined)
|
|
33
|
+
/** Words read as another type (spec 31): `slides` is a deck - for the type only; whether a board plays as slides stays
|
|
34
|
+
* its publish policy's. */
|
|
35
|
+
export const TYPE_ALIASES: Readonly<Record<string, KnownType>> = { slides: 'deck' }
|
|
36
|
+
const alias = (v: unknown): unknown => (typeof v === 'string' && Object.hasOwn(TYPE_ALIASES, v) ? TYPE_ALIASES[v] : v)
|
|
33
37
|
/** A type this Marver draws. */
|
|
34
38
|
export const knownType = (v: unknown): KnownType | undefined =>
|
|
35
39
|
(BOARD_TYPES as readonly string[]).includes(v as string) ? (v as KnownType) : undefined
|
|
@@ -37,8 +41,8 @@ export const knownType = (v: unknown): KnownType | undefined =>
|
|
|
37
41
|
/** A board's type: its own when it states one (an unknown word reads as plain - the board spoke
|
|
38
42
|
* for itself), else its folder's, else that folder's parent's, else plain. */
|
|
39
43
|
export function resolveType(own: unknown, folder?: unknown, parent?: unknown): BoardType {
|
|
40
|
-
if (readType(own)) return knownType(own) ?? 'plain'
|
|
41
|
-
return knownType(folder) ?? knownType(parent) ?? 'plain'
|
|
44
|
+
if (readType(own)) return knownType(alias(own)) ?? 'plain'
|
|
45
|
+
return knownType(alias(folder)) ?? knownType(alias(parent)) ?? 'plain'
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
/** The publish type a board's type proposes when its publish row names none - how a board
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec 31 Part D: the one contract for showing the human a place on a canvas - pure, no DOM, no Node, so the CLI,
|
|
3
|
+
* the dev server, the shell and the Mac app read it with one rule.
|
|
4
|
+
*
|
|
5
|
+
* - **A show target** (`ShowTarget`) is the hash's own targets on one board: `n` node keys, `f` frame ids, `s` scenes,
|
|
6
|
+
* `c` one comment thread. Node keys stay node keys (selecting one copy of a frame never selects every copy), and
|
|
7
|
+
* every value is checked against the hash grammar's characters - never a raw hash, never a URL, never script.
|
|
8
|
+
* - **The link hash** a target travels as: `#/b/<board>` and only the `f`, `s`, `n`, `c` query keys, each once, each
|
|
9
|
+
* value of the allowed characters (`targetFromHash` refuses anything else whole; `hashOfTarget` writes it back).
|
|
10
|
+
* - **A deep link** into the Mac app: `marver://open?ws=<folder>&to=<hash>[&port=<p>]`, both values written with
|
|
11
|
+
* `URLSearchParams` (so the hash's own `#`, `?` and `&` are percent-encoded inside `to`), 2 KB at most. `ws` is the
|
|
12
|
+
* canvas's folder (the app realpaths it and binds it to a running canvas); `port` is a hint the app uses only when
|
|
13
|
+
* that port's canvas has the same folder; a `to` that is not the grammar is dropped (the canvas opens on its default
|
|
14
|
+
* board), never the link.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export const DEEP_LINK_SCHEME = 'marver'
|
|
18
|
+
/** The longest deep link either side takes. */
|
|
19
|
+
export const DEEP_LINK_MAX = 2048
|
|
20
|
+
/** The most values one key carries. */
|
|
21
|
+
export const TARGET_LIST_MAX = 64
|
|
22
|
+
|
|
23
|
+
export interface ShowTarget {
|
|
24
|
+
board: string
|
|
25
|
+
/** node keys: exactly those nodes */
|
|
26
|
+
n?: string[]
|
|
27
|
+
/** frame ids: every node showing them */
|
|
28
|
+
f?: string[]
|
|
29
|
+
/** scenes: every frame of them */
|
|
30
|
+
s?: string[]
|
|
31
|
+
/** one comment thread, opened */
|
|
32
|
+
c?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The board-name grammar (shared/board-tree.ts BOARD_NAME, bounded) and the Not on a board view. */
|
|
36
|
+
const BOARD = /^[a-z0-9][a-z0-9-]{0,63}$/
|
|
37
|
+
export const UNPLACED_BOARD = '~unplaced'
|
|
38
|
+
const FRAME = /^[\w./-]{1,200}$/
|
|
39
|
+
const SCENE = /^[\w.-]{1,120}$/
|
|
40
|
+
/** a node key is the shell's: `<frame id>@<width>`, or a board file's own (`n-one`) */
|
|
41
|
+
const NODE = /^[\w./@:-]{1,200}$/
|
|
42
|
+
const THREAD = /^[\w-]{1,128}$/
|
|
43
|
+
|
|
44
|
+
const okBoard = (b: unknown): b is string => typeof b === 'string' && (BOARD.test(b) || b === UNPLACED_BOARD)
|
|
45
|
+
const okIn = (re: RegExp) => (v: unknown): v is string => typeof v === 'string' && re.test(v) && !v.includes('..')
|
|
46
|
+
const okFrame = okIn(FRAME), okScene = okIn(SCENE), okNode = okIn(NODE), okThread = okIn(THREAD)
|
|
47
|
+
const KEYS = { n: okNode, f: okFrame, s: okScene } as const
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A show target off the wire (pure): `board` a board name, `n`/`f`/`s` arrays of their grammar's values (at most
|
|
51
|
+
* `TARGET_LIST_MAX`, de-duplicated, empty ones left out), `c` a thread id. Unknown fields are stripped; a known one of
|
|
52
|
+
* the wrong type or any value off its grammar refuses the whole (null).
|
|
53
|
+
*/
|
|
54
|
+
export function checkShowTarget(v: unknown): ShowTarget | null {
|
|
55
|
+
if (!v || typeof v !== 'object' || Array.isArray(v)) return null
|
|
56
|
+
const r = v as Record<string, unknown>
|
|
57
|
+
if (!okBoard(r.board)) return null
|
|
58
|
+
const out: ShowTarget = { board: r.board }
|
|
59
|
+
for (const k of ['n', 'f', 's'] as const) {
|
|
60
|
+
if (r[k] === undefined) continue
|
|
61
|
+
const list = r[k]
|
|
62
|
+
if (!Array.isArray(list) || list.length > TARGET_LIST_MAX || !list.every(KEYS[k])) return null
|
|
63
|
+
const uniq = [...new Set(list as string[])]
|
|
64
|
+
if (uniq.length) out[k] = uniq
|
|
65
|
+
}
|
|
66
|
+
if (r.c !== undefined) {
|
|
67
|
+
if (!okThread(r.c)) return null
|
|
68
|
+
out.c = r.c
|
|
69
|
+
}
|
|
70
|
+
return out
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The link hash's target (pure): `#/b/<board>` with only `f`, `s`, `n`, `c`, each at most once, every value of its
|
|
75
|
+
* grammar; anything else - another route, another key, a repeated key, a bad value, more than 2 KB - is null.
|
|
76
|
+
*/
|
|
77
|
+
export function targetFromHash(hash: unknown): ShowTarget | null {
|
|
78
|
+
if (typeof hash !== 'string' || hash.length > DEEP_LINK_MAX) return null
|
|
79
|
+
const m = /^#\/b\/([^?#/]+)(?:\?([^#]*))?$/.exec(hash)
|
|
80
|
+
if (!m) return null
|
|
81
|
+
let board: string
|
|
82
|
+
try { board = decodeURIComponent(m[1]!) } catch { return null }
|
|
83
|
+
if (!okBoard(board)) return null
|
|
84
|
+
const raw: Record<string, unknown> = { board }
|
|
85
|
+
if (m[2] !== undefined && m[2] !== '') {
|
|
86
|
+
let params: URLSearchParams
|
|
87
|
+
try { params = new URLSearchParams(m[2]) } catch { return null }
|
|
88
|
+
const seen = new Set<string>()
|
|
89
|
+
for (const [k, v] of params) {
|
|
90
|
+
if (seen.has(k) || !['n', 'f', 's', 'c'].includes(k)) return null
|
|
91
|
+
seen.add(k)
|
|
92
|
+
if (k === 'c') raw.c = v
|
|
93
|
+
else raw[k] = v.split(',').map((x) => x.trim()).filter(Boolean)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return checkShowTarget(raw)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The target as the link hash (pure): the board, then `n`, `f`, `s`, `c` - every value already of URL-safe characters. */
|
|
100
|
+
export function hashOfTarget(t: ShowTarget): string {
|
|
101
|
+
const q = [
|
|
102
|
+
t.n?.length ? `n=${t.n.join(',')}` : '',
|
|
103
|
+
t.f?.length ? `f=${t.f.join(',')}` : '',
|
|
104
|
+
t.s?.length ? `s=${t.s.join(',')}` : '',
|
|
105
|
+
t.c ? `c=${t.c}` : '',
|
|
106
|
+
].filter(Boolean).join('&')
|
|
107
|
+
return `#/b/${t.board}${q ? `?${q}` : ''}`
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface DeepLink {
|
|
111
|
+
/** the canvas's folder, as the link wrote it (absolute; the app realpaths it) */
|
|
112
|
+
ws: string
|
|
113
|
+
/** the place, checked; null when the link named none or one off the grammar (the canvas's default board) */
|
|
114
|
+
to: ShowTarget | null
|
|
115
|
+
/** a hint: used only when that port's canvas has the same folder */
|
|
116
|
+
port?: number
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const CONTROL = /[\u0000-\u001f\u007f]/
|
|
120
|
+
|
|
121
|
+
/** `marver://open?ws=<folder>&to=<hash>[&port=<p>]`, written with URLSearchParams; null past 2 KB or with a bad folder. */
|
|
122
|
+
export function buildDeepLink(o: { ws: string; to?: string; port?: number }): string | null {
|
|
123
|
+
if (!o.ws.startsWith('/') || CONTROL.test(o.ws)) return null
|
|
124
|
+
const p = new URLSearchParams({ ws: o.ws })
|
|
125
|
+
if (o.to) p.set('to', o.to)
|
|
126
|
+
if (o.port !== undefined && Number.isInteger(o.port) && o.port > 0 && o.port < 65536) p.set('port', String(o.port))
|
|
127
|
+
const link = `${DEEP_LINK_SCHEME}://open?${p}`
|
|
128
|
+
return link.length <= DEEP_LINK_MAX ? link : null
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* A deep link as the app hears it (pure): `marver://open` and nothing else on its path, at most 2 KB, only `ws`, `to`
|
|
133
|
+
* and `port` (each once), `ws` an absolute path with no control character (1 KB at most). A `to` off the grammar is
|
|
134
|
+
* dropped to null; a `port` that is not a port is ignored. Anything else is null: nothing opens.
|
|
135
|
+
*/
|
|
136
|
+
export function parseDeepLink(raw: unknown): DeepLink | null {
|
|
137
|
+
if (typeof raw !== 'string' || raw.length > DEEP_LINK_MAX) return null
|
|
138
|
+
let u: URL
|
|
139
|
+
try { u = new URL(raw) } catch { return null }
|
|
140
|
+
if (u.protocol !== `${DEEP_LINK_SCHEME}:` || u.host !== 'open' || (u.pathname !== '' && u.pathname !== '/') || u.username || u.password || u.hash) return null
|
|
141
|
+
const seen = new Set<string>()
|
|
142
|
+
for (const k of u.searchParams.keys()) {
|
|
143
|
+
if (seen.has(k) || !['ws', 'to', 'port'].includes(k)) return null
|
|
144
|
+
seen.add(k)
|
|
145
|
+
}
|
|
146
|
+
const ws = u.searchParams.get('ws')
|
|
147
|
+
if (!ws || !ws.startsWith('/') || ws.length > 1024 || CONTROL.test(ws)) return null
|
|
148
|
+
const to = u.searchParams.has('to') ? targetFromHash(u.searchParams.get('to')) : null
|
|
149
|
+
const ps = u.searchParams.get('port')
|
|
150
|
+
const port = ps !== null && /^\d{1,5}$/.test(ps) && Number(ps) > 0 && Number(ps) < 65536 ? Number(ps) : undefined
|
|
151
|
+
return { ws, to, ...(port !== undefined ? { port } : {}) }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** The first `marver://` argument of a command line (a second instance's argv), or null. */
|
|
155
|
+
export function deepLinkArg(argv: readonly unknown[]): string | null {
|
|
156
|
+
for (const a of argv) if (typeof a === 'string' && a.toLowerCase().startsWith(`${DEEP_LINK_SCHEME}://`)) return a
|
|
157
|
+
return null
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Strictly newer x.y.z (pure): anything not three numbers compares false. */
|
|
161
|
+
export function newerVersion(a: unknown, b: unknown): boolean {
|
|
162
|
+
if (typeof a !== 'string' || typeof b !== 'string') return false
|
|
163
|
+
const pa = /^(\d+)\.(\d+)\.(\d+)$/.exec(a), pb = /^(\d+)\.(\d+)\.(\d+)$/.exec(b)
|
|
164
|
+
if (!pa || !pb) return false
|
|
165
|
+
for (let i = 1; i <= 3; i++) {
|
|
166
|
+
const x = Number(pa[i]), y = Number(pb[i])
|
|
167
|
+
if (x !== y) return x > y
|
|
168
|
+
}
|
|
169
|
+
return false
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ---- app-live.json: knowing when the app is in use (Part D2) ---------------------------------------------------
|
|
173
|
+
|
|
174
|
+
/** `<MARVER_HOME>/state/app-live.json`: the Mac app's word that it runs, rewritten every `APP_LIVE_EVERY_MS`. */
|
|
175
|
+
export const APP_LIVE_FILE = 'app-live.json'
|
|
176
|
+
export const APP_LIVE_EVERY_MS = 30_000
|
|
177
|
+
/** Older than this, the file is stale: the app is not in use (it quit without removing it, it hangs). */
|
|
178
|
+
export const APP_LIVE_FRESH_MS = 90_000
|
|
179
|
+
|
|
180
|
+
export interface AppLiveFile {
|
|
181
|
+
v: 1
|
|
182
|
+
pid: number
|
|
183
|
+
version: string
|
|
184
|
+
/** 1 when this app takes `marver://` links (an app that registered the scheme); absent otherwise */
|
|
185
|
+
scheme?: 1
|
|
186
|
+
/** when it was written, ms */
|
|
187
|
+
at: number
|
|
188
|
+
/** the real folders of the canvases open in its tabs */
|
|
189
|
+
workspaces: string[]
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** The file's shape (pure), or null. */
|
|
193
|
+
export function checkAppLive(v: unknown): AppLiveFile | null {
|
|
194
|
+
const r = v as Partial<AppLiveFile> | null
|
|
195
|
+
if (!r || typeof r !== 'object' || r.v !== 1) return null
|
|
196
|
+
if (!Number.isInteger(r.pid) || (r.pid as number) < 1 || typeof r.version !== 'string' || r.version.length > 32) return null
|
|
197
|
+
if (typeof r.at !== 'number' || !Number.isFinite(r.at)) return null
|
|
198
|
+
if (!Array.isArray(r.workspaces) || r.workspaces.length > 256 || !r.workspaces.every((w) => typeof w === 'string' && w.startsWith('/') && w.length <= 4096)) return null
|
|
199
|
+
return { v: 1, pid: r.pid as number, version: r.version, at: r.at, workspaces: [...r.workspaces], ...(r.scheme === 1 ? { scheme: 1 as const } : {}) }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Whether `marver link` gives the app's link for the canvas in `root` (pure): the file names a pid that runs, was
|
|
204
|
+
* written under 90 s ago (a stamp from the future is stale too), takes the scheme, and has this canvas's folder open.
|
|
205
|
+
* Anything else - no file, an older app, a stale file, the canvas not open in a tab - is the localhost link.
|
|
206
|
+
*/
|
|
207
|
+
export function appTakesLink(file: AppLiveFile | null, root: string, now: number, alive: (pid: number) => boolean): boolean {
|
|
208
|
+
if (!file || file.scheme !== 1) return false
|
|
209
|
+
if (file.at > now + 5_000 || now - file.at > APP_LIVE_FRESH_MS) return false
|
|
210
|
+
if (!file.workspaces.includes(root)) return false
|
|
211
|
+
return alive(file.pid)
|
|
212
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Your own breakpoints (spec 31 Part F): what a device shows as - its glyph and its label. Pure, shared by the
|
|
3
|
+
* server (which resolves design/config.ts's `viewports.<name>.icon` and `.label` once, at load) and the shell (which
|
|
4
|
+
* falls back to the same rules for a device name it has no resolved look for, e.g. a Jam step recorded earlier).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** The built-in device glyphs, as `viewports.<name>.icon` may name them (a `-landscape` suffix rotates one). */
|
|
8
|
+
export const DEVICE_GLYPHS = ['mobile', 'tablet', 'laptop', 'monitor', 'tv', 'watch', 'desktop', 'ereader'] as const
|
|
9
|
+
export type DeviceGlyph = typeof DEVICE_GLYPHS[number]
|
|
10
|
+
|
|
11
|
+
/** How a device shows: its label, and a built-in glyph (null: the generic devices glyph) turned a quarter for a
|
|
12
|
+
* landscape device - or `mask`, a sanitized SVG as a `data:image/svg+xml;base64,` URI drawn as a CSS mask in the
|
|
13
|
+
* ink (never inline DOM). */
|
|
14
|
+
export interface DeviceLook { label: string; glyph: DeviceGlyph | null; rotate: boolean; mask?: string }
|
|
15
|
+
|
|
16
|
+
/** The longest label a device carries. */
|
|
17
|
+
export const DEVICE_LABEL_MAX = 40
|
|
18
|
+
|
|
19
|
+
const words = (name: string): string[] => name.split(/[^A-Za-z0-9]+/).filter(Boolean)
|
|
20
|
+
const tokens = (name: string): string[] => words(name).map((w) => w.toLowerCase())
|
|
21
|
+
|
|
22
|
+
/** A `-landscape` device: the name says so (a word of its own). */
|
|
23
|
+
export const isLandscape = (name: string): boolean => tokens(name).includes('landscape')
|
|
24
|
+
|
|
25
|
+
/** The glyph a device's NAME suggests, or null (the generic devices glyph). Class words first (`pixel-tablet` is a
|
|
26
|
+
* tablet), then the brands. */
|
|
27
|
+
export function glyphFromName(name: string): DeviceGlyph | null {
|
|
28
|
+
const t = tokens(name)
|
|
29
|
+
const has = (...w: string[]) => t.some((x) => w.includes(x))
|
|
30
|
+
const starts = (p: string) => t.some((x) => x.startsWith(p))
|
|
31
|
+
// the class words: what a device IS beats whose it is
|
|
32
|
+
if (has('tablet')) return 'tablet'
|
|
33
|
+
if (has('laptop')) return 'laptop'
|
|
34
|
+
if (has('phone', 'mobile', 'smartphone')) return 'mobile'
|
|
35
|
+
if (has('monitor', 'desktop')) return 'monitor'
|
|
36
|
+
if (has('tv')) return 'tv'
|
|
37
|
+
if (has('watch')) return 'watch'
|
|
38
|
+
if (has('ereader')) return 'ereader'
|
|
39
|
+
// the brands and the models
|
|
40
|
+
if (starts('iphone') || has('android', 'pixel')) return 'mobile'
|
|
41
|
+
if (starts('ipad') || has('boox', 'kindle')) return 'tablet'
|
|
42
|
+
if (starts('macbook')) return 'laptop'
|
|
43
|
+
if (has('imac', 'studio')) return 'monitor'
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Brand casing, by word: "ipad" -> "iPad", "tv" -> "TV". */
|
|
48
|
+
const BRAND: Record<string, string> = {
|
|
49
|
+
iphone: 'iPhone', ipad: 'iPad', imac: 'iMac', ipod: 'iPod', macbook: 'MacBook', mac: 'Mac', ios: 'iOS', ipados: 'iPadOS',
|
|
50
|
+
macos: 'macOS', watchos: 'watchOS', tvos: 'tvOS', visionos: 'visionOS', tv: 'TV', appletv: 'Apple TV', android: 'Android', pixel: 'Pixel',
|
|
51
|
+
galaxy: 'Galaxy', samsung: 'Samsung', kindle: 'Kindle', boox: 'Boox', kobo: 'Kobo', remarkable: 'reMarkable', surface: 'Surface',
|
|
52
|
+
chromebook: 'Chromebook', apple: 'Apple', google: 'Google', oneplus: 'OnePlus', xl: 'XL', hd: 'HD', uhd: 'UHD', fhd: 'FHD',
|
|
53
|
+
qhd: 'QHD', '4k': '4K', '5k': '5K', '6k': '6K', '8k': '8K', xdr: 'XDR', oled: 'OLED', se: 'SE', xr: 'XR', xs: 'XS', ui: 'UI',
|
|
54
|
+
}
|
|
55
|
+
/** A model's suffix words, capitalised after a brand: "iphone-15-pro-max" -> "iPhone 15 Pro Max". */
|
|
56
|
+
const MODEL = new Set(['pro', 'max', 'plus', 'mini', 'air', 'ultra', 'fold', 'flip', 'lite', 'studio', 'display', 'note'])
|
|
57
|
+
/** Brands that start a model name, so the words after them are its model words. */
|
|
58
|
+
const BRANDED = new Set(['iphone', 'ipad', 'imac', 'ipod', 'macbook', 'mac', 'pixel', 'galaxy', 'kindle', 'boox', 'kobo', 'remarkable', 'surface', 'chromebook', 'apple', 'google', 'samsung', 'oneplus', 'studio'])
|
|
59
|
+
|
|
60
|
+
/** A device's label from its NAME: the words humanized, brand casing kept ("ipad-landscape" -> "iPad landscape",
|
|
61
|
+
* "boox-full" -> "Boox full", "iphone-15-pro" -> "iPhone 15 Pro"). The first word starts capitalised, the rest stay
|
|
62
|
+
* as written; a word already carrying capitals keeps them ("myDevice" stays "myDevice"). */
|
|
63
|
+
export function labelFromName(name: string): string {
|
|
64
|
+
const ws = words(name)
|
|
65
|
+
if (!ws.length) return name
|
|
66
|
+
let branded = false
|
|
67
|
+
return ws.map((w, i) => {
|
|
68
|
+
const low = w.toLowerCase()
|
|
69
|
+
// a brand word with a model number glued on: "iphone15" -> "iPhone15", "ipad13" -> "iPad13"
|
|
70
|
+
const glued = /^([a-z]+)(\d+)$/.exec(low)
|
|
71
|
+
const brand = BRAND[low] ?? (glued && BRANDED.has(glued[1]) && BRAND[glued[1]] ? BRAND[glued[1]] + glued[2] : undefined)
|
|
72
|
+
const isBrand = BRANDED.has(low) || (!!glued && BRANDED.has(glued[1]))
|
|
73
|
+
const out = brand ?? (/[A-Z]/.test(w) ? w
|
|
74
|
+
: branded && MODEL.has(low) ? low[0].toUpperCase() + low.slice(1)
|
|
75
|
+
: i === 0 ? low[0].toUpperCase() + low.slice(1)
|
|
76
|
+
: low)
|
|
77
|
+
if (isBrand) branded = true
|
|
78
|
+
return out
|
|
79
|
+
}).join(' ')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A built-in glyph as `viewports.<name>.icon` names it, with its rotation - or null when the value is no glyph. */
|
|
83
|
+
export function parseGlyph(v: string): { glyph: DeviceGlyph; rotate: boolean } | null {
|
|
84
|
+
const m = /^([a-z]+)(-landscape)?$/.exec(v)
|
|
85
|
+
return m && (DEVICE_GLYPHS as readonly string[]).includes(m[1]) ? { glyph: m[1] as DeviceGlyph, rotate: !!m[2] } : null
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A device's look from its name alone - the shell's fallback, and the server's for a device with no `icon`/`label`. */
|
|
89
|
+
export const lookFromName = (name: string): DeviceLook => ({ label: labelFromName(name), glyph: glyphFromName(name), rotate: isLandscape(name) })
|
package/src/shared/events.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
// 'reanchor' (Live Jam): re-pin a thread to a new element after the agent moved it.
|
|
8
|
-
|
|
8
|
+
// 'delete' (0.31, spec 31 C.4): a terminal tombstone on one message - its author's only.
|
|
9
|
+
export type EventType = 'create' | 'reply' | 'edit' | 'resolve' | 'reopen' | 'react' | 'profile' | 'reanchor' | 'delete'
|
|
9
10
|
|
|
10
11
|
// Live Jam: provenance stamped by the daemon on agent-authored events (who orchestrated the change).
|
|
11
12
|
export interface AgentMeta { devUser?: string; harness?: string; model?: string; effort?: string; /** who ran it (spec 29b): the owner's session, a copy of it, or a fresh agent */ runner?: 'session' | 'fork' | 'fresh' }
|
|
@@ -49,6 +50,8 @@ export interface CommentEvent {
|
|
|
49
50
|
capture?: string
|
|
50
51
|
facts?: string
|
|
51
52
|
origin?: string // server-stamped 'local' on dev-owner writes; the daemon's owner-trigger key
|
|
53
|
+
/** resolve and reopen events (0.31, spec 31 B.3): the resolve-all operation that wrote it - what its Undo matches */
|
|
54
|
+
op?: string
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
export interface Thread {
|
|
@@ -66,7 +69,11 @@ export interface Thread {
|
|
|
66
69
|
asks?: boolean
|
|
67
70
|
capture?: string // a capture's comment (0.26)
|
|
68
71
|
facts?: string
|
|
69
|
-
|
|
72
|
+
/** the first comment was deleted (0.31): its replies stay under a "Comment deleted" placeholder - no body, author or mentions */
|
|
73
|
+
deleted?: true
|
|
74
|
+
/** when its words were last edited (0.31: "edited" is shown) - an edit that changes only a flag does not count */
|
|
75
|
+
edited?: number
|
|
76
|
+
replies: { id: string; author?: CommentEvent['author']; body?: string; ts: number; agent?: boolean; agentMeta?: AgentMeta; mentions?: Mention[]; asks?: boolean; alsoChanged?: string[]; edited?: number }[]
|
|
70
77
|
reactions: Record<string, string[]> // emoji -> author emails (toggle semantics)
|
|
71
78
|
}
|
|
72
79
|
|
|
@@ -82,10 +89,31 @@ export function diffEvents(mine: CommentEvent[], theirIds: Iterable<string>): Co
|
|
|
82
89
|
return mine.filter((e) => !have.has(e.id))
|
|
83
90
|
}
|
|
84
91
|
|
|
92
|
+
/** The messages (create or reply comment ids) a log's tombstones name (spec 31 C.4): terminal, whatever came
|
|
93
|
+
* before or after them. Every reader that turns a request into agent input filters by it, per message. */
|
|
94
|
+
export function deletedMessages(events: readonly CommentEvent[]): Set<string> {
|
|
95
|
+
const out = new Set<string>()
|
|
96
|
+
for (const e of events) if (e.type === 'delete' && typeof e.commentId === 'string' && e.commentId) out.add(e.commentId)
|
|
97
|
+
return out
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** An event as a browser may see it (spec 31 C.4): a create, reply or edit of a deleted message carries no words or
|
|
101
|
+
* mentions - the log keeps them (sync is by id), no transport to a page does. `gone`: deletedMessages of the log. */
|
|
102
|
+
export const withoutDeletedWords = (e: CommentEvent, gone: ReadonlySet<string>): CommentEvent =>
|
|
103
|
+
gone.size && (e.type === 'create' || e.type === 'reply' || e.type === 'edit') && !!e.commentId && gone.has(e.commentId) ? { ...e, body: '', mentions: undefined } : e
|
|
104
|
+
|
|
105
|
+
/** The copy a published page keeps of what it just sent (spec 31 C.2): its author wears the viewer's own opaque id, as
|
|
106
|
+
* the server's projection of it will - the echo is a duplicate by id and dropped, so without it a message just written
|
|
107
|
+
* would not be "mine" (no Edit, no Delete) until a reload. Never sent: the server assigns ids. */
|
|
108
|
+
export const asSentBy = (events: CommentEvent[], myId: string | undefined): CommentEvent[] =>
|
|
109
|
+
!myId ? events : events.map((e) => (e.author && !e.author.id ? { ...e, author: { ...e.author, id: myId } } : e))
|
|
110
|
+
|
|
85
111
|
/** Replay a board's events into current thread state. Deterministic: replay order is
|
|
86
112
|
* (ts, id) so two stores holding the same event SET always derive the same state.
|
|
87
113
|
* TWO passes - creates first, then everything else - so a reply whose author's clock
|
|
88
|
-
* ran ahead of the creator's still lands instead of being dropped forever.
|
|
114
|
+
* ran ahead of the creator's still lands instead of being dropped forever. Deletes (0.31)
|
|
115
|
+
* apply after both, whatever their time: a deleted reply is gone; a deleted first comment
|
|
116
|
+
* keeps its surviving replies under a placeholder, and with none the thread is gone. */
|
|
89
117
|
export function replay(events: CommentEvent[]): Thread[] {
|
|
90
118
|
const ordered = [...events].sort((a, b) => a.ts - b.ts || (a.id < b.id ? -1 : 1))
|
|
91
119
|
const threads = new Map<string, Thread>()
|
|
@@ -112,7 +140,7 @@ export function replay(events: CommentEvent[]): Thread[] {
|
|
|
112
140
|
if (!ev.commentId || (ev.body === undefined && ev.asks === undefined && ev.alsoChanged === undefined)) break
|
|
113
141
|
const m = threads.get(ev.commentId) ?? [...threads.values()].flatMap((th) => th.replies).find((r) => r.id === ev.commentId)
|
|
114
142
|
if (!m) break
|
|
115
|
-
if (ev.body !== undefined) m.body = ev.body
|
|
143
|
+
if (ev.body !== undefined) { if (ev.body !== m.body) m.edited = ev.ts; m.body = ev.body }
|
|
116
144
|
if (ev.asks !== undefined) m.asks = ev.asks
|
|
117
145
|
if (ev.alsoChanged !== undefined && !('replies' in m)) (m as { alsoChanged?: string[] }).alsoChanged = ev.alsoChanged // a reply's
|
|
118
146
|
break
|
|
@@ -152,7 +180,22 @@ export function replay(events: CommentEvent[]): Thread[] {
|
|
|
152
180
|
break
|
|
153
181
|
}
|
|
154
182
|
// 'profile' events update author snapshots at write time on the client - replay ignores them
|
|
183
|
+
// 'delete' events are applied below, after everything else
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const gone = deletedMessages(ordered)
|
|
187
|
+
if (!gone.size) return [...threads.values()]
|
|
188
|
+
const out: Thread[] = []
|
|
189
|
+
for (const t of threads.values()) {
|
|
190
|
+
t.replies = t.replies.filter((r) => !gone.has(r.id))
|
|
191
|
+
if (gone.has(t.id)) {
|
|
192
|
+
if (!t.replies.length) continue
|
|
193
|
+
// the placeholder carries nothing of what was said, nor who said it
|
|
194
|
+
t.deleted = true
|
|
195
|
+
t.body = undefined; t.author = undefined; t.mentions = undefined; t.asks = undefined; t.edited = undefined
|
|
196
|
+
delete t.capture; delete t.facts
|
|
155
197
|
}
|
|
198
|
+
out.push(t)
|
|
156
199
|
}
|
|
157
|
-
return
|
|
200
|
+
return out
|
|
158
201
|
}
|