@zhangt58/svelte-vtable 0.1.2 → 0.1.4

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.
@@ -35,6 +35,18 @@
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
37
  dropdownInline = true,
38
+ // Relative-range quick-set presets shown in the datetime range picker.
39
+ // Each entry: { label: string, value: number, unit: 'hour'|'day'|'week'|'month'|'year' }
40
+ // Presets with unit 'hour' are only shown for 'datetimerange' columns.
41
+ relativeRangePresets = /** @type {Array<{label:string,value:number,unit:string}>} */ ([
42
+ { label: '1h', value: 1, unit: 'hour' },
43
+ { label: '6h', value: 6, unit: 'hour' },
44
+ { label: '12h', value: 12, unit: 'hour' },
45
+ { label: '1d', value: 1, unit: 'day' },
46
+ { label: '7d', value: 7, unit: 'day' },
47
+ { label: '30d', value: 30, unit: 'day' },
48
+ { label: '1y', value: 1, unit: 'year' },
49
+ ]),
38
50
  } = $props();
39
51
 
40
52
  // Internal state for selected options per column
@@ -96,11 +108,16 @@
96
108
  flushEmit();
97
109
  });
98
110
 
111
+ // Helper: is this column a date/datetime range filter?
112
+ function isDateRangeColumn(col) {
113
+ return col.type === 'daterange' || col.type === 'datetimerange';
114
+ }
115
+
99
116
  // Initialize selections from activeFilters
100
117
  $effect(() => {
101
118
  const newSelections = {};
102
119
  for (const col of columnFilters) {
103
- newSelections[col.key] = activeFilters[col.key] || [];
120
+ newSelections[col.key] = activeFilters[col.key] ?? (isDateRangeColumn(col) ? {} : []);
104
121
  }
105
122
  selections = newSelections;
106
123
  });
@@ -126,15 +143,17 @@
126
143
 
127
144
  // Clear all selections for a column
128
145
  function clearColumn(columnKey) {
129
- selections = { ...selections, [columnKey]: [] };
130
- scheduleEmit(columnKey, []);
146
+ const col = columnFilters.find((c) => c.key === columnKey);
147
+ const empty = isDateRangeColumn(col) ? {} : [];
148
+ selections = { ...selections, [columnKey]: empty };
149
+ scheduleEmit(columnKey, empty);
131
150
  }
132
151
 
133
152
  // Clear all filters
134
153
  function clearAllFilters() {
135
154
  const cleared = {};
136
155
  for (const col of columnFilters) {
137
- cleared[col.key] = [];
156
+ cleared[col.key] = isDateRangeColumn(col) ? {} : [];
138
157
  }
139
158
  selections = cleared;
140
159
 
@@ -144,12 +163,20 @@
144
163
 
145
164
  // Check if any filters are active
146
165
  const hasActiveFilters = $derived(() => {
147
- return Object.values(selections).some((arr) => arr && arr.length > 0);
166
+ return Object.values(selections).some((val) => {
167
+ if (Array.isArray(val)) return val.length > 0;
168
+ if (val && typeof val === 'object') return !!(val.from || val.to);
169
+ return false;
170
+ });
148
171
  });
149
172
 
150
173
  // Count active filters
151
174
  const activeFilterCount = $derived(() => {
152
- return Object.values(selections).reduce((sum, arr) => sum + (arr?.length || 0), 0);
175
+ return Object.values(selections).reduce((sum, val) => {
176
+ if (Array.isArray(val)) return sum + (val?.length || 0);
177
+ if (val && typeof val === 'object' && (val.from || val.to)) return sum + 1;
178
+ return sum;
179
+ }, 0);
153
180
  });
154
181
 
155
182
  // Toggle dropdown visibility for a column
@@ -243,6 +270,17 @@
243
270
  return { slice, start, end, top, totalHeight };
244
271
  }
245
272
 
273
+ // --- Helper: extract a numeric sort key from a value ---
274
+ // Returns the number itself if numeric, the first number found in a string,
275
+ // or 0 if no number can be found.
276
+ function extractNumber(v) {
277
+ if (v === null || v === undefined) return 0;
278
+ if (typeof v === 'number') return v;
279
+ const s = String(v);
280
+ const match = s.match(/-?\d+(\.\d+)?/);
281
+ return match ? parseFloat(match[0]) : 0;
282
+ }
283
+
246
284
  // --- Helper: return the values for a column after applying search + sort ---
247
285
  function getSortedValues(column) {
248
286
  // column.uniqueValues is expected to be an array of possible values
@@ -276,6 +314,13 @@
276
314
  // fallback to name compare
277
315
  }
278
316
 
317
+ if (mode === 'number') {
318
+ const na = extractNumber(va);
319
+ const nb = extractNumber(vb);
320
+ if (na !== nb) return (na - nb) * dir;
321
+ // fallback to name compare for equal numeric values
322
+ }
323
+
279
324
  // compare by name
280
325
  const sa = va === null || va === undefined ? '(empty)' : String(va);
281
326
  const sb = vb === null || vb === undefined ? '(empty)' : String(vb);
@@ -350,6 +395,101 @@
350
395
  clearColumn(columnKey);
351
396
  }
352
397
 
