@mui/x-data-grid-pro 5.6.1 → 5.7.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 (63) hide show
  1. package/CHANGELOG.md +71 -1
  2. package/DataGridPro/DataGridPro.js +20 -15
  3. package/DataGridPro/useDataGridProComponent.js +12 -10
  4. package/components/DataGridProColumnHeaders.js +10 -10
  5. package/components/DataGridProVirtualScroller.js +6 -6
  6. package/hooks/features/rowGrouping/gridRowGroupingInterfaces.d.ts +6 -0
  7. package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +4 -1
  8. package/hooks/features/rowGrouping/gridRowGroupingUtils.js +18 -3
  9. package/hooks/features/rowGrouping/useGridRowGrouping.js +44 -165
  10. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.d.ts +1 -1
  11. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +130 -3
  12. package/hooks/features/treeData/gridTreeDataUtils.d.ts +1 -0
  13. package/hooks/features/treeData/gridTreeDataUtils.js +2 -0
  14. package/hooks/features/treeData/useGridTreeData.d.ts +1 -5
  15. package/hooks/features/treeData/useGridTreeData.js +3 -82
  16. package/hooks/features/treeData/useGridTreeDataPreProcessors.d.ts +1 -1
  17. package/hooks/features/treeData/useGridTreeDataPreProcessors.js +72 -3
  18. package/index.js +1 -1
  19. package/legacy/DataGridPro/DataGridPro.js +20 -15
  20. package/legacy/DataGridPro/useDataGridProComponent.js +12 -10
  21. package/legacy/components/DataGridProColumnHeaders.js +10 -10
  22. package/legacy/components/DataGridProVirtualScroller.js +6 -6
  23. package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +19 -2
  24. package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +46 -170
  25. package/legacy/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +137 -3
  26. package/legacy/hooks/features/treeData/gridTreeDataUtils.js +2 -0
  27. package/legacy/hooks/features/treeData/useGridTreeData.js +3 -90
  28. package/legacy/hooks/features/treeData/useGridTreeDataPreProcessors.js +84 -3
  29. package/legacy/index.js +1 -1
  30. package/legacy/utils/releaseInfo.js +15 -0
  31. package/modern/DataGridPro/DataGridPro.js +20 -15
  32. package/modern/DataGridPro/useDataGridProComponent.js +10 -10
  33. package/modern/components/DataGridProColumnHeaders.js +10 -10
  34. package/modern/components/DataGridProVirtualScroller.js +6 -6
  35. package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +18 -3
  36. package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +44 -165
  37. package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +130 -3
  38. package/modern/hooks/features/treeData/gridTreeDataUtils.js +2 -0
  39. package/modern/hooks/features/treeData/useGridTreeData.js +3 -82
  40. package/modern/hooks/features/treeData/useGridTreeDataPreProcessors.js +72 -3
  41. package/modern/index.js +1 -1
  42. package/modern/utils/releaseInfo.js +15 -0
  43. package/node/DataGridPro/DataGridPro.js +18 -14
  44. package/node/DataGridPro/useDataGridProComponent.js +12 -10
  45. package/node/components/DataGridProColumnHeaders.js +10 -10
  46. package/node/components/DataGridProVirtualScroller.js +6 -6
  47. package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +24 -5
  48. package/node/hooks/features/rowGrouping/useGridRowGrouping.js +40 -163
  49. package/node/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +133 -0
  50. package/node/hooks/features/treeData/gridTreeDataUtils.js +5 -2
  51. package/node/hooks/features/treeData/useGridTreeData.js +2 -91
  52. package/node/hooks/features/treeData/useGridTreeDataPreProcessors.js +74 -2
  53. package/node/index.js +1 -1
  54. package/node/utils/releaseInfo.js +25 -0
  55. package/package.json +3 -3
  56. package/utils/releaseInfo.d.ts +1 -0
  57. package/utils/releaseInfo.js +15 -0
  58. package/utils/tree/buildRowTree.d.ts +3 -3
  59. package/components/Watermark.d.ts +0 -2
  60. package/components/Watermark.js +0 -43
  61. package/legacy/components/Watermark.js +0 -43
  62. package/modern/components/Watermark.js +0 -43
  63. package/node/components/Watermark.js +0 -56
@@ -17,14 +17,10 @@ var _xDataGrid = require("@mui/x-data-grid");
17
17
 
18
18
  var _internals = require("@mui/x-data-grid/internals");
19
19
 
20
- var _buildRowTree = require("../../../utils/tree/buildRowTree");
21
-
22
20
  var _gridRowGroupingSelector = require("./gridRowGroupingSelector");
