@mui/x-data-grid 6.17.0 → 6.18.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 (69) hide show
  1. package/CHANGELOG.md +124 -5
  2. package/DataGrid/DataGrid.js +6 -0
  3. package/DataGrid/useDataGridProps.js +1 -0
  4. package/colDef/gridStringOperators.js +5 -1
  5. package/components/cell/GridActionsCell.js +19 -12
  6. package/components/cell/GridCell.js +4 -4
  7. package/components/containers/GridRootStyles.js +2 -1
  8. package/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.js +6 -2
  9. package/hooks/core/useGridInitialization.d.ts +1 -1
  10. package/hooks/core/useGridInitialization.js +3 -0
  11. package/hooks/features/filter/gridFilterUtils.d.ts +9 -25
  12. package/hooks/features/filter/gridFilterUtils.js +61 -27
  13. package/hooks/features/filter/useGridFilter.d.ts +1 -1
  14. package/hooks/features/filter/useGridFilter.js +4 -3
  15. package/index.js +1 -1
  16. package/internals/index.d.ts +1 -0
  17. package/internals/index.js +1 -0
  18. package/internals/utils/computeSlots.js +8 -1
  19. package/legacy/DataGrid/DataGrid.js +6 -0
  20. package/legacy/DataGrid/useDataGridProps.js +1 -0
  21. package/legacy/colDef/gridStringOperators.js +4 -0
  22. package/legacy/components/cell/GridActionsCell.js +21 -12
  23. package/legacy/components/cell/GridCell.js +6 -4
  24. package/legacy/components/containers/GridRootStyles.js +2 -1
  25. package/legacy/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.js +6 -2
  26. package/legacy/hooks/core/useGridInitialization.js +3 -0
  27. package/legacy/hooks/features/filter/gridFilterUtils.js +47 -21
  28. package/legacy/hooks/features/filter/useGridFilter.js +4 -3
  29. package/legacy/index.js +1 -1
  30. package/legacy/internals/index.js +1 -0
  31. package/legacy/internals/utils/computeSlots.js +8 -1
  32. package/legacy/utils/getPublicApiRef.js +5 -0
  33. package/models/api/gridApiCommon.d.ts +3 -2
  34. package/models/api/gridApiCommunity.d.ts +2 -1
  35. package/models/api/gridCoreApi.d.ts +7 -1
  36. package/models/api/gridFilterApi.d.ts +6 -1
  37. package/models/api/gridLocaleTextApi.d.ts +3 -2
  38. package/models/props/DataGridProps.d.ts +6 -0
  39. package/modern/DataGrid/DataGrid.js +6 -0
  40. package/modern/DataGrid/useDataGridProps.js +1 -0
  41. package/modern/colDef/gridStringOperators.js +5 -1
  42. package/modern/components/cell/GridActionsCell.js +18 -12
  43. package/modern/components/cell/GridCell.js +3 -3
  44. package/modern/components/containers/GridRootStyles.js +2 -1
  45. package/modern/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.js +6 -2
  46. package/modern/hooks/core/useGridInitialization.js +3 -0
  47. package/modern/hooks/features/filter/gridFilterUtils.js +61 -27
  48. package/modern/hooks/features/filter/useGridFilter.js +4 -3
  49. package/modern/index.js +1 -1
  50. package/modern/internals/index.js +1 -0
  51. package/modern/internals/utils/computeSlots.js +8 -1
  52. package/modern/utils/getPublicApiRef.js +5 -0
  53. package/node/DataGrid/DataGrid.js +6 -0
  54. package/node/DataGrid/useDataGridProps.js +1 -0
  55. package/node/colDef/gridStringOperators.js +5 -1
  56. package/node/components/cell/GridActionsCell.js +18 -12
  57. package/node/components/cell/GridCell.js +3 -3
  58. package/node/components/containers/GridRootStyles.js +2 -1
  59. package/node/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.js +6 -2
  60. package/node/hooks/core/useGridInitialization.js +3 -0
  61. package/node/hooks/features/filter/gridFilterUtils.js +63 -30
  62. package/node/hooks/features/filter/useGridFilter.js +4 -3
  63. package/node/index.js +1 -1
  64. package/node/internals/index.js +12 -0
  65. package/node/internals/utils/computeSlots.js +8 -1
  66. package/node/utils/getPublicApiRef.js +11 -0
  67. package/package.json +2 -2
  68. package/utils/getPublicApiRef.d.ts +3 -0
  69. package/utils/getPublicApiRef.js +5 -0
