Refactor architecture into eight components and consolidate reliability work
Build and publish container images / images (push) Successful in 9m34s
Release container images / release (push) Successful in 36s

Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts.

Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation.

Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
This commit is contained in:
Anya Tokugawa committed 2026-11-01 15:23:31 +09:00
1 parent 9dd425f765
commit d5d21b7841
302 files changed
+20037 -3492

No files matched your search

+86 -162
View File
@@ -1,9 +1,9 @@
import { EditorView, keymap, lineNumbers } from "@codemirror/view";
import { EditorView, keymap, lineNumbers, highlightActiveLine, highlightActiveLineGutter } from "@codemirror/view";
import { EditorState } from "@codemirror/state";
import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
import {
bracketMatching,
defaultHighlightStyle,
HighlightStyle,
StreamLanguage,
syntaxHighlighting,
} from "@codemirror/language";
@@ -28,32 +28,59 @@ import { java } from "@codemirror/lang-java";
import { cpp } from "@codemirror/lang-cpp";
import { shell } from "@codemirror/legacy-modes/mode/shell";
import { toml } from "@codemirror/legacy-modes/mode/toml";
import { vim, Vim } from "@replit/codemirror-vim";
import { vim, Vim, getCM } from "@replit/codemirror-vim";
import { tags, highlightTree } from "@lezer/highlight";
// Stable semantic styles instead of selectors for generated Lezer class names.
// CSS variables follow the selected Wiki theme without rebuilding the document.
const pagesWikiHighlightStyle = HighlightStyle.define([
{tag: tags.heading, class: "pw-syntax-heading"},
{tag: [tags.link, tags.url], class: "pw-syntax-link"},
{tag: tags.emphasis, class: "pw-syntax-emphasis"},
{tag: tags.strong, class: "pw-syntax-strong"},
{tag: [tags.keyword, tags.operatorKeyword], class: "pw-syntax-keyword"},
{tag: [tags.tagName, tags.typeName, tags.monospace], class: "pw-syntax-type"},
{tag: [tags.string, tags.special(tags.string)], class: "pw-syntax-string"},
{tag: [tags.number, tags.bool, tags.null, tags.attributeName], class: "pw-syntax-number"},
{tag: tags.comment, class: "pw-syntax-comment"},
{tag: [tags.variableName, tags.propertyName], class: "pw-syntax-variable"},
{tag: tags.function(tags.variableName), class: "pw-syntax-function"},
{tag: tags.operator, class: "pw-syntax-operator"},
{tag: tags.invalid, class: "pw-syntax-invalid"},
]);
const pagesWikiTheme = EditorView.theme({
".cm-selectionBackground": {
backgroundColor: "rgba(255, 216, 102, 0.48) !important",
backgroundColor: "var(--editor-selection) !important",
},
"&.cm-focused .cm-selectionBackground": {
backgroundColor: "rgba(255, 216, 102, 0.58) !important",
backgroundColor: "var(--editor-selection) !important",
},
".cm-selectionLayer .cm-selectionBackground": {
backgroundColor: "rgba(255, 216, 102, 0.58) !important",
backgroundColor: "var(--editor-selection) !important",
},
".cm-content ::selection": {
backgroundColor: "rgba(255, 216, 102, 0.48) !important",
color: "#ffffff !important",
backgroundColor: "var(--editor-selection) !important",
color: "var(--fg) !important",
},
});
let vimMode = "INSERT";
const languageAliases = {js:'javascript', ts:'typescript', py:'python', sh:'shell', bash:'shell', zsh:'shell', yml:'yaml', md:'markdown', c:'cpp', 'c++':'cpp', xml:'html', htm:'html'};
function languageExtension(mode) {
switch (String(mode || "").toLowerCase()) {
mode = String(mode || "").toLowerCase();
switch (languageAliases[mode] || mode) {
case "html":
return html();
case "markdown":
return markdown();
return markdown({codeLanguages: info => {
const mode = info.trim().split(/\s+/)[0].toLowerCase();
if (['md','markdown'].includes(mode)) return null;
const support = languageExtension(mode);
return support?.language || support;
}});
case "javascript":
return javascript({ jsx: true });
case "typescript":
@@ -129,6 +156,7 @@ function attachMinimap(view, minimap, text) {
function setEditorMode(mode) {
vimMode = mode;
document.body.dataset.editorMode = mode.toLowerCase();
const el =
document.getElementById("editor-vim-mode");
@@ -152,6 +180,8 @@ function markdownCompletions(context) {
return null;
}
if (!context.explicit && !word.text.startsWith("{{")) return null;
return {
from: word.from,
options: [
@@ -163,10 +193,14 @@ function markdownCompletions(context) {
{ label: "```go", type: "snippet", apply: "```go\n\n```" },
{ label: "```bash", type: "snippet", apply: "```bash\n\n```" },
{ label: "[link](url)", type: "snippet", apply: "[text](url)" },
{ label: "{{children}}", type: "function", apply: "{{children}}" },
{ label: "{{children}}", type: "function", apply: "{{children}}", boost: 5 },
{ label: "{{children:/}}", type: "function", apply: "{{children:/}}" },
{ label: "{{children:/ exclude=/draft}}", type: "function", apply: "{{children:/ exclude=/draft}}" },
],
].map(option => option.label.startsWith("{{") ? {...option, apply(view, completion, from, to) {
// Existing close-bracket text is part of this macro replacement.
const tail = view.state.sliceDoc(to, to + 2).match(/^\}{1,2}/)?.[0] || "";
view.dispatch({changes:{from,to:to+tail.length,insert:option.label},selection:{anchor:from+option.label.length}});
}} : option),
};
}
@@ -190,11 +224,9 @@ function installVimCommands() {
window.PagesWikiCurrentPath || "/";
};
const saveQuit =
() => {
save();
setTimeout(quit, 120);
};
const saveQuit = async () => {
if (await window.PagesEditor?.saveNow()) quit();
};
// Register both canonical and short names.
Vim.defineEx("write", "w", save);
@@ -208,46 +240,13 @@ function installVimCommands() {
}
function attachVimModeTracking(view) {
view.dom.addEventListener(
"keydown",
(ev) => {
if (ev.key === "Escape" || (ev.ctrlKey && ev.key === "[")) {
setEditorMode("NORMAL");
return;
}
if (vimMode === "NORMAL") {
if (ev.key === "i" || ev.key === "a" || ev.key === "o" || ev.key === "O") {
setEditorMode("INSERT");
return;
}
if (ev.key === "R") {
setEditorMode("REPLACE");
return;
}
if (ev.key === "v" || ev.key === "V") {
setEditorMode("VISUAL");
return;
}
}
if (vimMode === "VISUAL" && ev.key === "Escape") {
setEditorMode("NORMAL");
}
},
true
);
view.dom.addEventListener(
"focusin",
() => {
if (!vimMode) {
setEditorMode("INSERT");
}
}
);
// Observe actual Vim transitions, including A/I/c/operator motions and
// command-line searches, rather than guessing the mode from individual keys.
getCM(view)?.on("vim-mode-change", event => {
const mode = String(event.mode || "normal").toUpperCase();
setEditorMode(mode);
view.dom.classList.toggle("pageswiki-vim-visual", mode === "VISUAL");
});
}
function attachStatusBar(view) {
@@ -281,10 +280,29 @@ function attachStatusBar(view) {
}
window.PagesWikiEditor = {
highlightCodeBlock(code, mode) {
mode = String(mode || '').toLowerCase();
const language = languageExtension(mode);
const text = code.textContent;
// Projection only: never change canonical HTML, unlabelled/plain text,
// or large samples. Large code files retain the windowed viewer.
if (!language || text.length > 32768) return false;
const parser = (language.language || language).parser;
const fragment = document.createDocumentFragment();
let offset = 0;
highlightTree(parser.parse(text), pagesWikiHighlightStyle, (from, to, classes) => {
if (from > offset) fragment.append(document.createTextNode(text.slice(offset, from)));
const span = document.createElement('span'); span.className = classes;
span.textContent = text.slice(from, to); fragment.append(span); offset = to;
});
fragment.append(document.createTextNode(text.slice(offset)));
code.replaceChildren(fragment);
return true;
},
createViewer(target, text, mode, minimap) {
const extensions = [
lineNumbers(),
syntaxHighlighting(defaultHighlightStyle),
syntaxHighlighting(pagesWikiHighlightStyle),
pagesWikiTheme,
EditorState.readOnly.of(true),
EditorView.editable.of(false),
@@ -305,11 +323,13 @@ window.PagesWikiEditor = {
},
create(target, initialText, mode, options = {}) {
const keymapName =
String(options.keymap || "default").toLowerCase();
const mobile = window.matchMedia("(pointer: coarse) and (hover: none)").matches;
const keymapName = mobile ? "default" : String(options.keymap || "default").toLowerCase();
const extensions = [
lineNumbers(),
highlightActiveLine(),
highlightActiveLineGutter(),
history(),
bracketMatching(),
closeBrackets(),
@@ -340,7 +360,7 @@ window.PagesWikiEditor = {
);
if (options.syntax !== false) {
extensions.push(syntaxHighlighting(defaultHighlightStyle));
extensions.push(syntaxHighlighting(pagesWikiHighlightStyle));
}
if (options.autocomplete !== false) {
@@ -358,6 +378,9 @@ window.PagesWikiEditor = {
if (language) {
extensions.push(language);
}
if (mode === "html" || mode === "markdown") {
extensions.push(EditorState.languageData.of(() => [{closeBrackets:{brackets:["(", "[", "'", '"', "`"]}}]));
}
const view =
new EditorView({
@@ -372,116 +395,17 @@ window.PagesWikiEditor = {
if (keymapName === "vim") {
attachVimModeTracking(view);
attachPagesWikiExFallback(view);
}
return view;
},
};
function attachPagesWikiExFallback(view) {
let active = false;
let buffer = "";
function save() {
if (window.PagesEditor && window.PagesEditor.saveNow) {
window.PagesEditor.saveNow();
}
}
function quit() {
location.href =
window.PagesWikiCurrentPath || "/";
}
view.dom.addEventListener(
"keydown",
(ev) => {
if (!active && vimMode === "NORMAL" && ev.key === ":") {
active = true;
buffer = "";
return;
}
if (!active) {
return;
}
if (ev.key === "Escape" || (ev.ctrlKey && ev.key === "[")) {
active = false;
buffer = "";
return;
}
if (ev.key === "Enter") {
const cmd =
buffer.trim();
active = false;
buffer = "";
if (cmd === "w") {
ev.preventDefault();
save();
return;
}
if (cmd === "q") {
ev.preventDefault();
quit();
return;
}
if (cmd === "wq" || cmd === "x") {
ev.preventDefault();
save();
setTimeout(quit, 120);
return;
}
return;
}
if (ev.key.length === 1) {
buffer += ev.key;
}
if (ev.key === "Backspace") {
buffer =
buffer.slice(0, -1);
}
},
true
);
}
let pagesWikiPreviewTimer = null;
function schedulePagesWikiPreview(view) {
const textarea =
document.getElementById("editor");
const textarea = document.getElementById("editor");
if (textarea) {
textarea.value =
view.state.doc.toString();
textarea.dispatchEvent(new Event("input", {bubbles:true}));
}
if (pagesWikiPreviewTimer) {
clearTimeout(pagesWikiPreviewTimer);
}
pagesWikiPreviewTimer =
setTimeout(
() => {
if (
window.PagesEditor &&
window.PagesEditor.renderPreview
) {
window.PagesEditor.renderPreview();
}
},
350
);
}