@mui/x-data-grid 8.9.1 → 8.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/CHANGELOG.md +217 -8
  2. package/DataGrid/DataGrid.js +5 -0
  3. package/DataGrid/useDataGridComponent.js +2 -0
  4. package/colDef/gridCheckboxSelectionColDef.js +1 -0
  5. package/components/GridDetailPanels.d.ts +2 -2
  6. package/components/GridFooter.js +1 -1
  7. package/components/GridPagination.js +4 -3
  8. package/components/GridPinnedRows.d.ts +2 -2
  9. package/components/GridRow.js +8 -1
  10. package/components/cell/GridCell.js +7 -5
  11. package/components/cell/GridEditSingleSelectCell.js +1 -1
  12. package/components/columnsManagement/GridColumnsManagement.d.ts +6 -0
  13. package/components/columnsManagement/GridColumnsManagement.js +17 -5
  14. package/components/containers/GridRootStyles.d.ts +1 -1
  15. package/components/toolbarV8/Toolbar.d.ts +1 -1
  16. package/components/virtualization/GridVirtualScroller.js +5 -5
  17. package/constants/dataGridPropsDefaultValues.js +1 -0
  18. package/esm/DataGrid/DataGrid.js +5 -0
  19. package/esm/DataGrid/useDataGridComponent.js +2 -0
  20. package/esm/colDef/gridCheckboxSelectionColDef.js +1 -0
  21. package/esm/components/GridDetailPanels.d.ts +2 -2
  22. package/esm/components/GridFooter.js +1 -1
  23. package/esm/components/GridPagination.js +3 -2
  24. package/esm/components/GridPinnedRows.d.ts +2 -2
  25. package/esm/components/GridRow.js +8 -1
  26. package/esm/components/cell/GridCell.js +7 -5
  27. package/esm/components/cell/GridEditSingleSelectCell.js +1 -1
  28. package/esm/components/columnsManagement/GridColumnsManagement.d.ts +6 -0
  29. package/esm/components/columnsManagement/GridColumnsManagement.js +17 -5
  30. package/esm/components/containers/GridRootStyles.d.ts +1 -1
  31. package/esm/components/toolbarV8/Toolbar.d.ts +1 -1
  32. package/esm/components/virtualization/GridVirtualScroller.js +5 -5
  33. package/esm/constants/dataGridPropsDefaultValues.js +1 -0
  34. package/esm/hooks/core/useGridVirtualizer.d.ts +9 -0
  35. package/esm/hooks/core/useGridVirtualizer.js +223 -0
  36. package/esm/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +1 -1
  37. package/esm/hooks/features/columnHeaders/useGridColumnHeaders.js +3 -2
  38. package/esm/hooks/features/columns/useGridColumnSpanning.js +5 -90
  39. package/esm/hooks/features/dataSource/models.d.ts +11 -2
  40. package/esm/hooks/features/dataSource/useGridDataSourceBase.d.ts +1 -1
  41. package/esm/hooks/features/dataSource/useGridDataSourceBase.js +9 -2
  42. package/esm/hooks/features/dimensions/useGridDimensions.js +18 -188
  43. package/esm/hooks/features/editing/useGridRowEditing.js +4 -1
  44. package/esm/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +1 -1
  45. package/esm/hooks/features/keyboardNavigation/utils.d.ts +3 -3
  46. package/esm/hooks/features/keyboardNavigation/utils.js +5 -5
  47. package/esm/hooks/features/pivoting/gridPivotingInterfaces.d.ts +0 -1
  48. package/esm/hooks/features/pivoting/gridPivotingSelectors.d.ts +1 -4
  49. package/esm/hooks/features/pivoting/gridPivotingSelectors.js +1 -2
  50. package/esm/hooks/features/rowReorder/gridRowReorderInterfaces.d.ts +9 -0
  51. package/esm/hooks/features/rowReorder/gridRowReorderInterfaces.js +1 -0
  52. package/esm/hooks/features/rowReorder/gridRowReorderSelector.d.ts +5 -0
  53. package/esm/hooks/features/rowReorder/gridRowReorderSelector.js +3 -0
  54. package/esm/hooks/features/rowSelection/useGridRowSelection.js +2 -2
  55. package/esm/hooks/features/rowSelection/utils.js +5 -0
  56. package/esm/hooks/features/rows/gridRowsMetaInterfaces.d.ts +2 -8
  57. package/esm/hooks/features/rows/gridRowsMetaState.d.ts +2 -18
  58. package/esm/hooks/features/rows/useGridRowAriaAttributes.js +3 -1
  59. package/esm/hooks/features/rows/useGridRowSpanning.d.ts +2 -12
  60. package/esm/hooks/features/rows/useGridRowSpanning.js +54 -85
  61. package/esm/hooks/features/rows/useGridRowsMeta.d.ts +1 -1
  62. package/esm/hooks/features/rows/useGridRowsMeta.js +17 -187
  63. package/esm/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +1 -1
  64. package/esm/hooks/features/virtualization/index.d.ts +1 -0
  65. package/esm/hooks/features/virtualization/index.js +1 -0
  66. package/esm/hooks/features/virtualization/useGridVirtualization.d.ts +5 -16
  67. package/esm/hooks/features/virtualization/useGridVirtualization.js +41 -22
  68. package/esm/hooks/utils/index.d.ts +1 -1
  69. package/esm/hooks/utils/index.js +1 -1
  70. package/esm/hooks/utils/useFirstRender.d.ts +1 -1
  71. package/esm/hooks/utils/useFirstRender.js +1 -8
  72. package/esm/index.js +1 -1
  73. package/esm/internals/index.d.ts +3 -1
  74. package/esm/internals/index.js +2 -1
  75. package/esm/internals/utils/getPinnedCellOffset.js +5 -0
  76. package/esm/locales/frFR.js +18 -21
  77. package/esm/locales/heIL.js +12 -12
  78. package/esm/locales/nnNO.js +96 -107
  79. package/esm/locales/plPL.js +22 -24
  80. package/esm/material/index.js +2 -2
  81. package/esm/models/api/gridApiCommon.d.ts +4 -1
  82. package/esm/models/api/gridColumnSpanning.d.ts +5 -11
  83. package/esm/models/gridStateCommunity.d.ts +2 -0
  84. package/esm/models/props/DataGridProps.d.ts +5 -0
  85. package/esm/utils/roundToDecimalPlaces.d.ts +1 -1
  86. package/esm/utils/roundToDecimalPlaces.js +1 -3
  87. package/hooks/core/useGridVirtualizer.d.ts +9 -0
  88. package/hooks/core/useGridVirtualizer.js +231 -0
  89. package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +1 -1
  90. package/hooks/features/columnHeaders/useGridColumnHeaders.js +4 -3
  91. package/hooks/features/columns/useGridColumnSpanning.js +5 -91
  92. package/hooks/features/dataSource/models.d.ts +11 -2
  93. package/hooks/features/dataSource/useGridDataSourceBase.d.ts +1 -1
  94. package/hooks/features/dataSource/useGridDataSourceBase.js +10 -3
  95. package/hooks/features/dimensions/useGridDimensions.js +18 -188
  96. package/hooks/features/editing/useGridRowEditing.js +4 -1
  97. package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +1 -1
  98. package/hooks/features/keyboardNavigation/utils.d.ts +3 -3
  99. package/hooks/features/keyboardNavigation/utils.js +5 -5
  100. package/hooks/features/pivoting/gridPivotingInterfaces.d.ts +0 -1
  101. package/hooks/features/pivoting/gridPivotingSelectors.d.ts +1 -4
  102. package/hooks/features/pivoting/gridPivotingSelectors.js +2 -3
  103. package/hooks/features/rowReorder/gridRowReorderInterfaces.d.ts +9 -0
  104. package/hooks/features/rowReorder/gridRowReorderInterfaces.js +5 -0
  105. package/hooks/features/rowReorder/gridRowReorderSelector.d.ts +5 -0
  106. package/hooks/features/rowReorder/gridRowReorderSelector.js +9 -0
  107. package/hooks/features/rowSelection/useGridRowSelection.js +2 -2
  108. package/hooks/features/rowSelection/utils.js +5 -0
  109. package/hooks/features/rows/gridRowsMetaInterfaces.d.ts +2 -8
  110. package/hooks/features/rows/gridRowsMetaState.d.ts +2 -18
  111. package/hooks/features/rows/useGridRowAriaAttributes.js +3 -1
  112. package/hooks/features/rows/useGridRowSpanning.d.ts +2 -12
  113. package/hooks/features/rows/useGridRowSpanning.js +54 -85
  114. package/hooks/features/rows/useGridRowsMeta.d.ts +1 -1
  115. package/hooks/features/rows/useGridRowsMeta.js +15 -186
  116. package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +1 -1
  117. package/hooks/features/virtualization/index.d.ts +1 -0
  118. package/hooks/features/virtualization/index.js +12 -0
  119. package/hooks/features/virtualization/useGridVirtualization.d.ts +5 -16
  120. package/hooks/features/virtualization/useGridVirtualization.js +42 -24
  121. package/hooks/utils/index.d.ts +1 -1
  122. package/hooks/utils/index.js +12 -12
  123. package/hooks/utils/useFirstRender.d.ts +1 -1
  124. package/hooks/utils/useFirstRender.js +11 -11
  125. package/index.js +1 -1
  126. package/internals/index.d.ts +3 -1
  127. package/internals/index.js +12 -11
  128. package/internals/utils/getPinnedCellOffset.js +5 -0
  129. package/locales/frFR.js +18 -21
  130. package/locales/heIL.js +12 -12
  131. package/locales/nnNO.js +96 -107
  132. package/locales/plPL.js +22 -24
  133. package/material/index.js +2 -2
  134. package/models/api/gridApiCommon.d.ts +4 -1
  135. package/models/api/gridColumnSpanning.d.ts +5 -11
  136. package/models/gridStateCommunity.d.ts +2 -0
  137. package/models/props/DataGridProps.d.ts +5 -0
  138. package/package.json +5 -6
  139. package/utils/roundToDecimalPlaces.d.ts +1 -1
  140. package/utils/roundToDecimalPlaces.js +7 -4
  141. package/esm/hooks/features/rows/gridRowSpanningSelectors.d.ts +0 -10
  142. package/esm/hooks/features/rows/gridRowSpanningSelectors.js +0 -5
  143. package/esm/hooks/features/virtualization/useGridVirtualScroller.d.ts +0 -56
  144. package/esm/hooks/features/virtualization/useGridVirtualScroller.js +0 -843
  145. package/esm/hooks/utils/useRunOnce.d.ts +0 -5
  146. package/esm/hooks/utils/useRunOnce.js +0 -18
  147. package/esm/utils/platform.d.ts +0 -1
  148. package/esm/utils/platform.js +0 -2
  149. package/hooks/features/rows/gridRowSpanningSelectors.d.ts +0 -10
  150. package/hooks/features/rows/gridRowSpanningSelectors.js +0 -11
  151. package/hooks/features/virtualization/useGridVirtualScroller.d.ts +0 -56
  152. package/hooks/features/virtualization/useGridVirtualScroller.js +0 -854
  153. package/hooks/utils/useRunOnce.d.ts +0 -5
  154. package/hooks/utils/useRunOnce.js +0 -27
  155. package/utils/platform.d.ts +0 -1
  156. package/utils/platform.js +0 -8
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
1
  import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
