@toolbox-web/grid 0.3.2 → 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.
- package/README.md +5 -4
- package/all.d.ts +19 -19
- package/all.d.ts.map +1 -1
- package/all.js +1775 -1202
- package/all.js.map +1 -1
- package/index.js +2143 -2015
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +22 -12
- package/lib/core/grid.d.ts.map +1 -1
- package/lib/core/internal/columns.d.ts +0 -9
- package/lib/core/internal/columns.d.ts.map +1 -1
- package/lib/core/internal/config-manager.d.ts +236 -0
- package/lib/core/internal/config-manager.d.ts.map +1 -0
- package/lib/core/internal/event-delegation.d.ts.map +1 -1
- package/lib/core/internal/header.d.ts.map +1 -1
- package/lib/core/internal/keyboard.d.ts.map +1 -1
- package/lib/core/internal/render-scheduler.d.ts +123 -0
- package/lib/core/internal/render-scheduler.d.ts.map +1 -0
- package/lib/core/internal/rows.d.ts +8 -3
- package/lib/core/internal/rows.d.ts.map +1 -1
- package/lib/core/internal/sanitize.d.ts +10 -2
- package/lib/core/internal/sanitize.d.ts.map +1 -1
- package/lib/core/internal/shell.d.ts +40 -2
- package/lib/core/internal/shell.d.ts.map +1 -1
- package/lib/core/internal/validate-config.d.ts +11 -0
- package/lib/core/internal/validate-config.d.ts.map +1 -0
- package/lib/core/plugin/base-plugin.d.ts +70 -0
- package/lib/core/plugin/base-plugin.d.ts.map +1 -1
- package/lib/core/plugin/plugin-manager.d.ts +13 -2
- package/lib/core/plugin/plugin-manager.d.ts.map +1 -1
- package/lib/core/plugin/types.d.ts +17 -3
- package/lib/core/plugin/types.d.ts.map +1 -1
- package/lib/core/types.d.ts +112 -12
- package/lib/core/types.d.ts.map +1 -1
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js +50 -18
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +60 -25
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +51 -16
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/EditingPlugin.d.ts +117 -0
- package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -0
- package/lib/{core/internal → plugins/editing}/editors.d.ts +1 -1
- package/lib/plugins/editing/editors.d.ts.map +1 -0
- package/lib/plugins/editing/index.d.ts +8 -0
- package/lib/plugins/editing/index.d.ts.map +1 -0
- package/lib/plugins/editing/index.js +705 -0
- package/lib/plugins/editing/index.js.map +1 -0
- package/lib/plugins/editing/types.d.ts +45 -0
- package/lib/plugins/editing/types.d.ts.map +1 -0
- package/lib/plugins/export/ExportPlugin.d.ts.map +1 -1
- package/lib/plugins/export/index.js +74 -39
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
- package/lib/plugins/filtering/index.js +87 -50
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/grouping-columns.d.ts +4 -4
- package/lib/plugins/grouping-columns/grouping-columns.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/index.js +59 -24
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts.map +1 -1
- package/lib/plugins/grouping-rows/grouping-rows.d.ts.map +1 -1
- package/lib/plugins/grouping-rows/index.js +46 -11
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +2 -2
- package/lib/plugins/master-detail/MasterDetailPlugin.d.ts.map +1 -1
- package/lib/plugins/master-detail/index.js +140 -102
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/master-detail/types.d.ts +12 -2
- package/lib/plugins/master-detail/types.d.ts.map +1 -1
- package/lib/plugins/multi-sort/MultiSortPlugin.d.ts.map +1 -1
- package/lib/plugins/multi-sort/index.js +59 -22
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js +41 -6
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts.map +1 -1
- package/lib/plugins/pinned-rows/index.js +45 -9
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +42 -7
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/reorder/ReorderPlugin.d.ts.map +1 -1
- package/lib/plugins/reorder/index.js +59 -19
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js +41 -6
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js +48 -13
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/TreePlugin.d.ts +3 -3
- package/lib/plugins/tree/TreePlugin.d.ts.map +1 -1
- package/lib/plugins/tree/index.js +165 -126
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/tree/tree-data.d.ts +6 -6
- package/lib/plugins/tree/tree-data.d.ts.map +1 -1
- package/lib/plugins/tree/tree-detect.d.ts +5 -9
- package/lib/plugins/tree/tree-detect.d.ts.map +1 -1
- package/lib/plugins/tree/types.d.ts +16 -4
- package/lib/plugins/tree/types.d.ts.map +1 -1
- package/lib/plugins/undo-redo/index.js +46 -11
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js +37 -2
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/public.d.ts +104 -13
- package/public.d.ts.map +1 -1
- package/umd/grid.all.umd.js +31 -19
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +18 -6
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js +1 -1
- package/umd/plugins/clipboard.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +2 -0
- package/umd/plugins/editing.umd.js.map +1 -0
- package/umd/plugins/export.umd.js +2 -2
- package/umd/plugins/export.umd.js.map +1 -1
- package/umd/plugins/filtering.umd.js +1 -1
- package/umd/plugins/filtering.umd.js.map +1 -1
- package/umd/plugins/grouping-columns.umd.js +1 -1
- package/umd/plugins/grouping-columns.umd.js.map +1 -1
- package/umd/plugins/grouping-rows.umd.js +1 -1
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/master-detail.umd.js +1 -1
- package/umd/plugins/master-detail.umd.js.map +1 -1
- package/umd/plugins/multi-sort.umd.js +1 -1
- package/umd/plugins/multi-sort.umd.js.map +1 -1
- package/umd/plugins/pinned-rows.umd.js +1 -1
- package/umd/plugins/pinned-rows.umd.js.map +1 -1
- package/umd/plugins/reorder.umd.js +1 -1
- package/umd/plugins/reorder.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
- package/lib/core/internal/column-state.d.ts +0 -124
- package/lib/core/internal/column-state.d.ts.map +0 -1
- package/lib/core/internal/editing.d.ts +0 -76
- package/lib/core/internal/editing.d.ts.map +0 -1
- package/lib/core/internal/editors.d.ts.map +0 -1
- package/lib/core/internal/grid-internals.d.ts +0 -83
- 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
|
|
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(
|
|
168
|
-
return
|
|
202
|
+
function x(i, e, t) {
|
|
203
|
+
return i.id !== void 0 ? String(i.id) : t ? `${t}-${e}` : String(e);
|
|
169
204
|
}
|
|
170
|
-
function
|
|
171
|
-
const t = new Set(
|
|
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(
|
|
175
|
-
const
|
|
176
|
-
for (let
|
|
177
|
-
const
|
|
178
|
-
if (Array.isArray(
|
|
179
|
-
|
|
180
|
-
const h = p(
|
|
181
|
-
for (const
|
|
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
|
|
219
|
+
return o;
|
|
185
220
|
}
|
|
186
|
-
function
|
|
221
|
+
function C() {
|
|
187
222
|
return /* @__PURE__ */ new Set();
|
|
188
223
|
}
|
|
189
|
-
function
|
|
190
|
-
const
|
|
191
|
-
for (let
|
|
192
|
-
const
|
|
193
|
-
if (
|
|
194
|
-
return [
|
|
195
|
-
const
|
|
196
|
-
if (Array.isArray(
|
|
197
|
-
const h =
|
|
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 [
|
|
234
|
+
return [a, ...h];
|
|
200
235
|
}
|
|
201
236
|
}
|
|
202
237
|
return null;
|
|
203
238
|
}
|
|
204
|
-
function
|
|
205
|
-
const
|
|
206
|
-
if (!
|
|
207
|
-
const
|
|
208
|
-
for (let
|
|
209
|
-
|
|
210
|
-
return
|
|
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
|
|
213
|
-
if (!Array.isArray(
|
|
214
|
-
for (const t of
|
|
215
|
-
if (t
|
|
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 _(
|
|
220
|
-
if (!Array.isArray(
|
|
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
|
|
223
|
-
if (!(!t || typeof t != "object"))
|
|
224
|
-
for (const n of e)
|
|
225
|
-
|
|
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
|
|
231
|
-
if (!Array.isArray(
|
|
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
|
|
234
|
-
if (!
|
|
235
|
-
const
|
|
236
|
-
if (Array.isArray(
|
|
237
|
-
const
|
|
238
|
-
|
|
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
|
|
244
|
-
if (!Array.isArray(
|
|
282
|
+
function k(i, e = "children") {
|
|
283
|
+
if (!Array.isArray(i)) return 0;
|
|
245
284
|
let t = 0;
|
|
246
|
-
for (const n of
|
|
285
|
+
for (const n of i) {
|
|
247
286
|
if (!n) continue;
|
|
248
287
|
t++;
|
|
249
|
-
const
|
|
250
|
-
Array.isArray(
|
|
288
|
+
const s = n[e];
|
|
289
|
+
Array.isArray(s) && (t += k(s, e));
|
|
251
290
|
}
|
|
252
291
|
return t;
|
|
253
292
|
}
|
|
254
|
-
const
|
|
255
|
-
class
|
|
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 =
|
|
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 ?? _(
|
|
297
|
-
return
|
|
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 (!
|
|
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
|
|
306
|
-
this.sortState && (
|
|
307
|
-
const
|
|
308
|
-
for (const
|
|
309
|
-
this.rowKeyMap.set(
|
|
310
|
-
return this.previousVisibleKeys =
|
|
311
|
-
...
|
|
312
|
-
__treeKey:
|
|
313
|
-
__treeDepth:
|
|
314
|
-
__treeHasChildren:
|
|
315
|
-
__treeExpanded:
|
|
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((
|
|
322
|
-
const s =
|
|
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
|
-
...
|
|
325
|
-
__stableKey:
|
|
326
|
-
...l ? { [n]: this.withStableKeys(a,
|
|
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
|
|
333
|
-
for (const
|
|
334
|
-
const a =
|
|
335
|
-
|
|
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:
|
|
376
|
+
data: r,
|
|
338
377
|
depth: n,
|
|
339
|
-
hasChildren:
|
|
340
|
-
isExpanded:
|
|
378
|
+
hasChildren: h,
|
|
379
|
+
isExpanded: f,
|
|
341
380
|
parentKey: n > 0 && a.substring(0, a.lastIndexOf("-")) || null
|
|
342
|
-
}),
|
|
381
|
+
}), h && f && o.push(...this.flattenTree(l, t, n + 1));
|
|
343
382
|
}
|
|
344
|
-
return
|
|
383
|
+
return o;
|
|
345
384
|
}
|
|
346
385
|
/** Sort tree recursively, keeping children with parents */
|
|
347
386
|
sortTree(e, t, n) {
|
|
348
|
-
const
|
|
349
|
-
return [...e].sort((
|
|
350
|
-
const
|
|
351
|
-
return
|
|
352
|
-
}).map((
|
|
353
|
-
const
|
|
354
|
-
return Array.isArray(
|
|
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] },
|
|
362
|
-
if (
|
|
363
|
-
const
|
|
364
|
-
const { value: h, row:
|
|
365
|
-
if (
|
|
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${
|
|
368
|
-
} else if (
|
|
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",
|
|
409
|
+
c.className = "tree-spacer", u.appendChild(c);
|
|
371
410
|
}
|
|
372
|
-
const
|
|
373
|
-
if (
|
|
374
|
-
const c =
|
|
375
|
-
c instanceof Node ?
|
|
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
|
-
|
|
378
|
-
return
|
|
416
|
+
y.textContent = String(h ?? "");
|
|
417
|
+
return u.appendChild(y), u;
|
|
379
418
|
};
|
|
380
|
-
return
|
|
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"),
|
|
388
|
-
return
|
|
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:
|
|
429
|
+
row: s.data,
|
|
391
430
|
expanded: this.expandedKeys.has(n),
|
|
392
|
-
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
|
|
409
|
-
const
|
|
410
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
483
|
+
this.expandedKeys = v(this.rows, e, this.config, this.expandedKeys), this.requestRender();
|
|
445
484
|
}
|
|
446
485
|
// #endregion
|
|
447
486
|
}
|
|
448
487
|
export {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
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
|