@svadmin/ui 0.122.0 → 0.126.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 (200) hide show
  1. package/dist/app.css +581 -4
  2. package/dist/app.theme.css +581 -4
  3. package/dist/components/AbacPolicyMatrix.svelte +356 -0
  4. package/dist/components/AbacPolicyMatrix.svelte.d.ts +30 -0
  5. package/dist/components/AboutSettings.svelte +1 -1
  6. package/dist/components/ActionPalette.svelte +272 -0
  7. package/dist/components/ActionPalette.svelte.d.ts +23 -0
  8. package/dist/components/AdminCopilotWidget.svelte +316 -0
  9. package/dist/components/AdminCopilotWidget.svelte.d.ts +33 -0
  10. package/dist/components/AnnouncementBanner.svelte +12 -1
  11. package/dist/components/AnnouncementBanner.svelte.d.ts +4 -0
  12. package/dist/components/ApiPlayground.svelte +255 -0
  13. package/dist/components/ApiPlayground.svelte.d.ts +24 -0
  14. package/dist/components/ApiSettings.svelte +1 -1
  15. package/dist/components/AppearanceSettings.svelte +1 -1
  16. package/dist/components/ApprovalChainBuilder.svelte +262 -0
  17. package/dist/components/ApprovalChainBuilder.svelte.d.ts +20 -0
  18. package/dist/components/ApprovalTimeline.svelte +8 -1
  19. package/dist/components/AsyncExportModal.svelte +1 -1
  20. package/dist/components/AudioFeedbackProvider.svelte +1 -1
  21. package/dist/components/AuditLogDrawer.svelte +2 -2
  22. package/dist/components/AuditTrailInspector.svelte +448 -0
  23. package/dist/components/AuditTrailInspector.svelte.d.ts +44 -0
  24. package/dist/components/AutoTable.svelte +20 -1
  25. package/dist/components/AutoTable.svelte.d.ts +2 -0
  26. package/dist/components/BatchEditModal.svelte +266 -0
  27. package/dist/components/BatchEditModal.svelte.d.ts +27 -0
  28. package/dist/components/BillingInvoiceDrawer.svelte +206 -0
  29. package/dist/components/BillingInvoiceDrawer.svelte.d.ts +30 -0
  30. package/dist/components/ChartAnnotationOverlay.svelte +228 -0
  31. package/dist/components/ChartAnnotationOverlay.svelte.d.ts +21 -0
  32. package/dist/components/CheckCard.svelte +1 -1
  33. package/dist/components/ClusterTopologyGraph.svelte +317 -0
  34. package/dist/components/ClusterTopologyGraph.svelte.d.ts +31 -0
  35. package/dist/components/ColumnHeaderFilter.svelte +6 -6
  36. package/dist/components/ColumnMappingTable.svelte +174 -0
  37. package/dist/components/ColumnMappingTable.svelte.d.ts +23 -0
  38. package/dist/components/ConversionFunnel.svelte +1 -1
  39. package/dist/components/CursorListFooter.svelte +67 -0
  40. package/dist/components/CursorListFooter.svelte.d.ts +17 -0
  41. package/dist/components/DashboardGridLayout.svelte +309 -0
  42. package/dist/components/DashboardGridLayout.svelte.d.ts +30 -0
  43. package/dist/components/DashboardLayoutStorage.svelte +278 -0
  44. package/dist/components/DashboardLayoutStorage.svelte.d.ts +23 -0
  45. package/dist/components/DataFreshnessIndicator.svelte +149 -0
  46. package/dist/components/DataFreshnessIndicator.svelte.d.ts +20 -0
  47. package/dist/components/DataImportDropzone.svelte +215 -0
  48. package/dist/components/DataImportDropzone.svelte.d.ts +24 -0
  49. package/dist/components/DataLineageGraph.svelte +203 -0
  50. package/dist/components/DataLineageGraph.svelte.d.ts +26 -0
  51. package/dist/components/DataMaskPolicyEngine.svelte +291 -0
  52. package/dist/components/DataMaskPolicyEngine.svelte.d.ts +25 -0
  53. package/dist/components/DataScopeRuleEditor.svelte +142 -0
  54. package/dist/components/DataScopeRuleEditor.svelte.d.ts +19 -0
  55. package/dist/components/DataScreenContainer.svelte +160 -0
  56. package/dist/components/DataScreenContainer.svelte.d.ts +15 -0
  57. package/dist/components/DevTools.svelte +3 -3
  58. package/dist/components/DualApprovalGate.svelte +132 -65
  59. package/dist/components/DualApprovalGate.svelte.d.ts +20 -1
  60. package/dist/components/EditableTable.svelte +2 -2
  61. package/dist/components/ElectronicSealStamp.svelte +102 -0
  62. package/dist/components/ElectronicSealStamp.svelte.d.ts +14 -0
  63. package/dist/components/EnvVariableEditor.svelte +284 -0
  64. package/dist/components/EnvVariableEditor.svelte.d.ts +17 -0
  65. package/dist/components/ExcelImportWizard.svelte +2 -2
  66. package/dist/components/FeatureAnnouncementModal.svelte +173 -0
  67. package/dist/components/FeatureAnnouncementModal.svelte.d.ts +21 -0
  68. package/dist/components/FieldRenderer.svelte +1 -1
  69. package/dist/components/FilterTagBar.svelte +210 -0
  70. package/dist/components/FilterTagBar.svelte.d.ts +23 -0
  71. package/dist/components/FormulaField.svelte +149 -0
  72. package/dist/components/FormulaField.svelte.d.ts +18 -0
  73. package/dist/components/GeoScatterMap.svelte +225 -0
  74. package/dist/components/GeoScatterMap.svelte.d.ts +22 -0
  75. package/dist/components/HmacSignatureCalculator.svelte +199 -0
  76. package/dist/components/HmacSignatureCalculator.svelte.d.ts +10 -0
  77. package/dist/components/I18nLanguagePackEditor.svelte +208 -0
  78. package/dist/components/I18nLanguagePackEditor.svelte.d.ts +17 -0
  79. package/dist/components/ImportPreviewValidator.svelte +239 -0
  80. package/dist/components/ImportPreviewValidator.svelte.d.ts +26 -0
  81. package/dist/components/ImportWizard.svelte +2 -2
  82. package/dist/components/IncidentWarRoomDrawer.svelte +194 -0
  83. package/dist/components/IncidentWarRoomDrawer.svelte.d.ts +24 -0
  84. package/dist/components/InputGroup.svelte +133 -0
  85. package/dist/components/InputGroup.svelte.d.ts +16 -0
  86. package/dist/components/JsonSchemaForm.svelte +4 -4
  87. package/dist/components/LightFilter.svelte +2 -2
  88. package/dist/components/ListPagination.svelte +39 -3
  89. package/dist/components/LiveStreamLogViewer.svelte +185 -0
  90. package/dist/components/LiveStreamLogViewer.svelte.d.ts +21 -0
  91. package/dist/components/MasterSubTableDrawer.svelte +223 -0
  92. package/dist/components/MasterSubTableDrawer.svelte.d.ts +25 -0
  93. package/dist/components/MicroAppRouteSync.svelte +185 -0
  94. package/dist/components/MicroAppRouteSync.svelte.d.ts +12 -0
  95. package/dist/components/MicroAppSandbox.svelte +200 -0
  96. package/dist/components/MicroAppSandbox.svelte.d.ts +16 -0
  97. package/dist/components/MicroAppStateBusIndicator.svelte +159 -0
  98. package/dist/components/MicroAppStateBusIndicator.svelte.d.ts +12 -0
  99. package/dist/components/MockDataInterceptor.svelte +292 -0
  100. package/dist/components/MockDataInterceptor.svelte.d.ts +27 -0
  101. package/dist/components/OmnibarCommandPalette.svelte +320 -0
  102. package/dist/components/OmnibarCommandPalette.svelte.d.ts +27 -0
  103. package/dist/components/PageSkeleton.svelte +19 -5
  104. package/dist/components/PageSkeleton.svelte.d.ts +5 -3
  105. package/dist/components/PeriodComparisonCard.svelte +142 -0
  106. package/dist/components/PeriodComparisonCard.svelte.d.ts +16 -0
  107. package/dist/components/PermissionMatrix.svelte +1 -1
  108. package/dist/components/PermissionSimulator.svelte +319 -0
  109. package/dist/components/PermissionSimulator.svelte.d.ts +34 -0
  110. package/dist/components/PivotMatrix.svelte +271 -0
  111. package/dist/components/PivotMatrix.svelte.d.ts +32 -0
  112. package/dist/components/PlanUsageQuotaBar.svelte +154 -0
  113. package/dist/components/PlanUsageQuotaBar.svelte.d.ts +26 -0
  114. package/dist/components/Popconfirm.svelte +20 -8
  115. package/dist/components/Popconfirm.svelte.d.ts +3 -1
  116. package/dist/components/ProSkeleton.svelte +4 -0
  117. package/dist/components/ProSkeleton.svelte.d.ts +2 -0
  118. package/dist/components/QueryAiExplainer.svelte +148 -0
  119. package/dist/components/QueryAiExplainer.svelte.d.ts +16 -0
  120. package/dist/components/QueryBuilder.svelte +456 -0
  121. package/dist/components/QueryBuilder.svelte.d.ts +33 -0
  122. package/dist/components/Rate.svelte +19 -2
  123. package/dist/components/Result.svelte +36 -4
  124. package/dist/components/Result.svelte.d.ts +4 -2
  125. package/dist/components/RolePermissionComparator.svelte +273 -0
  126. package/dist/components/RolePermissionComparator.svelte.d.ts +28 -0
  127. package/dist/components/RuleExpressionBuilder.svelte +380 -0
  128. package/dist/components/RuleExpressionBuilder.svelte.d.ts +31 -0
  129. package/dist/components/ScheduledJobManager.svelte +225 -0
  130. package/dist/components/ScheduledJobManager.svelte.d.ts +23 -0
  131. package/dist/components/SchemaVisualModeler.svelte +2 -2
  132. package/dist/components/ScreenAntiLeakGuard.svelte +88 -0
  133. package/dist/components/ScreenAntiLeakGuard.svelte.d.ts +12 -0
  134. package/dist/components/SecureDataExporter.svelte +296 -0
  135. package/dist/components/SecureDataExporter.svelte.d.ts +29 -0
  136. package/dist/components/ServerStatusGrid.svelte +179 -0
  137. package/dist/components/ServerStatusGrid.svelte.d.ts +21 -0
  138. package/dist/components/SnapshotTimelineReplay.svelte +219 -0
  139. package/dist/components/SnapshotTimelineReplay.svelte.d.ts +19 -0
  140. package/dist/components/Spin.svelte +33 -11
  141. package/dist/components/Spin.svelte.d.ts +7 -4
  142. package/dist/components/SqlConsole.svelte +247 -0
  143. package/dist/components/SqlConsole.svelte.d.ts +20 -0
  144. package/dist/components/StepWizard.svelte +1 -1
  145. package/dist/components/Steps.svelte +44 -3
  146. package/dist/components/SystemCapacityForecastCard.svelte +132 -0
  147. package/dist/components/SystemCapacityForecastCard.svelte.d.ts +19 -0
  148. package/dist/components/SystemHealthCheckDashboard.svelte +306 -0
  149. package/dist/components/SystemHealthCheckDashboard.svelte.d.ts +24 -0
  150. package/dist/components/TableAggregationFooter.svelte +173 -0
  151. package/dist/components/TableAggregationFooter.svelte.d.ts +22 -0
  152. package/dist/components/TaskCenter.svelte +37 -29
  153. package/dist/components/TenantContextSwitcher.svelte +314 -0
  154. package/dist/components/TenantContextSwitcher.svelte.d.ts +35 -0
  155. package/dist/components/TenantQuotasMatrix.svelte +229 -0
  156. package/dist/components/TenantQuotasMatrix.svelte.d.ts +22 -0
  157. package/dist/components/ThemeSettingsDrawer.svelte +6 -14
  158. package/dist/components/ThreadedCommentDrawer.svelte +246 -0
  159. package/dist/components/ThreadedCommentDrawer.svelte.d.ts +26 -0
  160. package/dist/components/TierFeatureComparison.svelte +147 -0
  161. package/dist/components/TierFeatureComparison.svelte.d.ts +28 -0
  162. package/dist/components/Timeline.svelte +12 -3
  163. package/dist/components/Timeline.svelte.d.ts +2 -0
  164. package/dist/components/TreeTransferSelect.svelte +333 -0
  165. package/dist/components/TreeTransferSelect.svelte.d.ts +18 -0
  166. package/dist/components/VirtualCardGrid.svelte +180 -0
  167. package/dist/components/VirtualCardGrid.svelte.d.ts +65 -0
  168. package/dist/components/WebhookSimulator.svelte +263 -0
  169. package/dist/components/WebhookSimulator.svelte.d.ts +26 -0
  170. package/dist/components/WidgetContainer.svelte +204 -0
  171. package/dist/components/WidgetContainer.svelte.d.ts +31 -0
  172. package/dist/components/WorkflowExecutionTracker.svelte +131 -0
  173. package/dist/components/WorkflowExecutionTracker.svelte.d.ts +19 -0
  174. package/dist/components/WorkflowGraphDesigner.svelte +202 -0
  175. package/dist/components/WorkflowGraphDesigner.svelte.d.ts +24 -0
  176. package/dist/components/WorkflowNodeInspector.svelte +217 -0
  177. package/dist/components/WorkflowNodeInspector.svelte.d.ts +24 -0
  178. package/dist/components/WorkflowStepper.svelte +1 -1
  179. package/dist/components/list-i18n.d.ts +7 -0
  180. package/dist/components/list-i18n.js +14 -0
  181. package/dist/components/ui/badge/badge.svelte +3 -3
  182. package/dist/components/ui/button/button.svelte +3 -1
  183. package/dist/components/ui/button/button.svelte.d.ts +1 -0
  184. package/dist/components/ui/tooltip/tooltip-content.svelte +1 -1
  185. package/dist/components/useDynamicLocale.d.svelte.ts +1 -0
  186. package/dist/components/useDynamicLocale.svelte.d.ts +10 -0
  187. package/dist/components/useDynamicLocale.svelte.js +40 -0
  188. package/dist/components/useFormulaEngine.d.svelte.ts +1 -0
  189. package/dist/components/useFormulaEngine.svelte.d.ts +9 -0
  190. package/dist/components/useFormulaEngine.svelte.js +209 -0
  191. package/dist/components/useMicroAppState.d.svelte.ts +1 -0
  192. package/dist/components/useMicroAppState.svelte.d.ts +17 -0
  193. package/dist/components/useMicroAppState.svelte.js +38 -0
  194. package/dist/components/useStorageCache.d.svelte.ts +1 -0
  195. package/dist/components/useStorageCache.svelte.d.ts +49 -0
  196. package/dist/components/useStorageCache.svelte.js +229 -0
  197. package/dist/components.css +5 -1
  198. package/dist/index.d.ts +75 -3
  199. package/dist/index.js +118 -2
  200. package/package.json +4 -4
