@open-press/cli 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/package.json +1 -1
- package/template/core/AGENTS.md +126 -0
- package/template/core/CHANGELOG.md +65 -0
- package/template/core/engine/commands/dev.mjs +2 -2
- package/template/core/engine/commands/upgrade.mjs +47 -5
- package/template/core/engine/output/chrome-pdf.mjs +18 -3
- package/template/core/engine/output/static-server.mjs +39 -0
- package/template/core/engine/react/comment-endpoint.mjs +13 -39
- package/template/core/engine/react/comment-marker.mjs +30 -6
- package/template/core/engine/react/document-entry.mjs +11 -0
- package/template/core/engine/react/document-export.mjs +45 -5
- package/template/core/engine/react/http-json.mjs +24 -0
- package/template/core/engine/react/mdx-compile.mjs +187 -3
- package/template/core/engine/react/measurement-css.mjs +93 -1
- package/template/core/engine/react/object-entities.mjs +119 -0
- package/template/core/engine/react/pipeline/allocate.mjs +10 -7
- package/template/core/engine/react/pipeline/frame-measurement.mjs +40 -9
- package/template/core/engine/react/project-asset-endpoint.mjs +6 -24
- package/template/core/engine/react/source-edit-endpoint.d.mts +10 -0
- package/template/core/engine/react/source-edit-endpoint.mjs +75 -0
- package/template/core/engine/react/sources/mdx-resolver.mjs +12 -14
- package/template/core/engine/react/style-discovery.mjs +1 -4
- package/template/core/engine/runtime/file-walk.mjs +22 -0
- package/template/core/engine/runtime/inspection.mjs +1 -20
- package/template/core/engine/runtime/path-utils.mjs +20 -0
- package/template/core/engine/runtime/source-text-tools.d.mts +102 -0
- package/template/core/engine/runtime/source-text-tools.mjs +551 -16
- package/template/core/engine/runtime/source-workspace.mjs +4 -31
- package/template/core/package.json +1 -1
- package/template/core/src/main.tsx +2 -2
- package/template/core/src/openpress/{App.tsx → app/OpenPressApp.tsx} +25 -12
- package/template/core/src/openpress/{renderer.tsx → app/OpenPressRuntime.tsx} +10 -7
- package/template/core/src/openpress/app/index.ts +2 -0
- package/template/core/src/openpress/core/Frame.tsx +9 -11
- package/template/core/src/openpress/core/FrameContext.tsx +8 -3
- package/template/core/src/openpress/core/MdxArea.tsx +11 -12
- package/template/core/src/openpress/core/cn.ts +4 -0
- package/template/core/src/openpress/core/index.tsx +2 -1
- package/template/core/src/openpress/core/primitives.tsx +29 -8
- package/template/core/src/openpress/core/types.ts +8 -0
- package/template/core/src/openpress/{anchorMap.ts → document-model/anchorMapModel.ts} +1 -1
- package/template/core/src/openpress/{indexes.ts → document-model/documentIndexes.ts} +1 -1
- package/template/core/src/openpress/{types.ts → document-model/documentTypes.ts} +42 -0
- package/template/core/src/openpress/document-model/index.ts +6 -0
- package/template/core/src/openpress/document-model/objectEntityModel.ts +51 -0
- package/template/core/src/openpress/{projectIdentity.ts → document-model/projectIdentityModel.ts} +1 -1
- package/template/core/src/openpress/{reactDocumentMetadata.ts → document-model/reactDocumentMetadataModel.ts} +1 -1
- package/template/core/src/openpress/manuscript/index.tsx +49 -7
- package/template/core/src/openpress/{publicPage.tsx → reader/PublicReaderPage.tsx} +31 -51
- package/template/core/src/openpress/{workbenchPanels.tsx → reader/ReaderNavigationPanel.tsx} +6 -5
- package/template/core/src/openpress/reader/index.ts +10 -0
- package/template/core/src/openpress/reader/pageViewportScaleModel.ts +73 -0
- package/template/core/src/openpress/reader/readerTypes.ts +4 -0
- package/template/core/src/openpress/reader/usePageViewportScale.ts +119 -0
- package/template/core/src/openpress/reader/usePanelState.ts +56 -0
- package/template/core/src/openpress/reader/useReaderHashSync.ts +61 -0
- package/template/core/src/openpress/reader/useReaderKeyboardNav.ts +48 -0
- package/template/core/src/openpress/reader/useReaderRuntime.ts +146 -0
- package/template/core/src/openpress/reader/useReaderScrollAnchor.ts +64 -0
- package/template/core/src/openpress/shared/Panel.tsx +77 -0
- package/template/core/src/openpress/shared/index.ts +4 -0
- package/template/core/src/openpress/shared/numberUtils.ts +3 -0
- package/template/core/src/openpress/{runtimeMode.ts → shared/runtimeMode.ts} +0 -11
- package/template/core/src/openpress/workbench/Workbench.tsx +407 -0
- package/template/core/src/openpress/workbench/actions/DeploymentControl.tsx +157 -0
- package/template/core/src/openpress/workbench/actions/PageZoomControl.tsx +182 -0
- package/template/core/src/openpress/workbench/actions/SearchControl.tsx +345 -0
- package/template/core/src/openpress/workbench/actions/deploymentStatusModel.ts +112 -0
- package/template/core/src/openpress/workbench/actions/index.ts +5 -0
- package/template/core/src/openpress/workbench/actions/useDeploymentWorkbench.ts +136 -0
- package/template/core/src/openpress/workbench/dialog/WorkbenchDialog.tsx +72 -0
- package/template/core/src/openpress/workbench/dialog/index.ts +1 -0
- package/template/core/src/openpress/workbench/document/components/DocumentPanel.tsx +127 -0
- package/template/core/src/openpress/workbench/document/components/InlineSourceEditorLayer.tsx +207 -0
- package/template/core/src/openpress/workbench/document/components/ReaderStage.tsx +9 -0
- package/template/core/src/openpress/workbench/document/hooks/useDocumentWorkbenchModel.ts +34 -0
- package/template/core/src/openpress/workbench/document/hooks/useInlineDocumentEditor.ts +525 -0
- package/template/core/src/openpress/workbench/document/index.ts +10 -0
- package/template/core/src/openpress/workbench/index.ts +2 -0
- package/template/core/src/openpress/workbench/inspector/InlineInspectorLayer.tsx +459 -0
- package/template/core/src/openpress/workbench/inspector/index.ts +5 -0
- package/template/core/src/openpress/workbench/inspector/inlineCommentModel.ts +125 -0
- package/template/core/src/openpress/workbench/inspector/inspectorGeometryModel.ts +160 -0
- package/template/core/src/openpress/workbench/inspector/inspectorModel.ts +408 -0
- package/template/core/src/openpress/workbench/inspector/useInspectorComments.ts +248 -0
- package/template/core/src/openpress/workbench/mentions/MentionSuggestionList.tsx +41 -0
- package/template/core/src/openpress/workbench/mentions/index.ts +2 -0
- package/template/core/src/openpress/{composerMentions.ts → workbench/mentions/useComposerMentions.ts} +1 -4
- package/template/core/src/openpress/workbench/panels/Panel.tsx +1 -0
- package/template/core/src/openpress/workbench/panels/PendingCommentsPanel.tsx +76 -0
- package/template/core/src/openpress/workbench/panels/WorkbenchControlPanel.tsx +29 -0
- package/template/core/src/openpress/workbench/panels/index.ts +3 -0
- package/template/core/src/openpress/workbench/project/ProjectEntryPanel.tsx +523 -0
- package/template/core/src/openpress/workbench/project/ProjectPreviewDialog.tsx +35 -0
- package/template/core/src/openpress/workbench/project/index.ts +2 -0
- package/template/core/src/openpress/workbench/project/projectPreviewTypes.ts +11 -0
- package/template/core/src/openpress/workbench/shell/WorkbenchShell.tsx +167 -0
- package/template/core/src/openpress/workbench/shell/index.ts +1 -0
- package/template/core/src/openpress/workbench/workbenchFormatters.ts +120 -0
- package/template/core/src/openpress/workbench/workbenchTypes.ts +35 -0
- package/template/core/src/styles/openpress/print-route.css +0 -2
- package/template/core/src/styles/openpress/{project-workspace.css → project-preview-panel.css} +13 -407
- package/template/core/src/styles/openpress/public-viewer.css +25 -320
- package/template/core/src/styles/openpress/reader-runtime.css +243 -55
- package/template/core/src/styles/openpress/responsive.css +145 -270
- package/template/core/src/styles/openpress/workbench-panels.css +214 -178
- package/template/core/src/styles/openpress/workbench.css +986 -451
- package/template/core/src/styles/openpress.css +1 -1
- package/template/core/vite.config.ts +50 -0
- package/template/packs/academic-paper/document/chapters/01-introduction/content/01-introduction.mdx +26 -12
- package/template/packs/academic-paper/document/chapters/02-methods/content/01-methods.mdx +37 -17
- package/template/packs/academic-paper/document/chapters/03-results-and-discussion/content/01-results.mdx +34 -16
- package/template/packs/academic-paper/document/chapters/04-acknowledgment/content/01-acknowledgment.mdx +22 -8
- package/template/packs/academic-paper/document/chapters/05-references/content/01-references.mdx +20 -15
- package/template/packs/academic-paper/document/components/Page.tsx +26 -3
- package/template/packs/academic-paper/document/index.tsx +51 -59
- package/template/packs/academic-paper/document/media/figure-placeholder.svg +9 -0
- package/template/packs/academic-paper/document/theme/base/page-contract.css +30 -13
- package/template/packs/academic-paper/document/theme/base/typography.css +30 -33
- package/template/packs/academic-paper/document/theme/page-surfaces/cover.css +74 -47
- package/template/core/src/openpress/inspector.ts +0 -282
- package/template/core/src/openpress/projectWorkspace.tsx +0 -919
- package/template/core/src/openpress/readerRuntime.ts +0 -230
- package/template/core/src/openpress/workbench.tsx +0 -1265
- package/template/core/src/openpress/workbenchTypes.ts +0 -4
- /package/template/core/src/openpress/{readerPageRegistry.ts → reader/readerPageRegistry.ts} +0 -0
- /package/template/core/src/openpress/{pageRoute.ts → reader/readerPageRoute.ts} +0 -0
- /package/template/core/src/openpress/{readerScroll.ts → reader/readerScroll.ts} +0 -0
- /package/template/core/src/openpress/{readerState.ts → reader/readerStateModel.ts} +0 -0
- /package/template/core/src/openpress/{frameScheduler.ts → shared/frameScheduler.ts} +0 -0
- /package/template/core/src/openpress/{projectSources.ts → workbench/project/projectSourceModel.ts} +0 -0
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
import { useState, type CSSProperties } from "react";
|
|
2
|
+
import { Component as ComponentIcon, Images, Palette, type LucideIcon } from "lucide-react";
|
|
3
|
+
import type { BookmarkItem, BookmarkSubItem, MediaAssetItem } from "../../document-model";
|
|
4
|
+
import { projectSourceDirectoryPath, PROJECT_SOURCES } from "./projectSourceModel";
|
|
5
|
+
import type { BlockSource } from "../../document-model";
|
|
6
|
+
import type { DisplayPage } from "../../reader";
|
|
7
|
+
import { Panel } from "../panels/Panel";
|
|
8
|
+
import { ProjectPreviewDialog } from "./ProjectPreviewDialog";
|
|
9
|
+
import {
|
|
10
|
+
createProjectObjectEntityId,
|
|
11
|
+
type ProjectMentionItem,
|
|
12
|
+
type ProjectPanelPreview,
|
|
13
|
+
} from "./projectPreviewTypes";
|
|
14
|
+
|
|
15
|
+
export { createProjectObjectEntityId } from "./projectPreviewTypes";
|
|
16
|
+
export type { ProjectMentionItem, ProjectPanelPreview } from "./projectPreviewTypes";
|
|
17
|
+
|
|
18
|
+
export const PROJECT_VISUAL_SYSTEM_KEY = "visual-system";
|
|
19
|
+
export const PROJECT_IMAGE_GALLERY_KEY = "image-gallery";
|
|
20
|
+
export const PROJECT_COMPONENT_LIBRARY_KEY = "component-library";
|
|
21
|
+
|
|
22
|
+
export type ProjectComponentUsage = {
|
|
23
|
+
count: number;
|
|
24
|
+
pageIndexes: number[];
|
|
25
|
+
html: string;
|
|
26
|
+
previews: ProjectComponentPreview[];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type ProjectComponentPreview = {
|
|
30
|
+
name: string;
|
|
31
|
+
html: string;
|
|
32
|
+
pageIndex: number;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function createProjectComponentUsages(pages: DisplayPage[]): Map<string, ProjectComponentUsage> {
|
|
36
|
+
const usages = new Map<string, ProjectComponentUsage>();
|
|
37
|
+
pages.forEach((page) => {
|
|
38
|
+
const html = String(page.html ?? "");
|
|
39
|
+
const pageIndex = page.pageNumber - 1;
|
|
40
|
+
for (const block of extractRenderedComponentBlocks(html)) {
|
|
41
|
+
const current = usages.get(block.name) ?? { count: 0, pageIndexes: [], html: block.html, previews: [] };
|
|
42
|
+
current.count += 1;
|
|
43
|
+
if (!current.html) current.html = block.html;
|
|
44
|
+
if (!current.pageIndexes.includes(pageIndex)) current.pageIndexes.push(pageIndex);
|
|
45
|
+
current.previews.push({ name: block.name, html: block.html, pageIndex });
|
|
46
|
+
usages.set(block.name, current);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return usages;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function createProjectMentionItems(
|
|
53
|
+
mediaAssets: MediaAssetItem[],
|
|
54
|
+
componentUsages: Map<string, ProjectComponentUsage>,
|
|
55
|
+
bookmarks: BookmarkItem[] = [],
|
|
56
|
+
): ProjectMentionItem[] {
|
|
57
|
+
const referenceItems = createBookmarkMentionItems(bookmarks);
|
|
58
|
+
|
|
59
|
+
const mediaItems: ProjectMentionItem[] = mediaAssets.map((item) => ({
|
|
60
|
+
trigger: "@",
|
|
61
|
+
value: mediaMention(item.fileName),
|
|
62
|
+
label: item.fileName,
|
|
63
|
+
meta: item.usageCount > 0 ? `media · P${String(item.pageIndex + 1).padStart(2, "0")}` : "media · unused",
|
|
64
|
+
kind: "media",
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
const componentItems: ProjectMentionItem[] = Array.from(componentUsages.entries())
|
|
68
|
+
.sort(([a], [b]) => a.localeCompare(b, "zh-Hant"))
|
|
69
|
+
.map(([name, usage]) => ({
|
|
70
|
+
trigger: "@",
|
|
71
|
+
value: componentMention(name),
|
|
72
|
+
label: name,
|
|
73
|
+
meta: `component · ${usage.count}`,
|
|
74
|
+
kind: "component",
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
return [...PROJECT_SKILL_MENTIONS, ...referenceItems, ...mediaItems, ...componentItems];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function ProjectEntryPanel({
|
|
81
|
+
mediaAssets,
|
|
82
|
+
componentUsages,
|
|
83
|
+
mentionItems,
|
|
84
|
+
currentSource,
|
|
85
|
+
onCommentSubmitted,
|
|
86
|
+
}: {
|
|
87
|
+
mediaAssets: MediaAssetItem[];
|
|
88
|
+
componentUsages: Map<string, ProjectComponentUsage>;
|
|
89
|
+
mentionItems: ProjectMentionItem[];
|
|
90
|
+
currentSource: BlockSource | undefined;
|
|
91
|
+
onCommentSubmitted?: () => void | Promise<void>;
|
|
92
|
+
}) {
|
|
93
|
+
const [preview, setPreview] = useState<ProjectPanelPreview | null>(null);
|
|
94
|
+
const componentItems = Array.from(componentUsages.entries())
|
|
95
|
+
.sort(([a], [b]) => a.localeCompare(b, "zh-Hant"))
|
|
96
|
+
.slice(0, 8);
|
|
97
|
+
const mediaItems = mediaAssets
|
|
98
|
+
.slice(0, 10)
|
|
99
|
+
.map((item) => ({
|
|
100
|
+
fileName: item.fileName,
|
|
101
|
+
src: item.src,
|
|
102
|
+
mention: mediaMention(item.fileName),
|
|
103
|
+
meta: item.usageCount > 0 ? `P${String(item.pageIndex + 1).padStart(2, "0")}` : "unused",
|
|
104
|
+
}));
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<Panel className="openpress-project-panel openpress-panel--compact" aria-label="Project tools">
|
|
108
|
+
<Panel.Section className="openpress-project-tool-block" aria-label="媒體素材">
|
|
109
|
+
<Panel.SectionTitle>Media</Panel.SectionTitle>
|
|
110
|
+
{mediaItems.length > 0 ? (
|
|
111
|
+
<div className="openpress-project-asset-list">
|
|
112
|
+
{mediaItems.map((item) => (
|
|
113
|
+
<button
|
|
114
|
+
type="button"
|
|
115
|
+
className="openpress-project-asset"
|
|
116
|
+
data-openpress-object-id={createProjectObjectEntityId("media", item.fileName)}
|
|
117
|
+
key={`${item.src}-${item.fileName}`}
|
|
118
|
+
onClick={() => setPreview({ kind: "media", title: item.fileName, src: item.src })}
|
|
119
|
+
>
|
|
120
|
+
<span className="openpress-project-asset-thumb">
|
|
121
|
+
<img src={item.src} alt="" loading="lazy" />
|
|
122
|
+
</span>
|
|
123
|
+
<span className="openpress-project-asset-body">
|
|
124
|
+
<strong>{item.fileName}</strong>
|
|
125
|
+
</span>
|
|
126
|
+
</button>
|
|
127
|
+
))}
|
|
128
|
+
</div>
|
|
129
|
+
) : (
|
|
130
|
+
<Panel.Empty>尚無圖片</Panel.Empty>
|
|
131
|
+
)}
|
|
132
|
+
</Panel.Section>
|
|
133
|
+
|
|
134
|
+
<Panel.Section className="openpress-project-tool-block" aria-label="Components">
|
|
135
|
+
<Panel.SectionTitle>Components</Panel.SectionTitle>
|
|
136
|
+
{componentItems.length > 0 ? (
|
|
137
|
+
<div className="openpress-project-component-mention-list">
|
|
138
|
+
{componentItems.map(([name, usage]) => (
|
|
139
|
+
<button
|
|
140
|
+
type="button"
|
|
141
|
+
data-openpress-object-id={createProjectObjectEntityId("component", name)}
|
|
142
|
+
key={name}
|
|
143
|
+
onClick={() => setPreview({ kind: "component", title: name, html: usage.html })}
|
|
144
|
+
>
|
|
145
|
+
<ComponentIcon aria-hidden="true" />
|
|
146
|
+
<span>
|
|
147
|
+
<strong>{name}</strong>
|
|
148
|
+
</span>
|
|
149
|
+
</button>
|
|
150
|
+
))}
|
|
151
|
+
</div>
|
|
152
|
+
) : (
|
|
153
|
+
<Panel.Empty>尚無 component</Panel.Empty>
|
|
154
|
+
)}
|
|
155
|
+
</Panel.Section>
|
|
156
|
+
{preview ? (
|
|
157
|
+
<ProjectPreviewDialog
|
|
158
|
+
key={`${preview.kind}-${preview.title}`}
|
|
159
|
+
preview={preview}
|
|
160
|
+
onClose={() => setPreview(null)}
|
|
161
|
+
/>
|
|
162
|
+
) : null}
|
|
163
|
+
</Panel>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
export function ProjectPreviewPanel({
|
|
169
|
+
mediaAssets,
|
|
170
|
+
componentUsages,
|
|
171
|
+
selectedKey,
|
|
172
|
+
}: {
|
|
173
|
+
mediaAssets: MediaAssetItem[];
|
|
174
|
+
componentUsages: Map<string, ProjectComponentUsage>;
|
|
175
|
+
selectedKey: string | null;
|
|
176
|
+
}) {
|
|
177
|
+
if (!selectedKey || selectedKey === PROJECT_VISUAL_SYSTEM_KEY) {
|
|
178
|
+
return <ProjectVisualSystem />;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (selectedKey === PROJECT_IMAGE_GALLERY_KEY) {
|
|
182
|
+
return <ProjectImageGallery mediaAssets={mediaAssets} />;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (selectedKey === PROJECT_COMPONENT_LIBRARY_KEY) {
|
|
186
|
+
return <ProjectComponentLibrary usages={componentUsages} />;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return <ProjectVisualSystem />;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function ProjectPanelButton({
|
|
193
|
+
icon: Icon,
|
|
194
|
+
label,
|
|
195
|
+
meta,
|
|
196
|
+
active,
|
|
197
|
+
onClick,
|
|
198
|
+
}: {
|
|
199
|
+
icon: LucideIcon;
|
|
200
|
+
label: string;
|
|
201
|
+
meta: string;
|
|
202
|
+
active: boolean;
|
|
203
|
+
onClick: () => void;
|
|
204
|
+
}) {
|
|
205
|
+
return (
|
|
206
|
+
<button
|
|
207
|
+
type="button"
|
|
208
|
+
className={`bookmark-item bookmark-h2 openpress-project-entry${active ? " is-active" : ""}`}
|
|
209
|
+
aria-pressed={active}
|
|
210
|
+
onClick={onClick}
|
|
211
|
+
>
|
|
212
|
+
<span className="bookmark-index openpress-project-entry-icon"><Icon aria-hidden="true" /></span>
|
|
213
|
+
<span className="bookmark-title">
|
|
214
|
+
<span>{label}</span>
|
|
215
|
+
<small>{meta}</small>
|
|
216
|
+
</span>
|
|
217
|
+
</button>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function ProjectVisualSystem() {
|
|
222
|
+
return (
|
|
223
|
+
<section className="openpress-project-preview-panel" aria-label="專案">
|
|
224
|
+
<article className="openpress-project-visual-system" aria-label="Visual System">
|
|
225
|
+
<ProjectSectionHeader title="Visual System" minimal />
|
|
226
|
+
|
|
227
|
+
<div className="openpress-project-visual-grid">
|
|
228
|
+
<section className="openpress-project-visual-card openpress-project-visual-card--typography" aria-label="Typography">
|
|
229
|
+
<header>
|
|
230
|
+
<span>Typography</span>
|
|
231
|
+
<strong>閱讀層級</strong>
|
|
232
|
+
</header>
|
|
233
|
+
<div className="openpress-project-type-specimen">
|
|
234
|
+
<p className="openpress-project-type-kicker">Course Notes</p>
|
|
235
|
+
<h2>Data Structures</h2>
|
|
236
|
+
<h3>Linked List 與 Tree Traversal</h3>
|
|
237
|
+
<h4>Pointer / Node / Recursive Thinking</h4>
|
|
238
|
+
<p>以 C/C++ 實作資料結構,整理概念、表示法與操作流程。</p>
|
|
239
|
+
<code>struct Node *next = head;</code>
|
|
240
|
+
</div>
|
|
241
|
+
</section>
|
|
242
|
+
|
|
243
|
+
<section className="openpress-project-visual-card" aria-label="Color Palette">
|
|
244
|
+
<header>
|
|
245
|
+
<span>Palette</span>
|
|
246
|
+
<strong>色票配置</strong>
|
|
247
|
+
</header>
|
|
248
|
+
<div className="openpress-project-swatch-grid">
|
|
249
|
+
{PROJECT_COLOR_SWATCHES.map((item) => (
|
|
250
|
+
<div className="openpress-project-swatch" key={item.token}>
|
|
251
|
+
<span
|
|
252
|
+
className="openpress-project-swatch-chip"
|
|
253
|
+
style={{ "--openpress-project-swatch": `var(${item.token})` } as CSSProperties}
|
|
254
|
+
aria-hidden="true"
|
|
255
|
+
/>
|
|
256
|
+
<strong>{item.label}</strong>
|
|
257
|
+
<code>{item.token.replace("--openpress-", "")}</code>
|
|
258
|
+
</div>
|
|
259
|
+
))}
|
|
260
|
+
</div>
|
|
261
|
+
</section>
|
|
262
|
+
|
|
263
|
+
<section className="openpress-project-visual-card openpress-project-visual-card--surfaces" aria-label="Surfaces">
|
|
264
|
+
<header>
|
|
265
|
+
<span>Surfaces</span>
|
|
266
|
+
<strong>區塊背景</strong>
|
|
267
|
+
</header>
|
|
268
|
+
<div className="openpress-project-surface-preview">
|
|
269
|
+
<div className="openpress-project-surface-paper">
|
|
270
|
+
<span>Page paper</span>
|
|
271
|
+
</div>
|
|
272
|
+
<div className="openpress-project-surface-block">
|
|
273
|
+
<span>Figure / Code block</span>
|
|
274
|
+
</div>
|
|
275
|
+
</div>
|
|
276
|
+
</section>
|
|
277
|
+
</div>
|
|
278
|
+
</article>
|
|
279
|
+
</section>
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function ProjectComponentLibrary({
|
|
284
|
+
usages,
|
|
285
|
+
}: {
|
|
286
|
+
usages: Map<string, ProjectComponentUsage>;
|
|
287
|
+
}) {
|
|
288
|
+
const previewItems = createComponentPreviewItems(usages);
|
|
289
|
+
return (
|
|
290
|
+
<section className="openpress-project-preview-panel" aria-label="專案">
|
|
291
|
+
<article className="openpress-project-component-viewer" aria-label={PROJECT_SOURCES.components.label}>
|
|
292
|
+
<ProjectSectionHeader
|
|
293
|
+
title="Rendered Components"
|
|
294
|
+
description="文件目前實際渲染出的 component、圖表與示意圖狀態。"
|
|
295
|
+
stats={[
|
|
296
|
+
["Kinds", String(usages.size)],
|
|
297
|
+
["Renders", String(previewItems.length)],
|
|
298
|
+
]}
|
|
299
|
+
/>
|
|
300
|
+
{previewItems.length > 0 ? (
|
|
301
|
+
<div className="openpress-project-component-list" aria-label="rendered content block list">
|
|
302
|
+
{previewItems.map((item) => (
|
|
303
|
+
<figure className="openpress-project-component-preview-row" key={`${item.name}-${item.index}`}>
|
|
304
|
+
<figcaption>
|
|
305
|
+
<span>{item.name}</span>
|
|
306
|
+
<small>P{String(item.preview.pageIndex + 1).padStart(2, "0")}</small>
|
|
307
|
+
</figcaption>
|
|
308
|
+
<div
|
|
309
|
+
className="openpress-project-component-preview"
|
|
310
|
+
dangerouslySetInnerHTML={{ __html: item.preview.html }}
|
|
311
|
+
/>
|
|
312
|
+
</figure>
|
|
313
|
+
))}
|
|
314
|
+
</div>
|
|
315
|
+
) : (
|
|
316
|
+
<p className="openpress-project-empty">目前文件尚未渲染任何內容區塊。</p>
|
|
317
|
+
)}
|
|
318
|
+
</article>
|
|
319
|
+
</section>
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function ProjectImageGallery({
|
|
324
|
+
mediaAssets,
|
|
325
|
+
}: {
|
|
326
|
+
mediaAssets: MediaAssetItem[];
|
|
327
|
+
}) {
|
|
328
|
+
const usedCount = mediaAssets.filter((item) => item.usageCount > 0).length;
|
|
329
|
+
const unreferencedAssets = mediaAssets.filter((item) => item.usageCount === 0);
|
|
330
|
+
const referencedAssets = mediaAssets.filter((item) => item.usageCount > 0);
|
|
331
|
+
return (
|
|
332
|
+
<section className="openpress-project-preview-panel" aria-label="專案">
|
|
333
|
+
<article className="openpress-project-gallery-viewer" aria-label="Image Gallery">
|
|
334
|
+
<ProjectSectionHeader
|
|
335
|
+
title="Media Library"
|
|
336
|
+
description={projectSourceDirectoryPath("media")}
|
|
337
|
+
stats={[
|
|
338
|
+
["Files", String(mediaAssets.length)],
|
|
339
|
+
["Used", String(usedCount)],
|
|
340
|
+
]}
|
|
341
|
+
/>
|
|
342
|
+
{mediaAssets.length > 0 ? (
|
|
343
|
+
<div className="openpress-project-media-sections" aria-label="media gallery">
|
|
344
|
+
<ProjectMediaSection title="未引用" assets={unreferencedAssets} />
|
|
345
|
+
<ProjectMediaSection title="已引用" assets={referencedAssets} />
|
|
346
|
+
</div>
|
|
347
|
+
) : (
|
|
348
|
+
<p className="openpress-project-empty">{projectSourceDirectoryPath("media")} 尚未有可預覽素材。</p>
|
|
349
|
+
)}
|
|
350
|
+
</article>
|
|
351
|
+
</section>
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function ProjectSectionHeader({
|
|
356
|
+
title,
|
|
357
|
+
description,
|
|
358
|
+
stats,
|
|
359
|
+
minimal = false,
|
|
360
|
+
}: {
|
|
361
|
+
title: string;
|
|
362
|
+
description?: string;
|
|
363
|
+
stats?: Array<[string, string]>;
|
|
364
|
+
minimal?: boolean;
|
|
365
|
+
}) {
|
|
366
|
+
return (
|
|
367
|
+
<header className={`openpress-project-section-header${minimal ? " openpress-project-section-header--minimal" : ""}`}>
|
|
368
|
+
<div>
|
|
369
|
+
<h2>{title}</h2>
|
|
370
|
+
{description ? <span>{description}</span> : null}
|
|
371
|
+
</div>
|
|
372
|
+
{!minimal && stats?.length ? (
|
|
373
|
+
<dl>
|
|
374
|
+
{stats.map(([label, value]) => (
|
|
375
|
+
<div key={label}>
|
|
376
|
+
<dt>{label}</dt>
|
|
377
|
+
<dd>{value}</dd>
|
|
378
|
+
</div>
|
|
379
|
+
))}
|
|
380
|
+
</dl>
|
|
381
|
+
) : null}
|
|
382
|
+
</header>
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function ProjectMediaSection({
|
|
387
|
+
title,
|
|
388
|
+
assets,
|
|
389
|
+
}: {
|
|
390
|
+
title: string;
|
|
391
|
+
assets: MediaAssetItem[];
|
|
392
|
+
}) {
|
|
393
|
+
return (
|
|
394
|
+
<section className="openpress-project-media-section" aria-label={title}>
|
|
395
|
+
<header className="openpress-project-media-section-header">
|
|
396
|
+
<h3>{title}</h3>
|
|
397
|
+
</header>
|
|
398
|
+
{assets.length > 0 ? (
|
|
399
|
+
<div className="openpress-project-media-gallery">
|
|
400
|
+
{assets.map((item) => (
|
|
401
|
+
<figure className="openpress-project-media-card" data-unused={item.usageCount === 0 ? "true" : "false"} key={item.id}>
|
|
402
|
+
<img src={item.src} alt="" loading="lazy" />
|
|
403
|
+
<figcaption>
|
|
404
|
+
<strong>{item.fileName}</strong>
|
|
405
|
+
</figcaption>
|
|
406
|
+
</figure>
|
|
407
|
+
))}
|
|
408
|
+
</div>
|
|
409
|
+
) : (
|
|
410
|
+
<p className="openpress-project-media-section-empty">沒有{title}圖片。</p>
|
|
411
|
+
)}
|
|
412
|
+
</section>
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function createComponentPreviewItems(usages: Map<string, ProjectComponentUsage>) {
|
|
417
|
+
return Array.from(usages.entries())
|
|
418
|
+
.flatMap(([name, usage]) => usage.previews.map((preview, index) => ({ name, preview, index })))
|
|
419
|
+
.filter((item) => Boolean(item.preview.html))
|
|
420
|
+
.sort((a, b) => {
|
|
421
|
+
const pageDelta = a.preview.pageIndex - b.preview.pageIndex;
|
|
422
|
+
return pageDelta || a.name.localeCompare(b.name, "zh-Hant") || a.index - b.index;
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function extractRenderedComponentBlocks(html: string) {
|
|
427
|
+
const blocks: Array<{ name: string; html: string }> = [];
|
|
428
|
+
const openTagPattern = /<(figure|section|article|div)\b[^>]*data-openpress-component="([^"]+)"[^>]*>/g;
|
|
429
|
+
for (const match of html.matchAll(openTagPattern)) {
|
|
430
|
+
const tagName = match[1];
|
|
431
|
+
const componentName = match[2];
|
|
432
|
+
const start = match.index ?? 0;
|
|
433
|
+
const end = findClosingTagEnd(html, tagName, start + match[0].length);
|
|
434
|
+
blocks.push({
|
|
435
|
+
name: componentName,
|
|
436
|
+
html: end > start ? html.slice(start, end) : match[0],
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
return blocks;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function findClosingTagEnd(html: string, tagName: string, fromIndex: number) {
|
|
443
|
+
const tagPattern = new RegExp(`</?${tagName}\\b[^>]*>`, "gi");
|
|
444
|
+
tagPattern.lastIndex = fromIndex;
|
|
445
|
+
let depth = 1;
|
|
446
|
+
let match: RegExpExecArray | null;
|
|
447
|
+
while ((match = tagPattern.exec(html))) {
|
|
448
|
+
if (match[0].startsWith("</")) {
|
|
449
|
+
depth -= 1;
|
|
450
|
+
} else if (!match[0].endsWith("/>")) {
|
|
451
|
+
depth += 1;
|
|
452
|
+
}
|
|
453
|
+
if (depth === 0) return tagPattern.lastIndex;
|
|
454
|
+
}
|
|
455
|
+
return -1;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function mediaMention(fileName: string) {
|
|
459
|
+
return `@media/${fileName}`;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function componentMention(name: string) {
|
|
463
|
+
return `@component/${name}`;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function createBookmarkMentionItems(bookmarks: BookmarkItem[]): ProjectMentionItem[] {
|
|
467
|
+
return bookmarks
|
|
468
|
+
.filter((item) => item.label !== "00")
|
|
469
|
+
.flatMap((chapter) => [
|
|
470
|
+
bookmarkMentionItem("chapter", chapter),
|
|
471
|
+
...chapter.subs.map((section) => bookmarkMentionItem("section", section)),
|
|
472
|
+
]);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function bookmarkMentionItem(kind: "chapter" | "section", item: BookmarkItem | BookmarkSubItem): ProjectMentionItem {
|
|
476
|
+
const label = item.label ? `${item.label} ` : "";
|
|
477
|
+
return {
|
|
478
|
+
trigger: "@",
|
|
479
|
+
value: `@${kind}/${bookmarkMentionSlug(item)}`,
|
|
480
|
+
label: `${label}${item.title}`,
|
|
481
|
+
meta: `${kind === "chapter" ? "chapter" : "section"} · P${String(item.pageIndex + 1).padStart(2, "0")}`,
|
|
482
|
+
kind,
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function bookmarkMentionSlug(item: BookmarkItem | BookmarkSubItem) {
|
|
487
|
+
const parts = [item.label, item.title]
|
|
488
|
+
.filter(Boolean)
|
|
489
|
+
.map((part) => mentionSlugPart(String(part)));
|
|
490
|
+
return parts.filter(Boolean).join("-") || item.id;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function mentionSlugPart(value: string) {
|
|
494
|
+
return value
|
|
495
|
+
.trim()
|
|
496
|
+
.replace(/\s+/g, "-")
|
|
497
|
+
.replace(/[^\p{L}\p{N}._-]+/gu, "-")
|
|
498
|
+
.replace(/-+/g, "-")
|
|
499
|
+
.replace(/^-|-$/g, "");
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
const PROJECT_SKILL_MENTIONS: ProjectMentionItem[] = [
|
|
504
|
+
{ trigger: "/", value: "/insert-image", label: "insert-image", meta: "skill", kind: "skill" },
|
|
505
|
+
{ trigger: "/", value: "/redraw-figure", label: "redraw-figure", meta: "skill", kind: "skill" },
|
|
506
|
+
{ trigger: "/", value: "/rewrite-section", label: "rewrite-section", meta: "skill", kind: "skill" },
|
|
507
|
+
{ trigger: "/", value: "/apply-comments", label: "apply-comments", meta: "skill", kind: "skill" },
|
|
508
|
+
{ trigger: "/", value: "/apply-style", label: "apply-style", meta: "skill", kind: "skill" },
|
|
509
|
+
{ trigger: "/", value: "/fix-code", label: "fix-code", meta: "skill", kind: "skill" },
|
|
510
|
+
];
|
|
511
|
+
|
|
512
|
+
const PROJECT_COLOR_SWATCHES = [
|
|
513
|
+
{ label: "Document", token: "--openpress-color-document" },
|
|
514
|
+
{ label: "Paper", token: "--openpress-color-paper" },
|
|
515
|
+
{ label: "Ink", token: "--openpress-color-ink" },
|
|
516
|
+
{ label: "Body", token: "--openpress-color-body" },
|
|
517
|
+
{ label: "Muted", token: "--openpress-color-muted" },
|
|
518
|
+
{ label: "Subtle", token: "--openpress-color-subtle" },
|
|
519
|
+
{ label: "Line", token: "--openpress-color-line" },
|
|
520
|
+
{ label: "Block", token: "--openpress-color-block" },
|
|
521
|
+
{ label: "Info", token: "--openpress-color-info" },
|
|
522
|
+
{ label: "Green", token: "--openpress-color-green" },
|
|
523
|
+
];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useId } from "react";
|
|
2
|
+
import { WorkbenchDialog } from "../dialog";
|
|
3
|
+
import type { ProjectPanelPreview } from "./projectPreviewTypes";
|
|
4
|
+
import { createProjectObjectEntityId } from "./projectPreviewTypes";
|
|
5
|
+
|
|
6
|
+
export interface ProjectPreviewDialogProps {
|
|
7
|
+
preview: ProjectPanelPreview;
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function ProjectPreviewDialog({ preview, onClose }: ProjectPreviewDialogProps) {
|
|
12
|
+
const titleId = useId();
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<WorkbenchDialog
|
|
16
|
+
titleId={titleId}
|
|
17
|
+
title={preview.title}
|
|
18
|
+
className="openpress-project-preview-dialog"
|
|
19
|
+
closeLabel="關閉預覽"
|
|
20
|
+
onClose={onClose}
|
|
21
|
+
>
|
|
22
|
+
<div
|
|
23
|
+
className="openpress-project-preview-dialog__body"
|
|
24
|
+
data-preview-kind={preview.kind}
|
|
25
|
+
data-openpress-object-id={createProjectObjectEntityId(preview.kind, preview.title)}
|
|
26
|
+
>
|
|
27
|
+
{preview.kind === "media" ? (
|
|
28
|
+
<img src={preview.src} alt="" />
|
|
29
|
+
) : (
|
|
30
|
+
<div dangerouslySetInnerHTML={{ __html: preview.html }} />
|
|
31
|
+
)}
|
|
32
|
+
</div>
|
|
33
|
+
</WorkbenchDialog>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ComposerMentionItem } from "../mentions";
|
|
2
|
+
|
|
3
|
+
export type ProjectMentionItem = ComposerMentionItem;
|
|
4
|
+
|
|
5
|
+
export type ProjectPanelPreview =
|
|
6
|
+
| { kind: "media"; title: string; src: string }
|
|
7
|
+
| { kind: "component"; title: string; html: string };
|
|
8
|
+
|
|
9
|
+
export function createProjectObjectEntityId(kind: "media" | "component", name: string) {
|
|
10
|
+
return [kind, encodeURIComponent(name)].join(":");
|
|
11
|
+
}
|