@mintplayer/web-components 2.17.0 → 2.18.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,16 +1,16 @@
1
- import { unsafeCSS as L, LitElement as P, nothing as u, render as v } from "lit";
2
- import { O as M } from "./overlay-controller-BHDagokg.mjs";
3
- import { s as k, i as z } from "./install-light-styles-DbCAGFOC.mjs";
4
- import { L as q } from "./live-announcer-Bi0orG4n.mjs";
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
5
  import { a as K, F as A } from "./focus-restore-DxuP1Oe2.mjs";
6
6
  import { H as U } from "./host-aria-WSGs7SPQ.mjs";
7
- import { repeat as C } from "lit/directives/repeat.js";
8
- import { live as T } from "lit/directives/live.js";
9
- import { classMap as x } from "lit/directives/class-map.js";
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";
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 O = {
13
+ const T = {
14
14
  eq: "equals",
15
15
  neq: "does not equal",
16
16
  lt: "is less than",
@@ -32,33 +32,35 @@ const O = {
32
32
  collapseRow: "Collapse row",
33
33
  loading: "Loading",
34
34
  rowsPerPage: "Rows per page",
35
- resizeColumn: (l) => `Resize column ${l}`,
36
- selectRow: (l) => `Select row ${l}`,
37
- filterColumn: (l) => `Filter ${l}`,
38
- filterColumnActive: (l, e) => e ? `Filter ${l}, filtered by ${e}` : `Filter ${l}, filtered`,
39
- filterClear: (l) => `Clear the filter on ${l}`,
35
+ resizeColumn: (n) => `Resize column ${n}`,
36
+ selectRow: (n) => `Select row ${n}`,
37
+ selectRowNamed: (n) => `Select ${n}`,
38
+ filterColumn: (n) => `Filter ${n}`,
39
+ filterColumnActive: (n, e) => e ? `Filter ${n}, filtered by ${e}` : `Filter ${n}, filtered`,
40
+ filterClear: (n) => `Clear the filter on ${n}`,
40
41
  filterSearch: "Search values",
41
42
  filterInvert: "Exclude the selected values",
42
- filterGroup: (l) => `Values of ${l}`,
43
+ filterGroup: (n) => `Values of ${n}`,
43
44
  filterHasMore: "More values exist — refine the search to see them",
44
45
  filterNoValues: "No values available",
45
- filterValue(l) {
46
- return l == null ? this.filterNone : l === "" ? this.filterEmpty : l === !0 ? this.filterTrue : l === !1 ? this.filterFalse : l instanceof Date ? l.toLocaleDateString() : String(l);
46
+ filterValue(n) {
47
+ return n == null ? this.filterNone : n === "" ? this.filterEmpty : n === !0 ? this.filterTrue : n === !1 ? this.filterFalse : n instanceof Date ? n.toLocaleDateString() : String(n);
47
48
  },
48
49
  filterNone: "(none)",
49
50
  filterEmpty: "(empty)",
50
51
  filterTrue: "Yes",
51
52
  filterFalse: "No",
52
- announceFilter: (l, e) => e === 0 ? `Filter cleared on ${l}` : e === 1 ? `1 value selected in ${l}` : `${e} values selected in ${l}`,
53
+ announceFilter: (n, e) => e === 0 ? `Filter cleared on ${n}` : e === 1 ? `1 value selected in ${n}` : `${e} values selected in ${n}`,
53
54
  filterOperator: "Comparison",
54
55
  filterOperand: "Value to compare with",
55
- filterOperatorLabel: (l) => O[l],
56
- announceComparisonFilter: (l, e, t) => t === "" ? `Filter cleared on ${l}` : `${l} ${e} ${t}`,
57
- announceSorted: (l, e) => e === "none" ? `Sorting removed from ${l}` : `Sorted by ${l}, ${e}`,
58
- announcePage: (l, e) => `Page ${l} of ${e}`,
59
- announceSelection: (l) => l === 1 ? "1 row selected" : `${l} rows selected`,
60
- announceLoaded: (l) => l === 1 ? "Loaded 1 row" : `Loaded ${l} rows`
61
- }, H = L(`@charset "UTF-8";
56
+ filterOperatorLabel: (n) => T[n],
57
+ announceComparisonFilter: (n, e, t) => t === "" ? `Filter cleared on ${n}` : `${n} ${e} ${t}`,
58
+ announceSorted: (n, e) => e === "none" ? `Sorting removed from ${n}` : `Sorted by ${n}, ${e}`,
59
+ announcePage: (n, e) => `Page ${n} of ${e}`,
60
+ announceSelection: (n) => n === 1 ? "1 row selected" : `${n} rows selected`,
61
+ announceLoaded: (n) => n === 1 ? "Loaded 1 row" : `Loaded ${n} rows`,
62
+ rangeIncomplete: "Range not selected: some rows in it have not loaded yet"
63
+ }, B = E(`@charset "UTF-8";
62
64
  mp-datatable {
63
65
  display: block;
64
66
  width: 100%;
@@ -269,6 +271,10 @@ tr[data-mps=datatable] > .checkbox-cell[data-mps=datatable] {
269
271
  text-overflow: clip;
270
272
  }
271
273
 
274
+ .checkbox-cell.checkbox-cell-toggles[data-mps=datatable] {
275
+ cursor: pointer;
276
+ }
277
+
272
278
  .tree-chevron-cell[data-mps=datatable] {
273
279
  width: 2rem;
274
280
  padding-right: 0;
@@ -544,56 +550,56 @@ tr.filter-row[data-mps=datatable] th[data-mps=datatable] {
544
550
  transition: none !important;
545
551
  }
546
552
  }`);
547
- function B(l, e, t) {
553
+ function H(n, e, t) {
548
554
  if (t) {
549
- const i = l.findIndex((s) => s.property === e);
550
- return i === -1 ? [...l, { property: e, direction: "ascending" }] : l[i].direction === "ascending" ? l.map(
551
- (s, r) => r === i ? { ...s, direction: "descending" } : s
552
- ) : l.filter((s, r) => r !== i);
555
+ const s = n.findIndex((i) => i.property === e);
556
+ 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);
553
559
  }
554
- const a = l.length === 1 && l[0].property === e;
560
+ const a = n.length === 1 && n[0].property === e;
555
561
  return [
556
562
  {
557
563
  property: e,
558
- direction: a && l[0].direction === "ascending" ? "descending" : "ascending"
564
+ direction: a && n[0].direction === "ascending" ? "descending" : "ascending"
559
565
  }
560
566
  ];
561
567
  }
562
- function y(l, e) {
563
- return e.length === 0 ? l.slice() : l.map((t, a) => ({ row: t, index: a })).sort((t, a) => {
564
- for (const i of e) {
565
- const s = S(t.row, i.property), r = S(a.row, i.property), o = V(s, r);
568
+ function y(n, e) {
569
+ return e.length === 0 ? n.slice() : n.map((t, a) => ({ row: t, index: a })).sort((t, a) => {
570
+ for (const s of e) {
571
+ const i = S(t.row, s.property), r = S(a.row, s.property), o = V(i, r);
566
572
  if (o !== 0)
567
- return i.direction === "ascending" ? o : -o;
573
+ return s.direction === "ascending" ? o : -o;
568
574
  }
569
575
  return t.index - a.index;
570
576
  }).map(({ row: t }) => t);
571
577
  }
572
- function S(l, e) {
573
- if (!(l == null || typeof l != "object"))
574
- return l[e];
578
+ function S(n, e) {
579
+ if (!(n == null || typeof n != "object"))
580
+ return n[e];
575
581
  }
576
- function V(l, e) {
577
- return l === e ? 0 : l == null ? 1 : e == null ? -1 : typeof l == "number" && typeof e == "number" ? l - e : l instanceof Date && e instanceof Date ? l.getTime() - e.getTime() : String(l).localeCompare(String(e));
582
+ function V(n, e) {
583
+ return n === e ? 0 : n == null ? 1 : e == null ? -1 : typeof n == "number" && typeof e == "number" ? n - e : n instanceof Date && e instanceof Date ? n.getTime() - e.getTime() : String(n).localeCompare(String(e));
578
584
  }
579
- const F = 40, $ = 10;
580
- function R(l, e) {
581
- return Math.max(F, l + e);
585
+ const F = 40, R = 10;
586
+ function $(n, e) {
587
+ return Math.max(F, n + e);
582
588
  }
583
- const h = k("datatable");
584
- function E(l, e) {
585
- return l === e || l !== l && e !== e;
589
+ const c = I("datatable");
590
+ function P(n, e) {
591
+ return n === e || n !== n && e !== e;
586
592
  }
587
- function g(l, e) {
588
- return l.some((t) => E(t.value, e));
593
+ function g(n, e) {
594
+ return n.some((t) => P(t.value, e));
589
595
  }
590
596
  const G = 250;
591
597
  let j = 0;
592
- class X extends P {
598
+ class X extends M {
593
599
  constructor() {
594
600
  super(...arguments), this.instanceId = `mp-datatable-${++j}`, this._caption = null, this._inputLabel = null, this.hostAria = new U(this, {
595
601
  referenceTarget: () => this.renderRoot?.querySelector("table") ?? null
596
- }), this.labels = void 0, this._columns = [], this._data = [], this._sortColumns = [], this._selectionMode = "none", this._selectedIds = /* @__PURE__ */ new Set(), this._cutIds = /* @__PURE__ */ new Set(), this._focusedRowKey = null, this.liveAnnouncer = new q(this), this.rowFocusRestore = new K(this, new A(
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(
597
603
  () => this.renderRoot ?? null,
598
604
  {
599
605
  selector: 'tbody tr[data-row-key]:not([data-placeholder="true"])',
@@ -602,8 +608,8 @@ class X extends P {
602
608
  }
603
609
  )), this._rowKey = (e, t) => {
604
610
  const a = e;
605
- return a && a.id != null ? String(a.id) : `row-${t}`;
606
- }, this._columnWidths = /* @__PURE__ */ new Map(), this._hasMeasuredInitial = !1, this._loading = !1, this._emptyMessage = "No data", this._pagination = !1, this._page = 1, this._perPage = 20, this._perPageOptions = [10, 20, 50], this._autoSort = !0, this._totalRecords = null, this._virtualScroll = !1, this._itemSize = 40, this._virtualBuffer = 10, this._virtualRange = { startIndex: 0, endIndex: 0 }, this._scrollElement = null, this._resizeObserver = null, this._scrollListener = null, this._viewportHeight = 0, this._openFilterColumn = null, this._mountedFilterColumn = null, this._consumerMountedFilter = !1, this._filterUid = `mp-dt-${Math.random().toString(36).slice(2, 9)}`, this._distincts = null, this._filterStates = /* @__PURE__ */ new Map(), this._tree = !1, this._idKey = null, this._childCountKey = null, this._treeIndent = 1.25, this._expandedIds = /* @__PURE__ */ new Set(), this._selectionStrategy = "flat", this._childCache = /* @__PURE__ */ new Map(), this._childTotals = /* @__PURE__ */ new Map(), this._pendingFetches = /* @__PURE__ */ new Set(), this._pageCache = /* @__PURE__ */ new Map(), this._pendingPageFetches = /* @__PURE__ */ new Set(), this._fetch = null, this._fetchGeneration = 0, this._initialFetchDone = !1, this._reloadScheduled = !1, this._lastReloadKey = null, this._cachedFlatList = null, this._cachedIndeterminateKeys = null, this._resizableColumns = !0, this.filterOverlay = new M(this, {
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, {
607
613
  portal: !0,
608
614
  modal: !0,
609
615
  scrollStrategy: "reposition",
@@ -634,9 +640,9 @@ class X extends P {
634
640
  })
635
641
  );
636
642
  }
637
- }), this._selectionAnchorKey = null, this.resizeState = null, this.onColumnResizeMove = (e) => {
643
+ }), this._keyByRowMemo = null, this._selectionAnchorKey = null, this.resizeState = null, this.onColumnResizeMove = (e) => {
638
644
  if (!this.resizeState) return;
639
- const t = R(this.resizeState.startWidth, e.clientX - this.resizeState.startX);
645
+ const t = $(this.resizeState.startWidth, e.clientX - this.resizeState.startX);
640
646
  this._columnWidths = new Map(this._columnWidths), this._columnWidths.set(this.resizeState.columnName, t), this.requestUpdate();
641
647
  }, this.onColumnResizeEnd = (e) => {
642
648
  if (this.resizeState) {
@@ -697,6 +703,19 @@ class X extends P {
697
703
  const t = e ?? null;
698
704
  this._caption !== t && (this._caption = t, this.requestUpdate());
699
705
  }
706
+ /**
707
+ * User-visible strings, overridable per key for localisation
708
+ * (see DatatableLabels). Property-only: it holds functions. Re-renders on
709
+ * assignment, so switching language on a mounted table renames every
710
+ * control (row-checkbox names included) without waiting for an unrelated
711
+ * update.
712
+ */
713
+ get labels() {
714
+ return this._labels;
715
+ }
716
+ set labels(e) {
717
+ e !== this._labels && (this._labels = e, this.requestUpdate());
718
+ }
700
719
  /** Merged view of labels — consumer keys over the English defaults. */
701
720
  get mergedLabels() {
702
721
  return { ...W, ...this.labels ?? {} };
@@ -709,6 +728,15 @@ class X extends P {
709
728
  const t = e ?? null;
710
729
  this._inputLabel !== t && (this._inputLabel = t, this.requestUpdate());
711
730
  }
731
+ /**
732
+ * Warn rather than throw: a static table without ids keeps working, and only
733
+ * a fetched or selectable one is actually harmed by a positional key.
734
+ */
735
+ warnPositionalKeyOnce() {
736
+ this._warnedPositionalKey || !this._fetch && this._selectionMode === "none" || (this._warnedPositionalKey = !0, console.warn(
737
+ "[mp-datatable] A row has no `id` and no `rowKey` is set, so it is keyed by its position. A positional key names a different row after a re-fetch, sort or expansion, so a selection cannot survive them. Set `rowKey` to return a stable identity."
738
+ ));
739
+ }
712
740
  /** When true, the WC sorts `data` itself using `sortRows`. Set `false` if the consumer sorts externally. */
713
741
  get autoSort() {
714
742
  return this._autoSort;
@@ -797,16 +825,25 @@ class X extends P {
797
825
  * loop and the consumer provides nothing else — no page-1 seeding via `data`,
798
826
  * no separate `totalRecords`, no event bridge. Works with any framework or
799
827
  * none (`el.fetch = fn`). Setting it kicks off the initial page-1 load.
828
+ *
829
+ * Pass a STABLE function. Assigning the same function again is a no-op, but
830
+ * a new closure on every render is a new callback, and each one reloads. To
831
+ * re-query with an unchanged callback, call `reload()`.
800
832
  */
801
833
  get fetch() {
802
834
  return this._fetch;
803
835
  }
804
836
  set fetch(e) {
805
- if (this._fetch = typeof e == "function" ? e : null, this._fetch) {
806
- this._autoSort = !1, this._initialFetchDone = !1, this._lastReloadKey = null, this.scheduleFetchReload();
807
- return;
808
- }
809
- this._totalRecords = null, this._pageCache.clear(), this._pendingPageFetches.clear(), this._childCache.clear(), this._childTotals.clear(), this._pendingFetches.clear(), this._fetchGeneration++, this._initialFetchDone = !1, this._lastReloadKey = null, this.requestUpdate();
837
+ this.assignFetch(e) && this.scheduleFetchReload();
838
+ }
839
+ /**
840
+ * Assigns the callback without scheduling a load; true when a load is due.
841
+ * Shared by the setter and `applyFetchState`, which schedules once for all
842
+ * of its fields.
843
+ */
844
+ assignFetch(e) {
845
+ const t = typeof e == "function" ? e : null;
846
+ return t === this._fetch ? !1 : (this._fetch = t, this._fetch ? (this._autoSort = !1, this._initialFetchDone = !1, this._lastReloadKey = null, !0) : (this._totalRecords = null, this._pageCache.clear(), this._pendingPageFetches.clear(), this._childCache.clear(), this._childTotals.clear(), this._pendingFetches.clear(), this._fetchGeneration++, this._initialFetchDone = !1, this._lastReloadKey = null, this.requestUpdate(), !1));
810
847
  }
811
848
  /**
812
849
  * Consumer-supplied source of distinct values for the filter panels.
@@ -827,19 +864,101 @@ class X extends P {
827
864
  return [...this._sortColumns];
828
865
  }
829
866
  set sortColumns(e) {
830
- this._sortColumns = Array.isArray(e) ? [...e] : [], this.requestUpdate(), this.scheduleFetchReload();
867
+ this.assignSortColumns(e) && (this.requestUpdate(), this.scheduleFetchReload());
868
+ }
869
+ /**
870
+ * Assigns without scheduling; false when the value is structurally equal. A
871
+ * wrapper echoing back the array it was just given is not a sort change, and
872
+ * must not cost a re-render or a request (#407).
873
+ */
874
+ assignSortColumns(e) {
875
+ 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);
877
+ }
878
+ /**
879
+ * Re-queries the `fetch` callback for the current sort, page and page size,
880
+ * even though none of them changed (the server data did). One request,
881
+ * coalesced with any change already pending in the same task.
882
+ *
883
+ * The loaded windows and tree children are dropped, because they may be
884
+ * stale. The selection is NOT: every selected key and its remembered row
885
+ * survive, so a re-fetched row simply replaces the remembered one.
886
+ *
887
+ * `resetPage: true` also returns to page 1 (and emits
888
+ * `mp-datatable-page-change` when that moves the page). A no-op without a
889
+ * `fetch` callback, apart from the page reset.
890
+ */
891
+ reload({ resetPage: e = !1 } = {}) {
892
+ e && this.assignPage(1) && (this.requestUpdate(), this.dispatchEvent(
893
+ new CustomEvent("mp-datatable-page-change", {
894
+ detail: { page: 1 },
895
+ bubbles: !0,
896
+ composed: !0
897
+ })
898
+ )), this._lastReloadKey = null, this.scheduleFetchReload();
899
+ }
900
+ /**
901
+ * Applies any of `fetch`, `sortColumns`, `page` and `perPage` as ONE change:
902
+ * every provided field is assigned first, then exactly one reload is
903
+ * scheduled. Assigning them one by one through the setters can split across
904
+ * ticks and cost two requests; this cannot (#407). Framework wrappers that
905
+ * forward several of these inputs should call this rather than the setters.
906
+ *
907
+ * A field that is absent (or `undefined`) is left alone, except `fetch`: a
908
+ * present `fetch` key is always assigned, so `{ fetch: null }` removes the
909
+ * callback. `perPage` returns to page 1 unless `page` is also given.
910
+ * Unchanged values cost nothing, as with the setters.
911
+ *
912
+ * When `perPage` changes and the given `page` would lie past the last page
913
+ * of the known row count (20 → 50 per page while on page 5 of 100 rows), the
914
+ * page is clamped to the last page and `mp-datatable-page-change` reports
915
+ * it, so a wrapper's page state follows. With no known count (a fetch table
916
+ * before its first response, or a new `fetch` in the same call) the page is
917
+ * kept as given.
918
+ */
919
+ applyFetchState(e) {
920
+ const t = "fetch" in e && this.assignFetch(e.fetch);
921
+ 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();
831
924
  }
832
925
  get selectionMode() {
833
926
  return this._selectionMode;
834
927
  }
835
928
  set selectionMode(e) {
836
- this._selectionMode = e, e === "none" && this._selectedIds.clear(), this.requestUpdate();
929
+ if (this._selectionMode = e, e === "none") {
930
+ this._selectionAnchorKey = null;
931
+ const t = this._selectedIds.size > 0;
932
+ this.commitSelection([]), t && this.emitSelectionChange();
933
+ }
934
+ this.requestUpdate();
935
+ }
936
+ /** Modes that select many rows and render the checkbox column. */
937
+ get isMulti() {
938
+ return this._selectionMode === "multiple" || this._selectionMode === "checkbox";
837
939
  }
838
940
  get selectedIds() {
839
941
  return [...this._selectedIds];
840
942
  }
841
943
  set selectedIds(e) {
842
- this._selectedIds = new Set(e ?? []), this.requestUpdate();
944
+ 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());
946
+ }
947
+ /**
948
+ * The selected rows, index-aligned with `selectedIds` (`undefined` for a key
949
+ * whose row the element has never seen). See `SelectionChangeEventDetail`.
950
+ *
951
+ * Setting it REPLACES the selection: the keys are derived through `rowKey`,
952
+ * and the rows are remembered, so a host that owns row objects (the Angular
953
+ * wrapper's `selection` model) can seed rows that are not loaded here — they
954
+ * are reported back in `selectedRows` even while off-page.
955
+ */
956
+ get selectedRows() {
957
+ return this.resolveRows([...this._selectedIds]);
958
+ }
959
+ 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());
843
962
  }
844
963
  get cutIds() {
845
964
  return [...this._cutIds];
@@ -853,6 +972,27 @@ class X extends P {
853
972
  set focusedRowKey(e) {
854
973
  this._focusedRowKey = e, this.requestUpdate();
855
974
  }
975
+ /**
976
+ * Names a row for its selection checkbox ("Select {label}"). Property-only (it
977
+ * holds a function). When unset, or when it returns an empty string, the
978
+ * trimmed text of the row's first data cell is used, and when that is empty
979
+ * too, the row number ("Select row N").
980
+ *
981
+ * The name is a string handed to the checkbox: an `aria-labelledby` pointing
982
+ * at the cell could not cross the checkbox's shadow boundary.
983
+ */
984
+ get rowLabel() {
985
+ return this._rowLabel;
986
+ }
987
+ set rowLabel(e) {
988
+ this._rowLabel = typeof e == "function" ? e : null, this.requestUpdate();
989
+ }
990
+ /**
991
+ * Row identity: selection, focus and row-view reuse are keyed by it. It must
992
+ * be stable, and derived from the row rather than its index: a row that is
993
+ * not loaded is keyed `rowKey(row, -1)`, so an index-based key maps every
994
+ * off-page row onto `row--1`. Required with `fetch`.
995
+ */
856
996
  get rowKey() {
857
997
  return this._rowKey;
858
998
  }
@@ -934,15 +1074,40 @@ class X extends P {
934
1074
  return this._page;
935
1075
  }
936
1076
  set page(e) {
1077
+ this.assignPage(e) && (this.requestUpdate(), this.scheduleFetchReload());
1078
+ }
1079
+ /** Assigns without scheduling; true when the page changed. */
1080
+ assignPage(e) {
937
1081
  const t = Math.max(1, Math.floor(e || 1));
938
- this._page !== t && (this._page = t, this.requestUpdate(), this.scheduleFetchReload());
1082
+ return this._page === t ? !1 : (this._page = t, !0);
939
1083
  }
940
1084
  get perPage() {
941
1085
  return this._perPage;
942
1086
  }
943
1087
  set perPage(e) {
1088
+ this.assignPerPage(e) && (this.requestUpdate(), this.scheduleFetchReload());
1089
+ }
1090
+ /**
1091
+ * Moves a page past the end back to the last page, when the row count is
1092
+ * known: the server's `totalRecords` with `fetch`, the data length without.
1093
+ * Reported through `mp-datatable-page-change` when it moves the page.
1094
+ */
1095
+ clampPageToKnownTotal() {
1096
+ const e = this._fetch ? this._totalRecords : this._data.length;
1097
+ if (e == null) return;
1098
+ const t = Math.max(1, Math.ceil(e / this._perPage));
1099
+ this._page <= t || (this._page = t, this.dispatchEvent(
1100
+ new CustomEvent("mp-datatable-page-change", {
1101
+ detail: { page: t },
1102
+ bubbles: !0,
1103
+ composed: !0
1104
+ })
1105
+ ));
1106
+ }
1107
+ /** Assigns without scheduling (and returns to page 1); true when it changed. */
1108
+ assignPerPage(e) {
944
1109
  const t = Math.max(1, Math.floor(e || 1));
945
- this._perPage !== t && (this._perPage = t, this._page = 1, this.requestUpdate(), this.scheduleFetchReload());
1110
+ return this._perPage === t ? !1 : (this._perPage = t, this._page = 1, !0);
946
1111
  }
947
1112
  get perPageOptions() {
948
1113
  return [...this._perPageOptions];
@@ -983,8 +1148,8 @@ class X extends P {
983
1148
  else if (e === "aria-labelledby" || e === "aria-describedby")
984
1149
  this.hostAria.syncReferences();
985
1150
  else if (e === "selection-mode") {
986
- const i = a ?? "none";
987
- (i === "none" || i === "single" || i === "multiple") && (this.selectionMode = i);
1151
+ const s = a ?? "none";
1152
+ (s === "none" || s === "single" || s === "multiple" || s === "checkbox") && (this.selectionMode = s);
988
1153
  } else if (e === "pagination")
989
1154
  this.pagination = a !== null;
990
1155
  else if (e === "resizable-columns")
@@ -996,13 +1161,13 @@ class X extends P {
996
1161
  else if (e === "virtual-scroll")
997
1162
  this.virtualScroll = a !== null;
998
1163
  else if (e === "item-size") {
999
- const i = Number(a);
1000
- Number.isFinite(i) && (this.itemSize = i);
1164
+ const s = Number(a);
1165
+ Number.isFinite(s) && (this.itemSize = s);
1001
1166
  } else if (e === "tree")
1002
1167
  this.tree = a !== null;
1003
1168
  else if (e === "tree-indent") {
1004
- const i = a === null ? 1.25 : Number(a);
1005
- Number.isFinite(i) && (this.treeIndent = i);
1169
+ const s = a === null ? 1.25 : Number(a);
1170
+ Number.isFinite(s) && (this.treeIndent = s);
1006
1171
  } else e === "selection-strategy" && (this.selectionStrategy = a === "cascading" ? "cascading" : "flat");
1007
1172
  }
1008
1173
  get resizableColumns() {
@@ -1021,11 +1186,11 @@ class X extends P {
1021
1186
  super.willUpdate(e), this._cachedFlatList = null, this._cachedIndeterminateKeys = null;
1022
1187
  }
1023
1188
  updated(e) {
1024
- super.updated(e), this.refreshVirtualRange(), this.maybeMeasureInitialColumnWidths();
1189
+ super.updated(e), this.refreshVirtualRange(), this.nameRowCheckboxes(), this.maybeMeasureInitialColumnWidths();
1025
1190
  const t = this.renderRoot?.querySelectorAll(".resize-handle:not([aria-valuenow])") ?? [];
1026
1191
  for (const a of t) {
1027
- const i = a.closest("th");
1028
- i && a.setAttribute("aria-valuenow", String(Math.round(i.getBoundingClientRect().width)));
1192
+ const s = a.closest("th");
1193
+ s && a.setAttribute("aria-valuenow", String(Math.round(s.getBoundingClientRect().width)));
1029
1194
  }
1030
1195
  this._openFilterColumn && this.renderFilterPanel(), this.publishHeaderHeight();
1031
1196
  }
@@ -1054,14 +1219,14 @@ class X extends P {
1054
1219
  if (this._hasMeasuredInitial || this._columns.length === 0 || this._data.length === 0 || !this.renderRoot || this.renderRoot.querySelectorAll('tbody tr[data-row-key]:not([data-placeholder="true"])').length === 0) return;
1055
1220
  const t = new Map(this._columnWidths);
1056
1221
  let a = !1;
1057
- for (const i of this._columns) {
1058
- if (t.has(i.name)) continue;
1059
- if (typeof i.width == "number") {
1060
- t.set(i.name, i.width), a = !0;
1222
+ for (const s of this._columns) {
1223
+ if (t.has(s.name)) continue;
1224
+ if (typeof s.width == "number") {
1225
+ t.set(s.name, s.width), a = !0;
1061
1226
  continue;
1062
1227
  }
1063
- const s = this.measureColumnWidth(i.name);
1064
- s != null && (t.set(i.name, s), a = !0);
1228
+ const i = this.measureColumnWidth(s.name);
1229
+ i != null && (t.set(s.name, i), a = !0);
1065
1230
  }
1066
1231
  a && (this._columnWidths = t, this._hasMeasuredInitial = !0, this.requestUpdate());
1067
1232
  }
@@ -1081,18 +1246,18 @@ class X extends P {
1081
1246
  if (!this._virtualScroll || !this._scrollElement) return;
1082
1247
  const e = this._scrollElement.scrollTop, t = this._scrollElement.clientHeight;
1083
1248
  this._viewportHeight = t;
1084
- const a = this.getEffectiveData().length, i = this._itemSize, s = Math.max(0, Math.floor(e / i) - this._virtualBuffer), r = Math.ceil(t / i), o = Math.min(a, s + r + this._virtualBuffer * 2);
1085
- (s !== this._virtualRange.startIndex || o !== this._virtualRange.endIndex) && (this._virtualRange = { startIndex: s, endIndex: o }, this.requestUpdate()), this._tree && this.maybeFetchPlaceholdersInViewport(), this.isRootWindowed() && this.maybeFetchPagesInViewport();
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();
1086
1251
  }
1087
1252
  /**
1088
1253
  * Walk the visible viewport for placeholder rows whose parent isn't cached
1089
1254
  * and isn't already in-flight. Emit a fetch-request per such parent.
1090
1255
  */
1091
1256
  maybeFetchPlaceholdersInViewport() {
1092
- const e = this.getFlatList(), { startIndex: t, endIndex: a } = this._virtualRange, i = this._virtualScroll ? t : 0, s = this._virtualScroll ? a : e.length, r = /* @__PURE__ */ new Set();
1093
- for (let o = i; o < s; o++) {
1094
- const n = e[o];
1095
- !n.isPlaceholder || n.parentId == null || this._childCache.has(n.parentId) || this._pendingFetches.has(n.parentId) || r.add(n.parentId);
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++) {
1259
+ const l = e[o];
1260
+ !l.isPlaceholder || l.parentId == null || this._childCache.has(l.parentId) || this._pendingFetches.has(l.parentId) || r.add(l.parentId);
1096
1261
  }
1097
1262
  for (const o of r) this.fetchChildren(o);
1098
1263
  }
@@ -1104,32 +1269,33 @@ class X extends P {
1104
1269
  * wrapper's first-page fetch).
1105
1270
  */
1106
1271
  maybeFetchPagesInViewport() {
1107
- const e = this.getFlatList(), { startIndex: t, endIndex: a } = this._virtualRange, i = this._virtualScroll ? t : 0, s = this._virtualScroll ? a : e.length, r = /* @__PURE__ */ new Set();
1108
- for (let o = i; o < s; o++) {
1109
- const n = e[o];
1110
- !n.isPlaceholder || n.page == null || n.page <= 1 || this._pageCache.has(n.page) || this._pendingPageFetches.has(n.page) || r.add(n.page);
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++) {
1274
+ const l = e[o];
1275
+ !l.isPlaceholder || l.page == null || l.page <= 1 || this._pageCache.has(l.page) || this._pendingPageFetches.has(l.page) || r.add(l.page);
1111
1276
  }
1112
1277
  for (const o of r) this.fetchWindowPage(o);
1113
1278
  }
1114
1279
  render() {
1115
- const e = this.computeVisibleRows(), t = this._totalRecords ?? this._data.length, a = this.pagination && !this._tree ? Math.max(1, Math.ceil(t / this._perPage)) : 1, i = this._selectionMode === "multiple", s = this._columns.length + (i ? 1 : 0) + (this._tree ? 1 : 0), r = this.getVirtualSpacerHeights(), o = this.hasFilterRow ? 2 : 1, n = (this._tree || this.isRootWindowed() ? this.getFlatList().length : this._data.length) + o;
1116
- return h`
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;
1281
+ return c`
1117
1282
  ${this.liveAnnouncer.template()}
1118
1283
  <div class="datatable-shell">
1119
1284
  <div class="datatable-scroll ${this._virtualScroll ? "datatable-virtual" : ""}" role="presentation">
1120
1285
  <table
1121
1286
  role=${this._tree ? "treegrid" : this._selectionMode !== "none" ? "grid" : u}
1122
- aria-rowcount=${n}
1123
- aria-colcount=${s}
1287
+ aria-multiselectable=${this.isMulti ? "true" : u}
1288
+ aria-rowcount=${l}
1289
+ aria-colcount=${i}
1124
1290
  aria-busy=${this._loading ? "true" : u}
1125
1291
  aria-label=${this.getAttribute("aria-label") ?? this._inputLabel ?? u}
1126
1292
  class=${this._hasMeasuredInitial ? "measured" : ""}
1127
1293
  >
1128
- ${this._caption ? h`<caption>${this._caption}</caption>` : u}
1294
+ ${this._caption ? c`<caption>${this._caption}</caption>` : u}
1129
1295
  <thead>
1130
1296
  <tr role="row" aria-rowindex="1">
1131
- ${this._tree ? h`<th class="tree-chevron-cell" scope="col" aria-label=${this.mergedLabels.treeChevronColumn}></th>` : u}
1132
- ${i ? h`<th class="checkbox-cell" scope="col">
1297
+ ${this._tree ? c`<th class="tree-chevron-cell" scope="col" aria-label=${this.mergedLabels.treeChevronColumn}></th>` : u}
1298
+ ${s ? c`<th class="checkbox-cell" scope="col">
1133
1299
  <mp-checkbox
1134
1300
  aria-label=${this.mergedLabels.deselectAll}
1135
1301
  aria-hidden=${this._selectedIds.size === 0 ? "true" : u}
@@ -1139,19 +1305,19 @@ class X extends P {
1139
1305
  @change=${this.onDeselectAll}
1140
1306
  ></mp-checkbox>
1141
1307
  </th>` : u}
1142
- ${this._columns.map((d, c) => this.renderHeader(d, c))}
1308
+ ${this._columns.map((h, d) => this.renderHeader(h, d))}
1143
1309
  </tr>
1144
- ${this.hasFilterRow ? this.renderFilterRow(i) : u}
1310
+ ${this.hasFilterRow ? this.renderFilterRow(s) : u}
1145
1311
  </thead>
1146
1312
  <tbody>
1147
- ${this._loading ? h`<tr><td colspan=${s} class="loading-state">Loading…</td></tr>` : e.length === 0 ? h`<tr><td colspan=${s} class="empty-state">${this._emptyMessage}</td></tr>` : h`
1148
- ${r.top > 0 ? h`<tr class="virtual-spacer" aria-hidden="true"><td colspan=${s} style=${_({ height: `${r.top}px`, padding: "0", border: "0" })}></td></tr>` : u}
1149
- ${C(
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(
1150
1316
  e,
1151
- ({ key: d }) => d,
1152
- ({ key: d, rowIndex: c, flat: p }) => this.renderRow(p, d, c, i)
1317
+ ({ key: h }) => h,
1318
+ ({ key: h, rowIndex: d, flat: p }) => this.renderRow(p, h, d, s)
1153
1319
  )}
1154
- ${r.bottom > 0 ? h`<tr class="virtual-spacer" aria-hidden="true"><td colspan=${s} style=${_({ height: `${r.bottom}px`, padding: "0", border: "0" })}></td></tr>` : u}
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}
1155
1321
  `}
1156
1322
  </tbody>
1157
1323
  </table>
@@ -1208,23 +1374,23 @@ class X extends P {
1208
1374
  return a.ctx = {
1209
1375
  values: () => a.view,
1210
1376
  loading: () => a.loading,
1211
- search: (i) => this.setFilterSearch(t, i),
1212
- apply: (i, s) => this.applyFilter(t, i, s),
1377
+ search: (s) => this.setFilterSearch(t, s),
1378
+ apply: (s, i) => this.applyFilter(t, s, i),
1213
1379
  // Clearing emits the shape of the column's OWN mode. A comparison column
1214
1380
  // emitting an empty `selected` array would be reporting a values-mode
1215
1381
  // filter it never had, and a consumer switching on `mode` would miss it.
1216
1382
  clear: () => this.clearFilter(t),
1217
- onChange: (i) => (a.listeners.add(i), () => a.listeners.delete(i))
1383
+ onChange: (s) => (a.listeners.add(s), () => a.listeners.delete(s))
1218
1384
  }, a;
1219
1385
  }
1220
1386
  /** State for a filterable column, created on demand. */
1221
1387
  filterState(e) {
1222
1388
  const t = this._filterStates.get(e);
1223
1389
  if (t) return t;
1224
- const a = this._columns.find((s) => s.name === e);
1390
+ const a = this._columns.find((i) => i.name === e);
1225
1391
  if (!a?.filterable) return null;
1226
- const i = this.createFilterState(a);
1227
- return this._filterStates.set(e, i), i;
1392
+ const s = this.createFilterState(a);
1393
+ return this._filterStates.set(e, s), s;
1228
1394
  }
1229
1395
  notifyFilterListeners(e) {
1230
1396
  e.listeners.forEach((t) => t()), this.requestUpdate();
@@ -1241,9 +1407,9 @@ class X extends P {
1241
1407
  * non-empty, so the list cannot collapse to the selection.
1242
1408
  */
1243
1409
  applyFilter(e, t, a) {
1244
- const i = this.filterState(e);
1245
- if (!i) return;
1246
- i.selection.values.length === 0 && t.length > 0 && i.snapshot == null && i.loaded && (i.snapshot = [...i.loaded.matching, ...i.loaded.remaining]), t.length === 0 && (i.snapshot = null), i.selection = { ...i.selection, values: [...t], inverse: a }, this.rebucket(i), this.notifyFilterListeners(i);
1410
+ const s = this.filterState(e);
1411
+ 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);
1247
1413
  const r = this._columns.find((o) => o.name === e);
1248
1414
  this.liveAnnouncer.announce(
1249
1415
  this.mergedLabels.announceFilter(r?.label ?? e, t.length)
@@ -1276,14 +1442,14 @@ class X extends P {
1276
1442
  * would filter everything away the moment its panel opened.
1277
1443
  */
1278
1444
  applyComparison(e, t, a) {
1279
- const i = this.filterState(e);
1280
- if (!i) return;
1281
- const s = this._columns.find((n) => n.name === e), r = this.parseOperand(a, s?.filterInputType);
1282
- i.operandText = a, i.selection = { ...i.selection, operator: t, operand: r }, this.notifyFilterListeners(i);
1445
+ const s = this.filterState(e);
1446
+ 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);
1283
1449
  const o = this.mergedLabels;
1284
1450
  this.liveAnnouncer.announce(
1285
1451
  o.announceComparisonFilter(
1286
- s?.label ?? e,
1452
+ i?.label ?? e,
1287
1453
  o.filterOperatorLabel(t),
1288
1454
  r == null ? "" : String(r)
1289
1455
  )
@@ -1310,8 +1476,8 @@ class X extends P {
1310
1476
  const a = this.filterState(e);
1311
1477
  if (!a) return;
1312
1478
  a.term = t, this.rebucket(a), this.notifyFilterListeners(a);
1313
- const i = a.loadedTerm ?? "";
1314
- (a.loaded?.hasMore || !t.startsWith(i)) && (a.debounce != null && clearTimeout(a.debounce), a.debounce = setTimeout(() => {
1479
+ const s = a.loadedTerm ?? "";
1480
+ (a.loaded?.hasMore || !t.startsWith(s)) && (a.debounce != null && clearTimeout(a.debounce), a.debounce = setTimeout(() => {
1315
1481
  a.debounce = null, this.loadDistincts(e, t);
1316
1482
  }, G));
1317
1483
  }
@@ -1326,19 +1492,19 @@ class X extends P {
1326
1492
  async loadDistincts(e, t) {
1327
1493
  const a = this.filterState(e);
1328
1494
  if (!a) return;
1329
- const i = ++a.generation;
1495
+ const s = ++a.generation;
1330
1496
  if (a.controller?.abort(), this._distincts) {
1331
- const s = new AbortController();
1332
- a.controller = s, a.loading = !0, this.notifyFilterListeners(a);
1497
+ const i = new AbortController();
1498
+ a.controller = i, a.loading = !0, this.notifyFilterListeners(a);
1333
1499
  try {
1334
- const r = await this._distincts({ column: e, search: t, signal: s.signal });
1335
- if (i !== a.generation) return;
1500
+ const r = await this._distincts({ column: e, search: t, signal: i.signal });
1501
+ if (s !== a.generation) return;
1336
1502
  if (a.loading = !1, a.controller = null, r) {
1337
1503
  a.loaded = r, a.loadedTerm = t, this.rebucket(a), this.notifyFilterListeners(a);
1338
1504
  return;
1339
1505
  }
1340
1506
  } catch {
1341
- if (i !== a.generation) return;
1507
+ if (s !== a.generation) return;
1342
1508
  a.loading = !1, a.controller = null, a.loaded = null, a.loadedTerm = t, this.notifyFilterListeners(a);
1343
1509
  return;
1344
1510
  }
@@ -1377,10 +1543,10 @@ class X extends P {
1377
1543
  localDistincts(e) {
1378
1544
  if (this._fetch != null || this.isExternallyPaged() || this._childCache.size > 0) return null;
1379
1545
  const t = this.mergedLabels, a = [];
1380
- return this._data.forEach((i) => {
1381
- const s = i?.[e];
1382
- g(a, s) || a.push({ value: s, label: t.filterValue(s) });
1383
- }), a.sort((i, s) => i.label.localeCompare(s.label)), { matching: a, remaining: [], hasMore: !1 };
1546
+ 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 };
1384
1550
  }
1385
1551
  /**
1386
1552
  * Re-derives `matching` / `remaining` from the snapshot and the search term.
@@ -1395,9 +1561,9 @@ class X extends P {
1395
1561
  e.view = null;
1396
1562
  return;
1397
1563
  }
1398
- const t = e.term.trim().toLowerCase(), a = (o) => t === "" || o.label.toLowerCase().includes(t), i = [...e.loaded.matching, ...e.loaded.remaining], s = e.snapshot ? e.snapshot.filter((o) => g(i, o.value)) : e.loaded.matching, r = e.snapshot ? e.snapshot.filter((o) => !g(i, o.value)) : e.loaded.remaining;
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;
1399
1565
  e.view = {
1400
- matching: s.filter(a),
1566
+ matching: i.filter(a),
1401
1567
  remaining: r.filter(a),
1402
1568
  hasMore: e.loaded.hasMore
1403
1569
  };
@@ -1455,7 +1621,7 @@ class X extends P {
1455
1621
  if (!t) return;
1456
1622
  const a = this.filterState(t.name);
1457
1623
  v(
1458
- h`
1624
+ c`
1459
1625
  <div
1460
1626
  class="filter-panel"
1461
1627
  id=${this.filterPanelId}
@@ -1467,18 +1633,18 @@ class X extends P {
1467
1633
  `,
1468
1634
  e
1469
1635
  );
1470
- const i = e.querySelector(".filter-panel-body");
1471
- if (!i || !a) return;
1472
- if (this._mountedFilterColumn === t.name && i.firstChild) {
1473
- this._consumerMountedFilter || this.renderDefaultFilterPanel(t, a, i);
1636
+ const s = e.querySelector(".filter-panel-body");
1637
+ if (!s || !a) return;
1638
+ if (this._mountedFilterColumn === t.name && s.firstChild) {
1639
+ this._consumerMountedFilter || this.renderDefaultFilterPanel(t, a, s);
1474
1640
  return;
1475
1641
  }
1476
- const s = t.filterRenderer?.(t, a.ctx) ?? null;
1477
- if (s) {
1478
- i.replaceChildren(s), this._consumerMountedFilter = !0, this._mountedFilterColumn = t.name;
1642
+ const i = t.filterRenderer?.(t, a.ctx) ?? null;
1643
+ if (i) {
1644
+ s.replaceChildren(i), this._consumerMountedFilter = !0, this._mountedFilterColumn = t.name;
1479
1645
  return;
1480
1646
  }
1481
- this._consumerMountedFilter = !1, this.renderDefaultFilterPanel(t, a, i), this._mountedFilterColumn = t.name;
1647
+ this._consumerMountedFilter = !1, this.renderDefaultFilterPanel(t, a, s), this._mountedFilterColumn = t.name;
1482
1648
  }
1483
1649
  /**
1484
1650
  * The built-in panel: clear, search, invert, checkbox list.
@@ -1494,27 +1660,27 @@ class X extends P {
1494
1660
  this.renderComparisonFilterPanel(e, t, a);
1495
1661
  return;
1496
1662
  }
1497
- const i = this.mergedLabels, s = e.label ?? e.name, r = t.view, o = t.selection.values, n = [
1663
+ const s = this.mergedLabels, i = e.label ?? e.name, r = t.view, o = t.selection.values, l = [
1498
1664
  ...o,
1499
- ...(r?.matching ?? []).filter((c) => !g(o, c.value)),
1500
- ...(r?.remaining ?? []).filter((c) => !g(o, c.value))
1501
- ], d = (c) => !!r && g(r.remaining, c);
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);
1502
1668
  v(
1503
- h`
1669
+ c`
1504
1670
  <button
1505
1671
  type="button"
1506
1672
  class="filter-clear"
1507
1673
  ?disabled=${o.length === 0 && !t.selection.inverse}
1508
1674
  @click=${() => this.onFilterClear(e.name)}
1509
1675
  >
1510
- ${i.filterClear(s)}
1676
+ ${s.filterClear(i)}
1511
1677
  </button>
1512
1678
  <input
1513
1679
  type="search"
1514
1680
  class="filter-search"
1515
1681
  .value=${t.term}
1516
- aria-label=${i.filterSearch}
1517
- @input=${(c) => t.ctx.search(c.target.value)}
1682
+ aria-label=${s.filterSearch}
1683
+ @input=${(d) => t.ctx.search(d.target.value)}
1518
1684
  />
1519
1685
  <button
1520
1686
  type="button"
@@ -1522,27 +1688,27 @@ class X extends P {
1522
1688
  aria-pressed=${t.selection.inverse ? "true" : "false"}
1523
1689
  @click=${() => t.ctx.apply(o, !t.selection.inverse)}
1524
1690
  >
1525
- ${i.filterInvert}
1691
+ ${s.filterInvert}
1526
1692
  </button>
1527
- <div class="filter-options" role="group" aria-label=${i.filterGroup(s)}>
1528
- ${t.loading ? h`<span class="filter-loading">${i.loading}</span>` : u}
1529
- ${C(
1530
- n,
1531
- (c) => c.value,
1532
- (c) => h`
1533
- <label class=${x({ "filter-option": !0, "filter-remaining": d(c.value) })}>
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(
1696
+ l,
1697
+ (d) => d.value,
1698
+ (d) => c`
1699
+ <label class=${w({ "filter-option": !0, "filter-remaining": h(d.value) })}>
1534
1700
  <input
1535
1701
  type="checkbox"
1536
- .checked=${g(o, c.value)}
1537
- @change=${(p) => this.onFilterToggle(e.name, c, p.target.checked)}
1702
+ .checked=${g(o, d.value)}
1703
+ @change=${(p) => this.onFilterToggle(e.name, d, p.target.checked)}
1538
1704
  />
1539
- <span>${c.label}</span>
1705
+ <span>${d.label}</span>
1540
1706
  </label>
1541
1707
  `
1542
1708
  )}
1543
- ${n.length === 0 && !t.loading ? h`<span class="filter-no-values">${i.filterNoValues}</span>` : u}
1709
+ ${l.length === 0 && !t.loading ? c`<span class="filter-no-values">${s.filterNoValues}</span>` : u}
1544
1710
  </div>
1545
- ${r?.hasMore ? h`<span class="filter-has-more">${i.filterHasMore}</span>` : u}
1711
+ ${r?.hasMore ? c`<span class="filter-has-more">${s.filterHasMore}</span>` : u}
1546
1712
  `,
1547
1713
  a
1548
1714
  );
@@ -1556,37 +1722,37 @@ class X extends P {
1556
1722
  * displayed.
1557
1723
  */
1558
1724
  renderComparisonFilterPanel(e, t, a) {
1559
- const i = this.mergedLabels, s = e.label ?? e.name, r = e.filterOperators?.length ? e.filterOperators : N, o = t.selection.operator ?? r[0], n = t.selection.operand, d = e.filterInputType ?? "number", c = () => a.querySelector(".filter-operand")?.value ?? "", p = () => a.querySelector(".filter-operator")?.value ?? o;
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;
1560
1726
  v(
1561
- h`
1727
+ c`
1562
1728
  <button
1563
1729
  type="button"
1564
1730
  class="filter-clear"
1565
- ?disabled=${n == null}
1731
+ ?disabled=${l == null}
1566
1732
  @click=${() => this.onFilterClear(e.name)}
1567
1733
  >
1568
- ${i.filterClear(s)}
1734
+ ${s.filterClear(i)}
1569
1735
  </button>
1570
1736
  <div class="filter-comparison">
1571
1737
  <select
1572
1738
  class="filter-operator"
1573
- aria-label=${i.filterOperator}
1574
- @change=${() => this.applyComparison(e.name, p(), c())}
1739
+ aria-label=${s.filterOperator}
1740
+ @change=${() => this.applyComparison(e.name, p(), d())}
1575
1741
  >
1576
1742
  ${r.map(
1577
- (f) => h`
1743
+ (f) => c`
1578
1744
  <option value=${f} ?selected=${f === o}>
1579
- ${D[f]} ${i.filterOperatorLabel(f)}
1745
+ ${D[f]} ${s.filterOperatorLabel(f)}
1580
1746
  </option>
1581
1747
  `
1582
1748
  )}
1583
1749
  </select>
1584
1750
  <input
1585
1751
  class="filter-operand"
1586
- type=${d}
1587
- .value=${T(t.operandText)}
1588
- aria-label=${i.filterOperand}
1589
- @input=${() => this.applyComparison(e.name, p(), c())}
1752
+ type=${h}
1753
+ .value=${O(t.operandText)}
1754
+ aria-label=${s.filterOperand}
1755
+ @input=${() => this.applyComparison(e.name, p(), d())}
1590
1756
  />
1591
1757
  </div>
1592
1758
  `,
@@ -1594,10 +1760,10 @@ class X extends P {
1594
1760
  );
1595
1761
  }
1596
1762
  onFilterToggle(e, t, a) {
1597
- const i = this.filterState(e);
1598
- if (!i) return;
1599
- const s = a ? [...i.selection.values, t] : i.selection.values.filter((r) => !E(r.value, t.value));
1600
- i.ctx.apply(s, i.selection.inverse);
1763
+ const s = this.filterState(e);
1764
+ 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);
1601
1767
  }
1602
1768
  onFilterClear(e) {
1603
1769
  const t = this.filterState(e);
@@ -1615,23 +1781,23 @@ class X extends P {
1615
1781
  * is width-neutral — see the note on that rule in `datatable.light.scss`.
1616
1782
  */
1617
1783
  renderFilterRow(e) {
1618
- return h`
1784
+ return c`
1619
1785
  <tr role="row" aria-rowindex="2" class="filter-row">
1620
- ${this._tree ? h`<th class="filter-cell tree-chevron-cell"></th>` : u}
1621
- ${e ? h`<th class="filter-cell checkbox-cell"></th>` : u}
1786
+ ${this._tree ? c`<th class="filter-cell tree-chevron-cell"></th>` : u}
1787
+ ${e ? c`<th class="filter-cell checkbox-cell"></th>` : u}
1622
1788
  ${this._columns.map((t) => this.renderFilterCell(t))}
1623
1789
  </tr>
1624
1790
  `;
1625
1791
  }
1626
1792
  renderFilterCell(e) {
1627
1793
  if (!e.filterable)
1628
- return h`<th class="filter-cell p-0" data-column=${e.name} scope="col"></th>`;
1629
- const t = this._openFilterColumn === e.name, a = this.mergedLabels, i = e.label ?? e.name, s = e.filterActive ? a.filterColumnActive(i, e.filterSummary) : a.filterColumn(i);
1630
- return h`
1794
+ 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);
1796
+ return c`
1631
1797
  <th class="filter-cell p-0" data-column=${e.name} scope="col">
1632
1798
  <button
1633
1799
  type="button"
1634
- class=${x({
1800
+ class=${w({
1635
1801
  "filter-trigger": !0,
1636
1802
  "p-2": !0,
1637
1803
  "rounded-0": !0,
@@ -1641,38 +1807,38 @@ class X extends P {
1641
1807
  id=${this.filterTriggerId(e.name)}
1642
1808
  aria-expanded=${t ? "true" : "false"}
1643
1809
  aria-controls=${t ? this.filterPanelId : u}
1644
- aria-label=${s}
1810
+ aria-label=${i}
1645
1811
  @click=${(r) => this.onFilterTriggerClick(e, r)}
1646
1812
  >
1647
1813
  <svg class="filter-icon" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
1648
1814
  <path d="M2 3h12l-4.5 5.25V13L6.5 11.5V8.25L2 3z" />
1649
1815
  </svg>
1650
- ${e.filterSummary ? h`<span class="filter-summary">${e.filterSummary}</span>` : u}
1816
+ ${e.filterSummary ? c`<span class="filter-summary">${e.filterSummary}</span>` : u}
1651
1817
  </button>
1652
1818
  </th>
1653
1819
  `;
1654
1820
  }
1655
1821
  renderHeader(e, t) {
1656
- const a = e.sortable ?? !0, i = this._sortColumns.findIndex((d) => d.property === e.name), s = i >= 0 ? this._sortColumns[i].direction : null, r = this._columnWidths.get(e.name) ?? e.width, o = e.headerRenderer ? e.headerRenderer(e) : e.label ?? e.name, n = {};
1657
- return typeof r == "number" && (n.width = `${r}px`, n.minWidth = `${r}px`), h`
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 = {};
1823
+ return typeof r == "number" && (l.width = `${r}px`, l.minWidth = `${r}px`), c`
1658
1824
  <th
1659
1825
  scope="col"
1660
1826
  data-column=${e.name}
1661
1827
  data-sortable=${a ? "true" : "false"}
1662
- aria-sort=${s ? s === "ascending" ? "ascending" : "descending" : "none"}
1663
- style=${_(n)}
1828
+ aria-sort=${i ? i === "ascending" ? "ascending" : "descending" : "none"}
1829
+ style=${_(l)}
1664
1830
  >
1665
- ${a ? h`<button
1831
+ ${a ? c`<button
1666
1832
  type="button"
1667
1833
  class="header-cell header-sort"
1668
- @click=${(d) => this.onHeaderClick(e, d)}
1834
+ @click=${(h) => this.onHeaderClick(e, h)}
1669
1835
  >
1670
- <span>${w(o)}</span>
1671
- ${i >= 0 && this._sortColumns.length > 1 ? h`<span class="sort-index">${i + 1}</span>` : u}
1672
- </button>` : h`<span class="header-cell">
1673
- <span>${w(o)}</span>
1836
+ <span>${C(o)}</span>
1837
+ ${s >= 0 && this._sortColumns.length > 1 ? c`<span class="sort-index">${s + 1}</span>` : u}
1838
+ </button>` : c`<span class="header-cell">
1839
+ <span>${C(o)}</span>
1674
1840
  </span>`}
1675
- ${this._resizableColumns ? h`<span
1841
+ ${this._resizableColumns ? c`<span
1676
1842
  class="resize-handle"
1677
1843
  role="separator"
1678
1844
  tabindex="0"
@@ -1680,78 +1846,101 @@ class X extends P {
1680
1846
  aria-label=${this.mergedLabels.resizeColumn(e.label ?? e.name)}
1681
1847
  aria-valuemin=${F}
1682
1848
  aria-valuenow=${Math.round(r ?? 0) || u}
1683
- @pointerdown=${(d) => this.startColumnResize(e, d)}
1684
- @keydown=${(d) => this.onResizeHandleKeydown(e, d)}
1849
+ @pointerdown=${(h) => this.startColumnResize(e, h)}
1850
+ @keydown=${(h) => this.onResizeHandleKeydown(e, h)}
1685
1851
  ></span>` : u}
1686
1852
  </th>
1687
1853
  `;
1688
1854
  }
1689
- renderRow(e, t, a, i) {
1690
- const { row: s, depth: r, isExpanded: o, isPlaceholder: n } = e, d = !n && this._selectedIds.has(t), c = !n && this._cutIds.has(t), p = !n && this._focusedRowKey === t, f = n ? 0 : this.extractChildCount(s), b = this._tree && !n && f > 0, I = !n && s != null && this.isParentIndeterminate(s);
1691
- return h`
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);
1857
+ return c`
1692
1858
  <tr
1693
1859
  role="row"
1694
1860
  aria-rowindex=${a + 1 + (this.hasFilterRow ? 2 : 1)}
1695
1861
  aria-level=${this._tree ? r + 1 : u}
1696
1862
  aria-expanded=${this._tree && f > 0 ? o ? "true" : "false" : u}
1697
- aria-busy=${n ? "true" : u}
1698
- aria-selected=${!n && this._selectionMode !== "none" ? d ? "true" : "false" : u}
1863
+ aria-busy=${l ? "true" : u}
1864
+ aria-selected=${!l && this._selectionMode !== "none" ? h ? "true" : "false" : u}
1699
1865
  data-row-key=${t}
1700
- data-selected=${d ? "true" : "false"}
1701
- data-cut=${c ? "true" : "false"}
1866
+ data-selected=${h ? "true" : "false"}
1867
+ data-cut=${d ? "true" : "false"}
1702
1868
  data-focused=${p ? "true" : "false"}
1703
- data-placeholder=${n ? "true" : "false"}
1869
+ data-placeholder=${l ? "true" : "false"}
1704
1870
  data-depth=${this._tree ? String(r) : u}
1705
- data-clickable=${!n && (this._selectionMode !== "none" || this.hasRowClickListeners()) ? "true" : "false"}
1706
- tabindex=${!n && (this._selectionMode !== "none" || this._tree) ? this._focusedRowKey === t || this._focusedRowKey === null && a === 0 ? "0" : "-1" : u}
1707
- @focus=${n ? null : () => {
1871
+ 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}
1873
+ @focus=${l ? null : () => {
1708
1874
  this._focusedRowKey = t, this.requestUpdate();
1709
1875
  }}
1710
- @click=${n ? null : (m) => this.onRowClick(s, t, a, m)}
1711
- @dblclick=${n ? null : (m) => this.onRowDblClick(s, t, a, m)}
1712
- @contextmenu=${n ? null : (m) => this.onRowContextMenu(s, t, a, m)}
1713
- @keydown=${n ? null : (m) => this.onRowKeydown(s, t, a, e.parentId, r, o, f, m)}
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)}
1714
1880
  >
1715
- ${this._tree ? h`<td class="tree-chevron-cell" style=${_({ paddingInlineStart: `${r * this._treeIndent}rem` })}>
1716
- ${b ? h`<button
1881
+ ${this._tree ? c`<td class="tree-chevron-cell" style=${_({ paddingInlineStart: `${r * this._treeIndent}rem` })}>
1882
+ ${b ? c`<button
1717
1883
  type="button"
1718
1884
  class="tree-chevron"
1719
1885
  aria-label=${o ? this.mergedLabels.collapseRow : this.mergedLabels.expandRow}
1720
1886
  aria-expanded=${o ? "true" : "false"}
1721
1887
  data-expanded=${o ? "true" : "false"}
1722
- @click=${(m) => this.toggleExpand(s, e.parentId, r, m)}
1888
+ @click=${(m) => this.toggleExpand(i, e.parentId, r, m)}
1723
1889
  >${o ? "▾" : "▸"}</button>` : u}
1724
1890
  </td>` : u}
1725
- ${i ? h`<td class="checkbox-cell" @click=${(m) => m.stopPropagation()}>
1726
- ${n ? u : h`<mp-checkbox
1727
- aria-label=${this.mergedLabels.selectRow(a + 1)}
1728
- .checked=${d}
1729
- .indeterminate=${I}
1730
- @change=${() => this.onRowCheckboxToggle(s, t)}
1891
+ ${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()}
1895
+ >
1896
+ ${l ? u : c`<mp-checkbox
1897
+ .checked=${h}
1898
+ .indeterminate=${k}
1899
+ @change=${() => this.onRowCheckboxToggle(i, t)}
1731
1900
  ></mp-checkbox>`}
1732
1901
  </td>` : u}
1733
- ${this._rowRenderer ? this.renderRowFromRenderer(s, a, { depth: r, isExpanded: o, isPlaceholder: n }) : n ? h`<td colspan=${this._columns.length} class="tree-placeholder-cell" aria-label=${this.mergedLabels.loading}>…</td>` : this._columns.map((m) => this.renderCell(s, m, a))}
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))}
1734
1903
  </tr>
1735
1904
  `;
1736
1905
  }
1906
+ /**
1907
+ * Names every rendered row checkbox (D14): `rowLabel(row)`, else the trimmed
1908
+ * text of the row's first data cell, else the row number.
1909
+ *
1910
+ * Runs after each render rather than in the template because the cell text
1911
+ * only exists once the cell is rendered — and it may be consumer DOM from a
1912
+ * `cellRenderer` or `rowRenderer` — so a re-rendered cell renames its
1913
+ * checkbox on the same update. The attribute is written only when it
1914
+ * changes, so an unchanged name costs no mutation.
1915
+ */
1916
+ nameRowCheckboxes() {
1917
+ 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);
1924
+ }
1925
+ }
1737
1926
  renderRowFromRenderer(e, t, a) {
1738
- const i = this._rowRenderer(e, t, a);
1739
- if (i == null)
1740
- return a.isPlaceholder ? h`<td colspan=${this._columns.length} class="tree-placeholder-cell" aria-label=${this.mergedLabels.loading}>…</td>` : this._columns.map((s) => this.renderCell(e, s, t));
1741
- if (Array.isArray(i) || J(i)) {
1742
- const s = [];
1743
- for (const r of i) s.push(r);
1744
- return s;
1927
+ const s = this._rowRenderer(e, t, a);
1928
+ 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;
1745
1934
  }
1746
- return i;
1935
+ return s;
1747
1936
  }
1748
1937
  renderCell(e, t, a) {
1749
- const i = t.cellRenderer ? t.cellRenderer(e, t, a) : Y(e, t);
1750
- return h`<td class=${t.cellClass ?? ""} data-column=${t.name}>${w(i)}</td>`;
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>`;
1751
1940
  }
1752
1941
  renderFooter(e) {
1753
- const t = Array.from({ length: e }, (a, i) => i + 1);
1754
- return h`
1942
+ const t = Array.from({ length: e }, (a, s) => s + 1);
1943
+ return c`
1755
1944
  <div class="datatable-footer">
1756
1945
  <mp-pagination
1757
1946
  class="datatable-per-page"
@@ -1811,65 +2000,94 @@ class X extends P {
1811
2000
  if (this._cachedFlatList !== null) return this._cachedFlatList;
1812
2001
  if (!this._tree) {
1813
2002
  if (this.isRootWindowed()) {
1814
- const r = this._totalRecords ?? this._data.length, o = Math.max(1, this._perPage), n = new Array(r);
1815
- for (let d = 0; d < r; d++) {
1816
- const c = Math.floor(d / o) + 1, p = d % o, f = c === 1 ? this._data[p] : this._pageCache.get(c)?.[p];
1817
- n[d] = f !== void 0 ? { row: f, key: this._rowKey(f, d), depth: 0, parentId: null, isExpanded: !1, isPlaceholder: !1 } : { row: void 0, key: `__placeholder-flat-${d}`, depth: 0, parentId: null, page: c, isExpanded: !1, isPlaceholder: !0 };
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 };
1818
2007
  }
1819
- return this._cachedFlatList = n;
2008
+ return this._cachedFlatList = h;
1820
2009
  }
1821
- const s = (() => {
1822
- let r = this._data;
1823
- if (this._autoSort && this._sortColumns.length > 0 && (r = y(r, this._sortColumns)), this._pagination && !this.isExternallyPaged()) {
1824
- const o = (this._page - 1) * this._perPage;
1825
- r = r.slice(o, o + this._perPage);
1826
- }
1827
- return r;
1828
- })();
1829
- return this._cachedFlatList = s.map((r, o) => ({
1830
- row: r,
1831
- key: this._rowKey(r, o),
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();
2011
+ return this._cachedFlatList = r.map((o, l) => ({
2012
+ row: o,
2013
+ key: this._rowKey(o, i + l),
1832
2014
  depth: 0,
1833
2015
  parentId: null,
1834
2016
  isExpanded: !1,
1835
2017
  isPlaceholder: !1
1836
2018
  }));
1837
2019
  }
1838
- const e = [], t = Math.max(1, this._perPage), a = (s) => this._autoSort && this._sortColumns.length > 0 ? y(s, this._sortColumns) : s, i = (s, r, o) => {
1839
- const n = this.extractId(s), d = n != null && this._expandedIds.has(n), c = this.extractChildCount(s);
1840
- if (e.push({ row: s, key: this._rowKey(s, e.length), depth: r, parentId: o, isExpanded: d, isPlaceholder: !1 }), !d || c === 0 || n == null) return;
1841
- const p = this._childCache.get(n);
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);
1842
2024
  if (p && p.length > 0) {
1843
- for (const b of a(p)) i(b, r + 1, n);
1844
- const f = this._childTotals.get(n) ?? p.length;
2025
+ for (const b of a(p)) s(b, r + 1, l);
2026
+ const f = this._childTotals.get(l) ?? p.length;
1845
2027
  for (let b = 0; b < Math.max(0, f - p.length); b++)
1846
- e.push({ row: void 0, key: `__placeholder-${String(n)}-${p.length + b}`, depth: r + 1, parentId: n, isExpanded: !1, isPlaceholder: !0 });
2028
+ e.push({ row: void 0, key: `__placeholder-${String(l)}-${p.length + b}`, depth: r + 1, parentId: l, isExpanded: !1, isPlaceholder: !0 });
1847
2029
  } else
1848
- for (let f = 0; f < c; f++)
1849
- e.push({ row: void 0, key: `__placeholder-${String(n)}-${f}`, depth: r + 1, parentId: n, isExpanded: !1, isPlaceholder: !0 });
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 });
1850
2032
  };
1851
2033
  if (this.isRootWindowed()) {
1852
- const s = this._totalRecords ?? this._data.length;
1853
- for (let r = 0; r < s; r++) {
1854
- const o = Math.floor(r / t) + 1, n = r % t, d = o === 1 ? this._data[n] : this._pageCache.get(o)?.[n];
1855
- d === void 0 ? e.push({ row: void 0, key: `__placeholder-root-${r}`, depth: 0, parentId: null, page: o, isExpanded: !1, isPlaceholder: !0 }) : i(d, 0, null);
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);
1856
2038
  }
1857
2039
  } else {
1858
- const s = this._autoSort && this._sortColumns.length > 0 ? y(this._data, this._sortColumns) : this._data;
1859
- for (const r of s) i(r, 0, null);
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);
1860
2042
  }
1861
2043
  return this._cachedFlatList = e;
1862
2044
  }
2045
+ /** `_data` in display order: client-sorted when the WC owns sorting. */
2046
+ localSortedRows() {
2047
+ return this._autoSort && this._sortColumns.length > 0 ? y(this._data, this._sortColumns) : this._data;
2048
+ }
2049
+ /**
2050
+ * Drops the flat-list memo. It is otherwise reset only in `willUpdate`, so a
2051
+ * path that runs between a data change and the next render (a programmatic
2052
+ * setter, an event fired before the re-render) would read the old rows.
2053
+ */
2054
+ freshFlatList() {
2055
+ return this._cachedFlatList = null, this.getFlatList();
2056
+ }
2057
+ /**
2058
+ * Every loaded row that has a renderer-assigned key, as `[key, row]`. The keys
2059
+ * are the ones the renderer uses (K1): a positional fallback key only means
2060
+ * anything at the row's rendered index. With local pagination every page is
2061
+ * loaded, so rows of the other pages are keyed by their global index too.
2062
+ */
2063
+ 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]);
2066
+ }
2067
+ /**
2068
+ * The key the renderer gives a row object. A row outside the live entries (a
2069
+ * child of a collapsed parent, a row only the host knows) has no rendered
2070
+ * index, so it falls back to an index-free `rowKey` call — exact for any
2071
+ * id-based key, and a positional key is already warned about.
2072
+ */
2073
+ keyOfRow(e) {
2074
+ 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);
2076
+ }
2077
+ /** `keyOfRow` against the current data, for paths that may run before a re-render. */
2078
+ rowKeyLookup() {
2079
+ return this.freshFlatList(), (e) => this.keyOfRow(e);
2080
+ }
1863
2081
  computeVisibleRows() {
1864
2082
  const e = this.getFlatList(), t = this._tree ? 0 : this._pagination ? (this._page - 1) * this._perPage : 0;
1865
- let a = e, i = 0;
2083
+ let a = e, s = 0;
1866
2084
  if (this._virtualScroll) {
1867
- const { startIndex: s, endIndex: r } = this._virtualRange;
1868
- a = e.slice(s, r), i = s;
2085
+ const { startIndex: i, endIndex: r } = this._virtualRange;
2086
+ a = e.slice(i, r), s = i;
1869
2087
  }
1870
- return a.map((s, r) => {
1871
- const o = t + i + r;
1872
- return { row: s.row, rowIndex: o, key: s.key, flat: s };
2088
+ return a.map((i, r) => {
2089
+ const o = t + s + r;
2090
+ return { row: i.row, rowIndex: o, key: i.key, flat: i };
1873
2091
  });
1874
2092
  }
1875
2093
  // ─── Tree-mode helpers ───────────────────────────────────────────────────
@@ -1881,21 +2099,18 @@ class X extends P {
1881
2099
  const t = e[this._childCountKey];
1882
2100
  return typeof t == "number" && t > 0 ? t : 0;
1883
2101
  }
1884
- /** Walks the loaded subtree of `row` and returns the rowKey for every descendant. */
1885
- collectDescendantKeys(e) {
2102
+ /**
2103
+ * Walks the loaded subtree of `row` and returns `[key, row]` for every
2104
+ * descendant — the row too, because a cascade selects it and the selection
2105
+ * remembers the rows it selected.
2106
+ */
2107
+ collectDescendants(e) {
1886
2108
  const t = this.extractId(e), a = t != null ? this._childCache.get(t) : void 0;
1887
- if (!a) return [];
1888
- const i = [];
1889
- for (const s of a) {
1890
- i.push(this._rowKey(s, -1));
1891
- const r = this.collectDescendantKeys(s);
1892
- for (const o of r) i.push(o);
1893
- }
1894
- return i;
2109
+ return a ? a.flatMap((s) => [[this.keyOfRow(s), s], ...this.collectDescendants(s)]) : [];
1895
2110
  }
1896
2111
  /** Some-but-not-all loaded descendants selected → indeterminate parent checkbox. */
1897
- isParentIndeterminate(e) {
1898
- return this._selectionStrategy !== "cascading" || e == null ? !1 : this.getIndeterminateKeys().has(this._rowKey(e, -1));
2112
+ isParentIndeterminate(e, t) {
2113
+ return this._selectionStrategy !== "cascading" || e == null ? !1 : this.getIndeterminateKeys().has(t);
1899
2114
  }
1900
2115
  /**
1901
2116
  * Per-render memo: the set of row keys whose loaded subtree is partially
@@ -1910,16 +2125,16 @@ class X extends P {
1910
2125
  if (this._selectionStrategy !== "cascading" || !this._tree)
1911
2126
  return this._cachedIndeterminateKeys = e;
1912
2127
  const t = (a) => {
1913
- const i = this.extractId(a);
1914
- if (i == null) return { selected: 0, total: 0 };
1915
- const s = this._childCache.get(i);
1916
- if (!s || s.length === 0) return { selected: 0, total: 0 };
2128
+ const s = this.extractId(a);
2129
+ 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 };
1917
2132
  let r = 0, o = 0;
1918
- for (const n of s) {
1919
- const d = this._rowKey(n, -1), c = this._selectedIds.has(d) ? 1 : 0, p = t(n);
1920
- r += c + p.selected, o += 1 + p.total;
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;
1921
2136
  }
1922
- return o > 0 && r > 0 && r < o && e.add(this._rowKey(a, -1)), { selected: r, total: o };
2137
+ return o > 0 && r > 0 && r < o && e.add(this.keyOfRow(a)), { selected: r, total: o };
1923
2138
  };
1924
2139
  for (const a of this._data) t(a);
1925
2140
  return this._cachedIndeterminateKeys = e;
@@ -1929,19 +2144,19 @@ class X extends P {
1929
2144
  * children aren't cached yet so the wrapper can bridge to the consumer's
1930
2145
  * `[fetch]` callback. Always fires `expanded-ids-change`.
1931
2146
  */
1932
- toggleExpand(e, t, a, i) {
1933
- i.stopPropagation(), i.preventDefault();
1934
- const s = this.extractId(e);
1935
- if (s == null) return;
2147
+ toggleExpand(e, t, a, s) {
2148
+ s.stopPropagation(), s.preventDefault();
2149
+ const i = this.extractId(e);
2150
+ if (i == null) return;
1936
2151
  const r = new Set(this._expandedIds);
1937
2152
  let o;
1938
- r.has(s) ? (r.delete(s), o = !1) : (r.add(s), o = !0), this._expandedIds = r, o ? (this.dispatchEvent(
2153
+ r.has(i) ? (r.delete(i), o = !1) : (r.add(i), o = !0), this._expandedIds = r, o ? (this.dispatchEvent(
1939
2154
  new CustomEvent("mp-datatable-row-expand", {
1940
2155
  detail: { row: e, depth: a, parentId: t },
1941
2156
  bubbles: !0,
1942
2157
  composed: !0
1943
2158
  })
1944
- ), this.extractChildCount(e) > 0 && !this._childCache.has(s) && !this._pendingFetches.has(s) && this.fetchChildren(s)) : this.dispatchEvent(
2159
+ ), this.extractChildCount(e) > 0 && !this._childCache.has(i) && !this._pendingFetches.has(i) && this.fetchChildren(i)) : this.dispatchEvent(
1945
2160
  new CustomEvent("mp-datatable-row-collapse", {
1946
2161
  detail: { row: e, depth: a, parentId: t },
1947
2162
  bubbles: !0,
@@ -1973,8 +2188,8 @@ class X extends P {
1973
2188
  const a = await this._fetch({ parentId: null, page: e, perPage: this._perPage, sortColumns: [...this._sortColumns] });
1974
2189
  if (t !== this._fetchGeneration || !this._fetch) return;
1975
2190
  this._pendingPageFetches.delete(e), this._pageCache.set(e, [...a?.data ?? []]);
1976
- const i = a?.totalRecords == null ? null : Math.max(0, Math.floor(a.totalRecords));
1977
- i != null && (this._totalRecords = i), this.requestUpdate();
2191
+ const s = a?.totalRecords == null ? null : Math.max(0, Math.floor(a.totalRecords));
2192
+ s != null && (this._totalRecords = s), this.requestUpdate();
1978
2193
  } catch (a) {
1979
2194
  this._pendingPageFetches.delete(e), console.error("[mp-datatable] fetch failed for root page", e, a);
1980
2195
  }
@@ -2006,14 +2221,14 @@ class X extends P {
2006
2221
  let a;
2007
2222
  try {
2008
2223
  a = await this._fetch({ parentId: null, page: e, perPage: this._perPage, sortColumns: [...this._sortColumns] });
2009
- } catch (s) {
2010
- console.error("[mp-datatable] fetch failed for page", e, s);
2224
+ } catch (i) {
2225
+ console.error("[mp-datatable] fetch failed for page", e, i);
2011
2226
  return;
2012
2227
  }
2013
2228
  if (t !== this._fetchGeneration || !this._fetch) return;
2014
2229
  this._data = [...a?.data ?? []];
2015
- const i = a?.totalRecords == null ? null : Math.max(0, Math.floor(a.totalRecords));
2016
- this._totalRecords = i, this._initialFetchDone = !0, this.requestUpdate();
2230
+ const s = a?.totalRecords == null ? null : Math.max(0, Math.floor(a.totalRecords));
2231
+ this._totalRecords = s, this._initialFetchDone = !0, this.requestUpdate();
2017
2232
  }
2018
2233
  /**
2019
2234
  * Coalesce sort/perPage/page changes (which arrive both as user actions and
@@ -2032,34 +2247,50 @@ class X extends P {
2032
2247
  this._initialFetchDone && e === this._lastReloadKey || (this._lastReloadKey = e, this._fetchGeneration++, this._pageCache.clear(), this._pendingPageFetches.clear(), this._childCache.clear(), this._childTotals.clear(), this._pendingFetches.clear(), this.loadPage(this._virtualScroll ? 1 : this._page));
2033
2248
  }));
2034
2249
  }
2035
- /** Keyboard handling on a tree-mode row. Arrow keys + Enter/Space toggle expansion. */
2036
- onRowKeydown(e, t, a, i, s, r, o, n) {
2037
- if (!n.altKey && n.composedPath()[0] === n.currentTarget) {
2038
- if (n.key === "ArrowDown" || n.key === "ArrowUp") {
2039
- n.preventDefault();
2040
- const d = Array.from(
2250
+ /**
2251
+ * Row keymap, the same in every mode: ArrowUp/Down move, ArrowRight/Left
2252
+ * expand/collapse a tree row, Enter opens (row-click), Space selects.
2253
+ * 'single'/'multiple': Enter and Space both select with the click modifiers
2254
+ * and emit row-click. 'checkbox': Enter only emits row-click, Space only
2255
+ * toggles the row's checkbox.
2256
+ */
2257
+ onRowKeydown(e, t, a, s, i, r, o, l) {
2258
+ if (!l.altKey && l.composedPath()[0] === l.currentTarget) {
2259
+ if (l.key === "ArrowDown" || l.key === "ArrowUp") {
2260
+ l.preventDefault();
2261
+ const h = Array.from(
2041
2262
  this.renderRoot.querySelectorAll("tbody tr[data-row-key]")
2042
- ), c = d.findIndex((f) => f.dataset.rowKey === t), p = d[c + (n.key === "ArrowDown" ? 1 : -1)];
2263
+ ), d = h.findIndex((f) => f.dataset.rowKey === t), p = h[d + (l.key === "ArrowDown" ? 1 : -1)];
2043
2264
  p && p.focus();
2044
2265
  return;
2045
2266
  }
2046
2267
  if (this._tree) {
2047
- if (n.key === "ArrowRight" && o > 0 && !r) {
2048
- this.toggleExpand(e, i, s, n);
2268
+ if (l.key === "ArrowRight" && o > 0 && !r) {
2269
+ this.toggleExpand(e, s, i, l);
2049
2270
  return;
2050
2271
  }
2051
- if (n.key === "ArrowLeft" && r) {
2052
- this.toggleExpand(e, i, s, n);
2272
+ if (l.key === "ArrowLeft" && r) {
2273
+ this.toggleExpand(e, s, i, l);
2053
2274
  return;
2054
2275
  }
2055
- if ((n.key === "Enter" || n.key === " ") && o > 0) {
2056
- this.toggleExpand(e, i, s, n);
2276
+ }
2277
+ if ((l.key === "Enter" || l.key === " ") && this._selectionMode === "checkbox") {
2278
+ if (l.preventDefault(), this._focusedRowKey = t, l.key === " ") {
2279
+ l.shiftKey || this.onRowCheckboxToggle(e, t), this.requestUpdate();
2057
2280
  return;
2058
2281
  }
2282
+ this.requestUpdate(), this.dispatchEvent(
2283
+ new CustomEvent("mp-datatable-row-click", {
2284
+ detail: { row: e, rowIndex: a, rowKey: t, originalEvent: l },
2285
+ bubbles: !0,
2286
+ composed: !0
2287
+ })
2288
+ );
2289
+ return;
2059
2290
  }
2060
- (n.key === "Enter" || n.key === " ") && this._selectionMode !== "none" && (n.preventDefault(), this._focusedRowKey = t, this.handleSelectionOnClick(t, n), this.requestUpdate(), this.dispatchEvent(
2291
+ (l.key === "Enter" || l.key === " ") && this._selectionMode !== "none" && (l.preventDefault(), this._focusedRowKey = t, this.handleSelectionOnClick(e, t, l), this.requestUpdate(), this.dispatchEvent(
2061
2292
  new CustomEvent("mp-datatable-row-click", {
2062
- detail: { row: e, rowIndex: a, rowKey: t, originalEvent: n },
2293
+ detail: { row: e, rowIndex: a, rowKey: t, originalEvent: l },
2063
2294
  bubbles: !0,
2064
2295
  composed: !0
2065
2296
  })
@@ -2074,13 +2305,13 @@ class X extends P {
2074
2305
  * the resize handle is the button's sibling, so its clicks never land here.
2075
2306
  */
2076
2307
  onHeaderClick(e, t) {
2077
- const a = B(this._sortColumns, e.name, t.shiftKey);
2308
+ const a = H(this._sortColumns, e.name, t.shiftKey);
2078
2309
  this._sortColumns = a, this._page = 1;
2079
- const i = a.find((s) => s.property === e.name);
2310
+ const s = a.find((i) => i.property === e.name);
2080
2311
  this.liveAnnouncer.announce(
2081
2312
  this.mergedLabels.announceSorted(
2082
2313
  e.label ?? e.name,
2083
- i ? i.direction === "ascending" ? "ascending" : "descending" : "none"
2314
+ s ? s.direction === "ascending" ? "ascending" : "descending" : "none"
2084
2315
  )
2085
2316
  ), this.requestUpdate(), this.scheduleFetchReload(), this.dispatchEvent(
2086
2317
  new CustomEvent("mp-datatable-sort-change", {
@@ -2090,41 +2321,60 @@ class X extends P {
2090
2321
  })
2091
2322
  );
2092
2323
  }
2093
- onRowClick(e, t, a, i) {
2094
- i.target.closest('input[type="checkbox"]') || (this._focusedRowKey = t, this.handleSelectionOnClick(t, i), this.requestUpdate(), this.dispatchEvent(
2324
+ onRowClick(e, t, a, s) {
2325
+ this._focusedRowKey = t, this._selectionMode !== "checkbox" && this.handleSelectionOnClick(e, t, s), this.requestUpdate(), this.dispatchEvent(
2095
2326
  new CustomEvent("mp-datatable-row-click", {
2096
- detail: { row: e, rowIndex: a, rowKey: t, originalEvent: i },
2327
+ detail: { row: e, rowIndex: a, rowKey: t, originalEvent: s },
2097
2328
  bubbles: !0,
2098
2329
  composed: !0
2099
2330
  })
2100
- ));
2331
+ );
2101
2332
  }
2102
- onRowDblClick(e, t, a, i) {
2333
+ onRowDblClick(e, t, a, s) {
2103
2334
  this.dispatchEvent(
2104
2335
  new CustomEvent("mp-datatable-row-dblclick", {
2105
- detail: { row: e, rowIndex: a, rowKey: t, originalEvent: i },
2336
+ detail: { row: e, rowIndex: a, rowKey: t, originalEvent: s },
2106
2337
  bubbles: !0,
2107
2338
  composed: !0
2108
2339
  })
2109
2340
  );
2110
2341
  }
2111
- onRowContextMenu(e, t, a, i) {
2112
- this._selectionMode !== "none" && !this._selectedIds.has(t) && (this._selectedIds = /* @__PURE__ */ new Set([t]), this._focusedRowKey = t, this.emitSelectionChange(), this.requestUpdate()), this.dispatchEvent(
2342
+ onRowContextMenu(e, t, a, s) {
2343
+ this._selectionMode !== "none" && this._selectionMode !== "checkbox" && !this._selectedIds.has(t) && (this.commitSelection([t], [[t, e]]), this._focusedRowKey = t, this.emitSelectionChange(), this.requestUpdate()), this.dispatchEvent(
2113
2344
  new CustomEvent("mp-datatable-row-contextmenu", {
2114
- detail: { row: e, rowIndex: a, rowKey: t, originalEvent: i },
2345
+ detail: { row: e, rowIndex: a, rowKey: t, originalEvent: s },
2115
2346
  bubbles: !0,
2116
2347
  composed: !0,
2117
2348
  cancelable: !0
2118
2349
  })
2119
- ) || i.preventDefault();
2350
+ ) || s.preventDefault();
2120
2351
  }
2121
- /** Row checkboxes render only in `'multiple'` mode, so this is multi-select toggling. */
2352
+ /**
2353
+ * A click anywhere in the checkbox cell, in every mode. The cell is
2354
+ * selection-only, so neither its click nor its double-click reaches the row
2355
+ * (D12: a double-click on a checkbox used to open the row).
2356
+ *
2357
+ * In 'checkbox' mode the whole cell is the hit target, not just the 20px box.
2358
+ * A click that went through the checkbox's own shadow root is the checkbox
2359
+ * operating itself (its change handler toggles), so it is left alone; every
2360
+ * other click toggles here. `closest('mp-checkbox')` cannot tell the two
2361
+ * apart: a click on the checkbox host's padding is retargeted to the host yet
2362
+ * fires no change, so it would be swallowed (spike S1). No focus() and no
2363
+ * preventDefault(): the browser focuses the row natively, which keeps Enter,
2364
+ * Space and the arrow keys working from there (spike S4).
2365
+ */
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);
2370
+ }
2371
+ /** Row checkboxes render only in the multi-select modes, so this is multi-select toggling. */
2122
2372
  onRowCheckboxToggle(e, t) {
2123
- const a = !this._selectedIds.has(t), i = /* @__PURE__ */ new Set([
2124
- t,
2125
- ...this._tree && this._selectionStrategy === "cascading" ? this.collectDescendantKeys(e) : []
2126
- ]);
2127
- this._selectedIds = a ? /* @__PURE__ */ new Set([...this._selectedIds, ...i]) : new Set([...this._selectedIds].filter((s) => !i.has(s))), this.emitSelectionChange(), this.requestUpdate();
2373
+ const a = !this._selectedIds.has(t), s = [
2374
+ [t, e],
2375
+ ...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();
2128
2378
  }
2129
2379
  /**
2130
2380
  * Clears the entire selection. The header checkbox is only rendered when
@@ -2134,30 +2384,81 @@ class X extends P {
2134
2384
  * therefore one-way: visible → deselect-all → hidden again.
2135
2385
  */
2136
2386
  onDeselectAll() {
2137
- this._selectedIds.size !== 0 && (this._selectedIds = /* @__PURE__ */ new Set(), this.emitSelectionChange(), this.requestUpdate());
2387
+ this._selectedIds.size !== 0 && (this.commitSelection([]), this.emitSelectionChange(), this.requestUpdate());
2138
2388
  }
2139
- handleSelectionOnClick(e, t) {
2389
+ handleSelectionOnClick(e, t, a) {
2140
2390
  if (this._selectionMode !== "none") {
2141
2391
  if (this._selectionMode === "single") {
2142
- this._selectedIds = /* @__PURE__ */ new Set([e]), this.emitSelectionChange();
2392
+ this.commitSelection([t], [[t, e]]), this.emitSelectionChange();
2143
2393
  return;
2144
2394
  }
2145
- if (t.shiftKey && this._selectionAnchorKey && this._selectionAnchorKey !== e) {
2146
- const a = this.computeVisibleRows(), i = a.findIndex((r) => r.key === this._selectionAnchorKey), s = a.findIndex((r) => r.key === e);
2147
- if (i >= 0 && s >= 0) {
2148
- const [r, o] = i < s ? [i, s] : [s, i], n = a.slice(r, o + 1).map((d) => d.key);
2149
- this._selectedIds = /* @__PURE__ */ new Set([...this._selectedIds, ...n]), this.emitSelectionChange();
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)) {
2400
+ this.liveAnnouncer.announce(this.mergedLabels.rangeIncomplete);
2401
+ return;
2402
+ }
2403
+ const d = h.map((p) => [p.key, p.row]);
2404
+ this.commitSelection([...this._selectedIds, ...d.map(([p]) => p)], d), this.emitSelectionChange();
2150
2405
  return;
2151
2406
  }
2152
2407
  }
2153
- if (t.ctrlKey || t.metaKey) {
2154
- const a = new Set(this._selectedIds);
2155
- a.has(e) ? a.delete(e) : a.add(e), this._selectedIds = a, this._selectionAnchorKey = e, this.emitSelectionChange();
2408
+ if (a.ctrlKey || a.metaKey) {
2409
+ const s = new Set(this._selectedIds);
2410
+ s.has(t) ? s.delete(t) : s.add(t), this.commitSelection(s, [[t, e]]), this._selectionAnchorKey = t, this.emitSelectionChange();
2156
2411
  return;
2157
2412
  }
2158
- this._selectedIds = /* @__PURE__ */ new Set([e]), this._selectionAnchorKey = e, this.emitSelectionChange();
2413
+ this.commitSelection([t], [[t, e]]), this._selectionAnchorKey = t, this.emitSelectionChange();
2159
2414
  }
2160
2415
  }
2416
+ /**
2417
+ * The one write path for a user-driven selection change. `rows` supplies the
2418
+ * row of each key being selected; the remembered rows are then pruned to the
2419
+ * new keys, so a deselected row is forgotten in the same step.
2420
+ */
2421
+ commitSelection(e, t = []) {
2422
+ 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);
2425
+ this.pruneSelectedRowCache();
2426
+ }
2427
+ /**
2428
+ * Every row the element holds right now, by key: the loaded rows (keyed as
2429
+ * the renderer keys them, K1) plus the fetched children of collapsed parents
2430
+ * (through `keyOfRow`'s index-free fallback).
2431
+ */
2432
+ liveRowMap() {
2433
+ const e = new Map(this.liveRowEntries(this.freshFlatList()));
2434
+ 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);
2438
+ }
2439
+ return e;
2440
+ }
2441
+ /** Remembers the loaded row of every selected key (a loaded row always wins, D2). */
2442
+ rememberLiveSelectedRows() {
2443
+ for (const [e, t] of this.liveRowMap())
2444
+ t !== void 0 && this._selectedIds.has(e) && this._selectedRowCache.set(e, t);
2445
+ }
2446
+ /**
2447
+ * True when `pairs` is exactly the current selection: the same keys in the
2448
+ * same order, each with the row object the element would report for it.
2449
+ */
2450
+ isSameSelectedRows(e) {
2451
+ if (e.length !== this._selectedIds.size) return !1;
2452
+ 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]);
2456
+ }
2457
+ /** Forgets the rows of keys that left the selection. One pass, deletes in place. */
2458
+ pruneSelectedRowCache() {
2459
+ for (const e of this._selectedRowCache.keys())
2460
+ this._selectedIds.has(e) || this._selectedRowCache.delete(e);
2461
+ }
2161
2462
  emitSelectionChange() {
2162
2463
  const e = [...this._selectedIds];
2163
2464
  this.liveAnnouncer.announce(this.mergedLabels.announceSelection(e.length)), this.dispatchEvent(
@@ -2169,19 +2470,21 @@ class X extends P {
2169
2470
  );
2170
2471
  }
2171
2472
  /**
2172
- * Resolve row keys → row objects across every loaded source (page-1 `_data`,
2173
- * fetched windows in `_pageCache`, tree children in `_childCache`). One pass
2174
- * builds a key→row index; unresolvable ids are skipped.
2473
+ * Resolves keys to rows, index-aligned with `ids` (D3): the loaded row if
2474
+ * there is one, else the row remembered at selection time, else `undefined`.
2475
+ *
2476
+ * A loaded row also refreshes the remembered one, so a re-fetched row object
2477
+ * always wins over a stale copy. Loaded rows are keyed exactly as the
2478
+ * renderer keys them (K1); children of collapsed parents have no rendered
2479
+ * index and go through `keyOfRow`'s index-free fallback.
2175
2480
  */
2176
2481
  resolveRows(e) {
2177
2482
  if (e.length === 0) return [];
2178
- const t = /* @__PURE__ */ new Map(), a = (i) => {
2179
- for (const s of i) t.set(this._rowKey(s, -1), s);
2180
- };
2181
- a(this._data);
2182
- for (const i of this._pageCache.values()) a(i);
2183
- for (const i of this._childCache.values()) a(i);
2184
- return e.map((i) => t.get(i)).filter((i) => i !== void 0);
2483
+ 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);
2487
+ });
2185
2488
  }
2186
2489
  gotoPage(e) {
2187
2490
  const t = this._totalRecords ?? this._data.length, a = Math.max(1, Math.ceil(t / this._perPage));
@@ -2201,38 +2504,38 @@ class X extends P {
2201
2504
  onResizeHandleKeydown(e, t) {
2202
2505
  if (!this._resizableColumns || t.key !== "ArrowLeft" && t.key !== "ArrowRight") return;
2203
2506
  t.preventDefault(), t.stopPropagation();
2204
- const i = t.currentTarget.closest("th"), s = this._columnWidths.get(e.name) ?? i?.getBoundingClientRect().width ?? 100, r = R(
2205
- s,
2206
- t.key === "ArrowRight" ? $ : -$
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
2207
2510
  );
2208
2511
  this._columnWidths = new Map(this._columnWidths), this._columnWidths.set(e.name, r), this.requestUpdate();
2209
2512
  }
2210
2513
  startColumnResize(e, t) {
2211
2514
  if (!this._resizableColumns) return;
2212
2515
  t.preventDefault(), t.stopPropagation();
2213
- const a = t.currentTarget, i = a.closest("th");
2214
- if (!i) return;
2215
- const s = i.getBoundingClientRect().width;
2216
- this.resizeState = { columnName: e.name, startX: t.clientX, startWidth: s, handle: a }, a.classList.add("active"), a.setPointerCapture(t.pointerId), a.addEventListener("pointermove", this.onColumnResizeMove), a.addEventListener("pointerup", this.onColumnResizeEnd), a.addEventListener("pointercancel", this.onColumnResizeEnd);
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);
2217
2520
  }
2218
2521
  }
2219
- function Y(l, e) {
2220
- if (l == null || typeof l != "object") return "";
2221
- const t = l[e.name];
2522
+ function Y(n, e) {
2523
+ if (n == null || typeof n != "object") return "";
2524
+ const t = n[e.name];
2222
2525
  return t == null ? "" : String(t);
2223
2526
  }
2224
- function J(l) {
2225
- return l != null && typeof l != "string" && typeof l[Symbol.iterator] == "function";
2527
+ function J(n) {
2528
+ return n != null && typeof n != "string" && typeof n[Symbol.iterator] == "function";
2226
2529
  }
2227
- function w(l) {
2228
- return l == null || l === !1 ? u : (l instanceof Node || typeof l == "object" && "_$litType$" in l, l);
2530
+ function C(n) {
2531
+ return n == null || n === !1 ? u : (n instanceof Node || typeof n == "object" && "_$litType$" in n, n);
2229
2532
  }
2230
- z("datatable", H);
2533
+ q("datatable", B);
2231
2534
  typeof customElements < "u" && !customElements.get("mp-datatable") && customElements.define("mp-datatable", X);
2232
2535
  export {
2233
2536
  W as D,
2234
2537
  X as M,
2235
- B as c,
2236
- H as d,
2538
+ H as c,
2539
+ B as d,
2237
2540
  y as s
2238
2541
  };