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