@zhangt58/svelte-vtable 0.4.3 → 0.5.1

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.
@@ -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 {
@@ -365,7 +368,6 @@
365
368
  display: table;
366
369
  width: 100%;
367
370
  min-width: 0;
368
- border-collapse: collapse;
369
371
  box-sizing: border-box;
370
372
  font-size: 0.875rem; /* 14px - smaller, more compact */
371
373
  font-family:
@@ -373,12 +375,106 @@
373
375
  line-height: 1.4;
374
376
  border: none;
375
377
  }
376
- /* Sticky header support */
377
- :global(.datatable-table) thead.sticky-header {
378
+ /* Sticky header: each header cell sticks (rather than the <thead>), so a
379
+ cell can also stick horizontally for sticky columns. */
380
+ :global(.datatable-table thead.sticky-header th) {
378
381
  position: sticky;
379
382
  top: 0;
380
383
  z-index: 2;
381
384
  }
385
+ /* separate + 0 spacing looks like collapse here (bottom borders only) but
386
+ keeps each border on its cell, so borders move with sticky cells. Set on
387
+ the inner <table> itself: Tailwind's preflight collapses every table. */
388
+ :global(.datatable-table table.vtlist-inner) {
389
+ border-collapse: separate;
390
+ border-spacing: 0;
391
+ }
392
+ /* Sticky columns (ColumnDef.sticky). Body cells take the row's background
393
+ (striping, hover, selection) so scrolled cells do not show through. The
394
+ <tbody> is rendered by VirtualList, hence fully global. */
395
+ :global(.datatable-table tbody td.vtable-sticky) {
396
+ position: sticky;
397
+ z-index: 1;
398
+ background-color: inherit;
399
+ }
400
+ :global(.datatable-table thead.sticky-header th.vtable-sticky) {
401
+ z-index: 3;
402
+ }
403
+ /* Keep an open header filter above the sticky header cells */
404
+ :global(.datatable-table thead.sticky-header th.vtable-filter-open) {
405
+ z-index: 4;
406
+ }
407
+ /* Divider shadow on the innermost sticky column, only while columns are
408
+ scrolled under it */
409
+ :global(.virtual-data-table[data-scrolled-start] .vtable-sticky-edge-left) {
410
+ box-shadow: 6px 0 6px -4px rgba(15, 23, 42, 0.18);
411
+ }
412
+ :global(.virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right) {
413
+ box-shadow: -6px 0 6px -4px rgba(15, 23, 42, 0.18);
414
+ }
415
+ :global(.dark .virtual-data-table[data-scrolled-start] .vtable-sticky-edge-left) {
416
+ box-shadow: 6px 0 6px -4px rgba(0, 0, 0, 0.6);
417
+ }
418
+ :global(.dark .virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right) {
419
+ box-shadow: -6px 0 6px -4px rgba(0, 0, 0, 0.6);
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
+ }
382
478
  /* Header visual styles - only bottom border */
383
479
  :global(.datatable-table) thead th {
384
480
  background-color: #f8f9fa;
@@ -457,7 +553,7 @@
457
553
  }
458
554
  /* Compact variant */
459
555
  :global(.datatable-table.compact tbody td) {
460
- padding: 0.1rem 0.3rem;
556
+ padding: 0.25rem 0.5rem;
461
557
  }
462
558
  /* Header content alignment helper */
463
559
  :global(.datatable-table thead th > div) {
@@ -465,9 +561,6 @@
465
561
  align-items: center;
466
562
  gap: 0.25rem;
467
563
  }
468
- :global(.datatable-table thead th) {
469
- position: relative;
470
- }
471
564
  :global(.datatable-table thead th .vtable-header-content) {
472
565
  display: flex;
473
566
  align-items: center;
@@ -490,6 +583,48 @@
490
583
  gap: 0.25rem;
491
584
  text-align: left;
492
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
+ }
493
628
  /* Allow certain long cells to wrap fully if explicitly requested */
494
629
  :global(.datatable-table td.wrap) {
495
630
  white-space: normal;
@@ -298,6 +298,9 @@
298
298
  --vtable-color-info: #3b82f6; /* blue-500 */
299
299
 
300
300
  --vtable-radius: 0.375rem; /* rounded-md */
301
+
302
+ --vtable-resize-line: #cbd5e1; /* slate-300: resize separator at rest */
303
+ --vtable-resize-line-hover: #64748b; /* slate-500: while its header is hovered */
301
304
  --vtable-row-height: 2.25rem; /* default row height hint for virtual scroll */
302
305
  }
303
306
  .virtual-data-table {
@@ -311,7 +314,6 @@
311
314
  display: table;
312
315
  width: 100%;
313
316
  min-width: 0;
314
- border-collapse: collapse;
315
317
  box-sizing: border-box;
316
318
  font-size: 0.875rem; /* 14px - smaller, more compact */
317
319
  font-family:
@@ -319,12 +321,106 @@
319
321
  line-height: 1.4;
320
322
  border: none;
321
323
  }
322
- /* Sticky header support */
323
- :global(.datatable-table) thead.sticky-header {
324
+ /* Sticky header: each header cell sticks (rather than the <thead>), so a
325
+ cell can also stick horizontally for sticky columns. */
326
+ :global(.datatable-table thead.sticky-header th) {
324
327
  position: sticky;
325
328
  top: 0;
326
329
  z-index: 2;
327
330
  }
331
+ /* separate + 0 spacing looks like collapse here (bottom borders only) but
332
+ keeps each border on its cell, so borders move with sticky cells. Set on
333
+ the inner <table> itself: Tailwind's preflight collapses every table. */
334
+ :global(.datatable-table table.vtlist-inner) {
335
+ border-collapse: separate;
336
+ border-spacing: 0;
337
+ }
338
+ /* Sticky columns (ColumnDef.sticky). Body cells take the row's background
339
+ (striping, hover, selection) so scrolled cells do not show through. The
340
+ <tbody> is rendered by VirtualList, hence fully global. */
341
+ :global(.datatable-table tbody td.vtable-sticky) {
342
+ position: sticky;
343
+ z-index: 1;
344
+ background-color: inherit;
345
+ }
346
+ :global(.datatable-table thead.sticky-header th.vtable-sticky) {
347
+ z-index: 3;
348
+ }
349
+ /* Keep an open header filter above the sticky header cells */
350
+ :global(.datatable-table thead.sticky-header th.vtable-filter-open) {
351
+ z-index: 4;
352
+ }
353
+ /* Divider shadow on the innermost sticky column, only while columns are
354
+ scrolled under it */
355
+ :global(.virtual-data-table[data-scrolled-start] .vtable-sticky-edge-left) {
356
+ box-shadow: 6px 0 6px -4px rgba(15, 23, 42, 0.18);
357
+ }
358
+ :global(.virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right) {
359
+ box-shadow: -6px 0 6px -4px rgba(15, 23, 42, 0.18);
360
+ }
361
+ :global(.dark .virtual-data-table[data-scrolled-start] .vtable-sticky-edge-left) {
362
+ box-shadow: 6px 0 6px -4px rgba(0, 0, 0, 0.6);
363
+ }
364
+ :global(.dark .virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right) {
365
+ box-shadow: -6px 0 6px -4px rgba(0, 0, 0, 0.6);
366
+ }
367
+ /* Resizable columns: once a column is resized the table switches to a
368
+ fixed layout whose width is the sum of the column widths (set by DataTable
369
+ as --vtable-table-width). */
370
+ :global(.virtual-data-table.vtable-fixed-layout table.vtlist-inner) {
371
+ table-layout: fixed;
372
+ width: var(--vtable-table-width);
373
+ }
374
+ :global(.datatable-table thead th .vtable-resize-handle) {
375
+ position: absolute;
376
+ top: 0;
377
+ right: 0;
378
+ bottom: 0;
379
+ width: 0.6rem;
380
+ cursor: col-resize;
381
+ touch-action: none;
382
+ z-index: 1;
383
+ }
384
+ /* Separator line on the header's right edge: always shown on resizable
385
+ columns, stronger while the header is hovered, accent-coloured and full
386
+ height on the handle itself or while dragging. */
387
+ :global(.datatable-table thead th .vtable-resize-handle::after) {
388
+ content: '';
389
+ position: absolute;
390
+ top: 22%;
391
+ bottom: 22%;
392
+ right: 0;
393
+ width: 2px;
394
+ border-radius: 1px;
395
+ background-color: var(--vtable-resize-line);
396
+ transition:
397
+ background-color 0.12s ease-in-out,
398
+ top 0.12s ease-in-out,
399
+ bottom 0.12s ease-in-out,
400
+ width 0.12s ease-in-out;
401
+ }
402
+ :global(.datatable-table thead th:hover .vtable-resize-handle::after) {
403
+ top: 12%;
404
+ bottom: 12%;
405
+ background-color: var(--vtable-resize-line-hover);
406
+ }
407
+ :global(.datatable-table thead th .vtable-resize-handle:hover::after),
408
+ :global(.datatable-table thead th .vtable-resize-handle.vtable-resize-active::after) {
409
+ top: 0;
410
+ bottom: 0;
411
+ width: 3px;
412
+ background-color: var(--vtable-color-accent-border);
413
+ }
414
+ :global(.dark) :global(.datatable-table thead th .vtable-resize-handle) {
415
+ --vtable-resize-line: #4b5563; /* gray-600 */
416
+ --vtable-resize-line-hover: #9ca3af; /* gray-400 */
417
+ }
418
+ /* Keep the resize cursor and stop text selection while dragging */
419
+ :global(.virtual-data-table.vtable-resizing),
420
+ :global(.virtual-data-table.vtable-resizing *) {
421
+ cursor: col-resize !important;
422
+ user-select: none;
423
+ }
328
424
  /* Header visual styles - only bottom border */
329
425
  :global(.datatable-table) thead th {
330
426
  background-color: #f8f9fa;
@@ -403,7 +499,7 @@
403
499
  }
404
500
  /* Compact variant */
405
501
  :global(.datatable-table.compact tbody td) {
406
- padding: 0.1rem 0.3rem;
502
+ padding: 0.25rem 0.5rem;
407
503
  }
408
504
  /* Header content alignment helper */
409
505
  :global(.datatable-table thead th > div) {
@@ -411,9 +507,6 @@
411
507
  align-items: center;
412
508
  gap: 0.25rem;
413
509
  }
414
- :global(.datatable-table thead th) {
415
- position: relative;
416
- }
417
510
  :global(.datatable-table thead th .vtable-header-content) {
418
511
  display: flex;
419
512
  align-items: center;
@@ -436,6 +529,48 @@
436
529
  gap: 0.25rem;
437
530
  text-align: left;
438
531
  }
532
+ /* Grouped column headers (ColumnDef.group): a header row above the column
533
+ headers, one cell per run of columns sharing a group. */
534
+ :global(.datatable-table thead th.vtable-group-header) {
535
+ text-align: center;
536
+ padding-top: 0.25rem;
537
+ padding-bottom: 0.25rem;
538
+ font-size: 0.75rem;
539
+ letter-spacing: 0.05em;
540
+ color: #475569;
541
+ box-shadow: none;
542
+ }
543
+ /* Divider between groups; a run continued past a sticky boundary has none */
544
+ :global(
545
+ .datatable-table thead th.vtable-group-header + th.vtable-group-header:not(.vtable-group-cont)
546
+ ) {
547
+ border-left: 1px solid #dee2e6;
548
+ }
549
+ :global(.datatable-table thead th.vtable-group-empty) {
550
+ border-bottom-color: transparent;
551
+ }
552
+ :global(.dark) :global(.datatable-table thead th.vtable-group-header) {
553
+ color: #cbd5e1;
554
+ box-shadow: none;
555
+ }
556
+ :global(.dark)
557
+ :global(
558
+ .datatable-table thead th.vtable-group-header + th.vtable-group-header:not(.vtable-group-cont)
559
+ ) {
560
+ border-left-color: #374151;
561
+ }
562
+ :global(.dark) :global(.datatable-table thead th.vtable-group-empty) {
563
+ border-bottom-color: transparent;
564
+ }
565
+ /* Single-line cells (DataTable wrap={false} or ColumnDef.wrap: false). The
566
+ zero max-width keeps cell text out of the automatic column sizing, so
567
+ columns keep their declared widths and long text ends in an ellipsis
568
+ (revealed in a tooltip on hover). */
569
+ :global(.datatable-table tbody td.vtable-truncate) {
570
+ white-space: nowrap;
571
+ text-overflow: ellipsis;
572
+ max-width: 0;
573
+ }
439
574
  /* Allow certain long cells to wrap fully if explicitly requested */
440
575
  :global(.datatable-table td.wrap) {
441
576
  white-space: normal;
package/dist/index.d.ts CHANGED
@@ -25,6 +25,35 @@ export type ColumnDef<T extends Record<string, unknown> = Record<string, unknown
25
25
  * CSS width value such as `'120px'`. Defaults to `1` (equal stretch).
26
26
  */
27
27
  width?: number | string;
28
+ /**
29
+ * - Minimum column width as a CSS length (e.g. `'12rem'`).
30
+ * A CSS-length `width` is also a minimum. When the minimums exceed the
31
+ * container, the table scrolls sideways instead of squeezing its columns.
32
+ * Applies to the declared layout: a user may resize the column below it.
33
+ */
34
+ minWidth?: string;
35
+ /**
36
+ * - Keep the column in view while the table
37
+ * scrolls sideways, pinned to that edge. Several columns may stick per side;
38
+ * offsets are measured, so any width type works.
39
+ */
40
+ sticky?: "left" | "right";
41
+ /**
42
+ * - Group label shown in a header row above the
43
+ * column headers. Adjacent columns with the same group share one cell.
44
+ */
45
+ group?: string;
46
+ /**
47
+ * - Set `false` to keep this column fixed when
48
+ * the table is `resizable`. Defaults to `true`.
49
+ */
50
+ resizable?: boolean;
51
+ /**
52
+ * - Wrap long text in this column's cells; overrides
53
+ * the table's `wrap` prop. When false, cells stay on one line and cut-off text
54
+ * is shown in a tooltip.
55
+ */
56
+ wrap?: boolean;
28
57
  /**
29
58
  * - Whether clicking the column header sorts the
30
59
  * table. Defaults to `true`.
package/dist/index.js CHANGED
@@ -40,6 +40,20 @@ export {
40
40
  * @property {string} [label] - Display label for the column header. Defaults to `key`.
41
41
  * @property {number|string} [width] - Column width: a stretch weight (number) or a
42
42
  * CSS width value such as `'120px'`. Defaults to `1` (equal stretch).
43
+ * @property {string} [minWidth] - Minimum column width as a CSS length (e.g. `'12rem'`).
44
+ * A CSS-length `width` is also a minimum. When the minimums exceed the
45
+ * container, the table scrolls sideways instead of squeezing its columns.
46
+ * Applies to the declared layout: a user may resize the column below it.
47
+ * @property {'left'|'right'} [sticky] - Keep the column in view while the table
48
+ * scrolls sideways, pinned to that edge. Several columns may stick per side;
49
+ * offsets are measured, so any width type works.
50
+ * @property {string} [group] - Group label shown in a header row above the
51
+ * column headers. Adjacent columns with the same group share one cell.
52
+ * @property {boolean} [resizable] - Set `false` to keep this column fixed when
53
+ * the table is `resizable`. Defaults to `true`.
54
+ * @property {boolean} [wrap] - Wrap long text in this column's cells; overrides
55
+ * the table's `wrap` prop. When false, cells stay on one line and cut-off text
56
+ * is shown in a tooltip.
43
57
  * @property {boolean} [sortable] - Whether clicking the column header sorts the
44
58
  * table. Defaults to `true`.
45
59
  * @property {'value'|'list'|'daterange'|'datetimerange'|'none'} [filterType]