@mui/x-data-grid-pro 5.7.0 → 5.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/CHANGELOG.md +241 -53
  2. package/DataGridPro/DataGridPro.d.ts +7 -1
  3. package/DataGridPro/DataGridPro.js +44 -6
  4. package/DataGridPro/useDataGridProComponent.js +8 -4
  5. package/DataGridPro/useDataGridProProps.d.ts +2 -1
  6. package/DataGridPro/useDataGridProProps.js +1 -0
  7. package/LICENSE +12 -0
  8. package/README.md +6 -4
  9. package/components/DataGridProColumnHeaders.js +0 -6
  10. package/components/DataGridProVirtualScroller.js +1 -3
  11. package/components/GridDetailPanelToggleCell.js +15 -4
  12. package/components/GridGroupingCriteriaCell.d.ts +2 -5
  13. package/components/GridGroupingCriteriaCell.js +2 -74
  14. package/components/GridRowReorderCell.d.ts +5 -0
  15. package/components/GridRowReorderCell.js +72 -0
  16. package/components/GridTreeDataGroupingCell.js +15 -4
  17. package/hooks/features/columnPinning/useGridColumnPinning.js +6 -6
  18. package/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +2 -2
  19. package/hooks/features/columnReorder/useGridColumnReorder.js +3 -3
  20. package/hooks/features/columnResize/useGridColumnResize.js +18 -6
  21. package/hooks/features/detailPanel/useGridDetailPanel.js +12 -4
  22. package/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
  23. package/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +2 -2
  24. package/hooks/features/index.d.ts +1 -0
  25. package/hooks/features/index.js +1 -0
  26. package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +1 -1
  27. package/hooks/features/rowGrouping/useGridRowGrouping.js +6 -8
  28. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +2 -2
  29. package/hooks/features/rowReorder/gridRowReorderColDef.d.ts +2 -0
  30. package/hooks/features/rowReorder/gridRowReorderColDef.js +18 -0
  31. package/hooks/features/rowReorder/index.d.ts +1 -0
  32. package/hooks/features/rowReorder/index.js +1 -0
  33. package/hooks/features/rowReorder/useGridRowReorder.d.ts +8 -0
  34. package/hooks/features/rowReorder/useGridRowReorder.js +111 -0
  35. package/hooks/features/rowReorder/useGridRowReorderPreProcessors.d.ts +4 -0
  36. package/hooks/features/rowReorder/useGridRowReorderPreProcessors.js +51 -0
  37. package/hooks/features/treeData/useGridTreeData.js +0 -2
  38. package/hooks/features/treeData/useGridTreeDataPreProcessors.js +2 -2
  39. package/index.d.ts +1 -1
  40. package/index.js +2 -2
  41. package/legacy/DataGridPro/DataGridPro.js +44 -6
  42. package/legacy/DataGridPro/useDataGridProComponent.js +8 -4
  43. package/legacy/DataGridPro/useDataGridProProps.js +1 -0
  44. package/legacy/components/DataGridProColumnHeaders.js +0 -6
  45. package/legacy/components/DataGridProVirtualScroller.js +1 -3
  46. package/legacy/components/GridDetailPanelToggleCell.js +15 -4
  47. package/legacy/components/GridGroupingCriteriaCell.js +2 -74
  48. package/legacy/components/GridRowReorderCell.js +74 -0
  49. package/legacy/components/GridTreeDataGroupingCell.js +15 -4
  50. package/legacy/hooks/features/columnPinning/useGridColumnPinning.js +6 -6
  51. package/legacy/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +2 -2
  52. package/legacy/hooks/features/columnReorder/useGridColumnReorder.js +3 -3
  53. package/legacy/hooks/features/columnResize/useGridColumnResize.js +18 -6
  54. package/legacy/hooks/features/detailPanel/useGridDetailPanel.js +12 -4
  55. package/legacy/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
  56. package/legacy/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +2 -2
  57. package/legacy/hooks/features/index.js +1 -0
  58. package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +6 -8
  59. package/legacy/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +2 -2
  60. package/legacy/hooks/features/rowReorder/gridRowReorderColDef.js +20 -0
  61. package/legacy/hooks/features/rowReorder/index.js +1 -0
  62. package/legacy/hooks/features/rowReorder/useGridRowReorder.js +115 -0
  63. package/legacy/hooks/features/rowReorder/useGridRowReorderPreProcessors.js +52 -0
  64. package/legacy/hooks/features/treeData/useGridTreeData.js +0 -2
  65. package/legacy/hooks/features/treeData/useGridTreeDataPreProcessors.js +2 -2
  66. package/legacy/index.js +2 -2
  67. package/legacy/models/gridRowOrderChangeParams.js +1 -0
  68. package/legacy/models/index.js +1 -0
  69. package/legacy/utils/domUtils.js +30 -3
  70. package/legacy/utils/releaseInfo.js +1 -1
  71. package/models/dataGridProProps.d.ts +21 -8
  72. package/models/gridGroupingColDefOverride.d.ts +2 -2
  73. package/models/gridGroupingValueGetterParams.d.ts +1 -1
  74. package/models/gridRowOrderChangeParams.d.ts +18 -0
  75. package/models/gridRowOrderChangeParams.js +1 -0
  76. package/models/index.d.ts +1 -0
  77. package/models/index.js +1 -0
  78. package/modern/DataGridPro/DataGridPro.js +44 -6
  79. package/modern/DataGridPro/useDataGridProComponent.js +8 -4
  80. package/modern/DataGridPro/useDataGridProProps.js +1 -0
  81. package/modern/components/DataGridProColumnHeaders.js +0 -6
  82. package/modern/components/DataGridProVirtualScroller.js +1 -3
  83. package/modern/components/GridDetailPanelToggleCell.js +15 -4
  84. package/modern/components/GridGroupingCriteriaCell.js +2 -74
  85. package/modern/components/GridRowReorderCell.js +72 -0
  86. package/modern/components/GridTreeDataGroupingCell.js +15 -4
  87. package/modern/hooks/features/columnPinning/useGridColumnPinning.js +6 -6
  88. package/modern/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +2 -2
  89. package/modern/hooks/features/columnReorder/useGridColumnReorder.js +3 -3
  90. package/modern/hooks/features/columnResize/useGridColumnResize.js +18 -6
  91. package/modern/hooks/features/detailPanel/useGridDetailPanel.js +12 -4
  92. package/modern/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
  93. package/modern/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +2 -2
  94. package/modern/hooks/features/index.js +1 -0
  95. package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +6 -8
  96. package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +2 -2
  97. package/modern/hooks/features/rowReorder/gridRowReorderColDef.js +18 -0
  98. package/modern/hooks/features/rowReorder/index.js +1 -0
  99. package/modern/hooks/features/rowReorder/useGridRowReorder.js +111 -0
  100. package/modern/hooks/features/rowReorder/useGridRowReorderPreProcessors.js +51 -0
  101. package/modern/hooks/features/treeData/useGridTreeData.js +0 -2
  102. package/modern/hooks/features/treeData/useGridTreeDataPreProcessors.js +2 -2
  103. package/modern/index.js +2 -2
  104. package/modern/models/gridRowOrderChangeParams.js +1 -0
  105. package/modern/models/index.js +1 -0
  106. package/modern/utils/domUtils.js +30 -3
  107. package/modern/utils/releaseInfo.js +1 -1
  108. package/node/DataGridPro/DataGridPro.js +44 -6
  109. package/node/DataGridPro/useDataGridProComponent.js +9 -3
  110. package/node/DataGridPro/useDataGridProProps.js +1 -0
  111. package/node/components/DataGridProColumnHeaders.js +0 -6
  112. package/node/components/DataGridProVirtualScroller.js +1 -3
  113. package/node/components/GridDetailPanelToggleCell.js +15 -4
  114. package/node/components/GridGroupingCriteriaCell.js +1 -72
  115. package/node/components/GridRowReorderCell.js +92 -0
  116. package/node/components/GridTreeDataGroupingCell.js +15 -4
  117. package/node/hooks/features/columnPinning/useGridColumnPinning.js +5 -5
  118. package/node/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +1 -1
  119. package/node/hooks/features/columnReorder/useGridColumnReorder.js +3 -3
  120. package/node/hooks/features/columnResize/useGridColumnResize.js +18 -6
  121. package/node/hooks/features/detailPanel/useGridDetailPanel.js +11 -3
  122. package/node/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
  123. package/node/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +1 -1
  124. package/node/hooks/features/index.js +13 -0
  125. package/node/hooks/features/rowGrouping/useGridRowGrouping.js +5 -7
  126. package/node/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +1 -1
  127. package/node/hooks/features/rowReorder/gridRowReorderColDef.js +31 -0
  128. package/node/hooks/features/rowReorder/index.js +18 -0
  129. package/node/hooks/features/rowReorder/useGridRowReorder.js +126 -0
  130. package/node/hooks/features/rowReorder/useGridRowReorderPreProcessors.js +70 -0
  131. package/node/hooks/features/treeData/useGridTreeData.js +0 -2
  132. package/node/hooks/features/treeData/useGridTreeDataPreProcessors.js +1 -1
  133. package/node/index.js +9 -9
  134. package/node/models/gridRowOrderChangeParams.js +5 -0
  135. package/node/models/index.js +13 -0
  136. package/node/utils/domUtils.js +30 -3
  137. package/node/utils/releaseInfo.js +1 -1
  138. package/package.json +7 -7
  139. package/typeOverloads/modules.d.ts +10 -7
  140. package/typeOverloads/reexports.d.ts +1 -1
  141. package/utils/domUtils.d.ts +2 -1
  142. package/utils/domUtils.js +30 -3
  143. package/utils/releaseInfo.js +1 -1
