@zhangt58/svelte-vtable 0.5.0 → 0.6.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.
- package/README.md +123 -32
- package/dist/components/DataTable.svelte +409 -16
- package/dist/components/DataTable.svelte.d.ts +11 -1
- package/dist/components/DataTableControls.svelte +102 -0
- package/dist/components/flowbite/DataTableControls.svelte +102 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +8 -0
- package/dist/styles.css +176 -62
- package/package.json +3 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
+
import { untrack } from 'svelte';
|
|
2
3
|
import { VirtualList } from 'svelte-virtuallists';
|
|
3
4
|
import ColumnHeaderFilter from './filters/ColumnHeaderFilter.svelte';
|
|
4
5
|
import { useFilterState } from './filters/useFilterState.svelte.js';
|
|
@@ -53,6 +54,19 @@
|
|
|
53
54
|
virtualize = true,
|
|
54
55
|
// Row density: 'comfortable' (default) or 'compact' (tighter cell padding).
|
|
55
56
|
density = 'comfortable',
|
|
57
|
+
// Drag a header's right edge to resize its column (ColumnDef.resizable: false opts out).
|
|
58
|
+
resizable = false,
|
|
59
|
+
// User-set column widths in px, keyed by column key. Bindable; empty means
|
|
60
|
+
// the declared widths. Once any column is resized the table switches to a
|
|
61
|
+
// fixed layout whose width is the sum of the column widths.
|
|
62
|
+
columnWidths = $bindable({}),
|
|
63
|
+
// oncolumnresize({ key, width, widths }) — called when a resize ends.
|
|
64
|
+
oncolumnresize = undefined,
|
|
65
|
+
// When set, columnWidths are saved to and restored from localStorage under this key.
|
|
66
|
+
storageKey = undefined,
|
|
67
|
+
// Wrap long cell text (default). When false, cells stay on one line and
|
|
68
|
+
// truncated text is shown in a tooltip. ColumnDef.wrap overrides per column.
|
|
69
|
+
wrap = true,
|
|
56
70
|
} = $props();
|
|
57
71
|
|
|
58
72
|
// --- Derived values from ColumnDef[] ---
|
|
@@ -69,9 +83,10 @@
|
|
|
69
83
|
const colDefMap = $derived(Object.fromEntries(columns.map((c) => [c.key, c])));
|
|
70
84
|
|
|
71
85
|
// --- Sticky columns ---
|
|
72
|
-
// Header cell widths
|
|
73
|
-
//
|
|
74
|
-
|
|
86
|
+
// Header cell widths, measured (bind:offsetWidth), so the sticky offsets hold
|
|
87
|
+
// whatever the width type (stretch weight or CSS length). Also the starting
|
|
88
|
+
// point of the first column resize.
|
|
89
|
+
let headerWidths = $state({});
|
|
75
90
|
|
|
76
91
|
// key → { side, offset, edge } for columns with `sticky: 'left' | 'right'`.
|
|
77
92
|
// A left column's offset is the width of the left sticky columns before it;
|
|
@@ -84,12 +99,12 @@
|
|
|
84
99
|
let acc = 0;
|
|
85
100
|
left.forEach((c, i) => {
|
|
86
101
|
map[c.key] = { side: 'left', offset: acc, edge: i === left.length - 1 };
|
|
87
|
-
acc +=
|
|
102
|
+
acc += headerWidths[c.key] ?? 0;
|
|
88
103
|
});
|
|
89
104
|
acc = 0;
|
|
90
105
|
right.forEach((c, i) => {
|
|
91
106
|
map[c.key] = { side: 'right', offset: acc, edge: i === right.length - 1 };
|
|
92
|
-
acc +=
|
|
107
|
+
acc += headerWidths[c.key] ?? 0;
|
|
93
108
|
});
|
|
94
109
|
return map;
|
|
95
110
|
});
|
|
@@ -104,11 +119,18 @@
|
|
|
104
119
|
// Set on the header content, it is a real minimum (a <col> width is only a
|
|
105
120
|
// hint under automatic table layout), so wide tables scroll sideways
|
|
106
121
|
// instead of squeezing their columns.
|
|
107
|
-
function
|
|
122
|
+
function declaredMinWidth(key) {
|
|
108
123
|
const c = colDefMap[key];
|
|
109
|
-
|
|
124
|
+
return (
|
|
110
125
|
c?.minWidth ??
|
|
111
|
-
(typeof c?.width === 'string' && !c.width.trim().endsWith('%') ? c.width : null)
|
|
126
|
+
(typeof c?.width === 'string' && !c.width.trim().endsWith('%') ? c.width : null)
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function minWidthStyle(key) {
|
|
131
|
+
// Under the fixed layout the column width already includes the minimum.
|
|
132
|
+
if (fixedLayout) return '';
|
|
133
|
+
const w = declaredMinWidth(key);
|
|
112
134
|
return w ? `min-width: ${w};` : '';
|
|
113
135
|
}
|
|
114
136
|
|
|
@@ -140,6 +162,220 @@
|
|
|
140
162
|
return () => ro.disconnect();
|
|
141
163
|
});
|
|
142
164
|
|
|
165
|
+
// --- Resizable columns ---
|
|
166
|
+
// Floor for user widths, so a column stays wide enough to grab again. A
|
|
167
|
+
// declared minWidth does not apply: it sizes the declared layout only, and
|
|
168
|
+
// the user may resize below it.
|
|
169
|
+
const MIN_RESIZE_WIDTH = 40;
|
|
170
|
+
// Width of a column that has no user width under the fixed layout and
|
|
171
|
+
// declares no CSS width either (a stretch weight has no meaning there).
|
|
172
|
+
const DEFAULT_FIXED_WIDTH = '10rem';
|
|
173
|
+
const STORAGE_PREFIX = 'svelte-vtable:column-widths:';
|
|
174
|
+
|
|
175
|
+
// { key, startX, startWidth } while a header edge is dragged.
|
|
176
|
+
let resizing = $state(null);
|
|
177
|
+
|
|
178
|
+
const fixedLayout = $derived(resizable && Object.keys(columnWidths ?? {}).length > 0);
|
|
179
|
+
|
|
180
|
+
function isResizable(key) {
|
|
181
|
+
return resizable && colDefMap[key]?.resizable !== false;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Column width under the fixed layout: the user width, else the declared
|
|
185
|
+
// CSS width or minimum.
|
|
186
|
+
function fixedColWidth(key) {
|
|
187
|
+
const px = columnWidths?.[key];
|
|
188
|
+
if (typeof px === 'number' && px > 0) return `${Math.max(MIN_RESIZE_WIDTH, px)}px`;
|
|
189
|
+
return declaredMinWidth(key) ?? DEFAULT_FIXED_WIDTH;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const fixedTableWidth = $derived(
|
|
193
|
+
fixedLayout ? `calc(${effectiveVisibleKeys.map(fixedColWidth).join(' + ')})` : '',
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
function readStoredWidths(key) {
|
|
197
|
+
try {
|
|
198
|
+
const parsed = JSON.parse(localStorage.getItem(STORAGE_PREFIX + key) ?? 'null');
|
|
199
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null;
|
|
200
|
+
} catch (e) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function writeStoredWidths(key, widths) {
|
|
206
|
+
try {
|
|
207
|
+
if (Object.keys(widths).length === 0) localStorage.removeItem(STORAGE_PREFIX + key);
|
|
208
|
+
else localStorage.setItem(STORAGE_PREFIX + key, JSON.stringify(widths));
|
|
209
|
+
} catch (e) {}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Restore saved widths before the first paint (and when the key changes).
|
|
213
|
+
$effect.pre(() => {
|
|
214
|
+
if (!storageKey) return;
|
|
215
|
+
const saved = readStoredWidths(storageKey);
|
|
216
|
+
untrack(() => {
|
|
217
|
+
columnWidths = saved ?? {};
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// Save widths when they change, but not on every pointer move of a drag.
|
|
222
|
+
$effect(() => {
|
|
223
|
+
if (!storageKey || resizing) return;
|
|
224
|
+
writeStoredWidths(storageKey, $state.snapshot(columnWidths) ?? {});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// The first resize pins every column at its current width, so switching to
|
|
228
|
+
// the fixed layout does not move the other columns.
|
|
229
|
+
function ensureFixedWidths() {
|
|
230
|
+
if (fixedLayout) return;
|
|
231
|
+
columnWidths = Object.fromEntries(
|
|
232
|
+
effectiveVisibleKeys.map((k) => [k, Math.round(headerWidths[k] ?? 0)]).filter(([, w]) => w),
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function setColumnWidth(key, width) {
|
|
237
|
+
columnWidths = { ...columnWidths, [key]: width };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function emitResize(key) {
|
|
241
|
+
try {
|
|
242
|
+
if (oncolumnresize)
|
|
243
|
+
oncolumnresize({ key, width: columnWidths[key], widths: $state.snapshot(columnWidths) });
|
|
244
|
+
} catch (err) {
|
|
245
|
+
try {
|
|
246
|
+
console.error('oncolumnresize threw:', err);
|
|
247
|
+
} catch (e) {}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function startResize(event, key) {
|
|
252
|
+
if (event.button !== 0) return;
|
|
253
|
+
event.preventDefault();
|
|
254
|
+
event.stopPropagation();
|
|
255
|
+
const handle = event.currentTarget;
|
|
256
|
+
const th = handle.closest('th');
|
|
257
|
+
ensureFixedWidths();
|
|
258
|
+
handle.setPointerCapture?.(event.pointerId);
|
|
259
|
+
resizing = {
|
|
260
|
+
key,
|
|
261
|
+
startX: event.clientX,
|
|
262
|
+
startWidth: th.offsetWidth,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function moveResize(event) {
|
|
267
|
+
if (!resizing) return;
|
|
268
|
+
const { key, startX, startWidth } = resizing;
|
|
269
|
+
setColumnWidth(
|
|
270
|
+
key,
|
|
271
|
+
Math.max(MIN_RESIZE_WIDTH, Math.round(startWidth + event.clientX - startX)),
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function endResize() {
|
|
276
|
+
if (!resizing) return;
|
|
277
|
+
const { key } = resizing;
|
|
278
|
+
resizing = null;
|
|
279
|
+
emitResize(key);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Double-clicking a header edge drops the user widths: the table returns to
|
|
283
|
+
// its declared layout. (A single column has no width to return to under the
|
|
284
|
+
// fixed layout when it declares only a stretch weight.)
|
|
285
|
+
function resetColumnWidths(key) {
|
|
286
|
+
if (!fixedLayout) return;
|
|
287
|
+
columnWidths = {};
|
|
288
|
+
emitResize(key);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// --- Grouped headers ---
|
|
292
|
+
// Runs of adjacent columns sharing ColumnDef.group, rendered as a header row
|
|
293
|
+
// above the column headers. A run is split where its columns' sticky side
|
|
294
|
+
// changes, so the sticky part can stick with its columns; only the first
|
|
295
|
+
// part shows the label.
|
|
296
|
+
const groupSegments = $derived.by(() => {
|
|
297
|
+
if (!columns.some((c) => c.group)) return [];
|
|
298
|
+
const segments = [];
|
|
299
|
+
for (const c of columns) {
|
|
300
|
+
const group = c.group || null;
|
|
301
|
+
const side = stickyMap[c.key]?.side ?? null;
|
|
302
|
+
const last = segments[segments.length - 1];
|
|
303
|
+
if (last && last.group === group && last.side === side) {
|
|
304
|
+
last.keys.push(c.key);
|
|
305
|
+
} else {
|
|
306
|
+
const cont = !!last && group !== null && last.group === group;
|
|
307
|
+
segments.push({ group, side, keys: [c.key], cont });
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return segments;
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
// Height of the group header row: the column header row sticks below it.
|
|
314
|
+
let groupRowHeight = $state(0);
|
|
315
|
+
|
|
316
|
+
function groupStickyKey(segment) {
|
|
317
|
+
if (!segment.side) return null;
|
|
318
|
+
return segment.side === 'left' ? segment.keys[0] : segment.keys[segment.keys.length - 1];
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function groupClass(segment) {
|
|
322
|
+
const base = segment.group
|
|
323
|
+
? `vtable-group-header${segment.cont ? ' vtable-group-cont' : ''}`
|
|
324
|
+
: 'vtable-group-header vtable-group-empty';
|
|
325
|
+
if (!segment.side) return base;
|
|
326
|
+
const edge = segment.keys.some((k) => stickyMap[k]?.edge);
|
|
327
|
+
return `${base} vtable-sticky vtable-sticky-${segment.side}${edge ? ` vtable-sticky-edge-${segment.side}` : ''}`;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// --- Truncated text ---
|
|
331
|
+
function cellWraps(col) {
|
|
332
|
+
return col.wrap ?? wrap;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function isTruncated(el) {
|
|
336
|
+
return (
|
|
337
|
+
el.clientWidth > 0 &&
|
|
338
|
+
(el.scrollWidth > el.clientWidth + 1 || el.scrollHeight > el.clientHeight + 1)
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// On hover, give a body cell (or header label) whose text is cut off a
|
|
343
|
+
// tooltip with the full text. Checks the hovered element and its ancestors
|
|
344
|
+
// up to the cell, so truncation inside custom cell snippets counts too.
|
|
345
|
+
function revealTruncated(event) {
|
|
346
|
+
const target = /** @type {Element} */ (event.target);
|
|
347
|
+
if (!target?.closest) return;
|
|
348
|
+
const label = target.closest('.vtable-header-label');
|
|
349
|
+
if (label) {
|
|
350
|
+
setAutoTitle(label, isTruncated(label) ? label.textContent : null);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const td = target.closest('td');
|
|
354
|
+
if (!td || !scroller?.contains(td)) return;
|
|
355
|
+
let text = null;
|
|
356
|
+
for (let el = target; el; el = el.parentElement) {
|
|
357
|
+
if (isTruncated(el)) {
|
|
358
|
+
text = el.textContent;
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
if (el === td) break;
|
|
362
|
+
}
|
|
363
|
+
setAutoTitle(td, text);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Only touch titles this component set, never a consumer's.
|
|
367
|
+
function setAutoTitle(el, text) {
|
|
368
|
+
const full = text?.replace(/\s+/g, ' ').trim();
|
|
369
|
+
if (full) {
|
|
370
|
+
if (el.hasAttribute('title') && !el.hasAttribute('data-vtable-auto-title')) return;
|
|
371
|
+
el.setAttribute('title', full);
|
|
372
|
+
el.setAttribute('data-vtable-auto-title', '');
|
|
373
|
+
} else if (el.hasAttribute('data-vtable-auto-title')) {
|
|
374
|
+
el.removeAttribute('title');
|
|
375
|
+
el.removeAttribute('data-vtable-auto-title');
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
143
379
|
const effectiveColumnFilters = $derived.by(() => {
|
|
144
380
|
return resolveColumnFilters({
|
|
145
381
|
columnFilters,
|
|
@@ -304,6 +540,7 @@
|
|
|
304
540
|
|
|
305
541
|
// Compute column width by key (fallback to even distribution)
|
|
306
542
|
function calcColWidth(key) {
|
|
543
|
+
if (fixedLayout) return fixedColWidth(key);
|
|
307
544
|
if (colWidthMap[key] !== undefined) return String(colWidthMap[key]);
|
|
308
545
|
const n = Math.max(1, effectiveVisibleKeys.length);
|
|
309
546
|
return Math.floor(100 / n) + '%';
|
|
@@ -312,11 +549,16 @@
|
|
|
312
549
|
|
|
313
550
|
<svelte:window onclick={closeFilter} onkeydown={handleKeydown} />
|
|
314
551
|
|
|
552
|
+
<!-- pointerover only adds tooltips to truncated text -->
|
|
553
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
315
554
|
<section
|
|
316
|
-
class="virtual-data-table {className}
|
|
317
|
-
|
|
555
|
+
class="virtual-data-table {className}{fixedLayout ? ' vtable-fixed-layout' : ''}{resizing
|
|
556
|
+
? ' vtable-resizing'
|
|
557
|
+
: ''}"
|
|
558
|
+
style="{style}{fixedTableWidth ? `; --vtable-table-width: ${fixedTableWidth}` : ''}"
|
|
318
559
|
bind:this={scroller}
|
|
319
560
|
onscroll={updateHorizontalScroll}
|
|
561
|
+
onpointerover={revealTruncated}
|
|
320
562
|
data-scrolled-start={scrolledFromStart ? '' : undefined}
|
|
321
563
|
data-scrolled-end={scrolledToEnd ? undefined : ''}
|
|
322
564
|
>
|
|
@@ -340,6 +582,23 @@
|
|
|
340
582
|
{/each}
|
|
341
583
|
</colgroup>
|
|
342
584
|
<thead class="sticky-header">
|
|
585
|
+
{#if groupSegments.length > 0}
|
|
586
|
+
<tr class="vtable-group-row" bind:offsetHeight={groupRowHeight}>
|
|
587
|
+
{#each groupSegments as segment}
|
|
588
|
+
{@const stickyKey = groupStickyKey(segment)}
|
|
589
|
+
<th
|
|
590
|
+
colspan={segment.keys.length}
|
|
591
|
+
class={groupClass(segment)}
|
|
592
|
+
style={stickyKey ? stickyStyle(stickyKey) : undefined}
|
|
593
|
+
scope={segment.group ? 'colgroup' : undefined}
|
|
594
|
+
>
|
|
595
|
+
{#if segment.group && !segment.cont}
|
|
596
|
+
<span class="vtable-header-label">{segment.group}</span>
|
|
597
|
+
{/if}
|
|
598
|
+
</th>
|
|
599
|
+
{/each}
|
|
600
|
+
</tr>
|
|
601
|
+
{/if}
|
|
343
602
|
<tr>
|
|
344
603
|
{#each effectiveVisibleKeys as key, columnIndex}
|
|
345
604
|
{@const colDef = colDefMap[key]}
|
|
@@ -349,11 +608,14 @@
|
|
|
349
608
|
{@const selection = filterDef ? filterState.selections[filterDef.key] : undefined}
|
|
350
609
|
{@const isFilterActive = hasActiveFilterValue(selection)}
|
|
351
610
|
<th
|
|
352
|
-
style="width: {calcColWidth(key)}; {stickyStyle(key)}
|
|
611
|
+
style="width: {calcColWidth(key)}; {stickyStyle(key)}{groupSegments.length > 0
|
|
612
|
+
? ` top: ${groupRowHeight}px;`
|
|
613
|
+
: ''}"
|
|
353
614
|
class="select-none {stickyClass(key)}{filterDef && openFilterKey === filterDef.key
|
|
354
615
|
? ' vtable-filter-open'
|
|
355
616
|
: ''}"
|
|
356
|
-
|
|
617
|
+
data-key={key}
|
|
618
|
+
bind:offsetWidth={headerWidths[key]}
|
|
357
619
|
aria-sort={sortKey === key
|
|
358
620
|
? sortDir === 'asc'
|
|
359
621
|
? 'ascending'
|
|
@@ -371,13 +633,13 @@
|
|
|
371
633
|
class="vtable-header-sort-button min-w-0 flex-1 cursor-pointer"
|
|
372
634
|
onclick={() => handleSort(key)}
|
|
373
635
|
>
|
|
374
|
-
<span class="min-w-0 truncate">{label}</span>
|
|
636
|
+
<span class="vtable-header-label min-w-0 truncate">{label}</span>
|
|
375
637
|
{#if sortKey === key}
|
|
376
638
|
<span aria-hidden="true">{sortDir === 'asc' ? '▲' : '▼'}</span>
|
|
377
639
|
{/if}
|
|
378
640
|
</button>
|
|
379
641
|
{:else}
|
|
380
|
-
<span class="min-w-0 flex-1 truncate">{label}</span>
|
|
642
|
+
<span class="vtable-header-label min-w-0 flex-1 truncate">{label}</span>
|
|
381
643
|
{/if}
|
|
382
644
|
|
|
383
645
|
{#if inlineFilters && filterDef}
|
|
@@ -405,6 +667,27 @@
|
|
|
405
667
|
/>
|
|
406
668
|
{/if}
|
|
407
669
|
</div>
|
|
670
|
+
{#if isResizable(key)}
|
|
671
|
+
<!-- Pointer-only affordance, hidden from assistive technology -->
|
|
672
|
+
<!-- svelte-ignore a11y_no_static_element_interactions, a11y_click_events_have_key_events -->
|
|
673
|
+
<span
|
|
674
|
+
class="vtable-resize-handle{resizing?.key === key
|
|
675
|
+
? ' vtable-resize-active'
|
|
676
|
+
: ''}"
|
|
677
|
+
aria-hidden="true"
|
|
678
|
+
title="Drag to resize, double-click to reset all widths"
|
|
679
|
+
onpointerdown={(e) => startResize(e, key)}
|
|
680
|
+
onpointermove={moveResize}
|
|
681
|
+
onpointerup={endResize}
|
|
682
|
+
onpointercancel={endResize}
|
|
683
|
+
onlostpointercapture={endResize}
|
|
684
|
+
onclick={(e) => e.stopPropagation()}
|
|
685
|
+
ondblclick={(e) => {
|
|
686
|
+
e.stopPropagation();
|
|
687
|
+
resetColumnWidths(key);
|
|
688
|
+
}}
|
|
689
|
+
></span>
|
|
690
|
+
{/if}
|
|
408
691
|
</th>
|
|
409
692
|
{/each}
|
|
410
693
|
</tr>
|
|
@@ -413,9 +696,17 @@
|
|
|
413
696
|
|
|
414
697
|
{#snippet vl_slot({ index, item })}
|
|
415
698
|
<!-- Default row rendering using each column's cellSnippet or raw value -->
|
|
416
|
-
<tr
|
|
699
|
+
<tr
|
|
700
|
+
onclick={() => selectItem(item, index)}
|
|
701
|
+
class={selected === item ? 'selected selected-row' : ''}
|
|
702
|
+
>
|
|
417
703
|
{#each columns as col}
|
|
418
|
-
<td
|
|
704
|
+
<td
|
|
705
|
+
class={[stickyClass(col.key), cellWraps(col) ? '' : 'vtable-truncate']
|
|
706
|
+
.filter(Boolean)
|
|
707
|
+
.join(' ') || undefined}
|
|
708
|
+
style={stickyStyle(col.key) || undefined}
|
|
709
|
+
>
|
|
419
710
|
{#if col.cellSnippet}
|
|
420
711
|
{@render col.cellSnippet({ item, value: item[col.key], index })}
|
|
421
712
|
{:else}
|
|
@@ -445,6 +736,9 @@
|
|
|
445
736
|
--vtable-color-info: #3b82f6; /* blue-500 */
|
|
446
737
|
|
|
447
738
|
--vtable-radius: 0.375rem; /* rounded-md */
|
|
739
|
+
|
|
740
|
+
--vtable-resize-line: #cbd5e1; /* slate-300: resize separator at rest */
|
|
741
|
+
--vtable-resize-line-hover: #64748b; /* slate-500: while its header is hovered */
|
|
448
742
|
--vtable-row-height: 2.25rem; /* default row height hint for virtual scroll */
|
|
449
743
|
}
|
|
450
744
|
.virtual-data-table {
|
|
@@ -508,6 +802,63 @@
|
|
|
508
802
|
:global(.dark .virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right) {
|
|
509
803
|
box-shadow: -6px 0 6px -4px rgba(0, 0, 0, 0.6);
|
|
510
804
|
}
|
|
805
|
+
/* Resizable columns: once a column is resized the table switches to a
|
|
806
|
+
fixed layout whose width is the sum of the column widths (set by DataTable
|
|
807
|
+
as --vtable-table-width). */
|
|
808
|
+
:global(.virtual-data-table.vtable-fixed-layout table.vtlist-inner) {
|
|
809
|
+
table-layout: fixed;
|
|
810
|
+
width: var(--vtable-table-width);
|
|
811
|
+
}
|
|
812
|
+
:global(.datatable-table thead th .vtable-resize-handle) {
|
|
813
|
+
position: absolute;
|
|
814
|
+
top: 0;
|
|
815
|
+
right: 0;
|
|
816
|
+
bottom: 0;
|
|
817
|
+
width: 0.6rem;
|
|
818
|
+
cursor: col-resize;
|
|
819
|
+
touch-action: none;
|
|
820
|
+
z-index: 1;
|
|
821
|
+
}
|
|
822
|
+
/* Separator line on the header's right edge: always shown on resizable
|
|
823
|
+
columns, stronger while the header is hovered, accent-coloured and full
|
|
824
|
+
height on the handle itself or while dragging. */
|
|
825
|
+
:global(.datatable-table thead th .vtable-resize-handle::after) {
|
|
826
|
+
content: '';
|
|
827
|
+
position: absolute;
|
|
828
|
+
top: 22%;
|
|
829
|
+
bottom: 22%;
|
|
830
|
+
right: 0;
|
|
831
|
+
width: 2px;
|
|
832
|
+
border-radius: 1px;
|
|
833
|
+
background-color: var(--vtable-resize-line);
|
|
834
|
+
transition:
|
|
835
|
+
background-color 0.12s ease-in-out,
|
|
836
|
+
top 0.12s ease-in-out,
|
|
837
|
+
bottom 0.12s ease-in-out,
|
|
838
|
+
width 0.12s ease-in-out;
|
|
839
|
+
}
|
|
840
|
+
:global(.datatable-table thead th:hover .vtable-resize-handle::after) {
|
|
841
|
+
top: 12%;
|
|
842
|
+
bottom: 12%;
|
|
843
|
+
background-color: var(--vtable-resize-line-hover);
|
|
844
|
+
}
|
|
845
|
+
:global(.datatable-table thead th .vtable-resize-handle:hover::after),
|
|
846
|
+
:global(.datatable-table thead th .vtable-resize-handle.vtable-resize-active::after) {
|
|
847
|
+
top: 0;
|
|
848
|
+
bottom: 0;
|
|
849
|
+
width: 3px;
|
|
850
|
+
background-color: var(--vtable-color-accent-border);
|
|
851
|
+
}
|
|
852
|
+
:global(.dark) :global(.datatable-table thead th .vtable-resize-handle) {
|
|
853
|
+
--vtable-resize-line: #4b5563; /* gray-600 */
|
|
854
|
+
--vtable-resize-line-hover: #9ca3af; /* gray-400 */
|
|
855
|
+
}
|
|
856
|
+
/* Keep the resize cursor and stop text selection while dragging */
|
|
857
|
+
:global(.virtual-data-table.vtable-resizing),
|
|
858
|
+
:global(.virtual-data-table.vtable-resizing *) {
|
|
859
|
+
cursor: col-resize !important;
|
|
860
|
+
user-select: none;
|
|
861
|
+
}
|
|
511
862
|
/* Header visual styles - only bottom border */
|
|
512
863
|
:global(.datatable-table) thead th {
|
|
513
864
|
background-color: #f8f9fa;
|
|
@@ -616,6 +967,48 @@
|
|
|
616
967
|
gap: 0.25rem;
|
|
617
968
|
text-align: left;
|
|
618
969
|
}
|
|
970
|
+
/* Grouped column headers (ColumnDef.group): a header row above the column
|
|
971
|
+
headers, one cell per run of columns sharing a group. */
|
|
972
|
+
:global(.datatable-table thead th.vtable-group-header) {
|
|
973
|
+
text-align: center;
|
|
974
|
+
padding-top: 0.25rem;
|
|
975
|
+
padding-bottom: 0.25rem;
|
|
976
|
+
font-size: 0.75rem;
|
|
977
|
+
letter-spacing: 0.05em;
|
|
978
|
+
color: #475569;
|
|
979
|
+
box-shadow: none;
|
|
980
|
+
}
|
|
981
|
+
/* Divider between groups; a run continued past a sticky boundary has none */
|
|
982
|
+
:global(
|
|
983
|
+
.datatable-table thead th.vtable-group-header + th.vtable-group-header:not(.vtable-group-cont)
|
|
984
|
+
) {
|
|
985
|
+
border-left: 1px solid #dee2e6;
|
|
986
|
+
}
|
|
987
|
+
:global(.datatable-table thead th.vtable-group-empty) {
|
|
988
|
+
border-bottom-color: transparent;
|
|
989
|
+
}
|
|
990
|
+
:global(.dark) :global(.datatable-table thead th.vtable-group-header) {
|
|
991
|
+
color: #cbd5e1;
|
|
992
|
+
box-shadow: none;
|
|
993
|
+
}
|
|
994
|
+
:global(.dark)
|
|
995
|
+
:global(
|
|
996
|
+
.datatable-table thead th.vtable-group-header + th.vtable-group-header:not(.vtable-group-cont)
|
|
997
|
+
) {
|
|
998
|
+
border-left-color: #374151;
|
|
999
|
+
}
|
|
1000
|
+
:global(.dark) :global(.datatable-table thead th.vtable-group-empty) {
|
|
1001
|
+
border-bottom-color: transparent;
|
|
1002
|
+
}
|
|
1003
|
+
/* Single-line cells (DataTable wrap={false} or ColumnDef.wrap: false). The
|
|
1004
|
+
zero max-width keeps cell text out of the automatic column sizing, so
|
|
1005
|
+
columns keep their declared widths and long text ends in an ellipsis
|
|
1006
|
+
(revealed in a tooltip on hover). */
|
|
1007
|
+
:global(.datatable-table tbody td.vtable-truncate) {
|
|
1008
|
+
white-space: nowrap;
|
|
1009
|
+
text-overflow: ellipsis;
|
|
1010
|
+
max-width: 0;
|
|
1011
|
+
}
|
|
619
1012
|
/* Allow certain long cells to wrap fully if explicitly requested */
|
|
620
1013
|
:global(.datatable-table td.wrap) {
|
|
621
1014
|
white-space: normal;
|
|
@@ -29,7 +29,12 @@ declare const DataTable: import("svelte").Component<{
|
|
|
29
29
|
relativeRangePresets?: typeof DEFAULT_RELATIVE_RANGE_PRESETS;
|
|
30
30
|
virtualize?: boolean;
|
|
31
31
|
density?: string;
|
|
32
|
-
|
|
32
|
+
resizable?: boolean;
|
|
33
|
+
columnWidths?: Record<string, any>;
|
|
34
|
+
oncolumnresize?: any;
|
|
35
|
+
storageKey?: any;
|
|
36
|
+
wrap?: boolean;
|
|
37
|
+
}, {}, "sortKey" | "sortDir" | "columnWidths">;
|
|
33
38
|
type $$ComponentProps = {
|
|
34
39
|
items?: any[];
|
|
35
40
|
columns?: any[];
|
|
@@ -56,5 +61,10 @@ type $$ComponentProps = {
|
|
|
56
61
|
relativeRangePresets?: typeof DEFAULT_RELATIVE_RANGE_PRESETS;
|
|
57
62
|
virtualize?: boolean;
|
|
58
63
|
density?: string;
|
|
64
|
+
resizable?: boolean;
|
|
65
|
+
columnWidths?: Record<string, any>;
|
|
66
|
+
oncolumnresize?: any;
|
|
67
|
+
storageKey?: any;
|
|
68
|
+
wrap?: boolean;
|
|
59
69
|
};
|
|
60
70
|
import { DEFAULT_RELATIVE_RANGE_PRESETS } from '../filterUtils.js';
|
|
@@ -352,6 +352,9 @@
|
|
|
352
352
|
--vtable-color-info: #3b82f6; /* blue-500 */
|
|
353
353
|
|
|
354
354
|
--vtable-radius: 0.375rem; /* rounded-md */
|
|
355
|
+
|
|
356
|
+
--vtable-resize-line: #cbd5e1; /* slate-300: resize separator at rest */
|
|
357
|
+
--vtable-resize-line-hover: #64748b; /* slate-500: while its header is hovered */
|
|
355
358
|
--vtable-row-height: 2.25rem; /* default row height hint for virtual scroll */
|
|
356
359
|
}
|
|
357
360
|
.virtual-data-table {
|
|
@@ -415,6 +418,63 @@
|
|
|
415
418
|
:global(.dark .virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right) {
|
|
416
419
|
box-shadow: -6px 0 6px -4px rgba(0, 0, 0, 0.6);
|
|
417
420
|
}
|
|
421
|
+
/* Resizable columns: once a column is resized the table switches to a
|
|
422
|
+
fixed layout whose width is the sum of the column widths (set by DataTable
|
|
423
|
+
as --vtable-table-width). */
|
|
424
|
+
:global(.virtual-data-table.vtable-fixed-layout table.vtlist-inner) {
|
|
425
|
+
table-layout: fixed;
|
|
426
|
+
width: var(--vtable-table-width);
|
|
427
|
+
}
|
|
428
|
+
:global(.datatable-table thead th .vtable-resize-handle) {
|
|
429
|
+
position: absolute;
|
|
430
|
+
top: 0;
|
|
431
|
+
right: 0;
|
|
432
|
+
bottom: 0;
|
|
433
|
+
width: 0.6rem;
|
|
434
|
+
cursor: col-resize;
|
|
435
|
+
touch-action: none;
|
|
436
|
+
z-index: 1;
|
|
437
|
+
}
|
|
438
|
+
/* Separator line on the header's right edge: always shown on resizable
|
|
439
|
+
columns, stronger while the header is hovered, accent-coloured and full
|
|
440
|
+
height on the handle itself or while dragging. */
|
|
441
|
+
:global(.datatable-table thead th .vtable-resize-handle::after) {
|
|
442
|
+
content: '';
|
|
443
|
+
position: absolute;
|
|
444
|
+
top: 22%;
|
|
445
|
+
bottom: 22%;
|
|
446
|
+
right: 0;
|
|
447
|
+
width: 2px;
|
|
448
|
+
border-radius: 1px;
|
|
449
|
+
background-color: var(--vtable-resize-line);
|
|
450
|
+
transition:
|
|
451
|
+
background-color 0.12s ease-in-out,
|
|
452
|
+
top 0.12s ease-in-out,
|
|
453
|
+
bottom 0.12s ease-in-out,
|
|
454
|
+
width 0.12s ease-in-out;
|
|
455
|
+
}
|
|
456
|
+
:global(.datatable-table thead th:hover .vtable-resize-handle::after) {
|
|
457
|
+
top: 12%;
|
|
458
|
+
bottom: 12%;
|
|
459
|
+
background-color: var(--vtable-resize-line-hover);
|
|
460
|
+
}
|
|
461
|
+
:global(.datatable-table thead th .vtable-resize-handle:hover::after),
|
|
462
|
+
:global(.datatable-table thead th .vtable-resize-handle.vtable-resize-active::after) {
|
|
463
|
+
top: 0;
|
|
464
|
+
bottom: 0;
|
|
465
|
+
width: 3px;
|
|
466
|
+
background-color: var(--vtable-color-accent-border);
|
|
467
|
+
}
|
|
468
|
+
:global(.dark) :global(.datatable-table thead th .vtable-resize-handle) {
|
|
469
|
+
--vtable-resize-line: #4b5563; /* gray-600 */
|
|
470
|
+
--vtable-resize-line-hover: #9ca3af; /* gray-400 */
|
|
471
|
+
}
|
|
472
|
+
/* Keep the resize cursor and stop text selection while dragging */
|
|
473
|
+
:global(.virtual-data-table.vtable-resizing),
|
|
474
|
+
:global(.virtual-data-table.vtable-resizing *) {
|
|
475
|
+
cursor: col-resize !important;
|
|
476
|
+
user-select: none;
|
|
477
|
+
}
|
|
418
478
|
/* Header visual styles - only bottom border */
|
|
419
479
|
:global(.datatable-table) thead th {
|
|
420
480
|
background-color: #f8f9fa;
|
|
@@ -523,6 +583,48 @@
|
|
|
523
583
|
gap: 0.25rem;
|
|
524
584
|
text-align: left;
|
|
525
585
|
}
|
|
586
|
+
/* Grouped column headers (ColumnDef.group): a header row above the column
|
|
587
|
+
headers, one cell per run of columns sharing a group. */
|
|
588
|
+
:global(.datatable-table thead th.vtable-group-header) {
|
|
589
|
+
text-align: center;
|
|
590
|
+
padding-top: 0.25rem;
|
|
591
|
+
padding-bottom: 0.25rem;
|
|
592
|
+
font-size: 0.75rem;
|
|
593
|
+
letter-spacing: 0.05em;
|
|
594
|
+
color: #475569;
|
|
595
|
+
box-shadow: none;
|
|
596
|
+
}
|
|
597
|
+
/* Divider between groups; a run continued past a sticky boundary has none */
|
|
598
|
+
:global(
|
|
599
|
+
.datatable-table thead th.vtable-group-header + th.vtable-group-header:not(.vtable-group-cont)
|
|
600
|
+
) {
|
|
601
|
+
border-left: 1px solid #dee2e6;
|
|
602
|
+
}
|
|
603
|
+
:global(.datatable-table thead th.vtable-group-empty) {
|
|
604
|
+
border-bottom-color: transparent;
|
|
605
|
+
}
|
|
606
|
+
:global(.dark) :global(.datatable-table thead th.vtable-group-header) {
|
|
607
|
+
color: #cbd5e1;
|
|
608
|
+
box-shadow: none;
|
|
609
|
+
}
|
|
610
|
+
:global(.dark)
|
|
611
|
+
:global(
|
|
612
|
+
.datatable-table thead th.vtable-group-header + th.vtable-group-header:not(.vtable-group-cont)
|
|
613
|
+
) {
|
|
614
|
+
border-left-color: #374151;
|
|
615
|
+
}
|
|
616
|
+
:global(.dark) :global(.datatable-table thead th.vtable-group-empty) {
|
|
617
|
+
border-bottom-color: transparent;
|
|
618
|
+
}
|
|
619
|
+
/* Single-line cells (DataTable wrap={false} or ColumnDef.wrap: false). The
|
|
620
|
+
zero max-width keeps cell text out of the automatic column sizing, so
|
|
621
|
+
columns keep their declared widths and long text ends in an ellipsis
|
|
622
|
+
(revealed in a tooltip on hover). */
|
|
623
|
+
:global(.datatable-table tbody td.vtable-truncate) {
|
|
624
|
+
white-space: nowrap;
|
|
625
|
+
text-overflow: ellipsis;
|
|
626
|
+
max-width: 0;
|
|
627
|
+
}
|
|
526
628
|
/* Allow certain long cells to wrap fully if explicitly requested */
|
|
527
629
|
:global(.datatable-table td.wrap) {
|
|
528
630
|
white-space: normal;
|