@toolbox-web/grid 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/all.d.ts +19 -19
  2. package/all.d.ts.map +1 -1
  3. package/all.js +1775 -1202
  4. package/all.js.map +1 -1
  5. package/index.js +2152 -2028
  6. package/index.js.map +1 -1
  7. package/lib/core/grid.d.ts +22 -12
  8. package/lib/core/grid.d.ts.map +1 -1
  9. package/lib/core/internal/columns.d.ts +0 -9
  10. package/lib/core/internal/columns.d.ts.map +1 -1
  11. package/lib/core/internal/config-manager.d.ts +236 -0
  12. package/lib/core/internal/config-manager.d.ts.map +1 -0
  13. package/lib/core/internal/event-delegation.d.ts.map +1 -1
  14. package/lib/core/internal/header.d.ts.map +1 -1
  15. package/lib/core/internal/keyboard.d.ts.map +1 -1
  16. package/lib/core/internal/render-scheduler.d.ts +123 -0
  17. package/lib/core/internal/render-scheduler.d.ts.map +1 -0
  18. package/lib/core/internal/rows.d.ts +8 -3
  19. package/lib/core/internal/rows.d.ts.map +1 -1
  20. package/lib/core/internal/sanitize.d.ts +2 -2
  21. package/lib/core/internal/sanitize.d.ts.map +1 -1
  22. package/lib/core/internal/shell.d.ts +40 -2
  23. package/lib/core/internal/shell.d.ts.map +1 -1
  24. package/lib/core/internal/validate-config.d.ts +11 -0
  25. package/lib/core/internal/validate-config.d.ts.map +1 -0
  26. package/lib/core/plugin/base-plugin.d.ts +70 -0
  27. package/lib/core/plugin/base-plugin.d.ts.map +1 -1
  28. package/lib/core/plugin/plugin-manager.d.ts +13 -2
  29. package/lib/core/plugin/plugin-manager.d.ts.map +1 -1
  30. package/lib/core/plugin/types.d.ts +17 -3
  31. package/lib/core/plugin/types.d.ts.map +1 -1
  32. package/lib/core/types.d.ts +112 -12
  33. package/lib/core/types.d.ts.map +1 -1
  34. package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
  35. package/lib/plugins/clipboard/index.js +50 -18
  36. package/lib/plugins/clipboard/index.js.map +1 -1
  37. package/lib/plugins/column-virtualization/index.js +60 -25
  38. package/lib/plugins/column-virtualization/index.js.map +1 -1
  39. package/lib/plugins/context-menu/index.js +51 -16
  40. package/lib/plugins/context-menu/index.js.map +1 -1
  41. package/lib/plugins/editing/EditingPlugin.d.ts +117 -0
  42. package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -0
  43. package/lib/{core/internal → plugins/editing}/editors.d.ts +1 -1
  44. package/lib/plugins/editing/editors.d.ts.map +1 -0
  45. package/lib/plugins/editing/index.d.ts +8 -0
  46. package/lib/plugins/editing/index.d.ts.map +1 -0
  47. package/lib/plugins/editing/index.js +705 -0
  48. package/lib/plugins/editing/index.js.map +1 -0
  49. package/lib/plugins/editing/types.d.ts +45 -0
  50. package/lib/plugins/editing/types.d.ts.map +1 -0
  51. package/lib/plugins/export/ExportPlugin.d.ts.map +1 -1
  52. package/lib/plugins/export/index.js +74 -39
  53. package/lib/plugins/export/index.js.map +1 -1
  54. package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
  55. package/lib/plugins/filtering/index.js +87 -50
  56. package/lib/plugins/filtering/index.js.map +1 -1
  57. package/lib/plugins/grouping-columns/grouping-columns.d.ts +4 -4
  58. package/lib/plugins/grouping-columns/grouping-columns.d.ts.map +1 -1
  59. package/lib/plugins/grouping-columns/index.js +59 -24
  60. package/lib/plugins/grouping-columns/index.js.map +1 -1
  61. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts.map +1 -1
  62. package/lib/plugins/grouping-rows/grouping-rows.d.ts.map +1 -1
  63. package/lib/plugins/grouping-rows/index.js +46 -11
  64. package/lib/plugins/grouping-rows/index.js.map +1 -1
  65. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +2 -2
  66. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts.map +1 -1
  67. package/lib/plugins/master-detail/index.js +140 -102
  68. package/lib/plugins/master-detail/index.js.map +1 -1
  69. package/lib/plugins/master-detail/types.d.ts +12 -2
  70. package/lib/plugins/master-detail/types.d.ts.map +1 -1
  71. package/lib/plugins/multi-sort/MultiSortPlugin.d.ts.map +1 -1
  72. package/lib/plugins/multi-sort/index.js +59 -22
  73. package/lib/plugins/multi-sort/index.js.map +1 -1
  74. package/lib/plugins/pinned-columns/index.js +41 -6
  75. package/lib/plugins/pinned-columns/index.js.map +1 -1
  76. package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts.map +1 -1
  77. package/lib/plugins/pinned-rows/index.js +45 -9
  78. package/lib/plugins/pinned-rows/index.js.map +1 -1
  79. package/lib/plugins/pivot/index.js +42 -7
  80. package/lib/plugins/pivot/index.js.map +1 -1
  81. package/lib/plugins/reorder/ReorderPlugin.d.ts.map +1 -1
  82. package/lib/plugins/reorder/index.js +59 -19
  83. package/lib/plugins/reorder/index.js.map +1 -1
  84. package/lib/plugins/selection/index.js +41 -6
  85. package/lib/plugins/selection/index.js.map +1 -1
  86. package/lib/plugins/server-side/index.js +48 -13
  87. package/lib/plugins/server-side/index.js.map +1 -1
  88. package/lib/plugins/tree/TreePlugin.d.ts +3 -3
  89. package/lib/plugins/tree/TreePlugin.d.ts.map +1 -1
  90. package/lib/plugins/tree/index.js +165 -126
  91. package/lib/plugins/tree/index.js.map +1 -1
  92. package/lib/plugins/tree/tree-data.d.ts +6 -6
  93. package/lib/plugins/tree/tree-data.d.ts.map +1 -1
  94. package/lib/plugins/tree/tree-detect.d.ts +5 -9
  95. package/lib/plugins/tree/tree-detect.d.ts.map +1 -1
  96. package/lib/plugins/tree/types.d.ts +16 -4
  97. package/lib/plugins/tree/types.d.ts.map +1 -1
  98. package/lib/plugins/undo-redo/index.js +46 -11
  99. package/lib/plugins/undo-redo/index.js.map +1 -1
  100. package/lib/plugins/visibility/index.js +37 -2
  101. package/lib/plugins/visibility/index.js.map +1 -1
  102. package/package.json +1 -1
  103. package/public.d.ts +104 -13
  104. package/public.d.ts.map +1 -1
  105. package/umd/grid.all.umd.js +31 -19
  106. package/umd/grid.all.umd.js.map +1 -1
  107. package/umd/grid.umd.js +18 -6
  108. package/umd/grid.umd.js.map +1 -1
  109. package/umd/plugins/clipboard.umd.js +1 -1
  110. package/umd/plugins/clipboard.umd.js.map +1 -1
  111. package/umd/plugins/editing.umd.js +2 -0
  112. package/umd/plugins/editing.umd.js.map +1 -0
  113. package/umd/plugins/export.umd.js +2 -2
  114. package/umd/plugins/export.umd.js.map +1 -1
  115. package/umd/plugins/filtering.umd.js +1 -1
  116. package/umd/plugins/filtering.umd.js.map +1 -1
  117. package/umd/plugins/grouping-columns.umd.js +1 -1
  118. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  119. package/umd/plugins/grouping-rows.umd.js +1 -1
  120. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  121. package/umd/plugins/master-detail.umd.js +1 -1
  122. package/umd/plugins/master-detail.umd.js.map +1 -1
  123. package/umd/plugins/multi-sort.umd.js +1 -1
  124. package/umd/plugins/multi-sort.umd.js.map +1 -1
  125. package/umd/plugins/pinned-rows.umd.js +1 -1
  126. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  127. package/umd/plugins/reorder.umd.js +1 -1
  128. package/umd/plugins/reorder.umd.js.map +1 -1
  129. package/umd/plugins/tree.umd.js +1 -1
  130. package/umd/plugins/tree.umd.js.map +1 -1
  131. package/lib/core/internal/column-state.d.ts +0 -124
  132. package/lib/core/internal/column-state.d.ts.map +0 -1
  133. package/lib/core/internal/editing.d.ts +0 -76
  134. package/lib/core/internal/editing.d.ts.map +0 -1
  135. package/lib/core/internal/editors.d.ts.map +0 -1
  136. package/lib/core/internal/grid-internals.d.ts +0 -83
  137. package/lib/core/internal/grid-internals.d.ts.map +0 -1
