@mui/x-data-grid 6.10.0 → 6.10.1

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 (64) hide show
  1. package/CHANGELOG.md +72 -3
  2. package/components/panel/GridPanel.js +2 -2
  3. package/components/panel/filterPanel/GridFilterForm.js +2 -2
  4. package/components/panel/filterPanel/GridFilterInputSingleSelect.js +2 -2
  5. package/hooks/features/columns/gridColumnsUtils.js +17 -7
  6. package/hooks/features/columns/useGridColumns.js +4 -4
  7. package/hooks/features/dimensions/useGridDimensions.js +1 -1
  8. package/hooks/features/editing/useGridCellEditing.js +4 -4
  9. package/hooks/features/export/serializers/csvSerializer.js +3 -5
  10. package/hooks/features/export/useGridPrintExport.js +10 -3
  11. package/hooks/features/export/utils.js +2 -2
  12. package/hooks/features/filter/gridFilterSelector.js +1 -1
  13. package/hooks/features/filter/gridFilterUtils.js +37 -10
  14. package/hooks/features/filter/useGridFilter.js +14 -9
  15. package/hooks/features/focus/useGridFocus.js +30 -1
  16. package/hooks/features/pagination/useGridPagination.js +6 -6
  17. package/hooks/features/rows/gridRowsSelector.js +3 -3
  18. package/hooks/features/rows/gridRowsUtils.js +2 -2
  19. package/hooks/features/rows/useGridRowsMeta.js +2 -2
  20. package/hooks/features/sorting/useGridSorting.js +6 -6
  21. package/hooks/features/virtualization/useGridVirtualScroller.js +1 -1
  22. package/index.js +1 -1
  23. package/joy/joySlots.js +2 -2
  24. package/legacy/components/panel/GridPanel.js +2 -2
  25. package/legacy/components/panel/filterPanel/GridFilterForm.js +2 -2
  26. package/legacy/components/panel/filterPanel/GridFilterInputSingleSelect.js +2 -2
  27. package/legacy/hooks/features/columns/gridColumnsUtils.js +17 -7
  28. package/legacy/hooks/features/columns/useGridColumns.js +4 -4
  29. package/legacy/hooks/features/dimensions/useGridDimensions.js +1 -1
  30. package/legacy/hooks/features/editing/useGridCellEditing.js +4 -4
  31. package/legacy/hooks/features/export/serializers/csvSerializer.js +4 -6
  32. package/legacy/hooks/features/export/useGridPrintExport.js +16 -4
  33. package/legacy/hooks/features/export/utils.js +2 -2
  34. package/legacy/hooks/features/filter/gridFilterSelector.js +1 -1
  35. package/legacy/hooks/features/filter/gridFilterUtils.js +30 -10
  36. package/legacy/hooks/features/filter/useGridFilter.js +14 -11
  37. package/legacy/hooks/features/focus/useGridFocus.js +32 -1
  38. package/legacy/hooks/features/pagination/useGridPagination.js +6 -6
  39. package/legacy/hooks/features/rows/gridRowsSelector.js +3 -3
  40. package/legacy/hooks/features/rows/gridRowsUtils.js +2 -2
  41. package/legacy/hooks/features/rows/useGridRowsMeta.js +2 -2
  42. package/legacy/hooks/features/sorting/useGridSorting.js +6 -6
  43. package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +1 -1
  44. package/legacy/index.js +1 -1
  45. package/legacy/joy/joySlots.js +2 -2
  46. package/legacy/utils/getGridLocalization.js +2 -2
  47. package/modern/hooks/features/columns/gridColumnsUtils.js +15 -5
  48. package/modern/hooks/features/dimensions/useGridDimensions.js +1 -1
  49. package/modern/hooks/features/export/serializers/csvSerializer.js +3 -5
  50. package/modern/hooks/features/export/useGridPrintExport.js +8 -1
  51. package/modern/hooks/features/filter/gridFilterUtils.js +37 -10
  52. package/modern/hooks/features/filter/useGridFilter.js +8 -3
  53. package/modern/hooks/features/focus/useGridFocus.js +30 -1
  54. package/modern/index.js +1 -1
  55. package/node/hooks/features/columns/gridColumnsUtils.js +15 -5
  56. package/node/hooks/features/dimensions/useGridDimensions.js +1 -1
  57. package/node/hooks/features/export/serializers/csvSerializer.js +3 -5
  58. package/node/hooks/features/export/useGridPrintExport.js +8 -1
  59. package/node/hooks/features/filter/gridFilterUtils.js +37 -10
  60. package/node/hooks/features/filter/useGridFilter.js +8 -3
  61. package/node/hooks/features/focus/useGridFocus.js +29 -0
  62. package/node/index.js +1 -1
  63. package/package.json +3 -3
  64. package/utils/getGridLocalization.js +2 -2
