@open-document/core 0.11.0 → 0.13.0

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.
Files changed (105) hide show
  1. package/dist/{build-BHFGY8eF.js → build-CbgIk6bA.js} +1 -1
  2. package/dist/{check-UEBmDfT_.js → check-BTroj-5Z.js} +3 -3
  3. package/dist/cli/bin.js +58 -34
  4. package/dist/config-BWtOZ1jc.d.ts +45 -0
  5. package/dist/{config-B_pdNbYg.js → config-DKKNIbvO.js} +1458 -983
  6. package/dist/{context-BM9_-u9P.js → context-DXNP8v9I.js} +3 -2
  7. package/dist/deploy-gcp-BUiSuqz7.js +758 -0
  8. package/dist/{dev-DX3QMIRi.js → dev-YXumw5iX.js} +1 -1
  9. package/dist/{diagram-BK4jTZr4.js → diagram-CKf3ptOE.js} +293 -13
  10. package/dist/{diff-DayvbXfX.js → diff-CTFfU4Tz.js} +2 -2
  11. package/dist/{export-BPsXj1i6.js → export-D2QLtF84.js} +11 -4
  12. package/dist/flow-CS5apebG.d.ts +252 -0
  13. package/dist/{import-71wlAsrd.js → import-CcmrFetU.js} +3 -2
  14. package/dist/index.d.ts +155 -59
  15. package/dist/index.js +945 -104
  16. package/dist/open-doc-plugin-DnX5usgI.js +320 -0
  17. package/dist/ops/index.d.ts +112 -3
  18. package/dist/ops/index.js +3 -3
  19. package/dist/{ops-BUo67DaP.js → ops-DmEecq1k.js} +86 -164
  20. package/dist/package-version-C89gtYSk.js +36 -0
  21. package/dist/{preview-D3m1-gUL.js → preview-_mHpBhMk.js} +1 -1
  22. package/dist/templates-MMblHwmT.js +34 -0
  23. package/dist/vite/index.d.ts +1 -1
  24. package/dist/vite/index.js +2 -1
  25. package/package.json +2 -1
  26. package/skills/apply-comments/SKILL.md +3 -1
  27. package/skills/create-doc/SKILL.md +2 -0
  28. package/skills/doc-authoring/SKILL.md +17 -16
  29. package/skills/doc-authoring/references/long-form.md +43 -2
  30. package/skills/doc-authoring/references/pagination.md +14 -2
  31. package/skills/doc-authoring/references/tables-and-charts.md +21 -17
  32. package/src/app/components/browser/browser-ui.tsx +21 -0
  33. package/src/app/components/browser/new-document-dialog.tsx +208 -0
  34. package/src/app/components/callout.tsx +101 -0
  35. package/src/app/components/changes/changes-overlay.tsx +68 -0
  36. package/src/app/components/changes/changes-panel.tsx +341 -0
  37. package/src/app/components/changes/use-changes.ts +85 -0
  38. package/src/app/components/chart.tsx +191 -33
  39. package/src/app/components/code-block.tsx +249 -0
  40. package/src/app/components/comments/comments-overlay.tsx +50 -0
  41. package/src/app/components/comments/comments-panel.tsx +272 -0
  42. package/src/app/components/comments/use-comments.ts +61 -0
  43. package/src/app/components/data-table.tsx +146 -18
  44. package/src/app/components/doc-sidebar.tsx +32 -2
  45. package/src/app/components/flow-page.tsx +57 -8
  46. package/src/app/components/inspector/field-source.tsx +41 -0
  47. package/src/app/components/inspector/inspector.tsx +64 -65
  48. package/src/app/components/numbering.tsx +226 -12
  49. package/src/app/components/overlay-frame.tsx +79 -0
  50. package/src/app/components/page-frame.tsx +46 -0
  51. package/src/app/components/page-placement.ts +68 -0
  52. package/src/app/components/record-picker.tsx +79 -0
  53. package/src/app/components/themes/theme-preview.tsx +5 -4
  54. package/src/app/lib/agent-bridge.ts +29 -1
  55. package/src/app/lib/chart.test.ts +15 -0
  56. package/src/app/lib/chart.ts +134 -9
  57. package/src/app/lib/diagnostics.ts +45 -1
  58. package/src/app/lib/docx/ooxml.test.ts +24 -1
  59. package/src/app/lib/docx/ooxml.ts +27 -1
  60. package/src/app/lib/export-docx.ts +3 -1
  61. package/src/app/lib/export-dom.ts +17 -3
  62. package/src/app/lib/export-html.ts +4 -2
  63. package/src/app/lib/export-image.ts +2 -1
  64. package/src/app/lib/export-pdf.ts +9 -1
  65. package/src/app/lib/flow-measure.test.ts +30 -0
  66. package/src/app/lib/flow-measure.ts +68 -14
  67. package/src/app/lib/flow.test.ts +20 -1
  68. package/src/app/lib/flow.ts +120 -20
  69. package/src/app/lib/i18n-ja/browser.ts +10 -0
  70. package/src/app/lib/i18n-ja/doc.ts +4 -0
  71. package/src/app/lib/i18n-ja/panels.ts +40 -0
  72. package/src/app/lib/i18n-ko/browser.ts +10 -0
  73. package/src/app/lib/i18n-ko/doc.ts +4 -0
  74. package/src/app/lib/i18n-ko/panels.ts +39 -0
  75. package/src/app/lib/i18n-zh-cn/browser.ts +10 -0
  76. package/src/app/lib/i18n-zh-cn/doc.ts +4 -0
  77. package/src/app/lib/i18n-zh-cn/panels.ts +38 -0
  78. package/src/app/lib/i18n-zh-tw/browser.ts +10 -0
  79. package/src/app/lib/i18n-zh-tw/doc.ts +4 -0
  80. package/src/app/lib/i18n-zh-tw/panels.ts +38 -0
  81. package/src/app/lib/labels.ts +29 -10
  82. package/src/app/lib/records.test.ts +38 -0
  83. package/src/app/lib/records.ts +127 -0
  84. package/src/app/lib/sdk.ts +35 -0
  85. package/src/app/lib/use-doc-module.ts +7 -0
  86. package/src/app/lib/use-doc-pages.ts +38 -17
  87. package/src/app/routes/doc.tsx +275 -13
  88. package/src/app/routes/home.tsx +30 -5
  89. package/src/app/styles.css +23 -0
  90. package/templates/blank/index.tsx +63 -0
  91. package/templates/blank/template.json +6 -0
  92. package/templates/certificate/data/recipients.csv +4 -0
  93. package/templates/certificate/index.tsx +128 -0
  94. package/templates/certificate/template.json +6 -0
  95. package/templates/letter/index.tsx +106 -0
  96. package/templates/letter/template.json +5 -0
  97. package/templates/meeting-notes/index.tsx +194 -0
  98. package/templates/meeting-notes/template.json +6 -0
  99. package/templates/proposal/index.tsx +264 -0
  100. package/templates/proposal/template.json +6 -0
  101. package/templates/report/data/metrics.csv +5 -0
  102. package/templates/report/index.tsx +224 -0
  103. package/templates/report/template.json +6 -0
  104. package/dist/config-P61niZMf.d.ts +0 -24
  105. package/dist/sdk-CpDEGRIo.d.ts +0 -138
