@open-document/core 0.1.0 → 0.2.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.
- package/dist/{build-BWZJ1gvL.js → build-U81g9Hnk.js} +2 -6
- package/dist/cli/bin.d.ts +1 -1
- package/dist/cli/bin.js +103 -13
- package/dist/{config-DBp4mOOf.js → config-8zkUElGq.js} +114 -66
- package/dist/{config-EBFfKtWH.d.ts → config-CSC5lHsR.d.ts} +3 -2
- package/dist/{design-BJLvOcCO.js → design-IyRSwCtK.js} +1 -2
- package/dist/{dev-CZtw1oqs.js → dev-DwwFT6uX.js} +2 -6
- package/dist/{edit-ops-DSdUroVO.js → edit-ops-D2W2plpc.js} +48 -83
- package/dist/index.d.ts +4 -28
- package/dist/index.js +4 -11
- package/dist/ops/index.d.ts +3 -8
- package/dist/ops/index.js +2 -5
- package/dist/{preview-DUfQl7Ij.js → preview-C_jbySle.js} +2 -6
- package/dist/vite/index.d.ts +3 -4
- package/dist/vite/index.js +3 -5
- package/package.json +8 -6
- package/skills/current-doc/SKILL.md +120 -0
- package/src/app/components/inspector/inspector.tsx +16 -0
- package/src/app/routes/doc.tsx +18 -1
- package/dist/sync-6GTPAt2t.js +0 -86
- package/dist/sync-C6CsPmyK.js +0 -3
|
@@ -5,7 +5,6 @@ import fg from "fast-glob";
|
|
|
5
5
|
import { loadConfigFromFile, normalizePath } from "vite";
|
|
6
6
|
import { parse } from "@babel/parser";
|
|
7
7
|
import { randomUUID } from "node:crypto";
|
|
8
|
-
|
|
9
8
|
//#region src/vite/open-doc-plugin.ts
|
|
10
9
|
const DOC_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
11
10
|
const CONFIG_FILE = "open-doc.config.ts";
|
|
@@ -33,12 +32,11 @@ function resolved$1(id) {
|
|
|
33
32
|
async function findDocs(userCwd, docsDir) {
|
|
34
33
|
const abs = path.resolve(userCwd, docsDir);
|
|
35
34
|
if (!existsSync(abs)) return [];
|
|
36
|
-
|
|
35
|
+
return (await fg("*/index.{tsx,jsx,ts,js}", {
|
|
37
36
|
cwd: abs,
|
|
38
37
|
absolute: true,
|
|
39
38
|
onlyFiles: true
|
|
40
|
-
});
|
|
41
|
-
return hits.sort();
|
|
39
|
+
})).sort();
|
|
42
40
|
}
|
|
43
41
|
function toId(absFile, docsRoot) {
|
|
44
42
|
return path.relative(docsRoot, absFile).split(path.sep)[0];
|
|
@@ -94,7 +92,7 @@ async function readMeta(abs) {
|
|
|
94
92
|
};
|
|
95
93
|
}
|
|
96
94
|
}
|
|
97
|
-
const warnedInvalidDocIds = new Set();
|
|
95
|
+
const warnedInvalidDocIds = /* @__PURE__ */ new Set();
|
|
98
96
|
async function generateDocsModule(files, docsRoot, isDev) {
|
|
99
97
|
const scanned = await Promise.all(files.map(async (abs) => {
|
|
100
98
|
const meta = await readMeta(abs);
|
|
@@ -131,7 +129,8 @@ if (import.meta.hot) {
|
|
|
131
129
|
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)})`;
|
|
132
130
|
return ` case ${JSON.stringify(e.id)}: return ${importExpr};`;
|
|
133
131
|
}).join("\n");
|
|
134
|
-
|
|
132
|
+
return {
|
|
133
|
+
code: `// virtual:open-doc/docs — generated
|
|
135
134
|
export const docIds = ${ids};
|
|
136
135
|
export const docCreatedAt = ${JSON.stringify(createdAtMap)};
|
|
137
136
|
export const docThemes = ${JSON.stringify(themesMap)};
|
|
@@ -143,9 +142,7 @@ ${cases}
|
|
|
143
142
|
default: throw new Error('Document not found: ' + id);
|
|
144
143
|
}
|
|
145
144
|
}
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
code,
|
|
145
|
+
`,
|
|
149
146
|
ignored
|
|
150
147
|
};
|
|
151
148
|
}
|
|
@@ -164,7 +161,7 @@ function openDocPlugin(opts) {
|
|
|
164
161
|
return parts[0];
|
|
165
162
|
};
|
|
166
163
|
let docChangeTimer = null;
|
|
167
|
-
const pendingDocChanges = new Set();
|
|
164
|
+
const pendingDocChanges = /* @__PURE__ */ new Set();
|
|
168
165
|
const queueDocChanged = (server, id) => {
|
|
169
166
|
pendingDocChanges.add(id);
|
|
170
167
|
if (docChangeTimer) clearTimeout(docChangeTimer);
|
|
@@ -195,8 +192,7 @@ function openDocPlugin(opts) {
|
|
|
195
192
|
},
|
|
196
193
|
async load(id) {
|
|
197
194
|
if (id === resolved$1(DOCS_VMOD)) {
|
|
198
|
-
const
|
|
199
|
-
const { code, ignored } = await generateDocsModule(files, docsRoot, isDev);
|
|
195
|
+
const { code, ignored } = await generateDocsModule(await findDocs(userCwd, docsDir), docsRoot, isDev);
|
|
200
196
|
for (const docId of ignored) {
|
|
201
197
|
if (warnedInvalidDocIds.has(docId)) continue;
|
|
202
198
|
warnedInvalidDocIds.add(docId);
|
|
@@ -206,7 +202,7 @@ function openDocPlugin(opts) {
|
|
|
206
202
|
}
|
|
207
203
|
if (id === resolved$1(CONFIG_VMOD)) {
|
|
208
204
|
const userBuild = config.build ?? {};
|
|
209
|
-
const build
|
|
205
|
+
const build = isDev ? {
|
|
210
206
|
showDocBrowser: true,
|
|
211
207
|
allowHtmlExport: true
|
|
212
208
|
} : {
|
|
@@ -215,7 +211,7 @@ function openDocPlugin(opts) {
|
|
|
215
211
|
};
|
|
216
212
|
return `export default ${JSON.stringify({
|
|
217
213
|
...config,
|
|
218
|
-
build
|
|
214
|
+
build,
|
|
219
215
|
version: coreVersion
|
|
220
216
|
})};\n`;
|
|
221
217
|
}
|
|
@@ -281,13 +277,11 @@ function openDocPlugin(opts) {
|
|
|
281
277
|
async function loadUserConfig(userCwd) {
|
|
282
278
|
const file = path.join(userCwd, CONFIG_FILE);
|
|
283
279
|
if (!existsSync(file)) return {};
|
|
284
|
-
|
|
280
|
+
return (await loadConfigFromFile({
|
|
285
281
|
command: "serve",
|
|
286
282
|
mode: "development"
|
|
287
|
-
}, file, userCwd, "silent");
|
|
288
|
-
return loaded?.config ?? {};
|
|
283
|
+
}, file, userCwd, "silent"))?.config ?? {};
|
|
289
284
|
}
|
|
290
|
-
|
|
291
285
|
//#endregion
|
|
292
286
|
//#region src/vite/routes/context.ts
|
|
293
287
|
function makeContext(opts) {
|
|
@@ -342,15 +336,14 @@ function resolveDocPath(userCwd, docsDir, docId) {
|
|
|
342
336
|
/** The entry file that actually exists on disk for a document, or null. */
|
|
343
337
|
function resolveDocEntry(docsRoot, docId) {
|
|
344
338
|
if (!DOC_ID_RE.test(docId)) return null;
|
|
345
|
-
const docDir
|
|
346
|
-
if (!docDir
|
|
339
|
+
const docDir = path.resolve(docsRoot, docId);
|
|
340
|
+
if (!docDir.startsWith(docsRoot + path.sep)) return null;
|
|
347
341
|
for (const name of ENTRY_NAMES$1) {
|
|
348
|
-
const candidate = path.join(docDir
|
|
342
|
+
const candidate = path.join(docDir, name);
|
|
349
343
|
if (existsSync(candidate)) return candidate;
|
|
350
344
|
}
|
|
351
345
|
return null;
|
|
352
346
|
}
|
|
353
|
-
|
|
354
347
|
//#endregion
|
|
355
348
|
//#region src/editing/doc-ops.ts
|
|
356
349
|
function parseSource$1(source) {
|
|
@@ -416,14 +409,11 @@ function setMetaTitle(source, title) {
|
|
|
416
409
|
if (prop.type !== "ObjectProperty") continue;
|
|
417
410
|
const p = prop;
|
|
418
411
|
if (p.computed) continue;
|
|
419
|
-
|
|
420
|
-
if (key !== "title") continue;
|
|
412
|
+
if ((p.key.type === "Identifier" ? p.key.name : p.key.value) !== "title") continue;
|
|
421
413
|
return source.slice(0, p.value.start) + jsString(title) + source.slice(p.value.end);
|
|
422
414
|
}
|
|
423
415
|
const open = object.start + 1;
|
|
424
|
-
const
|
|
425
|
-
const isEmpty = rest.trim() === "";
|
|
426
|
-
const inserted = isEmpty ? `\n title: ${jsString(title)},\n` : `\n title: ${jsString(title)},`;
|
|
416
|
+
const inserted = source.slice(open, object.end - 1).trim() === "" ? `\n title: ${jsString(title)},\n` : `\n title: ${jsString(title)},`;
|
|
427
417
|
return source.slice(0, open) + inserted + source.slice(open);
|
|
428
418
|
}
|
|
429
419
|
function readMetaTitle(source) {
|
|
@@ -436,8 +426,7 @@ function readMetaTitle(source) {
|
|
|
436
426
|
if (prop.type !== "ObjectProperty") continue;
|
|
437
427
|
const p = prop;
|
|
438
428
|
if (p.computed) continue;
|
|
439
|
-
|
|
440
|
-
if (key !== "title") continue;
|
|
429
|
+
if ((p.key.type === "Identifier" ? p.key.name : p.key.value) !== "title") continue;
|
|
441
430
|
if (p.value.type !== "StringLiteral") return null;
|
|
442
431
|
return typeof p.value.value === "string" ? p.value.value : null;
|
|
443
432
|
}
|
|
@@ -457,7 +446,6 @@ function nextCopyId(baseId, taken) {
|
|
|
457
446
|
function copyTitle(title) {
|
|
458
447
|
return /\(copy( \d+)?\)$/.test(title) ? title : `${title} (copy)`;
|
|
459
448
|
}
|
|
460
|
-
|
|
461
449
|
//#endregion
|
|
462
450
|
//#region src/files/folders.ts
|
|
463
451
|
const FOLDER_ID_RE = /^f-[a-f0-9]{8}$/;
|
|
@@ -497,7 +485,7 @@ function validateName(v) {
|
|
|
497
485
|
function validateReorder(v, current) {
|
|
498
486
|
if (!Array.isArray(v) || v.length !== current.length) return null;
|
|
499
487
|
const known = new Set(current.map((f) => f.id));
|
|
500
|
-
const seen = new Set();
|
|
488
|
+
const seen = /* @__PURE__ */ new Set();
|
|
501
489
|
const out = [];
|
|
502
490
|
for (const id of v) {
|
|
503
491
|
if (typeof id !== "string" || !FOLDER_ID_RE.test(id)) return null;
|
|
@@ -527,7 +515,6 @@ function validateIcon(v) {
|
|
|
527
515
|
}
|
|
528
516
|
return null;
|
|
529
517
|
}
|
|
530
|
-
|
|
531
518
|
//#endregion
|
|
532
519
|
//#region src/ops/documents.ts
|
|
533
520
|
/**
|
|
@@ -536,6 +523,7 @@ function validateIcon(v) {
|
|
|
536
523
|
* and a browser calling `/__docs` end up in exactly the same code.
|
|
537
524
|
*/
|
|
538
525
|
var OpsError = class extends Error {
|
|
526
|
+
status;
|
|
539
527
|
constructor(status, message) {
|
|
540
528
|
super(message);
|
|
541
529
|
this.status = status;
|
|
@@ -564,8 +552,7 @@ function resolveEntry(ctx, docId) {
|
|
|
564
552
|
}
|
|
565
553
|
async function listDocIds(ctx) {
|
|
566
554
|
try {
|
|
567
|
-
|
|
568
|
-
return entries.filter((e) => e.isDirectory() && DOC_ID_RE.test(e.name)).map((e) => e.name).sort();
|
|
555
|
+
return (await fs.readdir(ctx.docsRoot, { withFileTypes: true })).filter((e) => e.isDirectory() && DOC_ID_RE.test(e.name)).map((e) => e.name).sort();
|
|
569
556
|
} catch {
|
|
570
557
|
return [];
|
|
571
558
|
}
|
|
@@ -573,9 +560,7 @@ async function listDocIds(ctx) {
|
|
|
573
560
|
/** Reads what the doc declares without executing it — a regex over `export const meta`. */
|
|
574
561
|
function readMetaField(source, field) {
|
|
575
562
|
const re = new RegExp(`${field}\\s*:\\s*(['"\`])((?:\\\\.|(?!\\1).)*)\\1`);
|
|
576
|
-
|
|
577
|
-
const match = inMeta.match(re);
|
|
578
|
-
return match?.[2];
|
|
563
|
+
return source.slice(source.indexOf("export const meta")).match(re)?.[2];
|
|
579
564
|
}
|
|
580
565
|
async function listDocuments(ctx) {
|
|
581
566
|
const ids = await listDocIds(ctx);
|
|
@@ -625,8 +610,7 @@ async function writeDocument(ctx, docId, source, expected) {
|
|
|
625
610
|
const entry = resolveEntry(ctx, docId);
|
|
626
611
|
if (!entry) throw new OpsError(404, `document not found: ${docId}`);
|
|
627
612
|
if (expected !== void 0) {
|
|
628
|
-
|
|
629
|
-
if (current !== expected) throw new OpsError(409, "document changed on disk since it was read");
|
|
613
|
+
if (await fs.readFile(entry, "utf8") !== expected) throw new OpsError(409, "document changed on disk since it was read");
|
|
630
614
|
}
|
|
631
615
|
await fs.writeFile(entry, source, "utf8");
|
|
632
616
|
return {
|
|
@@ -686,11 +670,10 @@ async function deleteDocument(ctx, docId) {
|
|
|
686
670
|
await writeManifest(ctx.manifestPath, manifest);
|
|
687
671
|
}
|
|
688
672
|
}
|
|
689
|
-
|
|
690
673
|
//#endregion
|
|
691
674
|
//#region src/files/assets.ts
|
|
692
675
|
const GLOBAL_SCOPE = "@global";
|
|
693
|
-
const ASSET_MAX_BYTES =
|
|
676
|
+
const ASSET_MAX_BYTES = 26214400;
|
|
694
677
|
const ASSET_FORBIDDEN_RE = /[\x00-\x1F\x7F/\\:*?"<>|]/;
|
|
695
678
|
const MIME_BY_EXT = {
|
|
696
679
|
png: "image/png",
|
|
@@ -732,14 +715,14 @@ function validateAssetName(v) {
|
|
|
732
715
|
}
|
|
733
716
|
function resolveAssetsDir(docsRoot, docId) {
|
|
734
717
|
if (!DOC_ID_RE.test(docId)) return null;
|
|
735
|
-
const docDir
|
|
736
|
-
if (!docDir
|
|
737
|
-
const assetsDir = path.resolve(docDir
|
|
738
|
-
if (assetsDir !== path.join(docDir
|
|
718
|
+
const docDir = path.resolve(docsRoot, docId);
|
|
719
|
+
if (!docDir.startsWith(docsRoot + path.sep)) return null;
|
|
720
|
+
const assetsDir = path.resolve(docDir, "assets");
|
|
721
|
+
if (assetsDir !== path.join(docDir, "assets")) return null;
|
|
739
722
|
return assetsDir;
|
|
740
723
|
}
|
|
741
724
|
function resolveScopedAssetsDir(docsRoot, globalAssetsRoot, scope) {
|
|
742
|
-
if (scope ===
|
|
725
|
+
if (scope === "@global") return globalAssetsRoot;
|
|
743
726
|
return resolveAssetsDir(docsRoot, scope);
|
|
744
727
|
}
|
|
745
728
|
function resolveScopedAssetFile(docsRoot, globalAssetsRoot, scope, filename) {
|
|
@@ -752,7 +735,7 @@ function resolveScopedAssetFile(docsRoot, globalAssetsRoot, scope, filename) {
|
|
|
752
735
|
}
|
|
753
736
|
/** How a document imports an asset — the string we look for when counting usages. */
|
|
754
737
|
function assetImportPath(scope, filename) {
|
|
755
|
-
return scope ===
|
|
738
|
+
return scope === "@global" ? `@assets/${filename}` : `./assets/${filename}`;
|
|
756
739
|
}
|
|
757
740
|
function escapeRegExp(value) {
|
|
758
741
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -769,7 +752,6 @@ function countAssetUsages(source, importPath) {
|
|
|
769
752
|
function findReferencedAssets(source, importPaths) {
|
|
770
753
|
return importPaths.filter((p) => countAssetUsages(source, p) > 0);
|
|
771
754
|
}
|
|
772
|
-
|
|
773
755
|
//#endregion
|
|
774
756
|
//#region src/vite/themes-plugin.ts
|
|
775
757
|
const THEMES_VMOD = "virtual:open-doc/themes";
|
|
@@ -802,17 +784,15 @@ function parseFrontmatter(raw, themeId) {
|
|
|
802
784
|
async function findThemes(userCwd, themesDir) {
|
|
803
785
|
const abs = path.resolve(userCwd, themesDir);
|
|
804
786
|
if (!existsSync(abs)) return [];
|
|
805
|
-
|
|
787
|
+
return (await fg("*.md", {
|
|
806
788
|
cwd: abs,
|
|
807
789
|
absolute: true,
|
|
808
790
|
onlyFiles: true
|
|
809
|
-
});
|
|
810
|
-
return hits.sort();
|
|
791
|
+
})).sort();
|
|
811
792
|
}
|
|
812
793
|
async function readTheme(mdAbs, themesRoot) {
|
|
813
794
|
const id = path.basename(mdAbs, ".md");
|
|
814
|
-
const
|
|
815
|
-
const { fm, body } = parseFrontmatter(raw, id);
|
|
795
|
+
const { fm, body } = parseFrontmatter(await fs.readFile(mdAbs, "utf8"), id);
|
|
816
796
|
let demoAbs = null;
|
|
817
797
|
for (const cand of [
|
|
818
798
|
`${id}.demo.tsx`,
|
|
@@ -878,8 +858,7 @@ function themesPlugin(opts) {
|
|
|
878
858
|
async load(id) {
|
|
879
859
|
if (id !== resolved(THEMES_VMOD)) return null;
|
|
880
860
|
const files = await findThemes(userCwd, themesDir);
|
|
881
|
-
|
|
882
|
-
return generateThemesModule(themes, isDev);
|
|
861
|
+
return generateThemesModule(await Promise.all(files.map((f) => readTheme(f, themesRoot))), isDev);
|
|
883
862
|
},
|
|
884
863
|
configureServer(server) {
|
|
885
864
|
const isThemeFile = (p) => {
|
|
@@ -909,7 +888,6 @@ function themesPlugin(opts) {
|
|
|
909
888
|
}
|
|
910
889
|
};
|
|
911
890
|
}
|
|
912
|
-
|
|
913
891
|
//#endregion
|
|
914
892
|
//#region src/editing/babel-walk.ts
|
|
915
893
|
function parseSource(code) {
|
|
@@ -980,7 +958,6 @@ function findJsxOnLine(ast, line, column) {
|
|
|
980
958
|
});
|
|
981
959
|
return hits.sort((a, b) => a.distance - b.distance).map((hit) => hit.node);
|
|
982
960
|
}
|
|
983
|
-
|
|
984
961
|
//#endregion
|
|
985
962
|
//#region src/editing/comments.ts
|
|
986
963
|
const MARKER_RE = /\{\/\*\s*@doc-comment\s+id="(c-[a-f0-9]+)"\s+ts="([^"]+)"\s+text="([A-Za-z0-9_-]+={0,2})"\s*\*\/\}/;
|
|
@@ -1014,11 +991,10 @@ function newCommentId() {
|
|
|
1014
991
|
return `c-${randomUUID().replace(/-/g, "").slice(0, 8)}`;
|
|
1015
992
|
}
|
|
1016
993
|
function markerFor(id, ts, note, hint) {
|
|
1017
|
-
|
|
994
|
+
return `{/* @doc-comment id="${id}" ts="${ts}" text="${b64urlEncode(JSON.stringify(hint ? {
|
|
1018
995
|
note,
|
|
1019
996
|
hint
|
|
1020
|
-
} : { note }))
|
|
1021
|
-
return `{/* @doc-comment id="${id}" ts="${ts}" text="${payload}" */}`;
|
|
997
|
+
} : { note }))}" */}`;
|
|
1022
998
|
}
|
|
1023
999
|
function markerPattern(id) {
|
|
1024
1000
|
return `\\{\\/\\*\\s*@doc-comment\\s+id="${id}"\\s+ts="[^"]+"\\s+text="[A-Za-z0-9_\\-]+={0,2}"\\s*\\*\\/\\}`;
|
|
@@ -1038,8 +1014,7 @@ function removeMarker(source, id) {
|
|
|
1038
1014
|
}
|
|
1039
1015
|
function indentOfLine(source, offset) {
|
|
1040
1016
|
const lineStart = source.lastIndexOf("\n", offset - 1) + 1;
|
|
1041
|
-
|
|
1042
|
-
return match?.[0] ?? "";
|
|
1017
|
+
return /^[ \t]*/.exec(source.slice(lineStart, offset))?.[0] ?? "";
|
|
1043
1018
|
}
|
|
1044
1019
|
/**
|
|
1045
1020
|
* Splices the marker in as the **first child** of the target element. A
|
|
@@ -1057,15 +1032,13 @@ function insertMarker(source, target, note, hint) {
|
|
|
1057
1032
|
if (opening.selfClosing === true) return null;
|
|
1058
1033
|
const offset = opening.end;
|
|
1059
1034
|
const id = newCommentId();
|
|
1060
|
-
const marker = markerFor(id, new Date().toISOString(), note, hint);
|
|
1035
|
+
const marker = markerFor(id, (/* @__PURE__ */ new Date()).toISOString(), note, hint);
|
|
1061
1036
|
const indent = indentOfLine(source, element.start ?? offset);
|
|
1062
|
-
const next = `${source.slice(0, offset)}\n${indent} ${marker}${source.slice(offset)}`;
|
|
1063
1037
|
return {
|
|
1064
|
-
source:
|
|
1038
|
+
source: `${source.slice(0, offset)}\n${indent} ${marker}${source.slice(offset)}`,
|
|
1065
1039
|
id
|
|
1066
1040
|
};
|
|
1067
1041
|
}
|
|
1068
|
-
|
|
1069
1042
|
//#endregion
|
|
1070
1043
|
//#region src/editing/edit-ops.ts
|
|
1071
1044
|
/** JSX text is written literally; only these characters have to be escaped. */
|
|
@@ -1080,10 +1053,7 @@ function jsxChildren(element) {
|
|
|
1080
1053
|
}
|
|
1081
1054
|
function labelOf(node) {
|
|
1082
1055
|
if (node.type === "JSXExpressionContainer") return "{…}";
|
|
1083
|
-
if (node.type === "JSXElement") {
|
|
1084
|
-
const name = node.openingElement?.name;
|
|
1085
|
-
return `<${name?.name ?? "element"}>`;
|
|
1086
|
-
}
|
|
1056
|
+
if (node.type === "JSXElement") return `<${(node.openingElement?.name)?.name ?? "element"}>`;
|
|
1087
1057
|
return "…";
|
|
1088
1058
|
}
|
|
1089
1059
|
/** Text children with content, in document order. */
|
|
@@ -1114,15 +1084,12 @@ function partsOf(element) {
|
|
|
1114
1084
|
function describe(element) {
|
|
1115
1085
|
const parts = partsOf(element);
|
|
1116
1086
|
const texts = parts.filter((part) => part.kind === "text");
|
|
1117
|
-
if (texts.length === 0) {
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
reason: generated ? "text is produced by code — edit whatever feeds it" : "element has no text of its own"
|
|
1124
|
-
};
|
|
1125
|
-
}
|
|
1087
|
+
if (texts.length === 0) return {
|
|
1088
|
+
editable: false,
|
|
1089
|
+
text: "",
|
|
1090
|
+
parts,
|
|
1091
|
+
reason: parts.some((part) => part.kind === "markup" && part.label === "{…}") ? "text is produced by code — edit whatever feeds it" : "element has no text of its own"
|
|
1092
|
+
};
|
|
1126
1093
|
return {
|
|
1127
1094
|
editable: true,
|
|
1128
1095
|
text: texts.map((part) => part.value).join(" "),
|
|
@@ -1214,12 +1181,10 @@ function replaceTextAt(source, target, text, opts = {}) {
|
|
|
1214
1181
|
};
|
|
1215
1182
|
const leading = raw.match(/^\s*/)?.[0] ?? "";
|
|
1216
1183
|
const trailing = raw.match(/\s*$/)?.[0] ?? "";
|
|
1217
|
-
const next = source.slice(0, child.start) + leading + escapeJsxText(text) + trailing + source.slice(child.end);
|
|
1218
1184
|
return {
|
|
1219
1185
|
ok: true,
|
|
1220
|
-
source:
|
|
1186
|
+
source: source.slice(0, child.start) + leading + escapeJsxText(text) + trailing + source.slice(child.end)
|
|
1221
1187
|
};
|
|
1222
1188
|
}
|
|
1223
|
-
|
|
1224
1189
|
//#endregion
|
|
1225
|
-
export {
|
|
1190
|
+
export { writeDocument as A, readBody as B, docDir as C, readDocument as D, listDocuments as E, validateName as F, openDocPlugin as G, resolveDocPath as H, validateReorder as I, writeManifest as L, newFolderId as M, readManifest as N, renameDocument as O, validateIcon as P, json as R, deleteDocument as S, listDocIds as T, DOC_ID_RE as U, resolveDocEntry as V, loadUserConfig as W, resolveScopedAssetFile as _, removeMarker as a, OpsError as b, parseFrontmatter as c, GLOBAL_SCOPE as d, assetCreatedAt as f, mimeForFilename as g, findReferencedAssets as h, parseMarkers as i, FOLDER_ID_RE as j, resolveEntry as k, themesPlugin as l, countAssetUsages as m, resolveTextTarget as n, parseSource as o, assetImportPath as p, insertMarker as r, walkJsx as s, replaceTextAt as t, ASSET_MAX_BYTES as u, resolveScopedAssetsDir as v, duplicateDocument as w, createDocument as x, validateAssetName as y, makeContext as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as react0 from "react";
|
|
3
|
-
import * as react2 from "react";
|
|
1
|
+
import { n as OpenDocConfig, t as OpenDocBuildConfig } from "./config-CSC5lHsR.js";
|
|
4
2
|
import { CSSProperties, ComponentType, ReactNode } from "react";
|
|
5
|
-
|
|
6
3
|
//#region src/app/components/image-placeholder.d.ts
|
|
7
4
|
type ImagePlaceholderProps = {
|
|
8
5
|
/** What the final image should show — the user reads this when replacing it. */
|
|
@@ -17,14 +14,7 @@ type ImagePlaceholderProps = {
|
|
|
17
14
|
* product screenshot). Use it instead of inventing filler — never for
|
|
18
15
|
* decoration.
|
|
19
16
|
*/
|
|
20
|
-
declare function ImagePlaceholder({
|
|
21
|
-
hint,
|
|
22
|
-
width,
|
|
23
|
-
height,
|
|
24
|
-
style,
|
|
25
|
-
className
|
|
26
|
-
}: ImagePlaceholderProps): react0.JSX.Element;
|
|
27
|
-
|
|
17
|
+
declare function ImagePlaceholder({ hint, width, height, style, className }: ImagePlaceholderProps): import("react").JSX.Element;
|
|
28
18
|
//#endregion
|
|
29
19
|
//#region src/app/components/table-of-contents.d.ts
|
|
30
20
|
type TableOfContentsProps = {
|
|
@@ -45,15 +35,7 @@ type TableOfContentsProps = {
|
|
|
45
35
|
* first pass and populated on the next — including during PDF/HTML export,
|
|
46
36
|
* which scans before serializing.
|
|
47
37
|
*/
|
|
48
|
-
declare function TableOfContents({
|
|
49
|
-
maxLevel,
|
|
50
|
-
showPageNumbers,
|
|
51
|
-
includeOwnPage,
|
|
52
|
-
indent,
|
|
53
|
-
style,
|
|
54
|
-
className
|
|
55
|
-
}: TableOfContentsProps): react2.JSX.Element;
|
|
56
|
-
|
|
38
|
+
declare function TableOfContents({ maxLevel, showPageNumbers, includeOwnPage, indent, style, className }: TableOfContentsProps): import("react").JSX.Element;
|
|
57
39
|
//#endregion
|
|
58
40
|
//#region src/app/lib/design.d.ts
|
|
59
41
|
type DesignPalette = {
|
|
@@ -89,7 +71,6 @@ type DesignSystem = {
|
|
|
89
71
|
declare function designToCssVars(d: DesignSystem): Record<string, string>;
|
|
90
72
|
declare function cssVarsToString(vars: Record<string, string>): string;
|
|
91
73
|
declare const defaultDesign: DesignSystem;
|
|
92
|
-
|
|
93
74
|
//#endregion
|
|
94
75
|
//#region src/app/lib/sdk.d.ts
|
|
95
76
|
type PageSizeName = 'A4' | 'Letter' | 'A5' | 'Legal';
|
|
@@ -143,7 +124,6 @@ type DocModule = {
|
|
|
143
124
|
design?: DesignSystem;
|
|
144
125
|
};
|
|
145
126
|
declare function resolvePageGeometry(meta?: DocMeta): PageGeometry;
|
|
146
|
-
|
|
147
127
|
//#endregion
|
|
148
128
|
//#region src/app/lib/flow.d.ts
|
|
149
129
|
/**
|
|
@@ -177,10 +157,8 @@ type PaginationResult = {
|
|
|
177
157
|
* next page. Blocks are atomic; nothing is split mid-block.
|
|
178
158
|
*/
|
|
179
159
|
declare function paginateBlocks(blocks: BlockMetrics[], available: number): PaginationResult;
|
|
180
|
-
|
|
181
160
|
//#endregion
|
|
182
161
|
//#region src/app/lib/outline.d.ts
|
|
183
|
-
/** Blocks of the first flow section, for thumbnails that skip measurement. */
|
|
184
162
|
type OutlineEntry = {
|
|
185
163
|
id: string;
|
|
186
164
|
text: string;
|
|
@@ -194,13 +172,11 @@ type OutlineEntry = {
|
|
|
194
172
|
* has run.
|
|
195
173
|
*/
|
|
196
174
|
declare function useDocOutline(): OutlineEntry[];
|
|
197
|
-
|
|
198
175
|
//#endregion
|
|
199
176
|
//#region src/app/lib/page-context.d.ts
|
|
200
177
|
/** 1-based page number of the page currently rendering. `0` outside a page. */
|
|
201
178
|
declare function useDocPageNumber(): number;
|
|
202
179
|
/** Total page count of the document being rendered. `0` outside a page. */
|
|
203
180
|
declare function useDocPageCount(): number;
|
|
204
|
-
|
|
205
181
|
//#endregion
|
|
206
|
-
export { BlockMetrics, DEFAULT_PAGE_SIZE, DesignFonts, DesignPalette, DesignSystem, DesignTypeScale, DocEntry, DocMeta, DocModule, DocPage, FlowSection, ImagePlaceholder, ImagePlaceholderProps, OpenDocBuildConfig, OpenDocConfig, Orientation, OutlineEntry, PAGE_SIZES, PageGeometry, PageSizeName, PaginationResult, TableOfContents, TableOfContentsProps, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, paginateBlocks, resolvePageGeometry, useDocOutline, useDocPageCount, useDocPageNumber };
|
|
182
|
+
export { type BlockMetrics, DEFAULT_PAGE_SIZE, type DesignFonts, type DesignPalette, type DesignSystem, type DesignTypeScale, type DocEntry, type DocMeta, type DocModule, type DocPage, type FlowSection, ImagePlaceholder, type ImagePlaceholderProps, type OpenDocBuildConfig, type OpenDocConfig, type Orientation, type OutlineEntry, PAGE_SIZES, type PageGeometry, type PageSizeName, type PaginationResult, TableOfContents, type TableOfContentsProps, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, paginateBlocks, resolvePageGeometry, useDocOutline, useDocPageCount, useDocPageNumber };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as defaultDesign, r as designToCssVars, t as cssVarsToString } from "./design-IyRSwCtK.js";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Children, Fragment as Fragment$1, createContext, isValidElement, useContext, useSyncExternalStore } from "react";
|
|
4
|
-
|
|
5
4
|
//#region src/app/components/image-placeholder.tsx
|
|
6
5
|
/**
|
|
7
6
|
* Stands in for an image the user has to supply (a chart from their data, a
|
|
@@ -33,14 +32,13 @@ function ImagePlaceholder({ hint, width = "100%", height = 200, style, className
|
|
|
33
32
|
children: hint
|
|
34
33
|
});
|
|
35
34
|
}
|
|
36
|
-
|
|
37
35
|
//#endregion
|
|
38
36
|
//#region src/app/lib/outline.ts
|
|
39
37
|
const GLOBAL_KEY$1 = "__open_doc_outline_store__";
|
|
40
38
|
const g$1 = globalThis;
|
|
41
39
|
if (!g$1[GLOBAL_KEY$1]) g$1[GLOBAL_KEY$1] = {
|
|
42
40
|
snapshot: [],
|
|
43
|
-
listeners: new Set()
|
|
41
|
+
listeners: /* @__PURE__ */ new Set()
|
|
44
42
|
};
|
|
45
43
|
const store = g$1[GLOBAL_KEY$1];
|
|
46
44
|
function getOutline() {
|
|
@@ -58,7 +56,6 @@ function subscribe(listener) {
|
|
|
58
56
|
function useDocOutline() {
|
|
59
57
|
return useSyncExternalStore(subscribe, getOutline, getOutline);
|
|
60
58
|
}
|
|
61
|
-
|
|
62
59
|
//#endregion
|
|
63
60
|
//#region src/app/lib/page-context.tsx
|
|
64
61
|
const GLOBAL_KEY = "__open_doc_page_context__";
|
|
@@ -75,7 +72,6 @@ function useDocPageCount() {
|
|
|
75
72
|
const ctx = useContext(PageContext);
|
|
76
73
|
return ctx ? ctx.total : 0;
|
|
77
74
|
}
|
|
78
|
-
|
|
79
75
|
//#endregion
|
|
80
76
|
//#region src/app/components/table-of-contents.tsx
|
|
81
77
|
/**
|
|
@@ -121,7 +117,6 @@ function TableOfContents({ maxLevel = 2, showPageNumbers = true, includeOwnPage
|
|
|
121
117
|
}, entry.id))
|
|
122
118
|
});
|
|
123
119
|
}
|
|
124
|
-
|
|
125
120
|
//#endregion
|
|
126
121
|
//#region src/app/lib/flow.ts
|
|
127
122
|
/**
|
|
@@ -195,7 +190,6 @@ function paginateBlocks(blocks, available) {
|
|
|
195
190
|
overflowing
|
|
196
191
|
};
|
|
197
192
|
}
|
|
198
|
-
|
|
199
193
|
//#endregion
|
|
200
194
|
//#region src/app/lib/sdk.ts
|
|
201
195
|
/**
|
|
@@ -227,7 +221,7 @@ const PAGE_SIZES = {
|
|
|
227
221
|
};
|
|
228
222
|
const DEFAULT_PAGE_SIZE = "A4";
|
|
229
223
|
function resolvePageGeometry(meta) {
|
|
230
|
-
const size = PAGE_SIZES[meta?.pageSize ??
|
|
224
|
+
const size = PAGE_SIZES[meta?.pageSize ?? "A4"] ?? PAGE_SIZES["A4"];
|
|
231
225
|
const landscape = meta?.orientation === "landscape";
|
|
232
226
|
return {
|
|
233
227
|
width: landscape ? size.height : size.width,
|
|
@@ -235,6 +229,5 @@ function resolvePageGeometry(meta) {
|
|
|
235
229
|
css: landscape ? `${size.css} landscape` : size.css
|
|
236
230
|
};
|
|
237
231
|
}
|
|
238
|
-
|
|
239
232
|
//#endregion
|
|
240
|
-
export { DEFAULT_PAGE_SIZE, ImagePlaceholder, PAGE_SIZES, TableOfContents, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, paginateBlocks, resolvePageGeometry, useDocOutline, useDocPageCount, useDocPageNumber };
|
|
233
|
+
export { DEFAULT_PAGE_SIZE, ImagePlaceholder, PAGE_SIZES, TableOfContents, cssVarsToString, defaultDesign, designToCssVars, flow, isFlowSection, paginateBlocks, resolvePageGeometry, useDocOutline, useDocPageCount, useDocPageNumber };
|
package/dist/ops/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import "vite";
|
|
2
|
-
import "node:http";
|
|
3
|
-
|
|
4
2
|
//#region src/vite/routes/context.d.ts
|
|
5
3
|
type ApiContext = {
|
|
6
4
|
userCwd: string;
|
|
@@ -17,7 +15,8 @@ type ApiPluginOptions = {
|
|
|
17
15
|
assetsDir?: string;
|
|
18
16
|
coreVersion: string;
|
|
19
17
|
};
|
|
20
|
-
declare function makeContext(opts: ApiPluginOptions): ApiContext;
|
|
18
|
+
declare function makeContext(opts: ApiPluginOptions): ApiContext;
|
|
19
|
+
//#endregion
|
|
21
20
|
//#region src/ops/documents.d.ts
|
|
22
21
|
/**
|
|
23
22
|
* Operations shared by the dev API and the MCP server. Everything here takes an
|
|
@@ -67,7 +66,6 @@ declare function duplicateDocument(ctx: ApiContext, docId: string, newId?: strin
|
|
|
67
66
|
id: string;
|
|
68
67
|
}>;
|
|
69
68
|
declare function deleteDocument(ctx: ApiContext, docId: string): Promise<void>;
|
|
70
|
-
|
|
71
69
|
//#endregion
|
|
72
70
|
//#region src/files/folders.d.ts
|
|
73
71
|
type FolderIcon = {
|
|
@@ -82,7 +80,6 @@ type Folder = {
|
|
|
82
80
|
name: string;
|
|
83
81
|
icon: FolderIcon;
|
|
84
82
|
};
|
|
85
|
-
|
|
86
83
|
//#endregion
|
|
87
84
|
//#region src/ops/library.d.ts
|
|
88
85
|
/** Themes, assets, and folders — the material a document is written against. */
|
|
@@ -127,7 +124,6 @@ declare function listFolders(ctx: ApiContext): Promise<{
|
|
|
127
124
|
declare function createFolder(ctx: ApiContext, rawName: unknown, rawIcon?: unknown): Promise<Folder>;
|
|
128
125
|
/** Filing only edits assignments — a document id never moves on disk. */
|
|
129
126
|
declare function fileDocument(ctx: ApiContext, docId: string, folderId: string | null): Promise<void>;
|
|
130
|
-
|
|
131
127
|
//#endregion
|
|
132
128
|
//#region src/ops/text.d.ts
|
|
133
129
|
type Loc = {
|
|
@@ -155,6 +151,5 @@ declare function writeText(ctx: ApiContext, docId: string, loc: Loc, text: strin
|
|
|
155
151
|
declare function addComment(ctx: ApiContext, docId: string, loc: Loc, note: string, hint?: string): Promise<{
|
|
156
152
|
id: string;
|
|
157
153
|
}>;
|
|
158
|
-
|
|
159
154
|
//#endregion
|
|
160
|
-
export { ApiContext, AssetSummary, DocumentSummary, Loc, OpsError, ThemeSummary, addComment, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, fileDocument, findAssetUsages, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, resolveEntry, writeAsset, writeDocument, writeText };
|
|
155
|
+
export { type ApiContext, type AssetSummary, type DocumentSummary, type Loc, OpsError, type ThemeSummary, addComment, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, fileDocument, findAssetUsages, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, resolveEntry, writeAsset, writeDocument, writeText };
|
package/dist/ops/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as writeDocument, C as docDir, D as readDocument, E as listDocuments, F as validateName, L as writeManifest, M as newFolderId, N as readManifest, O as renameDocument, P as validateIcon, S as deleteDocument, T as listDocIds, _ as resolveScopedAssetFile, b as OpsError, c as parseFrontmatter, k as resolveEntry, m as countAssetUsages, n as resolveTextTarget, p as assetImportPath, r as insertMarker, t as replaceTextAt, v as resolveScopedAssetsDir, w as duplicateDocument, x as createDocument, y as validateAssetName, z as makeContext } from "../edit-ops-D2W2plpc.js";
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import fg from "fast-glob";
|
|
6
|
-
|
|
7
6
|
//#region src/ops/library.ts
|
|
8
7
|
function themesRoot(ctx, themesDir = "themes") {
|
|
9
8
|
return path.resolve(ctx.userCwd, themesDir);
|
|
@@ -153,7 +152,6 @@ async function fileDocument(ctx, docId, folderId) {
|
|
|
153
152
|
else manifest.assignments[docId] = folderId;
|
|
154
153
|
await writeManifest(ctx.manifestPath, manifest);
|
|
155
154
|
}
|
|
156
|
-
|
|
157
155
|
//#endregion
|
|
158
156
|
//#region src/ops/text.ts
|
|
159
157
|
async function sourceOf(ctx, docId) {
|
|
@@ -197,6 +195,5 @@ async function addComment(ctx, docId, loc, note, hint) {
|
|
|
197
195
|
await fs.writeFile(entry, inserted.source, "utf8");
|
|
198
196
|
return { id: inserted.id };
|
|
199
197
|
}
|
|
200
|
-
|
|
201
198
|
//#endregion
|
|
202
|
-
export { OpsError, addComment, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, fileDocument, findAssetUsages, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, resolveEntry, writeAsset, writeDocument, writeText };
|
|
199
|
+
export { OpsError, addComment, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, fileDocument, findAssetUsages, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, resolveEntry, writeAsset, writeDocument, writeText };
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./edit-ops-DSdUroVO.js";
|
|
3
|
-
import { createViteConfig } from "./config-DBp4mOOf.js";
|
|
1
|
+
import { t as createViteConfig } from "./config-8zkUElGq.js";
|
|
4
2
|
import { mergeConfig, preview as preview$1 } from "vite";
|
|
5
|
-
|
|
6
3
|
//#region src/cli/preview.ts
|
|
7
4
|
async function preview(opts = {}) {
|
|
8
5
|
const base = await createViteConfig({
|
|
@@ -18,6 +15,5 @@ async function preview(opts = {}) {
|
|
|
18
15
|
server.printUrls();
|
|
19
16
|
server.bindCLIShortcuts({ print: true });
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
//#endregion
|
|
23
|
-
export { preview };
|
|
19
|
+
export { preview };
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { OpenDocConfig } from "../config-
|
|
1
|
+
import { n as OpenDocConfig } from "../config-CSC5lHsR.js";
|
|
2
2
|
import { InlineConfig, Plugin } from "vite";
|
|
3
|
-
|
|
4
3
|
//#region src/vite/open-doc-plugin.d.ts
|
|
5
4
|
type OpenDocPluginOptions = {
|
|
6
5
|
userCwd: string;
|
|
7
6
|
config: OpenDocConfig;
|
|
8
7
|
coreVersion: string;
|
|
9
8
|
};
|
|
10
|
-
declare function openDocPlugin(opts: OpenDocPluginOptions): Plugin;
|
|
9
|
+
declare function openDocPlugin(opts: OpenDocPluginOptions): Plugin;
|
|
10
|
+
//#endregion
|
|
11
11
|
//#region src/vite/config.d.ts
|
|
12
12
|
type CreateViteConfigOptions = {
|
|
13
13
|
userCwd: string;
|
|
@@ -17,6 +17,5 @@ type CreateViteConfigOptions = {
|
|
|
17
17
|
mode?: 'serve' | 'build';
|
|
18
18
|
};
|
|
19
19
|
declare function createViteConfig(opts: CreateViteConfigOptions): Promise<InlineConfig>;
|
|
20
|
-
|
|
21
20
|
//#endregion
|
|
22
21
|
export { createViteConfig, openDocPlugin };
|