3
2
  import { useGridEvent } from "../../utils/useGridEvent.js";
4
3
  /**
@@ -6,36 +5,10 @@ import { useGridEvent } from "../../utils/useGridEvent.js";
6
5
  * @requires useGridParamsApi (method)
7
6
  */
8
7
  export const useGridColumnSpanning = apiRef => {
9
- const lookup = React.useRef({});
10
- const getCellColSpanInfo = (rowId, columnIndex) => {
11
- return lookup.current[rowId]?.[columnIndex];
12
- };
13
- const resetColSpan = () => {
14
- lookup.current = {};
15
- };
16
-
17
- // Calculate `colSpan` for each cell in the row
18
- const calculateColSpan = React.useCallback(({
19
- rowId,
20
- minFirstColumn,
21
- maxLastColumn,
22
- columns
23
- }) => {
24
- for (let i = minFirstColumn; i < maxLastColumn; i += 1) {
25
- const cellProps = calculateCellColSpan({
26
- apiRef,
27
- lookup: lookup.current,
28
- columnIndex: i,
29
- rowId,
30
- minFirstColumnIndex: minFirstColumn,
31
- maxLastColumnIndex: maxLastColumn,
32
- columns
33
- });
34
- if (cellProps.colSpan > 1) {
35
- i += cellProps.colSpan - 1;
36
- }
37
- }
38
- }, [apiRef]);
8
+ const virtualizer = apiRef.current.virtualizer;
9
+ const resetColSpan = virtualizer.api.resetColSpan;
10
+ const getCellColSpanInfo = virtualizer.api.getCellColSpanInfo;
11
+ const calculateColSpan = virtualizer.api.calculateColSpan;
39
12
  const columnSpanningPublicApi = {
40
13
  unstable_getCellColSpanInfo: getCellColSpanInfo
41
14
  };
@@ -46,62 +19,4 @@ export const useGridColumnSpanning = apiRef => {
46
19
  useGridApiMethod(apiRef, columnSpanningPublicApi, 'public');
47
20
  useGridApiMethod(apiRef, columnSpanningPrivateApi, 'private');
48
21
  useGridEvent(apiRef, 'columnOrderChange', resetColSpan);
49
- };
50
- function calculateCellColSpan(params) {
51
- const {
52
- apiRef,
53
- lookup,
54
- columnIndex,
55
- rowId,
56
- minFirstColumnIndex,
57
- maxLastColumnIndex,
58
- columns
59
- } = params;
60
- const columnsLength = columns.length;
61
- const column = columns[columnIndex];
62
- const row = apiRef.current.getRow(rowId);
63
- const value = apiRef.current.getRowValue(row, column);
64
- const colSpan = typeof column.colSpan === 'function' ? column.colSpan(value, row, column, apiRef) : column.colSpan;
65
- if (!colSpan || colSpan === 1) {
66
- setCellColSpanInfo(lookup, rowId, columnIndex, {
67
- spannedByColSpan: false,
68
- cellProps: {
69
- colSpan: 1,
70
- width: column.computedWidth
71
- }
72
- });
73
- return {
74
- colSpan: 1
75
- };
76
- }
77
- let width = column.computedWidth;
78
- for (let j = 1; j < colSpan; j += 1) {
79
- const nextColumnIndex = columnIndex + j;
80
- // Cells should be spanned only within their column section (left-pinned, right-pinned and unpinned).
81
- if (nextColumnIndex >= minFirstColumnIndex && nextColumnIndex < maxLastColumnIndex) {
82
- const nextColumn = columns[nextColumnIndex];
83
- width += nextColumn.computedWidth;
84
- setCellColSpanInfo(lookup, rowId, columnIndex + j, {
85
- spannedByColSpan: true,
86
- rightVisibleCellIndex: Math.min(columnIndex + colSpan, columnsLength - 1),
87
- leftVisibleCellIndex: columnIndex
88
- });
89
- }
90
- setCellColSpanInfo(lookup, rowId, columnIndex, {
91
- spannedByColSpan: false,
92
- cellProps: {
93
- colSpan,
94
- width
95
- }
96
- });
97
- }
98
- return {
99
- colSpan
100
- };
101
- }
102
- function setCellColSpanInfo(lookup, rowId, columnIndex, cellColSpanInfo) {
103
- if (!lookup[rowId]) {
104
- lookup[rowId] = {};
105
- }
106
- lookup[rowId][columnIndex] = cellColSpanInfo;
107
- }
22
+ };
@@ -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
@@ -2,11 +2,8 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import * as React from 'react';
5
- import useEventCallback from '@mui/utils/useEventCallback';
6
- import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
7
- import ownerDocument from '@mui/utils/ownerDocument';
8
- import { throttle } from '@mui/x-internals/throttle';
9
- import { isDeepEqual } from '@mui/x-internals/isDeepEqual';
5
+ import { useStoreEffect } from '@mui/x-internals/store';
6
+ import { Dimensions } from '@mui/x-virtualizer';
10
7
  import { useGridEventPriority } from "../../utils/useGridEvent.js";