@@ -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 };
@@ -1,4 +1,4 @@
1
- import { c as ExportFormat, d as Orientation, h as PageSizeName, p as PAGE_SIZE_NAMES, s as EXPORT_FORMATS, u as ORIENTATIONS } from "../sdk-CpDEGRIo.js";
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
@@ -25,8 +25,76 @@ type ApiPluginOptions = {
25
25
  };
26
26
  declare function makeContext(opts: ApiPluginOptions): ApiContext;
27
27
  //#endregion
28
+ //#region src/ops/changes-diff.d.ts
29
+ /**
30
+ * How a change shows on the page: the element is new, rewritten, or something
31
+ * was taken out just before or after it.
32
+ */
33
+ type ChangeMark = 'added' | 'changed' | 'removed-before' | 'removed-after';
34
+ type ChangeTarget = {
35
+ loc: string;
36
+ mark: ChangeMark;
37
+ };
38
+ type Hunk = {
39
+ /** Stable across edits elsewhere in the file, so a revert names the hunk the viewer saw. */
40
+ id: string;
41
+ oldStart: number;
42
+ oldLines: number;
43
+ newStart: number;
44
+ newLines: number;
45
+ removed: string[];
46
+ added: string[];
47
+ /** Elements on the page this hunk touches; empty when it is not drawn (meta, a style const). */
48
+ targets: ChangeTarget[];
49
+ };
50
+ type FileChange = {
51
+ /** Relative to the document's folder: `index.tsx`, `data/rows.csv`. */
52
+ path: string;
53
+ status: 'modified' | 'added' | 'deleted';
54
+ binary: boolean;
55
+ hunks: Hunk[];
56
+ };
57
+ //#endregion
58
+ //#region src/ops/changes.d.ts
59
+ type Revision = {
60
+ commit: string;
61
+ short: string;
62
+ subject: string;
63
+ when: string;
64
+ };
65
+ type ChangesResult = {
66
+ available: false;
67
+ reason: 'no-git' | 'no-repo';
68
+ } | {
69
+ available: true;
70
+ since: string;
71
+ commit: string | null;
72
+ files: FileChange[];
73
+ };
74
+ /**
75
+ * What changed in one document's folder since a revision — the working tree
76
+ * against `since`, untracked files included — with each hunk of the document's
77
+ * own source placed on the elements it touches, so the viewer can mark them.
78
+ */
79
+ declare function readChanges(ctx: ApiContext, docId: string, since?: string): Promise<ChangesResult>;
80
+ /** Recent commits that touched the document, newest first, for choosing what to compare against. */
81
+ declare function listRevisions(ctx: ApiContext, docId: string, limit?: number): Promise<Revision[]>;
82
+ /**
83
+ * Takes one hunk back out of the working tree. The hunk is found again by id
84
+ * in a fresh diff, never trusted from the request, and a source file must still
85
+ * parse afterwards — hunks can depend on each other, and a revert that leaves
86
+ * half a JSX tag behind is refused rather than written.
87
+ */
88
+ declare function revertChange(ctx: ApiContext, docId: string, opts: {
89
+ since?: string;
90
+ file: string;
91
+ hunk: string;
92
+ }): Promise<{
93
+ ok: true;
94
+ }>;
95
+ //#endregion
28
96
  //#region src/app/lib/diagnostics.d.ts