23
21
 
24
22
  var _gridRowGroupingUtils = require("./gridRowGroupingUtils");
25
23
 
26
- var _sortRowTree = require("../../../utils/tree/sortRowTree");
27
-
28
24
  var _GridRowGroupableColumnMenuItems = require("../../../components/GridRowGroupableColumnMenuItems");
29
25
 
30
26
  var _GridRowGroupingColumnMenuItems = require("../../../components/GridRowGroupingColumnMenuItems");
@@ -40,7 +36,8 @@ const rowGroupingStateInitializer = (state, props) => {
40
36
 
41
37
  return (0, _extends2.default)({}, state, {
42
38
  rowGrouping: {
43
- model: (_ref = (_props$rowGroupingMod = props.rowGroupingModel) != null ? _props$rowGroupingMod : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$r = _props$initialState.rowGrouping) == null ? void 0 : _props$initialState$r.model) != null ? _ref : []
39
+ model: (_ref = (_props$rowGroupingMod = props.rowGroupingModel) != null ? _props$rowGroupingMod : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$r = _props$initialState.rowGrouping) == null ? void 0 : _props$initialState$r.model) != null ? _ref : [],
40
+ unstable_sanitizedModelOnLastRowTreeCreation: []
44
41
  }
45
42
  });
46
43
  };
@@ -63,158 +60,6 @@ const useGridRowGrouping = (apiRef, props) => {
63
60
  stateSelector: _gridRowGroupingSelector.gridRowGroupingModelSelector,
64
61
  changeEvent: _xDataGrid.GridEvents.rowGroupingModelChange
65
62
  });
