@open-press/cli 1.0.0 → 1.1.1

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,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
- }