@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.
Files changed (250) hide show
  1. package/README.md +33 -23
  2. package/dist/cli.js +320 -252
  3. package/package.json +9 -8
  4. package/template/core/AGENTS.md +0 -126
  5. package/template/core/CHANGELOG.md +0 -215
  6. package/template/core/README.md +0 -40
  7. package/template/core/engine/cli.mjs +0 -96
  8. package/template/core/engine/commands/_shared.mjs +0 -177
  9. package/template/core/engine/commands/deploy.mjs +0 -31
  10. package/template/core/engine/commands/dev.mjs +0 -49
  11. package/template/core/engine/commands/doctor.mjs +0 -229
  12. package/template/core/engine/commands/export.mjs +0 -8
  13. package/template/core/engine/commands/init.mjs +0 -24
  14. package/template/core/engine/commands/inspect.mjs +0 -35
  15. package/template/core/engine/commands/pdf.mjs +0 -26
  16. package/template/core/engine/commands/preview.mjs +0 -26
  17. package/template/core/engine/commands/render.mjs +0 -17
  18. package/template/core/engine/commands/replace.mjs +0 -41
  19. package/template/core/engine/commands/search.mjs +0 -33
  20. package/template/core/engine/commands/typecheck.mjs +0 -5
  21. package/template/core/engine/commands/upgrade.mjs +0 -159
  22. package/template/core/engine/commands/validate.mjs +0 -17
  23. package/template/core/engine/document-export.mjs +0 -15
  24. package/template/core/engine/init.mjs +0 -90
  25. package/template/core/engine/output/chrome-pdf.d.mts +0 -34
  26. package/template/core/engine/output/chrome-pdf.mjs +0 -358
  27. package/template/core/engine/output/deploy-sync.mjs +0 -15
  28. package/template/core/engine/output/fonts.mjs +0 -62
  29. package/template/core/engine/output/katex-assets.mjs +0 -45
  30. package/template/core/engine/output/page-block.mjs +0 -30
  31. package/template/core/engine/output/pdf-media.mjs +0 -45
  32. package/template/core/engine/output/public-assets.mjs +0 -19
  33. package/template/core/engine/output/static-server.mjs +0 -532
  34. package/template/core/engine/react/caption-numbering.mjs +0 -73
  35. package/template/core/engine/react/comment-endpoint.d.mts +0 -11
  36. package/template/core/engine/react/comment-endpoint.mjs +0 -102
  37. package/template/core/engine/react/comment-marker.mjs +0 -374
  38. package/template/core/engine/react/document-entry.mjs +0 -324
  39. package/template/core/engine/react/document-export.mjs +0 -373
  40. package/template/core/engine/react/http-json.mjs +0 -24
  41. package/template/core/engine/react/mdx-compile.mjs +0 -599
  42. package/template/core/engine/react/measurement-css.mjs +0 -136
  43. package/template/core/engine/react/object-entities.mjs +0 -119
  44. package/template/core/engine/react/pagination/allocator.mjs +0 -122
  45. package/template/core/engine/react/pagination/regions.mjs +0 -81
  46. package/template/core/engine/react/pagination-constants.mjs +0 -3
  47. package/template/core/engine/react/pagination.mjs +0 -9
  48. package/template/core/engine/react/pipeline/allocate.mjs +0 -251
  49. package/template/core/engine/react/pipeline/final-render.mjs +0 -94
  50. package/template/core/engine/react/pipeline/frame-measurement.mjs +0 -302
  51. package/template/core/engine/react/pipeline/press-tree.mjs +0 -135
  52. package/template/core/engine/react/project-asset-endpoint.d.mts +0 -10
  53. package/template/core/engine/react/project-asset-endpoint.mjs +0 -361
  54. package/template/core/engine/react/section-css.mjs +0 -56
  55. package/template/core/engine/react/source-edit-endpoint.d.mts +0 -10
  56. package/template/core/engine/react/source-edit-endpoint.mjs +0 -75
  57. package/template/core/engine/react/sources/heading-numbering.mjs +0 -132
  58. package/template/core/engine/react/sources/mdx-resolver.mjs +0 -439
  59. package/template/core/engine/react/style-discovery.mjs +0 -142
  60. package/template/core/engine/runtime/config.d.mts +0 -40
  61. package/template/core/engine/runtime/config.mjs +0 -175
  62. package/template/core/engine/runtime/file-utils.mjs +0 -106
  63. package/template/core/engine/runtime/file-walk.mjs +0 -22
  64. package/template/core/engine/runtime/inspection.mjs +0 -328
  65. package/template/core/engine/runtime/issue-report.mjs +0 -44
  66. package/template/core/engine/runtime/path-utils.mjs +0 -20
  67. package/template/core/engine/runtime/source-text-tools.d.mts +0 -102
  68. package/template/core/engine/runtime/source-text-tools.mjs +0 -832
  69. package/template/core/engine/runtime/source-workspace.mjs +0 -159
  70. package/template/core/engine/runtime/validation.mjs +0 -174
  71. package/template/core/index.html +0 -13
  72. package/template/core/openpress.config.mjs +0 -12
  73. package/template/core/package.json +0 -91
  74. package/template/core/src/main.tsx +0 -16
  75. package/template/core/src/openpress/app/OpenPressApp.tsx +0 -140
  76. package/template/core/src/openpress/app/OpenPressRuntime.tsx +0 -94
  77. package/template/core/src/openpress/app/index.ts +0 -2
  78. package/template/core/src/openpress/core/Frame.tsx +0 -78
  79. package/template/core/src/openpress/core/FrameContext.tsx +0 -24
  80. package/template/core/src/openpress/core/MdxArea.tsx +0 -34
  81. package/template/core/src/openpress/core/Press.tsx +0 -34
  82. package/template/core/src/openpress/core/cn.ts +0 -4
  83. package/template/core/src/openpress/core/index.tsx +0 -40
  84. package/template/core/src/openpress/core/primitives.tsx +0 -44
  85. package/template/core/src/openpress/core/types.ts +0 -191
  86. package/template/core/src/openpress/core/useSource.ts +0 -28
  87. package/template/core/src/openpress/document-model/anchorMapModel.ts +0 -27
  88. package/template/core/src/openpress/document-model/documentIndexes.ts +0 -329
  89. package/template/core/src/openpress/document-model/documentTypes.ts +0 -138
  90. package/template/core/src/openpress/document-model/index.ts +0 -6
  91. package/template/core/src/openpress/document-model/objectEntityModel.ts +0 -51
  92. package/template/core/src/openpress/document-model/projectIdentityModel.ts +0 -15
  93. package/template/core/src/openpress/document-model/reactDocumentMetadataModel.ts +0 -27
  94. package/template/core/src/openpress/manuscript/index.tsx +0 -238
  95. package/template/core/src/openpress/mdx/index.ts +0 -88
  96. package/template/core/src/openpress/numbering/index.ts +0 -294
  97. package/template/core/src/openpress/reader/PublicReaderPage.tsx +0 -267
  98. package/template/core/src/openpress/reader/ReaderNavigationPanel.tsx +0 -123
  99. package/template/core/src/openpress/reader/index.ts +0 -10
  100. package/template/core/src/openpress/reader/pageViewportScaleModel.ts +0 -73
  101. package/template/core/src/openpress/reader/readerPageRegistry.ts +0 -41
  102. package/template/core/src/openpress/reader/readerPageRoute.ts +0 -21
  103. package/template/core/src/openpress/reader/readerScroll.ts +0 -92
  104. package/template/core/src/openpress/reader/readerStateModel.ts +0 -15
  105. package/template/core/src/openpress/reader/readerTypes.ts +0 -4
  106. package/template/core/src/openpress/reader/usePageViewportScale.ts +0 -119
  107. package/template/core/src/openpress/reader/usePanelState.ts +0 -56
  108. package/template/core/src/openpress/reader/useReaderHashSync.ts +0 -61
  109. package/template/core/src/openpress/reader/useReaderKeyboardNav.ts +0 -48
  110. package/template/core/src/openpress/reader/useReaderRuntime.ts +0 -146
  111. package/template/core/src/openpress/reader/useReaderScrollAnchor.ts +0 -64
  112. package/template/core/src/openpress/shared/Panel.tsx +0 -77
  113. package/template/core/src/openpress/shared/frameScheduler.ts +0 -32
  114. package/template/core/src/openpress/shared/index.ts +0 -4
  115. package/template/core/src/openpress/shared/numberUtils.ts +0 -3
  116. package/template/core/src/openpress/shared/runtimeMode.ts +0 -11
  117. package/template/core/src/openpress/workbench/Workbench.tsx +0 -407
  118. package/template/core/src/openpress/workbench/actions/DeploymentControl.tsx +0 -157
  119. package/template/core/src/openpress/workbench/actions/PageZoomControl.tsx +0 -182
  120. package/template/core/src/openpress/workbench/actions/SearchControl.tsx +0 -345
  121. package/template/core/src/openpress/workbench/actions/deploymentStatusModel.ts +0 -112
  122. package/template/core/src/openpress/workbench/actions/index.ts +0 -5
  123. package/template/core/src/openpress/workbench/actions/useDeploymentWorkbench.ts +0 -136
  124. package/template/core/src/openpress/workbench/dialog/WorkbenchDialog.tsx +0 -72
  125. package/template/core/src/openpress/workbench/dialog/index.ts +0 -1
  126. package/template/core/src/openpress/workbench/document/components/DocumentPanel.tsx +0 -127
  127. package/template/core/src/openpress/workbench/document/components/InlineSourceEditorLayer.tsx +0 -207
  128. package/template/core/src/openpress/workbench/document/components/ReaderStage.tsx +0 -9
  129. package/template/core/src/openpress/workbench/document/hooks/useDocumentWorkbenchModel.ts +0 -34
  130. package/template/core/src/openpress/workbench/document/hooks/useInlineDocumentEditor.ts +0 -525
  131. package/template/core/src/openpress/workbench/document/index.ts +0 -10
  132. package/template/core/src/openpress/workbench/index.ts +0 -2
  133. package/template/core/src/openpress/workbench/inspector/InlineInspectorLayer.tsx +0 -459
  134. package/template/core/src/openpress/workbench/inspector/index.ts +0 -5
  135. package/template/core/src/openpress/workbench/inspector/inlineCommentModel.ts +0 -125
  136. package/template/core/src/openpress/workbench/inspector/inspectorGeometryModel.ts +0 -160
  137. package/template/core/src/openpress/workbench/inspector/inspectorModel.ts +0 -408
  138. package/template/core/src/openpress/workbench/inspector/useInspectorComments.ts +0 -248
  139. package/template/core/src/openpress/workbench/mentions/MentionSuggestionList.tsx +0 -41
  140. package/template/core/src/openpress/workbench/mentions/index.ts +0 -2
  141. package/template/core/src/openpress/workbench/mentions/useComposerMentions.ts +0 -185
  142. package/template/core/src/openpress/workbench/panels/Panel.tsx +0 -1
  143. package/template/core/src/openpress/workbench/panels/PendingCommentsPanel.tsx +0 -76
  144. package/template/core/src/openpress/workbench/panels/WorkbenchControlPanel.tsx +0 -29
  145. package/template/core/src/openpress/workbench/panels/index.ts +0 -3
  146. package/template/core/src/openpress/workbench/project/ProjectEntryPanel.tsx +0 -523
  147. package/template/core/src/openpress/workbench/project/ProjectPreviewDialog.tsx +0 -35
  148. package/template/core/src/openpress/workbench/project/index.ts +0 -2
  149. package/template/core/src/openpress/workbench/project/projectPreviewTypes.ts +0 -11
  150. package/template/core/src/openpress/workbench/project/projectSourceModel.ts +0 -24
  151. package/template/core/src/openpress/workbench/shell/WorkbenchShell.tsx +0 -167
  152. package/template/core/src/openpress/workbench/shell/index.ts +0 -1
  153. package/template/core/src/openpress/workbench/workbenchFormatters.ts +0 -120
  154. package/template/core/src/openpress/workbench/workbenchTypes.ts +0 -35
  155. package/template/core/src/styles/openpress/app-shell.css +0 -251
  156. package/template/core/src/styles/openpress/media-workspace.css +0 -230
  157. package/template/core/src/styles/openpress/print-route.css +0 -184
  158. package/template/core/src/styles/openpress/project-preview-panel.css +0 -924
  159. package/template/core/src/styles/openpress/public-viewer.css +0 -688
  160. package/template/core/src/styles/openpress/reader-runtime.css +0 -980
  161. package/template/core/src/styles/openpress/responsive.css +0 -245
  162. package/template/core/src/styles/openpress/workbench-panels.css +0 -594
  163. package/template/core/src/styles/openpress/workbench.css +0 -1255
  164. package/template/core/src/styles/openpress.css +0 -14
  165. package/template/core/src/vite-env.d.ts +0 -9
  166. package/template/core/tsconfig.json +0 -40
  167. package/template/core/vite.config.ts +0 -584
  168. package/template/packs/academic-paper/document/chapters/01-introduction/content/01-introduction.mdx +0 -35
  169. package/template/packs/academic-paper/document/chapters/02-methods/content/01-methods.mdx +0 -50
  170. package/template/packs/academic-paper/document/chapters/03-results-and-discussion/content/01-results.mdx +0 -47
  171. package/template/packs/academic-paper/document/chapters/04-acknowledgment/content/01-acknowledgment.mdx +0 -26
  172. package/template/packs/academic-paper/document/chapters/05-references/content/01-references.mdx +0 -32
  173. package/template/packs/academic-paper/document/components/ChapterOpenerVisual/index.tsx +0 -76
  174. package/template/packs/academic-paper/document/components/Page.tsx +0 -60
  175. package/template/packs/academic-paper/document/components/TokenSwatchGrid/index.tsx +0 -46
  176. package/template/packs/academic-paper/document/components/TokenSwatchGrid/style.css +0 -63
  177. package/template/packs/academic-paper/document/components/TypeSpecimen/index.tsx +0 -38
  178. package/template/packs/academic-paper/document/components/TypeSpecimen/style.css +0 -111
  179. package/template/packs/academic-paper/document/design.md +0 -279
  180. package/template/packs/academic-paper/document/index.tsx +0 -123
  181. package/template/packs/academic-paper/document/media/README.md +0 -13
  182. package/template/packs/academic-paper/document/media/figure-placeholder.svg +0 -9
  183. package/template/packs/academic-paper/document/openpress.config.mjs +0 -26
  184. package/template/packs/academic-paper/document/theme/README.md +0 -11
  185. package/template/packs/academic-paper/document/theme/base/page-contract.css +0 -522
  186. package/template/packs/academic-paper/document/theme/base/print.css +0 -93
  187. package/template/packs/academic-paper/document/theme/base/typography.css +0 -333
  188. package/template/packs/academic-paper/document/theme/fonts.css +0 -3
  189. package/template/packs/academic-paper/document/theme/page-surfaces/back-cover.css +0 -43
  190. package/template/packs/academic-paper/document/theme/page-surfaces/chapter-opener.css +0 -205
  191. package/template/packs/academic-paper/document/theme/page-surfaces/cover.css +0 -294
  192. package/template/packs/academic-paper/document/theme/page-surfaces/toc.css +0 -149
  193. package/template/packs/academic-paper/document/theme/patterns/_chart-frame.css +0 -49
  194. package/template/packs/academic-paper/document/theme/patterns/figure-grid.css +0 -68
  195. package/template/packs/academic-paper/document/theme/patterns/table-utilities.css +0 -66
  196. package/template/packs/academic-paper/document/theme/shell/reader-controls.css +0 -761
  197. package/template/packs/academic-paper/document/theme/tokens.css +0 -80
  198. package/template/packs/academic-paper/openpress.config.mjs +0 -5
  199. package/template/packs/claude-document/document/chapters/01-document-shape/content/01-document-shape.mdx +0 -51
  200. package/template/packs/claude-document/document/chapters/02-review-loop/content/01-review-loop.mdx +0 -31
  201. package/template/packs/claude-document/document/components/ChapterOpenerVisual.tsx +0 -96
  202. package/template/packs/claude-document/document/components/Page.tsx +0 -37
  203. package/template/packs/claude-document/document/design.md +0 -142
  204. package/template/packs/claude-document/document/index.tsx +0 -94
  205. package/template/packs/claude-document/document/media/README.md +0 -13
  206. package/template/packs/claude-document/document/openpress.config.mjs +0 -26
  207. package/template/packs/claude-document/document/theme/README.md +0 -15
  208. package/template/packs/claude-document/document/theme/base/page-contract.css +0 -525
  209. package/template/packs/claude-document/document/theme/base/print.css +0 -93
  210. package/template/packs/claude-document/document/theme/base/typography.css +0 -612
  211. package/template/packs/claude-document/document/theme/fonts.css +0 -4
  212. package/template/packs/claude-document/document/theme/page-surfaces/back-cover.css +0 -72
  213. package/template/packs/claude-document/document/theme/page-surfaces/chapter-opener.css +0 -236
  214. package/template/packs/claude-document/document/theme/page-surfaces/cover.css +0 -309
  215. package/template/packs/claude-document/document/theme/page-surfaces/toc.css +0 -225
  216. package/template/packs/claude-document/document/theme/patterns/_chart-frame.css +0 -53
  217. package/template/packs/claude-document/document/theme/patterns/figure-grid.css +0 -68
  218. package/template/packs/claude-document/document/theme/patterns/table-utilities.css +0 -66
  219. package/template/packs/claude-document/document/theme/shell/reader-controls.css +0 -789
  220. package/template/packs/claude-document/document/theme/tokens.css +0 -89
  221. package/template/packs/claude-document/openpress.config.mjs +0 -5
  222. package/template/packs/editorial-monograph/document/chapters/01-product-and-use-cases/content/01-product-and-use-cases.mdx +0 -31
  223. package/template/packs/editorial-monograph/document/chapters/02-workflow/content/01-workflow.mdx +0 -89
  224. package/template/packs/editorial-monograph/document/chapters/03-agent-skills-contributors/content/01-agent-skills-contributors.mdx +0 -51
  225. package/template/packs/editorial-monograph/document/chapters/04-validation-deploy/content/01-validation-deploy.mdx +0 -39
  226. package/template/packs/editorial-monograph/document/components/ChapterOpenerVisual/index.tsx +0 -76
  227. package/template/packs/editorial-monograph/document/components/Page.tsx +0 -37
  228. package/template/packs/editorial-monograph/document/components/TokenSwatchGrid/index.tsx +0 -46
  229. package/template/packs/editorial-monograph/document/components/TokenSwatchGrid/style.css +0 -63
  230. package/template/packs/editorial-monograph/document/components/TypeSpecimen/index.tsx +0 -38
  231. package/template/packs/editorial-monograph/document/components/TypeSpecimen/style.css +0 -111
  232. package/template/packs/editorial-monograph/document/design.md +0 -279
  233. package/template/packs/editorial-monograph/document/index.tsx +0 -97
  234. package/template/packs/editorial-monograph/document/media/README.md +0 -13
  235. package/template/packs/editorial-monograph/document/openpress.config.mjs +0 -26
  236. package/template/packs/editorial-monograph/document/theme/README.md +0 -11
  237. package/template/packs/editorial-monograph/document/theme/base/page-contract.css +0 -505
  238. package/template/packs/editorial-monograph/document/theme/base/print.css +0 -93
  239. package/template/packs/editorial-monograph/document/theme/base/typography.css +0 -336
  240. package/template/packs/editorial-monograph/document/theme/fonts.css +0 -3
  241. package/template/packs/editorial-monograph/document/theme/page-surfaces/back-cover.css +0 -43
  242. package/template/packs/editorial-monograph/document/theme/page-surfaces/chapter-opener.css +0 -205
  243. package/template/packs/editorial-monograph/document/theme/page-surfaces/cover.css +0 -147
  244. package/template/packs/editorial-monograph/document/theme/page-surfaces/toc.css +0 -149
  245. package/template/packs/editorial-monograph/document/theme/patterns/_chart-frame.css +0 -49
  246. package/template/packs/editorial-monograph/document/theme/patterns/figure-grid.css +0 -68
  247. package/template/packs/editorial-monograph/document/theme/patterns/table-utilities.css +0 -66
  248. package/template/packs/editorial-monograph/document/theme/shell/reader-controls.css +0 -761
  249. package/template/packs/editorial-monograph/document/theme/tokens.css +0 -80
  250. package/template/packs/editorial-monograph/openpress.config.mjs +0 -5
