@dooc-dev/dooc 0.0.28 → 0.0.29
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/client.global.js +1 -1
- package/dist/edit.global.js +220 -221
- package/dist/engine/compiler/check.js +5 -3
- package/dist/engine/compiler/compile.d.ts +5 -0
- package/dist/engine/compiler/compile.js +44 -23
- package/dist/engine/compiler/dialect.js +1 -1
- package/dist/engine/compiler/document-diff.d.ts +53 -0
- package/dist/engine/compiler/document-diff.js +92 -0
- package/dist/engine/compiler/export.js +11 -3
- package/dist/engine/compiler/files.d.ts +1 -0
- package/dist/engine/compiler/files.js +75 -14
- package/dist/engine/compiler/from-mdast.js +12 -1
- package/dist/engine/compiler/icons.d.ts +7 -7
- package/dist/engine/compiler/icons.js +35 -37
- package/dist/engine/compiler/manifest.d.ts +1 -0
- package/dist/engine/compiler/manifest.js +25 -0
- package/dist/engine/compiler/ops.d.ts +2 -2
- package/dist/engine/compiler/ops.js +55 -112
- package/dist/engine/compiler/resource-index.js +4 -4
- package/dist/engine/compiler/root-page.d.ts +13 -0
- package/dist/engine/compiler/root-page.js +96 -0
- package/dist/engine/compiler/sidebar-removal.d.ts +63 -0
- package/dist/engine/compiler/sidebar-removal.js +317 -0
- package/dist/engine/compiler/subformats.d.ts +3 -0
- package/dist/engine/compiler/subformats.js +126 -32
- package/dist/engine/core/blocks.d.ts +5 -0
- package/dist/engine/core/content-metadata.d.ts +9 -4
- package/dist/engine/core/content-metadata.js +100 -16
- package/dist/engine/core/file-embed.d.ts +2 -1
- package/dist/engine/core/file-embed.js +4 -0
- package/dist/engine/core/files.d.ts +1 -0
- package/dist/engine/core/files.js +6 -1
- package/dist/engine/core/format-collections.js +2 -2
- package/dist/engine/core/formats.d.ts +1 -1
- package/dist/engine/core/formats.js +1 -1
- package/dist/engine/core/html.d.ts +1 -0
- package/dist/engine/core/html.js +8 -4
- package/dist/engine/core/icons.d.ts +7 -0
- package/dist/engine/core/icons.js +38 -0
- package/dist/engine/core/subformats.d.ts +2 -1
- package/dist/engine/core/subformats.js +6 -1
- package/dist/engine/core/toc-library.d.ts +5 -0
- package/dist/engine/core/toc-library.js +27 -0
- package/dist/frontend/document-application.d.ts +5 -2
- package/dist/frontend/document-application.js +378 -172
- package/dist/frontend/edit-dialog.d.ts +1 -0
- package/dist/frontend/edit-dialog.js +12 -8
- package/dist/frontend/file-references.js +1 -1
- package/dist/frontend/locales/eng.json +62 -1
- package/dist/frontend/locales/jpn.json +62 -1
- package/dist/frontend/locales/zho.json +62 -1
- package/dist/frontend/page-jump.js +17 -10
- package/dist/frontend/resize.js +38 -12
- package/dist/frontend/resource-library.js +1 -0
- package/dist/frontend/search.js +2 -0
- package/dist/frontend/theme-picker.d.ts +2 -2
- package/dist/frontend/theme-picker.js +2 -2
- package/dist/manifest.global.js +193 -192
- package/dist/mcp-relay.mjs +8 -4
- package/dist/plugins.global.js +49 -49
- package/dist/server/cli.js +12 -0
- package/dist/server/document-diff-cli.d.ts +1 -0
- package/dist/server/document-diff-cli.js +193 -0
- package/dist/server/document-diff-report.d.ts +3 -0
- package/dist/server/document-diff-report.js +124 -0
- package/dist/server/document-diff-sources.d.ts +40 -0
- package/dist/server/document-diff-sources.js +128 -0
- package/dist/server/document-versions.d.ts +3 -1
- package/dist/server/document-versions.js +19 -70
- package/dist/server/git-diff.d.ts +1 -0
- package/dist/server/git-diff.js +22 -2
- package/dist/server/git-document-snapshot.d.ts +2 -0
- package/dist/server/git-document-snapshot.js +63 -0
- package/dist/server/operation-log.js +2 -0
- package/dist/server/serve.d.ts +2 -2
- package/dist/server/serve.js +4 -9
- package/dist/server/workspace-server.js +6 -10
- package/dist/subformats.global.js +478 -74
- package/dist/ui.global.js +435 -80
- package/dist/workspace/file-operation.d.ts +10 -0
- package/dist/workspace/file-operation.js +47 -0
- package/dist/workspace/mcp-tools.js +8 -4
- package/dist/workspace/site-icon.js +30 -23
- package/dist/workspace/textfile.js +8 -8
- package/dist/workspace-worker.global.js +238 -196
- package/package.json +2 -2
|
@@ -7,7 +7,7 @@ import { themeVariantFile } from "../core/theme-variants.js";
|
|
|
7
7
|
import { assetProse, checkProse, markdownProse } from "./check-prose.js";
|
|
8
8
|
import { CHECK_KINDS, } from "./check-types.js";
|
|
9
9
|
import { parseContentSource } from "./code-blocks.js";
|
|
10
|
-
import { compileSite } from "./compile.js";
|
|
10
|
+
import { compileSite, linkedMarkdownFile } from "./compile.js";
|
|
11
11
|
import { collectRefs, parseDoc } from "./dialect.js";
|
|
12
12
|
import { rebaseFileLinks } from "./files.js";
|
|
13
13
|
import { formatFiles } from "./format-files.js";
|
|
@@ -328,8 +328,10 @@ export const checkSite = (root, options = {}) => {
|
|
|
328
328
|
for (const link of contentLinks(tree)) {
|
|
329
329
|
try {
|
|
330
330
|
const target = parseDocLink(link.url);
|
|
331
|
-
if (target &&
|
|
332
|
-
|
|
331
|
+
if (target &&
|
|
332
|
+
!docs.has(target.file) &&
|
|
333
|
+
!linkedMarkdownFile(report.root, target.file))
|
|
334
|
+
add("DOCUMENT_INVALID", "error", owner, `Linked document file is unavailable: ${target.file}`, context, { line: link.position?.start.line, relatedFile: target.file });
|
|
333
335
|
}
|
|
334
336
|
catch (error) {
|
|
335
337
|
add("DOCUMENT_INVALID", "error", owner, messageOf(error), context, {
|
|
@@ -49,6 +49,7 @@ export interface Compiled {
|
|
|
49
49
|
defaultLang: string;
|
|
50
50
|
contentLanguages?: string[];
|
|
51
51
|
themes?: ("light" | "dark")[];
|
|
52
|
+
accentColor?: string;
|
|
52
53
|
}
|
|
53
54
|
export interface CompileOptions {
|
|
54
55
|
/** Network permissions supplied by the host application, never by document metadata. */
|
|
@@ -87,6 +88,10 @@ export interface DraftContext {
|
|
|
87
88
|
/** Site default language for a draft. Default: DEFAULT_LANG. */
|
|
88
89
|
defaultLang?: string;
|
|
89
90
|
}
|
|
91
|
+
/** Markdown retained outside the sidebar opens through the project file viewer. */
|
|
92
|
+
export declare const linkedMarkdownFile: (root: string, file: string, fragment?: string, textfiles?: ReadonlyMap<string, string>) => {
|
|
93
|
+
toc?: readonly TocEntry[];
|
|
94
|
+
} | undefined;
|
|
90
95
|
export declare const createCompiler: (root: string, options?: CompileOptions) => Compiler;
|
|
91
96
|
/**
|
|
92
97
|
* Compiles a single unsaved draft (file = `content/<id>.md`) in the site's context.
|
|
@@ -16,16 +16,16 @@ import { parseContentSource } from "./code-blocks.js";
|
|
|
16
16
|
import { collectRefs, parseDoc } from "./dialect.js";
|
|
17
17
|
import { figureName, loadFigures } from "./figures.js";
|
|
18
18
|
import { createFileCache, createSigCache, dirSig, fileSig } from "./file-cache.js";
|
|
19
|
-
import { projectFiles, rebaseFileLinks } from "./files.js";
|
|
19
|
+
import { projectFilePath, projectFiles, rebaseFileLinks } from "./files.js";
|
|
20
20
|
import { formatCollectionBlock, readFormatCollection } from "./format-collections.js";
|
|
21
21
|
import { toBlocks } from "./from-mdast.js";
|
|
22
22
|
import { existsSync, join, readdirSync, statSync } from "./host.js";
|
|
23
|
-
import { loadIcons,
|
|
23
|
+
import { loadIcons, siteIconAssets } from "./icons.js";
|
|
24
24
|
import { assertNotIgnored, ignoredFiles } from "./ignored-files.js";
|
|
25
25
|
import { contentLanguageCode, isContentLanguage } from "./language-codes.js";
|
|
26
26
|
import { siteContentLanguages, translationFile } from "./locales.js";
|
|
27
|
-
import { manifestFile, readManifest } from "./manifest.js";
|
|
28
|
-
import { loadSubformat, parseSubformatRecord, subformatIconSvg, validateSubformatRecord, } from "./subformats.js";
|
|
27
|
+
import { hasContentsSource, manifestFile, readManifest, sourceOrigin } from "./manifest.js";
|
|
28
|
+
import { loadSubformat, parseSubformatRecord, recordSubformat, subformatDirectory, subformatIconSvg, validateSubformatRecord, } from "./subformats.js";
|
|
29
29
|
import { parseTermSource } from "./terms.js";
|
|
30
30
|
import { readTextfile, selectTextfileRange } from "./textfile.js";
|
|
31
31
|
import { TextfileUnavailable } from "./textfile-remote.js";
|
|
@@ -70,7 +70,9 @@ const parseFile = (raw, previews, file, origin) => {
|
|
|
70
70
|
};
|
|
71
71
|
const resolveFiles = (f, root, textfiles, previews, themes, manifest = root ? readManifest(root) : undefined) => {
|
|
72
72
|
if (!f.refs.terms.length &&
|
|
73
|
-
!walkBlocks(f.blocks).some((b) => b.type === "
|
|
73
|
+
!walkBlocks(f.blocks).some((b) => b.type === "pageContents" ||
|
|
74
|
+
b.type === "figureRef" ||
|
|
75
|
+
(b.type === "code" && b.filename)))
|
|
74
76
|
return f;
|
|
75
77
|
const errors = [...f.parsed.errors];
|
|
76
78
|
const terms = [...f.parsed.terms];
|
|
@@ -85,6 +87,11 @@ const resolveFiles = (f, root, textfiles, previews, themes, manifest = root ? re
|
|
|
85
87
|
? { blocks: item.blocks.map(resolveBlock) }
|
|
86
88
|
: { ...item, children: item.children.map(resolveItem) };
|
|
87
89
|
const resolveBlock = (b) => {
|
|
90
|
+
if (b.type === "pageContents") {
|
|
91
|
+
if (root && manifest && !hasContentsSource(manifest, manifestFile(root), b.file))
|
|
92
|
+
errors.push(`Table of contents source is not in this document: ${b.file}`);
|
|
93
|
+
return b;
|
|
94
|
+
}
|
|
88
95
|
const file = b.type === "code"
|
|
89
96
|
? b.filename?.replace(/^(\.\/)+/, "")
|
|
90
97
|
: b.type === "figureRef"
|
|
@@ -139,7 +146,8 @@ const resolveFiles = (f, root, textfiles, previews, themes, manifest = root ? re
|
|
|
139
146
|
const file = b.filename.replace(/^(\.\/)+/, "");
|
|
140
147
|
const schema = subformats?.find((format) => format.schema === file);
|
|
141
148
|
const config = b.range === undefined && !isRemoteTextfile(file)
|
|
142
|
-
? (schema ??
|
|
149
|
+
? (schema ??
|
|
150
|
+
(manifest && recordSubformat(root, manifest, file, previews?.domains)))
|
|
143
151
|
: undefined;
|
|
144
152
|
if (config) {
|
|
145
153
|
const loaded = loadSubformat(root, config, previews?.domains);
|
|
@@ -147,7 +155,9 @@ const resolveFiles = (f, root, textfiles, previews, themes, manifest = root ? re
|
|
|
147
155
|
validateSubformatOptions(b.embed ?? {}, loaded.fields);
|
|
148
156
|
const files = schema
|
|
149
157
|
? projectFiles(root)
|
|
150
|
-
.filter((item) =>
|
|
158
|
+
.filter((item) => manifest &&
|
|
159
|
+
recordSubformat(root, manifest, item.path, previews?.domains)
|
|
160
|
+
?.ext === config.ext)
|
|
151
161
|
.map((item) => item.path)
|
|
152
162
|
: [file];
|
|
153
163
|
const records = [];
|
|
@@ -274,8 +284,22 @@ const toDoc = (id, parent, file, f, lang, title) => ({
|
|
|
274
284
|
toc: f.toc,
|
|
275
285
|
refs: f.refs,
|
|
276
286
|
});
|
|
287
|
+
/** Markdown retained outside the sidebar opens through the project file viewer. */
|
|
288
|
+
export const linkedMarkdownFile = (root, file, fragment, textfiles) => {
|
|
289
|
+
try {
|
|
290
|
+
if (!statSync(projectFilePath(root, file)).isFile())
|
|
291
|
+
return;
|
|
292
|
+
if (!fragment)
|
|
293
|
+
return {};
|
|
294
|
+
const text = textfiles?.get(file) ?? readTextfile(root, file);
|
|
295
|
+
return { toc: toBlocks(parseMdast(text), text).toc };
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
277
301
|
// Validate the dialect and resolution of visual assets, terms and document links.
|
|
278
|
-
const docErrors = (f, { docs, figures }) => {
|
|
302
|
+
const docErrors = (f, { docs, figures, root, textfiles }) => {
|
|
279
303
|
const errors = [...f.parsed.errors];
|
|
280
304
|
for (const file of f.figureFiles) {
|
|
281
305
|
if (figures.get(figureName(file))?.file !== file) {
|
|
@@ -284,7 +308,9 @@ const docErrors = (f, { docs, figures }) => {
|
|
|
284
308
|
}
|
|
285
309
|
for (const url of f.docLinks) {
|
|
286
310
|
const ref = parseDocLink(url);
|
|
287
|
-
const target = ref &&
|
|
311
|
+
const target = ref &&
|
|
312
|
+
(docs.find((doc) => doc.file === ref.file) ??
|
|
313
|
+
(root ? linkedMarkdownFile(root, ref.file, ref.fragment, textfiles) : undefined));
|
|
288
314
|
if (ref && !target)
|
|
289
315
|
errors.push(`Document link "${url}" is unresolved (check the file path)`);
|
|
290
316
|
else if (ref?.fragment &&
|
|
@@ -379,17 +405,7 @@ export const createCompiler = (root, options = {}) => {
|
|
|
379
405
|
iconFile = manifestIcon;
|
|
380
406
|
if (iconFile) {
|
|
381
407
|
try {
|
|
382
|
-
icon =
|
|
383
|
-
if (!icon)
|
|
384
|
-
throw new Error("expected an SVG with a viewBox or width and height");
|
|
385
|
-
const variants = Object.entries(manifest.themeIcons ?? themeVariants(root, iconFile, themes, manifest));
|
|
386
|
-
if (variants.length)
|
|
387
|
-
iconVariants = Object.fromEntries(variants.map(([theme, file]) => {
|
|
388
|
-
const svg = squareSvg(readTextfile(root, file));
|
|
389
|
-
if (!svg)
|
|
390
|
-
throw new Error(`${file}: expected an SVG with a viewBox or width and height`);
|
|
391
|
-
return [theme, svg];
|
|
392
|
-
}));
|
|
408
|
+
({ icon, iconVariants } = siteIconAssets(root, manifest, themes));
|
|
393
409
|
}
|
|
394
410
|
catch (error) {
|
|
395
411
|
siteErrors.push(`${manifestFile(root)}: icon ${iconFile}: ${error instanceof Error ? error.message : error}`);
|
|
@@ -497,6 +513,7 @@ export const createCompiler = (root, options = {}) => {
|
|
|
497
513
|
}
|
|
498
514
|
const docs = files.map((f) => f.doc);
|
|
499
515
|
const ctx = {
|
|
516
|
+
root,
|
|
500
517
|
docs,
|
|
501
518
|
figures: new Map(figures.map((f) => [f.name, f])),
|
|
502
519
|
defaultLang,
|
|
@@ -555,8 +572,9 @@ export const createCompiler = (root, options = {}) => {
|
|
|
555
572
|
const loaded = loadSubformat(root, config, previews.domains);
|
|
556
573
|
collection.fields = loaded.fields;
|
|
557
574
|
collection.template = loaded.template;
|
|
558
|
-
collection.defaultFolder = manifest.
|
|
559
|
-
for (const record of paths.filter((file) =>
|
|
575
|
+
collection.defaultFolder = subformatDirectory(manifest, config.ext);
|
|
576
|
+
for (const record of paths.filter((file) => recordSubformat(root, manifest, file.path, previews?.domains)?.ext ===
|
|
577
|
+
config.ext)) {
|
|
560
578
|
try {
|
|
561
579
|
const content = readTextfile(root, record.path);
|
|
562
580
|
const data = parseSubformatRecord(content, config.format);
|
|
@@ -686,6 +704,7 @@ export const createCompiler = (root, options = {}) => {
|
|
|
686
704
|
subformats: manifest.subformats,
|
|
687
705
|
...(manifest.languages ? { contentLanguages: manifest.languages } : {}),
|
|
688
706
|
...(manifest.themes ? { themes: manifest.themes } : {}),
|
|
707
|
+
...(manifest.accentColor ? { accentColor: manifest.accentColor } : {}),
|
|
689
708
|
...(title === undefined ? {} : { title }),
|
|
690
709
|
...(icon === undefined ? {} : { icon }),
|
|
691
710
|
...(iconVariants === undefined ? {} : { iconVariants }),
|
|
@@ -708,7 +727,9 @@ export const createCompiler = (root, options = {}) => {
|
|
|
708
727
|
export const compileDraft = (ctx, file, raw) => {
|
|
709
728
|
const known = ctx.docs.find((d) => d.file === file);
|
|
710
729
|
const previews = ctx.previews;
|
|
711
|
-
const
|
|
730
|
+
const manifest = ctx.root ? readManifest(ctx.root) : undefined;
|
|
731
|
+
const origin = known ? known.origin : manifest && sourceOrigin(manifest, file);
|
|
732
|
+
const parsed = resolveFiles(parseFile(raw, previews, file, origin), ctx.root, ctx.textfiles, previews, undefined, manifest);
|
|
712
733
|
const doc = toDoc(known?.id ?? "", known?.parent, file, parsed, ctx.defaultLang ?? DEFAULT_LANG, known?.title);
|
|
713
734
|
if (known)
|
|
714
735
|
Object.assign(doc, {
|
|
@@ -125,7 +125,7 @@ export const collectRefs = (root, settings) => {
|
|
|
125
125
|
for (const image of embeddedImages(root)) {
|
|
126
126
|
try {
|
|
127
127
|
const { file, kind } = parseFileEmbed(image.url, settings);
|
|
128
|
-
if (formatReference(file) !== undefined)
|
|
128
|
+
if (kind === "toc" || formatReference(file) !== undefined)
|
|
129
129
|
continue;
|
|
130
130
|
if (kind === "textfile")
|
|
131
131
|
textfiles.push(file);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type StructuredPatchHunk } from "diff";
|
|
2
|
+
export declare const diffHash: (value: string | Buffer) => string;
|
|
3
|
+
export interface DiffFile {
|
|
4
|
+
data: Buffer;
|
|
5
|
+
hash: string;
|
|
6
|
+
mode: string;
|
|
7
|
+
link?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface DiffSnapshot {
|
|
10
|
+
files: Map<string, DiffFile>;
|
|
11
|
+
contentHash: string;
|
|
12
|
+
}
|
|
13
|
+
export interface DiffEndpoint {
|
|
14
|
+
selector: string;
|
|
15
|
+
revision: string;
|
|
16
|
+
version?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const compareDocuments: (manifest: string, from: DiffEndpoint, before: DiffSnapshot, to: DiffEndpoint, after: DiffSnapshot) => {
|
|
19
|
+
schemaVersion: number;
|
|
20
|
+
comparisonId: string;
|
|
21
|
+
coverage: string;
|
|
22
|
+
scope: {
|
|
23
|
+
manifest: string;
|
|
24
|
+
};
|
|
25
|
+
from: {
|
|
26
|
+
contentHash: string;
|
|
27
|
+
selector: string;
|
|
28
|
+
revision: string;
|
|
29
|
+
version?: string;
|
|
30
|
+
};
|
|
31
|
+
to: {
|
|
32
|
+
contentHash: string;
|
|
33
|
+
selector: string;
|
|
34
|
+
revision: string;
|
|
35
|
+
version?: string;
|
|
36
|
+
};
|
|
37
|
+
changes: {
|
|
38
|
+
kind: string;
|
|
39
|
+
fromPath: string | null;
|
|
40
|
+
toPath: string | null;
|
|
41
|
+
binary: boolean;
|
|
42
|
+
hunks: StructuredPatchHunk[];
|
|
43
|
+
beforeHash: string | null;
|
|
44
|
+
afterHash: string | null;
|
|
45
|
+
beforeBytes: number;
|
|
46
|
+
afterBytes: number;
|
|
47
|
+
beforeMode: string | null;
|
|
48
|
+
afterMode: string | null;
|
|
49
|
+
beforeLink: string | undefined;
|
|
50
|
+
afterLink: string | undefined;
|
|
51
|
+
}[];
|
|
52
|
+
};
|
|
53
|
+
export type DocumentDiff = ReturnType<typeof compareDocuments>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { structuredPatch } from "diff";
|
|
2
|
+
import { fileExtension } from "../core/files.js";
|
|
3
|
+
import { FORMAT_TRAITS } from "../core/format-collections.js";
|
|
4
|
+
import { createHash } from "./host.js";
|
|
5
|
+
export const diffHash = (value) => createHash("sha256").update(value).digest("hex");
|
|
6
|
+
const text = (file, path) => {
|
|
7
|
+
if (!file)
|
|
8
|
+
return "";
|
|
9
|
+
const ext = fileExtension(path);
|
|
10
|
+
if (file.data.includes(0) ||
|
|
11
|
+
(FORMAT_TRAITS.media?.includes(ext) && ext !== "svg" && ext !== "dxf") ||
|
|
12
|
+
["bin", "zip", "woff", "woff2", "ttf", "otf"].includes(ext))
|
|
13
|
+
return null;
|
|
14
|
+
try {
|
|
15
|
+
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(file.data);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/** Only a unique identical-content pair can be reported as a rename. */
|
|
22
|
+
const unmatched = (one, other) => {
|
|
23
|
+
const paths = new Map();
|
|
24
|
+
for (const [path, file] of one.files)
|
|
25
|
+
if (!other.files.has(path))
|
|
26
|
+
paths.set(file.hash, paths.has(file.hash) ? null : path);
|
|
27
|
+
return paths;
|
|
28
|
+
};
|
|
29
|
+
export const compareDocuments = (manifest, from, before, to, after) => {
|
|
30
|
+
const removed = unmatched(before, after);
|
|
31
|
+
const added = unmatched(after, before);
|
|
32
|
+
const paths = [...new Set([...before.files.keys(), ...after.files.keys()])].sort();
|
|
33
|
+
const changes = [];
|
|
34
|
+
for (const path of paths) {
|
|
35
|
+
const old = before.files.get(path);
|
|
36
|
+
const current = after.files.get(path);
|
|
37
|
+
if (old &&
|
|
38
|
+
current &&
|
|
39
|
+
old.hash === current.hash &&
|
|
40
|
+
old.mode === current.mode &&
|
|
41
|
+
old.link === current.link)
|
|
42
|
+
continue;
|
|
43
|
+
if (!old && current && added.get(current.hash) === path && removed.get(current.hash))
|
|
44
|
+
continue;
|
|
45
|
+
const rename = old && !current && removed.get(old.hash) === path ? added.get(old.hash) : undefined;
|
|
46
|
+
const next = rename ? after.files.get(rename) : current;
|
|
47
|
+
const fromPath = old ? path : null;
|
|
48
|
+
const toPath = rename || (next ? path : null);
|
|
49
|
+
const kind = rename ? "renamed" : !old ? "added" : !next ? "deleted" : "modified";
|
|
50
|
+
const left = text(old, path);
|
|
51
|
+
const right = text(next, toPath ?? path);
|
|
52
|
+
const binary = left === null || right === null;
|
|
53
|
+
let hunks = [];
|
|
54
|
+
if (!binary && old?.hash !== next?.hash) {
|
|
55
|
+
const patch = structuredPatch(fromPath ?? "/dev/null", toPath ?? "/dev/null", left, right, undefined, undefined, { context: 3, timeout: 3000 });
|
|
56
|
+
if (!patch)
|
|
57
|
+
throw new Error(`Text comparison timed out: ${path}`);
|
|
58
|
+
hunks = patch.hunks;
|
|
59
|
+
}
|
|
60
|
+
changes.push({
|
|
61
|
+
kind,
|
|
62
|
+
fromPath,
|
|
63
|
+
toPath,
|
|
64
|
+
binary,
|
|
65
|
+
hunks,
|
|
66
|
+
beforeHash: old?.hash ?? null,
|
|
67
|
+
afterHash: next?.hash ?? null,
|
|
68
|
+
beforeBytes: old?.data.length ?? 0,
|
|
69
|
+
afterBytes: next?.data.length ?? 0,
|
|
70
|
+
beforeMode: old?.mode ?? null,
|
|
71
|
+
afterMode: next?.mode ?? null,
|
|
72
|
+
beforeLink: old?.link,
|
|
73
|
+
afterLink: next?.link,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
schemaVersion: 1,
|
|
78
|
+
comparisonId: diffHash(JSON.stringify([
|
|
79
|
+
1,
|
|
80
|
+
manifest,
|
|
81
|
+
from.revision,
|
|
82
|
+
before.contentHash,
|
|
83
|
+
to.revision,
|
|
84
|
+
after.contentHash,
|
|
85
|
+
])),
|
|
86
|
+
coverage: "changes",
|
|
87
|
+
scope: { manifest },
|
|
88
|
+
from: { ...from, contentHash: before.contentHash },
|
|
89
|
+
to: { ...to, contentHash: after.contentHash },
|
|
90
|
+
changes,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
@@ -5,6 +5,7 @@ import { formatReference, parseFormatQuery } from "../core/format-collections.js
|
|
|
5
5
|
import { contentLinks, parseMdast } from "../core/markdown.js";
|
|
6
6
|
import { visitSchema } from "../core/schema-refs.js";
|
|
7
7
|
import { isRemoteTextfile, parseFileReference } from "../core/textfile.js";
|
|
8
|
+
import { tocReference } from "../core/toc-library.js";
|
|
8
9
|
import { assetReferences } from "./asset-references.js";
|
|
9
10
|
import { CODE_LANGUAGES_DIR } from "./code-languages.js";
|
|
10
11
|
import { CONFIG_FILE } from "./config.js";
|
|
@@ -16,8 +17,9 @@ import { formatFiles } from "./format-files.js";
|
|
|
16
17
|
import { existsSync, fileURLToPath, pathToFileURL, posix, readdirSync, readFileSync, realpathSync, relative as relativePath, statSync, } from "./host.js";
|
|
17
18
|
import { assertNotIgnored, ignoredFiles } from "./ignored-files.js";
|
|
18
19
|
import { siteContentLanguages, translationFile } from "./locales.js";
|
|
19
|
-
import { manifestFile, readManifest, sourceOrigin } from "./manifest.js";
|
|
20
|
+
import { hasContentsSource, manifestFile, readManifest, sourceOrigin } from "./manifest.js";
|
|
20
21
|
import { readProjectSkills } from "./skills.js";
|
|
22
|
+
import { recordSubformat } from "./subformats.js";
|
|
21
23
|
import { readTextfile, textfilePath } from "./textfile.js";
|
|
22
24
|
import { siteThemes, themeVariants } from "./theme-variants.js";
|
|
23
25
|
import { zip } from "./zip.js";
|
|
@@ -103,7 +105,7 @@ export const exportEntries = (root, file = manifestFile(root)) => {
|
|
|
103
105
|
if (format.icon)
|
|
104
106
|
add(format.icon);
|
|
105
107
|
for (const file of files)
|
|
106
|
-
if (file.
|
|
108
|
+
if (recordSubformat(root, manifest, file.path)?.ext === format.ext)
|
|
107
109
|
add(file.path);
|
|
108
110
|
}
|
|
109
111
|
for (const dir of [PROJECT_FONTS_DIR, CODE_LANGUAGES_DIR, ".dooc/editor-tools"]) {
|
|
@@ -175,7 +177,13 @@ export const exportEntries = (root, file = manifestFile(root)) => {
|
|
|
175
177
|
for (const record of readFormatCollection(root, selector, parseFormatQuery(ref.query ?? "")).records)
|
|
176
178
|
add(record.file, origin);
|
|
177
179
|
};
|
|
178
|
-
visit(tree, "image", (node) =>
|
|
180
|
+
visit(tree, "image", (node) => {
|
|
181
|
+
const contents = tocReference(node.url);
|
|
182
|
+
if (!contents)
|
|
183
|
+
reference(node.url);
|
|
184
|
+
else if (!hasContentsSource(manifest, file, contents.file))
|
|
185
|
+
throw new Error(`Table of contents source is not in this document: ${contents.file}`);
|
|
186
|
+
});
|
|
179
187
|
for (const link of contentLinks(tree))
|
|
180
188
|
reference(link.url);
|
|
181
189
|
}
|
|
@@ -9,10 +9,11 @@ import { docPath } from "../core/routing.js";
|
|
|
9
9
|
import { termFileUrl } from "../core/term-reference.js";
|
|
10
10
|
import { isRemoteTextfile, parseFileReference } from "../core/textfile.js";
|
|
11
11
|
import { themeVariantFile } from "../core/theme-variants.js";
|
|
12
|
+
import { tocReference, tocUrl } from "../core/toc-library.js";
|
|
12
13
|
import { assetReferences } from "./asset-references.js";
|
|
13
14
|
import { fileSig } from "./file-cache.js";
|
|
14
|
-
import { createHash, dirname, existsSync, join, linkSync, mkdirSync, posix, randomUUID, readdirSync, readFileSync, rmdirSync, rmSync, statSync, unlinkSync, writeFileSync, } from "./host.js";
|
|
15
|
-
import { ignoredFiles, withinRead } from "./ignored-files.js";
|
|
15
|
+
import { createHash, dirname, existsSync, join, linkSync, mkdirSync, posix, randomUUID, readdirSync, readFileSync, realpathSync, rmdirSync, rmSync, statSync, unlinkSync, writeFileSync, } from "./host.js";
|
|
16
|
+
import { assertNotIgnored, ignoredFiles, withinRead } from "./ignored-files.js";
|
|
16
17
|
import { translationFile, translationFiles, translationLanguages } from "./locales.js";
|
|
17
18
|
import { manifestFile, parseManifestText, readManifest, sourceOrigin } from "./manifest.js";
|
|
18
19
|
import { isRemoteSourceFile } from "./remote-manifests.js";
|
|
@@ -24,6 +25,26 @@ const reserved = new Set(["docs.config.mjs", "node_modules", "build", "dist", "l
|
|
|
24
25
|
export const managedFile = (file) => localFile(file) &&
|
|
25
26
|
!isManifestFile(file.split("/")[0] ?? "") &&
|
|
26
27
|
!reserved.has(file.split("/")[0] ?? "");
|
|
28
|
+
export const projectFilePath = (root, file) => {
|
|
29
|
+
if (!managedFile(file))
|
|
30
|
+
throw new Error("Expected a relative project path");
|
|
31
|
+
const path = textfilePath(root, file);
|
|
32
|
+
if (path !== join(realpathSync(root), file))
|
|
33
|
+
throw new Error("Choose a path without symlinks");
|
|
34
|
+
assertNotIgnored(root, file);
|
|
35
|
+
return path;
|
|
36
|
+
};
|
|
37
|
+
const checkedDirectory = (root, directory) => {
|
|
38
|
+
if (directory === "." || directory === "")
|
|
39
|
+
return "";
|
|
40
|
+
if (typeof directory !== "string")
|
|
41
|
+
throw new Error("Expected a relative project directory");
|
|
42
|
+
const path = projectFilePath(root, directory);
|
|
43
|
+
assertNotIgnored(root, `${directory}/`);
|
|
44
|
+
if (existsSync(path) && !statSync(path).isDirectory())
|
|
45
|
+
throw new Error("Expected a directory");
|
|
46
|
+
return directory;
|
|
47
|
+
};
|
|
27
48
|
const names = new Intl.Collator("en", { numeric: true });
|
|
28
49
|
const compareFilePaths = (a, b) => {
|
|
29
50
|
const left = a.split("/");
|
|
@@ -124,23 +145,40 @@ export const uploadFile = (root, input) => {
|
|
|
124
145
|
const manifest = readManifest(root);
|
|
125
146
|
if (manifest.errors.length)
|
|
126
147
|
throw new Error(manifest.errors.join("\n"));
|
|
127
|
-
const
|
|
148
|
+
const directory = checkedDirectory(root, input.directory ?? manifest.files?.uploadDirectory ?? "");
|
|
149
|
+
const initial = posix.join(directory, input.name);
|
|
128
150
|
const extension = posix.extname(initial);
|
|
129
151
|
const stem = initial.slice(0, initial.length - extension.length);
|
|
130
|
-
let
|
|
131
|
-
for (let index = 2; existsSync(textfilePath(root, file)); index++)
|
|
132
|
-
file = `${stem}-${index}${extension}`;
|
|
133
|
-
const path = textfilePath(root, file);
|
|
134
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
135
|
-
const temp = join(dirname(path), `.upload-${randomUUID()}.tmp`);
|
|
152
|
+
let temp;
|
|
136
153
|
try {
|
|
137
|
-
|
|
138
|
-
|
|
154
|
+
for (let index = 1;; index++) {
|
|
155
|
+
const file = index === 1 ? initial : `${stem}-${index}${extension}`;
|
|
156
|
+
const path = projectFilePath(root, file);
|
|
157
|
+
if (!existsSync(path)) {
|
|
158
|
+
if (!temp) {
|
|
159
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
160
|
+
temp = join(dirname(path), `.upload-${randomUUID()}.tmp`);
|
|
161
|
+
writeFileSync(temp, data, { flag: "wx" });
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
linkSync(temp, path);
|
|
165
|
+
return { file };
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (error.code !== "EEXIST")
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const existing = projectFilePath(root, file);
|
|
173
|
+
const stat = statSync(existing);
|
|
174
|
+
if (stat.isFile() && stat.size === data.length && readFileSync(existing).equals(data))
|
|
175
|
+
return { file };
|
|
176
|
+
}
|
|
139
177
|
}
|
|
140
178
|
finally {
|
|
141
|
-
|
|
179
|
+
if (temp)
|
|
180
|
+
rmSync(temp, { force: true });
|
|
142
181
|
}
|
|
143
|
-
return { file };
|
|
144
182
|
};
|
|
145
183
|
const imageDestination = (source) => {
|
|
146
184
|
let depth = 0;
|
|
@@ -277,6 +315,8 @@ const rewriteManifestPaths = (manifest, moves) => {
|
|
|
277
315
|
if (record)
|
|
278
316
|
for (const [id, file] of Object.entries(record))
|
|
279
317
|
record[id] = rewrite(file);
|
|
318
|
+
if (manifest.files?.uploadDirectory && manifest.files.uploadDirectory !== ".")
|
|
319
|
+
manifest.files.uploadDirectory = rewrite(manifest.files.uploadDirectory);
|
|
280
320
|
if (manifest.icon)
|
|
281
321
|
manifest.icon = rewrite(manifest.icon);
|
|
282
322
|
if (manifest.licence)
|
|
@@ -299,12 +339,17 @@ const rewriteManifestPaths = (manifest, moves) => {
|
|
|
299
339
|
}
|
|
300
340
|
for (const format of manifest.subformats ?? []) {
|
|
301
341
|
format.schema = rewrite(format.schema);
|
|
342
|
+
if (format.files)
|
|
343
|
+
format.files = format.files.map(rewrite);
|
|
302
344
|
if (format.icon)
|
|
303
345
|
format.icon = rewrite(format.icon);
|
|
304
346
|
}
|
|
305
347
|
const visit = (nodes) => {
|
|
306
348
|
for (const node of nodes) {
|
|
307
|
-
|
|
349
|
+
const contents = node.url && tocReference(node.url);
|
|
350
|
+
if (contents)
|
|
351
|
+
node.url = tocUrl(rewrite(contents.file), contents.recursive);
|
|
352
|
+
else if (node.url && ["manifest", "file"].includes(pageUrlKind(node.url)))
|
|
308
353
|
node.url = rewrite(node.url);
|
|
309
354
|
visit(node.children);
|
|
310
355
|
}
|
|
@@ -317,6 +362,20 @@ export const updateFiles = (root, input) => {
|
|
|
317
362
|
if (input.revision !== snapshot.revision)
|
|
318
363
|
throw new Error("Files changed. Reload before retrying.");
|
|
319
364
|
const manifest = readManifest(root);
|
|
365
|
+
if (input.action === "directory") {
|
|
366
|
+
const directory = checkedDirectory(root, input.directory);
|
|
367
|
+
const file = manifestFile(root);
|
|
368
|
+
const raw = existsSync(join(root, file)) ? readTextfile(root, file) : null;
|
|
369
|
+
const parsed = parseDocument(raw ?? "docs: []\n");
|
|
370
|
+
const yaml = isSeq(parsed.contents) ? new Document({ docs: parsed.toJS() }) : parsed;
|
|
371
|
+
const key = manifest.format
|
|
372
|
+
? ["system", "files", "upload_directory"]
|
|
373
|
+
: ["files", "uploadDirectory"];
|
|
374
|
+
yaml.setIn(key, directory || ".");
|
|
375
|
+
if (!writeTextfile(root, file, yaml.toString(), raw))
|
|
376
|
+
throw new Error("Manifest changed. Reload before retrying.");
|
|
377
|
+
return filesSnapshot(root);
|
|
378
|
+
}
|
|
320
379
|
const layout = snapshot.layout;
|
|
321
380
|
const paths = snapshot.files.map((file) => file.path);
|
|
322
381
|
const skillManifests = new Map([
|
|
@@ -474,6 +533,8 @@ export const updateFiles = (root, input) => {
|
|
|
474
533
|
const schemaWrites = rewriteSchemaFiles(root, (manifest.subformats ?? []).map((subformat) => subformat.schema), paths, moves);
|
|
475
534
|
for (const subformat of manifest.subformats ?? []) {
|
|
476
535
|
subformat.schema = moves.get(subformat.schema) ?? subformat.schema;
|
|
536
|
+
if (subformat.files)
|
|
537
|
+
subformat.files = subformat.files.map((file) => moves.get(file) ?? file);
|
|
477
538
|
if (subformat.icon)
|
|
478
539
|
subformat.icon = moves.get(subformat.icon) ?? subformat.icon;
|
|
479
540
|
}
|
|
@@ -68,7 +68,18 @@ export const toBlocks = (root, raw, settings, file) => {
|
|
|
68
68
|
add({ type: "p", text: inlineToText(n.children) });
|
|
69
69
|
for (const image of images) {
|
|
70
70
|
try {
|
|
71
|
-
const { file, range, tableMode, kind, embed } = parseFileEmbed(image.url, settings);
|
|
71
|
+
const { file, range, tableMode, kind, embed, recursive } = parseFileEmbed(image.url, settings);
|
|
72
|
+
if (kind === "toc") {
|
|
73
|
+
add({
|
|
74
|
+
type: "pageContents",
|
|
75
|
+
file,
|
|
76
|
+
recursive: recursive ?? true,
|
|
77
|
+
title: image.alt || undefined,
|
|
78
|
+
});
|
|
79
|
+
if (topLevel)
|
|
80
|
+
lines[lines.length - 1] = image.position?.start.line ?? 1;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
72
83
|
if (kind === "external") {
|
|
73
84
|
add({
|
|
74
85
|
type: "external",
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { ParsedManifest } from "../core/content-metadata.js";
|
|
2
2
|
import { type FileLayout } from "../core/files.js";
|
|
3
|
+
import { squareSvg } from "../core/icons.js";
|
|
4
|
+
export { squareSvg };
|
|
3
5
|
export declare const ICONS_DIR = "icons";
|
|
4
6
|
/** Only implicit, unshared icon files belong to a page's lifecycle. */
|
|
5
7
|
export declare const ownsDocIcon: (id: string, manifest: ParsedManifest) => boolean;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
export declare const squareSvg: (svg: string) => string | undefined;
|
|
8
|
+
export declare const projectIcon: (root: string, file: unknown) => string;
|
|
9
|
+
export declare const siteIconAssets: (root: string, manifest: ParsedManifest, themes?: string[]) => {
|
|
10
|
+
icon?: string;
|
|
11
|
+
iconVariants?: Record<string, string>;
|
|
12
|
+
};
|
|
13
13
|
/** Read icons/ (docId → svg markup). An icon with no doc is an error (missed rename / delete). */
|
|
14
14
|
export declare const loadIcons: (root: string, docIds: ReadonlySet<string>, siteIconFile?: string, layout?: FileLayout, siteIcons?: readonly string[]) => {
|
|
15
15
|
icons: Map<string, string>;
|