@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
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
import { GRID_ROOT_GROUP_ID, gridRowNodeSelector } from '@mui/x-data-grid-pro';
|
|
2
|
-
import { warnOnce } from '@mui/x-internals/warning';
|
|
3
|
-
// TODO: Share these conditions with the executor by making the contexts similar
|
|
4
|
-
/**
|
|
5
|
-
* Reusable validation conditions for row reordering validation
|
|
6
|
-
*/
|
|
7
|
-
export const conditions = {
|
|
8
|
-
// Node type checks
|
|
9
|
-
isGroupToGroup: ctx => ctx.sourceNode.type === 'group' && ctx.targetNode.type === 'group',
|
|
10
|
-
isLeafToLeaf: ctx => ctx.sourceNode.type === 'leaf' && ctx.targetNode.type === 'leaf',
|
|
11
|
-
isLeafToGroup: ctx => ctx.sourceNode.type === 'leaf' && ctx.targetNode.type === 'group',
|
|
12
|
-
isGroupToLeaf: ctx => ctx.sourceNode.type === 'group' && ctx.targetNode.type === 'leaf',
|
|
13
|
-
// Drop position checks
|
|
14
|
-
isDropAbove: ctx => ctx.dropPosition === 'above',
|
|
15
|
-
isDropBelow: ctx => ctx.dropPosition === 'below',
|
|
16
|
-
// Depth checks
|
|
17
|
-
sameDepth: ctx => ctx.sourceNode.depth === ctx.targetNode.depth,
|
|
18
|
-
sourceDepthGreater: ctx => ctx.sourceNode.depth > ctx.targetNode.depth,
|
|
19
|
-
targetDepthIsSourceMinusOne: ctx => ctx.targetNode.depth === ctx.sourceNode.depth - 1,
|
|
20
|
-
// Parent checks
|
|
21
|
-
sameParent: ctx => ctx.sourceNode.parent === ctx.targetNode.parent,
|
|
22
|
-
// Node state checks
|
|
23
|
-
targetGroupExpanded: ctx => (ctx.targetNode.type === 'group' && ctx.targetNode.childrenExpanded) ?? false,
|
|
24
|
-
targetGroupCollapsed: ctx => ctx.targetNode.type === 'group' && !ctx.targetNode.childrenExpanded,
|
|
25
|
-
// Previous/Next node checks
|
|
26
|
-
hasPrevNode: ctx => ctx.prevNode !== null,
|
|
27
|
-
hasNextNode: ctx => ctx.nextNode !== null,
|
|
28
|
-
prevIsLeaf: ctx => ctx.prevNode?.type === 'leaf',
|
|
29
|
-
prevIsGroup: ctx => ctx.prevNode?.type === 'group',
|
|
30
|
-
nextIsLeaf: ctx => ctx.nextNode?.type === 'leaf',
|
|
31
|
-
nextIsGroup: ctx => ctx.nextNode?.type === 'group',
|
|
32
|
-
prevDepthEquals: (ctx, depth) => ctx.prevNode?.depth === depth,
|
|
33
|
-
prevDepthEqualsSource: ctx => ctx.prevNode?.depth === ctx.sourceNode.depth,
|
|
34
|
-
// Complex checks
|
|
35
|
-
prevBelongsToSource: ctx => {
|
|
36
|
-
if (!ctx.prevNode) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
// Check if prevNode.parent OR any of its ancestors === sourceNode.id
|
|
40
|
-
let currentId = ctx.prevNode.parent;
|
|
41
|
-
while (currentId) {
|
|
42
|
-
if (currentId === ctx.sourceNode.id) {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
const node = ctx.rowTree[currentId];
|
|
46
|
-
if (!node) {
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
currentId = node.parent;
|
|
50
|
-
}
|
|
51
|
-
return false;
|
|
52
|
-
},
|
|
53
|
-
// Position checks
|
|
54
|
-
isAdjacentPosition: ctx => {
|
|
55
|
-
const {
|
|
56
|
-
sourceRowIndex,
|
|
57
|
-
targetRowIndex,
|
|
58
|
-
dropPosition
|
|
59
|
-
} = ctx;
|
|
60
|
-
return dropPosition === 'above' && targetRowIndex === sourceRowIndex + 1 || dropPosition === 'below' && targetRowIndex === sourceRowIndex - 1;
|
|
61
|
-
},
|
|
62
|
-
// First child check
|
|
63
|
-
targetFirstChildIsGroupWithSourceDepth: ctx => {
|
|
64
|
-
if (ctx.targetNode.type !== 'group') {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
const targetGroup = ctx.targetNode;
|
|
68
|
-
const firstChild = targetGroup.children?.[0] ? ctx.rowTree[targetGroup.children[0]] : null;
|
|
69
|
-
return firstChild?.type === 'group' && firstChild.depth === ctx.sourceNode.depth;
|
|
70
|
-
},
|
|
71
|
-
targetFirstChildDepthEqualsSource: ctx => {
|
|
72
|
-
if (ctx.targetNode.type !== 'group') {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
const targetGroup = ctx.targetNode;
|
|
76
|
-
const firstChild = targetGroup.children?.[0] ? ctx.rowTree[targetGroup.children[0]] : null;
|
|
77
|
-
return firstChild ? firstChild.depth === ctx.sourceNode.depth : false;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
export function determineOperationType(sourceNode, targetNode) {
|
|
81
|
-
if (sourceNode.parent === targetNode.parent) {
|
|
82
|
-
return 'same-parent-swap';
|
|
83
|
-
}
|
|
84
|
-
if (sourceNode.type === 'leaf') {
|
|
85
|
-
return 'cross-parent-leaf';
|
|
86
|
-
}
|
|
87
|
-
return 'cross-parent-group';
|
|
88
|
-
}
|
|
89
|
-
export function calculateTargetIndex(sourceNode, targetNode, isLastChild, rowTree) {
|
|
90
|
-
if (sourceNode.parent === targetNode.parent && !isLastChild) {
|
|
91
|
-
// Same parent: find target's position in parent's children
|
|
92
|
-
const parent = rowTree[sourceNode.parent];
|
|
93
|
-
return parent.children.findIndex(id => id === targetNode.id);
|
|
94
|
-
}
|
|
95
|
-
if (isLastChild) {
|
|
96
|
-
// Append at the end
|
|
97
|
-
const targetParent = rowTree[targetNode.parent];
|
|
98
|
-
return targetParent.children.length;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Find position in target parent
|
|
102
|
-
const targetParent = rowTree[targetNode.parent];
|
|
103
|
-
const targetIndex = targetParent.children.findIndex(id => id === targetNode.id);
|
|
104
|
-
return targetIndex >= 0 ? targetIndex : 0;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Get the path from a node to the root in the tree
|
|
108
|
-
export const getNodePathInTree = ({
|
|
109
|
-
id,
|
|
110
|
-
tree
|
|
111
|
-
}) => {
|
|
112
|
-
const path = [];
|
|
113
|
-
let node = tree[id];
|
|
114
|
-
while (node.id !== GRID_ROOT_GROUP_ID) {
|
|
115
|
-
path.push({
|
|
116
|
-
field: node.type === 'leaf' ? null : node.groupingField,
|
|
117
|
-
key: node.groupingKey
|
|
118
|
-
});
|
|
119
|
-
node = tree[node.parent];
|
|
120
|
-
}
|
|
121
|
-
path.reverse();
|
|
122
|
-
return path;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// Recursively collect all leaf node IDs from a group
|
|
126
|
-
export const collectAllLeafDescendants = (groupNode, tree) => {
|
|
127
|
-
const leafIds = [];
|
|
128
|
-
const collectFromNode = nodeId => {
|
|
129
|
-
const node = tree[nodeId];
|
|
130
|
-
if (node.type === 'leaf') {
|
|
131
|
-
leafIds.push(nodeId);
|
|
132
|
-
} else if (node.type === 'group') {
|
|
133
|
-
node.children.forEach(collectFromNode);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
groupNode.children.forEach(collectFromNode);
|
|
137
|
-
return leafIds;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Adjusts the target node based on specific reorder scenarios and constraints.
|
|
142
|
-
*
|
|
143
|
-
* This function applies scenario-specific logic to find the actual target node
|
|
144
|
-
* for operations, handling cases like:
|
|
145
|
-
* - Moving to collapsed groups
|
|
146
|
-
* - Depth-based adjustments
|
|
147
|
-
* - End-of-list positioning
|
|
148
|
-
*
|
|
149
|
-
* @param sourceNode The node being moved
|
|
150
|
-
* @param targetNode The initial target node
|
|
151
|
-
* @param targetIndex The index of the target node in the visible rows
|
|
152
|
-
* @param placeholderIndex The index where the placeholder appears
|
|
153
|
-
* @param sortedFilteredRowIds Array of visible row IDs in display order
|
|
154
|
-
* @param apiRef Reference to the grid API
|
|
155
|
-
* @returns Object containing the adjusted target node and last child flag
|
|
156
|
-
*/
|
|
157
|
-
export function adjustTargetNode(sourceNode, targetNode, targetIndex, placeholderIndex, sortedFilteredRowIds, apiRef) {
|
|
158
|
-
let adjustedTargetNode = targetNode;
|
|
159
|
-
let isLastChild = false;
|
|
160
|
-
|
|
161
|
-
// Handle end-of-list case
|
|
162
|
-
if (placeholderIndex >= sortedFilteredRowIds.length && sortedFilteredRowIds.length > 0) {
|
|
163
|
-
isLastChild = true;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Case A and B adjustment: Move to last child of parent where target should be the node above
|
|
167
|
-
if (targetNode.type === 'group' && sourceNode.parent !== targetNode.parent && sourceNode.depth > targetNode.depth) {
|
|
168
|
-
// Find the first node with the same depth as source before target and quit early if a
|
|
169
|
-
// node with depth < source.depth is found
|
|
170
|
-
let i = targetIndex - 1;
|
|
171
|
-
while (i >= 0) {
|
|
172
|
-
const node = apiRef.current.getRowNode(sortedFilteredRowIds[i]);
|
|
173
|
-
if (node && node.depth < sourceNode.depth) {
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
if (node && node.depth === sourceNode.depth) {
|
|
177
|
-
adjustedTargetNode = node;
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
i -= 1;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Case D adjustment: Leaf to group where we need previous leaf
|
|
185
|
-
if (sourceNode.type === 'leaf' && targetNode.type === 'group' && targetNode.depth < sourceNode.depth) {
|
|
186
|
-
isLastChild = true;
|
|
187
|
-
const prevIndex = placeholderIndex - 1;
|
|
188
|
-
if (prevIndex >= 0) {
|
|
189
|
-
const prevRowId = sortedFilteredRowIds[prevIndex];
|
|
190
|
-
const leafTargetNode = gridRowNodeSelector(apiRef, prevRowId);
|
|
191
|
-
if (leafTargetNode && leafTargetNode.type === 'leaf') {
|
|
192
|
-
adjustedTargetNode = leafTargetNode;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return {
|
|
197
|
-
adjustedTargetNode,
|
|
198
|
-
isLastChild
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Finds an existing group node with the same groupingKey and groupingField under a parent.
|
|
204
|
-
*
|
|
205
|
-
* @param parentNode - The parent group node to search in
|
|
206
|
-
* @param groupingKey - The grouping key to match
|
|
207
|
-
* @param groupingField - The grouping field to match
|
|
208
|
-
* @param tree - The row tree configuration
|
|
209
|
-
* @returns The existing group node if found, null otherwise
|
|
210
|
-
*/
|
|
211
|
-
export function findExistingGroupWithSameKey(parentNode, groupingKey, groupingField, tree) {
|
|
212
|
-
for (const childId of parentNode.children) {
|
|
213
|
-
const childNode = tree[childId];
|
|
214
|
-
if (childNode && childNode.type === 'group' && childNode.groupingKey === groupingKey && childNode.groupingField === groupingField) {
|
|
215
|
-
return childNode;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return null;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Removes empty ancestor groups from the tree after a row move operation.
|
|
223
|
-
* Walks up the tree from the given group, removing any empty groups encountered.
|
|
224
|
-
*
|
|
225
|
-
* @param groupId - The ID of the group to start checking from
|
|
226
|
-
* @param tree - The row tree configuration
|
|
227
|
-
* @param removedGroups - Set to track which groups have been removed
|
|
228
|
-
* @returns The number of root-level groups that were removed
|
|
229
|
-
*/
|
|
230
|
-
export function removeEmptyAncestors(groupId, tree, removedGroups) {
|
|
231
|
-
let rootLevelRemovals = 0;
|
|
232
|
-
let currentGroupId = groupId;
|
|
233
|
-
while (currentGroupId && currentGroupId !== GRID_ROOT_GROUP_ID) {
|
|
234
|
-
const group = tree[currentGroupId];
|
|
235
|
-
if (!group) {
|
|
236
|
-
break;
|
|
237
|
-
}
|
|
238
|
-
const remainingChildren = group.children.filter(childId => !removedGroups.has(childId));
|
|
239
|
-
if (remainingChildren.length > 0) {
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
if (group.depth === 0) {
|
|
243
|
-
rootLevelRemovals += 1;
|
|
244
|
-
}
|
|
245
|
-
removedGroups.add(currentGroupId);
|
|
246
|
-
currentGroupId = group.parent;
|
|
247
|
-
}
|
|
248
|
-
return rootLevelRemovals;
|
|
249
|
-
}
|
|
250
|
-
export function handleProcessRowUpdateError(error, onProcessRowUpdateError) {
|
|
251
|
-
if (onProcessRowUpdateError) {
|
|
252
|
-
onProcessRowUpdateError(error);
|
|
253
|
-
} else if (process.env.NODE_ENV !== 'production') {
|
|
254
|
-
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');
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Handles batch row updates with partial failure tracking.
|
|
260
|
-
*
|
|
261
|
-
* This class is designed for operations that need to update multiple rows
|
|
262
|
-
* atomically (like moving entire groups), while gracefully handling cases
|
|
263
|
-
* where some updates succeed and others fail.
|
|
264
|
-
*
|
|
265
|
-
* @example
|
|
266
|
-
* ```tsx
|
|
267
|
-
* const updater = new BatchRowUpdater(processRowUpdate, onError);
|
|
268
|
-
*
|
|
269
|
-
* // Queue multiple updates
|
|
270
|
-
* updater.queueUpdate('row1', originalRow1, newRow1);
|
|
271
|
-
* updater.queueUpdate('row2', originalRow2, newRow2);
|
|
272
|
-
*
|
|
273
|
-
* // Execute all updates
|
|
274
|
-
* const { successful, failed, updates } = await updater.executeAll();
|
|
275
|
-
*
|
|
276
|
-
* // Handle results
|
|
277
|
-
* if (successful.length > 0) {
|
|
278
|
-
* apiRef.current.updateRows(updates);
|
|
279
|
-
* }
|
|
280
|
-
* ```
|
|
281
|
-
*/
|
|
282
|
-
export class BatchRowUpdater {
|
|
283
|
-
rowsToUpdate = (() => new Map())();
|
|
284
|
-
originalRows = (() => new Map())();
|
|
285
|
-
successfulRowIds = (() => new Set())();
|
|
286
|
-
failedRowIds = (() => new Set())();
|
|
287
|
-
pendingRowUpdates = [];
|
|
288
|
-
constructor(processRowUpdate, onProcessRowUpdateError) {
|
|
289
|
-
this.processRowUpdate = processRowUpdate;
|
|
290
|
-
this.onProcessRowUpdateError = onProcessRowUpdateError;
|
|
291
|
-
}
|
|
292
|
-
queueUpdate(rowId, originalRow, updatedRow) {
|
|
293
|
-
this.originalRows.set(rowId, originalRow);
|
|
294
|
-
this.rowsToUpdate.set(rowId, updatedRow);
|
|
295
|
-
}
|
|
296
|
-
async executeAll() {
|
|
297
|
-
const rowIds = Array.from(this.rowsToUpdate.keys());
|
|
298
|
-
if (rowIds.length === 0) {
|
|
299
|
-
return {
|
|
300
|
-
successful: [],
|
|
301
|
-
failed: [],
|
|
302
|
-
updates: []
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
// Handle each row update, tracking success/failure
|
|
307
|
-
const handleRowUpdate = async rowId => {
|
|
308
|
-
const newRow = this.rowsToUpdate.get(rowId);
|
|
309
|
-
const oldRow = this.originalRows.get(rowId);
|
|
310
|
-
try {
|
|
311
|
-
if (typeof this.processRowUpdate === 'function') {
|
|
312
|
-
const params = {
|
|
313
|
-
rowId,
|
|
314
|
-
previousRow: oldRow,
|
|
315
|
-
updatedRow: newRow
|
|
316
|
-
};
|
|
317
|
-
const finalRow = await this.processRowUpdate(newRow, oldRow, params);
|
|
318
|
-
this.pendingRowUpdates.push(finalRow || newRow);
|
|
319
|
-
this.successfulRowIds.add(rowId);
|
|
320
|
-
} else {
|
|
321
|
-
this.pendingRowUpdates.push(newRow);
|
|
322
|
-
this.successfulRowIds.add(rowId);
|
|
323
|
-
}
|
|
324
|
-
} catch (error) {
|
|
325
|
-
this.failedRowIds.add(rowId);
|
|
326
|
-
handleProcessRowUpdateError(error, this.onProcessRowUpdateError);
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
// Use Promise.all with wrapped promises to avoid Promise.allSettled (browser support)
|
|
331
|
-
const promises = rowIds.map(rowId => {
|
|
332
|
-
return new Promise(resolve => {
|
|
333
|
-
handleRowUpdate(rowId).then(resolve).catch(resolve);
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
await Promise.all(promises);
|
|
337
|
-
return {
|
|
338
|
-
successful: Array.from(this.successfulRowIds),
|
|
339
|
-
failed: Array.from(this.failedRowIds),
|
|
340
|
-
updates: this.pendingRowUpdates
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
}
|
|
@@ -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,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.rowGroupingReorderExecutor = void 0;
|
|
7
|
-
var _warning = require("@mui/x-internals/warning");
|
|
8
|
-
var _operations = require("./operations");
|
|
9
|
-
/**
|
|
10
|
-
* Executor class for handling row reorder operations in grouped data grids.
|
|
11
|
-
*
|
|
12
|
-
* This class coordinates the execution of different reorder operation types,
|
|
13
|
-
* trying each operation in order until one succeeds or all fail.
|
|
14
|
-
*/
|
|
15
|
-
class RowReorderExecutor {
|
|
16
|
-
constructor(operations) {
|
|
17
|
-
this.operations = operations;
|
|
18
|
-
}
|
|
19
|
-
async execute(ctx) {
|
|
20
|
-
for (const operation of this.operations) {
|
|
21
|
-
const detectedOperation = operation.detectOperation(ctx);
|
|
22
|
-
if (detectedOperation) {
|
|
23
|
-
// eslint-disable-next-line no-await-in-loop
|
|
24
|
-
await operation.executeOperation(detectedOperation, ctx);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
(0, _warning.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');
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const rowGroupingReorderExecutor = exports.rowGroupingReorderExecutor = new RowReorderExecutor([new _operations.SameParentSwapOperation(), new _operations.CrossParentLeafOperation(), new _operations.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,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.rowGroupingReorderValidator = void 0;
|
|
7
|
-
var _utils = require("./utils");
|
|
8
|
-
const validationRules = [
|
|
9
|
-
// ===== Basic invalid cases =====
|
|
10
|
-
{
|
|
11
|
-
name: 'same-position',
|
|
12
|
-
applies: ctx => ctx.sourceRowIndex === ctx.targetRowIndex,
|
|
13
|
-
isInvalid: () => true,
|
|
14
|
-
message: 'Source and target are the same'
|
|
15
|
-
}, {
|
|
16
|
-
name: 'adjacent-position',
|
|
17
|
-
applies: ctx => _utils.conditions.isAdjacentPosition(ctx),
|
|
18
|
-
isInvalid: () => true,
|
|
19
|
-
message: 'Source and target are adjacent'
|
|
20
|
-
}, {
|
|
21
|
-
name: 'group-to-leaf',
|
|
22
|
-
applies: _utils.conditions.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 => _utils.conditions.isGroupToGroup(ctx) && _utils.conditions.isDropAbove(ctx) && _utils.conditions.prevIsLeaf(ctx),
|
|
30
|
-
isInvalid: _utils.conditions.prevBelongsToSource,
|
|
31
|
-
message: 'Previous leaf belongs to source group or its descendants'
|
|
32
|
-
}, {
|
|
33
|
-
name: 'group-to-group-above-invalid-depth',
|
|
34
|
-
applies: ctx => _utils.conditions.isGroupToGroup(ctx) && _utils.conditions.isDropAbove(ctx) && !_utils.conditions.sameDepth(ctx) && !(ctx.targetNode.depth < ctx.sourceNode.depth && (_utils.conditions.prevIsLeaf(ctx) || _utils.conditions.prevIsGroup(ctx) && _utils.conditions.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 => _utils.conditions.isGroupToGroup(ctx) && _utils.conditions.isDropAbove(ctx) && _utils.conditions.prevIsGroup(ctx) && _utils.conditions.prevDepthEqualsSource(ctx) && _utils.conditions.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 => _utils.conditions.isGroupToGroup(ctx) && _utils.conditions.isDropBelow(ctx),
|
|
45
|
-
isInvalid: ctx => {
|
|
46
|
-
// Valid case 1: Same depth and target not expanded
|
|
47
|
-
if (_utils.conditions.sameDepth(ctx) && _utils.conditions.targetGroupCollapsed(ctx)) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
// Valid case 2: Target is parent level, expanded, with compatible first child
|
|
51
|
-
if (_utils.conditions.targetDepthIsSourceMinusOne(ctx) && _utils.conditions.targetGroupExpanded(ctx) && _utils.conditions.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 => _utils.conditions.isLeafToLeaf(ctx) && !_utils.conditions.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 => _utils.conditions.isLeafToLeaf(ctx) && _utils.conditions.sameDepth(ctx) && !_utils.conditions.sameParent(ctx) && _utils.conditions.isDropBelow(ctx),
|
|
67
|
-
isInvalid: ctx => !(_utils.conditions.nextIsGroup(ctx) && ctx.sourceNode.depth > ctx.nextNode.depth) && !_utils.conditions.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 => _utils.conditions.isLeafToGroup(ctx) && _utils.conditions.isDropAbove(ctx),
|
|
74
|
-
isInvalid: ctx => !_utils.conditions.hasPrevNode(ctx) || !_utils.conditions.prevIsLeaf(ctx),
|
|
75
|
-
message: 'No valid previous leaf for leaf above group'
|
|
76
|
-
}, {
|
|
77
|
-
name: 'leaf-to-group-above-depth-mismatch',
|
|
78
|
-
applies: ctx => _utils.conditions.isLeafToGroup(ctx) && _utils.conditions.isDropAbove(ctx) && _utils.conditions.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 => _utils.conditions.isLeafToGroup(ctx) && _utils.conditions.isDropBelow(ctx),
|
|
84
|
-
isInvalid: _utils.conditions.targetGroupCollapsed,
|
|
85
|
-
message: 'Cannot drop below collapsed group'
|
|
86
|
-
}, {
|
|
87
|
-
name: 'leaf-to-group-below-invalid-depth',
|
|
88
|
-
applies: ctx => _utils.conditions.isLeafToGroup(ctx) && _utils.conditions.isDropBelow(ctx) && _utils.conditions.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 (_utils.conditions.targetFirstChildDepthEqualsSource(ctx)) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
return true;
|
|
99
|
-
},
|
|
100
|
-
message: 'Invalid depth configuration for leaf below group'
|
|
101
|
-
}];
|
|
102
|
-
class RowReorderValidator {
|
|
103
|
-
constructor(rules = validationRules) {
|
|
104
|
-
this.rules = rules;
|
|
105
|
-
}
|
|
106
|
-
addRule(rule) {
|
|
107
|
-
this.rules.push(rule);
|
|
108
|
-
}
|
|
109
|
-
removeRule(ruleName) {
|
|
110
|
-
this.rules = this.rules.filter(r => r.name !== ruleName);
|
|
111
|
-
}
|
|
112
|
-
validate(context) {
|
|
113
|
-
// Check all validation rules
|
|
114
|
-
for (const rule of this.rules) {
|
|
115
|
-
if (rule.applies(context) && rule.isInvalid(context)) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
const rowGroupingReorderValidator = exports.rowGroupingReorderValidator = new RowReorderValidator(validationRules);
|
|
@@ -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';
|