@lokvis/ui-react 0.1.0 → 0.2.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/LICENSE +21 -0
- package/dist/components/AssetPanel.d.ts +2 -2
- package/dist/components/AssetPanel.d.ts.map +1 -1
- package/dist/components/AssetPanel.js +80 -7
- package/dist/components/AssetPanel.js.map +1 -1
- package/dist/components/Canvas.d.ts +9 -1
- package/dist/components/Canvas.d.ts.map +1 -1
- package/dist/components/Canvas.js +41 -3
- package/dist/components/Canvas.js.map +1 -1
- package/dist/components/CommandPalette.d.ts +48 -0
- package/dist/components/CommandPalette.d.ts.map +1 -0
- package/dist/components/CommandPalette.js +154 -0
- package/dist/components/CommandPalette.js.map +1 -0
- package/dist/components/CompareSlider.d.ts +25 -0
- package/dist/components/CompareSlider.d.ts.map +1 -0
- package/dist/components/CompareSlider.js +106 -0
- package/dist/components/CompareSlider.js.map +1 -0
- package/dist/components/DownloadPanel.d.ts +20 -0
- package/dist/components/DownloadPanel.d.ts.map +1 -0
- package/dist/components/DownloadPanel.js +169 -0
- package/dist/components/DownloadPanel.js.map +1 -0
- package/dist/components/ErrorBanner.d.ts +22 -0
- package/dist/components/ErrorBanner.d.ts.map +1 -0
- package/dist/components/ErrorBanner.js +47 -0
- package/dist/components/ErrorBanner.js.map +1 -0
- package/dist/components/ExifPanel.d.ts +26 -0
- package/dist/components/ExifPanel.d.ts.map +1 -0
- package/dist/components/ExifPanel.js +104 -0
- package/dist/components/ExifPanel.js.map +1 -0
- package/dist/components/GlobalDropzone.d.ts +37 -0
- package/dist/components/GlobalDropzone.d.ts.map +1 -0
- package/dist/components/GlobalDropzone.js +154 -0
- package/dist/components/GlobalDropzone.js.map +1 -0
- package/dist/components/HistoryPanel.d.ts +17 -7
- package/dist/components/HistoryPanel.d.ts.map +1 -1
- package/dist/components/HistoryPanel.js +74 -62
- package/dist/components/HistoryPanel.js.map +1 -1
- package/dist/components/Inspector.d.ts.map +1 -1
- package/dist/components/Inspector.js +3 -1
- package/dist/components/Inspector.js.map +1 -1
- package/dist/components/PipelineBar.d.ts.map +1 -1
- package/dist/components/PipelineBar.js +4 -3
- package/dist/components/PipelineBar.js.map +1 -1
- package/dist/components/ProgressBar.d.ts +18 -0
- package/dist/components/ProgressBar.d.ts.map +1 -0
- package/dist/components/ProgressBar.js +35 -0
- package/dist/components/ProgressBar.js.map +1 -0
- package/dist/components/StatusBar.d.ts +8 -2
- package/dist/components/StatusBar.d.ts.map +1 -1
- package/dist/components/StatusBar.js +59 -4
- package/dist/components/StatusBar.js.map +1 -1
- package/dist/components/ThemeToggle.d.ts +20 -0
- package/dist/components/ThemeToggle.d.ts.map +1 -0
- package/dist/components/ThemeToggle.js +60 -0
- package/dist/components/ThemeToggle.js.map +1 -0
- package/dist/components/WorkflowEditor.d.ts +24 -0
- package/dist/components/WorkflowEditor.d.ts.map +1 -0
- package/dist/components/WorkflowEditor.js +160 -0
- package/dist/components/WorkflowEditor.js.map +1 -0
- package/dist/components/WorkflowTemplates.d.ts +23 -0
- package/dist/components/WorkflowTemplates.d.ts.map +1 -0
- package/dist/components/WorkflowTemplates.js +32 -0
- package/dist/components/WorkflowTemplates.js.map +1 -0
- package/dist/components/Workspace.d.ts +48 -2
- package/dist/components/Workspace.d.ts.map +1 -1
- package/dist/components/Workspace.js +80 -5
- package/dist/components/Workspace.js.map +1 -1
- package/dist/data/workflow-templates.d.ts +42 -0
- package/dist/data/workflow-templates.d.ts.map +1 -0
- package/dist/data/workflow-templates.js +112 -0
- package/dist/data/workflow-templates.js.map +1 -0
- package/dist/hooks/useDebouncedRun.d.ts +49 -0
- package/dist/hooks/useDebouncedRun.d.ts.map +1 -0
- package/dist/hooks/useDebouncedRun.js +117 -0
- package/dist/hooks/useDebouncedRun.js.map +1 -0
- package/dist/hooks/useLokvis.js +1 -1
- package/dist/hooks/useMediaQuery.d.ts +27 -0
- package/dist/hooks/useMediaQuery.d.ts.map +1 -0
- package/dist/hooks/useMediaQuery.js +41 -0
- package/dist/hooks/useMediaQuery.js.map +1 -0
- package/dist/hooks/useShareLink.d.ts +58 -0
- package/dist/hooks/useShareLink.d.ts.map +1 -0
- package/dist/hooks/useShareLink.js +120 -0
- package/dist/hooks/useShareLink.js.map +1 -0
- package/dist/hooks/useTheme.d.ts +30 -0
- package/dist/hooks/useTheme.d.ts.map +1 -0
- package/dist/hooks/useTheme.js +105 -0
- package/dist/hooks/useTheme.js.map +1 -0
- package/dist/hooks/useWorkflowProgress.d.ts +28 -0
- package/dist/hooks/useWorkflowProgress.d.ts.map +1 -0
- package/dist/hooks/useWorkflowProgress.js +25 -0
- package/dist/hooks/useWorkflowProgress.js.map +1 -0
- package/dist/hooks/useWorkflows.d.ts +86 -0
- package/dist/hooks/useWorkflows.d.ts.map +1 -0
- package/dist/hooks/useWorkflows.js +247 -0
- package/dist/hooks/useWorkflows.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -1
- package/dist/store/assets-slice.d.ts.map +1 -1
- package/dist/store/assets-slice.js +19 -0
- package/dist/store/assets-slice.js.map +1 -1
- package/dist/store/history-slice.d.ts +18 -0
- package/dist/store/history-slice.d.ts.map +1 -0
- package/dist/store/history-slice.js +42 -0
- package/dist/store/history-slice.js.map +1 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +3 -0
- package/dist/store/index.js.map +1 -1
- package/dist/store/runtime-slice.d.ts +10 -2
- package/dist/store/runtime-slice.d.ts.map +1 -1
- package/dist/store/runtime-slice.js +77 -28
- package/dist/store/runtime-slice.js.map +1 -1
- package/dist/store/types.d.ts +70 -1
- package/dist/store/types.d.ts.map +1 -1
- package/dist/store/types.js +10 -0
- package/dist/store/types.js.map +1 -1
- package/dist/store/workflow-slice.d.ts +1 -1
- package/dist/store/workflow-slice.d.ts.map +1 -1
- package/dist/store/workflow-slice.js +167 -20
- package/dist/store/workflow-slice.js.map +1 -1
- package/dist/store.d.ts +76 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +217 -0
- package/dist/store.js.map +1 -0
- package/package.json +9 -6
- package/src/components/AssetPanel.tsx +154 -12
- package/src/components/Canvas.tsx +85 -7
- package/src/components/CommandPalette.tsx +300 -0
- package/src/components/CompareSlider.tsx +186 -0
- package/src/components/DownloadPanel.tsx +252 -0
- package/src/components/ErrorBanner.tsx +95 -0
- package/src/components/ExifPanel.tsx +187 -0
- package/src/components/GlobalDropzone.tsx +220 -0
- package/src/components/HistoryPanel.tsx +231 -104
- package/src/components/Inspector.tsx +7 -2
- package/src/components/PipelineBar.tsx +13 -12
- package/src/components/ProgressBar.tsx +104 -0
- package/src/components/StatusBar.tsx +124 -5
- package/src/components/ThemeToggle.tsx +122 -0
- package/src/components/WorkflowEditor.tsx +382 -0
- package/src/components/WorkflowTemplates.tsx +101 -0
- package/src/components/Workspace.tsx +207 -9
- package/src/data/workflow-templates.ts +137 -0
- package/src/hooks/useDebouncedRun.ts +151 -0
- package/src/hooks/useLokvis.ts +1 -1
- package/src/hooks/useMediaQuery.ts +53 -0
- package/src/hooks/useShareLink.ts +158 -0
- package/src/hooks/useTheme.ts +116 -0
- package/src/hooks/useWorkflowProgress.ts +41 -0
- package/src/hooks/useWorkflows.ts +326 -0
- package/src/index.ts +32 -0
- package/src/store/assets-slice.ts +19 -0
- package/src/store/history-slice.ts +65 -0
- package/src/store/index.ts +3 -0
- package/src/store/runtime-slice.ts +89 -32
- package/src/store/types.ts +71 -1
- package/src/store/workflow-slice.ts +178 -20
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GlobalDropzone - 全屏拖拽导入区 + MIME 类型校验(W9.3)
|
|
3
|
+
*
|
|
4
|
+
* 当用户拖拽文件进入窗口时,显示全屏遮罩引导用户拖到任意位置即可导入。
|
|
5
|
+
* 通过 `accept` 白名单做 MIME 类型校验,拒绝类型时给出视觉反馈 + 警告。
|
|
6
|
+
*
|
|
7
|
+
* 工作机制:
|
|
8
|
+
* 1. 监听 window dragenter / dragover / dragleave / drop 事件
|
|
9
|
+
* 2. dragenter 显示遮罩,dragleave(离开 window)隐藏
|
|
10
|
+
* 3. drop 时校验文件类型 → 合法则 importFiles,非法则提示拒绝原因
|
|
11
|
+
*
|
|
12
|
+
* MIME 校验:
|
|
13
|
+
* - 默认接受所有 image/* 类型(以及 video/audio/pdf 等,与 workspace 多媒体定位对齐)
|
|
14
|
+
* - 拒绝类型在遮罩中央显示红色提示,并阻止导入
|
|
15
|
+
*
|
|
16
|
+
* 与 AssetPanel / Canvas 内置的局部 dropzone 互不冲突:它们各自处理自己的
|
|
17
|
+
* drop 事件并 `stopPropagation()`,本组件的 window drop 监听不会触发。
|
|
18
|
+
*
|
|
19
|
+
* 防御性兜底:即便子组件忘了 `stopPropagation`,本组件也会再次处理 drop 事件,
|
|
20
|
+
* 但通过 `importFiles` 的幂等性(以 File 引用去重)— 不,File 引用并不去重,
|
|
21
|
+
* 所以子组件**必须** `stopPropagation()`。本组件在 drop 事件触发时,先检查
|
|
22
|
+
* `e.defaultPrevented`(子组件会 `preventDefault()` 表明已处理),若已处理
|
|
23
|
+
* 则直接 return,避免双重导入。
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* <GlobalDropzone accept="image/*" />
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import * as React from 'react';
|
|
32
|
+
import { Icon } from '@lokvis/ui-core';
|
|
33
|
+
import { useWorkspaceStore } from '../store/index.js';
|
|
34
|
+
|
|
35
|
+
export interface GlobalDropzoneProps {
|
|
36
|
+
/** 接受的 MIME 类型(逗号分隔),默认接受图片/视频/音频/PDF */
|
|
37
|
+
accept?: string;
|
|
38
|
+
className?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 默认接受的类型:与 Workspace 多媒体定位对齐 */
|
|
42
|
+
const DEFAULT_ACCEPT = 'image/*,video/*,audio/*,application/pdf';
|
|
43
|
+
|
|
44
|
+
/** 检查单个文件是否符合 accept 白名单 */
|
|
45
|
+
function isFileAccepted(file: File, accept: string): boolean {
|
|
46
|
+
if (!accept) return true;
|
|
47
|
+
const patterns = accept.split(',').map((p) => p.trim().toLowerCase()).filter(Boolean);
|
|
48
|
+
if (patterns.length === 0) return true;
|
|
49
|
+
const mime = file.type.toLowerCase();
|
|
50
|
+
const name = file.name.toLowerCase();
|
|
51
|
+
return patterns.some((p) => {
|
|
52
|
+
// image/* → image/(prefix match)
|
|
53
|
+
if (p.endsWith('/*')) {
|
|
54
|
+
return mime.startsWith(p.slice(0, -1));
|
|
55
|
+
}
|
|
56
|
+
// image/jpeg → exact mime match
|
|
57
|
+
if (p.includes('/')) {
|
|
58
|
+
return mime === p;
|
|
59
|
+
}
|
|
60
|
+
// .png → extension match
|
|
61
|
+
if (p.startsWith('.')) {
|
|
62
|
+
return name.endsWith(p);
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function GlobalDropzone({
|
|
69
|
+
accept = DEFAULT_ACCEPT,
|
|
70
|
+
className = '',
|
|
71
|
+
}: GlobalDropzoneProps) {
|
|
72
|
+
const importFiles = useWorkspaceStore((s) => s.importFiles);
|
|
73
|
+
const setStatus = useWorkspaceStore((s) => s.setStatus);
|
|
74
|
+
const setError = useWorkspaceStore((s) => s.setError);
|
|
75
|
+
|
|
76
|
+
// dragCounter:用计数器而非布尔,避免子元素 dragenter/dragleave 触发抖动
|
|
77
|
+
const [dragCounter, setDragCounter] = React.useState(0);
|
|
78
|
+
const [rejectedFiles, setRejectedFiles] = React.useState<string[]>([]);
|
|
79
|
+
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
// 阻止浏览器默认行为(打开文件 / 下载),否则 drop 不会触发
|
|
82
|
+
const preventDefault = (e: DragEvent) => {
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
e.stopPropagation();
|
|
85
|
+
};
|
|
86
|
+
// dragenter:进入窗口,计数 +1
|
|
87
|
+
const onDragEnter = (e: DragEvent) => {
|
|
88
|
+
preventDefault(e);
|
|
89
|
+
if (e.dataTransfer?.types?.includes('Files')) {
|
|
90
|
+
setDragCounter((c) => c + 1);
|
|
91
|
+
setRejectedFiles([]);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// dragover:必须 preventDefault 才能触发 drop
|
|
95
|
+
const onDragOver = (e: DragEvent) => {
|
|
96
|
+
preventDefault(e);
|
|
97
|
+
if (e.dataTransfer) {
|
|
98
|
+
// 显示 drop 效果
|
|
99
|
+
e.dataTransfer.dropEffect = 'copy';
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
// dragleave:离开窗口,计数 -1
|
|
103
|
+
const onDragLeave = (e: DragEvent) => {
|
|
104
|
+
preventDefault(e);
|
|
105
|
+
// 只在离开 window 时(relatedTarget 为 null 或 document.documentElement)减计数
|
|
106
|
+
// relatedTarget 为 null 表示离开文档边界
|
|
107
|
+
if (e.relatedTarget === null) {
|
|
108
|
+
setDragCounter(0);
|
|
109
|
+
setRejectedFiles([]);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
// drop:校验 + 导入
|
|
113
|
+
const onDrop = (e: DragEvent) => {
|
|
114
|
+
// 兜底:子组件(Canvas / AssetPanel)若已处理 drop 并 preventDefault(),
|
|
115
|
+
// 表明文件已导入,本组件跳过避免双重导入。子组件仍需 stopPropagation()
|
|
116
|
+
// 防止事件冒泡到 window,这里 defaultPrevented 是双保险。
|
|
117
|
+
if (e.defaultPrevented) {
|
|
118
|
+
setDragCounter(0);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
preventDefault(e);
|
|
122
|
+
setDragCounter(0);
|
|
123
|
+
const files = e.dataTransfer?.files ? Array.from(e.dataTransfer.files) : [];
|
|
124
|
+
if (files.length === 0) return;
|
|
125
|
+
|
|
126
|
+
const accepted: File[] = [];
|
|
127
|
+
const rejected: string[] = [];
|
|
128
|
+
for (const file of files) {
|
|
129
|
+
if (isFileAccepted(file, accept)) {
|
|
130
|
+
accepted.push(file);
|
|
131
|
+
} else {
|
|
132
|
+
rejected.push(`${file.name} (${file.type || 'unknown'})`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (rejected.length > 0) {
|
|
136
|
+
setRejectedFiles(rejected);
|
|
137
|
+
// 5 秒后自动清空拒绝提示
|
|
138
|
+
setTimeout(() => setRejectedFiles([]), 5000);
|
|
139
|
+
}
|
|
140
|
+
if (accepted.length > 0) {
|
|
141
|
+
void importFiles(accepted);
|
|
142
|
+
} else {
|
|
143
|
+
setStatus(`Rejected ${rejected.length} file(s) — unsupported type`);
|
|
144
|
+
setError(null);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
window.addEventListener('dragenter', onDragEnter);
|
|
149
|
+
window.addEventListener('dragover', onDragOver);
|
|
150
|
+
window.addEventListener('dragleave', onDragLeave);
|
|
151
|
+
window.addEventListener('drop', onDrop);
|
|
152
|
+
return () => {
|
|
153
|
+
window.removeEventListener('dragenter', onDragEnter);
|
|
154
|
+
window.removeEventListener('dragover', onDragOver);
|
|
155
|
+
window.removeEventListener('dragleave', onDragLeave);
|
|
156
|
+
window.removeEventListener('drop', onDrop);
|
|
157
|
+
};
|
|
158
|
+
}, [accept, importFiles, setStatus, setError]);
|
|
159
|
+
|
|
160
|
+
const isDragging = dragCounter > 0;
|
|
161
|
+
const hasRejections = rejectedFiles.length > 0;
|
|
162
|
+
|
|
163
|
+
if (!isDragging && !hasRejections) return null;
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<div
|
|
167
|
+
className={`pointer-events-none fixed inset-0 z-40 flex items-center justify-center p-8 ${className}`}
|
|
168
|
+
role="alertdialog"
|
|
169
|
+
aria-live="polite"
|
|
170
|
+
>
|
|
171
|
+
{/* 遮罩 */}
|
|
172
|
+
<div className="absolute inset-0 bg-indigo-50/80 backdrop-blur-sm dark:bg-indigo-950/60" />
|
|
173
|
+
|
|
174
|
+
{/* 内容 */}
|
|
175
|
+
<div
|
|
176
|
+
className={`relative w-full max-w-md rounded-2xl border-2 border-dashed p-8 text-center bg-white shadow-2xl dark:bg-zinc-900 ${
|
|
177
|
+
hasRejections ? 'border-red-400 dark:border-red-600' : 'border-indigo-500 dark:border-indigo-400'
|
|
178
|
+
}`}
|
|
179
|
+
>
|
|
180
|
+
{hasRejections ? (
|
|
181
|
+
<>
|
|
182
|
+
<div className="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-red-100 dark:bg-red-900/40">
|
|
183
|
+
<Icon size={24} className="text-red-500" strokeWidth={2}>
|
|
184
|
+
<circle cx="12" cy="12" r="10" />
|
|
185
|
+
<line x1="15" y1="9" x2="9" y2="15" />
|
|
186
|
+
<line x1="9" y1="9" x2="15" y2="15" />
|
|
187
|
+
</Icon>
|
|
188
|
+
</div>
|
|
189
|
+
<p className="mt-3 text-sm font-semibold text-red-700 dark:text-red-400">
|
|
190
|
+
Unsupported file type
|
|
191
|
+
</p>
|
|
192
|
+
<p className="mt-1.5 text-xs text-red-600/80 dark:text-red-400/70">
|
|
193
|
+
{rejectedFiles.join(', ')}
|
|
194
|
+
</p>
|
|
195
|
+
<p className="mt-2 text-[10px] text-zinc-500">
|
|
196
|
+
Accepted: {accept || 'all files'}
|
|
197
|
+
</p>
|
|
198
|
+
</>
|
|
199
|
+
) : (
|
|
200
|
+
<>
|
|
201
|
+
<div className="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-indigo-100 dark:bg-indigo-900/40">
|
|
202
|
+
<Icon size={24} className="text-indigo-500" strokeWidth={1.5}>
|
|
203
|
+
<path d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5m-13.5-9L12 3m0 0 4.5 4.5M12 3v13.5" />
|
|
204
|
+
</Icon>
|
|
205
|
+
</div>
|
|
206
|
+
<p className="mt-3 text-sm font-semibold text-indigo-700 dark:text-indigo-300">
|
|
207
|
+
Drop files to import
|
|
208
|
+
</p>
|
|
209
|
+
<p className="mt-1 text-xs text-zinc-500 dark:text-zinc-400">
|
|
210
|
+
Files are processed locally in your browser
|
|
211
|
+
</p>
|
|
212
|
+
<p className="mt-2 text-[10px] text-zinc-400">
|
|
213
|
+
Accepted: {accept || 'all files'}
|
|
214
|
+
</p>
|
|
215
|
+
</>
|
|
216
|
+
)}
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
);
|
|
220
|
+
}
|
|
@@ -1,127 +1,254 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* HistoryPanel -
|
|
2
|
+
* HistoryPanel - 历史栈面板(W7.1 / W9.1)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* 展示当前工作流的执行历史,支持:
|
|
5
|
+
* - Undo / Redo 按钮(根据 cursor 禁用)
|
|
6
|
+
* - 点击条目直接跳转(jumpTo)
|
|
7
|
+
* - cursor 当前位置高亮,cursor 之后的条目标灰(redo 分支)
|
|
8
|
+
*
|
|
9
|
+
* W9.1: 支持 `variant` 切换布局方向
|
|
10
|
+
* - `vertical`(默认):侧栏垂直布局,适合嵌入左/右栏
|
|
11
|
+
* - `horizontal`:底部横条布局,作为底部 history bar 使用
|
|
12
|
+
*
|
|
13
|
+
* 数据来自 history-slice(store 单一来源),由 runtime-slice 的
|
|
14
|
+
* history:changed 订阅自动更新,组件无需自行订阅事件。
|
|
15
|
+
*
|
|
16
|
+
* 历史条目渲染:把 HistoryEntry 的 capability + params 摘要为可读标签。
|
|
6
17
|
*/
|
|
7
18
|
|
|
8
|
-
import
|
|
9
|
-
import
|
|
19
|
+
import type { HistoryEntry } from '@lokvis/schema';
|
|
20
|
+
import { Icon } from '@lokvis/ui-core';
|
|
10
21
|
import { useWorkspaceStore } from '../store/index.js';
|
|
11
22
|
|
|
12
|
-
interface HistoryItem {
|
|
13
|
-
id: string;
|
|
14
|
-
type: string;
|
|
15
|
-
message: string;
|
|
16
|
-
timestamp: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
23
|
export interface HistoryPanelProps {
|
|
20
24
|
className?: string;
|
|
21
|
-
/**
|
|
22
|
-
|
|
25
|
+
/** 布局方向(W9.1):vertical 侧栏,horizontal 底部横条 */
|
|
26
|
+
variant?: 'vertical' | 'horizontal';
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
export function HistoryPanel({ className = '',
|
|
26
|
-
const
|
|
27
|
-
const
|
|
29
|
+
export function HistoryPanel({ className = '', variant = 'vertical' }: HistoryPanelProps) {
|
|
30
|
+
const entries = useWorkspaceStore((s) => s.historyEntries);
|
|
31
|
+
const cursor = useWorkspaceStore((s) => s.historyCursor);
|
|
32
|
+
const workflowId = useWorkspaceStore((s) => s.historyWorkflowId);
|
|
33
|
+
const undo = useWorkspaceStore((s) => s.undo);
|
|
34
|
+
const redo = useWorkspaceStore((s) => s.redo);
|
|
35
|
+
const jumpTo = useWorkspaceStore((s) => s.jumpToHistory);
|
|
36
|
+
|
|
37
|
+
const canUndo = cursor >= 0;
|
|
38
|
+
const canRedo = cursor < entries.length - 1;
|
|
39
|
+
const horizontal = variant === 'horizontal';
|
|
28
40
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
const undoBtn = (
|
|
42
|
+
<button
|
|
43
|
+
type="button"
|
|
44
|
+
onClick={() => void undo()}
|
|
45
|
+
disabled={!canUndo}
|
|
46
|
+
aria-label="Undo"
|
|
47
|
+
className="rounded p-1 text-zinc-500 transition-colors hover:bg-zinc-100 hover:text-zinc-700 disabled:cursor-not-allowed disabled:opacity-30 dark:hover:bg-zinc-800 dark:hover:text-zinc-300"
|
|
48
|
+
>
|
|
49
|
+
<Icon size={13}>
|
|
50
|
+
<path d="M9 14L4 9l5-5" />
|
|
51
|
+
<path d="M4 9h11a4 4 0 0 1 0 8h-3" />
|
|
52
|
+
</Icon>
|
|
53
|
+
</button>
|
|
54
|
+
);
|
|
55
|
+
const redoBtn = (
|
|
56
|
+
<button
|
|
57
|
+
type="button"
|
|
58
|
+
onClick={() => void redo()}
|
|
59
|
+
disabled={!canRedo}
|
|
60
|
+
aria-label="Redo"
|
|
61
|
+
className="rounded p-1 text-zinc-500 transition-colors hover:bg-zinc-100 hover:text-zinc-700 disabled:cursor-not-allowed disabled:opacity-30 dark:hover:bg-zinc-800 dark:hover:text-zinc-300"
|
|
62
|
+
>
|
|
63
|
+
<Icon size={13}>
|
|
64
|
+
<path d="M15 14l5-5-5-5" />
|
|
65
|
+
<path d="M20 9H9a4 4 0 0 0 0 8h3" />
|
|
66
|
+
</Icon>
|
|
67
|
+
</button>
|
|
68
|
+
);
|
|
47
69
|
|
|
70
|
+
const headerEl = (
|
|
71
|
+
<div
|
|
72
|
+
className={`flex shrink-0 items-center justify-between px-3 ${
|
|
73
|
+
horizontal ? 'h-full border-r border-zinc-200 dark:border-zinc-800' : 'h-10 border-b border-zinc-200 dark:border-zinc-800'
|
|
74
|
+
}`}
|
|
75
|
+
>
|
|
76
|
+
<span className="text-[11px] font-semibold uppercase tracking-wider text-zinc-400">
|
|
77
|
+
History
|
|
78
|
+
</span>
|
|
79
|
+
<div className="flex items-center gap-0.5">
|
|
80
|
+
{undoBtn}
|
|
81
|
+
{redoBtn}
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
// 空状态
|
|
87
|
+
if (!workflowId || entries.length === 0) {
|
|
88
|
+
return (
|
|
89
|
+
<aside
|
|
90
|
+
className={`flex shrink-0 ${
|
|
91
|
+
horizontal
|
|
92
|
+
? 'h-12 flex-row items-center border-t border-zinc-200 dark:border-zinc-800'
|
|
93
|
+
: 'w-48 flex-col border-r border-zinc-200 dark:border-zinc-800'
|
|
94
|
+
} ${className}`}
|
|
95
|
+
aria-label="History panel"
|
|
96
|
+
>
|
|
97
|
+
{headerEl}
|
|
98
|
+
<p className="px-3 text-[10px] text-zinc-400">No history yet</p>
|
|
99
|
+
</aside>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (horizontal) {
|
|
104
|
+
// 横向布局:header | entries(横向滚动)
|
|
105
|
+
return (
|
|
106
|
+
<aside
|
|
107
|
+
className={`flex h-12 shrink-0 items-stretch border-t border-zinc-200 dark:border-zinc-800 ${className}`}
|
|
108
|
+
aria-label="History panel"
|
|
109
|
+
>
|
|
110
|
+
{headerEl}
|
|
111
|
+
<ol className="flex flex-1 items-center gap-1 overflow-x-auto px-2">
|
|
112
|
+
{/* 初始状态项 */}
|
|
113
|
+
<li className="shrink-0">
|
|
114
|
+
<button
|
|
115
|
+
type="button"
|
|
116
|
+
onClick={() => void jumpTo(-1)}
|
|
117
|
+
className={`flex items-center gap-1.5 rounded px-2 py-1 text-[10px] transition-colors ${
|
|
118
|
+
cursor === -1
|
|
119
|
+
? 'bg-indigo-50 text-indigo-700 ring-1 ring-indigo-200 dark:bg-indigo-950/30 dark:text-indigo-300 dark:ring-indigo-800'
|
|
120
|
+
: 'text-zinc-500 hover:bg-zinc-50 dark:hover:bg-zinc-800'
|
|
121
|
+
}`}
|
|
122
|
+
>
|
|
123
|
+
<span className="h-1.5 w-1.5 shrink-0 rounded-full bg-zinc-300 dark:bg-zinc-600" aria-hidden="true" />
|
|
124
|
+
<span className="truncate">Initial</span>
|
|
125
|
+
</button>
|
|
126
|
+
</li>
|
|
127
|
+
{entries.map((entry, i) => {
|
|
128
|
+
const isCurrent = i === cursor;
|
|
129
|
+
const isRedoBranch = i > cursor;
|
|
130
|
+
return (
|
|
131
|
+
<li key={entry.id} className="shrink-0">
|
|
132
|
+
<button
|
|
133
|
+
type="button"
|
|
134
|
+
onClick={() => void jumpTo(i)}
|
|
135
|
+
aria-current={isCurrent ? 'step' : undefined}
|
|
136
|
+
className={`flex items-center gap-1.5 rounded px-2 py-1 text-[10px] transition-colors ${
|
|
137
|
+
isCurrent
|
|
138
|
+
? 'bg-indigo-50 text-indigo-700 ring-1 ring-indigo-200 dark:bg-indigo-950/30 dark:text-indigo-300 dark:ring-indigo-800'
|
|
139
|
+
: isRedoBranch
|
|
140
|
+
? 'text-zinc-300 hover:bg-zinc-50 dark:text-zinc-600 dark:hover:bg-zinc-800/50'
|
|
141
|
+
: 'text-zinc-600 hover:bg-zinc-50 dark:text-zinc-300 dark:hover:bg-zinc-800'
|
|
142
|
+
}`}
|
|
143
|
+
>
|
|
144
|
+
<span
|
|
145
|
+
className={`h-1.5 w-1.5 shrink-0 rounded-full ${
|
|
146
|
+
isCurrent
|
|
147
|
+
? 'bg-indigo-500'
|
|
148
|
+
: isRedoBranch
|
|
149
|
+
? 'bg-zinc-200 dark:bg-zinc-700'
|
|
150
|
+
: 'bg-zinc-400 dark:bg-zinc-500'
|
|
151
|
+
}`}
|
|
152
|
+
aria-hidden="true"
|
|
153
|
+
/>
|
|
154
|
+
<span className="truncate font-medium">{describeHistoryEntry(entry)}</span>
|
|
155
|
+
</button>
|
|
156
|
+
</li>
|
|
157
|
+
);
|
|
158
|
+
})}
|
|
159
|
+
</ol>
|
|
160
|
+
</aside>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 垂直布局(原实现)
|
|
48
165
|
return (
|
|
49
166
|
<aside
|
|
50
|
-
className={`flex
|
|
167
|
+
className={`flex w-48 shrink-0 flex-col border-r border-zinc-200 dark:border-zinc-800 ${className}`}
|
|
168
|
+
aria-label="History panel"
|
|
51
169
|
>
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
170
|
+
{headerEl}
|
|
171
|
+
<div className="flex-1 overflow-y-auto px-2 py-2">
|
|
172
|
+
<ol className="space-y-0.5">
|
|
173
|
+
{/* 初始状态项(index=-1) */}
|
|
174
|
+
<li>
|
|
175
|
+
<button
|
|
176
|
+
type="button"
|
|
177
|
+
onClick={() => void jumpTo(-1)}
|
|
178
|
+
className={`flex w-full items-center gap-1.5 rounded px-2 py-1 text-left text-[10px] transition-colors ${
|
|
179
|
+
cursor === -1
|
|
180
|
+
? 'bg-indigo-50 text-indigo-700 ring-1 ring-indigo-200 dark:bg-indigo-950/30 dark:text-indigo-300 dark:ring-indigo-800'
|
|
181
|
+
: 'text-zinc-500 hover:bg-zinc-50 dark:hover:bg-zinc-800'
|
|
182
|
+
}`}
|
|
183
|
+
>
|
|
184
|
+
<span className="h-1.5 w-1.5 shrink-0 rounded-full bg-zinc-300 dark:bg-zinc-600" aria-hidden="true" />
|
|
185
|
+
<span className="truncate">Initial</span>
|
|
186
|
+
</button>
|
|
187
|
+
</li>
|
|
188
|
+
{entries.map((entry, i) => {
|
|
189
|
+
const isCurrent = i === cursor;
|
|
190
|
+
const isRedoBranch = i > cursor;
|
|
191
|
+
return (
|
|
192
|
+
<li key={entry.id}>
|
|
193
|
+
<button
|
|
194
|
+
type="button"
|
|
195
|
+
onClick={() => void jumpTo(i)}
|
|
196
|
+
aria-current={isCurrent ? 'step' : undefined}
|
|
197
|
+
className={`flex w-full items-start gap-1.5 rounded px-2 py-1 text-left text-[10px] transition-colors ${
|
|
198
|
+
isCurrent
|
|
199
|
+
? 'bg-indigo-50 text-indigo-700 ring-1 ring-indigo-200 dark:bg-indigo-950/30 dark:text-indigo-300 dark:ring-indigo-800'
|
|
200
|
+
: isRedoBranch
|
|
201
|
+
? 'text-zinc-300 hover:bg-zinc-50 dark:text-zinc-600 dark:hover:bg-zinc-800/50'
|
|
202
|
+
: 'text-zinc-600 hover:bg-zinc-50 dark:text-zinc-300 dark:hover:bg-zinc-800'
|
|
203
|
+
}`}
|
|
204
|
+
>
|
|
205
|
+
<span
|
|
206
|
+
className={`mt-0.5 h-1.5 w-1.5 shrink-0 rounded-full ${
|
|
207
|
+
isCurrent
|
|
208
|
+
? 'bg-indigo-500'
|
|
209
|
+
: isRedoBranch
|
|
210
|
+
? 'bg-zinc-200 dark:bg-zinc-700'
|
|
211
|
+
: 'bg-zinc-400 dark:bg-zinc-500'
|
|
212
|
+
}`}
|
|
213
|
+
aria-hidden="true"
|
|
214
|
+
/>
|
|
215
|
+
<div className="min-w-0 flex-1">
|
|
216
|
+
<div className="truncate font-medium">
|
|
217
|
+
{describeHistoryEntry(entry)}
|
|
218
|
+
</div>
|
|
219
|
+
<div className="text-[9px] text-zinc-400">
|
|
220
|
+
{new Date(entry.timestamp).toLocaleTimeString()}
|
|
221
|
+
</div>
|
|
222
|
+
</div>
|
|
223
|
+
</button>
|
|
85
224
|
</li>
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
|
|
225
|
+
);
|
|
226
|
+
})}
|
|
227
|
+
</ol>
|
|
89
228
|
</div>
|
|
90
229
|
</aside>
|
|
91
230
|
);
|
|
92
231
|
}
|
|
93
232
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return `Node finished: ${e.nodeId.slice(0, 8)} (${e.duration}ms)`;
|
|
114
|
-
case 'node:failed':
|
|
115
|
-
return `Node failed: ${e.error.message}`;
|
|
116
|
-
case 'plugin:loaded':
|
|
117
|
-
return `Plugin loaded: ${e.name}@${e.version}`;
|
|
118
|
-
case 'export:completed':
|
|
119
|
-
return `Exported ${e.format} (${(e.size / 1024).toFixed(1)} KB)`;
|
|
120
|
-
case 'capability:registered':
|
|
121
|
-
return `Capability registered: ${e.capability} (${e.engine})`;
|
|
122
|
-
case 'history:changed':
|
|
123
|
-
return `History changed (${e.entries.length} entries)`;
|
|
124
|
-
default:
|
|
125
|
-
return (e as { type: string }).type;
|
|
233
|
+
/** 把 HistoryEntry 摘要为可读标签(capability 简称 + 关键参数) */
|
|
234
|
+
function describeHistoryEntry(entry: HistoryEntry): string {
|
|
235
|
+
// image.resize → Resize;image.watermark → Watermark
|
|
236
|
+
const short = entry.capability.replace(/^image\./, '');
|
|
237
|
+
const cap = short.charAt(0).toUpperCase() + short.slice(1);
|
|
238
|
+
const params = entry.params ?? {};
|
|
239
|
+
// 摘取 1-2 个关键参数作为提示
|
|
240
|
+
const hints: string[] = [];
|
|
241
|
+
if (typeof params.width === 'number' || typeof params.width === 'string') {
|
|
242
|
+
hints.push(`${params.width}w`);
|
|
243
|
+
}
|
|
244
|
+
if (typeof params.quality === 'number') {
|
|
245
|
+
hints.push(`q${params.quality}`);
|
|
246
|
+
}
|
|
247
|
+
if (typeof params.format === 'string') {
|
|
248
|
+
hints.push(String(params.format));
|
|
249
|
+
}
|
|
250
|
+
if (typeof params.text === 'string' && params.text) {
|
|
251
|
+
hints.push(`"${String(params.text).slice(0, 8)}"`);
|
|
126
252
|
}
|
|
253
|
+
return hints.length > 0 ? `${cap} (${hints.join(' ')})` : cap;
|
|
127
254
|
}
|
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import * as React from 'react';
|
|
9
|
+
import { Icon } from '@lokvis/ui-core';
|
|
9
10
|
import { useWorkspaceStore } from '../store/index.js';
|
|
10
11
|
import { ParamForm } from './ParamForm.js';
|
|
12
|
+
import { ExifPanel } from './ExifPanel.js';
|
|
11
13
|
|
|
12
14
|
export interface InspectorProps {
|
|
13
15
|
className?: string;
|
|
@@ -48,6 +50,9 @@ export function Inspector({ className = '' }: InspectorProps) {
|
|
|
48
50
|
<aside
|
|
49
51
|
className={`flex w-72 shrink-0 flex-col border-l border-zinc-200 dark:border-zinc-800 ${className}`}
|
|
50
52
|
>
|
|
53
|
+
{/* EXIF panel (selected image asset only, hides automatically for non-image) */}
|
|
54
|
+
<ExifPanel />
|
|
55
|
+
|
|
51
56
|
{/* Configure section (when a node is selected) */}
|
|
52
57
|
{showConfigure && (
|
|
53
58
|
<div className="shrink-0 border-b border-zinc-200 dark:border-zinc-800">
|
|
@@ -57,7 +62,7 @@ export function Inspector({ className = '' }: InspectorProps) {
|
|
|
57
62
|
className="flex w-full items-center justify-between px-3 h-10 text-left transition-colors hover:bg-zinc-50 dark:hover:bg-zinc-800/50"
|
|
58
63
|
>
|
|
59
64
|
<div className="flex items-center gap-2">
|
|
60
|
-
<
|
|
65
|
+
<Icon size={12} className={`text-zinc-400 transition-transform ${configureOpen ? 'rotate-90' : ''}`}><path d="m9 5 7 7-7 7" /></Icon>
|
|
61
66
|
<span className="text-[11px] font-semibold uppercase tracking-wider text-zinc-400">Configure</span>
|
|
62
67
|
</div>
|
|
63
68
|
<span className="font-mono text-[10px] text-indigo-500 bg-indigo-50 dark:bg-indigo-950/30 px-1.5 py-0.5 rounded">
|
|
@@ -88,7 +93,7 @@ export function Inspector({ className = '' }: InspectorProps) {
|
|
|
88
93
|
{/* Search */}
|
|
89
94
|
<div className="px-2 py-2 border-b border-zinc-100 dark:border-zinc-800/50">
|
|
90
95
|
<div className="relative">
|
|
91
|
-
<
|
|
96
|
+
<Icon size={12} className="absolute left-2 top-1/2 -translate-y-1/2 text-zinc-400"><circle cx="11" cy="11" r="8" /><path d="m21 21-4.3-4.3" /></Icon>
|
|
92
97
|
<input
|
|
93
98
|
type="text"
|
|
94
99
|
placeholder="Search capabilities..."
|