@zhangt58/svelte-vtable 0.1.1 → 0.1.2
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 +86 -71
- package/package.json +7 -3
- package/src/components/DataTable.svelte +67 -16
- package/src/components/DataTableControls.svelte +136 -54
- package/src/components/DataTableFilters.svelte +182 -82
- package/src/components/FiltersModal.svelte +21 -17
- package/src/lib/dist/styles.css +12 -9
- package/src/lib/filterUtils.js +14 -13
- package/src/lib/index.js +1 -1
- package/src/lib/styles.css +13 -10
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
populateThreshold = 200,
|
|
35
35
|
// If true, render dropdowns inline (in-flow) so opening them expands the parent container.
|
|
36
36
|
// If false, render as absolutely-positioned overlays (old behavior).
|
|
37
|
-
dropdownInline = true
|
|
37
|
+
dropdownInline = true,
|
|
38
38
|
} = $props();
|
|
39
39
|
|
|
40
40
|
// Internal state for selected options per column
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
const initial = {};
|
|
49
49
|
for (const col of columnFilters) {
|
|
50
50
|
const len = Array.isArray(col.uniqueValues) ? col.uniqueValues.length : 0;
|
|
51
|
-
initial[col.key] =
|
|
51
|
+
initial[col.key] = populateThreshold <= 0 || len <= populateThreshold;
|
|
52
52
|
}
|
|
53
53
|
loadedOptions = initial;
|
|
54
54
|
});
|
|
@@ -81,9 +81,11 @@
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
try {
|
|
84
|
-
|
|
84
|
+
/** @type {any} */ (filterChange)(payload);
|
|
85
85
|
} catch (err) {
|
|
86
|
-
try {
|
|
86
|
+
try {
|
|
87
|
+
console.error('filterChange threw:', err);
|
|
88
|
+
} catch (e) {}
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
|
|
@@ -110,7 +112,7 @@
|
|
|
110
112
|
|
|
111
113
|
if (current.includes(value)) {
|
|
112
114
|
// Remove the value
|
|
113
|
-
updated = current.filter(v => v !== value);
|
|
115
|
+
updated = current.filter((v) => v !== value);
|
|
114
116
|
} else {
|
|
115
117
|
// Add the value
|
|
116
118
|
updated = [...current, value];
|
|
@@ -142,7 +144,7 @@
|
|
|
142
144
|
|
|
143
145
|
// Check if any filters are active
|
|
144
146
|
const hasActiveFilters = $derived(() => {
|
|
145
|
-
return Object.values(selections).some(arr => arr && arr.length > 0);
|
|
147
|
+
return Object.values(selections).some((arr) => arr && arr.length > 0);
|
|
146
148
|
});
|
|
147
149
|
|
|
148
150
|
// Count active filters
|
|
@@ -187,7 +189,7 @@
|
|
|
187
189
|
function updateState() {
|
|
188
190
|
virtualScroll = {
|
|
189
191
|
...virtualScroll,
|
|
190
|
-
[key]: { scrollTop: node.scrollTop, height: node.clientHeight }
|
|
192
|
+
[key]: { scrollTop: node.scrollTop, height: node.clientHeight },
|
|
191
193
|
};
|
|
192
194
|
}
|
|
193
195
|
|
|
@@ -219,7 +221,7 @@
|
|
|
219
221
|
const copy = { ...virtualScroll };
|
|
220
222
|
delete copy[key];
|
|
221
223
|
virtualScroll = copy;
|
|
222
|
-
}
|
|
224
|
+
},
|
|
223
225
|
};
|
|
224
226
|
}
|
|
225
227
|
|
|
@@ -250,7 +252,7 @@
|
|
|
250
252
|
const q = (searchQueries[column.key] || '').toString().trim().toLowerCase();
|
|
251
253
|
let filtered = raw;
|
|
252
254
|
if (q) {
|
|
253
|
-
filtered = raw.filter(v => {
|
|
255
|
+
filtered = raw.filter((v) => {
|
|
254
256
|
const text = v === null || v === undefined ? '(empty)' : String(v);
|
|
255
257
|
return text.toLowerCase().includes(q);
|
|
256
258
|
});
|
|
@@ -285,7 +287,7 @@
|
|
|
285
287
|
return a.i - b.i;
|
|
286
288
|
});
|
|
287
289
|
|
|
288
|
-
return withIndex.map(x => x.v);
|
|
290
|
+
return withIndex.map((x) => x.v);
|
|
289
291
|
}
|
|
290
292
|
|
|
291
293
|
// Toggle sort mode for a column. If the same mode is clicked again,
|
|
@@ -308,12 +310,16 @@
|
|
|
308
310
|
const newDir = sortDirs[columnKey] || 'asc';
|
|
309
311
|
try {
|
|
310
312
|
// notify parent if it wants to react to sort changes
|
|
311
|
-
|
|
313
|
+
/** @type {any} */ (sortChange)({ columnKey, mode, dir: newDir });
|
|
312
314
|
} catch (err) {
|
|
313
|
-
try {
|
|
315
|
+
try {
|
|
316
|
+
console.debug('sortChange callback threw', err);
|
|
317
|
+
} catch (e) {}
|
|
314
318
|
}
|
|
315
319
|
// debug log
|
|
316
|
-
try {
|
|
320
|
+
try {
|
|
321
|
+
console.debug('toggleSortMode', columnKey, mode, sortDirs[columnKey]);
|
|
322
|
+
} catch (e) {}
|
|
317
323
|
}
|
|
318
324
|
|
|
319
325
|
// Clear selection for a column (from within dropdown)
|
|
@@ -332,7 +338,7 @@
|
|
|
332
338
|
function invertSelection(columnKey, values) {
|
|
333
339
|
const current = new Set(selections[columnKey] || []);
|
|
334
340
|
const next = [];
|
|
335
|
-
for (const v of
|
|
341
|
+
for (const v of Array.isArray(values) ? values : []) {
|
|
336
342
|
if (!current.has(v)) next.push(v);
|
|
337
343
|
}
|
|
338
344
|
selections = { ...selections, [columnKey]: next };
|
|
@@ -360,17 +366,20 @@
|
|
|
360
366
|
|
|
361
367
|
// Check if all dropdowns are open
|
|
362
368
|
const allDropdownsOpen = $derived.by(() => {
|
|
363
|
-
return columnFilters.every(col => openDropdowns[col.key]);
|
|
369
|
+
return columnFilters.every((col) => openDropdowns[col.key]);
|
|
364
370
|
});
|
|
365
371
|
|
|
366
372
|
// Check if all dropdowns are closed
|
|
367
373
|
const allDropdownsClosed = $derived.by(() => {
|
|
368
|
-
return columnFilters.every(col => !openDropdowns[col.key]);
|
|
374
|
+
return columnFilters.every((col) => !openDropdowns[col.key]);
|
|
369
375
|
});
|
|
370
376
|
</script>
|
|
371
377
|
|
|
372
|
-
<div
|
|
373
|
-
|
|
378
|
+
<div
|
|
379
|
+
class="p-2 bg-gray-50 rounded-md border border-gray-200 dark:bg-gray-800 dark:border-gray-700 {className}"
|
|
380
|
+
class:horizontal={direction === 'horizontal'}
|
|
381
|
+
class:vertical={direction === 'vertical'}
|
|
382
|
+
>
|
|
374
383
|
<div class="flex justify-between items-center mb-2 flex-wrap gap-1">
|
|
375
384
|
<!-- Left controls: Show All, Close All -->
|
|
376
385
|
<div class="flex items-center gap-1 flex-wrap">
|
|
@@ -407,7 +416,11 @@
|
|
|
407
416
|
</div>
|
|
408
417
|
</div>
|
|
409
418
|
|
|
410
|
-
<div
|
|
419
|
+
<div
|
|
420
|
+
class="grid gap-2"
|
|
421
|
+
class:grid-horizontal={direction === 'horizontal'}
|
|
422
|
+
class:grid-vertical={direction === 'vertical'}
|
|
423
|
+
>
|
|
411
424
|
{#each columnFilters as column (column.key)}
|
|
412
425
|
{@const isActive = selections[column.key]?.length > 0}
|
|
413
426
|
{@const isOpen = openDropdowns[column.key]}
|
|
@@ -418,26 +431,28 @@
|
|
|
418
431
|
<div class="flex flex-col min-w-0 relative">
|
|
419
432
|
<button
|
|
420
433
|
id="filter-{column.key}"
|
|
421
|
-
class="w-full flex justify-between items-center px-3 py-2 text-sm text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md hover:border-gray-400 dark:hover:border-gray-500 focus:outline-none focus:border-blue-500 dark:focus:border-blue-400 focus:ring-2 focus:ring-blue-100 dark:focus:ring-blue-900 transition-all cursor-pointer gap-2 {isActive
|
|
434
|
+
class="w-full flex justify-between items-center px-3 py-2 text-sm text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md hover:border-gray-400 dark:hover:border-gray-500 focus:outline-none focus:border-blue-500 dark:focus:border-blue-400 focus:ring-2 focus:ring-blue-100 dark:focus:ring-blue-900 transition-all cursor-pointer gap-2 {isActive
|
|
435
|
+
? 'border-green-500 dark:border-green-400 bg-green-50 dark:bg-green-900/20'
|
|
436
|
+
: ''}"
|
|
422
437
|
onclick={() => toggleDropdown(column.key)}
|
|
423
438
|
type="button"
|
|
424
439
|
>
|
|
425
440
|
<span class="flex-1 text-left whitespace-nowrap overflow-hidden text-ellipsis min-w-0">
|
|
426
|
-
|
|
441
|
+
{column.label || column.key}
|
|
427
442
|
</span>
|
|
428
443
|
{#if isActive}
|
|
429
444
|
<Badge color="green" rounded class="ml-1">{selections[column.key].length}</Badge>
|
|
430
445
|
{/if}
|
|
431
|
-
<ChevronDownOutline
|
|
446
|
+
<ChevronDownOutline
|
|
447
|
+
class="w-5 h-5 shrink-0 transition-transform {isOpen ? 'rotate-180' : ''}"
|
|
448
|
+
/>
|
|
432
449
|
</button>
|
|
433
450
|
|
|
434
451
|
{#if isOpen}
|
|
435
452
|
<div
|
|
436
|
-
class={
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
: `absolute top-full mt-1 left-0 right-0 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md shadow-lg dark:shadow-gray-900 max-h-64 flex flex-col dropdown-menu`)
|
|
440
|
-
}
|
|
453
|
+
class={dropdownInline
|
|
454
|
+
? `mt-1 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md shadow-lg dark:shadow-gray-900 max-h-64 flex flex-col dropdown-menu`
|
|
455
|
+
: `absolute top-full mt-1 left-0 right-0 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md shadow-lg dark:shadow-gray-900 max-h-64 flex flex-col dropdown-menu`}
|
|
441
456
|
tabindex="-1"
|
|
442
457
|
data-column={column.key}
|
|
443
458
|
>
|
|
@@ -461,8 +476,13 @@
|
|
|
461
476
|
>
|
|
462
477
|
<span class="text-sm font-semibold">Aa</span>
|
|
463
478
|
<ArrowDownOutline
|
|
464
|
-
class={
|
|
465
|
-
|
|
479
|
+
class={'w-3 h-3 transition-transform ' +
|
|
480
|
+
(currentSortMode === 'name'
|
|
481
|
+
? 'text-blue-900 dark:text-blue-100'
|
|
482
|
+
: 'text-gray-400 dark:text-gray-500')}
|
|
483
|
+
style={currentSortMode === 'name' && currentSortDir === 'asc'
|
|
484
|
+
? 'transform: rotate(180deg);'
|
|
485
|
+
: ''}
|
|
466
486
|
aria-hidden="true"
|
|
467
487
|
/>
|
|
468
488
|
</button>
|
|
@@ -478,16 +498,18 @@
|
|
|
478
498
|
>
|
|
479
499
|
<span class="text-sm font-semibold">#</span>
|
|
480
500
|
<ArrowDownOutline
|
|
481
|
-
class={
|
|
482
|
-
|
|
501
|
+
class={'w-3 h-3 transition-transform ' +
|
|
502
|
+
(currentSortMode === 'count'
|
|
503
|
+
? 'text-blue-900 dark:text-blue-100'
|
|
504
|
+
: 'text-gray-400 dark:text-gray-500')}
|
|
505
|
+
style={currentSortMode === 'count' && currentSortDir === 'asc'
|
|
506
|
+
? 'transform: rotate(180deg);'
|
|
507
|
+
: ''}
|
|
483
508
|
aria-hidden="true"
|
|
484
509
|
/>
|
|
485
510
|
</button>
|
|
486
511
|
{/if}
|
|
487
|
-
|
|
488
|
-
|
|
489
512
|
</div>
|
|
490
|
-
|
|
491
513
|
</div>
|
|
492
514
|
</div>
|
|
493
515
|
|
|
@@ -504,9 +526,30 @@
|
|
|
504
526
|
title="Check all"
|
|
505
527
|
>
|
|
506
528
|
<!-- Checked square icon (higher contrast) -->
|
|
507
|
-
<svg
|
|
508
|
-
|
|
509
|
-
|
|
529
|
+
<svg
|
|
530
|
+
class="w-4 h-4 text-gray-800 dark:text-white"
|
|
531
|
+
viewBox="0 0 24 24"
|
|
532
|
+
fill="none"
|
|
533
|
+
aria-hidden="true"
|
|
534
|
+
>
|
|
535
|
+
<rect
|
|
536
|
+
x="3"
|
|
537
|
+
y="3"
|
|
538
|
+
width="18"
|
|
539
|
+
height="18"
|
|
540
|
+
rx="2"
|
|
541
|
+
stroke="currentColor"
|
|
542
|
+
stroke-width="2.5"
|
|
543
|
+
fill="none"
|
|
544
|
+
/>
|
|
545
|
+
<path
|
|
546
|
+
d="M7 13l3 3 7-7"
|
|
547
|
+
stroke="currentColor"
|
|
548
|
+
stroke-width="2"
|
|
549
|
+
stroke-linecap="round"
|
|
550
|
+
stroke-linejoin="round"
|
|
551
|
+
fill="none"
|
|
552
|
+
/>
|
|
510
553
|
</svg>
|
|
511
554
|
<span class="text-sm text-gray-800 dark:text-gray-100 select-none">All</span>
|
|
512
555
|
</button>
|
|
@@ -520,10 +563,39 @@
|
|
|
520
563
|
title="Invert selection"
|
|
521
564
|
>
|
|
522
565
|
<!-- Half-checked square icon (left half filled) - higher contrast -->
|
|
523
|
-
<svg
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
566
|
+
<svg
|
|
567
|
+
class="w-4 h-4 text-gray-800 dark:text-white"
|
|
568
|
+
viewBox="0 0 24 24"
|
|
569
|
+
fill="none"
|
|
570
|
+
aria-hidden="true"
|
|
571
|
+
>
|
|
572
|
+
<rect
|
|
573
|
+
x="3"
|
|
574
|
+
y="3"
|
|
575
|
+
width="18"
|
|
576
|
+
height="18"
|
|
577
|
+
rx="2"
|
|
578
|
+
stroke="currentColor"
|
|
579
|
+
stroke-width="2.5"
|
|
580
|
+
fill="none"
|
|
581
|
+
/>
|
|
582
|
+
<rect
|
|
583
|
+
x="4"
|
|
584
|
+
y="4"
|
|
585
|
+
width="8.5"
|
|
586
|
+
height="16"
|
|
587
|
+
fill="currentColor"
|
|
588
|
+
opacity="0.28"
|
|
589
|
+
stroke="none"
|
|
590
|
+
/>
|
|
591
|
+
<path
|
|
592
|
+
d="M7 13l3 3 7-7"
|
|
593
|
+
stroke="currentColor"
|
|
594
|
+
stroke-width="2"
|
|
595
|
+
stroke-linecap="round"
|
|
596
|
+
stroke-linejoin="round"
|
|
597
|
+
fill="none"
|
|
598
|
+
/>
|
|
527
599
|
</svg>
|
|
528
600
|
<span class="text-sm text-gray-800 dark:text-gray-100 select-none">Invert</span>
|
|
529
601
|
</button>
|
|
@@ -537,8 +609,22 @@
|
|
|
537
609
|
title="Uncheck all"
|
|
538
610
|
>
|
|
539
611
|
<!-- Empty square icon (higher contrast stroke) -->
|
|
540
|
-
<svg
|
|
541
|
-
|
|
612
|
+
<svg
|
|
613
|
+
class="w-4 h-4 text-gray-800 dark:text-white"
|
|
614
|
+
viewBox="0 0 24 24"
|
|
615
|
+
fill="none"
|
|
616
|
+
aria-hidden="true"
|
|
617
|
+
>
|
|
618
|
+
<rect
|
|
619
|
+
x="3"
|
|
620
|
+
y="3"
|
|
621
|
+
width="18"
|
|
622
|
+
height="18"
|
|
623
|
+
rx="2"
|
|
624
|
+
stroke="currentColor"
|
|
625
|
+
stroke-width="2"
|
|
626
|
+
fill="none"
|
|
627
|
+
/>
|
|
542
628
|
</svg>
|
|
543
629
|
<span class="text-sm text-gray-800 dark:text-gray-100 select-none">None</span>
|
|
544
630
|
</button>
|
|
@@ -557,66 +643,80 @@
|
|
|
557
643
|
<button
|
|
558
644
|
class="ml-2 px-2 py-1 text-xs rounded bg-gray-100 dark:bg-gray-600 text-gray-800 dark:text-white border border-gray-200 hover:bg-gray-200 dark:hover:bg-gray-500"
|
|
559
645
|
type="button"
|
|
560
|
-
onclick={() => loadedOptions = { ...loadedOptions, [column.key]: true }}
|
|
646
|
+
onclick={() => (loadedOptions = { ...loadedOptions, [column.key]: true })}
|
|
561
647
|
>
|
|
562
648
|
Load options
|
|
563
649
|
</button>
|
|
564
650
|
</div>
|
|
565
|
-
{:else}
|
|
566
|
-
{
|
|
567
|
-
{@const v = getVirtualSlice(column, sortedValues)}
|
|
568
|
-
|
|
569
|
-
<div style="height:{v.totalHeight}px; position:relative;">
|
|
570
|
-
<div style="position:absolute; top:{v.top}px; left:0; right:0;">
|
|
571
|
-
{#each v.slice as value, idx (idx)}
|
|
572
|
-
{@const isSelected = selections[column.key]?.includes(value)}
|
|
573
|
-
{@const displayValue = value === null || value === undefined ? '(empty)' : String(value)}
|
|
574
|
-
|
|
575
|
-
<label class="flex items-center gap-1 px-2 py-1 cursor-pointer rounded-sm hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors" style="height:{virtualItemHeight}px; box-sizing:border-box;">
|
|
576
|
-
<input
|
|
577
|
-
type="checkbox"
|
|
578
|
-
checked={isSelected}
|
|
579
|
-
onchange={() => toggleSelection(column.key, value)}
|
|
580
|
-
class="w-4 h-4 shrink-0 cursor-pointer accent-blue-500"
|
|
581
|
-
/>
|
|
582
|
-
<span class="flex-1 text-sm text-gray-700 dark:text-gray-300 select-none min-w-0 overflow-hidden text-ellipsis">{displayValue}</span>
|
|
583
|
-
{#if showCounts && column.counts && column.counts[value] !== undefined}
|
|
584
|
-
<span class="text-xs text-gray-500 dark:text-gray-400 ml-auto shrink-0">({column.counts[value]})</span>
|
|
585
|
-
{/if}
|
|
586
|
-
</label>
|
|
587
|
-
{/each}
|
|
588
|
-
</div>
|
|
589
|
-
</div>
|
|
651
|
+
{:else if sortedValues.length > virtualThreshold}
|
|
652
|
+
{@const v = getVirtualSlice(column, sortedValues)}
|
|
590
653
|
|
|
591
|
-
{:
|
|
592
|
-
{
|
|
593
|
-
{#each
|
|
654
|
+
<div style="height:{v.totalHeight}px; position:relative;">
|
|
655
|
+
<div style="position:absolute; top:{v.top}px; left:0; right:0;">
|
|
656
|
+
{#each v.slice as value, idx (idx)}
|
|
594
657
|
{@const isSelected = selections[column.key]?.includes(value)}
|
|
595
|
-
{@const displayValue =
|
|
658
|
+
{@const displayValue =
|
|
659
|
+
value === null || value === undefined ? '(empty)' : String(value)}
|
|
596
660
|
|
|
597
|
-
<label
|
|
661
|
+
<label
|
|
662
|
+
class="flex items-center gap-1 px-2 py-1 cursor-pointer rounded-sm hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors"
|
|
663
|
+
style="height:{virtualItemHeight}px; box-sizing:border-box;"
|
|
664
|
+
>
|
|
598
665
|
<input
|
|
599
666
|
type="checkbox"
|
|
600
667
|
checked={isSelected}
|
|
601
668
|
onchange={() => toggleSelection(column.key, value)}
|
|
602
669
|
class="w-4 h-4 shrink-0 cursor-pointer accent-blue-500"
|
|
603
670
|
/>
|
|
604
|
-
<span
|
|
671
|
+
<span
|
|
672
|
+
class="flex-1 text-sm text-gray-700 dark:text-gray-300 select-none min-w-0 overflow-hidden text-ellipsis"
|
|
673
|
+
>{displayValue}</span
|
|
674
|
+
>
|
|
605
675
|
{#if showCounts && column.counts && column.counts[value] !== undefined}
|
|
606
|
-
<span class="text-xs text-gray-500 dark:text-gray-400 ml-auto shrink-0"
|
|
676
|
+
<span class="text-xs text-gray-500 dark:text-gray-400 ml-auto shrink-0"
|
|
677
|
+
>({column.counts[value]})</span
|
|
678
|
+
>
|
|
607
679
|
{/if}
|
|
608
680
|
</label>
|
|
609
681
|
{/each}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
{
|
|
682
|
+
</div>
|
|
683
|
+
</div>
|
|
684
|
+
{:else if sortedValues.length > 0}
|
|
685
|
+
{#each sortedValues as value, idx (idx)}
|
|
686
|
+
{@const isSelected = selections[column.key]?.includes(value)}
|
|
687
|
+
{@const displayValue =
|
|
688
|
+
value === null || value === undefined ? '(empty)' : String(value)}
|
|
689
|
+
|
|
690
|
+
<label
|
|
691
|
+
class="flex items-center gap-1 px-2 py-1 cursor-pointer rounded-sm hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors"
|
|
692
|
+
>
|
|
693
|
+
<input
|
|
694
|
+
type="checkbox"
|
|
695
|
+
checked={isSelected}
|
|
696
|
+
onchange={() => toggleSelection(column.key, value)}
|
|
697
|
+
class="w-4 h-4 shrink-0 cursor-pointer accent-blue-500"
|
|
698
|
+
/>
|
|
699
|
+
<span
|
|
700
|
+
class="flex-1 text-sm text-gray-700 dark:text-gray-300 select-none min-w-0 overflow-hidden text-ellipsis"
|
|
701
|
+
>{displayValue}</span
|
|
702
|
+
>
|
|
703
|
+
{#if showCounts && column.counts && column.counts[value] !== undefined}
|
|
704
|
+
<span class="text-xs text-gray-500 dark:text-gray-400 ml-auto shrink-0"
|
|
705
|
+
>({column.counts[value]})</span
|
|
706
|
+
>
|
|
707
|
+
{/if}
|
|
708
|
+
</label>
|
|
709
|
+
{/each}
|
|
710
|
+
{:else}
|
|
711
|
+
<div class="p-4 text-center text-sm text-gray-400 dark:text-gray-500">
|
|
712
|
+
No values available
|
|
713
|
+
</div>
|
|
614
714
|
{/if}
|
|
615
715
|
</div>
|
|
616
716
|
</div>
|
|
617
717
|
{/if}
|
|
618
|
-
|
|
619
|
-
|
|
718
|
+
</div>
|
|
719
|
+
{/each}
|
|
620
720
|
</div>
|
|
621
721
|
</div>
|
|
622
722
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { Modal } from 'flowbite-svelte';
|
|
3
|
-
import { CloseOutline } from
|
|
3
|
+
import { CloseOutline } from 'flowbite-svelte-icons';
|
|
4
4
|
import DataTableFilters from './DataTableFilters.svelte';
|
|
5
5
|
|
|
6
6
|
// Props — make `open` bindable so parent can use `bind:open`
|
|
@@ -14,27 +14,31 @@
|
|
|
14
14
|
filterChange = (..._args) => {},
|
|
15
15
|
direction = 'horizontal',
|
|
16
16
|
showCounts = true,
|
|
17
|
-
className = ''
|
|
17
|
+
className = '',
|
|
18
18
|
} = $props();
|
|
19
19
|
</script>
|
|
20
20
|
|
|
21
|
-
<Modal bind:open
|
|
21
|
+
<Modal bind:open size="lg" dismissable={false}>
|
|
22
22
|
<div class="flex items-center justify-between mb-2">
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">Filters</h3>
|
|
24
|
+
<button
|
|
25
|
+
aria-label="Close"
|
|
26
|
+
class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center dark:hover:bg-gray-600 dark:hover:text-white"
|
|
27
|
+
onclick={() => (open = false)}
|
|
28
|
+
>
|
|
29
|
+
<CloseOutline class="shrink-0 h-6 w-6" />
|
|
30
|
+
</button>
|
|
31
31
|
</div>
|
|
32
32
|
|
|
33
33
|
<DataTableFilters
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
filterChange={(payload) => {
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
{columnFilters}
|
|
35
|
+
{activeFilters}
|
|
36
|
+
filterChange={(payload) => {
|
|
37
|
+
try {
|
|
38
|
+
return filterChange(payload);
|
|
39
|
+
} catch (e) {}
|
|
40
|
+
}}
|
|
41
|
+
{direction}
|
|
42
|
+
{showCounts}
|
|
39
43
|
/>
|
|
40
|
-
</Modal>
|
|
44
|
+
</Modal>
|
package/src/lib/dist/styles.css
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
border-collapse: collapse;
|
|
13
13
|
box-sizing: border-box;
|
|
14
14
|
font-size: 0.875rem; /* 14px - smaller, more compact */
|
|
15
|
-
font-family:
|
|
15
|
+
font-family:
|
|
16
|
+
-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
|
|
16
17
|
line-height: 1.4;
|
|
17
18
|
border: none;
|
|
18
19
|
}
|
|
@@ -71,9 +72,11 @@
|
|
|
71
72
|
|
|
72
73
|
.dark .datatable-table tbody tr.selected-row {
|
|
73
74
|
/* brighter, higher-contrast selection in dark mode */
|
|
74
|
-
background-color: rgba(14,165,233,0.22) !important; /* stronger visible blue */
|
|
75
|
-
box-shadow: inset 6px 0 0 0 rgba(56,189,248,0.85); /* stronger left accent */
|
|
76
|
-
transition:
|
|
75
|
+
background-color: rgba(14, 165, 233, 0.22) !important; /* stronger visible blue */
|
|
76
|
+
box-shadow: inset 6px 0 0 0 rgba(56, 189, 248, 0.85); /* stronger left accent */
|
|
77
|
+
transition:
|
|
78
|
+
background-color 0.12s ease-in-out,
|
|
79
|
+
box-shadow 0.12s ease-in-out;
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
/* Also apply to cells to defeat any cell-level background from striping and ensure readable text */
|
|
@@ -82,9 +85,9 @@
|
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
.dark .datatable-table tbody tr.selected-row td {
|
|
85
|
-
background-color: rgba(14,165,233,0.22) !important;
|
|
88
|
+
background-color: rgba(14, 165, 233, 0.22) !important;
|
|
86
89
|
color: #f0fbff !important; /* ensure high-contrast, very light text */
|
|
87
|
-
border-bottom-color: rgba(255,255,255,0.06);
|
|
90
|
+
border-bottom-color: rgba(255, 255, 255, 0.06);
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
/* Body cell defaults - only bottom border */
|
|
@@ -219,9 +222,9 @@
|
|
|
219
222
|
|
|
220
223
|
/* Force the active/current page to use the green tokens (override flowbite's primary/orange).
|
|
221
224
|
Intentionally specific to reliably win over third-party rules. */
|
|
222
|
-
[data-pagination-id] ul li [aria-current=
|
|
225
|
+
[data-pagination-id] ul li [aria-current='page'] {
|
|
223
226
|
background-color: #dcfce7 !important; /* bg-green-100 */
|
|
224
|
-
color: #16a34a !important;
|
|
227
|
+
color: #16a34a !important; /* text-green-600 */
|
|
225
228
|
border-color: transparent !important;
|
|
226
229
|
}
|
|
227
230
|
|
|
@@ -252,7 +255,7 @@
|
|
|
252
255
|
}
|
|
253
256
|
|
|
254
257
|
/* Ellipsis styling: make clickable and visually lighter (JS sets data-ellipsis/data-jump) */
|
|
255
|
-
[data-pagination-id] ul li [data-ellipsis=
|
|
258
|
+
[data-pagination-id] ul li [data-ellipsis='true'] {
|
|
256
259
|
cursor: pointer;
|
|
257
260
|
background: transparent !important;
|
|
258
261
|
color: inherit;
|
package/src/lib/filterUtils.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
export function getUniqueValuesWithCounts(data, key) {
|
|
12
12
|
const countMap = {};
|
|
13
13
|
|
|
14
|
-
data.forEach(item => {
|
|
14
|
+
data.forEach((item) => {
|
|
15
15
|
const value = item[key];
|
|
16
16
|
// Handle null/undefined
|
|
17
17
|
const normalizedValue = value ?? '(empty)';
|
|
@@ -20,7 +20,7 @@ export function getUniqueValuesWithCounts(data, key) {
|
|
|
20
20
|
|
|
21
21
|
return {
|
|
22
22
|
uniqueValues: Object.keys(countMap),
|
|
23
|
-
counts: countMap
|
|
23
|
+
counts: countMap,
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -31,13 +31,13 @@ export function getUniqueValuesWithCounts(data, key) {
|
|
|
31
31
|
* @returns {Array} Column filters configuration for DataTableFilters
|
|
32
32
|
*/
|
|
33
33
|
export function buildColumnFilters(data, columns) {
|
|
34
|
-
return columns.map(col => {
|
|
34
|
+
return columns.map((col) => {
|
|
35
35
|
const { uniqueValues, counts } = getUniqueValuesWithCounts(data, col.key);
|
|
36
36
|
return {
|
|
37
37
|
key: col.key,
|
|
38
38
|
label: col.label || col.key,
|
|
39
39
|
uniqueValues,
|
|
40
|
-
counts
|
|
40
|
+
counts,
|
|
41
41
|
};
|
|
42
42
|
});
|
|
43
43
|
}
|
|
@@ -53,7 +53,7 @@ export function applyFilters(data, activeFilters) {
|
|
|
53
53
|
return data;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
return data.filter(item => {
|
|
56
|
+
return data.filter((item) => {
|
|
57
57
|
// Check each column filter (AND logic across columns)
|
|
58
58
|
for (const [columnKey, selectedValues] of Object.entries(activeFilters)) {
|
|
59
59
|
// Skip if no values selected for this column
|
|
@@ -78,7 +78,7 @@ export function applyFilters(data, activeFilters) {
|
|
|
78
78
|
* @returns {boolean} True if any filters are active
|
|
79
79
|
*/
|
|
80
80
|
export function hasActiveFilters(activeFilters) {
|
|
81
|
-
return Object.values(activeFilters).some(arr => arr && arr.length > 0);
|
|
81
|
+
return Object.values(activeFilters).some((arr) => arr && arr.length > 0);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/**
|
|
@@ -97,7 +97,7 @@ export function countActiveFilters(activeFilters) {
|
|
|
97
97
|
*/
|
|
98
98
|
export function clearAllFilters(columnFilters) {
|
|
99
99
|
const cleared = {};
|
|
100
|
-
columnFilters.forEach(col => {
|
|
100
|
+
columnFilters.forEach((col) => {
|
|
101
101
|
cleared[col.key] = [];
|
|
102
102
|
});
|
|
103
103
|
return cleared;
|
|
@@ -127,19 +127,20 @@ export function filtersToSearchParams(activeFilters) {
|
|
|
127
127
|
* @returns {Object} Active filters object
|
|
128
128
|
*/
|
|
129
129
|
export function searchParamsToFilters(searchParams, columnFilters) {
|
|
130
|
-
const params =
|
|
131
|
-
? new URLSearchParams(searchParams)
|
|
132
|
-
: searchParams;
|
|
130
|
+
const params =
|
|
131
|
+
typeof searchParams === 'string' ? new URLSearchParams(searchParams) : searchParams;
|
|
133
132
|
|
|
134
|
-
const validKeys = new Set(columnFilters.map(c => c.key));
|
|
133
|
+
const validKeys = new Set(columnFilters.map((c) => c.key));
|
|
135
134
|
const filters = {};
|
|
136
135
|
|
|
137
136
|
for (const [key, value] of params.entries()) {
|
|
138
137
|
if (validKeys.has(key) && value) {
|
|
139
|
-
filters[key] = value
|
|
138
|
+
filters[key] = value
|
|
139
|
+
.split(',')
|
|
140
|
+
.map((v) => v.trim())
|
|
141
|
+
.filter(Boolean);
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
|
|
143
145
|
return filters;
|
|
144
146
|
}
|
|
145
|
-
|
package/src/lib/index.js
CHANGED