@zhangt58/svelte-vtable 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,44 +1,25 @@
1
1
  <script>
2
2
  import { Badge } from 'flowbite-svelte';
3
- import { ChevronDownOutline, ArrowDownOutline } from 'flowbite-svelte-icons';
4
- import { onDestroy } from 'svelte';
3
+ import { useFilterState } from './filters/useFilterState.svelte.js';
4
+ import FilterColumn from './filters/FilterColumn.svelte';
5
+ import FilterValueList from './filters/FilterValueList.svelte';
6
+ import FilterDateRange from './filters/FilterDateRange.svelte';
5
7
 
6
- // shared default no-op function
7
- const DEFAULT_NOOP = (..._args) => {};
8
-
9
- // Props using Svelte 5 $props()
10
8
  let {
11
- // columnFilters: array of { key, label, uniqueValues }
12
- // where uniqueValues is an array of unique values for that column
13
9
  columnFilters = [],
14
- // layout direction: 'horizontal' or 'vertical'
15
10
  direction = 'horizontal',
16
- // current active filters: { columnKey: [selectedValues] }
17
11
  activeFilters = {},
18
- // Callback when filters change
19
- filterChange = DEFAULT_NOOP,
20
- // Optional callback when sort mode/dir changes: ( { columnKey, mode, dir } )
21
- sortChange = DEFAULT_NOOP,
22
- // CSS class for the container
12
+ onfilter = undefined,
13
+ oncolumnsort = undefined,
23
14
  className = '',
24
- // Whether to show filter counts
25
15
  showCounts = true,
26
- // Virtualization props (defaults)
27
16
  virtualThreshold = 500,
28
17
  virtualItemHeight = 36,
29
18
  virtualOverscan = 5,
30
- // Debounce milliseconds for emitting filterChange (0 = immediate)
31
19
  emitDebounce = 100,
32
- // If the number of options exceeds this threshold, the options are not generated by default
33
- // and the user must click "Load options" to populate them. Set to 0 to always populate.
34
20
  populateThreshold = 200,
35
- // If true, render dropdowns inline (in-flow) so opening them expands the parent container.
36
- // If false, render as absolutely-positioned overlays (old behavior).
37
21
  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}>} */ ([
22
+ relativeRangePresets = [
42
23
  { label: '1h', value: 1, unit: 'hour' },
43
24
  { label: '6h', value: 6, unit: 'hour' },
44
25
  { label: '12h', value: 12, unit: 'hour' },
@@ -46,473 +27,51 @@
46
27
  { label: '7d', value: 7, unit: 'day' },
47
28
  { label: '30d', value: 30, unit: 'day' },
48
29
  { label: '1y', value: 1, unit: 'year' },
49
- ]),
30
+ ],
50
31
  } = $props();
51
32
 
