@adaptabletools/adaptable 24.0.3 → 24.0.5

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 (39) hide show
  1. package/package.json +1 -1
  2. package/src/AdaptableInterfaces/IAdaptable.d.ts +7 -0
  3. package/src/Api/AdaptableApi.d.ts +12 -0
  4. package/src/Api/GridApi.d.ts +13 -3
  5. package/src/Api/Implementation/AdaptableApiImpl.d.ts +1 -0
  6. package/src/Api/Implementation/AdaptableApiImpl.js +3 -0
  7. package/src/Api/Implementation/FlashingCellApiImpl.js +3 -8
  8. package/src/Api/Implementation/GridApiImpl.js +1 -1
  9. package/src/Api/Internal/AlertInternalApi.d.ts +7 -0
  10. package/src/Api/Internal/AlertInternalApi.js +42 -9
  11. package/src/Strategy/FlashingCellModule.js +2 -1
  12. package/src/Utilities/Helpers/CellValueHelper.d.ts +20 -0
  13. package/src/Utilities/Helpers/CellValueHelper.js +35 -0
  14. package/src/Utilities/Helpers/Layouts/LayoutHelper.d.ts +5 -0
  15. package/src/Utilities/Helpers/Layouts/LayoutHelper.js +33 -3
  16. package/src/Utilities/Services/CalculatedColumnExpressionService.d.ts +25 -1
  17. package/src/Utilities/Services/CalculatedColumnExpressionService.js +160 -42
  18. package/src/Utilities/Services/DataService.js +10 -6
  19. package/src/Utilities/Services/FlashingCellService.d.ts +12 -0
  20. package/src/Utilities/Services/FlashingCellService.js +40 -3
  21. package/src/Utilities/Services/Interface/ICalculatedColumnExpressionService.d.ts +5 -0
  22. package/src/Utilities/Services/Interface/IQueryLanguageService.d.ts +5 -0
  23. package/src/Utilities/Services/QueryLanguageService.d.ts +6 -0
  24. package/src/Utilities/Services/QueryLanguageService.js +29 -1
  25. package/src/agGrid/AdaptableAgGrid.d.ts +81 -14
  26. package/src/agGrid/AdaptableAgGrid.js +523 -163
  27. package/src/agGrid/AgGridAdapter.d.ts +10 -1
  28. package/src/agGrid/AgGridAdapter.js +16 -0
  29. package/src/agGrid/AgGridOptionsService.js +5 -0
  30. package/src/env.js +2 -2
  31. package/src/layout-manager/src/index.d.ts +51 -10
  32. package/src/layout-manager/src/index.js +334 -91
  33. package/src/layout-manager/src/isLayoutEqual.js +4 -0
  34. package/src/layout-manager/src/rowGroupExpansionMatcher.d.ts +116 -0
  35. package/src/layout-manager/src/rowGroupExpansionMatcher.js +240 -0
  36. package/tsconfig.esm.tsbuildinfo +1 -1
  37. package/vendor/components/Resizable/index.d.ts.map +1 -1
  38. package/vendor/components/Resizable/index.js +22 -10
  39. package/vendor/components/Resizable/index.js.map +1 -1
