snice 1.14.3 → 2.1.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.
Files changed (185) hide show
  1. package/bin/templates/base/tsconfig.json +5 -4
  2. package/components/accordion/demo.html +403 -0
  3. package/components/accordion/snice-accordion-item.css +85 -0
  4. package/components/accordion/snice-accordion-item.ts +226 -0
  5. package/components/accordion/snice-accordion.css +31 -0
  6. package/components/accordion/snice-accordion.ts +182 -0
  7. package/components/accordion/snice-accordion.types.ts +32 -0
  8. package/components/alert/demo.html +445 -0
  9. package/components/alert/snice-alert.css +195 -0
  10. package/components/alert/snice-alert.ts +141 -0
  11. package/components/alert/snice-alert.types.ts +12 -0
  12. package/components/avatar/demo.html +598 -0
  13. package/components/avatar/snice-avatar.css +131 -0
  14. package/components/avatar/snice-avatar.ts +136 -0
  15. package/components/avatar/snice-avatar.types.ts +13 -0
  16. package/components/badge/demo.html +523 -0
  17. package/components/badge/snice-badge.css +161 -0
  18. package/components/badge/snice-badge.ts +117 -0
  19. package/components/badge/snice-badge.types.ts +16 -0
  20. package/components/breadcrumbs/demo.html +404 -0
  21. package/components/breadcrumbs/snice-breadcrumbs.css +133 -0
  22. package/components/breadcrumbs/snice-breadcrumbs.ts +191 -0
  23. package/components/breadcrumbs/snice-breadcrumbs.types.ts +26 -0
  24. package/components/breadcrumbs/snice-crumb.ts +26 -0
  25. package/components/button/demo.html +42 -0
  26. package/components/button/snice-button.css +230 -0
  27. package/components/button/snice-button.ts +169 -0
  28. package/components/button/snice-button.types.ts +25 -0
  29. package/components/card/demo.html +525 -0
  30. package/components/card/snice-card.css +140 -0
  31. package/components/card/snice-card.ts +102 -0
  32. package/components/card/snice-card.types.ts +10 -0
  33. package/components/checkbox/demo.html +253 -0
  34. package/components/checkbox/snice-checkbox.css +164 -0
  35. package/components/checkbox/snice-checkbox.ts +223 -0
  36. package/components/checkbox/snice-checkbox.types.ts +22 -0
  37. package/components/chip/demo.html +383 -0
  38. package/components/chip/snice-chip.css +195 -0
  39. package/components/chip/snice-chip.ts +139 -0
  40. package/components/chip/snice-chip.types.ts +15 -0
  41. package/components/date-picker/README.md +233 -0
  42. package/components/date-picker/demo.html +191 -0
  43. package/components/date-picker/snice-date-picker.css +330 -0
  44. package/components/date-picker/snice-date-picker.ts +777 -0
  45. package/components/date-picker/snice-date-picker.types.ts +83 -0
  46. package/components/divider/demo.html +233 -0
  47. package/components/divider/snice-divider.css +155 -0
  48. package/components/divider/snice-divider.ts +69 -0
  49. package/components/divider/snice-divider.types.ts +15 -0
  50. package/components/drawer/demo.html +328 -0
  51. package/components/drawer/snice-drawer.css +476 -0
  52. package/components/drawer/snice-drawer.ts +287 -0
  53. package/components/drawer/snice-drawer.types.ts +17 -0
  54. package/components/global.d.ts +14 -0
  55. package/components/input/demo.html +303 -0
  56. package/components/input/snice-input.css +257 -0
  57. package/components/input/snice-input.ts +442 -0
  58. package/components/input/snice-input.types.ts +59 -0
  59. package/components/input/test.html +77 -0
  60. package/components/layout/README.md +260 -0
  61. package/components/layout/demo.html +538 -0
  62. package/components/layout/snice-layout-blog.css +129 -0
  63. package/components/layout/snice-layout-blog.ts +48 -0
  64. package/components/layout/snice-layout-card.css +104 -0
  65. package/components/layout/snice-layout-card.ts +35 -0
  66. package/components/layout/snice-layout-centered.css +51 -0
  67. package/components/layout/snice-layout-centered.ts +22 -0
  68. package/components/layout/snice-layout-dashboard.css +98 -0
  69. package/components/layout/snice-layout-dashboard.ts +45 -0
  70. package/components/layout/snice-layout-fullscreen.css +72 -0
  71. package/components/layout/snice-layout-fullscreen.ts +34 -0
  72. package/components/layout/snice-layout-landing.css +92 -0
  73. package/components/layout/snice-layout-landing.ts +47 -0
  74. package/components/layout/snice-layout-minimal.css +16 -0
  75. package/components/layout/snice-layout-minimal.ts +19 -0
  76. package/components/layout/snice-layout-sidebar.css +117 -0
  77. package/components/layout/snice-layout-sidebar.ts +48 -0
  78. package/components/layout/snice-layout-split.css +103 -0
  79. package/components/layout/snice-layout-split.ts +29 -0
  80. package/components/layout/snice-layout.css +72 -0
  81. package/components/layout/snice-layout.ts +35 -0
  82. package/components/layout/snice-layout.types.ts +5 -0
  83. package/components/login/demo-auth-controller.ts +185 -0
  84. package/components/login/demo.html +470 -0
  85. package/components/login/snice-login.css +204 -0
  86. package/components/login/snice-login.ts +337 -0
  87. package/components/login/snice-login.types.ts +34 -0
  88. package/components/modal/demo.html +291 -0
  89. package/components/modal/snice-modal.css +203 -0
  90. package/components/modal/snice-modal.ts +233 -0
  91. package/components/modal/snice-modal.types.ts +21 -0
  92. package/components/pagination/demo.html +395 -0
  93. package/components/pagination/snice-pagination.ts +333 -0
  94. package/components/pagination/snice-pagination.types.ts +21 -0
  95. package/components/progress/demo.html +510 -0
  96. package/components/progress/snice-progress.css +267 -0
  97. package/components/progress/snice-progress.ts +247 -0
  98. package/components/progress/snice-progress.types.ts +19 -0
  99. package/components/radio/demo.html +287 -0
  100. package/components/radio/snice-radio.css +171 -0
  101. package/components/radio/snice-radio.ts +218 -0
  102. package/components/radio/snice-radio.types.ts +21 -0
  103. package/components/select/demo.html +511 -0
  104. package/components/select/snice-option.ts +52 -0
  105. package/components/select/snice-option.types.ts +14 -0
  106. package/components/select/snice-select.css +392 -0
  107. package/components/select/snice-select.ts +796 -0
  108. package/components/select/snice-select.types.ts +55 -0
  109. package/components/skeleton/demo.html +514 -0
  110. package/components/skeleton/snice-skeleton.css +109 -0
  111. package/components/skeleton/snice-skeleton.ts +126 -0
  112. package/components/skeleton/snice-skeleton.types.ts +11 -0
  113. package/components/switch/demo.html +284 -0
  114. package/components/switch/snice-switch.css +221 -0
  115. package/components/switch/snice-switch.ts +229 -0
  116. package/components/switch/snice-switch.types.ts +23 -0
  117. package/components/symbols.ts +23 -0
  118. package/components/table/demo-table-controller.ts +100 -0
  119. package/components/table/demo.html +480 -0
  120. package/components/table/snice-cell-boolean.ts +112 -0
  121. package/components/table/snice-cell-date.ts +210 -0
  122. package/components/table/snice-cell-duration.ts +91 -0
  123. package/components/table/snice-cell-filesize.ts +90 -0
  124. package/components/table/snice-cell-number.ts +165 -0
  125. package/components/table/snice-cell-progress.ts +83 -0
  126. package/components/table/snice-cell-rating.ts +82 -0
  127. package/components/table/snice-cell-sparkline.ts +253 -0
  128. package/components/table/snice-cell-text.ts +125 -0
  129. package/components/table/snice-cell.css +296 -0
  130. package/components/table/snice-cell.ts +473 -0
  131. package/components/table/snice-column.ts +353 -0
  132. package/components/table/snice-header.css +243 -0
  133. package/components/table/snice-header.ts +261 -0
  134. package/components/table/snice-progress.ts +66 -0
  135. package/components/table/snice-rating.ts +45 -0
  136. package/components/table/snice-row.css +255 -0
  137. package/components/table/snice-row.ts +331 -0
  138. package/components/table/snice-table.css +241 -0
  139. package/components/table/snice-table.ts +737 -0
  140. package/components/table/snice-table.types.ts +158 -0
  141. package/components/tabs/demo.html +487 -0
  142. package/components/tabs/snice-tab-panel.css +264 -0
  143. package/components/tabs/snice-tab-panel.ts +47 -0
  144. package/components/tabs/snice-tab.css +96 -0
  145. package/components/tabs/snice-tab.ts +65 -0
  146. package/components/tabs/snice-tabs.css +189 -0
  147. package/components/tabs/snice-tabs.ts +332 -0
  148. package/components/tabs/snice-tabs.types.ts +28 -0
  149. package/components/theme/theme.css +234 -0
  150. package/components/toast/demo.html +329 -0
  151. package/components/toast/snice-toast-container.ts +256 -0
  152. package/components/toast/snice-toast.css +213 -0
  153. package/components/toast/snice-toast.ts +276 -0
  154. package/components/toast/snice-toast.types.ts +35 -0
  155. package/components/tooltip/demo.html +350 -0
  156. package/components/tooltip/snice-tooltip-portal.css +79 -0
  157. package/components/tooltip/snice-tooltip.css +117 -0
  158. package/components/tooltip/snice-tooltip.ts +612 -0
  159. package/components/tooltip/snice-tooltip.types.ts +32 -0
  160. package/components/transitions.ts +94 -0
  161. package/components/tsconfig.json +18 -0
  162. package/dist/index.cjs +441 -329
  163. package/dist/index.cjs.map +1 -1
  164. package/dist/index.cjs.min.map +1 -1
  165. package/dist/index.esm.js +441 -329
  166. package/dist/index.esm.js.map +1 -1
  167. package/dist/index.esm.min.js +3 -3
  168. package/dist/index.esm.min.js.map +1 -1
  169. package/dist/index.iife.js +441 -329
  170. package/dist/index.iife.js.map +1 -1
  171. package/dist/index.iife.min.js +3 -3
  172. package/dist/index.iife.min.js.map +1 -1
  173. package/dist/symbols.esm.js +1 -1
  174. package/dist/transitions.esm.js +1 -1
  175. package/dist/types/controller.d.ts +1 -1
  176. package/dist/types/element.d.ts +10 -10
  177. package/dist/types/events.d.ts +2 -2
  178. package/dist/types/index.d.ts +1 -1
  179. package/dist/types/observe.d.ts +1 -1
  180. package/dist/types/request-response.d.ts +2 -3
  181. package/dist/types/router.d.ts +1 -1
  182. package/package.json +9 -3
  183. package/dist/index.cjs.min +0 -15
  184. package/dist/symbols.cjs +0 -103
  185. package/dist/transitions.cjs +0 -219
