@mui/x-data-grid 6.9.2 → 6.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +232 -114
  2. package/DataGrid/DataGrid.js +1 -0
  3. package/components/toolbar/GridToolbarQuickFilter.d.ts +1 -1
  4. package/components/toolbar/GridToolbarQuickFilter.js +12 -9
  5. package/hooks/core/pipeProcessing/useGridPipeProcessing.js +4 -1
  6. package/hooks/core/useGridApiInitialization.d.ts +1 -0
  7. package/hooks/core/useGridApiInitialization.js +59 -36
  8. package/hooks/features/export/serializers/csvSerializer.d.ts +9 -6
  9. package/hooks/features/export/serializers/csvSerializer.js +78 -15
  10. package/hooks/features/export/useGridCsvExport.js +4 -3
  11. package/hooks/features/filter/gridFilterUtils.js +6 -5
  12. package/hooks/features/filter/useGridFilter.js +8 -0
  13. package/hooks/features/rows/gridRowsUtils.js +1 -1
  14. package/hooks/utils/useGridApiMethod.js +7 -23
  15. package/index.js +1 -1
  16. package/internals/index.d.ts +1 -0
  17. package/internals/index.js +1 -0
  18. package/legacy/DataGrid/DataGrid.js +1 -0
  19. package/legacy/components/toolbar/GridToolbarQuickFilter.js +12 -12
  20. package/legacy/hooks/core/pipeProcessing/useGridPipeProcessing.js +4 -1
  21. package/legacy/hooks/core/useGridApiInitialization.js +62 -39
  22. package/legacy/hooks/features/export/serializers/csvSerializer.js +84 -11
  23. package/legacy/hooks/features/export/useGridCsvExport.js +4 -3
  24. package/legacy/hooks/features/filter/gridFilterUtils.js +6 -5
  25. package/legacy/hooks/features/filter/useGridFilter.js +8 -0
  26. package/legacy/hooks/features/rows/gridRowsUtils.js +1 -1
  27. package/legacy/hooks/utils/useGridApiMethod.js +7 -25
  28. package/legacy/index.js +1 -1
  29. package/legacy/internals/index.js +1 -0
  30. package/legacy/locales/plPL.js +7 -7
  31. package/locales/plPL.js +7 -7
  32. package/models/events/gridEventLookup.d.ts +0 -1
  33. package/models/gridExport.d.ts +8 -1
  34. package/models/gridFilterModel.d.ts +5 -0
  35. package/modern/DataGrid/DataGrid.js +1 -0
  36. package/modern/components/toolbar/GridToolbarQuickFilter.js +12 -9
  37. package/modern/hooks/core/pipeProcessing/useGridPipeProcessing.js +4 -1
  38. package/modern/hooks/core/useGridApiInitialization.js +58 -36
  39. package/modern/hooks/features/export/serializers/csvSerializer.js +78 -15
  40. package/modern/hooks/features/export/useGridCsvExport.js +3 -2
  41. package/modern/hooks/features/filter/gridFilterUtils.js +3 -2
  42. package/modern/hooks/features/filter/useGridFilter.js +8 -0
  43. package/modern/hooks/features/rows/gridRowsUtils.js +1 -1
  44. package/modern/hooks/utils/useGridApiMethod.js +7 -23
  45. package/modern/index.js +1 -1
  46. package/modern/internals/index.js +1 -0
  47. package/modern/locales/plPL.js +7 -7
  48. package/node/DataGrid/DataGrid.js +1 -0
  49. package/node/components/toolbar/GridToolbarQuickFilter.js +12 -9
  50. package/node/hooks/core/pipeProcessing/useGridPipeProcessing.js +4 -1
  51. package/node/hooks/core/useGridApiInitialization.js +59 -36
  52. package/node/hooks/features/export/serializers/csvSerializer.js +78 -15
  53. package/node/hooks/features/export/useGridCsvExport.js +3 -2
  54. package/node/hooks/features/filter/gridFilterUtils.js +2 -1
  55. package/node/hooks/features/filter/useGridFilter.js +8 -0
  56. package/node/hooks/features/rows/gridRowsUtils.js +1 -1
  57. package/node/hooks/utils/useGridApiMethod.js +7 -23
  58. package/node/index.js +1 -1
  59. package/node/internals/index.js +8 -0
  60. package/node/locales/plPL.js +7 -7
  61. package/package.json +1 -1
