@mui/x-data-grid 5.17.2 → 5.17.4

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 (62) hide show
  1. package/CHANGELOG.md +70 -2
  2. package/colDef/gridNumericOperators.d.ts +1 -1
  3. package/colDef/gridSingleSelectOperators.d.ts +1 -1
  4. package/colDef/gridStringOperators.d.ts +1 -1
  5. package/components/GridRow.js +5 -2
  6. package/components/cell/GridEditBooleanCell.js +1 -0
  7. package/components/cell/GridEditDateCell.js +1 -0
  8. package/components/cell/GridEditInputCell.js +21 -7
  9. package/components/cell/GridEditSingleSelectCell.js +1 -0
  10. package/hooks/features/editRows/useGridCellEditing.new.js +6 -3
  11. package/hooks/features/editRows/useGridEditing.new.js +9 -1
  12. package/hooks/features/editRows/useGridRowEditing.new.js +6 -3
  13. package/hooks/features/focus/useGridFocus.js +14 -15
  14. package/hooks/utils/useGridInitializeState.d.ts +1 -1
  15. package/index.js +1 -1
  16. package/legacy/components/GridRow.js +6 -2
  17. package/legacy/components/cell/GridEditBooleanCell.js +1 -0
  18. package/legacy/components/cell/GridEditDateCell.js +1 -0
  19. package/legacy/components/cell/GridEditInputCell.js +23 -9
  20. package/legacy/components/cell/GridEditSingleSelectCell.js +1 -0
  21. package/legacy/hooks/features/editRows/useGridCellEditing.new.js +5 -4
  22. package/legacy/hooks/features/editRows/useGridEditing.new.js +9 -1
  23. package/legacy/hooks/features/editRows/useGridRowEditing.new.js +6 -3
  24. package/legacy/hooks/features/focus/useGridFocus.js +14 -15
  25. package/legacy/index.js +1 -1
  26. package/legacy/locales/faIR.js +14 -14
  27. package/legacy/locales/fiFI.js +32 -28
  28. package/legacy/locales/plPL.js +7 -7
  29. package/locales/faIR.js +14 -14
  30. package/locales/fiFI.js +28 -28
  31. package/locales/plPL.js +7 -7
  32. package/models/api/gridEditingApi.d.ts +10 -0
  33. package/models/gridEditRowModel.d.ts +2 -0
  34. package/models/gridRows.d.ts +1 -1
  35. package/models/params/gridEditCellParams.d.ts +7 -3
  36. package/modern/components/GridRow.js +5 -2
  37. package/modern/components/cell/GridEditBooleanCell.js +1 -0
  38. package/modern/components/cell/GridEditDateCell.js +1 -0
  39. package/modern/components/cell/GridEditInputCell.js +18 -6
  40. package/modern/components/cell/GridEditSingleSelectCell.js +1 -0
  41. package/modern/hooks/features/editRows/useGridCellEditing.new.js +6 -3
  42. package/modern/hooks/features/editRows/useGridEditing.new.js +9 -1
  43. package/modern/hooks/features/editRows/useGridRowEditing.new.js +6 -3
  44. package/modern/hooks/features/focus/useGridFocus.js +14 -15
  45. package/modern/index.js +1 -1
  46. package/modern/locales/faIR.js +14 -14
  47. package/modern/locales/fiFI.js +28 -28
  48. package/modern/locales/plPL.js +7 -7
  49. package/node/components/GridRow.js +4 -2
  50. package/node/components/cell/GridEditBooleanCell.js +1 -0
  51. package/node/components/cell/GridEditDateCell.js +1 -0
  52. package/node/components/cell/GridEditInputCell.js +21 -7
  53. package/node/components/cell/GridEditSingleSelectCell.js +1 -0
  54. package/node/hooks/features/editRows/useGridCellEditing.new.js +6 -3
  55. package/node/hooks/features/editRows/useGridEditing.new.js +10 -1
  56. package/node/hooks/features/editRows/useGridRowEditing.new.js +6 -3
  57. package/node/hooks/features/focus/useGridFocus.js +14 -15
  58. package/node/index.js +1 -1
  59. package/node/locales/faIR.js +14 -14
  60. package/node/locales/fiFI.js +28 -28
  61. package/node/locales/plPL.js +7 -7
  62. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -3,6 +3,74 @@
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
+ ## v5.17.4
7
+
8
+ _Sep 22, 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
+ - 🌍 Add Finnish (fi-FI) locale to the pickers (#6230) @PetroSilenius
13
+ - 🌍 Add Persian (fa-IR) locale to the pickers (#6181) @fakhamatia
14
+ - 🐞 Bugfixes
15
+
16
+ ### `@mui/x-data-grid@v5.17.4` / `@mui/x-data-grid-pro@v5.17.4` / `@mui/x-data-grid-premium@v5.17.4`
17
+
18
+ #### Changes
19
+
20
+ - [DataGrid] Do not publish `cellFocusOut` event if the row was removed (#6251) @cherniavskii
21
+ - [DataGrid] Improve Polish (pl-PL) locale on the data grid (#6245) @grzegorz-bach
22
+
23
+ ### `@mui/x-date-pickers@v5.0.3` / `@mui/x-date-pickers-pro@v5.0.3`
24
+
25
+ #### Changes
26
+
27
+ - [pickers] Add Finnish (fi-FI) locale to pickers (#6219) (#6230) @PetroSilenius
28
+ - [pickers] Add Persian (fa-IR) locale to the pickers (#6181) @fakhamatia
29
+ - [pickers] Fix usage with Typescript 4.8 (#6229) @flaviendelangle
30
+ - [YearPicker] Scroll to the current year even with `autoFocus=false` (#6224) @alexfauquette
31
+
32
+ ### Docs
33
+
34
+ - [docs] Fix 301 link (#6239) @oliviertassinari
35
+
36
+ ### Core
37
+
38
+ - [core] Use the official repository for `@mui/monorepo` instead of a fork (#6189) @oliviertassinari
39
+
40
+ ## 5.17.3
41
+
42
+ _Sep 16, 2022_
43
+
44
+ We'd like to offer a big thanks to the 6 contributors who made this release possible. Here are some highlights ✨:
45
+
46
+ - 📝 Fix lost characters when typing into fields in the DataGrid (#5646) @m4theushw
47
+ - 🌏 New locale and improvements for pickers
48
+ - 🎁 Improve support to theme augmentation for pickers
49
+
50
+ ### `@mui/x-data-grid@v5.17.3` / `@mui/x-data-grid-pro@v5.17.3` / `@mui/x-data-grid-premium@v5.17.3`
51
+
52
+ #### Changes
53
+
54
+ - [DataGrid] Only update input with value prop if debounce is off (#5646) @m4theushw
55
+
56
+ ### `@mui/x-date-pickers@v5.0.2` / `@mui/x-date-pickers-pro@v5.0.2`
57
+
58
+ #### Changes
59
+
60
+ - [pickers] Add Icelandic (is-IS) locale (#6137) @elvatli
61
+ - [pickers] Fix `@mui/x-date-pickers` theme augmentation and style overriding (#6156) @LukasTy
62
+ - [pickers] Fix `@mui/x-date-pickers-pro` theme augmentation (#6096) @LukasTy
63
+ - [pickers] Improve German (de-DE) locale (#6138) @alexfauquette
64
+
65
+ ### Docs
66
+
67
+ - [docs] Improve main demo to show new functionalities (#5292) @joserodolfofreitas
68
+
69
+ ### Core
70
+
71
+ - [core] Update to typescript 4.8.3 (#6136) @flaviendelangle
72
+ - [core] Update RFC template (#6100) @bytasv
73
+
6
74
  ## 5.17.2
7
75
 
8
76
  _Sep 9, 2022_
@@ -11,7 +79,7 @@ This release will the last regular release for our `v5` packages.
11
79
  From now on, we'll be focusing on developing MUI X v6.
12
80
  You can check the [roadmap](https://github.com/mui/mui-x/projects/1) for more details on what's coming next.
13
81
 
14
- And if you'd like to help, please consider volunteering to give us a [user interview](https://docs.google.com/forms/d/11L_zxL7oD_B-ZrZDuSyIkUzJLzOTUU2M4vHXxMVtWhU/edit).
82
+ And if you'd like to help, please consider volunteering to give us a [user interview](https://forms.gle/vsBv6CLPz9h57xg8A).
15
83
  We'd love to know more about your use cases, pain points and expectations for the future.
16
84
 
17
85
  The `v5` packages will only get new versions to patch critical bug fixes.
@@ -67,7 +135,7 @@ We'd like to offer a big thanks to the 3 contributors who made this release poss
67
135
 
68
136
  _Sep 2, 2022_
69
137
 
70
- 🎉 We are excited to finally introduce a stable release (v5.0.0) for the `@mui/x-date-pickers` and `@mui/x-date-pickers-pro` packages!
138
+ 🎉 We are excited to finally introduce a stable release (v5.0.0) for the `@mui/x-date-pickers` and `@mui/x-date-pickers-pro` packages!
71
139
 
72
140
  If you are still using picker components from the `lab`, take a look at the [migration guide](https://mui.com/x/react-date-pickers/migration-lab/).
73
141
 
@@ -1,6 +1,6 @@
1
1
  import { GridFilterOperator } from '../models/gridFilterOperator';
2
2
  import { GridCellParams } from '../models';
3
- export declare const getGridNumericQuickFilterFn: (value: any) => (({ value: columnValue }: GridCellParams) => boolean) | null;
3
+ export declare const getGridNumericQuickFilterFn: (value: any) => (({ value }: GridCellParams) => boolean) | null;
4
4
  export declare const getGridNumericOperators: () => GridFilterOperator<any, number | string | null, any>[];
5
5
  /**
6
6
  * @deprecated Use `getGridNumericOperators` instead.
@@ -1,5 +1,5 @@
1
1
  import { GridFilterOperator } from '../models/gridFilterOperator';
2
2
  import { GridCellParams, GridColDef } from '../models';
3
3
  import { GridApiCommunity } from '../models/api/gridApiCommunity';
4
- export declare const getGridSingleSelectQuickFilterFn: (value: any, column: GridColDef, apiRef: React.MutableRefObject<GridApiCommunity>) => (({ value: columnValue }: GridCellParams) => boolean) | null;
4
+ export declare const getGridSingleSelectQuickFilterFn: (value: any, column: GridColDef, apiRef: React.MutableRefObject<GridApiCommunity>) => (({ value }: GridCellParams) => boolean) | null;
5
5
  export declare const getGridSingleSelectOperators: () => GridFilterOperator[];
@@ -1,4 +1,4 @@
1
1
  import { GridFilterOperator } from '../models/gridFilterOperator';
2
2
  import { GridCellParams } from '../models';
3
- export declare const getGridStringQuickFilterFn: (value: any) => (({ value: columnValue }: GridCellParams) => boolean) | null;
3
+ export declare const getGridStringQuickFilterFn: (value: any) => (({ value }: GridCellParams) => boolean) | null;
4
4
  export declare const getGridStringOperators: (disableTrim?: boolean) => GridFilterOperator<any, number | string | null, any>[];
@@ -1,6 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "cellFocus", "cellTabIndex", "editRowsState", "isLastVisible", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"];
3
+ const _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "cellFocus", "cellTabIndex", "editRowsState", "isLastVisible", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"],
4
+ _excluded2 = ["changeReason"];
4
5
  import * as React from 'react';
5
6
  import PropTypes from 'prop-types';
6
7
  import clsx from 'clsx';
@@ -231,9 +232,11 @@ function GridRow(props) {
231
232
  updatedRow = apiRef.current.unstable_getRowWithUpdatedValues(rowId, column.field);
232
233
  }
233
234
 
235
+ const editCellStateRest = _objectWithoutPropertiesLoose(editCellState, _excluded2);
236
+
234
237
  const params = _extends({}, cellParams, {
235
238
  row: updatedRow
236
- }, editCellState, {
239
+ }, editCellStateRest, {
237
240
  api: apiRef.current
238
241
  });
239
242
 
@@ -95,6 +95,7 @@ process.env.NODE_ENV !== "production" ? GridEditBooleanCell.propTypes = {
95
95
  * The mode of the cell.
96
96
  */
97
97
  cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
98
+ changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
98
99
 
99
100
  /**
100
101
  * The column of the row that the current cell belongs to.
@@ -149,6 +149,7 @@ process.env.NODE_ENV !== "production" ? GridEditDateCell.propTypes = {
149
149
  * The mode of the cell.
150
150
  */
151
151
  cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
152
+ changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
152
153
 
153
154
  /**
154
155
  * The column of the row that the current cell belongs to.
@@ -38,7 +38,7 @@ const GridEditInputCellRoot = styled(InputBase, {
38
38
  }
39
39
  }));
40
40
  const GridEditInputCell = /*#__PURE__*/React.forwardRef((props, ref) => {
41
- var _rootProps$experiment;
41
+ var _rootProps$experiment, _rootProps$experiment3;
42
42
 
43
43
  const rootProps = useGridRootProps();
44
44
 
@@ -62,23 +62,36 @@ const GridEditInputCell = /*#__PURE__*/React.forwardRef((props, ref) => {
62
62
  };
63
63
  const classes = useUtilityClasses(ownerState);
64
64
  const handleChange = React.useCallback(async event => {
65
+ var _rootProps$experiment2;
66
+
65
67
  const newValue = event.target.value;
66
68
 
67
69
  if (onValueChange) {
68
70
  await onValueChange(event, newValue);
69
71
  }
70
72
 
71
- setValueState(newValue);
73
+ const column = apiRef.current.getColumn(field);
74
+ let parsedValue = newValue;
75
+
76
+ if (column.valueParser && (_rootProps$experiment2 = rootProps.experimentalFeatures) != null && _rootProps$experiment2.newEditingApi) {
77
+ parsedValue = column.valueParser(newValue, apiRef.current.getCellParams(id, field));
78
+ }
79
+
80
+ setValueState(parsedValue);
72
81
  apiRef.current.setEditCellValue({
73
82
  id,
74
83
  field,
75
- value: newValue,
76
- debounceMs
84
+ value: parsedValue,
85
+ debounceMs,
86
+ unstable_skipValueParser: true
77
87
  }, event);
78
- }, [apiRef, debounceMs, field, id, onValueChange]);
88
+ }, [apiRef, debounceMs, field, id, onValueChange, (_rootProps$experiment3 = rootProps.experimentalFeatures) == null ? void 0 : _rootProps$experiment3.newEditingApi]);
89
+ const meta = apiRef.current.unstable_getEditCellMeta ? apiRef.current.unstable_getEditCellMeta(id, field) : {};
79
90
  React.useEffect(() => {
80
- setValueState(value);
81
- }, [value]);
91
+ if (meta.changeReason !== 'debouncedSetEditCellValue') {
92
+ setValueState(value);
93
+ }
94
+ }, [meta.changeReason, value]);
82
95
  useEnhancedEffect(() => {
83
96
  if (hasFocus) {
84
97
  inputRef.current.focus();
@@ -111,6 +124,7 @@ process.env.NODE_ENV !== "production" ? GridEditInputCell.propTypes = {
111
124
  * The mode of the cell.
112
125
  */
113
126
  cellMode: PropTypes.oneOf(['edit', 'view']),
127
+ changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
114
128
 
115
129
  /**
116
130
  * The column of the row that the current cell belongs to.
@@ -193,6 +193,7 @@ process.env.NODE_ENV !== "production" ? GridEditSingleSelectCell.propTypes = {
193
193
  * The mode of the cell.
194
194
  */
195
195
  cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
196
+ changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
196
197
 
197
198
  /**
198
199
  * The column of the row that the current cell belongs to.
@@ -361,7 +361,9 @@ export const useGridCellEditing = (apiRef, props) => {
361
361
  const {
362
362
  id,
363
363
  field,
364
- value
364
+ value,
365
+ debounceMs,
366
+ unstable_skipValueParser: skipValueParser
365
367
  } = params;
366
368
  throwIfNotEditable(id, field);
367
369
  throwIfNotInMode(id, field, GridCellModes.Edit);
@@ -369,14 +371,15 @@ export const useGridCellEditing = (apiRef, props) => {
369
371
  const row = apiRef.current.getRow(id);
370
372
  let parsedValue = value;
371
373
 
372
- if (column.valueParser) {
374
+ if (column.valueParser && !skipValueParser) {
373
375
  parsedValue = column.valueParser(value, apiRef.current.getCellParams(id, field));
374
376
  }
375
377
 
376
378
  let editingState = gridEditRowsStateSelector(apiRef.current.state);
377
379
 
378
380
  let newProps = _extends({}, editingState[id][field], {
379
- value: parsedValue
381
+ value: parsedValue,
382
+ changeReason: debounceMs ? 'debouncedSetEditCellValue' : 'setEditCellValue'
380
383
  });
381
384
 
382
385
  if (column.preProcessEditCellProps) {
@@ -4,6 +4,7 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod';
4
4
  import { useGridCellEditing } from './useGridCellEditing.new';
5
5
  import { GridCellModes, GridEditModes } from '../../../models/gridEditRowModel';
6
6
  import { useGridRowEditing } from './useGridRowEditing.new';
7
+ import { gridEditRowsStateSelector } from './gridEditRowsSelector';
7
8
  export const editingStateInitializer = state => _extends({}, state, {
8
9
  editRows: {}
9
10
  });
@@ -116,11 +117,18 @@ export const useGridEditing = (apiRef, props) => {
116
117
  const getRowWithUpdatedValues = React.useCallback((id, field) => {
117
118
  return props.editMode === GridEditModes.Cell ? apiRef.current.unstable_getRowWithUpdatedValuesFromCellEditing(id, field) : apiRef.current.unstable_getRowWithUpdatedValuesFromRowEditing(id);
118
119
  }, [apiRef, props.editMode]);
120
+ const getEditCellMeta = React.useCallback((id, field) => {
121
+ const editingState = gridEditRowsStateSelector(apiRef.current.state);
122
+ return {
123
+ changeReason: editingState[id][field].changeReason
124
+ };
125
+ }, [apiRef]);
119
126
  const editingSharedApi = {
120
127
  isCellEditable,
121
128
  setEditCellValue,
122
129
  unstable_runPendingEditCellValueMutation: runPendingEditCellValueMutation,
123
- unstable_getRowWithUpdatedValues: getRowWithUpdatedValues
130
+ unstable_getRowWithUpdatedValues: getRowWithUpdatedValues,
131
+ unstable_getEditCellMeta: getEditCellMeta
124
132
  };
125
133
  useGridApiMethod(apiRef, editingSharedApi, 'EditingApi');
126
134
  };
@@ -442,21 +442,24 @@ export const useGridRowEditing = (apiRef, props) => {
442
442
  const {
443
443
  id,
444
444
  field,
445
- value
445
+ value,
446
+ debounceMs,
447
+ unstable_skipValueParser: skipValueParser
446
448
  } = params;
447
449
  throwIfNotEditable(id, field);
448
450
  const column = apiRef.current.getColumn(field);
449
451
  const row = apiRef.current.getRow(id);
450
452
  let parsedValue = value;
451
453
 
452
- if (column.valueParser) {
454
+ if (column.valueParser && !skipValueParser) {
453
455
  parsedValue = column.valueParser(value, apiRef.current.getCellParams(id, field));
454
456
  }
455
457
 
456
458
  let editingState = gridEditRowsStateSelector(apiRef.current.state);
457
459
 
458
460
  let newProps = _extends({}, editingState[id][field], {
459
- value: parsedValue
461
+ value: parsedValue,
462
+ changeReason: debounceMs ? 'debouncedSetEditCellValue' : 'setEditCellValue'
460
463
  });
461
464
 
462
465
  if (!column.preProcessEditCellProps) {
@@ -28,6 +28,14 @@ export const focusStateInitializer = state => _extends({}, state, {
28
28
  export const useGridFocus = (apiRef, props) => {
29
29
  const logger = useGridLogger(apiRef, 'useGridFocus');
30
30
  const lastClickedCell = React.useRef(null);
31
+ const publishCellFocusOut = React.useCallback((cell, event) => {
32
+ if (cell) {
33
+ // The row might have been deleted
34
+ if (apiRef.current.getRow(cell.id)) {
35
+ apiRef.current.publishEvent('cellFocusOut', apiRef.current.getCellParams(cell.id, cell.field), event);
36
+ }
37
+ }
38
+ }, [apiRef]);
31
39
  const setCellFocus = React.useCallback((id, field) => {
32
40
  const focusedCell = gridFocusCellSelector(apiRef);
33
41
 
@@ -63,18 +71,14 @@ export const useGridFocus = (apiRef, props) => {
63
71
  if (focusedCell) {
64
72
  // There's a focused cell but another cell was clicked
65
73
  // Publishes an event to notify that the focus was lost
66
- apiRef.current.publishEvent('cellFocusOut', apiRef.current.getCellParams(focusedCell.id, focusedCell.field));
74
+ publishCellFocusOut(focusedCell, {});
67
75
  }
68
76
 
69
77
  apiRef.current.publishEvent('cellFocusIn', apiRef.current.getCellParams(id, field));
70
- }, [apiRef, logger]);
78
+ }, [apiRef, logger, publishCellFocusOut]);
71
79
  const setColumnHeaderFocus = React.useCallback((field, event = {}) => {
72
80
  const cell = gridFocusCellSelector(apiRef);
73
-
74
- if (cell) {
75
- apiRef.current.publishEvent('cellFocusOut', apiRef.current.getCellParams(cell.id, cell.field), event);
76
- }
77
-
81
+ publishCellFocusOut(cell, event);
78
82
  apiRef.current.setState(state => {
79
83
  logger.debug(`Focusing on column header with colIndex=${field}`);
80
84
  return _extends({}, state, {
@@ -93,7 +97,7 @@ export const useGridFocus = (apiRef, props) => {
93
97
  });
94
98
  });
95
99
  apiRef.current.forceUpdate();
96
- }, [apiRef, logger]);
100
+ }, [apiRef, logger, publishCellFocusOut]);
97
101
  const moveFocusToRelativeCell = React.useCallback((id, field, direction) => {
98
102
  let columnIndexToFocus = apiRef.current.getColumnIndex(field);
99
103
  let rowIndexToFocus = apiRef.current.getRowIndexRelativeToVisibleRows(id);
@@ -202,11 +206,6 @@ export const useGridFocus = (apiRef, props) => {
202
206
 
203
207
  if (cellElement != null && cellElement.contains(event.target)) {
204
208
  return;
205
- } // The row might have been deleted during the click
206
-
207
-
208
- if (!apiRef.current.getRow(focusedCell.id)) {
209
- return;
210
209
  }
211
210
 
212
211
  if (cellParams) {
@@ -221,9 +220,9 @@ export const useGridFocus = (apiRef, props) => {
221
220
  apiRef.current.forceUpdate(); // There's a focused cell but another element (not a cell) was clicked
222
221
  // Publishes an event to notify that the focus was lost
223
222
 
224
- apiRef.current.publishEvent('cellFocusOut', apiRef.current.getCellParams(focusedCell.id, focusedCell.field), event);
223
+ publishCellFocusOut(focusedCell, event);
225
224
  }
226
- }, [apiRef]);
225
+ }, [apiRef, publishCellFocusOut]);
227
226
  const handleCellModeChange = React.useCallback(params => {
228
227
  if (params.cellMode === 'view') {
229
228
  return;
@@ -6,5 +6,5 @@ declare type DeepPartial<T> = {
6
6
  [P in keyof T]?: DeepPartial<T[P]>;
7
7
  };
8
8
  export declare type GridStateInitializer<P extends Partial<DataGridProcessedProps> = DataGridProcessedProps, Api extends GridApiCommon = GridApiCommunity> = (state: DeepPartial<Api['state']>, props: P, apiRef: React.MutableRefObject<Api>) => DeepPartial<Api['state']>;
9
- export declare const useGridInitializeState: <P, Api extends GridApiCommon = GridApiCommunity>(initializer: GridStateInitializer<P, Api>, apiRef: React.MutableRefObject<Api>, props: P) => void;
9
+ export declare const useGridInitializeState: <P extends Partial<DataGridProcessedProps<any>>, Api extends GridApiCommon = GridApiCommunity>(initializer: GridStateInitializer<P, Api>, apiRef: React.MutableRefObject<Api>, props: P) => void;
10
10
  export {};
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.17.2
1
+ /** @license MUI v5.17.4
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.
@@ -2,7 +2,8 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
- var _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "cellFocus", "cellTabIndex", "editRowsState", "isLastVisible", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"];
5
+ var _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "cellFocus", "cellTabIndex", "editRowsState", "isLastVisible", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"],
6
+ _excluded2 = ["changeReason"];
6
7
  import * as React from 'react';
7
8
  import PropTypes from 'prop-types';
8
9
  import clsx from 'clsx';
@@ -237,9 +238,12 @@ function GridRow(props) {
237
238
  updatedRow = apiRef.current.unstable_getRowWithUpdatedValues(rowId, column.field);
238
239
  }
239
240
 
241
+ var changeReason = editCellState.changeReason,
242
+ editCellStateRest = _objectWithoutProperties(editCellState, _excluded2);
243
+
240
244
  var params = _extends({}, cellParams, {
241
245
  row: updatedRow
242
- }, editCellState, {
246
+ }, editCellStateRest, {
243
247
  api: apiRef.current
244
248
  });
245
249
 
@@ -135,6 +135,7 @@ process.env.NODE_ENV !== "production" ? GridEditBooleanCell.propTypes = {
135
135
  * The mode of the cell.
136
136
  */
137
137
  cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
138
+ changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
138
139
 
139
140
  /**
140
141
  * The column of the row that the current cell belongs to.
@@ -186,6 +186,7 @@ process.env.NODE_ENV !== "production" ? GridEditDateCell.propTypes = {
186
186
  * The mode of the cell.
187
187
  */
188
188
  cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
189
+ changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
189
190
 
190
191
  /**
191
192
  * The column of the row that the current cell belongs to.
@@ -42,7 +42,7 @@ var GridEditInputCellRoot = styled(InputBase, {
42
42
  });
43
43
  });
44
44
  var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
45
- var _rootProps$experiment;
45
+ var _rootProps$experiment, _rootProps$experiment3;
46
46
 
47
47
  var rootProps = useGridRootProps();
48
48
 
@@ -80,7 +80,9 @@ var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
80
80
  var classes = useUtilityClasses(ownerState);
81
81
  var handleChange = React.useCallback( /*#__PURE__*/function () {
82
82
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(event) {
83
- var newValue;
83
+ var _rootProps$experiment2;
84
+
85
+ var newValue, column, parsedValue;
84
86
  return _regeneratorRuntime.wrap(function _callee$(_context) {
85
87
  while (1) {
86
88
  switch (_context.prev = _context.next) {
@@ -96,15 +98,23 @@ var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
96
98
  return onValueChange(event, newValue);
97
99
 
98
100
  case 4:
99
- setValueState(newValue);
101
+ column = apiRef.current.getColumn(field);
102
+ parsedValue = newValue;
103
+
104
+ if (column.valueParser && (_rootProps$experiment2 = rootProps.experimentalFeatures) != null && _rootProps$experiment2.newEditingApi) {
105
+ parsedValue = column.valueParser(newValue, apiRef.current.getCellParams(id, field));
106
+ }
107
+
108
+ setValueState(parsedValue);
100
109
  apiRef.current.setEditCellValue({
101
110
  id: id,
102
111
  field: field,
103
- value: newValue,
104
- debounceMs: debounceMs
112
+ value: parsedValue,
113
+ debounceMs: debounceMs,
114
+ unstable_skipValueParser: true
105
115
  }, event);
106
116
 
107
- case 6:
117
+ case 9:
108
118
  case "end":
109
119
  return _context.stop();
110
120
  }
@@ -115,10 +125,13 @@ var GridEditInputCell = /*#__PURE__*/React.forwardRef(function (props, ref) {
115
125
  return function (_x) {
116
126
  return _ref2.apply(this, arguments);
117
127
  };
118
- }(), [apiRef, debounceMs, field, id, onValueChange]);
128
+ }(), [apiRef, debounceMs, field, id, onValueChange, (_rootProps$experiment3 = rootProps.experimentalFeatures) == null ? void 0 : _rootProps$experiment3.newEditingApi]);
129
+ var meta = apiRef.current.unstable_getEditCellMeta ? apiRef.current.unstable_getEditCellMeta(id, field) : {};
119
130
  React.useEffect(function () {
120
- setValueState(value);
121
- }, [value]);
131
+ if (meta.changeReason !== 'debouncedSetEditCellValue') {
132
+ setValueState(value);
133
+ }
134
+ }, [meta.changeReason, value]);
122
135
  useEnhancedEffect(function () {
123
136
  if (hasFocus) {
124
137
  inputRef.current.focus();
@@ -151,6 +164,7 @@ process.env.NODE_ENV !== "production" ? GridEditInputCell.propTypes = {
151
164
  * The mode of the cell.
152
165
  */
153
166
  cellMode: PropTypes.oneOf(['edit', 'view']),
167
+ changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
154
168
 
155
169
  /**
156
170
  * The column of the row that the current cell belongs to.
@@ -250,6 +250,7 @@ process.env.NODE_ENV !== "production" ? GridEditSingleSelectCell.propTypes = {
250
250
  * The mode of the cell.
251
251
  */
252
252
  cellMode: PropTypes.oneOf(['edit', 'view']).isRequired,
253
+ changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
253
254
 
254
255
  /**
255
256
  * The column of the row that the current cell belongs to.
@@ -373,25 +373,26 @@ export var useGridCellEditing = function useGridCellEditing(apiRef, props) {
373
373
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
374
374
  var _editingState$id, _editingState$id$fiel2;
375
375
 
376
- var id, field, value, column, row, parsedValue, editingState, newProps, hasChanged;
376
+ var id, field, value, debounceMs, skipValueParser, column, row, parsedValue, editingState, newProps, hasChanged;
377
377
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
378
378
  while (1) {
379
379
  switch (_context2.prev = _context2.next) {
380
380
  case 0:
381
- id = params.id, field = params.field, value = params.value;
381
+ id = params.id, field = params.field, value = params.value, debounceMs = params.debounceMs, skipValueParser = params.unstable_skipValueParser;
382
382
  throwIfNotEditable(id, field);
383
383
  throwIfNotInMode(id, field, GridCellModes.Edit);
384
384
  column = apiRef.current.getColumn(field);
385
385
  row = apiRef.current.getRow(id);
386
386
  parsedValue = value;
387
387
 
388
- if (column.valueParser) {
388
+ if (column.valueParser && !skipValueParser) {
389
389
  parsedValue = column.valueParser(value, apiRef.current.getCellParams(id, field));
390
390
  }
391
391
 
392
392
  editingState = gridEditRowsStateSelector(apiRef.current.state);
393
393
  newProps = _extends({}, editingState[id][field], {
394
- value: parsedValue
394
+ value: parsedValue,
395
+ changeReason: debounceMs ? 'debouncedSetEditCellValue' : 'setEditCellValue'
395
396
  });
396
397
 
397
398
  if (!column.preProcessEditCellProps) {
@@ -7,6 +7,7 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod';
7
7
  import { useGridCellEditing } from './useGridCellEditing.new';
8
8
  import { GridCellModes, GridEditModes } from '../../../models/gridEditRowModel';
9
9
  import { useGridRowEditing } from './useGridRowEditing.new';
10
+ import { gridEditRowsStateSelector } from './gridEditRowsSelector';
10
11
  export var editingStateInitializer = function editingStateInitializer(state) {
11
12
  return _extends({}, state, {
12
13
  editRows: {}
@@ -150,11 +151,18 @@ export var useGridEditing = function useGridEditing(apiRef, props) {
150
151
  var getRowWithUpdatedValues = React.useCallback(function (id, field) {
151
152
  return props.editMode === GridEditModes.Cell ? apiRef.current.unstable_getRowWithUpdatedValuesFromCellEditing(id, field) : apiRef.current.unstable_getRowWithUpdatedValuesFromRowEditing(id);
152
153
  }, [apiRef, props.editMode]);
154
+ var getEditCellMeta = React.useCallback(function (id, field) {
155
+ var editingState = gridEditRowsStateSelector(apiRef.current.state);
156
+ return {
157
+ changeReason: editingState[id][field].changeReason
158
+ };
159
+ }, [apiRef]);
153
160
  var editingSharedApi = {
154
161
  isCellEditable: isCellEditable,
155
162
  setEditCellValue: setEditCellValue,
156
163
  unstable_runPendingEditCellValueMutation: runPendingEditCellValueMutation,
157
- unstable_getRowWithUpdatedValues: getRowWithUpdatedValues
164
+ unstable_getRowWithUpdatedValues: getRowWithUpdatedValues,
165
+ unstable_getEditCellMeta: getEditCellMeta
158
166
  };
159
167
  useGridApiMethod(apiRef, editingSharedApi, 'EditingApi');
160
168
  };
@@ -440,20 +440,23 @@ export var useGridRowEditing = function useGridRowEditing(apiRef, props) {
440
440
  var setRowEditingEditCellValue = React.useCallback(function (params) {
441
441
  var id = params.id,
442
442
  field = params.field,
443
- value = params.value;
443
+ value = params.value,
444
+ debounceMs = params.debounceMs,
445
+ skipValueParser = params.unstable_skipValueParser;
444
446
  throwIfNotEditable(id, field);
445
447
  var column = apiRef.current.getColumn(field);
446
448
  var row = apiRef.current.getRow(id);
447
449
  var parsedValue = value;
448
450
 
449
- if (column.valueParser) {
451
+ if (column.valueParser && !skipValueParser) {
450
452
  parsedValue = column.valueParser(value, apiRef.current.getCellParams(id, field));
451
453
  }
452
454
 
453
455
  var editingState = gridEditRowsStateSelector(apiRef.current.state);
454
456
 
455
457
  var newProps = _extends({}, editingState[id][field], {
456
- value: parsedValue
458
+ value: parsedValue,
459
+ changeReason: debounceMs ? 'debouncedSetEditCellValue' : 'setEditCellValue'
457
460
  });
458
461
 
459
462
  if (!column.preProcessEditCellProps) {