@@ -4,12 +4,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.sanitizeFilterModel = exports.passFilterLogic = exports.mergeStateWithFilterModel = exports.cleanFilterItem = exports.buildAggregatedQuickFilterApplier = exports.buildAggregatedFilterItemsApplier = exports.buildAggregatedFilterApplier = void 0;
7
+ exports.sanitizeFilterModel = exports.removeDiacritics = exports.passFilterLogic = exports.mergeStateWithFilterModel = exports.cleanFilterItem = exports.buildAggregatedFilterApplier = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _models = require("../../../models");
10
10
  var _utils = require("../../../colDef/utils");
11
11
  var _gridFilterState = require("./gridFilterState");
12
12
  var _warning = require("../../../utils/warning");
13
+ var _getPublicApiRef = require("../../../utils/getPublicApiRef");
13
14
  var _columns = require("../columns");
14
15
  // Fixes https://github.com/mui/mui-x/issues/10056
15
16
  const globalScope = typeof window === 'undefined' ? globalThis : window;
@@ -23,7 +24,7 @@ try {
23
24
  /**
24
25
  * Adds default values to the optional fields of a filter items.
25
26
  * @param {GridFilterItem} item The raw filter item.
26
- * @param {React.MutableRefObject<GridApiCommunity>} apiRef The API of the grid.
27
+ * @param {React.MutableRefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
27
28
  * @return {GridFilterItem} The clean filter item with an uniq ID and an always-defined operator.
28
29
  * TODO: Make the typing reflect the different between GridFilterInputItem and GridFilterItem.
29
30
  */
@@ -78,6 +79,13 @@ const mergeStateWithFilterModel = (filterModel, disableMultipleColumnsFiltering,
78
79
  filterModel: sanitizeFilterModel(filterModel, disableMultipleColumnsFiltering, apiRef)
79
80
  });
80
81
  exports.mergeStateWithFilterModel = mergeStateWithFilterModel;