@@ -0,0 +1,72 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import { unstable_composeClasses as composeClasses } from '@mui/material';
4
+ import { GridEvents, gridRowTreeDepthSelector, gridSortModelSelector, useGridApiContext, useGridSelector, getDataGridUtilityClass, gridEditRowsStateSelector } from '@mui/x-data-grid';
5
+ import { useGridRootProps } from '../hooks/utils/useGridRootProps';
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ import { jsxs as _jsxs } from "react/jsx-runtime";
8
+
9
+ const useUtilityClasses = ownerState => {
10
+ const {
11
+ isDraggable,
12
+ classes
13
+ } = ownerState;
14
+ const slots = {
15
+ root: ['rowReorderCell', isDraggable && 'rowReorderCell--draggable'],
16
+ placeholder: ['rowReorderCellPlaceholder']
17
+ };
18
+ return composeClasses(slots, getDataGridUtilityClass, classes);
19
+ };
20
+
21
+ const GridRowReorderCell = params => {
22
+ const apiRef = useGridApiContext();
23
+ const rootProps = useGridRootProps();
24
+ const sortModel = useGridSelector(apiRef, gridSortModelSelector);
25
+ const treeDepth = useGridSelector(apiRef, gridRowTreeDepthSelector);
26
+ const editRowsState = useGridSelector(apiRef, gridEditRowsStateSelector); // eslint-disable-next-line no-underscore-dangle
27
+
28
+ const cellValue = params.row.__reorder__ || params.id; // TODO: remove sortModel and treeDepth checks once row reorder is compatible
29
+
30
+ const isDraggable = !!rootProps.rowReordering && !sortModel.length && treeDepth === 1 && Object.keys(editRowsState).length === 0;
31
+ const ownerState = {
32
+ isDraggable,
33
+ classes: rootProps.classes
34
+ };
35
+ const classes = useUtilityClasses(ownerState);
36
+ const publish = React.useCallback((eventName, propHandler) => event => {
37
+ // Ignore portal
38
+ // The target is not an element when triggered by a Select inside the cell
39
+ // See https://github.com/mui/material-ui/issues/10534
40
+ if (event.target.nodeType === 1 && !event.currentTarget.contains(event.target)) {
41
+ return;
42
+ } // The row might have been deleted
43
+
44
+
45
+ if (!apiRef.current.getRow(params.row.id)) {
46
+ return;
47
+ }
48
+
49
+ apiRef.current.publishEvent(eventName, apiRef.current.getRowParams(params.row.id), event);
50
+
51
+ if (propHandler) {
52
+ propHandler(event);
53
+ }
54
+ }, [apiRef, params.row.id]);
55
+ const draggableEventHandlers = {
56
+ onDragStart: publish(GridEvents.rowDragStart),
57
+ onDragOver: publish(GridEvents.rowDragOver),
58
+ onDragEnd: publish(GridEvents.rowDragEnd)
59
+ };
60
+ return /*#__PURE__*/_jsxs("div", _extends({
61
+ className: classes.root,
62
+ draggable: isDraggable
63
+ }, draggableEventHandlers, {
64
+ children: [/*#__PURE__*/_jsx(rootProps.components.RowReorderIcon, {}), /*#__PURE__*/_jsx("div", {
65
+ className: classes.placeholder,
66
+ children: cellValue
67
+ })]
68
+ }));
69
+ };
70
+
71
+ export { GridRowReorderCell };
72
+ export const renderRowReorderCell = params => /*#__PURE__*/_jsx(GridRowReorderCell, _extends({}, params));
@@ -105,16 +105,27 @@ process.env.NODE_ENV !== "production" ? GridTreeDataGroupingCell.propTypes = {
105
105
  */
106
106
  field: PropTypes.string.isRequired,
107
107
 
108
+ /**
109
+ * A ref allowing to set imperative focus.
110
+ * It can be passed to the element that should receive focus.
111
+ * @ignore - do not document.
112
+ */
113
+ focusElementRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
114
+ current: PropTypes.shape({
115
+ focus: PropTypes.func.isRequired
116
+ })
117
+ })]),
118
+
108
119
  /**
109
120
  * The cell value formatted with the column valueFormatter.
110
121
  */
