@toolbox-web/grid 0.3.3 → 0.4.1

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 (148) hide show
  1. package/all.d.ts +19 -19
  2. package/all.d.ts.map +1 -1
  3. package/all.js +1798 -1201
  4. package/all.js.map +1 -1
  5. package/index.js +2215 -2026
  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/editing.d.ts +3 -3
  14. package/lib/core/internal/editing.d.ts.map +1 -1
  15. package/lib/core/internal/event-delegation.d.ts.map +1 -1
  16. package/lib/core/internal/header.d.ts.map +1 -1
  17. package/lib/core/internal/keyboard.d.ts.map +1 -1
  18. package/lib/core/internal/render-scheduler.d.ts +123 -0
  19. package/lib/core/internal/render-scheduler.d.ts.map +1 -0
  20. package/lib/core/internal/rows.d.ts +8 -3
  21. package/lib/core/internal/rows.d.ts.map +1 -1
  22. package/lib/core/internal/sanitize.d.ts +2 -2
  23. package/lib/core/internal/sanitize.d.ts.map +1 -1
  24. package/lib/core/internal/shell.d.ts +40 -2
  25. package/lib/core/internal/shell.d.ts.map +1 -1
  26. package/lib/core/internal/validate-config.d.ts +25 -0
  27. package/lib/core/internal/validate-config.d.ts.map +1 -0
  28. package/lib/core/plugin/base-plugin.d.ts +118 -0
  29. package/lib/core/plugin/base-plugin.d.ts.map +1 -1
  30. package/lib/core/plugin/index.d.ts +1 -0
  31. package/lib/core/plugin/index.d.ts.map +1 -1
  32. package/lib/core/plugin/plugin-manager.d.ts +13 -2
  33. package/lib/core/plugin/plugin-manager.d.ts.map +1 -1
  34. package/lib/core/plugin/types.d.ts +17 -3
  35. package/lib/core/plugin/types.d.ts.map +1 -1
  36. package/lib/core/types.d.ts +112 -12
  37. package/lib/core/types.d.ts.map +1 -1
  38. package/lib/plugins/clipboard/ClipboardPlugin.d.ts +7 -1
  39. package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
  40. package/lib/plugins/clipboard/index.js +78 -22
  41. package/lib/plugins/clipboard/index.js.map +1 -1
  42. package/lib/plugins/column-virtualization/index.js +72 -21
  43. package/lib/plugins/column-virtualization/index.js.map +1 -1
  44. package/lib/plugins/context-menu/index.js +53 -2
  45. package/lib/plugins/context-menu/index.js.map +1 -1
  46. package/lib/plugins/editing/EditingPlugin.d.ts +117 -0
  47. package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -0
  48. package/lib/{core/internal → plugins/editing}/editors.d.ts +1 -1
  49. package/lib/plugins/editing/editors.d.ts.map +1 -0
  50. package/lib/plugins/editing/index.d.ts +8 -0
  51. package/lib/plugins/editing/index.d.ts.map +1 -0
  52. package/lib/plugins/editing/index.js +721 -0
  53. package/lib/plugins/editing/index.js.map +1 -0
  54. package/lib/plugins/editing/types.d.ts +45 -0
  55. package/lib/plugins/editing/types.d.ts.map +1 -0
  56. package/lib/plugins/export/ExportPlugin.d.ts.map +1 -1
  57. package/lib/plugins/export/index.js +68 -17
  58. package/lib/plugins/export/index.js.map +1 -1
  59. package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
  60. package/lib/plugins/filtering/index.js +103 -50
  61. package/lib/plugins/filtering/index.js.map +1 -1
  62. package/lib/plugins/grouping-columns/grouping-columns.d.ts +4 -4
  63. package/lib/plugins/grouping-columns/grouping-columns.d.ts.map +1 -1
  64. package/lib/plugins/grouping-columns/index.js +80 -29
  65. package/lib/plugins/grouping-columns/index.js.map +1 -1
  66. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts.map +1 -1
  67. package/lib/plugins/grouping-rows/grouping-rows.d.ts.map +1 -1
  68. package/lib/plugins/grouping-rows/index.js +62 -11
  69. package/lib/plugins/grouping-rows/index.js.map +1 -1
  70. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +2 -2
  71. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts.map +1 -1
  72. package/lib/plugins/master-detail/index.js +156 -102
  73. package/lib/plugins/master-detail/index.js.map +1 -1
  74. package/lib/plugins/master-detail/types.d.ts +12 -2
  75. package/lib/plugins/master-detail/types.d.ts.map +1 -1
  76. package/lib/plugins/multi-sort/MultiSortPlugin.d.ts.map +1 -1
  77. package/lib/plugins/multi-sort/index.js +75 -22
  78. package/lib/plugins/multi-sort/index.js.map +1 -1
  79. package/lib/plugins/pinned-columns/index.js +57 -6
  80. package/lib/plugins/pinned-columns/index.js.map +1 -1
  81. package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts.map +1 -1
  82. package/lib/plugins/pinned-rows/index.js +61 -9
  83. package/lib/plugins/pinned-rows/index.js.map +1 -1
  84. package/lib/plugins/pivot/index.js +58 -7
  85. package/lib/plugins/pivot/index.js.map +1 -1
  86. package/lib/plugins/reorder/ReorderPlugin.d.ts.map +1 -1
  87. package/lib/plugins/reorder/index.js +75 -19
  88. package/lib/plugins/reorder/index.js.map +1 -1
  89. package/lib/plugins/selection/index.js +57 -6
  90. package/lib/plugins/selection/index.js.map +1 -1
  91. package/lib/plugins/server-side/index.js +60 -9
  92. package/lib/plugins/server-side/index.js.map +1 -1
  93. package/lib/plugins/tree/TreePlugin.d.ts +3 -3
  94. package/lib/plugins/tree/TreePlugin.d.ts.map +1 -1
  95. package/lib/plugins/tree/index.js +181 -126
  96. package/lib/plugins/tree/index.js.map +1 -1
  97. package/lib/plugins/tree/tree-data.d.ts +6 -6
  98. package/lib/plugins/tree/tree-data.d.ts.map +1 -1
  99. package/lib/plugins/tree/tree-detect.d.ts +5 -9
  100. package/lib/plugins/tree/tree-detect.d.ts.map +1 -1
  101. package/lib/plugins/tree/types.d.ts +16 -4
  102. package/lib/plugins/tree/types.d.ts.map +1 -1
  103. package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts +7 -1
  104. package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts.map +1 -1
  105. package/lib/plugins/undo-redo/index.js +65 -6
  106. package/lib/plugins/undo-redo/index.js.map +1 -1
  107. package/lib/plugins/visibility/VisibilityPlugin.d.ts +7 -1
  108. package/lib/plugins/visibility/VisibilityPlugin.d.ts.map +1 -1
  109. package/lib/plugins/visibility/index.js +61 -2
  110. package/lib/plugins/visibility/index.js.map +1 -1
  111. package/package.json +1 -1
  112. package/public.d.ts +104 -13
  113. package/public.d.ts.map +1 -1
  114. package/umd/grid.all.umd.js +37 -19
  115. package/umd/grid.all.umd.js.map +1 -1
  116. package/umd/grid.umd.js +25 -7
  117. package/umd/grid.umd.js.map +1 -1
  118. package/umd/plugins/clipboard.umd.js +2 -2
  119. package/umd/plugins/clipboard.umd.js.map +1 -1
  120. package/umd/plugins/editing.umd.js +2 -0
  121. package/umd/plugins/editing.umd.js.map +1 -0
  122. package/umd/plugins/export.umd.js +2 -2
  123. package/umd/plugins/export.umd.js.map +1 -1
  124. package/umd/plugins/filtering.umd.js +1 -1
  125. package/umd/plugins/filtering.umd.js.map +1 -1
  126. package/umd/plugins/grouping-columns.umd.js +1 -1
  127. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  128. package/umd/plugins/grouping-rows.umd.js +1 -1
  129. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  130. package/umd/plugins/master-detail.umd.js +1 -1
  131. package/umd/plugins/master-detail.umd.js.map +1 -1
  132. package/umd/plugins/multi-sort.umd.js +1 -1
  133. package/umd/plugins/multi-sort.umd.js.map +1 -1
  134. package/umd/plugins/pinned-rows.umd.js +1 -1
  135. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  136. package/umd/plugins/reorder.umd.js +1 -1
  137. package/umd/plugins/reorder.umd.js.map +1 -1
  138. package/umd/plugins/tree.umd.js +1 -1
  139. package/umd/plugins/tree.umd.js.map +1 -1
  140. package/umd/plugins/undo-redo.umd.js +1 -1
  141. package/umd/plugins/undo-redo.umd.js.map +1 -1
  142. package/umd/plugins/visibility.umd.js +1 -1
  143. package/umd/plugins/visibility.umd.js.map +1 -1
  144. package/lib/core/internal/column-state.d.ts +0 -124
  145. package/lib/core/internal/column-state.d.ts.map +0 -1
  146. package/lib/core/internal/editors.d.ts.map +0 -1
  147. package/lib/core/internal/grid-internals.d.ts +0 -83
  148. package/lib/core/internal/grid-internals.d.ts.map +0 -1
