@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.
- package/README.md +55 -4
- package/bin/whiteboard.ts +32 -0
- package/dist/bin/whiteboard.js +21 -0
- package/dist/client/runtime.js +44 -13
- 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/index.js +5 -1
- package/dist/plugins/steps/README.md +42 -0
- package/dist/plugins/steps/index.js +99 -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/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/src/auth.js +2 -1
- package/dist/src/client/page/main.js +14 -6
- package/dist/src/loader.js +8 -2
- package/dist/src/pages/render.js +42 -15
- package/dist/src/pages/window.js +3 -2
- package/dist/src/server.js +216 -10
- package/package.json +3 -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/index.ts +4 -0
- package/plugins/mermaid/index.ts +4 -2
- package/plugins/steps/README.md +42 -0
- package/plugins/steps/client.ts +66 -0
- package/plugins/steps/index.ts +127 -0
- package/plugins/steps/public/style.css +77 -0
- 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/src/auth.ts +3 -2
- package/src/client/page/main.ts +18 -6
- package/src/client/runtime.ts +51 -16
- package/src/define.ts +60 -12
- package/src/loader.ts +7 -2
- package/src/pages/index.ts +2 -2
- package/src/pages/render.ts +48 -16
- package/src/pages/window.ts +8 -1
- package/src/server.ts +253 -13
package/README.md
CHANGED
|
@@ -280,6 +280,7 @@ upward with a `.whiteboard/` folder.
|
|
|
280
280
|
| `whiteboard append --page <p> --type <t> [--data <json>]` | add an event to a page's log, such as a reply to a comment |
|
|
281
281
|
| `whiteboard pick <event id>` | record an event as picked up, as `wait` does when it hands one out |
|
|
282
282
|
| `whiteboard status [--page <p>]` | per page: questions without an answer, answers no agent picked up, who is listening |
|
|
283
|
+
| `whiteboard build [globs…] [--out <dir>] [--skip <a,b>]` | pages as a static site (see [Building a site](#building-a-site)) |
|
|
283
284
|
| `whiteboard serve` | run the server in the foreground |
|
|
284
285
|
| `whiteboard skill [dir]` | print where the agent skill is, or link it into a skills folder |
|
|
285
286
|
|
|
@@ -308,6 +309,7 @@ export default defineConfig({
|
|
|
308
309
|
],
|
|
309
310
|
style: new URL('./site.css', import.meta.url), // a stylesheet on every page, after the others
|
|
310
311
|
files: true, // serve and watch the rest of the project at /-/ (default: true)
|
|
312
|
+
build: { pages: ['docs/**/*.md'] }, // what `whiteboard build` makes (see Building a site)
|
|
311
313
|
})
|
|
312
314
|
```
|
|
313
315
|
|
|
@@ -339,13 +341,13 @@ Every colour is a `light-dark()` pair, so one line sets it for both themes:
|
|
|
339
341
|
:root { --text-size: 17px; --rhythm: 1em; }
|
|
340
342
|
```
|
|
341
343
|
|
|
342
|
-
The built-in plugins are callout, chat, code, comments, details,
|
|
343
|
-
form, gallery, grid, iframe, mermaid, quiet and window: every project has them, and
|
|
344
|
+
The built-in plugins are callout, chat, code, comments, details, draft,
|
|
345
|
+
forge, form, gallery, grid, iframe, mermaid, quiet, steps and window: every project has them, and
|
|
344
346
|
`whiteboard docs` shows how to write each. A config's `plugins` add to them,
|
|
345
347
|
and one with a built-in's name replaces it. The terminal and the Claude Code
|
|
346
348
|
plugin are opt-in, since they run code or are about one agent, and so is the
|
|
347
349
|
table of contents (`toc`), which a page then asks for in its frontmatter
|
|
348
|
-
(`toc: true`).
|
|
350
|
+
(`plugins: { toc: true }`).
|
|
349
351
|
|
|
350
352
|
Named forms need nothing in the config: the core sends a submit of any
|
|
351
353
|
`<form name>` as an event, on any page.
|
|
@@ -354,6 +356,54 @@ Set `files: false` for a project whose folder is not a repository, such as
|
|
|
354
356
|
your home folder. Then only `.whiteboard/` is served and watched.
|
|
355
357
|
`whiteboard init` sets it when run in the home folder.
|
|
356
358
|
|
|
359
|
+
## Building a site
|
|
360
|
+
|
|
361
|
+
Docs can be written as pages: the agent drafts, you comment on passages, a
|
|
362
|
+
form settles a choice, a chat clears up a question. Kept in a folder of the
|
|
363
|
+
repository (`docs/`), they are live pages at `/-/docs/…` while you write
|
|
364
|
+
them. `whiteboard build` turns them into a site: plain HTML files with their
|
|
365
|
+
images and styles, links between them relative, for GitHub Pages or any
|
|
366
|
+
file host.
|
|
367
|
+
|
|
368
|
+
```ts
|
|
369
|
+
export default defineConfig({
|
|
370
|
+
build: {
|
|
371
|
+
pages: ['docs/**/*.md', '!docs/notes/**'], // which pages, as globs; ! leaves out
|
|
372
|
+
skip: ['form', 'chat', 'comments', 'draft'], // plugins or blocks left out (this is the default)
|
|
373
|
+
out: 'site', // where it goes (default: site)
|
|
374
|
+
},
|
|
375
|
+
})
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
```sh
|
|
379
|
+
whiteboard build # as configured
|
|
380
|
+
whiteboard build 'docs/guide/*.md' --out preview # or what is given, over the config
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
- **What is for writing is left out:** the live channel and the event log
|
|
384
|
+
(so no answers, chats or comments), new-content marks and toasts, and the
|
|
385
|
+
plugins and blocks in `skip`: their blocks render as nothing, their
|
|
386
|
+
stylesheets, browser modules and what they add to the page aren't included.
|
|
387
|
+
A plugin's `shell` is asked with no request, since no browser asked for the
|
|
388
|
+
page: the terminal's drawer, which is only for the project's own browser,
|
|
389
|
+
isn't there.
|
|
390
|
+
- **What is for reading stays:** steps, the gallery's lightbox, ⤢ on
|
|
391
|
+
windows, the theme toggle, the contents, details. Code and diagrams were
|
|
392
|
+
rendered on the server, so the site loads no highlighter.
|
|
393
|
+
- **`:::draft`** is for what is there while you write and not after: a note
|
|
394
|
+
to check something, two versions of a paragraph. It shows marked as a
|
|
395
|
+
draft, and the build leaves it out.
|
|
396
|
+
- **Where pages land:** at their places below the folder they share, a
|
|
397
|
+
README.md or index.md as its folder's index.html (`docs/api/forms.md` →
|
|
398
|
+
`site/api/forms.html`). A link to a page outside the build, or to a file
|
|
399
|
+
outside that folder, stays as written, and the build says so.
|
|
400
|
+
- **The folder is the build's:** it is replaced on each build, and one that
|
|
401
|
+
holds files a build didn't write is refused.
|
|
402
|
+
|
|
403
|
+
Open the site through a web server (`npx serve site`) rather than as files:
|
|
404
|
+
browsers don't run JavaScript modules from `file://`. The pages read either
|
|
405
|
+
way, but steps, the lightbox and the theme toggle need the server.
|
|
406
|
+
|
|
357
407
|
## Writing a plugin
|
|
358
408
|
|
|
359
409
|
Everything that extends whiteboard is a plugin: syntax for pages,
|
|
@@ -534,7 +584,8 @@ A page module (`setup`'s `client`) gets `mount(root, page, api)`. Both get
|
|
|
534
584
|
the page's `api`: its `events` and `append` (which comes back through
|
|
535
585
|
`events.on`), the `listeners`, `forms` and `unread` messages, `onRendered`
|
|
536
586
|
(after a live update, to put back what it adds), the page's `frontmatter`
|
|
537
|
-
on the page handle,
|
|
587
|
+
on the page handle (YAML, as parsed) and the plugin's own `settings` in it
|
|
588
|
+
(under `plugins:` by its name: `plugins: { toc: true }` is `true` for toc), `corner()` for floating buttons, `toast()` for a label in
|
|
538
589
|
the corner that says what is going on and goes there (one that hides after a
|
|
539
590
|
few seconds, or one that stays with a count), `badge()` for counts in the
|
|
540
591
|
tab title, and the `theme`. Every value that changes is called for what it
|
package/bin/whiteboard.ts
CHANGED
|
@@ -47,6 +47,8 @@ const HELP = `whiteboard — markdown pages in the browser, what the reader does
|
|
|
47
47
|
whiteboard url <page|file> the same: print the page URL
|
|
48
48
|
whiteboard close <page> a page that did its job: remove its file, and its events from the log
|
|
49
49
|
whiteboard prune <page> [--type <t>] [--id <id>] remove a page's events from the log, keep the page
|
|
50
|
+
whiteboard build [globs…] [--out <dir>] [--skip <a,b>] pages as a static site: plain HTML, links
|
|
51
|
+
relative, without forms, chats, comments and drafts (the config's build)
|
|
50
52
|
whiteboard edit <event id> --data <json> change an agent's own event in place (merged into its data)
|
|
51
53
|
whiteboard scroll <page|file> <where> scroll the tabs that have the page open to a heading's text,
|
|
52
54
|
a form's name or any text on it (opening details around it)
|
|
@@ -94,6 +96,8 @@ const { values: opts, positionals } =
|
|
|
94
96
|
last: { type: 'string' },
|
|
95
97
|
follow: { type: 'boolean' },
|
|
96
98
|
id: { type: 'string' },
|
|
99
|
+
out: { type: 'string' },
|
|
100
|
+
skip: { type: 'string' },
|
|
97
101
|
help: { type: 'boolean', short: 'h' },
|
|
98
102
|
},
|
|
99
103
|
})
|
|
@@ -375,10 +379,38 @@ switch (cmd) {
|
|
|
375
379
|
console.error(`whiteboard: ${proj.name} is already served at ${base}`)
|
|
376
380
|
process.exit(1)
|
|
377
381
|
}
|
|
382
|
+
// the server only for the commands that run one: every other command (the hooks' among them,
|
|
383
|
+
// on every prompt) starts without it, a good part of its start-up time
|
|
378
384
|
const { start } = await import('../src/serve.ts')
|
|
379
385
|
await start(proj)
|
|
380
386
|
break
|
|
381
387
|
}
|
|
388
|
+
case 'build': {
|
|
389
|
+
// pages rendered once, as a static site: the config's `build`, with what is given here over it
|
|
390
|
+
const proj = needProject()
|
|
391
|
+
const { createServer } = await import('../src/server.ts') // as for serve: only when needed
|
|
392
|
+
const server = createServer(proj)
|
|
393
|
+
try {
|
|
394
|
+
const result = await server.build({
|
|
395
|
+
pages: positionals.length ? positionals : undefined,
|
|
396
|
+
out: opts.out,
|
|
397
|
+
skip:
|
|
398
|
+
opts.skip != null
|
|
399
|
+
? opts.skip
|
|
400
|
+
.split(',')
|
|
401
|
+
.map(s => s.trim())
|
|
402
|
+
.filter(Boolean)
|
|
403
|
+
: undefined,
|
|
404
|
+
})
|
|
405
|
+
for (const w of result.warnings) console.error(`whiteboard build: ${w}`)
|
|
406
|
+
console.log(
|
|
407
|
+
`built ${result.pages.length} page${result.pages.length === 1 ? '' : 's'} into ${path.relative(process.cwd(), result.out) || '.'}`,
|
|
408
|
+
)
|
|
409
|
+
} finally {
|
|
410
|
+
server.close()
|
|
411
|
+
}
|
|
412
|
+
process.exit(0)
|
|
413
|
+
}
|
|
382
414
|
case 'init': {
|
|
383
415
|
init(positionals[0])
|
|
384
416
|
break
|
package/dist/bin/whiteboard.js
CHANGED
|
@@ -30,6 +30,8 @@ const HELP = `whiteboard — markdown pages in the browser, what the reader does
|
|
|
30
30
|
whiteboard url <page|file> the same: print the page URL
|
|
31
31
|
whiteboard close <page> a page that did its job: remove its file, and its events from the log
|
|
32
32
|
whiteboard prune <page> [--type <t>] [--id <id>] remove a page's events from the log, keep the page
|
|
33
|
+
whiteboard build [globs…] [--out <dir>] [--skip <a,b>] pages as a static site: plain HTML, links
|
|
34
|
+
relative, without forms, chats, comments and drafts (the config's build)
|
|
33
35
|
whiteboard edit <event id> --data <json> change an agent's own event in place (merged into its data)
|
|
34
36
|
whiteboard scroll <page|file> <where> scroll the tabs that have the page open to a heading's text,
|
|
35
37
|
a form's name or any text on it (opening details around it)
|
|
@@ -74,6 +76,8 @@ const { values: opts, positionals } = cmd && !BUILTIN_COMMANDS.has(cmd) ? {
|
|
|
74
76
|
last: { type: "string" },
|
|
75
77
|
follow: { type: "boolean" },
|
|
76
78
|
id: { type: "string" },
|
|
79
|
+
out: { type: "string" },
|
|
80
|
+
skip: { type: "string" },
|
|
77
81
|
help: {
|
|
78
82
|
type: "boolean",
|
|
79
83
|
short: "h"
|
|
@@ -323,6 +327,23 @@ switch (cmd) {
|
|
|
323
327
|
await start(proj);
|
|
324
328
|
break;
|
|
325
329
|
}
|
|
330
|
+
case "build": {
|
|
331
|
+
const proj = needProject();
|
|
332
|
+
const { createServer } = await import("../src/server.js");
|
|
333
|
+
const server = createServer(proj);
|
|
334
|
+
try {
|
|
335
|
+
const result = await server.build({
|
|
336
|
+
pages: positionals.length ? positionals : void 0,
|
|
337
|
+
out: opts.out,
|
|
338
|
+
skip: opts.skip != null ? opts.skip.split(",").map((s) => s.trim()).filter(Boolean) : void 0
|
|
339
|
+
});
|
|
340
|
+
for (const w of result.warnings) console.error(`whiteboard build: ${w}`);
|
|
341
|
+
console.log(`built ${result.pages.length} page${result.pages.length === 1 ? "" : "s"} into ${path.relative(process.cwd(), result.out) || "."}`);
|
|
342
|
+
} finally {
|
|
343
|
+
server.close();
|
|
344
|
+
}
|
|
345
|
+
process.exit(0);
|
|
346
|
+
}
|
|
326
347
|
case "init":
|
|
327
348
|
init(positionals[0]);
|
|
328
349
|
break;
|
package/dist/client/runtime.js
CHANGED
|
@@ -487,6 +487,8 @@ const handoff = JSON.parse(document.getElementById("wb-page").textContent);
|
|
|
487
487
|
const root = document.getElementById("wb-root");
|
|
488
488
|
const page = handoff.id;
|
|
489
489
|
const isDir = handoff.kind === "pages" || handoff.kind === "folder";
|
|
490
|
+
const live = handoff.live !== false;
|
|
491
|
+
const moduleUrl = (path) => new URL(path, document.baseURI).href;
|
|
490
492
|
let events = [];
|
|
491
493
|
const eventsValue = reactive(() => events);
|
|
492
494
|
const unread = reactive(unread$1);
|
|
@@ -498,9 +500,11 @@ function setEvents(next) {
|
|
|
498
500
|
messagesChanged();
|
|
499
501
|
}
|
|
500
502
|
async function loadEvents() {
|
|
503
|
+
if (!live) return;
|
|
501
504
|
setEvents((await (await fetch(`/api/events?page=${encodeURIComponent(page)}`)).json()).filter((e) => e.page === page));
|
|
502
505
|
}
|
|
503
506
|
async function append(type, data = {}, action = null) {
|
|
507
|
+
if (!live) throw new Error("a built page is a file: there is no log to append to");
|
|
504
508
|
const res = await fetch("/api/events", {
|
|
505
509
|
method: "POST",
|
|
506
510
|
headers: { "content-type": "application/json" },
|
|
@@ -519,6 +523,7 @@ async function append(type, data = {}, action = null) {
|
|
|
519
523
|
let listeners = [];
|
|
520
524
|
const listenersValue = reactive(() => listeners);
|
|
521
525
|
async function loadListeners() {
|
|
526
|
+
if (!live) return;
|
|
522
527
|
listeners = await (await fetch(`/api/listeners?page=${encodeURIComponent(page)}`)).json();
|
|
523
528
|
listenersValue.notify();
|
|
524
529
|
}
|
|
@@ -528,7 +533,7 @@ let baseTitle = document.title;
|
|
|
528
533
|
const badges = /* @__PURE__ */ new Map();
|
|
529
534
|
let badgeCount = 0;
|
|
530
535
|
function writeTitle() {
|
|
531
|
-
const list = [...badges.values()].
|
|
536
|
+
const list = [...badges.values()].toSorted((a, b) => a.order - b.order || a.since - b.since);
|
|
532
537
|
document.title = `${list.map((b) => `(${b.text}) `).join("")}${baseTitle}`;
|
|
533
538
|
}
|
|
534
539
|
const api = {
|
|
@@ -586,8 +591,10 @@ let nextFrontmatter = frontmatter;
|
|
|
586
591
|
const dataValue = reactive(() => data);
|
|
587
592
|
const frontmatterValue = reactive(() => frontmatter);
|
|
588
593
|
const handle = {
|
|
594
|
+
settings: reactive(() => void 0),
|
|
589
595
|
id: page,
|
|
590
596
|
kind: handoff.kind,
|
|
597
|
+
live,
|
|
591
598
|
data: dataValue,
|
|
592
599
|
frontmatter: frontmatterValue,
|
|
593
600
|
onChange(fn) {
|
|
@@ -657,29 +664,53 @@ function connect() {
|
|
|
657
664
|
}
|
|
658
665
|
await Promise.all([loadEvents(), loadListeners()]);
|
|
659
666
|
if (handoff.client) try {
|
|
660
|
-
const mount = (await import(handoff.client)).default;
|
|
667
|
+
const mount = (await import(moduleUrl(handoff.client))).default;
|
|
661
668
|
await mount(root, handle, api);
|
|
662
669
|
} catch (err) {
|
|
663
670
|
console.error("page:", err);
|
|
664
671
|
root.insertAdjacentHTML("afterbegin", String(html`<pre class="wb-error" role="alert">the page failed to start: ${err.message}</pre>`));
|
|
665
672
|
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
}
|
|
673
|
+
if (live) {
|
|
674
|
+
trackForms(root, page, api);
|
|
675
|
+
trackReading({
|
|
676
|
+
messages: handoff.messages ?? [],
|
|
677
|
+
events: () => events,
|
|
678
|
+
send: (ids) => {
|
|
679
|
+
append(READ, { ids }).catch((err) => console.error("marking read:", err));
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* A plugin's page handle: the page's, with its own settings, the page's frontmatter under `plugins:`
|
|
685
|
+
* by its name, heard of only when they changed.
|
|
686
|
+
*/
|
|
687
|
+
function handleFor(name) {
|
|
688
|
+
const own = () => {
|
|
689
|
+
const plugins = frontmatter.plugins;
|
|
690
|
+
return plugins && typeof plugins === "object" ? plugins[name] : void 0;
|
|
691
|
+
};
|
|
692
|
+
const settings = reactive(own);
|
|
693
|
+
let last = JSON.stringify(own() ?? null);
|
|
694
|
+
frontmatterValue.on(() => {
|
|
695
|
+
const now = JSON.stringify(own() ?? null);
|
|
696
|
+
if (now === last) return;
|
|
697
|
+
last = now;
|
|
698
|
+
settings.notify();
|
|
699
|
+
});
|
|
700
|
+
return {
|
|
701
|
+
...handle,
|
|
702
|
+
settings
|
|
703
|
+
};
|
|
704
|
+
}
|
|
674
705
|
await Promise.all((handoff.plugins ?? []).map(async (ext) => {
|
|
675
706
|
try {
|
|
676
|
-
const mount = (await import(ext.client)).default;
|
|
707
|
+
const mount = (await import(moduleUrl(ext.client))).default;
|
|
677
708
|
if (typeof mount !== "function") throw new Error("the client module must export a mount(root, page, api) function as default");
|
|
678
|
-
await mount(root,
|
|
709
|
+
await mount(root, handleFor(ext.name), api);
|
|
679
710
|
} catch (err) {
|
|
680
711
|
console.error(`plugin ${ext.name}:`, err);
|
|
681
712
|
root.insertAdjacentHTML("afterbegin", String(html`<pre class="wb-error" role="alert">
|
|
682
713
|
plugin "${ext.name}" failed in the browser: ${err.message}</pre>`));
|
|
683
714
|
}
|
|
684
715
|
}));
|
|
685
|
-
connect();
|
|
716
|
+
if (live) connect();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
What is there while a page is written, and not once it is built: a note to
|
|
2
|
+
check something, two versions of a paragraph, a question for later. It shows
|
|
3
|
+
set apart, marked as a draft; `whiteboard build` leaves it out (it is in the
|
|
4
|
+
build's `skip` by default). The label is optional.
|
|
5
|
+
|
|
6
|
+
```markdown
|
|
7
|
+
:::draft[Check with the API]
|
|
8
|
+
Is `wait` really the only way to get answers?
|
|
9
|
+
:::
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
:::draft[Check with the API]
|
|
13
|
+
Is `wait` really the only way to get answers?
|
|
14
|
+
:::
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { builtinPublic } from "../../src/package.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { definePlugin, html, raw } from "@bigmistqke/whiteboard";
|
|
4
|
+
// plugins/draft/index.ts
|
|
5
|
+
async function render(ctx) {
|
|
6
|
+
const label = ctx.label != null && String(ctx.label) !== "" ? ctx.label : "draft";
|
|
7
|
+
return html`<aside class="wb-draft">
|
|
8
|
+
<div class="wb-draft-label">${raw(String(label))}</div>
|
|
9
|
+
${raw(await ctx.toHtml(ctx.children))}
|
|
10
|
+
</aside>`;
|
|
11
|
+
}
|
|
12
|
+
function draft() {
|
|
13
|
+
return definePlugin({
|
|
14
|
+
name: "draft",
|
|
15
|
+
public: builtinPublic("draft"),
|
|
16
|
+
style: "style.css",
|
|
17
|
+
blocks: { draft: { html: render } },
|
|
18
|
+
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export { draft as default, render };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* A draft (index.ts): set apart, plainly not final */
|
|
2
|
+
.wb-draft {
|
|
3
|
+
margin: calc(var(--rhythm) * 2) 0;
|
|
4
|
+
padding: var(--space-md) var(--space-xl) var(--space-xl);
|
|
5
|
+
border: var(--hairline) dashed color-mix(in srgb, var(--warn) var(--tint-strong), transparent);
|
|
6
|
+
border-radius: var(--radius);
|
|
7
|
+
background: color-mix(in srgb, var(--warn) var(--tint-faint), transparent);
|
|
8
|
+
}
|
|
9
|
+
.wb-draft-label {
|
|
10
|
+
font: var(--weight-strong) var(--ui-tiny) / var(--ui-line-height) var(--sans);
|
|
11
|
+
letter-spacing: var(--caps-spacing);
|
|
12
|
+
text-transform: uppercase;
|
|
13
|
+
color: var(--warn);
|
|
14
|
+
margin-bottom: var(--space-xs);
|
|
15
|
+
}
|
|
16
|
+
.wb-draft-label > * {
|
|
17
|
+
margin: 0;
|
|
18
|
+
}
|
|
19
|
+
.wb-draft > :last-child {
|
|
20
|
+
margin-bottom: 0;
|
|
21
|
+
}
|
package/dist/plugins/index.js
CHANGED
|
@@ -11,6 +11,8 @@ import iframe from "./iframe/index.js";
|
|
|
11
11
|
import mermaid from "./mermaid/index.js";
|
|
12
12
|
import quiet from "./quiet/index.js";
|
|
13
13
|
import windows from "./window/index.js";
|
|
14
|
+
import steps from "./steps/index.js";
|
|
15
|
+
import draft from "./draft/index.js";
|
|
14
16
|
// plugins/index.ts
|
|
15
17
|
function builtins() {
|
|
16
18
|
return [
|
|
@@ -26,7 +28,9 @@ function builtins() {
|
|
|
26
28
|
iframe(),
|
|
27
29
|
mermaid(),
|
|
28
30
|
quiet(),
|
|
29
|
-
windows()
|
|
31
|
+
windows(),
|
|
32
|
+
steps(),
|
|
33
|
+
draft()
|
|
30
34
|
];
|
|
31
35
|
}
|
|
32
36
|
export { builtins };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
One pane, one item at a time, with ‹ › between them: an A/B, the steps of a
|
|
2
|
+
procedure, versions of a design. It is a window, so ⤢ fills the browser
|
|
3
|
+
window with it (for going through steps, large).
|
|
4
|
+
|
|
5
|
+
Each heading at the shallowest level starts an item; without headings, `---`
|
|
6
|
+
separates them. With up to four items, all titled, the header shows the
|
|
7
|
+
titles as tabs; else it counts (`2 / 5`) and each item shows its title.
|
|
8
|
+
|
|
9
|
+
The items are laid over each other, so the pane is as tall as the tallest
|
|
10
|
+
and flipping doesn't move the page. ← and → step when it has the focus (a
|
|
11
|
+
click in it) or fills the window. Which item shows stays when the page
|
|
12
|
+
updates.
|
|
13
|
+
|
|
14
|
+
Attributes: `count` (count, never tabs), `wide`, `height`.
|
|
15
|
+
|
|
16
|
+
```markdown
|
|
17
|
+
:::steps[Two headers]
|
|
18
|
+
### A
|
|
19
|
+
The label on the left, the buttons on the right.
|
|
20
|
+
|
|
21
|
+
### B
|
|
22
|
+
Everything centred.
|
|
23
|
+
:::
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
:::steps[Two headers]
|
|
27
|
+
### A
|
|
28
|
+
The label on the left, the buttons on the right.
|
|
29
|
+
|
|
30
|
+
### B
|
|
31
|
+
Everything centred.
|
|
32
|
+
:::
|
|
33
|
+
|
|
34
|
+
```markdown
|
|
35
|
+
:::steps[The migration]
|
|
36
|
+
### Copy the table
|
|
37
|
+
`migrate --dry-run` on staging first.
|
|
38
|
+
|
|
39
|
+
### Switch the reads
|
|
40
|
+
…
|
|
41
|
+
:::
|
|
42
|
+
```
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { builtinPublic } from "../../src/package.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { definePlugin, html, raw, windowFrame } from "@bigmistqke/whiteboard";
|
|
4
|
+
// plugins/steps/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* The items of a block: one per heading at its shallowest level (what comes before the first is an
|
|
7
|
+
* item of its own); without headings, `---` separates them; else it is one item.
|
|
8
|
+
*/
|
|
9
|
+
function split(children) {
|
|
10
|
+
const content = children.filter((n) => !(n.type === "text" && !n.value?.trim()));
|
|
11
|
+
const heads = content.filter((n) => n.type === "heading");
|
|
12
|
+
const parts = [];
|
|
13
|
+
if (heads.length) {
|
|
14
|
+
const depth = Math.min(...heads.map((h) => h.depth));
|
|
15
|
+
for (const n of content) if (n.type === "heading" && n.depth === depth) parts.push({
|
|
16
|
+
title: n.children ?? [],
|
|
17
|
+
body: []
|
|
18
|
+
});
|
|
19
|
+
else if (parts.length) parts.at(-1).body.push(n);
|
|
20
|
+
else parts.push({
|
|
21
|
+
title: null,
|
|
22
|
+
body: [n]
|
|
23
|
+
});
|
|
24
|
+
return parts;
|
|
25
|
+
}
|
|
26
|
+
let current = {
|
|
27
|
+
title: null,
|
|
28
|
+
body: []
|
|
29
|
+
};
|
|
30
|
+
for (const n of content) if (n.type === "thematicBreak") {
|
|
31
|
+
if (current.body.length) parts.push(current);
|
|
32
|
+
current = {
|
|
33
|
+
title: null,
|
|
34
|
+
body: []
|
|
35
|
+
};
|
|
36
|
+
} else current.body.push(n);
|
|
37
|
+
if (current.body.length || !parts.length) parts.push(current);
|
|
38
|
+
return parts;
|
|
39
|
+
}
|
|
40
|
+
/** A height in px (a bare number) or a CSS length; else none. */
|
|
41
|
+
const height = (value) => value && /^\d+(\.\d+)?$/.test(value) ? `${value}px` : value && /^\d+(\.\d+)?(px|em|rem|vh|svh|dvh)$/.test(value) ? value : void 0;
|
|
42
|
+
const svg = (d) => raw(`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`);
|
|
43
|
+
const PREV = svg("M10 3.5 5.5 8l4.5 4.5");
|
|
44
|
+
const NEXT = svg("M6 3.5 10.5 8 6 12.5");
|
|
45
|
+
/** With this many items or fewer, all titled, the header shows their titles as tabs. */
|
|
46
|
+
const TABS = 4;
|
|
47
|
+
async function render(ctx) {
|
|
48
|
+
const parts = split(ctx.children);
|
|
49
|
+
const items = await Promise.all(parts.map(async (p) => ({
|
|
50
|
+
title: p.title ? await ctx.toHtml(p.title) : null,
|
|
51
|
+
html: await ctx.toHtml(p.body)
|
|
52
|
+
})));
|
|
53
|
+
const tabs = !("count" in ctx.attrs) && items.length <= TABS && items.every((i) => i.title);
|
|
54
|
+
const n = items.length;
|
|
55
|
+
const marks = tabs ? items.map((item, i) => html`<button type="button" class="wb-steps-tab wb-steps-mark" data-steps="${String(i)}">
|
|
56
|
+
${raw(item.title)}
|
|
57
|
+
</button>`) : html`<span class="wb-steps-count">
|
|
58
|
+
${items.map((_, i) => html`<span class="wb-steps-mark">${String(i + 1)} / ${String(n)}</span>`)}
|
|
59
|
+
</span>`;
|
|
60
|
+
const controls = html`<span class="wb-steps-nav">
|
|
61
|
+
<button
|
|
62
|
+
type="button"
|
|
63
|
+
class="wb-window-button wb-steps-prev"
|
|
64
|
+
data-steps="prev"
|
|
65
|
+
title="Previous (←)"
|
|
66
|
+
aria-label="Previous"
|
|
67
|
+
>
|
|
68
|
+
${PREV}
|
|
69
|
+
</button>
|
|
70
|
+
${marks}
|
|
71
|
+
<button type="button" class="wb-window-button wb-steps-next" data-steps="next" title="Next (→)" aria-label="Next">
|
|
72
|
+
${NEXT}
|
|
73
|
+
</button>
|
|
74
|
+
</span>`;
|
|
75
|
+
const body = html`<div class="wb-steps" tabindex="0">
|
|
76
|
+
${items.map((item) => html`<section class="wb-steps-item">
|
|
77
|
+
${!tabs && item.title ? html`<div class="wb-steps-title">${raw(item.title)}</div>` : ""} ${raw(item.html)}
|
|
78
|
+
</section>`)}
|
|
79
|
+
</div>`;
|
|
80
|
+
return windowFrame({
|
|
81
|
+
label: ctx.label,
|
|
82
|
+
className: "wb-steps-window",
|
|
83
|
+
controls,
|
|
84
|
+
wide: "wide" in ctx.attrs,
|
|
85
|
+
height: height(ctx.attrs.height),
|
|
86
|
+
body
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function steps() {
|
|
90
|
+
return definePlugin({
|
|
91
|
+
name: "steps",
|
|
92
|
+
public: builtinPublic("steps"),
|
|
93
|
+
style: "style.css",
|
|
94
|
+
setup: () => ({ client: "client.js" }),
|
|
95
|
+
blocks: { steps: { html: render } },
|
|
96
|
+
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
export { steps as default, render, split };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=()=>[...document.querySelectorAll(`#wb-main .wb-steps-window`)],t=e=>[...e.querySelectorAll(`:scope > .wb-window-body > .wb-steps > .wb-steps-item`)],n=e=>[...e.querySelectorAll(`:scope > .wb-window-bar .wb-steps-mark`)],r=/* @__PURE__ */ new Map;function i(e,i,a){let o=t(e),s=Math.max(o.length,1);a=Math.min(Math.max(a,0),s-1),r.set(i,a),e.setAttribute(`data-wb-step`,String(a)),o.forEach((e,t)=>e.toggleAttribute(`data-wb-current`,t===a)),n(e).forEach((e,t)=>e.toggleAttribute(`data-wb-current`,t===a)),e.toggleAttribute(`data-wb-first`,a===0),e.toggleAttribute(`data-wb-last`,a===s-1)}const a=()=>e().forEach((e,t)=>i(e,t,r.get(t)??0));function o(t,n){let a=e().indexOf(t);if(a<0)return;let o=r.get(a)??0;i(t,a,n===`prev`?o-1:n===`next`?o+1:n)}const s=e=>!!e?.closest?.(`input, textarea, select, [contenteditable]:not([contenteditable="false"])`);let c=!1;const l=(e,t,n)=>{a(),n.onRendered(a),c||(c=!0,document.addEventListener(`click`,e=>{let t=e.target.closest?.(`[data-steps]`),n=t?.closest(`.wb-steps-window`);if(!t||!n)return;let r=t.dataset.steps;o(n,r===`prev`||r===`next`?r:Number(r))}),document.addEventListener(`keydown`,e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.target;if(s(t))return;let n=t.closest?.(`.wb-steps-window`)??document.querySelector(`#wb-main .wb-steps-window[data-wb-maximized]`);n&&(e.preventDefault(),o(n,e.key===`ArrowLeft`?`prev`:`next`))}))};export{l as default};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* Steps (index.ts): the items over each other in one grid cell, so the pane is as tall as the
|
|
2
|
+
tallest; one shows. Before the browser marks one (data-wb-step), the first. */
|
|
3
|
+
.wb-steps {
|
|
4
|
+
display: grid;
|
|
5
|
+
outline: none;
|
|
6
|
+
}
|
|
7
|
+
.wb-steps:focus-visible {
|
|
8
|
+
box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) var(--tint-strong), transparent);
|
|
9
|
+
}
|
|
10
|
+
.wb-steps > .wb-steps-item {
|
|
11
|
+
grid-area: 1 / 1;
|
|
12
|
+
min-width: 0;
|
|
13
|
+
}
|
|
14
|
+
.wb-steps > .wb-steps-item > :first-child {
|
|
15
|
+
margin-top: 0;
|
|
16
|
+
}
|
|
17
|
+
.wb-steps > .wb-steps-item > :last-child {
|
|
18
|
+
margin-bottom: 0;
|
|
19
|
+
}
|
|
20
|
+
.wb-steps-window:not([data-wb-step]) > .wb-window-body > .wb-steps > .wb-steps-item:not(:first-child),
|
|
21
|
+
.wb-steps-window[data-wb-step] > .wb-window-body > .wb-steps > .wb-steps-item:not([data-wb-current]) {
|
|
22
|
+
visibility: hidden;
|
|
23
|
+
}
|
|
24
|
+
.wb-steps-title {
|
|
25
|
+
font: var(--weight-strong) var(--ui-small) / var(--ui-line-height) var(--sans);
|
|
26
|
+
color: var(--muted);
|
|
27
|
+
letter-spacing: var(--caps-spacing);
|
|
28
|
+
text-transform: uppercase;
|
|
29
|
+
margin-bottom: var(--space-md);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* the header: ‹ 2 / 5 › or ‹ A B › */
|
|
33
|
+
.wb-steps-nav {
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
gap: var(--space-2xs);
|
|
37
|
+
flex: none;
|
|
38
|
+
}
|
|
39
|
+
.wb-steps-count {
|
|
40
|
+
font: var(--ui-tiny) / 1 var(--sans);
|
|
41
|
+
font-variant-numeric: tabular-nums;
|
|
42
|
+
color: var(--muted);
|
|
43
|
+
padding: 0 var(--space-2xs);
|
|
44
|
+
}
|
|
45
|
+
.wb-steps-window:not([data-wb-step]) > .wb-window-bar .wb-steps-count > .wb-steps-mark:not(:first-child),
|
|
46
|
+
.wb-steps-window[data-wb-step] > .wb-window-bar .wb-steps-count > .wb-steps-mark:not([data-wb-current]) {
|
|
47
|
+
display: none;
|
|
48
|
+
}
|
|
49
|
+
.wb-steps-tab {
|
|
50
|
+
font: var(--ui-tiny) / 1 var(--sans);
|
|
51
|
+
color: var(--muted);
|
|
52
|
+
background: none;
|
|
53
|
+
border: var(--hairline) solid transparent;
|
|
54
|
+
border-radius: var(--radius-pill);
|
|
55
|
+
padding: var(--space-xs) var(--space-md);
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
white-space: nowrap;
|
|
58
|
+
}
|
|
59
|
+
.wb-steps-tab > * {
|
|
60
|
+
margin: 0;
|
|
61
|
+
}
|
|
62
|
+
.wb-steps-tab:hover {
|
|
63
|
+
color: var(--text);
|
|
64
|
+
background: color-mix(in srgb, var(--text) var(--tint-faint), transparent);
|
|
65
|
+
}
|
|
66
|
+
.wb-steps-window:not([data-wb-step]) > .wb-window-bar .wb-steps-tab:first-of-type,
|
|
67
|
+
.wb-steps-window > .wb-window-bar .wb-steps-tab[data-wb-current] {
|
|
68
|
+
color: var(--accent);
|
|
69
|
+
border-color: color-mix(in srgb, var(--accent) var(--tint-strong), transparent);
|
|
70
|
+
background: color-mix(in srgb, var(--accent) var(--tint-faint), transparent);
|
|
71
|
+
}
|
|
72
|
+
.wb-steps-window:not([data-wb-step]) > .wb-window-bar .wb-steps-prev,
|
|
73
|
+
.wb-steps-window[data-wb-first] > .wb-window-bar .wb-steps-prev,
|
|
74
|
+
.wb-steps-window[data-wb-last] > .wb-window-bar .wb-steps-next {
|
|
75
|
+
opacity: 0.35;
|
|
76
|
+
pointer-events: none;
|
|
77
|
+
}
|
|
@@ -4,6 +4,8 @@ import { createRequire } from "node:module";
|
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import net from "node:net";
|
|
7
|
+
import xtermHeadless from "@xterm/headless";
|
|
8
|
+
import xtermSerialize from "@xterm/addon-serialize";
|
|
7
9
|
// plugins/terminal/host.ts
|
|
8
10
|
const require = createRequire(import.meta.url);
|
|
9
11
|
const [dir, socket] = process.argv.slice(2);
|
|
@@ -11,7 +13,11 @@ if (!dir || !socket) {
|
|
|
11
13
|
console.error("usage: host <project dir> <socket path>");
|
|
12
14
|
process.exit(2);
|
|
13
15
|
}
|
|
14
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* node-pty, loaded when a session starts rather than imported: a native module that may not load on
|
|
18
|
+
* this machine, which then is an error to report, not a host that fails to start. Its prebuilt
|
|
19
|
+
* helper ships without execute permission (1.1.0): add it.
|
|
20
|
+
*/
|
|
15
21
|
function loadPty() {
|
|
16
22
|
const pty = require("node-pty");
|
|
17
23
|
const helper = path.join(path.dirname(require.resolve("node-pty/package.json")), "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper");
|
|
@@ -20,8 +26,8 @@ function loadPty() {
|
|
|
20
26
|
} catch {}
|
|
21
27
|
return pty;
|
|
22
28
|
}
|
|
23
|
-
const { Terminal } =
|
|
24
|
-
const { SerializeAddon } =
|
|
29
|
+
const { Terminal } = xtermHeadless;
|
|
30
|
+
const { SerializeAddon } = xtermSerialize;
|
|
25
31
|
/** the sessions by id, in the order they were made */
|
|
26
32
|
const sessions = /* @__PURE__ */ new Map();
|
|
27
33
|
let nextId = 1;
|
|
@@ -31,7 +31,8 @@ function leave(s, viewer) {
|
|
|
31
31
|
*/
|
|
32
32
|
function handOver(s, viewer) {
|
|
33
33
|
if (s.active !== viewer || s.viewers.has(viewer)) return null;
|
|
34
|
-
|
|
34
|
+
let next;
|
|
35
|
+
for (const viewer of s.viewers) if (!next || viewer[1].used > next[1].used) next = viewer;
|
|
35
36
|
s.active = next?.[0] ?? null;
|
|
36
37
|
return next ? {
|
|
37
38
|
cols: next[1].cols,
|