@open-press/cli 0.8.0 → 1.1.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/README.md +33 -23
- package/dist/cli.js +320 -252
- package/package.json +9 -8
- package/template/core/AGENTS.md +0 -126
- package/template/core/CHANGELOG.md +0 -215
- package/template/core/README.md +0 -40
- package/template/core/engine/cli.mjs +0 -96
- package/template/core/engine/commands/_shared.mjs +0 -177
- package/template/core/engine/commands/deploy.mjs +0 -31
- package/template/core/engine/commands/dev.mjs +0 -49
- package/template/core/engine/commands/doctor.mjs +0 -229
- package/template/core/engine/commands/export.mjs +0 -8
- package/template/core/engine/commands/init.mjs +0 -24
- package/template/core/engine/commands/inspect.mjs +0 -35
- package/template/core/engine/commands/pdf.mjs +0 -26
- package/template/core/engine/commands/preview.mjs +0 -26
- package/template/core/engine/commands/render.mjs +0 -17
- package/template/core/engine/commands/replace.mjs +0 -41
- package/template/core/engine/commands/search.mjs +0 -33
- package/template/core/engine/commands/typecheck.mjs +0 -5
- package/template/core/engine/commands/upgrade.mjs +0 -159
- package/template/core/engine/commands/validate.mjs +0 -17
- package/template/core/engine/document-export.mjs +0 -15
- package/template/core/engine/init.mjs +0 -90
- package/template/core/engine/output/chrome-pdf.d.mts +0 -34
- package/template/core/engine/output/chrome-pdf.mjs +0 -358
- package/template/core/engine/output/deploy-sync.mjs +0 -15
- package/template/core/engine/output/fonts.mjs +0 -62
- package/template/core/engine/output/katex-assets.mjs +0 -45
- package/template/core/engine/output/page-block.mjs +0 -30
- package/template/core/engine/output/pdf-media.mjs +0 -45
- package/template/core/engine/output/public-assets.mjs +0 -19
- package/template/core/engine/output/static-server.mjs +0 -532
- package/template/core/engine/react/caption-numbering.mjs +0 -73
- package/template/core/engine/react/comment-endpoint.d.mts +0 -11
- package/template/core/engine/react/comment-endpoint.mjs +0 -102
- package/template/core/engine/react/comment-marker.mjs +0 -374
- package/template/core/engine/react/document-entry.mjs +0 -324
- package/template/core/engine/react/document-export.mjs +0 -373
- package/template/core/engine/react/http-json.mjs +0 -24
- package/template/core/engine/react/mdx-compile.mjs +0 -599
- package/template/core/engine/react/measurement-css.mjs +0 -136
- package/template/core/engine/react/object-entities.mjs +0 -119
- package/template/core/engine/react/pagination/allocator.mjs +0 -122
- package/template/core/engine/react/pagination/regions.mjs +0 -81
- package/template/core/engine/react/pagination-constants.mjs +0 -3
- package/template/core/engine/react/pagination.mjs +0 -9
- package/template/core/engine/react/pipeline/allocate.mjs +0 -251
- package/template/core/engine/react/pipeline/final-render.mjs +0 -94
- package/template/core/engine/react/pipeline/frame-measurement.mjs +0 -302
- package/template/core/engine/react/pipeline/press-tree.mjs +0 -135
- package/template/core/engine/react/project-asset-endpoint.d.mts +0 -10
- package/template/core/engine/react/project-asset-endpoint.mjs +0 -361
- package/template/core/engine/react/section-css.mjs +0 -56
- package/template/core/engine/react/source-edit-endpoint.d.mts +0 -10
- package/template/core/engine/react/source-edit-endpoint.mjs +0 -75
- package/template/core/engine/react/sources/heading-numbering.mjs +0 -132
- package/template/core/engine/react/sources/mdx-resolver.mjs +0 -439
- package/template/core/engine/react/style-discovery.mjs +0 -142
- package/template/core/engine/runtime/config.d.mts +0 -40
- package/template/core/engine/runtime/config.mjs +0 -175
- package/template/core/engine/runtime/file-utils.mjs +0 -106
- package/template/core/engine/runtime/file-walk.mjs +0 -22
- package/template/core/engine/runtime/inspection.mjs +0 -328
- package/template/core/engine/runtime/issue-report.mjs +0 -44
- package/template/core/engine/runtime/path-utils.mjs +0 -20
- package/template/core/engine/runtime/source-text-tools.d.mts +0 -102
- package/template/core/engine/runtime/source-text-tools.mjs +0 -832
- package/template/core/engine/runtime/source-workspace.mjs +0 -159
- package/template/core/engine/runtime/validation.mjs +0 -174
- package/template/core/index.html +0 -13
- package/template/core/openpress.config.mjs +0 -12
- package/template/core/package.json +0 -91
- package/template/core/src/main.tsx +0 -16
- package/template/core/src/openpress/app/OpenPressApp.tsx +0 -140
- package/template/core/src/openpress/app/OpenPressRuntime.tsx +0 -94
- package/template/core/src/openpress/app/index.ts +0 -2
- package/template/core/src/openpress/core/Frame.tsx +0 -78
- package/template/core/src/openpress/core/FrameContext.tsx +0 -24
- package/template/core/src/openpress/core/MdxArea.tsx +0 -34
- package/template/core/src/openpress/core/Press.tsx +0 -34
- package/template/core/src/openpress/core/cn.ts +0 -4
- package/template/core/src/openpress/core/index.tsx +0 -40
- package/template/core/src/openpress/core/primitives.tsx +0 -44
- package/template/core/src/openpress/core/types.ts +0 -191
- package/template/core/src/openpress/core/useSource.ts +0 -28
- package/template/core/src/openpress/document-model/anchorMapModel.ts +0 -27
- package/template/core/src/openpress/document-model/documentIndexes.ts +0 -329
- package/template/core/src/openpress/document-model/documentTypes.ts +0 -138
- package/template/core/src/openpress/document-model/index.ts +0 -6
- package/template/core/src/openpress/document-model/objectEntityModel.ts +0 -51
- package/template/core/src/openpress/document-model/projectIdentityModel.ts +0 -15
- package/template/core/src/openpress/document-model/reactDocumentMetadataModel.ts +0 -27
- package/template/core/src/openpress/manuscript/index.tsx +0 -238
- package/template/core/src/openpress/mdx/index.ts +0 -88
- package/template/core/src/openpress/numbering/index.ts +0 -294
- package/template/core/src/openpress/reader/PublicReaderPage.tsx +0 -267
- package/template/core/src/openpress/reader/ReaderNavigationPanel.tsx +0 -123
- package/template/core/src/openpress/reader/index.ts +0 -10
- package/template/core/src/openpress/reader/pageViewportScaleModel.ts +0 -73
- package/template/core/src/openpress/reader/readerPageRegistry.ts +0 -41
- package/template/core/src/openpress/reader/readerPageRoute.ts +0 -21
- package/template/core/src/openpress/reader/readerScroll.ts +0 -92
- package/template/core/src/openpress/reader/readerStateModel.ts +0 -15
- package/template/core/src/openpress/reader/readerTypes.ts +0 -4
- package/template/core/src/openpress/reader/usePageViewportScale.ts +0 -119
- package/template/core/src/openpress/reader/usePanelState.ts +0 -56
- package/template/core/src/openpress/reader/useReaderHashSync.ts +0 -61
- package/template/core/src/openpress/reader/useReaderKeyboardNav.ts +0 -48
- package/template/core/src/openpress/reader/useReaderRuntime.ts +0 -146
- package/template/core/src/openpress/reader/useReaderScrollAnchor.ts +0 -64
- package/template/core/src/openpress/shared/Panel.tsx +0 -77
- package/template/core/src/openpress/shared/frameScheduler.ts +0 -32
- package/template/core/src/openpress/shared/index.ts +0 -4
- package/template/core/src/openpress/shared/numberUtils.ts +0 -3
- package/template/core/src/openpress/shared/runtimeMode.ts +0 -11
- package/template/core/src/openpress/workbench/Workbench.tsx +0 -407
- package/template/core/src/openpress/workbench/actions/DeploymentControl.tsx +0 -157
- package/template/core/src/openpress/workbench/actions/PageZoomControl.tsx +0 -182
- package/template/core/src/openpress/workbench/actions/SearchControl.tsx +0 -345
- package/template/core/src/openpress/workbench/actions/deploymentStatusModel.ts +0 -112
- package/template/core/src/openpress/workbench/actions/index.ts +0 -5
- package/template/core/src/openpress/workbench/actions/useDeploymentWorkbench.ts +0 -136
- package/template/core/src/openpress/workbench/dialog/WorkbenchDialog.tsx +0 -72
- package/template/core/src/openpress/workbench/dialog/index.ts +0 -1
- package/template/core/src/openpress/workbench/document/components/DocumentPanel.tsx +0 -127
- package/template/core/src/openpress/workbench/document/components/InlineSourceEditorLayer.tsx +0 -207
- package/template/core/src/openpress/workbench/document/components/ReaderStage.tsx +0 -9
- package/template/core/src/openpress/workbench/document/hooks/useDocumentWorkbenchModel.ts +0 -34
- package/template/core/src/openpress/workbench/document/hooks/useInlineDocumentEditor.ts +0 -525
- package/template/core/src/openpress/workbench/document/index.ts +0 -10
- package/template/core/src/openpress/workbench/index.ts +0 -2
- package/template/core/src/openpress/workbench/inspector/InlineInspectorLayer.tsx +0 -459
- package/template/core/src/openpress/workbench/inspector/index.ts +0 -5
- package/template/core/src/openpress/workbench/inspector/inlineCommentModel.ts +0 -125
- package/template/core/src/openpress/workbench/inspector/inspectorGeometryModel.ts +0 -160
- package/template/core/src/openpress/workbench/inspector/inspectorModel.ts +0 -408
- package/template/core/src/openpress/workbench/inspector/useInspectorComments.ts +0 -248
- package/template/core/src/openpress/workbench/mentions/MentionSuggestionList.tsx +0 -41
- package/template/core/src/openpress/workbench/mentions/index.ts +0 -2
- package/template/core/src/openpress/workbench/mentions/useComposerMentions.ts +0 -185
- package/template/core/src/openpress/workbench/panels/Panel.tsx +0 -1
- package/template/core/src/openpress/workbench/panels/PendingCommentsPanel.tsx +0 -76
- package/template/core/src/openpress/workbench/panels/WorkbenchControlPanel.tsx +0 -29
- package/template/core/src/openpress/workbench/panels/index.ts +0 -3
- package/template/core/src/openpress/workbench/project/ProjectEntryPanel.tsx +0 -523
- package/template/core/src/openpress/workbench/project/ProjectPreviewDialog.tsx +0 -35
- package/template/core/src/openpress/workbench/project/index.ts +0 -2
- package/template/core/src/openpress/workbench/project/projectPreviewTypes.ts +0 -11
- package/template/core/src/openpress/workbench/project/projectSourceModel.ts +0 -24
- package/template/core/src/openpress/workbench/shell/WorkbenchShell.tsx +0 -167
- package/template/core/src/openpress/workbench/shell/index.ts +0 -1
- package/template/core/src/openpress/workbench/workbenchFormatters.ts +0 -120
- package/template/core/src/openpress/workbench/workbenchTypes.ts +0 -35
- package/template/core/src/styles/openpress/app-shell.css +0 -251
- package/template/core/src/styles/openpress/media-workspace.css +0 -230
- package/template/core/src/styles/openpress/print-route.css +0 -184
- package/template/core/src/styles/openpress/project-preview-panel.css +0 -924
- package/template/core/src/styles/openpress/public-viewer.css +0 -688
- package/template/core/src/styles/openpress/reader-runtime.css +0 -980
- package/template/core/src/styles/openpress/responsive.css +0 -245
- package/template/core/src/styles/openpress/workbench-panels.css +0 -594
- package/template/core/src/styles/openpress/workbench.css +0 -1255
- package/template/core/src/styles/openpress.css +0 -14
- package/template/core/src/vite-env.d.ts +0 -9
- package/template/core/tsconfig.json +0 -40
- package/template/core/vite.config.ts +0 -584
- package/template/packs/academic-paper/document/chapters/01-introduction/content/01-introduction.mdx +0 -35
- package/template/packs/academic-paper/document/chapters/02-methods/content/01-methods.mdx +0 -50
- package/template/packs/academic-paper/document/chapters/03-results-and-discussion/content/01-results.mdx +0 -47
- package/template/packs/academic-paper/document/chapters/04-acknowledgment/content/01-acknowledgment.mdx +0 -26
- package/template/packs/academic-paper/document/chapters/05-references/content/01-references.mdx +0 -32
- package/template/packs/academic-paper/document/components/ChapterOpenerVisual/index.tsx +0 -76
- package/template/packs/academic-paper/document/components/Page.tsx +0 -60
- package/template/packs/academic-paper/document/components/TokenSwatchGrid/index.tsx +0 -46
- package/template/packs/academic-paper/document/components/TokenSwatchGrid/style.css +0 -63
- package/template/packs/academic-paper/document/components/TypeSpecimen/index.tsx +0 -38
- package/template/packs/academic-paper/document/components/TypeSpecimen/style.css +0 -111
- package/template/packs/academic-paper/document/design.md +0 -279
- package/template/packs/academic-paper/document/index.tsx +0 -123
- package/template/packs/academic-paper/document/media/README.md +0 -13
- package/template/packs/academic-paper/document/media/figure-placeholder.svg +0 -9
- package/template/packs/academic-paper/document/openpress.config.mjs +0 -26
- package/template/packs/academic-paper/document/theme/README.md +0 -11
- package/template/packs/academic-paper/document/theme/base/page-contract.css +0 -522
- package/template/packs/academic-paper/document/theme/base/print.css +0 -93
- package/template/packs/academic-paper/document/theme/base/typography.css +0 -333
- package/template/packs/academic-paper/document/theme/fonts.css +0 -3
- package/template/packs/academic-paper/document/theme/page-surfaces/back-cover.css +0 -43
- package/template/packs/academic-paper/document/theme/page-surfaces/chapter-opener.css +0 -205
- package/template/packs/academic-paper/document/theme/page-surfaces/cover.css +0 -294
- package/template/packs/academic-paper/document/theme/page-surfaces/toc.css +0 -149
- package/template/packs/academic-paper/document/theme/patterns/_chart-frame.css +0 -49
- package/template/packs/academic-paper/document/theme/patterns/figure-grid.css +0 -68
- package/template/packs/academic-paper/document/theme/patterns/table-utilities.css +0 -66
- package/template/packs/academic-paper/document/theme/shell/reader-controls.css +0 -761
- package/template/packs/academic-paper/document/theme/tokens.css +0 -80
- package/template/packs/academic-paper/openpress.config.mjs +0 -5
- package/template/packs/claude-document/document/chapters/01-document-shape/content/01-document-shape.mdx +0 -51
- package/template/packs/claude-document/document/chapters/02-review-loop/content/01-review-loop.mdx +0 -31
- package/template/packs/claude-document/document/components/ChapterOpenerVisual.tsx +0 -96
- package/template/packs/claude-document/document/components/Page.tsx +0 -37
- package/template/packs/claude-document/document/design.md +0 -142
- package/template/packs/claude-document/document/index.tsx +0 -94
- package/template/packs/claude-document/document/media/README.md +0 -13
- package/template/packs/claude-document/document/openpress.config.mjs +0 -26
- package/template/packs/claude-document/document/theme/README.md +0 -15
- package/template/packs/claude-document/document/theme/base/page-contract.css +0 -525
- package/template/packs/claude-document/document/theme/base/print.css +0 -93
- package/template/packs/claude-document/document/theme/base/typography.css +0 -612
- package/template/packs/claude-document/document/theme/fonts.css +0 -4
- package/template/packs/claude-document/document/theme/page-surfaces/back-cover.css +0 -72
- package/template/packs/claude-document/document/theme/page-surfaces/chapter-opener.css +0 -236
- package/template/packs/claude-document/document/theme/page-surfaces/cover.css +0 -309
- package/template/packs/claude-document/document/theme/page-surfaces/toc.css +0 -225
- package/template/packs/claude-document/document/theme/patterns/_chart-frame.css +0 -53
- package/template/packs/claude-document/document/theme/patterns/figure-grid.css +0 -68
- package/template/packs/claude-document/document/theme/patterns/table-utilities.css +0 -66
- package/template/packs/claude-document/document/theme/shell/reader-controls.css +0 -789
- package/template/packs/claude-document/document/theme/tokens.css +0 -89
- package/template/packs/claude-document/openpress.config.mjs +0 -5
- package/template/packs/editorial-monograph/document/chapters/01-product-and-use-cases/content/01-product-and-use-cases.mdx +0 -31
- package/template/packs/editorial-monograph/document/chapters/02-workflow/content/01-workflow.mdx +0 -89
- package/template/packs/editorial-monograph/document/chapters/03-agent-skills-contributors/content/01-agent-skills-contributors.mdx +0 -51
- package/template/packs/editorial-monograph/document/chapters/04-validation-deploy/content/01-validation-deploy.mdx +0 -39
- package/template/packs/editorial-monograph/document/components/ChapterOpenerVisual/index.tsx +0 -76
- package/template/packs/editorial-monograph/document/components/Page.tsx +0 -37
- package/template/packs/editorial-monograph/document/components/TokenSwatchGrid/index.tsx +0 -46
- package/template/packs/editorial-monograph/document/components/TokenSwatchGrid/style.css +0 -63
- package/template/packs/editorial-monograph/document/components/TypeSpecimen/index.tsx +0 -38
- package/template/packs/editorial-monograph/document/components/TypeSpecimen/style.css +0 -111
- package/template/packs/editorial-monograph/document/design.md +0 -279
- package/template/packs/editorial-monograph/document/index.tsx +0 -97
- package/template/packs/editorial-monograph/document/media/README.md +0 -13
- package/template/packs/editorial-monograph/document/openpress.config.mjs +0 -26
- package/template/packs/editorial-monograph/document/theme/README.md +0 -11
- package/template/packs/editorial-monograph/document/theme/base/page-contract.css +0 -505
- package/template/packs/editorial-monograph/document/theme/base/print.css +0 -93
- package/template/packs/editorial-monograph/document/theme/base/typography.css +0 -336
- package/template/packs/editorial-monograph/document/theme/fonts.css +0 -3
- package/template/packs/editorial-monograph/document/theme/page-surfaces/back-cover.css +0 -43
- package/template/packs/editorial-monograph/document/theme/page-surfaces/chapter-opener.css +0 -205
- package/template/packs/editorial-monograph/document/theme/page-surfaces/cover.css +0 -147
- package/template/packs/editorial-monograph/document/theme/page-surfaces/toc.css +0 -149
- package/template/packs/editorial-monograph/document/theme/patterns/_chart-frame.css +0 -49
- package/template/packs/editorial-monograph/document/theme/patterns/figure-grid.css +0 -68
- package/template/packs/editorial-monograph/document/theme/patterns/table-utilities.css +0 -66
- package/template/packs/editorial-monograph/document/theme/shell/reader-controls.css +0 -761
- package/template/packs/editorial-monograph/document/theme/tokens.css +0 -80
- package/template/packs/editorial-monograph/openpress.config.mjs +0 -5
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { loadReactDocumentEntry } from "../react/document-entry.mjs";
|
|
4
|
-
import { walkFiles } from "./file-walk.mjs";
|
|
5
|
-
import { resolveDocumentRelativePath, rootRelativePath } from "./path-utils.mjs";
|
|
6
|
-
|
|
7
|
-
export { rootRelativePath };
|
|
8
|
-
|
|
9
|
-
export const REACT_MDX_CONTENT_EXTENSIONS = new Set([".mdx"]);
|
|
10
|
-
|
|
11
|
-
export async function resolveActiveSourceWorkspace(config) {
|
|
12
|
-
const reactEntry = await loadReactDocumentEntry(config.root);
|
|
13
|
-
if (!reactEntry) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
"React/MDX document entry not found. Expected document/index.tsx with a Press default export before using workspace source tools.",
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
const contentRoots = contentRootsFromSources(reactEntry.sources, reactEntry.config);
|
|
19
|
-
const sourceDir = firstDirectoryRoot(contentRoots) ?? reactEntry.config.paths.documentRoot;
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
kind: "react-mdx",
|
|
23
|
-
checkedName: "react-source",
|
|
24
|
-
config: reactEntry.config,
|
|
25
|
-
entryPath: reactEntry.entryPath,
|
|
26
|
-
sourceDir,
|
|
27
|
-
contentRoots,
|
|
28
|
-
contentExtensions: REACT_MDX_CONTENT_EXTENSIONS,
|
|
29
|
-
contentLabel: "React MDX chapter source",
|
|
30
|
-
missingCode: "react-source.missing",
|
|
31
|
-
emptyCode: "react-source.empty",
|
|
32
|
-
missingMessage: "Registered React MDX sources do not exist yet; create the files or roots declared in document/index.tsx `sources` before running export.",
|
|
33
|
-
emptyMessage: "Registered React MDX sources contain no `*.mdx` files; the document will export with zero source blocks.",
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export async function collectActiveContentFiles(sourceWorkspace, { skipUnderscoreFiles = false } = {}) {
|
|
38
|
-
const files = [];
|
|
39
|
-
const seen = new Set();
|
|
40
|
-
for (const root of sourceWorkspace.contentRoots ?? [{ kind: "dir", absolutePath: sourceWorkspace.sourceDir }]) {
|
|
41
|
-
const visit = async (absolutePath) => {
|
|
42
|
-
if (seen.has(absolutePath)) return;
|
|
43
|
-
if (!sourceWorkspace.contentExtensions.has(path.extname(absolutePath))) return;
|
|
44
|
-
const name = path.basename(absolutePath);
|
|
45
|
-
if (skipUnderscoreFiles && name.startsWith("_")) return;
|
|
46
|
-
seen.add(absolutePath);
|
|
47
|
-
files.push({
|
|
48
|
-
absolutePath,
|
|
49
|
-
name,
|
|
50
|
-
relativePath: rootRelativePath(sourceWorkspace.config, absolutePath),
|
|
51
|
-
sourceRelativePath: path.relative(root.basePath ?? path.dirname(absolutePath), absolutePath).replaceAll("\\", "/"),
|
|
52
|
-
text: await fs.readFile(absolutePath, "utf8"),
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
if (root.kind === "file") {
|
|
56
|
-
try {
|
|
57
|
-
const stat = await fs.stat(root.absolutePath);
|
|
58
|
-
if (stat.isFile()) await visit(root.absolutePath);
|
|
59
|
-
} catch (error) {
|
|
60
|
-
if (error?.code !== "ENOENT") throw error;
|
|
61
|
-
}
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
await walkFiles(root.absolutePath, visit);
|
|
65
|
-
}
|
|
66
|
-
files.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
67
|
-
return files;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export async function sourceDirectoryExists(sourceWorkspace) {
|
|
71
|
-
const roots = sourceWorkspace.contentRoots ?? [{ kind: "dir", absolutePath: sourceWorkspace.sourceDir }];
|
|
72
|
-
for (const root of roots) {
|
|
73
|
-
try {
|
|
74
|
-
const stat = await fs.stat(root.absolutePath);
|
|
75
|
-
if (root.kind === "file" ? stat.isFile() : stat.isDirectory()) return true;
|
|
76
|
-
} catch (error) {
|
|
77
|
-
if (error?.code === "ENOENT") continue;
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function contentRootsFromSources(sources, config) {
|
|
85
|
-
const entries = Object.entries(sources ?? {});
|
|
86
|
-
if (entries.length === 0) {
|
|
87
|
-
return [{
|
|
88
|
-
kind: "dir",
|
|
89
|
-
absolutePath: config.paths.sourceDir,
|
|
90
|
-
basePath: config.paths.sourceDir,
|
|
91
|
-
sourceId: "default",
|
|
92
|
-
preset: "section-folders",
|
|
93
|
-
}];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const roots = [];
|
|
97
|
-
for (const [sourceId, descriptor] of entries) {
|
|
98
|
-
if (!descriptor || descriptor.type !== "mdx") continue;
|
|
99
|
-
if (descriptor.preset === "section-folders") {
|
|
100
|
-
roots.push(directoryRoot(config, descriptor.root ?? "chapters", sourceId, descriptor.preset));
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
if (descriptor.preset === "section-files") {
|
|
104
|
-
roots.push(directoryRoot(config, descriptor.root ?? "content", sourceId, descriptor.preset));
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
if (descriptor.preset === "file-list") {
|
|
108
|
-
for (const file of descriptor.files ?? []) {
|
|
109
|
-
roots.push(fileRoot(config, file, sourceId, descriptor.preset));
|
|
110
|
-
}
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return dedupeRoots(roots);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function directoryRoot(config, rel, sourceId, preset) {
|
|
118
|
-
const absolutePath = resolveDocumentRelativePath(config.paths.documentRoot, rel, `Source "${sourceId}" ${preset} root`);
|
|
119
|
-
return {
|
|
120
|
-
kind: "dir",
|
|
121
|
-
absolutePath,
|
|
122
|
-
basePath: absolutePath,
|
|
123
|
-
sourceId,
|
|
124
|
-
preset,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function fileRoot(config, rel, sourceId, preset) {
|
|
129
|
-
if (typeof rel !== "string" || !rel.trim()) {
|
|
130
|
-
throw new Error(`Source "${sourceId}" file-list contains an empty or invalid entry.`);
|
|
131
|
-
}
|
|
132
|
-
if (!rel.endsWith(".mdx")) {
|
|
133
|
-
throw new Error(`Source "${sourceId}" file-list path "${rel}" must end with .mdx.`);
|
|
134
|
-
}
|
|
135
|
-
const absolutePath = resolveDocumentRelativePath(config.paths.documentRoot, rel, `Source "${sourceId}" file-list path "${rel}"`);
|
|
136
|
-
return {
|
|
137
|
-
kind: "file",
|
|
138
|
-
absolutePath,
|
|
139
|
-
basePath: path.dirname(absolutePath),
|
|
140
|
-
sourceId,
|
|
141
|
-
preset,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function dedupeRoots(roots) {
|
|
146
|
-
const seen = new Set();
|
|
147
|
-
const out = [];
|
|
148
|
-
for (const root of roots) {
|
|
149
|
-
const key = `${root.kind}:${root.absolutePath}`;
|
|
150
|
-
if (seen.has(key)) continue;
|
|
151
|
-
seen.add(key);
|
|
152
|
-
out.push(root);
|
|
153
|
-
}
|
|
154
|
-
return out;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function firstDirectoryRoot(roots) {
|
|
158
|
-
return roots.find((root) => root.kind === "dir")?.absolutePath ?? null;
|
|
159
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { loadConfig } from "./config.mjs";
|
|
4
|
-
import { createIssue, createIssueReport } from "./issue-report.mjs";
|
|
5
|
-
import { collectSourceTextFiles } from "./source-text-tools.mjs";
|
|
6
|
-
import { collectActiveContentFiles, resolveActiveSourceWorkspace, sourceDirectoryExists } from "./source-workspace.mjs";
|
|
7
|
-
|
|
8
|
-
// Adapters that publish the document to a URL anyone on the internet can reach.
|
|
9
|
-
// `deploy.requiresConfirmation: true` is mandatory for these so an automated
|
|
10
|
-
// pipeline (or a careless command) cannot ship without an explicit human step.
|
|
11
|
-
// Adapters not in this set (local file copy, custom in-house tooling, null)
|
|
12
|
-
// can opt out of the confirmation gate.
|
|
13
|
-
const PUBLIC_DEPLOY_ADAPTERS = new Set([
|
|
14
|
-
"cloudflare-pages",
|
|
15
|
-
"github-pages",
|
|
16
|
-
"netlify",
|
|
17
|
-
"vercel",
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
export async function discoverWorkspace(startPath = ".") {
|
|
21
|
-
let current = path.resolve(startPath);
|
|
22
|
-
try {
|
|
23
|
-
const stat = await fs.stat(current);
|
|
24
|
-
if (!stat.isDirectory()) current = path.dirname(current);
|
|
25
|
-
} catch {
|
|
26
|
-
current = path.dirname(current);
|
|
27
|
-
}
|
|
28
|
-
while (true) {
|
|
29
|
-
const configPath = path.join(current, "openpress.config.mjs");
|
|
30
|
-
try {
|
|
31
|
-
await fs.access(configPath);
|
|
32
|
-
return current;
|
|
33
|
-
} catch {
|
|
34
|
-
const parent = path.dirname(current);
|
|
35
|
-
if (parent === current) throw new Error(`No OpenPress workspace found from ${startPath}`);
|
|
36
|
-
current = parent;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export async function validateWorkspace(root) {
|
|
42
|
-
const config = await loadConfig(root);
|
|
43
|
-
const sourceWorkspace = await resolveActiveSourceWorkspace(config);
|
|
44
|
-
const activeConfig = sourceWorkspace.config;
|
|
45
|
-
const issues = [];
|
|
46
|
-
const checked = [];
|
|
47
|
-
const mark = (name) => {
|
|
48
|
-
if (!checked.includes(name)) checked.push(name);
|
|
49
|
-
};
|
|
50
|
-
const add = (level, code, message, filePath = null, detail = undefined) => issues.push(createIssue({ level, code, message, path: filePath, detail }));
|
|
51
|
-
|
|
52
|
-
mark("config");
|
|
53
|
-
for (const [key, target] of [
|
|
54
|
-
["sourceDir", sourceWorkspace.sourceDir],
|
|
55
|
-
["mediaDir", activeConfig.paths.mediaDir],
|
|
56
|
-
["themeDir", activeConfig.paths.themeDir],
|
|
57
|
-
["designDoc", activeConfig.paths.designDoc],
|
|
58
|
-
["componentsDir", activeConfig.paths.componentsDir],
|
|
59
|
-
]) {
|
|
60
|
-
if (!(await exists(target))) add("error", `config.${key}`, `Configured OpenPress path \`${key}\` does not exist.`, target);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
mark("design-doc");
|
|
64
|
-
const designDoc = activeConfig.paths.designDoc;
|
|
65
|
-
if (!(await exists(designDoc))) {
|
|
66
|
-
add("error", "design-doc.missing", "Design document must exist.", designDoc);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
mark("deploy-gate");
|
|
70
|
-
if (PUBLIC_DEPLOY_ADAPTERS.has(config.deploy.adapter) && config.deploy.requiresConfirmation !== true) {
|
|
71
|
-
add(
|
|
72
|
-
"error",
|
|
73
|
-
"deploy.confirmation",
|
|
74
|
-
`Public deploy adapter \`${config.deploy.adapter}\` must require user confirmation (set deploy.requiresConfirmation: true).`,
|
|
75
|
-
config.configPath,
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
mark(sourceWorkspace.checkedName);
|
|
80
|
-
if (!(typeof activeConfig.title === "string" && activeConfig.title.trim())) {
|
|
81
|
-
add("warning", "config.title", "openpress.config.mjs `title` is empty; the workbench will show the default placeholder.", activeConfig.configPath);
|
|
82
|
-
}
|
|
83
|
-
if (!(await sourceDirectoryExists(sourceWorkspace))) {
|
|
84
|
-
add("warning", sourceWorkspace.missingCode, sourceWorkspace.missingMessage, sourceWorkspace.sourceDir);
|
|
85
|
-
} else {
|
|
86
|
-
const contentFiles = await collectActiveContentFiles(sourceWorkspace, { skipUnderscoreFiles: true });
|
|
87
|
-
if (contentFiles.length === 0) {
|
|
88
|
-
add("warning", sourceWorkspace.emptyCode, sourceWorkspace.emptyMessage, sourceWorkspace.sourceDir);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (sourceWorkspace.kind === "react-mdx") {
|
|
93
|
-
mark("react-comments");
|
|
94
|
-
const sourceFiles = await collectSourceTextFiles(activeConfig, { scope: "all" });
|
|
95
|
-
for (const file of sourceFiles) {
|
|
96
|
-
for (const marker of findCommentMarkers(file.text)) {
|
|
97
|
-
add(
|
|
98
|
-
"warning",
|
|
99
|
-
"react-comments.pending",
|
|
100
|
-
`Pending OpenPress comment \`${marker.id}\` remains in React source; run apply-comments or resolve it manually before publishing.`,
|
|
101
|
-
file.absolutePath,
|
|
102
|
-
{
|
|
103
|
-
id: marker.id,
|
|
104
|
-
line: marker.line,
|
|
105
|
-
path: file.path ?? file.relativePath,
|
|
106
|
-
},
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
mark("react-source");
|
|
113
|
-
const documentJsonPath = path.join(activeConfig.paths.publicDir, "document.json");
|
|
114
|
-
const exportedDocument = await readJsonIfExists(documentJsonPath);
|
|
115
|
-
const pressWarnings = exportedDocument?.source?.warnings;
|
|
116
|
-
if (Array.isArray(pressWarnings)) {
|
|
117
|
-
for (const warning of pressWarnings) {
|
|
118
|
-
const code = typeof warning?.code === "string" && warning.code ? warning.code : "warning";
|
|
119
|
-
add(
|
|
120
|
-
"warning",
|
|
121
|
-
`react-source.${code}`,
|
|
122
|
-
pressWarningMessage(warning),
|
|
123
|
-
documentJsonPath,
|
|
124
|
-
warning,
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return createIssueReport({
|
|
130
|
-
kind: "validation",
|
|
131
|
-
checked,
|
|
132
|
-
issues,
|
|
133
|
-
okMessage: "OpenPress validation OK",
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function findCommentMarkers(text) {
|
|
138
|
-
const markers = [];
|
|
139
|
-
const lines = String(text ?? "").split(/\r?\n/);
|
|
140
|
-
for (const [index, line] of lines.entries()) {
|
|
141
|
-
const match = line.match(/@openpress-comment\b[^}]*\bid="([^"]+)"/);
|
|
142
|
-
if (!match) continue;
|
|
143
|
-
markers.push({ id: match[1], line: index + 1 });
|
|
144
|
-
}
|
|
145
|
-
return markers;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function pressWarningMessage(warning) {
|
|
149
|
-
if (warning?.code === "chain-overflowed") {
|
|
150
|
-
return `Content chain \`${warning.chainId ?? "(unknown)"}\` overflowed during Press Tree allocation.`;
|
|
151
|
-
}
|
|
152
|
-
if (warning?.code === "chain-has-no-area") {
|
|
153
|
-
return `Content chain \`${warning.chainId ?? "(unknown)"}\` has blocks but no matching MdxArea.`;
|
|
154
|
-
}
|
|
155
|
-
return `Press Tree export warning: ${warning?.code ?? "warning"}.`;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async function readJsonIfExists(filePath) {
|
|
159
|
-
try {
|
|
160
|
-
return JSON.parse(await fs.readFile(filePath, "utf8"));
|
|
161
|
-
} catch (error) {
|
|
162
|
-
if (error?.code === "ENOENT") return null;
|
|
163
|
-
throw error;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async function exists(filePath) {
|
|
168
|
-
try {
|
|
169
|
-
await fs.access(filePath);
|
|
170
|
-
return true;
|
|
171
|
-
} catch {
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
}
|
package/template/core/index.html
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="zh-Hant">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
|
|
7
|
-
<title>OpenPress Workspace</title>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div id="root"></div>
|
|
11
|
-
<script type="module" src="/src/main.tsx"></script>
|
|
12
|
-
</body>
|
|
13
|
-
</html>
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// Root pointer. The real workspace config lives at document/openpress.config.mjs.
|
|
2
|
-
//
|
|
3
|
-
// document/ is git-ignored in this framework checkout. Populate it locally
|
|
4
|
-
// from a style pack's React/MDX document starter:
|
|
5
|
-
// cp -R skills/editorial-monograph/starter/document/. document/
|
|
6
|
-
// Or create a separate workspace:
|
|
7
|
-
// node engine/cli.mjs init ../my-openpress-document
|
|
8
|
-
|
|
9
|
-
export default {
|
|
10
|
-
documentDir: "document",
|
|
11
|
-
config: "document/openpress.config.mjs",
|
|
12
|
-
};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@open-press/core",
|
|
3
|
-
"version": "0.8.0",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "open-press core — runtime primitives, CLI, and render pipeline for AI-first fixed-layout documents.",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"author": "quan0715",
|
|
8
|
-
"homepage": "https://github.com/quan0715/open-press#readme",
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/quan0715/open-press.git",
|
|
12
|
-
"directory": "packages/core"
|
|
13
|
-
},
|
|
14
|
-
"bugs": {
|
|
15
|
-
"url": "https://github.com/quan0715/open-press/issues"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"document",
|
|
19
|
-
"mdx",
|
|
20
|
-
"react",
|
|
21
|
-
"pdf",
|
|
22
|
-
"a4",
|
|
23
|
-
"fixed-layout",
|
|
24
|
-
"ai-first"
|
|
25
|
-
],
|
|
26
|
-
"main": "./src/openpress/core/index.tsx",
|
|
27
|
-
"types": "./src/openpress/core/index.tsx",
|
|
28
|
-
"exports": {
|
|
29
|
-
".": "./src/openpress/core/index.tsx",
|
|
30
|
-
"./mdx": "./src/openpress/mdx/index.ts",
|
|
31
|
-
"./manuscript": "./src/openpress/manuscript/index.tsx",
|
|
32
|
-
"./numbering": "./src/openpress/numbering/index.ts"
|
|
33
|
-
},
|
|
34
|
-
"bin": {
|
|
35
|
-
"open-press": "engine/cli.mjs"
|
|
36
|
-
},
|
|
37
|
-
"files": [
|
|
38
|
-
"engine",
|
|
39
|
-
"src/openpress",
|
|
40
|
-
"src/styles",
|
|
41
|
-
"index.html",
|
|
42
|
-
"vite.config.ts",
|
|
43
|
-
"tsconfig.json"
|
|
44
|
-
],
|
|
45
|
-
"publishConfig": {
|
|
46
|
-
"access": "public"
|
|
47
|
-
},
|
|
48
|
-
"scripts": {
|
|
49
|
-
"dev": "node engine/cli.mjs dev . --renderer react",
|
|
50
|
-
"build": "node engine/cli.mjs render . --renderer react",
|
|
51
|
-
"preview": "node engine/cli.mjs preview . --renderer react",
|
|
52
|
-
"typecheck": "node engine/cli.mjs typecheck .",
|
|
53
|
-
"test": "pnpm run test:node && pnpm run test:react",
|
|
54
|
-
"test:e2e:reader": "playwright test --config playwright.reader.config.ts",
|
|
55
|
-
"test:node": "node --test tests/*.test.mjs",
|
|
56
|
-
"test:react": "vitest run",
|
|
57
|
-
"openpress:validate": "node engine/cli.mjs validate .",
|
|
58
|
-
"openpress:export": "node engine/cli.mjs export .",
|
|
59
|
-
"openpress:pdf": "node engine/cli.mjs pdf .",
|
|
60
|
-
"openpress:render": "node engine/cli.mjs render . --renderer react",
|
|
61
|
-
"openpress:preview": "node engine/cli.mjs preview . --renderer react",
|
|
62
|
-
"openpress:deploy": "node engine/cli.mjs deploy .",
|
|
63
|
-
"openpress:deploy:dry-run": "node engine/cli.mjs deploy . --confirm --dry-run"
|
|
64
|
-
},
|
|
65
|
-
"dependencies": {
|
|
66
|
-
"@mdx-js/mdx": "^3.1.1",
|
|
67
|
-
"@mdx-js/react": "^3.1.1",
|
|
68
|
-
"js-yaml": "^4.1.1",
|
|
69
|
-
"katex": "^0.16.47",
|
|
70
|
-
"lucide-react": "^1.16.0",
|
|
71
|
-
"playwright": "^1.60.0",
|
|
72
|
-
"postcss": "^8.5.6",
|
|
73
|
-
"react": "^19.2.6",
|
|
74
|
-
"react-dom": "^19.2.6",
|
|
75
|
-
"rehype-katex": "^7.0.1",
|
|
76
|
-
"remark-gfm": "^4.0.1",
|
|
77
|
-
"remark-math": "^6.0.0"
|
|
78
|
-
},
|
|
79
|
-
"devDependencies": {
|
|
80
|
-
"@playwright/test": "^1.60.0",
|
|
81
|
-
"@testing-library/react": "^16.3.2",
|
|
82
|
-
"@types/node": "^25.8.0",
|
|
83
|
-
"@types/react": "^19.2.14",
|
|
84
|
-
"@types/react-dom": "^19.2.3",
|
|
85
|
-
"@vitejs/plugin-react": "^6.0.2",
|
|
86
|
-
"jsdom": "^26.1.0",
|
|
87
|
-
"typescript": "^6.0.3",
|
|
88
|
-
"vite": "^8.0.13",
|
|
89
|
-
"vitest": "^4.1.6"
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { StrictMode } from "react";
|
|
2
|
-
import { createRoot } from "react-dom/client";
|
|
3
|
-
import { OpenPressApp } from "./openpress/app";
|
|
4
|
-
import "./styles/openpress.css";
|
|
5
|
-
|
|
6
|
-
const rootElement = document.getElementById("root");
|
|
7
|
-
|
|
8
|
-
if (!rootElement) {
|
|
9
|
-
throw new Error("OpenPress renderer requires a #root element.");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
createRoot(rootElement).render(
|
|
13
|
-
<StrictMode>
|
|
14
|
-
<OpenPressApp />
|
|
15
|
-
</StrictMode>,
|
|
16
|
-
);
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from "react";
|
|
2
|
-
import { OpenPressRuntime } from "./OpenPressRuntime";
|
|
3
|
-
import { isLocalWorkspaceHost } from "../shared";
|
|
4
|
-
import type { DeploymentInfo, ReaderDocument } from "../document-model";
|
|
5
|
-
|
|
6
|
-
type LoadState =
|
|
7
|
-
| { status: "loading" }
|
|
8
|
-
| {
|
|
9
|
-
status: "ready";
|
|
10
|
-
document: ReaderDocument;
|
|
11
|
-
deploymentInfo: DeploymentInfo;
|
|
12
|
-
}
|
|
13
|
-
| { status: "error"; message: string };
|
|
14
|
-
|
|
15
|
-
interface DeployConfig {
|
|
16
|
-
pdf?: string;
|
|
17
|
-
deployed_at?: string;
|
|
18
|
-
public_url?: string;
|
|
19
|
-
dirty?: boolean;
|
|
20
|
-
deploy_configured?: boolean;
|
|
21
|
-
deploy_adapter?: string;
|
|
22
|
-
deploy_source?: string;
|
|
23
|
-
deploy_project_name?: string | null;
|
|
24
|
-
deploy_setup_message?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const offlineDeploymentInfo: DeploymentInfo = { online: false };
|
|
28
|
-
|
|
29
|
-
function LoadingScreen() {
|
|
30
|
-
return (
|
|
31
|
-
<div className="openpress-loading-screen" aria-label="載入中" role="status">
|
|
32
|
-
<div className="openpress-loading-screen__inner">
|
|
33
|
-
<div className="openpress-loading-dots" aria-hidden="true">
|
|
34
|
-
<span /><span /><span />
|
|
35
|
-
</div>
|
|
36
|
-
<span className="openpress-loading-screen__label">載入文件</span>
|
|
37
|
-
</div>
|
|
38
|
-
</div>
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function OpenPressApp() {
|
|
43
|
-
const [state, setState] = useState<LoadState>({ status: "loading" });
|
|
44
|
-
|
|
45
|
-
const refreshDocument = useCallback(async () => {
|
|
46
|
-
const document = await loadReaderDocument();
|
|
47
|
-
setState((current) => {
|
|
48
|
-
if (current.status !== "ready") return current;
|
|
49
|
-
return { ...current, document };
|
|
50
|
-
});
|
|
51
|
-
}, []);
|
|
52
|
-
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
let cancelled = false;
|
|
55
|
-
|
|
56
|
-
async function loadDocument() {
|
|
57
|
-
try {
|
|
58
|
-
const [document, deploymentInfo] = await Promise.all([
|
|
59
|
-
loadReaderDocument(),
|
|
60
|
-
loadDeploymentInfo(),
|
|
61
|
-
]);
|
|
62
|
-
if (!cancelled) {
|
|
63
|
-
setState({ status: "ready", document, deploymentInfo });
|
|
64
|
-
}
|
|
65
|
-
} catch (error) {
|
|
66
|
-
if (!cancelled) {
|
|
67
|
-
setState({
|
|
68
|
-
status: "error",
|
|
69
|
-
message: error instanceof Error ? error.message : "Unable to load OpenPress document.",
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
void loadDocument();
|
|
76
|
-
return () => {
|
|
77
|
-
cancelled = true;
|
|
78
|
-
};
|
|
79
|
-
}, []);
|
|
80
|
-
|
|
81
|
-
if (state.status === "loading") return <LoadingScreen />;
|
|
82
|
-
|
|
83
|
-
if (state.status === "error") {
|
|
84
|
-
return <div className="openpress-load-state openpress-load-state--error">{state.message}</div>;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<OpenPressRuntime
|
|
89
|
-
document={state.document}
|
|
90
|
-
deploymentInfo={state.deploymentInfo}
|
|
91
|
-
onDocumentRefresh={refreshDocument}
|
|
92
|
-
/>
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async function loadReaderDocument(): Promise<ReaderDocument> {
|
|
97
|
-
const response = await fetch("/openpress/document.json", { cache: "no-store" });
|
|
98
|
-
if (!response.ok) {
|
|
99
|
-
throw new Error(`Unable to load /openpress/document.json (${response.status})`);
|
|
100
|
-
}
|
|
101
|
-
return (await response.json()) as ReaderDocument;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async function loadDeploymentInfo(): Promise<DeploymentInfo> {
|
|
105
|
-
if (typeof window !== "undefined" && isLocalWorkspaceHost(window.location.hostname)) {
|
|
106
|
-
const localInfo = await loadDeploymentInfoFrom("/__openpress/status");
|
|
107
|
-
if (localInfo) return localInfo;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return (await loadDeploymentInfoFrom("/openpress/deploy.json")) ?? offlineDeploymentInfo;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async function loadDeploymentInfoFrom(path: string): Promise<DeploymentInfo | null> {
|
|
114
|
-
try {
|
|
115
|
-
const response = await fetch(path, { cache: "no-store" });
|
|
116
|
-
if (!response.ok) {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
const config = (await response.json()) as DeployConfig;
|
|
120
|
-
return deploymentConfigToInfo(config);
|
|
121
|
-
} catch {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function deploymentConfigToInfo(config: DeployConfig): DeploymentInfo {
|
|
127
|
-
const configured = config.deploy_configured !== false;
|
|
128
|
-
return {
|
|
129
|
-
online: configured && Boolean(config.deployed_at || config.public_url),
|
|
130
|
-
deployedAt: config.deployed_at,
|
|
131
|
-
pdf: typeof config.pdf === "string" ? config.pdf : undefined,
|
|
132
|
-
publicUrl: typeof config.public_url === "string" ? config.public_url : undefined,
|
|
133
|
-
dirty: config.dirty === true,
|
|
134
|
-
configured,
|
|
135
|
-
adapter: typeof config.deploy_adapter === "string" ? config.deploy_adapter : undefined,
|
|
136
|
-
source: typeof config.deploy_source === "string" ? config.deploy_source : undefined,
|
|
137
|
-
projectName: typeof config.deploy_project_name === "string" ? config.deploy_project_name : undefined,
|
|
138
|
-
setupMessage: typeof config.deploy_setup_message === "string" ? config.deploy_setup_message : undefined,
|
|
139
|
-
};
|
|
140
|
-
}
|