@bigmistqke/workpad 0.0.0-stage → 0.18.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 +781 -2
- package/bin/workpad.ts +1509 -0
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/bin/workpad.js +1190 -0
- package/dist/client/runtime.js +1194 -0
- package/dist/define.js +27 -0
- package/dist/plugins/alert/README.md +18 -0
- package/dist/plugins/alert/index.js +40 -0
- package/dist/plugins/alert/public/style.css +40 -0
- package/dist/plugins/ansi/README.md +36 -0
- package/dist/plugins/ansi/index.js +63 -0
- package/dist/plugins/ansi/public/style.css +28 -0
- package/dist/plugins/badge/README.md +32 -0
- package/dist/plugins/badge/index.js +28 -0
- package/dist/plugins/badge/public/style.css +30 -0
- package/dist/plugins/chat/README.md +81 -0
- package/dist/plugins/chat/index.js +96 -0
- package/dist/plugins/chat/public/client.js +3 -0
- package/dist/plugins/chat/public/style.css +143 -0
- package/dist/plugins/claude/README.md +116 -0
- package/dist/plugins/claude/channel.js +130 -0
- package/dist/plugins/claude/doctor.js +316 -0
- package/dist/plugins/claude/index.js +199 -0
- package/dist/plugins/claude/session.js +68 -0
- package/dist/plugins/code/README.md +54 -0
- package/dist/plugins/code/diff.js +75 -0
- package/dist/plugins/code/index.js +105 -0
- package/dist/plugins/code/public/client.js +1 -0
- package/dist/plugins/code/public/style.css +99 -0
- package/dist/plugins/comments/README.md +30 -0
- package/dist/plugins/comments/index.js +39 -0
- package/dist/plugins/comments/public/client.js +24 -0
- package/dist/plugins/comments/public/style.css +224 -0
- package/dist/plugins/details/README.md +24 -0
- package/dist/plugins/details/index.js +28 -0
- package/dist/plugins/details/public/style.css +7 -0
- package/dist/plugins/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +27 -0
- package/dist/plugins/draft/public/style.css +21 -0
- package/dist/plugins/forge/README.md +22 -0
- package/dist/plugins/forge/index.js +83 -0
- package/dist/plugins/form/README.md +126 -0
- package/dist/plugins/form/index.js +179 -0
- package/dist/plugins/form/public/style.css +172 -0
- package/dist/plugins/grid/README.md +45 -0
- package/dist/plugins/grid/index.js +35 -0
- package/dist/plugins/grid/public/style.css +98 -0
- package/dist/plugins/iframe/README.md +18 -0
- package/dist/plugins/iframe/index.js +49 -0
- package/dist/plugins/iframe/public/style.css +28 -0
- package/dist/plugins/index.js +44 -0
- package/dist/plugins/lightbox/README.md +24 -0
- package/dist/plugins/lightbox/index.js +20 -0
- package/dist/plugins/lightbox/public/client.js +4 -0
- package/dist/plugins/lightbox/public/style.css +66 -0
- package/dist/plugins/mermaid/README.md +21 -0
- package/dist/plugins/mermaid/index.js +42 -0
- package/dist/plugins/mermaid/public/style.css +21 -0
- package/dist/plugins/opencode/README.md +48 -0
- package/dist/plugins/opencode/channel.js +92 -0
- package/dist/plugins/opencode/index.js +64 -0
- package/dist/plugins/opencode/shim.js +150 -0
- package/dist/plugins/quiet/README.md +26 -0
- package/dist/plugins/quiet/index.js +23 -0
- package/dist/plugins/tabs/README.md +44 -0
- package/dist/plugins/tabs/index.js +75 -0
- package/dist/plugins/tabs/public/client.js +1 -0
- package/dist/plugins/tabs/public/style.css +98 -0
- package/dist/plugins/terminal/README.md +63 -0
- package/dist/plugins/terminal/host.js +338 -0
- package/dist/plugins/terminal/index.js +170 -0
- package/dist/plugins/terminal/modes.js +32 -0
- package/dist/plugins/terminal/public/client.js +41 -0
- package/dist/plugins/terminal/public/style.css +511 -0
- package/dist/plugins/terminal/server.js +256 -0
- package/dist/plugins/terminal/sizes.js +58 -0
- package/dist/plugins/timeline/README.md +48 -0
- package/dist/plugins/timeline/index.js +83 -0
- package/dist/plugins/timeline/public/style.css +138 -0
- package/dist/plugins/toc/README.md +40 -0
- package/dist/plugins/toc/index.js +29 -0
- package/dist/plugins/toc/public/client.js +1 -0
- package/dist/plugins/toc/public/style.css +117 -0
- package/dist/plugins/window/README.md +51 -0
- package/dist/plugins/window/index.js +91 -0
- package/dist/solid/index.js +41 -0
- package/dist/src/agents.js +81 -0
- package/dist/src/anchors.js +52 -0
- package/dist/src/api.js +282 -0
- package/dist/src/archive.js +49 -0
- package/dist/src/auth.js +67 -0
- package/dist/src/build.js +159 -0
- package/dist/src/client/page/base.css +1762 -0
- package/dist/src/client/page/main.js +2098 -0
- package/dist/src/config.js +76 -0
- package/dist/src/document.js +93 -0
- package/dist/src/entries.js +264 -0
- package/dist/src/events.js +322 -0
- package/dist/src/files.js +47 -0
- package/dist/src/formstate.js +65 -0
- package/dist/src/help.js +211 -0
- package/dist/src/html.js +34 -0
- package/dist/src/hub.js +341 -0
- package/dist/src/icons.js +6 -0
- package/dist/src/listen.js +132 -0
- package/dist/src/listeners.js +64 -0
- package/dist/src/load.js +81 -0
- package/dist/src/loader.js +179 -0
- package/dist/src/migrate.js +314 -0
- package/dist/src/package.js +52 -0
- package/dist/src/pages/blocks.js +67 -0
- package/dist/src/pages/board.js +59 -0
- package/dist/src/pages/index.js +27 -0
- package/dist/src/pages/markdown.js +863 -0
- package/dist/src/pages/render.js +665 -0
- package/dist/src/pages/window.js +29 -0
- package/dist/src/plugins.js +283 -0
- package/dist/src/public.js +24 -0
- package/dist/src/rename.js +130 -0
- package/dist/src/running.js +146 -0
- package/dist/src/serve.js +188 -0
- package/dist/src/server.js +1105 -0
- package/dist/src/site.js +179 -0
- package/dist/src/state.js +155 -0
- package/dist/src/status.js +323 -0
- package/dist/src/thread.js +68 -0
- package/dist/src/watchdog.js +38 -0
- package/dist/src/ws.js +128 -0
- package/package.json +154 -4
- package/plugins/README.md +304 -0
- package/plugins/alert/README.md +18 -0
- package/plugins/alert/index.ts +50 -0
- package/plugins/alert/public/style.css +40 -0
- package/plugins/ansi/README.md +36 -0
- package/plugins/ansi/index.ts +95 -0
- package/plugins/ansi/public/style.css +28 -0
- package/plugins/badge/README.md +32 -0
- package/plugins/badge/index.ts +36 -0
- package/plugins/badge/public/style.css +30 -0
- package/plugins/chat/README.md +81 -0
- package/plugins/chat/autosize.ts +139 -0
- package/plugins/chat/client.tsx +187 -0
- package/plugins/chat/index.ts +146 -0
- package/plugins/chat/public/style.css +143 -0
- package/plugins/claude/README.md +116 -0
- package/plugins/claude/channel.ts +136 -0
- package/plugins/claude/doctor.ts +274 -0
- package/plugins/claude/index.ts +248 -0
- package/plugins/claude/session.ts +70 -0
- package/plugins/code/README.md +54 -0
- package/plugins/code/client.ts +73 -0
- package/plugins/code/diff.ts +96 -0
- package/plugins/code/index.ts +136 -0
- package/plugins/code/public/style.css +99 -0
- package/plugins/comments/README.md +30 -0
- package/plugins/comments/client.ts +723 -0
- package/plugins/comments/index.ts +48 -0
- package/plugins/comments/public/style.css +224 -0
- package/plugins/details/README.md +24 -0
- package/plugins/details/index.ts +30 -0
- package/plugins/details/public/style.css +7 -0
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- package/plugins/forge/README.md +22 -0
- package/plugins/forge/index.ts +84 -0
- package/plugins/form/README.md +126 -0
- package/plugins/form/index.ts +199 -0
- package/plugins/form/public/style.css +172 -0
- package/plugins/grid/README.md +45 -0
- package/plugins/grid/index.ts +41 -0
- package/plugins/grid/public/style.css +98 -0
- package/plugins/iframe/README.md +18 -0
- package/plugins/iframe/index.ts +53 -0
- package/plugins/iframe/public/style.css +28 -0
- package/plugins/index.ts +49 -0
- package/plugins/lightbox/README.md +24 -0
- package/plugins/lightbox/client.ts +109 -0
- package/plugins/lightbox/index.ts +25 -0
- package/plugins/lightbox/public/style.css +66 -0
- package/plugins/mermaid/README.md +21 -0
- package/plugins/mermaid/index.ts +46 -0
- package/plugins/mermaid/public/style.css +21 -0
- package/plugins/opencode/README.md +48 -0
- package/plugins/opencode/channel.ts +112 -0
- package/plugins/opencode/index.ts +91 -0
- package/plugins/opencode/shim.ts +166 -0
- package/plugins/quiet/README.md +26 -0
- package/plugins/quiet/index.ts +28 -0
- package/plugins/tabs/README.md +44 -0
- package/plugins/tabs/client.ts +96 -0
- package/plugins/tabs/index.ts +103 -0
- package/plugins/tabs/public/style.css +98 -0
- package/plugins/terminal/README.md +63 -0
- package/plugins/terminal/client.ts +391 -0
- package/plugins/terminal/host.ts +434 -0
- package/plugins/terminal/index.ts +199 -0
- package/plugins/terminal/modes.ts +30 -0
- package/plugins/terminal/public/style.css +225 -0
- package/plugins/terminal/server.ts +266 -0
- package/plugins/terminal/sizes.ts +72 -0
- package/plugins/timeline/README.md +48 -0
- package/plugins/timeline/index.ts +82 -0
- package/plugins/timeline/public/style.css +138 -0
- package/plugins/toc/README.md +40 -0
- package/plugins/toc/client.ts +236 -0
- package/plugins/toc/index.ts +55 -0
- package/plugins/toc/public/style.css +117 -0
- package/plugins/window/README.md +51 -0
- package/plugins/window/index.ts +92 -0
- package/skills/workpad/SKILL.md +588 -0
- package/solid/index.tsx +80 -0
- package/src/agents.ts +133 -0
- package/src/anchors.ts +85 -0
- package/src/api.ts +444 -0
- package/src/archive.ts +75 -0
- package/src/auth.ts +99 -0
- package/src/build.ts +213 -0
- package/src/client/base.ts +19 -0
- package/src/client/forms.ts +420 -0
- package/src/client/markdown.ts +147 -0
- package/src/client/page/base.css +1762 -0
- package/src/client/page/board.ts +137 -0
- package/src/client/page/elsewhere.ts +153 -0
- package/src/client/page/fresh.ts +343 -0
- package/src/client/page/heading-link.ts +32 -0
- package/src/client/page/live.ts +134 -0
- package/src/client/page/main.ts +398 -0
- package/src/client/page/orphans.ts +64 -0
- package/src/client/page/place.ts +260 -0
- package/src/client/page/sort.ts +49 -0
- package/src/client/page/sticky.ts +58 -0
- package/src/client/page/theme.ts +36 -0
- package/src/client/page/view.ts +9 -0
- package/src/client/page/waiting.ts +278 -0
- package/src/client/page/window.ts +40 -0
- package/src/client/reactive.ts +19 -0
- package/src/client/read.ts +111 -0
- package/src/client/runtime.ts +499 -0
- package/src/client/scroll.ts +90 -0
- package/src/client/toast.ts +99 -0
- package/src/config.ts +111 -0
- package/src/define.ts +997 -0
- package/src/document.ts +191 -0
- package/src/entries.ts +352 -0
- package/src/events.ts +463 -0
- package/src/files.ts +74 -0
- package/src/formstate.ts +72 -0
- package/src/help.ts +238 -0
- package/src/html.ts +44 -0
- package/src/hub.ts +426 -0
- package/src/icons.ts +18 -0
- package/src/listen.ts +171 -0
- package/src/listeners.ts +89 -0
- package/src/load.ts +113 -0
- package/src/loader.ts +227 -0
- package/src/migrate.ts +352 -0
- package/src/package.ts +62 -0
- package/src/pages/blocks.ts +106 -0
- package/src/pages/board.ts +89 -0
- package/src/pages/index.ts +79 -0
- package/src/pages/markdown.ts +976 -0
- package/src/pages/render.ts +748 -0
- package/src/pages/window.ts +69 -0
- package/src/plugins.ts +319 -0
- package/src/public.ts +39 -0
- package/src/rename.ts +147 -0
- package/src/running.ts +171 -0
- package/src/serve.ts +221 -0
- package/src/server.ts +1385 -0
- package/src/site.ts +170 -0
- package/src/state.ts +327 -0
- package/src/status.ts +466 -0
- package/src/thread.ts +98 -0
- package/src/watchdog.ts +53 -0
- package/src/ws.ts +155 -0
|
@@ -0,0 +1,665 @@
|
|
|
1
|
+
import { fileFilter } from "../files.js";
|
|
2
|
+
import { FRONTMATTER } from "../site.js";
|
|
3
|
+
import { renderMarkdown } from "./markdown.js";
|
|
4
|
+
import { html, raw } from "../html.js";
|
|
5
|
+
import { awaitingLabel } from "../icons.js";
|
|
6
|
+
import { ACTIVE_FOR, byProject, byState, total, withoutPages } from "./board.js";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
import { execFileSync } from "node:child_process";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
// src/pages/render.ts
|
|
13
|
+
const BASE_CSS = new URL("../client/page/base.css", import.meta.url);
|
|
14
|
+
const THEME_SCRIPT = raw(`<script>try{const t=localStorage.getItem('wp-theme');if(t==='light'||t==='dark')document.documentElement.dataset.theme=t;const b=new URLSearchParams(location.search).get('columns')||localStorage.getItem('wp-board');if(b==='project')document.documentElement.dataset.wpBoard=b}catch{}<\/script>`);
|
|
15
|
+
const CODE_LANG = {
|
|
16
|
+
js: "javascript",
|
|
17
|
+
mjs: "javascript",
|
|
18
|
+
cjs: "javascript",
|
|
19
|
+
ts: "typescript",
|
|
20
|
+
tsx: "tsx",
|
|
21
|
+
jsx: "jsx",
|
|
22
|
+
json: "json",
|
|
23
|
+
css: "css",
|
|
24
|
+
html: "html",
|
|
25
|
+
sh: "bash",
|
|
26
|
+
zsh: "bash",
|
|
27
|
+
py: "python",
|
|
28
|
+
rs: "rust",
|
|
29
|
+
go: "go",
|
|
30
|
+
toml: "toml",
|
|
31
|
+
yml: "yaml",
|
|
32
|
+
yaml: "yaml"
|
|
33
|
+
};
|
|
34
|
+
/** Frontmatter is the core's; the page starts after it (a page's own is cut off by the site: PageSource.body). */
|
|
35
|
+
const body = (source) => source.replace(FRONTMATTER, "");
|
|
36
|
+
/** A page's title: its first heading, else its name. */
|
|
37
|
+
function titleOf(file, fallback) {
|
|
38
|
+
try {
|
|
39
|
+
const h1 = /^#\s+(.+)$/m.exec(body(fs.readFileSync(file, "utf8")));
|
|
40
|
+
return h1 ? h1[1].replace(/[*_`]/g, "") : fallback;
|
|
41
|
+
} catch {
|
|
42
|
+
return fallback;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function crumbs(id, name, base, entry) {
|
|
46
|
+
const parts = id ? id.split("/") : [];
|
|
47
|
+
const above = entry ? html`<a href="/">workpad</a> / ` : "";
|
|
48
|
+
return html`${above}<a href="${base}/">${name}</a
|
|
49
|
+
>${parts.map((p, i) => html` / <a href="${base}/${parts.slice(0, i + 1).join("/")}">${p}</a>`)}`;
|
|
50
|
+
}
|
|
51
|
+
const time = (ts) => html`<time data-ts="${ts}"></time>`;
|
|
52
|
+
function pageList(pages, base) {
|
|
53
|
+
return html`<ul class="wp-index">
|
|
54
|
+
${pages.map((p) => html`<li>
|
|
55
|
+
<a href="${base}/${p.id}">${titleOf(p.file, path.basename(p.id))}</a>${p.awaiting > 0 && html` <a
|
|
56
|
+
class="wp-awaiting"
|
|
57
|
+
href="${base}/${p.id}#wp-waiting"
|
|
58
|
+
title="${awaitingLabel(p.awaiting)}"
|
|
59
|
+
aria-label="${awaitingLabel(p.awaiting)}"
|
|
60
|
+
>${raw("<svg viewBox=\"0 0 16 16\" width=\"13\" height=\"13\" aria-hidden=\"true\"><path d=\"M2 9.5 3.8 3.2A1 1 0 0 1 4.8 2.5h6.4a1 1 0 0 1 1 .7L14 9.5V13a.5.5 0 0 1-.5.5h-11A.5.5 0 0 1 2 13Zm0 0h3.5l1 1.5h3l1-1.5H14\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\" stroke-linejoin=\"round\"/></svg>")}${p.awaiting}</a
|
|
61
|
+
>`}
|
|
62
|
+
<span class="wp-meta"
|
|
63
|
+
><code>${p.id}</code> · edited
|
|
64
|
+
${time(p.mtime)}${p.lastEvent && html` · last submit ${time(Date.parse(p.lastEvent))}`}</span
|
|
65
|
+
>
|
|
66
|
+
</li>`)}
|
|
67
|
+
</ul>`;
|
|
68
|
+
}
|
|
69
|
+
/** The folder's README, when it has one. */
|
|
70
|
+
function readmeOf(page) {
|
|
71
|
+
const name = [
|
|
72
|
+
"README.md",
|
|
73
|
+
"readme.md",
|
|
74
|
+
"Readme.md"
|
|
75
|
+
].find((n) => page.entries.some((e) => !e.dir && e.name === n));
|
|
76
|
+
if (!name) return null;
|
|
77
|
+
const file = path.join(page.file, name);
|
|
78
|
+
return {
|
|
79
|
+
file,
|
|
80
|
+
source: fs.readFileSync(file, "utf8")
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** A stylesheet reference (URL, file: URL string, or absolute path) → absolute path. */
|
|
84
|
+
function stylePath(ref) {
|
|
85
|
+
if (ref == null) return null;
|
|
86
|
+
const file = ref instanceof URL || String(ref).startsWith("file:") ? fileURLToPath(ref) : String(ref);
|
|
87
|
+
if (!path.isAbsolute(file)) throw new Error(`style: use a URL, e.g. new URL('./style.css', import.meta.url)`);
|
|
88
|
+
if (!fs.existsSync(file)) throw new Error(`style: file not found: ${file}`);
|
|
89
|
+
return file;
|
|
90
|
+
}
|
|
91
|
+
const SKIP = /* @__PURE__ */ new Set([
|
|
92
|
+
"node_modules",
|
|
93
|
+
".git",
|
|
94
|
+
".workpad",
|
|
95
|
+
"dist",
|
|
96
|
+
"build"
|
|
97
|
+
]);
|
|
98
|
+
const MARKDOWN = /\.(md|markdown)$/i;
|
|
99
|
+
/**
|
|
100
|
+
* Every markdown file in the project, which renders as a page: the top folder's first,
|
|
101
|
+
* then by path. In a git repository, the files git knows (tracked, or new and not ignored), so
|
|
102
|
+
* built copies and dependencies stay out; elsewhere a walk that skips the usual build and
|
|
103
|
+
* dependency folders. The project's own pages (.workpad/) are listed apart.
|
|
104
|
+
*/
|
|
105
|
+
function documentsIn(dir, shows = (rel) => fileFilter().shows(rel)) {
|
|
106
|
+
let files;
|
|
107
|
+
try {
|
|
108
|
+
files = execFileSync("git", [
|
|
109
|
+
"ls-files",
|
|
110
|
+
"--cached",
|
|
111
|
+
"--others",
|
|
112
|
+
"--exclude-standard",
|
|
113
|
+
"--",
|
|
114
|
+
":(icase)*.md",
|
|
115
|
+
":(icase)*.markdown"
|
|
116
|
+
], {
|
|
117
|
+
cwd: dir,
|
|
118
|
+
encoding: "utf8",
|
|
119
|
+
stdio: [
|
|
120
|
+
"ignore",
|
|
121
|
+
"pipe",
|
|
122
|
+
"ignore"
|
|
123
|
+
]
|
|
124
|
+
}).split("\n").filter((f) => f && !f.startsWith(".workpad/") && fs.existsSync(path.join(dir, f)));
|
|
125
|
+
} catch {
|
|
126
|
+
files = [];
|
|
127
|
+
const walk = (rel) => {
|
|
128
|
+
let entries = [];
|
|
129
|
+
try {
|
|
130
|
+
entries = fs.readdirSync(path.join(dir, rel), { withFileTypes: true });
|
|
131
|
+
} catch {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
for (const e of entries) if (e.isDirectory()) {
|
|
135
|
+
if (!SKIP.has(e.name) && !e.name.startsWith(".")) walk(path.posix.join(rel, e.name));
|
|
136
|
+
} else if (MARKDOWN.test(e.name)) files.push(path.posix.join(rel, e.name));
|
|
137
|
+
};
|
|
138
|
+
walk("");
|
|
139
|
+
}
|
|
140
|
+
const depth = (f) => f.split("/").length;
|
|
141
|
+
return [...new Set(files)].filter(shows).toSorted((a, b) => depth(a) - depth(b) || a.localeCompare(b));
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The overview's list of the project's documents: each by its title, linked to its rendered page,
|
|
145
|
+
* with when its file last changed. The list can be sorted in the browser (sort.ts): by folder (as
|
|
146
|
+
* written here), by when last updated, or by title; each row carries what it is sorted by.
|
|
147
|
+
*/
|
|
148
|
+
function documentList(ctx) {
|
|
149
|
+
return documentsOf(ctx.project.dir, ctx.base ?? "", ctx.urlFor, false, ctx.project.shows);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* A project's documents by the folder they are in, each folder a fold with how many it holds, the
|
|
153
|
+
* top folder's own documents first: the shared server's overview, where a repository's many
|
|
154
|
+
* documents would otherwise be one long list. A folder holding only one folder is shown as one
|
|
155
|
+
* (`docs/adr/`), so the tree is no deeper than what tells folders apart.
|
|
156
|
+
*/
|
|
157
|
+
function documentTree(files, dir, base, urlFor, open = false) {
|
|
158
|
+
const root = {
|
|
159
|
+
files: [],
|
|
160
|
+
folders: /* @__PURE__ */ new Map(),
|
|
161
|
+
count: 0
|
|
162
|
+
};
|
|
163
|
+
for (const f of files) {
|
|
164
|
+
let at = root;
|
|
165
|
+
at.count++;
|
|
166
|
+
const parts = f.split("/");
|
|
167
|
+
for (const part of parts.slice(0, -1)) {
|
|
168
|
+
if (!at.folders.has(part)) at.folders.set(part, {
|
|
169
|
+
files: [],
|
|
170
|
+
folders: /* @__PURE__ */ new Map(),
|
|
171
|
+
count: 0
|
|
172
|
+
});
|
|
173
|
+
at = at.folders.get(part);
|
|
174
|
+
at.count++;
|
|
175
|
+
}
|
|
176
|
+
at.files.push(f);
|
|
177
|
+
}
|
|
178
|
+
const row = (f) => {
|
|
179
|
+
const abs = path.join(dir, f);
|
|
180
|
+
const name = path.posix.basename(f);
|
|
181
|
+
const title = titleOf(abs, name);
|
|
182
|
+
let mtime = 0;
|
|
183
|
+
try {
|
|
184
|
+
mtime = fs.statSync(abs).mtimeMs;
|
|
185
|
+
} catch {}
|
|
186
|
+
return html`<li>
|
|
187
|
+
<a href="${urlFor(abs) ?? `${base}/-/${f}`}">${title}</a>
|
|
188
|
+
<span class="wp-meta">${title !== name && html`<code>${name}</code> · `}edited ${time(mtime)}</span>
|
|
189
|
+
</li>`;
|
|
190
|
+
};
|
|
191
|
+
const folder = (name, f) => {
|
|
192
|
+
while (!f.files.length && f.folders.size === 1) {
|
|
193
|
+
const [inner, next] = [...f.folders][0];
|
|
194
|
+
name = `${name}/${inner}`;
|
|
195
|
+
f = next;
|
|
196
|
+
}
|
|
197
|
+
return html`<details class="wp-folder">
|
|
198
|
+
<summary>${name}/ <span class="wp-meta">${f.count}</span></summary>
|
|
199
|
+
${contents(f)}
|
|
200
|
+
</details>`;
|
|
201
|
+
};
|
|
202
|
+
const contents = (f) => html`${f.files.length > 0 && html`<ul class="wp-index">
|
|
203
|
+
${f.files.map(row)}
|
|
204
|
+
</ul>`}${[...f.folders].toSorted(([a], [b]) => a.localeCompare(b)).map(([name, sub]) => folder(name, sub))}`;
|
|
205
|
+
return html`<details class="wp-documents wp-folded-documents"${raw(open ? " open" : "")}>
|
|
206
|
+
<summary>Files <span class="wp-meta">${files.length}</span></summary>
|
|
207
|
+
${contents(root)}
|
|
208
|
+
</details>`;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* A project's documents, as its overview lists them: from its folder, linked where it serves them.
|
|
212
|
+
* `folded`: in a fold that says how many (the shared server's overview, where each project has them).
|
|
213
|
+
*/
|
|
214
|
+
function documentsOf(dir, base, urlFor, folded = false, shows, open = false) {
|
|
215
|
+
const files = documentsIn(dir, shows);
|
|
216
|
+
if (!files.length) return "";
|
|
217
|
+
const ctx = {
|
|
218
|
+
project: { dir },
|
|
219
|
+
base,
|
|
220
|
+
urlFor
|
|
221
|
+
};
|
|
222
|
+
const rows = files.map((f, i) => {
|
|
223
|
+
const abs = path.join(ctx.project.dir, f);
|
|
224
|
+
const name = path.posix.basename(f);
|
|
225
|
+
const title = titleOf(abs, name);
|
|
226
|
+
const where = title === name ? path.posix.dirname(f) : f;
|
|
227
|
+
let mtime = 0;
|
|
228
|
+
try {
|
|
229
|
+
mtime = fs.statSync(abs).mtimeMs;
|
|
230
|
+
} catch {}
|
|
231
|
+
return html`<li data-order="${i}" data-updated="${mtime}" data-title="${title.toLowerCase()}">
|
|
232
|
+
<a href="${ctx.urlFor(abs) ?? `${ctx.base ?? ""}/-/${f}`}">${title}</a>
|
|
233
|
+
<span class="wp-meta"
|
|
234
|
+
>${where !== "." && html`<code>${where === f ? f : `${where}/`}</code> · `}edited ${time(mtime)}</span
|
|
235
|
+
>
|
|
236
|
+
</li>`;
|
|
237
|
+
});
|
|
238
|
+
if (folded) return documentTree(files, dir, base, urlFor, open);
|
|
239
|
+
return html`<section class="wp-documents">
|
|
240
|
+
<div class="wp-list-head">
|
|
241
|
+
<h2>Documents</h2>
|
|
242
|
+
<label class="wp-sort"
|
|
243
|
+
>sort
|
|
244
|
+
<select data-wp-sort="documents" aria-label="Sort the documents">
|
|
245
|
+
<option value="order">by folder</option>
|
|
246
|
+
<option value="updated">last updated</option>
|
|
247
|
+
<option value="title">by title</option>
|
|
248
|
+
</select></label
|
|
249
|
+
>
|
|
250
|
+
</div>
|
|
251
|
+
<ul class="wp-index">
|
|
252
|
+
${rows}
|
|
253
|
+
</ul>
|
|
254
|
+
</section>`;
|
|
255
|
+
}
|
|
256
|
+
/** What waits on a page or a project, as small badges; nothing when nothing waits. */
|
|
257
|
+
function counts(w, href) {
|
|
258
|
+
const badge = (kind, n, text, title) => n > 0 && (href ? html`<a class="wp-count wp-count-${kind}" href="${href}" title="${title}">${n} ${text}</a>` : html`<span class="wp-count wp-count-${kind}" title="${title}">${n} ${text}</span>`);
|
|
259
|
+
if (!total(w)) return "";
|
|
260
|
+
return html`<span class="wp-counts"
|
|
261
|
+
>${badge("open", w.open, "open", w.open === 1 ? "1 question waiting for you" : `${w.open} questions waiting for you`)}${badge("unread", w.unread, "unread", w.unread === 1 ? "1 message you haven’t read" : `${w.unread} messages you haven’t read`)}${badge("unreceived", w.unreceived, "not received", w.unreceived === 1 ? "1 answer no agent received" : `${w.unreceived} answers no agent received`)}</span
|
|
262
|
+
>`;
|
|
263
|
+
}
|
|
264
|
+
/** A page on the board: its title, what waits on it, and (in a column of states) its project. */
|
|
265
|
+
function card(c, withProject) {
|
|
266
|
+
return html`<li class="wp-board-card${total(c.waiting) > 0 ? " wp-board-waits" : ""}">
|
|
267
|
+
<a class="wp-board-title" href="${c.page.url}">${c.page.title}</a>
|
|
268
|
+
${counts(c.waiting, `${c.page.url}#wp-waiting`)}
|
|
269
|
+
${withProject && html`<span class="wp-board-project">${c.project.label}</span>`}
|
|
270
|
+
<span class="wp-meta wp-board-when">edited ${time(c.page.mtime)}</span>
|
|
271
|
+
</li>`;
|
|
272
|
+
}
|
|
273
|
+
function cards(list, withProject) {
|
|
274
|
+
return list.length ? html`<ul class="wp-board-cards">
|
|
275
|
+
${list.map((c) => card(c, withProject))}
|
|
276
|
+
</ul>` : html`<p class="wp-meta wp-board-none">Nothing here.</p>`;
|
|
277
|
+
}
|
|
278
|
+
const pagesCount = (n) => n === 1 ? "1 page" : `${n} pages`;
|
|
279
|
+
/** The projects without pages, folded into one column at the end. */
|
|
280
|
+
function emptyColumn(projects) {
|
|
281
|
+
if (!projects.length) return "";
|
|
282
|
+
return html`<details class="wp-board-column wp-board-empty">
|
|
283
|
+
<summary>${projects.length} without pages</summary>
|
|
284
|
+
<ul>
|
|
285
|
+
${projects.map((p) => html`<li><a href="${p.base}/" title="${p.error ?? p.dir}">${p.label}</a></li>`)}
|
|
286
|
+
</ul>
|
|
287
|
+
</details>`;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* The shared server's overview: its projects' pages as columns you scroll sideways, a column per
|
|
291
|
+
* state (what waits for you, what changed lately, the rest) or a column per project; the reader
|
|
292
|
+
* switches between them (board.ts in the page), both are here. Projects without pages are folded
|
|
293
|
+
* at the end of either.
|
|
294
|
+
*/
|
|
295
|
+
function board(projects, now) {
|
|
296
|
+
const states = byState(projects, now);
|
|
297
|
+
const docsOf = new Map(withoutPages(projects).map((p) => [p, p.files ? documentsIn(p.dir).length : 0]));
|
|
298
|
+
const empty = withoutPages(projects);
|
|
299
|
+
const withDocs = [...docsOf].filter(([, n]) => n > 0).map(([p]) => p);
|
|
300
|
+
const bare = empty.filter((p) => !docsOf.get(p));
|
|
301
|
+
const hours = ACTIVE_FOR / 36e5;
|
|
302
|
+
const stateColumn = (key, title, note) => html`<section class="wp-board-column wp-board-${key}${key === "waiting" && states.waiting.length ? " wp-board-waits" : ""}">
|
|
303
|
+
<header class="wp-board-head">
|
|
304
|
+
<h2>${title}</h2>
|
|
305
|
+
<span class="wp-meta">${pagesCount(states[key].length)}${note && ` · ${note}`}</span>
|
|
306
|
+
</header>
|
|
307
|
+
${cards(states[key], true)}
|
|
308
|
+
</section>`;
|
|
309
|
+
const projectColumn = (col) => {
|
|
310
|
+
const p = col.project;
|
|
311
|
+
return html`<section class="wp-board-column${total(col.waiting) > 0 ? " wp-board-waits" : ""}">
|
|
312
|
+
<header class="wp-board-head" title="${p.dir.replace(os.homedir(), "~")}">
|
|
313
|
+
<h2>${p.label}</h2>
|
|
314
|
+
<span class="wp-meta">edited ${time(p.active)} · ${pagesCount(col.cards.length)}</span>
|
|
315
|
+
${counts(col.waiting, null)}
|
|
316
|
+
</header>
|
|
317
|
+
${cards(col.cards, false)} ${p.files && documentsOf(p.dir, p.base, () => null, true)}
|
|
318
|
+
</section>`;
|
|
319
|
+
};
|
|
320
|
+
const docsColumn = (p) => html`<section class="wp-board-column wp-board-docs">
|
|
321
|
+
<header class="wp-board-head" title="${p.dir.replace(os.homedir(), "~")}">
|
|
322
|
+
<h2><a href="${p.base}/">${p.label}</a></h2>
|
|
323
|
+
<span class="wp-meta">no pages · ${docsOf.get(p)} file${docsOf.get(p) === 1 ? "" : "s"}</span>
|
|
324
|
+
</header>
|
|
325
|
+
${documentsOf(p.dir, p.base, () => null, true, void 0, true)}
|
|
326
|
+
</section>`;
|
|
327
|
+
return html`<div class="wp-board-bar">
|
|
328
|
+
<div class="wp-board-switch" role="group" aria-label="Columns">
|
|
329
|
+
<button type="button" data-wp-board="state">By state</button
|
|
330
|
+
><button type="button" data-wp-board="project">By project</button>
|
|
331
|
+
</div>
|
|
332
|
+
<input
|
|
333
|
+
type="search"
|
|
334
|
+
class="wp-board-search"
|
|
335
|
+
placeholder="Search pages, projects, files /"
|
|
336
|
+
aria-label="Search the overview"
|
|
337
|
+
autocomplete="off"
|
|
338
|
+
spellcheck="false"
|
|
339
|
+
/>
|
|
340
|
+
</div>
|
|
341
|
+
<p class="wp-board-nomatch" hidden>Nothing here matches.</p>
|
|
342
|
+
<div class="wp-board" data-board="state">
|
|
343
|
+
${stateColumn("waiting", "Waiting for you", "")}
|
|
344
|
+
${stateColumn("active", "Active", `changed in the last ${hours} hours`)}
|
|
345
|
+
${stateColumn("quiet", "Quiet", "")} ${emptyColumn(empty)}
|
|
346
|
+
</div>
|
|
347
|
+
<div class="wp-board" data-board="project">
|
|
348
|
+
${byProject(projects).map(projectColumn)} ${withDocs.map(docsColumn)} ${emptyColumn(bare)}
|
|
349
|
+
</div>`;
|
|
350
|
+
}
|
|
351
|
+
/** The plugins' text links for a project folder, asked once per folder. */
|
|
352
|
+
function textLinksOf(links) {
|
|
353
|
+
const linksFor = /* @__PURE__ */ new Map();
|
|
354
|
+
return (dir) => {
|
|
355
|
+
let got = linksFor.get(dir);
|
|
356
|
+
if (!got) {
|
|
357
|
+
got = links.flatMap((fn) => {
|
|
358
|
+
try {
|
|
359
|
+
return fn({ dir });
|
|
360
|
+
} catch (err) {
|
|
361
|
+
console.error("links:", err);
|
|
362
|
+
return [];
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
linksFor.set(dir, got);
|
|
366
|
+
}
|
|
367
|
+
return got;
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* A message (a comment, a chat message) as HTML: markdown as on a page, but its raw HTML as text and
|
|
372
|
+
* its directives as written. Code fences go to the code block, so `styles` are what it needs linked.
|
|
373
|
+
*/
|
|
374
|
+
/**
|
|
375
|
+
* An agent's chat message as a small page (Pages.agentMessage): every block, as on the page, in the
|
|
376
|
+
* chat it is in (RenderOptions.chat).
|
|
377
|
+
*/
|
|
378
|
+
/** Islands as the browser loads them: each client module at the address the server serves it from. */
|
|
379
|
+
const served = (islands, ctx) => Object.fromEntries(Object.entries(islands).map(([id, island]) => [id, {
|
|
380
|
+
...island,
|
|
381
|
+
client: ctx.asset(island.client)
|
|
382
|
+
}]));
|
|
383
|
+
function createAgentMessageRender(blocks, links = [], composers = /* @__PURE__ */ new Map()) {
|
|
384
|
+
const textLinks = textLinksOf(links);
|
|
385
|
+
return async (text, ctx, where) => {
|
|
386
|
+
const { blocks: set, code, alert } = blocks();
|
|
387
|
+
const out = await renderMarkdown(String(text ?? ""), {
|
|
388
|
+
page: where.page,
|
|
389
|
+
file: where.file,
|
|
390
|
+
resolve: (name) => set.get(name) ?? null,
|
|
391
|
+
code,
|
|
392
|
+
alert: alert?.name ?? null,
|
|
393
|
+
linkFor: ctx.urlFor,
|
|
394
|
+
textLinks: textLinks(ctx.project.dir),
|
|
395
|
+
composers,
|
|
396
|
+
chat: {
|
|
397
|
+
name: where.chat,
|
|
398
|
+
first: where.first,
|
|
399
|
+
prefix: where.prefix
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
return {
|
|
403
|
+
html: String(out.html),
|
|
404
|
+
islands: served(out.islands, ctx),
|
|
405
|
+
styles: out.styles.map((s) => ctx.asset(s))
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Markdown a plugin's client asks for (Api.blocks): every block, as on the page `where.page`, files
|
|
411
|
+
* resolved from it, its islands' ids starting with `where.prefix`.
|
|
412
|
+
*/
|
|
413
|
+
function createBlocksRender(blocks, links = [], composers = /* @__PURE__ */ new Map()) {
|
|
414
|
+
const textLinks = textLinksOf(links);
|
|
415
|
+
return async (text, ctx, where) => {
|
|
416
|
+
const { blocks: set, code, alert } = blocks();
|
|
417
|
+
const out = await renderMarkdown(String(text ?? ""), {
|
|
418
|
+
page: where.page,
|
|
419
|
+
file: where.file,
|
|
420
|
+
resolve: (name) => set.get(name) ?? null,
|
|
421
|
+
code,
|
|
422
|
+
alert: alert?.name ?? null,
|
|
423
|
+
linkFor: ctx.urlFor,
|
|
424
|
+
textLinks: textLinks(ctx.project.dir),
|
|
425
|
+
composers,
|
|
426
|
+
prefix: where.prefix
|
|
427
|
+
});
|
|
428
|
+
return {
|
|
429
|
+
html: String(out.html),
|
|
430
|
+
islands: served(out.islands, ctx),
|
|
431
|
+
styles: out.styles.map((s) => ctx.asset(s))
|
|
432
|
+
};
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
function createMessageRender(blocks, links = []) {
|
|
436
|
+
const textLinks = textLinksOf(links);
|
|
437
|
+
return async (text, ctx) => {
|
|
438
|
+
const out = await renderMarkdown(String(text ?? ""), {
|
|
439
|
+
page: "",
|
|
440
|
+
file: "",
|
|
441
|
+
resolve: (name) => {
|
|
442
|
+
const block = blocks().blocks.get(name) ?? null;
|
|
443
|
+
return block?.fences ? block : null;
|
|
444
|
+
},
|
|
445
|
+
code: blocks().code,
|
|
446
|
+
textLinks: textLinks(ctx.project.dir),
|
|
447
|
+
message: true
|
|
448
|
+
});
|
|
449
|
+
return {
|
|
450
|
+
html: out.html,
|
|
451
|
+
styles: out.styles.map((s) => ctx.asset(s))
|
|
452
|
+
};
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
/** What a block left out of a build (RenderContext.skip) is: nothing, for its directives and fences alike. */
|
|
456
|
+
const skipped = (name) => ({
|
|
457
|
+
name,
|
|
458
|
+
code: false,
|
|
459
|
+
fences: true,
|
|
460
|
+
alerts: false,
|
|
461
|
+
attrs: null,
|
|
462
|
+
menu: null,
|
|
463
|
+
props: null,
|
|
464
|
+
html: () => "",
|
|
465
|
+
open: null,
|
|
466
|
+
client: null,
|
|
467
|
+
style: null,
|
|
468
|
+
source: "build"
|
|
469
|
+
});
|
|
470
|
+
function createRender(blocks, style, pluginStyles = [], links = [], composers = /* @__PURE__ */ new Map()) {
|
|
471
|
+
const textLinks = textLinksOf(links);
|
|
472
|
+
const STYLE = stylePath(style);
|
|
473
|
+
const PLUGIN_STYLES = pluginStyles.map((s) => ({
|
|
474
|
+
plugin: s.plugin,
|
|
475
|
+
file: stylePath(s.file)
|
|
476
|
+
})).filter((s) => !!s.file);
|
|
477
|
+
/** `content`: the markdown without its frontmatter. */
|
|
478
|
+
async function markdown(content, page, file, ctx) {
|
|
479
|
+
const { blocks: set, code, alert } = blocks();
|
|
480
|
+
const skip = ctx.skip;
|
|
481
|
+
return renderMarkdown(content, {
|
|
482
|
+
page,
|
|
483
|
+
file,
|
|
484
|
+
resolve: (name) => {
|
|
485
|
+
const block = set.get(name) ?? null;
|
|
486
|
+
if (skip && (skip.has(name) || block && skip.has(block.source))) return {
|
|
487
|
+
...skipped(name),
|
|
488
|
+
alerts: block?.alerts ?? false
|
|
489
|
+
};
|
|
490
|
+
return block;
|
|
491
|
+
},
|
|
492
|
+
code,
|
|
493
|
+
alert: alert?.name ?? null,
|
|
494
|
+
linkFor: ctx.urlFor,
|
|
495
|
+
textLinks: textLinks(ctx.project.dir),
|
|
496
|
+
composers: skip ? new Map([...composers].map(([name, compose]) => skip.has(name) ? [name, ({ children }) => String(children)] : [name, compose])) : composers
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
async function content(page, ctx) {
|
|
500
|
+
const { project } = ctx;
|
|
501
|
+
switch (page.kind) {
|
|
502
|
+
case "page": return markdown(page.body, page.id, page.file, ctx);
|
|
503
|
+
case "pages": {
|
|
504
|
+
if (page.projects) return {
|
|
505
|
+
html: html`<h1>${project.name}</h1>
|
|
506
|
+
${board(page.projects, Date.now())} ${page.note && html`<p class="wp-meta">${page.note}</p>`}`,
|
|
507
|
+
title: project.name,
|
|
508
|
+
islands: {},
|
|
509
|
+
styles: []
|
|
510
|
+
};
|
|
511
|
+
const list = page.pages.length ? pageList(page.pages, ctx.base ?? "") : html`<p class="wp-meta">No pages yet.</p>`;
|
|
512
|
+
return {
|
|
513
|
+
html: page.id ? html`<h1>${page.id}</h1>
|
|
514
|
+
${list}
|
|
515
|
+
<p class="wp-meta">${page.file}</p>` : html`<h1>${project.name}</h1>
|
|
516
|
+
${list}${project.files && documentList(ctx)}
|
|
517
|
+
<p class="wp-meta">
|
|
518
|
+
<code>${project.dir}</code>${project.files && html` · <a href="${ctx.base ?? ""}/-/">files</a>`} ·
|
|
519
|
+
<a href="${ctx.base ?? ""}/_/docs">how to write pages</a>
|
|
520
|
+
</p>`,
|
|
521
|
+
title: page.id || project.name,
|
|
522
|
+
islands: {},
|
|
523
|
+
styles: []
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
case "folder": {
|
|
527
|
+
const rel = page.id.slice(2);
|
|
528
|
+
const rows = page.entries.map((e) => html`<li>
|
|
529
|
+
<a href="${encodeURIComponent(e.name) + (e.dir ? "/" : "")}">${e.name + (e.dir ? "/" : "")}</a>
|
|
530
|
+
</li>`);
|
|
531
|
+
const listing = html`<h1>${rel || project.name}</h1>
|
|
532
|
+
<ul class="wp-files">
|
|
533
|
+
${rel && html`<li><a href="../">../</a></li>`}${rows}
|
|
534
|
+
</ul>
|
|
535
|
+
<p class="wp-meta">${page.file} · <code>${page.id}</code></p>`;
|
|
536
|
+
const readme = readmeOf(page);
|
|
537
|
+
if (!readme) return {
|
|
538
|
+
html: listing,
|
|
539
|
+
title: rel || project.name,
|
|
540
|
+
islands: {},
|
|
541
|
+
styles: []
|
|
542
|
+
};
|
|
543
|
+
const r = await markdown(body(readme.source), page.id, readme.file, ctx);
|
|
544
|
+
return {
|
|
545
|
+
...r,
|
|
546
|
+
html: html`${raw(r.html)}
|
|
547
|
+
<hr />
|
|
548
|
+
${listing}`
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
case "file": {
|
|
552
|
+
const { code } = blocks();
|
|
553
|
+
const ext = path.extname(page.file).slice(1).toLowerCase();
|
|
554
|
+
const tree = {
|
|
555
|
+
type: "root",
|
|
556
|
+
children: [{
|
|
557
|
+
type: "code",
|
|
558
|
+
lang: CODE_LANG[ext] ?? (ext || null),
|
|
559
|
+
meta: null,
|
|
560
|
+
value: page.source
|
|
561
|
+
}]
|
|
562
|
+
};
|
|
563
|
+
const out = await renderMarkdown(tree, {
|
|
564
|
+
page: page.id,
|
|
565
|
+
file: page.file,
|
|
566
|
+
resolve: () => null,
|
|
567
|
+
code,
|
|
568
|
+
linkFor: ctx.urlFor
|
|
569
|
+
});
|
|
570
|
+
return {
|
|
571
|
+
html: html`<h1 class="wp-code-title wp-wide">${page.id.slice(2)}</h1>
|
|
572
|
+
<div class="wp-code wp-wide">${raw(out.html)}</div>`,
|
|
573
|
+
title: path.basename(page.file),
|
|
574
|
+
islands: out.islands,
|
|
575
|
+
styles: out.styles
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return async function render(page, ctx) {
|
|
581
|
+
let out;
|
|
582
|
+
try {
|
|
583
|
+
out = await content(page, ctx);
|
|
584
|
+
} catch (err) {
|
|
585
|
+
out = {
|
|
586
|
+
html: html`<pre class="wp-error">${err.message}</pre>`,
|
|
587
|
+
islands: {},
|
|
588
|
+
styles: []
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
const islands = Object.fromEntries(Object.entries(out.islands).map(([id, island]) => [id, {
|
|
592
|
+
...island,
|
|
593
|
+
client: ctx.asset(island.client)
|
|
594
|
+
}]));
|
|
595
|
+
const styles = out.styles.map((s) => ctx.asset(s));
|
|
596
|
+
const nav = ctx.live === false ? html`<nav class="wp-nav">
|
|
597
|
+
<span>${ctx.project.name}</span><span data-wp-slot="header"></span
|
|
598
|
+
><button
|
|
599
|
+
type="button"
|
|
600
|
+
class="wp-theme"
|
|
601
|
+
title="Theme: follow the system, light or dark"
|
|
602
|
+
aria-label="Theme"
|
|
603
|
+
></button>
|
|
604
|
+
</nav>` : html`<nav class="wp-nav">
|
|
605
|
+
<span>${crumbs(page.id, ctx.entry?.label || ctx.project.name, ctx.base ?? "", ctx.entry)}</span
|
|
606
|
+
>${page.mtime != null && html`<span class="wp-meta">updated <time id="wp-updated" data-ts="${page.mtime}"></time></span>`}<span
|
|
607
|
+
data-wp-slot="header"
|
|
608
|
+
></span
|
|
609
|
+
><button
|
|
610
|
+
type="button"
|
|
611
|
+
class="wp-theme"
|
|
612
|
+
title="Theme: follow the system, light or dark"
|
|
613
|
+
aria-label="Theme"
|
|
614
|
+
></button
|
|
615
|
+
><span class="wp-live" role="img" title="Connecting…" aria-label="Connecting…"></span>
|
|
616
|
+
</nav>`;
|
|
617
|
+
const links = [
|
|
618
|
+
ctx.asset(BASE_CSS),
|
|
619
|
+
...PLUGIN_STYLES.filter((s) => !ctx.skip?.has(s.plugin)).map((s) => ctx.asset(s.file)),
|
|
620
|
+
...styles,
|
|
621
|
+
...STYLE ? [ctx.asset(STYLE)] : []
|
|
622
|
+
];
|
|
623
|
+
return {
|
|
624
|
+
title: out.title || page.id || ctx.project.name,
|
|
625
|
+
head: html`${THEME_SCRIPT} ${links.map((href) => html`<link rel="stylesheet" href="${href}" />`)}`,
|
|
626
|
+
html: html`${nav}
|
|
627
|
+
<div class="wp-body"><main id="wp-main">${raw(out.html)}</main></div>`,
|
|
628
|
+
data: {
|
|
629
|
+
islands,
|
|
630
|
+
styles,
|
|
631
|
+
mtime: page.mtime
|
|
632
|
+
},
|
|
633
|
+
problems: out.problems ?? []
|
|
634
|
+
};
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
/** The menu's groups, in order: what an agent writing a page is trying to do. */
|
|
638
|
+
const GROUPS = [
|
|
639
|
+
["ask", "Ask: get something back from the reader"],
|
|
640
|
+
["show", "Show: put something in front of the reader"],
|
|
641
|
+
["arrange", "Arrange: several things, or one out of the way"],
|
|
642
|
+
["mark", "Mark: how something stands, or how much it counts"]
|
|
643
|
+
];
|
|
644
|
+
/**
|
|
645
|
+
* What `workpad docs` prints first: how pages are written, then the menu: a line per block that
|
|
646
|
+
* has one (Block.menu), under what it is for. How to write each is in its plugin's docs.
|
|
647
|
+
*/
|
|
648
|
+
function createDocs(blocks) {
|
|
649
|
+
return function docs(_ctx) {
|
|
650
|
+
const all = [...blocks().blocks.values()].filter((t) => t.menu);
|
|
651
|
+
const width = Math.max(0, ...all.map((t) => t.name.length)) + 3;
|
|
652
|
+
return `# Pages
|
|
653
|
+
|
|
654
|
+
A page is markdown: GFM tables, \`<details>\`, raw HTML and a hand-written \`<form name="…">\` work as they are. Blocks: \`:::name\` around content, \`::name\` on a line, \`:name\` inside a line, and code fences (\`\`\`\` \`\`\`name \`\`\`\`). What the reader answers comes back as events: through your session's channel once \`workpad agent ping\` confirmed it (once a session), else with \`workpad listen\`. A block nobody brings renders its content, so a typo never breaks a page.
|
|
655
|
+
|
|
656
|
+
\`\`\`\`text
|
|
657
|
+
${GROUPS.map(([group, title]) => {
|
|
658
|
+
const lines = all.filter((t) => t.menu.group === group).map((t) => ` ${t.name.padEnd(width)}${t.menu.summary}`);
|
|
659
|
+
return lines.length ? `${title}\n${lines.join("\n")}` : "";
|
|
660
|
+
}).filter(Boolean).join("\n\n")}
|
|
661
|
+
\`\`\`\`
|
|
662
|
+
`;
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
export { createAgentMessageRender, createBlocksRender, createDocs, createMessageRender, createRender, titleOf };
|