@@ -0,0 +1,116 @@
1
+ import { IRowNode } from 'ag-grid-enterprise';
2
+ import { BaseLayoutModel, PivotLayoutModel, TableLayoutModel } from './LayoutManagerModel';
3
+ /**
4
+ * #ssrm_row_group_expansion
5
+ *
6
+ * Server-Side Row Model (SSRM) row-group expansion architecture & runtime optimisations:
7
+ *
8
+ * 1. Why SSRM differs from CSRM:
9
+ * - AG Grid forbids `api.onGroupExpandedOrCollapsed()` on SSRM (error #311).
10
+ * - Walking loaded nodes with `setRowNodeExpanded` cannot reach unloaded child groups or exit
11
+ * AG Grid's `ExpandAllStrategy`, and `expandAll()` / `collapseAll()` under AdapTable's default
12
+ * `ssrmExpandAllAffectsAllRows: true` also expand Master Detail rows.
13
+ *
14
+ * 2. Shared pre-compiled matcher + `resetRowGroupExpansion()`:
15
+ * - `AdaptableAgGrid` wraps `gridOptions.isServerSideGroupOpenByDefault` before `createGrid`
16
+ * (delegating non-group Master Detail and SSRM Tree Data rows to the app's callback) and reads
17
+ * `rowGroupExpansionMatcherRef.current`.
18
+ * - Because AG Grid's `ExpandStrategy` caches `isServerSideGroupOpenByDefault` per `rowNode.id`
19
+ * for the life of the strategy, applying `RowGroupValues` updates `rowGroupExpansionMatcherRef`
20
+ * *before* `applyColumnState` (and inside `silentSetCurrentLayout`) and calls
21
+ * `gridApi.resetRowGroupExpansion()` once when the layout has grouped columns.
22
+ *
23
+ * 3. Zero-allocation reversed (leaf-to-root) `Map` trie:
24
+ * - `ExceptionGroupKeys` / `GroupKeys` compile into a trie keyed from leaf (`path[last]`) up to
25
+ * root (`path[0]`), or `null` when empty.
26
+ * - Lookups (`isRowGroupExpandedByMatcher`) allocate zero arrays: empty exceptions return in O(1)
27
+ * without touching `rowNode.parent`; non-empty exceptions exit in O(1) on the first leaf-key
28
+ * mismatch and check `isTerminal` only after walking past `level === 0` (worst case O(depth)).
29
+ *
30
+ * 4. Incremental write-back & microtask burst coalescing:
31
+ * - Most SSRM groups are unloaded, so `ExceptionGroupKeys` is patched/merged incrementally rather
32
+ * than rebuilt from loaded nodes (ignoring stubs, footers, master rows, and non-expandable
33
+ * pivot `leafGroup` rows).
34
+ * - Because `ServerSideExpansionService.expandAll` synchronously fires `rowGroupOpened` for all
35
+ * `N` loaded groups before `expandOrCollapseAll` (and `checkOpenByDefault` fires per row per
36
+ * loaded block under `ExpandAllStrategy`), `LayoutManager` coalesces consecutive same-tick
37
+ * expansion events via `queueMicrotask` into a single layout diff / Redux update and unions
38
+ * loaded paths (`mergeRowGroupExceptionPaths`) so unloaded exceptions are preserved.
39
+ *
40
+ * 5. Early event short-circuit:
41
+ * - `rowGroupOpened` and `expandOrCollapseAll` events that cannot change `RowGroupValues`
42
+ * (non-group/stub/footer/`leafGroup` nodes and `always-*` modes on all row models, plus SSRM
43
+ * default-opens matching the compiled matcher when no batch is pending) are dropped before
44
+ * `getLayoutModelFromGrid` / `isLayoutEqual`.
45
+ */
46
+ export type ReversePathTrieNode = {
47
+ isTerminal: boolean;
48
+ parents?: Map<any, ReversePathTrieNode>;
49
+ };
50
+ export type RowGroupExpansionMatcher = {
51
+ mode: 'always-expanded';
52
+ } | {
53
+ mode: 'always-collapsed';
54
+ } | {
55
+ mode: 'exceptions';
56
+ defaultExpanded: boolean;
57
+ exceptions: Map<any, ReversePathTrieNode> | null;
58
+ };
59
+ export type RowGroupExpansionMatcherRef = {
60
+ current: RowGroupExpansionMatcher | null;
61
+ };
62
+ /**
63
+ * Returns `true` when `node` is a real expandable row-group node whose expand/collapse state
64
+ * can be persisted in `RowGroupValues` (excluding Master Detail rows, SSRM stubs, group footers,
65
+ * non-expandable deepest-level pivot `leafGroup` rows, and hidden SSRM `groupAllowUnbalanced` placeholders).
66
+ */
67
+ export declare function isPersistableGroupNode(node: IRowNode | null | undefined, options?: {
68
+ inPivotMode?: boolean;
69
+ allowUnbalanced?: boolean;
70
+ }): boolean;
71
+ export declare function getLayoutModelGroupedColumns(layout: TableLayoutModel | PivotLayoutModel | null | undefined): string[] | undefined;
72
+ /**
73
+ * Builds the group-key path from the top-level group down to `rowNode`.
74
+ * Stops at `level < 0` (AG Grid's root node) so it never dereferences a missing parent.
75
+ */
76
+ export declare function getRowGroupNodePath(rowNode: IRowNode): any[];
77
+ export declare function compileRowGroupExpansionMatcher(rowGroupValues: BaseLayoutModel['RowGroupValues'], rowGroupedColumns?: string[]): RowGroupExpansionMatcher | null;
78
+ /**
79
+ * Compiles the matcher used by AdapTable's `isServerSideGroupOpenByDefault` for a layout.
80
+ * Returns `null` when the layout has no grouped columns (e.g. an ungrouped layout or Tree Data),
81
+ * so the application's own callback stays in charge of those rows.
82
+ */
83
+ export declare function compileLayoutRowGroupExpansionMatcher(layout: TableLayoutModel | PivotLayoutModel | null | undefined): RowGroupExpansionMatcher | null;
84
+ export declare function isRowGroupExpandedByMatcher(matcher: RowGroupExpansionMatcher, rowNode: IRowNode): boolean;
85
+ /**
86
+ * Server-Side Row Model only: returns `true` when a `rowGroupOpened` event cannot change the
87
+ * persisted `RowGroupValues`, so the (expensive) layout diff can be skipped.
88
+ *
89
+ * AG Grid fires `rowGroupOpened` for every group opened by `isServerSideGroupOpenByDefault`
90
+ * as its block loads, so in an `expanded` layout this runs once per loaded group row.
91
+ * The check is O(depth) with zero allocations and relies on `matcher` being compiled from the current layout.
92
+ */
93
+ export declare function isRowGroupOpenedEventRedundant(params: {
94
+ node: IRowNode | null | undefined;
95
+ expanded: boolean;
96
+ rowGroupDisplay: string | undefined;
97
+ matcher: RowGroupExpansionMatcher | null;
98
+ inPivotMode?: boolean;
99
+ allowUnbalanced?: boolean;
100
+ }): boolean;
101
+ /**
102
+ * Incrementally adds or removes a single group-key path from an exception list.
103
+ * Returns the original array reference when the path is already in the desired state
104
+ * so idempotent SSRM auto-open events do not trigger spurious layout changes.
105
+ */
106
+ export declare function patchRowGroupExceptionPaths(existingPaths: any[][], path: any[], shouldInclude: boolean): any[][];
107
+ /**
108
+ * Unions `addedPaths` into `existingPaths` in O((K + M) * depth) using the reverse trie,
109
+ * preserving unloaded exception paths and returning `existingPaths` when nothing new is added.
110
+ */
111
+ export declare function mergeRowGroupExceptionPaths(existingPaths: any[][], addedPaths: any[][]): any[][];
112
+ /**
113
+ * Removes all paths in `removedPaths` from `existingPaths` in O((K + M) * depth) using the reverse trie,
114
+ * preserving unloaded exception paths and returning `existingPaths` when nothing is removed.
115
+ */
116
+ export declare function subtractRowGroupExceptionPaths(existingPaths: any[][], removedPaths: any[][]): any[][];
@@ -0,0 +1,240 @@
1
+ import { isPivotLayoutModel } from './isPivotLayoutModel';
2
+ function insertPathIntoReverseTrie(root, path) {
3
+ if (!Array.isArray(path) || path.length === 0) {
4
+ return false;
5
+ }
6
+ const leafKey = path[path.length - 1];
7
+ let node = root.get(leafKey);
8
+ if (!node) {
9
+ node = { isTerminal: false };
10
+ root.set(leafKey, node);
11
+ }
12
+ for (let i = path.length - 2; i >= 0; i--) {
13
+ if (!node.parents) {
14
+ node.parents = new Map();
15
+ }
16
+ const key = path[i];
17
+ let parentNode = node.parents.get(key);
18
+ if (!parentNode) {
19
+ parentNode = { isTerminal: false };
20
+ node.parents.set(key, parentNode);
21
+ }
22
+ node = parentNode;
23
+ }
24
+ if (node.isTerminal) {
25
+ return false;
26
+ }
27
+ node.isTerminal = true;
28
+ return true;
29
+ }
30
+ function buildReversePathTrie(paths) {
31
+ if (!paths || paths.length === 0) {
32
+ return null;
33
+ }
34
+ const root = new Map();
35
+ for (let i = 0; i < paths.length; i++) {
36
+ insertPathIntoReverseTrie(root, paths[i]);
37
+ }
38
+ return root.size > 0 ? root : null;
39
+ }
40
+ function hasPathInReverseTrie(root, path) {
41
+ if (!Array.isArray(path) || path.length === 0) {
42
+ return false;
43
+ }
44
+ let node = root.get(path[path.length - 1]);
45
+ if (!node) {
46
+ return false;
47
+ }
48
+ for (let i = path.length - 2; i >= 0; i--) {
49
+ node = node.parents?.get(path[i]);
50
+ if (!node) {
51
+ return false;
52
+ }
53
+ }
54
+ return node.isTerminal;
55
+ }
56
+ function hasRowNodeInReverseTrie(root, rowNode) {
57
+ if (!rowNode || rowNode.level < 0) {
58
+ return false;
59
+ }
60
+ let node = root.get(rowNode.key);
61
+ if (!node) {
62
+ return false;
63
+ }
64
+ let cur = rowNode.parent;
65
+ while (cur && cur.level >= 0) {
66
+ node = node.parents?.get(cur.key);
67
+ if (!node) {
68
+ return false;
69
+ }
70
+ cur = cur.parent;
71
+ }
72
+ return node.isTerminal;
73
+ }
74
+ export function isPersistableGroupNode(node, options) {
75
+ if (!node || !node.group || node.stub || node.footer) {
76
+ return false;
77
+ }
78
+ if (options?.inPivotMode && node.leafGroup) {
79
+ return false;
80
+ }
81
+ if (options?.allowUnbalanced && node.key === '') {
82
+ return false;
83
+ }
84
+ return true;
85
+ }
86
+ export function getLayoutModelGroupedColumns(layout) {
87
+ if (!layout) {
88
+ return undefined;
89
+ }
90
+ return isPivotLayoutModel(layout) ? layout.PivotGroupedColumns : layout.RowGroupedColumns;
91
+ }
92
+ export function getRowGroupNodePath(rowNode) {
93
+ const nodePath = [];
94
+ let currentNode = rowNode;
95
+ while (currentNode && currentNode.level >= 0) {
96
+ nodePath.push(currentNode.key);
97
+ currentNode = currentNode.parent;
98
+ }
99
+ if (nodePath.length > 1) {
100
+ nodePath.reverse();
101
+ }
102
+ return nodePath;
103
+ }
104
+ export function compileRowGroupExpansionMatcher(rowGroupValues, rowGroupedColumns) {
105
+ if (!rowGroupValues) {
106
+ return null;
107
+ }
108
+ if (rowGroupValues.RowGroupDisplay === 'always-expanded') {
109
+ return { mode: 'always-expanded' };
110
+ }
111
+ if (rowGroupValues.RowGroupDisplay === 'always-collapsed') {
112
+ return { mode: 'always-collapsed' };
113
+ }
114
+ if (rowGroupValues.RowGroupDisplay !== 'expanded' &&
115
+ rowGroupValues.RowGroupDisplay !== 'collapsed') {
116
+ return null;
117
+ }
118
+ const defaultExpanded = rowGroupValues.RowGroupDisplay === 'expanded';
119
+ let currentRowGroupedValues = rowGroupValues.Values;
120
+ if (Array.isArray(rowGroupValues.GroupKeys)) {
121
+ const groupedColumnsKey = (rowGroupedColumns || []).join(',');
122
+ const matchingRowGroupColumnValues = rowGroupValues.GroupKeys.find((item) => (item.RowGroupedColumns || []).join(',') === groupedColumnsKey);
123
+ currentRowGroupedValues = matchingRowGroupColumnValues?.Values ?? [];
124
+ }
125
+ return {
126
+ mode: 'exceptions',
127
+ defaultExpanded,
128
+ exceptions: buildReversePathTrie(currentRowGroupedValues),
129
+ };
130
+ }
131
+ export function compileLayoutRowGroupExpansionMatcher(layout) {
132
+ const groupedColumns = getLayoutModelGroupedColumns(layout);
133
+ if (!layout || !groupedColumns?.length) {
134
+ return null;
135
+ }
136
+ return compileRowGroupExpansionMatcher(layout.RowGroupValues, groupedColumns);
137
+ }
138
+ export function isRowGroupExpandedByMatcher(matcher, rowNode) {
139
+ if (matcher.mode === 'always-expanded') {
140
+ return true;
141
+ }
142
+ if (matcher.mode === 'always-collapsed') {
143
+ return false;
144
+ }
145
+ if (!matcher.exceptions) {
146
+ return matcher.defaultExpanded;
147
+ }
148
+ const isException = hasRowNodeInReverseTrie(matcher.exceptions, rowNode);
149
+ return matcher.defaultExpanded ? !isException : isException;
150
+ }
151
+ export function isRowGroupOpenedEventRedundant(params) {
152
+ const { node, expanded, rowGroupDisplay, matcher, inPivotMode, allowUnbalanced } = params;
153
+ if (!isPersistableGroupNode(node, { inPivotMode, allowUnbalanced })) {
154
+ return true;
155
+ }
156
+ if (rowGroupDisplay !== 'expanded' && rowGroupDisplay !== 'collapsed') {
157
+ return true;
158
+ }
159
+ if (!matcher ||
160
+ matcher.mode !== 'exceptions' ||
161
+ matcher.defaultExpanded !== (rowGroupDisplay === 'expanded')) {
162
+ return false;
163
+ }
164
+ return isRowGroupExpandedByMatcher(matcher, node) === expanded;
165
+ }
166
+ function areGroupPathsEqual(a, b) {
167
+ return (a.length === b.length &&
168
+ a.every((value, index) => {
169
+ const other = b[index];
170
+ return value === other || (value !== value && other !== other);
171
+ }));
172
+ }
173
+ export function patchRowGroupExceptionPaths(existingPaths, path, shouldInclude) {
174
+ const firstIndex = existingPaths.findIndex((existing) => areGroupPathsEqual(existing, path));
175
+ if (shouldInclude) {
176
+ return firstIndex !== -1 ? existingPaths : [...existingPaths, path];
177
+ }
178
+ if (firstIndex === -1) {
179
+ return existingPaths;
180
+ }
181
+ const nextPaths = existingPaths.slice(0, firstIndex);
182
+ for (let i = firstIndex + 1; i < existingPaths.length; i++) {
183
+ if (!areGroupPathsEqual(existingPaths[i], path)) {
184
+ nextPaths.push(existingPaths[i]);
185
+ }
186
+ }
187
+ return nextPaths;
188
+ }
189
+ export function mergeRowGroupExceptionPaths(existingPaths, addedPaths) {
190
+ if (!addedPaths.length) {
191
+ return existingPaths;
192
+ }
193
+ if (!existingPaths.length) {
194
+ const root = new Map();
195
+ const deduped = [];
196
+ for (let i = 0; i < addedPaths.length; i++) {
197
+ if (insertPathIntoReverseTrie(root, addedPaths[i])) {
198
+ deduped.push(addedPaths[i]);
199
+ }
200
+ }
201
+ return deduped.length ? deduped : existingPaths;
202
+ }
203
+ const root = new Map();
204
+ for (let i = 0; i < existingPaths.length; i++) {
205
+ insertPathIntoReverseTrie(root, existingPaths[i]);
206
+ }
207
+ let appended = null;
208
+ for (let i = 0; i < addedPaths.length; i++) {
209
+ const candidate = addedPaths[i];
210
+ if (insertPathIntoReverseTrie(root, candidate)) {
211
+ if (!appended) {
212
+ appended = existingPaths.slice();
213
+ }
214
+ appended.push(candidate);
215
+ }
216
+ }
217
+ return appended ?? existingPaths;
218
+ }
219
+ export function subtractRowGroupExceptionPaths(existingPaths, removedPaths) {
220
+ if (!existingPaths.length || !removedPaths.length) {
221
+ return existingPaths;
222
+ }
223
+ const removedTrie = buildReversePathTrie(removedPaths);
224
+ if (!removedTrie) {
225
+ return existingPaths;
226
+ }
227
+ let nextPaths = null;
228
+ for (let i = 0; i < existingPaths.length; i++) {
229
+ const existing = existingPaths[i];
230
+ if (hasPathInReverseTrie(removedTrie, existing)) {
231
+ if (!nextPaths) {
232
+ nextPaths = existingPaths.slice(0, i);
233
+ }
234
+ }
235
+ else if (nextPaths) {
236
+ nextPaths.push(existing);
237
+ }
238
+ }
239
+ return nextPaths ?? existingPaths;
240
+ }