@@ -8,7 +8,23 @@ const S = {
8
8
  dragHandle: "⋮⋮",
9
9
  toolPanel: "☰"
10
10
  };
11
- class K {
11
+ class R {
12
+ /**
13
+ * Plugin dependencies - declare other plugins this one requires.
14
+ *
15
+ * Dependencies are validated when the plugin is attached.
16
+ * Required dependencies throw an error if missing.
17
+ * Optional dependencies log an info message if missing.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * static readonly dependencies: PluginDependency[] = [
22
+ * { name: 'editing', required: true, reason: 'Tracks cell edits for undo/redo' },
23
+ * { name: 'selection', required: false, reason: 'Enables selection-based undo' },
24
+ * ];
25
+ * ```
26
+ */
27
+ static dependencies;
12
28
  /** Plugin version - override in subclass if needed */
13
29
  version = "1.0.0";
14
30
  /** CSS styles to inject into the grid's shadow DOM */
@@ -25,6 +41,12 @@ class K {
25
41
  config;
26
42
  /** User-provided configuration from constructor */
27
43
  userConfig;
44
+ /**
45
+ * Plugin-level AbortController for event listener cleanup.
46
+ * Created fresh in attach(), aborted in detach().
47
+ * This ensures event listeners are properly cleaned up when plugins are re-attached.
48
+ */
49
+ #e;
28
50
  /**
29
51
  * Default configuration - subclasses should override this getter.
30
52
  * Note: This must be a getter (not property initializer) for proper inheritance
@@ -39,19 +61,48 @@ class K {
39
61
  /**
40
62
  * Called when the plugin is attached to a grid.
41
63
  * Override to set up event listeners, initialize state, etc.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * attach(grid: GridElement): void {
68
+ * super.attach(grid);
69
+ * // Set up document-level listeners with auto-cleanup
70
+ * document.addEventListener('keydown', this.handleEscape, {
71
+ * signal: this.disconnectSignal
72
+ * });
73
+ * }
74
+ * ```
42
75
  */
43
76
  attach(e) {
44
- this.grid = e, this.config = { ...this.defaultConfig, ...this.userConfig };
77
+ this.#e?.abort(), this.#e = new AbortController(), this.grid = e, this.config = { ...this.defaultConfig, ...this.userConfig };
45
78
  }
46
79
  /**
47
80
  * Called when the plugin is detached from a grid.
48
81
  * Override to clean up event listeners, timers, etc.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * detach(): void {
86
+ * // Clean up any state not handled by disconnectSignal
87
+ * this.selectedRows.clear();
88
+ * this.cache = null;
89
+ * }
90
+ * ```
49
91
  */
50
92
  detach() {
93
+ this.#e?.abort(), this.#e = void 0;
51
94
  }
52
95
  /**
53
96
  * Get another plugin instance from the same grid.
54
97
  * Use for inter-plugin communication.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * const selection = this.getPlugin(SelectionPlugin);
102
+ * if (selection) {
103
+ * const selectedRows = selection.getSelectedRows();
104
+ * }
105
+ * ```
55
106
  */
56
107
  getPlugin(e) {
57
108
  return this.grid?.getPlugin(e);
@@ -125,7 +176,7 @@ class K {
125
176
  * document.addEventListener('keydown', handler, { signal: this.disconnectSignal });
126
177
  */
127
178
  get disconnectSignal() {
128
- return this.grid?.disconnectSignal;
179
+ return this.#e?.signal ?? this.grid?.disconnectSignal;
129
180
  }
130
181
  /**
131
182
  * Get the grid-level icons configuration.
@@ -164,98 +215,102 @@ class K {
164
215
  }
165
216
  // #endregion
166
217
  }
167
- function x(o, e, t) {
168
- return o.id !== void 0 ? String(o.id) : t ? `${t}-${e}` : String(e);
218
+ function x(i, e, t) {
219
+ return i.id !== void 0 ? String(i.id) : t ? `${t}-${e}` : String(e);
169
220
  }
170
- function w(o, e) {
171
- const t = new Set(o);
221
+ function m(i, e) {
222
+ const t = new Set(i);
172
223
  return t.has(e) ? t.delete(e) : t.add(e), t;
173
224
  }
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);
225
+ function p(i, e, t = null, n = 0) {
226
+ const s = e.childrenField ?? "children", o = /* @__PURE__ */ new Set();
227
+ for (let r = 0; r < i.length; r++) {
228
+ const d = i[r], a = x(d, r, t), l = d[s];
229
+ if (Array.isArray(l) && l.length > 0) {
230
+ o.add(a);
231
+ const h = p(l, e, a, n + 1);
232
+ for (const f of h) o.add(f);
182
233
  }
183
234
  }
184
- return i;
235
+ return o;
185
236
  }
186
- function R() {
237
+ function C() {
187
238
  return /* @__PURE__ */ new Set();
188
239
  }
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);
240
+ function A(i, e, t, n = null, s = 0) {
241
+ const o = t.childrenField ?? "children";
242
+ for (let r = 0; r < i.length; r++) {
243
+ const d = i[r], a = x(d, r, n);
244
+ if (a === e)
245
+ return [a];
246
+ const l = d[o];
247
+ if (Array.isArray(l) && l.length > 0) {
248
+ const h = A(l, e, t, a, s + 1);
198
249
  if (h)
199
- return [l, ...h];
250
+ return [a, ...h];
200
251
  }
201
252
  }
202
253
  return null;
203
254
  }
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;
255
+ function v(i, e, t, n) {
256
+ const s = A(i, e, t);
257
+ if (!s) return n;
258
+ const o = new Set(n);
259
+ for (let r = 0; r < s.length - 1; r++)
260
+ o.add(s[r]);
261
+ return o;
211
262
  }
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)
263
+ function b(i, e = "children") {
264
+ if (!Array.isArray(i) || i.length === 0) return !1;
265
+ for (const t of i) {
266
+ if (!t) continue;
267
+ const n = t[e];
268
+ if (Array.isArray(n) && n.length > 0)
216
269
  return !0;
270
+ }
217
271
  return !1;
218
272
  }
219
- function _(o) {
220
- if (!Array.isArray(o) || o.length === 0) return null;
273
+ function _(i) {
274
+ if (!Array.isArray(i) || i.length === 0) return null;
221
275
  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)
276
+ for (const t of i)
277
+ if (!(!t || typeof t != "object"))
278
+ for (const n of e) {
279
+ const s = t[n];
280
+ if (Array.isArray(s) && s.length > 0)
226
281
  return n;
227
- }
282
+ }
228
283
  return null;
229
284
  }
230
- function v(o, e = "children", t = 0) {
231
- if (!Array.isArray(o) || o.length === 0) return t;
285
+ function E(i, e = "children", t = 0) {
286
+ if (!Array.isArray(i) || i.length === 0) return t;
232
287
  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);
288
+ for (const s of i) {
289
+ if (!s) continue;
290
+ const o = s[e];
291
+ if (Array.isArray(o) && o.length > 0) {
292
+ const r = E(o, e, t + 1);
293
+ r > n && (n = r);
239
294
  }
240
295
  }
241
296
  return n;
242
297
  }
243
- function E(o, e = "children") {
244
- if (!Array.isArray(o)) return 0;
298
+ function k(i, e = "children") {
299
+ if (!Array.isArray(i)) return 0;
245
300
  let t = 0;
246
- for (const n of o) {
301
+ for (const n of i) {
247
302
  if (!n) continue;
248
303
  t++;
249
- const r = n[e];
250
- Array.isArray(r) && (t += E(r, e));
304
+ const s = n[e];
305
+ Array.isArray(s) && (t += k(s, e));
251
306
  }
252
307
  return t;
253
308
  }
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 {
309
+ 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}}";
310
+ class F extends R {
256
311
  name = "tree";
257
312
  version = "1.0.0";
258
- styles = k;
313
+ styles = T;
259
314
  get defaultConfig() {
260
315
  return {
261
316
  childrenField: "children",
@@ -293,103 +348,103 @@ class T extends K {
293
348
  // #region Auto-Detection
294
349
  detect(e) {
295
350
  if (!this.config.autoDetect) return !1;
296
- const t = this.config.childrenField ?? _(e) ?? "children";
297
- return m(e, t);
351
+ const t = e, n = this.config.childrenField ?? _(t) ?? "children";
352
+ return b(t, n);
298
353
  }
299
354
  // #endregion
300
355
  // #region Data Processing
301
356
  processRows(e) {
302
- const t = this.config.childrenField ?? "children";
303
- if (!m(e, t))
357
+ const t = this.config.childrenField ?? "children", n = e;
358
+ if (!b(n, t))
304
359
  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
360
+ let s = this.withStableKeys(n);
361
+ 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();
362
+ const o = /* @__PURE__ */ new Set();
363
+ for (const r of this.flattenedRows)
364
+ this.rowKeyMap.set(r.key, r), o.add(r.key), !this.previousVisibleKeys.has(r.key) && r.depth > 0 && this.keysToAnimate.add(r.key);
365
+ return this.previousVisibleKeys = o, this.flattenedRows.map((r) => ({
366
+ ...r.data,
367
+ __treeKey: r.key,
368
+ __treeDepth: r.depth,
369
+ __treeHasChildren: r.hasChildren,
370
+ __treeExpanded: r.isExpanded
316
371
  }));
317
372
  }
318
373
  /** Assign stable keys to rows (preserves key across sort operations) */
319
374
  withStableKeys(e, t = null) {
320
375
  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;
376
+ return e.map((s, o) => {
377
+ 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
378
  return {
324
- ...r,
325
- __stableKey: s,
326
- ...l ? { [n]: this.withStableKeys(a, s) } : {}
379
+ ...s,
380
+ __stableKey: d,
381
+ ...l ? { [n]: this.withStableKeys(a, d) } : {}
327
382
  };
328
383
  });
329
384
  }
330
385
  /** Flatten tree using stable keys */
331
386
  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({
387
+ const s = this.config.childrenField ?? "children", o = [];
388
+ for (const r of e) {
389
+ const a = r.__stableKey ?? String(r.id ?? "?"), l = r[s], h = Array.isArray(l) && l.length > 0, f = t.has(a);
390
+ o.push({
336
391
  key: a,
337
- data: s,
392
+ data: r,
338
393
  depth: n,
339
- hasChildren: d,
340
- isExpanded: h,
394
+ hasChildren: h,
395
+ isExpanded: f,
341
396
  parentKey: n > 0 && a.substring(0, a.lastIndexOf("-")) || null
342
- }), d && h && i.push(...this.flattenTree(l, t, n + 1));
397
+ }), h && f && o.push(...this.flattenTree(l, t, n + 1));
343
398
  }
344
- return i;
399
+ return o;
345
400
  }
346
401
  /** Sort tree recursively, keeping children with parents */
347
402
  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;
403
+ const s = this.config.childrenField ?? "children";
404
+ return [...e].sort((r, d) => {
405
+ const a = r[t], l = d[t];
406
+ return a == null && l == null ? 0 : a == null ? -1 : l == null ? 1 : a > l ? n : a < l ? -n : 0;
407
+ }).map((r) => {
408
+ const d = r[s];
409
+ return Array.isArray(d) && d.length > 0 ? { ...r, [s]: this.sortTree(d, t, n) } : r;
355
410
  });
356
411
  }
357
412
  processColumns(e) {
358
413
  if (this.flattenedRows.length === 0) return [...e];
359
414
  const t = [...e];
360
415
  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) {
416
+ const n = { ...t[0] }, s = n.viewRenderer;
417
+ if (s?.__treeWrapped) return t;
418
+ const o = () => this.config, r = this.setIcon.bind(this), d = this.resolveIcon.bind(this), a = (l) => {
419
+ const { value: h, row: f } = l, { indentWidth: K = 20, showExpandIcons: w = !0 } = o(), g = f, u = document.createElement("span");
420
+ 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
421
  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) {
422
+ 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);
423
+ } else if (w) {
369
424
  const c = document.createElement("span");
370
- c.className = "tree-spacer", f.appendChild(c);
425
+ c.className = "tree-spacer", u.appendChild(c);
371
426
  }
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 ?? "");
427
+ const y = document.createElement("span");
428
+ if (s) {
429
+ const c = s(l);
430
+ c instanceof Node ? y.appendChild(c) : y.textContent = String(c ?? h ?? "");
376
431
  } else
377
- g.textContent = String(h ?? "");
378
- return f.appendChild(g), f;
432
+ y.textContent = String(h ?? "");
433
+ return u.appendChild(y), u;
379
434
  };
380
- return l.__treeWrapped = !0, n.viewRenderer = l, t[0] = n, t;
435
+ return a.__treeWrapped = !0, n.viewRenderer = a, t[0] = n, t;
381
436
  }
382
437
  // #endregion
383
438
  // #region Event Handlers
384
439
  onCellClick(e) {
385
440
  const t = e.originalEvent?.target;
386
441
  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", {
442
+ const n = t.getAttribute("data-tree-key"), s = n ? this.rowKeyMap.get(n) : null;
443
+ return s ? (this.expandedKeys = m(this.expandedKeys, n), this.emit("tree-expand", {
389
444
  key: n,
390
- row: r.data,
445
+ row: s.data,
391
446
  expanded: this.expandedKeys.has(n),
392
- depth: r.depth
447
+ depth: s.depth
393
448
  }), this.requestRender(), !0) : !1;
394
449
  }
395
450
  onHeaderClick(e) {
@@ -405,9 +460,9 @@ class T extends K {
405
460
  const t = this.shadowRoot?.querySelector(".rows");
406
461
  if (!t) return;
407
462
  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 }));
463
+ for (const s of t.querySelectorAll(".data-grid-row")) {
464
+ const o = s.querySelector(".cell[data-row]"), r = o ? parseInt(o.getAttribute("data-row") ?? "-1", 10) : -1, d = this.flattenedRows[r]?.key;
465
+ d && this.keysToAnimate.has(d) && (s.classList.add(n), s.addEventListener("animationend", () => s.classList.remove(n), { once: !0 }));
411
466
  }
412
467
  this.keysToAnimate.clear();
413
468
  }
