@mui/x-data-grid-premium 7.0.0-beta.6 → 7.0.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 (41) hide show
  1. package/CHANGELOG.md +311 -12
  2. package/DataGridPremium/DataGridPremium.js +26 -18
  3. package/README.md +1 -1
  4. package/esm/DataGridPremium/DataGridPremium.js +26 -18
  5. package/esm/components/GridAggregationHeader.js +1 -2
  6. package/esm/components/GridColumnMenuAggregationItem.js +2 -3
  7. package/esm/components/GridColumnMenuRowGroupItem.js +1 -2
  8. package/esm/components/GridColumnMenuRowUngroupItem.js +1 -2
  9. package/esm/components/GridExcelExportMenuItem.js +1 -1
  10. package/esm/components/GridGroupingColumnLeafCell.js +1 -2
  11. package/esm/components/GridGroupingCriteriaCell.js +2 -3
  12. package/esm/hooks/features/aggregation/gridAggregationUtils.js +4 -4
  13. package/esm/hooks/features/aggregation/useGridAggregation.js +1 -2
  14. package/esm/hooks/features/aggregation/useGridAggregationPreProcessors.js +1 -2
  15. package/esm/hooks/features/aggregation/wrapColumnWithAggregation.js +5 -9
  16. package/esm/hooks/features/cellSelection/useGridCellSelection.js +25 -34
  17. package/esm/hooks/features/clipboard/useGridClipboardImport.js +21 -8
  18. package/esm/hooks/features/export/serializer/excelSerializer.js +9 -22
  19. package/esm/hooks/features/export/useGridExcelExport.js +9 -11
  20. package/esm/hooks/features/rowGrouping/createGroupingColDef.js +23 -32
  21. package/esm/hooks/features/rowGrouping/gridRowGroupingUtils.js +4 -7
  22. package/esm/hooks/features/rowGrouping/useGridRowGrouping.js +5 -9
  23. package/esm/hooks/utils/useKeepGroupedColumnsHidden.js +7 -9
  24. package/esm/utils/releaseInfo.js +1 -1
  25. package/hooks/features/aggregation/wrapColumnWithAggregation.d.ts +1 -1
  26. package/hooks/features/cellSelection/useGridCellSelection.d.ts +1 -1
  27. package/hooks/features/cellSelection/useGridCellSelection.js +12 -12
  28. package/hooks/features/clipboard/useGridClipboardImport.d.ts +1 -1
  29. package/hooks/features/clipboard/useGridClipboardImport.js +18 -3
  30. package/hooks/features/rowGrouping/createGroupingColDef.js +3 -2
  31. package/index.js +1 -1
  32. package/models/dataGridPremiumProps.d.ts +12 -2
  33. package/models/gridApiPremium.d.ts +2 -2
  34. package/modern/DataGridPremium/DataGridPremium.js +26 -18
  35. package/modern/hooks/features/cellSelection/useGridCellSelection.js +14 -14
  36. package/modern/hooks/features/clipboard/useGridClipboardImport.js +19 -4
  37. package/modern/hooks/features/rowGrouping/createGroupingColDef.js +3 -2
  38. package/modern/index.js +1 -1
  39. package/modern/utils/releaseInfo.js +1 -1
  40. package/package.json +7 -7
  41. package/utils/releaseInfo.js +1 -1
