@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
package/dist/viewer/resize.js
CHANGED
|
@@ -37,6 +37,8 @@ export const mountPanelResize = () => {
|
|
|
37
37
|
}
|
|
38
38
|
const property = options.direction === 1 ? "--sidebar-width" : "--panel-width";
|
|
39
39
|
const requested = () => preferred ?? (options.direction === 1 ? 260 : Math.min(760, window.innerWidth * 0.52));
|
|
40
|
+
if (options.direction === 1 && closed())
|
|
41
|
+
element.style.setProperty(property, `${requested()}px`);
|
|
40
42
|
const apply = (width) => {
|
|
41
43
|
const other = options.direction === 1 ? editor : sidebar;
|
|
42
44
|
const max = Math.max(0, Math.min(options.max, window.innerWidth -
|
|
@@ -138,101 +140,3 @@ export const mountPanelResize = () => {
|
|
|
138
140
|
});
|
|
139
141
|
layout();
|
|
140
142
|
};
|
|
141
|
-
/** The navigation is replaced on refresh; keep listeners and height on its stable sidebar. */
|
|
142
|
-
export const mountToolsResize = () => {
|
|
143
|
-
const sidebar = document.getElementById("sidebar");
|
|
144
|
-
if (!sidebar || !document.getElementById("nav-tools"))
|
|
145
|
-
return () => { };
|
|
146
|
-
const key = "docs:tools-height";
|
|
147
|
-
let preferred;
|
|
148
|
-
try {
|
|
149
|
-
const saved = Number(localStorage.getItem(key));
|
|
150
|
-
if (Number.isFinite(saved) && saved > 0)
|
|
151
|
-
preferred = saved;
|
|
152
|
-
}
|
|
153
|
-
catch {
|
|
154
|
-
/* Persistence is optional. */
|
|
155
|
-
}
|
|
156
|
-
const apply = (height = preferred ?? Math.min(220, innerHeight * 0.4)) => {
|
|
157
|
-
const handle = document.getElementById("tools-resize");
|
|
158
|
-
if (!handle)
|
|
159
|
-
return;
|
|
160
|
-
const max = Math.max(80, sidebar.clientHeight - 100);
|
|
161
|
-
const min = Math.min(144, max);
|
|
162
|
-
const value = Math.round(Math.max(min, Math.min(height, max)));
|
|
163
|
-
sidebar.style.setProperty("--tools-height", `${value}px`);
|
|
164
|
-
handle.setAttribute("aria-valuemin", String(min));
|
|
165
|
-
handle.setAttribute("aria-valuemax", String(max));
|
|
166
|
-
handle.setAttribute("aria-valuenow", String(value));
|
|
167
|
-
};
|
|
168
|
-
const persist = () => {
|
|
169
|
-
preferred = Number.parseFloat(sidebar.style.getPropertyValue("--tools-height"));
|
|
170
|
-
try {
|
|
171
|
-
localStorage.setItem(key, String(preferred));
|
|
172
|
-
}
|
|
173
|
-
catch {
|
|
174
|
-
/* Optional. */
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
const isHandle = (event) => event.target instanceof Element && !!event.target.closest("#tools-resize");
|
|
178
|
-
const height = () => document.getElementById("nav-tools")?.getBoundingClientRect().height ?? 0;
|
|
179
|
-
let drag;
|
|
180
|
-
sidebar.addEventListener("pointerdown", (event) => {
|
|
181
|
-
if (!isHandle(event) || event.button !== 0 || drag)
|
|
182
|
-
return;
|
|
183
|
-
const handle = document.getElementById("tools-resize");
|
|
184
|
-
if (!handle)
|
|
185
|
-
return;
|
|
186
|
-
event.preventDefault();
|
|
187
|
-
handle.focus({ preventScroll: true });
|
|
188
|
-
drag = { id: event.pointerId, y: event.clientY, height: height(), handle };
|
|
189
|
-
handle.setPointerCapture(event.pointerId);
|
|
190
|
-
document.body.classList.add("resizing-tools");
|
|
191
|
-
});
|
|
192
|
-
sidebar.addEventListener("pointermove", (event) => {
|
|
193
|
-
if (drag?.id === event.pointerId)
|
|
194
|
-
apply(drag.height + drag.y - event.clientY);
|
|
195
|
-
});
|
|
196
|
-
const stop = () => {
|
|
197
|
-
if (!drag)
|
|
198
|
-
return;
|
|
199
|
-
drag = undefined;
|
|
200
|
-
document.body.classList.remove("resizing-tools");
|
|
201
|
-
persist();
|
|
202
|
-
};
|
|
203
|
-
for (const type of ["pointerup", "pointercancel", "lostpointercapture"])
|
|
204
|
-
sidebar.addEventListener(type, (event) => {
|
|
205
|
-
if (drag?.id === event.pointerId)
|
|
206
|
-
stop();
|
|
207
|
-
});
|
|
208
|
-
sidebar.addEventListener("keydown", (event) => {
|
|
209
|
-
if (!isHandle(event) || (event.key !== "ArrowUp" && event.key !== "ArrowDown"))
|
|
210
|
-
return;
|
|
211
|
-
event.preventDefault();
|
|
212
|
-
apply(height() + (event.key === "ArrowUp" ? 20 : -20));
|
|
213
|
-
persist();
|
|
214
|
-
});
|
|
215
|
-
sidebar.addEventListener("dblclick", (event) => {
|
|
216
|
-
if (!isHandle(event))
|
|
217
|
-
return;
|
|
218
|
-
preferred = undefined;
|
|
219
|
-
try {
|
|
220
|
-
localStorage.removeItem(key);
|
|
221
|
-
}
|
|
222
|
-
catch {
|
|
223
|
-
/* Optional. */
|
|
224
|
-
}
|
|
225
|
-
apply();
|
|
226
|
-
});
|
|
227
|
-
window.addEventListener("resize", () => apply());
|
|
228
|
-
const restore = () => {
|
|
229
|
-
if (drag && !drag.handle.isConnected)
|
|
230
|
-
stop();
|
|
231
|
-
apply();
|
|
232
|
-
};
|
|
233
|
-
const nav = document.getElementById("nav-groups");
|
|
234
|
-
if (nav)
|
|
235
|
-
new MutationObserver(restore).observe(nav, { childList: true });
|
|
236
|
-
restore();
|
|
237
|
-
return restore;
|
|
238
|
-
};
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type SubformatCollection } from "../core/subformats.js";
|
|
2
2
|
interface SourceLocation {
|
|
3
3
|
file: string;
|
|
4
4
|
line: number;
|
|
5
5
|
}
|
|
6
6
|
export interface ResourceIndex {
|
|
7
|
-
|
|
8
|
-
entry: TermEntry;
|
|
9
|
-
source: SourceLocation;
|
|
10
|
-
}[];
|
|
11
|
-
code: {
|
|
7
|
+
codeblocks: {
|
|
12
8
|
language: string;
|
|
9
|
+
format: string;
|
|
13
10
|
caption: string;
|
|
14
11
|
content: string;
|
|
15
12
|
source: SourceLocation;
|
|
13
|
+
reference?: SourceLocation & {
|
|
14
|
+
range?: string;
|
|
15
|
+
};
|
|
16
16
|
}[];
|
|
17
17
|
urls: {
|
|
18
18
|
url: string;
|
|
19
19
|
host: string;
|
|
20
20
|
sources: SourceLocation[];
|
|
21
21
|
}[];
|
|
22
|
+
urlPreviews: ResourceIndex["urls"];
|
|
23
|
+
subformats: SubformatCollection[];
|
|
22
24
|
errors: string[];
|
|
23
25
|
}
|
|
24
26
|
/** Index authored content, including files not referenced by any document. */
|
|
25
27
|
export declare const resourceIndex: (root: string, files: readonly string[]) => ResourceIndex;
|
|
26
|
-
export type ResourceView = "files" | "
|
|
28
|
+
export type ResourceView = "files" | "codeblocks" | "urls" | "url-previews";
|
|
27
29
|
export declare const resourceTabs: (view: ResourceView) => string;
|
|
28
|
-
export declare const resourceLibraryHtml: (index: ResourceIndex, view: Exclude<ResourceView, "files">) => string;
|
|
30
|
+
export declare const resourceLibraryHtml: (index: ResourceIndex, view: Exclude<ResourceView, "files"> | "subformats", pageTitle?: string) => string;
|
|
29
31
|
export {};
|
|
@@ -1,15 +1,56 @@
|
|
|
1
|
+
import { basename, extname } from "node:path";
|
|
2
|
+
import { bundledLanguagesInfo } from "shiki/langs";
|
|
1
3
|
import { visit } from "unist-util-visit";
|
|
4
|
+
import { readManifest } from "../compiler/manifest.js";
|
|
5
|
+
import { loadSubformat, parseSubformatRecord, validateSubformatRecord, } from "../compiler/subformats.js";
|
|
2
6
|
import { parseTermSource } from "../compiler/terms.js";
|
|
3
|
-
import { readTextfile } from "../compiler/textfile.js";
|
|
7
|
+
import { readTextfile, selectTextfileRange } from "../compiler/textfile.js";
|
|
8
|
+
import { parseFileEmbed } from "../core/file-embed.js";
|
|
9
|
+
import { fileExtension, localFile } from "../core/files.js";
|
|
4
10
|
import { blocksHtml, escapeHtml } from "../core/html.js";
|
|
11
|
+
import { SEARCH_ICON_PATH } from "../core/icons.js";
|
|
5
12
|
import { parseMdast } from "../core/markdown.js";
|
|
13
|
+
import { subformatChange } from "../core/subformats.js";
|
|
14
|
+
import { parseFileReference, parseTextfileRange } from "../core/textfile.js";
|
|
15
|
+
const codeFormat = (language) => /^(text|txt|plain|plaintext)$/.test(language)
|
|
16
|
+
? "text"
|
|
17
|
+
: (bundledLanguagesInfo.find((entry) => entry.id === language || entry.aliases?.includes(language))?.id ?? language);
|
|
6
18
|
/** Index authored content, including files not referenced by any document. */
|
|
7
19
|
export const resourceIndex = (root, files) => {
|
|
8
|
-
const result = {
|
|
20
|
+
const result = {
|
|
21
|
+
codeblocks: [],
|
|
22
|
+
urls: [],
|
|
23
|
+
urlPreviews: [],
|
|
24
|
+
subformats: [],
|
|
25
|
+
errors: [],
|
|
26
|
+
};
|
|
27
|
+
const paths = new Set(files);
|
|
28
|
+
const manifest = readManifest(root);
|
|
29
|
+
result.errors.push(...manifest.errors);
|
|
30
|
+
const formats = new Map();
|
|
31
|
+
for (const config of manifest.subformats ?? []) {
|
|
32
|
+
try {
|
|
33
|
+
if (!paths.has(config.schema))
|
|
34
|
+
throw new Error("Schema is not available in the workspace");
|
|
35
|
+
const loaded = loadSubformat(root, config);
|
|
36
|
+
formats.set(config.ext, loaded);
|
|
37
|
+
result.subformats.push({
|
|
38
|
+
...config,
|
|
39
|
+
fields: loaded.fields,
|
|
40
|
+
template: loaded.template,
|
|
41
|
+
defaultFolder: manifest.defaultSubformatFolder,
|
|
42
|
+
records: [],
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
result.errors.push(`${config.schema}: ${error instanceof Error ? error.message : String(error)}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
9
49
|
const urls = new Map();
|
|
10
|
-
const
|
|
50
|
+
const urlPreviews = new Map();
|
|
51
|
+
const references = new Map();
|
|
52
|
+
const validateTerms = (raw, source) => {
|
|
11
53
|
const parsed = parseTermSource(`${source.file}#L${source.line}`, raw);
|
|
12
|
-
result.terms.push(...parsed.entries.map((entry) => ({ entry, source })));
|
|
13
54
|
result.errors.push(...parsed.errors.map((error) => `${source.file}:L${source.line + error.line}: ${error.message}`));
|
|
14
55
|
};
|
|
15
56
|
const scan = (tree, file, offset = 0) => {
|
|
@@ -21,14 +62,15 @@ export const resourceIndex = (root, files) => {
|
|
|
21
62
|
const source = { file, line: offset + (node.position?.start.line ?? 1) };
|
|
22
63
|
if (node.type === "code") {
|
|
23
64
|
const language = node.lang?.toLowerCase() || "text";
|
|
24
|
-
result.
|
|
25
|
-
language,
|
|
65
|
+
result.codeblocks.push({
|
|
66
|
+
language: formats.get(language)?.format ?? language,
|
|
67
|
+
format: formats.has(language) ? language : codeFormat(language),
|
|
26
68
|
caption: node.meta ?? "",
|
|
27
69
|
content: node.value,
|
|
28
70
|
source,
|
|
29
71
|
});
|
|
30
72
|
if (language === "termth")
|
|
31
|
-
|
|
73
|
+
validateTerms(node.value, { ...source, line: source.line + 1 });
|
|
32
74
|
if (language === "callouth")
|
|
33
75
|
scan(parseMdast(node.value), file, source.line);
|
|
34
76
|
return;
|
|
@@ -40,31 +82,104 @@ export const resourceIndex = (root, files) => {
|
|
|
40
82
|
: undefined;
|
|
41
83
|
if (!target)
|
|
42
84
|
return;
|
|
85
|
+
if (!/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(target)) {
|
|
86
|
+
try {
|
|
87
|
+
const file = parseFileReference(target).file.replace(/^(\.\/)+/, "");
|
|
88
|
+
if (localFile(file) && formats.has(fileExtension(file))) {
|
|
89
|
+
const sources = references.get(file) ?? [];
|
|
90
|
+
sources.push(source);
|
|
91
|
+
references.set(file, sources);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// Invalid references are reported by the compiler.
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const preview = node.type === "image" || node.type === "imageReference";
|
|
99
|
+
if (preview && !/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(target)) {
|
|
100
|
+
try {
|
|
101
|
+
const ref = parseFileEmbed(target);
|
|
102
|
+
if (ref.kind !== "textfile")
|
|
103
|
+
return;
|
|
104
|
+
const referencedFile = ref.file.replace(/^(\.\/)+/, "");
|
|
105
|
+
if (!paths.has(referencedFile))
|
|
106
|
+
throw new Error("File is not available in the workspace");
|
|
107
|
+
const language = (extname(referencedFile).slice(1) || basename(referencedFile)).toLowerCase();
|
|
108
|
+
result.codeblocks.push({
|
|
109
|
+
language: formats.get(language)?.format ?? language,
|
|
110
|
+
format: formats.has(language) ? language : codeFormat(language),
|
|
111
|
+
caption: node.alt ?? "",
|
|
112
|
+
content: selectTextfileRange(readTextfile(root, referencedFile), ref.range),
|
|
113
|
+
source,
|
|
114
|
+
reference: {
|
|
115
|
+
file: referencedFile,
|
|
116
|
+
line: ref.range ? parseTextfileRange(ref.range)[0] : 1,
|
|
117
|
+
...(ref.range ? { range: ref.range } : {}),
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
result.errors.push(`${file}:L${source.line}: ${target}: ${error instanceof Error ? error.message : String(error)}`);
|
|
123
|
+
}
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
43
126
|
try {
|
|
44
127
|
const url = new URL(target);
|
|
45
128
|
if (!["http:", "https:", "mailto:"].includes(url.protocol))
|
|
46
129
|
return;
|
|
130
|
+
const entries = preview ? urlPreviews : urls;
|
|
47
131
|
const key = url.href;
|
|
48
|
-
const entry =
|
|
132
|
+
const entry = entries.get(key) ?? {
|
|
49
133
|
url: key,
|
|
50
134
|
host: url.host || url.protocol,
|
|
51
135
|
sources: [],
|
|
52
136
|
};
|
|
53
137
|
entry.sources.push(source);
|
|
54
|
-
|
|
138
|
+
entries.set(key, entry);
|
|
55
139
|
}
|
|
56
140
|
catch {
|
|
57
141
|
// Local paths and anchors are not external URL resources.
|
|
58
142
|
}
|
|
59
143
|
});
|
|
60
144
|
};
|
|
61
|
-
for (const file of
|
|
145
|
+
for (const file of paths) {
|
|
146
|
+
const format = formats.get(fileExtension(file));
|
|
147
|
+
if (format && !(manifest.subformats ?? []).some((item) => item.schema === file)) {
|
|
148
|
+
try {
|
|
149
|
+
const content = readTextfile(root, file);
|
|
150
|
+
result.codeblocks.push({
|
|
151
|
+
language: format.format,
|
|
152
|
+
format: format.ext,
|
|
153
|
+
caption: file,
|
|
154
|
+
content,
|
|
155
|
+
source: { file, line: 1 },
|
|
156
|
+
});
|
|
157
|
+
const data = parseSubformatRecord(content, format.format);
|
|
158
|
+
validateSubformatRecord(format, data);
|
|
159
|
+
result.subformats
|
|
160
|
+
.find((item) => item.ext === format.ext)
|
|
161
|
+
?.records.push({ file, content, data });
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
result.errors.push(`${file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
165
|
+
}
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
62
168
|
if (!/\.(?:md|termth)$/i.test(file))
|
|
63
169
|
continue;
|
|
64
170
|
try {
|
|
65
171
|
const raw = readTextfile(root, file);
|
|
66
|
-
if (/\.termth$/i.test(file))
|
|
67
|
-
|
|
172
|
+
if (/\.termth$/i.test(file)) {
|
|
173
|
+
const source = { file, line: 1 };
|
|
174
|
+
result.codeblocks.push({
|
|
175
|
+
language: "termth",
|
|
176
|
+
format: "termth",
|
|
177
|
+
caption: "",
|
|
178
|
+
content: raw,
|
|
179
|
+
source,
|
|
180
|
+
});
|
|
181
|
+
validateTerms(raw, source);
|
|
182
|
+
}
|
|
68
183
|
else
|
|
69
184
|
scan(parseMdast(raw), file);
|
|
70
185
|
}
|
|
@@ -72,33 +187,67 @@ export const resourceIndex = (root, files) => {
|
|
|
72
187
|
result.errors.push(`${file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
73
188
|
}
|
|
74
189
|
}
|
|
75
|
-
result.terms.sort((a, b) => a.entry.name.localeCompare(b.entry.name, undefined, { numeric: true }));
|
|
76
190
|
result.urls = [...urls.values()].sort((a, b) => a.url.localeCompare(b.url));
|
|
191
|
+
result.urlPreviews = [...urlPreviews.values()].sort((a, b) => a.url.localeCompare(b.url));
|
|
192
|
+
for (const collection of result.subformats)
|
|
193
|
+
for (const record of collection.records)
|
|
194
|
+
record.references = references.get(record.file) ?? [];
|
|
77
195
|
return result;
|
|
78
196
|
};
|
|
79
197
|
export const resourceTabs = (view) => view === "files"
|
|
80
198
|
? ""
|
|
81
199
|
: `<nav class="resource-tabs" aria-label="Resource views" data-i18n-aria-label="Resource views">${[
|
|
82
|
-
["
|
|
83
|
-
["code", "Code blocks"],
|
|
200
|
+
["codeblocks", "Codeblocks"],
|
|
84
201
|
["urls", "URLs"],
|
|
202
|
+
["url-previews", "URL previews"],
|
|
85
203
|
]
|
|
86
|
-
.map(([key, label]) => `<a href="/_statics
|
|
204
|
+
.map(([key, label]) => `<a href="/_statics/${key}"${view === key ? ' aria-current="page"' : ""} data-i18n="${label}">${label}</a>`)
|
|
87
205
|
.join("")}</nav>`;
|
|
88
206
|
const sourceLink = ({ file, line }) => `<a class="resource-source" href="/_files/file/${encodeURIComponent(file)}#L${line}" data-resource-source="${escapeHtml(file)}" data-resource-line="${line}" title="${escapeHtml(file)}:L${line}"><span class="resource-source-file">${escapeHtml(file)}</span><span>L${line}</span></a>`;
|
|
89
|
-
export const resourceLibraryHtml = (index, view) => {
|
|
90
|
-
const
|
|
91
|
-
const
|
|
207
|
+
export const resourceLibraryHtml = (index, view, pageTitle) => {
|
|
208
|
+
const subformatsOnly = view === "subformats";
|
|
209
|
+
const groupLabel = subformatsOnly ? "Subformats" : view === "codeblocks" ? "Format" : "Domain";
|
|
210
|
+
const urls = view === "url-previews" ? index.urlPreviews : index.urls;
|
|
211
|
+
const groups = [
|
|
212
|
+
...new Set(subformatsOnly
|
|
213
|
+
? index.subformats.map((item) => item.ext)
|
|
214
|
+
: view === "codeblocks"
|
|
215
|
+
? [
|
|
216
|
+
...index.codeblocks.map((item) => item.format),
|
|
217
|
+
...index.subformats.map((item) => item.ext),
|
|
218
|
+
]
|
|
219
|
+
: urls.map((item) => item.host)),
|
|
220
|
+
].sort();
|
|
221
|
+
const items = subformatsOnly
|
|
92
222
|
? []
|
|
93
|
-
:
|
|
94
|
-
|
|
95
|
-
?
|
|
96
|
-
:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
223
|
+
: view === "codeblocks"
|
|
224
|
+
? index.codeblocks.map(({ language, format, caption, content, source, reference }) => {
|
|
225
|
+
const name = caption || (reference ? reference.file + (reference.range ?? "") : "");
|
|
226
|
+
return `<details class="resource-item resource-code" data-resource-item data-resource-group="${escapeHtml(format)}"><summary><span class="resource-badge">${escapeHtml(format)}</span>${name ? `<span class="resource-name" title="${escapeHtml(name)}">${escapeHtml(name)}</span>` : ""}${sourceLink(source)}</summary><div class="resource-body">${reference ? `<div class="resource-sources">${sourceLink(reference)}</div>` : ""}${blocksHtml([{ type: "code", lang: language === "mermaid" ? "text" : language, lines: content.split("\n") }])}</div></details>`;
|
|
227
|
+
})
|
|
228
|
+
: urls.map(({ url, host, sources }) => `<details class="resource-item resource-url" data-resource-item data-resource-group="${escapeHtml(host)}"><summary><a class="resource-name" href="${escapeHtml(url)}" title="${escapeHtml(url)}" target="_blank" rel="noopener noreferrer">${escapeHtml(url)}</a><span class="resource-usage" title="references" data-i18n-title="references">${sources.length}</span></summary><div class="resource-body resource-sources">${sources.map(sourceLink).join("")}</div></details>`);
|
|
229
|
+
const filterGroups = subformatsOnly ? index.subformats.map((item) => item.ext) : groups;
|
|
230
|
+
const selector = filterGroups.length || subformatsOnly
|
|
231
|
+
? `<select data-resource-filter${subformatsOnly ? " data-subformat-filter hidden" : ""} aria-label="${groupLabel}" data-i18n-aria-label="${groupLabel}">${subformatsOnly ? (filterGroups.length ? "" : '<option value="" data-i18n="Subformats">Subformats</option>') : '<option value="" data-i18n="All">All</option>'}${filterGroups
|
|
232
|
+
.map((group) => {
|
|
233
|
+
const collection = index.subformats.find((item) => item.ext === group);
|
|
234
|
+
const change = collection && subformatChange(collection);
|
|
235
|
+
return `<option value="${escapeHtml(group)}"${change ? ` data-subformat-change="${change}"` : ""}>${escapeHtml(group)}</option>`;
|
|
236
|
+
})
|
|
237
|
+
.join("")}</select>`
|
|
238
|
+
: "";
|
|
239
|
+
const selectedChange = index.subformats[0] && subformatChange(index.subformats[0]);
|
|
240
|
+
const filter = pageTitle !== undefined
|
|
241
|
+
? `<h1 class="subformat-page-title">${escapeHtml(pageTitle)}</h1>`
|
|
242
|
+
: subformatsOnly
|
|
243
|
+
? `<div class="subformat-picker">${selector}<button type="button" data-subformat-trigger aria-haspopup="menu" aria-expanded="false"${selectedChange ? ` data-subformat-change="${selectedChange}"` : ""}>${escapeHtml(filterGroups[0] ?? "Subformats")}</button><div class="subformat-picker-menu" data-subformat-options popover="auto" role="menu" aria-label="Subformats" data-i18n-aria-label="Subformats"></div></div>`
|
|
244
|
+
: selector;
|
|
245
|
+
const search = `<label class="resource-search"><svg width="13" height="13" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="${SEARCH_ICON_PATH}"/></svg><input type="search" data-resource-search placeholder="Search resources" aria-label="Search resources" data-i18n-placeholder="Search resources" data-i18n-aria-label="Search resources"></label>`;
|
|
246
|
+
const subformats = subformatsOnly || (view === "codeblocks" && index.subformats.length)
|
|
247
|
+
? `<template data-subformats>${escapeHtml(JSON.stringify(index.subformats))}</template><div data-subformat-board role="region" hidden></div>`
|
|
248
|
+
: "";
|
|
249
|
+
const emptyMessage = subformatsOnly && !index.subformats.length
|
|
250
|
+
? "No subformats configured. Add subformats to dooc.yaml."
|
|
251
|
+
: "No matching resources";
|
|
252
|
+
return `<section class="resource-results" data-resource-results${pageTitle !== undefined ? ` data-subformat-page="${escapeHtml(index.subformats[0]?.ext ?? "")}"` : ""}><div class="resource-toolbar">${subformatsOnly ? `<div class="resource-query">${filter}</div>` : `<span data-i18n="Name">Name</span>${search}${filter}`}${subformatsOnly ? "" : `<span class="resource-count" data-resource-count role="status" aria-live="polite">${items.length}</span>`}</div>${subformats}${index.errors.length ? `<details class="resource-errors"><summary><span data-i18n="Files with errors">Files with errors</span> (${index.errors.length})</summary><ul>${index.errors.map((error) => `<li>${escapeHtml(error)}</li>`).join("")}</ul></details>` : ""}<div class="resource-items resource-${view}">${items.join("")}</div><p class="resource-empty" data-resource-empty${items.length ? " hidden" : ""} data-i18n="${emptyMessage}">${emptyMessage}</p></section>`;
|
|
104
253
|
};
|
package/dist/viewer/search.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import type { Site } from "./serve.js";
|
|
2
2
|
export interface SearchSection {
|
|
3
|
+
/** text: rendered document text; file: a file name; folder: a folder document's path. */
|
|
4
|
+
kind: "text" | "file" | "folder";
|
|
3
5
|
path: string;
|
|
4
6
|
file: string;
|
|
5
|
-
folder: boolean;
|
|
6
7
|
title: string;
|
|
7
8
|
heading: string;
|
|
8
9
|
anchor: string;
|
|
9
10
|
text: string;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
+
/** `files` are workspace files that open at /_files/file/<path> (edit mode only). */
|
|
13
|
+
export declare const searchIndex: (site: Site, files?: readonly string[]) => SearchSection[];
|
|
12
14
|
export declare const searchSections: (index: SearchSection[], query: string, currentPath?: string) => (SearchSection & {
|
|
13
15
|
snippet: string;
|
|
14
16
|
})[];
|