@bigmistqke/whiteboard 0.4.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 (128) hide show
  1. package/README.md +177 -26
  2. package/bin/whiteboard.ts +331 -16
  3. package/dist/bin/whiteboard.js +268 -17
  4. package/dist/client/runtime.js +66 -23
  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/draft/README.md +14 -0
  15. package/dist/plugins/draft/index.js +21 -0
  16. package/dist/plugins/draft/public/style.css +21 -0
  17. package/dist/plugins/grid/README.md +12 -12
  18. package/dist/plugins/grid/index.js +7 -19
  19. package/dist/plugins/grid/public/style.css +4 -33
  20. package/dist/plugins/iframe/README.md +7 -7
  21. package/dist/plugins/iframe/index.js +11 -11
  22. package/dist/plugins/iframe/public/style.css +15 -0
  23. package/dist/plugins/index.js +11 -3
  24. package/dist/plugins/lightbox/README.md +22 -0
  25. package/dist/plugins/lightbox/index.js +20 -0
  26. package/dist/plugins/lightbox/public/client.js +4 -0
  27. package/dist/plugins/lightbox/public/style.css +66 -0
  28. package/dist/plugins/steps/README.md +42 -0
  29. package/dist/plugins/steps/index.js +60 -0
  30. package/dist/plugins/steps/public/client.js +1 -0
  31. package/dist/plugins/steps/public/style.css +77 -0
  32. package/dist/plugins/terminal/host.js +9 -3
  33. package/dist/plugins/terminal/public/client.js +1 -1
  34. package/dist/plugins/terminal/sizes.js +2 -1
  35. package/dist/plugins/toc/README.md +21 -3
  36. package/dist/plugins/toc/index.js +8 -2
  37. package/dist/plugins/toc/public/client.js +1 -1
  38. package/dist/plugins/toc/public/style.css +10 -4
  39. package/dist/plugins/window/README.md +34 -14
  40. package/dist/plugins/window/index.js +21 -13
  41. package/dist/src/auth.js +6 -4
  42. package/dist/src/client/page/base.css +61 -1
  43. package/dist/src/client/page/main.js +74 -20
  44. package/dist/src/entries.js +211 -0
  45. package/dist/src/events.js +1 -1
  46. package/dist/src/hub.js +272 -0
  47. package/dist/src/loader.js +12 -3
  48. package/dist/src/package.js +23 -1
  49. package/dist/src/pages/blocks.js +1 -0
  50. package/dist/src/pages/index.js +1 -1
  51. package/dist/src/pages/markdown.js +87 -33
  52. package/dist/src/pages/render.js +157 -28
  53. package/dist/src/pages/window.js +17 -18
  54. package/dist/src/running.js +37 -2
  55. package/dist/src/serve.js +111 -2
  56. package/dist/src/server.js +264 -23
  57. package/package.json +3 -2
  58. package/plugins/ansi/README.md +36 -0
  59. package/plugins/ansi/index.ts +95 -0
  60. package/plugins/ansi/public/style.css +28 -0
  61. package/plugins/badge/README.md +28 -0
  62. package/plugins/badge/index.ts +35 -0
  63. package/plugins/badge/public/style.css +30 -0
  64. package/plugins/chat/public/style.css +7 -2
  65. package/plugins/code/README.md +4 -2
  66. package/plugins/code/diff.ts +14 -2
  67. package/plugins/code/index.ts +3 -1
  68. package/plugins/draft/README.md +14 -0
  69. package/plugins/draft/index.ts +23 -0
  70. package/plugins/draft/public/style.css +21 -0
  71. package/plugins/grid/README.md +12 -12
  72. package/plugins/grid/index.ts +11 -26
  73. package/plugins/grid/public/style.css +4 -33
  74. package/plugins/iframe/README.md +7 -7
  75. package/plugins/iframe/index.ts +15 -15
  76. package/plugins/iframe/public/style.css +15 -0
  77. package/plugins/index.ts +10 -2
  78. package/plugins/lightbox/README.md +22 -0
  79. package/plugins/lightbox/client.ts +99 -0
  80. package/plugins/lightbox/index.ts +25 -0
  81. package/plugins/lightbox/public/style.css +66 -0
  82. package/plugins/mermaid/index.ts +4 -2
  83. package/plugins/steps/README.md +42 -0
  84. package/plugins/steps/client.ts +75 -0
  85. package/plugins/steps/index.ts +84 -0
  86. package/plugins/steps/public/style.css +77 -0
  87. package/plugins/terminal/client.ts +16 -7
  88. package/plugins/terminal/host.ts +12 -6
  89. package/plugins/terminal/sizes.ts +3 -1
  90. package/plugins/toc/README.md +21 -3
  91. package/plugins/toc/client.ts +47 -6
  92. package/plugins/toc/index.ts +19 -6
  93. package/plugins/toc/public/style.css +10 -4
  94. package/plugins/window/README.md +34 -14
  95. package/plugins/window/index.ts +20 -13
  96. package/skills/whiteboard/SKILL.md +18 -10
  97. package/src/auth.ts +8 -5
  98. package/src/client/base.ts +19 -0
  99. package/src/client/forms.ts +2 -1
  100. package/src/client/markdown.ts +2 -1
  101. package/src/client/page/base.css +61 -1
  102. package/src/client/page/elsewhere.ts +72 -16
  103. package/src/client/page/fresh.ts +2 -1
  104. package/src/client/page/main.ts +18 -6
  105. package/src/client/page/sort.ts +2 -1
  106. package/src/client/runtime.ts +62 -25
  107. package/src/define.ts +126 -19
  108. package/src/entries.ts +258 -0
  109. package/src/events.ts +2 -1
  110. package/src/hub.ts +355 -0
  111. package/src/loader.ts +14 -3
  112. package/src/package.ts +22 -0
  113. package/src/pages/blocks.ts +3 -0
  114. package/src/pages/index.ts +6 -4
  115. package/src/pages/markdown.ts +89 -32
  116. package/src/pages/render.ts +181 -28
  117. package/src/pages/window.ts +23 -25
  118. package/src/running.ts +47 -1
  119. package/src/serve.ts +114 -1
  120. package/src/server.ts +332 -26
  121. package/dist/plugins/gallery/README.md +0 -30
  122. package/dist/plugins/gallery/index.js +0 -75
  123. package/dist/plugins/gallery/public/client.js +0 -1
  124. package/dist/plugins/gallery/public/style.css +0 -90
  125. package/plugins/gallery/README.md +0 -30
  126. package/plugins/gallery/client.tsx +0 -70
  127. package/plugins/gallery/index.ts +0 -89
  128. package/plugins/gallery/public/style.css +0 -90
