@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.
package/dist/styles.css CHANGED
@@ -9,6 +9,9 @@
9
9
  --vtable-color-info: #3b82f6; /* blue-500 */
10
10
 
11
11
  --vtable-radius: 0.375rem; /* rounded-md */
12
+
13
+ --vtable-resize-line: #cbd5e1; /* slate-300: resize separator at rest */
14
+ --vtable-resize-line-hover: #64748b; /* slate-500: while its header is hovered */
12
15
  --vtable-row-height: 2.25rem; /* default row height hint for virtual scroll */
13
16
  }
14
17
 
@@ -20,11 +23,10 @@
20
23
  isolation: isolate;
21
24
  }
22
25
 
23
- :global(.datatable-table) {
26
+ .datatable-table {
24
27
  display: table;
25
28
  width: 100%;
26
29
  min-width: 0;
27
- border-collapse: collapse;
28
30
  box-sizing: border-box;
29
31
  font-size: 0.875rem; /* 14px - smaller, more compact */
30
32
  font-family:
@@ -33,15 +35,124 @@
33
35
  border: none;
34
36
  }
35
37
 
36
- /* Sticky header support */
37
- :global(.datatable-table) thead.sticky-header {
38
+ /* Sticky header: each header cell sticks (rather than the <thead>), so a
39
+ cell can also stick horizontally for sticky columns. */
40
+ .datatable-table thead.sticky-header th {
38
41
  position: sticky;
39
42
  top: 0;
40
43
  z-index: 2;
41
44
  }
42
45
 
46
+ /* separate + 0 spacing looks like collapse here (bottom borders only) but
47
+ keeps each border on its cell, so borders move with sticky cells. Set on
48
+ the inner <table> itself: Tailwind's preflight collapses every table. */
49
+ .datatable-table table.vtlist-inner {
50
+ border-collapse: separate;
51
+ border-spacing: 0;
52
+ }
53
+
54
+ /* Sticky columns (ColumnDef.sticky). Body cells take the row's background
55
+ (striping, hover, selection) so scrolled cells do not show through. The
56
+ <tbody> is rendered by VirtualList, hence fully global. */
57
+ .datatable-table tbody td.vtable-sticky {
58
+ position: sticky;
59
+ z-index: 1;
60
+ background-color: inherit;
61
+ }
62
+
63
+ .datatable-table thead.sticky-header th.vtable-sticky {
64
+ z-index: 3;
65
+ }
66
+
67
+ /* Keep an open header filter above the sticky header cells */
68
+ .datatable-table thead.sticky-header th.vtable-filter-open {
69
+ z-index: 4;
70
+ }
71
+
72
+ /* Divider shadow on the innermost sticky column, only while columns are
73
+ scrolled under it */
74
+ .virtual-data-table[data-scrolled-start] .vtable-sticky-edge-left {
75
+ box-shadow: 6px 0 6px -4px rgba(15, 23, 42, 0.18);
76
+ }
77
+
78
+ .virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right {
79
+ box-shadow: -6px 0 6px -4px rgba(15, 23, 42, 0.18);
80
+ }
81
+
82
+ .dark .virtual-data-table[data-scrolled-start] .vtable-sticky-edge-left {
83
+ box-shadow: 6px 0 6px -4px rgba(0, 0, 0, 0.6);
84
+ }
85
+
86
+ .dark .virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right {
87
+ box-shadow: -6px 0 6px -4px rgba(0, 0, 0, 0.6);
88
+ }
89
+
90
+ /* Resizable columns: once a column is resized the table switches to a
91
+ fixed layout whose width is the sum of the column widths (set by DataTable
92
+ as --vtable-table-width). */
93
+ .virtual-data-table.vtable-fixed-layout table.vtlist-inner {
94
+ table-layout: fixed;
95
+ width: var(--vtable-table-width);
96
+ }
97
+
98
+ .datatable-table thead th .vtable-resize-handle {
99
+ position: absolute;
100
+ top: 0;
101
+ right: 0;
102
+ bottom: 0;
103
+ width: 0.6rem;
104
+ cursor: col-resize;
105
+ touch-action: none;
106
+ z-index: 1;
107
+ }
108
+
109
+ /* Separator line on the header's right edge: always shown on resizable
110
+ columns, stronger while the header is hovered, accent-coloured and full
111
+ height on the handle itself or while dragging. */
112
+ .datatable-table thead th .vtable-resize-handle::after {
113
+ content: '';
114
+ position: absolute;
115
+ top: 22%;
116
+ bottom: 22%;
117
+ right: 0;
118
+ width: 2px;
119
+ border-radius: 1px;
120
+ background-color: var(--vtable-resize-line);
121
+ transition:
122
+ background-color 0.12s ease-in-out,
123
+ top 0.12s ease-in-out,
124
+ bottom 0.12s ease-in-out,
125
+ width 0.12s ease-in-out;
126
+ }
127
+
128
+ .datatable-table thead th:hover .vtable-resize-handle::after {
129
+ top: 12%;
130
+ bottom: 12%;
131
+ background-color: var(--vtable-resize-line-hover);
132
+ }
133
+
134
+ .datatable-table thead th .vtable-resize-handle:hover::after,
135
+ .datatable-table thead th .vtable-resize-handle.vtable-resize-active::after {
136
+ top: 0;
137
+ bottom: 0;
138
+ width: 3px;
139
+ background-color: var(--vtable-color-accent-border);
140
+ }
141
+
142
+ .dark .datatable-table thead th .vtable-resize-handle {
143
+ --vtable-resize-line: #4b5563; /* gray-600 */
144
+ --vtable-resize-line-hover: #9ca3af; /* gray-400 */
145
+ }
146
+
147
+ /* Keep the resize cursor and stop text selection while dragging */
148
+ .virtual-data-table.vtable-resizing,
149
+ .virtual-data-table.vtable-resizing * {
150
+ cursor: col-resize !important;
151
+ user-select: none;
152
+ }
153
+
43
154
  /* Header visual styles - only bottom border */
44
- :global(.datatable-table) thead th {
155
+ .datatable-table thead th {
45
156
  background-color: #f8f9fa;
46
157
  font-size: 0.8125rem; /* 13px */
47
158
  font-weight: 600;
@@ -60,32 +171,32 @@
60
171
 
61
172
  /* Row striping - alternating colors */
62
173
  /* VirtualList may wrap rows, so we target tr directly */
63
- :global(.datatable-table tbody tr:nth-of-type(even)) {
174
+ .datatable-table tbody tr:nth-of-type(even) {
64
175
  background-color: #ffffff;
65
176
  }
66
177
 
67
- :global(.datatable-table tbody tr:nth-of-type(odd)) {
178
+ .datatable-table tbody tr:nth-of-type(odd) {
68
179
  background-color: #f8f9fa;
69
180
  }
70
181
 
71
182
  /* Also ensure tr elements themselves have background */
72
- :global(.datatable-table tbody tr) {
183
+ .datatable-table tbody tr {
73
184
  background-color: inherit;
74
185
  }
75
186
 
76
187
  /* Hover effect */
77
- :global(.datatable-table tbody tr:hover) {
188
+ .datatable-table tbody tr:hover {
78
189
  background-color: #e7f1ff !important;
79
190
  transition: background-color 0.15s ease-in-out;
80
191
  }
81
192
 
82
193
  /* Selesky-500 row overrides striping and hover */
83
- :global(.datatable-table tbody tr.selected-row) {
194
+ .datatable-table tbody tr.selected-row {
84
195
  background-color: #e0f2fe !important; /* light sky background */
85
196
  box-shadow: inset 4px 0 0 0 #0369a1; /* left accent */
86
197
  }
87
198
 
88
- :global(.dark) :global(.datatable-table tbody tr.selected-row) {
199
+ .dark .datatable-table tbody tr.selected-row {
89
200
  /* brighter, higher-contrast selection in dark mode */
90
201
  background-color: rgba(14, 165, 233, 0.22) !important; /* stronger visible blue */
91
202
  box-shadow: inset 6px 0 0 0 rgba(56, 189, 248, 0.85); /* stronger left accent */
@@ -95,18 +206,18 @@
95
206
  }
96
207
 
97
208
  /* Also apply to cells to defeat any cell-level background from striping and ensure readable text */
98
- :global(.datatable-table tbody tr.selected-row) td {
209
+ .datatable-table tbody tr.selected-row td {
99
210
  background-color: #e0f2fe !important;
100
211
  }
101
212
 
102
- :global(.dark) :global(.datatable-table tbody tr.selected-row) td {
213
+ .dark .datatable-table tbody tr.selected-row td {
103
214
  background-color: rgba(14, 165, 233, 0.22) !important;
104
215
  color: #f0fbff !important; /* ensure high-contrast, very light text */
105
216
  border-bottom-color: rgba(255, 255, 255, 0.06);
106
217
  }
107
218
 
108
219
  /* Body cell defaults - only bottom border */
109
- :global(.datatable-table tbody td) {
220
+ .datatable-table tbody td {
110
221
  padding: 0.5rem 0.5rem;
111
222
  border-top: none;
112
223
  border-left: none;
@@ -122,28 +233,24 @@
122
233
  }
123
234
 
124
235
  /* No-wrap variant for cells that should truncate */
125
- :global(.datatable-table tbody td.nowrap) {
236
+ .datatable-table tbody td.nowrap {
126
237
  white-space: nowrap;
127
238
  text-overflow: ellipsis;
128
239
  }
129
240
 
130
241
  /* Compact variant */
131
- :global(.datatable-table.compact tbody td) {
132
- padding: 0.1rem 0.3rem;
242
+ .datatable-table.compact tbody td {
243
+ padding: 0.25rem 0.5rem;
133
244
  }
134
245
 
135
246
  /* Header content alignment helper */
136
- :global(.datatable-table thead th > div) {
247
+ .datatable-table thead th > div {
137
248
  display: inline-flex;
138
249
  align-items: center;
139
250
  gap: 0.25rem;
140
251
  }
141
252
 
142
- :global(.datatable-table thead th) {
143
- position: relative;
144
- }
145
-
146
- :global(.datatable-table thead th .vtable-header-content) {
253
+ .datatable-table thead th .vtable-header-content {
147
254
  display: flex;
148
255
  align-items: center;
149
256
  justify-content: space-between;
@@ -152,7 +259,7 @@
152
259
  width: 100%;
153
260
  }
154
261
 
155
- :global(.datatable-table thead th .vtable-header-sort-button) {
262
+ .datatable-table thead th .vtable-header-sort-button {
156
263
  appearance: none;
157
264
  border: 0;
158
265
  background: transparent;
@@ -167,33 +274,80 @@
167
274
  text-align: left;
168
275
  }
169
276
 
277
+ /* Grouped column headers (ColumnDef.group): a header row above the column
278
+ headers, one cell per run of columns sharing a group. */
279
+ .datatable-table thead th.vtable-group-header {
280
+ text-align: center;
281
+ padding-top: 0.25rem;
282
+ padding-bottom: 0.25rem;
283
+ font-size: 0.75rem;
284
+ letter-spacing: 0.05em;
285
+ color: #475569;
286
+ box-shadow: none;
287
+ }
288
+
289
+ /* Divider between groups; a run continued past a sticky boundary has none */
290
+ .datatable-table thead th.vtable-group-header + th.vtable-group-header:not(.vtable-group-cont
291
+ ) {
292
+ border-left: 1px solid #dee2e6;
293
+ }
294
+
295
+ .datatable-table thead th.vtable-group-empty {
296
+ border-bottom-color: transparent;
297
+ }
298
+
299
+ .dark .datatable-table thead th.vtable-group-header {
300
+ color: #cbd5e1;
301
+ box-shadow: none;
302
+ }
303
+
304
+ .dark
305
+ .datatable-table thead th.vtable-group-header + th.vtable-group-header:not(.vtable-group-cont
306
+ ) {
307
+ border-left-color: #374151;
308
+ }
309
+
310
+ .dark .datatable-table thead th.vtable-group-empty {
311
+ border-bottom-color: transparent;
312
+ }
313
+
314
+ /* Single-line cells (DataTable wrap={false} or ColumnDef.wrap: false). The
315
+ zero max-width keeps cell text out of the automatic column sizing, so
316
+ columns keep their declared widths and long text ends in an ellipsis
317
+ (revealed in a tooltip on hover). */
318
+ .datatable-table tbody td.vtable-truncate {
319
+ white-space: nowrap;
320
+ text-overflow: ellipsis;
321
+ max-width: 0;
322
+ }
323
+
170
324
  /* Allow certain long cells to wrap fully if explicitly requested */
171
- :global(.datatable-table td.wrap) {
325
+ .datatable-table td.wrap {
172
326
  white-space: normal;
173
327
  word-break: break-word;
174
328
  }
175
329
 
176
330
  /* Dark mode variants for the datatable */
177
- :global(.dark) :global(.datatable-table thead th) {
331
+ .dark .datatable-table thead th {
178
332
  background-color: #1f2937;
179
333
  border-bottom-color: #374151;
180
334
  color: #f9fafb;
181
335
  box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.3); /* Darker shadow for dark mode */
182
336
  }
183
337
 
184
- :global(.dark) :global(.datatable-table tbody tr:nth-of-type(even)) {
338
+ .dark .datatable-table tbody tr:nth-of-type(even) {
185
339
  background-color: #111827;
186
340
  }
187
341
 
188
- :global(.dark) :global(.datatable-table tbody tr:nth-of-type(odd)) {
342
+ .dark .datatable-table tbody tr:nth-of-type(odd) {
189
343
  background-color: #1f2937;
190
344
  }
191
345
 
192
- :global(.dark) :global(.datatable-table tbody tr:hover) {
346
+ .dark .datatable-table tbody tr:hover {
193
347
  background-color: #374151 !important;
194
348
  }
195
349
 
196
- :global(.dark) :global(.datatable-table tbody td) {
350
+ .dark .datatable-table tbody td {
197
351
  border-bottom-color: #374151;
198
352
  color: #e5e7eb;
199
353
  }
@@ -201,36 +355,36 @@
201
355
  /* Shared control styles (inputs, pagination, column filters) used by page components */
202
356
 
203
357
  /* Accent-color focus ring for search input and per-page select — respects --vtable-color-accent */
204
- :global(.vtable-search-input:focus),
205
- :global(.vtable-perpage-select:focus) {
358
+ .vtable-search-input:focus,
359
+ .vtable-perpage-select:focus {
206
360
  border-color: var(--vtable-color-accent-border);
207
361
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--vtable-color-accent) 20%, transparent);
208
362
  outline: none;
209
363
  }
210
364
 
211
- :global(.datatable-input) {
365
+ .datatable-input {
212
366
  padding: 0.375rem 0.75rem;
213
367
  font-size: 0.95rem;
214
368
  border: 1px solid #ced4da;
215
369
  border-radius: 0.25rem;
216
370
  }
217
371
 
218
- :global(.datatable-input:focus) {
372
+ .datatable-input:focus {
219
373
  border-color: #86b7fe;
220
374
  outline: 0;
221
375
  box-shadow: 0 0 0.1rem 0.2rem rgba(13, 110, 253, 0.25);
222
376
  }
223
377
 
224
- :global(.search-filtering-row) {
378
+ .search-filtering-row {
225
379
  background-color: #f8f9fa;
226
380
  }
227
381
 
228
- :global(.search-filtering-row th) {
382
+ .search-filtering-row th {
229
383
  padding: 0.1rem 0.1rem;
230
384
  border-bottom: 1px solid #dee2e6;
231
385
  }
232
386
 
233
- :global(.column-filter) {
387
+ .column-filter {
234
388
  width: 95%;
235
389
  padding: 0.2rem 0.25rem;
236
390
  font-size: 0.8rem;
@@ -238,20 +392,20 @@
238
392
  border-radius: 0.25rem;
239
393
  }
240
394
 
241
- :global(.column-filter::placeholder) {
395
+ .column-filter::placeholder {
242
396
  color: #adb5bd;
243
397
  font-size: 0.75rem;
244
398
  font-style: italic;
245
399
  }
246
400
 
247
- :global(.datatable-pagination) {
401
+ .datatable-pagination {
248
402
  display: flex;
249
403
  gap: 0.1rem;
250
404
  margin-top: 0.6rem;
251
405
  }
252
406
 
253
- :global(.datatable-pagination li a),
254
- :global(.datatable-pagination li button) {
407
+ .datatable-pagination li a,
408
+ .datatable-pagination li button {
255
409
  padding: 0.3rem 0.7rem;
256
410
  border: 1px solid #dee2e6;
257
411
  border-radius: 0;
@@ -260,13 +414,13 @@
260
414
  text-decoration: none;
261
415
  }
262
416
 
263
- :global(.datatable-pagination li a:hover),
264
- :global(.datatable-pagination li button:hover) {
417
+ .datatable-pagination li a:hover,
418
+ .datatable-pagination li button:hover {
265
419
  background-color: #e9ecef;
266
420
  }
267
421
 
268
- :global(.datatable-pagination .datatable-active a),
269
- :global(.datatable-pagination .datatable-active button) {
422
+ .datatable-pagination .datatable-active a,
423
+ .datatable-pagination .datatable-active button {
270
424
  background-color: #0d6efd;
271
425
  border-color: #0d6efd;
272
426
  color: #fff;
@@ -274,7 +428,7 @@
274
428
 
275
429
  /* Force the active/current page to use the accent tokens (override flowbite's primary/orange).
276
430
  Intentionally specific to reliably win over third-party rules. */
277
- :global([data-pagination-id] ul li [aria-current='page']) {
431
+ [data-pagination-id] ul li [aria-current='page'] {
278
432
  background-color: var(--vtable-color-accent-light) !important;
279
433
  color: var(--vtable-color-accent) !important;
280
434
  border-color: transparent !important;
@@ -283,10 +437,10 @@
283
437
  /* Ensure Prev/Next controls visually match the numeric buttons' border and rhythm
284
438
  (keeps border, radius and min-width consistent). This is minimal and won't
285
439
  override hover/text colors managed by Tailwind classes applied at runtime. */
286
- :global([data-pagination-id] ul li:first-child > button),
287
- :global([data-pagination-id] ul li:first-child > a),
288
- :global([data-pagination-id] ul li:last-child > button),
289
- :global([data-pagination-id] ul li:last-child > a) {
440
+ [data-pagination-id] ul li:first-child > button,
441
+ [data-pagination-id] ul li:first-child > a,
442
+ [data-pagination-id] ul li:last-child > button,
443
+ [data-pagination-id] ul li:last-child > a {
290
444
  border: 1px solid #d1d5db; /* border-gray-300 */
291
445
  min-width: 2rem; /* align with numeric buttons' min width */
292
446
  background: transparent;
@@ -294,20 +448,20 @@
294
448
  }
295
449
 
296
450
  /* Light mode: hover/focus for Prev/Next match numeric button hover */
297
- :global([data-pagination-id] ul li:first-child > button:hover),
298
- :global([data-pagination-id] ul li:first-child > a:hover),
299
- :global([data-pagination-id] ul li:last-child > button:hover),
300
- :global([data-pagination-id] ul li:last-child > a:hover),
301
- :global([data-pagination-id] ul li:first-child > button:focus),
302
- :global([data-pagination-id] ul li:first-child > a:focus),
303
- :global([data-pagination-id] ul li:last-child > button:focus),
304
- :global([data-pagination-id] ul li:last-child > a:focus) {
451
+ [data-pagination-id] ul li:first-child > button:hover,
452
+ [data-pagination-id] ul li:first-child > a:hover,
453
+ [data-pagination-id] ul li:last-child > button:hover,
454
+ [data-pagination-id] ul li:last-child > a:hover,
455
+ [data-pagination-id] ul li:first-child > button:focus,
456
+ [data-pagination-id] ul li:first-child > a:focus,
457
+ [data-pagination-id] ul li:last-child > button:focus,
458
+ [data-pagination-id] ul li:last-child > a:focus {
305
459
  background-color: #f3f4f6; /* tailwind gray-100 */
306
460
  outline: none;
307
461
  }
308
462
 
309
463
  /* Ellipsis styling: make clickable and visually lighter (JS sets data-ellipsis/data-jump) */
310
- :global([data-pagination-id] ul li [data-ellipsis='true']) {
464
+ [data-pagination-id] ul li [data-ellipsis='true'] {
311
465
  cursor: pointer;
312
466
  background: transparent !important;
313
467
  color: inherit;
@@ -317,8 +471,8 @@
317
471
  }
318
472
 
319
473
  /* Chevron sizing for Prev/Next so icons sit comfortably in the buttons */
320
- :global([data-pagination-id] ul li:first-child svg),
321
- :global([data-pagination-id] ul li:last-child svg) {
474
+ [data-pagination-id] ul li:first-child svg,
475
+ [data-pagination-id] ul li:last-child svg {
322
476
  height: 1.25rem;
323
477
  width: 1.25rem;
324
478
  display: block;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhangt58/svelte-vtable",
3
- "version": "0.4.3",
3
+ "version": "0.5.1",
4
4
  "description": "A Svelte 5 library for virtualized data tables with sorting, selection, and pagination controls.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -31,8 +31,8 @@
31
31
  "scripts": {
32
32
  "check": "svelte-check --tsconfig ./tsconfig.json",
33
33
  "build:styles": "node ./scripts/build-styles.cjs",
34
- "build": "svelte-package -i src/lib",
35
- "prepare": "npm run build:styles && npm run build",
34
+ "build": "svelte-package -i src/lib && node ./scripts/build-styles.cjs",
35
+ "prepare": "npm run build",
36
36
  "prepublishOnly": "npm run build && npm run check && npm run test",
37
37
  "format": "prettier --write .",
38
38
  "format:check": "prettier --check .",