66
- /**
67
- * ROW GROUPING
68
- */
69
- // Tracks the model on the last pre-processing to check if we need to re-build the grouping columns when the grid upserts a column.
70
-
71
- const sanitizedModelOnLastRowPreProcessing = React.useRef([]);
72
- const updateRowGrouping = React.useCallback(() => {
73
- const groupRows = params => {
74
- const rowGroupingModel = (0, _gridRowGroupingSelector.gridRowGroupingSanitizedModelSelector)(apiRef);
75
- const columnsLookup = (0, _xDataGrid.gridColumnLookupSelector)(apiRef);
76
- sanitizedModelOnLastRowPreProcessing.current = rowGroupingModel;
77
-
78
- if (props.disableRowGrouping || rowGroupingModel.length === 0) {
79
- return null;
80
- }
81
-
82
- const distinctValues = Object.fromEntries(rowGroupingModel.map(groupingField => [groupingField, {
83
- lookup: {},
84
- list: []
85
- }]));
86
-
87
- const getCellGroupingCriteria = ({
88
- row,
89
- id,
90
- colDef
91
- }) => {
92
- let key;
93
-
94
- if (colDef.groupingValueGetter) {
95
- const groupingValueGetterParams = {
96
- colDef,
97
- field: colDef.field,
98
- value: row[colDef.field],
99
- id,
100
- row,
101
- rowNode: {
102
- isAutoGenerated: false,
103
- id
104
- }
105
- };
106
- key = colDef.groupingValueGetter(groupingValueGetterParams);
107
- } else {
108
- key = row[colDef.field];
109
- }
110
-
111
- return {
112
- key,
113
- field: colDef.field
114
- };
115
- };
116
-
117
- params.ids.forEach(rowId => {
118
- const row = params.idRowsLookup[rowId];
119
- rowGroupingModel.forEach(groupingCriteria => {
120
- const {
121
- key
122
- } = getCellGroupingCriteria({
123
- row,
124
- id: rowId,
125
- colDef: columnsLookup[groupingCriteria]
126
- });
127
- const groupingFieldsDistinctKeys = distinctValues[groupingCriteria];
128
-
129
- if (key != null && !groupingFieldsDistinctKeys.lookup[key.toString()]) {
130
- groupingFieldsDistinctKeys.lookup[key.toString()] = true;
131
- groupingFieldsDistinctKeys.list.push(key);
132
- }
133
- });
134
- });
135
- const rows = params.ids.map(rowId => {
136
- const row = params.idRowsLookup[rowId];
137
- const parentPath = rowGroupingModel.map(groupingField => getCellGroupingCriteria({
138
- row,
139
- id: rowId,
140
- colDef: columnsLookup[groupingField]
141
- })).filter(cell => cell.key != null);
142
- const leafGroupingCriteria = {
143
- key: rowId.toString(),
144
- field: null
145
- };
146
- return {
147
- path: [...parentPath, leafGroupingCriteria],
148
- id: rowId
149
- };
150
- });
151
- return (0, _buildRowTree.buildRowTree)((0, _extends2.default)({}, params, {
152
- rows,
153
- defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
154
- isGroupExpandedByDefault: props.isGroupExpandedByDefault,
155
- groupingName: _gridRowGroupingUtils.GROUPING_COLUMNS_FEATURE_NAME
156
- }));
157
- };
158
-
159
- return apiRef.current.unstable_registerRowGroupsBuilder('rowGrouping', groupRows);
160
- }, [apiRef, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault, props.disableRowGrouping]);
161
- (0, _xDataGrid.useFirstRender)(() => {
162
- updateRowGrouping();
163
- });
164
- const isFirstRender = React.useRef(true);
165
- React.useEffect(() => {
166
- if (isFirstRender.current) {
167
- isFirstRender.current = false;
168
- return () => {};
169
- }
170
-
171
- return updateRowGrouping();
172
- }, [updateRowGrouping]);
173
- /**
174
- * PRE-PROCESSING
175
- */
176
-
177
- const addColumnMenuButtons = React.useCallback((initialValue, columns) => {
178
- if (props.disableRowGrouping) {
179
- return initialValue;
180
- }
181
-
182
- let menuItems;
183
-
184
- if ((0, _gridRowGroupingUtils.isGroupingColumn)(columns.field)) {
185
- menuItems = /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridRowGroupingColumnMenuItems.GridRowGroupingColumnMenuItems, {});
186
- } else if (columns.groupable) {
187
- menuItems = /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridRowGroupableColumnMenuItems.GridRowGroupableColumnMenuItems, {});
188
- } else {
189
- menuItems = null;
190
- }
191
-
192
- if (menuItems == null) {
193
- return initialValue;
194
- }
195
-
196
- return [...initialValue, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {}), menuItems];
197
- }, [props.disableRowGrouping]);
198
- const filteringMethod = React.useCallback(params => {
199
- const rowTree = (0, _xDataGrid.gridRowTreeSelector)(apiRef);
200
- return (0, _gridRowGroupingUtils.filterRowTreeFromGroupingColumns)({
201
- rowTree,
202
- isRowMatchingFilters: params.isRowMatchingFilters
203
- });
204
- }, [apiRef]);
205
- const sortingMethod = React.useCallback(params => {
206
- const rowTree = (0, _xDataGrid.gridRowTreeSelector)(apiRef);
207
- const rowIds = (0, _xDataGrid.gridRowIdsSelector)(apiRef);
208
- return (0, _sortRowTree.sortRowTree)({
209
- rowTree,
210
- rowIds,
211
- sortRowList: params.sortRowList,
212
- disableChildrenSorting: false
213
- });
214
- }, [apiRef]);
215
- (0, _internals.useGridRegisterPreProcessor)(apiRef, 'columnMenu', addColumnMenuButtons);
216
- (0, _internals.useGridRegisterFilteringMethod)(apiRef, _gridRowGroupingUtils.GROUPING_COLUMNS_FEATURE_NAME, filteringMethod);
217
- (0, _internals.useGridRegisterSortingMethod)(apiRef, _gridRowGroupingUtils.GROUPING_COLUMNS_FEATURE_NAME, sortingMethod);
218
63
  /**
219
64
  * API METHODS
220
65
  */