111
- formattedValue: PropTypes.any.isRequired,
122
+ formattedValue: PropTypes.any,
112
123
 
113
124
  /**
114
125
  * Get the cell value of a row and field.
115
126
  * @param {GridRowId} id The row id.
116
127
  * @param {string} field The field.
117
- * @returns {GridCellValue} The cell value.
128
+ * @returns {any} The cell value.
118
129
  * @deprecated Use `params.row` to directly access the fields you want instead.
119
130
  */
120
131
  getValue: PropTypes.func.isRequired,
@@ -138,7 +149,7 @@ process.env.NODE_ENV !== "production" ? GridTreeDataGroupingCell.propTypes = {
138
149
  /**
139
150
  * The row model of the row that the current cell belongs to.
140
151
  */
141
- row: PropTypes.any.isRequired,
152
+ row: PropTypes.object.isRequired,
142
153
 
143
154
  /**
144
155
  * The node of the row that the current cell belongs to.
@@ -153,6 +164,6 @@ process.env.NODE_ENV !== "production" ? GridTreeDataGroupingCell.propTypes = {
153
164
  /**
154
165
  * The cell value, but if the column has valueGetter, use getValue.
155
166
  */
156
- value: PropTypes.any.isRequired
167
+ value: PropTypes.any
157
168
  } : void 0;
158
169
  export { GridTreeDataGroupingCell };
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import MuiDivider from '@mui/material/Divider';
4
4
  import { useGridSelector, gridVisibleColumnDefinitionsSelector, gridColumnsTotalWidthSelector, gridColumnPositionsSelector, gridVisibleColumnFieldsSelector, gridClasses, GridEvents, useGridApiMethod, useGridApiEventHandler } from '@mui/x-data-grid';
5
- import { useGridRegisterPreProcessor } from '@mui/x-data-grid/internals';
5
+ import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
6
6
  import { GridColumnPinningMenuItems } from '../../../components/GridColumnPinningMenuItems';
