@lokvis/ui-react 0.2.1 → 0.4.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.
Files changed (165) hide show
  1. package/dist/components/AssetPanel.d.ts.map +1 -1
  2. package/dist/components/AssetPanel.js +18 -62
  3. package/dist/components/AssetPanel.js.map +1 -1
  4. package/dist/components/Canvas.d.ts +4 -4
  5. package/dist/components/Canvas.d.ts.map +1 -1
  6. package/dist/components/Canvas.js +9 -9
  7. package/dist/components/Canvas.js.map +1 -1
  8. package/dist/components/CommandPalette.d.ts +7 -7
  9. package/dist/components/CommandPalette.d.ts.map +1 -1
  10. package/dist/components/CommandPalette.js +10 -10
  11. package/dist/components/CommandPalette.js.map +1 -1
  12. package/dist/components/CompareSlider.d.ts +9 -8
  13. package/dist/components/CompareSlider.d.ts.map +1 -1
  14. package/dist/components/CompareSlider.js +10 -9
  15. package/dist/components/CompareSlider.js.map +1 -1
  16. package/dist/components/DownloadPanel.d.ts +3 -3
  17. package/dist/components/DownloadPanel.d.ts.map +1 -1
  18. package/dist/components/DownloadPanel.js +10 -17
  19. package/dist/components/DownloadPanel.js.map +1 -1
  20. package/dist/components/ErrorBanner.d.ts +2 -2
  21. package/dist/components/ErrorBanner.d.ts.map +1 -1
  22. package/dist/components/ErrorBanner.js +3 -3
  23. package/dist/components/ErrorBanner.js.map +1 -1
  24. package/dist/components/ErrorBoundary.d.ts +40 -0
  25. package/dist/components/ErrorBoundary.d.ts.map +1 -0
  26. package/dist/components/ErrorBoundary.js +52 -0
  27. package/dist/components/ErrorBoundary.js.map +1 -0
  28. package/dist/components/ExifPanel.d.ts +1 -1
  29. package/dist/components/ExifPanel.d.ts.map +1 -1
  30. package/dist/components/ExifPanel.js +2 -2
  31. package/dist/components/ExifPanel.js.map +1 -1
  32. package/dist/components/GlobalDropzone.d.ts +5 -5
  33. package/dist/components/GlobalDropzone.d.ts.map +1 -1
  34. package/dist/components/GlobalDropzone.js +15 -8
  35. package/dist/components/GlobalDropzone.js.map +1 -1
  36. package/dist/components/HistoryPanel.d.ts +2 -2
  37. package/dist/components/HistoryPanel.d.ts.map +1 -1
  38. package/dist/components/HistoryPanel.js +23 -23
  39. package/dist/components/HistoryPanel.js.map +1 -1
  40. package/dist/components/Inspector.d.ts.map +1 -1
  41. package/dist/components/Inspector.js +13 -10
  42. package/dist/components/Inspector.js.map +1 -1
  43. package/dist/components/ParamForm.d.ts.map +1 -1
  44. package/dist/components/ParamForm.js +10 -7
  45. package/dist/components/ParamForm.js.map +1 -1
  46. package/dist/components/PipelineBar.d.ts.map +1 -1
  47. package/dist/components/PipelineBar.js +19 -28
  48. package/dist/components/PipelineBar.js.map +1 -1
  49. package/dist/components/ProgressBar.d.ts +4 -4
  50. package/dist/components/ProgressBar.d.ts.map +1 -1
  51. package/dist/components/ProgressBar.js +8 -8
  52. package/dist/components/ProgressBar.js.map +1 -1
  53. package/dist/components/StatusBar.d.ts +3 -3
  54. package/dist/components/StatusBar.d.ts.map +1 -1
  55. package/dist/components/StatusBar.js +12 -21
  56. package/dist/components/StatusBar.js.map +1 -1
  57. package/dist/components/StatusDot.d.ts +12 -0
  58. package/dist/components/StatusDot.d.ts.map +1 -0
  59. package/dist/components/StatusDot.js +15 -0
  60. package/dist/components/StatusDot.js.map +1 -0
  61. package/dist/components/ThemeToggle.d.ts +4 -4
  62. package/dist/components/ThemeToggle.d.ts.map +1 -1
  63. package/dist/components/ThemeToggle.js +7 -7
  64. package/dist/components/ThemeToggle.js.map +1 -1
  65. package/dist/components/ToolRunner.d.ts +53 -0
  66. package/dist/components/ToolRunner.d.ts.map +1 -0
  67. package/dist/components/ToolRunner.js +142 -0
  68. package/dist/components/ToolRunner.js.map +1 -0
  69. package/dist/components/Toolbar.d.ts.map +1 -1
  70. package/dist/components/Toolbar.js +3 -3
  71. package/dist/components/Toolbar.js.map +1 -1
  72. package/dist/components/WorkflowEditor.d.ts +6 -6
  73. package/dist/components/WorkflowEditor.d.ts.map +1 -1
  74. package/dist/components/WorkflowEditor.js +40 -49
  75. package/dist/components/WorkflowEditor.js.map +1 -1
  76. package/dist/components/WorkflowTemplates.d.ts +2 -2
  77. package/dist/components/WorkflowTemplates.d.ts.map +1 -1
  78. package/dist/components/WorkflowTemplates.js +17 -7
  79. package/dist/components/WorkflowTemplates.js.map +1 -1
  80. package/dist/components/Workspace.d.ts +45 -23
  81. package/dist/components/Workspace.d.ts.map +1 -1
  82. package/dist/components/Workspace.js +87 -40
  83. package/dist/components/Workspace.js.map +1 -1
  84. package/dist/hooks/useCustomPresets.d.ts +98 -0
  85. package/dist/hooks/useCustomPresets.d.ts.map +1 -0
  86. package/dist/hooks/useCustomPresets.js +210 -0
  87. package/dist/hooks/useCustomPresets.js.map +1 -0
  88. package/dist/hooks/useLokvis.d.ts +19 -1
  89. package/dist/hooks/useLokvis.d.ts.map +1 -1
  90. package/dist/hooks/useLokvis.js +30 -9
  91. package/dist/hooks/useLokvis.js.map +1 -1
  92. package/dist/index.d.ts +4 -0
  93. package/dist/index.d.ts.map +1 -1
  94. package/dist/index.js +6 -0
  95. package/dist/index.js.map +1 -1
  96. package/dist/store/assets-slice.d.ts +8 -1
  97. package/dist/store/assets-slice.d.ts.map +1 -1
  98. package/dist/store/assets-slice.js +101 -54
  99. package/dist/store/assets-slice.js.map +1 -1
  100. package/dist/store/capabilities-slice.d.ts +1 -1
  101. package/dist/store/capabilities-slice.d.ts.map +1 -1
  102. package/dist/store/capabilities-slice.js +8 -1
  103. package/dist/store/capabilities-slice.js.map +1 -1
  104. package/dist/store/index.d.ts +1 -1
  105. package/dist/store/index.d.ts.map +1 -1
  106. package/dist/store/index.js +1 -1
  107. package/dist/store/index.js.map +1 -1
  108. package/dist/store/runtime-slice.d.ts.map +1 -1
  109. package/dist/store/runtime-slice.js +22 -16
  110. package/dist/store/runtime-slice.js.map +1 -1
  111. package/dist/store/subscribe-utils.d.ts +45 -0
  112. package/dist/store/subscribe-utils.d.ts.map +1 -0
  113. package/dist/store/subscribe-utils.js +69 -0
  114. package/dist/store/subscribe-utils.js.map +1 -0
  115. package/dist/store/types.d.ts +19 -11
  116. package/dist/store/types.d.ts.map +1 -1
  117. package/dist/store/types.js +0 -10
  118. package/dist/store/types.js.map +1 -1
  119. package/dist/store/workflow-slice.d.ts +1 -1
  120. package/dist/store/workflow-slice.d.ts.map +1 -1
  121. package/dist/store/workflow-slice.js +19 -51
  122. package/dist/store/workflow-slice.js.map +1 -1
  123. package/dist/utils.d.ts +24 -0
  124. package/dist/utils.d.ts.map +1 -0
  125. package/dist/utils.js +31 -0
  126. package/dist/utils.js.map +1 -0
  127. package/package.json +7 -6
  128. package/src/components/AssetPanel.tsx +224 -264
  129. package/src/components/Canvas.tsx +178 -174
  130. package/src/components/CommandPalette.tsx +242 -242
  131. package/src/components/CompareSlider.tsx +168 -165
  132. package/src/components/DownloadPanel.tsx +201 -207
  133. package/src/components/ErrorBanner.tsx +64 -64
  134. package/src/components/ErrorBoundary.tsx +101 -0
  135. package/src/components/ExifPanel.tsx +154 -154
  136. package/src/components/GlobalDropzone.tsx +175 -170
  137. package/src/components/HistoryPanel.tsx +219 -219
  138. package/src/components/Inspector.tsx +145 -137
  139. package/src/components/ParamForm.tsx +140 -137
  140. package/src/components/PipelineBar.tsx +97 -104
  141. package/src/components/ProgressBar.tsx +78 -78
  142. package/src/components/StatusBar.tsx +145 -152
  143. package/src/components/StatusDot.tsx +27 -0
  144. package/src/components/ThemeToggle.tsx +98 -98
  145. package/src/components/ToolRunner.tsx +352 -0
  146. package/src/components/Toolbar.tsx +65 -65
  147. package/src/components/WorkflowEditor.tsx +333 -326
  148. package/src/components/WorkflowTemplates.tsx +101 -78
  149. package/src/components/Workspace.tsx +310 -223
  150. package/src/css-modules.d.ts +3 -0
  151. package/src/hooks/useCustomPresets.ts +284 -0
  152. package/src/hooks/useLokvis.ts +43 -10
  153. package/src/index.ts +7 -0
  154. package/src/store/assets-slice.ts +106 -52
  155. package/src/store/capabilities-slice.ts +10 -2
  156. package/src/store/index.ts +1 -1
  157. package/src/store/runtime-slice.ts +20 -15
  158. package/src/store/subscribe-utils.ts +82 -0
  159. package/src/store/types.ts +19 -12
  160. package/src/store/workflow-slice.ts +19 -53
  161. package/src/utils.ts +41 -0
  162. package/dist/store.d.ts +0 -76
  163. package/dist/store.d.ts.map +0 -1
  164. package/dist/store.js +0 -217
  165. package/dist/store.js.map +0 -1
