@open-document/core 0.12.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.
- package/dist/{build-DfUfpeTR.js → build-CbgIk6bA.js} +1 -1
- package/dist/{check-CHxiOkQG.js → check-BTroj-5Z.js} +3 -3
- package/dist/cli/bin.js +47 -10
- package/dist/config-BWtOZ1jc.d.ts +45 -0
- package/dist/{config-9IdbhVuT.js → config-DKKNIbvO.js} +68 -320
- package/dist/{context-BLI1-64_.js → context-DXNP8v9I.js} +2 -1
- package/dist/deploy-gcp-BUiSuqz7.js +758 -0
- package/dist/{dev-yNYKv5mm.js → dev-YXumw5iX.js} +1 -1
- package/dist/{diagram-BK4jTZr4.js → diagram-CKf3ptOE.js} +293 -13
- package/dist/{diff-Bs205mOx.js → diff-CTFfU4Tz.js} +2 -2
- package/dist/{export-tkquS5O5.js → export-D2QLtF84.js} +3 -3
- package/dist/{sdk-CHEGeINh.d.ts → flow-CS5apebG.d.ts} +72 -3
- package/dist/{import-D1hIKIr3.js → import-CcmrFetU.js} +2 -2
- package/dist/index.d.ts +155 -59
- package/dist/index.js +896 -90
- package/dist/open-doc-plugin-DnX5usgI.js +320 -0
- package/dist/ops/index.d.ts +2 -2
- package/dist/ops/index.js +2 -2
- package/dist/{ops-Dgqujq5a.js → ops-DmEecq1k.js} +2 -1
- package/dist/{preview-BImdTH6K.js → preview-_mHpBhMk.js} +1 -1
- package/dist/{templates-DT5zzqHq.js → templates-MMblHwmT.js} +3 -3
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +2 -1
- package/package.json +1 -1
- package/skills/doc-authoring/SKILL.md +15 -16
- package/skills/doc-authoring/references/long-form.md +43 -2
- package/skills/doc-authoring/references/pagination.md +14 -2
- package/skills/doc-authoring/references/tables-and-charts.md +21 -17
- package/src/app/components/callout.tsx +101 -0
- package/src/app/components/chart.tsx +191 -33
- package/src/app/components/code-block.tsx +249 -0
- package/src/app/components/data-table.tsx +146 -18
- package/src/app/components/flow-page.tsx +57 -8
- package/src/app/components/numbering.tsx +226 -12
- package/src/app/components/page-frame.tsx +42 -0
- package/src/app/lib/chart.test.ts +15 -0
- package/src/app/lib/chart.ts +134 -9
- package/src/app/lib/diagnostics.ts +45 -1
- package/src/app/lib/export-dom.ts +15 -2
- package/src/app/lib/export-pdf.ts +9 -1
- package/src/app/lib/flow-measure.ts +33 -4
- package/src/app/lib/flow.test.ts +20 -1
- package/src/app/lib/flow.ts +120 -20
- package/src/app/lib/labels.ts +29 -10
- package/src/app/lib/sdk.ts +6 -0
- package/src/app/lib/use-doc-pages.ts +23 -8
- package/src/app/routes/doc.tsx +1 -0
- package/dist/config-P61niZMf.d.ts +0 -24
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as listDocIds } from "./config-
|
|
2
|
-
import { n as closeRenderSession, t as checkLayout } from "./ops-
|
|
3
|
-
import { t as cliContext } from "./context-
|
|
1
|
+
import { D as listDocIds } from "./config-DKKNIbvO.js";
|
|
2
|
+
import { n as closeRenderSession, t as checkLayout } from "./ops-DmEecq1k.js";
|
|
3
|
+
import { t as cliContext } from "./context-DXNP8v9I.js";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
//#region src/cli/check.ts
|
|
6
6
|
function line(finding) {
|
package/dist/cli/bin.js
CHANGED
|
@@ -5,7 +5,7 @@ import chalk from "chalk";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import * as readline from "node:readline/promises";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
-
import { Command, Option } from "commander";
|
|
8
|
+
import { Argument, Command, Option } from "commander";
|
|
9
9
|
import fs from "node:fs/promises";
|
|
10
10
|
import { existsSync } from "node:fs";
|
|
11
11
|
//#region \0rolldown/runtime.js
|
|
@@ -107,6 +107,16 @@ function parsePort(value) {
|
|
|
107
107
|
if (!Number.isInteger(n) || n < 0 || n > 65535) throw new Error(`Invalid port: ${value}`);
|
|
108
108
|
return n;
|
|
109
109
|
}
|
|
110
|
+
const GCP_DEPLOY_ACTIONS = [
|
|
111
|
+
"up",
|
|
112
|
+
"check",
|
|
113
|
+
"status",
|
|
114
|
+
"pull",
|
|
115
|
+
"push",
|
|
116
|
+
"stop",
|
|
117
|
+
"start",
|
|
118
|
+
"down"
|
|
119
|
+
];
|
|
110
120
|
function resolveBuiltinSkillsDir() {
|
|
111
121
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
112
122
|
return path.resolve(here, "..", "..", "skills");
|
|
@@ -144,45 +154,72 @@ async function run(argv) {
|
|
|
144
154
|
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)"));
|
|
145
155
|
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) => {
|
|
146
156
|
if (flags.skillsCheck !== false) await runSkillsDriftCheck(resolveBuiltinSkillsDir());
|
|
147
|
-
const { dev } = await import("../dev-
|
|
157
|
+
const { dev } = await import("../dev-YXumw5iX.js");
|
|
148
158
|
await dev(flags);
|
|
149
159
|
});
|
|
150
160
|
program.command("build").description("Build a static site").option("--out-dir <dir>", "output directory (defaults to `dist`)").action(async (flags) => {
|
|
151
|
-
const { build } = await import("../build-
|
|
161
|
+
const { build } = await import("../build-CbgIk6bA.js");
|
|
152
162
|
await build(flags);
|
|
153
163
|
});
|
|
154
164
|
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) => {
|
|
155
|
-
const { preview } = await import("../preview-
|
|
165
|
+
const { preview } = await import("../preview-_mHpBhMk.js");
|
|
156
166
|
await preview(flags);
|
|
157
167
|
});
|
|
158
168
|
program.command("export [docIds...]").description("Render documents headlessly to PDF, HTML, PNG, or DOCX").addOption(new Option("-f, --format <format>", "output format").choices([...EXPORT_FORMATS])).option("-o, --out-dir <dir>", "directory to write into (defaults to `out`)").option("--all", "export every document under docs/").option("--each", "one copy per row of the document's `records`").option("--name <pattern>", "with --each: file name, e.g. \"certificate-{name}\" ({#} is the row number)").action(async (docIds, flags) => {
|
|
159
|
-
const { exportDocs } = await import("../export-
|
|
169
|
+
const { exportDocs } = await import("../export-D2QLtF84.js");
|
|
160
170
|
await exportDocs(docIds, flags);
|
|
161
171
|
});
|
|
162
172
|
program.command("diff <docId>").description("Show what changed in a document since a git revision, page by page").option("-s, --since <rev>", "revision to compare against (defaults to HEAD)").option("-o, --out-dir <dir>", "directory to write the report into (defaults to `out`)").option("--json", "print the result as JSON").action(async (docId, flags) => {
|
|
163
|
-
const { diffDoc } = await import("../diff-
|
|
173
|
+
const { diffDoc } = await import("../diff-CTFfU4Tz.js");
|
|
164
174
|
await diffDoc(docId, flags);
|
|
165
175
|
});
|
|
166
176
|
program.command("check [docIds...]").description("Report layout faults — clipped content, blank sheets, stranded headings").option("--json", "print the full report as JSON").action(async (docIds, flags) => {
|
|
167
|
-
const { checkDocs } = await import("../check-
|
|
177
|
+
const { checkDocs } = await import("../check-BTroj-5Z.js");
|
|
168
178
|
await checkDocs(docIds, flags);
|
|
169
179
|
});
|
|
170
180
|
program.command("templates").description("List the templates a new document can start from").option("--json", "print them as JSON").action(async (flags) => {
|
|
171
|
-
const { printTemplates } = await import("../templates-
|
|
181
|
+
const { printTemplates } = await import("../templates-MMblHwmT.js");
|
|
172
182
|
await printTemplates(flags);
|
|
173
183
|
});
|
|
174
184
|
program.command("new [docId]").description("Create a document under docs/ from a template (see `open-doc templates`)").option("-t, --template <name>", "template to start from (defaults to blank)").option("--title <title>", "title of the new document").action(async (docId, flags) => {
|
|
175
|
-
const { newDoc } = await import("../templates-
|
|
185
|
+
const { newDoc } = await import("../templates-MMblHwmT.js");
|
|
176
186
|
await newDoc(docId, flags);
|
|
177
187
|
});
|
|
178
188
|
program.command("import <file>").description("Turn a Markdown file into a document under docs/").option("--id <id>", "document id (defaults to a slug of the title)").option("--title <title>", "override the title").option("--subtitle <subtitle>", "subtitle, also used as the cover eyebrow").option("--lang <tag>", "language of the text, e.g. zh-Hant-TW (detected for CJK when omitted)").option("--author <author>", "author line on the cover").option("--theme <theme>", "theme id to back-link from meta.theme").addOption(new Option("--page-size <size>", "page size").choices(PAGE_SIZE_NAMES)).addOption(new Option("--orientation <orientation>", "page orientation").choices(ORIENTATIONS)).option("--no-cover", "skip the title page").option("--contents", "add a self-filling contents page").action(async (file, flags) => {
|
|
179
|
-
const { importDoc } = await import("../import-
|
|
189
|
+
const { importDoc } = await import("../import-CcmrFetU.js");
|
|
180
190
|
await importDoc(file, flags);
|
|
181
191
|
});
|
|
182
192
|
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) => {
|
|
183
193
|
const { syncSkills } = await Promise.resolve().then(() => sync_exports);
|
|
184
194
|
await syncSkills(resolveBuiltinSkillsDir(), flags);
|
|
185
195
|
});
|
|
196
|
+
program.command("deploy").description("Deploy and manage this workspace on a cloud provider (e.g. `open-doc deploy gcp`)").command("gcp").description("Deploy to Google Cloud Run + Cloud Storage, sync files, or stop/delete the service").addArgument(new Argument("[action]", "up (deploy), check (preflight diagnostics), status, pull, push, stop, start, or down").choices([...GCP_DEPLOY_ACTIONS]).default("up")).option("--project <id>", "Google Cloud project ID").option("--region <region>", "Cloud Run and Cloud Storage region (defaults to asia-east1)").option("--service <name>", "Cloud Run service name").option("--bucket <name>", "Cloud Storage bucket name for persistent docs/assets/themes").addOption(new Option("--mode <mode>", "deployment mode: editable (GCS + MCP) or static").choices(["editable", "static"])).option("--memory <size>", "Cloud Run memory limit (defaults to 1Gi)").option("--token <token>", "Bearer token for the remote /mcp endpoint").option("--dry-run", "print the cloud commands without executing them").option("--json", "print output as JSON (for check and status)").option("--delete", "with pull/push: delete destination files missing from source").option("--pull", "with stop: pull latest files from Cloud Storage before locking service").option("--skip-pull", "with down: skip backing up files from Cloud Storage before deleting").option("--purge-storage", "with down: also delete the Cloud Storage bucket").option("-y, --yes", "skip confirmation prompts").action(async (action, flags) => {
|
|
197
|
+
const mod = await import("../deploy-gcp-BUiSuqz7.js");
|
|
198
|
+
switch (action) {
|
|
199
|
+
case "up":
|
|
200
|
+
await mod.runGcpUp(flags);
|
|
201
|
+
break;
|
|
202
|
+
case "check":
|
|
203
|
+
await mod.runGcpCheck(flags);
|
|
204
|
+
break;
|
|
205
|
+
case "status":
|
|
206
|
+
await mod.runGcpStatus(flags);
|
|
207
|
+
break;
|
|
208
|
+
case "pull":
|
|
209
|
+
await mod.runGcpPull(flags);
|
|
210
|
+
break;
|
|
211
|
+
case "push":
|
|
212
|
+
await mod.runGcpPush(flags);
|
|
213
|
+
break;
|
|
214
|
+
case "stop":
|
|
215
|
+
await mod.runGcpStop(flags);
|
|
216
|
+
break;
|
|
217
|
+
case "start":
|
|
218
|
+
await mod.runGcpStart(flags);
|
|
219
|
+
break;
|
|
220
|
+
case "down": await mod.runGcpDown(flags);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
186
223
|
await program.parseAsync(argv, { from: "user" });
|
|
187
224
|
}
|
|
188
225
|
//#endregion
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/config.d.ts
|
|
2
|
+
type OpenDocBuildConfig = {
|
|
3
|
+
/** Ship the document browser (`/`) in the static build. Defaults to true. */
|
|
4
|
+
showDocBrowser?: boolean;
|
|
5
|
+
/** Offer the "Export HTML" button in the static build. Defaults to true. */
|
|
6
|
+
allowHtmlExport?: boolean;
|
|
7
|
+
};
|
|
8
|
+
type OpenDocGcpDeployConfig = {
|
|
9
|
+
/** Google Cloud project ID. Falls back to `--project` or `gcloud config`. */
|
|
10
|
+
project?: string;
|
|
11
|
+
/** Cloud Run and Cloud Storage region. Defaults to `asia-east1`. */
|
|
12
|
+
region?: string;
|
|
13
|
+
/** Cloud Run service name. Defaults to package name or directory name. */
|
|
14
|
+
service?: string;
|
|
15
|
+
/** Cloud Storage bucket name for persistent docs/assets/themes. */
|
|
16
|
+
bucket?: string;
|
|
17
|
+
/**
|
|
18
|
+
* `editable` runs `open-doc dev --mcp` backed by GCS FUSE so edits and
|
|
19
|
+
* Antigravity MCP calls persist. `static` builds a read-only bundle.
|
|
20
|
+
*/
|
|
21
|
+
mode?: 'editable' | 'static';
|
|
22
|
+
/** Cloud Run container memory limit. Defaults to `1Gi`. */
|
|
23
|
+
memory?: string;
|
|
24
|
+
};
|
|
25
|
+
type OpenDocDeployConfig = {
|
|
26
|
+
gcp?: OpenDocGcpDeployConfig;
|
|
27
|
+
};
|
|
28
|
+
type OpenDocConfig = {
|
|
29
|
+
base?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Where the viewer's back affordance goes. Unset it points at this app's own
|
|
32
|
+
* document browser; set it to escape the app entirely — a viewer mounted
|
|
33
|
+
* under a larger site needs to return to that site, not to its own index.
|
|
34
|
+
*/
|
|
35
|
+
home?: string;
|
|
36
|
+
docsDir?: string;
|
|
37
|
+
themesDir?: string;
|
|
38
|
+
assetsDir?: string;
|
|
39
|
+
port?: number;
|
|
40
|
+
allowedHosts?: string[] | true;
|
|
41
|
+
build?: OpenDocBuildConfig;
|
|
42
|
+
deploy?: OpenDocDeployConfig;
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { OpenDocGcpDeployConfig as i, OpenDocConfig as n, OpenDocDeployConfig as r, OpenDocBuildConfig as t };
|
|
@@ -1,318 +1,19 @@
|
|
|
1
|
-
import { a as defaultDesign, n as DiagramSyntaxError, r as parseDelimited, t as compileDiagram } from "./diagram-
|
|
1
|
+
import { a as defaultDesign, n as DiagramSyntaxError, r as parseDelimited, t as compileDiagram } from "./diagram-CKf3ptOE.js";
|
|
2
2
|
import { t as corePackageRoot } from "./package-version-C89gtYSk.js";
|
|
3
|
+
import { n as loadUserConfig, r as openDocPlugin, t as DOC_ID_RE } from "./open-doc-plugin-DnX5usgI.js";
|
|
3
4
|
import chalk from "chalk";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
7
|
import fs from "node:fs/promises";
|
|
7
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
8
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
8
9
|
import fg from "fast-glob";
|
|
9
|
-
import {
|
|
10
|
+
import { normalizePath } from "vite";
|
|
10
11
|
import { execFile } from "node:child_process";
|
|
11
12
|
import { promisify } from "node:util";
|
|
12
13
|
import { parse } from "@babel/parser";
|
|
13
14
|
import { createHash, randomUUID } from "node:crypto";
|
|
14
15
|
import tailwindcss from "@tailwindcss/vite";
|
|
15
16
|
import react from "@vitejs/plugin-react";
|
|
16
|
-
//#region src/vite/open-doc-plugin.ts
|
|
17
|
-
const DOC_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
18
|
-
const CONFIG_FILE = "open-doc.config.ts";
|
|
19
|
-
const DOCS_VMOD = "virtual:open-doc/docs";
|
|
20
|
-
const CONFIG_VMOD = "virtual:open-doc/config";
|
|
21
|
-
const FOLDERS_VMOD = "virtual:open-doc/folders";
|
|
22
|
-
async function readFoldersManifest(file) {
|
|
23
|
-
try {
|
|
24
|
-
const parsed = JSON.parse(await fs.readFile(file, "utf8"));
|
|
25
|
-
return {
|
|
26
|
-
folders: Array.isArray(parsed.folders) ? parsed.folders : [],
|
|
27
|
-
assignments: parsed.assignments && typeof parsed.assignments === "object" ? parsed.assignments : {}
|
|
28
|
-
};
|
|
29
|
-
} catch (err) {
|
|
30
|
-
if (err.code === "ENOENT") return {
|
|
31
|
-
folders: [],
|
|
32
|
-
assignments: {}
|
|
33
|
-
};
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function resolved$1(id) {
|
|
38
|
-
return `\0${id}`;
|
|
39
|
-
}
|
|
40
|
-
async function findDocs(userCwd, docsDir) {
|
|
41
|
-
const abs = path.resolve(userCwd, docsDir);
|
|
42
|
-
if (!existsSync(abs)) return [];
|
|
43
|
-
return (await fg("*/index.{tsx,jsx,ts,js}", {
|
|
44
|
-
cwd: abs,
|
|
45
|
-
absolute: true,
|
|
46
|
-
onlyFiles: true
|
|
47
|
-
})).sort();
|
|
48
|
-
}
|
|
49
|
-
function toId(absFile, docsRoot) {
|
|
50
|
-
return path.relative(docsRoot, absFile).split(path.sep)[0];
|
|
51
|
-
}
|
|
52
|
-
const META_CREATED_AT_RE = /(?:^|[\s,{])createdAt\s*:\s*['"]([^'"]+)['"]/;
|
|
53
|
-
const META_THEME_RE = /(?:^|[\s,{])theme\s*:\s*['"]([^'"]+)['"]/;
|
|
54
|
-
const META_TITLE_RE = /(?:^|[\s,{])title\s*:\s*(['"`])((?:\\.|(?!\1)[^\\])*)\1/;
|
|
55
|
-
/**
|
|
56
|
-
* Reads `meta` with a brace-matched regex instead of parsing: the plugin runs on
|
|
57
|
-
* every discovery pass, and the fields it needs (sort order, theme back-link,
|
|
58
|
-
* the title search and sorting use without loading every document) are
|
|
59
|
-
* contractually string literals.
|
|
60
|
-
*/
|
|
61
|
-
function extractMeta(src) {
|
|
62
|
-
const empty = {
|
|
63
|
-
theme: null,
|
|
64
|
-
createdAt: null,
|
|
65
|
-
title: null
|
|
66
|
-
};
|
|
67
|
-
const metaStart = src.search(/export\s+const\s+meta\b/);
|
|
68
|
-
if (metaStart === -1) return empty;
|
|
69
|
-
const openBrace = src.indexOf("{", src.indexOf("=", metaStart));
|
|
70
|
-
if (openBrace === -1) return empty;
|
|
71
|
-
let depth = 0;
|
|
72
|
-
let closeBrace = -1;
|
|
73
|
-
for (let i = openBrace; i < src.length; i++) {
|
|
74
|
-
const ch = src[i];
|
|
75
|
-
if (ch === "{") depth++;
|
|
76
|
-
else if (ch === "}") {
|
|
77
|
-
depth--;
|
|
78
|
-
if (depth === 0) {
|
|
79
|
-
closeBrace = i;
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (closeBrace === -1) return empty;
|
|
85
|
-
const body = src.slice(openBrace + 1, closeBrace);
|
|
86
|
-
return {
|
|
87
|
-
theme: body.match(META_THEME_RE)?.[1] ?? null,
|
|
88
|
-
createdAt: body.match(META_CREATED_AT_RE)?.[1] ?? null,
|
|
89
|
-
title: unescapeLiteral(body.match(META_TITLE_RE)?.[2] ?? null)
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function unescapeLiteral(raw) {
|
|
93
|
-
return raw === null ? null : raw.replace(/\\(.)/g, "$1");
|
|
94
|
-
}
|
|
95
|
-
function parseCreatedAtMs(iso) {
|
|
96
|
-
if (!iso) return null;
|
|
97
|
-
const ms = Date.parse(iso);
|
|
98
|
-
return Number.isFinite(ms) ? ms : null;
|
|
99
|
-
}
|
|
100
|
-
async function readMeta(abs) {
|
|
101
|
-
try {
|
|
102
|
-
return extractMeta(await fs.readFile(abs, "utf8"));
|
|
103
|
-
} catch {
|
|
104
|
-
return {
|
|
105
|
-
theme: null,
|
|
106
|
-
createdAt: null,
|
|
107
|
-
title: null
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
const warnedInvalidDocIds = /* @__PURE__ */ new Set();
|
|
112
|
-
async function generateDocsModule(files, docsRoot, isDev) {
|
|
113
|
-
const scanned = await Promise.all(files.map(async (abs) => {
|
|
114
|
-
const meta = await readMeta(abs);
|
|
115
|
-
return {
|
|
116
|
-
id: toId(abs, docsRoot),
|
|
117
|
-
importPath: isDev ? `@fs/${normalizePath(abs).replace(/^\/+/, "")}` : abs,
|
|
118
|
-
theme: meta.theme,
|
|
119
|
-
title: meta.title,
|
|
120
|
-
createdAt: parseCreatedAtMs(meta.createdAt)
|
|
121
|
-
};
|
|
122
|
-
}));
|
|
123
|
-
const entries = scanned.filter((e) => DOC_ID_RE.test(e.id));
|
|
124
|
-
const ignored = scanned.filter((e) => !DOC_ID_RE.test(e.id)).map((e) => e.id);
|
|
125
|
-
const ids = JSON.stringify(entries.map((e) => e.id).sort());
|
|
126
|
-
const createdAtMap = {};
|
|
127
|
-
const themesMap = {};
|
|
128
|
-
const titlesMap = {};
|
|
129
|
-
for (const e of entries) {
|
|
130
|
-
if (e.createdAt !== null) createdAtMap[e.id] = e.createdAt;
|
|
131
|
-
if (e.theme) themesMap[e.id] = e.theme;
|
|
132
|
-
if (e.title) titlesMap[e.id] = e.title;
|
|
133
|
-
}
|
|
134
|
-
const importTokens = JSON.stringify(Object.fromEntries(entries.map((e) => [e.id, 0])));
|
|
135
|
-
const devRuntime = isDev ? `
|
|
136
|
-
const docImportTokens = ${importTokens};
|
|
137
|
-
if (import.meta.hot) {
|
|
138
|
-
import.meta.hot.on('open-doc:doc-changed', (data) => {
|
|
139
|
-
const ids = Array.isArray(data?.docIds) ? data.docIds : data?.docId ? [data.docId] : [];
|
|
140
|
-
const token = Date.now();
|
|
141
|
-
for (const id of ids) {
|
|
142
|
-
if (Object.prototype.hasOwnProperty.call(docImportTokens, id)) docImportTokens[id] = token;
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
` : "";
|
|
147
|
-
const cases = entries.map((e) => {
|
|
148
|
-
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)})`;
|
|
149
|
-
return ` case ${JSON.stringify(e.id)}: return ${importExpr};`;
|
|
150
|
-
}).join("\n");
|
|
151
|
-
return {
|
|
152
|
-
code: `// virtual:open-doc/docs — generated
|
|
153
|
-
export const docIds = ${ids};
|
|
154
|
-
export const docCreatedAt = ${JSON.stringify(createdAtMap)};
|
|
155
|
-
export const docThemes = ${JSON.stringify(themesMap)};
|
|
156
|
-
export const docTitles = ${JSON.stringify(titlesMap)};
|
|
157
|
-
${devRuntime}
|
|
158
|
-
|
|
159
|
-
export async function loadDoc(id) {
|
|
160
|
-
switch (id) {
|
|
161
|
-
${cases}
|
|
162
|
-
default: throw new Error('Document not found: ' + id);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
`,
|
|
166
|
-
ignored
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
function openDocPlugin(opts) {
|
|
170
|
-
const { userCwd, config, coreVersion } = opts;
|
|
171
|
-
const docsDir = config.docsDir ?? "docs";
|
|
172
|
-
const docsRoot = path.resolve(userCwd, docsDir);
|
|
173
|
-
const foldersManifestPath = path.join(docsRoot, ".folders.json");
|
|
174
|
-
let isDev = false;
|
|
175
|
-
let listedIds = "";
|
|
176
|
-
const docIdForEntry = (p) => {
|
|
177
|
-
const rel = path.relative(docsRoot, p);
|
|
178
|
-
if (rel.startsWith("..") || path.isAbsolute(rel)) return null;
|
|
179
|
-
const parts = rel.split(path.sep);
|
|
180
|
-
if (parts.length !== 2) return null;
|
|
181
|
-
if (!/^index\.(tsx|jsx|ts|js)$/.test(parts[1])) return null;
|
|
182
|
-
return parts[0];
|
|
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$1(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$1(DOCS_VMOD);
|
|
210
|
-
if (id === CONFIG_VMOD) return resolved$1(CONFIG_VMOD);
|
|
211
|
-
if (id === FOLDERS_VMOD) return resolved$1(FOLDERS_VMOD);
|
|
212
|
-
return null;
|
|
213
|
-
},
|
|
214
|
-
async load(id) {
|
|
215
|
-
if (id === resolved$1(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$1(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$1(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$1(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.middlewares.use("/__docs-rescan", async (_req, res) => {
|
|
270
|
-
const files = await findDocs(userCwd, docsDir);
|
|
271
|
-
const changed = JSON.stringify(files.map((file) => toId(file, docsRoot)).sort()) !== listedIds;
|
|
272
|
-
if (changed) reload();
|
|
273
|
-
res.setHeader("content-type", "application/json");
|
|
274
|
-
res.end(JSON.stringify({ changed }));
|
|
275
|
-
});
|
|
276
|
-
server.watcher.on("unlink", (p) => {
|
|
277
|
-
if (isDocEntry(p)) reload();
|
|
278
|
-
});
|
|
279
|
-
server.watcher.on("unlinkDir", (p) => {
|
|
280
|
-
if (path.dirname(p) === docsRoot) reload();
|
|
281
|
-
});
|
|
282
|
-
let foldersTimer = null;
|
|
283
|
-
const foldersChanged = () => {
|
|
284
|
-
if (foldersTimer) clearTimeout(foldersTimer);
|
|
285
|
-
foldersTimer = setTimeout(() => {
|
|
286
|
-
foldersTimer = null;
|
|
287
|
-
const mod = server.moduleGraph.getModuleById(resolved$1(FOLDERS_VMOD));
|
|
288
|
-
if (mod) server.moduleGraph.invalidateModule(mod);
|
|
289
|
-
server.ws.send({
|
|
290
|
-
type: "custom",
|
|
291
|
-
event: "open-doc:files-changed",
|
|
292
|
-
data: {}
|
|
293
|
-
});
|
|
294
|
-
}, 100);
|
|
295
|
-
};
|
|
296
|
-
server.watcher.add(foldersManifestPath);
|
|
297
|
-
for (const event of [
|
|
298
|
-
"add",
|
|
299
|
-
"change",
|
|
300
|
-
"unlink"
|
|
301
|
-
]) server.watcher.on(event, (p) => {
|
|
302
|
-
if (p === foldersManifestPath) foldersChanged();
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
async function loadUserConfig(userCwd) {
|
|
308
|
-
const file = path.join(userCwd, CONFIG_FILE);
|
|
309
|
-
if (!existsSync(file)) return {};
|
|
310
|
-
return (await loadConfigFromFile({
|
|
311
|
-
command: "serve",
|
|
312
|
-
mode: "development"
|
|
313
|
-
}, file, userCwd, "silent"))?.config ?? {};
|
|
314
|
-
}
|
|
315
|
-
//#endregion
|
|
316
17
|
//#region src/vite/routes/context.ts
|
|
317
18
|
function makeContext(opts) {
|
|
318
19
|
const userCwd = opts.userCwd;
|
|
@@ -461,7 +162,9 @@ const FORWARDING_COMPONENTS = /* @__PURE__ */ new Set([
|
|
|
461
162
|
"ImagePlaceholder",
|
|
462
163
|
"Figure",
|
|
463
164
|
"DataTable",
|
|
464
|
-
"Footnote"
|
|
165
|
+
"Footnote",
|
|
166
|
+
"CodeBlock",
|
|
167
|
+
"Callout"
|
|
465
168
|
]);
|
|
466
169
|
function taggableName(opening) {
|
|
467
170
|
const name = opening.name;
|
|
@@ -1984,15 +1687,18 @@ function registerDocRoutes(server, ctx) {
|
|
|
1984
1687
|
if (method === "PATCH") {
|
|
1985
1688
|
const requestCheck = validateMutationRequest(req, { requireJsonBody: true });
|
|
1986
1689
|
if (!requestCheck.ok) return json(res, requestCheck.status, { error: requestCheck.error });
|
|
1690
|
+
const result = await renameDocument(ctx, docId, (await readBody(req)).title);
|
|
1691
|
+
server.watcher.emit("change", `${ctx.docsRoot}/${docId}/index.tsx`);
|
|
1987
1692
|
return json(res, 200, {
|
|
1988
1693
|
ok: true,
|
|
1989
|
-
title:
|
|
1694
|
+
title: result.title
|
|
1990
1695
|
});
|
|
1991
1696
|
}
|
|
1992
1697
|
if (method === "DELETE") {
|
|
1993
1698
|
const requestCheck = validateMutationRequest(req);
|
|
1994
1699
|
if (!requestCheck.ok) return json(res, requestCheck.status, { error: requestCheck.error });
|
|
1995
1700
|
await deleteDocument(ctx, docId);
|
|
1701
|
+
server.watcher.emit("unlink", `${ctx.docsRoot}/${docId}/index.tsx`);
|
|
1996
1702
|
return json(res, 200, { ok: true });
|
|
1997
1703
|
}
|
|
1998
1704
|
}
|
|
@@ -3619,7 +3325,10 @@ function registerEditRoutes(server, ctx) {
|
|
|
3619
3325
|
prop: typeof body.prop === "string" ? body.prop : void 0
|
|
3620
3326
|
});
|
|
3621
3327
|
if (!result.ok) return json(res, result.status, { error: result.error });
|
|
3622
|
-
if (result.source !== source)
|
|
3328
|
+
if (result.source !== source) {
|
|
3329
|
+
await fs.writeFile(entry, result.source, "utf8");
|
|
3330
|
+
server.watcher.emit("change", entry);
|
|
3331
|
+
}
|
|
3623
3332
|
return json(res, 200, { ok: true });
|
|
3624
3333
|
}
|
|
3625
3334
|
if (method === "PUT" && url.pathname === "/texts") {
|
|
@@ -3629,7 +3338,10 @@ function registerEditRoutes(server, ctx) {
|
|
|
3629
3338
|
if (typeof body.docId !== "string" || !Array.isArray(body.edits)) return json(res, 400, { error: "invalid payload" });
|
|
3630
3339
|
const edits = readTextEdits(body.docId, body.edits);
|
|
3631
3340
|
if (!edits) return json(res, 400, { error: "invalid payload" });
|
|
3632
|
-
|
|
3341
|
+
const out = await writeTexts(ctx, body.docId, edits);
|
|
3342
|
+
const entry = entryFor(body.docId);
|
|
3343
|
+
if (entry) server.watcher.emit("change", entry);
|
|
3344
|
+
return json(res, 200, out);
|
|
3633
3345
|
}
|
|
3634
3346
|
if (method === "GET" && url.pathname === "/style") {
|
|
3635
3347
|
const loc = readLoc({
|
|
@@ -3649,7 +3361,10 @@ function registerEditRoutes(server, ctx) {
|
|
|
3649
3361
|
const texts = readTextEdits(body.docId, body.texts ?? []);
|
|
3650
3362
|
const styles = readStyleEdits(body.docId, body.styles ?? []);
|
|
3651
3363
|
if (!texts || !styles) return json(res, 400, { error: "invalid payload" });
|
|
3652
|
-
|
|
3364
|
+
const out = await writeEdits(ctx, body.docId, texts, styles);
|
|
3365
|
+
const entry = entryFor(body.docId);
|
|
3366
|
+
if (entry) server.watcher.emit("change", entry);
|
|
3367
|
+
return json(res, 200, out);
|
|
3653
3368
|
}
|
|
3654
3369
|
if (method === "POST" && url.pathname === "/comment") {
|
|
3655
3370
|
const check = validateMutationRequest(req, { requireJsonBody: true });
|
|
@@ -3663,6 +3378,7 @@ function registerEditRoutes(server, ctx) {
|
|
|
3663
3378
|
const inserted = insertMarker(await fs.readFile(entry, "utf8"), loc, note.trim(), typeof body.hint === "string" ? body.hint : void 0);
|
|
3664
3379
|
if (!inserted) return json(res, 422, { error: "cannot anchor a comment here — pick the surrounding element" });
|
|
3665
3380
|
await fs.writeFile(entry, inserted.source, "utf8");
|
|
3381
|
+
server.watcher.emit("change", entry);
|
|
3666
3382
|
return json(res, 200, {
|
|
3667
3383
|
ok: true,
|
|
3668
3384
|
id: inserted.id
|
|
@@ -3693,6 +3409,7 @@ function registerEditRoutes(server, ctx) {
|
|
|
3693
3409
|
const next = removeMarker(await fs.readFile(entry, "utf8"), id);
|
|
3694
3410
|
if (next === null) return json(res, 404, { error: "comment not found" });
|
|
3695
3411
|
await fs.writeFile(entry, next, "utf8");
|
|
3412
|
+
server.watcher.emit("change", entry);
|
|
3696
3413
|
return json(res, 200, { ok: true });
|
|
3697
3414
|
}
|
|
3698
3415
|
return next();
|
|
@@ -4371,7 +4088,11 @@ function mcpPlugin(opts) {
|
|
|
4371
4088
|
docsDir: opts.docsDir,
|
|
4372
4089
|
assetsDir: opts.assetsDir,
|
|
4373
4090
|
version: opts.coreVersion,
|
|
4374
|
-
serverOrigin: originOf()
|
|
4091
|
+
serverOrigin: originOf(),
|
|
4092
|
+
...opts.allowedHosts !== void 0 ? { allowedHosts: opts.allowedHosts } : {},
|
|
4093
|
+
onFileChange: (event, filePath) => {
|
|
4094
|
+
server.watcher.emit(event, filePath);
|
|
4095
|
+
}
|
|
4375
4096
|
});
|
|
4376
4097
|
return middleware(req, res, next);
|
|
4377
4098
|
});
|
|
@@ -4404,6 +4125,13 @@ function readCoreVersion() {
|
|
|
4404
4125
|
}
|
|
4405
4126
|
}
|
|
4406
4127
|
const CORE_VERSION = readCoreVersion();
|
|
4128
|
+
function safeRealpath(target) {
|
|
4129
|
+
try {
|
|
4130
|
+
return existsSync(target) ? realpathSync(target) : null;
|
|
4131
|
+
} catch {
|
|
4132
|
+
return null;
|
|
4133
|
+
}
|
|
4134
|
+
}
|
|
4407
4135
|
async function createViteConfig(opts) {
|
|
4408
4136
|
const userCwd = path.resolve(opts.userCwd);
|
|
4409
4137
|
const config = opts.config ?? await loadUserConfig(userCwd);
|
|
@@ -4412,6 +4140,25 @@ async function createViteConfig(opts) {
|
|
|
4412
4140
|
const docsAbs = path.resolve(userCwd, docsDir);
|
|
4413
4141
|
const themesAbs = path.resolve(userCwd, config.themesDir ?? "themes");
|
|
4414
4142
|
const assetsAbs = path.resolve(userCwd, assetsDir);
|
|
4143
|
+
const isCloud = process.env.OPEN_DOC_CLOUD === "1" || Boolean(process.env.K_SERVICE);
|
|
4144
|
+
const allowedHosts = config.allowedHosts ?? (isCloud ? true : void 0);
|
|
4145
|
+
const fsAllow = /* @__PURE__ */ new Set([
|
|
4146
|
+
APP_ROOT,
|
|
4147
|
+
userCwd,
|
|
4148
|
+
docsAbs,
|
|
4149
|
+
themesAbs,
|
|
4150
|
+
assetsAbs
|
|
4151
|
+
]);
|
|
4152
|
+
for (const candidate of [
|
|
4153
|
+
userCwd,
|
|
4154
|
+
docsAbs,
|
|
4155
|
+
themesAbs,
|
|
4156
|
+
assetsAbs
|
|
4157
|
+
]) {
|
|
4158
|
+
const real = safeRealpath(candidate);
|
|
4159
|
+
if (real) fsAllow.add(real);
|
|
4160
|
+
}
|
|
4161
|
+
if (process.env.OPEN_DOC_MOUNT_DIR) fsAllow.add(path.resolve(process.env.OPEN_DOC_MOUNT_DIR));
|
|
4415
4162
|
return {
|
|
4416
4163
|
base: config.base ?? "/",
|
|
4417
4164
|
root: APP_ROOT,
|
|
@@ -4453,7 +4200,8 @@ async function createViteConfig(opts) {
|
|
|
4453
4200
|
userCwd,
|
|
4454
4201
|
docsDir,
|
|
4455
4202
|
assetsDir,
|
|
4456
|
-
coreVersion: CORE_VERSION
|
|
4203
|
+
coreVersion: CORE_VERSION,
|
|
4204
|
+
...allowedHosts !== void 0 ? { allowedHosts } : {}
|
|
4457
4205
|
})] : []
|
|
4458
4206
|
],
|
|
4459
4207
|
resolve: { alias: {
|
|
@@ -4464,6 +4212,8 @@ async function createViteConfig(opts) {
|
|
|
4464
4212
|
entries: [path.join(APP_ROOT, "main.tsx")],
|
|
4465
4213
|
include: [
|
|
4466
4214
|
"react",
|
|
4215
|
+
"react/jsx-runtime",
|
|
4216
|
+
"react/jsx-dev-runtime",
|
|
4467
4217
|
"react-dom",
|
|
4468
4218
|
"react-dom/client",
|
|
4469
4219
|
"react-router-dom",
|
|
@@ -4483,15 +4233,13 @@ async function createViteConfig(opts) {
|
|
|
4483
4233
|
}] }
|
|
4484
4234
|
},
|
|
4485
4235
|
server: {
|
|
4486
|
-
port: config.port ?? 5273,
|
|
4487
|
-
...
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
assetsAbs
|
|
4494
|
-
] }
|
|
4236
|
+
port: config.port ?? (process.env.PORT ? Number(process.env.PORT) : 5273),
|
|
4237
|
+
...allowedHosts !== void 0 ? { allowedHosts } : {},
|
|
4238
|
+
...isCloud ? { watch: {
|
|
4239
|
+
usePolling: true,
|
|
4240
|
+
interval: 1500
|
|
4241
|
+
} } : {},
|
|
4242
|
+
fs: { allow: [...fsAllow] }
|
|
4495
4243
|
},
|
|
4496
4244
|
build: {
|
|
4497
4245
|
outDir: path.resolve(userCwd, "dist"),
|
|
@@ -4500,4 +4248,4 @@ async function createViteConfig(opts) {
|
|
|
4500
4248
|
};
|
|
4501
4249
|
}
|
|
4502
4250
|
//#endregion
|
|
4503
|
-
export { renameDocument as A, createDocument as C, listDocIds$1 as D, duplicateDocument as E,
|
|
4251
|
+
export { renameDocument as A, createDocument as C, listDocIds$1 as D, duplicateDocument as E, writeDocument as M, makeContext as N, listDocuments as O, OpsError as S, docDir as T, writeAsset as _, writeTexts as a, readChanges as b, suggestDocId as c, fileDocument as d, findAssetUsages as f, readTheme as g, listThemes as h, writeText as i, resolveEntry as j, readDocument as k, createFolder as l, listFolders as m, addComment as n, createFromTemplate as o, listAssets as p, readText as r, listTemplates as s, createViteConfig as t, deleteAsset as u, validateAssetName as v, deleteDocument as w, revertChange as x, listRevisions as y };
|