@@ -1,136 +0,0 @@
1
- import { useCallback, useMemo, useState } from "react";
2
- import { isLocalWorkspaceHost } from "../../shared";
3
- import type { DeploymentInfo } from "../../document-model";
4
- import type { DeployStatus, PdfActionStatus } from "../workbenchTypes";
5
- import { parseDeployError, workbenchPdfButtonText, workbenchPdfStatusMessage } from "./deploymentStatusModel";
6
-
7
- export interface UseDeploymentWorkbenchOptions {
8
- deploymentInfo: DeploymentInfo;
9
- }
10
-
11
- export interface DeploymentWorkbench {
12
- status: DeployStatus;
13
- pdfActionStatus: PdfActionStatus;
14
- currentDeploymentInfo: DeploymentInfo;
15
- staticPdfHref: string | undefined;
16
- localDeployEnabled: boolean;
17
- pdfButtonText: string;
18
- pdfButtonDisabled: boolean;
19
- pdfStatusMessage: string | null;
20
- pdfToolbarExpanded: boolean;
21
- handleDeploy: () => Promise<void>;
22
- handleOpenWorkbenchPdf: () => void;
23
- }
24
-
25
- export function useDeploymentWorkbench({ deploymentInfo }: UseDeploymentWorkbenchOptions): DeploymentWorkbench {
26
- const [status, setStatus] = useState<DeployStatus>("idle");
27
- const [pdfActionStatus, setPdfActionStatus] = useState<PdfActionStatus>("idle");
28
- const [currentDeploymentInfo, setCurrentDeploymentInfo] = useState(deploymentInfo);
29
- const staticPdfHref = currentDeploymentInfo.pdf;
30
-
31
- const localDeployEnabled = useMemo(() => {
32
- if (typeof window === "undefined") return false;
33
- return isLocalWorkspaceHost(window.location.hostname);
34
- }, []);
35
-
36
- const pdfButtonText = workbenchPdfButtonText(localDeployEnabled, pdfActionStatus, staticPdfHref);
37
- const pdfStatusMessage = workbenchPdfStatusMessage(localDeployEnabled, pdfActionStatus);
38
- const pdfButtonDisabled = localDeployEnabled
39
- ? pdfActionStatus === "generating" || pdfActionStatus === "opening"
40
- : !staticPdfHref;
41
- const pdfToolbarExpanded = pdfActionStatus !== "idle";
42
-
43
- const handleDeploy = useCallback(async () => {
44
- if (status === "deploying") return;
45
- if (currentDeploymentInfo.configured === false) {
46
- setStatus("setup");
47
- return;
48
- }
49
- setStatus("deploying");
50
- try {
51
- const response = await fetch("/__openpress/deploy", { method: "POST" });
52
- if (response.status === 404 || response.status === 405) {
53
- setStatus("unavailable");
54
- return;
55
- }
56
- if (!response.ok) {
57
- const text = await response.text().catch(() => "");
58
- const result = parseDeployError(text);
59
- if (result?.deploy_configured === false) {
60
- setCurrentDeploymentInfo((info) => ({
61
- ...info,
62
- configured: false,
63
- adapter: result.deploy_adapter ?? info.adapter,
64
- source: result.deploy_source ?? info.source,
65
- projectName: result.deploy_project_name ?? info.projectName,
66
- setupMessage: result.message ?? info.setupMessage,
67
- }));
68
- setStatus("setup");
69
- return;
70
- }
71
- console.error("OpenPress deploy failed", text);
72
- setStatus("failed");
73
- return;
74
- }
75
- const result = (await response.json().catch(() => null)) as {
76
- deployed_at?: string;
77
- pdf?: string;
78
- public_url?: string;
79
- } | null;
80
- setCurrentDeploymentInfo((info) => ({
81
- online: true,
82
- deployedAt: result?.deployed_at ?? new Date().toISOString(),
83
- pdf: result?.pdf ?? info.pdf ?? __OPENPRESS_PDF_HREF__,
84
- publicUrl: result?.public_url ?? info.publicUrl,
85
- dirty: false,
86
- }));
87
- setStatus("deployed");
88
- setTimeout(() => setStatus("idle"), 3200);
89
- } catch (error) {
90
- console.error("OpenPress deploy unavailable", error);
91
- setStatus("unavailable");
92
- }
93
- }, [status, currentDeploymentInfo.configured]);
94
-
95
- const handleOpenLatestLocalPdf = useCallback(async () => {
96
- if (pdfActionStatus === "generating") return;
97
- setPdfActionStatus("generating");
98
- try {
99
- const response = await fetch("/__openpress/local-pdf-export", { method: "POST" });
100
- if (!response.ok) {
101
- const text = await response.text().catch(() => "");
102
- throw new Error(text || `Local PDF export failed with status ${response.status}`);
103
- }
104
- const result = (await response.json().catch(() => null)) as { pdf?: string } | null;
105
- const pdfHref = result?.pdf ?? "/__openpress/local-pdf-file";
106
- setPdfActionStatus("opening");
107
- window.setTimeout(() => window.location.assign(pdfHref), 180);
108
- } catch (error) {
109
- console.error("OpenPress local PDF export failed", error);
110
- setPdfActionStatus("failed");
111
- }
112
- }, [pdfActionStatus]);
113
-
114
- const handleOpenWorkbenchPdf = useCallback(() => {
115
- if (localDeployEnabled) {
116
- void handleOpenLatestLocalPdf();
117
- return;
118
- }
119
- if (!staticPdfHref) return;
120
- window.open(staticPdfHref, "_blank", "noopener,noreferrer");
121
- }, [handleOpenLatestLocalPdf, localDeployEnabled, staticPdfHref]);
122
-
123
- return {
124
- status,
125
- pdfActionStatus,
126
- currentDeploymentInfo,
127
- staticPdfHref,
128
- localDeployEnabled,
129
- pdfButtonText,
130
- pdfButtonDisabled,
131
- pdfStatusMessage,
132
- pdfToolbarExpanded,
133
- handleDeploy,
134
- handleOpenWorkbenchPdf,
135
- };
136
- }
@@ -1,72 +0,0 @@
1
- import { type ReactNode } from "react";
2
- import { createPortal } from "react-dom";
3
- import { X } from "lucide-react";
4
-
5
- export function WorkbenchDialog({
6
- titleId,
7
- title,
8
- eyebrow,
9
- titleMeta,
10
- className,
11
- backdropClassName,
12
- headerClassName,
13
- closeLabel,
14
- onClose,
15
- children,
16
- footer,
17
- }: {
18
- titleId: string;
19
- title: ReactNode;
20
- eyebrow?: ReactNode;
21
- titleMeta?: ReactNode;
22
- className?: string;
23
- backdropClassName?: string;
24
- headerClassName?: string;
25
- closeLabel: string;
26
- onClose: () => void;
27
- children: ReactNode;
28
- footer?: ReactNode;
29
- }) {
30
- if (typeof document === "undefined") return null;
31
-
32
- return createPortal(
33
- <div
34
- className={joinClassNames("openpress-workbench-dialog-backdrop", backdropClassName)}
35
- role="presentation"
36
- onClick={onClose}
37
- >
38
- <section
39
- className={joinClassNames("openpress-workbench-dialog", className)}
40
- role="dialog"
41
- aria-modal="true"
42
- aria-labelledby={titleId}
43
- onClick={(event) => event.stopPropagation()}
44
- >
45
- <header className={joinClassNames("openpress-workbench-dialog__header", headerClassName)}>
46
- <div className="openpress-workbench-dialog__heading">
47
- {eyebrow ? <span className="openpress-workbench-dialog__eyebrow">{eyebrow}</span> : null}
48
- <div className="openpress-workbench-dialog__title-row">
49
- <h2 id={titleId}>{title}</h2>
50
- {titleMeta ? <div className="openpress-workbench-dialog__title-meta">{titleMeta}</div> : null}
51
- </div>
52
- </div>
53
- <button
54
- type="button"
55
- className="openpress-workbench-dialog__close"
56
- aria-label={closeLabel}
57
- onClick={onClose}
58
- >
59
- <X aria-hidden="true" />
60
- </button>
61
- </header>
62
- {children}
63
- {footer ? <footer className="openpress-workbench-dialog__footer">{footer}</footer> : null}
64
- </section>
65
- </div>,
66
- document.body,
67
- );
68
- }
69
-
70
- function joinClassNames(...classNames: Array<string | false | null | undefined>) {
71
- return classNames.filter(Boolean).join(" ");
72
- }
@@ -1 +0,0 @@
1
- export { WorkbenchDialog } from "./WorkbenchDialog";
@@ -1,127 +0,0 @@
1
- import { createContext, useContext, useId, useState, type ReactNode } from "react";
2
- import { FolderKanban, MessageSquareText, type LucideIcon } from "lucide-react";
3
-
4
- type DocumentPanelProps = {
5
- children: ReactNode;
6
- };
7
-
8
- type DocumentPanelTabValue = "comments" | "project";
9
-
10
- type DocumentPanelContextValue = {
11
- activeTab: DocumentPanelTabValue;
12
- setActiveTab: (tab: DocumentPanelTabValue) => void;
13
- baseId: string;
14
- };
15
-
16
- const DocumentPanelContext = createContext<DocumentPanelContextValue | null>(null);
17
-
18
- const PANEL_TABS: Array<{ value: DocumentPanelTabValue; label: string; icon: LucideIcon }> = [
19
- { value: "comments", label: "註解", icon: MessageSquareText },
20
- { value: "project", label: "Project", icon: FolderKanban },
21
- ];
22
-
23
- function useDocumentPanel() {
24
- const value = useContext(DocumentPanelContext);
25
- if (!value) throw new Error("DocumentPanel compound components must be rendered inside <DocumentPanel>.");
26
- return value;
27
- }
28
-
29
- function DocumentPanelRoot({ children }: DocumentPanelProps) {
30
- const reactId = useId();
31
- const [activeTab, setActiveTab] = useState<DocumentPanelTabValue>("comments");
32
- const baseId = `openpress-document-panel-${reactId.replaceAll(":", "")}`;
33
-
34
- return (
35
- <DocumentPanelContext.Provider value={{ activeTab, setActiveTab, baseId }}>
36
- <section
37
- className="openpress-document-panel"
38
- data-openpress-document-panel
39
- data-openpress-document-panel-tab={activeTab}
40
- >
41
- {children}
42
- </section>
43
- </DocumentPanelContext.Provider>
44
- );
45
- }
46
-
47
- function DocumentPanelTabs() {
48
- const { activeTab, setActiveTab, baseId } = useDocumentPanel();
49
-
50
- return (
51
- <div className="openpress-dev-control-tabs openpress-document-panel-tabs" role="tablist" aria-label="側邊面板">
52
- {PANEL_TABS.map((item) => {
53
- const Icon = item.icon;
54
- const selected = activeTab === item.value;
55
- return (
56
- <button
57
- type="button"
58
- role="tab"
59
- aria-selected={selected}
60
- aria-controls={`${baseId}-${item.value}`}
61
- id={`${baseId}-${item.value}-tab`}
62
- className={selected ? "is-active" : undefined}
63
- key={item.value}
64
- onClick={() => setActiveTab(item.value)}
65
- >
66
- <Icon aria-hidden="true" />
67
- <span>{item.label}</span>
68
- </button>
69
- );
70
- })}
71
- </div>
72
- );
73
- }
74
-
75
- function DocumentPanelTabPanel({
76
- value,
77
- className,
78
- children,
79
- }: DocumentPanelProps & {
80
- value: DocumentPanelTabValue;
81
- className?: string;
82
- }) {
83
- const { activeTab, baseId } = useDocumentPanel();
84
- const active = activeTab === value;
85
-
86
- return (
87
- <section
88
- id={`${baseId}-${value}`}
89
- className={className}
90
- role="tabpanel"
91
- aria-labelledby={`${baseId}-${value}-tab`}
92
- data-openpress-document-panel-tab-panel={value}
93
- data-active={active ? "true" : "false"}
94
- hidden={!active}
95
- >
96
- {children}
97
- </section>
98
- );
99
- }
100
-
101
- function DocumentPanelProject({ children }: DocumentPanelProps) {
102
- return (
103
- <DocumentPanelTabPanel value="project" className="openpress-document-panel__project">
104
- {children}
105
- </DocumentPanelTabPanel>
106
- );
107
- }
108
-
109
- function DocumentPanelPendingComments({ children }: DocumentPanelProps) {
110
- return (
111
- <DocumentPanelTabPanel value="comments" className="openpress-document-panel__comments">
112
- {children}
113
- </DocumentPanelTabPanel>
114
- );
115
- }
116
-
117
- function DocumentPanelSlot({ children }: DocumentPanelProps) {
118
- return <>{children}</>;
119
- }
120
-
121
- export const DocumentPanel = Object.assign(DocumentPanelRoot, {
122
- Tabs: DocumentPanelTabs,
123
- Project: DocumentPanelProject,
124
- PendingComments: DocumentPanelPendingComments,
125
- Actions: DocumentPanelSlot,
126
- CurrentPage: DocumentPanelSlot,
127
- });
@@ -1,207 +0,0 @@
1
- import { useEffect, useMemo, useState } from "react";
2
- import type {
3
- InlineDocumentEditStatus,
4
- InlineDocumentSourceTarget,
5
- } from "../hooks/useInlineDocumentEditor";
6
-
7
- export function InlineSourceEditorLayer({
8
- target,
9
- fetchImpl,
10
- onClose,
11
- onStatusChange,
12
- geometryVersion,
13
- }: {
14
- target: InlineDocumentSourceTarget | null;
15
- fetchImpl?: typeof fetch;
16
- onClose: () => void;
17
- onStatusChange?: (status: InlineDocumentEditStatus) => void;
18
- geometryVersion?: unknown;
19
- }) {
20
- const [text, setText] = useState("");
21
- const [status, setStatus] = useState<"idle" | "loading" | "saving" | "failed">("idle");
22
- const [error, setError] = useState("");
23
- const sourceRequestUrl = useMemo(() => target ? sourceReadUrl(target) : "", [target]);
24
- const targetRect = useMemo(() => target ? resolveSourceEditorTargetRect(target) : null, [geometryVersion, target]);
25
-
26
- useEffect(() => {
27
- if (!target) {
28
- setText("");
29
- setStatus("idle");
30
- setError("");
31
- return undefined;
32
- }
33
-
34
- const request = fetchImpl ?? globalThis.fetch?.bind(globalThis);
35
- if (!request) {
36
- setStatus("failed");
37
- setError("Source edit endpoint is unavailable.");
38
- return undefined;
39
- }
40
-
41
- let canceled = false;
42
- setStatus("loading");
43
- setError("");
44
- void request(sourceRequestUrl, { method: "GET" })
45
- .then(async (response) => {
46
- if (!response.ok) {
47
- const message = await response.text().catch(() => "");
48
- throw new Error(message || `Source read failed with status ${response.status}`);
49
- }
50
- return response.json() as Promise<{ source?: { text?: string } }>;
51
- })
52
- .then((result) => {
53
- if (canceled) return;
54
- setText(result.source?.text ?? "");
55
- setStatus("idle");
56
- onStatusChange?.({ state: "editing", blockId: target.block.id });
57
- })
58
- .catch((readError) => {
59
- if (canceled) return;
60
- const message = readError instanceof Error ? readError.message : String(readError);
61
- setStatus("failed");
62
- setError(message);
63
- onStatusChange?.({ state: "failed", blockId: target.block.id, message });
64
- });
65
-
66
- return () => {
67
- canceled = true;
68
- };
69
- }, [fetchImpl, onStatusChange, sourceRequestUrl, target]);
70
-
71
- if (!target) return null;
72
-
73
- const block = target.block;
74
- const position = sourceEditorPosition(targetRect ?? target.rect);
75
- const canSave = status !== "loading" && status !== "saving" && text.trim().length > 0;
76
-
77
- const handleSave = async () => {
78
- const request = fetchImpl ?? globalThis.fetch?.bind(globalThis);
79
- if (!request) {
80
- setStatus("failed");
81
- setError("Source edit endpoint is unavailable.");
82
- return;
83
- }
84
-
85
- setStatus("saving");
86
- setError("");
87
- onStatusChange?.({ state: "saving", blockId: block.id });
88
- try {
89
- const response = await request("/__openpress/source-edit", {
90
- method: "POST",
91
- headers: { "Content-Type": "application/json" },
92
- body: JSON.stringify({
93
- blockId: block.id,
94
- path: block.path,
95
- kind: block.kind,
96
- name: block.name,
97
- source: block.source,
98
- sourceMode: true,
99
- text,
100
- }),
101
- });
102
- if (!response.ok) {
103
- const message = await response.text().catch(() => "");
104
- throw new Error(message || `Source edit failed with status ${response.status}`);
105
- }
106
- setStatus("idle");
107
- onStatusChange?.({ state: "saved", blockId: block.id });
108
- onClose();
109
- } catch (saveError) {
110
- const message = saveError instanceof Error ? saveError.message : String(saveError);
111
- setStatus("failed");
112
- setError(message);
113
- onStatusChange?.({ state: "failed", blockId: block.id, message });
114
- }
115
- };
116
-
117
- const statusText = sourceEditorStatusText(status, error);
118
-
119
- return (
120
- <div className="openpress-inline-source-editor-layer" onMouseDown={(event) => event.stopPropagation()}>
121
- <section
122
- className="openpress-inline-source-editor"
123
- role="dialog"
124
- aria-label="Source 編輯"
125
- style={position}
126
- >
127
- <header className="openpress-inline-source-editor__header">
128
- <div>
129
- <span className="openpress-inline-source-editor__eyebrow">SOURCE</span>
130
- <strong>{block.name ?? block.kind ?? "Block"}</strong>
131
- </div>
132
- <button type="button" onClick={onClose} aria-label="關閉 source 編輯">
133
- ×
134
- </button>
135
- </header>
136
- <textarea
137
- aria-label="Source 內容"
138
- value={text}
139
- disabled={status === "loading" || status === "saving"}
140
- spellCheck={false}
141
- onChange={(event) => {
142
- setText(event.target.value);
143
- onStatusChange?.({ state: "editing", blockId: block.id });
144
- }}
145
- onKeyDown={(event) => {
146
- if (event.key === "Escape") {
147
- event.stopPropagation();
148
- onClose();
149
- }
150
- }}
151
- />
152
- <footer className="openpress-inline-source-editor__footer">
153
- <span data-openpress-source-editor-status={status} role="status" aria-live="polite">
154
- {statusText}
155
- </span>
156
- <div>
157
- <button type="button" onClick={onClose}>
158
- 取消
159
- </button>
160
- <button type="button" onClick={handleSave} disabled={!canSave}>
161
- 儲存 source
162
- </button>
163
- </div>
164
- </footer>
165
- </section>
166
- </div>
167
- );
168
- }
169
-
170
- function sourceReadUrl(target: InlineDocumentSourceTarget) {
171
- const params = new URLSearchParams();
172
- params.set("path", target.block.path);
173
- params.set("line", String(target.block.source?.line ?? 1));
174
- params.set("column", String(target.block.source?.column ?? 1));
175
- params.set("endLine", String(target.block.source?.endLine ?? target.block.source?.line ?? 1));
176
- params.set("endColumn", String(target.block.source?.endColumn ?? target.block.source?.column ?? 1));
177
- return `/__openpress/source-edit?${params.toString()}`;
178
- }
179
-
180
- function resolveSourceEditorTargetRect(target: InlineDocumentSourceTarget) {
181
- const rect = target.element.getBoundingClientRect();
182
- if (rect.width > 0 || rect.height > 0 || rect.left !== 0 || rect.top !== 0) return rect;
183
- return target.rect;
184
- }
185
-
186
- function sourceEditorPosition(rect: DOMRect) {
187
- const width = 420;
188
- const margin = 14;
189
- const viewportWidth = typeof window === "undefined" ? 1280 : window.innerWidth;
190
- const viewportHeight = typeof window === "undefined" ? 900 : window.innerHeight;
191
- const left = Math.min(Math.max(rect.left, margin), Math.max(margin, viewportWidth - width - margin));
192
- const top = rect.bottom + 12 + 280 < viewportHeight
193
- ? rect.bottom + 12
194
- : Math.max(margin, rect.top - 292);
195
- return {
196
- left,
197
- top,
198
- width,
199
- };
200
- }
201
-
202
- function sourceEditorStatusText(status: "idle" | "loading" | "saving" | "failed", error: string) {
203
- if (status === "loading") return "讀取中";
204
- if (status === "saving") return "儲存中";
205
- if (status === "failed") return error || "儲存失敗";
206
- return "可編輯 source";
207
- }
@@ -1,9 +0,0 @@
1
- import { forwardRef, type ReactNode } from "react";
2
-
3
- export const ReaderStage = forwardRef<HTMLElement, { children: ReactNode }>(function ReaderStage({ children }, ref) {
4
- return (
5
- <main className="reader-stage" tabIndex={-1} ref={ref}>
6
- {children}
7
- </main>
8
- );
9
- });
@@ -1,34 +0,0 @@
1
- import { useMemo } from "react";
2
- import {
3
- collectBookmarkIndex,
4
- collectMediaAssetIndex,
5
- createAnchorPageMap,
6
- getSourceBlockMap,
7
- type ReaderDocument,
8
- } from "../../../document-model";
9
- import type { DisplayPage } from "../../../reader";
10
- import { groupSourceBlocksByPath } from "../../inspector";
11
- import { createProjectComponentUsages, createProjectMentionItems } from "../../project";
12
-
13
- export function useDocumentWorkbenchModel(document: ReaderDocument, pages: DisplayPage[]) {
14
- const mediaAssets = useMemo(() => collectMediaAssetIndex(pages), [pages]);
15
- const anchorPageMap = useMemo(() => createAnchorPageMap(pages), [pages]);
16
- const projectComponentUsages = useMemo(() => createProjectComponentUsages(pages), [pages]);
17
- const bookmarks = useMemo(() => collectBookmarkIndex(pages), [pages]);
18
- const sourceBlockMap = useMemo(() => getSourceBlockMap(document), [document]);
19
- const sourceBlocksByPath = useMemo(() => groupSourceBlocksByPath(sourceBlockMap), [sourceBlockMap]);
20
- const projectMentionItems = useMemo(
21
- () => createProjectMentionItems(mediaAssets, projectComponentUsages, bookmarks),
22
- [bookmarks, mediaAssets, projectComponentUsages],
23
- );
24
-
25
- return {
26
- mediaAssets,
27
- anchorPageMap,
28
- projectComponentUsages,
29
- bookmarks,
30
- sourceBlockMap,
31
- sourceBlocksByPath,
32
- projectMentionItems,
33
- };
34
- }