@dooc-dev/dooc 0.0.5 → 0.0.6
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 +128 -67
- package/dist/code-worker.global.js +152 -0
- package/dist/code.global.js +101 -101
- package/dist/compiler/bundle-urls.js +2 -0
- package/dist/compiler/check.js +2 -0
- package/dist/compiler/compile.js +13 -3
- package/dist/compiler/dxf.d.ts +1 -0
- package/dist/compiler/dxf.js +81 -0
- package/dist/compiler/export.js +22 -15
- package/dist/compiler/figures.js +39 -10
- package/dist/compiler/files.js +2 -0
- package/dist/compiler/ignored-files.d.ts +2 -0
- package/dist/compiler/ignored-files.js +30 -0
- package/dist/compiler/ops.js +1 -1
- package/dist/compiler/subformat-schema.d.ts +14 -0
- package/dist/compiler/subformat-schema.js +92 -0
- package/dist/compiler/subformats.d.ts +5 -7
- package/dist/compiler/subformats.js +115 -75
- package/dist/core/code-file.js +7 -5
- package/dist/core/code-grammars.d.ts +5 -0
- package/dist/core/code-grammars.js +34 -0
- package/dist/core/content-metadata.d.ts +2 -1
- package/dist/core/content-metadata.js +7 -2
- package/dist/core/content-types.d.ts +1 -1
- package/dist/core/escape-html.d.ts +1 -0
- package/dist/core/escape-html.js +1 -0
- package/dist/core/figure-frame.js +1 -1
- package/dist/core/file-embed.js +7 -3
- package/dist/core/html.d.ts +4 -1
- package/dist/core/html.js +8 -7
- package/dist/core/language.js +5 -2
- package/dist/core/markdown.js +3 -1
- package/dist/core/previewers.d.ts +8 -0
- package/dist/core/previewers.js +2 -0
- package/dist/core/schema-fields.d.ts +13 -0
- package/dist/core/schema-fields.js +175 -0
- package/dist/core/schema-graph-mount.js +26 -3
- package/dist/core/schema-refs.d.ts +8 -0
- package/dist/core/schema-refs.js +82 -0
- package/dist/core/toc-ui.js +1 -1
- package/dist/edit.global.js +266 -285
- package/dist/flow.global.js +3 -3
- package/dist/graph/abnfDiagram-S7VZAUFO-ASBULSKE.js +1 -0
- package/dist/graph/architecture-WOLXFQ4H-V57EDXXY.js +1 -0
- package/dist/graph/architectureDiagram-YGSQEFNW-GIMP347N.js +36 -0
- package/dist/graph/blockDiagram-APKKGZFW-RDL2T4JW.js +140 -0
- package/dist/graph/bpmnIcons-APHXDYXF-TWOSQNUQ.js +1 -0
- package/dist/graph/c4Diagram-KJ2TOQU5-75LIUC4F.js +38 -0
- package/dist/graph/chunk-26TUJSYJ.js +1 -0
- package/dist/graph/chunk-3LU66YMI.js +1 -0
- package/dist/graph/chunk-3RNHDNP5.js +1 -0
- package/dist/graph/chunk-3Y2PDVDE.js +1 -0
- package/dist/graph/chunk-3YJHMOOA.js +3 -0
- package/dist/graph/chunk-4KILFWYV.js +339 -0
- package/dist/graph/chunk-4QDE4SUK.js +1 -0
- package/dist/graph/chunk-5OO6DATX.js +1 -0
- package/dist/graph/chunk-5UUEAHTN.js +1 -0
- package/dist/graph/chunk-6T55RVVR.js +1 -0
- package/dist/graph/chunk-ARAJTKOH.js +2 -0
- package/dist/graph/chunk-BBD5CEDC.js +72 -0
- package/dist/graph/chunk-BVXT562I.js +1 -0
- package/dist/graph/chunk-BZAMCJ6B.js +32 -0
- package/dist/graph/chunk-C6J4A356.js +15 -0
- package/dist/graph/chunk-EG5UVNOC.js +213 -0
- package/dist/graph/chunk-GF4TOPUK.js +1 -0
- package/dist/graph/chunk-GYT4IYBZ.js +1 -0
- package/dist/graph/chunk-HJG2HUYJ.js +88 -0
- package/dist/graph/chunk-HOPPTA6H.js +62 -0
- package/dist/graph/chunk-I3DMZIHV.js +1 -0
- package/dist/graph/chunk-IC23EEF6.js +1 -0
- package/dist/graph/chunk-ISO77HML.js +1 -0
- package/dist/graph/chunk-JD7ZBJD2.js +1 -0
- package/dist/graph/chunk-JRSH5GNS.js +1 -0
- package/dist/graph/chunk-JSHWCPFJ.js +1 -0
- package/dist/graph/chunk-K2KLZU7M.js +10 -0
- package/dist/graph/chunk-K4I76XBX.js +14 -0
- package/dist/graph/chunk-KT4VPQD5.js +135 -0
- package/dist/graph/chunk-KU6GTEMS.js +1 -0
- package/dist/graph/chunk-LT6LXKCR.js +136 -0
- package/dist/graph/chunk-MPR575IN.js +1 -0
- package/dist/graph/chunk-N3OHKGRZ.js +1 -0
- package/dist/graph/chunk-O656ZI37.js +1 -0
- package/dist/graph/chunk-OFZLK5G4.js +1 -0
- package/dist/graph/chunk-PDH25ALM.js +2 -0
- package/dist/graph/chunk-PW2RGZ3O.js +1 -0
- package/dist/graph/chunk-QCJUF4YA.js +1 -0
- package/dist/graph/chunk-QEEA3KYY.js +2 -0
- package/dist/graph/chunk-QYAXYFNI.js +1 -0
- package/dist/graph/chunk-QYTM6GY3.js +1 -0
- package/dist/graph/chunk-R63JUMUK.js +1 -0
- package/dist/graph/chunk-SCEY3ZPT.js +1 -0
- package/dist/graph/chunk-VM2H7G2R.js +1 -0
- package/dist/graph/chunk-XQS73SBQ.js +1 -0
- package/dist/graph/chunk-YCRLJT2S.js +1 -0
- package/dist/graph/chunk-Z4FIZ7CR.js +1 -0
- package/dist/graph/chunk-ZMCB7VP2.js +1 -0
- package/dist/graph/chunk-ZSZXN4BT.js +2 -0
- package/dist/graph/classDiagram-v2-L25IHNXF-JL7LVDZH.js +217 -0
- package/dist/graph/cose-bilkent-JH36ORCC-PNM3EYPB.js +1 -0
- package/dist/graph/cynefin-EF2NZ3EQ-PSXP3DXL.js +1 -0
- package/dist/graph/cynefinDiagram-L36ESFBY-QVY54CXO.js +62 -0
- package/dist/graph/dagre-SPEB5RXH-HPGQXBZJ.js +4 -0
- package/dist/graph/diagram-3B7GL73J-DWH5WS2P.js +200 -0
- package/dist/graph/diagram-DNEMPZML-TEGH2U5I.js +24 -0
- package/dist/graph/diagram-L3MUGCDN-X4MREUWR.js +41 -0
- package/dist/graph/diagram-LA4NIPWU-NXT746HG.js +24 -0
- package/dist/graph/diagram-MHCOC4E2-JGHXSAGS.js +3 -0
- package/dist/graph/diagram-XPFHEONP-ZHZPBLT4.js +30 -0
- package/dist/graph/ebnfDiagram-UZSYDL2S-SMF6KJ43.js +1 -0
- package/dist/graph/elk-XV6XMXQE-AZ4HLCWI.js +27 -0
- package/dist/graph/erDiagram-EYBAPDEH-B3JNJ357.js +99 -0
- package/dist/graph/eventmodeling-K75KTNOO-WG6DDYMC.js +1 -0
- package/dist/graph/flowDiagram-MALGAFMO-2R7EYAQI.js +1 -0
- package/dist/graph/ganttDiagram-23REXITY-YXBYWFOJ.js +292 -0
- package/dist/graph/gitGraph-VSP46ZUC-VBFWJBBT.js +1 -0
- package/dist/graph/gitGraphDiagram-STJD7YCW-4FZDCFGV.js +106 -0
- package/dist/graph/info-OHQRW6UA-ALVDUVYV.js +1 -0
- package/dist/graph/infoDiagram-KBXO4MBG-7EHX2GQG.js +2 -0
- package/dist/graph/ishikawaDiagram-M35NCXHK-FRZD2PWQ.js +70 -0
- package/dist/graph/journeyDiagram-OPLOXDXO-7Z66JCPR.js +139 -0
- package/dist/graph/kanban-definition-BZKZHSQY-NN5AIKTE.js +89 -0
- package/dist/graph/katex-DXDNVO6V.js +257 -0
- package/dist/graph/mindmap-definition-I2QAS2VK-HDPCABN2.js +98 -0
- package/dist/graph/packet-JDAUHWVQ-5MQIBWAH.js +1 -0
- package/dist/graph/pegDiagram-FD4XPPHP-H2BFNCKT.js +1 -0
- package/dist/graph/pie-XZMESJXO-T5VRKHVT.js +1 -0
- package/dist/graph/pieDiagram-J4AKIIQI-O3NJSVD3.js +39 -0
- package/dist/graph/quadrantDiagram-XTYBLID2-TMTZJI3P.js +7 -0
- package/dist/graph/radar-ABXABTNO-C6FXIBYW.js +1 -0
- package/dist/graph/railroad-I3PHUGI6-ZSO5JXB3.js +1 -0
- package/dist/graph/railroad-abnf-LNEFI6M7-CI4GQRHB.js +1 -0
- package/dist/graph/railroad-ebnf-DWYD2UWJ-MUENNCGK.js +1 -0
- package/dist/graph/railroad-peg-JR7BVNR7-N3X5GGIX.js +1 -0
- package/dist/graph/railroadDiagram-MRQ6NCDL-JHWS23UO.js +1 -0
- package/dist/graph/requirementDiagram-Y7LWUY3S-7DVLPO4B.js +84 -0
- package/dist/graph/sankeyDiagram-WGJFYUXA-Z5L4R5TR.js +40 -0
- package/dist/graph/schema-graph-global.js +639 -0
- package/dist/graph/sequenceDiagram-5NDRBG5M-RCTU25NT.js +169 -0
- package/dist/graph/sizeCapture-INFHLROL-RROY32P5.js +1 -0
- package/dist/graph/stateDiagram-v2-FJ4FJNEA-BXUSPWDK.js +291 -0
- package/dist/graph/swimlanes-UMQ2AFYF-LDD74Q2S.js +1 -0
- package/dist/graph/swimlanesDiagram-OMPLPG4O-ZYULLJSU.js +8 -0
- package/dist/graph/timeline-definition-SEUHKTQE-ZQSMIVAS.js +120 -0
- package/dist/graph/treeView-D4JQ5SDB-42S7U73N.js +1 -0
- package/dist/graph/treemap-SAJKECNS-RUBYQ7XF.js +1 -0
- package/dist/graph/usecaseDiagram-AFA6YXN4-57RDRYXF.js +370 -0
- package/dist/graph/vennDiagram-NNMJR3RB-5C3LVAV6.js +34 -0
- package/dist/graph/wardley-7MLQ67FV-NV5HXTTC.js +1 -0
- package/dist/graph/wardleyDiagram-S7YFUSEH-6D5BKXHM.js +78 -0
- package/dist/graph/xychartDiagram-GGNKY7IX-6ET3ZM67.js +7 -0
- package/dist/mcp.js +5 -4
- package/dist/plugins.global.js +71 -104
- package/dist/subformats.global.js +6 -112
- package/dist/ui.global.js +75 -108
- package/dist/viewer/build.d.ts +2 -0
- package/dist/viewer/build.js +22 -8
- package/dist/viewer/code-file.js +7 -2
- package/dist/viewer/figure-preview.d.ts +4 -0
- package/dist/viewer/figure-preview.js +54 -0
- package/dist/viewer/hmr.js +4 -3
- package/dist/viewer/lazy-preview.d.ts +2 -0
- package/dist/viewer/lazy-preview.js +43 -0
- package/dist/viewer/locales/eng.json +26 -3
- package/dist/viewer/locales/jpn.json +26 -3
- package/dist/viewer/locales/zho.json +26 -3
- package/dist/viewer/plugin-blocks.js +1 -1
- package/dist/viewer/plugins.js +1 -1
- package/dist/viewer/resource-library.d.ts +1 -1
- package/dist/viewer/resource-library.js +5 -4
- package/dist/viewer/serve.d.ts +2 -1
- package/dist/viewer/serve.js +148 -41
- package/dist/viewer/textfile.d.ts +2 -0
- package/dist/viewer/textfile.js +20 -5
- package/package.json +5 -3
- package/dist/viewer/lazy-graph.d.ts +0 -2
- package/dist/viewer/lazy-graph.js +0 -30
|
@@ -1,59 +1,27 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
4
|
import { stringify as stringifyToml } from "smol-toml";
|
|
5
|
-
import { Document, isSeq, parseDocument, stringify as stringifyYaml } from "yaml";
|
|
6
|
-
import { MANIFEST_FILE } from "../core/content-metadata.js";
|
|
5
|
+
import { Document, isSeq, parseDocument, stringify as stringifyYaml, visit } from "yaml";
|
|
6
|
+
import { flattenTree, MANIFEST_FILE, subformatPageId } from "../core/content-metadata.js";
|
|
7
7
|
import { fileExtension } from "../core/files.js";
|
|
8
|
+
import { schemaResolver } from "../core/schema-refs.js";
|
|
8
9
|
import { parseSubformatRecord, setSubformatValue } from "../core/subformat-record.js";
|
|
9
|
-
import { parseSubformats, SUBFORMAT_SCHEMA_TEMPLATE,
|
|
10
|
+
import { parseSubformats, SUBFORMAT_SCHEMA_TEMPLATE, } from "../core/subformats.js";
|
|
10
11
|
import { filesSnapshot, managedFile } from "./files.js";
|
|
11
12
|
import { parseManifestText, readManifest } from "./manifest.js";
|
|
13
|
+
import { compileSubformatSchema } from "./subformat-schema.js";
|
|
12
14
|
import { readTextfile, textfilePath, writeTextfile } from "./textfile.js";
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
if (!schema || typeof schema !== "object" || Array.isArray(schema) || schema.$async)
|
|
16
|
-
throw new Error("Use a synchronous JSON object schema");
|
|
17
|
-
if (schema.$schema !== undefined && schema.$schema !== SUBFORMAT_SCHEMA_VERSION)
|
|
18
|
-
throw new Error(`Use JSON Schema 2020-12: ${SUBFORMAT_SCHEMA_VERSION}`);
|
|
19
|
-
const ajv = new Ajv2020({ allErrors: true, strict: true, ownProperties: true });
|
|
20
|
-
addFormats.default(ajv);
|
|
21
|
-
const validate = ajv.compile(schema);
|
|
22
|
-
return { schema, validate };
|
|
23
|
-
};
|
|
24
|
-
const schemaCache = new Map();
|
|
25
|
-
export const loadSubformat = (root, config) => {
|
|
15
|
+
export { compileSubformatSchema } from "./subformat-schema.js";
|
|
16
|
+
export const loadSubformat = (root, config, domains = []) => {
|
|
26
17
|
const content = readTextfile(root, config.schema);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
const { schema, validate } = compiled;
|
|
36
|
-
const resolve = (value) => {
|
|
37
|
-
const seen = new Set();
|
|
38
|
-
while (typeof value.$ref === "string" && value.$ref.startsWith("#/")) {
|
|
39
|
-
if (seen.has(value.$ref))
|
|
40
|
-
break;
|
|
41
|
-
seen.add(value.$ref);
|
|
42
|
-
const target = value.$ref
|
|
43
|
-
.slice(2)
|
|
44
|
-
.split("/")
|
|
45
|
-
.reduce((node, key) => {
|
|
46
|
-
const property = key.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
47
|
-
return node && Object.hasOwn(node, property) ? node[property] : undefined;
|
|
48
|
-
}, schema);
|
|
49
|
-
if (!target || typeof target !== "object")
|
|
50
|
-
break;
|
|
51
|
-
const { $ref: _ref, ...siblings } = value;
|
|
52
|
-
value = { ...target, ...siblings };
|
|
53
|
-
}
|
|
54
|
-
return value;
|
|
55
|
-
};
|
|
56
|
-
// shortcut: controls use top-level properties and local refs, extend extraction for composed schemas.
|
|
18
|
+
const { schema, validate, context } = compileSubformatSchema(content, {
|
|
19
|
+
root,
|
|
20
|
+
file: config.schema,
|
|
21
|
+
domains,
|
|
22
|
+
});
|
|
23
|
+
const resolve = schemaResolver(schema, context);
|
|
24
|
+
// shortcut: controls use top-level properties and refs; extend extraction for composed schemas.
|
|
57
25
|
const fields = Object.entries(resolve(schema).properties ?? {}).flatMap(([name, definition]) => {
|
|
58
26
|
if (!definition || typeof definition !== "object")
|
|
59
27
|
return [];
|
|
@@ -87,22 +55,26 @@ export const loadSubformat = (root, config) => {
|
|
|
87
55
|
const property = resolve(definition);
|
|
88
56
|
if (!object.required?.includes(name) && property.default === undefined)
|
|
89
57
|
return [];
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
property
|
|
93
|
-
(property.
|
|
94
|
-
?
|
|
95
|
-
:
|
|
96
|
-
?
|
|
97
|
-
: property.type === "
|
|
98
|
-
?
|
|
99
|
-
: property.type
|
|
100
|
-
?
|
|
101
|
-
: property.
|
|
102
|
-
?
|
|
103
|
-
: property.
|
|
104
|
-
?
|
|
105
|
-
: ""
|
|
58
|
+
const prescribed = ["default", "const"].find((key) => Object.hasOwn(property, key));
|
|
59
|
+
const value = prescribed
|
|
60
|
+
? property[prescribed]
|
|
61
|
+
: Array.isArray(property.enum)
|
|
62
|
+
? property.enum[0]
|
|
63
|
+
: property.type === "null"
|
|
64
|
+
? null
|
|
65
|
+
: property.type === "boolean"
|
|
66
|
+
? false
|
|
67
|
+
: ["number", "integer"].includes(property.type)
|
|
68
|
+
? (property.minimum ?? 0)
|
|
69
|
+
: property.type === "object"
|
|
70
|
+
? {}
|
|
71
|
+
: property.type === "array"
|
|
72
|
+
? []
|
|
73
|
+
: property.format === "date"
|
|
74
|
+
? new Date().toISOString().slice(0, 10)
|
|
75
|
+
: property.format === "date-time"
|
|
76
|
+
? new Date().toISOString()
|
|
77
|
+
: "";
|
|
106
78
|
return [[name, value]];
|
|
107
79
|
}));
|
|
108
80
|
let template = "";
|
|
@@ -125,28 +97,56 @@ export const validateSubformatRecord = (format, data) => {
|
|
|
125
97
|
.map((error) => `${error.instancePath || "/"} ${error.message}`)
|
|
126
98
|
.join("; "));
|
|
127
99
|
};
|
|
128
|
-
export const
|
|
100
|
+
export const isSubformatSchemaFile = (root, file, domains = []) => {
|
|
101
|
+
const configs = readManifest(root).subformats ?? [];
|
|
102
|
+
if (/\.schema\.json$/i.test(file) ||
|
|
103
|
+
configs.some((config) => config.schema === file.replace(/^(\.\/)+/, "")))
|
|
104
|
+
return true;
|
|
105
|
+
const uri = pathToFileURL(textfilePath(root, file)).href;
|
|
106
|
+
return configs.some((config) => {
|
|
107
|
+
try {
|
|
108
|
+
return Object.hasOwn(compileSubformatSchema(readTextfile(root, config.schema), {
|
|
109
|
+
root,
|
|
110
|
+
file: config.schema,
|
|
111
|
+
domains,
|
|
112
|
+
}).context.schemas, uri);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// A broken referring schema must not prevent opening a file for repair.
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
export const validateSubformatFile = (root, file, content, domains = []) => {
|
|
129
121
|
const configs = readManifest(root).subformats;
|
|
130
|
-
if (
|
|
131
|
-
compileSubformatSchema(content);
|
|
122
|
+
if (isSubformatSchemaFile(root, file, domains))
|
|
123
|
+
compileSubformatSchema(content, { root, file, domains });
|
|
132
124
|
const config = configs?.find((format) => format.ext === fileExtension(file));
|
|
133
125
|
if (!config)
|
|
134
126
|
return;
|
|
135
127
|
if (!filesSnapshot(root).files.some((file) => file.path === config.schema))
|
|
136
128
|
throw new Error("Subformat schema is not available in the workspace");
|
|
137
129
|
try {
|
|
138
|
-
validateSubformatRecord(loadSubformat(root, config), parseSubformatRecord(content, config.format));
|
|
130
|
+
validateSubformatRecord(loadSubformat(root, config, domains), parseSubformatRecord(content, config.format));
|
|
139
131
|
}
|
|
140
132
|
catch (error) {
|
|
141
133
|
throw new Error(`${file} (${config.format}): ${error instanceof Error ? error.message : String(error)}`);
|
|
142
134
|
}
|
|
143
135
|
};
|
|
144
|
-
export const subformatResponse = (root, input) => {
|
|
136
|
+
export const subformatResponse = (root, input, domains = []) => {
|
|
145
137
|
try {
|
|
146
138
|
if (input?.action === "validate") {
|
|
147
139
|
if (typeof input.content !== "string")
|
|
148
140
|
throw new Error("Schema content is required");
|
|
149
|
-
|
|
141
|
+
if (input.file !== undefined && typeof input.file !== "string")
|
|
142
|
+
throw new Error("Schema file must be a path");
|
|
143
|
+
compileSubformatSchema(input.content, {
|
|
144
|
+
root,
|
|
145
|
+
file: typeof input.file === "string" && input.file
|
|
146
|
+
? input.file
|
|
147
|
+
: "subformat.schema.json",
|
|
148
|
+
domains,
|
|
149
|
+
});
|
|
150
150
|
return { status: 200, body: {} };
|
|
151
151
|
}
|
|
152
152
|
if (input?.action === "layouts") {
|
|
@@ -171,7 +171,7 @@ export const subformatResponse = (root, input) => {
|
|
|
171
171
|
};
|
|
172
172
|
parseSubformats([{ ...config, layouts: { ...config.layouts, [key]: input.value } }]);
|
|
173
173
|
if (key !== "sort_order" && input.value) {
|
|
174
|
-
const field = loadSubformat(root, config).fields.find((field) => field.name === input.value);
|
|
174
|
+
const field = loadSubformat(root, config, domains).fields.find((field) => field.name === input.value);
|
|
175
175
|
if (!field ||
|
|
176
176
|
(key === "group_by" && !field.enum?.length) ||
|
|
177
177
|
(key === "sort_by" && !field.enum && !field.format && !field.type))
|
|
@@ -184,6 +184,46 @@ export const subformatResponse = (root, input) => {
|
|
|
184
184
|
return { status: 409, body: { error: "Manifest changed externally. Try again." } };
|
|
185
185
|
return { status: 200, body: {} };
|
|
186
186
|
}
|
|
187
|
+
if (input?.action === "delete") {
|
|
188
|
+
if (typeof input.ext !== "string")
|
|
189
|
+
throw new Error("A subformat extension is required");
|
|
190
|
+
const raw = readTextfile(root, MANIFEST_FILE);
|
|
191
|
+
const manifest = parseManifestText(raw);
|
|
192
|
+
if (manifest.errors.length)
|
|
193
|
+
throw new Error(manifest.errors.join("\n"));
|
|
194
|
+
const index = manifest.subformats?.findIndex((format) => format.ext === input.ext) ?? -1;
|
|
195
|
+
const config = manifest.subformats?.[index];
|
|
196
|
+
if (!config)
|
|
197
|
+
throw new Error("Unknown subformat");
|
|
198
|
+
if (!isDeepStrictEqual(config, parseSubformats([input.base])[0]))
|
|
199
|
+
return {
|
|
200
|
+
status: 409,
|
|
201
|
+
body: { error: "Subformat changed externally. Reload and try again." },
|
|
202
|
+
};
|
|
203
|
+
const id = subformatPageId(input.ext);
|
|
204
|
+
if (flattenTree(manifest.tree).some((node) => node.parent === id))
|
|
205
|
+
throw new Error("Move or remove this subformat page's child pages before deleting it.");
|
|
206
|
+
const document = parseDocument(raw);
|
|
207
|
+
const nested = manifest.format === "nested";
|
|
208
|
+
document.deleteIn([nested ? "json_subformats" : "subformats", index]);
|
|
209
|
+
const pages = document.get(nested ? "center_contents" : "docs", true);
|
|
210
|
+
if (isSeq(pages))
|
|
211
|
+
visit(pages, {
|
|
212
|
+
Map: (_key, node) => {
|
|
213
|
+
if (node.get("subformat") === input.ext)
|
|
214
|
+
return visit.REMOVE;
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
if (!nested && document.hasIn(["files", "icons", id]))
|
|
218
|
+
document.deleteIn(["files", "icons", id]);
|
|
219
|
+
const content = document.toString();
|
|
220
|
+
const next = parseManifestText(content);
|
|
221
|
+
if (next.errors.length)
|
|
222
|
+
throw new Error(next.errors.join("\n"));
|
|
223
|
+
if (!writeTextfile(root, MANIFEST_FILE, content, raw))
|
|
224
|
+
return { status: 409, body: { error: "Manifest changed externally. Try again." } };
|
|
225
|
+
return { status: 200, body: {} };
|
|
226
|
+
}
|
|
187
227
|
if (input?.action === "register") {
|
|
188
228
|
const raw = readTextfile(root, MANIFEST_FILE);
|
|
189
229
|
const manifest = parseManifestText(raw);
|
|
@@ -202,7 +242,7 @@ export const subformatResponse = (root, input) => {
|
|
|
202
242
|
if (input.content !== undefined && typeof input.content !== "string")
|
|
203
243
|
throw new Error("Schema content must be text");
|
|
204
244
|
const initial = input.content ?? SUBFORMAT_SCHEMA_TEMPLATE;
|
|
205
|
-
compileSubformatSchema(initial);
|
|
245
|
+
compileSubformatSchema(initial, { root, file: config.schema, domains });
|
|
206
246
|
if (!existsSync(textfilePath(root, config.schema))) {
|
|
207
247
|
if (!writeTextfile(root, config.schema, initial, null))
|
|
208
248
|
return {
|
|
@@ -219,7 +259,7 @@ export const subformatResponse = (root, input) => {
|
|
|
219
259
|
}
|
|
220
260
|
if (!filesSnapshot(root).files.some((file) => file.path === config.schema))
|
|
221
261
|
throw new Error("Subformat schema is not available in the workspace");
|
|
222
|
-
const loaded = loadSubformat(root, config);
|
|
262
|
+
const loaded = loadSubformat(root, config, domains);
|
|
223
263
|
const parsed = parseDocument(raw);
|
|
224
264
|
const document = isSeq(parsed.contents) || parsed.contents == null
|
|
225
265
|
? new Document({ docs: parsed.toJS() ?? [] })
|
|
@@ -253,7 +293,7 @@ export const subformatResponse = (root, input) => {
|
|
|
253
293
|
const config = readManifest(root).subformats?.find((format) => format.ext === fileExtension(input.file));
|
|
254
294
|
if (!config)
|
|
255
295
|
throw new Error("Choose a configured subformat extension");
|
|
256
|
-
validateSubformatFile(root, input.file, input.content);
|
|
296
|
+
validateSubformatFile(root, input.file, input.content, domains);
|
|
257
297
|
const data = parseSubformatRecord(input.content, config.format);
|
|
258
298
|
if (!writeTextfile(root, input.file, input.content, null))
|
|
259
299
|
return { status: 409, body: { error: "File already exists" } };
|
|
@@ -269,7 +309,7 @@ export const subformatResponse = (root, input) => {
|
|
|
269
309
|
const config = readManifest(root).subformats?.find((format) => format.ext === fileExtension(input.file));
|
|
270
310
|
if (!config || !files.includes(config.schema))
|
|
271
311
|
throw new Error("Subformat schema is not available in the workspace");
|
|
272
|
-
const format = loadSubformat(root, config);
|
|
312
|
+
const format = loadSubformat(root, config, domains);
|
|
273
313
|
const field = format.fields.find((field) => field.name === input.field);
|
|
274
314
|
if (field?.readOnly || !field?.enum?.some((value) => value === input.value))
|
|
275
315
|
throw new Error("Choose a writable enum value defined by the schema");
|
package/dist/core/code-file.js
CHANGED
|
@@ -17,11 +17,13 @@ export const codeFileName = (body, position, documentId) => {
|
|
|
17
17
|
markdown: "md",
|
|
18
18
|
"c++": "cpp",
|
|
19
19
|
};
|
|
20
|
-
const extension =
|
|
21
|
-
?
|
|
22
|
-
:
|
|
23
|
-
? language
|
|
24
|
-
:
|
|
20
|
+
const extension = /^\.[a-z0-9][a-z0-9_-]*$/.test(language)
|
|
21
|
+
? language.slice(1)
|
|
22
|
+
: Object.hasOwn(aliases, language)
|
|
23
|
+
? aliases[language]
|
|
24
|
+
: /^[a-z0-9_-]+$/.test(language)
|
|
25
|
+
? language
|
|
26
|
+
: "txt";
|
|
25
27
|
const directory = language === "termth"
|
|
26
28
|
? "terms"
|
|
27
29
|
: language === "graphth" || language === "schemath"
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LanguageRegistration } from "shiki/core";
|
|
2
|
+
import type { Subformat } from "./subformats.js";
|
|
3
|
+
/** Include referenced scopes as well as declared embedded languages for custom grammars. */
|
|
4
|
+
export declare const selectCodeGrammars: (all: LanguageRegistration[], languages: Iterable<string>) => LanguageRegistration[];
|
|
5
|
+
export declare const subformatCodeGrammars: (grammars: LanguageRegistration[], subformats?: readonly Subformat[]) => LanguageRegistration[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Include referenced scopes as well as declared embedded languages for custom grammars. */
|
|
2
|
+
export const selectCodeGrammars = (all, languages) => {
|
|
3
|
+
const selected = new Set();
|
|
4
|
+
const add = (entry) => {
|
|
5
|
+
if (selected.has(entry))
|
|
6
|
+
return;
|
|
7
|
+
selected.add(entry);
|
|
8
|
+
const names = new Set(entry.embeddedLangs ?? []);
|
|
9
|
+
for (const match of JSON.stringify(entry).matchAll(/"include":"([^"#$][^"]*)"/g))
|
|
10
|
+
names.add((match[1] ?? "").split("#")[0] ?? "");
|
|
11
|
+
for (const dependency of all)
|
|
12
|
+
if (names.has(dependency.name) || names.has(dependency.scopeName))
|
|
13
|
+
add(dependency);
|
|
14
|
+
};
|
|
15
|
+
for (const language of languages) {
|
|
16
|
+
const grammar = all.find((entry) => entry.name === language || entry.aliases?.includes(language));
|
|
17
|
+
if (grammar)
|
|
18
|
+
add(grammar);
|
|
19
|
+
}
|
|
20
|
+
return [...selected];
|
|
21
|
+
};
|
|
22
|
+
export const subformatCodeGrammars = (grammars, subformats = []) => {
|
|
23
|
+
const registered = new Set(grammars.flatMap((grammar) => [grammar.name, ...(grammar.aliases ?? [])]));
|
|
24
|
+
return grammars.map((grammar) => ({
|
|
25
|
+
...grammar,
|
|
26
|
+
aliases: [
|
|
27
|
+
...(grammar.aliases ?? []),
|
|
28
|
+
...subformats
|
|
29
|
+
.filter(({ format }) => format === grammar.name)
|
|
30
|
+
.flatMap(({ ext }) => [`.${ext}`, ext])
|
|
31
|
+
.filter((alias) => !registered.has(alias)),
|
|
32
|
+
],
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
@@ -16,6 +16,7 @@ export interface ParsedManifest {
|
|
|
16
16
|
title?: string;
|
|
17
17
|
icon?: string;
|
|
18
18
|
defaultLang?: string;
|
|
19
|
+
licence?: string;
|
|
19
20
|
files?: FileLayout;
|
|
20
21
|
/** Content languages offered by the site, including defaultLang; normalized to ISO 639-3. */
|
|
21
22
|
languages?: string[];
|
|
@@ -37,7 +38,7 @@ export declare const docIdOfFile: (name: string) => string | undefined;
|
|
|
37
38
|
*/
|
|
38
39
|
export declare const parseManifest: (value: unknown) => ParsedManifest;
|
|
39
40
|
/** Serialize the authored format; legacy manifests remain readable during migration. */
|
|
40
|
-
export declare const serializeManifest: (tree: readonly DocNode[], { format, titles, themeIcons, title, icon, defaultLang, files, languages, themes, subformats, defaultSubformatFolder, }?: Omit<ParsedManifest, "tree" | "errors">) => string;
|
|
41
|
+
export declare const serializeManifest: (tree: readonly DocNode[], { format, titles, themeIcons, title, icon, defaultLang, licence, files, languages, themes, subformats, defaultSubformatFolder, }?: Omit<ParsedManifest, "tree" | "errors">) => string;
|
|
41
42
|
/** Flatten the tree into display order (pre-order). parent omitted = top level. */
|
|
42
43
|
export declare const flattenTree: (tree: readonly DocNode[]) => (Omit<DocNode, "children"> & {
|
|
43
44
|
parent?: string;
|
|
@@ -223,7 +223,10 @@ const parseNestedManifest = (input) => {
|
|
|
223
223
|
"json_subformats",
|
|
224
224
|
"default_subformat_folder",
|
|
225
225
|
], MANIFEST_FILE);
|
|
226
|
-
const system = object(root.system ?? {}, ["languages", "default_lang", "themes", "files"], "system");
|
|
226
|
+
const system = object(root.system ?? {}, ["languages", "default_lang", "themes", "licence", "files"], "system");
|
|
227
|
+
const licence = system.licence;
|
|
228
|
+
if (licence !== undefined && (!localFile(licence) || !licence.trim()))
|
|
229
|
+
throw new Error("system.licence must be a local file path");
|
|
227
230
|
const sidebar = object(root.left_sidebar ?? {}, ["title", "icon"], "left_sidebar");
|
|
228
231
|
const layout = object(system.files ?? {}, ["default_layout", "order"], "system.files");
|
|
229
232
|
const titles = {};
|
|
@@ -329,6 +332,7 @@ const parseNestedManifest = (input) => {
|
|
|
329
332
|
...parsed,
|
|
330
333
|
format: "nested",
|
|
331
334
|
tree,
|
|
335
|
+
...(licence === undefined ? {} : { licence }),
|
|
332
336
|
...(sidebar.title === undefined ? {} : { titles }),
|
|
333
337
|
...(sidebar.icon === undefined ? {} : { themeIcons }),
|
|
334
338
|
};
|
|
@@ -342,7 +346,7 @@ const parseNestedManifest = (input) => {
|
|
|
342
346
|
}
|
|
343
347
|
};
|
|
344
348
|
/** Serialize the authored format; legacy manifests remain readable during migration. */
|
|
345
|
-
export const serializeManifest = (tree, { format, titles, themeIcons, title, icon, defaultLang, files, languages, themes, subformats, defaultSubformatFolder, } = {}) => {
|
|
349
|
+
export const serializeManifest = (tree, { format, titles, themeIcons, title, icon, defaultLang, licence, files, languages, themes, subformats, defaultSubformatFolder, } = {}) => {
|
|
346
350
|
if (format === "nested") {
|
|
347
351
|
const contents = (nodes) => nodes.map((node) => ({
|
|
348
352
|
...(node.subformat
|
|
@@ -355,6 +359,7 @@ export const serializeManifest = (tree, { format, titles, themeIcons, title, ico
|
|
|
355
359
|
system: {
|
|
356
360
|
...(languages ? { languages } : {}),
|
|
357
361
|
default_lang: defaultLang ?? DEFAULT_LANG,
|
|
362
|
+
...(licence === undefined ? {} : { licence }),
|
|
358
363
|
...(themes ? { themes } : {}),
|
|
359
364
|
...(files
|
|
360
365
|
? {
|
|
@@ -12,7 +12,7 @@ export interface TermEntry {
|
|
|
12
12
|
export interface FigureEntry {
|
|
13
13
|
name: string;
|
|
14
14
|
file: string;
|
|
15
|
-
kind: "svg" | "html" | "image" | "video";
|
|
15
|
+
kind: "svg" | "html" | "image" | "video" | "pdf";
|
|
16
16
|
/**
|
|
17
17
|
* Full figure content (SVG / HTML fragment / <img> data URI for rasters). Consumers render it
|
|
18
18
|
* inline; MCP can pass it as text.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const escapeHtml: (s: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const escapeHtml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
@@ -31,7 +31,7 @@ const svgBox = (markup) => {
|
|
|
31
31
|
};
|
|
32
32
|
/** One figure → an isolated iframe (rasters stay as <img>). */
|
|
33
33
|
export const figureFrameHtml = (fig, cls = "fig-frame", label) => {
|
|
34
|
-
if (fig.kind === "video")
|
|
34
|
+
if (fig.kind === "video" || fig.kind === "pdf")
|
|
35
35
|
return label
|
|
36
36
|
? fig.markup.replace(/\baria-label="[^"]*"/, () => `aria-label="${esc(label)}"`)
|
|
37
37
|
: fig.markup;
|
package/dist/core/file-embed.js
CHANGED
|
@@ -6,7 +6,7 @@ export const parseFigureLink = (source) => {
|
|
|
6
6
|
if (/^(?:[a-z][a-z\d+.-]*:|\/)/i.test(source))
|
|
7
7
|
return undefined;
|
|
8
8
|
const path = decodeURIComponent(source.split(/[?#]/)[0] ?? "");
|
|
9
|
-
if (!/\.(svg|html|png|webp|gif|mp4|webm|jpe?g)
|
|
9
|
+
if (!/\.(svg|html|png|webp|gif|mp4|webm|jpe?g|pdf|dxf)$/i.test(path))
|
|
10
10
|
return undefined;
|
|
11
11
|
const ref = parseFileReference(source);
|
|
12
12
|
const file = ref.file.replace(/^(\.\/)+/, "");
|
|
@@ -34,10 +34,14 @@ export const parseFileEmbed = (source, settings) => {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
if (ref.range !== undefined ||
|
|
37
|
-
(previewer !== "image" &&
|
|
37
|
+
(previewer !== "image" &&
|
|
38
|
+
previewer !== "html" &&
|
|
39
|
+
previewer !== "video" &&
|
|
40
|
+
previewer !== "pdf" &&
|
|
41
|
+
previewer !== "dxf"))
|
|
38
42
|
return { ...ref, kind: "textfile" };
|
|
39
43
|
const file = ref.file.replace(/^(\.\/)+/, "");
|
|
40
44
|
if (!localFile(file))
|
|
41
|
-
throw new Error("
|
|
45
|
+
throw new Error("Visual previews require a local file inside the docs root");
|
|
42
46
|
return { file, kind: previewer === "html" ? "html" : "figure" };
|
|
43
47
|
};
|
package/dist/core/html.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { Block, TocEntry } from "./blocks.js";
|
|
2
2
|
import type { FigureEntry, TermEntry } from "./content-types.js";
|
|
3
|
+
import { figureFrameHtml } from "./figure-frame.js";
|
|
3
4
|
import { type LanguageAdapter } from "./language.js";
|
|
4
5
|
import { type Frontmatter } from "./taxonomy.js";
|
|
6
|
+
export { escapeHtml } from "./escape-html.js";
|
|
5
7
|
export interface RenderCtx {
|
|
6
8
|
/** Source file to published document route. */
|
|
7
9
|
docLinks?: ReadonlyMap<string, string>;
|
|
8
10
|
/** Figures including their markup (name → entry). */
|
|
9
11
|
figures: ReadonlyMap<string, FigureEntry>;
|
|
12
|
+
/** Local viewers may defer large figures; published HTML embeds them directly. */
|
|
13
|
+
figurePreview?: typeof figureFrameHtml;
|
|
10
14
|
terms: readonly TermEntry[];
|
|
11
15
|
termLinks?: ReadonlyMap<string, string>;
|
|
12
16
|
/** The doc's language tag (BCP 47), emitted as `<article lang>`. */
|
|
@@ -22,7 +26,6 @@ export interface RenderCtx {
|
|
|
22
26
|
language?: LanguageAdapter;
|
|
23
27
|
}
|
|
24
28
|
export declare const emptyCtx: RenderCtx;
|
|
25
|
-
export declare const escapeHtml: (s: string) => string;
|
|
26
29
|
/** Shared dictionary entries for definitions and the Resources list. */
|
|
27
30
|
export declare const termsHtml: (terms: readonly TermEntry[], language?: LanguageAdapter, sortable?: boolean) => string;
|
|
28
31
|
export declare const blocksHtml: (blocks: Block[], ctx?: RenderCtx) => string;
|
package/dist/core/html.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// "just map blocks + inline segments to output" pipeline as consumers (= prevents rendering
|
|
3
3
|
// semantics from drifting). Headings and body text share the same weight (headings are also
|
|
4
4
|
// font-weight 400).
|
|
5
|
+
import { escapeHtml } from "./escape-html.js";
|
|
5
6
|
import { figureFrameHtml } from "./figure-frame.js";
|
|
6
7
|
import { parseFigureLink } from "./file-embed.js";
|
|
7
8
|
import { GRAPH_LAYOUT_MARGIN, GRAPH_LEGEND, graphUid, layoutGraph, } from "./graph.js";
|
|
@@ -13,8 +14,8 @@ import { layoutSchemaGraph, SCHEMA_LAYOUT_MARGIN, schemaGraphClientData, schemaG
|
|
|
13
14
|
import { docDisplayName } from "./taxonomy.js";
|
|
14
15
|
import { termAnchor } from "./term-reference.js";
|
|
15
16
|
import { textfileName } from "./textfile.js";
|
|
17
|
+
export { escapeHtml } from "./escape-html.js";
|
|
16
18
|
export const emptyCtx = { figures: new Map(), terms: [] };
|
|
17
|
-
export const escapeHtml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
18
19
|
// File links open their resource page; SVGs and terms also have hover previews.
|
|
19
20
|
const segmentsHtml = (text, ctx, seg) => inlineHtml(seg(text), ctx);
|
|
20
21
|
const inlineHtml = (segments, ctx) => segments
|
|
@@ -48,7 +49,7 @@ const inlineHtml = (segments, ctx) => segments
|
|
|
48
49
|
? `#${encodeURIComponent(figureRef.fragment)}`
|
|
49
50
|
: "");
|
|
50
51
|
const pop = fig.kind === "svg"
|
|
51
|
-
? `<span class="figpop">${figureFrameHtml(fig, "fig-frame figpop-frame")}</span>`
|
|
52
|
+
? `<span class="figpop">${(ctx.figurePreview ?? figureFrameHtml)(fig, "fig-frame figpop-frame")}</span>`
|
|
52
53
|
: "";
|
|
53
54
|
return `<a class="figref" href="${escapeHtml(href)}">${label}${pop}</a>`;
|
|
54
55
|
}
|
|
@@ -90,10 +91,10 @@ const listHtml = (items, ctx, seg, ordered = false) => {
|
|
|
90
91
|
// caption: line 1 = the label "Fig.<name>", then a newline and the description (.cap keeps it via
|
|
91
92
|
// pre-line). The figure content is figure-frame.ts's sandboxed iframe (fully isolates svg / html;
|
|
92
93
|
// raster images use <img>).
|
|
93
|
-
const figureHtml = (fig, withLabel = true, caption) => {
|
|
94
|
+
const figureHtml = (fig, ctx, withLabel = true, caption) => {
|
|
94
95
|
const label = caption ?? fig.title ?? `Fig.${fig.name}`;
|
|
95
96
|
const cap = [withLabel ? label : undefined, fig.desc].filter(Boolean).join("\n");
|
|
96
|
-
return `<figure class="fig">${figureFrameHtml(fig, "fig-frame", caption)}${cap ? `<figcaption class="cap">${escapeHtml(cap)}</figcaption>` : ""}</figure>`;
|
|
97
|
+
return `<figure class="fig">${(ctx.figurePreview ?? figureFrameHtml)(fig, "fig-frame", caption)}${cap ? `<figcaption class="cap">${escapeHtml(cap)}</figcaption>` : ""}</figure>`;
|
|
97
98
|
};
|
|
98
99
|
const tableHtml = (b, ctx, seg) => {
|
|
99
100
|
if (b.dataSource) {
|
|
@@ -388,8 +389,8 @@ const blockHtml = (b, ctx, seg) => {
|
|
|
388
389
|
const fig = ctx.figures.get(b.name);
|
|
389
390
|
if (fig) {
|
|
390
391
|
if (b.alt !== undefined)
|
|
391
|
-
return `<figure class="fig">${figureFrameHtml(fig, "fig-frame", b.alt)}</figure>`;
|
|
392
|
-
return figureHtml(fig, true, b.caption);
|
|
392
|
+
return `<figure class="fig">${(ctx.figurePreview ?? figureFrameHtml)(fig, "fig-frame", b.alt)}</figure>`;
|
|
393
|
+
return figureHtml(fig, ctx, true, b.caption);
|
|
393
394
|
}
|
|
394
395
|
return `<div class="ph">${escapeHtml(b.alt || `Fig. ${b.name}`)}<span> — not found in figures/</span></div>`;
|
|
395
396
|
}
|
|
@@ -399,7 +400,7 @@ const blockHtml = (b, ctx, seg) => {
|
|
|
399
400
|
// Figure list. The h2 doubles as the label, so captions omit it. h2 id = fig name
|
|
400
401
|
// (anchor).
|
|
401
402
|
return [...ctx.figures.values()]
|
|
402
|
-
.map((f) => `<h2 id="${escapeHtml(f.name)}">${escapeHtml(f.title ?? f.name)}</h2>${figureHtml(f, false)}`)
|
|
403
|
+
.map((f) => `<h2 id="${escapeHtml(f.name)}">${escapeHtml(f.title ?? f.name)}</h2>${figureHtml(f, ctx, false)}`)
|
|
403
404
|
.join("\n");
|
|
404
405
|
case "schemaGraph":
|
|
405
406
|
// table DSL → ER diagram. The parsed model is turned into SVG with a
|
package/dist/core/language.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { iso6393, iso6393To1 } from "iso-639-3";
|
|
2
2
|
export const DEFAULT_LANG = "en";
|
|
3
|
-
|
|
3
|
+
let contentCodes;
|
|
4
4
|
const from1 = new Map(Object.entries(iso6393To1).map(([three, two]) => [two, three]));
|
|
5
|
-
export const isContentLanguage = (code) =>
|
|
5
|
+
export const isContentLanguage = (code) => {
|
|
6
|
+
contentCodes ??= new Set(iso6393.map((language) => language.iso6393));
|
|
7
|
+
return contentCodes.has(code);
|
|
8
|
+
};
|
|
6
9
|
/** Normalize site language declarations and translation directory names consistently. */
|
|
7
10
|
export const contentLanguageCode = (tag) => {
|
|
8
11
|
const primary = tag.toLowerCase().split("-")[0] ?? "";
|
package/dist/core/markdown.js
CHANGED
|
@@ -8,7 +8,8 @@ import { parseFigureLink } from "./file-embed.js";
|
|
|
8
8
|
import { parseDocLink } from "./routing.js";
|
|
9
9
|
import { parseTermReference, termFileUrl } from "./term-reference.js";
|
|
10
10
|
const processor = unified().use(remarkParse).use(remarkFrontmatter).use(remarkGfm);
|
|
11
|
-
const
|
|
11
|
+
const createInlinePrinter = () => unified().use(remarkGfm).use(remarkStringify);
|
|
12
|
+
let inlinePrinter;
|
|
12
13
|
export const parseMdast = (raw) => processor.parse(raw);
|
|
13
14
|
/** File previews occupy whole paragraphs; prose, lists and tables keep their inline layout. */
|
|
14
15
|
export const standaloneImages = (node) => node.type === "paragraph" &&
|
|
@@ -115,6 +116,7 @@ export const inlineToText = (nodes) => {
|
|
|
115
116
|
/* Reported by validation. */
|
|
116
117
|
}
|
|
117
118
|
});
|
|
119
|
+
inlinePrinter ??= createInlinePrinter();
|
|
118
120
|
return inlinePrinter.stringify(root).replace(/\n$/, "");
|
|
119
121
|
};
|
|
120
122
|
export const listItems = (n, convert) => n.children.map((li) => {
|
|
@@ -22,6 +22,14 @@ export declare const PREVIEWERS: readonly [{
|
|
|
22
22
|
readonly id: "video";
|
|
23
23
|
readonly label: "Video";
|
|
24
24
|
readonly extensions: readonly ["mp4", "webm"];
|
|
25
|
+
}, {
|
|
26
|
+
readonly id: "pdf";
|
|
27
|
+
readonly label: "PDF";
|
|
28
|
+
readonly extensions: readonly ["pdf"];
|
|
29
|
+
}, {
|
|
30
|
+
readonly id: "dxf";
|
|
31
|
+
readonly label: "DXF";
|
|
32
|
+
readonly extensions: readonly ["dxf"];
|
|
25
33
|
}];
|
|
26
34
|
export type PreviewerId = (typeof PREVIEWERS)[number]["id"];
|
|
27
35
|
export interface PreviewSettings {
|
package/dist/core/previewers.js
CHANGED
|
@@ -43,6 +43,8 @@ export const PREVIEWERS = [
|
|
|
43
43
|
],
|
|
44
44
|
},
|
|
45
45
|
{ id: "video", label: "Video", extensions: ["mp4", "webm"] },
|
|
46
|
+
{ id: "pdf", label: "PDF", extensions: ["pdf"] },
|
|
47
|
+
{ id: "dxf", label: "DXF", extensions: ["dxf"] },
|
|
46
48
|
];
|
|
47
49
|
export const defaultPreviewSettings = () => ({
|
|
48
50
|
domains: [],
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type SchemaObject = Record<string, unknown>;
|
|
2
|
+
export declare const schemaTypes: string[];
|
|
3
|
+
export declare const schemaObject: (value: unknown) => value is SchemaObject;
|
|
4
|
+
export declare const schemaKeyword: (name: string) => SchemaObject;
|
|
5
|
+
export declare const schemaConstraints: Record<string, string[]>;
|
|
6
|
+
export declare const schemaJsonParameters: string[];
|
|
7
|
+
export declare const parseFieldSchema: (content: string) => SchemaObject;
|
|
8
|
+
export declare const renameSchemaField: (parent: SchemaObject, from: string, to: string) => void;
|
|
9
|
+
export declare const schemaFieldNamesLocked: (schema: unknown) => boolean;
|
|
10
|
+
export declare const setSchemaType: (schema: SchemaObject, type: string) => void;
|
|
11
|
+
export declare const formatSchemaChoices: (values: unknown[], type: unknown) => string;
|
|
12
|
+
export declare const schemaChoices: (text: string, type: unknown) => unknown[];
|
|
13
|
+
export declare const parseSchemaParameter: (key: string, text: string, type: unknown) => unknown;
|