@mui/x-data-grid-pro 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/DataGridPro/DataGridPro.js +29 -2
- package/components/GridRowReorderCell.js +15 -3
- package/components/headerFiltering/GridHeaderFilterCell.js +2 -3
- package/esm/DataGridPro/DataGridPro.js +29 -2
- package/esm/components/GridRowReorderCell.js +15 -3
- package/esm/components/headerFiltering/GridHeaderFilterCell.js +2 -3
- package/esm/hooks/features/dataSource/useGridDataSourceBasePro.js +1 -1
- package/esm/hooks/features/rowReorder/commonReorderConditions.d.ts +30 -0
- package/esm/hooks/features/rowReorder/commonReorderConditions.js +78 -0
- package/esm/hooks/features/rowReorder/index.d.ts +2 -1
- package/esm/hooks/features/rowReorder/index.js +2 -1
- package/esm/hooks/features/rowReorder/models.d.ts +17 -0
- package/esm/hooks/features/rowReorder/models.js +1 -0
- package/esm/hooks/features/rowReorder/reorderExecutor.d.ts +27 -0
- package/esm/hooks/features/rowReorder/reorderExecutor.js +29 -0
- package/esm/hooks/features/rowReorder/reorderValidator.d.ts +12 -0
- package/esm/hooks/features/rowReorder/reorderValidator.js +14 -0
- package/esm/hooks/features/rowReorder/types.d.ts +25 -0
- package/esm/hooks/features/rowReorder/types.js +1 -0
- package/esm/hooks/features/rowReorder/useGridRowReorder.d.ts +1 -1
- package/esm/hooks/features/rowReorder/useGridRowReorder.js +167 -80
- package/esm/hooks/features/rowReorder/utils.d.ts +82 -0
- package/esm/hooks/features/rowReorder/utils.js +259 -0
- package/esm/hooks/features/rows/useGridRowsOverridableMethods.d.ts +7 -0
- package/esm/hooks/features/rows/useGridRowsOverridableMethods.js +59 -0
- package/esm/hooks/features/treeData/treeDataReorderExecutor.d.ts +11 -0
- package/esm/hooks/features/treeData/treeDataReorderExecutor.js +534 -0
- package/esm/hooks/features/treeData/treeDataReorderValidator.d.ts +2 -0
- package/esm/hooks/features/treeData/treeDataReorderValidator.js +35 -0
- package/esm/hooks/features/treeData/useGridTreeData.d.ts +3 -3
- package/esm/hooks/features/treeData/useGridTreeData.js +49 -4
- package/esm/hooks/features/treeData/utils.d.ts +8 -0
- package/esm/hooks/features/treeData/utils.js +96 -0
- package/esm/index.js +1 -1
- package/esm/internals/index.d.ts +8 -0
- package/esm/internals/index.js +6 -0
- package/esm/models/dataGridProProps.d.ts +32 -4
- package/esm/models/gridRowOrderChangeParams.d.ts +29 -5
- package/hooks/features/dataSource/useGridDataSourceBasePro.js +1 -1
- package/hooks/features/rowReorder/commonReorderConditions.d.ts +30 -0
- package/hooks/features/rowReorder/commonReorderConditions.js +84 -0
- package/hooks/features/rowReorder/index.d.ts +2 -1
- package/hooks/features/rowReorder/models.d.ts +17 -0
- package/hooks/features/rowReorder/models.js +5 -0
- package/hooks/features/rowReorder/reorderExecutor.d.ts +27 -0
- package/hooks/features/rowReorder/reorderExecutor.js +37 -0
- package/hooks/features/rowReorder/reorderValidator.d.ts +12 -0
- package/hooks/features/rowReorder/reorderValidator.js +21 -0
- package/hooks/features/rowReorder/types.d.ts +25 -0
- package/hooks/features/rowReorder/types.js +5 -0
- package/hooks/features/rowReorder/useGridRowReorder.d.ts +1 -1
- package/hooks/features/rowReorder/useGridRowReorder.js +168 -81
- package/hooks/features/rowReorder/utils.d.ts +82 -0
- package/hooks/features/rowReorder/utils.js +286 -0
- package/hooks/features/rows/useGridRowsOverridableMethods.d.ts +7 -0
- package/hooks/features/rows/useGridRowsOverridableMethods.js +67 -0
- package/hooks/features/treeData/treeDataReorderExecutor.d.ts +11 -0
- package/hooks/features/treeData/treeDataReorderExecutor.js +541 -0
- package/hooks/features/treeData/treeDataReorderValidator.d.ts +2 -0
- package/hooks/features/treeData/treeDataReorderValidator.js +41 -0
- package/hooks/features/treeData/useGridTreeData.d.ts +3 -3
- package/hooks/features/treeData/useGridTreeData.js +48 -3
- package/hooks/features/treeData/utils.d.ts +8 -0
- package/hooks/features/treeData/utils.js +109 -0
- package/index.js +1 -1
- package/internals/index.d.ts +8 -0
- package/internals/index.js +53 -1
- package/models/dataGridProProps.d.ts +32 -4
- package/models/gridRowOrderChangeParams.d.ts +29 -5
- package/package.json +4 -4
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.BatchRowUpdater = void 0;
|
|
8
|
+
exports.calculateTargetIndex = calculateTargetIndex;
|
|
9
|
+
exports.collectAllLeafDescendants = exports.collectAllDescendants = void 0;
|
|
10
|
+
exports.determineOperationType = determineOperationType;
|
|
11
|
+
exports.findCellElement = findCellElement;
|
|
12
|
+
exports.findExistingGroupWithSameKey = findExistingGroupWithSameKey;
|
|
13
|
+
Object.defineProperty(exports, "getNodePathInTree", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _utils.getNodePathInTree;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
exports.handleProcessRowUpdateError = handleProcessRowUpdateError;
|
|
20
|
+
exports.isDescendantOf = void 0;
|
|
21
|
+
exports.removeEmptyAncestors = removeEmptyAncestors;
|
|
22
|
+
exports.updateDescendantDepths = void 0;
|
|
23
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
24
|
+
var _xDataGrid = require("@mui/x-data-grid");
|
|
25
|
+
var _warning = require("@mui/x-internals/warning");
|
|
26
|
+
var _utils = require("../../../utils/tree/utils");
|
|
27
|
+
// Re-export to be made part of `rowReorderUtils`
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Finds the closest cell element from the given event target.
|
|
31
|
+
* If the target itself is a cell, returns it.
|
|
32
|
+
* Otherwise, searches for the closest parent with 'cell' in its className.
|
|
33
|
+
* @param target - The event target to start searching from
|
|
34
|
+
* @returns The cell element or the original target if no cell is found
|
|
35
|
+
*/
|
|
36
|
+
function findCellElement(target) {
|
|
37
|
+
const element = target;
|
|
38
|
+
if (!element) {
|
|
39
|
+
return element;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Check if the target itself is a cell
|
|
43
|
+
if (element instanceof Element && element.classList.contains(_xDataGrid.gridClasses.cell)) {
|
|
44
|
+
return element;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Try to find the closest cell parent
|
|
48
|
+
const cellElement = element.closest(`[class*="${_xDataGrid.gridClasses.cell}"]`);
|
|
49
|
+
return cellElement || element;
|
|
50
|
+
}
|
|
51
|
+
function determineOperationType(sourceNode, targetNode) {
|
|
52
|
+
if (sourceNode.parent === targetNode.parent) {
|
|
53
|
+
return 'same-parent-swap';
|
|
54
|
+
}
|
|
55
|
+
if (sourceNode.type === 'leaf') {
|
|
56
|
+
return 'cross-parent-leaf';
|
|
57
|
+
}
|
|
58
|
+
return 'cross-parent-group';
|
|
59
|
+
}
|
|
60
|
+
function calculateTargetIndex(sourceNode, targetNode, isLastChild, rowTree) {
|
|
61
|
+
if (sourceNode.parent === targetNode.parent && !isLastChild) {
|
|
62
|
+
// Same parent: find target's position in parent's children
|
|
63
|
+
const parent = rowTree[sourceNode.parent];
|
|
64
|
+
return parent.children.findIndex(id => id === targetNode.id);
|
|
65
|
+
}
|
|
66
|
+
if (isLastChild) {
|
|
67
|
+
// Append at the end
|
|
68
|
+
const targetParent = rowTree[targetNode.parent];
|
|
69
|
+
return targetParent.children.length;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Find position in target parent
|
|
73
|
+
const targetParent = rowTree[targetNode.parent];
|
|
74
|
+
const targetIndex = targetParent.children.findIndex(id => id === targetNode.id);
|
|
75
|
+
return targetIndex >= 0 ? targetIndex : 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Recursively collect all leaf node IDs from a group
|
|
79
|
+
const collectAllLeafDescendants = (groupNode, tree) => {
|
|
80
|
+
const leafIds = [];
|
|
81
|
+
const collectFromNode = nodeId => {
|
|
82
|
+
const node = tree[nodeId];
|
|
83
|
+
if (node.type === 'leaf') {
|
|
84
|
+
leafIds.push(nodeId);
|
|
85
|
+
} else if (node.type === 'group') {
|
|
86
|
+
node.children.forEach(collectFromNode);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
groupNode.children.forEach(collectFromNode);
|
|
90
|
+
return leafIds;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// Recursively collect all descendant nodes (groups and leaves) from a group
|
|
94
|
+
exports.collectAllLeafDescendants = collectAllLeafDescendants;
|
|
95
|
+
const collectAllDescendants = (groupNode, tree) => {
|
|
96
|
+
const descendants = [];
|
|
97
|
+
const collectFromNode = nodeId => {
|
|
98
|
+
const node = tree[nodeId];
|
|
99
|
+
if (node) {
|
|
100
|
+
descendants.push(node);
|
|
101
|
+
if (node.type === 'group') {
|
|
102
|
+
node.children.forEach(collectFromNode);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
groupNode.children.forEach(collectFromNode);
|
|
107
|
+
return descendants;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// Check if a node is a descendant of another node
|
|
111
|
+
exports.collectAllDescendants = collectAllDescendants;
|
|
112
|
+
const isDescendantOf = (possibleDescendant, ancestor, tree) => {
|
|
113
|
+
let current = possibleDescendant;
|
|
114
|
+
while (current && current.id !== _xDataGrid.GRID_ROOT_GROUP_ID) {
|
|
115
|
+
if (current.id === ancestor.id) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
current = tree[current.parent];
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// Update depths for all descendant nodes recursively
|
|
124
|
+
exports.isDescendantOf = isDescendantOf;
|
|
125
|
+
const updateDescendantDepths = (group, tree, depthDiff) => {
|
|
126
|
+
const updateNodeDepth = nodeId => {
|
|
127
|
+
const node = tree[nodeId];
|
|
128
|
+
if (node) {
|
|
129
|
+
tree[nodeId] = (0, _extends2.default)({}, node, {
|
|
130
|
+
depth: node.depth + depthDiff
|
|
131
|
+
});
|
|
132
|
+
if (node.type === 'group') {
|
|
133
|
+
node.children.forEach(updateNodeDepth);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
group.children.forEach(updateNodeDepth);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Finds an existing group node with the same groupingKey and groupingField under a parent.
|
|
142
|
+
*
|
|
143
|
+
* @param parentNode - The parent group node to search in
|
|
144
|
+
* @param groupingKey - The grouping key to match
|
|
145
|
+
* @param groupingField - The grouping field to match
|
|
146
|
+
* @param tree - The row tree configuration
|
|
147
|
+
* @returns The existing group node if found, null otherwise
|
|
148
|
+
*/
|
|
149
|
+
exports.updateDescendantDepths = updateDescendantDepths;
|
|
150
|
+
function findExistingGroupWithSameKey(parentNode, groupingKey, groupingField, tree) {
|
|
151
|
+
for (const childId of parentNode.children) {
|
|
152
|
+
const childNode = tree[childId];
|
|
153
|
+
if (childNode && childNode.type === 'group' && childNode.groupingKey === groupingKey && childNode.groupingField === groupingField) {
|
|
154
|
+
return childNode;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Removes empty ancestor groups from the tree after a row move operation.
|
|
162
|
+
* Walks up the tree from the given group, removing any empty groups encountered.
|
|
163
|
+
*
|
|
164
|
+
* @param groupId - The ID of the group to start checking from
|
|
165
|
+
* @param tree - The row tree configuration
|
|
166
|
+
* @param removedGroups - Set to track which groups have been removed
|
|
167
|
+
* @returns The number of root-level groups that were removed
|
|
168
|
+
*/
|
|
169
|
+
function removeEmptyAncestors(groupId, tree, removedGroups) {
|
|
170
|
+
let rootLevelRemovals = 0;
|
|
171
|
+
let currentGroupId = groupId;
|
|
172
|
+
while (currentGroupId && currentGroupId !== _xDataGrid.GRID_ROOT_GROUP_ID) {
|
|
173
|
+
const group = tree[currentGroupId];
|
|
174
|
+
if (!group) {
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
const remainingChildren = group.children.filter(childId => !removedGroups.has(childId));
|
|
178
|
+
if (remainingChildren.length > 0) {
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
if (group.depth === 0) {
|
|
182
|
+
rootLevelRemovals += 1;
|
|
183
|
+
}
|
|
184
|
+
removedGroups.add(currentGroupId);
|
|
185
|
+
currentGroupId = group.parent;
|
|
186
|
+
}
|
|
187
|
+
return rootLevelRemovals;
|
|
188
|
+
}
|
|
189
|
+
function handleProcessRowUpdateError(error, onProcessRowUpdateError) {
|
|
190
|
+
if (onProcessRowUpdateError) {
|
|
191
|
+
onProcessRowUpdateError(error);
|
|
192
|
+
} else {
|
|
193
|
+
(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');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Handles batch row updates with partial failure tracking.
|
|
199
|
+
*
|
|
200
|
+
* This class is designed for operations that need to update multiple rows
|
|
201
|
+
* atomically (like moving entire groups), while gracefully handling cases
|
|
202
|
+
* where some updates succeed and others fail.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```tsx
|
|
206
|
+
* const updater = new BatchRowUpdater(apiRef, processRowUpdate, onError);
|
|
207
|
+
*
|
|
208
|
+
* // Queue multiple updates
|
|
209
|
+
* updater.queueUpdate('row1', originalRow1, newRow1);
|
|
210
|
+
* updater.queueUpdate('row2', originalRow2, newRow2);
|
|
211
|
+
*
|
|
212
|
+
* // Execute all updates
|
|
213
|
+
* const { successful, failed, updates } = await updater.executeAll();
|
|
214
|
+
*
|
|
215
|
+
* // Handle results
|
|
216
|
+
* if (successful.length > 0) {
|
|
217
|
+
* apiRef.current.updateRows(updates);
|
|
218
|
+
* }
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
class BatchRowUpdater {
|
|
222
|
+
rowsToUpdate = new Map();
|
|
223
|
+
originalRows = new Map();
|
|
224
|
+
successfulRowIds = new Set();
|
|
225
|
+
failedRowIds = new Set();
|
|
226
|
+
pendingRowUpdates = [];
|
|
227
|
+
constructor(apiRef, processRowUpdate, onProcessRowUpdateError) {
|
|
228
|
+
this.apiRef = apiRef;
|
|
229
|
+
this.processRowUpdate = processRowUpdate;
|
|
230
|
+
this.onProcessRowUpdateError = onProcessRowUpdateError;
|
|
231
|
+
}
|
|
232
|
+
queueUpdate(rowId, originalRow, updatedRow) {
|
|
233
|
+
this.originalRows.set(rowId, originalRow);
|
|
234
|
+
this.rowsToUpdate.set(rowId, updatedRow);
|
|
235
|
+
}
|
|
236
|
+
async executeAll() {
|
|
237
|
+
const rowIds = Array.from(this.rowsToUpdate.keys());
|
|
238
|
+
if (rowIds.length === 0) {
|
|
239
|
+
return {
|
|
240
|
+
successful: [],
|
|
241
|
+
failed: [],
|
|
242
|
+
updates: []
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Handle each row update, tracking success/failure
|
|
247
|
+
const handleRowUpdate = async rowId => {
|
|
248
|
+
const newRow = this.rowsToUpdate.get(rowId);
|
|
249
|
+
const oldRow = this.originalRows.get(rowId);
|
|
250
|
+
try {
|
|
251
|
+
if (typeof this.processRowUpdate === 'function') {
|
|
252
|
+
const params = {
|
|
253
|
+
rowId,
|
|
254
|
+
previousRow: oldRow,
|
|
255
|
+
updatedRow: newRow
|
|
256
|
+
};
|
|
257
|
+
const finalRow = await this.processRowUpdate(newRow, oldRow, params);
|
|
258
|
+
this.pendingRowUpdates.push(finalRow || newRow);
|
|
259
|
+
this.successfulRowIds.add(rowId);
|
|
260
|
+
} else {
|
|
261
|
+
this.pendingRowUpdates.push(newRow);
|
|
262
|
+
this.successfulRowIds.add(rowId);
|
|
263
|
+
}
|
|
264
|
+
} catch (error) {
|
|
265
|
+
this.failedRowIds.add(rowId);
|
|
266
|
+
handleProcessRowUpdateError(error, this.onProcessRowUpdateError);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
// Use Promise.all with wrapped promises to avoid Promise.allSettled (browser support)
|
|
271
|
+
const promises = rowIds.map(rowId => {
|
|
272
|
+
return new Promise(resolve => {
|
|
273
|
+
handleRowUpdate(rowId).then(resolve).catch(resolve);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
this.apiRef.current.setLoading(true);
|
|
277
|
+
await Promise.all(promises);
|
|
278
|
+
this.apiRef.current.setLoading(false);
|
|
279
|
+
return {
|
|
280
|
+
successful: Array.from(this.successfulRowIds),
|
|
281
|
+
failed: Array.from(this.failedRowIds),
|
|
282
|
+
updates: this.pendingRowUpdates
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
exports.BatchRowUpdater = BatchRowUpdater;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RefObject } from '@mui/x-internals/types';
|
|
2
|
+
import type { GridPrivateApiPro } from "../../../models/gridApiPro.js";
|
|
3
|
+
import type { DataGridProProcessedProps } from "../../../models/dataGridProProps.js";
|
|
4
|
+
export declare const useGridRowsOverridableMethods: (apiRef: RefObject<GridPrivateApiPro>, props: Pick<DataGridProProcessedProps, "processRowUpdate" | "onProcessRowUpdateError" | "setTreeDataPath">) => {
|
|
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
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useGridRowsOverridableMethods = void 0;
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _xDataGrid = require("@mui/x-data-grid");
|
|
10
|
+
var _internals = require("@mui/x-data-grid/internals");
|
|
11
|
+
var _treeDataReorderExecutor = require("../treeData/treeDataReorderExecutor");
|
|
12
|
+
const useGridRowsOverridableMethods = (apiRef, props) => {
|
|
13
|
+
const {
|
|
14
|
+
processRowUpdate,
|
|
15
|
+
onProcessRowUpdateError,
|
|
16
|
+
setTreeDataPath
|
|
17
|
+
} = props;
|
|
18
|
+
const {
|
|
19
|
+
setRowIndex: setRowIndexFlat,
|
|
20
|
+
setRowPosition: setRowPositionFlat
|
|
21
|
+
} = (0, _internals.useGridRowsOverridableMethodsCommunity)(apiRef);
|
|
22
|
+
const flatTree = (0, _xDataGrid.useGridSelector)(apiRef, _xDataGrid.gridRowMaximumTreeDepthSelector) === 1;
|
|
23
|
+
const setRowPosition = React.useCallback(async (sourceRowId, targetRowId, position) => {
|
|
24
|
+
const sortedFilteredRowIds = (0, _xDataGrid.gridExpandedSortedRowIdsSelector)(apiRef);
|
|
25
|
+
const sortedFilteredRowIndexLookup = (0, _xDataGrid.gridExpandedSortedRowIndexLookupSelector)(apiRef);
|
|
26
|
+
const rowTree = (0, _xDataGrid.gridRowTreeSelector)(apiRef);
|
|
27
|
+
const sourceNode = (0, _xDataGrid.gridRowNodeSelector)(apiRef, sourceRowId);
|
|
28
|
+
const targetNode = (0, _xDataGrid.gridRowNodeSelector)(apiRef, targetRowId);
|
|
29
|
+
if (!sourceNode) {
|
|
30
|
+
throw new Error(`MUI X: No row with id #${sourceRowId} found.`);
|
|
31
|
+
}
|
|
32
|
+
if (!targetNode) {
|
|
33
|
+
throw new Error(`MUI X: No row with id #${targetRowId} found.`);
|
|
34
|
+
}
|
|
35
|
+
if (sourceNode.type === 'footer') {
|
|
36
|
+
throw new Error(`MUI X: The row reordering do not support reordering of footer rows.`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Get the target index from the targetRowId using the lookup selector
|
|
40
|
+
const targetIndexUnadjusted = sortedFilteredRowIndexLookup[targetRowId];
|
|
41
|
+
if (targetIndexUnadjusted === undefined) {
|
|
42
|
+
throw new Error(`MUI X: Target row with id #${targetRowId} not found in current view.`);
|
|
43
|
+
}
|
|
44
|
+
const targetIndex = position === 'below' ? targetIndexUnadjusted + 1 : targetIndexUnadjusted;
|
|
45
|
+
const executionContext = {
|
|
46
|
+
sourceRowId,
|
|
47
|
+
dropPosition: position,
|
|
48
|
+
placeholderIndex: targetIndex,
|
|
49
|
+
sortedFilteredRowIds,
|
|
50
|
+
sortedFilteredRowIndexLookup,
|
|
51
|
+
rowTree,
|
|
52
|
+
apiRef,
|
|
53
|
+
processRowUpdate,
|
|
54
|
+
onProcessRowUpdateError,
|
|
55
|
+
setTreeDataPath
|
|
56
|
+
};
|
|
57
|
+
return _treeDataReorderExecutor.treeDataReorderExecutor.execute(executionContext);
|
|
58
|
+
}, [apiRef, processRowUpdate, onProcessRowUpdateError, setTreeDataPath]);
|
|
59
|
+
const setRowIndex = React.useCallback(async () => {
|
|
60
|
+
throw new Error(`MUI X: \`setRowIndex()\` is not supported for tree data. Use \`setRowPosition()\` instead.`);
|
|
61
|
+
}, []);
|
|
62
|
+
return {
|
|
63
|
+
setRowIndex: flatTree ? setRowIndexFlat : setRowIndex,
|
|
64
|
+
setRowPosition: flatTree ? setRowPositionFlat : setRowPosition
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
exports.useGridRowsOverridableMethods = useGridRowsOverridableMethods;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseReorderOperation, RowReorderExecutor } from "../rowReorder/reorderExecutor.js";
|
|
2
|
+
import { type ReorderOperation, type ReorderExecutionContext } from "../rowReorder/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Handles reordering of items within the same parent group.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SameParentSwapOperation extends BaseReorderOperation {
|
|
7
|
+
readonly operationType = "same-parent-swap";
|
|
8
|
+
detectOperation(ctx: ReorderExecutionContext): ReorderOperation | null;
|
|
9
|
+
executeOperation(operation: ReorderOperation, ctx: ReorderExecutionContext): void;
|
|
10
|
+
}
|
|
11
|
+
export declare const treeDataReorderExecutor: RowReorderExecutor;
|