@bigmistqke/whiteboard 0.5.0 → 0.6.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 (106) hide show
  1. package/README.md +125 -25
  2. package/bin/whiteboard.ts +299 -16
  3. package/dist/bin/whiteboard.js +247 -17
  4. package/dist/client/runtime.js +22 -10
  5. package/dist/plugins/ansi/README.md +36 -0
  6. package/dist/plugins/ansi/index.js +64 -0
  7. package/dist/plugins/ansi/public/style.css +28 -0
  8. package/dist/plugins/badge/README.md +28 -0
  9. package/dist/plugins/badge/index.js +24 -0
  10. package/dist/plugins/badge/public/style.css +30 -0
  11. package/dist/plugins/chat/public/style.css +7 -2
  12. package/dist/plugins/code/README.md +4 -2
  13. package/dist/plugins/code/diff.js +12 -2
  14. package/dist/plugins/grid/README.md +12 -12
  15. package/dist/plugins/grid/index.js +7 -19
  16. package/dist/plugins/grid/public/style.css +4 -33
  17. package/dist/plugins/iframe/README.md +7 -7
  18. package/dist/plugins/iframe/index.js +11 -11
  19. package/dist/plugins/iframe/public/style.css +15 -0
  20. package/dist/plugins/index.js +7 -3
  21. package/dist/plugins/lightbox/README.md +22 -0
  22. package/dist/plugins/lightbox/index.js +20 -0
  23. package/dist/plugins/lightbox/public/client.js +4 -0
  24. package/dist/plugins/lightbox/public/style.css +66 -0
  25. package/dist/plugins/steps/README.md +3 -3
  26. package/dist/plugins/steps/index.js +3 -42
  27. package/dist/plugins/steps/public/client.js +1 -1
  28. package/dist/plugins/terminal/host.js +1 -1
  29. package/dist/plugins/terminal/public/client.js +1 -1
  30. package/dist/plugins/window/README.md +34 -14
  31. package/dist/plugins/window/index.js +21 -13
  32. package/dist/src/auth.js +4 -3
  33. package/dist/src/client/page/base.css +61 -1
  34. package/dist/src/client/page/main.js +60 -14
  35. package/dist/src/entries.js +211 -0
  36. package/dist/src/events.js +1 -1
  37. package/dist/src/hub.js +272 -0
  38. package/dist/src/loader.js +4 -1
  39. package/dist/src/package.js +23 -1
  40. package/dist/src/pages/blocks.js +1 -0
  41. package/dist/src/pages/index.js +1 -1
  42. package/dist/src/pages/markdown.js +87 -33
  43. package/dist/src/pages/render.js +116 -14
  44. package/dist/src/pages/window.js +16 -18
  45. package/dist/src/running.js +37 -2
  46. package/dist/src/serve.js +111 -2
  47. package/dist/src/server.js +49 -14
  48. package/package.json +1 -1
  49. package/plugins/ansi/README.md +36 -0
  50. package/plugins/ansi/index.ts +95 -0
  51. package/plugins/ansi/public/style.css +28 -0
  52. package/plugins/badge/README.md +28 -0
  53. package/plugins/badge/index.ts +35 -0
  54. package/plugins/badge/public/style.css +30 -0
  55. package/plugins/chat/public/style.css +7 -2
  56. package/plugins/code/README.md +4 -2
  57. package/plugins/code/diff.ts +14 -2
  58. package/plugins/grid/README.md +12 -12
  59. package/plugins/grid/index.ts +11 -26
  60. package/plugins/grid/public/style.css +4 -33
  61. package/plugins/iframe/README.md +7 -7
  62. package/plugins/iframe/index.ts +15 -15
  63. package/plugins/iframe/public/style.css +15 -0
  64. package/plugins/index.ts +6 -2
  65. package/plugins/lightbox/README.md +22 -0
  66. package/plugins/lightbox/client.ts +99 -0
  67. package/plugins/lightbox/index.ts +25 -0
  68. package/plugins/lightbox/public/style.css +66 -0
  69. package/plugins/steps/README.md +3 -3
  70. package/plugins/steps/client.ts +15 -6
  71. package/plugins/steps/index.ts +3 -46
  72. package/plugins/terminal/client.ts +16 -7
  73. package/plugins/window/README.md +34 -14
  74. package/plugins/window/index.ts +20 -13
  75. package/skills/whiteboard/SKILL.md +18 -10
  76. package/src/auth.ts +5 -3
  77. package/src/client/base.ts +19 -0
  78. package/src/client/forms.ts +2 -1
  79. package/src/client/markdown.ts +2 -1
  80. package/src/client/page/base.css +61 -1
  81. package/src/client/page/elsewhere.ts +72 -16
  82. package/src/client/page/fresh.ts +2 -1
  83. package/src/client/page/sort.ts +2 -1
  84. package/src/client/runtime.ts +11 -9
  85. package/src/define.ts +66 -7
  86. package/src/entries.ts +258 -0
  87. package/src/events.ts +2 -1
  88. package/src/hub.ts +355 -0
  89. package/src/loader.ts +7 -1
  90. package/src/package.ts +22 -0
  91. package/src/pages/blocks.ts +3 -0
  92. package/src/pages/index.ts +4 -2
  93. package/src/pages/markdown.ts +89 -32
  94. package/src/pages/render.ts +134 -13
  95. package/src/pages/window.ts +16 -25
  96. package/src/running.ts +47 -1
  97. package/src/serve.ts +114 -1
  98. package/src/server.ts +80 -14
  99. package/dist/plugins/gallery/README.md +0 -30
  100. package/dist/plugins/gallery/index.js +0 -75
  101. package/dist/plugins/gallery/public/client.js +0 -1
  102. package/dist/plugins/gallery/public/style.css +0 -90
  103. package/plugins/gallery/README.md +0 -30
  104. package/plugins/gallery/client.tsx +0 -70
  105. package/plugins/gallery/index.ts +0 -89
  106. package/plugins/gallery/public/style.css +0 -90
