@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
|
@@ -9,14 +9,32 @@ import toc from '@bigmistqke/whiteboard/toc'
|
|
|
9
9
|
export default defineConfig({ plugins: [toc()] })
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
A page has it when its frontmatter
|
|
12
|
+
A page has it when its frontmatter asks, under `plugins:` (where every
|
|
13
|
+
plugin's settings for a page go, by the plugin's name):
|
|
13
14
|
|
|
14
15
|
```markdown
|
|
15
16
|
---
|
|
16
|
-
|
|
17
|
+
plugins:
|
|
18
|
+
toc: true
|
|
17
19
|
---
|
|
18
20
|
# A long page
|
|
19
21
|
```
|
|
20
22
|
|
|
21
23
|
To have it on every page, `toc({ always: true })`; a page then goes without
|
|
22
|
-
with `toc: false
|
|
24
|
+
with `toc: false` there.
|
|
25
|
+
|
|
26
|
+
The panel fits its items, between a minimum and a maximum width (160px and
|
|
27
|
+
320px by default). A project sets its own in the options, and a page in its
|
|
28
|
+
frontmatter, which is then also how it asks for the contents:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
toc({ minWidth: 180, maxWidth: '24rem' }) // pixels, or a CSS length
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```markdown
|
|
35
|
+
---
|
|
36
|
+
plugins:
|
|
37
|
+
toc:
|
|
38
|
+
maxWidth: 240px
|
|
39
|
+
---
|
|
40
|
+
```
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { builtinPublic } from "../../src/package.js";
|
|
2
|
+
import { html } from "../../src/html.js";
|
|
2
3
|
// plugins/toc/index.ts
|
|
3
4
|
const DOCS = `## Table of contents
|
|
4
5
|
|
|
@@ -9,12 +10,17 @@ in it. A section with an unanswered question or an unread message has a dot.
|
|
|
9
10
|
function toc(options = {}) {
|
|
10
11
|
return {
|
|
11
12
|
name: "toc",
|
|
12
|
-
docs: () => options.always ? DOCS + "\nIn this project every page has it; a page without
|
|
13
|
+
docs: () => options.always ? DOCS + "\nIn this project every page has it; a page goes without with `toc: false` under `plugins:` in its frontmatter:\n\n```markdown\n---\nplugins:\n toc: false\n---\n```\n" : DOCS + "\nA page has it when its frontmatter asks, under `plugins:`:\n\n```markdown\n---\nplugins:\n toc: true\n---\n# A long page\n```\n",
|
|
13
14
|
public: builtinPublic("toc"),
|
|
14
15
|
style: "style.css",
|
|
15
16
|
setup: () => ({
|
|
16
17
|
client: "client.js",
|
|
17
|
-
shell: () => ({ head: `<meta
|
|
18
|
+
shell: () => ({ head: html`<meta
|
|
19
|
+
name="wb-toc"
|
|
20
|
+
content="${options.always ? "always" : "opt-in"}"
|
|
21
|
+
${options.minWidth != null ? html` data-min-width="${String(options.minWidth)}"` : ""}
|
|
22
|
+
${options.maxWidth != null ? html` data-max-width="${String(options.maxWidth)}"` : ""}
|
|
23
|
+
/>` })
|
|
18
24
|
})
|
|
19
25
|
};
|
|
20
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=document.createElement(`nav`);e.className=`wb-toc`,e.setAttribute(`aria-label`,`Contents`);const t=document.createElement(`ol`);e.append(t);const n=document.createElement(`button`);n.type=`button`,n.className=`wb-toc-toggle`,n.title=n.ariaLabel=`Contents`,n.innerHTML=`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"><path d="M2.5 4h11M2.5 8h11M2.5 12h7"/></svg>`;let r,i,a=[];const o=()=>document.querySelector(`.wb-nav`)?.getBoundingClientRect().height??0;function s(){return r.getBoundingClientRect().left>=
|
|
1
|
+
const e=document.createElement(`nav`);e.className=`wb-toc`,e.setAttribute(`aria-label`,`Contents`);const t=document.createElement(`ol`);e.append(t);const n=document.createElement(`button`);n.type=`button`,n.className=`wb-toc-toggle`,n.title=n.ariaLabel=`Contents`,n.innerHTML=`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"><path d="M2.5 4h11M2.5 8h11M2.5 12h7"/></svg>`;let r,i,a=[];const o=()=>document.querySelector(`.wb-nav`)?.getBoundingClientRect().height??0;function s(){let t=parseFloat(getComputedStyle(e).minWidth)||0;return r.getBoundingClientRect().left>=t+40+16}const c=e=>{let t=/^(\d+(?:\.\d+)?)(px|em|rem|ch|vw)?$/.exec(String(e??``).trim());return t&&Number(t[1])>0?t[1]+(t[2]??`px`):null};function l(){let t=document.querySelector(`meta[name=wb-toc]`),n=d.settings(),r=n&&typeof n==`object`?n:{};for(let[n,i]of[[`minWidth`,`--wb-toc-min-width`],[`maxWidth`,`--wb-toc-max-width`]]){let a=c(r[n])??c(t?.dataset[n]);a?e.style.setProperty(i,a):e.style.removeProperty(i)}}function u(){let t=r.getBoundingClientRect().left;e.style.setProperty(`--wb-toc-right`,`${document.documentElement.clientWidth-t+40}px`),e.style.setProperty(`--wb-toc-room`,`${t-40-16}px`)}let d;function f(){let e=d.settings(),t=document.querySelector(`meta[name=wb-toc]`)?.getAttribute(`content`)===`always`;return e===!1?!1:e===!0||e&&typeof e==`object`?!0:t}function p(){a=f()?[...r.querySelectorAll(`:scope > h2, :scope > h3`)]:[];let i=0,o=0;t.replaceChildren(...a.map((e,t)=>{let n=e.tagName===`H2`?`${++i}`:`${i}.${++o}`;e.tagName===`H2`&&(o=0);let r=document.createElement(`li`);r.dataset.level=e.tagName===`H2`?`2`:`3`;let a=document.createElement(`a`);return a.href=`#`,a.dataset.index=String(t),a.innerHTML=`<span class="wb-toc-number"></span><span class="wb-toc-text"></span>`,a.querySelector(`.wb-toc-number`).textContent=n,a.querySelector(`.wb-toc-text`).textContent=e.textContent??``,r.append(a),r}));let c=a.length>1;l(),u(),n.hidden=!c||s(),e.hidden=!c||!s()&&!e.classList.contains(`wb-toc-open`),e.classList.toggle(`wb-toc-docked`,s()),h(),g()}function m(e){let t=-1;for(let n=0;n<a.length&&a[n].compareDocumentPosition(e)&Node.DOCUMENT_POSITION_FOLLOWING;n++)t=n;return t}function h(){let e=/* @__PURE__ */ new Set,n=new Set(i.unread().map(e=>e.id)),o=[...r.querySelectorAll(`form[data-wb-open]`),...[...r.querySelectorAll(`[data-wb-message]`)].filter(e=>n.has(e.dataset.wbMessage))];for(let t of o)e.add(m(t));for(let t of document.querySelectorAll(`[data-wb-holds]`)){if(!t.dataset.wbHolds.split(` `).some(e=>n.has(e)))continue;let r=t.getBoundingClientRect().top,i=-1;a.forEach((e,t)=>{e.getBoundingClientRect().top<=r&&(i=t)}),e.add(i)}t.querySelectorAll(`a`).forEach((t,n)=>t.toggleAttribute(`data-waiting`,e.has(n)))}function g(){let e=o()+40,n=0;a.forEach((t,r)=>{t.getBoundingClientRect().top<=e&&(n=r)}),t.querySelectorAll(`a`).forEach((e,t)=>e.toggleAttribute(`aria-current`,t===n&&a.length>0))}function _(t){let n=a[t];n&&(scrollTo({top:Math.max(0,scrollY+n.getBoundingClientRect().top-o()-12),behavior:`smooth`}),s()||(e.classList.remove(`wb-toc-open`),e.hidden=!0))}const v=(a,o,s)=>{if(o.kind!==`page`&&o.kind!==`file`)return;d=o,r=a.querySelector(`#wb-main`)??a,i=s,document.body.append(e),a.querySelector(`.wb-nav .wb-theme`)?.before(n),t.addEventListener(`click`,e=>{let t=e.target.closest(`a[data-index]`);t&&(e.preventDefault(),_(Number(t.dataset.index)))}),n.addEventListener(`click`,()=>{let t=!e.classList.contains(`wb-toc-open`);e.classList.toggle(`wb-toc-open`,t),e.hidden=!t}),document.addEventListener(`keydown`,t=>{t.key===`Escape`&&e.classList.contains(`wb-toc-open`)&&n.click()});let c=0,l=e=>()=>{cancelAnimationFrame(c),c=requestAnimationFrame(e)};addEventListener(`scroll`,l(g),{passive:!0}),addEventListener(`resize`,l(p)),i.onRendered(p),o.settings.on(p),i.forms.on(()=>h()),i.events.on(()=>requestAnimationFrame(h)),p()};export{v as default};
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
/* the table of contents (client.ts): in the margin left of the text, or opened from the header */
|
|
2
|
+
/* it fits its items, between a minimum and a maximum (client.ts sets them from the options and the
|
|
3
|
+
page's frontmatter); docked, never wider than the room left of the text */
|
|
2
4
|
.wb-toc {
|
|
3
5
|
position: fixed;
|
|
4
6
|
z-index: var(--layer-aside);
|
|
5
|
-
font: var(--ui-small)/var(--ui-line-height) var(--sans, sans-serif);
|
|
7
|
+
font: var(--ui-small) / var(--ui-line-height) var(--sans, sans-serif);
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
width: max-content;
|
|
10
|
+
min-width: var(--wb-toc-min-width, 160px);
|
|
11
|
+
max-width: var(--wb-toc-max-width, 320px);
|
|
6
12
|
}
|
|
7
13
|
.wb-toc[hidden],
|
|
8
14
|
.wb-toc-toggle[hidden] {
|
|
@@ -10,15 +16,15 @@
|
|
|
10
16
|
}
|
|
11
17
|
.wb-toc-docked {
|
|
12
18
|
top: 72px;
|
|
13
|
-
|
|
14
|
-
width:
|
|
19
|
+
right: var(--wb-toc-right);
|
|
20
|
+
max-width: min(var(--wb-toc-max-width, 320px), var(--wb-toc-room, 320px));
|
|
15
21
|
max-height: calc(100vh - 120px - var(--wb-inset-bottom, 0px));
|
|
16
22
|
overflow: auto;
|
|
17
23
|
}
|
|
18
24
|
.wb-toc-open:not(.wb-toc-docked) {
|
|
19
25
|
top: 52px;
|
|
20
26
|
left: 16px;
|
|
21
|
-
width: min(
|
|
27
|
+
max-width: min(var(--wb-toc-max-width, 320px), 100vw - 32px);
|
|
22
28
|
max-height: calc(100vh - 100px - var(--wb-inset-bottom, 0px));
|
|
23
29
|
overflow: auto;
|
|
24
30
|
padding: var(--space-sm);
|
package/dist/src/auth.js
CHANGED
|
@@ -17,8 +17,9 @@ function createAuth(wb) {
|
|
|
17
17
|
const token = projectToken(wb);
|
|
18
18
|
const same = (a, b) => typeof a === "string" && a.length === b.length && crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
19
19
|
const cookies = (req) => Object.fromEntries((req.headers.cookie ?? "").split(";").map((c) => c.trim().split("=")).filter(([k]) => k));
|
|
20
|
-
/** Has this request the token, from this origin? */
|
|
20
|
+
/** Has this request the token, from this origin? No request (a page being built) has none. */
|
|
21
21
|
function authorized(req) {
|
|
22
|
+
if (!req) return false;
|
|
22
23
|
const jar = cookies(req);
|
|
23
24
|
if (!(same(jar[COOKIE], token) || same(req.headers["x-whiteboard-token"], token))) return false;
|
|
24
25
|
const origin = req.headers.origin;
|
|
@@ -1248,7 +1248,7 @@ async function mountOne(el) {
|
|
|
1248
1248
|
el.dataset.wbMounted = "";
|
|
1249
1249
|
if (!island) return;
|
|
1250
1250
|
try {
|
|
1251
|
-
const mod = await import(island.client);
|
|
1251
|
+
const mod = await import(new URL(island.client, document.baseURI).href);
|
|
1252
1252
|
if (!el.isConnected) return;
|
|
1253
1253
|
const mount = mod.default;
|
|
1254
1254
|
if (typeof mount !== "function") throw new Error("the client module must export a mount(element, props, api) function as default");
|
|
@@ -1462,13 +1462,19 @@ function keepPlace(place, sigs) {
|
|
|
1462
1462
|
if (el) window.scrollBy(0, el.getBoundingClientRect().top - place.top);
|
|
1463
1463
|
}
|
|
1464
1464
|
/** The new render of the page, patched in. */
|
|
1465
|
+
let leaving = false;
|
|
1466
|
+
addEventListener("pagehide", () => {
|
|
1467
|
+
leaving = true;
|
|
1468
|
+
});
|
|
1465
1469
|
async function refresh() {
|
|
1466
1470
|
let next;
|
|
1467
1471
|
try {
|
|
1468
1472
|
next = await currentPage.render();
|
|
1469
1473
|
} catch (err) {
|
|
1474
|
+
if (leaving) return;
|
|
1470
1475
|
if (/: 404$/.test(err.message)) {
|
|
1471
1476
|
if (currentPage.data()?.mtime == null) return;
|
|
1477
|
+
leaving = true;
|
|
1472
1478
|
return location.reload();
|
|
1473
1479
|
}
|
|
1474
1480
|
throw err;
|
|
@@ -1527,10 +1533,12 @@ const mount = async (root, handle, coreApi) => {
|
|
|
1527
1533
|
if (isDir) core.events.on(() => refresh());
|
|
1528
1534
|
if (isDir) core.listeners.on(() => refresh());
|
|
1529
1535
|
blockSigs = [...main.children].map(signature);
|
|
1530
|
-
if (
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1536
|
+
if (handle.live) {
|
|
1537
|
+
if (!isDir) trackInitial(main, page, core);
|
|
1538
|
+
if (!isDir) trackWaiting(main, core);
|
|
1539
|
+
trackElsewhere(root, handle, core);
|
|
1540
|
+
trackLive(root, handle, core);
|
|
1541
|
+
}
|
|
1534
1542
|
if (isDir) {
|
|
1535
1543
|
trackSorts();
|
|
1536
1544
|
core.onRendered(applySorts);
|
|
@@ -1538,7 +1546,7 @@ const mount = async (root, handle, coreApi) => {
|
|
|
1538
1546
|
trackSticky(main, (fn) => core.onRendered(fn));
|
|
1539
1547
|
trackHold();
|
|
1540
1548
|
trackWindows(core);
|
|
1541
|
-
if (!isDir) trackOrphanThreads(main, core);
|
|
1549
|
+
if (!isDir && handle.live) trackOrphanThreads(main, core);
|
|
1542
1550
|
await mountIslands();
|
|
1543
1551
|
tickTimes();
|
|
1544
1552
|
};
|
package/dist/src/loader.js
CHANGED
|
@@ -25,6 +25,7 @@ const BUILTIN_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
25
25
|
"scroll",
|
|
26
26
|
"close",
|
|
27
27
|
"prune",
|
|
28
|
+
"build",
|
|
28
29
|
"edit",
|
|
29
30
|
"skill",
|
|
30
31
|
"help"
|
|
@@ -92,7 +93,10 @@ function createConfigLoader(proj, { pages: withPages = true } = {}) {
|
|
|
92
93
|
plugin: p.name,
|
|
93
94
|
public: publicDirs.get(p.name)
|
|
94
95
|
})));
|
|
95
|
-
const styles = plugins.filter((p) => p.style).map((p) =>
|
|
96
|
+
const styles = plugins.filter((p) => p.style).map((p) => ({
|
|
97
|
+
plugin: p.name,
|
|
98
|
+
file: inPublic(publicDirs.get(p.name), p.style, `plugin ${p.name}: style`)
|
|
99
|
+
}));
|
|
96
100
|
const links = plugins.flatMap((p) => p.links ? [p.links.bind(p)] : []);
|
|
97
101
|
const pages = withPages ? createPages({
|
|
98
102
|
blocks,
|
|
@@ -107,7 +111,8 @@ function createConfigLoader(proj, { pages: withPages = true } = {}) {
|
|
|
107
111
|
handedOut: declared("handOut"),
|
|
108
112
|
forReader: declared("forReader"),
|
|
109
113
|
publicDirs,
|
|
110
|
-
files: config?.files !== false
|
|
114
|
+
files: config?.files !== false,
|
|
115
|
+
build: config?.build ?? {}
|
|
111
116
|
};
|
|
112
117
|
}
|
|
113
118
|
function config() {
|
|
@@ -121,6 +126,7 @@ function createConfigLoader(proj, { pages: withPages = true } = {}) {
|
|
|
121
126
|
forReader: /* @__PURE__ */ new Set(),
|
|
122
127
|
publicDirs: /* @__PURE__ */ new Map(),
|
|
123
128
|
files: false,
|
|
129
|
+
build: {},
|
|
124
130
|
errors: [error]
|
|
125
131
|
}));
|
|
126
132
|
return cached;
|
package/dist/src/pages/render.js
CHANGED
|
@@ -133,7 +133,7 @@ function documentsIn(dir) {
|
|
|
133
133
|
walk("");
|
|
134
134
|
}
|
|
135
135
|
const depth = (f) => f.split("/").length;
|
|
136
|
-
return [...new Set(files)].
|
|
136
|
+
return [...new Set(files)].toSorted((a, b) => depth(a) - depth(b) || a.localeCompare(b));
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* The overview's list of the project's documents: each by its title, linked to its rendered page,
|
|
@@ -216,16 +216,35 @@ function createMessageRender(blocks, links = []) {
|
|
|
216
216
|
};
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
|
+
/** What a block left out of a build (RenderContext.skip) is: nothing, for its directives and fences alike. */
|
|
220
|
+
const skipped = (name) => ({
|
|
221
|
+
name,
|
|
222
|
+
code: false,
|
|
223
|
+
fences: true,
|
|
224
|
+
props: null,
|
|
225
|
+
html: () => "",
|
|
226
|
+
client: null,
|
|
227
|
+
style: null,
|
|
228
|
+
source: "build"
|
|
229
|
+
});
|
|
219
230
|
function createRender(blocks, style, pluginStyles = [], links = []) {
|
|
220
231
|
const textLinks = textLinksOf(links);
|
|
221
232
|
const STYLE = stylePath(style);
|
|
222
|
-
const PLUGIN_STYLES = pluginStyles.map(
|
|
233
|
+
const PLUGIN_STYLES = pluginStyles.map((s) => ({
|
|
234
|
+
plugin: s.plugin,
|
|
235
|
+
file: stylePath(s.file)
|
|
236
|
+
})).filter((s) => !!s.file);
|
|
223
237
|
async function markdown(source, page, file, ctx) {
|
|
224
238
|
const { blocks: set, code } = blocks();
|
|
239
|
+
const skip = ctx.skip;
|
|
225
240
|
return renderMarkdown(body(source), {
|
|
226
241
|
page,
|
|
227
242
|
file,
|
|
228
|
-
resolve: (name) =>
|
|
243
|
+
resolve: (name) => {
|
|
244
|
+
const block = set.get(name) ?? null;
|
|
245
|
+
if (skip && (skip.has(name) || block && skip.has(block.source))) return skipped(name);
|
|
246
|
+
return block;
|
|
247
|
+
},
|
|
229
248
|
code,
|
|
230
249
|
linkFor: ctx.urlFor,
|
|
231
250
|
textLinks: textLinks(ctx.project.dir)
|
|
@@ -321,19 +340,27 @@ function createRender(blocks, style, pluginStyles = [], links = []) {
|
|
|
321
340
|
client: ctx.asset(island.client)
|
|
322
341
|
}]));
|
|
323
342
|
const styles = out.styles.map((s) => ctx.asset(s));
|
|
324
|
-
const nav = html`<nav class="wb-nav">
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
343
|
+
const nav = ctx.live === false ? html`<nav class="wb-nav">
|
|
344
|
+
<span>${ctx.project.name}</span
|
|
345
|
+
><button
|
|
346
|
+
type="button"
|
|
347
|
+
class="wb-theme"
|
|
348
|
+
title="Theme: follow the system, light or dark"
|
|
349
|
+
aria-label="Theme"
|
|
350
|
+
></button>
|
|
351
|
+
</nav>` : html`<nav class="wb-nav">
|
|
352
|
+
<span>${crumbs(page.id, ctx.project.name)}</span
|
|
353
|
+
>${page.mtime != null && html`<span class="wb-meta">updated <time id="wb-updated" data-ts="${page.mtime}"></time></span>`}<button
|
|
354
|
+
type="button"
|
|
355
|
+
class="wb-theme"
|
|
356
|
+
title="Theme: follow the system, light or dark"
|
|
357
|
+
aria-label="Theme"
|
|
358
|
+
></button
|
|
359
|
+
><span class="wb-live" role="img" title="Connecting…" aria-label="Connecting…"></span>
|
|
360
|
+
</nav>`;
|
|
334
361
|
const links = [
|
|
335
362
|
ctx.asset(BASE_CSS),
|
|
336
|
-
...PLUGIN_STYLES.map((
|
|
363
|
+
...PLUGIN_STYLES.filter((s) => !ctx.skip?.has(s.plugin)).map((s) => ctx.asset(s.file)),
|
|
337
364
|
...styles,
|
|
338
365
|
...STYLE ? [ctx.asset(STYLE)] : []
|
|
339
366
|
];
|
|
@@ -364,7 +391,7 @@ A page is markdown: GFM tables, \`<details>\`, raw HTML and a hand-written \`<fo
|
|
|
364
391
|
|
|
365
392
|
The blocks here, by the plugin that brings them (each plugin's section below says how to write them):
|
|
366
393
|
|
|
367
|
-
${[...byPlugin].
|
|
394
|
+
${[...byPlugin].toSorted(([a], [b]) => a.localeCompare(b)).map(([plugin, blocks]) => `- **${plugin}**: ${blocks.map((b) => `\`${b}\``).join(", ")}`).join("\n")}
|
|
368
395
|
`;
|
|
369
396
|
};
|
|
370
397
|
}
|
package/dist/src/pages/window.js
CHANGED
|
@@ -5,10 +5,11 @@ const OPEN = svg("<path d=\"M9 2.5h4.5V7M13.5 2.5 7.5 8.5M11.5 9.5v3a1 1 0 0 1-1
|
|
|
5
5
|
const MAXIMIZE = svg("<path d=\"M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10\"/>");
|
|
6
6
|
const RESTORE = svg("<path d=\"M6 2.5V6H2.5M13.5 6H10V2.5M10 13.5V10h3.5M2.5 10H6v3.5\"/>");
|
|
7
7
|
/** A window around a block's HTML: see the top of this file. */
|
|
8
|
-
function windowFrame({ body, label = null, open = null, wide = false, bare = false, bodyClass = "", height }) {
|
|
8
|
+
function windowFrame({ body, label = null, open = null, wide = false, bare = false, bodyClass = "", height, className = "", controls = "" }) {
|
|
9
9
|
const name = label != null && String(label) !== "" ? html`<span class="wb-window-title">${raw(String(label))}</span>` : open ? html`<span class="wb-window-address">${open}</span>` : html``;
|
|
10
10
|
const header = !bare && html`<div class="wb-window-bar">
|
|
11
11
|
<span class="wb-window-name" ${open ? html` title="${open}"` : ""}>${name}</span>
|
|
12
|
+
${raw(String(controls))}
|
|
12
13
|
${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>`}
|
|
13
14
|
<button
|
|
14
15
|
type="button"
|
|
@@ -20,7 +21,7 @@ function windowFrame({ body, label = null, open = null, wide = false, bare = fal
|
|
|
20
21
|
<span class="wb-window-max">${MAXIMIZE}</span><span class="wb-window-restore">${RESTORE}</span>
|
|
21
22
|
</button>
|
|
22
23
|
</div>`;
|
|
23
|
-
return html`<div class="wb-window${wide && raw(" wb-wide")}">
|
|
24
|
+
return html`<div class="wb-window${wide && raw(" wb-wide")}${className && raw(" " + className)}">
|
|
24
25
|
${header}
|
|
25
26
|
<div class="wb-window-body${bodyClass && raw(" " + bodyClass)}" ${height ? html` style="height: ${height}"` : ""}>
|
|
26
27
|
${raw(String(body))}
|
package/dist/src/server.js
CHANGED
|
@@ -11,6 +11,7 @@ import _taggedTemplateLiteral from "../_virtual/_@oxc-project_runtime@0.156.0/he
|
|
|
11
11
|
import { stripTypeScriptTypes } from "node:module";
|
|
12
12
|
import fs from "node:fs";
|
|
13
13
|
import path from "node:path";
|
|
14
|
+
import { parse } from "yaml";
|
|
14
15
|
// src/server.ts
|
|
15
16
|
var _templateObject;
|
|
16
17
|
const ENGINE_DIR = PACKAGE_DIR;
|
|
@@ -165,14 +166,34 @@ function createServer(project) {
|
|
|
165
166
|
return within(p, base) ? p : null;
|
|
166
167
|
}
|
|
167
168
|
const isRepoId = (id) => id === "-" || id.startsWith("-/");
|
|
169
|
+
/** A page's frontmatter, parsed as YAML; empty, with the reason, when it isn't fields. */
|
|
168
170
|
function frontmatter(source) {
|
|
169
171
|
const m = FRONTMATTER.exec(source);
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
if (!m) return {
|
|
173
|
+
data: {},
|
|
174
|
+
error: null
|
|
175
|
+
};
|
|
176
|
+
let data;
|
|
177
|
+
try {
|
|
178
|
+
data = parse(m[1]);
|
|
179
|
+
} catch (err) {
|
|
180
|
+
return {
|
|
181
|
+
data: {},
|
|
182
|
+
error: err.message
|
|
183
|
+
};
|
|
174
184
|
}
|
|
175
|
-
return
|
|
185
|
+
if (data == null) return {
|
|
186
|
+
data: {},
|
|
187
|
+
error: null
|
|
188
|
+
};
|
|
189
|
+
if (typeof data !== "object" || Array.isArray(data)) return {
|
|
190
|
+
data: {},
|
|
191
|
+
error: "it must be fields (`key: value` lines), not a single value or a list"
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
data,
|
|
195
|
+
error: null
|
|
196
|
+
};
|
|
176
197
|
}
|
|
177
198
|
function pageSource(id, file) {
|
|
178
199
|
const source = fs.readFileSync(file, "utf8");
|
|
@@ -183,7 +204,10 @@ function createServer(project) {
|
|
|
183
204
|
mtime: fs.statSync(file).mtimeMs,
|
|
184
205
|
source,
|
|
185
206
|
body: source.replace(FRONTMATTER, ""),
|
|
186
|
-
|
|
207
|
+
...(({ data, error }) => ({
|
|
208
|
+
frontmatter: data,
|
|
209
|
+
frontmatterError: error
|
|
210
|
+
}))(frontmatter(source))
|
|
187
211
|
};
|
|
188
212
|
}
|
|
189
213
|
/** The pages in a folder of the pages folder, newest first, with when each was last answered. */
|
|
@@ -319,6 +343,7 @@ function createServer(project) {
|
|
|
319
343
|
async function render(page) {
|
|
320
344
|
const { pages, errors } = await config();
|
|
321
345
|
const notices = errors.map((e) => `config: ${e.message}`);
|
|
346
|
+
if (page.kind === "page" && page.frontmatterError) notices.push(`frontmatter: ${page.frontmatterError}`);
|
|
322
347
|
let out;
|
|
323
348
|
let rendered = !!pages;
|
|
324
349
|
try {
|
|
@@ -417,11 +442,12 @@ function createServer(project) {
|
|
|
417
442
|
head: [],
|
|
418
443
|
body: [],
|
|
419
444
|
clients: []
|
|
420
|
-
}) {
|
|
445
|
+
}, built) {
|
|
421
446
|
const handoff = {
|
|
422
447
|
id: page.id,
|
|
423
448
|
kind: page.kind,
|
|
424
|
-
|
|
449
|
+
live: !built,
|
|
450
|
+
client: rendered ? (built ?? { asset }).asset(PAGE_CLIENT) : null,
|
|
425
451
|
data: out.data ?? null,
|
|
426
452
|
frontmatter: frontmatterOf(page),
|
|
427
453
|
plugins: extras.clients,
|
|
@@ -437,9 +463,10 @@ function createServer(project) {
|
|
|
437
463
|
"\">\n ",
|
|
438
464
|
"\n <div id=\"wb-root\">",
|
|
439
465
|
"</div>\n <div id=\"wb-dock\"></div>\n <script type=\"application/json\" id=\"wb-page\">\n ",
|
|
440
|
-
"\n <\/script>\n <script type=\"module\" src=\"
|
|
466
|
+
"\n <\/script>\n <script type=\"module\" src=\"",
|
|
467
|
+
"\"><\/script>\n ",
|
|
441
468
|
"\n </body>\n </html>"
|
|
442
|
-
])), out.title || page.id || project.name, DOCK_STYLE, raw(out.head ?? ""), extras.head, page.id, page.kind, notices.map((n) => html`<pre class="wb-error" role="alert">${n}</pre>`), raw(String(out.html)), raw(json(handoff)), extras.body));
|
|
469
|
+
])), out.title || page.id || project.name, DOCK_STYLE, raw(out.head ?? ""), extras.head, page.id, page.kind, notices.map((n) => html`<pre class="wb-error" role="alert">${n}</pre>`), raw(String(out.html)), raw(json(handoff)), built ? built.asset(RUNTIME) : "/_/runtime.js", extras.body));
|
|
443
470
|
}
|
|
444
471
|
/** A listener as the server holds it. */
|
|
445
472
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -740,10 +767,189 @@ function createServer(project) {
|
|
|
740
767
|
send(res, 500, String(err?.stack || err), "text/plain");
|
|
741
768
|
}
|
|
742
769
|
}
|
|
770
|
+
/** What a build leaves out unless told otherwise: what is for writing a page, not for reading it. */
|
|
771
|
+
const BUILD_SKIP = [
|
|
772
|
+
"form",
|
|
773
|
+
"chat",
|
|
774
|
+
"comments",
|
|
775
|
+
"draft"
|
|
776
|
+
];
|
|
777
|
+
/** In the folder a build writes, so that a next build knows it may replace it. */
|
|
778
|
+
const BUILD_MARK = ".whiteboard-build";
|
|
779
|
+
async function build(options = {}) {
|
|
780
|
+
const cfg = await config();
|
|
781
|
+
if (cfg.errors.length) throw new Error(`the config failed to load: ${cfg.errors[0].message}`);
|
|
782
|
+
if (!cfg.pages) throw new Error("the config has no pages renderer");
|
|
783
|
+
const pages = cfg.pages;
|
|
784
|
+
const defined = (...xs) => xs.find((x) => x !== void 0);
|
|
785
|
+
const patterns = defined(options.pages, cfg.build.pages) ?? [];
|
|
786
|
+
const skip = new Set(defined(options.skip, cfg.build.skip) ?? BUILD_SKIP);
|
|
787
|
+
const outDir = path.resolve(project.dir, defined(options.out, cfg.build.out) ?? "site");
|
|
788
|
+
if (!patterns.length) throw new Error("nothing to build: name the pages, as globs from the project's folder (whiteboard build 'docs/**/*.md'), or set build.pages in the config");
|
|
789
|
+
const warnings = [];
|
|
790
|
+
const include = patterns.filter((p) => !p.startsWith("!"));
|
|
791
|
+
const exclude = patterns.filter((p) => p.startsWith("!")).map((p) => p.slice(1));
|
|
792
|
+
const files = [...new Set(include.flatMap((p) => fs.globSync(p, { cwd: project.dir }).map((f) => path.resolve(project.dir, f))))].filter((f) => /\.(md|markdown)$/i.test(f) && fs.statSync(f).isFile()).filter((f) => !exclude.some((g) => path.matchesGlob(path.relative(project.dir, f), g))).sort();
|
|
793
|
+
if (!files.length) throw new Error(`no markdown files match ${patterns.join(" ")}`);
|
|
794
|
+
const base = files.map(path.dirname).reduce((a, b) => {
|
|
795
|
+
while (!within(b, a)) a = path.dirname(a);
|
|
796
|
+
return a;
|
|
797
|
+
});
|
|
798
|
+
const outOf = (file) => {
|
|
799
|
+
const rel = path.relative(base, file);
|
|
800
|
+
return path.join(outDir, /^(readme|index)\.(md|markdown)$/i.test(path.basename(rel)) ? path.join(path.dirname(rel), "index.html") : rel.replace(/\.(md|markdown)$/i, ".html"));
|
|
801
|
+
};
|
|
802
|
+
const built = new Map(files.map((f) => [f, outOf(f)]));
|
|
803
|
+
if (fs.existsSync(outDir)) {
|
|
804
|
+
if (fs.readdirSync(outDir).length && !fs.existsSync(path.join(outDir, BUILD_MARK))) throw new Error(`${outDir} has files a build didn't write: give another folder (--out), or empty it`);
|
|
805
|
+
fs.rmSync(outDir, { recursive: true });
|
|
806
|
+
}
|
|
807
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
808
|
+
fs.writeFileSync(path.join(outDir, BUILD_MARK), "written by whiteboard build; the next build replaces this folder\n");
|
|
809
|
+
const copied = /* @__PURE__ */ new Map();
|
|
810
|
+
function copyAsset(file) {
|
|
811
|
+
const known = copied.get(file);
|
|
812
|
+
if (known) return known;
|
|
813
|
+
const rel = within(file, ENGINE_DIR) ? path.join("_", "whiteboard", path.relative(ENGINE_DIR, file)) : within(file, project.dir) ? path.join("_", "project", path.relative(project.dir, file)) : path.join("_", "files", path.basename(path.dirname(file)), path.basename(file));
|
|
814
|
+
const dest = path.join(outDir, TYPESCRIPT.test(rel) ? rel.replace(/\.m?ts$/i, ".js") : rel);
|
|
815
|
+
copied.set(file, dest);
|
|
816
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
817
|
+
if (TYPESCRIPT.test(file)) fs.writeFileSync(dest, typeScriptModule(file));
|
|
818
|
+
else fs.copyFileSync(file, dest);
|
|
819
|
+
if (/\.css$/i.test(file)) for (const m of fs.readFileSync(file, "utf8").matchAll(/url\(\s*['"]?([^'")]+)['"]?\s*\)/g)) {
|
|
820
|
+
const ref = m[1];
|
|
821
|
+
if (/^(data:|[a-z][a-z0-9+.-]*:|\/|#)/i.test(ref)) continue;
|
|
822
|
+
const target = path.resolve(path.dirname(file), ref.replace(/[?#].*$/, ""));
|
|
823
|
+
if (fs.existsSync(target) && fs.statSync(target).isFile()) copyAsset(target);
|
|
824
|
+
}
|
|
825
|
+
return dest;
|
|
826
|
+
}
|
|
827
|
+
/** a file beside the pages (an image), copied to its place below the site */
|
|
828
|
+
function copyBeside(file) {
|
|
829
|
+
if (!within(file, base)) return null;
|
|
830
|
+
const dest = path.join(outDir, path.relative(base, file));
|
|
831
|
+
if (!fs.existsSync(dest)) {
|
|
832
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
833
|
+
fs.copyFileSync(file, dest);
|
|
834
|
+
}
|
|
835
|
+
return dest;
|
|
836
|
+
}
|
|
837
|
+
const hooks = await pluginHooks();
|
|
838
|
+
const result = {
|
|
839
|
+
out: outDir,
|
|
840
|
+
pages: [],
|
|
841
|
+
warnings
|
|
842
|
+
};
|
|
843
|
+
for (const [file, dest] of built) {
|
|
844
|
+
const here = path.dirname(dest);
|
|
845
|
+
const relTo = (target) => path.relative(here, target).split(path.sep).map(encodeURIComponent).join("/") || ".";
|
|
846
|
+
const assetHere = (ref) => relTo(copyAsset(toPath(ref)));
|
|
847
|
+
const urlFor = (abs) => {
|
|
848
|
+
for (const candidate of [abs, abs + ".md"]) {
|
|
849
|
+
if (!fs.existsSync(candidate)) continue;
|
|
850
|
+
if (fs.statSync(candidate).isDirectory()) {
|
|
851
|
+
const index = [...built.keys()].find((f) => path.dirname(f) === candidate && /^(readme|index)\.(md|markdown)$/i.test(path.basename(f)));
|
|
852
|
+
if (index) return relTo(built.get(index));
|
|
853
|
+
continue;
|
|
854
|
+
}
|
|
855
|
+
if (built.has(candidate)) return relTo(built.get(candidate));
|
|
856
|
+
if (/\.(md|markdown)$/i.test(candidate)) {
|
|
857
|
+
warnings.push(`${path.relative(project.dir, file)} links to ${path.relative(project.dir, candidate)}, which is not in the build`);
|
|
858
|
+
return null;
|
|
859
|
+
}
|
|
860
|
+
const copy = copyBeside(candidate);
|
|
861
|
+
if (copy) return relTo(copy);
|
|
862
|
+
warnings.push(`${path.relative(project.dir, file)} links to ${path.relative(project.dir, candidate)}, outside the built pages' folder`);
|
|
863
|
+
return null;
|
|
864
|
+
}
|
|
865
|
+
return null;
|
|
866
|
+
};
|
|
867
|
+
const id = within(file, project.pagesDir) ? path.relative(project.pagesDir, file).split(path.sep).join("/").replace(/\.(md|markdown)$/i, "") : "-/" + path.relative(project.dir, file).split(path.sep).join("/");
|
|
868
|
+
const stored = pageSource(id, file);
|
|
869
|
+
if (stored.frontmatterError) warnings.push(`${path.relative(project.dir, file)}: frontmatter: ${stored.frontmatterError}`);
|
|
870
|
+
const context = {
|
|
871
|
+
project: {
|
|
872
|
+
name: project.name,
|
|
873
|
+
dir: project.dir,
|
|
874
|
+
files: !!FILES
|
|
875
|
+
},
|
|
876
|
+
asset: assetHere,
|
|
877
|
+
urlFor,
|
|
878
|
+
live: false,
|
|
879
|
+
skip
|
|
880
|
+
};
|
|
881
|
+
const rendered = await pages.render(stored, context);
|
|
882
|
+
const named = /^(readme|index)\.(md|markdown)$/i.test(path.basename(file)) ? path.basename(path.dirname(file)) : path.basename(file).replace(/\.(md|markdown)$/i, "");
|
|
883
|
+
const title = !rendered.title || rendered.title === id ? named : rendered.title;
|
|
884
|
+
const out = {
|
|
885
|
+
...rendered,
|
|
886
|
+
title,
|
|
887
|
+
html: String(rendered.html ?? ""),
|
|
888
|
+
head: String(rendered.head ?? "")
|
|
889
|
+
};
|
|
890
|
+
const included = hooks.filter((h) => !h.error && !skip.has(h.name));
|
|
891
|
+
const clients = included.filter((h) => h.client).map((h) => ({
|
|
892
|
+
name: h.name,
|
|
893
|
+
client: assetHere(h.client)
|
|
894
|
+
}));
|
|
895
|
+
const parts = await Promise.all(included.map(async (h) => {
|
|
896
|
+
try {
|
|
897
|
+
return await h.shell?.(null) ?? null;
|
|
898
|
+
} catch (err) {
|
|
899
|
+
warnings.push(`plugin ${h.name} failed on ${path.relative(project.dir, file)}: ${err.message}`);
|
|
900
|
+
return null;
|
|
901
|
+
}
|
|
902
|
+
}));
|
|
903
|
+
const extras = {
|
|
904
|
+
head: parts.map((x) => raw(String(x?.head ?? ""))),
|
|
905
|
+
body: parts.map((x) => raw(String(x?.body ?? ""))),
|
|
906
|
+
clients
|
|
907
|
+
};
|
|
908
|
+
let doc = shell(stored, {
|
|
909
|
+
page: true,
|
|
910
|
+
out,
|
|
911
|
+
notices: []
|
|
912
|
+
}, extras, { asset: assetHere });
|
|
913
|
+
doc = doc.replace(/\/_\/file(\/[^"'\s)<>]+)/g, (all, served) => {
|
|
914
|
+
let file;
|
|
915
|
+
try {
|
|
916
|
+
file = path.resolve(served.split("/").map(decodeURIComponent).join(path.sep));
|
|
917
|
+
} catch {
|
|
918
|
+
return all;
|
|
919
|
+
}
|
|
920
|
+
return fs.existsSync(file) && fs.statSync(file).isFile() ? assetHere(file) : all;
|
|
921
|
+
});
|
|
922
|
+
doc = doc.replace(/\b(src|href|poster)="([^"#?:]+)([^"]*)"/g, (all, _attr, ref) => {
|
|
923
|
+
if (ref.startsWith("/") || ref.startsWith("_/") || ref.startsWith("../")) return all;
|
|
924
|
+
let decoded = ref;
|
|
925
|
+
try {
|
|
926
|
+
decoded = decodeURIComponent(ref);
|
|
927
|
+
} catch {}
|
|
928
|
+
const source = path.resolve(path.dirname(file), decoded);
|
|
929
|
+
if (fs.existsSync(source) && fs.statSync(source).isFile() && !/\.(md|markdown)$/i.test(source)) {
|
|
930
|
+
const target = path.resolve(here, decoded);
|
|
931
|
+
if (within(target, outDir) && !fs.existsSync(target)) {
|
|
932
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
933
|
+
fs.copyFileSync(source, target);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
return all;
|
|
937
|
+
});
|
|
938
|
+
fs.mkdirSync(here, { recursive: true });
|
|
939
|
+
fs.writeFileSync(dest, doc);
|
|
940
|
+
result.pages.push({
|
|
941
|
+
file,
|
|
942
|
+
to: dest
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
if (![...built.values()].includes(path.join(outDir, "index.html"))) warnings.push("no README.md or index.md in the top folder: the site has no index.html");
|
|
946
|
+
return result;
|
|
947
|
+
}
|
|
743
948
|
return {
|
|
744
949
|
handle,
|
|
745
950
|
status: (page = null) => status(page),
|
|
746
951
|
config,
|
|
952
|
+
build,
|
|
747
953
|
close() {
|
|
748
954
|
for (const w of watchers) w.close();
|
|
749
955
|
watchers.clear();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigmistqke/whiteboard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A whiteboard for you and your agent: it writes markdown pages you read live in the browser, you answer through forms it waits on",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -106,7 +106,8 @@
|
|
|
106
106
|
"remark-parse": "^11.0.0",
|
|
107
107
|
"remark-rehype": "^11.1.2",
|
|
108
108
|
"shiki": "^4.6.0",
|
|
109
|
-
"unified": "^11.0.5"
|
|
109
|
+
"unified": "^11.0.5",
|
|
110
|
+
"yaml": "^2.9.1"
|
|
110
111
|
},
|
|
111
112
|
"peerDependencies": {
|
|
112
113
|
"@solidjs/web": "^2.0.0-rc.21",
|