52
- // Internal state for selected options per column
53
- let selections = $state({});
54
-
55
- // Track whether options have been loaded (populated) per-column when the list is large
56
- let loadedOptions = $state({});
57
-
58
- // Auto-enable loading for small lists when columnFilters change
59
- $effect(() => {
60
- const initial = {};
61
- for (const col of columnFilters) {
62
- const len = Array.isArray(col.uniqueValues) ? col.uniqueValues.length : 0;
63
- initial[col.key] = populateThreshold <= 0 || len <= populateThreshold;
64
- }
65
- loadedOptions = initial;
66
- });
67
-
68
- // --- Debounced emission helpers ---
69
- let _emitTimer = null;
70
- let _pendingEmit = null;
71
-
72
- function scheduleEmit(columnKey, selectedValues) {
73
- // capture latest state snapshot
74
- _pendingEmit = { columnKey, selectedValues, allFilters: selections };
75
-
76
- if (!emitDebounce || emitDebounce <= 0) {
77
- // immediate
78
- flushEmit();
79
- return;
80
- }
81
-
82
- if (_emitTimer) clearTimeout(_emitTimer);
83
- _emitTimer = setTimeout(() => flushEmit(), emitDebounce);
84
- }
85
-
86
- function flushEmit() {
87
- if (!_pendingEmit) return;
88
- const payload = _pendingEmit;
89
- _pendingEmit = null;
90
- if (_emitTimer) {
91
- clearTimeout(_emitTimer);
92
- _emitTimer = null;
93
- }
94
-
95
- try {
96
- /** @type {any} */ (filterChange)(payload);
97
- } catch (err) {
98
- try {
99
- console.error('filterChange threw:', err);
100
- } catch (e) {}
101
- }
102
- }
103
-
104
- // cleanup on destroy to avoid timers running after unmount
105
- onDestroy(() => {
106
- if (_emitTimer) clearTimeout(_emitTimer);
107
- // flush any pending emit synchronously
108
- flushEmit();
109
- });
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
-
116
- // Initialize selections from activeFilters
117
- $effect(() => {
118
- const newSelections = {};
119
- for (const col of columnFilters) {
120
- newSelections[col.key] = activeFilters[col.key] ?? (isDateRangeColumn(col) ? {} : []);
121
- }
122
- selections = newSelections;
123
- });
124
-
125
- // Toggle selection for a specific column and value
126
- function toggleSelection(columnKey, value) {
127
- const current = selections[columnKey] || [];
128
- let updated;
129
-
130
- if (current.includes(value)) {
131
- // Remove the value
132
- updated = current.filter((v) => v !== value);
133
- } else {
134
- // Add the value
135
- updated = [...current, value];
136
- }
137
-
138
- selections = { ...selections, [columnKey]: updated };
139
-
140
- // Schedule debounced filter change emission
141
- scheduleEmit(columnKey, updated);
142
- }
143
-
144
- // Clear all selections for a column
145
- function clearColumn(columnKey) {
146
- const col = columnFilters.find((c) => c.key === columnKey);
147
- const empty = isDateRangeColumn(col) ? {} : [];
148
- selections = { ...selections, [columnKey]: empty };
149
- scheduleEmit(columnKey, empty);
150
- }
151
-
152
- // Clear all filters
153
- function clearAllFilters() {
154
- const cleared = {};
155
- for (const col of columnFilters) {
156
- cleared[col.key] = isDateRangeColumn(col) ? {} : [];
157
- }
158
- selections = cleared;
159
-
160
- // emit after debounce (columnKey null indicates global clear)
161
- scheduleEmit(null, []);
162
- }
163
-
164
- // Check if any filters are active
165
- const hasActiveFilters = $derived(() => {
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
- });
33
+ const fs = useFilterState({
34
+ columnFilters: () => columnFilters,
35
+ activeFilters: () => activeFilters,
36
+ emitDebounce: () => emitDebounce,
37
+ onfilter: () => onfilter,
171
38
  });
172
39
 
173
- // Count active filters
174
- const activeFilterCount = $derived(() => {
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);
180
- });
181
-
182
- // Toggle dropdown visibility for a column
183
40
  let openDropdowns = $state({});
