@zhangt58/svelte-vtable 0.1.1 → 0.1.3

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.
@@ -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] = (populateThreshold <= 0) || len <= populateThreshold;
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
- (/** @type {any} */ (filterChange))(payload);
84
+ /** @type {any} */ (filterChange)(payload);
85
85
  } catch (err) {
86
- try { console.error('filterChange threw:', err); } catch (e) {}
86
+ try {
87
+ console.error('filterChange threw:', err);
88
+ } catch (e) {}
87
89
  }
88
90
  }
89
91
 
@@ -94,11 +96,16 @@
94
96
  flushEmit();
95
97
  });
96
98
 
99
+ // Helper: is this column a date/datetime range filter?
100
+ function isDateRangeColumn(col) {
101
+ return col.type === 'daterange' || col.type === 'datetimerange';
102
+ }
103
+
97
104
  // Initialize selections from activeFilters
98
105
  $effect(() => {
99
106
  const newSelections = {};
100
107
  for (const col of columnFilters) {
101
- newSelections[col.key] = activeFilters[col.key] || [];
108
+ newSelections[col.key] = activeFilters[col.key] ?? (isDateRangeColumn(col) ? {} : []);
102
109
  }
103
110
  selections = newSelections;
104
111
  });
@@ -110,7 +117,7 @@
110
117
 
111
118
  if (current.includes(value)) {
112
119
  // Remove the value
113
- updated = current.filter(v => v !== value);
120
+ updated = current.filter((v) => v !== value);
114
121
  } else {
115
122
  // Add the value
116
123
  updated = [...current, value];
@@ -124,15 +131,17 @@
124
131
 
125
132
  // Clear all selections for a column
126
133
  function clearColumn(columnKey) {
127
- selections = { ...selections, [columnKey]: [] };
128
- scheduleEmit(columnKey, []);
134
+ const col = columnFilters.find((c) => c.key === columnKey);
135
+ const empty = isDateRangeColumn(col) ? {} : [];
136
+ selections = { ...selections, [columnKey]: empty };
137
+ scheduleEmit(columnKey, empty);
129
138
  }
130
139
 
131
140
  // Clear all filters
132
141
  function clearAllFilters() {
133
142
  const cleared = {};
134
143
  for (const col of columnFilters) {
135
- cleared[col.key] = [];
144
+ cleared[col.key] = isDateRangeColumn(col) ? {} : [];
136
145
  }
137
146
  selections = cleared;
138
147
 
@@ -142,12 +151,20 @@
142
151
 
143
152
  // Check if any filters are active
144
153
  const hasActiveFilters = $derived(() => {
145
- return Object.values(selections).some(arr => arr && arr.length > 0);
154
+ return Object.values(selections).some((val) => {
155
+ if (Array.isArray(val)) return val.length > 0;
156
+ if (val && typeof val === 'object') return !!(val.from || val.to);
157
+ return false;
158
+ });
146
159
  });
147
160
 
148
161
  // Count active filters
149
162
  const activeFilterCount = $derived(() => {
150
- return Object.values(selections).reduce((sum, arr) => sum + (arr?.length || 0), 0);
163
+ return Object.values(selections).reduce((sum, val) => {
164
+ if (Array.isArray(val)) return sum + (val?.length || 0);
165
+ if (val && typeof val === 'object' && (val.from || val.to)) return sum + 1;
166
+ return sum;
167
+ }, 0);
151
168
  });
152
169
 
153
170
  // Toggle dropdown visibility for a column
@@ -187,7 +204,7 @@
187
204
  function updateState() {
188
205
  virtualScroll = {
189
206
  ...virtualScroll,
190
- [key]: { scrollTop: node.scrollTop, height: node.clientHeight }
207
+ [key]: { scrollTop: node.scrollTop, height: node.clientHeight },
191
208
  };
192
209
  }
193
210
 
@@ -219,7 +236,7 @@
219
236
  const copy = { ...virtualScroll };
220
237
  delete copy[key];
221
238
  virtualScroll = copy;
222
- }
239
+ },
223
240
  };