@@ -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
@@ -22,13 +23,20 @@ interface Handoff {
22
23
  /** the event types that, from the agent, are messages for the reader */
23
24
  messages: string[]
24
25
  /** the page's frontmatter (PageHandle.frontmatter) */
25
- frontmatter: Record<string, string>
26
+ frontmatter: Record<string, unknown>
27
+ /** false on a built page (`whiteboard build`): a file, no server behind it */
28
+ live?: boolean
26
29
  }
27
30
 
28
31
  const handoff: Handoff = JSON.parse(document.getElementById('wb-page')!.textContent!)
29
32
  const root = document.getElementById('wb-root')!
30
33
  const page = handoff.id
31
34
  const isDir = handoff.kind === 'pages' || handoff.kind === 'folder'
35
+ // a built page has no server: no events, no listeners, no live channel, nothing to record
36
+ const live = handoff.live !== false
37
+ // a module's path as the page names it: a built page's are relative to the page, which an import()
38
+ // here would take as relative to this module
39
+ const moduleUrl = (path: string) => new URL(path, document.baseURI).href
32
40
 
33
41
  // ---- events ------------------------------------------------------------------------------------
34
42
 
@@ -45,7 +53,8 @@ function setEvents(next: WbEvent[]) {
45
53
  }
46
54
 
47
55
  async function loadEvents() {
48
- const res = await fetch(`/api/events?page=${encodeURIComponent(page)}`)
56
+ if (!live) return
57
+ const res = await fetch(url(`/api/events?page=${encodeURIComponent(page)}`))
49
58
  const all: WbEvent[] = await res.json()
50
59
  setEvents(all.filter(e => e.page === page))
51
60
  }
