@warkypublic/svelix 0.1.46 → 0.2.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.
- package/README.md +93 -33
- package/dist/components/BetterMenu/BetterMenu.svelte +21 -37
- package/dist/components/BetterMenu/BetterMenuAsyncButton.svelte +21 -31
- package/dist/components/BetterMenu/BetterMenuPreview.svelte +27 -29
- package/dist/components/BetterMenu/MenuRenderer.svelte +40 -51
- package/dist/components/Boxer/Boxer.svelte +492 -602
- package/dist/components/Boxer/BoxerTarget.svelte +6 -46
- package/dist/components/Boxer/BoxerTarget.svelte.d.ts +1 -0
- package/dist/components/Boxer/types.d.ts +0 -1
- package/dist/components/Button.svelte +19 -43
- package/dist/components/ButtonPreview.svelte +2 -11
- package/dist/components/CardGrid/CardGrid.svelte +489 -614
- package/dist/components/CardGrid/CardGrid.svelte.d.ts +4 -0
- package/dist/components/CardGrid/CardGridFilterPanel.svelte +111 -90
- package/dist/components/CardGrid/DefaultCard.svelte +86 -97
- package/dist/components/CardGrid/DefaultCard.svelte.d.ts +1 -0
- package/dist/components/CardGrid/ImageCardStory.svelte +87 -36
- package/dist/components/CardGrid/cardGrid.d.ts +24 -0
- package/dist/components/CardGrid/cardGrid.js +20 -0
- package/dist/components/ContentEditor/CollaboraInsertTextDemo.svelte +5 -10
- package/dist/components/ContentEditor/ContentEditor.svelte +24 -50
- package/dist/components/ContentEditor/subcomponents/AudioPlayer.svelte +17 -17
- package/dist/components/ContentEditor/subcomponents/CollaboraEditor.svelte +244 -309
- package/dist/components/ContentEditor/subcomponents/EmailViewer.svelte +2 -3
- package/dist/components/ContentEditor/subcomponents/ImageViewer.svelte +14 -15
- package/dist/components/ContentEditor/subcomponents/MarkdownViewer.svelte +74 -90
- package/dist/components/ContentEditor/subcomponents/MonacoEditor.svelte +75 -103
- package/dist/components/ContentEditor/subcomponents/Office365Editor.svelte +234 -297
- package/dist/components/ContentEditor/subcomponents/PdfViewer.svelte +14 -20
- package/dist/components/ContentEditor/subcomponents/TextEditor.svelte +122 -150
- package/dist/components/ContentEditor/subcomponents/UnknownFile.svelte +105 -126
- package/dist/components/ContentEditor/subcomponents/VideoPlayer.svelte +17 -17
- package/dist/components/ContentEditor/subcomponents/ZipViewer.svelte +2 -3
- package/dist/components/ErrorBoundary/ErrorBoundary.svelte +41 -58
- package/dist/components/ErrorBoundary/ErrorBoundaryPreview.svelte +8 -16
- package/dist/components/Former/Former.svelte +306 -424
- package/dist/components/Former/FormerButtonArea.svelte +17 -68
- package/dist/components/Former/FormerDrawer.svelte +16 -80
- package/dist/components/Former/FormerDrawerPreview.svelte +99 -89
- package/dist/components/Former/FormerModal.svelte +16 -74
- package/dist/components/Former/FormerModalPreview.svelte +99 -89
- package/dist/components/Former/FormerPreview.svelte +76 -78
- package/dist/components/Former/FormerRestApiPreview.svelte +55 -48
- package/dist/components/Former/formerOverlayHelpers.svelte.d.ts +11 -0
- package/dist/components/Former/formerOverlayHelpers.svelte.js +38 -0
- package/dist/components/Former/index.d.ts +1 -0
- package/dist/components/Former/index.js +1 -0
- package/dist/components/FormerControllers/ButtonCtrl.svelte +13 -49
- package/dist/components/FormerControllers/CtrlFieldShell.svelte +15 -0
- package/dist/components/FormerControllers/CtrlFieldShell.svelte.d.ts +12 -0
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrl.svelte +285 -457
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrlCalendar.svelte +95 -136
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrlPickerPanel.svelte +3 -62
- package/dist/components/FormerControllers/DateTimeCtrl/DateTimeCtrlTimeFields.svelte +143 -217
- package/dist/components/FormerControllers/IconButtonCtrl.svelte +13 -47
- package/dist/components/FormerControllers/InlineWrapper.svelte +12 -41
- package/dist/components/FormerControllers/InlineWrapperPreview.svelte +4 -26
- package/dist/components/FormerControllers/NativeSelectCtrl.svelte +7 -39
- package/dist/components/FormerControllers/NumberInputCtrl.svelte +21 -43
- package/dist/components/FormerControllers/PasswordInputCtrl.svelte +8 -33
- package/dist/components/FormerControllers/SwitchCtrl.svelte +4 -20
- package/dist/components/FormerControllers/TextAreaCtrl.svelte +7 -34
- package/dist/components/FormerControllers/TextInputCtrl.svelte +7 -34
- package/dist/components/FormerControllers/ctrlLoading.svelte.d.ts +8 -0
- package/dist/components/FormerControllers/ctrlLoading.svelte.js +43 -0
- package/dist/components/FormerControllers/index.d.ts +2 -0
- package/dist/components/FormerControllers/index.js +2 -0
- package/dist/components/FormerControllers/utils.d.ts +1 -0
- package/dist/components/FormerControllers/utils.js +3 -0
- package/dist/components/GlobalStateStore/GlobalStateStoreProvider.svelte +73 -120
- package/dist/components/Gridler/components/Gridler.svelte +344 -442
- package/dist/components/Gridler/components/GridlerCanvas.svelte +720 -1115
- package/dist/components/Gridler/components/GridlerEditor.svelte +2 -15
- package/dist/components/Gridler/components/GridlerFull.svelte +521 -841
- package/dist/components/Gridler/components/GridlerFull.svelte.d.ts +1 -1
- package/dist/components/Gridler/components/GridlerFullWithFormerPreview.svelte +194 -147
- package/dist/components/Gridler/components/GridlerSearch.svelte +7 -16
- package/dist/components/Gridler/components/GridlerSearchToggle.svelte +7 -19
- package/dist/components/Gridler/types.d.ts +1 -1
- package/dist/components/Gridler/utils/serverPaging.d.ts +1 -0
- package/dist/components/Gridler/utils/serverPaging.js +7 -0
- package/dist/components/Icons/IconAdd.svelte +1 -3
- package/dist/components/Icons/IconAlertCircle.svelte +1 -3
- package/dist/components/Icons/IconAlertTriangle.svelte +1 -3
- package/dist/components/Icons/IconCamera.svelte +1 -3
- package/dist/components/Icons/IconClose.svelte +1 -3
- package/dist/components/Icons/IconEdit.svelte +1 -3
- package/dist/components/Icons/IconFilter.svelte +1 -3
- package/dist/components/Icons/IconSearch.svelte +1 -3
- package/dist/components/Icons/IconSort.svelte +1 -3
- package/dist/components/Icons/IconTrash.svelte +1 -3
- package/dist/components/Portal/Portal.svelte +14 -38
- package/dist/components/Screenshot/Screenshot.svelte +7 -13
- package/dist/components/Svark/Svark.svelte +680 -852
- package/dist/components/Svark/SvarkContextMenu.svelte +44 -63
- package/dist/components/Svark/SvarkInfiniteLoader.svelte +2 -6
- package/dist/components/Svark/SvarkPager.svelte +2 -28
- package/dist/components/Svark/SvarkSelectionDemo.svelte +4 -8
- package/dist/components/Svark/SvarkTopBar.svelte +9 -74
- package/dist/components/SvarkGrid/SvarkGrid.svelte +877 -1123
- package/dist/components/SvarkGrid/components/SvarkColumnFilterForm.svelte +45 -58
- package/dist/components/SvarkGrid/components/SvarkContextMenu.svelte +44 -63
- package/dist/components/SvarkGrid/components/SvarkHeaderFilterCell.svelte +41 -75
- package/dist/components/SvarkGrid/components/SvarkInfiniteLoader.svelte +2 -6
- package/dist/components/SvarkGrid/components/SvarkPager.svelte +2 -28
- package/dist/components/SvarkGrid/components/SvarkSearchPopover.svelte +8 -16
- package/dist/components/SvarkGrid/components/SvarkTopBar.svelte +6 -62
- package/dist/components/SvarkGrid/internal/SvarkGridView.svelte +345 -507
- package/dist/components/VTree/VTree.svelte +454 -431
- package/dist/components/VTree/VTree.utils.d.ts +23 -0
- package/dist/components/VTree/VTree.utils.js +73 -0
- package/dist/components/VTree/VTreeContextMenu.svelte +21 -33
- package/dist/components/VTree/VTreeControlledSelectionDemo.svelte +20 -0
- package/dist/components/VTree/VTreeControlledSelectionDemo.svelte.d.ts +18 -0
- package/dist/components/VTree/VTreeCustomizationDemo.svelte +23 -0
- package/dist/components/VTree/VTreeCustomizationDemo.svelte.d.ts +18 -0
- package/dist/components/VTree/VTreeEventsDemo.svelte +48 -58
- package/dist/components/VTree/VTreeInteractionDemo.svelte +29 -0
- package/dist/components/VTree/VTreeInteractionDemo.svelte.d.ts +18 -0
- package/dist/components/VTree/VTreeMultiSelectDemo.svelte +27 -0
- package/dist/components/VTree/VTreeMultiSelectDemo.svelte.d.ts +18 -0
- package/dist/components/VTree/VTreeRow.svelte +77 -115
- package/dist/components/VTree/VTreeRow.svelte.d.ts +34 -18
- package/dist/components/VTree/VTreeSearch.svelte +6 -13
- package/dist/components/VTree/VTreeVirtualViewport.svelte +54 -143
- package/dist/components/VTree/VTreeVirtualViewport.svelte.d.ts +35 -18
- package/dist/components/VTree/types.d.ts +39 -1
- package/llm/COMPONENT_GUIDE.md +25 -0
- package/package.json +51 -50
|
@@ -1,434 +1,441 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
1
|
+
<script lang="ts">import { onMount } from "svelte";
|
|
2
|
+
import VTreeSearch from "./VTreeSearch.svelte";
|
|
3
|
+
import VTreeVirtualViewport from "./VTreeVirtualViewport.svelte";
|
|
4
|
+
import VTreeContextMenu from "./VTreeContextMenu.svelte";
|
|
5
|
+
import { buildNodeIndex, computeMultiSelectClick, findAncestorIds } from "./VTree.utils.js";
|
|
6
|
+
const { data = [], adapter, idField = "id", labelField = "label", descriptionField = "description", childrenField = "children", hasChildrenField = "hasChildren", height = 420, rowHeight = 36, indent = 18, overscan = 8, searchable = true, searchPlaceholder = "Search tree...", searchValue = "", serverSideSearch = false, autoExpandSearchResults = true, loadOnMount = true, emptyMessage = "Nothing here...", loadingMessage = "Loading...", leftSection, rightSection, contextMenuItems, onselect, onclick, ondoubleclick, oncontext, ontoggle, onsearch, onloaderror, selected, onSelectedChange, multiple = false, selectedItems, onSelectedItemsChange, selectionMode = "modifier", autoMeasure = false, iconField, icon, classes, showRowSeparator = true, hoverEffect = true, onsingleclick, singleClickDelay = 250, onlongpress, longPressDelay = 500, longPressMoveTolerance = 10, onrowhover, onrowhoverend } = $props();
|
|
7
|
+
let viewportRef = $state(undefined);
|
|
8
|
+
let focusedIndex = $state(0);
|
|
9
|
+
let selectedId = $state(null);
|
|
10
|
+
let searchQuery = $state("");
|
|
11
|
+
let loadingRoot = $state(false);
|
|
12
|
+
let rootNodes = $state([]);
|
|
13
|
+
let searchNodes = $state([]);
|
|
14
|
+
let childrenByParent = $state({});
|
|
15
|
+
let expandedById = $state({});
|
|
16
|
+
let loadingById = $state({});
|
|
17
|
+
let loadedById = $state({});
|
|
18
|
+
let errorsById = $state({});
|
|
19
|
+
let lastSearchHandle;
|
|
20
|
+
let searchRunId = 0;
|
|
21
|
+
let contextOpen = $state(false);
|
|
22
|
+
let contextX = $state(0);
|
|
23
|
+
let contextY = $state(0);
|
|
24
|
+
let contextRow = $state(null);
|
|
25
|
+
let contextItems = $state([]);
|
|
26
|
+
// Long-press is handled per row and committed here when fired.
|
|
27
|
+
function handleRowLongpress(index, event) {
|
|
28
|
+
const row = flattenedRows[index];
|
|
29
|
+
if (!row) return;
|
|
30
|
+
selectRow(index);
|
|
31
|
+
commitSelection(index);
|
|
32
|
+
onlongpress?.(row.node, treeDataSnapshot, event);
|
|
33
|
+
}
|
|
34
|
+
// Selection model state.
|
|
35
|
+
let internalSelected = $state(null);
|
|
36
|
+
let internalSelectedItems = $state([]);
|
|
37
|
+
let rangeAnchorIndex = $state(null);
|
|
38
|
+
let lastRevealedId = $state(null);
|
|
39
|
+
let lastScrolledId = $state(null);
|
|
40
|
+
let singleClickTimer;
|
|
41
|
+
let clickCount = 0;
|
|
42
|
+
function commitSelection(index, event, forceToggle = false) {
|
|
43
|
+
const row = flattenedRows[index];
|
|
44
|
+
if (!row) return;
|
|
45
|
+
if (multiple) {
|
|
46
|
+
applyMultiSelect(row.node, index, event, forceToggle);
|
|
47
|
+
} else {
|
|
48
|
+
onSelectedChange?.(row.node);
|
|
49
|
+
if (selected === undefined) internalSelected = row.node;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function applyMultiSelect(node, index, event, forceToggle = false) {
|
|
53
|
+
const currentItems = selectedItems ?? internalSelectedItems;
|
|
54
|
+
const orderedRowIds = flattenedRows.map((row) => row.id);
|
|
55
|
+
const clickedId = getNodeId(node);
|
|
56
|
+
const result = computeMultiSelectClick({
|
|
57
|
+
currentIds: currentItems.map((item) => getNodeId(item)),
|
|
58
|
+
clickedId,
|
|
59
|
+
clickedIndex: index,
|
|
60
|
+
anchorIndex: rangeAnchorIndex,
|
|
61
|
+
orderedRowIds,
|
|
62
|
+
ctrlOrMeta: forceToggle || Boolean(event?.ctrlKey || event?.metaKey),
|
|
63
|
+
shift: Boolean(event?.shiftKey)
|
|
64
|
+
});
|
|
65
|
+
rangeAnchorIndex = result.nextAnchorIndex;
|
|
66
|
+
const items = result.ids.map((id) => nodeIndex.byId.get(id)).filter((item) => Boolean(item));
|
|
67
|
+
if (selectedItems === undefined) internalSelectedItems = items;
|
|
68
|
+
onSelectedItemsChange?.(items);
|
|
69
|
+
}
|
|
70
|
+
function getNodeId(node) {
|
|
71
|
+
const value = node?.[idField];
|
|
72
|
+
return String(value ?? "");
|
|
73
|
+
}
|
|
74
|
+
function getNodeLabel(node) {
|
|
75
|
+
return String(node?.[labelField] ?? "");
|
|
76
|
+
}
|
|
77
|
+
function getNodeDescription(node) {
|
|
78
|
+
const value = node?.[descriptionField];
|
|
79
|
+
return value === undefined || value === null ? "" : String(value);
|
|
80
|
+
}
|
|
81
|
+
function getNodeChildren(node) {
|
|
82
|
+
const nodeId = getNodeId(node);
|
|
83
|
+
const remoteChildren = childrenByParent[nodeId];
|
|
84
|
+
if (remoteChildren) return remoteChildren;
|
|
85
|
+
const localChildren = node?.[childrenField];
|
|
86
|
+
return Array.isArray(localChildren) ? localChildren : [];
|
|
87
|
+
}
|
|
88
|
+
function nodeHasChildren(node) {
|
|
89
|
+
const children = getNodeChildren(node);
|
|
90
|
+
if (children.length > 0) return true;
|
|
91
|
+
return typeof node?.[hasChildrenField] === "boolean" ? Boolean(node[hasChildrenField]) : false;
|
|
92
|
+
}
|
|
93
|
+
function normalizeRows(rows) {
|
|
94
|
+
return Array.isArray(rows) ? rows : [];
|
|
95
|
+
}
|
|
96
|
+
async function loadRoot() {
|
|
97
|
+
if (!adapter) {
|
|
98
|
+
rootNodes = normalizeRows(data ?? []);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
loadingRoot = true;
|
|
102
|
+
try {
|
|
103
|
+
const rows = await adapter.readRoot();
|
|
104
|
+
rootNodes = normalizeRows(rows);
|
|
105
|
+
searchNodes = [];
|
|
106
|
+
errorsById = {};
|
|
107
|
+
} catch (error) {
|
|
108
|
+
onloaderror?.(error);
|
|
109
|
+
} finally {
|
|
110
|
+
loadingRoot = false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async function loadChildren(node) {
|
|
114
|
+
if (!adapter) return;
|
|
115
|
+
const nodeId = getNodeId(node);
|
|
116
|
+
if (!nodeId || loadingById[nodeId] || loadedById[nodeId]) return;
|
|
117
|
+
loadingById = {
|
|
118
|
+
...loadingById,
|
|
119
|
+
[nodeId]: true
|
|
120
|
+
};
|
|
121
|
+
errorsById = {
|
|
122
|
+
...errorsById,
|
|
123
|
+
[nodeId]: ""
|
|
124
|
+
};
|
|
125
|
+
try {
|
|
126
|
+
const rows = await adapter.readChildren(node);
|
|
127
|
+
childrenByParent = {
|
|
128
|
+
...childrenByParent,
|
|
129
|
+
[nodeId]: normalizeRows(rows)
|
|
130
|
+
};
|
|
131
|
+
loadedById = {
|
|
132
|
+
...loadedById,
|
|
133
|
+
[nodeId]: true
|
|
134
|
+
};
|
|
135
|
+
} catch (error) {
|
|
136
|
+
const message = error instanceof Error ? error.message : "Unable to load node";
|
|
137
|
+
errorsById = {
|
|
138
|
+
...errorsById,
|
|
139
|
+
[nodeId]: message
|
|
140
|
+
};
|
|
141
|
+
onloaderror?.(error, node);
|
|
142
|
+
} finally {
|
|
143
|
+
loadingById = {
|
|
144
|
+
...loadingById,
|
|
145
|
+
[nodeId]: false
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function matchesLocalSearch(node, query) {
|
|
150
|
+
const q = query.toLowerCase();
|
|
151
|
+
return getNodeLabel(node).toLowerCase().includes(q) || getNodeDescription(node).toLowerCase().includes(q);
|
|
152
|
+
}
|
|
153
|
+
function toggleNode(node) {
|
|
154
|
+
const nodeId = getNodeId(node);
|
|
155
|
+
if (!nodeId) return;
|
|
156
|
+
const currentlyExpanded = Boolean(expandedById[nodeId]);
|
|
157
|
+
expandedById = {
|
|
158
|
+
...expandedById,
|
|
159
|
+
[nodeId]: !currentlyExpanded
|
|
160
|
+
};
|
|
161
|
+
ontoggle?.(node, !currentlyExpanded);
|
|
162
|
+
if (!currentlyExpanded && adapter && nodeHasChildren(node)) {
|
|
163
|
+
void loadChildren(node);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const displayRoots = $derived.by(() => {
|
|
167
|
+
if (adapter && serverSideSearch && searchQuery.trim().length > 0) return searchNodes;
|
|
168
|
+
return rootNodes;
|
|
169
|
+
});
|
|
170
|
+
const nodeIndex = $derived.by(() => buildNodeIndex(displayRoots, getNodeId, getNodeChildren));
|
|
171
|
+
const flattenedRows = $derived.by(() => {
|
|
172
|
+
const rows = [];
|
|
173
|
+
const activeSearch = searchQuery.trim().toLowerCase();
|
|
174
|
+
const useLocalSearch = activeSearch.length > 0 && !(adapter && serverSideSearch);
|
|
175
|
+
const walk = (nodes, level, parentId) => {
|
|
176
|
+
const walkRows = [];
|
|
177
|
+
let hasAnyMatch = false;
|
|
178
|
+
for (const node of nodes) {
|
|
179
|
+
const id = getNodeId(node);
|
|
180
|
+
const children = getNodeChildren(node);
|
|
181
|
+
const childResult = walk(children, level + 1, id);
|
|
182
|
+
const selfMatch = useLocalSearch ? matchesLocalSearch(node, activeSearch) : false;
|
|
183
|
+
const childHasMatch = childResult.matches;
|
|
184
|
+
const includeNode = !useLocalSearch || selfMatch || childHasMatch;
|
|
185
|
+
if (!includeNode) continue;
|
|
186
|
+
hasAnyMatch = true;
|
|
187
|
+
const expanded = Boolean(expandedById[id]);
|
|
188
|
+
const forceExpanded = useLocalSearch && autoExpandSearchResults && childHasMatch;
|
|
189
|
+
walkRows.push({
|
|
190
|
+
id,
|
|
191
|
+
node,
|
|
192
|
+
level,
|
|
193
|
+
parentId,
|
|
194
|
+
expanded,
|
|
195
|
+
hasChildren: nodeHasChildren(node),
|
|
196
|
+
loading: Boolean(loadingById[id]),
|
|
197
|
+
error: errorsById[id] || undefined,
|
|
198
|
+
matched: selfMatch
|
|
199
|
+
});
|
|
200
|
+
if ((expanded || forceExpanded) && childResult.rows.length > 0) {
|
|
201
|
+
walkRows.push(...childResult.rows);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
rows: walkRows,
|
|
206
|
+
matches: hasAnyMatch
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
for (const root of displayRoots) {
|
|
210
|
+
rows.push(...walk([root], 1, null).rows);
|
|
211
|
+
}
|
|
212
|
+
return rows;
|
|
213
|
+
});
|
|
214
|
+
const treeDataSnapshot = $derived.by(() => {
|
|
215
|
+
const buildTree = (nodes) => nodes.map((node) => {
|
|
216
|
+
const children = getNodeChildren(node);
|
|
217
|
+
if (children.length === 0) {
|
|
218
|
+
return node;
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
...node,
|
|
222
|
+
[childrenField]: buildTree(children)
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
return buildTree(displayRoots);
|
|
226
|
+
});
|
|
227
|
+
const selectedNodeId = $derived(selected ? getNodeId(selected) : selected === null ? "" : internalSelected ? getNodeId(internalSelected) : "");
|
|
228
|
+
$effect(() => {
|
|
229
|
+
if (!selectedNodeId || lastRevealedId === selectedNodeId) return;
|
|
230
|
+
const ancestors = findAncestorIds(nodeIndex.parentById, selectedNodeId);
|
|
231
|
+
const next = { ...expandedById };
|
|
232
|
+
let changed = false;
|
|
233
|
+
for (const id of ancestors) {
|
|
234
|
+
if (!next[id]) {
|
|
235
|
+
next[id] = true;
|
|
236
|
+
changed = true;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (changed) expandedById = next;
|
|
240
|
+
lastRevealedId = selectedNodeId;
|
|
241
|
+
lastScrolledId = null;
|
|
242
|
+
});
|
|
243
|
+
$effect(() => {
|
|
244
|
+
if (!selectedNodeId || lastScrolledId === selectedNodeId) return;
|
|
245
|
+
const index = flattenedRows.findIndex((row) => row.id === selectedNodeId);
|
|
246
|
+
if (index < 0) return;
|
|
247
|
+
focusedIndex = index;
|
|
248
|
+
selectedId = selectedNodeId;
|
|
249
|
+
viewportRef?.scrollToIndex(index);
|
|
250
|
+
lastScrolledId = selectedNodeId;
|
|
251
|
+
});
|
|
252
|
+
function selectRow(index) {
|
|
253
|
+
const row = flattenedRows[index];
|
|
254
|
+
if (!row) return;
|
|
255
|
+
focusedIndex = index;
|
|
256
|
+
// Keep existing uncontrolled fallback behavior.
|
|
257
|
+
selectedId = row.id;
|
|
258
|
+
onselect?.(row.node);
|
|
259
|
+
viewportRef?.scrollToIndex(index);
|
|
260
|
+
}
|
|
261
|
+
function moveFocus(delta) {
|
|
262
|
+
if (flattenedRows.length === 0) return;
|
|
263
|
+
const next = Math.min(flattenedRows.length - 1, Math.max(0, focusedIndex + delta));
|
|
264
|
+
selectRow(next);
|
|
265
|
+
}
|
|
266
|
+
function handleTreeKeydown(event) {
|
|
267
|
+
if (flattenedRows.length === 0) return;
|
|
268
|
+
const current = flattenedRows[focusedIndex];
|
|
269
|
+
if (!current) {
|
|
270
|
+
selectRow(0);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (event.key === "ArrowDown") {
|
|
274
|
+
event.preventDefault();
|
|
275
|
+
moveFocus(1);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (event.key === "ArrowUp") {
|
|
279
|
+
event.preventDefault();
|
|
280
|
+
moveFocus(-1);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (event.key === "PageDown") {
|
|
284
|
+
event.preventDefault();
|
|
285
|
+
moveFocus(10);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (event.key === "PageUp") {
|
|
289
|
+
event.preventDefault();
|
|
290
|
+
moveFocus(-10);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (event.key === "Home") {
|
|
294
|
+
event.preventDefault();
|
|
295
|
+
selectRow(0);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (event.key === "End") {
|
|
299
|
+
event.preventDefault();
|
|
300
|
+
selectRow(flattenedRows.length - 1);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
if (event.key === "ArrowRight") {
|
|
304
|
+
event.preventDefault();
|
|
305
|
+
if (current.hasChildren && !current.expanded) {
|
|
306
|
+
toggleNode(current.node);
|
|
307
|
+
} else {
|
|
308
|
+
moveFocus(1);
|
|
309
|
+
}
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (event.key === "ArrowLeft") {
|
|
313
|
+
event.preventDefault();
|
|
314
|
+
if (current.expanded) {
|
|
315
|
+
toggleNode(current.node);
|
|
316
|
+
} else if (current.parentId) {
|
|
317
|
+
const parentIndex = flattenedRows.findIndex((row) => row.id === current.parentId);
|
|
318
|
+
if (parentIndex >= 0) selectRow(parentIndex);
|
|
319
|
+
}
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (event.key === "Enter") {
|
|
323
|
+
event.preventDefault();
|
|
324
|
+
selectRow(focusedIndex);
|
|
325
|
+
// Single-click selection via Enter.
|
|
326
|
+
commitSelection(focusedIndex);
|
|
327
|
+
if (current.hasChildren) {
|
|
328
|
+
toggleNode(current.node);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
// Single-click selection via Space.
|
|
332
|
+
if (event.key === " ") {
|
|
333
|
+
event.preventDefault();
|
|
334
|
+
commitSelection(focusedIndex);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
async function runServerSearch(query) {
|
|
338
|
+
if (!adapter || !serverSideSearch) return;
|
|
339
|
+
const runId = ++searchRunId;
|
|
340
|
+
if (!query.trim()) {
|
|
341
|
+
searchNodes = [];
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
try {
|
|
345
|
+
const rows = await adapter.search(query.trim());
|
|
346
|
+
if (runId !== searchRunId) return;
|
|
347
|
+
searchNodes = normalizeRows(rows);
|
|
348
|
+
focusedIndex = 0;
|
|
349
|
+
} catch (error) {
|
|
350
|
+
if (runId !== searchRunId) return;
|
|
351
|
+
onloaderror?.(error);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
function handleSearchInput(value) {
|
|
355
|
+
searchQuery = value;
|
|
356
|
+
onsearch?.(value);
|
|
357
|
+
}
|
|
358
|
+
function handleRowClick(index, event) {
|
|
359
|
+
const row = flattenedRows[index];
|
|
360
|
+
if (!row) return;
|
|
361
|
+
selectRow(index);
|
|
362
|
+
onclick?.(row.node, treeDataSnapshot, event);
|
|
363
|
+
// Checkbox mode intentionally leaves row-body clicks out of multi-selection.
|
|
364
|
+
if (!multiple || selectionMode === "modifier") commitSelection(index, event);
|
|
365
|
+
clearTimeout(singleClickTimer);
|
|
366
|
+
clickCount += 1;
|
|
367
|
+
singleClickTimer = setTimeout(() => {
|
|
368
|
+
if (clickCount === 1) onsingleclick?.(row.node, treeDataSnapshot, event);
|
|
369
|
+
clickCount = 0;
|
|
370
|
+
}, singleClickDelay);
|
|
371
|
+
}
|
|
372
|
+
function handleRowDoubleClick(index, event) {
|
|
373
|
+
const row = flattenedRows[index];
|
|
374
|
+
if (!row) return;
|
|
375
|
+
clearTimeout(singleClickTimer);
|
|
376
|
+
clickCount = 0;
|
|
377
|
+
selectRow(index);
|
|
378
|
+
ondoubleclick?.(row.node, treeDataSnapshot, event);
|
|
379
|
+
}
|
|
380
|
+
function handleRowContext(index, event) {
|
|
381
|
+
const row = flattenedRows[index];
|
|
382
|
+
if (!row) return;
|
|
383
|
+
event.preventDefault();
|
|
384
|
+
selectRow(index);
|
|
385
|
+
oncontext?.(row.node, treeDataSnapshot, event);
|
|
386
|
+
if (!contextMenuItems) return;
|
|
387
|
+
const items = typeof contextMenuItems === "function" ? contextMenuItems(row.node, treeDataSnapshot) : contextMenuItems;
|
|
388
|
+
contextItems = items ?? [];
|
|
389
|
+
contextRow = row.node;
|
|
390
|
+
contextX = event.clientX;
|
|
391
|
+
contextY = event.clientY;
|
|
392
|
+
contextOpen = contextItems.length > 0;
|
|
393
|
+
}
|
|
394
|
+
function handleViewportContext(event) {
|
|
395
|
+
event.preventDefault();
|
|
396
|
+
oncontext?.(null, treeDataSnapshot, event);
|
|
397
|
+
if (!contextMenuItems) return;
|
|
398
|
+
const items = typeof contextMenuItems === "function" ? contextMenuItems(null, treeDataSnapshot) : contextMenuItems;
|
|
399
|
+
contextItems = items ?? [];
|
|
400
|
+
contextRow = null;
|
|
401
|
+
contextX = event.clientX;
|
|
402
|
+
contextY = event.clientY;
|
|
403
|
+
contextOpen = contextItems.length > 0;
|
|
404
|
+
}
|
|
405
|
+
function handleContextMenuItem(item) {
|
|
406
|
+
if (item.id !== "__close__" && contextRow) {
|
|
407
|
+
item.onselect?.(contextRow, treeDataSnapshot);
|
|
408
|
+
}
|
|
409
|
+
contextOpen = false;
|
|
410
|
+
}
|
|
411
|
+
$effect(() => {
|
|
412
|
+
if (!adapter) rootNodes = normalizeRows(data ?? []);
|
|
413
|
+
});
|
|
414
|
+
$effect(() => {
|
|
415
|
+
if (!adapter || !serverSideSearch) return;
|
|
416
|
+
clearTimeout(lastSearchHandle);
|
|
417
|
+
lastSearchHandle = setTimeout(() => {
|
|
418
|
+
void runServerSearch(searchQuery);
|
|
419
|
+
}, 250);
|
|
420
|
+
return () => clearTimeout(lastSearchHandle);
|
|
421
|
+
});
|
|
422
|
+
$effect(() => {
|
|
423
|
+
if (focusedIndex > flattenedRows.length - 1) {
|
|
424
|
+
focusedIndex = Math.max(flattenedRows.length - 1, 0);
|
|
425
|
+
}
|
|
426
|
+
if (!selectedId && flattenedRows.length > 0) {
|
|
427
|
+
selectedId = flattenedRows[0].id;
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
onMount(() => {
|
|
431
|
+
searchQuery = searchValue ?? "";
|
|
432
|
+
if (adapter && loadOnMount) {
|
|
433
|
+
void loadRoot();
|
|
434
|
+
} else {
|
|
435
|
+
rootNodes = normalizeRows(data ?? []);
|
|
436
|
+
}
|
|
437
|
+
return () => clearTimeout(lastSearchHandle);
|
|
438
|
+
});
|
|
432
439
|
</script>
|
|
433
440
|
|
|
434
441
|
<div class="card space-y-2 border border-surface-300-700 bg-surface-100-900 p-2">
|
|
@@ -440,6 +447,7 @@
|
|
|
440
447
|
bind:this={viewportRef}
|
|
441
448
|
rows={flattenedRows}
|
|
442
449
|
{rowHeight}
|
|
450
|
+
{autoMeasure}
|
|
443
451
|
{height}
|
|
444
452
|
{indent}
|
|
445
453
|
{overscan}
|
|
@@ -453,12 +461,27 @@
|
|
|
453
461
|
{treeDataSnapshot}
|
|
454
462
|
{leftSection}
|
|
455
463
|
{rightSection}
|
|
464
|
+
{iconField}
|
|
465
|
+
{icon}
|
|
466
|
+
{classes}
|
|
467
|
+
{showRowSeparator}
|
|
468
|
+
{hoverEffect}
|
|
469
|
+
{multiple}
|
|
470
|
+
{selectionMode}
|
|
471
|
+
selectedItemIds={(selectedItems ?? internalSelectedItems).map((item) => getNodeId(item))}
|
|
472
|
+
selectedNodeId={selectedNodeId}
|
|
456
473
|
onselectrow={handleRowClick}
|
|
457
474
|
onrowdoubleclick={handleRowDoubleClick}
|
|
458
475
|
onrowcontext={handleRowContext}
|
|
459
476
|
onviewportcontext={handleViewportContext}
|
|
460
477
|
ontogglerow={toggleNode}
|
|
461
478
|
ontreekeydown={handleTreeKeydown}
|
|
479
|
+
onrowlongpress={handleRowLongpress}
|
|
480
|
+
oncheckboxselect={(index, event) => commitSelection(index, event, true)}
|
|
481
|
+
onrowhover={(index, event) => { const row = flattenedRows[index]; if (row) onrowhover?.(row.node, treeDataSnapshot, index, event); }}
|
|
482
|
+
onrowhoverend={(index, event) => { const row = flattenedRows[index]; if (row) onrowhoverend?.(row.node, treeDataSnapshot, index, event); }}
|
|
483
|
+
{longPressDelay}
|
|
484
|
+
{longPressMoveTolerance}
|
|
462
485
|
/>
|
|
463
486
|
|
|
464
487
|
<VTreeContextMenu
|