@@ -5,97 +5,120 @@
5
5
  * 适合新用户快速上手,无需从零编排。
6
6
  *
7
7
  * 集成位置:
8
- * - 可作为独立组件渲染(如在 Inspector 底部或 Command Palette 中)
9
- * - Workspace 默认不渲染;由消费方按需挂载
8
+ * - 可作为独立组件渲染(如在 Inspector 底部或 Command Palette 中)
9
+ * - Workspace 默认不渲染;由消费方按需挂载
10
10
  *
11
11
  * @module WorkflowTemplates
12
12
  */
13
13
 
14
14
  import * as React from 'react';
15
- import { Icon } from '@lokvis/ui-core';
15
+ import { ConfirmDialog, Icon } from '@lokvis/ui-core';
16
16
  import { useWorkspaceStore } from '../store/index.js';
17
17
  import { WORKFLOW_TEMPLATES, type WorkflowTemplate } from '../data/workflow-templates.js';
18
18
 
19
19
  export interface WorkflowTemplatesProps {
20
- className?: string;
21
- /** 应用模板前是否需要确认(当前有节点时默认 true) */
22
- confirmIfNotEmpty?: boolean;
23
- /** 模板应用后的回调 */
24
- onApply?: (template: WorkflowTemplate) => void;
20
+ className?: string;
21
+ /** 应用模板前是否需要确认(当前有节点时默认 true) */
22
+ confirmIfNotEmpty?: boolean;
23
+ /** 模板应用后的回调 */
24
+ onApply?: (template: WorkflowTemplate) => void;
25
25
  }