29
- type LayoutRule = 'unresolved-ref' | 'page-overflow' | 'off-page' | 'blank-page' | 'oversized-block' | 'orphan-heading' | 'tiny-text' | 'broken-image';
97
+ type LayoutRule = 'unresolved-ref' | 'duplicate-id' | 'heading-skip' | 'page-overflow' | 'off-page' | 'blank-page' | 'oversized-block' | 'orphan-heading' | 'tiny-text' | 'broken-image';
30
98
  type LayoutSeverity = 'error' | 'warn';
31
99
  type LayoutFinding = {
32
100
  /** 1-based sheet the problem is on. */
@@ -157,6 +225,8 @@ type ImportMarkdownOptions = {
157
225
  theme?: string;
158
226
  pageSize?: string;
159
227
  orientation?: string;
228
+ /** BCP 47 tag; read from the front matter, else detected for Chinese, Japanese and Korean. */
229
+ lang?: string;
160
230
  /** Open with a title page. Defaults to true. */
161
231
  cover?: boolean;
162
232
  /** Insert a self-filling contents page. Defaults to false. */
@@ -196,6 +266,8 @@ type ExportResult = {
196
266
  pageCount: number;
197
267
  /** Written paths, relative to the workspace root. */
198
268
  files: string[];
269
+ /** With `each`: how many rows were written, one copy each. */
270
+ records?: number;
199
271
  };
200
272
  /** Closes the warm browser. Call before the process exits so nothing lingers. */
201
273
  declare function closeRenderSession(): Promise<void>;
@@ -211,9 +283,16 @@ declare function renderDocPage(ctx: ApiContext, docId: string, page: number): Pr
211
283
  mimeType: string;
212
284
  base64: string;
213
285
  }>;
286
+ /**
287
+ * Writes the document's files. With `each`, a document that exports
288
+ * `records` is laid out and written once per row — `name` (or
289
+ * `meta.recordName`) names each row's files.
290
+ */
214
291
  declare function exportDocument(ctx: ApiContext, docId: string, opts?: {
215
292
  format?: ExportFormat;
216
293
  outDir?: string;
294
+ each?: boolean;
295
+ name?: string;
217
296
  }): Promise<ExportResult>;
218
297
  //#endregion
219
298
  //#region src/files/folders.d.ts
@@ -274,6 +353,36 @@ declare function createFolder(ctx: ApiContext, rawName: unknown, rawIcon?: unkno
274
353
  /** Filing only edits assignments — a document id never moves on disk. */
275
354
  declare function fileDocument(ctx: ApiContext, docId: string, folderId: string | null): Promise<void>;
276
355
  //#endregion
356
+ //#region src/ops/templates.d.ts
357
+ type TemplateSummary = {
358
+ /** What `--template` takes. */
359
+ name: string;
360
+ title: string;
361
+ description: string;
362
+ category: string;
363
+ /** Shipped with open-doc, or written in this workspace's `templates/`. */
364
+ source: 'builtin' | 'workspace';
365
+ };
366
+ declare function listTemplates(ctx: ApiContext): Promise<TemplateSummary[]>;
367
+ /**
368
+ * A free id from a title, else the template's name — a title in Chinese has
369
+ * no letters to make one from: `quarterly-report`, then `quarterly-report-2`.
370
+ */
371
+ declare function suggestDocId(bases: string[], taken: Set<string>): string;
372
+ /**
373
+ * A new document copied from a template: its folder as it is, minus the
374
+ * manifest, with the title it was given and today as its creation date — so
375
+ * it sorts as new, not as old as the template.
376
+ */
377
+ declare function createFromTemplate(ctx: ApiContext, opts: {
378
+ template: string;
379
+ docId?: string;
380
+ title?: string;
381
+ }): Promise<{
382
+ id: string;
383
+ entry: string;
384
+ }>;
385
+ //#endregion
277
386
  //#region src/editing/edit-ops.d.ts
278
387
  type EditTarget = {
279
388
  line: number;
@@ -345,4 +454,4 @@ declare function addComment(ctx: ApiContext, docId: string, loc: Loc, note: stri
345
454
  id: string;
346
455
  }>;
347
456
  //#endregion
348
- export { type ApiContext, type AssetSummary, 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 ThemeSummary, addComment, checkLayout, closeRenderSession, createDocument, createFolder, deleteAsset, deleteDocument, diffDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, slugify, writeAsset, writeDocument, writeText, writeTexts };
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 };
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 { O as makeContext, _ as writeDocument, a as writeText, c as createDocument, d as duplicateDocument, f as listDocIds, g as resolveEntry, h as renameDocument, i as readText, l as deleteDocument, m as readDocument, o as writeTexts, p as listDocuments, r as addComment, s as OpsError, u as docDir } from "../config-B_pdNbYg.js";
3
- import { a as listAssets, c as readTheme, d as closeRenderSession, f as exportDocument, g as diffDocument, h as slugify, i as findAssetUsages, l as writeAsset, m as importMarkdown, n as deleteAsset, o as listFolders, p as renderDocPage, r as fileDocument, s as listThemes, t as createFolder, u as checkLayout } from "../ops-BUo67DaP.js";
4
- export { EXPORT_FORMATS, ORIENTATIONS, OpsError, PAGE_SIZE_NAMES, addComment, checkLayout, closeRenderSession, createDocument, createFolder, deleteAsset, deleteDocument, diffDocument, docDir, duplicateDocument, exportDocument, fileDocument, findAssetUsages, importMarkdown, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, renderDocPage, resolveEntry, slugify, writeAsset, writeDocument, writeText, writeTexts };
2
+ import { A as renameDocument, C as createDocument, D as listDocIds, E as duplicateDocument, M as writeDocument, N as makeContext, O as listDocuments, S as OpsError, T as docDir, _ as writeAsset, a as writeTexts, b as readChanges, c as suggestDocId, d as fileDocument, f as findAssetUsages, g as readTheme, h as listThemes, i as writeText, j as resolveEntry, k as readDocument, l as createFolder, m as listFolders, n as addComment, o as createFromTemplate, p as listAssets, r as readText, s as listTemplates, u as deleteAsset, w as deleteDocument, x as revertChange, y as listRevisions } from "../config-DKKNIbvO.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-DmEecq1k.js";
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 };