@@ -0,0 +1,199 @@
1
+ <script lang="ts">
2
+ import { untrack } from 'svelte';
3
+ import { Shield, Key, Copy, Check, CheckCircle2, XCircle } from '@lucide/svelte';
4
+ import { cn } from '../utils.js';
5
+
6
+ export type HmacAlgorithm = 'SHA-256' | 'SHA-384' | 'SHA-512';
7
+
8
+ export interface HmacSignatureCalculatorProps {
9
+ defaultSecret?: string | undefined;
10
+ defaultBody?: string | undefined;
11
+ algorithm?: HmacAlgorithm | undefined;
12
+ class?: string | undefined;
13
+ }
14
+
15
+ let {
16
+ defaultSecret = 'whsec_test_secret_key_8848',
17
+ defaultBody = '{"event":"order.paid","amount":100}',
18
+ algorithm = 'SHA-256',
19
+ class: className = '',
20
+ }: HmacSignatureCalculatorProps = $props();
21
+
22
+ let secretKey = $state(untrack(() => defaultSecret));
23
+ let requestBody = $state(untrack(() => defaultBody));
24
+ let selectedAlgorithm = $state<HmacAlgorithm>(untrack(() => algorithm));
25
+ let computedHexSignature = $state('');
26
+ let expectedSignature = $state('');
27
+ let isCopied = $state(false);
28
+
29
+ async function calculateHmac() {
30
+ if (!secretKey || !requestBody) {
31
+ computedHexSignature = '';
32
+ return;
33
+ }
34
+
35
+ try {
36
+ const encoder = new TextEncoder();
37
+ const keyData = encoder.encode(secretKey);
38
+ const messageData = encoder.encode(requestBody);
39
+
40
+ if (typeof crypto !== 'undefined' && crypto.subtle) {
41
+ const cryptoKey = await crypto.subtle.importKey(
42
+ 'raw',
43
+ keyData,
44
+ { name: 'HMAC', hash: selectedAlgorithm },
45
+ false,
46
+ ['sign']
47
+ );
48
+ const signature = await crypto.subtle.sign('HMAC', cryptoKey, messageData);
49
+ const hashArray = Array.from(new Uint8Array(signature));
50
+ computedHexSignature = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
51
+ } else {
52
+ // Fallback for non-crypto environments
53
+ computedHexSignature = 'simulated_hmac_' + secretKey.length + '_' + requestBody.length;
54
+ }
55
+ } catch {
56
+ computedHexSignature = '';
57
+ }
58
+ }
59
+
60
+ $effect(() => {
61
+ // Recompute whenever inputs change
62
+ if (secretKey !== undefined && requestBody !== undefined && selectedAlgorithm !== undefined) {
63
+ calculateHmac();
64
+ }
65
+ });
66
+
67
+ const isMatched = $derived.by<boolean | null>(() => {
68
+ if (!expectedSignature.trim() || !computedHexSignature) return null;
69
+ return expectedSignature.trim().toLowerCase() === computedHexSignature.toLowerCase();
70
+ });
71
+
72
+ async function copySignature() {
73
+ if (!computedHexSignature || typeof navigator === 'undefined' || !navigator.clipboard) return;
74
+ try {
75
+ await navigator.clipboard.writeText(computedHexSignature);
76
+ isCopied = true;
77
+ setTimeout(() => {
78
+ isCopied = false;
79
+ }, 1500);
80
+ } catch {
81
+ // Ignore
82
+ }
83
+ }
84
+ </script>
85
+
86
+ <div
87
+ class={cn('rounded-md border border-border bg-card p-5 text-card-foreground shadow-xs space-y-4', className)}
88
+ data-svadmin-component="HmacSignatureCalculator"
89
+ >
90
+ <header class="flex items-center justify-between border-b border-border pb-3">
91
+ <div class="flex items-center gap-2">
92
+ <Shield class="h-4 w-4 text-primary" />
93
+ <h3 class="font-bold text-sm text-foreground">HMAC 签名计算与现场验签沙箱</h3>
94
+ </div>
95
+ <span class="text-xs font-mono text-muted-foreground">Web Crypto 原生算法加速</span>
96
+ </header>
97
+
98
+ <!-- Input Form -->
99
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4 text-xs font-mono">
100
+ <!-- Secret -->
101
+ <div class="space-y-1">
102
+ <label for="hmac-secret-key" class="block font-medium text-foreground">
103
+ 签名密钥 (Signing Secret Key)
104
+ </label>
105
+ <div class="flex items-center rounded-md border border-input bg-background px-3 py-1.5 focus-within:ring-1 focus-within:ring-primary">
106
+ <Key class="h-3.5 w-3.5 text-muted-foreground mr-1.5 shrink-0" />
107
+ <input
108
+ id="hmac-secret-key"
109
+ type="text"
110
+ class="w-full bg-transparent outline-none text-foreground text-xs"
111
+ bind:value={secretKey}
112
+ placeholder="请输入密钥..."
113
+ />
114
+ </div>
115
+ </div>
116
+
117
+ <!-- Algorithm Selector -->
118
+ <div class="space-y-1">
119
+ <label for="hmac-algorithm" class="block font-medium text-foreground">
120
+ 哈希加密算法 (Algorithm)
121
+ </label>
122
+ <select data-size="compact"
123
+ id="hmac-algorithm"
124
+ class="svadmin-select w-full"
125
+ bind:value={selectedAlgorithm}
126
+ >
127
+ <option value="SHA-256">HMAC-SHA256 (推荐工业规范)</option>
128
+ <option value="SHA-384">HMAC-SHA384</option>
129
+ <option value="SHA-512">HMAC-SHA512 (高安全等级)</option>
130
+ </select>
131
+ </div>
132
+ </div>
133
+
134
+ <!-- Body Textarea -->
135
+ <div class="space-y-1 text-xs">
136
+ <label for="hmac-body" class="block font-medium text-foreground font-mono">
137
+ 待签名原始载荷 (Raw Payload)
138
+ </label>
139
+ <textarea
140
+ id="hmac-body"
141
+ class="w-full h-24 rounded-md border border-input bg-background p-3 font-mono text-xs leading-relaxed text-foreground outline-none focus:ring-1 focus:ring-primary"
142
+ bind:value={requestBody}
143
+ spellcheck="false"
144
+ ></textarea>
145
+ </div>
146
+
147
+ <!-- Computed Output -->
148
+ <div class="rounded-md border border-border bg-muted/20 p-3.5 space-y-2 text-xs font-mono">
149
+ <div class="flex items-center justify-between text-muted-foreground">
150
+ <span class="font-bold text-foreground">实时计算所得 HMAC 签名结果 (Hex Digest)</span>
151
+ <button
152
+ type="button"
153
+ class="inline-flex items-center gap-1 text-primary hover:underline cursor-pointer"
154
+ onclick={copySignature}
155
+ >
156
+ {#if isCopied}
157
+ <Check class="h-3 w-3 text-success" />
158
+ <span class="text-success font-semibold">已复制</span>
159
+ {:else}
160
+ <Copy class="h-3 w-3" />
161
+ <span>复制结果</span>
162
+ {/if}
163
+ </button>
164
+ </div>
165
+ <div class="rounded border border-border bg-background p-2.5 font-bold text-foreground break-all select-all">
166
+ {computedHexSignature || '请输入有效密钥与载荷以生成签名'}
167
+ </div>
168
+ </div>
169
+
170
+ <!-- Signature Verifier Matcher -->
171
+ <div class="space-y-1.5 text-xs font-mono border-t border-border pt-3">
172
+ <label for="expected-signature" class="block font-medium text-foreground">
173
+ 接收端签名对比验证 (输入接收到的 Header 签名进行校验)
174
+ </label>
175
+ <div class="flex items-center gap-2">
176
+ <input
177
+ id="expected-signature"
178
+ type="text"
179
+ class="flex-1 rounded-md border border-input bg-background px-3 py-1.5 text-xs text-foreground outline-none focus:ring-1 focus:ring-primary"
180
+ bind:value={expectedSignature}
181
+ placeholder="例如粘贴 X-Svadmin-Signature 标头值..."
182
+ />
183
+
184
+ {#if isMatched !== null}
185
+ {#if isMatched}
186
+ <span class="inline-flex items-center gap-1 rounded bg-success/10 border border-success/30 text-success font-semibold px-2.5 py-1 shrink-0">
187
+ <CheckCircle2 class="h-3.5 w-3.5" />
188
+ <span>验签成功 (Valid)</span>
189
+ </span>
190
+ {:else}
191
+ <span class="inline-flex items-center gap-1 rounded bg-destructive/10 border border-destructive/30 text-destructive font-semibold px-2.5 py-1 shrink-0">
192
+ <XCircle class="h-3.5 w-3.5" />
193
+ <span>不匹配 (Mismatch)</span>
194
+ </span>
195
+ {/if}
196
+ {/if}
197
+ </div>
198
+ </div>
199
+ </div>
@@ -0,0 +1,10 @@
1
+ export type HmacAlgorithm = 'SHA-256' | 'SHA-384' | 'SHA-512';
2
+ export interface HmacSignatureCalculatorProps {
3
+ defaultSecret?: string | undefined;
4
+ defaultBody?: string | undefined;
5
+ algorithm?: HmacAlgorithm | undefined;
6
+ class?: string | undefined;
7
+ }
8
+ declare const HmacSignatureCalculator: import("svelte").Component<HmacSignatureCalculatorProps, {}, "">;
9
+ type HmacSignatureCalculator = ReturnType<typeof HmacSignatureCalculator>;
10
+ export default HmacSignatureCalculator;
@@ -0,0 +1,208 @@
1
+ <script lang="ts">
2
+ import {
3
+ Languages,
4
+ Search,
5
+ Save,
6
+ RotateCcw,
7
+ Check,
8
+ } from '@lucide/svelte';
9
+ import { untrack } from 'svelte';
10
+ import { useTranslation } from '@svadmin/core/i18n';
11
+ import { cn } from '../utils.js';
12
+ import { Button } from './ui/button/index.js';
13
+ import { applyLocalePatch } from './useDynamicLocale.svelte.js';
14
+
15
+ export interface I18nEntry {
16
+ key: string;
17
+ namespace: string;
18
+ defaultValue: string;
19
+ currentValue: string;
20
+ isModified?: boolean | undefined;
21
+ }
22
+
23
+ export interface I18nLanguagePackEditorProps {
24
+ targetLocale?: string | undefined;
25
+ initialEntries?: I18nEntry[] | undefined;
26
+ title?: string | undefined;
27
+ class?: string | undefined;
28
+ onSavePatch?: ((locale: string, patch: Record<string, string>) => void) | undefined;
29
+ }
30
+
31
+ let {
32
+ targetLocale = 'zh-CN',
33
+ initialEntries = [
34
+ { key: 'common.save', namespace: 'common', defaultValue: 'Save', currentValue: '保存' },
35
+ { key: 'common.cancel', namespace: 'common', defaultValue: 'Cancel', currentValue: '取消' },
36
+ { key: 'common.delete', namespace: 'common', defaultValue: 'Delete', currentValue: '删除' },
37
+ { key: 'table.actions', namespace: 'table', defaultValue: 'Actions', currentValue: '操作' },
38
+ { key: 'table.filter', namespace: 'table', defaultValue: 'Filter', currentValue: '筛选' },
39
+ { key: 'auth.login', namespace: 'auth', defaultValue: 'Sign in', currentValue: '登录系统' },
40
+ ],
41
+ title,
42
+ class: className = '',
43
+ onSavePatch,
44
+ }: I18nLanguagePackEditorProps = $props();
45
+
46
+ const i18n = useTranslation();
47
+ const chinese = $derived(i18n.locale.startsWith('zh'));
48
+
49
+ let query = $state('');
50
+ let activeNamespace = $state<string>('all');
51
+ let entries = $state<I18nEntry[]>(untrack(() => JSON.parse(JSON.stringify(initialEntries))));
52
+ let isSaved = $state(false);
53
+
54
+ const namespaces = $derived([
55
+ 'all',
56
+ ...Array.from(new Set(initialEntries.map((e) => e.namespace))),
57
+ ]);
58
+
59
+ const filteredEntries = $derived.by(() => {
60
+ const q = query.trim().toLowerCase();
61
+ return entries.filter((e) => {
62
+ const matchNs = activeNamespace === 'all' || e.namespace === activeNamespace;
63
+ const matchQuery =
64
+ !q ||
65
+ e.key.toLowerCase().includes(q) ||
66
+ e.defaultValue.toLowerCase().includes(q) ||
67
+ e.currentValue.toLowerCase().includes(q);
68
+ return matchNs && matchQuery;
69
+ });
70
+ });
71
+
72
+ function updateValue(entry: I18nEntry, val: string) {
73
+ entry.currentValue = val;
74
+ entry.isModified = entry.currentValue !== entry.defaultValue;
75
+ isSaved = false;
76
+ }
77
+
78
+ function handleSaveAll() {
79
+ const patch: Record<string, string> = {};
80
+ entries.forEach((e) => {
81
+ if (e.currentValue) {
82
+ patch[e.key] = e.currentValue;
83
+ }
84
+ });
85
+
86
+ applyLocalePatch(targetLocale, patch);
87
+ onSavePatch?.(targetLocale, patch);
88
+ isSaved = true;
89
+ setTimeout(() => {
90
+ isSaved = false;
91
+ }, 2000);
92
+ }
93
+
94
+ function handleResetAll() {
95
+ entries = JSON.parse(JSON.stringify(initialEntries));
96
+ isSaved = false;
97
+ }
98
+
99
+ const modifiedCount = $derived(entries.filter((e) => e.isModified).length);
100
+ const resolvedTitle = $derived(
101
+ title ?? (chinese ? '多语言文案在线热修与补丁管理' : 'I18n Dynamic Language Pack Editor'),
102
+ );
103
+ </script>
104
+
105
+ <div
106
+ data-svadmin-component="I18nLanguagePackEditor"
107
+ class={cn(
108
+ 'w-full rounded-md border border-border bg-card text-card-foreground shadow-xs p-6 space-y-4 flex flex-col',
109
+ className,
110
+ )}
111
+ >
112
+ <!-- Header -->
113
+ <div class="flex items-center justify-between border-b border-border/70 pb-4">
114
+ <div class="flex items-center gap-3">
115
+ <div class="flex h-9 w-9 items-center justify-center rounded-sm bg-primary/10 text-primary border border-primary/20">
116
+ <Languages class="h-5 w-5" />
117
+ </div>
118
+ <div>
119
+ <h3 class="text-base font-semibold text-foreground">{resolvedTitle}</h3>
120
+ <p class="text-xs text-muted-foreground">
121
+ {chinese ? `目标语种: ${targetLocale} · 在线即时覆盖生效,无需重新构建部署` : `Target: ${targetLocale}`}
122
+ </p>
123
+ </div>
124
+ </div>
125
+
126
+ <div class="flex items-center gap-2">
127
+ <Button variant="outline" size="sm" class="h-8 text-xs gap-1" onclick={handleResetAll}>
128
+ <RotateCcw class="h-3.5 w-3.5" />
129
+ <span>{chinese ? '还原初始' : 'Reset'}</span>
130
+ </Button>
131
+
132
+ <Button size="sm" class="h-8 text-xs gap-1.5" onclick={handleSaveAll}>
133
+ {#if isSaved}
134
+ <Check class="h-3.5 w-3.5 text-success" />
135
+ <span>{chinese ? '已发布热补丁' : 'Published'}</span>
136
+ {:else}
137
+ <Save class="h-3.5 w-3.5" />
138
+ <span>{chinese ? `发布热补丁 (${modifiedCount})` : 'Publish Patch'}</span>
139
+ {/if}
140
+ </Button>
141
+ </div>
142
+ </div>
143
+
144
+ <!-- Filters Toolbar -->
145
+ <div class="flex flex-wrap items-center justify-between gap-3 bg-muted/20 p-3 rounded-md border border-border/60">
146
+ <!-- Namespace tabs -->
147
+ <div class="flex gap-1 overflow-x-auto text-xs">
148
+ {#each namespaces as ns (ns)}
149
+ <button
150
+ type="button"
151
+ onclick={() => (activeNamespace = ns)}
152
+ class={cn(
153
+ 'px-2.5 py-1 rounded-md font-medium transition-colors',
154
+ activeNamespace === ns ? 'bg-card text-foreground shadow-2xs font-bold' : 'text-muted-foreground hover:text-foreground',
155
+ )}
156
+ >
157
+ {ns}
158
+ </button>
159
+ {/each}
160
+ </div>
161
+
162
+ <!-- Search box -->
163
+ <div class="relative flex items-center min-w-56">
164
+ <Search class="absolute left-2.5 h-3.5 w-3.5 text-muted-foreground pointer-events-none" />
165
+ <input
166
+ type="text"
167
+ bind:value={query}
168
+ placeholder={chinese ? '检索词条 Key 或文本...' : 'Search keys or text...'}
169
+ class="h-7.5 w-full rounded-md border border-input bg-background pl-8 pr-2.5 text-xs focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
170
+ />
171
+ </div>
172
+ </div>
173
+
174
+ <!-- Translation Table -->
175
+ <div class="rounded-md border border-border overflow-hidden">
176
+ <table class="w-full text-left text-xs border-collapse">
177
+ <thead class="bg-muted/40 border-b border-border text-muted-foreground font-semibold">
178
+ <tr>
179
+ <th class="p-3 w-56">{chinese ? '词条标识 (Key)' : 'Key'}</th>
180
+ <th class="p-3 w-28">{chinese ? '命名空间' : 'Namespace'}</th>
181
+ <th class="p-3">{chinese ? '默认基准文案' : 'Default'}</th>
182
+ <th class="p-3">{chinese ? '线上覆盖文案 (可直接编辑)' : 'Current Translation (Editable)'}</th>
183
+ </tr>
184
+ </thead>
185
+ <tbody class="divide-y divide-border/60">
186
+ {#each filteredEntries as entry (entry.key)}
187
+ <tr class={cn('hover:bg-muted/20', entry.isModified && 'bg-primary/5')}>
188
+ <td class="p-3 font-mono font-medium text-foreground">{entry.key}</td>
189
+ <td class="p-3">
190
+ <span class="rounded bg-muted px-1.5 py-0.5 text-xs font-mono text-muted-foreground">
191
+ {entry.namespace}
192
+ </span>
193
+ </td>
194
+ <td class="p-3 text-muted-foreground">{entry.defaultValue}</td>
195
+ <td class="p-2.5">
196
+ <input
197
+ type="text"
198
+ value={entry.currentValue}
199
+ oninput={(e) => updateValue(entry, (e.target as HTMLInputElement).value)}
200
+ class="h-7.5 w-full rounded border border-input bg-background px-2.5 text-xs text-foreground font-medium focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
201
+ />
202
+ </td>
203
+ </tr>
204
+ {/each}
205
+ </tbody>
206
+ </table>
207
+ </div>
208
+ </div>
@@ -0,0 +1,17 @@
1
+ export interface I18nEntry {
2
+ key: string;
3
+ namespace: string;
4
+ defaultValue: string;
5
+ currentValue: string;
6
+ isModified?: boolean | undefined;
7
+ }
8
+ export interface I18nLanguagePackEditorProps {
9
+ targetLocale?: string | undefined;
10
+ initialEntries?: I18nEntry[] | undefined;
11
+ title?: string | undefined;
12
+ class?: string | undefined;
13
+ onSavePatch?: ((locale: string, patch: Record<string, string>) => void) | undefined;
14
+ }
15
+ declare const I18nLanguagePackEditor: import("svelte").Component<I18nLanguagePackEditorProps, {}, "">;
16
+ type I18nLanguagePackEditor = ReturnType<typeof I18nLanguagePackEditor>;
17
+ export default I18nLanguagePackEditor;
@@ -0,0 +1,239 @@
1
+ <script lang="ts">
2
+ import { CheckCircle2, AlertCircle, Trash2, Check, Filter, Loader2, ArrowRight } from '@lucide/svelte';
3
+ import { cn } from '../utils.js';
4
+
5
+ export interface RowValidationError {
6
+ rowIndex: number;
7
+ field: string;
8
+ message: string;
9
+ }
10
+
11
+ export interface ImportPreviewValidatorProps {
12
+ /** 预览列定义 */
13
+ columns: Array<{ key: string; label: string }>;
14
+ /** 解析出的各行数据数组 */
15
+ rows: Array<Record<string, unknown>>;
16
+ /** 校验错误列表 */
17
+ errors?: RowValidationError[] | undefined;
18
+ /** 行内修改单元格回调 */
19
+ onrowchange?: ((rowIndex: number, field: string, newValue: string) => void) | undefined;
20
+ /** 删除某行回调 */
21
+ onremoverow?: ((rowIndex: number) => void) | undefined;
22
+ /** 提交导入回调 */
23
+ onsubmit?: ((validRows: Array<Record<string, unknown>>) => Promise<void> | void) | undefined;
24
+ class?: string | undefined;
25
+ }
26
+
27
+ let {
28
+ columns = [],
29
+ rows = [],
30
+ errors = [],
31
+ onrowchange,
32
+ onremoverow,
33
+ onsubmit,
34
+ class: className = '',
35
+ }: ImportPreviewValidatorProps = $props();
36
+
37
+ let filterOnlyErrors = $state(false);
38
+ let isSubmitting = $state(false);
39
+
40
+ const errorMap = $derived.by(() => {
41
+ const map = new Map<string, string>();
42
+ for (const err of errors) {
43
+ map.set(`${err.rowIndex}_${err.field}`, err.message);
44
+ }
45
+ return map;
46
+ });
47
+
48
+ const rowErrorIndices = $derived.by(() => {
49
+ return new Set(errors.map((e) => e.rowIndex));
50
+ });
51
+
52
+ const displayRows = $derived.by(() => {
53
+ return rows
54
+ .map((row, index) => ({ row, index }))
55
+ .filter(({ index }) => (filterOnlyErrors ? rowErrorIndices.has(index) : true));
56
+ });
57
+
58
+ const validCount = $derived(rows.length - rowErrorIndices.size);
59
+ const invalidCount = $derived(rowErrorIndices.size);
60
+
61
+ async function handleConfirmSubmit() {
62
+ if (isSubmitting || rows.length === 0) return;
63
+ isSubmitting = true;
64
+ try {
65
+ const validRows = rows.filter((_, idx) => !rowErrorIndices.has(idx));
66
+ if (onsubmit) {
67
+ await onsubmit(validRows);
68
+ }
69
+ } finally {
70
+ isSubmitting = false;
71
+ }
72
+ }
73
+ </script>
74
+
75
+ <div
76
+ class={cn('rounded-xl border border-border bg-card p-5 text-card-foreground shadow-xs space-y-4', className)}
77
+ data-svadmin-component="ImportPreviewValidator"
78
+ >
79
+ <!-- Header & Stats Summary -->
80
+ <header class="flex flex-wrap items-center justify-between gap-3 border-b border-border pb-3">
81
+ <div>
82
+ <h3 class="font-bold text-sm text-foreground">导入前数据预检与行内修正</h3>
83
+ <p class="text-xs text-muted-foreground mt-0.5">高亮异常数据,支持就地双击订正后直接入库</p>
84
+ </div>
85
+
86
+ <!-- Stats summary badges -->
87
+ <div class="flex items-center gap-3 text-xs font-mono">
88
+ <span class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded bg-muted text-muted-foreground">
89
+ 总待导入: <strong class="text-foreground">{rows.length}</strong> 行
90
+ </span>
91
+ <span class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded bg-success/10 text-success font-semibold">
92
+ <CheckCircle2 class="h-3.5 w-3.5" />
93
+ {validCount} 行正常
94
+ </span>
95
+ {#if invalidCount > 0}
96
+ <span class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded bg-destructive/10 text-destructive font-semibold">
97
+ <AlertCircle class="h-3.5 w-3.5" />
98
+ {invalidCount} 行格式异常
99
+ </span>
100
+ {/if}
101
+ </div>
102
+ </header>
103
+
104
+ <!-- Filter Toggle -->
105
+ <div class="flex items-center justify-between text-xs">
106
+ <div class="flex items-center gap-2">
107
+ <button
108
+ type="button"
109
+ class={cn(
110
+ 'inline-flex items-center gap-1 rounded-md border px-2.5 py-1 font-medium transition-colors cursor-pointer',
111
+ !filterOnlyErrors
112
+ ? 'border-primary bg-primary text-primary-foreground'
113
+ : 'border-border bg-background text-muted-foreground hover:text-foreground'
114
+ )}
115
+ onclick={() => (filterOnlyErrors = false)}
116
+ >
117
+ <span>全部数据 ({rows.length})</span>
118
+ </button>
119
+
120
+ {#if invalidCount > 0}
121
+ <button
122
+ type="button"
123
+ class={cn(
124
+ 'inline-flex items-center gap-1 rounded-md border px-2.5 py-1 font-medium transition-colors cursor-pointer',
125
+ filterOnlyErrors
126
+ ? 'border-destructive bg-destructive text-destructive-foreground'
127
+ : 'border-destructive/30 bg-destructive/10 text-destructive hover:bg-destructive/20'
128
+ )}
129
+ onclick={() => (filterOnlyErrors = true)}
130
+ >
131
+ <Filter class="h-3 w-3" />
132
+ <span>仅看异常行 ({invalidCount})</span>
133
+ </button>
134
+ {/if}
135
+ </div>
136
+
137
+ <span class="text-[11px] text-muted-foreground font-mono">
138
+ 可直接在输入框内修改内容订正
139
+ </span>
140
+ </div>
141
+
142
+ <!-- Data Table with Inline Editing -->
143
+ <div class="rounded-lg border border-border overflow-x-auto max-h-96">
144
+ <table class="w-full border-collapse text-xs">
145
+ <thead class="bg-muted/40 border-b border-border text-muted-foreground font-mono sticky top-0 z-10">
146
+ <tr>
147
+ <th class="p-2.5 text-center w-12 font-medium">#</th>
148
+ {#each columns as col (col.key)}
149
+ <th class="p-2.5 text-left font-medium">{col.label}</th>
150
+ {/each}
151
+ <th class="p-2.5 text-center w-12 font-medium">操作</th>
152
+ </tr>
153
+ </thead>
154
+ <tbody class="divide-y divide-border/60">
155
+ {#each displayRows as { row, index } (index)}
156
+ {@const hasError = rowErrorIndices.has(index)}
157
+ <tr class={cn('hover:bg-muted/20 transition-colors', hasError && 'bg-destructive/5')}>
158
+ <!-- Row Index & Error indicator -->
159
+ <td class="p-2.5 text-center font-mono text-muted-foreground">
160
+ {#if hasError}
161
+ <span class="text-destructive font-bold" title="该行包含校验错误">!{index + 1}</span>
162
+ {:else}
163
+ <span class="text-success">✓</span>
164
+ {/if}
165
+ </td>
166
+
167
+ <!-- Columns Input / Cells -->
168
+ {#each columns as col (col.key)}
169
+ {@const cellErr = errorMap.get(`${index}_${col.key}`)}
170
+ {@const val = String(row[col.key] ?? '')}
171
+ <td class="p-1.5">
172
+ <div class="relative">
173
+ <input
174
+ type="text"
175
+ class={cn(
176
+ 'w-full rounded px-2 py-1 font-mono text-xs outline-none transition-all',
177
+ cellErr
178
+ ? 'border border-destructive bg-destructive/10 text-destructive font-semibold'
179
+ : 'border border-transparent hover:border-border focus:border-primary bg-transparent text-foreground focus:bg-background'
180
+ )}
181
+ value={val}
182
+ onchange={(e) => onrowchange?.(index, col.key, (e.currentTarget as HTMLInputElement).value)}
183
+ title={cellErr ?? undefined}
184
+ />
185
+ {#if cellErr}
186
+ <span class="block text-[10px] text-destructive mt-0.5 font-sans leading-tight">
187
+ {cellErr}
188
+ </span>
189
+ {/if}
190
+ </div>
191
+ </td>
192
+ {/each}
193
+
194
+ <!-- Remove Action -->
195
+ <td class="p-2 text-center">
196
+ <button
197
+ type="button"
198
+ class="rounded p-1 text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors cursor-pointer"
199
+ onclick={() => onremoverow?.(index)}
200
+ aria-label="Remove row"
201
+ title="忽略/移除该行"
202
+ >
203
+ <Trash2 class="h-3.5 w-3.5" />
204
+ </button>
205
+ </td>
206
+ </tr>
207
+ {/each}
208
+ </tbody>
209
+ </table>
210
+ </div>
211
+
212
+ <!-- Footer Actions -->
213
+ <footer class="flex items-center justify-between border-t border-border pt-3 text-xs">
214
+ <div class="text-muted-foreground">
215
+ {#if invalidCount > 0}
216
+ <span>当前仍有 <strong>{invalidCount}</strong> 行异常,提交时将仅导入合法的 <strong>{validCount}</strong> 行。</span>
217
+ {:else}
218
+ <span class="text-success font-semibold flex items-center gap-1">
219
+ <Check class="h-3.5 w-3.5" /> 全部数据校验通过,可放心入库
220
+ </span>
221
+ {/if}
222
+ </div>
223
+
224
+ <button
225
+ type="button"
226
+ class="inline-flex items-center gap-1.5 rounded-md bg-primary px-4 py-2 font-semibold text-primary-foreground hover:opacity-90 transition-opacity cursor-pointer disabled:opacity-50 shadow-2xs"
227
+ onclick={handleConfirmSubmit}
228
+ disabled={isSubmitting || validCount === 0}
229
+ >
230
+ {#if isSubmitting}
231
+ <Loader2 class="h-3.5 w-3.5 animate-spin" />
232
+ <span>正在入库提交...</span>
233
+ {:else}
234
+ <span>确认导入 ({validCount} 条正常数据)</span>
235
+ <ArrowRight class="h-3.5 w-3.5" />
236
+ {/if}
237
+ </button>
238
+ </footer>
239
+ </div>