@zhangt58/svelte-vtable 0.3.1 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/dist/components/DataTable.svelte +2 -1
- package/dist/components/DataTableControls.svelte +16 -3
- package/dist/components/FiltersModal.svelte +10 -3
- package/dist/components/filters/FilterValueList.svelte +18 -3
- package/dist/components/flowbite/DataTableControls.svelte +11 -8
- package/dist/components/flowbite/FiltersModal.svelte +3 -2
- package/dist/filterUtils.js +24 -5
- package/dist/index.flowbite.js +1 -1
- package/dist/styles.css +2 -1
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ This library requires the following peer dependencies:
|
|
|
27
27
|
npm install svelte@^5.0.0 tailwindcss@^4.0.0 svelte-virtuallists@^1.0.0
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
`flowbite-svelte`
|
|
30
|
+
`flowbite-svelte` is **optional** — only needed if you use the Flowbite adapter (see [Flowbite Adapter](#flowbite-adapter)).
|
|
31
31
|
|
|
32
32
|
## Quick Start
|
|
33
33
|
|
|
@@ -108,7 +108,7 @@ If your project already uses **Flowbite**, you can opt in to the Flowbite-flavou
|
|
|
108
108
|
|
|
109
109
|
```bash
|
|
110
110
|
# Install optional Flowbite peer dependencies
|
|
111
|
-
npm install flowbite-svelte@^1.0.0
|
|
111
|
+
npm install flowbite-svelte@^1.0.0
|
|
112
112
|
```
|
|
113
113
|
|
|
114
114
|
```svelte
|
|
@@ -140,7 +140,6 @@ See [`examples/flowbite/App.svelte`](./examples/flowbite/App.svelte) for a compl
|
|
|
140
140
|
|
|
141
141
|
A virtualized table component for efficient rendering of large datasets. The component was renamed to `DataTable`; `VirtualDataTable` is still exported for backward compatibility.
|
|
142
142
|
|
|
143
|
-
|
|
144
143
|
#### Props
|
|
145
144
|
|
|
146
145
|
| Prop | Type | Default | Description |
|
|
@@ -247,6 +247,7 @@
|
|
|
247
247
|
min-width: 0;
|
|
248
248
|
height: 100%;
|
|
249
249
|
overflow: auto;
|
|
250
|
+
isolation: isolate;
|
|
250
251
|
}
|
|
251
252
|
:global(.datatable-table) {
|
|
252
253
|
display: table;
|
|
@@ -264,7 +265,7 @@
|
|
|
264
265
|
:global(.datatable-table) thead.sticky-header {
|
|
265
266
|
position: sticky;
|
|
266
267
|
top: 0;
|
|
267
|
-
z-index:
|
|
268
|
+
z-index: 2;
|
|
268
269
|
}
|
|
269
270
|
/* Header visual styles - only bottom border */
|
|
270
271
|
:global(.datatable-table) thead th {
|
|
@@ -270,8 +270,20 @@
|
|
|
270
270
|
}
|
|
271
271
|
}}
|
|
272
272
|
>
|
|
273
|
-
<svg
|
|
274
|
-
|
|
273
|
+
<svg
|
|
274
|
+
class="h-4 w-4"
|
|
275
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
276
|
+
fill="none"
|
|
277
|
+
viewBox="0 0 24 24"
|
|
278
|
+
stroke="currentColor"
|
|
279
|
+
aria-hidden="true"
|
|
280
|
+
>
|
|
281
|
+
<path
|
|
282
|
+
stroke-linecap="round"
|
|
283
|
+
stroke-linejoin="round"
|
|
284
|
+
stroke-width="2"
|
|
285
|
+
d="M6 18L18 6M6 6l12 12"
|
|
286
|
+
/>
|
|
275
287
|
</svg>
|
|
276
288
|
</button>
|
|
277
289
|
{/if}
|
|
@@ -334,6 +346,7 @@
|
|
|
334
346
|
min-width: 0;
|
|
335
347
|
height: 100%;
|
|
336
348
|
overflow: auto;
|
|
349
|
+
isolation: isolate;
|
|
337
350
|
}
|
|
338
351
|
:global(.datatable-table) {
|
|
339
352
|
display: table;
|
|
@@ -351,7 +364,7 @@
|
|
|
351
364
|
:global(.datatable-table) thead.sticky-header {
|
|
352
365
|
position: sticky;
|
|
353
366
|
top: 0;
|
|
354
|
-
z-index:
|
|
367
|
+
z-index: 2;
|
|
355
368
|
}
|
|
356
369
|
/* Header visual styles - only bottom border */
|
|
357
370
|
:global(.datatable-table) thead th {
|
|
@@ -33,9 +33,11 @@
|
|
|
33
33
|
aria-labelledby="vtable-modal-title"
|
|
34
34
|
>
|
|
35
35
|
<div
|
|
36
|
-
class="vtable-modal-panel bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-2xl pointer-events-auto overflow-hidden"
|
|
36
|
+
class="vtable-modal-panel bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-sm sm:max-w-2xl lg:max-w-4xl xl:max-w-5xl pointer-events-auto overflow-hidden"
|
|
37
37
|
>
|
|
38
|
-
<div
|
|
38
|
+
<div
|
|
39
|
+
class="flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700"
|
|
40
|
+
>
|
|
39
41
|
<h3 id="vtable-modal-title" class="text-lg font-semibold text-gray-900 dark:text-white">
|
|
40
42
|
{title}
|
|
41
43
|
</h3>
|
|
@@ -52,7 +54,12 @@
|
|
|
52
54
|
stroke="currentColor"
|
|
53
55
|
aria-hidden="true"
|
|
54
56
|
>
|
|
55
|
-
<path
|
|
57
|
+
<path
|
|
58
|
+
stroke-linecap="round"
|
|
59
|
+
stroke-linejoin="round"
|
|
60
|
+
stroke-width="2"
|
|
61
|
+
d="M6 18L18 6M6 6l12 12"
|
|
62
|
+
/>
|
|
56
63
|
</svg>
|
|
57
64
|
</button>
|
|
58
65
|
</div>
|
|
@@ -179,7 +179,12 @@
|
|
|
179
179
|
stroke="currentColor"
|
|
180
180
|
aria-hidden="true"
|
|
181
181
|
>
|
|
182
|
-
<path
|
|
182
|
+
<path
|
|
183
|
+
stroke-linecap="round"
|
|
184
|
+
stroke-linejoin="round"
|
|
185
|
+
stroke-width="2"
|
|
186
|
+
d="M19 9l-7 7-7-7"
|
|
187
|
+
/>
|
|
183
188
|
</svg>
|
|
184
189
|
</button>
|
|
185
190
|
<!-- Sort by number -->
|
|
@@ -211,7 +216,12 @@
|
|
|
211
216
|
stroke="currentColor"
|
|
212
217
|
aria-hidden="true"
|
|
213
218
|
>
|
|
214
|
-
<path
|
|
219
|
+
<path
|
|
220
|
+
stroke-linecap="round"
|
|
221
|
+
stroke-linejoin="round"
|
|
222
|
+
stroke-width="2"
|
|
223
|
+
d="M19 9l-7 7-7-7"
|
|
224
|
+
/>
|
|
215
225
|
</svg>
|
|
216
226
|
</button>
|
|
217
227
|
<!-- Sort by count (only when counts are available) -->
|
|
@@ -237,7 +247,12 @@
|
|
|
237
247
|
stroke="currentColor"
|
|
238
248
|
aria-hidden="true"
|
|
239
249
|
>
|
|
240
|
-
<path
|
|
250
|
+
<path
|
|
251
|
+
stroke-linecap="round"
|
|
252
|
+
stroke-linejoin="round"
|
|
253
|
+
stroke-width="2"
|
|
254
|
+
d="M19 9l-7 7-7-7"
|
|
255
|
+
/>
|
|
241
256
|
</svg>
|
|
242
257
|
</button>
|
|
243
258
|
{/if}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { Search, Badge, Select } from 'flowbite-svelte';
|
|
3
|
-
import { FilterOutline } from 'flowbite-svelte-icons';
|
|
4
3
|
import FiltersModal from './FiltersModal.svelte';
|
|
5
4
|
import PaginationBar from '../PaginationBar.svelte';
|
|
6
5
|
|
|
@@ -39,10 +38,11 @@
|
|
|
39
38
|
// count of active filters (sum of selected values per column)
|
|
40
39
|
const activeFilterCount = $derived.by(() => {
|
|
41
40
|
try {
|
|
42
|
-
return Object.values(activeFilters || {}).reduce(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
46
|
} catch (e) {
|
|
47
47
|
return 0;
|
|
48
48
|
}
|
|
@@ -209,8 +209,10 @@
|
|
|
209
209
|
filtersVisible = !filtersVisible;
|
|
210
210
|
}}
|
|
211
211
|
>
|
|
212
|
-
<!-- Funnel icon (
|
|
213
|
-
<
|
|
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>
|
|
214
216
|
<span class="text-sm">Filters</span>
|
|
215
217
|
</button>
|
|
216
218
|
|
|
@@ -283,6 +285,7 @@
|
|
|
283
285
|
min-width: 0;
|
|
284
286
|
height: 100%;
|
|
285
287
|
overflow: auto;
|
|
288
|
+
isolation: isolate;
|
|
286
289
|
}
|
|
287
290
|
:global(.datatable-table) {
|
|
288
291
|
display: table;
|
|
@@ -300,7 +303,7 @@
|
|
|
300
303
|
:global(.datatable-table) thead.sticky-header {
|
|
301
304
|
position: sticky;
|
|
302
305
|
top: 0;
|
|
303
|
-
z-index:
|
|
306
|
+
z-index: 2;
|
|
304
307
|
}
|
|
305
308
|
/* Header visual styles - only bottom border */
|
|
306
309
|
:global(.datatable-table) thead th {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { Modal } from 'flowbite-svelte';
|
|
3
|
-
import { CloseOutline } from 'flowbite-svelte-icons';
|
|
4
3
|
import DataTableFilters from '../DataTableFilters.svelte';
|
|
5
4
|
|
|
6
5
|
// Props — make `open` bindable so parent can use `bind:open`
|
|
@@ -26,7 +25,9 @@
|
|
|
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
|
-
<
|
|
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
|
|
package/dist/filterUtils.js
CHANGED
|
@@ -13,9 +13,18 @@ export function getUniqueValuesWithCounts(data, key) {
|
|
|
13
13
|
|
|
14
14
|
data.forEach((item) => {
|
|
15
15
|
const value = item[key];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
|
|
17
|
+
if (Array.isArray(value)) {
|
|
18
|
+
// If the value is an array, count each element separately
|
|
19
|
+
for (const v of value) {
|
|
20
|
+
const normalizedV = String(v ?? '');
|
|
21
|
+
countMap[normalizedV] = (countMap[normalizedV] || 0) + 1;
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
// Handle null/undefined
|
|
25
|
+
const normalizedValue = value ?? '(empty)';
|
|
26
|
+
countMap[normalizedValue] = (countMap[normalizedValue] || 0) + 1;
|
|
27
|
+
}
|
|
19
28
|
});
|
|
20
29
|
|
|
21
30
|
return {
|
|
@@ -150,8 +159,18 @@ export function applyFilters(data, activeFilters) {
|
|
|
150
159
|
// Value-based filter (OR logic within column)
|
|
151
160
|
if (filterValue.length === 0) continue;
|
|
152
161
|
const itemValue = item[columnKey];
|
|
153
|
-
|
|
154
|
-
if (
|
|
162
|
+
|
|
163
|
+
if (Array.isArray(itemValue)) {
|
|
164
|
+
// array value - check if any element matches the filter values
|
|
165
|
+
const hasMatch = itemValue.some((v) =>
|
|
166
|
+
filterValue.includes(String(v ?? ''))
|
|
167
|
+
);
|
|
168
|
+
if (!hasMatch) return false;
|
|
169
|
+
} else {
|
|
170
|
+
// scalar value - treat null/undefined as '(empty)'
|
|
171
|
+
const normalizedItemValue = itemValue ?? '(empty)';
|
|
172
|
+
if (!filterValue.includes(normalizedItemValue)) return false;
|
|
173
|
+
}
|
|
155
174
|
} else if (typeof filterValue === 'object') {
|
|
156
175
|
// Date / datetime range filter
|
|
157
176
|
const { from, to } = filterValue;
|
package/dist/index.flowbite.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Flowbite-flavoured adapter components.
|
|
2
2
|
// Import from '@zhangt58/svelte-vtable/flowbite' to use these.
|
|
3
|
-
// Requires flowbite-svelte
|
|
3
|
+
// Requires flowbite-svelte as a peer dependency.
|
|
4
4
|
export { default as DataTableControls } from './components/flowbite/DataTableControls.svelte';
|
|
5
5
|
export { default as FiltersModal } from './components/flowbite/FiltersModal.svelte';
|
|
6
6
|
|
package/dist/styles.css
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
min-width: 0;
|
|
18
18
|
height: 100%;
|
|
19
19
|
overflow: auto;
|
|
20
|
+
isolation: isolate;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
:global(.datatable-table) {
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
:global(.datatable-table) thead.sticky-header {
|
|
37
38
|
position: sticky;
|
|
38
39
|
top: 0;
|
|
39
|
-
z-index:
|
|
40
|
+
z-index: 2;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
/* Header visual styles - only bottom border */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhangt58/svelte-vtable",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "A Svelte 5 library for virtualized data tables with sorting, selection, and pagination controls.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -65,14 +65,12 @@
|
|
|
65
65
|
"tailwindcss": "^4.1.17"
|
|
66
66
|
},
|
|
67
67
|
"optionalPeerDependencies": {
|
|
68
|
-
"flowbite-svelte": "^1.28.1"
|
|
69
|
-
"flowbite-svelte-icons": "^3.0.0"
|
|
68
|
+
"flowbite-svelte": "^1.28.1"
|
|
70
69
|
},
|
|
71
70
|
"devDependencies": {
|
|
72
71
|
"@sveltejs/package": "^2.5.7",
|
|
73
72
|
"@sveltejs/vite-plugin-svelte": "^6.2.1",
|
|
74
73
|
"flowbite-svelte": "^1.28.1",
|
|
75
|
-
"flowbite-svelte-icons": "^3.0.0",
|
|
76
74
|
"prettier": "^3.7.4",
|
|
77
75
|
"prettier-plugin-svelte": "^3.4.1",
|
|
78
76
|
"svelte": "^5.0.0",
|