@kodaris/krubble-components 1.0.9 → 1.0.10

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.
@@ -0,0 +1,1146 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { LitElement, html, css, nothing } from 'lit';
8
+ import { customElement, property, state } from 'lit/decorators.js';
9
+ import { classMap } from 'lit/directives/class-map.js';
10
+ import { styleMap } from 'lit/directives/style-map.js';
11
+ import { krBaseCSS } from '../style/base.js';
12
+ import '../button/button.js';
13
+ import { KRSnackbar } from '../snackbar/snackbar.js';
14
+ // === Solr Utilities ===
15
+ const SOLR_RESERVED_CHARS = [
16
+ '"', '+', '-', '&&', '||', '!', '(', ')', '{',
17
+ '}', '[', ']', '^', '~', '*', '?', ':'
18
+ ];
19
+ const SOLR_RESERVED_CHARS_REPLACEMENT = [
20
+ '\\"', '\\+', '\\-', '\\&\\&', '\\|\\|', '\\!', '\\(', '\\)', '\\{',
21
+ '\\}', '\\[', '\\]', '\\^', '\\~', '\\*', '\\?', '\\:'
22
+ ];
23
+ function escapeSolrQuery(query) {
24
+ let escaped = query;
25
+ for (let i = 0; i < SOLR_RESERVED_CHARS.length; i++) {
26
+ escaped = escaped.split(SOLR_RESERVED_CHARS[i]).join(SOLR_RESERVED_CHARS_REPLACEMENT[i]);
27
+ }
28
+ return escaped;
29
+ }
30
+ let KRTable = class KRTable extends LitElement {
31
+ constructor() {
32
+ super(...arguments);
33
+ /**
34
+ * Internal flag to switch between scroll edge modes:
35
+ * - 'overlay': Fixed padding with overlay elements that hide content at edges (scrollbar at viewport edge)
36
+ * - 'edge': Padding scrolls with content, allowing table to reach edges when scrolling
37
+ */
38
+ this._scrollStyle = 'edge';
39
+ this._data = [];
40
+ this._dataState = 'idle';
41
+ this._page = 1;
42
+ this._pageSize = 50;
43
+ this._totalItems = 0;
44
+ this._totalPages = 0;
45
+ this._searchQuery = '';
46
+ this._canScrollLeft = false;
47
+ this._canScrollRight = false;
48
+ this._canScrollHorizontal = false;
49
+ this._columnPickerOpen = false;
50
+ this._displayedColumns = [];
51
+ this._columnWidths = new Map();
52
+ this._resizing = null;
53
+ this._resizeObserver = null;
54
+ this._searchPositionLocked = false;
55
+ this.def = { columns: [] };
56
+ this._handleClickOutsideColumnPicker = (e) => {
57
+ if (!this._columnPickerOpen)
58
+ return;
59
+ const path = e.composedPath();
60
+ const picker = this.shadowRoot?.querySelector('.column-picker-wrapper');
61
+ if (picker && !path.includes(picker)) {
62
+ this._columnPickerOpen = false;
63
+ }
64
+ };
65
+ this._handleResizeMove = (e) => {
66
+ if (!this._resizing)
67
+ return;
68
+ this._columnWidths.set(this._resizing.columnId, Math.max(50, this._resizing.startWidth + (e.clientX - this._resizing.startX)));
69
+ this.requestUpdate();
70
+ };
71
+ this._handleResizeEnd = () => {
72
+ this._resizing = null;
73
+ document.removeEventListener('mousemove', this._handleResizeMove);
74
+ document.removeEventListener('mouseup', this._handleResizeEnd);
75
+ };
76
+ }
77
+ connectedCallback() {
78
+ super.connectedCallback();
79
+ this.classList.toggle('kr-table--scroll-overlay', this._scrollStyle === 'overlay');
80
+ this.classList.toggle('kr-table--scroll-edge', this._scrollStyle === 'edge');
81
+ this._fetch();
82
+ this._initRefresh();
83
+ document.addEventListener('click', this._handleClickOutsideColumnPicker);
84
+ this._resizeObserver = new ResizeObserver(() => {
85
+ // Unlock and recalculate on resize since layout changes
86
+ this._searchPositionLocked = false;
87
+ this._updateSearchPosition();
88
+ });
89
+ this._resizeObserver.observe(this);
90
+ }
91
+ disconnectedCallback() {
92
+ super.disconnectedCallback();
93
+ clearInterval(this._refreshTimer);
94
+ document.removeEventListener('click', this._handleClickOutsideColumnPicker);
95
+ this._resizeObserver?.disconnect();
96
+ }
97
+ updated(changedProperties) {
98
+ if (changedProperties.has('def')) {
99
+ this._displayedColumns = this.def.displayedColumns || this.def.columns.map(c => c.id);
100
+ this._fetch();
101
+ this._initRefresh();
102
+ }
103
+ this._updateScrollFlags();
104
+ }
105
+ // ----------------------------------------------------------------------------
106
+ // Public Interface
107
+ // ----------------------------------------------------------------------------
108
+ refresh() {
109
+ this._fetch();
110
+ }
111
+ goToPrevPage() {
112
+ if (this._page > 1) {
113
+ this._page--;
114
+ this._fetch();
115
+ }
116
+ }
117
+ goToNextPage() {
118
+ if (this._page < this._totalPages) {
119
+ this._page++;
120
+ this._fetch();
121
+ }
122
+ }
123
+ goToPage(page) {
124
+ if (page >= 1 && page <= this._totalPages) {
125
+ this._page = page;
126
+ this._fetch();
127
+ }
128
+ }
129
+ // ----------------------------------------------------------------------------
130
+ // Data Fetching
131
+ // ----------------------------------------------------------------------------
132
+ /**
133
+ * Fetches data from the API and updates the table.
134
+ * Shows a loading spinner while fetching, then displays rows on success
135
+ * or an error snackbar on failure.
136
+ * Request/response format depends on dataSource.mode (solr, opensearch, db).
137
+ */
138
+ _fetch() {
139
+ if (!this.def.dataSource)
140
+ return;
141
+ this._dataState = 'loading';
142
+ // Build request based on mode
143
+ let request;
144
+ switch (this.def.dataSource.mode) {
145
+ case 'opensearch':
146
+ throw Error('Opensearch not supported yet');
147
+ case 'db':
148
+ throw Error('DB not supported yet');
149
+ default: // solr
150
+ request = {
151
+ page: this._page - 1,
152
+ size: this._pageSize,
153
+ sorts: [],
154
+ filterFields: [],
155
+ queryFields: [],
156
+ facetFields: []
157
+ };
158
+ if (this._searchQuery?.trim().length) {
159
+ request.queryFields.push({
160
+ name: '_text_',
161
+ operation: 'IS',
162
+ value: escapeSolrQuery(this._searchQuery)
163
+ });
164
+ }
165
+ }
166
+ this.def.dataSource.fetch(request)
167
+ .then(response => {
168
+ // Parse response based on mode
169
+ switch (this.def.dataSource?.mode) {
170
+ case 'opensearch': {
171
+ throw Error('Opensearch not supported yet');
172
+ break;
173
+ }
174
+ case 'db': {
175
+ throw Error('DB not supported yet');
176
+ break;
177
+ }
178
+ default: { // solr
179
+ const res = response;
180
+ this._data = res.data.content;
181
+ this._totalItems = res.data.totalElements;
182
+ this._totalPages = res.data.totalPages;
183
+ this._pageSize = res.data.size;
184
+ }
185
+ }
186
+ this._dataState = 'success';
187
+ this._updateSearchPosition();
188
+ })
189
+ .catch(err => {
190
+ this._dataState = 'error';
191
+ KRSnackbar.show({
192
+ message: err instanceof Error ? err.message : 'Failed to load data',
193
+ type: 'error'
194
+ });
195
+ });
196
+ }
197
+ /**
198
+ * Sets up auto-refresh so the table automatically fetches fresh data
199
+ * at a regular interval (useful for dashboards, monitoring views).
200
+ * Configured via def.refreshInterval in milliseconds.
201
+ */
202
+ _initRefresh() {
203
+ clearInterval(this._refreshTimer);
204
+ if (this.def.refreshInterval && this.def.refreshInterval > 0) {
205
+ this._refreshTimer = window.setInterval(() => {
206
+ this._fetch();
207
+ }, this.def.refreshInterval);
208
+ }
209
+ }
210
+ _handleSearch(e) {
211
+ const input = e.target;
212
+ this._searchQuery = input.value;
213
+ this._page = 1;
214
+ this._fetch();
215
+ }
216
+ /**
217
+ * Updates search position to be centered with equal gaps from title and tools.
218
+ * On first call: resets to flex centering, measures position, then locks with fixed margin.
219
+ * Subsequent calls are ignored unless _searchPositionLocked is reset (e.g., on resize).
220
+ */
221
+ _updateSearchPosition() {
222
+ // Skip if already locked (prevents shifts on pagination changes)
223
+ if (this._searchPositionLocked)
224
+ return;
225
+ const search = this.shadowRoot?.querySelector('.search');
226
+ const searchField = search?.querySelector('.search-field');
227
+ if (!search || !searchField)
228
+ return;
229
+ // Reset to flex centering
230
+ search.style.justifyContent = 'center';
231
+ searchField.style.marginLeft = '';
232
+ requestAnimationFrame(() => {
233
+ const searchRect = search.getBoundingClientRect();
234
+ const fieldRect = searchField.getBoundingClientRect();
235
+ // Calculate how far from the left of search container the field currently is
236
+ const currentOffset = fieldRect.left - searchRect.left;
237
+ // Lock position: switch to flex-start and use fixed margin
238
+ search.style.justifyContent = 'flex-start';
239
+ searchField.style.marginLeft = `${currentOffset}px`;
240
+ // Mark as locked so pagination changes don't shift the search
241
+ this._searchPositionLocked = true;
242
+ });
243
+ }
244
+ // ----------------------------------------------------------------------------
245
+ // Columns
246
+ // ----------------------------------------------------------------------------
247
+ _toggleColumnPicker() {
248
+ this._columnPickerOpen = !this._columnPickerOpen;
249
+ }
250
+ _toggleColumn(columnId) {
251
+ if (this._displayedColumns.includes(columnId)) {
252
+ this._displayedColumns = this._displayedColumns.filter(id => id !== columnId);
253
+ }
254
+ else {
255
+ this._displayedColumns = [...this._displayedColumns, columnId];
256
+ }
257
+ }
258
+ // When a user toggles a column on via the column picker, it gets appended
259
+ // to _displayedColumns. By mapping over _displayedColumns (not def.columns),
260
+ // the new column appears at the right edge of the table instead of jumping
261
+ // back to its original position in the column definition.
262
+ getDisplayedColumns() {
263
+ return this._displayedColumns.map(id => this.def.columns.find(col => col.id === id));
264
+ }
265
+ // ----------------------------------------------------------------------------
266
+ // Scrolling
267
+ // ----------------------------------------------------------------------------
268
+ /**
269
+ * Scroll event handler that updates scroll flags in real-time as user scrolls.
270
+ * Updates shadow indicators to show if more content exists left/right.
271
+ */
272
+ _handleScroll(e) {
273
+ const container = e.target;
274
+ this._canScrollLeft = container.scrollLeft > 0;
275
+ this._canScrollRight = container.scrollLeft < container.scrollWidth - container.clientWidth - 1;
276
+ }
277
+ /**
278
+ * Updates scroll state flags for the table content container.
279
+ * - _canScrollLeft: true if scrolled right (can scroll back left)
280
+ * - _canScrollRight: true if more content exists to the right
281
+ * - _canScrollHorizontal: true if content is wider than container
282
+ * These flags control scroll shadow indicators and CSS classes.
283
+ */
284
+ _updateScrollFlags() {
285
+ const container = this.shadowRoot?.querySelector('.content');
286
+ if (container) {
287
+ this._canScrollLeft = container.scrollLeft > 0;
288
+ this._canScrollRight = container.scrollWidth > container.clientWidth && container.scrollLeft < container.scrollWidth - container.clientWidth - 1;
289
+ this._canScrollHorizontal = container.scrollWidth > container.clientWidth;
290
+ }
291
+ this.classList.toggle('kr-table--scroll-left-available', this._canScrollLeft);
292
+ this.classList.toggle('kr-table--scroll-right-available', this._canScrollRight);
293
+ this.classList.toggle('kr-table--scroll-horizontal-available', this._canScrollHorizontal);
294
+ }
295
+ // ----------------------------------------------------------------------------
296
+ // Column Resizing
297
+ // ----------------------------------------------------------------------------
298
+ _handleResizeStart(e, columnId) {
299
+ e.preventDefault();
300
+ const column = this.def.columns.find(c => c.id === columnId);
301
+ this._resizing = {
302
+ columnId,
303
+ startX: e.clientX,
304
+ startWidth: this._columnWidths.get(columnId) || parseInt(column?.width || '150', 10)
305
+ };
306
+ document.addEventListener('mousemove', this._handleResizeMove);
307
+ document.addEventListener('mouseup', this._handleResizeEnd);
308
+ }
309
+ // ----------------------------------------------------------------------------
310
+ // Header
311
+ // ----------------------------------------------------------------------------
312
+ _handleAction(action) {
313
+ this.dispatchEvent(new CustomEvent('action', {
314
+ detail: { action: action.id },
315
+ bubbles: true,
316
+ composed: true
317
+ }));
318
+ }
319
+ // ----------------------------------------------------------------------------
320
+ // Rendering
321
+ // ----------------------------------------------------------------------------
322
+ _renderCellContent(column, row) {
323
+ const value = row[column.id];
324
+ if (column.render) {
325
+ return column.render(row);
326
+ }
327
+ if (value === null || value === undefined) {
328
+ return '';
329
+ }
330
+ switch (column.type) {
331
+ case 'number':
332
+ return typeof value === 'number' ? value.toLocaleString() : String(value);
333
+ case 'currency':
334
+ return typeof value === 'number'
335
+ ? value.toLocaleString('en-US', { style: 'currency', currency: 'USD' })
336
+ : String(value);
337
+ case 'date':
338
+ return value instanceof Date
339
+ ? value.toLocaleDateString()
340
+ : new Date(value).toLocaleDateString();
341
+ case 'boolean':
342
+ if (value === true)
343
+ return 'Yes';
344
+ if (value === false)
345
+ return 'No';
346
+ return '';
347
+ default:
348
+ return String(value);
349
+ }
350
+ }
351
+ /**
352
+ * Returns CSS classes for a header cell based on column config.
353
+ */
354
+ _getHeaderCellClasses(column, index) {
355
+ return {
356
+ 'header-cell': true,
357
+ 'header-cell--align-center': column.align === 'center',
358
+ 'header-cell--align-right': column.align === 'right',
359
+ 'header-cell--sticky-left': column.sticky === 'left',
360
+ 'header-cell--sticky-left-last': column.sticky === 'left' &&
361
+ !this.getDisplayedColumns().slice(index + 1).some(c => c.sticky === 'left'),
362
+ 'header-cell--sticky-right': column.sticky === 'right',
363
+ 'header-cell--sticky-right-first': column.sticky === 'right' &&
364
+ !this.getDisplayedColumns().slice(0, index).some(c => c.sticky === 'right')
365
+ };
366
+ }
367
+ /**
368
+ * Returns CSS classes for a table cell based on column config:
369
+ * - Alignment (center, right)
370
+ * - Sticky positioning (left, right)
371
+ * - Border classes for the last left-sticky or first right-sticky column
372
+ */
373
+ _getCellClasses(column, index) {
374
+ return {
375
+ 'cell': true,
376
+ 'cell--align-center': column.align === 'center',
377
+ 'cell--align-right': column.align === 'right',
378
+ 'cell--sticky-left': column.sticky === 'left',
379
+ 'cell--sticky-left-last': column.sticky === 'left' &&
380
+ !this.getDisplayedColumns().slice(index + 1).some(c => c.sticky === 'left'),
381
+ 'cell--sticky-right': column.sticky === 'right',
382
+ 'cell--sticky-right-first': column.sticky === 'right' &&
383
+ !this.getDisplayedColumns().slice(0, index).some(c => c.sticky === 'right')
384
+ };
385
+ }
386
+ /**
387
+ * Returns inline styles for a table cell:
388
+ * - Width (from column config or default 150px)
389
+ * - Min-width (if specified)
390
+ * - Left/right offset for sticky columns (calculated from widths of preceding sticky columns)
391
+ */
392
+ _getCellStyle(column, index) {
393
+ const styles = {};
394
+ const isLastColumn = index === this.getDisplayedColumns().length - 1;
395
+ const customWidth = this._columnWidths.get(column.id);
396
+ const width = customWidth ? `${customWidth}px` : (column.width || '150px');
397
+ if (isLastColumn && !customWidth) {
398
+ styles.flex = '1';
399
+ styles.minWidth = column.width || '150px';
400
+ styles.marginRight = '24px';
401
+ }
402
+ else {
403
+ styles.width = width;
404
+ }
405
+ if (column.minWidth)
406
+ styles.minWidth = column.minWidth;
407
+ if (column.sticky === 'left') {
408
+ let leftOffset = 0;
409
+ for (let i = 0; i < index; i++) {
410
+ if (this.getDisplayedColumns()[i].sticky === 'left') {
411
+ leftOffset += parseInt(this.getDisplayedColumns()[i].width || '150', 10);
412
+ }
413
+ }
414
+ styles.left = `${leftOffset}px`;
415
+ }
416
+ if (column.sticky === 'right') {
417
+ let rightOffset = 0;
418
+ for (let i = index + 1; i < this.getDisplayedColumns().length; i++) {
419
+ if (this.getDisplayedColumns()[i].sticky === 'right') {
420
+ rightOffset += parseInt(this.getDisplayedColumns()[i].width || '150', 10);
421
+ }
422
+ }
423
+ styles.right = `${rightOffset}px`;
424
+ }
425
+ return styles;
426
+ }
427
+ /**
428
+ * Renders the pagination controls:
429
+ * - Previous page arrow (disabled on first page)
430
+ * - Range text showing "1-50 of 150" format
431
+ * - Next page arrow (disabled on last page)
432
+ *
433
+ * Hidden when there's no data or all data fits on one page.
434
+ */
435
+ _renderPagination() {
436
+ const start = (this._page - 1) * this._pageSize + 1;
437
+ const end = Math.min(this._page * this._pageSize, this._totalItems);
438
+ return html `
439
+ <div class="pagination">
440
+ <span
441
+ class="pagination-icon ${this._page === 1 ? 'pagination-icon--disabled' : ''}"
442
+ @click=${this.goToPrevPage}
443
+ >
444
+ <svg viewBox="0 0 24 24" fill="currentColor"><path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/></svg>
445
+ </span>
446
+ <span class="pagination-info">${start}-${end} of ${this._totalItems}</span>
447
+ <span
448
+ class="pagination-icon ${this._page === this._totalPages ? 'pagination-icon--disabled' : ''}"
449
+ @click=${this.goToNextPage}
450
+ >
451
+ <svg viewBox="0 0 24 24" fill="currentColor"><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg>
452
+ </span>
453
+ </div>
454
+ `;
455
+ }
456
+ /**
457
+ * Renders the header toolbar containing:
458
+ * - Title (left)
459
+ * - Search bar with view selector dropdown (center)
460
+ * - Tools (right): page navigation, refresh button, column visibility picker, actions dropdown
461
+ *
462
+ * Hidden when there's no title, no actions, and data fits on one page.
463
+ */
464
+ _renderHeader() {
465
+ if (!this.def.title && !this.def.actions?.length && this._totalPages <= 1) {
466
+ return nothing;
467
+ }
468
+ return html `
469
+ <div class="header">
470
+ <div class="title">${this.def.title ?? ''}</div>
471
+ <div class="search">
472
+ <!-- TODO: Saved views dropdown
473
+ <div class="views">
474
+ <span>Default View</span>
475
+ <svg viewBox="0 0 24 24" fill="currentColor"><path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z"/></svg>
476
+ </div>
477
+ -->
478
+ <div class="search-field">
479
+ <svg class="search-icon" viewBox="0 -960 960 960" fill="currentColor"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400Z"/></svg>
480
+ <input
481
+ type="text"
482
+ class="search-input"
483
+ placeholder="Search..."
484
+ .value=${this._searchQuery}
485
+ @input=${this._handleSearch}
486
+ />
487
+ </div>
488
+ </div>
489
+ <div class="tools">
490
+ ${this._renderPagination()}
491
+ <span class="refresh" title="Refresh" @click=${() => this.refresh()}>
492
+ <svg viewBox="0 -960 960 960" fill="currentColor"><path d="M480-160q-134 0-227-93t-93-227q0-134 93-227t227-93q69 0 132 28.5T720-690v-110h80v280H520v-80h168q-32-56-87.5-88T480-720q-100 0-170 70t-70 170q0 100 70 170t170 70q77 0 139-44t87-116h84q-28 106-114 173t-196 67Z"/></svg>
493
+ </span>
494
+ <div class="column-picker-wrapper">
495
+ <span class="header-icon" title="Columns" @click=${this._toggleColumnPicker}>
496
+ <svg viewBox="0 -960 960 960" fill="currentColor"><path d="M121-280v-400q0-33 23.5-56.5T201-760h559q33 0 56.5 23.5T840-680v400q0 33-23.5 56.5T760-200H201q-33 0-56.5-23.5T121-280Zm79 0h133v-400H200v400Zm213 0h133v-400H413v400Zm213 0h133v-400H626v400Z"/></svg>
497
+ </span>
498
+ <div class="column-picker ${this._columnPickerOpen ? 'open' : ''}">
499
+ ${[...this.def.columns].sort((a, b) => (a.label ?? a.id).localeCompare(b.label ?? b.id)).map(col => html `
500
+ <div class="column-picker-item" @click=${() => this._toggleColumn(col.id)}>
501
+ <div class="column-picker-checkbox ${this._displayedColumns.includes(col.id) ? 'checked' : ''}">
502
+ <svg viewBox="0 0 24 24" fill="currentColor"><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/></svg>
503
+ </div>
504
+ <span class="column-picker-label">${col.label ?? col.id}</span>
505
+ </div>
506
+ `)}
507
+ </div>
508
+ </div>
509
+ ${this.def.actions?.length ? html `
510
+ <kr-button
511
+ class="actions"
512
+ .options=${this.def.actions.map(a => ({ id: a.id, label: a.label }))}
513
+ @option-select=${(e) => this._handleAction({ id: e.detail.id, label: e.detail.label })}
514
+ >
515
+ Actions
516
+ </kr-button>
517
+ ` : nothing}
518
+ </div>
519
+ </div>
520
+ `;
521
+ }
522
+ /** Renders status message (loading, error, empty) */
523
+ _renderStatus() {
524
+ if (this._dataState === 'loading' && this._data.length === 0) {
525
+ return html `<div class="status">Loading...</div>`;
526
+ }
527
+ if (this._dataState === 'error' && this._data.length === 0) {
528
+ return html `<div class="status status--error">Error loading data</div>`;
529
+ }
530
+ if (this._data.length === 0) {
531
+ return html `<div class="status">No data available</div>`;
532
+ }
533
+ return nothing;
534
+ }
535
+ /** Renders the scrollable data grid with column headers and rows. */
536
+ _renderTable() {
537
+ return html `
538
+ <div class="wrapper">
539
+ <div class="overlay-left"></div>
540
+ <div class="overlay-right"></div>
541
+ ${this._renderStatus()}
542
+ <div class="content" @scroll=${this._handleScroll}>
543
+ <div class="table">
544
+ <div class="header-row">
545
+ ${this.getDisplayedColumns().map((col, i) => html `
546
+ <div
547
+ class=${classMap(this._getHeaderCellClasses(col, i))}
548
+ style=${styleMap(this._getCellStyle(col, i))}
549
+ >
550
+ <span class="header-cell__label">${col.label ?? col.id}</span>
551
+ <div
552
+ class="header-cell__resize"
553
+ @mousedown=${(e) => this._handleResizeStart(e, col.id)}
554
+ ></div>
555
+ </div>
556
+ `)}
557
+ </div>
558
+ ${this._data.map(row => html `
559
+ <div class="row">
560
+ ${this.getDisplayedColumns().map((col, i) => html `
561
+ <div
562
+ class=${classMap(this._getCellClasses(col, i))}
563
+ style=${styleMap(this._getCellStyle(col, i))}
564
+ >
565
+ ${this._renderCellContent(col, row)}
566
+ </div>
567
+ `)}
568
+ </div>
569
+ `)}
570
+ </div>
571
+ </div>
572
+ </div>
573
+ `;
574
+ }
575
+ /**
576
+ * Renders a data table with:
577
+ * - Header bar with title, search input with view selector, and tools (pagination, refresh, column visibility, actions dropdown)
578
+ * - Scrollable grid with sticky header row and optional sticky left/right columns
579
+ * - Loading, error message, or empty state when no data
580
+ */
581
+ render() {
582
+ if (!this.def.columns.length) {
583
+ return html `<slot></slot>`;
584
+ }
585
+ return html `
586
+ ${this._renderHeader()}
587
+ ${this._renderTable()}
588
+ `;
589
+ }
590
+ };
591
+ KRTable.styles = [krBaseCSS, css `
592
+ /* -------------------------------------------------------------------------
593
+ * Host
594
+ * ----------------------------------------------------------------------- */
595
+ :host {
596
+ display: flex;
597
+ flex-direction: column;
598
+ width: 100%;
599
+ height: 100%;
600
+ overflow: hidden;
601
+ container-type: inline-size;
602
+ }
603
+
604
+ /* -------------------------------------------------------------------------
605
+ * Header
606
+ * ----------------------------------------------------------------------- */
607
+ .header {
608
+ flex-shrink: 0;
609
+ display: flex;
610
+ align-items: center;
611
+ gap: 16px;
612
+ margin: 0 24px;
613
+ padding: 0 4px;
614
+ height: 64px;
615
+ border-bottom: 1px solid #e5e7eb;
616
+ background: #fff;
617
+ }
618
+
619
+ :host(.kr-table--scroll-edge) .header {
620
+ border-bottom: none;
621
+ }
622
+
623
+ .title {
624
+ font-size: 20px;
625
+ font-weight: 400;
626
+ color: #000;
627
+ }
628
+
629
+ /* -------------------------------------------------------------------------
630
+ * Content
631
+ * ----------------------------------------------------------------------- */
632
+ .wrapper {
633
+ flex: 1;
634
+ position: relative;
635
+ overflow: hidden;
636
+ }
637
+
638
+ .content {
639
+ height: 100%;
640
+ overflow: auto;
641
+ padding-bottom: 24px;
642
+ }
643
+
644
+ /* -------------------------------------------------------------------------
645
+ * Search
646
+ * ----------------------------------------------------------------------- */
647
+ .search {
648
+ flex: 1;
649
+ display: flex;
650
+ align-items: center;
651
+ justify-content: center;
652
+ min-width: 0;
653
+ }
654
+
655
+ .search-field {
656
+ width: 100%;
657
+ max-width: 400px;
658
+ position: relative;
659
+ display: flex;
660
+ align-items: center;
661
+ border: 1px solid #00000038;
662
+ border-radius: 18px;
663
+ transition: border-color 0.2s, box-shadow 0.2s;
664
+ }
665
+
666
+ .search-field:focus-within {
667
+ border-color: #163052;
668
+ box-shadow: 0 0 0 3px rgba(22, 48, 82, 0.1);
669
+ }
670
+
671
+ /* TODO: Uncomment when views dropdown is added
672
+ .search-field:focus-within .views {
673
+ border-color: #163052;
674
+ }
675
+ */
676
+
677
+ .search-icon {
678
+ position: absolute;
679
+ left: 16px;
680
+ width: 20px;
681
+ height: 20px;
682
+ color: #656871;
683
+ pointer-events: none;
684
+ }
685
+
686
+ .search-input {
687
+ height: 36px;
688
+ padding: 0 16px 0 42px;
689
+ border: none;
690
+ border-radius: 16px;
691
+ font-size: 14px;
692
+ font-weight: 400;
693
+ font-family: inherit;
694
+ color: #163052;
695
+ background: transparent;
696
+ outline: none;
697
+ flex: 1;
698
+ min-width: 0;
699
+ width: 100%;
700
+ }
701
+
702
+ .search-input::placeholder {
703
+ color: #656871;
704
+ font-weight: 400;
705
+ }
706
+
707
+ .search-input:focus {
708
+ outline: none;
709
+ }
710
+
711
+ @container (max-width: 800px) {
712
+ .search-field {
713
+ max-width: 250px;
714
+ }
715
+ }
716
+
717
+ .views {
718
+ display: flex;
719
+ align-items: center;
720
+ gap: 4px;
721
+ height: 36px;
722
+ padding: 0 16px;
723
+ border: 1px solid #00000038;
724
+ border-right: none;
725
+ border-radius: 16px 0 0 16px;
726
+ font-size: 14px;
727
+ font-family: inherit;
728
+ color: #163052;
729
+ background: transparent;
730
+ cursor: pointer;
731
+ white-space: nowrap;
732
+ transition: border-color 0.2s;
733
+ }
734
+
735
+ .views:hover {
736
+ background: #e8f0f8;
737
+ }
738
+
739
+ .views svg {
740
+ width: 16px;
741
+ height: 16px;
742
+ color: #163052;
743
+ }
744
+
745
+ /* -------------------------------------------------------------------------
746
+ * Pagination
747
+ * ----------------------------------------------------------------------- */
748
+ .tools {
749
+ display: flex;
750
+ align-items: center;
751
+ gap: 8px;
752
+ }
753
+
754
+ .pagination {
755
+ display: flex;
756
+ align-items: center;
757
+ gap: 2px;
758
+ }
759
+
760
+ .pagination-info {
761
+ font-size: 13px;
762
+ color: var(--kr-primary);
763
+ white-space: nowrap;
764
+ }
765
+
766
+ .pagination-icon {
767
+ display: flex;
768
+ color: var(--kr-primary);
769
+ cursor: pointer;
770
+ }
771
+
772
+ .pagination-icon--disabled {
773
+ opacity: 0.3;
774
+ pointer-events: none;
775
+ }
776
+
777
+ .pagination-icon svg {
778
+ width: 24px;
779
+ height: 24px;
780
+ }
781
+
782
+ /* -------------------------------------------------------------------------
783
+ * Header Icons
784
+ * ----------------------------------------------------------------------- */
785
+ .refresh,
786
+ .header-icon {
787
+ display: flex;
788
+ align-items: center;
789
+ justify-content: center;
790
+ color: var(--kr-primary);
791
+ background: #EBF1FA;
792
+ cursor: pointer;
793
+ padding: 6px;
794
+ border-radius: 50%;
795
+ transition: background 0.15s;
796
+ }
797
+
798
+ .refresh:hover,
799
+ .header-icon:hover {
800
+ background: #e8f0f8;
801
+ }
802
+
803
+ .refresh svg,
804
+ .header-icon svg {
805
+ width: 24px;
806
+ height: 24px;
807
+ }
808
+
809
+ /* -------------------------------------------------------------------------
810
+ * Column Picker
811
+ * ----------------------------------------------------------------------- */
812
+ .column-picker-wrapper {
813
+ position: relative;
814
+ }
815
+
816
+ .column-picker {
817
+ position: absolute;
818
+ top: 100%;
819
+ right: 0;
820
+ margin-top: 4px;
821
+ min-width: 200px;
822
+ max-height: calc(100vh - 120px);
823
+ overflow-y: auto;
824
+ background: white;
825
+ border: 1px solid #9ba7b6;
826
+ border-radius: 8px;
827
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
828
+ padding: 8px 0;
829
+ z-index: 100;
830
+ display: none;
831
+ transform-origin: top;
832
+ }
833
+
834
+ .column-picker.open {
835
+ display: block;
836
+ animation: column-picker-fade-in 150ms ease-out;
837
+ }
838
+
839
+ @keyframes column-picker-fade-in {
840
+ from {
841
+ opacity: 0;
842
+ transform: translateY(-4px);
843
+ }
844
+ to {
845
+ opacity: 1;
846
+ transform: translateY(0);
847
+ }
848
+ }
849
+
850
+ .column-picker-item {
851
+ display: flex;
852
+ align-items: center;
853
+ gap: 10px;
854
+ padding: 8px 16px;
855
+ cursor: pointer;
856
+ white-space: nowrap;
857
+ }
858
+
859
+ .column-picker-item:hover {
860
+ background: #f3f4f6;
861
+ }
862
+
863
+ .column-picker-checkbox {
864
+ width: 16px;
865
+ height: 16px;
866
+ border: 1.5px solid #9ca3af;
867
+ border-radius: 3px;
868
+ display: flex;
869
+ align-items: center;
870
+ justify-content: center;
871
+ flex-shrink: 0;
872
+ transition: all 0.15s;
873
+ }
874
+
875
+ .column-picker-checkbox.checked {
876
+ background: var(--kr-primary);
877
+ border-color: var(--kr-primary);
878
+ }
879
+
880
+ .column-picker-checkbox svg {
881
+ width: 12px;
882
+ height: 12px;
883
+ color: white;
884
+ opacity: 0;
885
+ }
886
+
887
+ .column-picker-checkbox.checked svg {
888
+ opacity: 1;
889
+ }
890
+
891
+ .column-picker-label {
892
+ font-size: 14px;
893
+ color: #374151;
894
+ }
895
+
896
+ /* -------------------------------------------------------------------------
897
+ * Table Structure
898
+ * ----------------------------------------------------------------------- */
899
+ .table {
900
+ display: flex;
901
+ flex-direction: column;
902
+ width: 100%;
903
+ min-width: max-content;
904
+ font-size: 14px;
905
+ }
906
+
907
+ .row {
908
+ display: flex;
909
+ }
910
+
911
+ .header-row {
912
+ display: flex;
913
+ position: sticky;
914
+ top: 0;
915
+ z-index: 2;
916
+ }
917
+
918
+ .row:hover .cell {
919
+ background: #f9fafb;
920
+ }
921
+
922
+ .cell {
923
+ padding: 12px 16px;
924
+ white-space: nowrap;
925
+ overflow: hidden;
926
+ text-overflow: ellipsis;
927
+ flex-shrink: 0;
928
+ box-sizing: border-box;
929
+ }
930
+
931
+ .header-cell {
932
+ display: flex;
933
+ align-items: center;
934
+ padding: 12px 16px;
935
+ white-space: nowrap;
936
+ flex-shrink: 0;
937
+ box-sizing: border-box;
938
+ background: #f9fafb;
939
+ border-bottom: 2px solid #e5e7eb;
940
+ font-weight: 600;
941
+ color: #374151;
942
+ overflow: visible;
943
+ }
944
+
945
+ .header-cell__label {
946
+ flex: 1;
947
+ overflow: hidden;
948
+ text-overflow: ellipsis;
949
+ }
950
+
951
+ .header-cell__resize {
952
+ width: 14px;
953
+ margin-right: -22px;
954
+ align-self: stretch;
955
+ cursor: col-resize;
956
+ display: flex;
957
+ align-items: center;
958
+ justify-content: center;
959
+ z-index: 1;
960
+ }
961
+
962
+ .header-cell__resize::after {
963
+ content: '';
964
+ width: 2px;
965
+ height: 20px;
966
+ background: #c6c6cd;
967
+ }
968
+
969
+ .header-cell:last-child .header-cell__resize::after {
970
+ display: none;
971
+ }
972
+
973
+ .cell {
974
+ background: #fff;
975
+ border-bottom: 1px solid #e5e7eb;
976
+ color: #1f2937;
977
+ }
978
+
979
+ .cell--align-center {
980
+ text-align: center;
981
+ }
982
+
983
+ .cell--align-right {
984
+ text-align: right;
985
+ }
986
+
987
+ .cell--sticky-left,
988
+ .cell--sticky-right {
989
+ position: sticky;
990
+ z-index: 1;
991
+ }
992
+
993
+ .header-cell--sticky-left,
994
+ .header-cell--sticky-right {
995
+ position: sticky;
996
+ z-index: 3;
997
+ }
998
+
999
+ .header-cell--align-center {
1000
+ text-align: center;
1001
+ }
1002
+
1003
+ .header-cell--align-right {
1004
+ text-align: right;
1005
+ }
1006
+
1007
+ .header-cell--sticky-left-last,
1008
+ .cell--sticky-left-last {
1009
+ border-right: 1px solid #d1d5db;
1010
+ }
1011
+
1012
+ .header-cell--sticky-right-first,
1013
+ .cell--sticky-right-first {
1014
+ border-left: 1px solid #d1d5db;
1015
+ }
1016
+
1017
+ /* -------------------------------------------------------------------------
1018
+ * Scroll Mode: Edge
1019
+ * Padding scrolls with content, table can reach edges when scrolling
1020
+ * ----------------------------------------------------------------------- */
1021
+ :host(.kr-table--scroll-edge) .table {
1022
+ padding-left: 24px;
1023
+ }
1024
+
1025
+ /* Only add right padding when no horizontal scroll is needed */
1026
+ :host(.kr-table--scroll-edge):not(.kr-table--scroll-horizontal-available) .table {
1027
+ padding-right: 24px;
1028
+ }
1029
+
1030
+ :host(.kr-table--scroll-edge) .header-row .header-cell {
1031
+ border-top: 1px solid #e5e7eb;
1032
+ }
1033
+
1034
+ /* -------------------------------------------------------------------------
1035
+ * Scroll Mode: Overlay
1036
+ * Fixed padding with overlay elements that hide content at edges
1037
+ * ----------------------------------------------------------------------- */
1038
+ :host(.kr-table--scroll-overlay) .content {
1039
+ padding-left: 24px;
1040
+ padding-right: 24px;
1041
+ }
1042
+
1043
+ .overlay-left,
1044
+ .overlay-right {
1045
+ display: none;
1046
+ position: absolute;
1047
+ top: 0;
1048
+ bottom: 0;
1049
+ width: 24px;
1050
+ z-index: 5;
1051
+ pointer-events: none;
1052
+ transition: box-shadow 0.15s ease;
1053
+ }
1054
+
1055
+ :host(.kr-table--scroll-overlay) .overlay-left,
1056
+ :host(.kr-table--scroll-overlay) .overlay-right {
1057
+ display: block;
1058
+ }
1059
+
1060
+ .overlay-left {
1061
+ left: 0;
1062
+ background: linear-gradient(to right, #fff 50%, transparent);
1063
+ }
1064
+
1065
+ .overlay-right {
1066
+ right: 0;
1067
+ background: linear-gradient(to left, #fff 50%, transparent);
1068
+ }
1069
+
1070
+ :host(.kr-table--scroll-left-available) .overlay-left {
1071
+ box-shadow: inset -6px 0 6px -6px rgba(0, 0, 0, 0.08);
1072
+ }
1073
+
1074
+ :host(.kr-table--scroll-right-available) .overlay-right {
1075
+ box-shadow: inset 6px 0 6px -6px rgba(0, 0, 0, 0.08);
1076
+ }
1077
+
1078
+ /* -------------------------------------------------------------------------
1079
+ * Status (Loading, Error, Empty)
1080
+ * ----------------------------------------------------------------------- */
1081
+ .status {
1082
+ position: absolute;
1083
+ top: 0;
1084
+ left: 0;
1085
+ right: 0;
1086
+ bottom: 0;
1087
+ display: flex;
1088
+ align-items: center;
1089
+ justify-content: center;
1090
+ font-size: 14px;
1091
+ font-weight: 400;
1092
+ color: #5f6368;
1093
+ pointer-events: none;
1094
+ }
1095
+
1096
+ .status--error {
1097
+ color: #dc2626;
1098
+ }
1099
+ `];
1100
+ __decorate([
1101
+ state()
1102
+ ], KRTable.prototype, "_data", void 0);
1103
+ __decorate([
1104
+ state()
1105
+ ], KRTable.prototype, "_dataState", void 0);
1106
+ __decorate([
1107
+ state()
1108
+ ], KRTable.prototype, "_page", void 0);
1109
+ __decorate([
1110
+ state()
1111
+ ], KRTable.prototype, "_pageSize", void 0);
1112
+ __decorate([
1113
+ state()
1114
+ ], KRTable.prototype, "_totalItems", void 0);
1115
+ __decorate([
1116
+ state()
1117
+ ], KRTable.prototype, "_totalPages", void 0);
1118
+ __decorate([
1119
+ state()
1120
+ ], KRTable.prototype, "_searchQuery", void 0);
1121
+ __decorate([
1122
+ state()
1123
+ ], KRTable.prototype, "_canScrollLeft", void 0);
1124
+ __decorate([
1125
+ state()
1126
+ ], KRTable.prototype, "_canScrollRight", void 0);
1127
+ __decorate([
1128
+ state()
1129
+ ], KRTable.prototype, "_canScrollHorizontal", void 0);
1130
+ __decorate([
1131
+ state()
1132
+ ], KRTable.prototype, "_columnPickerOpen", void 0);
1133
+ __decorate([
1134
+ state()
1135
+ ], KRTable.prototype, "_displayedColumns", void 0);
1136
+ __decorate([
1137
+ state()
1138
+ ], KRTable.prototype, "_columnWidths", void 0);
1139
+ __decorate([
1140
+ property({ type: Object })
1141
+ ], KRTable.prototype, "def", void 0);
1142
+ KRTable = __decorate([
1143
+ customElement('kr-table')
1144
+ ], KRTable);
1145
+ export { KRTable };
1146
+ //# sourceMappingURL=table.js.map