@mui/x-data-grid 8.10.0 → 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 (35) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/components/GridRow.js +5 -5
  3. package/components/virtualization/GridVirtualScroller.js +3 -3
  4. package/esm/DataGrid/index.js +1 -1
  5. package/esm/components/GridRow.js +5 -5
  6. package/esm/components/virtualization/GridVirtualScroller.js +3 -3
  7. package/esm/hooks/core/useGridVirtualizer.js +64 -44
  8. package/esm/hooks/features/dataSource/cache.js +0 -3
  9. package/esm/hooks/features/dataSource/gridDataSourceError.js +16 -16
  10. package/esm/hooks/features/dataSource/utils.js +51 -52
  11. package/esm/hooks/features/dimensions/gridDimensionsApi.d.ts +2 -67
  12. package/esm/hooks/features/dimensions/useGridDimensions.js +20 -15
  13. package/esm/hooks/features/export/serializers/csvSerializer.js +2 -3
  14. package/esm/hooks/features/export/useGridPrintExport.js +3 -8
  15. package/esm/index.js +1 -1
  16. package/esm/internals/utils/cache.js +0 -1
  17. package/esm/models/api/gridApiCommon.d.ts +1 -1
  18. package/esm/models/gridRowSelectionManager.js +0 -2
  19. package/esm/utils/cleanupTracking/FinalizationRegistryBasedCleanupTracking.js +5 -7
  20. package/esm/utils/cleanupTracking/TimerBasedCleanupTracking.js +2 -2
  21. package/hooks/core/useGridVirtualizer.js +62 -42
  22. package/hooks/features/dataSource/cache.js +0 -3
  23. package/hooks/features/dataSource/gridDataSourceError.js +16 -16
  24. package/hooks/features/dataSource/utils.js +51 -52
  25. package/hooks/features/dimensions/gridDimensionsApi.d.ts +2 -67
  26. package/hooks/features/dimensions/useGridDimensions.js +20 -15
  27. package/hooks/features/export/serializers/csvSerializer.js +2 -3
  28. package/hooks/features/export/useGridPrintExport.js +3 -8
  29. package/index.js +1 -1
  30. package/internals/utils/cache.js +0 -1
  31. package/models/api/gridApiCommon.d.ts +1 -1
  32. package/models/gridRowSelectionManager.js +0 -2
  33. package/package.json +15 -16
  34. package/utils/cleanupTracking/FinalizationRegistryBasedCleanupTracking.js +5 -7
  35. package/utils/cleanupTracking/TimerBasedCleanupTracking.js +2 -2
@@ -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
  }
@@ -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
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v8.10.0
2
+ * @mui/x-data-grid v8.10.1
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,7 +1,6 @@
1
1
  import { getKeyDefault } from "../../hooks/features/dataSource/cache.js";