@@ -0,0 +1,737 @@
1
+ import { element, on, property, query, request, dispatch, watch } from 'snice';
2
+ import 'snice/input/snice-input';
3
+ import 'snice/select/snice-select';
4
+ import './snice-cell.ts';
5
+ import './snice-cell-text.ts';
6
+ import './snice-cell-number.ts';
7
+ import './snice-cell-date.ts';
8
+ import './snice-cell-boolean.ts';
9
+ import './snice-cell-rating.ts';
10
+ import './snice-cell-progress.ts';
11
+ import './snice-cell-duration.ts';
12
+ import './snice-cell-filesize.ts';
13
+ import './snice-cell-sparkline.ts';
14
+
15
+ @element('snice-table')
16
+ export class SniceTable extends HTMLElement {
17
+
18
+ @property({ type: Boolean, reflect: true, attribute: 'striped' })
19
+ striped = false;
20
+
21
+ @property({ type: Boolean, reflect: true, attribute: 'searchable' })
22
+ searchable = false;
23
+
24
+ @property({ type: Boolean, reflect: true, attribute: 'sortable' })
25
+ sortable = false;
26
+
27
+ @property({ type: Boolean, reflect: true, attribute: 'selectable' })
28
+ selectable = false;
29
+
30
+ @property({ type: Boolean, reflect: true, attribute: 'hoverable' })
31
+ hoverable = true;
32
+
33
+ @property({ type: Boolean, reflect: true, attribute: 'clickable' })
34
+ clickable = false;
35
+
36
+ @property({ type: Array, attribute: 'columns' })
37
+ columns: any[] = [];
38
+
39
+ @property({ type: Array, attribute: 'data' })
40
+ data: any[] = [];
41
+
42
+ @property({ type: Array, attribute: 'current-sort' })
43
+ currentSort: Array<{ column: string, direction: 'asc' | 'desc' }> = [];
44
+
45
+ @property({ type: String, attribute: 'search-text' })
46
+ searchText: string = '';
47
+
48
+ @property({ type: String, attribute: 'selector' })
49
+ selector: string = '';
50
+
51
+ @property({ type: Array, attribute: 'selector-options' })
52
+ selectorOptions: Array<{value: string, label: string}> = [];
53
+
54
+ @property({ type: Boolean, reflect: true, attribute: 'loading' })
55
+ loading: boolean = false;
56
+
57
+ @property({ type: Array, attribute: 'selected-rows' })
58
+ selectedRows: number[] = [];
59
+
60
+ @query('table')
61
+ table!: HTMLTableElement;
62
+
63
+ @query('thead')
64
+ thead!: HTMLTableSectionElement;
65
+
66
+ @query('tbody')
67
+ tbody!: HTMLTableSectionElement;
68
+
69
+ @request('@snice/table/config')
70
+ async *getTableConfig(): any {
71
+ const config = await (yield {});
72
+ this.columns = config.columns || [];
73
+ this.selectorOptions = config.selectorOptions || [];
74
+ this.render();
75
+ return config;
76
+ }
77
+
78
+ @request('@snice/table/data')
79
+ async *getTableData(): any {
80
+ this.loading = true;
81
+ this.selectedRows = []; // Clear selections when loading new data
82
+
83
+ try {
84
+ const params = {
85
+ search: this.searchText,
86
+ sort: this.currentSort,
87
+ selector: this.selector
88
+ };
89
+ console.log('Requesting table data with params:', params);
90
+ const response = await (yield params);
91
+ console.log('Received table data response:', response);
92
+ this.data = response.data || [];
93
+ this.loading = false;
94
+ this.render();
95
+ return response;
96
+ } catch (error) {
97
+ console.error('Error loading table data:', error);
98
+ this.data = [];
99
+ this.loading = false;
100
+ this.render();
101
+ }
102
+ }
103
+
104
+ private dataRequestTimeout: any = null;
105
+
106
+ private debouncedDataRequest() {
107
+ // Set loading immediately for instant feedback
108
+ if (!this.loading) {
109
+ this.loading = true;
110
+ }
111
+
112
+ if (this.dataRequestTimeout) {
113
+ clearTimeout(this.dataRequestTimeout);
114
+ }
115
+
116
+ this.dataRequestTimeout = setTimeout(() => {
117
+ this.getTableData();
118
+ this.dataRequestTimeout = null;
119
+ }, 500);
120
+ }
121
+
122
+ css() {
123
+ return /*css*/`
124
+ :host {
125
+ display: block;
126
+ }
127
+
128
+ .snice-table {
129
+ border-collapse: collapse;
130
+ width: 100%;
131
+ }
132
+
133
+ table {
134
+ width: 100%;
135
+ border-collapse: separate;
136
+ border-spacing: 0;
137
+ border-radius: var(--snice-border-radius-lg);
138
+ overflow: hidden;
139
+ border: 1px solid var(--snice-color-border);
140
+ }
141
+
142
+ th, td {
143
+ padding: var(--snice-spacing-sm);
144
+ border: 1px solid var(--snice-color-border);
145
+ text-align: left;
146
+ color: var(--snice-color-text);
147
+ }
148
+
149
+ th {
150
+ background-color: var(--snice-color-background-secondary);
151
+ color: var(--snice-color-text);
152
+ font-weight: var(--snice-font-weight-semibold);
153
+ border-bottom: 2px solid var(--snice-color-border);
154
+ }
155
+
156
+ th.sortable {
157
+ cursor: pointer;
158
+ user-select: none;
159
+ }
160
+
161
+ th.sortable:hover {
162
+ background-color: var(--snice-color-background-tertiary);
163
+ }
164
+
165
+ /* Row styling */
166
+ :host([striped]) tbody tr:nth-child(even) {
167
+ background-color: var(--snice-color-background-secondary);
168
+ }
169
+
170
+ :host([hoverable]) tbody tr:hover {
171
+ background-color: var(--snice-color-background-tertiary);
172
+ }
173
+
174
+ :host([clickable]) tbody tr {
175
+ cursor: pointer;
176
+ }
177
+
178
+ :host([selectable]) tbody tr {
179
+ cursor: pointer;
180
+ }
181
+
182
+ tbody tr[data-selected="true"] {
183
+ background-color: var(--snice-color-background-tertiary);
184
+ border-left: 3px solid var(--snice-color-primary);
185
+ }
186
+
187
+ tbody tr[data-selected="true"]:hover {
188
+ background-color: var(--snice-color-background-tertiary);
189
+ }
190
+
191
+ [part="header"] {
192
+ background-color: var(--snice-color-background);
193
+ }
194
+
195
+ [part="body"] {
196
+ background-color: var(--snice-table-body-bg, --snice-color-background);
197
+ display: block;
198
+ }
199
+
200
+ .table-controls {
201
+ display: flex;
202
+ gap: var(--snice-spacing-md);
203
+ align-items: center;
204
+ flex-wrap: wrap;
205
+ }
206
+
207
+ :host(:not([searchable])) .search-input {
208
+ display: none;
209
+ }
210
+
211
+ :host(.selector-options-empty) .selector-input {
212
+ display: none;
213
+ }
214
+
215
+ .search-input {
216
+ min-width: 200px;
217
+ flex: 1;
218
+ }
219
+
220
+ .selector-input {
221
+ min-width: 150px;
222
+ }
223
+
224
+ /* Sort indicators */
225
+ .sort-header {
226
+ display: flex;
227
+ align-items: center;
228
+ gap: var(--snice-spacing-xs);
229
+ justify-content: space-between;
230
+ }
231
+
232
+
233
+ .sort-indicator {
234
+ display: flex;
235
+ flex-direction: column;
236
+ font-size: 0.7em;
237
+ line-height: 1;
238
+ opacity: 0.3;
239
+ transition: opacity var(--snice-transition-fast);
240
+ }
241
+
242
+ .sort-indicator.active {
243
+ opacity: 1;
244
+ }
245
+
246
+ .sort-order {
247
+ font-size: 0.6em;
248
+ background: var(--snice-color-primary);
249
+ color: var(--snice-color-text-inverse);
250
+ border-radius: var(--snice-border-radius-sm);
251
+ padding: 1px 3px;
252
+ min-width: 12px;
253
+ text-align: center;
254
+ }
255
+
256
+ /* Loading fade */
257
+ tbody {
258
+ transition: opacity var(--snice-transition-normal);
259
+ }
260
+
261
+ :host([loading]) tbody {
262
+ opacity: 0.5;
263
+ }
264
+
265
+ .no-data {
266
+ text-align: center;
267
+ padding: var(--snice-spacing-lg);
268
+ color: var(--snice-color-text-secondary);
269
+ }
270
+ `;
271
+ }
272
+
273
+ html() {
274
+ return /*html*/`
275
+ <div class="snice-table">
276
+ ${this.renderControls()}
277
+ <table>
278
+ <thead></thead>
279
+ <tbody></tbody>
280
+ </table>
281
+ </div>
282
+ `;
283
+ }
284
+
285
+ renderControls() {
286
+ return /*html*/`
287
+ <div class="table-controls" part="controls">
288
+ <snice-input
289
+ class="search-input"
290
+ type="search"
291
+ placeholder="Search..."
292
+ value="${this.searchText}"
293
+ size="medium"
294
+ ></snice-input>
295
+ <snice-select
296
+ class="selector-input"
297
+ multiple
298
+ searchable
299
+ clearable
300
+ placeholder="Filter..."
301
+ size="medium"
302
+ >
303
+ ${this.selectorOptions.map(opt =>
304
+ `<snice-option value="${opt.value}">${opt.label}</snice-option>`
305
+ ).join('')}
306
+ </snice-select>
307
+ </div>
308
+ `;
309
+ }
310
+
311
+ render() {
312
+ console.log('render() called');
313
+ this.renderHeader();
314
+ this.renderBody();
315
+ }
316
+
317
+ @watch('selector-options')
318
+ handleSelectorOptionsChange() {
319
+ // Update CSS class to show/hide selector
320
+ if (this.selectorOptions.length === 0) {
321
+ this.classList.add('selector-options-empty');
322
+ } else {
323
+ this.classList.remove('selector-options-empty');
324
+ }
325
+ }
326
+
327
+ @watch('sortable')
328
+ handleSortableChange() {
329
+ this.renderHeader(); // Re-render header to show/hide sort indicators
330
+ }
331
+
332
+ @watch('selectable')
333
+ handleSelectableChange() {
334
+ this.render(); // Re-render both header and body for checkbox columns
335
+ }
336
+
337
+ @watch('columns')
338
+ handleColumnsChange() {
339
+ this.renderHeader();
340
+ }
341
+
342
+ @watch('data', 'loading')
343
+ handleDataChange() {
344
+ this.renderBody();
345
+ }
346
+
347
+ @watch('selected-rows')
348
+ handleSelectedRowsChange() {
349
+ this.updateRowSelectionState();
350
+ this.updateSelectAllState();
351
+ }
352
+
353
+ @watch('current-sort')
354
+ handleSortChange() {
355
+ this.renderHeader();
356
+ }
357
+
358
+ renderHeader() {
359
+ if (!this.thead) return;
360
+
361
+ const headerRow = document.createElement('tr');
362
+
363
+ if (this.selectable) {
364
+ const selectCell = document.createElement('th');
365
+ const allSelected = this.selectedRows.length === this.data.length && this.data.length > 0;
366
+ const someSelected = this.selectedRows.length > 0 && this.selectedRows.length < this.data.length;
367
+ selectCell.innerHTML = `<input type="checkbox" class="select-all" ${allSelected ? 'checked' : ''} />`;
368
+ headerRow.appendChild(selectCell);
369
+
370
+ // Set indeterminate after insertion
371
+ setTimeout(() => {
372
+ const checkbox = selectCell.querySelector('.select-all') as HTMLInputElement;
373
+ if (checkbox) {
374
+ checkbox.indeterminate = someSelected;
375
+ }
376
+ }, 0);
377
+ }
378
+
379
+ this.columns.forEach(column => {
380
+ const th = document.createElement('th');
381
+ th.setAttribute('data-key', column.key);
382
+
383
+ if (this.sortable && column.sortable !== false) {
384
+ th.classList.add('sortable');
385
+ th.setAttribute('role', 'button');
386
+ th.innerHTML = this.renderSortableHeader(column);
387
+ } else {
388
+ th.textContent = column.label;
389
+ }
390
+
391
+ headerRow.appendChild(th);
392
+ });
393
+
394
+ this.thead.innerHTML = '';
395
+ this.thead.appendChild(headerRow);
396
+ }
397
+
398
+ renderSortableHeader(column: any): string {
399
+ const sortItem = this.currentSort.find(s => s.column === column.key);
400
+ const sortIndex = this.currentSort.findIndex(s => s.column === column.key);
401
+ const isActive = !!sortItem;
402
+
403
+ let indicator = '▲▼'; // Default unsorted state
404
+ let orderNumber = '';
405
+
406
+ if (sortItem) {
407
+ if (sortItem.direction === 'asc') {
408
+ indicator = '▲';
409
+ } else if (sortItem.direction === 'desc') {
410
+ indicator = '▼';
411
+ }
412
+
413
+ if (this.currentSort.length > 1) {
414
+ orderNumber = `<span class="sort-order">${sortIndex + 1}</span>`;
415
+ }
416
+ }
417
+
418
+ return `
419
+ <div class="sort-header">
420
+ <span>${column.label}</span>
421
+ <div class="sort-indicator ${isActive ? 'active' : ''}">
422
+ ${indicator}
423
+ ${orderNumber}
424
+ </div>
425
+ </div>
426
+ `;
427
+ }
428
+
429
+
430
+ renderBody() {
431
+ if (!this.tbody) return;
432
+
433
+ console.log('renderBody called with data:', this.data.length, 'columns:', this.columns.length, 'loading:', this.loading);
434
+
435
+ this.tbody.innerHTML = '';
436
+
437
+ if (this.data.length === 0 && this.columns.length > 0) {
438
+ if (this.loading) {
439
+ // Show loading spinner
440
+ const tr = document.createElement('tr');
441
+ const td = document.createElement('td');
442
+ const colSpan = this.columns.length + (this.selectable ? 1 : 0);
443
+ td.colSpan = colSpan;
444
+ td.className = 'no-data';
445
+ td.innerHTML = '<snice-progress variant="circular" indeterminate size="small"></snice-progress>';
446
+ tr.appendChild(td);
447
+ this.tbody.appendChild(tr);
448
+ return;
449
+ } else {
450
+ // Show "No Data" message
451
+ const tr = document.createElement('tr');
452
+ const td = document.createElement('td');
453
+ const colSpan = this.columns.length + (this.selectable ? 1 : 0);
454
+ td.colSpan = colSpan;
455
+ td.className = 'no-data';
456
+ td.textContent = 'No Data';
457
+ tr.appendChild(td);
458
+ this.tbody.appendChild(tr);
459
+ return;
460
+ }
461
+ }
462
+
463
+ this.data.forEach((rowData, index) => {
464
+ const tr = document.createElement('tr');
465
+ tr.setAttribute('data-index', String(index));
466
+
467
+ // Set row selection state
468
+ const isSelected = this.selectedRows.includes(index);
469
+ tr.setAttribute('data-selected', String(isSelected));
470
+
471
+ if (this.selectable) {
472
+ const selectCell = document.createElement('td');
473
+ selectCell.innerHTML = `<input type="checkbox" class="row-select" ${isSelected ? 'checked' : ''} data-row-index="${index}" />`;
474
+ tr.appendChild(selectCell);
475
+ }
476
+
477
+ this.columns.forEach(column => {
478
+ const td = document.createElement('td');
479
+ const value = rowData[column.key];
480
+
481
+ // Create cell component as HTML string
482
+ const cellTagName = this.getCellTagName(column.type);
483
+ const attributes = this.getCellAttributes(column, value);
484
+ td.innerHTML = `<${cellTagName} ${attributes}></${cellTagName}>`;
485
+
486
+ tr.appendChild(td);
487
+ });
488
+
489
+ this.tbody.appendChild(tr);
490
+ });
491
+ }
492
+
493
+ getCellAttributes(column: any, value: any): string {
494
+ const attributes = [
495
+ `type="${column.type}"`,
496
+ `align="${column.align || 'left'}"`,
497
+ `value="${String(value || '').replace(/"/g, '&quot;')}"`,
498
+ `in-table="true"`
499
+ ];
500
+
501
+ // Add type-specific attributes
502
+ if (column.type === 'number' || column.type === 'currency') {
503
+ if (column.decimals !== undefined) attributes.push(`decimals="${column.decimals}"`);
504
+ if (column.thousandsSeparator) attributes.push(`thousands-separator="true"`);
505
+ if (column.prefix) attributes.push(`prefix="${column.prefix}"`);
506
+ if (column.suffix) attributes.push(`suffix="${column.suffix}"`);
507
+ }
508
+
509
+ if (column.type === 'date') {
510
+ if (column.dateFormat) attributes.push(`date-format="${column.dateFormat}"`);
511
+ }
512
+
513
+ if (column.type === 'boolean') {
514
+ if (column.useSymbols) attributes.push(`use-symbols="true"`);
515
+ if (column.trueSymbol) attributes.push(`true-symbol="${column.trueSymbol}"`);
516
+ if (column.falseSymbol) attributes.push(`false-symbol="${column.falseSymbol}"`);
517
+ if (column.trueValue) attributes.push(`true-value="${column.trueValue}"`);
518
+ if (column.falseValue) attributes.push(`false-value="${column.falseValue}"`);
519
+ }
520
+
521
+ return attributes.join(' ');
522
+ }
523
+
524
+ getCellTagName(type: string): string {
525
+ switch (type) {
526
+ case 'text':
527
+ return 'snice-cell-text';
528
+ case 'number':
529
+ case 'currency':
530
+ return 'snice-cell-number';
531
+ case 'date':
532
+ return 'snice-cell-date';
533
+ case 'boolean':
534
+ return 'snice-cell-boolean';
535
+ case 'rating':
536
+ return 'snice-cell-rating';
537
+ case 'progress':
538
+ return 'snice-cell-progress';
539
+ case 'duration':
540
+ return 'snice-cell-duration';
541
+ case 'filesize':
542
+ return 'snice-cell-filesize';
543
+ case 'sparkline':
544
+ return 'snice-cell-sparkline';
545
+ default:
546
+ return 'snice-cell';
547
+ }
548
+ }
549
+
550
+ @on('click', 'th.sortable')
551
+ handleSort(e: MouseEvent) {
552
+ const th = (e.target as HTMLElement).closest('th.sortable');
553
+ if (!th) return;
554
+
555
+ const columnKey = th.getAttribute('data-key');
556
+ if (columnKey) {
557
+ console.log('Sorting column:', columnKey);
558
+ this.toggleSort(columnKey, true); // Always multi-sort
559
+ }
560
+ }
561
+
562
+
563
+ @on('change', '.row-select')
564
+ handleRowSelect(e: Event) {
565
+ const checkbox = e.target as HTMLInputElement;
566
+ const rowIndex = parseInt(checkbox.getAttribute('data-row-index') || '0');
567
+
568
+ if (checkbox.checked) {
569
+ if (!this.selectedRows.includes(rowIndex)) {
570
+ this.selectedRows = [...this.selectedRows, rowIndex];
571
+ }
572
+ } else {
573
+ this.selectedRows = this.selectedRows.filter(i => i !== rowIndex);
574
+ }
575
+
576
+ this.updateRowSelectionState();
577
+ this.updateSelectAllState();
578
+ this.dispatchRowSelectionChanged(rowIndex, checkbox.checked);
579
+ }
580
+
581
+ @on('change', '.select-all')
582
+ handleSelectAll(e: Event) {
583
+ const checkbox = e.target as HTMLInputElement;
584
+
585
+ if (checkbox.checked) {
586
+ this.selectedRows = this.data.map((_, index) => index);
587
+ } else {
588
+ this.selectedRows = [];
589
+ }
590
+
591
+ this.updateRowSelectionState();
592
+ this.dispatchSelectAllChanged(checkbox.checked);
593
+ }
594
+
595
+ @on('click', 'tbody tr')
596
+ handleRowClick(e: Event) {
597
+ const tr = (e.target as HTMLElement).closest('tr');
598
+ if (!tr) return;
599
+
600
+ const target = e.target as HTMLElement;
601
+
602
+ // Don't trigger if clicking on checkbox or other interactive elements
603
+ if (target.matches('input[type="checkbox"], button, a, .interactive')) {
604
+ return;
605
+ }
606
+
607
+ const rowIndex = parseInt(tr.getAttribute('data-index') || '0');
608
+ const rowData = this.data[rowIndex];
609
+
610
+ // Handle row selection if selectable
611
+ if (this.selectable) {
612
+ const isCurrentlySelected = this.selectedRows.includes(rowIndex);
613
+
614
+ if (isCurrentlySelected) {
615
+ this.selectedRows = this.selectedRows.filter(i => i !== rowIndex);
616
+ } else {
617
+ this.selectedRows = [...this.selectedRows, rowIndex];
618
+ }
619
+
620
+ this.updateRowSelectionState();
621
+ this.updateSelectAllState();
622
+ this.dispatchRowSelectionChanged(rowIndex, !isCurrentlySelected);
623
+ }
624
+
625
+ // Handle clickable row event
626
+ if (this.clickable) {
627
+ this.dispatchEvent(new CustomEvent('row-clicked', {
628
+ detail: { rowData, rowIndex }
629
+ }));
630
+ }
631
+ }
632
+
633
+ @on('@snice/controller-attached')
634
+ onAttached() {
635
+ console.log('Controller attached, loading config and data...');
636
+ this.getTableConfig();
637
+ this.getTableData();
638
+ }
639
+
640
+ @on('input', '.search-input', { debounce: 500 })
641
+ handleSearchChange(e: Event) {
642
+ const input = e.target as HTMLInputElement;
643
+ this.searchText = input.value;
644
+ this.debouncedDataRequest();
645
+ }
646
+
647
+ @on('@snice/select/change', '.selector-input', { debounce: 150 })
648
+ handleSelectorChange(e: CustomEvent) {
649
+ this.selector = Array.isArray(e.detail.value) ? e.detail.value.join(',') : e.detail.value;
650
+ this.debouncedDataRequest();
651
+ }
652
+
653
+
654
+ updateRowSelectionState() {
655
+ if (!this.tbody) return;
656
+
657
+ const rows = this.tbody.querySelectorAll('tr');
658
+ rows.forEach((row, index) => {
659
+ const isSelected = this.selectedRows.includes(index);
660
+ row.setAttribute('data-selected', String(isSelected));
661
+
662
+ const checkbox = row.querySelector('.row-select') as HTMLInputElement;
663
+ if (checkbox) {
664
+ checkbox.checked = isSelected;
665
+ }
666
+ });
667
+ }
668
+
669
+ updateSelectAllState() {
670
+ const selectAllCheckbox = this.thead?.querySelector('.select-all') as HTMLInputElement;
671
+ if (!selectAllCheckbox) return;
672
+
673
+ const allSelected = this.selectedRows.length === this.data.length;
674
+ const someSelected = this.selectedRows.length > 0 && this.selectedRows.length < this.data.length;
675
+
676
+ selectAllCheckbox.checked = allSelected;
677
+ selectAllCheckbox.indeterminate = someSelected;
678
+ }
679
+
680
+ toggleSort(columnKey: string, multiSort: boolean = false) {
681
+ console.log('toggleSort called:', { columnKey, multiSort, currentSort: this.currentSort });
682
+
683
+ if (!multiSort) {
684
+ // Single column sort - clear all other sorts
685
+ const existingSort = this.currentSort.find(s => s.column === columnKey);
686
+
687
+ if (!existingSort) {
688
+ this.currentSort = [{ column: columnKey, direction: 'asc' }];
689
+ } else if (existingSort.direction === 'asc') {
690
+ this.currentSort = [{ column: columnKey, direction: 'desc' }];
691
+ } else {
692
+ this.currentSort = [];
693
+ }
694
+ } else {
695
+ // Multi column sort - modify existing or add new
696
+ const existingSortIndex = this.currentSort.findIndex(s => s.column === columnKey);
697
+
698
+ if (existingSortIndex === -1) {
699
+ // Add new sort
700
+ this.currentSort = [...this.currentSort, { column: columnKey, direction: 'asc' }];
701
+ } else {
702
+ const existingSort = this.currentSort[existingSortIndex];
703
+ if (existingSort.direction === 'asc') {
704
+ // Change to desc - create new array to trigger reactivity
705
+ this.currentSort = this.currentSort.map((sort, index) =>
706
+ index === existingSortIndex ? { ...sort, direction: 'desc' as const } : sort
707
+ );
708
+ } else {
709
+ // Remove this sort
710
+ this.currentSort = this.currentSort.filter(s => s.column !== columnKey);
711
+ }
712
+ }
713
+ }
714
+
715
+ console.log('New sort state:', this.currentSort);
716
+ this.renderHeader(); // Update sort indicators immediately
717
+ this.debouncedDataRequest(); // Show loading immediately, debounce the actual request
718
+ }
719
+
720
+ @dispatch('@snice/table/row-selection-changed', { bubbles: true, composed: true })
721
+ private dispatchRowSelectionChanged(rowIndex: number, selected: boolean) {
722
+ return {
723
+ selectedRows: this.selectedRows,
724
+ rowIndex,
725
+ selected
726
+ };
727
+ }
728
+
729
+ @dispatch('@snice/table/select-all-changed', { bubbles: true, composed: true })
730
+ private dispatchSelectAllChanged(allSelected: boolean) {
731
+ return {
732
+ selectedRows: this.selectedRows,
733
+ allSelected
734
+ };
735
+ }
736
+
737
+ }