@bigmistqke/whiteboard 0.4.0 → 0.5.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 (50) hide show
  1. package/README.md +55 -4
  2. package/bin/whiteboard.ts +32 -0
  3. package/dist/bin/whiteboard.js +21 -0
  4. package/dist/client/runtime.js +44 -13
  5. package/dist/plugins/draft/README.md +14 -0
  6. package/dist/plugins/draft/index.js +21 -0
  7. package/dist/plugins/draft/public/style.css +21 -0
  8. package/dist/plugins/index.js +5 -1
  9. package/dist/plugins/steps/README.md +42 -0
  10. package/dist/plugins/steps/index.js +99 -0
  11. package/dist/plugins/steps/public/client.js +1 -0
  12. package/dist/plugins/steps/public/style.css +77 -0
  13. package/dist/plugins/terminal/host.js +9 -3
  14. package/dist/plugins/terminal/sizes.js +2 -1
  15. package/dist/plugins/toc/README.md +21 -3
  16. package/dist/plugins/toc/index.js +8 -2
  17. package/dist/plugins/toc/public/client.js +1 -1
  18. package/dist/plugins/toc/public/style.css +10 -4
  19. package/dist/src/auth.js +2 -1
  20. package/dist/src/client/page/main.js +14 -6
  21. package/dist/src/loader.js +8 -2
  22. package/dist/src/pages/render.js +42 -15
  23. package/dist/src/pages/window.js +3 -2
  24. package/dist/src/server.js +216 -10
  25. package/package.json +3 -2
  26. package/plugins/code/index.ts +3 -1
  27. package/plugins/draft/README.md +14 -0
  28. package/plugins/draft/index.ts +23 -0
  29. package/plugins/draft/public/style.css +21 -0
  30. package/plugins/index.ts +4 -0
  31. package/plugins/mermaid/index.ts +4 -2
  32. package/plugins/steps/README.md +42 -0
  33. package/plugins/steps/client.ts +66 -0
  34. package/plugins/steps/index.ts +127 -0
  35. package/plugins/steps/public/style.css +77 -0
  36. package/plugins/terminal/host.ts +12 -6
  37. package/plugins/terminal/sizes.ts +3 -1
  38. package/plugins/toc/README.md +21 -3
  39. package/plugins/toc/client.ts +47 -6
  40. package/plugins/toc/index.ts +19 -6
  41. package/plugins/toc/public/style.css +10 -4
  42. package/src/auth.ts +3 -2
  43. package/src/client/page/main.ts +18 -6
  44. package/src/client/runtime.ts +51 -16
  45. package/src/define.ts +60 -12
  46. package/src/loader.ts +7 -2
  47. package/src/pages/index.ts +2 -2
  48. package/src/pages/render.ts +48 -16
  49. package/src/pages/window.ts +8 -1
  50. package/src/server.ts +253 -13
@@ -1,8 +1,14 @@
1
1
  /* the table of contents (client.ts): in the margin left of the text, or opened from the header */
2
+ /* it fits its items, between a minimum and a maximum (client.ts sets them from the options and the
3
+ page's frontmatter); docked, never wider than the room left of the text */
2
4
  .wb-toc {
3
5
  position: fixed;
4
6
  z-index: var(--layer-aside);
5
- font: var(--ui-small)/var(--ui-line-height) var(--sans, sans-serif);
7
+ font: var(--ui-small) / var(--ui-line-height) var(--sans, sans-serif);
8
+ box-sizing: border-box;
9
+ width: max-content;
10
+ min-width: var(--wb-toc-min-width, 160px);
11
+ max-width: var(--wb-toc-max-width, 320px);
6
12
  }
7
13
  .wb-toc[hidden],
8
14
  .wb-toc-toggle[hidden] {
@@ -10,15 +16,15 @@
10
16
  }
11
17
  .wb-toc-docked {
12
18
  top: 72px;
13
- left: max(16px, calc((100vw - var(--measure, 680px)) / 2 - 250px));
14
- width: 210px;
19
+ right: var(--wb-toc-right);
20
+ max-width: min(var(--wb-toc-max-width, 320px), var(--wb-toc-room, 320px));
15
21
  max-height: calc(100vh - 120px - var(--wb-inset-bottom, 0px));
16
22
  overflow: auto;
17
23
  }