184
-
185
- // Simple toggle/close functions — dropdowns are controlled only by their
186
- // toggle button and programmatic calls (e.g. Show All / Collapse All).
187
- function toggleDropdown(columnKey) {
188
- const wasOpen = openDropdowns[columnKey];
189
- openDropdowns = { ...openDropdowns, [columnKey]: !wasOpen };
190
- }
191
-
192
- // Sorting state for each column's dropdown
193
- let sortModes = $state({});
194
- // Per-column sort direction: 'asc' or 'desc'
195
- let sortDirs = $state({});
196
-
197
- // Inline header search queries per column (small text filter for options)
198
- let searchQueries = $state({});
199
-
200
- // --- Virtualization settings and state ---
201
- // (virtual props are provided via the main $props() destructure above)
202
-
203
- // DOM refs for per-column scroll containers
204
- let listRefs = $state({});
205
-
206
- // Per-column scroll state: { scrollTop, height }
207
- let virtualScroll = $state({});
208
-
209
- // Svelte action to register list containers and keep virtualScroll updated
210
- function registerList(node, params) {
211
- const key = params && params.key;
212
- if (!key) return { destroy() {} };
213
-
214
- listRefs = { ...listRefs, [key]: node };
215
-
216
- function updateState() {
217
- virtualScroll = {
218
- ...virtualScroll,
219
- [key]: { scrollTop: node.scrollTop, height: node.clientHeight },
220
- };
221
- }
222
-
223
- // initialize
224
- updateState();
225
-
226
- const onScroll = () => updateState();
227
- const onResize = () => updateState();
228
-
229
- node.addEventListener('scroll', onScroll);
230
- // Observe size changes (in case container height changes)
231
- const ro = new ResizeObserver(onResize);
232
- ro.observe(node);
233
-
234
- return {
235
- update(newParams) {
236
- // allow key to be updated (unlikely)
237
- if (!newParams || newParams.key !== key) {
238
- node.removeEventListener('scroll', onScroll);
239
- ro.disconnect();
240
- delete listRefs[key];
241
- }
242
- },
243
- destroy() {
244
- node.removeEventListener('scroll', onScroll);
245
- ro.disconnect();
246
- delete listRefs[key];
247
- // remove virtualScroll entry
248
- const copy = { ...virtualScroll };
249
- delete copy[key];
250
- virtualScroll = copy;
251
- },
252
- };
253
- }
254
-
255
- // Compute virtual slice for a column when the values exceed threshold
256
- function getVirtualSlice(column, values) {
257
- if (!values || values.length <= virtualThreshold) return null;
258
- const vs = virtualScroll[column.key] || { scrollTop: 0, height: 200 };
259
- const itemH = virtualItemHeight;
260
- const height = vs.height || 200;
261
- const overscan = virtualOverscan;
262
-
263
- const start = Math.max(0, Math.floor(vs.scrollTop / itemH) - overscan);
264
- const visibleCount = Math.ceil(height / itemH) + overscan * 2;
265
- const end = Math.min(values.length, start + visibleCount);
266
- const slice = values.slice(start, end);
267
- const top = start * itemH;
268
- const totalHeight = values.length * itemH;
269
-
270
- return { slice, start, end, top, totalHeight };
271
- }
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
-
284
- // --- Helper: return the values for a column after applying search + sort ---
285
- function getSortedValues(column) {
286
- // column.uniqueValues is expected to be an array of possible values
287
- const raw = Array.isArray(column.uniqueValues) ? column.uniqueValues.slice() : [];
288
-
289
- // apply search filter if present
290
- const q = (searchQueries[column.key] || '').toString().trim().toLowerCase();
291
- let filtered = raw;
292
- if (q) {
293
- filtered = raw.filter((v) => {
294
- const text = v === null || v === undefined ? '(empty)' : String(v);
295
- return text.toLowerCase().includes(q);
296
- });
297
- }
298
-
299
- // determine sort mode and direction
300
- const mode = sortModes[column.key] || 'name';
301
- const dir = (sortDirs[column.key] || 'asc') === 'asc' ? 1 : -1;
302
-
303
- // stable sort: map-index technique
304
- const withIndex = filtered.map((v, i) => ({ v, i }));
305
-
306
- withIndex.sort((a, b) => {
307
- const va = a.v;
308
- const vb = b.v;
309
-
310
- if (mode === 'count' && column.counts) {
311
- const ca = Number(column.counts[va] ?? 0);
312
- const cb = Number(column.counts[vb] ?? 0);
313
- if (ca !== cb) return (ca - cb) * dir * -1; // higher counts first when desc
314
- // fallback to name compare
315
- }
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
-
324
- // compare by name
325
- const sa = va === null || va === undefined ? '(empty)' : String(va);
326
- const sb = vb === null || vb === undefined ? '(empty)' : String(vb);
327
- const la = sa.toLowerCase();
328
- const lb = sb.toLowerCase();
329
- if (la < lb) return -1 * dir;
330
- if (la > lb) return 1 * dir;
331
- // maintain stable order
332
- return a.i - b.i;
333
- });
334
-
335
- return withIndex.map((x) => x.v);
336
- }
337
-
338
- // Toggle sort mode for a column. If the same mode is clicked again,
339
- // flip the direction; otherwise set the mode and default to 'desc'.
340
- function toggleSortMode(columnKey, mode) {
341
- const prevMode = sortModes[columnKey];
342
- if (prevMode === mode) {
343
- // flip direction
344
- const prevDir = sortDirs[columnKey] || 'desc';
345
- const nextDir = prevDir === 'asc' ? 'desc' : 'asc';
346
- sortDirs = { ...sortDirs, [columnKey]: nextDir };
347
- } else {
348
- sortModes = { ...sortModes, [columnKey]: mode };
349
- // default first click to descending (common expectation for counts)
350
- sortDirs = { ...sortDirs, [columnKey]: 'desc' };
351
- }
352
- // ensure the mode is set (for first-time clicks)
353
- sortModes = { ...sortModes, [columnKey]: mode };
354
-
355
- const newDir = sortDirs[columnKey] || 'asc';
41
+ const toggle = (key) => (openDropdowns = { ...openDropdowns, [key]: !openDropdowns[key] });
42
+ const showAll = () => {
43
+ const a = {};
44
+ for (const c of columnFilters) a[c.key] = true;
45
+ openDropdowns = a;
46
+ };
47
+ const closeAll = () => (openDropdowns = {});
48
+
49
+ const allOpen = $derived(columnFilters.every((c) => openDropdowns[c.key]));
50
+ const allClosed = $derived(columnFilters.every((c) => !openDropdowns[c.key]));
51
+ const isDateRange = (col) => col.type === 'daterange' || col.type === 'datetimerange';
52
+
53
+ const hasActive = $derived(
54
+ Object.values(fs.selections).some((v) =>
55
+ Array.isArray(v) ? v.length > 0 : !!(v?.from || v?.to),
56
+ ),
57
+ );
58
+ const activeCount = $derived(
59
+ Object.values(fs.selections).reduce((s, v) => {
60
+ if (Array.isArray(v)) return s + (v?.length || 0);
61
+ if (v && typeof v === 'object' && (v.from || v.to)) return s + 1;
62
+ return s;
63
+ }, 0),
64
+ );
65
+
66
+ function handleSortChange(columnKey, { mode, dir }) {
356
67
  try {
357
- // notify parent if it wants to react to sort changes
358
- /** @type {any} */ (sortChange)({ columnKey, mode, dir: newDir });
68
+ if (oncolumnsort) /** @type {any} */ (oncolumnsort)({ key: columnKey, mode, dir });
359
69
  } catch (err) {
360
70
  try {
361
- console.debug('sortChange callback threw', err);
71
+ console.debug('oncolumnsort threw', err);
362
72
  } catch (e) {}
363
73
  }
364
- // debug log
365
- try {
366
- console.debug('toggleSortMode', columnKey, mode, sortDirs[columnKey]);
367
- } catch (e) {}
368
74
  }
369
-
370
- // Clear selection for a column (from within dropdown)
371
- function clearSelection(columnKey) {
372
- clearColumn(columnKey);
373
- }
374
-
375
- // Check all values for a column
376
- function checkAll(columnKey, values) {
377
- const all = Array.isArray(values) ? values.slice() : [];
378
- selections = { ...selections, [columnKey]: all };
379
- scheduleEmit(columnKey, all);
380
- }
381
-
382
- // Invert selection for a column (values is the full option list)
383
- function invertSelection(columnKey, values) {
384
- const current = new Set(selections[columnKey] || []);
385
- const next = [];
386
- for (const v of Array.isArray(values) ? values : []) {
387
- if (!current.has(v)) next.push(v);
388
- }
389
- selections = { ...selections, [columnKey]: next };
390
- scheduleEmit(columnKey, next);
391
- }
392
-
393
- // Uncheck all -> reuse clearColumn
394
- function checkNone(columnKey) {
395
- clearColumn(columnKey);
396
- }
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
-
493
- // Show all dropdowns
494
- function showAllDropdowns() {
495
- const allOpen = {};
496
- for (const col of columnFilters) {
497
- allOpen[col.key] = true;
498
- }
499
- openDropdowns = allOpen;
500
- }
501
-
502
- // Collapse all dropdowns
503
- function collapseAllDropdowns() {
504
- openDropdowns = {};
505
- }
506
-
507
- // Check if all dropdowns are open
508
- const allDropdownsOpen = $derived.by(() => {
509
- return columnFilters.every((col) => openDropdowns[col.key]);
510
- });
511
-
512
- // Check if all dropdowns are closed
513
- const allDropdownsClosed = $derived.by(() => {
514
- return columnFilters.every((col) => !openDropdowns[col.key]);
515
- });
516
75
  </script>
517
76
 
518
77
  <div
@@ -521,37 +80,39 @@
521
80
  class:vertical={direction === 'vertical'}
522
81
  >
523
82
  <div class="flex justify-between items-center mb-2 flex-wrap gap-1">
524
- <!-- Left controls: Show All, Close All -->
525
83
  <div class="flex items-center gap-1 flex-wrap">
526
84
  <button
527
- class="px-3 py-1 text-sm text-green-600 bg-transparent border border-green-600 rounded-md hover:bg-green-600 hover:text-white transition-all cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-green-600"
528
- disabled={allDropdownsOpen}
529
- onclick={showAllDropdowns}
530
- title="Show all filter dropdowns"
85
+ class="px-3 py-1 text-sm bg-transparent border rounded-md transition-all cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed"
86
+ style="color: var(--vtable-color-accent); border-color: var(--vtable-color-accent);"
87
+ disabled={allOpen}
88
+ onclick={showAll}
89
+ onmouseenter={(e) => {
90
+ if (!e.currentTarget.disabled) {
91
+ e.currentTarget.style.backgroundColor = 'var(--vtable-color-accent)';
92
+ e.currentTarget.style.color = '#fff';
93
+ }
94
+ }}
95
+ onmouseleave={(e) => {
96
+ e.currentTarget.style.backgroundColor = '';
97
+ e.currentTarget.style.color = 'var(--vtable-color-accent)';
98
+ }}
99
+ title="Show all filter dropdowns">Show All</button
531
100
  >
532
- Show All
533
- </button>
534
101
  <button
535
102
  class="px-3 py-1 text-sm text-gray-600 bg-transparent border border-gray-600 rounded-md hover:bg-gray-600 hover:text-white transition-all cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-gray-600"
536
- disabled={allDropdownsClosed}
537
- onclick={collapseAllDropdowns}
538
- title="Close all filter dropdowns"
103
+ disabled={allClosed}
104
+ onclick={closeAll}
105
+ title="Close all filter dropdowns">Close All</button
539
106
  >
540
- Close All
541
- </button>
542
107
  </div>
543
-
544
- <!-- Right controls: active badge and Clear All -->
545
108
  <div class="flex items-center gap-2 flex-wrap">
546
- {#if hasActiveFilters()}
547
- <Badge color="blue" rounded>{activeFilterCount()} active</Badge>
109
+ {#if hasActive}
110
+ <Badge color="blue" rounded>{activeCount} active</Badge>
548
111
  <button
549
112
  class="px-3 py-1 text-sm text-red-600 bg-transparent border border-red-600 rounded-md hover:bg-red-600 hover:text-white transition-all cursor-pointer"
550
- onclick={clearAllFilters}
551
- title="Clear all filters"
113
+ onclick={fs.clearAllFilters}
114
+ title="Clear all filters">Clear All</button
552
115
  >
553
- Clear All
554
- </button>
555
116
  {/if}
556
117
  </div>
557
118
  </div>
@@ -562,547 +123,52 @@
562
123
  class:grid-vertical={direction === 'vertical'}
563
124
  >
564
125
  {#each columnFilters as column (column.key)}
565
- {@const _sel = selections[column.key]}
566
- {@const isActive = Array.isArray(_sel) ? _sel.length > 0 : !!(_sel?.from || _sel?.to)}
567
- {@const isOpen = openDropdowns[column.key]}
568
- {@const sortedValues = getSortedValues(column)}
569
- {@const currentSortMode = sortModes[column.key] || 'name'}
570
- {@const currentSortDir = sortDirs[column.key] || 'asc'}
571
-
126
+ {@const sel = fs.selections[column.key]}
127
+ {@const isActive = Array.isArray(sel) ? sel.length > 0 : !!(sel?.from || sel?.to)}
128
+ {@const isOpen = !!openDropdowns[column.key]}
572
129
  <div class="flex flex-col min-w-0 relative">
573
- <button
574
- id="filter-{column.key}"
575
- 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
576
- ? 'border-green-500 dark:border-green-400 bg-green-50 dark:bg-green-900/20'
577
- : ''}"
578
- onclick={() => toggleDropdown(column.key)}
579
- type="button"
580
- >
581
- <span class="flex-1 text-left whitespace-nowrap overflow-hidden text-ellipsis min-w-0">
582
- {column.label || column.key}
583
- </span>
584
- {#if isActive}
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}
590
- {/if}
591
- <ChevronDownOutline
592
- class="w-5 h-5 shrink-0 transition-transform {isOpen ? 'rotate-180' : ''}"
593
- />
594
- </button>
595
-
130
+ <FilterColumn
131
+ {column}
132
+ {isOpen}
133
+ {isActive}
134
+ selection={sel}
135
+ ontoggle={() => toggle(column.key)}
136
+ />
596
137
  {#if isOpen}
597
138
  <div
598
139
  class={[
599
140
  dropdownInline ? '' : 'absolute top-full left-0 right-0',
600
141
  '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',
142
+ isDateRange(column) ? 'overflow-y-auto' : 'max-h-64',
602
143
  ]
603
144
  .filter(Boolean)
604
145
  .join(' ')}
605
146
  tabindex="-1"
606
147
  data-column={column.key}
607
148
  >
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}
799
- <button
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)}
803
- >
804
- Clear range
805
- </button>
806
- {/if}
807
- </div>
149
+ {#if isDateRange(column)}
150
+ <FilterDateRange
151
+ {column}
152
+ selection={sel || {}}
153
+ {relativeRangePresets}
154
+ onchange={(u) => fs.updateDateRange(column.key, u)}
155
+ onclear={() => fs.clearColumn(column.key)}
156
+ />
808
157
  {: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>
846
-
847
- <button
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"
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"
854
- type="button"
855
- >
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>
863
- <ArrowDownOutline
864
- class={'w-3 h-3 transition-transform ' +
865
- (currentSortMode === 'number'
866
- ? 'text-blue-900 dark:text-blue-100'
867
- : 'text-gray-400 dark:text-gray-500')}
868
- style={currentSortMode === 'number' && currentSortDir === 'asc'
869
- ? 'transform: rotate(180deg);'
870
- : ''}
871
- aria-hidden="true"
872
- />
873
- </button>
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>
898
- </div>
899
- </div>
900
-
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"
912
- >
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"
917
- fill="none"
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>
941
-
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"
949
- >
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"
954
- fill="none"
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>
989
-
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"
997
- >
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"
1002
- fill="none"
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>
1019
-
1020
- <div class="pr-1">
1021
- <Badge color="blue" rounded title="Total options">{sortedValues.length}</Badge>
1022
- </div>
1023
- </div>
1024
- </div>
1025
-
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;"
1054
- >
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
1064
- >
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>
1073
- </div>
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"
1082
- >
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
1092
- >
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>
158
+ <FilterValueList
159
+ {column}
160
+ selections={sel || []}
161
+ {showCounts}
162
+ {virtualThreshold}
163
+ {virtualItemHeight}
164
+ {virtualOverscan}
165
+ {populateThreshold}
166
+ ontoggle={(v) => fs.toggleSelection(column.key, v)}
167
+ oncheckall={(vs) => fs.checkAll(column.key, vs)}
168
+ oninvert={(vs) => fs.invertSelection(column.key, vs)}
169
+ onchecknone={() => fs.checkNone(column.key)}
170
+ onsortchange={(i) => handleSortChange(column.key, i)}
171
+ />
1106
172
  {/if}
1107
173
  </div>
1108
174
  {/if}
@@ -1112,114 +178,23 @@
1112
178
  </div>
1113
179
 
1114
180
  <style>
1115
- /* Grid layout classes */
1116
181
  .grid-horizontal {
1117
182
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
1118
183
  }
1119
-
1120
184
  .grid-vertical {
1121
185
  grid-template-columns: 1fr;
1122
186
  }
1123
-
1124
- /* Dropdown menu positioning */
1125
187
  .dropdown-menu {
1126
188
  z-index: 9999;
1127
189
  }
1128
-
1129
- /* Responsive adjustments */
1130
190
  @media (max-width: 768px) {
1131
191
  .grid-horizontal {
1132
192
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
1133
193
  }
1134
194
  }
1135
-
1136
195
  @media (max-width: 640px) {
1137
196
  .grid-horizontal {
1138
197
  grid-template-columns: 1fr;
1139
198
  }
1140
199
  }
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
- }
1225
200
  </style>