@mintplayer/web-components 2.14.0 → 2.16.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 (63) hide show
  1. package/README.md +15 -0
  2. package/badge/src/styles/badge.styles.d.ts +2 -0
  3. package/chunks/install-light-styles-DbCAGFOC.mjs +209 -0
  4. package/chunks/mp-datatable-B7st6G-I.mjs +2238 -0
  5. package/chunks/{mp-datetime-picker.element-D1CiLbHm.mjs → mp-datetime-picker.element-DsWA1AFs.mjs} +2 -2
  6. package/chunks/{mp-timepicker.element-COZEUIoE.mjs → mp-timepicker.element-CwaAAOcm.mjs} +1 -1
  7. package/chunks/{mp-treeview-tkWu28iF.mjs → mp-treeview-C8iltDbq.mjs} +61 -63
  8. package/chunks/{overlay-controller-D6agzzOI.mjs → overlay-controller-DifgO6jT.mjs} +103 -47
  9. package/datatable/index.mjs +6 -5
  10. package/datatable/src/components/mp-datatable.d.ts +210 -2
  11. package/datatable/src/index.d.ts +4 -2
  12. package/datatable/src/styles/datatable.light.styles.d.ts +2 -0
  13. package/datatable/src/styles/index.d.ts +1 -1
  14. package/datatable/src/types/column-def.d.ts +61 -0
  15. package/datatable/src/types/filter.d.ts +138 -0
  16. package/datatable/src/types/index.d.ts +3 -2
  17. package/datatable/src/types/labels.d.ts +58 -0
  18. package/datepicker/index.mjs +1 -1
  19. package/datetime-picker/index.mjs +1 -1
  20. package/dock/index.mjs +477 -492
  21. package/dock/src/components/mint-dock-manager.element.d.ts +10 -8
  22. package/dock/src/core/index.d.ts +1 -0
  23. package/dock/src/core/intersection-sizing.d.ts +83 -0
  24. package/dock/src/core/layout-tree.d.ts +23 -2
  25. package/dock/src/core/types.d.ts +14 -0
  26. package/file-manager/index.mjs +30 -29
  27. package/file-manager/src/components/mp-file-manager.d.ts +2 -0
  28. package/light-dom/index.d.ts +1 -0
  29. package/light-dom/index.mjs +11 -0
  30. package/light-dom/src/index.d.ts +2 -0
  31. package/light-dom/src/install-light-styles.d.ts +25 -0
  32. package/light-dom/src/scoped-html.d.ts +26 -0
  33. package/navbar/index.mjs +1 -1
  34. package/overlay/index.mjs +5 -2
  35. package/overlay/src/index.d.ts +2 -0
  36. package/overlay/src/overlay-controller.d.ts +27 -0
  37. package/overlay/src/overlay-portal.d.ts +53 -0
  38. package/package.json +5 -1
  39. package/query-builder/index.mjs +1472 -2651
  40. package/query-builder/src/index.d.ts +4 -0
  41. package/query-builder/src/mp-query-builder.element.d.ts +1 -1
  42. package/query-builder/src/mp-query-builder.light.styles.d.ts +2 -0
  43. package/query-builder/src/mp-query-condition.element.d.ts +1 -1
  44. package/query-builder/src/mp-query-condition.light.styles.d.ts +2 -0
  45. package/query-builder/src/mp-query-group.element.d.ts +1 -1
  46. package/query-builder/src/mp-query-group.light.styles.d.ts +2 -0
  47. package/query-builder/src/mp-query-subquery.element.d.ts +1 -1
  48. package/query-builder/src/mp-query-subquery.light.styles.d.ts +2 -0
  49. package/ribbon/index.mjs +1 -1
  50. package/scheduler/index.mjs +2 -2
  51. package/timepicker/index.mjs +1 -1
  52. package/tree-select/index.mjs +60 -58
  53. package/tree-select/src/components/mp-tree-select.d.ts +1 -1
  54. package/tree-select/src/index.d.ts +1 -1
  55. package/tree-select/src/styles/index.d.ts +1 -1
  56. package/tree-select/src/styles/tree-select.light.styles.d.ts +2 -0
  57. package/treeview/index.mjs +3 -3
  58. package/treeview/src/components/mp-treeview.d.ts +1 -1
  59. package/treeview/src/index.d.ts +1 -1
  60. package/treeview/src/styles/index.d.ts +1 -1
  61. package/treeview/src/styles/treeview.light.styles.d.ts +2 -0
  62. package/chunks/mp-datatable-GmKqaN8y.mjs +0 -1392
  63. package/datatable/src/styles/datatable.styles.d.ts +0 -2
