@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.
Files changed (160) hide show
  1. package/LICENSE +21 -0
  2. package/dist/components/AssetPanel.d.ts +2 -2
  3. package/dist/components/AssetPanel.d.ts.map +1 -1
  4. package/dist/components/AssetPanel.js +80 -7
  5. package/dist/components/AssetPanel.js.map +1 -1
  6. package/dist/components/Canvas.d.ts +9 -1
  7. package/dist/components/Canvas.d.ts.map +1 -1
  8. package/dist/components/Canvas.js +41 -3
  9. package/dist/components/Canvas.js.map +1 -1
  10. package/dist/components/CommandPalette.d.ts +48 -0
  11. package/dist/components/CommandPalette.d.ts.map +1 -0
  12. package/dist/components/CommandPalette.js +154 -0
  13. package/dist/components/CommandPalette.js.map +1 -0
  14. package/dist/components/CompareSlider.d.ts +25 -0
  15. package/dist/components/CompareSlider.d.ts.map +1 -0
  16. package/dist/components/CompareSlider.js +106 -0
  17. package/dist/components/CompareSlider.js.map +1 -0
  18. package/dist/components/DownloadPanel.d.ts +20 -0
  19. package/dist/components/DownloadPanel.d.ts.map +1 -0
  20. package/dist/components/DownloadPanel.js +169 -0
  21. package/dist/components/DownloadPanel.js.map +1 -0
  22. package/dist/components/ErrorBanner.d.ts +22 -0
  23. package/dist/components/ErrorBanner.d.ts.map +1 -0
  24. package/dist/components/ErrorBanner.js +47 -0
  25. package/dist/components/ErrorBanner.js.map +1 -0
  26. package/dist/components/ExifPanel.d.ts +26 -0
  27. package/dist/components/ExifPanel.d.ts.map +1 -0
  28. package/dist/components/ExifPanel.js +104 -0
  29. package/dist/components/ExifPanel.js.map +1 -0
  30. package/dist/components/GlobalDropzone.d.ts +37 -0
  31. package/dist/components/GlobalDropzone.d.ts.map +1 -0
  32. package/dist/components/GlobalDropzone.js +154 -0
  33. package/dist/components/GlobalDropzone.js.map +1 -0
  34. package/dist/components/HistoryPanel.d.ts +17 -7
  35. package/dist/components/HistoryPanel.d.ts.map +1 -1
  36. package/dist/components/HistoryPanel.js +74 -62
  37. package/dist/components/HistoryPanel.js.map +1 -1
  38. package/dist/components/Inspector.d.ts.map +1 -1
  39. package/dist/components/Inspector.js +3 -1
  40. package/dist/components/Inspector.js.map +1 -1
  41. package/dist/components/PipelineBar.d.ts.map +1 -1
  42. package/dist/components/PipelineBar.js +4 -3
  43. package/dist/components/PipelineBar.js.map +1 -1
  44. package/dist/components/ProgressBar.d.ts +18 -0
  45. package/dist/components/ProgressBar.d.ts.map +1 -0
  46. package/dist/components/ProgressBar.js +35 -0
  47. package/dist/components/ProgressBar.js.map +1 -0
  48. package/dist/components/StatusBar.d.ts +8 -2
  49. package/dist/components/StatusBar.d.ts.map +1 -1
  50. package/dist/components/StatusBar.js +59 -4
  51. package/dist/components/StatusBar.js.map +1 -1
  52. package/dist/components/ThemeToggle.d.ts +20 -0
  53. package/dist/components/ThemeToggle.d.ts.map +1 -0
  54. package/dist/components/ThemeToggle.js +60 -0
  55. package/dist/components/ThemeToggle.js.map +1 -0
  56. package/dist/components/WorkflowEditor.d.ts +24 -0
  57. package/dist/components/WorkflowEditor.d.ts.map +1 -0
  58. package/dist/components/WorkflowEditor.js +160 -0
  59. package/dist/components/WorkflowEditor.js.map +1 -0
  60. package/dist/components/WorkflowTemplates.d.ts +23 -0
  61. package/dist/components/WorkflowTemplates.d.ts.map +1 -0
  62. package/dist/components/WorkflowTemplates.js +32 -0
  63. package/dist/components/WorkflowTemplates.js.map +1 -0
  64. package/dist/components/Workspace.d.ts +48 -2
  65. package/dist/components/Workspace.d.ts.map +1 -1
  66. package/dist/components/Workspace.js +80 -5
  67. package/dist/components/Workspace.js.map +1 -1
  68. package/dist/data/workflow-templates.d.ts +42 -0
  69. package/dist/data/workflow-templates.d.ts.map +1 -0
  70. package/dist/data/workflow-templates.js +112 -0
  71. package/dist/data/workflow-templates.js.map +1 -0
  72. package/dist/hooks/useDebouncedRun.d.ts +49 -0
  73. package/dist/hooks/useDebouncedRun.d.ts.map +1 -0
  74. package/dist/hooks/useDebouncedRun.js +117 -0
  75. package/dist/hooks/useDebouncedRun.js.map +1 -0
  76. package/dist/hooks/useLokvis.js +1 -1
  77. package/dist/hooks/useMediaQuery.d.ts +27 -0
  78. package/dist/hooks/useMediaQuery.d.ts.map +1 -0
  79. package/dist/hooks/useMediaQuery.js +41 -0
  80. package/dist/hooks/useMediaQuery.js.map +1 -0
  81. package/dist/hooks/useShareLink.d.ts +58 -0
  82. package/dist/hooks/useShareLink.d.ts.map +1 -0
  83. package/dist/hooks/useShareLink.js +120 -0
  84. package/dist/hooks/useShareLink.js.map +1 -0
  85. package/dist/hooks/useTheme.d.ts +30 -0
  86. package/dist/hooks/useTheme.d.ts.map +1 -0
  87. package/dist/hooks/useTheme.js +105 -0
  88. package/dist/hooks/useTheme.js.map +1 -0
  89. package/dist/hooks/useWorkflowProgress.d.ts +28 -0
  90. package/dist/hooks/useWorkflowProgress.d.ts.map +1 -0
  91. package/dist/hooks/useWorkflowProgress.js +25 -0
  92. package/dist/hooks/useWorkflowProgress.js.map +1 -0
  93. package/dist/hooks/useWorkflows.d.ts +86 -0
  94. package/dist/hooks/useWorkflows.d.ts.map +1 -0
  95. package/dist/hooks/useWorkflows.js +247 -0
  96. package/dist/hooks/useWorkflows.js.map +1 -0
  97. package/dist/index.d.ts +26 -0
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +26 -0
  100. package/dist/index.js.map +1 -1
  101. package/dist/store/assets-slice.d.ts.map +1 -1
  102. package/dist/store/assets-slice.js +19 -0
  103. package/dist/store/assets-slice.js.map +1 -1
  104. package/dist/store/history-slice.d.ts +18 -0
  105. package/dist/store/history-slice.d.ts.map +1 -0
  106. package/dist/store/history-slice.js +42 -0
  107. package/dist/store/history-slice.js.map +1 -0
  108. package/dist/store/index.d.ts +1 -0
  109. package/dist/store/index.d.ts.map +1 -1
  110. package/dist/store/index.js +3 -0
  111. package/dist/store/index.js.map +1 -1
  112. package/dist/store/runtime-slice.d.ts +10 -2
  113. package/dist/store/runtime-slice.d.ts.map +1 -1
  114. package/dist/store/runtime-slice.js +77 -28
  115. package/dist/store/runtime-slice.js.map +1 -1
  116. package/dist/store/types.d.ts +70 -1
  117. package/dist/store/types.d.ts.map +1 -1
  118. package/dist/store/types.js +10 -0
  119. package/dist/store/types.js.map +1 -1
  120. package/dist/store/workflow-slice.d.ts +1 -1
  121. package/dist/store/workflow-slice.d.ts.map +1 -1
  122. package/dist/store/workflow-slice.js +167 -20
  123. package/dist/store/workflow-slice.js.map +1 -1
  124. package/dist/store.d.ts +76 -0
  125. package/dist/store.d.ts.map +1 -0
  126. package/dist/store.js +217 -0
  127. package/dist/store.js.map +1 -0
  128. package/package.json +9 -6
  129. package/src/components/AssetPanel.tsx +154 -12
  130. package/src/components/Canvas.tsx +85 -7
  131. package/src/components/CommandPalette.tsx +300 -0
  132. package/src/components/CompareSlider.tsx +186 -0
  133. package/src/components/DownloadPanel.tsx +252 -0
  134. package/src/components/ErrorBanner.tsx +95 -0
  135. package/src/components/ExifPanel.tsx +187 -0
  136. package/src/components/GlobalDropzone.tsx +220 -0
  137. package/src/components/HistoryPanel.tsx +231 -104
  138. package/src/components/Inspector.tsx +7 -2
  139. package/src/components/PipelineBar.tsx +13 -12
  140. package/src/components/ProgressBar.tsx +104 -0
  141. package/src/components/StatusBar.tsx +124 -5
  142. package/src/components/ThemeToggle.tsx +122 -0
  143. package/src/components/WorkflowEditor.tsx +382 -0
  144. package/src/components/WorkflowTemplates.tsx +101 -0
  145. package/src/components/Workspace.tsx +207 -9
  146. package/src/data/workflow-templates.ts +137 -0
  147. package/src/hooks/useDebouncedRun.ts +151 -0
  148. package/src/hooks/useLokvis.ts +1 -1
  149. package/src/hooks/useMediaQuery.ts +53 -0
  150. package/src/hooks/useShareLink.ts +158 -0
  151. package/src/hooks/useTheme.ts +116 -0
  152. package/src/hooks/useWorkflowProgress.ts +41 -0
  153. package/src/hooks/useWorkflows.ts +326 -0
  154. package/src/index.ts +32 -0
  155. package/src/store/assets-slice.ts +19 -0
  156. package/src/store/history-slice.ts +65 -0
  157. package/src/store/index.ts +3 -0
  158. package/src/store/runtime-slice.ts +89 -32
  159. package/src/store/types.ts +71 -1
  160. 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