@@ -8,7 +8,7 @@ const S = {
8
8
  dragHandle: "⋮⋮",
9
9
  toolPanel: "☰"
10
10
  };
11
- class K {
11
+ class R {
12
12
  /** Plugin version - override in subclass if needed */
13
13
  version = "1.0.0";
14
14
  /** CSS styles to inject into the grid's shadow DOM */
@@ -25,6 +25,12 @@ class K {
25
25
  config;
26
26
  /** User-provided configuration from constructor */
27
27
  userConfig;
28
+ /**
29
+ * Plugin-level AbortController for event listener cleanup.
30
+ * Created fresh in attach(), aborted in detach().
31
+ * This ensures event listeners are properly cleaned up when plugins are re-attached.
32
+ */
33
+ #e;
28
34
  /**
29
35
  * Default configuration - subclasses should override this getter.
30
36
  * Note: This must be a getter (not property initializer) for proper inheritance
@@ -39,19 +45,48 @@ class K {
39
45
  /**
40
46
  * Called when the plugin is attached to a grid.
41
47
  * Override to set up event listeners, initialize state, etc.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * attach(grid: GridElement): void {
52
+ * super.attach(grid);
53
+ * // Set up document-level listeners with auto-cleanup
54
+ * document.addEventListener('keydown', this.handleEscape, {
55
+ * signal: this.disconnectSignal
56
+ * });
57
+ * }
58
+ * ```
42
59
  */
43
60
  attach(e) {
44
- this.grid = e, this.config = { ...this.defaultConfig, ...this.userConfig };
61
+ this.#e?.abort(), this.#e = new AbortController(), this.grid = e, this.config = { ...this.defaultConfig, ...this.userConfig };
45
62
  }
46
63
  /**
47
64
  * Called when the plugin is detached from a grid.
48
65
  * Override to clean up event listeners, timers, etc.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * detach(): void {
70
+ * // Clean up any state not handled by disconnectSignal
71
+ * this.selectedRows.clear();
72
+ * this.cache = null;
73
+ * }
74
+ * ```
49
75
  */
50
76
  detach() {
77
+ this.#e?.abort(), this.#e = void 0;
51
78
  }
52
79
  /**
53
80
  * Get another plugin instance from the same grid.
54
81
  * Use for inter-plugin communication.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * const selection = this.getPlugin(SelectionPlugin);
86
+ * if (selection) {
87
+ * const selectedRows = selection.getSelectedRows();
88
+ * }
89
+ * ```
55
90
  */
56
91
  getPlugin(e) {
57
92
  return this.grid?.getPlugin(e);
@@ -125,7 +160,7 @@ class K {
125
160
  * document.addEventListener('keydown', handler, { signal: this.disconnectSignal });
126
161
  */
127
162
  get disconnectSignal() {
128
- return this.grid?.disconnectSignal;
163
+ return this.#e?.signal ?? this.grid?.disconnectSignal;
129
164
  }
130
165
  /**
131
166
  * Get the grid-level icons configuration.
@@ -164,98 +199,102 @@ class K {
164
199
  }
165
200
  // #endregion
166
201
  }
167
- function x(o, e, t) {
168
- return o.id !== void 0 ? String(o.id) : t ? `${t}-${e}` : String(e);
202
+ function x(i, e, t) {
203
+ return i.id !== void 0 ? String(i.id) : t ? `${t}-${e}` : String(e);
169
204
  }
170
- function w(o, e) {
171
- const t = new Set(o);
205
+ function m(i, e) {
206
+ const t = new Set(i);
172
207
  return t.has(e) ? t.delete(e) : t.add(e), t;
173
208
  }
174
- function p(o, e, t = null, n = 0) {
175
- const r = e.childrenField ?? "children", i = /* @__PURE__ */ new Set();
176
- for (let s = 0; s < o.length; s++) {
177
- const a = o[s], l = x(a, s, t), d = a[r];
178
- if (Array.isArray(d) && d.length > 0) {
179
- i.add(l);
180
- const h = p(d, e, l, n + 1);
181
- for (const u of h) i.add(u);
209
+ function p(i, e, t = null, n = 0) {
210
+ const s = e.childrenField ?? "children", o = /* @__PURE__ */ new Set();
211
+ for (let r = 0; r < i.length; r++) {
212
+ const d = i[r], a = x(d, r, t), l = d[s];
213
+ if (Array.isArray(l) && l.length > 0) {
214
+ o.add(a);
215
+ const h = p(l, e, a, n + 1);
216
+ for (const f of h) o.add(f);
182
217
  }
183
218
  }
184
- return i;
219
+ return o;
185
220
  }
186
- function R() {
221
+ function C() {
187
222
  return /* @__PURE__ */ new Set();
188
223
  }
189
- function b(o, e, t, n = null, r = 0) {
190
- const i = t.childrenField ?? "children";
191
- for (let s = 0; s < o.length; s++) {
192
- const a = o[s], l = x(a, s, n);
193
- if (l === e)
194
- return [l];
195
- const d = a[i];
196
- if (Array.isArray(d) && d.length > 0) {
197
- const h = b(d, e, t, l, r + 1);
224
+ function A(i, e, t, n = null, s = 0) {
225
+ const o = t.childrenField ?? "children";
226
+ for (let r = 0; r < i.length; r++) {
227
+ const d = i[r], a = x(d, r, n);
228
+ if (a === e)
229
+ return [a];
230
+ const l = d[o];
231
+ if (Array.isArray(l) && l.length > 0) {
232
+ const h = A(l, e, t, a, s + 1);
198
233
  if (h)
199
- return [l, ...h];
234
+ return [a, ...h];
200
235
  }
201
236
  }
202
237
  return null;
203
238
  }
204
- function C(o, e, t, n) {
205
- const r = b(o, e, t);
206
- if (!r) return n;
207
- const i = new Set(n);
208
- for (let s = 0; s < r.length - 1; s++)
209
- i.add(r[s]);
210
- return i;
239
+ function v(i, e, t, n) {
240
+ const s = A(i, e, t);
241
+ if (!s) return n;
242
+ const o = new Set(n);
243
+ for (let r = 0; r < s.length - 1; r++)
244
+ o.add(s[r]);
245
+ return o;
211
246
  }
212
- function m(o, e = "children") {
213
- if (!Array.isArray(o) || o.length === 0) return !1;
214
- for (const t of o)
215
- if (t && Array.isArray(t[e]) && t[e].length > 0)
247
+ function b(i, e = "children") {
248
+ if (!Array.isArray(i) || i.length === 0) return !1;
249
+ for (const t of i) {
250
+ if (!t) continue;
251
+ const n = t[e];
252
+ if (Array.isArray(n) && n.length > 0)
216
253
  return !0;
254
+ }
217
255
  return !1;
218
256
  }
219
- function _(o) {
220
- if (!Array.isArray(o) || o.length === 0) return null;
257
+ function _(i) {
258
+ if (!Array.isArray(i) || i.length === 0) return null;
221
259
  const e = ["children", "items", "nodes", "subRows", "nested"];
222
- for (const t of o)
223
- if (!(!t || typeof t != "object")) {
224
- for (const n of e)
225
- if (Array.isArray(t[n]) && t[n].length > 0)
260
+ for (const t of i)
261
+ if (!(!t || typeof t != "object"))
262
+ for (const n of e) {
263
+ const s = t[n];
264
+ if (Array.isArray(s) && s.length > 0)
226
265
  return n;
227
- }
266
+ }
228
267
  return null;
229
268
  }
230
- function v(o, e = "children", t = 0) {
231
- if (!Array.isArray(o) || o.length === 0) return t;
269
+ function E(i, e = "children", t = 0) {
270
+ if (!Array.isArray(i) || i.length === 0) return t;
232
271
  let n = t;
233
- for (const r of o) {
234
- if (!r) continue;
235
- const i = r[e];
236
- if (Array.isArray(i) && i.length > 0) {
237
- const s = v(i, e, t + 1);
238
- s > n && (n = s);
272
+ for (const s of i) {
273
+ if (!s) continue;
274
+ const o = s[e];
275
+ if (Array.isArray(o) && o.length > 0) {
276
+ const r = E(o, e, t + 1);
277
+ r > n && (n = r);
239
278
  }
240
279
  }
241
280
  return n;
242
281
  }
243
- function E(o, e = "children") {
244
- if (!Array.isArray(o)) return 0;
282
+ function k(i, e = "children") {
283
+ if (!Array.isArray(i)) return 0;
245
284
  let t = 0;
246
- for (const n of o) {
285
+ for (const n of i) {
247
286
  if (!n) continue;
248
287
  t++;
249
- const r = n[e];
250
- Array.isArray(r) && (t += E(r, e));
288
+ const s = n[e];
289
+ Array.isArray(s) && (t += k(s, e));
251
290
  }
252
291
  return t;
253
292
  }
254
- const k = ".tree-cell{display:flex;align-items:center;padding-left:calc(var(--tree-depth, 0) * var(--tbw-tree-indent, 20px))}.tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;margin-right:4px}.tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}.tree-spacer{width:14px;display:inline-block}.data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-tree-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.data-grid-row.tbw-tree-fade-in{animation:tbw-tree-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-tree-fade-in{0%{opacity:0}to{opacity:1}}";
255
- class T extends K {
293
+ const T = ".tree-cell{display:flex;align-items:center;padding-left:calc(var(--tree-depth, 0) * var(--tbw-tree-indent, 20px))}.tree-toggle{cursor:pointer;-webkit-user-select:none;user-select:none;display:inline-flex;align-items:center;justify-content:center;margin-right:4px}.tree-toggle:hover{color:var(--tbw-tree-accent, var(--tbw-color-accent))}.tree-spacer{width:14px;display:inline-block}.data-grid-row.tbw-tree-slide-in{animation:tbw-tree-slide-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-tree-slide-in{0%{opacity:0;transform:translate(-8px)}to{opacity:1;transform:translate(0)}}.data-grid-row.tbw-tree-fade-in{animation:tbw-tree-fade-in var(--tbw-animation-duration, .2s) var(--tbw-animation-easing, ease-out) forwards}@keyframes tbw-tree-fade-in{0%{opacity:0}to{opacity:1}}";
294
+ class F extends R {
256
295
  name = "tree";
257
296
  version = "1.0.0";
258
- styles = k;
297
+ styles = T;
259
298
  get defaultConfig() {
260
299
  return {
261
300
  childrenField: "children",
@@ -293,103 +332,103 @@ class T extends K {
293
332
  // #region Auto-Detection
294
333
  detect(e) {
295
334
  if (!this.config.autoDetect) return !1;
296
- const t = this.config.childrenField ?? _(e) ?? "children";
297
- return m(e, t);
335
+ const t = e, n = this.config.childrenField ?? _(t) ?? "children";
336
+ return b(t, n);
298
337
  }
299
338
  // #endregion
300
339
  // #region Data Processing
301
340
  processRows(e) {
302
- const t = this.config.childrenField ?? "children";
303
- if (!m(e, t))
341
+ const t = this.config.childrenField ?? "children", n = e;
342
+ if (!b(n, t))
304
343
  return this.flattenedRows = [], this.rowKeyMap.clear(), this.previousVisibleKeys.clear(), [...e];
305
- let n = this.withStableKeys(e);
306
- this.sortState && (n = this.sortTree(n, this.sortState.field, this.sortState.direction)), this.config.defaultExpanded && !this.initialExpansionDone && (this.expandedKeys = p(n, this.config), this.initialExpansionDone = !0), this.flattenedRows = this.flattenTree(n, this.expandedKeys), this.rowKeyMap.clear(), this.keysToAnimate.clear();
307
- const r = /* @__PURE__ */ new Set();
308
- for (const i of this.flattenedRows)
309
- this.rowKeyMap.set(i.key, i), r.add(i.key), !this.previousVisibleKeys.has(i.key) && i.depth > 0 && this.keysToAnimate.add(i.key);
310
- return this.previousVisibleKeys = r, this.flattenedRows.map((i) => ({
311
- ...i.data,
312
- __treeKey: i.key,
313
- __treeDepth: i.depth,
314
- __treeHasChildren: i.hasChildren,
315
- __treeExpanded: i.isExpanded
344
+ let s = this.withStableKeys(n);
345
+ this.sortState && (s = this.sortTree(s, this.sortState.field, this.sortState.direction)), this.config.defaultExpanded && !this.initialExpansionDone && (this.expandedKeys = p(s, this.config), this.initialExpansionDone = !0), this.flattenedRows = this.flattenTree(s, this.expandedKeys), this.rowKeyMap.clear(), this.keysToAnimate.clear();
346
+ const o = /* @__PURE__ */ new Set();
347
+ for (const r of this.flattenedRows)
348
+ this.rowKeyMap.set(r.key, r), o.add(r.key), !this.previousVisibleKeys.has(r.key) && r.depth > 0 && this.keysToAnimate.add(r.key);
349
+ return this.previousVisibleKeys = o, this.flattenedRows.map((r) => ({
350
+ ...r.data,
351
+ __treeKey: r.key,
352
+ __treeDepth: r.depth,
353
+ __treeHasChildren: r.hasChildren,
354
+ __treeExpanded: r.isExpanded
316
355
  }));
317
356
  }
318
357
  /** Assign stable keys to rows (preserves key across sort operations) */
319
358
  withStableKeys(e, t = null) {
320
359
  const n = this.config.childrenField ?? "children";
321
- return e.map((r, i) => {
322
- const s = r.id !== void 0 ? String(r.id) : r.__stableKey ?? (t ? `${t}-${i}` : String(i)), a = r[n], l = Array.isArray(a) && a.length > 0;
360
+ return e.map((s, o) => {
361
+ const r = s.__stableKey, d = s.id !== void 0 ? String(s.id) : r ?? (t ? `${t}-${o}` : String(o)), a = s[n], l = Array.isArray(a) && a.length > 0;
323
362
  return {
324
- ...r,
325
- __stableKey: s,
326
- ...l ? { [n]: this.withStableKeys(a, s) } : {}
363
+ ...s,
364
+ __stableKey: d,
365
+ ...l ? { [n]: this.withStableKeys(a, d) } : {}
327
366
  };
328
367
  });
329
368
  }
330
369
  /** Flatten tree using stable keys */
331
370
  flattenTree(e, t, n = 0) {
332
- const r = this.config.childrenField ?? "children", i = [];
333
- for (const s of e) {
334
- const a = s.__stableKey ?? s.id ?? "?", l = s[r], d = Array.isArray(l) && l.length > 0, h = t.has(a);
335
- i.push({
371
+ const s = this.config.childrenField ?? "children", o = [];
372
+ for (const r of e) {
373
+ const a = r.__stableKey ?? String(r.id ?? "?"), l = r[s], h = Array.isArray(l) && l.length > 0, f = t.has(a);
374
+ o.push({
336
375
  key: a,
337
- data: s,
376
+ data: r,
338
377
  depth: n,
339
- hasChildren: d,
340
- isExpanded: h,
378
+ hasChildren: h,
379
+ isExpanded: f,
341
380
  parentKey: n > 0 && a.substring(0, a.lastIndexOf("-")) || null
342
- }), d && h && i.push(...this.flattenTree(l, t, n + 1));
381
+ }), h && f && o.push(...this.flattenTree(l, t, n + 1));
343
382
  }
344
- return i;
383
+ return o;
345
384
  }
346
385
  /** Sort tree recursively, keeping children with parents */
347
386
  sortTree(e, t, n) {
348
- const r = this.config.childrenField ?? "children";
349
- return [...e].sort((s, a) => {
350
- const l = s[t], d = a[t];
351
- return l == null && d == null ? 0 : l == null ? -1 : d == null ? 1 : l > d ? n : l < d ? -n : 0;
352
- }).map((s) => {
353
- const a = s[r];
354
- return Array.isArray(a) && a.length > 0 ? { ...s, [r]: this.sortTree(a, t, n) } : s;
387
+ const s = this.config.childrenField ?? "children";
388
+ return [...e].sort((r, d) => {
389
+ const a = r[t], l = d[t];
390
+ return a == null && l == null ? 0 : a == null ? -1 : l == null ? 1 : a > l ? n : a < l ? -n : 0;
391
+ }).map((r) => {
392
+ const d = r[s];
393
+ return Array.isArray(d) && d.length > 0 ? { ...r, [s]: this.sortTree(d, t, n) } : r;
355
394
  });
356
395
  }
357
396
  processColumns(e) {
358
397
  if (this.flattenedRows.length === 0) return [...e];
359
398
  const t = [...e];
360
399
  if (t.length === 0) return t;
361
- const n = { ...t[0] }, r = n.viewRenderer;
362
- if (r?.__treeWrapped) return t;
363
- const i = () => this.config, s = this.setIcon.bind(this), a = this.resolveIcon.bind(this), l = (d) => {
364
- const { value: h, row: u } = d, { indentWidth: A = 20, showExpandIcons: y = !0 } = i(), f = document.createElement("span");
365
- if (f.className = "tree-cell", f.style.setProperty("--tree-depth", String(u.__treeDepth ?? 0)), f.style.setProperty("--tbw-tree-indent", `${A}px`), u.__treeHasChildren && y) {
400
+ const n = { ...t[0] }, s = n.viewRenderer;
401
+ if (s?.__treeWrapped) return t;
402
+ const o = () => this.config, r = this.setIcon.bind(this), d = this.resolveIcon.bind(this), a = (l) => {
403
+ const { value: h, row: f } = l, { indentWidth: K = 20, showExpandIcons: w = !0 } = o(), g = f, u = document.createElement("span");
404
+ if (u.className = "tree-cell", u.style.setProperty("--tree-depth", String(g.__treeDepth ?? 0)), u.style.setProperty("--tbw-tree-indent", `${K}px`), g.__treeHasChildren && w) {
366
405
  const c = document.createElement("span");
367
- c.className = `tree-toggle${u.__treeExpanded ? " expanded" : ""}`, s(c, a(u.__treeExpanded ? "collapse" : "expand")), c.setAttribute("data-tree-key", u.__treeKey), f.appendChild(c);
368
- } else if (y) {
406
+ c.className = `tree-toggle${g.__treeExpanded ? " expanded" : ""}`, r(c, d(g.__treeExpanded ? "collapse" : "expand")), c.setAttribute("data-tree-key", String(g.__treeKey ?? "")), u.appendChild(c);
407
+ } else if (w) {
369
408
  const c = document.createElement("span");
370
- c.className = "tree-spacer", f.appendChild(c);
409
+ c.className = "tree-spacer", u.appendChild(c);
371
410
  }
372
- const g = document.createElement("span");
373
- if (r) {
374
- const c = r(d);
375
- c instanceof Node ? g.appendChild(c) : g.textContent = String(c ?? h ?? "");
411
+ const y = document.createElement("span");
412
+ if (s) {
413
+ const c = s(l);
414
+ c instanceof Node ? y.appendChild(c) : y.textContent = String(c ?? h ?? "");
376
415
  } else
377
- g.textContent = String(h ?? "");
378
- return f.appendChild(g), f;
416
+ y.textContent = String(h ?? "");
417
+ return u.appendChild(y), u;
379
418
  };
380
- return l.__treeWrapped = !0, n.viewRenderer = l, t[0] = n, t;
419
+ return a.__treeWrapped = !0, n.viewRenderer = a, t[0] = n, t;
381
420
  }
382
421
  // #endregion
383
422
  // #region Event Handlers
384
423
  onCellClick(e) {
385
424
  const t = e.originalEvent?.target;
386
425
  if (!t?.classList.contains("tree-toggle")) return !1;
387
- const n = t.getAttribute("data-tree-key"), r = n ? this.rowKeyMap.get(n) : null;
388
- return r ? (this.expandedKeys = w(this.expandedKeys, n), this.emit("tree-expand", {
426
+ const n = t.getAttribute("data-tree-key"), s = n ? this.rowKeyMap.get(n) : null;
427
+ return s ? (this.expandedKeys = m(this.expandedKeys, n), this.emit("tree-expand", {
389
428
  key: n,
390
- row: r.data,
429
+ row: s.data,
391
430
  expanded: this.expandedKeys.has(n),
392
- depth: r.depth
431
+ depth: s.depth
393
432
  }), this.requestRender(), !0) : !1;
394
433
  }
395
434
  onHeaderClick(e) {
@@ -405,9 +444,9 @@ class T extends K {
405
444
  const t = this.shadowRoot?.querySelector(".rows");
406
445
  if (!t) return;
407
446
  const n = e === "fade" ? "tbw-tree-fade-in" : "tbw-tree-slide-in";
408
- for (const r of t.querySelectorAll(".data-grid-row")) {
409
- const i = r.querySelector(".cell[data-row]"), s = i ? parseInt(i.getAttribute("data-row") ?? "-1", 10) : -1, a = this.flattenedRows[s]?.key;
410
- a && this.keysToAnimate.has(a) && (r.classList.add(n), r.addEventListener("animationend", () => r.classList.remove(n), { once: !0 }));
447
+ for (const s of t.querySelectorAll(".data-grid-row")) {
448
+ const o = s.querySelector(".cell[data-row]"), r = o ? parseInt(o.getAttribute("data-row") ?? "-1", 10) : -1, d = this.flattenedRows[r]?.key;
449
+ d && this.keysToAnimate.has(d) && (s.classList.add(n), s.addEventListener("animationend", () => s.classList.remove(n), { once: !0 }));
411
450
  }
412
451
  this.keysToAnimate.clear();
413
452
  }
@@ -420,13 +459,13 @@ class T extends K {
420
459
  this.expandedKeys.delete(e), this.requestRender();
421
460
  }
422
461
  toggle(e) {
423
- this.expandedKeys = w(this.expandedKeys, e), this.requestRender();
462
+ this.expandedKeys = m(this.expandedKeys, e), this.requestRender();
424
463
  }
425
464
  expandAll() {
426
465
  this.expandedKeys = p(this.rows, this.config), this.requestRender();
427
466
  }
428
467
  collapseAll() {
429
- this.expandedKeys = R(), this.requestRender();
468
+ this.expandedKeys = C(), this.requestRender();
430
469
  }
431
470
  isExpanded(e) {
432
471
  return this.expandedKeys.has(e);
@@ -441,15 +480,15 @@ class T extends K {
441
480
  return this.rowKeyMap.get(e)?.data;
442
481
  }
443
482
  expandToKey(e) {
444
- this.expandedKeys = C(this.rows, e, this.config, this.expandedKeys), this.requestRender();
483
+ this.expandedKeys = v(this.rows, e, this.config, this.expandedKeys), this.requestRender();
445
484
  }
446
485
  // #endregion
447
486
  }
448
487
  export {
449
- T as TreePlugin,
450
- E as countNodes,
451
- m as detectTreeStructure,
452
- v as getMaxDepth,
488
+ F as TreePlugin,
489
+ k as countNodes,
490
+ b as detectTreeStructure,
491
+ E as getMaxDepth,
453
492
  _ as inferChildrenField
454
493
  };
455
494
  //# sourceMappingURL=index.js.map