@mui/x-data-grid-premium 8.18.0 → 8.20.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 (53) hide show
  1. package/CHANGELOG.md +175 -0
  2. package/DataGridPremium/DataGridPremium.d.ts +1 -1
  3. package/DataGridPremium/DataGridPremium.js +40 -7
  4. package/DataGridPremium/useDataGridPremiumComponent.d.ts +1 -1
  5. package/DataGridPremium/useDataGridPremiumComponent.js +3 -2
  6. package/components/GridFooterCell.js +1 -1
  7. package/esm/DataGridPremium/DataGridPremium.d.ts +1 -1
  8. package/esm/DataGridPremium/DataGridPremium.js +40 -7
  9. package/esm/DataGridPremium/useDataGridPremiumComponent.d.ts +1 -1
  10. package/esm/DataGridPremium/useDataGridPremiumComponent.js +4 -3
  11. package/esm/components/GridFooterCell.js +1 -1
  12. package/esm/hooks/features/aggregation/useGridAggregation.js +38 -17
  13. package/esm/hooks/features/chartsIntegration/useGridChartsIntegration.js +1 -0
  14. package/esm/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
  15. package/esm/hooks/features/rowGrouping/useGridRowGrouping.js +21 -17
  16. package/esm/hooks/features/rowReorder/operations.d.ts +7 -27
  17. package/esm/hooks/features/rowReorder/operations.js +133 -274
  18. package/esm/hooks/features/rowReorder/rowGroupingReorderExecutor.d.ts +2 -0
  19. package/esm/hooks/features/rowReorder/rowGroupingReorderExecutor.js +3 -0
  20. package/esm/hooks/features/rowReorder/rowGroupingReorderValidator.d.ts +2 -0
  21. package/esm/hooks/features/rowReorder/{reorderValidator.js → rowGroupingReorderValidator.js} +2 -22
  22. package/esm/hooks/features/rows/useGridRowsOverridableMethods.d.ts +3 -3
  23. package/esm/hooks/features/rows/useGridRowsOverridableMethods.js +61 -7
  24. package/esm/index.js +1 -1
  25. package/hooks/features/aggregation/useGridAggregation.js +37 -16
  26. package/hooks/features/chartsIntegration/useGridChartsIntegration.js +1 -0
  27. package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
  28. package/hooks/features/rowGrouping/useGridRowGrouping.js +20 -16
  29. package/hooks/features/rowReorder/operations.d.ts +7 -27
  30. package/hooks/features/rowReorder/operations.js +136 -279
  31. package/hooks/features/rowReorder/rowGroupingReorderExecutor.d.ts +2 -0
  32. package/hooks/features/rowReorder/rowGroupingReorderExecutor.js +9 -0
  33. package/hooks/features/rowReorder/rowGroupingReorderValidator.d.ts +2 -0
  34. package/hooks/features/rowReorder/rowGroupingReorderValidator.js +102 -0
  35. package/hooks/features/rows/useGridRowsOverridableMethods.d.ts +3 -3
  36. package/hooks/features/rows/useGridRowsOverridableMethods.js +61 -7
  37. package/index.js +1 -1
  38. package/package.json +6 -6
  39. package/esm/hooks/features/rowReorder/reorderExecutor.d.ts +0 -15
  40. package/esm/hooks/features/rowReorder/reorderExecutor.js +0 -25
  41. package/esm/hooks/features/rowReorder/reorderValidator.d.ts +0 -16
  42. package/esm/hooks/features/rowReorder/types.d.ts +0 -42
  43. package/esm/hooks/features/rowReorder/types.js +0 -1
  44. package/esm/hooks/features/rowReorder/utils.d.ts +0 -127
  45. package/esm/hooks/features/rowReorder/utils.js +0 -343
  46. package/hooks/features/rowReorder/reorderExecutor.d.ts +0 -15
  47. package/hooks/features/rowReorder/reorderExecutor.js +0 -31
  48. package/hooks/features/rowReorder/reorderValidator.d.ts +0 -16
  49. package/hooks/features/rowReorder/reorderValidator.js +0 -122
  50. package/hooks/features/rowReorder/types.d.ts +0 -42
  51. package/hooks/features/rowReorder/types.js +0 -5
  52. package/hooks/features/rowReorder/utils.d.ts +0 -127
  53. package/hooks/features/rowReorder/utils.js +0 -360
