@bigmistqke/whiteboard 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +609 -2
- package/bin/whiteboard.ts +431 -0
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/bin/whiteboard.js +471 -0
- package/dist/client/runtime.js +391 -0
- package/dist/define.js +7 -0
- package/dist/plugins/callout/README.md +13 -0
- package/dist/plugins/callout/index.js +27 -0
- package/dist/plugins/callout/style.css +12 -0
- package/dist/plugins/chat/README.md +45 -0
- package/dist/plugins/chat/client.js +3 -0
- package/dist/plugins/chat/index.js +46 -0
- package/dist/plugins/chat/style.css +17 -0
- package/dist/plugins/claude-code/index.js +120 -0
- package/dist/plugins/code/README.md +42 -0
- package/dist/plugins/code/diff.js +64 -0
- package/dist/plugins/code/index.js +77 -0
- package/dist/plugins/code/style.css +29 -0
- package/dist/plugins/comments/client.js +10 -0
- package/dist/plugins/comments/index.js +51 -0
- package/dist/plugins/comments/style.css +32 -0
- package/dist/plugins/details/README.md +17 -0
- package/dist/plugins/details/index.js +17 -0
- package/dist/plugins/details/style.css +3 -0
- package/dist/plugins/form/README.md +111 -0
- package/dist/plugins/form/index.js +102 -0
- package/dist/plugins/form/style.css +41 -0
- package/dist/plugins/gallery/README.md +30 -0
- package/dist/plugins/gallery/client.js +1 -0
- package/dist/plugins/gallery/index.js +74 -0
- package/dist/plugins/gallery/style.css +27 -0
- package/dist/plugins/grid/README.md +33 -0
- package/dist/plugins/grid/index.js +33 -0
- package/dist/plugins/grid/style.css +25 -0
- package/dist/plugins/index.js +26 -0
- package/dist/plugins/mermaid/README.md +21 -0
- package/dist/plugins/mermaid/index.js +34 -0
- package/dist/plugins/mermaid/style.css +16 -0
- package/dist/plugins/quiet/README.md +26 -0
- package/dist/plugins/quiet/index.js +17 -0
- package/dist/plugins/terminal/client.js +41 -0
- package/dist/plugins/terminal/host.js +332 -0
- package/dist/plugins/terminal/index.js +171 -0
- package/dist/plugins/terminal/modes.js +32 -0
- package/dist/plugins/terminal/server.js +256 -0
- package/dist/plugins/terminal/sizes.js +57 -0
- package/dist/plugins/terminal/style.css +357 -0
- package/dist/solid/index.js +35 -0
- package/dist/src/auth.js +54 -0
- package/dist/src/client/page/base.css +274 -0
- package/dist/src/client/page/main.js +1004 -0
- package/dist/src/config.js +76 -0
- package/dist/src/events.js +162 -0
- package/dist/src/html.js +34 -0
- package/dist/src/load.js +77 -0
- package/dist/src/loader.js +120 -0
- package/dist/src/package.js +33 -0
- package/dist/src/pages/blocks.js +49 -0
- package/dist/src/pages/index.js +14 -0
- package/dist/src/pages/markdown.js +307 -0
- package/dist/src/pages/render.js +257 -0
- package/dist/src/plugins.js +238 -0
- package/dist/src/running.js +24 -0
- package/dist/src/serve.js +71 -0
- package/dist/src/server.js +700 -0
- package/dist/src/status.js +43 -0
- package/package.json +131 -4
- package/plugins/callout/README.md +13 -0
- package/plugins/callout/index.ts +25 -0
- package/plugins/callout/style.css +12 -0
- package/plugins/chat/README.md +45 -0
- package/plugins/chat/autosize.ts +101 -0
- package/plugins/chat/client.tsx +81 -0
- package/plugins/chat/index.ts +61 -0
- package/plugins/chat/style.css +17 -0
- package/plugins/claude-code/index.ts +136 -0
- package/plugins/code/README.md +42 -0
- package/plugins/code/diff.ts +58 -0
- package/plugins/code/index.ts +94 -0
- package/plugins/code/style.css +29 -0
- package/plugins/comments/client.ts +448 -0
- package/plugins/comments/index.ts +52 -0
- package/plugins/comments/style.css +32 -0
- package/plugins/details/README.md +17 -0
- package/plugins/details/index.ts +21 -0
- package/plugins/details/style.css +3 -0
- package/plugins/form/README.md +111 -0
- package/plugins/form/index.ts +104 -0
- package/plugins/form/style.css +41 -0
- package/plugins/gallery/README.md +30 -0
- package/plugins/gallery/client.tsx +64 -0
- package/plugins/gallery/index.ts +67 -0
- package/plugins/gallery/style.css +27 -0
- package/plugins/grid/README.md +33 -0
- package/plugins/grid/index.ts +36 -0
- package/plugins/grid/style.css +25 -0
- package/plugins/index.ts +19 -0
- package/plugins/mermaid/README.md +21 -0
- package/plugins/mermaid/index.ts +39 -0
- package/plugins/mermaid/style.css +16 -0
- package/plugins/quiet/README.md +26 -0
- package/plugins/quiet/index.ts +27 -0
- package/plugins/terminal/client.ts +317 -0
- package/plugins/terminal/host.ts +326 -0
- package/plugins/terminal/index.ts +138 -0
- package/plugins/terminal/modes.ts +30 -0
- package/plugins/terminal/server.ts +215 -0
- package/plugins/terminal/sizes.ts +60 -0
- package/plugins/terminal/style.css +71 -0
- package/skills/whiteboard/SKILL.md +292 -0
- package/solid/index.tsx +56 -0
- package/src/auth.ts +66 -0
- package/src/client/forms.ts +186 -0
- package/src/client/page/base.css +274 -0
- package/src/client/page/fresh.ts +205 -0
- package/src/client/page/main.ts +249 -0
- package/src/client/page/orphans.ts +46 -0
- package/src/client/page/theme.ts +32 -0
- package/src/client/page/view.ts +9 -0
- package/src/client/page/waiting.ts +109 -0
- package/src/client/runtime.ts +170 -0
- package/src/config.ts +96 -0
- package/src/define.ts +546 -0
- package/src/events.ts +194 -0
- package/src/html.ts +40 -0
- package/src/load.ts +89 -0
- package/src/loader.ts +109 -0
- package/src/package.ts +39 -0
- package/src/pages/blocks.ts +67 -0
- package/src/pages/index.ts +36 -0
- package/src/pages/markdown.ts +276 -0
- package/src/pages/render.ts +196 -0
- package/src/plugins.ts +197 -0
- package/src/running.ts +22 -0
- package/src/serve.ts +52 -0
- package/src/server.ts +644 -0
- package/src/status.ts +69 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { statusLines, whose } from "../../src/status.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
// plugins/claude-code/index.ts
|
|
6
|
+
/** What is open on a page, in short phrases; the command that picks it up comes last, once. */
|
|
7
|
+
const openOn = (p, options) => statusLines(p, relFile(p.file), options);
|
|
8
|
+
const MODES = {
|
|
9
|
+
stop: "Stop",
|
|
10
|
+
prompt: "UserPromptSubmit",
|
|
11
|
+
session: "SessionStart"
|
|
12
|
+
};
|
|
13
|
+
/** A hook command this plugin installs. */
|
|
14
|
+
const OURS = /\bwhiteboard claude-code hook\b/;
|
|
15
|
+
function claudeCode() {
|
|
16
|
+
return {
|
|
17
|
+
name: "claude-code",
|
|
18
|
+
session: () => process.env.CLAUDE_CODE_SESSION_ID || null,
|
|
19
|
+
commands: {
|
|
20
|
+
hook: {
|
|
21
|
+
description: "what Claude Code runs on an event (stop, prompt or session): report what is open on the session's pages; never blocks",
|
|
22
|
+
args: "<stop|prompt|session>",
|
|
23
|
+
async run(ctx) {
|
|
24
|
+
const mode = ctx.positionals[0];
|
|
25
|
+
if (!mode || !(mode in MODES)) throw new Error(`usage: whiteboard claude-code hook <${Object.keys(MODES).join("|")}>`);
|
|
26
|
+
try {
|
|
27
|
+
await hook(ctx, mode);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
console.error(`whiteboard claude-code hook ${mode}: ${err.message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
install: {
|
|
34
|
+
description: "add the hooks to this project's .claude/settings.json",
|
|
35
|
+
run: (ctx) => install(ctx.project.dir)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** The JSON Claude Code passes a hook on its standard input, or nothing. */
|
|
41
|
+
function hookInput() {
|
|
42
|
+
if (process.stdin.isTTY) return {};
|
|
43
|
+
try {
|
|
44
|
+
return JSON.parse(fs.readFileSync(0, "utf8") || "{}");
|
|
45
|
+
} catch {
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const relFile = (file) => path.relative(process.cwd(), file) || file;
|
|
50
|
+
async function hook(ctx, mode) {
|
|
51
|
+
const session = hookInput().session_id ?? process.env.CLAUDE_CODE_SESSION_ID ?? null;
|
|
52
|
+
const busy = (await ctx.status()).filter((p) => p.unpicked.length || p.open.length);
|
|
53
|
+
const mine = busy.filter((p) => session && p.owner === session);
|
|
54
|
+
if (mode === "stop") {
|
|
55
|
+
const loose = mine.filter((p) => p.unheard.length || p.unpicked.length);
|
|
56
|
+
if (!loose.length) return;
|
|
57
|
+
const said = (p) => {
|
|
58
|
+
const l = openOn(p, { waiting: false });
|
|
59
|
+
return `${l.slice(0, -1).join("; ")} ${l.at(-1)}`;
|
|
60
|
+
};
|
|
61
|
+
console.log(JSON.stringify({ systemMessage: `whiteboard: ${loose.map((p) => `${p.page}: ${said(p)}`).join(" · ")}` }));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const out = [];
|
|
65
|
+
for (const p of mine) {
|
|
66
|
+
const handed = [];
|
|
67
|
+
await ctx.handOut({
|
|
68
|
+
page: p.page,
|
|
69
|
+
exact: true
|
|
70
|
+
}, (e) => handed.push(e), { follow: false });
|
|
71
|
+
if (handed.length) {
|
|
72
|
+
out.push(`Answers on your page ${p.page} (${relFile(p.file)}) that no wait picked up; they count as picked up now:`);
|
|
73
|
+
for (const e of handed) out.push(JSON.stringify(e));
|
|
74
|
+
}
|
|
75
|
+
if (p.unheard.length) out.push(`Nobody listens for ${p.unheard.join(", ")} on your page ${p.page}: run \`whiteboard wait --page ${relFile(p.file)}\` in the background.`);
|
|
76
|
+
}
|
|
77
|
+
if (mode === "session") {
|
|
78
|
+
const others = busy.filter((p) => !mine.includes(p));
|
|
79
|
+
if (others.length) {
|
|
80
|
+
out.push("Other pages in this whiteboard project with something open (not this session's; their answers stay for whoever waits on them):");
|
|
81
|
+
for (const p of others) out.push(`- ${p.page} (${whose(p, session)}): ${openOn(p).join(" ")}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (out.length) console.log(out.join("\n"));
|
|
85
|
+
}
|
|
86
|
+
/** Add the hooks to the project's .claude/settings.json, replacing ours that run another command. */
|
|
87
|
+
function install(dir) {
|
|
88
|
+
const file = path.join(dir, ".claude", "settings.json");
|
|
89
|
+
let settings = {};
|
|
90
|
+
if (fs.existsSync(file)) try {
|
|
91
|
+
settings = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
92
|
+
} catch {
|
|
93
|
+
throw new Error(`${file} is not valid JSON; fix it first`);
|
|
94
|
+
}
|
|
95
|
+
const bin = spawnSync("sh", ["-c", "command -v whiteboard"], { encoding: "utf8" }).status === 0 ? "whiteboard" : "npx whiteboard";
|
|
96
|
+
const changed = [];
|
|
97
|
+
const hooks = settings.hooks ??= {};
|
|
98
|
+
for (const [mode, event] of Object.entries(MODES)) {
|
|
99
|
+
const command = `${bin} claude-code hook ${mode}`;
|
|
100
|
+
const groups = hooks[event] ?? [];
|
|
101
|
+
if (groups.some((g) => g.hooks?.some((h) => h.command === command))) continue;
|
|
102
|
+
hooks[event] = [...groups.map((g) => ({
|
|
103
|
+
...g,
|
|
104
|
+
hooks: (g.hooks ?? []).filter((h) => !OURS.test(h.command ?? ""))
|
|
105
|
+
})).filter((g) => g.hooks.length), { hooks: [{
|
|
106
|
+
type: "command",
|
|
107
|
+
command
|
|
108
|
+
}] }];
|
|
109
|
+
changed.push(event);
|
|
110
|
+
}
|
|
111
|
+
if (!changed.length) {
|
|
112
|
+
console.log(`hooks already installed: ${file}`);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
116
|
+
fs.writeFileSync(`${file}.tmp`, JSON.stringify(settings, null, 2) + "\n");
|
|
117
|
+
fs.renameSync(`${file}.tmp`, file);
|
|
118
|
+
console.log(`hooks added to ${file}: ${changed.join(", ")}`);
|
|
119
|
+
}
|
|
120
|
+
export { claudeCode as default };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Syntax highlighting for code blocks. [Shiki](https://shiki.style) runs on the server, so no script
|
|
2
|
+
runs on the page, and the colours follow the page theme. It applies to every
|
|
3
|
+
fence that no other block claims by name, and to the code view of
|
|
4
|
+
repository files. Write an ordinary fence with a language:
|
|
5
|
+
|
|
6
|
+
````markdown
|
|
7
|
+
```ts
|
|
8
|
+
const page = await whiteboard.show('plan')
|
|
9
|
+
```
|
|
10
|
+
````
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
const page = await whiteboard.show('plan')
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
A `diff` fence (what `git diff` or `diff -u` prints) is shown for reading:
|
|
17
|
+
each file's headers become its name, a hunk's `@@ … @@` line becomes a `⋯`
|
|
18
|
+
where lines are skipped, lines have their numbers in a gutter and are tinted
|
|
19
|
+
when added or removed. Each line in a hunk also says where it is from
|
|
20
|
+
(`src/a.ts:12`), and a comment on it records that. Use four
|
|
21
|
+
backticks around it, since a diff can hold three.
|
|
22
|
+
|
|
23
|
+
A missing or unknown language renders as plain text. Fences named after
|
|
24
|
+
another block, such as `mermaid`, still go to that block.
|
|
25
|
+
|
|
26
|
+
It's a built-in plugin. For options, replace it in the config with your own
|
|
27
|
+
`code(…)`:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import code from '@bigmistqke/whiteboard/code'
|
|
31
|
+
|
|
32
|
+
export default defineConfig({
|
|
33
|
+
plugins: [code({
|
|
34
|
+
themes: { light: 'github-light', dark: 'github-dark' }, // any Shiki theme names
|
|
35
|
+
colorReplacements: { 'github-light': { '#e36209': '#0f766e' } }, // per theme
|
|
36
|
+
})],
|
|
37
|
+
})
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Without options it uses the GitHub themes, with their oranges swapped for a
|
|
41
|
+
teal that fits the default palette. If you pass `themes`, nothing is swapped
|
|
42
|
+
unless you also pass `colorReplacements`.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// plugins/code/diff.ts
|
|
2
|
+
const unprefix = (p) => p.replace(/\t.*$/, "").replace(/^"|"$/g, "").replace(/^[ab]\//, "");
|
|
3
|
+
function diffLines(text) {
|
|
4
|
+
let file = "", oldFile = "", oldN = 0, newN = 0, inHunk = false;
|
|
5
|
+
let status = "", renamedFrom = "";
|
|
6
|
+
return text.split("\n").map((line) => {
|
|
7
|
+
const at = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(line);
|
|
8
|
+
if (at) {
|
|
9
|
+
oldN = Number(at[1]);
|
|
10
|
+
newN = Number(at[2]);
|
|
11
|
+
inHunk = true;
|
|
12
|
+
return {
|
|
13
|
+
kind: "hunk",
|
|
14
|
+
label: ""
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (inHunk) {
|
|
18
|
+
const sign = line[0];
|
|
19
|
+
const where = (side, n) => {
|
|
20
|
+
const name = side === "old" ? oldFile || file : file || oldFile;
|
|
21
|
+
return name ? {
|
|
22
|
+
n,
|
|
23
|
+
at: side === "old" ? `${name} (old):${n}` : `${name}:${n}`
|
|
24
|
+
} : { n };
|
|
25
|
+
};
|
|
26
|
+
if (sign === "+") return {
|
|
27
|
+
kind: "add",
|
|
28
|
+
...where("new", newN++)
|
|
29
|
+
};
|
|
30
|
+
if (sign === "-") return {
|
|
31
|
+
kind: "del",
|
|
32
|
+
...where("old", oldN++)
|
|
33
|
+
};
|
|
34
|
+
if (sign === " ") {
|
|
35
|
+
oldN++;
|
|
36
|
+
return {
|
|
37
|
+
kind: "context",
|
|
38
|
+
...where("new", newN++)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (sign === "\\") return { kind: "meta" };
|
|
42
|
+
inHunk = false;
|
|
43
|
+
}
|
|
44
|
+
if (line.startsWith("diff --git ")) {
|
|
45
|
+
file = "";
|
|
46
|
+
oldFile = "";
|
|
47
|
+
status = "";
|
|
48
|
+
renamedFrom = "";
|
|
49
|
+
} else if (line.startsWith("new file mode")) status = "new";
|
|
50
|
+
else if (line.startsWith("deleted file mode")) status = "deleted";
|
|
51
|
+
else if (line.startsWith("rename from ")) renamedFrom = line.slice(12);
|
|
52
|
+
else if (line.startsWith("--- ")) oldFile = line === "--- /dev/null" ? "" : unprefix(line.slice(4));
|
|
53
|
+
else if (line.startsWith("+++ ")) {
|
|
54
|
+
file = line === "+++ /dev/null" ? "" : unprefix(line.slice(4));
|
|
55
|
+
const name = renamedFrom ? `${renamedFrom} → ${file}` : file || oldFile;
|
|
56
|
+
return {
|
|
57
|
+
kind: "file",
|
|
58
|
+
label: status ? `${name} (${status})` : name
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return { kind: "meta" };
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export { diffLines };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { diffLines } from "./diff.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { definePlugin } from "@bigmistqke/whiteboard";
|
|
4
|
+
// plugins/code/index.ts
|
|
5
|
+
const DEFAULT_THEMES = {
|
|
6
|
+
light: "github-light",
|
|
7
|
+
dark: "github-dark"
|
|
8
|
+
};
|
|
9
|
+
const DEFAULT_REPLACEMENTS = {
|
|
10
|
+
"github-light": {
|
|
11
|
+
"#e36209": "#0f766e",
|
|
12
|
+
"#b08800": "#0f766e"
|
|
13
|
+
},
|
|
14
|
+
"github-dark": {
|
|
15
|
+
"#ffab70": "#5eead4",
|
|
16
|
+
"#c24e00": "#2dd4bf"
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
function code(options = {}) {
|
|
20
|
+
const themes = options.themes ?? DEFAULT_THEMES;
|
|
21
|
+
const colorReplacements = options.colorReplacements ?? (options.themes ? {} : DEFAULT_REPLACEMENTS);
|
|
22
|
+
let highlighter;
|
|
23
|
+
let shiki;
|
|
24
|
+
const loaded = /* @__PURE__ */ new Set();
|
|
25
|
+
/** Highlight `code` as `lang`; an unknown or missing language renders as plain text. */
|
|
26
|
+
async function highlight(code, lang) {
|
|
27
|
+
shiki ??= await import("shiki");
|
|
28
|
+
highlighter ??= shiki.createHighlighter({
|
|
29
|
+
themes: Object.values(themes),
|
|
30
|
+
langs: []
|
|
31
|
+
});
|
|
32
|
+
const h = await highlighter;
|
|
33
|
+
let language = String(lang ?? "").toLowerCase();
|
|
34
|
+
if (language in shiki.bundledLanguages) {
|
|
35
|
+
if (!loaded.has(language)) {
|
|
36
|
+
await h.loadLanguage(language);
|
|
37
|
+
loaded.add(language);
|
|
38
|
+
}
|
|
39
|
+
} else language = "text";
|
|
40
|
+
const diff = language === "diff" ? diffLines(code) : null;
|
|
41
|
+
return h.codeToHtml(code, {
|
|
42
|
+
lang: language,
|
|
43
|
+
themes,
|
|
44
|
+
defaultColor: false,
|
|
45
|
+
colorReplacements,
|
|
46
|
+
transformers: diff ? [{
|
|
47
|
+
line(node, n) {
|
|
48
|
+
const info = diff[n - 1];
|
|
49
|
+
if (!info) return;
|
|
50
|
+
node.properties["data-diff"] = info.kind;
|
|
51
|
+
if (info.n != null) node.properties["data-n"] = String(info.n);
|
|
52
|
+
if (info.at) node.properties["data-wb-at"] = info.at;
|
|
53
|
+
if (info.label != null) node.children = [{
|
|
54
|
+
type: "text",
|
|
55
|
+
value: info.label
|
|
56
|
+
}];
|
|
57
|
+
},
|
|
58
|
+
code(node) {
|
|
59
|
+
node.children = node.children.filter((child, i, all) => {
|
|
60
|
+
const isMeta = (c) => c?.type === "element" && c.properties["data-diff"] === "meta";
|
|
61
|
+
return !isMeta(child) && !(child.type === "text" && isMeta(all[i - 1]));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}] : []
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return definePlugin({
|
|
68
|
+
name: "code",
|
|
69
|
+
blocks: { code: {
|
|
70
|
+
fence: "any",
|
|
71
|
+
html: (ctx) => highlight(ctx.text, ctx.lang),
|
|
72
|
+
style: new URL("./style.css", import.meta.url)
|
|
73
|
+
} },
|
|
74
|
+
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export { code as default };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* Code blocks highlighted by Shiki: tokens carry both colours; pick the one for the current theme.
|
|
2
|
+
The block keeps the page's own code background. */
|
|
3
|
+
pre.shiki { background: var(--code-bg); }
|
|
4
|
+
.shiki span {
|
|
5
|
+
color: var(--shiki-light); font-style: var(--shiki-light-font-style);
|
|
6
|
+
font-weight: var(--shiki-light-font-weight); text-decoration: var(--shiki-light-text-decoration);
|
|
7
|
+
}
|
|
8
|
+
@media (prefers-color-scheme: dark) {
|
|
9
|
+
:root:not([data-theme="light"]) .shiki span {
|
|
10
|
+
color: var(--shiki-dark); font-style: var(--shiki-dark-font-style);
|
|
11
|
+
font-weight: var(--shiki-dark-font-weight); text-decoration: var(--shiki-dark-text-decoration);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
:root[data-theme="dark"] .shiki span {
|
|
15
|
+
color: var(--shiki-dark); font-style: var(--shiki-dark-font-style);
|
|
16
|
+
font-weight: var(--shiki-dark-font-weight); text-decoration: var(--shiki-dark-text-decoration);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* a diff: one row per line, as wide as the longest (a grid leaves out the line breaks between them,
|
|
20
|
+
which stay in the text), tinted by what it is, with its number in a gutter */
|
|
21
|
+
.shiki code:has(> .line[data-diff]) { display: grid; width: max-content; min-width: 100%; }
|
|
22
|
+
.shiki .line[data-diff=add] { background: color-mix(in srgb, #16a34a 14%, transparent); }
|
|
23
|
+
.shiki .line[data-diff=del] { background: color-mix(in srgb, #dc2626 14%, transparent); }
|
|
24
|
+
.shiki .line[data-diff]::before { content: attr(data-n); display: inline-block; width: 4ch; margin-right: 1.5ch; text-align: right; color: var(--muted, #696e76); opacity: .7; user-select: none; }
|
|
25
|
+
:root .shiki .line[data-diff=hunk] { color: var(--muted, #696e76); line-height: 1.2; margin: 2px 0; }
|
|
26
|
+
.shiki .line[data-diff=hunk]::before { content: '⋯'; text-align: center; }
|
|
27
|
+
.shiki .line[data-diff=file] { font-weight: 600; margin-bottom: 8px; }
|
|
28
|
+
.shiki .line[data-diff=file]::before { content: none; }
|
|
29
|
+
.shiki .line[data-diff=file] + .line[data-diff=hunk] { margin-top: 0; }
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var e=class{value;constructor(e){this.value=e}toString(){return this.value}};const t={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},n=e=>String(e).replace(/[&<>"']/g,e=>t[e]);function r(t){return t==null||t===!1?``:t instanceof e?t.value:Array.isArray(t)?t.map(r).join(``):n(t)}function i(t,...n){let i=t[0];for(let e=0;e<n.length;e++)i+=r(n[e])+t[e+1];return new e(i)}const a=`comments:new`,o=`comments:reply`,s=`comments:resolve`;let c,l,u,d=[],f=null;const p=document.createElement(`div`);p.className=`wb-comments`;const m=document.createElement(`button`);m.type=`button`,m.className=`wb-comment-start`,m.textContent=`Comment`,m.hidden=!0;const h=document.createElement(`div`);h.className=`wb-thread`,h.hidden=!0;function g(){let e=[],t=``,n=document.createTreeWalker(u,NodeFilter.SHOW_TEXT,{acceptNode:e=>e.parentElement?.closest(`script, style, textarea`)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT});for(let r=n.nextNode();r;r=n.nextNode())e.push({node:r,start:t.length}),t+=r.data;return{text:t,nodes:e}}function _(e,t,n){for(let r=0;r<e.nodes.length;r++){let{node:i,start:a}=e.nodes[r],o=a+i.data.length;if(t<o||n&&t===o||r===e.nodes.length-1)return{node:i,offset:Math.min(Math.max(t-a,0),i.data.length)}}return null}function v(e,t){let n=(t,n)=>{if(t.nodeType===Node.TEXT_NODE){let r=e.nodes.find(e=>e.node===t);return r?r.start+n:null}let r=document.createRange();r.setStart(u,0),r.setEnd(t,n);let i=0;for(let{node:t,start:n}of e.nodes)r.intersectsNode(t)&&(i=n+t.data.length);return i},r=n(t.startContainer,t.startOffset),i=n(t.endContainer,t.endOffset);return r==null||i==null?null:{start:r,end:i}}function y(e,t){let n=String(t.quote??``);if(!n)return null;let r=String(t.before??``),i=String(t.after??``),a=-1,o=-1;for(let t=e.text.indexOf(n);t>=0;t=e.text.indexOf(n,t+1)){let s=e.text.slice(Math.max(0,t-r.length),t),c=e.text.slice(t+n.length,t+n.length+i.length),l=0;for(;l<s.length&&s[s.length-1-l]===r[r.length-1-l];)l++;let u=0;for(;u<c.length&&c[u]===i[u];)u++;l+u>o&&(a=t,o=l+u)}if(a<0)return null;let s=_(e,a,!1),c=_(e,a+n.length,!0);if(!s||!c)return null;let l=document.createRange();return l.setStart(s.node,s.offset),l.setEnd(c.node,c.offset),l}function b(){let e=l.events(),t=new Set(e.filter(e=>e.type===s).map(e=>String(e.data.replyTo))),n=g();return e.filter(e=>e.type===a&&!t.has(e.id)).map(t=>({id:t.id,comment:t,replies:e.filter(e=>e.type===o&&e.data.replyTo===t.id),range:y(n,t.data)}))}const x=e=>e.replies.at(-1)?.from===`cli`;function S(){let e=CSS.highlights,t=window.Highlight;if(e&&t){e.set(`wb-comment`,new t(...d.filter(e=>e.range&&e.id!==f).map(e=>e.range)));let n=d.find(e=>e.id===f)?.range;n?e.set(`wb-comment-active`,new t(n)):e.delete(`wb-comment-active`)}let n=u.getBoundingClientRect();p.replaceChildren(...d.map((e,t)=>{let r=document.createElement(`button`);r.type=`button`,r.className=`wb-comment-badge`,r.dataset.thread=e.id,r.toggleAttribute(`data-agent`,x(e)),r.title=x(e)?`the agent replied`:`comment`,r.textContent=String(1+e.replies.length);let i=e.range?.getClientRects()[0],a=i?i.top+scrollY:n.top+scrollY+t*30,o=Math.min(n.right+8+scrollX,document.documentElement.clientWidth-36+scrollX);return r.style.top=`${a}px`,r.style.left=`${o}px`,i||(r.dataset.detached=``),r})),f&&T()}function C(){c&&(u=c.querySelector(`main`)??c,d=b(),f&&!d.some(e=>e.id===f)?D():f&&w(),S())}function w(){let e=d.find(e=>e.id===f);if(!e)return;let t=e=>e.from===`cli`?`agent`:`you`,n=e=>i`<div class="wb-thread-message" data-from="${t(e)}"><span class="wb-thread-who">${t(e)}</span><div class="wb-thread-text">${e.data.text??``}</div></div>`,r=h.querySelector(`textarea`)?.value??``;h.innerHTML=String(i`
|
|
2
|
+
<blockquote class="wb-thread-quote">${e.comment.data.quote??``}</blockquote>
|
|
3
|
+
${e.comment.data.at&&i`<p class="wb-thread-at">${e.comment.data.at}</p>`}
|
|
4
|
+
${!e.range&&i`<p class="wb-thread-detached">This passage is no longer on the page.</p>`}
|
|
5
|
+
${[e.comment,...e.replies].map(n)}
|
|
6
|
+
<form class="wb-thread-reply">
|
|
7
|
+
<textarea rows="2" placeholder="Reply"></textarea>
|
|
8
|
+
<div class="wb-thread-actions"><button type="submit" class="wb-comment-button wb-comment-primary">Reply</button><button type="button" class="wb-comment-button" data-close>Close thread</button></div>
|
|
9
|
+
</form>`),h.querySelector(`textarea`).value=r}function T(){let e=p.querySelector(`[data-thread="${f}"]`);if(!e)return;let t=parseFloat(e.style.top)+28,n=Math.min(360,document.documentElement.clientWidth-32),r=Math.max(16+scrollX,Math.min(parseFloat(e.style.left)+28-n,document.documentElement.clientWidth-n-16+scrollX));h.style.top=`${t}px`,h.style.left=`${r}px`,h.style.width=`${n}px`}function E(e){f=e,h.hidden=!1,h.querySelector(`textarea`)?.replaceWith(document.createElement(`textarea`)),w(),S(),h.querySelector(`textarea`)?.focus({preventScroll:!0})}function D(){f=null,h.hidden=!0,S()}let O=null;function k(){u=c.querySelector(`main`)??c;let e=getSelection();if(!e||e.isCollapsed||!e.rangeCount){m.matches(`:focus`)||(m.hidden=!0);return}let t=e.getRangeAt(0),n=e=>u.contains(e)&&!(e instanceof Element?e:e.parentElement)?.closest(`form, input, textarea, select, button`);!n(t.startContainer)||!n(t.endContainer)?m.hidden=!0:m.hidden=!A(t)}function A(e){let t=e.toString().trim();if(!t)return!1;let n=g(),r=v(n,e);if(!r)return!1;let i=n.text.indexOf(t,r.start),a=i>=0&&i<=r.end?i:r.start,o=e.startContainer instanceof Element?e.startContainer:e.startContainer.parentElement;for(;o&&o.parentElement!==u;)o=o.parentElement;O={quote:t,before:n.text.slice(Math.max(0,a-32),a),after:n.text.slice(a+t.length,a+t.length+32),block:o?[...u.children].indexOf(o):-1};let s=[...u.querySelectorAll(`[data-wb-at]`)].filter(t=>e.intersectsNode(t)&&t.textContent).map(e=>e.dataset.wbAt);s.length&&(O.at=s.length>1&&s.at(-1)!==s[0]?`${s[0]} – ${s.at(-1)}`:s[0]);let c=e.getClientRects(),l=c[c.length-1]??e.getBoundingClientRect();return m.style.top=`${l.bottom+scrollY+6}px`,m.style.left=`${Math.min(l.right+scrollX-40,document.documentElement.clientWidth-110+scrollX)}px`,!0}const j=document.createElement(`button`);j.type=`button`,j.className=`wb-line-comment`,j.textContent=`+`,j.title=`Comment on this line (drag for several)`,j.hidden=!0;let M=null,N=null;const P=e=>{let t=e instanceof Element?e.closest(`pre .line`):null;return t&&u.contains(t)&&!t.closest(`form`)?t:null};function F(e,t){let[n,r]=e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_PRECEDING?[t,e]:[e,t],i=document.createRange();return i.setStart(n,0),i.setEnd(r,r.childNodes.length),i}function I(e){M=e;let t=e.getBoundingClientRect(),n=e.closest(`pre`).getBoundingClientRect();j.style.top=`${t.top+scrollY+t.height/2-10}px`,j.style.left=`${Math.max(scrollX+2,n.left+scrollX-24)}px`,j.hidden=!1}function L(e){if(N){let t=N.pre.getBoundingClientRect(),n=N.from.getBoundingClientRect().left+4,r=P(document.elementFromPoint(n,Math.min(Math.max(e.clientY,t.top+1),t.bottom-1)));if(r&&N.pre.contains(r)&&r!==N.to){N.to=r;let e=CSS.highlights,t=window.Highlight;e&&t&&e.set(`wb-comment-active`,new t(F(N.from,N.to)))}return}if(e.target===j)return;let t=P(e.target);if(t)return I(t);if(j.hidden||!M)return;let n=M.closest(`pre`),r=n.getBoundingClientRect(),i=j.getBoundingClientRect(),a=e.clientX>=i.left-4&&e.clientX<=r.right&&e.clientY>=r.top&&e.clientY<=r.bottom,o=a?P(document.elementFromPoint(M.getBoundingClientRect().left+4,e.clientY)):null;o&&n.contains(o)?I(o):a&&e.clientY>=i.top-4&&e.clientY<=i.bottom+4||(j.hidden=!0,M=null)}const R=document.createElement(`form`);R.className=`wb-thread wb-comment-new`,R.hidden=!0,R.innerHTML=String(i`<blockquote class="wb-thread-quote"></blockquote><textarea rows="3" placeholder="Your comment"></textarea>
|
|
10
|
+
<div class="wb-thread-actions"><button type="submit" class="wb-comment-button wb-comment-primary">Comment</button><button type="button" class="wb-comment-button" data-cancel>Cancel</button></div>`);function z(){if(!O)return;R.querySelector(`blockquote`).textContent=O.at?`${O.at}\n${O.quote}`:O.quote,R.style.top=m.style.top;let e=Math.min(360,document.documentElement.clientWidth-32);R.style.width=`${e}px`,R.style.left=`${Math.max(16+scrollX,Math.min(parseFloat(m.style.left),document.documentElement.clientWidth-e-16+scrollX))}px`,R.hidden=!1,m.hidden=!0,R.querySelector(`textarea`).focus({preventScroll:!0})}const B=(e,t,n)=>{if(t.kind!==`page`&&t.kind!==`file`)return;c=e,u=c.querySelector(`main`)??c,l=n,document.body.append(p,m,j,h,R),document.addEventListener(`mousemove`,L),document.documentElement.addEventListener(`mouseleave`,()=>{N||(j.hidden=!0,M=null)}),j.addEventListener(`mousedown`,e=>{if(!M||e.button!==0)return;e.preventDefault();let t=CSS.highlights,n=window.Highlight;t&&n&&t.set(`wb-comment-active`,new n(F(M,M))),N={pre:M.closest(`pre`),from:M,to:M}}),document.addEventListener(`mouseup`,()=>{if(!N)return;let{from:e,to:t}=N;N=null,j.hidden=!0,A(F(e,t))?z():S()});let r=0;document.addEventListener(`selectionchange`,()=>{clearTimeout(r),r=window.setTimeout(k,150)}),m.addEventListener(`mousedown`,e=>e.preventDefault()),m.addEventListener(`click`,z),R.addEventListener(`submit`,async e=>{e.preventDefault();let t=R.querySelector(`textarea`).value.trim();if(!t||!O)return;let n=await l.append(a,{...O,text:t});R.querySelector(`textarea`).value=``,R.hidden=!0,O=null,getSelection()?.removeAllRanges(),C(),E(n.id)}),R.querySelector(`[data-cancel]`).addEventListener(`click`,()=>{R.hidden=!0,O=null}),p.addEventListener(`click`,e=>{let t=e.target.closest(`[data-thread]`)?.dataset.thread;t&&(f===t?D():E(t))}),h.addEventListener(`submit`,async e=>{e.preventDefault();let t=h.querySelector(`textarea`),n=t.value.trim();n&&f&&(await l.append(o,{replyTo:f,text:n}),t.value=``,C())}),h.addEventListener(`click`,async e=>{if(!e.target.closest(`[data-close]`)||!f)return;let t=f;D(),await l.append(s,{replyTo:t}),C()}),document.addEventListener(`keydown`,e=>{e.key===`Escape`&&(R.hidden?f&&D():(R.hidden=!0,O=null))}),l.onEvents(C),l.onRendered(C),new ResizeObserver(()=>S()).observe(c),addEventListener(`resize`,()=>S()),C()};export{B as default};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { packagePath } from "../../src/package.js";
|
|
2
|
+
// plugins/comments/index.ts
|
|
3
|
+
const CLIENT = packagePath("dist/plugins/comments/client.js");
|
|
4
|
+
const STYLE = packagePath("dist/plugins/comments/style.css");
|
|
5
|
+
const DOCS = `## Comments
|
|
6
|
+
|
|
7
|
+
The reader can select text on any page and comment on it, or comment on
|
|
8
|
+
whole lines of a code block (a "+" beside each line; dragging it takes
|
|
9
|
+
several). Each comment comes to you as an event on the page, like a form
|
|
10
|
+
answer:
|
|
11
|
+
|
|
12
|
+
\`\`\`json
|
|
13
|
+
{"id":"…","page":"plan","type":"comments:new","data":{"quote":"the selected text","before":"…","after":"…","block":3,"text":"their comment"}}
|
|
14
|
+
\`\`\`
|
|
15
|
+
|
|
16
|
+
On lines that say where they are from, \`data.at\` says it too: in a
|
|
17
|
+
\`diff\` fence, \`"src/a.ts:12"\` (a line of the new file), \`"src/a.ts (old):9"\`
|
|
18
|
+
(a removed line), or \`"src/a.ts:12 – src/a.ts:15"\` for several. Any block
|
|
19
|
+
can say where its parts are from with a \`data-wb-at\` attribute.
|
|
20
|
+
|
|
21
|
+
Replies to a thread come as \`comments:reply\` (\`data.replyTo\` is the comment's
|
|
22
|
+
id), and \`comments:resolve\` when the reader closed it. A thread stays on the
|
|
23
|
+
page until the reader closes it. Answer a comment the way it asks:
|
|
24
|
+
|
|
25
|
+
- **It asks for a change:** edit the page. The thread stays, so say what you
|
|
26
|
+
changed in a reply if it is not obvious.
|
|
27
|
+
- **It asks a question:** reply in the thread:
|
|
28
|
+
\`whiteboard append --page <file> --type comments:reply --data '{"replyTo":"<comment id>","text":"…"}'\`
|
|
29
|
+
|
|
30
|
+
Your replies show as the agent's, and \`wait\` and \`watch\` skip what you
|
|
31
|
+
append, so you don't hear your own replies.`;
|
|
32
|
+
function comments() {
|
|
33
|
+
return {
|
|
34
|
+
name: "comments",
|
|
35
|
+
docs: () => DOCS,
|
|
36
|
+
events: {
|
|
37
|
+
"comments:new": {
|
|
38
|
+
handOut: true,
|
|
39
|
+
description: "a comment on a passage or lines of code: `{ quote, before, after, block, at?, text }`; its id is the thread's"
|
|
40
|
+
},
|
|
41
|
+
"comments:reply": {
|
|
42
|
+
handOut: true,
|
|
43
|
+
description: "a reply in a thread: `{ replyTo, text }`"
|
|
44
|
+
},
|
|
45
|
+
"comments:resolve": { description: "the reader closed a thread: `{ replyTo }`" }
|
|
46
|
+
},
|
|
47
|
+
style: STYLE,
|
|
48
|
+
setup: () => ({ client: CLIENT })
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export { comments as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Comments: highlights through the CSS Highlight API, badges and threads above the page. Colors
|
|
3
|
+
* and fonts come from the page's theme variables, else from
|
|
4
|
+
* the fallbacks here.
|
|
5
|
+
*/
|
|
6
|
+
::highlight(wb-comment) { background-color: color-mix(in srgb, var(--accent, #1d5bbf) 18%, transparent); }
|
|
7
|
+
::highlight(wb-comment-active) { background-color: color-mix(in srgb, var(--accent, #1d5bbf) 34%, transparent); }
|
|
8
|
+
.wb-comment-start, .wb-comment-badge, .wb-thread { position: absolute; z-index: 20; font-family: var(--sans, sans-serif); }
|
|
9
|
+
.wb-comment-start[hidden], .wb-thread[hidden], .wb-line-comment[hidden] { display: none; }
|
|
10
|
+
.wb-comment-start { background: var(--accent, #1d5bbf); color: var(--accent-text, #fff); border-color: var(--accent, #1d5bbf); border-radius: 99px; font-size: .78rem; padding: 3px 10px; box-shadow: 0 2px 8px rgb(0 0 0 / .15); }
|
|
11
|
+
.wb-comment-badge { min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px 12px 12px 3px; font-size: .72rem; font-weight: 600; background: var(--bg, Canvas); color: var(--accent, #1d5bbf); border: 1px solid color-mix(in srgb, var(--accent, #1d5bbf) 50%, transparent); }
|
|
12
|
+
.wb-comment-badge[data-agent] { background: var(--accent, #1d5bbf); color: var(--accent-text, #fff); }
|
|
13
|
+
.wb-comment-badge[data-detached] { border-style: dashed; }
|
|
14
|
+
.wb-thread { background: var(--bg, Canvas); border: 1px solid var(--border, #e3e5e9); border-radius: 8px; padding: 12px 14px; box-shadow: 0 8px 28px rgb(0 0 0 / .16); display: grid; gap: 10px; font-size: .9rem; }
|
|
15
|
+
.wb-thread-quote { margin: 0; padding-left: 10px; border-left: 3px solid color-mix(in srgb, var(--accent, #1d5bbf) 50%, transparent); color: var(--muted, #696e76); font-size: .85rem; max-height: 6.5em; overflow: auto; white-space: pre-wrap; }
|
|
16
|
+
.wb-thread-detached { margin: 0; color: var(--muted, #696e76); font-size: .8rem; }
|
|
17
|
+
.wb-thread-message { display: grid; gap: 2px; }
|
|
18
|
+
.wb-thread-who { font-size: .7rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted, #696e76); }
|
|
19
|
+
.wb-thread-message[data-from=agent] .wb-thread-who { color: var(--accent, #1d5bbf); }
|
|
20
|
+
.wb-thread-text { white-space: pre-wrap; line-height: 1.45; }
|
|
21
|
+
.wb-thread textarea { width: 100%; resize: vertical; font: inherit; }
|
|
22
|
+
.wb-thread-reply { display: grid; gap: 8px; margin: 0; }
|
|
23
|
+
.wb-thread-actions { display: flex; gap: 8px; }
|
|
24
|
+
/* its own buttons, styled here rather than borrowed from the page */
|
|
25
|
+
.wb-comment-button { font: 500 .85rem/1.3 var(--sans, sans-serif); padding: 6px 12px; border-radius: 6px; cursor: pointer; border: 1px solid var(--border, #e3e5e9); background: var(--surface, Canvas); color: var(--text, CanvasText); }
|
|
26
|
+
.wb-comment-button:hover { border-color: var(--muted, #696e76); }
|
|
27
|
+
.wb-comment-primary { background: var(--accent, #1d5bbf); color: var(--accent-text, #fff); border-color: var(--accent, #1d5bbf); }
|
|
28
|
+
.wb-comment-start, .wb-comment-badge { cursor: pointer; border-style: solid; border-width: 1px; }
|
|
29
|
+
|
|
30
|
+
/* "+" beside a line of code: comment on it, or drag over several */
|
|
31
|
+
.wb-line-comment { position: absolute; z-index: 20; width: 20px; height: 20px; padding: 0; border-radius: 4px; cursor: pointer; font: 600 14px/1 var(--sans, sans-serif); background: var(--accent, #1d5bbf); color: var(--accent-text, #fff); border: none; box-shadow: 0 1px 4px rgb(0 0 0 / .2); }
|
|
32
|
+
.wb-thread-at { margin: -4px 0 0; font: .78rem var(--mono, monospace); color: var(--muted, #696e76); }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
A collapsible section. The label is the summary line; the body is any
|
|
2
|
+
markdown. Use it to keep in-depth explanation out of the way of the main read.
|
|
3
|
+
Unlike a raw `<details>` tag, the body needs no blank-line care.
|
|
4
|
+
|
|
5
|
+
Attributes: `open` (start expanded).
|
|
6
|
+
|
|
7
|
+
```markdown
|
|
8
|
+
:::details[Why remark-directive instead of MDX?]
|
|
9
|
+
MDX fails the **whole page** on one stray `<` or `{`. Directives that no
|
|
10
|
+
block handles still render as plain markdown.
|
|
11
|
+
:::
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
:::details[Why remark-directive instead of MDX?]
|
|
15
|
+
MDX fails the **whole page** on one stray `<` or `{`. Directives that no
|
|
16
|
+
block handles still render as plain markdown.
|
|
17
|
+
:::
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { definePlugin, html, raw } from "@bigmistqke/whiteboard";
|
|
3
|
+
// plugins/details/index.ts
|
|
4
|
+
async function render(ctx) {
|
|
5
|
+
return html`<details class="wb-details"${"open" in ctx.attrs && raw(" open")}><summary>${ctx.label ? raw(ctx.label) : "Details"}</summary><div class="wb-details-body">${raw(await ctx.toHtml(ctx.children))}</div></details>`;
|
|
6
|
+
}
|
|
7
|
+
function details() {
|
|
8
|
+
return definePlugin({
|
|
9
|
+
name: "details",
|
|
10
|
+
blocks: { details: {
|
|
11
|
+
html: render,
|
|
12
|
+
style: new URL("./style.css", import.meta.url)
|
|
13
|
+
} },
|
|
14
|
+
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export { details as default, render };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
A named form, written as markdown. Submitting it appends
|
|
2
|
+
`{ id, ts, page, type, action, data }` to the events log, where `type` is the
|
|
3
|
+
form's `name`, `action` is the button that was pressed and `data` holds the
|
|
4
|
+
inputs. The form starts from its last answer.
|
|
5
|
+
|
|
6
|
+
The body of `:::form{name=…}` is ordinary markdown, and inputs are inline
|
|
7
|
+
directives that can sit anywhere in it: in a paragraph, a list, a table
|
|
8
|
+
cell, a heading, a grid card. So a question sits with everything that
|
|
9
|
+
explains it.
|
|
10
|
+
|
|
11
|
+
| input | written as | sends |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| one choice | `:radio[This week]{name=when}` per option | the picked label's text, or `null` |
|
|
14
|
+
| several choices | `:check[Android]{name=phones}` per option | an array of the checked labels |
|
|
15
|
+
| one checkbox | `:check[I read it]{name=read}` | `true` or `false` |
|
|
16
|
+
| text | `:text[Title]{name=title placeholder="a short name"}` | the text |
|
|
17
|
+
| more text | `:textarea[Notes]{name=notes}` | the text |
|
|
18
|
+
| number, date, range | `:number[Count]{name=count min=0 max=10}`, `:date[Due]{name=due}`, `:range[…]{name=… min=0 max=100}` | the value |
|
|
19
|
+
| dropdown | `:select[Target]{name=env options="staging, production"}` | the picked option |
|
|
20
|
+
| fixed value | `:hidden{name=version value=2.3}` | the value |
|
|
21
|
+
| buttons | `:button[Approve]` `:button[Hold]` | which one is `action` |
|
|
22
|
+
|
|
23
|
+
- The label in `[…]` is markdown. An option sends its label as plain text
|
|
24
|
+
(`:radio[This **week**]` sends `This week`), unless `value=…` says what
|
|
25
|
+
to send instead.
|
|
26
|
+
- `recommended` tags an option as the writer's recommendation; it is never
|
|
27
|
+
preselected, so a choice is only made by picking it. `checked` does
|
|
28
|
+
preselect one; use it for defaults, not for decisions.
|
|
29
|
+
- Without a `:button`, the form gets one `Send` button. The first button is
|
|
30
|
+
the primary one.
|
|
31
|
+
- `value=…` on `:text`, `:textarea`, `:select` and the others sets what
|
|
32
|
+
they start with.
|
|
33
|
+
|
|
34
|
+
**Options with what they mean.** When the options of a decision need
|
|
35
|
+
explaining, put each one at the start of a list item, with its explanation
|
|
36
|
+
under it. Such an item reads as a row to pick:
|
|
37
|
+
|
|
38
|
+
````markdown
|
|
39
|
+
:::form{name=storage}
|
|
40
|
+
**Where are answers kept?**
|
|
41
|
+
|
|
42
|
+
- :radio[One log per project]{name=where recommended}
|
|
43
|
+
Simple, and the agent waits on one file.
|
|
44
|
+
- :radio[One log per page]{name=where}
|
|
45
|
+
Pages can be moved with their answers.
|
|
46
|
+
:::
|
|
47
|
+
````
|
|
48
|
+
|
|
49
|
+
:::form{name=storage}
|
|
50
|
+
**Where are answers kept?**
|
|
51
|
+
|
|
52
|
+
- :radio[One log per project]{name=where recommended}
|
|
53
|
+
Simple, and the agent waits on one file.
|
|
54
|
+
- :radio[One log per page]{name=where}
|
|
55
|
+
Pages can be moved with their answers.
|
|
56
|
+
:::
|
|
57
|
+
|
|
58
|
+
An option's explanation can be any markdown: a code block, a table, a
|
|
59
|
+
picture, a `:::details` block. Indent it under the item, and mind the
|
|
60
|
+
colons: a container inside the form needs fewer colons than the form, so
|
|
61
|
+
write the form as `::::form` around a `:::details`.
|
|
62
|
+
|
|
63
|
+
**Inputs anywhere.** Since an input is a word-sized element, any layout
|
|
64
|
+
can hold one: a card per option in a grid, a checkbox per row of a table.
|
|
65
|
+
|
|
66
|
+
````markdown
|
|
67
|
+
::::form{name=deploy-review}
|
|
68
|
+
Ship **v2.3** to production?
|
|
69
|
+
|
|
70
|
+
:::grid{cols=2}
|
|
71
|
+
### :radio[Staging]{name=env}
|
|
72
|
+
Runs the migration on a copy first.
|
|
73
|
+
|
|
74
|
+
### :radio[Production]{name=env recommended}
|
|
75
|
+
The migration is reversible.
|
|
76
|
+
:::
|
|
77
|
+
|
|
78
|
+
:textarea[Notes]{name=notes placeholder="anything to check first"}
|
|
79
|
+
|
|
80
|
+
:button[Approve] :button[Hold]
|
|
81
|
+
::::
|
|
82
|
+
````
|
|
83
|
+
|
|
84
|
+
::::form{name=deploy-review}
|
|
85
|
+
Ship **v2.3** to production?
|
|
86
|
+
|
|
87
|
+
:::grid{cols=2}
|
|
88
|
+
### :radio[Staging]{name=env}
|
|
89
|
+
Runs the migration on a copy first.
|
|
90
|
+
|
|
91
|
+
### :radio[Production]{name=env recommended}
|
|
92
|
+
The migration is reversible.
|
|
93
|
+
:::
|
|
94
|
+
|
|
95
|
+
:textarea[Notes]{name=notes placeholder="anything to check first"}
|
|
96
|
+
|
|
97
|
+
:button[Approve] :button[Hold]
|
|
98
|
+
::::
|
|
99
|
+
|
|
100
|
+
Forms don't nest, and inputs belong inside a form: outside one they show
|
|
101
|
+
but send nothing.
|
|
102
|
+
|
|
103
|
+
**A chat under every form.** The reader can ask about a question without
|
|
104
|
+
answering it: under every form is a chat (see the chat plugin), named
|
|
105
|
+
after the form, whose messages are never a submit, so talking about a choice
|
|
106
|
+
never makes it. Answer there with `whiteboard append --type chat:message
|
|
107
|
+
--data '{"chat":"<form name>","text":"…"}'`, and don't add a free-text field
|
|
108
|
+
for questions to a decision form.
|
|
109
|
+
|
|
110
|
+
A hand-written `<form name="…">` (no `action` attribute) is recorded the same
|
|
111
|
+
way; this block only saves typing.
|