@zhangt58/svelte-vtable 0.2.0 → 0.3.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.
Files changed (34) hide show
  1. package/README.md +38 -2
  2. package/dist/components/DataTable.svelte +490 -0
  3. package/dist/components/DataTable.svelte.d.ts +31 -0
  4. package/dist/components/DataTableControls.svelte +589 -0
  5. package/dist/components/DataTableControls.svelte.d.ts +39 -0
  6. package/{src → dist}/components/DataTableFilters.svelte +18 -3
  7. package/dist/components/DataTableFilters.svelte.d.ts +37 -0
  8. package/dist/components/FiltersModal.svelte +72 -0
  9. package/dist/components/FiltersModal.svelte.d.ts +25 -0
  10. package/dist/components/PaginationBar.svelte.d.ts +15 -0
  11. package/{src → dist}/components/filters/FilterColumn.svelte +10 -3
  12. package/dist/components/filters/FilterColumn.svelte.d.ts +19 -0
  13. package/dist/components/filters/FilterDateRange.svelte.d.ts +19 -0
  14. package/{src → dist}/components/filters/FilterValueList.svelte +43 -10
  15. package/dist/components/filters/FilterValueList.svelte.d.ts +33 -0
  16. package/dist/components/filters/useFilterState.svelte.d.ts +25 -0
  17. package/dist/components/flowbite/DataTableControls.svelte +528 -0
  18. package/dist/components/flowbite/DataTableControls.svelte.d.ts +39 -0
  19. package/{src/components → dist/components/flowbite}/FiltersModal.svelte +5 -4
  20. package/dist/components/flowbite/FiltersModal.svelte.d.ts +25 -0
  21. package/dist/filterUtils.d.ts +76 -0
  22. package/dist/index.d.ts +60 -0
  23. package/dist/index.flowbite.d.ts +3 -0
  24. package/dist/index.flowbite.js +9 -0
  25. package/{src/lib → dist}/index.js +7 -7
  26. package/{src/lib → dist}/styles.css +11 -1
  27. package/package.json +37 -18
  28. package/src/components/DataTable.svelte +0 -234
  29. package/src/components/DataTableControls.svelte +0 -270
  30. package/src/lib/dist/styles.css +0 -287
  31. /package/{src → dist}/components/PaginationBar.svelte +0 -0
  32. /package/{src → dist}/components/filters/FilterDateRange.svelte +0 -0
  33. /package/{src → dist}/components/filters/useFilterState.svelte.js +0 -0
  34. /package/{src/lib → dist}/filterUtils.js +0 -0
