@svadmin/ui 0.118.0 → 0.119.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/dist/app.css +198 -52
- package/dist/app.theme.css +198 -52
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/AuditLogDrawer.svelte +165 -55
- package/dist/components/AuditLogDrawer.svelte.d.ts +4 -2
- package/dist/components/Authenticated.svelte +2 -2
- package/dist/components/AutoSaveIndicator.svelte +2 -2
- package/dist/components/AutoTable.svelte +1 -1
- package/dist/components/Breadcrumbs.svelte +1 -1
- package/dist/components/Breadcrumbs.svelte.d.ts +1 -1
- package/dist/components/CanAccess.svelte +2 -2
- package/dist/components/CancelTaskButton.svelte +2 -2
- package/dist/components/Cascader.svelte +19 -19
- package/dist/components/Cascader.svelte.d.ts +19 -19
- package/dist/components/ColorPicker.svelte +9 -9
- package/dist/components/ColorPicker.svelte.d.ts +9 -9
- package/dist/components/ComboboxField.svelte +15 -15
- package/dist/components/ComboboxField.svelte.d.ts +15 -15
- package/dist/components/ConcurrentConflictModal.svelte +292 -0
- package/dist/components/ConcurrentConflictModal.svelte.d.ts +24 -0
- package/dist/components/ConfigErrorScreen.svelte +2 -2
- package/dist/components/ConfirmDialog.svelte +6 -4
- package/dist/components/ConfirmDialog.svelte.d.ts +2 -2
- package/dist/components/CronExpressionBuilder.svelte +389 -0
- package/dist/components/CronExpressionBuilder.svelte.d.ts +20 -0
- package/dist/components/DateRangeInput.svelte +22 -22
- package/dist/components/DateRangeInput.svelte.d.ts +22 -22
- package/dist/components/DateTimeInput.svelte +2 -2
- package/dist/components/DateTimeInput.svelte.d.ts +2 -2
- package/dist/components/EmptyState.svelte +2 -2
- package/dist/components/ErrorComponent.svelte +2 -2
- package/dist/components/ErrorSummary.svelte +2 -2
- package/dist/components/FieldRenderer.svelte +3 -3
- package/dist/components/FileUpload.svelte +16 -16
- package/dist/components/FileUpload.svelte.d.ts +16 -16
- package/dist/components/FileUploadField.svelte +7 -7
- package/dist/components/FileUploadField.svelte.d.ts +7 -7
- package/dist/components/FilterDropdown.svelte.d.ts +1 -1
- package/dist/components/ForgotPasswordPage.svelte +2 -2
- package/dist/components/Header.svelte +2 -2
- package/dist/components/LiveIndicator.svelte +2 -2
- package/dist/components/LoginPage.svelte +2 -2
- package/dist/components/MetricGrid.svelte +163 -0
- package/dist/components/MetricGrid.svelte.d.ts +39 -0
- package/dist/components/MicroAppFrame.svelte +290 -0
- package/dist/components/MicroAppFrame.svelte.d.ts +36 -0
- package/dist/components/MoneyInput.svelte +15 -15
- package/dist/components/MoneyInput.svelte.d.ts +15 -15
- package/dist/components/NotificationCenter.svelte +16 -16
- package/dist/components/NotificationCenter.svelte.d.ts +16 -16
- package/dist/components/NumberInput.svelte +13 -13
- package/dist/components/NumberInput.svelte.d.ts +13 -13
- package/dist/components/NumericInput.svelte +16 -16
- package/dist/components/NumericInput.svelte.d.ts +16 -16
- package/dist/components/OfflineGuard.svelte +65 -0
- package/dist/components/OfflineGuard.svelte.d.ts +15 -0
- package/dist/components/OrgChart.svelte +171 -0
- package/dist/components/OrgChart.svelte.d.ts +26 -0
- package/dist/components/PageSkeleton.svelte +2 -2
- package/dist/components/PercentInput.svelte +14 -14
- package/dist/components/PercentInput.svelte.d.ts +14 -14
- package/dist/components/PresenceAvatarGroup.svelte +78 -29
- package/dist/components/PresenceAvatarGroup.svelte.d.ts +14 -8
- package/dist/components/Rate.svelte +9 -9
- package/dist/components/Rate.svelte.d.ts +9 -9
- package/dist/components/RegisterPage.svelte +2 -2
- package/dist/components/ResizeBox.svelte.d.ts +1 -1
- package/dist/components/RetryTaskButton.svelte +2 -2
- package/dist/components/SafeDeleteConfirm.svelte +301 -0
- package/dist/components/SafeDeleteConfirm.svelte.d.ts +24 -0
- package/dist/components/SignaturePad.svelte +19 -3
- package/dist/components/SignaturePad.svelte.d.ts +3 -0
- package/dist/components/SliderCaptcha.svelte +448 -0
- package/dist/components/SliderCaptcha.svelte.d.ts +26 -0
- package/dist/components/TagsInput.svelte +10 -10
- package/dist/components/TagsInput.svelte.d.ts +10 -10
- package/dist/components/TaskCenter.svelte +450 -0
- package/dist/components/TaskCenter.svelte.d.ts +37 -0
- package/dist/components/TaskDetails.svelte +2 -2
- package/dist/components/TaskList.svelte +2 -2
- package/dist/components/TaskProgressBar.svelte +2 -2
- package/dist/components/TaskStatusBadge.svelte +2 -2
- package/dist/components/ThemedTitle.svelte +2 -2
- package/dist/components/Tour.svelte +9 -1
- package/dist/components/Tour.svelte.d.ts +2 -1
- package/dist/components/Transfer.svelte +11 -11
- package/dist/components/Transfer.svelte.d.ts +11 -11
- package/dist/components/TreeSelect.svelte +17 -17
- package/dist/components/TreeSelect.svelte.d.ts +17 -17
- package/dist/components/TreeTable.svelte.d.ts +1 -1
- package/dist/components/TrendIndicator.svelte +177 -0
- package/dist/components/TrendIndicator.svelte.d.ts +27 -0
- package/dist/components/UndoableNotification.svelte +2 -2
- package/dist/components/UpdatePasswordPage.svelte +2 -2
- package/dist/components/VirtualTreeSelect.svelte +431 -0
- package/dist/components/VirtualTreeSelect.svelte.d.ts +34 -0
- package/dist/components/buttons/CreateButton.svelte +2 -2
- package/dist/components/buttons/ExportButton.svelte +2 -2
- package/dist/components/buttons/ListButton.svelte +2 -2
- package/dist/components/buttons/RefreshButton.svelte +2 -2
- package/dist/components/buttons/SaveButton.svelte +2 -2
- package/dist/components/charts/GaugeChart.svelte +452 -57
- package/dist/components/charts/GaugeChart.svelte.d.ts +61 -10
- package/dist/components/content/AuditTimeline.svelte +125 -28
- package/dist/components/content/AuditTimeline.svelte.d.ts +30 -16
- package/dist/components/fields/JsonField.svelte +2 -2
- package/dist/components/fields/MultiSelectField.svelte +2 -2
- package/dist/components/fields/RelationField.svelte +2 -2
- package/dist/components/fields/RichTextField.svelte +2 -2
- package/dist/components/fields/SelectField.svelte +2 -2
- package/dist/components/list-state.svelte.d.ts +1 -1
- package/dist/components/ui/checkbox/checkbox.svelte.d.ts +1 -1
- package/dist/components/ui/command/command-dialog.svelte.d.ts +1 -1
- package/dist/components/ui/command/index.d.ts +1 -1
- package/dist/components/ui/input/input.svelte.d.ts +1 -1
- package/dist/components/ui/switch/switch.svelte.d.ts +1 -1
- package/dist/components/useNetworkStatus.d.svelte.ts +1 -0
- package/dist/components/useNetworkStatus.svelte.d.ts +30 -0
- package/dist/components/useNetworkStatus.svelte.js +74 -0
- package/dist/design-system.d.ts +4 -4
- package/dist/index.d.ts +31 -5
- package/dist/index.js +23 -3
- package/dist/recipes.d.ts +91 -619
- package/package.json +30 -30
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { ChevronRight, ChevronDown, Check, Minus, Search, X } from '@lucide/svelte';
|
|
3
|
+
import { cn } from '../utils.js';
|
|
4
|
+
|
|
5
|
+
export interface VirtualTreeNode {
|
|
6
|
+
value: string | number;
|
|
7
|
+
label: string;
|
|
8
|
+
children?: VirtualTreeNode[] | undefined;
|
|
9
|
+
disabled?: boolean | undefined;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface VirtualTreeSelectProps {
|
|
14
|
+
/** Hierarchical tree nodes */
|
|
15
|
+
options?: VirtualTreeNode[] | undefined;
|
|
16
|
+
/** Bound value: single value or array of values for multiple */
|
|
17
|
+
value?: string | number | (string | number)[] | undefined;
|
|
18
|
+
/** Multiple selection mode */
|
|
19
|
+
multiple?: boolean | undefined;
|
|
20
|
+
/** Placeholder when no value is selected */
|
|
21
|
+
placeholder?: string | undefined;
|
|
22
|
+
/** Disabled state */
|
|
23
|
+
disabled?: boolean | undefined;
|
|
24
|
+
/** Height of the virtual list viewport in pixels (default: 260) */
|
|
25
|
+
height?: number | undefined;
|
|
26
|
+
/** Fixed item height in pixels for virtual row slicing (default: 32) */
|
|
27
|
+
itemHeight?: number | undefined;
|
|
28
|
+
/** Enable search filter */
|
|
29
|
+
searchable?: boolean | undefined;
|
|
30
|
+
/** Cascade selection: selecting parent selects all children (default: true for multiple) */
|
|
31
|
+
cascade?: boolean | undefined;
|
|
32
|
+
/** Extra classes */
|
|
33
|
+
class?: string | undefined;
|
|
34
|
+
/** Change event callback */
|
|
35
|
+
onchange?: ((val: string | number | (string | number)[]) => void) | undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let {
|
|
39
|
+
options = [],
|
|
40
|
+
value = $bindable(undefined),
|
|
41
|
+
multiple = false,
|
|
42
|
+
placeholder = 'Please select...',
|
|
43
|
+
disabled = false,
|
|
44
|
+
height = 260,
|
|
45
|
+
itemHeight = 32,
|
|
46
|
+
searchable = true,
|
|
47
|
+
cascade = true,
|
|
48
|
+
class: className = '',
|
|
49
|
+
onchange,
|
|
50
|
+
}: VirtualTreeSelectProps = $props();
|
|
51
|
+
|
|
52
|
+
let isOpen = $state(false);
|
|
53
|
+
let searchQuery = $state('');
|
|
54
|
+
let expandedKeys = $state<Set<string | number>>(new Set());
|
|
55
|
+
let containerEl = $state<HTMLDivElement | null>(null);
|
|
56
|
+
let scrollTop = $state(0);
|
|
57
|
+
|
|
58
|
+
// 内部规范化选中值集合
|
|
59
|
+
const selectedSet = $derived.by<Set<string | number>>(() => {
|
|
60
|
+
if (value === undefined || value === null) return new Set();
|
|
61
|
+
if (Array.isArray(value)) return new Set(value);
|
|
62
|
+
return new Set([value]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// 判断是否为叶子节点
|
|
66
|
+
function isLeaf(node: VirtualTreeNode): boolean {
|
|
67
|
+
return !node.children || node.children.length === 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 展开 / 折叠切换
|
|
71
|
+
function toggleExpand(key: string | number, e: MouseEvent) {
|
|
72
|
+
e.stopPropagation();
|
|
73
|
+
const next = new Set(expandedKeys);
|
|
74
|
+
if (next.has(key)) {
|
|
75
|
+
next.delete(key);
|
|
76
|
+
} else {
|
|
77
|
+
next.add(key);
|
|
78
|
+
}
|
|
79
|
+
expandedKeys = next;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 节点查找映射表
|
|
83
|
+
const nodeMap = $derived.by<Map<string | number, VirtualTreeNode>>(() => {
|
|
84
|
+
const map = new Map<string | number, VirtualTreeNode>();
|
|
85
|
+
function traverse(list: VirtualTreeNode[]) {
|
|
86
|
+
for (const n of list) {
|
|
87
|
+
map.set(n.value, n);
|
|
88
|
+
if (n.children) traverse(n.children);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
traverse(options);
|
|
92
|
+
return map;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// 获取某个节点的所有叶子子孙节点
|
|
96
|
+
function getAllDescendantValues(node: VirtualTreeNode): (string | number)[] {
|
|
97
|
+
const res: (string | number)[] = [];
|
|
98
|
+
function walk(curr: VirtualTreeNode) {
|
|
99
|
+
if (isLeaf(curr)) {
|
|
100
|
+
res.push(curr.value);
|
|
101
|
+
} else if (curr.children) {
|
|
102
|
+
for (const c of curr.children) walk(c);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
walk(node);
|
|
106
|
+
return res;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// 检查节点的选中/半选状态 (仅用于多选 + cascade)
|
|
110
|
+
function getNodeCheckState(node: VirtualTreeNode): 'checked' | 'indeterminate' | 'unchecked' {
|
|
111
|
+
if (isLeaf(node)) {
|
|
112
|
+
return selectedSet.has(node.value) ? 'checked' : 'unchecked';
|
|
113
|
+
}
|
|
114
|
+
const descendants = getAllDescendantValues(node);
|
|
115
|
+
if (descendants.length === 0) {
|
|
116
|
+
return selectedSet.has(node.value) ? 'checked' : 'unchecked';
|
|
117
|
+
}
|
|
118
|
+
let checkedCount = 0;
|
|
119
|
+
for (const d of descendants) {
|
|
120
|
+
if (selectedSet.has(d)) checkedCount++;
|
|
121
|
+
}
|
|
122
|
+
if (checkedCount === descendants.length) return 'checked';
|
|
123
|
+
if (checkedCount > 0) return 'indeterminate';
|
|
124
|
+
return 'unchecked';
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 处理节点选中操作
|
|
128
|
+
function handleSelectNode(node: VirtualTreeNode) {
|
|
129
|
+
if (node.disabled) return;
|
|
130
|
+
|
|
131
|
+
if (!multiple) {
|
|
132
|
+
value = node.value;
|
|
133
|
+
onchange?.(node.value);
|
|
134
|
+
isOpen = false;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 多选模式
|
|
139
|
+
const next = new Set(selectedSet);
|
|
140
|
+
if (cascade && !isLeaf(node)) {
|
|
141
|
+
const descendants = getAllDescendantValues(node);
|
|
142
|
+
const isCurrentlyAll = descendants.every((val) => next.has(val));
|
|
143
|
+
if (isCurrentlyAll) {
|
|
144
|
+
for (const v of descendants) next.delete(v);
|
|
145
|
+
next.delete(node.value);
|
|
146
|
+
} else {
|
|
147
|
+
for (const v of descendants) next.add(v);
|
|
148
|
+
next.add(node.value);
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
if (next.has(node.value)) {
|
|
152
|
+
next.delete(node.value);
|
|
153
|
+
} else {
|
|
154
|
+
next.add(node.value);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const arr = Array.from(next);
|
|
159
|
+
value = arr;
|
|
160
|
+
onchange?.(arr);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// 搜索过滤与祖先自动展开
|
|
164
|
+
interface FlatRow {
|
|
165
|
+
node: VirtualTreeNode;
|
|
166
|
+
depth: number;
|
|
167
|
+
hasChildren: boolean;
|
|
168
|
+
expanded: boolean;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const flattenedRows = $derived.by<FlatRow[]>(() => {
|
|
172
|
+
const q = searchQuery.trim().toLowerCase();
|
|
173
|
+
const rows: FlatRow[] = [];
|
|
174
|
+
|
|
175
|
+
// 若有搜索关键词,先找出命中节点及其所有上级祖先的 keys
|
|
176
|
+
const matchExpanded = new Set<string | number>();
|
|
177
|
+
const matchedKeys = new Set<string | number>();
|
|
178
|
+
if (q) {
|
|
179
|
+
function findMatches(list: VirtualTreeNode[], ancestors: (string | number)[]) {
|
|
180
|
+
for (const n of list) {
|
|
181
|
+
const match = n.label.toLowerCase().includes(q);
|
|
182
|
+
if (match) {
|
|
183
|
+
matchedKeys.add(n.value);
|
|
184
|
+
for (const a of ancestors) matchExpanded.add(a);
|
|
185
|
+
}
|
|
186
|
+
if (n.children) {
|
|
187
|
+
findMatches(n.children, [...ancestors, n.value]);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
findMatches(options, []);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function walk(list: VirtualTreeNode[], depth: number) {
|
|
195
|
+
for (const n of list) {
|
|
196
|
+
const hasChildren = Boolean(n.children && n.children.length > 0);
|
|
197
|
+
const isExp = q ? matchExpanded.has(n.value) || expandedKeys.has(n.value) : expandedKeys.has(n.value);
|
|
198
|
+
|
|
199
|
+
// 如果在搜索模式,只有自身匹配或子孙匹配才展示
|
|
200
|
+
const shouldShow = !q || matchedKeys.has(n.value) || matchExpanded.has(n.value);
|
|
201
|
+
if (shouldShow) {
|
|
202
|
+
rows.push({
|
|
203
|
+
node: n,
|
|
204
|
+
depth,
|
|
205
|
+
hasChildren,
|
|
206
|
+
expanded: isExp,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (hasChildren && n.children && (isExp || (q && matchExpanded.has(n.value)))) {
|
|
211
|
+
walk(n.children, depth + 1);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
walk(options, 0);
|
|
217
|
+
return rows;
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// 虚拟滚动计算切片
|
|
221
|
+
const totalCount = $derived(flattenedRows.length);
|
|
222
|
+
const totalHeight = $derived(totalCount * itemHeight);
|
|
223
|
+
const buffer = 4;
|
|
224
|
+
const visibleCount = $derived(Math.ceil(height / itemHeight));
|
|
225
|
+
|
|
226
|
+
const startIndex = $derived(Math.max(0, Math.floor(scrollTop / itemHeight) - buffer));
|
|
227
|
+
const endIndex = $derived(Math.min(totalCount, startIndex + visibleCount + buffer * 2));
|
|
228
|
+
const visibleRows = $derived(flattenedRows.slice(startIndex, endIndex));
|
|
229
|
+
const offsetY = $derived(startIndex * itemHeight);
|
|
230
|
+
|
|
231
|
+
function handleScroll(e: Event) {
|
|
232
|
+
const target = e.currentTarget as HTMLElement;
|
|
233
|
+
scrollTop = target.scrollTop;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// 标签回显文本
|
|
237
|
+
const displayLabels = $derived.by<string[]>(() => {
|
|
238
|
+
if (!value) return [];
|
|
239
|
+
if (Array.isArray(value)) {
|
|
240
|
+
return value.map((v) => nodeMap.get(v)?.label ?? String(v));
|
|
241
|
+
}
|
|
242
|
+
const single = nodeMap.get(value);
|
|
243
|
+
return single ? [single.label] : [String(value)];
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
function removeSingleTag(val: string | number, e: MouseEvent) {
|
|
247
|
+
e.stopPropagation();
|
|
248
|
+
if (!multiple) {
|
|
249
|
+
value = undefined;
|
|
250
|
+
onchange?.(undefined as unknown as string);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const next = new Set(selectedSet);
|
|
254
|
+
next.delete(val);
|
|
255
|
+
const arr = Array.from(next);
|
|
256
|
+
value = arr;
|
|
257
|
+
onchange?.(arr);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function handleClear(e: MouseEvent) {
|
|
261
|
+
e.stopPropagation();
|
|
262
|
+
value = multiple ? [] : undefined;
|
|
263
|
+
onchange?.(multiple ? [] : (undefined as unknown as string));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// 点击外部收起
|
|
267
|
+
function handleClickOutside(e: MouseEvent) {
|
|
268
|
+
if (containerEl && !containerEl.contains(e.target as Node)) {
|
|
269
|
+
isOpen = false;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
</script>
|
|
273
|
+
|
|
274
|
+
<svelte:window onclick={handleClickOutside} />
|
|
275
|
+
|
|
276
|
+
<div
|
|
277
|
+
bind:this={containerEl}
|
|
278
|
+
data-svadmin-component="VirtualTreeSelect"
|
|
279
|
+
class={cn('relative w-full text-xs font-sans', className)}
|
|
280
|
+
>
|
|
281
|
+
<!-- Input trigger box -->
|
|
282
|
+
<button
|
|
283
|
+
type="button"
|
|
284
|
+
{disabled}
|
|
285
|
+
onclick={() => { if (!disabled) isOpen = !isOpen; }}
|
|
286
|
+
class={cn(
|
|
287
|
+
'flex min-h-9 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-1.5 text-xs shadow-xs transition-colors',
|
|
288
|
+
'focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring',
|
|
289
|
+
'hover:border-accent disabled:cursor-not-allowed disabled:opacity-50 text-left'
|
|
290
|
+
)}
|
|
291
|
+
>
|
|
292
|
+
<div class="flex flex-wrap items-center gap-1 overflow-hidden pr-2 flex-1">
|
|
293
|
+
{#if displayLabels.length === 0}
|
|
294
|
+
<span class="text-muted-foreground select-none">{placeholder}</span>
|
|
295
|
+
{:else if !multiple}
|
|
296
|
+
<span class="text-foreground truncate font-medium">{displayLabels[0]}</span>
|
|
297
|
+
{:else}
|
|
298
|
+
{#each displayLabels as tag, idx (idx)}
|
|
299
|
+
{@const tagVal = Array.isArray(value) ? value[idx] : undefined}
|
|
300
|
+
<span class="inline-flex items-center gap-1 rounded bg-secondary/80 text-secondary-foreground px-1.5 py-0.5 text-[11px] font-medium border border-border/40">
|
|
301
|
+
<span class="truncate max-w-[120px]">{tag}</span>
|
|
302
|
+
{#if !disabled && tagVal !== undefined}
|
|
303
|
+
<span
|
|
304
|
+
role="button"
|
|
305
|
+
tabindex="-1"
|
|
306
|
+
class="hover:text-destructive cursor-pointer"
|
|
307
|
+
onclick={(e) => removeSingleTag(tagVal, e)}
|
|
308
|
+
onkeydown={(e) => { if (e.key === 'Enter') removeSingleTag(tagVal, e as unknown as MouseEvent); }}
|
|
309
|
+
>
|
|
310
|
+
<X class="h-3 w-3" />
|
|
311
|
+
</span>
|
|
312
|
+
{/if}
|
|
313
|
+
</span>
|
|
314
|
+
{/each}
|
|
315
|
+
{/if}
|
|
316
|
+
</div>
|
|
317
|
+
|
|
318
|
+
<div class="flex items-center gap-1 text-muted-foreground shrink-0">
|
|
319
|
+
{#if displayLabels.length > 0 && !disabled}
|
|
320
|
+
<span
|
|
321
|
+
role="button"
|
|
322
|
+
tabindex="-1"
|
|
323
|
+
aria-label="Clear selection"
|
|
324
|
+
class="hover:text-foreground cursor-pointer p-0.5"
|
|
325
|
+
onclick={handleClear}
|
|
326
|
+
onkeydown={(e) => { if (e.key === 'Enter') handleClear(e as unknown as MouseEvent); }}
|
|
327
|
+
>
|
|
328
|
+
<X class="h-3.5 w-3.5" />
|
|
329
|
+
</span>
|
|
330
|
+
{/if}
|
|
331
|
+
<ChevronDown class={cn('h-3.5 w-3.5 transition-transform duration-200', isOpen && 'rotate-180')} />
|
|
332
|
+
</div>
|
|
333
|
+
</button>
|
|
334
|
+
|
|
335
|
+
<!-- Dropdown popover with virtual list -->
|
|
336
|
+
{#if isOpen}
|
|
337
|
+
<div
|
|
338
|
+
class="absolute left-0 top-full z-50 mt-1 w-full rounded-md border border-border bg-popover text-popover-foreground shadow-lg overflow-hidden animate-in fade-in-0 zoom-in-95"
|
|
339
|
+
>
|
|
340
|
+
{#if searchable}
|
|
341
|
+
<div class="p-2 border-b border-border/60 bg-muted/20">
|
|
342
|
+
<div class="relative flex items-center">
|
|
343
|
+
<Search class="absolute left-2.5 h-3.5 w-3.5 text-muted-foreground" />
|
|
344
|
+
<input
|
|
345
|
+
type="text"
|
|
346
|
+
bind:value={searchQuery}
|
|
347
|
+
placeholder="Search nodes..."
|
|
348
|
+
class="w-full rounded-sm border border-input bg-background pl-8 pr-2.5 py-1 text-xs focus:outline-hidden focus:ring-1 focus:ring-ring"
|
|
349
|
+
/>
|
|
350
|
+
</div>
|
|
351
|
+
</div>
|
|
352
|
+
{/if}
|
|
353
|
+
|
|
354
|
+
<!-- Virtual Scrolling Viewport -->
|
|
355
|
+
<div
|
|
356
|
+
class="overflow-y-auto overscroll-contain"
|
|
357
|
+
style="height: {height}px;"
|
|
358
|
+
onscroll={handleScroll}
|
|
359
|
+
>
|
|
360
|
+
{#if flattenedRows.length === 0}
|
|
361
|
+
<div class="py-8 text-center text-muted-foreground text-xs select-none">
|
|
362
|
+
No matching nodes
|
|
363
|
+
</div>
|
|
364
|
+
{:else}
|
|
365
|
+
<div class="relative w-full" style="height: {totalHeight}px;">
|
|
366
|
+
<div
|
|
367
|
+
class="absolute left-0 top-0 w-full"
|
|
368
|
+
style="transform: translateY({offsetY}px);"
|
|
369
|
+
>
|
|
370
|
+
{#each visibleRows as row (row.node.value)}
|
|
371
|
+
{@const checkState = getNodeCheckState(row.node)}
|
|
372
|
+
{@const isSelected = selectedSet.has(row.node.value)}
|
|
373
|
+
<div
|
|
374
|
+
role="button"
|
|
375
|
+
tabindex="0"
|
|
376
|
+
style="height: {itemHeight}px; padding-left: {row.depth * 18 + 8}px;"
|
|
377
|
+
class={cn(
|
|
378
|
+
'flex items-center gap-1.5 px-2 text-xs transition-colors cursor-pointer select-none',
|
|
379
|
+
'hover:bg-accent hover:text-accent-foreground',
|
|
380
|
+
isSelected && !multiple && 'bg-primary/10 font-medium text-primary',
|
|
381
|
+
row.node.disabled && 'opacity-40 cursor-not-allowed hover:bg-transparent'
|
|
382
|
+
)}
|
|
383
|
+
onclick={() => handleSelectNode(row.node)}
|
|
384
|
+
onkeydown={(e) => { if (e.key === 'Enter') handleSelectNode(row.node); }}
|
|
385
|
+
>
|
|
386
|
+
<!-- Expand/collapse toggle -->
|
|
387
|
+
{#if row.hasChildren}
|
|
388
|
+
<button
|
|
389
|
+
type="button"
|
|
390
|
+
class="flex h-4 w-4 items-center justify-center rounded text-muted-foreground hover:text-foreground"
|
|
391
|
+
onclick={(e) => toggleExpand(row.node.value, e)}
|
|
392
|
+
>
|
|
393
|
+
<ChevronRight class={cn('h-3.5 w-3.5 transition-transform', row.expanded && 'rotate-90')} />
|
|
394
|
+
</button>
|
|
395
|
+
{:else}
|
|
396
|
+
<span class="w-4"></span>
|
|
397
|
+
{/if}
|
|
398
|
+
|
|
399
|
+
<!-- Checkbox for multiple selection -->
|
|
400
|
+
{#if multiple}
|
|
401
|
+
<span
|
|
402
|
+
class={cn(
|
|
403
|
+
'flex h-3.5 w-3.5 items-center justify-center rounded-xs border transition-colors',
|
|
404
|
+
checkState === 'checked' && 'border-primary bg-primary text-primary-foreground',
|
|
405
|
+
checkState === 'indeterminate' && 'border-primary bg-primary text-primary-foreground',
|
|
406
|
+
checkState === 'unchecked' && 'border-muted-foreground/50 bg-background'
|
|
407
|
+
)}
|
|
408
|
+
>
|
|
409
|
+
{#if checkState === 'checked'}
|
|
410
|
+
<Check class="h-2.5 w-2.5 stroke-[3]" />
|
|
411
|
+
{:else if checkState === 'indeterminate'}
|
|
412
|
+
<Minus class="h-2.5 w-2.5 stroke-[3]" />
|
|
413
|
+
{/if}
|
|
414
|
+
</span>
|
|
415
|
+
{/if}
|
|
416
|
+
|
|
417
|
+
<!-- Node label -->
|
|
418
|
+
<span class="truncate flex-1">{row.node.label}</span>
|
|
419
|
+
|
|
420
|
+
{#if !multiple && isSelected}
|
|
421
|
+
<Check class="h-3.5 w-3.5 text-primary shrink-0 mr-1" />
|
|
422
|
+
{/if}
|
|
423
|
+
</div>
|
|
424
|
+
{/each}
|
|
425
|
+
</div>
|
|
426
|
+
</div>
|
|
427
|
+
{/if}
|
|
428
|
+
</div>
|
|
429
|
+
</div>
|
|
430
|
+
{/if}
|
|
431
|
+
</div>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface VirtualTreeNode {
|
|
2
|
+
value: string | number;
|
|
3
|
+
label: string;
|
|
4
|
+
children?: VirtualTreeNode[] | undefined;
|
|
5
|
+
disabled?: boolean | undefined;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface VirtualTreeSelectProps {
|
|
9
|
+
/** Hierarchical tree nodes */
|
|
10
|
+
options?: VirtualTreeNode[] | undefined;
|
|
11
|
+
/** Bound value: single value or array of values for multiple */
|
|
12
|
+
value?: string | number | (string | number)[] | undefined;
|
|
13
|
+
/** Multiple selection mode */
|
|
14
|
+
multiple?: boolean | undefined;
|
|
15
|
+
/** Placeholder when no value is selected */
|
|
16
|
+
placeholder?: string | undefined;
|
|
17
|
+
/** Disabled state */
|
|
18
|
+
disabled?: boolean | undefined;
|
|
19
|
+
/** Height of the virtual list viewport in pixels (default: 260) */
|
|
20
|
+
height?: number | undefined;
|
|
21
|
+
/** Fixed item height in pixels for virtual row slicing (default: 32) */
|
|
22
|
+
itemHeight?: number | undefined;
|
|
23
|
+
/** Enable search filter */
|
|
24
|
+
searchable?: boolean | undefined;
|
|
25
|
+
/** Cascade selection: selecting parent selects all children (default: true for multiple) */
|
|
26
|
+
cascade?: boolean | undefined;
|
|
27
|
+
/** Extra classes */
|
|
28
|
+
class?: string | undefined;
|
|
29
|
+
/** Change event callback */
|
|
30
|
+
onchange?: ((val: string | number | (string | number)[]) => void) | undefined;
|
|
31
|
+
}
|
|
32
|
+
declare const VirtualTreeSelect: import("svelte").Component<VirtualTreeSelectProps, {}, "value">;
|
|
33
|
+
type VirtualTreeSelect = ReturnType<typeof VirtualTreeSelect>;
|
|
34
|
+
export default VirtualTreeSelect;
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
hideText = false,
|
|
15
15
|
accessControl = { enabled: true, hideIfUnauthorized: true },
|
|
16
16
|
class: className = '',
|
|
17
|
-
}
|
|
17
|
+
}: {
|
|
18
18
|
resource: string;
|
|
19
19
|
label?: string;
|
|
20
20
|
children?: Snippet;
|
|
21
21
|
hideText?: boolean;
|
|
22
22
|
accessControl?: ButtonAccessControl;
|
|
23
23
|
class?: string;
|
|
24
|
-
}
|
|
24
|
+
} = $props();
|
|
25
25
|
|
|
26
26
|
const nav = useNavigation();
|
|
27
27
|
const resourceDefinition = $derived.by(() => {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
format = 'csv',
|
|
26
26
|
meta,
|
|
27
27
|
class: className = '',
|
|
28
|
-
}
|
|
28
|
+
}: {
|
|
29
29
|
resource: string;
|
|
30
30
|
label?: string;
|
|
31
31
|
children?: Snippet;
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
format?: ExportFormat;
|
|
43
43
|
meta?: Record<string, unknown>;
|
|
44
44
|
class?: string;
|
|
45
|
-
}
|
|
45
|
+
} = $props();
|
|
46
46
|
|
|
47
47
|
const binding = useResourceContract(() => resource);
|
|
48
48
|
const can = useCan(() => ({
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
|
|
7
7
|
const i18n = useTranslation();
|
|
8
8
|
|
|
9
|
-
let { resource: resourceName, hideText = false, label, children, onBeforeNavigate, class: className = '' }
|
|
9
|
+
let { resource: resourceName, hideText = false, label, children, onBeforeNavigate, class: className = '' }: {
|
|
10
10
|
resource: string;
|
|
11
11
|
hideText?: boolean;
|
|
12
12
|
label?: string;
|
|
13
13
|
children?: Snippet;
|
|
14
14
|
onBeforeNavigate?: (navigate: () => void) => void;
|
|
15
15
|
class?: string;
|
|
16
|
-
}
|
|
16
|
+
} = $props();
|
|
17
17
|
|
|
18
18
|
const nav = useNavigation();
|
|
19
19
|
const res = $derived((() => {
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
children,
|
|
14
14
|
hideText = false,
|
|
15
15
|
class: className = '',
|
|
16
|
-
}
|
|
16
|
+
}: {
|
|
17
17
|
resource: string;
|
|
18
18
|
label?: string;
|
|
19
19
|
children?: Snippet;
|
|
20
20
|
hideText?: boolean;
|
|
21
21
|
class?: string;
|
|
22
|
-
}
|
|
22
|
+
} = $props();
|
|
23
23
|
|
|
24
24
|
const binding = useResourceContract(() => resource);
|
|
25
25
|
const context = captureAdminContext();
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
hideText = false,
|
|
14
14
|
type = 'submit',
|
|
15
15
|
class: className = '',
|
|
16
|
-
}
|
|
16
|
+
}: {
|
|
17
17
|
loading?: boolean;
|
|
18
18
|
label?: string;
|
|
19
19
|
children?: Snippet;
|
|
20
20
|
hideText?: boolean;
|
|
21
21
|
type?: 'submit' | 'button';
|
|
22
22
|
class?: string;
|
|
23
|
-
}
|
|
23
|
+
} = $props();
|
|
24
24
|
|
|
25
25
|
const displayText = $derived(label ?? i18n.t('common.save'));
|
|
26
26
|
</script>
|