@@ -420,13 +475,13 @@ class T extends K {
420
475
  this.expandedKeys.delete(e), this.requestRender();
421
476
  }
422
477
  toggle(e) {
423
- this.expandedKeys = w(this.expandedKeys, e), this.requestRender();
478
+ this.expandedKeys = m(this.expandedKeys, e), this.requestRender();
424
479
  }
425
480
  expandAll() {
426
481
  this.expandedKeys = p(this.rows, this.config), this.requestRender();
427
482
  }
428
483
  collapseAll() {
429
- this.expandedKeys = R(), this.requestRender();
484
+ this.expandedKeys = C(), this.requestRender();
430
485
  }
431
486
  isExpanded(e) {
432
487
  return this.expandedKeys.has(e);
@@ -441,15 +496,15 @@ class T extends K {
441
496
  return this.rowKeyMap.get(e)?.data;
442
497
  }
443
498
  expandToKey(e) {
444
- this.expandedKeys = C(this.rows, e, this.config, this.expandedKeys), this.requestRender();
499
+ this.expandedKeys = v(this.rows, e, this.config, this.expandedKeys), this.requestRender();
445
500
  }
446
501
  // #endregion
447
502
  }
448
503
  export {
449
- T as TreePlugin,
450
- E as countNodes,
451
- m as detectTreeStructure,
452
- v as getMaxDepth,
504
+ F as TreePlugin,
505
+ k as countNodes,
506
+ b as detectTreeStructure,
507
+ E as getMaxDepth,
453
508
  _ as inferChildrenField
454
509
  };
455
510
  //# sourceMappingURL=index.js.map