7
7
  import { GridPinnedPosition } from './gridColumnPinningInterface';
8
8
  import { gridPinnedColumnsSelector } from './gridColumnPinningSelector';
@@ -175,11 +175,11 @@ export const useGridColumnPinning = (apiRef, props) => {
175
175
 
176
176
  return params;
177
177
  }, [apiRef]);
178
- useGridRegisterPreProcessor(apiRef, 'scrollToIndexes', calculateScrollLeft);
179
- useGridRegisterPreProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
180
- useGridRegisterPreProcessor(apiRef, 'canBeReordered', checkIfCanBeReordered);
181
- useGridRegisterPreProcessor(apiRef, 'exportState', stateExportPreProcessing);
182
- useGridRegisterPreProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
178
+ useGridRegisterPipeProcessor(apiRef, 'scrollToIndexes', calculateScrollLeft);
179
+ useGridRegisterPipeProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
180
+ useGridRegisterPipeProcessor(apiRef, 'canBeReordered', checkIfCanBeReordered);
181
+ useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
182
+ useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
183
183
  apiRef.current.unstable_updateControlState({
184
184
  stateId: 'pinnedColumns',
185
185
  propModel: props.pinnedColumns,
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
- import { useGridRegisterPreProcessor } from '@mui/x-data-grid/internals';
3
+ import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
4
4
  import { gridPinnedColumnsSelector } from './gridColumnPinningSelector';
5
5
  import { columnPinningStateInitializer } from './useGridColumnPinning';
6
6
  import { filterColumns } from '../../../components/DataGridProVirtualScroller';
@@ -41,5 +41,5 @@ export const useGridColumnPinningPreProcessors = (apiRef, props) => {
41
41
  all: [...leftPinnedColumns, ...centerColumns, ...rightPinnedColumns]
42
42
  });
43
43
  }, [disableColumnPinning, pinnedColumns]);
44
- useGridRegisterPreProcessor(apiRef, 'hydrateColumns', reorderPinnedColumns);
44
+ useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', reorderPinnedColumns);
45
45
  };
@@ -50,7 +50,7 @@ export const useGridColumnReorder = (apiRef, props) => {
50
50
  clearTimeout(removeDnDStylesTimeout.current);
51
51
  };
52
52
  }, []);
53
- const handleColumnHeaderDragStart = React.useCallback((params, event) => {
53
+ const handleDragStart = React.useCallback((params, event) => {
54
54
  if (props.disableColumnReorder || params.colDef.disableReorder) {
55
55
  return;
56
56
  }
@@ -116,7 +116,7 @@ export const useGridColumnReorder = (apiRef, props) => {
116
116
  canBeReordered = targetColIndex < visibleColumns.length - 1 && !visibleColumns[targetColIndex + 1].disableReorder;
117
117
  }
118
118
 
119
- const canBeReorderedProcessed = apiRef.current.unstable_applyPreProcessors('canBeReordered', canBeReordered, {
119
+ const canBeReorderedProcessed = apiRef.current.unstable_applyPipeProcessors('canBeReordered', canBeReordered, {
120
120
  targetIndex: targetColVisibleIndex
121
121
  });
122
122
 
@@ -156,7 +156,7 @@ export const useGridColumnReorder = (apiRef, props) => {
156
156
  }));
157
157
  apiRef.current.forceUpdate();
158
158
  }, [props.disableColumnReorder, logger, apiRef]);
159
- useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragStart, handleColumnHeaderDragStart);
159
+ useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragStart, handleDragStart);
160
160
  useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragEnter, handleDragEnter);
161
161
  useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragOver, handleDragOver);
162
162
  useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragEnd, handleDragEnd);
@@ -100,17 +100,29 @@ export const useGridColumnResize = (apiRef, props) => {
100
100
 
101
101
  const updateWidth = newWidth => {
102
102
  logger.debug(`Updating width to ${newWidth} for col ${colDefRef.current.field}`);
103
+ const prevWidth = colElementRef.current.offsetWidth;
104
+ const widthDiff = newWidth - prevWidth;
103
105
  colDefRef.current.computedWidth = newWidth;
104
106
  colDefRef.current.width = newWidth;
105
- colDefRef.current.flex = undefined;
107
+ colDefRef.current.flex = 0;
106
108
  colElementRef.current.style.width = `${newWidth}px`;
107
109
  colElementRef.current.style.minWidth = `${newWidth}px`;
108
110
  colElementRef.current.style.maxWidth = `${newWidth}px`;
109
111
  colCellElementsRef.current.forEach(element => {
110
112
  const div = element;
111
- div.style.width = `${newWidth}px`;
112
- div.style.minWidth = `${newWidth}px`;
113
- div.style.maxWidth = `${newWidth}px`;
113
+ let finalWidth;
114
+
115
+ if (div.getAttribute('aria-colspan') === '1') {
116
+ finalWidth = `${newWidth}px`;
117
+ } else {
118
+ // Cell with colspan > 1 cannot be just updated width new width.
119
+ // Instead, we add width diff to the current width.
120
+ finalWidth = `${div.offsetWidth + widthDiff}px`;
121
+ }
122
+
123
+ div.style.width = finalWidth;
124
+ div.style.minWidth = finalWidth;
125
+ div.style.maxWidth = finalWidth;
114
126
  });
115
127
  };
116
128
 
@@ -170,7 +182,7 @@ export const useGridColumnResize = (apiRef, props) => {
170
182
  }, event);
