@mui/x-data-grid 6.7.0 → 6.9.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 (205) hide show
  1. package/CHANGELOG.md +145 -5541
  2. package/components/GridColumnHeaders.d.ts +2 -2
  3. package/components/GridColumnHeaders.js +3 -1
  4. package/components/GridPagination.d.ts +2 -2
  5. package/components/GridRow.d.ts +2 -2
  6. package/components/GridRow.js +33 -79
  7. package/components/cell/GridCell.d.ts +24 -15
  8. package/components/cell/GridCell.js +422 -45
  9. package/components/cell/GridEditInputCell.js +9 -9
  10. package/components/cell/index.d.ts +2 -1
  11. package/components/cell/index.js +1 -1
  12. package/components/containers/GridRootStyles.js +30 -16
  13. package/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
  14. package/components/panel/GridPanel.d.ts +1 -1
  15. package/components/toolbar/GridToolbar.js +2 -2
  16. package/components/virtualization/GridVirtualScroller.js +4 -9
  17. package/components/virtualization/GridVirtualScrollerContent.js +11 -20
  18. package/constants/defaultGridSlotsComponents.js +6 -2
  19. package/hooks/core/useGridApiInitialization.js +4 -1
  20. package/hooks/core/useGridStateInitialization.js +2 -9
  21. package/hooks/features/clipboard/useGridClipboard.js +1 -4
  22. package/hooks/features/columnGrouping/gridColumnGroupsSelector.js +4 -4
  23. package/hooks/features/columnHeaders/useGridColumnHeaders.js +9 -3
  24. package/hooks/features/columns/gridColumnsSelector.js +7 -7
  25. package/hooks/features/dimensions/useGridDimensions.js +6 -12
  26. package/hooks/features/editing/useGridCellEditing.js +5 -3
  27. package/hooks/features/editing/useGridRowEditing.js +14 -6
  28. package/hooks/features/filter/gridFilterSelector.js +8 -8
  29. package/hooks/features/filter/gridFilterUtils.d.ts +4 -1
  30. package/hooks/features/filter/gridFilterUtils.js +19 -13
  31. package/hooks/features/filter/useGridFilter.js +2 -1
  32. package/hooks/features/focus/useGridFocus.js +9 -4
  33. package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +2 -3
  34. package/hooks/features/pagination/gridPaginationSelector.js +4 -4
  35. package/hooks/features/rowSelection/gridRowSelectionSelector.js +3 -3
  36. package/hooks/features/rows/gridRowsSelector.js +3 -3
  37. package/hooks/features/rows/useGridParamsApi.d.ts +2 -0
  38. package/hooks/features/rows/useGridParamsApi.js +7 -15
  39. package/hooks/features/sorting/gridSortingSelector.js +3 -3
  40. package/hooks/features/virtualization/useGridVirtualScroller.d.ts +8 -816
  41. package/hooks/features/virtualization/useGridVirtualScroller.js +40 -38
  42. package/hooks/utils/index.d.ts +1 -1
  43. package/hooks/utils/index.js +1 -1
  44. package/hooks/utils/useGridSelector.d.ts +3 -1
  45. package/hooks/utils/useGridSelector.js +37 -6
  46. package/hooks/utils/useLazyRef.d.ts +2 -0
  47. package/hooks/utils/useLazyRef.js +9 -0
  48. package/hooks/utils/useOnMount.d.ts +2 -0
  49. package/hooks/utils/useOnMount.js +7 -0
  50. package/index.js +1 -1
  51. package/internals/index.d.ts +1 -1
  52. package/internals/index.js +1 -1
  53. package/legacy/components/GridColumnHeaders.js +3 -1
  54. package/legacy/components/GridRow.js +35 -79
  55. package/legacy/components/cell/GridCell.js +425 -46
  56. package/legacy/components/cell/GridEditInputCell.js +9 -9
  57. package/legacy/components/cell/index.js +1 -1
  58. package/legacy/components/containers/GridRootStyles.js +20 -17
  59. package/legacy/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
  60. package/legacy/components/toolbar/GridToolbar.js +2 -2
  61. package/legacy/components/virtualization/GridVirtualScroller.js +4 -7
  62. package/legacy/components/virtualization/GridVirtualScrollerContent.js +10 -17
  63. package/legacy/constants/defaultGridSlotsComponents.js +6 -2
  64. package/legacy/hooks/core/useGridApiInitialization.js +4 -1
  65. package/legacy/hooks/core/useGridStateInitialization.js +2 -7
  66. package/legacy/hooks/features/clipboard/useGridClipboard.js +1 -4
  67. package/legacy/hooks/features/columnGrouping/gridColumnGroupsSelector.js +4 -4
  68. package/legacy/hooks/features/columnHeaders/useGridColumnHeaders.js +9 -3
  69. package/legacy/hooks/features/columns/gridColumnsSelector.js +7 -7
  70. package/legacy/hooks/features/dimensions/useGridDimensions.js +6 -12
  71. package/legacy/hooks/features/editing/useGridCellEditing.js +5 -3
  72. package/legacy/hooks/features/editing/useGridRowEditing.js +15 -7
  73. package/legacy/hooks/features/filter/gridFilterSelector.js +8 -8
  74. package/legacy/hooks/features/filter/gridFilterUtils.js +23 -19
  75. package/legacy/hooks/features/filter/useGridFilter.js +2 -1
  76. package/legacy/hooks/features/focus/useGridFocus.js +9 -4
  77. package/legacy/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +2 -3
  78. package/legacy/hooks/features/pagination/gridPaginationSelector.js +4 -4
  79. package/legacy/hooks/features/rowSelection/gridRowSelectionSelector.js +3 -3
  80. package/legacy/hooks/features/rows/gridRowsSelector.js +3 -3
  81. package/legacy/hooks/features/rows/useGridParamsApi.js +23 -15
  82. package/legacy/hooks/features/sorting/gridSortingSelector.js +3 -3
  83. package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +38 -34
  84. package/legacy/hooks/utils/index.js +1 -1
  85. package/legacy/hooks/utils/useGridSelector.js +43 -5
  86. package/legacy/hooks/utils/useLazyRef.js +9 -0
  87. package/legacy/hooks/utils/useOnMount.js +7 -0
  88. package/legacy/index.js +1 -1
  89. package/legacy/internals/index.js +1 -1
  90. package/legacy/locales/elGR.js +70 -79
  91. package/legacy/locales/ptBR.js +12 -13
  92. package/legacy/utils/Store.js +34 -0
  93. package/legacy/utils/createSelector.js +74 -6
  94. package/legacy/utils/doesSupportPreventScroll.js +13 -0
  95. package/legacy/utils/fastMemo.js +5 -0
  96. package/legacy/utils/fastObjectShallowCompare.js +32 -0
  97. package/legacy/utils/keyboardUtils.js +4 -2
  98. package/locales/elGR.js +66 -79
  99. package/locales/ptBR.js +12 -13
  100. package/models/api/gridCoreApi.d.ts +6 -0
  101. package/models/colDef/gridColDef.d.ts +4 -3
  102. package/models/colDef/gridColType.d.ts +3 -1
  103. package/models/events/gridEventLookup.d.ts +3 -3
  104. package/modern/components/GridColumnHeaders.js +3 -1
  105. package/modern/components/GridRow.js +32 -79
  106. package/modern/components/cell/GridCell.js +421 -45
  107. package/modern/components/cell/GridEditInputCell.js +9 -9
  108. package/modern/components/cell/index.js +1 -1
  109. package/modern/components/containers/GridRootStyles.js +30 -16
  110. package/modern/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
  111. package/modern/components/toolbar/GridToolbar.js +2 -2
  112. package/modern/components/virtualization/GridVirtualScroller.js +4 -9
  113. package/modern/components/virtualization/GridVirtualScrollerContent.js +10 -20
  114. package/modern/constants/defaultGridSlotsComponents.js +6 -2
  115. package/modern/hooks/core/useGridApiInitialization.js +4 -1
  116. package/modern/hooks/core/useGridStateInitialization.js +2 -9
  117. package/modern/hooks/features/clipboard/useGridClipboard.js +1 -4
  118. package/modern/hooks/features/columnGrouping/gridColumnGroupsSelector.js +4 -4
  119. package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +9 -3
  120. package/modern/hooks/features/columns/gridColumnsSelector.js +7 -7
  121. package/modern/hooks/features/dimensions/useGridDimensions.js +6 -12
  122. package/modern/hooks/features/editing/useGridCellEditing.js +5 -3
  123. package/modern/hooks/features/editing/useGridRowEditing.js +14 -6
  124. package/modern/hooks/features/filter/gridFilterSelector.js +8 -8
  125. package/modern/hooks/features/filter/gridFilterUtils.js +17 -12
  126. package/modern/hooks/features/filter/useGridFilter.js +2 -1
  127. package/modern/hooks/features/focus/useGridFocus.js +8 -4
  128. package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +2 -3
  129. package/modern/hooks/features/pagination/gridPaginationSelector.js +4 -4
  130. package/modern/hooks/features/rowSelection/gridRowSelectionSelector.js +3 -3
  131. package/modern/hooks/features/rows/gridRowsSelector.js +3 -3
  132. package/modern/hooks/features/rows/useGridParamsApi.js +7 -15
  133. package/modern/hooks/features/sorting/gridSortingSelector.js +3 -3
  134. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +40 -38
  135. package/modern/hooks/utils/index.js +1 -1
  136. package/modern/hooks/utils/useGridSelector.js +37 -6
  137. package/modern/hooks/utils/useLazyRef.js +9 -0
  138. package/modern/hooks/utils/useOnMount.js +7 -0
  139. package/modern/index.js +1 -1
  140. package/modern/internals/index.js +1 -1
  141. package/modern/locales/elGR.js +66 -79
  142. package/modern/locales/ptBR.js +12 -13
  143. package/modern/utils/Store.js +24 -0
  144. package/modern/utils/createSelector.js +74 -6
  145. package/modern/utils/doesSupportPreventScroll.js +13 -0
  146. package/modern/utils/fastMemo.js +5 -0
  147. package/modern/utils/fastObjectShallowCompare.js +32 -0
  148. package/modern/utils/keyboardUtils.js +4 -2
  149. package/node/components/GridColumnHeaders.js +4 -2
  150. package/node/components/GridRow.js +32 -79
  151. package/node/components/cell/GridCell.js +424 -47
  152. package/node/components/cell/GridEditInputCell.js +9 -9
  153. package/node/components/cell/index.js +17 -10
  154. package/node/components/containers/GridRootStyles.js +30 -16
  155. package/node/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
  156. package/node/components/toolbar/GridToolbar.js +2 -2
  157. package/node/components/virtualization/GridVirtualScroller.js +4 -9
  158. package/node/components/virtualization/GridVirtualScrollerContent.js +10 -20
  159. package/node/constants/defaultGridSlotsComponents.js +4 -1
  160. package/node/hooks/core/useGridApiInitialization.js +4 -1
  161. package/node/hooks/core/useGridStateInitialization.js +2 -9
  162. package/node/hooks/features/clipboard/useGridClipboard.js +1 -4
  163. package/node/hooks/features/columnGrouping/gridColumnGroupsSelector.js +3 -3
  164. package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +8 -2
  165. package/node/hooks/features/columns/gridColumnsSelector.js +6 -6
  166. package/node/hooks/features/dimensions/useGridDimensions.js +6 -12
  167. package/node/hooks/features/editing/useGridCellEditing.js +5 -3
  168. package/node/hooks/features/editing/useGridRowEditing.js +14 -6
  169. package/node/hooks/features/filter/gridFilterSelector.js +7 -7
  170. package/node/hooks/features/filter/gridFilterUtils.js +17 -12
  171. package/node/hooks/features/filter/useGridFilter.js +2 -1
  172. package/node/hooks/features/focus/useGridFocus.js +8 -4
  173. package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +2 -3
  174. package/node/hooks/features/pagination/gridPaginationSelector.js +3 -3
  175. package/node/hooks/features/rowSelection/gridRowSelectionSelector.js +2 -2
  176. package/node/hooks/features/rows/gridRowsSelector.js +2 -2
  177. package/node/hooks/features/rows/useGridParamsApi.js +9 -15
  178. package/node/hooks/features/sorting/gridSortingSelector.js +2 -2
  179. package/node/hooks/features/virtualization/useGridVirtualScroller.js +40 -36
  180. package/node/hooks/utils/index.js +14 -10
  181. package/node/hooks/utils/useGridSelector.js +41 -7
  182. package/node/hooks/utils/useLazyRef.js +17 -0
  183. package/node/hooks/utils/useOnMount.js +15 -0
  184. package/node/index.js +1 -1
  185. package/node/internals/index.js +7 -0
  186. package/node/locales/elGR.js +66 -79
  187. package/node/locales/ptBR.js +12 -13
  188. package/node/utils/Store.js +31 -0
  189. package/node/utils/createSelector.js +77 -8
  190. package/node/utils/doesSupportPreventScroll.js +19 -0
  191. package/node/utils/fastMemo.js +13 -0
  192. package/node/utils/fastObjectShallowCompare.js +38 -0
  193. package/node/utils/keyboardUtils.js +4 -2
  194. package/package.json +2 -2
  195. package/utils/Store.d.ts +11 -0
  196. package/utils/Store.js +24 -0
  197. package/utils/createSelector.d.ts +1 -0
  198. package/utils/createSelector.js +74 -6
  199. package/utils/doesSupportPreventScroll.d.ts +1 -0
  200. package/utils/doesSupportPreventScroll.js +13 -0
  201. package/utils/fastMemo.d.ts +1 -0
  202. package/utils/fastMemo.js +5 -0
  203. package/utils/fastObjectShallowCompare.d.ts +1 -0
  204. package/utils/fastObjectShallowCompare.js +32 -0
  205. package/utils/keyboardUtils.js +4 -2
