@bigmistqke/workpad 0.0.0-stage → 0.18.1
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 +1526 -0
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/bin/workpad.js +1202 -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 +2121 -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 +213 -0
- package/dist/src/html.js +34 -0
- package/dist/src/hub.js +348 -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 +761 -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 +592 -0
- package/solid/index.tsx +80 -0
- package/src/agents.ts +134 -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 +166 -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 +240 -0
- package/src/html.ts +44 -0
- package/src/hub.ts +435 -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 +845 -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,179 @@
|
|
|
1
|
+
import { fileFilter } from "./files.js";
|
|
2
|
+
import { importFresh, importOwn } from "./load.js";
|
|
3
|
+
import { createPages } from "./pages/index.js";
|
|
4
|
+
import { configCommands, pluginCommands } from "./plugins.js";
|
|
5
|
+
import { inPublic, publicDirOf } from "./public.js";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
// src/loader.ts
|
|
10
|
+
const NAME = /^[\w-]+$/;
|
|
11
|
+
/** The command line's own commands: a plugin can't be named like one, since its commands are `workpad <name>`. */
|
|
12
|
+
const BUILTIN_COMMANDS = /* @__PURE__ */ new Set([
|
|
13
|
+
"serve",
|
|
14
|
+
"init",
|
|
15
|
+
"root",
|
|
16
|
+
"new",
|
|
17
|
+
"agent",
|
|
18
|
+
"show",
|
|
19
|
+
"check",
|
|
20
|
+
"migrate",
|
|
21
|
+
"settle",
|
|
22
|
+
"hold",
|
|
23
|
+
"release",
|
|
24
|
+
"url",
|
|
25
|
+
"anchors",
|
|
26
|
+
"docs",
|
|
27
|
+
"events",
|
|
28
|
+
"listen",
|
|
29
|
+
"append",
|
|
30
|
+
"handled",
|
|
31
|
+
"thread",
|
|
32
|
+
"status",
|
|
33
|
+
"scroll",
|
|
34
|
+
"archive",
|
|
35
|
+
"destroy",
|
|
36
|
+
"prune",
|
|
37
|
+
"build",
|
|
38
|
+
"edit",
|
|
39
|
+
"skill",
|
|
40
|
+
"paths",
|
|
41
|
+
"help"
|
|
42
|
+
]);
|
|
43
|
+
const RESERVED = /* @__PURE__ */ new Set([
|
|
44
|
+
"pages",
|
|
45
|
+
"plugins",
|
|
46
|
+
"archive",
|
|
47
|
+
...BUILTIN_COMMANDS
|
|
48
|
+
]);
|
|
49
|
+
/** A plugin's own folder, `.workpad/<name>/`, made with a .gitignore that ignores all of it. */
|
|
50
|
+
function pluginDir(wp, name) {
|
|
51
|
+
const dir = path.join(wp, name);
|
|
52
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
53
|
+
const ignore = path.join(dir, ".gitignore");
|
|
54
|
+
if (!fs.existsSync(ignore)) fs.writeFileSync(ignore, `# what the ${name} plugin keeps; not for git\n*\n`);
|
|
55
|
+
return dir;
|
|
56
|
+
}
|
|
57
|
+
/** A file reference (URL, file: URL string, or absolute path) → absolute path. */
|
|
58
|
+
function toPath(ref) {
|
|
59
|
+
if (ref instanceof URL || typeof ref === "string" && ref.startsWith("file:")) return fileURLToPath(ref);
|
|
60
|
+
return String(ref);
|
|
61
|
+
}
|
|
62
|
+
/** The built-in plugins, afresh with every load of the config, like what a config imports itself. */
|
|
63
|
+
async function builtinPlugins() {
|
|
64
|
+
const { builtins } = await importOwn("plugins");
|
|
65
|
+
return builtins();
|
|
66
|
+
}
|
|
67
|
+
/** Check a plugin, as the config gives it. */
|
|
68
|
+
function checkPlugin(e, where) {
|
|
69
|
+
if (typeof e !== "object" || !NAME.test(e?.name ?? "")) throw new Error(`a plugin in ${where} needs a name: letters, digits, - and _`);
|
|
70
|
+
if (RESERVED.has(e.name)) throw new Error(`plugin name "${e.name}" in ${where} is taken by the core (a folder in .workpad/ or a command)`);
|
|
71
|
+
pluginCommands(e);
|
|
72
|
+
for (const type of Object.keys(e.events ?? {})) if (!type.startsWith(`${e.name}:`) || type.length <= e.name.length + 1) throw new Error(`plugin ${e.name}: event type "${type}" must be named after it: ${e.name}:<what>`);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The config, cached until invalidate() (which loads it afresh). Errors are returned, not thrown:
|
|
76
|
+
* a config that fails to load leaves the project without its plugins, so pages show as raw text,
|
|
77
|
+
* and serves no repository files.
|
|
78
|
+
*
|
|
79
|
+
* The project's plugins are the built-in ones, then the config's: one with a built-in's name
|
|
80
|
+
* replaces it. Their blocks make the pages. `pages: false` leaves the pages out, for the command
|
|
81
|
+
* line, which only needs the plugins (their commands, the session, their events).
|
|
82
|
+
*/
|
|
83
|
+
/**
|
|
84
|
+
* How long a config that failed to load is kept before it is tried again: what failed may lie
|
|
85
|
+
* outside its file (a package installed, a link made), and no change to the file would reload it.
|
|
86
|
+
*/
|
|
87
|
+
const RETRY_FAILED_MS = 5e3;
|
|
88
|
+
/**
|
|
89
|
+
* `files`: whether the project serves its own files when its config doesn't say (a machine config's
|
|
90
|
+
* entry can say false for all of its projects; see EntryConfig).
|
|
91
|
+
*/
|
|
92
|
+
function createConfigLoader(proj, { pages: withPages = true, files: filesDefault = true } = {}) {
|
|
93
|
+
let cached = null;
|
|
94
|
+
let failedAt = null;
|
|
95
|
+
async function load() {
|
|
96
|
+
const configFile = proj.configFile;
|
|
97
|
+
const exported = (configFile ? await importFresh(configFile) : { default: {} }).default;
|
|
98
|
+
const config = typeof exported === "function" ? await exported() : exported;
|
|
99
|
+
const plugins = await builtinPlugins();
|
|
100
|
+
const builtin = new Set(plugins.map((p) => p.name));
|
|
101
|
+
const added = /* @__PURE__ */ new Set();
|
|
102
|
+
for (const e of [config?.plugins ?? []].flat(Infinity)) {
|
|
103
|
+
if (!e) continue;
|
|
104
|
+
checkPlugin(e, configFile);
|
|
105
|
+
if (added.has(e.name)) throw new Error(`two plugins are named "${e.name}" in ${configFile}`);
|
|
106
|
+
added.add(e.name);
|
|
107
|
+
if (builtin.has(e.name)) plugins[plugins.findIndex((p) => p.name === e.name)] = e;
|
|
108
|
+
else plugins.push(e);
|
|
109
|
+
}
|
|
110
|
+
const publicDirs = new Map(plugins.map((p) => [p.name, publicDirOf(p, proj.wp)]));
|
|
111
|
+
const blocks = plugins.flatMap((p) => Object.entries(p.blocks ?? {}).map(([name, block]) => ({
|
|
112
|
+
name,
|
|
113
|
+
block,
|
|
114
|
+
plugin: p.name,
|
|
115
|
+
public: publicDirs.get(p.name)
|
|
116
|
+
})));
|
|
117
|
+
const styles = plugins.filter((p) => p.style).map((p) => ({
|
|
118
|
+
plugin: p.name,
|
|
119
|
+
file: inPublic(publicDirs.get(p.name), p.style, `plugin ${p.name}: style`)
|
|
120
|
+
}));
|
|
121
|
+
const links = plugins.flatMap((p) => p.links ? [p.links.bind(p)] : []);
|
|
122
|
+
const composers = new Map(plugins.flatMap((p) => typeof p.compose === "function" ? [[p.name, p.compose.bind(p)]] : []));
|
|
123
|
+
const ends = plugins.flatMap((p) => p.end ? [p.end.bind(p)] : []);
|
|
124
|
+
const pages = withPages ? createPages({
|
|
125
|
+
blocks,
|
|
126
|
+
style: config?.style,
|
|
127
|
+
styles,
|
|
128
|
+
links,
|
|
129
|
+
composers,
|
|
130
|
+
ends
|
|
131
|
+
}) : null;
|
|
132
|
+
const declared = (flag) => new Set(plugins.flatMap((p) => Object.entries(p.events ?? {}).filter(([, spec]) => spec?.[flag]).map(([type]) => type)));
|
|
133
|
+
return {
|
|
134
|
+
pages,
|
|
135
|
+
plugins,
|
|
136
|
+
handedOut: declared("handOut"),
|
|
137
|
+
forReader: declared("forReader"),
|
|
138
|
+
publicDirs,
|
|
139
|
+
files: config?.files == null ? filesDefault : config.files !== false,
|
|
140
|
+
fileFilter: fileFilter(config?.files),
|
|
141
|
+
build: config?.build ?? {},
|
|
142
|
+
commands: configCommands(config?.commands, {
|
|
143
|
+
taken: RESERVED,
|
|
144
|
+
plugins: plugins.map((p) => p.name),
|
|
145
|
+
where: configFile
|
|
146
|
+
})
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function config() {
|
|
150
|
+
if (failedAt !== null && Date.now() - failedAt > RETRY_FAILED_MS) cached = null;
|
|
151
|
+
cached ??= load().then((value) => {
|
|
152
|
+
failedAt = null;
|
|
153
|
+
return {
|
|
154
|
+
...value,
|
|
155
|
+
errors: []
|
|
156
|
+
};
|
|
157
|
+
}, (error) => (failedAt = Date.now(), {
|
|
158
|
+
pages: null,
|
|
159
|
+
plugins: [],
|
|
160
|
+
handedOut: /* @__PURE__ */ new Set(),
|
|
161
|
+
forReader: /* @__PURE__ */ new Set(),
|
|
162
|
+
publicDirs: /* @__PURE__ */ new Map(),
|
|
163
|
+
files: false,
|
|
164
|
+
fileFilter: fileFilter(),
|
|
165
|
+
build: {},
|
|
166
|
+
commands: [],
|
|
167
|
+
errors: [error]
|
|
168
|
+
}));
|
|
169
|
+
return cached;
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
config,
|
|
173
|
+
invalidate: () => {
|
|
174
|
+
cached = null;
|
|
175
|
+
failedAt = null;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export { BUILTIN_COMMANDS, createConfigLoader, pluginDir, toPath };
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { parseAttrs, parseMarkdown } from "./pages/markdown.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
// src/migrate.ts
|
|
5
|
+
const start = (n) => n.position.start.offset;
|
|
6
|
+
const end = (n) => n.position.end.offset;
|
|
7
|
+
/** Every node of the tree (depth first, in source order) that `match` picks. */
|
|
8
|
+
function nodes(tree, match) {
|
|
9
|
+
const found = [];
|
|
10
|
+
const walk = (n) => {
|
|
11
|
+
if (match(n)) found.push(n);
|
|
12
|
+
n.children?.forEach(walk);
|
|
13
|
+
};
|
|
14
|
+
walk(tree);
|
|
15
|
+
return found;
|
|
16
|
+
}
|
|
17
|
+
/** `source` with the edits made (they don't overlap). */
|
|
18
|
+
function edit(source, edits) {
|
|
19
|
+
let out = source;
|
|
20
|
+
for (const e of [...edits].sort((a, b) => b.from - a.from)) out = out.slice(0, e.from) + e.text + out.slice(e.to);
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
const directive = (name, type = "containerDirective") => (n) => n.type === type && n.name === name;
|
|
24
|
+
/** What is before `offset` on its line, when that is only indentation and quote markers (` > `); else ''. */
|
|
25
|
+
function prefixAt(source, offset) {
|
|
26
|
+
const before = source.slice(source.lastIndexOf("\n", offset - 1) + 1, offset);
|
|
27
|
+
return /^[ \t>]*$/.test(before) ? before : "";
|
|
28
|
+
}
|
|
29
|
+
/** The end of the line `offset` is on (before its newline). */
|
|
30
|
+
function lineEnd(source, offset) {
|
|
31
|
+
const at = source.indexOf("\n", offset);
|
|
32
|
+
return at < 0 ? source.length : at;
|
|
33
|
+
}
|
|
34
|
+
/** The label and the content of a container: remark-directive keeps the label as a flagged first paragraph. */
|
|
35
|
+
function parts(node) {
|
|
36
|
+
const [head, ...rest] = node.children ?? [];
|
|
37
|
+
return head?.data?.directiveLabel ? {
|
|
38
|
+
label: head,
|
|
39
|
+
kids: rest
|
|
40
|
+
} : {
|
|
41
|
+
label: null,
|
|
42
|
+
kids: node.children ?? []
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** The label of a container as written, between its brackets; '' without one. */
|
|
46
|
+
function labelSource(source, label) {
|
|
47
|
+
const kids = label?.children ?? [];
|
|
48
|
+
return kids.length ? source.slice(start(kids[0]), end(kids[kids.length - 1])) : "";
|
|
49
|
+
}
|
|
50
|
+
/** `:::steps` is `:::tabs` (its `count` is gone), and a link's `#step:` is `#tab:`. */
|
|
51
|
+
const stepsToTabs = {
|
|
52
|
+
name: "steps → tabs",
|
|
53
|
+
description: ":::steps is :::tabs (count dropped); a link to #step:x goes to #tab:x",
|
|
54
|
+
apply(source) {
|
|
55
|
+
const tree = parseMarkdown(source);
|
|
56
|
+
const edits = [];
|
|
57
|
+
for (const n of nodes(tree, directive("steps"))) {
|
|
58
|
+
const from = start(n);
|
|
59
|
+
const to = lineEnd(source, from);
|
|
60
|
+
const line = source.slice(from, to).replace(/^(:+)steps/, "$1tabs").replace(/\{([^}]*)\}(\s*)$/, (_, attrs, space) => {
|
|
61
|
+
const kept = attrs.replace(/(^|\s)count(=("[^"]*"|'[^']*'|[^\s}]*))?(?=\s|$)/g, "").trim();
|
|
62
|
+
return kept ? `{${kept}}${space}` : space;
|
|
63
|
+
});
|
|
64
|
+
edits.push({
|
|
65
|
+
from,
|
|
66
|
+
to,
|
|
67
|
+
text: line
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
for (const n of nodes(tree, (n) => (n.type === "link" || n.type === "definition") && /#step:/.test(n.url ?? ""))) {
|
|
71
|
+
const text = source.slice(start(n), end(n));
|
|
72
|
+
edits.push({
|
|
73
|
+
from: start(n),
|
|
74
|
+
to: end(n),
|
|
75
|
+
text: text.replaceAll("#step:", "#tab:")
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
source: edit(source, edits),
|
|
80
|
+
changes: edits.length
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const CALLOUT_TYPES = /* @__PURE__ */ new Set([
|
|
85
|
+
"note",
|
|
86
|
+
"tip",
|
|
87
|
+
"success",
|
|
88
|
+
"warning",
|
|
89
|
+
"danger",
|
|
90
|
+
"question"
|
|
91
|
+
]);
|
|
92
|
+
/** A `:::callout` as the alert it is now: `> [!TYPE] Title` and its lines behind `> `. */
|
|
93
|
+
function alertFor(source, node) {
|
|
94
|
+
const { label, kids } = parts(node);
|
|
95
|
+
const attrs = node.attributes ?? {};
|
|
96
|
+
const type = [attrs.type, ...String(attrs.class ?? "").split(/\s+/)].find((t) => t && CALLOUT_TYPES.has(t)) ?? "note";
|
|
97
|
+
const title = labelSource(source, label).trim();
|
|
98
|
+
const prefix = prefixAt(source, start(node));
|
|
99
|
+
const lines = [`[!${type.toUpperCase()}]${title ? ` ${title}` : ""}`];
|
|
100
|
+
if (kids.length) {
|
|
101
|
+
const from = lineEnd(source, start(node)) + 1;
|
|
102
|
+
const content = source.slice(from, end(kids[kids.length - 1]));
|
|
103
|
+
for (const line of content.split("\n")) {
|
|
104
|
+
const own = line.startsWith(prefix) ? line.slice(prefix.length) : line.trimStart();
|
|
105
|
+
lines.push(own);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return lines.map((l, i) => `${i ? prefix : ""}${l ? `> ${l}` : ">"}`.replace(/[ \t]+$/, "")).join("\n");
|
|
109
|
+
}
|
|
110
|
+
/** `:::callout[Title]{.warning}` is a GitHub alert, `> [!WARNING] Title`. */
|
|
111
|
+
const calloutToAlert = {
|
|
112
|
+
name: "callout → alert",
|
|
113
|
+
description: ":::callout[Title]{.warning} is > [!WARNING] Title (or type=…; a NOTE without)",
|
|
114
|
+
apply(source) {
|
|
115
|
+
let changes = 0;
|
|
116
|
+
for (;;) {
|
|
117
|
+
const callouts = nodes(parseMarkdown(source), directive("callout"));
|
|
118
|
+
const innermost = callouts.filter((c) => !callouts.some((d) => d !== c && start(d) >= start(c) && end(d) <= end(c)));
|
|
119
|
+
if (!innermost.length) break;
|
|
120
|
+
source = edit(source, innermost.map((n) => ({
|
|
121
|
+
from: start(n),
|
|
122
|
+
to: end(n),
|
|
123
|
+
text: alertFor(source, n)
|
|
124
|
+
})));
|
|
125
|
+
changes += innermost.length;
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
source,
|
|
129
|
+
changes
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const ITEM_BLOCKS = /* @__PURE__ */ new Set([
|
|
134
|
+
"grid",
|
|
135
|
+
"tabs",
|
|
136
|
+
"timeline"
|
|
137
|
+
]);
|
|
138
|
+
/** Directly in a block of items, these are an item as they are. */
|
|
139
|
+
const AS_IS = /* @__PURE__ */ new Set(["form", "details"]);
|
|
140
|
+
const FENCE = /^[ \t>]*(`{3,}|~{3,})/;
|
|
141
|
+
/** The most colons a container fence in `text` has, outside code fences; 0 for none. */
|
|
142
|
+
function maxColons(text) {
|
|
143
|
+
let most = 0;
|
|
144
|
+
let open = null;
|
|
145
|
+
for (const line of text.split("\n")) {
|
|
146
|
+
const fence = FENCE.exec(line);
|
|
147
|
+
if (open) {
|
|
148
|
+
if (fence && fence[1][0] === open.char && fence[1].length >= open.length && !line.slice(fence[0].length).trim()) open = null;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (fence) {
|
|
152
|
+
open = {
|
|
153
|
+
char: fence[1][0],
|
|
154
|
+
length: fence[1].length
|
|
155
|
+
};
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const colons = /^[ \t>]*(:{3,})/.exec(line);
|
|
159
|
+
if (colons) most = Math.max(most, colons[1].length);
|
|
160
|
+
}
|
|
161
|
+
return most;
|
|
162
|
+
}
|
|
163
|
+
/** A container's first line with at least `colons` colons, and its closing line likewise. */
|
|
164
|
+
function withColons(text, colons, closed) {
|
|
165
|
+
const lines = text.split("\n");
|
|
166
|
+
const more = (line) => line.replace(/^([ \t>]*)(:{3,})/, (_, space, has) => space + ":".repeat(Math.max(has.length, colons)));
|
|
167
|
+
lines[0] = more(lines[0]);
|
|
168
|
+
if (closed && lines.length > 1) lines[lines.length - 1] = more(lines[lines.length - 1]);
|
|
169
|
+
return lines.join("\n");
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The items of a grid, tabs or a timeline as `:::item[Title]` containers, where a heading at the
|
|
173
|
+
* block's shallowest heading level started one (titled by it) and a `---` did (untitled). What came
|
|
174
|
+
* before the first is an untitled item; a lone form or details is an item as it is. Every container
|
|
175
|
+
* around them takes the colons it needs now (only ever more than it had).
|
|
176
|
+
*/
|
|
177
|
+
function itemsIn(source) {
|
|
178
|
+
const tree = parseMarkdown(source);
|
|
179
|
+
let changes = 0;
|
|
180
|
+
/** The containers in `node` that aren't inside another: what `rebuild` emits afresh. */
|
|
181
|
+
const containersIn = (node) => (node.children ?? []).flatMap((c) => c.type === "containerDirective" ? [c] : containersIn(c));
|
|
182
|
+
/** source[from, to), its containers emitted afresh. */
|
|
183
|
+
function rebuild(from, to, within) {
|
|
184
|
+
const inside = within.flatMap((n) => n.type === "containerDirective" ? [n] : containersIn(n));
|
|
185
|
+
let out = "";
|
|
186
|
+
let at = from;
|
|
187
|
+
for (const c of inside.filter((c) => start(c) >= from && end(c) <= to).sort((a, b) => start(a) - start(b))) {
|
|
188
|
+
out += source.slice(at, start(c)) + emit(c);
|
|
189
|
+
at = end(c);
|
|
190
|
+
}
|
|
191
|
+
return out + source.slice(at, to);
|
|
192
|
+
}
|
|
193
|
+
function emit(node) {
|
|
194
|
+
const { kids } = parts(node);
|
|
195
|
+
const last = kids[kids.length - 1];
|
|
196
|
+
const closed = /\n[ \t>]*:{3,}[ \t]*$/.test(source.slice(start(node), end(node)));
|
|
197
|
+
const already = kids.every((k) => k.type === "containerDirective" && (k.name === "item" || AS_IS.has(k.name)));
|
|
198
|
+
if (!ITEM_BLOCKS.has(node.name) || already) {
|
|
199
|
+
if (!kids.length) return source.slice(start(node), end(node));
|
|
200
|
+
const body = rebuild(start(kids[0]), end(last), kids);
|
|
201
|
+
return withColons(source.slice(start(node), start(kids[0])) + body + source.slice(end(last), end(node)), maxColons(body) + 1, closed);
|
|
202
|
+
}
|
|
203
|
+
changes++;
|
|
204
|
+
const prefix = prefixAt(source, start(node));
|
|
205
|
+
const headings = kids.filter((k) => k.type === "heading");
|
|
206
|
+
const depth = headings.length ? Math.min(...headings.map((h) => h.depth)) : null;
|
|
207
|
+
const groups = [];
|
|
208
|
+
let current = null;
|
|
209
|
+
for (const k of kids) if (k.type === "heading" && k.depth === depth) groups.push(current = {
|
|
210
|
+
heading: k,
|
|
211
|
+
body: []
|
|
212
|
+
});
|
|
213
|
+
else if (k.type === "thematicBreak") groups.push(current = {
|
|
214
|
+
heading: null,
|
|
215
|
+
body: []
|
|
216
|
+
});
|
|
217
|
+
else {
|
|
218
|
+
if (!current) groups.push(current = {
|
|
219
|
+
heading: null,
|
|
220
|
+
body: []
|
|
221
|
+
});
|
|
222
|
+
current.body.push(k);
|
|
223
|
+
}
|
|
224
|
+
const content = groups.filter((g) => g.heading || g.body.length).map((g) => {
|
|
225
|
+
const body = g.body.length ? rebuild(start(g.body[0]), end(g.body[g.body.length - 1]), g.body) : "";
|
|
226
|
+
const lone = g.body[0];
|
|
227
|
+
if (!g.heading && g.body.length === 1 && lone.type === "containerDirective" && AS_IS.has(lone.name)) return body;
|
|
228
|
+
const label = g.heading ? labelSource(source, g.heading) : "";
|
|
229
|
+
const colons = ":".repeat(Math.max(3, maxColons(body) + 1));
|
|
230
|
+
return `${colons}item${label ? `[${label}]` : ""}\n${body ? `${prefix}${body}\n` : ""}${prefix}${colons}`;
|
|
231
|
+
}).join(`\n${prefix.trimEnd()}\n${prefix}`);
|
|
232
|
+
return withColons(`${source.slice(start(node), lineEnd(source, start(node)))}\n${prefix}${content}${closed ? `\n${prefix}:::` : ""}`, maxColons(content) + 1, closed);
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
source: rebuild(0, source.length, tree.children ?? []),
|
|
236
|
+
changes
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The migrations, in the order they run: each release's renames at the end. steps → tabs comes
|
|
241
|
+
* before items (tabs take items), and callouts are quotes before items count colons.
|
|
242
|
+
*/
|
|
243
|
+
const MIGRATIONS = [
|
|
244
|
+
stepsToTabs,
|
|
245
|
+
calloutToAlert,
|
|
246
|
+
{
|
|
247
|
+
name: "items",
|
|
248
|
+
description: "grid, tabs and timeline items started by a heading or --- are :::item[Title] containers",
|
|
249
|
+
apply: itemsIn
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: "check → checkbox",
|
|
253
|
+
description: "a form's :check[…] is :checkbox[…]",
|
|
254
|
+
apply(source) {
|
|
255
|
+
const found = nodes(parseMarkdown(source), directive("check", "textDirective")).filter((n) => source.startsWith(":check", start(n)));
|
|
256
|
+
return {
|
|
257
|
+
source: edit(source, found.map((n) => ({
|
|
258
|
+
from: start(n),
|
|
259
|
+
to: start(n) + 6,
|
|
260
|
+
text: ":checkbox"
|
|
261
|
+
}))),
|
|
262
|
+
changes: found.length
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
name: "ansi window",
|
|
268
|
+
description: "an ```ansi fence with a title gets compose=window, to stay a window",
|
|
269
|
+
apply(source) {
|
|
270
|
+
const edits = nodes(parseMarkdown(source), (n) => {
|
|
271
|
+
if (n.type !== "code" || n.lang !== "ansi") return false;
|
|
272
|
+
const attrs = parseAttrs(n.meta);
|
|
273
|
+
return "title" in attrs && !("compose" in attrs);
|
|
274
|
+
}).flatMap((n) => {
|
|
275
|
+
const from = start(n);
|
|
276
|
+
const line = source.slice(from, lineEnd(source, from));
|
|
277
|
+
const at = line.search(/(^|[\s{])title\b/);
|
|
278
|
+
if (at < 0) return [];
|
|
279
|
+
const where = from + at + (/[\s{]/.test(line[at]) ? 1 : 0);
|
|
280
|
+
return [{
|
|
281
|
+
from: where,
|
|
282
|
+
to: where,
|
|
283
|
+
text: "compose=window "
|
|
284
|
+
}];
|
|
285
|
+
});
|
|
286
|
+
return {
|
|
287
|
+
source: edit(source, edits),
|
|
288
|
+
changes: edits.length
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
];
|
|
293
|
+
/** A page's markdown in the current syntax, and what changed it: each migration that did, with how often. */
|
|
294
|
+
function migrate(source, migrations = MIGRATIONS) {
|
|
295
|
+
const applied = [];
|
|
296
|
+
for (const migration of migrations) {
|
|
297
|
+
const result = migration.apply(source);
|
|
298
|
+
if (result.source !== source) applied.push({
|
|
299
|
+
migration,
|
|
300
|
+
changes: Math.max(1, result.changes)
|
|
301
|
+
});
|
|
302
|
+
source = result.source;
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
source,
|
|
306
|
+
applied
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
/** The markdown files of a file or folder (in a folder: those below it, dot folders and node_modules left out). */
|
|
310
|
+
function markdownFiles(target) {
|
|
311
|
+
if (fs.statSync(target).isFile()) return [target];
|
|
312
|
+
return fs.readdirSync(target, { withFileTypes: true }).filter((e) => !e.name.startsWith(".") && e.name !== "node_modules").sort((a, b) => a.name.localeCompare(b.name)).flatMap((e) => e.isDirectory() ? markdownFiles(path.join(target, e.name)) : e.name.endsWith(".md") ? [path.join(target, e.name)] : []);
|
|
313
|
+
}
|
|
314
|
+
export { MIGRATIONS, markdownFiles, migrate };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
// src/package.ts
|
|
5
|
+
function findRoot(from) {
|
|
6
|
+
for (let dir = from;; dir = path.dirname(dir)) {
|
|
7
|
+
try {
|
|
8
|
+
if (JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8")).name === "@bigmistqke/workpad") return dir;
|
|
9
|
+
} catch {}
|
|
10
|
+
if (path.dirname(dir) === dir) throw new Error(`workpad: no package.json of @bigmistqke/workpad above ${from}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** The package's folder: where its package.json is. */
|
|
14
|
+
const PACKAGE_DIR = findRoot(path.dirname(fileURLToPath(import.meta.url)));
|
|
15
|
+
/** A path inside the package. */
|
|
16
|
+
const packagePath = (...parts) => path.join(PACKAGE_DIR, ...parts);
|
|
17
|
+
/**
|
|
18
|
+
* Is the engine running from its TypeScript source (`bin/workpad.ts`), rather than from its build
|
|
19
|
+
* (`dist/bin/workpad.js`, what an installed package runs)? Then what a config imports from the
|
|
20
|
+
* package comes from source too (the `source` export conditions), so the two never mix.
|
|
21
|
+
*/
|
|
22
|
+
const FROM_SOURCE = fileURLToPath(import.meta.url).endsWith(".ts");
|
|
23
|
+
/**
|
|
24
|
+
* A browser file built from the module at `moduleUrl`'s folder: `name` in that folder's place in
|
|
25
|
+
* dist/. The same whether the module runs from source (plugins/form/index.ts gives
|
|
26
|
+
* dist/plugins/form/client.js) or from dist/ itself.
|
|
27
|
+
*/
|
|
28
|
+
/** A built-in plugin's public folder: its built browser modules and copied styles (build.ts). */
|
|
29
|
+
const builtinPublic = (name) => packagePath("dist", "plugins", name, "public");
|
|
30
|
+
/** This package's version, from its package.json: what a shared server records, and its takeover compares. */
|
|
31
|
+
const VERSION = JSON.parse(fs.readFileSync(path.join(PACKAGE_DIR, "package.json"), "utf8")).version;
|
|
32
|
+
/** Compare two versions, x.y.z with an optional -pre: < 0 when a is older, 0 when the same, > 0 when newer. */
|
|
33
|
+
function compareVersions(a, b) {
|
|
34
|
+
const parse = (v) => {
|
|
35
|
+
const [main, pre] = String(v).split("-", 2);
|
|
36
|
+
return {
|
|
37
|
+
nums: main.split(".").map((n) => Number(n) || 0),
|
|
38
|
+
pre: pre ?? null
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const x = parse(a);
|
|
42
|
+
const y = parse(b);
|
|
43
|
+
for (let i = 0; i < Math.max(x.nums.length, y.nums.length); i++) {
|
|
44
|
+
const d = (x.nums[i] ?? 0) - (y.nums[i] ?? 0);
|
|
45
|
+
if (d) return Math.sign(d);
|
|
46
|
+
}
|
|
47
|
+
if (x.pre === y.pre) return 0;
|
|
48
|
+
if (x.pre == null) return 1;
|
|
49
|
+
if (y.pre == null) return -1;
|
|
50
|
+
return x.pre < y.pre ? -1 : 1;
|
|
51
|
+
}
|
|
52
|
+
export { FROM_SOURCE, PACKAGE_DIR, VERSION, builtinPublic, compareVersions, packagePath };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { inPublic } from "../public.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import "node:path";
|
|
4
|
+
import "node:url";
|
|
5
|
+
// src/pages/blocks.ts
|
|
6
|
+
const NAME = /^[\w-]+$/;
|
|
7
|
+
const GROUPS = [
|
|
8
|
+
"ask",
|
|
9
|
+
"show",
|
|
10
|
+
"arrange",
|
|
11
|
+
"mark"
|
|
12
|
+
];
|
|
13
|
+
/** A block's line on the docs menu, checked: a group of the four, and a summary. */
|
|
14
|
+
function menuOf(menu, where) {
|
|
15
|
+
if (menu == null) return null;
|
|
16
|
+
const m = menu;
|
|
17
|
+
if (!GROUPS.includes(m.group)) throw new Error(`${where}: menu.group is ${JSON.stringify(m.group)}, one of ${GROUPS.join(", ")}`);
|
|
18
|
+
if (typeof m.summary !== "string" || !m.summary.trim()) throw new Error(`${where}: menu.summary is empty`);
|
|
19
|
+
return {
|
|
20
|
+
group: m.group,
|
|
21
|
+
summary: m.summary.trim()
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Check and resolve one block into what the engine uses: its files in its plugin's public folder. */
|
|
25
|
+
function normalize({ name, block: b, plugin, public: dir }) {
|
|
26
|
+
if (typeof b !== "object" || !b) throw new Error(`plugin ${plugin}: block "${name}" is not an object`);
|
|
27
|
+
if (!NAME.test(name)) throw new Error(`plugin ${plugin}: block name ${JSON.stringify(name)}: use letters, digits, - and _`);
|
|
28
|
+
const file = (ref, field) => ref == null ? null : inPublic(dir, ref, `plugin ${plugin}, block "${name}": ${field}`);
|
|
29
|
+
const files = {
|
|
30
|
+
client: file(b.client, "client"),
|
|
31
|
+
style: file(b.style, "style")
|
|
32
|
+
};
|
|
33
|
+
for (const [field, file] of Object.entries(files)) if (file && !fs.existsSync(file)) throw new Error(`plugin ${plugin}, block "${name}": ${field} file not found: ${file}`);
|
|
34
|
+
return {
|
|
35
|
+
name,
|
|
36
|
+
code: b.fence === "any",
|
|
37
|
+
fences: b.fence === true || b.fence === "any",
|
|
38
|
+
alerts: b.alert === true,
|
|
39
|
+
attrs: Array.isArray(b.attrs) ? b.attrs.map(String) : null,
|
|
40
|
+
menu: menuOf(b.menu, `plugin ${plugin}, block "${name}"`),
|
|
41
|
+
props: typeof b.props === "function" ? b.props.bind(b) : null,
|
|
42
|
+
html: typeof b.html === "function" ? b.html.bind(b) : null,
|
|
43
|
+
open: typeof b.open === "function" ? b.open.bind(b) : null,
|
|
44
|
+
...files,
|
|
45
|
+
source: plugin
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Resolve the plugins' blocks. A block name is one plugin's: two plugins bringing the same block is
|
|
50
|
+
* an error. `code` is the block for code fences no block claims by name: the last one with
|
|
51
|
+
* `fence: 'any'`.
|
|
52
|
+
*/
|
|
53
|
+
function resolveBlocks(entries) {
|
|
54
|
+
const blocks = /* @__PURE__ */ new Map();
|
|
55
|
+
for (const entry of entries) {
|
|
56
|
+
const n = normalize(entry);
|
|
57
|
+
const other = blocks.get(n.name);
|
|
58
|
+
if (other) throw new Error(`block "${n.name}" comes from two plugins: ${other.source} and ${n.source}`);
|
|
59
|
+
blocks.set(n.name, n);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
blocks,
|
|
63
|
+
code: [...blocks.values()].findLast((t) => t.code) ?? null,
|
|
64
|
+
alert: [...blocks.values()].findLast((t) => t.alerts) ?? null
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export { resolveBlocks };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/pages/board.ts
|
|
2
|
+
/** A page changed this recently, with nothing waiting on it, is active; older, quiet. */
|
|
3
|
+
const ACTIVE_FOR = 108e5;
|
|
4
|
+
const waitingOn = (p) => ({
|
|
5
|
+
open: p.open.length,
|
|
6
|
+
unread: p.unread,
|
|
7
|
+
unreceived: p.unreceived
|
|
8
|
+
});
|
|
9
|
+
const total = (w) => w.open + w.unread + w.unreceived;
|
|
10
|
+
/** Every project's pages by state, each column newest first. */
|
|
11
|
+
function byState(projects, now, activeFor = ACTIVE_FOR) {
|
|
12
|
+
const columns = {
|
|
13
|
+
waiting: [],
|
|
14
|
+
active: [],
|
|
15
|
+
quiet: []
|
|
16
|
+
};
|
|
17
|
+
for (const project of projects) for (const page of project.pages) {
|
|
18
|
+
const card = {
|
|
19
|
+
page,
|
|
20
|
+
project,
|
|
21
|
+
waiting: waitingOn(page)
|
|
22
|
+
};
|
|
23
|
+
columns[total(card.waiting) > 0 ? "waiting" : now - page.mtime <= activeFor ? "active" : "quiet"].push(card);
|
|
24
|
+
}
|
|
25
|
+
for (const cards of [
|
|
26
|
+
columns.waiting,
|
|
27
|
+
columns.active,
|
|
28
|
+
columns.quiet
|
|
29
|
+
]) cards.sort((a, b) => b.page.mtime - a.page.mtime);
|
|
30
|
+
return columns;
|
|
31
|
+
}
|
|
32
|
+
/** The projects with pages, a column each, the one changed last first. */
|
|
33
|
+
function byProject(projects) {
|
|
34
|
+
return projects.filter((p) => p.pages.length).toSorted((a, b) => b.active - a.active).map((project) => {
|
|
35
|
+
const cards = project.pages.map((page) => ({
|
|
36
|
+
page,
|
|
37
|
+
project,
|
|
38
|
+
waiting: waitingOn(page)
|
|
39
|
+
})).sort((a, b) => b.page.mtime - a.page.mtime);
|
|
40
|
+
return {
|
|
41
|
+
project,
|
|
42
|
+
cards,
|
|
43
|
+
waiting: cards.reduce((sum, c) => ({
|
|
44
|
+
open: sum.open + c.waiting.open,
|
|
45
|
+
unread: sum.unread + c.waiting.unread,
|
|
46
|
+
unreceived: sum.unreceived + c.waiting.unreceived
|
|
47
|
+
}), {
|
|
48
|
+
open: 0,
|
|
49
|
+
unread: 0,
|
|
50
|
+
unreceived: 0
|
|
51
|
+
})
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/** The projects without pages, folded at the end of either layout: by name. */
|
|
56
|
+
function withoutPages(projects) {
|
|
57
|
+
return projects.filter((p) => !p.pages.length).toSorted((a, b) => a.label.localeCompare(b.label));
|
|
58
|
+
}
|
|
59
|
+
export { ACTIVE_FOR, byProject, byState, total, waitingOn, withoutPages };
|