171
183
  colDefRef.current = colDef;
172
184
  colElementRef.current = apiRef.current.columnHeadersContainerElementRef?.current.querySelector(`[data-field="${colDef.field}"]`);
173
- colCellElementsRef.current = findGridCellElementsFromCol(colElementRef.current);
185
+ colCellElementsRef.current = findGridCellElementsFromCol(colElementRef.current, apiRef.current);
174
186
  const doc = ownerDocument(apiRef.current.rootElementRef.current);
175
187
  doc.body.style.cursor = 'col-resize';
176
188
  separatorSide.current = getSeparatorSide(event.currentTarget);
@@ -245,7 +257,7 @@ export const useGridColumnResize = (apiRef, props) => {
245
257
  }, event);
246
258
  colDefRef.current = colDef;
247
259
  colElementRef.current = findHeaderElementFromField(apiRef.current.columnHeadersElementRef?.current, colDef.field);
248
- colCellElementsRef.current = findGridCellElementsFromCol(colElementRef.current);
260
+ colCellElementsRef.current = findGridCellElementsFromCol(colElementRef.current, apiRef.current);
249
261
  separatorSide.current = getSeparatorSide(event.target);
250
262
  initialOffsetToSeparator.current = computeOffsetToSeparator(touch.clientX, colElementRef.current.getBoundingClientRect(), separatorSide.current);
251
263
  const doc = ownerDocument(event.currentTarget);
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { GridEvents, useGridSelector, useGridApiEventHandler, useGridApiMethod } from '@mui/x-data-grid';
4
- import { useGridRegisterPreProcessor } from '@mui/x-data-grid/internals';
4
+ import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
5
5
  import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from './gridDetailPanelToggleColDef';
6
6
  import { gridDetailPanelExpandedRowIdsSelector, gridDetailPanelExpandedRowsContentCacheSelector, gridDetailPanelExpandedRowsHeightCacheSelector } from './gridDetailPanelSelector';
7
7
  export const detailPanelStateInitializer = (state, props) => {
@@ -33,11 +33,19 @@ export const useGridDetailPanel = (apiRef, props) => {
33
33
  apiRef.current.toggleDetailPanel(params.id);
34
34
  }, [apiRef, contentCache, props.getDetailPanelContent]);
35
35
  const handleCellKeyDown = React.useCallback((params, event) => {
36
- if (!event.ctrlKey || event.key !== 'Enter' || props.getDetailPanelContent == null) {
36
+ if (props.getDetailPanelContent == null) {
37
37
  return;
38
38
  }
39
39
 
40
- apiRef.current.toggleDetailPanel(params.id);
40
+ if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') {
41
+ // TODO v6: only support Space on the detail toggle
42
+ apiRef.current.toggleDetailPanel(params.id);
43
+ return;
44
+ }
45
+
46
+ if (params.field === GRID_DETAIL_PANEL_TOGGLE_FIELD && event.key === ' ') {
47
+ apiRef.current.toggleDetailPanel(params.id);
48
+ }
41
49
  }, [apiRef, props.getDetailPanelContent]);
42
50
  useGridApiEventHandler(apiRef, GridEvents.cellClick, handleCellClick);
43
51
  useGridApiEventHandler(apiRef, GridEvents.cellKeyDown, handleCellKeyDown);
@@ -54,7 +62,7 @@ export const useGridDetailPanel = (apiRef, props) => {
54
62
 
55
63
  });
56
64
  }, [apiRef, expandedRowIds]);
57
- useGridRegisterPreProcessor(apiRef, 'rowHeight', addDetailHeight);
65
+ useGridRegisterPipeProcessor(apiRef, 'rowHeight', addDetailHeight);
58
66
  apiRef.current.unstable_updateControlState({
59
67
  stateId: 'detailPanels',
60
68
  propModel: props.detailPanelExpandedRowIds,
@@ -39,7 +39,7 @@ export const useGridDetailPanelCache = (apiRef, props) => {
39
39
  });
40
40
  apiRef.current.forceUpdate();
41
41
  }, [apiRef, props.getDetailPanelContent, props.getDetailPanelHeight]);
42
- useGridApiEventHandler(apiRef, GridEvents.visibleRowsSet, updateCaches);
42
+ useGridApiEventHandler(apiRef, GridEvents.sortedRowsSet, updateCaches);
43
43
  const isFirstRender = React.useRef(true);
44
44
 
