@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.
- package/all.d.ts +19 -19
- package/all.d.ts.map +1 -1
- package/all.js +1798 -1201
- package/all.js.map +1 -1
- package/index.js +2215 -2026
- 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/editing.d.ts +3 -3
- package/lib/core/internal/editing.d.ts.map +1 -1
- 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 +2 -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 +25 -0
- package/lib/core/internal/validate-config.d.ts.map +1 -0
- package/lib/core/plugin/base-plugin.d.ts +118 -0
- package/lib/core/plugin/base-plugin.d.ts.map +1 -1
- package/lib/core/plugin/index.d.ts +1 -0
- package/lib/core/plugin/index.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 +7 -1
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js +78 -22
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +72 -21
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +53 -2
- 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 +721 -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 +68 -17
- 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 +103 -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 +80 -29
- 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 +62 -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 +156 -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 +75 -22
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js +57 -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 +61 -9
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +58 -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 +75 -19
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js +57 -6
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js +60 -9
- 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 +181 -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/UndoRedoPlugin.d.ts +7 -1
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts.map +1 -1
- package/lib/plugins/undo-redo/index.js +65 -6
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/VisibilityPlugin.d.ts +7 -1
- package/lib/plugins/visibility/VisibilityPlugin.d.ts.map +1 -1
- package/lib/plugins/visibility/index.js +61 -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 +37 -19
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +25 -7
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js +2 -2
- 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/umd/plugins/undo-redo.umd.js +1 -1
- package/umd/plugins/undo-redo.umd.js.map +1 -1
- package/umd/plugins/visibility.umd.js +1 -1
- package/umd/plugins/visibility.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/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,23 @@ const S = {
|
|
|
8
8
|
dragHandle: "⋮⋮",
|
|
9
9
|
toolPanel: "☰"
|
|
10
10
|
};
|
|
11
|
-
class
|
|
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(
|
|
168
|
-
return
|
|
218
|
+
function x(i, e, t) {
|
|
219
|
+
return i.id !== void 0 ? String(i.id) : t ? `${t}-${e}` : String(e);
|
|
169
220
|
}
|
|
170
|
-
function
|
|
171
|
-
const t = new Set(
|
|
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(
|
|
175
|
-
const
|
|
176
|
-
for (let
|
|
177
|
-
const
|
|
178
|
-
if (Array.isArray(
|
|
179
|
-
|
|
180
|
-
const h = p(
|
|
181
|
-
for (const
|
|
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
|
|
235
|
+
return o;
|
|
185
236
|
}
|
|
186
|
-
function
|
|
237
|
+
function C() {
|
|
187
238
|
return /* @__PURE__ */ new Set();
|
|
188
239
|
}
|
|
189
|
-
function
|
|
190
|
-
const
|
|
191
|
-
for (let
|
|
192
|
-
const
|
|
193
|
-
if (
|
|
194
|
-
return [
|
|
195
|
-
const
|
|
196
|
-
if (Array.isArray(
|
|
197
|
-
const h =
|
|
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 [
|
|
250
|
+
return [a, ...h];
|
|
200
251
|
}
|
|
201
252
|
}
|
|
202
253
|
return null;
|
|
203
254
|
}
|
|
204
|
-
function
|
|
205
|
-
const
|
|
206
|
-
if (!
|
|
207
|
-
const
|
|
208
|
-
for (let
|
|
209
|
-
|
|
210
|
-
return
|
|
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
|
|
213
|
-
if (!Array.isArray(
|
|
214
|
-
for (const t of
|
|
215
|
-
if (t
|
|
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 _(
|
|
220
|
-
if (!Array.isArray(
|
|
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
|
|
223
|
-
if (!(!t || typeof t != "object"))
|
|
224
|
-
for (const n of e)
|
|
225
|
-
|
|
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
|
|
231
|
-
if (!Array.isArray(
|
|
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
|
|
234
|
-
if (!
|
|
235
|
-
const
|
|
236
|
-
if (Array.isArray(
|
|
237
|
-
const
|
|
238
|
-
|
|
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
|
|
244
|
-
if (!Array.isArray(
|
|
298
|
+
function k(i, e = "children") {
|
|
299
|
+
if (!Array.isArray(i)) return 0;
|
|
245
300
|
let t = 0;
|
|
246
|
-
for (const n of
|
|
301
|
+
for (const n of i) {
|
|
247
302
|
if (!n) continue;
|
|
248
303
|
t++;
|
|
249
|
-
const
|
|
250
|
-
Array.isArray(
|
|
304
|
+
const s = n[e];
|
|
305
|
+
Array.isArray(s) && (t += k(s, e));
|
|
251
306
|
}
|
|
252
307
|
return t;
|
|
253
308
|
}
|
|
254
|
-
const
|
|
255
|
-
class
|
|
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 =
|
|
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 ?? _(
|
|
297
|
-
return
|
|
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 (!
|
|
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
|
|
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:
|
|
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((
|
|
322
|
-
const s =
|
|
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
|
-
...
|
|
325
|
-
__stableKey:
|
|
326
|
-
...l ? { [n]: this.withStableKeys(a,
|
|
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
|
|
333
|
-
for (const
|
|
334
|
-
const a =
|
|
335
|
-
|
|
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:
|
|
392
|
+
data: r,
|
|
338
393
|
depth: n,
|
|
339
|
-
hasChildren:
|
|
340
|
-
isExpanded:
|
|
394
|
+
hasChildren: h,
|
|
395
|
+
isExpanded: f,
|
|
341
396
|
parentKey: n > 0 && a.substring(0, a.lastIndexOf("-")) || null
|
|
342
|
-
}),
|
|
397
|
+
}), h && f && o.push(...this.flattenTree(l, t, n + 1));
|
|
343
398
|
}
|
|
344
|
-
return
|
|
399
|
+
return o;
|
|
345
400
|
}
|
|
346
401
|
/** Sort tree recursively, keeping children with parents */
|
|
347
402
|
sortTree(e, t, n) {
|
|
348
|
-
const
|
|
349
|
-
return [...e].sort((
|
|
350
|
-
const
|
|
351
|
-
return
|
|
352
|
-
}).map((
|
|
353
|
-
const
|
|
354
|
-
return Array.isArray(
|
|
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] },
|
|
362
|
-
if (
|
|
363
|
-
const
|
|
364
|
-
const { value: h, row:
|
|
365
|
-
if (
|
|
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${
|
|
368
|
-
} else if (
|
|
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",
|
|
425
|
+
c.className = "tree-spacer", u.appendChild(c);
|
|
371
426
|
}
|
|
372
|
-
const
|
|
373
|
-
if (
|
|
374
|
-
const c =
|
|
375
|
-
c instanceof Node ?
|
|
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
|
-
|
|
378
|
-
return
|
|
432
|
+
y.textContent = String(h ?? "");
|
|
433
|
+
return u.appendChild(y), u;
|
|
379
434
|
};
|
|
380
|
-
return
|
|
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"),
|
|
388
|
-
return
|
|
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:
|
|
445
|
+
row: s.data,
|
|
391
446
|
expanded: this.expandedKeys.has(n),
|
|
392
|
-
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
|
|
409
|
-
const
|
|
410
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
499
|
+
this.expandedKeys = v(this.rows, e, this.config, this.expandedKeys), this.requestRender();
|
|
445
500
|
}
|
|
446
501
|
// #endregion
|
|
447
502
|
}
|
|
448
503
|
export {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
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
|