@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.
- package/README.md +177 -26
- package/bin/whiteboard.ts +331 -16
- package/dist/bin/whiteboard.js +268 -17
- package/dist/client/runtime.js +66 -23
- package/dist/plugins/ansi/README.md +36 -0
- package/dist/plugins/ansi/index.js +64 -0
- package/dist/plugins/ansi/public/style.css +28 -0
- package/dist/plugins/badge/README.md +28 -0
- package/dist/plugins/badge/index.js +24 -0
- package/dist/plugins/badge/public/style.css +30 -0
- package/dist/plugins/chat/public/style.css +7 -2
- package/dist/plugins/code/README.md +4 -2
- package/dist/plugins/code/diff.js +12 -2
- package/dist/plugins/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +21 -0
- package/dist/plugins/draft/public/style.css +21 -0
- package/dist/plugins/grid/README.md +12 -12
- package/dist/plugins/grid/index.js +7 -19
- package/dist/plugins/grid/public/style.css +4 -33
- package/dist/plugins/iframe/README.md +7 -7
- package/dist/plugins/iframe/index.js +11 -11
- package/dist/plugins/iframe/public/style.css +15 -0
- package/dist/plugins/index.js +11 -3
- package/dist/plugins/lightbox/README.md +22 -0
- package/dist/plugins/lightbox/index.js +20 -0
- package/dist/plugins/lightbox/public/client.js +4 -0
- package/dist/plugins/lightbox/public/style.css +66 -0
- package/dist/plugins/steps/README.md +42 -0
- package/dist/plugins/steps/index.js +60 -0
- package/dist/plugins/steps/public/client.js +1 -0
- package/dist/plugins/steps/public/style.css +77 -0
- package/dist/plugins/terminal/host.js +9 -3
- package/dist/plugins/terminal/public/client.js +1 -1
- package/dist/plugins/terminal/sizes.js +2 -1
- package/dist/plugins/toc/README.md +21 -3
- package/dist/plugins/toc/index.js +8 -2
- package/dist/plugins/toc/public/client.js +1 -1
- package/dist/plugins/toc/public/style.css +10 -4
- package/dist/plugins/window/README.md +34 -14
- package/dist/plugins/window/index.js +21 -13
- package/dist/src/auth.js +6 -4
- package/dist/src/client/page/base.css +61 -1
- package/dist/src/client/page/main.js +74 -20
- package/dist/src/entries.js +211 -0
- package/dist/src/events.js +1 -1
- package/dist/src/hub.js +272 -0
- package/dist/src/loader.js +12 -3
- package/dist/src/package.js +23 -1
- package/dist/src/pages/blocks.js +1 -0
- package/dist/src/pages/index.js +1 -1
- package/dist/src/pages/markdown.js +87 -33
- package/dist/src/pages/render.js +157 -28
- package/dist/src/pages/window.js +17 -18
- package/dist/src/running.js +37 -2
- package/dist/src/serve.js +111 -2
- package/dist/src/server.js +264 -23
- package/package.json +3 -2
- package/plugins/ansi/README.md +36 -0
- package/plugins/ansi/index.ts +95 -0
- package/plugins/ansi/public/style.css +28 -0
- package/plugins/badge/README.md +28 -0
- package/plugins/badge/index.ts +35 -0
- package/plugins/badge/public/style.css +30 -0
- package/plugins/chat/public/style.css +7 -2
- package/plugins/code/README.md +4 -2
- package/plugins/code/diff.ts +14 -2
- package/plugins/code/index.ts +3 -1
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- package/plugins/grid/README.md +12 -12
- package/plugins/grid/index.ts +11 -26
- package/plugins/grid/public/style.css +4 -33
- package/plugins/iframe/README.md +7 -7
- package/plugins/iframe/index.ts +15 -15
- package/plugins/iframe/public/style.css +15 -0
- package/plugins/index.ts +10 -2
- package/plugins/lightbox/README.md +22 -0
- package/plugins/lightbox/client.ts +99 -0
- package/plugins/lightbox/index.ts +25 -0
- package/plugins/lightbox/public/style.css +66 -0
- package/plugins/mermaid/index.ts +4 -2
- package/plugins/steps/README.md +42 -0
- package/plugins/steps/client.ts +75 -0
- package/plugins/steps/index.ts +84 -0
- package/plugins/steps/public/style.css +77 -0
- package/plugins/terminal/client.ts +16 -7
- package/plugins/terminal/host.ts +12 -6
- package/plugins/terminal/sizes.ts +3 -1
- package/plugins/toc/README.md +21 -3
- package/plugins/toc/client.ts +47 -6
- package/plugins/toc/index.ts +19 -6
- package/plugins/toc/public/style.css +10 -4
- package/plugins/window/README.md +34 -14
- package/plugins/window/index.ts +20 -13
- package/skills/whiteboard/SKILL.md +18 -10
- package/src/auth.ts +8 -5
- package/src/client/base.ts +19 -0
- package/src/client/forms.ts +2 -1
- package/src/client/markdown.ts +2 -1
- package/src/client/page/base.css +61 -1
- package/src/client/page/elsewhere.ts +72 -16
- package/src/client/page/fresh.ts +2 -1
- package/src/client/page/main.ts +18 -6
- package/src/client/page/sort.ts +2 -1
- package/src/client/runtime.ts +62 -25
- package/src/define.ts +126 -19
- package/src/entries.ts +258 -0
- package/src/events.ts +2 -1
- package/src/hub.ts +355 -0
- package/src/loader.ts +14 -3
- package/src/package.ts +22 -0
- package/src/pages/blocks.ts +3 -0
- package/src/pages/index.ts +6 -4
- package/src/pages/markdown.ts +89 -32
- package/src/pages/render.ts +181 -28
- package/src/pages/window.ts +23 -25
- package/src/running.ts +47 -1
- package/src/serve.ts +114 -1
- package/src/server.ts +332 -26
- package/dist/plugins/gallery/README.md +0 -30
- package/dist/plugins/gallery/index.js +0 -75
- package/dist/plugins/gallery/public/client.js +0 -1
- package/dist/plugins/gallery/public/style.css +0 -90
- package/plugins/gallery/README.md +0 -30
- package/plugins/gallery/client.tsx +0 -70
- package/plugins/gallery/index.ts +0 -89
- package/plugins/gallery/public/style.css +0 -90
package/src/package.ts
CHANGED
|
@@ -38,3 +38,25 @@ export const FROM_SOURCE = fileURLToPath(import.meta.url).endsWith('.ts')
|
|
|
38
38
|
*/
|
|
39
39
|
/** A built-in plugin's public folder: its built browser modules and copied styles (build.ts). */
|
|
40
40
|
export const builtinPublic = (name: string): string => packagePath('dist', 'plugins', name, 'public')
|
|
41
|
+
|
|
42
|
+
/** This package's version, from its package.json: what a shared server records, and its takeover compares. */
|
|
43
|
+
export const VERSION: string = JSON.parse(fs.readFileSync(path.join(PACKAGE_DIR, 'package.json'), 'utf8')).version
|
|
44
|
+
|
|
45
|
+
/** Compare two versions, x.y.z with an optional -pre: < 0 when a is older, 0 when the same, > 0 when newer. */
|
|
46
|
+
export function compareVersions(a: string, b: string): number {
|
|
47
|
+
const parse = (v: string) => {
|
|
48
|
+
const [main, pre] = String(v).split('-', 2)
|
|
49
|
+
return { nums: main!.split('.').map(n => Number(n) || 0), pre: pre ?? null }
|
|
50
|
+
}
|
|
51
|
+
const x = parse(a)
|
|
52
|
+
const y = parse(b)
|
|
53
|
+
for (let i = 0; i < Math.max(x.nums.length, y.nums.length); i++) {
|
|
54
|
+
const d = (x.nums[i] ?? 0) - (y.nums[i] ?? 0)
|
|
55
|
+
if (d) return Math.sign(d)
|
|
56
|
+
}
|
|
57
|
+
// a release is newer than its pre-releases
|
|
58
|
+
if (x.pre === y.pre) return 0
|
|
59
|
+
if (x.pre == null) return 1
|
|
60
|
+
if (y.pre == null) return -1
|
|
61
|
+
return x.pre < y.pre ? -1 : 1
|
|
62
|
+
}
|
package/src/pages/blocks.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface ResolvedBlock {
|
|
|
26
26
|
fences: boolean
|
|
27
27
|
props: ((ctx: any) => unknown) | null
|
|
28
28
|
html: ((ctx: any) => string | Html | null | Promise<string | Html | null>) | null
|
|
29
|
+
/** what it shows on its own, for the ↗ of a window around it (Block.open) */
|
|
30
|
+
open: ((ctx: any) => string | null) | null
|
|
29
31
|
client: string | null
|
|
30
32
|
style: string | null
|
|
31
33
|
/** the plugin it comes from */
|
|
@@ -54,6 +56,7 @@ function normalize({ name, block: b, plugin, public: dir }: BlockEntry): Resolve
|
|
|
54
56
|
fences: b.fence === true || b.fence === 'any',
|
|
55
57
|
props: typeof b.props === 'function' ? b.props.bind(b) : null,
|
|
56
58
|
html: typeof b.html === 'function' ? b.html.bind(b) : null,
|
|
59
|
+
open: typeof b.open === 'function' ? b.open.bind(b) : null,
|
|
57
60
|
...files,
|
|
58
61
|
source: plugin,
|
|
59
62
|
}
|
package/src/pages/index.ts
CHANGED
|
@@ -5,17 +5,19 @@ import { resolveBlocks, type BlockEntry } from './blocks.ts'
|
|
|
5
5
|
import { createDocs, createMessageRender, createRender } from './render.ts'
|
|
6
6
|
import { formNames } from './markdown.ts'
|
|
7
7
|
import type { PageSource, RenderContext, Rendered, StoredPage } from '../define.ts'
|
|
8
|
-
import type { TextLink } from '../define.ts'
|
|
8
|
+
import type { Plugin, TextLink } from '../define.ts'
|
|
9
9
|
|
|
10
10
|
export interface PagesOptions {
|
|
11
11
|
/** the blocks of the project's plugins, in plugin order */
|
|
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?:
|
|
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
|
+
/** the plugins that compose themselves around blocks (Plugin.compose), by name */
|
|
20
|
+
composers?: Map<string, NonNullable<Plugin['compose']>>
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
/** How the core renders pages for one loaded config. */
|
|
@@ -34,7 +36,7 @@ export function createPages(options: PagesOptions): Pages {
|
|
|
34
36
|
const resolved = resolveBlocks(options.blocks)
|
|
35
37
|
const blocks = () => resolved
|
|
36
38
|
return {
|
|
37
|
-
render: createRender(blocks, options.style, options.styles ?? [], options.links ?? []),
|
|
39
|
+
render: createRender(blocks, options.style, options.styles ?? [], options.links ?? [], options.composers),
|
|
38
40
|
message: createMessageRender(blocks, options.links ?? []),
|
|
39
41
|
docs: createDocs(blocks),
|
|
40
42
|
questions: page => formNames(page.source),
|
package/src/pages/markdown.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { toString } from 'mdast-util-to-string'
|
|
|
16
16
|
import { html, raw, type Html } from '../html.ts'
|
|
17
17
|
import { isQuestionName } from '../status.ts'
|
|
18
18
|
import type { ResolvedBlock } from './blocks.ts'
|
|
19
|
-
import type { TextLink } from '../define.ts'
|
|
19
|
+
import type { Plugin, TextLink } from '../define.ts'
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* An mdast node, loosely: the pipeline hands nodes between remark, the directive plugin and
|
|
@@ -88,14 +88,25 @@ const toHast = unified()
|
|
|
88
88
|
.use(rehypeStringify, { allowDangerousHtml: true })
|
|
89
89
|
.freeze()
|
|
90
90
|
|
|
91
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* `cols=3 open title="a b"` → { cols: '3', open: '', title: 'a b' } (bare words get '' like directive
|
|
93
|
+
* attrs). In braces too, as a fence writes them: `{compose=window}` (an unquoted value ends at `}`).
|
|
94
|
+
*/
|
|
92
95
|
export function parseAttrs(s: unknown) {
|
|
93
96
|
const out: Record<string, string> = {}
|
|
94
|
-
for (const m of String(s ?? '').matchAll(/([\w-]+)(?:=("[^"]*"|'[^']*'
|
|
97
|
+
for (const m of String(s ?? '').matchAll(/([\w-]+)(?:=("[^"]*"|'[^']*'|[^\s}]+))?/g))
|
|
95
98
|
out[m[1]] = m[2] ? m[2].replace(/^["']|["']$/g, '') : ''
|
|
96
99
|
return out
|
|
97
100
|
}
|
|
98
101
|
|
|
102
|
+
/** A heading's text as a key: lowercase, words joined by - */
|
|
103
|
+
const slugOf = (text: string) =>
|
|
104
|
+
text
|
|
105
|
+
.toLowerCase()
|
|
106
|
+
.trim()
|
|
107
|
+
.replace(/[^\p{L}\p{N}]+/gu, '-')
|
|
108
|
+
.replace(/^-|-$/g, '')
|
|
109
|
+
|
|
99
110
|
const DIRECTIVES = new Set(['containerDirective', 'leafDirective', 'textDirective'])
|
|
100
111
|
const PHRASING = new Set([
|
|
101
112
|
'text',
|
|
@@ -250,6 +261,8 @@ export interface RenderOptions {
|
|
|
250
261
|
* written (no buttons or forms in a message); code fences and text links work as on a page
|
|
251
262
|
*/
|
|
252
263
|
message?: boolean
|
|
264
|
+
/** the plugins that compose themselves around blocks (Plugin.compose), by name: a block names them in `compose` */
|
|
265
|
+
composers?: Map<string, NonNullable<Plugin['compose']>>
|
|
253
266
|
}
|
|
254
267
|
|
|
255
268
|
export interface Island {
|
|
@@ -265,7 +278,7 @@ export interface Island {
|
|
|
265
278
|
*/
|
|
266
279
|
export async function renderMarkdown(
|
|
267
280
|
source: string | MdNode,
|
|
268
|
-
{ page, file, resolve, code = null, linkFor, textLinks = [], message = false }: RenderOptions,
|
|
281
|
+
{ page, file, resolve, code = null, linkFor, textLinks = [], message = false, composers }: RenderOptions,
|
|
269
282
|
) {
|
|
270
283
|
let nextId = 0
|
|
271
284
|
const islands: Record<string, Island> = {}
|
|
@@ -289,41 +302,85 @@ export async function renderMarkdown(
|
|
|
289
302
|
return stringify(nodes)
|
|
290
303
|
}
|
|
291
304
|
|
|
292
|
-
|
|
305
|
+
/**
|
|
306
|
+
* A block's items (DirectiveContext.items): a heading at the block's shallowest heading level, or a
|
|
307
|
+
* `---`, starts one; what comes before the first is one too, untitled; content with neither is one
|
|
308
|
+
* item. Deeper headings stay inside their item. An untitled item with nothing in it (a `---` right
|
|
309
|
+
* before a heading) is none.
|
|
310
|
+
*/
|
|
311
|
+
async function itemsOf(children: MdNode[]) {
|
|
293
312
|
await transform({ type: 'root', children })
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
313
|
+
const content = children.filter(n => !(n.type === 'text' && !String(n.value ?? '').trim()))
|
|
314
|
+
const heads = content.filter(n => n.type === 'heading')
|
|
315
|
+
const depth = heads.length ? Math.min(...heads.map(h => h.depth)) : null
|
|
316
|
+
const groups: { heading: MdNode | null; body: MdNode[] }[] = []
|
|
317
|
+
let current: { heading: MdNode | null; body: MdNode[] } | null = null
|
|
318
|
+
for (const n of content) {
|
|
319
|
+
if (n.type === 'heading' && n.depth === depth) groups.push((current = { heading: n, body: [] }))
|
|
320
|
+
else if (n.type === 'thematicBreak') groups.push((current = { heading: null, body: [] }))
|
|
321
|
+
else {
|
|
322
|
+
if (!current) groups.push((current = { heading: null, body: [] }))
|
|
323
|
+
current.body.push(n)
|
|
299
324
|
}
|
|
300
325
|
}
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
html: stringify(s.body),
|
|
318
|
-
})),
|
|
319
|
-
}
|
|
326
|
+
const taken = new Map<string, number>()
|
|
327
|
+
return groups
|
|
328
|
+
.filter(g => g.heading || g.body.length)
|
|
329
|
+
.map((g, i) => {
|
|
330
|
+
const text = g.heading ? toString(g.heading as any) : null
|
|
331
|
+
const base = (text && slugOf(text)) || String(i + 1)
|
|
332
|
+
const n = (taken.get(base) ?? 0) + 1
|
|
333
|
+
taken.set(base, n)
|
|
334
|
+
return {
|
|
335
|
+
title: g.heading ? stringify(g.heading.children ?? []) : null,
|
|
336
|
+
text,
|
|
337
|
+
html: stringify(g.body),
|
|
338
|
+
nodes: g.body,
|
|
339
|
+
key: n > 1 ? `${base}-${n}` : base,
|
|
340
|
+
}
|
|
341
|
+
})
|
|
320
342
|
}
|
|
321
343
|
|
|
322
344
|
/** HTML into the markdown tree, where the rest of the pipeline takes it as it is: the one place it becomes a string. */
|
|
323
345
|
const htmlNode = (markup: Html | string): MdNode => ({ type: 'html', value: String(markup) })
|
|
324
346
|
|
|
325
|
-
/**
|
|
347
|
+
/**
|
|
348
|
+
* A block's output for one directive or fence: static HTML, or an island around it; then put in
|
|
349
|
+
* what the plugins its `compose` attribute names compose around it (Plugin.compose), in the order
|
|
350
|
+
* written, the first innermost: `{compose=lightbox,window}`. A name no plugin composes is said in
|
|
351
|
+
* place. Not inline blocks, not a block of the composing plugin's own name, not one that renders
|
|
352
|
+
* nothing (left out of a build), and not one that says what's wrong with it instead.
|
|
353
|
+
*/
|
|
326
354
|
async function run(block: ResolvedBlock, ctx: any, fallback: () => Promise<Html | string>): Promise<Html> {
|
|
355
|
+
let out = await output(block, ctx, fallback)
|
|
356
|
+
const attrs: Record<string, string> = ctx.attrs ?? {}
|
|
357
|
+
const names = String(attrs.compose ?? '')
|
|
358
|
+
.split(/[\s,]+/)
|
|
359
|
+
.filter(Boolean)
|
|
360
|
+
const shown = String(out).trim()
|
|
361
|
+
if (!names.length || ctx.kind === 'textDirective' || !shown || shown.startsWith('<pre class="wb-error"')) return out
|
|
362
|
+
let open: string | null | undefined
|
|
363
|
+
for (const name of names) {
|
|
364
|
+
if (block.name === name) continue
|
|
365
|
+
const compose = composers?.get(name)
|
|
366
|
+
if (!compose) {
|
|
367
|
+
out = html`<pre class="wb-error">compose: no plugin named "${name}" composes around blocks</pre>
|
|
368
|
+
${out}`
|
|
369
|
+
continue
|
|
370
|
+
}
|
|
371
|
+
try {
|
|
372
|
+
open ??= block.open?.(ctx) ?? null
|
|
373
|
+
out = raw(String(await compose({ children: out, block: block.name, attrs, label: ctx.label ?? null, open })))
|
|
374
|
+
} catch (err) {
|
|
375
|
+
console.error(`plugin ${name}: compose:`, err)
|
|
376
|
+
out = html`<pre class="wb-error">
|
|
377
|
+
plugin "${name}" failed to compose around block "${block.name}": ${(err as Error).message}</pre>`
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return out
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
async function output(block: ResolvedBlock, ctx: any, fallback: () => Promise<Html | string>): Promise<Html> {
|
|
327
384
|
used.set(block.name, block)
|
|
328
385
|
try {
|
|
329
386
|
// a block may return a string or an `html` result: either is HTML
|
|
@@ -382,7 +439,7 @@ export async function renderMarkdown(
|
|
|
382
439
|
labelText: label ? toString({ type: 'root', children: label } as any) : null,
|
|
383
440
|
children,
|
|
384
441
|
node,
|
|
385
|
-
|
|
442
|
+
items: () => itemsOf(children),
|
|
386
443
|
defaults: () =>
|
|
387
444
|
(defaults ??= (async () => {
|
|
388
445
|
const content = await toHtml(children)
|
|
@@ -391,7 +448,7 @@ export async function renderMarkdown(
|
|
|
391
448
|
attrs: { ...node.attributes },
|
|
392
449
|
label: labelHtml,
|
|
393
450
|
html: content,
|
|
394
|
-
|
|
451
|
+
items: (await itemsOf(children)).map(({ nodes: _, ...item }) => item),
|
|
395
452
|
}
|
|
396
453
|
})()),
|
|
397
454
|
}
|
package/src/pages/render.ts
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
// code, folders as listings with their README on top; around all of it goes the page's frame.
|
|
4
4
|
// What the page draws itself is built with `html` (../html.ts), which escapes every value.
|
|
5
5
|
import fs from 'node:fs'
|
|
6
|
+
import os from 'node:os'
|
|
6
7
|
import path from 'node:path'
|
|
7
8
|
import { fileURLToPath } from 'node:url'
|
|
8
9
|
import { execFileSync } from 'node:child_process'
|
|
9
10
|
import { renderMarkdown, type Island, type MdNode } from './markdown.ts'
|
|
10
11
|
import { html, raw, type Html } from '../html.ts'
|
|
11
12
|
import { INBOX_ICON, awaitingLabel } from '../icons.ts'
|
|
12
|
-
import type { RenderContext, Rendered, StoredPage, TextLink } from '../define.ts'
|
|
13
|
+
import type { Plugin, RenderContext, Rendered, StoredPage, TextLink } from '../define.ts'
|
|
13
14
|
import type { ResolvedBlock, ResolvedBlocks } from './blocks.ts'
|
|
14
15
|
|
|
15
16
|
type PagesPage = Extract<StoredPage, { kind: 'pages' }>
|
|
@@ -63,24 +64,26 @@ export function titleOf(file: string, fallback: string) {
|
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
function crumbs(id: string, name: string) {
|
|
67
|
+
function crumbs(id: string, name: string, base: string, entry?: RenderContext['entry']) {
|
|
67
68
|
const parts = id ? id.split('/') : []
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
// under a shared server, the overview of every project comes first, by its own name
|
|
70
|
+
const above = entry ? html`<a href="/">whiteboard</a> / ` : ''
|
|
71
|
+
return html`${above}<a href="${base}/">${name}</a
|
|
72
|
+
>${parts.map((p, i) => html` / <a href="${base}/${parts.slice(0, i + 1).join('/')}">${p}</a>`)}`
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
const time = (ts: number) => html`<time data-ts="${ts}"></time>`
|
|
73
76
|
|
|
74
|
-
function pageList(pages: PagesPage['pages']) {
|
|
77
|
+
function pageList(pages: PagesPage['pages'], base: string) {
|
|
75
78
|
return html`<ul class="wb-index">
|
|
76
79
|
${pages.map(
|
|
77
80
|
p =>
|
|
78
81
|
html`<li>
|
|
79
|
-
<a href="/${p.id}">${titleOf(p.file, path.basename(p.id))}</a>${
|
|
82
|
+
<a href="${base}/${p.id}">${titleOf(p.file, path.basename(p.id))}</a>${
|
|
80
83
|
p.awaiting > 0 &&
|
|
81
84
|
html` <a
|
|
82
85
|
class="wb-awaiting"
|
|
83
|
-
href="/${p.id}#wb-waiting"
|
|
86
|
+
href="${base}/${p.id}#wb-waiting"
|
|
84
87
|
title="${awaitingLabel(p.awaiting)}"
|
|
85
88
|
aria-label="${awaitingLabel(p.awaiting)}"
|
|
86
89
|
>${raw(INBOX_ICON)}${p.awaiting}</a
|
|
@@ -149,7 +152,7 @@ function documentsIn(dir: string) {
|
|
|
149
152
|
walk('')
|
|
150
153
|
}
|
|
151
154
|
const depth = (f: string) => f.split('/').length
|
|
152
|
-
return [...new Set(files)].
|
|
155
|
+
return [...new Set(files)].toSorted((a, b) => depth(a) - depth(b) || a.localeCompare(b))
|
|
153
156
|
}
|
|
154
157
|
|
|
155
158
|
/**
|
|
@@ -158,8 +161,81 @@ function documentsIn(dir: string) {
|
|
|
158
161
|
* written here), by when last updated, or by title; each row carries what it is sorted by.
|
|
159
162
|
*/
|
|
160
163
|
function documentList(ctx: RenderContext) {
|
|
161
|
-
|
|
164
|
+
return documentsOf(ctx.project.dir, ctx.base ?? '', ctx.urlFor)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* A project's documents by the folder they are in, each folder a fold with how many it holds, the
|
|
169
|
+
* top folder's own documents first: the shared server's overview, where a repository's many
|
|
170
|
+
* documents would otherwise be one long list. A folder holding only one folder is shown as one
|
|
171
|
+
* (`docs/adr/`), so the tree is no deeper than what tells folders apart.
|
|
172
|
+
*/
|
|
173
|
+
function documentTree(files: string[], dir: string, base: string, urlFor: (abs: string) => string | null) {
|
|
174
|
+
interface Folder {
|
|
175
|
+
files: string[]
|
|
176
|
+
folders: Map<string, Folder>
|
|
177
|
+
count: number
|
|
178
|
+
}
|
|
179
|
+
const root: Folder = { files: [], folders: new Map(), count: 0 }
|
|
180
|
+
for (const f of files) {
|
|
181
|
+
let at = root
|
|
182
|
+
at.count++
|
|
183
|
+
const parts = f.split('/')
|
|
184
|
+
for (const part of parts.slice(0, -1)) {
|
|
185
|
+
if (!at.folders.has(part)) at.folders.set(part, { files: [], folders: new Map(), count: 0 })
|
|
186
|
+
at = at.folders.get(part)!
|
|
187
|
+
at.count++
|
|
188
|
+
}
|
|
189
|
+
at.files.push(f)
|
|
190
|
+
}
|
|
191
|
+
const row = (f: string) => {
|
|
192
|
+
const abs = path.join(dir, f)
|
|
193
|
+
const name = path.posix.basename(f)
|
|
194
|
+
const title = titleOf(abs, name)
|
|
195
|
+
let mtime = 0
|
|
196
|
+
try {
|
|
197
|
+
mtime = fs.statSync(abs).mtimeMs
|
|
198
|
+
} catch {
|
|
199
|
+
/* gone meanwhile */
|
|
200
|
+
}
|
|
201
|
+
return html`<li>
|
|
202
|
+
<a href="${urlFor(abs) ?? `${base}/-/${f}`}">${title}</a>
|
|
203
|
+
<span class="wb-meta">${title !== name && html`<code>${name}</code> · `}edited ${time(mtime)}</span>
|
|
204
|
+
</li>`
|
|
205
|
+
}
|
|
206
|
+
const folder = (name: string, f: Folder): Html => {
|
|
207
|
+
// a folder with only one folder in it is shown as one
|
|
208
|
+
while (!f.files.length && f.folders.size === 1) {
|
|
209
|
+
const [inner, next] = [...f.folders][0]!
|
|
210
|
+
name = `${name}/${inner}`
|
|
211
|
+
f = next
|
|
212
|
+
}
|
|
213
|
+
return html`<details class="wb-folder">
|
|
214
|
+
<summary>${name}/ <span class="wb-meta">${f.count}</span></summary>
|
|
215
|
+
${contents(f)}
|
|
216
|
+
</details>`
|
|
217
|
+
}
|
|
218
|
+
const contents = (f: Folder): Html =>
|
|
219
|
+
html`${
|
|
220
|
+
f.files.length > 0 &&
|
|
221
|
+
html`<ul class="wb-index">
|
|
222
|
+
${f.files.map(row)}
|
|
223
|
+
</ul>`
|
|
224
|
+
}${[...f.folders].toSorted(([a], [b]) => a.localeCompare(b)).map(([name, sub]) => folder(name, sub))}`
|
|
225
|
+
return html`<details class="wb-documents wb-folded-documents">
|
|
226
|
+
<summary>Files <span class="wb-meta">${files.length}</span></summary>
|
|
227
|
+
${contents(root)}
|
|
228
|
+
</details>`
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* A project's documents, as its overview lists them: from its folder, linked where it serves them.
|
|
233
|
+
* `folded`: in a fold that says how many (the shared server's overview, where each project has them).
|
|
234
|
+
*/
|
|
235
|
+
function documentsOf(dir: string, base: string, urlFor: (abs: string) => string | null, folded = false) {
|
|
236
|
+
const files = documentsIn(dir)
|
|
162
237
|
if (!files.length) return ''
|
|
238
|
+
const ctx = { project: { dir }, base, urlFor }
|
|
163
239
|
const rows = files.map((f, i) => {
|
|
164
240
|
const abs = path.join(ctx.project.dir, f)
|
|
165
241
|
// a file without a heading goes by its name, and the line under it says the folder it is in
|
|
@@ -173,12 +249,13 @@ function documentList(ctx: RenderContext) {
|
|
|
173
249
|
/* gone meanwhile */
|
|
174
250
|
}
|
|
175
251
|
return html`<li data-order="${i}" data-updated="${mtime}" data-title="${title.toLowerCase()}">
|
|
176
|
-
<a href="${ctx.urlFor(abs) ??
|
|
252
|
+
<a href="${ctx.urlFor(abs) ?? `${ctx.base ?? ''}/-/${f}`}">${title}</a>
|
|
177
253
|
<span class="wb-meta"
|
|
178
254
|
>${where !== '.' && html`<code>${where === f ? f : `${where}/`}</code> · `}edited ${time(mtime)}</span
|
|
179
255
|
>
|
|
180
256
|
</li>`
|
|
181
257
|
})
|
|
258
|
+
if (folded) return documentTree(files, dir, base, urlFor)
|
|
182
259
|
// in a section, so the heading isn't numbered like the page's own sections
|
|
183
260
|
return html`<section class="wb-documents">
|
|
184
261
|
<div class="wb-list-head">
|
|
@@ -240,24 +317,53 @@ export function createMessageRender(
|
|
|
240
317
|
}
|
|
241
318
|
}
|
|
242
319
|
|
|
320
|
+
/** What a block left out of a build (RenderContext.skip) is: nothing, for its directives and fences alike. */
|
|
321
|
+
const skipped = (name: string): ResolvedBlock => ({
|
|
322
|
+
name,
|
|
323
|
+
code: false,
|
|
324
|
+
fences: true,
|
|
325
|
+
props: null,
|
|
326
|
+
html: () => '',
|
|
327
|
+
open: null,
|
|
328
|
+
client: null,
|
|
329
|
+
style: null,
|
|
330
|
+
source: 'build',
|
|
331
|
+
})
|
|
332
|
+
|
|
243
333
|
export function createRender(
|
|
244
334
|
blocks: () => ResolvedBlocks,
|
|
245
335
|
style?: URL | string,
|
|
246
|
-
pluginStyles:
|
|
336
|
+
pluginStyles: { plugin: string; file: URL | string }[] = [],
|
|
247
337
|
links: ((ctx: { dir: string }) => TextLink[])[] = [],
|
|
338
|
+
composers: Map<string, NonNullable<Plugin['compose']>> = new Map(),
|
|
248
339
|
) {
|
|
249
340
|
const textLinks = textLinksOf(links)
|
|
250
341
|
const STYLE = stylePath(style)
|
|
251
|
-
const PLUGIN_STYLES = pluginStyles
|
|
342
|
+
const PLUGIN_STYLES = pluginStyles
|
|
343
|
+
.map(s => ({ plugin: s.plugin, file: stylePath(s.file) }))
|
|
344
|
+
.filter((s): s is { plugin: string; file: string } => !!s.file)
|
|
252
345
|
async function markdown(source: string, page: string, file: string, ctx: RenderContext) {
|
|
253
346
|
const { blocks: set, code } = blocks()
|
|
347
|
+
const skip = ctx.skip
|
|
254
348
|
return renderMarkdown(body(source), {
|
|
255
349
|
page,
|
|
256
350
|
file,
|
|
257
|
-
resolve: name =>
|
|
351
|
+
resolve: name => {
|
|
352
|
+
const block = set.get(name) ?? null
|
|
353
|
+
if (skip && (skip.has(name) || (block && skip.has(block.source)))) return skipped(name)
|
|
354
|
+
return block
|
|
355
|
+
},
|
|
258
356
|
code,
|
|
259
357
|
linkFor: ctx.urlFor,
|
|
260
358
|
textLinks: textLinks(ctx.project.dir),
|
|
359
|
+
// a build leaves out a skipped plugin's composing too: the block as it is
|
|
360
|
+
composers: skip
|
|
361
|
+
? new Map(
|
|
362
|
+
[...composers].map(([name, compose]) =>
|
|
363
|
+
skip.has(name) ? [name, ({ children }: { children: unknown }) => String(children)] : [name, compose],
|
|
364
|
+
),
|
|
365
|
+
)
|
|
366
|
+
: composers,
|
|
261
367
|
})
|
|
262
368
|
}
|
|
263
369
|
|
|
@@ -267,7 +373,41 @@ export function createRender(
|
|
|
267
373
|
case 'page':
|
|
268
374
|
return markdown(page.source, page.id, page.file, ctx)
|
|
269
375
|
case 'pages': {
|
|
270
|
-
|
|
376
|
+
// the shared server's overview: every project's pages, by project, the projects with
|
|
377
|
+
// something waiting first, and in each the pages waiting first
|
|
378
|
+
if (page.groups) {
|
|
379
|
+
const waiting = (ps: PagesPage['pages']) => ps.reduce((n, p) => n + p.awaiting, 0)
|
|
380
|
+
const first = (ps: PagesPage['pages']) =>
|
|
381
|
+
ps.toSorted((a, b) => Number(b.awaiting > 0) - Number(a.awaiting > 0))
|
|
382
|
+
const groups = page.groups.toSorted((a, b) => Number(waiting(b.pages) > 0) - Number(waiting(a.pages) > 0))
|
|
383
|
+
const view = html`<h1>${project.name}</h1>
|
|
384
|
+
${groups.map(
|
|
385
|
+
g =>
|
|
386
|
+
html`<section class="wb-project">
|
|
387
|
+
<h2>${g.title}</h2>
|
|
388
|
+
<p class="wb-meta">
|
|
389
|
+
<code>${g.dir.replace(os.homedir(), '~')}</code>
|
|
390
|
+
</p>
|
|
391
|
+
${pageList(first(g.pages), g.base)} ${g.files && documentsOf(g.dir, g.base, () => null, true)}
|
|
392
|
+
</section>`,
|
|
393
|
+
)}
|
|
394
|
+
${!groups.length && html`<p class="wb-meta">No pages yet.</p>`}
|
|
395
|
+
${
|
|
396
|
+
page.empty?.length
|
|
397
|
+
? html`<details class="wb-empty-projects">
|
|
398
|
+
<summary>${page.empty.length} without pages</summary>
|
|
399
|
+
<ul>
|
|
400
|
+
${page.empty.map(e => html`<li><a href="${e.base}/">${e.title}</a></li>`)}
|
|
401
|
+
</ul>
|
|
402
|
+
</details>`
|
|
403
|
+
: ''
|
|
404
|
+
}
|
|
405
|
+
${page.note && html`<p class="wb-meta">${page.note}</p>`}`
|
|
406
|
+
return { html: view, title: project.name, islands: {}, styles: [] }
|
|
407
|
+
}
|
|
408
|
+
const list = page.pages.length
|
|
409
|
+
? pageList(page.pages, ctx.base ?? '')
|
|
410
|
+
: html`<p class="wb-meta">No pages yet.</p>`
|
|
271
411
|
const view = page.id
|
|
272
412
|
? html`<h1>${page.id}</h1>
|
|
273
413
|
${list}
|
|
@@ -275,8 +415,8 @@ export function createRender(
|
|
|
275
415
|
: html`<h1>${project.name}</h1>
|
|
276
416
|
${list}${project.files && documentList(ctx)}
|
|
277
417
|
<p class="wb-meta">
|
|
278
|
-
<code>${project.dir}</code>${project.files && html` · <a href="/-/">files</a>`} ·
|
|
279
|
-
<a href="/_/docs">how to write pages</a>
|
|
418
|
+
<code>${project.dir}</code>${project.files && html` · <a href="${ctx.base ?? ''}/-/">files</a>`} ·
|
|
419
|
+
<a href="${ctx.base ?? ''}/_/docs">how to write pages</a>
|
|
280
420
|
</p>`
|
|
281
421
|
return { html: view, title: page.id || project.name, islands: {}, styles: [] }
|
|
282
422
|
}
|
|
@@ -338,20 +478,33 @@ export function createRender(
|
|
|
338
478
|
Object.entries(out.islands).map(([id, island]) => [id, { ...island, client: ctx.asset(island.client) }]),
|
|
339
479
|
)
|
|
340
480
|
const styles = out.styles.map(s => ctx.asset(s))
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
class="wb-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
481
|
+
// a built page: the project's name and the theme; nothing of the server's (crumbs into its
|
|
482
|
+
// folders, when it was updated, whether it is live)
|
|
483
|
+
const nav =
|
|
484
|
+
ctx.live === false
|
|
485
|
+
? html`<nav class="wb-nav">
|
|
486
|
+
<span>${ctx.project.name}</span
|
|
487
|
+
><button
|
|
488
|
+
type="button"
|
|
489
|
+
class="wb-theme"
|
|
490
|
+
title="Theme: follow the system, light or dark"
|
|
491
|
+
aria-label="Theme"
|
|
492
|
+
></button>
|
|
493
|
+
</nav>`
|
|
494
|
+
: html`<nav class="wb-nav">
|
|
495
|
+
<span>${crumbs(page.id, ctx.entry?.label || ctx.project.name, ctx.base ?? '', ctx.entry)}</span
|
|
496
|
+
>${page.mtime != null && html`<span class="wb-meta">updated <time id="wb-updated" data-ts="${page.mtime}"></time></span>`}<button
|
|
497
|
+
type="button"
|
|
498
|
+
class="wb-theme"
|
|
499
|
+
title="Theme: follow the system, light or dark"
|
|
500
|
+
aria-label="Theme"
|
|
501
|
+
></button
|
|
502
|
+
><span class="wb-live" role="img" title="Connecting…" aria-label="Connecting…"></span>
|
|
503
|
+
</nav>`
|
|
351
504
|
// the page's own, the plugins' (every page), the blocks' on this page, then the project's
|
|
352
505
|
const links = [
|
|
353
506
|
ctx.asset(BASE_CSS),
|
|
354
|
-
...PLUGIN_STYLES.map(
|
|
507
|
+
...PLUGIN_STYLES.filter(s => !ctx.skip?.has(s.plugin)).map(s => ctx.asset(s.file)),
|
|
355
508
|
...styles,
|
|
356
509
|
...(STYLE ? [ctx.asset(STYLE)] : []),
|
|
357
510
|
]
|
|
@@ -380,7 +533,7 @@ export function createDocs(blocks: () => ResolvedBlocks) {
|
|
|
380
533
|
t.code ? `${t.name} (every other code fence)` : t.name,
|
|
381
534
|
])
|
|
382
535
|
const list = [...byPlugin]
|
|
383
|
-
.
|
|
536
|
+
.toSorted(([a], [b]) => a.localeCompare(b))
|
|
384
537
|
.map(([plugin, blocks]) => `- **${plugin}**: ${blocks.map(b => `\`${b}\``).join(', ')}`)
|
|
385
538
|
return `# Pages
|
|
386
539
|
|
package/src/pages/window.ts
CHANGED
|
@@ -24,11 +24,12 @@ export interface WindowOptions {
|
|
|
24
24
|
open?: string | null
|
|
25
25
|
/** wider than the text column */
|
|
26
26
|
wide?: boolean
|
|
27
|
-
/**
|
|
28
|
-
bare?: boolean
|
|
29
|
-
/** a class for its body, and a height for it (a CSS length), for what has none of its own (an iframe) */
|
|
30
|
-
bodyClass?: string
|
|
27
|
+
/** a height for its body (a CSS length); what's taller scrolls */
|
|
31
28
|
height?: string
|
|
29
|
+
/** a class for the window itself, for a block's styles and browser code to find it by */
|
|
30
|
+
className?: string
|
|
31
|
+
/** more in the header, after the label: a block's own controls (the steps' ‹ › ) */
|
|
32
|
+
controls?: Html | string
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
/** A window around a block's HTML: see the top of this file. */
|
|
@@ -37,9 +38,9 @@ export function windowFrame({
|
|
|
37
38
|
label = null,
|
|
38
39
|
open = null,
|
|
39
40
|
wide = false,
|
|
40
|
-
bare = false,
|
|
41
|
-
bodyClass = '',
|
|
42
41
|
height,
|
|
42
|
+
className = '',
|
|
43
|
+
controls = '',
|
|
43
44
|
}: WindowOptions): Html {
|
|
44
45
|
const name =
|
|
45
46
|
label != null && String(label) !== ''
|
|
@@ -47,25 +48,22 @@ export function windowFrame({
|
|
|
47
48
|
: open
|
|
48
49
|
? html`<span class="wb-window-address">${open}</span>`
|
|
49
50
|
: html``
|
|
50
|
-
const header =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return html`<div class="wb-window${wide && raw(' wb-wide')}">
|
|
51
|
+
const header = html`<div class="wb-window-bar">
|
|
52
|
+
<span class="wb-window-name" ${open ? html` title="${open}"` : ''}>${name}</span>
|
|
53
|
+
${raw(String(controls))}
|
|
54
|
+
${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
|
+
<button
|
|
56
|
+
type="button"
|
|
57
|
+
class="wb-window-button"
|
|
58
|
+
data-wb-maximize
|
|
59
|
+
title="Fill the window"
|
|
60
|
+
aria-label="Fill the window"
|
|
61
|
+
>
|
|
62
|
+
<span class="wb-window-max">${MAXIMIZE}</span><span class="wb-window-restore">${RESTORE}</span>
|
|
63
|
+
</button>
|
|
64
|
+
</div>`
|
|
65
|
+
return html`<div class="wb-window${wide && raw(' wb-wide')}${className && raw(' ' + className)}">
|
|
66
66
|
${header}
|
|
67
|
-
<div class="wb-window-body
|
|
68
|
-
${raw(String(body))}
|
|
69
|
-
</div>
|
|
67
|
+
<div class="wb-window-body" ${height ? html` style="height: ${height}"` : ''}>${raw(String(body))}</div>
|
|
70
68
|
</div>`
|
|
71
69
|
}
|