45
45
  if (isFirstRender.current) {
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { useGridRegisterPreProcessor } from '@mui/x-data-grid/internals';
2
+ import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
3
3
  import { GRID_DETAIL_PANEL_TOGGLE_FIELD, GRID_DETAIL_PANEL_TOGGLE_COL_DEF } from './gridDetailPanelToggleColDef';
4
4
  export const useGridDetailPanelPreProcessors = (apiRef, props) => {
5
5
  const addToggleColumn = React.useCallback(columnsState => {
@@ -24,5 +24,5 @@ export const useGridDetailPanelPreProcessors = (apiRef, props) => {
24
24
  columnsState.lookup[GRID_DETAIL_PANEL_TOGGLE_FIELD] = GRID_DETAIL_PANEL_TOGGLE_COL_DEF;
25
25
  return columnsState;
26
26
  }, [props.getDetailPanelContent]);
27
- useGridRegisterPreProcessor(apiRef, 'hydrateColumns', addToggleColumn);
27
+ useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', addToggleColumn);
28
28
  };
@@ -3,5 +3,6 @@ export * from './columnPinning';
3
3
  export * from './columnReorder';
4
4
  export * from './columnResize';
5
5
  export * from './rowGrouping';
6
+ export * from './rowReorder';
6
7
  export * from './treeData';
7
8
  export * from './detailPanel';
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import Divider from '@mui/material/Divider';
4
4
  import { GridEvents, useGridApiEventHandler, useGridApiMethod, gridFilteredDescendantCountLookupSelector } from '@mui/x-data-grid';
5
- import { useGridRegisterPreProcessor, isDeepEqual } from '@mui/x-data-grid/internals';
5
+ import { useGridRegisterPipeProcessor, isDeepEqual } from '@mui/x-data-grid/internals';
6
6
  import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector, gridRowGroupingStateSelector } from './gridRowGroupingSelector';
7
7
  import { getRowGroupingFieldFromGroupingCriteria, ROW_GROUPING_STRATEGY, isGroupingColumn, mergeStateWithRowGroupingModel, setStrategyAvailability } from './gridRowGroupingUtils';
8
8
  import { GridRowGroupableColumnMenuItems } from '../../../components/GridRowGroupableColumnMenuItems';
@@ -137,9 +137,9 @@ export const useGridRowGrouping = (apiRef, props) => {
137
137
 
138
138
  return params;
139
139
  }, [apiRef, props.disableRowGrouping]);
140
- useGridRegisterPreProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
141
- useGridRegisterPreProcessor(apiRef, 'exportState', stateExportPreProcessing);
142
- useGridRegisterPreProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
140
+ useGridRegisterPipeProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
141
+ useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
142
+ useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
143
143
  /**
144
144
  * EVENTS
145
145
  */
@@ -169,10 +169,8 @@ export const useGridRowGrouping = (apiRef, props) => {
169
169
  rowGrouping: _extends({}, state.rowGrouping, {
170
170
  unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
171
171
  })
172
- })); // Refresh the column pre-processing
173
- // TODO: Add a clean way to re-run a pipe processing without faking a change
174
-
175
- apiRef.current.updateColumns([]);
172
+ }));
173
+ apiRef.current.unstable_requestPipeProcessorsApplication('hydrateColumns');
176
174
  setStrategyAvailability(apiRef, props.disableRowGrouping); // Refresh the row tree creation strategy processing
177
175
  // TODO: Add a clean way to re-run a strategy processing without publishing a private event
178
176
 
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { gridColumnLookupSelector, gridRowIdsSelector, gridRowTreeSelector, useFirstRender } from '@mui/x-data-grid';
4
- import { useGridRegisterPreProcessor, useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
4
+ import { useGridRegisterPipeProcessor, useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
5
5
  import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
6
6
  import { createGroupingColDefForAllGroupingCriteria, createGroupingColDefForOneGroupingCriteria } from './createGroupingColDef';
7
7
  import { filterRowTreeFromGroupingColumns, getColDefOverrides, ROW_GROUPING_STRATEGY, isGroupingColumn, setStrategyAvailability } from './gridRowGroupingUtils';
@@ -177,7 +177,7 @@ export const useGridRowGroupingPreProcessors = (apiRef, props) => {
177
177
  disableChildrenSorting: false
178
178
  });
179
179
  }, [apiRef]);
180
- useGridRegisterPreProcessor(apiRef, 'hydrateColumns', updateGroupingColumn);
180
+ useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateGroupingColumn);
181
181
  useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'rowTreeCreation', createRowTree);
182
182
  useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'filtering', filterRows);
183
183
  useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'sorting', sortRows);