- * 监听 Runtime 事件,记录最近处理过的资产与工作流执行。
5
- * MVP 仅做只读展示,撤销/重做通过 Runtime API(已留接口)。
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 * as React from 'react';
9
- import type { LokvisEvent } from '@lokvis/schema';
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
- maxItems?: number;
25
+ /** 布局方向(W9.1):vertical 侧栏,horizontal 底部横条 */
26
+ variant?: 'vertical' | 'horizontal';
23
27
  }
24
28
 
25
- export function HistoryPanel({ className = '', maxItems = 50 }: HistoryPanelProps) {
26
- const runtime = useWorkspaceStore((s) => s.runtime);
27
- const [items, setItems] = React.useState<HistoryItem[]>([]);
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
- React.useEffect(() => {
30
- if (!runtime) return;
31
- const push = (e: LokvisEvent) => {
32
- const item: HistoryItem = {
33
- id: `${Date.now()}_${Math.random().toString(36).slice(2, 6)}`,
34
- type: e.type,
35
- message: formatEvent(e),
36
- timestamp: Date.now(),
37
- };
38
- setItems((prev) => [item, ...prev].slice(0, maxItems));
39
- };
40
- // 使用 onAny 订阅所有事件,避免枚举所有类型
41
- const off = runtime.eventBus.onAny(push);
42
- return () => {
43
- off();
44
- };
45
- // eslint-disable-next-line react-hooks/exhaustive-deps
46
- }, [runtime]);
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 h-32 flex-col border-t border-zinc-200 bg-zinc-50/50 dark:border-zinc-800 dark:bg-zinc-950/50 ${className}`}
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
- <div className="flex items-center justify-between border-b border-zinc-200 px-4 py-1.5 dark:border-zinc-800">
53
- <h3 className="text-xs font-semibold uppercase tracking-wide text-zinc-500">
54
- History
55
- </h3>
56
- {items.length > 0 && (
57
- <button
58
- type="button"
59
- onClick={() => setItems([])}
60
- className="text-xs text-zinc-400 hover:text-zinc-600"
61
- >
62
- Clear
63
- </button>
64
- )}
65
- </div>
66
- <div className="flex-1 overflow-x-auto overflow-y-hidden px-2 py-1.5">
67
- {items.length === 0 ? (
68
- <p className="px-2 text-xs text-zinc-400">No history yet</p>
69
- ) : (
70
- <ul className="flex h-full items-stretch gap-1.5">
71
- {items.map((item) => (
72
- <li
73
- key={item.id}
74
- className="flex w-56 flex-none flex-col justify-between rounded border border-zinc-200 bg-white px-2 py-1 text-xs dark:border-zinc-800 dark:bg-zinc-900"
75
- >
76
- <div className="flex items-center justify-between gap-2">
77
- <span className="font-mono text-[10px] text-zinc-400">
78
- {new Date(item.timestamp).toLocaleTimeString()}
79
- </span>
80
- <span className="font-mono text-[10px] text-zinc-400">{item.type}</span>
81
- </div>
82
- <div className="truncate text-zinc-600 dark:text-zinc-300" title={item.message}>
83
- {item.message}
84
- </div>
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
- </ul>
88
- )}
225
+ );
226
+ })}
227
+ </ol>
89
228
  </div>
90
229
  </aside>
91
230
  );
92
231
  }
93
232
 
94
- function formatEvent(e: LokvisEvent): string {
95
- switch (e.type) {
96
- case 'asset:imported':
97
- return `Imported ${e.metadata.mimeType}`;
98
- case 'asset:removed':
99
- return `Removed asset ${e.assetId.slice(0, 8)}`;
100
- case 'workflow:started':
101
- return `Workflow started: ${e.workflowId.slice(0, 8)}`;
102
- case 'workflow:completed':
103
- return `Workflow ${e.result.status} in ${e.result.duration}ms`;
104
- case 'workflow:cancelled':
105
- return 'Workflow cancelled';
106
- case 'workflow:paused':
107
- return 'Workflow paused';
108
- case 'workflow:resumed':
109
- return 'Workflow resumed';
110
- case 'node:started':
111
- return `Node started: ${e.nodeId.slice(0, 8)}`;
112
- case 'node:finished':
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
- <svg className={`h-3 w-3 text-zinc-400 transition-transform ${configureOpen ? 'rotate-90' : ''}`} fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}><path strokeLinecap="round" strokeLinejoin="round" d="m9 5 7 7-7 7"/></svg>
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
- <svg className="absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-zinc-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>
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..."