82
+ const removeDiacritics = value => {
83
+ if (typeof value === 'string') {
84
+ return value.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
85
+ }
86
+ return value;
87
+ };
88
+ exports.removeDiacritics = removeDiacritics;
81
89
  const getFilterCallbackFromItem = (filterItem, apiRef) => {
82
90
  if (!filterItem.field || !filterItem.operator) {
83
91
  return null;
@@ -93,6 +101,12 @@ const getFilterCallbackFromItem = (filterItem, apiRef) => {
93
101
  } else {
94
102
  parsedValue = filterItem.value;
95
103
  }
104
+ const {
105
+ ignoreDiacritics
106
+ } = apiRef.current.rootProps;
107
+ if (ignoreDiacritics) {
108
+ parsedValue = removeDiacritics(parsedValue);
109
+ }
96
110
  const newFilterItem = (0, _extends2.default)({}, filterItem, {
97
111
  value: parsedValue
98
112
  });
@@ -106,6 +120,7 @@ const getFilterCallbackFromItem = (filterItem, apiRef) => {
106
120
  }
107
121
  const hasUserFunctionLegacy = !(0, _utils.isInternalFilter)(filterOperator.getApplyFilterFn);
108
122
  const hasUserFunctionV7 = !(0, _utils.isInternalFilter)(filterOperator.getApplyFilterFnV7);
123
+ const publicApiRef = (0, _getPublicApiRef.getPublicApiRef)(apiRef);
109
124
  if (filterOperator.getApplyFilterFnV7 && !(hasUserFunctionLegacy && !hasUserFunctionV7)) {
110
125
  const applyFilterOnRow = filterOperator.getApplyFilterFnV7(newFilterItem, column);
111
126
  if (typeof applyFilterOnRow !== 'function') {
@@ -115,8 +130,11 @@ const getFilterCallbackFromItem = (filterItem, apiRef) => {
115
130
  v7: true,
116
131
  item: newFilterItem,
117
132
  fn: row => {
118
- const value = apiRef.current.getRowValue(row, column);
119
- return applyFilterOnRow(value, row, column, apiRef);
133
+ let value = apiRef.current.getRowValue(row, column);
134
+ if (ignoreDiacritics) {
135
+ value = removeDiacritics(value);
136
+ }
137
+ return applyFilterOnRow(value, row, column, publicApiRef);
120
138
  }
121
139
  };
122
140
  }
@@ -129,7 +147,10 @@ const getFilterCallbackFromItem = (filterItem, apiRef) => {
129
147
  item: newFilterItem,
130
148
  fn: rowId => {
131
149
  const params = apiRef.current.getCellParams(rowId, newFilterItem.field);
132
- _utils.GLOBAL_API_REF.current = apiRef;
150
+ _utils.GLOBAL_API_REF.current = publicApiRef;
151
+ if (ignoreDiacritics) {
152
+ params.value = removeDiacritics(params.value);
153
+ }
133
154
  const result = applyFilterOnRow(params);
134
155
  _utils.GLOBAL_API_REF.current = null;
135
156
  return result;
@@ -140,12 +161,11 @@ let filterItemsApplierId = 1;
140
161
 
141
162
  /**
142
163
  * Generates a method to easily check if a row is matching the current filter model.
143
- * @param {GridRowIdGetter | undefined} getRowId The getter for row's id.
144
164
  * @param {GridFilterModel} filterModel The model with which we want to filter the rows.
145
- * @param {React.MutableRefObject<GridApiCommunity>} apiRef The API of the grid.
165
+ * @param {React.MutableRefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
146
166
  * @returns {GridAggregatedFilterItemApplier | null} A method that checks if a row is matching the current filter model. If `null`, we consider that all the rows are matching the filters.
147
167
  */
148
- const buildAggregatedFilterItemsApplier = (getRowId, filterModel, apiRef, disableEval) => {
168
+ const buildAggregatedFilterItemsApplier = (filterModel, apiRef, disableEval) => {
149
169
  const {
150
170
  items
151
171
  } = filterModel;
@@ -160,7 +180,7 @@ const buildAggregatedFilterItemsApplier = (getRowId, filterModel, apiRef, disabl
160
180
  for (let i = 0; i < appliers.length; i += 1) {
161
181
  const applier = appliers[i];
162
182
  if (!shouldApplyFilter || shouldApplyFilter(applier.item.field)) {
163
- resultPerItemId[applier.item.id] = applier.v7 ? applier.fn(row) : applier.fn(getRowId ? getRowId(row) : row.id);
183
+ resultPerItemId[applier.item.id] = applier.v7 ? applier.fn(row) : applier.fn(apiRef.current.getRowId(row));
164
184
  }
165
185
  }
166
186
  return resultPerItemId;
@@ -176,14 +196,14 @@ const buildAggregatedFilterItemsApplier = (getRowId, filterModel, apiRef, disabl
176
196
  ${appliers.map((applier, i) => `${JSON.stringify(String(applier.item.id))}:
177
197
  !shouldApply${i} ?
178
198
  false :
179
- ${applier.v7 ? `appliers[${i}].fn(row)` : `appliers[${i}].fn(${getRowId ? 'getRowId(row)' : 'row.id'})`},
199
+ ${applier.v7 ? `appliers[${i}].fn(row)` : `appliers[${i}].fn(getRowId(row))`},
180
200
  `).join('\n')}};
181
201
 
182
202
  return result$$;
183
203
  })`;
184
204
  const filterItemCore = evalCode(filterItemTemplate.replaceAll('$$', String(filterItemsApplierId)));
185
205
  const filterItem = (row, shouldApplyItem) => {
186
- return filterItemCore(getRowId, appliers, row, shouldApplyItem);
206
+ return filterItemCore(apiRef.current.getRowId, appliers, row, shouldApplyItem);
187
207
  };
188
208
  filterItemsApplierId += 1;
189
209
  return filterItem;
@@ -191,13 +211,11 @@ const buildAggregatedFilterItemsApplier = (getRowId, filterModel, apiRef, disabl
191
211
 
192
212
  /**
193
213
  * Generates a method to easily check if a row is matching the current quick filter.
194
- * @param {GridRowIdGetter | undefined} getRowId The getter for row's id.
195
214
  * @param {any[]} filterModel The model with which we want to filter the rows.
196
- * @param {React.MutableRefObject<GridApiCommunity>} apiRef The API of the grid.
215
+ * @param {React.MutableRefObject<GridPrivateApiCommunity>} apiRef The API of the grid.
197
216
  * @returns {GridAggregatedFilterItemApplier | null} A method that checks if a row is matching the current filter model. If `null`, we consider that all the rows are matching the filters.
198
217
  */
199
- exports.buildAggregatedFilterItemsApplier = buildAggregatedFilterItemsApplier;
200
- const buildAggregatedQuickFilterApplier = (getRowId, filterModel, apiRef) => {
218
+ const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
201
219
  const quickFilterValues = filterModel.quickFilterValues?.filter(Boolean) ?? [];
202
220
  if (quickFilterValues.length === 0) {
203
221
  return null;
@@ -205,6 +223,10 @@ const buildAggregatedQuickFilterApplier = (getRowId, filterModel, apiRef) => {
205
223
  const quickFilterExcludeHiddenColumns = filterModel.quickFilterExcludeHiddenColumns ?? false;
206
224
  const columnFields = quickFilterExcludeHiddenColumns ? (0, _columns.gridVisibleColumnFieldsSelector)(apiRef) : (0, _columns.gridColumnFieldsSelector)(apiRef);
207
225
  const appliersPerField = [];
226
+ const {
227
+ ignoreDiacritics
228
+ } = apiRef.current.rootProps;
229
+ const publicApiRef = (0, _getPublicApiRef.getPublicApiRef)(apiRef);
208
230
  columnFields.forEach(field => {
209
231
  const column = apiRef.current.getColumn(field);
210
232
  const getApplyQuickFilterFn = column?.getApplyQuickFilterFn;
@@ -214,18 +236,24 @@ const buildAggregatedQuickFilterApplier = (getRowId, filterModel, apiRef) => {
214
236
  if (getApplyQuickFilterFnV7 && !(hasUserFunctionLegacy && !hasUserFunctionV7)) {
215
237
  appliersPerField.push({
216
238
  column,
217
- appliers: quickFilterValues.map(value => ({
218
- v7: true,
219
- fn: getApplyQuickFilterFnV7(value, column, apiRef)
220
- }))
239
+ appliers: quickFilterValues.map(quickFilterValue => {
240
+ const value = ignoreDiacritics ? removeDiacritics(quickFilterValue) : quickFilterValue;
241
+ return {
242
+ v7: true,
243
+ fn: getApplyQuickFilterFnV7(value, column, publicApiRef)
244
+ };
245
+ })
221
246
  });
222
247
  } else if (getApplyQuickFilterFn) {
223
248
  appliersPerField.push({
224
249
  column,
225
- appliers: quickFilterValues.map(value => ({
226
- v7: false,
227
- fn: getApplyQuickFilterFn(value, column, apiRef)
228
- }))
250
+ appliers: quickFilterValues.map(quickFilterValue => {
251
+ const value = ignoreDiacritics ? removeDiacritics(quickFilterValue) : quickFilterValue;
252
+ return {
253
+ v7: false,
254
+ fn: getApplyQuickFilterFn(value, column, publicApiRef)
255
+ };
256
+ })
229
257
  });
230
258
  }
231
259
  });
@@ -248,18 +276,24 @@ const buildAggregatedQuickFilterApplier = (getRowId, filterModel, apiRef) => {
248
276
  continue;
249
277
  }
250
278
  const applier = appliers[v];
251
- const value = apiRef.current.getRowValue(row, column);
279
+ let value = apiRef.current.getRowValue(row, column);
252
280
  if (applier.fn === null) {
253
281
  continue;
254
282
  }
255
283
  if (applier.v7) {
256
- const isMatching = applier.fn(value, row, column, apiRef);
284
+ if (ignoreDiacritics) {
285
+ value = removeDiacritics(value);
286
+ }
287
+ const isMatching = applier.fn(value, row, column, publicApiRef);
257
288
  if (isMatching) {
258
289
  result[filterValue] = true;
259
290
  continue outer;
260
291
  }
261
292
  } else {
262
- const cellParams = usedCellParams[field] ?? apiRef.current.getCellParams(getRowId ? getRowId(row) : row.id, field);
293
+ const cellParams = usedCellParams[field] ?? apiRef.current.getCellParams(apiRef.current.getRowId(row), field);
294
+ if (ignoreDiacritics) {
295
+ cellParams.value = removeDiacritics(cellParams.value);
296
+ }
263
297
  usedCellParams[field] = cellParams;
264
298
  const isMatching = applier.fn(cellParams);
265
299
  if (isMatching) {
@@ -275,10 +309,9 @@ const buildAggregatedQuickFilterApplier = (getRowId, filterModel, apiRef) => {
275
309
  return result;
276
310
  };
277
311
  };
278
- exports.buildAggregatedQuickFilterApplier = buildAggregatedQuickFilterApplier;
279
- const buildAggregatedFilterApplier = (getRowId, filterModel, apiRef, disableEval) => {
280
- const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(getRowId, filterModel, apiRef, disableEval);
281
- const isRowMatchingQuickFilter = buildAggregatedQuickFilterApplier(getRowId, filterModel, apiRef);
312
+ const buildAggregatedFilterApplier = (filterModel, apiRef, disableEval) => {
313
+ const isRowMatchingFilterItems = buildAggregatedFilterItemsApplier(filterModel, apiRef, disableEval);
314
+ const isRowMatchingQuickFilter = buildAggregatedQuickFilterApplier(filterModel, apiRef);
282
315
  return function isRowMatchingFilters(row, shouldApplyFilter, result) {
283
316
  result.passingFilterItems = isRowMatchingFilterItems?.(row, shouldApplyFilter) ?? null;
284
317
  result.passingQuickFilterValues = isRowMatchingQuickFilter?.(row, shouldApplyFilter) ?? null;
@@ -69,7 +69,7 @@ const useGridFilter = (apiRef, props) => {
69
69
  const updateFilteredRows = React.useCallback(() => {
70
70
  apiRef.current.setState(state => {
71
71
  const filterModel = (0, _gridFilterSelector.gridFilterModelSelector)(state, apiRef.current.instanceId);
72
- const isRowMatchingFilters = props.filterMode === 'client' ? (0, _gridFilterUtils.buildAggregatedFilterApplier)(props.getRowId, filterModel, apiRef, props.disableEval) : null;
72
+ const isRowMatchingFilters = props.filterMode === 'client' ? (0, _gridFilterUtils.buildAggregatedFilterApplier)(filterModel, apiRef, props.disableEval) : null;
73
73
  const filteringResult = apiRef.current.applyStrategyProcessor('filtering', {
74
74
  isRowMatchingFilters,
75
75
  filterModel: filterModel ?? (0, _gridFilterState.getDefaultGridFilterModel)()
@@ -83,7 +83,7 @@ const useGridFilter = (apiRef, props) => {
83
83
  });
84
84
  });
85
85
  apiRef.current.publishEvent('filteredRowsSet');
86
- }, [apiRef, props.filterMode, props.getRowId, props.disableEval]);
86
+ }, [apiRef, props.filterMode, props.disableEval]);
87
87
  const addColumnMenuItem = React.useCallback((columnMenuItems, colDef) => {
88
88
  if (colDef == null || colDef.filterable === false || props.disableColumnFilter) {
89
89
  return columnMenuItems;
@@ -222,7 +222,8 @@ const useGridFilter = (apiRef, props) => {
222
222
  setFilterModel,
223
223
  showFilterPanel,
224
224
  hideFilterPanel,
225
- setQuickFilterValues
225
+ setQuickFilterValues,
226
+ ignoreDiacritics: props.ignoreDiacritics
226
227
  };
227
228
  (0, _useGridApiMethod.useGridApiMethod)(apiRef, filterApi, 'public');
228
229
 
package/node/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v6.17.0
2
+ * @mui/x-data-grid v6.18.1
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -716,6 +716,18 @@ var _keyboardUtils = require("../utils/keyboardUtils");
716
716
  var _utils2 = require("../utils/utils");
717
717
  var _warning = require("../utils/warning");
718
718
  var _exportAs = require("../utils/exportAs");
719
+ var _getPublicApiRef = require("../utils/getPublicApiRef");
720
+ Object.keys(_getPublicApiRef).forEach(function (key) {
721
+ if (key === "default" || key === "__esModule") return;
722
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
723
+ if (key in exports && exports[key] === _getPublicApiRef[key]) return;
724
+ Object.defineProperty(exports, key, {
725
+ enumerable: true,
726
+ get: function () {
727
+ return _getPublicApiRef[key];
728
+ }
729
+ });
730
+ });
719
731
  var _useGridPrivateApiContext = require("../hooks/utils/useGridPrivateApiContext");
720
732
  var _useOnMount = require("../hooks/utils/useOnMount");
721
733
  Object.keys(_useOnMount).forEach(function (key) {
@@ -19,5 +19,12 @@ function computeSlots({
19
19
  if (!overrides || Object.keys(overrides).length === 0) {
20
20
  return defaultSlots;
21
21
  }
22
- return (0, _extends2.default)({}, defaultSlots, overrides);
22
+ const result = (0, _extends2.default)({}, defaultSlots);
23
+ Object.keys(overrides).forEach(key => {
24
+ const k = key;
25
+ if (overrides[k] !== undefined) {
26
+ result[k] = overrides[k];
27
+ }
28
+ });
29
+ return result;
23
30
  }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getPublicApiRef = getPublicApiRef;
7
+ function getPublicApiRef(apiRef) {
8
+ return {
9
+ current: apiRef.current.getPublicApi()
10
+ };
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-data-grid",
3
- "version": "6.17.0",
3
+ "version": "6.18.1",
4
4
  "description": "The community edition of the data grid component (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./node/index.js",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@babel/runtime": "^7.23.2",
39
- "@mui/utils": "^5.14.14",
39
+ "@mui/utils": "^5.14.16",
40
40
  "clsx": "^2.0.0",
41
41
  "prop-types": "^15.8.1",
42
42
  "reselect": "^4.1.8"
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import type { GridPrivateApiCommunity } from '../models/api/gridApiCommunity';
3
+ export declare function getPublicApiRef<PrivateApi extends GridPrivateApiCommunity>(apiRef: React.MutableRefObject<PrivateApi>): import("react").MutableRefObject<ReturnType<PrivateApi["getPublicApi"]>>;
@@ -0,0 +1,5 @@
1
+ export function getPublicApiRef(apiRef) {
2
+ return {
3
+ current: apiRef.current.getPublicApi()
4
+ };
5
+ }