@mui/x-data-grid-premium 8.19.0 → 8.21.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +174 -0
  2. package/DataGridPremium/DataGridPremium.d.ts +1 -1
  3. package/DataGridPremium/DataGridPremium.js +27 -1
  4. package/DataGridPremium/useDataGridPremiumComponent.d.ts +1 -1
  5. package/esm/DataGridPremium/DataGridPremium.d.ts +1 -1
  6. package/esm/DataGridPremium/DataGridPremium.js +27 -1
  7. package/esm/DataGridPremium/useDataGridPremiumComponent.d.ts +1 -1
  8. package/esm/hooks/features/clipboard/useGridClipboardImport.js +6 -0
  9. package/esm/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
  10. package/esm/hooks/features/rowGrouping/useGridRowGrouping.js +21 -17
  11. package/esm/hooks/features/rowReorder/operations.d.ts +7 -27
  12. package/esm/hooks/features/rowReorder/operations.js +133 -274
  13. package/esm/hooks/features/rowReorder/rowGroupingReorderExecutor.d.ts +2 -0
  14. package/esm/hooks/features/rowReorder/rowGroupingReorderExecutor.js +3 -0
  15. package/esm/hooks/features/rowReorder/rowGroupingReorderValidator.d.ts +2 -0
  16. package/esm/hooks/features/rowReorder/{reorderValidator.js → rowGroupingReorderValidator.js} +2 -22
  17. package/esm/hooks/features/rows/useGridRowsOverridableMethods.d.ts +3 -3
  18. package/esm/hooks/features/rows/useGridRowsOverridableMethods.js +61 -7
  19. package/esm/index.js +1 -1
  20. package/hooks/features/clipboard/useGridClipboardImport.js +6 -0
  21. package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
  22. package/hooks/features/rowGrouping/useGridRowGrouping.js +20 -16
  23. package/hooks/features/rowReorder/operations.d.ts +7 -27
  24. package/hooks/features/rowReorder/operations.js +136 -279
  25. package/hooks/features/rowReorder/rowGroupingReorderExecutor.d.ts +2 -0
  26. package/hooks/features/rowReorder/rowGroupingReorderExecutor.js +9 -0
  27. package/hooks/features/rowReorder/rowGroupingReorderValidator.d.ts +2 -0
  28. package/hooks/features/rowReorder/rowGroupingReorderValidator.js +102 -0
  29. package/hooks/features/rows/useGridRowsOverridableMethods.d.ts +3 -3
  30. package/hooks/features/rows/useGridRowsOverridableMethods.js +61 -7
  31. package/index.js +1 -1
  32. package/package.json +5 -5
  33. package/esm/hooks/features/rowReorder/reorderExecutor.d.ts +0 -15
  34. package/esm/hooks/features/rowReorder/reorderExecutor.js +0 -25
  35. package/esm/hooks/features/rowReorder/reorderValidator.d.ts +0 -16
  36. package/esm/hooks/features/rowReorder/types.d.ts +0 -42
  37. package/esm/hooks/features/rowReorder/types.js +0 -1
  38. package/esm/hooks/features/rowReorder/utils.d.ts +0 -127
  39. package/esm/hooks/features/rowReorder/utils.js +0 -343
  40. package/hooks/features/rowReorder/reorderExecutor.d.ts +0 -15
  41. package/hooks/features/rowReorder/reorderExecutor.js +0 -31
  42. package/hooks/features/rowReorder/reorderValidator.d.ts +0 -16
  43. package/hooks/features/rowReorder/reorderValidator.js +0 -122
  44. package/hooks/features/rowReorder/types.d.ts +0 -42
  45. package/hooks/features/rowReorder/types.js +0 -5
  46. package/hooks/features/rowReorder/utils.d.ts +0 -127
  47. package/hooks/features/rowReorder/utils.js +0 -360
@@ -8,4 +8,4 @@ export declare const rowGroupingStateInitializer: GridStateInitializer<Pick<Data
8
8
  * @requires useGridRows (state, method) - can be after, async only
9
9
  * @requires useGridParamsApi (method) - can be after, async only
10
10
  */
11
- export declare const useGridRowGrouping: (apiRef: RefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, "initialState" | "rowGroupingModel" | "onRowGroupingModelChange" | "isGroupExpandedByDefault" | "rowGroupingColumnMode" | "disableRowGrouping" | "slotProps" | "slots" | "dataSource" | "treeData">) => void;
11
+ export declare const useGridRowGrouping: (apiRef: RefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, "initialState" | "rowGroupingModel" | "onRowGroupingModelChange" | "isGroupExpandedByDefault" | "rowGroupingColumnMode" | "disableRowGrouping" | "slotProps" | "slots" | "dataSource" | "treeData" | "isValidRowReorder">) => void;
@@ -13,7 +13,7 @@ var _xDataGridPro = require("@mui/x-data-grid-pro");
13
13
  var _internals = require("@mui/x-data-grid-pro/internals");
