@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
|
@@ -6,6 +6,7 @@
|
|
|
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
|
|
|
11
12
|
export interface PipelineBarProps {
|
|
@@ -32,14 +33,14 @@ export function PipelineBar({ className = '' }: PipelineBarProps) {
|
|
|
32
33
|
<div className="flex flex-1 items-center gap-1 overflow-x-auto min-w-0">
|
|
33
34
|
{/* Source indicator */}
|
|
34
35
|
<div className="flex items-center gap-1 rounded-md bg-zinc-100 px-2 py-1 text-[10px] font-medium text-zinc-500 dark:bg-zinc-800 dark:text-zinc-400 shrink-0">
|
|
35
|
-
<
|
|
36
|
+
<Icon size={12}><path d="M12 4.5v15m7.5-7.5h-15" /></Icon>
|
|
36
37
|
Source
|
|
37
38
|
</div>
|
|
38
39
|
|
|
39
40
|
{/* Arrow */}
|
|
40
|
-
<
|
|
41
|
-
<path
|
|
42
|
-
</
|
|
41
|
+
<Icon size={12} className="shrink-0 text-zinc-300 dark:text-zinc-600">
|
|
42
|
+
<path d="m9 5 7 7-7 7" />
|
|
43
|
+
</Icon>
|
|
43
44
|
|
|
44
45
|
{/* Nodes */}
|
|
45
46
|
{nodes.map((node, i) => {
|
|
@@ -72,26 +73,26 @@ export function PipelineBar({ className = '' }: PipelineBarProps) {
|
|
|
72
73
|
role="button"
|
|
73
74
|
aria-label="Remove step"
|
|
74
75
|
>
|
|
75
|
-
<
|
|
76
|
+
<Icon size={10} strokeWidth={3}><path d="M6 18L18 6M6 6l12 12" /></Icon>
|
|
76
77
|
</span>
|
|
77
78
|
</button>
|
|
78
79
|
|
|
79
80
|
{/* Arrow between nodes */}
|
|
80
81
|
{i < nodes.length - 1 && (
|
|
81
|
-
<
|
|
82
|
-
<path
|
|
83
|
-
</
|
|
82
|
+
<Icon size={12} className="shrink-0 text-zinc-300 dark:text-zinc-600">
|
|
83
|
+
<path d="m9 5 7 7-7 7" />
|
|
84
|
+
</Icon>
|
|
84
85
|
)}
|
|
85
86
|
</React.Fragment>
|
|
86
87
|
);
|
|
87
88
|
})}
|
|
88
89
|
|
|
89
90
|
{/* Output indicator */}
|
|
90
|
-
<
|
|
91
|
-
<path
|
|
92
|
-
</
|
|
91
|
+
<Icon size={12} className="shrink-0 text-zinc-300 dark:text-zinc-600">
|
|
92
|
+
<path d="m9 5 7 7-7 7" />
|
|
93
|
+
</Icon>
|
|
93
94
|
<div className="flex items-center gap-1 rounded-md bg-zinc-100 px-2 py-1 text-[10px] font-medium text-zinc-500 dark:bg-zinc-800 dark:text-zinc-400 shrink-0">
|
|
94
|
-
<
|
|
95
|
+
<Icon size={12}><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.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3" /></Icon>
|
|
95
96
|
Output
|
|
96
97
|
</div>
|
|
97
98
|
</div>
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProgressBar - 工作流执行进度条 + 取消按钮(W11.6)
|
|
3
|
+
*
|
|
4
|
+
* 展示:
|
|
5
|
+
* - 节点完成进度(成功数 / 总数)
|
|
6
|
+
* - 横向进度条(running 时动画)
|
|
7
|
+
* - Cancel 按钮(调用 cancelRun)
|
|
8
|
+
* - 状态消息(statusMessage)
|
|
9
|
+
*
|
|
10
|
+
* 仅在 running 或最近一次执行有结果时显示。
|
|
11
|
+
*
|
|
12
|
+
* @module ProgressBar
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { Icon } from '@lokvis/ui-core';
|
|
16
|
+
import { useWorkspaceStore } from '../store/index.js';
|
|
17
|
+
import { useWorkflowProgress } from '../hooks/useWorkflowProgress.js';
|
|
18
|
+
|
|
19
|
+
export interface ProgressBarProps {
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function ProgressBar({ className = '' }: ProgressBarProps) {
|
|
24
|
+
const running = useWorkspaceStore((s) => s.running);
|
|
25
|
+
const statusMessage = useWorkspaceStore((s) => s.statusMessage);
|
|
26
|
+
const cancelRun = useWorkspaceStore((s) => s.cancelRun);
|
|
27
|
+
|
|
28
|
+
// 进度计算抽取到共享 hook(与 StatusBar 共用,避免重复逻辑)
|
|
29
|
+
const { total, done, failedCount, pct, hasFailure } = useWorkflowProgress();
|
|
30
|
+
|
|
31
|
+
// 没有节点或未运行且无最近结果时不渲染
|
|
32
|
+
if (total === 0) return null;
|
|
33
|
+
if (!running && done === 0) return null;
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<div
|
|
37
|
+
className={`flex items-center gap-2 border-b border-zinc-200 bg-white px-3 py-1.5 dark:border-zinc-800 dark:bg-zinc-900 ${className}`}
|
|
38
|
+
role="status"
|
|
39
|
+
aria-live="polite"
|
|
40
|
+
aria-label={`工作流进度:${done} / ${total}`}
|
|
41
|
+
>
|
|
42
|
+
{/* 进度条 */}
|
|
43
|
+
<div className="relative h-1.5 flex-1 overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-800">
|
|
44
|
+
<div
|
|
45
|
+
className={`absolute inset-y-0 left-0 transition-all duration-300 ${
|
|
46
|
+
hasFailure
|
|
47
|
+
? 'bg-red-500'
|
|
48
|
+
: running
|
|
49
|
+
? 'bg-indigo-500'
|
|
50
|
+
: 'bg-emerald-500'
|
|
51
|
+
} ${running ? 'animate-pulse' : ''}`}
|
|
52
|
+
style={{ width: `${pct}%` }}
|
|
53
|
+
/>
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
{/* 计数 */}
|
|
57
|
+
<span className="shrink-0 text-[10px] font-medium tabular-nums text-zinc-500 dark:text-zinc-400">
|
|
58
|
+
{done}/{total}
|
|
59
|
+
{failedCount > 0 && (
|
|
60
|
+
<span className="ml-1 text-red-500">({failedCount} failed)</span>
|
|
61
|
+
)}
|
|
62
|
+
</span>
|
|
63
|
+
|
|
64
|
+
{/* 状态消息(running 时显示) */}
|
|
65
|
+
{running && statusMessage && (
|
|
66
|
+
<span className="hidden shrink-0 truncate text-[10px] text-zinc-400 sm:inline">
|
|
67
|
+
{statusMessage}
|
|
68
|
+
</span>
|
|
69
|
+
)}
|
|
70
|
+
|
|
71
|
+
{/* Cancel 按钮(仅 running 时) */}
|
|
72
|
+
{running && (
|
|
73
|
+
<button
|
|
74
|
+
type="button"
|
|
75
|
+
onClick={() => void cancelRun()}
|
|
76
|
+
aria-label="取消运行"
|
|
77
|
+
title="取消运行"
|
|
78
|
+
className="flex shrink-0 items-center gap-1 rounded-md bg-red-50 px-2 py-0.5 text-[10px] font-medium text-red-600 transition-colors hover:bg-red-100 dark:bg-red-950/30 dark:text-red-400 dark:hover:bg-red-900/40"
|
|
79
|
+
>
|
|
80
|
+
<Icon size={10} strokeWidth={3}><path d="M6 6l12 12M6 18L18 6" /></Icon>
|
|
81
|
+
Cancel
|
|
82
|
+
</button>
|
|
83
|
+
)}
|
|
84
|
+
|
|
85
|
+
{/* 完成图标(非 running 且有结果) */}
|
|
86
|
+
{!running && done === total && (
|
|
87
|
+
<span
|
|
88
|
+
className={`flex shrink-0 items-center gap-1 text-[10px] font-medium ${
|
|
89
|
+
hasFailure ? 'text-red-500' : 'text-emerald-500'
|
|
90
|
+
}`}
|
|
91
|
+
>
|
|
92
|
+
<Icon size={10} strokeWidth={3}>
|
|
93
|
+
{hasFailure ? (
|
|
94
|
+
<path d="M12 2L2 22h20L12 2zM12 9v5M12 17v.01" />
|
|
95
|
+
) : (
|
|
96
|
+
<path d="M20 6L9 17l-5-5" />
|
|
97
|
+
)}
|
|
98
|
+
</Icon>
|
|
99
|
+
{hasFailure ? 'Failed' : 'Done'}
|
|
100
|
+
</span>
|
|
101
|
+
)}
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -1,15 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* StatusBar - 底部状态栏
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 紧凑单行:左侧状态指示 + 当前工具 + 进度,右侧在线状态 + 资源统计 + 存储配额。
|
|
5
|
+
*
|
|
6
|
+
* W9.6 新增:
|
|
7
|
+
* - 当前选中工具名(从 selectedNode 取)
|
|
8
|
+
* - 执行进度(已完成节点数 / 总节点数)
|
|
9
|
+
* - 在线状态(navigator.onLine + 事件监听)
|
|
5
10
|
*/
|
|
6
11
|
|
|
12
|
+
import * as React from 'react';
|
|
7
13
|
import { useWorkspaceStore } from '../store/index.js';
|
|
14
|
+
import { useWorkflowProgress } from '../hooks/useWorkflowProgress.js';
|
|
8
15
|
|
|
9
16
|
export interface StatusBarProps {
|
|
10
17
|
className?: string;
|
|
11
18
|
}
|
|
12
19
|
|
|
20
|
+
/** 格式化字节数为人类可读(KB/MB/GB) */
|
|
21
|
+
function formatBytes(bytes: number): string {
|
|
22
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
23
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
24
|
+
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
25
|
+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** useOnlineStatus - 监听 navigator.onLine + online/offline 事件(W9.6) */
|
|
29
|
+
function useOnlineStatus(): boolean {
|
|
30
|
+
const [online, setOnline] = React.useState<boolean>(() =>
|
|
31
|
+
typeof navigator !== 'undefined' ? navigator.onLine : true
|
|
32
|
+
);
|
|
33
|
+
React.useEffect(() => {
|
|
34
|
+
const onOnline = () => setOnline(true);
|
|
35
|
+
const onOffline = () => setOnline(false);
|
|
36
|
+
window.addEventListener('online', onOnline);
|
|
37
|
+
window.addEventListener('offline', onOffline);
|
|
38
|
+
return () => {
|
|
39
|
+
window.removeEventListener('online', onOnline);
|
|
40
|
+
window.removeEventListener('offline', onOffline);
|
|
41
|
+
};
|
|
42
|
+
}, []);
|
|
43
|
+
return online;
|
|
44
|
+
}
|
|
45
|
+
|
|
13
46
|
export function StatusBar({ className = '' }: StatusBarProps) {
|
|
14
47
|
const statusMessage = useWorkspaceStore((s) => s.statusMessage);
|
|
15
48
|
const error = useWorkspaceStore((s) => s.error);
|
|
@@ -17,14 +50,32 @@ export function StatusBar({ className = '' }: StatusBarProps) {
|
|
|
17
50
|
const assets = useWorkspaceStore((s) => s.assets);
|
|
18
51
|
const capabilities = useWorkspaceStore((s) => s.capabilities);
|
|
19
52
|
const nodes = useWorkspaceStore((s) => s.nodes);
|
|
53
|
+
const selectedNodeId = useWorkspaceStore((s) => s.selectedNodeId);
|
|
54
|
+
const storageUsage = useWorkspaceStore((s) => s.storageUsage);
|
|
20
55
|
const setError = useWorkspaceStore((s) => s.setError);
|
|
56
|
+
const online = useOnlineStatus();
|
|
57
|
+
|
|
58
|
+
// W9.6 当前选中工具名
|
|
59
|
+
const selectedNode = nodes.find((n) => n.id === selectedNodeId);
|
|
60
|
+
|
|
61
|
+
// W9.6 执行进度(抽取到共享 hook,与 ProgressBar 共用,避免重复逻辑)
|
|
62
|
+
const { total: totalNodes, done: doneNodes, pct: progressPct } = useWorkflowProgress();
|
|
63
|
+
|
|
64
|
+
// W6.7 存储配额压力:>=95% 红(临界),>=80% 琥珀(警告),其余正常
|
|
65
|
+
const ratio = storageUsage ? storageUsage.usage / storageUsage.quota : 0;
|
|
66
|
+
const storageCritical = ratio >= 0.95;
|
|
67
|
+
const storageWarning = ratio >= 0.8 && !storageCritical;
|
|
21
68
|
|
|
22
69
|
return (
|
|
23
70
|
<footer
|
|
24
71
|
className={`flex h-7 shrink-0 items-center justify-between border-t border-zinc-200 bg-zinc-50 px-3 dark:border-zinc-800 dark:bg-zinc-950 ${className}`}
|
|
25
72
|
>
|
|
26
|
-
{/* Left: Status */}
|
|
27
|
-
<div
|
|
73
|
+
{/* Left: Status — m5 加 aria-live,屏幕阅读器播报状态变化 */}
|
|
74
|
+
<div
|
|
75
|
+
className="flex items-center gap-2 min-w-0"
|
|
76
|
+
role="status"
|
|
77
|
+
aria-live="polite"
|
|
78
|
+
>
|
|
28
79
|
<span className="flex items-center gap-1.5">
|
|
29
80
|
<span
|
|
30
81
|
className={`h-1.5 w-1.5 rounded-full shrink-0 ${
|
|
@@ -34,11 +85,33 @@ export function StatusBar({ className = '' }: StatusBarProps) {
|
|
|
34
85
|
? 'bg-amber-500 animate-pulse'
|
|
35
86
|
: 'bg-emerald-500'
|
|
36
87
|
}`}
|
|
88
|
+
aria-hidden="true"
|
|
37
89
|
/>
|
|
38
90
|
<span className={`truncate text-[10px] ${error ? 'text-red-500' : 'text-zinc-500'}`}>
|
|
39
91
|
{statusMessage}
|
|
40
92
|
</span>
|
|
41
93
|
</span>
|
|
94
|
+
|
|
95
|
+
{/* W9.6 当前工具名 */}
|
|
96
|
+
{selectedNode && (
|
|
97
|
+
<>
|
|
98
|
+
<span className="text-zinc-300 dark:text-zinc-700" aria-hidden="true">·</span>
|
|
99
|
+
<span className="shrink-0 font-mono text-[10px] text-indigo-500 dark:text-indigo-400 truncate max-w-[120px]">
|
|
100
|
+
{selectedNode.capability}
|
|
101
|
+
</span>
|
|
102
|
+
</>
|
|
103
|
+
)}
|
|
104
|
+
|
|
105
|
+
{/* W9.6 执行进度 */}
|
|
106
|
+
{running && totalNodes > 0 && (
|
|
107
|
+
<>
|
|
108
|
+
<span className="text-zinc-300 dark:text-zinc-700" aria-hidden="true">·</span>
|
|
109
|
+
<span className="shrink-0 tabular-nums text-[10px] text-amber-600 dark:text-amber-400">
|
|
110
|
+
{doneNodes}/{totalNodes} ({progressPct}%)
|
|
111
|
+
</span>
|
|
112
|
+
</>
|
|
113
|
+
)}
|
|
114
|
+
|
|
42
115
|
{error && (
|
|
43
116
|
<button
|
|
44
117
|
type="button"
|
|
@@ -52,10 +125,56 @@ export function StatusBar({ className = '' }: StatusBarProps) {
|
|
|
52
125
|
|
|
53
126
|
{/* Right: Stats */}
|
|
54
127
|
<div className="flex items-center gap-3 shrink-0 text-[10px] text-zinc-400 tabular-nums">
|
|
128
|
+
{/* W9.6 在线状态 */}
|
|
129
|
+
<span
|
|
130
|
+
className={`flex items-center gap-1 ${online ? 'text-emerald-500' : 'text-amber-500'}`}
|
|
131
|
+
title={online ? 'Online' : 'Offline — running locally, no upload needed'}
|
|
132
|
+
aria-label={online ? 'Online' : 'Offline — files still processed locally'}
|
|
133
|
+
>
|
|
134
|
+
<span className={`h-1.5 w-1.5 rounded-full ${online ? 'bg-emerald-500' : 'bg-amber-500'}`} aria-hidden="true" />
|
|
135
|
+
{online ? 'Online' : 'Offline'}
|
|
136
|
+
</span>
|
|
137
|
+
<span className="text-zinc-300 dark:text-zinc-700" aria-hidden="true">|</span>
|
|
138
|
+
|
|
139
|
+
{/* W6.7 存储配额:接近上限时变色警告;m5 加 aria-label 让屏幕阅读器播报告警 */}
|
|
140
|
+
{storageUsage && (
|
|
141
|
+
<>
|
|
142
|
+
<span
|
|
143
|
+
className={`flex items-center gap-1 ${
|
|
144
|
+
storageCritical
|
|
145
|
+
? 'text-red-500 font-semibold'
|
|
146
|
+
: storageWarning
|
|
147
|
+
? 'text-amber-500'
|
|
148
|
+
: 'text-zinc-400'
|
|
149
|
+
}`}
|
|
150
|
+
title={
|
|
151
|
+
storageCritical
|
|
152
|
+
? `Storage almost full (${Math.round(ratio * 100)}%) — clean up to free space`
|
|
153
|
+
: storageWarning
|
|
154
|
+
? `Storage nearing limit (${Math.round(ratio * 100)}%)`
|
|
155
|
+
: `Storage: ${formatBytes(storageUsage.usage)} of ${formatBytes(storageUsage.quota)}`
|
|
156
|
+
}
|
|
157
|
+
aria-label={
|
|
158
|
+
storageCritical
|
|
159
|
+
? `Storage critical: ${formatBytes(storageUsage.usage)} of ${formatBytes(storageUsage.quota)} used, ${Math.round(ratio * 100)} percent. Clean up to free space.`
|
|
160
|
+
: storageWarning
|
|
161
|
+
? `Storage warning: ${formatBytes(storageUsage.usage)} of ${formatBytes(storageUsage.quota)} used, ${Math.round(ratio * 100)} percent.`
|
|
162
|
+
: `Storage: ${formatBytes(storageUsage.usage)} of ${formatBytes(storageUsage.quota)} used.`
|
|
163
|
+
}
|
|
164
|
+
aria-live={storageCritical ? 'assertive' : 'polite'}
|
|
165
|
+
>
|
|
166
|
+
{(storageCritical || storageWarning) && (
|
|
167
|
+
<span className="text-[9px]" aria-hidden="true">⚠</span>
|
|
168
|
+
)}
|
|
169
|
+
{formatBytes(storageUsage.usage)} / {formatBytes(storageUsage.quota)}
|
|
170
|
+
</span>
|
|
171
|
+
<span className="text-zinc-300 dark:text-zinc-700" aria-hidden="true">|</span>
|
|
172
|
+
</>
|
|
173
|
+
)}
|
|
55
174
|
<span>{assets.length} asset{assets.length !== 1 ? 's' : ''}</span>
|
|
56
|
-
<span className="text-zinc-300 dark:text-zinc-700">|</span>
|
|
175
|
+
<span className="text-zinc-300 dark:text-zinc-700" aria-hidden="true">|</span>
|
|
57
176
|
<span>{capabilities.length} cap{capabilities.length !== 1 ? 's' : ''}</span>
|
|
58
|
-
<span className="text-zinc-300 dark:text-zinc-700">|</span>
|
|
177
|
+
<span className="text-zinc-300 dark:text-zinc-700" aria-hidden="true">|</span>
|
|
59
178
|
<span>{nodes.length} step{nodes.length !== 1 ? 's' : ''}</span>
|
|
60
179
|
</div>
|
|
61
180
|
</footer>
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ThemeToggle - 暗色模式切换按钮(W9.7)
|
|
3
|
+
*
|
|
4
|
+
* 使用 `useTheme()` hook 读写 localStorage + 跟随系统偏好。
|
|
5
|
+
* 与 `tokens.css` 的 `.dark` / `.light` 类双触发机制对齐。
|
|
6
|
+
*
|
|
7
|
+
* 交互:
|
|
8
|
+
* - 左键单击:在 light / dark 之间切换(基于当前 resolvedTheme 决定下一态)
|
|
9
|
+
* - 右键单击:弹出菜单(light / dark / system 三态)
|
|
10
|
+
* - ESC:关闭菜单
|
|
11
|
+
* - 点击菜单外部:关闭菜单
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import * as React from 'react';
|
|
15
|
+
import { Icon } from '@lokvis/ui-core';
|
|
16
|
+
import { useTheme, type ThemeMode } from '../hooks/useTheme.js';
|
|
17
|
+
|
|
18
|
+
export interface ThemeToggleProps {
|
|
19
|
+
className?: string;
|
|
20
|
+
/** 是否显示文字标签(默认仅图标) */
|
|
21
|
+
showLabel?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function ThemeToggle({ className = '', showLabel = false }: ThemeToggleProps) {
|
|
25
|
+
const { theme, resolvedTheme, toggleTheme, setTheme } = useTheme();
|
|
26
|
+
const [menuOpen, setMenuOpen] = React.useState(false);
|
|
27
|
+
const btnRef = React.useRef<HTMLButtonElement>(null);
|
|
28
|
+
|
|
29
|
+
// 点击外部关闭菜单 + ESC 关闭
|
|
30
|
+
React.useEffect(() => {
|
|
31
|
+
if (!menuOpen) return;
|
|
32
|
+
const onDown = (e: MouseEvent) => {
|
|
33
|
+
// e.target 可能是任意 EventTarget;用 instanceof Node 类型守卫收窄,
|
|
34
|
+
// 避免 as 断言(与 WorkflowEditor 等处统一)
|
|
35
|
+
if (e.target instanceof Node && btnRef.current && !btnRef.current.contains(e.target)) {
|
|
36
|
+
setMenuOpen(false);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const onKey = (e: KeyboardEvent) => {
|
|
40
|
+
if (e.key === 'Escape') setMenuOpen(false);
|
|
41
|
+
};
|
|
42
|
+
document.addEventListener('mousedown', onDown);
|
|
43
|
+
document.addEventListener('keydown', onKey);
|
|
44
|
+
return () => {
|
|
45
|
+
document.removeEventListener('mousedown', onDown);
|
|
46
|
+
document.removeEventListener('keydown', onKey);
|
|
47
|
+
};
|
|
48
|
+
}, [menuOpen]);
|
|
49
|
+
|
|
50
|
+
const isDark = resolvedTheme === 'dark';
|
|
51
|
+
|
|
52
|
+
const icon = isDark ? (
|
|
53
|
+
<Icon size={14} strokeWidth={2}>
|
|
54
|
+
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" />
|
|
55
|
+
</Icon>
|
|
56
|
+
) : (
|
|
57
|
+
<Icon size={14} strokeWidth={2}>
|
|
58
|
+
<circle cx="12" cy="12" r="4" />
|
|
59
|
+
<path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41" />
|
|
60
|
+
</Icon>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const label = theme === null ? 'System' : theme === 'dark' ? 'Dark' : 'Light';
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div className={`relative ${className}`}>
|
|
67
|
+
<button
|
|
68
|
+
ref={btnRef}
|
|
69
|
+
type="button"
|
|
70
|
+
aria-haspopup="menu"
|
|
71
|
+
aria-expanded={menuOpen}
|
|
72
|
+
onClick={() => toggleTheme()}
|
|
73
|
+
onContextMenu={(e) => {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
setMenuOpen((v) => !v);
|
|
76
|
+
}}
|
|
77
|
+
aria-label={`Theme: ${label}. Click to toggle, right-click for options.`}
|
|
78
|
+
title={`Theme: ${label} (right-click for options)`}
|
|
79
|
+
className="flex h-8 w-8 items-center justify-center rounded-md text-zinc-500 transition-colors hover:bg-zinc-100 hover:text-zinc-700 dark:hover:bg-zinc-800 dark:hover:text-zinc-200"
|
|
80
|
+
>
|
|
81
|
+
{icon}
|
|
82
|
+
{showLabel && <span className="ml-1 text-xs">{label}</span>}
|
|
83
|
+
</button>
|
|
84
|
+
|
|
85
|
+
{menuOpen && (
|
|
86
|
+
<div
|
|
87
|
+
role="menu"
|
|
88
|
+
className="absolute right-0 top-full z-50 mt-1 w-32 overflow-hidden rounded-md border border-zinc-200 bg-white py-1 shadow-lg dark:border-zinc-800 dark:bg-zinc-900"
|
|
89
|
+
>
|
|
90
|
+
{(['light', 'dark', null] as Array<ThemeMode | null>).map((mode) => {
|
|
91
|
+
const isActive = theme === mode;
|
|
92
|
+
const text = mode === null ? 'System' : mode === 'dark' ? 'Dark' : 'Light';
|
|
93
|
+
return (
|
|
94
|
+
<button
|
|
95
|
+
key={mode ?? 'system'}
|
|
96
|
+
type="button"
|
|
97
|
+
role="menuitemradio"
|
|
98
|
+
aria-checked={isActive}
|
|
99
|
+
onClick={() => {
|
|
100
|
+
setTheme(mode);
|
|
101
|
+
setMenuOpen(false);
|
|
102
|
+
}}
|
|
103
|
+
className={`flex w-full items-center justify-between px-3 py-1.5 text-left text-xs transition-colors ${
|
|
104
|
+
isActive
|
|
105
|
+
? 'bg-indigo-50 text-indigo-700 dark:bg-indigo-950/30 dark:text-indigo-300'
|
|
106
|
+
: 'text-zinc-700 hover:bg-zinc-100 dark:text-zinc-200 dark:hover:bg-zinc-800'
|
|
107
|
+
}`}
|
|
108
|
+
>
|
|
109
|
+
<span>{text}</span>
|
|
110
|
+
{isActive && (
|
|
111
|
+
<Icon size={12} strokeWidth={3}>
|
|
112
|
+
<path d="M5 13l4 4L19 7" />
|
|
113
|
+
</Icon>
|
|
114
|
+
)}
|
|
115
|
+
</button>
|
|
116
|
+
);
|
|
117
|
+
})}
|
|
118
|
+
</div>
|
|
119
|
+
)}
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|