@open-press/cli 1.0.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 (175) hide show
  1. package/README.md +11 -12
  2. package/dist/cli.js +298 -79
  3. package/package.json +9 -7
  4. package/template/core/AGENTS.md +0 -130
  5. package/template/core/CHANGELOG.md +0 -218
  6. package/template/core/README.md +0 -43
  7. package/template/core/engine/cli.mjs +0 -96
  8. package/template/core/engine/commands/_shared.mjs +0 -199
  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/image.mjs +0 -29
  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/skills-sync.mjs +0 -71
  21. package/template/core/engine/commands/typecheck.mjs +0 -67
  22. package/template/core/engine/commands/upgrade.mjs +0 -159
  23. package/template/core/engine/commands/validate.mjs +0 -17
  24. package/template/core/engine/document-export.mjs +0 -15
  25. package/template/core/engine/output/chrome-pdf.d.mts +0 -34
  26. package/template/core/engine/output/chrome-pdf.mjs +0 -450
  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 -571
  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 -331
  39. package/template/core/engine/react/document-export.mjs +0 -512
  40. package/template/core/engine/react/http-json.mjs +0 -24
  41. package/template/core/engine/react/mdx-compile.mjs +0 -629
  42. package/template/core/engine/react/measurement-css.mjs +0 -157
  43. package/template/core/engine/react/object-entities.mjs +0 -204
  44. package/template/core/engine/react/pagination/allocator.mjs +0 -167
  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 -217
  49. package/template/core/engine/react/pipeline/final-render.mjs +0 -94
  50. package/template/core/engine/react/pipeline/frame-measurement.mjs +0 -306
  51. package/template/core/engine/react/pipeline/press-tree.mjs +0 -135
  52. package/template/core/engine/react/press-tree-inspection.mjs +0 -172
  53. package/template/core/engine/react/project-asset-endpoint.d.mts +0 -10
  54. package/template/core/engine/react/project-asset-endpoint.mjs +0 -361
  55. package/template/core/engine/react/section-css.mjs +0 -56
  56. package/template/core/engine/react/source-edit-endpoint.d.mts +0 -10
  57. package/template/core/engine/react/source-edit-endpoint.mjs +0 -75
  58. package/template/core/engine/react/sources/heading-numbering.mjs +0 -132
  59. package/template/core/engine/react/sources/mdx-resolver.mjs +0 -439
  60. package/template/core/engine/react/style-discovery.mjs +0 -160
  61. package/template/core/engine/runtime/config.d.mts +0 -48
  62. package/template/core/engine/runtime/config.mjs +0 -172
  63. package/template/core/engine/runtime/file-utils.mjs +0 -114
  64. package/template/core/engine/runtime/file-walk.mjs +0 -22
  65. package/template/core/engine/runtime/inspection.mjs +0 -328
  66. package/template/core/engine/runtime/issue-report.mjs +0 -44
  67. package/template/core/engine/runtime/page-geometry.mjs +0 -131
  68. package/template/core/engine/runtime/path-utils.mjs +0 -20
  69. package/template/core/engine/runtime/source-text-tools.d.mts +0 -102
  70. package/template/core/engine/runtime/source-text-tools.mjs +0 -832
  71. package/template/core/engine/runtime/source-workspace.mjs +0 -168
  72. package/template/core/engine/runtime/validation.mjs +0 -183
  73. package/template/core/index.html +0 -13
  74. package/template/core/openpress.config.mjs +0 -8
  75. package/template/core/package.json +0 -89
  76. package/template/core/src/main.tsx +0 -16
  77. package/template/core/src/openpress/app/OpenPressApp.tsx +0 -296
  78. package/template/core/src/openpress/app/OpenPressRuntime.tsx +0 -102
  79. package/template/core/src/openpress/app/WorkspaceGalleryPage.tsx +0 -219
  80. package/template/core/src/openpress/app/index.ts +0 -2
  81. package/template/core/src/openpress/core/Frame.tsx +0 -91
  82. package/template/core/src/openpress/core/FrameContext.tsx +0 -26
  83. package/template/core/src/openpress/core/MdxArea.tsx +0 -34
  84. package/template/core/src/openpress/core/Press.tsx +0 -55
  85. package/template/core/src/openpress/core/Workspace.tsx +0 -36
  86. package/template/core/src/openpress/core/cn.ts +0 -4
  87. package/template/core/src/openpress/core/index.tsx +0 -47
  88. package/template/core/src/openpress/core/primitives.tsx +0 -91
  89. package/template/core/src/openpress/core/types.ts +0 -236
  90. package/template/core/src/openpress/core/useSource.ts +0 -28
  91. package/template/core/src/openpress/document-model/anchorMapModel.ts +0 -27
  92. package/template/core/src/openpress/document-model/documentIndexes.ts +0 -329
  93. package/template/core/src/openpress/document-model/documentTypes.ts +0 -147
  94. package/template/core/src/openpress/document-model/index.ts +0 -7
  95. package/template/core/src/openpress/document-model/objectEntityModel.ts +0 -55
  96. package/template/core/src/openpress/document-model/projectIdentityModel.ts +0 -15
  97. package/template/core/src/openpress/document-model/reactDocumentMetadataModel.ts +0 -27
  98. package/template/core/src/openpress/document-model/workspaceManifestModel.ts +0 -57
  99. package/template/core/src/openpress/manuscript/index.tsx +0 -238
  100. package/template/core/src/openpress/mdx/index.ts +0 -96
  101. package/template/core/src/openpress/numbering/index.ts +0 -294
  102. package/template/core/src/openpress/reader/PageThumbnailsPanel.tsx +0 -168
  103. package/template/core/src/openpress/reader/PublicReaderPage.tsx +0 -267
  104. package/template/core/src/openpress/reader/ReaderNavigationPanel.tsx +0 -123
  105. package/template/core/src/openpress/reader/index.ts +0 -11
  106. package/template/core/src/openpress/reader/pageViewportScaleModel.ts +0 -73
  107. package/template/core/src/openpress/reader/readerPageRegistry.ts +0 -41
  108. package/template/core/src/openpress/reader/readerPageRoute.ts +0 -21
  109. package/template/core/src/openpress/reader/readerScroll.ts +0 -92
  110. package/template/core/src/openpress/reader/readerStateModel.ts +0 -15
  111. package/template/core/src/openpress/reader/readerTypes.ts +0 -4
  112. package/template/core/src/openpress/reader/usePageViewportScale.ts +0 -119
  113. package/template/core/src/openpress/reader/usePanelState.ts +0 -56
  114. package/template/core/src/openpress/reader/useReaderHashSync.ts +0 -61
  115. package/template/core/src/openpress/reader/useReaderKeyboardNav.ts +0 -48
  116. package/template/core/src/openpress/reader/useReaderRuntime.ts +0 -146
  117. package/template/core/src/openpress/reader/useReaderScrollAnchor.ts +0 -64
  118. package/template/core/src/openpress/shared/Panel.tsx +0 -77
  119. package/template/core/src/openpress/shared/frameScheduler.ts +0 -32
  120. package/template/core/src/openpress/shared/index.ts +0 -4
  121. package/template/core/src/openpress/shared/numberUtils.ts +0 -3
  122. package/template/core/src/openpress/shared/runtimeMode.ts +0 -11
  123. package/template/core/src/openpress/workbench/Workbench.tsx +0 -506
  124. package/template/core/src/openpress/workbench/actions/DeploymentControl.tsx +0 -157
  125. package/template/core/src/openpress/workbench/actions/ExportImageControl.tsx +0 -96
  126. package/template/core/src/openpress/workbench/actions/PageZoomControl.tsx +0 -182
  127. package/template/core/src/openpress/workbench/actions/SearchControl.tsx +0 -345
  128. package/template/core/src/openpress/workbench/actions/deploymentStatusModel.ts +0 -112
  129. package/template/core/src/openpress/workbench/actions/index.ts +0 -6
  130. package/template/core/src/openpress/workbench/actions/useDeploymentWorkbench.ts +0 -136
  131. package/template/core/src/openpress/workbench/dialog/WorkbenchDialog.tsx +0 -72
  132. package/template/core/src/openpress/workbench/dialog/index.ts +0 -1
  133. package/template/core/src/openpress/workbench/document/components/DocumentPanel.tsx +0 -127
  134. package/template/core/src/openpress/workbench/document/components/InlineSourceEditorLayer.tsx +0 -207
  135. package/template/core/src/openpress/workbench/document/components/ReaderStage.tsx +0 -9
  136. package/template/core/src/openpress/workbench/document/hooks/useDocumentWorkbenchModel.ts +0 -34
  137. package/template/core/src/openpress/workbench/document/hooks/useInlineDocumentEditor.ts +0 -525
  138. package/template/core/src/openpress/workbench/document/index.ts +0 -10
  139. package/template/core/src/openpress/workbench/index.ts +0 -2
  140. package/template/core/src/openpress/workbench/inspector/InlineInspectorLayer.tsx +0 -459
  141. package/template/core/src/openpress/workbench/inspector/index.ts +0 -5
  142. package/template/core/src/openpress/workbench/inspector/inlineCommentModel.ts +0 -125
  143. package/template/core/src/openpress/workbench/inspector/inspectorGeometryModel.ts +0 -160
  144. package/template/core/src/openpress/workbench/inspector/inspectorModel.ts +0 -408
  145. package/template/core/src/openpress/workbench/inspector/useInspectorComments.ts +0 -254
  146. package/template/core/src/openpress/workbench/mentions/MentionSuggestionList.tsx +0 -41
  147. package/template/core/src/openpress/workbench/mentions/index.ts +0 -2
  148. package/template/core/src/openpress/workbench/mentions/useComposerMentions.ts +0 -185
  149. package/template/core/src/openpress/workbench/panels/Panel.tsx +0 -1
  150. package/template/core/src/openpress/workbench/panels/PendingCommentsPanel.tsx +0 -80
  151. package/template/core/src/openpress/workbench/panels/WorkbenchControlPanel.tsx +0 -29
  152. package/template/core/src/openpress/workbench/panels/index.ts +0 -3
  153. package/template/core/src/openpress/workbench/project/ProjectEntryPanel.tsx +0 -525
  154. package/template/core/src/openpress/workbench/project/ProjectPreviewDialog.tsx +0 -35
  155. package/template/core/src/openpress/workbench/project/index.ts +0 -2
  156. package/template/core/src/openpress/workbench/project/projectPreviewTypes.ts +0 -11
  157. package/template/core/src/openpress/workbench/project/projectSourceModel.ts +0 -24
  158. package/template/core/src/openpress/workbench/shell/WorkbenchShell.tsx +0 -167
  159. package/template/core/src/openpress/workbench/shell/index.ts +0 -1
  160. package/template/core/src/openpress/workbench/workbenchFormatters.ts +0 -120
  161. package/template/core/src/openpress/workbench/workbenchTypes.ts +0 -35
  162. package/template/core/src/styles/openpress/app-shell.css +0 -251
  163. package/template/core/src/styles/openpress/media-workspace.css +0 -230
  164. package/template/core/src/styles/openpress/print-route.css +0 -184
  165. package/template/core/src/styles/openpress/project-preview-panel.css +0 -924
  166. package/template/core/src/styles/openpress/public-viewer.css +0 -688
  167. package/template/core/src/styles/openpress/reader-runtime.css +0 -989
  168. package/template/core/src/styles/openpress/responsive.css +0 -245
  169. package/template/core/src/styles/openpress/workbench-panels.css +0 -707
  170. package/template/core/src/styles/openpress/workbench.css +0 -1255
  171. package/template/core/src/styles/openpress/workspace-gallery.css +0 -300
  172. package/template/core/src/styles/openpress.css +0 -15
  173. package/template/core/src/vite-env.d.ts +0 -9
  174. package/template/core/tsconfig.json +0 -40
  175. package/template/core/vite.config.ts +0 -584
