@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.
- package/CHANGELOG.md +174 -0
- package/DataGridPremium/DataGridPremium.d.ts +1 -1
- package/DataGridPremium/DataGridPremium.js +27 -1
- package/DataGridPremium/useDataGridPremiumComponent.d.ts +1 -1
- package/esm/DataGridPremium/DataGridPremium.d.ts +1 -1
- package/esm/DataGridPremium/DataGridPremium.js +27 -1
- package/esm/DataGridPremium/useDataGridPremiumComponent.d.ts +1 -1
- package/esm/hooks/features/clipboard/useGridClipboardImport.js +6 -0
- package/esm/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
- package/esm/hooks/features/rowGrouping/useGridRowGrouping.js +21 -17
- package/esm/hooks/features/rowReorder/operations.d.ts +7 -27
- package/esm/hooks/features/rowReorder/operations.js +133 -274
- package/esm/hooks/features/rowReorder/rowGroupingReorderExecutor.d.ts +2 -0
- package/esm/hooks/features/rowReorder/rowGroupingReorderExecutor.js +3 -0
- package/esm/hooks/features/rowReorder/rowGroupingReorderValidator.d.ts +2 -0
- package/esm/hooks/features/rowReorder/{reorderValidator.js → rowGroupingReorderValidator.js} +2 -22
- package/esm/hooks/features/rows/useGridRowsOverridableMethods.d.ts +3 -3
- package/esm/hooks/features/rows/useGridRowsOverridableMethods.js +61 -7
- package/esm/index.js +1 -1
- package/hooks/features/clipboard/useGridClipboardImport.js +6 -0
- package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
- package/hooks/features/rowGrouping/useGridRowGrouping.js +20 -16
- package/hooks/features/rowReorder/operations.d.ts +7 -27
- package/hooks/features/rowReorder/operations.js +136 -279
- package/hooks/features/rowReorder/rowGroupingReorderExecutor.d.ts +2 -0
- package/hooks/features/rowReorder/rowGroupingReorderExecutor.js +9 -0
- package/hooks/features/rowReorder/rowGroupingReorderValidator.d.ts +2 -0
- package/hooks/features/rowReorder/rowGroupingReorderValidator.js +102 -0
- package/hooks/features/rows/useGridRowsOverridableMethods.d.ts +3 -3
- package/hooks/features/rows/useGridRowsOverridableMethods.js +61 -7
- package/index.js +1 -1
- package/package.json +5 -5
- package/esm/hooks/features/rowReorder/reorderExecutor.d.ts +0 -15
- package/esm/hooks/features/rowReorder/reorderExecutor.js +0 -25
- package/esm/hooks/features/rowReorder/reorderValidator.d.ts +0 -16
- package/esm/hooks/features/rowReorder/types.d.ts +0 -42
- package/esm/hooks/features/rowReorder/types.js +0 -1
- package/esm/hooks/features/rowReorder/utils.d.ts +0 -127
- package/esm/hooks/features/rowReorder/utils.js +0 -343
- package/hooks/features/rowReorder/reorderExecutor.d.ts +0 -15
- package/hooks/features/rowReorder/reorderExecutor.js +0 -31
- package/hooks/features/rowReorder/reorderValidator.d.ts +0 -16
- package/hooks/features/rowReorder/reorderValidator.js +0 -122
- package/hooks/features/rowReorder/types.d.ts +0 -42
- package/hooks/features/rowReorder/types.js +0 -5
- package/hooks/features/rowReorder/utils.d.ts +0 -127
- package/hooks/features/rowReorder/utils.js +0 -360
|
@@ -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
|
};
|
|
@@ -8,28 +8,44 @@ exports.useGridRowsOverridableMethods = void 0;
|
|
|
8
8
|
var React = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _xDataGridPro = require("@mui/x-data-grid-pro");
|
|
10
10
|
var _internals = require("@mui/x-data-grid-pro/internals");
|
|
11
|
-
var
|
|
11
|
+
var _rowGroupingReorderExecutor = require("../rowReorder/rowGroupingReorderExecutor");
|
|
12
12
|
const useGridRowsOverridableMethods = (apiRef, props) => {
|
|
13
13
|
const {
|
|
14
14
|
processRowUpdate,
|
|
15
15
|
onProcessRowUpdateError
|
|
16
16
|
} = props;
|
|
17
17
|
const {
|
|
18
|
-
setRowIndex: setRowIndexPlain
|
|
19
|
-
|
|
18
|
+
setRowIndex: setRowIndexPlain,
|
|
19
|
+
setRowPosition: setRowPositionPlain
|
|
20
|
+
} = (0, _internals.useGridRowsOverridableMethodsCommunity)(apiRef);
|
|
21
|
+
const {
|
|
22
|
+
setRowIndex: setRowIndexTreeData,
|
|
23
|
+
setRowPosition: setRowPositionTreeData
|
|
24
|
+
} = (0, _internals.useGridRowsOverridableMethodsPro)(apiRef, props);
|
|
20
25
|
const flatTree = (0, _internals.useGridSelector)(apiRef, _xDataGridPro.gridRowMaximumTreeDepthSelector) === 1;
|
|
21
|
-
const
|
|
26
|
+
const setRowPosition = React.useCallback(async (sourceRowId, targetRowId, position) => {
|
|
22
27
|
const sortedFilteredRowIds = (0, _xDataGridPro.gridExpandedSortedRowIdsSelector)(apiRef);
|
|
23
|
-
const sortedFilteredRowIndexLookup = (0,
|
|
28
|
+
const sortedFilteredRowIndexLookup = (0, _xDataGridPro.gridExpandedSortedRowIndexLookupSelector)(apiRef);
|
|
24
29
|
const rowTree = (0, _xDataGridPro.gridRowTreeSelector)(apiRef);
|
|
25
30
|
const sourceNode = (0, _xDataGridPro.gridRowNodeSelector)(apiRef, sourceRowId);
|
|
31
|
+
const targetNode = (0, _xDataGridPro.gridRowNodeSelector)(apiRef, targetRowId);
|
|
26
32
|
if (!sourceNode) {
|
|
27
33
|
throw new Error(`MUI X: No row with id #${sourceRowId} found.`);
|
|
28
34
|
}
|
|
35
|
+
if (!targetNode) {
|
|
36
|
+
throw new Error(`MUI X: No row with id #${targetRowId} found.`);
|
|
37
|
+
}
|
|
29
38
|
if (sourceNode.type === 'footer') {
|
|
30
39
|
throw new Error(`MUI X: The row reordering do not support reordering of footer rows.`);
|
|
31
40
|
}
|
|
32
41
|
|
|
42
|
+
// Get the target index from the targetRowId using the lookup selector
|
|
43
|
+
const targetIndexUnadjusted = sortedFilteredRowIndexLookup[targetRowId];
|
|
44
|
+
if (targetIndexUnadjusted === undefined) {
|
|
45
|
+
throw new Error(`MUI X: Target row with id #${targetRowId} not found in current view.`);
|
|
46
|
+
}
|
|
47
|
+
const targetIndex = position === 'below' ? targetIndexUnadjusted + 1 : targetIndexUnadjusted;
|
|
48
|
+
|
|
33
49
|
/**
|
|
34
50
|
* Row Grouping Reordering Use Cases
|
|
35
51
|
* =================================
|
|
@@ -47,6 +63,31 @@ const useGridRowsOverridableMethods = (apiRef, props) => {
|
|
|
47
63
|
|
|
48
64
|
const executionContext = {
|
|
49
65
|
sourceRowId,
|
|
66
|
+
dropPosition: position,
|
|
67
|
+
placeholderIndex: targetIndex,
|
|
68
|
+
sortedFilteredRowIds,
|
|
69
|
+
sortedFilteredRowIndexLookup,
|
|
70
|
+
rowTree,
|
|
71
|
+
apiRef,
|
|
72
|
+
processRowUpdate,
|
|
73
|
+
onProcessRowUpdateError
|
|
74
|
+
};
|
|
75
|
+
return _rowGroupingReorderExecutor.rowGroupingReorderExecutor.execute(executionContext);
|
|
76
|
+
}, [apiRef, processRowUpdate, onProcessRowUpdateError]);
|
|
77
|
+
const setRowIndex = React.useCallback(async (sourceRowId, targetOriginalIndex) => {
|
|
78
|
+
const sortedFilteredRowIds = (0, _xDataGridPro.gridExpandedSortedRowIdsSelector)(apiRef);
|
|
79
|
+
const sortedFilteredRowIndexLookup = (0, _xDataGridPro.gridExpandedSortedRowIndexLookupSelector)(apiRef);
|
|
80
|
+
const rowTree = (0, _xDataGridPro.gridRowTreeSelector)(apiRef);
|
|
81
|
+
const sourceNode = (0, _xDataGridPro.gridRowNodeSelector)(apiRef, sourceRowId);
|
|
82
|
+
if (!sourceNode) {
|
|
83
|
+
throw new Error(`MUI X: No row with id #${sourceRowId} found.`);
|
|
84
|
+
}
|
|
85
|
+
if (sourceNode.type === 'footer') {
|
|
86
|
+
throw new Error(`MUI X: The row reordering do not support reordering of footer rows.`);
|
|
87
|
+
}
|
|
88
|
+
const executionContext = {
|
|
89
|
+
sourceRowId,
|
|
90
|
+
dropPosition: 'below',
|
|
50
91
|
placeholderIndex: targetOriginalIndex,
|
|
51
92
|
sortedFilteredRowIds,
|
|
52
93
|
sortedFilteredRowIndexLookup,
|
|
@@ -55,10 +96,23 @@ const useGridRowsOverridableMethods = (apiRef, props) => {
|
|
|
55
96
|
processRowUpdate,
|
|
56
97
|
onProcessRowUpdateError
|
|
57
98
|
};
|
|
58
|
-
|
|
99
|
+
return _rowGroupingReorderExecutor.rowGroupingReorderExecutor.execute(executionContext);
|
|
59
100
|
}, [apiRef, processRowUpdate, onProcessRowUpdateError]);
|
|
101
|
+
if (flatTree) {
|
|
102
|
+
return {
|
|
103
|
+
setRowIndex: setRowIndexPlain,
|
|
104
|
+
setRowPosition: setRowPositionPlain
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (props.treeData) {
|
|
108
|
+
return {
|
|
109
|
+
setRowIndex: setRowIndexTreeData,
|
|
110
|
+
setRowPosition: setRowPositionTreeData
|
|
111
|
+
};
|
|
112
|
+
}
|
|
60
113
|
return {
|
|
61
|
-
setRowIndex
|
|
114
|
+
setRowIndex,
|
|
115
|
+
setRowPosition
|
|
62
116
|
};
|
|
63
117
|
};
|
|
64
118
|
exports.useGridRowsOverridableMethods = useGridRowsOverridableMethods;
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-data-grid-premium",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.21.0",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "The Premium plan edition of the MUI X Data Grid Components.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"@mui/x-internal-exceljs-fork": "4.4.3",
|
|
39
39
|
"clsx": "^2.1.1",
|
|
40
40
|
"prop-types": "^15.8.1",
|
|
41
|
-
"@mui/x-data-grid-pro": "8.
|
|
42
|
-
"@mui/x-data-grid": "8.
|
|
43
|
-
"@mui/x-internals": "8.
|
|
44
|
-
"@mui/x-license": "8.
|
|
41
|
+
"@mui/x-data-grid-pro": "8.21.0",
|
|
42
|
+
"@mui/x-data-grid": "8.21.0",
|
|
43
|
+
"@mui/x-internals": "8.21.0",
|
|
44
|
+
"@mui/x-license": "8.21.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@emotion/react": "^11.9.0",
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { BaseReorderOperation } from "./operations.js";
|
|
2
|
-
import type { ReorderExecutionContext } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Executor class for handling row reorder operations in grouped data grids.
|
|
5
|
-
*
|
|
6
|
-
* This class coordinates the execution of different reorder operation types,
|
|
7
|
-
* trying each operation in order until one succeeds or all fail.
|
|
8
|
-
*/
|
|
9
|
-
declare class RowReorderExecutor {
|
|
10
|
-
private operations;
|
|
11
|
-
constructor(operations: BaseReorderOperation[]);
|
|
12
|
-
execute(ctx: ReorderExecutionContext): Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
export declare const rowGroupingReorderExecutor: RowReorderExecutor;
|
|
15
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { warnOnce } from '@mui/x-internals/warning';
|
|
2
|
-
import { SameParentSwapOperation, CrossParentLeafOperation, CrossParentGroupOperation } from "./operations.js";
|
|
3
|
-
/**
|
|
4
|
-
* Executor class for handling row reorder operations in grouped data grids.
|
|
5
|
-
*
|
|
6
|
-
* This class coordinates the execution of different reorder operation types,
|
|
7
|
-
* trying each operation in order until one succeeds or all fail.
|
|
8
|
-
*/
|
|
9
|
-
class RowReorderExecutor {
|
|
10
|
-
constructor(operations) {
|
|
11
|
-
this.operations = operations;
|
|
12
|
-
}
|
|
13
|
-
async execute(ctx) {
|
|
14
|
-
for (const operation of this.operations) {
|
|
15
|
-
const detectedOperation = operation.detectOperation(ctx);
|
|
16
|
-
if (detectedOperation) {
|
|
17
|
-
// eslint-disable-next-line no-await-in-loop
|
|
18
|
-
await operation.executeOperation(detectedOperation, ctx);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
warnOnce(['MUI X: The parameters provided to the `setRowIndex()` resulted in a no-op.', 'Consider looking at the documentation at https://mui.com/x/react-data-grid/row-grouping/'], 'warning');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export const rowGroupingReorderExecutor = new RowReorderExecutor([new SameParentSwapOperation(), new CrossParentLeafOperation(), new CrossParentGroupOperation()]);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ReorderValidationContext } from "./types.js";
|
|
2
|
-
interface ValidationRule {
|
|
3
|
-
name: string;
|
|
4
|
-
applies: (ctx: ReorderValidationContext) => boolean;
|
|
5
|
-
isInvalid: (ctx: ReorderValidationContext) => boolean;
|
|
6
|
-
message?: string;
|
|
7
|
-
}
|
|
8
|
-
declare class RowReorderValidator {
|
|
9
|
-
private rules;
|
|
10
|
-
constructor(rules?: ValidationRule[]);
|
|
11
|
-
addRule(rule: ValidationRule): void;
|
|
12
|
-
removeRule(ruleName: string): void;
|
|
13
|
-
validate(context: ReorderValidationContext): boolean;
|
|
14
|
-
}
|
|
15
|
-
export declare const rowGroupingReorderValidator: RowReorderValidator;
|
|
16
|
-
export {};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { GridRowId, GridTreeNode } from '@mui/x-data-grid-pro';
|
|
2
|
-
import type { GridRowTreeConfig } from '@mui/x-data-grid-pro';
|
|
3
|
-
import { RefObject } from '@mui/x-internals/types';
|
|
4
|
-
import { GridPrivateApiPremium } from "../../../models/gridApiPremium.js";
|
|
5
|
-
import { DataGridPremiumProcessedProps } from "../../../models/dataGridPremiumProps.js";
|
|
6
|
-
export type DropPosition = 'above' | 'below';
|
|
7
|
-
export type DragDirection = 'up' | 'down';
|
|
8
|
-
export interface ReorderValidationContext {
|
|
9
|
-
sourceNode: GridTreeNode;
|
|
10
|
-
targetNode: GridTreeNode;
|
|
11
|
-
prevNode: GridTreeNode | null;
|
|
12
|
-
nextNode: GridTreeNode | null;
|
|
13
|
-
rowTree: Record<GridRowId, GridTreeNode>;
|
|
14
|
-
dropPosition: DropPosition;
|
|
15
|
-
dragDirection: DragDirection;
|
|
16
|
-
targetRowIndex: number;
|
|
17
|
-
sourceRowIndex: number;
|
|
18
|
-
expandedSortedRowIndexLookup: Record<GridRowId, number>;
|
|
19
|
-
}
|
|
20
|
-
export interface ReorderExecutionContext {
|
|
21
|
-
sourceRowId: GridRowId;
|
|
22
|
-
placeholderIndex: number;
|
|
23
|
-
sortedFilteredRowIds: GridRowId[];
|
|
24
|
-
sortedFilteredRowIndexLookup: Record<GridRowId, number>;
|
|
25
|
-
rowTree: GridRowTreeConfig;
|
|
26
|
-
apiRef: RefObject<GridPrivateApiPremium>;
|
|
27
|
-
processRowUpdate?: DataGridPremiumProcessedProps['processRowUpdate'];
|
|
28
|
-
onProcessRowUpdateError?: DataGridPremiumProcessedProps['onProcessRowUpdateError'];
|
|
29
|
-
}
|
|
30
|
-
export interface ReorderOperation {
|
|
31
|
-
sourceNode: GridTreeNode;
|
|
32
|
-
targetNode: GridTreeNode;
|
|
33
|
-
actualTargetIndex: number;
|
|
34
|
-
isLastChild: boolean;
|
|
35
|
-
operationType: ReorderOperationType;
|
|
36
|
-
}
|
|
37
|
-
export interface ReorderScenario {
|
|
38
|
-
name: string;
|
|
39
|
-
detectOperation: (ctx: ReorderExecutionContext) => ReorderOperation | null;
|
|
40
|
-
execute: (operation: ReorderOperation, ctx: ReorderExecutionContext) => Promise<void> | void;
|
|
41
|
-
}
|
|
42
|
-
export type ReorderOperationType = 'same-parent-swap' | 'cross-parent-leaf' | 'cross-parent-group';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import type { RefObject } from '@mui/x-internals/types';
|
|
2
|
-
import { type GridRowId, type GridTreeNode, type GridGroupNode, type GridRowTreeConfig, type GridKeyValue, type GridValidRowModel } from '@mui/x-data-grid-pro';
|
|
3
|
-
import type { RowTreeBuilderGroupingCriterion } from '@mui/x-data-grid-pro/internals';
|
|
4
|
-
import type { ReorderValidationContext as Ctx, ReorderOperationType } from "./types.js";
|
|
5
|
-
import type { GridPrivateApiPremium } from "../../../models/gridApiPremium.js";
|
|
6
|
-
import { DataGridPremiumProcessedProps } from "../../../models/dataGridPremiumProps.js";
|
|
7
|
-
/**
|
|
8
|
-
* Reusable validation conditions for row reordering validation
|
|
9
|
-
*/
|
|
10
|
-
export declare const conditions: {
|
|
11
|
-
isGroupToGroup: (ctx: Ctx) => boolean;
|
|
12
|
-
isLeafToLeaf: (ctx: Ctx) => boolean;
|
|
13
|
-
isLeafToGroup: (ctx: Ctx) => boolean;
|
|
14
|
-
isGroupToLeaf: (ctx: Ctx) => boolean;
|
|
15
|
-
isDropAbove: (ctx: Ctx) => boolean;
|
|
16
|
-
isDropBelow: (ctx: Ctx) => boolean;
|
|
17
|
-
sameDepth: (ctx: Ctx) => boolean;
|
|
18
|
-
sourceDepthGreater: (ctx: Ctx) => boolean;
|
|
19
|
-
targetDepthIsSourceMinusOne: (ctx: Ctx) => boolean;
|
|
20
|
-
sameParent: (ctx: Ctx) => boolean;
|
|
21
|
-
targetGroupExpanded: (ctx: Ctx) => boolean;
|
|
22
|
-
targetGroupCollapsed: (ctx: Ctx) => boolean;
|
|
23
|
-
hasPrevNode: (ctx: Ctx) => boolean;
|
|
24
|
-
hasNextNode: (ctx: Ctx) => boolean;
|
|
25
|
-
prevIsLeaf: (ctx: Ctx) => boolean;
|
|
26
|
-
prevIsGroup: (ctx: Ctx) => boolean;
|
|
27
|
-
nextIsLeaf: (ctx: Ctx) => boolean;
|
|
28
|
-
nextIsGroup: (ctx: Ctx) => boolean;
|
|
29
|
-
prevDepthEquals: (ctx: Ctx, depth: number) => boolean;
|
|
30
|
-
prevDepthEqualsSource: (ctx: Ctx) => boolean;
|
|
31
|
-
prevBelongsToSource: (ctx: Ctx) => boolean;
|
|
32
|
-
isAdjacentPosition: (ctx: Ctx) => boolean;
|
|
33
|
-
targetFirstChildIsGroupWithSourceDepth: (ctx: Ctx) => boolean;
|
|
34
|
-
targetFirstChildDepthEqualsSource: (ctx: Ctx) => boolean;
|
|
35
|
-
};
|
|
36
|
-
export declare function determineOperationType(sourceNode: GridTreeNode, targetNode: GridTreeNode): ReorderOperationType;
|
|
37
|
-
export declare function calculateTargetIndex(sourceNode: GridTreeNode, targetNode: GridTreeNode, isLastChild: boolean, rowTree: Record<GridRowId, GridTreeNode>): number;
|
|
38
|
-
export declare const getNodePathInTree: ({
|
|
39
|
-
id,
|
|
40
|
-
tree
|
|
41
|
-
}: {
|
|
42
|
-
id: GridRowId;
|
|
43
|
-
tree: GridRowTreeConfig;
|
|
44
|
-
}) => RowTreeBuilderGroupingCriterion[];
|
|
45
|
-
export declare const collectAllLeafDescendants: (groupNode: GridGroupNode, tree: GridRowTreeConfig) => GridRowId[];
|
|
46
|
-
/**
|
|
47
|
-
* Adjusts the target node based on specific reorder scenarios and constraints.
|
|
48
|
-
*
|
|
49
|
-
* This function applies scenario-specific logic to find the actual target node
|
|
50
|
-
* for operations, handling cases like:
|
|
51
|
-
* - Moving to collapsed groups
|
|
52
|
-
* - Depth-based adjustments
|
|
53
|
-
* - End-of-list positioning
|
|
54
|
-
*
|
|
55
|
-
* @param sourceNode The node being moved
|
|
56
|
-
* @param targetNode The initial target node
|
|
57
|
-
* @param targetIndex The index of the target node in the visible rows
|
|
58
|
-
* @param placeholderIndex The index where the placeholder appears
|
|
59
|
-
* @param sortedFilteredRowIds Array of visible row IDs in display order
|
|
60
|
-
* @param apiRef Reference to the grid API
|
|
61
|
-
* @returns Object containing the adjusted target node and last child flag
|
|
62
|
-
*/
|
|
63
|
-
export declare function adjustTargetNode(sourceNode: GridTreeNode, targetNode: GridTreeNode, targetIndex: number, placeholderIndex: number, sortedFilteredRowIds: GridRowId[], apiRef: RefObject<GridPrivateApiPremium>): {
|
|
64
|
-
adjustedTargetNode: GridTreeNode;
|
|
65
|
-
isLastChild: boolean;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Finds an existing group node with the same groupingKey and groupingField under a parent.
|
|
69
|
-
*
|
|
70
|
-
* @param parentNode - The parent group node to search in
|
|
71
|
-
* @param groupingKey - The grouping key to match
|
|
72
|
-
* @param groupingField - The grouping field to match
|
|
73
|
-
* @param tree - The row tree configuration
|
|
74
|
-
* @returns The existing group node if found, null otherwise
|
|
75
|
-
*/
|
|
76
|
-
export declare function findExistingGroupWithSameKey(parentNode: GridGroupNode, groupingKey: GridKeyValue, groupingField: string, tree: GridRowTreeConfig): GridGroupNode | null;
|
|
77
|
-
/**
|
|
78
|
-
* Removes empty ancestor groups from the tree after a row move operation.
|
|
79
|
-
* Walks up the tree from the given group, removing any empty groups encountered.
|
|
80
|
-
*
|
|
81
|
-
* @param groupId - The ID of the group to start checking from
|
|
82
|
-
* @param tree - The row tree configuration
|
|
83
|
-
* @param removedGroups - Set to track which groups have been removed
|
|
84
|
-
* @returns The number of root-level groups that were removed
|
|
85
|
-
*/
|
|
86
|
-
export declare function removeEmptyAncestors(groupId: GridRowId, tree: GridRowTreeConfig, removedGroups: Set<GridRowId>): number;
|
|
87
|
-
export declare function handleProcessRowUpdateError(error: any, onProcessRowUpdateError?: DataGridPremiumProcessedProps['onProcessRowUpdateError']): void;
|
|
88
|
-
/**
|
|
89
|
-
* Handles batch row updates with partial failure tracking.
|
|
90
|
-
*
|
|
91
|
-
* This class is designed for operations that need to update multiple rows
|
|
92
|
-
* atomically (like moving entire groups), while gracefully handling cases
|
|
93
|
-
* where some updates succeed and others fail.
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```tsx
|
|
97
|
-
* const updater = new BatchRowUpdater(processRowUpdate, onError);
|
|
98
|
-
*
|
|
99
|
-
* // Queue multiple updates
|
|
100
|
-
* updater.queueUpdate('row1', originalRow1, newRow1);
|
|
101
|
-
* updater.queueUpdate('row2', originalRow2, newRow2);
|
|
102
|
-
*
|
|
103
|
-
* // Execute all updates
|
|
104
|
-
* const { successful, failed, updates } = await updater.executeAll();
|
|
105
|
-
*
|
|
106
|
-
* // Handle results
|
|
107
|
-
* if (successful.length > 0) {
|
|
108
|
-
* apiRef.current.updateRows(updates);
|
|
109
|
-
* }
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
export declare class BatchRowUpdater {
|
|
113
|
-
private processRowUpdate;
|
|
114
|
-
private onProcessRowUpdateError;
|
|
115
|
-
private rowsToUpdate;
|
|
116
|
-
private originalRows;
|
|
117
|
-
private successfulRowIds;
|
|
118
|
-
private failedRowIds;
|
|
119
|
-
private pendingRowUpdates;
|
|
120
|
-
constructor(processRowUpdate: DataGridPremiumProcessedProps['processRowUpdate'] | undefined, onProcessRowUpdateError: DataGridPremiumProcessedProps['onProcessRowUpdateError'] | undefined);
|
|
121
|
-
queueUpdate(rowId: GridRowId, originalRow: GridValidRowModel, updatedRow: GridValidRowModel): void;
|
|
122
|
-
executeAll(): Promise<{
|
|
123
|
-
successful: GridRowId[];
|
|
124
|
-
failed: GridRowId[];
|
|
125
|
-
updates: GridValidRowModel[];
|
|
126
|
-
}>;
|
|
127
|
-
}
|