@@ -224,10 +69,10 @@ const useGridRowGrouping = (apiRef, props) => {
224
69
 
225
70
  if (currentModel !== model) {
226
71
  apiRef.current.setState((0, _gridRowGroupingUtils.mergeStateWithRowGroupingModel)(model));
227
- updateRowGrouping();
72
+ (0, _gridRowGroupingUtils.setStrategyAvailability)(apiRef, props.disableRowGrouping);
228
73
  apiRef.current.forceUpdate();
229
74
  }
230
- }, [apiRef, updateRowGrouping]);
75
+ }, [apiRef, props.disableRowGrouping]);
231
76
  const addRowGroupingCriteria = React.useCallback((field, groupingIndex) => {
232
77
  const currentModel = (0, _gridRowGroupingSelector.gridRowGroupingModelSelector)(apiRef);
233
78
 
@@ -271,6 +116,27 @@ const useGridRowGrouping = (apiRef, props) => {
271
116
  * PRE-PROCESSING
272
117
  */
273
118
 
119
+ const addColumnMenuButtons = React.useCallback((initialValue, columns) => {
120
+ if (props.disableRowGrouping) {
121
+ return initialValue;
122
+ }
123
+
124
+ let menuItems;
125
+
126
+ if ((0, _gridRowGroupingUtils.isGroupingColumn)(columns.field)) {
127
+ menuItems = /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridRowGroupingColumnMenuItems.GridRowGroupingColumnMenuItems, {});
128
+ } else if (columns.groupable) {
129
+ menuItems = /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridRowGroupableColumnMenuItems.GridRowGroupableColumnMenuItems, {});
130
+ } else {
131
+ menuItems = null;
132
+ }
133
+
134
+ if (menuItems == null) {
135
+ return initialValue;
136
+ }
137
+
138
+ return [...initialValue, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {}), menuItems];
139
+ }, [props.disableRowGrouping]);
274
140
  const stateExportPreProcessing = React.useCallback(prevState => {
275
141
  if (props.disableRowGrouping) {
276
142
  return prevState;
@@ -303,6 +169,7 @@ const useGridRowGrouping = (apiRef, props) => {
303
169
 
304
170
  return params;
305
171
  }, [apiRef, props.disableRowGrouping]);
172
+ (0, _internals.useGridRegisterPreProcessor)(apiRef, 'columnMenu', addColumnMenuButtons);
306
173
  (0, _internals.useGridRegisterPreProcessor)(apiRef, 'exportState', stateExportPreProcessing);
307
174
  (0, _internals.useGridRegisterPreProcessor)(apiRef, 'restoreState', stateRestorePreProcessing);
308
175
  /**
@@ -329,15 +196,25 @@ const useGridRowGrouping = (apiRef, props) => {
329
196
  }, [apiRef, props.rowGroupingColumnMode]);
330
197
  const checkGroupingColumnsModelDiff = React.useCallback(() => {
331
198
  const rowGroupingModel = (0, _gridRowGroupingSelector.gridRowGroupingSanitizedModelSelector)(apiRef);
332
- const lastGroupingColumnsModelApplied = sanitizedModelOnLastRowPreProcessing.current;
199
+ const lastGroupingColumnsModelApplied = (0, _gridRowGroupingSelector.gridRowGroupingStateSelector)(apiRef.current.state).unstable_sanitizedModelOnLastRowTreeCreation;
333
200
 
334
201
  if (!(0, _internals.isDeepEqual)(lastGroupingColumnsModelApplied, rowGroupingModel)) {
335
- sanitizedModelOnLastRowPreProcessing.current = rowGroupingModel; // Refresh the column pre-processing
202
+ apiRef.current.setState(state => (0, _extends2.default)({}, state, {
203
+ rowGrouping: (0, _extends2.default)({}, state.rowGrouping, {
204
+ unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
205
+ })
206
+ })); // Refresh the column pre-processing
207
+ // TODO: Add a clean way to re-run a pipe processing without faking a change
336
208
 
337
209
  apiRef.current.updateColumns([]);
338
- updateRowGrouping();
210
+ (0, _gridRowGroupingUtils.setStrategyAvailability)(apiRef, props.disableRowGrouping); // Refresh the row tree creation strategy processing
211
+ // TODO: Add a clean way to re-run a strategy processing without publishing a private event
212
+
213
+ if (apiRef.current.unstable_getActiveStrategy('rowTree') === _gridRowGroupingUtils.ROW_GROUPING_STRATEGY) {
214
+ apiRef.current.publishEvent(_xDataGrid.GridEvents.activeStrategyProcessorChange, 'rowTreeCreation');
215
+ }
339
216
  }
340
- }, [apiRef, updateRowGrouping]);
217
+ }, [apiRef, props.disableRowGrouping]);
341
218
  (0, _xDataGrid.useGridApiEventHandler)(apiRef, _xDataGrid.GridEvents.cellKeyDown, handleCellKeyDown);
342
219
  (0, _xDataGrid.useGridApiEventHandler)(apiRef, _xDataGrid.GridEvents.columnsChange, checkGroupingColumnsModelDiff);
343
220
  (0, _xDataGrid.useGridApiEventHandler)(apiRef, _xDataGrid.GridEvents.rowGroupingModelChange, checkGroupingColumnsModelDiff);
@@ -1,12 +1,18 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
8
  exports.useGridRowGroupingPreProcessors = void 0;
7
9
 
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
8
12
  var React = _interopRequireWildcard(require("react"));
9
13
 
14
+ var _xDataGrid = require("@mui/x-data-grid");
15
+
10
16
  var _internals = require("@mui/x-data-grid/internals");
11
17
 
12
18
  var _gridRowGroupingSelector = require("./gridRowGroupingSelector");
@@ -15,6 +21,10 @@ var _createGroupingColDef = require("./createGroupingColDef");
15
21
 
16
22
  var _gridRowGroupingUtils = require("./gridRowGroupingUtils");
17
23
 
24
+ var _buildRowTree = require("../../../utils/tree/buildRowTree");
25
+
26
+ var _sortRowTree = require("../../../utils/tree/sortRowTree");
27
+
18
28
  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); }
19
29
 
20
30
  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; }
@@ -88,7 +98,130 @@ const useGridRowGroupingPreProcessors = (apiRef, props) => {
88
98
  columnsState.lookup = newColumnsLookup;
89
99
  return columnsState;
90
100
  }, [getGroupingColDefs]);
101
+ const createRowTree = React.useCallback(params => {
102
+ const rowGroupingModel = (0, _gridRowGroupingSelector.gridRowGroupingSanitizedModelSelector)(apiRef);
103
+ const columnsLookup = (0, _xDataGrid.gridColumnLookupSelector)(apiRef);
104
+ apiRef.current.setState(state => (0, _extends2.default)({}, state, {
105
+ rowGrouping: (0, _extends2.default)({}, state.rowGrouping, {
106
+ unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
107
+ })
108
+ }));
109
+ const distinctValues = Object.fromEntries(rowGroupingModel.map(groupingField => [groupingField, {
110
+ lookup: {},
111
+ list: []
112
+ }]));
113
+
114
+ const getCellGroupingCriteria = ({
115
+ row,
116
+ id,
117
+ colDef
118
+ }) => {
119
+ let key;
120
+
121
+ if (colDef.groupingValueGetter) {
122
+ const groupingValueGetterParams = {
123
+ colDef,
124
+ field: colDef.field,
125
+ value: row[colDef.field],
126
+ id,
127
+ row,
128
+ rowNode: {
129
+ isAutoGenerated: false,
130
+ id
131
+ }
132
+ };
133
+ key = colDef.groupingValueGetter(groupingValueGetterParams);
134
+ } else {
135
+ key = row[colDef.field];
136
+ }
137
+
138
+ return {
139
+ key,
140
+ field: colDef.field
141
+ };
142
+ };
143
+
144
+ params.ids.forEach(rowId => {
145
+ const row = params.idRowsLookup[rowId];
146
+ rowGroupingModel.forEach(groupingCriteria => {
147
+ const {
148
+ key
149
+ } = getCellGroupingCriteria({
150
+ row,
151
+ id: rowId,
152
+ colDef: columnsLookup[groupingCriteria]
153
+ });
154
+ const groupingFieldsDistinctKeys = distinctValues[groupingCriteria];
155
+
156
+ if (key != null && !groupingFieldsDistinctKeys.lookup[key.toString()]) {
157
+ groupingFieldsDistinctKeys.lookup[key.toString()] = true;
158
+ groupingFieldsDistinctKeys.list.push(key);
159
+ }
160
+ });
161
+ });
162
+ const rows = params.ids.map(rowId => {
163
+ const row = params.idRowsLookup[rowId];
164
+ const parentPath = rowGroupingModel.map(groupingField => getCellGroupingCriteria({
165
+ row,
166
+ id: rowId,
167
+ colDef: columnsLookup[groupingField]
168
+ })).filter(cell => cell.key != null);
169
+ const leafGroupingCriteria = {
170
+ key: rowId.toString(),
171
+ field: null
172
+ };
173
+ return {
174
+ path: [...parentPath, leafGroupingCriteria],
175
+ id: rowId
176
+ };
177
+ });
178
+ return (0, _buildRowTree.buildRowTree)((0, _extends2.default)({}, params, {
179
+ rows,
180
+ defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
181
+ isGroupExpandedByDefault: props.isGroupExpandedByDefault,
182
+ groupingName: _gridRowGroupingUtils.ROW_GROUPING_STRATEGY
183
+ }));
184
+ }, [apiRef, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault]);
185
+ const filterRows = React.useCallback(params => {
186
+ const rowTree = (0, _xDataGrid.gridRowTreeSelector)(apiRef);
187
+ return (0, _gridRowGroupingUtils.filterRowTreeFromGroupingColumns)({
188
+ rowTree,
189
+ isRowMatchingFilters: params.isRowMatchingFilters
190
+ });
191
+ }, [apiRef]);
192
+ const sortRows = React.useCallback(params => {
193
+ const rowTree = (0, _xDataGrid.gridRowTreeSelector)(apiRef);
194
+ const rowIds = (0, _xDataGrid.gridRowIdsSelector)(apiRef);
195
+ return (0, _sortRowTree.sortRowTree)({
196
+ rowTree,
197
+ rowIds,
198
+ sortRowList: params.sortRowList,
199
+ disableChildrenSorting: false
200
+ });
201
+ }, [apiRef]);
91
202
  (0, _internals.useGridRegisterPreProcessor)(apiRef, 'hydrateColumns', updateGroupingColumn);
203
+ (0, _internals.useGridRegisterStrategyProcessor)(apiRef, _gridRowGroupingUtils.ROW_GROUPING_STRATEGY, 'rowTreeCreation', createRowTree);
204
+ (0, _internals.useGridRegisterStrategyProcessor)(apiRef, _gridRowGroupingUtils.ROW_GROUPING_STRATEGY, 'filtering', filterRows);
205
+ (0, _internals.useGridRegisterStrategyProcessor)(apiRef, _gridRowGroupingUtils.ROW_GROUPING_STRATEGY, 'sorting', sortRows);
206
+ /**
207
+ * 1ST RENDER
208
+ */
209
+
210
+ (0, _xDataGrid.useFirstRender)(() => {
211
+ (0, _gridRowGroupingUtils.setStrategyAvailability)(apiRef, props.disableRowGrouping);
212
+ });
213
+ /**
214
+ * EFFECTS
215
+ */
216
+
217
+ const isFirstRender = React.useRef(true);
218
+ React.useEffect(() => {
219
+ if (!isFirstRender.current) {
220
+ (0, _gridRowGroupingUtils.setStrategyAvailability)(apiRef, props.disableRowGrouping);
221
+ } else {
222
+ isFirstRender.current = false;
223
+ }
224
+ }, [apiRef, props.disableRowGrouping]);
92
225
  };
93
226
 
94
227
  exports.useGridRowGroupingPreProcessors = useGridRowGroupingPreProcessors;
@@ -3,13 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.filterRowTreeFromTreeData = void 0;
7
-
6
+ exports.filterRowTreeFromTreeData = exports.TREE_DATA_STRATEGY = void 0;
7
+ const TREE_DATA_STRATEGY = 'tree-data';
8
8
  /**
9
9
  * A node is visible if one of the following criteria is met:
10
10
  * - One of its children is passing the filter
11
11
  * - It is passing the filter
12
12
  */
13
+
14
+ exports.TREE_DATA_STRATEGY = TREE_DATA_STRATEGY;
15
+
13
16
  const filterRowTreeFromTreeData = params => {
14
17
  const {
15
18
  rowTree,
@@ -1,114 +1,25 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
- exports.useGridTreeData = exports.TREE_DATA_GROUPING_NAME = void 0;
9
-
10
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
6
+ exports.useGridTreeData = void 0;
11
7
 
12
8
  var React = _interopRequireWildcard(require("react"));
13
9
 
14
10
  var _xDataGrid = require("@mui/x-data-grid");
15
11
 
16
- var _internals = require("@mui/x-data-grid/internals");
17
-
18
- var _buildRowTree = require("../../../utils/tree/buildRowTree");
19
-
20
- var _sortRowTree = require("../../../utils/tree/sortRowTree");
21
-
22
- var _gridTreeDataUtils = require("./gridTreeDataUtils");
23
-
24
12
  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); }
25
13
 
26
14
  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; }