2
2
  export class TestCache {
3
3
  constructor() {
4
- this.cache = void 0;
5
4
  this.cache = new Map();
6
5
  }
7
6
  set(key, value) {
@@ -31,7 +31,7 @@ import type { GridHeaderFilteringApi, GridHeaderFilteringPrivateApi } from "./gr
31
31
  import type { DataGridProcessedProps } from "../props/DataGridProps.js";
32
32
  import type { GridColumnResizeApi } from "../../hooks/features/columnResize/index.js";
33
33
  import type { GridPivotingPrivateApiCommunity } from "../../hooks/features/pivoting/gridPivotingInterfaces.js";
34
- export interface GridApiCommon<GridState extends GridStateCommunity = any, GridInitialState extends GridInitialStateCommunity = any> extends GridCoreApi, GridPipeProcessingApi, GridDensityApi, GridDimensionsApi, GridRowApi, GridRowsMetaApi, GridEditingApi, GridParamsApi, GridColumnApi, GridRowSelectionApi, GridSortApi, GridPaginationApi, GridCsvExportApi, GridFocusApi, GridFilterApi, GridColumnMenuApi, GridPreferencesPanelApi, GridPrintExportApi, GridVirtualizationApi, GridLocaleTextApi, GridScrollApi, GridColumnSpanningApi, GridStateApi<GridState>, GridStatePersistenceApi<GridInitialState>, GridColumnGroupingApi, GridHeaderFilteringApi, GridColumnResizeApi {}
34
+ export interface GridApiCommon<GridState extends GridStateCommunity = GridStateCommunity, GridInitialState extends GridInitialStateCommunity = GridInitialStateCommunity> extends GridCoreApi, GridPipeProcessingApi, GridDensityApi, GridDimensionsApi, GridRowApi, GridRowsMetaApi, GridEditingApi, GridParamsApi, GridColumnApi, GridRowSelectionApi, GridSortApi, GridPaginationApi, GridCsvExportApi, GridFocusApi, GridFilterApi, GridColumnMenuApi, GridPreferencesPanelApi, GridPrintExportApi, GridVirtualizationApi, GridLocaleTextApi, GridScrollApi, GridColumnSpanningApi, GridStateApi<GridState>, GridStatePersistenceApi<GridInitialState>, GridColumnGroupingApi, GridHeaderFilteringApi, GridColumnResizeApi {}
35
35
  export interface GridPrivateOnlyApiCommon<Api extends GridApiCommon, PrivateApi extends GridPrivateApiCommon, Props extends DataGridProcessedProps> extends GridCorePrivateApi<Api, PrivateApi, Props>, GridStatePrivateApi<PrivateApi['state']>, GridPipeProcessingPrivateApi, GridStrategyProcessingApi, GridColumnSpanningPrivateApi, GridRowsMetaPrivateApi, GridDimensionsPrivateApi, GridEditingPrivateApi, GridLoggerApi, GridFocusPrivateApi, GridHeaderFilteringPrivateApi, GridVirtualizationPrivateApi, GridRowProPrivateApi, GridParamsPrivateApi, GridPivotingPrivateApiCommunity {
36
36
  virtualizer: Virtualizer;
37
37
  }
@@ -1,6 +1,5 @@
1
1
  class IncludeManager {
2
2
  constructor(model) {
3
- this.data = void 0;
4
3
  this.data = model.ids;
5
4
  }
6
5
  has(id) {
@@ -15,7 +14,6 @@ class IncludeManager {
15
14
  }
16
15
  class ExcludeManager {
17
16
  constructor(model) {
18
- this.data = void 0;
19
17
  this.data = model.ids;
20
18
  }
21
19
  has(id) {
@@ -1,11 +1,9 @@
1
1
  export class FinalizationRegistryBasedCleanupTracking {
2
- constructor() {
3
- this.registry = new FinalizationRegistry(unsubscribe => {
4
- if (typeof unsubscribe === 'function') {
5
- unsubscribe();
6
- }
7
- });
8
- }
2
+ registry = (() => new FinalizationRegistry(unsubscribe => {
3
+ if (typeof unsubscribe === 'function') {
4
+ unsubscribe();
5
+ }
6
+ }))();
9
7
  register(object, unsubscribe, unregisterToken) {
10
8
  this.registry.register(object, unsubscribe, unregisterToken);
11
9
  }
@@ -1,9 +1,9 @@
1
1
  // If no effect ran after this amount of time, we assume that the render was not committed by React
2
2
  const CLEANUP_TIMER_LOOP_MILLIS = 1000;
3
3
  export class TimerBasedCleanupTracking {
4
+ timeouts = (() => new Map())();
5
+ cleanupTimeout = (() => CLEANUP_TIMER_LOOP_MILLIS)();
4
6
  constructor(timeout = CLEANUP_TIMER_LOOP_MILLIS) {
5
- this.timeouts = new Map();
6
- this.cleanupTimeout = CLEANUP_TIMER_LOOP_MILLIS;
7
7
  this.cleanupTimeout = timeout;
8
8
  }
9
9
  register(object, unsubscribe, unregisterToken) {
@@ -8,9 +8,11 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.useGridVirtualizer = useGridVirtualizer;
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
10
  var React = _interopRequireWildcard(require("react"));
11
+ var _useLazyRef = _interopRequireDefault(require("@mui/utils/useLazyRef"));
11
12
  var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
12
13
  var _RtlProvider = require("@mui/system/RtlProvider");
13
14
  var _math = require("@mui/x-internals/math");
15
+ var _lruMemoize = require("@mui/x-internals/lruMemoize");
14
16
  var _store = require("@mui/x-internals/store");
15
17
  var _xVirtualizer = require("@mui/x-virtualizer");
16
18
  var _useFirstRender = require("../utils/useFirstRender");
@@ -39,6 +41,18 @@ const columnsTotalWidthSelector = (0, _createSelector.createSelector)(_gridColum
39
41
  return (0, _math.roundToDecimalPlaces)(positions[colCount - 1] + visibleColumns[colCount - 1].computedWidth, 1);
40
42
  });
41
43
 
44
+ /** Translates virtualizer state to grid state */
45
+ const addGridDimensionsCreator = () => (0, _lruMemoize.lruMemoize)((dimensions, headerHeight, groupHeaderHeight, headerFilterHeight, headersTotalHeight) => {
46
+ return (0, _extends2.default)({}, dimensions, {
47
+ headerHeight,
48
+ groupHeaderHeight,
49
+ headerFilterHeight,
50
+ headersTotalHeight
51
+ });
52
+ }, {
53
+ maxSize: 1
54
+ });
55
+
42
56
  /**
43
57
  * Virtualizer setup
44
58
  */
@@ -54,9 +68,6 @@ function useGridVirtualizer(apiRef, rootProps) {
54
68
  const isRowSelected = id => rowSelectionManager.has(id) && apiRef.current.isRowSelectable(id);
55
69
  const currentPage = (0, _useGridVisibleRows.useGridVisibleRows)(apiRef);
56
70
  const hasColSpan = (0, _useGridSelector.useGridSelector)(apiRef, _gridColumnsSelector.gridHasColSpanSelector);
57
-
58
- /* TODO: extract dimensions code */
59
- const contentHeight = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridContentHeightSelector);
60
71
  const verticalScrollbarWidth = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridVerticalScrollbarWidthSelector);
61
72
  const hasFiller = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridHasFillerSelector);
62
73
  const {
@@ -75,16 +86,17 @@ function useGridVirtualizer(apiRef, rootProps) {
75
86
  const headersTotalHeight = (0, _gridColumnsUtils.getTotalHeaderHeight)(apiRef, rootProps);
76
87
  const leftPinnedWidth = pinnedColumns.left.reduce((w, col) => w + col.computedWidth, 0);
77
88
  const rightPinnedWidth = pinnedColumns.right.reduce((w, col) => w + col.computedWidth, 0);
78
- const dimensions = {
89
+ const dimensionsParams = {
79
90
  rowHeight,
80
91
  headerHeight,
81
- groupHeaderHeight,
82
- headerFilterHeight,
83
92
  columnsTotalWidth,
84
- headersTotalHeight,
85
93
  leftPinnedWidth,
86
- rightPinnedWidth
94
+ rightPinnedWidth,
95
+ topPinnedHeight: headersTotalHeight,
96
+ bottomPinnedHeight: 0,
97
+ scrollbarSize: rootProps.scrollbarSize
87
98
  };
99
+ const addGridDimensions = (0, _useLazyRef.default)(addGridDimensionsCreator).current;
88
100
 
89
101
  // </DIMENSIONS>
90
102
 
@@ -101,32 +113,42 @@ function useGridVirtualizer(apiRef, rootProps) {
101
113
 
102
114
  const focusedVirtualCell = (0, _useGridSelector.useGridSelector)(apiRef, _gridFocusedVirtualCellSelector.gridFocusedVirtualCellSelector);
103
115
  const virtualizer = (0, _xVirtualizer.useVirtualizer)({
104
- scrollbarSize: rootProps.scrollbarSize,
105
- dimensions,
116
+ refs: {
117
+ container: apiRef.current.mainElementRef,
118
+ scroller: apiRef.current.virtualScrollerRef,
119
+ scrollbarVertical: apiRef.current.virtualScrollbarVerticalRef,
120
+ scrollbarHorizontal: apiRef.current.virtualScrollbarHorizontalRef
121
+ },
122
+ dimensions: dimensionsParams,
123
+ virtualization: {
124
+ isRtl,
125
+ rowBufferPx: rootProps.rowBufferPx,
126
+ columnBufferPx: rootProps.columnBufferPx
127
+ },
128
+ colspan: {
129
+ enabled: hasColSpan,
130
+ getColspan: (rowId, column) => {
131
+ if (typeof column.colSpan === 'function') {
132
+ const row = apiRef.current.getRow(rowId);
133
+ const value = apiRef.current.getRowValue(row, column);
134
+ return column.colSpan(value, row, column, apiRef) ?? 0;
135
+ }
136
+ return column.colSpan ?? 1;
137
+ }
138
+ },
106
139
  initialState: {
107
140
  scroll: rootProps.initialState?.scroll,
108
- dimensions: apiRef.current.state.dimensions,
109
141
  rowSpanning: apiRef.current.state.rowSpanning,
110
142
  virtualization: apiRef.current.state.virtualization
111
143
  },
112
- isRtl,
113
144
  rows: currentPage.rows,
114
145
  range: currentPage.range,
115
- rowIdToIndexMap: currentPage.rowIdToIndexMap,
116
146
  rowCount,
117
147
  columns: visibleColumns,
118
148
  pinnedRows,
119
149
  pinnedColumns,
120
- refs: {
121
- container: apiRef.current.mainElementRef,
122
- scroller: apiRef.current.virtualScrollerRef,
123
- scrollbarVertical: apiRef.current.virtualScrollbarVerticalRef,
124
- scrollbarHorizontal: apiRef.current.virtualScrollbarHorizontalRef
125
- },
126
- hasColSpan,
127
- contentHeight,
128
- minimalContentHeight: _gridRowsUtils.minimalContentHeight,
129
150
  autoHeight,
151
+ minimalContentHeight: _gridRowsUtils.minimalContentHeight,
130
152
  getRowHeight: React.useMemo(() => {
131
153
  if (!getRowHeight) {
132
154
  return undefined;
@@ -138,14 +160,20 @@ function useGridVirtualizer(apiRef, rootProps) {
138
160
  getEstimatedRowHeight: React.useMemo(() => getEstimatedRowHeight ? rowEntry => getEstimatedRowHeight((0, _extends2.default)({}, rowEntry, {
139
161
  densityFactor: density
140
162
  })) : undefined, [getEstimatedRowHeight, density]),
141
- getRowSpacing: React.useMemo(() => getRowSpacing ? (rowEntry, visibility) => getRowSpacing((0, _extends2.default)({}, rowEntry, visibility, {
142
- indexRelativeToCurrentPage: apiRef.current.getRowIndexRelativeToVisibleRows(rowEntry.id)
143
- })) : undefined, [apiRef, getRowSpacing]),
163
+ getRowSpacing: React.useMemo(() => getRowSpacing ? rowEntry => {
164
+ const indexRelativeToCurrentPage = currentPage.rowIdToIndexMap.get(rowEntry.id) ?? -1;
165
+ const visibility = {
166
+ isFirstVisible: indexRelativeToCurrentPage === 0,
167
+ isLastVisible: indexRelativeToCurrentPage === currentPage.rows.length - 1,
168
+ indexRelativeToCurrentPage
169
+ };
170
+ return getRowSpacing((0, _extends2.default)({}, rowEntry, visibility, {
171
+ indexRelativeToCurrentPage: apiRef.current.getRowIndexRelativeToVisibleRows(rowEntry.id)
172
+ }));
173
+ } : undefined, [apiRef, getRowSpacing, currentPage.rows, currentPage.rowIdToIndexMap]),
144
174
  applyRowHeight: (0, _useEventCallback.default)((entry, row) => apiRef.current.unstable_applyPipeProcessors('rowHeight', entry, row)),
145
175
  virtualizeColumnsWithAutoRowHeight: rootProps.virtualizeColumnsWithAutoRowHeight,
146
176
  focusedVirtualCell: (0, _useEventCallback.default)(() => focusedVirtualCell),
147
- rowBufferPx: rootProps.rowBufferPx,
148
- columnBufferPx: rootProps.columnBufferPx,
149
177
  resizeThrottleMs: rootProps.resizeThrottleMs,
150
178
  onResize: (0, _useEventCallback.default)(size => apiRef.current.publishEvent('resize', size)),
151
179
  onWheel: (0, _useEventCallback.default)(event => {
@@ -165,14 +193,6 @@ function useGridVirtualizer(apiRef, rootProps) {
165
193
  });
166
194
  },
167
195
  scrollReset,
168
- getColspan: (rowId, column) => {
169
- if (typeof column.colSpan === 'function') {
170
- const row = apiRef.current.getRow(rowId);
171
- const value = apiRef.current.getRowValue(row, column);
172
- return column.colSpan(value, row, column, apiRef) ?? 0;
173
- }
174
- return column.colSpan ?? 0;
175
- },
176
196
  renderRow: params => /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.row, (0, _extends2.default)({
177
197
  row: params.model,
178
198
  rowId: params.id,
@@ -182,7 +202,7 @@ function useGridVirtualizer(apiRef, rootProps) {
182
202
  columnsTotalWidth: columnsTotalWidth,
183
203
  rowHeight: params.baseRowHeight,
184
204
  pinnedColumns: pinnedColumns,
185
- visibleColumns: params.columns,
205
+ visibleColumns: visibleColumns,
186
206
  firstColumnIndex: params.firstColumnIndex,
187
207
  lastColumnIndex: params.lastColumnIndex,
188
208
  focusedColumnIndex: params.focusedColumnIndex,
@@ -204,16 +224,16 @@ function useGridVirtualizer(apiRef, rootProps) {
204
224
  //
205
225
  // TODO(v9): Remove this
206
226
  (0, _useFirstRender.useFirstRender)(() => {
207
- apiRef.current.store.state.dimensions = virtualizer.store.state.dimensions;
227
+ apiRef.current.store.state.dimensions = addGridDimensions(virtualizer.store.state.dimensions, headerHeight, groupHeaderHeight, headerFilterHeight, headersTotalHeight);
208
228
  apiRef.current.store.state.rowsMeta = virtualizer.store.state.rowsMeta;
209
229
  apiRef.current.store.state.virtualization = virtualizer.store.state.virtualization;
210
230
  });
231
+ (0, _store.useStoreEffect)(virtualizer.store, _xVirtualizer.Dimensions.selectors.dimensions, (_, dimensions) => {
232
+ apiRef.current.setState(gridState => (0, _extends2.default)({}, gridState, {
233
+ dimensions: addGridDimensions(dimensions, headerHeight, groupHeaderHeight, headerFilterHeight, headersTotalHeight)
234
+ }));
235
+ });
211
236
  (0, _store.useStoreEffect)(virtualizer.store, identity, (_, state) => {
212
- if (state.dimensions !== apiRef.current.state.dimensions) {
213
- apiRef.current.setState(gridState => (0, _extends2.default)({}, gridState, {
214
- dimensions: state.dimensions
215
- }));
216
- }
217
237
  if (state.rowsMeta !== apiRef.current.state.rowsMeta) {
218
238
  apiRef.current.setState(gridState => (0, _extends2.default)({}, gridState, {
219
239
  rowsMeta: state.rowsMeta
@@ -13,9 +13,6 @@ class GridDataSourceCacheDefault {
13
13
  ttl = 300_000,
14
14
  getKey = getKeyDefault
15
15
  }) {
16
- this.cache = void 0;
17
- this.ttl = void 0;
18
- this.getKey = void 0;
19
16
  this.cache = {};
20
17
  this.ttl = ttl;
21
18
  this.getKey = getKey;
@@ -5,16 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.GridUpdateRowError = exports.GridGetRowsError = void 0;
7
7
  class GridGetRowsError extends Error {
8
+ /**
9
+ * The parameters used in the failed request
10
+ */
11
+
12
+ /**
13
+ * The original error that caused this error
14
+ */
15
+
8
16
  constructor(options) {
9
17
  super(options.message);
10
- /**
11
- * The parameters used in the failed request
12
- */
13
- this.params = void 0;
14
- /**
15
- * The original error that caused this error
16
- */
17
- this.cause = void 0;
18
18
  this.name = 'GridGetRowsError';
19
19
  this.params = options.params;
20
20
  this.cause = options.cause;
@@ -22,16 +22,16 @@ class GridGetRowsError extends Error {
22
22
  }
23
23
  exports.GridGetRowsError = GridGetRowsError;
24
24
  class GridUpdateRowError extends Error {
25
+ /**
26
+ * The parameters used in the failed request
27
+ */
28
+
29
+ /**
30
+ * The original error that caused this error
31
+ */
32
+
25
33
  constructor(options) {
26
34
  super(options.message);
27
- /**
28
- * The parameters used in the failed request
29
- */
30
- this.params = void 0;
31
- /**
32
- * The original error that caused this error
33
- */
34
- this.cause = void 0;
35
35
  this.name = 'GridUpdateRowError';
36
36
  this.params = options.params;
37
37
  this.cause = options.cause;
@@ -24,58 +24,57 @@ class CacheChunkManager {
24
24
  * Has no effect if cursor pagination is used.
25
25
  */
26
26
  constructor(chunkSize) {
27
- this.chunkSize = void 0;
28
- this.getCacheKeys = key => {
29
- if (this.chunkSize < 1 || typeof key.start !== 'number') {
30
- return [key];
31
- }
32
-
33
- // split the range into chunks
34
- const chunkedKeys = [];
35
- for (let i = key.start; i <= key.end; i += this.chunkSize) {
36
- const end = Math.min(i + this.chunkSize - 1, key.end);
37
- chunkedKeys.push((0, _extends2.default)({}, key, {
38
- start: i,
39
- end
40
- }));
41
- }
42
- return chunkedKeys;
43
- };
44
- this.splitResponse = (key, response) => {
45
- const cacheKeys = this.getCacheKeys(key);
46
- if (cacheKeys.length === 1) {
47
- return new Map([[key, response]]);
48
- }
49
- const responses = new Map();
50
- cacheKeys.forEach(chunkKey => {
51
- const isLastChunk = chunkKey.end === key.end;
52
- const responseSlice = (0, _extends2.default)({}, response, {
53
- pageInfo: (0, _extends2.default)({}, response.pageInfo, {
54
- // If the original response had page info, update that information for all but last chunk and keep the original value for the last chunk
55
- hasNextPage: response.pageInfo?.hasNextPage !== undefined && !isLastChunk ? true : response.pageInfo?.hasNextPage,
56
- nextCursor: response.pageInfo?.nextCursor !== undefined && !isLastChunk ? response.rows[chunkKey.end + 1].id : response.pageInfo?.nextCursor
57
- }),
58
- rows: typeof chunkKey.start !== 'number' || typeof key.start !== 'number' ? response.rows : response.rows.slice(chunkKey.start - key.start, chunkKey.end - key.start + 1)
59
- });
60
- responses.set(chunkKey, responseSlice);
61
- });
62
- return responses;
63
- };
64
27
  this.chunkSize = chunkSize;
65
28
  }
29
+ getCacheKeys = key => {
30
+ if (this.chunkSize < 1 || typeof key.start !== 'number') {
31
+ return [key];
32
+ }
33
+
34
+ // split the range into chunks
35
+ const chunkedKeys = [];
36
+ for (let i = key.start; i <= key.end; i += this.chunkSize) {
37
+ const end = Math.min(i + this.chunkSize - 1, key.end);
38
+ chunkedKeys.push((0, _extends2.default)({}, key, {
39
+ start: i,
40
+ end
41
+ }));
42
+ }
43
+ return chunkedKeys;
44
+ };
45
+ splitResponse = (key, response) => {
46
+ const cacheKeys = this.getCacheKeys(key);
47
+ if (cacheKeys.length === 1) {
48
+ return new Map([[key, response]]);
49
+ }
50
+ const responses = new Map();
51
+ cacheKeys.forEach(chunkKey => {
52
+ const isLastChunk = chunkKey.end === key.end;
53
+ const responseSlice = (0, _extends2.default)({}, response, {
54
+ pageInfo: (0, _extends2.default)({}, response.pageInfo, {
55
+ // If the original response had page info, update that information for all but last chunk and keep the original value for the last chunk
56
+ hasNextPage: response.pageInfo?.hasNextPage !== undefined && !isLastChunk ? true : response.pageInfo?.hasNextPage,
57
+ nextCursor: response.pageInfo?.nextCursor !== undefined && !isLastChunk ? response.rows[chunkKey.end + 1].id : response.pageInfo?.nextCursor
58
+ }),
59
+ rows: typeof chunkKey.start !== 'number' || typeof key.start !== 'number' ? response.rows : response.rows.slice(chunkKey.start - key.start, chunkKey.end - key.start + 1)
60
+ });
61
+ responses.set(chunkKey, responseSlice);
62
+ });
63
+ return responses;
64
+ };
65
+ static mergeResponses = responses => {
66
+ if (responses.length === 1) {
67
+ return responses[0];
68
+ }
69
+ return responses.reduce((acc, response) => ({
70
+ rows: [...acc.rows, ...response.rows],
71
+ rowCount: response.rowCount,
72
+ pageInfo: response.pageInfo
73
+ }), {
74
+ rows: [],
75
+ rowCount: 0,
76
+ pageInfo: {}
77
+ });
78
+ };
66
79
  }
67
- exports.CacheChunkManager = CacheChunkManager;
68
- CacheChunkManager.mergeResponses = responses => {
69
- if (responses.length === 1) {
70
- return responses[0];
71
- }
72
- return responses.reduce((acc, response) => ({
73
- rows: [...acc.rows, ...response.rows],
74
- rowCount: response.rowCount,
75
- pageInfo: response.pageInfo
76
- }), {
77
- rows: [],
78
- rowCount: 0,
79
- pageInfo: {}
80
- });
81
- };
80
+ exports.CacheChunkManager = CacheChunkManager;
@@ -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
  /**