@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
|
@@ -1,9 +1,6 @@
|
|
|
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 path from "node:path";
|
|
5
3
|
import { build as build$1, mergeConfig } from "vite";
|
|
6
|
-
|
|
7
4
|
//#region src/cli/build.ts
|
|
8
5
|
async function build(opts = {}) {
|
|
9
6
|
const base = await createViteConfig({
|
|
@@ -13,6 +10,5 @@ async function build(opts = {}) {
|
|
|
13
10
|
const config = mergeConfig(base, { build: { ...opts.outDir !== void 0 ? { outDir: path.resolve(process.cwd(), opts.outDir) } : {} } });
|
|
14
11
|
await build$1(config);
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
//#endregion
|
|
18
|
-
export { build };
|
|
14
|
+
export { build };
|
package/dist/cli/bin.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {}
|
package/dist/cli/bin.js
CHANGED
|
@@ -1,12 +1,104 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { detectSkillsDrift, syncSkills } from "../sync-6GTPAt2t.js";
|
|
3
2
|
import chalk from "chalk";
|
|
4
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
+
import fs, { readFile } from "node:fs/promises";
|
|
5
4
|
import path from "node:path";
|
|
6
5
|
import * as readline from "node:readline/promises";
|
|
7
6
|
import { fileURLToPath } from "node:url";
|
|
8
7
|
import { Command, Option } from "commander";
|
|
9
|
-
|
|
8
|
+
import { existsSync } from "node:fs";
|
|
9
|
+
//#region \0rolldown/runtime.js
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __exportAll = (all, no_symbols) => {
|
|
12
|
+
let target = {};
|
|
13
|
+
for (var name in all) __defProp(target, name, {
|
|
14
|
+
get: all[name],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/cli/sync.ts
|
|
22
|
+
var sync_exports = /* @__PURE__ */ __exportAll({
|
|
23
|
+
detectSkillsDrift: () => detectSkillsDrift,
|
|
24
|
+
syncSkills: () => syncSkills
|
|
25
|
+
});
|
|
26
|
+
const SKILL_TARGET_DIRS = [".agents/skills", ".claude/skills"];
|
|
27
|
+
async function listFiles(dir) {
|
|
28
|
+
const out = [];
|
|
29
|
+
const walk = async (current) => {
|
|
30
|
+
const entries = await fs.readdir(current, { withFileTypes: true });
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
const abs = path.join(current, entry.name);
|
|
33
|
+
if (entry.isDirectory()) await walk(abs);
|
|
34
|
+
else out.push(path.relative(dir, abs));
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
await walk(dir);
|
|
38
|
+
return out.sort();
|
|
39
|
+
}
|
|
40
|
+
async function sameTree(src, dst) {
|
|
41
|
+
if (!existsSync(dst)) return false;
|
|
42
|
+
const [srcFiles, dstFiles] = await Promise.all([listFiles(src), listFiles(dst)]);
|
|
43
|
+
if (srcFiles.length !== dstFiles.length) return false;
|
|
44
|
+
if (srcFiles.some((f, i) => f !== dstFiles[i])) return false;
|
|
45
|
+
for (const rel of srcFiles) {
|
|
46
|
+
const [a, b] = await Promise.all([fs.readFile(path.join(src, rel), "utf8"), fs.readFile(path.join(dst, rel), "utf8")]);
|
|
47
|
+
if (a !== b) return false;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
async function skillNames(builtinDir) {
|
|
52
|
+
if (!existsSync(builtinDir)) return [];
|
|
53
|
+
return (await fs.readdir(builtinDir, { withFileTypes: true })).filter((e) => e.isDirectory()).map((e) => e.name).sort();
|
|
54
|
+
}
|
|
55
|
+
async function detectSkillsDrift(builtinDir, userCwd = process.cwd()) {
|
|
56
|
+
const names = await skillNames(builtinDir);
|
|
57
|
+
const primaryTarget = path.join(userCwd, SKILL_TARGET_DIRS[0]);
|
|
58
|
+
const drift = [];
|
|
59
|
+
for (const name of names) {
|
|
60
|
+
const src = path.join(builtinDir, name);
|
|
61
|
+
const dst = path.join(primaryTarget, name);
|
|
62
|
+
if (!existsSync(dst)) drift.push({
|
|
63
|
+
name,
|
|
64
|
+
status: "added"
|
|
65
|
+
});
|
|
66
|
+
else if (!await sameTree(src, dst)) drift.push({
|
|
67
|
+
name,
|
|
68
|
+
status: "updated"
|
|
69
|
+
});
|
|
70
|
+
else drift.push({
|
|
71
|
+
name,
|
|
72
|
+
status: "unchanged"
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return drift;
|
|
76
|
+
}
|
|
77
|
+
async function syncSkills(builtinDir, opts = {}, userCwd = process.cwd()) {
|
|
78
|
+
const stale = (await detectSkillsDrift(builtinDir, userCwd)).filter((d) => d.status !== "unchanged");
|
|
79
|
+
if (stale.length === 0) {
|
|
80
|
+
process.stdout.write(`${chalk.green("✔")} Skills already up to date.\n`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
for (const { name, status } of stale) {
|
|
84
|
+
if (opts.dryRun) {
|
|
85
|
+
process.stdout.write(`${chalk.yellow("~")} ${name} ${chalk.dim(`(${status})`)}\n`);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
for (const targetDir of SKILL_TARGET_DIRS) {
|
|
89
|
+
const dst = path.join(userCwd, targetDir, name);
|
|
90
|
+
await fs.rm(dst, {
|
|
91
|
+
recursive: true,
|
|
92
|
+
force: true
|
|
93
|
+
});
|
|
94
|
+
await fs.mkdir(path.dirname(dst), { recursive: true });
|
|
95
|
+
await fs.cp(path.join(builtinDir, name), dst, { recursive: true });
|
|
96
|
+
}
|
|
97
|
+
process.stdout.write(`${chalk.green("✔")} ${name} ${chalk.dim(`(${status})`)}\n`);
|
|
98
|
+
}
|
|
99
|
+
if (opts.dryRun) process.stdout.write(chalk.dim("\nDry run — nothing written.\n"));
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
10
102
|
//#region src/cli/run.ts
|
|
11
103
|
async function readVersion() {
|
|
12
104
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -34,8 +126,7 @@ async function runSkillsDriftCheck(skillsDir) {
|
|
|
34
126
|
const stale = drift.filter((d) => d.status !== "unchanged");
|
|
35
127
|
if (stale.length === 0) return;
|
|
36
128
|
const names = stale.map((d) => d.name).join(", ");
|
|
37
|
-
|
|
38
|
-
if (!interactive) {
|
|
129
|
+
if (!Boolean(process.stdin.isTTY && process.stdout.isTTY)) {
|
|
39
130
|
process.stderr.write(`${chalk.yellow("!")} Skills out of date (${names}). Run \`open-doc sync:skills\` to update.\n`);
|
|
40
131
|
return;
|
|
41
132
|
}
|
|
@@ -57,24 +148,23 @@ async function run(argv) {
|
|
|
57
148
|
program.name("open-doc").description("Author documents — we handle the Vite/React stack, pagination, and export.").version(version, "-v, --version", "print version").helpOption("-h, --help", "show help").showHelpAfterError(chalk.dim("(run `open-doc --help` for usage)"));
|
|
58
149
|
program.command("dev").description("Start the dev server").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").option("--no-skills-check", "skip the built-in skills drift check").option("--mcp", "serve an MCP endpoint at /mcp (requires @open-document/mcp)").action(async (flags) => {
|
|
59
150
|
if (flags.skillsCheck !== false) await runSkillsDriftCheck(resolveBuiltinSkillsDir());
|
|
60
|
-
const { dev } = await import("../dev-
|
|
151
|
+
const { dev } = await import("../dev-DwwFT6uX.js");
|
|
61
152
|
await dev(flags);
|
|
62
153
|
});
|
|
63
154
|
program.command("build").description("Build a static site").option("--out-dir <dir>", "output directory (defaults to `dist`)").action(async (flags) => {
|
|
64
|
-
const { build } = await import("../build-
|
|
155
|
+
const { build } = await import("../build-U81g9Hnk.js");
|
|
65
156
|
await build(flags);
|
|
66
157
|
});
|
|
67
158
|
program.command("preview").description("Preview the production build").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").action(async (flags) => {
|
|
68
|
-
const { preview } = await import("../preview-
|
|
159
|
+
const { preview } = await import("../preview-C_jbySle.js");
|
|
69
160
|
await preview(flags);
|
|
70
161
|
});
|
|
71
162
|
program.command("sync:skills").description("Sync built-in skills from @open-document/core into this workspace").option("--dry-run", "show what would change without writing").action(async (flags) => {
|
|
72
|
-
const { syncSkills
|
|
73
|
-
await syncSkills
|
|
163
|
+
const { syncSkills } = await Promise.resolve().then(() => sync_exports);
|
|
164
|
+
await syncSkills(resolveBuiltinSkillsDir(), flags);
|
|
74
165
|
});
|
|
75
166
|
await program.parseAsync(argv, { from: "user" });
|
|
76
167
|
}
|
|
77
|
-
|
|
78
168
|
//#endregion
|
|
79
169
|
//#region src/cli/bin.ts
|
|
80
170
|
run(process.argv.slice(2)).catch((err) => {
|
|
@@ -82,5 +172,5 @@ run(process.argv.slice(2)).catch((err) => {
|
|
|
82
172
|
process.stderr.write(`${chalk.red("error:")} ${message}\n`);
|
|
83
173
|
process.exit(1);
|
|
84
174
|
});
|
|
85
|
-
|
|
86
|
-
|
|
175
|
+
//#endregion
|
|
176
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defaultDesign } from "./design-
|
|
2
|
-
import {
|
|
1
|
+
import { n as defaultDesign } from "./design-IyRSwCtK.js";
|
|
2
|
+
import { B as readBody, F as validateName, G as openDocPlugin, H as resolveDocPath, I as validateReorder, L as writeManifest, M as newFolderId, N as readManifest, O as renameDocument, P as validateIcon, R as json, S as deleteDocument, U as DOC_ID_RE, V as resolveDocEntry, W as loadUserConfig, _ as resolveScopedAssetFile, a as removeMarker, b as OpsError, d as GLOBAL_SCOPE, f as assetCreatedAt, g as mimeForFilename, h as findReferencedAssets, i as parseMarkers, j as FOLDER_ID_RE, l as themesPlugin, m as countAssetUsages, n as resolveTextTarget, o as parseSource$1, p as assetImportPath, r as insertMarker, s as walkJsx, t as replaceTextAt, v as resolveScopedAssetsDir, w as duplicateDocument, y as validateAssetName, z as makeContext } from "./edit-ops-D2W2plpc.js";
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import fs from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
@@ -8,7 +8,6 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
8
8
|
import { parse } from "@babel/parser";
|
|
9
9
|
import tailwindcss from "@tailwindcss/vite";
|
|
10
10
|
import react from "@vitejs/plugin-react";
|
|
11
|
-
|
|
12
11
|
//#region src/http/request-guard.ts
|
|
13
12
|
function firstHeaderValue(value) {
|
|
14
13
|
if (Array.isArray(value)) return value[0] ?? null;
|
|
@@ -41,15 +40,13 @@ function normalizedOrigin(origin) {
|
|
|
41
40
|
*/
|
|
42
41
|
function validateMutationRequest(req, opts = {}) {
|
|
43
42
|
if (opts.requireJsonBody) {
|
|
44
|
-
|
|
45
|
-
if (!contentType?.startsWith("application/json")) return {
|
|
43
|
+
if (!(headerValue(req, "content-type")?.toLowerCase())?.startsWith("application/json")) return {
|
|
46
44
|
ok: false,
|
|
47
45
|
status: 415,
|
|
48
46
|
error: "content-type must be application/json"
|
|
49
47
|
};
|
|
50
48
|
}
|
|
51
|
-
|
|
52
|
-
if (fetchSite === "cross-site") return {
|
|
49
|
+
if (firstCommaToken(headerValue(req, "sec-fetch-site"))?.toLowerCase() === "cross-site") return {
|
|
53
50
|
ok: false,
|
|
54
51
|
status: 403,
|
|
55
52
|
error: "cross-site request blocked"
|
|
@@ -73,21 +70,18 @@ function validateMutationRequest(req, opts = {}) {
|
|
|
73
70
|
status: 400,
|
|
74
71
|
error: "missing host header"
|
|
75
72
|
};
|
|
76
|
-
|
|
77
|
-
if (actualOrigin !== expectedOrigin) return {
|
|
73
|
+
if (actualOrigin !== `${requestProto(req)}://${host}`.toLowerCase()) return {
|
|
78
74
|
ok: false,
|
|
79
75
|
status: 403,
|
|
80
76
|
error: "origin mismatch"
|
|
81
77
|
};
|
|
82
78
|
return { ok: true };
|
|
83
79
|
}
|
|
84
|
-
|
|
85
80
|
//#endregion
|
|
86
81
|
//#region src/vite/routes/assets.ts
|
|
87
82
|
async function listDocIds(docsRoot) {
|
|
88
83
|
try {
|
|
89
|
-
|
|
90
|
-
return entries.filter((e) => e.isDirectory() && DOC_ID_RE.test(e.name)).map((e) => e.name);
|
|
84
|
+
return (await fs.readdir(docsRoot, { withFileTypes: true })).filter((e) => e.isDirectory() && DOC_ID_RE.test(e.name)).map((e) => e.name);
|
|
91
85
|
} catch {
|
|
92
86
|
return [];
|
|
93
87
|
}
|
|
@@ -165,8 +159,7 @@ function registerAssetRoutes(server, ctx) {
|
|
|
165
159
|
}
|
|
166
160
|
assets.sort((a, b) => a.name.localeCompare(b.name));
|
|
167
161
|
if (assets.length > 0) {
|
|
168
|
-
const
|
|
169
|
-
const scanIds = isGlobal ? await listDocIds(ctx.docsRoot) : [scope];
|
|
162
|
+
const scanIds = scope === "@global" ? await listDocIds(ctx.docsRoot) : [scope];
|
|
170
163
|
const pathToAsset = new Map(assets.map((a) => [a.importPath, a]));
|
|
171
164
|
const paths = assets.map((a) => a.importPath);
|
|
172
165
|
for (const docId of scanIds) {
|
|
@@ -202,7 +195,7 @@ function registerAssetRoutes(server, ctx) {
|
|
|
202
195
|
const overwrite = url.searchParams.get("overwrite") === "1";
|
|
203
196
|
const lenHeader = req.headers["content-length"];
|
|
204
197
|
const len = typeof lenHeader === "string" ? Number(lenHeader) : NaN;
|
|
205
|
-
if (Number.isFinite(len) && len >
|
|
198
|
+
if (Number.isFinite(len) && len > 26214400) return json(res, 413, { error: "file too large" });
|
|
206
199
|
if (!overwrite) try {
|
|
207
200
|
await fs.access(file);
|
|
208
201
|
return json(res, 409, { error: "asset exists" });
|
|
@@ -216,7 +209,7 @@ function registerAssetRoutes(server, ctx) {
|
|
|
216
209
|
await new Promise((resolve, reject) => {
|
|
217
210
|
req.on("data", (c) => {
|
|
218
211
|
total += c.length;
|
|
219
|
-
if (total >
|
|
212
|
+
if (total > 26214400) {
|
|
220
213
|
oversized = true;
|
|
221
214
|
req.destroy();
|
|
222
215
|
return;
|
|
@@ -285,7 +278,6 @@ function registerAssetRoutes(server, ctx) {
|
|
|
285
278
|
}
|
|
286
279
|
});
|
|
287
280
|
}
|
|
288
|
-
|
|
289
281
|
//#endregion
|
|
290
282
|
//#region src/vite/routes/docs.ts
|
|
291
283
|
function registerDocRoutes(server, ctx) {
|
|
@@ -333,7 +325,6 @@ function registerDocRoutes(server, ctx) {
|
|
|
333
325
|
}
|
|
334
326
|
});
|
|
335
327
|
}
|
|
336
|
-
|
|
337
328
|
//#endregion
|
|
338
329
|
//#region src/vite/routes/edit.ts
|
|
339
330
|
function readLoc(body) {
|
|
@@ -422,9 +413,9 @@ function registerEditRoutes(server, ctx) {
|
|
|
422
413
|
const id = url.searchParams.get("id") ?? "";
|
|
423
414
|
if (!entry || !/^c-[a-f0-9]+$/.test(id)) return json(res, 400, { error: "invalid id" });
|
|
424
415
|
const source = await fs.readFile(entry, "utf8");
|
|
425
|
-
const next
|
|
426
|
-
if (next
|
|
427
|
-
await fs.writeFile(entry, next
|
|
416
|
+
const next = removeMarker(source, id);
|
|
417
|
+
if (next === null) return json(res, 404, { error: "comment not found" });
|
|
418
|
+
await fs.writeFile(entry, next, "utf8");
|
|
428
419
|
return json(res, 200, { ok: true });
|
|
429
420
|
}
|
|
430
421
|
return next();
|
|
@@ -433,7 +424,6 @@ function registerEditRoutes(server, ctx) {
|
|
|
433
424
|
}
|
|
434
425
|
});
|
|
435
426
|
}
|
|
436
|
-
|
|
437
427
|
//#endregion
|
|
438
428
|
//#region src/vite/routes/folders.ts
|
|
439
429
|
function registerFolderRoutes(server, ctx) {
|
|
@@ -531,7 +521,6 @@ function registerFolderRoutes(server, ctx) {
|
|
|
531
521
|
}
|
|
532
522
|
});
|
|
533
523
|
}
|
|
534
|
-
|
|
535
524
|
//#endregion
|
|
536
525
|
//#region src/vite/api-plugin.ts
|
|
537
526
|
function apiPlugin(opts) {
|
|
@@ -547,10 +536,83 @@ function apiPlugin(opts) {
|
|
|
547
536
|
}
|
|
548
537
|
};
|
|
549
538
|
}
|
|
550
|
-
|
|
539
|
+
//#endregion
|
|
540
|
+
//#region src/vite/current-plugin.ts
|
|
541
|
+
const TEXT_SNIPPET_MAX = 120;
|
|
542
|
+
function parseSelection(raw) {
|
|
543
|
+
if (raw == null || typeof raw !== "object") return null;
|
|
544
|
+
const sel = raw;
|
|
545
|
+
if (typeof sel.line !== "number" || !Number.isFinite(sel.line)) return null;
|
|
546
|
+
if (typeof sel.column !== "number" || !Number.isFinite(sel.column)) return null;
|
|
547
|
+
const tagName = typeof sel.tagName === "string" ? sel.tagName.toLowerCase().slice(0, 32) : "unknown";
|
|
548
|
+
const text = typeof sel.text === "string" ? sel.text.replace(/\s+/g, " ").trim().slice(0, TEXT_SNIPPET_MAX) : "";
|
|
549
|
+
return {
|
|
550
|
+
line: Math.max(1, Math.floor(sel.line)),
|
|
551
|
+
column: Math.max(0, Math.floor(sel.column)),
|
|
552
|
+
tagName,
|
|
553
|
+
text
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Writes `node_modules/.open-doc/current.json` whenever the viewer navigates or
|
|
558
|
+
* the inspector picks an element, so an agent can resolve "this page" without
|
|
559
|
+
* asking. Dev only — a static build has no cursor to report.
|
|
560
|
+
*/
|
|
561
|
+
function currentPlugin(opts) {
|
|
562
|
+
const userCwd = opts.userCwd;
|
|
563
|
+
const docsDir = opts.docsDir ?? "docs";
|
|
564
|
+
const outDir = path.join(userCwd, "node_modules", ".open-doc");
|
|
565
|
+
const outFile = path.join(outDir, "current.json");
|
|
566
|
+
const tmpFile = `${outFile}.tmp`;
|
|
567
|
+
let cached = null;
|
|
568
|
+
return {
|
|
569
|
+
name: "open-doc:current",
|
|
570
|
+
apply: "serve",
|
|
571
|
+
configureServer(server) {
|
|
572
|
+
server.ws.on("open-doc:current", async (raw) => {
|
|
573
|
+
const next = cached ? { ...cached } : {
|
|
574
|
+
docId: "",
|
|
575
|
+
pageIndex: 0,
|
|
576
|
+
pageNumber: 1,
|
|
577
|
+
totalPages: 1,
|
|
578
|
+
docTitle: "",
|
|
579
|
+
pagePath: "",
|
|
580
|
+
selection: null
|
|
581
|
+
};
|
|
582
|
+
if (typeof raw?.docId === "string") {
|
|
583
|
+
if (!DOC_ID_RE.test(raw.docId)) return;
|
|
584
|
+
const totalPages = typeof raw.totalPages === "number" && Number.isFinite(raw.totalPages) && raw.totalPages > 0 ? Math.floor(raw.totalPages) : 1;
|
|
585
|
+
const rawIndex = typeof raw.pageIndex === "number" && Number.isFinite(raw.pageIndex) ? Math.floor(raw.pageIndex) : 0;
|
|
586
|
+
const pageIndex = Math.max(0, Math.min(totalPages - 1, rawIndex));
|
|
587
|
+
const docTitle = typeof raw.docTitle === "string" ? raw.docTitle : raw.docId;
|
|
588
|
+
const pagePath = path.join(docsDir, raw.docId, "index.tsx").split(path.sep).join("/");
|
|
589
|
+
if (cached?.docId !== raw.docId || cached?.pageIndex !== pageIndex) next.selection = null;
|
|
590
|
+
next.docId = raw.docId;
|
|
591
|
+
next.pageIndex = pageIndex;
|
|
592
|
+
next.pageNumber = pageIndex + 1;
|
|
593
|
+
next.totalPages = totalPages;
|
|
594
|
+
next.docTitle = docTitle;
|
|
595
|
+
next.pagePath = pagePath;
|
|
596
|
+
}
|
|
597
|
+
if ("selection" in raw) next.selection = parseSelection(raw.selection);
|
|
598
|
+
if (!next.docId) return;
|
|
599
|
+
cached = next;
|
|
600
|
+
const body = {
|
|
601
|
+
...next,
|
|
602
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
603
|
+
};
|
|
604
|
+
try {
|
|
605
|
+
await fs.mkdir(outDir, { recursive: true });
|
|
606
|
+
await fs.writeFile(tmpFile, `${JSON.stringify(body, null, 2)}\n`, "utf8");
|
|
607
|
+
await fs.rename(tmpFile, outFile);
|
|
608
|
+
} catch {}
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
}
|
|
551
613
|
//#endregion
|
|
552
614
|
//#region src/vite/design-plugin.ts
|
|
553
|
-
function parseSource
|
|
615
|
+
function parseSource(source) {
|
|
554
616
|
try {
|
|
555
617
|
return parse(source, {
|
|
556
618
|
sourceType: "module",
|
|
@@ -624,8 +686,7 @@ function literalToValue(node) {
|
|
|
624
686
|
}
|
|
625
687
|
case "TemplateLiteral": {
|
|
626
688
|
const quasis = node.quasis;
|
|
627
|
-
|
|
628
|
-
if (expressions.length > 0) throw new Error("template literal has expressions");
|
|
689
|
+
if (node.expressions.length > 0) throw new Error("template literal has expressions");
|
|
629
690
|
const value = quasis[0].value;
|
|
630
691
|
return value.cooked ?? value.raw;
|
|
631
692
|
}
|
|
@@ -680,11 +741,10 @@ function serializeValue(value, level) {
|
|
|
680
741
|
const entries = Object.entries(value);
|
|
681
742
|
if (entries.length === 0) return "{}";
|
|
682
743
|
const childIndent = indent(level + 1);
|
|
683
|
-
|
|
744
|
+
return `{\n${entries.map(([k, v]) => {
|
|
684
745
|
const key = isValidIdentifier(k) ? k : jsString(k);
|
|
685
746
|
return `${childIndent}${key}: ${serializeValue(v, level + 1)},`;
|
|
686
|
-
})
|
|
687
|
-
return `{\n${lines.join("\n")}\n${indent(level)}}`;
|
|
747
|
+
}).join("\n")}\n${indent(level)}}`;
|
|
688
748
|
}
|
|
689
749
|
throw new Error(`unsupported value type ${typeof value}`);
|
|
690
750
|
}
|
|
@@ -692,7 +752,7 @@ function serializeDesign(design) {
|
|
|
692
752
|
return serializeValue(design, 0);
|
|
693
753
|
}
|
|
694
754
|
function parseDocDesign(source) {
|
|
695
|
-
const ast = parseSource
|
|
755
|
+
const ast = parseSource(source);
|
|
696
756
|
if (!ast) return {
|
|
697
757
|
ok: false,
|
|
698
758
|
exists: true,
|
|
@@ -700,8 +760,7 @@ function parseDocDesign(source) {
|
|
|
700
760
|
};
|
|
701
761
|
const found = findDesign(ast);
|
|
702
762
|
if (!found) {
|
|
703
|
-
|
|
704
|
-
if (hasBinding) return {
|
|
763
|
+
if (programBody(ast).some((node) => designObjectOf(node) !== null)) return {
|
|
705
764
|
ok: false,
|
|
706
765
|
exists: true,
|
|
707
766
|
error: "design has an unsupported initializer"
|
|
@@ -745,15 +804,12 @@ function ensureDesignSystemImport(source, ast) {
|
|
|
745
804
|
const imports = findImports(ast);
|
|
746
805
|
const coreImport = imports.find((imp) => imp.source === "@open-document/core");
|
|
747
806
|
if (coreImport) {
|
|
748
|
-
|
|
807
|
+
if (coreImport.specifiers.some((spec) => {
|
|
749
808
|
if (spec.type !== "ImportSpecifier") return false;
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
});
|
|
753
|
-
if (hasDesignSystem) return source;
|
|
809
|
+
return spec.imported?.name === "DesignSystem";
|
|
810
|
+
})) return source;
|
|
754
811
|
const node = coreImport.node;
|
|
755
|
-
const
|
|
756
|
-
const braceClose = importText.lastIndexOf("}");
|
|
812
|
+
const braceClose = source.slice(node.start, node.end).lastIndexOf("}");
|
|
757
813
|
if (braceClose === -1) return source;
|
|
758
814
|
const absoluteBrace = node.start + braceClose;
|
|
759
815
|
const insertText = coreImport.specifiers.length > 0 ? ", type DesignSystem" : "type DesignSystem";
|
|
@@ -786,23 +842,20 @@ function applyDesignWrite(source, next) {
|
|
|
786
842
|
error: `serialize failed: ${err.message}`
|
|
787
843
|
};
|
|
788
844
|
}
|
|
789
|
-
const ast = parseSource
|
|
845
|
+
const ast = parseSource(source);
|
|
790
846
|
if (!ast) return {
|
|
791
847
|
ok: false,
|
|
792
848
|
status: 422,
|
|
793
849
|
error: "could not parse document source"
|
|
794
850
|
};
|
|
795
851
|
const found = findDesign(ast);
|
|
796
|
-
if (found) {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
created: false
|
|
802
|
-
};
|
|
803
|
-
}
|
|
852
|
+
if (found) return {
|
|
853
|
+
ok: true,
|
|
854
|
+
source: source.slice(0, found.loc.objectStart) + body + source.slice(found.loc.objectEnd),
|
|
855
|
+
created: false
|
|
856
|
+
};
|
|
804
857
|
const withImport = ensureDesignSystemImport(source, ast);
|
|
805
|
-
const ast2 = parseSource
|
|
858
|
+
const ast2 = parseSource(withImport);
|
|
806
859
|
if (!ast2) return {
|
|
807
860
|
ok: false,
|
|
808
861
|
status: 422,
|
|
@@ -857,8 +910,7 @@ function designPlugin(opts) {
|
|
|
857
910
|
if (method === "PUT" && url.pathname === "/") {
|
|
858
911
|
const requestCheck = validateMutationRequest(req, { requireJsonBody: true });
|
|
859
912
|
if (!requestCheck.ok) return json(res, requestCheck.status, { error: requestCheck.error });
|
|
860
|
-
const
|
|
861
|
-
const patch = body.patch;
|
|
913
|
+
const patch = (await readBody(req)).patch;
|
|
862
914
|
if (!patch || typeof patch !== "object") return json(res, 400, { error: "missing patch object" });
|
|
863
915
|
let source;
|
|
864
916
|
try {
|
|
@@ -904,10 +956,9 @@ function designPlugin(opts) {
|
|
|
904
956
|
}
|
|
905
957
|
};
|
|
906
958
|
}
|
|
907
|
-
|
|
908
959
|
//#endregion
|
|
909
960
|
//#region src/vite/loc-tags-plugin.ts
|
|
910
|
-
const FORWARDING_COMPONENTS = new Set(["ImagePlaceholder"]);
|
|
961
|
+
const FORWARDING_COMPONENTS = /* @__PURE__ */ new Set(["ImagePlaceholder"]);
|
|
911
962
|
function taggableName(opening) {
|
|
912
963
|
const name = opening.name;
|
|
913
964
|
if (name?.type !== "JSXIdentifier" || typeof name.name !== "string") return null;
|
|
@@ -915,15 +966,13 @@ function taggableName(opening) {
|
|
|
915
966
|
return null;
|
|
916
967
|
}
|
|
917
968
|
function alreadyTagged(opening) {
|
|
918
|
-
|
|
919
|
-
return attributes.some((attr) => {
|
|
969
|
+
return (opening.attributes ?? []).some((attr) => {
|
|
920
970
|
if (attr.type !== "JSXAttribute") return false;
|
|
921
|
-
|
|
922
|
-
return name?.name === "data-od-loc";
|
|
971
|
+
return attr.name?.name === "data-od-loc";
|
|
923
972
|
});
|
|
924
973
|
}
|
|
925
974
|
function injectLocTags(code) {
|
|
926
|
-
const ast = parseSource(code);
|
|
975
|
+
const ast = parseSource$1(code);
|
|
927
976
|
if (!ast) return null;
|
|
928
977
|
const insertions = [];
|
|
929
978
|
walkJsx(ast, (node) => {
|
|
@@ -965,7 +1014,6 @@ function locTagsPlugin(opts) {
|
|
|
965
1014
|
}
|
|
966
1015
|
};
|
|
967
1016
|
}
|
|
968
|
-
|
|
969
1017
|
//#endregion
|
|
970
1018
|
//#region src/vite/mcp-plugin.ts
|
|
971
1019
|
/**
|
|
@@ -984,9 +1032,7 @@ function mcpPlugin(opts) {
|
|
|
984
1032
|
async configureServer(server) {
|
|
985
1033
|
let middleware;
|
|
986
1034
|
try {
|
|
987
|
-
|
|
988
|
-
const mod = await import(specifier);
|
|
989
|
-
middleware = mod.createOpenDocMcpMiddleware({
|
|
1035
|
+
middleware = (await import("@open-document/mcp")).createOpenDocMcpMiddleware({
|
|
990
1036
|
userCwd: opts.userCwd,
|
|
991
1037
|
docsDir: opts.docsDir,
|
|
992
1038
|
assetsDir: opts.assetsDir,
|
|
@@ -1005,7 +1051,6 @@ function mcpPlugin(opts) {
|
|
|
1005
1051
|
}
|
|
1006
1052
|
};
|
|
1007
1053
|
}
|
|
1008
|
-
|
|
1009
1054
|
//#endregion
|
|
1010
1055
|
//#region src/vite/config.ts
|
|
1011
1056
|
function findPackageRoot(fromFile) {
|
|
@@ -1066,6 +1111,10 @@ async function createViteConfig(opts) {
|
|
|
1066
1111
|
assetsDir,
|
|
1067
1112
|
coreVersion: CORE_VERSION
|
|
1068
1113
|
}),
|
|
1114
|
+
currentPlugin({
|
|
1115
|
+
userCwd,
|
|
1116
|
+
docsDir
|
|
1117
|
+
}),
|
|
1069
1118
|
...opts.mcp ? [mcpPlugin({
|
|
1070
1119
|
userCwd,
|
|
1071
1120
|
docsDir,
|
|
@@ -1116,6 +1165,5 @@ async function createViteConfig(opts) {
|
|
|
1116
1165
|
}
|
|
1117
1166
|
};
|
|
1118
1167
|
}
|
|
1119
|
-
|
|
1120
1168
|
//#endregion
|
|
1121
|
-
export { createViteConfig };
|
|
1169
|
+
export { createViteConfig as t };
|
|
@@ -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 { createServer, mergeConfig } from "vite";
|
|
5
|
-
|
|
6
3
|
//#region src/cli/dev.ts
|
|
7
4
|
async function dev(opts = {}) {
|
|
8
5
|
const base = await createViteConfig({
|
|
@@ -19,6 +16,5 @@ async function dev(opts = {}) {
|
|
|
19
16
|
server.printUrls();
|
|
20
17
|
server.bindCLIShortcuts({ print: true });
|
|
21
18
|
}
|
|
22
|
-
|
|
23
19
|
//#endregion
|
|
24
|
-
export { dev };
|
|
20
|
+
export { dev };
|