@mui/x-data-grid 8.10.0 → 8.10.2

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 (43) hide show
  1. package/CHANGELOG.md +182 -0
  2. package/components/GridRow.js +5 -5
  3. package/components/columnHeaders/GridColumnHeaderItem.js +5 -1
  4. package/components/containers/GridRootStyles.js +5 -0
  5. package/components/virtualization/GridVirtualScroller.js +3 -3
  6. package/esm/DataGrid/index.js +1 -1
  7. package/esm/components/GridRow.js +5 -5
  8. package/esm/components/columnHeaders/GridColumnHeaderItem.js +5 -1
  9. package/esm/components/containers/GridRootStyles.js +5 -0
  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/utils.js +51 -52
  15. package/esm/hooks/features/dimensions/gridDimensionsApi.d.ts +2 -67
  16. package/esm/hooks/features/dimensions/useGridDimensions.js +20 -15
  17. package/esm/hooks/features/export/serializers/csvSerializer.js +2 -3
  18. package/esm/hooks/features/export/useGridPrintExport.js +3 -8
  19. package/esm/hooks/features/filter/gridFilterUtils.js +11 -2
  20. package/esm/index.js +1 -1
  21. package/esm/internals/utils/cache.js +0 -1
  22. package/esm/locales/fiFI.js +6 -6
  23. package/esm/models/api/gridApiCommon.d.ts +1 -1
  24. package/esm/models/gridRowSelectionManager.js +0 -2
  25. package/esm/utils/cleanupTracking/FinalizationRegistryBasedCleanupTracking.js +5 -7
  26. package/esm/utils/cleanupTracking/TimerBasedCleanupTracking.js +2 -2
  27. package/hooks/core/useGridVirtualizer.js +62 -42
  28. package/hooks/features/dataSource/cache.js +0 -3
  29. package/hooks/features/dataSource/gridDataSourceError.js +16 -16
  30. package/hooks/features/dataSource/utils.js +51 -52
  31. package/hooks/features/dimensions/gridDimensionsApi.d.ts +2 -67
  32. package/hooks/features/dimensions/useGridDimensions.js +20 -15
  33. package/hooks/features/export/serializers/csvSerializer.js +2 -3
  34. package/hooks/features/export/useGridPrintExport.js +3 -8
  35. package/hooks/features/filter/gridFilterUtils.js +10 -1
  36. package/index.js +1 -1
  37. package/internals/utils/cache.js +0 -1
  38. package/locales/fiFI.js +6 -6
  39. package/models/api/gridApiCommon.d.ts +1 -1
  40. package/models/gridRowSelectionManager.js +0 -2
  41. package/package.json +8 -9
  42. package/utils/cleanupTracking/FinalizationRegistryBasedCleanupTracking.js +5 -7
  43. package/utils/cleanupTracking/TimerBasedCleanupTracking.js +2 -2
@@ -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
  }
@@ -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
@@ -3,7 +3,7 @@ import { warnOnce } from '@mui/x-internals/warning';
3
3
  import { GridLogicOperator } from "../../../models/index.js";
4
4
  import { getDefaultGridFilterModel } from "./gridFilterState.js";
5
5
  import { getPublicApiRef } from "../../../utils/getPublicApiRef.js";
6
- import { gridColumnFieldsSelector, gridColumnLookupSelector, gridVisibleColumnFieldsSelector } from "../columns/index.js";
6
+ import { gridColumnFieldsSelector, gridColumnLookupSelector, gridColumnVisibilityModelSelector } from "../columns/index.js";
7
7
  let hasEval;
8
8
  function getHasEval() {
9
9
  if (hasEval !== undefined) {
@@ -191,7 +191,16 @@ const buildAggregatedQuickFilterApplier = (filterModel, apiRef) => {
191
191
  if (quickFilterValues.length === 0) {
192
192
  return null;
193
193
  }
194
- const columnFields = shouldQuickFilterExcludeHiddenColumns(filterModel) ? gridVisibleColumnFieldsSelector(apiRef) : gridColumnFieldsSelector(apiRef);
194
+ const allColumnFields = gridColumnFieldsSelector(apiRef);
195
+ const columnVisibilityModel = gridColumnVisibilityModelSelector(apiRef);
196
+ let columnFields;
197
+ if (shouldQuickFilterExcludeHiddenColumns(filterModel)) {
198
+ // Do not use gridVisibleColumnFieldsSelector here, because quick filter won't work in the list view mode
199
+ // See https://github.com/mui/mui-x/issues/19145
200
+ columnFields = allColumnFields.filter(field => columnVisibilityModel[field] !== false);
201
+ } else {
202
+ columnFields = allColumnFields;
203
+ }
195
204
  const appliersPerField = [];
196
205
  const {
197
206
  ignoreDiacritics
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.2
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) {
@@ -3,8 +3,8 @@ const fiFIGrid = {
3
3
  // Root
4
4
  noRowsLabel: 'Ei rivejä',
5
5
  noResultsOverlayLabel: 'Ei tuloksia.',
6
- // noColumnsOverlayLabel: 'No columns',
7
- // noColumnsOverlayManageColumns: 'Manage columns',
6
+ noColumnsOverlayLabel: 'Ei sarakkeita',
7
+ noColumnsOverlayManageColumns: 'Hallitse sarakkeita',
8
8
  // emptyPivotOverlayLabel: 'Add fields to rows, columns, and values to create a pivot table',
9
9
 
10
10
  // Density selector toolbar button text
@@ -58,9 +58,9 @@ const fiFIGrid = {
58
58
  filterPanelInputPlaceholder: 'Suodattimen arvo',
59
59
  // Filter operators text
60
60
  filterOperatorContains: 'sisältää',
61
- // filterOperatorDoesNotContain: 'does not contain',
61
+ filterOperatorDoesNotContain: 'ei sisällä',
62
62
  filterOperatorEquals: 'on yhtä suuri kuin',
63
- // filterOperatorDoesNotEqual: 'does not equal',
63
+ filterOperatorDoesNotEqual: 'on eri suuri kuin',
64
64
  filterOperatorStartsWith: 'alkaa',
65
65
  filterOperatorEndsWith: 'päättyy',
66
66
  filterOperatorIs: 'on',
@@ -80,9 +80,9 @@ const fiFIGrid = {
80
80
  'filterOperator<=': '<=',
81
81
  // Header filter operators text
82
82
  headerFilterOperatorContains: 'Sisältää',
83
- // headerFilterOperatorDoesNotContain: 'Does not contain',
83
+ headerFilterOperatorDoesNotContain: 'Ei sisällä',
84
84
  headerFilterOperatorEquals: 'On yhtä suuri kuin',
85
- // headerFilterOperatorDoesNotEqual: 'Does not equal',
85
+ headerFilterOperatorDoesNotEqual: 'On eri suuri kuin',
86
86
  headerFilterOperatorStartsWith: 'Alkaa',
87
87
  headerFilterOperatorEndsWith: 'Päättyy',
88
88
  headerFilterOperatorIs: 'On',
@@ -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;