@mui/x-data-grid 5.17.6 → 5.17.8

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 (40) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/components/panel/GridColumnsPanel.d.ts +2 -0
  3. package/components/panel/GridColumnsPanel.js +10 -4
  4. package/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
  5. package/hooks/features/editRows/useGridCellEditing.new.js +20 -5
  6. package/hooks/features/editRows/useGridRowEditing.new.js +19 -5
  7. package/hooks/features/rows/gridRowsState.d.ts +1 -0
  8. package/hooks/features/rows/gridRowsUtils.d.ts +1 -1
  9. package/hooks/features/rows/gridRowsUtils.js +3 -1
  10. package/hooks/features/rows/useGridRows.js +25 -7
  11. package/index.js +1 -1
  12. package/legacy/components/panel/GridColumnsPanel.js +10 -3
  13. package/legacy/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
  14. package/legacy/hooks/features/editRows/useGridCellEditing.new.js +20 -5
  15. package/legacy/hooks/features/editRows/useGridRowEditing.new.js +19 -5
  16. package/legacy/hooks/features/rows/gridRowsUtils.js +3 -1
  17. package/legacy/hooks/features/rows/useGridRows.js +27 -7
  18. package/legacy/index.js +1 -1
  19. package/legacy/locales/trTR.js +17 -17
  20. package/locales/trTR.js +17 -17
  21. package/models/api/gridEditingApi.d.ts +10 -0
  22. package/models/params/gridEditCellParams.d.ts +4 -0
  23. package/models/params/gridRowParams.d.ts +4 -0
  24. package/modern/components/panel/GridColumnsPanel.js +10 -4
  25. package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
  26. package/modern/hooks/features/editRows/useGridCellEditing.new.js +20 -5
  27. package/modern/hooks/features/editRows/useGridRowEditing.new.js +19 -5
  28. package/modern/hooks/features/rows/gridRowsUtils.js +3 -1
  29. package/modern/hooks/features/rows/useGridRows.js +25 -7
  30. package/modern/index.js +1 -1
  31. package/modern/locales/trTR.js +17 -17
  32. package/node/components/panel/GridColumnsPanel.js +10 -4
  33. package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
  34. package/node/hooks/features/editRows/useGridCellEditing.new.js +20 -5
  35. package/node/hooks/features/editRows/useGridRowEditing.new.js +19 -5
  36. package/node/hooks/features/rows/gridRowsUtils.js +3 -1
  37. package/node/hooks/features/rows/useGridRows.js +25 -7
  38. package/node/index.js +1 -1
  39. package/node/locales/trTR.js +17 -17
  40. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,51 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 5.17.8
