@dooc-dev/dooc 0.0.3 → 0.0.5
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/dist/cli.js +98 -56
- package/dist/compiler/asset-references.d.ts +4 -0
- package/dist/compiler/asset-references.js +117 -0
- package/dist/compiler/bundle-urls.d.ts +1 -1
- package/dist/compiler/bundle-urls.js +15 -5
- package/dist/compiler/check.js +8 -5
- package/dist/compiler/code-languages.js +7 -2
- package/dist/compiler/compile.d.ts +5 -0
- package/dist/compiler/compile.js +105 -10
- package/dist/compiler/config.js +2 -1
- package/dist/compiler/export.d.ts +4 -0
- package/dist/compiler/export.js +140 -0
- package/dist/compiler/figures.js +4 -0
- package/dist/compiler/files.d.ts +1 -0
- package/dist/compiler/files.js +96 -38
- package/dist/compiler/fonts.js +4 -1
- package/dist/compiler/icons.d.ts +1 -1
- package/dist/compiler/icons.js +11 -2
- package/dist/compiler/ignored-files.d.ts +3 -0
- package/dist/compiler/ignored-files.js +68 -0
- package/dist/compiler/locales.js +13 -8
- package/dist/compiler/manifest.d.ts +2 -0
- package/dist/compiler/manifest.js +9 -2
- package/dist/compiler/ops.d.ts +6 -0
- package/dist/compiler/ops.js +98 -7
- package/dist/compiler/subformats.d.ts +24 -0
- package/dist/compiler/subformats.js +299 -0
- package/dist/compiler/textfile.js +3 -0
- package/dist/compiler/theme-variants.js +5 -2
- package/dist/core/content-metadata.d.ts +15 -6
- package/dist/core/content-metadata.js +278 -17
- package/dist/core/content-types.d.ts +3 -1
- package/dist/core/figure-frame.js +19 -1
- package/dist/core/files.d.ts +2 -1
- package/dist/core/files.js +6 -8
- package/dist/core/flow-base-css.generated.js +1 -1
- package/dist/core/html.js +3 -3
- package/dist/core/icons.d.ts +3 -0
- package/dist/core/icons.js +3 -0
- package/dist/core/json-tools.d.ts +1 -0
- package/dist/core/json-tools.js +12 -0
- package/dist/core/routing.d.ts +5 -2
- package/dist/core/routing.js +17 -5
- package/dist/core/subformat-record.d.ts +3 -0
- package/dist/core/subformat-record.js +131 -0
- package/dist/core/subformats.d.ts +43 -0
- package/dist/core/subformats.js +81 -0
- package/dist/core/toc-ui.js +25 -23
- package/dist/edit.global.js +322 -95
- package/dist/mcp.js +50 -9
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/local-storage.js +3 -0
- package/dist/plugins/oauth.d.ts +1 -1
- package/dist/plugins/oauth.js +8 -2
- package/dist/plugins/runtime.d.ts +6 -0
- package/dist/plugins/runtime.js +166 -34
- package/dist/plugins/transport.d.ts +22 -0
- package/dist/plugins/transport.js +1 -0
- package/dist/plugins/types.d.ts +3 -1
- package/dist/plugins.global.js +128 -0
- package/dist/subformats.global.js +127 -0
- package/dist/ui.global.js +91 -38
- package/dist/viewer/build-plugins.d.ts +7 -0
- package/dist/viewer/build-plugins.js +70 -0
- package/dist/viewer/build.d.ts +9 -0
- package/dist/viewer/build.js +32 -5
- package/dist/viewer/editor-tools.d.ts +7 -7
- package/dist/viewer/editor-tools.js +36 -5
- package/dist/viewer/font-picker.js +5 -1
- package/dist/viewer/git-diff.d.ts +3 -0
- package/dist/viewer/git-diff.js +47 -0
- package/dist/viewer/hmr.js +4 -1
- package/dist/viewer/i18n.js +7 -5
- package/dist/viewer/language-picker.d.ts +2 -2
- package/dist/viewer/language-picker.js +26 -9
- package/dist/viewer/lazy-graph.d.ts +2 -0
- package/dist/viewer/lazy-graph.js +30 -0
- package/dist/viewer/locales/eng.json +74 -10
- package/dist/viewer/locales/jpn.json +75 -11
- package/dist/viewer/locales/zho.json +75 -11
- package/dist/viewer/nav-focus.js +8 -1
- package/dist/viewer/nav-update.d.ts +2 -0
- package/dist/viewer/nav-update.js +117 -0
- package/dist/viewer/plugin-style.d.ts +1 -0
- package/dist/viewer/plugin-style.js +82 -0
- package/dist/viewer/plugins.js +46 -3
- package/dist/viewer/resize.d.ts +0 -2
- package/dist/viewer/resize.js +2 -98
- package/dist/viewer/resource-library.d.ts +10 -8
- package/dist/viewer/resource-library.js +179 -30
- package/dist/viewer/search.d.ts +4 -2
- package/dist/viewer/search.js +252 -53
- package/dist/viewer/serve.d.ts +10 -5
- package/dist/viewer/serve.js +882 -287
- package/dist/viewer/site-icon.js +13 -6
- package/dist/viewer/site-title.d.ts +13 -0
- package/dist/viewer/site-title.js +50 -0
- package/dist/viewer/textfile.d.ts +3 -0
- package/dist/viewer/textfile.js +19 -2
- package/dist/viewer/theme-picker.d.ts +2 -0
- package/dist/viewer/theme-picker.js +24 -8
- package/dist/viewer/workspace.d.ts +2 -0
- package/dist/viewer/workspace.js +46 -1
- package/package.json +24 -9
- package/dist/compiler/bundle.d.ts +0 -2
- package/dist/compiler/bundle.js +0 -100
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PluginTransport } from "../plugins/transport.js";
|
|
2
|
+
/** Only previously enabled packages execute; personal credentials never enter the artifact. */
|
|
3
|
+
export declare const loadBuildPlugins: (root: string, module?: string) => Promise<{
|
|
4
|
+
request: PluginTransport;
|
|
5
|
+
dispose: () => void;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const pluginSnapshot: (request: PluginTransport) => (url: string) => Promise<string | undefined>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createLocalPluginStorage } from "../plugins/local-storage.js";
|
|
2
|
+
import { createPluginRuntime } from "../plugins/runtime.js";
|
|
3
|
+
import { createExtensionManager } from "./extensions.js";
|
|
4
|
+
import { loadViewerPlugins } from "./plugin-config.js";
|
|
5
|
+
import { PLUGIN_BLOCK_CSS } from "./plugin-style.js";
|
|
6
|
+
import { pluginViewHtml } from "./plugin-view.js";
|
|
7
|
+
/** Only previously enabled packages execute; personal credentials never enter the artifact. */
|
|
8
|
+
export const loadBuildPlugins = async (root, module) => {
|
|
9
|
+
const initial = await loadViewerPlugins(module);
|
|
10
|
+
if (initial.setup)
|
|
11
|
+
throw new Error("Build plugins must be declared without a viewer setup callback");
|
|
12
|
+
const personal = createLocalPluginStorage();
|
|
13
|
+
let config = initial;
|
|
14
|
+
const manager = createExtensionManager(root, {
|
|
15
|
+
configuration: () => config,
|
|
16
|
+
register(plugin, options) {
|
|
17
|
+
config = {
|
|
18
|
+
...config,
|
|
19
|
+
plugins: [...config.plugins, plugin],
|
|
20
|
+
mocks: {
|
|
21
|
+
...config.mocks,
|
|
22
|
+
...(options?.mock ? { [plugin.id]: options.mock } : {}),
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
unregister(id) {
|
|
27
|
+
config = {
|
|
28
|
+
...config,
|
|
29
|
+
plugins: config.plugins.filter((plugin) => plugin.id !== id),
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
}, initial, personal);
|
|
33
|
+
try {
|
|
34
|
+
const errors = await manager.restore();
|
|
35
|
+
if (errors.length)
|
|
36
|
+
throw new Error(errors.join("\n"));
|
|
37
|
+
const runtime = createPluginRuntime(config.plugins, async (input, init) => {
|
|
38
|
+
const request = new Request(input, init);
|
|
39
|
+
const mock = Object.values(config.mocks).find((mock) => mock.origin === new URL(request.url).origin);
|
|
40
|
+
return mock ? mock.handle(request) : fetch(request);
|
|
41
|
+
}, personal.credentials);
|
|
42
|
+
const session = runtime.createSession();
|
|
43
|
+
const request = async (input) => {
|
|
44
|
+
if (input.action === "resolve")
|
|
45
|
+
return { plugin: runtime.resolve(input.url) };
|
|
46
|
+
if (input.action === "read" && input.plugin)
|
|
47
|
+
return runtime.read(session, input.plugin, input.url);
|
|
48
|
+
throw new Error("Static builds only resolve and read plugins");
|
|
49
|
+
};
|
|
50
|
+
return { request, dispose: () => manager.dispose() };
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
manager.dispose();
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export const pluginSnapshot = (request) => async (url) => {
|
|
58
|
+
const { plugin } = await request({ action: "resolve", url });
|
|
59
|
+
if (!plugin)
|
|
60
|
+
return undefined;
|
|
61
|
+
const { view } = await request({ action: "read", plugin, url });
|
|
62
|
+
if (!view)
|
|
63
|
+
throw new Error(`Plugin ${plugin} returned no view for ${url}`);
|
|
64
|
+
const html = pluginViewHtml(view).replace(/<button\b/g, "<button disabled");
|
|
65
|
+
return `<div class="plugin"><style>${PLUGIN_BLOCK_CSS}
|
|
66
|
+
.plugin { container-type: inline-size; color: var(--doc-fg, #000000); --doc-mono: ui-monospace, monospace; }
|
|
67
|
+
.plugin-copy { display: none; }
|
|
68
|
+
.plugin button:disabled { cursor: default; }
|
|
69
|
+
</style><div class="plugin-content">${html}</div></div>`;
|
|
70
|
+
};
|
package/dist/viewer/build.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import type { PluginTransport } from "../plugins/transport.js";
|
|
1
2
|
export interface BuildOptions {
|
|
2
3
|
format: "html" | "zip";
|
|
3
4
|
urlPreview?: "embed" | "network";
|
|
5
|
+
mode?: "static" | "live";
|
|
6
|
+
auth?: "external";
|
|
7
|
+
/** Public directory URL corresponding to the manifest directory, embedded in HTML. */
|
|
8
|
+
sourceUrl?: string;
|
|
9
|
+
/** Trusted server module used for static snapshots, never serialized into HTML. */
|
|
10
|
+
pluginModule?: string;
|
|
11
|
+
/** Build-time authenticated reads; live HTML receives its transport at runtime. */
|
|
12
|
+
pluginTransport?: PluginTransport;
|
|
4
13
|
}
|
|
5
14
|
/** Build one artifact from the manifest and its managed content. */
|
|
6
15
|
export declare const buildBundle: (root: string, options: BuildOptions) => Promise<{
|
package/dist/viewer/build.js
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
-
import { bundleEntries } from "../compiler/bundle.js";
|
|
5
4
|
import { embedBundleUrls } from "../compiler/bundle-urls.js";
|
|
6
5
|
import { compileSite } from "../compiler/compile.js";
|
|
6
|
+
import { exportEntries } from "../compiler/export.js";
|
|
7
7
|
import { loadProjectFonts } from "../compiler/fonts.js";
|
|
8
8
|
import { textfilePath } from "../compiler/textfile.js";
|
|
9
9
|
import { zip } from "../compiler/zip.js";
|
|
10
|
+
import { loadBuildPlugins, pluginSnapshot } from "./build-plugins.js";
|
|
10
11
|
import { loadSiteLanguages } from "./languages.js";
|
|
12
|
+
import { sourceFileBase } from "./workspace.js";
|
|
11
13
|
/** Build one artifact from the manifest and its managed content. */
|
|
12
14
|
export const buildBundle = async (root, options) => {
|
|
13
15
|
const { format } = options;
|
|
14
|
-
|
|
16
|
+
if (options.sourceUrl !== undefined && format !== "html")
|
|
17
|
+
throw new Error("Source URL applies to HTML builds only");
|
|
18
|
+
const sourceBase = format === "html" ? sourceFileBase(root, options.sourceUrl) : undefined;
|
|
19
|
+
const urlPreview = options.urlPreview ?? (options.mode === "live" ? "network" : "embed");
|
|
20
|
+
if (options.mode !== undefined && !["static", "live"].includes(options.mode))
|
|
21
|
+
throw new Error("build mode must be static | live");
|
|
22
|
+
if (options.mode && format !== "html")
|
|
23
|
+
throw new Error("Build modes apply to HTML; use export for source ZIPs");
|
|
24
|
+
if (options.auth !== undefined && (options.auth !== "external" || options.mode !== "live"))
|
|
25
|
+
throw new Error("External authentication requires live HTML");
|
|
26
|
+
if (options.mode === "static" && urlPreview !== "embed")
|
|
27
|
+
throw new Error("Static HTML requires embedded resources");
|
|
28
|
+
if (options.mode === "live" && urlPreview !== "network")
|
|
29
|
+
throw new Error("Live HTML requires network resources");
|
|
15
30
|
if (format !== "html" && format !== "zip")
|
|
16
31
|
throw new Error("build format must be html | zip");
|
|
17
32
|
if (urlPreview !== "embed" && urlPreview !== "network")
|
|
@@ -22,10 +37,19 @@ export const buildBundle = async (root, options) => {
|
|
|
22
37
|
throw new Error(`Content validation failed:\n${compiled.errors.join("\n")}`);
|
|
23
38
|
return compiled;
|
|
24
39
|
};
|
|
40
|
+
let entries = exportEntries(root);
|
|
25
41
|
let compiled = validate(root);
|
|
26
|
-
let entries = format === "zip" || urlPreview === "embed" ? bundleEntries(root) : [];
|
|
27
42
|
if (urlPreview === "embed") {
|
|
28
|
-
|
|
43
|
+
const plugins = format === "html" && !options.pluginTransport
|
|
44
|
+
? await loadBuildPlugins(root, options.pluginModule)
|
|
45
|
+
: undefined;
|
|
46
|
+
try {
|
|
47
|
+
const request = options.pluginTransport ?? plugins?.request;
|
|
48
|
+
entries = await embedBundleUrls(root, entries, request ? pluginSnapshot(request) : undefined);
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
plugins?.dispose();
|
|
52
|
+
}
|
|
29
53
|
const temp = mkdtempSync(join(tmpdir(), "dooc-bundle-"));
|
|
30
54
|
try {
|
|
31
55
|
for (const entry of entries) {
|
|
@@ -46,10 +70,13 @@ export const buildBundle = async (root, options) => {
|
|
|
46
70
|
return {
|
|
47
71
|
data: publishHtml({
|
|
48
72
|
...siteFrom(compiled, config.languages),
|
|
73
|
+
sourceBase,
|
|
49
74
|
fonts: loadProjectFonts(root),
|
|
50
75
|
codeLanguages: config.codeLanguages,
|
|
51
76
|
codeGrammars: config.codeGrammars,
|
|
52
|
-
}, await bundleClient("core/schema-graph-global.tsx"
|
|
77
|
+
}, await bundleClient("core/schema-graph-global.tsx"), undefined, await bundleClient("viewer/code-highlight.ts"), options.mode === "live" ? "live" : urlPreview === "embed" ? "static" : "network", options.mode === "live" ? await bundleClient("viewer/published-plugins.ts") : "", compiled.docs.some((doc) => doc.subformat)
|
|
78
|
+
? await bundleClient("viewer/published-subformats.ts")
|
|
79
|
+
: ""),
|
|
53
80
|
docs: compiled.docs.length,
|
|
54
81
|
};
|
|
55
82
|
};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
export { codeBlockAt } from "../core/markdown.js";
|
|
2
2
|
export declare function isLocalToolRequest(host: string, origin: string | undefined, contentType: string | undefined): boolean;
|
|
3
3
|
export declare function runCodeTool(root: string, body: string, position: number, action: "format" | "lint"): Promise<{
|
|
4
|
-
change: {
|
|
5
|
-
from: number;
|
|
6
|
-
to: number;
|
|
7
|
-
insert: string;
|
|
8
|
-
};
|
|
9
|
-
findings?: undefined;
|
|
10
|
-
} | {
|
|
11
4
|
findings: {
|
|
12
5
|
range: [number, number];
|
|
13
6
|
message: string;
|
|
14
7
|
ruleId: string;
|
|
15
8
|
}[];
|
|
16
9
|
change?: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
change: {
|
|
12
|
+
from: number;
|
|
13
|
+
to: number;
|
|
14
|
+
insert: string;
|
|
15
|
+
};
|
|
16
|
+
findings?: undefined;
|
|
17
17
|
}>;
|
|
18
18
|
export declare function validateCodeTools(root: string, body: string): Promise<{
|
|
19
19
|
changes: {
|
|
@@ -2,6 +2,7 @@ import { execFile } from "node:child_process";
|
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { visit } from "unist-util-visit";
|
|
5
|
+
import { formatJson } from "../core/json-tools.js";
|
|
5
6
|
import { codeBlockAt, offsetAt, parseMdast } from "../core/markdown.js";
|
|
6
7
|
export { codeBlockAt } from "../core/markdown.js";
|
|
7
8
|
import { formatMarkdown } from "../compiler/format.js";
|
|
@@ -49,12 +50,39 @@ export async function runCodeTool(root, body, position, action) {
|
|
|
49
50
|
try {
|
|
50
51
|
config = JSON.parse(await readFile(path, "utf8"));
|
|
51
52
|
}
|
|
52
|
-
catch {
|
|
53
|
-
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error.code !== "ENOENT")
|
|
55
|
+
throw error;
|
|
56
|
+
if (block.language !== "json")
|
|
57
|
+
throw new Error(`Create .dooc/editor-tools/${block.language}.json to configure this language`);
|
|
58
|
+
config = {};
|
|
54
59
|
}
|
|
55
60
|
if (!config || typeof config !== "object")
|
|
56
61
|
throw new Error("Invalid editor tool configuration");
|
|
57
|
-
const
|
|
62
|
+
const tool = config[action === "format" ? "formatter" : "linter"];
|
|
63
|
+
let output;
|
|
64
|
+
if (block.language === "json" && tool == null) {
|
|
65
|
+
if (action === "lint") {
|
|
66
|
+
try {
|
|
67
|
+
JSON.parse(block.code);
|
|
68
|
+
return { findings: [] };
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
return {
|
|
72
|
+
findings: [
|
|
73
|
+
{
|
|
74
|
+
range: [block.from, block.to],
|
|
75
|
+
message: String(error),
|
|
76
|
+
ruleId: "error",
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
output = formatJson(block.code);
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
output = await execute(command(tool), root, `${block.code}\n`, action === "lint");
|
|
58
86
|
if (action === "format") {
|
|
59
87
|
const normalized = output.replace(/\r\n/g, "\n").replace(/\n$/, "");
|
|
60
88
|
if (!normalized && block.code.trim())
|
|
@@ -134,14 +162,17 @@ export async function validateCodeTools(root, body) {
|
|
|
134
162
|
raw = await readFile(join(root, ".dooc/editor-tools", `${node.lang}.json`), "utf8");
|
|
135
163
|
}
|
|
136
164
|
catch (error) {
|
|
137
|
-
if (error.code === "ENOENT")
|
|
165
|
+
if (error.code === "ENOENT") {
|
|
166
|
+
if (node.lang === "json")
|
|
167
|
+
blocks.push(node.position.start.offset);
|
|
138
168
|
continue;
|
|
169
|
+
}
|
|
139
170
|
throw error;
|
|
140
171
|
}
|
|
141
172
|
const config = JSON.parse(raw);
|
|
142
173
|
if (!config || typeof config !== "object")
|
|
143
174
|
throw new Error("Invalid editor tool configuration");
|
|
144
|
-
if (config[tool] != null)
|
|
175
|
+
if (config[tool] != null || node.lang === "json")
|
|
145
176
|
blocks.push(offsetAt(text, node.position.start.line, node.position.start.column));
|
|
146
177
|
}
|
|
147
178
|
return blocks;
|
|
@@ -46,8 +46,12 @@ export const mountFontPickers = async (createSettings, registered) => {
|
|
|
46
46
|
const names = choices();
|
|
47
47
|
for (const button of document.querySelectorAll("[data-font-picker]")) {
|
|
48
48
|
const kind = target(button);
|
|
49
|
+
const name = names.get(settings.selected[kind]) ?? t("Default font");
|
|
50
|
+
const valueLabel = button.querySelector("[data-picker-value]");
|
|
51
|
+
if (valueLabel && valueLabel.textContent !== name)
|
|
52
|
+
valueLabel.textContent = name;
|
|
49
53
|
button.disabled = busy;
|
|
50
|
-
button.title = `${t(kind === "editor" ? "Editor font" : "Viewer font")}: ${
|
|
54
|
+
button.title = `${t(kind === "editor" ? "Editor font" : "Viewer font")}: ${name}`;
|
|
51
55
|
button.setAttribute("aria-label", button.title);
|
|
52
56
|
button.setAttribute("aria-controls", popup.id);
|
|
53
57
|
button.setAttribute("popovertarget", popup.id);
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { SubformatCollection } from "../core/subformats.js";
|
|
2
|
+
export declare const gitFileChanges: (root: string) => Map<string, "added" | "modified">;
|
|
1
3
|
/** Compare against HEAD so saving or staging does not clear the editor's changes. */
|
|
2
4
|
export declare const gitBaseText: (root: string, file: string) => string | null;
|
|
3
5
|
export declare const gitBaseBody: (root: string, file: string) => string | null;
|
|
6
|
+
export declare const setSubformatChanges: (root: string, collections: SubformatCollection[]) => void;
|
package/dist/viewer/git-diff.js
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
3
|
import { parseDoc } from "../compiler/dialect.js";
|
|
4
|
+
import { parseManifestText } from "../compiler/manifest.js";
|
|
3
5
|
import { textfilePath } from "../compiler/textfile.js";
|
|
6
|
+
import { MANIFEST_FILE } from "../core/content-metadata.js";
|
|
7
|
+
import { parseGitChanges } from "./git.js";
|
|
8
|
+
export const gitFileChanges = (root) => {
|
|
9
|
+
const changes = new Map();
|
|
10
|
+
const git = (...args) => execFileSync("git", ["--no-optional-locks", "-C", root, ...args], {
|
|
11
|
+
encoding: "utf8",
|
|
12
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
13
|
+
timeout: 2_000,
|
|
14
|
+
maxBuffer: 5_000_000,
|
|
15
|
+
});
|
|
16
|
+
try {
|
|
17
|
+
const prefix = git("rev-parse", "--show-prefix").trim();
|
|
18
|
+
const status = git("status", "--porcelain=v1", "-z", "--untracked-files=all", "--no-renames", "--", ".");
|
|
19
|
+
for (const change of parseGitChanges(status)) {
|
|
20
|
+
if (!change.path.startsWith(prefix))
|
|
21
|
+
continue;
|
|
22
|
+
changes.set(change.path.slice(prefix.length), /[?A]/.test(change.index + change.worktree) ? "added" : "modified");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// Git metadata is optional; unavailable repositories keep neutral cards.
|
|
27
|
+
}
|
|
28
|
+
return changes;
|
|
29
|
+
};
|
|
4
30
|
/** Compare against HEAD so saving or staging does not clear the editor's changes. */
|
|
5
31
|
export const gitBaseText = (root, file) => {
|
|
6
32
|
const git = (...args) => execFileSync("git", ["-C", root, ...args], {
|
|
@@ -31,3 +57,24 @@ export const gitBaseBody = (root, file) => {
|
|
|
31
57
|
const raw = gitBaseText(root, file);
|
|
32
58
|
return raw === null ? null : parseDoc(raw).body;
|
|
33
59
|
};
|
|
60
|
+
export const setSubformatChanges = (root, collections) => {
|
|
61
|
+
const changes = gitFileChanges(root);
|
|
62
|
+
const raw = gitBaseText(root, MANIFEST_FILE);
|
|
63
|
+
const base = raw === null ? undefined : parseManifestText(raw);
|
|
64
|
+
for (const collection of collections) {
|
|
65
|
+
const previous = base?.subformats?.find((item) => item.ext === collection.ext);
|
|
66
|
+
collection.baseLayouts =
|
|
67
|
+
base && !base.errors.length ? (previous?.layouts ?? {}) : undefined;
|
|
68
|
+
collection.change =
|
|
69
|
+
base && !base.errors.length && !previous
|
|
70
|
+
? "added"
|
|
71
|
+
: previous &&
|
|
72
|
+
(previous.format !== collection.format ||
|
|
73
|
+
previous.schema !== collection.schema ||
|
|
74
|
+
!isDeepStrictEqual(previous.layouts ?? {}, collection.layouts ?? {}))
|
|
75
|
+
? "modified"
|
|
76
|
+
: changes.get(collection.schema);
|
|
77
|
+
for (const record of collection.records)
|
|
78
|
+
record.change = changes.get(record.file);
|
|
79
|
+
}
|
|
80
|
+
};
|
package/dist/viewer/hmr.js
CHANGED
|
@@ -20,6 +20,7 @@ import { textfilePath } from "../compiler/textfile.js";
|
|
|
20
20
|
import { MANIFEST_FILE } from "../core/content-metadata.js";
|
|
21
21
|
import { isRemoteTextfile } from "../core/textfile.js";
|
|
22
22
|
import { prebuilt } from "./assets.js";
|
|
23
|
+
import { updateNav } from "./nav-update.js";
|
|
23
24
|
import { gitHeadFile } from "./workspace.js";
|
|
24
25
|
/** SSE endpoint. SoT for the server route and the client script's connection target. */
|
|
25
26
|
export const HMR_PATH = "/api/hmr";
|
|
@@ -37,6 +38,7 @@ export const classifyChange = (rel) => {
|
|
|
37
38
|
if (p === "src/viewer/edit-client.ts" ||
|
|
38
39
|
p === "src/viewer/files-ui.ts" ||
|
|
39
40
|
p === "src/viewer/resource-library-ui.ts" ||
|
|
41
|
+
p === "src/viewer/subformats-ui.ts" ||
|
|
40
42
|
p === "src/viewer/edit-code-file.ts" ||
|
|
41
43
|
p === "src/core/code-file.ts" ||
|
|
42
44
|
p === "src/core/files.ts" ||
|
|
@@ -67,6 +69,7 @@ export const classifyChange = (rel) => {
|
|
|
67
69
|
p === "src/viewer/preview-update.ts" ||
|
|
68
70
|
p === "src/plugins/view.ts" ||
|
|
69
71
|
p === "src/viewer/nav-focus.ts" ||
|
|
72
|
+
p === "src/viewer/nav-update.ts" ||
|
|
70
73
|
p === "src/viewer/code-highlight.ts" ||
|
|
71
74
|
(p.startsWith("src/viewer/locales/") && p.endsWith(".json")) ||
|
|
72
75
|
(p.startsWith("src/core/") && p.endsWith(".tsx"))) {
|
|
@@ -296,7 +299,7 @@ export const hmrClientScript = (mode) => `
|
|
|
296
299
|
const nav = document.getElementById("nav-groups");
|
|
297
300
|
const nextNav = next.getElementById("nav-groups");
|
|
298
301
|
if (nav && nextNav) {
|
|
299
|
-
nav
|
|
302
|
+
(${updateNav.toString()})(nav, nextNav.innerHTML);
|
|
300
303
|
if (window.__docsNavRestore) window.__docsNavRestore();
|
|
301
304
|
}
|
|
302
305
|
window.scrollTo(0, y);
|
package/dist/viewer/i18n.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { iso6393To1 } from "iso-639-3";
|
|
2
|
-
import {
|
|
2
|
+
import { mountSelectPickers } from "./language-picker.js";
|
|
3
3
|
import eng from "./locales/eng.json" with { type: "json" };
|
|
4
4
|
import jpn from "./locales/jpn.json" with { type: "json" };
|
|
5
5
|
import zho from "./locales/zho.json" with { type: "json" };
|
|
@@ -25,9 +25,11 @@ export const applyUiLanguage = () => {
|
|
|
25
25
|
const marker = attr === "text" ? "data-i18n" : `data-i18n-${attr}`;
|
|
26
26
|
for (const element of document.querySelectorAll(`[${marker}]`)) {
|
|
27
27
|
const value = t(element.getAttribute(marker) ?? "");
|
|
28
|
-
if (attr === "text")
|
|
29
|
-
element.textContent
|
|
30
|
-
|
|
28
|
+
if (attr === "text") {
|
|
29
|
+
if (element.textContent !== value)
|
|
30
|
+
element.textContent = value;
|
|
31
|
+
}
|
|
32
|
+
else if (element.getAttribute(attr) !== value)
|
|
31
33
|
element.setAttribute(attr, value);
|
|
32
34
|
}
|
|
33
35
|
}
|
|
@@ -61,5 +63,5 @@ export const mountUiLanguage = () => {
|
|
|
61
63
|
}
|
|
62
64
|
});
|
|
63
65
|
document.addEventListener("docs:ui-refresh", applyUiLanguage);
|
|
64
|
-
|
|
66
|
+
mountSelectPickers(t);
|
|
65
67
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/** Keep the native select as the
|
|
2
|
-
export declare const
|
|
1
|
+
/** Keep the native select as the value and change-event source. */
|
|
2
|
+
export declare const mountSelectPickers: (t: (key: string) => string, selects?: Iterable<HTMLSelectElement>) => (() => void);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
/** Keep the native select as the
|
|
2
|
-
export const
|
|
3
|
-
|
|
1
|
+
/** Keep the native select as the value and change-event source. */
|
|
2
|
+
export const mountSelectPickers = (t, selects = document.querySelectorAll("#fm-lang, #ui-language")) => {
|
|
3
|
+
const disposers = [];
|
|
4
|
+
for (const select of selects) {
|
|
4
5
|
const translations = select.id === "fm-lang";
|
|
5
6
|
const trigger = select
|
|
6
7
|
.closest(".fm-language")
|
|
@@ -115,7 +116,7 @@ export const mountLanguagePickers = (t) => {
|
|
|
115
116
|
if (trigger)
|
|
116
117
|
trigger.disabled = select.disabled;
|
|
117
118
|
input.setAttribute("aria-disabled", String(select.disabled));
|
|
118
|
-
input.placeholder = t("Search languages");
|
|
119
|
+
input.placeholder = select.dataset.placeholder ?? t("Search languages");
|
|
119
120
|
input.setAttribute("aria-label", select.getAttribute("aria-label") ?? t("Language"));
|
|
120
121
|
if (translations)
|
|
121
122
|
input.setAttribute("aria-description", t("Enter to edit; Ctrl+Enter to add or remove translation"));
|
|
@@ -213,21 +214,37 @@ export const mountLanguagePickers = (t) => {
|
|
|
213
214
|
!(event.relatedTarget instanceof Node && wrapper.contains(event.relatedTarget)))
|
|
214
215
|
popup.hidePopover();
|
|
215
216
|
});
|
|
216
|
-
|
|
217
|
+
const outside = (event) => {
|
|
217
218
|
if (isOpen() && event.target instanceof Node && !wrapper.contains(event.target))
|
|
218
219
|
popup.hidePopover();
|
|
219
|
-
}
|
|
220
|
-
|
|
220
|
+
};
|
|
221
|
+
document.addEventListener("pointerdown", outside);
|
|
222
|
+
const resize = new ResizeObserver(() => {
|
|
221
223
|
if (isOpen())
|
|
222
224
|
position();
|
|
223
|
-
})
|
|
225
|
+
});
|
|
226
|
+
resize.observe(input);
|
|
224
227
|
select.addEventListener("change", sync);
|
|
225
|
-
new MutationObserver(sync)
|
|
228
|
+
const observer = new MutationObserver(sync);
|
|
229
|
+
observer.observe(select, {
|
|
226
230
|
childList: true,
|
|
227
231
|
subtree: true,
|
|
228
232
|
attributes: true,
|
|
229
233
|
});
|
|
230
234
|
document.addEventListener("docs:ui-language", sync);
|
|
235
|
+
disposers.push(() => {
|
|
236
|
+
document.removeEventListener("pointerdown", outside);
|
|
237
|
+
document.removeEventListener("docs:ui-language", sync);
|
|
238
|
+
select.removeEventListener("change", sync);
|
|
239
|
+
resize.disconnect();
|
|
240
|
+
observer.disconnect();
|
|
241
|
+
wrapper.replaceWith(select);
|
|
242
|
+
select.hidden = false;
|
|
243
|
+
});
|
|
231
244
|
sync();
|
|
232
245
|
}
|
|
246
|
+
return () => {
|
|
247
|
+
for (const dispose of disposers)
|
|
248
|
+
dispose();
|
|
249
|
+
};
|
|
233
250
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Load diagram runtimes only when a page or live preview contains a diagram. */
|
|
2
|
+
export const loadGraphScript = () => {
|
|
3
|
+
const root = document.querySelector("main") ?? document.body;
|
|
4
|
+
const selector = "svg[data-sg-layout], [data-mermaid]";
|
|
5
|
+
let requested = false;
|
|
6
|
+
const load = () => {
|
|
7
|
+
if (requested)
|
|
8
|
+
return;
|
|
9
|
+
requested = true;
|
|
10
|
+
const script = document.createElement("script");
|
|
11
|
+
script.src = "/assets/graph.js";
|
|
12
|
+
script.onload = () => observer.disconnect();
|
|
13
|
+
script.onerror = () => {
|
|
14
|
+
script.remove();
|
|
15
|
+
requested = false;
|
|
16
|
+
};
|
|
17
|
+
document.head.append(script);
|
|
18
|
+
};
|
|
19
|
+
const observer = new MutationObserver((records) => {
|
|
20
|
+
for (const record of records)
|
|
21
|
+
for (const node of record.addedNodes)
|
|
22
|
+
if (node instanceof Element &&
|
|
23
|
+
root.contains(node) &&
|
|
24
|
+
(node.matches(selector) || node.querySelector(selector)))
|
|
25
|
+
load();
|
|
26
|
+
});
|
|
27
|
+
observer.observe(root, { childList: true, subtree: true });
|
|
28
|
+
if (root.querySelector(selector))
|
|
29
|
+
load();
|
|
30
|
+
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
+
"Site title": "Site title",
|
|
3
|
+
"Edit site title": "Edit site title",
|
|
2
4
|
"Editor font": "Editor font",
|
|
3
5
|
"Viewer font": "Viewer font",
|
|
4
6
|
"Default font": "Default font",
|
|
@@ -151,9 +153,14 @@
|
|
|
151
153
|
"{count} results": "{count} results",
|
|
152
154
|
"Showing {shown} of {count} results": "Showing {shown} of {count} results",
|
|
153
155
|
"Add translation": "Add translation",
|
|
154
|
-
"Folder": "Folder",
|
|
155
156
|
"Move search": "Move search",
|
|
156
157
|
"Resize search": "Resize search",
|
|
158
|
+
"Matches text": "Matches text",
|
|
159
|
+
"Matches file name": "Matches file name",
|
|
160
|
+
"Matches folder name": "Matches folder name",
|
|
161
|
+
"Close search": "Close search",
|
|
162
|
+
"Move search to sidebar": "Move search to sidebar",
|
|
163
|
+
"Float search": "Float search",
|
|
157
164
|
"Notice": "Notice",
|
|
158
165
|
"OK": "OK",
|
|
159
166
|
"Discard changes": "Discard changes",
|
|
@@ -210,16 +217,21 @@
|
|
|
210
217
|
"File details": "File details",
|
|
211
218
|
"Show Git changes": "Show Git changes",
|
|
212
219
|
"Resource views": "Resource views",
|
|
213
|
-
"
|
|
214
|
-
"
|
|
215
|
-
"
|
|
220
|
+
"Default": "Default",
|
|
221
|
+
"Set as default": "Set as default",
|
|
222
|
+
"Group by": "Group by",
|
|
223
|
+
"Sort by": "Sort by",
|
|
224
|
+
"Newest first": "Newest first",
|
|
225
|
+
"Oldest first": "Oldest first",
|
|
226
|
+
"Unassigned": "Unassigned",
|
|
227
|
+
"Records": "Records",
|
|
228
|
+
"Codeblocks": "Codeblocks",
|
|
229
|
+
"Format": "Format",
|
|
216
230
|
"URLs": "URLs",
|
|
231
|
+
"URL previews": "URL previews",
|
|
217
232
|
"Domain": "Domain",
|
|
218
233
|
"All": "All",
|
|
219
234
|
"references": "references",
|
|
220
|
-
"Definitions from term files and Markdown": "Definitions from term files and Markdown",
|
|
221
|
-
"Code blocks collected from Markdown files": "Code blocks collected from Markdown files",
|
|
222
|
-
"External links and embeds with their source locations": "External links and embeds with their source locations",
|
|
223
235
|
"Search resources": "Search resources",
|
|
224
236
|
"Files with errors": "Files with errors",
|
|
225
237
|
"No matching resources": "No matching resources",
|
|
@@ -279,14 +291,21 @@
|
|
|
279
291
|
"Restore stash": "Restore stash",
|
|
280
292
|
"Stash changes": "Stash changes",
|
|
281
293
|
"Statics": "Statics",
|
|
294
|
+
"Subformats": "Subformats",
|
|
295
|
+
"Expand card": "Expand card",
|
|
296
|
+
"Collapse card": "Collapse card",
|
|
297
|
+
"View details": "View details",
|
|
298
|
+
"Click for details; double-click to edit": "Click for details; double-click to edit",
|
|
299
|
+
"No grouping": "No grouping",
|
|
300
|
+
"Ascending": "Ascending",
|
|
301
|
+
"Descending": "Descending",
|
|
302
|
+
"No subformats configured. Add subformats to dooc.yaml.": "No subformats configured. Add subformats to dooc.yaml.",
|
|
282
303
|
"Workspace tools": "Workspace tools",
|
|
283
|
-
"Resize workspace tools": "Resize workspace tools",
|
|
284
304
|
"Git controls": "Git controls",
|
|
285
305
|
"Actions": "Actions",
|
|
286
306
|
"Updated": "Updated",
|
|
287
307
|
"Copy": "Copy",
|
|
288
308
|
"Edit": "Edit",
|
|
289
|
-
"Saving…": "Saving…",
|
|
290
309
|
"Reload actions before saving again.": "Reload actions before saving again.",
|
|
291
310
|
"Saved, but refresh failed. Reload actions before saving again.": "Saved, but refresh failed. Reload actions before saving again.",
|
|
292
311
|
"Actions could not be loaded.": "Actions could not be loaded.",
|
|
@@ -313,5 +332,50 @@
|
|
|
313
332
|
"Sign out": "Sign out",
|
|
314
333
|
"Not signed in": "Not signed in",
|
|
315
334
|
"Continue login": "Continue login",
|
|
316
|
-
"Provided by viewer": "Provided by viewer"
|
|
335
|
+
"Provided by viewer": "Provided by viewer",
|
|
336
|
+
"Added": "Added",
|
|
337
|
+
"Modified": "Modified",
|
|
338
|
+
"Add subformat…": "Add subformat…",
|
|
339
|
+
"Add subformat": "Add subformat",
|
|
340
|
+
"Extension": "Extension",
|
|
341
|
+
"Storage format": "Storage format",
|
|
342
|
+
"Schema file (optional)": "Schema file (optional)",
|
|
343
|
+
"Create automatically": "Create automatically",
|
|
344
|
+
"Form": "Form",
|
|
345
|
+
"Enter a valid number.": "Enter a valid number.",
|
|
346
|
+
"Value editing mode": "Value editing mode",
|
|
347
|
+
"{format} text": "{format} text",
|
|
348
|
+
"Schema editing mode": "Schema editing mode",
|
|
349
|
+
"JSON text": "JSON text",
|
|
350
|
+
"Build kit": "Build kit",
|
|
351
|
+
"Field settings": "Field settings",
|
|
352
|
+
"Field name": "Field name",
|
|
353
|
+
"New field name": "New field name",
|
|
354
|
+
"New field type": "New field type",
|
|
355
|
+
"Remove field": "Remove field",
|
|
356
|
+
"Add field": "Add field",
|
|
357
|
+
"Required": "Required",
|
|
358
|
+
"Allow extra fields": "Allow extra fields",
|
|
359
|
+
"Choices (one per line)": "Choices (one per line)",
|
|
360
|
+
"Item type": "Item type",
|
|
361
|
+
"Rename linked fields in JSON text.": "Rename linked fields in JSON text.",
|
|
362
|
+
"Additional rules are preserved in JSON text.": "Additional rules are preserved in JSON text.",
|
|
363
|
+
"Enter a field name.": "Enter a field name.",
|
|
364
|
+
"Enter a unique field name.": "Enter a unique field name.",
|
|
365
|
+
"A field with this name already exists.": "A field with this name already exists.",
|
|
366
|
+
"Each choice must match the field type.": "Each choice must match the field type.",
|
|
367
|
+
"Choices must be unique.": "Choices must be unique.",
|
|
368
|
+
"Enter a value greater than {minimum}.": "Enter a value greater than {minimum}.",
|
|
369
|
+
"Page type": "Page type",
|
|
370
|
+
"Markdown page": "Markdown page",
|
|
371
|
+
"No subformats available to add.": "No subformats available to add.",
|
|
372
|
+
"Add page": "Add page",
|
|
373
|
+
"Remove page": "Remove page",
|
|
374
|
+
"Rename page": "Rename page",
|
|
375
|
+
"Remove this page from the sidebar? The records will be kept.": "Remove this page from the sidebar? The records will be kept.",
|
|
376
|
+
"Constraints": "Constraints",
|
|
377
|
+
"Semantic": "Semantic",
|
|
378
|
+
"Items": "Items",
|
|
379
|
+
"Remove parameter": "Remove parameter",
|
|
380
|
+
"Check the parameter value.": "Check the parameter value."
|
|
317
381
|
}
|