224
241
  }
225
242
 
@@ -241,6 +258,17 @@
241
258
  return { slice, start, end, top, totalHeight };
242
259
  }
243
260
 
261
+ // --- Helper: extract a numeric sort key from a value ---
262
+ // Returns the number itself if numeric, the first number found in a string,
263
+ // or 0 if no number can be found.
264
+ function extractNumber(v) {
265
+ if (v === null || v === undefined) return 0;
266
+ if (typeof v === 'number') return v;
267
+ const s = String(v);
268
+ const match = s.match(/-?\d+(\.\d+)?/);
269
+ return match ? parseFloat(match[0]) : 0;
270
+ }
271
+
244
272
  // --- Helper: return the values for a column after applying search + sort ---
245
273
  function getSortedValues(column) {
246
274
  // column.uniqueValues is expected to be an array of possible values
@@ -250,7 +278,7 @@
250
278
  const q = (searchQueries[column.key] || '').toString().trim().toLowerCase();
251
279
  let filtered = raw;
252
280
  if (q) {
253
- filtered = raw.filter(v => {
281
+ filtered = raw.filter((v) => {
254
282
  const text = v === null || v === undefined ? '(empty)' : String(v);
255
283
  return text.toLowerCase().includes(q);
256
284
  });
@@ -274,6 +302,13 @@
274
302
  // fallback to name compare
275
303
  }
276
304
 
305
+ if (mode === 'number') {
306
+ const na = extractNumber(va);
307
+ const nb = extractNumber(vb);
308
+ if (na !== nb) return (na - nb) * dir;
309
+ // fallback to name compare for equal numeric values
310
+ }
311
+
277
312
  // compare by name
278
313
  const sa = va === null || va === undefined ? '(empty)' : String(va);
279
314
  const sb = vb === null || vb === undefined ? '(empty)' : String(vb);
@@ -285,7 +320,7 @@
285
320
  return a.i - b.i;
286
321
  });
287
322
 
288
- return withIndex.map(x => x.v);
323
+ return withIndex.map((x) => x.v);
289
324
  }
290
325
 
291
326
  // Toggle sort mode for a column. If the same mode is clicked again,
@@ -308,12 +343,16 @@
308
343
  const newDir = sortDirs[columnKey] || 'asc';
309
344
  try {
310
345
  // notify parent if it wants to react to sort changes
311
- (/** @type {any} */ (sortChange))({ columnKey, mode, dir: newDir });
346
+ /** @type {any} */ (sortChange)({ columnKey, mode, dir: newDir });
312
347
  } catch (err) {
313
- try { console.debug('sortChange callback threw', err); } catch (e) {}
348
+ try {
349
+ console.debug('sortChange callback threw', err);
350
+ } catch (e) {}
314
351
  }
315
352
  // debug log
316
- try { console.debug('toggleSortMode', columnKey, mode, sortDirs[columnKey]); } catch (e) {}
353
+ try {
354
+ console.debug('toggleSortMode', columnKey, mode, sortDirs[columnKey]);
355
+ } catch (e) {}
317
356
  }
318
357
 
319
358
  // Clear selection for a column (from within dropdown)