@@ -0,0 +1,528 @@
1
+ <script>
2
+ import { Search, Badge, Select } from 'flowbite-svelte';
3
+ import FiltersModal from './FiltersModal.svelte';
4
+ import PaginationBar from '../PaginationBar.svelte';
5
+
6
+ // Props for search, pagination (perPage made bindable using Svelte 5 rune $bindable)
7
+ let {
8
+ search = '',
9
+ currentPage = 1,
10
+ perPage = $bindable(25),
11
+ totalItems = 0,
12
+ onpage = undefined,
13
+ onsearch = undefined,
14
+ // control visibility of DataTableFilters above the controls
15
+ filtersVisible = false,
16
+ // callback when toggle changes: onfilterstoggle({ visible })
17
+ onfilterstoggle = undefined,
18
+ // optional DataTableFilters inputs - when provided, this component will render the filters
19
+ columnFilters = [],
20
+ activeFilters = {},
21
+ // onfilter({ key, values, allFilters }) — passed through to DataTableFilters
22
+ /** @type {((..._args: any[]) => void) | undefined} */
23
+ onfilter = undefined,
24
+ direction = 'horizontal',
25
+ showCounts = true,
26
+ className = '',
27
+ // callback when perPage changes: onperpage({ perPage })
28
+ onperpage = undefined,
29
+ } = $props();
30
+
31
+ const perPageOptions = [
32
+ { value: 10, name: '10 rows' },
33
+ { value: 25, name: '25 rows' },
34
+ { value: 50, name: '50 rows' },
35
+ { value: 100, name: '100 rows' },
36
+ ];
37
+
38
+ // count of active filters (sum of selected values per column)
39
+ const activeFilterCount = $derived.by(() => {
40
+ try {
41
+ return Object.values(activeFilters || {}).reduce((sum, v) => {
42
+ if (Array.isArray(v)) return sum + v.length;
43
+ if (v && typeof v === 'object' && (v.from || v.to)) return sum + 1;
44
+ return sum;
45
+ }, 0);
46
+ } catch (e) {
47
+ return 0;
48
+ }
49
+ });
50
+
51
+ // totalPages derived from totalItems and perPage
52
+ const totalPages = $derived(Math.max(1, Math.ceil(totalItems / perPage)));
53
+
54
+ // clamp currentPage into valid range whenever currentPage or totalPages change
55
+ $effect(() => {
56
+ currentPage = Math.min(Math.max(1, +currentPage || 1), totalPages);
57
+ });
58
+
59
+ function goTo(p) {
60
+ const np = Math.min(Math.max(1, Math.floor(p)), totalPages);
61
+ if (np !== currentPage) {
62
+ currentPage = np;
63
+ if (onpage !== undefined) {
64
+ onpage({ page: np });
65
+ }
66
+ }
67
+ }
68
+
69
+ // emit search changes for parent when search updates
70
+ $effect(() => {
71
+ if (typeof search !== 'undefined') {
72
+ if (onsearch !== undefined) {
73
+ onsearch({ search });
74
+ }
75
+ }
76
+ });
77
+
78
+ // call onfilterstoggle when filtersVisible changes (avoid on:change typing issues)
79
+ let _prevFiltersVisible = undefined;
80
+ $effect(() => {
81
+ // initialize previous value on first run without emitting
82
+ if (_prevFiltersVisible === undefined) {
83
+ _prevFiltersVisible = filtersVisible;
84
+ return;
85
+ }
86
+ if (filtersVisible !== _prevFiltersVisible) {
87
+ if (onfilterstoggle !== undefined) {
88
+ try {
89
+ onfilterstoggle({ visible: filtersVisible });
90
+ } catch (err) {}
91
+ }
92
+ _prevFiltersVisible = filtersVisible;
93
+ }
94
+ });
95
+
96
+ // Watch perPage changes: reset to first page and notify parent
97
+ let _prevPerPage = undefined;
98
+ $effect(() => {
99
+ if (_prevPerPage === undefined) {
100
+ _prevPerPage = perPage;
101
+ return;
102
+ }
103
+ if (perPage !== _prevPerPage) {
104
+ // coerce to number just in case
105
+ perPage = +perPage || 25;
106
+ _prevPerPage = perPage;
107
+ // reset to page 1 (common UX) and notify parent
108
+ currentPage = 1;
109
+ if (onperpage !== undefined) {
110
+ try {
111
+ onperpage({ perPage });
112
+ } catch (err) {}
113
+ }
114
+ if (onpage !== undefined) {
115
+ try {
116
+ onpage({ page: currentPage });
117
+ } catch (err) {}
118
+ }
119
+ }
120
+ });
121
+
122
+ // Calculate range for display
123
+ const startItem = $derived(totalItems === 0 ? 0 : (currentPage - 1) * perPage + 1);
124
+ const endItem = $derived(Math.min(currentPage * perPage, totalItems));
125
+
126
+ // visiblePages: number of middle numeric buttons to show (not counting first/last)
127
+ const visiblePages = 5;
128
+
129
+ const perPageSelectId = `dpc-perpage-${Math.random().toString(36).slice(2, 7)}`;
130
+
131
+ // pages array for Pagination component (condensed with ellipses)
132
+ const pages = $derived.by(() => {
133
+ const total = totalPages;
134
+ const current = Math.min(Math.max(1, Math.floor(currentPage)), total);
135
+
136
+ // If small number of pages, show all
137
+ if (total <= visiblePages + 2) {
138
+ return Array.from({ length: total }, (_, i) => ({
139
+ name: String(i + 1),
140
+ active: i + 1 === current,
141
+ }));
142
+ }
143
+
144
+ const pagesArr = [];
145
+ // always show first
146
+ pagesArr.push({ name: '1', active: current === 1 });
147
+
148
+ const half = Math.floor(visiblePages / 2);
149
+ let start = Math.max(2, current - half);
150
+ let end = Math.min(total - 1, current + half);
151
+
152
+ // adjust window when near the boundaries
153
+ if (current - 1 <= half) {
154
+ start = 2;
155
+ end = 1 + visiblePages;
156
+ }
157
+ if (total - current <= half) {
158
+ end = total - 1;
159
+ start = total - visiblePages;
160
+ }
161
+
162
+ if (start > 2) {
163
+ // compute left jump (midpoint of hidden range 2..start-1)
164
+ const leftHiddenStart = 2;
165
+ const leftHiddenEnd = start - 1;
166
+ const leftJump = Math.max(leftHiddenStart, Math.floor((leftHiddenStart + leftHiddenEnd) / 2));
167
+ pagesArr.push({ name: '…', active: false, ellipsis: 'left', jump: leftJump });
168
+ }
169
+
170
+ for (let i = start; i <= end; i++) pagesArr.push({ name: String(i), active: i === current });
171
+
172
+ if (end < total - 1) {
173
+ // compute right jump (midpoint of hidden range end+1..total-1)
174
+ const rightHiddenStart = end + 1;
175
+ const rightHiddenEnd = total - 1;
176
+ const rightJump = Math.min(
177
+ rightHiddenEnd,
178
+ Math.ceil((rightHiddenStart + rightHiddenEnd) / 2),
179
+ );
180
+ pagesArr.push({ name: '…', active: false, ellipsis: 'right', jump: rightJump });
181
+ }
182
+
183
+ // always show last
184
+ pagesArr.push({ name: String(total), active: current === total });
185
+
186
+ return pagesArr;
187
+ });
188
+
189
+ // No external tooltip component in use; we rely on native title attribute for ellipses
190
+ </script>
191
+
192
+ <div class="w-full">
193
+ <div class="flex items-center w-full gap-3 px-0 py-0">
194
+ <!-- Search field on the left -->
195
+ <div class="flex-1">
196
+ <div class="flex items-center gap-2">
197
+ <!-- Styled button to open/close filters modal -->
198
+ <div class="flex items-center gap-1 relative">
199
+ <button
200
+ type="button"
201
+ class={'inline-flex items-center gap-2 px-3 py-1 text-sm rounded-md border transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 ' +
202
+ (filtersVisible
203
+ ? 'bg-slate-100 dark:bg-slate-700 border-slate-300 dark:border-slate-600 text-slate-900 dark:text-slate-100'
204
+ : 'bg-transparent border-transparent text-slate-700 dark:text-slate-300 hover:bg-slate-100 dark:hover:bg-slate-700')}
205
+ aria-pressed={filtersVisible}
206
+ aria-label="Toggle filters"
207
+ title="Filters"
208
+ onclick={() => {
209
+ filtersVisible = !filtersVisible;
210
+ }}
211
+ >
212
+ <!-- Funnel/filter icon (inline SVG) -->
213
+ <svg class="h-4 w-4 shrink-0" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
214
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2a1 1 0 01-.293.707L13 13.414V19a1 1 0 01-.553.894l-4 2A1 1 0 017 21v-7.586L3.293 6.707A1 1 0 013 6V4z" />
215
+ </svg>
216
+ <span class="text-sm">Filters</span>
217
+ </button>
218
+
219
+ {#if activeFilterCount > 0}
220
+ <!-- positioned badge -->
221
+ <span
222
+ class="absolute top-0 right-0 -translate-y-1/2 translate-x-1/2 inline-flex items-center justify-center h-5 min-w-[1.25rem] px-1.5 rounded-full text-white text-xs font-medium"
223
+ style="background-color: var(--vtable-color-accent);">{activeFilterCount}</span
224
+ >
225
+ {/if}
226
+ </div>
227
+
228
+ <Search
229
+ size="sm"
230
+ bind:value={search}
231
+ placeholder="Search..."
232
+ clearable
233
+ clearableOnClick={() => {
234
+ search = '';
235
+ if (onsearch !== undefined) {
236
+ onsearch({ search: '' });
237
+ }
238
+ }}
239
+ />
240
+ </div>
241
+ </div>
242
+
243
+ <!-- Range count badge + per-page selector -->
244
+ <div class="flex-2 flex items-center gap-2">
245
+ <Badge rounded color="gray">
246
+ Showing {startItem} to {endItem} of {totalItems}
247
+ </Badge>
248
+
249
+ <!-- Per-page selector -->
250
+ <div class="flex items-center gap-2">
251
+ <Select id={perPageSelectId} size="sm" items={perPageOptions} bind:value={perPage} />
252
+ </div>
253
+ </div>
254
+
255
+ <!-- Pagination navigation -->
256
+ <PaginationBar {pages} {currentPage} onpage={goTo} />
257
+ </div>
258
+ </div>
259
+
260
+ <FiltersModal
261
+ bind:open={filtersVisible}
262
+ {columnFilters}
263
+ {activeFilters}
264
+ {onfilter}
265
+ {direction}
266
+ {showCounts}
267
+ {className}
268
+ />
269
+
270
+ <style>/* ── Theming contract — override these on :root or any wrapper element ── */
271
+ :root {
272
+ --vtable-color-accent: #16a34a; /* green-600 */
273
+ --vtable-color-accent-light: #dcfce7; /* green-100 */
274
+ --vtable-color-accent-border: #22c55e; /* green-500 */
275
+ --vtable-color-accent-text: #15803d; /* green-700 */
276
+
277
+ --vtable-color-danger: #dc2626; /* red-600 */
278
+ --vtable-color-info: #3b82f6; /* blue-500 */
279
+
280
+ --vtable-radius: 0.375rem; /* rounded-md */
281
+ --vtable-row-height: 2.25rem; /* default row height hint for virtual scroll */
282
+ }
283
+ .virtual-data-table {
284
+ display: block;
285
+ min-width: 0;
286
+ height: 100%;
287
+ overflow: auto;
288
+ isolation: isolate;
289
+ }
290
+ :global(.datatable-table) {
291
+ display: table;
292
+ width: 100%;
293
+ min-width: 0;
294
+ border-collapse: collapse;
295
+ box-sizing: border-box;
296
+ font-size: 0.875rem; /* 14px - smaller, more compact */
297
+ font-family:
298
+ -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
299
+ line-height: 1.4;
300
+ border: none;
301
+ }
302
+ /* Sticky header support */
303
+ :global(.datatable-table) thead.sticky-header {
304
+ position: sticky;
305
+ top: 0;
306
+ z-index: 2;
307
+ }
308
+ /* Header visual styles - only bottom border */
309
+ :global(.datatable-table) thead th {
310
+ background-color: #f8f9fa;
311
+ font-size: 0.8125rem; /* 13px */
312
+ font-weight: 600;
313
+ text-transform: uppercase;
314
+ letter-spacing: 0.025em;
315
+ border-top: none;
316
+ border-left: none;
317
+ border-right: none;
318
+ border-bottom: 1px solid #dee2e6;
319
+ padding: 0.5rem 0.5rem;
320
+ text-align: left;
321
+ white-space: normal; /* Allow header text to wrap */
322
+ overflow: visible;
323
+ box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1); /* Keep border visible on scroll */
324
+ }
325
+ /* Row striping - alternating colors */
326
+ /* VirtualList may wrap rows, so we target tr directly */
327
+ :global(.datatable-table tbody tr:nth-of-type(even)) {
328
+ background-color: #ffffff;
329
+ }
330
+ :global(.datatable-table tbody tr:nth-of-type(odd)) {
331
+ background-color: #f8f9fa;
332
+ }
333
+ /* Also ensure tr elements themselves have background */
334
+ :global(.datatable-table tbody tr) {
335
+ background-color: inherit;
336
+ }
337
+ /* Hover effect */
338
+ :global(.datatable-table tbody tr:hover) {
339
+ background-color: #e7f1ff !important;
340
+ transition: background-color 0.15s ease-in-out;
341
+ }
342
+ /* Selesky-500 row overrides striping and hover */
343
+ :global(.datatable-table tbody tr.selected-row) {
344
+ background-color: #e0f2fe !important; /* light sky background */
345
+ box-shadow: inset 4px 0 0 0 #0369a1; /* left accent */
346
+ }
347
+ :global(.dark) :global(.datatable-table tbody tr.selected-row) {
348
+ /* brighter, higher-contrast selection in dark mode */
349
+ background-color: rgba(14, 165, 233, 0.22) !important; /* stronger visible blue */
350
+ box-shadow: inset 6px 0 0 0 rgba(56, 189, 248, 0.85); /* stronger left accent */
351
+ transition:
352
+ background-color 0.12s ease-in-out,
353
+ box-shadow 0.12s ease-in-out;
354
+ }
355
+ /* Also apply to cells to defeat any cell-level background from striping and ensure readable text */
356
+ :global(.datatable-table tbody tr.selected-row) td {
357
+ background-color: #e0f2fe !important;
358
+ }
359
+ :global(.dark) :global(.datatable-table tbody tr.selected-row) td {
360
+ background-color: rgba(14, 165, 233, 0.22) !important;
361
+ color: #f0fbff !important; /* ensure high-contrast, very light text */
362
+ border-bottom-color: rgba(255, 255, 255, 0.06);
363
+ }
364
+ /* Body cell defaults - only bottom border */
365
+ :global(.datatable-table tbody td) {
366
+ padding: 0.5rem 0.5rem;
367
+ border-top: none;
368
+ border-left: none;
369
+ border-right: none;
370
+ border-bottom: 1px solid #e9ecef;
371
+ vertical-align: middle;
372
+ text-align: left;
373
+ font-size: 0.875rem; /* 14px */
374
+ overflow: hidden;
375
+ white-space: normal; /* Allow wrapping by default */
376
+ word-wrap: break-word;
377
+ box-sizing: border-box;
378
+ }
379
+ /* No-wrap variant for cells that should truncate */
380
+ :global(.datatable-table tbody td.nowrap) {
381
+ white-space: nowrap;
382
+ text-overflow: ellipsis;
383
+ }
384
+ /* Compact variant */
385
+ :global(.datatable-table.compact tbody td) {
386
+ padding: 0.1rem 0.3rem;
387
+ }
388
+ /* Header content alignment helper */
389
+ :global(.datatable-table thead th > div) {
390
+ display: inline-flex;
391
+ align-items: center;
392
+ gap: 0.25rem;
393
+ }
394
+ /* Allow certain long cells to wrap fully if explicitly requested */
395
+ :global(.datatable-table td.wrap) {
396
+ white-space: normal;
397
+ word-break: break-word;
398
+ }
399
+ /* Dark mode variants for the datatable */
400
+ :global(.dark) :global(.datatable-table thead th) {
401
+ background-color: #1f2937;
402
+ border-bottom-color: #374151;
403
+ color: #f9fafb;
404
+ box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.3); /* Darker shadow for dark mode */
405
+ }
406
+ :global(.dark) :global(.datatable-table tbody tr:nth-of-type(even)) {
407
+ background-color: #111827;
408
+ }
409
+ :global(.dark) :global(.datatable-table tbody tr:nth-of-type(odd)) {
410
+ background-color: #1f2937;
411
+ }
412
+ :global(.dark) :global(.datatable-table tbody tr:hover) {
413
+ background-color: #374151 !important;
414
+ }
415
+ :global(.dark) :global(.datatable-table tbody td) {
416
+ border-bottom-color: #374151;
417
+ color: #e5e7eb;
418
+ }
419
+ /* Shared control styles (inputs, pagination, column filters) used by page components */
420
+ /* Accent-color focus ring for search input and per-page select — respects --vtable-color-accent */
421
+ :global(.vtable-search-input:focus),
422
+ :global(.vtable-perpage-select:focus) {
423
+ border-color: var(--vtable-color-accent-border);
424
+ box-shadow: 0 0 0 2px color-mix(in srgb, var(--vtable-color-accent) 20%, transparent);
425
+ outline: none;
426
+ }
427
+ :global(.datatable-input) {
428
+ padding: 0.375rem 0.75rem;
429
+ font-size: 0.95rem;
430
+ border: 1px solid #ced4da;
431
+ border-radius: 0.25rem;
432
+ }
433
+ :global(.datatable-input:focus) {
434
+ border-color: #86b7fe;
435
+ outline: 0;
436
+ box-shadow: 0 0 0.1rem 0.2rem rgba(13, 110, 253, 0.25);
437
+ }
438
+ :global(.search-filtering-row) {
439
+ background-color: #f8f9fa;
440
+ }
441
+ :global(.search-filtering-row th) {
442
+ padding: 0.1rem 0.1rem;
443
+ border-bottom: 1px solid #dee2e6;
444
+ }
445
+ :global(.column-filter) {
446
+ width: 95%;
447
+ padding: 0.2rem 0.25rem;
448
+ font-size: 0.8rem;
449
+ border: 1px solid #ced4da;
450
+ border-radius: 0.25rem;
451
+ }
452
+ :global(.column-filter::placeholder) {
453
+ color: #adb5bd;
454
+ font-size: 0.75rem;
455
+ font-style: italic;
456
+ }
457
+ :global(.datatable-pagination) {
458
+ display: flex;
459
+ gap: 0.1rem;
460
+ margin-top: 0.6rem;
461
+ }
462
+ :global(.datatable-pagination li a),
463
+ :global(.datatable-pagination li button) {
464
+ padding: 0.3rem 0.7rem;
465
+ border: 1px solid #dee2e6;
466
+ border-radius: 0;
467
+ background-color: #fff;
468
+ color: #0d6efd;
469
+ text-decoration: none;
470
+ }
471
+ :global(.datatable-pagination li a:hover),
472
+ :global(.datatable-pagination li button:hover) {
473
+ background-color: #e9ecef;
474
+ }
475
+ :global(.datatable-pagination .datatable-active a),
476
+ :global(.datatable-pagination .datatable-active button) {
477
+ background-color: #0d6efd;
478
+ border-color: #0d6efd;
479
+ color: #fff;
480
+ }
481
+ /* Force the active/current page to use the accent tokens (override flowbite's primary/orange).
482
+ Intentionally specific to reliably win over third-party rules. */
483
+ :global([data-pagination-id] ul li [aria-current='page']) {
484
+ background-color: var(--vtable-color-accent-light) !important;
485
+ color: var(--vtable-color-accent) !important;
486
+ border-color: transparent !important;
487
+ }
488
+ /* Ensure Prev/Next controls visually match the numeric buttons' border and rhythm
489
+ (keeps border, radius and min-width consistent). This is minimal and won't
490
+ override hover/text colors managed by Tailwind classes applied at runtime. */
491
+ :global([data-pagination-id] ul li:first-child > button),
492
+ :global([data-pagination-id] ul li:first-child > a),
493
+ :global([data-pagination-id] ul li:last-child > button),
494
+ :global([data-pagination-id] ul li:last-child > a) {
495
+ border: 1px solid #d1d5db; /* border-gray-300 */
496
+ min-width: 2rem; /* align with numeric buttons' min width */
497
+ background: transparent;
498
+ padding: 0.25rem 0.5rem; /* keep comfortable hit area */
499
+ }
500
+ /* Light mode: hover/focus for Prev/Next match numeric button hover */
501
+ :global([data-pagination-id] ul li:first-child > button:hover),
502
+ :global([data-pagination-id] ul li:first-child > a:hover),
503
+ :global([data-pagination-id] ul li:last-child > button:hover),
504
+ :global([data-pagination-id] ul li:last-child > a:hover),
505
+ :global([data-pagination-id] ul li:first-child > button:focus),
506
+ :global([data-pagination-id] ul li:first-child > a:focus),
507
+ :global([data-pagination-id] ul li:last-child > button:focus),
508
+ :global([data-pagination-id] ul li:last-child > a:focus) {
509
+ background-color: #f3f4f6; /* tailwind gray-100 */
510
+ outline: none;
511
+ }
512
+ /* Ellipsis styling: make clickable and visually lighter (JS sets data-ellipsis/data-jump) */
513
+ :global([data-pagination-id] ul li [data-ellipsis='true']) {
514
+ cursor: pointer;
515
+ background: transparent !important;
516
+ color: inherit;
517
+ opacity: 0.9;
518
+ font-size: 0.875rem;
519
+ padding: 0.25rem 0.5rem;
520
+ }
521
+ /* Chevron sizing for Prev/Next so icons sit comfortably in the buttons */
522
+ :global([data-pagination-id] ul li:first-child svg),
523
+ :global([data-pagination-id] ul li:last-child svg) {
524
+ height: 1.25rem;
525
+ width: 1.25rem;
526
+ display: block;
527
+ }
528
+ </style>
@@ -0,0 +1,39 @@
1
+ export default DataTableControls;
2
+ type DataTableControls = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<$$ComponentProps>): void;
5
+ };
6
+ declare const DataTableControls: import("svelte").Component<{
7
+ search?: string;
8
+ currentPage?: number;
9
+ perPage?: number;
10
+ totalItems?: number;
11
+ onpage?: any;
12
+ onsearch?: any;
13
+ filtersVisible?: boolean;
14
+ onfilterstoggle?: any;
15
+ columnFilters?: any[];
16
+ activeFilters?: Record<string, any>;
17
+ onfilter?: any;
18
+ direction?: string;
19
+ showCounts?: boolean;
20
+ className?: string;
21
+ onperpage?: any;
22
+ }, {}, "perPage">;
23
+ type $$ComponentProps = {
24
+ search?: string;
25
+ currentPage?: number;
26
+ perPage?: number;
27
+ totalItems?: number;
28
+ onpage?: any;
29
+ onsearch?: any;
30
+ filtersVisible?: boolean;
31
+ onfilterstoggle?: any;
32
+ columnFilters?: any[];
33
+ activeFilters?: Record<string, any>;
34
+ onfilter?: any;
35
+ direction?: string;
36
+ showCounts?: boolean;
37
+ className?: string;
38
+ onperpage?: any;
39
+ };
@@ -1,7 +1,6 @@
1
1
  <script>