11
8
  import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
12
9
  import { createSelector } from "../../../utils/createSelector.js";
@@ -14,10 +11,6 @@ import { useGridLogger } from "../../utils/useGridLogger.js";
14
11
  import { gridColumnPositionsSelector, gridVisibleColumnDefinitionsSelector, gridVisiblePinnedColumnDefinitionsSelector } from "../columns/index.js";
15
12
  import { gridDimensionsSelector } from "./gridDimensionsSelectors.js";
16
13
  import { gridDensityFactorSelector } from "../density/index.js";
17
- import { gridRenderContextSelector } from "../virtualization/index.js";
18
- import { useGridSelector } from "../../utils/index.js";
19
- import { getVisibleRows } from "../../utils/useGridVisibleRows.js";
20
- import { gridRowsMetaSelector } from "../rows/gridRowsMetaSelector.js";
21
14
  import { getValidRowHeight, rowHeightWarning } from "../rows/gridRowsUtils.js";
22
15
  import { getTotalHeaderHeight } from "../columns/gridColumnsUtils.js";
23
16
  import { DATA_GRID_PROPS_DEFAULT_VALUES } from "../../../constants/dataGridPropsDefaultValues.js";
@@ -66,148 +59,10 @@ const columnsTotalWidthSelector = createSelector(gridVisibleColumnDefinitionsSel
66
59
  export function useGridDimensions(apiRef, props) {
67
60
  const logger = useGridLogger(apiRef, 'useResizeContainer');
68
61
  const errorShown = React.useRef(false);
69
- const rootDimensionsRef = React.useRef(EMPTY_SIZE);
70
- const pinnedColumns = useGridSelector(apiRef, gridVisiblePinnedColumnDefinitionsSelector);
71
- const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
72
- const columnsTotalWidth = useGridSelector(apiRef, columnsTotalWidthSelector);
73
- const isFirstSizing = React.useRef(true);
74
- const {
75
- rowHeight,
76
- headerHeight,
77
- groupHeaderHeight,
78
- headerFilterHeight,
79
- headersTotalHeight,
80
- leftPinnedWidth,
81
- rightPinnedWidth
82
- } = getStaticDimensions(props, apiRef, densityFactor, pinnedColumns);
62
+ const virtualizer = apiRef.current.virtualizer;
63
+ const updateDimensions = virtualizer.api.updateDimensions;
64
+ const getViewportPageSize = virtualizer.api.getViewportPageSize;
83
65
  const getRootDimensions = React.useCallback(() => gridDimensionsSelector(apiRef), [apiRef]);
84
- const setDimensions = React.useCallback(dimensions => {
85
- apiRef.current.setState(state => _extends({}, state, {
86
- dimensions
87
- }));
88
- if (apiRef.current.rootElementRef.current) {
89
- setCSSVariables(apiRef.current.rootElementRef.current, gridDimensionsSelector(apiRef));
90
- }
91
- }, [apiRef]);
92
- const getViewportPageSize = React.useCallback(() => {
93
- const dimensions = gridDimensionsSelector(apiRef);
94
- if (!dimensions.isReady) {
95
- return 0;
96
- }
97
- const currentPage = getVisibleRows(apiRef);
98
-
99
- // TODO: Use a combination of scrollTop, dimensions.viewportInnerSize.height and rowsMeta.possitions
100
- // to find out the maximum number of rows that can fit in the visible part of the grid
101
- if (props.getRowHeight) {
102
- const renderContext = gridRenderContextSelector(apiRef);
103
- const viewportPageSize = renderContext.lastRowIndex - renderContext.firstRowIndex;
104
- return Math.min(viewportPageSize - 1, currentPage.rows.length);
105
- }
106
- const maximumPageSizeWithoutScrollBar = Math.floor(dimensions.viewportInnerSize.height / rowHeight);
107
- return Math.min(maximumPageSizeWithoutScrollBar, currentPage.rows.length);
108
- }, [apiRef, props.getRowHeight, rowHeight]);
109
- const updateDimensions = React.useCallback(() => {
110
- if (isFirstSizing.current) {
111
- return;
112
- }
113
- // All the floating point dimensions should be rounded to .1 decimal places to avoid subpixel rendering issues
114
- // https://github.com/mui/mui-x/issues/9550#issuecomment-1619020477
115
- // https://github.com/mui/mui-x/issues/15721
116
- const scrollbarSize = measureScrollbarSize(apiRef.current.mainElementRef.current, props.scrollbarSize);
117
- const rowsMeta = gridRowsMetaSelector(apiRef);
118
- const topContainerHeight = headersTotalHeight + rowsMeta.pinnedTopRowsTotalHeight;
119
- const bottomContainerHeight = rowsMeta.pinnedBottomRowsTotalHeight;
120
- const contentSize = {
121
- width: columnsTotalWidth,
122
- height: roundToDecimalPlaces(rowsMeta.currentPageTotalHeight, 1)
123
- };
124
- let viewportOuterSize;
125
- let viewportInnerSize;
126
- let hasScrollX = false;
127
- let hasScrollY = false;
128
- if (props.autoHeight) {
129
- hasScrollY = false;
130
- hasScrollX = Math.round(columnsTotalWidth) > Math.round(rootDimensionsRef.current.width);
131
- viewportOuterSize = {
132
- width: rootDimensionsRef.current.width,
133
- height: topContainerHeight + bottomContainerHeight + contentSize.height
134
- };
135
- viewportInnerSize = {
136
- width: Math.max(0, viewportOuterSize.width - (hasScrollY ? scrollbarSize : 0)),
137
- height: Math.max(0, viewportOuterSize.height - (hasScrollX ? scrollbarSize : 0))
138
- };
139
- } else {
140
- viewportOuterSize = {
141
- width: rootDimensionsRef.current.width,
142
- height: rootDimensionsRef.current.height
143
- };
144
- viewportInnerSize = {
145
- width: Math.max(0, viewportOuterSize.width),
146
- height: Math.max(0, viewportOuterSize.height - topContainerHeight - bottomContainerHeight)
147
- };
148
- const content = contentSize;
149
- const container = viewportInnerSize;
150
- const hasScrollXIfNoYScrollBar = content.width > container.width;
151
- const hasScrollYIfNoXScrollBar = content.height > container.height;
152
- if (hasScrollXIfNoYScrollBar || hasScrollYIfNoXScrollBar) {
153
- hasScrollY = hasScrollYIfNoXScrollBar;
154
- hasScrollX = content.width + (hasScrollY ? scrollbarSize : 0) > container.width;
155
-
156
- // We recalculate the scroll y to consider the size of the x scrollbar.
157
- if (hasScrollX) {
158
- hasScrollY = content.height + scrollbarSize > container.height;
159
- }
160
- }
161
- if (hasScrollY) {
162
- viewportInnerSize.width -= scrollbarSize;
163
- }
164
- if (hasScrollX) {
165
- viewportInnerSize.height -= scrollbarSize;
166
- }
167
- }
168
- const rowWidth = Math.max(viewportOuterSize.width, columnsTotalWidth + (hasScrollY ? scrollbarSize : 0));
169
- const minimumSize = {
170
- width: columnsTotalWidth,
171
- height: topContainerHeight + contentSize.height + bottomContainerHeight
172
- };
173
- const newDimensions = {
174
- isReady: true,
175
- root: rootDimensionsRef.current,
176
- viewportOuterSize,
177
- viewportInnerSize,
178
- contentSize,
179
- minimumSize,
180
- hasScrollX,
181
- hasScrollY,
182
- scrollbarSize,
183
- headerHeight,
184
- groupHeaderHeight,
185
- headerFilterHeight,
186
- rowWidth,
187
- rowHeight,
188
- columnsTotalWidth,
189
- leftPinnedWidth,
190
- rightPinnedWidth,
191
- headersTotalHeight,
192
- topContainerHeight,
193
- bottomContainerHeight
194
- };
195
- const prevDimensions = apiRef.current.state.dimensions;
196
- if (isDeepEqual(prevDimensions, newDimensions)) {
197
- return;
198
- }
199
- setDimensions(newDimensions);
200
- if (!areElementSizesEqual(newDimensions.viewportInnerSize, prevDimensions.viewportInnerSize)) {
201
- apiRef.current.publishEvent('viewportInnerSizeChange', newDimensions.viewportInnerSize);
202
- }
203
- apiRef.current.updateRenderContext?.();
204
- }, [apiRef, setDimensions, props.scrollbarSize, props.autoHeight, rowHeight, headerHeight, groupHeaderHeight, headerFilterHeight, columnsTotalWidth, headersTotalHeight, leftPinnedWidth, rightPinnedWidth]);
205
- const updateDimensionCallback = useEventCallback(updateDimensions);
206
- const debouncedUpdateDimensions = React.useMemo(() => props.resizeThrottleMs > 0 ? throttle(() => {
207
- updateDimensionCallback();
208
- apiRef.current.publishEvent('debouncedResize', rootDimensionsRef.current);
209
- }, props.resizeThrottleMs) : undefined, [apiRef, props.resizeThrottleMs, updateDimensionCallback]);
210
- React.useEffect(() => debouncedUpdateDimensions?.clear, [debouncedUpdateDimensions]);
211
66
  const apiPublic = {
212
67
  getRootDimensions
213
68
  };
@@ -215,14 +70,12 @@ export function useGridDimensions(apiRef, props) {
215
70
  updateDimensions,
216
71
  getViewportPageSize
217
72
  };
218
- useEnhancedEffect(updateDimensions, [updateDimensions]);
219
73
  useGridApiMethod(apiRef, apiPublic, 'public');
220
74
  useGridApiMethod(apiRef, apiPrivate, 'private');
221
- const handleRootMount = React.useCallback(root => {
75
+ const handleRootMount = root => {
222
76
  setCSSVariables(root, gridDimensionsSelector(apiRef));
223
- }, [apiRef]);
224
- const handleResize = React.useCallback(size => {
225
- rootDimensionsRef.current = size;
77
+ };
78
+ const handleResize = size => {
226
79
  if (size.height === 0 && !errorShown.current && !props.autoHeight && !isJSDOM) {
227
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'));
228
81
  errorShown.current = true;
@@ -231,17 +84,19 @@ export function useGridDimensions(apiRef, props) {
231
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'));
232
85
  errorShown.current = true;
233
86
  }
234
- if (isFirstSizing.current || !debouncedUpdateDimensions) {
235
- // We want to initialize the grid dimensions as soon as possible to avoid flickering
236
- isFirstSizing.current = false;
237
- updateDimensions();
238
- return;
239
- }
240
- debouncedUpdateDimensions();
241
- }, [updateDimensions, props.autoHeight, debouncedUpdateDimensions, logger]);
87
+ };
242
88
  useGridEventPriority(apiRef, 'rootMount', handleRootMount);
243
89
  useGridEventPriority(apiRef, 'resize', handleResize);
244
90
  useGridEventPriority(apiRef, 'debouncedResize', props.onResize);
91
+ useStoreEffect(virtualizer.store, Dimensions.selectors.dimensions, (previous, next) => {
92
+ if (apiRef.current.rootElementRef.current) {
93
+ setCSSVariables(apiRef.current.rootElementRef.current, next);
94
+ }
95
+ if (!areElementSizesEqual(next.viewportInnerSize, previous.viewportInnerSize)) {
96
+ apiRef.current.publishEvent('viewportInnerSizeChange', next.viewportInnerSize);
97
+ }
98
+ apiRef.current.publishEvent('debouncedResize', next.root);
99
+ });
245
100
  }
246
101
  function setCSSVariables(root, dimensions) {
247
102
  const set = (k, v) => root.style.setProperty(k, v);
@@ -271,31 +126,6 @@ function getStaticDimensions(props, apiRef, density, pinnedColumnns) {
271
126
  rightPinnedWidth: pinnedColumnns.right.reduce((w, col) => w + col.computedWidth, 0)
272
127
  };
273
128
  }
274
- const scrollbarSizeCache = new WeakMap();
275
- function measureScrollbarSize(element, scrollbarSize) {
276
- if (scrollbarSize !== undefined) {
277
- return scrollbarSize;
278
- }
279
- if (element === null) {
280
- return 0;
281
- }
282
- const cachedSize = scrollbarSizeCache.get(element);
283
- if (cachedSize !== undefined) {
284
- return cachedSize;
285
- }
286
- const doc = ownerDocument(element);
287
- const scrollDiv = doc.createElement('div');
288
- scrollDiv.style.width = '99px';
289
- scrollDiv.style.height = '99px';
290
- scrollDiv.style.position = 'absolute';
291
- scrollDiv.style.overflow = 'scroll';
292
- scrollDiv.className = 'scrollDiv';
293
- element.appendChild(scrollDiv);
294
- const size = scrollDiv.offsetWidth - scrollDiv.clientWidth;
295
- element.removeChild(scrollDiv);
296
- scrollbarSizeCache.set(element, size);
297
- return size;
298
- }
299
129
  function areElementSizesEqual(a, b) {
300
130
  return a.width === b.width && a.height === b.height;
301
131
  }
@@ -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;
@@ -58,7 +58,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
58
58
  }
59
59
  }