@@ -1,30 +1,48 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["align", "children", "colIndex", "colDef", "cellMode", "field", "formattedValue", "hasFocus", "height", "isEditable", "isSelected", "rowId", "tabIndex", "value", "width", "className", "showRightBorder", "extendRowFullWidth", "row", "colSpan", "disableDragEvents", "onClick", "onDoubleClick", "onMouseDown", "onMouseUp", "onMouseOver", "onKeyDown", "onKeyUp", "onDragEnter", "onDragOver"];
3
+ var _excluded = ["changeReason", "unstable_updateValueOnRender"],
4
+ _excluded2 = ["align", "children", "colIndex", "column", "cellMode", "field", "formattedValue", "hasFocus", "height", "isEditable", "isSelected", "rowId", "tabIndex", "value", "width", "className", "showRightBorder", "extendRowFullWidth", "row", "colSpan", "disableDragEvents", "onClick", "onDoubleClick", "onMouseDown", "onMouseUp", "onMouseOver", "onKeyDown", "onKeyUp", "onDragEnter", "onDragOver"],
5
+ _excluded3 = ["column", "rowId", "editCellState", "align", "children", "colIndex", "height", "width", "className", "showRightBorder", "extendRowFullWidth", "row", "colSpan", "disableDragEvents", "onClick", "onDoubleClick", "onMouseDown", "onMouseUp", "onMouseOver", "onKeyDown", "onKeyUp", "onDragEnter", "onDragOver"],
6
+ _excluded4 = ["changeReason", "unstable_updateValueOnRender"];
4
7
  /* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
5
8
  import * as React from 'react';
6
9
  import PropTypes from 'prop-types';
7
10
  import clsx from 'clsx';
8
11
  import { unstable_useForkRef as useForkRef, unstable_composeClasses as composeClasses, unstable_ownerDocument as ownerDocument, unstable_capitalize as capitalize } from '@mui/utils';
9
- import { getDataGridUtilityClass } from '../../constants/gridClasses';
12
+ import { fastMemo } from '../../utils/fastMemo';
13
+ import { doesSupportPreventScroll } from '../../utils/doesSupportPreventScroll';
14
+ import { getDataGridUtilityClass, gridClasses } from '../../constants/gridClasses';
10
15
  import { GridCellModes } from '../../models';
16
+ import { useGridSelector, objectShallowCompare } from '../../hooks/utils/useGridSelector';
11
17
  import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
12
18
  import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
13
19
  import { gridFocusCellSelector } from '../../hooks/features/focus/gridFocusStateSelector';
20
+ import { MissingRowIdError } from '../../hooks/features/rows/useGridParamsApi';
14
21
  import { jsx as _jsx } from "react/jsx-runtime";
15
- // Based on https://stackoverflow.com/a/59518678
16
- var cachedSupportsPreventScroll;
17
- function doesSupportPreventScroll() {
18
- if (cachedSupportsPreventScroll === undefined) {
19
- document.createElement('div').focus({
20
- get preventScroll() {
21
- cachedSupportsPreventScroll = true;
22
- return false;
23
- }
24
- });
25
- }
26
- return cachedSupportsPreventScroll;
27
- }
22
+ var EMPTY_CELL_PARAMS = {
23
+ id: -1,
24
+ field: '__unset__',
25
+ row: {},
26
+ rowNode: {
27
+ id: -1,
28
+ depth: 0,
29
+ type: 'leaf',
30
+ parent: -1,
31
+ groupingKey: null
32
+ },
33
+ colDef: {
34
+ type: 'string',
35
+ field: '__unset__',
36
+ computedWidth: 0
37
+ },
38
+ cellMode: GridCellModes.View,
39
+ hasFocus: false,
40
+ tabIndex: -1,
41
+ value: null,
42
+ formattedValue: '__unset__',
43
+ isEditable: false,
44
+ api: {}
45
+ };
28
46
  var useUtilityClasses = function useUtilityClasses(ownerState) {
29
47
  var align = ownerState.align,
30
48
  showRightBorder = ownerState.showRightBorder,
@@ -38,12 +56,105 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
38
56
  return composeClasses(slots, getDataGridUtilityClass, classes);
39
57
  };
40
58
  var warnedOnce = false;
59
+
60
+ // GridCellWrapper is a compatibility layer for the V6 cell slot. If we can use the more efficient
61
+ // `GridCellV7`, we should. That component is a merge of `GridCellWrapper` and `GridCell`.
62
+ // TODO(v7): Remove the wrapper & cellV6 and use the cellV7 exclusively.
63
+ // TODO(v7): Removing the wrapper will break the docs performance visualization demo.
64
+ var GridCellWrapper = /*#__PURE__*/React.forwardRef(function (props, ref) {
65
+ var column = props.column,
66
+ rowId = props.rowId,
67
+ editCellState = props.editCellState;
68
+ var apiRef = useGridApiContext();
69
+ var rootProps = useGridRootProps();
70
+ var field = column.field;
71
+ var cellParamsWithAPI = useGridSelector(apiRef, function () {
72
+ // This is required because `.getCellParams` tries to get the `state.rows.tree` entry
73
+ // associated with `rowId`/`fieldId`, but this selector runs after the state has been
74
+ // updated, while `rowId`/`fieldId` reference an entry in the old state.
75
+ try {
76
+ var cellParams = apiRef.current.getCellParams(rowId, field);
77
+ var result = cellParams;
78
+ result.api = apiRef.current;
79
+ return result;
80
+ } catch (e) {
81
+ if (e instanceof MissingRowIdError) {
82
+ return EMPTY_CELL_PARAMS;
83
+ }
84
+ throw e;
85
+ }
86
+ }, objectShallowCompare);
87
+ var isSelected = useGridSelector(apiRef, function () {
88
+ return apiRef.current.unstable_applyPipeProcessors('isCellSelected', false, {
89
+ id: rowId,
90
+ field: field
91
+ });
92
+ });
93
+ if (cellParamsWithAPI === EMPTY_CELL_PARAMS) {
94
+ return null;
95
+ }
96
+ var cellMode = cellParamsWithAPI.cellMode,
97
+ hasFocus = cellParamsWithAPI.hasFocus,
98
+ isEditable = cellParamsWithAPI.isEditable,
99
+ value = cellParamsWithAPI.value,
100
+ formattedValue = cellParamsWithAPI.formattedValue;
101
+ var managesOwnFocus = column.type === 'actions';
102
+ var tabIndex = (cellMode === 'view' || !isEditable) && !managesOwnFocus ? cellParamsWithAPI.tabIndex : -1;
103
+ var rootClasses = rootProps.classes,
104
+ getCellClassName = rootProps.getCellClassName;
105
+ var classNames = apiRef.current.unstable_applyPipeProcessors('cellClassName', [], {
106
+ id: rowId,
107
+ field: field
108
+ });
109
+ if (column.cellClassName) {
110
+ classNames.push(typeof column.cellClassName === 'function' ? column.cellClassName(cellParamsWithAPI) : column.cellClassName);
111
+ }
112
+ if (getCellClassName) {
113
+ classNames.push(getCellClassName(cellParamsWithAPI));
114
+ }
115
+ var children;
116
+ if (editCellState == null && column.renderCell) {
117
+ children = column.renderCell(cellParamsWithAPI);
118
+ classNames.push(gridClasses['cell--withRenderer']);
119
+ classNames.push(rootClasses == null ? void 0 : rootClasses['cell--withRenderer']);
120
+ }
121
+ if (editCellState != null && column.renderEditCell) {
122
+ var updatedRow = apiRef.current.getRowWithUpdatedValues(rowId, column.field);
123
+
124
+ // eslint-disable-next-line @typescript-eslint/naming-convention
125
+ var changeReason = editCellState.changeReason,
126
+ unstable_updateValueOnRender = editCellState.unstable_updateValueOnRender,
127
+ editCellStateRest = _objectWithoutProperties(editCellState, _excluded);
128
+ var params = _extends({}, cellParamsWithAPI, {
129
+ row: updatedRow
130
+ }, editCellStateRest);
131
+ children = column.renderEditCell(params);
132
+ classNames.push(gridClasses['cell--editing']);
133
+ classNames.push(rootClasses == null ? void 0 : rootClasses['cell--editing']);
134
+ }
135
+ var slots = rootProps.slots;
136
+ var CellComponent = slots.cell;
137
+ var cellProps = _extends({}, props, {
138
+ ref: ref,
139
+ field: field,
140
+ formattedValue: formattedValue,
141
+ hasFocus: hasFocus,
142
+ isEditable: isEditable,
143
+ isSelected: isSelected,
144
+ value: value,
145
+ cellMode: cellMode,
146
+ children: children,
147
+ tabIndex: tabIndex,
148
+ className: clsx(classNames)
149
+ });
150
+ return /*#__PURE__*/React.createElement(CellComponent, cellProps);
151
+ });
41
152
  var GridCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