@@ -26,10 +26,9 @@ const GROUPING_COL_DEF_FORCED_PROPERTIES = {
26
26
  * TODO: Make this index comparator depth invariant, the logic should not be inverted when sorting in the "desc" direction (but the current return format of `sortComparator` does not support this behavior).
27
27
  */
28
28
  const groupingFieldIndexComparator = (v1, v2, cellParams1, cellParams2) => {
29
- var _groupingField, _groupingField2;
30
29
  const model = gridRowGroupingSanitizedModelSelector(cellParams1.api.state, cellParams1.api.instanceId);
31
- const groupingField1 = (_groupingField = cellParams1.rowNode.groupingField) != null ? _groupingField : null;
32
- const groupingField2 = (_groupingField2 = cellParams2.rowNode.groupingField) != null ? _groupingField2 : null;
30
+ const groupingField1 = cellParams1.rowNode.groupingField ?? null;
31
+ const groupingField2 = cellParams2.rowNode.groupingField ?? null;
33
32
  if (groupingField1 === groupingField2) {
34
33
  return 0;
35
34
  }
@@ -44,23 +43,20 @@ const groupingFieldIndexComparator = (v1, v2, cellParams1, cellParams2) => {
44
43
  }
45
44
  return 1;
46
45
  };
47
- const getLeafProperties = leafColDef => {
48
- var _leafColDef$headerNam;
49
- return {
50
- headerName: (_leafColDef$headerNam = leafColDef.headerName) != null ? _leafColDef$headerNam : leafColDef.field,
51
- sortable: leafColDef.sortable,
52
- filterable: leafColDef.filterable,
53
- valueOptions: isSingleSelectColDef(leafColDef) ? leafColDef.valueOptions : undefined,
54
- filterOperators: leafColDef.filterOperators,
55
- sortComparator: (v1, v2, cellParams1, cellParams2) => {
56
- // We only want to sort the leaves
57
- if (cellParams1.rowNode.type === 'leaf' && cellParams2.rowNode.type === 'leaf') {
58
- return leafColDef.sortComparator(v1, v2, cellParams1, cellParams2);
59
- }
60
- return groupingFieldIndexComparator(v1, v2, cellParams1, cellParams2);
46
+ const getLeafProperties = leafColDef => ({
47
+ headerName: leafColDef.headerName ?? leafColDef.field,
48
+ sortable: leafColDef.sortable,
49
+ filterable: leafColDef.filterable,
50
+ valueOptions: isSingleSelectColDef(leafColDef) ? leafColDef.valueOptions : undefined,
51
+ filterOperators: leafColDef.filterOperators,
52
+ sortComparator: (v1, v2, cellParams1, cellParams2) => {
53
+ // We only want to sort the leaves
54
+ if (cellParams1.rowNode.type === 'leaf' && cellParams2.rowNode.type === 'leaf') {
55
+ return leafColDef.sortComparator(v1, v2, cellParams1, cellParams2);
61
56
  }
62
- };
63
- };
57
+ return groupingFieldIndexComparator(v1, v2, cellParams1, cellParams2);
58
+ }
59
+ });
64
60
  const getGroupingCriteriaProperties = (groupedByColDef, applyHeaderName) => {
65
61
  const properties = {
66
62
  sortable: groupedByColDef.sortable,
@@ -68,16 +64,16 @@ const getGroupingCriteriaProperties = (groupedByColDef, applyHeaderName) => {
68
64
  valueOptions: isSingleSelectColDef(groupedByColDef) ? groupedByColDef.valueOptions : undefined,
69
65
  sortComparator: (v1, v2, cellParams1, cellParams2) => {
70
66
  // We only want to sort the groups of the current grouping criteria
71
- if (cellParams1.rowNode.type === 'group' && cellParams1.rowNode.groupingField === groupedByColDef.field && cellParams2.rowNode.type === 'group' && cellParams2.rowNode.groupingField === groupedByColDef.field) {
72
- return groupedByColDef.sortComparator(v1, v2, cellParams1, cellParams2);
67
+ if (cellParams1.rowNode.type === 'group' && cellParams2.rowNode.type === 'group' && cellParams1.rowNode.groupingField === cellParams2.rowNode.groupingField) {
68
+ const colDef = cellParams1.api.getColumn(cellParams1.rowNode.groupingField);
69
+ return colDef.sortComparator(v1, v2, cellParams1, cellParams2);
73
70
  }
74
71
  return groupingFieldIndexComparator(v1, v2, cellParams1, cellParams2);
75
72
  },
76
73
  filterOperators: groupedByColDef.filterOperators
77
74
  };
78
75
  if (applyHeaderName) {
79
- var _groupedByColDef$head;
80
- properties.headerName = (_groupedByColDef$head = groupedByColDef.headerName) != null ? _groupedByColDef$head : groupedByColDef.field;
76
+ properties.headerName = groupedByColDef.headerName ?? groupedByColDef.field;
81
77
  }
82
78
  return properties;
83
79
  };
@@ -90,8 +86,7 @@ export const createGroupingColDefForOneGroupingCriteria = ({
90
86
  groupingCriteria,
91
87
  colDefOverride
92
88
  }) => {
93
- var _groupedByColDef$widt, _leafColDef$width;
94
- const _ref = colDefOverride != null ? colDefOverride : {},
89
+ const _ref = colDefOverride ?? {},
95
90
  {
96
91
  leafField,
97
92
  mainGroupingCriteria,
@@ -102,7 +97,7 @@ export const createGroupingColDefForOneGroupingCriteria = ({
102
97
 
103
98
  // The properties that do not depend on the presence of a `leafColDef` and that can be overridden by `colDefOverride`
104
99
  const commonProperties = {
105
- width: Math.max(((_groupedByColDef$widt = groupedByColDef.width) != null ? _groupedByColDef$widt : GRID_STRING_COL_DEF.width) + 40, (_leafColDef$width = leafColDef == null ? void 0 : leafColDef.width) != null ? _leafColDef$width : 0),
100
+ width: Math.max((groupedByColDef.width ?? GRID_STRING_COL_DEF.width) + 40, leafColDef?.width ?? 0),
106
101
  renderCell: params => {
107
102
  // Render footer
108
103
  if (params.rowNode.type === 'footer' || params.rowNode.type === 'pinnedRow') {
@@ -183,8 +178,7 @@ export const createGroupingColDefForAllGroupingCriteria = ({
183
178
  rowGroupingModel,
184
179
  colDefOverride
185
180
  }) => {
186
- var _leafColDef$width2;
187
- const _ref2 = colDefOverride != null ? colDefOverride : {},
181
+ const _ref2 = colDefOverride ?? {},
188
182
  {
189
183
  leafField,
190
184
  mainGroupingCriteria,
@@ -196,10 +190,7 @@ export const createGroupingColDefForAllGroupingCriteria = ({
196
190
  // The properties that do not depend on the presence of a `leafColDef` and that can be overridden by `colDefOverride`
197
191
  const commonProperties = {
198
192
  headerName: apiRef.current.getLocaleText('groupingColumnHeaderName'),
199
- width: Math.max(...rowGroupingModel.map(field => {
200
- var _columnsLookup$field$;
201
- return ((_columnsLookup$field$ = columnsLookup[field].width) != null ? _columnsLookup$field$ : GRID_STRING_COL_DEF.width) + 40;
202
- }), (_leafColDef$width2 = leafColDef == null ? void 0 : leafColDef.width) != null ? _leafColDef$width2 : 0),
193
+ width: Math.max(...rowGroupingModel.map(field => (columnsLookup[field].width ?? GRID_STRING_COL_DEF.width) + 40), leafColDef?.width ?? 0),
203
194
  renderCell: params => {
204
195
  // Render footer
205
196
  if (params.rowNode.type === 'footer' || params.rowNode.type === 'pinnedRow') {
@@ -142,13 +142,10 @@ export const getCellGroupingCriteria = ({
142
142
  export const getGroupingRules = ({
143
143
  sanitizedRowGroupingModel,
144
144
  columnsLookup
145
- }) => sanitizedRowGroupingModel.map(field => {
146
- var _columnsLookup$field;
147
- return {
148
- field,
149
- groupingValueGetter: (_columnsLookup$field = columnsLookup[field]) == null ? void 0 : _columnsLookup$field.groupingValueGetter
150
- };
151
- });
145
+ }) => sanitizedRowGroupingModel.map(field => ({
146
+ field,
147
+ groupingValueGetter: columnsLookup[field]?.groupingValueGetter
148
+ }));
152
149
 
153
150
  /**
154
151
  * Compares two sets of grouping rules to determine if they are equal or not.
@@ -5,13 +5,12 @@ import { useGridRegisterPipeProcessor } from '@mui/x-data-grid-pro/internals';
5
5
  import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
6
6
  import { getRowGroupingFieldFromGroupingCriteria, ROW_GROUPING_STRATEGY, isGroupingColumn, mergeStateWithRowGroupingModel, setStrategyAvailability, getGroupingRules, areGroupingRulesEqual } from './gridRowGroupingUtils';
7
7
  export const rowGroupingStateInitializer = (state, props, apiRef) => {
8
- var _ref, _props$rowGroupingMod, _props$initialState;
9
8
  apiRef.current.caches.rowGrouping = {
10
9
  rulesOnLastRowTreeCreation: []
11
10
  };
12
11
  return _extends({}, state, {
13
12
  rowGrouping: {
14
- model: (_ref = (_props$rowGroupingMod = props.rowGroupingModel) != null ? _props$rowGroupingMod : (_props$initialState = props.initialState) == null || (_props$initialState = _props$initialState.rowGrouping) == null ? void 0 : _props$initialState.model) != null ? _ref : []
13
+ model: props.rowGroupingModel ?? props.initialState?.rowGrouping?.model ?? []
15
14
  }
16
15
  });
17
16
  };
@@ -22,7 +21,6 @@ export const rowGroupingStateInitializer = (state, props, apiRef) => {
22
21
  * @requires useGridParamsApi (method) - can be after, async only
23
22
  */
24
23
  export const useGridRowGrouping = (apiRef, props) => {
25
- var _props$initialState3;
26
24
  apiRef.current.registerControlState({
27
25
  stateId: 'rowGrouping',
28
26
  propModel: props.rowGroupingModel,
@@ -47,7 +45,7 @@ export const useGridRowGrouping = (apiRef, props) => {
47
45
  if (currentModel.includes(field)) {
48
46
  return;
49
47
  }
50
- const cleanGroupingIndex = groupingIndex != null ? groupingIndex : currentModel.length;
48
+ const cleanGroupingIndex = groupingIndex ?? currentModel.length;
51
49
  const updatedModel = [...currentModel.slice(0, cleanGroupingIndex), field, ...currentModel.slice(cleanGroupingIndex)];
52
50
  apiRef.current.setRowGroupingModel(updatedModel);
53
51
  }, [apiRef]);
@@ -89,7 +87,6 @@ export const useGridRowGrouping = (apiRef, props) => {
89
87
  return columnMenuItems;
90
88
  }, [props.disableRowGrouping]);
91
89
  const stateExportPreProcessing = React.useCallback((prevState, context) => {
92
- var _props$initialState2;
93
90
  const rowGroupingModelToExport = gridRowGroupingModelSelector(apiRef);
94
91
  const shouldExportRowGroupingModel =
95
92
  // Always export if the `exportOnlyDirtyModels` property is not activated
@@ -97,7 +94,7 @@ export const useGridRowGrouping = (apiRef, props) => {
97
94
  // Always export if the model is controlled
98
95
  props.rowGroupingModel != null ||
99
96
  // Always export if the model has been initialized
100
- ((_props$initialState2 = props.initialState) == null || (_props$initialState2 = _props$initialState2.rowGrouping) == null ? void 0 : _props$initialState2.model) != null ||
97
+ props.initialState?.rowGrouping?.model != null ||
101
98
  // Export if the model is not empty
102
99
  Object.keys(rowGroupingModelToExport).length > 0;
103
100
  if (!shouldExportRowGroupingModel) {
@@ -108,13 +105,12 @@ export const useGridRowGrouping = (apiRef, props) => {
108
105
  model: rowGroupingModelToExport
109
106
  }
110
107
  });
111
- }, [apiRef, props.rowGroupingModel, (_props$initialState3 = props.initialState) == null || (_props$initialState3 = _props$initialState3.rowGrouping) == null ? void 0 : _props$initialState3.model]);
108
+ }, [apiRef, props.rowGroupingModel, props.initialState?.rowGrouping?.model]);
112
109
  const stateRestorePreProcessing = React.useCallback((params, context) => {
113
- var _context$stateToResto;
114
110
  if (props.disableRowGrouping) {
115
111
  return params;
116
112
  }
117
- const rowGroupingModel = (_context$stateToResto = context.stateToRestore.rowGrouping) == null ? void 0 : _context$stateToResto.model;
113
+ const rowGroupingModel = context.stateToRestore.rowGrouping?.model;
118
114
  if (rowGroupingModel != null) {
119
115
  apiRef.current.setState(mergeStateWithRowGroupingModel(rowGroupingModel));
120
116
  }
@@ -3,13 +3,13 @@ import * as React from 'react';
3
3
  import { gridColumnVisibilityModelSelector } from '@mui/x-data-grid-pro';
4
4
  const updateColumnVisibilityModel = (columnVisibilityModel, rowGroupingModel, prevRowGroupingModel) => {
5
5
  const newColumnVisibilityModel = _extends({}, columnVisibilityModel);
6
- rowGroupingModel == null || rowGroupingModel.forEach(field => {
7
- if (!(prevRowGroupingModel != null && prevRowGroupingModel.includes(field))) {
6
+ rowGroupingModel?.forEach(field => {
7
+ if (!prevRowGroupingModel?.includes(field)) {
8
8
  newColumnVisibilityModel[field] = false;
9
9
  }
10
10
  });
11
- prevRowGroupingModel == null || prevRowGroupingModel.forEach(field => {
12
- if (!(rowGroupingModel != null && rowGroupingModel.includes(field))) {
11
+ prevRowGroupingModel?.forEach(field => {
12
+ if (!rowGroupingModel?.includes(field)) {
13
13
  newColumnVisibilityModel[field] = true;
14
14
  }
15
15
  });
@@ -22,9 +22,8 @@ const updateColumnVisibilityModel = (columnVisibilityModel, rowGroupingModel, pr
22
22
  * Does not work when used with the `hide` property of `GridColDef`
23
23
  */
24
24
  export const useKeepGroupedColumnsHidden = props => {
25
- var _props$rowGroupingMod, _props$initialState;
26
25
  const initialProps = React.useRef(props);
27
- const rowGroupingModel = React.useRef((_props$rowGroupingMod = props.rowGroupingModel) != null ? _props$rowGroupingMod : (_props$initialState = props.initialState) == null || (_props$initialState = _props$initialState.rowGrouping) == null ? void 0 : _props$initialState.model);
26
+ const rowGroupingModel = React.useRef(props.rowGroupingModel ?? props.initialState?.rowGrouping?.model);
28
27
  React.useEffect(() => {
29
28
  props.apiRef.current.subscribeEvent('rowGroupingModelChange', newModel => {
30
29
  const columnVisibilityModel = updateColumnVisibilityModel(gridColumnVisibilityModelSelector(props.apiRef), newModel, rowGroupingModel.current);
@@ -33,11 +32,10 @@ export const useKeepGroupedColumnsHidden = props => {
33
32
  });
34
33
  }, [props.apiRef]);
35
34
  return React.useMemo(() => {
36
- var _invariantInitialStat;
37
35
  const invariantInitialState = initialProps.current.initialState;
38
- const columnVisibilityModel = updateColumnVisibilityModel(invariantInitialState == null || (_invariantInitialStat = invariantInitialState.columns) == null ? void 0 : _invariantInitialStat.columnVisibilityModel, rowGroupingModel.current, undefined);
36
+ const columnVisibilityModel = updateColumnVisibilityModel(invariantInitialState?.columns?.columnVisibilityModel, rowGroupingModel.current, undefined);
39
37
  return _extends({}, invariantInitialState, {
40
- columns: _extends({}, invariantInitialState == null ? void 0 : invariantInitialState.columns, {
38
+ columns: _extends({}, invariantInitialState?.columns, {
41
39
  columnVisibilityModel
42
40
  })
43
41
  });
@@ -1,6 +1,6 @@
1
1
  import { ponyfillGlobal } from '@mui/utils';
2
2
  export const getReleaseInfo = () => {
3
- const releaseInfo = "MTcwOTg1MjQwMDAwMA==";
3
+ const releaseInfo = "MTcxMTA1ODQwMDAwMA==";
4
4
  if (process.env.NODE_ENV !== 'production') {
5
5
  // A simple hack to set the value in the test environment (has no build step).
6
6
  // eslint-disable-next-line no-useless-concat
@@ -64,7 +64,7 @@ export declare const unwrapColumnFromAggregation: ({ column, }: {
64
64
  disableReorder?: boolean | undefined;
65
65
  disableExport?: boolean | undefined;
66
66
  colSpan?: number | import("@mui/x-data-grid-pro").GridColSpanFn<import("@mui/x-data-grid-pro").GridValidRowModel, any, any> | undefined;
67
- renderHeaderFilter?: ((params: import("@mui/x-data-grid-pro").GridHeaderFilterCellProps) => React.ReactNode) | undefined;
67
+ renderHeaderFilter?: ((params: import("@mui/x-data-grid-pro").GridRenderHeaderFilterProps) => React.ReactNode) | undefined;
68
68
  aggregable?: boolean | undefined;
69
69
  availableAggregationFunctions?: string[] | undefined;
70
70
  groupingValueGetter?: import("../../..").GridGroupingValueGetter<import("@mui/x-data-grid-pro").GridValidRowModel> | undefined;
@@ -3,4 +3,4 @@ import { GridStateInitializer } from '@mui/x-data-grid-pro/internals';
3
3
  import { DataGridPremiumProcessedProps } from '../../../models/dataGridPremiumProps';
4
4
  import { GridPrivateApiPremium } from '../../../models/gridApiPremium';
5
5
  export declare const cellSelectionStateInitializer: GridStateInitializer<Pick<DataGridPremiumProcessedProps, 'cellSelectionModel' | 'initialState'>>;
6
- export declare const useGridCellSelection: (apiRef: React.MutableRefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'cellSelection' | 'cellSelectionModel' | 'onCellSelectionModelChange' | 'pagination' | 'paginationMode' | 'ignoreValueFormatterDuringExport' | 'clipboardCopyCellDelimiter'>) => void;
6
+ export declare const useGridCellSelection: (apiRef: React.MutableRefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'cellSelection' | 'cellSelectionModel' | 'onCellSelectionModelChange' | 'pagination' | 'paginationMode' | 'ignoreValueFormatterDuringExport' | 'clipboardCopyCellDelimiter' | 'columnHeaderHeight'>) => void;
@@ -30,6 +30,8 @@ const useGridCellSelection = (apiRef, props) => {
30
30
  const mousePosition = React.useRef(null);
31
31
  const autoScrollRAF = React.useRef();
32
32
  const sortedRowIds = (0, _xDataGridPro.useGridSelector)(apiRef, _xDataGridPro.gridSortedRowIdsSelector);
33
+ const dimensions = (0, _xDataGridPro.useGridSelector)(apiRef, _xDataGridPro.gridDimensionsSelector);
34
+ const totalHeaderHeight = (0, _internals.getTotalHeaderHeight)(apiRef, props.columnHeaderHeight);
33
35
  const ignoreValueFormatterProp = props.ignoreValueFormatterDuringExport;
34
36
  const ignoreValueFormatter = (typeof ignoreValueFormatterProp === 'object' ? ignoreValueFormatterProp?.clipboardExport : ignoreValueFormatterProp) || false;
35
37
  const clipboardCopyCellDelimiter = props.clipboardCopyCellDelimiter;
@@ -176,10 +178,6 @@ const useGridCellSelection = (apiRef, props) => {
176
178
  if (!apiRef.current.virtualScrollerRef?.current) {
177
179
  return;
178
180
  }
179
- const virtualScrollerRect = apiRef.current.virtualScrollerRef?.current?.getBoundingClientRect();
180
- if (!virtualScrollerRect) {
181
- return;
182
- }
183
181
  function autoScroll() {
184
182
  if (!mousePosition.current || !apiRef.current.virtualScrollerRef?.current) {
185
183
  return;
@@ -191,11 +189,10 @@ const useGridCellSelection = (apiRef, props) => {
191
189
  const {
192
190
  height,
193
191
  width
194
- } = virtualScrollerRect;
192
+ } = dimensions.viewportInnerSize;
195
193
  let deltaX = 0;
196
194
  let deltaY = 0;
197
195
  let factor = 0;
198
- const dimensions = apiRef.current.getRootDimensions();
199
196
  if (mouseY <= AUTO_SCROLL_SENSITIVITY && dimensions.hasScrollY) {
200
197
  // When scrolling up, the multiplier increases going closer to the top edge
201
198
  factor = (AUTO_SCROLL_SENSITIVITY - mouseY) / -AUTO_SCROLL_SENSITIVITY;
@@ -226,7 +223,7 @@ const useGridCellSelection = (apiRef, props) => {
226
223
  autoScrollRAF.current = requestAnimationFrame(autoScroll);
227
224
  }
228
225
  autoScroll();
229
- }, [apiRef]);
226
+ }, [apiRef, dimensions]);
230
227
  const handleCellMouseOver = React.useCallback((params, event) => {
231
228
  if (!lastMouseDownCell.current) {
232
229
  return;
@@ -244,13 +241,15 @@ const useGridCellSelection = (apiRef, props) => {
244
241
  return;
245
242
  }
246
243
  const {
247
- height,
248
- width,
249
244
  x,
250
245
  y
251
246
  } = virtualScrollerRect;
247
+ const {
248
+ height,
249
+ width
250
+ } = dimensions.viewportInnerSize;
252
251
  const mouseX = event.clientX - x;
253
- const mouseY = event.clientY - y;
252
+ const mouseY = event.clientY - y - totalHeaderHeight;
254
253
  mousePosition.current = {
255
254
  x: mouseX,
256
255
  y: mouseY
@@ -265,7 +264,7 @@ const useGridCellSelection = (apiRef, props) => {
265
264
  // Mouse has left the sensitivity area while auto scroll is on
266
265
  stopAutoScroll();
267
266
  }
268
- }, [apiRef, startAutoScroll, stopAutoScroll]);
267
+ }, [apiRef, startAutoScroll, stopAutoScroll, totalHeaderHeight, dimensions]);
269
268
  const handleCellClick = (0, _utils.useEventCallback)((params, event) => {
270
269
  const {
271
270
  id,
@@ -457,7 +456,8 @@ const useGridCellSelection = (apiRef, props) => {
457
456
  const cellParams = apiRef.current.getCellParams(rowId, field);
458
457
  cellData = (0, _internals.serializeCellValue)(cellParams, {
459
458
  delimiterCharacter: clipboardCopyCellDelimiter,
460
- ignoreValueFormatter
459
+ ignoreValueFormatter,
460
+ shouldAppendQuotes: true
461
461
  });
462
462
  } else {
463
463
  cellData = '';
@@ -1,4 +1,4 @@
1
1
  import * as React from 'react';
2
2
  import { GridPrivateApiPremium } from '../../../models/gridApiPremium';
3
3
  import type { DataGridPremiumProcessedProps } from '../../../models/dataGridPremiumProps';
4
- export declare const useGridClipboardImport: (apiRef: React.MutableRefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'pagination' | 'paginationMode' | 'processRowUpdate' | 'onProcessRowUpdateError' | 'getRowId' | 'onClipboardPasteStart' | 'onClipboardPasteEnd' | 'splitClipboardPastedText' | 'disableClipboardPaste'>) => void;
4
+ export declare const useGridClipboardImport: (apiRef: React.MutableRefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'pagination' | 'paginationMode' | 'processRowUpdate' | 'onProcessRowUpdateError' | 'getRowId' | 'onClipboardPasteStart' | 'onClipboardPasteEnd' | 'splitClipboardPastedText' | 'disableClipboardPaste' | 'onBeforeClipboardPasteStart'>) => void;
@@ -13,7 +13,7 @@ var _xDataGridPro = require("@mui/x-data-grid-pro");
13
13
  var _utils = require("@mui/utils");
14
14
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
15
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
- const missingOnProcessRowUpdateErrorWarning = (0, _internals.buildWarning)(['MUI X: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop, e.g. `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/#server-side-persistence.'], 'error');
16
+ const missingOnProcessRowUpdateErrorWarning = (0, _internals.buildWarning)(['MUI X: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/#server-side-persistence.'], 'error');
17
17
  const columnFieldsToExcludeFromPaste = [_xDataGrid.GRID_CHECKBOX_SELECTION_FIELD, _xDataGridPro.GRID_REORDER_COL_DEF.field, _xDataGridPro.GRID_DETAIL_PANEL_TOGGLE_FIELD];
18
18
 
19
19
  // Batches rows that are updated during clipboard paste to reduce `updateRows` calls
@@ -249,7 +249,12 @@ const useGridClipboardImport = (apiRef, props) => {
249
249
  const getRowId = props.getRowId;
250
250
  const enableClipboardPaste = !props.disableClipboardPaste;
251
251
  const rootEl = apiRef.current.rootElementRef?.current;
252
+ const logger = (0, _internals.useGridLogger)(apiRef, 'useGridClipboardImport');
252
253
  const splitClipboardPastedText = props.splitClipboardPastedText;
254
+ const {
255
+ pagination,
256
+ onBeforeClipboardPasteStart
257
+ } = props;
253
258
  const handlePaste = React.useCallback(async (params, event) => {
254
259
  if (!enableClipboardPaste) {
255
260
  return;
@@ -276,6 +281,16 @@ const useGridClipboardImport = (apiRef, props) => {
276
281
  if (!pastedData) {
277
282
  return;
278
283
  }
284
+ if (onBeforeClipboardPasteStart) {
285
+ try {
286
+ await onBeforeClipboardPasteStart({
287
+ data: pastedData
288
+ });
289
+ } catch (error) {
290
+ logger.debug('Clipboard paste operation cancelled');
291
+ return;
292
+ }
293
+ }
279
294
  const cellUpdater = new CellValueUpdater({
280
295
  apiRef,
281
296
  processRowUpdate,
@@ -291,10 +306,10 @@ const useGridClipboardImport = (apiRef, props) => {
291
306
  updateCell: (...args) => {
292
307
  cellUpdater.updateCell(...args);
293
308
  },
294
- pagination: props.pagination
309
+ pagination
295
310
  });
296
311
  cellUpdater.applyUpdates();
297
- }, [apiRef, processRowUpdate, onProcessRowUpdateError, getRowId, enableClipboardPaste, rootEl, splitClipboardPastedText, props.pagination]);
312
+ }, [apiRef, processRowUpdate, onProcessRowUpdateError, getRowId, enableClipboardPaste, rootEl, splitClipboardPastedText, pagination, onBeforeClipboardPasteStart, logger]);
298
313
  const checkIfCanStartEditing = React.useCallback((initialValue, {
299
314
  event
300
315
  }) => {
@@ -73,8 +73,9 @@ const getGroupingCriteriaProperties = (groupedByColDef, applyHeaderName) => {
73
73
  valueOptions: (0, _internals.isSingleSelectColDef)(groupedByColDef) ? groupedByColDef.valueOptions : undefined,
74
74
  sortComparator: (v1, v2, cellParams1, cellParams2) => {
75
75
  // We only want to sort the groups of the current grouping criteria
76
- if (cellParams1.rowNode.type === 'group' && cellParams1.rowNode.groupingField === groupedByColDef.field && cellParams2.rowNode.type === 'group' && cellParams2.rowNode.groupingField === groupedByColDef.field) {
77
- return groupedByColDef.sortComparator(v1, v2, cellParams1, cellParams2);
76
+ if (cellParams1.rowNode.type === 'group' && cellParams2.rowNode.type === 'group' && cellParams1.rowNode.groupingField === cellParams2.rowNode.groupingField) {
77
+ const colDef = cellParams1.api.getColumn(cellParams1.rowNode.groupingField);
78
+ return colDef.sortComparator(v1, v2, cellParams1, cellParams2);
78
79
  }
79
80
  return groupingFieldIndexComparator(v1, v2, cellParams1, cellParams2);
80
81
  },
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid-premium v7.0.0-beta.6
2
+ * @mui/x-data-grid-premium v7.0.0
3
3
  *
4
4
  * @license MUI X Commercial
5
5
  * This source code is licensed under the commercial license found in the
@@ -18,7 +18,7 @@ export interface DataGridPremiumPropsWithComplexDefaultValueBeforeProcessing ext
18
18
  /**
19
19
  * The props users can give to the `DataGridPremiumProps` component.
20
20
  */
21
- export interface DataGridPremiumProps<R extends GridValidRowModel = any> extends Omit<Partial<DataGridPremiumPropsWithDefaultValue> & DataGridPremiumPropsWithComplexDefaultValueBeforeProcessing & DataGridPremiumPropsWithoutDefaultValue<R>, DataGridPremiumForcedPropsKey> {
21
+ export interface DataGridPremiumProps<R extends GridValidRowModel = any> extends Omit<Partial<DataGridPremiumPropsWithDefaultValue<R>> & DataGridPremiumPropsWithComplexDefaultValueBeforeProcessing & DataGridPremiumPropsWithoutDefaultValue<R>, DataGridPremiumForcedPropsKey> {
22
22
  }
23
23
  export interface DataGridPremiumPropsWithComplexDefaultValueAfterProcessing extends Pick<DataGridPropsWithComplexDefaultValueAfterProcessing, 'localeText'> {
24
24
  slots: GridPremiumSlotsComponent;
@@ -34,7 +34,7 @@ export type DataGridPremiumForcedPropsKey = 'signature';
34
34
  * None of the entry of this interface should be optional, they all have default values and `DataGridProps` already applies a `Partial<DataGridSimpleOptions>` for the public interface.
35
35
  * The controlled model do not have a default value at the prop processing level, so they must be defined in `DataGridOtherProps`.
36
36
  */
37
- export interface DataGridPremiumPropsWithDefaultValue extends DataGridProPropsWithDefaultValue {
37
+ export interface DataGridPremiumPropsWithDefaultValue<R extends GridValidRowModel = any> extends DataGridProPropsWithDefaultValue<R> {
38
38
  /**
39
39
  * If `true`, the cell selection mode is enabled.
40
40
  * @default false
@@ -134,6 +134,16 @@ export interface DataGridPremiumPropsWithoutDefaultValue<R extends GridValidRowM
134
134
  * @param {string} inProgress Indicates if the task is in progress.
135
135
  */
136
136
  onExcelExportStateChange?: (inProgress: 'pending' | 'finished') => void;
137
+ /**
138
+ * Callback fired before the clipboard paste operation starts.
139
+ * Use it to confirm or cancel the paste operation.
140
+ * @param {object} params Params passed to the callback.
141
+ * @param {string[][]} params.data The raw pasted data split by rows and cells.
142
+ * @returns {Promise<any>} A promise that resolves to confirm the paste operation, and rejects to cancel it.
143
+ */
144
+ onBeforeClipboardPasteStart?: (params: {
145
+ data: string[][];
146
+ }) => Promise<any>;
137
147
  /**
138
148
  * Callback fired when the clipboard paste operation starts.
139
149
  */
@@ -1,5 +1,5 @@
1
1
  import { GridPrivateOnlyApiCommon } from '@mui/x-data-grid/internals';
2
- import { GridApiCommon, GridColumnPinningApi, GridColumnResizeApi, GridDetailPanelApi, GridDetailPanelPrivateApi, GridRowPinningApi, GridRowMultiSelectionApi, GridColumnReorderApi, GridRowProApi } from '@mui/x-data-grid-pro';
2
+ import { GridApiCommon, GridColumnPinningApi, GridDetailPanelApi, GridDetailPanelPrivateApi, GridRowPinningApi, GridRowMultiSelectionApi, GridColumnReorderApi, GridRowProApi } from '@mui/x-data-grid-pro';
3
3
  import { GridInitialStatePremium, GridStatePremium } from './gridStatePremium';
4
4
  import type { GridRowGroupingApi, GridExcelExportApi, GridAggregationApi } from '../hooks';
5
5
  import { GridCellSelectionApi } from '../hooks/features/cellSelection/gridCellSelectionInterfaces';
@@ -8,7 +8,7 @@ import type { DataGridPremiumProcessedProps } from './dataGridPremiumProps';
8
8
  * The api of `DataGridPremium`.
9
9
  * TODO: Do not redefine manually the pro features
10
10
  */
11
- export interface GridApiPremium extends GridApiCommon<GridStatePremium, GridInitialStatePremium>, GridRowProApi, GridColumnPinningApi, GridColumnResizeApi, GridDetailPanelApi, GridRowGroupingApi, GridExcelExportApi, GridAggregationApi, GridRowPinningApi, GridCellSelectionApi, GridRowMultiSelectionApi, GridColumnReorderApi {
11
+ export interface GridApiPremium extends GridApiCommon<GridStatePremium, GridInitialStatePremium>, GridRowProApi, GridColumnPinningApi, GridDetailPanelApi, GridRowGroupingApi, GridExcelExportApi, GridAggregationApi, GridRowPinningApi, GridCellSelectionApi, GridRowMultiSelectionApi, GridColumnReorderApi {
12
12
  }
13
13
  export interface GridPrivateApiPremium extends GridApiPremium, GridPrivateOnlyApiCommon<GridApiPremium, GridPrivateApiPremium, DataGridPremiumProcessedProps>, GridDetailPanelPrivateApi {
14
14
  }
@@ -138,10 +138,10 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
138
138
  */
139
139
  clipboardCopyCellDelimiter: PropTypes.string,
140
140
  /**
141
- * Number of extra columns to be rendered before/after the visible slice.
142
- * @default 3
141
+ * Column region in pixels to render before/after the viewport
142
+ * @default 150
143
143
  */
144
- columnBuffer: PropTypes.number,
144
+ columnBufferPx: PropTypes.number,
145
145
  columnGroupingModel: PropTypes.arrayOf(PropTypes.object),
146
146
  /**
147
147
  * Sets the height in pixel of the column headers in the Data Grid.
@@ -152,11 +152,6 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
152
152
  * Set of columns of type [[GridColDef]][].
153
153
  */
154
154
  columns: PropTypes.arrayOf(PropTypes.object).isRequired,
155
- /**
156
- * Number of rows from the `columnBuffer` that can be visible before a new slice is rendered.
157
- * @default 3
158
- */
159
- columnThreshold: PropTypes.number,
160
155
  /**
161
156
  * Set the column visibility model of the Data Grid.
162
157
  * If defined, the Data Grid will ignore the `hide` property in [[GridColDef]].
@@ -288,7 +283,6 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
288
283
  * For each feature, if the flag is not explicitly set to `true`, then the feature is fully disabled, and neither property nor method calls will have any effect.
289
284
  */
290
285
  experimentalFeatures: PropTypes.shape({
291
- lazyLoading: PropTypes.bool,
292
286
  warnIfFocusStateIsNotSynced: PropTypes.bool
293
287
  }),
294
288
  /**
@@ -504,6 +498,14 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
504
498
  * @param {GridCallbackDetails} details Additional details for this callback.
505
499
  */
506
500
  onAggregationModelChange: PropTypes.func,
501
+ /**
502
+ * Callback fired before the clipboard paste operation starts.
503
+ * Use it to confirm or cancel the paste operation.
504
+ * @param {object} params Params passed to the callback.
505
+ * @param {string[][]} params.data The raw pasted data split by rows and cells.
506
+ * @returns {Promise<any>} A promise that resolves to confirm the paste operation, and rejects to cancel it.
507
+ */
508
+ onBeforeClipboardPasteStart: PropTypes.func,
507
509
  /**
508
510
  * Callback fired when any cell is clicked.
509
511
  * @param {GridCellParams} params With all properties from [[GridCellParams]].
@@ -631,6 +633,11 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
631
633
  * @param {GridCallbackDetails} details Additional details for this callback.
632
634
  */
633
635
  onColumnWidthChange: PropTypes.func,
636
+ /**
637
+ * Callback fired when the density changes.
638
+ * @param {GridDensity} density New density value.
639
+ */
640
+ onDensityChange: PropTypes.func,
634
641
  /**
635
642
  * Callback fired when the detail panel of a row is opened or closed.
636
643
  * @param {GridRowId[]} ids The ids of the rows which have the detail panel open.
@@ -715,6 +722,11 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
715
722
  * @param {GridCallbackDetails} details Additional details for this callback.
716
723
  */
717
724
  onRowClick: PropTypes.func,
725
+ /**
726
+ * Callback fired when the row count has changed.
727
+ * @param {number} count Updated row count.
728
+ */
729
+ onRowCountChange: PropTypes.func,
718
730
  /**
719
731
  * Callback fired when a double click event comes from a row container element.
720
732
  * @param {GridRowParams} params With all properties from [[RowParams]].
@@ -827,10 +839,10 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
827
839
  */
828
840
  processRowUpdate: PropTypes.func,
829
841
  /**
830
- * Number of extra rows to be rendered before/after the visible slice.
831
- * @default 3
842
+ * Row region in pixels to render before/after the viewport
843
+ * @default 150
832
844
  */
833
- rowBuffer: PropTypes.number,
845
+ rowBufferPx: PropTypes.number,
834
846
  /**
835
847
  * Set the total number of rows, if it is different from the length of the value `rows` prop.
836
848
  * If some rows have children (for instance in the tree data), this number represents the amount of top level rows.
@@ -869,8 +881,9 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
869
881
  rowReordering: PropTypes.bool,
870
882
  /**
871
883
  * Set of rows of type [[GridRowsProp]].
884
+ * @default []
872
885
  */
873
- rows: PropTypes.arrayOf(PropTypes.object).isRequired,
886
+ rows: PropTypes.arrayOf(PropTypes.object),
874
887
  /**
875
888
  * If `false`, the row selection mode is disabled.
876
889
  * @default true
@@ -892,11 +905,6 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
892
905
  * @default "margin"
893
906
  */
894
907
  rowSpacingType: PropTypes.oneOf(['border', 'margin']),
895
- /**
896
- * Number of rows from the `rowBuffer` that can be visible before a new slice is rendered.
897
- * @default 3
898
- */
899
- rowThreshold: PropTypes.number,
900
908
  /**
901
909
  * Override the height/width of the Data Grid inner scrollbar.
902
910
  */