@mui/x-data-grid-pro 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.
- package/CHANGELOG.md +175 -0
- package/DataGridPro/DataGridPro.js +42 -8
- package/DataGridPro/useDataGridProComponent.js +3 -2
- package/components/GridDetailPanelToggleCell.js +0 -10
- package/components/GridRowReorderCell.js +15 -13
- package/components/GridTreeDataGroupingCell.js +0 -10
- package/components/headerFiltering/GridHeaderFilterCell.js +2 -3
- package/esm/DataGridPro/DataGridPro.js +42 -8
- package/esm/DataGridPro/useDataGridProComponent.js +4 -3
- package/esm/components/GridDetailPanelToggleCell.js +0 -10
- package/esm/components/GridRowReorderCell.js +15 -13
- package/esm/components/GridTreeDataGroupingCell.js +0 -10
- package/esm/components/headerFiltering/GridHeaderFilterCell.js +2 -3
- package/esm/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +4 -0
- package/esm/hooks/features/dataSource/useGridDataSourceBasePro.js +1 -1
- package/esm/hooks/features/detailPanel/useGridDetailPanel.js +6 -5
- package/esm/hooks/features/infiniteLoader/useGridInfiniteLoader.js +4 -4
- 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 +171 -82
- 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/serverSideLazyLoader/useGridInfiniteLoadingIntersection.js +3 -3
- 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/columnPinning/useGridColumnPinningPreProcessors.js +4 -0
- package/hooks/features/dataSource/useGridDataSourceBasePro.js +1 -1
- package/hooks/features/detailPanel/useGridDetailPanel.js +5 -4
- package/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
- 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 +169 -80
- 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/serverSideLazyLoader/useGridInfiniteLoadingIntersection.js +3 -3
- 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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import {
|
|
5
|
+
import { useGridEvent, useGridApiMethod, gridDataRowIdsSelector } from '@mui/x-data-grid';
|
|
6
6
|
import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
|
|
7
7
|
import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from "./gridDetailPanelToggleColDef.js";
|
|
8
8
|
import { gridDetailPanelExpandedRowIdsSelector, gridDetailPanelExpandedRowsContentCacheSelector, gridDetailPanelRawHeightCacheSelector } from "./gridDetailPanelSelector.js";
|
|
@@ -46,11 +46,11 @@ function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeig
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
export const useGridDetailPanel = (apiRef, props) => {
|
|
49
|
-
const contentCache = useGridSelector(apiRef, gridDetailPanelExpandedRowsContentCacheSelector);
|
|
50
49
|
const handleCellClick = React.useCallback((params, event) => {
|
|
51
50
|
if (params.field !== GRID_DETAIL_PANEL_TOGGLE_FIELD || props.getDetailPanelContent == null) {
|
|
52
51
|
return;
|
|
53
52
|
}
|
|
53
|
+
const contentCache = gridDetailPanelExpandedRowsContentCacheSelector(apiRef);
|
|
54
54
|
const content = contentCache[params.id];
|
|
55
55
|
if (! /*#__PURE__*/React.isValidElement(content)) {
|
|
56
56
|
return;
|
|
@@ -61,7 +61,7 @@ export const useGridDetailPanel = (apiRef, props) => {
|
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
apiRef.current.toggleDetailPanel(params.id);
|
|
64
|
-
}, [apiRef,
|
|
64
|
+
}, [apiRef, props.getDetailPanelContent]);
|
|
65
65
|
const handleCellKeyDown = React.useCallback((params, event) => {
|
|
66
66
|
if (props.getDetailPanelContent == null) {
|
|
67
67
|
return;
|
|
@@ -83,6 +83,7 @@ export const useGridDetailPanel = (apiRef, props) => {
|
|
|
83
83
|
if (props.getDetailPanelContent == null) {
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
|
+
const contentCache = gridDetailPanelExpandedRowsContentCacheSelector(apiRef);
|
|
86
87
|
const content = contentCache[id];
|
|
87
88
|
if (! /*#__PURE__*/React.isValidElement(content)) {
|
|
88
89
|
return;
|
|
@@ -95,7 +96,7 @@ export const useGridDetailPanel = (apiRef, props) => {
|
|
|
95
96
|
newIds.add(id);
|
|
96
97
|
}
|
|
97
98
|
apiRef.current.setExpandedDetailPanels(newIds);
|
|
98
|
-
}, [apiRef,
|
|
99
|
+
}, [apiRef, props.getDetailPanelContent]);
|
|
99
100
|
const getExpandedDetailPanels = React.useCallback(() => gridDetailPanelExpandedRowIdsSelector(apiRef), [apiRef]);
|
|
100
101
|
const setExpandedDetailPanels = React.useCallback(ids => {
|
|
101
102
|
apiRef.current.setState(state => {
|
|
@@ -157,7 +158,7 @@ export const useGridDetailPanel = (apiRef, props) => {
|
|
|
157
158
|
const previousGetDetailPanelContentProp = React.useRef(undefined);
|
|
158
159
|
const previousGetDetailPanelHeightProp = React.useRef(undefined);
|
|
159
160
|
const updateCachesIfNeeded = React.useCallback(() => {
|
|
160
|
-
if (props.getDetailPanelContent === previousGetDetailPanelContentProp.current && props.getDetailPanelHeight === previousGetDetailPanelHeightProp.current) {
|
|
161
|
+
if (props.getDetailPanelContent === previousGetDetailPanelContentProp.current && props.getDetailPanelHeight === previousGetDetailPanelHeightProp.current || !props.getDetailPanelContent) {
|
|
161
162
|
return;
|
|
162
163
|
}
|
|
163
164
|
apiRef.current.setState(state => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useGridEventPriority, gridVisibleColumnDefinitionsSelector, useGridEvent } from '@mui/x-data-grid';
|
|
2
|
+
import { runIf, getVisibleRows } from '@mui/x-data-grid/internals';
|
|
3
3
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
4
4
|
/**
|
|
5
5
|
* @requires useGridColumns (state)
|
|
@@ -7,10 +7,10 @@ import useEventCallback from '@mui/utils/useEventCallback';
|
|
|
7
7
|
* @requires useGridScroll (method
|
|
8
8
|
*/
|
|
9
9
|
export const useGridInfiniteLoader = (apiRef, props) => {
|
|
10
|
-
const visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
|
|
11
|
-
const currentPage = useGridVisibleRows(apiRef, props);
|
|
12
10
|
const isEnabled = props.rowsLoadingMode === 'client' && !!props.onRowsScrollEnd;
|
|
13
11
|
const handleLoadMoreRows = useEventCallback(() => {
|
|
12
|
+
const visibleColumns = gridVisibleColumnDefinitionsSelector(apiRef);
|
|
13
|
+
const currentPage = getVisibleRows(apiRef);
|
|
14
14
|
const viewportPageSize = apiRef.current.getViewportPageSize();
|
|
15
15
|
const rowScrollEndParams = {
|
|
16
16
|
visibleColumns,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ReorderValidationContext as Ctx } from "./models.js";
|
|
2
|
+
/**
|
|
3
|
+
* Reusable validation conditions for row reordering validation
|
|
4
|
+
*/
|
|
5
|
+
export declare const commonReorderConditions: {
|
|
6
|
+
isGroupToGroup: (ctx: Ctx) => boolean;
|
|
7
|
+
isLeafToLeaf: (ctx: Ctx) => boolean;
|
|
8
|
+
isLeafToGroup: (ctx: Ctx) => boolean;
|
|
9
|
+
isGroupToLeaf: (ctx: Ctx) => boolean;
|
|
10
|
+
isDropAbove: (ctx: Ctx) => boolean;
|
|
11
|
+
isDropBelow: (ctx: Ctx) => boolean;
|
|
12
|
+
sameDepth: (ctx: Ctx) => boolean;
|
|
13
|
+
sourceDepthGreater: (ctx: Ctx) => boolean;
|
|
14
|
+
targetDepthIsSourceMinusOne: (ctx: Ctx) => boolean;
|
|
15
|
+
sameParent: (ctx: Ctx) => boolean;
|
|
16
|
+
targetGroupExpanded: (ctx: Ctx) => boolean;
|
|
17
|
+
targetGroupCollapsed: (ctx: Ctx) => boolean;
|
|
18
|
+
hasPrevNode: (ctx: Ctx) => boolean;
|
|
19
|
+
hasNextNode: (ctx: Ctx) => boolean;
|
|
20
|
+
prevIsLeaf: (ctx: Ctx) => boolean;
|
|
21
|
+
prevIsGroup: (ctx: Ctx) => boolean;
|
|
22
|
+
nextIsLeaf: (ctx: Ctx) => boolean;
|
|
23
|
+
nextIsGroup: (ctx: Ctx) => boolean;
|
|
24
|
+
prevDepthEquals: (ctx: Ctx, depth: number) => boolean;
|
|
25
|
+
prevDepthEqualsSource: (ctx: Ctx) => boolean;
|
|
26
|
+
prevBelongsToSource: (ctx: Ctx) => boolean;
|
|
27
|
+
isAdjacentPosition: (ctx: Ctx) => boolean;
|
|
28
|
+
targetFirstChildIsGroupWithSourceDepth: (ctx: Ctx) => boolean;
|
|
29
|
+
targetFirstChildDepthEqualsSource: (ctx: Ctx) => boolean;
|
|
30
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { gridExpandedSortedRowIndexLookupSelector, gridRowTreeSelector } from '@mui/x-data-grid';
|
|
2
|
+
/**
|
|
3
|
+
* Reusable validation conditions for row reordering validation
|
|
4
|
+
*/
|
|
5
|
+
export const commonReorderConditions = {
|
|
6
|
+
// Node type checks
|
|
7
|
+
isGroupToGroup: ctx => ctx.sourceNode.type === 'group' && ctx.targetNode.type === 'group',
|
|
8
|
+
isLeafToLeaf: ctx => ctx.sourceNode.type === 'leaf' && ctx.targetNode.type === 'leaf',
|
|
9
|
+
isLeafToGroup: ctx => ctx.sourceNode.type === 'leaf' && ctx.targetNode.type === 'group',
|
|
10
|
+
isGroupToLeaf: ctx => ctx.sourceNode.type === 'group' && ctx.targetNode.type === 'leaf',
|
|
11
|
+
// Drop position checks
|
|
12
|
+
isDropAbove: ctx => ctx.dropPosition === 'above',
|
|
13
|
+
isDropBelow: ctx => ctx.dropPosition === 'below',
|
|
14
|
+
// Depth checks
|
|
15
|
+
sameDepth: ctx => ctx.sourceNode.depth === ctx.targetNode.depth,
|
|
16
|
+
sourceDepthGreater: ctx => ctx.sourceNode.depth > ctx.targetNode.depth,
|
|
17
|
+
targetDepthIsSourceMinusOne: ctx => ctx.targetNode.depth === ctx.sourceNode.depth - 1,
|
|
18
|
+
// Parent checks
|
|
19
|
+
sameParent: ctx => ctx.sourceNode.parent === ctx.targetNode.parent,
|
|
20
|
+
// Node state checks
|
|
21
|
+
targetGroupExpanded: ctx => (ctx.targetNode.type === 'group' && ctx.targetNode.childrenExpanded) ?? false,
|
|
22
|
+
targetGroupCollapsed: ctx => ctx.targetNode.type === 'group' && !ctx.targetNode.childrenExpanded,
|
|
23
|
+
// Previous/Next node checks
|
|
24
|
+
hasPrevNode: ctx => ctx.prevNode !== null,
|
|
25
|
+
hasNextNode: ctx => ctx.nextNode !== null,
|
|
26
|
+
prevIsLeaf: ctx => ctx.prevNode?.type === 'leaf',
|
|
27
|
+
prevIsGroup: ctx => ctx.prevNode?.type === 'group',
|
|
28
|
+
nextIsLeaf: ctx => ctx.nextNode?.type === 'leaf',
|
|
29
|
+
nextIsGroup: ctx => ctx.nextNode?.type === 'group',
|
|
30
|
+
prevDepthEquals: (ctx, depth) => ctx.prevNode?.depth === depth,
|
|
31
|
+
prevDepthEqualsSource: ctx => ctx.prevNode?.depth === ctx.sourceNode.depth,
|
|
32
|
+
// Complex checks
|
|
33
|
+
prevBelongsToSource: ctx => {
|
|
34
|
+
if (!ctx.prevNode) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
// Check if prevNode.parent OR any of its ancestors === sourceNode.id
|
|
38
|
+
let currentId = ctx.prevNode.parent;
|
|
39
|
+
while (currentId) {
|
|
40
|
+
if (currentId === ctx.sourceNode.id) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
const node = gridRowTreeSelector(ctx.apiRef)[currentId];
|
|
44
|
+
if (!node) {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
currentId = node.parent;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
},
|
|
51
|
+
// Position checks
|
|
52
|
+
isAdjacentPosition: ctx => {
|
|
53
|
+
const expandedSortedRowIndexLookup = gridExpandedSortedRowIndexLookupSelector(ctx.apiRef);
|
|
54
|
+
const sourceRowIndex = expandedSortedRowIndexLookup[ctx.sourceNode.id];
|
|
55
|
+
const targetRowIndex = expandedSortedRowIndexLookup[ctx.targetNode.id];
|
|
56
|
+
const dropPosition = ctx.dropPosition;
|
|
57
|
+
return dropPosition === 'above' && targetRowIndex === sourceRowIndex + 1 || dropPosition === 'below' && targetRowIndex === sourceRowIndex - 1;
|
|
58
|
+
},
|
|
59
|
+
// First child check
|
|
60
|
+
targetFirstChildIsGroupWithSourceDepth: ctx => {
|
|
61
|
+
if (ctx.targetNode.type !== 'group') {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const rowTree = gridRowTreeSelector(ctx.apiRef);
|
|
65
|
+
const targetGroup = ctx.targetNode;
|
|
66
|
+
const firstChild = targetGroup.children?.[0] ? rowTree[targetGroup.children[0]] : null;
|
|
67
|
+
return firstChild?.type === 'group' && firstChild.depth === ctx.sourceNode.depth;
|
|
68
|
+
},
|
|
69
|
+
targetFirstChildDepthEqualsSource: ctx => {
|
|
70
|
+
if (ctx.targetNode.type !== 'group') {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const rowTree = gridRowTreeSelector(ctx.apiRef);
|
|
74
|
+
const targetGroup = ctx.targetNode;
|
|
75
|
+
const firstChild = targetGroup.children?.[0] ? rowTree[targetGroup.children[0]] : null;
|
|
76
|
+
return firstChild ? firstChild.depth === ctx.sourceNode.depth : false;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./gridRowReorderColDef.js";
|
|
1
|
+
export * from "./gridRowReorderColDef.js";
|
|
2
|
+
export type { ReorderValidationContext, IsRowReorderableParams } from "./models.js";
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./gridRowReorderColDef.js";
|
|
1
|
+
export * from "./gridRowReorderColDef.js";
|
|
2
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GridTreeNode, GridValidRowModel } from '@mui/x-data-grid';
|
|
2
|
+
import type { RefObject } from '@mui/x-internals/types';
|
|
3
|
+
import type { RowReorderDropPosition, RowReorderDragDirection } from '@mui/x-data-grid/internals';
|
|
4
|
+
import type { GridPrivateApiPro } from "../../../models/gridApiPro.js";
|
|
5
|
+
export type IsRowReorderableParams<R extends GridValidRowModel = any> = {
|
|
6
|
+
row: R;
|
|
7
|
+
rowNode: GridTreeNode;
|
|
8
|
+
};
|
|
9
|
+
export type ReorderValidationContext = {
|
|
10
|
+
apiRef: RefObject<GridPrivateApiPro>;
|
|
11
|
+
sourceNode: GridTreeNode;
|
|
12
|
+
targetNode: GridTreeNode;
|
|
13
|
+
prevNode: GridTreeNode | null;
|
|
14
|
+
nextNode: GridTreeNode | null;
|
|
15
|
+
dropPosition: RowReorderDropPosition;
|
|
16
|
+
dragDirection: RowReorderDragDirection;
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReorderExecutionContext, ReorderOperation } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all reorder operations.
|
|
4
|
+
* Provides abstract methods for operation detection and execution.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseReorderOperation {
|
|
7
|
+
abstract readonly operationType: string;
|
|
8
|
+
/**
|
|
9
|
+
* Detects if this operation can handle the given context.
|
|
10
|
+
*/
|
|
11
|
+
abstract detectOperation(ctx: ReorderExecutionContext): ReorderOperation | null;
|
|
12
|
+
/**
|
|
13
|
+
* Executes the detected operation.
|
|
14
|
+
*/
|
|
15
|
+
abstract executeOperation(operation: ReorderOperation, ctx: ReorderExecutionContext): Promise<void> | void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Executor class for handling row reorder operations in grouped data grids.
|
|
19
|
+
*
|
|
20
|
+
* This class coordinates the execution of different reorder operation types,
|
|
21
|
+
* trying each operation in order until one succeeds or all fail.
|
|
22
|
+
*/
|
|
23
|
+
export declare class RowReorderExecutor {
|
|
24
|
+
private operations;
|
|
25
|
+
constructor(operations: BaseReorderOperation[]);
|
|
26
|
+
execute(ctx: ReorderExecutionContext): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { warnOnce } from '@mui/x-internals/warning';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all reorder operations.
|
|
4
|
+
* Provides abstract methods for operation detection and execution.
|
|
5
|
+
*/
|
|
6
|
+
export class BaseReorderOperation {}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Executor class for handling row reorder operations in grouped data grids.
|
|
10
|
+
*
|
|
11
|
+
* This class coordinates the execution of different reorder operation types,
|
|
12
|
+
* trying each operation in order until one succeeds or all fail.
|
|
13
|
+
*/
|
|
14
|
+
export class RowReorderExecutor {
|
|
15
|
+
constructor(operations) {
|
|
16
|
+
this.operations = operations;
|
|
17
|
+
}
|
|
18
|
+
async execute(ctx) {
|
|
19
|
+
for (const operation of this.operations) {
|
|
20
|
+
const detectedOperation = operation.detectOperation(ctx);
|
|
21
|
+
if (detectedOperation) {
|
|
22
|
+
// eslint-disable-next-line no-await-in-loop
|
|
23
|
+
await operation.executeOperation(detectedOperation, ctx);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
warnOnce(['MUI X: The parameters provided to the API method resulted in a no-op.', 'Consider looking at the documentation at https://mui.com/x/react-data-grid/row-ordering/'], 'warning');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReorderValidationContext } from "./models.js";
|
|
2
|
+
export interface ValidationRule {
|
|
3
|
+
name: string;
|
|
4
|
+
applies: (ctx: ReorderValidationContext) => boolean;
|
|
5
|
+
isInvalid: (ctx: ReorderValidationContext) => boolean;
|
|
6
|
+
message?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class RowReorderValidator {
|
|
9
|
+
private rules;
|
|
10
|
+
constructor(rules: ValidationRule[]);
|
|
11
|
+
validate(context: ReorderValidationContext): boolean;
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class RowReorderValidator {
|
|
2
|
+
constructor(rules) {
|
|
3
|
+
this.rules = rules;
|
|
4
|
+
}
|
|
5
|
+
validate(context) {
|
|
6
|
+
// Check all validation rules
|
|
7
|
+
for (const rule of this.rules) {
|
|
8
|
+
if (rule.applies(context) && rule.isInvalid(context)) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { GridRowId, GridTreeNode, GridRowTreeConfig } from '@mui/x-data-grid';
|
|
2
|
+
import type { RefObject } from '@mui/x-internals/types';
|
|
3
|
+
import type { RowReorderDropPosition } from '@mui/x-data-grid/internals';
|
|
4
|
+
import type { GridPrivateApiPro } from "../../../models/gridApiPro.js";
|
|
5
|
+
import type { DataGridProProcessedProps } from "../../../models/dataGridProProps.js";
|
|
6
|
+
export type ReorderOperationType = 'same-parent-swap' | 'cross-parent-leaf' | 'cross-parent-group' | 'drop-on-leaf' | 'drop-on-group';
|
|
7
|
+
export interface ReorderExecutionContext<ApiRef extends GridPrivateApiPro = GridPrivateApiPro> {
|
|
8
|
+
sourceRowId: GridRowId;
|
|
9
|
+
dropPosition: RowReorderDropPosition;
|
|
10
|
+
placeholderIndex: number;
|
|
11
|
+
sortedFilteredRowIds: GridRowId[];
|
|
12
|
+
sortedFilteredRowIndexLookup: Record<GridRowId, number>;
|
|
13
|
+
rowTree: GridRowTreeConfig;
|
|
14
|
+
apiRef: RefObject<ApiRef>;
|
|
15
|
+
processRowUpdate?: DataGridProProcessedProps['processRowUpdate'];
|
|
16
|
+
onProcessRowUpdateError?: DataGridProProcessedProps['onProcessRowUpdateError'];
|
|
17
|
+
setTreeDataPath?: DataGridProProcessedProps['setTreeDataPath'];
|
|
18
|
+
}
|
|
19
|
+
export interface ReorderOperation {
|
|
20
|
+
sourceNode: GridTreeNode;
|
|
21
|
+
targetNode: GridTreeNode;
|
|
22
|
+
actualTargetIndex: number;
|
|
23
|
+
isLastChild: boolean;
|
|
24
|
+
operationType: ReorderOperationType;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -7,4 +7,4 @@ export declare const rowReorderStateInitializer: GridStateInitializer;
|
|
|
7
7
|
* Hook for row reordering (Pro package)
|
|
8
8
|
* @requires useGridRows (method)
|
|
9
9
|
*/
|
|
10
|
-
export declare const useGridRowReorder: (apiRef: RefObject<GridPrivateApiPro>, props: Pick<DataGridProProcessedProps, "rowReordering" | "onRowOrderChange" | "classes" | "treeData" | "dataSource">) => void;
|
|
10
|
+
export declare const useGridRowReorder: (apiRef: RefObject<GridPrivateApiPro>, props: Pick<DataGridProProcessedProps, "rowReordering" | "onRowOrderChange" | "classes" | "treeData" | "dataSource" | "isValidRowReorder">) => void;
|