@mui/x-data-grid 8.9.2 → 8.10.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 +217 -6
  2. package/components/GridFooter.js +1 -1
  3. package/components/GridPagination.js +4 -3
  4. package/components/GridRow.js +8 -6
  5. package/components/virtualization/GridVirtualScroller.js +3 -3
  6. package/esm/DataGrid/index.js +1 -1
  7. package/esm/components/GridFooter.js +1 -1
  8. package/esm/components/GridPagination.js +3 -2
  9. package/esm/components/GridRow.js +8 -6
  10. package/esm/components/virtualization/GridVirtualScroller.js +3 -3
  11. package/esm/hooks/core/useGridVirtualizer.js +64 -44
  12. package/esm/hooks/features/dataSource/cache.js +0 -3
  13. package/esm/hooks/features/dataSource/gridDataSourceError.js +16 -16
  14. package/esm/hooks/features/dataSource/models.d.ts +11 -2
  15. package/esm/hooks/features/dataSource/useGridDataSourceBase.d.ts +1 -1
  16. package/esm/hooks/features/dataSource/useGridDataSourceBase.js +9 -2
  17. package/esm/hooks/features/dataSource/utils.js +51 -52
  18. package/esm/hooks/features/dimensions/gridDimensionsApi.d.ts +2 -67
  19. package/esm/hooks/features/dimensions/useGridDimensions.js +20 -15
  20. package/esm/hooks/features/editing/useGridRowEditing.js +4 -1
  21. package/esm/hooks/features/export/serializers/csvSerializer.js +2 -3
  22. package/esm/hooks/features/export/useGridPrintExport.js +3 -8
  23. package/esm/hooks/features/rowReorder/gridRowReorderInterfaces.d.ts +9 -0
  24. package/esm/hooks/features/rowReorder/gridRowReorderInterfaces.js +1 -0
  25. package/esm/hooks/features/rowReorder/gridRowReorderSelector.d.ts +5 -0
  26. package/esm/hooks/features/rowReorder/gridRowReorderSelector.js +3 -0
  27. package/esm/hooks/features/rowSelection/useGridRowSelection.js +2 -2
  28. package/esm/hooks/features/rowSelection/utils.js +5 -0
  29. package/esm/index.js +1 -1
  30. package/esm/internals/index.d.ts +2 -0
  31. package/esm/internals/index.js +1 -0
  32. package/esm/internals/utils/cache.js +0 -1
  33. package/esm/locales/nnNO.js +96 -107
  34. package/esm/material/index.js +2 -2
  35. package/esm/models/api/gridApiCommon.d.ts +1 -1
  36. package/esm/models/gridRowSelectionManager.js +0 -2
  37. package/esm/models/gridStateCommunity.d.ts +2 -0
  38. package/esm/utils/cleanupTracking/FinalizationRegistryBasedCleanupTracking.js +5 -7
  39. package/esm/utils/cleanupTracking/TimerBasedCleanupTracking.js +2 -2
  40. package/hooks/core/useGridVirtualizer.js +62 -42
  41. package/hooks/features/dataSource/cache.js +0 -3
  42. package/hooks/features/dataSource/gridDataSourceError.js +16 -16
  43. package/hooks/features/dataSource/models.d.ts +11 -2
  44. package/hooks/features/dataSource/useGridDataSourceBase.d.ts +1 -1
  45. package/hooks/features/dataSource/useGridDataSourceBase.js +10 -3
  46. package/hooks/features/dataSource/utils.js +51 -52
  47. package/hooks/features/dimensions/gridDimensionsApi.d.ts +2 -67
  48. package/hooks/features/dimensions/useGridDimensions.js +20 -15
  49. package/hooks/features/editing/useGridRowEditing.js +4 -1
  50. package/hooks/features/export/serializers/csvSerializer.js +2 -3
  51. package/hooks/features/export/useGridPrintExport.js +3 -8
  52. package/hooks/features/rowReorder/gridRowReorderInterfaces.d.ts +9 -0
  53. package/hooks/features/rowReorder/gridRowReorderInterfaces.js +5 -0
  54. package/hooks/features/rowReorder/gridRowReorderSelector.d.ts +5 -0
  55. package/hooks/features/rowReorder/gridRowReorderSelector.js +9 -0
  56. package/hooks/features/rowSelection/useGridRowSelection.js +2 -2
  57. package/hooks/features/rowSelection/utils.js +5 -0
  58. package/index.js +1 -1
  59. package/internals/index.d.ts +2 -0
  60. package/internals/index.js +8 -0
  61. package/internals/utils/cache.js +0 -1
  62. package/locales/nnNO.js +96 -107
  63. package/material/index.js +2 -2
  64. package/models/api/gridApiCommon.d.ts +1 -1
  65. package/models/gridRowSelectionManager.js +0 -2
  66. package/models/gridStateCommunity.d.ts +2 -0
  67. package/package.json +16 -18
  68. package/utils/cleanupTracking/FinalizationRegistryBasedCleanupTracking.js +5 -7
  69. package/utils/cleanupTracking/TimerBasedCleanupTracking.js +2 -2
