@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,75 @@
|
|
|
1
|
+
// plugins/code/diff.ts
|
|
2
|
+
const unprefix = (p) => p.replace(/\t.*$/, "").replace(/^"|"$/g, "").replace(/^[ab]\//, "");
|
|
3
|
+
function diffLines(text) {
|
|
4
|
+
if (!/^(@@|diff --git )/m.test(text) && !/^--- .*\n\+\+\+ /m.test(text)) return text.split("\n").map((line) => ({ kind: line[0] === "+" ? "add" : line[0] === "-" ? "del" : "context" }));
|
|
5
|
+
let file = "", oldFile = "", oldN = 0, newN = 0, numbered = false, inHunk = false;
|
|
6
|
+
let status = "", renamedFrom = "";
|
|
7
|
+
return text.split("\n").map((line) => {
|
|
8
|
+
const at = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(line);
|
|
9
|
+
if (at) {
|
|
10
|
+
oldN = Number(at[1]);
|
|
11
|
+
newN = Number(at[2]);
|
|
12
|
+
inHunk = true;
|
|
13
|
+
numbered = true;
|
|
14
|
+
return {
|
|
15
|
+
kind: "hunk",
|
|
16
|
+
label: ""
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (line.startsWith("@@")) {
|
|
20
|
+
inHunk = true;
|
|
21
|
+
numbered = false;
|
|
22
|
+
return {
|
|
23
|
+
kind: "hunk",
|
|
24
|
+
label: ""
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (inHunk) {
|
|
28
|
+
const sign = line[0];
|
|
29
|
+
const where = (side, n) => {
|
|
30
|
+
if (!numbered) return {};
|
|
31
|
+
const name = side === "old" ? oldFile || file : file || oldFile;
|
|
32
|
+
return name ? {
|
|
33
|
+
n,
|
|
34
|
+
at: side === "old" ? `${name} (old):${n}` : `${name}:${n}`
|
|
35
|
+
} : { n };
|
|
36
|
+
};
|
|
37
|
+
if (sign === "+") return {
|
|
38
|
+
kind: "add",
|
|
39
|
+
...where("new", newN++)
|
|
40
|
+
};
|
|
41
|
+
if (sign === "-") return {
|
|
42
|
+
kind: "del",
|
|
43
|
+
...where("old", oldN++)
|
|
44
|
+
};
|
|
45
|
+
if (sign === " ") {
|
|
46
|
+
oldN++;
|
|
47
|
+
return {
|
|
48
|
+
kind: "context",
|
|
49
|
+
...where("new", newN++)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (sign === "\\") return { kind: "meta" };
|
|
53
|
+
inHunk = false;
|
|
54
|
+
}
|
|
55
|
+
if (line.startsWith("diff --git ")) {
|
|
56
|
+
file = "";
|
|
57
|
+
oldFile = "";
|
|
58
|
+
status = "";
|
|
59
|
+
renamedFrom = "";
|
|
60
|
+
} else if (line.startsWith("new file mode")) status = "new";
|
|
61
|
+
else if (line.startsWith("deleted file mode")) status = "deleted";
|
|
62
|
+
else if (line.startsWith("rename from ")) renamedFrom = line.slice(12);
|
|
63
|
+
else if (line.startsWith("--- ")) oldFile = line === "--- /dev/null" ? "" : unprefix(line.slice(4));
|
|
64
|
+
else if (line.startsWith("+++ ")) {
|
|
65
|
+
file = line === "+++ /dev/null" ? "" : unprefix(line.slice(4));
|
|
66
|
+
const name = renamedFrom ? `${renamedFrom} → ${file}` : file || oldFile;
|
|
67
|
+
return {
|
|
68
|
+
kind: "file",
|
|
69
|
+
label: status ? `${name} (${status})` : name
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return { kind: "meta" };
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export { diffLines };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { diffLines } from "./diff.js";
|
|
2
|
+
import { builtinPublic } from "../../src/package.js";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import { definePlugin } from "@bigmistqke/workpad";
|
|
5
|
+
// plugins/code/index.ts
|
|
6
|
+
const DEFAULT_THEMES = {
|
|
7
|
+
light: "github-light",
|
|
8
|
+
dark: "github-dark"
|
|
9
|
+
};
|
|
10
|
+
const DEFAULT_REPLACEMENTS = {
|
|
11
|
+
"github-light": {
|
|
12
|
+
"#e36209": "#0f766e",
|
|
13
|
+
"#b08800": "#0f766e"
|
|
14
|
+
},
|
|
15
|
+
"github-dark": {
|
|
16
|
+
"#ffab70": "#5eead4",
|
|
17
|
+
"#c24e00": "#2dd4bf"
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* One highlighter per set of themes for the whole process. The server imports this module afresh
|
|
22
|
+
* each time the config changes, so what is kept here must outlive the module: a highlighter holds
|
|
23
|
+
* WebAssembly memory that is never freed, and one per reload ran out of it after a few days.
|
|
24
|
+
*/
|
|
25
|
+
function shared(shiki, themes) {
|
|
26
|
+
const all = globalThis[Symbol.for("workpad.code.highlighters")] ??= /* @__PURE__ */ new Map();
|
|
27
|
+
const key = themes.join("\0");
|
|
28
|
+
let one = all.get(key);
|
|
29
|
+
if (!one) all.set(key, one = {
|
|
30
|
+
highlighter: shiki.createHighlighter({
|
|
31
|
+
themes,
|
|
32
|
+
langs: []
|
|
33
|
+
}),
|
|
34
|
+
loaded: /* @__PURE__ */ new Set()
|
|
35
|
+
});
|
|
36
|
+
return one;
|
|
37
|
+
}
|
|
38
|
+
function code(options = {}) {
|
|
39
|
+
const themes = options.themes ?? DEFAULT_THEMES;
|
|
40
|
+
const colorReplacements = options.colorReplacements ?? (options.themes ? {} : DEFAULT_REPLACEMENTS);
|
|
41
|
+
let shiki;
|
|
42
|
+
/**
|
|
43
|
+
* Highlight `code` as `lang`; an unknown or missing language renders as plain text. A long line
|
|
44
|
+
* scrolls the block sideways; with `wrap` it wraps at the block's edge.
|
|
45
|
+
*/
|
|
46
|
+
async function highlight(code, lang, wrap = false) {
|
|
47
|
+
shiki ??= await import("shiki");
|
|
48
|
+
const { highlighter, loaded } = shared(shiki, Object.values(themes));
|
|
49
|
+
const h = await highlighter;
|
|
50
|
+
let language = String(lang ?? "").toLowerCase();
|
|
51
|
+
if (language in shiki.bundledLanguages) {
|
|
52
|
+
if (!loaded.has(language)) {
|
|
53
|
+
await h.loadLanguage(language);
|
|
54
|
+
loaded.add(language);
|
|
55
|
+
}
|
|
56
|
+
} else language = "text";
|
|
57
|
+
const diff = language === "diff" ? diffLines(code) : null;
|
|
58
|
+
const transformers = [];
|
|
59
|
+
if (wrap) transformers.push({ pre(node) {
|
|
60
|
+
node.properties["data-wrap"] = "";
|
|
61
|
+
} });
|
|
62
|
+
if (diff) transformers.push({
|
|
63
|
+
line(node, n) {
|
|
64
|
+
const info = diff[n - 1];
|
|
65
|
+
if (!info) return;
|
|
66
|
+
node.properties["data-diff"] = info.kind;
|
|
67
|
+
if (info.n != null) node.properties["data-n"] = String(info.n);
|
|
68
|
+
if (info.at) node.properties["data-wp-at"] = info.at;
|
|
69
|
+
if (info.label != null) node.children = [{
|
|
70
|
+
type: "text",
|
|
71
|
+
value: info.label
|
|
72
|
+
}];
|
|
73
|
+
},
|
|
74
|
+
code(node) {
|
|
75
|
+
node.children = node.children.filter((child, i, all) => {
|
|
76
|
+
const isMeta = (c) => c?.type === "element" && c.properties["data-diff"] === "meta";
|
|
77
|
+
return !isMeta(child) && !(child.type === "text" && isMeta(all[i - 1]));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return h.codeToHtml(code, {
|
|
82
|
+
lang: language,
|
|
83
|
+
themes,
|
|
84
|
+
defaultColor: false,
|
|
85
|
+
colorReplacements,
|
|
86
|
+
transformers
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return definePlugin({
|
|
90
|
+
name: "code",
|
|
91
|
+
public: builtinPublic("code"),
|
|
92
|
+
setup: () => ({ client: "client.js" }),
|
|
93
|
+
blocks: { code: {
|
|
94
|
+
menu: {
|
|
95
|
+
group: "show",
|
|
96
|
+
summary: "code, highlighted: any fence no other block claims; diff for a change"
|
|
97
|
+
},
|
|
98
|
+
fence: "any",
|
|
99
|
+
html: (ctx) => highlight(ctx.text, ctx.lang, "wrap" in ctx.attrs),
|
|
100
|
+
style: "style.css"
|
|
101
|
+
} },
|
|
102
|
+
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
export { code as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=`pre.shiki > code`,t=t=>{let n=e=>{let t=String(e.scrollWidth>e.clientWidth);e.dataset.overflow!==t&&(e.dataset.overflow=t)},r=new ResizeObserver(e=>{for(let{target:t}of e)n(t)}),i=/* @__PURE__ */ new WeakSet,a=t=>{let a=t.matches(e)?[t]:t.querySelectorAll(e);for(let e of a)n(e),i.has(e)||(i.add(e),r.observe(e))};a(t),document.fonts?.addEventListener(`loadingdone`,()=>{for(let r of t.querySelectorAll(e))n(r)}),new MutationObserver(t=>{for(let r of t){if(r.type===`characterData`){let t=r.target.parentElement?.closest(e);t&&n(t);continue}for(let e of r.addedNodes)e instanceof Element&&a(e);let t=r.target instanceof Element?r.target.closest(e):null;t&&n(t)}}).observe(t,{childList:!0,characterData:!0,subtree:!0})};export{t as default};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/* Code blocks highlighted by Shiki: tokens carry both colours; pick the one for the current theme.
|
|
2
|
+
The block keeps the page's own code background. */
|
|
3
|
+
pre.shiki {
|
|
4
|
+
background: var(--code-bg);
|
|
5
|
+
}
|
|
6
|
+
.shiki span {
|
|
7
|
+
color: var(--shiki-light);
|
|
8
|
+
font-style: var(--shiki-light-font-style);
|
|
9
|
+
font-weight: var(--shiki-light-font-weight);
|
|
10
|
+
text-decoration: var(--shiki-light-text-decoration);
|
|
11
|
+
}
|
|
12
|
+
@media (prefers-color-scheme: dark) {
|
|
13
|
+
:root:not([data-theme='light']) .shiki span {
|
|
14
|
+
color: var(--shiki-dark);
|
|
15
|
+
font-style: var(--shiki-dark-font-style);
|
|
16
|
+
font-weight: var(--shiki-dark-font-weight);
|
|
17
|
+
text-decoration: var(--shiki-dark-text-decoration);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
:root[data-theme='dark'] .shiki span {
|
|
21
|
+
color: var(--shiki-dark);
|
|
22
|
+
font-style: var(--shiki-dark-font-style);
|
|
23
|
+
font-weight: var(--shiki-dark-font-weight);
|
|
24
|
+
text-decoration: var(--shiki-dark-text-decoration);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* a long line scrolls the block sideways, wherever it is; a fence that says {wrap} wraps it. The
|
|
28
|
+
code inside the block scrolls, not the block: WebKit sizes a block that scrolls sideways without
|
|
29
|
+
its scrollbar, so the bar ate into its height (a vertical scrollbar came with it) */
|
|
30
|
+
pre.shiki {
|
|
31
|
+
white-space: pre;
|
|
32
|
+
overflow-wrap: normal;
|
|
33
|
+
overflow: visible;
|
|
34
|
+
}
|
|
35
|
+
pre.shiki > code {
|
|
36
|
+
display: block;
|
|
37
|
+
overflow-x: auto;
|
|
38
|
+
overflow-y: hidden;
|
|
39
|
+
}
|
|
40
|
+
/* the scrollbar chosen in advance, from measured overflow (client.ts): WebKit lays out an `auto`
|
|
41
|
+
scrollbar under a flex or grid ancestor after the ancestors, which keep the height they had
|
|
42
|
+
without it (https://github.com/block/buzz-app/pull/1677,
|
|
43
|
+
https://bugs.webkit.org/show_bug.cgi?id=51148) */
|
|
44
|
+
pre.shiki > code[data-overflow='true'] {
|
|
45
|
+
overflow-x: scroll;
|
|
46
|
+
}
|
|
47
|
+
pre.shiki > code[data-overflow='false'] {
|
|
48
|
+
overflow-x: hidden;
|
|
49
|
+
}
|
|
50
|
+
pre.shiki[data-wrap] {
|
|
51
|
+
white-space: pre-wrap;
|
|
52
|
+
overflow-wrap: anywhere;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* a diff: one row per line, as wide as the longest (a grid leaves out the line breaks between them,
|
|
56
|
+
which stay in the text), tinted by what it is, with its number in a gutter */
|
|
57
|
+
.shiki code:has(> .line[data-diff]) {
|
|
58
|
+
display: grid;
|
|
59
|
+
grid-template-columns: minmax(max-content, 1fr);
|
|
60
|
+
}
|
|
61
|
+
.shiki .line[data-diff='add'] {
|
|
62
|
+
background: color-mix(in srgb, #16a34a var(--tint-soft), transparent);
|
|
63
|
+
}
|
|
64
|
+
.shiki .line[data-diff='del'] {
|
|
65
|
+
background: color-mix(in srgb, #dc2626 var(--tint-soft), transparent);
|
|
66
|
+
}
|
|
67
|
+
.shiki .line[data-diff]::before {
|
|
68
|
+
content: attr(data-n);
|
|
69
|
+
display: inline-block;
|
|
70
|
+
width: 4ch;
|
|
71
|
+
margin-right: 1.5ch;
|
|
72
|
+
text-align: right;
|
|
73
|
+
color: var(--muted, #696e76);
|
|
74
|
+
opacity: 0.7;
|
|
75
|
+
user-select: none;
|
|
76
|
+
}
|
|
77
|
+
:root .shiki .line[data-diff='hunk'] {
|
|
78
|
+
color: var(--muted, #696e76);
|
|
79
|
+
line-height: 1.2;
|
|
80
|
+
margin: var(--space-2xs) 0;
|
|
81
|
+
}
|
|
82
|
+
.shiki .line[data-diff='hunk']::before {
|
|
83
|
+
content: '⋯';
|
|
84
|
+
text-align: center;
|
|
85
|
+
}
|
|
86
|
+
.shiki .line[data-diff='file'] {
|
|
87
|
+
font-weight: var(--weight-strong);
|
|
88
|
+
margin-bottom: var(--space-md);
|
|
89
|
+
}
|
|
90
|
+
.shiki .line[data-diff='file']::before {
|
|
91
|
+
content: none;
|
|
92
|
+
}
|
|
93
|
+
.shiki .line[data-diff='file'] + .line[data-diff='hunk'] {
|
|
94
|
+
margin-top: 0;
|
|
95
|
+
}
|
|
96
|
+
/* a diff that wraps: its rows fill the block, and a long one wraps inside its row */
|
|
97
|
+
pre.shiki[data-wrap] code:has(> .line[data-diff]) {
|
|
98
|
+
grid-template-columns: minmax(0, 1fr);
|
|
99
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
## Comments
|
|
2
|
+
|
|
3
|
+
The reader can select text on any page and comment on it, or comment on
|
|
4
|
+
whole lines of a code block (a "+" beside each line; dragging it takes
|
|
5
|
+
several). Each comment comes to you as an event on the page, like a form
|
|
6
|
+
answer:
|
|
7
|
+
|
|
8
|
+
```json
|
|
9
|
+
{"id":"…","page":"plan","type":"comments:new","data":{"quote":"the selected text","before":"…","after":"…","block":3,"text":"their comment"}}
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
On lines that say where they are from, `data.at` says it too: in a
|
|
13
|
+
`diff` fence, `"src/a.ts:12"` (a line of the new file), `"src/a.ts (old):9"`
|
|
14
|
+
(a removed line), or `"src/a.ts:12 – src/a.ts:15"` for several. Any block
|
|
15
|
+
can say where its parts are from with a `data-wp-at` attribute.
|
|
16
|
+
|
|
17
|
+
Replies to a thread come as `comments:reply` (`data.replyTo` is the comment's
|
|
18
|
+
id), and `comments:resolve` when the reader closed it. A thread stays on the
|
|
19
|
+
page until the reader closes it. Answer a comment the way it asks:
|
|
20
|
+
|
|
21
|
+
- **It asks for a change:** edit the page. The thread stays, so say what you
|
|
22
|
+
changed in a reply if it is not obvious.
|
|
23
|
+
- **It asks a question:** reply in the thread:
|
|
24
|
+
`workpad append --page <file> --type comments:reply --data '{"replyTo":"<comment id>","text":"…"}'`
|
|
25
|
+
|
|
26
|
+
Your replies show as the agent's, and your own `listen` skips what you
|
|
27
|
+
append, so you don't hear your own replies. Comments and replies are
|
|
28
|
+
markdown: code in backticks or fences, lists, links, `#12`, a
|
|
29
|
+
```mermaid diagram; raw HTML and directives (`:::…`, `:button`) show as
|
|
30
|
+
written.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { builtinPublic } from "../../src/package.js";
|
|
2
|
+
import { item, when } from "../../src/archive.js";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
// plugins/comments/index.ts
|
|
5
|
+
function comments() {
|
|
6
|
+
return {
|
|
7
|
+
name: "comments",
|
|
8
|
+
docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8"),
|
|
9
|
+
archive: archiveComments,
|
|
10
|
+
events: {
|
|
11
|
+
"comments:new": {
|
|
12
|
+
handOut: true,
|
|
13
|
+
description: "a comment on a passage or lines of code: `{ quote, before, after, block, at?, text }`; its id is the thread's"
|
|
14
|
+
},
|
|
15
|
+
"comments:reply": {
|
|
16
|
+
handOut: true,
|
|
17
|
+
forReader: true,
|
|
18
|
+
description: "a reply in a thread: `{ replyTo, text }`"
|
|
19
|
+
},
|
|
20
|
+
"comments:resolve": { description: "the reader closed a thread: `{ replyTo }`" }
|
|
21
|
+
},
|
|
22
|
+
public: builtinPublic("comments"),
|
|
23
|
+
style: "style.css",
|
|
24
|
+
setup: () => ({ client: "client.js" })
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** An archived page's comments: each thread, the passage it is on, its replies, and whether it was closed. */
|
|
28
|
+
function archiveComments(events) {
|
|
29
|
+
const threads = events.filter((e) => e.type === "comments:new");
|
|
30
|
+
if (!threads.length) return;
|
|
31
|
+
const who = (e) => e.from === "cli" ? "agent" : "you";
|
|
32
|
+
return ["## Comments", ...threads.map((c) => {
|
|
33
|
+
const replies = events.filter((e) => e.type === "comments:reply" && e.data.replyTo === c.id);
|
|
34
|
+
const closed = events.some((e) => e.type === "comments:resolve" && e.data.replyTo === c.id);
|
|
35
|
+
const on = String(c.data.quote ?? c.data.at ?? "").trim();
|
|
36
|
+
return [`### On ${on ? `“${on.length > 80 ? on.slice(0, 80) + "…" : on}”` : "the page"}${closed ? " (closed)" : ""}`, [c, ...replies].map((e) => item(`${who(e)}, ${when(e)}`, String(e.data.text ?? ""))).join("\n")].join("\n\n");
|
|
37
|
+
})].join("\n\n");
|
|
38
|
+
}
|
|
39
|
+
export { comments as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var e=class{value;constructor(e){this.value=e}toString(){return this.value}};const t={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},n=e=>String(e).replace(/[&<>"']/g,e=>t[e]),r=t=>new e(String(t??``));function i(t){return t==null||t===!1?``:t instanceof e?t.value:Array.isArray(t)?t.map(i).join(``):n(t)}function a(t,...n){let r=t[0];for(let e=0;e<n.length;e++)r+=i(n[e])+t[e+1];return new e(r)}const o=`comments:new`,s=`comments:reply`,c=`comments:resolve`;let l,u,d,f=[],p=null;const m=document.createElement(`div`);m.className=`wp-comments`;const h=document.createElement(`button`);h.type=`button`,h.className=`wp-comment-start`,h.textContent=`Comment`,h.hidden=!0;const g=document.createElement(`div`);g.className=`wp-thread`,g.hidden=!0;const _=document.createElement(`section`);_.className=`wp-orphan-comments`,_.hidden=!0;let v=``;function y(){let e=[],t=``,n=document.createTreeWalker(d,NodeFilter.SHOW_TEXT,{acceptNode:e=>e.parentElement?.closest(`script, style, textarea`)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT});for(let r=n.nextNode();r;r=n.nextNode())e.push({node:r,start:t.length}),t+=r.data;return{text:t,nodes:e}}function b(e,t,n){for(let r=0;r<e.nodes.length;r++){let{node:i,start:a}=e.nodes[r],o=a+i.data.length;if(t<o||n&&t===o||r===e.nodes.length-1)return{node:i,offset:Math.min(Math.max(t-a,0),i.data.length)}}return null}function x(e,t){let n=(t,n)=>{if(t.nodeType===Node.TEXT_NODE){let r=e.nodes.find(e=>e.node===t);return r?r.start+n:null}let r=document.createRange();r.setStart(d,0),r.setEnd(t,n);let i=0;for(let{node:t,start:n}of e.nodes)r.intersectsNode(t)&&(i=n+t.data.length);return i},r=n(t.startContainer,t.startOffset),i=n(t.endContainer,t.endOffset);return r==null||i==null?null:{start:r,end:i}}function S(e,t){let n=String(t.quote??``);if(!n)return null;let r=String(t.before??``),i=String(t.after??``),a=-1,o=-1;for(let t=e.text.indexOf(n);t>=0;t=e.text.indexOf(n,t+1)){let s=e.text.slice(Math.max(0,t-r.length),t),c=e.text.slice(t+n.length,t+n.length+i.length),l=0;for(;l<s.length&&s[s.length-1-l]===r[r.length-1-l];)l++;let u=0;for(;u<c.length&&c[u]===i[u];)u++;l+u>o&&(a=t,o=l+u)}if(a<0)return null;let s=b(e,a,!1),c=b(e,a+n.length,!0);if(!s||!c)return null;let l=document.createRange();return l.setStart(s.node,s.offset),l.setEnd(c.node,c.offset),l}function C(e,t){let n=(t,n,r)=>{let i=b(e,t,!1),a=b(e,n,!0);if(!i||!a)return null;let o=document.createRange();o.setStart(i.node,i.offset),o.setEnd(a.node,a.offset);let s=o.getClientRects(),c=r?s[s.length-1]:s[0];return c?c.top:null},r=String(t.before??``).trim(),i=String(t.after??``).trim();if(r.length>=8){let t=e.text.indexOf(r);if(t>=0&&e.text.indexOf(r,t+1)<0){let e=n(t,t+r.length,!0);if(e!=null)return e}}if(i.length>=8){let t=e.text.indexOf(i);if(t>=0&&e.text.indexOf(i,t+1)<0){let e=n(t,t+i.length,!1);if(e!=null)return e}}let a=typeof t.block==`number`&&t.block>=0?d.children[t.block]:null;return a?a.getBoundingClientRect().top:null}function w(){let e=u.events(),t=new Set(e.filter(e=>e.type===c).map(e=>String(e.data.replyTo))),n=y();return e.filter(e=>e.type===o&&!t.has(e.id)).map(t=>({id:t.id,comment:t,replies:e.filter(e=>e.type===s&&e.data.replyTo===t.id),range:S(n,t.data),index:n}))}const T=e=>e.replies.at(-1)?.from===`cli`;function E(){let e=CSS.highlights,t=window.Highlight;if(e&&t){e.set(`wp-comment`,new t(...f.filter(e=>e.range&&e.id!==p).map(e=>e.range)));let n=f.find(e=>e.id===p)?.range;n?e.set(`wp-comment-active`,new t(n)):e.delete(`wp-comment-active`)}let n=/* @__PURE__ */ new Map;for(let e of f)e.range?.getClientRects().length||n.set(e.id,e.index?C(e.index,e.comment.data):null);D(f.filter(e=>n.has(e.id)&&n.get(e.id)==null));let r=d.getBoundingClientRect(),i=new Set(u.unread().map(e=>e.id)),a=/* @__PURE__ */ new Map;m.replaceChildren(...f.map(e=>{let t=document.createElement(`button`);t.type=`button`,t.className=`wp-comment-badge`,t.dataset.thread=e.id,t.toggleAttribute(`data-agent`,T(e)),t.dataset.wpHolds=e.replies.map(e=>e.id).join(` `);let o=e.replies.some(e=>i.has(e.id));t.toggleAttribute(`data-unread`,o),t.title=o?`the agent replied: unread`:T(e)?`the agent replied`:`comment`,t.textContent=String(1+e.replies.length);let s=e.range?.getClientRects()[0],c,l=_.querySelector(`[data-row="${CSS.escape(e.id)}"]`);if(s)c=s.top+scrollY;else if(l)c=l.getBoundingClientRect().top+scrollY;else{let t=Math.round(n.get(e.id)??r.top),i=a.get(t)??0;a.set(t,i+1),c=t+i*30+scrollY}let u=Math.min(r.right+8+scrollX,document.documentElement.clientWidth-36+scrollX);return t.style.top=`${c}px`,t.style.left=`${u}px`,s||(t.dataset.detached=``),t})),p&&M()}function D(e){_.isConnected&&_.previousElementSibling===d||d.after(_);let t=e.map(e=>e.id).join(` `);if(t===v)return;v=t,_.hidden=!e.length;let n=document.createElement(`p`);n.className=`wp-orphan-comments-title`,n.textContent=`${e.length} comment${e.length===1?``:`s`} on text no longer on this page`;let r=e.map(e=>{let t=document.createElement(`blockquote`);return t.className=`wp-thread-quote`,t.dataset.row=t.dataset.thread=e.id,t.textContent=String(e.comment.data.quote??``),t});_.replaceChildren(...e.length?[n,...r]:[])}function O(e){let t=g.querySelector(`textarea`),n=!!t&&document.activeElement===t,r=n?t.getBoundingClientRect().top:0;e();let i=g.querySelector(`textarea`);if(!n||!i||document.activeElement!==i)return;let a=i.getBoundingClientRect().top-r;Math.abs(a)>=1&&scrollBy(0,a)}function k(){l&&(d=l.querySelector(`main`)??l,O(()=>{f=w(),p&&!f.some(e=>e.id===p)?P():p&&j(),E()}))}const A=/* @__PURE__ */ new Map;function j(){let e=f.find(e=>e.id===p);if(!e)return;let t=e=>e.from===`cli`?`agent`:`you`,n=e=>{let n=String(e.data.text??``),i=A.get(n);return a`<div
|
|
2
|
+
class="wp-thread-message"
|
|
3
|
+
data-from="${t(e)}"
|
|
4
|
+
data-wp-message="${e.id}"
|
|
5
|
+
${e.sending?r(` data-sending`):``}
|
|
6
|
+
>
|
|
7
|
+
<span class="wp-thread-who">${t(e)}</span>
|
|
8
|
+
<div class="wp-thread-text" ${i==null?``:r(` data-md`)}>${i==null?n:r(i)}</div>
|
|
9
|
+
</div>`},i=g.querySelector(`textarea`),o=i?.value??``,s=!!i&&document.activeElement===i,c=i?[i.selectionStart,i.selectionEnd]:null;g.innerHTML=String(a` <blockquote class="wp-thread-quote">${e.comment.data.quote??``}</blockquote>
|
|
10
|
+
${e.comment.data.at&&a`<p class="wp-thread-at">${e.comment.data.at}</p>`}
|
|
11
|
+
${!e.range&&a`<p class="wp-thread-detached">This passage is no longer on the page.</p>`}
|
|
12
|
+
${[e.comment,...e.replies].map(n)}
|
|
13
|
+
<form class="wp-thread-reply">
|
|
14
|
+
<textarea rows="2" placeholder="Reply (Shift+Enter for a new line)"></textarea>
|
|
15
|
+
<div class="wp-thread-actions">
|
|
16
|
+
<button type="submit" class="wp-comment-button wp-comment-primary">Reply</button
|
|
17
|
+
><button type="button" class="wp-comment-button" data-close>Close thread</button>
|
|
18
|
+
</div>
|
|
19
|
+
</form>`);let l=g.querySelector(`textarea`);l.value=o,s&&(l.focus({preventScroll:!0}),c&&l.setSelectionRange(c[0],c[1]));for(let t of[e.comment,...e.replies]){let e=String(t.data.text??``);A.has(e)||u.markdown(e).then(n=>{A.set(e,n);let r=g.querySelector(`[data-wp-message="${CSS.escape(t.id)}"] .wp-thread-text`);r&&!r.hasAttribute(`data-md`)&&O(()=>{r.innerHTML=n,r.setAttribute(`data-md`,``)})},e=>console.error(`comments:`,e))}}function M(){let e=m.querySelector(`[data-thread="${p}"]`);if(!e)return;let t=parseFloat(e.style.top)+28,n=Math.min(360,document.documentElement.clientWidth-32),r=Math.max(16+scrollX,Math.min(parseFloat(e.style.left)+28-n,document.documentElement.clientWidth-n-16+scrollX));g.style.top=`${t}px`,g.style.left=`${r}px`,g.style.width=`${n}px`}function N(e){p=e,g.hidden=!1,g.querySelector(`textarea`)?.replaceWith(document.createElement(`textarea`)),j(),E(),g.querySelector(`textarea`)?.focus({preventScroll:!0})}function P(){p=null,g.hidden=!0,E()}let F=null;function I(){d=l.querySelector(`main`)??l;let e=getSelection();if(!e||e.isCollapsed||!e.rangeCount){h.matches(`:focus`)||(h.hidden=!0);return}let t=e.getRangeAt(0),n=e=>d.contains(e)&&!(e instanceof Element?e:e.parentElement)?.closest(`form, input, textarea, select, button`);!n(t.startContainer)||!n(t.endContainer)?h.hidden=!0:h.hidden=!L(t)}function L(e){let t=e.toString().trim();if(!t)return!1;let n=y(),r=x(n,e);if(!r)return!1;let i=n.text.indexOf(t,r.start),a=i>=0&&i<=r.end?i:r.start,o=e.startContainer instanceof Element?e.startContainer:e.startContainer.parentElement;for(;o&&o.parentElement!==d;)o=o.parentElement;F={quote:t,before:n.text.slice(Math.max(0,a-32),a),after:n.text.slice(a+t.length,a+t.length+32),block:o?[...d.children].indexOf(o):-1};let s=[...d.querySelectorAll(`[data-wp-at]`)].filter(t=>e.intersectsNode(t)&&t.textContent).map(e=>e.dataset.wpAt);s.length&&(F.at=s.length>1&&s.at(-1)!==s[0]?`${s[0]} – ${s.at(-1)}`:s[0]);let c=e.getClientRects(),l=c[c.length-1]??e.getBoundingClientRect();return h.style.top=`${l.bottom+scrollY+6}px`,h.style.left=`${Math.min(l.right+scrollX-40,document.documentElement.clientWidth-110+scrollX)}px`,!0}const R=document.createElement(`button`);R.type=`button`,R.className=`wp-line-comment`,R.textContent=`+`,R.title=`Comment on this line (drag for several)`,R.hidden=!0;let z=null,B=null;const V=e=>{let t=e instanceof Element?e.closest(`pre .line`):null;return t&&d.contains(t)&&!t.closest(`form`)?t:null};function H(e,t){let[n,r]=e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_PRECEDING?[t,e]:[e,t],i=document.createRange();return i.setStart(n,0),i.setEnd(r,r.childNodes.length),i}function U(e){z=e;let t=e.getBoundingClientRect(),n=e.closest(`pre`).getBoundingClientRect();R.style.top=`${t.top+scrollY+t.height/2-10}px`,R.style.left=`${Math.max(scrollX+2,n.left+scrollX-24)}px`,R.hidden=!1}function W(e){if(B){let t=B.pre.getBoundingClientRect(),n=B.from.getBoundingClientRect().left+4,r=V(document.elementFromPoint(n,Math.min(Math.max(e.clientY,t.top+1),t.bottom-1)));if(r&&B.pre.contains(r)&&r!==B.to){B.to=r;let e=CSS.highlights,t=window.Highlight;e&&t&&e.set(`wp-comment-active`,new t(H(B.from,B.to)))}return}if(e.target===R)return;let t=V(e.target);if(t)return U(t);if(R.hidden||!z)return;let n=z.closest(`pre`),r=n.getBoundingClientRect(),i=R.getBoundingClientRect(),a=e.clientX>=i.left-4&&e.clientX<=r.right&&e.clientY>=r.top&&e.clientY<=r.bottom,o=a?V(document.elementFromPoint(z.getBoundingClientRect().left+4,e.clientY)):null;o&&n.contains(o)?U(o):a&&e.clientY>=i.top-4&&e.clientY<=i.bottom+4||(R.hidden=!0,z=null)}const G=document.createElement(`form`);G.className=`wp-thread wp-comment-new`,G.hidden=!0,G.innerHTML=String(a`<blockquote class="wp-thread-quote"></blockquote>
|
|
20
|
+
<textarea rows="3" placeholder="Your comment (Shift+Enter for a new line)"></textarea>
|
|
21
|
+
<div class="wp-thread-actions">
|
|
22
|
+
<button type="submit" class="wp-comment-button wp-comment-primary">Comment</button
|
|
23
|
+
><button type="button" class="wp-comment-button" data-cancel>Cancel</button>
|
|
24
|
+
</div>`);function K(){if(!F)return;G.querySelector(`blockquote`).textContent=F.at?`${F.at}\n${F.quote}`:F.quote,G.style.top=h.style.top;let e=Math.min(360,document.documentElement.clientWidth-32);G.style.width=`${e}px`,G.style.left=`${Math.max(16+scrollX,Math.min(parseFloat(h.style.left),document.documentElement.clientWidth-e-16+scrollX))}px`,G.hidden=!1,h.hidden=!0,G.querySelector(`textarea`).focus({preventScroll:!0})}const q=(e,t,n)=>{if(t.kind!==`page`&&t.kind!==`file`)return;l=e,d=l.querySelector(`main`)??l,u=n,n.slot(`overlay`,e=>(e.append(m,h,R,g,G),()=>{for(let e of[m,h,R,g,G])e.remove()})),document.addEventListener(`mousemove`,W),document.documentElement.addEventListener(`mouseleave`,()=>{B||(R.hidden=!0,z=null)}),R.addEventListener(`mousedown`,e=>{if(!z||e.button!==0)return;e.preventDefault();let t=CSS.highlights,n=window.Highlight;t&&n&&t.set(`wp-comment-active`,new n(H(z,z))),B={pre:z.closest(`pre`),from:z,to:z}}),document.addEventListener(`mouseup`,()=>{if(!B)return;let{from:e,to:t}=B;B=null,R.hidden=!0,L(H(e,t))?K():E()});let r=0;document.addEventListener(`selectionchange`,()=>{clearTimeout(r),r=window.setTimeout(I,150)}),h.addEventListener(`mousedown`,e=>e.preventDefault()),h.addEventListener(`click`,K);for(let e of[G,g])e.addEventListener(`keydown`,e=>{let t=e.target;t.tagName!==`TEXTAREA`||e.key!==`Enter`||e.shiftKey||e.isComposing||(e.preventDefault(),t.closest(`form`)?.requestSubmit())});G.addEventListener(`submit`,async e=>{e.preventDefault();let t=G.querySelector(`textarea`).value.trim();if(!t||!F)return;let n=F,r=u.append(o,{...n,text:t}),i=u.events().findLast(e=>e.type===o&&e.sending&&e.data.text===t);G.querySelector(`textarea`).value=``,G.hidden=!0,F=null,getSelection()?.removeAllRanges(),k(),i&&N(i.id);try{await r}catch(e){if(console.error(`comments:`,e),!G.hidden)return;F=n,G.querySelector(`textarea`).value=t,G.hidden=!1,u.toast(`Couldn't send the comment`,{kind:`alert`,name:`comment-failed`,details:`It's back in the box: send it again.`})}}),G.querySelector(`[data-cancel]`).addEventListener(`click`,()=>{G.hidden=!0,F=null}),_.addEventListener(`click`,e=>{let t=e.target.closest(`[data-thread]`)?.dataset.thread;t&&(p===t?P():N(t))}),m.addEventListener(`click`,e=>{let t=e.target.closest(`[data-thread]`)?.dataset.thread;t&&(p===t?P():N(t))}),g.addEventListener(`submit`,async e=>{e.preventDefault();let t=g.querySelector(`textarea`),n=t.value.trim();if(!n||!p)return;let r=p;t.value=``;let i=u.append(s,{replyTo:r,text:n});k();try{await i}catch(e){console.error(`comments:`,e);let t=g.querySelector(`textarea`);p===r&&t&&!t.value.trim()&&(t.value=n),u.toast(`Couldn't send the reply`,{kind:`alert`,name:`comment-failed`,details:`It's back in the box: send it again.`})}}),g.addEventListener(`click`,async e=>{if(!e.target.closest(`[data-close]`)||!p)return;let t=p;P(),u.markRead(f.find(e=>e.id===t)?.replies.map(e=>e.id)??[]);let n=u.append(c,{replyTo:t});k(),n.catch(e=>{console.error(`comments:`,e),u.toast(`Couldn't close the thread`,{kind:`alert`,name:`comment-failed`,details:`It's open again.`})})}),m.addEventListener(`wp-reveal`,e=>{let t=e.target.closest(`[data-thread]`)?.dataset.thread;t&&p!==t&&N(t)}),document.addEventListener(`dblclick`,e=>{let t=e.target;!p||g.contains(t)||m.contains(t)||P()}),document.addEventListener(`keydown`,e=>{e.key===`Escape`&&(G.hidden?p&&P():(G.hidden=!0,F=null))}),u.events.on(k),u.onRendered(k),new ResizeObserver(()=>E()).observe(l),addEventListener(`resize`,()=>E()),k()};export{q as default};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Comments: highlights through the CSS Highlight API, badges and threads above the page. Colors
|
|
3
|
+
* and fonts come from the page's theme variables, else from
|
|
4
|
+
* the fallbacks here.
|
|
5
|
+
*/
|
|
6
|
+
::highlight(wp-comment) {
|
|
7
|
+
background-color: color-mix(in srgb, var(--accent, #1d5bbf) var(--tint-soft), transparent);
|
|
8
|
+
}
|
|
9
|
+
::highlight(wp-comment-active) {
|
|
10
|
+
background-color: color-mix(in srgb, var(--accent, #1d5bbf) var(--tint-strong), transparent);
|
|
11
|
+
}
|
|
12
|
+
.wp-comment-start,
|
|
13
|
+
.wp-comment-badge,
|
|
14
|
+
.wp-thread {
|
|
15
|
+
position: absolute;
|
|
16
|
+
z-index: var(--layer-popover);
|
|
17
|
+
font-family: var(--sans, sans-serif);
|
|
18
|
+
}
|
|
19
|
+
.wp-comment-start[hidden],
|
|
20
|
+
.wp-thread[hidden],
|
|
21
|
+
.wp-line-comment[hidden] {
|
|
22
|
+
display: none;
|
|
23
|
+
}
|
|
24
|
+
.wp-comment-start {
|
|
25
|
+
background: var(--accent, #1d5bbf);
|
|
26
|
+
color: var(--accent-text, #fff);
|
|
27
|
+
border-color: var(--accent, #1d5bbf);
|
|
28
|
+
border-radius: var(--radius-pill);
|
|
29
|
+
font-size: var(--ui-small);
|
|
30
|
+
padding: var(--space-2xs) var(--space-lg);
|
|
31
|
+
box-shadow: 0 2px 8px rgb(0 0 0 / 0.15);
|
|
32
|
+
}
|
|
33
|
+
.wp-comment-badge {
|
|
34
|
+
min-width: 24px;
|
|
35
|
+
height: 24px;
|
|
36
|
+
padding: 0 var(--space-sm);
|
|
37
|
+
border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
|
|
38
|
+
font-size: var(--ui-tiny);
|
|
39
|
+
font-weight: var(--weight-strong);
|
|
40
|
+
background: var(--bg, Canvas);
|
|
41
|
+
color: var(--accent, #1d5bbf);
|
|
42
|
+
border: var(--hairline) solid color-mix(in srgb, var(--accent, #1d5bbf) var(--tint-strong), transparent);
|
|
43
|
+
}
|
|
44
|
+
.wp-comment-badge[data-agent] {
|
|
45
|
+
background: var(--accent, #1d5bbf);
|
|
46
|
+
color: var(--accent-text, #fff);
|
|
47
|
+
}
|
|
48
|
+
.wp-comment-badge[data-detached] {
|
|
49
|
+
border-style: dashed;
|
|
50
|
+
}
|
|
51
|
+
/* a reply the reader hasn't read: a dot on the badge until its thread is open and it is in view */
|
|
52
|
+
.wp-comment-badge[data-unread]::after {
|
|
53
|
+
content: '';
|
|
54
|
+
position: absolute;
|
|
55
|
+
top: -3px;
|
|
56
|
+
right: -3px;
|
|
57
|
+
width: 9px;
|
|
58
|
+
height: 9px;
|
|
59
|
+
border-radius: 50%;
|
|
60
|
+
background: var(--bad, #c4352b);
|
|
61
|
+
border: 2px solid var(--bg, Canvas);
|
|
62
|
+
}
|
|
63
|
+
.wp-thread {
|
|
64
|
+
background: var(--bg, Canvas);
|
|
65
|
+
border: var(--hairline) solid var(--border, #e3e5e9);
|
|
66
|
+
border-radius: var(--radius);
|
|
67
|
+
padding: var(--space-xl) var(--space-xl);
|
|
68
|
+
box-shadow: var(--shadow-pop);
|
|
69
|
+
display: grid;
|
|
70
|
+
/* one column as wide as the thread: a line that can't wrap scrolls in its own block, not the thread */
|
|
71
|
+
grid-template-columns: minmax(0, 1fr);
|
|
72
|
+
gap: var(--space-lg);
|
|
73
|
+
font-size: var(--ui-text);
|
|
74
|
+
}
|
|
75
|
+
.wp-thread-quote {
|
|
76
|
+
margin: 0;
|
|
77
|
+
padding-left: var(--space-lg);
|
|
78
|
+
border-left: 3px solid color-mix(in srgb, var(--accent, #1d5bbf) var(--tint-strong), transparent);
|
|
79
|
+
color: var(--muted, #696e76);
|
|
80
|
+
font-size: var(--ui-small);
|
|
81
|
+
max-height: 6.5em;
|
|
82
|
+
overflow: auto;
|
|
83
|
+
white-space: pre-wrap;
|
|
84
|
+
overflow-wrap: anywhere;
|
|
85
|
+
}
|
|
86
|
+
.wp-thread-detached {
|
|
87
|
+
margin: 0;
|
|
88
|
+
color: var(--muted, #696e76);
|
|
89
|
+
font-size: var(--ui-small);
|
|
90
|
+
}
|
|
91
|
+
.wp-thread-message {
|
|
92
|
+
display: grid;
|
|
93
|
+
grid-template-columns: minmax(0, 1fr);
|
|
94
|
+
gap: var(--space-2xs);
|
|
95
|
+
}
|
|
96
|
+
.wp-thread-who {
|
|
97
|
+
font-size: var(--ui-tiny);
|
|
98
|
+
font-weight: var(--weight-strong);
|
|
99
|
+
letter-spacing: var(--caps-spacing);
|
|
100
|
+
text-transform: uppercase;
|
|
101
|
+
color: var(--muted, #696e76);
|
|
102
|
+
}
|
|
103
|
+
.wp-thread-message[data-from='agent'] .wp-thread-who {
|
|
104
|
+
color: var(--accent, #1d5bbf);
|
|
105
|
+
}
|
|
106
|
+
.wp-thread-text {
|
|
107
|
+
white-space: pre-wrap;
|
|
108
|
+
overflow-wrap: anywhere;
|
|
109
|
+
line-height: var(--ui-line-height);
|
|
110
|
+
}
|
|
111
|
+
/* rendered from markdown: its paragraphs and code carry the spacing */
|
|
112
|
+
.wp-thread-text[data-md] {
|
|
113
|
+
white-space: normal;
|
|
114
|
+
overflow-wrap: anywhere;
|
|
115
|
+
}
|
|
116
|
+
.wp-thread-text[data-md] > :first-child {
|
|
117
|
+
margin-top: 0;
|
|
118
|
+
}
|
|
119
|
+
.wp-thread-text[data-md] > :last-child {
|
|
120
|
+
margin-bottom: 0;
|
|
121
|
+
}
|
|
122
|
+
.wp-thread-text[data-md] :is(p, ul, ol, pre, blockquote) {
|
|
123
|
+
margin: 0 0 0.5em;
|
|
124
|
+
}
|
|
125
|
+
.wp-thread-text[data-md] pre {
|
|
126
|
+
font-size: var(--ui-small);
|
|
127
|
+
padding: var(--space-md) var(--space-lg);
|
|
128
|
+
border-radius: var(--radius-sm);
|
|
129
|
+
overflow-x: auto;
|
|
130
|
+
max-width: 100%;
|
|
131
|
+
}
|
|
132
|
+
.wp-thread textarea {
|
|
133
|
+
width: 100%;
|
|
134
|
+
resize: vertical;
|
|
135
|
+
font: inherit;
|
|
136
|
+
}
|
|
137
|
+
.wp-thread-reply {
|
|
138
|
+
display: grid;
|
|
139
|
+
gap: var(--space-md);
|
|
140
|
+
margin: 0;
|
|
141
|
+
}
|
|
142
|
+
.wp-thread-actions {
|
|
143
|
+
display: flex;
|
|
144
|
+
gap: var(--space-md);
|
|
145
|
+
}
|
|
146
|
+
/* its own buttons, styled here rather than borrowed from the page */
|
|
147
|
+
.wp-comment-button {
|
|
148
|
+
font: 500 var(--ui-small)/1.3 var(--sans, sans-serif);
|
|
149
|
+
padding: var(--space-sm) var(--space-xl);
|
|
150
|
+
border-radius: var(--radius-sm);
|
|
151
|
+
cursor: pointer;
|
|
152
|
+
border: var(--hairline) solid var(--border, #e3e5e9);
|
|
153
|
+
background: var(--surface, Canvas);
|
|
154
|
+
color: var(--text, CanvasText);
|
|
155
|
+
}
|
|
156
|
+
.wp-comment-button:hover {
|
|
157
|
+
border-color: var(--muted, #696e76);
|
|
158
|
+
}
|
|
159
|
+
.wp-comment-primary {
|
|
160
|
+
background: var(--accent, #1d5bbf);
|
|
161
|
+
color: var(--accent-text, #fff);
|
|
162
|
+
border-color: var(--accent, #1d5bbf);
|
|
163
|
+
}
|
|
164
|
+
.wp-comment-start,
|
|
165
|
+
.wp-comment-badge {
|
|
166
|
+
cursor: pointer;
|
|
167
|
+
border-style: solid;
|
|
168
|
+
border-width: var(--hairline);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/* "+" beside a line of code: comment on it, or drag over several */
|
|
172
|
+
.wp-line-comment {
|
|
173
|
+
position: absolute;
|
|
174
|
+
z-index: var(--layer-popover);
|
|
175
|
+
width: 20px;
|
|
176
|
+
height: 20px;
|
|
177
|
+
padding: 0;
|
|
178
|
+
border-radius: var(--radius-sm);
|
|
179
|
+
cursor: pointer;
|
|
180
|
+
font: var(--weight-strong) 14px/1 var(--sans, sans-serif);
|
|
181
|
+
background: var(--accent, #1d5bbf);
|
|
182
|
+
color: var(--accent-text, #fff);
|
|
183
|
+
border: none;
|
|
184
|
+
box-shadow: 0 1px 4px rgb(0 0 0 / 0.2);
|
|
185
|
+
}
|
|
186
|
+
.wp-thread-at {
|
|
187
|
+
margin: -4px 0 0;
|
|
188
|
+
font: var(--ui-small) var(--mono, monospace);
|
|
189
|
+
color: var(--muted, #696e76);
|
|
190
|
+
}
|
|
191
|
+
/* shown at once, grey until the server has it */
|
|
192
|
+
.wp-thread-message[data-sending] .wp-thread-text {
|
|
193
|
+
color: var(--wp-sending, #9a9fa7);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/* comments on text no longer on the page, with nothing of where it was left: listed after the
|
|
197
|
+
page's content, each quote with its badge beside it; a click opens the thread */
|
|
198
|
+
.wp-orphan-comments-title {
|
|
199
|
+
margin: var(--gap-section) 0 var(--space-md);
|
|
200
|
+
color: var(--muted, #696e76);
|
|
201
|
+
font-size: var(--ui-small);
|
|
202
|
+
}
|
|
203
|
+
/* laid out as the list of chats no longer on the page (the page's .wp-orphans), which may follow */
|
|
204
|
+
.wp-orphan-comments {
|
|
205
|
+
max-width: calc(var(--measure) + 66px);
|
|
206
|
+
margin: 0 auto;
|
|
207
|
+
position: relative;
|
|
208
|
+
left: calc(var(--wp-aside, 0px) / 2);
|
|
209
|
+
padding: 0 var(--space-2xl) 220px;
|
|
210
|
+
box-sizing: border-box;
|
|
211
|
+
font: var(--ui-text)/var(--ui-line-height) var(--sans);
|
|
212
|
+
}
|
|
213
|
+
.wp-orphan-comments[hidden] {
|
|
214
|
+
display: none;
|
|
215
|
+
}
|
|
216
|
+
/* the page's bottom space goes below the last list after the page */
|
|
217
|
+
main:has(+ .wp-orphan-comments:not([hidden])),
|
|
218
|
+
.wp-orphan-comments:has(+ .wp-orphans:not([hidden])) {
|
|
219
|
+
padding-bottom: 0;
|
|
220
|
+
}
|
|
221
|
+
.wp-orphan-comments .wp-thread-quote {
|
|
222
|
+
cursor: pointer;
|
|
223
|
+
margin: 0 0 var(--space-md);
|
|
224
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
A collapsible section. The label is the summary line; the body is any
|
|
2
|
+
markdown. Use it to keep in-depth explanation out of the way of the main read.
|
|
3
|
+
Unlike a raw `<details>` tag, the body needs no blank-line care. While it
|
|
4
|
+
is open, its title stays at the top as you scroll through it, and the title
|
|
5
|
+
of a details inside it stacks below.
|
|
6
|
+
|
|
7
|
+
A link to it, `#details:<its label as a slug>`, opens it.
|
|
8
|
+
|
|
9
|
+
Directly in a grid, tabs or a timeline, a details is an item as it is, its
|
|
10
|
+
label the title: in a grid it is the card, collapsed until opened.
|
|
11
|
+
|
|
12
|
+
Attributes: `open` (start expanded).
|
|
13
|
+
|
|
14
|
+
```markdown
|
|
15
|
+
:::details[Why remark-directive instead of MDX?]
|
|
16
|
+
MDX fails the **whole page** on one stray `<` or `{`. Directives that no
|
|
17
|
+
block handles still render as plain markdown.
|
|
18
|
+
:::
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
:::details[Why remark-directive instead of MDX?]
|
|
22
|
+
MDX fails the **whole page** on one stray `<` or `{`. Directives that no
|
|
23
|
+
block handles still render as plain markdown.
|
|
24
|
+
:::
|