@@ -332,7 +371,7 @@
332
371
  function invertSelection(columnKey, values) {
333
372
  const current = new Set(selections[columnKey] || []);
334
373
  const next = [];
335
- for (const v of (Array.isArray(values) ? values : [])) {
374
+ for (const v of Array.isArray(values) ? values : []) {
336
375
  if (!current.has(v)) next.push(v);
337
376
  }
338
377
  selections = { ...selections, [columnKey]: next };
@@ -344,6 +383,14 @@
344
383
  clearColumn(columnKey);
345
384
  }
346
385
 
386
+ // Handle a date/datetime range input change
387
+ function handleDateRangeChange(columnKey, field, value) {
388
+ const current = selections[columnKey] || {};
389
+ const updated = { ...current, [field]: value };
390
+ selections = { ...selections, [columnKey]: updated };
391
+ scheduleEmit(columnKey, updated);
392
+ }
393
+
347
394
  // Show all dropdowns
348
395
  function showAllDropdowns() {
349
396
  const allOpen = {};
@@ -360,17 +407,20 @@
360
407
 
361
408
  // Check if all dropdowns are open
362
409
  const allDropdownsOpen = $derived.by(() => {
363
- return columnFilters.every(col => openDropdowns[col.key]);
410
+ return columnFilters.every((col) => openDropdowns[col.key]);
364
411
  });
365
412
 
366
413
  // Check if all dropdowns are closed
367
414
  const allDropdownsClosed = $derived.by(() => {
368
- return columnFilters.every(col => !openDropdowns[col.key]);
415
+ return columnFilters.every((col) => !openDropdowns[col.key]);
369
416
  });
370
417
  </script>
371
418
 
372
- <div class="p-2 bg-gray-50 rounded-md border border-gray-200 dark:bg-gray-800 dark:border-gray-700 {className}"
373
- class:horizontal={direction === 'horizontal'} class:vertical={direction === 'vertical'}>
419
+ <div
420
+ class="p-2 bg-gray-50 rounded-md border border-gray-200 dark:bg-gray-800 dark:border-gray-700 {className}"
421
+ class:horizontal={direction === 'horizontal'}
422
+ class:vertical={direction === 'vertical'}
423
+ >
374
424
  <div class="flex justify-between items-center mb-2 flex-wrap gap-1">
375
425
  <!-- Left controls: Show All, Close All -->
376
426
  <div class="flex items-center gap-1 flex-wrap">
@@ -407,9 +457,14 @@
407
457
  </div>
408
458
  </div>
409
459
 
410
- <div class="grid gap-2" class:grid-horizontal={direction === 'horizontal'} class:grid-vertical={direction === 'vertical'}>
460
+ <div
461
+ class="grid gap-2"
462
+ class:grid-horizontal={direction === 'horizontal'}
463
+ class:grid-vertical={direction === 'vertical'}
464
+ >
411
465
  {#each columnFilters as column (column.key)}
412
- {@const isActive = selections[column.key]?.length > 0}
466
+ {@const _sel = selections[column.key]}
467
+ {@const isActive = Array.isArray(_sel) ? _sel.length > 0 : !!(_sel?.from || _sel?.to)}
413
468
  {@const isOpen = openDropdowns[column.key]}
414
469
  {@const sortedValues = getSortedValues(column)}
415
470
  {@const currentSortMode = sortModes[column.key] || 'name'}
@@ -418,205 +473,384 @@
418
473
  <div class="flex flex-col min-w-0 relative">
419
474
  <button
420
475
  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 ? 'border-green-500 dark:border-green-400 bg-green-50 dark:bg-green-900/20' : ''}"
476
+ 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
477
+ ? 'border-green-500 dark:border-green-400 bg-green-50 dark:bg-green-900/20'
478
+ : ''}"
422
479
  onclick={() => toggleDropdown(column.key)}
423
480
  type="button"
424
481
  >
425
482
  <span class="flex-1 text-left whitespace-nowrap overflow-hidden text-ellipsis min-w-0">
426
- {column.label || column.key}
483
+ {column.label || column.key}
427
484
  </span>
428
485
  {#if isActive}
429
- <Badge color="green" rounded class="ml-1">{selections[column.key].length}</Badge>
486
+ {#if Array.isArray(_sel)}
487
+ <Badge color="green" rounded class="ml-1">{_sel.length}</Badge>
488
+ {:else}
489
+ <Badge color="green" rounded class="ml-1">range</Badge>
490
+ {/if}
430
491
  {/if}
431
- <ChevronDownOutline class="w-5 h-5 shrink-0 transition-transform {isOpen ? 'rotate-180' : ''}" />
492
+ <ChevronDownOutline
493
+ class="w-5 h-5 shrink-0 transition-transform {isOpen ? 'rotate-180' : ''}"
494
+ />
432
495
  </button>
433
496
 
434
497
  {#if isOpen}
435
498
  <div
436
- class={
437
- (dropdownInline
438
- ? `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`
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
- }
499
+ class={dropdownInline
500
+ ? `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`
501
+ : `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
502
  tabindex="-1"
442
503
  data-column={column.key}
443
504
  >
444
- <div class="px-1 py-1 border-b border-gray-200 dark:border-gray-600">
445
- <div class="flex items-center gap-1 w-full min-w-0">
446
- <input
447
- type="text"
448
- placeholder="Filter..."
449
- 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"
450
- bind:value={searchQueries[column.key]}
451
- />
452
-
453
- <div class="flex items-center gap-1">
505
+ {#if isDateRangeColumn(column)}
506
+ <!-- Date / datetime range picker UI -->
507
+ {@const inputType = column.type === 'datetimerange' ? 'datetime-local' : 'date'}
508
+ {@const dateRange = selections[column.key] || {}}
509
+ <div class="p-3 flex flex-col gap-2">
510
+ <div class="flex items-center gap-2">
511
+ <label
512
+ class="text-xs font-medium text-gray-500 dark:text-gray-400 w-8 shrink-0"
513
+ for="filter-{column.key}-from"
514
+ >
515
+ From
516
+ </label>
517
+ <input
518
+ id="filter-{column.key}-from"
519
+ type={inputType}
520
+ 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"
521
+ value={dateRange.from || ''}
522
+ oninput={(e) =>
523
+ handleDateRangeChange(column.key, 'from', e.currentTarget.value)}
524
+ />
525
+ </div>
526
+ <div class="flex items-center gap-2">
527
+ <label
528
+ class="text-xs font-medium text-gray-500 dark:text-gray-400 w-8 shrink-0"
529
+ for="filter-{column.key}-to"
530
+ >
531
+ To
532
+ </label>
533
+ <input
534
+ id="filter-{column.key}-to"
535
+ type={inputType}
536
+ 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"
537
+ value={dateRange.to || ''}
538
+ oninput={(e) => handleDateRangeChange(column.key, 'to', e.currentTarget.value)}
539
+ />
540
+ </div>
541
+ {#if dateRange.from || dateRange.to}
454
542
  <button
455
- 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"
456
- class:bg-blue-100={currentSortMode === 'name'}
457
- class:dark:bg-blue-900={currentSortMode === 'name'}
458
- onclick={() => toggleSortMode(column.key, 'name')}
459
- title="Sort by name"
460
543
  type="button"
544
+ class="mt-1 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"
545
+ onclick={() => clearColumn(column.key)}
461
546
  >
462
- <span class="text-sm font-semibold">Aa</span>
463
- <ArrowDownOutline
464
- class={"w-3 h-3 transition-transform " + (currentSortMode === 'name' ? 'text-blue-900 dark:text-blue-100' : 'text-gray-400 dark:text-gray-500')}
465
- style={currentSortMode === 'name' && currentSortDir === 'asc' ? 'transform: rotate(180deg);' : ''}
466
- aria-hidden="true"
467
- />
547
+ Clear range
468
548
  </button>
469
-
470
- {#if showCounts && column.counts}
549
+ {/if}
550
+ </div>
551
+ {:else}
552
+ <!-- Value-selection filter UI (checkboxes) -->
553
+ <div class="px-1 py-1 border-b border-gray-200 dark:border-gray-600">
554
+ <div class="flex items-center gap-1 w-full min-w-0">
555
+ <input
556
+ type="text"
557
+ placeholder="Filter..."
558
+ 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"
559
+ bind:value={searchQueries[column.key]}
560
+ />
561
+
562
+ <div class="flex items-center gap-1">
471
563
  <button
472
564
  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"
473
- class:bg-blue-100={currentSortMode === 'count'}
474
- class:dark:bg-blue-900={currentSortMode === 'count'}
475
- onclick={() => toggleSortMode(column.key, 'count')}
476
- title="Sort by count"
565
+ class:bg-blue-100={currentSortMode === 'name'}
566
+ class:dark:bg-blue-900={currentSortMode === 'name'}
567
+ onclick={() => toggleSortMode(column.key, 'name')}
568
+ title="Sort by name"
477
569
  type="button"
478
570
  >
479
- <span class="text-sm font-semibold">#</span>
571
+ <span
572
+ class="flex flex-col items-center leading-none font-semibold"
573
+ style="font-size:0.6rem;"
574
+ >
575
+ <span>A</span>
576
+ <span>Z</span>
577
+ </span>
480
578
  <ArrowDownOutline
481
- class={"w-3 h-3 transition-transform " + (currentSortMode === 'count' ? 'text-blue-900 dark:text-blue-100' : 'text-gray-400 dark:text-gray-500')}
482
- style={currentSortMode === 'count' && currentSortDir === 'asc' ? 'transform: rotate(180deg);' : ''}
579
+ class={'w-3 h-3 transition-transform ' +
580
+ (currentSortMode === 'name'
581
+ ? 'text-blue-900 dark:text-blue-100'
582
+ : 'text-gray-400 dark:text-gray-500')}
583
+ style={currentSortMode === 'name' && currentSortDir === 'asc'
584
+ ? 'transform: rotate(180deg);'
585
+ : ''}
483
586
  aria-hidden="true"
484
587
  />
485
588
  </button>
486
- {/if}
487
589
 
590
+ <button
591
+ 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"
592
+ class:bg-blue-100={currentSortMode === 'number'}
593
+ class:dark:bg-blue-900={currentSortMode === 'number'}
594
+ onclick={() => toggleSortMode(column.key, 'number')}
595
+ title="Sort by number"
596
+ aria-label="Sort by number"
597
+ type="button"
598
+ >
599
+ <span
600
+ class="flex flex-col items-center leading-none font-semibold"
601
+ style="font-size:0.6rem;"
602
+ >
603
+ <span>0</span>
604
+ <span>9</span>
605
+ </span>
606
+ <ArrowDownOutline
607
+ class={'w-3 h-3 transition-transform ' +
608
+ (currentSortMode === 'number'
609
+ ? 'text-blue-900 dark:text-blue-100'
610
+ : 'text-gray-400 dark:text-gray-500')}
611
+ style={currentSortMode === 'number' && currentSortDir === 'asc'
612
+ ? 'transform: rotate(180deg);'
613
+ : ''}
614
+ aria-hidden="true"
615
+ />
616
+ </button>
488
617
 
618
+ {#if showCounts && column.counts}
619
+ <button
620
+ 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"
621
+ class:bg-blue-100={currentSortMode === 'count'}
622
+ class:dark:bg-blue-900={currentSortMode === 'count'}
623
+ onclick={() => toggleSortMode(column.key, 'count')}
624
+ title="Sort by count"
625
+ type="button"
626
+ >
627
+ <span class="text-sm font-semibold">#</span>
628
+ <ArrowDownOutline
629
+ class={'w-3 h-3 transition-transform ' +
630
+ (currentSortMode === 'count'
631
+ ? 'text-blue-900 dark:text-blue-100'
632
+ : 'text-gray-400 dark:text-gray-500')}
633
+ style={currentSortMode === 'count' && currentSortDir === 'asc'
634
+ ? 'transform: rotate(180deg);'
635
+ : ''}
636
+ aria-hidden="true"
637
+ />
638
+ </button>
639
+ {/if}
640
+ </div>
489
641
  </div>
490
-
491
642
  </div>
492
- </div>
493
643
 
494
- <!-- Action row: Check all / Invert / Uncheck all (icon buttons) -->
495
- <div class="px-2 py-1 border-b border-gray-100 dark:border-gray-600">
496
- <div class="flex items-center justify-between">
497
- <div class="flex items-center gap-1">
498
- <button
499
- type="button"
500
- 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"
501
- onclick={() => checkAll(column.key, sortedValues)}
502
- disabled={sortedValues.length === 0}
503
- aria-label="Check all"
504
- title="Check all"
505
- >
506
- <!-- Checked square icon (higher contrast) -->
507
- <svg class="w-4 h-4 text-gray-800 dark:text-white" viewBox="0 0 24 24" fill="none" aria-hidden="true">
508
- <rect x="3" y="3" width="18" height="18" rx="2" stroke="currentColor" stroke-width="2.5" fill="none" />
509
- <path d="M7 13l3 3 7-7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="none" />
510
- </svg>
511
- <span class="text-sm text-gray-800 dark:text-gray-100 select-none">All</span>
512
- </button>
644
+ <!-- Action row: Check all / Invert / Uncheck all (icon buttons) -->
645
+ <div class="px-2 py-1 border-b border-gray-100 dark:border-gray-600">
646
+ <div class="flex items-center justify-between">
647
+ <div class="flex items-center gap-1">
648
+ <button
649
+ type="button"
650
+ 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"
651
+ onclick={() => checkAll(column.key, sortedValues)}
652
+ disabled={sortedValues.length === 0}
653
+ aria-label="Check all"
654
+ title="Check all"
655
+ >
656
+ <!-- Checked square icon (higher contrast) -->
657
+ <svg
658
+ class="w-4 h-4 text-gray-800 dark:text-white"
659
+ viewBox="0 0 24 24"
660
+ fill="none"
661
+ aria-hidden="true"
662
+ >
663
+ <rect
664
+ x="3"
665
+ y="3"
666
+ width="18"
667
+ height="18"
668
+ rx="2"
669
+ stroke="currentColor"
670
+ stroke-width="2.5"
671
+ fill="none"
672
+ />
673
+ <path
674
+ d="M7 13l3 3 7-7"
675
+ stroke="currentColor"
676
+ stroke-width="2"
677
+ stroke-linecap="round"
678
+ stroke-linejoin="round"
679
+ fill="none"
680
+ />
681
+ </svg>
682
+ <span class="text-sm text-gray-800 dark:text-gray-100 select-none">All</span>
683
+ </button>
513
684
 
514
- <button
515
- type="button"
516
- 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"
517
- onclick={() => invertSelection(column.key, sortedValues)}
518
- disabled={sortedValues.length === 0}
519
- aria-label="Invert selection"
520
- title="Invert selection"
521
- >
522
- <!-- Half-checked square icon (left half filled) - higher contrast -->
523
- <svg class="w-4 h-4 text-gray-800 dark:text-white" viewBox="0 0 24 24" fill="none" aria-hidden="true">
524
- <rect x="3" y="3" width="18" height="18" rx="2" stroke="currentColor" stroke-width="2.5" fill="none" />
525
- <rect x="4" y="4" width="8.5" height="16" fill="currentColor" opacity="0.28" stroke="none" />
526
- <path d="M7 13l3 3 7-7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="none" />
527
- </svg>
528
- <span class="text-sm text-gray-800 dark:text-gray-100 select-none">Invert</span>
529
- </button>
685
+ <button
686
+ type="button"
687
+ 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"
688
+ onclick={() => invertSelection(column.key, sortedValues)}
689
+ disabled={sortedValues.length === 0}
690
+ aria-label="Invert selection"
691
+ title="Invert selection"
692
+ >
693
+ <!-- Half-checked square icon (left half filled) - higher contrast -->
694
+ <svg
695
+ class="w-4 h-4 text-gray-800 dark:text-white"
696
+ viewBox="0 0 24 24"
697
+ fill="none"
698
+ aria-hidden="true"
699
+ >
700
+ <rect
701
+ x="3"
702
+ y="3"
703
+ width="18"
704
+ height="18"
705
+ rx="2"
706
+ stroke="currentColor"
707
+ stroke-width="2.5"
708
+ fill="none"
709
+ />
710
+ <rect
711
+ x="4"
712
+ y="4"
713
+ width="8.5"
714
+ height="16"
715
+ fill="currentColor"
716
+ opacity="0.28"
717
+ stroke="none"
718
+ />
719
+ <path
720
+ d="M7 13l3 3 7-7"
721
+ stroke="currentColor"
722
+ stroke-width="2"
723
+ stroke-linecap="round"
724
+ stroke-linejoin="round"
725
+ fill="none"
726
+ />
727
+ </svg>
728
+ <span class="text-sm text-gray-800 dark:text-gray-100 select-none"
729
+ >Invert</span
730
+ >
731
+ </button>
530
732
 
531
- <button
532
- type="button"
533
- 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"
534
- onclick={() => checkNone(column.key)}
535
- disabled={sortedValues.length === 0}
536
- aria-label="Uncheck all"
537
- title="Uncheck all"
538
- >
539
- <!-- Empty square icon (higher contrast stroke) -->
540
- <svg class="w-4 h-4 text-gray-800 dark:text-white" viewBox="0 0 24 24" fill="none" aria-hidden="true">
541
- <rect x="3" y="3" width="18" height="18" rx="2" stroke="currentColor" stroke-width="2" fill="none" />
542
- </svg>
543
- <span class="text-sm text-gray-800 dark:text-gray-100 select-none">None</span>
544
- </button>
545
- </div>
733
+ <button
734
+ type="button"
735
+ 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"
736
+ onclick={() => checkNone(column.key)}
737
+ disabled={sortedValues.length === 0}
738
+ aria-label="Uncheck all"
739
+ title="Uncheck all"
740
+ >
741
+ <!-- Empty square icon (higher contrast stroke) -->
742
+ <svg
743
+ class="w-4 h-4 text-gray-800 dark:text-white"
744
+ viewBox="0 0 24 24"
745
+ fill="none"
746
+ aria-hidden="true"
747
+ >
748
+ <rect
749
+ x="3"
750
+ y="3"
751
+ width="18"
752
+ height="18"
753
+ rx="2"
754
+ stroke="currentColor"
755
+ stroke-width="2"
756
+ fill="none"
757
+ />
758
+ </svg>
759
+ <span class="text-sm text-gray-800 dark:text-gray-100 select-none">None</span>
760
+ </button>
761
+ </div>
546
762
 
547
- <div class="pr-1">
548
- <Badge color="blue" rounded title="Total options">{sortedValues.length}</Badge>
763
+ <div class="pr-1">
764
+ <Badge color="blue" rounded title="Total options">{sortedValues.length}</Badge>
765
+ </div>
549
766
  </div>
550
767
  </div>
551
- </div>
552
768
 
553
- <div class="p-1 overflow-y-auto flex-1" use:registerList={{ key: column.key }}>
554
- {#if sortedValues.length > populateThreshold && !loadedOptions[column.key]}
555
- <div class="p-1 text-sm text-gray-700 dark:text-gray-200">
556
- Too many options ({sortedValues.length}) to render by default.
557
- <button
558
- 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
- type="button"
560
- onclick={() => loadedOptions = { ...loadedOptions, [column.key]: true }}
561
- >
562
- Load options
563
- </button>
564
- </div>
565
- {:else}
566
- {#if sortedValues.length > virtualThreshold}
769
+ <div
770
+ class="p-1 overflow-y-auto flex-1 max-h-48"
771
+ use:registerList={{ key: column.key }}
772
+ >
773
+ {#if sortedValues.length > populateThreshold && !loadedOptions[column.key]}
774
+ <div class="p-1 text-sm text-gray-700 dark:text-gray-200">
775
+ Too many options ({sortedValues.length}) to render by default.
776
+ <button
777
+ 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"
778
+ type="button"
779
+ onclick={() => (loadedOptions = { ...loadedOptions, [column.key]: true })}
780
+ >
781
+ Load options
782
+ </button>
783
+ </div>
784
+ {:else if sortedValues.length > virtualThreshold}
567
785
  {@const v = getVirtualSlice(column, sortedValues)}
568
786
 
569
787
  <div style="height:{v.totalHeight}px; position:relative;">
570
788
  <div style="position:absolute; top:{v.top}px; left:0; right:0;">
571
789
  {#each v.slice as value, idx (idx)}
572
790
  {@const isSelected = selections[column.key]?.includes(value)}
573
- {@const displayValue = value === null || value === undefined ? '(empty)' : String(value)}
791
+ {@const displayValue =
792
+ value === null || value === undefined ? '(empty)' : String(value)}
574
793
 
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;">
794
+ <label
795
+ 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"
796
+ style="height:{virtualItemHeight}px; box-sizing:border-box;"
797
+ >
576
798
  <input
577
799
  type="checkbox"
578
800
  checked={isSelected}
579
801
  onchange={() => toggleSelection(column.key, value)}
580
802
  class="w-4 h-4 shrink-0 cursor-pointer accent-blue-500"
581
803
  />
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>
804
+ <span
805
+ class="flex-1 text-sm text-gray-700 dark:text-gray-300 select-none min-w-0 overflow-hidden text-ellipsis"
806
+ >{displayValue}</span
807
+ >
583
808
  {#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>
809
+ <span class="text-xs text-gray-500 dark:text-gray-400 ml-auto shrink-0"
810
+ >({column.counts[value]})</span
811
+ >
585
812
  {/if}
586
813
  </label>
587
814
  {/each}
588
815
  </div>
589
816
  </div>
590
-
817
+ {:else if sortedValues.length > 0}
818
+ {#each sortedValues as value, idx (idx)}
819
+ {@const isSelected = selections[column.key]?.includes(value)}
820
+ {@const displayValue =
821
+ value === null || value === undefined ? '(empty)' : String(value)}
822
+
823
+ <label
824
+ 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"
825
+ >
826
+ <input
827
+ type="checkbox"
828
+ checked={isSelected}
829
+ onchange={() => toggleSelection(column.key, value)}
830
+ class="w-4 h-4 shrink-0 cursor-pointer accent-blue-500"
831
+ />
832
+ <span
833
+ class="flex-1 text-sm text-gray-700 dark:text-gray-300 select-none min-w-0 overflow-hidden text-ellipsis"
834
+ >{displayValue}</span
835
+ >
836
+ {#if showCounts && column.counts && column.counts[value] !== undefined}
837
+ <span class="text-xs text-gray-500 dark:text-gray-400 ml-auto shrink-0"
838
+ >({column.counts[value]})</span
839
+ >
840
+ {/if}
841
+ </label>
842
+ {/each}
591
843
  {:else}
592
- {#if sortedValues.length > 0}
593
- {#each sortedValues as value, idx (idx)}
594
- {@const isSelected = selections[column.key]?.includes(value)}
595
- {@const displayValue = value === null || value === undefined ? '(empty)' : String(value)}
596
-
597
- <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">
598
- <input
599
- type="checkbox"
600
- checked={isSelected}
601
- onchange={() => toggleSelection(column.key, value)}
602
- class="w-4 h-4 shrink-0 cursor-pointer accent-blue-500"
603
- />
604
- <span class="flex-1 text-sm text-gray-700 dark:text-gray-300 select-none min-w-0 overflow-hidden text-ellipsis">{displayValue}</span>
605
- {#if showCounts && column.counts && column.counts[value] !== undefined}
606
- <span class="text-xs text-gray-500 dark:text-gray-400 ml-auto shrink-0">({column.counts[value]})</span>
607
- {/if}
608
- </label>
609
- {/each}
610
- {:else}
611
- <div class="p-4 text-center text-sm text-gray-400 dark:text-gray-500">No values available</div>
612
- {/if}
844
+ <div class="p-4 text-center text-sm text-gray-400 dark:text-gray-500">
845
+ No values available
846
+ </div>
613
847
  {/if}
614
- {/if}
615
- </div>
848
+ </div>
849
+ {/if}
616
850
  </div>
617
851
  {/if}
618
- </div>
619
- {/each}
852
+ </div>
853
+ {/each}
620
854
  </div>
621
855
  </div>
622
856