@toolbox-web/grid 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/all.d.ts +29 -6
  2. package/all.js +421 -421
  3. package/all.js.map +1 -1
  4. package/index.d.ts +28 -0
  5. package/index.js +774 -726
  6. package/index.js.map +1 -1
  7. package/lib/plugins/clipboard/index.js +55 -35
  8. package/lib/plugins/clipboard/index.js.map +1 -1
  9. package/lib/plugins/column-virtualization/index.js +49 -29
  10. package/lib/plugins/column-virtualization/index.js.map +1 -1
  11. package/lib/plugins/context-menu/index.js +35 -15
  12. package/lib/plugins/context-menu/index.js.map +1 -1
  13. package/lib/plugins/export/index.js +52 -32
  14. package/lib/plugins/export/index.js.map +1 -1
  15. package/lib/plugins/filtering/index.js +116 -99
  16. package/lib/plugins/filtering/index.js.map +1 -1
  17. package/lib/plugins/grouping-columns/index.js +42 -22
  18. package/lib/plugins/grouping-columns/index.js.map +1 -1
  19. package/lib/plugins/grouping-rows/index.js +20 -0
  20. package/lib/plugins/grouping-rows/index.js.map +1 -1
  21. package/lib/plugins/master-detail/index.js +50 -27
  22. package/lib/plugins/master-detail/index.js.map +1 -1
  23. package/lib/plugins/multi-sort/index.js +25 -5
  24. package/lib/plugins/multi-sort/index.js.map +1 -1
  25. package/lib/plugins/pinned-columns/index.js +20 -0
  26. package/lib/plugins/pinned-columns/index.js.map +1 -1
  27. package/lib/plugins/pinned-rows/index.js +20 -0
  28. package/lib/plugins/pinned-rows/index.js.map +1 -1
  29. package/lib/plugins/pivot/index.js +20 -0
  30. package/lib/plugins/pivot/index.js.map +1 -1
  31. package/lib/plugins/reorder/index.js +48 -28
  32. package/lib/plugins/reorder/index.js.map +1 -1
  33. package/lib/plugins/selection/index.js +51 -31
  34. package/lib/plugins/selection/index.js.map +1 -1
  35. package/lib/plugins/server-side/index.js +20 -0
  36. package/lib/plugins/server-side/index.js.map +1 -1
  37. package/lib/plugins/tree/index.js +76 -53
  38. package/lib/plugins/tree/index.js.map +1 -1
  39. package/lib/plugins/undo-redo/index.js +20 -0
  40. package/lib/plugins/undo-redo/index.js.map +1 -1
  41. package/lib/plugins/visibility/index.js +20 -0
  42. package/lib/plugins/visibility/index.js.map +1 -1
  43. package/package.json +1 -1
  44. package/umd/grid.all.umd.js +25 -25
  45. package/umd/grid.all.umd.js.map +1 -1
  46. package/umd/grid.umd.js +12 -12
  47. package/umd/grid.umd.js.map +1 -1
  48. package/umd/plugins/filtering.umd.js +3 -3
  49. package/umd/plugins/filtering.umd.js.map +1 -1
  50. package/umd/plugins/master-detail.umd.js +2 -2
  51. package/umd/plugins/master-detail.umd.js.map +1 -1
  52. package/umd/plugins/reorder.umd.js +1 -1
  53. package/umd/plugins/reorder.umd.js.map +1 -1
  54. package/umd/plugins/tree.umd.js +2 -2
  55. package/umd/plugins/tree.umd.js.map +1 -1