@@ -55,7 +64,8 @@ async function append(
55
64
  data: Record<string, unknown> = {},
56
65
  action: string | null = null,
57
66
  ): Promise<WbEvent> {
58
- const res = await fetch('/api/events', {
67
+ if (!live) throw new Error('a built page is a file: there is no log to append to')
68
+ const res = await fetch(url('/api/events'), {
59
69
  method: 'POST',
60
70
  headers: { 'content-type': 'application/json' },
61
71
  body: JSON.stringify({ page, type, action, data }),
@@ -70,7 +80,8 @@ let listeners: Listener[] = []
70
80
  const listenersValue = reactive(() => listeners)
71
81
 
72
82
  async function loadListeners() {
73
- listeners = await (await fetch(`/api/listeners?page=${encodeURIComponent(page)}`)).json()
83
+ if (!live) return
84
+ listeners = await (await fetch(url(`/api/listeners?page=${encodeURIComponent(page)}`))).json()
74
85
  listenersValue.notify()
75
86
  }
76
87
 
@@ -86,12 +97,13 @@ let baseTitle = document.title
86
97
  const badges = new Map<string, { text: string; order: number; since: number }>()
87
98
  let badgeCount = 0
88
99
  function writeTitle() {
89
- const list = [...badges.values()].sort((a, b) => a.order - b.order || a.since - b.since)
100
+ const list = [...badges.values()].toSorted((a, b) => a.order - b.order || a.since - b.since)
90
101
  document.title = `${list.map(b => `(${b.text}) `).join('')}${baseTitle}`
91
102
  }
92
103
 
93
104
  const api: Api = {
94
105
  page,
106
+ url,
95
107
  events: eventsValue,
96
108
  last: type => events.findLast(e => e.type === type),
97
109
  pickedUp: id => !!events.find(e => e.id === id)?.pickedUp,
@@ -145,13 +157,16 @@ async function getJson<T>(url: string): Promise<T> {
145
157
  // place (api.rendered), so a listener never sees new values over the old page
146
158
  let data: unknown = handoff.data
147
159
  let nextData: unknown = data
148
- let frontmatter: Record<string, string> = handoff.frontmatter ?? {}
160
+ let frontmatter: Record<string, unknown> = handoff.frontmatter ?? {}
149
161
  let nextFrontmatter = frontmatter
150
162
  const dataValue = reactive(() => data)
151
163
  const frontmatterValue = reactive(() => frontmatter)
164
+ const nothing = reactive((): unknown => undefined)
152
165
  const handle: PageHandle = {
166
+ settings: nothing,
153
167
  id: page,
154
168
  kind: handoff.kind,
169
+ live,
155
170
  data: dataValue,
156
171
  frontmatter: frontmatterValue,
157
172
  onChange(fn) {
@@ -159,12 +174,12 @@ const handle: PageHandle = {
159
174
  return () => changeListeners.delete(fn)
160
175
  },
161
176
  render: async () => {
162
- const next = await getJson<RenderedPage>(`/api/render?page=${encodeURIComponent(page)}`)
177
+ const next = await getJson<RenderedPage>(url(`/api/render?page=${encodeURIComponent(page)}`))
163
178
  nextData = next.data ?? null
164
179
  nextFrontmatter = next.frontmatter ?? {}
165
180
  return next
166
181
  },
167
- stored: () => getJson<StoredPage>(`/api/page?page=${encodeURIComponent(page)}`),
182
+ stored: () => getJson<StoredPage>(url(`/api/page?page=${encodeURIComponent(page)}`)),
168
183
  }
169
184
 
170
185
  /** Did the page change since it was rendered here (its file's time, or it came to be)? Then say so. */
@@ -172,8 +187,8 @@ async function caughtUp() {
172
187
  let now: number | null
173
188
  try {
174
189
  now =
175
- (await getJson<RenderedPage & { mtime: number | null }>(`/api/render?page=${encodeURIComponent(page)}`)).mtime ??
176
- null
190
+ (await getJson<RenderedPage & { mtime: number | null }>(url(`/api/render?page=${encodeURIComponent(page)}`)))
191
+ .mtime ?? null
177
192
  } catch {
178
193
  now = null
179
194
  }
@@ -191,7 +206,7 @@ if (!handoff.client)
191
206
  // ---- live channel ------------------------------------------------------------------------------
192
207
 
193
208
  function connect() {
194
- const es = new EventSource(`/api/watch?page=${encodeURIComponent(page)}${isDir ? '&dir' : ''}`)
209
+ const es = new EventSource(url(`/api/watch?page=${encodeURIComponent(page)}${isDir ? '&dir' : ''}`))
195
210
  es.onopen = () => {
196
211
  document.documentElement.dataset.wbLive = ''
197
212
  // after a server restart: who is listening now, and what was answered meanwhile
@@ -216,7 +231,7 @@ function connect() {
216
231
  es.addEventListener('reload', () => {
217
232
  const go = async () => {
218
233
  try {
219
- 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()
220
235
  } catch {
221
236
  /* not up yet */
222
237
  }
@@ -242,7 +257,7 @@ function connect() {
242
257
  await Promise.all([loadEvents(), loadListeners()])
243
258
  if (handoff.client) {
244
259
  try {
245
- const mount: PluginMount = (await import(handoff.client)).default
260
+ const mount: PluginMount = (await import(moduleUrl(handoff.client))).default
246
261
  await mount(root, handle, api)
247
262
  } catch (err) {
248
263
  console.error('page:', err)
@@ -252,23 +267,45 @@ if (handoff.client) {
252
267
  )
253
268
  }
254
269
  }
255
- // named forms, once the page is on the page
256
- trackForms(root, page, api)
257
- trackReading({
258
- messages: handoff.messages ?? [],
259
- events: () => events,
260
- send: ids => {
261
- append(READ, { ids }).catch(err => console.error('marking read:', err))
262
- },
263
- })
270
+ // named forms, once the page is on the page, and what the reader read: neither on a built page
271
+ if (live) {
272
+ trackForms(root, page, api)
273
+ trackReading({
274
+ messages: handoff.messages ?? [],
275
+ events: () => events,
276
+ send: ids => {
277
+ append(READ, { ids }).catch(err => console.error('marking read:', err))
278
+ },
279
+ })
280
+ }
281
+ /**
282
+ * A plugin's page handle: the page's, with its own settings, the page's frontmatter under `plugins:`
283
+ * by its name, heard of only when they changed.
284
+ */
285
+ function handleFor(name: string): PageHandle {
286
+ const own = () => {
287
+ const plugins = frontmatter.plugins
288
+ return plugins && typeof plugins === 'object' ? (plugins as Record<string, unknown>)[name] : undefined
289
+ }
290
+ const settings = reactive(own)
291
+ let last = JSON.stringify(own() ?? null)
292
+ frontmatterValue.on(() => {
293
+ const now = JSON.stringify(own() ?? null)
294
+ if (now === last) return
295
+ last = now
296
+ settings.notify()
297
+ })
298
+ return { ...handle, settings }
299
+ }
300
+
264
301
  // the plugins' modules after the page, so that what they work on is there; one failing leaves the others
265
302
  await Promise.all(
266
303
  (handoff.plugins ?? []).map(async ext => {
267
304
  try {
268
- const mount: PluginMount = (await import(ext.client)).default
305
+ const mount: PluginMount = (await import(moduleUrl(ext.client))).default
269
306
  if (typeof mount !== 'function')
270
307
  throw new Error('the client module must export a mount(root, page, api) function as default')
271
- await mount(root, handle, api)
308
+ await mount(root, handleFor(ext.name), api)
272
309
  } catch (err) {
273
310
  console.error(`plugin ${ext.name}:`, err)
274
311
  root.insertAdjacentHTML(
@@ -281,4 +318,4 @@ plugin "${ext.name}" failed in the browser: ${(err as Error).message}</pre>`,
281
318
  }
282
319
  }),
283
320
  )
284
- connect()
321
+ if (live) connect()
package/src/define.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  // between them and a browser. Everything else is a plugin: the syntax pages are written in (blocks),
7
7
  // behaviour on every page, commands, routes. defineConfig and definePlugin only return their
8
8
  // argument; they exist for types.
9
+ import type { IncomingMessage, ServerResponse } from 'node:http'
9
10
  import type { Html } from './html.ts'
10
11
 
11
12
  // HTML from a template literal, escaped by default: for a block, a plugin's `shell`
@@ -31,6 +32,26 @@ export interface Config {
31
32
  plugins?: Plugin[]
32
33
  /** a stylesheet linked on every page, after the built-in ones: the project's own look */
33
34
  style?: URL | string
35
+ /** what `whiteboard build` makes: a static site of some pages, without what is only for writing them */
36
+ build?: BuildConfig
37
+ }
38
+
39
+ /**
40
+ * `whiteboard build`: pages rendered once, as plain HTML files with their images and styles, links
41
+ * between them relative. What is for writing them is left out: the live channel, the event log,
42
+ * and the plugins and blocks in `skip`. What is for reading stays (steps, ⤢, the theme, contents).
43
+ */
44
+ export interface BuildConfig {
45
+ /**
46
+ * Which pages, as globs from the project's folder; `!` leaves out: `['docs/**\/*.md', '!docs/notes/**']`.
47
+ * Each lands in `out` at its place below the folder they share (`docs/api/forms.md` →
48
+ * `api/forms.html`); a README.md or index.md is its folder's index.html.
49
+ */
50
+ pages?: string[]
51
+ /** plugins or blocks left out of the site (default: form, chat, comments, draft) */
52
+ skip?: string[]
53
+ /** the folder the site goes to, from the project's folder (default: site) */
54
+ out?: string
34
55
  }
35
56
 
36
57
  export const defineConfig = (config: Config): Config => config
@@ -79,6 +100,15 @@ export interface Plugin {
79
100
  * Others stay in the log, for `whiteboard events` or a `wait --type` that asks for them by name.
80
101
  */
81
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>
82
112
  setup?(ctx: PluginContext): PluginHooks | Promise<PluginHooks>
83
113
  /** by subcommand: `''` is `whiteboard <name>` itself, `stop` is `whiteboard <name> stop` */
84
114
  commands?: Record<string, Command>
@@ -153,8 +183,11 @@ export interface PluginContext {
153
183
  project: Project
154
184
  /** the plugin's own folder, `.whiteboard/<name>/` (made, and ignored in git) */
155
185
  dataDir: string
156
- /** whether a request carries the project's token: for a check of its own, beyond a route's `auth` */
157
- authorized(req: import('node:http').IncomingMessage): boolean
186
+ /**
187
+ * whether a request carries the project's token: for a check of its own, beyond a route's `auth`.
188
+ * No request (`shell` for a page being built) has none.
189
+ */
190
+ authorized(req: IncomingMessage | null): boolean
158
191
  /** the URL that serves a file of the plugin (its browser module, a stylesheet) */
159
192
  asset(file: URL | string): string
160
193
  }
@@ -177,9 +210,13 @@ export interface PluginHooks {
177
210
  * length in `--wb-inset-bottom` on :root, registered with `@property` so that it computes to
178
211
  * pixels. The page keeps its own fixed elements clear of it and counts what is behind it as out
179
212
  * of view.
213
+ *
214
+ * `req` is the browser's request for the page; null for a page `whiteboard build` writes, which no
215
+ * browser asked for: what is only for the project's own browser (the terminal's drawer, behind
216
+ * `authorized`) has nothing to add there.
180
217
  */
181
218
  shell?(
182
- req: import('node:http').IncomingMessage,
219
+ req: IncomingMessage | null,
183
220
  ):
184
221
  | { head?: string | Html; body?: string | Html }
185
222
  | null
@@ -213,9 +250,9 @@ export interface Route {
213
250
  export interface RouteRequest {
214
251
  body: Record<string, unknown>
215
252
  query: Record<string, unknown>
216
- req: import('node:http').IncomingMessage
253
+ req: IncomingMessage
217
254
  /** only for a stream route */
218
- res?: import('node:http').ServerResponse
255
+ res?: ServerResponse
219
256
  }
220
257
 
221
258
  /** `whiteboard <plugin> [sub] …` */
@@ -306,7 +343,7 @@ export interface RenderedPage extends Rendered {
306
343
  html: string
307
344
  head?: string
308
345
  /** the page's frontmatter (see PageHandle.frontmatter) */
309
- frontmatter: Record<string, string>
346
+ frontmatter: Record<string, unknown>
310
347
  }
311
348
 
312
349
  /** A page as the core stores it: what is in the file, read as is. */
@@ -327,8 +364,10 @@ export interface PageSource extends StoredBase {
327
364
  source: string
328
365
  /** `source` without its frontmatter: the page's content */
329
366
  body: string
330
- /** the frontmatter's fields, when the file starts with one (`source` keeps it) */
331
- frontmatter: Record<string, string>
367
+ /** the frontmatter's fields, when the file starts with one (`source` keeps it): YAML, as parsed */
368
+ frontmatter: Record<string, unknown>
369
+ /** why the frontmatter couldn't be read (it is then empty), shown on the page */
370
+ frontmatterError?: string | null
332
371
  }
333
372
 
334
373
  /** Any other text file in the repository. */
@@ -348,6 +387,14 @@ export interface PagesSource extends StoredBase {
348
387
  kind: 'pages'
349
388
  /** `awaiting`: how many things on the page wait for the reader: open questions, unread messages */
350
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
351
398
  }
352
399
 
353
400
  /** What the core offers the pages on the server: how files are served and linked. */
@@ -364,6 +411,17 @@ export interface RenderContext {
364
411
  * not exist or nothing serves it. For relative links: resolve them from the page's folder first.
365
412
  */
366
413
  urlFor(file: string): string | null
414
+ /** false in a build (`whiteboard build`): the page is a file, with no updates and no events */
415
+ live?: boolean
416
+ /** in a build, the plugins and blocks left out: their blocks render as nothing */
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 }
367
425
  }
368
426
 
369
427
  /**
@@ -376,14 +434,28 @@ export type PluginMount = (root: HTMLElement, page: PageHandle, api: Api) => voi
376
434
  export interface PageHandle {
377
435
  id: string
378
436
  kind: StoredPage['kind']
437
+ /**
438
+ * false on a built page (`whiteboard build`): a file, with no server behind it, so no events, no
439
+ * listeners and no updates; only what is for reading runs.
440
+ */
441
+ live: boolean
379
442
  /** what the server render returned with the HTML now in the root; it changes with each live update */
380
443
  data: Reactive<unknown>
381
444
  /**
382
- * The page's frontmatter: its fields as written, as strings (`toc: true` is `'true'`); empty for a
383
- * page without one, and for the overview, folders and code. It changes with a live update that
384
- * changed it, once the new page is in place (`onChange` comes before, with the old one still here).
445
+ * The page's frontmatter: YAML between `---` lines at its start, as parsed; empty for a page
446
+ * without one, one that doesn't parse, and for the overview, folders and code. It changes with a
447
+ * live update that changed it, once the new page is in place (`onChange` comes before, with the
448
+ * old one still here). The top level is the core's and other tools' (`title`, `tags`); a plugin's
449
+ * own is under `plugins:`, by its name, and is its `settings`.
450
+ */
451
+ frontmatter: Reactive<Record<string, unknown>>
452
+ /**
453
+ * For a plugin's browser module, its own entry in the page's frontmatter, under `plugins:` by its
454
+ * name, as parsed: `plugins: { toc: true }` is `true` for toc, `plugins: { toc: { maxWidth: 240px } }`
455
+ * an object; undefined when the page says nothing for it (and for the page module). It changes
456
+ * when that entry does.
385
457
  */
386
- frontmatter: Reactive<Record<string, string>>
458
+ settings: Reactive<unknown>
387
459
  /** called when the stored page changed; returns an unsubscribe */
388
460
  onChange(fn: () => void): () => void
389
461
  /** the server render, afresh */
@@ -463,6 +535,12 @@ export interface Reactive<T> {
463
535
  export interface Api {
464
536
  /** this page's id */
465
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
466
544
  /** every event recorded for this page, oldest first */
467
545
  events: Reactive<WbEvent[]>
468
546
  /** the latest event of a type, e.g. the last submit of a form */
@@ -566,6 +644,11 @@ export interface Block<Props = unknown> {
566
644
  * output; with it, what shows until it mounts.
567
645
  */
568
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
569
652
  /** a browser module whose default export is a `Mount`, in its plugin's public folder: `'chart.js'` */
570
653
  client?: URL | string
571
654
  /** a stylesheet linked on every page that uses the block, in its plugin's public folder: `'chart.css'` */
@@ -587,12 +670,22 @@ export type Mount<Props = unknown> = (
587
670
 
588
671
  // ---- server context ----------------------------------------------------------------------------
589
672
 
590
- export interface Section {
591
- /** 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 */
592
680
  title: string | null
593
- /** heading as plain text */
681
+ /** the heading as plain text */
594
682
  text: string | null
683
+ /** the item's content as HTML */
595
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
596
689
  }
597
690
 
598
691
  interface BaseContext {
@@ -623,8 +716,8 @@ export interface DirectiveContext extends BaseContext {
623
716
  labelText: string | null
624
717
  /** the block's content as mdast nodes */
625
718
  children: unknown[]
626
- /** split the content at its shallowest headings, or at blank lines when it has none */
627
- 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[]>
628
721
  }
629
722
 
630
723
  /** ```name attrs */
@@ -637,14 +730,28 @@ export interface FenceContext extends BaseContext {
637
730
 
638
731
  export type ServerContext = DirectiveContext | FenceContext
639
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
+
640
747
  /** Default props of a directive without props(). */
641
748
  export interface DirectiveProps {
642
749
  name: string
643
750
  attrs: Record<string, string>
644
751
  label: string | null
645
752
  html: string
646
- intro: string
647
- sections: Section[]
753
+ /** its items (Item), without their mdast nodes */
754
+ items: Omit<Item, 'nodes'>[]
648
755
  }
649
756
 
650
757
  /** Default props of a fence without props(). */