@mintplayer/web-components 2.18.0 → 2.19.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.
@@ -1,30 +1,30 @@
1
- import { unsafeCSS as E, LitElement as M, nothing as u, render as v } from "lit";
2
- import { O as L } from "./overlay-controller-BHDagokg.mjs";
3
- import { s as I, i as q } from "./install-light-styles-DbCAGFOC.mjs";
4
- import { L as z } from "./live-announcer-Bi0orG4n.mjs";
5
- import { a as K, F as A } from "./focus-restore-DxuP1Oe2.mjs";
1
+ import { unsafeCSS as P, LitElement as I, nothing as p, render as y } from "lit";
2
+ import { O as $ } from "./overlay-controller-BHDagokg.mjs";
3
+ import { s as q, i as K } from "./install-light-styles-DbCAGFOC.mjs";
4
+ import { L as A } from "./live-announcer-Bi0orG4n.mjs";
5
+ import { a as O, F as W } from "./focus-restore-DxuP1Oe2.mjs";
6
6
  import { H as U } from "./host-aria-WSGs7SPQ.mjs";
7
- import { repeat as x } from "lit/directives/repeat.js";
8
- import { live as O } from "lit/directives/live.js";
9
- import { classMap as w } from "lit/directives/class-map.js";
7
+ import { repeat as F } 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
10
  import { styleMap as _ } from "lit/directives/style-map.js";
11
11
  import "./mp-pagination-hGy4dL7p.mjs";
12
12
  import "./mp-checkbox-zV83gILn.mjs";