package/index.js CHANGED
@@ -9,19 +9,19 @@ function be(o) {
9
9
  function ae(o, e) {
10
10
  const t = o._columns, n = be(o);
11
11
  return {
12
- columns: t.map((s, i) => {
12
+ columns: t.map((i, s) => {
13
13
  const l = {
14
- field: s.field,
15
- order: i,
14
+ field: i.field,
15
+ order: s,
16
16
  visible: !0
17
17
  // If it's in _columns, it's visible (hidden columns are filtered out)
18
- }, r = s;
19
- r.__renderedWidth !== void 0 ? l.width = r.__renderedWidth : s.width !== void 0 && (l.width = typeof s.width == "string" ? parseFloat(s.width) : s.width);
20
- const a = n.get(s.field);
18
+ }, r = i;
19
+ r.__renderedWidth !== void 0 ? l.width = r.__renderedWidth : i.width !== void 0 && (l.width = typeof i.width == "string" ? parseFloat(i.width) : i.width);
20
+ const a = n.get(i.field);
21
21
  a && (l.sort = a);
22
22
  for (const f of e)
23
23
  if (f.getColumnState) {
24
- const p = f.getColumnState(s.field);
24
+ const p = f.getColumnState(i.field);
25
25
  p && Object.assign(l, p);
26
26
  }
27
27
  return l;
@@ -30,16 +30,16 @@ function ae(o, e) {
30
30
  }
31
31
  function ge(o, e, t, n) {
32
32
  if (!e.columns || e.columns.length === 0) return;
33
- const s = new Map(e.columns.map((r) => [r.field, r])), i = t.map((r) => {
34
- const a = s.get(r.field);
33
+ const i = new Map(e.columns.map((r) => [r.field, r])), s = t.map((r) => {
34
+ const a = i.get(r.field);
35
35
  if (!a) return r;
36
36
  const f = { ...r };
37
37
  return a.width !== void 0 && (f.width = a.width, f.__renderedWidth = a.width), a.visible !== void 0 && (f.hidden = !a.visible), f;
38
38
  });
39
- i.sort((r, a) => {
40
- const f = s.get(r.field)?.order ?? 1 / 0, p = s.get(a.field)?.order ?? 1 / 0;
39
+ s.sort((r, a) => {
40
+ const f = i.get(r.field)?.order ?? 1 / 0, p = i.get(a.field)?.order ?? 1 / 0;
41
41
  return f - p;
42
- }), o._columns = i;
42
+ }), o._columns = s;
43
43
  const l = e.columns.filter((r) => r.sort !== void 0).sort((r, a) => (r.sort?.priority ?? 0) - (a.sort?.priority ?? 0));
44
44
  if (l.length > 0) {
45
45
  const r = l[0];
@@ -59,12 +59,12 @@ function me(o, e, t) {
59
59
  return () => {
60
60
  n !== null && clearTimeout(n), n = setTimeout(() => {
61
61
  n = null;
62
- const s = ae(o, e());
63
- t(s);
62
+ const i = ae(o, e());
63
+ t(i);
64
64
  }, 100);
65
65
  };
66
66
  }
67
- const O = {
67
+ const M = {
68
68
  STRETCH: "stretch",
69
69
  FIXED: "fixed"
70
70
  };
@@ -73,20 +73,20 @@ function ve(o) {
73
73
  }
74
74
  function ce(o, e) {
75
75
  if (e && e.length) {
76
- const i = {};
76
+ const s = {};
77
77
  return e.forEach((l) => {
78
- l.type && (i[l.field] = l.type);
79
- }), { columns: e, typeMap: i };
80
- }
81
- const t = o[0] || {}, n = Object.keys(t).map((i) => {
82
- const l = t[i], r = ve(l);
83
- return { field: i, header: i.charAt(0).toUpperCase() + i.slice(1), type: r };
84
- }), s = {};
85
- return n.forEach((i) => {
86
- s[i.field] = i.type || "string";
87
- }), { columns: n, typeMap: s };
88
- }
89
- const Ce = /{{\s*([^}]+)\s*}}/g, R = "__DG_EMPTY__", ye = /^[\w$. '?+\-*/%:()!<>=,&|]+$/, Ee = /__(proto|defineGetter|defineSetter)|constructor|window|globalThis|global|process|Function|import|eval|Reflect|Proxy|Error|arguments|document|location|cookie|localStorage|sessionStorage|indexedDB|fetch|XMLHttpRequest|WebSocket|Worker|SharedWorker|ServiceWorker|opener|parent|top|frames|self|this\b/, Re = /* @__PURE__ */ new Set([
78
+ l.type && (s[l.field] = l.type);
79
+ }), { columns: e, typeMap: s };
80
+ }
81
+ const t = o[0] || {}, n = Object.keys(t).map((s) => {
82
+ const l = t[s], r = ve(l);
83
+ return { field: s, header: s.charAt(0).toUpperCase() + s.slice(1), type: r };
84
+ }), i = {};
85
+ return n.forEach((s) => {
86
+ i[s.field] = s.type || "string";
87
+ }), { columns: n, typeMap: i };
88
+ }
89
+ const Ce = /{{\s*([^}]+)\s*}}/g, A = "__DG_EMPTY__", ye = /^[\w$. '?+\-*/%:()!<>=,&|]+$/, Ee = /__(proto|defineGetter|defineSetter)|constructor|window|globalThis|global|process|Function|import|eval|Reflect|Proxy|Error|arguments|document|location|cookie|localStorage|sessionStorage|indexedDB|fetch|XMLHttpRequest|WebSocket|Worker|SharedWorker|ServiceWorker|opener|parent|top|frames|self|this\b/, Re = /* @__PURE__ */ new Set([
90
90
  "script",
91
91
  "iframe",
92
92
  "object",
@@ -112,7 +112,7 @@ const Ce = /{{\s*([^}]+)\s*}}/g, R = "__DG_EMPTY__", ye = /^[\w$. '?+\-*/%:()!<>
112
112
  "xmp",
113
113
  "listing"
114
114
  ]), U = /^on\w+$/i, _e = /* @__PURE__ */ new Set(["href", "src", "action", "formaction", "data", "srcdoc", "xlink:href", "poster", "srcset"]), Ae = /^\s*(javascript|vbscript|data|blob):/i;
115
- function N(o) {
115
+ function z(o) {
116
116
  if (!o || typeof o != "string") return "";
117
117
  if (o.indexOf("<") === -1) return o;
118
118
  const e = document.createElement("template");
@@ -121,34 +121,34 @@ function N(o) {
121
121
  function Se(o) {
122
122
  const e = [], t = o.querySelectorAll("*");
123
123
  for (const n of t) {
124
- const s = n.tagName.toLowerCase();
125
- if (Re.has(s)) {
124
+ const i = n.tagName.toLowerCase();
125
+ if (Re.has(i)) {
126
126
  e.push(n);
127
127
  continue;
128
128
  }
129
- if ((s === "svg" || n.namespaceURI === "http://www.w3.org/2000/svg") && Array.from(n.attributes).some(
129
+ if ((i === "svg" || n.namespaceURI === "http://www.w3.org/2000/svg") && Array.from(n.attributes).some(
130
130
  (r) => U.test(r.name) || r.name === "href" || r.name === "xlink:href"
131
131
  )) {
132
132
  e.push(n);
133
133
  continue;
134
134
  }
135
- const i = [];
135
+ const s = [];
136
136
  for (const l of n.attributes) {
137
137
  const r = l.name.toLowerCase();
138
138
  if (U.test(r)) {
139
- i.push(l.name);
139
+ s.push(l.name);
140
140
  continue;
141
141
  }
142
142
  if (_e.has(r) && Ae.test(l.value)) {
143
- i.push(l.name);
143
+ s.push(l.name);
144
144
  continue;
145
145
  }
146
146
  if (r === "style" && /expression\s*\(|javascript:|behavior\s*:/i.test(l.value)) {
147
- i.push(l.name);
147
+ s.push(l.name);
148
148
  continue;
149
149
  }
150
150
  }
151
- i.forEach((l) => n.removeAttribute(l));
151
+ s.forEach((l) => n.removeAttribute(l));
152
152
  }
153
153
  e.forEach((n) => n.remove());
154
154
  }
@@ -157,28 +157,28 @@ function de(o, e) {
157
157
  const t = [], n = o.replace(Ce, (r, a) => {
158
158
  const f = xe(a, e);
159
159
  return t.push({ expr: a.trim(), result: f }), f;
160
- }), s = Te(n), i = t.length && t.every((r) => r.result === "" || r.result === R);
161
- return /Reflect\.|\bProxy\b|ownKeys\(/.test(o) || i ? "" : s;
160
+ }), i = Te(n), s = t.length && t.every((r) => r.result === "" || r.result === A);
161
+ return /Reflect\.|\bProxy\b|ownKeys\(/.test(o) || s ? "" : i;
162
162
  }
163
163
  function xe(o, e) {
164
- if (o = (o || "").trim(), !o || /\b(Reflect|Proxy|ownKeys)\b/.test(o)) return R;
165
- if (o === "value") return e.value == null ? R : String(e.value);
164
+ if (o = (o || "").trim(), !o || /\b(Reflect|Proxy|ownKeys)\b/.test(o)) return A;
165
+ if (o === "value") return e.value == null ? A : String(e.value);
166
166
  if (o.startsWith("row.") && !/[()?]/.test(o) && !o.includes(":")) {
167
- const n = o.slice(4), s = e.row ? e.row[n] : void 0;
168
- return s == null ? R : String(s);
167
+ const n = o.slice(4), i = e.row ? e.row[n] : void 0;
168
+ return i == null ? A : String(i);
169
169
  }
170
- if (o.length > 80 || !ye.test(o) || Ee.test(o)) return R;
170
+ if (o.length > 80 || !ye.test(o) || Ee.test(o)) return A;
171
171
  const t = o.match(/\./g);
172
- if (t && t.length > 1) return R;
172
+ if (t && t.length > 1) return A;
173
173
  try {
174
- const s = new Function("value", "row", `return (${o});`)(e.value, e.row), i = s == null ? "" : String(s);
175
- return /Reflect|Proxy|ownKeys/.test(i) ? R : i || R;
174
+ const i = new Function("value", "row", `return (${o});`)(e.value, e.row), s = i == null ? "" : String(i);
175
+ return /Reflect|Proxy|ownKeys/.test(s) ? A : s || A;
176
176
  } catch {
177
- return R;
177
+ return A;
178
178
  }
179
179
  }
180
180
  function Te(o) {
181
- return o && o.replace(new RegExp(R, "g"), "").replace(/Reflect\.[^<>{}\s]+/g, "").replace(/\bProxy\b/g, "").replace(/ownKeys\([^)]*\)/g, "");
181
+ return o && o.replace(new RegExp(A, "g"), "").replace(/Reflect\.[^<>{}\s]+/g, "").replace(/\bProxy\b/g, "").replace(/ownKeys\([^)]*\)/g, "");
182
182
  }
183
183
  function Le(o) {
184
184
  if (/Reflect|Proxy|ownKeys/.test(o.textContent || "")) {
@@ -200,15 +200,15 @@ function ke(o) {
200
200
  return Array.from(o.querySelectorAll("tbw-grid-column")).map((t) => {
201
201
  const n = t.getAttribute("field") || "";
202
202
  if (!n) return null;
203
- const s = t.getAttribute("type") || void 0, l = s && (/* @__PURE__ */ new Set(["number", "string", "date", "boolean", "select", "typeahead"])).has(s) ? s : void 0, r = t.getAttribute("header") || void 0, a = t.hasAttribute("sortable"), f = t.hasAttribute("editable"), p = { field: n, type: l, header: r, sortable: a, editable: f };
203
+ const i = t.getAttribute("type") || void 0, l = i && (/* @__PURE__ */ new Set(["number", "string", "date", "boolean", "select", "typeahead"])).has(i) ? i : void 0, r = t.getAttribute("header") || void 0, a = t.hasAttribute("sortable"), f = t.hasAttribute("editable"), p = { field: n, type: l, header: r, sortable: a, editable: f };
204
204
  t.hasAttribute("resizable") && (p.resizable = !0), t.hasAttribute("sizable") && (p.resizable = !0);
205
205
  const w = t.getAttribute("options");
206
- w && (p.options = w.split(",").map((u) => {
207
- const [b, y] = u.includes(":") ? u.split(":") : [u.trim(), u.trim()];
208
- return { value: b.trim(), label: y?.trim() || b.trim() };
206
+ w && (p.options = w.split(",").map((d) => {
207
+ const [g, m] = d.includes(":") ? d.split(":") : [d.trim(), d.trim()];
208
+ return { value: g.trim(), label: m?.trim() || g.trim() };
209
209
  }));
210
- const h = t.querySelector("tbw-grid-column-view"), c = t.querySelector("tbw-grid-column-editor"), d = t.querySelector("tbw-grid-column-header");
211
- return h && (p.__viewTemplate = h), c && (p.__editorTemplate = c), d && (p.__headerTemplate = d), p;
210
+ const u = t.querySelector("tbw-grid-column-view"), c = t.querySelector("tbw-grid-column-editor"), h = t.querySelector("tbw-grid-column-header");
211
+ return u && (p.__viewTemplate = u), c && (p.__editorTemplate = c), h && (p.__headerTemplate = h), p;
212
212
  }).filter((t) => !!t);
213
213
  }
214
214
  function Pe(o, e) {
@@ -216,14 +216,14 @@ function Pe(o, e) {
216
216
  if (!o || !o.length) return e || [];
217
217
  if (!e || !e.length) return o;
218
218
  const t = {};
219
- e.forEach((s) => t[s.field] = s);
220
- const n = o.map((s) => {
221
- const i = t[s.field];
222
- if (!i) return s;
223
- const l = { ...s };
224
- return i.header && !l.header && (l.header = i.header), i.type && !l.type && (l.type = i.type), l.sortable = s.sortable || i.sortable, (s.resizable === !0 || i.resizable === !0) && (l.resizable = !0), l.editable = s.editable || i.editable, i.__viewTemplate && (l.__viewTemplate = i.__viewTemplate), i.__editorTemplate && (l.__editorTemplate = i.__editorTemplate), i.__headerTemplate && (l.__headerTemplate = i.__headerTemplate), delete t[s.field], l;
219
+ e.forEach((i) => t[i.field] = i);
220
+ const n = o.map((i) => {
221
+ const s = t[i.field];
222
+ if (!s) return i;
223
+ const l = { ...i };
224
+ return s.header && !l.header && (l.header = s.header), s.type && !l.type && (l.type = s.type), l.sortable = i.sortable || s.sortable, (i.resizable === !0 || s.resizable === !0) && (l.resizable = !0), l.editable = i.editable || s.editable, s.__viewTemplate && (l.__viewTemplate = s.__viewTemplate), s.__editorTemplate && (l.__editorTemplate = s.__editorTemplate), s.__headerTemplate && (l.__headerTemplate = s.__headerTemplate), delete t[i.field], l;
225
225
  });
226
- return Object.keys(t).forEach((s) => n.push(t[s])), n;
226
+ return Object.keys(t).forEach((i) => n.push(t[i])), n;
227
227
  }
228
228
  function B(o, e) {
229
229
  try {
@@ -233,39 +233,39 @@ function B(o, e) {
233
233
  const t = o.getAttribute("part");
234
234
  t ? t.split(/\s+/).includes(e) || o.setAttribute("part", t + " " + e) : o.setAttribute("part", e);
235
235
  }
236
- function Oe(o) {
236
+ function Me(o) {
237
237
  o.__lightDomColumnsCache || (o.__originalColumnNodes = Array.from(
238
238
  o.querySelectorAll("tbw-grid-column")
239
239
  ), o.__lightDomColumnsCache = o.__originalColumnNodes.length ? ke(o) : []);
240
240
  const e = o.__lightDomColumnsCache, t = Pe(o._columns, e);
241
- t.forEach((s) => {
242
- s.__viewTemplate && !s.__compiledView && (s.__compiledView = X(s.__viewTemplate.innerHTML)), s.__editorTemplate && !s.__compiledEditor && (s.__compiledEditor = X(s.__editorTemplate.innerHTML));
241
+ t.forEach((i) => {
242
+ i.__viewTemplate && !i.__compiledView && (i.__compiledView = X(i.__viewTemplate.innerHTML)), i.__editorTemplate && !i.__compiledEditor && (i.__compiledEditor = X(i.__editorTemplate.innerHTML));
243
243
  });
244
244
  const { columns: n } = ce(o._rows, t);
245
245
  o._columns = n;
246
246
  }
247
- function Me(o) {
248
- const e = o.effectiveConfig?.fitMode || o.fitMode || O.STRETCH;
249
- if (e !== O.STRETCH && e !== O.FIXED || o.__didInitialAutoSize || !o.isConnected) return;
247
+ function Oe(o) {
248
+ const e = o.effectiveConfig?.fitMode || o.fitMode || M.STRETCH;
249
+ if (e !== M.STRETCH && e !== M.FIXED || o.__didInitialAutoSize || !o.isConnected) return;
250
250
  const t = o.headerRowEl?.children || [];
251
251
  if (!t.length) return;
252
252
  let n = !1;
253
- o.visibleColumns.forEach((s, i) => {
254
- if (s.width) return;
255
- const l = t[i];
253
+ o.visibleColumns.forEach((i, s) => {
254
+ if (i.width) return;
255
+ const l = t[s];
256
256
  let r = l ? l.scrollWidth : 0;
257
257
  for (const a of o.rowPool) {
258
- const f = a.children[i];
258
+ const f = a.children[s];
259
259
  if (f) {
260
260
  const p = f.scrollWidth;
261
261
  p > r && (r = p);
262
262
  }
263
263
  }
264
- r > 0 && (s.width = r + 2, s.__autoSized = !0, n = !0);
264
+ r > 0 && (i.width = r + 2, i.__autoSized = !0, n = !0);
265
265
  }), n && he(o), o.__didInitialAutoSize = !0;
266
266
  }
267
267
  function he(o) {
268
- (o.effectiveConfig?.fitMode || o.fitMode || O.STRETCH) === O.STRETCH ? o.gridTemplate = o.visibleColumns.map((t) => {
268
+ (o.effectiveConfig?.fitMode || o.fitMode || M.STRETCH) === M.STRETCH ? o.gridTemplate = o.visibleColumns.map((t) => {
269
269
  if (t.width) return `${t.width}px`;
270
270
  const n = t.minWidth;
271
271
  return n != null ? `minmax(${n}px, 1fr)` : "1fr";
@@ -296,21 +296,21 @@ function De(o) {
296
296
  case "typeahead":
297
297
  return (e) => {
298
298
  const t = document.createElement("select");
299
- e.column.multi && (t.multiple = !0), (typeof e.column.options == "function" ? e.column.options() : e.column.options || []).forEach((i) => {
299
+ e.column.multi && (t.multiple = !0), (typeof e.column.options == "function" ? e.column.options() : e.column.options || []).forEach((s) => {
300
300
  const l = document.createElement("option");
301
- l.value = String(i.value), l.textContent = i.label, (e.column.multi && Array.isArray(e.value) && e.value.includes(i.value) || !e.column.multi && e.value === i.value) && (l.selected = !0), t.appendChild(l);
301
+ l.value = String(s.value), l.textContent = s.label, (e.column.multi && Array.isArray(e.value) && e.value.includes(s.value) || !e.column.multi && e.value === s.value) && (l.selected = !0), t.appendChild(l);
302
302
  });
303
- const s = () => {
303
+ const i = () => {
304
304
  if (e.column.multi) {
305
- const i = [];
305
+ const s = [];
306
306
  Array.from(t.selectedOptions).forEach((l) => {
307
- i.push(l.value);
308
- }), e.commit(i);
307
+ s.push(l.value);
308
+ }), e.commit(s);
309
309
  } else
310
310
  e.commit(t.value);
311
311
  };
312
- return t.addEventListener("change", s), t.addEventListener("blur", s), t.addEventListener("keydown", (i) => {
313
- i.key === "Escape" && e.cancel();
312
+ return t.addEventListener("change", i), t.addEventListener("blur", i), t.addEventListener("keydown", (s) => {
313
+ s.key === "Escape" && e.cancel();
314
314
  }), t.focus(), t;
315
315
  };
316
316
  default:
@@ -325,22 +325,22 @@ function De(o) {
325
325
  function He(o, e) {
326
326
  if (o.dispatchKeyDown?.(e))
327
327
  return;
328
- const t = o._rows.length - 1, n = o.visibleColumns.length - 1, s = o.activeEditRows !== void 0 && o.activeEditRows !== -1, l = o.visibleColumns[o.focusCol]?.type, r = e.composedPath ? e.composedPath() : [], a = r && r.length ? r[0] : e.target, f = (p) => {
328
+ const t = o._rows.length - 1, n = o.visibleColumns.length - 1, i = o.activeEditRows !== void 0 && o.activeEditRows !== -1, l = o.visibleColumns[o.focusCol]?.type, r = e.composedPath ? e.composedPath() : [], a = r && r.length ? r[0] : e.target, f = (p) => {
329
329
  if (!p) return !1;
330
330
  const w = p.tagName;
331
331
  return !!(w === "INPUT" || w === "SELECT" || w === "TEXTAREA" || p.isContentEditable);
332
332
  };
333
- if (!(f(a) && (e.key === "Home" || e.key === "End")) && !(f(a) && (e.key === "ArrowUp" || e.key === "ArrowDown") && a.tagName === "INPUT" && a.type === "number") && !(s && (l === "select" || l === "typeahead") && (e.key === "ArrowDown" || e.key === "ArrowUp"))) {
333
+ if (!(f(a) && (e.key === "Home" || e.key === "End")) && !(f(a) && (e.key === "ArrowUp" || e.key === "ArrowDown") && a.tagName === "INPUT" && a.type === "number") && !(i && (l === "select" || l === "typeahead") && (e.key === "ArrowDown" || e.key === "ArrowUp"))) {
334
334
  switch (e.key) {
335
335
  case "Tab": {
336
- e.preventDefault(), !e.shiftKey ? o.focusCol < n ? o.focusCol += 1 : (typeof o.commitActiveRowEdit == "function" && o.commitActiveRowEdit(), o.focusRow < t && (o.focusRow += 1, o.focusCol = 0)) : o.focusCol > 0 ? o.focusCol -= 1 : o.focusRow > 0 && (typeof o.commitActiveRowEdit == "function" && o.activeEditRows === o.focusRow && o.commitActiveRowEdit(), o.focusRow -= 1, o.focusCol = n), M(o);
336
+ e.preventDefault(), !e.shiftKey ? o.focusCol < n ? o.focusCol += 1 : (typeof o.commitActiveRowEdit == "function" && o.commitActiveRowEdit(), o.focusRow < t && (o.focusRow += 1, o.focusCol = 0)) : o.focusCol > 0 ? o.focusCol -= 1 : o.focusRow > 0 && (typeof o.commitActiveRowEdit == "function" && o.activeEditRows === o.focusRow && o.commitActiveRowEdit(), o.focusRow -= 1, o.focusCol = n), O(o);
337
337
  return;
338
338
  }
339
339
  case "ArrowDown":
340
- s && typeof o.commitActiveRowEdit == "function" && o.commitActiveRowEdit(), o.focusRow = Math.min(t, o.focusRow + 1), e.preventDefault();
340
+ i && typeof o.commitActiveRowEdit == "function" && o.commitActiveRowEdit(), o.focusRow = Math.min(t, o.focusRow + 1), e.preventDefault();
341
341
  break;
342
342
  case "ArrowUp":
343
- s && typeof o.commitActiveRowEdit == "function" && o.commitActiveRowEdit(), o.focusRow = Math.max(0, o.focusRow - 1), e.preventDefault();
343
+ i && typeof o.commitActiveRowEdit == "function" && o.commitActiveRowEdit(), o.focusRow = Math.max(0, o.focusRow - 1), e.preventDefault();
344
344
  break;
345
345
  case "ArrowRight":
346
346
  o.focusCol = Math.min(n, o.focusCol + 1), e.preventDefault();
@@ -363,27 +363,27 @@ function He(o, e) {
363
363
  case "Enter":
364
364
  return typeof o.beginBulkEdit == "function" ? o.beginBulkEdit(o.focusRow) : o.dispatchEvent(
365
365
  new CustomEvent("activate-cell", { detail: { row: o.focusRow, col: o.focusCol } })
366
- ), M(o);
366
+ ), O(o);
367
367
  default:
368
368
  return;
369
369
  }
370
- M(o);
370
+ O(o);
371
371
  }
372
372
  }
373
- function M(o) {
373
+ function O(o) {
374
374
  if (o.virtualization?.enabled) {
375
- const { rowHeight: s } = o.virtualization, i = o, l = o.focusRow * s;
376
- l < i.scrollTop ? i.scrollTop = l : l + s > i.scrollTop + i.clientHeight && (i.scrollTop = l - i.clientHeight + s);
375
+ const { rowHeight: i } = o.virtualization, s = o, l = o.focusRow * i;
376
+ l < s.scrollTop ? s.scrollTop = l : l + i > s.scrollTop + s.clientHeight && (s.scrollTop = l - s.clientHeight + i);
377
377
  }
378
- o.refreshVirtualWindow(!1), Array.from(o.bodyEl.querySelectorAll(".cell-focus")).forEach((s) => s.classList.remove("cell-focus")), Array.from(o.bodyEl.querySelectorAll('[aria-selected="true"]')).forEach((s) => {
379
- s.setAttribute("aria-selected", "false");
378
+ o.refreshVirtualWindow(!1), Array.from(o.bodyEl.querySelectorAll(".cell-focus")).forEach((i) => i.classList.remove("cell-focus")), Array.from(o.bodyEl.querySelectorAll('[aria-selected="true"]')).forEach((i) => {
379
+ i.setAttribute("aria-selected", "false");
380
380
  });
381
381
  const e = o.focusRow, t = o.virtualization.start ?? 0, n = o.virtualization.end ?? o._rows.length;
382
382
  if (e >= t && e < n) {
383
- const i = o.bodyEl.querySelectorAll(".data-grid-row")[e - t]?.children[o.focusCol];
384
- if (i) {
385
- if (i.classList.add("cell-focus"), i.setAttribute("aria-selected", "true"), o.activeEditRows !== void 0 && o.activeEditRows !== -1 && i.classList.contains("editing")) {
386
- const l = i.querySelector(
383
+ const s = o.bodyEl.querySelectorAll(".data-grid-row")[e - t]?.children[o.focusCol];
384
+ if (s) {
385
+ if (s.classList.add("cell-focus"), s.setAttribute("aria-selected", "true"), o.activeEditRows !== void 0 && o.activeEditRows !== -1 && s.classList.contains("editing")) {
386
+ const l = s.querySelector(
387
387
  'input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])'
388
388
  );
389
389
  if (l && document.activeElement !== l)
@@ -391,10 +391,10 @@ function M(o) {
391
391
  l.focus();
392
392
  } catch {
393
393
  }
394
- } else if (!i.contains(document.activeElement)) {
395
- i.hasAttribute("tabindex") || i.setAttribute("tabindex", "-1");
394
+ } else if (!s.contains(document.activeElement)) {
395
+ s.hasAttribute("tabindex") || s.setAttribute("tabindex", "-1");
396
396
  try {
397
- i.focus({ preventScroll: !0 });
397
+ s.focus({ preventScroll: !0 });
398
398
  } catch {
399
399
  }
400
400
  }
@@ -405,125 +405,131 @@ const ze = "__cellDisplayCache", Ne = "__cellCacheEpoch";
405
405
  function j(o) {
406
406
  o[ze] = void 0, o[Ne] = void 0, o.__hasSpecialColumns = void 0;
407
407
  }
408
- function qe(o, e, t, n, s) {
409
- const i = Math.max(0, t - e), l = o.bodyEl, r = o.visibleColumns, a = r.length;
408
+ function qe(o, e, t, n, i) {
409
+ const s = Math.max(0, t - e), l = o.bodyEl, r = o.visibleColumns, a = r.length;
410
410
  let f = o.__cachedHeaderRowCount;
411
- for (f === void 0 && (f = o.shadowRoot?.querySelector(".header-group-row") ? 2 : 1, o.__cachedHeaderRowCount = f); o.rowPool.length < i; ) {
411
+ for (f === void 0 && (f = o.shadowRoot?.querySelector(".header-group-row") ? 2 : 1, o.__cachedHeaderRowCount = f); o.rowPool.length < s; ) {
412
412
  const w = document.createElement("div");
413
- w.className = "data-grid-row", w.setAttribute("role", "row"), w.addEventListener("click", (h) => Z(o, h, w, !1)), w.addEventListener("dblclick", (h) => Z(o, h, w, !0)), o.rowPool.push(w);
413
+ w.className = "data-grid-row", w.setAttribute("role", "row"), w.addEventListener("click", (u) => Z(o, u, w, !1)), w.addEventListener("dblclick", (u) => Z(o, u, w, !0)), o.rowPool.push(w);
414
414
  }
415
- if (o.rowPool.length > i) {
416
- for (let w = i; w < o.rowPool.length; w++) {
417
- const h = o.rowPool[w];
418
- h.parentNode === l && h.remove();
415
+ if (o.rowPool.length > s) {
416
+ for (let w = s; w < o.rowPool.length; w++) {
417
+ const u = o.rowPool[w];
418
+ u.parentNode === l && u.remove();
419
419
  }
420
- o.rowPool.length = i;
420
+ o.rowPool.length = s;
421
421
  }
422
- const p = s && o.__hasRenderRowPlugins !== !1;
423
- for (let w = 0; w < i; w++) {
424
- const h = e + w, c = o._rows[h], d = o.rowPool[w];
425
- if (d.setAttribute("aria-rowindex", String(h + f + 1)), p && s(c, d, h)) {
426
- d.__epoch = n, d.__rowDataRef = c, d.parentNode !== l && l.appendChild(d);
422
+ const p = i && o.__hasRenderRowPlugins !== !1;
423
+ for (let w = 0; w < s; w++) {
424
+ const u = e + w, c = o._rows[u], h = o.rowPool[w];
425
+ if (h.setAttribute("aria-rowindex", String(u + f + 1)), p && i(c, h, u)) {
426
+ h.__epoch = n, h.__rowDataRef = c, h.parentNode !== l && l.appendChild(h);
427
427
  continue;
428
428
  }
429
- const u = d.__epoch, b = d.__rowDataRef, y = d.children.length, E = u === n && y === a, _ = b !== c;
430
- let x = !1;
431
- if (E && _) {
432
- for (let A = 0; A < a; A++)
433
- if (r[A].externalView && !d.querySelector(`.cell[data-col="${A}"] [data-external-view]`)) {
434
- x = !0;
429
+ const d = h.__epoch, g = h.__rowDataRef, m = h.children.length, R = d === n && m === a, E = g !== c;
430
+ let _ = !1;
431
+ if (R && E) {
432
+ for (let S = 0; S < a; S++)
433
+ if (r[S].externalView && !h.querySelector(`.cell[data-col="${S}"] [data-external-view]`)) {
434
+ _ = !0;
435
435
  break;
436
436
  }
437
437
  }
438
- !E || x ? (d.__isCustomRow && (d.className = "data-grid-row", d.setAttribute("role", "row"), d.__isCustomRow = !1), F(o, d, c, h), d.__epoch = n, d.__rowDataRef = c) : _ ? (Y(o, d, c, h), d.__rowDataRef = c) : Y(o, d, c, h);
439
- const g = o._changedRowIndices.has(h), m = d.classList.contains("changed");
440
- g !== m && d.classList.toggle("changed", g), d.parentNode !== l && l.appendChild(d);
438
+ !R || _ ? (h.__isCustomRow && (h.className = "data-grid-row", h.setAttribute("role", "row"), h.__isCustomRow = !1), F(o, h, c, u), h.__epoch = n, h.__rowDataRef = c) : E ? (Y(o, h, c, u), h.__rowDataRef = c) : Y(o, h, c, u);
439
+ const b = o._changedRowIndices.has(u), v = h.classList.contains("changed");
440
+ b !== v && h.classList.toggle("changed", b), h.parentNode !== l && l.appendChild(h);
441
441
  }
442
442
  }
443
443
  function Y(o, e, t, n) {
444
- const s = e.children, i = o.visibleColumns, l = i.length, r = s.length, a = l < r ? l : r, f = o.focusRow, p = o.focusCol;
444
+ const i = e.children, s = o.visibleColumns, l = s.length, r = i.length, a = l < r ? l : r, f = o.focusRow, p = o.focusCol;
445
445
  let w = o.__hasSpecialColumns;
446
446
  if (w === void 0) {
447
447
  w = !1;
448
448
  for (let c = 0; c < l; c++) {
449
- const d = i[c];
450
- if (d.__viewTemplate || d.__compiledView || d.viewRenderer || d.externalView || d.format || d.type === "date" || d.type === "boolean") {
449
+ const h = s[c];
450
+ if (h.__viewTemplate || h.__compiledView || h.viewRenderer || h.externalView || h.format || h.type === "date" || h.type === "boolean") {
451
451
  w = !0;
452
452
  break;
453
453
  }
454
454
  }
455
455
  o.__hasSpecialColumns = w;
456
456
  }
457
- const h = String(n);
457
+ const u = String(n);
458
458
  if (!w) {
459
459
  for (let c = 0; c < a; c++) {
460
- const d = s[c], u = t[i[c].field];
461
- d.textContent = u == null ? "" : String(u), d.getAttribute("data-row") !== h && d.setAttribute("data-row", h);
462
- const b = f === n && p === c, y = d.classList.contains("cell-focus");
463
- b !== y && (d.classList.toggle("cell-focus", b), d.setAttribute("aria-selected", String(b)));
460
+ const h = i[c], d = t[s[c].field];
461
+ h.textContent = d == null ? "" : String(d), h.getAttribute("data-row") !== u && h.setAttribute("data-row", u);
462
+ const g = f === n && p === c, m = h.classList.contains("cell-focus");
463
+ g !== m && (h.classList.toggle("cell-focus", g), h.setAttribute("aria-selected", String(g)));
464
464
  }
465
465
  return;
466
466
  }
467
467
  for (let c = 0; c < a; c++)
468
- if (i[c].externalView && !s[c].querySelector("[data-external-view]")) {
468
+ if (s[c].externalView && !i[c].querySelector("[data-external-view]")) {
469
469
  F(o, e, t, n);
470
470
  return;
471
471
  }
472
472
  for (let c = 0; c < a; c++) {
473
- const d = i[c], u = s[c];
474
- u.getAttribute("data-row") !== h && u.setAttribute("data-row", h);
475
- const b = f === n && p === c, y = u.classList.contains("cell-focus");
476
- if (b !== y && (u.classList.toggle("cell-focus", b), u.setAttribute("aria-selected", String(b))), u.classList.contains("editing") || d.__viewTemplate || d.__compiledView || d.viewRenderer || d.externalView)
473
+ const h = s[c], d = i[c];
474
+ d.getAttribute("data-row") !== u && d.setAttribute("data-row", u);
475
+ const g = f === n && p === c, m = d.classList.contains("cell-focus");
476
+ if (g !== m && (d.classList.toggle("cell-focus", g), d.setAttribute("aria-selected", String(g))), d.classList.contains("editing")) continue;
477
+ if (h.viewRenderer) {
478
+ const E = t[h.field], _ = h.viewRenderer({ row: t, value: E, field: h.field, column: h });
479
+ typeof _ == "string" ? d.innerHTML = z(_) : _ ? (d.innerHTML = "", d.appendChild(_)) : d.textContent = E == null ? "" : String(E);
480
+ continue;
481
+ }
482
+ if (h.__viewTemplate || h.__compiledView || h.externalView)
477
483
  continue;
478
- const v = t[d.field];
479
- let E;
480
- if (d.format)
484
+ const C = t[h.field];
485
+ let R;
486
+ if (h.format)
481
487
  try {
482
- const _ = d.format(v, t);
483
- E = _ == null ? "" : String(_);
488
+ const E = h.format(C, t);
489
+ R = E == null ? "" : String(E);
484
490
  } catch {
485
- E = v == null ? "" : String(v);
491
+ R = C == null ? "" : String(C);
486
492
  }
487
- else if (d.type === "date")
488
- if (v == null || v === "")
489
- E = "";
490
- else if (v instanceof Date)
491
- E = isNaN(v.getTime()) ? "" : v.toLocaleDateString();
493
+ else if (h.type === "date")
494
+ if (C == null || C === "")
495
+ R = "";
496
+ else if (C instanceof Date)
497
+ R = isNaN(C.getTime()) ? "" : C.toLocaleDateString();
492
498
  else {
493
- const _ = new Date(v);
494
- E = isNaN(_.getTime()) ? "" : _.toLocaleDateString();
499
+ const E = new Date(C);
500
+ R = isNaN(E.getTime()) ? "" : E.toLocaleDateString();
495
501
  }
496
- else d.type === "boolean" ? (E = v ? "🗹" : "☐", u.setAttribute("aria-checked", String(!!v))) : E = v == null ? "" : String(v);
497
- u.textContent = E;
502
+ else h.type === "boolean" ? (R = C ? "🗹" : "☐", d.setAttribute("aria-checked", String(!!C))) : R = C == null ? "" : String(C);
503
+ d.textContent = R;
498
504
  }
499
505
  }
500
506
  function F(o, e, t, n) {
501
507
  e.innerHTML = "";
502
- const s = o.visibleColumns, i = s.length, l = o.focusRow, r = o.focusCol, a = o.effectiveConfig?.editOn || o.editOn, f = o, p = document.createDocumentFragment();
503
- for (let w = 0; w < i; w++) {
504
- const h = s[w], c = document.createElement("div");
505
- c.className = "cell", B(c, "cell"), h.type !== "boolean" && c.setAttribute("role", "gridcell"), c.setAttribute("data-col", String(w)), c.setAttribute("data-row", String(n)), c.setAttribute("aria-colindex", String(w + 1)), h.type && c.setAttribute("data-type", h.type);
506
- const d = h.sticky;
507
- d === "left" ? c.classList.add("sticky-left") : d === "right" && c.classList.add("sticky-right");
508
- let u = t[h.field];
509
- const b = h.format;
510
- if (b)
508
+ const i = o.visibleColumns, s = i.length, l = o.focusRow, r = o.focusCol, a = o.effectiveConfig?.editOn || o.editOn, f = o, p = document.createDocumentFragment();
509
+ for (let w = 0; w < s; w++) {
510
+ const u = i[w], c = document.createElement("div");
511
+ c.className = "cell", B(c, "cell"), u.type !== "boolean" && c.setAttribute("role", "gridcell"), c.setAttribute("data-col", String(w)), c.setAttribute("data-row", String(n)), c.setAttribute("aria-colindex", String(w + 1)), u.type && c.setAttribute("data-type", u.type);
512
+ const h = u.sticky;
513
+ h === "left" ? c.classList.add("sticky-left") : h === "right" && c.classList.add("sticky-right");
514
+ let d = t[u.field];
515
+ const g = u.format;
516
+ if (g)
511
517
  try {
512
- u = b(u, t);
518
+ d = g(d, t);
513
519
  } catch {
514
520
  }
515
- const y = h.__compiledView, v = h.__viewTemplate, E = h.viewRenderer, _ = h.externalView;
516
- let x = !1;
517
- if (E) {
518
- const g = E({ row: t, value: u, field: h.field, column: h });
519
- typeof g == "string" ? (c.innerHTML = N(g), x = !0) : g ? c.appendChild(g) : c.textContent = u == null ? "" : String(u);
520
- } else if (_) {
521
- const g = _, m = document.createElement("div");
522
- m.setAttribute("data-external-view", ""), m.setAttribute("data-field", h.field), c.appendChild(m);
523
- const A = { row: t, value: u, field: h.field, column: h };
524
- if (g.mount)
521
+ const m = u.__compiledView, C = u.__viewTemplate, R = u.viewRenderer, E = u.externalView;
522
+ let _ = !1;
523
+ if (R) {
524
+ const b = R({ row: t, value: d, field: u.field, column: u });
525
+ typeof b == "string" ? (c.innerHTML = z(b), _ = !0) : b ? c.appendChild(b) : c.textContent = d == null ? "" : String(d);
526
+ } else if (E) {
527
+ const b = E, v = document.createElement("div");
528
+ v.setAttribute("data-external-view", ""), v.setAttribute("data-field", u.field), c.appendChild(v);
529
+ const S = { row: t, value: d, field: u.field, column: u };
530
+ if (b.mount)
525
531
  try {
526
- g.mount({ placeholder: m, context: A, spec: g });
532
+ b.mount({ placeholder: v, context: S, spec: b });
527
533
  } catch {
528
534
  }
529
535
  else
@@ -533,86 +539,86 @@ function F(o, e, t, n) {
533
539
  new CustomEvent("mount-external-view", {
534
540
  bubbles: !0,
535
541
  composed: !0,
536
- detail: { placeholder: m, spec: g, context: A }
542
+ detail: { placeholder: v, spec: b, context: S }
537
543
  })
538
544
  );
539
545
  } catch {
540
546
  }
541
547
  });
542
- m.setAttribute("data-mounted", "");
543
- } else if (y) {
544
- const g = y({ row: t, value: u, field: h.field, column: h }), m = y.__blocked;
545
- c.innerHTML = m ? "" : N(g), x = !0, m && (c.textContent = "", c.setAttribute("data-blocked-template", ""));
546
- } else if (v) {
547
- const g = v.innerHTML;
548
- /Reflect\.|\bProxy\b|ownKeys\(/.test(g) ? (c.textContent = "", c.setAttribute("data-blocked-template", "")) : (c.innerHTML = N(de(g, { row: t, value: u })), x = !0);
549
- } else if (h.type === "date")
550
- if (u == null || u === "")
548
+ v.setAttribute("data-mounted", "");
549
+ } else if (m) {
550
+ const b = m({ row: t, value: d, field: u.field, column: u }), v = m.__blocked;
551
+ c.innerHTML = v ? "" : z(b), _ = !0, v && (c.textContent = "", c.setAttribute("data-blocked-template", ""));
552
+ } else if (C) {
553
+ const b = C.innerHTML;
554
+ /Reflect\.|\bProxy\b|ownKeys\(/.test(b) ? (c.textContent = "", c.setAttribute("data-blocked-template", "")) : (c.innerHTML = z(de(b, { row: t, value: d })), _ = !0);
555
+ } else if (u.type === "date")
556
+ if (d == null || d === "")
551
557
  c.textContent = "";
552
558
  else {
553
- let g = null;
554
- if (u instanceof Date) g = u;
555
- else if (typeof u == "number" || typeof u == "string") {
556
- const m = new Date(u);
557
- isNaN(m.getTime()) || (g = m);
559
+ let b = null;
560
+ if (d instanceof Date) b = d;
561
+ else if (typeof d == "number" || typeof d == "string") {
562
+ const v = new Date(d);
563
+ isNaN(v.getTime()) || (b = v);
558
564
  }
559
- c.textContent = g ? g.toLocaleDateString() : "";
565
+ c.textContent = b ? b.toLocaleDateString() : "";
560
566
  }
561
- else if (h.type === "boolean") {
562
- const g = !!u;
563
- c.innerHTML = g ? "&#x1F5F9;" : "&#9744;", c.setAttribute("role", "checkbox"), c.setAttribute("aria-checked", String(g)), c.setAttribute("aria-label", String(g));
567
+ else if (u.type === "boolean") {
568
+ const b = !!d;
569
+ c.innerHTML = b ? "&#x1F5F9;" : "&#9744;", c.setAttribute("role", "checkbox"), c.setAttribute("aria-checked", String(b)), c.setAttribute("aria-label", String(b));
564
570
  } else
565
- c.textContent = u == null ? "" : String(u);
566
- if (x) {
571
+ c.textContent = d == null ? "" : String(d);
572
+ if (_) {
567
573
  Le(c);
568
- const g = c.textContent || "";
569
- /Proxy|Reflect\.ownKeys/.test(g) && (c.textContent = g.replace(/Proxy|Reflect\.ownKeys/g, "").trim(), /Proxy|Reflect\.ownKeys/.test(c.textContent || "") && (c.textContent = ""));
570
- }
571
- c.hasAttribute("data-blocked-template") && (c.textContent || "").trim().length && (c.textContent = ""), h.editable ? (c.tabIndex = 0, c.addEventListener("mousedown", () => {
572
- o.focusRow = n, o.focusCol = w, M(o);
573
- }), a === "click" ? c.addEventListener("click", (g) => {
574
- c.classList.contains("editing") || (g.stopPropagation(), o.focusRow = n, o.focusCol = w, L(o, t, n, h, c));
575
- }) : c.addEventListener("dblclick", (g) => {
576
- g.stopPropagation(), T(o, n, t);
577
- const m = o.findRenderedRowElement?.(n);
578
- if (m) {
579
- const A = m.children;
580
- for (let k = 0; k < A.length; k++) {
574
+ const b = c.textContent || "";
575
+ /Proxy|Reflect\.ownKeys/.test(b) && (c.textContent = b.replace(/Proxy|Reflect\.ownKeys/g, "").trim(), /Proxy|Reflect\.ownKeys/.test(c.textContent || "") && (c.textContent = ""));
576
+ }
577
+ c.hasAttribute("data-blocked-template") && (c.textContent || "").trim().length && (c.textContent = ""), u.editable ? (c.tabIndex = 0, c.addEventListener("mousedown", () => {
578
+ o.focusRow = n, o.focusCol = w, O(o);
579
+ }), a === "click" ? c.addEventListener("click", (b) => {
580
+ c.classList.contains("editing") || (b.stopPropagation(), o.focusRow = n, o.focusCol = w, L(o, t, n, u, c));
581
+ }) : c.addEventListener("dblclick", (b) => {
582
+ b.stopPropagation(), T(o, n, t);
583
+ const v = o.findRenderedRowElement?.(n);
584
+ if (v) {
585
+ const S = v.children;
586
+ for (let k = 0; k < S.length; k++) {
581
587
  const D = o.visibleColumns[k];
582
- D && D.editable && L(o, t, n, D, A[k]);
588
+ D && D.editable && L(o, t, n, D, S[k]);
583
589
  }
584
590
  }
585
- }), c.addEventListener("keydown", (g) => {
586
- if ((h.type === "select" || h.type === "typeahead") && !c.classList.contains("editing") && g.key === "Enter") {
587
- g.preventDefault(), o.activeEditRows !== n && T(o, n, t), L(o, t, n, h, c), setTimeout(() => {
588
- const m = c.querySelector("select");
591
+ }), c.addEventListener("keydown", (b) => {
592
+ if ((u.type === "select" || u.type === "typeahead") && !c.classList.contains("editing") && b.key === "Enter") {
593
+ b.preventDefault(), o.activeEditRows !== n && T(o, n, t), L(o, t, n, u, c), setTimeout(() => {
594
+ const v = c.querySelector("select");
589
595
  try {
590
- m?.showPicker?.();
596
+ v?.showPicker?.();
591
597
  } catch {
592
598
  }
593
- m?.focus();
599
+ v?.focus();
594
600
  }, 0);
595
601
  return;
596
602
  }
597
- if (h.type === "boolean" && g.key === " " && !c.classList.contains("editing")) {
598
- g.preventDefault(), o.activeEditRows !== n && T(o, n, t);
599
- const m = !t[h.field];
600
- $(o, n, h, m, t), c.innerHTML = m ? "&#x1F5F9;" : "&#9744;", c.setAttribute("aria-label", String(!!m));
603
+ if (u.type === "boolean" && b.key === " " && !c.classList.contains("editing")) {
604
+ b.preventDefault(), o.activeEditRows !== n && T(o, n, t);
605
+ const v = !t[u.field];
606
+ $(o, n, u, v, t), c.innerHTML = v ? "&#x1F5F9;" : "&#9744;", c.setAttribute("aria-label", String(!!v));
601
607
  return;
602
608
  }
603
- if (g.key === "Enter" && !c.classList.contains("editing")) {
604
- g.preventDefault(), o.focusRow = n, o.focusCol = w, typeof o.beginBulkEdit == "function" ? o.beginBulkEdit(n) : L(o, t, n, h, c);
609
+ if (b.key === "Enter" && !c.classList.contains("editing")) {
610
+ b.preventDefault(), o.focusRow = n, o.focusCol = w, typeof o.beginBulkEdit == "function" ? o.beginBulkEdit(n) : L(o, t, n, u, c);
605
611
  return;
606
612
  }
607
- if (g.key === "F2" && !c.classList.contains("editing")) {
608
- g.preventDefault(), L(o, t, n, h, c);
613
+ if (b.key === "F2" && !c.classList.contains("editing")) {
614
+ b.preventDefault(), L(o, t, n, u, c);
609
615
  return;
610
616
  }
611
- })) : h.type === "boolean" && (c.hasAttribute("tabindex") || (c.tabIndex = 0), c.addEventListener("keydown", (g) => {
612
- if (g.key === " ") {
613
- g.preventDefault();
614
- const m = !t[h.field];
615
- o.activeEditRows !== n && T(o, n, t), $(o, n, h, m, t), c.innerHTML = m ? "&#x1F5F9;" : "&#9744;", c.setAttribute("role", "checkbox"), c.setAttribute("aria-checked", String(!!m)), c.setAttribute("aria-label", String(!!m));
617
+ })) : u.type === "boolean" && (c.hasAttribute("tabindex") || (c.tabIndex = 0), c.addEventListener("keydown", (b) => {
618
+ if (b.key === " ") {
619
+ b.preventDefault();
620
+ const v = !t[u.field];
621
+ o.activeEditRows !== n && T(o, n, t), $(o, n, u, v, t), c.innerHTML = v ? "&#x1F5F9;" : "&#9744;", c.setAttribute("role", "checkbox"), c.setAttribute("aria-checked", String(!!v)), c.setAttribute("aria-label", String(!!v));
616
622
  }
617
623
  })), l === n && r === w ? c.setAttribute("aria-selected", "true") : c.setAttribute("aria-selected", "false"), p.appendChild(c);
618
624
  }
@@ -620,19 +626,19 @@ function F(o, e, t, n) {
620
626
  }
621
627
  function Z(o, e, t, n) {
622
628
  if (e.target?.closest(".resize-handle")) return;
623
- const s = t.querySelector(".cell[data-row]");
624
- if (!s) return;
625
- const i = Number(s.getAttribute("data-row"));
626
- if (isNaN(i)) return;
627
- const l = o._rows[i];
629
+ const i = t.querySelector(".cell[data-row]");
630
+ if (!i) return;
631
+ const s = Number(i.getAttribute("data-row"));
632
+ if (isNaN(s)) return;
633
+ const l = o._rows[s];
628
634
  if (!l) return;
629
635
  const r = e.target?.closest(".cell[data-col]");
630
636
  if (r) {
631
637
  const f = Number(r.getAttribute("data-col"));
632
638
  if (!isNaN(f)) {
633
- if (o.dispatchCellClick?.(e, i, f, r))
639
+ if (o.dispatchCellClick?.(e, s, f, r))
634
640
  return;
635
- o.focusRow = i, o.focusCol = f, M(o);
641
+ o.focusRow = s, o.focusCol = f, O(o);
636
642
  }
637
643
  }
638
644
  if (t.querySelector(".cell.editing")) {
@@ -641,11 +647,11 @@ function Z(o, e, t, n) {
641
647
  f.forEach((p) => p.classList.remove("editing"));
642
648
  }
643
649
  const a = o.effectiveConfig?.editOn || o.editOn || "doubleClick";
644
- if (a === "click" || a === "doubleClick" && n) T(o, i, l);
650
+ if (a === "click" || a === "doubleClick" && n) T(o, s, l);
645
651
  else return;
646
652
  Array.from(t.children).forEach((f, p) => {
647
653
  const w = o.visibleColumns[p];
648
- w && w.editable && L(o, l, i, w, f);
654
+ w && w.editable && L(o, l, s, w, f);
649
655
  }), r && queueMicrotask(() => {
650
656
  const f = t.querySelector(`.cell[data-col="${o.focusCol}"]`);
651
657
  if (f?.classList.contains("editing")) {
@@ -664,16 +670,16 @@ function T(o, e, t) {
664
670
  }
665
671
  function Ie(o, e, t) {
666
672
  if (o.activeEditRows !== e) return;
667
- const n = o.rowEditSnapshots.get(e), s = o._rows[e];
668
- if (t && n && s)
669
- Object.keys(n).forEach((l) => s[l] = n[l]), o._changedRowIndices.delete(e);
673
+ const n = o.rowEditSnapshots.get(e), i = o._rows[e];
674
+ if (t && n && i)
675
+ Object.keys(n).forEach((l) => i[l] = n[l]), o._changedRowIndices.delete(e);
670
676
  else if (!t) {
671
677
  const l = o._changedRowIndices.has(e);
672
678
  o.dispatchEvent(
673
679
  new CustomEvent("row-commit", {
674
680
  detail: {
675
681
  rowIndex: e,
676
- row: s,
682
+ row: i,
677
683
  changed: l,
678
684
  changedRows: o.changedRows,
679
685
  changedRowIndices: o.changedRowIndices
@@ -682,8 +688,8 @@ function Ie(o, e, t) {
682
688
  );
683
689
  }
684
690
  o.rowEditSnapshots.delete(e), o.activeEditRows = -1;
685
- const i = o.findRenderedRowElement?.(e);
686
- i && (F(o, i, o._rows[e], e), o._changedRowIndices.has(e) ? i.classList.add("changed") : i.classList.remove("changed")), t && queueMicrotask(() => {
691
+ const s = o.findRenderedRowElement?.(e);
692
+ s && (F(o, s, o._rows[e], e), o._changedRowIndices.has(e) ? s.classList.add("changed") : s.classList.remove("changed")), t && queueMicrotask(() => {
687
693
  try {
688
694
  o.focus();
689
695
  const l = o.focusRow, r = o.focusCol, a = o.findRenderedRowElement?.(l);
@@ -698,18 +704,18 @@ function Ie(o, e, t) {
698
704
  }
699
705
  });
700
706
  }
701
- function $(o, e, t, n, s) {
702
- const i = t.field;
703
- if (s[i] === n) return;
704
- s[i] = n;
707
+ function $(o, e, t, n, i) {
708
+ const s = t.field;
709
+ if (i[s] === n) return;
710
+ i[s] = n;
705
711
  const r = !o._changedRowIndices.has(e);
706
712
  o._changedRowIndices.add(e);
707
713
  const a = o.findRenderedRowElement?.(e);
708
714
  a && a.classList.add("changed"), o.dispatchEvent(
709
715
  new CustomEvent("cell-commit", {
710
716
  detail: {
711
- row: s,
712
- field: i,
717
+ row: i,
718
+ field: s,
713
719
  value: n,
714
720
  rowIndex: e,
715
721
  changedRows: o.changedRows,
@@ -719,63 +725,63 @@ function $(o, e, t, n, s) {
719
725
  })
720
726
  );
721
727
  }
722
- function L(o, e, t, n, s) {
723
- if (!n.editable || (o.activeEditRows !== t && T(o, t, e), s.classList.contains("editing"))) return;
724
- const i = e[n.field];
725
- s.classList.add("editing");
726
- const l = (h) => {
727
- $(o, t, n, h, e);
728
+ function L(o, e, t, n, i) {
729
+ if (!n.editable || (o.activeEditRows !== t && T(o, t, e), i.classList.contains("editing"))) return;
730
+ const s = e[n.field];
731
+ i.classList.add("editing");
732
+ const l = (u) => {
733
+ $(o, t, n, u, e);
728
734
  }, r = () => {
729
- e[n.field] = i;
730
- const h = s.querySelector("input,textarea,select");
731
- h && (typeof HTMLInputElement < "u" && h instanceof HTMLInputElement && h.type === "checkbox" ? h.checked = !!i : "value" in h && (h.value = i ?? ""));
735
+ e[n.field] = s;
736
+ const u = i.querySelector("input,textarea,select");
737
+ u && (typeof HTMLInputElement < "u" && u instanceof HTMLInputElement && u.type === "checkbox" ? u.checked = !!s : "value" in u && (u.value = s ?? ""));
732
738
  }, a = document.createElement("div");
733
- a.style.display = "contents", s.innerHTML = "", s.appendChild(a);
734
- const f = n.__editorTemplate, p = n.editor || (f ? "template" : De(n)), w = i;
739
+ a.style.display = "contents", i.innerHTML = "", i.appendChild(a);
740
+ const f = n.__editorTemplate, p = n.editor || (f ? "template" : De(n)), w = s;
735
741
  if (p === "template" && f) {
736
- const h = f.cloneNode(!0), c = n.__compiledEditor;
737
- c ? h.innerHTML = c({ row: e, value: i, field: n.field, column: n }) : h.querySelectorAll("*").forEach((u) => {
738
- u.childNodes.length === 1 && u.firstChild?.nodeType === Node.TEXT_NODE && (u.textContent = u.textContent?.replace(/{{\s*value\s*}}/g, i == null ? "" : String(i)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g, (b, y) => {
739
- const v = e[y];
740
- return v == null ? "" : String(v);
742
+ const u = f.cloneNode(!0), c = n.__compiledEditor;
743
+ c ? u.innerHTML = c({ row: e, value: s, field: n.field, column: n }) : u.querySelectorAll("*").forEach((d) => {
744
+ d.childNodes.length === 1 && d.firstChild?.nodeType === Node.TEXT_NODE && (d.textContent = d.textContent?.replace(/{{\s*value\s*}}/g, s == null ? "" : String(s)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g, (g, m) => {
745
+ const C = e[m];
746
+ return C == null ? "" : String(C);
741
747
  }) || "");
742
748
  });
743
- const d = h.querySelector("input,textarea,select");
744
- if (d) {
745
- const u = typeof HTMLInputElement < "u";
746
- u && d instanceof HTMLInputElement && d.type === "checkbox" ? d.checked = !!i : "value" in d && (d.value = i ?? ""), d.addEventListener("blur", () => {
747
- const b = u && d instanceof HTMLInputElement && d.type === "checkbox" ? d.checked : d.value;
748
- l(b);
749
- }), d.addEventListener("keydown", (b) => {
750
- if (b.key === "Enter") {
751
- const y = u && d instanceof HTMLInputElement && d.type === "checkbox" ? d.checked : d.value;
752
- l(y);
749
+ const h = u.querySelector("input,textarea,select");
750
+ if (h) {
751
+ const d = typeof HTMLInputElement < "u";
752
+ d && h instanceof HTMLInputElement && h.type === "checkbox" ? h.checked = !!s : "value" in h && (h.value = s ?? ""), h.addEventListener("blur", () => {
753
+ const g = d && h instanceof HTMLInputElement && h.type === "checkbox" ? h.checked : h.value;
754
+ l(g);
755
+ }), h.addEventListener("keydown", (g) => {
756
+ if (g.key === "Enter") {
757
+ const m = d && h instanceof HTMLInputElement && h.type === "checkbox" ? h.checked : h.value;
758
+ l(m);
753
759
  }
754
- b.key === "Escape" && r();
755
- }), u && d instanceof HTMLInputElement && d.type === "checkbox" && d.addEventListener("change", () => {
756
- const b = d.checked;
757
- l(b);
758
- }), setTimeout(() => d.focus(), 0);
760
+ g.key === "Escape" && r();
761
+ }), d && h instanceof HTMLInputElement && h.type === "checkbox" && h.addEventListener("change", () => {
762
+ const g = h.checked;
763
+ l(g);
764
+ }), setTimeout(() => h.focus(), 0);
759
765
  }
760
- a.appendChild(h);
766
+ a.appendChild(u);
761
767
  } else if (typeof p == "string") {
762
- const h = document.createElement(p);
763
- h.value = w, h.addEventListener("change", () => l(h.value)), a.appendChild(h);
768
+ const u = document.createElement(p);
769
+ u.value = w, u.addEventListener("change", () => l(u.value)), a.appendChild(u);
764
770
  } else if (typeof p == "function") {
765
- const h = p({ row: e, value: w, field: n.field, column: n, commit: l, cancel: r });
766
- typeof h == "string" ? a.innerHTML = h : a.appendChild(h);
771
+ const u = p({ row: e, value: w, field: n.field, column: n, commit: l, cancel: r });
772
+ typeof u == "string" ? a.innerHTML = u : a.appendChild(u);
767
773
  } else if (p && typeof p == "object") {
768
- const h = document.createElement("div");
769
- h.setAttribute("data-external-editor", ""), h.setAttribute("data-field", n.field), a.appendChild(h);
774
+ const u = document.createElement("div");
775
+ u.setAttribute("data-external-editor", ""), u.setAttribute("data-field", n.field), a.appendChild(u);
770
776
  const c = { row: e, value: w, field: n.field, column: n, commit: l, cancel: r };
771
777
  if (p.mount)
772
778
  try {
773
- p.mount({ placeholder: h, context: c, spec: p });
779
+ p.mount({ placeholder: u, context: c, spec: p });
774
780
  } catch {
775
781
  }
776
782
  else
777
783
  o.dispatchEvent(
778
- new CustomEvent("mount-external-editor", { detail: { placeholder: h, spec: p, context: c } })
784
+ new CustomEvent("mount-external-editor", { detail: { placeholder: u, spec: p, context: c } })
779
785
  );
780
786
  }
781
787
  }
@@ -788,8 +794,8 @@ function J(o, e) {
788
794
  }
789
795
  function Q(o, e, t) {
790
796
  o.sortState = { field: e.field, direction: t };
791
- const n = e.sortComparator || ((s, i) => s == null && i == null ? 0 : s == null ? -1 : i == null || s > i ? 1 : s < i ? -1 : 0);
792
- o._rows.sort((s, i) => n(s[e.field], i[e.field], s, i) * t), o.__rowRenderEpoch++, o.rowPool.forEach((s) => s.__epoch = -1), V(o), o.refreshVirtualWindow(!0), o.dispatchEvent(
797
+ const n = e.sortComparator || ((i, s) => i == null && s == null ? 0 : i == null ? -1 : s == null || i > s ? 1 : i < s ? -1 : 0);
798
+ o._rows.sort((i, s) => n(i[e.field], s[e.field], i, s) * t), o.__rowRenderEpoch++, o.rowPool.forEach((i) => i.__epoch = -1), V(o), o.refreshVirtualWindow(!0), o.dispatchEvent(
793
799
  new CustomEvent("sort-change", { detail: { field: e.field, direction: t } })
794
800
  ), o.requestStateChange?.();
795
801
  }
@@ -797,41 +803,41 @@ function V(o) {
797
803
  o.headerRowEl = o.findHeaderRow();
798
804
  const e = o.headerRowEl;
799
805
  e.innerHTML = "", e.setAttribute("role", "row"), e.setAttribute("aria-rowindex", "1"), o.visibleColumns.forEach((t, n) => {
800
- const s = document.createElement("div");
801
- s.className = "cell", B(s, "header-cell"), s.setAttribute("role", "columnheader"), s.setAttribute("aria-colindex", String(n + 1)), s.setAttribute("data-field", t.field), s.setAttribute("data-col", String(n)), t.sticky === "left" ? s.classList.add("sticky-left") : t.sticky === "right" && s.classList.add("sticky-right");
802
- const i = t.__headerTemplate;
803
- if (i) Array.from(i.childNodes).forEach((l) => s.appendChild(l.cloneNode(!0)));
806
+ const i = document.createElement("div");
807
+ i.className = "cell", B(i, "header-cell"), i.setAttribute("role", "columnheader"), i.setAttribute("aria-colindex", String(n + 1)), i.setAttribute("data-field", t.field), i.setAttribute("data-col", String(n)), t.sticky === "left" ? i.classList.add("sticky-left") : t.sticky === "right" && i.classList.add("sticky-right");
808
+ const s = t.__headerTemplate;
809
+ if (s) Array.from(s.childNodes).forEach((l) => i.appendChild(l.cloneNode(!0)));
804
810
  else {
805
811
  const l = t.header || t.field, r = document.createElement("span");
806
- r.textContent = l, s.appendChild(r);
812
+ r.textContent = l, i.appendChild(r);
807
813
  }
808
814
  if (t.sortable) {
809
- s.classList.add("sortable"), s.tabIndex = 0;
815
+ i.classList.add("sortable"), i.tabIndex = 0;
810
816
  const l = document.createElement("span");
811
817
  B(l, "sort-indicator"), l.style.opacity = "0.6";
812
818
  const r = o.sortState?.field === t.field ? o.sortState.direction : 0;
813
- l.textContent = r === 1 ? "▲" : r === -1 ? "▼" : "⇅", s.appendChild(l), s.setAttribute("aria-sort", r === 0 ? "none" : r === 1 ? "ascending" : "descending"), s.addEventListener("click", (a) => {
814
- o.resizeController?.isResizing || o.dispatchHeaderClick?.(a, n, s) || J(o, t);
815
- }), s.addEventListener("keydown", (a) => {
819
+ l.textContent = r === 1 ? "▲" : r === -1 ? "▼" : "⇅", i.appendChild(l), i.setAttribute("aria-sort", r === 0 ? "none" : r === 1 ? "ascending" : "descending"), i.addEventListener("click", (a) => {
820
+ o.resizeController?.isResizing || o.dispatchHeaderClick?.(a, n, i) || J(o, t);
821
+ }), i.addEventListener("keydown", (a) => {
816
822
  if (a.key === "Enter" || a.key === " ") {
817
- if (a.preventDefault(), o.dispatchHeaderClick?.(a, n, s)) return;
823
+ if (a.preventDefault(), o.dispatchHeaderClick?.(a, n, i)) return;
818
824
  J(o, t);
819
825
  }
820
826
  });
821
827
  }
822
828
  if (t.resizable) {
823
- t.sticky || (s.style.position = "relative");
829
+ t.sticky || (i.style.position = "relative");
824
830
  const l = document.createElement("div");
825
831
  l.className = "resize-handle", l.setAttribute("aria-hidden", "true"), l.addEventListener("mousedown", (r) => {
826
- r.stopPropagation(), r.preventDefault(), o.resizeController.start(r, n, s);
827
- }), s.appendChild(l);
832
+ r.stopPropagation(), r.preventDefault(), o.resizeController.start(r, n, i);
833
+ }), i.appendChild(l);
828
834
  }
829
- e.appendChild(s);
835
+ e.appendChild(i);
830
836
  });
831
837
  try {
832
838
  const t = o.shadowRoot;
833
- t && t.querySelectorAll(".header-group-row .cell").forEach((s) => {
834
- s.getAttribute("data-group") && s.classList.add("grouped");
839
+ t && t.querySelectorAll(".header-group-row .cell").forEach((i) => {
840
+ i.getAttribute("data-group") && i.classList.add("grouped");
835
841
  });
836
842
  } catch {
837
843
  }
@@ -840,8 +846,8 @@ function V(o) {
840
846
  });
841
847
  }
842
848
  function Be(o) {
843
- let e = null, t = null, n = null, s = null;
844
- const i = (a) => {
849
+ let e = null, t = null, n = null, i = null;
850
+ const s = (a) => {
845
851
  if (!e) return;
846
852
  const f = a.clientX - e.startX, p = Math.max(40, e.startWidth + f), w = o.visibleColumns[e.colIndex];
847
853
  w.width = p, w.__userResized = !0, w.__renderedWidth = p, t == null && (t = requestAnimationFrame(() => {
@@ -855,7 +861,7 @@ function Be(o) {
855
861
  const a = e !== null;
856
862
  a && (l = !0, requestAnimationFrame(() => {
857
863
  l = !1;
858
- })), window.removeEventListener("mousemove", i), window.removeEventListener("mouseup", r), n !== null && (document.documentElement.style.cursor = n, n = null), s !== null && (document.body.style.userSelect = s, s = null), e = null, a && o.requestStateChange && o.requestStateChange();
864
+ })), window.removeEventListener("mousemove", s), window.removeEventListener("mouseup", r), n !== null && (document.documentElement.style.cursor = n, n = null), i !== null && (document.body.style.userSelect = i, i = null), e = null, a && o.requestStateChange && o.requestStateChange();
859
865
  };
860
866
  return {
861
867
  get isResizing() {
@@ -864,7 +870,7 @@ function Be(o) {
864
870
  start(a, f, p) {
865
871
  a.preventDefault();
866
872
  const w = p.getBoundingClientRect();
867
- e = { startX: a.clientX, colIndex: f, startWidth: w.width }, window.addEventListener("mousemove", i), window.addEventListener("mouseup", r), n === null && (n = document.documentElement.style.cursor), document.documentElement.style.cursor = "e-resize", s === null && (s = document.body.style.userSelect), document.body.style.userSelect = "none";
873
+ e = { startX: a.clientX, colIndex: f, startWidth: w.width }, window.addEventListener("mousemove", s), window.addEventListener("mouseup", r), n === null && (n = document.documentElement.style.cursor), document.documentElement.style.cursor = "e-resize", i === null && (i = document.body.style.userSelect), document.body.style.userSelect = "none";
868
874
  },
869
875
  dispose() {
870
876
  r();
@@ -888,20 +894,20 @@ function Ke(o, e) {
888
894
  return !!(o?.header?.title || o?.header?.toolbarButtons?.length || e.toolPanels.size > 0 || e.headerContents.size > 0 || e.toolbarButtons.size > 0 || e.lightDomButtons.length > 0 || e.lightDomHeaderContent.length > 0);
889
895
  }
890
896
  function We(o, e) {
891
- const t = o?.header?.title ?? "", n = !!t, s = o?.header?.toolbarButtons ?? [], i = s.length > 0, l = e.toolbarButtons.size > 0, r = e.lightDomButtons.length > 0, a = e.toolPanels.size > 0, p = (i || l || r) && a, w = [...s].sort((u, b) => (u.order ?? 100) - (b.order ?? 100)), h = [...e.toolbarButtons.values()].sort((u, b) => (u.order ?? 100) - (b.order ?? 100)), c = [...e.toolPanels.values()].sort((u, b) => (u.order ?? 100) - (b.order ?? 100));
892
- let d = "";
893
- for (const u of w)
894
- u.icon && u.action && (d += `<button class="tbw-toolbar-btn" data-btn="${u.id}" title="${u.label}" aria-label="${u.label}"${u.disabled ? " disabled" : ""}>${u.icon}</button>`);
895
- for (const u of h)
896
- u.icon && u.action && (d += `<button class="tbw-toolbar-btn" data-btn="${u.id}" title="${u.label}" aria-label="${u.label}"${u.disabled ? " disabled" : ""}>${u.icon}</button>`);
897
- for (const u of w)
898
- (u.element || u.render) && (d += `<div class="tbw-toolbar-btn-slot" data-btn-slot="${u.id}"></div>`);
899
- for (const u of h)
900
- (u.element || u.render) && (d += `<div class="tbw-toolbar-btn-slot" data-btn-slot="${u.id}"></div>`);
901
- r && (d += '<slot name="toolbar"></slot>'), p && (d += '<div class="tbw-toolbar-separator"></div>');
902
- for (const u of c) {
903
- const b = e.activePanel === u.id;
904
- d += `<button class="tbw-toolbar-btn${b ? " active" : ""}" data-panel="${u.id}" title="${u.tooltip ?? u.title}" aria-label="${u.tooltip ?? u.title}" aria-pressed="${b}" aria-controls="tbw-panel-${u.id}">${u.icon}</button>`;
897
+ const t = o?.header?.title ?? "", n = !!t, i = o?.header?.toolbarButtons ?? [], s = i.length > 0, l = e.toolbarButtons.size > 0, r = e.lightDomButtons.length > 0, a = e.toolPanels.size > 0, p = (s || l || r) && a, w = [...i].sort((d, g) => (d.order ?? 100) - (g.order ?? 100)), u = [...e.toolbarButtons.values()].sort((d, g) => (d.order ?? 100) - (g.order ?? 100)), c = [...e.toolPanels.values()].sort((d, g) => (d.order ?? 100) - (g.order ?? 100));
898
+ let h = "";
899
+ for (const d of w)
900
+ d.icon && d.action && (h += `<button class="tbw-toolbar-btn" data-btn="${d.id}" title="${d.label}" aria-label="${d.label}"${d.disabled ? " disabled" : ""}>${d.icon}</button>`);
901
+ for (const d of u)
902
+ d.icon && d.action && (h += `<button class="tbw-toolbar-btn" data-btn="${d.id}" title="${d.label}" aria-label="${d.label}"${d.disabled ? " disabled" : ""}>${d.icon}</button>`);
903
+ for (const d of w)
904
+ (d.element || d.render) && (h += `<div class="tbw-toolbar-btn-slot" data-btn-slot="${d.id}"></div>`);
905
+ for (const d of u)
906
+ (d.element || d.render) && (h += `<div class="tbw-toolbar-btn-slot" data-btn-slot="${d.id}"></div>`);
907
+ r && (h += '<slot name="toolbar"></slot>'), p && (h += '<div class="tbw-toolbar-separator"></div>');
908
+ for (const d of c) {
909
+ const g = e.activePanel === d.id;
910
+ h += `<button class="tbw-toolbar-btn${g ? " active" : ""}" data-panel="${d.id}" title="${d.tooltip ?? d.title}" aria-label="${d.tooltip ?? d.title}" aria-pressed="${g}" aria-controls="tbw-panel-${d.id}">${d.icon}</button>`;
905
911
  }
906
912
  return `
907
913
  <div class="tbw-shell-header" part="shell-header" role="banner">
@@ -910,14 +916,14 @@ function We(o, e) {
910
916
  <slot name="header-content"></slot>
911
917
  </div>
912
918
  <div class="tbw-shell-toolbar" part="shell-toolbar" role="toolbar" aria-label="Grid tools">
913
- ${d}
919
+ ${h}
914
920
  </div>
915
921
  </div>
916
922
  `;
917
923
  }
918
924
  function Fe(o, e, t) {
919
- const n = o?.toolPanel?.position ?? "right", s = e.toolPanels.size > 0, i = e.activePanel !== null, l = e.activePanel ? e.toolPanels.get(e.activePanel) : null, r = s ? `
920
- <aside class="tbw-tool-panel${i ? " open" : ""}" part="tool-panel" data-position="${n}" role="complementary" aria-label="${l?.title ?? "Tool panel"}" id="tbw-panel-${e.activePanel ?? "closed"}">
925
+ const n = o?.toolPanel?.position ?? "right", i = e.toolPanels.size > 0, s = e.activePanel !== null, l = e.activePanel ? e.toolPanels.get(e.activePanel) : null, r = i ? `
926
+ <aside class="tbw-tool-panel${s ? " open" : ""}" part="tool-panel" data-position="${n}" role="complementary" aria-label="${l?.title ?? "Tool panel"}" id="tbw-panel-${e.activePanel ?? "closed"}">
921
927
  <div class="tbw-tool-panel-header">
922
928
  <span class="tbw-tool-panel-title">${l?.title ?? ""}</span>
923
929
  <button class="tbw-tool-panel-close" aria-label="Close panel">✕</button>
@@ -946,20 +952,20 @@ function ee(o, e) {
946
952
  if (!t) return;
947
953
  t.style.display = "none";
948
954
  const n = t.querySelectorAll("tbw-grid-header-content");
949
- e.lightDomHeaderContent = Array.from(n), e.lightDomHeaderContent.forEach((i, l) => {
950
- i.setAttribute("slot", "header-content");
955
+ e.lightDomHeaderContent = Array.from(n), e.lightDomHeaderContent.forEach((s, l) => {
956
+ s.setAttribute("slot", "header-content");
951
957
  });
952
- const s = t.querySelectorAll("tbw-grid-tool-button");
953
- e.lightDomButtons = Array.from(s), e.lightDomButtons.sort((i, l) => {
954
- const r = parseInt(i.getAttribute("order") ?? "100", 10), a = parseInt(l.getAttribute("order") ?? "100", 10);
958
+ const i = t.querySelectorAll("tbw-grid-tool-button");
959
+ e.lightDomButtons = Array.from(i), e.lightDomButtons.sort((s, l) => {
960
+ const r = parseInt(s.getAttribute("order") ?? "100", 10), a = parseInt(l.getAttribute("order") ?? "100", 10);
955
961
  return r - a;
956
- }), e.lightDomButtons.forEach((i) => {
957
- i.setAttribute("slot", "toolbar");
962
+ }), e.lightDomButtons.forEach((s) => {
963
+ s.setAttribute("slot", "toolbar");
958
964
  });
959
965
  }
960
966
  function Ve(o, e, t, n) {
961
- const s = o.querySelector(".tbw-shell-toolbar");
962
- s && s.addEventListener("click", (l) => {
967
+ const i = o.querySelector(".tbw-shell-toolbar");
968
+ i && i.addEventListener("click", (l) => {
963
969
  const r = l.target, a = r.closest("[data-panel]");
964
970
  if (a) {
965
971
  const p = a.getAttribute("data-panel");
@@ -972,36 +978,36 @@ function Ve(o, e, t, n) {
972
978
  p && n.onToolbarButtonClick(p);
973
979
  }
974
980
  });
975
- const i = o.querySelector(".tbw-tool-panel-close");
976
- i && i.addEventListener("click", () => {
981
+ const s = o.querySelector(".tbw-tool-panel-close");
982
+ s && s.addEventListener("click", () => {
977
983
  n.onPanelClose();
978
984
  });
979
985
  }
980
986
  function Ge(o, e, t) {
981
987
  const n = [...e?.header?.toolbarButtons ?? [], ...t.toolbarButtons.values()];
982
- for (const s of n) {
983
- const i = o.querySelector(`[data-btn-slot="${s.id}"]`);
984
- if (!i) continue;
985
- const l = t.toolbarButtonCleanups.get(s.id);
986
- if (l && (l(), t.toolbarButtonCleanups.delete(s.id)), s.element)
987
- i.appendChild(s.element);
988
- else if (s.render) {
989
- const r = s.render(i);
990
- r && t.toolbarButtonCleanups.set(s.id, r);
988
+ for (const i of n) {
989
+ const s = o.querySelector(`[data-btn-slot="${i.id}"]`);
990
+ if (!s) continue;
991
+ const l = t.toolbarButtonCleanups.get(i.id);
992
+ if (l && (l(), t.toolbarButtonCleanups.delete(i.id)), i.element)
993
+ s.appendChild(i.element);
994
+ else if (i.render) {
995
+ const r = i.render(s);
996
+ r && t.toolbarButtonCleanups.set(i.id, r);
991
997
  }
992
998
  }
993
999
  }
994
1000
  function te(o, e) {
995
1001
  const t = o.querySelector(".tbw-shell-content");
996
1002
  if (!t) return;
997
- const n = [...e.headerContents.values()].sort((i, l) => (i.order ?? 100) - (l.order ?? 100)), s = t.querySelector('slot[name="header-content"]');
998
- for (const i of n) {
999
- const l = e.headerContentCleanups.get(i.id);
1000
- l && (l(), e.headerContentCleanups.delete(i.id));
1001
- let r = t.querySelector(`[data-header-content="${i.id}"]`);
1002
- r || (r = document.createElement("div"), r.setAttribute("data-header-content", i.id), s ? t.insertBefore(r, s) : t.appendChild(r));
1003
- const a = i.render(r);
1004
- a && e.headerContentCleanups.set(i.id, a);
1003
+ const n = [...e.headerContents.values()].sort((s, l) => (s.order ?? 100) - (l.order ?? 100)), i = t.querySelector('slot[name="header-content"]');
1004
+ for (const s of n) {
1005
+ const l = e.headerContentCleanups.get(s.id);
1006
+ l && (l(), e.headerContentCleanups.delete(s.id));
1007
+ let r = t.querySelector(`[data-header-content="${s.id}"]`);
1008
+ r || (r = document.createElement("div"), r.setAttribute("data-header-content", s.id), i ? t.insertBefore(r, i) : t.appendChild(r));
1009
+ const a = s.render(r);
1010
+ a && e.headerContentCleanups.set(s.id, a);
1005
1011
  }
1006
1012
  }
1007
1013
  function Ue(o, e) {
@@ -1011,13 +1017,13 @@ function Ue(o, e) {
1011
1017
  const n = o.querySelector(".tbw-tool-panel-content");
1012
1018
  if (!n) return;
1013
1019
  e.activePanelCleanup && (e.activePanelCleanup(), e.activePanelCleanup = null), n.innerHTML = "";
1014
- const s = t.render(n);
1015
- s && (e.activePanelCleanup = s);
1020
+ const i = t.render(n);
1021
+ i && (e.activePanelCleanup = i);
1016
1022
  }
1017
1023
  function oe(o, e) {
1018
1024
  o.querySelectorAll("[data-panel]").forEach((n) => {
1019
- const i = n.getAttribute("data-panel") === e.activePanel;
1020
- n.classList.toggle("active", i), n.setAttribute("aria-pressed", String(i));
1025
+ const s = n.getAttribute("data-panel") === e.activePanel;
1026
+ n.classList.toggle("active", s), n.setAttribute("aria-pressed", String(s));
1021
1027
  });
1022
1028
  }
1023
1029
  function ne(o, e) {
@@ -1025,8 +1031,8 @@ function ne(o, e) {
1025
1031
  if (!t) return;
1026
1032
  const n = e.activePanel !== null;
1027
1033
  if (t.classList.toggle("open", n), n && e.activePanel) {
1028
- const s = e.toolPanels.get(e.activePanel), i = t.querySelector(".tbw-tool-panel-title");
1029
- i && (i.textContent = s?.title ?? ""), t.setAttribute("aria-label", `${s?.title ?? "Tool"} panel`), t.id = `tbw-panel-${e.activePanel}`;
1034
+ const i = e.toolPanels.get(e.activePanel), s = t.querySelector(".tbw-tool-panel-title");
1035
+ s && (s.textContent = i?.title ?? ""), t.setAttribute("aria-label", `${i?.title ?? "Tool"} panel`), t.id = `tbw-panel-${e.activePanel}`;
1030
1036
  }
1031
1037
  }
1032
1038
  function Xe(o, e) {
@@ -1046,11 +1052,11 @@ function Xe(o, e) {
1046
1052
  source: "config"
1047
1053
  });
1048
1054
  for (let n = 0; n < e.lightDomButtons.length; n++) {
1049
- const i = e.lightDomButtons[n].querySelector("button");
1055
+ const s = e.lightDomButtons[n].querySelector("button");
1050
1056
  t.push({
1051
1057
  id: `light-dom-${n}`,
1052
- label: i?.getAttribute("title") ?? i?.getAttribute("aria-label") ?? "",
1053
- disabled: i?.disabled ?? !1,
1058
+ label: s?.getAttribute("title") ?? s?.getAttribute("aria-label") ?? "",
1059
+ disabled: s?.disabled ?? !1,
1054
1060
  source: "light-dom"
1055
1061
  });
1056
1062
  }
@@ -1211,8 +1217,8 @@ class Ye {
1211
1217
  * Returns true if any plugin handled the row.
1212
1218
  */
1213
1219
  renderRow(e, t, n) {
1214
- for (const s of this.plugins)
1215
- if (s.renderRow?.(e, t, n))
1220
+ for (const i of this.plugins)
1221
+ if (i.renderRow?.(e, t, n))
1216
1222
  return !0;
1217
1223
  return !1;
1218
1224
  }
@@ -1299,8 +1305,8 @@ class Ye {
1299
1305
  getContextMenuItems(e) {
1300
1306
  const t = [];
1301
1307
  for (const n of this.plugins) {
1302
- const s = n.getContextMenuItems?.(e);
1303
- s && t.push(...s);
1308
+ const i = n.getContextMenuItems?.(e);
1309
+ i && t.push(...i);
1304
1310
  }
1305
1311
  return t;
1306
1312
  }
@@ -1333,46 +1339,45 @@ class Ye {
1333
1339
  class q extends HTMLElement {
1334
1340
  // TODO: Rename to 'data-grid' when migration is complete
1335
1341
  static tagName = "tbw-grid";
1336
- #n;
1342
+ #o;
1337
1343
  #i = !1;
1338
1344
  // ---------------- Ready Promise ----------------
1345
+ #H;
1339
1346
  #z;
1340
- #N;
1341
1347
  // ================== INPUT PROPERTIES ==================
1342
1348
  // These backing fields store raw user input. They are merged into
1343
1349
  // #effectiveConfig by #mergeEffectiveConfig(). Never read directly
1344
1350
  // for rendering logic - always use effectiveConfig or derived state.
1345
1351
  #l = [];
1346
1352
  #r;
1353
+ #p;
1347
1354
  #g;
1348
- #C;
1349
- #y;
1355
+ #m;
1350
1356
  // ================== SINGLE SOURCE OF TRUTH ==================
1351
1357
  // All input sources converge here. This is the canonical config
1352
1358
  // that all rendering and logic should read from.
1353
- #o = {};
1354
- #u = !1;
1355
- #L = 0;
1356
- #E = null;
1357
- #R = !1;
1359
+ #n = {};
1360
+ #f = !1;
1361
+ #T = 0;
1362
+ #v = null;
1363
+ #C = !1;
1358
1364
  // Cached flag for plugin scroll handlers
1359
- #k;
1365
+ #L;
1360
1366
  // Cached hook to avoid closures
1361
- #f;
1362
- #p;
1363
- #_ = !1;
1364
- #w;
1365
- #b;
1367
+ #y = !1;
1368
+ #E = null;
1369
+ #R = null;
1370
+ #_ = null;
1366
1371
  #A = null;
1367
- #S = null;
1372
+ #a;
1368
1373
  // ---------------- Plugin System ----------------
1369
1374
  #t;
1370
1375
  // ---------------- Column State ----------------
1371
- #P;
1372
- #d;
1376
+ #k;
1377
+ #h;
1373
1378
  // ---------------- Shell State ----------------
1374
1379
  #e = $e();
1375
- #a = !1;
1380
+ #c = !1;
1376
1381
  // ================== DERIVED STATE ==================
1377
1382
  // _rows: result of applying plugin processRows hooks
1378
1383
  _rows = [];
@@ -1380,10 +1385,10 @@ class q extends HTMLElement {
1380
1385
  // This ensures effectiveConfig.columns is the single source of truth for columns
1381
1386
  // _columns always contains ALL columns (including hidden)
1382
1387
  get _columns() {
1383
- return this.#o.columns ?? [];
1388
+ return this.#n.columns ?? [];
1384
1389
  }
1385
1390
  set _columns(e) {
1386
- this.#o.columns = e;
1391
+ this.#n.columns = e;
1387
1392
  }
1388
1393
  // visibleColumns returns only visible columns for rendering
1389
1394
  // This is what header/row rendering should use
@@ -1433,7 +1438,7 @@ class q extends HTMLElement {
1433
1438
  }
1434
1439
  set rows(e) {
1435
1440
  const t = this.#l;
1436
- this.#l = e, t !== e && this.#Z();
1441
+ this.#l = e, t !== e && this.#Y();
1437
1442
  }
1438
1443
  /**
1439
1444
  * Get the original unfiltered/unprocessed rows.
@@ -1447,41 +1452,51 @@ class q extends HTMLElement {
1447
1452
  }
1448
1453
  set columns(e) {
1449
1454
  const t = this.#r;
1450
- this.#r = e, t !== e && this.#J();
1455
+ this.#r = e, t !== e && this.#Z();
1451
1456
  }
1452
1457
  get gridConfig() {
1453
- return this.#o;
1458
+ return this.#n;
1454
1459
  }
1455
1460
  set gridConfig(e) {
1456
- const t = this.#g;
1457
- this.#g = e, t !== e && this.#Q();
1461
+ const t = this.#p;
1462
+ this.#p = e, t !== e && this.#J();
1458
1463
  }
1459
1464
  get fitMode() {
1460
- return this.#o.fitMode ?? "stretch";
1465
+ return this.#n.fitMode ?? "stretch";
1461
1466
  }
1462
1467
  set fitMode(e) {
1463
- const t = this.#C;
1464
- this.#C = e, t !== e && this.#j();
1468
+ const t = this.#g;
1469
+ this.#g = e, t !== e && this.#X();
1465
1470
  }
1466
1471
  get editOn() {
1467
- return this.#o.editOn;
1472
+ return this.#n.editOn;
1468
1473
  }
1469
1474
  set editOn(e) {
1470
- const t = this.#y;
1471
- this.#y = e, t !== e && this.#Y();
1475
+ const t = this.#m;
1476
+ this.#m = e, t !== e && this.#j();
1472
1477
  }
1473
1478
  // Effective config accessor for internal modules and plugins
1474
1479
  // Returns the merged config (single source of truth) before plugin processing
1475
1480
  // Use this when you need the raw merged config (e.g., for column definitions including hidden)
1476
1481
  get effectiveConfig() {
1477
- return this.#o;
1482
+ return this.#n;
1483
+ }
1484
+ /**
1485
+ * Get the disconnect signal for event listener cleanup.
1486
+ * This signal is aborted when the grid disconnects from the DOM.
1487
+ * Plugins and internal code can use this for automatic listener cleanup.
1488
+ * @example
1489
+ * element.addEventListener('click', handler, { signal: this.grid.disconnectSignal });
1490
+ */
1491
+ get disconnectSignal() {
1492
+ return this.#a || (this.#a = new AbortController()), this.#a.signal;
1478
1493
  }
1479
1494
  constructor() {
1480
- super(), this.#n = this.attachShadow({ mode: "open" }), this.#V(), this.#z = new Promise((e) => this.#N = e);
1495
+ super(), this.#o = this.attachShadow({ mode: "open" }), this.#F(), this.#H = new Promise((e) => this.#z = e);
1481
1496
  }
1482
- #V() {
1497
+ #F() {
1483
1498
  const e = new CSSStyleSheet();
1484
- e.replaceSync(we), this.#n.adoptedStyleSheets = [e];
1499
+ e.replaceSync(we), this.#o.adoptedStyleSheets = [e];
1485
1500
  }
1486
1501
  // ---------------- Plugin System ----------------
1487
1502
  /**
@@ -1504,7 +1519,7 @@ class q extends HTMLElement {
1504
1519
  * Note: This does NOT reset plugin state - just re-processes rows/columns and renders.
1505
1520
  */
1506
1521
  requestRender() {
1507
- this.#T(), this.#O(), this.#x(), this.updateTemplate(), this.refreshVirtualWindow(!0);
1522
+ this.#x(), this.#P(), this.#S(), this.updateTemplate(), this.refreshVirtualWindow(!0);
1508
1523
  }
1509
1524
  /**
1510
1525
  * Request a lightweight style update without rebuilding DOM.
@@ -1512,46 +1527,46 @@ class q extends HTMLElement {
1512
1527
  * This runs all plugin afterRender hooks without rebuilding row/column DOM.
1513
1528
  */
1514
1529
  requestAfterRender() {
1515
- this.#m();
1530
+ this.#w();
1516
1531
  }
1517
1532
  /**
1518
1533
  * Initialize plugin system with instances from config.
1519
1534
  * Plugins are class instances passed in gridConfig.plugins[].
1520
1535
  */
1521
- #q() {
1536
+ #N() {
1522
1537
  this.#t = new Ye(this);
1523
- const e = this.#o?.plugins, t = Array.isArray(e) ? e : [];
1538
+ const e = this.#n?.plugins, t = Array.isArray(e) ? e : [];
1524
1539
  this.#t.attachAll(t);
1525
1540
  }
1526
1541
  /**
1527
1542
  * Inject all plugin styles into the shadow DOM.
1528
1543
  * Must be called after #render() since innerHTML wipes existing content.
1529
1544
  */
1530
- #I() {
1545
+ #q() {
1531
1546
  const e = this.#t?.getAllStyles() ?? "";
1532
1547
  if (e) {
1533
1548
  const t = document.createElement("style");
1534
- t.setAttribute("data-plugin", "all"), t.textContent = e, this.#n.appendChild(t);
1549
+ t.setAttribute("data-plugin", "all"), t.textContent = e, this.#o.appendChild(t);
1535
1550
  }
1536
1551
  }
1537
1552
  /**
1538
1553
  * Update plugins when grid config changes.
1539
1554
  * With class-based plugins, we need to detach old and attach new.
1540
1555
  */
1541
- #B() {
1542
- this.#t && this.#t.detachAll(), this.#q(), this.#I(), this.#R = this.#t?.getAll().some((e) => e.onScroll) ?? !1;
1556
+ #I() {
1557
+ this.#t && this.#t.detachAll(), this.#N(), this.#q(), this.#C = this.#t?.getAll().some((e) => e.onScroll) ?? !1;
1543
1558
  }
1544
1559
  /**
1545
1560
  * Clean up plugin states when grid disconnects.
1546
1561
  */
1547
- #G() {
1562
+ #V() {
1548
1563
  this.#t?.detachAll();
1549
1564
  }
1550
1565
  /**
1551
1566
  * Collect tool panels and header content from all plugins.
1552
1567
  * Called after plugins are attached but before render.
1553
1568
  */
1554
- #U() {
1569
+ #G() {
1555
1570
  if (!this.#t) return;
1556
1571
  const e = this.#t.getToolPanels();
1557
1572
  for (const { panel: n } of e)
@@ -1562,75 +1577,85 @@ class q extends HTMLElement {
1562
1577
  }
1563
1578
  // ---------------- Lifecycle ----------------
1564
1579
  connectedCallback() {
1565
- this.hasAttribute("tabindex") || (this.tabIndex = 0), this._rows = Array.isArray(this.#l) ? [...this.#l] : [], this.#h(), this.#q(), this.#U(), this.#i || (this.#F(), this.#I(), this.#i = !0), this.#$();
1580
+ this.hasAttribute("tabindex") || (this.tabIndex = 0), this._rows = Array.isArray(this.#l) ? [...this.#l] : [], this.#a?.abort(), this.#a = new AbortController(), this.#u(), this.#N(), this.#G(), this.#i || (this.#W(), this.#q(), this.#i = !0), this.#B();
1566
1581
  }
1567
1582
  disconnectedCallback() {
1568
- this.#G(), je(this.#e), this.#a = !1, this.#f && (document.removeEventListener("keydown", this.#f, !0), this.#f = void 0), this.#p && (document.removeEventListener("mousedown", this.#p, !1), this.#p = void 0), this.#w && (document.removeEventListener("mousemove", this.#w), this.#w = void 0), this.#b && (document.removeEventListener("mouseup", this.#b), this.#b = void 0), this.resizeController && this.resizeController.dispose(), this.#u = !1;
1583
+ this.#V(), je(this.#e), this.#c = !1, this.#a && (this.#a.abort(), this.#a = void 0), this.resizeController && this.resizeController.dispose(), this.#f = !1;
1569
1584
  }
1570
- #$() {
1571
- const t = this.#n.querySelector(".tbw-grid-content") ?? this.#n.querySelector(".tbw-grid-root");
1572
- if (this.headerRowEl = t?.querySelector(".header-row"), this.virtualization.totalHeightEl = t?.querySelector(".faux-vscroll-spacer"), this.virtualization.viewportEl = t?.querySelector(".rows-viewport"), this.bodyEl = t?.querySelector(".rows"), this.#a) {
1573
- te(this.#n, this.#e), Ge(this.#n, this.#o?.shell, this.#e);
1574
- const i = this.#o?.shell?.toolPanel?.defaultOpen;
1575
- i && this.#e.toolPanels.has(i) && this.openToolPanel(i);
1576
- }
1577
- this.setAttribute("data-upgraded", ""), this.hasAttribute("role") || this.setAttribute("role", "grid"), this.#u = !0, this.#c(), this.addEventListener("keydown", (i) => He(this, i)), this.#f || (this.#f = (i) => {
1578
- i.key === "Escape" && this.activeEditRows !== -1 && this.#D(this.activeEditRows, !0);
1579
- }, document.addEventListener("keydown", this.#f, !0)), this.#p || (this.#p = (i) => {
1580
- if (this.activeEditRows === -1) return;
1581
- const l = this.findRenderedRowElement(this.activeEditRows);
1582
- !l || (i.composedPath && i.composedPath() || []).includes(l) || this.#D(this.activeEditRows, !1);
1583
- }, document.addEventListener("mousedown", this.#p, !1));
1584
- const n = t?.querySelector(".faux-vscroll"), s = t?.querySelector(".rows");
1585
- if (this.virtualization.container = n ?? this, this.#R = this.#t?.getAll().some((i) => i.onScroll) ?? !1, n && s) {
1586
- n.addEventListener(
1585
+ #B() {
1586
+ const t = this.#o.querySelector(".tbw-grid-content") ?? this.#o.querySelector(".tbw-grid-root");
1587
+ if (this.headerRowEl = t?.querySelector(".header-row"), this.virtualization.totalHeightEl = t?.querySelector(".faux-vscroll-spacer"), this.virtualization.viewportEl = t?.querySelector(".rows-viewport"), this.bodyEl = t?.querySelector(".rows"), this.#c) {
1588
+ te(this.#o, this.#e), Ge(this.#o, this.#n?.shell, this.#e);
1589
+ const l = this.#n?.shell?.toolPanel?.defaultOpen;
1590
+ l && this.#e.toolPanels.has(l) && this.openToolPanel(l);
1591
+ }
1592
+ this.setAttribute("data-upgraded", ""), this.hasAttribute("role") || this.setAttribute("role", "grid"), this.#f = !0;
1593
+ const n = this.disconnectSignal;
1594
+ this.#d(), this.addEventListener("keydown", (l) => He(this, l), { signal: n }), document.addEventListener(
1595
+ "keydown",
1596
+ (l) => {
1597
+ l.key === "Escape" && this.activeEditRows !== -1 && this.#O(this.activeEditRows, !0);
1598
+ },
1599
+ { capture: !0, signal: n }
1600
+ ), document.addEventListener(
1601
+ "mousedown",
1602
+ (l) => {
1603
+ if (this.activeEditRows === -1) return;
1604
+ const r = this.findRenderedRowElement(this.activeEditRows);
1605
+ !r || (l.composedPath && l.composedPath() || []).includes(r) || this.#O(this.activeEditRows, !1);
1606
+ },
1607
+ { signal: n }
1608
+ );
1609
+ const i = t?.querySelector(".faux-vscroll"), s = t?.querySelector(".rows");
1610
+ if (this.virtualization.container = i ?? this, this.#C = this.#t?.getAll().some((l) => l.onScroll) ?? !1, i && s) {
1611
+ i.addEventListener(
1587
1612
  "scroll",
1588
1613
  () => {
1589
- if (!this.virtualization.enabled && !this.#R) return;
1590
- const l = n.scrollTop, r = this.virtualization.rowHeight, a = -(l % r);
1591
- s.style.transform = `translateY(${a}px)`, this.#E = l, this.#L || (this.#L = requestAnimationFrame(() => {
1592
- this.#L = 0, this.#E !== null && (this.#ne(this.#E), this.#E = null);
1614
+ if (!this.virtualization.enabled && !this.#C) return;
1615
+ const a = i.scrollTop, f = this.virtualization.rowHeight, p = -(a % f);
1616
+ s.style.transform = `translateY(${p}px)`, this.#v = a, this.#T || (this.#T = requestAnimationFrame(() => {
1617
+ this.#T = 0, this.#v !== null && (this.#oe(this.#v), this.#v = null);
1593
1618
  }));
1594
1619
  },
1595
- { passive: !0 }
1620
+ { passive: !0, signal: n }
1596
1621
  );
1597
- const i = t?.querySelector(".rows-body");
1598
- i && (i.addEventListener(
1622
+ const l = this.#o.querySelector(".tbw-grid-content"), r = this.#o.querySelector(".tbw-scroll-area");
1623
+ l && (l.addEventListener(
1599
1624
  "wheel",
1600
- (l) => {
1601
- l.preventDefault(), n.scrollTop += l.deltaY;
1625
+ (a) => {
1626
+ a.preventDefault(), a.shiftKey || Math.abs(a.deltaX) > Math.abs(a.deltaY) ? r && (r.scrollLeft += a.shiftKey ? a.deltaY : a.deltaX) : i.scrollTop += a.deltaY;
1602
1627
  },
1603
- { passive: !1 }
1604
- ), i.addEventListener(
1628
+ { passive: !1, signal: n }
1629
+ ), l.addEventListener(
1605
1630
  "touchstart",
1606
- (l) => {
1607
- l.touches.length === 1 && (this.#A = l.touches[0].clientY, this.#S = n.scrollTop);
1631
+ (a) => {
1632
+ a.touches.length === 1 && (this.#E = a.touches[0].clientY, this.#R = a.touches[0].clientX, this.#_ = i.scrollTop, this.#A = r?.scrollLeft ?? 0);
1608
1633
  },
1609
- { passive: !0 }
1610
- ), i.addEventListener(
1634
+ { passive: !0, signal: n }
1635
+ ), l.addEventListener(
1611
1636
  "touchmove",
1612
- (l) => {
1613
- if (l.touches.length === 1 && this.#A !== null && this.#S !== null) {
1614
- const r = this.#A - l.touches[0].clientY;
1615
- n.scrollTop = this.#S + r, l.preventDefault();
1637
+ (a) => {
1638
+ if (a.touches.length === 1 && this.#E !== null && this.#R !== null && this.#_ !== null && this.#A !== null) {
1639
+ const f = this.#E - a.touches[0].clientY, p = this.#R - a.touches[0].clientX;
1640
+ i.scrollTop = this.#_ + f, r && (r.scrollLeft = this.#A + p), a.preventDefault();
1616
1641
  }
1617
1642
  },
1618
- { passive: !1 }
1619
- ), i.addEventListener(
1643
+ { passive: !1, signal: n }
1644
+ ), l.addEventListener(
1620
1645
  "touchend",
1621
1646
  () => {
1622
- this.#A = null, this.#S = null;
1647
+ this.#E = null, this.#R = null, this.#_ = null, this.#A = null;
1623
1648
  },
1624
- { passive: !0 }
1649
+ { passive: !0, signal: n }
1625
1650
  ));
1626
1651
  }
1627
- this.resizeController = Be(this), this.#n.addEventListener("mousedown", (i) => this.#ie(i)), this.#w || (this.#w = (i) => this.#se(i), document.addEventListener("mousemove", this.#w)), this.#b || (this.#b = (i) => this.#le(i), document.addEventListener("mouseup", this.#b)), this.virtualization.enabled && requestAnimationFrame(() => this.refreshVirtualWindow(!0)), requestAnimationFrame(() => {
1628
- const i = this.bodyEl.querySelector(".data-grid-row");
1629
- if (i) {
1630
- const l = i.getBoundingClientRect().height;
1631
- l && Math.abs(l - this.virtualization.rowHeight) > 0.1 && (this.virtualization.rowHeight = l, this.refreshVirtualWindow(!0));
1652
+ this.resizeController = Be(this), this.#o.addEventListener("mousedown", (l) => this.#ne(l), { signal: n }), document.addEventListener("mousemove", (l) => this.#ie(l), { signal: n }), document.addEventListener("mouseup", (l) => this.#se(l), { signal: n }), this.virtualization.enabled && requestAnimationFrame(() => this.refreshVirtualWindow(!0)), requestAnimationFrame(() => {
1653
+ const l = this.bodyEl.querySelector(".data-grid-row");
1654
+ if (l) {
1655
+ const r = l.getBoundingClientRect().height;
1656
+ r && Math.abs(r - this.virtualization.rowHeight) > 0.1 && (this.virtualization.rowHeight = r, this.refreshVirtualWindow(!0));
1632
1657
  }
1633
- }), queueMicrotask(() => this.#X()), requestAnimationFrame(() => requestAnimationFrame(() => this.#N?.()));
1658
+ }), queueMicrotask(() => this.#U()), requestAnimationFrame(() => requestAnimationFrame(() => this.#z?.()));
1634
1659
  }
1635
1660
  // ---------------- Event Emitters ----------------
1636
1661
  #s(e, t) {
@@ -1652,65 +1677,65 @@ class q extends HTMLElement {
1652
1677
  this.#s("activate-cell", e);
1653
1678
  }
1654
1679
  /** Update ARIA selection attributes on rendered rows/cells */
1655
- #X() {
1680
+ #U() {
1656
1681
  this.bodyEl?.querySelectorAll(".data-grid-row")?.forEach((t, n) => {
1657
- const s = n === this.focusRow;
1658
- t.setAttribute("aria-selected", String(s)), t.querySelectorAll(".cell").forEach((i, l) => {
1659
- i.setAttribute("aria-selected", String(s && l === this.focusCol));
1682
+ const i = n === this.focusRow;
1683
+ t.setAttribute("aria-selected", String(i)), t.querySelectorAll(".cell").forEach((s, l) => {
1684
+ s.setAttribute("aria-selected", String(i && l === this.focusCol));
1660
1685
  });
1661
1686
  });
1662
1687
  }
1663
1688
  // ---------------- Watch Handlers ----------------
1664
- #j() {
1665
- if (!this.#u) return;
1666
- this.#h(), this.#o.fitMode === "fixed" ? (this.__didInitialAutoSize = !1, this.#K()) : (this._columns.forEach((t) => {
1689
+ #X() {
1690
+ if (!this.#f) return;
1691
+ this.#u(), this.#n.fitMode === "fixed" ? (this.__didInitialAutoSize = !1, this.#$()) : (this._columns.forEach((t) => {
1667
1692
  !t.__userResized && t.__autoSized && delete t.width;
1668
1693
  }), this.updateTemplate());
1669
1694
  }
1695
+ #j() {
1696
+ this.#f && (this.#u(), this.rowPool.length = 0, this.bodyEl && (this.bodyEl.innerHTML = ""), this.__rowRenderEpoch++, this.refreshVirtualWindow(!0));
1697
+ }
1670
1698
  #Y() {
1671
- this.#u && (this.#h(), this.rowPool.length = 0, this.bodyEl && (this.bodyEl.innerHTML = ""), this.__rowRenderEpoch++, this.refreshVirtualWindow(!0));
1699
+ this._rows = Array.isArray(this.#l) ? [...this.#l] : [], this.#x(), !this.#r || Array.isArray(this.#r) && this.#r.length === 0 ? this.#d() : this.refreshVirtualWindow(!0);
1672
1700
  }
1673
1701
  #Z() {
1674
- this._rows = Array.isArray(this.#l) ? [...this.#l] : [], this.#T(), !this.#r || Array.isArray(this.#r) && this.#r.length === 0 ? this.#c() : this.refreshVirtualWindow(!0);
1702
+ j(this), this.#f && (this.#u(), this.#d());
1675
1703
  }
1676
1704
  #J() {
1677
- j(this), this.#u && (this.#h(), this.#c());
1678
- }
1679
- #Q() {
1680
- this.#u && (this.#h(), this.#B(), this.#T(), this.#O(), this.#x(), this.updateTemplate(), this.refreshVirtualWindow(!0));
1705
+ this.#f && (this.#u(), this.#I(), this.#x(), this.#P(), this.#S(), this.updateTemplate(), this.refreshVirtualWindow(!0));
1681
1706
  }
1682
1707
  // ---------------- Helper Wrappers ----------------
1683
- #ee() {
1684
- Oe(this);
1708
+ #Q() {
1709
+ Me(this);
1685
1710
  }
1686
- #x() {
1711
+ #S() {
1687
1712
  V(this);
1688
1713
  }
1689
1714
  updateTemplate() {
1690
1715
  he(this);
1691
1716
  }
1692
- #K() {
1693
- Me(this);
1717
+ #$() {
1718
+ Oe(this);
1694
1719
  }
1695
- #O() {
1720
+ #P() {
1696
1721
  if (this.#t) {
1697
1722
  const e = this._columns.filter((n) => !n.hidden), t = this.#t.processColumns([...e]);
1698
1723
  if (t !== e) {
1699
- const n = new Map(t.map((i, l) => [i.field, { col: i, order: l }])), s = this._columns.map((i) => {
1700
- if (i.hidden) return i;
1701
- const l = n.get(i.field);
1702
- return l ? l.col : i;
1724
+ const n = new Map(t.map((s, l) => [s.field, { col: s, order: l }])), i = this._columns.map((s) => {
1725
+ if (s.hidden) return s;
1726
+ const l = n.get(s.field);
1727
+ return l ? l.col : s;
1703
1728
  });
1704
- this._columns = s;
1729
+ this._columns = i;
1705
1730
  }
1706
1731
  }
1707
1732
  }
1708
1733
  /** Execute all plugin afterRender hooks */
1709
- #m() {
1734
+ #w() {
1710
1735
  this.#t?.afterRender();
1711
1736
  }
1712
1737
  /** Recompute row model via plugin hooks (grouping, tree, filtering, etc.). */
1713
- #T() {
1738
+ #x() {
1714
1739
  j(this);
1715
1740
  const e = Array.isArray(this.#l) ? [...this.#l] : [], t = this.#t?.processRows(e) ?? e;
1716
1741
  this._rows = t;
@@ -1733,75 +1758,75 @@ class q extends HTMLElement {
1733
1758
  * - `_columns` is NOT set here (done by #getColumnConfiguration + #processColumns)
1734
1759
  * - Plugins receive config via their attach() method
1735
1760
  */
1736
- #h() {
1737
- const e = this.#g ? { ...this.#g } : {};
1761
+ #u() {
1762
+ const e = this.#p ? { ...this.#p } : {};
1738
1763
  let t = Array.isArray(e.columns) ? [...e.columns] : [];
1739
- const n = (this.__lightDomColumnsCache || []).map((s) => ({
1740
- ...s
1764
+ const n = (this.__lightDomColumnsCache || []).map((i) => ({
1765
+ ...i
1741
1766
  }));
1742
1767
  if (n.length) {
1743
- const s = {};
1744
- t.forEach((i) => s[i.field] = i), n.forEach((i) => {
1745
- const l = s[i.field];
1746
- l ? (i.header && !l.header && (l.header = i.header), i.type && !l.type && (l.type = i.type), l.sortable = l.sortable || i.sortable, i.resizable && (l.resizable = !0), i.editable && (l.editable = !0)) : (t.push(i), s[i.field] = i);
1768
+ const i = {};
1769
+ t.forEach((s) => i[s.field] = s), n.forEach((s) => {
1770
+ const l = i[s.field];
1771
+ l ? (s.header && !l.header && (l.header = s.header), s.type && !l.type && (l.type = s.type), l.sortable = l.sortable || s.sortable, s.resizable && (l.resizable = !0), s.editable && (l.editable = !0)) : (t.push(s), i[s.field] = s);
1747
1772
  });
1748
1773
  }
1749
1774
  if (this.#r && this.#r.length && (t = [...this.#r]), (!t || t.length === 0) && this._rows.length && (t = ce(this._rows).columns), t.length) {
1750
1775
  t.forEach((l) => {
1751
1776
  l.sortable === void 0 && (l.sortable = !0), l.resizable === void 0 && (l.resizable = !0);
1752
1777
  });
1753
- const s = this.#o.columns;
1754
- s?.some((l) => l.__compiledView || l.__compiledEditor) ? e.columns = s : e.columns = t;
1778
+ const i = this.#n.columns;
1779
+ i?.some((l) => l.__compiledView || l.__compiledEditor) ? e.columns = i : e.columns = t;
1755
1780
  } else {
1756
- const s = this.#o.columns;
1757
- s?.some((i) => i.__compiledView || i.__compiledEditor) && (e.columns = s);
1781
+ const i = this.#n.columns;
1782
+ i?.some((s) => s.__compiledView || s.__compiledEditor) && (e.columns = i);
1758
1783
  }
1759
- this.#C && (e.fitMode = this.#C), e.fitMode || (e.fitMode = "stretch"), this.#y && (e.editOn = this.#y), e.columnState && !this.#d && (this.#d = e.columnState), this.#o = e, e.fitMode === "fixed" && this._columns.forEach((s) => {
1760
- s.width == null && (s.width = 80);
1784
+ this.#g && (e.fitMode = this.#g), e.fitMode || (e.fitMode = "stretch"), this.#m && (e.editOn = this.#m), e.columnState && !this.#h && (this.#h = e.columnState), this.#n = e, e.fitMode === "fixed" && this._columns.forEach((i) => {
1785
+ i.width == null && (i.width = 80);
1761
1786
  });
1762
1787
  }
1763
1788
  // ---------------- Delegate Wrappers ----------------
1764
1789
  #M(e, t, n = this.__rowRenderEpoch) {
1765
- this.#k || (this.#k = (s, i, l) => this.#t?.renderRow(s, i, l) ?? !1), qe(this, e, t, n, this.#k);
1790
+ this.#L || (this.#L = (i, s, l) => this.#t?.renderRow(i, s, l) ?? !1), qe(this, e, t, n, this.#L);
1766
1791
  }
1767
- #te(e, t) {
1792
+ #ee(e, t) {
1768
1793
  T(this, e, t);
1769
1794
  }
1770
- #D(e, t) {
1795
+ #O(e, t) {
1771
1796
  Ie(this, e, t);
1772
1797
  }
1773
1798
  // ---------------- Core Helpers ----------------
1774
- #c() {
1799
+ #d() {
1775
1800
  if (!this.isConnected || !this.headerRowEl || !this.bodyEl)
1776
1801
  return;
1777
- const e = this.#g?.columns || this.#r || [];
1802
+ const e = this.#p?.columns || this.#r || [];
1778
1803
  if (e.length) {
1779
- const n = new Map(this._columns.filter((i) => i.hidden).map((i) => [i.field, !0])), s = e.map((i) => ({
1780
- ...i,
1781
- hidden: n.get(i.field) ?? i.hidden
1804
+ const n = new Map(this._columns.filter((s) => s.hidden).map((s) => [s.field, !0])), i = e.map((s) => ({
1805
+ ...s,
1806
+ hidden: n.get(s.field) ?? s.hidden
1782
1807
  }));
1783
- this._columns = s;
1808
+ this._columns = i;
1784
1809
  }
1785
- if (this.#ee(), this.#h(), this.#B(), this.#T(), this.#O(), this.#d) {
1786
- const n = this.#d;
1787
- this.#d = void 0, this.#W(n);
1810
+ if (this.#Q(), this.#u(), this.#I(), this.#x(), this.#P(), this.#h) {
1811
+ const n = this.#h;
1812
+ this.#h = void 0, this.#K(n);
1788
1813
  }
1789
- this.#x(), this.updateTemplate(), this.refreshVirtualWindow(!0), this.#o.fitMode === "fixed" && !this.__didInitialAutoSize && requestAnimationFrame(() => this.#K()), this.bodyEl && (this.bodyEl.style.display = "", this.bodyEl.style.gridTemplateColumns = ""), queueMicrotask(() => this.#m());
1814
+ this.#S(), this.updateTemplate(), this.refreshVirtualWindow(!0), this.#n.fitMode === "fixed" && !this.__didInitialAutoSize && requestAnimationFrame(() => this.#$()), this.bodyEl && (this.bodyEl.style.display = "", this.bodyEl.style.gridTemplateColumns = ""), queueMicrotask(() => this.#w());
1790
1815
  }
1791
1816
  /** Internal method to apply column state without triggering setup loop */
1792
- #W(e) {
1793
- const t = this.#o.columns ?? [], n = this.#t?.getAll() ?? [];
1817
+ #K(e) {
1818
+ const t = this.#n.columns ?? [], n = this.#t?.getAll() ?? [];
1794
1819
  ge(this, e, t, n);
1795
- for (const s of e.columns) {
1796
- const i = t.find((l) => l.field === s.field);
1797
- i && (i.hidden = !s.visible);
1820
+ for (const i of e.columns) {
1821
+ const s = t.find((l) => l.field === i.field);
1822
+ s && (s.hidden = !i.visible);
1798
1823
  }
1799
1824
  }
1800
- #oe() {
1825
+ #te() {
1801
1826
  return this._rows.length <= this.virtualization.bypassThreshold;
1802
1827
  }
1803
- #ne(e) {
1804
- if (this.refreshVirtualWindow(!1), this.#t?.onScrollRender(), this.#R) {
1828
+ #oe(e) {
1829
+ if (this.refreshVirtualWindow(!1), this.#t?.onScrollRender(), this.#C) {
1805
1830
  const t = this.virtualization.container, n = {
1806
1831
  scrollTop: e,
1807
1832
  scrollLeft: t?.scrollLeft ?? 0,
@@ -1815,7 +1840,7 @@ class q extends HTMLElement {
1815
1840
  }
1816
1841
  }
1817
1842
  findHeaderRow() {
1818
- return this.#n.querySelector(".header-row");
1843
+ return this.#o.querySelector(".header-row");
1819
1844
  }
1820
1845
  findRenderedRowElement(e) {
1821
1846
  return Array.from(this.bodyEl.querySelectorAll(".data-grid-row")).find((t) => {
@@ -1827,16 +1852,16 @@ class q extends HTMLElement {
1827
1852
  * Dispatch a cell click event to the plugin system.
1828
1853
  * Returns true if any plugin handled the event.
1829
1854
  */
1830
- dispatchCellClick(e, t, n, s) {
1831
- const i = this._rows[t], l = this._columns[n];
1832
- if (!i || !l) return !1;
1855
+ dispatchCellClick(e, t, n, i) {
1856
+ const s = this._rows[t], l = this._columns[n];
1857
+ if (!s || !l) return !1;
1833
1858
  const r = {
1834
- row: i,
1859
+ row: s,
1835
1860
  rowIndex: t,
1836
1861
  colIndex: n,
1837
1862
  field: l.field,
1838
- value: i[l.field],
1839
- cellEl: s,
1863
+ value: s[l.field],
1864
+ cellEl: i,
1840
1865
  originalEvent: e
1841
1866
  };
1842
1867
  return this.#t?.onCellClick(r) ?? !1;
@@ -1846,16 +1871,16 @@ class q extends HTMLElement {
1846
1871
  * Returns true if any plugin handled the event.
1847
1872
  */
1848
1873
  dispatchHeaderClick(e, t, n) {
1849
- const s = this._columns[t];
1850
- if (!s) return !1;
1851
- const i = {
1874
+ const i = this._columns[t];
1875
+ if (!i) return !1;
1876
+ const s = {
1852
1877
  colIndex: t,
1853
- field: s.field,
1854
- column: s,
1878
+ field: i.field,
1879
+ column: i,
1855
1880
  headerEl: n,
1856
1881
  originalEvent: e
1857
1882
  };
1858
- return this.#t?.onHeaderClick(i) ?? !1;
1883
+ return this.#t?.onHeaderClick(s) ?? !1;
1859
1884
  }
1860
1885
  /**
1861
1886
  * Dispatch a keyboard event to the plugin system.
@@ -1868,25 +1893,25 @@ class q extends HTMLElement {
1868
1893
  * Build a CellMouseEvent from a native MouseEvent.
1869
1894
  * Extracts cell/row information from the event target.
1870
1895
  */
1871
- #H(e, t) {
1896
+ #D(e, t) {
1872
1897
  let n = null;
1873
- const s = e.composedPath?.();
1874
- if (s && s.length > 0 ? n = s[0] : n = e.target, n && !this.#n.contains(n)) {
1875
- const d = this.#n.elementFromPoint(e.clientX, e.clientY);
1876
- d && (n = d);
1877
- }
1878
- const i = n?.closest?.("[data-col]"), l = n?.closest?.(".data-grid-row"), r = n?.closest?.(".header-row");
1879
- let a, f, p, w, h, c;
1880
- return i && (a = parseInt(i.getAttribute("data-row") ?? "-1", 10), f = parseInt(i.getAttribute("data-col") ?? "-1", 10), a >= 0 && f >= 0 && (p = this._rows[a], c = this._columns[f], w = c?.field, h = p && w ? p[w] : void 0)), {
1898
+ const i = e.composedPath?.();
1899
+ if (i && i.length > 0 ? n = i[0] : n = e.target, n && !this.#o.contains(n)) {
1900
+ const h = this.#o.elementFromPoint(e.clientX, e.clientY);
1901
+ h && (n = h);
1902
+ }
1903
+ const s = n?.closest?.("[data-col]"), l = n?.closest?.(".data-grid-row"), r = n?.closest?.(".header-row");
1904
+ let a, f, p, w, u, c;
1905
+ return s && (a = parseInt(s.getAttribute("data-row") ?? "-1", 10), f = parseInt(s.getAttribute("data-col") ?? "-1", 10), a >= 0 && f >= 0 && (p = this._rows[a], c = this._columns[f], w = c?.field, u = p && w ? p[w] : void 0)), {
1881
1906
  type: t,
1882
1907
  row: p,
1883
1908
  rowIndex: a !== void 0 && a >= 0 ? a : void 0,
1884
1909
  colIndex: f !== void 0 && f >= 0 ? f : void 0,
1885
1910
  field: w,
1886
- value: h,
1911
+ value: u,
1887
1912
  column: c,
1888
1913
  originalEvent: e,
1889
- cellElement: i ?? void 0,
1914
+ cellElement: s ?? void 0,
1890
1915
  rowElement: l ?? void 0,
1891
1916
  isHeader: !!r,
1892
1917
  cell: a !== void 0 && f !== void 0 && a >= 0 && f >= 0 ? { row: a, col: f } : void 0
@@ -1895,25 +1920,25 @@ class q extends HTMLElement {
1895
1920
  /**
1896
1921
  * Handle mousedown events and dispatch to plugin system.
1897
1922
  */
1898
- #ie(e) {
1899
- const t = this.#H(e, "mousedown");
1900
- (this.#t?.onCellMouseDown(t) ?? !1) && (this.#_ = !0);
1923
+ #ne(e) {
1924
+ const t = this.#D(e, "mousedown");
1925
+ (this.#t?.onCellMouseDown(t) ?? !1) && (this.#y = !0);
1901
1926
  }
1902
1927
  /**
1903
1928
  * Handle mousemove events (only when dragging).
1904
1929
  */
1905
- #se(e) {
1906
- if (!this.#_) return;
1907
- const t = this.#H(e, "mousemove");
1930
+ #ie(e) {
1931
+ if (!this.#y) return;
1932
+ const t = this.#D(e, "mousemove");
1908
1933
  this.#t?.onCellMouseMove(t);
1909
1934
  }
1910
1935
  /**
1911
1936
  * Handle mouseup events.
1912
1937
  */
1913
- #le(e) {
1914
- if (!this.#_) return;
1915
- const t = this.#H(e, "mouseup");
1916
- this.#t?.onCellMouseUp(t), this.#_ = !1;
1938
+ #se(e) {
1939
+ if (!this.#y) return;
1940
+ const t = this.#D(e, "mouseup");
1941
+ this.#t?.onCellMouseUp(t), this.#y = !1;
1917
1942
  }
1918
1943
  // API consumed by internal utils (rows.ts)
1919
1944
  get changedRows() {
@@ -1926,20 +1951,20 @@ class q extends HTMLElement {
1926
1951
  this._changedRowIndices.clear(), e || this.#s("changed-rows-reset", { rows: this.changedRows, indices: this.changedRowIndices }), this.rowPool.forEach((t) => t.classList.remove("changed"));
1927
1952
  }
1928
1953
  async beginBulkEdit(e) {
1929
- this.#te(e, this._rows[e]);
1954
+ this.#ee(e, this._rows[e]);
1930
1955
  }
1931
1956
  async commitActiveRowEdit() {
1932
- this.activeEditRows !== -1 && this.#D(this.activeEditRows, !1);
1957
+ this.activeEditRows !== -1 && this.#O(this.activeEditRows, !1);
1933
1958
  }
1934
1959
  async ready() {
1935
- return this.#z;
1960
+ return this.#H;
1936
1961
  }
1937
1962
  async forceLayout() {
1938
- this.#c(), await new Promise((e) => requestAnimationFrame(() => requestAnimationFrame(e)));
1963
+ this.#d(), await new Promise((e) => requestAnimationFrame(() => requestAnimationFrame(e)));
1939
1964
  }
1940
1965
  /** Public method: returns a frozen snapshot of the merged effective configuration */
1941
1966
  async getConfig() {
1942
- return Object.freeze({ ...this.#o || {} });
1967
+ return Object.freeze({ ...this.#n || {} });
1943
1968
  }
1944
1969
  // ---------------- Column Visibility API ----------------
1945
1970
  /**
@@ -1949,15 +1974,15 @@ class q extends HTMLElement {
1949
1974
  * @returns True if visibility was changed, false if column not found or locked
1950
1975
  */
1951
1976
  setColumnVisible(e, t) {
1952
- const n = this.#o.columns, s = n?.find((r) => r.field === e);
1953
- if (!s || !t && s.lockVisible || !t && (n ?? []).filter((a) => !a.hidden && a.field !== e).length === 0)
1977
+ const n = this.#n.columns, i = n?.find((r) => r.field === e);
1978
+ if (!i || !t && i.lockVisible || !t && (n ?? []).filter((a) => !a.hidden && a.field !== e).length === 0)
1954
1979
  return !1;
1955
- const i = !!s.hidden, l = !t;
1956
- return i !== l ? (s.hidden = l, this.#s("column-visibility", {
1980
+ const s = !!i.hidden, l = !t;
1981
+ return s !== l ? (i.hidden = l, this.#s("column-visibility", {
1957
1982
  field: e,
1958
1983
  visible: t,
1959
1984
  visibleColumns: (n ?? []).filter((r) => !r.hidden).map((r) => r.field)
1960
- }), this.rowPool.length = 0, this.bodyEl && (this.bodyEl.innerHTML = ""), this.__rowRenderEpoch++, this.#c(), this.requestStateChange(), !0) : !1;
1985
+ }), this.rowPool.length = 0, this.bodyEl && (this.bodyEl.innerHTML = ""), this.__rowRenderEpoch++, this.#d(), this.requestStateChange(), !0) : !1;
1961
1986
  }
1962
1987
  /**
1963
1988
  * Toggle the visibility of a column.
@@ -1965,8 +1990,8 @@ class q extends HTMLElement {
1965
1990
  * @returns True if visibility was toggled, false if column not found or locked
1966
1991
  */
1967
1992
  toggleColumnVisibility(e) {
1968
- const s = !!this.#o.columns?.find((i) => i.field === e)?.hidden;
1969
- return this.setColumnVisible(e, s);
1993
+ const i = !!this.#n.columns?.find((s) => s.field === e)?.hidden;
1994
+ return this.setColumnVisible(e, i);
1970
1995
  }
1971
1996
  /**
1972
1997
  * Check if a column is currently visible.
@@ -1974,19 +1999,19 @@ class q extends HTMLElement {
1974
1999
  * @returns True if visible, false if hidden or not found
1975
2000
  */
1976
2001
  isColumnVisible(e) {
1977
- const n = this.#o.columns?.find((s) => s.field === e);
2002
+ const n = this.#n.columns?.find((i) => i.field === e);
1978
2003
  return n ? !n.hidden : !1;
1979
2004
  }
1980
2005
  /**
1981
2006
  * Show all columns.
1982
2007
  */
1983
2008
  showAllColumns() {
1984
- const e = this.#o.columns;
2009
+ const e = this.#n.columns;
1985
2010
  e?.some((n) => n.hidden) && (e?.forEach((n) => {
1986
2011
  n.hidden = !1;
1987
2012
  }), this.#s("column-visibility", {
1988
2013
  visibleColumns: (e ?? []).map((n) => n.field)
1989
- }), this.rowPool.length = 0, this.bodyEl && (this.bodyEl.innerHTML = ""), this.__rowRenderEpoch++, this.#c(), this.requestStateChange());
2014
+ }), this.rowPool.length = 0, this.bodyEl && (this.bodyEl.innerHTML = ""), this.__rowRenderEpoch++, this.#d(), this.requestStateChange());
1990
2015
  }
1991
2016
  /**
1992
2017
  * Get list of all column fields (including hidden).
@@ -1995,7 +2020,7 @@ class q extends HTMLElement {
1995
2020
  * @returns Array of all field names with their visibility status
1996
2021
  */
1997
2022
  getAllColumns() {
1998
- return (this.#o.columns ?? []).map((t) => ({
2023
+ return (this.#n.columns ?? []).map((t) => ({
1999
2024
  field: t.field,
2000
2025
  header: t.header || t.field,
2001
2026
  visible: !t.hidden,
@@ -2009,14 +2034,14 @@ class q extends HTMLElement {
2009
2034
  */
2010
2035
  setColumnOrder(e) {
2011
2036
  if (!e.length) return;
2012
- const t = new Map(this._columns.map((s) => [s.field, s])), n = [];
2013
- for (const s of e) {
2014
- const i = t.get(s);
2015
- i && (n.push(i), t.delete(s));
2037
+ const t = new Map(this._columns.map((i) => [i.field, i])), n = [];
2038
+ for (const i of e) {
2039
+ const s = t.get(i);
2040
+ s && (n.push(s), t.delete(i));
2016
2041
  }
2017
- for (const s of t.values())
2018
- n.push(s);
2019
- this._columns = n, this.#x(), this.updateTemplate(), this.refreshVirtualWindow(!0);
2042
+ for (const i of t.values())
2043
+ n.push(i);
2044
+ this._columns = n, this.#S(), this.updateTemplate(), this.refreshVirtualWindow(!0);
2020
2045
  }
2021
2046
  /**
2022
2047
  * Get the current column order as an array of field names.
@@ -2039,7 +2064,7 @@ class q extends HTMLElement {
2039
2064
  * Use this to restore previously saved column state.
2040
2065
  */
2041
2066
  set columnState(e) {
2042
- e && (this.#d = e, this.#i && this.#re(e));
2067
+ e && (this.#h = e, this.#i && this.#le(e));
2043
2068
  }
2044
2069
  /**
2045
2070
  * Get the current column state.
@@ -2050,10 +2075,10 @@ class q extends HTMLElement {
2050
2075
  /**
2051
2076
  * Apply column state internally.
2052
2077
  */
2053
- #re(e) {
2054
- (this.#o.columns ?? []).forEach((n) => {
2078
+ #le(e) {
2079
+ (this.#n.columns ?? []).forEach((n) => {
2055
2080
  n.hidden = !1;
2056
- }), this.#W(e), this.#c();
2081
+ }), this.#K(e), this.#d();
2057
2082
  }
2058
2083
  /**
2059
2084
  * Request a state change event to be emitted.
@@ -2062,26 +2087,26 @@ class q extends HTMLElement {
2062
2087
  * The event is debounced to avoid excessive events during drag operations.
2063
2088
  */
2064
2089
  requestStateChange() {
2065
- this.#P || (this.#P = me(
2090
+ this.#k || (this.#k = me(
2066
2091
  this,
2067
2092
  () => this.#t?.getAll() ?? [],
2068
2093
  (e) => this.#s("column-state-change", e)
2069
- )), this.#P();
2094
+ )), this.#k();
2070
2095
  }
2071
2096
  /**
2072
2097
  * Reset column state to initial configuration.
2073
2098
  * Clears all user modifications (order, width, visibility, sort).
2074
2099
  */
2075
2100
  resetColumnState() {
2076
- this.#d = void 0, (this.#o.columns ?? []).forEach((n) => {
2101
+ this.#h = void 0, (this.#n.columns ?? []).forEach((n) => {
2077
2102
  n.hidden = !1;
2078
- }), this.sortState = null, this.__originalOrder = [], this.#h(), this.#c();
2103
+ }), this.sortState = null, this.__originalOrder = [], this.#u(), this.#d();
2079
2104
  const t = this.#t?.getAll() ?? [];
2080
2105
  for (const n of t)
2081
2106
  if (n.applyColumnState)
2082
- for (const s of this._columns)
2083
- n.applyColumnState(s.field, {
2084
- field: s.field,
2107
+ for (const i of this._columns)
2108
+ n.applyColumnState(i.field, {
2109
+ field: i.field,
2085
2110
  order: 0,
2086
2111
  visible: !0
2087
2112
  });
@@ -2103,7 +2128,7 @@ class q extends HTMLElement {
2103
2128
  console.warn(`[tbw-grid] Tool panel "${e}" not found`);
2104
2129
  return;
2105
2130
  }
2106
- this.#e.activePanel && this.#e.activePanel !== e && this.closeToolPanel(), this.#e.activePanel = e, oe(this.#n, this.#e), ne(this.#n, this.#e), Ue(this.#n, this.#e), this.#s("tool-panel-open", { id: e });
2131
+ this.#e.activePanel && this.#e.activePanel !== e && this.closeToolPanel(), this.#e.activePanel = e, oe(this.#o, this.#e), ne(this.#o, this.#e), Ue(this.#o, this.#e), this.#s("tool-panel-open", { id: e });
2107
2132
  }
2108
2133
  /**
2109
2134
  * Close the currently open tool panel.
@@ -2111,7 +2136,7 @@ class q extends HTMLElement {
2111
2136
  closeToolPanel() {
2112
2137
  if (!this.#e.activePanel) return;
2113
2138
  const e = this.#e.activePanel, t = this.#e.toolPanels.get(e);
2114
- this.#e.activePanelCleanup && (this.#e.activePanelCleanup(), this.#e.activePanelCleanup = null), t?.onClose?.(), this.#e.activePanel = null, oe(this.#n, this.#e), ne(this.#n, this.#e), this.#s("tool-panel-close", { id: e });
2139
+ this.#e.activePanelCleanup && (this.#e.activePanelCleanup(), this.#e.activePanelCleanup = null), t?.onClose?.(), this.#e.activePanel = null, oe(this.#o, this.#e), ne(this.#o, this.#e), this.#s("tool-panel-close", { id: e });
2115
2140
  }
2116
2141
  /**
2117
2142
  * Toggle a tool panel open/closed.
@@ -2133,13 +2158,13 @@ class q extends HTMLElement {
2133
2158
  console.warn(`[tbw-grid] Tool panel "${e.id}" already registered`);
2134
2159
  return;
2135
2160
  }
2136
- this.#e.toolPanels.set(e.id, e), this.#a && this.#v();
2161
+ this.#e.toolPanels.set(e.id, e), this.#c && this.#b();
2137
2162
  }
2138
2163
  /**
2139
2164
  * Unregister a custom tool panel.
2140
2165
  */
2141
2166
  unregisterToolPanel(e) {
2142
- this.#e.activePanel === e && this.closeToolPanel(), this.#e.toolPanels.delete(e), this.#a && this.#v();
2167
+ this.#e.activePanel === e && this.closeToolPanel(), this.#e.toolPanels.delete(e), this.#c && this.#b();
2143
2168
  }
2144
2169
  /**
2145
2170
  * Get registered header content definitions.
@@ -2155,20 +2180,20 @@ class q extends HTMLElement {
2155
2180
  console.warn(`[tbw-grid] Header content "${e.id}" already registered`);
2156
2181
  return;
2157
2182
  }
2158
- this.#e.headerContents.set(e.id, e), this.#a && te(this.#n, this.#e);
2183
+ this.#e.headerContents.set(e.id, e), this.#c && te(this.#o, this.#e);
2159
2184
  }
2160
2185
  /**
2161
2186
  * Unregister custom header content.
2162
2187
  */
2163
2188
  unregisterHeaderContent(e) {
2164
2189
  const t = this.#e.headerContentCleanups.get(e);
2165
- t && (t(), this.#e.headerContentCleanups.delete(e)), this.#e.headerContents.get(e)?.onDestroy?.(), this.#e.headerContents.delete(e), this.#n.querySelector(`[data-header-content="${e}"]`)?.remove();
2190
+ t && (t(), this.#e.headerContentCleanups.delete(e)), this.#e.headerContents.get(e)?.onDestroy?.(), this.#e.headerContents.delete(e), this.#o.querySelector(`[data-header-content="${e}"]`)?.remove();
2166
2191
  }
2167
2192
  /**
2168
2193
  * Get all registered toolbar buttons.
2169
2194
  */
2170
2195
  getToolbarButtons() {
2171
- return Xe(this.#o?.shell, this.#e);
2196
+ return Xe(this.#n?.shell, this.#e);
2172
2197
  }
2173
2198
  /**
2174
2199
  * Register a custom toolbar button programmatically.
@@ -2178,14 +2203,14 @@ class q extends HTMLElement {
2178
2203
  console.warn(`[tbw-grid] Toolbar button "${e.id}" already registered`);
2179
2204
  return;
2180
2205
  }
2181
- this.#e.toolbarButtons.set(e.id, e), this.#a && this.#v();
2206
+ this.#e.toolbarButtons.set(e.id, e), this.#c && this.#b();
2182
2207
  }
2183
2208
  /**
2184
2209
  * Unregister a custom toolbar button.
2185
2210
  */
2186
2211
  unregisterToolbarButton(e) {
2187
2212
  const t = this.#e.toolbarButtonCleanups.get(e);
2188
- t && (t(), this.#e.toolbarButtonCleanups.delete(e)), this.#e.toolbarButtons.delete(e), this.#a && this.#v();
2213
+ t && (t(), this.#e.toolbarButtonCleanups.delete(e)), this.#e.toolbarButtons.delete(e), this.#c && this.#b();
2189
2214
  }
2190
2215
  /**
2191
2216
  * Enable/disable a toolbar button by ID.
@@ -2193,21 +2218,21 @@ class q extends HTMLElement {
2193
2218
  setToolbarButtonDisabled(e, t) {
2194
2219
  const n = this.#e.toolbarButtons.get(e);
2195
2220
  n && (n.disabled = t);
2196
- const s = this.#n.querySelector(`[data-btn="${e}"]`);
2197
- s && (s.disabled = t);
2221
+ const i = this.#o.querySelector(`[data-btn="${e}"]`);
2222
+ i && (i.disabled = t);
2198
2223
  }
2199
2224
  /**
2200
2225
  * Re-parse light DOM shell elements and refresh shell header.
2201
2226
  * Call this after dynamically modifying <tbw-grid-header> children.
2202
2227
  */
2203
2228
  refreshShellHeader() {
2204
- this.#v();
2229
+ this.#b();
2205
2230
  }
2206
2231
  /**
2207
2232
  * Internal shell header refresh.
2208
2233
  */
2209
- #v() {
2210
- ee(this, this.#e), this.#F(), this.#$();
2234
+ #b() {
2235
+ ee(this, this.#e), this.#W(), this.#B();
2211
2236
  }
2212
2237
  // ---------------- Virtual Window ----------------
2213
2238
  /**
@@ -2218,26 +2243,26 @@ class q extends HTMLElement {
2218
2243
  if (!this.bodyEl) return;
2219
2244
  const t = this._rows.length;
2220
2245
  if (!this.virtualization.enabled) {
2221
- this.#M(0, t), this.#m();
2246
+ this.#M(0, t), this.#w();
2222
2247
  return;
2223
2248
  }
2224
- if (this.#oe()) {
2225
- this.virtualization.start = 0, this.virtualization.end = t, this.bodyEl.style.transform = "translateY(0px)", this.#M(0, t, this.__rowRenderEpoch), this.virtualization.totalHeightEl && (this.virtualization.totalHeightEl.style.height = `${t * this.virtualization.rowHeight}px`), this.setAttribute("aria-rowcount", String(t)), this.setAttribute("aria-colcount", String(this.visibleColumns.length)), this.#m();
2249
+ if (this.#te()) {
2250
+ this.virtualization.start = 0, this.virtualization.end = t, this.bodyEl.style.transform = "translateY(0px)", this.#M(0, t, this.__rowRenderEpoch), this.virtualization.totalHeightEl && (this.virtualization.totalHeightEl.style.height = `${t * this.virtualization.rowHeight}px`), this.setAttribute("aria-rowcount", String(t)), this.setAttribute("aria-colcount", String(this.visibleColumns.length)), this.#w();
2226
2251
  return;
2227
2252
  }
2228
- const n = this.virtualization.container ?? this, i = (this.virtualization.viewportEl ?? n).clientHeight, l = this.virtualization.rowHeight, r = n.scrollTop;
2253
+ const n = this.virtualization.container ?? this, s = (this.virtualization.viewportEl ?? n).clientHeight, l = this.virtualization.rowHeight, r = n.scrollTop;
2229
2254
  let a = Math.floor(r / l);
2230
2255
  a < 0 && (a = 0);
2231
- const f = Math.ceil(i / l) + 2;
2256
+ const f = Math.ceil(s / l) + 2;
2232
2257
  let p = a + f;
2233
2258
  p > t && (p = t), this.virtualization.start = a, this.virtualization.end = p, this.virtualization.totalHeightEl && (this.virtualization.totalHeightEl.style.height = `${t * l}px`);
2234
2259
  const w = -(r % l);
2235
- this.bodyEl.style.transform = `translateY(${w}px)`, this.#M(a, p, e ? ++this.__rowRenderEpoch : this.__rowRenderEpoch), this.setAttribute("aria-rowcount", String(t)), this.setAttribute("aria-colcount", String(this.visibleColumns.length)), e && this.#m();
2260
+ this.bodyEl.style.transform = `translateY(${w}px)`, this.#M(a, p, e ? ++this.__rowRenderEpoch : this.__rowRenderEpoch), this.setAttribute("aria-rowcount", String(t)), this.setAttribute("aria-colcount", String(this.visibleColumns.length)), e && this.#w();
2236
2261
  }
2237
2262
  // ---------------- Render ----------------
2238
- #F() {
2263
+ #W() {
2239
2264
  ee(this, this.#e);
2240
- const e = this.#o?.shell, t = Ke(e, this.#e), n = `
2265
+ const e = this.#n?.shell, t = Ke(e, this.#e), n = `
2241
2266
  <div class="tbw-scroll-area">
2242
2267
  <div class="rows-body-wrapper">
2243
2268
  <div class="rows-body">
@@ -2257,15 +2282,15 @@ class q extends HTMLElement {
2257
2282
  </div>
2258
2283
  `;
2259
2284
  if (t) {
2260
- const s = We(e, this.#e), i = Fe(e, this.#e, n);
2261
- this.#n.innerHTML = `
2285
+ const i = We(e, this.#e), s = Fe(e, this.#e, n);
2286
+ this.#o.innerHTML = `
2262
2287
  <div class="tbw-grid-root has-shell">
2263
- ${s}
2264
2288
  ${i}
2289
+ ${s}
2265
2290
  </div>
2266
- `, this.#ae(), this.#a = !0;
2291
+ `, this.#re(), this.#c = !0;
2267
2292
  } else
2268
- this.#n.innerHTML = `
2293
+ this.#o.innerHTML = `
2269
2294
  <div class="tbw-grid-root">
2270
2295
  <div class="tbw-grid-content">
2271
2296
  ${n}
@@ -2276,24 +2301,24 @@ class q extends HTMLElement {
2276
2301
  /**
2277
2302
  * Set up shell event listeners after render.
2278
2303
  */
2279
- #ae() {
2280
- Ve(this.#n, this.#o?.shell, this.#e, {
2304
+ #re() {
2305
+ Ve(this.#o, this.#n?.shell, this.#e, {
2281
2306
  onPanelToggle: (e) => this.toggleToolPanel(e),
2282
2307
  onPanelClose: () => this.closeToolPanel(),
2283
- onToolbarButtonClick: (e) => this.#ce(e)
2308
+ onToolbarButtonClick: (e) => this.#ae(e)
2284
2309
  });
2285
2310
  }
2286
2311
  /**
2287
2312
  * Handle toolbar button click (for config buttons with action).
2288
2313
  */
2289
- #ce(e) {
2290
- const n = (this.#o?.shell?.header?.toolbarButtons ?? []).find((i) => i.id === e);
2314
+ #ae(e) {
2315
+ const n = (this.#n?.shell?.header?.toolbarButtons ?? []).find((s) => s.id === e);
2291
2316
  if (n?.action) {
2292
2317
  n.action();
2293
2318
  return;
2294
2319
  }
2295
- const s = this.#e.toolbarButtons.get(e);
2296
- s?.action && s.action();
2320
+ const i = this.#e.toolbarButtons.get(e);
2321
+ i?.action && i.action();
2297
2322
  }
2298
2323
  }
2299
2324
  customElements.get(q.tagName) || customElements.define(q.tagName, q);
@@ -2396,6 +2421,26 @@ class ue {
2396
2421
  get shadowRoot() {
2397
2422
  return this.grid?.shadowRoot ?? null;
2398
2423
  }
2424
+ /**
2425
+ * Get the disconnect signal for event listener cleanup.
2426
+ * This signal is aborted when the grid disconnects from the DOM.
2427
+ * Use this when adding event listeners that should be cleaned up automatically.
2428
+ *
2429
+ * Best for:
2430
+ * - Document/window-level listeners added in attach()
2431
+ * - Listeners on the grid element itself
2432
+ * - Any listener that should persist across renders
2433
+ *
2434
+ * Not needed for:
2435
+ * - Listeners on elements created in afterRender() (removed with element)
2436
+ *
2437
+ * @example
2438
+ * element.addEventListener('click', handler, { signal: this.disconnectSignal });
2439
+ * document.addEventListener('keydown', handler, { signal: this.disconnectSignal });
2440
+ */
2441
+ get disconnectSignal() {
2442
+ return this.grid?.disconnectSignal;
2443
+ }
2399
2444
  /**
2400
2445
  * Log a warning message.
2401
2446
  */
@@ -2403,7 +2448,7 @@ class ue {
2403
2448
  console.warn(`[tbw-grid:${this.name}] ${e}`);
2404
2449
  }
2405
2450
  }
2406
- function z(o) {
2451
+ function N(o) {
2407
2452
  return {
2408
2453
  startRow: Math.min(o.startRow, o.endRow),
2409
2454
  startCol: Math.min(o.startCol, o.endCol),
@@ -2412,7 +2457,7 @@ function z(o) {
2412
2457
  };
2413
2458
  }
2414
2459
  function Ze(o) {
2415
- const e = z(o);
2460
+ const e = N(o);
2416
2461
  return {
2417
2462
  from: { row: e.startRow, col: e.startCol },
2418
2463
  to: { row: e.endRow, col: e.endCol }
@@ -2422,17 +2467,17 @@ function K(o) {
2422
2467
  return o.map(Ze);
2423
2468
  }
2424
2469
  function Je(o, e, t) {
2425
- const n = z(t);
2470
+ const n = N(t);
2426
2471
  return o >= n.startRow && o <= n.endRow && e >= n.startCol && e <= n.endCol;
2427
2472
  }
2428
2473
  function ie(o, e, t) {
2429
2474
  return t.some((n) => Je(o, e, n));
2430
2475
  }
2431
2476
  function Qe(o) {
2432
- const e = [], t = z(o);
2477
+ const e = [], t = N(o);
2433
2478
  for (let n = t.startRow; n <= t.endRow; n++)
2434
- for (let s = t.startCol; s <= t.endCol; s++)
2435
- e.push({ row: n, col: s });
2479
+ for (let i = t.startCol; i <= t.endCol; i++)
2480
+ e.push({ row: n, col: i });
2436
2481
  return e;
2437
2482
  }
2438
2483
  function et(o) {
@@ -2462,9 +2507,9 @@ function tt(o, e, t) {
2462
2507
  ]
2463
2508
  };
2464
2509
  if (o === "row" && e.selected.size > 0) {
2465
- const n = [...e.selected].map((s) => ({
2466
- from: { row: s, col: 0 },
2467
- to: { row: s, col: t - 1 }
2510
+ const n = [...e.selected].map((i) => ({
2511
+ from: { row: i, col: 0 },
2512
+ to: { row: i, col: t - 1 }
2468
2513
  }));
2469
2514
  return { mode: o, ranges: n };
2470
2515
  }
@@ -2496,13 +2541,13 @@ class st extends ue {
2496
2541
  }
2497
2542
  // ===== Event Handlers =====
2498
2543
  onCellClick(e) {
2499
- const { rowIndex: t, colIndex: n, originalEvent: s } = e, { mode: i } = this.config;
2500
- if (i === "cell")
2544
+ const { rowIndex: t, colIndex: n, originalEvent: i } = e, { mode: s } = this.config;
2545
+ if (s === "cell")
2501
2546
  return this.selectedCell = { row: t, col: n }, this.emit("selection-change", this.#i()), this.requestAfterRender(), !1;
2502
- if (i === "row")
2547
+ if (s === "row")
2503
2548
  return this.selected.clear(), this.selected.add(t), this.lastSelected = t, this.emit("selection-change", this.#i()), this.requestAfterRender(), !1;
2504
- if (i === "range") {
2505
- const l = s.shiftKey, r = s.ctrlKey || s.metaKey;
2549
+ if (s === "range") {
2550
+ const l = i.shiftKey, r = i.ctrlKey || i.metaKey;
2506
2551
  if (l && this.cellAnchor) {
2507
2552
  const a = se(this.cellAnchor, { row: t, col: n });
2508
2553
  r ? this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] = a : this.ranges.push(a) : this.ranges = [a], this.activeRange = a;
@@ -2532,15 +2577,15 @@ class st extends ue {
2532
2577
  if (e.key === "Escape")
2533
2578
  return t === "cell" ? this.selectedCell = null : t === "row" ? (this.selected.clear(), this.anchor = null) : t === "range" && (this.ranges = [], this.activeRange = null, this.cellAnchor = null), this.emit("selection-change", this.#i()), this.requestAfterRender(), !0;
2534
2579
  if (t === "range" && e.key === "a" && (e.ctrlKey || e.metaKey)) {
2535
- const n = this.rows.length, s = this.columns.length;
2536
- if (n > 0 && s > 0) {
2537
- const i = {
2580
+ const n = this.rows.length, i = this.columns.length;
2581
+ if (n > 0 && i > 0) {
2582
+ const s = {
2538
2583
  startRow: 0,
2539
2584
  startCol: 0,
2540
2585
  endRow: n - 1,
2541
- endCol: s - 1
2586
+ endCol: i - 1
2542
2587
  };
2543
- return this.ranges = [i], this.activeRange = i, this.emit("selection-change", this.#i()), this.requestAfterRender(), !0;
2588
+ return this.ranges = [s], this.activeRange = s, this.emit("selection-change", this.#i()), this.requestAfterRender(), !0;
2544
2589
  }
2545
2590
  }
2546
2591
  return !1;
@@ -2551,13 +2596,13 @@ class st extends ue {
2551
2596
  this.isDragging = !0;
2552
2597
  const t = e.rowIndex, n = e.colIndex;
2553
2598
  this.cellAnchor = { row: t, col: n }, e.originalEvent.ctrlKey || e.originalEvent.metaKey || (this.ranges = []);
2554
- const i = {
2599
+ const s = {
2555
2600
  startRow: t,
2556
2601
  startCol: n,
2557
2602
  endRow: t,
2558
2603
  endCol: n
2559
2604
  };
2560
- return this.ranges.push(i), this.activeRange = i, this.emit("selection-change", this.#i()), this.requestAfterRender(), !0;
2605
+ return this.ranges.push(s), this.activeRange = s, this.emit("selection-change", this.#i()), this.requestAfterRender(), !0;
2561
2606
  }
2562
2607
  onCellMouseMove(e) {
2563
2608
  if (this.config.mode !== "range" || !this.isDragging || !this.cellAnchor || e.rowIndex === void 0 || e.colIndex === void 0 || e.rowIndex < 0) return;
@@ -2572,40 +2617,40 @@ class st extends ue {
2572
2617
  * Apply selection classes to visible cells/rows.
2573
2618
  * Shared by afterRender and onScrollRender.
2574
2619
  */
2575
- #n() {
2620
+ #o() {
2576
2621
  const e = this.shadowRoot;
2577
2622
  if (!e) return;
2578
2623
  const { mode: t } = this.config;
2579
- e.querySelectorAll(".cell").forEach((i) => {
2580
- i.classList.remove("selected", "top", "bottom", "first", "last");
2624
+ e.querySelectorAll(".cell").forEach((s) => {
2625
+ s.classList.remove("selected", "top", "bottom", "first", "last");
2581
2626
  });
2582
- const s = e.querySelectorAll(".data-grid-row");
2583
- if (s.forEach((i) => {
2584
- i.classList.remove("selected", "row-focus");
2585
- }), t === "row" && s.forEach((i) => {
2586
- const l = i.querySelector(".cell[data-row]"), r = parseInt(l?.getAttribute("data-row") ?? "-1", 10);
2587
- r >= 0 && this.selected.has(r) && (i.classList.add("selected", "row-focus"), i.querySelectorAll(".cell-focus").forEach((a) => a.classList.remove("cell-focus")));
2627
+ const i = e.querySelectorAll(".data-grid-row");
2628
+ if (i.forEach((s) => {
2629
+ s.classList.remove("selected", "row-focus");
2630
+ }), t === "row" && i.forEach((s) => {
2631
+ const l = s.querySelector(".cell[data-row]"), r = parseInt(l?.getAttribute("data-row") ?? "-1", 10);
2632
+ r >= 0 && this.selected.has(r) && (s.classList.add("selected", "row-focus"), s.querySelectorAll(".cell-focus").forEach((a) => a.classList.remove("cell-focus")));
2588
2633
  }), t === "range" && this.ranges.length > 0) {
2589
- const i = this.activeRange ? z(this.activeRange) : null;
2634
+ const s = this.activeRange ? N(this.activeRange) : null;
2590
2635
  e.querySelectorAll(".cell[data-row][data-col]").forEach((r) => {
2591
2636
  const a = parseInt(r.getAttribute("data-row") ?? "-1", 10), f = parseInt(r.getAttribute("data-col") ?? "-1", 10);
2592
- a >= 0 && f >= 0 && ie(a, f, this.ranges) && (r.classList.add("selected"), r.classList.remove("cell-focus"), i && (a === i.startRow && r.classList.add("top"), a === i.endRow && r.classList.add("bottom"), f === i.startCol && r.classList.add("first"), f === i.endCol && r.classList.add("last")));
2637
+ a >= 0 && f >= 0 && ie(a, f, this.ranges) && (r.classList.add("selected"), r.classList.remove("cell-focus"), s && (a === s.startRow && r.classList.add("top"), a === s.endRow && r.classList.add("bottom"), f === s.startCol && r.classList.add("first"), f === s.endCol && r.classList.add("last")));
2593
2638
  });
2594
2639
  }
2595
- t === "cell" && this.selectedCell && e.querySelectorAll(".cell-focus").forEach((i) => i.classList.remove("cell-focus"));
2640
+ t === "cell" && this.selectedCell && e.querySelectorAll(".cell-focus").forEach((s) => s.classList.remove("cell-focus"));
2596
2641
  }
2597
2642
  afterRender() {
2598
2643
  const e = this.shadowRoot;
2599
2644
  if (!e) return;
2600
2645
  const t = e.children[0], { mode: n } = this.config;
2601
- this.grid.setAttribute("data-selection-mode", n), t && t.classList.toggle("selecting", this.isDragging), this.#n();
2646
+ this.grid.setAttribute("data-selection-mode", n), t && t.classList.toggle("selecting", this.isDragging), this.#o();
2602
2647
  }
2603
2648
  /**
2604
2649
  * Called after scroll-triggered row rendering.
2605
2650
  * Reapplies selection classes to recycled DOM elements.
2606
2651
  */
2607
2652
  onScrollRender() {
2608
- this.#n();
2653
+ this.#o();
2609
2654
  }
2610
2655
  // ===== Public API =====
2611
2656
  /**
@@ -2708,19 +2753,19 @@ class st extends ue {
2708
2753
  function G(o, e, t) {
2709
2754
  return o.id !== void 0 ? String(o.id) : t ? `${t}-${e}` : String(e);
2710
2755
  }
2711
- function fe(o, e, t, n = null, s = 0) {
2712
- const i = e.childrenField ?? "children", l = [];
2756
+ function fe(o, e, t, n = null, i = 0) {
2757
+ const s = e.childrenField ?? "children", l = [];
2713
2758
  for (let r = 0; r < o.length; r++) {
2714
- const a = o[r], f = G(a, r, n), p = a[i], w = Array.isArray(p) && p.length > 0, h = t.has(f);
2759
+ const a = o[r], f = G(a, r, n), p = a[s], w = Array.isArray(p) && p.length > 0, u = t.has(f);
2715
2760
  if (l.push({
2716
2761
  key: f,
2717
2762
  data: a,
2718
- depth: s,
2763
+ depth: i,
2719
2764
  hasChildren: w,
2720
- isExpanded: h,
2765
+ isExpanded: u,
2721
2766
  parentKey: n
2722
- }), w && h) {
2723
- const c = fe(p, e, t, f, s + 1);
2767
+ }), w && u) {
2768
+ const c = fe(p, e, t, f, i + 1);
2724
2769
  l.push(...c);
2725
2770
  }
2726
2771
  }
@@ -2731,29 +2776,29 @@ function le(o, e) {
2731
2776
  return t.has(e) ? t.delete(e) : t.add(e), t;
2732
2777
  }
2733
2778
  function W(o, e, t = null, n = 0) {
2734
- const s = e.childrenField ?? "children", i = /* @__PURE__ */ new Set();
2779
+ const i = e.childrenField ?? "children", s = /* @__PURE__ */ new Set();
2735
2780
  for (let l = 0; l < o.length; l++) {
2736
- const r = o[l], a = G(r, l, t), f = r[s];
2781
+ const r = o[l], a = G(r, l, t), f = r[i];
2737
2782
  if (Array.isArray(f) && f.length > 0) {
2738
- i.add(a);
2783
+ s.add(a);
2739
2784
  const p = W(f, e, a, n + 1);
2740
- for (const w of p) i.add(w);
2785
+ for (const w of p) s.add(w);
2741
2786
  }
2742
2787
  }
2743
- return i;
2788
+ return s;
2744
2789
  }
2745
2790
  function ot() {
2746
2791
  return /* @__PURE__ */ new Set();
2747
2792
  }
2748
- function pe(o, e, t, n = null, s = 0) {
2749
- const i = t.childrenField ?? "children";
2793
+ function pe(o, e, t, n = null, i = 0) {
2794
+ const s = t.childrenField ?? "children";
2750
2795
  for (let l = 0; l < o.length; l++) {
2751
2796
  const r = o[l], a = G(r, l, n);
2752
2797
  if (a === e)
2753
2798
  return [a];
2754
- const f = r[i];
2799
+ const f = r[s];
2755
2800
  if (Array.isArray(f) && f.length > 0) {
2756
- const p = pe(f, e, t, a, s + 1);
2801
+ const p = pe(f, e, t, a, i + 1);
2757
2802
  if (p)
2758
2803
  return [a, ...p];
2759
2804
  }
@@ -2761,12 +2806,12 @@ function pe(o, e, t, n = null, s = 0) {
2761
2806
  return null;
2762
2807
  }
2763
2808
  function nt(o, e, t, n) {
2764
- const s = pe(o, e, t);
2765
- if (!s) return n;
2766
- const i = new Set(n);
2767
- for (let l = 0; l < s.length - 1; l++)
2768
- i.add(s[l]);
2769
- return i;
2809
+ const i = pe(o, e, t);
2810
+ if (!i) return n;
2811
+ const s = new Set(n);
2812
+ for (let l = 0; l < i.length - 1; l++)
2813
+ s.add(i[l]);
2814
+ return s;
2770
2815
  }
2771
2816
  function re(o, e = "children") {
2772
2817
  if (!Array.isArray(o) || o.length === 0) return !1;
@@ -2840,28 +2885,31 @@ class lt extends ue {
2840
2885
  }
2841
2886
  processColumns(e) {
2842
2887
  if (this.flattenedRows.length === 0) return [...e];
2843
- const t = this.config.indentWidth ?? 20, n = this.config.showExpandIcons ?? !0, s = [...e];
2844
- if (s.length > 0) {
2845
- const i = { ...s[0] }, l = i.viewRenderer;
2846
- i.viewRenderer = (r) => {
2847
- const { value: a, row: f, column: p } = r, w = f.__treeDepth ?? 0, h = f.__treeHasChildren ?? !1, c = f.__treeExpanded ?? !1, d = document.createElement("span");
2848
- if (d.style.display = "flex", d.style.alignItems = "center", d.style.paddingLeft = `${w * t}px`, h && n) {
2849
- const b = document.createElement("span");
2850
- b.className = "tree-toggle", b.textContent = c ? "" : "▶", b.style.cursor = "pointer", b.style.marginRight = "4px", b.style.fontSize = "10px", b.setAttribute("data-tree-key", f.__treeKey), d.appendChild(b);
2888
+ const t = this.config.indentWidth ?? 20, n = this.config.showExpandIcons ?? !0, i = [...e];
2889
+ if (i.length > 0) {
2890
+ const s = { ...i[0] }, l = s.viewRenderer;
2891
+ if (l?.__treeWrapped)
2892
+ return i;
2893
+ const r = (a) => {
2894
+ const { value: f, row: p, column: w } = a, u = p.__treeDepth ?? 0, c = p.__treeHasChildren ?? !1, h = p.__treeExpanded ?? !1, d = document.createElement("span");
2895
+ if (d.style.display = "flex", d.style.alignItems = "center", d.style.paddingLeft = `${u * t}px`, c && n) {
2896
+ const m = document.createElement("span");
2897
+ m.className = "tree-toggle", m.textContent = h ? "▼" : "▶", m.style.cursor = "pointer", m.style.marginRight = "4px", m.style.fontSize = "10px", m.setAttribute("data-tree-key", p.__treeKey), d.appendChild(m);
2851
2898
  } else if (n) {
2852
- const b = document.createElement("span");
2853
- b.style.width = "14px", b.style.display = "inline-block", d.appendChild(b);
2899
+ const m = document.createElement("span");
2900
+ m.style.width = "14px", m.style.display = "inline-block", d.appendChild(m);
2854
2901
  }
2855
- const u = document.createElement("span");
2902
+ const g = document.createElement("span");
2856
2903
  if (l) {
2857
- const b = l(r);
2858
- b instanceof Node ? u.appendChild(b) : u.textContent = String(b ?? a ?? "");
2904
+ const m = l(a);
2905
+ m instanceof Node ? g.appendChild(m) : g.textContent = String(m ?? f ?? "");
2859
2906
  } else
2860
- u.textContent = String(a ?? "");
2861
- return d.appendChild(u), d;
2862
- }, s[0] = i;
2907
+ g.textContent = String(f ?? "");
2908
+ return d.appendChild(g), d;
2909
+ };
2910
+ r.__treeWrapped = !0, s.viewRenderer = r, i[0] = s;
2863
2911
  }
2864
- return s;
2912
+ return i;
2865
2913
  }
2866
2914
  // ===== Event Handlers =====
2867
2915
  onCellClick(e) {
@@ -2869,12 +2917,12 @@ class lt extends ue {
2869
2917
  if (!t?.classList.contains("tree-toggle")) return !1;
2870
2918
  const n = t.getAttribute("data-tree-key");
2871
2919
  if (!n) return !1;
2872
- const s = this.rowKeyMap.get(n);
2873
- return s ? (this.expandedKeys = le(this.expandedKeys, n), this.emit("tree-expand", {
2920
+ const i = this.rowKeyMap.get(n);
2921
+ return i ? (this.expandedKeys = le(this.expandedKeys, n), this.emit("tree-expand", {
2874
2922
  key: n,
2875
- row: s.data,
2923
+ row: i.data,
2876
2924
  expanded: this.expandedKeys.has(n),
2877
- depth: s.depth
2925
+ depth: i.depth
2878
2926
  }), this.requestRender(), !0) : !1;
2879
2927
  }
2880
2928
  // ===== Public API =====
@@ -2950,7 +2998,7 @@ class lt extends ue {
2950
2998
  }
2951
2999
  `;
2952
3000
  }
2953
- const C = {
3001
+ const y = {
2954
3002
  // Root structure
2955
3003
  ROOT: "tbw-grid-root",
2956
3004
  HEADER: "header",
@@ -3003,22 +3051,22 @@ const C = {
3003
3051
  TREE_LEVEL: "data-tree-level",
3004
3052
  STICKY: "data-sticky"
3005
3053
  }, rt = {
3006
- ROOT: `.${C.ROOT}`,
3007
- HEADER: `.${C.HEADER}`,
3008
- HEADER_ROW: `.${C.HEADER_ROW}`,
3009
- HEADER_CELL: `.${C.HEADER_CELL}`,
3010
- ROWS_VIEWPORT: `.${C.ROWS_VIEWPORT}`,
3011
- ROWS_CONTAINER: `.${C.ROWS_CONTAINER}`,
3012
- DATA_ROW: `.${C.DATA_ROW}`,
3013
- DATA_CELL: `.${C.DATA_CELL}`,
3014
- GROUP_ROW: `.${C.GROUP_ROW}`,
3054
+ ROOT: `.${y.ROOT}`,
3055
+ HEADER: `.${y.HEADER}`,
3056
+ HEADER_ROW: `.${y.HEADER_ROW}`,
3057
+ HEADER_CELL: `.${y.HEADER_CELL}`,
3058
+ ROWS_VIEWPORT: `.${y.ROWS_VIEWPORT}`,
3059
+ ROWS_CONTAINER: `.${y.ROWS_CONTAINER}`,
3060
+ DATA_ROW: `.${y.DATA_ROW}`,
3061
+ DATA_CELL: `.${y.DATA_CELL}`,
3062
+ GROUP_ROW: `.${y.GROUP_ROW}`,
3015
3063
  // By data attribute
3016
- ROW_BY_INDEX: (o) => `.${C.DATA_ROW}[${H.ROW_INDEX}="${o}"]`,
3017
- CELL_BY_FIELD: (o) => `.${C.DATA_CELL}[${H.FIELD}="${o}"]`,
3018
- CELL_AT: (o, e) => `.${C.DATA_ROW}[${H.ROW_INDEX}="${o}"] .${C.DATA_CELL}[${H.COL_INDEX}="${e}"]`,
3064
+ ROW_BY_INDEX: (o) => `.${y.DATA_ROW}[${H.ROW_INDEX}="${o}"]`,
3065
+ CELL_BY_FIELD: (o) => `.${y.DATA_CELL}[${H.FIELD}="${o}"]`,
3066
+ CELL_AT: (o, e) => `.${y.DATA_ROW}[${H.ROW_INDEX}="${o}"] .${y.DATA_CELL}[${H.COL_INDEX}="${e}"]`,
3019
3067
  // State selectors
3020
- SELECTED_ROWS: `.${C.DATA_ROW}.${C.SELECTED}`,
3021
- EDITING_CELL: `.${C.DATA_CELL}.${C.EDITING}`
3068
+ SELECTED_ROWS: `.${y.DATA_ROW}.${y.SELECTED}`,
3069
+ EDITING_CELL: `.${y.DATA_CELL}.${y.EDITING}`
3022
3070
  }, at = {
3023
3071
  // Colors
3024
3072
  COLOR_BG: "--tbw-color-bg",
@@ -3086,7 +3134,7 @@ const C = {
3086
3134
  }, I = {
3087
3135
  sum: (o, e) => o.reduce((t, n) => t + (Number(n[e]) || 0), 0),
3088
3136
  avg: (o, e) => {
3089
- const t = o.reduce((n, s) => n + (Number(s[e]) || 0), 0);
3137
+ const t = o.reduce((n, i) => n + (Number(i[e]) || 0), 0);
3090
3138
  return o.length ? t / o.length : 0;
3091
3139
  },
3092
3140
  count: (o) => o.length,
@@ -3094,7 +3142,7 @@ const C = {
3094
3142
  max: (o, e) => Math.max(...o.map((t) => Number(t[e]) || -1 / 0)),
3095
3143
  first: (o, e) => o[0]?.[e],
3096
3144
  last: (o, e) => o[o.length - 1]?.[e]
3097
- }, P = /* @__PURE__ */ new Map(), S = {
3145
+ }, P = /* @__PURE__ */ new Map(), x = {
3098
3146
  /**
3099
3147
  * Register a custom aggregator function.
3100
3148
  */
@@ -3118,8 +3166,8 @@ const C = {
3118
3166
  * Run an aggregator on a set of rows.
3119
3167
  */
3120
3168
  run(o, e, t, n) {
3121
- const s = this.get(o);
3122
- return s ? s(e, t, n) : void 0;
3169
+ const i = this.get(o);
3170
+ return i ? i(e, t, n) : void 0;
3123
3171
  },
3124
3172
  /**
3125
3173
  * Check if an aggregator exists.
@@ -3133,14 +3181,14 @@ const C = {
3133
3181
  list() {
3134
3182
  return [...Object.keys(I), ...P.keys()];
3135
3183
  }
3136
- }, ht = S.register.bind(S), ut = S.unregister.bind(S), ft = S.get.bind(S), pt = S.run.bind(S), wt = S.list.bind(S);
3184
+ }, ht = x.register.bind(x), ut = x.unregister.bind(x), ft = x.get.bind(x), pt = x.run.bind(x), wt = x.list.bind(x);
3137
3185
  export {
3138
3186
  ue as BaseGridPlugin,
3139
3187
  ct as DGEvents,
3140
3188
  q as DataGridElement,
3141
- O as FitModeEnum,
3189
+ M as FitModeEnum,
3142
3190
  at as GridCSSVars,
3143
- C as GridClasses,
3191
+ y as GridClasses,
3144
3192
  H as GridDataAttrs,
3145
3193
  q as GridElement,
3146
3194
  rt as GridSelectors,
@@ -3148,7 +3196,7 @@ export {
3148
3196
  Ye as PluginManager,
3149
3197
  st as SelectionPlugin,
3150
3198
  lt as TreePlugin,
3151
- S as aggregatorRegistry,
3199
+ x as aggregatorRegistry,
3152
3200
  ft as getAggregator,
3153
3201
  wt as listAggregators,
3154
3202
  ht as registerAggregator,