27
15
 
28
- const TREE_DATA_GROUPING_NAME = 'tree-data';
29
16
  /**
30
17
  * Only available in DataGridPro
31
- * @requires useGridPreProcessing (method)
32
- * @requires useGridRowGroupsPreProcessing (method)
33
18
  */
34
-
35
- exports.TREE_DATA_GROUPING_NAME = TREE_DATA_GROUPING_NAME;
36
-
37
- const useGridTreeData = (apiRef, props) => {
38
- /**
39
- * ROW GROUPING
40
- */
41
- const updateRowGrouping = React.useCallback(() => {
42
- if (!props.treeData) {
43
- return apiRef.current.unstable_registerRowGroupsBuilder('treeData', null);
44
- }
45
-
46
- const groupRows = params => {
47
- if (!props.getTreeDataPath) {
48
- throw new Error('MUI: No getTreeDataPath given.');
49
- }
50
-
51
- const rows = params.ids.map(rowId => ({
52
- id: rowId,
53
- path: props.getTreeDataPath(params.idRowsLookup[rowId]).map(key => ({
54
- key,
55
- field: null
56
- }))
57
- })).sort((a, b) => a.path.length - b.path.length);
58
- return (0, _buildRowTree.buildRowTree)((0, _extends2.default)({
59
- rows
60
- }, params, {
61
- defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
62
- isGroupExpandedByDefault: props.isGroupExpandedByDefault,
63
- groupingName: TREE_DATA_GROUPING_NAME,
64
- onDuplicatePath: (firstId, secondId, path) => {
65
- throw new Error(['MUI: The path returned by `getTreeDataPath` should be unique.', `The rows with id #${firstId} and #${secondId} have the same.`, `Path: ${JSON.stringify(path.map(step => step.key))}.`].join('\n'));
66
- }
67
- }));
68
- };
69
-
70
- return apiRef.current.unstable_registerRowGroupsBuilder('treeData', groupRows);
71
- }, [apiRef, props.getTreeDataPath, props.treeData, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault]);
72
- (0, _xDataGrid.useFirstRender)(() => {
73
- updateRowGrouping();
74
- });
75
- const isFirstRender = React.useRef(true);
76
- React.useEffect(() => {
77
- if (isFirstRender.current) {
78
- isFirstRender.current = false;
79
- return;
80
- }
81
-
82
- updateRowGrouping();
83
- }, [updateRowGrouping]);
84
- /**
85
- * PRE-PROCESSING
86
- */
87
-
88
- const filteringMethod = React.useCallback(params => {
89
- const rowTree = (0, _xDataGrid.gridRowTreeSelector)(apiRef);
90
- return (0, _gridTreeDataUtils.filterRowTreeFromTreeData)({
91
- rowTree,
92
- isRowMatchingFilters: params.isRowMatchingFilters,
93
- disableChildrenFiltering: props.disableChildrenFiltering
94
- });
95
- }, [apiRef, props.disableChildrenFiltering]);
96
- const sortingMethod = React.useCallback(params => {
97
- const rowTree = (0, _xDataGrid.gridRowTreeSelector)(apiRef);
98
- const rowIds = (0, _xDataGrid.gridRowIdsSelector)(apiRef);
99
- return (0, _sortRowTree.sortRowTree)({
100
- rowTree,
101
- rowIds,
102
- sortRowList: params.sortRowList,
103
- disableChildrenSorting: props.disableChildrenSorting
104
- });
105
- }, [apiRef, props.disableChildrenSorting]);
106
- (0, _internals.useGridRegisterFilteringMethod)(apiRef, TREE_DATA_GROUPING_NAME, filteringMethod);
107
- (0, _internals.useGridRegisterSortingMethod)(apiRef, TREE_DATA_GROUPING_NAME, sortingMethod);
19
+ const useGridTreeData = apiRef => {
108
20
  /**
109
21
  * EVENTS
110
22
  */
111
-
112
23
  const handleCellKeyDown = React.useCallback((params, event) => {
113
24
  const cellParams = apiRef.current.getCellParams(params.id, params.field);
114
25
 
@@ -13,14 +13,20 @@ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runt
13
13
 
14
14
  var React = _interopRequireWildcard(require("react"));
15
15
 
16
+ var _xDataGrid = require("@mui/x-data-grid");
17
+
16
18
  var _internals = require("@mui/x-data-grid/internals");
17
19
 
18
20
  var _gridTreeDataGroupColDef = require("./gridTreeDataGroupColDef");
19
21
 
20
- var _useGridTreeData = require("./useGridTreeData");
22
+ var _gridTreeDataUtils = require("./gridTreeDataUtils");
21
23
 
22
24
  var _components = require("../../../components");
23
25
 
26
+ var _buildRowTree = require("../../../utils/tree/buildRowTree");
27
+
28
+ var _sortRowTree = require("../../../utils/tree/sortRowTree");
29
+
24
30
  var _jsxRuntime = require("react/jsx-runtime");
25
31
 
26
32
  const _excluded = ["hideDescendantCount"];
@@ -30,6 +36,9 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
30
36
  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; }
31
37
 
32
38
  const useGridTreeDataPreProcessors = (apiRef, props) => {
39
+ const setStrategyAvailability = React.useCallback(() => {
40
+ apiRef.current.unstable_setStrategyAvailability('rowTree', _gridTreeDataUtils.TREE_DATA_STRATEGY, props.treeData ? () => true : () => false);
41
+ }, [apiRef, props.treeData]);
33
42
  const getGroupingColDef = React.useCallback(() => {
34
43
  var _colDefOverride;
35
44
 
@@ -38,7 +47,7 @@ const useGridTreeDataPreProcessors = (apiRef, props) => {
38
47
 
39
48
  if (typeof groupingColDefProp === 'function') {
40
49
  const params = {
41
- groupingName: _useGridTreeData.TREE_DATA_GROUPING_NAME,
50
+ groupingName: _gridTreeDataUtils.TREE_DATA_STRATEGY,
42
51
  fields: []
43
52
  };
44
53
  colDefOverride = groupingColDefProp(params);
@@ -86,7 +95,70 @@ const useGridTreeDataPreProcessors = (apiRef, props) => {
86
95
 
87
96
  return columnsState;
88
97
  }, [props.treeData, getGroupingColDef]);
98
+ const createRowTree = React.useCallback(params => {
99
+ if (!props.getTreeDataPath) {
100
+ throw new Error('MUI: No getTreeDataPath given.');
101
+ }
102
+
103
+ const rows = params.ids.map(rowId => ({
104
+ id: rowId,
105
+ path: props.getTreeDataPath(params.idRowsLookup[rowId]).map(key => ({
106
+ key,
107
+ field: null
108
+ }))
109
+ })).sort((a, b) => a.path.length - b.path.length);
110
+ return (0, _buildRowTree.buildRowTree)((0, _extends2.default)({
111
+ rows
112
+ }, params, {
113
+ defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
114
+ isGroupExpandedByDefault: props.isGroupExpandedByDefault,
115
+ groupingName: _gridTreeDataUtils.TREE_DATA_STRATEGY,
116
+ onDuplicatePath: (firstId, secondId, path) => {
117
+ throw new Error(['MUI: The path returned by `getTreeDataPath` should be unique.', `The rows with id #${firstId} and #${secondId} have the same.`, `Path: ${JSON.stringify(path.map(step => step.key))}.`].join('\n'));
118
+ }
119
+ }));
120
+ }, [props.getTreeDataPath, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault]);
121
+ const filterRows = React.useCallback(params => {
122
+ const rowTree = (0, _xDataGrid.gridRowTreeSelector)(apiRef);
123
+ return (0, _gridTreeDataUtils.filterRowTreeFromTreeData)({
124
+ rowTree,
125
+ isRowMatchingFilters: params.isRowMatchingFilters,
126
+ disableChildrenFiltering: props.disableChildrenFiltering
127
+ });
128
+ }, [apiRef, props.disableChildrenFiltering]);
129
+ const sortRows = React.useCallback(params => {
130
+ const rowTree = (0, _xDataGrid.gridRowTreeSelector)(apiRef);
131
+ const rowIds = (0, _xDataGrid.gridRowIdsSelector)(apiRef);
132
+ return (0, _sortRowTree.sortRowTree)({
133
+ rowTree,
134
+ rowIds,
135
+ sortRowList: params.sortRowList,
136
+ disableChildrenSorting: props.disableChildrenSorting
137
+ });
138
+ }, [apiRef, props.disableChildrenSorting]);
89
139
  (0, _internals.useGridRegisterPreProcessor)(apiRef, 'hydrateColumns', updateGroupingColumn);
140
+ (0, _internals.useGridRegisterStrategyProcessor)(apiRef, _gridTreeDataUtils.TREE_DATA_STRATEGY, 'rowTreeCreation', createRowTree);
141
+ (0, _internals.useGridRegisterStrategyProcessor)(apiRef, _gridTreeDataUtils.TREE_DATA_STRATEGY, 'filtering', filterRows);
142
+ (0, _internals.useGridRegisterStrategyProcessor)(apiRef, _gridTreeDataUtils.TREE_DATA_STRATEGY, 'sorting', sortRows);
143
+ /**
144
+ * 1ST RENDER
145
+ */
146
+
147
+ (0, _xDataGrid.useFirstRender)(() => {
148
+ setStrategyAvailability();
149
+ });
150
+ /**
151
+ * EFFECTS
152
+ */
153
+
154
+ const isFirstRender = React.useRef(true);
155
+ React.useEffect(() => {
156
+ if (!isFirstRender.current) {
157
+ setStrategyAvailability();
158
+ } else {
159
+ isFirstRender.current = false;
160
+ }
161
+ }, [setStrategyAvailability]);
90
162
  };
91
163
 
92
164
  exports.useGridTreeDataPreProcessors = useGridTreeDataPreProcessors;
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.6.1
1
+ /** @license MUI v5.7.0
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.