@@ -1,14 +1,16 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
+ import useLazyRef from '@mui/utils/useLazyRef';
3
4
  import useEventCallback from '@mui/utils/useEventCallback';
4
5
  import { useRtl } from '@mui/system/RtlProvider';
5
6
  import { roundToDecimalPlaces } from '@mui/x-internals/math';
7
+ import { lruMemoize } from '@mui/x-internals/lruMemoize';
6
8
  import { useStoreEffect } from '@mui/x-internals/store';
7
- import { useVirtualizer } from '@mui/x-virtualizer';
9
+ import { useVirtualizer, Dimensions } from '@mui/x-virtualizer';
8
10
  import { useFirstRender } from "../utils/useFirstRender.js";
9
11
  import { createSelector } from "../../utils/createSelector.js";
10
12
  import { useGridSelector } from "../utils/useGridSelector.js";
11
- import { gridContentHeightSelector, gridHasFillerSelector, gridVerticalScrollbarWidthSelector } from "../features/dimensions/gridDimensionsSelectors.js";
13
+ import { gridHasFillerSelector, gridVerticalScrollbarWidthSelector } from "../features/dimensions/gridDimensionsSelectors.js";
12
14
  import { gridDensityFactorSelector } from "../features/density/index.js";
13
15
  import { gridVisibleColumnDefinitionsSelector, gridVisiblePinnedColumnDefinitionsSelector, gridColumnPositionsSelector, gridHasColSpanSelector } from "../features/columns/gridColumnsSelector.js";
14
16
  import { gridPinnedRowsSelector, gridRowCountSelector } from "../features/rows/gridRowsSelector.js";
@@ -31,6 +33,18 @@ const columnsTotalWidthSelector = createSelector(gridVisibleColumnDefinitionsSel
31
33
  return roundToDecimalPlaces(positions[colCount - 1] + visibleColumns[colCount - 1].computedWidth, 1);
32
34
  });
33
35
 
36
+ /** Translates virtualizer state to grid state */
37
+ const addGridDimensionsCreator = () => lruMemoize((dimensions, headerHeight, groupHeaderHeight, headerFilterHeight, headersTotalHeight) => {
38
+ return _extends({}, dimensions, {
39
+ headerHeight,
40
+ groupHeaderHeight,
41
+ headerFilterHeight,
42
+ headersTotalHeight
43
+ });
44
+ }, {
45
+ maxSize: 1
46
+ });
47
+
34
48
  /**
35
49
  * Virtualizer setup
36
50
  */