26
26
 
27
27
  export function WorkflowTemplates({
28
- className = '',
29
- confirmIfNotEmpty = true,
30
- onApply,
28
+ className = '',
29
+ confirmIfNotEmpty = true,
30
+ onApply,
31
31
  }: WorkflowTemplatesProps) {
32
- const loadWorkflowTemplate = useWorkspaceStore((s) => s.loadWorkflowTemplate);
33
- const nodes = useWorkspaceStore((s) => s.nodes);
32
+ const loadWorkflowTemplate = useWorkspaceStore((s) => s.loadWorkflowTemplate);
33
+ const nodes = useWorkspaceStore((s) => s.nodes);
34
+ // 待确认应用的模板(非空工作流替换前需用户确认)
35
+ const [pendingTpl, setPendingTpl] = React.useState<WorkflowTemplate | null>(null);
34
36
 
35
- const handleApply = (tpl: WorkflowTemplate) => {
36
- if (confirmIfNotEmpty && nodes.length > 0) {
37
- if (!window.confirm(`应用模板「${tpl.name}」将替换当前 ${nodes.length} 个节点,继续?`)) {
38
- return;
39
- }
40
- }
41
- loadWorkflowTemplate(
42
- tpl.nodes.map((n) => ({ capability: n.capability, params: n.params }))
43
- );
44
- onApply?.(tpl);
45
- };
37
+ const handleApply = (tpl: WorkflowTemplate) => {
38
+ if (confirmIfNotEmpty && nodes.length > 0) {
39
+ setPendingTpl(tpl);
40
+ return;
41
+ }
42
+ applyTemplate(tpl);
43
+ };
46
44
 
47
- return (
48
- <div
49
- className={`flex flex-col ${className}`}
50
- role="region"
51
- aria-label="工作流模板"
52
- >
53
- <div className="flex items-center justify-between px-3 py-2 border-b border-zinc-200 dark:border-zinc-800">
54
- <span className="text-[11px] font-semibold uppercase tracking-wider text-zinc-400">
55
- Templates
56
- </span>
57
- <span className="text-[10px] text-zinc-400">{WORKFLOW_TEMPLATES.length} 内置</span>
58
- </div>
59
- <div className="grid grid-cols-1 gap-1.5 p-2">
60
- {WORKFLOW_TEMPLATES.map((tpl) => (
61
- <button
62
- key={tpl.id}
63
- type="button"
64
- onClick={() => handleApply(tpl)}
65
- className="group flex items-start gap-2 rounded-md border border-zinc-200 bg-white px-2.5 py-2 text-left transition-all hover:border-indigo-300 hover:bg-indigo-50/50 dark:border-zinc-700 dark:bg-zinc-900 dark:hover:border-indigo-700 dark:hover:bg-indigo-950/30"
66
- >
67
- <span className="mt-0.5 text-base leading-none">{tpl.icon}</span>
68
- <div className="flex-1 min-w-0">
69
- <div className="flex items-center justify-between gap-1">
70
- <span className="truncate text-[11px] font-medium text-zinc-700 dark:text-zinc-300">
71
- {tpl.name}
72
- </span>
73
- <span className="shrink-0 rounded bg-zinc-100 px-1 py-0.5 text-[9px] font-medium uppercase text-zinc-500 dark:bg-zinc-800 dark:text-zinc-400">
74
- {tpl.nodes.length}
75
- </span>
76
- </div>
77
- <p className="mt-0.5 truncate text-[10px] text-zinc-500 dark:text-zinc-400">
78
- {tpl.description}
79
- </p>
80
- {/* 节点链预览 */}
81
- <div className="mt-1 flex flex-wrap items-center gap-0.5">
82
- {tpl.nodes.map((n, i) => (
83
- <React.Fragment key={i}>
84
- {i > 0 && (
85
- <Icon size={8} className="text-zinc-300 dark:text-zinc-600">
86
- <path d="m5 5 5 5-5 5" />
87
- </Icon>
88
- )}
89
- <code className="rounded bg-zinc-100 px-1 py-0.5 text-[9px] text-zinc-600 dark:bg-zinc-800 dark:text-zinc-400">
90
- {n.capability}
91
- </code>
92
- </React.Fragment>
93
- ))}
94
- </div>
95
- </div>
96
- </button>
97
- ))}
98
- </div>
99
- </div>
100
- );
45
+ const applyTemplate = (tpl: WorkflowTemplate) => {
46
+ loadWorkflowTemplate(
47
+ tpl.nodes.map((n) => ({ capability: n.capability, params: n.params }))
48
+ );
49
+ onApply?.(tpl);
50
+ };
51
+
52
+ return (
53
+ <div
54
+ className={`flex flex-col ${className}`}
55
+ role="region"
56
+ aria-label="工作流模板"
57
+ >
58
+ <div className="flex items-center justify-between px-3 py-2 border-b border-[var(--lokvis-border)]">
59
+ <span className="text-[11px] font-semibold uppercase tracking-wider text-[var(--lokvis-fg-subtle)]">
60
+ Templates
61
+ </span>
62
+ <span className="text-[10px] text-[var(--lokvis-fg-subtle)]">{WORKFLOW_TEMPLATES.length} 内置</span>
63
+ </div>
64
+ <div className="grid grid-cols-1 gap-1.5 p-2">
65
+ {WORKFLOW_TEMPLATES.map((tpl) => (
66
+ <button
67
+ key={tpl.id}
68
+ type="button"
69
+ onClick={() => handleApply(tpl)}
70
+ className="group flex items-start gap-2 rounded-md border border-[var(--lokvis-border)] bg-[var(--lokvis-surface)] px-2.5 py-2 text-left transition-all hover:border-[var(--lokvis-primary)]/50 hover:bg-[var(--lokvis-primary)]/10"
71
+ >
72
+ <span className="mt-0.5 text-base leading-none">{tpl.icon}</span>
73
+ <div className="flex-1 min-w-0">
74
+ <div className="flex items-center justify-between gap-1">
75
+ <span className="truncate text-[11px] font-medium text-[var(--lokvis-fg-muted)]">
76
+ {tpl.name}
77
+ </span>
78
+ <span className="shrink-0 rounded bg-[var(--lokvis-surface-muted)] px-1 py-0.5 text-[9px] font-medium uppercase text-[var(--lokvis-fg-muted)]">
79
+ {tpl.nodes.length}
80
+ </span>
81
+ </div>
82
+ <p className="mt-0.5 truncate text-[10px] text-[var(--lokvis-fg-muted)]">
83
+ {tpl.description}
84
+ </p>
85
+ {/* 节点链预览 */}
86
+ <div className="mt-1 flex flex-wrap items-center gap-0.5">
87
+ {tpl.nodes.map((n, i) => (
88
+ <React.Fragment key={i}>
89
+ {i > 0 && (
90
+ <Icon size={8} className="text-[var(--lokvis-fg-subtle)]">
91
+ <path d="m5 5 5 5-5 5" />
92
+ </Icon>
93
+ )}
94
+ <code className="rounded bg-[var(--lokvis-surface-muted)] px-1 py-0.5 text-[9px] text-[var(--lokvis-fg-muted)]">
95
+ {n.capability}
96
+ </code>
97
+ </React.Fragment>
98
+ ))}
99
+ </div>
100
+ </div>
101
+ </button>
102
+ ))}
103
+ </div>
104
+
105
+ {/* 替换确认对话框(替代 window.confirm) */}
106
+ <ConfirmDialog
107
+ open={pendingTpl !== null}
108
+ title="应用模板"
109
+ message={
110
+ pendingTpl
111
+ ? `应用模板「${pendingTpl.name}」将替换当前 ${nodes.length} 个节点,继续?`
112
+ : ''
113
+ }
114
+ confirmText="替换"
115
+ variant="danger"
116
+ onConfirm={() => {
117
+ if (pendingTpl) applyTemplate(pendingTpl);
118
+ setPendingTpl(null);
119
+ }}
120
+ onClose={() => setPendingTpl(null)}
121
+ />
122
+ </div>
123
+ );
101
124
  }