@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
@@ -1,1400 +0,0 @@
1
- import { unsafeCSS as x, LitElement as C, nothing as h } from "lit";
2
- import { s as R, i as S } from "./install-light-styles-DbCAGFOC.mjs";
3
- import { L as $ } from "./live-announcer-Bi0orG4n.mjs";
4
- import { a as I, F as P } from "./focus-restore-DxuP1Oe2.mjs";
5
- import { H as E } from "./host-aria-WSGs7SPQ.mjs";
6
- import { repeat as M } from "lit/directives/repeat.js";
7
- import { styleMap as b } from "lit/directives/style-map.js";
8
- import "./mp-pagination-Dea75mD4.mjs";
9
- import "./mp-checkbox-CzwS7Y_t.mjs";
10
- const K = {
11
- treeChevronColumn: "Expand or collapse",
12
- deselectAll: "Deselect all",
13
- selectAll: "Select all",
14
- expandRow: "Expand row",
15
- collapseRow: "Collapse row",
16
- loading: "Loading",
17
- rowsPerPage: "Rows per page",
18
- resizeColumn: (l) => `Resize column ${l}`,
19
- selectRow: (l) => `Select row ${l}`,
20
- announceSorted: (l, t) => t === "none" ? `Sorting removed from ${l}` : `Sorted by ${l}, ${t}`,
21
- announcePage: (l, t) => `Page ${l} of ${t}`,
22
- announceSelection: (l) => l === 1 ? "1 row selected" : `${l} rows selected`,
23
- announceLoaded: (l) => l === 1 ? "Loaded 1 row" : `Loaded ${l} rows`
24
- }, z = x(`@charset "UTF-8";
25
- mp-datatable {
26
- display: block;
27
- width: 100%;
28
- position: relative;
29
- --mp-datatable-border-color: var(--bs-border-color, rgba(0, 0, 0, 0.125));
30
- --mp-datatable-row-hover-bg: var(--bs-table-hover-bg, rgba(0, 0, 0, 0.04));
31
- --mp-datatable-row-selected-bg: var(--bs-list-group-active-bg, var(--bs-primary, #0d6efd));
32
- --mp-datatable-row-selected-color: var(--bs-list-group-active-color, #fff);
33
- --mp-datatable-cut-opacity: 0.55;
34
- --mp-datatable-resize-handle-color: var(--bs-primary, #0d6efd);
35
- }
36
-
37
- [data-mps=datatable] {
38
- box-sizing: border-box;
39
- }
40
-
41
- .datatable-shell[data-mps=datatable] {
42
- display: flex;
43
- flex-direction: column;
44
- width: 100%;
45
- height: 100%;
46
- }
47
-
48
- .datatable-scroll[data-mps=datatable] {
49
- overflow: auto;
50
- flex: 1 1 auto;
51
- }
52
-
53
- .datatable-scroll.datatable-virtual[data-mps=datatable] {
54
- max-height: var(--mp-datatable-virtual-max-height, 480px);
55
- }
56
- .datatable-scroll.datatable-virtual[data-mps=datatable] thead[data-mps=datatable] th[data-mps=datatable] {
57
- position: sticky;
58
- top: 0;
59
- z-index: 1;
60
- background-color: var(--bs-body-bg, #fff);
61
- }
62
- .datatable-scroll.datatable-virtual[data-mps=datatable] thead[data-mps=datatable] th[data-sortable=true]:hover[data-mps=datatable] {
63
- background-color: var(--bs-body-bg, #fff);
64
- background-image: linear-gradient(var(--mp-datatable-row-hover-bg), var(--mp-datatable-row-hover-bg));
65
- }
66
-
67
- tr.virtual-spacer[data-mps=datatable] {
68
- pointer-events: none;
69
- }
70
- tr.virtual-spacer[data-mps=datatable] > td {
71
- border-bottom: 0;
72
- }
73
-
74
- table[data-mps=datatable] {
75
- width: 100%;
76
- border-collapse: collapse;
77
- margin: 0;
78
- table-layout: auto;
79
- }
80
-
81
- table.measured[data-mps=datatable] {
82
- table-layout: fixed;
83
- }
84
- tbody[data-mps=datatable] > tr[data-mps=datatable] > td {
85
- white-space: nowrap;
86
- overflow: hidden;
87
- text-overflow: ellipsis;
88
- }
89
-
90
- thead[data-mps=datatable] th[data-mps=datatable] {
91
- background-color: var(--bs-table-bg, transparent);
92
- border-bottom: 1px solid var(--mp-datatable-border-color);
93
- text-align: left;
94
- font-weight: 600;
95
- padding: 0.5rem 0.75rem;
96
- white-space: nowrap;
97
- position: relative;
98
- user-select: none;
99
- }
100
-
101
- thead[data-mps=datatable] th[data-sortable=true][data-mps=datatable] {
102
- cursor: pointer;
103
- padding-right: 2rem;
104
- }
105
- thead[data-mps=datatable] th[data-sortable=true][data-mps=datatable]::before, thead[data-mps=datatable] th[data-sortable=true][data-mps=datatable]::after {
106
- position: absolute;
107
- display: block;
108
- opacity: 0.3;
109
- bottom: 0.5em;
110
- }
111
- thead[data-mps=datatable] th[data-sortable=true][data-mps=datatable]::before {
112
- content: "↑";
113
- right: 1em;
114
- }
115
- thead[data-mps=datatable] th[data-sortable=true][data-mps=datatable]::after {
116
- content: "↓";
117
- right: 0.5em;
118
- }
119
- thead[data-mps=datatable] th[data-sortable=true][aria-sort=ascending][data-mps=datatable]::after {
120
- opacity: 1;
121
- }
122
- thead[data-mps=datatable] th[data-sortable=true][aria-sort=descending][data-mps=datatable]::before {
123
- opacity: 1;
124
- }
125
-
126
- thead[data-mps=datatable] th[data-sortable=true]:hover[data-mps=datatable] {
127
- background-color: var(--mp-datatable-row-hover-bg);
128
- }
129
-
130
- .header-cell[data-mps=datatable] {
131
- display: inline-flex;
132
- align-items: center;
133
- gap: 0.4rem;
134
- }
135
-
136
- button.header-sort[data-mps=datatable] {
137
- border: 0;
138
- padding: 0;
139
- margin: 0;
140
- background: none;
141
- font: inherit;
142
- color: inherit;
143
- text-align: inherit;
144
- cursor: pointer;
145
- }
146
-
147
- .resize-handle:focus-visible[data-mps=datatable],
148
- button.header-sort:focus-visible[data-mps=datatable] {
149
- outline: 2px solid var(--mp-datatable-resize-handle-color);
150
- outline-offset: 1px;
151
- }
152
-
153
- tbody[data-mps=datatable] tr:focus-visible[data-mps=datatable] {
154
- outline: 2px solid var(--mp-datatable-resize-handle-color);
155
- outline-offset: -2px;
156
- }
157
-
158
- .sort-index[data-mps=datatable] {
159
- position: absolute;
160
- right: 0.1em;
161
- bottom: 0.3em;
162
- font-size: 0.65em;
163
- font-weight: bold;
164
- opacity: 0.7;
165
- }
166
-
167
- .resize-handle[data-mps=datatable] {
168
- position: absolute;
169
- right: 0;
170
- top: 0;
171
- width: 6px;
172
- height: 100%;
173
- cursor: col-resize;
174
- user-select: none;
175
- z-index: 2;
176
- }
177
-
178
- .resize-handle:hover[data-mps=datatable],
179
- .resize-handle.active[data-mps=datatable] {
180
- background-color: var(--mp-datatable-resize-handle-color);
181
- }
182
- tbody[data-mps=datatable] > tr[data-mps=datatable] > td {
183
- padding: 0.5rem 0.75rem;
184
- border-bottom: 1px solid var(--mp-datatable-border-color);
185
- vertical-align: middle;
186
- }
187
- tbody[data-mps=datatable] > tr[data-mps=datatable] > td svg,
188
- tbody[data-mps=datatable] > tr[data-mps=datatable] > td img {
189
- max-width: var(--mp-datatable-cell-media-max-width, none);
190
- height: auto;
191
- vertical-align: middle;
192
- }
193
-
194
- tbody[data-mps=datatable] tr[data-mps=datatable] {
195
- cursor: default;
196
- }
197
-
198
- tbody[data-mps=datatable] tr[data-clickable=true][data-mps=datatable] {
199
- cursor: pointer;
200
- }
201
-
202
- tbody[data-mps=datatable] tr:hover[data-mps=datatable] {
203
- background-color: var(--mp-datatable-row-hover-bg);
204
- }
205
-
206
- tbody[data-mps=datatable] tr[data-selected=true][data-mps=datatable] {
207
- background-color: var(--mp-datatable-row-selected-bg);
208
- color: var(--mp-datatable-row-selected-color);
209
- }
210
-
211
- tbody[data-mps=datatable] tr[data-cut=true][data-mps=datatable] {
212
- opacity: var(--mp-datatable-cut-opacity);
213
- }
214
-
215
- tbody[data-mps=datatable] tr[data-focused=true][data-mps=datatable] {
216
- outline: 2px solid var(--bs-primary, #0d6efd);
217
- outline-offset: -2px;
218
- }
219
- tr[data-mps=datatable] > .checkbox-cell[data-mps=datatable] {
220
- width: 2.5rem;
221
- padding-inline: 0.5rem;
222
- text-align: center;
223
- text-overflow: clip;
224
- }
225
-
226
- .tree-chevron-cell[data-mps=datatable] {
227
- width: 2rem;
228
- padding-right: 0;
229
- white-space: nowrap;
230
- user-select: none;
231
- }
232
-
233
- .tree-chevron[data-mps=datatable] {
234
- appearance: none;
235
- background: transparent;
236
- border: 0;
237
- padding: 0;
238
- width: 1.5rem;
239
- height: 1.5rem;
240
- line-height: 1;
241
- cursor: pointer;
242
- color: var(--bs-body-color, inherit);
243
- font-size: 0.85em;
244
- border-radius: 0.25rem;
245
- display: inline-flex;
246
- align-items: center;
247
- justify-content: center;
248
- }
249
- .tree-chevron:hover[data-mps=datatable] {
250
- background-color: var(--mp-datatable-row-hover-bg);
251
- }
252
- .tree-chevron:focus-visible[data-mps=datatable] {
253
- outline: 2px solid var(--bs-primary, #0d6efd);
254
- outline-offset: 1px;
255
- }
256
-
257
- tbody[data-mps=datatable] tr[data-placeholder=true][data-mps=datatable] {
258
- cursor: default;
259
- opacity: 0.6;
260
- pointer-events: none;
261
- }
262
-
263
- .tree-placeholder-cell[data-mps=datatable] {
264
- color: var(--bs-secondary-color, #6c757d);
265
- font-style: italic;
266
- padding-left: 1.25rem;
267
- }
268
-
269
- .empty-state[data-mps=datatable],
270
- .loading-state[data-mps=datatable] {
271
- padding: 2rem 1rem;
272
- text-align: center;
273
- color: var(--bs-secondary-color, #6c757d);
274
- }
275
-
276
- .datatable-footer[data-mps=datatable] {
277
- display: flex;
278
- align-items: center;
279
- justify-content: space-between;
280
- padding: 0.5rem 0;
281
- gap: 1rem;
282
- flex-wrap: wrap;
283
- flex: 0 0 auto;
284
- }
285
-
286
- .datatable-per-page[data-mps=datatable],
287
- .datatable-pagination[data-mps=datatable] {
288
- flex: 0 1 auto;
289
- }
290
-
291
- @media (prefers-reduced-motion: reduce) {
292
- .resize-handle[data-mps=datatable] {
293
- transition: none !important;
294
- }
295
- }`);
296
- function L(l, t, e) {
297
- if (e) {
298
- const a = l.findIndex((i) => i.property === t);
299
- return a === -1 ? [...l, { property: t, direction: "ascending" }] : l[a].direction === "ascending" ? l.map(
300
- (i, r) => r === a ? { ...i, direction: "descending" } : i
301
- ) : l.filter((i, r) => r !== a);
302
- }
303
- const s = l.length === 1 && l[0].property === t;
304
- return [
305
- {
306
- property: t,
307
- direction: s && l[0].direction === "ascending" ? "descending" : "ascending"
308
- }
309
- ];
310
- }
311
- function _(l, t) {
312
- return t.length === 0 ? l.slice() : l.map((e, s) => ({ row: e, index: s })).sort((e, s) => {
313
- for (const a of t) {
314
- const i = w(e.row, a.property), r = w(s.row, a.property), o = k(i, r);
315
- if (o !== 0)
316
- return a.direction === "ascending" ? o : -o;
317
- }
318
- return e.index - s.index;
319
- }).map(({ row: e }) => e);
320
- }
321
- function w(l, t) {
322
- if (!(l == null || typeof l != "object"))
323
- return l[t];
324
- }
325
- function k(l, t) {
326
- return l === t ? 0 : l == null ? 1 : t == null ? -1 : typeof l == "number" && typeof t == "number" ? l - t : l instanceof Date && t instanceof Date ? l.getTime() - t.getTime() : String(l).localeCompare(String(t));
327
- }
328
- const c = R("datatable");
329
- let A = 0;
330
- class F extends C {
331
- constructor() {
332
- super(...arguments), this.instanceId = `mp-datatable-${++A}`, this._caption = null, this._inputLabel = null, this.hostAria = new E(this, {
333
- referenceTarget: () => this.renderRoot?.querySelector("table") ?? null
334
- }), 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 $(this), this.rowFocusRestore = new I(this, new P(
335
- () => this.renderRoot ?? null,
336
- {
337
- selector: 'tbody tr[data-row-key]:not([data-placeholder="true"])',
338
- keyOf: (t) => t.dataset.rowKey ?? null,
339
- container: () => this.renderRoot?.querySelector("table") ?? null
340
- }
341
- )), this._rowKey = (t, e) => {
342
- const s = t;
343
- return s && s.id != null ? String(s.id) : `row-${e}`;
344
- }, 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._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._selectionAnchorKey = null, this.resizeState = null, this.onColumnResizeMove = (t) => {
345
- if (!this.resizeState) return;
346
- const e = t.clientX - this.resizeState.startX, s = Math.max(40, this.resizeState.startWidth + e);
347
- this._columnWidths = new Map(this._columnWidths), this._columnWidths.set(this.resizeState.columnName, s), this.requestUpdate();
348
- }, this.onColumnResizeEnd = (t) => {
349
- if (this.resizeState) {
350
- 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);
351
- try {
352
- this.resizeState.handle.releasePointerCapture(t.pointerId);
353
- } catch {
354
- }
355
- this.resizeState = null;
356
- }
357
- };
358
- }
359
- /**
360
- * Light DOM. Consumer-authored row/cell/header content is mounted here by the
361
- * render callbacks, and inside a shadow root the page's stylesheets — the
362
- * consumer's own component CSS and Bootstrap's utilities alike — cannot reach
363
- * it (issue #408). Rendering in the document tree is what makes that content
364
- * style correctly; encapsulation is preserved by the build-time rescoping
365
- * instead of by the boundary.
366
- */
367
- createRenderRoot() {
368
- return this;
369
- }
370
- static get observedAttributes() {
371
- return [
372
- ...super.observedAttributes ?? [],
373
- "selection-mode",
374
- "pagination",
375
- "resizable-columns",
376
- "auto-sort",
377
- "empty-message",
378
- "virtual-scroll",
379
- "item-size",
380
- "tree",
381
- "tree-indent",
382
- "selection-strategy",
383
- // Naming for the inner <table> (the role-bearing node): caption renders a
384
- // real <caption>, the native, visible table name; aria-label / input-label
385
- // are the invisible alternative and win in the accessible-name computation
386
- // when both are present.
387
- "caption",
388
- "aria-label",
389
- "input-label",
390
- "aria-labelledby",
391
- "aria-describedby"
392
- ];
393
- }
394
- /**
395
- * Visible table caption, rendered as a real <caption> — the native way to name
396
- * a table, and the only one sighted users benefit from too. For an invisible
397
- * name use aria-label / input-label instead (they win over the caption in the
398
- * accessible-name computation when both are set).
399
- */
400
- get caption() {
401
- return this._caption;
402
- }
403
- set caption(t) {
404
- const e = t ?? null;
405
- this._caption !== e && (this._caption = e, this.requestUpdate());
406
- }
407
- /** Merged view of labels — consumer keys over the English defaults. */
408
- get mergedLabels() {
409
- return { ...K, ...this.labels ?? {} };
410
- }
411
- /** Optional invisible accessible name for the <table>. Host aria-label wins. */
412
- get inputLabel() {
413
- return this._inputLabel;
414
- }
415
- set inputLabel(t) {
416
- const e = t ?? null;
417
- this._inputLabel !== e && (this._inputLabel = e, this.requestUpdate());
418
- }
419
- /** When true, the WC sorts `data` itself using `sortRows`. Set `false` if the consumer sorts externally. */
420
- get autoSort() {
421
- return this._autoSort;
422
- }
423
- set autoSort(t) {
424
- this._autoSort = !!t, this.requestUpdate();
425
- }
426
- /**
427
- * Per-row renderer. When set, the WC delegates row content production to
428
- * this callback (used by the Angular wrapper to host `*bsRowTemplate`
429
- * templates). Returning `undefined` falls back to per-column `cellRenderer`s.
430
- */
431
- get rowRenderer() {
432
- return this._rowRenderer;
433
- }
434
- set rowRenderer(t) {
435
- this._rowRenderer = t, this.requestUpdate();
436
- }
437
- /** Enable scroll-position-driven virtualization. Rows outside the viewport are not rendered. */
438
- get virtualScroll() {
439
- return this._virtualScroll;
440
- }
441
- set virtualScroll(t) {
442
- const e = !!t;
443
- this._virtualScroll !== e && (this._virtualScroll = e, this.requestUpdate());
444
- }
445
- /** Approximate row height in px (used by virtual scroll). Default `40`. */
446
- get itemSize() {
447
- return this._itemSize;
448
- }
449
- set itemSize(t) {
450
- const e = Math.max(1, Math.floor(t || 0)) || 40;
451
- this._itemSize !== e && (this._itemSize = e, this.requestUpdate());
452
- }
453
- /** Off-screen row buffer (each side) for virtual scrolling. */
454
- get virtualBuffer() {
455
- return this._virtualBuffer;
456
- }
457
- set virtualBuffer(t) {
458
- const e = Math.max(0, Math.floor(t || 0));
459
- this._virtualBuffer !== e && (this._virtualBuffer = e, this.requestUpdate());
460
- }
461
- get columns() {
462
- return this._columns;
463
- }
464
- set columns(t) {
465
- this._columns = Array.isArray(t) ? t : [], this.requestUpdate();
466
- }
467
- get data() {
468
- return this._data;
469
- }
470
- set data(t) {
471
- this._data = Array.isArray(t) ? t : [], this.requestUpdate();
472
- }
473
- /**
474
- * High-level fetch callback. When set, the WC owns the entire server-paged
475
- * loop and the consumer provides nothing else — no page-1 seeding via `data`,
476
- * no separate `totalRecords`, no event bridge. Works with any framework or
477
- * none (`el.fetch = fn`). Setting it kicks off the initial page-1 load.
478
- */
479
- get fetch() {
480
- return this._fetch;
481
- }
482
- set fetch(t) {
483
- this._fetch = typeof t == "function" ? t : null, this._fetch && (this._autoSort = !1, this._initialFetchDone = !1, this._lastReloadKey = null, this.scheduleFetchReload());
484
- }
485
- get sortColumns() {
486
- return [...this._sortColumns];
487
- }
488
- set sortColumns(t) {
489
- this._sortColumns = Array.isArray(t) ? [...t] : [], this.requestUpdate(), this.scheduleFetchReload();
490
- }
491
- get selectionMode() {
492
- return this._selectionMode;
493
- }
494
- set selectionMode(t) {
495
- this._selectionMode = t, t === "none" && this._selectedIds.clear(), this.requestUpdate();
496
- }
497
- get selectedIds() {
498
- return [...this._selectedIds];
499
- }
500
- set selectedIds(t) {
501
- this._selectedIds = new Set(t ?? []), this.requestUpdate();
502
- }
503
- get cutIds() {
504
- return [...this._cutIds];
505
- }
506
- set cutIds(t) {
507
- this._cutIds = new Set(t ?? []), this.requestUpdate();
508
- }
509
- get focusedRowKey() {
510
- return this._focusedRowKey;
511
- }
512
- set focusedRowKey(t) {
513
- this._focusedRowKey = t, this.requestUpdate();
514
- }
515
- get rowKey() {
516
- return this._rowKey;
517
- }
518
- set rowKey(t) {
519
- this._rowKey = typeof t == "function" ? t : this._rowKey, this.requestUpdate();
520
- }
521
- // ─── Tree-mode public API ────────────────────────────────────────────────
522
- /** Enable tree mode (chevron column, nested expansion, lazy children). */
523
- get tree() {
524
- return this._tree;
525
- }
526
- set tree(t) {
527
- const e = !!t;
528
- this._tree !== e && (this._tree = e, this.requestUpdate());
529
- }
530
- /**
531
- * Property name or function that extracts the stable row identity used as
532
- * the expansion key and as `parentId` in `mp-datatable-fetch-request`.
533
- * Required when `tree=true`.
534
- */
535
- get idKey() {
536
- return this._idKey;
537
- }
538
- set idKey(t) {
539
- this._idKey = t, this.requestUpdate();
540
- }
541
- /**
542
- * Property name on the row that holds the direct-child count. Drives both
543
- * chevron visibility AND placeholder reservation. Required when `tree=true`.
544
- */
545
- get childCountKey() {
546
- return this._childCountKey;
547
- }
548
- set childCountKey(t) {
549
- this._childCountKey = t || null, this.requestUpdate();
550
- }
551
- /** Indent in rem per depth level on the chevron cell. Default `1.25`. */
552
- get treeIndent() {
553
- return this._treeIndent;
554
- }
555
- set treeIndent(t) {
556
- const e = Number(t);
557
- this._treeIndent = Number.isFinite(e) && e >= 0 ? e : 1.25, this.requestUpdate();
558
- }
559
- /** Two-way binding target: set of expanded-row id values (per `idKey`). */
560
- get expandedIds() {
561
- return new Set(this._expandedIds);
562
- }
563
- set expandedIds(t) {
564
- t ? t instanceof Set ? this._expandedIds = new Set(t) : this._expandedIds = new Set(t) : this._expandedIds = /* @__PURE__ */ new Set(), this.requestUpdate();
565
- }
566
- /** `'flat'` (default) or `'cascading'`. When `tree=true`, cascading is recommended. */
567
- get selectionStrategy() {
568
- return this._selectionStrategy;
569
- }
570
- set selectionStrategy(t) {
571
- this._selectionStrategy = t === "cascading" ? "cascading" : "flat", this.requestUpdate();
572
- }
573
- get loading() {
574
- return this._loading;
575
- }
576
- set loading(t) {
577
- const e = this._loading;
578
- this._loading = !!t, e && !this._loading && this.liveAnnouncer.announce(this.mergedLabels.announceLoaded(this._data.length)), this.requestUpdate();
579
- }
580
- get emptyMessage() {
581
- return this._emptyMessage;
582
- }
583
- set emptyMessage(t) {
584
- this._emptyMessage = t || "No data", this.requestUpdate();
585
- }
586
- get pagination() {
587
- return this._pagination;
588
- }
589
- set pagination(t) {
590
- this._pagination = !!t, this.requestUpdate();
591
- }
592
- get page() {
593
- return this._page;
594
- }
595
- set page(t) {
596
- const e = Math.max(1, Math.floor(t || 1));
597
- this._page !== e && (this._page = e, this.requestUpdate(), this.scheduleFetchReload());
598
- }
599
- get perPage() {
600
- return this._perPage;
601
- }
602
- set perPage(t) {
603
- const e = Math.max(1, Math.floor(t || 1));
604
- this._perPage !== e && (this._perPage = e, this._page = 1, this.requestUpdate(), this.scheduleFetchReload());
605
- }
606
- get perPageOptions() {
607
- return [...this._perPageOptions];
608
- }
609
- set perPageOptions(t) {
610
- this._perPageOptions = Array.isArray(t) && t.length > 0 ? [...t] : [10, 20, 50], this.requestUpdate();
611
- }
612
- /**
613
- * Read-only grand total. Derived by the WC from the `fetch` response (server
614
- * paging) or `_data.length` (static data) — consumers never set it. Exposed
615
- * so a consumer can render "row X of N" if it wants.
616
- */
617
- get totalRecords() {
618
- return this._totalRecords;
619
- }
620
- /** True when the consumer is paging externally (totalRecords exceeds the in-memory rows). */
621
- isExternallyPaged() {
622
- return this._totalRecords != null && this._totalRecords > this._data.length;
623
- }
624
- /**
625
- * True when virtual scrolling is driving lazy windowed fetches at the **root**
626
- * level: the consumer pages externally and the WC pulls root pages ≥ 2 on
627
- * demand. Applies to BOTH flat mode (the rows are the roots) and tree mode
628
- * (the top-level rows; their children are windowed separately, keyed by
629
- * parentId). When false (single page or no virtual scroll) the WC falls back
630
- * to the trivial mapping of `_data`.
631
- */
632
- isRootWindowed() {
633
- return this._virtualScroll && this.isExternallyPaged();
634
- }
635
- attributeChangedCallback(t, e, s) {
636
- if (super.attributeChangedCallback(t, e, s), t === "caption")
637
- this._caption = s, this.requestUpdate();
638
- else if (t === "input-label")
639
- this._inputLabel = s, this.requestUpdate();
640
- else if (t === "aria-label")
641
- this.requestUpdate();
642
- else if (t === "aria-labelledby" || t === "aria-describedby")
643
- this.hostAria.syncReferences();
644
- else if (t === "selection-mode") {
645
- const a = s;
646
- (a === "none" || a === "single" || a === "multiple") && (this.selectionMode = a);
647
- } else if (t === "pagination")
648
- this.pagination = s !== null;
649
- else if (t === "resizable-columns")
650
- this.resizableColumns = s !== null;
651
- else if (t === "auto-sort")
652
- this.autoSort = s !== "false";
653
- else if (t === "empty-message")
654
- this.emptyMessage = s ?? "No data";
655
- else if (t === "virtual-scroll")
656
- this.virtualScroll = s !== null;
657
- else if (t === "item-size") {
658
- const a = Number(s);
659
- Number.isFinite(a) && (this.itemSize = a);
660
- } else if (t === "tree")
661
- this.tree = s !== null;
662
- else if (t === "tree-indent") {
663
- const a = Number(s);
664
- Number.isFinite(a) && (this.treeIndent = a);
665
- } else t === "selection-strategy" && (this.selectionStrategy = s === "cascading" ? "cascading" : "flat");
666
- }
667
- get resizableColumns() {
668
- return this._resizableColumns;
669
- }
670
- set resizableColumns(t) {
671
- this._resizableColumns = !!t, this.requestUpdate();
672
- }
673
- connectedCallback() {
674
- super.connectedCallback();
675
- }
676
- firstUpdated() {
677
- 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();
678
- }
679
- willUpdate(t) {
680
- super.willUpdate(t), this._cachedFlatList = null, this._cachedIndeterminateKeys = null;
681
- }
682
- updated(t) {
683
- super.updated(t), this.refreshVirtualRange(), this.maybeMeasureInitialColumnWidths();
684
- const e = this.renderRoot?.querySelectorAll(".resize-handle:not([aria-valuenow])") ?? [];
685
- for (const s of e) {
686
- const a = s.closest("th");
687
- a && s.setAttribute("aria-valuenow", String(Math.round(a.getBoundingClientRect().width)));
688
- }
689
- }
690
- /**
691
- * Run the auto-size-once pass after the first batch of rows lands in the
692
- * DOM. Columns with an explicit `col.width` are pinned to that value
693
- * without measurement; the rest are measured from their natural
694
- * (`table-layout: auto`) width via `getBoundingClientRect()` on the
695
- * `<th>`. Once any column gets a width, `_hasMeasuredInitial` flips and
696
- * the table renders with `table-layout: fixed` so the widths are
697
- * authoritative and overflowing content clips with ellipsis.
698
- */
699
- maybeMeasureInitialColumnWidths() {
700
- 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;
701
- const e = new Map(this._columnWidths);
702
- let s = !1;
703
- for (const a of this._columns) {
704
- if (e.has(a.name)) continue;
705
- if (typeof a.width == "number") {
706
- e.set(a.name, a.width), s = !0;
707
- continue;
708
- }
709
- const i = this.measureColumnWidth(a.name);
710
- i != null && (e.set(a.name, i), s = !0);
711
- }
712
- s && (this._columnWidths = e, this._hasMeasuredInitial = !0, this.requestUpdate());
713
- }
714
- measureColumnWidth(t) {
715
- if (!this.renderRoot) return null;
716
- const e = this.renderRoot.querySelector(`th[data-column="${t}"]`);
717
- if (!e) return null;
718
- const s = Math.ceil(e.getBoundingClientRect().width);
719
- return s > 0 ? s : null;
720
- }
721
- disconnectedCallback() {
722
- super.disconnectedCallback(), this._scrollElement && this._scrollListener && this._scrollElement.removeEventListener("scroll", this._scrollListener), this._scrollListener = null, this._resizeObserver?.disconnect(), this._resizeObserver = null, this._scrollElement = null;
723
- }
724
- refreshVirtualRange() {
725
- if (!this._virtualScroll || !this._scrollElement) return;
726
- const t = this._scrollElement.scrollTop, e = this._scrollElement.clientHeight;
727
- this._viewportHeight = e;
728
- const s = this.getEffectiveData().length, a = this._itemSize, i = Math.max(0, Math.floor(t / a) - this._virtualBuffer), r = Math.ceil(e / a), o = Math.min(s, i + r + this._virtualBuffer * 2);
729
- (i !== this._virtualRange.startIndex || o !== this._virtualRange.endIndex) && (this._virtualRange = { startIndex: i, endIndex: o }, this.requestUpdate()), this._tree && this.maybeFetchPlaceholdersInViewport(), this.isRootWindowed() && this.maybeFetchPagesInViewport();
730
- }
731
- /**
732
- * Walk the visible viewport for placeholder rows whose parent isn't cached
733
- * and isn't already in-flight. Emit a fetch-request per such parent.
734
- */
735
- maybeFetchPlaceholdersInViewport() {
736
- const t = this.getFlatList(), { startIndex: e, endIndex: s } = this._virtualRange, a = this._virtualScroll ? e : 0, i = this._virtualScroll ? s : t.length, r = /* @__PURE__ */ new Set();
737
- for (let o = a; o < i; o++) {
738
- const n = t[o];
739
- !n.isPlaceholder || n.parentId == null || this._childCache.has(n.parentId) || this._pendingFetches.has(n.parentId) || r.add(n.parentId);
740
- }
741
- for (const o of r) this.fetchChildren(o);
742
- }
743
- /**
744
- * Flat-window counterpart of `maybeFetchPlaceholdersInViewport`: scan the
745
- * visible range for flat placeholder rows, collect the distinct pages they
746
- * belong to that aren't cached or already in-flight, and request each once.
747
- * Page 1 is never requested here — it lives in `_data` (seeded by the
748
- * wrapper's first-page fetch).
749
- */
750
- maybeFetchPagesInViewport() {
751
- const t = this.getFlatList(), { startIndex: e, endIndex: s } = this._virtualRange, a = this._virtualScroll ? e : 0, i = this._virtualScroll ? s : t.length, r = /* @__PURE__ */ new Set();
752
- for (let o = a; o < i; o++) {
753
- const n = t[o];
754
- !n.isPlaceholder || n.page == null || n.page <= 1 || this._pageCache.has(n.page) || this._pendingPageFetches.has(n.page) || r.add(n.page);
755
- }
756
- for (const o of r) this.fetchWindowPage(o);
757
- }
758
- render() {
759
- const t = this.computeVisibleRows(), e = this._totalRecords ?? this._data.length, s = this.pagination && !this._tree ? Math.max(1, Math.ceil(e / this._perPage)) : 1, a = this._selectionMode === "multiple", i = this._columns.length + (a ? 1 : 0) + (this._tree ? 1 : 0), r = this.getVirtualSpacerHeights(), o = (this._tree || this.isRootWindowed() ? this.getFlatList().length : this._data.length) + 1;
760
- return c`
761
- ${this.liveAnnouncer.template()}
762
- <div class="datatable-shell">
763
- <div class="datatable-scroll ${this._virtualScroll ? "datatable-virtual" : ""}" role="presentation">
764
- <table
765
- role=${this._tree ? "treegrid" : this._selectionMode !== "none" ? "grid" : h}
766
- aria-rowcount=${o}
767
- aria-colcount=${i}
768
- aria-busy=${this._loading ? "true" : h}
769
- aria-label=${this.getAttribute("aria-label") ?? this._inputLabel ?? h}
770
- class=${this._hasMeasuredInitial ? "measured" : ""}
771
- >
772
- ${this._caption ? c`<caption>${this._caption}</caption>` : h}
773
- <thead>
774
- <tr role="row" aria-rowindex="1">
775
- ${this._tree ? c`<th class="tree-chevron-cell" scope="col" aria-label=${this.mergedLabels.treeChevronColumn}></th>` : h}
776
- ${a ? c`<th class="checkbox-cell" scope="col">
777
- <mp-checkbox
778
- aria-label=${this.mergedLabels.deselectAll}
779
- aria-hidden=${this._selectedIds.size === 0 ? "true" : h}
780
- style=${b({ visibility: this._selectedIds.size > 0 ? "visible" : "hidden" })}
781
- .checked=${!1}
782
- .indeterminate=${this._selectedIds.size > 0}
783
- @change=${this.onDeselectAll}
784
- ></mp-checkbox>
785
- </th>` : h}
786
- ${this._columns.map((n, d) => this.renderHeader(n, d))}
787
- </tr>
788
- </thead>
789
- <tbody>
790
- ${this._loading ? c`<tr><td colspan=${i} class="loading-state">Loading…</td></tr>` : t.length === 0 ? c`<tr><td colspan=${i} class="empty-state">${this._emptyMessage}</td></tr>` : c`
791
- ${r.top > 0 ? c`<tr class="virtual-spacer" aria-hidden="true"><td colspan=${i} style=${b({ height: `${r.top}px`, padding: "0", border: "0" })}></td></tr>` : h}
792
- ${M(
793
- t,
794
- ({ key: n }) => n,
795
- ({ key: n, rowIndex: d, flat: m }) => this.renderRow(m, n, d, a)
796
- )}
797
- ${r.bottom > 0 ? c`<tr class="virtual-spacer" aria-hidden="true"><td colspan=${i} style=${b({ height: `${r.bottom}px`, padding: "0", border: "0" })}></td></tr>` : h}
798
- `}
799
- </tbody>
800
- </table>
801
- </div>
802
- ${this._pagination && !this._tree ? this.renderFooter(s) : h}
803
- </div>
804
- `;
805
- }
806
- getVirtualSpacerHeights() {
807
- if (!this._virtualScroll) return { top: 0, bottom: 0 };
808
- const t = this.getEffectiveData().length, { startIndex: e, endIndex: s } = this._virtualRange;
809
- return {
810
- top: e * this._itemSize,
811
- bottom: Math.max(0, (t - s) * this._itemSize)
812
- };
813
- }
814
- renderHeader(t, e) {
815
- const s = t.sortable ?? !0, a = this._sortColumns.findIndex((d) => d.property === t.name), i = a >= 0 ? this._sortColumns[a].direction : null, r = this._columnWidths.get(t.name) ?? t.width, o = t.headerRenderer ? t.headerRenderer(t) : t.label ?? t.name, n = {};
816
- return typeof r == "number" && (n.width = `${r}px`, n.minWidth = `${r}px`), c`
817
- <th
818
- scope="col"
819
- data-column=${t.name}
820
- data-sortable=${s ? "true" : "false"}
821
- aria-sort=${i ? i === "ascending" ? "ascending" : "descending" : "none"}
822
- style=${b(n)}
823
- >
824
- ${s ? c`<button
825
- type="button"
826
- class="header-cell header-sort"
827
- @click=${(d) => this.onHeaderClick(t, d)}
828
- >
829
- <span>${y(o)}</span>
830
- ${a >= 0 && this._sortColumns.length > 1 ? c`<span class="sort-index">${a + 1}</span>` : h}
831
- </button>` : c`<span class="header-cell">
832
- <span>${y(o)}</span>
833
- </span>`}
834
- ${this._resizableColumns ? c`<span
835
- class="resize-handle"
836
- role="separator"
837
- tabindex="0"
838
- aria-orientation="vertical"
839
- aria-label=${this.mergedLabels.resizeColumn(t.label ?? t.name)}
840
- aria-valuemin="40"
841
- aria-valuenow=${Math.round(r ?? 0) || h}
842
- @pointerdown=${(d) => this.startColumnResize(t, d)}
843
- @keydown=${(d) => this.onResizeHandleKeydown(t, d)}
844
- ></span>` : h}
845
- </th>
846
- `;
847
- }
848
- renderRow(t, e, s, a) {
849
- const { row: i, depth: r, isExpanded: o, isPlaceholder: n } = t, d = !n && this._selectedIds.has(e), m = !n && this._cutIds.has(e), u = !n && this._focusedRowKey === e, p = n ? 0 : this.extractChildCount(i), f = this._tree && !n && p > 0, v = !n && i != null && this.isParentIndeterminate(i);
850
- return c`
851
- <tr
852
- role="row"
853
- aria-rowindex=${s + 2}
854
- aria-level=${this._tree ? r + 1 : h}
855
- aria-expanded=${this._tree && p > 0 ? o ? "true" : "false" : h}
856
- aria-busy=${n ? "true" : h}
857
- aria-selected=${!n && this._selectionMode !== "none" ? d ? "true" : "false" : h}
858
- data-row-key=${e}
859
- data-selected=${d ? "true" : "false"}
860
- data-cut=${m ? "true" : "false"}
861
- data-focused=${u ? "true" : "false"}
862
- data-placeholder=${n ? "true" : "false"}
863
- data-depth=${this._tree ? String(r) : h}
864
- data-clickable=${!n && (this._selectionMode !== "none" || this.hasRowClickListeners()) ? "true" : "false"}
865
- tabindex=${!n && (this._selectionMode !== "none" || this._tree) ? this._focusedRowKey === e || this._focusedRowKey === null && s === 0 ? "0" : "-1" : h}
866
- @focus=${n ? null : () => {
867
- this._focusedRowKey = e, this.requestUpdate();
868
- }}
869
- @click=${n ? null : (g) => this.onRowClick(i, e, s, g)}
870
- @dblclick=${n ? null : (g) => this.onRowDblClick(i, e, s, g)}
871
- @contextmenu=${n ? null : (g) => this.onRowContextMenu(i, e, s, g)}
872
- @keydown=${n ? null : (g) => this.onRowKeydown(i, e, s, t.parentId, r, o, p, g)}
873
- >
874
- ${this._tree ? c`<td class="tree-chevron-cell" style=${b({ paddingInlineStart: `${r * this._treeIndent}rem` })}>
875
- ${f ? c`<button
876
- type="button"
877
- class="tree-chevron"
878
- aria-label=${o ? this.mergedLabels.collapseRow : this.mergedLabels.expandRow}
879
- aria-expanded=${o ? "true" : "false"}
880
- data-expanded=${o ? "true" : "false"}
881
- @click=${(g) => this.toggleExpand(i, t.parentId, r, g)}
882
- >${o ? "▾" : "▸"}</button>` : h}
883
- </td>` : h}
884
- ${a ? c`<td class="checkbox-cell" @click=${(g) => g.stopPropagation()}>
885
- ${n ? h : c`<mp-checkbox
886
- aria-label=${this.mergedLabels.selectRow(s + 1)}
887
- .checked=${d}
888
- .indeterminate=${v}
889
- @change=${(g) => this.onRowCheckboxToggle(i, e, s, g)}
890
- ></mp-checkbox>`}
891
- </td>` : h}
892
- ${this._rowRenderer ? this.renderRowFromRenderer(i, s, { depth: r, isExpanded: o, isPlaceholder: n }) : n ? c`<td colspan=${this._columns.length} class="tree-placeholder-cell" aria-label=${this.mergedLabels.loading}>…</td>` : this._columns.map((g) => this.renderCell(i, g, s))}
893
- </tr>
894
- `;
895
- }
896
- renderRowFromRenderer(t, e, s) {
897
- const a = this._rowRenderer(t, e, s);
898
- if (a == null)
899
- return s.isPlaceholder ? c`<td colspan=${this._columns.length} class="tree-placeholder-cell" aria-label=${this.mergedLabels.loading}>…</td>` : this._columns.map((i) => this.renderCell(t, i, e));
900
- if (Array.isArray(a) || U(a)) {
901
- const i = [];
902
- for (const r of a) i.push(r);
903
- return i;
904
- }
905
- return a;
906
- }
907
- renderCell(t, e, s) {
908
- const a = e.cellRenderer ? e.cellRenderer(t, e, s) : q(t, e);
909
- return c`<td class=${e.cellClass ?? ""} data-column=${e.name}>${y(a)}</td>`;
910
- }
911
- renderFooter(t) {
912
- const e = Array.from({ length: t }, (s, a) => a + 1);
913
- return c`
914
- <div class="datatable-footer">
915
- <mp-pagination
916
- class="datatable-per-page"
917
- aria-label=${this.mergedLabels.rowsPerPage}
918
- .pageNumbers=${this._perPageOptions}
919
- .selectedPageNumber=${this._perPage}
920
- .showArrows=${!1}
921
- @mp-pagination-page-change=${(s) => this.setPerPage(s.detail.page)}
922
- ></mp-pagination>
923
- <mp-pagination
924
- class="datatable-pagination"
925
- .pageNumbers=${e}
926
- .selectedPageNumber=${this._page}
927
- .numberOfBoxes=${7}
928
- .showArrows=${!0}
929
- @mp-pagination-page-change=${(s) => this.gotoPage(s.detail.page)}
930
- ></mp-pagination>
931
- </div>
932
- `;
933
- }
934
- setPerPage(t) {
935
- const e = Math.max(1, Math.floor(t || 1));
936
- this._perPage !== e && (this._perPage = e, this._page = 1, this.requestUpdate(), this.scheduleFetchReload(), this.dispatchEvent(
937
- new CustomEvent("mp-datatable-per-page-change", {
938
- detail: { perPage: e },
939
- bubbles: !0,
940
- composed: !0
941
- })
942
- ), this.dispatchEvent(
943
- new CustomEvent("mp-datatable-page-change", {
944
- detail: { page: 1 },
945
- bubbles: !0,
946
- composed: !0
947
- })
948
- ));
949
- }
950
- getEffectiveData() {
951
- if (this._tree || this.isRootWindowed())
952
- return this.getFlatList().map((e) => e.row);
953
- let t = this._data;
954
- if (this._autoSort && this._sortColumns.length > 0 && (t = _(t, this._sortColumns)), this._pagination && !this.isExternallyPaged()) {
955
- const e = (this._page - 1) * this._perPage;
956
- t = t.slice(e, e + this._perPage);
957
- }
958
- return t;
959
- }
960
- /**
961
- * Flat list of visible rows including expansion + placeholders. Computed
962
- * each render in tree mode; flat mode produces a trivial mapping of `_data`
963
- * (after sort+pagination) with default metadata.
964
- *
965
- * Memoised via `_cachedFlatList`, cleared in `willUpdate`. Multiple calls
966
- * during the same render cycle (`computeVisibleRows`,
967
- * `getVirtualSpacerHeights`, aria-rowcount) share one computation.
968
- */
969
- getFlatList() {
970
- if (this._cachedFlatList !== null) return this._cachedFlatList;
971
- if (!this._tree) {
972
- if (this.isRootWindowed()) {
973
- const r = this._totalRecords ?? this._data.length, o = Math.max(1, this._perPage), n = new Array(r);
974
- for (let d = 0; d < r; d++) {
975
- const m = Math.floor(d / o) + 1, u = d % o, p = m === 1 ? this._data[u] : this._pageCache.get(m)?.[u];
976
- n[d] = p !== void 0 ? { row: p, key: this._rowKey(p, d), depth: 0, parentId: null, isExpanded: !1, isPlaceholder: !1 } : { row: void 0, key: `__placeholder-flat-${d}`, depth: 0, parentId: null, page: m, isExpanded: !1, isPlaceholder: !0 };
977
- }
978
- return this._cachedFlatList = n;
979
- }
980
- const i = (() => {
981
- let r = this._data;
982
- if (this._autoSort && this._sortColumns.length > 0 && (r = _(r, this._sortColumns)), this._pagination && !this.isExternallyPaged()) {
983
- const o = (this._page - 1) * this._perPage;
984
- r = r.slice(o, o + this._perPage);
985
- }
986
- return r;
987
- })();
988
- return this._cachedFlatList = i.map((r, o) => ({
989
- row: r,
990
- key: this._rowKey(r, o),
991
- depth: 0,
992
- parentId: null,
993
- isExpanded: !1,
994
- isPlaceholder: !1
995
- }));
996
- }
997
- const t = [], e = Math.max(1, this._perPage), s = (i) => this._autoSort && this._sortColumns.length > 0 ? _(i, this._sortColumns) : i, a = (i, r, o) => {
998
- const n = this.extractId(i), d = n != null && this._expandedIds.has(n), m = this.extractChildCount(i);
999
- if (t.push({ row: i, key: this._rowKey(i, t.length), depth: r, parentId: o, isExpanded: d, isPlaceholder: !1 }), !d || m === 0 || n == null) return;
1000
- const u = this._childCache.get(n);
1001
- if (u && u.length > 0) {
1002
- for (const f of s(u)) a(f, r + 1, n);
1003
- const p = this._childTotals.get(n) ?? u.length;
1004
- for (let f = 0; f < Math.max(0, p - u.length); f++)
1005
- t.push({ row: void 0, key: `__placeholder-${String(n)}-${u.length + f}`, depth: r + 1, parentId: n, isExpanded: !1, isPlaceholder: !0 });
1006
- } else
1007
- for (let p = 0; p < m; p++)
1008
- t.push({ row: void 0, key: `__placeholder-${String(n)}-${p}`, depth: r + 1, parentId: n, isExpanded: !1, isPlaceholder: !0 });
1009
- };
1010
- if (this.isRootWindowed()) {
1011
- const i = this._totalRecords ?? this._data.length;
1012
- for (let r = 0; r < i; r++) {
1013
- const o = Math.floor(r / e) + 1, n = r % e, d = o === 1 ? this._data[n] : this._pageCache.get(o)?.[n];
1014
- d === void 0 ? t.push({ row: void 0, key: `__placeholder-root-${r}`, depth: 0, parentId: null, page: o, isExpanded: !1, isPlaceholder: !0 }) : a(d, 0, null);
1015
- }
1016
- } else {
1017
- const i = this._autoSort && this._sortColumns.length > 0 ? _(this._data, this._sortColumns) : this._data;
1018
- for (const r of i) a(r, 0, null);
1019
- }
1020
- return this._cachedFlatList = t;
1021
- }
1022
- computeVisibleRows() {
1023
- const t = this.getFlatList(), e = this._tree ? 0 : this._pagination ? (this._page - 1) * this._perPage : 0;
1024
- let s = t, a = 0;
1025
- if (this._virtualScroll) {
1026
- const { startIndex: i, endIndex: r } = this._virtualRange;
1027
- s = t.slice(i, r), a = i;
1028
- }
1029
- return s.map((i, r) => {
1030
- const o = e + a + r;
1031
- return { row: i.row, rowIndex: o, key: i.key, flat: i };
1032
- });
1033
- }
1034
- // ─── Tree-mode helpers ───────────────────────────────────────────────────
1035
- extractId(t) {
1036
- return !this._idKey || t == null || typeof t != "object" ? null : typeof this._idKey == "function" ? this._idKey(t) : t[this._idKey];
1037
- }
1038
- extractChildCount(t) {
1039
- if (!this._childCountKey || t == null || typeof t != "object") return 0;
1040
- const e = t[this._childCountKey];
1041
- return typeof e == "number" && e > 0 ? e : 0;
1042
- }
1043
- /** Walks the loaded subtree of `row` and returns the rowKey for every descendant. */
1044
- collectDescendantKeys(t) {
1045
- const e = this.extractId(t), s = e != null ? this._childCache.get(e) : void 0;
1046
- if (!s) return [];
1047
- const a = [];
1048
- for (const i of s) {
1049
- a.push(this._rowKey(i, -1));
1050
- const r = this.collectDescendantKeys(i);
1051
- for (const o of r) a.push(o);
1052
- }
1053
- return a;
1054
- }
1055
- /** Some-but-not-all loaded descendants selected → indeterminate parent checkbox. */
1056
- isParentIndeterminate(t) {
1057
- return this._selectionStrategy !== "cascading" || t == null ? !1 : this.getIndeterminateKeys().has(this._rowKey(t, -1));
1058
- }
1059
- /**
1060
- * Per-render memo: the set of row keys whose loaded subtree is partially
1061
- * selected. Built in one DFS over `_childCache` so each loaded parent is
1062
- * visited exactly once per render. Replaces the previous
1063
- * `collectDescendantKeys`-per-visible-row recursion which was O(visible ×
1064
- * descendants) per render.
1065
- */
1066
- getIndeterminateKeys() {
1067
- if (this._cachedIndeterminateKeys !== null) return this._cachedIndeterminateKeys;
1068
- const t = /* @__PURE__ */ new Set();
1069
- if (this._selectionStrategy !== "cascading" || !this._tree)
1070
- return this._cachedIndeterminateKeys = t;
1071
- const e = (s) => {
1072
- const a = this.extractId(s);
1073
- if (a == null) return { selected: 0, total: 0 };
1074
- const i = this._childCache.get(a);
1075
- if (!i || i.length === 0) return { selected: 0, total: 0 };
1076
- let r = 0, o = 0;
1077
- for (const n of i) {
1078
- const d = this._rowKey(n, -1), m = this._selectedIds.has(d) ? 1 : 0, u = e(n);
1079
- r += m + u.selected, o += 1 + u.total;
1080
- }
1081
- return o > 0 && r > 0 && r < o && t.add(this._rowKey(s, -1)), { selected: r, total: o };
1082
- };
1083
- for (const s of this._data) e(s);
1084
- return this._cachedIndeterminateKeys = t;
1085
- }
1086
- /**
1087
- * Toggle a row's expanded state. On expand, fires a fetch-request event if
1088
- * children aren't cached yet so the wrapper can bridge to the consumer's
1089
- * `[fetch]` callback. Always fires `expanded-ids-change`.
1090
- */
1091
- toggleExpand(t, e, s, a) {
1092
- a.stopPropagation(), a.preventDefault();
1093
- const i = this.extractId(t);
1094
- if (i == null) return;
1095
- const r = new Set(this._expandedIds);
1096
- let o;
1097
- r.has(i) ? (r.delete(i), o = !1) : (r.add(i), o = !0), this._expandedIds = r, o ? (this.dispatchEvent(
1098
- new CustomEvent("mp-datatable-row-expand", {
1099
- detail: { row: t, depth: s, parentId: e },
1100
- bubbles: !0,
1101
- composed: !0
1102
- })
1103
- ), this.extractChildCount(t) > 0 && !this._childCache.has(i) && !this._pendingFetches.has(i) && this.fetchChildren(i)) : this.dispatchEvent(
1104
- new CustomEvent("mp-datatable-row-collapse", {
1105
- detail: { row: t, depth: s, parentId: e },
1106
- bubbles: !0,
1107
- composed: !0
1108
- })
1109
- ), this.emitExpandedIdsChange(), this.requestUpdate();
1110
- }
1111
- emitExpandedIdsChange() {
1112
- this.dispatchEvent(
1113
- new CustomEvent("mp-datatable-expanded-ids-change", {
1114
- detail: { expandedIds: new Set(this._expandedIds) },
1115
- bubbles: !0,
1116
- composed: !0
1117
- })
1118
- );
1119
- }
1120
- // ─── Fetch-callback driver (the WC owns the whole server-paged loop) ─────
1121
- /**
1122
- * Fetch a windowed root page (≥ 2) into the page cache. Called when a root
1123
- * placeholder scrolls into view. Keyed on the requested page, so a server
1124
- * that echoes a different page number can't deadlock the window.
1125
- * Generation-guarded against responses that land after an invalidation.
1126
- */
1127
- async fetchWindowPage(t) {
1128
- if (!this._fetch || t <= 1) return;
1129
- this._pendingPageFetches.add(t);
1130
- const e = this._fetchGeneration;
1131
- try {
1132
- const s = await this._fetch({ parentId: null, page: t, perPage: this._perPage, sortColumns: [...this._sortColumns] });
1133
- if (e !== this._fetchGeneration || !this._fetch) return;
1134
- this._pendingPageFetches.delete(t), this._pageCache.set(t, [...s?.data ?? []]);
1135
- const a = s?.totalRecords == null ? null : Math.max(0, Math.floor(s.totalRecords));
1136
- a != null && (this._totalRecords = a), this.requestUpdate();
1137
- } catch (s) {
1138
- this._pendingPageFetches.delete(t), console.error("[mp-datatable] fetch failed for root page", t, s);
1139
- }
1140
- }
1141
- /**
1142
- * Fetch a node's children into the child cache. Called on expand or when a
1143
- * child placeholder scrolls into view. Generation-guarded.
1144
- */
1145
- async fetchChildren(t) {
1146
- if (!this._fetch || t == null) return;
1147
- this._pendingFetches.add(t);
1148
- const e = this._fetchGeneration;
1149
- try {
1150
- const s = await this._fetch({ parentId: t, page: 1, perPage: this._perPage, sortColumns: [...this._sortColumns] });
1151
- if (e !== this._fetchGeneration || !this._fetch) return;
1152
- this._pendingFetches.delete(t), this._childCache.set(t, [...s?.data ?? []]), this._childTotals.set(t, s?.totalRecords ?? s?.data?.length ?? 0), this.requestUpdate();
1153
- } catch (s) {
1154
- this._pendingFetches.delete(t), console.error("[mp-datatable] fetch failed for children of", t, s);
1155
- }
1156
- }
1157
- /**
1158
- * Fetch a single page of roots and make it the page-1 data (initial load and
1159
- * non-virtual pagination). The grand total is read from the response —
1160
- * consumers never set `totalRecords`. Generation-guarded against stale loads.
1161
- */
1162
- async loadPage(t) {
1163
- if (!this._fetch) return;
1164
- const e = this._fetchGeneration;
1165
- let s;
1166
- try {
1167
- s = await this._fetch({ parentId: null, page: t, perPage: this._perPage, sortColumns: [...this._sortColumns] });
1168
- } catch (i) {
1169
- console.error("[mp-datatable] fetch failed for page", t, i);
1170
- return;
1171
- }
1172
- if (e !== this._fetchGeneration || !this._fetch) return;
1173
- this._data = [...s?.data ?? []];
1174
- const a = s?.totalRecords == null ? null : Math.max(0, Math.floor(s.totalRecords));
1175
- this._totalRecords = a, this._initialFetchDone = !0, this.requestUpdate();
1176
- }
1177
- /**
1178
- * Coalesce sort/perPage/page changes (which arrive both as user actions and
1179
- * as echoed property pushes) into a single reload. A microtask debounces the
1180
- * burst; a `{sort,perPage,page}` change-key skips echoes that didn't actually
1181
- * change anything.
1182
- */
1183
- scheduleFetchReload() {
1184
- !this._fetch || this._reloadScheduled || (this._reloadScheduled = !0, queueMicrotask(() => {
1185
- if (this._reloadScheduled = !1, !this._fetch) return;
1186
- const t = JSON.stringify({
1187
- s: this._sortColumns,
1188
- pp: this._perPage,
1189
- p: this._virtualScroll ? 1 : this._page
1190
- });
1191
- this._initialFetchDone && t === this._lastReloadKey || (this._lastReloadKey = t, this._fetchGeneration++, this._pageCache.clear(), this._pendingPageFetches.clear(), this._childCache.clear(), this._childTotals.clear(), this._pendingFetches.clear(), this.loadPage(this._virtualScroll ? 1 : this._page));
1192
- }));
1193
- }
1194
- /** Keyboard handling on a tree-mode row. Arrow keys + Enter/Space toggle expansion. */
1195
- onRowKeydown(t, e, s, a, i, r, o, n) {
1196
- if (!n.altKey && n.composedPath()[0] === n.currentTarget) {
1197
- if (n.key === "ArrowDown" || n.key === "ArrowUp") {
1198
- n.preventDefault();
1199
- const d = Array.from(
1200
- this.renderRoot.querySelectorAll("tbody tr[data-row-key]")
1201
- ), m = d.findIndex((p) => p.dataset.rowKey === e), u = d[m + (n.key === "ArrowDown" ? 1 : -1)];
1202
- u && u.focus();
1203
- return;
1204
- }
1205
- if (this._tree) {
1206
- if (n.key === "ArrowRight" && o > 0 && !r) {
1207
- this.toggleExpand(t, a, i, n);
1208
- return;
1209
- }
1210
- if (n.key === "ArrowLeft" && r) {
1211
- this.toggleExpand(t, a, i, n);
1212
- return;
1213
- }
1214
- if ((n.key === "Enter" || n.key === " ") && o > 0) {
1215
- this.toggleExpand(t, a, i, n);
1216
- return;
1217
- }
1218
- }
1219
- (n.key === "Enter" || n.key === " ") && this._selectionMode !== "none" && (n.preventDefault(), this._focusedRowKey = e, this.handleSelectionOnClick(e, n), this.requestUpdate(), this.dispatchEvent(
1220
- new CustomEvent("mp-datatable-row-click", {
1221
- detail: { row: t, rowIndex: s, rowKey: e, originalEvent: n },
1222
- bubbles: !0,
1223
- composed: !0
1224
- })
1225
- ));
1226
- }
1227
- }
1228
- hasRowClickListeners() {
1229
- return !0;
1230
- }
1231
- onHeaderClick(t, e) {
1232
- if (!(t.sortable ?? !0) || e.target.closest(".resize-handle")) return;
1233
- const i = L(this._sortColumns, t.name, e.shiftKey);
1234
- this._sortColumns = i, this._page = 1;
1235
- const r = i.find((o) => o.property === t.name);
1236
- this.liveAnnouncer.announce(
1237
- this.mergedLabels.announceSorted(
1238
- t.label ?? t.name,
1239
- r ? r.direction === "ascending" ? "ascending" : "descending" : "none"
1240
- )
1241
- ), this.requestUpdate(), this.scheduleFetchReload(), this.dispatchEvent(
1242
- new CustomEvent("mp-datatable-sort-change", {
1243
- detail: { sortColumns: i },
1244
- bubbles: !0,
1245
- composed: !0
1246
- })
1247
- );
1248
- }
1249
- onRowClick(t, e, s, a) {
1250
- a.target.closest('input[type="checkbox"]') || (this._focusedRowKey = e, this.handleSelectionOnClick(e, a), this.requestUpdate(), this.dispatchEvent(
1251
- new CustomEvent("mp-datatable-row-click", {
1252
- detail: { row: t, rowIndex: s, rowKey: e, originalEvent: a },
1253
- bubbles: !0,
1254
- composed: !0
1255
- })
1256
- ));
1257
- }
1258
- onRowDblClick(t, e, s, a) {
1259
- this.dispatchEvent(
1260
- new CustomEvent("mp-datatable-row-dblclick", {
1261
- detail: { row: t, rowIndex: s, rowKey: e, originalEvent: a },
1262
- bubbles: !0,
1263
- composed: !0
1264
- })
1265
- );
1266
- }
1267
- onRowContextMenu(t, e, s, a) {
1268
- this._selectionMode !== "none" && !this._selectedIds.has(e) && (this._selectedIds = /* @__PURE__ */ new Set([e]), this._focusedRowKey = e, this.emitSelectionChange(), this.requestUpdate()), this.dispatchEvent(
1269
- new CustomEvent("mp-datatable-row-contextmenu", {
1270
- detail: { row: t, rowIndex: s, rowKey: e, originalEvent: a },
1271
- bubbles: !0,
1272
- composed: !0,
1273
- cancelable: !0
1274
- })
1275
- );
1276
- }
1277
- onRowCheckboxToggle(t, e, s, a) {
1278
- if (this._selectionMode !== "none") {
1279
- if (this._selectionMode === "single")
1280
- this._selectedIds = /* @__PURE__ */ new Set([e]);
1281
- else {
1282
- const i = new Set(this._selectedIds), r = !i.has(e);
1283
- if (r ? i.add(e) : i.delete(e), this._tree && this._selectionStrategy === "cascading" && t != null) {
1284
- const o = this.collectDescendantKeys(t);
1285
- if (r)
1286
- for (const n of o) i.add(n);
1287
- else
1288
- for (const n of o) i.delete(n);
1289
- }
1290
- this._selectedIds = i;
1291
- }
1292
- this.emitSelectionChange(), this.requestUpdate();
1293
- }
1294
- }
1295
- /**
1296
- * Clears the entire selection. The header checkbox is only rendered when
1297
- * at least one row is selected — a true "select all" affordance would be
1298
- * misleading because the WC doesn't know about rows outside the current
1299
- * pagination slice or virtual-scroll window. Click semantics are
1300
- * therefore one-way: visible → deselect-all → hidden again.
1301
- */
1302
- onDeselectAll() {
1303
- this._selectedIds.size !== 0 && (this._selectedIds = /* @__PURE__ */ new Set(), this.emitSelectionChange(), this.requestUpdate());
1304
- }
1305
- handleSelectionOnClick(t, e) {
1306
- if (this._selectionMode !== "none") {
1307
- if (this._selectionMode === "single") {
1308
- this._selectedIds = /* @__PURE__ */ new Set([t]), this.emitSelectionChange();
1309
- return;
1310
- }
1311
- if (e.shiftKey && this._selectionAnchorKey && this._selectionAnchorKey !== t) {
1312
- const s = this.computeVisibleRows(), a = s.findIndex((r) => r.key === this._selectionAnchorKey), i = s.findIndex((r) => r.key === t);
1313
- if (a >= 0 && i >= 0) {
1314
- const [r, o] = a < i ? [a, i] : [i, a], n = s.slice(r, o + 1).map((d) => d.key);
1315
- this._selectedIds = /* @__PURE__ */ new Set([...this._selectedIds, ...n]), this.emitSelectionChange();
1316
- return;
1317
- }
1318
- }
1319
- if (e.ctrlKey || e.metaKey) {
1320
- const s = new Set(this._selectedIds);
1321
- s.has(t) ? s.delete(t) : s.add(t), this._selectedIds = s, this._selectionAnchorKey = t, this.emitSelectionChange();
1322
- return;
1323
- }
1324
- this._selectedIds = /* @__PURE__ */ new Set([t]), this._selectionAnchorKey = t, this.emitSelectionChange();
1325
- }
1326
- }
1327
- emitSelectionChange() {
1328
- const t = [...this._selectedIds];
1329
- this.liveAnnouncer.announce(this.mergedLabels.announceSelection(t.length)), this.dispatchEvent(
1330
- new CustomEvent("mp-datatable-selection-change", {
1331
- detail: { selectedIds: t, selectedRows: this.resolveRows(t) },
1332
- bubbles: !0,
1333
- composed: !0
1334
- })
1335
- );
1336
- }
1337
- /**
1338
- * Resolve row keys → row objects across every loaded source (page-1 `_data`,
1339
- * fetched windows in `_pageCache`, tree children in `_childCache`). One pass
1340
- * builds a key→row index; unresolvable ids are skipped.
1341
- */
1342
- resolveRows(t) {
1343
- if (t.length === 0) return [];
1344
- const e = /* @__PURE__ */ new Map(), s = (a) => {
1345
- for (const i of a) e.set(this._rowKey(i, -1), i);
1346
- };
1347
- s(this._data);
1348
- for (const a of this._pageCache.values()) s(a);
1349
- for (const a of this._childCache.values()) s(a);
1350
- return t.map((a) => e.get(a)).filter((a) => a !== void 0);
1351
- }
1352
- gotoPage(t) {
1353
- const e = this._totalRecords ?? this._data.length, s = Math.max(1, Math.ceil(e / this._perPage));
1354
- this._page = Math.max(1, Math.min(s, t)), this.liveAnnouncer.announce(this.mergedLabels.announcePage(this._page, s)), this.requestUpdate(), this.scheduleFetchReload(), this.dispatchEvent(
1355
- new CustomEvent("mp-datatable-page-change", {
1356
- detail: { page: this._page },
1357
- bubbles: !0,
1358
- composed: !0
1359
- })
1360
- );
1361
- }
1362
- /**
1363
- * Keyboard column resize — the same ±px model as the pointer path, same 40px
1364
- * floor. The handle is a focusable role="separator"; without this it was the
1365
- * audit's pointer-only finding for the datatable.
1366
- */
1367
- onResizeHandleKeydown(t, e) {
1368
- if (!this._resizableColumns || e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
1369
- e.preventDefault(), e.stopPropagation();
1370
- const a = e.currentTarget.closest("th"), i = this._columnWidths.get(t.name) ?? a?.getBoundingClientRect().width ?? 100, r = Math.max(40, i + (e.key === "ArrowRight" ? 10 : -10));
1371
- this._columnWidths = new Map(this._columnWidths), this._columnWidths.set(t.name, r), this.requestUpdate();
1372
- }
1373
- startColumnResize(t, e) {
1374
- if (!this._resizableColumns) return;
1375
- e.preventDefault(), e.stopPropagation();
1376
- const s = e.currentTarget, a = s.closest("th");
1377
- if (!a) return;
1378
- const i = a.getBoundingClientRect().width;
1379
- this.resizeState = { columnName: t.name, startX: e.clientX, startWidth: i, handle: s }, s.classList.add("active"), s.setPointerCapture(e.pointerId), s.addEventListener("pointermove", this.onColumnResizeMove), s.addEventListener("pointerup", this.onColumnResizeEnd), s.addEventListener("pointercancel", this.onColumnResizeEnd);
1380
- }
1381
- }
1382
- function q(l, t) {
1383
- if (l == null || typeof l != "object") return "";
1384
- const e = l[t.name];
1385
- return e == null ? "" : String(e);
1386
- }
1387
- function U(l) {
1388
- return l != null && typeof l != "string" && typeof l[Symbol.iterator] == "function";
1389
- }
1390
- function y(l) {
1391
- return l == null || l === !1 ? h : (l instanceof Node || typeof l == "object" && "_$litType$" in l, l);
1392
- }
1393
- S("datatable", z);
1394
- typeof customElements < "u" && !customElements.get("mp-datatable") && customElements.define("mp-datatable", F);
1395
- export {
1396
- F as M,
1397
- L as c,
1398
- z as d,
1399
- _ as s
1400
- };