@@ -46,9 +60,6 @@ export function useGridVirtualizer(apiRef, rootProps) {
46
60
  const isRowSelected = id => rowSelectionManager.has(id) && apiRef.current.isRowSelectable(id);
47
61
  const currentPage = useGridVisibleRows(apiRef);
48
62
  const hasColSpan = useGridSelector(apiRef, gridHasColSpanSelector);
49
-
50
- /* TODO: extract dimensions code */
51
- const contentHeight = useGridSelector(apiRef, gridContentHeightSelector);
52
63
  const verticalScrollbarWidth = useGridSelector(apiRef, gridVerticalScrollbarWidthSelector);
53
64
  const hasFiller = useGridSelector(apiRef, gridHasFillerSelector);
54
65
  const {
@@ -67,16 +78,17 @@ export function useGridVirtualizer(apiRef, rootProps) {
67
78
  const headersTotalHeight = getTotalHeaderHeight(apiRef, rootProps);
68
79
  const leftPinnedWidth = pinnedColumns.left.reduce((w, col) => w + col.computedWidth, 0);
69
80
  const rightPinnedWidth = pinnedColumns.right.reduce((w, col) => w + col.computedWidth, 0);
70
- const dimensions = {
81
+ const dimensionsParams = {
71
82
  rowHeight,
72
83
  headerHeight,
73
- groupHeaderHeight,
74
- headerFilterHeight,
75
84
  columnsTotalWidth,
76
- headersTotalHeight,
77
85
  leftPinnedWidth,
78
- rightPinnedWidth
86
+ rightPinnedWidth,
87
+ topPinnedHeight: headersTotalHeight,
88
+ bottomPinnedHeight: 0,
89
+ scrollbarSize: rootProps.scrollbarSize
79
90
  };
91
+ const addGridDimensions = useLazyRef(addGridDimensionsCreator).current;
80
92
 
81
93
  // </DIMENSIONS>
82
94
 
@@ -93,32 +105,42 @@ export function useGridVirtualizer(apiRef, rootProps) {
93
105
 
94
106
  const focusedVirtualCell = useGridSelector(apiRef, gridFocusedVirtualCellSelector);
95
107
  const virtualizer = useVirtualizer({
96
- scrollbarSize: rootProps.scrollbarSize,
97
- dimensions,
108
+ refs: {
109
+ container: apiRef.current.mainElementRef,
110
+ scroller: apiRef.current.virtualScrollerRef,
111
+ scrollbarVertical: apiRef.current.virtualScrollbarVerticalRef,
112
+ scrollbarHorizontal: apiRef.current.virtualScrollbarHorizontalRef
113
+ },
114
+ dimensions: dimensionsParams,
115
+ virtualization: {
116
+ isRtl,
117
+ rowBufferPx: rootProps.rowBufferPx,
118
+ columnBufferPx: rootProps.columnBufferPx
119
+ },
120
+ colspan: {
121
+ enabled: hasColSpan,
122
+ getColspan: (rowId, column) => {
123
+ if (typeof column.colSpan === 'function') {
124
+ const row = apiRef.current.getRow(rowId);
125
+ const value = apiRef.current.getRowValue(row, column);
126
+ return column.colSpan(value, row, column, apiRef) ?? 0;
127
+ }
128
+ return column.colSpan ?? 1;
129
+ }
130
+ },
98
131
  initialState: {
99
132
  scroll: rootProps.initialState?.scroll,
100
- dimensions: apiRef.current.state.dimensions,
101
133
  rowSpanning: apiRef.current.state.rowSpanning,
102
134
  virtualization: apiRef.current.state.virtualization
103
135
  },
104
- isRtl,
105
136
  rows: currentPage.rows,
106
137
  range: currentPage.range,
107
- rowIdToIndexMap: currentPage.rowIdToIndexMap,
108
138
  rowCount,
109
139
  columns: visibleColumns,
110
140
  pinnedRows,
111
141
  pinnedColumns,
112
- refs: {
113
- container: apiRef.current.mainElementRef,
114
- scroller: apiRef.current.virtualScrollerRef,
115
- scrollbarVertical: apiRef.current.virtualScrollbarVerticalRef,
116
- scrollbarHorizontal: apiRef.current.virtualScrollbarHorizontalRef
117
- },
118
- hasColSpan,
119
- contentHeight,
120
- minimalContentHeight,
121
142
  autoHeight,
143
+ minimalContentHeight,
122
144
  getRowHeight: React.useMemo(() => {
123
145
  if (!getRowHeight) {
124
146
  return undefined;
@@ -130,14 +152,20 @@ export function useGridVirtualizer(apiRef, rootProps) {
130
152
  getEstimatedRowHeight: React.useMemo(() => getEstimatedRowHeight ? rowEntry => getEstimatedRowHeight(_extends({}, rowEntry, {
131
153
  densityFactor: density
132
154
  })) : undefined, [getEstimatedRowHeight, density]),
133
- getRowSpacing: React.useMemo(() => getRowSpacing ? (rowEntry, visibility) => getRowSpacing(_extends({}, rowEntry, visibility, {
134
- indexRelativeToCurrentPage: apiRef.current.getRowIndexRelativeToVisibleRows(rowEntry.id)
135
- })) : undefined, [apiRef, getRowSpacing]),
155
+ getRowSpacing: React.useMemo(() => getRowSpacing ? rowEntry => {
156
+ const indexRelativeToCurrentPage = currentPage.rowIdToIndexMap.get(rowEntry.id) ?? -1;
157
+ const visibility = {
158
+ isFirstVisible: indexRelativeToCurrentPage === 0,
159
+ isLastVisible: indexRelativeToCurrentPage === currentPage.rows.length - 1,
160
+ indexRelativeToCurrentPage
161
+ };
162
+ return getRowSpacing(_extends({}, rowEntry, visibility, {
163
+ indexRelativeToCurrentPage: apiRef.current.getRowIndexRelativeToVisibleRows(rowEntry.id)
164
+ }));
165
+ } : undefined, [apiRef, getRowSpacing, currentPage.rows, currentPage.rowIdToIndexMap]),
136
166
  applyRowHeight: useEventCallback((entry, row) => apiRef.current.unstable_applyPipeProcessors('rowHeight', entry, row)),
137
167
  virtualizeColumnsWithAutoRowHeight: rootProps.virtualizeColumnsWithAutoRowHeight,
138
168
  focusedVirtualCell: useEventCallback(() => focusedVirtualCell),
139
- rowBufferPx: rootProps.rowBufferPx,
140
- columnBufferPx: rootProps.columnBufferPx,
141
169
  resizeThrottleMs: rootProps.resizeThrottleMs,
142
170
  onResize: useEventCallback(size => apiRef.current.publishEvent('resize', size)),
143
171
  onWheel: useEventCallback(event => {
@@ -157,14 +185,6 @@ export function useGridVirtualizer(apiRef, rootProps) {
157
185
  });
158
186
  },
159
187
  scrollReset,
160
- getColspan: (rowId, column) => {
161
- if (typeof column.colSpan === 'function') {
162
- const row = apiRef.current.getRow(rowId);
163
- const value = apiRef.current.getRowValue(row, column);
164
- return column.colSpan(value, row, column, apiRef) ?? 0;
165
- }
166
- return column.colSpan ?? 0;
167
- },
168
188
  renderRow: params => /*#__PURE__*/_jsx(rootProps.slots.row, _extends({
169
189
  row: params.model,
170
190
  rowId: params.id,
@@ -174,7 +194,7 @@ export function useGridVirtualizer(apiRef, rootProps) {
174
194
  columnsTotalWidth: columnsTotalWidth,
175
195
  rowHeight: params.baseRowHeight,
176
196
  pinnedColumns: pinnedColumns,
177
- visibleColumns: params.columns,
197
+ visibleColumns: visibleColumns,
178
198
  firstColumnIndex: params.firstColumnIndex,
179
199
  lastColumnIndex: params.lastColumnIndex,
180
200
  focusedColumnIndex: params.focusedColumnIndex,
@@ -196,16 +216,16 @@ export function useGridVirtualizer(apiRef, rootProps) {
196
216
  //
197
217
  // TODO(v9): Remove this
198
218
  useFirstRender(() => {
199
- apiRef.current.store.state.dimensions = virtualizer.store.state.dimensions;
219
+ apiRef.current.store.state.dimensions = addGridDimensions(virtualizer.store.state.dimensions, headerHeight, groupHeaderHeight, headerFilterHeight, headersTotalHeight);
200
220
  apiRef.current.store.state.rowsMeta = virtualizer.store.state.rowsMeta;
201
221
  apiRef.current.store.state.virtualization = virtualizer.store.state.virtualization;
202
222
  });
223
+ useStoreEffect(virtualizer.store, Dimensions.selectors.dimensions, (_, dimensions) => {
224
+ apiRef.current.setState(gridState => _extends({}, gridState, {
225
+ dimensions: addGridDimensions(dimensions, headerHeight, groupHeaderHeight, headerFilterHeight, headersTotalHeight)
226
+ }));
227
+ });
203
228
  useStoreEffect(virtualizer.store, identity, (_, state) => {
204
- if (state.dimensions !== apiRef.current.state.dimensions) {
205
- apiRef.current.setState(gridState => _extends({}, gridState, {
206
- dimensions: state.dimensions
207
- }));
208
- }
209
229
  if (state.rowsMeta !== apiRef.current.state.rowsMeta) {
210
230
  apiRef.current.setState(gridState => _extends({}, gridState, {
211
231
  rowsMeta: state.rowsMeta
@@ -6,9 +6,6 @@ export class GridDataSourceCacheDefault {
6
6
  ttl = 300_000,
7
7
  getKey = getKeyDefault
8
8
  }) {
9
- this.cache = void 0;
10
- this.ttl = void 0;
11
- this.getKey = void 0;
12
9
  this.cache = {};
13
10
  this.ttl = ttl;
14
11
  this.getKey = getKey;
@@ -1,30 +1,30 @@
1
1
  export class GridGetRowsError extends Error {
2
+ /**
3
+ * The parameters used in the failed request
4
+ */
5
+
6
+ /**
7
+ * The original error that caused this error
8
+ */
9
+
2
10
  constructor(options) {
3
11
  super(options.message);
4
- /**
5
- * The parameters used in the failed request
6
- */
7
- this.params = void 0;
8
- /**
9
- * The original error that caused this error
10
- */
11
- this.cause = void 0;
12
12
  this.name = 'GridGetRowsError';
13
13
  this.params = options.params;
14
14
  this.cause = options.cause;
15
15
  }
16
16
  }
17
17
  export class GridUpdateRowError extends Error {
18
+ /**
19
+ * The parameters used in the failed request
20
+ */
21
+
22
+ /**
23
+ * The original error that caused this error
24
+ */
25
+
18
26
  constructor(options) {
19
27
  super(options.message);
20
- /**
21
- * The parameters used in the failed request
22
- */
23
- this.params = void 0;
24
- /**
25
- * The original error that caused this error
26
- */
27
- this.cause = void 0;
28
28
  this.name = 'GridUpdateRowError';
29
29
  this.params = options.params;
30
30
  this.cause = options.cause;
@@ -1,15 +1,24 @@
1
1
  import type { GridDataSourceCache, GridGetRowsParams, GridUpdateRowParams } from "../../../models/gridDataSource.js";
2
2
  import type { GridRowId, GridRowModel } from "../../../models/gridRows.js";
3
3
  import type { GridDataSourceCacheDefaultConfig } from "./cache.js";
4
+ /**
5
+ * The parameters for the `fetchRows` method.
6
+ */
7
+ export interface GridDataSourceFetchRowsParams extends Partial<GridGetRowsParams> {
8
+ /**
9
+ * If `true`, bypasses the cache and forces a refetch of the rows from the server.
10
+ */
11
+ skipCache?: boolean;
12
+ }
4
13
  export interface GridDataSourceApiBase {
5
14
  /**
6
15
  * Fetches the rows from the server.
7
16
  * If no `parentId` option is provided, it fetches the root rows.
8
17
  * Any missing parameter from `params` will be filled from the state (sorting, filtering, etc.).
9
18
  * @param {GridRowId} parentId The id of the parent node (default: `GRID_ROOT_GROUP_ID`).
10
- * @param {Partial<GridGetRowsParams>} params Request parameters override.
19
+ * @param {GridDataSourceFetchRowsParams} params Request parameters override.
11
20
  */
12
- fetchRows: (parentId?: GridRowId, params?: Partial<GridGetRowsParams>) => void;
21
+ fetchRows: (parentId?: GridRowId, params?: GridDataSourceFetchRowsParams) => void;
13
22
  /**
14
23
  * The data source cache object.
15
24
  */
@@ -10,7 +10,7 @@ export declare const useGridDataSourceBase: <Api extends GridPrivateApiCommunity
10
10
  api: {
11
11
  public: GridDataSourceApi;
12
12
  };
13
- debouncedFetchRows: ((parentId?: import("@mui/x-data-grid").GridRowId, params?: Partial<import("@mui/x-data-grid").GridGetRowsParams>) => void) & import("@mui/utils/debounce").Cancelable;
13
+ debouncedFetchRows: ((parentId?: import("@mui/x-data-grid").GridRowId, params?: import("./models.js").GridDataSourceFetchRowsParams) => void) & import("@mui/utils/debounce").Cancelable;
14
14
  strategyProcessor: {
15
15
  strategyName: DataSourceRowsUpdateStrategy;
16
16
  group: "dataSourceRowsUpdate";
@@ -1,6 +1,8 @@
1
1
  'use client';
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
+ const _excluded = ["skipCache"];
4
6
  import * as React from 'react';
5
7
  import useLazyRef from '@mui/utils/useLazyRef';
6
8
  import debounce from '@mui/utils/debounce';
@@ -53,10 +55,15 @@ export const useGridDataSourceBase = (apiRef, props, options = {}) => {
53
55
  return;
54
56
  }
55
57
  options.clearDataSourceState?.();
56
- const fetchParams = _extends({}, gridGetRowsParamsSelector(apiRef), apiRef.current.unstable_applyPipeProcessors('getRowsParams', {}), params);
58
+ const _ref = params || {},
59
+ {
60
+ skipCache
61
+ } = _ref,
62
+ getRowsParams = _objectWithoutPropertiesLoose(_ref, _excluded);
63
+ const fetchParams = _extends({}, gridGetRowsParamsSelector(apiRef), apiRef.current.unstable_applyPipeProcessors('getRowsParams', {}), getRowsParams);
57
64
  const cacheKeys = cacheChunkManager.getCacheKeys(fetchParams);
58
65
  const responses = cacheKeys.map(cacheKey => cache.get(cacheKey));
59
- if (responses.every(response => response !== undefined)) {
66
+ if (!skipCache && responses.every(response => response !== undefined)) {
60
67
  apiRef.current.applyStrategyProcessor('dataSourceRowsUpdate', {
61
68
  response: CacheChunkManager.mergeResponses(responses),
62
69
  fetchParams
@@ -18,57 +18,56 @@ export class CacheChunkManager {
18
18
  * Has no effect if cursor pagination is used.
19
19
  */
20
20
  constructor(chunkSize) {
21
- this.chunkSize = void 0;
22
- this.getCacheKeys = key => {
23
- if (this.chunkSize < 1 || typeof key.start !== 'number') {
24
- return [key];
25
- }
26
-
27
- // split the range into chunks
28
- const chunkedKeys = [];
29
- for (let i = key.start; i <= key.end; i += this.chunkSize) {
30
- const end = Math.min(i + this.chunkSize - 1, key.end);
31
- chunkedKeys.push(_extends({}, key, {
32
- start: i,
33
- end
34
- }));
35
- }
36
- return chunkedKeys;
37
- };
38
- this.splitResponse = (key, response) => {
39
- const cacheKeys = this.getCacheKeys(key);
40
- if (cacheKeys.length === 1) {
41
- return new Map([[key, response]]);
42
- }
43
- const responses = new Map();
44
- cacheKeys.forEach(chunkKey => {
45
- const isLastChunk = chunkKey.end === key.end;
46
- const responseSlice = _extends({}, response, {
47
- pageInfo: _extends({}, response.pageInfo, {
48
- // If the original response had page info, update that information for all but last chunk and keep the original value for the last chunk
49
- hasNextPage: response.pageInfo?.hasNextPage !== undefined && !isLastChunk ? true : response.pageInfo?.hasNextPage,
50
- nextCursor: response.pageInfo?.nextCursor !== undefined && !isLastChunk ? response.rows[chunkKey.end + 1].id : response.pageInfo?.nextCursor
51
- }),
52
- rows: typeof chunkKey.start !== 'number' || typeof key.start !== 'number' ? response.rows : response.rows.slice(chunkKey.start - key.start, chunkKey.end - key.start + 1)
53
- });
54
- responses.set(chunkKey, responseSlice);
55
- });
56
- return responses;
57
- };
58
21
  this.chunkSize = chunkSize;
59
22
  }
60
- }
61
- CacheChunkManager.mergeResponses = responses => {
62
- if (responses.length === 1) {
63
- return responses[0];
64
- }
65
- return responses.reduce((acc, response) => ({
66
- rows: [...acc.rows, ...response.rows],
67
- rowCount: response.rowCount,
68
- pageInfo: response.pageInfo
69
- }), {
70
- rows: [],
71
- rowCount: 0,
72
- pageInfo: {}
73
- });
74
- };
23
+ getCacheKeys = key => {
24
+ if (this.chunkSize < 1 || typeof key.start !== 'number') {
25
+ return [key];
26
+ }
27
+
28
+ // split the range into chunks
29
+ const chunkedKeys = [];
30
+ for (let i = key.start; i <= key.end; i += this.chunkSize) {
31
+ const end = Math.min(i + this.chunkSize - 1, key.end);
32
+ chunkedKeys.push(_extends({}, key, {
33
+ start: i,
34
+ end
35
+ }));
36
+ }
37
+ return chunkedKeys;
38
+ };
39
+ splitResponse = (key, response) => {
40
+ const cacheKeys = this.getCacheKeys(key);
41
+ if (cacheKeys.length === 1) {
42
+ return new Map([[key, response]]);
43
+ }
44
+ const responses = new Map();
45
+ cacheKeys.forEach(chunkKey => {
46
+ const isLastChunk = chunkKey.end === key.end;
47
+ const responseSlice = _extends({}, response, {
48
+ pageInfo: _extends({}, response.pageInfo, {
49
+ // If the original response had page info, update that information for all but last chunk and keep the original value for the last chunk
50
+ hasNextPage: response.pageInfo?.hasNextPage !== undefined && !isLastChunk ? true : response.pageInfo?.hasNextPage,
51
+ nextCursor: response.pageInfo?.nextCursor !== undefined && !isLastChunk ? response.rows[chunkKey.end + 1].id : response.pageInfo?.nextCursor
52
+ }),
53
+ rows: typeof chunkKey.start !== 'number' || typeof key.start !== 'number' ? response.rows : response.rows.slice(chunkKey.start - key.start, chunkKey.end - key.start + 1)
54
+ });
55
+ responses.set(chunkKey, responseSlice);
56
+ });
57
+ return responses;
58
+ };
59
+ static mergeResponses = responses => {
60
+ if (responses.length === 1) {
61
+ return responses[0];
62
+ }
63
+ return responses.reduce((acc, response) => ({
64
+ rows: [...acc.rows, ...response.rows],
65
+ rowCount: response.rowCount,
66
+ pageInfo: response.pageInfo
67
+ }), {
68
+ rows: [],
69
+ rowCount: 0,
70
+ pageInfo: {}
71
+ });
72
+ };
73
+ }
@@ -1,62 +1,5 @@
1
- import type { ElementSize } from "../../../models/elementSize.js";
2
- export interface GridDimensions {
3
- /**
4
- * Indicates that the dimensions have been initialized.
5
- */
6
- isReady: boolean;
7
- /**
8
- * The root container size.
9
- */
10
- root: ElementSize;
11
- /**
12
- * The viewport size including scrollbars.
13
- */
14
- viewportOuterSize: ElementSize;
15
- /**
16
- * The viewport size not including scrollbars.
17
- */
18
- viewportInnerSize: ElementSize;
19
- /**
20
- * The size of the main content (unpinned rows & columns).
21
- */
22
- contentSize: ElementSize;
23
- /**
24
- * The minimum size to display the grid, including all pinned sections and headers.
25
- */
26
- minimumSize: ElementSize;
27
- /**
28
- * Indicates if a scroll is currently needed to go from the beginning of the first column to the end of the last column.
29
- */
30
- hasScrollX: boolean;
31
- /**
32
- * Indicates if a scroll is currently needed to go from the beginning of the first row to the end of the last row.
33
- */
34
- hasScrollY: boolean;
35
- /**
36
- * Size of the scrollbar used to scroll the rows in pixel.
37
- * It is defined even when the scrollbar is currently not needed.
38
- */
39
- scrollbarSize: number;
40
- /**
41
- * Width of a row.
42
- */
43
- rowWidth: number;
44
- /**
45
- * Height of a row.
46
- */
47
- rowHeight: number;
48
- /**
49
- * Size of all the visible columns.
50
- */
51
- columnsTotalWidth: number;
52
- /**
53
- * Size of left pinned columns.
54
- */
55
- leftPinnedWidth: number;
56
- /**
57
- * Size of right pinned columns.
58
- */
59
- rightPinnedWidth: number;
1
+ import type { DimensionsState } from '@mui/x-virtualizer/models';
2
+ export interface GridDimensions extends DimensionsState {
60
3
  /**
61
4
  * Height of one column header.
62
5
  */
@@ -73,14 +16,6 @@ export interface GridDimensions {
73
16
  * Height of all the column headers.
74
17
  */
75
18
  headersTotalHeight: number;
76
- /**
77
- * Size of the top container.
78
- */
79
- topContainerHeight: number;
80
- /**
81
- * Size of the bottom container.
82
- */
83
- bottomContainerHeight: number;
84
19
  }
85
20
  export interface GridDimensionsApi {
86
21
  /**
@@ -3,7 +3,6 @@
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import * as React from 'react';
5
5
  import { useStoreEffect } from '@mui/x-internals/store';
6
- import { Dimensions } from '@mui/x-virtualizer';
7
6
  import { useGridEventPriority } from "../../utils/useGridEvent.js";
8
7
  import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
9
8
  import { createSelector } from "../../../utils/createSelector.js";
@@ -57,8 +56,6 @@ const columnsTotalWidthSelector = createSelector(gridVisibleColumnDefinitionsSel
57
56
  return roundToDecimalPlaces(positions[colCount - 1] + visibleColumns[colCount - 1].computedWidth, 1);
58
57
  });
59
58
  export function useGridDimensions(apiRef, props) {
60
- const logger = useGridLogger(apiRef, 'useResizeContainer');
61
- const errorShown = React.useRef(false);
62
59
  const virtualizer = apiRef.current.virtualizer;
63
60
  const updateDimensions = virtualizer.api.updateDimensions;
64
61
  const getViewportPageSize = virtualizer.api.getViewportPageSize;
@@ -75,20 +72,28 @@ export function useGridDimensions(apiRef, props) {
75
72
  const handleRootMount = root => {
76
73
  setCSSVariables(root, gridDimensionsSelector(apiRef));
77
74
  };
78
- const handleResize = size => {
79
- if (size.height === 0 && !errorShown.current && !props.autoHeight && !isJSDOM) {
80
- logger.error(['The parent DOM element of the Data Grid has an empty height.', 'Please make sure that this element has an intrinsic height.', 'The grid displays with a height of 0px.', '', 'More details: https://mui.com/r/x-data-grid-no-dimensions.'].join('\n'));
81
- errorShown.current = true;
82
- }
83
- if (size.width === 0 && !errorShown.current && !isJSDOM) {
84
- logger.error(['The parent DOM element of the Data Grid has an empty width.', 'Please make sure that this element has an intrinsic width.', 'The grid displays with a width of 0px.', '', 'More details: https://mui.com/r/x-data-grid-no-dimensions.'].join('\n'));
85
- errorShown.current = true;
86
- }
87
- };
88
75
  useGridEventPriority(apiRef, 'rootMount', handleRootMount);
89
- useGridEventPriority(apiRef, 'resize', handleResize);
90
76
  useGridEventPriority(apiRef, 'debouncedResize', props.onResize);
91
- useStoreEffect(virtualizer.store, Dimensions.selectors.dimensions, (previous, next) => {
77
+ if (process.env.NODE_ENV !== 'production') {
78
+ /* eslint-disable react-hooks/rules-of-hooks */
79
+ const logger = useGridLogger(apiRef, 'useResizeContainer');
80
+ const errorShown = React.useRef(false);
81
+ useGridEventPriority(apiRef, 'resize', size => {
82
+ if (!getRootDimensions().isReady) {
83
+ return;
84
+ }
85
+ if (size.height === 0 && !errorShown.current && !props.autoHeight && !isJSDOM) {
86
+ logger.error(['The parent DOM element of the Data Grid has an empty height.', 'Please make sure that this element has an intrinsic height.', 'The grid displays with a height of 0px.', '', 'More details: https://mui.com/r/x-data-grid-no-dimensions.'].join('\n'));
87
+ errorShown.current = true;
88
+ }
89
+ if (size.width === 0 && !errorShown.current && !isJSDOM) {
90
+ logger.error(['The parent DOM element of the Data Grid has an empty width.', 'Please make sure that this element has an intrinsic width.', 'The grid displays with a width of 0px.', '', 'More details: https://mui.com/r/x-data-grid-no-dimensions.'].join('\n'));
91
+ errorShown.current = true;
92
+ }
93
+ });
94
+ /* eslint-enable react-hooks/rules-of-hooks */
95
+ }
96
+ useStoreEffect(apiRef.current.store, s => s.dimensions, (previous, next) => {
92
97
  if (apiRef.current.rootElementRef.current) {
93
98
  setCSSVariables(apiRef.current.rootElementRef.current, next);
94
99
  }
@@ -343,7 +343,10 @@ export const useGridRowEditing = (apiRef, props) => {
343
343
  if (fieldToFocus) {
344
344
  apiRef.current.setCellFocus(id, fieldToFocus);
345
345
  }
346
- columns.filter(column => column.editable && !!column.preProcessEditCellProps && deleteValue).forEach(column => {
346
+ columns.filter(column => {
347
+ const isCellEditable = apiRef.current.getCellParams(id, column.field).isEditable;
348
+ return isCellEditable && column.editable && !!column.preProcessEditCellProps && deleteValue;
349
+ }).forEach(column => {
347
350
  const field = column.field;
348
351
  const value = apiRef.current.getCellValue(id, field);
349
352
  const newValue = deleteValue ? getDefaultCellValue(column) : initialValue ?? value;
@@ -44,10 +44,9 @@ export const serializeCellValue = (cellParams, options) => {
44
44
  return sanitizeCellValue(value, csvOptions);
45
45
  };
46
46
  class CSVRow {
47
+ rowString = '';
48
+ isEmpty = true;
47
49
  constructor(options) {
48
- this.options = void 0;
49
- this.rowString = '';
50
- this.isEmpty = true;
51
50
  this.options = options;
52
51
  }
53
52
  addValue(value) {
@@ -107,11 +107,11 @@ export const useGridPrintExport = (apiRef, props) => {
107
107
 
108
108
  // See https://support.google.com/chrome/thread/191619088?hl=en&msgid=193009642
109
109
  gridClone.style.contain = 'size';
110
- let gridToolbarElementHeight = gridRootElement.querySelector(`.${gridClasses.toolbarContainer}`)?.offsetHeight || 0;
110
+ let gridToolbarElementHeight = gridRootElement.querySelector(`.${gridClasses.toolbar}`)?.offsetHeight || 0;
111
111
  let gridFooterElementHeight = gridRootElement.querySelector(`.${gridClasses.footerContainer}`)?.offsetHeight || 0;
112
112
  const gridFooterElement = gridClone.querySelector(`.${gridClasses.footerContainer}`);
113
113
  if (normalizeOptions.hideToolbar) {
114
- gridClone.querySelector(`.${gridClasses.toolbarContainer}`)?.remove();
114
+ gridClone.querySelector(`.${gridClasses.toolbar}`)?.remove();
115
115
  gridToolbarElementHeight = 0;
116
116
  }
117
117
  if (normalizeOptions.hideFooter && gridFooterElement) {
@@ -209,12 +209,7 @@ export const useGridPrintExport = (apiRef, props) => {
209
209
  }));
210
210
  }
211
211
  previousVirtualizationState.current = apiRef.current.state.virtualization;
212
- apiRef.current.setState(state => _extends({}, state, {
213
- virtualization: _extends({}, state.virtualization, {
214
- enabled: false,
215
- enabledForColumns: false
216
- })
217
- }));
212
+ apiRef.current.unstable_setVirtualization(false);
218
213
  await updateGridColumnsForPrint(options?.fields, options?.allColumns, options?.includeCheckboxes);
219
214
  updateGridRowsForPrint(options?.getRowsToExport ?? defaultGetRowsToExport);
220
215
  await raf(); // wait for the state changes to take action
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The row reorder state.
3
+ */
4
+ export interface GridRowReorderState {
5
+ /**
6
+ * Whether a row drag operation is currently active.
7
+ */
8
+ isActive: boolean;
9
+ }
@@ -0,0 +1,5 @@
1
+ import { GridStateCommunity } from "../../../models/gridStateCommunity.js";
2
+ export declare const gridRowReorderStateSelector: import("@mui/x-data-grid").OutputSelector<GridStateCommunity, unknown, import("./gridRowReorderInterfaces.js").GridRowReorderState>;
3
+ export declare const gridIsRowDragActiveSelector: (args_0: import("react").RefObject<{
4
+ state: GridStateCommunity;
5
+ } | null>) => boolean;
@@ -0,0 +1,3 @@
1
+ import { createRootSelector, createSelector } from "../../../utils/createSelector.js";
2
+ export const gridRowReorderStateSelector = createRootSelector(state => state.rowReorder);
3
+ export const gridIsRowDragActiveSelector = createSelector(gridRowReorderStateSelector, rowReorder => rowReorder?.isActive ?? false);