@@ -0,0 +1,2238 @@
1
+ import { unsafeCSS as F, LitElement as E, nothing as u, render as v } from "lit";
2
+ import { O as I } from "./overlay-controller-DifgO6jT.mjs";
3
+ import { s as L, i as M } from "./install-light-styles-DbCAGFOC.mjs";
4
+ import { L as P } from "./live-announcer-Bi0orG4n.mjs";
5
+ import { a as k, F as z } from "./focus-restore-DxuP1Oe2.mjs";
6
+ import { H as q } from "./host-aria-WSGs7SPQ.mjs";
7
+ import { repeat as x } from "lit/directives/repeat.js";
8
+ import { live as K } from "lit/directives/live.js";
9
+ import { classMap as C } from "lit/directives/class-map.js";
10
+ import { styleMap as _ } from "lit/directives/style-map.js";
11
+ import "./mp-pagination-Dea75mD4.mjs";
12
+ import "./mp-checkbox-CzwS7Y_t.mjs";
13
+ const A = {
14
+ eq: "equals",
15
+ neq: "does not equal",
16
+ lt: "is less than",
17
+ lte: "is at most",
18
+ gt: "is greater than",
19
+ gte: "is at least"
20
+ }, U = {
21
+ eq: "=",
22
+ neq: "≠",
23
+ lt: "<",
24
+ lte: "≤",
25
+ gt: ">",
26
+ gte: "≥"
27
+ }, T = ["eq", "neq", "lt", "lte", "gt", "gte"], O = {
28
+ treeChevronColumn: "Expand or collapse",
29
+ deselectAll: "Deselect all",
30
+ selectAll: "Select all",
31
+ expandRow: "Expand row",
32
+ collapseRow: "Collapse row",
33
+ loading: "Loading",
34
+ rowsPerPage: "Rows per page",
35
+ resizeColumn: (n) => `Resize column ${n}`,
36
+ selectRow: (n) => `Select row ${n}`,
37
+ filterColumn: (n) => `Filter ${n}`,
38
+ filterColumnActive: (n, e) => e ? `Filter ${n}, filtered by ${e}` : `Filter ${n}, filtered`,
39
+ filterClear: (n) => `Clear the filter on ${n}`,
40
+ filterSearch: "Search values",
41
+ filterInvert: "Exclude the selected values",
42
+ filterGroup: (n) => `Values of ${n}`,
43
+ filterHasMore: "More values exist — refine the search to see them",
44
+ filterNoValues: "No values available",
45
+ filterValue(n) {
46
+ return n == null ? this.filterNone : n === "" ? this.filterEmpty : n === !0 ? this.filterTrue : n === !1 ? this.filterFalse : n instanceof Date ? n.toLocaleDateString() : String(n);
47
+ },
48
+ filterNone: "(none)",
49
+ filterEmpty: "(empty)",
50
+ filterTrue: "Yes",
51
+ filterFalse: "No",
52
+ announceFilter: (n, e) => e === 0 ? `Filter cleared on ${n}` : e === 1 ? `1 value selected in ${n}` : `${e} values selected in ${n}`,
53
+ filterOperator: "Comparison",
54
+ filterOperand: "Value to compare with",
55
+ filterOperatorLabel: (n) => A[n],
56
+ announceComparisonFilter: (n, e, t) => t === "" ? `Filter cleared on ${n}` : `${n} ${e} ${t}`,
57
+ announceSorted: (n, e) => e === "none" ? `Sorting removed from ${n}` : `Sorted by ${n}, ${e}`,
58
+ announcePage: (n, e) => `Page ${n} of ${e}`,
59
+ announceSelection: (n) => n === 1 ? "1 row selected" : `${n} rows selected`,
60
+ announceLoaded: (n) => n === 1 ? "Loaded 1 row" : `Loaded ${n} rows`
61
+ }, D = F(`@charset "UTF-8";
62
+ mp-datatable {
63
+ display: block;
64
+ width: 100%;
65
+ position: relative;
66
+ --mp-datatable-border-color: var(--bs-border-color, rgba(0, 0, 0, 0.125));
67
+ --mp-datatable-row-hover-bg: var(--bs-table-hover-bg, rgba(0, 0, 0, 0.04));
68
+ --mp-datatable-row-selected-bg: var(--bs-list-group-active-bg, var(--bs-primary, #0d6efd));
69
+ --mp-datatable-row-selected-color: var(--bs-list-group-active-color, #fff);
70
+ --mp-datatable-cut-opacity: 0.55;
71
+ --mp-datatable-resize-handle-color: var(--bs-primary, #0d6efd);
72
+ }
73
+
74
+ [data-mps=datatable] {
75
+ box-sizing: border-box;
76
+ }
77
+
78
+ .datatable-shell[data-mps=datatable] {
79
+ display: flex;
80
+ flex-direction: column;
81
+ width: 100%;
82
+ height: 100%;
83
+ }
84
+
85
+ .datatable-scroll[data-mps=datatable] {
86
+ overflow: auto;
87
+ flex: 1 1 auto;
88
+ }
89
+
90
+ .datatable-scroll.datatable-virtual[data-mps=datatable] {
91
+ max-height: var(--mp-datatable-virtual-max-height, 480px);
92
+ }
93
+ .datatable-scroll.datatable-virtual[data-mps=datatable] thead[data-mps=datatable] th[data-mps=datatable] {
94
+ position: sticky;
95
+ top: 0;
96
+ z-index: 1;
97
+ background-color: var(--bs-body-bg, #fff);
98
+ }
99
+ .datatable-scroll.datatable-virtual[data-mps=datatable] thead[data-mps=datatable] th[data-sortable=true]:hover[data-mps=datatable] {
100
+ background-color: var(--bs-body-bg, #fff);
101
+ background-image: linear-gradient(var(--mp-datatable-row-hover-bg), var(--mp-datatable-row-hover-bg));
102
+ }
103
+ .datatable-scroll.datatable-virtual[data-mps=datatable] thead[data-mps=datatable] tr.filter-row[data-mps=datatable] th[data-mps=datatable] {
104
+ position: sticky;
105
+ top: var(--mp-datatable-header-height, 0px);
106
+ z-index: 1;
107
+ background-color: var(--bs-body-bg, #fff);
108
+ }
109
+
110
+ tr.virtual-spacer[data-mps=datatable] {
111
+ pointer-events: none;
112
+ }
113
+ tr.virtual-spacer[data-mps=datatable] > td {
114
+ border-bottom: 0;
115
+ }
116
+
117
+ table[data-mps=datatable] {
118
+ width: 100%;
119
+ border-collapse: collapse;
120
+ margin: 0;
121
+ table-layout: auto;
122
+ }
123
+
124
+ table.measured[data-mps=datatable] {
125
+ table-layout: fixed;
126
+ }
127
+ tbody[data-mps=datatable] > tr[data-mps=datatable] > td {
128
+ white-space: nowrap;
129
+ overflow: hidden;
130
+ text-overflow: ellipsis;
131
+ }
132
+
133
+ thead[data-mps=datatable] th[data-mps=datatable] {
134
+ background-color: var(--bs-table-bg, transparent);
135
+ border-bottom: 1px solid var(--mp-datatable-border-color);
136
+ text-align: left;
137
+ font-weight: 600;
138
+ padding: 0.5rem 0.75rem;
139
+ white-space: nowrap;
140
+ position: relative;
141
+ user-select: none;
142
+ }
143
+
144
+ thead[data-mps=datatable] th[data-sortable=true][data-mps=datatable] {
145
+ cursor: pointer;
146
+ padding: 0;
147
+ }
148
+ thead[data-mps=datatable] th[data-sortable=true][data-mps=datatable]::before, thead[data-mps=datatable] th[data-sortable=true][data-mps=datatable]::after {
149
+ position: absolute;
150
+ display: block;
151
+ opacity: 0.3;
152
+ bottom: 0.5em;
153
+ }
154
+ thead[data-mps=datatable] th[data-sortable=true][data-mps=datatable]::before {
155
+ content: "↑";
156
+ right: 1em;
157
+ }
158
+ thead[data-mps=datatable] th[data-sortable=true][data-mps=datatable]::after {
159
+ content: "↓";
160
+ right: 0.5em;
161
+ }
162
+ thead[data-mps=datatable] th[data-sortable=true][aria-sort=ascending][data-mps=datatable]::after {
163
+ opacity: 1;
164
+ }
165
+ thead[data-mps=datatable] th[data-sortable=true][aria-sort=descending][data-mps=datatable]::before {
166
+ opacity: 1;
167
+ }
168
+
169
+ thead[data-mps=datatable] th[data-sortable=true]:hover[data-mps=datatable] {
170
+ background-color: var(--mp-datatable-row-hover-bg);
171
+ }
172
+
173
+ .header-cell[data-mps=datatable] {
174
+ display: inline-flex;
175
+ align-items: center;
176
+ gap: 0.4rem;
177
+ }
178
+
179
+ button.header-sort[data-mps=datatable] {
180
+ border: 0;
181
+ margin: 0;
182
+ background: none;
183
+ font: inherit;
184
+ color: inherit;
185
+ text-align: inherit;
186
+ cursor: pointer;
187
+ display: flex;
188
+ width: 100%;
189
+ box-sizing: border-box;
190
+ padding: 0.5rem 2rem 0.5rem 0.75rem;
191
+ }
192
+
193
+ .resize-handle:focus-visible[data-mps=datatable],
194
+ button.header-sort:focus-visible[data-mps=datatable] {
195
+ outline: 2px solid var(--mp-datatable-resize-handle-color);
196
+ outline-offset: 1px;
197
+ }
198
+
199
+ tbody[data-mps=datatable] tr:focus-visible[data-mps=datatable] {
200
+ outline: 2px solid var(--mp-datatable-resize-handle-color);
201
+ outline-offset: -2px;
202
+ }
203
+
204
+ .sort-index[data-mps=datatable] {
205
+ position: absolute;
206
+ right: 0.1em;
207
+ bottom: 0.3em;
208
+ font-size: 0.65em;
209
+ font-weight: bold;
210
+ opacity: 0.7;
211
+ }
212
+
213
+ .resize-handle[data-mps=datatable] {
214
+ position: absolute;
215
+ right: 0;
216
+ top: 0;
217
+ width: 6px;
218
+ height: 100%;
219
+ cursor: col-resize;
220
+ user-select: none;
221
+ z-index: 2;
222
+ }
223
+
224
+ .resize-handle:hover[data-mps=datatable],
225
+ .resize-handle.active[data-mps=datatable] {
226
+ background-color: var(--mp-datatable-resize-handle-color);
227
+ }
228
+ tbody[data-mps=datatable] > tr[data-mps=datatable] > td {
229
+ padding: 0.5rem 0.75rem;
230
+ border-bottom: 1px solid var(--mp-datatable-border-color);
231
+ vertical-align: middle;
232
+ }
233
+ tbody[data-mps=datatable] > tr[data-mps=datatable] > td svg,
234
+ tbody[data-mps=datatable] > tr[data-mps=datatable] > td img {
235
+ max-width: var(--mp-datatable-cell-media-max-width, none);
236
+ height: auto;
237
+ vertical-align: middle;
238
+ }
239
+
240
+ tbody[data-mps=datatable] tr[data-mps=datatable] {
241
+ cursor: default;
242
+ }
243
+
244
+ tbody[data-mps=datatable] tr[data-clickable=true][data-mps=datatable] {
245
+ cursor: pointer;
246
+ }
247
+
248
+ tbody[data-mps=datatable] tr:hover[data-mps=datatable] {
249
+ background-color: var(--mp-datatable-row-hover-bg);
250
+ }
251
+
252
+ tbody[data-mps=datatable] tr[data-selected=true][data-mps=datatable] {
253
+ background-color: var(--mp-datatable-row-selected-bg);
254
+ color: var(--mp-datatable-row-selected-color);
255
+ }
256
+
257
+ tbody[data-mps=datatable] tr[data-cut=true][data-mps=datatable] {
258
+ opacity: var(--mp-datatable-cut-opacity);
259
+ }
260
+
261
+ tbody[data-mps=datatable] tr[data-focused=true][data-mps=datatable] {
262
+ outline: 2px solid var(--bs-primary, #0d6efd);
263
+ outline-offset: -2px;
264
+ }
265
+ tr[data-mps=datatable] > .checkbox-cell[data-mps=datatable] {
266
+ width: 2.5rem;
267
+ padding-inline: 0.5rem;
268
+ text-align: center;
269
+ text-overflow: clip;
270
+ }
271
+
272
+ .tree-chevron-cell[data-mps=datatable] {
273
+ width: 2rem;
274
+ padding-right: 0;
275
+ white-space: nowrap;
276
+ user-select: none;
277
+ }
278
+
279
+ .tree-chevron[data-mps=datatable] {
280
+ appearance: none;
281
+ background: transparent;
282
+ border: 0;
283
+ padding: 0;
284
+ width: 1.5rem;
285
+ height: 1.5rem;
286
+ line-height: 1;
287
+ cursor: pointer;
288
+ color: var(--bs-body-color, inherit);
289
+ font-size: 0.85em;
290
+ border-radius: 0.25rem;
291
+ display: inline-flex;
292
+ align-items: center;
293
+ justify-content: center;
294
+ }
295
+ .tree-chevron:hover[data-mps=datatable] {
296
+ background-color: var(--mp-datatable-row-hover-bg);
297
+ }
298
+ .tree-chevron:focus-visible[data-mps=datatable] {
299
+ outline: 2px solid var(--bs-primary, #0d6efd);
300
+ outline-offset: 1px;
301
+ }
302
+
303
+ tbody[data-mps=datatable] tr[data-placeholder=true][data-mps=datatable] {
304
+ cursor: default;
305
+ opacity: 0.6;
306
+ pointer-events: none;
307
+ }
308
+
309
+ .tree-placeholder-cell[data-mps=datatable] {
310
+ color: var(--bs-secondary-color, #6c757d);
311
+ font-style: italic;
312
+ padding-left: 1.25rem;
313
+ }
314
+
315
+ .empty-state[data-mps=datatable],
316
+ .loading-state[data-mps=datatable] {
317
+ padding: 2rem 1rem;
318
+ text-align: center;
319
+ color: var(--bs-secondary-color, #6c757d);
320
+ }
321
+
322
+ .datatable-footer[data-mps=datatable] {
323
+ display: flex;
324
+ align-items: center;
325
+ justify-content: space-between;
326
+ padding: 0.5rem 0;
327
+ gap: 1rem;
328
+ flex-wrap: wrap;
329
+ flex: 0 0 auto;
330
+ }
331
+
332
+ .datatable-per-page[data-mps=datatable],
333
+ .datatable-pagination[data-mps=datatable] {
334
+ flex: 0 1 auto;
335
+ }
336
+
337
+ tr.filter-row[data-mps=datatable] th[data-mps=datatable] {
338
+ padding: 0;
339
+ border-bottom: 1px solid var(--mp-datatable-border-color);
340
+ font-weight: 400;
341
+ user-select: none;
342
+ }
343
+
344
+ .filter-trigger[data-mps=datatable] {
345
+ display: flex;
346
+ align-items: center;
347
+ justify-content: center;
348
+ width: 100%;
349
+ min-width: 0;
350
+ box-sizing: border-box;
351
+ padding: 0.5rem;
352
+ border-radius: 0;
353
+ background: transparent;
354
+ border: 1px solid transparent;
355
+ color: inherit;
356
+ cursor: pointer;
357
+ line-height: 1;
358
+ }
359
+
360
+ .filter-trigger:hover[data-mps=datatable] {
361
+ background-color: var(--mp-datatable-row-hover-bg, rgba(0, 0, 0, 0.04));
362
+ }
363
+
364
+ .filter-trigger:focus-visible[data-mps=datatable] {
365
+ outline: 2px solid var(--bs-focus-ring-color, #0d6efd);
366
+ outline-offset: 1px;
367
+ }
368
+
369
+ .filter-trigger[aria-expanded=true][data-mps=datatable] {
370
+ background-color: var(--mp-datatable-row-hover-bg, rgba(0, 0, 0, 0.04));
371
+ border-color: var(--mp-datatable-border-color);
372
+ }
373
+
374
+ .filter-icon[data-mps=datatable] {
375
+ width: 0.875rem;
376
+ height: 0.875rem;
377
+ fill: currentColor;
378
+ flex: 0 0 auto;
379
+ }
380
+
381
+ .filter-trigger.active[data-mps=datatable] .filter-icon[data-mps=datatable] {
382
+ fill: var(--bs-primary, #0d6efd);
383
+ }
384
+
385
+ .filter-trigger.active[data-mps=datatable]::after {
386
+ content: "";
387
+ width: 0.375rem;
388
+ height: 0.375rem;
389
+ margin-inline-start: 0.25rem;
390
+ border-radius: 50%;
391
+ background-color: var(--bs-primary, #0d6efd);
392
+ flex: 0 0 auto;
393
+ }
394
+
395
+ .filter-panel[data-mps=datatable] {
396
+ position: fixed;
397
+ min-width: 12rem;
398
+ max-width: min(22rem, 100vw - 2rem);
399
+ padding: 0.5rem;
400
+ background-color: var(--bs-body-bg, #fff);
401
+ color: var(--bs-body-color, inherit);
402
+ border: 1px solid var(--mp-datatable-border-color, var(--bs-border-color, rgba(0, 0, 0, 0.125)));
403
+ border-radius: 0.375rem;
404
+ box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
405
+ }
406
+
407
+ .filter-panel-body[data-mps=datatable] {
408
+ display: block;
409
+ max-height: min(20rem, 60vh);
410
+ overflow: auto;
411
+ }
412
+
413
+ .filter-clear[data-mps=datatable],
414
+ .filter-invert[data-mps=datatable] {
415
+ display: block;
416
+ width: 100%;
417
+ box-sizing: border-box;
418
+ padding: 0.25rem 0.5rem;
419
+ margin-bottom: 0.375rem;
420
+ background: transparent;
421
+ border: 1px solid var(--mp-datatable-border-color, var(--bs-border-color, rgba(0, 0, 0, 0.125)));
422
+ border-radius: 0.25rem;
423
+ color: inherit;
424
+ cursor: pointer;
425
+ text-align: start;
426
+ line-height: 1.4;
427
+ }
428
+
429
+ .filter-clear:disabled[data-mps=datatable] {
430
+ opacity: 0.5;
431
+ cursor: default;
432
+ }
433
+
434
+ .filter-invert[aria-pressed=true][data-mps=datatable] {
435
+ background-color: var(--bs-primary, #0d6efd);
436
+ border-color: var(--bs-primary, #0d6efd);
437
+ color: var(--bs-primary-bg-subtle, #fff);
438
+ }
439
+
440
+ .filter-search[data-mps=datatable],
441
+ .filter-operand[data-mps=datatable],
442
+ .filter-operator[data-mps=datatable] {
443
+ box-sizing: border-box;
444
+ padding: 0.25rem 0.5rem;
445
+ background-color: var(--bs-body-bg, #fff);
446
+ color: inherit;
447
+ border: 1px solid var(--mp-datatable-border-color, var(--bs-border-color, rgba(0, 0, 0, 0.125)));
448
+ border-radius: 0.25rem;
449
+ font: inherit;
450
+ line-height: 1.5;
451
+ }
452
+
453
+ .filter-operand[type=number][data-mps=datatable] {
454
+ appearance: textfield;
455
+ }
456
+
457
+ .filter-operand[data-mps=datatable]::-webkit-outer-spin-button,
458
+ .filter-operand[data-mps=datatable]::-webkit-inner-spin-button {
459
+ appearance: none;
460
+ margin: 0;
461
+ }
462
+
463
+ .filter-search[data-mps=datatable] {
464
+ display: block;
465
+ width: 100%;
466
+ margin-bottom: 0.375rem;
467
+ }
468
+
469
+ .filter-clear:focus-visible[data-mps=datatable],
470
+ .filter-invert:focus-visible[data-mps=datatable],
471
+ .filter-search:focus-visible[data-mps=datatable],
472
+ .filter-option[data-mps=datatable] input:focus-visible[data-mps=datatable] {
473
+ outline: 2px solid var(--bs-focus-ring-color, #0d6efd);
474
+ outline-offset: 1px;
475
+ }
476
+
477
+ .filter-comparison[data-mps=datatable] {
478
+ display: flex;
479
+ gap: 0.375rem;
480
+ align-items: stretch;
481
+ }
482
+
483
+ .filter-operator[data-mps=datatable] {
484
+ flex: 0 0 auto;
485
+ max-width: 9rem;
486
+ padding-inline: 0.375rem;
487
+ }
488
+
489
+ .filter-operand[data-mps=datatable] {
490
+ flex: 1 1 auto;
491
+ min-width: 0;
492
+ }
493
+
494
+ .filter-operator:focus-visible[data-mps=datatable],
495
+ .filter-operand:focus-visible[data-mps=datatable] {
496
+ outline: 2px solid var(--bs-focus-ring-color, #0d6efd);
497
+ outline-offset: 1px;
498
+ }
499
+
500
+ .filter-options[data-mps=datatable] {
501
+ display: flex;
502
+ flex-direction: column;
503
+ gap: 0.125rem;
504
+ }
505
+
506
+ .filter-option[data-mps=datatable] {
507
+ display: flex;
508
+ align-items: center;
509
+ gap: 0.375rem;
510
+ padding: 0.125rem 0.25rem;
511
+ border-radius: 0.25rem;
512
+ cursor: pointer;
513
+ overflow-wrap: anywhere;
514
+ }
515
+
516
+ .filter-option:hover[data-mps=datatable] {
517
+ background-color: var(--mp-datatable-row-hover-bg, rgba(0, 0, 0, 0.04));
518
+ }
519
+
520
+ .filter-remaining[data-mps=datatable] {
521
+ color: var(--bs-secondary-color, #6c757d);
522
+ }
523
+
524
+ .filter-loading[data-mps=datatable],
525
+ .filter-no-values[data-mps=datatable],
526
+ .filter-has-more[data-mps=datatable] {
527
+ display: block;
528
+ padding: 0.25rem;
529
+ color: var(--bs-secondary-color, #6c757d);
530
+ font-size: 0.875em;
531
+ }
532
+
533
+ .filter-summary[data-mps=datatable] {
534
+ margin-inline-start: 0.25rem;
535
+ min-width: 0;
536
+ overflow: hidden;
537
+ text-overflow: ellipsis;
538
+ white-space: nowrap;
539
+ font-size: 0.875em;
540
+ }
541
+
542
+ @media (prefers-reduced-motion: reduce) {
543
+ .resize-handle[data-mps=datatable] {
544
+ transition: none !important;
545
+ }
546
+ }`);
547
+ function N(n, e, t) {
548
+ if (t) {
549
+ const i = n.findIndex((s) => s.property === e);
550
+ return i === -1 ? [...n, { property: e, direction: "ascending" }] : n[i].direction === "ascending" ? n.map(
551
+ (s, r) => r === i ? { ...s, direction: "descending" } : s
552
+ ) : n.filter((s, r) => r !== i);
553
+ }
554
+ const a = n.length === 1 && n[0].property === e;
555
+ return [
556
+ {
557
+ property: e,
558
+ direction: a && n[0].direction === "ascending" ? "descending" : "ascending"
559
+ }
560
+ ];
561
+ }
562
+ function y(n, e) {
563
+ return e.length === 0 ? n.slice() : n.map((t, a) => ({ row: t, index: a })).sort((t, a) => {
564
+ for (const i of e) {
565
+ const s = S(t.row, i.property), r = S(a.row, i.property), o = W(s, r);
566
+ if (o !== 0)
567
+ return i.direction === "ascending" ? o : -o;
568
+ }
569
+ return t.index - a.index;
570
+ }).map(({ row: t }) => t);
571
+ }
572
+ function S(n, e) {
573
+ if (!(n == null || typeof n != "object"))
574
+ return n[e];
575
+ }
576
+ function W(n, e) {
577
+ return n === e ? 0 : n == null ? 1 : e == null ? -1 : typeof n == "number" && typeof e == "number" ? n - e : n instanceof Date && e instanceof Date ? n.getTime() - e.getTime() : String(n).localeCompare(String(e));
578
+ }
579
+ const h = L("datatable");
580
+ function $(n, e) {
581
+ return n === e || n !== n && e !== e;
582
+ }
583
+ function g(n, e) {
584
+ return n.some((t) => $(t.value, e));
585
+ }
586
+ const H = 250;
587
+ let B = 0;
588
+ class V extends E {
589
+ constructor() {
590
+ super(...arguments), this.instanceId = `mp-datatable-${++B}`, this._caption = null, this._inputLabel = null, this.hostAria = new q(this, {
591
+ referenceTarget: () => this.renderRoot?.querySelector("table") ?? null
592
+ }), this.labels = void 0, this._columns = [], this._data = [], this._sortColumns = [], this._selectionMode = "none", this._selectedIds = /* @__PURE__ */ new Set(), this._cutIds = /* @__PURE__ */ new Set(), this._focusedRowKey = null, this.liveAnnouncer = new P(this), this.rowFocusRestore = new k(this, new z(
593
+ () => this.renderRoot ?? null,
594
+ {
595
+ selector: 'tbody tr[data-row-key]:not([data-placeholder="true"])',
596
+ keyOf: (e) => e.dataset.rowKey ?? null,
597
+ container: () => this.renderRoot?.querySelector("table") ?? null
598
+ }
599
+ )), this._rowKey = (e, t) => {
600
+ const a = e;
601
+ return a && a.id != null ? String(a.id) : `row-${t}`;
602
+ }, this._columnWidths = /* @__PURE__ */ new Map(), this._hasMeasuredInitial = !1, this._loading = !1, this._emptyMessage = "No data", this._pagination = !1, this._page = 1, this._perPage = 20, this._perPageOptions = [10, 20, 50], this._autoSort = !0, this._totalRecords = null, this._virtualScroll = !1, this._itemSize = 40, this._virtualBuffer = 10, this._virtualRange = { startIndex: 0, endIndex: 0 }, this._scrollElement = null, this._resizeObserver = null, this._scrollListener = null, this._viewportHeight = 0, this._openFilterColumn = null, this._mountedFilterColumn = null, this._consumerMountedFilter = !1, this._filterUid = `mp-dt-${Math.random().toString(36).slice(2, 9)}`, this._distincts = null, this._filterStates = /* @__PURE__ */ new Map(), this._tree = !1, this._idKey = null, this._childCountKey = null, this._treeIndent = 1.25, this._expandedIds = /* @__PURE__ */ new Set(), this._selectionStrategy = "flat", this._childCache = /* @__PURE__ */ new Map(), this._childTotals = /* @__PURE__ */ new Map(), this._pendingFetches = /* @__PURE__ */ new Set(), this._pageCache = /* @__PURE__ */ new Map(), this._pendingPageFetches = /* @__PURE__ */ new Set(), this._fetch = null, this._fetchGeneration = 0, this._initialFetchDone = !1, this._reloadScheduled = !1, this._lastReloadKey = null, this._cachedFlatList = null, this._cachedIndeterminateKeys = null, this._resizableColumns = !0, this.filterOverlay = new I(this, {
603
+ portal: !0,
604
+ modal: !0,
605
+ scrollStrategy: "reposition",
606
+ // Resolved lazily by column name on every call: each render rebuilds the
607
+ // header, so a captured element would detach under the open panel. The
608
+ // trigger IS the anchor, so both read the same element — resolving the
609
+ // trigger by id instead would buy nothing and cost a CSS.escape call, which
610
+ // is not universally available and threw out of close() before it could
611
+ // fire onClose.
612
+ anchor: () => this.openFilterTrigger(),
613
+ trigger: () => this.openFilterTrigger(),
614
+ panel: () => this.filterOverlay.portalContainer?.querySelector(".filter-panel") ?? null,
615
+ // The search box, not merely the first tabbable: Clear precedes it in the
616
+ // DOM because it belongs at the top of the panel visually, and opening onto
617
+ // a disabled-or-destructive button is the wrong place to land.
618
+ // Returning null falls back to 'first', which is what a consumer's own
619
+ // panel gets — it has no `.filter-search` to aim at.
620
+ initialFocus: () => this.filterOverlay.portalContainer?.querySelector(".filter-search, .filter-operand") ?? null,
621
+ onClose: () => {
622
+ const e = this._openFilterColumn;
623
+ if (e == null) return;
624
+ const t = this._filterStates.get(e);
625
+ t && (this.abortFilterRequest(t), t.term = "", this.rebucket(t)), this._openFilterColumn = null, this._mountedFilterColumn = null, this.requestUpdate(), this.dispatchEvent(
626
+ new CustomEvent("mp-datatable-filter-close", {
627
+ detail: { column: e },
628
+ bubbles: !0,
629
+ composed: !0
630
+ })
631
+ );
632
+ }
633
+ }), this._selectionAnchorKey = null, this.resizeState = null, this.onColumnResizeMove = (e) => {
634
+ if (!this.resizeState) return;
635
+ const t = e.clientX - this.resizeState.startX, a = Math.max(40, this.resizeState.startWidth + t);
636
+ this._columnWidths = new Map(this._columnWidths), this._columnWidths.set(this.resizeState.columnName, a), this.requestUpdate();
637
+ }, this.onColumnResizeEnd = (e) => {
638
+ if (this.resizeState) {
639
+ this.resizeState.handle.classList.remove("active"), this.resizeState.handle.removeEventListener("pointermove", this.onColumnResizeMove), this.resizeState.handle.removeEventListener("pointerup", this.onColumnResizeEnd), this.resizeState.handle.removeEventListener("pointercancel", this.onColumnResizeEnd);
640
+ try {
641
+ this.resizeState.handle.releasePointerCapture(e.pointerId);
642
+ } catch {
643
+ }
644
+ this.resizeState = null;
645
+ }
646
+ };
647
+ }
648
+ /**
649
+ * Light DOM. Consumer-authored row/cell/header content is mounted here by the
650
+ * render callbacks, and inside a shadow root the page's stylesheets — the
651
+ * consumer's own component CSS and Bootstrap's utilities alike — cannot reach
652
+ * it (issue #408). Rendering in the document tree is what makes that content
653
+ * style correctly; encapsulation is preserved by the build-time rescoping
654
+ * instead of by the boundary.
655
+ */
656
+ createRenderRoot() {
657
+ return this;
658
+ }
659
+ static get observedAttributes() {
660
+ return [
661
+ ...super.observedAttributes ?? [],
662
+ "selection-mode",
663
+ "pagination",
664
+ "resizable-columns",
665
+ "auto-sort",
666
+ "empty-message",
667
+ "virtual-scroll",
668
+ "item-size",
669
+ "tree",
670
+ "tree-indent",
671
+ "selection-strategy",
672
+ // Naming for the inner <table> (the role-bearing node): caption renders a
673
+ // real <caption>, the native, visible table name; aria-label / input-label
674
+ // are the invisible alternative and win in the accessible-name computation
675
+ // when both are present.
676
+ "caption",
677
+ "aria-label",
678
+ "input-label",
679
+ "aria-labelledby",
680
+ "aria-describedby"
681
+ ];
682
+ }
683
+ /**
684
+ * Visible table caption, rendered as a real <caption> — the native way to name
685
+ * a table, and the only one sighted users benefit from too. For an invisible
686
+ * name use aria-label / input-label instead (they win over the caption in the
687
+ * accessible-name computation when both are set).
688
+ */
689
+ get caption() {
690
+ return this._caption;
691
+ }
692
+ set caption(e) {
693
+ const t = e ?? null;
694
+ this._caption !== t && (this._caption = t, this.requestUpdate());
695
+ }
696
+ /** Merged view of labels — consumer keys over the English defaults. */
697
+ get mergedLabels() {
698
+ return { ...O, ...this.labels ?? {} };
699
+ }
700
+ /** Optional invisible accessible name for the <table>. Host aria-label wins. */
701
+ get inputLabel() {
702
+ return this._inputLabel;
703
+ }
704
+ set inputLabel(e) {
705
+ const t = e ?? null;
706
+ this._inputLabel !== t && (this._inputLabel = t, this.requestUpdate());
707
+ }
708
+ /** When true, the WC sorts `data` itself using `sortRows`. Set `false` if the consumer sorts externally. */
709
+ get autoSort() {
710
+ return this._autoSort;
711
+ }
712
+ set autoSort(e) {
713
+ this._autoSort = !!e, this.requestUpdate();
714
+ }
715
+ /**
716
+ * Per-row renderer. When set, the WC delegates row content production to
717
+ * this callback (used by the Angular wrapper to host `*bsRowTemplate`
718
+ * templates). Returning `undefined` falls back to per-column `cellRenderer`s.
719
+ */
720
+ get rowRenderer() {
721
+ return this._rowRenderer;
722
+ }
723
+ set rowRenderer(e) {
724
+ this._rowRenderer = e, this.requestUpdate();
725
+ }
726
+ /** Enable scroll-position-driven virtualization. Rows outside the viewport are not rendered. */
727
+ get virtualScroll() {
728
+ return this._virtualScroll;
729
+ }
730
+ set virtualScroll(e) {
731
+ const t = !!e;
732
+ this._virtualScroll !== t && (this._virtualScroll = t, this.requestUpdate());
733
+ }
734
+ /** Approximate row height in px (used by virtual scroll). Default `40`. */
735
+ get itemSize() {
736
+ return this._itemSize;
737
+ }
738
+ set itemSize(e) {
739
+ const t = Math.max(1, Math.floor(e || 0)) || 40;
740
+ this._itemSize !== t && (this._itemSize = t, this.requestUpdate());
741
+ }
742
+ /** Off-screen row buffer (each side) for virtual scrolling. */
743
+ get virtualBuffer() {
744
+ return this._virtualBuffer;
745
+ }
746
+ set virtualBuffer(e) {
747
+ const t = Math.max(0, Math.floor(e || 0));
748
+ this._virtualBuffer !== t && (this._virtualBuffer = t, this.requestUpdate());
749
+ }
750
+ get columns() {
751
+ return this._columns;
752
+ }
753
+ set columns(e) {
754
+ this._columns = Array.isArray(e) ? e : [], this.syncFilterStates(), this.requestUpdate();
755
+ }
756
+ /**
757
+ * Drops state for columns that are gone and seeds state for new ones from
758
+ * `filterSelection`.
759
+ *
760
+ * An existing column keeps its state: the Angular wrapper rebuilds the whole
761
+ * column array on every change detection, so treating a re-assignment as
762
+ * "new columns" would wipe the user's selection on any unrelated input change.
763
+ * A column whose `filterSelection` reference actually changed is re-seeded —
764
+ * that is the consumer restoring a filter, and it is why the input is a
765
+ * reference and not a value.
766
+ */
767
+ syncFilterStates() {
768
+ const e = new Set(this._columns.map((t) => t.name));
769
+ this._filterStates.forEach((t, a) => {
770
+ e.has(a) || (this.abortFilterRequest(t), this._filterStates.delete(a));
771
+ }), this._columns.forEach((t) => {
772
+ const a = this._filterStates.get(t.name);
773
+ if (!a) {
774
+ t.filterable && this._filterStates.set(t.name, this.createFilterState(t));
775
+ return;
776
+ }
777
+ t.filterSelection && t.filterSelection !== a.seededFrom && (a.seededFrom = t.filterSelection, a.selection = {
778
+ values: [...t.filterSelection.values],
779
+ inverse: !!t.filterSelection.inverse,
780
+ operator: t.filterSelection.operator,
781
+ operand: t.filterSelection.operand ?? null
782
+ }, a.operandText = t.filterSelection.operand == null ? "" : String(t.filterSelection.operand), a.snapshot = null);
783
+ });
784
+ }
785
+ get data() {
786
+ return this._data;
787
+ }
788
+ set data(e) {
789
+ this._data = Array.isArray(e) ? e : [], this.refreshLocalDistincts(), this.requestUpdate();
790
+ }
791
+ /**
792
+ * High-level fetch callback. When set, the WC owns the entire server-paged
793
+ * loop and the consumer provides nothing else — no page-1 seeding via `data`,
794
+ * no separate `totalRecords`, no event bridge. Works with any framework or
795
+ * none (`el.fetch = fn`). Setting it kicks off the initial page-1 load.
796
+ */
797
+ get fetch() {
798
+ return this._fetch;
799
+ }
800
+ set fetch(e) {
801
+ if (this._fetch = typeof e == "function" ? e : null, this._fetch) {
802
+ this._autoSort = !1, this._initialFetchDone = !1, this._lastReloadKey = null, this.scheduleFetchReload();
803
+ return;
804
+ }
805
+ this._totalRecords = null, this._pageCache.clear(), this._pendingPageFetches.clear(), this._childCache.clear(), this._childTotals.clear(), this._pendingFetches.clear(), this._fetchGeneration++, this._initialFetchDone = !1, this._lastReloadKey = null, this.requestUpdate();
806
+ }
807
+ /**
808
+ * Consumer-supplied source of distinct values for the filter panels.
809
+ * Property-only (it holds a function), mirroring `fetch` and `labels`.
810
+ *
811
+ * A source that resolves `null` for a column means "compute that column
812
+ * locally", so one table can mix server-backed and local filter columns.
813
+ */
814
+ get distincts() {
815
+ return this._distincts;
816
+ }
817
+ set distincts(e) {
818
+ this._distincts = typeof e == "function" ? e : null, this._filterStates.forEach((t) => {
819
+ t.loaded = null, t.view = null, t.loadedTerm = null;
820
+ }), this._openFilterColumn && this.requestUpdate();
821
+ }
822
+ get sortColumns() {
823
+ return [...this._sortColumns];
824
+ }
825
+ set sortColumns(e) {
826
+ this._sortColumns = Array.isArray(e) ? [...e] : [], this.requestUpdate(), this.scheduleFetchReload();
827
+ }
828
+ get selectionMode() {
829
+ return this._selectionMode;
830
+ }
831
+ set selectionMode(e) {
832
+ this._selectionMode = e, e === "none" && this._selectedIds.clear(), this.requestUpdate();
833
+ }
834
+ get selectedIds() {
835
+ return [...this._selectedIds];
836
+ }
837
+ set selectedIds(e) {
838
+ this._selectedIds = new Set(e ?? []), this.requestUpdate();
839
+ }
840
+ get cutIds() {
841
+ return [...this._cutIds];
842
+ }
843
+ set cutIds(e) {
844
+ this._cutIds = new Set(e ?? []), this.requestUpdate();
845
+ }
846
+ get focusedRowKey() {
847
+ return this._focusedRowKey;
848
+ }
849
+ set focusedRowKey(e) {
850
+ this._focusedRowKey = e, this.requestUpdate();
851
+ }
852
+ get rowKey() {
853
+ return this._rowKey;
854
+ }
855
+ set rowKey(e) {
856
+ this._rowKey = typeof e == "function" ? e : this._rowKey, this.requestUpdate();
857
+ }
858
+ // ─── Tree-mode public API ────────────────────────────────────────────────
859
+ /** Enable tree mode (chevron column, nested expansion, lazy children). */
860
+ get tree() {
861
+ return this._tree;
862
+ }
863
+ set tree(e) {
864
+ const t = !!e;
865
+ this._tree !== t && (this._tree = t, this.requestUpdate());
866
+ }
867
+ /**
868
+ * Property name or function that extracts the stable row identity used as
869
+ * the expansion key and as `parentId` in `mp-datatable-fetch-request`.
870
+ * Required when `tree=true`.
871
+ */
872
+ get idKey() {
873
+ return this._idKey;
874
+ }
875
+ set idKey(e) {
876
+ this._idKey = e, this.requestUpdate();
877
+ }
878
+ /**
879
+ * Property name on the row that holds the direct-child count. Drives both
880
+ * chevron visibility AND placeholder reservation. Required when `tree=true`.
881
+ */
882
+ get childCountKey() {
883
+ return this._childCountKey;
884
+ }
885
+ set childCountKey(e) {
886
+ this._childCountKey = e || null, this.requestUpdate();
887
+ }
888
+ /** Indent in rem per depth level on the chevron cell. Default `1.25`. */
889
+ get treeIndent() {
890
+ return this._treeIndent;
891
+ }
892
+ set treeIndent(e) {
893
+ const t = Number(e);
894
+ this._treeIndent = Number.isFinite(t) && t >= 0 ? t : 1.25, this.requestUpdate();
895
+ }
896
+ /** Two-way binding target: set of expanded-row id values (per `idKey`). */
897
+ get expandedIds() {
898
+ return new Set(this._expandedIds);
899
+ }
900
+ set expandedIds(e) {
901
+ e ? e instanceof Set ? this._expandedIds = new Set(e) : this._expandedIds = new Set(e) : this._expandedIds = /* @__PURE__ */ new Set(), this.requestUpdate();
902
+ }
903
+ /** `'flat'` (default) or `'cascading'`. When `tree=true`, cascading is recommended. */
904
+ get selectionStrategy() {
905
+ return this._selectionStrategy;
906
+ }
907
+ set selectionStrategy(e) {
908
+ this._selectionStrategy = e === "cascading" ? "cascading" : "flat", this.requestUpdate();
909
+ }
910
+ get loading() {
911
+ return this._loading;
912
+ }
913
+ set loading(e) {
914
+ const t = this._loading;
915
+ this._loading = !!e, t && !this._loading && this.liveAnnouncer.announce(this.mergedLabels.announceLoaded(this._data.length)), this.requestUpdate();
916
+ }
917
+ get emptyMessage() {
918
+ return this._emptyMessage;
919
+ }
920
+ set emptyMessage(e) {
921
+ this._emptyMessage = e || "No data", this.requestUpdate();
922
+ }
923
+ get pagination() {
924
+ return this._pagination;
925
+ }
926
+ set pagination(e) {
927
+ this._pagination = !!e, this.requestUpdate();
928
+ }
929
+ get page() {
930
+ return this._page;
931
+ }
932
+ set page(e) {
933
+ const t = Math.max(1, Math.floor(e || 1));
934
+ this._page !== t && (this._page = t, this.requestUpdate(), this.scheduleFetchReload());
935
+ }
936
+ get perPage() {
937
+ return this._perPage;
938
+ }
939
+ set perPage(e) {
940
+ const t = Math.max(1, Math.floor(e || 1));
941
+ this._perPage !== t && (this._perPage = t, this._page = 1, this.requestUpdate(), this.scheduleFetchReload());
942
+ }
943
+ get perPageOptions() {
944
+ return [...this._perPageOptions];
945
+ }
946
+ set perPageOptions(e) {
947
+ this._perPageOptions = Array.isArray(e) && e.length > 0 ? [...e] : [10, 20, 50], this.requestUpdate();
948
+ }
949
+ /**
950
+ * Read-only grand total. Derived by the WC from the `fetch` response (server
951
+ * paging) or `_data.length` (static data) — consumers never set it. Exposed
952
+ * so a consumer can render "row X of N" if it wants.
953
+ */
954
+ get totalRecords() {
955
+ return this._totalRecords;
956
+ }
957
+ /** True when the consumer is paging externally (totalRecords exceeds the in-memory rows). */
958
+ isExternallyPaged() {
959
+ return this._totalRecords != null && this._totalRecords > this._data.length;
960
+ }
961
+ /**
962
+ * True when virtual scrolling is driving lazy windowed fetches at the **root**
963
+ * level: the consumer pages externally and the WC pulls root pages ≥ 2 on
964
+ * demand. Applies to BOTH flat mode (the rows are the roots) and tree mode
965
+ * (the top-level rows; their children are windowed separately, keyed by
966
+ * parentId). When false (single page or no virtual scroll) the WC falls back
967
+ * to the trivial mapping of `_data`.
968
+ */
969
+ isRootWindowed() {
970
+ return this._virtualScroll && this.isExternallyPaged();
971
+ }
972
+ attributeChangedCallback(e, t, a) {
973
+ if (super.attributeChangedCallback(e, t, a), e === "caption")
974
+ this._caption = a, this.requestUpdate();
975
+ else if (e === "input-label")
976
+ this._inputLabel = a, this.requestUpdate();
977
+ else if (e === "aria-label")
978
+ this.requestUpdate();
979
+ else if (e === "aria-labelledby" || e === "aria-describedby")
980
+ this.hostAria.syncReferences();
981
+ else if (e === "selection-mode") {
982
+ const i = a;
983
+ (i === "none" || i === "single" || i === "multiple") && (this.selectionMode = i);
984
+ } else if (e === "pagination")
985
+ this.pagination = a !== null;
986
+ else if (e === "resizable-columns")
987
+ this.resizableColumns = a !== null;
988
+ else if (e === "auto-sort")
989
+ this.autoSort = a !== "false";
990
+ else if (e === "empty-message")
991
+ this.emptyMessage = a ?? "No data";
992
+ else if (e === "virtual-scroll")
993
+ this.virtualScroll = a !== null;
994
+ else if (e === "item-size") {
995
+ const i = Number(a);
996
+ Number.isFinite(i) && (this.itemSize = i);
997
+ } else if (e === "tree")
998
+ this.tree = a !== null;
999
+ else if (e === "tree-indent") {
1000
+ const i = Number(a);
1001
+ Number.isFinite(i) && (this.treeIndent = i);
1002
+ } else e === "selection-strategy" && (this.selectionStrategy = a === "cascading" ? "cascading" : "flat");
1003
+ }
1004
+ get resizableColumns() {
1005
+ return this._resizableColumns;
1006
+ }
1007
+ set resizableColumns(e) {
1008
+ this._resizableColumns = !!e, this.requestUpdate();
1009
+ }
1010
+ connectedCallback() {
1011
+ super.connectedCallback();
1012
+ }
1013
+ firstUpdated() {
1014
+ this._scrollElement = this.renderRoot?.querySelector(".datatable-scroll"), this._scrollElement && (this._scrollListener = () => this.refreshVirtualRange(), this._scrollElement.addEventListener("scroll", this._scrollListener, { passive: !0 }), typeof ResizeObserver < "u" && (this._resizeObserver = new ResizeObserver(() => this.refreshVirtualRange()), this._resizeObserver.observe(this._scrollElement))), this.refreshVirtualRange(), this.hostAria.syncReferences();
1015
+ }
1016
+ willUpdate(e) {
1017
+ super.willUpdate(e), this._cachedFlatList = null, this._cachedIndeterminateKeys = null;
1018
+ }
1019
+ updated(e) {
1020
+ super.updated(e), this.refreshVirtualRange(), this.maybeMeasureInitialColumnWidths();
1021
+ const t = this.renderRoot?.querySelectorAll(".resize-handle:not([aria-valuenow])") ?? [];
1022
+ for (const a of t) {
1023
+ const i = a.closest("th");
1024
+ i && a.setAttribute("aria-valuenow", String(Math.round(i.getBoundingClientRect().width)));
1025
+ }
1026
+ this._openFilterColumn && this.renderFilterPanel(), this.publishHeaderHeight();
1027
+ }
1028
+ /**
1029
+ * Publish header row 1's height as `--mp-datatable-header-height` for the
1030
+ * filter row's sticky offset. Cheap and idempotent: it writes only on change,
1031
+ * so it cannot feed back into the render loop.
1032
+ */
1033
+ publishHeaderHeight() {
1034
+ if (!this.hasFilterRow) return;
1035
+ const e = this.renderRoot?.querySelector("thead tr:first-child th"), t = this.renderRoot?.querySelector(".datatable-shell");
1036
+ if (!e || !t) return;
1037
+ const a = Math.round(e.getBoundingClientRect().height);
1038
+ a <= 0 || t.style.getPropertyValue("--mp-datatable-header-height") !== `${a}px` && t.style.setProperty("--mp-datatable-header-height", `${a}px`);
1039
+ }
1040
+ /**
1041
+ * Run the auto-size-once pass after the first batch of rows lands in the
1042
+ * DOM. Columns with an explicit `col.width` are pinned to that value
1043
+ * without measurement; the rest are measured from their natural
1044
+ * (`table-layout: auto`) width via `getBoundingClientRect()` on the
1045
+ * `<th>`. Once any column gets a width, `_hasMeasuredInitial` flips and
1046
+ * the table renders with `table-layout: fixed` so the widths are
1047
+ * authoritative and overflowing content clips with ellipsis.
1048
+ */
1049
+ maybeMeasureInitialColumnWidths() {
1050
+ if (this._hasMeasuredInitial || this._columns.length === 0 || this._data.length === 0 || !this.renderRoot || this.renderRoot.querySelectorAll('tbody tr[data-row-key]:not([data-placeholder="true"])').length === 0) return;
1051
+ const t = new Map(this._columnWidths);
1052
+ let a = !1;
1053
+ for (const i of this._columns) {
1054
+ if (t.has(i.name)) continue;
1055
+ if (typeof i.width == "number") {
1056
+ t.set(i.name, i.width), a = !0;
1057
+ continue;
1058
+ }
1059
+ const s = this.measureColumnWidth(i.name);
1060
+ s != null && (t.set(i.name, s), a = !0);
1061
+ }
1062
+ a && (this._columnWidths = t, this._hasMeasuredInitial = !0, this.requestUpdate());
1063
+ }
1064
+ measureColumnWidth(e) {
1065
+ if (!this.renderRoot) return null;
1066
+ const t = this.renderRoot.querySelector(
1067
+ `thead tr:first-child th[data-column="${e}"]`
1068
+ );
1069
+ if (!t) return null;
1070
+ const a = Math.ceil(t.getBoundingClientRect().width);
1071
+ return a > 0 ? a : null;
1072
+ }
1073
+ disconnectedCallback() {
1074
+ super.disconnectedCallback(), this._scrollElement && this._scrollListener && this._scrollElement.removeEventListener("scroll", this._scrollListener), this._scrollListener = null, this._resizeObserver?.disconnect(), this._resizeObserver = null, this._scrollElement = null, this._filterStates.forEach((e) => this.abortFilterRequest(e));
1075
+ }
1076
+ refreshVirtualRange() {
1077
+ if (!this._virtualScroll || !this._scrollElement) return;
1078
+ const e = this._scrollElement.scrollTop, t = this._scrollElement.clientHeight;
1079
+ this._viewportHeight = t;
1080
+ const a = this.getEffectiveData().length, i = this._itemSize, s = Math.max(0, Math.floor(e / i) - this._virtualBuffer), r = Math.ceil(t / i), o = Math.min(a, s + r + this._virtualBuffer * 2);
1081
+ (s !== this._virtualRange.startIndex || o !== this._virtualRange.endIndex) && (this._virtualRange = { startIndex: s, endIndex: o }, this.requestUpdate()), this._tree && this.maybeFetchPlaceholdersInViewport(), this.isRootWindowed() && this.maybeFetchPagesInViewport();
1082
+ }
1083
+ /**
1084
+ * Walk the visible viewport for placeholder rows whose parent isn't cached
1085
+ * and isn't already in-flight. Emit a fetch-request per such parent.
1086
+ */
1087
+ maybeFetchPlaceholdersInViewport() {
1088
+ const e = this.getFlatList(), { startIndex: t, endIndex: a } = this._virtualRange, i = this._virtualScroll ? t : 0, s = this._virtualScroll ? a : e.length, r = /* @__PURE__ */ new Set();
1089
+ for (let o = i; o < s; o++) {
1090
+ const l = e[o];
1091
+ !l.isPlaceholder || l.parentId == null || this._childCache.has(l.parentId) || this._pendingFetches.has(l.parentId) || r.add(l.parentId);
1092
+ }
1093
+ for (const o of r) this.fetchChildren(o);
1094
+ }
1095
+ /**
1096
+ * Flat-window counterpart of `maybeFetchPlaceholdersInViewport`: scan the
1097
+ * visible range for flat placeholder rows, collect the distinct pages they
1098
+ * belong to that aren't cached or already in-flight, and request each once.
1099
+ * Page 1 is never requested here — it lives in `_data` (seeded by the
1100
+ * wrapper's first-page fetch).
1101
+ */
1102
+ maybeFetchPagesInViewport() {
1103
+ const e = this.getFlatList(), { startIndex: t, endIndex: a } = this._virtualRange, i = this._virtualScroll ? t : 0, s = this._virtualScroll ? a : e.length, r = /* @__PURE__ */ new Set();
1104
+ for (let o = i; o < s; o++) {
1105
+ const l = e[o];
1106
+ !l.isPlaceholder || l.page == null || l.page <= 1 || this._pageCache.has(l.page) || this._pendingPageFetches.has(l.page) || r.add(l.page);
1107
+ }
1108
+ for (const o of r) this.fetchWindowPage(o);
1109
+ }
1110
+ render() {
1111
+ const e = this.computeVisibleRows(), t = this._totalRecords ?? this._data.length, a = this.pagination && !this._tree ? Math.max(1, Math.ceil(t / this._perPage)) : 1, i = this._selectionMode === "multiple", s = this._columns.length + (i ? 1 : 0) + (this._tree ? 1 : 0), r = this.getVirtualSpacerHeights(), o = this.hasFilterRow ? 2 : 1, l = (this._tree || this.isRootWindowed() ? this.getFlatList().length : this._data.length) + o;
1112
+ return h`
1113
+ ${this.liveAnnouncer.template()}
1114
+ <div class="datatable-shell">
1115
+ <div class="datatable-scroll ${this._virtualScroll ? "datatable-virtual" : ""}" role="presentation">
1116
+ <table
1117
+ role=${this._tree ? "treegrid" : this._selectionMode !== "none" ? "grid" : u}
1118
+ aria-rowcount=${l}
1119
+ aria-colcount=${s}
1120
+ aria-busy=${this._loading ? "true" : u}
1121
+ aria-label=${this.getAttribute("aria-label") ?? this._inputLabel ?? u}
1122
+ class=${this._hasMeasuredInitial ? "measured" : ""}
1123
+ >
1124
+ ${this._caption ? h`<caption>${this._caption}</caption>` : u}
1125
+ <thead>
1126
+ <tr role="row" aria-rowindex="1">
1127
+ ${this._tree ? h`<th class="tree-chevron-cell" scope="col" aria-label=${this.mergedLabels.treeChevronColumn}></th>` : u}
1128
+ ${i ? h`<th class="checkbox-cell" scope="col">
1129
+ <mp-checkbox
1130
+ aria-label=${this.mergedLabels.deselectAll}
1131
+ aria-hidden=${this._selectedIds.size === 0 ? "true" : u}
1132
+ style=${_({ visibility: this._selectedIds.size > 0 ? "visible" : "hidden" })}
1133
+ .checked=${!1}
1134
+ .indeterminate=${this._selectedIds.size > 0}
1135
+ @change=${this.onDeselectAll}
1136
+ ></mp-checkbox>
1137
+ </th>` : u}
1138
+ ${this._columns.map((d, c) => this.renderHeader(d, c))}
1139
+ </tr>
1140
+ ${this.hasFilterRow ? this.renderFilterRow(i) : u}
1141
+ </thead>
1142
+ <tbody>
1143
+ ${this._loading ? h`<tr><td colspan=${s} class="loading-state">Loading…</td></tr>` : e.length === 0 ? h`<tr><td colspan=${s} class="empty-state">${this._emptyMessage}</td></tr>` : h`
1144
+ ${r.top > 0 ? h`<tr class="virtual-spacer" aria-hidden="true"><td colspan=${s} style=${_({ height: `${r.top}px`, padding: "0", border: "0" })}></td></tr>` : u}
1145
+ ${x(
1146
+ e,
1147
+ ({ key: d }) => d,
1148
+ ({ key: d, rowIndex: c, flat: p }) => this.renderRow(p, d, c, i)
1149
+ )}
1150
+ ${r.bottom > 0 ? h`<tr class="virtual-spacer" aria-hidden="true"><td colspan=${s} style=${_({ height: `${r.bottom}px`, padding: "0", border: "0" })}></td></tr>` : u}
1151
+ `}
1152
+ </tbody>
1153
+ </table>
1154
+ </div>
1155
+ ${this._pagination && !this._tree ? this.renderFooter(a) : u}
1156
+ </div>
1157
+ `;
1158
+ }
1159
+ getVirtualSpacerHeights() {
1160
+ if (!this._virtualScroll) return { top: 0, bottom: 0 };
1161
+ const e = this.getEffectiveData().length, { startIndex: t, endIndex: a } = this._virtualRange;
1162
+ return {
1163
+ top: t * this._itemSize,
1164
+ bottom: Math.max(0, (e - a) * this._itemSize)
1165
+ };
1166
+ }
1167
+ /** True when any column opted in. No column opts in, no second row, no cost. */
1168
+ get hasFilterRow() {
1169
+ return this._columns.some((e) => e.filterable);
1170
+ }
1171
+ get filterPanelId() {
1172
+ return `${this._filterUid}-filter-panel`;
1173
+ }
1174
+ filterTriggerId(e) {
1175
+ return `${this._filterUid}-filter-trigger-${e}`;
1176
+ }
1177
+ createFilterState(e) {
1178
+ const t = e.name, a = {
1179
+ selection: {
1180
+ values: e.filterSelection ? [...e.filterSelection.values] : [],
1181
+ inverse: !!e.filterSelection?.inverse,
1182
+ // Seeded too, or a restored comparison filter comes back empty while
1183
+ // its trigger still claims to be active.
1184
+ operator: e.filterSelection?.operator,
1185
+ operand: e.filterSelection?.operand ?? null
1186
+ },
1187
+ seededFrom: e.filterSelection ?? null,
1188
+ snapshot: null,
1189
+ loaded: null,
1190
+ view: null,
1191
+ loadedTerm: null,
1192
+ fromLocal: !1,
1193
+ term: "",
1194
+ operandText: e.filterSelection?.operand == null ? "" : String(e.filterSelection.operand),
1195
+ loading: !1,
1196
+ generation: 0,
1197
+ controller: null,
1198
+ debounce: null,
1199
+ listeners: /* @__PURE__ */ new Set(),
1200
+ // Assigned below: the context closes over `state`, which does not exist
1201
+ // until the literal is complete.
1202
+ ctx: null
1203
+ };
1204
+ return a.ctx = {
1205
+ values: () => a.view,
1206
+ loading: () => a.loading,
1207
+ search: (i) => this.setFilterSearch(t, i),
1208
+ apply: (i, s) => this.applyFilter(t, i, s),
1209
+ // Clearing emits the shape of the column's OWN mode. A comparison column
1210
+ // emitting an empty `selected` array would be reporting a values-mode
1211
+ // filter it never had, and a consumer switching on `mode` would miss it.
1212
+ clear: () => this.clearFilter(t),
1213
+ onChange: (i) => (a.listeners.add(i), () => a.listeners.delete(i))
1214
+ }, a;
1215
+ }
1216
+ /** State for a filterable column, created on demand. */
1217
+ filterState(e) {
1218
+ const t = this._filterStates.get(e);
1219
+ if (t) return t;
1220
+ const a = this._columns.find((s) => s.name === e);
1221
+ if (!a?.filterable) return null;
1222
+ const i = this.createFilterState(a);
1223
+ return this._filterStates.set(e, i), i;
1224
+ }
1225
+ notifyFilterListeners(e) {
1226
+ e.listeners.forEach((t) => t()), this.requestUpdate();
1227
+ }
1228
+ abortFilterRequest(e) {
1229
+ e.controller?.abort(), e.controller = null, e.debounce != null && clearTimeout(e.debounce), e.debounce = null, e.loading = !1;
1230
+ }
1231
+ /**
1232
+ * Replaces a column's selection and emits the one event the component owns.
1233
+ *
1234
+ * The component never filters `_data` itself — what a selection means, and
1235
+ * whether it is applied here or on a server, belongs to the consumer. All it
1236
+ * does locally is snapshot the value list the first time a selection becomes
1237
+ * non-empty, so the list cannot collapse to the selection.
1238
+ */
1239
+ applyFilter(e, t, a) {
1240
+ const i = this.filterState(e);
1241
+ if (!i) return;
1242
+ i.selection.values.length === 0 && t.length > 0 && i.snapshot == null && i.loaded && (i.snapshot = [...i.loaded.matching, ...i.loaded.remaining]), t.length === 0 && (i.snapshot = null), i.selection = { ...i.selection, values: [...t], inverse: a }, this.rebucket(i), this.notifyFilterListeners(i);
1243
+ const r = this._columns.find((o) => o.name === e);
1244
+ this.liveAnnouncer.announce(
1245
+ this.mergedLabels.announceFilter(r?.label ?? e, t.length)
1246
+ ), this.dispatchEvent(
1247
+ new CustomEvent("mp-datatable-filter-change", {
1248
+ detail: { mode: "values", column: e, selected: [...t], inverse: a },
1249
+ bubbles: !0,
1250
+ composed: !0
1251
+ })
1252
+ );
1253
+ }
1254
+ /** The column's mode, defaulting to a checkbox list of distinct values. */
1255
+ filterModeOf(e) {
1256
+ return this._columns.find((t) => t.name === e)?.filterMode ?? "values";
1257
+ }
1258
+ clearFilter(e) {
1259
+ if (this.filterModeOf(e) === "comparison") {
1260
+ const t = this.filterState(e);
1261
+ this.applyComparison(e, t?.selection.operator ?? "eq", "");
1262
+ return;
1263
+ }
1264
+ this.applyFilter(e, [], !1);
1265
+ }
1266
+ /**
1267
+ * Comparison mode's counterpart to `applyFilter`.
1268
+ *
1269
+ * It keeps the same contract: the component records what the user asked for
1270
+ * and emits it, and never filters `_data`. An empty operand is a cleared
1271
+ * filter, not a comparison against the empty string — otherwise every column
1272
+ * would filter everything away the moment its panel opened.
1273
+ */
1274
+ applyComparison(e, t, a) {
1275
+ const i = this.filterState(e);
1276
+ if (!i) return;
1277
+ const s = this._columns.find((l) => l.name === e), r = this.parseOperand(a, s?.filterInputType);
1278
+ i.operandText = a, i.selection = { ...i.selection, operator: t, operand: r }, this.notifyFilterListeners(i);
1279
+ const o = this.mergedLabels;
1280
+ this.liveAnnouncer.announce(
1281
+ o.announceComparisonFilter(
1282
+ s?.label ?? e,
1283
+ o.filterOperatorLabel(t),
1284
+ r == null ? "" : String(r)
1285
+ )
1286
+ ), this.dispatchEvent(
1287
+ new CustomEvent("mp-datatable-filter-change", {
1288
+ detail: { mode: "comparison", column: e, operator: t, operand: r },
1289
+ bubbles: !0,
1290
+ composed: !0
1291
+ })
1292
+ );
1293
+ }
1294
+ /**
1295
+ * An empty input, and a `'number'` input holding something unparseable, both
1296
+ * mean "no filter" rather than a comparison against `NaN` — which would be
1297
+ * false for every row and silently empty the table.
1298
+ */
1299
+ parseOperand(e, t) {
1300
+ if (e.trim() === "") return null;
1301
+ if ((t ?? "number") === "date") return e;
1302
+ const a = Number(e);
1303
+ return Number.isNaN(a) ? null : a;
1304
+ }
1305
+ setFilterSearch(e, t) {
1306
+ const a = this.filterState(e);
1307
+ if (!a) return;
1308
+ a.term = t, this.rebucket(a), this.notifyFilterListeners(a);
1309
+ const i = a.loadedTerm ?? "";
1310
+ (a.loaded?.hasMore || !t.startsWith(i)) && (a.debounce != null && clearTimeout(a.debounce), a.debounce = setTimeout(() => {
1311
+ a.debounce = null, this.loadDistincts(e, t);
1312
+ }, H));
1313
+ }
1314
+ /**
1315
+ * Loads (or recomputes) one column's value list.
1316
+ *
1317
+ * Called on every panel open — there is no cross-open cache, because the data
1318
+ * behind a list can change while the panel is closed and a stale list is worse
1319
+ * than a re-query. The source is asked first; a source resolving `null` means
1320
+ * it cannot answer for this column, and the local path takes over.
1321
+ */
1322
+ async loadDistincts(e, t) {
1323
+ const a = this.filterState(e);
1324
+ if (!a) return;
1325
+ const i = ++a.generation;
1326
+ if (a.controller?.abort(), this._distincts) {
1327
+ const s = new AbortController();
1328
+ a.controller = s, a.loading = !0, this.notifyFilterListeners(a);
1329
+ try {
1330
+ const r = await this._distincts({ column: e, search: t, signal: s.signal });
1331
+ if (i !== a.generation) return;
1332
+ if (a.loading = !1, a.controller = null, r) {
1333
+ a.loaded = r, a.loadedTerm = t, this.rebucket(a), this.notifyFilterListeners(a);
1334
+ return;
1335
+ }
1336
+ } catch {
1337
+ if (i !== a.generation) return;
1338
+ a.loading = !1, a.controller = null, a.loaded = null, a.loadedTerm = t, this.notifyFilterListeners(a);
1339
+ return;
1340
+ }
1341
+ }
1342
+ a.loaded = this.localDistincts(e), a.loadedTerm = "", a.fromLocal = !0, this.rebucket(a), this.notifyFilterListeners(a);
1343
+ }
1344
+ /**
1345
+ * Recomputes the OPEN column's list when it is locally derived and the rows
1346
+ * changed under it.
1347
+ *
1348
+ * This is what makes the `remaining` bucket work at all. A consumer applies a
1349
+ * filter by rebinding `data` to the subset; if the list were not recomputed,
1350
+ * `loaded` would still describe the pre-filter rows, every snapshot value
1351
+ * would still look present, and nothing would ever be marked as having left
1352
+ * the data.
1353
+ *
1354
+ * Only the open column, and only the local path: a closed panel reloads when
1355
+ * it opens, and a consumer-supplied source owns its own freshness — re-asking
1356
+ * it on every `data` assignment would be a request per keystroke of whatever
1357
+ * the consumer's own filtering does.
1358
+ */
1359
+ refreshLocalDistincts() {
1360
+ if (!this._openFilterColumn) return;
1361
+ const e = this._filterStates.get(this._openFilterColumn);
1362
+ !e || !e.fromLocal || (e.loaded = this.localDistincts(this._openFilterColumn), this.rebucket(e), this.notifyFilterListeners(e));
1363
+ }
1364
+ /**
1365
+ * The value list computed from the rows this element holds — but only when it
1366
+ * holds all of them.
1367
+ *
1368
+ * With a `fetch` callback, external paging, or loaded tree children, `_data`
1369
+ * is a window onto a larger set, and a list built from a window silently omits
1370
+ * values. There is no partial answer worth giving there: the column reports
1371
+ * that it has no values and the consumer is expected to supply `distincts`.
1372
+ */
1373
+ localDistincts(e) {
1374
+ if (this._fetch != null || this.isExternallyPaged() || this._childCache.size > 0) return null;
1375
+ const t = this.mergedLabels, a = [];
1376
+ return this._data.forEach((i) => {
1377
+ const s = i?.[e];
1378
+ g(a, s) || a.push({ value: s, label: t.filterValue(s) });
1379
+ }), a.sort((i, s) => i.label.localeCompare(s.label)), { matching: a, remaining: [], hasMore: !1 };
1380
+ }
1381
+ /**
1382
+ * Re-derives `matching` / `remaining` from the snapshot and the search term.
1383
+ *
1384
+ * `remaining` holds snapshot values the current list no longer contains: they
1385
+ * stay listed (dimmed) so a selection can be widened. Search is applied to
1386
+ * both buckets client-side — the debounced re-query above is the exception,
1387
+ * not the rule.
1388
+ */
1389
+ rebucket(e) {
1390
+ if (!e.loaded) {
1391
+ e.view = null;
1392
+ return;
1393
+ }
1394
+ const t = e.term.trim().toLowerCase(), a = (o) => t === "" || o.label.toLowerCase().includes(t), i = [...e.loaded.matching, ...e.loaded.remaining], s = e.snapshot ? e.snapshot.filter((o) => g(i, o.value)) : e.loaded.matching, r = e.snapshot ? e.snapshot.filter((o) => !g(i, o.value)) : e.loaded.remaining;
1395
+ e.view = {
1396
+ matching: s.filter(a),
1397
+ remaining: r.filter(a),
1398
+ hasMore: e.loaded.hasMore
1399
+ };
1400
+ }
1401
+ /** The open column's trigger button, or null. Re-queried on every call. */
1402
+ openFilterTrigger() {
1403
+ return this._openFilterColumn ? this.renderRoot?.querySelector(
1404
+ `tr.filter-row th[data-column="${this._openFilterColumn}"] .filter-trigger`
1405
+ ) ?? null : null;
1406
+ }
1407
+ onFilterTriggerClick(e, t) {
1408
+ if (t.preventDefault(), t.stopPropagation(), this._openFilterColumn === e.name) {
1409
+ this.filterOverlay.close();
1410
+ return;
1411
+ }
1412
+ this.filterOverlay.isOpen && this.filterOverlay.close(!1), this._openFilterColumn = e.name, this.requestUpdate(), (e.filterMode ?? "values") !== "comparison" && this.loadDistincts(e.name, ""), this.filterOverlay.open(), this.dispatchEvent(
1413
+ new CustomEvent("mp-datatable-filter-open", {
1414
+ detail: { column: e.name },
1415
+ bubbles: !0,
1416
+ composed: !0
1417
+ })
1418
+ );
1419
+ }
1420
+ /**
1421
+ * Renders the open panel into the overlay pane, with a render root of its
1422
+ * own. The panel is NOT part of this element's template: relocating a node
1423
+ * lit rendered is unsupported, so the pane gets its own `render()` call
1424
+ * whose container happens to live in `document.body`.
1425
+ *
1426
+ * The consumer's node is appended AFTER the template has been stamped —
1427
+ * `stampScope` recurses, so stamping a subtree that already holds consumer
1428
+ * DOM would brand it with our scope and let our rules match their content.
1429
+ *
1430
+ * ### Why this dialog is deliberately NOT `aria-modal` (#416)
1431
+ *
1432
+ * Tab is contained and Escape closes, but the rest of the page stays
1433
+ * available to assistive tech — and it must. A column filter is anchored to
1434
+ * its trigger, dismissible, and does not own the page.
1435
+ *
1436
+ * `aria-modal="true"` would tell a screen reader that everything outside the
1437
+ * panel is unavailable while a virtual cursor could still walk into the table
1438
+ * behind it. The honest way to keep that promise — marking the table `inert`
1439
+ * while the panel is open — would hide the very rows whose values the user is
1440
+ * picking from, which is worse than the inconsistency it fixes.
1441
+ *
1442
+ * So it is a non-modal dialog: the wrong claim removed rather than an
1443
+ * unfinished one completed. `OverlayController` is right to refuse to guess
1444
+ * whether its host is a dialog or a menu; the call belongs here, where the
1445
+ * component knows what it is.
1446
+ */
1447
+ renderFilterPanel() {
1448
+ const e = this.filterOverlay.portalContainer;
1449
+ if (!e) return;
1450
+ const t = this._columns.find((r) => r.name === this._openFilterColumn);
1451
+ if (!t) return;
1452
+ const a = this.filterState(t.name);
1453
+ v(
1454
+ h`
1455
+ <div
1456
+ class="filter-panel"
1457
+ id=${this.filterPanelId}
1458
+ role="dialog"
1459
+ aria-label=${this.mergedLabels.filterColumn(t.label ?? t.name)}
1460
+ >
1461
+ <div class="filter-panel-body"></div>
1462
+ </div>
1463
+ `,
1464
+ e
1465
+ );
1466
+ const i = e.querySelector(".filter-panel-body");
1467
+ if (!i || !a) return;
1468
+ if (this._mountedFilterColumn === t.name && i.firstChild) {
1469
+ this._consumerMountedFilter || this.renderDefaultFilterPanel(t, a, i);
1470
+ return;
1471
+ }
1472
+ const s = t.filterRenderer?.(t, a.ctx) ?? null;
1473
+ if (s) {
1474
+ i.replaceChildren(s), this._consumerMountedFilter = !0, this._mountedFilterColumn = t.name;
1475
+ return;
1476
+ }
1477
+ this._consumerMountedFilter = !1, this.renderDefaultFilterPanel(t, a, i), this._mountedFilterColumn = t.name;
1478
+ }
1479
+ /**
1480
+ * The built-in panel: clear, search, invert, checkbox list.
1481
+ *
1482
+ * Rendered with a `render()` of its own into the panel body, for the same
1483
+ * reason the panel itself is: this is not part of the element's template, and
1484
+ * lit must own the container it diffs. The checkbox list is keyed on `value`
1485
+ * so a repaint after a re-query moves rows instead of rebuilding them — an
1486
+ * unkeyed list would rebuild the input the user is interacting with.
1487
+ */
1488
+ renderDefaultFilterPanel(e, t, a) {
1489
+ if ((e.filterMode ?? "values") === "comparison") {
1490
+ this.renderComparisonFilterPanel(e, t, a);
1491
+ return;
1492
+ }
1493
+ const i = this.mergedLabels, s = e.label ?? e.name, r = t.view, o = t.selection.values, l = [
1494
+ ...o,
1495
+ ...(r?.matching ?? []).filter((c) => !g(o, c.value)),
1496
+ ...(r?.remaining ?? []).filter((c) => !g(o, c.value))
1497
+ ], d = (c) => !!r && g(r.remaining, c);
1498
+ v(
1499
+ h`
1500
+ <button
1501
+ type="button"
1502
+ class="filter-clear"
1503
+ ?disabled=${o.length === 0 && !t.selection.inverse}
1504
+ @click=${() => this.onFilterClear(e.name)}
1505
+ >
1506
+ ${i.filterClear(s)}
1507
+ </button>
1508
+ <input
1509
+ type="search"
1510
+ class="filter-search"
1511
+ .value=${t.term}
1512
+ aria-label=${i.filterSearch}
1513
+ @input=${(c) => t.ctx.search(c.target.value)}
1514
+ />
1515
+ <button
1516
+ type="button"
1517
+ class="filter-invert"
1518
+ aria-pressed=${t.selection.inverse ? "true" : "false"}
1519
+ @click=${() => t.ctx.apply(o, !t.selection.inverse)}
1520
+ >
1521
+ ${i.filterInvert}
1522
+ </button>
1523
+ <div class="filter-options" role="group" aria-label=${i.filterGroup(s)}>
1524
+ ${t.loading ? h`<span class="filter-loading">${i.loading}</span>` : u}
1525
+ ${x(
1526
+ l,
1527
+ (c) => c.value,
1528
+ (c) => h`
1529
+ <label class=${C({ "filter-option": !0, "filter-remaining": d(c.value) })}>
1530
+ <input
1531
+ type="checkbox"
1532
+ .checked=${g(o, c.value)}
1533
+ @change=${(p) => this.onFilterToggle(e.name, c, p.target.checked)}
1534
+ />
1535
+ <span>${c.label}</span>
1536
+ </label>
1537
+ `
1538
+ )}
1539
+ ${l.length === 0 && !t.loading ? h`<span class="filter-no-values">${i.filterNoValues}</span>` : u}
1540
+ </div>
1541
+ ${r?.hasMore ? h`<span class="filter-has-more">${i.filterHasMore}</span>` : u}
1542
+ `,
1543
+ a
1544
+ );
1545
+ }
1546
+ /**
1547
+ * The `'comparison'` panel: an operator and one operand.
1548
+ *
1549
+ * It deliberately does NOT load distinct values — the whole point of this mode
1550
+ * is that the column's values are a quantity rather than a set worth listing,
1551
+ * so asking the source for them would be a round trip whose answer is never
1552
+ * displayed.
1553
+ */
1554
+ renderComparisonFilterPanel(e, t, a) {
1555
+ const i = this.mergedLabels, s = e.label ?? e.name, r = e.filterOperators?.length ? e.filterOperators : T, o = t.selection.operator ?? r[0], l = t.selection.operand, d = e.filterInputType ?? "number", c = () => a.querySelector(".filter-operand")?.value ?? "", p = () => a.querySelector(".filter-operator")?.value ?? o;
1556
+ v(
1557
+ h`
1558
+ <button
1559
+ type="button"
1560
+ class="filter-clear"
1561
+ ?disabled=${l == null}
1562
+ @click=${() => this.onFilterClear(e.name)}
1563
+ >
1564
+ ${i.filterClear(s)}
1565
+ </button>
1566
+ <div class="filter-comparison">
1567
+ <select
1568
+ class="filter-operator"
1569
+ aria-label=${i.filterOperator}
1570
+ @change=${() => this.applyComparison(e.name, p(), c())}
1571
+ >
1572
+ ${r.map(
1573
+ (f) => h`
1574
+ <option value=${f} ?selected=${f === o}>
1575
+ ${U[f]} ${i.filterOperatorLabel(f)}
1576
+ </option>
1577
+ `
1578
+ )}
1579
+ </select>
1580
+ <input
1581
+ class="filter-operand"
1582
+ type=${d}
1583
+ .value=${K(t.operandText)}
1584
+ aria-label=${i.filterOperand}
1585
+ @input=${() => this.applyComparison(e.name, p(), c())}
1586
+ />
1587
+ </div>
1588
+ `,
1589
+ a
1590
+ );
1591
+ }
1592
+ onFilterToggle(e, t, a) {
1593
+ const i = this.filterState(e);
1594
+ if (!i) return;
1595
+ const s = a ? [...i.selection.values, t] : i.selection.values.filter((r) => !$(r.value, t.value));
1596
+ i.ctx.apply(s, i.selection.inverse);
1597
+ }
1598
+ onFilterClear(e) {
1599
+ const t = this.filterState(e);
1600
+ t && (t.ctx.clear(), this.filterOverlay.portalContainer?.querySelector(".filter-search, .filter-operand")?.focus({ preventScroll: !0 }));
1601
+ }
1602
+ /**
1603
+ * The second `<thead>` row. One cell per column in the SAME order as row 1,
1604
+ * gutters included — alignment is structural, not a CSS problem, and the
1605
+ * empty cells for non-filterable columns are what keeps it that way.
1606
+ *
1607
+ * The cells deliberately carry no width. Widths live on row 1's `<th>`, and
1608
+ * `table-layout: fixed` resolves columns from the first row only, so this row
1609
+ * cannot perturb geometry once the measure pass has run. Before it runs the
1610
+ * table is `auto`, where the row is only harmless because `.filter-trigger`
1611
+ * is width-neutral — see the note on that rule in `datatable.light.scss`.
1612
+ */
1613
+ renderFilterRow(e) {
1614
+ return h`
1615
+ <tr role="row" aria-rowindex="2" class="filter-row">
1616
+ ${this._tree ? h`<th class="filter-cell tree-chevron-cell"></th>` : u}
1617
+ ${e ? h`<th class="filter-cell checkbox-cell"></th>` : u}
1618
+ ${this._columns.map((t) => this.renderFilterCell(t))}
1619
+ </tr>
1620
+ `;
1621
+ }
1622
+ renderFilterCell(e) {
1623
+ if (!e.filterable)
1624
+ return h`<th class="filter-cell p-0" data-column=${e.name} scope="col"></th>`;
1625
+ const t = this._openFilterColumn === e.name, a = this.mergedLabels, i = e.label ?? e.name, s = e.filterActive ? a.filterColumnActive(i, e.filterSummary) : a.filterColumn(i);
1626
+ return h`
1627
+ <th class="filter-cell p-0" data-column=${e.name} scope="col">
1628
+ <button
1629
+ type="button"
1630
+ class=${C({
1631
+ "filter-trigger": !0,
1632
+ "p-2": !0,
1633
+ "rounded-0": !0,
1634
+ active: !!e.filterActive,
1635
+ open: t
1636
+ })}
1637
+ id=${this.filterTriggerId(e.name)}
1638
+ aria-expanded=${t ? "true" : "false"}
1639
+ aria-controls=${t ? this.filterPanelId : u}
1640
+ aria-label=${s}
1641
+ @click=${(r) => this.onFilterTriggerClick(e, r)}
1642
+ >
1643
+ <svg class="filter-icon" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
1644
+ <path d="M2 3h12l-4.5 5.25V13L6.5 11.5V8.25L2 3z" />
1645
+ </svg>
1646
+ ${e.filterSummary ? h`<span class="filter-summary">${e.filterSummary}</span>` : u}
1647
+ </button>
1648
+ </th>
1649
+ `;
1650
+ }
1651
+ renderHeader(e, t) {
1652
+ const a = e.sortable ?? !0, i = this._sortColumns.findIndex((d) => d.property === e.name), s = i >= 0 ? this._sortColumns[i].direction : null, r = this._columnWidths.get(e.name) ?? e.width, o = e.headerRenderer ? e.headerRenderer(e) : e.label ?? e.name, l = {};
1653
+ return typeof r == "number" && (l.width = `${r}px`, l.minWidth = `${r}px`), h`
1654
+ <th
1655
+ scope="col"
1656
+ data-column=${e.name}
1657
+ data-sortable=${a ? "true" : "false"}
1658
+ aria-sort=${s ? s === "ascending" ? "ascending" : "descending" : "none"}
1659
+ style=${_(l)}
1660
+ >
1661
+ ${a ? h`<button
1662
+ type="button"
1663
+ class="header-cell header-sort"
1664
+ @click=${(d) => this.onHeaderClick(e, d)}
1665
+ >
1666
+ <span>${w(o)}</span>
1667
+ ${i >= 0 && this._sortColumns.length > 1 ? h`<span class="sort-index">${i + 1}</span>` : u}
1668
+ </button>` : h`<span class="header-cell">
1669
+ <span>${w(o)}</span>
1670
+ </span>`}
1671
+ ${this._resizableColumns ? h`<span
1672
+ class="resize-handle"
1673
+ role="separator"
1674
+ tabindex="0"
1675
+ aria-orientation="vertical"
1676
+ aria-label=${this.mergedLabels.resizeColumn(e.label ?? e.name)}
1677
+ aria-valuemin="40"
1678
+ aria-valuenow=${Math.round(r ?? 0) || u}
1679
+ @pointerdown=${(d) => this.startColumnResize(e, d)}
1680
+ @keydown=${(d) => this.onResizeHandleKeydown(e, d)}
1681
+ ></span>` : u}
1682
+ </th>
1683
+ `;
1684
+ }
1685
+ renderRow(e, t, a, i) {
1686
+ const { row: s, depth: r, isExpanded: o, isPlaceholder: l } = e, d = !l && this._selectedIds.has(t), c = !l && this._cutIds.has(t), p = !l && this._focusedRowKey === t, f = l ? 0 : this.extractChildCount(s), b = this._tree && !l && f > 0, R = !l && s != null && this.isParentIndeterminate(s);
1687
+ return h`
1688
+ <tr
1689
+ role="row"
1690
+ aria-rowindex=${a + 1 + (this.hasFilterRow ? 2 : 1)}
1691
+ aria-level=${this._tree ? r + 1 : u}
1692
+ aria-expanded=${this._tree && f > 0 ? o ? "true" : "false" : u}
1693
+ aria-busy=${l ? "true" : u}
1694
+ aria-selected=${!l && this._selectionMode !== "none" ? d ? "true" : "false" : u}
1695
+ data-row-key=${t}
1696
+ data-selected=${d ? "true" : "false"}
1697
+ data-cut=${c ? "true" : "false"}
1698
+ data-focused=${p ? "true" : "false"}
1699
+ data-placeholder=${l ? "true" : "false"}
1700
+ data-depth=${this._tree ? String(r) : u}
1701
+ data-clickable=${!l && (this._selectionMode !== "none" || this.hasRowClickListeners()) ? "true" : "false"}
1702
+ tabindex=${!l && (this._selectionMode !== "none" || this._tree) ? this._focusedRowKey === t || this._focusedRowKey === null && a === 0 ? "0" : "-1" : u}
1703
+ @focus=${l ? null : () => {
1704
+ this._focusedRowKey = t, this.requestUpdate();
1705
+ }}
1706
+ @click=${l ? null : (m) => this.onRowClick(s, t, a, m)}
1707
+ @dblclick=${l ? null : (m) => this.onRowDblClick(s, t, a, m)}
1708
+ @contextmenu=${l ? null : (m) => this.onRowContextMenu(s, t, a, m)}
1709
+ @keydown=${l ? null : (m) => this.onRowKeydown(s, t, a, e.parentId, r, o, f, m)}
1710
+ >
1711
+ ${this._tree ? h`<td class="tree-chevron-cell" style=${_({ paddingInlineStart: `${r * this._treeIndent}rem` })}>
1712
+ ${b ? h`<button
1713
+ type="button"
1714
+ class="tree-chevron"
1715
+ aria-label=${o ? this.mergedLabels.collapseRow : this.mergedLabels.expandRow}
1716
+ aria-expanded=${o ? "true" : "false"}
1717
+ data-expanded=${o ? "true" : "false"}
1718
+ @click=${(m) => this.toggleExpand(s, e.parentId, r, m)}
1719
+ >${o ? "▾" : "▸"}</button>` : u}
1720
+ </td>` : u}
1721
+ ${i ? h`<td class="checkbox-cell" @click=${(m) => m.stopPropagation()}>
1722
+ ${l ? u : h`<mp-checkbox
1723
+ aria-label=${this.mergedLabels.selectRow(a + 1)}
1724
+ .checked=${d}
1725
+ .indeterminate=${R}
1726
+ @change=${(m) => this.onRowCheckboxToggle(s, t, a, m)}
1727
+ ></mp-checkbox>`}
1728
+ </td>` : u}
1729
+ ${this._rowRenderer ? this.renderRowFromRenderer(s, a, { depth: r, isExpanded: o, isPlaceholder: l }) : l ? h`<td colspan=${this._columns.length} class="tree-placeholder-cell" aria-label=${this.mergedLabels.loading}>…</td>` : this._columns.map((m) => this.renderCell(s, m, a))}
1730
+ </tr>
1731
+ `;
1732
+ }
1733
+ renderRowFromRenderer(e, t, a) {
1734
+ const i = this._rowRenderer(e, t, a);
1735
+ if (i == null)
1736
+ return a.isPlaceholder ? h`<td colspan=${this._columns.length} class="tree-placeholder-cell" aria-label=${this.mergedLabels.loading}>…</td>` : this._columns.map((s) => this.renderCell(e, s, t));
1737
+ if (Array.isArray(i) || j(i)) {
1738
+ const s = [];
1739
+ for (const r of i) s.push(r);
1740
+ return s;
1741
+ }
1742
+ return i;
1743
+ }
1744
+ renderCell(e, t, a) {
1745
+ const i = t.cellRenderer ? t.cellRenderer(e, t, a) : G(e, t);
1746
+ return h`<td class=${t.cellClass ?? ""} data-column=${t.name}>${w(i)}</td>`;
1747
+ }
1748
+ renderFooter(e) {
1749
+ const t = Array.from({ length: e }, (a, i) => i + 1);
1750
+ return h`
1751
+ <div class="datatable-footer">
1752
+ <mp-pagination
1753
+ class="datatable-per-page"
1754
+ aria-label=${this.mergedLabels.rowsPerPage}
1755
+ .pageNumbers=${this._perPageOptions}
1756
+ .selectedPageNumber=${this._perPage}
1757
+ .showArrows=${!1}
1758
+ @mp-pagination-page-change=${(a) => this.setPerPage(a.detail.page)}
1759
+ ></mp-pagination>
1760
+ <mp-pagination
1761
+ class="datatable-pagination"
1762
+ .pageNumbers=${t}
1763
+ .selectedPageNumber=${this._page}
1764
+ .numberOfBoxes=${7}
1765
+ .showArrows=${!0}
1766
+ @mp-pagination-page-change=${(a) => this.gotoPage(a.detail.page)}
1767
+ ></mp-pagination>
1768
+ </div>
1769
+ `;
1770
+ }
1771
+ setPerPage(e) {
1772
+ const t = Math.max(1, Math.floor(e || 1));
1773
+ this._perPage !== t && (this._perPage = t, this._page = 1, this.requestUpdate(), this.scheduleFetchReload(), this.dispatchEvent(
1774
+ new CustomEvent("mp-datatable-per-page-change", {
1775
+ detail: { perPage: t },
1776
+ bubbles: !0,
1777
+ composed: !0
1778
+ })
1779
+ ), this.dispatchEvent(
1780
+ new CustomEvent("mp-datatable-page-change", {
1781
+ detail: { page: 1 },
1782
+ bubbles: !0,
1783
+ composed: !0
1784
+ })
1785
+ ));
1786
+ }
1787
+ getEffectiveData() {
1788
+ if (this._tree || this.isRootWindowed())
1789
+ return this.getFlatList().map((t) => t.row);
1790
+ let e = this._data;
1791
+ if (this._autoSort && this._sortColumns.length > 0 && (e = y(e, this._sortColumns)), this._pagination && !this.isExternallyPaged()) {
1792
+ const t = (this._page - 1) * this._perPage;
1793
+ e = e.slice(t, t + this._perPage);
1794
+ }
1795
+ return e;
1796
+ }
1797
+ /**
1798
+ * Flat list of visible rows including expansion + placeholders. Computed
1799
+ * each render in tree mode; flat mode produces a trivial mapping of `_data`
1800
+ * (after sort+pagination) with default metadata.
1801
+ *
1802
+ * Memoised via `_cachedFlatList`, cleared in `willUpdate`. Multiple calls
1803
+ * during the same render cycle (`computeVisibleRows`,
1804
+ * `getVirtualSpacerHeights`, aria-rowcount) share one computation.
1805
+ */
1806
+ getFlatList() {
1807
+ if (this._cachedFlatList !== null) return this._cachedFlatList;
1808
+ if (!this._tree) {
1809
+ if (this.isRootWindowed()) {
1810
+ const r = this._totalRecords ?? this._data.length, o = Math.max(1, this._perPage), l = new Array(r);
1811
+ for (let d = 0; d < r; d++) {
1812
+ const c = Math.floor(d / o) + 1, p = d % o, f = c === 1 ? this._data[p] : this._pageCache.get(c)?.[p];
1813
+ l[d] = f !== void 0 ? { row: f, key: this._rowKey(f, d), depth: 0, parentId: null, isExpanded: !1, isPlaceholder: !1 } : { row: void 0, key: `__placeholder-flat-${d}`, depth: 0, parentId: null, page: c, isExpanded: !1, isPlaceholder: !0 };
1814
+ }
1815
+ return this._cachedFlatList = l;
1816
+ }
1817
+ const s = (() => {
1818
+ let r = this._data;
1819
+ if (this._autoSort && this._sortColumns.length > 0 && (r = y(r, this._sortColumns)), this._pagination && !this.isExternallyPaged()) {
1820
+ const o = (this._page - 1) * this._perPage;
1821
+ r = r.slice(o, o + this._perPage);
1822
+ }
1823
+ return r;
1824
+ })();
1825
+ return this._cachedFlatList = s.map((r, o) => ({
1826
+ row: r,
1827
+ key: this._rowKey(r, o),
1828
+ depth: 0,
1829
+ parentId: null,
1830
+ isExpanded: !1,
1831
+ isPlaceholder: !1
1832
+ }));
1833
+ }
1834
+ const e = [], t = Math.max(1, this._perPage), a = (s) => this._autoSort && this._sortColumns.length > 0 ? y(s, this._sortColumns) : s, i = (s, r, o) => {
1835
+ const l = this.extractId(s), d = l != null && this._expandedIds.has(l), c = this.extractChildCount(s);
1836
+ if (e.push({ row: s, key: this._rowKey(s, e.length), depth: r, parentId: o, isExpanded: d, isPlaceholder: !1 }), !d || c === 0 || l == null) return;
1837
+ const p = this._childCache.get(l);
1838
+ if (p && p.length > 0) {
1839
+ for (const b of a(p)) i(b, r + 1, l);
1840
+ const f = this._childTotals.get(l) ?? p.length;
1841
+ for (let b = 0; b < Math.max(0, f - p.length); b++)
1842
+ e.push({ row: void 0, key: `__placeholder-${String(l)}-${p.length + b}`, depth: r + 1, parentId: l, isExpanded: !1, isPlaceholder: !0 });
1843
+ } else
1844
+ for (let f = 0; f < c; f++)
1845
+ e.push({ row: void 0, key: `__placeholder-${String(l)}-${f}`, depth: r + 1, parentId: l, isExpanded: !1, isPlaceholder: !0 });
1846
+ };
1847
+ if (this.isRootWindowed()) {
1848
+ const s = this._totalRecords ?? this._data.length;
1849
+ for (let r = 0; r < s; r++) {
1850
+ const o = Math.floor(r / t) + 1, l = r % t, d = o === 1 ? this._data[l] : this._pageCache.get(o)?.[l];
1851
+ d === void 0 ? e.push({ row: void 0, key: `__placeholder-root-${r}`, depth: 0, parentId: null, page: o, isExpanded: !1, isPlaceholder: !0 }) : i(d, 0, null);
1852
+ }
1853
+ } else {
1854
+ const s = this._autoSort && this._sortColumns.length > 0 ? y(this._data, this._sortColumns) : this._data;
1855
+ for (const r of s) i(r, 0, null);
1856
+ }
1857
+ return this._cachedFlatList = e;
1858
+ }
1859
+ computeVisibleRows() {
1860
+ const e = this.getFlatList(), t = this._tree ? 0 : this._pagination ? (this._page - 1) * this._perPage : 0;
1861
+ let a = e, i = 0;
1862
+ if (this._virtualScroll) {
1863
+ const { startIndex: s, endIndex: r } = this._virtualRange;
1864
+ a = e.slice(s, r), i = s;
1865
+ }
1866
+ return a.map((s, r) => {
1867
+ const o = t + i + r;
1868
+ return { row: s.row, rowIndex: o, key: s.key, flat: s };
1869
+ });
1870
+ }
1871
+ // ─── Tree-mode helpers ───────────────────────────────────────────────────
1872
+ extractId(e) {
1873
+ return !this._idKey || e == null || typeof e != "object" ? null : typeof this._idKey == "function" ? this._idKey(e) : e[this._idKey];
1874
+ }
1875
+ extractChildCount(e) {
1876
+ if (!this._childCountKey || e == null || typeof e != "object") return 0;
1877
+ const t = e[this._childCountKey];
1878
+ return typeof t == "number" && t > 0 ? t : 0;
1879
+ }
1880
+ /** Walks the loaded subtree of `row` and returns the rowKey for every descendant. */
1881
+ collectDescendantKeys(e) {
1882
+ const t = this.extractId(e), a = t != null ? this._childCache.get(t) : void 0;
1883
+ if (!a) return [];
1884
+ const i = [];
1885
+ for (const s of a) {
1886
+ i.push(this._rowKey(s, -1));
1887
+ const r = this.collectDescendantKeys(s);
1888
+ for (const o of r) i.push(o);
1889
+ }
1890
+ return i;
1891
+ }
1892
+ /** Some-but-not-all loaded descendants selected → indeterminate parent checkbox. */
1893
+ isParentIndeterminate(e) {
1894
+ return this._selectionStrategy !== "cascading" || e == null ? !1 : this.getIndeterminateKeys().has(this._rowKey(e, -1));
1895
+ }
1896
+ /**
1897
+ * Per-render memo: the set of row keys whose loaded subtree is partially
1898
+ * selected. Built in one DFS over `_childCache` so each loaded parent is
1899
+ * visited exactly once per render. Replaces the previous
1900
+ * `collectDescendantKeys`-per-visible-row recursion which was O(visible ×
1901
+ * descendants) per render.
1902
+ */
1903
+ getIndeterminateKeys() {
1904
+ if (this._cachedIndeterminateKeys !== null) return this._cachedIndeterminateKeys;
1905
+ const e = /* @__PURE__ */ new Set();
1906
+ if (this._selectionStrategy !== "cascading" || !this._tree)
1907
+ return this._cachedIndeterminateKeys = e;
1908
+ const t = (a) => {
1909
+ const i = this.extractId(a);
1910
+ if (i == null) return { selected: 0, total: 0 };
1911
+ const s = this._childCache.get(i);
1912
+ if (!s || s.length === 0) return { selected: 0, total: 0 };
1913
+ let r = 0, o = 0;
1914
+ for (const l of s) {
1915
+ const d = this._rowKey(l, -1), c = this._selectedIds.has(d) ? 1 : 0, p = t(l);
1916
+ r += c + p.selected, o += 1 + p.total;
1917
+ }
1918
+ return o > 0 && r > 0 && r < o && e.add(this._rowKey(a, -1)), { selected: r, total: o };
1919
+ };
1920
+ for (const a of this._data) t(a);
1921
+ return this._cachedIndeterminateKeys = e;
1922
+ }
1923
+ /**
1924
+ * Toggle a row's expanded state. On expand, fires a fetch-request event if
1925
+ * children aren't cached yet so the wrapper can bridge to the consumer's
1926
+ * `[fetch]` callback. Always fires `expanded-ids-change`.
1927
+ */
1928
+ toggleExpand(e, t, a, i) {
1929
+ i.stopPropagation(), i.preventDefault();
1930
+ const s = this.extractId(e);
1931
+ if (s == null) return;
1932
+ const r = new Set(this._expandedIds);
1933
+ let o;
1934
+ r.has(s) ? (r.delete(s), o = !1) : (r.add(s), o = !0), this._expandedIds = r, o ? (this.dispatchEvent(
1935
+ new CustomEvent("mp-datatable-row-expand", {
1936
+ detail: { row: e, depth: a, parentId: t },
1937
+ bubbles: !0,
1938
+ composed: !0
1939
+ })
1940
+ ), this.extractChildCount(e) > 0 && !this._childCache.has(s) && !this._pendingFetches.has(s) && this.fetchChildren(s)) : this.dispatchEvent(
1941
+ new CustomEvent("mp-datatable-row-collapse", {
1942
+ detail: { row: e, depth: a, parentId: t },
1943
+ bubbles: !0,
1944
+ composed: !0
1945
+ })
1946
+ ), this.emitExpandedIdsChange(), this.requestUpdate();
1947
+ }
1948
+ emitExpandedIdsChange() {
1949
+ this.dispatchEvent(
1950
+ new CustomEvent("mp-datatable-expanded-ids-change", {
1951
+ detail: { expandedIds: new Set(this._expandedIds) },
1952
+ bubbles: !0,
1953
+ composed: !0
1954
+ })
1955
+ );
1956
+ }
1957
+ // ─── Fetch-callback driver (the WC owns the whole server-paged loop) ─────
1958
+ /**
1959
+ * Fetch a windowed root page (≥ 2) into the page cache. Called when a root
1960
+ * placeholder scrolls into view. Keyed on the requested page, so a server
1961
+ * that echoes a different page number can't deadlock the window.
1962
+ * Generation-guarded against responses that land after an invalidation.
1963
+ */
1964
+ async fetchWindowPage(e) {
1965
+ if (!this._fetch || e <= 1) return;
1966
+ this._pendingPageFetches.add(e);
1967
+ const t = this._fetchGeneration;
1968
+ try {
1969
+ const a = await this._fetch({ parentId: null, page: e, perPage: this._perPage, sortColumns: [...this._sortColumns] });
1970
+ if (t !== this._fetchGeneration || !this._fetch) return;
1971
+ this._pendingPageFetches.delete(e), this._pageCache.set(e, [...a?.data ?? []]);
1972
+ const i = a?.totalRecords == null ? null : Math.max(0, Math.floor(a.totalRecords));
1973
+ i != null && (this._totalRecords = i), this.requestUpdate();
1974
+ } catch (a) {
1975
+ this._pendingPageFetches.delete(e), console.error("[mp-datatable] fetch failed for root page", e, a);
1976
+ }
1977
+ }
1978
+ /**
1979
+ * Fetch a node's children into the child cache. Called on expand or when a
1980
+ * child placeholder scrolls into view. Generation-guarded.
1981
+ */
1982
+ async fetchChildren(e) {
1983
+ if (!this._fetch || e == null) return;
1984
+ this._pendingFetches.add(e);
1985
+ const t = this._fetchGeneration;
1986
+ try {
1987
+ const a = await this._fetch({ parentId: e, page: 1, perPage: this._perPage, sortColumns: [...this._sortColumns] });
1988
+ if (t !== this._fetchGeneration || !this._fetch) return;
1989
+ this._pendingFetches.delete(e), this._childCache.set(e, [...a?.data ?? []]), this._childTotals.set(e, a?.totalRecords ?? a?.data?.length ?? 0), this.requestUpdate();
1990
+ } catch (a) {
1991
+ this._pendingFetches.delete(e), console.error("[mp-datatable] fetch failed for children of", e, a);
1992
+ }
1993
+ }
1994
+ /**
1995
+ * Fetch a single page of roots and make it the page-1 data (initial load and
1996
+ * non-virtual pagination). The grand total is read from the response —
1997
+ * consumers never set `totalRecords`. Generation-guarded against stale loads.
1998
+ */
1999
+ async loadPage(e) {
2000
+ if (!this._fetch) return;
2001
+ const t = this._fetchGeneration;
2002
+ let a;
2003
+ try {
2004
+ a = await this._fetch({ parentId: null, page: e, perPage: this._perPage, sortColumns: [...this._sortColumns] });
2005
+ } catch (s) {
2006
+ console.error("[mp-datatable] fetch failed for page", e, s);
2007
+ return;
2008
+ }
2009
+ if (t !== this._fetchGeneration || !this._fetch) return;
2010
+ this._data = [...a?.data ?? []];
2011
+ const i = a?.totalRecords == null ? null : Math.max(0, Math.floor(a.totalRecords));
2012
+ this._totalRecords = i, this._initialFetchDone = !0, this.requestUpdate();
2013
+ }
2014
+ /**
2015
+ * Coalesce sort/perPage/page changes (which arrive both as user actions and
2016
+ * as echoed property pushes) into a single reload. A microtask debounces the
2017
+ * burst; a `{sort,perPage,page}` change-key skips echoes that didn't actually
2018
+ * change anything.
2019
+ */
2020
+ scheduleFetchReload() {
2021
+ !this._fetch || this._reloadScheduled || (this._reloadScheduled = !0, queueMicrotask(() => {
2022
+ if (this._reloadScheduled = !1, !this._fetch) return;
2023
+ const e = JSON.stringify({
2024
+ s: this._sortColumns,
2025
+ pp: this._perPage,
2026
+ p: this._virtualScroll ? 1 : this._page
2027
+ });
2028
+ this._initialFetchDone && e === this._lastReloadKey || (this._lastReloadKey = e, this._fetchGeneration++, this._pageCache.clear(), this._pendingPageFetches.clear(), this._childCache.clear(), this._childTotals.clear(), this._pendingFetches.clear(), this.loadPage(this._virtualScroll ? 1 : this._page));
2029
+ }));
2030
+ }
2031
+ /** Keyboard handling on a tree-mode row. Arrow keys + Enter/Space toggle expansion. */
2032
+ onRowKeydown(e, t, a, i, s, r, o, l) {
2033
+ if (!l.altKey && l.composedPath()[0] === l.currentTarget) {
2034
+ if (l.key === "ArrowDown" || l.key === "ArrowUp") {
2035
+ l.preventDefault();
2036
+ const d = Array.from(
2037
+ this.renderRoot.querySelectorAll("tbody tr[data-row-key]")
2038
+ ), c = d.findIndex((f) => f.dataset.rowKey === t), p = d[c + (l.key === "ArrowDown" ? 1 : -1)];
2039
+ p && p.focus();
2040
+ return;
2041
+ }
2042
+ if (this._tree) {
2043
+ if (l.key === "ArrowRight" && o > 0 && !r) {
2044
+ this.toggleExpand(e, i, s, l);
2045
+ return;
2046
+ }
2047
+ if (l.key === "ArrowLeft" && r) {
2048
+ this.toggleExpand(e, i, s, l);
2049
+ return;
2050
+ }
2051
+ if ((l.key === "Enter" || l.key === " ") && o > 0) {
2052
+ this.toggleExpand(e, i, s, l);
2053
+ return;
2054
+ }
2055
+ }
2056
+ (l.key === "Enter" || l.key === " ") && this._selectionMode !== "none" && (l.preventDefault(), this._focusedRowKey = t, this.handleSelectionOnClick(t, l), this.requestUpdate(), this.dispatchEvent(
2057
+ new CustomEvent("mp-datatable-row-click", {
2058
+ detail: { row: e, rowIndex: a, rowKey: t, originalEvent: l },
2059
+ bubbles: !0,
2060
+ composed: !0
2061
+ })
2062
+ ));
2063
+ }
2064
+ }
2065
+ hasRowClickListeners() {
2066
+ return !0;
2067
+ }
2068
+ onHeaderClick(e, t) {
2069
+ if (!(e.sortable ?? !0) || t.target.closest(".resize-handle")) return;
2070
+ const s = N(this._sortColumns, e.name, t.shiftKey);
2071
+ this._sortColumns = s, this._page = 1;
2072
+ const r = s.find((o) => o.property === e.name);
2073
+ this.liveAnnouncer.announce(
2074
+ this.mergedLabels.announceSorted(
2075
+ e.label ?? e.name,
2076
+ r ? r.direction === "ascending" ? "ascending" : "descending" : "none"
2077
+ )
2078
+ ), this.requestUpdate(), this.scheduleFetchReload(), this.dispatchEvent(
2079
+ new CustomEvent("mp-datatable-sort-change", {
2080
+ detail: { sortColumns: s },
2081
+ bubbles: !0,
2082
+ composed: !0
2083
+ })
2084
+ );
2085
+ }
2086
+ onRowClick(e, t, a, i) {
2087
+ i.target.closest('input[type="checkbox"]') || (this._focusedRowKey = t, this.handleSelectionOnClick(t, i), this.requestUpdate(), this.dispatchEvent(
2088
+ new CustomEvent("mp-datatable-row-click", {
2089
+ detail: { row: e, rowIndex: a, rowKey: t, originalEvent: i },
2090
+ bubbles: !0,
2091
+ composed: !0
2092
+ })
2093
+ ));
2094
+ }
2095
+ onRowDblClick(e, t, a, i) {
2096
+ this.dispatchEvent(
2097
+ new CustomEvent("mp-datatable-row-dblclick", {
2098
+ detail: { row: e, rowIndex: a, rowKey: t, originalEvent: i },
2099
+ bubbles: !0,
2100
+ composed: !0
2101
+ })
2102
+ );
2103
+ }
2104
+ onRowContextMenu(e, t, a, i) {
2105
+ this._selectionMode !== "none" && !this._selectedIds.has(t) && (this._selectedIds = /* @__PURE__ */ new Set([t]), this._focusedRowKey = t, this.emitSelectionChange(), this.requestUpdate()), this.dispatchEvent(
2106
+ new CustomEvent("mp-datatable-row-contextmenu", {
2107
+ detail: { row: e, rowIndex: a, rowKey: t, originalEvent: i },
2108
+ bubbles: !0,
2109
+ composed: !0,
2110
+ cancelable: !0
2111
+ })
2112
+ );
2113
+ }
2114
+ onRowCheckboxToggle(e, t, a, i) {
2115
+ if (this._selectionMode !== "none") {
2116
+ if (this._selectionMode === "single")
2117
+ this._selectedIds = /* @__PURE__ */ new Set([t]);
2118
+ else {
2119
+ const s = new Set(this._selectedIds), r = !s.has(t);
2120
+ if (r ? s.add(t) : s.delete(t), this._tree && this._selectionStrategy === "cascading" && e != null) {
2121
+ const o = this.collectDescendantKeys(e);
2122
+ if (r)
2123
+ for (const l of o) s.add(l);
2124
+ else
2125
+ for (const l of o) s.delete(l);
2126
+ }
2127
+ this._selectedIds = s;
2128
+ }
2129
+ this.emitSelectionChange(), this.requestUpdate();
2130
+ }
2131
+ }
2132
+ /**
2133
+ * Clears the entire selection. The header checkbox is only rendered when
2134
+ * at least one row is selected — a true "select all" affordance would be
2135
+ * misleading because the WC doesn't know about rows outside the current
2136
+ * pagination slice or virtual-scroll window. Click semantics are
2137
+ * therefore one-way: visible → deselect-all → hidden again.
2138
+ */
2139
+ onDeselectAll() {
2140
+ this._selectedIds.size !== 0 && (this._selectedIds = /* @__PURE__ */ new Set(), this.emitSelectionChange(), this.requestUpdate());
2141
+ }
2142
+ handleSelectionOnClick(e, t) {
2143
+ if (this._selectionMode !== "none") {
2144
+ if (this._selectionMode === "single") {
2145
+ this._selectedIds = /* @__PURE__ */ new Set([e]), this.emitSelectionChange();
2146
+ return;
2147
+ }
2148
+ if (t.shiftKey && this._selectionAnchorKey && this._selectionAnchorKey !== e) {
2149
+ const a = this.computeVisibleRows(), i = a.findIndex((r) => r.key === this._selectionAnchorKey), s = a.findIndex((r) => r.key === e);
2150
+ if (i >= 0 && s >= 0) {
2151
+ const [r, o] = i < s ? [i, s] : [s, i], l = a.slice(r, o + 1).map((d) => d.key);
2152
+ this._selectedIds = /* @__PURE__ */ new Set([...this._selectedIds, ...l]), this.emitSelectionChange();
2153
+ return;
2154
+ }
2155
+ }
2156
+ if (t.ctrlKey || t.metaKey) {
2157
+ const a = new Set(this._selectedIds);
2158
+ a.has(e) ? a.delete(e) : a.add(e), this._selectedIds = a, this._selectionAnchorKey = e, this.emitSelectionChange();
2159
+ return;
2160
+ }
2161
+ this._selectedIds = /* @__PURE__ */ new Set([e]), this._selectionAnchorKey = e, this.emitSelectionChange();
2162
+ }
2163
+ }
2164
+ emitSelectionChange() {
2165
+ const e = [...this._selectedIds];
2166
+ this.liveAnnouncer.announce(this.mergedLabels.announceSelection(e.length)), this.dispatchEvent(
2167
+ new CustomEvent("mp-datatable-selection-change", {
2168
+ detail: { selectedIds: e, selectedRows: this.resolveRows(e) },
2169
+ bubbles: !0,
2170
+ composed: !0
2171
+ })
2172
+ );
2173
+ }
2174
+ /**
2175
+ * Resolve row keys → row objects across every loaded source (page-1 `_data`,
2176
+ * fetched windows in `_pageCache`, tree children in `_childCache`). One pass
2177
+ * builds a key→row index; unresolvable ids are skipped.
2178
+ */
2179
+ resolveRows(e) {
2180
+ if (e.length === 0) return [];
2181
+ const t = /* @__PURE__ */ new Map(), a = (i) => {
2182
+ for (const s of i) t.set(this._rowKey(s, -1), s);
2183
+ };
2184
+ a(this._data);
2185
+ for (const i of this._pageCache.values()) a(i);
2186
+ for (const i of this._childCache.values()) a(i);
2187
+ return e.map((i) => t.get(i)).filter((i) => i !== void 0);
2188
+ }
2189
+ gotoPage(e) {
2190
+ const t = this._totalRecords ?? this._data.length, a = Math.max(1, Math.ceil(t / this._perPage));
2191
+ this._page = Math.max(1, Math.min(a, e)), this.liveAnnouncer.announce(this.mergedLabels.announcePage(this._page, a)), this.requestUpdate(), this.scheduleFetchReload(), this.dispatchEvent(
2192
+ new CustomEvent("mp-datatable-page-change", {
2193
+ detail: { page: this._page },
2194
+ bubbles: !0,
2195
+ composed: !0
2196
+ })
2197
+ );
2198
+ }
2199
+ /**
2200
+ * Keyboard column resize — the same ±px model as the pointer path, same 40px
2201
+ * floor. The handle is a focusable role="separator"; without this it was the
2202
+ * audit's pointer-only finding for the datatable.
2203
+ */
2204
+ onResizeHandleKeydown(e, t) {
2205
+ if (!this._resizableColumns || t.key !== "ArrowLeft" && t.key !== "ArrowRight") return;
2206
+ t.preventDefault(), t.stopPropagation();
2207
+ const i = t.currentTarget.closest("th"), s = this._columnWidths.get(e.name) ?? i?.getBoundingClientRect().width ?? 100, r = Math.max(40, s + (t.key === "ArrowRight" ? 10 : -10));
2208
+ this._columnWidths = new Map(this._columnWidths), this._columnWidths.set(e.name, r), this.requestUpdate();
2209
+ }
2210
+ startColumnResize(e, t) {
2211
+ if (!this._resizableColumns) return;
2212
+ t.preventDefault(), t.stopPropagation();
2213
+ const a = t.currentTarget, i = a.closest("th");
2214
+ if (!i) return;
2215
+ const s = i.getBoundingClientRect().width;
2216
+ this.resizeState = { columnName: e.name, startX: t.clientX, startWidth: s, handle: a }, a.classList.add("active"), a.setPointerCapture(t.pointerId), a.addEventListener("pointermove", this.onColumnResizeMove), a.addEventListener("pointerup", this.onColumnResizeEnd), a.addEventListener("pointercancel", this.onColumnResizeEnd);
2217
+ }
2218
+ }
2219
+ function G(n, e) {
2220
+ if (n == null || typeof n != "object") return "";
2221
+ const t = n[e.name];
2222
+ return t == null ? "" : String(t);
2223
+ }
2224
+ function j(n) {
2225
+ return n != null && typeof n != "string" && typeof n[Symbol.iterator] == "function";
2226
+ }
2227
+ function w(n) {
2228
+ return n == null || n === !1 ? u : (n instanceof Node || typeof n == "object" && "_$litType$" in n, n);
2229
+ }
2230
+ M("datatable", D);
2231
+ typeof customElements < "u" && !customElements.get("mp-datatable") && customElements.define("mp-datatable", V);
2232
+ export {
2233
+ O as D,
2234
+ V as M,
2235
+ N as c,
2236
+ D as d,
2237
+ y as s
2238
+ };