14
14
  var _gridRowGroupingSelector = require("./gridRowGroupingSelector");
15
15
  var _gridRowGroupingUtils = require("./gridRowGroupingUtils");
16
- var _reorderValidator = require("../rowReorder/reorderValidator");
16
+ var _rowGroupingReorderValidator = require("../rowReorder/rowGroupingReorderValidator");
17
17
  const rowGroupingStateInitializer = (state, props, apiRef) => {
18
18
  apiRef.current.caches.rowGrouping = {
19
19
  rulesOnLastRowTreeCreation: []
@@ -177,7 +177,8 @@ const useGridRowGrouping = (apiRef, props) => {
177
177
  }
178
178
  }
179
179
  }, [apiRef, props.disableRowGrouping]);
180
- const getRowReorderTargetIndex = React.useCallback((initialValue, {
180
+ const isValidRowReorderProp = props.isValidRowReorder;
181
+ const isRowReorderValid = React.useCallback((initialValue, {
181
182
  sourceRowId,
182
183
  targetRowId,
183
184
  dropPosition,
@@ -186,10 +187,9 @@ const useGridRowGrouping = (apiRef, props) => {
186
187
  if ((0, _xDataGridPro.gridRowMaximumTreeDepthSelector)(apiRef) === 1 || props.treeData) {
187
188
  return initialValue;
188
189
  }
189
- const expandedSortedRowIndexLookup = (0, _internals.gridExpandedSortedRowIndexLookupSelector)(apiRef);
190
+ const expandedSortedRowIndexLookup = (0, _xDataGridPro.gridExpandedSortedRowIndexLookupSelector)(apiRef);
190
191
  const expandedSortedRowIds = (0, _xDataGridPro.gridExpandedSortedRowIdsSelector)(apiRef);
191
192
  const rowTree = (0, _xDataGridPro.gridRowTreeSelector)(apiRef);
192
- const sourceRowIndex = expandedSortedRowIndexLookup[sourceRowId];
193
193
  const targetRowIndex = expandedSortedRowIndexLookup[targetRowId];
194
194
  const sourceNode = rowTree[sourceRowId];
195
195
  const targetNode = rowTree[targetRowId];
@@ -198,30 +198,34 @@ const useGridRowGrouping = (apiRef, props) => {
198
198
 
199
199
  // Basic validity checks
200
200
  if (!sourceNode || !targetNode) {
201
- return -1;
201
+ return false;
202
202
  }
203
203
 
204
204
  // Create context object
205
205
  const context = {
206
+ apiRef,
206
207
  sourceNode,
207
208
  targetNode,
208
209
  prevNode,
209
210
  nextNode,
210
- rowTree,
211
211
  dropPosition,
212
- dragDirection,
213
- targetRowIndex,
214
- sourceRowIndex,
215
- expandedSortedRowIndexLookup
212
+ dragDirection
216
213
  };
217
214
 
218
- // Check if the reorder is valid
219
- if (_reorderValidator.rowGroupingReorderValidator.validate(context)) {
220
- return dropPosition === 'below' ? targetRowIndex + 1 : targetRowIndex;
215
+ // First apply internal validation
216
+ let isValid = _rowGroupingReorderValidator.rowGroupingReorderValidator.validate(context);
217
+
218
+ // If internal validation passes AND user provided additional validation
219
+ if (isValid && isValidRowReorderProp) {
220
+ // Apply additional user restrictions
221
+ isValid = isValidRowReorderProp(context);
222
+ }
223
+ if (isValid) {
224
+ return true;
221
225
  }
222
- return -1;
223
- }, [apiRef, props.treeData]);
224
- (0, _internals.useGridRegisterPipeProcessor)(apiRef, 'getRowReorderTargetIndex', getRowReorderTargetIndex);
226
+ return false;
227
+ }, [apiRef, props.treeData, isValidRowReorderProp]);
228
+ (0, _internals.useGridRegisterPipeProcessor)(apiRef, 'isRowReorderValid', isRowReorderValid);
225
229
  (0, _xDataGridPro.useGridEvent)(apiRef, 'cellKeyDown', handleCellKeyDown);
226
230
  (0, _xDataGridPro.useGridEvent)(apiRef, 'columnsChange', checkGroupingColumnsModelDiff);
227
231
  (0, _xDataGridPro.useGridEvent)(apiRef, 'rowGroupingModelChange', checkGroupingColumnsModelDiff);
@@ -1,34 +1,13 @@
1
- import type { ReorderOperation, ReorderExecutionContext } from "./types.js";
2
- /**
3
- * Base class for all reorder operations.
4
- * Provides abstract methods for operation detection and execution.
5
- */
6
- export declare abstract class BaseReorderOperation {
7
- abstract readonly operationType: string;
8
- /**
9
- * Detects if this operation can handle the given context.
10
- */
11
- abstract detectOperation(ctx: ReorderExecutionContext): ReorderOperation | null;
12
- /**
13
- * Executes the detected operation.
14
- */
15
- abstract executeOperation(operation: ReorderOperation, ctx: ReorderExecutionContext): Promise<void> | void;
16
- }
17
- /**
18
- * Handles reordering of items within the same parent group.
19
- */
20
- export declare class SameParentSwapOperation extends BaseReorderOperation {
21
- readonly operationType = "same-parent-swap";
22
- detectOperation(ctx: ReorderExecutionContext): ReorderOperation | null;
23
- executeOperation(operation: ReorderOperation, ctx: ReorderExecutionContext): void;
24
- }
1
+ import { BaseReorderOperation, type ReorderOperation, type ReorderExecutionContext } from '@mui/x-data-grid-pro/internals';
2
+ import { GridPrivateApiPremium } from "../../../models/gridApiPremium.js";
3
+ type ReorderExecutionContextType = ReorderExecutionContext<GridPrivateApiPremium>;
25
4
  /**
26
5
  * Handles moving leaf nodes between different parent groups.
27
6
  */
28
7
  export declare class CrossParentLeafOperation extends BaseReorderOperation {
29
8
  readonly operationType = "cross-parent-leaf";
30
9
  detectOperation(ctx: ReorderExecutionContext): ReorderOperation | null;
31
- executeOperation(operation: ReorderOperation, ctx: ReorderExecutionContext): Promise<void>;
10
+ executeOperation(operation: ReorderOperation, ctx: ReorderExecutionContextType): Promise<void>;
32
11
  }
33
12
  /**
34
13
  * Handles moving entire groups between different parents.
@@ -36,5 +15,6 @@ export declare class CrossParentLeafOperation extends BaseReorderOperation {
36
15
  export declare class CrossParentGroupOperation extends BaseReorderOperation {
37
16
  readonly operationType = "cross-parent-group";
38
17
  detectOperation(ctx: ReorderExecutionContext): ReorderOperation | null;
39
- executeOperation(operation: ReorderOperation, ctx: ReorderExecutionContext): Promise<void>;
40
- }
18
+ executeOperation(operation: ReorderOperation, ctx: ReorderExecutionContextType): Promise<void>;
19
+ }
20
+ export {};
@@ -4,138 +4,16 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.SameParentSwapOperation = exports.CrossParentLeafOperation = exports.CrossParentGroupOperation = exports.BaseReorderOperation = void 0;
7
+ exports.CrossParentLeafOperation = exports.CrossParentGroupOperation = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _xDataGridPro = require("@mui/x-data-grid-pro");
10
- var _warning = require("@mui/x-internals/warning");
11
- var _isDeepEqual = require("@mui/x-internals/isDeepEqual");
10
+ var _internals = require("@mui/x-data-grid-pro/internals");
12
11
  var _rowGrouping = require("../rowGrouping");
13
12
  var _gridRowGroupingUtils = require("../rowGrouping/gridRowGroupingUtils");
14
- var _utils = require("./utils");
15
- /**
16
- * Base class for all reorder operations.
17
- * Provides abstract methods for operation detection and execution.
18
- */
19
- class BaseReorderOperation {}
20
-
21
- /**
22
- * Handles reordering of items within the same parent group.
23
- */
24
- exports.BaseReorderOperation = BaseReorderOperation;
25
- class SameParentSwapOperation extends BaseReorderOperation {
26
- operationType = 'same-parent-swap';
27
- detectOperation(ctx) {
28
- const {
29
- sourceRowId,
30
- placeholderIndex,
31
- sortedFilteredRowIds,
32
- sortedFilteredRowIndexLookup,
33
- rowTree,
34
- apiRef
35
- } = ctx;
36
- const sourceNode = (0, _xDataGridPro.gridRowNodeSelector)(apiRef, sourceRowId);
37
- if (!sourceNode || sourceNode.type === 'footer') {
38
- return null;
39
- }
40
- let targetIndex = placeholderIndex;
41
- const sourceIndex = sortedFilteredRowIndexLookup[sourceRowId];
42
- if (targetIndex === sortedFilteredRowIds.length && sortedFilteredRowIds.length > 0) {
43
- targetIndex -= 1;
44
- }
45
- let targetNode = (0, _xDataGridPro.gridRowNodeSelector)(apiRef, sortedFilteredRowIds[targetIndex]);
46
- if (placeholderIndex > sourceIndex && sourceNode.parent === targetNode.parent) {
47
- targetIndex = placeholderIndex - 1;
48
- targetNode = (0, _xDataGridPro.gridRowNodeSelector)(apiRef, sortedFilteredRowIds[targetIndex]);
49
- if (targetNode && targetNode.depth !== sourceNode.depth) {
50
- while (targetNode.depth > sourceNode.depth && targetIndex >= 0) {
51
- targetIndex -= 1;
52
- targetNode = (0, _xDataGridPro.gridRowNodeSelector)(apiRef, sortedFilteredRowIds[targetIndex]);
53
- }
54
- }
55
- if (targetIndex === -1) {
56
- return null;
57
- }
58
- }
59
- let isLastChild = false;
60
- if (!targetNode) {
61
- if (placeholderIndex >= sortedFilteredRowIds.length && sortedFilteredRowIds.length > 0) {
62
- targetNode = (0, _xDataGridPro.gridRowNodeSelector)(apiRef, sortedFilteredRowIds[sortedFilteredRowIds.length - 1]);
63
- isLastChild = true;
64
- } else {
65
- return null;
66
- }
67
- }
68
- let adjustedTargetNode = targetNode;
69
-
70
- // Case A and B adjustment
71
- if (targetNode.type === 'group' && sourceNode.parent !== targetNode.parent && sourceNode.depth > targetNode.depth) {
72
- let i = targetIndex - 1;
73
- while (i >= 0) {
74
- const node = (0, _xDataGridPro.gridRowNodeSelector)(apiRef, sortedFilteredRowIds[i]);
75
- if (node && node.depth < sourceNode.depth) {
76
- return null;
77
- }
78
- if (node && node.depth === sourceNode.depth) {
79
- targetIndex = i;
80
- adjustedTargetNode = node;
81
- break;
82
- }
83
- i -= 1;
84
- }
85
- }
86
- const operationType = (0, _utils.determineOperationType)(sourceNode, adjustedTargetNode);
87
- if (operationType !== 'same-parent-swap') {
88
- return null;
89
- }
90
- const actualTargetIndex = (0, _utils.calculateTargetIndex)(sourceNode, adjustedTargetNode, isLastChild, rowTree);
91
- targetNode = adjustedTargetNode;
92
- if (sourceNode.type !== targetNode.type) {
93
- return null;
94
- }
95
- return {
96
- sourceNode,
97
- targetNode,
98
- actualTargetIndex,
99
- isLastChild,
100
- operationType
101
- };
102
- }
103
- executeOperation(operation, ctx) {
104
- const {
105
- sourceNode,
106
- actualTargetIndex
107
- } = operation;
108
- const {
109
- apiRef,
110
- sourceRowId
111
- } = ctx;
112
- apiRef.current.setState(state => {
113
- const group = (0, _xDataGridPro.gridRowTreeSelector)(apiRef)[sourceNode.parent];
114
- const currentChildren = [...group.children];
115
- const oldIndex = currentChildren.findIndex(row => row === sourceRowId);
116
- if (oldIndex === -1 || actualTargetIndex === -1 || oldIndex === actualTargetIndex) {
117
- return state;
118
- }
119
- currentChildren.splice(actualTargetIndex, 0, currentChildren.splice(oldIndex, 1)[0]);
120
- return (0, _extends2.default)({}, state, {
121
- rows: (0, _extends2.default)({}, state.rows, {
122
- tree: (0, _extends2.default)({}, state.rows.tree, {
123
- [sourceNode.parent]: (0, _extends2.default)({}, group, {
124
- children: currentChildren
125
- })
126
- })
127
- })
128
- });
129
- });
130
- apiRef.current.publishEvent('rowsSet');
131
- }
132
- }
133
-
134
13
  /**
135
14
  * Handles moving leaf nodes between different parent groups.
136
15
  */
137
- exports.SameParentSwapOperation = SameParentSwapOperation;
138
- class CrossParentLeafOperation extends BaseReorderOperation {
16
+ class CrossParentLeafOperation extends _internals.BaseReorderOperation {
139
17
  operationType = 'cross-parent-leaf';
140
18
  detectOperation(ctx) {
141
19
  const {
@@ -173,11 +51,11 @@ class CrossParentLeafOperation extends BaseReorderOperation {
173
51
  }
174
52
  }
175
53
  }
176
- const operationType = (0, _utils.determineOperationType)(sourceNode, adjustedTargetNode);
54
+ const operationType = _internals.rowReorderUtils.determineOperationType(sourceNode, adjustedTargetNode);
177
55
  if (operationType !== 'cross-parent-leaf') {
178
56
  return null;
179
57
  }
180
- const actualTargetIndex = (0, _utils.calculateTargetIndex)(sourceNode, adjustedTargetNode, isLastChild, rowTree);
58
+ const actualTargetIndex = _internals.rowReorderUtils.calculateTargetIndex(sourceNode, adjustedTargetNode, isLastChild, rowTree);
181
59
  targetNode = adjustedTargetNode;
182
60
 
183
61
  // Validate depth constraints
@@ -255,72 +133,56 @@ class CrossParentLeafOperation extends BaseReorderOperation {
255
133
  updatedSourceRow[groupingRule.field] = targetRow[groupingRule.field];
256
134
  }
257
135
  }
258
- const commitStateUpdate = finalSourceRow => {
259
- apiRef.current.setState(state => {
260
- const updatedSourceChildren = sourceChildren.filter(rowId => rowId !== sourceRowId);
261
- const updatedTree = (0, _extends2.default)({}, state.rows.tree);
262
- const removedGroups = new Set();
263
- let rootLevelRemovals = 0;
264
- if (updatedSourceChildren.length === 0) {
265
- removedGroups.add(sourceGroup.id);
266
- rootLevelRemovals = (0, _utils.removeEmptyAncestors)(sourceGroup.parent, updatedTree, removedGroups);
267
- }
268
- removedGroups.forEach(groupId => {
269
- const group = updatedTree[groupId];
270
- if (group && group.parent && updatedTree[group.parent]) {
271
- const parent = updatedTree[group.parent];
272
- updatedTree[group.parent] = (0, _extends2.default)({}, parent, {
273
- children: parent.children.filter(childId => childId !== groupId)
274
- });
275
- }
276
- delete updatedTree[groupId];
277
- });
278
- if (!removedGroups.has(sourceGroup.id)) {
279
- updatedTree[sourceNode.parent] = (0, _extends2.default)({}, sourceGroup, {
280
- children: updatedSourceChildren
136
+ const updater = new _internals.rowReorderUtils.BatchRowUpdater(apiRef, processRowUpdate, onProcessRowUpdateError);
137
+ updater.queueUpdate(sourceRowId, originalSourceRow, updatedSourceRow);
138
+ const {
139
+ successful,
140
+ updates
141
+ } = await updater.executeAll();
142
+ if (successful.length === 0) {
143
+ return;
144
+ }
145
+ const finalSourceRow = updates[0];
146
+ apiRef.current.setState(state => {
147
+ const updatedSourceChildren = sourceChildren.filter(rowId => rowId !== sourceRowId);
148
+ const updatedTree = (0, _extends2.default)({}, state.rows.tree);
149
+ const removedGroups = new Set();
150
+ let rootLevelRemovals = 0;
151
+ if (updatedSourceChildren.length === 0) {
152
+ removedGroups.add(sourceGroup.id);
153
+ rootLevelRemovals = _internals.rowReorderUtils.removeEmptyAncestors(sourceGroup.parent, updatedTree, removedGroups);
154
+ }
155
+ removedGroups.forEach(groupId => {
156
+ const group = updatedTree[groupId];
157
+ if (group && group.parent && updatedTree[group.parent]) {
158
+ const parent = updatedTree[group.parent];
159
+ updatedTree[group.parent] = (0, _extends2.default)({}, parent, {
160
+ children: parent.children.filter(childId => childId !== groupId)
281
161
  });
282
162
  }
283
- const updatedTargetChildren = isLastChild ? [...targetChildren, sourceRowId] : [...targetChildren.slice(0, targetIndex), sourceRowId, ...targetChildren.slice(targetIndex)];
284
- updatedTree[target.parent] = (0, _extends2.default)({}, targetGroup, {
285
- children: updatedTargetChildren
286
- });
287
- updatedTree[sourceNode.id] = (0, _extends2.default)({}, sourceNode, {
288
- parent: target.parent
289
- });
290
- return (0, _extends2.default)({}, state, {
291
- rows: (0, _extends2.default)({}, state.rows, {
292
- totalTopLevelRowCount: state.rows.totalTopLevelRowCount - rootLevelRemovals,
293
- tree: updatedTree
294
- })
295
- });
163
+ delete updatedTree[groupId];
296
164
  });
297
- apiRef.current.updateRows([finalSourceRow]);
298
- apiRef.current.publishEvent('rowsSet');
299
- };
300
- if (processRowUpdate && !(0, _isDeepEqual.isDeepEqual)(originalSourceRow, updatedSourceRow)) {
301
- const params = {
302
- rowId: sourceRowId,
303
- previousRow: originalSourceRow,
304
- updatedRow: updatedSourceRow
305
- };
306
- apiRef.current.setLoading(true);
307
- try {
308
- const processedRow = await processRowUpdate(updatedSourceRow, originalSourceRow, params);
309
- const finalRow = processedRow || updatedSourceRow;
310
- commitStateUpdate(finalRow);
311
- } catch (error) {
312
- apiRef.current.setLoading(false);
313
- if (onProcessRowUpdateError) {
314
- onProcessRowUpdateError(error);
315
- } else if (process.env.NODE_ENV !== 'production') {
316
- (0, _warning.warnOnce)(['MUI X: A call to `processRowUpdate()` threw an error which was not handled because `onProcessRowUpdateError()` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError()` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'], 'error');
317
- }
318
- } finally {
319
- apiRef.current.setLoading(false);
165
+ if (!removedGroups.has(sourceGroup.id)) {
166
+ updatedTree[sourceNode.parent] = (0, _extends2.default)({}, sourceGroup, {
167
+ children: updatedSourceChildren
168
+ });
320
169
  }
321
- } else {
322
- commitStateUpdate(updatedSourceRow);
323
- }
170
+ const updatedTargetChildren = isLastChild ? [...targetChildren, sourceRowId] : [...targetChildren.slice(0, targetIndex), sourceRowId, ...targetChildren.slice(targetIndex)];
171
+ updatedTree[target.parent] = (0, _extends2.default)({}, targetGroup, {
172
+ children: updatedTargetChildren
173
+ });
174
+ updatedTree[sourceNode.id] = (0, _extends2.default)({}, sourceNode, {
175
+ parent: target.parent
176
+ });
177
+ return (0, _extends2.default)({}, state, {
178
+ rows: (0, _extends2.default)({}, state.rows, {
179
+ totalTopLevelRowCount: state.rows.totalTopLevelRowCount - rootLevelRemovals,
180
+ tree: updatedTree
181
+ })
182
+ });
183
+ });
184
+ apiRef.current.updateRows([finalSourceRow]);
185
+ apiRef.current.publishEvent('rowsSet');
324
186
  }
325
187
  }
326
188
 
@@ -328,7 +190,7 @@ class CrossParentLeafOperation extends BaseReorderOperation {
328
190
  * Handles moving entire groups between different parents.
329
191
  */
330
192
  exports.CrossParentLeafOperation = CrossParentLeafOperation;
331
- class CrossParentGroupOperation extends BaseReorderOperation {
193
+ class CrossParentGroupOperation extends _internals.BaseReorderOperation {
332
194
  operationType = 'cross-parent-group';
333
195
  detectOperation(ctx) {
334
196
  const {
@@ -375,11 +237,11 @@ class CrossParentGroupOperation extends BaseReorderOperation {
375
237
  isLastChild = true;
376
238
  adjustedTargetNode = prevNode;
377
239
  }
378
- const operationType = (0, _utils.determineOperationType)(sourceNode, adjustedTargetNode);
240
+ const operationType = _internals.rowReorderUtils.determineOperationType(sourceNode, adjustedTargetNode);
379
241
  if (operationType !== 'cross-parent-group') {
380
242
  return null;
381
243
  }
382
- const actualTargetIndex = (0, _utils.calculateTargetIndex)(sourceNode, adjustedTargetNode, isLastChild, rowTree);
244
+ const actualTargetIndex = _internals.rowReorderUtils.calculateTargetIndex(sourceNode, adjustedTargetNode, isLastChild, rowTree);
383
245
  const operation = {
384
246
  sourceNode,
385
247
  targetNode: adjustedTargetNode,
@@ -408,16 +270,16 @@ class CrossParentGroupOperation extends BaseReorderOperation {
408
270
  const dataRowIdToModelLookup = (0, _xDataGridPro.gridRowsLookupSelector)(apiRef);
409
271
  const columnsLookup = (0, _xDataGridPro.gridColumnLookupSelector)(apiRef);
410
272
  const sanitizedRowGroupingModel = (0, _rowGrouping.gridRowGroupingSanitizedModelSelector)(apiRef);
411
- const allLeafIds = (0, _utils.collectAllLeafDescendants)(sourceNode, tree);
273
+ const allLeafIds = _internals.rowReorderUtils.collectAllLeafDescendants(sourceNode, tree);
412
274
  if (allLeafIds.length === 0) {
413
275
  return;
414
276
  }
415
- const updater = new _utils.BatchRowUpdater(processRowUpdate, onProcessRowUpdateError);
277
+ const updater = new _internals.rowReorderUtils.BatchRowUpdater(apiRef, processRowUpdate, onProcessRowUpdateError);
416
278
  const groupingRules = (0, _gridRowGroupingUtils.getGroupingRules)({
417
279
  sanitizedRowGroupingModel,
418
280
  columnsLookup
419
281
  });
420
- const targetParentPath = (0, _utils.getNodePathInTree)({
282
+ const targetParentPath = _internals.rowReorderUtils.getNodePathInTree({
421
283
  id: targetNode.parent,
422
284
  tree
423
285
  });
@@ -440,22 +302,75 @@ class CrossParentGroupOperation extends BaseReorderOperation {
440
302
  }
441
303
  updater.queueUpdate(leafId, originalRow, updatedRow);
442
304
  }
443
- apiRef.current.setLoading(true);
444
- try {
445
- const {
446
- successful,
447
- failed,
448
- updates
449
- } = await updater.executeAll();
450
- if (successful.length > 0) {
451
- apiRef.current.setState(state => {
452
- const updatedTree = (0, _extends2.default)({}, state.rows.tree);
453
- const treeDepths = (0, _extends2.default)({}, state.rows.treeDepths);
454
- let rootLevelRemovals = 0;
455
- if (failed.length === 0) {
456
- const sourceParentNode = updatedTree[sourceNode.parent];
457
- if (!sourceParentNode) {
458
- const targetParentNode = updatedTree[targetNode.parent];
305
+ const {
306
+ successful,
307
+ failed,
308
+ updates
309
+ } = await updater.executeAll();
310
+ if (successful.length > 0) {
311
+ apiRef.current.setState(state => {
312
+ const updatedTree = (0, _extends2.default)({}, state.rows.tree);
313
+ const treeDepths = (0, _extends2.default)({}, state.rows.treeDepths);
314
+ let rootLevelRemovals = 0;
315
+ if (failed.length === 0) {
316
+ const sourceParentNode = updatedTree[sourceNode.parent];
317
+ if (!sourceParentNode) {
318
+ const targetParentNode = updatedTree[targetNode.parent];
319
+ const targetIndex = targetParentNode.children.indexOf(targetNode.id);
320
+ const newTargetChildren = [...targetParentNode.children];
321
+ if (isLastChild) {
322
+ newTargetChildren.push(sourceNode.id);
323
+ } else {
324
+ newTargetChildren.splice(targetIndex, 0, sourceNode.id);
325
+ }
326
+ updatedTree[targetNode.parent] = (0, _extends2.default)({}, targetParentNode, {
327
+ children: newTargetChildren
328
+ });
329
+ updatedTree[sourceNode.id] = (0, _extends2.default)({}, sourceNode, {
330
+ parent: targetNode.parent
331
+ });
332
+ } else {
333
+ const updatedSourceParentChildren = sourceParentNode.children.filter(id => id !== sourceNode.id);
334
+ if (updatedSourceParentChildren.length === 0) {
335
+ const removedGroups = new Set();
336
+ removedGroups.add(sourceNode.parent);
337
+ const parentOfSourceParent = updatedTree[sourceNode.parent].parent;
338
+ if (parentOfSourceParent) {
339
+ rootLevelRemovals = _internals.rowReorderUtils.removeEmptyAncestors(parentOfSourceParent, updatedTree, removedGroups);
340
+ }
341
+ removedGroups.forEach(groupId => {
342
+ const group = updatedTree[groupId];
343
+ if (group && group.parent && updatedTree[group.parent]) {
344
+ const parent = updatedTree[group.parent];
345
+ updatedTree[group.parent] = (0, _extends2.default)({}, parent, {
346
+ children: parent.children.filter(childId => childId !== groupId)
347
+ });
348
+ }
349
+ delete updatedTree[groupId];
350
+ });
351
+ } else {
352
+ updatedTree[sourceNode.parent] = (0, _extends2.default)({}, sourceParentNode, {
353
+ children: updatedSourceParentChildren
354
+ });
355
+ }
356
+ const targetParentNode = updatedTree[targetNode.parent];
357
+ const sourceGroupNode = sourceNode;
358
+ const existingGroup = sourceGroupNode.groupingKey !== null && sourceGroupNode.groupingField !== null ? _internals.rowReorderUtils.findExistingGroupWithSameKey(targetParentNode, sourceGroupNode.groupingKey, sourceGroupNode.groupingField, updatedTree) : null;
359
+ if (existingGroup) {
360
+ const updatedExistingGroup = (0, _extends2.default)({}, existingGroup, {
361
+ children: [...existingGroup.children, ...sourceGroupNode.children]
362
+ });
363
+ updatedTree[existingGroup.id] = updatedExistingGroup;
364
+ sourceGroupNode.children.forEach(childId => {
365
+ const childNode = updatedTree[childId];
366
+ if (childNode) {
367
+ updatedTree[childId] = (0, _extends2.default)({}, childNode, {
368
+ parent: existingGroup.id
369
+ });
370
+ }
371
+ });
372
+ delete updatedTree[sourceNode.id];
373
+ } else {
459
374
  const targetIndex = targetParentNode.children.indexOf(targetNode.id);
460
375
  const newTargetChildren = [...targetParentNode.children];
461
376
  if (isLastChild) {
@@ -469,77 +384,19 @@ class CrossParentGroupOperation extends BaseReorderOperation {
469
384
  updatedTree[sourceNode.id] = (0, _extends2.default)({}, sourceNode, {
470
385
  parent: targetNode.parent
471
386
  });
472
- } else {
473
- const updatedSourceParentChildren = sourceParentNode.children.filter(id => id !== sourceNode.id);
474
- if (updatedSourceParentChildren.length === 0) {
475
- const removedGroups = new Set();
476
- removedGroups.add(sourceNode.parent);
477
- const parentOfSourceParent = updatedTree[sourceNode.parent].parent;
478
- if (parentOfSourceParent) {
479
- rootLevelRemovals = (0, _utils.removeEmptyAncestors)(parentOfSourceParent, updatedTree, removedGroups);
480
- }
481
- removedGroups.forEach(groupId => {
482
- const group = updatedTree[groupId];
483
- if (group && group.parent && updatedTree[group.parent]) {
484
- const parent = updatedTree[group.parent];
485
- updatedTree[group.parent] = (0, _extends2.default)({}, parent, {
486
- children: parent.children.filter(childId => childId !== groupId)
487
- });
488
- }
489
- delete updatedTree[groupId];
490
- });
491
- } else {
492
- updatedTree[sourceNode.parent] = (0, _extends2.default)({}, sourceParentNode, {
493
- children: updatedSourceParentChildren
494
- });
495
- }
496
- const targetParentNode = updatedTree[targetNode.parent];
497
- const sourceGroupNode = sourceNode;
498
- const existingGroup = sourceGroupNode.groupingKey !== null && sourceGroupNode.groupingField !== null ? (0, _utils.findExistingGroupWithSameKey)(targetParentNode, sourceGroupNode.groupingKey, sourceGroupNode.groupingField, updatedTree) : null;
499
- if (existingGroup) {
500
- const updatedExistingGroup = (0, _extends2.default)({}, existingGroup, {
501
- children: [...existingGroup.children, ...sourceGroupNode.children]
502
- });
503
- updatedTree[existingGroup.id] = updatedExistingGroup;
504
- sourceGroupNode.children.forEach(childId => {
505
- const childNode = updatedTree[childId];
506
- if (childNode) {
507
- updatedTree[childId] = (0, _extends2.default)({}, childNode, {
508
- parent: existingGroup.id
509
- });
510
- }
511
- });
512
- delete updatedTree[sourceNode.id];
513
- } else {
514
- const targetIndex = targetParentNode.children.indexOf(targetNode.id);
515
- const newTargetChildren = [...targetParentNode.children];
516
- if (isLastChild) {
517
- newTargetChildren.push(sourceNode.id);
518
- } else {
519
- newTargetChildren.splice(targetIndex, 0, sourceNode.id);
520
- }
521
- updatedTree[targetNode.parent] = (0, _extends2.default)({}, targetParentNode, {
522
- children: newTargetChildren
523
- });
524
- updatedTree[sourceNode.id] = (0, _extends2.default)({}, sourceNode, {
525
- parent: targetNode.parent
526
- });
527
- }
528
387
  }
529
388
  }
530
- return (0, _extends2.default)({}, state, {
531
- rows: (0, _extends2.default)({}, state.rows, {
532
- totalTopLevelRowCount: state.rows.totalTopLevelRowCount - rootLevelRemovals,
533
- tree: updatedTree,
534
- treeDepths
535
- })
536
- });
389
+ }
390
+ return (0, _extends2.default)({}, state, {
391
+ rows: (0, _extends2.default)({}, state.rows, {
392
+ totalTopLevelRowCount: state.rows.totalTopLevelRowCount - rootLevelRemovals,
393
+ tree: updatedTree,
394
+ treeDepths
395
+ })
537
396
  });
538
- apiRef.current.updateRows(updates);
539
- apiRef.current.publishEvent('rowsSet');
540
- }
541
- } finally {
542
- apiRef.current.setLoading(false);
397
+ });
398
+ apiRef.current.updateRows(updates);
399
+ apiRef.current.publishEvent('rowsSet');
543
400
  }
544
401
  }
545
402
  }
@@ -0,0 +1,2 @@
1
+ import { RowReorderExecutor } from '@mui/x-data-grid-pro/internals';
2
+ export declare const rowGroupingReorderExecutor: RowReorderExecutor;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.rowGroupingReorderExecutor = void 0;
7
+ var _internals = require("@mui/x-data-grid-pro/internals");
8
+ var _operations = require("./operations");
9
+ const rowGroupingReorderExecutor = exports.rowGroupingReorderExecutor = new _internals.RowReorderExecutor([new _internals.SameParentSwapOperation(), new _operations.CrossParentLeafOperation(), new _operations.CrossParentGroupOperation()]);
@@ -0,0 +1,2 @@
1
+ import { RowReorderValidator } from '@mui/x-data-grid-pro/internals';
2
+ export declare const rowGroupingReorderValidator: RowReorderValidator;