@@ -1,345 +0,0 @@
1
- import { useCallback, useEffect, useId, useMemo, useRef, useState, type FormEvent } from "react";
2
- import { FileText, Loader2, Search } from "lucide-react";
3
- import type { SourceBlock } from "../../document-model";
4
- import { WorkbenchDialog } from "../dialog";
5
-
6
- type SearchScope = "content" | "all";
7
- type SearchStatus = "idle" | "loading" | "success" | "error";
8
- const SEARCH_SCOPE: SearchScope = "all";
9
- const LIVE_SEARCH_DEBOUNCE_MS = 280;
10
-
11
- type SearchFile = {
12
- scope: string;
13
- file: string;
14
- path: string;
15
- matchCount: number;
16
- };
17
-
18
- type SearchMatch = {
19
- id: string;
20
- scope: string;
21
- file: string;
22
- path: string;
23
- line: number;
24
- column: number;
25
- index: number;
26
- text: string;
27
- preview: string;
28
- };
29
-
30
- type SearchReport = {
31
- ok?: boolean;
32
- kind: "search";
33
- query: string;
34
- scope: SearchScope;
35
- caseSensitive: boolean;
36
- matchCount: number;
37
- files: Array<SearchFile>;
38
- matches: Array<SearchMatch>;
39
- message?: string;
40
- };
41
-
42
- type SearchJumpTarget = {
43
- blockId: string;
44
- pageIndex: number;
45
- pageNumber: number;
46
- };
47
-
48
- export function SearchControl({
49
- sourceBlocksByPath = {},
50
- onSelectPage,
51
- }: {
52
- sourceBlocksByPath?: Record<string, SourceBlock[]>;
53
- onSelectPage?: (pageIndex: number, options?: { behavior?: ScrollBehavior }) => void;
54
- }) {
55
- const titleId = useId();
56
- const [open, setOpen] = useState(false);
57
- const [query, setQuery] = useState("");
58
- const [status, setStatus] = useState<SearchStatus>("idle");
59
- const [report, setReport] = useState<SearchReport | null>(null);
60
- const [error, setError] = useState("");
61
- const activeSearchControllerRef = useRef<AbortController | null>(null);
62
- const searchRequestIdRef = useRef(0);
63
- const submittedQueryRef = useRef<string | null>(null);
64
- const matchesByPath = useMemo(() => groupMatchesByPath(report?.matches ?? []), [report]);
65
-
66
- const jumpToMatch = (match: SearchMatch) => {
67
- const target = resolveSearchJumpTarget(match, sourceBlocksByPath);
68
- if (!target || !onSelectPage) return;
69
- onSelectPage(target.pageIndex, { behavior: "smooth" });
70
- setOpen(false);
71
- };
72
-
73
- useEffect(() => {
74
- if (!open) return;
75
- const handleKeyDown = (event: KeyboardEvent) => {
76
- if (event.key === "Escape") setOpen(false);
77
- };
78
- window.addEventListener("keydown", handleKeyDown);
79
- return () => window.removeEventListener("keydown", handleKeyDown);
80
- }, [open]);
81
-
82
- const runSearch = useCallback(async (rawQuery: string, controller: AbortController) => {
83
- const trimmedQuery = rawQuery.trim();
84
- if (!trimmedQuery) {
85
- activeSearchControllerRef.current?.abort();
86
- activeSearchControllerRef.current = null;
87
- setReport(null);
88
- setError("");
89
- setStatus("idle");
90
- return;
91
- }
92
-
93
- activeSearchControllerRef.current?.abort();
94
- activeSearchControllerRef.current = controller;
95
- const requestId = searchRequestIdRef.current + 1;
96
- searchRequestIdRef.current = requestId;
97
- setStatus("loading");
98
- setError("");
99
-
100
- try {
101
- const params = new URLSearchParams();
102
- params.set("q", trimmedQuery);
103
- params.set("scope", SEARCH_SCOPE);
104
- const response = await fetch(`/__openpress/search?${params.toString()}`, {
105
- cache: "no-store",
106
- signal: controller.signal,
107
- });
108
- const data = await response.json().catch(() => null) as (Partial<SearchReport> & { message?: string }) | null;
109
- if (controller.signal.aborted || requestId !== searchRequestIdRef.current) return;
110
- if (!response.ok || data?.ok === false || !isSearchReport(data)) {
111
- throw new Error(data?.message ?? "搜尋失敗。");
112
- }
113
- setReport(data);
114
- setStatus("success");
115
- } catch (searchError) {
116
- if (controller.signal.aborted || requestId !== searchRequestIdRef.current) return;
117
- setError(searchError instanceof Error ? searchError.message : String(searchError));
118
- setStatus("error");
119
- }
120
- }, []);
121
-
122
- useEffect(() => {
123
- if (!open) return undefined;
124
- const trimmedQuery = query.trim();
125
- if (!trimmedQuery) {
126
- activeSearchControllerRef.current?.abort();
127
- activeSearchControllerRef.current = null;
128
- setReport(null);
129
- setError("");
130
- setStatus("idle");
131
- return undefined;
132
- }
133
-
134
- const controller = new AbortController();
135
- const timer = window.setTimeout(() => {
136
- if (submittedQueryRef.current === trimmedQuery) {
137
- submittedQueryRef.current = null;
138
- return;
139
- }
140
- void runSearch(trimmedQuery, controller);
141
- }, LIVE_SEARCH_DEBOUNCE_MS);
142
-
143
- return () => {
144
- window.clearTimeout(timer);
145
- controller.abort();
146
- };
147
- }, [open, query, runSearch]);
148
-
149
- const submitSearch = async (event: FormEvent<HTMLFormElement>) => {
150
- event.preventDefault();
151
- const trimmedQuery = query.trim();
152
- submittedQueryRef.current = trimmedQuery;
153
- await runSearch(trimmedQuery, new AbortController());
154
- };
155
-
156
- const dialog = open ? (
157
- <WorkbenchDialog
158
- titleId={titleId}
159
- title="搜尋文件"
160
- eyebrow="Search"
161
- className="openpress-search-dialog"
162
- backdropClassName="openpress-search-dialog-backdrop"
163
- headerClassName="openpress-search-dialog__header"
164
- closeLabel="關閉搜尋"
165
- onClose={() => setOpen(false)}
166
- >
167
- <form className="openpress-search-dialog__form" role="search" aria-label="文件搜尋" onSubmit={submitSearch}>
168
- <div className="openpress-search-dialog__input-row">
169
- <Search aria-hidden="true" />
170
- <input
171
- type="search"
172
- value={query}
173
- autoFocus
174
- aria-label="搜尋文字"
175
- placeholder="搜尋所有來源"
176
- onChange={(event) => setQuery(event.currentTarget.value)}
177
- />
178
- <button type="submit" disabled={status === "loading"}>
179
- {status === "loading" ? <Loader2 aria-hidden="true" /> : <Search aria-hidden="true" />}
180
- <span>搜尋</span>
181
- </button>
182
- </div>
183
- </form>
184
- <SearchResults
185
- status={status}
186
- report={report}
187
- error={error}
188
- matchesByPath={matchesByPath}
189
- sourceBlocksByPath={sourceBlocksByPath}
190
- onJumpToMatch={jumpToMatch}
191
- />
192
- </WorkbenchDialog>
193
- ) : null;
194
-
195
- return (
196
- <>
197
- <button
198
- type="button"
199
- className="openpress-workbench-toolbar-action"
200
- data-openpress-search
201
- data-openpress-toolbar-expanded="false"
202
- data-openpress-toolbar-active={open ? "true" : "false"}
203
- aria-label="搜尋文件"
204
- title="搜尋文件"
205
- onClick={() => setOpen(true)}
206
- >
207
- <Search aria-hidden="true" />
208
- </button>
209
- {dialog}
210
- </>
211
- );
212
- }
213
-
214
- function SearchResults({
215
- status,
216
- report,
217
- error,
218
- matchesByPath,
219
- sourceBlocksByPath,
220
- onJumpToMatch,
221
- }: {
222
- status: SearchStatus;
223
- report: SearchReport | null;
224
- error: string;
225
- matchesByPath: Map<string, Array<SearchMatch>>;
226
- sourceBlocksByPath: Record<string, SourceBlock[]>;
227
- onJumpToMatch: (match: SearchMatch) => void;
228
- }) {
229
- if (status === "idle") {
230
- return <p className="openpress-search-dialog__empty">輸入關鍵字即可搜尋文件內容、元件與設定來源。</p>;
231
- }
232
-
233
- if (status === "loading") {
234
- return (
235
- <p className="openpress-search-dialog__empty" role="status">
236
- <Loader2 aria-hidden="true" />
237
- <span>搜尋中</span>
238
- </p>
239
- );
240
- }
241
-
242
- if (status === "error") {
243
- return <p className="openpress-search-dialog__error" role="alert">{error || "搜尋失敗。"}</p>;
244
- }
245
-
246
- if (!report || report.matchCount === 0) {
247
- return <p className="openpress-search-dialog__empty">沒有符合的來源文字。</p>;
248
- }
249
-
250
- return (
251
- <div className="openpress-search-dialog__results" aria-live="polite">
252
- <p className="openpress-search-dialog__summary">{report.matchCount} 個符合結果</p>
253
- {report.files.map((file) => (
254
- <section className="openpress-search-dialog__file" key={file.path}>
255
- <h3>
256
- <FileText aria-hidden="true" />
257
- <span>{file.path}</span>
258
- <small>{file.matchCount}</small>
259
- </h3>
260
- <ol>
261
- {(matchesByPath.get(file.path) ?? []).map((match) => {
262
- const jumpTarget = resolveSearchJumpTarget(match, sourceBlocksByPath);
263
- return (
264
- <li key={match.id}>
265
- <button
266
- type="button"
267
- className="openpress-search-dialog__result"
268
- data-openpress-search-result-jump={jumpTarget ? "true" : "false"}
269
- disabled={!jumpTarget}
270
- onClick={() => onJumpToMatch(match)}
271
- >
272
- <span className="openpress-search-dialog__line">{match.line}:{match.column}</span>
273
- <span className="openpress-search-dialog__preview">{match.preview}</span>
274
- <span className="openpress-search-dialog__page">
275
- {jumpTarget ? `P${String(jumpTarget.pageNumber).padStart(2, "0")}` : "source"}
276
- </span>
277
- </button>
278
- </li>
279
- );
280
- })}
281
- </ol>
282
- </section>
283
- ))}
284
- </div>
285
- );
286
- }
287
-
288
- function groupMatchesByPath(matches: Array<SearchMatch>) {
289
- const grouped = new Map<string, Array<SearchMatch>>();
290
- for (const match of matches) {
291
- const existing = grouped.get(match.path) ?? [];
292
- existing.push(match);
293
- grouped.set(match.path, existing);
294
- }
295
- return grouped;
296
- }
297
-
298
- function isSearchReport(value: unknown): value is SearchReport {
299
- if (!value || typeof value !== "object") return false;
300
- const report = value as Partial<SearchReport>;
301
- return report.kind === "search"
302
- && typeof report.query === "string"
303
- && typeof report.matchCount === "number"
304
- && Array.isArray(report.files)
305
- && Array.isArray(report.matches);
306
- }
307
-
308
- function resolveSearchJumpTarget(
309
- match: SearchMatch,
310
- sourceBlocksByPath: Record<string, SourceBlock[]>,
311
- ): SearchJumpTarget | null {
312
- const blocks = sourcePathKeys(match.path)
313
- .flatMap((key) => sourceBlocksByPath[key] ?? []);
314
- if (!blocks.length) return null;
315
-
316
- let selectedBlock: SourceBlock | null = null;
317
- for (const block of blocks) {
318
- const line = block.source?.line;
319
- if (typeof line !== "number") continue;
320
- if (line <= match.line) {
321
- selectedBlock = block;
322
- continue;
323
- }
324
- break;
325
- }
326
-
327
- const targetBlock = selectedBlock ?? blocks[0] ?? null;
328
- if (!targetBlock || typeof targetBlock.pageIndex !== "number") return null;
329
- return {
330
- blockId: targetBlock.id,
331
- pageIndex: targetBlock.pageIndex,
332
- pageNumber: targetBlock.pageNumber ?? targetBlock.pageIndex + 1,
333
- };
334
- }
335
-
336
- function sourcePathKeys(value: string) {
337
- const normalized = value.trim().replaceAll("\\", "/").replace(/^\.\//, "");
338
- const keys = [normalized];
339
- if (normalized.startsWith("press/")) {
340
- keys.push(normalized.replace(/^press\//, ""));
341
- } else {
342
- keys.push(`press/${normalized}`);
343
- }
344
- return Array.from(new Set(keys));
345
- }
@@ -1,112 +0,0 @@
1
- import type { DeploymentInfo } from "../../document-model";
2
- import type { DeployStatus, PdfActionStatus } from "../workbenchTypes";
3
-
4
- export function deployButtonText(info: DeploymentInfo, status: DeployStatus) {
5
- if (info.configured === false || status === "setup") return "設定部署";
6
- if (status === "deploying") return "部署中";
7
- if (status === "failed") return "重試部署";
8
- if (status === "unavailable") return "本機限定";
9
- if (isDeploymentDirty(info, status)) return "重新部署";
10
- return "部署";
11
- }
12
-
13
- export function workbenchPdfButtonText(localPdfEnabled: boolean, status: PdfActionStatus, staticPdfHref?: string) {
14
- if (localPdfEnabled) {
15
- if (status === "generating") return "產生中";
16
- if (status === "opening") return "正在開啟";
17
- if (status === "failed") return "重試 PDF";
18
- return "產生 PDF";
19
- }
20
- return !staticPdfHref ? "PDF 未部署" : "開啟 PDF";
21
- }
22
-
23
- export function workbenchPdfStatusMessage(localPdfEnabled: boolean, status: PdfActionStatus) {
24
- if (!localPdfEnabled) return null;
25
- if (status === "generating") return "正在產生 PDF";
26
- if (status === "opening") return "PDF 已完成,正在開啟";
27
- if (status === "failed") return "PDF 產生失敗,請重試";
28
- return null;
29
- }
30
-
31
- export function deploymentStatusKind(info: DeploymentInfo, status: DeployStatus) {
32
- if (info.configured === false || status === "setup") return "failed";
33
- if (status === "deploying") return "deploying";
34
- if (status === "failed") return "failed";
35
- if (status === "unavailable") return "unavailable";
36
- if (isDeploymentDirty(info, status)) return "dirty";
37
- if (status === "deployed" || hasOnlineDeployment(info)) return "online";
38
- return "offline";
39
- }
40
-
41
- export function deploymentStatusSummary(info: DeploymentInfo, status: DeployStatus) {
42
- const label = deploymentStatusLabel(info, status);
43
- if ((status === "deployed" || hasOnlineDeployment(info)) && info.deployedAt) {
44
- return `${label} · ${formatDeployTime(info.deployedAt)}`;
45
- }
46
- return label;
47
- }
48
-
49
- export function deploymentStatusText(info: DeploymentInfo, status: DeployStatus) {
50
- if (info.configured === false || status === "setup") {
51
- return info.setupMessage ?? "部署設定尚未完成,請先設定 deploy.projectName";
52
- }
53
- if (status === "deploying") return "部署中";
54
- if (status === "failed") return "部署失敗,請查看終端機";
55
- if (status === "unavailable") return "目前環境沒有本地部署服務";
56
- if (isDeploymentDirty(info, status)) return "已上線但內容有更動,點擊重新部署";
57
- if (status === "deployed" || hasOnlineDeployment(info)) {
58
- return `已上線${info.deployedAt ? `,更新:${formatDeployTime(info.deployedAt)}` : ""}`;
59
- }
60
- return "未上線";
61
- }
62
-
63
- export function parseDeployError(text: string): {
64
- message?: string;
65
- deploy_configured?: boolean;
66
- deploy_adapter?: string;
67
- deploy_source?: string;
68
- deploy_project_name?: string;
69
- } | null {
70
- try {
71
- return JSON.parse(text) as {
72
- message?: string;
73
- deploy_configured?: boolean;
74
- deploy_adapter?: string;
75
- deploy_source?: string;
76
- deploy_project_name?: string;
77
- };
78
- } catch {
79
- return null;
80
- }
81
- }
82
-
83
- function deploymentStatusLabel(info: DeploymentInfo, status: DeployStatus) {
84
- if (info.configured === false || status === "setup") return "缺少設定";
85
- if (status === "deploying") return "正在部署";
86
- if (status === "failed") return "部署失敗";
87
- if (status === "unavailable") return "本機限定";
88
- if (isDeploymentDirty(info, status)) return "有更新";
89
- if (status === "deployed" || hasOnlineDeployment(info)) return "已上線";
90
- return "未上線";
91
- }
92
-
93
- function hasOnlineDeployment(info: DeploymentInfo) {
94
- if (info.configured === false) return false;
95
- return Boolean(info.online || info.deployedAt || info.publicUrl || (info.pdf && /^https?:\/\//i.test(info.pdf)));
96
- }
97
-
98
- function isDeploymentDirty(info: DeploymentInfo, status: DeployStatus) {
99
- return status === "idle" && hasOnlineDeployment(info) && info.dirty === true;
100
- }
101
-
102
- function formatDeployTime(value: string) {
103
- const date = new Date(value);
104
- if (Number.isNaN(date.getTime())) return "時間未知";
105
- return new Intl.DateTimeFormat("zh-TW", {
106
- month: "2-digit",
107
- day: "2-digit",
108
- hour: "2-digit",
109
- minute: "2-digit",
110
- hour12: false,
111
- }).format(date);
112
- }
@@ -1,6 +0,0 @@
1
- export * from "./deploymentStatusModel";
2
- export * from "./DeploymentControl";
3
- export * from "./ExportImageControl";
4
- export * from "./PageZoomControl";
5
- export * from "./SearchControl";
6
- export * from "./useDeploymentWorkbench";
@@ -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";