7
+
8
+ _Oct 20, 2022_
9
+
10
+ We'd like to offer a big thanks to the 5 contributors who made this release possible. Here are some highlights ✨:
11
+
12
+ - 🐞 Bugfixes
13
+ - 🌍 Improve Turkish (tr-TR) locale on the data grid and pickers (#6573) @ramazansancar
14
+
15
+ ### `@mui/x-data-grid@v5.17.8` / `@mui/x-data-grid-pro@v5.17.8` / `@mui/x-data-grid-premium@v5.17.8`
16
+
17
+ #### Changes
18
+
19
+ - [DataGrid] Add `searchPredicate` prop to `GridColumnsPanel` component (#6572) @cherniavskii
20
+ - [DataGrid] Fix grid not updating state on `rowCount` prop change (#6474) @cherniavskii
21
+ - [DataGridPro] Fix row order being reset after updating the row (#6544) @cherniavskii
22
+ - [l10n] Improve Turkish (tr-TR) locale on the data grid and pickers (#6542) (#6573) @ramazansancar
23
+
24
+ ### `@mui/x-date-pickers@v5.0.5` / `@mui/x-date-pickers-pro@v5.0.5`
25
+
26
+ #### Changes
27
+
28
+ - [CalendarPicker] Don't move to closest enabled date when `props.date` contains a disabled date (#6537) @flaviendelangle
29
+ - [DateRangePicker] Fix calendar day outside of month layout shifting on hover (pick #6448) (#6538) @alexfauquette
30
+ - [pickers] Fix typescript issues (#6510) @flaviendelangle
31
+
32
+ ### Docs
33
+
34
+ - [docs] Fix 301 link to the sx prop page @oliviertassinari
35
+
36
+ ## 5.17.7
37
+
38
+ _Oct 13, 2022_
39
+
40
+ We'd like to offer a big thanks to the 2 contributors who made this release possible. Here are some highlights ✨:
41
+
42
+ - 🐞 Bugfixes
43
+
44
+ ### `@mui/x-data-grid@v5.17.7` / `@mui/x-data-grid-pro@v5.17.7` / `@mui/x-data-grid-premium@v5.17.7`
45
+
46
+ #### Changes
47
+
48
+ - [DataGrid] Fix error when using column grouping with all columns hidden (#6425) @alexfauquette
49
+ - [DataGrid] Fix start edit mode with printable character in React 18 (#6478) @m4theushw
50
+
6
51
  ## 5.17.6
7
52
 
8
53
  _Oct 6, 2022_
@@ -1,7 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import { GridPanelWrapperProps } from './GridPanelWrapper';
3
+ import { GridStateColDef } from '../../models/colDef/gridColDef';
3
4
  export interface GridColumnsPanelProps extends GridPanelWrapperProps {
4
5
  sort?: 'asc' | 'desc';
6
+ searchPredicate?: (column: GridStateColDef, searchValue: string) => boolean;
5
7
  }
6
8
  declare function GridColumnsPanel(props: GridColumnsPanelProps): JSX.Element;
7
9
  declare namespace GridColumnsPanel {
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["sort"];
3
+ const _excluded = ["sort", "searchPredicate"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { unstable_composeClasses as composeClasses } from '@mui/material';
@@ -59,6 +59,10 @@ const GridIconButtonRoot = styled(IconButton)({
59
59
  });
60
60
  const collator = new Intl.Collator();
61
61
 
62
+ const defaultSearchPredicate = (column, searchValue) => {
63
+ return (column.headerName || column.field).toLowerCase().indexOf(searchValue) > -1;
64
+ };
65
+
62
66
  function GridColumnsPanel(props) {
63
67
  var _rootProps$components, _rootProps$components3, _rootProps$components4;
64
68
 
@@ -74,7 +78,8 @@ function GridColumnsPanel(props) {
74
78
  const classes = useUtilityClasses(ownerState);
75
79
 
76
80
  const {
77
- sort
81
+ sort,
82
+ searchPredicate = defaultSearchPredicate
78
83
  } = props,
79
84
  other = _objectWithoutPropertiesLoose(props, _excluded);
80
85
 
@@ -128,8 +133,8 @@ function GridColumnsPanel(props) {
128
133
  }
129
134
 
130
135
  const searchValueToCheck = searchValue.toLowerCase();
131
- return sortedColumns.filter(column => (column.headerName || column.field).toLowerCase().indexOf(searchValueToCheck) > -1);
132
- }, [sortedColumns, searchValue]);
136
+ return sortedColumns.filter(column => searchPredicate(column, searchValueToCheck));
137
+ }, [sortedColumns, searchValue, searchPredicate]);
133
138
  React.useEffect(() => {
134
139
  searchInputRef.current.focus();
135
140
  }, []);
@@ -191,6 +196,7 @@ process.env.NODE_ENV !== "production" ? GridColumnsPanel.propTypes = {
191
196
  // | These PropTypes are generated from the TypeScript type definitions |
192
197
  // | To update them edit the TypeScript types and run "yarn proptypes" |
193
198
  // ----------------------------------------------------------------------
199
+ searchPredicate: PropTypes.func,
194
200
  sort: PropTypes.oneOf(['asc', 'desc'])
195
201
  } : void 0;
196
202
  export { GridColumnsPanel };
@@ -238,7 +238,7 @@ export const useGridColumnHeaders = props => {
238
238
 
239
239
  const columnsToRender = getColumnsToRender(params);
240
240
 
241
- if (columnsToRender == null) {
241
+ if (columnsToRender == null || columnsToRender.renderedColumns.length === 0) {
242
242
  return null;
243
243
  }
244
244
 
@@ -121,7 +121,8 @@ export const useGridCellEditing = (apiRef, props) => {
121
121
 
122
122
  if (reason) {
123
123
  const newParams = _extends({}, params, {
124
- reason
124
+ reason,
125
+ key: event.key
125
126
  });
126
127
 
127
128
  apiRef.current.publishEvent('cellEditStart', newParams, event);
@@ -132,14 +133,21 @@ export const useGridCellEditing = (apiRef, props) => {
132
133
  const {
133
134
  id,
134
135
  field,
135
- reason
136
+ reason,
137
+ key
136
138
  } = params;
137
139
  const startCellEditModeParams = {
138
140
  id,
139
141
  field
140
142
  };
141
143
 
142
- if (reason === GridCellEditStartReasons.deleteKeyDown || reason === GridCellEditStartReasons.printableKeyDown) {
144
+ if (reason === GridCellEditStartReasons.printableKeyDown) {
145
+ if (React.version.startsWith('18')) {
146
+ startCellEditModeParams.initialValue = key; // In React 17, cleaning the input is enough
147
+ } else {
148
+ startCellEditModeParams.deleteValue = true;
149
+ }
150
+ } else if (reason === GridCellEditStartReasons.deleteKeyDown) {
143
151
  startCellEditModeParams.deleteValue = true;
144
152
  }
145
153
 
@@ -270,10 +278,17 @@ export const useGridCellEditing = (apiRef, props) => {
270
278
  const {
271
279
  id,
272
280
  field,
273
- deleteValue
281
+ deleteValue,
282
+ initialValue
274
283
  } = params;
284
+ let newValue = apiRef.current.getCellValue(id, field);
285
+
286
+ if (deleteValue || initialValue) {
287
+ newValue = deleteValue ? '' : initialValue;
288
+ }
289
+
275
290
  const newProps = {
276
- value: deleteValue ? '' : apiRef.current.getCellValue(id, field),
291
+ value: newValue,
277
292
  error: false,
278
293
  isProcessingProps: false
279
294
  };
@@ -181,6 +181,7 @@ export const useGridRowEditing = (apiRef, props) => {
181
181
 
182
182
  const newParams = _extends({}, rowParams, {
183
183
  field: params.field,
184
+ key: event.key,
184
185
  reason
185
186
  });
186
187
 
@@ -192,14 +193,21 @@ export const useGridRowEditing = (apiRef, props) => {
192
193
  const {
193
194
  id,
194
195
  field,
195
- reason
196
+ reason,
197
+ key
196
198
  } = params;
197
199
  const startRowEditModeParams = {
198
200
  id,
199
201
  fieldToFocus: field
200
202
  };
201
203
 
202
- if (reason === GridRowEditStartReasons.deleteKeyDown || reason === GridRowEditStartReasons.printableKeyDown) {
204
+ if (reason === GridRowEditStartReasons.printableKeyDown) {
205
+ if (React.version.startsWith('18')) {
206
+ startRowEditModeParams.initialValue = key; // In React 17, cleaning the input is enough
207
+ } else {
208
+ startRowEditModeParams.deleteValue = !!field;
209
+ }
210
+ } else if (reason === GridRowEditStartReasons.deleteKeyDown) {
203
211
  startRowEditModeParams.deleteValue = !!field;
204
212
  }
205
213
 
@@ -339,7 +347,8 @@ export const useGridRowEditing = (apiRef, props) => {
339
347
  const {
340
348
  id,
341
349
  fieldToFocus,
342
- deleteValue
350
+ deleteValue,
351
+ initialValue
343
352
  } = params;
344
353
  const columnFields = gridColumnFieldsSelector(apiRef);
345
354
  const newProps = columnFields.reduce((acc, field) => {
@@ -349,9 +358,14 @@ export const useGridRowEditing = (apiRef, props) => {
349
358
  return acc;
350
359
  }
351
360
 
352
- const shouldDeleteValue = deleteValue && fieldToFocus === field;
361
+ let newValue = apiRef.current.getCellValue(id, field);
362
+
363
+ if (fieldToFocus === field && (deleteValue || initialValue)) {
364
+ newValue = deleteValue ? '' : initialValue;
365
+ }
366
+
353
367
  acc[field] = {
354
- value: shouldDeleteValue ? '' : apiRef.current.getCellValue(id, field),
368
+ value: newValue,
355
369
  error: false,
356
370
  isProcessingProps: false
357
371
  };
@@ -31,6 +31,7 @@ export interface GridRowsInternalCache extends Omit<GridRowTreeCreationParams, '
31
31
  * The value of the `loading` prop since the last time that the rows state was updated.
32
32
  */
33
33
  loadingPropBeforePartialUpdates: DataGridProcessedProps['loading'];
34
+ rowCountPropBeforePartialUpdates: DataGridProcessedProps['rowCount'];
34
35
  }
35
36
  export interface GridRowsState extends GridRowTreeCreationValue {
36
37
  /**
@@ -11,7 +11,7 @@ import { GridRowsInternalCache, GridRowsState } from './gridRowsState';
11
11
  */
12
12
  export declare function checkGridRowIdIsValid(id: GridRowId, row: GridRowModel | Partial<GridRowModel>, detailErrorMessage?: string): void;
13
13
  export declare const getRowIdFromRowModel: (rowModel: GridRowModel, getRowId?: GridRowIdGetter, detailErrorMessage?: string) => GridRowId;
14
- export declare const createRowsInternalCache: ({ rows, getRowId, loading, }: Pick<DataGridProcessedProps, 'rows' | 'getRowId' | 'loading'>) => GridRowsInternalCache;
14
+ export declare const createRowsInternalCache: ({ rows, getRowId, loading, rowCount, }: Pick<DataGridProcessedProps, 'rows' | 'getRowId' | 'loading' | 'rowCount'>) => GridRowsInternalCache;
15
15
  export declare const getRowsStateFromCache: ({ apiRef, previousTree, rowCountProp, loadingProp, }: {
16
16
  apiRef: React.MutableRefObject<GridApiCommunity>;
17
17
  previousTree: GridRowTreeConfig | null;
@@ -22,11 +22,13 @@ export const getRowIdFromRowModel = (rowModel, getRowId, detailErrorMessage) =>
22
22
  export const createRowsInternalCache = ({
23
23
  rows,
24
24
  getRowId,
25
- loading
25
+ loading,
26
+ rowCount
26
27
  }) => {
27
28
  const cache = {
28
29
  rowsBeforePartialUpdates: rows,
29
30
  loadingPropBeforePartialUpdates: loading,
31
+ rowCountPropBeforePartialUpdates: rowCount,
30
32
  idRowsLookup: {},
31
33
  idToIdLookup: {},
32
34
  ids: []
@@ -13,7 +13,8 @@ export const rowsStateInitializer = (state, props, apiRef) => {
13
13
  apiRef.current.unstable_caches.rows = createRowsInternalCache({
14
14
  rows: props.rows,
15
15
  getRowId: props.getRowId,
16
- loading: props.loading
16
+ loading: props.loading,
17
+ rowCount: props.rowCount
17
18
  });
18
19
  return _extends({}, state, {
19
20
  rows: getRowsStateFromCache({
@@ -94,9 +95,10 @@ export const useGridRows = (apiRef, props) => {
94
95
  throttledRowsChange(createRowsInternalCache({
95
96
  rows,
96
97
  getRowId: props.getRowId,
97
- loading: props.loading
98
+ loading: props.loading,
99
+ rowCount: props.rowCount
98
100
  }), true);
99
- }, [logger, props.getRowId, props.loading, throttledRowsChange]);
101
+ }, [logger, props.getRowId, props.loading, props.rowCount, throttledRowsChange]);
100
102
  const updateRows = React.useCallback(updates => {
101
103
  if (props.signature === GridSignature.DataGrid && updates.length > 1) {
102
104
  // TODO: Add test with direct call to `apiRef.current.updateRows` in DataGrid after enabling the `apiRef` on the free plan.
@@ -119,6 +121,7 @@ export const useGridRows = (apiRef, props) => {
119
121
  const newCache = {
120
122
  rowsBeforePartialUpdates: prevCache.rowsBeforePartialUpdates,
121
123
  loadingPropBeforePartialUpdates: prevCache.loadingPropBeforePartialUpdates,
124
+ rowCountPropBeforePartialUpdates: prevCache.rowCountPropBeforePartialUpdates,
122
125
  idRowsLookup: _extends({}, prevCache.idRowsLookup),
123
126
  idToIdLookup: _extends({}, prevCache.idToIdLookup),
124
127
  ids: [...prevCache.ids]
@@ -241,6 +244,7 @@ export const useGridRows = (apiRef, props) => {
241
244
  ids: updatedRows
242
245
  })
243
246
  }));
247
+ apiRef.current.unstable_caches.rows.ids = updatedRows;
244
248
  apiRef.current.publishEvent('rowsSet');
245
249
  }, [apiRef, logger]);
246
250
  const replaceRows = React.useCallback((firstRowToRender, newRows) => {
@@ -332,12 +336,13 @@ export const useGridRows = (apiRef, props) => {
332
336
  cache = createRowsInternalCache({
333
337
  rows: props.rows,
334
338
  getRowId: props.getRowId,
335
- loading: props.loading
339
+ loading: props.loading,
340
+ rowCount: props.rowCount
336
341
  });
337
342
  }
338
343
 
339
344
  throttledRowsChange(cache, false);
340
- }, [logger, apiRef, props.rows, props.getRowId, props.loading, throttledRowsChange]);
345
+ }, [logger, apiRef, props.rows, props.getRowId, props.loading, props.rowCount, throttledRowsChange]);
341
346
  const handleStrategyProcessorChange = React.useCallback(methodName => {
342
347
  if (methodName === 'rowTreeCreation') {
343
348
  groupRows();
@@ -386,7 +391,8 @@ export const useGridRows = (apiRef, props) => {
386
391
  }
387
392
 
388
393
  const areNewRowsAlreadyInState = apiRef.current.unstable_caches.rows.rowsBeforePartialUpdates === props.rows;
389
- const isNewLoadingAlreadyInState = apiRef.current.unstable_caches.rows.loadingPropBeforePartialUpdates === props.loading; // The new rows have already been applied (most likely in the `'rowGroupsPreProcessingChange'` listener)
394
+ const isNewLoadingAlreadyInState = apiRef.current.unstable_caches.rows.loadingPropBeforePartialUpdates === props.loading;
395
+ const isNewRowCountAlreadyInState = apiRef.current.unstable_caches.rows.rowCountPropBeforePartialUpdates === props.rowCount; // The new rows have already been applied (most likely in the `'rowGroupsPreProcessingChange'` listener)
390
396
 
391
397
  if (areNewRowsAlreadyInState) {
392
398
  // If the loading prop has changed, we need to update its value in the state because it won't be done by `throttledRowsChange`
@@ -400,6 +406,17 @@ export const useGridRows = (apiRef, props) => {
400
406
  apiRef.current.forceUpdate();
401
407
  }
402
408
 
409
+ if (!isNewRowCountAlreadyInState) {
410
+ apiRef.current.setState(state => _extends({}, state, {
411
+ rows: _extends({}, state.rows, {
412
+ totalRowCount: Math.max(props.rowCount || 0, state.rows.totalRowCount),
413
+ totalTopLevelRowCount: Math.max(props.rowCount || 0, state.rows.totalTopLevelRowCount)
414
+ })
415
+ }));
416
+ apiRef.current.unstable_caches.rows.rowCountPropBeforePartialUpdates = props.rowCount;
417
+ apiRef.current.forceUpdate();
418
+ }
419
+
403
420
  return;
404
421
  }
405
422
 
@@ -407,7 +424,8 @@ export const useGridRows = (apiRef, props) => {
407
424
  throttledRowsChange(createRowsInternalCache({
408
425
  rows: props.rows,
409
426
  getRowId: props.getRowId,
410
- loading: props.loading
427
+ loading: props.loading,
428
+ rowCount: props.rowCount
411
429
  }), false);
412
430
  }, [props.rows, props.rowCount, props.getRowId, props.loading, logger, throttledRowsChange, apiRef]);
413
431
  };
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.17.6
1
+ /** @license MUI v5.17.8
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.
@@ -3,7 +3,7 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
4
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
5
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
- var _excluded = ["sort"];
6
+ var _excluded = ["sort", "searchPredicate"];
7
7
  import * as React from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  import { unstable_composeClasses as composeClasses } from '@mui/material';
@@ -66,6 +66,10 @@ var GridIconButtonRoot = styled(IconButton)({
66
66
  });
67
67
  var collator = new Intl.Collator();
68
68
 
69
+ var defaultSearchPredicate = function defaultSearchPredicate(column, searchValue) {
70
+ return (column.headerName || column.field).toLowerCase().indexOf(searchValue) > -1;
71
+ };
72
+
69
73
  function GridColumnsPanel(props) {
70
74
  var _rootProps$components, _rootProps$components3, _rootProps$components4;
71
75
 
@@ -86,6 +90,8 @@ function GridColumnsPanel(props) {
86
90
  var classes = useUtilityClasses(ownerState);
87
91
 
88
92
  var sort = props.sort,
93
+ _props$searchPredicat = props.searchPredicate,
94
+ searchPredicate = _props$searchPredicat === void 0 ? defaultSearchPredicate : _props$searchPredicat,
89
95
  other = _objectWithoutProperties(props, _excluded);
90
96
 
91
97
  var sortedColumns = React.useMemo(function () {
@@ -146,9 +152,9 @@ function GridColumnsPanel(props) {
146
152
 
147
153
  var searchValueToCheck = searchValue.toLowerCase();
148
154
  return sortedColumns.filter(function (column) {
149
- return (column.headerName || column.field).toLowerCase().indexOf(searchValueToCheck) > -1;
155
+ return searchPredicate(column, searchValueToCheck);
150
156
  });
151
- }, [sortedColumns, searchValue]);
157
+ }, [sortedColumns, searchValue, searchPredicate]);
152
158
  React.useEffect(function () {
153
159
  searchInputRef.current.focus();
154
160
  }, []);
@@ -214,6 +220,7 @@ process.env.NODE_ENV !== "production" ? GridColumnsPanel.propTypes = {
214
220
  // | These PropTypes are generated from the TypeScript type definitions |
215
221
  // | To update them edit the TypeScript types and run "yarn proptypes" |
216
222
  // ----------------------------------------------------------------------
223
+ searchPredicate: PropTypes.func,
217
224
  sort: PropTypes.oneOf(['asc', 'desc'])
218
225
  } : void 0;
219
226
  export { GridColumnsPanel };
@@ -283,7 +283,7 @@ export var useGridColumnHeaders = function useGridColumnHeaders(props) {
283
283
 
284
284
  var columnsToRender = getColumnsToRender(params);
285
285
 
286
- if (columnsToRender == null) {
286
+ if (columnsToRender == null || columnsToRender.renderedColumns.length === 0) {
287
287
  return null;
288
288
  }
289
289
 
@@ -129,7 +129,8 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
129
129
 
130
130
  if (_reason) {
131
131
  var _newParams = _extends({}, params, {
132
- reason: _reason
132
+ reason: _reason,
133
+ key: event.key
133
134
  });
134
135
 
135
136
  apiRef.current.publishEvent('cellEditStart', _newParams, event);
@@ -139,13 +140,20 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
139
140
  var handleCellEditStart = React.useCallback(function (params) {
140
141
  var id = params.id,
141
142
  field = params.field,
142
- reason = params.reason;
143
+ reason = params.reason,
144
+ key = params.key;
143
145
  var startCellEditModeParams = {
144
146
  id: id,
145
147
  field: field
146
148
  };
147
149
 
148
- if (reason === GridCellEditStartReasons.deleteKeyDown || reason === GridCellEditStartReasons.printableKeyDown) {
150
+ if (reason === GridCellEditStartReasons.printableKeyDown) {
151
+ if (React.version.startsWith('18')) {
152
+ startCellEditModeParams.initialValue = key; // In React 17, cleaning the input is enough
153
+ } else {
154
+ startCellEditModeParams.deleteValue = true;
155
+ }
156
+ } else if (reason === GridCellEditStartReasons.deleteKeyDown) {
149
157
  startCellEditModeParams.deleteValue = true;
150
158
  }
151
159
 
@@ -268,9 +276,16 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
268
276
  var updateStateToStartCellEditMode = useEventCallback(function (params) {
269
277
  var id = params.id,
270
278
  field = params.field,
271
- deleteValue = params.deleteValue;
279
+ deleteValue = params.deleteValue,
280
+ initialValue = params.initialValue;
281
+ var newValue = apiRef.current.getCellValue(id, field);
282
+
283
+ if (deleteValue || initialValue) {
284
+ newValue = deleteValue ? '' : initialValue;
285
+ }
286
+
272
287
  var newProps = {
273
- value: deleteValue ? '' : apiRef.current.getCellValue(id, field),
288
+ value: newValue,
274
289
  error: false,
275
290
  isProcessingProps: false
276
291
  };
@@ -189,6 +189,7 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
189
189
 
190
190
  var _newParams = _extends({}, _rowParams, {
191
191
  field: params.field,
192
+ key: event.key,
192
193
  reason: _reason
193
194
  });
194
195
 
@@ -199,13 +200,20 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
199
200
  var handleRowEditStart = React.useCallback(function (params) {
200
201
  var id = params.id,
201
202
  field = params.field,
202
- reason = params.reason;
203
+ reason = params.reason,
204
+ key = params.key;
203
205
  var startRowEditModeParams = {
204
206
  id: id,
205
207
  fieldToFocus: field
206
208
  };
207
209
 
208
- if (reason === GridRowEditStartReasons.deleteKeyDown || reason === GridRowEditStartReasons.printableKeyDown) {
210
+ if (reason === GridRowEditStartReasons.printableKeyDown) {
211
+ if (React.version.startsWith('18')) {
212
+ startRowEditModeParams.initialValue = key; // In React 17, cleaning the input is enough
213
+ } else {
214
+ startRowEditModeParams.deleteValue = !!field;
215
+ }
216
+ } else if (reason === GridRowEditStartReasons.deleteKeyDown) {
209
217
  startRowEditModeParams.deleteValue = !!field;
210
218
  }
211
219
 
@@ -338,7 +346,8 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
338
346
  var updateStateToStartRowEditMode = useEventCallback(function (params) {
339
347
  var id = params.id,
340
348
  fieldToFocus = params.fieldToFocus,
341
- deleteValue = params.deleteValue;
349
+ deleteValue = params.deleteValue,
350
+ initialValue = params.initialValue;
342
351
  var columnFields = gridColumnFieldsSelector(apiRef);
343
352
  var newProps = columnFields.reduce(function (acc, field) {
344
353
  var cellParams = apiRef.current.getCellParams(id, field);
@@ -347,9 +356,14 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
347
356
  return acc;
348
357
  }
349
358
 
350
- var shouldDeleteValue = deleteValue && fieldToFocus === field;
359
+ var newValue = apiRef.current.getCellValue(id, field);
360
+
361
+ if (fieldToFocus === field && (deleteValue || initialValue)) {
362
+ newValue = deleteValue ? '' : initialValue;
363
+ }
364
+
351
365
  acc[field] = {
352
- value: shouldDeleteValue ? '' : apiRef.current.getCellValue(id, field),
366
+ value: newValue,
353
367
  error: false,
354
368
  isProcessingProps: false
355
369
  };
@@ -25,10 +25,12 @@ export var getRowIdFromRowModel = function getRowIdFromRowModel(rowModel, getRow
25
25
  export var createRowsInternalCache = function createRowsInternalCache(_ref) {
26
26
  var rows = _ref.rows,
27
27
  getRowId = _ref.getRowId,
28
- loading = _ref.loading;
28
+ loading = _ref.loading,
29
+ rowCount = _ref.rowCount;
29
30
  var cache = {
30
31
  rowsBeforePartialUpdates: rows,
31
32
  loadingPropBeforePartialUpdates: loading,
33
+ rowCountPropBeforePartialUpdates: rowCount,
32
34
  idRowsLookup: {},
33
35
  idToIdLookup: {},
34
36
  ids: []
@@ -16,7 +16,8 @@ export var rowsStateInitializer = function rowsStateInitializer(state, props, ap
16
16
  apiRef.current.unstable_caches.rows = createRowsInternalCache({
17
17
  rows: props.rows,
18
18
  getRowId: props.getRowId,
19
- loading: props.loading
19
+ loading: props.loading,
20
+ rowCount: props.rowCount
20
21
  });
21
22
  return _extends({}, state, {
22
23
  rows: getRowsStateFromCache({
@@ -100,9 +101,10 @@ export var useGridRows = function useGridRows(apiRef, props) {
100
101
  throttledRowsChange(createRowsInternalCache({
101
102
  rows: rows,
102
103
  getRowId: props.getRowId,
103
- loading: props.loading
104
+ loading: props.loading,
105
+ rowCount: props.rowCount
104
106
  }), true);
105
- }, [logger, props.getRowId, props.loading, throttledRowsChange]);
107
+ }, [logger, props.getRowId, props.loading, props.rowCount, throttledRowsChange]);
106
108
  var updateRows = React.useCallback(function (updates) {
107
109
  if (props.signature === GridSignature.DataGrid && updates.length > 1) {
108
110
  // TODO: Add test with direct call to `apiRef.current.updateRows` in DataGrid after enabling the `apiRef` on the free plan.
@@ -125,6 +127,7 @@ export var useGridRows = function useGridRows(apiRef, props) {
125
127
  var newCache = {
126
128
  rowsBeforePartialUpdates: prevCache.rowsBeforePartialUpdates,
127
129
  loadingPropBeforePartialUpdates: prevCache.loadingPropBeforePartialUpdates,
130
+ rowCountPropBeforePartialUpdates: prevCache.rowCountPropBeforePartialUpdates,
128
131
  idRowsLookup: _extends({}, prevCache.idRowsLookup),
129
132
  idToIdLookup: _extends({}, prevCache.idToIdLookup),
130
133
  ids: _toConsumableArray(prevCache.ids)
@@ -265,6 +268,7 @@ export var useGridRows = function useGridRows(apiRef, props) {
265
268
  })
266
269
  });
267
270
  });
271
+ apiRef.current.unstable_caches.rows.ids = updatedRows;
268
272
  apiRef.current.publishEvent('rowsSet');
269
273
  }, [apiRef, logger]);
270
274
  var replaceRows = React.useCallback(function (firstRowToRender, newRows) {
@@ -363,12 +367,13 @@ export var useGridRows = function useGridRows(apiRef, props) {
363
367
  cache = createRowsInternalCache({
364
368
  rows: props.rows,
365
369
  getRowId: props.getRowId,
366
- loading: props.loading
370
+ loading: props.loading,
371
+ rowCount: props.rowCount
367
372
  });
368
373
  }
369
374
 
370
375
  throttledRowsChange(cache, false);
371
- }, [logger, apiRef, props.rows, props.getRowId, props.loading, throttledRowsChange]);
376
+ }, [logger, apiRef, props.rows, props.getRowId, props.loading, props.rowCount, throttledRowsChange]);
372
377
  var handleStrategyProcessorChange = React.useCallback(function (methodName) {
373
378
  if (methodName === 'rowTreeCreation') {
374
379
  groupRows();
@@ -419,7 +424,8 @@ export var useGridRows = function useGridRows(apiRef, props) {
419
424
  }
420
425
 
421
426
  var areNewRowsAlreadyInState = apiRef.current.unstable_caches.rows.rowsBeforePartialUpdates === props.rows;
422
- var isNewLoadingAlreadyInState = apiRef.current.unstable_caches.rows.loadingPropBeforePartialUpdates === props.loading; // The new rows have already been applied (most likely in the `'rowGroupsPreProcessingChange'` listener)
427
+ var isNewLoadingAlreadyInState = apiRef.current.unstable_caches.rows.loadingPropBeforePartialUpdates === props.loading;
428
+ var isNewRowCountAlreadyInState = apiRef.current.unstable_caches.rows.rowCountPropBeforePartialUpdates === props.rowCount; // The new rows have already been applied (most likely in the `'rowGroupsPreProcessingChange'` listener)
423
429
 
424
430
  if (areNewRowsAlreadyInState) {
425
431
  // If the loading prop has changed, we need to update its value in the state because it won't be done by `throttledRowsChange`
@@ -435,6 +441,19 @@ export var useGridRows = function useGridRows(apiRef, props) {
435
441
  apiRef.current.forceUpdate();
436
442
  }
437
443
 
444
+ if (!isNewRowCountAlreadyInState) {
445
+ apiRef.current.setState(function (state) {
446
+ return _extends({}, state, {
447
+ rows: _extends({}, state.rows, {
448
+ totalRowCount: Math.max(props.rowCount || 0, state.rows.totalRowCount),
449
+ totalTopLevelRowCount: Math.max(props.rowCount || 0, state.rows.totalTopLevelRowCount)
450
+ })
451
+ });
452
+ });
453
+ apiRef.current.unstable_caches.rows.rowCountPropBeforePartialUpdates = props.rowCount;
454
+ apiRef.current.forceUpdate();
455
+ }
456
+
438
457
  return;
439
458
  }
440
459
 
@@ -442,7 +461,8 @@ export var useGridRows = function useGridRows(apiRef, props) {
442
461
  throttledRowsChange(createRowsInternalCache({
443
462
  rows: props.rows,
444
463
  getRowId: props.getRowId,
445
- loading: props.loading
464
+ loading: props.loading,
465
+ rowCount: props.rowCount
446
466
  }), false);
447
467
  }, [props.rows, props.rowCount, props.getRowId, props.loading, logger, throttledRowsChange, apiRef]);
448
468
  };
package/legacy/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.17.6
1
+ /** @license MUI v5.17.8
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.