18
24
  .wb-toc-open:not(.wb-toc-docked) {
19
25
  top: 52px;
20
26
  left: 16px;
21
- width: min(300px, 100vw - 32px);
27
+ max-width: min(var(--wb-toc-max-width, 320px), 100vw - 32px);
22
28
  max-height: calc(100vh - 100px - var(--wb-inset-bottom, 0px));
23
29
  overflow: auto;
24
30
  padding: var(--space-sm);
package/src/auth.ts CHANGED
@@ -44,8 +44,9 @@ export function createAuth(wb: string) {
44
44
  .filter(([k]) => k),
45
45
  )
46
46
 
47
- /** Has this request the token, from this origin? */
48
- function authorized(req: IncomingMessage): boolean {
47
+ /** Has this request the token, from this origin? No request (a page being built) has none. */
48
+ function authorized(req: IncomingMessage | null): boolean {
49
+ if (!req) return false
49
50
  const jar = cookies(req)
50
51
  const has = same(jar[COOKIE], token) || same(req.headers['x-whiteboard-token'], token)
51
52
  if (!has) return false
@@ -41,7 +41,7 @@ async function mountOne(el: HTMLElement) {
41
41
  el.dataset.wbMounted = ''
42
42
  if (!island) return
43
43
  try {
44
- const mod = await import(island.client)
44
+ const mod = await import(new URL(island.client, document.baseURI).href)
45
45
  if (!el.isConnected) return
46
46
  const mount: Mount = mod.default
47
47
  if (typeof mount !== 'function')
@@ -314,16 +314,25 @@ function keepPlace(place: ReturnType<typeof placeOf>, sigs: string[]) {
314
314
  }
315
315
 
316
316
  /** The new render of the page, patched in. */
317
+ // the page is going (its own reload below, or the reader went elsewhere): a render still in flight is
318
+ // cut off then, and its failure is not the page's
319
+ let leaving = false
320
+ addEventListener('pagehide', () => {
321
+ leaving = true
322
+ })
323
+
317
324
  async function refresh() {
318
325
  let next: Awaited<ReturnType<PageHandle['render']>>
319
326
  try {
320
327
  next = await currentPage.render()
321
328
  } catch (err) {
329
+ if (leaving) return
322
330
  // the page is gone (closed, deleted): load what its address shows now, the "Not found" page,
323
331
  // which turns into the page again if it is written back. Already that page (it has no file, so
324
332
  // no time it was edited): still not there, nothing to do
325
333
  if (/: 404$/.test((err as Error).message)) {
326
334
  if ((currentPage.data() as Data | null)?.mtime == null) return
335
+ leaving = true
327
336
  return location.reload()
328
337
  }
329
338
  throw err
@@ -402,10 +411,13 @@ const mount: PluginMount = async (root: HTMLElement, handle: PageHandle, coreApi
402
411
  if (isDir) core.listeners.on(() => refresh())
403
412
 
404
413
  blockSigs = [...main.children].map(signature)
405
- if (!isDir) trackInitial(main, page, core)
406
- if (!isDir) trackWaiting(main, core)
407
- trackElsewhere(root, handle, core)
408
- trackLive(root, handle, core)
414
+ // what is new, what waits, what is elsewhere, whether it's live: the server's, not a built page's
415
+ if (handle.live) {
416
+ if (!isDir) trackInitial(main, page, core)
417
+ if (!isDir) trackWaiting(main, core)
418
+ trackElsewhere(root, handle, core)
419
+ trackLive(root, handle, core)
420
+ }
409
421
  if (isDir) {
410
422
  trackSorts()
411
423
  core.onRendered(applySorts)
@@ -413,7 +425,7 @@ const mount: PluginMount = async (root: HTMLElement, handle: PageHandle, coreApi
413
425
  trackSticky(main, fn => core.onRendered(fn))
414
426
  trackHold()
415
427
  trackWindows(core)
416
- if (!isDir) trackOrphanThreads(main, core)
428
+ if (!isDir && handle.live) trackOrphanThreads(main, core)
417
429
  await mountIslands()
418
430
  tickTimes()
419
431
  }
@@ -22,13 +22,20 @@ interface Handoff {
22
22
  /** the event types that, from the agent, are messages for the reader */
23
23
  messages: string[]
24
24
  /** the page's frontmatter (PageHandle.frontmatter) */
25
- frontmatter: Record<string, string>
25
+ frontmatter: Record<string, unknown>
26
+ /** false on a built page (`whiteboard build`): a file, no server behind it */
27
+ live?: boolean
26
28
  }
27
29
 
28
30
  const handoff: Handoff = JSON.parse(document.getElementById('wb-page')!.textContent!)
29
31
  const root = document.getElementById('wb-root')!
30
32
  const page = handoff.id
31
33
  const isDir = handoff.kind === 'pages' || handoff.kind === 'folder'
34
+ // a built page has no server: no events, no listeners, no live channel, nothing to record
35
+ const live = handoff.live !== false
36
+ // a module's path as the page names it: a built page's are relative to the page, which an import()
37
+ // here would take as relative to this module
38
+ const moduleUrl = (path: string) => new URL(path, document.baseURI).href
32
39
 
33
40
  // ---- events ------------------------------------------------------------------------------------
34
41
 
@@ -45,6 +52,7 @@ function setEvents(next: WbEvent[]) {
45
52
  }
46
53
 
47
54
  async function loadEvents() {
55
+ if (!live) return
48
56
  const res = await fetch(`/api/events?page=${encodeURIComponent(page)}`)
49
57
  const all: WbEvent[] = await res.json()
50
58
  setEvents(all.filter(e => e.page === page))
@@ -55,6 +63,7 @@ async function append(
55
63
  data: Record<string, unknown> = {},
56
64
  action: string | null = null,
57
65
  ): Promise<WbEvent> {
66
+ if (!live) throw new Error('a built page is a file: there is no log to append to')
58
67
  const res = await fetch('/api/events', {
59
68
  method: 'POST',
60
69
  headers: { 'content-type': 'application/json' },
@@ -70,6 +79,7 @@ let listeners: Listener[] = []
70
79
  const listenersValue = reactive(() => listeners)
71
80
 
72
81
  async function loadListeners() {
82
+ if (!live) return
73
83
  listeners = await (await fetch(`/api/listeners?page=${encodeURIComponent(page)}`)).json()
74
84
  listenersValue.notify()
75
85
  }
@@ -86,7 +96,7 @@ let baseTitle = document.title
86
96
  const badges = new Map<string, { text: string; order: number; since: number }>()
87
97
  let badgeCount = 0
88
98
  function writeTitle() {
89
- const list = [...badges.values()].sort((a, b) => a.order - b.order || a.since - b.since)
99
+ const list = [...badges.values()].toSorted((a, b) => a.order - b.order || a.since - b.since)
90
100
  document.title = `${list.map(b => `(${b.text}) `).join('')}${baseTitle}`
91
101
  }
92
102
 
@@ -145,13 +155,16 @@ async function getJson<T>(url: string): Promise<T> {
145
155
  // place (api.rendered), so a listener never sees new values over the old page
146
156
  let data: unknown = handoff.data
147
157
  let nextData: unknown = data
148
- let frontmatter: Record<string, string> = handoff.frontmatter ?? {}
158
+ let frontmatter: Record<string, unknown> = handoff.frontmatter ?? {}
149
159
  let nextFrontmatter = frontmatter
150
160
  const dataValue = reactive(() => data)
151
161
  const frontmatterValue = reactive(() => frontmatter)
162
+ const nothing = reactive((): unknown => undefined)
152
163
  const handle: PageHandle = {
164
+ settings: nothing,
153
165
  id: page,
154
166
  kind: handoff.kind,
167
+ live,
155
168
  data: dataValue,
156
169
  frontmatter: frontmatterValue,
157
170
  onChange(fn) {
@@ -242,7 +255,7 @@ function connect() {
242
255
  await Promise.all([loadEvents(), loadListeners()])
243
256
  if (handoff.client) {
244
257
  try {
245
- const mount: PluginMount = (await import(handoff.client)).default
258
+ const mount: PluginMount = (await import(moduleUrl(handoff.client))).default
246
259
  await mount(root, handle, api)
247
260
  } catch (err) {
248
261
  console.error('page:', err)
@@ -252,23 +265,45 @@ if (handoff.client) {
252
265
  )
253
266
  }
254
267
  }
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
- })
268
+ // named forms, once the page is on the page, and what the reader read: neither on a built page
269
+ if (live) {
270
+ trackForms(root, page, api)
271
+ trackReading({
272
+ messages: handoff.messages ?? [],
273
+ events: () => events,
274
+ send: ids => {
275
+ append(READ, { ids }).catch(err => console.error('marking read:', err))
276
+ },
277
+ })
278
+ }
279
+ /**
280
+ * A plugin's page handle: the page's, with its own settings, the page's frontmatter under `plugins:`
281
+ * by its name, heard of only when they changed.
282
+ */
283
+ function handleFor(name: string): PageHandle {
284
+ const own = () => {
285
+ const plugins = frontmatter.plugins
286
+ return plugins && typeof plugins === 'object' ? (plugins as Record<string, unknown>)[name] : undefined
287
+ }
288
+ const settings = reactive(own)
289
+ let last = JSON.stringify(own() ?? null)
290
+ frontmatterValue.on(() => {
291
+ const now = JSON.stringify(own() ?? null)
292
+ if (now === last) return
293
+ last = now
294
+ settings.notify()
295
+ })
296
+ return { ...handle, settings }
297
+ }
298
+
264
299
  // the plugins' modules after the page, so that what they work on is there; one failing leaves the others
265
300
  await Promise.all(
266
301
  (handoff.plugins ?? []).map(async ext => {
267
302
  try {
268
- const mount: PluginMount = (await import(ext.client)).default
303
+ const mount: PluginMount = (await import(moduleUrl(ext.client))).default
269
304
  if (typeof mount !== 'function')
270
305
  throw new Error('the client module must export a mount(root, page, api) function as default')
271
- await mount(root, handle, api)
306
+ await mount(root, handleFor(ext.name), api)
272
307
  } catch (err) {
273
308
  console.error(`plugin ${ext.name}:`, err)
274
309
  root.insertAdjacentHTML(
@@ -281,4 +316,4 @@ plugin "${ext.name}" failed in the browser: ${(err as Error).message}</pre>`,
281
316
  }
282
317
  }),
283
318
  )
284
- connect()
319
+ 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
@@ -153,8 +174,11 @@ export interface PluginContext {
153
174
  project: Project
154
175
  /** the plugin's own folder, `.whiteboard/<name>/` (made, and ignored in git) */
155
176
  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
177
+ /**
178
+ * whether a request carries the project's token: for a check of its own, beyond a route's `auth`.
179
+ * No request (`shell` for a page being built) has none.
180
+ */
181
+ authorized(req: IncomingMessage | null): boolean
158
182
  /** the URL that serves a file of the plugin (its browser module, a stylesheet) */
159
183
  asset(file: URL | string): string
160
184
  }
@@ -177,9 +201,13 @@ export interface PluginHooks {
177
201
  * length in `--wb-inset-bottom` on :root, registered with `@property` so that it computes to
178
202
  * pixels. The page keeps its own fixed elements clear of it and counts what is behind it as out
179
203
  * of view.
204
+ *
205
+ * `req` is the browser's request for the page; null for a page `whiteboard build` writes, which no
206
+ * browser asked for: what is only for the project's own browser (the terminal's drawer, behind
207
+ * `authorized`) has nothing to add there.
180
208
  */
181
209
  shell?(
182
- req: import('node:http').IncomingMessage,
210
+ req: IncomingMessage | null,
183
211
  ):
184
212
  | { head?: string | Html; body?: string | Html }
185
213
  | null
@@ -213,9 +241,9 @@ export interface Route {
213
241
  export interface RouteRequest {
214
242
  body: Record<string, unknown>
215
243
  query: Record<string, unknown>
216
- req: import('node:http').IncomingMessage
244
+ req: IncomingMessage
217
245
  /** only for a stream route */
218
- res?: import('node:http').ServerResponse
246
+ res?: ServerResponse
219
247
  }
220
248
 
221
249
  /** `whiteboard <plugin> [sub] …` */
@@ -306,7 +334,7 @@ export interface RenderedPage extends Rendered {
306
334
  html: string
307
335
  head?: string
308
336
  /** the page's frontmatter (see PageHandle.frontmatter) */
309
- frontmatter: Record<string, string>
337
+ frontmatter: Record<string, unknown>
310
338
  }
311
339
 
312
340
  /** A page as the core stores it: what is in the file, read as is. */
@@ -327,8 +355,10 @@ export interface PageSource extends StoredBase {
327
355
  source: string
328
356
  /** `source` without its frontmatter: the page's content */
329
357
  body: string
330
- /** the frontmatter's fields, when the file starts with one (`source` keeps it) */
331
- frontmatter: Record<string, string>
358
+ /** the frontmatter's fields, when the file starts with one (`source` keeps it): YAML, as parsed */
359
+ frontmatter: Record<string, unknown>
360
+ /** why the frontmatter couldn't be read (it is then empty), shown on the page */
361
+ frontmatterError?: string | null
332
362
  }
333
363
 
334
364
  /** Any other text file in the repository. */
@@ -364,6 +394,10 @@ export interface RenderContext {
364
394
  * not exist or nothing serves it. For relative links: resolve them from the page's folder first.
365
395
  */
366
396
  urlFor(file: string): string | null
397
+ /** false in a build (`whiteboard build`): the page is a file, with no updates and no events */
398
+ live?: boolean
399
+ /** in a build, the plugins and blocks left out: their blocks render as nothing */
400
+ skip?: ReadonlySet<string>
367
401
  }
368
402
 
369
403
  /**
@@ -376,14 +410,28 @@ export type PluginMount = (root: HTMLElement, page: PageHandle, api: Api) => voi
376
410
  export interface PageHandle {
377
411
  id: string
378
412
  kind: StoredPage['kind']
413
+ /**
414
+ * false on a built page (`whiteboard build`): a file, with no server behind it, so no events, no
415
+ * listeners and no updates; only what is for reading runs.
416
+ */
417
+ live: boolean
379
418
  /** what the server render returned with the HTML now in the root; it changes with each live update */
380
419
  data: Reactive<unknown>
381
420
  /**
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).
421
+ * The page's frontmatter: YAML between `---` lines at its start, as parsed; empty for a page
422
+ * without one, one that doesn't parse, and for the overview, folders and code. It changes with a
423
+ * live update that changed it, once the new page is in place (`onChange` comes before, with the
424
+ * old one still here). The top level is the core's and other tools' (`title`, `tags`); a plugin's
425
+ * own is under `plugins:`, by its name, and is its `settings`.
426
+ */
427
+ frontmatter: Reactive<Record<string, unknown>>
428
+ /**
429
+ * For a plugin's browser module, its own entry in the page's frontmatter, under `plugins:` by its
430
+ * name, as parsed: `plugins: { toc: true }` is `true` for toc, `plugins: { toc: { maxWidth: 240px } }`
431
+ * an object; undefined when the page says nothing for it (and for the page module). It changes
432
+ * when that entry does.
385
433
  */
386
- frontmatter: Reactive<Record<string, string>>
434
+ settings: Reactive<unknown>
387
435
  /** called when the stored page changed; returns an unsubscribe */
388
436
  onChange(fn: () => void): () => void
389
437
  /** the server render, afresh */
package/src/loader.ts CHANGED
@@ -9,7 +9,7 @@ import { importFresh, importOwn } from './load.ts'
9
9
  import { createPages, type Pages } from './pages/index.ts'
10
10
  import { pluginCommands } from './plugins.ts'
11
11
  import { inPublic, publicDirOf } from './public.ts'
12
- import type { Config, Plugin } from './define.ts'
12
+ import type { BuildConfig, Config, Plugin } from './define.ts'
13
13
  import type { Project } from './config.ts'
14
14
 
15
15
  /** A config as loaded: what went wrong is in `errors`. */
@@ -24,6 +24,8 @@ export interface LoadedConfig {
24
24
  /** each plugin's public folder, by name: the one place its browser files are served from */
25
25
  publicDirs: Map<string, string>
26
26
  files: boolean
27
+ /** what `whiteboard build` makes */
28
+ build: BuildConfig
27
29
  errors: unknown[]
28
30
  }
29
31
 
@@ -46,6 +48,7 @@ export const BUILTIN_COMMANDS = new Set([
46
48
  'scroll',
47
49
  'close',
48
50
  'prune',
51
+ 'build',
49
52
  'edit',
50
53
  'skill',
51
54
  'help',
@@ -130,7 +133,7 @@ export function createConfigLoader(proj: Project, { pages: withPages = true } =
130
133
  )
131
134
  const styles = plugins
132
135
  .filter(p => p.style)
133
- .map(p => inPublic(publicDirs.get(p.name)!, p.style!, `plugin ${p.name}: style`))
136
+ .map(p => ({ plugin: p.name, file: inPublic(publicDirs.get(p.name)!, p.style!, `plugin ${p.name}: style`) }))
134
137
  const links = plugins.flatMap(p => (p.links ? [p.links.bind(p)] : []))
135
138
  const pages = withPages ? createPages({ blocks, style: config?.style, styles, links }) : null
136
139
  const declared = (flag: 'handOut' | 'forReader') =>
@@ -148,6 +151,7 @@ export function createConfigLoader(proj: Project, { pages: withPages = true } =
148
151
  forReader: declared('forReader'),
149
152
  publicDirs,
150
153
  files: config?.files !== false,
154
+ build: config?.build ?? {},
151
155
  }
152
156
  }
153
157
 
@@ -161,6 +165,7 @@ export function createConfigLoader(proj: Project, { pages: withPages = true } =
161
165
  forReader: new Set<string>(),
162
166
  publicDirs: new Map<string, string>(),
163
167
  files: false,
168
+ build: {},
164
169
  errors: [error],
165
170
  }),
166
171
  )
@@ -12,8 +12,8 @@ export interface PagesOptions {
12
12
  blocks: BlockEntry[]
13
13
  /** the project's stylesheet, linked on every page after the others */
14
14
  style?: URL | string
15
- /** the plugins' stylesheets, linked on every page */
16
- styles?: (URL | string)[]
15
+ /** the plugins' stylesheets, linked on every page (but a build's, for a plugin it skips) */
16
+ styles?: { plugin: string; file: URL | string }[]
17
17
  /** the plugins' text links (Plugin.links), each asked once per project folder */
18
18
  links?: ((ctx: { dir: string }) => TextLink[])[]
19
19
  }
@@ -149,7 +149,7 @@ function documentsIn(dir: string) {
149
149
  walk('')
150
150
  }
151
151
  const depth = (f: string) => f.split('/').length
152
- return [...new Set(files)].sort((a, b) => depth(a) - depth(b) || a.localeCompare(b))
152
+ return [...new Set(files)].toSorted((a, b) => depth(a) - depth(b) || a.localeCompare(b))
153
153
  }
154
154
 
155
155
  /**
@@ -240,21 +240,40 @@ export function createMessageRender(
240
240
  }
241
241
  }
242
242
 
243
+ /** What a block left out of a build (RenderContext.skip) is: nothing, for its directives and fences alike. */
244
+ const skipped = (name: string): ResolvedBlock => ({
245
+ name,
246
+ code: false,
247
+ fences: true,
248
+ props: null,
249
+ html: () => '',
250
+ client: null,
251
+ style: null,
252
+ source: 'build',
253
+ })
254
+
243
255
  export function createRender(
244
256
  blocks: () => ResolvedBlocks,
245
257
  style?: URL | string,
246
- pluginStyles: (URL | string)[] = [],
258
+ pluginStyles: { plugin: string; file: URL | string }[] = [],
247
259
  links: ((ctx: { dir: string }) => TextLink[])[] = [],
248
260
  ) {
249
261
  const textLinks = textLinksOf(links)
250
262
  const STYLE = stylePath(style)
251
- const PLUGIN_STYLES = pluginStyles.map(stylePath).filter((f): f is string => !!f)
263
+ const PLUGIN_STYLES = pluginStyles
264
+ .map(s => ({ plugin: s.plugin, file: stylePath(s.file) }))
265
+ .filter((s): s is { plugin: string; file: string } => !!s.file)
252
266
  async function markdown(source: string, page: string, file: string, ctx: RenderContext) {
253
267
  const { blocks: set, code } = blocks()
268
+ const skip = ctx.skip
254
269
  return renderMarkdown(body(source), {
255
270
  page,
256
271
  file,
257
- resolve: name => set.get(name) ?? null,
272
+ resolve: name => {
273
+ const block = set.get(name) ?? null
274
+ if (skip && (skip.has(name) || (block && skip.has(block.source)))) return skipped(name)
275
+ return block
276
+ },
258
277
  code,
259
278
  linkFor: ctx.urlFor,
260
279
  textLinks: textLinks(ctx.project.dir),
@@ -338,20 +357,33 @@ export function createRender(
338
357
  Object.entries(out.islands).map(([id, island]) => [id, { ...island, client: ctx.asset(island.client) }]),
339
358
  )
340
359
  const styles = out.styles.map(s => ctx.asset(s))
341
- const nav = html`<nav class="wb-nav">
342
- <span>${crumbs(page.id, ctx.project.name)}</span
343
- >${page.mtime != null && html`<span class="wb-meta">updated <time id="wb-updated" data-ts="${page.mtime}"></time></span>`}<button
344
- type="button"
345
- class="wb-theme"
346
- title="Theme: follow the system, light or dark"
347
- aria-label="Theme"
348
- ></button
349
- ><span class="wb-live" role="img" title="Connecting…" aria-label="Connecting…"></span>
350
- </nav>`
360
+ // a built page: the project's name and the theme; nothing of the server's (crumbs into its
361
+ // folders, when it was updated, whether it is live)
362
+ const nav =
363
+ ctx.live === false
364
+ ? html`<nav class="wb-nav">
365
+ <span>${ctx.project.name}</span
366
+ ><button
367
+ type="button"
368
+ class="wb-theme"
369
+ title="Theme: follow the system, light or dark"
370
+ aria-label="Theme"
371
+ ></button>
372
+ </nav>`
373
+ : html`<nav class="wb-nav">
374
+ <span>${crumbs(page.id, ctx.project.name)}</span
375
+ >${page.mtime != null && html`<span class="wb-meta">updated <time id="wb-updated" data-ts="${page.mtime}"></time></span>`}<button
376
+ type="button"
377
+ class="wb-theme"
378
+ title="Theme: follow the system, light or dark"
379
+ aria-label="Theme"
380
+ ></button
381
+ ><span class="wb-live" role="img" title="Connecting…" aria-label="Connecting…"></span>
382
+ </nav>`
351
383
  // the page's own, the plugins' (every page), the blocks' on this page, then the project's
352
384
  const links = [
353
385
  ctx.asset(BASE_CSS),
354
- ...PLUGIN_STYLES.map(f => ctx.asset(f)),
386
+ ...PLUGIN_STYLES.filter(s => !ctx.skip?.has(s.plugin)).map(s => ctx.asset(s.file)),
355
387
  ...styles,
356
388
  ...(STYLE ? [ctx.asset(STYLE)] : []),
357
389
  ]
@@ -380,7 +412,7 @@ export function createDocs(blocks: () => ResolvedBlocks) {
380
412
  t.code ? `${t.name} (every other code fence)` : t.name,
381
413
  ])
382
414
  const list = [...byPlugin]
383
- .sort(([a], [b]) => a.localeCompare(b))
415
+ .toSorted(([a], [b]) => a.localeCompare(b))
384
416
  .map(([plugin, blocks]) => `- **${plugin}**: ${blocks.map(b => `\`${b}\``).join(', ')}`)
385
417
  return `# Pages
386
418
 
@@ -29,6 +29,10 @@ export interface WindowOptions {
29
29
  /** a class for its body, and a height for it (a CSS length), for what has none of its own (an iframe) */
30
30
  bodyClass?: string
31
31
  height?: string
32
+ /** a class for the window itself, for a block's styles and browser code to find it by */
33
+ className?: string
34
+ /** more in the header, after the label: a block's own controls (the steps' ‹ › ) */
35
+ controls?: Html | string
32
36
  }
33
37
 
34
38
  /** A window around a block's HTML: see the top of this file. */
@@ -40,6 +44,8 @@ export function windowFrame({
40
44
  bare = false,
41
45
  bodyClass = '',
42
46
  height,
47
+ className = '',
48
+ controls = '',
43
49
  }: WindowOptions): Html {
44
50
  const name =
45
51
  label != null && String(label) !== ''
@@ -51,6 +57,7 @@ export function windowFrame({
51
57
  !bare &&
52
58
  html`<div class="wb-window-bar">
53
59
  <span class="wb-window-name" ${open ? html` title="${open}"` : ''}>${name}</span>
60
+ ${raw(String(controls))}
54
61
  ${open && html`<a class="wb-window-button" href="${open}" target="_blank" rel="noopener" title="Open on its own" aria-label="Open on its own">${OPEN}</a>`}
55
62
  <button
56
63
  type="button"
@@ -62,7 +69,7 @@ export function windowFrame({
62
69
  <span class="wb-window-max">${MAXIMIZE}</span><span class="wb-window-restore">${RESTORE}</span>
63
70
  </button>
64
71
  </div>`
65
- return html`<div class="wb-window${wide && raw(' wb-wide')}">
72
+ return html`<div class="wb-window${wide && raw(' wb-wide')}${className && raw(' ' + className)}">
66
73
  ${header}
67
74
  <div class="wb-window-body${bodyClass && raw(' ' + bodyClass)}" ${height ? html` style="height: ${height}"` : ''}>
68
75
  ${raw(String(body))}