@@ -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;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.rowGroupingReorderValidator = void 0;
7
+ var _internals = require("@mui/x-data-grid-pro/internals");
8
+ const validationRules = [
9
+ // ===== Basic invalid cases =====
10
+ {
11
+ name: 'same-position',
12
+ applies: ctx => ctx.sourceNode.id === ctx.targetNode.id,
13
+ isInvalid: () => true,
14
+ message: 'Source and target are the same'
15
+ }, {
16
+ name: 'adjacent-position',
17
+ applies: ctx => _internals.commonReorderConditions.isAdjacentPosition(ctx),
18
+ isInvalid: () => true,
19
+ message: 'Source and target are adjacent'
20
+ }, {
21
+ name: 'group-to-leaf',
22
+ applies: _internals.commonReorderConditions.isGroupToLeaf,
23
+ isInvalid: () => true,
24
+ message: 'Cannot drop group on leaf'
25
+ },
26
+ // ===== Group to Group Rules =====
27
+ {
28
+ name: 'group-to-group-above-leaf-belongs-to-source',
29
+ applies: ctx => _internals.commonReorderConditions.isGroupToGroup(ctx) && _internals.commonReorderConditions.isDropAbove(ctx) && _internals.commonReorderConditions.prevIsLeaf(ctx),
30
+ isInvalid: _internals.commonReorderConditions.prevBelongsToSource,
31
+ message: 'Previous leaf belongs to source group or its descendants'
32
+ }, {
33
+ name: 'group-to-group-above-invalid-depth',
34
+ applies: ctx => _internals.commonReorderConditions.isGroupToGroup(ctx) && _internals.commonReorderConditions.isDropAbove(ctx) && !_internals.commonReorderConditions.sameDepth(ctx) && !(ctx.targetNode.depth < ctx.sourceNode.depth && (_internals.commonReorderConditions.prevIsLeaf(ctx) || _internals.commonReorderConditions.prevIsGroup(ctx) && _internals.commonReorderConditions.prevDepthEqualsSource(ctx))),
35
+ isInvalid: () => true,
36
+ message: 'Invalid depth configuration for group above group'
37
+ }, {
38
+ name: 'group-to-group-above-different-parent-depth',
39
+ applies: ctx => _internals.commonReorderConditions.isGroupToGroup(ctx) && _internals.commonReorderConditions.isDropAbove(ctx) && _internals.commonReorderConditions.prevIsGroup(ctx) && _internals.commonReorderConditions.prevDepthEqualsSource(ctx) && _internals.commonReorderConditions.targetGroupExpanded(ctx),
40
+ isInvalid: ctx => ctx.prevNode.depth !== ctx.sourceNode.depth,
41
+ message: 'Cannot reorder groups with different depths'
42
+ }, {
43
+ name: 'group-to-group-below-invalid-config',
44
+ applies: ctx => _internals.commonReorderConditions.isGroupToGroup(ctx) && _internals.commonReorderConditions.isDropBelow(ctx),
45
+ isInvalid: ctx => {
46
+ // Valid case 1: Same depth and target not expanded
47
+ if (_internals.commonReorderConditions.sameDepth(ctx) && _internals.commonReorderConditions.targetGroupCollapsed(ctx)) {
48
+ return false;
49
+ }
50
+ // Valid case 2: Target is parent level, expanded, with compatible first child
51
+ if (_internals.commonReorderConditions.targetDepthIsSourceMinusOne(ctx) && _internals.commonReorderConditions.targetGroupExpanded(ctx) && _internals.commonReorderConditions.targetFirstChildIsGroupWithSourceDepth(ctx)) {
52
+ return false;
53
+ }
54
+ return true;
55
+ },
56
+ message: 'Invalid group below group configuration'
57
+ },
58
+ // ===== Leaf to Leaf Rules =====
59
+ {
60
+ name: 'leaf-to-leaf-different-depth',
61
+ applies: ctx => _internals.commonReorderConditions.isLeafToLeaf(ctx) && !_internals.commonReorderConditions.sameDepth(ctx),
62
+ isInvalid: () => true,
63
+ message: 'Leaves at different depths cannot be reordered'
64
+ }, {
65
+ name: 'leaf-to-leaf-invalid-below',
66
+ applies: ctx => _internals.commonReorderConditions.isLeafToLeaf(ctx) && _internals.commonReorderConditions.sameDepth(ctx) && !_internals.commonReorderConditions.sameParent(ctx) && _internals.commonReorderConditions.isDropBelow(ctx),
67
+ isInvalid: ctx => !(_internals.commonReorderConditions.nextIsGroup(ctx) && ctx.sourceNode.depth > ctx.nextNode.depth) && !_internals.commonReorderConditions.nextIsLeaf(ctx),
68
+ message: 'Invalid leaf below leaf configuration'
69
+ },
70
+ // ===== Leaf to Group Rules =====
71
+ {
72
+ name: 'leaf-to-group-above-no-prev-leaf',
73
+ applies: ctx => _internals.commonReorderConditions.isLeafToGroup(ctx) && _internals.commonReorderConditions.isDropAbove(ctx),
74
+ isInvalid: ctx => !_internals.commonReorderConditions.hasPrevNode(ctx) || !_internals.commonReorderConditions.prevIsLeaf(ctx),
75
+ message: 'No valid previous leaf for leaf above group'
76
+ }, {
77
+ name: 'leaf-to-group-above-depth-mismatch',
78
+ applies: ctx => _internals.commonReorderConditions.isLeafToGroup(ctx) && _internals.commonReorderConditions.isDropAbove(ctx) && _internals.commonReorderConditions.prevIsLeaf(ctx) && !(ctx.sourceNode.depth > ctx.targetNode.depth && ctx.targetNode.depth === 0),
79
+ isInvalid: ctx => ctx.prevNode.depth !== ctx.sourceNode.depth,
80
+ message: 'Previous node depth mismatch for leaf above group'
81
+ }, {
82
+ name: 'leaf-to-group-below-collapsed',
83
+ applies: ctx => _internals.commonReorderConditions.isLeafToGroup(ctx) && _internals.commonReorderConditions.isDropBelow(ctx),
84
+ isInvalid: _internals.commonReorderConditions.targetGroupCollapsed,
85
+ message: 'Cannot drop below collapsed group'
86
+ }, {
87
+ name: 'leaf-to-group-below-invalid-depth',
88
+ applies: ctx => _internals.commonReorderConditions.isLeafToGroup(ctx) && _internals.commonReorderConditions.isDropBelow(ctx) && _internals.commonReorderConditions.targetGroupExpanded(ctx),
89
+ isInvalid: ctx => {
90
+ // Valid case 1: Target is parent level
91
+ if (ctx.sourceNode.depth > ctx.targetNode.depth && ctx.targetNode.depth === ctx.sourceNode.depth - 1) {
92
+ return false;
93
+ }
94
+ // Valid case 2: First child has same depth as source
95
+ if (_internals.commonReorderConditions.targetFirstChildDepthEqualsSource(ctx)) {
96
+ return false;
97
+ }
98
+ return true;
99
+ },
100
+ message: 'Invalid depth configuration for leaf below group'
101
+ }];
102
+ const rowGroupingReorderValidator = exports.rowGroupingReorderValidator = new _internals.RowReorderValidator(validationRules);
@@ -1,7 +1,7 @@
1
- import { GridRowId } from '@mui/x-data-grid-pro';
2
1
  import type { RefObject } from '@mui/x-internals/types';
3
2
  import type { GridPrivateApiPremium } from "../../../models/gridApiPremium.js";
4
3
  import type { DataGridPremiumProcessedProps } from "../../../models/dataGridPremiumProps.js";
5
- export declare const useGridRowsOverridableMethods: (apiRef: RefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, "processRowUpdate" | "onProcessRowUpdateError">) => {
6
- setRowIndex: (rowId: GridRowId, targetIndex: number) => void;
4
+ export declare const useGridRowsOverridableMethods: (apiRef: RefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, "processRowUpdate" | "onProcessRowUpdateError" | "treeData">) => {
5
+ setRowIndex: (rowId: import("@mui/x-data-grid").GridRowId, targetIndex: number) => void;
6
+ setRowPosition: (sourceRowId: import("@mui/x-data-grid").GridRowId, targetRowId: import("@mui/x-data-grid").GridRowId, position: import("@mui/x-data-grid/internals").RowReorderDropPosition) => void | Promise<void>;
7
7
  };