42
153
  var _rootProps$experiment;
43
154
  var align = props.align,
44
- children = props.children,
155
+ childrenProp = props.children,
45
156
  colIndex = props.colIndex,
46
- colDef = props.colDef,
157
+ column = props.column,
47
158
  cellMode = props.cellMode,
48
159
  field = props.field,
49
160
  formattedValue = props.formattedValue,
@@ -70,7 +181,7 @@ var GridCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
70
181
  onKeyUp = props.onKeyUp,
71
182
  onDragEnter = props.onDragEnter,
72
183
  onDragOver = props.onDragOver,
73
- other = _objectWithoutProperties(props, _excluded);
184
+ other = _objectWithoutProperties(props, _excluded2);
74
185
  var valueToRender = formattedValue == null ? value : formattedValue;
75
186
  var cellRef = React.useRef(null);
76
187
  var handleRef = useForkRef(ref, cellRef);
@@ -158,24 +269,21 @@ var GridCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
158
269
  }
159
270
  };
160
271
  }
161
- var column = apiRef.current.getColumn(field);
162
272
  var managesOwnFocus = column.type === 'actions';
163
- var renderChildren = function renderChildren() {
164
- if (children === undefined) {
165
- var valueString = valueToRender == null ? void 0 : valueToRender.toString();
166
- return /*#__PURE__*/_jsx("div", {
167
- className: classes.content,
168
- title: valueString,
169
- children: valueString
170
- });
171
- }
172
- if ( /*#__PURE__*/React.isValidElement(children) && managesOwnFocus) {
173
- return /*#__PURE__*/React.cloneElement(children, {
174
- focusElementRef: focusElementRef
175
- });
176
- }
177
- return children;
178
- };
273
+ var children = childrenProp;
274
+ if (children === undefined) {
275
+ var valueString = valueToRender == null ? void 0 : valueToRender.toString();
276
+ children = /*#__PURE__*/_jsx("div", {
277
+ className: classes.content,
278
+ title: valueString,
279
+ children: valueString
280
+ });
281
+ }
282
+ if ( /*#__PURE__*/React.isValidElement(children) && managesOwnFocus) {
283
+ children = /*#__PURE__*/React.cloneElement(children, {
284
+ focusElementRef: focusElementRef
285
+ });
286
+ }
179
287
  var draggableEventHandlers = disableDragEvents ? null : {
180
288
  onDragEnter: publish('cellDragEnter', onDragEnter),
181
289
  onDragOver: publish('cellDragOver', onDragOver)
@@ -189,7 +297,7 @@ var GridCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
189
297
  "aria-colindex": colIndex + 1,
190
298
  "aria-colspan": colSpan,
191
299
  style: style,
192
- tabIndex: (cellMode === 'view' || !isEditable) && !managesOwnFocus ? tabIndex : -1,
300
+ tabIndex: tabIndex,
193
301
  onClick: publish('cellClick', onClick),
194
302
  onDoubleClick: publish('cellDoubleClick', onDoubleClick),
195
303
  onMouseOver: publish('cellMouseOver', onMouseOver),
@@ -199,10 +307,33 @@ var GridCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
199
307
  onKeyUp: publish('cellKeyUp', onKeyUp)
200
308
  }, draggableEventHandlers, other, {
201
309
  onFocus: handleFocus,
202
- children: renderChildren()
310
+ children: children
203
311
  }));