@@ -0,0 +1,18 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { GRID_STRING_COL_DEF } from '@mui/x-data-grid';
3
+ import { renderRowReorderCell } from '../../../components/GridRowReorderCell';
4
+ export const GRID_REORDER_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
5
+ field: '__reorder__',
6
+ type: 'reorder',
7
+ sortable: false,
8
+ filterable: false,
9
+ width: 50,
10
+ align: 'center',
11
+ headerAlign: 'center',
12
+ disableColumnMenu: true,
13
+ disableExport: true,
14
+ disableReorder: true,
15
+ resizable: false,
16
+ renderHeader: () => ' ',
17
+ renderCell: renderRowReorderCell
18
+ });
@@ -0,0 +1 @@
1
+ export * from './gridRowReorderColDef';
@@ -0,0 +1,111 @@
1
+ import * as React from 'react';
2
+ import { unstable_composeClasses as composeClasses } from '@mui/material';
3
+ import { useGridLogger, GridEvents, useGridApiEventHandler, getDataGridUtilityClass, useGridSelector, gridSortModelSelector, gridRowTreeDepthSelector, useGridApiOptionHandler, gridEditRowsStateSelector } from '@mui/x-data-grid';
4
+
5
+ const useUtilityClasses = ownerState => {
6
+ const {
7
+ classes
8
+ } = ownerState;
9
+ const slots = {
10
+ rowDragging: ['row--dragging']
11
+ };
12
+ return composeClasses(slots, getDataGridUtilityClass, classes);
13
+ };
14
+ /**
15
+ * Only available in DataGridPro
16
+ * @requires useGridRows (method)
17
+ */
18
+
19
+
20
+ export const useGridRowReorder = (apiRef, props) => {
21
+ const logger = useGridLogger(apiRef, 'useGridRowReorder');
22
+ const sortModel = useGridSelector(apiRef, gridSortModelSelector);
23
+ const treeDepth = useGridSelector(apiRef, gridRowTreeDepthSelector);
24
+ const dragRowNode = React.useRef(null);
25
+ const originRowIndex = React.useRef(null);
26
+ const removeDnDStylesTimeout = React.useRef();
27
+ const ownerState = {
28
+ classes: props.classes
29
+ };
30
+ const classes = useUtilityClasses(ownerState);
31
+ const [dragRowId, setDragRowId] = React.useState('');
32
+ React.useEffect(() => {
33
+ return () => {
34
+ clearTimeout(removeDnDStylesTimeout.current);
35
+ };
36
+ }, []); // TODO: remove sortModel check once row reorder is sorting compatible
37
+ // remove treeDepth once row reorder is tree compatible
38
+
39
+ const isRowReorderDisabled = React.useMemo(() => {
40
+ return !props.rowReordering || !!sortModel.length || treeDepth !== 1;
41
+ }, [props.rowReordering, sortModel, treeDepth]);
42
+ const handleDragStart = React.useCallback((params, event) => {
43
+ // Call the gridEditRowsStateSelector directly to avoid infnite loop
44
+ const editRowsState = gridEditRowsStateSelector(apiRef.current.state);
45
+
46
+ if (isRowReorderDisabled || Object.keys(editRowsState).length !== 0) {
47
+ return;
48
+ }
49
+
50
+ logger.debug(`Start dragging row ${params.id}`); // Prevent drag events propagation.
51
+ // For more information check here https://github.com/mui/mui-x/issues/2680.
52
+
53
+ event.stopPropagation();
54
+ dragRowNode.current = event.currentTarget;
55
+ dragRowNode.current.classList.add(classes.rowDragging);
56
+ setDragRowId(params.id);
57
+ removeDnDStylesTimeout.current = setTimeout(() => {
58
+ dragRowNode.current.classList.remove(classes.rowDragging);
59
+ });
60
+ originRowIndex.current = apiRef.current.getRowIndex(params.id);
61
+ }, [isRowReorderDisabled, classes.rowDragging, logger, apiRef]);
62
+ const handleDragOver = React.useCallback((params, event) => {
63
+ logger.debug(`Dragging over row ${params.id}`);
64
+ event.preventDefault(); // Prevent drag events propagation.
65
+ // For more information check here https://github.com/mui/mui-x/issues/2680.
66
+
67
+ event.stopPropagation();
68
+
69
+ if (params.id !== dragRowId) {
70
+ const targetRowIndex = apiRef.current.getRowIndex(params.id);
71
+ apiRef.current.setRowIndex(dragRowId, targetRowIndex);
72
+ }
73
+ }, [apiRef, logger, dragRowId]);
74
+ const handleDragEnd = React.useCallback((params, event) => {
75
+ // Call the gridEditRowsStateSelector directly to avoid infnite loop
76
+ const editRowsState = gridEditRowsStateSelector(apiRef.current.state);
77
+
78
+ if (isRowReorderDisabled || Object.keys(editRowsState).length !== 0) {
79
+ return;
80
+ }
81
+
82
+ logger.debug('End dragging row');
83
+ event.preventDefault(); // Prevent drag events propagation.
84
+ // For more information check here https://github.com/mui/mui-x/issues/2680.
85
+
86
+ event.stopPropagation();
87
+ clearTimeout(removeDnDStylesTimeout.current);
88
+ dragRowNode.current = null; // Check if the row was dropped outside the grid.
89
+
90
+ if (event.dataTransfer.dropEffect === 'none') {
91
+ // Accessing params.field may contain the wrong field as header elements are reused
92
+ apiRef.current.setRowIndex(dragRowId, originRowIndex.current);
93
+ originRowIndex.current = null;
94
+ } else {
95
+ // Emit the rowOrderChange event only once when the reordering stops.
96
+ const rowOrderChangeParams = {
97
+ row: apiRef.current.getRow(dragRowId),
98
+ targetIndex: apiRef.current.getRowIndex(params.id),
99
+ oldIndex: originRowIndex.current
100
+ };
101
+ apiRef.current.publishEvent(GridEvents.rowOrderChange, rowOrderChangeParams);
102
+ }
103
+
104
+ setDragRowId('');
105
+ }, [isRowReorderDisabled, logger, apiRef, dragRowId]);
106
+ useGridApiEventHandler(apiRef, GridEvents.rowDragStart, handleDragStart);
107
+ useGridApiEventHandler(apiRef, GridEvents.rowDragOver, handleDragOver);
108
+ useGridApiEventHandler(apiRef, GridEvents.rowDragEnd, handleDragEnd);
109
+ useGridApiEventHandler(apiRef, GridEvents.cellDragOver, handleDragOver);
110
+ useGridApiOptionHandler(apiRef, GridEvents.rowOrderChange, props.onRowOrderChange);
111
+ };
@@ -0,0 +1,51 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import { unstable_composeClasses as composeClasses } from '@mui/material';
4
+ import { getDataGridUtilityClass } from '@mui/x-data-grid';
5
+ import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
6
+ import { GRID_REORDER_COL_DEF } from './gridRowReorderColDef';
7
+
8
+ const useUtilityClasses = ownerState => {
9
+ const {
10
+ classes
11
+ } = ownerState;
12
+ return React.useMemo(() => {
13
+ const slots = {
14
+ rowReorderCellContainer: ['rowReorderCellContainer'],
15
+ columnHeaderReorder: ['columnHeaderReorder']
16
+ };
17
+ return composeClasses(slots, getDataGridUtilityClass, classes);
18
+ }, [classes]);
19
+ };
20
+
21
+ export const useGridRowReorderPreProcessors = (apiRef, props) => {
22
+ const ownerState = {
23
+ classes: props.classes
24
+ };
25
+ const classes = useUtilityClasses(ownerState);
26
+ const updateReorderColumn = React.useCallback(columnsState => {
27
+ const reorderColumn = _extends({}, GRID_REORDER_COL_DEF, {
28
+ cellClassName: classes.rowReorderCellContainer,
29
+ headerClassName: classes.columnHeaderReorder,
30
+ headerName: apiRef.current.getLocaleText('rowReorderingHeaderName')
31
+ });
32
+
33
+ const shouldHaveReorderColumn = props.rowReordering;
34
+ const haveReorderColumn = columnsState.lookup[reorderColumn.field] != null;
35
+
36
+ if (shouldHaveReorderColumn && haveReorderColumn) {
37
+ return columnsState;
38
+ }
39
+
40
+ if (shouldHaveReorderColumn && !haveReorderColumn) {
41
+ columnsState.lookup[reorderColumn.field] = reorderColumn;
42
+ columnsState.all = [reorderColumn.field, ...columnsState.all];
43
+ } else if (!shouldHaveReorderColumn && haveReorderColumn) {
44
+ delete columnsState.lookup[reorderColumn.field];
45
+ columnsState.all = columnsState.all.filter(field => field !== reorderColumn.field);
46
+ }
47
+
48
+ return columnsState;
49
+ }, [apiRef, classes, props.rowReordering]);
50
+ useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateReorderColumn);
51
+ };
@@ -12,8 +12,6 @@ export const useGridTreeData = apiRef => {
12
12
  const cellParams = apiRef.current.getCellParams(params.id, params.field);
13
13
 
14
14
  if (cellParams.colDef.type === 'treeDataGroup' && event.key === ' ' && !event.shiftKey) {
15
- event.stopPropagation();
16
- event.preventDefault();
17
15
  const filteredDescendantCount = gridFilteredDescendantCountLookupSelector(apiRef)[params.id] ?? 0;
18
16
 
19
17
  if (filteredDescendantCount === 0) {
@@ -3,7 +3,7 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
3
3
  const _excluded = ["hideDescendantCount"];
4
4
  import * as React from 'react';
5
5
  import { gridRowIdsSelector, gridRowTreeSelector, useFirstRender } from '@mui/x-data-grid';
6
- import { useGridRegisterPreProcessor, useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
6
+ import { useGridRegisterPipeProcessor, useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
7
7
  import { GRID_TREE_DATA_GROUPING_COL_DEF, GRID_TREE_DATA_GROUPING_COL_DEF_FORCED_PROPERTIES } from './gridTreeDataGroupColDef';
8
8
  import { filterRowTreeFromTreeData, TREE_DATA_STRATEGY } from './gridTreeDataUtils';
9
9
  import { GridTreeDataGroupingCell } from '../../../components';
@@ -110,7 +110,7 @@ export const useGridTreeDataPreProcessors = (apiRef, props) => {
110
110
  disableChildrenSorting: props.disableChildrenSorting
111
111
  });
112
112
  }, [apiRef, props.disableChildrenSorting]);
113
- useGridRegisterPreProcessor(apiRef, 'hydrateColumns', updateGroupingColumn);
113
+ useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateGroupingColumn);
114
114
  useGridRegisterStrategyProcessor(apiRef, TREE_DATA_STRATEGY, 'rowTreeCreation', createRowTree);
115
115
  useGridRegisterStrategyProcessor(apiRef, TREE_DATA_STRATEGY, 'filtering', filterRows);
116
116
  useGridRegisterStrategyProcessor(apiRef, TREE_DATA_STRATEGY, 'sorting', sortRows);
package/modern/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.7.0
1
+ /** @license MUI v5.10.0
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -11,8 +11,8 @@ export * from '@mui/x-data-grid/hooks';
11
11
  export * from '@mui/x-data-grid/locales';
12
12
  export * from '@mui/x-data-grid/models';
13
13
  export * from '@mui/x-data-grid/context';
14
- export * from '@mui/x-data-grid/colDef';
15
14
  export * from '@mui/x-data-grid/utils';
15
+ export * from '@mui/x-data-grid/colDef';
16
16
  export * from './DataGridPro';
17
17
  export * from './hooks';
18
18
  export * from './models';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
1
  export * from './gridGroupingColDefOverride';
2
2
  export * from './gridRowScrollEndParams';
3
+ export * from './gridRowOrderChangeParams';
3
4
  export * from './gridGroupingValueGetterParams';
4
5
  export {};