2
2
  import { Modal } from 'flowbite-svelte';
3
- import { CloseOutline } from 'flowbite-svelte-icons';
4
- import DataTableFilters from './DataTableFilters.svelte';
3
+ import DataTableFilters from '../DataTableFilters.svelte';
5
4
 
6
5
  // Props — make `open` bindable so parent can use `bind:open`
7
6
  let {
@@ -20,13 +19,15 @@
20
19
 
21
20
  <Modal bind:open size="lg" dismissable={false}>
22
21
  <div class="flex items-center justify-between mb-2">
23
- <h3 class="text-lg font-semibold text-gray-900 dark:text-white">Filters</h3>
22
+ <h3 class="text-lg font-semibold text-gray-900 dark:text-white">{title}</h3>
24
23
  <button
25
24
  aria-label="Close"
26
25
  class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center dark:hover:bg-gray-600 dark:hover:text-white"
27
26
  onclick={() => (open = false)}
28
27
  >
29
- <CloseOutline class="shrink-0 h-6 w-6" />
28
+ <svg class="shrink-0 h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
29
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
30
+ </svg>
30
31
  </button>
31
32
  </div>
32
33
 
@@ -0,0 +1,25 @@
1
+ export default FiltersModal;
2
+ type FiltersModal = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<$$ComponentProps>): void;
5
+ };
6
+ declare const FiltersModal: import("svelte").Component<{
7
+ open?: boolean;
8
+ columnFilters?: any[];
9
+ activeFilters?: Record<string, any>;
10
+ title?: string;
11
+ onfilter?: any;
12
+ direction?: string;
13
+ showCounts?: boolean;
14
+ className?: string;
15
+ }, {}, "open">;
16
+ type $$ComponentProps = {
17
+ open?: boolean;
18
+ columnFilters?: any[];
19
+ activeFilters?: Record<string, any>;
20
+ title?: string;
21
+ onfilter?: any;
22
+ direction?: string;
23
+ showCounts?: boolean;
24
+ className?: string;
25
+ };
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Utility functions for working with DataTableFilters
3
+ */
4
+ /**
5
+ * Extract unique values and their counts from an array of objects for a given key
6
+ * @param {Array} data - Array of data objects
7
+ * @param {string} key - The property key to extract unique values from
8
+ * @returns {{uniqueValues: Array, counts: Object}} Object with unique values array and counts map
9
+ */
10
+ export function getUniqueValuesWithCounts(data: any[], key: string): {
11
+ uniqueValues: any[];
12
+ counts: any;
13
+ };
14
+ /**
15
+ * Build column filters configuration from data and column definitions.
16
+ * Columns with `filterType: 'none'` are excluded from the returned array.
17
+ * @param {Array} data - Array of data objects
18
+ * @param {import('./index.js').ColumnDef[]} columns - Array of ColumnDef objects.
19
+ * @returns {Array} Column filters configuration for DataTableFilters
20
+ */
21
+ export function buildColumnFilters(data: any[], columns: import("./index.js").ColumnDef[]): any[];
22
+ /**
23
+ * Check whether a value falls within a date/datetime range.
24
+ * Both `from` and `to` are optional; omitting one leaves that end open.
25
+ * Date-only strings (YYYY-MM-DD) are parsed as **local** midnight (i.e. they
26
+ * are treated as `<date>T00:00:00` in the local timezone, not UTC). A date-only
27
+ * `to` value is inclusive through the end of that calendar day (23:59:59.999
28
+ * local time).
29
+ * @param {any} value - The item's date value (string, Date, or number)
30
+ * @param {string|null|undefined} from - Range start (ISO date or datetime-local string)
31
+ * @param {string|null|undefined} to - Range end (ISO date or datetime-local string)
32
+ * @returns {boolean}
33
+ */
34
+ export function matchesDateRange(value: any, from: string | null | undefined, to: string | null | undefined): boolean;
35
+ /**
36
+ * Apply filters to data with OR logic within columns and AND logic across columns.
37
+ * Supports both value-selection filters (array) and date/datetime range filters
38
+ * (object with optional `from` and `to` string fields).
39
+ * @param {Array} data - Array of data objects to filter
40
+ * @param {Object} activeFilters - Active filters: { columnKey: string[] | {from?, to?} }
41
+ * @returns {Array} Filtered data array
42
+ */
43
+ export function applyFilters(data: any[], activeFilters: any): any[];
44
+ /**
45
+ * Check if any filters are currently active
46
+ * @param {Object} activeFilters - Active filters object
47
+ * @returns {boolean} True if any filters are active
48
+ */
49
+ export function hasActiveFilters(activeFilters: any): boolean;
50
+ /**
51
+ * Count total number of active filter selections.
52
+ * Each active date range counts as 1.
53
+ * @param {Object} activeFilters - Active filters object
54
+ * @returns {number} Total count of active filter values/ranges
55
+ */
56
+ export function countActiveFilters(activeFilters: any): number;
57
+ /**
58
+ * Clear all filters
59
+ * @param {Array} columnFilters - Column filters configuration
60
+ * @returns {Object} Cleared filters object (arrays for value columns, empty objects for date ranges)
61
+ */
62
+ export function clearAllFilters(columnFilters: any[]): any;
63
+ /**
64
+ * Export active filters as URL search params.
65
+ * Date range filters are serialised as `<key>_from` and `<key>_to` params.
66
+ * @param {Object} activeFilters - Active filters object
67
+ * @returns {URLSearchParams} URL search params object
68
+ */
69
+ export function filtersToSearchParams(activeFilters: any): URLSearchParams;
70
+ /**
71
+ * Import active filters from URL search params
72
+ * @param {URLSearchParams|string} searchParams - URL search params or query string
73
+ * @param {Array} columnFilters - Column filters configuration (to validate keys)
74
+ * @returns {Object} Active filters object
75
+ */
76
+ export function searchParamsToFilters(searchParams: URLSearchParams | string, columnFilters: any[]): any;