204
312
  });
205
- var MemoizedCell = /*#__PURE__*/React.memo(GridCell);
313
+ var MemoizedCellWrapper = fastMemo(GridCellWrapper);
314
+ process.env.NODE_ENV !== "production" ? GridCellWrapper.propTypes = {
315
+ // ----------------------------- Warning --------------------------------
316
+ // | These PropTypes are generated from the TypeScript type definitions |
317
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
318
+ // ----------------------------------------------------------------------
319
+ align: PropTypes.oneOf(['center', 'left', 'right']),
320
+ className: PropTypes.string,
321
+ colIndex: PropTypes.number,
322
+ colSpan: PropTypes.number,
323
+ column: PropTypes.object,
324
+ disableDragEvents: PropTypes.bool,
325
+ height: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
326
+ onClick: PropTypes.func,
327
+ onDoubleClick: PropTypes.func,
328
+ onDragEnter: PropTypes.func,
329
+ onDragOver: PropTypes.func,
330
+ onKeyDown: PropTypes.func,
331
+ onMouseDown: PropTypes.func,
332
+ onMouseUp: PropTypes.func,
333
+ rowId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
334
+ showRightBorder: PropTypes.bool,
335
+ width: PropTypes.number
336
+ } : void 0;
206
337
  process.env.NODE_ENV !== "production" ? GridCell.propTypes = {
207
338
  // ----------------------------- Warning --------------------------------
208
339
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -214,13 +345,15 @@ process.env.NODE_ENV !== "production" ? GridCell.propTypes = {
214
345
  className: PropTypes.string,
215
346
  colIndex: PropTypes.number,
216
347
  colSpan: PropTypes.number,
348
+ column: PropTypes.object,
217
349
  disableDragEvents: PropTypes.bool,
218
- field: PropTypes.string,
219
- formattedValue: PropTypes.any,
220
- hasFocus: PropTypes.bool,
350
+ editCellState: PropTypes.shape({
351
+ changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
352
+ isProcessingProps: PropTypes.bool,
353
+ isValidating: PropTypes.bool,
354
+ value: PropTypes.any
355
+ }),
221
356
  height: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
222
- isEditable: PropTypes.bool,
223
- isSelected: PropTypes.bool,
224
357
  onClick: PropTypes.func,
225
358
  onDoubleClick: PropTypes.func,
226
359
  onDragEnter: PropTypes.func,
@@ -230,8 +363,254 @@ process.env.NODE_ENV !== "production" ? GridCell.propTypes = {
230
363
  onMouseUp: PropTypes.func,
231
364
  rowId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
232
365
  showRightBorder: PropTypes.bool,
233
- tabIndex: PropTypes.oneOf([-1, 0]),
234
- value: PropTypes.any,
235
366
  width: PropTypes.number
236
367
  } : void 0;
237
- export { MemoizedCell as GridCell };
368
+ export { MemoizedCellWrapper as GridCellWrapper, GridCell };
369
+ var GridCellV7 = /*#__PURE__*/React.forwardRef(function (props, ref) {
370
+ var _rootProps$experiment2;
371
+ var column = props.column,
372
+ rowId = props.rowId,
373
+ editCellState = props.editCellState,
374
+ align = props.align,
375
+ childrenProp = props.children,
376
+ colIndex = props.colIndex,
377
+ height = props.height,
378
+ width = props.width,
379
+ className = props.className,
380
+ showRightBorder = props.showRightBorder,
381
+ extendRowFullWidth = props.extendRowFullWidth,
382
+ row = props.row,
383
+ colSpan = props.colSpan,
384
+ disableDragEvents = props.disableDragEvents,
385
+ onClick = props.onClick,
386
+ onDoubleClick = props.onDoubleClick,
387
+ onMouseDown = props.onMouseDown,
388
+ onMouseUp = props.onMouseUp,
389
+ onMouseOver = props.onMouseOver,
390
+ onKeyDown = props.onKeyDown,
391
+ onKeyUp = props.onKeyUp,
392
+ onDragEnter = props.onDragEnter,
393
+ onDragOver = props.onDragOver,
394
+ other = _objectWithoutProperties(props, _excluded3);
395
+ var apiRef = useGridApiContext();
396
+ var rootProps = useGridRootProps();
397
+ var field = column.field;
398
+ var cellParamsWithAPI = useGridSelector(apiRef, function () {
399
+ // This is required because `.getCellParams` tries to get the `state.rows.tree` entry
400
+ // associated with `rowId`/`fieldId`, but this selector runs after the state has been
401
+ // updated, while `rowId`/`fieldId` reference an entry in the old state.
402
+ try {
403
+ var cellParams = apiRef.current.getCellParams(rowId, field);
404
+ var result = cellParams;
405
+ result.api = apiRef.current;
406
+ return result;
407
+ } catch (e) {
408
+ if (e instanceof MissingRowIdError) {
409
+ return EMPTY_CELL_PARAMS;
410
+ }
411
+ throw e;
412
+ }
413
+ }, objectShallowCompare);
414
+ var isSelected = useGridSelector(apiRef, function () {
415
+ return apiRef.current.unstable_applyPipeProcessors('isCellSelected', false, {
416
+ id: rowId,
417
+ field: field
418
+ });
419
+ });
420
+ var cellMode = cellParamsWithAPI.cellMode,
421
+ hasFocus = cellParamsWithAPI.hasFocus,
422
+ isEditable = cellParamsWithAPI.isEditable,
423
+ value = cellParamsWithAPI.value,
424
+ formattedValue = cellParamsWithAPI.formattedValue;
425
+ var managesOwnFocus = column.type === 'actions';
426
+ var tabIndex = (cellMode === 'view' || !isEditable) && !managesOwnFocus ? cellParamsWithAPI.tabIndex : -1;
427
+ var rootClasses = rootProps.classes,
428
+ getCellClassName = rootProps.getCellClassName;
429
+ var classNames = apiRef.current.unstable_applyPipeProcessors('cellClassName', [], {
430
+ id: rowId,
431
+ field: field
432
+ });
433
+ if (column.cellClassName) {
434
+ classNames.push(typeof column.cellClassName === 'function' ? column.cellClassName(cellParamsWithAPI) : column.cellClassName);
435
+ }
436
+ if (getCellClassName) {
437
+ classNames.push(getCellClassName(cellParamsWithAPI));
438
+ }
439
+ var valueToRender = formattedValue == null ? value : formattedValue;
440
+ var cellRef = React.useRef(null);
441
+ var handleRef = useForkRef(ref, cellRef);
442
+ var focusElementRef = React.useRef(null);
443
+ var ownerState = {
444
+ align: align,
445
+ showRightBorder: showRightBorder,
446
+ isEditable: isEditable,
447
+ classes: rootProps.classes,
448
+ isSelected: isSelected
449
+ };
450
+ var classes = useUtilityClasses(ownerState);
451
+ var publishMouseUp = React.useCallback(function (eventName) {
452
+ return function (event) {
453
+ var params = apiRef.current.getCellParams(rowId, field || '');
454
+ apiRef.current.publishEvent(eventName, params, event);
455
+ if (onMouseUp) {
456
+ onMouseUp(event);
457
+ }
458
+ };
459
+ }, [apiRef, field, onMouseUp, rowId]);
460
+ var publishMouseDown = React.useCallback(function (eventName) {
461
+ return function (event) {
462
+ var params = apiRef.current.getCellParams(rowId, field || '');
463
+ apiRef.current.publishEvent(eventName, params, event);
464
+ if (onMouseDown) {
465
+ onMouseDown(event);
466
+ }
467
+ };
468
+ }, [apiRef, field, onMouseDown, rowId]);
469
+ var publish = React.useCallback(function (eventName, propHandler) {
470
+ return function (event) {
471
+ // The row might have been deleted during the click
472
+ if (!apiRef.current.getRow(rowId)) {
473
+ return;
474
+ }
475
+ var params = apiRef.current.getCellParams(rowId, field || '');
476
+ apiRef.current.publishEvent(eventName, params, event);
477
+ if (propHandler) {
478
+ propHandler(event);
479
+ }
480
+ };
481
+ }, [apiRef, field, rowId]);
482
+ var style = {
483
+ minWidth: width,
484
+ maxWidth: width,
485
+ minHeight: height,
486
+ maxHeight: height === 'auto' ? 'none' : height // max-height doesn't support "auto"
487
+ };
488
+
489
+ React.useEffect(function () {
490
+ if (!hasFocus || cellMode === GridCellModes.Edit) {
491
+ return;
492
+ }
493
+ var doc = ownerDocument(apiRef.current.rootElementRef.current);
494
+ if (cellRef.current && !cellRef.current.contains(doc.activeElement)) {
495
+ var focusableElement = cellRef.current.querySelector('[tabindex="0"]');
496
+ var elementToFocus = focusElementRef.current || focusableElement || cellRef.current;
497
+ if (doesSupportPreventScroll()) {
498
+ elementToFocus.focus({
499
+ preventScroll: true
500
+ });
501
+ } else {
502
+ var scrollPosition = apiRef.current.getScrollPosition();
503
+ elementToFocus.focus();
504
+ apiRef.current.scroll(scrollPosition);
505
+ }
506
+ }
507
+ }, [hasFocus, cellMode, apiRef]);
508
+ if (cellParamsWithAPI === EMPTY_CELL_PARAMS) {
509
+ return null;
510
+ }
511
+ var handleFocus = other.onFocus;
512
+ if (process.env.NODE_ENV === 'test' && (_rootProps$experiment2 = rootProps.experimentalFeatures) != null && _rootProps$experiment2.warnIfFocusStateIsNotSynced) {
513
+ handleFocus = function handleFocus(event) {
514
+ var focusedCell = gridFocusCellSelector(apiRef);
515
+ if ((focusedCell == null ? void 0 : focusedCell.id) === rowId && focusedCell.field === field) {
516
+ if (typeof other.onFocus === 'function') {
517
+ other.onFocus(event);
518
+ }
519
+ return;
520
+ }
521
+ if (!warnedOnce) {
522
+ console.warn(["MUI: The cell with id=".concat(rowId, " and field=").concat(field, " received focus."), "According to the state, the focus should be at id=".concat(focusedCell == null ? void 0 : focusedCell.id, ", field=").concat(focusedCell == null ? void 0 : focusedCell.field, "."), "Not syncing the state may cause unwanted behaviors since the `cellFocusIn` event won't be fired.", 'Call `fireEvent.mouseUp` before the `fireEvent.click` to sync the focus with the state.'].join('\n'));
523
+ warnedOnce = true;
524
+ }
525
+ };
526
+ }
527
+ var children;
528
+ if (editCellState == null && column.renderCell) {
529
+ children = column.renderCell(cellParamsWithAPI);
530
+ classNames.push(gridClasses['cell--withRenderer']);
531
+ classNames.push(rootClasses == null ? void 0 : rootClasses['cell--withRenderer']);
532
+ }
533
+ if (editCellState != null && column.renderEditCell) {
534
+ var updatedRow = apiRef.current.getRowWithUpdatedValues(rowId, column.field);
535
+
536
+ // eslint-disable-next-line @typescript-eslint/naming-convention
537
+ var changeReason = editCellState.changeReason,
538
+ unstable_updateValueOnRender = editCellState.unstable_updateValueOnRender,
539
+ editCellStateRest = _objectWithoutProperties(editCellState, _excluded4);
540
+ var params = _extends({}, cellParamsWithAPI, {
541
+ row: updatedRow
542
+ }, editCellStateRest);
543
+ children = column.renderEditCell(params);
544
+ classNames.push(gridClasses['cell--editing']);
545
+ classNames.push(rootClasses == null ? void 0 : rootClasses['cell--editing']);
546
+ }
547
+ if (children === undefined) {
548
+ var valueString = valueToRender == null ? void 0 : valueToRender.toString();
549
+ children = /*#__PURE__*/_jsx("div", {
550
+ className: classes.content,
551
+ title: valueString,
552
+ children: valueString
553
+ });
554
+ }
555
+ if ( /*#__PURE__*/React.isValidElement(children) && managesOwnFocus) {
556
+ children = /*#__PURE__*/React.cloneElement(children, {
557
+ focusElementRef: focusElementRef
558
+ });
559
+ }
560
+ var draggableEventHandlers = disableDragEvents ? null : {
561
+ onDragEnter: publish('cellDragEnter', onDragEnter),
562
+ onDragOver: publish('cellDragOver', onDragOver)
563
+ };
564
+ return /*#__PURE__*/_jsx("div", _extends({
565
+ ref: handleRef,
566
+ className: clsx(className, classNames, classes.root),
567
+ role: "cell",
568
+ "data-field": field,
569
+ "data-colindex": colIndex,
570
+ "aria-colindex": colIndex + 1,
571
+ "aria-colspan": colSpan,
572
+ style: style,
573
+ tabIndex: tabIndex,
574
+ onClick: publish('cellClick', onClick),
575
+ onDoubleClick: publish('cellDoubleClick', onDoubleClick),
576
+ onMouseOver: publish('cellMouseOver', onMouseOver),
577
+ onMouseDown: publishMouseDown('cellMouseDown'),
578
+ onMouseUp: publishMouseUp('cellMouseUp'),
579
+ onKeyDown: publish('cellKeyDown', onKeyDown),
580
+ onKeyUp: publish('cellKeyUp', onKeyUp)
581
+ }, draggableEventHandlers, other, {
582
+ onFocus: handleFocus,
583
+ children: children
584
+ }));
585
+ });
586
+ process.env.NODE_ENV !== "production" ? GridCellV7.propTypes = {
587
+ // ----------------------------- Warning --------------------------------
588
+ // | These PropTypes are generated from the TypeScript type definitions |
589
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
590
+ // ----------------------------------------------------------------------
591
+ align: PropTypes.oneOf(['center', 'left', 'right']).isRequired,
592
+ className: PropTypes.string,
593
+ colIndex: PropTypes.number.isRequired,
594
+ colSpan: PropTypes.number,
595
+ column: PropTypes.object.isRequired,
596
+ disableDragEvents: PropTypes.bool,
597
+ editCellState: PropTypes.shape({
598
+ changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
599
+ isProcessingProps: PropTypes.bool,
600
+ isValidating: PropTypes.bool,
601
+ value: PropTypes.any
602
+ }),
603
+ height: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]).isRequired,
604
+ onClick: PropTypes.func,
605
+ onDoubleClick: PropTypes.func,
606
+ onDragEnter: PropTypes.func,
607
+ onDragOver: PropTypes.func,
608
+ onKeyDown: PropTypes.func,
609
+ onMouseDown: PropTypes.func,
610
+ onMouseUp: PropTypes.func,
611
+ rowId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
612
+ showRightBorder: PropTypes.bool,
613
+ width: PropTypes.number.isRequired
614
+ } : void 0;
615
+ var MemoizedGridCellV7 = fastMemo(GridCellV7);
616
+ export { MemoizedGridCellV7 as GridCellV7 };
@@ -134,21 +134,21 @@ process.env.NODE_ENV !== "production" ? GridEditInputCell.propTypes = {
134
134
  /**
135
135
  * GridApi that let you manipulate the grid.
136
136
  */
137
- api: PropTypes.object,
137
+ api: PropTypes.object.isRequired,
138
138
  /**
139
139
  * The mode of the cell.
140
140
  */
141
- cellMode: PropTypes.oneOf(['edit', 'view']),
141
+ cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
142
142
  changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
143
143
  /**
144
144
  * The column of the row that the current cell belongs to.
145
145
  */
146
- colDef: PropTypes.object,
146
+ colDef: PropTypes.object.isRequired,
147
147
  debounceMs: PropTypes.number,
148
148
  /**
149
149
  * The column field of the cell that triggered the event.
150
150
  */
151
- field: PropTypes.string,
151
+ field: PropTypes.string.isRequired,
152
152
  /**
153
153
  * The cell value formatted with the column valueFormatter.
154
154
  */
@@ -156,11 +156,11 @@ process.env.NODE_ENV !== "production" ? GridEditInputCell.propTypes = {
156
156
  /**
157
157
  * If true, the cell is the active element.
158
158
  */
159
- hasFocus: PropTypes.bool,
159
+ hasFocus: PropTypes.bool.isRequired,
160
160
  /**
161
161
  * The grid row id.
162
162
  */
163
- id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
163
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
164
164
  /**
165
165
  * If true, the cell is editable.
166
166
  */
@@ -177,15 +177,15 @@ process.env.NODE_ENV !== "production" ? GridEditInputCell.propTypes = {
177
177
  /**
178
178
  * The row model of the row that the current cell belongs to.
179
179
  */
180
- row: PropTypes.any,
180
+ row: PropTypes.any.isRequired,
181
181
  /**
182
182
  * The node of the row that the current cell belongs to.
183
183
  */
184
- rowNode: PropTypes.object,
184
+ rowNode: PropTypes.object.isRequired,
185
185
  /**
186
186
  * the tabIndex value.
187
187
  */
188
- tabIndex: PropTypes.oneOf([-1, 0]),
188
+ tabIndex: PropTypes.oneOf([-1, 0]).isRequired,
189
189
  /**
190
190
  * The cell value.
191
191
  * If the column has `valueGetter`, use `params.row` to directly access the fields.
@@ -1,4 +1,4 @@
1
- export * from './GridCell';
1
+ export { GridCell } from './GridCell';
2
2
  export * from './GridBooleanCell';
3
3
  export * from './GridEditBooleanCell';
4
4
  export * from './GridEditDateCell';