@open-press/core 1.2.0 → 1.2.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.
- package/engine/cli.mjs +1 -1
- package/engine/commands/_shared.mjs +10 -5
- package/engine/commands/deploy.mjs +19 -4
- package/engine/output/static-server.mjs +16 -9
- package/package.json +1 -1
- package/src/openpress/app/OpenPressApp.tsx +4 -1
- package/src/openpress/app/OpenPressRuntime.tsx +26 -1
- package/src/openpress/reader/PageThumbnailsPanel.tsx +28 -5
- package/src/openpress/reader/SlidePresentationPage.tsx +36 -19
- package/src/openpress/reader/SlidePublicPage.tsx +332 -0
- package/src/openpress/reader/index.ts +1 -0
- package/src/openpress/reader/pageViewportScaleModel.ts +5 -3
- package/src/openpress/reader/usePageViewportScale.ts +9 -5
- package/src/openpress/workbench/Workbench.tsx +46 -164
- package/src/openpress/workbench/actions/DeploymentControl.tsx +1 -1
- package/src/openpress/workbench/actions/ExportControl.tsx +267 -0
- package/src/openpress/workbench/actions/index.ts +1 -1
- package/src/openpress/workbench/actions/useDeploymentWorkbench.ts +7 -2
- package/src/openpress/workbench/hooks/useWorkbenchNavigation.ts +42 -0
- package/src/openpress/workbench/project/ProjectEntryPanel.tsx +2 -278
- package/src/openpress/workbench/shell/WorkbenchToolbarActions.tsx +206 -0
- package/src/styles/openpress/app-shell.css +0 -83
- package/src/styles/openpress/print-route.css +1 -3
- package/src/styles/openpress/project-preview-panel.css +5 -783
- package/src/styles/openpress/public-viewer.css +7 -249
- package/src/styles/openpress/reader-runtime.css +0 -274
- package/src/styles/openpress/slide-presenter.css +150 -0
- package/src/styles/openpress/slide-public-viewer.css +222 -0
- package/src/styles/openpress/workbench-dialog.css +267 -0
- package/src/styles/openpress/workbench-export.css +154 -0
- package/src/styles/openpress/workbench-inline-editor.css +128 -0
- package/src/styles/openpress/workbench-panels.css +0 -88
- package/src/styles/openpress/workbench-search.css +257 -0
- package/src/styles/openpress/workbench-toolbar.css +422 -0
- package/src/styles/openpress/workbench.css +34 -1263
- package/src/styles/openpress/workspace-gallery.css +0 -5
- package/src/styles/openpress.css +7 -1
- package/vite.config.ts +16 -9
- package/src/openpress/workbench/actions/ExportImageControl.tsx +0 -96
- package/src/styles/openpress/media-workspace.css +0 -230
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
2
|
+
import { ChevronDown, Download, FileDown, FileText, Image as ImageIcon } from "lucide-react";
|
|
3
|
+
import { toPng } from "html-to-image";
|
|
4
|
+
import type { HtmlPageBlock, Theme } from "../../document-model";
|
|
5
|
+
import { PageThumbnails } from "../../reader";
|
|
6
|
+
import { WorkbenchDialog } from "../dialog";
|
|
7
|
+
|
|
8
|
+
type ExportDialog = "none" | "pdf" | "png";
|
|
9
|
+
type PngExportStatus = "idle" | "exporting" | "done" | "error";
|
|
10
|
+
|
|
11
|
+
export function ExportControl({
|
|
12
|
+
pages,
|
|
13
|
+
currentPageIndex,
|
|
14
|
+
pressTitle,
|
|
15
|
+
theme,
|
|
16
|
+
pdfHref,
|
|
17
|
+
onExportPdf,
|
|
18
|
+
pdfDisabled = false,
|
|
19
|
+
pdfLabel,
|
|
20
|
+
pdfStatusMessage,
|
|
21
|
+
pdfActionStatus,
|
|
22
|
+
}: {
|
|
23
|
+
pages: HtmlPageBlock[];
|
|
24
|
+
currentPageIndex: number;
|
|
25
|
+
pressTitle: string;
|
|
26
|
+
theme?: Theme;
|
|
27
|
+
pdfHref?: string;
|
|
28
|
+
onExportPdf?: () => void;
|
|
29
|
+
pdfDisabled?: boolean;
|
|
30
|
+
pdfLabel?: string;
|
|
31
|
+
pdfStatusMessage?: string | null;
|
|
32
|
+
pdfActionStatus?: string;
|
|
33
|
+
}) {
|
|
34
|
+
const menuId = useId();
|
|
35
|
+
const pdfTitleId = useId();
|
|
36
|
+
const pngTitleId = useId();
|
|
37
|
+
const rootRef = useRef<HTMLDivElement | null>(null);
|
|
38
|
+
const [dropdownOpen, setDropdownOpen] = useState(false);
|
|
39
|
+
const [activeDialog, setActiveDialog] = useState<ExportDialog>("none");
|
|
40
|
+
const [pngPageIndex, setPngPageIndex] = useState(currentPageIndex);
|
|
41
|
+
const [selectedPngPageIndexes, setSelectedPngPageIndexes] = useState<Set<number>>(() => new Set());
|
|
42
|
+
const [pngStatus, setPngStatus] = useState<PngExportStatus>("idle");
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!dropdownOpen) return undefined;
|
|
46
|
+
const handlePointerDown = (event: PointerEvent) => {
|
|
47
|
+
if (event.target instanceof Node && rootRef.current?.contains(event.target)) return;
|
|
48
|
+
setDropdownOpen(false);
|
|
49
|
+
};
|
|
50
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
51
|
+
if (event.key === "Escape") setDropdownOpen(false);
|
|
52
|
+
};
|
|
53
|
+
window.addEventListener("pointerdown", handlePointerDown);
|
|
54
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
55
|
+
return () => {
|
|
56
|
+
window.removeEventListener("pointerdown", handlePointerDown);
|
|
57
|
+
window.removeEventListener("keydown", handleKeyDown);
|
|
58
|
+
};
|
|
59
|
+
}, [dropdownOpen]);
|
|
60
|
+
|
|
61
|
+
const openPdf = () => { setDropdownOpen(false); setActiveDialog("pdf"); };
|
|
62
|
+
const openPng = () => {
|
|
63
|
+
setDropdownOpen(false);
|
|
64
|
+
setPngPageIndex(currentPageIndex);
|
|
65
|
+
setSelectedPngPageIndexes(createAllPageIndexSet(pages));
|
|
66
|
+
setPngStatus("idle");
|
|
67
|
+
setActiveDialog("png");
|
|
68
|
+
};
|
|
69
|
+
const closeDialog = () => setActiveDialog("none");
|
|
70
|
+
|
|
71
|
+
const togglePngPage = (pageIndex: number) => {
|
|
72
|
+
setSelectedPngPageIndexes((current) => {
|
|
73
|
+
const next = new Set(current);
|
|
74
|
+
if (next.has(pageIndex)) next.delete(pageIndex);
|
|
75
|
+
else next.add(pageIndex);
|
|
76
|
+
return next;
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const selectAllPngPages = () => setSelectedPngPageIndexes(createAllPageIndexSet(pages));
|
|
81
|
+
const clearPngPages = () => setSelectedPngPageIndexes(new Set());
|
|
82
|
+
|
|
83
|
+
const handleExportPng = useCallback(async () => {
|
|
84
|
+
if (pngStatus === "exporting") return;
|
|
85
|
+
const pageIndexes = pages
|
|
86
|
+
.map((page) => page.pageNumber - 1)
|
|
87
|
+
.filter((pageIndex) => selectedPngPageIndexes.has(pageIndex));
|
|
88
|
+
if (pageIndexes.length === 0) return;
|
|
89
|
+
setPngStatus("exporting");
|
|
90
|
+
try {
|
|
91
|
+
const safeTitle = sanitizeFilename(pressTitle) || "openpress";
|
|
92
|
+
for (const pageIndex of pageIndexes) {
|
|
93
|
+
const pageEl = typeof window === "undefined"
|
|
94
|
+
? null
|
|
95
|
+
: window.document.querySelector<HTMLElement>(`[data-openpress-page-index="${pageIndex}"]`);
|
|
96
|
+
if (!pageEl) throw new Error(`找不到第 ${pageIndex + 1} 頁元素`);
|
|
97
|
+
const dataUrl = await toPng(pageEl, { pixelRatio: 2, cacheBust: true, backgroundColor: "#ffffff" });
|
|
98
|
+
const safePage = String(pageIndex + 1).padStart(2, "0");
|
|
99
|
+
const link = window.document.createElement("a");
|
|
100
|
+
link.href = dataUrl;
|
|
101
|
+
link.download = `${safeTitle}-${safePage}.png`;
|
|
102
|
+
window.document.body.appendChild(link);
|
|
103
|
+
link.click();
|
|
104
|
+
link.remove();
|
|
105
|
+
}
|
|
106
|
+
setPngStatus("done");
|
|
107
|
+
window.setTimeout(() => setPngStatus("idle"), 1600);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error("[openpress] PNG export failed", error);
|
|
110
|
+
setPngStatus("error");
|
|
111
|
+
window.setTimeout(() => setPngStatus("idle"), 2400);
|
|
112
|
+
}
|
|
113
|
+
}, [pages, pngStatus, pressTitle, selectedPngPageIndexes]);
|
|
114
|
+
|
|
115
|
+
const hasPdf = Boolean(pdfHref ?? onExportPdf);
|
|
116
|
+
const selectedPngCount = selectedPngPageIndexes.size;
|
|
117
|
+
const pngButtonLabel = pngStatus === "exporting" ? "匯出中…"
|
|
118
|
+
: pngStatus === "done" ? "已下載"
|
|
119
|
+
: pngStatus === "error" ? "匯出失敗"
|
|
120
|
+
: selectedPngCount === 0 ? "請選擇圖片"
|
|
121
|
+
: `匯出 ${selectedPngCount} 張`;
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<div ref={rootRef} className="openpress-workbench-zoom-control-wrap" data-openpress-export-control>
|
|
125
|
+
<button
|
|
126
|
+
type="button"
|
|
127
|
+
className="openpress-workbench-zoom-control"
|
|
128
|
+
aria-label="匯出"
|
|
129
|
+
title="匯出"
|
|
130
|
+
aria-haspopup="menu"
|
|
131
|
+
aria-expanded={dropdownOpen}
|
|
132
|
+
aria-controls={dropdownOpen ? menuId : undefined}
|
|
133
|
+
onClick={() => setDropdownOpen((v) => !v)}
|
|
134
|
+
>
|
|
135
|
+
<FileDown aria-hidden="true" />
|
|
136
|
+
<span>匯出</span>
|
|
137
|
+
<ChevronDown className="openpress-workbench-zoom-control__chevron" aria-hidden="true" />
|
|
138
|
+
</button>
|
|
139
|
+
|
|
140
|
+
{dropdownOpen ? (
|
|
141
|
+
<div id={menuId} className="openpress-workbench-zoom-menu" role="menu" aria-label="匯出選項">
|
|
142
|
+
<div className="openpress-workbench-zoom-menu__section" role="group">
|
|
143
|
+
{hasPdf ? (
|
|
144
|
+
<button type="button" className="openpress-workbench-zoom-menu__item" role="menuitem" onClick={openPdf}>
|
|
145
|
+
<span className="openpress-workbench-zoom-menu__check" aria-hidden="true" />
|
|
146
|
+
<FileText aria-hidden="true" />
|
|
147
|
+
<span>PDF</span>
|
|
148
|
+
</button>
|
|
149
|
+
) : null}
|
|
150
|
+
<button type="button" className="openpress-workbench-zoom-menu__item" role="menuitem" onClick={openPng}>
|
|
151
|
+
<span className="openpress-workbench-zoom-menu__check" aria-hidden="true" />
|
|
152
|
+
<ImageIcon aria-hidden="true" />
|
|
153
|
+
<span>PNG 圖片</span>
|
|
154
|
+
</button>
|
|
155
|
+
</div>
|
|
156
|
+
</div>
|
|
157
|
+
) : null}
|
|
158
|
+
|
|
159
|
+
{activeDialog === "pdf" ? (
|
|
160
|
+
<WorkbenchDialog
|
|
161
|
+
titleId={pdfTitleId}
|
|
162
|
+
eyebrow="匯出"
|
|
163
|
+
title="PDF"
|
|
164
|
+
closeLabel="關閉"
|
|
165
|
+
className="openpress-export-dialog"
|
|
166
|
+
onClose={closeDialog}
|
|
167
|
+
footer={
|
|
168
|
+
pdfHref ? (
|
|
169
|
+
<a
|
|
170
|
+
href={pdfHref}
|
|
171
|
+
target="_blank"
|
|
172
|
+
rel="noopener noreferrer"
|
|
173
|
+
className="openpress-export-dialog__action"
|
|
174
|
+
onClick={closeDialog}
|
|
175
|
+
>
|
|
176
|
+
<Download aria-hidden="true" />
|
|
177
|
+
<span>下載 PDF</span>
|
|
178
|
+
</a>
|
|
179
|
+
) : onExportPdf ? (
|
|
180
|
+
<button
|
|
181
|
+
type="button"
|
|
182
|
+
className="openpress-export-dialog__action"
|
|
183
|
+
disabled={pdfDisabled}
|
|
184
|
+
onClick={onExportPdf}
|
|
185
|
+
>
|
|
186
|
+
<Download aria-hidden="true" />
|
|
187
|
+
<span>{pdfLabel ?? "生成 PDF"}</span>
|
|
188
|
+
{pdfStatusMessage ? (
|
|
189
|
+
<span
|
|
190
|
+
className="openpress-dev-pdf-status"
|
|
191
|
+
data-openpress-pdf-status={pdfActionStatus}
|
|
192
|
+
role="status"
|
|
193
|
+
aria-live="polite"
|
|
194
|
+
>
|
|
195
|
+
<span className="openpress-dev-pdf-status__spinner" aria-hidden="true" />
|
|
196
|
+
<span>{pdfStatusMessage}</span>
|
|
197
|
+
</span>
|
|
198
|
+
) : null}
|
|
199
|
+
</button>
|
|
200
|
+
) : null
|
|
201
|
+
}
|
|
202
|
+
>
|
|
203
|
+
<div className="openpress-export-dialog__body">
|
|
204
|
+
<p className="openpress-export-dialog__summary">共 {pages.length} 頁</p>
|
|
205
|
+
</div>
|
|
206
|
+
</WorkbenchDialog>
|
|
207
|
+
) : null}
|
|
208
|
+
|
|
209
|
+
{activeDialog === "png" ? (
|
|
210
|
+
<WorkbenchDialog
|
|
211
|
+
titleId={pngTitleId}
|
|
212
|
+
eyebrow="匯出"
|
|
213
|
+
title="PNG 圖片"
|
|
214
|
+
closeLabel="關閉"
|
|
215
|
+
className="openpress-export-dialog openpress-export-png-dialog"
|
|
216
|
+
onClose={closeDialog}
|
|
217
|
+
footer={
|
|
218
|
+
<button
|
|
219
|
+
type="button"
|
|
220
|
+
className="openpress-export-dialog__action"
|
|
221
|
+
disabled={pngStatus === "exporting" || selectedPngCount === 0}
|
|
222
|
+
data-openpress-export-status={pngStatus}
|
|
223
|
+
onClick={handleExportPng}
|
|
224
|
+
>
|
|
225
|
+
<Download aria-hidden="true" />
|
|
226
|
+
<span>{pngButtonLabel}</span>
|
|
227
|
+
</button>
|
|
228
|
+
}
|
|
229
|
+
>
|
|
230
|
+
<div className="openpress-export-dialog__selection-bar">
|
|
231
|
+
<span>{selectedPngCount} / {pages.length} 張已選</span>
|
|
232
|
+
<div className="openpress-export-dialog__selection-actions">
|
|
233
|
+
<button type="button" onClick={selectAllPngPages}>全選</button>
|
|
234
|
+
<button type="button" onClick={clearPngPages}>清除</button>
|
|
235
|
+
</div>
|
|
236
|
+
</div>
|
|
237
|
+
<div className="openpress-export-dialog__thumbs">
|
|
238
|
+
<PageThumbnails
|
|
239
|
+
pages={pages}
|
|
240
|
+
currentPageIndex={pngPageIndex}
|
|
241
|
+
selectedPageIndexes={selectedPngPageIndexes}
|
|
242
|
+
onTogglePage={(idx) => {
|
|
243
|
+
setPngPageIndex(idx);
|
|
244
|
+
togglePngPage(idx);
|
|
245
|
+
}}
|
|
246
|
+
onSelectPage={(idx) => setPngPageIndex(idx)}
|
|
247
|
+
theme={theme}
|
|
248
|
+
/>
|
|
249
|
+
</div>
|
|
250
|
+
</WorkbenchDialog>
|
|
251
|
+
) : null}
|
|
252
|
+
</div>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function sanitizeFilename(value: string): string {
|
|
257
|
+
return value
|
|
258
|
+
.replace(/[\\/:*?"<>|]+/g, "-")
|
|
259
|
+
.replace(/\s+/g, "-")
|
|
260
|
+
.replace(/-+/g, "-")
|
|
261
|
+
.replace(/^-+|-+$/g, "")
|
|
262
|
+
.slice(0, 80);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function createAllPageIndexSet(pages: HtmlPageBlock[]) {
|
|
266
|
+
return new Set(pages.map((page) => page.pageNumber - 1));
|
|
267
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./deploymentStatusModel";
|
|
2
2
|
export * from "./DeploymentControl";
|
|
3
|
-
export * from "./
|
|
3
|
+
export * from "./ExportControl";
|
|
4
4
|
export * from "./PageZoomControl";
|
|
5
5
|
export * from "./SearchControl";
|
|
6
6
|
export * from "./useDeploymentWorkbench";
|
|
@@ -54,7 +54,12 @@ export function useDeploymentWorkbench({ deploymentInfo, pressSlug = null }: Use
|
|
|
54
54
|
}
|
|
55
55
|
setStatus("deploying");
|
|
56
56
|
try {
|
|
57
|
-
const
|
|
57
|
+
const requestBody = pressSlug ? { press: pressSlug } : {};
|
|
58
|
+
const response = await fetch("/__openpress/deploy", {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: { "Content-Type": "application/json" },
|
|
61
|
+
body: JSON.stringify(requestBody),
|
|
62
|
+
});
|
|
58
63
|
if (response.status === 404 || response.status === 405) {
|
|
59
64
|
setStatus("unavailable");
|
|
60
65
|
return;
|
|
@@ -96,7 +101,7 @@ export function useDeploymentWorkbench({ deploymentInfo, pressSlug = null }: Use
|
|
|
96
101
|
console.error("OpenPress deploy unavailable", error);
|
|
97
102
|
setStatus("unavailable");
|
|
98
103
|
}
|
|
99
|
-
}, [status, currentDeploymentInfo.configured]);
|
|
104
|
+
}, [status, currentDeploymentInfo.configured, pressSlug]);
|
|
100
105
|
|
|
101
106
|
const handleOpenLatestLocalPdf = useCallback(async () => {
|
|
102
107
|
if (pdfActionStatus === "generating") return;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { resolveAnchorPageIndex } from "../../document-model";
|
|
3
|
+
import { PUBLIC_DRAWER_BREAKPOINT, type DisplayPage } from "../../reader";
|
|
4
|
+
|
|
5
|
+
type SetPage = (pageIndex: number, options?: { behavior?: ScrollBehavior }) => void;
|
|
6
|
+
|
|
7
|
+
export function useWorkbenchNavigation({
|
|
8
|
+
anchorPageMap,
|
|
9
|
+
pages,
|
|
10
|
+
rightPanelOpen,
|
|
11
|
+
setPage,
|
|
12
|
+
toggleRightPanel,
|
|
13
|
+
}: {
|
|
14
|
+
anchorPageMap: Map<string, number>;
|
|
15
|
+
pages: DisplayPage[];
|
|
16
|
+
rightPanelOpen: boolean;
|
|
17
|
+
setPage: SetPage;
|
|
18
|
+
toggleRightPanel: () => void;
|
|
19
|
+
}) {
|
|
20
|
+
const selectWorkspacePage = useCallback((pageIndex: number, options?: { behavior?: ScrollBehavior }) => {
|
|
21
|
+
setPage(pageIndex, options);
|
|
22
|
+
if (
|
|
23
|
+
typeof window !== "undefined"
|
|
24
|
+
&& window.innerWidth < PUBLIC_DRAWER_BREAKPOINT
|
|
25
|
+
&& rightPanelOpen
|
|
26
|
+
) {
|
|
27
|
+
toggleRightPanel();
|
|
28
|
+
}
|
|
29
|
+
}, [rightPanelOpen, setPage, toggleRightPanel]);
|
|
30
|
+
|
|
31
|
+
const selectWorkspaceAnchor = useCallback((anchorId: string, pageIndex?: number) => {
|
|
32
|
+
const targetPageIndex = resolveAnchorPageIndex(anchorPageMap, pages.length, anchorId, pageIndex);
|
|
33
|
+
if (targetPageIndex === null) return false;
|
|
34
|
+
selectWorkspacePage(targetPageIndex, { behavior: "smooth" });
|
|
35
|
+
return true;
|
|
36
|
+
}, [anchorPageMap, pages.length, selectWorkspacePage]);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
selectWorkspaceAnchor,
|
|
40
|
+
selectWorkspacePage,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { memo, useState
|
|
2
|
-
import { Component as ComponentIcon
|
|
1
|
+
import { memo, useState } from "react";
|
|
2
|
+
import { Component as ComponentIcon } from "lucide-react";
|
|
3
3
|
import type { BookmarkItem, BookmarkSubItem, MediaAssetItem } from "../../document-model";
|
|
4
|
-
import { projectSourceDirectoryPath, PROJECT_SOURCES } from "./projectSourceModel";
|
|
5
4
|
import type { BlockSource } from "../../document-model";
|
|
6
5
|
import type { DisplayPage } from "../../reader";
|
|
7
6
|
import { Panel } from "../panels/Panel";
|
|
@@ -15,10 +14,6 @@ import {
|
|
|
15
14
|
export { createProjectObjectEntityId } from "./projectPreviewTypes";
|
|
16
15
|
export type { ProjectMentionItem, ProjectPanelPreview } from "./projectPreviewTypes";
|
|
17
16
|
|
|
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
17
|
export type ProjectComponentUsage = {
|
|
23
18
|
count: number;
|
|
24
19
|
pageIndexes: number[];
|
|
@@ -167,264 +162,6 @@ function ProjectEntryPanelImpl({
|
|
|
167
162
|
export const ProjectEntryPanel = memo(ProjectEntryPanelImpl);
|
|
168
163
|
ProjectEntryPanel.displayName = "ProjectEntryPanel";
|
|
169
164
|
|
|
170
|
-
export function ProjectPreviewPanel({
|
|
171
|
-
mediaAssets,
|
|
172
|
-
componentUsages,
|
|
173
|
-
selectedKey,
|
|
174
|
-
}: {
|
|
175
|
-
mediaAssets: MediaAssetItem[];
|
|
176
|
-
componentUsages: Map<string, ProjectComponentUsage>;
|
|
177
|
-
selectedKey: string | null;
|
|
178
|
-
}) {
|
|
179
|
-
if (!selectedKey || selectedKey === PROJECT_VISUAL_SYSTEM_KEY) {
|
|
180
|
-
return <ProjectVisualSystem />;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (selectedKey === PROJECT_IMAGE_GALLERY_KEY) {
|
|
184
|
-
return <ProjectImageGallery mediaAssets={mediaAssets} />;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (selectedKey === PROJECT_COMPONENT_LIBRARY_KEY) {
|
|
188
|
-
return <ProjectComponentLibrary usages={componentUsages} />;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return <ProjectVisualSystem />;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function ProjectPanelButton({
|
|
195
|
-
icon: Icon,
|
|
196
|
-
label,
|
|
197
|
-
meta,
|
|
198
|
-
active,
|
|
199
|
-
onClick,
|
|
200
|
-
}: {
|
|
201
|
-
icon: LucideIcon;
|
|
202
|
-
label: string;
|
|
203
|
-
meta: string;
|
|
204
|
-
active: boolean;
|
|
205
|
-
onClick: () => void;
|
|
206
|
-
}) {
|
|
207
|
-
return (
|
|
208
|
-
<button
|
|
209
|
-
type="button"
|
|
210
|
-
className={`bookmark-item bookmark-h2 openpress-project-entry${active ? " is-active" : ""}`}
|
|
211
|
-
aria-pressed={active}
|
|
212
|
-
onClick={onClick}
|
|
213
|
-
>
|
|
214
|
-
<span className="bookmark-index openpress-project-entry-icon"><Icon aria-hidden="true" /></span>
|
|
215
|
-
<span className="bookmark-title">
|
|
216
|
-
<span>{label}</span>
|
|
217
|
-
<small>{meta}</small>
|
|
218
|
-
</span>
|
|
219
|
-
</button>
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function ProjectVisualSystem() {
|
|
224
|
-
return (
|
|
225
|
-
<section className="openpress-project-preview-panel" aria-label="專案">
|
|
226
|
-
<article className="openpress-project-visual-system" aria-label="Visual System">
|
|
227
|
-
<ProjectSectionHeader title="Visual System" minimal />
|
|
228
|
-
|
|
229
|
-
<div className="openpress-project-visual-grid">
|
|
230
|
-
<section className="openpress-project-visual-card openpress-project-visual-card--typography" aria-label="Typography">
|
|
231
|
-
<header>
|
|
232
|
-
<span>Typography</span>
|
|
233
|
-
<strong>閱讀層級</strong>
|
|
234
|
-
</header>
|
|
235
|
-
<div className="openpress-project-type-specimen">
|
|
236
|
-
<p className="openpress-project-type-kicker">Course Notes</p>
|
|
237
|
-
<h2>Data Structures</h2>
|
|
238
|
-
<h3>Linked List 與 Tree Traversal</h3>
|
|
239
|
-
<h4>Pointer / Node / Recursive Thinking</h4>
|
|
240
|
-
<p>以 C/C++ 實作資料結構,整理概念、表示法與操作流程。</p>
|
|
241
|
-
<code>struct Node *next = head;</code>
|
|
242
|
-
</div>
|
|
243
|
-
</section>
|
|
244
|
-
|
|
245
|
-
<section className="openpress-project-visual-card" aria-label="Color Palette">
|
|
246
|
-
<header>
|
|
247
|
-
<span>Palette</span>
|
|
248
|
-
<strong>色票配置</strong>
|
|
249
|
-
</header>
|
|
250
|
-
<div className="openpress-project-swatch-grid">
|
|
251
|
-
{PROJECT_COLOR_SWATCHES.map((item) => (
|
|
252
|
-
<div className="openpress-project-swatch" key={item.token}>
|
|
253
|
-
<span
|
|
254
|
-
className="openpress-project-swatch-chip"
|
|
255
|
-
style={{ "--openpress-project-swatch": `var(${item.token})` } as CSSProperties}
|
|
256
|
-
aria-hidden="true"
|
|
257
|
-
/>
|
|
258
|
-
<strong>{item.label}</strong>
|
|
259
|
-
<code>{item.token.replace("--openpress-", "")}</code>
|
|
260
|
-
</div>
|
|
261
|
-
))}
|
|
262
|
-
</div>
|
|
263
|
-
</section>
|
|
264
|
-
|
|
265
|
-
<section className="openpress-project-visual-card openpress-project-visual-card--surfaces" aria-label="Surfaces">
|
|
266
|
-
<header>
|
|
267
|
-
<span>Surfaces</span>
|
|
268
|
-
<strong>區塊背景</strong>
|
|
269
|
-
</header>
|
|
270
|
-
<div className="openpress-project-surface-preview">
|
|
271
|
-
<div className="openpress-project-surface-paper">
|
|
272
|
-
<span>Page paper</span>
|
|
273
|
-
</div>
|
|
274
|
-
<div className="openpress-project-surface-block">
|
|
275
|
-
<span>Figure / Code block</span>
|
|
276
|
-
</div>
|
|
277
|
-
</div>
|
|
278
|
-
</section>
|
|
279
|
-
</div>
|
|
280
|
-
</article>
|
|
281
|
-
</section>
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function ProjectComponentLibrary({
|
|
286
|
-
usages,
|
|
287
|
-
}: {
|
|
288
|
-
usages: Map<string, ProjectComponentUsage>;
|
|
289
|
-
}) {
|
|
290
|
-
const previewItems = createComponentPreviewItems(usages);
|
|
291
|
-
return (
|
|
292
|
-
<section className="openpress-project-preview-panel" aria-label="專案">
|
|
293
|
-
<article className="openpress-project-component-viewer" aria-label={PROJECT_SOURCES.components.label}>
|
|
294
|
-
<ProjectSectionHeader
|
|
295
|
-
title="Rendered Components"
|
|
296
|
-
description="文件目前實際渲染出的 component、圖表與示意圖狀態。"
|
|
297
|
-
stats={[
|
|
298
|
-
["Kinds", String(usages.size)],
|
|
299
|
-
["Renders", String(previewItems.length)],
|
|
300
|
-
]}
|
|
301
|
-
/>
|
|
302
|
-
{previewItems.length > 0 ? (
|
|
303
|
-
<div className="openpress-project-component-list" aria-label="rendered content block list">
|
|
304
|
-
{previewItems.map((item) => (
|
|
305
|
-
<figure className="openpress-project-component-preview-row" key={`${item.name}-${item.index}`}>
|
|
306
|
-
<figcaption>
|
|
307
|
-
<span>{item.name}</span>
|
|
308
|
-
<small>P{String(item.preview.pageIndex + 1).padStart(2, "0")}</small>
|
|
309
|
-
</figcaption>
|
|
310
|
-
<div
|
|
311
|
-
className="openpress-project-component-preview"
|
|
312
|
-
dangerouslySetInnerHTML={{ __html: item.preview.html }}
|
|
313
|
-
/>
|
|
314
|
-
</figure>
|
|
315
|
-
))}
|
|
316
|
-
</div>
|
|
317
|
-
) : (
|
|
318
|
-
<p className="openpress-project-empty">目前文件尚未渲染任何內容區塊。</p>
|
|
319
|
-
)}
|
|
320
|
-
</article>
|
|
321
|
-
</section>
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
function ProjectImageGallery({
|
|
326
|
-
mediaAssets,
|
|
327
|
-
}: {
|
|
328
|
-
mediaAssets: MediaAssetItem[];
|
|
329
|
-
}) {
|
|
330
|
-
const usedCount = mediaAssets.filter((item) => item.usageCount > 0).length;
|
|
331
|
-
const unreferencedAssets = mediaAssets.filter((item) => item.usageCount === 0);
|
|
332
|
-
const referencedAssets = mediaAssets.filter((item) => item.usageCount > 0);
|
|
333
|
-
return (
|
|
334
|
-
<section className="openpress-project-preview-panel" aria-label="專案">
|
|
335
|
-
<article className="openpress-project-gallery-viewer" aria-label="Image Gallery">
|
|
336
|
-
<ProjectSectionHeader
|
|
337
|
-
title="Media Library"
|
|
338
|
-
description={projectSourceDirectoryPath("media")}
|
|
339
|
-
stats={[
|
|
340
|
-
["Files", String(mediaAssets.length)],
|
|
341
|
-
["Used", String(usedCount)],
|
|
342
|
-
]}
|
|
343
|
-
/>
|
|
344
|
-
{mediaAssets.length > 0 ? (
|
|
345
|
-
<div className="openpress-project-media-sections" aria-label="media gallery">
|
|
346
|
-
<ProjectMediaSection title="未引用" assets={unreferencedAssets} />
|
|
347
|
-
<ProjectMediaSection title="已引用" assets={referencedAssets} />
|
|
348
|
-
</div>
|
|
349
|
-
) : (
|
|
350
|
-
<p className="openpress-project-empty">{projectSourceDirectoryPath("media")} 尚未有可預覽素材。</p>
|
|
351
|
-
)}
|
|
352
|
-
</article>
|
|
353
|
-
</section>
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
function ProjectSectionHeader({
|
|
358
|
-
title,
|
|
359
|
-
description,
|
|
360
|
-
stats,
|
|
361
|
-
minimal = false,
|
|
362
|
-
}: {
|
|
363
|
-
title: string;
|
|
364
|
-
description?: string;
|
|
365
|
-
stats?: Array<[string, string]>;
|
|
366
|
-
minimal?: boolean;
|
|
367
|
-
}) {
|
|
368
|
-
return (
|
|
369
|
-
<header className={`openpress-project-section-header${minimal ? " openpress-project-section-header--minimal" : ""}`}>
|
|
370
|
-
<div>
|
|
371
|
-
<h2>{title}</h2>
|
|
372
|
-
{description ? <span>{description}</span> : null}
|
|
373
|
-
</div>
|
|
374
|
-
{!minimal && stats?.length ? (
|
|
375
|
-
<dl>
|
|
376
|
-
{stats.map(([label, value]) => (
|
|
377
|
-
<div key={label}>
|
|
378
|
-
<dt>{label}</dt>
|
|
379
|
-
<dd>{value}</dd>
|
|
380
|
-
</div>
|
|
381
|
-
))}
|
|
382
|
-
</dl>
|
|
383
|
-
) : null}
|
|
384
|
-
</header>
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
function ProjectMediaSection({
|
|
389
|
-
title,
|
|
390
|
-
assets,
|
|
391
|
-
}: {
|
|
392
|
-
title: string;
|
|
393
|
-
assets: MediaAssetItem[];
|
|
394
|
-
}) {
|
|
395
|
-
return (
|
|
396
|
-
<section className="openpress-project-media-section" aria-label={title}>
|
|
397
|
-
<header className="openpress-project-media-section-header">
|
|
398
|
-
<h3>{title}</h3>
|
|
399
|
-
</header>
|
|
400
|
-
{assets.length > 0 ? (
|
|
401
|
-
<div className="openpress-project-media-gallery">
|
|
402
|
-
{assets.map((item) => (
|
|
403
|
-
<figure className="openpress-project-media-card" data-unused={item.usageCount === 0 ? "true" : "false"} key={item.id}>
|
|
404
|
-
<img src={item.src} alt="" loading="lazy" />
|
|
405
|
-
<figcaption>
|
|
406
|
-
<strong>{item.fileName}</strong>
|
|
407
|
-
</figcaption>
|
|
408
|
-
</figure>
|
|
409
|
-
))}
|
|
410
|
-
</div>
|
|
411
|
-
) : (
|
|
412
|
-
<p className="openpress-project-media-section-empty">沒有{title}圖片。</p>
|
|
413
|
-
)}
|
|
414
|
-
</section>
|
|
415
|
-
);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
function createComponentPreviewItems(usages: Map<string, ProjectComponentUsage>) {
|
|
419
|
-
return Array.from(usages.entries())
|
|
420
|
-
.flatMap(([name, usage]) => usage.previews.map((preview, index) => ({ name, preview, index })))
|
|
421
|
-
.filter((item) => Boolean(item.preview.html))
|
|
422
|
-
.sort((a, b) => {
|
|
423
|
-
const pageDelta = a.preview.pageIndex - b.preview.pageIndex;
|
|
424
|
-
return pageDelta || a.name.localeCompare(b.name, "zh-Hant") || a.index - b.index;
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
|
|
428
165
|
function extractRenderedComponentBlocks(html: string) {
|
|
429
166
|
const blocks: Array<{ name: string; html: string }> = [];
|
|
430
167
|
const openTagPattern = /<(figure|section|article|div)\b[^>]*data-openpress-component="([^"]+)"[^>]*>/g;
|
|
@@ -510,16 +247,3 @@ const PROJECT_SKILL_MENTIONS: ProjectMentionItem[] = [
|
|
|
510
247
|
{ trigger: "/", value: "/apply-style", label: "apply-style", meta: "skill", kind: "skill" },
|
|
511
248
|
{ trigger: "/", value: "/fix-code", label: "fix-code", meta: "skill", kind: "skill" },
|
|
512
249
|
];
|
|
513
|
-
|
|
514
|
-
const PROJECT_COLOR_SWATCHES = [
|
|
515
|
-
{ label: "Document", token: "--openpress-color-document" },
|
|
516
|
-
{ label: "Paper", token: "--openpress-color-paper" },
|
|
517
|
-
{ label: "Ink", token: "--openpress-color-ink" },
|
|
518
|
-
{ label: "Body", token: "--openpress-color-body" },
|
|
519
|
-
{ label: "Muted", token: "--openpress-color-muted" },
|
|
520
|
-
{ label: "Subtle", token: "--openpress-color-subtle" },
|
|
521
|
-
{ label: "Line", token: "--openpress-color-line" },
|
|
522
|
-
{ label: "Block", token: "--openpress-color-block" },
|
|
523
|
-
{ label: "Info", token: "--openpress-color-info" },
|
|
524
|
-
{ label: "Green", token: "--openpress-color-green" },
|
|
525
|
-
];
|