@@ -43,43 +43,106 @@ const serializeCellValue = (cellParams, options) => {
43
43
  };
44
44
  exports.serializeCellValue = serializeCellValue;
45
45
  const objectFormattedValueWarning = (0, _warning.buildWarning)(['MUI: When the value of a field is an object or a `renderCell` is provided, the CSV export might not display the value correctly.', 'You can provide a `valueFormatter` with a string representation to be used.']);
46
+ class CSVRow {
47
+ constructor(options) {
48
+ this.options = void 0;
49
+ this.rowString = '';
50
+ this.isEmpty = true;
51
+ this.options = options;
52
+ }
53
+ addValue(value) {
54
+ if (!this.isEmpty) {
55
+ this.rowString += this.options.delimiterCharacter;
56
+ }
57
+ if (value === null || value === undefined) {
58
+ this.rowString += '';
59
+ } else if (typeof this.options.sanitizeCellValue === 'function') {
60
+ this.rowString += this.options.sanitizeCellValue(value, this.options.delimiterCharacter);
61
+ } else {
62
+ this.rowString += value;
63
+ }
64
+ this.isEmpty = false;
65
+ }
66
+ getRowString() {
67
+ return this.rowString;
68
+ }
69
+ }
46
70
  const serializeRow = ({
47
71
  id,
48
72
  columns,
49
73
  getCellParams,
50
74
  delimiterCharacter,
51
75
  ignoreValueFormatter
52
- }) => columns.map(column => {
53
- const cellParams = getCellParams(id, column.field);
54
- if (process.env.NODE_ENV !== 'production') {
55
- if (String(cellParams.formattedValue) === '[object Object]') {
56
- objectFormattedValueWarning();
76
+ }) => {
77
+ const row = new CSVRow({
78
+ delimiterCharacter
79
+ });
80
+ columns.forEach(column => {
81
+ const cellParams = getCellParams(id, column.field);
82
+ if (process.env.NODE_ENV !== 'production') {
83
+ if (String(cellParams.formattedValue) === '[object Object]') {
84
+ objectFormattedValueWarning();
85
+ }
57
86
  }
58
- }
59
- return serializeCellValue(cellParams, {
60
- delimiterCharacter,
61
- ignoreValueFormatter
87
+ row.addValue(serializeCellValue(cellParams, {
88
+ delimiterCharacter,
89
+ ignoreValueFormatter
90
+ }));
62
91
  });
63
- });
92
+ return row.getRowString();
93
+ };
64
94
  function buildCSV(options) {
65
95
  const {
66
96
  columns,
67
97
  rowIds,
68
- getCellParams,
69
98
  delimiterCharacter,
70
99
  includeHeaders,
71
- ignoreValueFormatter
100
+ includeColumnGroupsHeaders,
101
+ ignoreValueFormatter,
102
+ apiRef
72
103
  } = options;
73
104
  const CSVBody = rowIds.reduce((acc, id) => `${acc}${serializeRow({
74
105
  id,
75
106
  columns,
76
- getCellParams,
107
+ getCellParams: apiRef.current.getCellParams,
77
108
  delimiterCharacter,
78
109
  ignoreValueFormatter
79
- }).join(delimiterCharacter)}\r\n`, '').trim();
110
+ })}\r\n`, '').trim();
80
111
  if (!includeHeaders) {
81
112
  return CSVBody;
82
113
  }
83
- const CSVHead = `${columns.filter(column => column.field !== _colDef.GRID_CHECKBOX_SELECTION_COL_DEF.field).map(column => sanitizeCellValue(column.headerName || column.field, delimiterCharacter)).join(delimiterCharacter)}\r\n`;
114
+ const filteredColumns = columns.filter(column => column.field !== _colDef.GRID_CHECKBOX_SELECTION_COL_DEF.field);
115
+ const headerRows = [];
116
+ if (includeColumnGroupsHeaders) {
117
+ const columnGroupLookup = apiRef.current.unstable_getAllGroupDetails();
118
+ let maxColumnGroupsDepth = 0;
119
+ const columnGroupPathsLookup = filteredColumns.reduce((acc, column) => {
120
+ const columnGroupPath = apiRef.current.unstable_getColumnGroupPath(column.field);
121
+ acc[column.field] = columnGroupPath;
122
+ maxColumnGroupsDepth = Math.max(maxColumnGroupsDepth, columnGroupPath.length);
123
+ return acc;
124
+ }, {});
125
+ for (let i = 0; i < maxColumnGroupsDepth; i += 1) {
126
+ const headerGroupRow = new CSVRow({
127
+ delimiterCharacter,
128
+ sanitizeCellValue
129
+ });
130
+ headerRows.push(headerGroupRow);
131
+ filteredColumns.forEach(column => {
132
+ const columnGroupId = (columnGroupPathsLookup[column.field] || [])[i];
133
+ const columnGroup = columnGroupLookup[columnGroupId];
134
+ headerGroupRow.addValue(columnGroup ? columnGroup.headerName || columnGroup.groupId : '');
135
+ });
136
+ }
137
+ }
138
+ const mainHeaderRow = new CSVRow({
139
+ delimiterCharacter,
140
+ sanitizeCellValue
141
+ });
142
+ filteredColumns.forEach(column => {
143
+ mainHeaderRow.addValue(column.headerName || column.field);
144
+ });
145
+ headerRows.push(mainHeaderRow);
146
+ const CSVHead = `${headerRows.map(row => row.getRowString()).join('\r\n')}\r\n`;
84
147
  return `${CSVHead}${CSVBody}`.trim();
85
148
  }
@@ -39,10 +39,11 @@ const useGridCsvExport = (apiRef, props) => {
39
39
  return (0, _csvSerializer.buildCSV)({
40
40
  columns: exportedColumns,
41
41
  rowIds: exportedRowIds,
42
- getCellParams: apiRef.current.getCellParams,
43
42
  delimiterCharacter: options.delimiter || ',',
44
43
  includeHeaders: options.includeHeaders ?? true,
45
- ignoreValueFormatter
44
+ includeColumnGroupsHeaders: options.includeColumnGroupsHeaders ?? true,
45
+ ignoreValueFormatter,
46
+ apiRef
46
47
  });
47
48
  }, [logger, apiRef, ignoreValueFormatter]);
48
49
  const exportDataAsCsv = React.useCallback(options => {
@@ -168,7 +168,8 @@ const buildAggregatedQuickFilterApplier = (getRowId, filterModel, apiRef) => {
168
168
  if (quickFilterValues.length === 0) {
169
169
  return null;
170
170
  }
171
- const columnFields = (0, _columns.gridColumnFieldsSelector)(apiRef);
171
+ const quickFilterExcludeHiddenColumns = filterModel.quickFilterExcludeHiddenColumns ?? false;
172
+ const columnFields = quickFilterExcludeHiddenColumns ? (0, _columns.gridVisibleColumnFieldsSelector)(apiRef) : (0, _columns.gridColumnFieldsSelector)(apiRef);
172
173
  const appliersPerField = [];
173
174
  columnFields.forEach(field => {
174
175
  const column = apiRef.current.getColumn(field);
@@ -29,6 +29,7 @@ const filterStateInitializer = (state, props, apiRef) => {
29
29
  return (0, _extends2.default)({}, state, {
30
30
  filter: {
31
31
  filterModel: (0, _gridFilterUtils.sanitizeFilterModel)(filterModel, props.disableMultipleColumnsFiltering, apiRef),
32
+ filteredRowsLookup: {},
32
33
  filteredDescendantCountLookup: {}
33
34
  },
34
35
  visibleRowsLookup: {}
@@ -340,6 +341,13 @@ const useGridFilter = (apiRef, props) => {
340
341
  (0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'columnsChange', handleColumnsChange);
341
342
  (0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'activeStrategyProcessorChange', handleStrategyProcessorChange);
342
343
  (0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'rowExpansionChange', updateVisibleRowsLookupState);
344
+ (0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'columnVisibilityModelChange', () => {
345
+ const filterModel = (0, _gridFilterSelector.gridFilterModelSelector)(apiRef);
346
+ if (filterModel.quickFilterValues && filterModel.quickFilterExcludeHiddenColumns) {
347
+ // re-apply filters because the quick filter results may have changed
348
+ apiRef.current.unstable_applyFilters();
349
+ }
350
+ });
343
351
 
344
352
  /**
345
353
  * 1ST RENDER
@@ -15,7 +15,7 @@ var _gridRowsSelector = require("./gridRowsSelector");
15
15
  var _densitySelector = require("../density/densitySelector");
16
16
  const GRID_ROOT_GROUP_ID = `auto-generated-group-node-root`;
17
17
  exports.GRID_ROOT_GROUP_ID = GRID_ROOT_GROUP_ID;
18
- const GRID_ID_AUTOGENERATED = Symbol('mui-autogenerated-id');
18
+ const GRID_ID_AUTOGENERATED = Symbol('mui.id_autogenerated');
19
19
  exports.GRID_ID_AUTOGENERATED = GRID_ID_AUTOGENERATED;
20
20
  const buildRootGroup = () => ({
21
21
  type: 'group',
@@ -8,28 +8,12 @@ var React = _interopRequireWildcard(require("react"));
8
8
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
9
9
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
10
10
  function useGridApiMethod(privateApiRef, apiMethods, visibility) {
11
- const apiMethodsRef = React.useRef(apiMethods);
12
- const [apiMethodsNames] = React.useState(Object.keys(apiMethods));
13
- const installMethods = React.useCallback(() => {
14
- if (!privateApiRef.current) {
15
- return;
16
- }
17
- apiMethodsNames.forEach(methodName => {
18
- if (!privateApiRef.current.hasOwnProperty(methodName)) {
19
- privateApiRef.current.register(visibility, {
20
- [methodName]: (...args) => {
21
- const fn = apiMethodsRef.current[methodName];
22
- return fn(...args);
23
- }
24
- });
25
- }
26
- });
27
- }, [apiMethodsNames, privateApiRef, visibility]);
11
+ const isFirstRender = React.useRef(true);
28
12
  React.useEffect(() => {
29
- apiMethodsRef.current = apiMethods;
30
- }, [apiMethods]);
31
- React.useEffect(() => {
32
- installMethods();
33
- }, [installMethods]);
34
- installMethods();
13
+ isFirstRender.current = false;
14
+ privateApiRef.current.register(visibility, apiMethods);
15
+ }, [privateApiRef, visibility, apiMethods]);
16
+ if (isFirstRender.current) {
17
+ privateApiRef.current.register(visibility, apiMethods);
18
+ }
35
19
  }
package/node/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v6.9.2
2
+ * @mui/x-data-grid v6.10.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -15,6 +15,7 @@ var _exportNames = {
15
15
  useGridRegisterStrategyProcessor: true,
16
16
  GRID_DEFAULT_STRATEGY: true,
17
17
  useGridInitialization: true,
18
+ unwrapPrivateAPI: true,
18
19
  useGridClipboard: true,
19
20
  useGridColumnHeaders: true,
20
21
  unstable_gridHeaderFilteringEditFieldSelector: true,
@@ -403,6 +404,12 @@ Object.defineProperty(exports, "unstable_resetCreateSelectorCache", {
403
404
  return _createSelector.unstable_resetCreateSelectorCache;
404
405
  }
405
406
  });
407
+ Object.defineProperty(exports, "unwrapPrivateAPI", {
408
+ enumerable: true,
409
+ get: function () {
410
+ return _useGridApiInitialization.unwrapPrivateAPI;
411
+ }
412
+ });
406
413
  Object.defineProperty(exports, "useGridClipboard", {
407
414
  enumerable: true,
408
415
  get: function () {
@@ -617,6 +624,7 @@ var _GridFilterPanel = require("../components/panel/filterPanel/GridFilterPanel"
617
624
  var _pipeProcessing = require("../hooks/core/pipeProcessing");
618
625
  var _strategyProcessing = require("../hooks/core/strategyProcessing");
619
626
  var _useGridInitialization = require("../hooks/core/useGridInitialization");
627
+ var _useGridApiInitialization = require("../hooks/core/useGridApiInitialization");
620
628
  var _useGridClipboard = require("../hooks/features/clipboard/useGridClipboard");
621
629
  var _useGridColumnHeaders = require("../hooks/features/columnHeaders/useGridColumnHeaders");
622
630
  var _gridHeaderFilteringSelectors = require("../hooks/features/headerFiltering/gridHeaderFilteringSelectors");
@@ -43,7 +43,7 @@ const plPLGrid = {
43
43
  columnsPanelHideAllButton: 'Ukryj wszystko',
44
44
  // Filter panel text
45
45
  filterPanelAddFilter: 'Dodaj filtr',
46
- // filterPanelRemoveAll: 'Remove all',
46
+ filterPanelRemoveAll: 'Usuń wszystkie',
47
47
  filterPanelDeleteIconLabel: 'Usuń',
48
48
  filterPanelLogicOperator: 'Operator logiczny',
49
49
  filterPanelOperator: 'Operator',
@@ -74,12 +74,12 @@ const plPLGrid = {
74
74
  // 'filterOperator<=': '<=',
75
75
 
76
76
  // Header filter operators text
77
- // headerFilterOperatorContains: 'Contains',
78
- // headerFilterOperatorEquals: 'Equals',
79
- // headerFilterOperatorStartsWith: 'Starts with',
80
- // headerFilterOperatorEndsWith: 'Ends with',
77
+ headerFilterOperatorContains: 'Zawiera',
78
+ headerFilterOperatorEquals: 'Równa się',
79
+ headerFilterOperatorStartsWith: 'Zaczyna się od',
80
+ headerFilterOperatorEndsWith: 'Kończy się na',
81
81
  // headerFilterOperatorIs: 'Is',
82
- // headerFilterOperatorNot: 'Is not',
82
+ headerFilterOperatorNot: 'Niepuste',
83
83
  // headerFilterOperatorAfter: 'Is after',
84
84
  // headerFilterOperatorOnOrAfter: 'Is on or after',
85
85
  // headerFilterOperatorBefore: 'Is before',
@@ -101,7 +101,7 @@ const plPLGrid = {
101
101
  // Column menu text
102
102
  columnMenuLabel: 'Menu',
103
103
  columnMenuShowColumns: 'Pokaż wszystkie kolumny',
104
- // columnMenuManageColumns: 'Manage columns',
104
+ columnMenuManageColumns: 'Zarządzaj kolumnami',
105
105
  columnMenuFilter: 'Filtr',
106
106
  columnMenuHideColumn: 'Ukryj',
107
107
  columnMenuUnsort: 'Anuluj sortowanie',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-data-grid",
3
- "version": "6.9.2",
3
+ "version": "6.10.0",
4
4
  "description": "The community edition of the data grid component (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./node/index.js",