@omnigrid/core 0.1.23 → 0.1.25

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/dist/grid.js CHANGED
@@ -1,4 +1,4 @@
1
- import { applyWrapText, flattenColumns, getColumnGroups, getRowSpans, resolveColSpan } from "./columns";
1
+ import { applyWrapText, flattenColumns, getColumnGroups, getCellValue, getRowSpans, resolveColSpan } from "./columns";
2
2
  import { EventBus } from "./events";
3
3
  import { applyFilterModel, applyQuickFilter, isActiveCondition } from "./filtering";
4
4
  import { PopupManager } from "./ui";
@@ -6,6 +6,8 @@ import { evaluateAutoOverlay } from "./overlays";
6
6
  import { IconRegistry } from "./icons";
7
7
  import { SlotManager } from "./slots";
8
8
  import { Store } from "./store";
9
+ import { DataPipeline } from "./pipeline";
10
+ import { buildGroupTree, computeAggregations, flattenTree } from "./groupingPipeline";
9
11
  import { Virtualizer } from "./virtualizer";
10
12
  export class Grid {
11
13
  constructor(options) {
@@ -14,9 +16,15 @@ export class Grid {
14
16
  this.pluginRegistrations = new Map();
15
17
  this.dataProcessors = new Set();
16
18
  this.icons = new IconRegistry();
19
+ this.methods = {};
17
20
  this.processedDataCache = null;
18
21
  /** Output of the built-in filter stage; sits in front of every data processor. */
19
22
  this.filteredDataCache = null;
23
+ /** Flattened grouped rows (TreeRowNode[]), invalidated on structural/group changes. */
24
+ this.groupedRowsCache = null;
25
+ this.groupedRowsRevision = -1;
26
+ /** Column id -> aggregation function map, registered by aggregation plugins. */
27
+ this.aggregationFuncs = new Map();
20
28
  this.filterModel = {};
21
29
  this.filterMenuProviders = 0;
22
30
  this.popups = new PopupManager((popup) => this.events.emit("popupChange", popup));
@@ -26,6 +34,10 @@ export class Grid {
26
34
  this.hasData = true;
27
35
  this.overlayState = { type: null };
28
36
  this.overlayManual = false;
37
+ /** Normalized cell flash configuration. `false` when disabled. */
38
+ this.cellFlash = false;
39
+ /** Cells currently flashed: key `${rowId}:${columnId}` → expiry timestamp. */
40
+ this.flashedCells = new Map();
29
41
  /**
30
42
  * Separate ephemeral scroll position that is NOT stored in the Store.
31
43
  *
@@ -40,8 +52,15 @@ export class Grid {
40
52
  columns: applyWrapText(options.columns, options.wrapText),
41
53
  viewport: { width: 0, height: 0, scrollTop: 0, scrollLeft: 0 },
42
54
  rowHeight: options.rowHeight ?? 32,
55
+ groupBy: [],
56
+ expandedGroups: {},
57
+ groupColumnMode: 'single',
58
+ groupColumnHeader: 'Group',
59
+ showChildCount: true,
60
+ groupRowRenderer: undefined,
43
61
  rowOverscan: options.rowOverscan ?? 5,
44
62
  columnOverscan: options.columnOverscan ?? 2,
63
+ flashedCells: new Map(),
45
64
  overlay: { type: null },
46
65
  quickFilter: options.quickFilter ?? "",
47
66
  };
@@ -51,6 +70,13 @@ export class Grid {
51
70
  this.loading = options.loading ?? false;
52
71
  this.hasData = options.data !== undefined && options.data !== null;
53
72
  this.wrapTextAll = options.wrapText;
73
+ const raw = options.cellFlash;
74
+ this.cellFlash =
75
+ raw === true
76
+ ? { enabled: true, durationMs: 1000 }
77
+ : typeof raw === "number" && raw > 0
78
+ ? { enabled: true, durationMs: raw }
79
+ : false;
54
80
  if (options.filterModel)
55
81
  this.filterModel = Grid.cloneFilterModel(options.filterModel);
56
82
  this.virtualizer = new Virtualizer({
@@ -72,6 +98,13 @@ export class Grid {
72
98
  this.events.emit("slotsChange", { slot, mounts });
73
99
  },
74
100
  });
101
+ this.pipeline = new DataPipeline(() => {
102
+ this.processedDataCache = null;
103
+ this.groupedRowsCache = null;
104
+ this.groupedRowsRevision = -1;
105
+ if (!this.destroyed)
106
+ this.recomputeOverlay();
107
+ });
75
108
  this.store.subscribe(() => this.events.emit("stateChange", this.store.getState()));
76
109
  options.plugins?.forEach((plugin) => this.registerPlugin(plugin));
77
110
  this.recomputeOverlay();
@@ -79,7 +112,7 @@ export class Grid {
79
112
  /** Returns the calculated width for a visible column, including off-screen columns. */
80
113
  getColumnWidth(columnId) {
81
114
  const state = this.getState();
82
- const visibleColumns = flattenColumns(state.columns).filter((column) => !column.hidden);
115
+ const visibleColumns = this.getVisibleLeafColumns();
83
116
  if (!visibleColumns.some((column) => column.id === columnId))
84
117
  return undefined;
85
118
  const pinnedLeft = visibleColumns.filter((column) => column.pinned === "left");
@@ -103,6 +136,65 @@ export class Grid {
103
136
  getState() {
104
137
  return this.store.getState();
105
138
  }
139
+ /** Returns the row hierarchy capability registered by the active row-model plugin. @api */
140
+ getRowHierarchy() {
141
+ return this.rowHierarchy;
142
+ }
143
+ /**
144
+ * Registers the row hierarchy capability for composite row models.
145
+ * @param hierarchy - The active row hierarchy implementation.
146
+ * @returns Cleanup callback to unregister the provider.
147
+ * @api
148
+ */
149
+ registerRowHierarchy(hierarchy) {
150
+ this.assertActive();
151
+ if (this.rowHierarchy && this.rowHierarchy !== hierarchy) {
152
+ throw new Error("A row hierarchy provider is already registered for this grid");
153
+ }
154
+ this.rowHierarchy = hierarchy;
155
+ return () => {
156
+ if (this.rowHierarchy === hierarchy)
157
+ this.rowHierarchy = undefined;
158
+ };
159
+ }
160
+ /**
161
+ * Updates the grid state via partial patch or functional updater.
162
+ * Accessible by plugins to update their contributed state slices.
163
+ * @param updater - Partial state patch or reducer function.
164
+ * @api
165
+ */
166
+ setState(updater) {
167
+ this.assertActive();
168
+ this.filteredDataCache = null;
169
+ this.processedDataCache = null;
170
+ this.groupedRowsCache = null;
171
+ this.groupedRowsRevision = -1;
172
+ this.revision += 1;
173
+ this.store.setState(updater);
174
+ this.recomputeOverlay();
175
+ }
176
+ /**
177
+ * Registers methods dynamically contributed by plugins.
178
+ * These methods are attached both to `api.methods` and directly to `api`.
179
+ * @param methods - Methods to register.
180
+ * @returns Cleanup callback to unregister the methods.
181
+ * @api
182
+ */
183
+ registerMethods(methods) {
184
+ this.assertActive();
185
+ const registeredKeys = [];
186
+ for (const [key, value] of Object.entries(methods)) {
187
+ this.methods[key] = value;
188
+ this[key] = value;
189
+ registeredKeys.push(key);
190
+ }
191
+ return () => {
192
+ for (const key of registeredKeys) {
193
+ delete this.methods[key];
194
+ delete this[key];
195
+ }
196
+ };
197
+ }
106
198
  /** Returns the current ephemeral scroll position (not part of Store state). */
107
199
  getScrollPosition() {
108
200
  return this.scrollPosition;
@@ -120,6 +212,28 @@ export class Grid {
120
212
  this.scrollPosition = nextPosition;
121
213
  this.events.emit("scrollTo", nextPosition);
122
214
  }
215
+ /**
216
+ * Returns the flat array of visible leaf columns.
217
+ *
218
+ * A column is visible when it is not explicitly `hidden`. In `'single'` group
219
+ * column mode with active grouping, all grouped columns except the primary
220
+ * one are hidden.
221
+ */
222
+ getVisibleLeafColumns() {
223
+ const state = this.getState();
224
+ return flattenColumns(state.columns).filter((column) => {
225
+ if (column.hidden)
226
+ return false;
227
+ if (state.groupBy.length > 0 && state.groupColumnMode === "single") {
228
+ const isGrouped = state.groupBy.some((field) => column.id === field || column.field === field);
229
+ if (isGrouped) {
230
+ const primary = state.groupBy[0];
231
+ return column.id === primary || column.field === primary;
232
+ }
233
+ }
234
+ return true;
235
+ });
236
+ }
123
237
  getViewportData() {
124
238
  const state = this.getState();
125
239
  const processedData = this.getProcessedData();
@@ -129,8 +243,8 @@ export class Grid {
129
243
  // array of leaf columns. The hierarchy lives in `state.columns`;
130
244
  // groups are projected onto the visible leaf order in `columnGroups`
131
245
  // so adapters can render stacked group header rows.
132
- const visibleColumns = flattenColumns(state.columns).filter((column) => !column.hidden);
133
- const columnGroups = getColumnGroups(state.columns, (leaf) => !leaf.hidden);
246
+ const visibleColumns = this.getVisibleLeafColumns();
247
+ const columnGroups = getColumnGroups(state.columns, (leaf) => visibleColumns.includes(leaf));
134
248
  // Pre-compute group layout metadata for adapters:
135
249
  // - `headerRowCount`: number of group header rows above the leaf row
136
250
  // - `columnGroupDepth`: maps each leaf column's flat visible index to
@@ -179,15 +293,17 @@ export class Grid {
179
293
  : { start: 0, end: 0 };
180
294
  const columnRange = Grid.expandColumnRangeForSpans(scrollable, baseColumnRange);
181
295
  const hasVariable = this.virtualizer.hasVariableHeights;
182
- const rowRange = this.virtualizer.getRowRange(processedData.length, this.scrollPosition.scrollTop, state.viewport.height, hasVariable);
296
+ const grouped = this.getGroupedRows();
297
+ const rowCount = grouped.length > 0 ? grouped.length : processedData.length;
298
+ const rowRange = this.virtualizer.getRowRange(rowCount, this.scrollPosition.scrollTop, state.viewport.height, hasVariable);
183
299
  // The rows that actually intersect the viewport (no overscan): the
184
300
  // adapter binds them eagerly so a recycled node never shows the data
185
301
  // of a different row.
186
- const visibleRowRange = this.virtualizer.getVisibleRowRange(processedData.length, this.scrollPosition.scrollTop, state.viewport.height);
187
- const rowOffsets = hasVariable
302
+ const visibleRowRange = this.virtualizer.getVisibleRowRange(rowCount, this.scrollPosition.scrollTop, state.viewport.height);
303
+ const rowOffsets = hasVariable && grouped.length === 0
188
304
  ? Array.from({ length: rowRange.end - rowRange.start }, (_, i) => this.virtualizer.getRowTop(rowRange.start + i, processedData.length))
189
305
  : undefined;
190
- const rowHeights = hasVariable
306
+ const rowHeights = hasVariable && grouped.length === 0
191
307
  ? Array.from({ length: rowRange.end - rowRange.start }, (_, i) => this.virtualizer.getRowHeight(rowRange.start + i))
192
308
  : undefined;
193
309
  // Offset composition:
@@ -218,12 +334,41 @@ export class Grid {
218
334
  };
219
335
  });
220
336
  return {
221
- rows: processedData.slice(rowRange.start, rowRange.end).map((data, index) => {
337
+ rows: (grouped.length > 0 ? grouped : processedData).slice(rowRange.start, rowRange.end).map((row, index) => {
222
338
  const rowIndex = rowRange.start + index;
339
+ if (grouped.length > 0) {
340
+ const node = row;
341
+ if (node.type === 'group') {
342
+ return {
343
+ id: node.id,
344
+ data: undefined,
345
+ index: rowIndex,
346
+ level: node.level,
347
+ type: 'group',
348
+ group: node,
349
+ offset: rowIndex * state.rowHeight,
350
+ height: state.rowHeight,
351
+ };
352
+ }
353
+ return {
354
+ id: node.id,
355
+ data: node.data,
356
+ index: rowIndex,
357
+ level: node.level,
358
+ type: 'leaf',
359
+ group: node.parent,
360
+ offset: rowIndex * state.rowHeight,
361
+ height: state.rowHeight,
362
+ };
363
+ }
364
+ const data = row;
223
365
  return {
224
366
  id: this.getRowId(data, rowIndex),
225
367
  data,
226
368
  index: rowIndex,
369
+ level: 0,
370
+ type: 'leaf',
371
+ group: undefined,
227
372
  offset: rowOffsets ? rowOffsets[index] : rowIndex * state.rowHeight,
228
373
  height: rowHeights ? rowHeights[index] : state.rowHeight,
229
374
  };
@@ -246,7 +391,7 @@ export class Grid {
246
391
  rowOffsets,
247
392
  rowHeights,
248
393
  totalWidth,
249
- totalHeight: this.virtualizer.getTotalHeight(processedData.length),
394
+ totalHeight: this.virtualizer.getTotalHeight(rowCount),
250
395
  };
251
396
  }
252
397
  /**
@@ -332,10 +477,183 @@ export class Grid {
332
477
  // optimization for DOM Pool operation with large row counts.
333
478
  if (this.processedDataCache !== null)
334
479
  return this.processedDataCache;
335
- const result = [...this.dataProcessors].reduce((data, processor) => processor(data), this.getFilteredData());
480
+ const state = this.getState();
481
+ const filtered = this.getFilteredData();
482
+ const legacyProcessed = [...this.dataProcessors].reduce((data, processor) => processor(data), filtered);
483
+ const result = this.pipeline.process(legacyProcessed, state);
336
484
  this.processedDataCache = result;
337
485
  return result;
338
486
  }
487
+ /**
488
+ * Returns the active dataset consumed by the virtualizer and DOM pool.
489
+ * When grouping or a custom row model is active, returns the transformed rows;
490
+ * otherwise returns the processed data rows.
491
+ * @api
492
+ */
493
+ getRows() {
494
+ const customRows = typeof this.getGroupedRows === "function" ? this.getGroupedRows() : undefined;
495
+ return customRows && customRows.length > 0 ? customRows : this.getProcessedData();
496
+ }
497
+ /**
498
+ * Returns the flattened `TreeRowNode[]` consumed by the virtualizer when
499
+ * grouping is active. Rebuilds the tree + aggregates only when the
500
+ * structural revision changes (data / columns / groupBy / expanded state).
501
+ *
502
+ * @returns The flattened group/data rows, empty when grouping is disabled.
503
+ * @api
504
+ */
505
+ getGroupedRows() {
506
+ const state = this.getState();
507
+ if (!state.groupBy || state.groupBy.length === 0) {
508
+ this.groupedRowsCache = null;
509
+ this.groupedRowsRevision = -1;
510
+ return [];
511
+ }
512
+ const revision = this.getRevision();
513
+ if (this.groupedRowsCache !== null && this.groupedRowsRevision === revision) {
514
+ return this.groupedRowsCache;
515
+ }
516
+ const processed = this.getProcessedData();
517
+ const root = buildGroupTree(processed, state.groupBy, state.expandedGroups, this.resolveRowId);
518
+ if (!root)
519
+ return [];
520
+ const aggregations = Object.fromEntries(this.aggregationFuncs);
521
+ computeAggregations(root, aggregations);
522
+ const flat = flattenTree(root, state.expandedGroups);
523
+ this.groupedRowsCache = flat;
524
+ this.groupedRowsRevision = revision;
525
+ return flat;
526
+ }
527
+ /**
528
+ * Sets the grouping fields. Replaces any existing grouping and resets the
529
+ * expanded state to all-expanded. Scroll position is reset to the top.
530
+ *
531
+ * @param fields - Grouping fields in nesting order, or empty/null to disable grouping.
532
+ * @api
533
+ */
534
+ setGroupBy(fields, expandedGroups) {
535
+ this.assertActive();
536
+ const next = fields ?? [];
537
+ const state = this.getState();
538
+ const changed = next.length !== state.groupBy.length ||
539
+ next.some((field, index) => field !== state.groupBy[index]) ||
540
+ JSON.stringify(expandedGroups ?? {}) !== JSON.stringify(state.expandedGroups);
541
+ if (!changed)
542
+ return;
543
+ this.groupedRowsCache = null;
544
+ this.groupedRowsRevision = -1;
545
+ this.revision += 1;
546
+ this.store.setState({ groupBy: next, expandedGroups: expandedGroups ?? {} });
547
+ this.scrollTo({ scrollTop: 0 });
548
+ this.recomputeOverlay();
549
+ }
550
+ /**
551
+ * Toggles the expanded state of a single group.
552
+ *
553
+ * @param groupId - Stable group id (the `id` field of a `GroupRowNode`).
554
+ * @api
555
+ */
556
+ toggleGroup(groupId) {
557
+ this.assertActive();
558
+ const state = this.getState();
559
+ // `undefined` means expanded, so toggling an unmarked group collapses it.
560
+ const next = { ...state.expandedGroups };
561
+ next[groupId] = state.expandedGroups[groupId] === false;
562
+ this.groupedRowsCache = null;
563
+ this.revision += 1;
564
+ this.store.setState({ expandedGroups: next });
565
+ }
566
+ /** Expands every group. @api */
567
+ expandAll() {
568
+ this.assertActive();
569
+ const state = this.getState();
570
+ const next = { ...state.expandedGroups };
571
+ this.getGroupedRows()
572
+ .filter((row) => row.type === 'group')
573
+ .forEach((group) => {
574
+ next[group.id] = true;
575
+ });
576
+ this.groupedRowsCache = null;
577
+ this.revision += 1;
578
+ this.store.setState({ expandedGroups: next });
579
+ }
580
+ /** Collapses every group. @api */
581
+ collapseAll() {
582
+ this.assertActive();
583
+ const state = this.getState();
584
+ const next = { ...state.expandedGroups };
585
+ this.getGroupedRows()
586
+ .filter((row) => row.type === 'group')
587
+ .forEach((group) => {
588
+ next[group.id] = false;
589
+ });
590
+ this.groupedRowsCache = null;
591
+ this.revision += 1;
592
+ this.store.setState({ expandedGroups: next });
593
+ }
594
+ /** Replaces the expanded-state map for groups. @api */
595
+ setExpandedGroups(expandedGroups) {
596
+ this.assertActive();
597
+ const state = this.getState();
598
+ const next = { ...expandedGroups };
599
+ const changed = JSON.stringify(next) !== JSON.stringify(state.expandedGroups);
600
+ if (!changed)
601
+ return;
602
+ this.groupedRowsCache = null;
603
+ this.revision += 1;
604
+ this.store.setState({ expandedGroups: next });
605
+ }
606
+ /**
607
+ * Registers column id -> aggregation function mappings. Called by
608
+ * aggregation plugins (e.g. `@omnigrid/aggregation-plugin`). Replaces any
609
+ * previously registered functions.
610
+ * @param funcs - Column id to aggregation function map.
611
+ * @returns Unregister function.
612
+ * @api
613
+ */
614
+ registerAggregationFuncs(funcs) {
615
+ this.assertActive();
616
+ for (const [key, func] of Object.entries(funcs)) {
617
+ this.aggregationFuncs.set(key, func);
618
+ }
619
+ this.groupedRowsCache = null;
620
+ this.groupedRowsRevision = -1;
621
+ const registeredKeys = Object.keys(funcs);
622
+ const unregister = () => {
623
+ for (const key of registeredKeys) {
624
+ this.aggregationFuncs.delete(key);
625
+ }
626
+ this.groupedRowsCache = null;
627
+ this.groupedRowsRevision = -1;
628
+ this.revision += 1;
629
+ };
630
+ return unregister;
631
+ }
632
+ /** Configures the group column UI mode and header. @api */
633
+ setGroupColumnConfig(config) {
634
+ this.assertActive();
635
+ const state = this.getState();
636
+ const nextMode = config.mode ?? state.groupColumnMode;
637
+ const nextHeader = config.header ?? state.groupColumnHeader;
638
+ const nextShowChildCount = config.showChildCount ?? state.showChildCount;
639
+ const nextGroupRowRenderer = config.groupRowRenderer === null ? undefined : (config.groupRowRenderer ?? state.groupRowRenderer);
640
+ if (state.groupColumnMode === nextMode &&
641
+ state.groupColumnHeader === nextHeader &&
642
+ state.showChildCount === nextShowChildCount &&
643
+ state.groupRowRenderer === nextGroupRowRenderer)
644
+ return;
645
+ this.revision += 1;
646
+ this.store.setState({
647
+ groupColumnMode: nextMode,
648
+ groupColumnHeader: nextHeader,
649
+ showChildCount: nextShowChildCount,
650
+ groupRowRenderer: nextGroupRowRenderer,
651
+ });
652
+ }
653
+ /** Sets or clears the custom group row renderer. @api */
654
+ setGroupRowRenderer() {
655
+ // Group row rendering is handled by plugins/adapters.
656
+ }
339
657
  getFilteredData() {
340
658
  if (this.filteredDataCache !== null)
341
659
  return this.filteredDataCache;
@@ -365,6 +683,8 @@ export class Grid {
365
683
  this.filterModel = next;
366
684
  this.filteredDataCache = null;
367
685
  this.processedDataCache = null;
686
+ this.groupedRowsCache = null;
687
+ this.groupedRowsRevision = -1;
368
688
  this.revision += 1;
369
689
  this.scrollTo({ scrollTop: 0 });
370
690
  this.store.setState({});
@@ -409,6 +729,8 @@ export class Grid {
409
729
  return;
410
730
  this.filteredDataCache = null;
411
731
  this.processedDataCache = null;
732
+ this.groupedRowsCache = null;
733
+ this.groupedRowsRevision = -1;
412
734
  this.revision += 1;
413
735
  this.store.setState({ quickFilter: nextQuery });
414
736
  this.scrollTo({ scrollTop: 0 });
@@ -540,6 +862,8 @@ export class Grid {
540
862
  const nextData = data ?? [];
541
863
  this.filteredDataCache = null;
542
864
  this.processedDataCache = null;
865
+ this.groupedRowsCache = null;
866
+ this.groupedRowsRevision = -1;
543
867
  this.virtualizer.resetAllRowHeights();
544
868
  this.revision += 1;
545
869
  this.store.setState({ data: nextData });
@@ -562,6 +886,8 @@ export class Grid {
562
886
  this.hasData = true;
563
887
  this.filteredDataCache = null;
564
888
  this.processedDataCache = null;
889
+ this.groupedRowsCache = null;
890
+ this.groupedRowsRevision = -1;
565
891
  this.revision += 1;
566
892
  this.store.setState({ data: nextData });
567
893
  this.events.emit("dataChange", nextData);
@@ -632,6 +958,33 @@ export class Grid {
632
958
  affectedIndexes.add(index);
633
959
  }
634
960
  }
961
+ // ---------- cell flash on update ----------
962
+ if (this.cellFlash !== false && updated.length > 0) {
963
+ const state = this.store.getState();
964
+ const leafColumns = flattenColumns(state.columns).filter((column) => column.field !== undefined);
965
+ // Lazy cleanup: drop entries older than the flash duration so the map
966
+ // doesn't grow unboundedly and cells can re-flash later.
967
+ const cutoff = Date.now() - this.cellFlash.durationMs;
968
+ for (const [key, ts] of this.flashedCells) {
969
+ if (ts < cutoff) {
970
+ this.flashedCells.delete(key);
971
+ }
972
+ }
973
+ const now = Date.now();
974
+ for (const { id, index, data: newRow } of updated) {
975
+ const oldRow = currentData[index];
976
+ if (oldRow === undefined)
977
+ continue;
978
+ for (const column of leafColumns) {
979
+ const oldValue = getCellValue(oldRow, column);
980
+ const newValue = getCellValue(newRow, column);
981
+ if (oldValue !== newValue) {
982
+ this.flashedCells.set(`${id}:${column.id}`, now);
983
+ }
984
+ }
985
+ }
986
+ this.store.setState({ flashedCells: new Map(this.flashedCells) });
987
+ }
635
988
  // ---------- adds ----------
636
989
  const insertAt = Math.min(Math.max(transaction.addIndex ?? nextData.length, 0), nextData.length);
637
990
  if (transaction.add) {
@@ -662,6 +1015,8 @@ export class Grid {
662
1015
  }
663
1016
  this.filteredDataCache = null;
664
1017
  this.processedDataCache = null;
1018
+ this.groupedRowsCache = null;
1019
+ this.groupedRowsRevision = -1;
665
1020
  this.revision += 1;
666
1021
  this.store.setState({ data: nextData });
667
1022
  this.events.emit("dataChange", nextData);
@@ -727,6 +1082,8 @@ export class Grid {
727
1082
  this.assertActive();
728
1083
  this.filteredDataCache = null;
729
1084
  this.processedDataCache = null;
1085
+ this.groupedRowsCache = null;
1086
+ this.groupedRowsRevision = -1;
730
1087
  this.revision += 1;
731
1088
  this.store.setState({ columns: applyWrapText(columns, this.wrapTextAll) });
732
1089
  this.recomputeOverlay();
@@ -735,6 +1092,8 @@ export class Grid {
735
1092
  this.assertActive();
736
1093
  this.dataProcessors.add(processor);
737
1094
  this.processedDataCache = null;
1095
+ this.groupedRowsCache = null;
1096
+ this.groupedRowsRevision = -1;
738
1097
  this.recomputeOverlay();
739
1098
  const unregister = () => {
740
1099
  this.dataProcessors.delete(processor);
@@ -888,9 +1247,16 @@ export class Grid {
888
1247
  destroy() {
889
1248
  if (this.destroyed)
890
1249
  return;
1250
+ this.flashedCells.clear();
891
1251
  this.cleanupPlugins.forEach((cleanup) => cleanup());
892
1252
  this.cleanupPlugins.clear();
893
1253
  this.dataProcessors.clear();
1254
+ this.pipeline.clear();
1255
+ this.rowHierarchy = undefined;
1256
+ for (const key of Object.keys(this.methods)) {
1257
+ delete this.methods[key];
1258
+ delete this[key];
1259
+ }
894
1260
  this.popups.close();
895
1261
  this.filteredDataCache = null;
896
1262
  this.processedDataCache = null;
@@ -0,0 +1,49 @@
1
+ import type { AggregationFunc, DataRowNode, GroupRowNode, RowId, TreeRowNode } from "./types";
2
+ /** Internal mutable node used while building the group tree. */
3
+ interface BuildGroupNode<T> extends GroupRowNode<T> {
4
+ /** Leaf rows grouped directly under this node. */
5
+ leaves: DataRowNode<T>[];
6
+ }
7
+ /**
8
+ * Builds a group tree from flat data.
9
+ *
10
+ * Rows are inserted level by level according to `groupBy`. The result is a
11
+ * rooted tree whose root is a synthetic group (level -1). Use
12
+ * `flattenTree` to obtain the linear `TreeRowNode[]` consumed by the
13
+ * virtualizer.
14
+ *
15
+ * @param data - Filtered/sorted flat row data.
16
+ * @param groupBy - Grouping fields in nesting order.
17
+ * @param expandedGroups - Initial expanded state keyed by group id.
18
+ * @param getRowId - Stable row id resolver.
19
+ * @returns The root group node, or `null` when `groupBy` is empty.
20
+ * @api
21
+ */
22
+ export declare function buildGroupTree<T>(data: T[], groupBy: string[], expandedGroups: Record<string, boolean>, getRowId: (row: T, index: number) => RowId): BuildGroupNode<T> | null;
23
+ /**
24
+ * Flattens a group tree into the linear array consumed by the virtualizer.
25
+ *
26
+ * Only expanded groups contribute their descendants to the output; a collapsed
27
+ * group appears as a single row. Group `expanded` is re-derived from
28
+ * `expandedGroups` on every call, so toggling a group only requires re-flatten
29
+ * (no tree rebuild).
30
+ *
31
+ * @param root - Root group node from `buildGroupTree`.
32
+ * @param expandedGroups - Current expanded state keyed by group id.
33
+ * @returns The flattened `TreeRowNode[]` in pre-order.
34
+ * @api
35
+ */
36
+ export declare function flattenTree<T>(root: BuildGroupNode<T> | null, expandedGroups: Record<string, boolean>): TreeRowNode<T>[];
37
+ /**
38
+ * Computes per-column aggregates for every group in the tree (bottom-up).
39
+ *
40
+ * Aggregates cover all descendant leaf rows. Results are written into each
41
+ * group node's `aggregations` map and `childrenCount`.
42
+ *
43
+ * @param root - Root group node.
44
+ * @param aggregations - Column id -> aggregation function map, provided by an
45
+ * aggregation plugin (e.g. `@omnigrid/aggregation-plugin`).
46
+ * @api
47
+ */
48
+ export declare function computeAggregations<T>(root: BuildGroupNode<T> | null, aggregations: Record<string, AggregationFunc<T>>): void;
49
+ export {};