@bigmistqke/whiteboard 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -25
- package/bin/whiteboard.ts +299 -16
- package/dist/bin/whiteboard.js +247 -17
- package/dist/client/runtime.js +22 -10
- 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/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 +7 -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 +3 -3
- package/dist/plugins/steps/index.js +3 -42
- package/dist/plugins/steps/public/client.js +1 -1
- package/dist/plugins/terminal/host.js +1 -1
- package/dist/plugins/terminal/public/client.js +1 -1
- package/dist/plugins/window/README.md +34 -14
- package/dist/plugins/window/index.js +21 -13
- package/dist/src/auth.js +4 -3
- package/dist/src/client/page/base.css +61 -1
- package/dist/src/client/page/main.js +60 -14
- 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 +4 -1
- 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 +116 -14
- package/dist/src/pages/window.js +16 -18
- package/dist/src/running.js +37 -2
- package/dist/src/serve.js +111 -2
- package/dist/src/server.js +49 -14
- package/package.json +1 -1
- 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/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 +6 -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/steps/README.md +3 -3
- package/plugins/steps/client.ts +15 -6
- package/plugins/steps/index.ts +3 -46
- package/plugins/terminal/client.ts +16 -7
- 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 +5 -3
- 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/sort.ts +2 -1
- package/src/client/runtime.ts +11 -9
- package/src/define.ts +66 -7
- package/src/entries.ts +258 -0
- package/src/events.ts +2 -1
- package/src/hub.ts +355 -0
- package/src/loader.ts +7 -1
- package/src/package.ts +22 -0
- package/src/pages/blocks.ts +3 -0
- package/src/pages/index.ts +4 -2
- package/src/pages/markdown.ts +89 -32
- package/src/pages/render.ts +134 -13
- package/src/pages/window.ts +16 -25
- package/src/running.ts +47 -1
- package/src/serve.ts +114 -1
- package/src/server.ts +80 -14
- 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/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,7 +5,7 @@ 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 */
|
|
@@ -16,6 +16,8 @@ export interface PagesOptions {
|
|
|
16
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
|
|
@@ -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">
|
|
@@ -247,6 +324,7 @@ const skipped = (name: string): ResolvedBlock => ({
|
|
|
247
324
|
fences: true,
|
|
248
325
|
props: null,
|
|
249
326
|
html: () => '',
|
|
327
|
+
open: null,
|
|
250
328
|
client: null,
|
|
251
329
|
style: null,
|
|
252
330
|
source: 'build',
|
|
@@ -257,6 +335,7 @@ export function createRender(
|
|
|
257
335
|
style?: URL | string,
|
|
258
336
|
pluginStyles: { plugin: string; file: URL | string }[] = [],
|
|
259
337
|
links: ((ctx: { dir: string }) => TextLink[])[] = [],
|
|
338
|
+
composers: Map<string, NonNullable<Plugin['compose']>> = new Map(),
|
|
260
339
|
) {
|
|
261
340
|
const textLinks = textLinksOf(links)
|
|
262
341
|
const STYLE = stylePath(style)
|
|
@@ -277,6 +356,14 @@ export function createRender(
|
|
|
277
356
|
code,
|
|
278
357
|
linkFor: ctx.urlFor,
|
|
279
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,
|
|
280
367
|
})
|
|
281
368
|
}
|
|
282
369
|
|
|
@@ -286,7 +373,41 @@ export function createRender(
|
|
|
286
373
|
case 'page':
|
|
287
374
|
return markdown(page.source, page.id, page.file, ctx)
|
|
288
375
|
case 'pages': {
|
|
289
|
-
|
|
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>`
|
|
290
411
|
const view = page.id
|
|
291
412
|
? html`<h1>${page.id}</h1>
|
|
292
413
|
${list}
|
|
@@ -294,8 +415,8 @@ export function createRender(
|
|
|
294
415
|
: html`<h1>${project.name}</h1>
|
|
295
416
|
${list}${project.files && documentList(ctx)}
|
|
296
417
|
<p class="wb-meta">
|
|
297
|
-
<code>${project.dir}</code>${project.files && html` · <a href="/-/">files</a>`} ·
|
|
298
|
-
<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>
|
|
299
420
|
</p>`
|
|
300
421
|
return { html: view, title: page.id || project.name, islands: {}, styles: [] }
|
|
301
422
|
}
|
|
@@ -371,7 +492,7 @@ export function createRender(
|
|
|
371
492
|
></button>
|
|
372
493
|
</nav>`
|
|
373
494
|
: html`<nav class="wb-nav">
|
|
374
|
-
<span>${crumbs(page.id, ctx.project.name)}</span
|
|
495
|
+
<span>${crumbs(page.id, ctx.entry?.label || ctx.project.name, ctx.base ?? '', ctx.entry)}</span
|
|
375
496
|
>${page.mtime != null && html`<span class="wb-meta">updated <time id="wb-updated" data-ts="${page.mtime}"></time></span>`}<button
|
|
376
497
|
type="button"
|
|
377
498
|
class="wb-theme"
|
package/src/pages/window.ts
CHANGED
|
@@ -24,10 +24,7 @@ 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
|
|
32
29
|
/** a class for the window itself, for a block's styles and browser code to find it by */
|
|
33
30
|
className?: string
|
|
@@ -41,8 +38,6 @@ export function windowFrame({
|
|
|
41
38
|
label = null,
|
|
42
39
|
open = null,
|
|
43
40
|
wide = false,
|
|
44
|
-
bare = false,
|
|
45
|
-
bodyClass = '',
|
|
46
41
|
height,
|
|
47
42
|
className = '',
|
|
48
43
|
controls = '',
|
|
@@ -53,26 +48,22 @@ export function windowFrame({
|
|
|
53
48
|
: open
|
|
54
49
|
? html`<span class="wb-window-address">${open}</span>`
|
|
55
50
|
: html``
|
|
56
|
-
const header =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
</button>
|
|
71
|
-
</div>`
|
|
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>`
|
|
72
65
|
return html`<div class="wb-window${wide && raw(' wb-wide')}${className && raw(' ' + className)}">
|
|
73
66
|
${header}
|
|
74
|
-
<div class="wb-window-body
|
|
75
|
-
${raw(String(body))}
|
|
76
|
-
</div>
|
|
67
|
+
<div class="wb-window-body" ${height ? html` style="height: ${height}"` : ''}>${raw(String(body))}</div>
|
|
77
68
|
</div>`
|
|
78
69
|
}
|
package/src/running.ts
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
import fs from 'node:fs'
|
|
5
5
|
import type { Project } from './config.ts'
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* How long a server may take to say it is there: a loaded machine (many agents, builds) can take
|
|
9
|
+
* seconds, and a server taken for gone is one a command starts again or does without.
|
|
10
|
+
*/
|
|
11
|
+
const HEALTH_TIMEOUT = 5000
|
|
12
|
+
|
|
7
13
|
/** The port the last server of this project recorded, or null. */
|
|
8
14
|
export function recordedPort(project: Project): number | null {
|
|
9
15
|
try {
|
|
@@ -19,10 +25,50 @@ export async function runningServer(project: Project, { except }: { except?: num
|
|
|
19
25
|
if (!port) return null
|
|
20
26
|
const base = `http://localhost:${port}`
|
|
21
27
|
try {
|
|
22
|
-
const res = await fetch(`${base}/api/health`, { signal: AbortSignal.timeout(
|
|
28
|
+
const res = await fetch(`${base}/api/health`, { signal: AbortSignal.timeout(HEALTH_TIMEOUT) })
|
|
23
29
|
const health = res.ok ? await res.json() : null
|
|
24
30
|
return health?.dir === project.dir && health.pid !== except ? base : null
|
|
25
31
|
} catch {
|
|
26
32
|
return null
|
|
27
33
|
}
|
|
28
34
|
}
|
|
35
|
+
|
|
36
|
+
/** The shared server as its health says: where it is, its version, the projects it serves. */
|
|
37
|
+
export interface SharedServer {
|
|
38
|
+
origin: string
|
|
39
|
+
pid: number
|
|
40
|
+
version: string
|
|
41
|
+
projects: { entry: string; dir: string; base: string }[]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The port the shared server recorded in the machine folder, or null. */
|
|
45
|
+
export function recordedSharedPort(file: string): number | null {
|
|
46
|
+
try {
|
|
47
|
+
return Number(JSON.parse(fs.readFileSync(file, 'utf8')).port) || null
|
|
48
|
+
} catch {
|
|
49
|
+
return null
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The machine's running shared server, or null: the port in its record, checked by asking it.
|
|
55
|
+
* `rescan`: have it look for projects first (one just made, say). `except`: a process not to count.
|
|
56
|
+
*/
|
|
57
|
+
export async function sharedServer(
|
|
58
|
+
file: string,
|
|
59
|
+
{ rescan = false, except }: { rescan?: boolean; except?: number } = {},
|
|
60
|
+
): Promise<SharedServer | null> {
|
|
61
|
+
const port = recordedSharedPort(file)
|
|
62
|
+
if (!port) return null
|
|
63
|
+
const origin = `http://localhost:${port}`
|
|
64
|
+
try {
|
|
65
|
+
const res = await fetch(`${origin}/api/health${rescan ? '?rescan' : ''}`, {
|
|
66
|
+
signal: AbortSignal.timeout(HEALTH_TIMEOUT),
|
|
67
|
+
})
|
|
68
|
+
const health = res.ok ? await res.json() : null
|
|
69
|
+
if (!health?.hub || health.pid === except) return null
|
|
70
|
+
return { origin, pid: health.pid, version: String(health.version ?? '0.0.0'), projects: health.projects ?? [] }
|
|
71
|
+
} catch {
|
|
72
|
+
return null
|
|
73
|
+
}
|
|
74
|
+
}
|