60
60
  const field = gridVisibleColumnFieldsSelector(apiRef)[colIndex];
61
- const nonRowSpannedRowId = findNonRowSpannedCell(apiRef, rowId, field, rowSpanScanDirection);
61
+ const nonRowSpannedRowId = findNonRowSpannedCell(apiRef, rowId, colIndex, rowSpanScanDirection);
62
62
  // `scrollToIndexes` requires a rowIndex relative to all visible rows.
63
63
  // Those rows do not include pinned rows, but pinned rows do not need scroll anyway.
64
64
  const rowIndexRelativeToAllRows = visibleSortedRows.findIndex(row => row.id === nonRowSpannedRowId);
@@ -1,6 +1,6 @@
1
1
  import { RefObject } from '@mui/x-internals/types';
2
- import { GridColDef, GridRowId } from "../../../models/index.js";
3
- import { GridApiCommunity } from "../../../models/api/gridApiCommunity.js";
2
+ import { GridRowId } from "../../../models/index.js";
3
+ import { GridPrivateApiCommunity } from "../../../models/api/gridApiCommunity.js";
4
4
  export declare const getLeftColumnIndex: ({
5
5
  currentColIndex,
6
6
  firstColIndex,
@@ -23,4 +23,4 @@ export declare const getRightColumnIndex: ({
23
23
  lastColIndex: number;
24
24
  isRtl: boolean;
25
25
  }) => number | null;
26
- export declare function findNonRowSpannedCell(apiRef: RefObject<GridApiCommunity>, rowId: GridRowId, field: GridColDef['field'], rowSpanScanDirection: 'up' | 'down'): GridRowId;
26
+ export declare function findNonRowSpannedCell(apiRef: RefObject<GridPrivateApiCommunity>, rowId: GridRowId, colIndex: number, rowSpanScanDirection: 'up' | 'down'): GridRowId;
@@ -1,5 +1,5 @@
1
+ import { Rowspan } from '@mui/x-virtualizer';
1
2
  import { gridFilteredSortedRowIdsSelector } from "../filter/gridFilterSelector.js";
2
- import { gridRowSpanningHiddenCellsSelector } from "../rows/gridRowSpanningSelectors.js";
3
3
  export const getLeftColumnIndex = ({
4
4
  currentColIndex,
5
5
  firstColIndex,
@@ -34,9 +34,9 @@ export const getRightColumnIndex = ({
34
34
  }
35
35
  return null;
36
36
  };
37
- export function findNonRowSpannedCell(apiRef, rowId, field, rowSpanScanDirection) {
38
- const rowSpanHiddenCells = gridRowSpanningHiddenCellsSelector(apiRef);
39
- if (!rowSpanHiddenCells[rowId]?.[field]) {
37
+ export function findNonRowSpannedCell(apiRef, rowId, colIndex, rowSpanScanDirection) {
38
+ const rowSpanHiddenCells = Rowspan.selectors.hiddenCells(apiRef.current.virtualizer.store.state);
39
+ if (!rowSpanHiddenCells[rowId]?.[colIndex]) {
40
40
  return rowId;
41
41
  }
42
42
  const filteredSortedRowIds = gridFilteredSortedRowIdsSelector(apiRef);
@@ -44,7 +44,7 @@ export function findNonRowSpannedCell(apiRef, rowId, field, rowSpanScanDirection
44
44
  let nextRowIndex = filteredSortedRowIds.indexOf(rowId) + (rowSpanScanDirection === 'down' ? 1 : -1);
45
45
  while (nextRowIndex >= 0 && nextRowIndex < filteredSortedRowIds.length) {
46
46
  const nextRowId = filteredSortedRowIds[nextRowIndex];
47
- if (!rowSpanHiddenCells[nextRowId]?.[field]) {
47
+ if (!rowSpanHiddenCells[nextRowId]?.[colIndex]) {
48
48
  return nextRowId;
49
49
  }
50
50
  nextRowIndex += rowSpanScanDirection === 'down' ? 1 : -1;
@@ -2,7 +2,6 @@ import type { GridRowModelUpdate } from '@mui/x-data-grid';
2
2
  import type { GridColDef } from "../../../models/colDef/index.js";
3
3
  export interface GridPivotingStatePartial {
4
4
  active: boolean;
5
- panelOpen: boolean;
6
5
  initialColumns: Map<string, GridColDef> | undefined;
7
6
  }
8
7
  export interface GridPivotingPrivateApiCommunity {
@@ -5,7 +5,4 @@ export declare const gridPivotActiveSelector: (args_0: import("react").RefObject
5
5
  } | null>) => boolean;
6
6
  export declare const gridPivotInitialColumnsSelector: (args_0: import("react").RefObject<{
7
7
  state: GridStateCommunity;
8
- } | null>) => Map<string, GridColDef>;
9
- export declare const gridPivotPanelOpenSelector: (args_0: import("react").RefObject<{
10
- state: GridStateCommunity;
11
- } | null>) => boolean;
8
+ } | null>) => Map<string, GridColDef>;
@@ -4,5 +4,4 @@ const gridPivotingStateSelector = createRootSelector(
4
4
  state => state.pivoting);
5
5
  export const gridPivotActiveSelector = createSelector(gridPivotingStateSelector, pivoting => pivoting?.active);
6
6
  const emptyColumns = new Map();
7
- export const gridPivotInitialColumnsSelector = createSelector(gridPivotingStateSelector, pivoting => pivoting?.initialColumns || emptyColumns);
8
- export const gridPivotPanelOpenSelector = createSelector(gridPivotingStateSelector, pivoting => pivoting?.panelOpen);
7
+ export const gridPivotInitialColumnsSelector = createSelector(gridPivotingStateSelector, pivoting => pivoting?.initialColumns || emptyColumns);
@@ -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);
@@ -43,7 +43,8 @@ export const useGridRowSelection = (apiRef, props) => {
43
43
  callback(...args);
44
44
  }
45
45
  }, [props.rowSelection]);
46
- const applyAutoSelection = props.signature !== GridSignature.DataGrid && (props.rowSelectionPropagation?.parents || props.rowSelectionPropagation?.descendants);
46
+ const isNestedData = useGridSelector(apiRef, gridRowMaximumTreeDepthSelector) > 1;
47
+ const applyAutoSelection = props.signature !== GridSignature.DataGrid && (props.rowSelectionPropagation?.parents || props.rowSelectionPropagation?.descendants) && isNestedData;
47
48
  const propRowSelectionModel = React.useMemo(() => {
48
49
  return props.rowSelectionModel;
49
50
  }, [props.rowSelectionModel]);
@@ -62,7 +63,6 @@ export const useGridRowSelection = (apiRef, props) => {
62
63
  } = props;
63
64
  const canHaveMultipleSelection = isMultipleRowSelectionEnabled(props);
64
65
  const tree = useGridSelector(apiRef, gridRowTreeSelector);
65
- const isNestedData = useGridSelector(apiRef, gridRowMaximumTreeDepthSelector) > 1;
66
66
  const expandMouseRowRangeSelection = React.useCallback(id => {
67
67
  let endId = id;
68
68
  const startId = lastRowToggled.current ?? id;
@@ -137,6 +137,11 @@ export const findRowsToSelect = (apiRef, tree, selectedRow, autoSelectDescendant
137
137
  }
138
138
  }
139
139
  };
140
+ // For root level rows, we don't need to traverse parents
141
+ const rowNode = tree[selectedRow];
142
+ if (!rowNode || rowNode.parent === GRID_ROOT_GROUP_ID) {
143
+ return;
144
+ }
140
145
  traverseParents(selectedRow);
141
146
  }
142
147
  };
@@ -1,12 +1,6 @@
1
+ import type { HeightEntry } from '@mui/x-virtualizer/models';
1
2
  import { GridRowId } from "../../../models/gridRows.js";
2
- export type HeightEntry = {
3
- content: number;
4
- spacingTop: number;
5
- spacingBottom: number;
6
- detail: number;
7
- autoHeight: boolean;
8
- needsFirstMeasurement: boolean;
9
- };
3
+ export type { HeightEntry } from '@mui/x-virtualizer/models';
10
4
  export type HeightCache = Map<GridRowId, HeightEntry>;
11
5
  export interface GridRowsMetaInternalCache {
12
6
  /**
@@ -1,21 +1,5 @@
1
+ import { RowsMetaState } from '@mui/x-virtualizer/models';
1
2
  /**
2
3
  * The grid rows total height and row positions.
3
4
  */
4
- export interface GridRowsMetaState {
5
- /**
6
- * The sum of all visible grid rows in the current rows.
7
- */
8
- currentPageTotalHeight: number;
9
- /**
10
- * The grid rows positions.
11
- */
12
- positions: number[];
13
- /**
14
- * The total height of the pinned top rows.
15
- */
16
- pinnedTopRowsTotalHeight: number;
17
- /**
18
- * The total height of the pinned bottom rows.
19
- */
20
- pinnedBottomRowsTotalHeight: number;
21
- }
5
+ export interface GridRowsMetaState extends RowsMetaState {}
@@ -9,7 +9,9 @@ export const useGridRowAriaAttributes = () => {
9
9
  const ariaAttributes = {};
10
10
  const ariaRowIndex = index + headerGroupingMaxDepth + 2; // 1 for the header row and 1 as it's 1-based
11
11
  ariaAttributes['aria-rowindex'] = ariaRowIndex;
12
- if (apiRef.current.isRowSelectable(rowNode.id)) {
12
+
13
+ // XXX: fix this properly
14
+ if (rowNode && apiRef.current.isRowSelectable(rowNode.id)) {
13
15
  ariaAttributes['aria-selected'] = apiRef.current.isRowSelected(rowNode.id);
14
16
  }
15
17
  return ariaAttributes;
@@ -1,19 +1,9 @@
1
1
  import { RefObject } from '@mui/x-internals/types';
2
- import type { GridColDef } from "../../../models/colDef/index.js";
3
- import type { GridRowId } from "../../../models/gridRows.js";
2
+ import { RowSpanningState } from '@mui/x-virtualizer/models';
4
3
  import type { DataGridProcessedProps } from "../../../models/props/DataGridProps.js";
5
4
  import type { GridPrivateApiCommunity } from "../../../models/api/gridApiCommunity.js";
6
5
  import type { GridStateInitializer } from "../../utils/useGridInitializeState.js";
7
- export interface GridRowSpanningState {
8
- spannedCells: Record<GridRowId, Record<GridColDef['field'], number>>;
9
- hiddenCells: Record<GridRowId, Record<GridColDef['field'], boolean>>;
10
- /**
11
- * For each hidden cell, it contains the row index corresponding to the cell that is
12
- * the origin of the hidden cell. i.e. the cell which is spanned.
13
- * Used by the virtualization to properly keep the spanned cells in view.
14
- */
15
- hiddenCellOriginMap: Record<number, Record<GridColDef['field'], number>>;
16
- }
6
+ export interface GridRowSpanningState extends RowSpanningState {}
17
7
  export type RowRange = {
18
8
  firstRowIndex: number;
19
9
  lastRowIndex: number;