398
+ // Handle a date/datetime range input change
399
+ function handleDateRangeChange(columnKey, field, value) {
400
+ const current = selections[columnKey] || {};
401
+ const updated = { ...current, [field]: value };
402
+ selections = { ...selections, [columnKey]: updated };
403
+ scheduleEmit(columnKey, updated);
404
+ }
405
+
406
+ // --- Date-range slider helpers ---
407
+
408
+ // Parse a date-filter string (e.g. "2024-01-15" or "2024-01-15T08:30") to a ms timestamp.
409
+ // Uses the same rule as filterUtils.matchesDateRange: a bare YYYY-MM-DD string is treated as
410
+ // local midnight (appended with "T00:00:00") so slider thumb positions stay consistent with
411
+ // how records are matched.
412
+ function parseFilterDate(str) {
413
+ if (!str) return NaN;
414
+ return /^\d{4}-\d{2}-\d{2}$/.test(str)
415
+ ? new Date(str + 'T00:00:00').getTime()
416
+ : new Date(str).getTime();
417
+ }
418
+
419
+ // Format a timestamp back to the value expected by <input type="date"> or
420
+ // <input type="datetime-local">.
421
+ function formatAsInputValue(ms, inputType) {
422
+ const d = new Date(ms);
423
+ const pad = (n) => String(n).padStart(2, '0');
424
+ const dateStr = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
425
+ if (inputType === 'datetime-local') {
426
+ return `${dateStr}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
427
+ }
428
+ return dateStr;
429
+ }
430
+
431
+ // Handle the "from" slider thumb moving.
432
+ function handleFromSlider(columnKey, pct, minMs, maxMs, inputType) {
433
+ const current = selections[columnKey] || {};
434
+ const toMs = parseFilterDate(current.to);
435
+ let newFromMs = minMs + (pct / 100) * (maxMs - minMs);
436
+ // Clamp: from must not exceed to
437
+ if (!isNaN(toMs) && newFromMs > toMs) newFromMs = toMs;
438
+ const newFrom = formatAsInputValue(newFromMs, inputType);
439
+ const updated = { ...current, from: newFrom };
440
+ selections = { ...selections, [columnKey]: updated };
441
+ scheduleEmit(columnKey, updated);
442
+ }
443
+
444
+ // Handle the "to" slider thumb moving.
445
+ function handleToSlider(columnKey, pct, minMs, maxMs, inputType) {
446
+ const current = selections[columnKey] || {};
447
+ const fromMs = parseFilterDate(current.from);
448
+ let newToMs = minMs + (pct / 100) * (maxMs - minMs);
449
+ // Clamp: to must not be less than from
450
+ if (!isNaN(fromMs) && newToMs < fromMs) newToMs = fromMs;
451
+ const newTo = formatAsInputValue(newToMs, inputType);
452
+ const updated = { ...current, to: newTo };
453
+ selections = { ...selections, [columnKey]: updated };
454
+ scheduleEmit(columnKey, updated);
455
+ }
456
+
457
+ // Set the date range from a relative preset (e.g. "last 7 days" → from=now-7d, to=now).
458
+ function setRelativeRange(columnKey, value, unit) {
459
+ const now = new Date();
460
+ const from = new Date(now);
461
+ switch (unit) {
462
+ case 'hour':
463
+ from.setHours(from.getHours() - value);
464
+ break;
465
+ case 'day':
466
+ from.setDate(from.getDate() - value);
467
+ break;
468
+ case 'week':
469
+ from.setDate(from.getDate() - value * 7);
470
+ break;
471
+ case 'month':
472
+ from.setMonth(from.getMonth() - value);
473
+ break;
474
+ case 'year':
475
+ from.setFullYear(from.getFullYear() - value);
476
+ break;
477
+ }
478
+ const col = columnFilters.find((c) => c.key === columnKey);
479
+ const inputType = col?.type === 'datetimerange' ? 'datetime-local' : 'date';
480
+ const updated = {
481
+ from: formatAsInputValue(from.getTime(), inputType),
482
+ to: formatAsInputValue(now.getTime(), inputType),
483
+ };
484
+ selections = { ...selections, [columnKey]: updated };
485
+ scheduleEmit(columnKey, updated);
486
+ }
487
+
488
+ // Return the relative presets applicable to a given column type.
489
+ function getApplicablePresets(colType) {
490
+ return relativeRangePresets.filter((p) => p.unit !== 'hour' || colType === 'datetimerange');
491
+ }
492
+
353
493
  // Show all dropdowns
354
494
  function showAllDropdowns() {
355
495
  const allOpen = {};
@@ -422,7 +562,8 @@
422
562
  class:grid-vertical={direction === 'vertical'}
423
563
  >
424
564
  {#each columnFilters as column (column.key)}
425
- {@const isActive = selections[column.key]?.length > 0}
565
+ {@const _sel = selections[column.key]}
566
+ {@const isActive = Array.isArray(_sel) ? _sel.length > 0 : !!(_sel?.from || _sel?.to)}
426
567
  {@const isOpen = openDropdowns[column.key]}
427
568
  {@const sortedValues = getSortedValues(column)}
428
569
  {@const currentSortMode = sortModes[column.key] || 'name'}
@@ -441,7 +582,11 @@
441
582
  {column.label || column.key}
442
583
  </span>
443
584
  {#if isActive}
444
- <Badge color="green" rounded class="ml-1">{selections[column.key].length}</Badge>
585
+ {#if Array.isArray(_sel)}
586
+ <Badge color="green" rounded class="ml-1">{_sel.length}</Badge>
587
+ {:else}
588
+ <Badge color="green" rounded class="ml-1">range</Badge>
589
+ {/if}
445
590
  {/if}
446
591
  <ChevronDownOutline
447
592
  class="w-5 h-5 shrink-0 transition-transform {isOpen ? 'rotate-180' : ''}"
@@ -450,269 +595,515 @@
450
595
 
451
596
  {#if isOpen}
452
597
  <div
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`}
598
+ class={[
599
+ dropdownInline ? '' : 'absolute top-full left-0 right-0',
600
+ 'mt-1 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md shadow-lg dark:shadow-gray-900 flex flex-col dropdown-menu',
601
+ isDateRangeColumn(column) ? 'overflow-y-auto' : 'max-h-64',
602
+ ]
603
+ .filter(Boolean)
604
+ .join(' ')}
456
605
  tabindex="-1"
457
606
  data-column={column.key}
458
607
  >
459
- <div class="px-1 py-1 border-b border-gray-200 dark:border-gray-600">
460
- <div class="flex items-center gap-1 w-full min-w-0">
461
- <input
462
- type="text"
463
- placeholder="Filter..."
464
- class="p-1 flex-1 min-w-0 px-2 py-1 text-xs border border-gray-200 dark:border-gray-600 rounded bg-white dark:bg-gray-700 text-gray-700 dark:text-gray-200 focus:outline-none focus:border-blue-500"
465
- bind:value={searchQueries[column.key]}
466
- />
467
-
468
- <div class="flex items-center gap-1">
608
+ {#if isDateRangeColumn(column)}
609
+ <!-- Date / datetime range picker UI -->
610
+ {@const inputType = column.type === 'datetimerange' ? 'datetime-local' : 'date'}
611
+ {@const dateRange = selections[column.key] || {}}
612
+ {@const minMs = parseFilterDate(column.minValue)}
613
+ {@const maxMs = parseFilterDate(column.maxValue)}
614
+ {@const totalMs = maxMs - minMs}
615
+ {@const fromMs = parseFilterDate(dateRange.from)}
616
+ {@const toMs = parseFilterDate(dateRange.to)}
617
+ {@const fromPct =
618
+ totalMs > 0 && !isNaN(fromMs)
619
+ ? Math.max(0, Math.min(100, ((fromMs - minMs) / totalMs) * 100))
620
+ : 0}
621
+ {@const toPct =
622
+ totalMs > 0 && !isNaN(toMs)
623
+ ? Math.max(0, Math.min(100, ((toMs - minMs) / totalMs) * 100))
624
+ : 100}
625
+ {@const applicablePresets = getApplicablePresets(column.type)}
626
+ <div class="p-3 flex flex-col gap-2">
627
+ <!-- From input + Earliest shortcut -->
628
+ <div class="flex items-center gap-2">
629
+ <label
630
+ class="text-xs font-medium text-gray-500 dark:text-gray-400 w-8 shrink-0"
631
+ for="filter-{column.key}-from"
632
+ >
633
+ From
634
+ </label>
635
+ <input
636
+ id="filter-{column.key}-from"
637
+ type={inputType}
638
+ class="flex-1 min-w-0 px-2 py-1 text-xs border border-gray-200 dark:border-gray-600 rounded bg-white dark:bg-gray-800 text-gray-700 dark:text-gray-200 focus:outline-none focus:border-blue-500 dark:focus:border-blue-400"
639
+ value={dateRange.from || ''}
640
+ oninput={(e) =>
641
+ handleDateRangeChange(column.key, 'from', e.currentTarget.value)}
642
+ />
643
+ {#if column.minValue}
644
+ <button
645
+ type="button"
646
+ class="shrink-0 px-2 py-0.5 text-xs rounded border border-indigo-400 text-indigo-700 dark:text-indigo-300 hover:bg-indigo-50 dark:hover:bg-indigo-900/20 transition-colors flex items-center"
647
+ title="Set From to the earliest record ({column.minValue})"
648
+ aria-label="Set From to the earliest record"
649
+ onclick={() => handleDateRangeChange(column.key, 'from', column.minValue)}
650
+ >
651
+ <!-- Double-chevron-left icon (Earliest) -->
652
+ <svg
653
+ class="w-4 h-4 text-indigo-700 dark:text-indigo-300"
654
+ viewBox="0 0 24 24"
655
+ fill="none"
656
+ aria-hidden="true"
657
+ >
658
+ <path
659
+ d="M11.5 7.5L7 12l4.5 4.5"
660
+ stroke="currentColor"
661
+ stroke-width="2"
662
+ stroke-linecap="round"
663
+ stroke-linejoin="round"
664
+ fill="none"
665
+ />
666
+ <path
667
+ d="M17.5 7.5L13 12l4.5 4.5"
668
+ stroke="currentColor"
669
+ stroke-width="2"
670
+ stroke-linecap="round"
671
+ stroke-linejoin="round"
672
+ fill="none"
673
+ />
674
+ </svg>
675
+ </button>
676
+ {/if}
677
+ </div>
678
+ <!-- To input + Latest shortcut -->
679
+ <div class="flex items-center gap-2">
680
+ <label
681
+ class="text-xs font-medium text-gray-500 dark:text-gray-400 w-8 shrink-0"
682
+ for="filter-{column.key}-to"
683
+ >
684
+ To
685
+ </label>
686
+ <input
687
+ id="filter-{column.key}-to"
688
+ type={inputType}
689
+ class="flex-1 min-w-0 px-2 py-1 text-xs border border-gray-200 dark:border-gray-600 rounded bg-white dark:bg-gray-800 text-gray-700 dark:text-gray-200 focus:outline-none focus:border-blue-500 dark:focus:border-blue-400"
690
+ value={dateRange.to || ''}
691
+ oninput={(e) => handleDateRangeChange(column.key, 'to', e.currentTarget.value)}
692
+ />
693
+ {#if column.maxValue}
694
+ <button
695
+ type="button"
696
+ class="shrink-0 px-2 py-0.5 text-xs rounded border border-indigo-400 text-indigo-700 dark:text-indigo-300 hover:bg-indigo-50 dark:hover:bg-indigo-900/20 transition-colors flex items-center"
697
+ title="Set To to the latest record ({column.maxValue})"
698
+ aria-label="Set To to the latest record"
699
+ onclick={() => handleDateRangeChange(column.key, 'to', column.maxValue)}
700
+ >
701
+ <!-- Double-chevron-right icon (Latest) -->
702
+ <svg
703
+ class="w-4 h-4 text-indigo-700 dark:text-indigo-300"
704
+ viewBox="0 0 24 24"
705
+ fill="none"
706
+ aria-hidden="true"
707
+ >
708
+ <path
709
+ d="M12.5 7.5L17 12l-4.5 4.5"
710
+ stroke="currentColor"
711
+ stroke-width="2"
712
+ stroke-linecap="round"
713
+ stroke-linejoin="round"
714
+ fill="none"
715
+ />
716
+ <path
717
+ d="M6.5 7.5L11 12l-4.5 4.5"
718
+ stroke="currentColor"
719
+ stroke-width="2"
720
+ stroke-linecap="round"
721
+ stroke-linejoin="round"
722
+ fill="none"
723
+ />
724
+ </svg>
725
+ </button>
726
+ {/if}
727
+ </div>
728
+
729
+ <!-- Dual-range slider (only when column provides min/max) -->
730
+ {#if column.minValue && column.maxValue && totalMs > 0}
731
+ <div class="dual-range-wrapper" aria-label="Date range slider">
732
+ <!-- Background track -->
733
+ <div class="dual-range-track-bg"></div>
734
+ <!-- Active-range highlight -->
735
+ <div
736
+ class="dual-range-track-fill"
737
+ style="left:{fromPct}%; right:{100 - toPct}%"
738
+ ></div>
739
+ <!-- From thumb -->
740
+ <input
741
+ type="range"
742
+ class="dual-range-input"
743
+ min="0"
744
+ max="100"
745
+ step="0.02"
746
+ value={fromPct}
747
+ style="z-index:{fromPct >= toPct - 2 ? 4 : 3}"
748
+ oninput={(e) =>
749
+ handleFromSlider(
750
+ column.key,
751
+ parseFloat(e.currentTarget.value),
752
+ minMs,
753
+ maxMs,
754
+ inputType,
755
+ )}
756
+ aria-label="Range start"
757
+ />
758
+ <!-- To thumb -->
759
+ <input
760
+ type="range"
761
+ class="dual-range-input"
762
+ min="0"
763
+ max="100"
764
+ step="0.02"
765
+ value={toPct}
766
+ style="z-index:{fromPct >= toPct - 2 ? 3 : 4}"
767
+ oninput={(e) =>
768
+ handleToSlider(
769
+ column.key,
770
+ parseFloat(e.currentTarget.value),
771
+ minMs,
772
+ maxMs,
773
+ inputType,
774
+ )}
775
+ aria-label="Range end"
776
+ />
777
+ </div>
778
+ {/if}
779
+
780
+ <!-- Relative-range quick buttons -->
781
+ {#if applicablePresets.length > 0}
782
+ <div
783
+ class="flex flex-wrap gap-1 pt-1 border-t border-gray-100 dark:border-gray-600"
784
+ >
785
+ {#each applicablePresets as preset (preset.label)}
786
+ <button
787
+ type="button"
788
+ class="px-2 py-0.5 text-xs rounded border border-blue-400 text-blue-700 dark:text-blue-300 hover:bg-blue-50 dark:hover:bg-blue-900/20 transition-colors"
789
+ title="Last {preset.value} {preset.unit}{preset.value !== 1 ? 's' : ''}"
790
+ onclick={() => setRelativeRange(column.key, preset.value, preset.unit)}
791
+ >
792
+ Last {preset.label}
793
+ </button>
794
+ {/each}
795
+ </div>
796
+ {/if}
797
+
798
+ {#if dateRange.from || dateRange.to}
469
799
  <button
470
- class="p-0.5 flex-1 flex items-center justify-center gap-1 text-sm text-gray-600 dark:text-gray-400 bg-transparent border border-gray-200 dark:border-gray-700 rounded hover:bg-gray-100 dark:hover:bg-gray-700 hover:border-gray-300 dark:hover:border-gray-600 hover:text-gray-700 dark:hover:text-gray-300 transition-all"
471
- class:bg-blue-100={currentSortMode === 'name'}
472
- class:dark:bg-blue-900={currentSortMode === 'name'}
473
- onclick={() => toggleSortMode(column.key, 'name')}
474
- title="Sort by name"
475
800
  type="button"
801
+ class="self-start px-2 py-0.5 text-xs text-red-600 border border-red-400 rounded hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors"
802
+ onclick={() => clearColumn(column.key)}
476
803
  >
477
- <span class="text-sm font-semibold">Aa</span>
478
- <ArrowDownOutline
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
- : ''}
486
- aria-hidden="true"
487
- />
804
+ Clear range
488
805
  </button>
806
+ {/if}
807
+ </div>
808
+ {:else}
809
+ <!-- Value-selection filter UI (checkboxes) -->
810
+ <div class="px-1 py-1 border-b border-gray-200 dark:border-gray-600">
811
+ <div class="flex items-center gap-1 w-full min-w-0">
812
+ <input
813
+ type="text"
814
+ placeholder="Filter..."
815
+ class="p-1 flex-1 min-w-0 px-2 py-1 text-xs border border-gray-200 dark:border-gray-600 rounded bg-white dark:bg-gray-700 text-gray-700 dark:text-gray-200 focus:outline-none focus:border-blue-500"
816
+ bind:value={searchQueries[column.key]}
817
+ />
818
+
819
+ <div class="flex items-center gap-1">
820
+ <button
821
+ class="p-0.5 flex-1 flex items-center justify-center gap-1 text-sm text-gray-600 dark:text-gray-400 bg-transparent border border-gray-200 dark:border-gray-700 rounded hover:bg-gray-100 dark:hover:bg-gray-700 hover:border-gray-300 dark:hover:border-gray-600 hover:text-gray-700 dark:hover:text-gray-300 transition-all"
822
+ class:bg-blue-100={currentSortMode === 'name'}
823
+ class:dark:bg-blue-900={currentSortMode === 'name'}
824
+ onclick={() => toggleSortMode(column.key, 'name')}
825
+ title="Sort by name"
826
+ type="button"
827
+ >
828
+ <span
829
+ class="flex flex-col items-center leading-none font-semibold"
830
+ style="font-size:0.6rem;"
831
+ >
832
+ <span>A</span>
833
+ <span>Z</span>
834
+ </span>
835
+ <ArrowDownOutline
836
+ class={'w-3 h-3 transition-transform ' +
837
+ (currentSortMode === 'name'
838
+ ? 'text-blue-900 dark:text-blue-100'
839
+ : 'text-gray-400 dark:text-gray-500')}
840
+ style={currentSortMode === 'name' && currentSortDir === 'asc'
841
+ ? 'transform: rotate(180deg);'
842
+ : ''}
843
+ aria-hidden="true"
844
+ />
845
+ </button>
489
846
 
490
- {#if showCounts && column.counts}
491
847
  <button
492
848
  class="p-0.5 flex-1 flex items-center justify-center gap-1 text-sm text-gray-600 dark:text-gray-400 bg-transparent border border-gray-200 dark:border-gray-700 rounded hover:bg-gray-100 dark:hover:bg-gray-700 hover:border-gray-300 dark:hover:border-gray-600 hover:text-gray-700 dark:hover:text-gray-300 transition-all"
493
- class:bg-blue-100={currentSortMode === 'count'}
494
- class:dark:bg-blue-900={currentSortMode === 'count'}
495
- onclick={() => toggleSortMode(column.key, 'count')}
496
- title="Sort by count"
849
+ class:bg-blue-100={currentSortMode === 'number'}
850
+ class:dark:bg-blue-900={currentSortMode === 'number'}
851
+ onclick={() => toggleSortMode(column.key, 'number')}
852
+ title="Sort by number"
853
+ aria-label="Sort by number"
497
854
  type="button"
498
855
  >
499
- <span class="text-sm font-semibold">#</span>
856
+ <span
857
+ class="flex flex-col items-center leading-none font-semibold"
858
+ style="font-size:0.6rem;"
859
+ >
860
+ <span>0</span>
861
+ <span>9</span>
862
+ </span>
500
863
  <ArrowDownOutline
501
864
  class={'w-3 h-3 transition-transform ' +
502
- (currentSortMode === 'count'
865
+ (currentSortMode === 'number'
503
866
  ? 'text-blue-900 dark:text-blue-100'
504
867
  : 'text-gray-400 dark:text-gray-500')}
505
- style={currentSortMode === 'count' && currentSortDir === 'asc'
868
+ style={currentSortMode === 'number' && currentSortDir === 'asc'
506
869
  ? 'transform: rotate(180deg);'
507
870
  : ''}
508
871
  aria-hidden="true"
509
872
  />
510
873
  </button>
511
- {/if}
874
+
875
+ {#if showCounts && column.counts}
876
+ <button
877
+ class="p-0.5 flex-1 flex items-center justify-center gap-1 text-sm text-gray-600 dark:text-gray-400 bg-transparent border border-gray-200 dark:border-gray-700 rounded hover:bg-gray-100 dark:hover:bg-gray-700 hover:border-gray-300 dark:hover:border-gray-600 hover:text-gray-700 dark:hover:text-gray-300 transition-all"
878
+ class:bg-blue-100={currentSortMode === 'count'}
879
+ class:dark:bg-blue-900={currentSortMode === 'count'}
880
+ onclick={() => toggleSortMode(column.key, 'count')}
881
+ title="Sort by count"
882
+ type="button"
883
+ >
884
+ <span class="text-sm font-semibold">#</span>
885
+ <ArrowDownOutline
886
+ class={'w-3 h-3 transition-transform ' +
887
+ (currentSortMode === 'count'
888
+ ? 'text-blue-900 dark:text-blue-100'
889
+ : 'text-gray-400 dark:text-gray-500')}
890
+ style={currentSortMode === 'count' && currentSortDir === 'asc'
891
+ ? 'transform: rotate(180deg);'
892
+ : ''}
893
+ aria-hidden="true"
894
+ />
895
+ </button>
896
+ {/if}
897
+ </div>
512
898
  </div>
513
899
  </div>
514
- </div>
515
900
 
516
- <!-- Action row: Check all / Invert / Uncheck all (icon buttons) -->
517
- <div class="px-2 py-1 border-b border-gray-100 dark:border-gray-600">
518
- <div class="flex items-center justify-between">
519
- <div class="flex items-center gap-1">
520
- <button
521
- type="button"
522
- class="p-1 rounded-md flex items-center gap-1 text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-600 disabled:opacity-50 disabled:cursor-not-allowed"
523
- onclick={() => checkAll(column.key, sortedValues)}
524
- disabled={sortedValues.length === 0}
525
- aria-label="Check all"
526
- title="Check all"
527
- >
528
- <!-- Checked square icon (higher contrast) -->
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"
901
+ <!-- Action row: Check all / Invert / Uncheck all (icon buttons) -->
902
+ <div class="px-2 py-1 border-b border-gray-100 dark:border-gray-600">
903
+ <div class="flex items-center justify-between">
904
+ <div class="flex items-center gap-1">
905
+ <button
906
+ type="button"
907
+ class="p-1 rounded-md flex items-center gap-1 text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-600 disabled:opacity-50 disabled:cursor-not-allowed"
908
+ onclick={() => checkAll(column.key, sortedValues)}
909
+ disabled={sortedValues.length === 0}
910
+ aria-label="Check all"
911
+ title="Check all"
534
912
  >
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"
913
+ <!-- Checked square icon (higher contrast) -->
914
+ <svg
915
+ class="w-4 h-4 text-gray-800 dark:text-white"
916
+ viewBox="0 0 24 24"
551
917
  fill="none"
552
- />
553
- </svg>
554
- <span class="text-sm text-gray-800 dark:text-gray-100 select-none">All</span>
555
- </button>
918
+ aria-hidden="true"
919
+ >
920
+ <rect
921
+ x="3"
922
+ y="3"
923
+ width="18"
924
+ height="18"
925
+ rx="2"
926
+ stroke="currentColor"
927
+ stroke-width="2.5"
928
+ fill="none"
929
+ />
930
+ <path
931
+ d="M7 13l3 3 7-7"
932
+ stroke="currentColor"
933
+ stroke-width="2"
934
+ stroke-linecap="round"
935
+ stroke-linejoin="round"
936
+ fill="none"
937
+ />
938
+ </svg>
939
+ <span class="text-sm text-gray-800 dark:text-gray-100 select-none">All</span>
940
+ </button>
556
941
 
557
- <button
558
- type="button"
559
- class="p-1 rounded-md flex items-center gap-1 text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-600 disabled:opacity-50 disabled:cursor-not-allowed"
560
- onclick={() => invertSelection(column.key, sortedValues)}
561
- disabled={sortedValues.length === 0}
562
- aria-label="Invert selection"
563
- title="Invert selection"
564
- >
565
- <!-- Half-checked square icon (left half filled) - higher contrast -->
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"
942
+ <button
943
+ type="button"
944
+ class="p-1 rounded-md flex items-center gap-1 text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-600 disabled:opacity-50 disabled:cursor-not-allowed"
945
+ onclick={() => invertSelection(column.key, sortedValues)}
946
+ disabled={sortedValues.length === 0}
947
+ aria-label="Invert selection"
948
+ title="Invert selection"
571
949
  >
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"
950
+ <!-- Half-checked square icon (left half filled) - higher contrast -->
951
+ <svg
952
+ class="w-4 h-4 text-gray-800 dark:text-white"
953
+ viewBox="0 0 24 24"
597
954
  fill="none"
598
- />
599
- </svg>
600
- <span class="text-sm text-gray-800 dark:text-gray-100 select-none">Invert</span>
601
- </button>
955
+ aria-hidden="true"
956
+ >
957
+ <rect
958
+ x="3"
959
+ y="3"
960
+ width="18"
961
+ height="18"
962
+ rx="2"
963
+ stroke="currentColor"
964
+ stroke-width="2.5"
965
+ fill="none"
966
+ />
967
+ <rect
968
+ x="4"
969
+ y="4"
970
+ width="8.5"
971
+ height="16"
972
+ fill="currentColor"
973
+ opacity="0.28"
974
+ stroke="none"
975
+ />
976
+ <path
977
+ d="M7 13l3 3 7-7"
978
+ stroke="currentColor"
979
+ stroke-width="2"
980
+ stroke-linecap="round"
981
+ stroke-linejoin="round"
982
+ fill="none"
983
+ />
984
+ </svg>
985
+ <span class="text-sm text-gray-800 dark:text-gray-100 select-none"
986
+ >Invert</span
987
+ >
988
+ </button>
602
989
 
603
- <button
604
- type="button"
605
- class="p-1 rounded-md flex items-center gap-1 text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-600 disabled:opacity-50 disabled:cursor-not-allowed"
606
- onclick={() => checkNone(column.key)}
607
- disabled={sortedValues.length === 0}
608
- aria-label="Uncheck all"
609
- title="Uncheck all"
610
- >
611
- <!-- Empty square icon (higher contrast stroke) -->
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"
990
+ <button
991
+ type="button"
992
+ class="p-1 rounded-md flex items-center gap-1 text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-600 disabled:opacity-50 disabled:cursor-not-allowed"
993
+ onclick={() => checkNone(column.key)}
994
+ disabled={sortedValues.length === 0}
995
+ aria-label="Uncheck all"
996
+ title="Uncheck all"
617
997
  >
618
- <rect
619
- x="3"
620
- y="3"
621
- width="18"
622
- height="18"
623
- rx="2"
624
- stroke="currentColor"
625
- stroke-width="2"
998
+ <!-- Empty square icon (higher contrast stroke) -->
999
+ <svg
1000
+ class="w-4 h-4 text-gray-800 dark:text-white"
1001
+ viewBox="0 0 24 24"
626
1002
  fill="none"
627
- />
628
- </svg>
629
- <span class="text-sm text-gray-800 dark:text-gray-100 select-none">None</span>
630
- </button>
631
- </div>
1003
+ aria-hidden="true"
1004
+ >
1005
+ <rect
1006
+ x="3"
1007
+ y="3"
1008
+ width="18"
1009
+ height="18"
1010
+ rx="2"
1011
+ stroke="currentColor"
1012
+ stroke-width="2"
1013
+ fill="none"
1014
+ />
1015
+ </svg>
1016
+ <span class="text-sm text-gray-800 dark:text-gray-100 select-none">None</span>
1017
+ </button>
1018
+ </div>
632
1019
 
633
- <div class="pr-1">
634
- <Badge color="blue" rounded title="Total options">{sortedValues.length}</Badge>
1020
+ <div class="pr-1">
1021
+ <Badge color="blue" rounded title="Total options">{sortedValues.length}</Badge>
1022
+ </div>
635
1023
  </div>
636
1024
  </div>
637
- </div>
638
1025
 
639
- <div class="p-1 overflow-y-auto flex-1" use:registerList={{ key: column.key }}>
640
- {#if sortedValues.length > populateThreshold && !loadedOptions[column.key]}
641
- <div class="p-1 text-sm text-gray-700 dark:text-gray-200">
642
- Too many options ({sortedValues.length}) to render by default.
643
- <button
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"
645
- type="button"
646
- onclick={() => (loadedOptions = { ...loadedOptions, [column.key]: true })}
647
- >
648
- Load options
649
- </button>
650
- </div>
651
- {:else if sortedValues.length > virtualThreshold}
652
- {@const v = getVirtualSlice(column, sortedValues)}
653
-
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)}
657
- {@const isSelected = selections[column.key]?.includes(value)}
658
- {@const displayValue =
659
- value === null || value === undefined ? '(empty)' : String(value)}
660
-
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
- >
665
- <input
666
- type="checkbox"
667
- checked={isSelected}
668
- onchange={() => toggleSelection(column.key, value)}
669
- class="w-4 h-4 shrink-0 cursor-pointer accent-blue-500"
670
- />
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
1026
+ <div
1027
+ class="p-1 overflow-y-auto flex-1 max-h-48"
1028
+ use:registerList={{ key: column.key }}
1029
+ >
1030
+ {#if sortedValues.length > populateThreshold && !loadedOptions[column.key]}
1031
+ <div class="p-1 text-sm text-gray-700 dark:text-gray-200">
1032
+ Too many options ({sortedValues.length}) to render by default.
1033
+ <button
1034
+ 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"
1035
+ type="button"
1036
+ onclick={() => (loadedOptions = { ...loadedOptions, [column.key]: true })}
1037
+ >
1038
+ Load options
1039
+ </button>
1040
+ </div>
1041
+ {:else if sortedValues.length > virtualThreshold}
1042
+ {@const v = getVirtualSlice(column, sortedValues)}
1043
+
1044
+ <div style="height:{v.totalHeight}px; position:relative;">
1045
+ <div style="position:absolute; top:{v.top}px; left:0; right:0;">
1046
+ {#each v.slice as value, idx (idx)}
1047
+ {@const isSelected = selections[column.key]?.includes(value)}
1048
+ {@const displayValue =
1049
+ value === null || value === undefined ? '(empty)' : String(value)}
1050
+
1051
+ <label
1052
+ 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"
1053
+ style="height:{virtualItemHeight}px; box-sizing:border-box;"
674
1054
  >
675
- {#if showCounts && column.counts && column.counts[value] !== undefined}
676
- <span class="text-xs text-gray-500 dark:text-gray-400 ml-auto shrink-0"
677
- >({column.counts[value]})</span
1055
+ <input
1056
+ type="checkbox"
1057
+ checked={isSelected}
1058
+ onchange={() => toggleSelection(column.key, value)}
1059
+ class="w-4 h-4 shrink-0 cursor-pointer accent-blue-500"
1060
+ />
1061
+ <span
1062
+ class="flex-1 text-sm text-gray-700 dark:text-gray-300 select-none min-w-0 overflow-hidden text-ellipsis"
1063
+ >{displayValue}</span
678
1064
  >
679
- {/if}
680
- </label>
681
- {/each}
1065
+ {#if showCounts && column.counts && column.counts[value] !== undefined}
1066
+ <span class="text-xs text-gray-500 dark:text-gray-400 ml-auto shrink-0"
1067
+ >({column.counts[value]})</span
1068
+ >
1069
+ {/if}
1070
+ </label>
1071
+ {/each}
1072
+ </div>
682
1073
  </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
1074
+ {:else if sortedValues.length > 0}
1075
+ {#each sortedValues as value, idx (idx)}
1076
+ {@const isSelected = selections[column.key]?.includes(value)}
1077
+ {@const displayValue =
1078
+ value === null || value === undefined ? '(empty)' : String(value)}
1079
+
1080
+ <label
1081
+ 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"
702
1082
  >
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
1083
+ <input
1084
+ type="checkbox"
1085
+ checked={isSelected}
1086
+ onchange={() => toggleSelection(column.key, value)}
1087
+ class="w-4 h-4 shrink-0 cursor-pointer accent-blue-500"
1088
+ />
1089
+ <span
1090
+ class="flex-1 text-sm text-gray-700 dark:text-gray-300 select-none min-w-0 overflow-hidden text-ellipsis"
1091
+ >{displayValue}</span
706
1092
  >
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>
714
- {/if}
715
- </div>
1093
+ {#if showCounts && column.counts && column.counts[value] !== undefined}
1094
+ <span class="text-xs text-gray-500 dark:text-gray-400 ml-auto shrink-0"
1095
+ >({column.counts[value]})</span
1096
+ >
1097
+ {/if}
1098
+ </label>
1099
+ {/each}
1100
+ {:else}
1101
+ <div class="p-4 text-center text-sm text-gray-400 dark:text-gray-500">
1102
+ No values available
1103
+ </div>
1104
+ {/if}
1105
+ </div>
1106
+ {/if}
716
1107
  </div>
717
1108
  {/if}
718
1109
  </div>
@@ -747,4 +1138,88 @@
747
1138
  grid-template-columns: 1fr;
748
1139
  }
749
1140
  }
1141
+
1142
+ /* ── Dual-range slider ─────────────────────────────────────────────────── */
1143
+ .dual-range-wrapper {
1144
+ position: relative;
1145
+ height: 20px;
1146
+ display: flex;
1147
+ align-items: center;
1148
+ margin: 4px 0;
1149
+ }
1150
+
1151
+ .dual-range-track-bg {
1152
+ position: absolute;
1153
+ left: 0;
1154
+ right: 0;
1155
+ height: 4px;
1156
+ border-radius: 2px;
1157
+ background: #d1d5db; /* gray-300 */
1158
+ }
1159
+
1160
+ :global(.dark) .dual-range-track-bg {
1161
+ background: #4b5563; /* gray-600 */
1162
+ }
1163
+
1164
+ .dual-range-track-fill {
1165
+ position: absolute;
1166
+ height: 4px;
1167
+ border-radius: 2px;
1168
+ background: #60a5fa; /* blue-400 */
1169
+ pointer-events: none;
1170
+ }
1171
+
1172
+ :global(.dark) .dual-range-track-fill {
1173
+ background: #3b82f6; /* blue-500 */
1174
+ }
1175
+
1176
+ .dual-range-input {
1177
+ position: absolute;
1178
+ left: 0;
1179
+ width: 100%;
1180
+ height: 4px;
1181
+ background: none;
1182
+ pointer-events: none;
1183
+ appearance: none;
1184
+ -webkit-appearance: none;
1185
+ outline: none;
1186
+ margin: 0;
1187
+ padding: 0;
1188
+ }
1189
+
1190
+ /* Webkit thumb */
1191
+ .dual-range-input::-webkit-slider-thumb {
1192
+ -webkit-appearance: none;
1193
+ appearance: none;
1194
+ pointer-events: all;
1195
+ width: 16px;
1196
+ height: 16px;
1197
+ border-radius: 50%;
1198
+ background: #3b82f6; /* blue-500 */
1199
+ cursor: pointer;
1200
+ border: 2px solid #ffffff;
1201
+ box-shadow: 0 0 0 1px #3b82f6;
1202
+ transition: background 0.15s;
1203
+ }
1204
+
1205
+ .dual-range-input::-webkit-slider-thumb:hover {
1206
+ background: #2563eb; /* blue-600 */
1207
+ }
1208
+
1209
+ /* Firefox thumb */
1210
+ .dual-range-input::-moz-range-thumb {
1211
+ pointer-events: all;
1212
+ width: 14px;
1213
+ height: 14px;
1214
+ border-radius: 50%;
1215
+ background: #3b82f6;
1216
+ cursor: pointer;
1217
+ border: 2px solid #ffffff;
1218
+ box-shadow: 0 0 0 1px #3b82f6;
1219
+ transition: background 0.15s;
1220
+ }
1221
+
1222
+ .dual-range-input::-moz-range-thumb:hover {
1223
+ background: #2563eb;
1224
+ }
750
1225
  </style>