@@ -264,11 +264,11 @@ export const updateCacheWithNewRows = ({
264
264
  export function calculatePinnedRowsHeight(apiRef) {
265
265
  var _pinnedRows$top, _pinnedRows$bottom;
266
266
  const pinnedRows = gridPinnedRowsSelector(apiRef);
267
- const topPinnedRowsHeight = (pinnedRows == null ? void 0 : (_pinnedRows$top = pinnedRows.top) == null ? void 0 : _pinnedRows$top.reduce((acc, value) => {
267
+ const topPinnedRowsHeight = (pinnedRows == null || (_pinnedRows$top = pinnedRows.top) == null ? void 0 : _pinnedRows$top.reduce((acc, value) => {
268
268
  acc += apiRef.current.unstable_getRowHeight(value.id);
269
269
  return acc;
270
270
  }, 0)) || 0;
271
- const bottomPinnedRowsHeight = (pinnedRows == null ? void 0 : (_pinnedRows$bottom = pinnedRows.bottom) == null ? void 0 : _pinnedRows$bottom.reduce((acc, value) => {
271
+ const bottomPinnedRowsHeight = (pinnedRows == null || (_pinnedRows$bottom = pinnedRows.bottom) == null ? void 0 : _pinnedRows$bottom.reduce((acc, value) => {
272
272
  acc += apiRef.current.unstable_getRowHeight(value.id);
273
273
  return acc;
274
274
  }, 0)) || 0;
@@ -145,10 +145,10 @@ export const useGridRowsMeta = (apiRef, props) => {
145
145
  }
146
146
  return acc + maximumBaseSize + otherSizes;
147
147
  }, 0);
148
- pinnedRows == null ? void 0 : (_pinnedRows$top = pinnedRows.top) == null ? void 0 : _pinnedRows$top.forEach(row => {
148
+ pinnedRows == null || (_pinnedRows$top = pinnedRows.top) == null ? void 0 : _pinnedRows$top.forEach(row => {
149
149
  calculateRowProcessedSizes(row);
150
150
  });
151
- pinnedRows == null ? void 0 : (_pinnedRows$bottom = pinnedRows.bottom) == null ? void 0 : _pinnedRows$bottom.forEach(row => {
151
+ pinnedRows == null || (_pinnedRows$bottom = pinnedRows.bottom) == null ? void 0 : _pinnedRows$bottom.forEach(row => {
152
152
  calculateRowProcessedSizes(row);
153
153
  });
154
154
  apiRef.current.setState(state => {
@@ -14,8 +14,8 @@ import { buildAggregatedSortingApplier, mergeStateWithSortModel, getNextGridSort
14
14
  import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
15
15
  import { getTreeNodeDescendants } from '../rows/gridRowsUtils';
16
16
  export const sortingStateInitializer = (state, props) => {
17
- var _ref, _props$sortModel, _props$initialState, _props$initialState$s;
18
- const sortModel = (_ref = (_props$sortModel = props.sortModel) != null ? _props$sortModel : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$s = _props$initialState.sorting) == null ? void 0 : _props$initialState$s.sortModel) != null ? _ref : [];
17
+ var _ref, _props$sortModel, _props$initialState;
18
+ const sortModel = (_ref = (_props$sortModel = props.sortModel) != null ? _props$sortModel : (_props$initialState = props.initialState) == null || (_props$initialState = _props$initialState.sorting) == null ? void 0 : _props$initialState.sortModel) != null ? _ref : [];
19
19
  return _extends({}, state, {
20
20
  sorting: {
21
21
  sortModel: sanitizeSortModel(sortModel, props.disableMultipleColumnsSorting),
@@ -29,7 +29,7 @@ export const sortingStateInitializer = (state, props) => {
29
29
  * @requires useGridColumns (event)
30
30
  */
31
31
  export const useGridSorting = (apiRef, props) => {
32
- var _props$initialState3, _props$initialState3$;
32
+ var _props$initialState3;
33
33
  const logger = useGridLogger(apiRef, 'useGridSorting');
34
34
  apiRef.current.registerControlState({
35
35
  stateId: 'sortModel',
@@ -151,7 +151,7 @@ export const useGridSorting = (apiRef, props) => {
151
151
  * PRE-PROCESSING
152
152
  */
153
153
  const stateExportPreProcessing = React.useCallback((prevState, context) => {
154
- var _props$initialState2, _props$initialState2$;
154
+ var _props$initialState2;
155
155
  const sortModelToExport = gridSortModelSelector(apiRef);
156
156
  const shouldExportSortModel =
157
157
  // Always export if the `exportOnlyDirtyModels` property is not activated
@@ -159,7 +159,7 @@ export const useGridSorting = (apiRef, props) => {
159
159
  // Always export if the model is controlled
160
160
  props.sortModel != null ||
161
161
  // Always export if the model has been initialized
162
- ((_props$initialState2 = props.initialState) == null ? void 0 : (_props$initialState2$ = _props$initialState2.sorting) == null ? void 0 : _props$initialState2$.sortModel) != null ||
162
+ ((_props$initialState2 = props.initialState) == null || (_props$initialState2 = _props$initialState2.sorting) == null ? void 0 : _props$initialState2.sortModel) != null ||
163
163
  // Export if the model is not empty
164
164
  sortModelToExport.length > 0;
165
165
  if (!shouldExportSortModel) {
@@ -170,7 +170,7 @@ export const useGridSorting = (apiRef, props) => {
170
170
  sortModel: sortModelToExport
171
171
  }
172
172
  });
173
- }, [apiRef, props.sortModel, (_props$initialState3 = props.initialState) == null ? void 0 : (_props$initialState3$ = _props$initialState3.sorting) == null ? void 0 : _props$initialState3$.sortModel]);
173
+ }, [apiRef, props.sortModel, (_props$initialState3 = props.initialState) == null || (_props$initialState3 = _props$initialState3.sorting) == null ? void 0 : _props$initialState3.sortModel]);
174
174
  const stateRestorePreProcessing = React.useCallback((params, context) => {
175
175
  var _context$stateToResto;
176
176
  const sortModel = (_context$stateToResto = context.stateToRestore.sorting) == null ? void 0 : _context$stateToResto.sortModel;
@@ -427,7 +427,7 @@ export const useGridVirtualScroller = props => {
427
427
  firstColumnToRender: firstColumnToRender,
428
428
  lastColumnToRender: lastColumnToRender,
429
429
  selected: isSelected,
430
- index: rowIndexOffset + ((currentPage == null ? void 0 : (_currentPage$range5 = currentPage.range) == null ? void 0 : _currentPage$range5.firstRowIndex) || 0) + firstRowToRender + i,
430
+ index: rowIndexOffset + ((currentPage == null || (_currentPage$range5 = currentPage.range) == null ? void 0 : _currentPage$range5.firstRowIndex) || 0) + firstRowToRender + i,
431
431
  containerWidth: availableSpace,
432
432
  isLastVisible: lastVisibleRowIndex,
433
433
  position: position
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v6.10.0
2
+ * @mui/x-data-grid v6.10.1
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
package/joy/joySlots.js CHANGED
@@ -94,7 +94,7 @@ const TextField = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
94
94
  } = _ref2,
95
95
  props = _objectWithoutPropertiesLoose(_ref2, _excluded2);
96
96
  const rootRef = useForkRef(ref, (_props$InputProps = props.InputProps) == null ? void 0 : _props$InputProps.ref);
97
- const inputForkRef = useForkRef(inputRef, props == null ? void 0 : (_props$inputProps = props.inputProps) == null ? void 0 : _props$inputProps.ref);
97
+ const inputForkRef = useForkRef(inputRef, props == null || (_props$inputProps = props.inputProps) == null ? void 0 : _props$inputProps.ref);
98
98
  const {
99
99
  startAdornment,
100
100
  endAdornment
@@ -234,7 +234,7 @@ const Select = /*#__PURE__*/React.forwardRef((_ref6, ref) => {
234
234
  onOpen == null ? void 0 : onOpen({});
235
235
  } else {
236
236
  var _MenuProps$onClose;
237
- MenuProps == null ? void 0 : (_MenuProps$onClose = MenuProps.onClose) == null ? void 0 : _MenuProps$onClose.call(MenuProps, {}, undefined);
237
+ MenuProps == null || (_MenuProps$onClose = MenuProps.onClose) == null ? void 0 : _MenuProps$onClose.call(MenuProps, {}, undefined);
238
238
  }
239
239
  },
240
240
  size: convertSize(size),
@@ -86,8 +86,8 @@ var GridPanel = /*#__PURE__*/React.forwardRef(function (props, ref) {
86
86
  anchorEl = _React$useState4[0],
87
87
  setAnchorEl = _React$useState4[1];
88
88
  React.useEffect(function () {
89
- var _apiRef$current$rootE, _apiRef$current$rootE2;
90
- var columnHeadersElement = (_apiRef$current$rootE = apiRef.current.rootElementRef) == null ? void 0 : (_apiRef$current$rootE2 = _apiRef$current$rootE.current) == null ? void 0 : _apiRef$current$rootE2.querySelector(".".concat(gridClasses.columnHeaders));
89
+ var _apiRef$current$rootE;
90
+ var columnHeadersElement = (_apiRef$current$rootE = apiRef.current.rootElementRef) == null || (_apiRef$current$rootE = _apiRef$current$rootE.current) == null ? void 0 : _apiRef$current$rootE.querySelector(".".concat(gridClasses.columnHeaders));
91
91
  if (columnHeadersElement) {
92
92
  setAnchorEl(columnHeadersElement);
93
93
  }
@@ -247,7 +247,7 @@ var GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(props
247
247
  focus: function focus() {
248
248
  if (currentOperator != null && currentOperator.InputComponent) {
249
249
  var _valueRef$current;
250
- valueRef == null ? void 0 : (_valueRef$current = valueRef.current) == null ? void 0 : _valueRef$current.focus();
250
+ valueRef == null || (_valueRef$current = valueRef.current) == null ? void 0 : _valueRef$current.focus();
251
251
  } else {
252
252
  filterSelectorRef.current.focus();
253
253
  }
@@ -348,7 +348,7 @@ var GridFilterForm = /*#__PURE__*/React.forwardRef(function GridFilterForm(props
348
348
  native: isBaseSelectNative,
349
349
  inputRef: filterSelectorRef
350
350
  }, (_rootProps$slotProps8 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps8.baseSelect, {
351
- children: currentColumn == null ? void 0 : (_currentColumn$filter2 = currentColumn.filterOperators) == null ? void 0 : _currentColumn$filter2.map(function (operator) {
351
+ children: currentColumn == null || (_currentColumn$filter2 = currentColumn.filterOperators) == null ? void 0 : _currentColumn$filter2.map(function (operator) {
352
352
  return /*#__PURE__*/_createElement(rootProps.slots.baseSelectOption, _extends({}, baseSelectOptionProps, {
353
353
  native: isBaseSelectNative,
354
354
  key: operator.value,
@@ -43,7 +43,7 @@ var SingleSelectOperatorContainer = styled('div')(_defineProperty({
43
43
  margin: 'auto 0px 5px 5px'
44
44
  }));
45
45
  function GridFilterInputSingleSelect(props) {
46
- var _item$value, _rootProps$slotProps$, _rootProps$slotProps, _rootProps$slotProps$2, _resolvedColumn, _resolvedColumn2, _rootProps$slotProps2, _rootProps$slotProps3, _rootProps$slotProps4;
46
+ var _item$value, _rootProps$slotProps$, _rootProps$slotProps, _resolvedColumn, _resolvedColumn2, _rootProps$slotProps2, _rootProps$slotProps3, _rootProps$slotProps4;
47
47
  var item = props.item,
48
48
  applyValue = props.applyValue,
49
49
  type = props.type,
@@ -64,7 +64,7 @@ function GridFilterInputSingleSelect(props) {
64
64
  var id = useId();
65
65
  var labelId = useId();
66
66
  var rootProps = useGridRootProps();
67
- var isSelectNative = (_rootProps$slotProps$ = (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : (_rootProps$slotProps$2 = _rootProps$slotProps.baseSelect) == null ? void 0 : _rootProps$slotProps$2.native) != null ? _rootProps$slotProps$ : true;
67
+ var isSelectNative = (_rootProps$slotProps$ = (_rootProps$slotProps = rootProps.slotProps) == null || (_rootProps$slotProps = _rootProps$slotProps.baseSelect) == null ? void 0 : _rootProps$slotProps.native) != null ? _rootProps$slotProps$ : true;
68
68
  var resolvedColumn = null;
69
69
  if (item.field) {
70
70
  var column = apiRef.current.getColumn(item.field);
@@ -208,8 +208,15 @@ export var applyInitialState = function applyInitialState(columnsState, initialS
208
208
  });
209
209
  return newColumnsState;
210
210
  };
211
+ function getDefaultColTypeDef(columnTypes, type) {
212
+ var colDef = columnTypes[DEFAULT_GRID_COL_TYPE_KEY];
213
+ if (type && columnTypes[type]) {
214
+ colDef = columnTypes[type];
215
+ }
216
+ return colDef;
217
+ }
211
218
  export var createColumnsState = function createColumnsState(_ref5) {
212
- var _apiRef$current$getRo, _apiRef$current$getRo2, _apiRef$current, _apiRef$current$getRo3;
219
+ var _apiRef$current$getRo, _apiRef$current$getRo2, _apiRef$current;
213
220
  var apiRef = _ref5.apiRef,
214
221
  columnsToUpsert = _ref5.columnsToUpsert,
215
222
  initialState = _ref5.initialState,
@@ -248,11 +255,7 @@ export var createColumnsState = function createColumnsState(_ref5) {
248
255
  columnsToKeep[field] = true;
249
256
  var existingState = columnsState.lookup[field];
250
257
  if (existingState == null) {
251
- var colDef = columnTypes[DEFAULT_GRID_COL_TYPE_KEY];
252
- if (newColumn.type && columnTypes[newColumn.type]) {
253
- colDef = columnTypes[newColumn.type];
254
- }
255
- existingState = _extends({}, colDef, {
258
+ existingState = _extends({}, getDefaultColTypeDef(columnTypes, newColumn.type), {
256
259
  field: field,
257
260
  hasBeenResized: false
258
261
  });
@@ -260,6 +263,13 @@ export var createColumnsState = function createColumnsState(_ref5) {
260
263
  } else if (keepOnlyColumnsToUpsert) {
261
264
  columnsState.orderedFields.push(field);
262
265
  }
266
+
267
+ // If the column type has changed - merge the existing state with the default column type definition
268
+ if (existingState && existingState.type !== newColumn.type) {
269
+ existingState = _extends({}, existingState, getDefaultColTypeDef(columnTypes, newColumn.type), {
270
+ field: field
271
+ });
272
+ }
263
273
  var hasBeenResized = existingState.hasBeenResized;
264
274
  COLUMNS_DIMENSION_PROPERTIES.forEach(function (key) {
265
275
  if (newColumn[key] !== undefined) {
@@ -282,7 +292,7 @@ export var createColumnsState = function createColumnsState(_ref5) {
282
292
  }
283
293
  var columnsStateWithPreProcessing = apiRef.current.unstable_applyPipeProcessors('hydrateColumns', columnsState);
284
294
  var columnsStateWithPortableColumns = applyInitialState(columnsStateWithPreProcessing, initialState);
285
- return hydrateColumnsWidth(columnsStateWithPortableColumns, (_apiRef$current$getRo = (_apiRef$current$getRo2 = (_apiRef$current = apiRef.current).getRootDimensions) == null ? void 0 : (_apiRef$current$getRo3 = _apiRef$current$getRo2.call(_apiRef$current)) == null ? void 0 : _apiRef$current$getRo3.viewportInnerSize.width) != null ? _apiRef$current$getRo : 0);
295
+ return hydrateColumnsWidth(columnsStateWithPortableColumns, (_apiRef$current$getRo = (_apiRef$current$getRo2 = (_apiRef$current = apiRef.current).getRootDimensions) == null || (_apiRef$current$getRo2 = _apiRef$current$getRo2.call(_apiRef$current)) == null ? void 0 : _apiRef$current$getRo2.viewportInnerSize.width) != null ? _apiRef$current$getRo : 0);
286
296
  };
287
297
  export var mergeColumnsState = function mergeColumnsState(columnsState) {
288
298
  return function (state) {
@@ -13,13 +13,13 @@ import { getGridDefaultColumnTypes } from '../../../colDef';
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  var defaultColumnTypes = getGridDefaultColumnTypes();
15
15
  export var columnsStateInitializer = function columnsStateInitializer(state, props, apiRef) {
16
- var _props$initialState, _ref, _props$columnVisibili, _props$initialState2, _props$initialState2$;
16
+ var _props$initialState, _ref, _props$columnVisibili, _props$initialState2;
17
17
  var columnsState = createColumnsState({
18
18
  apiRef: apiRef,
19
19
  columnTypes: defaultColumnTypes,
20
20
  columnsToUpsert: props.columns,
21
21
  initialState: (_props$initialState = props.initialState) == null ? void 0 : _props$initialState.columns,
22
- columnVisibilityModel: (_ref = (_props$columnVisibili = props.columnVisibilityModel) != null ? _props$columnVisibili : (_props$initialState2 = props.initialState) == null ? void 0 : (_props$initialState2$ = _props$initialState2.columns) == null ? void 0 : _props$initialState2$.columnVisibilityModel) != null ? _ref : {},
22
+ columnVisibilityModel: (_ref = (_props$columnVisibili = props.columnVisibilityModel) != null ? _props$columnVisibili : (_props$initialState2 = props.initialState) == null || (_props$initialState2 = _props$initialState2.columns) == null ? void 0 : _props$initialState2.columnVisibilityModel) != null ? _ref : {},
23
23
  keepOnlyColumnsToUpsert: true
24
24
  });
25
25
  return _extends({}, state, {
@@ -173,7 +173,7 @@ export function useGridColumns(apiRef, props) {
173
173
  * PRE-PROCESSING
174
174
  */
175
175
  var stateExportPreProcessing = React.useCallback(function (prevState, context) {
176
- var _props$initialState$c, _props$initialState3, _props$initialState3$;
176
+ var _props$initialState$c, _props$initialState3;
177
177
  var columnsStateToExport = {};
178
178
  var columnVisibilityModelToExport = gridColumnVisibilityModelSelector(apiRef);
179
179
  var shouldExportColumnVisibilityModel =
@@ -183,7 +183,7 @@ export function useGridColumns(apiRef, props) {
183
183
  props.columnVisibilityModel != null ||
184
184
  // Always export if the model has been initialized
185
185
  // TODO v6 Do a nullish check instead to export even if the initial model equals "{}"
186
- Object.keys((_props$initialState$c = (_props$initialState3 = props.initialState) == null ? void 0 : (_props$initialState3$ = _props$initialState3.columns) == null ? void 0 : _props$initialState3$.columnVisibilityModel) != null ? _props$initialState$c : {}).length > 0 ||
186
+ Object.keys((_props$initialState$c = (_props$initialState3 = props.initialState) == null || (_props$initialState3 = _props$initialState3.columns) == null ? void 0 : _props$initialState3.columnVisibilityModel) != null ? _props$initialState$c : {}).length > 0 ||
187
187
  // Always export if the model is not empty
188
188
  Object.keys(columnVisibilityModelToExport).length > 0;
189
189
  if (shouldExportColumnVisibilityModel) {
@@ -81,7 +81,7 @@ export function useGridDimensions(apiRef, props) {
81
81
  } else {
82
82
  viewportOuterSize = {
83
83
  width: rootDimensionsRef.current.width,
84
- height: rootDimensionsRef.current.height - totalHeaderHeight
84
+ height: Math.max(rootDimensionsRef.current.height - totalHeaderHeight, 0)
85
85
  };
86
86
  var scrollInformation = hasScroll({
87
87
  content: {
@@ -345,7 +345,7 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
345
345
  }());
346
346
  var setCellEditingEditCellValue = React.useCallback( /*#__PURE__*/function () {
347
347
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
348
- var _editingState$id, _editingState$id$fiel2;
348
+ var _editingState$id;
349
349
  var id, field, value, debounceMs, skipValueParser, column, row, parsedValue, editingState, newProps, hasChanged;
350
350
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
351
351
  while (1) switch (_context2.prev = _context2.next) {
@@ -399,7 +399,7 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
399
399
  newProps.value = column.preProcessEditCellProps ? editingState[id][field].value : parsedValue;
400
400
  updateOrDeleteFieldState(id, field, newProps);
401
401
  editingState = gridEditRowsStateSelector(apiRef.current.state);
402
- return _context2.abrupt("return", !((_editingState$id = editingState[id]) != null && (_editingState$id$fiel2 = _editingState$id[field]) != null && _editingState$id$fiel2.error));
402
+ return _context2.abrupt("return", !((_editingState$id = editingState[id]) != null && (_editingState$id = _editingState$id[field]) != null && _editingState$id.error));
403
403
  case 24:
404
404
  case "end":
405
405
  return _context2.stop();
@@ -451,11 +451,11 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
451
451
  id = _ref4[0],
452
452
  fields = _ref4[1];
453
453
  Object.entries(fields).forEach(function (_ref5) {
454
- var _copyOfPrevCellModes$, _copyOfPrevCellModes$2, _idToIdLookup$id;
454
+ var _copyOfPrevCellModes$, _idToIdLookup$id;
455
455
  var _ref6 = _slicedToArray(_ref5, 2),
456
456
  field = _ref6[0],
457
457
  params = _ref6[1];
458
- var prevMode = ((_copyOfPrevCellModes$ = copyOfPrevCellModes[id]) == null ? void 0 : (_copyOfPrevCellModes$2 = _copyOfPrevCellModes$[field]) == null ? void 0 : _copyOfPrevCellModes$2.mode) || GridCellModes.View;
458
+ var prevMode = ((_copyOfPrevCellModes$ = copyOfPrevCellModes[id]) == null || (_copyOfPrevCellModes$ = _copyOfPrevCellModes$[field]) == null ? void 0 : _copyOfPrevCellModes$.mode) || GridCellModes.View;
459
459
  var originalId = (_idToIdLookup$id = idToIdLookup[id]) != null ? _idToIdLookup$id : id;
460
460
  if (params.mode === GridCellModes.Edit && prevMode === GridCellModes.View) {
461
461
  updateStateToStartCellEditMode(_extends({
@@ -4,15 +4,13 @@ import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../../../../colDef';
4
4
  import { buildWarning } from '../../../../utils/warning';
5
5
  function sanitizeCellValue(value, delimiterCharacter) {
6
6
  if (typeof value === 'string') {
7
- var formattedValue = value.replace(/"/g, '""');
8
-
9
7
  // Make sure value containing delimiter or line break won't be split into multiple rows
10
- if ([delimiterCharacter, '\n', '\r'].some(function (delimiter) {
11
- return formattedValue.includes(delimiter);
8
+ if ([delimiterCharacter, '\n', '\r', '"'].some(function (delimiter) {
9
+ return value.includes(delimiter);
12
10
  })) {
13
- return "\"".concat(formattedValue, "\"");
11
+ return "\"".concat(value.replace(/"/g, '""'), "\"");
14
12
  }
15
- return formattedValue;
13
+ return value;
16
14
  }
17
15
  return value;
18
16
  }
@@ -131,11 +131,12 @@ export var useGridPrintExport = function useGridPrintExport(apiRef, props) {
131
131
  var _printDoc$body$classL;
132
132
  (_printDoc$body$classL = printDoc.body.classList).add.apply(_printDoc$body$classL, _toConsumableArray(normalizeOptions.bodyClassName.split(' ')));
133
133
  }
134
+ var stylesheetLoadPromises = [];
134
135
  if (normalizeOptions.copyStyles) {
135
136
  var rootCandidate = gridRootElement.getRootNode();
136
137
  var root = rootCandidate.constructor.name === 'ShadowRoot' ? rootCandidate : doc.current;
137
138
  var headStyleElements = root.querySelectorAll("style, link[rel='stylesheet']");
138
- for (var i = 0; i < headStyleElements.length; i += 1) {
139
+ var _loop = function _loop() {
139
140
  var node = headStyleElements[i];
140
141
  if (node.tagName === 'STYLE') {
141
142
  var newHeadStyleElements = printDoc.createElement(node.tagName);
@@ -161,24 +162,35 @@ export var useGridPrintExport = function useGridPrintExport(apiRef, props) {
161
162
  _newHeadStyleElements.setAttribute(attr.nodeName, attr.nodeValue || '');
162
163
  }
163
164
  }
165
+ stylesheetLoadPromises.push(new Promise(function (resolve) {
166
+ _newHeadStyleElements.addEventListener('load', function () {
167
+ return resolve();
168
+ });
169
+ }));
164
170
  printDoc.head.appendChild(_newHeadStyleElements);
165
171
  }
172
+ };
173
+ for (var i = 0; i < headStyleElements.length; i += 1) {
174
+ _loop();
166
175
  }
167
176
  }
168
177
 
169
178
  // Trigger print
170
179
  if (process.env.NODE_ENV !== 'test') {
171
- printWindow.contentWindow.print();
180
+ // wait for remote stylesheets to load
181
+ Promise.all(stylesheetLoadPromises).then(function () {
182
+ printWindow.contentWindow.print();
183
+ });
172
184
  }
173
185
  }, [apiRef, doc, props.columnHeaderHeight]);
174
186
  var handlePrintWindowAfterPrint = React.useCallback(function (printWindow) {
175
- var _previousGridState$cu, _previousGridState$cu2;
187
+ var _previousGridState$cu;
176
188
  // Remove the print iframe
177
189
  doc.current.body.removeChild(printWindow);
178
190
 
179
191
  // Revert grid to previous state
180
192
  apiRef.current.restoreState(previousGridState.current || {});
181
- if (!((_previousGridState$cu = previousGridState.current) != null && (_previousGridState$cu2 = _previousGridState$cu.columns) != null && _previousGridState$cu2.columnVisibilityModel)) {
193
+ if (!((_previousGridState$cu = previousGridState.current) != null && (_previousGridState$cu = _previousGridState$cu.columns) != null && _previousGridState$cu.columnVisibilityModel)) {
182
194
  // if the apiRef.current.exportState(); did not exported the column visibility, we update it
183
195
  apiRef.current.setColumnVisibilityModel(previousColumnVisibility.current);
184
196
  }
@@ -30,10 +30,10 @@ export var defaultGetRowsToExport = function defaultGetRowsToExport(_ref2) {
30
30
  return rowTree[id].type !== 'footer';
31
31
  });
32
32
  var pinnedRows = gridPinnedRowsSelector(apiRef);
33
- var topPinnedRowsIds = (pinnedRows == null ? void 0 : (_pinnedRows$top = pinnedRows.top) == null ? void 0 : _pinnedRows$top.map(function (row) {
33
+ var topPinnedRowsIds = (pinnedRows == null || (_pinnedRows$top = pinnedRows.top) == null ? void 0 : _pinnedRows$top.map(function (row) {
34
34
  return row.id;
35
35
  })) || [];
36
- var bottomPinnedRowsIds = (pinnedRows == null ? void 0 : (_pinnedRows$bottom = pinnedRows.bottom) == null ? void 0 : _pinnedRows$bottom.map(function (row) {
36
+ var bottomPinnedRowsIds = (pinnedRows == null || (_pinnedRows$bottom = pinnedRows.bottom) == null ? void 0 : _pinnedRows$bottom.map(function (row) {
37
37
  return row.id;
38
38
  })) || [];
39
39
  bodyRows.unshift.apply(bodyRows, _toConsumableArray(topPinnedRowsIds));
@@ -136,7 +136,7 @@ export var gridFilterActiveItemsSelector = createSelectorMemoized(gridFilterMode
136
136
  return false;
137
137
  }
138
138
  var column = columnLookup[item.field];
139
- if (!(column != null && column.filterOperators) || (column == null ? void 0 : (_column$filterOperato = column.filterOperators) == null ? void 0 : _column$filterOperato.length) === 0) {
139
+ if (!(column != null && column.filterOperators) || (column == null || (_column$filterOperato = column.filterOperators) == null ? void 0 : _column$filterOperato.length) === 0) {
140
140
  return false;
141
141
  }
142
142
  var filterOperator = column.filterOperators.find(function (operator) {
@@ -132,6 +132,7 @@ var getFilterCallbackFromItem = function getFilterCallbackFromItem(filterItem, a
132
132
  }
133
133
  };
134
134
  };
135
+ var filterItemsApplierId = 1;
135
136
 
136
137
  /**
137
138
  * Generates a method to easily check if a row is matching the current filter model.
@@ -150,16 +151,35 @@ export var buildAggregatedFilterItemsApplier = function buildAggregatedFilterIte
150
151
  if (appliers.length === 0) {
151
152
  return null;
152
153
  }
153
- return function (row, shouldApplyFilter) {
154
- var resultPerItemId = {};
155
- for (var i = 0; i < appliers.length; i += 1) {
156
- var applier = appliers[i];
157
- if (!shouldApplyFilter || shouldApplyFilter(applier.item.field)) {
158
- resultPerItemId[applier.item.id] = applier.v7 ? applier.fn(row) : applier.fn(getRowId ? getRowId(row) : row.id);
159
- }
160
- }
161
- return resultPerItemId;
162
- };
154
+
155
+ // Original logic:
156
+ // return (row, shouldApplyFilter) => {
157
+ // const resultPerItemId: GridFilterItemResult = {};
158
+ //
159
+ // for (let i = 0; i < appliers.length; i += 1) {
160
+ // const applier = appliers[i];
161
+ // if (!shouldApplyFilter || shouldApplyFilter(applier.item.field)) {
162
+ // resultPerItemId[applier.item.id!] = applier.v7
163
+ // ? applier.fn(row)
164
+ // : applier.fn(getRowId ? getRowId(row) : row.id);
165
+ // }
166
+ // }
167
+ //
168
+ // return resultPerItemId;
169
+ // };
170
+
171
+ // We generate a new function with `eval()` to avoid expensive patterns for JS engines
172
+ // such as a dynamic object assignment, e.g. `{ [dynamicKey]: value }`.
173
+ var filterItemTemplate = "(function filterItem$$(row, shouldApplyFilter) {\n ".concat(appliers.map(function (applier, i) {
174
+ return "const shouldApply".concat(i, " = !shouldApplyFilter || shouldApplyFilter(").concat(JSON.stringify(applier.item.field), ");");
175
+ }).join('\n'), "\n\n const result$$ = {\n ").concat(appliers.map(function (applier, i) {
176
+ return "".concat(JSON.stringify(String(applier.item.id)), ":\n !shouldApply").concat(i, " ?\n false :\n ").concat(applier.v7 ? "appliers[".concat(i, "].fn(row)") : "appliers[".concat(i, "].fn(").concat(getRowId ? 'getRowId(row)' : 'row.id', ")"), ",\n ");
177
+ }).join('\n'), "};\n\n return result$$;\n })");
178
+
179
+ // eslint-disable-next-line no-eval
180
+ var filterItem = eval(filterItemTemplate.replaceAll('$$', String(filterItemsApplierId)));
181
+ filterItemsApplierId += 1;
182
+ return filterItem;
163
183
  };
164
184
 
165
185
  /**
@@ -1,7 +1,9 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  import * as React from 'react';
4
+ import { defaultMemoize } from 'reselect';
4
5
  import { unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
6
+ import { useLazyRef } from '../../utils/useLazyRef';
5
7
  import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
6
8
  import { useGridApiMethod } from '../../utils/useGridApiMethod';
7
9
  import { useGridLogger } from '../../utils/useGridLogger';
@@ -17,8 +19,8 @@ import { buildAggregatedFilterApplier, sanitizeFilterModel, mergeStateWithFilter
17
19
  import { isDeepEqual } from '../../../utils/utils';
18
20
  import { jsx as _jsx } from "react/jsx-runtime";
19
21
  export var filterStateInitializer = function filterStateInitializer(state, props, apiRef) {
20
- var _ref, _props$filterModel, _props$initialState, _props$initialState$f;
21
- var filterModel = (_ref = (_props$filterModel = props.filterModel) != null ? _props$filterModel : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$f = _props$initialState.filter) == null ? void 0 : _props$initialState$f.filterModel) != null ? _ref : getDefaultGridFilterModel();
22
+ var _ref, _props$filterModel, _props$initialState;
23
+ var filterModel = (_ref = (_props$filterModel = props.filterModel) != null ? _props$filterModel : (_props$initialState = props.initialState) == null || (_props$initialState = _props$initialState.filter) == null ? void 0 : _props$initialState.filterModel) != null ? _ref : getDefaultGridFilterModel();
22
24
  return _extends({}, state, {
23
25
  filter: {
24
26
  filterModel: sanitizeFilterModel(filterModel, props.disableMultipleColumnsFiltering, apiRef),
@@ -38,6 +40,9 @@ function getVisibleRowsLookupState(apiRef, state) {
38
40
  filteredRowsLookup: state.filter.filteredRowsLookup
39
41
  });
40
42
  }
43
+ function createMemoizedValues() {
44
+ return defaultMemoize(Object.values);
45
+ }
41
46
 
42
47
  /**
43
48
  * @requires useGridColumns (method, event)
@@ -45,7 +50,7 @@ function getVisibleRowsLookupState(apiRef, state) {
45
50
  * @requires useGridRows (event)
46
51
  */
47
52
  export var useGridFilter = function useGridFilter(apiRef, props) {
48
- var _props$initialState3, _props$initialState3$, _props$slotProps2;
53
+ var _props$initialState3, _props$slotProps2;
49
54
  var logger = useGridLogger(apiRef, 'useGridFilter');
50
55
  apiRef.current.registerControlState({
51
56
  stateId: 'filter',
@@ -229,7 +234,7 @@ export var useGridFilter = function useGridFilter(apiRef, props) {
229
234
  * PRE-PROCESSING
230
235
  */
231
236
  var stateExportPreProcessing = React.useCallback(function (prevState, context) {
232
- var _props$initialState2, _props$initialState2$;
237
+ var _props$initialState2;
233
238
  var filterModelToExport = gridFilterModelSelector(apiRef);
234
239
  var shouldExportFilterModel =
235
240
  // Always export if the `exportOnlyDirtyModels` property is not activated
@@ -237,7 +242,7 @@ export var useGridFilter = function useGridFilter(apiRef, props) {
237
242
  // Always export if the model is controlled
238
243
  props.filterModel != null ||
239
244
  // Always export if the model has been initialized
240
- ((_props$initialState2 = props.initialState) == null ? void 0 : (_props$initialState2$ = _props$initialState2.filter) == null ? void 0 : _props$initialState2$.filterModel) != null ||
245
+ ((_props$initialState2 = props.initialState) == null || (_props$initialState2 = _props$initialState2.filter) == null ? void 0 : _props$initialState2.filterModel) != null ||
241
246
  // Export if the model is not equal to the default value
242
247
  !isDeepEqual(filterModelToExport, getDefaultGridFilterModel());
243
248
  if (!shouldExportFilterModel) {
@@ -248,7 +253,7 @@ export var useGridFilter = function useGridFilter(apiRef, props) {
248
253
  filterModel: filterModelToExport
249
254
  }
250
255
  });
251
- }, [apiRef, props.filterModel, (_props$initialState3 = props.initialState) == null ? void 0 : (_props$initialState3$ = _props$initialState3.filter) == null ? void 0 : _props$initialState3$.filterModel]);
256
+ }, [apiRef, props.filterModel, (_props$initialState3 = props.initialState) == null || (_props$initialState3 = _props$initialState3.filter) == null ? void 0 : _props$initialState3.filterModel]);
252
257
  var stateRestorePreProcessing = React.useCallback(function (params, context) {
253
258
  var _context$stateToResto;
254
259
  var filterModel = (_context$stateToResto = context.stateToRestore.filter) == null ? void 0 : _context$stateToResto.filterModel;
@@ -268,11 +273,8 @@ export var useGridFilter = function useGridFilter(apiRef, props) {
268
273
  }
269
274
  return initialValue;
270
275
  }, [props.slots.filterPanel, (_props$slotProps2 = props.slotProps) == null ? void 0 : _props$slotProps2.filterPanel]);
271
- var dataRowIdToIdLookup = apiRef.current.state.rows.dataRowIdToModelLookup;
272
- var rows = React.useMemo(function () {
273
- return Object.values(dataRowIdToIdLookup);
274
- }, [dataRowIdToIdLookup]);
275
276
  var getRowId = props.getRowId;
277
+ var getRowsRef = useLazyRef(createMemoizedValues);
276
278
  var flatFilteringMethod = React.useCallback(function (params) {
277
279
  if (props.filterMode !== 'client' || !params.isRowMatchingFilters) {
278
280
  return {
@@ -288,6 +290,7 @@ export var useGridFilter = function useGridFilter(apiRef, props) {
288
290
  passingFilterItems: null,
289
291
  passingQuickFilterValues: null
290
292
  };
293
+ var rows = getRowsRef.current(apiRef.current.state.rows.dataRowIdToModelLookup);
291
294
  for (var i = 0; i < rows.length; i += 1) {
292
295
  var row = rows[i];
293
296
  var id = getRowId ? getRowId(row) : row.id;
@@ -304,7 +307,7 @@ export var useGridFilter = function useGridFilter(apiRef, props) {
304
307
  filteredRowsLookup: filteredRowsLookup,
305
308
  filteredDescendantCountLookup: {}
306
309
  };
307
- }, [apiRef, rows, props.filterMode, getRowId]);
310
+ }, [apiRef, props.filterMode, getRowId, getRowsRef]);
308
311
  useGridRegisterPipeProcessor(apiRef, 'columnMenu', addColumnMenuItem);
309
312
  useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
310
313
  useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
- import { unstable_ownerDocument as ownerDocument } from '@mui/utils';
3
+ import { unstable_ownerDocument as ownerDocument, unstable_useEventCallback as useEventcallback } from '@mui/utils';
4
4
  import { gridClasses } from '../../../constants/gridClasses';
5
5
  import { useGridApiMethod } from '../../utils/useGridApiMethod';
6
6
  import { useGridLogger } from '../../utils/useGridLogger';
@@ -347,6 +347,36 @@ export var useGridFocus = function useGridFocus(apiRef, props) {
347
347
  });
348
348
  }
349
349
  }, [apiRef]);
350
+ var handlePaginationModelChange = useEventcallback(function () {
351
+ var currentFocusedCell = gridFocusCellSelector(apiRef);
352
+ if (!currentFocusedCell) {
353
+ return;
354
+ }
355
+ var currentPage = getVisibleRows(apiRef, {
356
+ pagination: props.pagination,
357
+ paginationMode: props.paginationMode
358
+ });
359
+ var rowIsInCurrentPage = currentPage.rows.find(function (row) {
360
+ return row.id === currentFocusedCell.id;
361
+ });
362
+ if (rowIsInCurrentPage) {
363
+ return;
364
+ }
365
+ var visibleColumns = gridVisibleColumnDefinitionsSelector(apiRef);
366
+ apiRef.current.setState(function (state) {
367
+ return _extends({}, state, {
368
+ tabIndex: {
369
+ cell: {
370
+ id: currentPage.rows[0].id,
371
+ field: visibleColumns[0].field
372
+ },
373
+ columnGroupHeader: null,
374
+ columnHeader: null,
375
+ columnHeaderFilter: null
376
+ }
377
+ });
378
+ });
379
+ });
350
380
  var focusApi = {
351
381
  setCellFocus: setCellFocus,
352
382
  setColumnHeaderFocus: setColumnHeaderFocus,
@@ -375,4 +405,5 @@ export var useGridFocus = function useGridFocus(apiRef, props) {
375
405
  useGridApiEventHandler(apiRef, 'columnHeaderFocus', handleColumnHeaderFocus);
376
406
  useGridApiEventHandler(apiRef, 'columnGroupHeaderFocus', handleColumnGroupHeaderFocus);
377
407
  useGridApiEventHandler(apiRef, 'rowsSet', handleRowSet);
408
+ useGridApiEventHandler(apiRef, 'paginationModelChange', handlePaginationModelChange);
378
409
  };