@open-document/core 0.12.0 → 0.13.1
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/{build-DfUfpeTR.js → build-CvsOak5B.js} +1 -1
- package/dist/{check-CHxiOkQG.js → check-CbUBwYmf.js} +3 -3
- package/dist/cli/bin.js +47 -10
- package/dist/config-BWtOZ1jc.d.ts +45 -0
- package/dist/{config-9IdbhVuT.js → config-CltJJVsw.js} +398 -493
- package/dist/{context-BLI1-64_.js → context-CWgfsHoE.js} +2 -1
- package/dist/deploy-gcp-BUiSuqz7.js +758 -0
- package/dist/{dev-yNYKv5mm.js → dev-B8H2qT6G.js} +1 -1
- package/dist/{diagram-BK4jTZr4.js → diagram-CKf3ptOE.js} +293 -13
- package/dist/{diff-Bs205mOx.js → diff-BvIjjgnc.js} +2 -2
- package/dist/{export-tkquS5O5.js → export-DX30_s2q.js} +3 -3
- package/dist/{sdk-CHEGeINh.d.ts → flow-CS5apebG.d.ts} +72 -3
- package/dist/{import-D1hIKIr3.js → import-DgsdJT5e.js} +2 -2
- package/dist/index.d.ts +155 -59
- package/dist/index.js +896 -90
- package/dist/open-doc-plugin-DnX5usgI.js +320 -0
- package/dist/ops/index.d.ts +98 -13
- package/dist/ops/index.js +3 -3
- package/dist/{ops-Dgqujq5a.js → ops-CSR5RlrE.js} +2 -1
- package/dist/{preview-BImdTH6K.js → preview-DYMUNjXL.js} +1 -1
- package/dist/{templates-DT5zzqHq.js → templates-B5Tz0AKb.js} +3 -3
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +2 -1
- package/package.json +1 -1
- package/skills/doc-authoring/SKILL.md +15 -16
- package/skills/doc-authoring/references/long-form.md +43 -2
- package/skills/doc-authoring/references/pagination.md +14 -2
- package/skills/doc-authoring/references/tables-and-charts.md +21 -17
- package/src/app/components/callout.tsx +101 -0
- package/src/app/components/chart.tsx +191 -33
- package/src/app/components/code-block.tsx +249 -0
- package/src/app/components/data-table.tsx +146 -18
- package/src/app/components/flow-page.tsx +57 -8
- package/src/app/components/numbering.tsx +226 -12
- package/src/app/components/page-frame.tsx +42 -0
- package/src/app/lib/chart.test.ts +15 -0
- package/src/app/lib/chart.ts +134 -9
- package/src/app/lib/diagnostics.ts +45 -1
- package/src/app/lib/export-dom.ts +15 -2
- package/src/app/lib/export-pdf.ts +9 -1
- package/src/app/lib/flow-measure.ts +33 -4
- package/src/app/lib/flow.test.ts +20 -1
- package/src/app/lib/flow.ts +120 -20
- package/src/app/lib/labels.ts +29 -10
- package/src/app/lib/sdk.ts +6 -0
- package/src/app/lib/use-doc-pages.ts +23 -8
- package/src/app/routes/doc.tsx +1 -0
- package/dist/config-P61niZMf.d.ts +0 -24
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
4
|
+
import fg from "fast-glob";
|
|
5
|
+
import { loadConfigFromFile, normalizePath } from "vite";
|
|
6
|
+
//#region src/vite/open-doc-plugin.ts
|
|
7
|
+
const DOC_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
8
|
+
const CONFIG_FILE = "open-doc.config.ts";
|
|
9
|
+
const DOCS_VMOD = "virtual:open-doc/docs";
|
|
10
|
+
const CONFIG_VMOD = "virtual:open-doc/config";
|
|
11
|
+
const FOLDERS_VMOD = "virtual:open-doc/folders";
|
|
12
|
+
async function readFoldersManifest(file) {
|
|
13
|
+
try {
|
|
14
|
+
const parsed = JSON.parse(await fs.readFile(file, "utf8"));
|
|
15
|
+
return {
|
|
16
|
+
folders: Array.isArray(parsed.folders) ? parsed.folders : [],
|
|
17
|
+
assignments: parsed.assignments && typeof parsed.assignments === "object" ? parsed.assignments : {}
|
|
18
|
+
};
|
|
19
|
+
} catch (err) {
|
|
20
|
+
if (err.code === "ENOENT") return {
|
|
21
|
+
folders: [],
|
|
22
|
+
assignments: {}
|
|
23
|
+
};
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function resolved(id) {
|
|
28
|
+
return `\0${id}`;
|
|
29
|
+
}
|
|
30
|
+
async function findDocs(userCwd, docsDir) {
|
|
31
|
+
const abs = path.resolve(userCwd, docsDir);
|
|
32
|
+
if (!existsSync(abs)) return [];
|
|
33
|
+
return (await fg("*/index.{tsx,jsx,ts,js}", {
|
|
34
|
+
cwd: abs,
|
|
35
|
+
absolute: true,
|
|
36
|
+
onlyFiles: true
|
|
37
|
+
})).sort();
|
|
38
|
+
}
|
|
39
|
+
function toId(absFile, docsRoot) {
|
|
40
|
+
return path.relative(docsRoot, absFile).split(path.sep)[0];
|
|
41
|
+
}
|
|
42
|
+
const META_CREATED_AT_RE = /(?:^|[\s,{])createdAt\s*:\s*['"]([^'"]+)['"]/;
|
|
43
|
+
const META_THEME_RE = /(?:^|[\s,{])theme\s*:\s*['"]([^'"]+)['"]/;
|
|
44
|
+
const META_TITLE_RE = /(?:^|[\s,{])title\s*:\s*(['"`])((?:\\.|(?!\1)[^\\])*)\1/;
|
|
45
|
+
/**
|
|
46
|
+
* Reads `meta` with a brace-matched regex instead of parsing: the plugin runs on
|
|
47
|
+
* every discovery pass, and the fields it needs (sort order, theme back-link,
|
|
48
|
+
* the title search and sorting use without loading every document) are
|
|
49
|
+
* contractually string literals.
|
|
50
|
+
*/
|
|
51
|
+
function extractMeta(src) {
|
|
52
|
+
const empty = {
|
|
53
|
+
theme: null,
|
|
54
|
+
createdAt: null,
|
|
55
|
+
title: null
|
|
56
|
+
};
|
|
57
|
+
const metaStart = src.search(/export\s+const\s+meta\b/);
|
|
58
|
+
if (metaStart === -1) return empty;
|
|
59
|
+
const openBrace = src.indexOf("{", src.indexOf("=", metaStart));
|
|
60
|
+
if (openBrace === -1) return empty;
|
|
61
|
+
let depth = 0;
|
|
62
|
+
let closeBrace = -1;
|
|
63
|
+
for (let i = openBrace; i < src.length; i++) {
|
|
64
|
+
const ch = src[i];
|
|
65
|
+
if (ch === "{") depth++;
|
|
66
|
+
else if (ch === "}") {
|
|
67
|
+
depth--;
|
|
68
|
+
if (depth === 0) {
|
|
69
|
+
closeBrace = i;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (closeBrace === -1) return empty;
|
|
75
|
+
const body = src.slice(openBrace + 1, closeBrace);
|
|
76
|
+
return {
|
|
77
|
+
theme: body.match(META_THEME_RE)?.[1] ?? null,
|
|
78
|
+
createdAt: body.match(META_CREATED_AT_RE)?.[1] ?? null,
|
|
79
|
+
title: unescapeLiteral(body.match(META_TITLE_RE)?.[2] ?? null)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function unescapeLiteral(raw) {
|
|
83
|
+
return raw === null ? null : raw.replace(/\\(.)/g, "$1");
|
|
84
|
+
}
|
|
85
|
+
function parseCreatedAtMs(iso) {
|
|
86
|
+
if (!iso) return null;
|
|
87
|
+
const ms = Date.parse(iso);
|
|
88
|
+
return Number.isFinite(ms) ? ms : null;
|
|
89
|
+
}
|
|
90
|
+
async function readMeta(abs) {
|
|
91
|
+
try {
|
|
92
|
+
return extractMeta(await fs.readFile(abs, "utf8"));
|
|
93
|
+
} catch {
|
|
94
|
+
return {
|
|
95
|
+
theme: null,
|
|
96
|
+
createdAt: null,
|
|
97
|
+
title: null
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const warnedInvalidDocIds = /* @__PURE__ */ new Set();
|
|
102
|
+
async function generateDocsModule(files, docsRoot, isDev) {
|
|
103
|
+
const scanned = await Promise.all(files.map(async (abs) => {
|
|
104
|
+
const meta = await readMeta(abs);
|
|
105
|
+
return {
|
|
106
|
+
id: toId(abs, docsRoot),
|
|
107
|
+
importPath: isDev ? `@fs/${normalizePath(abs).replace(/^\/+/, "")}` : abs,
|
|
108
|
+
theme: meta.theme,
|
|
109
|
+
title: meta.title,
|
|
110
|
+
createdAt: parseCreatedAtMs(meta.createdAt)
|
|
111
|
+
};
|
|
112
|
+
}));
|
|
113
|
+
const entries = scanned.filter((e) => DOC_ID_RE.test(e.id));
|
|
114
|
+
const ignored = scanned.filter((e) => !DOC_ID_RE.test(e.id)).map((e) => e.id);
|
|
115
|
+
const ids = JSON.stringify(entries.map((e) => e.id).sort());
|
|
116
|
+
const createdAtMap = {};
|
|
117
|
+
const themesMap = {};
|
|
118
|
+
const titlesMap = {};
|
|
119
|
+
for (const e of entries) {
|
|
120
|
+
if (e.createdAt !== null) createdAtMap[e.id] = e.createdAt;
|
|
121
|
+
if (e.theme) themesMap[e.id] = e.theme;
|
|
122
|
+
if (e.title) titlesMap[e.id] = e.title;
|
|
123
|
+
}
|
|
124
|
+
const importTokens = JSON.stringify(Object.fromEntries(entries.map((e) => [e.id, 0])));
|
|
125
|
+
const devRuntime = isDev ? `
|
|
126
|
+
const docImportTokens = ${importTokens};
|
|
127
|
+
if (import.meta.hot) {
|
|
128
|
+
import.meta.hot.on('open-doc:doc-changed', (data) => {
|
|
129
|
+
const ids = Array.isArray(data?.docIds) ? data.docIds : data?.docId ? [data.docId] : [];
|
|
130
|
+
const token = Date.now();
|
|
131
|
+
for (const id of ids) {
|
|
132
|
+
if (Object.prototype.hasOwnProperty.call(docImportTokens, id)) docImportTokens[id] = token;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
` : "";
|
|
137
|
+
const cases = entries.map((e) => {
|
|
138
|
+
const importExpr = isDev ? `import(/* @vite-ignore */ import.meta.env.BASE_URL + ${JSON.stringify(`${e.importPath}?t=`)} + docImportTokens[${JSON.stringify(e.id)}])` : `import(${JSON.stringify(e.importPath)})`;
|
|
139
|
+
return ` case ${JSON.stringify(e.id)}: return ${importExpr};`;
|
|
140
|
+
}).join("\n");
|
|
141
|
+
return {
|
|
142
|
+
code: `// virtual:open-doc/docs — generated
|
|
143
|
+
export const docIds = ${ids};
|
|
144
|
+
export const docCreatedAt = ${JSON.stringify(createdAtMap)};
|
|
145
|
+
export const docThemes = ${JSON.stringify(themesMap)};
|
|
146
|
+
export const docTitles = ${JSON.stringify(titlesMap)};
|
|
147
|
+
${devRuntime}
|
|
148
|
+
|
|
149
|
+
export async function loadDoc(id) {
|
|
150
|
+
switch (id) {
|
|
151
|
+
${cases}
|
|
152
|
+
default: throw new Error('Document not found: ' + id);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
`,
|
|
156
|
+
ignored
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function openDocPlugin(opts) {
|
|
160
|
+
const { userCwd, config, coreVersion } = opts;
|
|
161
|
+
const docsDir = config.docsDir ?? "docs";
|
|
162
|
+
const docsRoot = path.resolve(userCwd, docsDir);
|
|
163
|
+
const foldersManifestPath = path.join(docsRoot, ".folders.json");
|
|
164
|
+
let isDev = false;
|
|
165
|
+
let listedIds = "";
|
|
166
|
+
const docIdForEntry = (p) => {
|
|
167
|
+
const roots = [docsRoot];
|
|
168
|
+
try {
|
|
169
|
+
if (existsSync(docsRoot)) {
|
|
170
|
+
const real = realpathSync(docsRoot);
|
|
171
|
+
if (real !== docsRoot) roots.push(real);
|
|
172
|
+
}
|
|
173
|
+
} catch {}
|
|
174
|
+
for (const root of roots) {
|
|
175
|
+
const rel = path.relative(root, p);
|
|
176
|
+
if (rel.startsWith("..") || path.isAbsolute(rel)) continue;
|
|
177
|
+
const parts = rel.split(path.sep);
|
|
178
|
+
if (parts.length !== 2) continue;
|
|
179
|
+
if (!/^index\.(tsx|jsx|ts|js)$/.test(parts[1])) continue;
|
|
180
|
+
return parts[0];
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
};
|
|
184
|
+
let docChangeTimer = null;
|
|
185
|
+
const pendingDocChanges = /* @__PURE__ */ new Set();
|
|
186
|
+
const queueDocChanged = (server, id) => {
|
|
187
|
+
pendingDocChanges.add(id);
|
|
188
|
+
if (docChangeTimer) clearTimeout(docChangeTimer);
|
|
189
|
+
docChangeTimer = setTimeout(() => {
|
|
190
|
+
docChangeTimer = null;
|
|
191
|
+
const mod = server.moduleGraph.getModuleById(resolved(DOCS_VMOD));
|
|
192
|
+
if (mod) server.moduleGraph.invalidateModule(mod);
|
|
193
|
+
const docIds = Array.from(pendingDocChanges);
|
|
194
|
+
pendingDocChanges.clear();
|
|
195
|
+
server.ws.send({
|
|
196
|
+
type: "custom",
|
|
197
|
+
event: "open-doc:doc-changed",
|
|
198
|
+
data: { docIds }
|
|
199
|
+
});
|
|
200
|
+
}, 100);
|
|
201
|
+
};
|
|
202
|
+
return {
|
|
203
|
+
name: "open-doc",
|
|
204
|
+
config(_c, env) {
|
|
205
|
+
isDev = env.command === "serve";
|
|
206
|
+
return { server: { fs: { allow: [userCwd] } } };
|
|
207
|
+
},
|
|
208
|
+
resolveId(id) {
|
|
209
|
+
if (id === DOCS_VMOD) return resolved(DOCS_VMOD);
|
|
210
|
+
if (id === CONFIG_VMOD) return resolved(CONFIG_VMOD);
|
|
211
|
+
if (id === FOLDERS_VMOD) return resolved(FOLDERS_VMOD);
|
|
212
|
+
return null;
|
|
213
|
+
},
|
|
214
|
+
async load(id) {
|
|
215
|
+
if (id === resolved(DOCS_VMOD)) {
|
|
216
|
+
const files = await findDocs(userCwd, docsDir);
|
|
217
|
+
listedIds = JSON.stringify(files.map((file) => toId(file, docsRoot)).sort());
|
|
218
|
+
const { code, ignored } = await generateDocsModule(files, docsRoot, isDev);
|
|
219
|
+
for (const docId of ignored) {
|
|
220
|
+
if (warnedInvalidDocIds.has(docId)) continue;
|
|
221
|
+
warnedInvalidDocIds.add(docId);
|
|
222
|
+
this.warn(`Ignoring document folder "${docId}": ids must match ${DOC_ID_RE} (letters, digits, "-", "_"). Rename it under "${docsDir}/" to a kebab-case id so it shows up.`);
|
|
223
|
+
}
|
|
224
|
+
return code;
|
|
225
|
+
}
|
|
226
|
+
if (id === resolved(CONFIG_VMOD)) {
|
|
227
|
+
const userBuild = config.build ?? {};
|
|
228
|
+
const build = isDev ? {
|
|
229
|
+
showDocBrowser: true,
|
|
230
|
+
allowHtmlExport: true
|
|
231
|
+
} : {
|
|
232
|
+
showDocBrowser: userBuild.showDocBrowser ?? true,
|
|
233
|
+
allowHtmlExport: userBuild.allowHtmlExport ?? true
|
|
234
|
+
};
|
|
235
|
+
return `export default ${JSON.stringify({
|
|
236
|
+
...config,
|
|
237
|
+
build,
|
|
238
|
+
version: coreVersion
|
|
239
|
+
})};\n`;
|
|
240
|
+
}
|
|
241
|
+
if (id === resolved(FOLDERS_VMOD)) {
|
|
242
|
+
const manifest = await readFoldersManifest(foldersManifestPath);
|
|
243
|
+
return `export default ${JSON.stringify(manifest)};\n`;
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
},
|
|
247
|
+
handleHotUpdate(ctx) {
|
|
248
|
+
const docId = docIdForEntry(ctx.file);
|
|
249
|
+
if (!docId) return;
|
|
250
|
+
queueDocChanged(ctx.server, docId);
|
|
251
|
+
return [];
|
|
252
|
+
},
|
|
253
|
+
configureServer(server) {
|
|
254
|
+
const isDocEntry = (p) => docIdForEntry(p) !== null;
|
|
255
|
+
let reloadTimer = null;
|
|
256
|
+
const reload = () => {
|
|
257
|
+
if (reloadTimer) clearTimeout(reloadTimer);
|
|
258
|
+
reloadTimer = setTimeout(() => {
|
|
259
|
+
reloadTimer = null;
|
|
260
|
+
const mod = server.moduleGraph.getModuleById(resolved(DOCS_VMOD));
|
|
261
|
+
if (mod) server.moduleGraph.invalidateModule(mod);
|
|
262
|
+
server.ws.send({ type: "full-reload" });
|
|
263
|
+
}, 150);
|
|
264
|
+
};
|
|
265
|
+
server.watcher.add(docsRoot);
|
|
266
|
+
server.watcher.on("add", (p) => {
|
|
267
|
+
if (isDocEntry(p)) reload();
|
|
268
|
+
});
|
|
269
|
+
server.watcher.on("change", (p) => {
|
|
270
|
+
const docId = docIdForEntry(p);
|
|
271
|
+
if (docId) queueDocChanged(server, docId);
|
|
272
|
+
});
|
|
273
|
+
server.middlewares.use("/__docs-rescan", async (_req, res) => {
|
|
274
|
+
const files = await findDocs(userCwd, docsDir);
|
|
275
|
+
const changed = JSON.stringify(files.map((file) => toId(file, docsRoot)).sort()) !== listedIds;
|
|
276
|
+
if (changed) reload();
|
|
277
|
+
res.setHeader("content-type", "application/json");
|
|
278
|
+
res.end(JSON.stringify({ changed }));
|
|
279
|
+
});
|
|
280
|
+
server.watcher.on("unlink", (p) => {
|
|
281
|
+
if (isDocEntry(p)) reload();
|
|
282
|
+
});
|
|
283
|
+
server.watcher.on("unlinkDir", (p) => {
|
|
284
|
+
if (path.dirname(p) === docsRoot) reload();
|
|
285
|
+
});
|
|
286
|
+
let foldersTimer = null;
|
|
287
|
+
const foldersChanged = () => {
|
|
288
|
+
if (foldersTimer) clearTimeout(foldersTimer);
|
|
289
|
+
foldersTimer = setTimeout(() => {
|
|
290
|
+
foldersTimer = null;
|
|
291
|
+
const mod = server.moduleGraph.getModuleById(resolved(FOLDERS_VMOD));
|
|
292
|
+
if (mod) server.moduleGraph.invalidateModule(mod);
|
|
293
|
+
server.ws.send({
|
|
294
|
+
type: "custom",
|
|
295
|
+
event: "open-doc:files-changed",
|
|
296
|
+
data: {}
|
|
297
|
+
});
|
|
298
|
+
}, 100);
|
|
299
|
+
};
|
|
300
|
+
server.watcher.add(foldersManifestPath);
|
|
301
|
+
for (const event of [
|
|
302
|
+
"add",
|
|
303
|
+
"change",
|
|
304
|
+
"unlink"
|
|
305
|
+
]) server.watcher.on(event, (p) => {
|
|
306
|
+
if (p === foldersManifestPath) foldersChanged();
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
async function loadUserConfig(userCwd) {
|
|
312
|
+
const file = path.join(userCwd, CONFIG_FILE);
|
|
313
|
+
if (!existsSync(file)) return {};
|
|
314
|
+
return (await loadConfigFromFile({
|
|
315
|
+
command: "serve",
|
|
316
|
+
mode: "development"
|
|
317
|
+
}, file, userCwd, "silent"))?.config ?? {};
|
|
318
|
+
}
|
|
319
|
+
//#endregion
|
|
320
|
+
export { loadUserConfig as n, openDocPlugin as r, DOC_ID_RE as t };
|
package/dist/ops/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as Orientation, g as ORIENTATIONS, m as ExportFormat, p as EXPORT_FORMATS, x as PageSizeName, y as PAGE_SIZE_NAMES } from "../flow-CS5apebG.js";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
3
|
import "vite";
|
|
4
4
|
//#region src/vite/routes/context.d.ts
|
|
@@ -93,8 +93,30 @@ declare function revertChange(ctx: ApiContext, docId: string, opts: {
|
|
|
93
93
|
ok: true;
|
|
94
94
|
}>;
|
|
95
95
|
//#endregion
|
|
96
|
+
//#region src/ops/concurrency.d.ts
|
|
97
|
+
/**
|
|
98
|
+
* Deterministic 16-char SHA-256 hex digest of a document's UTF-8 source.
|
|
99
|
+
* Used as a lightweight optimistic concurrency token (`hash` / `expectedHash`)
|
|
100
|
+
* so clients and MCP agents do not need to re-send the full source string.
|
|
101
|
+
*/
|
|
102
|
+
declare function hashSource(source: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* Verifies that `current` on disk still matches what the caller last read,
|
|
105
|
+
* either via full-source comparison (`expected`) or SHA-256 digest (`expectedHash`).
|
|
106
|
+
*/
|
|
107
|
+
declare function assertExpectedSource(current: string, opts?: {
|
|
108
|
+
expected?: string;
|
|
109
|
+
expectedHash?: string;
|
|
110
|
+
}): void;
|
|
111
|
+
/**
|
|
112
|
+
* Serializes async read-modify-write operations on the same file path in FIFO order.
|
|
113
|
+
* Prevents concurrent edits (e.g. over high-latency GCS FUSE mounts or parallel
|
|
114
|
+
* MCP tool calls) from reading the same stale snapshot and overwriting each other.
|
|
115
|
+
*/
|
|
116
|
+
declare function withFileLock<T>(filePath: string, fn: () => Promise<T>): Promise<T>;
|
|
117
|
+
//#endregion
|
|
96
118
|
//#region src/app/lib/diagnostics.d.ts
|
|
97
|
-
type LayoutRule = 'unresolved-ref' | 'page-overflow' | 'off-page' | 'blank-page' | 'oversized-block' | 'orphan-heading' | 'tiny-text' | 'broken-image';
|
|
119
|
+
type LayoutRule = 'unresolved-ref' | 'duplicate-id' | 'heading-skip' | 'page-overflow' | 'off-page' | 'blank-page' | 'oversized-block' | 'orphan-heading' | 'tiny-text' | 'broken-image';
|
|
98
120
|
type LayoutSeverity = 'error' | 'warn';
|
|
99
121
|
type LayoutFinding = {
|
|
100
122
|
/** 1-based sheet the problem is on. */
|
|
@@ -189,23 +211,30 @@ declare function readDocument(ctx: ApiContext, docId: string): Promise<{
|
|
|
189
211
|
id: string;
|
|
190
212
|
entry: string;
|
|
191
213
|
source: string;
|
|
214
|
+
hash: string;
|
|
192
215
|
}>;
|
|
193
216
|
declare function createDocument(ctx: ApiContext, docId: string, source: string): Promise<{
|
|
194
217
|
id: string;
|
|
195
218
|
entry: string;
|
|
219
|
+
hash: string;
|
|
196
220
|
}>;
|
|
197
221
|
/**
|
|
198
|
-
* Whole-file overwrite. `expected`
|
|
199
|
-
*
|
|
200
|
-
*
|
|
222
|
+
* Whole-file overwrite. `expected` (full source) or `expectedHash` (16-char
|
|
223
|
+
* SHA-256 digest from `readDocument`) turns a blind overwrite into an atomic
|
|
224
|
+
* conflict check inside a per-file write lock, keeping two agents (or an agent
|
|
225
|
+
* and a person on GCS FUSE) from clobbering each other.
|
|
201
226
|
*/
|
|
202
|
-
declare function writeDocument(ctx: ApiContext, docId: string, source: string, expected?: string): Promise<{
|
|
227
|
+
declare function writeDocument(ctx: ApiContext, docId: string, source: string, expected?: string, expectedHash?: string): Promise<{
|
|
203
228
|
id: string;
|
|
204
229
|
entry: string;
|
|
230
|
+
hash: string;
|
|
205
231
|
}>;
|
|
206
|
-
declare function renameDocument(ctx: ApiContext, docId: string, rawTitle: unknown
|
|
232
|
+
declare function renameDocument(ctx: ApiContext, docId: string, rawTitle: unknown, opts?: {
|
|
233
|
+
expectedHash?: string;
|
|
234
|
+
}): Promise<{
|
|
207
235
|
id: string;
|
|
208
236
|
title: string;
|
|
237
|
+
hash: string;
|
|
209
238
|
}>;
|
|
210
239
|
declare function duplicateDocument(ctx: ApiContext, docId: string, newId?: string): Promise<{
|
|
211
240
|
id: string;
|
|
@@ -383,6 +412,33 @@ declare function createFromTemplate(ctx: ApiContext, opts: {
|
|
|
383
412
|
entry: string;
|
|
384
413
|
}>;
|
|
385
414
|
//#endregion
|
|
415
|
+
//#region src/app/lib/inspector/format.d.ts
|
|
416
|
+
/**
|
|
417
|
+
* The element panel's Format section, shared by the viewer and the dev server:
|
|
418
|
+
* which style keys it may write, which design tokens each one offers, and what
|
|
419
|
+
* a value has to look like before it is spliced into a document's source.
|
|
420
|
+
*/
|
|
421
|
+
declare const STYLE_PROPS: readonly ["fontFamily", "fontSize", "fontWeight", "fontStyle", "textAlign", "lineHeight", "letterSpacing", "color", "background"];
|
|
422
|
+
type StyleProp = (typeof STYLE_PROPS)[number];
|
|
423
|
+
/** `null` takes the key off the element, so the value comes from wherever it did before. */
|
|
424
|
+
type StyleValue = string | number | null;
|
|
425
|
+
type StyleChanges = Partial<Record<StyleProp, StyleValue>>;
|
|
426
|
+
/** What the source says about one key: a literal, a design token, or code the panel can only show. */
|
|
427
|
+
type StyleSource = {
|
|
428
|
+
kind: 'literal';
|
|
429
|
+
value: string | number;
|
|
430
|
+
} | {
|
|
431
|
+
kind: 'token';
|
|
432
|
+
token: string;
|
|
433
|
+
} | {
|
|
434
|
+
kind: 'code';
|
|
435
|
+
code: string;
|
|
436
|
+
};
|
|
437
|
+
/** `from` names the shared style object the key comes from, when it is not the element's own. */
|
|
438
|
+
type StyleOrigin = StyleSource & {
|
|
439
|
+
from?: string;
|
|
440
|
+
};
|
|
441
|
+
//#endregion
|
|
386
442
|
//#region src/editing/edit-ops.d.ts
|
|
387
443
|
type EditTarget = {
|
|
388
444
|
line: number;
|
|
@@ -414,6 +470,15 @@ type TextEditOutcome = {
|
|
|
414
470
|
error: string;
|
|
415
471
|
};
|
|
416
472
|
//#endregion
|
|
473
|
+
//#region src/editing/style-ops.d.ts
|
|
474
|
+
type StyleEdit = EditTarget & {
|
|
475
|
+
/** The tag the viewer clicked; a mismatch means the location points elsewhere now. */
|
|
476
|
+
tag: string;
|
|
477
|
+
changes: StyleChanges;
|
|
478
|
+
/** What the viewer was shown for each changed key; a write over anything else is refused. */
|
|
479
|
+
expected?: Partial<Record<StyleProp, StyleOrigin | null>>;
|
|
480
|
+
};
|
|
481
|
+
//#endregion
|
|
417
482
|
//#region src/ops/text.d.ts
|
|
418
483
|
type Loc = {
|
|
419
484
|
line: number;
|
|
@@ -428,17 +493,19 @@ declare function readText(ctx: ApiContext, docId: string, locs: Loc[], shown?: s
|
|
|
428
493
|
/**
|
|
429
494
|
* `expected` is the text the caller believes is there; when it no longer
|
|
430
495
|
* matches the write is refused rather than silently overwriting someone else's
|
|
431
|
-
* edit. `
|
|
432
|
-
*
|
|
433
|
-
* is refused rather than dropping the formatting.
|
|
496
|
+
* edit. `expectedHash` optionally verifies the file-level SHA-256 digest.
|
|
497
|
+
* All reads and writes on the same document are serialized via `withFileLock`.
|
|
434
498
|
*/
|
|
435
499
|
declare function writeText(ctx: ApiContext, docId: string, loc: Loc, text: string, opts?: {
|
|
436
500
|
index?: number;
|
|
437
501
|
expected?: string;
|
|
502
|
+
expectedHash?: string;
|
|
503
|
+
shown?: string;
|
|
438
504
|
segments?: TextSegment[];
|
|
439
505
|
prop?: string;
|
|
440
506
|
}): Promise<{
|
|
441
507
|
ok: true;
|
|
508
|
+
hash: string;
|
|
442
509
|
}>;
|
|
443
510
|
/**
|
|
444
511
|
* Several run replacements in one read and one write, so an editing session
|
|
@@ -446,12 +513,30 @@ declare function writeText(ctx: ApiContext, docId: string, loc: Loc, text: strin
|
|
|
446
513
|
* that each re-paginate the document. Per-edit failures are reported, not
|
|
447
514
|
* thrown: the edits that still apply are written.
|
|
448
515
|
*/
|
|
449
|
-
declare function writeTexts(ctx: ApiContext, docId: string, edits: TextEdit[]
|
|
516
|
+
declare function writeTexts(ctx: ApiContext, docId: string, edits: TextEdit[], opts?: {
|
|
517
|
+
expectedHash?: string;
|
|
518
|
+
}): Promise<{
|
|
450
519
|
results: TextEditOutcome[];
|
|
520
|
+
hash: string;
|
|
521
|
+
}>;
|
|
522
|
+
/**
|
|
523
|
+
* One save from the element panel: retyped text and style changes, located
|
|
524
|
+
* against the same read of the file and written once. Per-edit failures are
|
|
525
|
+
* reported, not thrown, like `writeTexts`.
|
|
526
|
+
*/
|
|
527
|
+
declare function writeEdits(ctx: ApiContext, docId: string, texts: TextEdit[], styles: StyleEdit[], opts?: {
|
|
528
|
+
expectedHash?: string;
|
|
529
|
+
}): Promise<{
|
|
530
|
+
texts: TextEditOutcome[];
|
|
531
|
+
styles: TextEditOutcome[];
|
|
532
|
+
hash: string;
|
|
451
533
|
}>;
|
|
452
534
|
/** Leaves a `@doc-comment` marker in the source for a later agent pass to act on. */
|
|
453
|
-
declare function addComment(ctx: ApiContext, docId: string, loc: Loc, note: string, hint?: string
|
|
535
|
+
declare function addComment(ctx: ApiContext, docId: string, loc: Loc, note: string, hint?: string, opts?: {
|
|
536
|
+
expectedHash?: string;
|
|
537
|
+
}): Promise<{
|
|
454
538
|
id: string;
|
|
539
|
+
hash: string;
|
|
455
540
|
}>;
|
|
456
541
|
//#endregion
|
|
457
|
-
export { type ApiContext, type AssetSummary, type ChangesResult, type DiffResult, type DocumentSummary, EXPORT_FORMATS, type ExportFormat, type ExportResult, type ImportMarkdownOptions, type ImportResult, type LayoutFinding, type LayoutReport, type Loc, ORIENTATIONS, OpsError, type Orientation, PAGE_SIZE_NAMES, type PageChange, type PageSizeName, type PageStatus, type Revision, type TemplateSummary, type ThemeSummary, addComment, checkLayout, closeRenderSession, createDocument, createFolder, createFromTemplate, deleteAsset, deleteDocument, diffDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listRevisions, listTemplates, listThemes, makeContext, readChanges, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, revertChange, slugify, suggestDocId, writeAsset, writeDocument, writeText, writeTexts };
|
|
542
|
+
export { type ApiContext, type AssetSummary, type ChangesResult, type DiffResult, type DocumentSummary, EXPORT_FORMATS, type ExportFormat, type ExportResult, type ImportMarkdownOptions, type ImportResult, type LayoutFinding, type LayoutReport, type Loc, ORIENTATIONS, OpsError, type Orientation, PAGE_SIZE_NAMES, type PageChange, type PageSizeName, type PageStatus, type Revision, type TemplateSummary, type ThemeSummary, addComment, assertExpectedSource, checkLayout, closeRenderSession, createDocument, createFolder, createFromTemplate, deleteAsset, deleteDocument, diffDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, hashSource, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listRevisions, listTemplates, listThemes, makeContext, readChanges, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, revertChange, slugify, suggestDocId, withFileLock, writeAsset, writeDocument, writeEdits, writeText, writeTexts };
|
package/dist/ops/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { i as ORIENTATIONS, o as PAGE_SIZE_NAMES, r as EXPORT_FORMATS } from "../sdk-CqNZzbkz.js";
|
|
2
|
-
import { A as
|
|
3
|
-
import { a as importMarkdown, i as renderDocPage, n as closeRenderSession, o as slugify, r as exportDocument, s as diffDocument, t as checkLayout } from "../ops-
|
|
4
|
-
export { EXPORT_FORMATS, ORIENTATIONS, OpsError, PAGE_SIZE_NAMES, addComment, checkLayout, closeRenderSession, createDocument, createFolder, createFromTemplate, deleteAsset, deleteDocument, diffDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listRevisions, listTemplates, listThemes, makeContext, readChanges, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, revertChange, slugify, suggestDocId, writeAsset, writeDocument, writeText, writeTexts };
|
|
2
|
+
import { A as duplicateDocument, C as assertExpectedSource, D as createDocument, E as OpsError, F as resolveEntry, I as writeDocument, L as makeContext, M as listDocuments, N as readDocument, O as deleteDocument, P as renameDocument, S as revertChange, T as withFileLock, _ as readTheme, a as writeText, b as listRevisions, c as listTemplates, d as deleteAsset, f as fileDocument, g as listThemes, h as listFolders, i as writeEdits, j as listDocIds, k as docDir, l as suggestDocId, m as listAssets, n as addComment, o as writeTexts, p as findAssetUsages, r as readText, s as createFromTemplate, u as createFolder, v as writeAsset, w as hashSource, x as readChanges } from "../config-CltJJVsw.js";
|
|
3
|
+
import { a as importMarkdown, i as renderDocPage, n as closeRenderSession, o as slugify, r as exportDocument, s as diffDocument, t as checkLayout } from "../ops-CSR5RlrE.js";
|
|
4
|
+
export { EXPORT_FORMATS, ORIENTATIONS, OpsError, PAGE_SIZE_NAMES, addComment, assertExpectedSource, checkLayout, closeRenderSession, createDocument, createFolder, createFromTemplate, deleteAsset, deleteDocument, diffDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, hashSource, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listRevisions, listTemplates, listThemes, makeContext, readChanges, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, revertChange, slugify, suggestDocId, withFileLock, writeAsset, writeDocument, writeEdits, writeText, writeTexts };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { c as isPageSizeName, i as ORIENTATIONS, o as PAGE_SIZE_NAMES, s as isOrientation } from "./sdk-CqNZzbkz.js";
|
|
2
|
-
import {
|
|
2
|
+
import { t as DOC_ID_RE } from "./open-doc-plugin-DnX5usgI.js";
|
|
3
|
+
import { D as createDocument, E as OpsError, F as resolveEntry, j as listDocIds, t as createViteConfig, y as validateAssetName } from "./config-CltJJVsw.js";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import fs from "node:fs/promises";
|
|
5
6
|
import { existsSync } from "node:fs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./ops-
|
|
3
|
-
import { t as cliContext } from "./context-
|
|
1
|
+
import { c as listTemplates, s as createFromTemplate } from "./config-CltJJVsw.js";
|
|
2
|
+
import "./ops-CSR5RlrE.js";
|
|
3
|
+
import { t as cliContext } from "./context-CWgfsHoE.js";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
//#region src/cli/templates.ts
|
|
6
6
|
/**
|
package/dist/vite/index.d.ts
CHANGED
package/dist/vite/index.js
CHANGED
package/package.json
CHANGED
|
@@ -17,11 +17,11 @@ Read the matching reference **before** using a primitive:
|
|
|
17
17
|
| Primitive | Read before | File |
|
|
18
18
|
| --- | --- | --- |
|
|
19
19
|
| `design` const + `var(--od-*)` tokens | writing any new document | `references/design-system.md` |
|
|
20
|
-
| `flow()` auto-pagination | any body content (the default) | `references/pagination.md` |
|
|
20
|
+
| `flow()` auto-pagination & multi-column | any body content (the default) | `references/pagination.md` |
|
|
21
21
|
| Vertical budget (fixed pages) | laying out a cover or divider by hand | `references/pagination.md` |
|
|
22
|
-
| Tables, stat rows,
|
|
22
|
+
| Tables, stat rows, `<Chart>`, `<Sparkline>`, `<Callout>` | rendering data or callouts | `references/tables-and-charts.md` |
|
|
23
23
|
| Assets + `<ImagePlaceholder>` | importing images or leaving a placeholder | `references/assets.md` |
|
|
24
|
-
| Footnotes, `<Figure>`, `<Ref>`, `<DataTable>` |
|
|
24
|
+
| Footnotes, `<Figure>`, `<Ref>`, `<DataTable>`, `<Cite>`, `<Bibliography>`, `<CodeBlock>` | notes, figures, cross-references, citations, code blocks, or `.csv` | `references/long-form.md` |
|
|
25
25
|
|
|
26
26
|
## Themes
|
|
27
27
|
|
|
@@ -62,6 +62,7 @@ export default [Cover, Body] satisfies DocPage[];
|
|
|
62
62
|
- `meta.pageSize` is `'A4' | 'B4' | 'A3'` (default `'A4'`) and `meta.orientation` is `'portrait' | 'landscape'` (default portrait). **These six combinations are the only sheets there are** — there is no Letter, no A5, no custom size, and no way to set a page's dimensions by hand. The same value drives the on-screen page, the `@page` size when printing, and the HTML export.
|
|
63
63
|
- `meta.lang` is the document's language as a BCP 47 tag — **set it for anything not in English**: `'zh-Hant-TW'`, `'zh-Hans'`, `'ja'`, `'ko'`. Every sheet carries it, so it decides the glyph shapes of shared Han characters, the line-breaking rules (no `,。」` at the start of a line), and the language exported HTML and Word declare. The sheet already sets CJK text properly — strict kinsoku, and an eighth-em gap where a CJK character meets a Latin letter or digit with no space typed — so don't hand-insert spaces for that; a block that must not get the gap takes `textAutospace: 'no-autospace'`.
|
|
64
64
|
- **One document per row of data** (certificates, letters, quotes): `export const records = rows` (an imported `.csv`) makes the document print once per row. Pages read the current row with `useRecord()` or print one value with `<Field name="company" />`; `meta.recordName: 'certificate-{name}'` names each row's file (`{#}` is the row number) and `meta.recordLabel` names rows in the viewer's picker. `open-doc export <id> --each` writes one file per row. A flow section's blocks are fixed when the module loads, so content that varies by row goes **inside** blocks — a block can render nothing for a row — never as a different number of blocks.
|
|
65
|
+
- `meta.watermark` (optional string, e.g. `'CONFIDENTIAL'` or `'DRAFT'`) renders a subtle diagonal watermark across every sheet in the viewer and exports.
|
|
65
66
|
- `meta.createdAt` is an **ISO 8601 string literal** set once when the doc is scaffolded — the home page sorts on it. **Immediately before writing the file, run `node -e "console.log(new Date().toISOString())"` and paste the exact output.** It must stay a plain string literal (no `new Date(...)`): the framework reads it with a regex at build time, it never evaluates the module.
|
|
66
67
|
|
|
67
68
|
## Two ways to fill pages
|
|
@@ -154,11 +155,12 @@ contents list does. Read `references/long-form.md` before using any of them.
|
|
|
154
155
|
content in one unbreakable block. `<ListOfFigures />` / `<ListOfTables />`
|
|
155
156
|
build the lists.
|
|
156
157
|
- **`<Ref to="id" />`** — "Figure 3", plus the page when the target is elsewhere.
|
|
157
|
-
- **`<
|
|
158
|
-
- **`<
|
|
159
|
-
|
|
160
|
-
- **`<
|
|
161
|
-
|
|
158
|
+
- **`<Cite id="…" source="…" />` & `<Bibliography />`** — academic/report citations numbered in order of first appearance (`[1]`), deduplicated by `id`, and listed by `<Bibliography />`.
|
|
159
|
+
- **`<DataTable rows={…} splittable summaryRow>`** — a print-shaped table from an imported `.csv` (supports automatic multi-page splitting with repeated headers when `splittable` is set, plus `summaryRow`, `dataBar`, `'currency'`, and `'delta'` formats).
|
|
160
|
+
- **`<CodeBlock code={…} lang="ts" lineNumbers highlightLines={[…]} caption="…" />`** — zero-dependency syntax-highlighted code block with optional line numbers, highlighted lines, and figure numbering when given `caption`.
|
|
161
|
+
- **`<Callout type="note|tip|warning|danger" title="…">`** — semantic callout box styled with `--od-*` tokens.
|
|
162
|
+
- **`<Diagram chart={…} caption>`** — an architecture, flow, or sequence drawing from an imported `.mmd`. Given a caption it numbers as a figure, like `<Figure>`.
|
|
163
|
+
- **`<Chart data x y caption>` & `<Sparkline data={…} />`** — `bar`, `horizontal-bar`, `line`, `area`, or `pie` charts from rows, plus inline SVG `<Sparkline>` for tables and stat cards. See `references/tables-and-charts.md`.
|
|
162
164
|
|
|
163
165
|
`meta.labels` sets what they are called (`圖`, `表`) — the numbering itself is
|
|
164
166
|
structural.
|
|
@@ -188,13 +190,10 @@ It is compiled to SVG at build time and drawn with the document's own theme
|
|
|
188
190
|
variables, so it prints with the same ink and faces as the prose around it.
|
|
189
191
|
Never reach for an image of a diagram when the diagram can be written.
|
|
190
192
|
|
|
191
|
-
Supported:
|
|
192
|
-
`A([stadium])`, `A[(database)]`, `A{decision}`, `A((circle))`; links `-->`,
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
steps in between. Anything else
|
|
196
|
-
in Mermaid's syntax — subgraphs, class diagrams, sequence diagrams — is not
|
|
197
|
-
supported, and a bad diagram fails the build with the line to fix.
|
|
193
|
+
Supported:
|
|
194
|
+
- `flowchart`/`graph` with `TD` or `LR`; nodes as `A[box]`, `A(round)`, `A([stadium])`, `A[(database)]`, `A{decision}`, `A((circle))`; links `-->`, `---`, `-.->`, `==>` with optional `|labels|`; chains `A --> B --> C`; `subgraph id [Title] ... end` clusters; `%%` comments. A link back to an earlier step is drawn round the side, clear of the steps in between.
|
|
195
|
+
- `sequenceDiagram` with `participant Id as Label`, message arrows (`->>`, `-->>`, `->`, `-->`), and `Note over A,B: text` (or `Note left of` / `Note right of`).
|
|
196
|
+
- Anything else in Mermaid's syntax is not supported, and a bad diagram fails the build with the line to fix.
|
|
198
197
|
|
|
199
198
|
Keep `width` inside the text block: a drawing wider than the column is a layout
|
|
200
199
|
fault, and `open-doc check` reports it as one.
|
|
@@ -416,7 +415,7 @@ confirms it.
|
|
|
416
415
|
- [ ] `docs/<id>/index.tsx` `export default`s a non-empty `DocEntry[]`, with body content in a `flow()` section rather than hand-split pages.
|
|
417
416
|
- [ ] Every page's root fills `100% × 100%` and sets `boxSizing: 'border-box'` with the margin as padding.
|
|
418
417
|
- [ ] **For every fixed page, sum (font_size × line_height × lines) + gaps + 2×margin ≤ page height.** If close, split — or move the content into the flow section. No `overflow: auto` escape hatches.
|
|
419
|
-
- [ ] No block inside a `flow()` section is taller than one page (
|
|
418
|
+
- [ ] No unbreakable block inside a `flow()` section is taller than one page (pass `splittable` on long `<DataTable>` instances so the framework splits rows across pages with repeated headers).
|
|
420
419
|
- [ ] Body type ≥ 13px; nothing on the page under 9px.
|
|
421
420
|
- [ ] Section titles are real `h1`/`h2`/`h3` elements, so the outline and TOC pick them up.
|
|
422
421
|
- [ ] Contents page uses `<TableOfContents />`, not a hand-written list.
|