@@ -2,6 +2,7 @@
2
2
  // page (code fences highlighted, `#12` linked), without raw HTML or directives (api.markdown). The
3
3
  // texts asked for at once go in one request; each text is rendered once, then cached. A
4
4
  // stylesheet a message needs (the code block's) is linked once it is first used.
5
+ import { url } from './base.ts'
5
6
 
6
7
  const cache = new Map<string, Promise<string>>()
7
8
  let queue: { text: string; resolve: (html: string) => void; reject: (err: unknown) => void }[] = []
@@ -10,7 +11,7 @@ async function flush() {
10
11
  const batch = queue
11
12
  queue = []
12
13
  try {
13
- const res = await fetch('/api/markdown', {
14
+ const res = await fetch(url('/api/markdown'), {
14
15
  method: 'POST',
15
16
  headers: { 'content-type': 'application/json' },
16
17
  body: JSON.stringify({ texts: batch.map(b => b.text) }),
@@ -565,6 +565,23 @@ details[open] > :last-child {
565
565
  text-overflow: ellipsis;
566
566
  white-space: nowrap;
567
567
  }
568
+ /* under a shared server, the other projects' pages, under each project's name */
569
+ .wb-elsewhere-group {
570
+ padding: var(--space-sm) var(--space-lg) var(--space-xs);
571
+ overflow: hidden;
572
+ text-overflow: ellipsis;
573
+ white-space: nowrap;
574
+ color: var(--muted);
575
+ font: var(--weight-strong) var(--ui-small)/var(--ui-line-height) var(--sans);
576
+ }
577
+ .wb-elsewhere-group:not(:first-child) {
578
+ margin-top: var(--space-xs);
579
+ border-top: var(--hairline) solid var(--border);
580
+ }
581
+ .wb-elsewhere-list {
582
+ max-height: min(70vh, 480px);
583
+ overflow-y: auto;
584
+ }
568
585
  .wb-nav .wb-elsewhere-list a:hover,
569
586
  .wb-nav .wb-elsewhere-list a:focus-visible {
570
587
  background: color-mix(in srgb, var(--accent) var(--tint-soft), transparent);
@@ -908,6 +925,49 @@ form[data-wb-just-sent] .wb-folded-change {
908
925
  font-size: 1.1rem;
909
926
  margin: 0;
910
927
  }
928
+ /* the shared server's overview (/): each project's pages under its name, as quiet as the
929
+ documents' heading above, and the projects without pages folded at the end */
930
+ .wb-project {
931
+ margin-top: calc(var(--rhythm) * 2.5);
932
+ }
933
+ .wb-project h2 {
934
+ font-size: 1.25rem;
935
+ margin: 0;
936
+ }
937
+ .wb-project > .wb-meta {
938
+ margin: var(--space-xs) 0 0;
939
+ }
940
+ .wb-folded-documents {
941
+ margin-top: var(--rhythm);
942
+ }
943
+ .wb-folded-documents > summary {
944
+ cursor: pointer;
945
+ font: var(--weight-strong) var(--ui-small)/var(--ui-line-height) var(--sans);
946
+ color: var(--muted);
947
+ }
948
+ .wb-folded-documents .wb-folder {
949
+ margin: var(--space-xs) 0 0 var(--space-xl);
950
+ }
951
+ .wb-folded-documents .wb-folder > summary {
952
+ cursor: pointer;
953
+ font: var(--ui-small)/var(--ui-line-height) var(--mono);
954
+ color: var(--muted);
955
+ }
956
+ .wb-folded-documents .wb-index li {
957
+ padding: var(--space-md) 0;
958
+ }
959
+ .wb-empty-projects {
960
+ margin-top: calc(var(--rhythm) * 2.5);
961
+ color: var(--muted);
962
+ font: var(--ui-small)/var(--ui-line-height) var(--sans);
963
+ }
964
+ .wb-empty-projects summary {
965
+ cursor: pointer;
966
+ }
967
+ .wb-empty-projects ul {
968
+ margin: var(--space-sm) 0 0;
969
+ padding-left: var(--space-xl);
970
+ }
911
971
  /* a list's heading with its sort control at the right (sort.ts) */
912
972
  .wb-list-head {
913
973
  display: flex;
@@ -1073,7 +1133,7 @@ main:has(+ .wb-orphans:not([hidden])) {
1073
1133
  .wb-window-body > :last-child {
1074
1134
  margin-bottom: 0;
1075
1135
  }
1076
- .wb-window-body:not(.wb-iframe-frame) {
1136
+ .wb-window-body {
1077
1137
  padding: var(--space-xl) var(--space-xl);
1078
1138
  overflow: auto;
1079
1139
  }
@@ -5,6 +5,7 @@
5
5
  import type { Api, PageHandle, PageStatus } from '../../define.ts'
6
6
  import { INBOX_ICON, awaitingLabel } from '../../icons.ts'
7
7
  import { awaiting } from '../../status.ts'
8
+ import { base, url } from '../base.ts'
8
9
 
9
10
  /** A link to a page that scrolls it to its first waiting question. */
10
11
  export const WAITING_HASH = '#wb-waiting'
@@ -27,32 +28,85 @@ function open(yes: boolean) {
27
28
 
28
29
  let current = ''
29
30
 
31
+ /** A page with something waiting, in a group of the menu (its project, under a shared server). */
32
+ interface Waiting {
33
+ href: string
34
+ title: string
35
+ n: number
36
+ }
37
+
38
+ /** This project's pages with something waiting, but this one. */
39
+ async function here(): Promise<Waiting[]> {
40
+ const pages = (await (await fetch(url('/api/status'), { cache: 'no-store' })).json()) as PageStatus[]
41
+ return pages
42
+ .filter(p => p.page !== current)
43
+ .map(p => ({
44
+ href: `${base}/${p.page.split('/').map(encodeURIComponent).join('/')}${WAITING_HASH}`,
45
+ title: p.title,
46
+ n: awaiting(p),
47
+ }))
48
+ .filter(w => w.n > 0)
49
+ }
50
+
51
+ /**
52
+ * Under a shared server (see Entries in DESIGN.md): the other projects of this one's entry, by
53
+ * project, as the server's index has them; empty on a server of its own, or when it can't say.
54
+ */
55
+ async function others(): Promise<{ label: string; pages: Waiting[] }[]> {
56
+ if (!base) return []
57
+ const entry = base.split('/')[1]
58
+ try {
59
+ const res = await fetch(`/api/index?entry=${encodeURIComponent(entry ?? '')}`, { cache: 'no-store' })
60
+ if (!res.ok) return []
61
+ const projects = (await res.json()) as {
62
+ label: string
63
+ base: string
64
+ pages: { title: string; url: string; open: string[]; unread: number }[]
65
+ }[]
66
+ return projects
67
+ .filter(p => p.base !== base)
68
+ .map(p => ({
69
+ label: p.label,
70
+ pages: p.pages
71
+ .map(x => ({ href: `${x.url}${WAITING_HASH}`, title: x.title, n: x.open.length + x.unread }))
72
+ .filter(w => w.n > 0),
73
+ }))
74
+ .filter(g => g.pages.length)
75
+ } catch {
76
+ return []
77
+ }
78
+ }
79
+
30
80
  async function load() {
31
- let pages: PageStatus[]
81
+ let mine: Waiting[]
82
+ let rest: { label: string; pages: Waiting[] }[]
32
83
  try {
33
- pages = await (await fetch('/api/status', { cache: 'no-store' })).json()
84
+ ;[mine, rest] = await Promise.all([here(), others()])
34
85
  } catch {
35
86
  return
36
87
  }
37
- const waiting = pages
38
- .filter(p => p.page !== current)
39
- .map(p => ({ p, n: awaiting(p) }))
40
- .filter(({ n }) => n > 0)
41
- const total = waiting.reduce((sum, { n }) => sum + n, 0)
88
+ const all = [...mine, ...rest.flatMap(g => g.pages)]
89
+ const total = all.reduce((sum, w) => sum + w.n, 0)
42
90
  box.hidden = total === 0
43
91
  if (!total) open(false)
44
92
  count.textContent = String(total)
45
- toggle.title = awaitingLabel(total, ` on ${waiting.length === 1 ? 'another page' : `${waiting.length} other pages`}`)
93
+ toggle.title = awaitingLabel(total, ` on ${all.length === 1 ? 'another page' : `${all.length} other pages`}`)
46
94
  toggle.setAttribute('aria-label', toggle.title)
95
+ const item = (w: Waiting) => {
96
+ const li = document.createElement('li')
97
+ const a = document.createElement('a')
98
+ a.href = w.href
99
+ a.textContent = `${w.title} (${w.n})`
100
+ li.append(a)
101
+ return li
102
+ }
103
+ const heading = (text: string) =>
104
+ Object.assign(document.createElement('li'), { className: 'wb-elsewhere-group', textContent: text, title: text })
105
+ // this project's own first; the others by project, named only when there are others
47
106
  list.replaceChildren(
48
- ...waiting.map(({ p, n }) => {
49
- const li = document.createElement('li')
50
- const a = document.createElement('a')
51
- a.href = `/${p.page.split('/').map(encodeURIComponent).join('/')}${WAITING_HASH}`
52
- a.textContent = `${p.title} (${n})`
53
- li.append(a)
54
- return li
55
- }),
107
+ ...(rest.length && mine.length ? [heading('here')] : []),
108
+ ...mine.map(item),
109
+ ...rest.flatMap(g => [heading(g.label), ...g.pages.map(item)]),
56
110
  )
57
111
  }
58
112
 
@@ -84,4 +138,6 @@ export function trackElsewhere(root: HTMLElement, handle: PageHandle, core: Api)
84
138
  core.listeners.on(reload)
85
139
  handle.onChange(reload)
86
140
  load()
141
+ // other projects' pages change without this page hearing of it: look again now and then
142
+ if (base) setInterval(reload, 5000)
87
143
  }
@@ -6,6 +6,7 @@
6
6
  import { html } from '../../html.ts'
7
7
  import type { Api, Toast } from '../../define.ts'
8
8
  import { viewBottom } from './view'
9
+ import { storageKey } from '../base.ts'
9
10
 
10
11
  const DWELL_MS = 600
11
12
  const FADE_MS = 2500
@@ -236,7 +237,7 @@ export function trackInitial(main: HTMLElement, page: string, api: Api) {
236
237
  upToast.hide()
237
238
  downToast.hide()
238
239
  mainEl = main
239
- storeKey = `wb-seen:${page}`
240
+ storeKey = storageKey(`wb-seen:${page}`)
240
241
  const blocks = [...main.children]
241
242
  const sigs = blocks.map(signature)
242
243
  blocks.forEach((el, i) => sigOf.set(el, sigs[i]))
@@ -2,7 +2,8 @@
2
2
  // by what each `li` carries (`data-order`, `data-updated`, `data-title`: the overview's documents).
3
3
  // The choice is kept per list in this browser, and put back after a live update, which writes the
4
4
  // list again in the server's order.
5
- const KEY = (name: string) => `wb-sort:${name}`
5
+ import { storageKey } from '../base.ts'
6
+ const KEY = (name: string) => storageKey(`wb-sort:${name}`)
6
7
 
7
8
  function sortList(select: HTMLSelectElement) {
8
9
  const list = select.closest('section')?.querySelector('ul')
@@ -10,6 +10,7 @@ import { READ } from '../status.ts'
10
10
  import { markdown } from './markdown'
11
11
  import { scrollToTarget } from './scroll'
12
12
  import { reactive } from './reactive'
13
+ import { url } from './base.ts'
13
14
 
14
15
  interface Handoff {
15
16
  id: string
@@ -53,7 +54,7 @@ function setEvents(next: WbEvent[]) {
53
54
 
54
55
  async function loadEvents() {
55
56
  if (!live) return
56
- const res = await fetch(`/api/events?page=${encodeURIComponent(page)}`)
57
+ const res = await fetch(url(`/api/events?page=${encodeURIComponent(page)}`))
57
58
  const all: WbEvent[] = await res.json()
58
59
  setEvents(all.filter(e => e.page === page))
59
60
  }
@@ -64,7 +65,7 @@ async function append(
64
65
  action: string | null = null,
65
66
  ): Promise<WbEvent> {
66
67
  if (!live) throw new Error('a built page is a file: there is no log to append to')
67
- const res = await fetch('/api/events', {
68
+ const res = await fetch(url('/api/events'), {
68
69
  method: 'POST',
69
70
  headers: { 'content-type': 'application/json' },
70
71
  body: JSON.stringify({ page, type, action, data }),
@@ -80,7 +81,7 @@ const listenersValue = reactive(() => listeners)
80
81
 
81
82
  async function loadListeners() {
82
83
  if (!live) return
83
- listeners = await (await fetch(`/api/listeners?page=${encodeURIComponent(page)}`)).json()
84
+ listeners = await (await fetch(url(`/api/listeners?page=${encodeURIComponent(page)}`))).json()
84
85
  listenersValue.notify()
85
86
  }
86
87
 
@@ -102,6 +103,7 @@ function writeTitle() {
102
103
 
103
104
  const api: Api = {
104
105
  page,
106
+ url,
105
107
  events: eventsValue,
106
108
  last: type => events.findLast(e => e.type === type),
107
109
  pickedUp: id => !!events.find(e => e.id === id)?.pickedUp,
@@ -172,12 +174,12 @@ const handle: PageHandle = {
172
174
  return () => changeListeners.delete(fn)
173
175
  },
174
176
  render: async () => {
175
- const next = await getJson<RenderedPage>(`/api/render?page=${encodeURIComponent(page)}`)
177
+ const next = await getJson<RenderedPage>(url(`/api/render?page=${encodeURIComponent(page)}`))
176
178
  nextData = next.data ?? null
177
179
  nextFrontmatter = next.frontmatter ?? {}
178
180
  return next
179
181
  },
180
- stored: () => getJson<StoredPage>(`/api/page?page=${encodeURIComponent(page)}`),
182
+ stored: () => getJson<StoredPage>(url(`/api/page?page=${encodeURIComponent(page)}`)),
181
183
  }
182
184
 
183
185
  /** Did the page change since it was rendered here (its file's time, or it came to be)? Then say so. */
@@ -185,8 +187,8 @@ async function caughtUp() {
185
187
  let now: number | null
186
188
  try {
187
189
  now =
188
- (await getJson<RenderedPage & { mtime: number | null }>(`/api/render?page=${encodeURIComponent(page)}`)).mtime ??
189
- null
190
+ (await getJson<RenderedPage & { mtime: number | null }>(url(`/api/render?page=${encodeURIComponent(page)}`)))
191
+ .mtime ?? null
190
192
  } catch {
191
193
  now = null
192
194
  }
@@ -204,7 +206,7 @@ if (!handoff.client)
204
206
  // ---- live channel ------------------------------------------------------------------------------
205
207
 
206
208
  function connect() {
207
- const es = new EventSource(`/api/watch?page=${encodeURIComponent(page)}${isDir ? '&dir' : ''}`)
209
+ const es = new EventSource(url(`/api/watch?page=${encodeURIComponent(page)}${isDir ? '&dir' : ''}`))
208
210
  es.onopen = () => {
209
211
  document.documentElement.dataset.wbLive = ''
210
212
  // after a server restart: who is listening now, and what was answered meanwhile
@@ -229,7 +231,7 @@ function connect() {
229
231
  es.addEventListener('reload', () => {
230
232
  const go = async () => {
231
233
  try {
232
- if ((await fetch('/api/health', { cache: 'no-store' })).ok) return location.reload()
234
+ if ((await fetch(url('/api/health'), { cache: 'no-store' })).ok) return location.reload()
233
235
  } catch {
234
236
  /* not up yet */
235
237
  }
package/src/define.ts CHANGED
@@ -100,6 +100,15 @@ export interface Plugin {
100
100
  * Others stay in the log, for `whiteboard events` or a `wait --type` that asks for them by name.
101
101
  */
102
102
  events?: Record<string, EventSpec>
103
+ /**
104
+ * Composes itself around other blocks: a block whose `compose` attribute names this plugin
105
+ * (`::image{src compose=window}`, ```` ```mermaid {compose=window} ````) is put in what this
106
+ * returns, the block's own HTML as `children`, as a component gets what it wraps. The block needs
107
+ * to know nothing of it. Several named (`compose=lightbox,window`) compose in the order written, the
108
+ * first innermost. Not inline blocks, nor a block of this plugin's name (`:::window` is one already).
109
+ * What it reads of the block's attributes (the window's `title`) its docs say.
110
+ */
111
+ compose?(ctx: ComposeContext): string | Html | Promise<string | Html>
103
112
  setup?(ctx: PluginContext): PluginHooks | Promise<PluginHooks>
104
113
  /** by subcommand: `''` is `whiteboard <name>` itself, `stop` is `whiteboard <name> stop` */
105
114
  commands?: Record<string, Command>
@@ -378,6 +387,14 @@ export interface PagesSource extends StoredBase {
378
387
  kind: 'pages'
379
388
  /** `awaiting`: how many things on the page wait for the reader: open questions, unread messages */
380
389
  pages: { id: string; file: string; mtime: number; lastEvent: string | null; awaiting: number }[]
390
+ /**
391
+ * The shared server's overview at `/` (see Entries in DESIGN.md): every project's pages, by
392
+ * project, those waiting for the reader first; `note` is said under them (the server's version).
393
+ */
394
+ groups?: { title: string; base: string; dir: string; files: boolean; pages: PagesSource['pages'] }[]
395
+ /** projects without pages, folded under the groups: their name and where they are served */
396
+ empty?: { title: string; base: string }[]
397
+ note?: string
381
398
  }
382
399
 
383
400
  /** What the core offers the pages on the server: how files are served and linked. */
@@ -398,6 +415,13 @@ export interface RenderContext {
398
415
  live?: boolean
399
416
  /** in a build, the plugins and blocks left out: their blocks render as nothing */
400
417
  skip?: ReadonlySet<string>
418
+ /**
419
+ * The path the project is served under: '' for a server of its own, `/rg/develop` under a shared
420
+ * server (see Entries). Every URL the server makes starts with it; `asset` and `urlFor` add it.
421
+ */
422
+ base?: string
423
+ /** under a shared server: the entry the project is in, and how the project is known in it (`worktrees › cmux`) */
424
+ entry?: { name: string; label?: string }
401
425
  }
402
426
 
403
427
  /**
@@ -511,6 +535,12 @@ export interface Reactive<T> {
511
535
  export interface Api {
512
536
  /** this page's id */
513
537
  page: string
538
+ /**
539
+ * A path of the project's server as this page requests it: `url('/api/<plugin>/x')`. Under a shared
540
+ * server the project is served below a path (`/rg/develop`), so a plugin's client asks through this
541
+ * rather than writing `/api/…` itself.
542
+ */
543
+ url(path: string): string
514
544
  /** every event recorded for this page, oldest first */
515
545
  events: Reactive<WbEvent[]>
516
546
  /** the latest event of a type, e.g. the last submit of a form */
@@ -614,6 +644,11 @@ export interface Block<Props = unknown> {
614
644
  * output; with it, what shows until it mounts.
615
645
  */
616
646
  html?(ctx: ServerContext): string | Html | null | Promise<string | Html | null>
647
+ /**
648
+ * What the block shows, on its own: an image's file, a page's address: what a plugin composed
649
+ * around it gets as `open` (Plugin.compose), the window's ↗. Without it, the window has no ↗.
650
+ */
651
+ open?(ctx: ServerContext): string | null
617
652
  /** a browser module whose default export is a `Mount`, in its plugin's public folder: `'chart.js'` */
618
653
  client?: URL | string
619
654
  /** a stylesheet linked on every page that uses the block, in its plugin's public folder: `'chart.css'` */
@@ -635,12 +670,22 @@ export type Mount<Props = unknown> = (
635
670
 
636
671
  // ---- server context ----------------------------------------------------------------------------
637
672
 
638
- export interface Section {
639
- /** heading content as HTML (no <h*> wrapper), null when the block has no headings */
673
+ /**
674
+ * One of a block's items (DirectiveContext.items): what a grid makes a card of, steps a step. A
675
+ * heading at the block's shallowest heading level starts one, titled by it; so does a `---`, without
676
+ * a title; content with neither is one item.
677
+ */
678
+ export interface Item {
679
+ /** the heading's content as HTML (no <h*> around it); null for an item a `---` started */
640
680
  title: string | null
641
- /** heading as plain text */
681
+ /** the heading as plain text */
642
682
  text: string | null
683
+ /** the item's content as HTML */
643
684
  html: string
685
+ /** the same as mdast nodes, for a block that takes it apart (its first picture, say) */
686
+ nodes: unknown[]
687
+ /** stays the same while its heading does (its slug), else its place: to remember an item across updates */
688
+ key: string
644
689
  }
645
690
 
646
691
  interface BaseContext {
@@ -671,8 +716,8 @@ export interface DirectiveContext extends BaseContext {
671
716
  labelText: string | null
672
717
  /** the block's content as mdast nodes */
673
718
  children: unknown[]
674
- /** split the content at its shallowest headings, or at blank lines when it has none */
675
- sections(): Promise<{ intro: string; sections: Section[] }>
719
+ /** the content as items: a heading at its shallowest heading level, or a `---`, starts one (Item) */
720
+ items(): Promise<Item[]>
676
721
  }
677
722
 
678
723
  /** ```name attrs */
@@ -685,14 +730,28 @@ export interface FenceContext extends BaseContext {
685
730
 
686
731
  export type ServerContext = DirectiveContext | FenceContext
687
732
 
733
+ /** What a plugin's `compose` gets: the block it goes around, and that block's HTML as `children`. */
734
+ export interface ComposeContext {
735
+ /** the block's HTML: what is composed in */
736
+ children: Html
737
+ /** the block's name: `image`, `mermaid` */
738
+ block: string
739
+ /** the block's attributes */
740
+ attrs: Record<string, string>
741
+ /** the block's label as HTML, null without one (fences have none) */
742
+ label: string | null
743
+ /** what the block shows on its own (Block.open): an image's file, a page's address; null without */
744
+ open: string | null
745
+ }
746
+
688
747
  /** Default props of a directive without props(). */
689
748
  export interface DirectiveProps {
690
749
  name: string
691
750
  attrs: Record<string, string>
692
751
  label: string | null
693
752
  html: string
694
- intro: string
695
- sections: Section[]
753
+ /** its items (Item), without their mdast nodes */
754
+ items: Omit<Item, 'nodes'>[]
696
755
  }
697
756
 
698
757
  /** Default props of a fence without props(). */