@dooc-dev/dooc 0.0.27 → 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/format-collections.js +8 -2
- 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 +9 -5
- 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 +403 -189
- 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/build.js +11 -8
- package/dist/server/cli.js +18 -1
- 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 +241 -197
- package/package.json +2 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const fileOperation: (root: string, input: Record<string, unknown>) => Promise<string | string[] | Record<string, string> | {
|
|
2
|
+
file: string;
|
|
3
|
+
} | {
|
|
4
|
+
files: import("../engine/compiler/files.js").ProjectFile[];
|
|
5
|
+
layout: import("../engine/core/files.js").FileLayout;
|
|
6
|
+
revision: string;
|
|
7
|
+
documents: {
|
|
8
|
+
[k: string]: string;
|
|
9
|
+
};
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { completeFilePaths, filesSnapshot, projectFilePath, updateFiles, uploadFile, } from "../engine/compiler/files.js";
|
|
2
|
+
import { createHash, open, statSync } from "../engine/compiler/host.js";
|
|
3
|
+
import { projectIcon } from "../engine/compiler/icons.js";
|
|
4
|
+
export const fileOperation = async (root, input) => {
|
|
5
|
+
switch (input.action) {
|
|
6
|
+
case "read":
|
|
7
|
+
return filesSnapshot(root);
|
|
8
|
+
case "complete":
|
|
9
|
+
return completeFilePaths(root, input.prefix);
|
|
10
|
+
case "hashes": {
|
|
11
|
+
if (!Array.isArray(input.paths))
|
|
12
|
+
throw new Error("Expected file paths");
|
|
13
|
+
const hashes = Object.create(null);
|
|
14
|
+
const buffer = new Uint8Array(256 * 1024);
|
|
15
|
+
for (const file of new Set(input.paths)) {
|
|
16
|
+
if (typeof file !== "string")
|
|
17
|
+
throw new Error("Expected a file path");
|
|
18
|
+
const path = projectFilePath(root, file);
|
|
19
|
+
if (!statSync(path).isFile())
|
|
20
|
+
throw new Error("Expected a regular file");
|
|
21
|
+
const handle = await open(path, "r");
|
|
22
|
+
try {
|
|
23
|
+
if (!(await handle.stat()).isFile())
|
|
24
|
+
throw new Error("Expected a regular file");
|
|
25
|
+
const digest = createHash("sha256");
|
|
26
|
+
for (;;) {
|
|
27
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, null);
|
|
28
|
+
if (!bytesRead)
|
|
29
|
+
break;
|
|
30
|
+
digest.update(buffer.subarray(0, bytesRead));
|
|
31
|
+
}
|
|
32
|
+
hashes[file] = digest.digest("hex");
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
await handle.close();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return hashes;
|
|
39
|
+
}
|
|
40
|
+
case "icon-preview":
|
|
41
|
+
return `data:image/svg+xml;base64,${Buffer.from(projectIcon(root, input.file)).toString("base64")}`;
|
|
42
|
+
case "upload":
|
|
43
|
+
return uploadFile(root, input);
|
|
44
|
+
default:
|
|
45
|
+
return updateFiles(root, input);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -74,14 +74,18 @@ const definitions = {
|
|
|
74
74
|
required: ["file", "content", "base"],
|
|
75
75
|
},
|
|
76
76
|
upload_file: {
|
|
77
|
-
description: "Import a binary or text file from base64 data
|
|
78
|
-
props: {
|
|
77
|
+
description: "Import a binary or text file from base64 data into a chosen directory, the registered upload directory, or the project root. Identical destination files are reused and name collisions are preserved. Maximum 64 MiB.",
|
|
78
|
+
props: {
|
|
79
|
+
name: str,
|
|
80
|
+
directory: str,
|
|
81
|
+
data: { ...str, description: "Canonical base64 file bytes" },
|
|
82
|
+
},
|
|
79
83
|
required: ["name", "data"],
|
|
80
84
|
},
|
|
81
85
|
update_files: {
|
|
82
|
-
description: "Rename a file (file, name), move files/folders (paths, directory), change automatic layout (enabled), or restructure by extension. Updates document references and variants. Requires revision from list_files.",
|
|
86
|
+
description: "Rename a file (file, name), move files/folders (paths, directory), register an upload directory (action directory), change automatic layout (enabled), or restructure by extension. Updates document references and variants. Requires revision from list_files.",
|
|
83
87
|
props: {
|
|
84
|
-
action: { ...str, enum: ["rename", "move", "layout", "restructure"] },
|
|
88
|
+
action: { ...str, enum: ["rename", "move", "layout", "directory", "restructure"] },
|
|
85
89
|
revision: str,
|
|
86
90
|
file: str,
|
|
87
91
|
name: str,
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import { Document, isSeq, parseDocument } from "yaml";
|
|
1
|
+
import { Document, isScalar, isSeq, parseDocument } from "yaml";
|
|
2
2
|
import { existsSync } from "../engine/compiler/host.js";
|
|
3
|
-
import { ICONS_DIR, squareSvg } from "../engine/compiler/icons.js";
|
|
3
|
+
import { ICONS_DIR, projectIcon, squareSvg } from "../engine/compiler/icons.js";
|
|
4
4
|
import { manifestFile, parseManifestText } from "../engine/compiler/manifest.js";
|
|
5
5
|
import { readTextfile, textfilePath, writeTextfile } from "../engine/compiler/textfile.js";
|
|
6
6
|
import { migrateDocumentIcon } from "../engine/core/content-metadata.js";
|
|
7
7
|
import { defaultFilePath } from "../engine/core/files.js";
|
|
8
8
|
export const siteIconResponse = (root, input) => {
|
|
9
|
-
const svg = typeof input?.data === "string"
|
|
10
|
-
? squareSvg(Buffer.from(input.data, "base64").toString("utf8"))
|
|
11
|
-
: undefined;
|
|
12
|
-
if (!svg)
|
|
13
|
-
return {
|
|
14
|
-
status: 400,
|
|
15
|
-
body: { error: "specify an svg (viewBox or width / height required)" },
|
|
16
|
-
};
|
|
17
9
|
try {
|
|
10
|
+
const reference = input?.path;
|
|
11
|
+
const svg = reference !== undefined
|
|
12
|
+
? projectIcon(root, reference)
|
|
13
|
+
: typeof input?.data === "string"
|
|
14
|
+
? squareSvg(Buffer.from(input.data, "base64").toString("utf8"))
|
|
15
|
+
: undefined;
|
|
16
|
+
if (!svg)
|
|
17
|
+
return {
|
|
18
|
+
status: 400,
|
|
19
|
+
body: { error: "specify an svg (viewBox or width / height required)" },
|
|
20
|
+
};
|
|
18
21
|
const raw = existsSync(textfilePath(root, manifestFile(root)))
|
|
19
22
|
? readTextfile(root, manifestFile(root))
|
|
20
23
|
: null;
|
|
@@ -30,31 +33,35 @@ export const siteIconResponse = (root, input) => {
|
|
|
30
33
|
? manifest.icon
|
|
31
34
|
: undefined))
|
|
32
35
|
: manifest.icon;
|
|
33
|
-
const file =
|
|
36
|
+
const file = (typeof reference === "string" ? reference : undefined) ??
|
|
37
|
+
configured ??
|
|
34
38
|
(manifest.files?.defaultLayout !== false
|
|
35
39
|
? defaultFilePath(manifest.format !== undefined ? `_site-${theme}.svg` : "_site.svg")
|
|
36
40
|
: `${ICONS_DIR}/_site${manifest.format !== undefined ? `-${theme}` : ""}.svg`);
|
|
37
|
-
if (!configured && existsSync(textfilePath(root, file)))
|
|
41
|
+
if (reference === undefined && !configured && existsSync(textfilePath(root, file)))
|
|
38
42
|
return {
|
|
39
43
|
status: 409,
|
|
40
44
|
body: { error: `${file} already exists; set dooc.yaml's icon to use it` },
|
|
41
45
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
if (reference === undefined) {
|
|
47
|
+
const base = existsSync(textfilePath(root, file)) ? readTextfile(root, file) : null;
|
|
48
|
+
if (!writeTextfile(root, file, svg, base))
|
|
49
|
+
return { status: 409, body: { error: "Icon changed externally. Try again." } };
|
|
50
|
+
}
|
|
45
51
|
const parsed = parseDocument(raw ?? "docs: []\n");
|
|
46
52
|
const document = isSeq(parsed.contents) || parsed.contents == null
|
|
47
53
|
? new Document({ docs: parsed.toJS() ?? [] })
|
|
48
54
|
: parsed;
|
|
49
55
|
const migrated = migrateDocumentIcon(document);
|
|
50
|
-
if (
|
|
51
|
-
if (
|
|
52
|
-
document
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
], file);
|
|
57
|
-
|
|
56
|
+
if (configured !== file || migrated) {
|
|
57
|
+
if (configured !== file && manifest.format !== undefined) {
|
|
58
|
+
const key = [manifest.format === "document" ? "document" : "left_sidebar", "icon"];
|
|
59
|
+
const previous = document.getIn(key, true);
|
|
60
|
+
if (isScalar(previous) && typeof previous.value === "string")
|
|
61
|
+
document.setIn(key, document.createNode({ light: previous, dark: previous.clone() }));
|
|
62
|
+
document.setIn([...key, theme], file);
|
|
63
|
+
}
|
|
64
|
+
else if (configured !== file)
|
|
58
65
|
document.set("icon", file);
|
|
59
66
|
if (!writeTextfile(root, manifestFile(root), document.toString(), raw))
|
|
60
67
|
return { status: 409, body: { error: "Manifest changed externally. Try again." } };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseDocument } from "yaml";
|
|
2
2
|
import { parseManifestText, readManifest } from "../engine/compiler/manifest.js";
|
|
3
|
-
import { compileSubformatSchema, isSubformatSchemaFile, validateSubformatFile, } from "../engine/compiler/subformats.js";
|
|
3
|
+
import { compileSubformatSchema, isSubformatSchemaFile, recordSubformat, validateSubformatFile, } from "../engine/compiler/subformats.js";
|
|
4
4
|
import { readTextfile, readTextfileAsync, textfilePath, writeTextfile, } from "../engine/compiler/textfile.js";
|
|
5
5
|
import { TextfileUnavailable } from "../engine/compiler/textfile-remote.js";
|
|
6
6
|
import { isManifestFile, migrateDocumentIcon } from "../engine/core/content-metadata.js";
|
|
@@ -49,9 +49,12 @@ export const textfileResponse = async (root, input, domains = []) => {
|
|
|
49
49
|
};
|
|
50
50
|
return { status: 200, body: { content } };
|
|
51
51
|
}
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const format =
|
|
52
|
+
const schemaDocument = !isRemoteTextfile(input.file) && isSubformatSchemaFile(root, input.file, domains);
|
|
53
|
+
const manifest = isRemoteTextfile(input.file) || schemaDocument ? undefined : readManifest(root);
|
|
54
|
+
const format = manifest &&
|
|
55
|
+
(typeof input.recordType === "string"
|
|
56
|
+
? manifest.subformats?.find((type) => type.ext === input.recordType)
|
|
57
|
+
: recordSubformat(root, manifest, input.file, domains));
|
|
55
58
|
const compiled = format
|
|
56
59
|
? compileSubformatSchema(readTextfile(root, format.schema), {
|
|
57
60
|
root,
|
|
@@ -76,10 +79,7 @@ export const textfileResponse = async (root, input, domains = []) => {
|
|
|
76
79
|
schemaContext: compiled?.context,
|
|
77
80
|
}
|
|
78
81
|
: {}),
|
|
79
|
-
...(
|
|
80
|
-
isSubformatSchemaFile(root, input.file, domains)
|
|
81
|
-
? { schemaDocument: true }
|
|
82
|
-
: {}),
|
|
82
|
+
...(schemaDocument ? { schemaDocument: true } : {}),
|
|
83
83
|
},
|
|
84
84
|
};
|
|
85
85
|
}
|