@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.
- package/README.md +38 -2
- package/dist/components/DataTable.svelte +490 -0
- package/dist/components/DataTable.svelte.d.ts +31 -0
- package/dist/components/DataTableControls.svelte +589 -0
- package/dist/components/DataTableControls.svelte.d.ts +39 -0
- package/{src → dist}/components/DataTableFilters.svelte +18 -3
- package/dist/components/DataTableFilters.svelte.d.ts +37 -0
- package/dist/components/FiltersModal.svelte +72 -0
- package/dist/components/FiltersModal.svelte.d.ts +25 -0
- package/dist/components/PaginationBar.svelte.d.ts +15 -0
- package/{src → dist}/components/filters/FilterColumn.svelte +10 -3
- package/dist/components/filters/FilterColumn.svelte.d.ts +19 -0
- package/dist/components/filters/FilterDateRange.svelte.d.ts +19 -0
- package/{src → dist}/components/filters/FilterValueList.svelte +43 -10
- package/dist/components/filters/FilterValueList.svelte.d.ts +33 -0
- package/dist/components/filters/useFilterState.svelte.d.ts +25 -0
- package/dist/components/flowbite/DataTableControls.svelte +528 -0
- package/dist/components/flowbite/DataTableControls.svelte.d.ts +39 -0
- package/{src/components → dist/components/flowbite}/FiltersModal.svelte +5 -4
- package/dist/components/flowbite/FiltersModal.svelte.d.ts +25 -0
- package/dist/filterUtils.d.ts +76 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.flowbite.d.ts +3 -0
- package/dist/index.flowbite.js +9 -0
- package/{src/lib → dist}/index.js +7 -7
- package/{src/lib → dist}/styles.css +11 -1
- package/package.json +37 -18
- package/src/components/DataTable.svelte +0 -234
- package/src/components/DataTableControls.svelte +0 -270
- package/src/lib/dist/styles.css +0 -287
- /package/{src → dist}/components/PaginationBar.svelte +0 -0
- /package/{src → dist}/components/filters/FilterDateRange.svelte +0 -0
- /package/{src → dist}/components/filters/useFilterState.svelte.js +0 -0
- /package/{src/lib → dist}/filterUtils.js +0 -0
package/README.md
CHANGED
|
@@ -21,12 +21,14 @@ npm install @zhangt58/svelte-vtable
|
|
|
21
21
|
|
|
22
22
|
## Peer Dependencies
|
|
23
23
|
|
|
24
|
-
This library requires the following peer dependencies
|
|
24
|
+
This library requires the following peer dependencies:
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
npm install svelte@^5.0.0 tailwindcss@^4.0.0
|
|
27
|
+
npm install svelte@^5.0.0 tailwindcss@^4.0.0 svelte-virtuallists@^1.0.0
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
`flowbite-svelte` is **optional** — only needed if you use the Flowbite adapter (see [Flowbite Adapter](#flowbite-adapter)).
|
|
31
|
+
|
|
30
32
|
## Quick Start
|
|
31
33
|
|
|
32
34
|
```svelte
|
|
@@ -98,6 +100,40 @@ npm install svelte@^5.0.0 tailwindcss@^4.0.0 flowbite-svelte@^1.0.0 flowbite-sve
|
|
|
98
100
|
</DataTable>
|
|
99
101
|
```
|
|
100
102
|
|
|
103
|
+
## Flowbite Adapter
|
|
104
|
+
|
|
105
|
+
By default, `DataTableControls` uses **zero external UI-framework dependencies** — it renders using plain `<input>`, `<select>`, `<button>`, and `<nav>` elements with Tailwind utility classes.
|
|
106
|
+
|
|
107
|
+
If your project already uses **Flowbite**, you can opt in to the Flowbite-flavoured controls by importing from the `/flowbite` entrypoint:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# Install optional Flowbite peer dependencies
|
|
111
|
+
npm install flowbite-svelte@^1.0.0
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
```svelte
|
|
115
|
+
<script>
|
|
116
|
+
// Import Flowbite-flavoured DataTableControls (Search, Badge, Select, Modal)
|
|
117
|
+
import { DataTable, DataTableControls, DataTableFilters } from '@zhangt58/svelte-vtable/flowbite';
|
|
118
|
+
</script>
|
|
119
|
+
|
|
120
|
+
<DataTableControls
|
|
121
|
+
search={searchQuery}
|
|
122
|
+
{currentPage}
|
|
123
|
+
bind:perPage
|
|
124
|
+
totalItems={items.length}
|
|
125
|
+
onpage={({ page }) => (currentPage = page)}
|
|
126
|
+
onsearch={({ search }) => (searchQuery = search)}
|
|
127
|
+
{columnFilters}
|
|
128
|
+
{activeFilters}
|
|
129
|
+
onfilter={handleFilterChange}
|
|
130
|
+
/>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The Flowbite entrypoint re-exports everything from the default entrypoint, so you can use a single import for all components and utilities.
|
|
134
|
+
|
|
135
|
+
See [`examples/flowbite/App.svelte`](./examples/flowbite/App.svelte) for a complete working example.
|
|
136
|
+
|
|
101
137
|
## Components
|
|
102
138
|
|
|
103
139
|
### DataTable (previously named VirtualDataTable)
|
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { VirtualList } from 'svelte-virtuallists';
|
|
3
|
+
|
|
4
|
+
// Runic props: accept props via $props() so the component matches the
|
|
5
|
+
// project's runes-style components. Include the `select` callback prop.
|
|
6
|
+
let {
|
|
7
|
+
items = [],
|
|
8
|
+
// Unified column definitions array (required).
|
|
9
|
+
// @type {import('../index.js').ColumnDef[]}
|
|
10
|
+
columns = [],
|
|
11
|
+
// sortKey/sortDir are bindable so parents can observe or control sort state.
|
|
12
|
+
sortKey = $bindable(null),
|
|
13
|
+
sortDir = $bindable('asc'),
|
|
14
|
+
className = '',
|
|
15
|
+
style = '',
|
|
16
|
+
emptyMessage = 'No items to display.',
|
|
17
|
+
selected = null,
|
|
18
|
+
// onselect({ item, index }) — called when a row is selected
|
|
19
|
+
onselect = undefined,
|
|
20
|
+
// onsort({ key, dir }) is called whenever sort changes.
|
|
21
|
+
// When provided, no local sorting is applied (server-side sort pattern).
|
|
22
|
+
onsort = undefined,
|
|
23
|
+
// Allow consumers to disable virtualization (useful when paginating by fixed item counts).
|
|
24
|
+
// If `virtualize` is false we ask the wrapped VirtualList to render as a normal list/table
|
|
25
|
+
// by setting its `isDisabled` prop. Default: true (virtualization enabled).
|
|
26
|
+
virtualize = true,
|
|
27
|
+
} = $props();
|
|
28
|
+
|
|
29
|
+
// --- Derived values from ColumnDef[] ---
|
|
30
|
+
|
|
31
|
+
// Keys of columns to display.
|
|
32
|
+
const effectiveVisibleKeys = $derived(columns.map((c) => c.key));
|
|
33
|
+
|
|
34
|
+
// Width configuration: build an object keyed by column key.
|
|
35
|
+
const effectiveColWidths = $derived(
|
|
36
|
+
Object.fromEntries(columns.map((c) => [c.key, c.width ?? 1])),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// Fast lookup map: key → ColumnDef.
|
|
40
|
+
const colDefMap = $derived(Object.fromEntries(columns.map((c) => [c.key, c])));
|
|
41
|
+
|
|
42
|
+
// Internal sorted array derived from items + current sort state.
|
|
43
|
+
// When onsort is provided the parent manages sorting (server-side), so we
|
|
44
|
+
// pass items through unchanged. Otherwise we sort locally.
|
|
45
|
+
const sortedItems = $derived.by(() => {
|
|
46
|
+
if (onsort !== undefined || !sortKey) return items;
|
|
47
|
+
|
|
48
|
+
const key = sortKey;
|
|
49
|
+
const dir = sortDir;
|
|
50
|
+
return [...items].sort((a, b) => {
|
|
51
|
+
const aVal = a[key];
|
|
52
|
+
const bVal = b[key];
|
|
53
|
+
|
|
54
|
+
// Handle null/undefined values
|
|
55
|
+
if (aVal == null && bVal == null) return 0;
|
|
56
|
+
if (aVal == null) return 1;
|
|
57
|
+
if (bVal == null) return -1;
|
|
58
|
+
|
|
59
|
+
// Convert to strings for comparison
|
|
60
|
+
const aStr = String(aVal);
|
|
61
|
+
const bStr = String(bVal);
|
|
62
|
+
|
|
63
|
+
// Alphabetical comparison
|
|
64
|
+
const comparison = aStr.localeCompare(bStr, undefined, {
|
|
65
|
+
numeric: true,
|
|
66
|
+
sensitivity: 'base',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return dir === 'asc' ? comparison : -comparison;
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// expose selection via the callback prop (if provided)
|
|
74
|
+
function selectItem(item, index) {
|
|
75
|
+
selected = item;
|
|
76
|
+
try {
|
|
77
|
+
if (onselect !== undefined) {
|
|
78
|
+
onselect({ item, index });
|
|
79
|
+
}
|
|
80
|
+
} catch (err) {
|
|
81
|
+
try {
|
|
82
|
+
console.error('onselect threw:', err);
|
|
83
|
+
} catch (e) {}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// When a header is clicked, toggle/update sortKey and sortDir, then notify
|
|
88
|
+
// the parent via onsort. Parents using bind:sortKey / bind:sortDir will
|
|
89
|
+
// receive the updated values automatically.
|
|
90
|
+
function handleSort(key) {
|
|
91
|
+
if (sortKey === key) {
|
|
92
|
+
sortDir = sortDir === 'asc' ? 'desc' : 'asc';
|
|
93
|
+
} else {
|
|
94
|
+
sortKey = key;
|
|
95
|
+
sortDir = 'asc';
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
if (onsort) onsort({ key: sortKey, dir: sortDir });
|
|
99
|
+
} catch (err) {
|
|
100
|
+
try {
|
|
101
|
+
console.error('onsort threw:', err);
|
|
102
|
+
} catch (e) {}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Normalize colWidths: treat numeric values as stretch weights and pass through CSS strings.
|
|
107
|
+
// Memoized: only recomputes when effectiveVisibleKeys or effectiveColWidths changes.
|
|
108
|
+
const colWidthMap = $derived(normalizeColWidths());
|
|
109
|
+
|
|
110
|
+
function normalizeColWidths() {
|
|
111
|
+
const map = {};
|
|
112
|
+
const keys = effectiveVisibleKeys;
|
|
113
|
+
const widths = effectiveColWidths;
|
|
114
|
+
|
|
115
|
+
const numeric = [];
|
|
116
|
+
const otherStrings = [];
|
|
117
|
+
|
|
118
|
+
for (const key of keys) {
|
|
119
|
+
const v = widths[key];
|
|
120
|
+
if (typeof v === 'number' && !Number.isNaN(v)) {
|
|
121
|
+
numeric.push({ key, w: v });
|
|
122
|
+
} else if (typeof v === 'string') {
|
|
123
|
+
const s = v.trim();
|
|
124
|
+
if (!s.endsWith('%')) {
|
|
125
|
+
otherStrings.push({ key, v: s });
|
|
126
|
+
}
|
|
127
|
+
// percent strings are intentionally unsupported — ignore silently
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const totalWeight = numeric.reduce((s, r) => s + r.w, 0);
|
|
132
|
+
const availablePct = 100;
|
|
133
|
+
|
|
134
|
+
if (numeric.length > 0 && totalWeight > 0) {
|
|
135
|
+
let acc = 0;
|
|
136
|
+
numeric.forEach((n, idx) => {
|
|
137
|
+
const pct =
|
|
138
|
+
idx === numeric.length - 1
|
|
139
|
+
? Math.max(0, Math.round((availablePct - acc) * 100) / 100)
|
|
140
|
+
: Math.round((n.w / totalWeight) * availablePct * 100) / 100;
|
|
141
|
+
map[n.key] = `${pct}%`;
|
|
142
|
+
acc += pct;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Copy through non-percent CSS strings (e.g. '120px')
|
|
147
|
+
for (const o of otherStrings) {
|
|
148
|
+
map[o.key] = o.v;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return map;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Compute column width by key (fallback to even distribution)
|
|
155
|
+
function calcColWidth(key) {
|
|
156
|
+
if (colWidthMap[key] !== undefined) return String(colWidthMap[key]);
|
|
157
|
+
const n = Math.max(1, effectiveVisibleKeys.length);
|
|
158
|
+
return Math.floor(100 / n) + '%';
|
|
159
|
+
}
|
|
160
|
+
</script>
|
|
161
|
+
|
|
162
|
+
<section class="virtual-data-table {className}" {style}>
|
|
163
|
+
{#if items && items.length > 0}
|
|
164
|
+
<!-- When `virtualize` is false we instruct VirtualList to render as a normal list/table
|
|
165
|
+
by setting `isDisabled`. This ensures pagination based on item counts shows the
|
|
166
|
+
exact number of rows expected (useful when rows have variable height). -->
|
|
167
|
+
<VirtualList
|
|
168
|
+
items={sortedItems}
|
|
169
|
+
isTable
|
|
170
|
+
isDisabled={!virtualize}
|
|
171
|
+
class="datatable-table max-w-full max-h-full overflow-auto"
|
|
172
|
+
>
|
|
173
|
+
<!-- colgroup enforces the column widths so table-layout: fixed distributes as intended -->
|
|
174
|
+
{#snippet header()}
|
|
175
|
+
<colgroup>
|
|
176
|
+
{#each effectiveVisibleKeys as key}
|
|
177
|
+
<col style="width: {calcColWidth(key)}" />
|
|
178
|
+
{/each}
|
|
179
|
+
</colgroup>
|
|
180
|
+
<thead class="sticky-header">
|
|
181
|
+
<tr>
|
|
182
|
+
{#each effectiveVisibleKeys as key}
|
|
183
|
+
{@const colDef = colDefMap[key]}
|
|
184
|
+
{@const label = colDef?.label ?? key}
|
|
185
|
+
{@const isSortable = colDef?.sortable !== false}
|
|
186
|
+
<th
|
|
187
|
+
style="width: {calcColWidth(key)}"
|
|
188
|
+
class={isSortable ? 'cursor-pointer select-none' : 'select-none'}
|
|
189
|
+
onclick={isSortable ? () => handleSort(key) : undefined}
|
|
190
|
+
aria-sort={sortKey === key
|
|
191
|
+
? sortDir === 'asc'
|
|
192
|
+
? 'ascending'
|
|
193
|
+
: 'descending'
|
|
194
|
+
: 'none'}
|
|
195
|
+
>
|
|
196
|
+
{#if colDef?.headerSnippet}
|
|
197
|
+
{@render colDef.headerSnippet({ key, label, sortKey, sortDir })}
|
|
198
|
+
{:else}
|
|
199
|
+
<div class="inline-flex items-center gap-1">
|
|
200
|
+
<span>{label}</span>
|
|
201
|
+
{#if sortKey === key}
|
|
202
|
+
<span aria-hidden="true">{sortDir === 'asc' ? '▲' : '▼'}</span>
|
|
203
|
+
{/if}
|
|
204
|
+
</div>
|
|
205
|
+
{/if}
|
|
206
|
+
</th>
|
|
207
|
+
{/each}
|
|
208
|
+
</tr>
|
|
209
|
+
</thead>
|
|
210
|
+
{/snippet}
|
|
211
|
+
|
|
212
|
+
{#snippet vl_slot({ index, item })}
|
|
213
|
+
<!-- Default row rendering using each column's cellSnippet or raw value -->
|
|
214
|
+
<tr onclick={() => selectItem(item, index)} class={selected === item ? 'selected' : ''}>
|
|
215
|
+
{#each columns as col}
|
|
216
|
+
<td>
|
|
217
|
+
{#if col.cellSnippet}
|
|
218
|
+
{@render col.cellSnippet({ item, value: item[col.key], index })}
|
|
219
|
+
{:else}
|
|
220
|
+
{item[col.key] ?? ''}
|
|
221
|
+
{/if}
|
|
222
|
+
</td>
|
|
223
|
+
{/each}
|
|
224
|
+
</tr>
|
|
225
|
+
{/snippet}
|
|
226
|
+
</VirtualList>
|
|
227
|
+
{:else}
|
|
228
|
+
<div class="p-4 text-center text-slate-500">{emptyMessage}</div>
|
|
229
|
+
{/if}
|
|
230
|
+
</section>
|
|
231
|
+
|
|
232
|
+
<style>/* ── Theming contract — override these on :root or any wrapper element ── */
|
|
233
|
+
:root {
|
|
234
|
+
--vtable-color-accent: #16a34a; /* green-600 */
|
|
235
|
+
--vtable-color-accent-light: #dcfce7; /* green-100 */
|
|
236
|
+
--vtable-color-accent-border: #22c55e; /* green-500 */
|
|
237
|
+
--vtable-color-accent-text: #15803d; /* green-700 */
|
|
238
|
+
|
|
239
|
+
--vtable-color-danger: #dc2626; /* red-600 */
|
|
240
|
+
--vtable-color-info: #3b82f6; /* blue-500 */
|
|
241
|
+
|
|
242
|
+
--vtable-radius: 0.375rem; /* rounded-md */
|
|
243
|
+
--vtable-row-height: 2.25rem; /* default row height hint for virtual scroll */
|
|
244
|
+
}
|
|
245
|
+
.virtual-data-table {
|
|
246
|
+
display: block;
|
|
247
|
+
min-width: 0;
|
|
248
|
+
height: 100%;
|
|
249
|
+
overflow: auto;
|
|
250
|
+
isolation: isolate;
|
|
251
|
+
}
|
|
252
|
+
:global(.datatable-table) {
|
|
253
|
+
display: table;
|
|
254
|
+
width: 100%;
|
|
255
|
+
min-width: 0;
|
|
256
|
+
border-collapse: collapse;
|
|
257
|
+
box-sizing: border-box;
|
|
258
|
+
font-size: 0.875rem; /* 14px - smaller, more compact */
|
|
259
|
+
font-family:
|
|
260
|
+
-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
|
|
261
|
+
line-height: 1.4;
|
|
262
|
+
border: none;
|
|
263
|
+
}
|
|
264
|
+
/* Sticky header support */
|
|
265
|
+
:global(.datatable-table) thead.sticky-header {
|
|
266
|
+
position: sticky;
|
|
267
|
+
top: 0;
|
|
268
|
+
z-index: 2;
|
|
269
|
+
}
|
|
270
|
+
/* Header visual styles - only bottom border */
|
|
271
|
+
:global(.datatable-table) thead th {
|
|
272
|
+
background-color: #f8f9fa;
|
|
273
|
+
font-size: 0.8125rem; /* 13px */
|
|
274
|
+
font-weight: 600;
|
|
275
|
+
text-transform: uppercase;
|
|
276
|
+
letter-spacing: 0.025em;
|
|
277
|
+
border-top: none;
|
|
278
|
+
border-left: none;
|
|
279
|
+
border-right: none;
|
|
280
|
+
border-bottom: 1px solid #dee2e6;
|
|
281
|
+
padding: 0.5rem 0.5rem;
|
|
282
|
+
text-align: left;
|
|
283
|
+
white-space: normal; /* Allow header text to wrap */
|
|
284
|
+
overflow: visible;
|
|
285
|
+
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1); /* Keep border visible on scroll */
|
|
286
|
+
}
|
|
287
|
+
/* Row striping - alternating colors */
|
|
288
|
+
/* VirtualList may wrap rows, so we target tr directly */
|
|
289
|
+
:global(.datatable-table tbody tr:nth-of-type(even)) {
|
|
290
|
+
background-color: #ffffff;
|
|
291
|
+
}
|
|
292
|
+
:global(.datatable-table tbody tr:nth-of-type(odd)) {
|
|
293
|
+
background-color: #f8f9fa;
|
|
294
|
+
}
|
|
295
|
+
/* Also ensure tr elements themselves have background */
|
|
296
|
+
:global(.datatable-table tbody tr) {
|
|
297
|
+
background-color: inherit;
|
|
298
|
+
}
|
|
299
|
+
/* Hover effect */
|
|
300
|
+
:global(.datatable-table tbody tr:hover) {
|
|
301
|
+
background-color: #e7f1ff !important;
|
|
302
|
+
transition: background-color 0.15s ease-in-out;
|
|
303
|
+
}
|
|
304
|
+
/* Selesky-500 row overrides striping and hover */
|
|
305
|
+
:global(.datatable-table tbody tr.selected-row) {
|
|
306
|
+
background-color: #e0f2fe !important; /* light sky background */
|
|
307
|
+
box-shadow: inset 4px 0 0 0 #0369a1; /* left accent */
|
|
308
|
+
}
|
|
309
|
+
:global(.dark) :global(.datatable-table tbody tr.selected-row) {
|
|
310
|
+
/* brighter, higher-contrast selection in dark mode */
|
|
311
|
+
background-color: rgba(14, 165, 233, 0.22) !important; /* stronger visible blue */
|
|
312
|
+
box-shadow: inset 6px 0 0 0 rgba(56, 189, 248, 0.85); /* stronger left accent */
|
|
313
|
+
transition:
|
|
314
|
+
background-color 0.12s ease-in-out,
|
|
315
|
+
box-shadow 0.12s ease-in-out;
|
|
316
|
+
}
|
|
317
|
+
/* Also apply to cells to defeat any cell-level background from striping and ensure readable text */
|
|
318
|
+
:global(.datatable-table tbody tr.selected-row) td {
|
|
319
|
+
background-color: #e0f2fe !important;
|
|
320
|
+
}
|
|
321
|
+
:global(.dark) :global(.datatable-table tbody tr.selected-row) td {
|
|
322
|
+
background-color: rgba(14, 165, 233, 0.22) !important;
|
|
323
|
+
color: #f0fbff !important; /* ensure high-contrast, very light text */
|
|
324
|
+
border-bottom-color: rgba(255, 255, 255, 0.06);
|
|
325
|
+
}
|
|
326
|
+
/* Body cell defaults - only bottom border */
|
|
327
|
+
:global(.datatable-table tbody td) {
|
|
328
|
+
padding: 0.5rem 0.5rem;
|
|
329
|
+
border-top: none;
|
|
330
|
+
border-left: none;
|
|
331
|
+
border-right: none;
|
|
332
|
+
border-bottom: 1px solid #e9ecef;
|
|
333
|
+
vertical-align: middle;
|
|
334
|
+
text-align: left;
|
|
335
|
+
font-size: 0.875rem; /* 14px */
|
|
336
|
+
overflow: hidden;
|
|
337
|
+
white-space: normal; /* Allow wrapping by default */
|
|
338
|
+
word-wrap: break-word;
|
|
339
|
+
box-sizing: border-box;
|
|
340
|
+
}
|
|
341
|
+
/* No-wrap variant for cells that should truncate */
|
|
342
|
+
:global(.datatable-table tbody td.nowrap) {
|
|
343
|
+
white-space: nowrap;
|
|
344
|
+
text-overflow: ellipsis;
|
|
345
|
+
}
|
|
346
|
+
/* Compact variant */
|
|
347
|
+
:global(.datatable-table.compact tbody td) {
|
|
348
|
+
padding: 0.1rem 0.3rem;
|
|
349
|
+
}
|
|
350
|
+
/* Header content alignment helper */
|
|
351
|
+
:global(.datatable-table thead th > div) {
|
|
352
|
+
display: inline-flex;
|
|
353
|
+
align-items: center;
|
|
354
|
+
gap: 0.25rem;
|
|
355
|
+
}
|
|
356
|
+
/* Allow certain long cells to wrap fully if explicitly requested */
|
|
357
|
+
:global(.datatable-table td.wrap) {
|
|
358
|
+
white-space: normal;
|
|
359
|
+
word-break: break-word;
|
|
360
|
+
}
|
|
361
|
+
/* Dark mode variants for the datatable */
|
|
362
|
+
:global(.dark) :global(.datatable-table thead th) {
|
|
363
|
+
background-color: #1f2937;
|
|
364
|
+
border-bottom-color: #374151;
|
|
365
|
+
color: #f9fafb;
|
|
366
|
+
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.3); /* Darker shadow for dark mode */
|
|
367
|
+
}
|
|
368
|
+
:global(.dark) :global(.datatable-table tbody tr:nth-of-type(even)) {
|
|
369
|
+
background-color: #111827;
|
|
370
|
+
}
|
|
371
|
+
:global(.dark) :global(.datatable-table tbody tr:nth-of-type(odd)) {
|
|
372
|
+
background-color: #1f2937;
|
|
373
|
+
}
|
|
374
|
+
:global(.dark) :global(.datatable-table tbody tr:hover) {
|
|
375
|
+
background-color: #374151 !important;
|
|
376
|
+
}
|
|
377
|
+
:global(.dark) :global(.datatable-table tbody td) {
|
|
378
|
+
border-bottom-color: #374151;
|
|
379
|
+
color: #e5e7eb;
|
|
380
|
+
}
|
|
381
|
+
/* Shared control styles (inputs, pagination, column filters) used by page components */
|
|
382
|
+
/* Accent-color focus ring for search input and per-page select — respects --vtable-color-accent */
|
|
383
|
+
:global(.vtable-search-input:focus),
|
|
384
|
+
:global(.vtable-perpage-select:focus) {
|
|
385
|
+
border-color: var(--vtable-color-accent-border);
|
|
386
|
+
box-shadow: 0 0 0 2px color-mix(in srgb, var(--vtable-color-accent) 20%, transparent);
|
|
387
|
+
outline: none;
|
|
388
|
+
}
|
|
389
|
+
:global(.datatable-input) {
|
|
390
|
+
padding: 0.375rem 0.75rem;
|
|
391
|
+
font-size: 0.95rem;
|
|
392
|
+
border: 1px solid #ced4da;
|
|
393
|
+
border-radius: 0.25rem;
|
|
394
|
+
}
|
|
395
|
+
:global(.datatable-input:focus) {
|
|
396
|
+
border-color: #86b7fe;
|
|
397
|
+
outline: 0;
|
|
398
|
+
box-shadow: 0 0 0.1rem 0.2rem rgba(13, 110, 253, 0.25);
|
|
399
|
+
}
|
|
400
|
+
:global(.search-filtering-row) {
|
|
401
|
+
background-color: #f8f9fa;
|
|
402
|
+
}
|
|
403
|
+
:global(.search-filtering-row th) {
|
|
404
|
+
padding: 0.1rem 0.1rem;
|
|
405
|
+
border-bottom: 1px solid #dee2e6;
|
|
406
|
+
}
|
|
407
|
+
:global(.column-filter) {
|
|
408
|
+
width: 95%;
|
|
409
|
+
padding: 0.2rem 0.25rem;
|
|
410
|
+
font-size: 0.8rem;
|
|
411
|
+
border: 1px solid #ced4da;
|
|
412
|
+
border-radius: 0.25rem;
|
|
413
|
+
}
|
|
414
|
+
:global(.column-filter::placeholder) {
|
|
415
|
+
color: #adb5bd;
|
|
416
|
+
font-size: 0.75rem;
|
|
417
|
+
font-style: italic;
|
|
418
|
+
}
|
|
419
|
+
:global(.datatable-pagination) {
|
|
420
|
+
display: flex;
|
|
421
|
+
gap: 0.1rem;
|
|
422
|
+
margin-top: 0.6rem;
|
|
423
|
+
}
|
|
424
|
+
:global(.datatable-pagination li a),
|
|
425
|
+
:global(.datatable-pagination li button) {
|
|
426
|
+
padding: 0.3rem 0.7rem;
|
|
427
|
+
border: 1px solid #dee2e6;
|
|
428
|
+
border-radius: 0;
|
|
429
|
+
background-color: #fff;
|
|
430
|
+
color: #0d6efd;
|
|
431
|
+
text-decoration: none;
|
|
432
|
+
}
|
|
433
|
+
:global(.datatable-pagination li a:hover),
|
|
434
|
+
:global(.datatable-pagination li button:hover) {
|
|
435
|
+
background-color: #e9ecef;
|
|
436
|
+
}
|
|
437
|
+
:global(.datatable-pagination .datatable-active a),
|
|
438
|
+
:global(.datatable-pagination .datatable-active button) {
|
|
439
|
+
background-color: #0d6efd;
|
|
440
|
+
border-color: #0d6efd;
|
|
441
|
+
color: #fff;
|
|
442
|
+
}
|
|
443
|
+
/* Force the active/current page to use the accent tokens (override flowbite's primary/orange).
|
|
444
|
+
Intentionally specific to reliably win over third-party rules. */
|
|
445
|
+
:global([data-pagination-id] ul li [aria-current='page']) {
|
|
446
|
+
background-color: var(--vtable-color-accent-light) !important;
|
|
447
|
+
color: var(--vtable-color-accent) !important;
|
|
448
|
+
border-color: transparent !important;
|
|
449
|
+
}
|
|
450
|
+
/* Ensure Prev/Next controls visually match the numeric buttons' border and rhythm
|
|
451
|
+
(keeps border, radius and min-width consistent). This is minimal and won't
|
|
452
|
+
override hover/text colors managed by Tailwind classes applied at runtime. */
|
|
453
|
+
:global([data-pagination-id] ul li:first-child > button),
|
|
454
|
+
:global([data-pagination-id] ul li:first-child > a),
|
|
455
|
+
:global([data-pagination-id] ul li:last-child > button),
|
|
456
|
+
:global([data-pagination-id] ul li:last-child > a) {
|
|
457
|
+
border: 1px solid #d1d5db; /* border-gray-300 */
|
|
458
|
+
min-width: 2rem; /* align with numeric buttons' min width */
|
|
459
|
+
background: transparent;
|
|
460
|
+
padding: 0.25rem 0.5rem; /* keep comfortable hit area */
|
|
461
|
+
}
|
|
462
|
+
/* Light mode: hover/focus for Prev/Next match numeric button hover */
|
|
463
|
+
:global([data-pagination-id] ul li:first-child > button:hover),
|
|
464
|
+
:global([data-pagination-id] ul li:first-child > a:hover),
|
|
465
|
+
:global([data-pagination-id] ul li:last-child > button:hover),
|
|
466
|
+
:global([data-pagination-id] ul li:last-child > a:hover),
|
|
467
|
+
:global([data-pagination-id] ul li:first-child > button:focus),
|
|
468
|
+
:global([data-pagination-id] ul li:first-child > a:focus),
|
|
469
|
+
:global([data-pagination-id] ul li:last-child > button:focus),
|
|
470
|
+
:global([data-pagination-id] ul li:last-child > a:focus) {
|
|
471
|
+
background-color: #f3f4f6; /* tailwind gray-100 */
|
|
472
|
+
outline: none;
|
|
473
|
+
}
|
|
474
|
+
/* Ellipsis styling: make clickable and visually lighter (JS sets data-ellipsis/data-jump) */
|
|
475
|
+
:global([data-pagination-id] ul li [data-ellipsis='true']) {
|
|
476
|
+
cursor: pointer;
|
|
477
|
+
background: transparent !important;
|
|
478
|
+
color: inherit;
|
|
479
|
+
opacity: 0.9;
|
|
480
|
+
font-size: 0.875rem;
|
|
481
|
+
padding: 0.25rem 0.5rem;
|
|
482
|
+
}
|
|
483
|
+
/* Chevron sizing for Prev/Next so icons sit comfortably in the buttons */
|
|
484
|
+
:global([data-pagination-id] ul li:first-child svg),
|
|
485
|
+
:global([data-pagination-id] ul li:last-child svg) {
|
|
486
|
+
height: 1.25rem;
|
|
487
|
+
width: 1.25rem;
|
|
488
|
+
display: block;
|
|
489
|
+
}
|
|
490
|
+
</style>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export default DataTable;
|
|
2
|
+
type DataTable = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const DataTable: import("svelte").Component<{
|
|
7
|
+
items?: any[];
|
|
8
|
+
columns?: any[];
|
|
9
|
+
sortKey?: any;
|
|
10
|
+
sortDir?: string;
|
|
11
|
+
className?: string;
|
|
12
|
+
style?: string;
|
|
13
|
+
emptyMessage?: string;
|
|
14
|
+
selected?: any;
|
|
15
|
+
onselect?: any;
|
|
16
|
+
onsort?: any;
|
|
17
|
+
virtualize?: boolean;
|
|
18
|
+
}, {}, "sortKey" | "sortDir">;
|
|
19
|
+
type $$ComponentProps = {
|
|
20
|
+
items?: any[];
|
|
21
|
+
columns?: any[];
|
|
22
|
+
sortKey?: any;
|
|
23
|
+
sortDir?: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
style?: string;
|
|
26
|
+
emptyMessage?: string;
|
|
27
|
+
selected?: any;
|
|
28
|
+
onselect?: any;
|
|
29
|
+
onsort?: any;
|
|
30
|
+
virtualize?: boolean;
|
|
31
|
+
};
|