13
- const T = {
13
+ const D = {
14
14
  eq: "equals",
15
15
  neq: "does not equal",
16
16
  lt: "is less than",
17
17
  lte: "is at most",
18
18
  gt: "is greater than",
19
19
  gte: "is at least"
20
- }, D = {
20
+ }, N = {
21
21
  eq: "=",
22
22
  neq: "≠",
23
23
  lt: "<",
24
24
  lte: "≤",
25
25
  gt: ">",
26
26
  gte: "≥"
27
- }, N = ["eq", "neq", "lt", "lte", "gt", "gte"], W = {
27
+ }, H = ["eq", "neq", "lt", "lte", "gt", "gte"], B = {
28
28
  treeChevronColumn: "Expand or collapse",
29
29
  deselectAll: "Deselect all",
30
30
  selectAll: "Select all",
@@ -33,6 +33,13 @@ const T = {
33
33
  loading: "Loading",
34
34
  rowsPerPage: "Rows per page",
35
35
  resizeColumn: (n) => `Resize column ${n}`,
36
+ resizeColumnHint: "Left and Right arrows resize the column. Enter opens the resize options.",
37
+ resizeColumnOptions: (n) => `Resize options for ${n}`,
38
+ narrowerColumn: (n) => `Make ${n} narrower`,
39
+ widerColumn: (n) => `Make ${n} wider`,
40
+ columnWidth: (n) => `${n} px`,
41
+ fitColumn: "Fit to content",
42
+ resetColumn: "Reset width",
36
43
  selectRow: (n) => `Select row ${n}`,
37
44
  selectRowNamed: (n) => `Select ${n}`,
38
45
  filterColumn: (n) => `Filter ${n}`,
@@ -53,14 +60,14 @@ const T = {
53
60
  announceFilter: (n, e) => e === 0 ? `Filter cleared on ${n}` : e === 1 ? `1 value selected in ${n}` : `${e} values selected in ${n}`,
54
61
  filterOperator: "Comparison",
55
62
  filterOperand: "Value to compare with",
56
- filterOperatorLabel: (n) => T[n],
63
+ filterOperatorLabel: (n) => D[n],
57
64
  announceComparisonFilter: (n, e, t) => t === "" ? `Filter cleared on ${n}` : `${n} ${e} ${t}`,
58
65
  announceSorted: (n, e) => e === "none" ? `Sorting removed from ${n}` : `Sorted by ${n}, ${e}`,
59
66
  announcePage: (n, e) => `Page ${n} of ${e}`,
60
67
  announceSelection: (n) => n === 1 ? "1 row selected" : `${n} rows selected`,
61
68
  announceLoaded: (n) => n === 1 ? "Loaded 1 row" : `Loaded ${n} rows`,
62
69
  rangeIncomplete: "Range not selected: some rows in it have not loaded yet"
63
- }, B = E(`@charset "UTF-8";
70
+ }, V = P(`@charset "UTF-8";
64
71
  mp-datatable {
65
72
  display: block;
66
73
  width: 100%;
@@ -152,6 +159,7 @@ thead[data-mps=datatable] th[data-sortable=true][data-mps=datatable]::before, th
152
159
  display: block;
153
160
  opacity: 0.3;
154
161
  bottom: 0.5em;
162
+ pointer-events: none;
155
163
  }
156
164
  thead[data-mps=datatable] th[data-sortable=true][data-mps=datatable]::before {
157
165
  content: "↑";
@@ -216,17 +224,38 @@ tbody[data-mps=datatable] tr:focus-visible[data-mps=datatable] {
216
224
  position: absolute;
217
225
  right: 0;
218
226
  top: 0;
219
- width: 6px;
227
+ width: 24px;
228
+ max-width: 50%;
220
229
  height: 100%;
221
230
  cursor: col-resize;
222
231
  user-select: none;
223
232
  z-index: 2;
233
+ touch-action: none;
234
+ -webkit-touch-callout: none;
224
235
  }
225
236
 
226
- .resize-handle:hover[data-mps=datatable],
227
- .resize-handle.active[data-mps=datatable] {
237
+ .resize-handle[data-mps=datatable]::before {
238
+ content: "";
239
+ position: absolute;
240
+ top: 0;
241
+ bottom: 0;
242
+ right: 0;
243
+ width: 3px;
244
+ }
245
+
246
+ .resize-handle:hover[data-mps=datatable]::before,
247
+ .resize-handle.active[data-mps=datatable]::before {
228
248
  background-color: var(--mp-datatable-resize-handle-color);
229
249
  }
250
+
251
+ @media (pointer: coarse) {
252
+ .resize-handle[data-mps=datatable] {
253
+ width: 40px;
254
+ }
255
+ .resize-handle[data-mps=datatable]::before {
256
+ background-color: var(--mp-datatable-border-color);
257
+ }
258
+ }
230
259
  tbody[data-mps=datatable] > tr[data-mps=datatable] > td {
231
260
  padding: 0.5rem 0.75rem;
232
261
  border-bottom: 1px solid var(--mp-datatable-border-color);
@@ -416,6 +445,61 @@ tr.filter-row[data-mps=datatable] th[data-mps=datatable] {
416
445
  overflow: auto;
417
446
  }
418
447
 
448
+ .resize-panel[data-mps=datatable] {
449
+ position: fixed;
450
+ display: flex;
451
+ flex-direction: column;
452
+ gap: 0.375rem;
453
+ min-width: 12rem;
454
+ padding: 0.5rem;
455
+ background-color: var(--bs-body-bg, #fff);
456
+ color: var(--bs-body-color, inherit);
457
+ border: 1px solid var(--mp-datatable-border-color, var(--bs-border-color, rgba(0, 0, 0, 0.125)));
458
+ border-radius: 0.375rem;
459
+ box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
460
+ }
461
+
462
+ .resize-panel-steps[data-mps=datatable] {
463
+ display: flex;
464
+ align-items: center;
465
+ gap: 0.375rem;
466
+ }
467
+
468
+ .resize-panel-width[data-mps=datatable] {
469
+ flex: 1 1 auto;
470
+ text-align: center;
471
+ font-variant-numeric: tabular-nums;
472
+ }
473
+
474
+ .resize-panel-step[data-mps=datatable],
475
+ .resize-panel-action[data-mps=datatable] {
476
+ min-height: 2.75rem;
477
+ padding: 0.25rem 0.75rem;
478
+ font: inherit;
479
+ color: inherit;
480
+ background: transparent;
481
+ border: 1px solid var(--mp-datatable-border-color, var(--bs-border-color, rgba(0, 0, 0, 0.125)));
482
+ border-radius: 0.25rem;
483
+ cursor: pointer;
484
+ }
485
+
486
+ .resize-panel-step[data-mps=datatable] {
487
+ flex: 0 0 2.75rem;
488
+ font-size: 1.25rem;
489
+ line-height: 1;
490
+ }
491
+
492
+ .resize-panel-step:hover[data-mps=datatable],
493
+ .resize-panel-action:hover[data-mps=datatable] {
494
+ background-color: var(--mp-datatable-row-hover-bg, rgba(var(--bs-emphasis-color-rgb), 0.04));
495
+ }
496
+
497
+ .resize-panel-step:focus-visible[data-mps=datatable],
498
+ .resize-panel-action:focus-visible[data-mps=datatable] {
499
+ outline: 2px solid var(--mp-datatable-resize-handle-color, var(--bs-primary, #0d6efd));
500
+ outline-offset: 1px;
501
+ }
502
+
419
503
  .filter-clear[data-mps=datatable],
420
504
  .filter-invert[data-mps=datatable] {
421
505
  display: block;
@@ -550,56 +634,61 @@ tr.filter-row[data-mps=datatable] th[data-mps=datatable] {
550
634
  transition: none !important;
551
635
  }
552
636
  }`);
553
- function H(n, e, t) {
637
+ function G(n, e, t) {
554
638
  if (t) {
555
- const s = n.findIndex((i) => i.property === e);
639
+ const s = n.findIndex((a) => a.property === e);
556
640
  return s === -1 ? [...n, { property: e, direction: "ascending" }] : n[s].direction === "ascending" ? n.map(
557
- (i, r) => r === s ? { ...i, direction: "descending" } : i
558
- ) : n.filter((i, r) => r !== s);
641
+ (a, r) => r === s ? { ...a, direction: "descending" } : a
642
+ ) : n.filter((a, r) => r !== s);
559
643
  }
560
- const a = n.length === 1 && n[0].property === e;
644
+ const i = n.length === 1 && n[0].property === e;
561
645
  return [
562
646
  {
563
647
  property: e,
564
- direction: a && n[0].direction === "ascending" ? "descending" : "ascending"
648
+ direction: i && n[0].direction === "ascending" ? "descending" : "ascending"
565
649
  }
566
650
  ];
567
651
  }
568
- function y(n, e) {
569
- return e.length === 0 ? n.slice() : n.map((t, a) => ({ row: t, index: a })).sort((t, a) => {
652
+ function v(n, e) {
653
+ return e.length === 0 ? n.slice() : n.map((t, i) => ({ row: t, index: i })).sort((t, i) => {
570
654
  for (const s of e) {
571
- const i = S(t.row, s.property), r = S(a.row, s.property), o = V(i, r);
655
+ const a = z(t.row, s.property), r = z(i.row, s.property), o = j(a, r);
572
656
  if (o !== 0)
573
657
  return s.direction === "ascending" ? o : -o;
574
658
  }
575
- return t.index - a.index;
659
+ return t.index - i.index;
576
660
  }).map(({ row: t }) => t);
577
661
  }
578
- function S(n, e) {
662
+ function z(n, e) {
579
663
  if (!(n == null || typeof n != "object"))
580
664
  return n[e];
581
665
  }
582
- function V(n, e) {
666
+ function j(n, e) {
583
667
  return n === e ? 0 : n == null ? 1 : e == null ? -1 : typeof n == "number" && typeof e == "number" ? n - e : n instanceof Date && e instanceof Date ? n.getTime() - e.getTime() : String(n).localeCompare(String(e));
584
668
  }
585
- const F = 40, R = 10;
586
- function $(n, e) {
587
- return Math.max(F, n + e);
669
+ const C = 40, w = 10;
670
+ function M(n, e) {
671
+ return Math.max(C, n + e);
588
672
  }
589
- const c = I("datatable");
590
- function P(n, e) {
673
+ const X = 0.75, Y = 4;
674
+ function Z(n) {
675
+ const e = Math.max(0, ...n.filter((t) => Number.isFinite(t)));
676
+ return e > 0 ? Math.max(C, Math.ceil(e)) : null;
677
+ }
678
+ const c = q("datatable");
679
+ function k(n, e) {
591
680
  return n === e || n !== n && e !== e;
592
681
  }
593
682
  function g(n, e) {
594
- return n.some((t) => P(t.value, e));
683
+ return n.some((t) => k(t.value, e));
595
684
  }
596
- const G = 250;
597
- let j = 0;
598
- class X extends M {
685
+ const J = 250;
686
+ let Q = 0;
687
+ class ee extends I {
599
688
  constructor() {
600
- super(...arguments), this.instanceId = `mp-datatable-${++j}`, this._caption = null, this._inputLabel = null, this.hostAria = new U(this, {
689
+ super(...arguments), this.instanceId = `mp-datatable-${++Q}`, this._caption = null, this._inputLabel = null, this.hostAria = new U(this, {
601
690
  referenceTarget: () => this.renderRoot?.querySelector("table") ?? null
602
- }), this._labels = void 0, this._columns = [], this._data = [], this._sortColumns = [], this._selectionMode = "none", this._selectedIds = /* @__PURE__ */ new Set(), this._selectedRowCache = /* @__PURE__ */ new Map(), this._cutIds = /* @__PURE__ */ new Set(), this._focusedRowKey = null, this.liveAnnouncer = new z(this), this.rowFocusRestore = new K(this, new A(
691
+ }), this._labels = void 0, this._columns = [], this._data = [], this._sortColumns = [], this._selectionMode = "none", this._selectedIds = /* @__PURE__ */ new Set(), this._selectedRowCache = /* @__PURE__ */ new Map(), this._cutIds = /* @__PURE__ */ new Set(), this._focusedRowKey = null, this.liveAnnouncer = new A(this), this.rowFocusRestore = new O(this, new W(
603
692
  () => this.renderRoot ?? null,
604
693
  {
605
694
  selector: 'tbody tr[data-row-key]:not([data-placeholder="true"])',
@@ -607,9 +696,9 @@ class X extends M {
607
696
  container: () => this.renderRoot?.querySelector("table") ?? null
608
697
  }
609
698
  )), this._rowKey = (e, t) => {
610
- const a = e;
611
- return a && a.id != null ? String(a.id) : (this.warnPositionalKeyOnce(), `row-${t}`);
612
- }, this._warnedPositionalKey = !1, 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._rowLabel = null, this._resizableColumns = !0, this.filterOverlay = new L(this, {
699
+ const i = e;
700
+ return i && i.id != null ? String(i.id) : (this.warnPositionalKeyOnce(), `row-${t}`);
701
+ }, this._warnedPositionalKey = !1, this._columnWidths = /* @__PURE__ */ new Map(), this._measuredWidths = /* @__PURE__ */ new Map(), this._userWidths = /* @__PURE__ */ new Set(), this._derivedLabels = /* @__PURE__ */ new Map(), this._hasMeasuredInitial = !1, this._measuredFit = !1, this._refitFrame = null, 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._headerObserver = null, this._observedThead = 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._rowLabel = null, this._resizableColumns = !0, this.filterOverlay = new $(this, {
613
702
  portal: !0,
614
703
  modal: !0,
615
704
  scrollStrategy: "reposition",
@@ -640,20 +729,33 @@ class X extends M {
640
729
  })
641
730
  );
642
731
  }
643
- }), this._keyByRowMemo = null, this._selectionAnchorKey = null, this.resizeState = null, this.onColumnResizeMove = (e) => {
644
- if (!this.resizeState) return;
645
- const t = $(this.resizeState.startWidth, e.clientX - this.resizeState.startX);
646
- this._columnWidths = new Map(this._columnWidths), this._columnWidths.set(this.resizeState.columnName, t), this.requestUpdate();
732
+ }), this._keyByRowMemo = null, this._selectionAnchorKey = null, this.resizeState = null, this._openResizeColumn = null, this._resizeHintAnnounced = !1, this._frozenExtraWidth = null, this._frozenWidths = /* @__PURE__ */ new Map(), this.onColumnResizeMove = (e) => {
733
+ const t = this.resizeState;
734
+ if (!t || e.pointerId !== t.pointerId) return;
735
+ const i = e.clientX - t.startX;
736
+ !t.dragging && Math.abs(i) <= Y || (t.dragging = !0, this.setUserColumnWidth(t.column.name, M(t.startWidth, i)));
647
737
  }, this.onColumnResizeEnd = (e) => {
648
- if (this.resizeState) {
649
- 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);
738
+ const t = this.resizeState;
739
+ if (!(!t || e.pointerId !== t.pointerId)) {
740
+ t.handle.classList.remove("active"), t.handle.removeEventListener("pointermove", this.onColumnResizeMove), t.handle.removeEventListener("pointerup", this.onColumnResizeEnd), t.handle.removeEventListener("pointercancel", this.onColumnResizeEnd);
650
741
  try {
651
- this.resizeState.handle.releasePointerCapture(e.pointerId);
742
+ t.handle.releasePointerCapture(e.pointerId);
652
743
  } catch {
653
744
  }
654
- this.resizeState = null;
745
+ this.resizeState = null, e.type === "pointerup" && !t.dragging && this.openResizePanel(t.column);
655
746
  }
656
- };
747
+ }, this.resizeOverlay = new $(this, {
748
+ portal: !0,
749
+ modal: !0,
750
+ scrollStrategy: "reposition",
751
+ // Re-queried by name: every render rebuilds the header row.
752
+ anchor: () => this._openResizeColumn ? this.resizeHandle(this._openResizeColumn) : null,
753
+ trigger: () => this._openResizeColumn ? this.resizeHandle(this._openResizeColumn) : null,
754
+ panel: () => this.resizeOverlay.portalContainer?.querySelector(".resize-panel") ?? null,
755
+ onClose: () => {
756
+ this._openResizeColumn = null, this.requestUpdate();
757
+ }
758
+ });
657
759
  }
658
760
  /**
659
761
  * Light DOM. Consumer-authored row/cell/header content is mounted here by the
@@ -718,7 +820,7 @@ class X extends M {
718
820
  }
719
821
  /** Merged view of labels — consumer keys over the English defaults. */
720
822
  get mergedLabels() {
721
- return { ...W, ...this.labels ?? {} };
823
+ return { ...B, ...this.labels ?? {} };
722
824
  }
723
825
  /** Optional invisible accessible name for the <table>. Host aria-label wins. */
724
826
  get inputLabel() {
@@ -798,20 +900,20 @@ class X extends M {
798
900
  */
799
901
  syncFilterStates() {
800
902
  const e = new Set(this._columns.map((t) => t.name));
801
- this._filterStates.forEach((t, a) => {
802
- e.has(a) || (this.abortFilterRequest(t), this._filterStates.delete(a));
903
+ this._filterStates.forEach((t, i) => {
904
+ e.has(i) || (this.abortFilterRequest(t), this._filterStates.delete(i));
803
905
  }), this._columns.forEach((t) => {
804
- const a = this._filterStates.get(t.name);
805
- if (!a) {
906
+ const i = this._filterStates.get(t.name);
907
+ if (!i) {
806
908
  t.filterable && this._filterStates.set(t.name, this.createFilterState(t));
807
909
  return;
808
910
  }
809
- t.filterSelection && t.filterSelection !== a.seededFrom && (a.seededFrom = t.filterSelection, a.selection = {
911
+ t.filterSelection && t.filterSelection !== i.seededFrom && (i.seededFrom = t.filterSelection, i.selection = {
810
912
  values: [...t.filterSelection.values],
811
913
  inverse: !!t.filterSelection.inverse,
812
914
  operator: t.filterSelection.operator,
813
915
  operand: t.filterSelection.operand ?? null
814
- }, a.operandText = t.filterSelection.operand == null ? "" : String(t.filterSelection.operand), a.snapshot = null);
916
+ }, i.operandText = t.filterSelection.operand == null ? "" : String(t.filterSelection.operand), i.snapshot = null);
815
917
  });
816
918
  }
817
919
  get data() {
@@ -873,7 +975,7 @@ class X extends M {
873
975
  */
874
976
  assignSortColumns(e) {
875
977
  const t = Array.isArray(e) ? [...e] : [];
876
- return t.length === this._sortColumns.length && t.every((s, i) => s.property === this._sortColumns[i].property && s.direction === this._sortColumns[i].direction) ? !1 : (this._sortColumns = t, !0);
978
+ return t.length === this._sortColumns.length && t.every((s, a) => s.property === this._sortColumns[a].property && s.direction === this._sortColumns[a].direction) ? !1 : (this._sortColumns = t, !0);
877
979
  }
878
980
  /**
879
981
  * Re-queries the `fetch` callback for the current sort, page and page size,
@@ -919,8 +1021,8 @@ class X extends M {
919
1021
  applyFetchState(e) {
920
1022
  const t = "fetch" in e && this.assignFetch(e.fetch);
921
1023
  e.sortColumns !== void 0 && this.assignSortColumns(e.sortColumns);
922
- const a = e.perPage !== void 0 && this.assignPerPage(e.perPage);
923
- e.page !== void 0 && (this.assignPage(e.page), a && !t && this.clampPageToKnownTotal()), this.requestUpdate(), this.scheduleFetchReload();
1024
+ const i = e.perPage !== void 0 && this.assignPerPage(e.perPage);
1025
+ e.page !== void 0 && (this.assignPage(e.page), i && !t && this.clampPageToKnownTotal()), this.requestUpdate(), this.scheduleFetchReload();
924
1026
  }
925
1027
  get selectionMode() {
926
1028
  return this._selectionMode;
@@ -942,7 +1044,7 @@ class X extends M {
942
1044
  }
943
1045
  set selectedIds(e) {
944
1046
  const t = new Set(e ?? []);
945
- t.size === this._selectedIds.size && [...t].every((a) => this._selectedIds.has(a)) || (this._selectedIds = t, this.pruneSelectedRowCache(), t.size > 0 && this.rememberLiveSelectedRows(), this.requestUpdate());
1047
+ t.size === this._selectedIds.size && [...t].every((i) => this._selectedIds.has(i)) || (this._selectedIds = t, this.pruneSelectedRowCache(), t.size > 0 && this.rememberLiveSelectedRows(), this.requestUpdate());
946
1048
  }
947
1049
  /**
948
1050
  * The selected rows, index-aligned with `selectedIds` (`undefined` for a key
@@ -957,8 +1059,8 @@ class X extends M {
957
1059
  return this.resolveRows([...this._selectedIds]);
958
1060
  }
959
1061
  set selectedRows(e) {
960
- const t = e ?? [], a = this.rowKeyLookup(), s = t.map((i) => [a(i), i]);
961
- this.isSameSelectedRows(s) || (this._selectedIds = new Set(s.map(([i]) => i)), this._selectedRowCache = new Map(s), this.requestUpdate());
1062
+ const t = e ?? [], i = this.rowKeyLookup(), s = t.map((a) => [i(a), a]);
1063
+ this.isSameSelectedRows(s) || (this._selectedIds = new Set(s.map(([a]) => a)), this._selectedRowCache = new Map(s), this.requestUpdate());
962
1064
  }
963
1065
  get cutIds() {
964
1066
  return [...this._cutIds];
@@ -1138,37 +1240,37 @@ class X extends M {
1138
1240
  isRootWindowed() {
1139
1241
  return this._virtualScroll && this.isExternallyPaged();
1140
1242
  }
1141
- attributeChangedCallback(e, t, a) {
1142
- if (super.attributeChangedCallback(e, t, a), e === "caption")
1143
- this._caption = a, this.requestUpdate();
1243
+ attributeChangedCallback(e, t, i) {
1244
+ if (super.attributeChangedCallback(e, t, i), e === "caption")
1245
+ this._caption = i, this.requestUpdate();
1144
1246
  else if (e === "input-label")
1145
- this._inputLabel = a, this.requestUpdate();
1247
+ this._inputLabel = i, this.requestUpdate();
1146
1248
  else if (e === "aria-label")
1147
1249
  this.requestUpdate();
1148
1250
  else if (e === "aria-labelledby" || e === "aria-describedby")
1149
1251
  this.hostAria.syncReferences();
1150
1252
  else if (e === "selection-mode") {
1151
- const s = a ?? "none";
1253
+ const s = i ?? "none";
1152
1254
  (s === "none" || s === "single" || s === "multiple" || s === "checkbox") && (this.selectionMode = s);
1153
1255
  } else if (e === "pagination")
1154
- this.pagination = a !== null;
1256
+ this.pagination = i !== null;
1155
1257
  else if (e === "resizable-columns")
1156
- this.resizableColumns = a !== "false";
1258
+ this.resizableColumns = i !== "false";
1157
1259
  else if (e === "auto-sort")
1158
- this.autoSort = a !== "false";
1260
+ this.autoSort = i !== "false";
1159
1261
  else if (e === "empty-message")
1160
- this.emptyMessage = a ?? "No data";
1262
+ this.emptyMessage = i ?? "No data";
1161
1263
  else if (e === "virtual-scroll")
1162
- this.virtualScroll = a !== null;
1264
+ this.virtualScroll = i !== null;
1163
1265
  else if (e === "item-size") {
1164
- const s = Number(a);
1266
+ const s = Number(i);
1165
1267
  Number.isFinite(s) && (this.itemSize = s);
1166
1268
  } else if (e === "tree")
1167
- this.tree = a !== null;
1269
+ this.tree = i !== null;
1168
1270
  else if (e === "tree-indent") {
1169
- const s = a === null ? 1.25 : Number(a);
1271
+ const s = i === null ? 1.25 : Number(i);
1170
1272
  Number.isFinite(s) && (this.treeIndent = s);
1171
- } else e === "selection-strategy" && (this.selectionStrategy = a === "cascading" ? "cascading" : "flat");
1273
+ } else e === "selection-strategy" && (this.selectionStrategy = i === "cascading" ? "cascading" : "flat");
1172
1274
  }
1173
1275
  get resizableColumns() {
1174
1276
  return this._resizableColumns;
@@ -1180,7 +1282,9 @@ class X extends M {
1180
1282
  super.connectedCallback();
1181
1283
  }
1182
1284
  firstUpdated() {
1183
- 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();
1285
+ 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(() => {
1286
+ this.refreshVirtualRange(), this.scheduleRefit();
1287
+ }), this._resizeObserver.observe(this._scrollElement))), this.refreshVirtualRange(), this.hostAria.syncReferences();
1184
1288
  }
1185
1289
  willUpdate(e) {
1186
1290
  super.willUpdate(e), this._cachedFlatList = null, this._cachedIndeterminateKeys = null;
@@ -1188,11 +1292,11 @@ class X extends M {
1188
1292
  updated(e) {
1189
1293
  super.updated(e), this.refreshVirtualRange(), this.nameRowCheckboxes(), this.maybeMeasureInitialColumnWidths();
1190
1294
  const t = this.renderRoot?.querySelectorAll(".resize-handle:not([aria-valuenow])") ?? [];
1191
- for (const a of t) {
1192
- const s = a.closest("th");
1193
- s && a.setAttribute("aria-valuenow", String(Math.round(s.getBoundingClientRect().width)));
1295
+ for (const i of t) {
1296
+ const s = i.closest("th");
1297
+ s && i.setAttribute("aria-valuenow", String(Math.round(s.getBoundingClientRect().width)));
1194
1298
  }
1195
- this._openFilterColumn && this.renderFilterPanel(), this.publishHeaderHeight();
1299
+ this._openFilterColumn && this.renderFilterPanel(), this._openResizeColumn && this.renderResizePanel(), this.observeHeaderText(), this.publishHeaderHeight();
1196
1300
  }
1197
1301
  /**
1198
1302
  * Publish header row 1's height as `--mp-datatable-header-height` for the
@@ -1203,8 +1307,8 @@ class X extends M {
1203
1307
  if (!this.hasFilterRow) return;
1204
1308
  const e = this.renderRoot?.querySelector("thead tr:first-child th"), t = this.renderRoot?.querySelector(".datatable-shell");
1205
1309
  if (!e || !t) return;
1206
- const a = Math.round(e.getBoundingClientRect().height);
1207
- a <= 0 || t.style.getPropertyValue("--mp-datatable-header-height") !== `${a}px` && t.style.setProperty("--mp-datatable-header-height", `${a}px`);
1310
+ const i = Math.round(e.getBoundingClientRect().height);
1311
+ i <= 0 || t.style.getPropertyValue("--mp-datatable-header-height") !== `${i}px` && t.style.setProperty("--mp-datatable-header-height", `${i}px`);
1208
1312
  }
1209
1313
  /**
1210
1314
  * Run the auto-size-once pass after the first batch of rows lands in the
@@ -1218,17 +1322,51 @@ class X extends M {
1218
1322
  maybeMeasureInitialColumnWidths() {
1219
1323
  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;
1220
1324
  const t = new Map(this._columnWidths);
1221
- let a = !1;
1325
+ let i = !1;
1222
1326
  for (const s of this._columns) {
1223
1327
  if (t.has(s.name)) continue;
1224
1328
  if (typeof s.width == "number") {
1225
- t.set(s.name, s.width), a = !0;
1329
+ t.set(s.name, s.width), i = !0;
1226
1330
  continue;
1227
1331
  }
1228
- const i = this.measureColumnWidth(s.name);
1229
- i != null && (t.set(s.name, i), a = !0);
1332
+ const a = this.measureColumnWidth(s.name);
1333
+ a != null && (t.set(s.name, a), this._measuredWidths.set(s.name, a), i = !0);
1230
1334
  }
1231
- a && (this._columnWidths = t, this._hasMeasuredInitial = !0, this.requestUpdate());
1335
+ if (i) {
1336
+ const s = [...this.renderRoot.querySelectorAll("thead tr:first-child th")].reduce((a, r) => a + r.getBoundingClientRect().width, 0);
1337
+ this._measuredFit = !!this._scrollElement && s <= this._scrollElement.clientWidth + 0.5, this._columnWidths = t, this._hasMeasuredInitial = !0, this.requestUpdate();
1338
+ }
1339
+ }
1340
+ scheduleRefit() {
1341
+ this._refitFrame != null || typeof requestAnimationFrame > "u" || (this._refitFrame = requestAnimationFrame(() => {
1342
+ this._refitFrame = null, this.refitMeasuredWidths();
1343
+ }));
1344
+ }
1345
+ /**
1346
+ * Keeps columns that fitted fitting when the scroller narrows: when it is
1347
+ * resized, or when a classic vertical scrollbar appears after the
1348
+ * measurement (13-15px, measured on Windows Chromium and Firefox), which
1349
+ * otherwise brings back the very horizontal scrollbar #426 removed.
1350
+ *
1351
+ * Only MEASURED widths move. A user-set width, an explicit `col.width` and
1352
+ * the fixed checkbox/chevron cells keep theirs, and their total is taken off
1353
+ * the room first. Scaling is always from the measured base, never from the
1354
+ * previous result, which would ratchet down a pixel per pass through the
1355
+ * floor; that also restores the exact widths when the scroller widens again.
1356
+ *
1357
+ * It only ever shrinks (fixed layout spreads any surplus by itself), and
1358
+ * never below MIN_REFIT_SCALE: past that the columns would crush into
1359
+ * ellipses, and content that no longer fits is meant to scroll instead.
1360
+ */
1361
+ refitMeasuredWidths() {
1362
+ if (this._frozenExtraWidth != null || !this._measuredFit || !this._scrollElement || !this.renderRoot) return;
1363
+ const e = [...this._measuredWidths].filter(([d]) => !this._userWidths.has(d));
1364
+ if (e.length === 0) return;
1365
+ const t = new Set(e.map(([d]) => d)), i = [...this.renderRoot.querySelectorAll("thead tr:first-child th")].filter((d) => !t.has(d.dataset.column ?? "")).reduce((d, h) => d + h.getBoundingClientRect().width, 0), s = e.reduce((d, [, h]) => d + h, 0), a = this._scrollElement.clientWidth - i, r = Math.min(1, Math.max(X, a / s)), o = new Map(this._columnWidths);
1366
+ e.map(([d, h]) => {
1367
+ const u = Math.max(C, Math.floor(h * r)), m = o.get(d) !== u;
1368
+ return o.set(d, u), m;
1369
+ }).some(Boolean) && (this._columnWidths = o, this.requestUpdate());
1232
1370
  }
1233
1371
  measureColumnWidth(e) {
1234
1372
  if (!this.renderRoot) return null;
@@ -1236,26 +1374,26 @@ class X extends M {
1236
1374
  `thead tr:first-child th[data-column="${e}"]`
1237
1375
  );
1238
1376
  if (!t) return null;
1239
- const a = Math.ceil(t.getBoundingClientRect().width);
1240
- return a > 0 ? a : null;
1377
+ const i = Math.floor(t.getBoundingClientRect().width);
1378
+ return i > 0 ? i : null;
1241
1379
  }
1242
1380
  disconnectedCallback() {
1243
- 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));
1381
+ super.disconnectedCallback(), this._scrollElement && this._scrollListener && this._scrollElement.removeEventListener("scroll", this._scrollListener), this._scrollListener = null, this._resizeObserver?.disconnect(), this._resizeObserver = null, this._headerObserver?.disconnect(), this._observedThead = null, this._refitFrame != null && cancelAnimationFrame(this._refitFrame), this._refitFrame = null, this._scrollElement = null, this._filterStates.forEach((e) => this.abortFilterRequest(e));
1244
1382
  }
1245
1383
  refreshVirtualRange() {
1246
1384
  if (!this._virtualScroll || !this._scrollElement) return;
1247
1385
  const e = this._scrollElement.scrollTop, t = this._scrollElement.clientHeight;
1248
1386
  this._viewportHeight = t;
1249
- const a = this.getEffectiveData().length, s = this._itemSize, i = Math.max(0, Math.floor(e / s) - this._virtualBuffer), r = Math.ceil(t / s), o = Math.min(a, i + r + this._virtualBuffer * 2);
1250
- (i !== this._virtualRange.startIndex || o !== this._virtualRange.endIndex) && (this._virtualRange = { startIndex: i, endIndex: o }, this.requestUpdate()), this._tree && this.maybeFetchPlaceholdersInViewport(), this.isRootWindowed() && this.maybeFetchPagesInViewport();
1387
+ const i = this.getEffectiveData().length, s = this._itemSize, a = Math.max(0, Math.floor(e / s) - this._virtualBuffer), r = Math.ceil(t / s), o = Math.min(i, a + r + this._virtualBuffer * 2);
1388
+ (a !== this._virtualRange.startIndex || o !== this._virtualRange.endIndex) && (this._virtualRange = { startIndex: a, endIndex: o }, this.requestUpdate()), this._tree && this.maybeFetchPlaceholdersInViewport(), this.isRootWindowed() && this.maybeFetchPagesInViewport();
1251
1389
  }
1252
1390
  /**
1253
1391
  * Walk the visible viewport for placeholder rows whose parent isn't cached
1254
1392
  * and isn't already in-flight. Emit a fetch-request per such parent.
1255
1393
  */
1256
1394
  maybeFetchPlaceholdersInViewport() {
1257
- const e = this.getFlatList(), { startIndex: t, endIndex: a } = this._virtualRange, s = this._virtualScroll ? t : 0, i = this._virtualScroll ? a : e.length, r = /* @__PURE__ */ new Set();
1258
- for (let o = s; o < i; o++) {
1395
+ const e = this.getFlatList(), { startIndex: t, endIndex: i } = this._virtualRange, s = this._virtualScroll ? t : 0, a = this._virtualScroll ? i : e.length, r = /* @__PURE__ */ new Set();
1396
+ for (let o = s; o < a; o++) {
1259
1397
  const l = e[o];
1260
1398
  !l.isPlaceholder || l.parentId == null || this._childCache.has(l.parentId) || this._pendingFetches.has(l.parentId) || r.add(l.parentId);
1261
1399
  }
@@ -1269,69 +1407,70 @@ class X extends M {
1269
1407
  * wrapper's first-page fetch).
1270
1408
  */
1271
1409
  maybeFetchPagesInViewport() {
1272
- const e = this.getFlatList(), { startIndex: t, endIndex: a } = this._virtualRange, s = this._virtualScroll ? t : 0, i = this._virtualScroll ? a : e.length, r = /* @__PURE__ */ new Set();
1273
- for (let o = s; o < i; o++) {
1410
+ const e = this.getFlatList(), { startIndex: t, endIndex: i } = this._virtualRange, s = this._virtualScroll ? t : 0, a = this._virtualScroll ? i : e.length, r = /* @__PURE__ */ new Set();
1411
+ for (let o = s; o < a; o++) {
1274
1412
  const l = e[o];
1275
1413
  !l.isPlaceholder || l.page == null || l.page <= 1 || this._pageCache.has(l.page) || this._pendingPageFetches.has(l.page) || r.add(l.page);
1276
1414
  }
1277
1415
  for (const o of r) this.fetchWindowPage(o);
1278
1416
  }
1279
1417
  render() {
1280
- const e = this.computeVisibleRows(), t = this._totalRecords ?? this._data.length, a = this.pagination && !this._tree ? Math.max(1, Math.ceil(t / this._perPage)) : 1, s = this.isMulti, i = this._columns.length + (s ? 1 : 0) + (this._tree ? 1 : 0), r = this.getVirtualSpacerHeights(), o = this.hasFilterRow ? 2 : 1, l = (this._tree || this.isRootWindowed() ? this.getFlatList().length : this._data.length) + o;
1418
+ const e = this.computeVisibleRows(), t = this._totalRecords ?? this._data.length, i = this.pagination && !this._tree ? Math.max(1, Math.ceil(t / this._perPage)) : 1, s = this.isMulti, a = this._columns.length + (s ? 1 : 0) + (this._tree ? 1 : 0), r = this.getVirtualSpacerHeights(), o = this.hasFilterRow ? 2 : 1, l = (this._tree || this.isRootWindowed() ? this.getFlatList().length : this._data.length) + o;
1281
1419
  return c`
1282
1420
  ${this.liveAnnouncer.template()}
1283
1421
  <div class="datatable-shell">
1284
1422
  <div class="datatable-scroll ${this._virtualScroll ? "datatable-virtual" : ""}" role="presentation">
1285
1423
  <table
1286
- role=${this._tree ? "treegrid" : this._selectionMode !== "none" ? "grid" : u}
1287
- aria-multiselectable=${this.isMulti ? "true" : u}
1424
+ role=${this._tree ? "treegrid" : this._selectionMode !== "none" ? "grid" : p}
1425
+ aria-multiselectable=${this.isMulti ? "true" : p}
1288
1426
  aria-rowcount=${l}
1289
- aria-colcount=${i}
1290
- aria-busy=${this._loading ? "true" : u}
1291
- aria-label=${this.getAttribute("aria-label") ?? this._inputLabel ?? u}
1427
+ aria-colcount=${a}
1428
+ aria-busy=${this._loading ? "true" : p}
1429
+ aria-label=${this.getAttribute("aria-label") ?? this._inputLabel ?? p}
1292
1430
  class=${this._hasMeasuredInitial ? "measured" : ""}
1431
+ style=${_(this._frozenExtraWidth == null ? {} : { width: `${this.frozenTableWidth()}px` })}
1293
1432
  >
1294
- ${this._caption ? c`<caption>${this._caption}</caption>` : u}
1433
+ ${this._caption ? c`<caption>${this._caption}</caption>` : p}
1295
1434
  <thead>
1296
1435
  <tr role="row" aria-rowindex="1">
1297
- ${this._tree ? c`<th class="tree-chevron-cell" scope="col" aria-label=${this.mergedLabels.treeChevronColumn}></th>` : u}
1436
+ ${this._tree ? c`<th class="tree-chevron-cell" scope="col" aria-label=${this.mergedLabels.treeChevronColumn}></th>` : p}
1298
1437
  ${s ? c`<th class="checkbox-cell" scope="col">
1299
1438
  <mp-checkbox
1300
1439
  aria-label=${this.mergedLabels.deselectAll}
1301
- aria-hidden=${this._selectedIds.size === 0 ? "true" : u}
1440
+ aria-hidden=${this._selectedIds.size === 0 ? "true" : p}
1302
1441
  style=${_({ visibility: this._selectedIds.size > 0 ? "visible" : "hidden" })}
1303
1442
  .checked=${!1}
1304
1443
  .indeterminate=${this._selectedIds.size > 0}
1305
1444
  @change=${this.onDeselectAll}
1306
1445
  ></mp-checkbox>
1307
- </th>` : u}
1308
- ${this._columns.map((h, d) => this.renderHeader(h, d))}
1446
+ </th>` : p}
1447
+ ${this._columns.map((d, h) => this.renderHeader(d, h))}
1309
1448
  </tr>
1310
- ${this.hasFilterRow ? this.renderFilterRow(s) : u}
1449
+ ${this.hasFilterRow ? this.renderFilterRow(s) : p}
1311
1450
  </thead>
1312
1451
  <tbody>
1313
- ${this._loading ? c`<tr><td colspan=${i} class="loading-state">Loading…</td></tr>` : e.length === 0 ? c`<tr><td colspan=${i} class="empty-state">${this._emptyMessage}</td></tr>` : c`
1314
- ${r.top > 0 ? c`<tr class="virtual-spacer" aria-hidden="true"><td colspan=${i} style=${_({ height: `${r.top}px`, padding: "0", border: "0" })}></td></tr>` : u}
1315
- ${x(
1452
+ ${this._loading ? c`<tr><td colspan=${a} class="loading-state">Loading…</td></tr>` : e.length === 0 ? c`<tr><td colspan=${a} class="empty-state">${this._emptyMessage}</td></tr>` : c`
1453
+ ${r.top > 0 ? c`<tr class="virtual-spacer" aria-hidden="true"><td colspan=${a} style=${_({ height: `${r.top}px`, padding: "0", border: "0" })}></td></tr>` : p}
1454
+ ${F(
1316
1455
  e,
1317
- ({ key: h }) => h,
1318
- ({ key: h, rowIndex: d, flat: p }) => this.renderRow(p, h, d, s)
1456
+ ({ key: d }) => d,
1457
+ ({ key: d, rowIndex: h, flat: u }) => this.renderRow(u, d, h, s)
1319
1458
  )}
1320
- ${r.bottom > 0 ? c`<tr class="virtual-spacer" aria-hidden="true"><td colspan=${i} style=${_({ height: `${r.bottom}px`, padding: "0", border: "0" })}></td></tr>` : u}
1459
+ ${r.bottom > 0 ? c`<tr class="virtual-spacer" aria-hidden="true"><td colspan=${a} style=${_({ height: `${r.bottom}px`, padding: "0", border: "0" })}></td></tr>` : p}
1321
1460
  `}
1322
1461
  </tbody>
1323
1462
  </table>
1324
1463
  </div>
1325
- ${this._pagination && !this._tree ? this.renderFooter(a) : u}
1464
+ ${this._pagination && !this._tree ? this.renderFooter(i) : p}
1326
1465
  </div>
1327
1466
  `;
1328
1467
  }
1329
1468
  getVirtualSpacerHeights() {
1330
1469
  if (!this._virtualScroll) return { top: 0, bottom: 0 };
1331
- const e = this.getEffectiveData().length, { startIndex: t, endIndex: a } = this._virtualRange;
1470
+ const e = this.getEffectiveData().length, { startIndex: t, endIndex: i } = this._virtualRange;
1332
1471
  return {
1333
1472
  top: t * this._itemSize,
1334
- bottom: Math.max(0, (e - a) * this._itemSize)
1473
+ bottom: Math.max(0, (e - i) * this._itemSize)
1335
1474
  };
1336
1475
  }
1337
1476
  /** True when any column opted in. No column opts in, no second row, no cost. */
@@ -1345,7 +1484,7 @@ class X extends M {
1345
1484
  return `${this._filterUid}-filter-trigger-${e}`;
1346
1485
  }
1347
1486
  createFilterState(e) {
1348
- const t = e.name, a = {
1487
+ const t = e.name, i = {
1349
1488
  selection: {
1350
1489
  values: e.filterSelection ? [...e.filterSelection.values] : [],
1351
1490
  inverse: !!e.filterSelection?.inverse,
@@ -1371,25 +1510,25 @@ class X extends M {
1371
1510
  // until the literal is complete.
1372
1511
  ctx: null
1373
1512
  };
1374
- return a.ctx = {
1375
- values: () => a.view,
1376
- loading: () => a.loading,
1513
+ return i.ctx = {
1514
+ values: () => i.view,
1515
+ loading: () => i.loading,
1377
1516
  search: (s) => this.setFilterSearch(t, s),
1378
- apply: (s, i) => this.applyFilter(t, s, i),
1517
+ apply: (s, a) => this.applyFilter(t, s, a),
1379
1518
  // Clearing emits the shape of the column's OWN mode. A comparison column
1380
1519
  // emitting an empty `selected` array would be reporting a values-mode
1381
1520
  // filter it never had, and a consumer switching on `mode` would miss it.
1382
1521
  clear: () => this.clearFilter(t),
1383
- onChange: (s) => (a.listeners.add(s), () => a.listeners.delete(s))
1384
- }, a;
1522
+ onChange: (s) => (i.listeners.add(s), () => i.listeners.delete(s))
1523
+ }, i;
1385
1524
  }
1386
1525
  /** State for a filterable column, created on demand. */
1387
1526
  filterState(e) {
1388
1527
  const t = this._filterStates.get(e);
1389
1528
  if (t) return t;
1390
- const a = this._columns.find((i) => i.name === e);
1391
- if (!a?.filterable) return null;
1392
- const s = this.createFilterState(a);
1529
+ const i = this._columns.find((a) => a.name === e);
1530
+ if (!i?.filterable) return null;
1531
+ const s = this.createFilterState(i);
1393
1532
  return this._filterStates.set(e, s), s;
1394
1533
  }
1395
1534
  notifyFilterListeners(e) {
@@ -1406,16 +1545,16 @@ class X extends M {
1406
1545
  * does locally is snapshot the value list the first time a selection becomes
1407
1546
  * non-empty, so the list cannot collapse to the selection.
1408
1547
  */
1409
- applyFilter(e, t, a) {
1548
+ applyFilter(e, t, i) {
1410
1549
  const s = this.filterState(e);
1411
1550
  if (!s) return;
1412
- s.selection.values.length === 0 && t.length > 0 && s.snapshot == null && s.loaded && (s.snapshot = [...s.loaded.matching, ...s.loaded.remaining]), t.length === 0 && (s.snapshot = null), s.selection = { ...s.selection, values: [...t], inverse: a }, this.rebucket(s), this.notifyFilterListeners(s);
1551
+ s.selection.values.length === 0 && t.length > 0 && s.snapshot == null && s.loaded && (s.snapshot = [...s.loaded.matching, ...s.loaded.remaining]), t.length === 0 && (s.snapshot = null), s.selection = { ...s.selection, values: [...t], inverse: i }, this.rebucket(s), this.notifyFilterListeners(s);
1413
1552
  const r = this._columns.find((o) => o.name === e);
1414
1553
  this.liveAnnouncer.announce(
1415
- this.mergedLabels.announceFilter(r?.label ?? e, t.length)
1554
+ this.mergedLabels.announceFilter(r ? this.columnLabel(r) : e, t.length)
1416
1555
  ), this.dispatchEvent(
1417
1556
  new CustomEvent("mp-datatable-filter-change", {
1418
- detail: { mode: "values", column: e, selected: [...t], inverse: a },
1557
+ detail: { mode: "values", column: e, selected: [...t], inverse: i },
1419
1558
  bubbles: !0,
1420
1559
  composed: !0
1421
1560
  })
@@ -1441,15 +1580,15 @@ class X extends M {
1441
1580
  * filter, not a comparison against the empty string — otherwise every column
1442
1581
  * would filter everything away the moment its panel opened.
1443
1582
  */
1444
- applyComparison(e, t, a) {
1583
+ applyComparison(e, t, i) {
1445
1584
  const s = this.filterState(e);
1446
1585
  if (!s) return;
1447
- const i = this._columns.find((l) => l.name === e), r = this.parseOperand(a, i?.filterInputType);
1448
- s.operandText = a, s.selection = { ...s.selection, operator: t, operand: r }, this.notifyFilterListeners(s);
1586
+ const a = this._columns.find((l) => l.name === e), r = this.parseOperand(i, a?.filterInputType);
1587
+ s.operandText = i, s.selection = { ...s.selection, operator: t, operand: r }, this.notifyFilterListeners(s);
1449
1588
  const o = this.mergedLabels;
1450
1589
  this.liveAnnouncer.announce(
1451
1590
  o.announceComparisonFilter(
1452
- i?.label ?? e,
1591
+ a ? this.columnLabel(a) : e,
1453
1592
  o.filterOperatorLabel(t),
1454
1593
  r == null ? "" : String(r)
1455
1594
  )
@@ -1469,17 +1608,17 @@ class X extends M {
1469
1608
  parseOperand(e, t) {
1470
1609
  if (e.trim() === "") return null;
1471
1610
  if ((t ?? "number") === "date") return e;
1472
- const a = Number(e);
1473
- return Number.isNaN(a) ? null : a;
1611
+ const i = Number(e);
1612
+ return Number.isNaN(i) ? null : i;
1474
1613
  }
1475
1614
  setFilterSearch(e, t) {
1476
- const a = this.filterState(e);
1477
- if (!a) return;
1478
- a.term = t, this.rebucket(a), this.notifyFilterListeners(a);
1479
- const s = a.loadedTerm ?? "";
1480
- (a.loaded?.hasMore || !t.startsWith(s)) && (a.debounce != null && clearTimeout(a.debounce), a.debounce = setTimeout(() => {
1481
- a.debounce = null, this.loadDistincts(e, t);
1482
- }, G));
1615
+ const i = this.filterState(e);
1616
+ if (!i) return;
1617
+ i.term = t, this.rebucket(i), this.notifyFilterListeners(i);
1618
+ const s = i.loadedTerm ?? "";
1619
+ (i.loaded?.hasMore || !t.startsWith(s)) && (i.debounce != null && clearTimeout(i.debounce), i.debounce = setTimeout(() => {
1620
+ i.debounce = null, this.loadDistincts(e, t);
1621
+ }, J));
1483
1622
  }
1484
1623
  /**
1485
1624
  * Loads (or recomputes) one column's value list.
@@ -1490,26 +1629,26 @@ class X extends M {
1490
1629
  * it cannot answer for this column, and the local path takes over.
1491
1630
  */
1492
1631
  async loadDistincts(e, t) {
1493
- const a = this.filterState(e);
1494
- if (!a) return;
1495
- const s = ++a.generation;
1496
- if (a.controller?.abort(), this._distincts) {
1497
- const i = new AbortController();
1498
- a.controller = i, a.loading = !0, this.notifyFilterListeners(a);
1632
+ const i = this.filterState(e);
1633
+ if (!i) return;
1634
+ const s = ++i.generation;
1635
+ if (i.controller?.abort(), this._distincts) {
1636
+ const a = new AbortController();
1637
+ i.controller = a, i.loading = !0, this.notifyFilterListeners(i);
1499
1638
  try {
1500
- const r = await this._distincts({ column: e, search: t, signal: i.signal });
1501
- if (s !== a.generation) return;
1502
- if (a.loading = !1, a.controller = null, r) {
1503
- a.loaded = r, a.loadedTerm = t, this.rebucket(a), this.notifyFilterListeners(a);
1639
+ const r = await this._distincts({ column: e, search: t, signal: a.signal });
1640
+ if (s !== i.generation) return;
1641
+ if (i.loading = !1, i.controller = null, r) {
1642
+ i.loaded = r, i.loadedTerm = t, this.rebucket(i), this.notifyFilterListeners(i);
1504
1643
  return;
1505
1644
  }
1506
1645
  } catch {
1507
- if (s !== a.generation) return;
1508
- a.loading = !1, a.controller = null, a.loaded = null, a.loadedTerm = t, this.notifyFilterListeners(a);
1646
+ if (s !== i.generation) return;
1647
+ i.loading = !1, i.controller = null, i.loaded = null, i.loadedTerm = t, this.notifyFilterListeners(i);
1509
1648
  return;
1510
1649
  }
1511
1650
  }
1512
- a.loaded = this.localDistincts(e), a.loadedTerm = "", a.fromLocal = !0, this.rebucket(a), this.notifyFilterListeners(a);
1651
+ i.loaded = this.localDistincts(e), i.loadedTerm = "", i.fromLocal = !0, this.rebucket(i), this.notifyFilterListeners(i);
1513
1652
  }
1514
1653
  /**
1515
1654
  * Recomputes the OPEN column's list when it is locally derived and the rows
@@ -1542,11 +1681,11 @@ class X extends M {
1542
1681
  */
1543
1682
  localDistincts(e) {
1544
1683
  if (this._fetch != null || this.isExternallyPaged() || this._childCache.size > 0) return null;
1545
- const t = this.mergedLabels, a = [];
1684
+ const t = this.mergedLabels, i = [];
1546
1685
  return this._data.forEach((s) => {
1547
- const i = s?.[e];
1548
- g(a, i) || a.push({ value: i, label: t.filterValue(i) });
1549
- }), a.sort((s, i) => s.label.localeCompare(i.label)), { matching: a, remaining: [], hasMore: !1 };
1686
+ const a = s?.[e];
1687
+ g(i, a) || i.push({ value: a, label: t.filterValue(a) });
1688
+ }), i.sort((s, a) => s.label.localeCompare(a.label)), { matching: i, remaining: [], hasMore: !1 };
1550
1689
  }
1551
1690
  /**
1552
1691
  * Re-derives `matching` / `remaining` from the snapshot and the search term.
@@ -1561,10 +1700,10 @@ class X extends M {
1561
1700
  e.view = null;
1562
1701
  return;
1563
1702
  }
1564
- const t = e.term.trim().toLowerCase(), a = (o) => t === "" || o.label.toLowerCase().includes(t), s = [...e.loaded.matching, ...e.loaded.remaining], i = e.snapshot ? e.snapshot.filter((o) => g(s, o.value)) : e.loaded.matching, r = e.snapshot ? e.snapshot.filter((o) => !g(s, o.value)) : e.loaded.remaining;
1703
+ const t = e.term.trim().toLowerCase(), i = (o) => t === "" || o.label.toLowerCase().includes(t), s = [...e.loaded.matching, ...e.loaded.remaining], a = e.snapshot ? e.snapshot.filter((o) => g(s, o.value)) : e.loaded.matching, r = e.snapshot ? e.snapshot.filter((o) => !g(s, o.value)) : e.loaded.remaining;
1565
1704
  e.view = {
1566
- matching: i.filter(a),
1567
- remaining: r.filter(a),
1705
+ matching: a.filter(i),
1706
+ remaining: r.filter(i),
1568
1707
  hasMore: e.loaded.hasMore
1569
1708
  };
1570
1709
  }
@@ -1619,14 +1758,14 @@ class X extends M {
1619
1758
  if (!e) return;
1620
1759
  const t = this._columns.find((r) => r.name === this._openFilterColumn);
1621
1760
  if (!t) return;
1622
- const a = this.filterState(t.name);
1623
- v(
1761
+ const i = this.filterState(t.name);
1762
+ y(
1624
1763
  c`
1625
1764
  <div
1626
1765
  class="filter-panel"
1627
1766
  id=${this.filterPanelId}
1628
1767
  role="dialog"
1629
- aria-label=${this.mergedLabels.filterColumn(t.label ?? t.name)}
1768
+ aria-label=${this.mergedLabels.filterColumn(this.columnLabel(t))}
1630
1769
  >
1631
1770
  <div class="filter-panel-body"></div>
1632
1771
  </div>
@@ -1634,17 +1773,17 @@ class X extends M {
1634
1773
  e
1635
1774
  );
1636
1775
  const s = e.querySelector(".filter-panel-body");
1637
- if (!s || !a) return;
1776
+ if (!s || !i) return;
1638
1777
  if (this._mountedFilterColumn === t.name && s.firstChild) {
1639
- this._consumerMountedFilter || this.renderDefaultFilterPanel(t, a, s);
1778
+ this._consumerMountedFilter || this.renderDefaultFilterPanel(t, i, s);
1640
1779
  return;
1641
1780
  }
1642
- const i = t.filterRenderer?.(t, a.ctx) ?? null;
1643
- if (i) {
1644
- s.replaceChildren(i), this._consumerMountedFilter = !0, this._mountedFilterColumn = t.name;
1781
+ const a = t.filterRenderer?.(t, i.ctx) ?? null;
1782
+ if (a) {
1783
+ s.replaceChildren(a), this._consumerMountedFilter = !0, this._mountedFilterColumn = t.name;
1645
1784
  return;
1646
1785
  }
1647
- this._consumerMountedFilter = !1, this.renderDefaultFilterPanel(t, a, s), this._mountedFilterColumn = t.name;
1786
+ this._consumerMountedFilter = !1, this.renderDefaultFilterPanel(t, i, s), this._mountedFilterColumn = t.name;
1648
1787
  }
1649
1788
  /**
1650
1789
  * The built-in panel: clear, search, invert, checkbox list.
@@ -1655,17 +1794,17 @@ class X extends M {
1655
1794
  * so a repaint after a re-query moves rows instead of rebuilding them — an
1656
1795
  * unkeyed list would rebuild the input the user is interacting with.
1657
1796
  */
1658
- renderDefaultFilterPanel(e, t, a) {
1797
+ renderDefaultFilterPanel(e, t, i) {
1659
1798
  if ((e.filterMode ?? "values") === "comparison") {
1660
- this.renderComparisonFilterPanel(e, t, a);
1799
+ this.renderComparisonFilterPanel(e, t, i);
1661
1800
  return;
1662
1801
  }
1663
- const s = this.mergedLabels, i = e.label ?? e.name, r = t.view, o = t.selection.values, l = [
1802
+ const s = this.mergedLabels, a = this.columnLabel(e), r = t.view, o = t.selection.values, l = [
1664
1803
  ...o,
1665
- ...(r?.matching ?? []).filter((d) => !g(o, d.value)),
1666
- ...(r?.remaining ?? []).filter((d) => !g(o, d.value))
1667
- ], h = (d) => !!r && g(r.remaining, d);
1668
- v(
1804
+ ...(r?.matching ?? []).filter((h) => !g(o, h.value)),
1805
+ ...(r?.remaining ?? []).filter((h) => !g(o, h.value))
1806
+ ], d = (h) => !!r && g(r.remaining, h);
1807
+ y(
1669
1808
  c`
1670
1809
  <button
1671
1810
  type="button"
@@ -1673,14 +1812,14 @@ class X extends M {
1673
1812
  ?disabled=${o.length === 0 && !t.selection.inverse}
1674
1813
  @click=${() => this.onFilterClear(e.name)}
1675
1814
  >
1676
- ${s.filterClear(i)}
1815
+ ${s.filterClear(a)}
1677
1816
  </button>
1678
1817
  <input
1679
1818
  type="search"
1680
1819
  class="filter-search"
1681
1820
  .value=${t.term}
1682
1821
  aria-label=${s.filterSearch}
1683
- @input=${(d) => t.ctx.search(d.target.value)}
1822
+ @input=${(h) => t.ctx.search(h.target.value)}
1684
1823
  />
1685
1824
  <button
1686
1825
  type="button"
@@ -1690,27 +1829,27 @@ class X extends M {
1690
1829
  >
1691
1830
  ${s.filterInvert}
1692
1831
  </button>
1693
- <div class="filter-options" role="group" aria-label=${s.filterGroup(i)}>
1694
- ${t.loading ? c`<span class="filter-loading">${s.loading}</span>` : u}
1695
- ${x(
1832
+ <div class="filter-options" role="group" aria-label=${s.filterGroup(a)}>
1833
+ ${t.loading ? c`<span class="filter-loading">${s.loading}</span>` : p}
1834
+ ${F(
1696
1835
  l,
1697
- (d) => d.value,
1698
- (d) => c`
1699
- <label class=${w({ "filter-option": !0, "filter-remaining": h(d.value) })}>
1836
+ (h) => h.value,
1837
+ (h) => c`
1838
+ <label class=${x({ "filter-option": !0, "filter-remaining": d(h.value) })}>
1700
1839
  <input
1701
1840
  type="checkbox"
1702
- .checked=${g(o, d.value)}
1703
- @change=${(p) => this.onFilterToggle(e.name, d, p.target.checked)}
1841
+ .checked=${g(o, h.value)}
1842
+ @change=${(u) => this.onFilterToggle(e.name, h, u.target.checked)}
1704
1843
  />
1705
- <span>${d.label}</span>
1844
+ <span>${h.label}</span>
1706
1845
  </label>
1707
1846
  `
1708
1847
  )}
1709
- ${l.length === 0 && !t.loading ? c`<span class="filter-no-values">${s.filterNoValues}</span>` : u}
1848
+ ${l.length === 0 && !t.loading ? c`<span class="filter-no-values">${s.filterNoValues}</span>` : p}
1710
1849
  </div>
1711
- ${r?.hasMore ? c`<span class="filter-has-more">${s.filterHasMore}</span>` : u}
1850
+ ${r?.hasMore ? c`<span class="filter-has-more">${s.filterHasMore}</span>` : p}
1712
1851
  `,
1713
- a
1852
+ i
1714
1853
  );
1715
1854
  }
1716
1855
  /**
@@ -1721,9 +1860,9 @@ class X extends M {
1721
1860
  * so asking the source for them would be a round trip whose answer is never
1722
1861
  * displayed.
1723
1862
  */
1724
- renderComparisonFilterPanel(e, t, a) {
1725
- const s = this.mergedLabels, i = e.label ?? e.name, r = e.filterOperators?.length ? e.filterOperators : N, o = t.selection.operator ?? r[0], l = t.selection.operand, h = e.filterInputType ?? "number", d = () => a.querySelector(".filter-operand")?.value ?? "", p = () => a.querySelector(".filter-operator")?.value ?? o;
1726
- v(
1863
+ renderComparisonFilterPanel(e, t, i) {
1864
+ const s = this.mergedLabels, a = this.columnLabel(e), r = e.filterOperators?.length ? e.filterOperators : H, o = t.selection.operator ?? r[0], l = t.selection.operand, d = e.filterInputType ?? "number", h = () => i.querySelector(".filter-operand")?.value ?? "", u = () => i.querySelector(".filter-operator")?.value ?? o;
1865
+ y(
1727
1866
  c`
1728
1867
  <button
1729
1868
  type="button"
@@ -1731,39 +1870,39 @@ class X extends M {
1731
1870
  ?disabled=${l == null}
1732
1871
  @click=${() => this.onFilterClear(e.name)}
1733
1872
  >
1734
- ${s.filterClear(i)}
1873
+ ${s.filterClear(a)}
1735
1874
  </button>
1736
1875
  <div class="filter-comparison">
1737
1876
  <select
1738
1877
  class="filter-operator"
1739
1878
  aria-label=${s.filterOperator}
1740
- @change=${() => this.applyComparison(e.name, p(), d())}
1879
+ @change=${() => this.applyComparison(e.name, u(), h())}
1741
1880
  >
1742
1881
  ${r.map(
1743
- (f) => c`
1744
- <option value=${f} ?selected=${f === o}>
1745
- ${D[f]} ${s.filterOperatorLabel(f)}
1882
+ (m) => c`
1883
+ <option value=${m} ?selected=${m === o}>
1884
+ ${N[m]} ${s.filterOperatorLabel(m)}
1746
1885
  </option>
1747
1886
  `
1748
1887
  )}
1749
1888
  </select>
1750
1889
  <input
1751
1890
  class="filter-operand"
1752
- type=${h}
1753
- .value=${O(t.operandText)}
1891
+ type=${d}
1892
+ .value=${T(t.operandText)}
1754
1893
  aria-label=${s.filterOperand}
1755
- @input=${() => this.applyComparison(e.name, p(), d())}
1894
+ @input=${() => this.applyComparison(e.name, u(), h())}
1756
1895
  />
1757
1896
  </div>
1758
1897
  `,
1759
- a
1898
+ i
1760
1899
  );
1761
1900
  }
1762
- onFilterToggle(e, t, a) {
1901
+ onFilterToggle(e, t, i) {
1763
1902
  const s = this.filterState(e);
1764
1903
  if (!s) return;
1765
- const i = a ? [...s.selection.values, t] : s.selection.values.filter((r) => !P(r.value, t.value));
1766
- s.ctx.apply(i, s.selection.inverse);
1904
+ const a = i ? [...s.selection.values, t] : s.selection.values.filter((r) => !k(r.value, t.value));
1905
+ s.ctx.apply(a, s.selection.inverse);
1767
1906
  }
1768
1907
  onFilterClear(e) {
1769
1908
  const t = this.filterState(e);
@@ -1783,8 +1922,8 @@ class X extends M {
1783
1922
  renderFilterRow(e) {
1784
1923
  return c`
1785
1924
  <tr role="row" aria-rowindex="2" class="filter-row">
1786
- ${this._tree ? c`<th class="filter-cell tree-chevron-cell"></th>` : u}
1787
- ${e ? c`<th class="filter-cell checkbox-cell"></th>` : u}
1925
+ ${this._tree ? c`<th class="filter-cell tree-chevron-cell"></th>` : p}
1926
+ ${e ? c`<th class="filter-cell checkbox-cell"></th>` : p}
1788
1927
  ${this._columns.map((t) => this.renderFilterCell(t))}
1789
1928
  </tr>
1790
1929
  `;
@@ -1792,12 +1931,12 @@ class X extends M {
1792
1931
  renderFilterCell(e) {
1793
1932
  if (!e.filterable)
1794
1933
  return c`<th class="filter-cell p-0" data-column=${e.name} scope="col"></th>`;
1795
- const t = this._openFilterColumn === e.name, a = this.mergedLabels, s = e.label ?? e.name, i = e.filterActive ? a.filterColumnActive(s, e.filterSummary) : a.filterColumn(s);
1934
+ const t = this._openFilterColumn === e.name, i = this.mergedLabels, s = this.columnLabel(e), a = e.filterActive ? i.filterColumnActive(s, e.filterSummary) : i.filterColumn(s);
1796
1935
  return c`
1797
1936
  <th class="filter-cell p-0" data-column=${e.name} scope="col">
1798
1937
  <button
1799
1938
  type="button"
1800
- class=${w({
1939
+ class=${x({
1801
1940
  "filter-trigger": !0,
1802
1941
  "p-2": !0,
1803
1942
  "rounded-0": !0,
@@ -1806,77 +1945,128 @@ class X extends M {
1806
1945
  })}
1807
1946
  id=${this.filterTriggerId(e.name)}
1808
1947
  aria-expanded=${t ? "true" : "false"}
1809
- aria-controls=${t ? this.filterPanelId : u}
1810
- aria-label=${i}
1948
+ aria-controls=${t ? this.filterPanelId : p}
1949
+ aria-label=${a}
1811
1950
  @click=${(r) => this.onFilterTriggerClick(e, r)}
1812
1951
  >
1813
1952
  <svg class="filter-icon" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
1814
1953
  <path d="M2 3h12l-4.5 5.25V13L6.5 11.5V8.25L2 3z" />
1815
1954
  </svg>
1816
- ${e.filterSummary ? c`<span class="filter-summary">${e.filterSummary}</span>` : u}
1955
+ ${e.filterSummary ? c`<span class="filter-summary">${e.filterSummary}</span>` : p}
1817
1956
  </button>
1818
1957
  </th>
1819
1958
  `;
1820
1959
  }
1960
+ /**
1961
+ * The column's name in every generated string: the consumer's label, else the
1962
+ * text its header renders, else its key. The header-text step is what makes a
1963
+ * wrapper that only passes a header template (Angular) correct with no extra
1964
+ * input, and that text is already localized because the consumer rendered it.
1965
+ */
1966
+ columnLabel(e) {
1967
+ return e.label ?? this._derivedLabels.get(e.name) ?? e.name;
1968
+ }
1969
+ /**
1970
+ * Caches the text of a Node header. Read during render, before lit moves a
1971
+ * fragment's children into the cell, and only a non-empty text replaces the
1972
+ * cache: a renderer that hands back the same, already-emptied fragment on a
1973
+ * later render must not erase the name it had.
1974
+ */
1975
+ deriveHeaderLabel(e, t) {
1976
+ if (!(t instanceof Node)) {
1977
+ this._derivedLabels.delete(e.name);
1978
+ return;
1979
+ }
1980
+ const i = t.textContent?.replace(/\s+/g, " ").trim();
1981
+ i && this._derivedLabels.set(e.name, i);
1982
+ }
1983
+ /** Idempotent; re-attaches if the thead was replaced or the element reconnected. */
1984
+ observeHeaderText() {
1985
+ if (typeof MutationObserver > "u") return;
1986
+ const e = this.renderRoot?.querySelector("thead") ?? null;
1987
+ e !== this._observedThead && (this._headerObserver ??= new MutationObserver(() => {
1988
+ this.headerTextChanged() && this.requestUpdate();
1989
+ }), this._headerObserver.disconnect(), this._observedThead = e, e && this._headerObserver.observe(e, { characterData: !0, childList: !0, subtree: !0 }));
1990
+ }
1991
+ /**
1992
+ * Whether a header now shows different text than the name derived from it.
1993
+ * The gate that keeps the observer from looping: a renderer that returns
1994
+ * fresh nodes on every call (a new fragment each time, the React/Vue
1995
+ * render-prop shape) mutates the header on EVERY render, but its text stays
1996
+ * the same, so only a real change re-renders.
1997
+ */
1998
+ headerTextChanged() {
1999
+ return [...this._derivedLabels].some(([e, t]) => {
2000
+ const s = this.headerCell(e)?.querySelector(".header-cell > span")?.textContent?.replace(/\s+/g, " ").trim();
2001
+ return !!s && s !== t;
2002
+ });
2003
+ }
2004
+ /** The column's own flag wins in either direction; absent, the table-wide one. */
2005
+ isColumnResizable(e) {
2006
+ return e.resizable ?? this._resizableColumns;
2007
+ }
1821
2008
  renderHeader(e, t) {
1822
- const a = e.sortable ?? !0, s = this._sortColumns.findIndex((h) => h.property === e.name), i = s >= 0 ? this._sortColumns[s].direction : null, r = this._columnWidths.get(e.name) ?? e.width, o = e.headerRenderer ? e.headerRenderer(e) : e.label ?? e.name, l = {};
2009
+ const i = e.sortable ?? !0, s = this._sortColumns.findIndex((d) => d.property === e.name), a = s >= 0 ? this._sortColumns[s].direction : null, r = this._columnWidths.get(e.name) ?? e.width, o = e.headerRenderer ? e.headerRenderer(e) : e.label ?? e.name;
2010
+ this.deriveHeaderLabel(e, o);
2011
+ const l = {};
1823
2012
  return typeof r == "number" && (l.width = `${r}px`, l.minWidth = `${r}px`), c`
1824
2013
  <th
1825
2014
  scope="col"
1826
2015
  data-column=${e.name}
1827
- data-sortable=${a ? "true" : "false"}
1828
- aria-sort=${i ? i === "ascending" ? "ascending" : "descending" : "none"}
2016
+ data-sortable=${i ? "true" : "false"}
2017
+ aria-sort=${a ? a === "ascending" ? "ascending" : "descending" : "none"}
1829
2018
  style=${_(l)}
1830
2019
  >
1831
- ${a ? c`<button
2020
+ ${i ? c`<button
1832
2021
  type="button"
1833
2022
  class="header-cell header-sort"
1834
- @click=${(h) => this.onHeaderClick(e, h)}
2023
+ @click=${(d) => this.onHeaderClick(e, d)}
1835
2024
  >
1836
- <span>${C(o)}</span>
1837
- ${s >= 0 && this._sortColumns.length > 1 ? c`<span class="sort-index">${s + 1}</span>` : u}
2025
+ <span>${S(o)}</span>
2026
+ ${s >= 0 && this._sortColumns.length > 1 ? c`<span class="sort-index">${s + 1}</span>` : p}
1838
2027
  </button>` : c`<span class="header-cell">
1839
- <span>${C(o)}</span>
2028
+ <span>${S(o)}</span>
1840
2029
  </span>`}
1841
- ${this._resizableColumns ? c`<span
2030
+ ${this.isColumnResizable(e) ? c`<span
1842
2031
  class="resize-handle"
1843
2032
  role="separator"
1844
2033
  tabindex="0"
1845
2034
  aria-orientation="vertical"
1846
- aria-label=${this.mergedLabels.resizeColumn(e.label ?? e.name)}
1847
- aria-valuemin=${F}
1848
- aria-valuenow=${Math.round(r ?? 0) || u}
1849
- @pointerdown=${(h) => this.startColumnResize(e, h)}
1850
- @keydown=${(h) => this.onResizeHandleKeydown(e, h)}
1851
- ></span>` : u}
2035
+ aria-label=${this.mergedLabels.resizeColumn(this.columnLabel(e))}
2036
+ aria-valuemin=${C}
2037
+ aria-valuenow=${Math.round(r ?? 0) || p}
2038
+ @pointerdown=${(d) => this.startColumnResize(e, d)}
2039
+ @keydown=${(d) => this.onResizeHandleKeydown(e, d)}
2040
+ @focus=${() => this.onResizeHandleFocus()}
2041
+ ></span>` : p}
1852
2042
  </th>
1853
2043
  `;
1854
2044
  }
1855
- renderRow(e, t, a, s) {
1856
- const { row: i, depth: r, isExpanded: o, isPlaceholder: l } = e, h = !l && this._selectedIds.has(t), d = !l && this._cutIds.has(t), p = !l && this._focusedRowKey === t, f = l ? 0 : this.extractChildCount(i), b = this._tree && !l && f > 0, k = !l && i != null && this.isParentIndeterminate(i, t);
2045
+ renderRow(e, t, i, s) {
2046
+ const { row: a, depth: r, isExpanded: o, isPlaceholder: l } = e, d = !l && this._selectedIds.has(t), h = !l && this._cutIds.has(t), u = !l && this._focusedRowKey === t, m = l ? 0 : this.extractChildCount(a), b = this._tree && !l && m > 0, E = !l && a != null && this.isParentIndeterminate(a, t);
1857
2047
  return c`
1858
2048
  <tr
1859
2049
  role="row"
1860
- aria-rowindex=${a + 1 + (this.hasFilterRow ? 2 : 1)}
1861
- aria-level=${this._tree ? r + 1 : u}
1862
- aria-expanded=${this._tree && f > 0 ? o ? "true" : "false" : u}
1863
- aria-busy=${l ? "true" : u}
1864
- aria-selected=${!l && this._selectionMode !== "none" ? h ? "true" : "false" : u}
2050
+ aria-rowindex=${i + 1 + (this.hasFilterRow ? 2 : 1)}
2051
+ aria-level=${this._tree ? r + 1 : p}
2052
+ aria-expanded=${this._tree && m > 0 ? o ? "true" : "false" : p}
2053
+ aria-busy=${l ? "true" : p}
2054
+ aria-selected=${!l && this._selectionMode !== "none" ? d ? "true" : "false" : p}
1865
2055
  data-row-key=${t}
1866
- data-selected=${h ? "true" : "false"}
1867
- data-cut=${d ? "true" : "false"}
1868
- data-focused=${p ? "true" : "false"}
2056
+ data-selected=${d ? "true" : "false"}
2057
+ data-cut=${h ? "true" : "false"}
2058
+ data-focused=${u ? "true" : "false"}
1869
2059
  data-placeholder=${l ? "true" : "false"}
1870
- data-depth=${this._tree ? String(r) : u}
2060
+ data-depth=${this._tree ? String(r) : p}
1871
2061
  data-clickable=${!l && (this._selectionMode !== "none" || this.hasRowClickListeners()) ? "true" : "false"}
1872
- tabindex=${!l && (this._selectionMode !== "none" || this._tree) ? this._focusedRowKey === t || this._focusedRowKey === null && a === 0 ? "0" : "-1" : u}
2062
+ tabindex=${!l && (this._selectionMode !== "none" || this._tree) ? this._focusedRowKey === t || this._focusedRowKey === null && i === 0 ? "0" : "-1" : p}
1873
2063
  @focus=${l ? null : () => {
1874
2064
  this._focusedRowKey = t, this.requestUpdate();
1875
2065
  }}
1876
- @click=${l ? null : (m) => this.onRowClick(i, t, a, m)}
1877
- @dblclick=${l ? null : (m) => this.onRowDblClick(i, t, a, m)}
1878
- @contextmenu=${l ? null : (m) => this.onRowContextMenu(i, t, a, m)}
1879
- @keydown=${l ? null : (m) => this.onRowKeydown(i, t, a, e.parentId, r, o, f, m)}
2066
+ @click=${l ? null : (f) => this.onRowClick(a, t, i, f)}
2067
+ @dblclick=${l ? null : (f) => this.onRowDblClick(a, t, i, f)}
2068
+ @contextmenu=${l ? null : (f) => this.onRowContextMenu(a, t, i, f)}
2069
+ @keydown=${l ? null : (f) => this.onRowKeydown(a, t, i, e.parentId, r, o, m, f)}
1880
2070
  >
1881
2071
  ${this._tree ? c`<td class="tree-chevron-cell" style=${_({ paddingInlineStart: `${r * this._treeIndent}rem` })}>
1882
2072
  ${b ? c`<button
@@ -1885,21 +2075,21 @@ class X extends M {
1885
2075
  aria-label=${o ? this.mergedLabels.collapseRow : this.mergedLabels.expandRow}
1886
2076
  aria-expanded=${o ? "true" : "false"}
1887
2077
  data-expanded=${o ? "true" : "false"}
1888
- @click=${(m) => this.toggleExpand(i, e.parentId, r, m)}
1889
- >${o ? "▾" : "▸"}</button>` : u}
1890
- </td>` : u}
2078
+ @click=${(f) => this.toggleExpand(a, e.parentId, r, f)}
2079
+ >${o ? "▾" : "▸"}</button>` : p}
2080
+ </td>` : p}
1891
2081
  ${s ? c`<td
1892
- class=${w({ "checkbox-cell": !0, "checkbox-cell-toggles": this._selectionMode === "checkbox" })}
1893
- @click=${l ? (m) => m.stopPropagation() : (m) => this.onCheckboxCellClick(i, t, m)}
1894
- @dblclick=${(m) => m.stopPropagation()}
2082
+ class=${x({ "checkbox-cell": !0, "checkbox-cell-toggles": this._selectionMode === "checkbox" })}
2083
+ @click=${l ? (f) => f.stopPropagation() : (f) => this.onCheckboxCellClick(a, t, f)}
2084
+ @dblclick=${(f) => f.stopPropagation()}
1895
2085
  >
1896
- ${l ? u : c`<mp-checkbox
1897
- .checked=${h}
1898
- .indeterminate=${k}
1899
- @change=${() => this.onRowCheckboxToggle(i, t)}
2086
+ ${l ? p : c`<mp-checkbox
2087
+ .checked=${d}
2088
+ .indeterminate=${E}
2089
+ @change=${() => this.onRowCheckboxToggle(a, t)}
1900
2090
  ></mp-checkbox>`}
1901
- </td>` : u}
1902
- ${this._rowRenderer ? this.renderRowFromRenderer(i, a, { depth: r, isExpanded: o, isPlaceholder: l }) : l ? c`<td colspan=${this._columns.length} class="tree-placeholder-cell" aria-label=${this.mergedLabels.loading}>…</td>` : this._columns.map((m) => this.renderCell(i, m, a))}
2091
+ </td>` : p}
2092
+ ${this._rowRenderer ? this.renderRowFromRenderer(a, i, { depth: r, isExpanded: o, isPlaceholder: l }) : l ? c`<td colspan=${this._columns.length} class="tree-placeholder-cell" aria-label=${this.mergedLabels.loading}>…</td>` : this._columns.map((f) => this.renderCell(a, f, i))}
1903
2093
  </tr>
1904
2094
  `;
1905
2095
  }
@@ -1915,31 +2105,31 @@ class X extends M {
1915
2105
  */
1916
2106
  nameRowCheckboxes() {
1917
2107
  if (!this.isMulti) return;
1918
- const e = this.mergedLabels, t = new Map(this.computeVisibleRows().map((s) => [s.key, s])), a = this.renderRoot.querySelectorAll('tbody tr[data-row-key]:not([data-placeholder="true"])');
1919
- for (const s of a) {
1920
- const i = s.querySelector(":scope > td.checkbox-cell > mp-checkbox"), r = t.get(s.dataset.rowKey ?? "");
1921
- if (!i || !r) continue;
1922
- const o = this._rowLabel?.(r.row)?.trim(), l = s.querySelector(":scope > td:not(.checkbox-cell):not(.tree-chevron-cell)")?.textContent?.trim(), h = o || l, d = h ? e.selectRowNamed(h) : e.selectRow(r.rowIndex + 1);
1923
- i.getAttribute("aria-label") !== d && i.setAttribute("aria-label", d);
2108
+ const e = this.mergedLabels, t = new Map(this.computeVisibleRows().map((s) => [s.key, s])), i = this.renderRoot.querySelectorAll('tbody tr[data-row-key]:not([data-placeholder="true"])');
2109
+ for (const s of i) {
2110
+ const a = s.querySelector(":scope > td.checkbox-cell > mp-checkbox"), r = t.get(s.dataset.rowKey ?? "");
2111
+ if (!a || !r) continue;
2112
+ const o = this._rowLabel?.(r.row)?.trim(), l = s.querySelector(":scope > td:not(.checkbox-cell):not(.tree-chevron-cell)")?.textContent?.trim(), d = o || l, h = d ? e.selectRowNamed(d) : e.selectRow(r.rowIndex + 1);
2113
+ a.getAttribute("aria-label") !== h && a.setAttribute("aria-label", h);
1924
2114
  }
1925
2115
  }
1926
- renderRowFromRenderer(e, t, a) {
1927
- const s = this._rowRenderer(e, t, a);
2116
+ renderRowFromRenderer(e, t, i) {
2117
+ const s = this._rowRenderer(e, t, i);
1928
2118
  if (s == null)
1929
- return a.isPlaceholder ? c`<td colspan=${this._columns.length} class="tree-placeholder-cell" aria-label=${this.mergedLabels.loading}>…</td>` : this._columns.map((i) => this.renderCell(e, i, t));
1930
- if (Array.isArray(s) || J(s)) {
1931
- const i = [];
1932
- for (const r of s) i.push(r);
1933
- return i;
2119
+ return i.isPlaceholder ? c`<td colspan=${this._columns.length} class="tree-placeholder-cell" aria-label=${this.mergedLabels.loading}>…</td>` : this._columns.map((a) => this.renderCell(e, a, t));
2120
+ if (Array.isArray(s) || ie(s)) {
2121
+ const a = [];
2122
+ for (const r of s) a.push(r);
2123
+ return a;
1934
2124
  }
1935
2125
  return s;
1936
2126
  }
1937
- renderCell(e, t, a) {
1938
- const s = t.cellRenderer ? t.cellRenderer(e, t, a) : Y(e, t);
1939
- return c`<td class=${t.cellClass ?? ""} data-column=${t.name}>${C(s)}</td>`;
2127
+ renderCell(e, t, i) {
2128
+ const s = t.cellRenderer ? t.cellRenderer(e, t, i) : te(e, t);
2129
+ return c`<td class=${t.cellClass ?? ""} data-column=${t.name}>${S(s)}</td>`;
1940
2130
  }
1941
2131
  renderFooter(e) {
1942
- const t = Array.from({ length: e }, (a, s) => s + 1);
2132
+ const t = Array.from({ length: e }, (i, s) => s + 1);
1943
2133
  return c`
1944
2134
  <div class="datatable-footer">
1945
2135
  <mp-pagination
@@ -1948,7 +2138,7 @@ class X extends M {
1948
2138
  .pageNumbers=${this._perPageOptions}
1949
2139
  .selectedPageNumber=${this._perPage}
1950
2140
  .showArrows=${!1}
1951
- @mp-pagination-page-change=${(a) => this.setPerPage(a.detail.page)}
2141
+ @mp-pagination-page-change=${(i) => this.setPerPage(i.detail.page)}
1952
2142
  ></mp-pagination>
1953
2143
  <mp-pagination
1954
2144
  class="datatable-pagination"
@@ -1956,7 +2146,7 @@ class X extends M {
1956
2146
  .selectedPageNumber=${this._page}
1957
2147
  .numberOfBoxes=${7}
1958
2148
  .showArrows=${!0}
1959
- @mp-pagination-page-change=${(a) => this.gotoPage(a.detail.page)}
2149
+ @mp-pagination-page-change=${(i) => this.gotoPage(i.detail.page)}
1960
2150
  ></mp-pagination>
1961
2151
  </div>
1962
2152
  `;
@@ -1981,7 +2171,7 @@ class X extends M {
1981
2171
  if (this._tree || this.isRootWindowed())
1982
2172
  return this.getFlatList().map((t) => t.row);
1983
2173
  let e = this._data;
1984
- if (this._autoSort && this._sortColumns.length > 0 && (e = y(e, this._sortColumns)), this._pagination && !this.isExternallyPaged()) {
2174
+ if (this._autoSort && this._sortColumns.length > 0 && (e = v(e, this._sortColumns)), this._pagination && !this.isExternallyPaged()) {
1985
2175
  const t = (this._page - 1) * this._perPage;
1986
2176
  e = e.slice(t, t + this._perPage);
1987
2177
  }
@@ -2000,51 +2190,51 @@ class X extends M {
2000
2190
  if (this._cachedFlatList !== null) return this._cachedFlatList;
2001
2191
  if (!this._tree) {
2002
2192
  if (this.isRootWindowed()) {
2003
- const o = this._totalRecords ?? this._data.length, l = Math.max(1, this._perPage), h = new Array(o);
2004
- for (let d = 0; d < o; d++) {
2005
- const p = Math.floor(d / l) + 1, f = d % l, b = p === 1 ? this._data[f] : this._pageCache.get(p)?.[f];
2006
- h[d] = b !== void 0 ? { row: b, key: this._rowKey(b, d), depth: 0, parentId: null, isExpanded: !1, isPlaceholder: !1 } : { row: void 0, key: `__placeholder-flat-${d}`, depth: 0, parentId: null, page: p, isExpanded: !1, isPlaceholder: !0 };
2193
+ const o = this._totalRecords ?? this._data.length, l = Math.max(1, this._perPage), d = new Array(o);
2194
+ for (let h = 0; h < o; h++) {
2195
+ const u = Math.floor(h / l) + 1, m = h % l, b = u === 1 ? this._data[m] : this._pageCache.get(u)?.[m];
2196
+ d[h] = b !== void 0 ? { row: b, key: this._rowKey(b, h), depth: 0, parentId: null, isExpanded: !1, isPlaceholder: !1 } : { row: void 0, key: `__placeholder-flat-${h}`, depth: 0, parentId: null, page: u, isExpanded: !1, isPlaceholder: !0 };
2007
2197
  }
2008
- return this._cachedFlatList = h;
2198
+ return this._cachedFlatList = d;
2009
2199
  }
2010
- const i = this._pagination ? (this._page - 1) * this._perPage : 0, r = this._pagination && !this.isExternallyPaged() ? this.localSortedRows().slice(i, i + this._perPage) : this.localSortedRows();
2200
+ const a = this._pagination ? (this._page - 1) * this._perPage : 0, r = this._pagination && !this.isExternallyPaged() ? this.localSortedRows().slice(a, a + this._perPage) : this.localSortedRows();
2011
2201
  return this._cachedFlatList = r.map((o, l) => ({
2012
2202
  row: o,
2013
- key: this._rowKey(o, i + l),
2203
+ key: this._rowKey(o, a + l),
2014
2204
  depth: 0,
2015
2205
  parentId: null,
2016
2206
  isExpanded: !1,
2017
2207
  isPlaceholder: !1
2018
2208
  }));
2019
2209
  }
2020
- const e = [], t = Math.max(1, this._perPage), a = (i) => this._autoSort && this._sortColumns.length > 0 ? y(i, this._sortColumns) : i, s = (i, r, o) => {
2021
- const l = this.extractId(i), h = l != null && this._expandedIds.has(l), d = this.extractChildCount(i);
2022
- if (e.push({ row: i, key: this._rowKey(i, e.length), depth: r, parentId: o, isExpanded: h, isPlaceholder: !1 }), !h || d === 0 || l == null) return;
2023
- const p = this._childCache.get(l);
2024
- if (p && p.length > 0) {
2025
- for (const b of a(p)) s(b, r + 1, l);
2026
- const f = this._childTotals.get(l) ?? p.length;
2027
- for (let b = 0; b < Math.max(0, f - p.length); b++)
2028
- e.push({ row: void 0, key: `__placeholder-${String(l)}-${p.length + b}`, depth: r + 1, parentId: l, isExpanded: !1, isPlaceholder: !0 });
2210
+ const e = [], t = Math.max(1, this._perPage), i = (a) => this._autoSort && this._sortColumns.length > 0 ? v(a, this._sortColumns) : a, s = (a, r, o) => {
2211
+ const l = this.extractId(a), d = l != null && this._expandedIds.has(l), h = this.extractChildCount(a);
2212
+ if (e.push({ row: a, key: this._rowKey(a, e.length), depth: r, parentId: o, isExpanded: d, isPlaceholder: !1 }), !d || h === 0 || l == null) return;
2213
+ const u = this._childCache.get(l);
2214
+ if (u && u.length > 0) {
2215
+ for (const b of i(u)) s(b, r + 1, l);
2216
+ const m = this._childTotals.get(l) ?? u.length;
2217
+ for (let b = 0; b < Math.max(0, m - u.length); b++)
2218
+ e.push({ row: void 0, key: `__placeholder-${String(l)}-${u.length + b}`, depth: r + 1, parentId: l, isExpanded: !1, isPlaceholder: !0 });
2029
2219
  } else
2030
- for (let f = 0; f < d; f++)
2031
- e.push({ row: void 0, key: `__placeholder-${String(l)}-${f}`, depth: r + 1, parentId: l, isExpanded: !1, isPlaceholder: !0 });
2220
+ for (let m = 0; m < h; m++)
2221
+ e.push({ row: void 0, key: `__placeholder-${String(l)}-${m}`, depth: r + 1, parentId: l, isExpanded: !1, isPlaceholder: !0 });
2032
2222
  };
2033
2223
  if (this.isRootWindowed()) {
2034
- const i = this._totalRecords ?? this._data.length;
2035
- for (let r = 0; r < i; r++) {
2036
- const o = Math.floor(r / t) + 1, l = r % t, h = o === 1 ? this._data[l] : this._pageCache.get(o)?.[l];
2037
- h === void 0 ? e.push({ row: void 0, key: `__placeholder-root-${r}`, depth: 0, parentId: null, page: o, isExpanded: !1, isPlaceholder: !0 }) : s(h, 0, null);
2224
+ const a = this._totalRecords ?? this._data.length;
2225
+ for (let r = 0; r < a; r++) {
2226
+ const o = Math.floor(r / t) + 1, l = r % t, d = o === 1 ? this._data[l] : this._pageCache.get(o)?.[l];
2227
+ d === void 0 ? e.push({ row: void 0, key: `__placeholder-root-${r}`, depth: 0, parentId: null, page: o, isExpanded: !1, isPlaceholder: !0 }) : s(d, 0, null);
2038
2228
  }
2039
2229
  } else {
2040
- const i = this._autoSort && this._sortColumns.length > 0 ? y(this._data, this._sortColumns) : this._data;
2041
- for (const r of i) s(r, 0, null);
2230
+ const a = this._autoSort && this._sortColumns.length > 0 ? v(this._data, this._sortColumns) : this._data;
2231
+ for (const r of a) s(r, 0, null);
2042
2232
  }
2043
2233
  return this._cachedFlatList = e;
2044
2234
  }
2045
2235
  /** `_data` in display order: client-sorted when the WC owns sorting. */
2046
2236
  localSortedRows() {
2047
- return this._autoSort && this._sortColumns.length > 0 ? y(this._data, this._sortColumns) : this._data;
2237
+ return this._autoSort && this._sortColumns.length > 0 ? v(this._data, this._sortColumns) : this._data;
2048
2238
  }
2049
2239
  /**
2050
2240
  * Drops the flat-list memo. It is otherwise reset only in `willUpdate`, so a
@@ -2061,8 +2251,8 @@ class X extends M {
2061
2251
  * loaded, so rows of the other pages are keyed by their global index too.
2062
2252
  */
2063
2253
  liveRowEntries(e) {
2064
- const t = e.filter((a) => !a.isPlaceholder).map((a) => [a.key, a.row]);
2065
- return this._tree || !this._pagination || this.isExternallyPaged() ? t : this.localSortedRows().map((a, s) => [this._rowKey(a, s), a]);
2254
+ const t = e.filter((i) => !i.isPlaceholder).map((i) => [i.key, i.row]);
2255
+ return this._tree || !this._pagination || this.isExternallyPaged() ? t : this.localSortedRows().map((i, s) => [this._rowKey(i, s), i]);
2066
2256
  }
2067
2257
  /**
2068
2258
  * The key the renderer gives a row object. A row outside the live entries (a
@@ -2072,7 +2262,7 @@ class X extends M {
2072
2262
  */
2073
2263
  keyOfRow(e) {
2074
2264
  const t = this.getFlatList();
2075
- return this._keyByRowMemo?.list !== t && (this._keyByRowMemo = { list: t, byRow: new Map(this.liveRowEntries(t).map(([a, s]) => [s, a])) }), this._keyByRowMemo.byRow.get(e) ?? this._rowKey(e, -1);
2265
+ return this._keyByRowMemo?.list !== t && (this._keyByRowMemo = { list: t, byRow: new Map(this.liveRowEntries(t).map(([i, s]) => [s, i])) }), this._keyByRowMemo.byRow.get(e) ?? this._rowKey(e, -1);
2076
2266
  }
2077
2267
  /** `keyOfRow` against the current data, for paths that may run before a re-render. */
2078
2268
  rowKeyLookup() {
@@ -2080,14 +2270,14 @@ class X extends M {
2080
2270
  }
2081
2271
  computeVisibleRows() {
2082
2272
  const e = this.getFlatList(), t = this._tree ? 0 : this._pagination ? (this._page - 1) * this._perPage : 0;
2083
- let a = e, s = 0;
2273
+ let i = e, s = 0;
2084
2274
  if (this._virtualScroll) {
2085
- const { startIndex: i, endIndex: r } = this._virtualRange;
2086
- a = e.slice(i, r), s = i;
2275
+ const { startIndex: a, endIndex: r } = this._virtualRange;
2276
+ i = e.slice(a, r), s = a;
2087
2277
  }
2088
- return a.map((i, r) => {
2278
+ return i.map((a, r) => {
2089
2279
  const o = t + s + r;
2090
- return { row: i.row, rowIndex: o, key: i.key, flat: i };
2280
+ return { row: a.row, rowIndex: o, key: a.key, flat: a };
2091
2281
  });
2092
2282
  }
2093
2283
  // ─── Tree-mode helpers ───────────────────────────────────────────────────
@@ -2105,8 +2295,8 @@ class X extends M {
2105
2295
  * remembers the rows it selected.
2106
2296
  */
2107
2297
  collectDescendants(e) {
2108
- const t = this.extractId(e), a = t != null ? this._childCache.get(t) : void 0;
2109
- return a ? a.flatMap((s) => [[this.keyOfRow(s), s], ...this.collectDescendants(s)]) : [];
2298
+ const t = this.extractId(e), i = t != null ? this._childCache.get(t) : void 0;
2299
+ return i ? i.flatMap((s) => [[this.keyOfRow(s), s], ...this.collectDescendants(s)]) : [];
2110
2300
  }
2111
2301
  /** Some-but-not-all loaded descendants selected → indeterminate parent checkbox. */
2112
2302
  isParentIndeterminate(e, t) {
@@ -2124,19 +2314,19 @@ class X extends M {
2124
2314
  const e = /* @__PURE__ */ new Set();
2125
2315
  if (this._selectionStrategy !== "cascading" || !this._tree)
2126
2316
  return this._cachedIndeterminateKeys = e;
2127
- const t = (a) => {
2128
- const s = this.extractId(a);
2317
+ const t = (i) => {
2318
+ const s = this.extractId(i);
2129
2319
  if (s == null) return { selected: 0, total: 0 };
2130
- const i = this._childCache.get(s);
2131
- if (!i || i.length === 0) return { selected: 0, total: 0 };
2320
+ const a = this._childCache.get(s);
2321
+ if (!a || a.length === 0) return { selected: 0, total: 0 };
2132
2322
  let r = 0, o = 0;
2133
- for (const l of i) {
2134
- const h = this.keyOfRow(l), d = this._selectedIds.has(h) ? 1 : 0, p = t(l);
2135
- r += d + p.selected, o += 1 + p.total;
2323
+ for (const l of a) {
2324
+ const d = this.keyOfRow(l), h = this._selectedIds.has(d) ? 1 : 0, u = t(l);
2325
+ r += h + u.selected, o += 1 + u.total;
2136
2326
  }
2137
- return o > 0 && r > 0 && r < o && e.add(this.keyOfRow(a)), { selected: r, total: o };
2327
+ return o > 0 && r > 0 && r < o && e.add(this.keyOfRow(i)), { selected: r, total: o };
2138
2328
  };
2139
- for (const a of this._data) t(a);
2329
+ for (const i of this._data) t(i);
2140
2330
  return this._cachedIndeterminateKeys = e;
2141
2331
  }
2142
2332
  /**
@@ -2144,21 +2334,21 @@ class X extends M {
2144
2334
  * children aren't cached yet so the wrapper can bridge to the consumer's
2145
2335
  * `[fetch]` callback. Always fires `expanded-ids-change`.
2146
2336
  */
2147
- toggleExpand(e, t, a, s) {
2337
+ toggleExpand(e, t, i, s) {
2148
2338
  s.stopPropagation(), s.preventDefault();
2149
- const i = this.extractId(e);
2150
- if (i == null) return;
2339
+ const a = this.extractId(e);
2340
+ if (a == null) return;
2151
2341
  const r = new Set(this._expandedIds);
2152
2342
  let o;
2153
- r.has(i) ? (r.delete(i), o = !1) : (r.add(i), o = !0), this._expandedIds = r, o ? (this.dispatchEvent(
2343
+ r.has(a) ? (r.delete(a), o = !1) : (r.add(a), o = !0), this._expandedIds = r, o ? (this.dispatchEvent(
2154
2344
  new CustomEvent("mp-datatable-row-expand", {
2155
- detail: { row: e, depth: a, parentId: t },
2345
+ detail: { row: e, depth: i, parentId: t },
2156
2346
  bubbles: !0,
2157
2347
  composed: !0
2158
2348
  })
2159
- ), this.extractChildCount(e) > 0 && !this._childCache.has(i) && !this._pendingFetches.has(i) && this.fetchChildren(i)) : this.dispatchEvent(
2349
+ ), this.extractChildCount(e) > 0 && !this._childCache.has(a) && !this._pendingFetches.has(a) && this.fetchChildren(a)) : this.dispatchEvent(
2160
2350
  new CustomEvent("mp-datatable-row-collapse", {
2161
- detail: { row: e, depth: a, parentId: t },
2351
+ detail: { row: e, depth: i, parentId: t },
2162
2352
  bubbles: !0,
2163
2353
  composed: !0
2164
2354
  })
@@ -2185,13 +2375,13 @@ class X extends M {
2185
2375
  this._pendingPageFetches.add(e);
2186
2376
  const t = this._fetchGeneration;
2187
2377
  try {
2188
- const a = await this._fetch({ parentId: null, page: e, perPage: this._perPage, sortColumns: [...this._sortColumns] });
2378
+ const i = await this._fetch({ parentId: null, page: e, perPage: this._perPage, sortColumns: [...this._sortColumns] });
2189
2379
  if (t !== this._fetchGeneration || !this._fetch) return;
2190
- this._pendingPageFetches.delete(e), this._pageCache.set(e, [...a?.data ?? []]);
2191
- const s = a?.totalRecords == null ? null : Math.max(0, Math.floor(a.totalRecords));
2380
+ this._pendingPageFetches.delete(e), this._pageCache.set(e, [...i?.data ?? []]);
2381
+ const s = i?.totalRecords == null ? null : Math.max(0, Math.floor(i.totalRecords));
2192
2382
  s != null && (this._totalRecords = s), this.requestUpdate();
2193
- } catch (a) {
2194
- this._pendingPageFetches.delete(e), console.error("[mp-datatable] fetch failed for root page", e, a);
2383
+ } catch (i) {
2384
+ this._pendingPageFetches.delete(e), console.error("[mp-datatable] fetch failed for root page", e, i);
2195
2385
  }
2196
2386
  }
2197
2387
  /**
@@ -2203,11 +2393,11 @@ class X extends M {
2203
2393
  this._pendingFetches.add(e);
2204
2394
  const t = this._fetchGeneration;
2205
2395
  try {
2206
- const a = await this._fetch({ parentId: e, page: 1, perPage: this._perPage, sortColumns: [...this._sortColumns] });
2396
+ const i = await this._fetch({ parentId: e, page: 1, perPage: this._perPage, sortColumns: [...this._sortColumns] });
2207
2397
  if (t !== this._fetchGeneration || !this._fetch) return;
2208
- this._pendingFetches.delete(e), this._childCache.set(e, [...a?.data ?? []]), this._childTotals.set(e, a?.totalRecords ?? a?.data?.length ?? 0), this.requestUpdate();
2209
- } catch (a) {
2210
- this._pendingFetches.delete(e), console.error("[mp-datatable] fetch failed for children of", e, a);
2398
+ this._pendingFetches.delete(e), this._childCache.set(e, [...i?.data ?? []]), this._childTotals.set(e, i?.totalRecords ?? i?.data?.length ?? 0), this.requestUpdate();
2399
+ } catch (i) {
2400
+ this._pendingFetches.delete(e), console.error("[mp-datatable] fetch failed for children of", e, i);
2211
2401
  }
2212
2402
  }
2213
2403
  /**
@@ -2218,16 +2408,16 @@ class X extends M {
2218
2408
  async loadPage(e) {
2219
2409
  if (!this._fetch) return;
2220
2410
  const t = this._fetchGeneration;
2221
- let a;
2411
+ let i;
2222
2412
  try {
2223
- a = await this._fetch({ parentId: null, page: e, perPage: this._perPage, sortColumns: [...this._sortColumns] });
2224
- } catch (i) {
2225
- console.error("[mp-datatable] fetch failed for page", e, i);
2413
+ i = await this._fetch({ parentId: null, page: e, perPage: this._perPage, sortColumns: [...this._sortColumns] });
2414
+ } catch (a) {
2415
+ console.error("[mp-datatable] fetch failed for page", e, a);
2226
2416
  return;
2227
2417
  }
2228
2418
  if (t !== this._fetchGeneration || !this._fetch) return;
2229
- this._data = [...a?.data ?? []];
2230
- const s = a?.totalRecords == null ? null : Math.max(0, Math.floor(a.totalRecords));
2419
+ this._data = [...i?.data ?? []];
2420
+ const s = i?.totalRecords == null ? null : Math.max(0, Math.floor(i.totalRecords));
2231
2421
  this._totalRecords = s, this._initialFetchDone = !0, this.requestUpdate();
2232
2422
  }
2233
2423
  /**
@@ -2254,23 +2444,23 @@ class X extends M {
2254
2444
  * and emit row-click. 'checkbox': Enter only emits row-click, Space only
2255
2445
  * toggles the row's checkbox.
2256
2446
  */
2257
- onRowKeydown(e, t, a, s, i, r, o, l) {
2447
+ onRowKeydown(e, t, i, s, a, r, o, l) {
2258
2448
  if (!l.altKey && l.composedPath()[0] === l.currentTarget) {
2259
2449
  if (l.key === "ArrowDown" || l.key === "ArrowUp") {
2260
2450
  l.preventDefault();
2261
- const h = Array.from(
2451
+ const d = Array.from(
2262
2452
  this.renderRoot.querySelectorAll("tbody tr[data-row-key]")
2263
- ), d = h.findIndex((f) => f.dataset.rowKey === t), p = h[d + (l.key === "ArrowDown" ? 1 : -1)];
2264
- p && p.focus();
2453
+ ), h = d.findIndex((m) => m.dataset.rowKey === t), u = d[h + (l.key === "ArrowDown" ? 1 : -1)];
2454
+ u && u.focus();
2265
2455
  return;
2266
2456
  }
2267
2457
  if (this._tree) {
2268
2458
  if (l.key === "ArrowRight" && o > 0 && !r) {
2269
- this.toggleExpand(e, s, i, l);
2459
+ this.toggleExpand(e, s, a, l);
2270
2460
  return;
2271
2461
  }
2272
2462
  if (l.key === "ArrowLeft" && r) {
2273
- this.toggleExpand(e, s, i, l);
2463
+ this.toggleExpand(e, s, a, l);
2274
2464
  return;
2275
2465
  }
2276
2466
  }
@@ -2281,7 +2471,7 @@ class X extends M {
2281
2471
  }
2282
2472
  this.requestUpdate(), this.dispatchEvent(
2283
2473
  new CustomEvent("mp-datatable-row-click", {
2284
- detail: { row: e, rowIndex: a, rowKey: t, originalEvent: l },
2474
+ detail: { row: e, rowIndex: i, rowKey: t, originalEvent: l },
2285
2475
  bubbles: !0,
2286
2476
  composed: !0
2287
2477
  })
@@ -2290,7 +2480,7 @@ class X extends M {
2290
2480
  }
2291
2481
  (l.key === "Enter" || l.key === " ") && this._selectionMode !== "none" && (l.preventDefault(), this._focusedRowKey = t, this.handleSelectionOnClick(e, t, l), this.requestUpdate(), this.dispatchEvent(
2292
2482
  new CustomEvent("mp-datatable-row-click", {
2293
- detail: { row: e, rowIndex: a, rowKey: t, originalEvent: l },
2483
+ detail: { row: e, rowIndex: i, rowKey: t, originalEvent: l },
2294
2484
  bubbles: !0,
2295
2485
  composed: !0
2296
2486
  })
@@ -2305,44 +2495,44 @@ class X extends M {
2305
2495
  * the resize handle is the button's sibling, so its clicks never land here.
2306
2496
  */
2307
2497
  onHeaderClick(e, t) {
2308
- const a = H(this._sortColumns, e.name, t.shiftKey);
2309
- this._sortColumns = a, this._page = 1;
2310
- const s = a.find((i) => i.property === e.name);
2498
+ const i = G(this._sortColumns, e.name, t.shiftKey);
2499
+ this._sortColumns = i, this._page = 1;
2500
+ const s = i.find((a) => a.property === e.name);
2311
2501
  this.liveAnnouncer.announce(
2312
2502
  this.mergedLabels.announceSorted(
2313
- e.label ?? e.name,
2503
+ this.columnLabel(e),
2314
2504
  s ? s.direction === "ascending" ? "ascending" : "descending" : "none"
2315
2505
  )
2316
2506
  ), this.requestUpdate(), this.scheduleFetchReload(), this.dispatchEvent(
2317
2507
  new CustomEvent("mp-datatable-sort-change", {
2318
- detail: { sortColumns: a },
2508
+ detail: { sortColumns: i },
2319
2509
  bubbles: !0,
2320
2510
  composed: !0
2321
2511
  })
2322
2512
  );
2323
2513
  }
2324
- onRowClick(e, t, a, s) {
2514
+ onRowClick(e, t, i, s) {
2325
2515
  this._focusedRowKey = t, this._selectionMode !== "checkbox" && this.handleSelectionOnClick(e, t, s), this.requestUpdate(), this.dispatchEvent(
2326
2516
  new CustomEvent("mp-datatable-row-click", {
2327
- detail: { row: e, rowIndex: a, rowKey: t, originalEvent: s },
2517
+ detail: { row: e, rowIndex: i, rowKey: t, originalEvent: s },
2328
2518
  bubbles: !0,
2329
2519
  composed: !0
2330
2520
  })
2331
2521
  );
2332
2522
  }
2333
- onRowDblClick(e, t, a, s) {
2523
+ onRowDblClick(e, t, i, s) {
2334
2524
  this.dispatchEvent(
2335
2525
  new CustomEvent("mp-datatable-row-dblclick", {
2336
- detail: { row: e, rowIndex: a, rowKey: t, originalEvent: s },
2526
+ detail: { row: e, rowIndex: i, rowKey: t, originalEvent: s },
2337
2527
  bubbles: !0,
2338
2528
  composed: !0
2339
2529
  })
2340
2530
  );
2341
2531
  }
2342
- onRowContextMenu(e, t, a, s) {
2532
+ onRowContextMenu(e, t, i, s) {
2343
2533
  this._selectionMode !== "none" && this._selectionMode !== "checkbox" && !this._selectedIds.has(t) && (this.commitSelection([t], [[t, e]]), this._focusedRowKey = t, this.emitSelectionChange(), this.requestUpdate()), this.dispatchEvent(
2344
2534
  new CustomEvent("mp-datatable-row-contextmenu", {
2345
- detail: { row: e, rowIndex: a, rowKey: t, originalEvent: s },
2535
+ detail: { row: e, rowIndex: i, rowKey: t, originalEvent: s },
2346
2536
  bubbles: !0,
2347
2537
  composed: !0,
2348
2538
  cancelable: !0
@@ -2363,18 +2553,18 @@ class X extends M {
2363
2553
  * preventDefault(): the browser focuses the row natively, which keeps Enter,
2364
2554
  * Space and the arrow keys working from there (spike S4).
2365
2555
  */
2366
- onCheckboxCellClick(e, t, a) {
2367
- if (a.stopPropagation(), this._selectionMode !== "checkbox") return;
2368
- const s = a.currentTarget.querySelector("mp-checkbox")?.shadowRoot;
2369
- s && a.composedPath().includes(s) || this.onRowCheckboxToggle(e, t);
2556
+ onCheckboxCellClick(e, t, i) {
2557
+ if (i.stopPropagation(), this._selectionMode !== "checkbox") return;
2558
+ const s = i.currentTarget.querySelector("mp-checkbox")?.shadowRoot;
2559
+ s && i.composedPath().includes(s) || this.onRowCheckboxToggle(e, t);
2370
2560
  }
2371
2561
  /** Row checkboxes render only in the multi-select modes, so this is multi-select toggling. */
2372
2562
  onRowCheckboxToggle(e, t) {
2373
- const a = !this._selectedIds.has(t), s = [
2563
+ const i = !this._selectedIds.has(t), s = [
2374
2564
  [t, e],
2375
2565
  ...this._tree && this._selectionStrategy === "cascading" ? this.collectDescendants(e) : []
2376
- ], i = new Set(s.map(([r]) => r));
2377
- a ? this.commitSelection([...this._selectedIds, ...i], s) : this.commitSelection([...this._selectedIds].filter((r) => !i.has(r))), this.emitSelectionChange(), this.requestUpdate();
2566
+ ], a = new Set(s.map(([r]) => r));
2567
+ i ? this.commitSelection([...this._selectedIds, ...a], s) : this.commitSelection([...this._selectedIds].filter((r) => !a.has(r))), this.emitSelectionChange(), this.requestUpdate();
2378
2568
  }
2379
2569
  /**
2380
2570
  * Clears the entire selection. The header checkbox is only rendered when
@@ -2386,26 +2576,26 @@ class X extends M {
2386
2576
  onDeselectAll() {
2387
2577
  this._selectedIds.size !== 0 && (this.commitSelection([]), this.emitSelectionChange(), this.requestUpdate());
2388
2578
  }
2389
- handleSelectionOnClick(e, t, a) {
2579
+ handleSelectionOnClick(e, t, i) {
2390
2580
  if (this._selectionMode !== "none") {
2391
2581
  if (this._selectionMode === "single") {
2392
2582
  this.commitSelection([t], [[t, e]]), this.emitSelectionChange();
2393
2583
  return;
2394
2584
  }
2395
- if (a.shiftKey && this._selectionAnchorKey && this._selectionAnchorKey !== t) {
2396
- const s = this.getFlatList(), i = s.findIndex((o) => !o.isPlaceholder && o.key === this._selectionAnchorKey), r = s.findIndex((o) => o.key === t);
2397
- if (i >= 0 && r >= 0) {
2398
- const [o, l] = i < r ? [i, r] : [r, i], h = s.slice(o, l + 1);
2399
- if (h.some((p) => p.isPlaceholder)) {
2585
+ if (i.shiftKey && this._selectionAnchorKey && this._selectionAnchorKey !== t) {
2586
+ const s = this.getFlatList(), a = s.findIndex((o) => !o.isPlaceholder && o.key === this._selectionAnchorKey), r = s.findIndex((o) => o.key === t);
2587
+ if (a >= 0 && r >= 0) {
2588
+ const [o, l] = a < r ? [a, r] : [r, a], d = s.slice(o, l + 1);
2589
+ if (d.some((u) => u.isPlaceholder)) {
2400
2590
  this.liveAnnouncer.announce(this.mergedLabels.rangeIncomplete);
2401
2591
  return;
2402
2592
  }
2403
- const d = h.map((p) => [p.key, p.row]);
2404
- this.commitSelection([...this._selectedIds, ...d.map(([p]) => p)], d), this.emitSelectionChange();
2593
+ const h = d.map((u) => [u.key, u.row]);
2594
+ this.commitSelection([...this._selectedIds, ...h.map(([u]) => u)], h), this.emitSelectionChange();
2405
2595
  return;
2406
2596
  }
2407
2597
  }
2408
- if (a.ctrlKey || a.metaKey) {
2598
+ if (i.ctrlKey || i.metaKey) {
2409
2599
  const s = new Set(this._selectedIds);
2410
2600
  s.has(t) ? s.delete(t) : s.add(t), this.commitSelection(s, [[t, e]]), this._selectionAnchorKey = t, this.emitSelectionChange();
2411
2601
  return;
@@ -2420,8 +2610,8 @@ class X extends M {
2420
2610
  */
2421
2611
  commitSelection(e, t = []) {
2422
2612
  this._selectedIds = new Set(e);
2423
- for (const [a, s] of t)
2424
- s !== void 0 && this._selectedIds.has(a) && this._selectedRowCache.set(a, s);
2613
+ for (const [i, s] of t)
2614
+ s !== void 0 && this._selectedIds.has(i) && this._selectedRowCache.set(i, s);
2425
2615
  this.pruneSelectedRowCache();
2426
2616
  }
2427
2617
  /**
@@ -2432,9 +2622,9 @@ class X extends M {
2432
2622
  liveRowMap() {
2433
2623
  const e = new Map(this.liveRowEntries(this.freshFlatList()));
2434
2624
  for (const t of this._childCache.values())
2435
- for (const a of t) {
2436
- const s = this.keyOfRow(a);
2437
- e.has(s) || e.set(s, a);
2625
+ for (const i of t) {
2626
+ const s = this.keyOfRow(i);
2627
+ e.has(s) || e.set(s, i);
2438
2628
  }
2439
2629
  return e;
2440
2630
  }
@@ -2450,9 +2640,9 @@ class X extends M {
2450
2640
  isSameSelectedRows(e) {
2451
2641
  if (e.length !== this._selectedIds.size) return !1;
2452
2642
  const t = [...this._selectedIds];
2453
- if (!e.every(([s], i) => s === t[i])) return !1;
2454
- const a = this.resolveRows(t);
2455
- return e.every(([, s], i) => s === a[i]);
2643
+ if (!e.every(([s], a) => s === t[a])) return !1;
2644
+ const i = this.resolveRows(t);
2645
+ return e.every(([, s], a) => s === i[a]);
2456
2646
  }
2457
2647
  /** Forgets the rows of keys that left the selection. One pass, deletes in place. */
2458
2648
  pruneSelectedRowCache() {
@@ -2481,14 +2671,14 @@ class X extends M {
2481
2671
  resolveRows(e) {
2482
2672
  if (e.length === 0) return [];
2483
2673
  const t = this.liveRowMap();
2484
- return e.map((a) => {
2485
- const s = t.get(a);
2486
- return s === void 0 ? this._selectedRowCache.get(a) : (this._selectedIds.has(a) && this._selectedRowCache.set(a, s), s);
2674
+ return e.map((i) => {
2675
+ const s = t.get(i);
2676
+ return s === void 0 ? this._selectedRowCache.get(i) : (this._selectedIds.has(i) && this._selectedRowCache.set(i, s), s);
2487
2677
  });
2488
2678
  }
2489
2679
  gotoPage(e) {
2490
- const t = this._totalRecords ?? this._data.length, a = Math.max(1, Math.ceil(t / this._perPage));
2491
- this._page = Math.max(1, Math.min(a, e)), this.liveAnnouncer.announce(this.mergedLabels.announcePage(this._page, a)), this.requestUpdate(), this.scheduleFetchReload(), this.dispatchEvent(
2680
+ const t = this._totalRecords ?? this._data.length, i = Math.max(1, Math.ceil(t / this._perPage));
2681
+ this._page = Math.max(1, Math.min(i, e)), this.liveAnnouncer.announce(this.mergedLabels.announcePage(this._page, i)), this.requestUpdate(), this.scheduleFetchReload(), this.dispatchEvent(
2492
2682
  new CustomEvent("mp-datatable-page-change", {
2493
2683
  detail: { page: this._page },
2494
2684
  bubbles: !0,
@@ -2496,46 +2686,199 @@ class X extends M {
2496
2686
  })
2497
2687
  );
2498
2688
  }
2689
+ /**
2690
+ * Every resize path ends here. A user-set width is never re-fitted when the
2691
+ * scroller resizes (see `refitMeasuredWidths`): the user chose it.
2692
+ */
2693
+ setUserColumnWidth(e, t) {
2694
+ this.freezeColumnWidths(), this._columnWidths = new Map(this._columnWidths), this._columnWidths.set(e, t), this._userWidths.add(e), this.requestUpdate();
2695
+ }
2696
+ currentColumnWidth(e) {
2697
+ return this._columnWidths.get(e.name) ?? this.headerCell(e.name)?.getBoundingClientRect().width ?? 100;
2698
+ }
2699
+ /**
2700
+ * Before the first user resize, pins every column at the width it RENDERS
2701
+ * and gives the table that total as an explicit width.
2702
+ *
2703
+ * Without this the resized edge does not follow the pointer. The table is
2704
+ * 100% wide with fixed layout, so whenever the pins add up to less than the
2705
+ * container the slack is shared out over every column, the one being
2706
+ * resized included: widening it shrinks its share (it grows slower than the
2707
+ * pointer), narrowing it grows its share (it hardly moves). With an explicit
2708
+ * width equal to the sum there is no slack to share, so a column is exactly
2709
+ * as wide as its pin and the edge tracks the pointer 1:1. Narrowing then
2710
+ * leaves room on the right, as in a spreadsheet, instead of refusing to move.
2711
+ *
2712
+ * Idempotent. Unfrozen again when the last user width is reset.
2713
+ */
2714
+ freezeColumnWidths() {
2715
+ if (this._frozenExtraWidth != null || !this.renderRoot) return;
2716
+ const e = this.renderRoot.querySelector("table");
2717
+ if (!e) return;
2718
+ const t = this._columns.map((s) => [s.name, this.headerCell(s.name)?.getBoundingClientRect().width ?? 0]).filter(([, s]) => s > 0);
2719
+ if (t.length === 0) return;
2720
+ const i = t.reduce((s, [, a]) => s + a, 0);
2721
+ this._frozenExtraWidth = Math.max(0, e.getBoundingClientRect().width - i), this._columnWidths = new Map([...this._columnWidths, ...t]), this._frozenWidths = new Map(t);
2722
+ }
2723
+ frozenTableWidth() {
2724
+ return this._columns.reduce((t, i) => t + (this._columnWidths.get(i.name) ?? 0), 0) + (this._frozenExtraWidth ?? 0);
2725
+ }
2726
+ headerCell(e) {
2727
+ return this.renderRoot?.querySelector(
2728
+ `thead tr:first-child th[data-column="${e}"]`
2729
+ ) ?? null;
2730
+ }
2731
+ resizeHandle(e) {
2732
+ return this.headerCell(e)?.querySelector(".resize-handle") ?? null;
2733
+ }
2499
2734
  /**
2500
2735
  * Keyboard column resize — the same ±px model as the pointer path, same 40px
2501
- * floor. The handle is a focusable role="separator"; without this it was the
2502
- * audit's pointer-only finding for the datatable.
2736
+ * floor. Enter opens the same options dialog a tap does, so every pointer
2737
+ * path has a keyboard twin and the other way round.
2503
2738
  */
2504
2739
  onResizeHandleKeydown(e, t) {
2505
- if (!this._resizableColumns || t.key !== "ArrowLeft" && t.key !== "ArrowRight") return;
2506
- t.preventDefault(), t.stopPropagation();
2507
- const s = t.currentTarget.closest("th"), i = this._columnWidths.get(e.name) ?? s?.getBoundingClientRect().width ?? 100, r = $(
2508
- i,
2509
- t.key === "ArrowRight" ? R : -R
2510
- );
2511
- this._columnWidths = new Map(this._columnWidths), this._columnWidths.set(e.name, r), this.requestUpdate();
2740
+ if (this.isColumnResizable(e)) {
2741
+ if (t.key === "Enter") {
2742
+ t.preventDefault(), t.stopPropagation(), this.openResizePanel(e);
2743
+ return;
2744
+ }
2745
+ t.key !== "ArrowLeft" && t.key !== "ArrowRight" || (t.preventDefault(), t.stopPropagation(), this.stepColumnWidth(e, t.key === "ArrowRight" ? w : -w));
2746
+ }
2747
+ }
2748
+ stepColumnWidth(e, t) {
2749
+ this.freezeColumnWidths(), this.setUserColumnWidth(e.name, M(this.currentColumnWidth(e), t));
2512
2750
  }
2751
+ /** The keymap, spoken once per element: a separator gives no hint of Enter on its own. */
2752
+ onResizeHandleFocus() {
2753
+ this._resizeHintAnnounced || (this._resizeHintAnnounced = !0, this.liveAnnouncer.announce(this.mergedLabels.resizeColumnHint));
2754
+ }
2755
+ /**
2756
+ * A press on a handle is a drag only once it moves past `RESIZE_TAP_SLOP`;
2757
+ * released before that it is a tap, and a tap opens the options dialog. That
2758
+ * dialog is the single-pointer alternative WCAG 2.5.7 requires for the drag,
2759
+ * and the arrow keys do not count as one.
2760
+ *
2761
+ * The gesture itself is protected by `touch-action: none` on the handle, not
2762
+ * by anything here: `preventDefault()` on pointerdown does not stop a touch
2763
+ * pan, and a pan the browser claims ends in `pointercancel`.
2764
+ */
2513
2765
  startColumnResize(e, t) {
2514
- if (!this._resizableColumns) return;
2766
+ if (!this.isColumnResizable(e) || t.pointerType === "mouse" && t.button !== 0) return;
2515
2767
  t.preventDefault(), t.stopPropagation();
2516
- const a = t.currentTarget, s = a.closest("th");
2517
- if (!s) return;
2518
- const i = s.getBoundingClientRect().width;
2519
- this.resizeState = { columnName: e.name, startX: t.clientX, startWidth: i, 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);
2768
+ const i = t.currentTarget, s = i.closest("th");
2769
+ s && (this.resizeState = {
2770
+ column: e,
2771
+ pointerId: t.pointerId,
2772
+ startX: t.clientX,
2773
+ startWidth: s.getBoundingClientRect().width,
2774
+ handle: i,
2775
+ dragging: !1
2776
+ }, i.classList.add("active"), i.setPointerCapture(t.pointerId), i.addEventListener("pointermove", this.onColumnResizeMove), i.addEventListener("pointerup", this.onColumnResizeEnd), i.addEventListener("pointercancel", this.onColumnResizeEnd));
2777
+ }
2778
+ openResizePanel(e) {
2779
+ this.filterOverlay.isOpen && this.filterOverlay.close(!1), this.resizeOverlay.isOpen && this.resizeOverlay.close(!1), this.resizeHandle(e.name)?.focus({ preventScroll: !0 }), this._openResizeColumn = e.name, this.requestUpdate(), this.resizeOverlay.open();
2520
2780
  }
2781
+ /**
2782
+ * The resize options dialog: step narrower, step wider, fit, reset. Rendered
2783
+ * into the overlay pane with a render() of its own, like the filter panel,
2784
+ * and for the same reasons — including being a NON-modal dialog in ARIA
2785
+ * terms (#416): it is anchored, dismissible and does not own the page.
2786
+ *
2787
+ * The readout is an `output`, whose implicit status role announces each new
2788
+ * width: the only feedback a screen reader gets for a step, because the
2789
+ * buttons keep focus and the separator's valuenow is not where focus is.
2790
+ */
2791
+ renderResizePanel() {
2792
+ const e = this.resizeOverlay.portalContainer;
2793
+ if (!e) return;
2794
+ const t = this._columns.find((r) => r.name === this._openResizeColumn);
2795
+ if (!t) return;
2796
+ const i = this.mergedLabels, s = this.columnLabel(t), a = Math.round(this.currentColumnWidth(t));
2797
+ y(
2798
+ c`
2799
+ <div class="resize-panel" role="dialog" aria-label=${i.resizeColumnOptions(s)}>
2800
+ <div class="resize-panel-steps">
2801
+ <button
2802
+ type="button"
2803
+ class="resize-panel-step"
2804
+ aria-label=${i.narrowerColumn(s)}
2805
+ @click=${() => this.stepColumnWidth(t, -w)}
2806
+ ><span aria-hidden="true">&minus;</span></button>
2807
+ <output class="resize-panel-width">${i.columnWidth(a)}</output>
2808
+ <button
2809
+ type="button"
2810
+ class="resize-panel-step"
2811
+ aria-label=${i.widerColumn(s)}
2812
+ @click=${() => this.stepColumnWidth(t, w)}
2813
+ ><span aria-hidden="true">+</span></button>
2814
+ </div>
2815
+ <button type="button" class="resize-panel-action" @click=${() => this.fitColumnWidth(t)}>
2816
+ ${i.fitColumn}
2817
+ </button>
2818
+ <button type="button" class="resize-panel-action" @click=${() => this.resetColumnWidth(t)}>
2819
+ ${i.resetColumn}
2820
+ </button>
2821
+ </div>
2822
+ `,
2823
+ e
2824
+ );
2825
+ }
2826
+ /**
2827
+ * Sizes the column to its widest RENDERED content: header plus the body rows
2828
+ * currently in the DOM (one window, in virtual mode). Read with a Range,
2829
+ * because a clipped cell's own box reports the column width, not its
2830
+ * content's, while a range over its contents measures the text itself.
2831
+ */
2832
+ fitColumnWidth(e) {
2833
+ const t = this.renderRoot;
2834
+ if (!t) return;
2835
+ const i = this.headerCell(e.name), s = i?.querySelector(".header-cell > span") ?? null, a = i?.querySelector(".header-cell") ?? null, r = [...t.querySelectorAll(
2836
+ `tbody tr[data-row-key] > td[data-column="${e.name}"]`
2837
+ )], o = [
2838
+ s && a && i ? L(s) + R(a) + R(i) : NaN,
2839
+ ...r.map((d) => L(d) + R(d))
2840
+ ], l = Z(o);
2841
+ l != null && this.setUserColumnWidth(e.name, l);
2842
+ }
2843
+ /** Back to the width the table chose: the measured one, else the column's own. */
2844
+ resetColumnWidth(e) {
2845
+ if (this._userWidths.delete(e.name), this._userWidths.size === 0) {
2846
+ this._frozenExtraWidth = null, this._frozenWidths = /* @__PURE__ */ new Map(), this._columnWidths = new Map(
2847
+ this._columns.map((i) => [i.name, this._measuredWidths.get(i.name) ?? i.width]).filter((i) => typeof i[1] == "number")
2848
+ ), this.requestUpdate(), this.refitMeasuredWidths();
2849
+ return;
2850
+ }
2851
+ const t = this._frozenWidths.get(e.name) ?? this._measuredWidths.get(e.name) ?? e.width;
2852
+ this._columnWidths = new Map(this._columnWidths), typeof t == "number" ? this._columnWidths.set(e.name, t) : this._columnWidths.delete(e.name), this.requestUpdate();
2853
+ }
2854
+ }
2855
+ function L(n) {
2856
+ const e = n.ownerDocument;
2857
+ if (typeof e.createRange != "function") return NaN;
2858
+ const t = e.createRange();
2859
+ return t.selectNodeContents(n), typeof t.getBoundingClientRect == "function" ? t.getBoundingClientRect().width : NaN;
2860
+ }
2861
+ function R(n) {
2862
+ const e = getComputedStyle(n);
2863
+ return (parseFloat(e.paddingLeft) || 0) + (parseFloat(e.paddingRight) || 0);
2521
2864
  }
2522
- function Y(n, e) {
2865
+ function te(n, e) {
2523
2866
  if (n == null || typeof n != "object") return "";
2524
2867
  const t = n[e.name];
2525
2868
  return t == null ? "" : String(t);
2526
2869
  }
2527
- function J(n) {
2870
+ function ie(n) {
2528
2871
  return n != null && typeof n != "string" && typeof n[Symbol.iterator] == "function";
2529
2872
  }
2530
- function C(n) {
2531
- return n == null || n === !1 ? u : (n instanceof Node || typeof n == "object" && "_$litType$" in n, n);
2873
+ function S(n) {
2874
+ return n == null || n === !1 ? p : (n instanceof Node || typeof n == "object" && "_$litType$" in n, n);
2532
2875
  }
2533
- q("datatable", B);
2534
- typeof customElements < "u" && !customElements.get("mp-datatable") && customElements.define("mp-datatable", X);
2876
+ K("datatable", V);
2877
+ typeof customElements < "u" && !customElements.get("mp-datatable") && customElements.define("mp-datatable", ee);
2535
2878
  export {
2536
- W as D,
2537
- X as M,
2538
- H as c,
2539
- B as d,
2540
- y as s
2879
+ B as D,
2880
+ ee as M,
2881
+ G as c,
2882
+ V as d,
2883
+ v as s
2541
2884
  };