@mui/x-data-grid 7.20.0 → 7.22.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 (186) hide show
  1. package/CHANGELOG.md +200 -31
  2. package/DataGrid/DataGrid.js +1 -0
  3. package/DataGrid/index.d.ts +0 -1
  4. package/DataGrid/index.js +1 -2
  5. package/DataGrid/useDataGridComponent.js +4 -1
  6. package/DataGrid/useDataGridProps.d.ts +1 -5
  7. package/DataGrid/useDataGridProps.js +3 -62
  8. package/components/GridPagination.js +1 -0
  9. package/components/GridRow.js +25 -36
  10. package/components/base/GridOverlays.js +8 -0
  11. package/components/cell/GridBooleanCell.d.ts +3 -3
  12. package/components/cell/GridBooleanCell.js +11 -1
  13. package/components/columnHeaders/GridColumnHeaderFilterIconButton.js +1 -2
  14. package/components/columnHeaders/GridColumnHeaderSortIcon.js +1 -2
  15. package/components/containers/GridRootStyles.js +5 -2
  16. package/components/menu/columnMenu/GridColumnMenu.js +32 -0
  17. package/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
  18. package/components/panel/filterPanel/GridFilterInputMultipleValue.js +2 -2
  19. package/components/panel/filterPanel/GridFilterInputValue.js +2 -2
  20. package/components/toolbar/GridToolbar.js +2 -3
  21. package/components/toolbar/GridToolbarExport.d.ts +9 -3
  22. package/components/toolbar/GridToolbarExport.js +43 -3
  23. package/components/toolbar/GridToolbarFilterButton.js +1 -2
  24. package/components/virtualization/GridBottomContainer.js +0 -17
  25. package/components/virtualization/GridMainContainer.js +2 -1
  26. package/components/virtualization/GridVirtualScrollbar.js +4 -0
  27. package/components/virtualization/GridVirtualScroller.js +4 -2
  28. package/constants/dataGridPropsDefaultValues.d.ts +5 -0
  29. package/constants/dataGridPropsDefaultValues.js +60 -0
  30. package/constants/gridClasses.d.ts +5 -0
  31. package/constants/gridClasses.js +1 -1
  32. package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +6 -1
  33. package/hooks/features/clipboard/useGridClipboard.js +2 -1
  34. package/hooks/features/columnHeaders/useGridColumnHeaders.js +3 -1
  35. package/hooks/features/columnMenu/useGridColumnMenuSlots.js +4 -3
  36. package/hooks/features/columns/gridColumnsUtils.d.ts +1 -1
  37. package/hooks/features/columns/gridColumnsUtils.js +3 -0
  38. package/hooks/features/dimensions/useGridDimensions.js +4 -2
  39. package/hooks/features/focus/useGridFocus.js +18 -3
  40. package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.d.ts +1 -1
  41. package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +9 -5
  42. package/hooks/features/listView/gridListViewSelectors.d.ts +5 -0
  43. package/hooks/features/listView/gridListViewSelectors.js +4 -0
  44. package/hooks/features/listView/useGridListView.d.ts +10 -0
  45. package/hooks/features/listView/useGridListView.js +54 -0
  46. package/hooks/features/pagination/gridPaginationSelector.js +2 -1
  47. package/hooks/features/rowSelection/useGridRowSelection.js +11 -2
  48. package/hooks/features/rowSelection/utils.js +1 -1
  49. package/hooks/features/rows/gridRowsMetaInterfaces.d.ts +16 -0
  50. package/hooks/features/rows/gridRowsMetaInterfaces.js +1 -0
  51. package/hooks/features/rows/gridRowsUtils.d.ts +3 -0
  52. package/hooks/features/rows/gridRowsUtils.js +14 -1
  53. package/hooks/features/rows/useGridParamsApi.d.ts +2 -1
  54. package/hooks/features/rows/useGridParamsApi.js +4 -3
  55. package/hooks/features/rows/useGridRowsMeta.js +135 -154
  56. package/hooks/features/scroll/useGridScroll.d.ts +1 -1
  57. package/hooks/features/scroll/useGridScroll.js +3 -2
  58. package/hooks/features/virtualization/useGridVirtualScroller.js +25 -10
  59. package/hooks/utils/useGridApiMethod.js +2 -1
  60. package/index.d.ts +1 -0
  61. package/index.js +2 -1
  62. package/internals/index.d.ts +2 -1
  63. package/internals/index.js +2 -1
  64. package/joy/joySlots.js +45 -27
  65. package/locales/daDK.js +5 -6
  66. package/locales/itIT.js +27 -28
  67. package/locales/ptBR.js +4 -4
  68. package/material/index.js +4 -0
  69. package/models/api/gridRowsMetaApi.d.ts +15 -14
  70. package/models/colDef/gridColDef.d.ts +6 -0
  71. package/models/colDef/index.d.ts +1 -1
  72. package/models/gridApiCaches.d.ts +2 -0
  73. package/models/gridExport.d.ts +1 -1
  74. package/models/gridSlotsComponent.d.ts +10 -0
  75. package/models/gridSlotsComponentsProps.d.ts +9 -0
  76. package/models/gridStateCommunity.d.ts +2 -0
  77. package/models/props/DataGridProps.d.ts +14 -3
  78. package/modern/DataGrid/DataGrid.js +1 -0
  79. package/modern/DataGrid/index.js +1 -2
  80. package/modern/DataGrid/useDataGridComponent.js +4 -1
  81. package/modern/DataGrid/useDataGridProps.js +3 -62
  82. package/modern/components/GridPagination.js +1 -0
  83. package/modern/components/GridRow.js +25 -36
  84. package/modern/components/base/GridOverlays.js +8 -0
  85. package/modern/components/cell/GridBooleanCell.js +11 -1
  86. package/modern/components/columnHeaders/GridColumnHeaderFilterIconButton.js +1 -2
  87. package/modern/components/columnHeaders/GridColumnHeaderSortIcon.js +1 -2
  88. package/modern/components/containers/GridRootStyles.js +5 -2
  89. package/modern/components/menu/columnMenu/GridColumnMenu.js +32 -0
  90. package/modern/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
  91. package/modern/components/panel/filterPanel/GridFilterInputMultipleValue.js +2 -2
  92. package/modern/components/panel/filterPanel/GridFilterInputValue.js +2 -2
  93. package/modern/components/toolbar/GridToolbar.js +2 -3
  94. package/modern/components/toolbar/GridToolbarExport.js +43 -3
  95. package/modern/components/toolbar/GridToolbarFilterButton.js +1 -2
  96. package/modern/components/virtualization/GridBottomContainer.js +0 -17
  97. package/modern/components/virtualization/GridMainContainer.js +2 -1
  98. package/modern/components/virtualization/GridVirtualScrollbar.js +4 -0
  99. package/modern/components/virtualization/GridVirtualScroller.js +4 -2
  100. package/modern/constants/dataGridPropsDefaultValues.js +60 -0
  101. package/modern/constants/gridClasses.js +1 -1
  102. package/modern/hooks/features/clipboard/useGridClipboard.js +2 -1
  103. package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +3 -1
  104. package/modern/hooks/features/columnMenu/useGridColumnMenuSlots.js +4 -3
  105. package/modern/hooks/features/columns/gridColumnsUtils.js +3 -0
  106. package/modern/hooks/features/dimensions/useGridDimensions.js +4 -2
  107. package/modern/hooks/features/focus/useGridFocus.js +18 -3
  108. package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +9 -5
  109. package/modern/hooks/features/listView/gridListViewSelectors.js +4 -0
  110. package/modern/hooks/features/listView/useGridListView.js +54 -0
  111. package/modern/hooks/features/pagination/gridPaginationSelector.js +2 -1
  112. package/modern/hooks/features/rowSelection/useGridRowSelection.js +11 -2
  113. package/modern/hooks/features/rowSelection/utils.js +1 -1
  114. package/modern/hooks/features/rows/gridRowsMetaInterfaces.js +1 -0
  115. package/modern/hooks/features/rows/gridRowsUtils.js +14 -1
  116. package/modern/hooks/features/rows/useGridParamsApi.js +4 -3
  117. package/modern/hooks/features/rows/useGridRowsMeta.js +135 -154
  118. package/modern/hooks/features/scroll/useGridScroll.js +3 -2
  119. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +25 -10
  120. package/modern/hooks/utils/useGridApiMethod.js +2 -1
  121. package/modern/index.js +2 -1
  122. package/modern/internals/index.js +2 -1
  123. package/modern/joy/joySlots.js +45 -27
  124. package/modern/locales/daDK.js +5 -6
  125. package/modern/locales/itIT.js +27 -28
  126. package/modern/locales/ptBR.js +4 -4
  127. package/modern/material/index.js +4 -0
  128. package/modern/utils/ResizeObserver.js +10 -0
  129. package/modern/utils/keyboardUtils.js +12 -4
  130. package/node/DataGrid/DataGrid.js +1 -0
  131. package/node/DataGrid/index.js +1 -12
  132. package/node/DataGrid/useDataGridComponent.js +4 -1
  133. package/node/DataGrid/useDataGridProps.js +6 -65
  134. package/node/components/GridPagination.js +1 -0
  135. package/node/components/GridRow.js +25 -36
  136. package/node/components/base/GridOverlays.js +8 -0
  137. package/node/components/cell/GridBooleanCell.js +11 -1
  138. package/node/components/columnHeaders/GridColumnHeaderFilterIconButton.js +1 -2
  139. package/node/components/columnHeaders/GridColumnHeaderSortIcon.js +1 -2
  140. package/node/components/containers/GridRootStyles.js +5 -2
  141. package/node/components/menu/columnMenu/GridColumnMenu.js +32 -0
  142. package/node/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
  143. package/node/components/panel/filterPanel/GridFilterInputMultipleValue.js +2 -2
  144. package/node/components/panel/filterPanel/GridFilterInputValue.js +2 -2
  145. package/node/components/toolbar/GridToolbar.js +2 -3
  146. package/node/components/toolbar/GridToolbarExport.js +40 -0
  147. package/node/components/toolbar/GridToolbarFilterButton.js +1 -2
  148. package/node/components/virtualization/GridBottomContainer.js +0 -17
  149. package/node/components/virtualization/GridMainContainer.js +2 -1
  150. package/node/components/virtualization/GridVirtualScrollbar.js +4 -0
  151. package/node/components/virtualization/GridVirtualScroller.js +4 -2
  152. package/node/constants/dataGridPropsDefaultValues.js +66 -0
  153. package/node/constants/gridClasses.js +1 -1
  154. package/node/hooks/features/clipboard/useGridClipboard.js +2 -1
  155. package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +3 -1
  156. package/node/hooks/features/columnMenu/useGridColumnMenuSlots.js +4 -3
  157. package/node/hooks/features/columns/gridColumnsUtils.js +3 -0
  158. package/node/hooks/features/dimensions/useGridDimensions.js +3 -1
  159. package/node/hooks/features/focus/useGridFocus.js +18 -3
  160. package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +9 -5
  161. package/node/hooks/features/listView/gridListViewSelectors.js +11 -0
  162. package/node/hooks/features/listView/useGridListView.js +64 -0
  163. package/node/hooks/features/pagination/gridPaginationSelector.js +3 -1
  164. package/node/hooks/features/rowSelection/useGridRowSelection.js +11 -2
  165. package/node/hooks/features/rowSelection/utils.js +1 -1
  166. package/node/hooks/features/rows/gridRowsMetaInterfaces.js +5 -0
  167. package/node/hooks/features/rows/gridRowsUtils.js +16 -2
  168. package/node/hooks/features/rows/useGridParamsApi.js +4 -3
  169. package/node/hooks/features/rows/useGridRowsMeta.js +136 -154
  170. package/node/hooks/features/scroll/useGridScroll.js +3 -2
  171. package/node/hooks/features/virtualization/useGridVirtualScroller.js +25 -10
  172. package/node/hooks/utils/useGridApiMethod.js +3 -1
  173. package/node/index.js +13 -1
  174. package/node/internals/index.js +22 -0
  175. package/node/joy/joySlots.js +45 -27
  176. package/node/locales/daDK.js +5 -6
  177. package/node/locales/itIT.js +27 -28
  178. package/node/locales/ptBR.js +4 -4
  179. package/node/material/index.js +4 -0
  180. package/node/utils/ResizeObserver.js +16 -0
  181. package/node/utils/keyboardUtils.js +15 -5
  182. package/package.json +2 -2
  183. package/utils/ResizeObserver.d.ts +4 -0
  184. package/utils/ResizeObserver.js +10 -0
  185. package/utils/keyboardUtils.d.ts +1 -0
  186. package/utils/keyboardUtils.js +12 -4
@@ -1,7 +1,9 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
- import { unstable_debounce as debounce } from '@mui/utils';
3
+ import useLazyRef from '@mui/utils/useLazyRef';
4
+ import { ResizeObserver } from "../../../utils/ResizeObserver.js";
4
5
  import { useGridVisibleRows } from "../../utils/useGridVisibleRows.js";
6
+ import { eslintUseValue } from "../../../utils/utils.js";
5
7
  import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
6
8
  import { useGridSelector } from "../../utils/useGridSelector.js";
7
9
  import { gridDensityFactorSelector } from "../density/densitySelector.js";
@@ -10,29 +12,21 @@ import { gridPaginationSelector } from "../pagination/gridPaginationSelector.js"
10
12
  import { gridSortModelSelector } from "../sorting/gridSortingSelector.js";
11
13
  import { useGridRegisterPipeApplier } from "../../core/pipeProcessing/index.js";
12
14
  import { gridPinnedRowsSelector } from "./gridRowsSelector.js";
13
- import { DATA_GRID_PROPS_DEFAULT_VALUES } from "../../../DataGrid/useDataGridProps.js";
15
+ import { gridDimensionsSelector } from "../dimensions/gridDimensionsSelectors.js";
16
+ import { getValidRowHeight, getRowHeightWarning } from "./gridRowsUtils.js";
17
+ /* eslint-disable no-underscore-dangle */
14
18
 
15
- // TODO: I think the row heights can now be encoded as a single `size` instead of `sizes.baseXxxx`
16
-
17
- export const rowsMetaStateInitializer = state => _extends({}, state, {
18
- rowsMeta: {
19
- currentPageTotalHeight: 0,
20
- positions: []
21
- }
22
- });
23
- let warnedOnceInvalidRowHeight = false;
24
- const getValidRowHeight = (rowHeightProp, defaultRowHeight, warningMessage) => {
25
- if (typeof rowHeightProp === 'number' && rowHeightProp > 0) {
26
- return rowHeightProp;
27
- }
28
- if (process.env.NODE_ENV !== 'production' && !warnedOnceInvalidRowHeight && typeof rowHeightProp !== 'undefined' && rowHeightProp !== null) {
29
- console.warn(warningMessage);
30
- warnedOnceInvalidRowHeight = true;
31
- }
32
- return defaultRowHeight;
19
+ export const rowsMetaStateInitializer = (state, props, apiRef) => {
20
+ apiRef.current.caches.rowsMeta = {
21
+ heights: new Map()
22
+ };
23
+ return _extends({}, state, {
24
+ rowsMeta: {
25
+ currentPageTotalHeight: 0,
26
+ positions: []
27
+ }
28
+ });
33
29
  };
34
- const rowHeightWarning = [`MUI X: The \`rowHeight\` prop should be a number greater than 0.`, `The default value will be used instead.`].join('\n');
35
- const getRowHeightWarning = [`MUI X: The \`getRowHeight\` prop should return a number greater than 0 or 'auto'.`, `The default value will be used instead.`].join('\n');
36
30
 
37
31
  /**
38
32
  * @requires useGridPageSize (method)
@@ -44,105 +38,94 @@ export const useGridRowsMeta = (apiRef, props) => {
44
38
  getRowSpacing,
45
39
  getEstimatedRowHeight
46
40
  } = props;
47
- const rowsHeightLookup = React.useRef(Object.create(null));
48
-
49
- // Inspired by https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/utils/CellSizeAndPositionManager.js
41
+ const heightCache = apiRef.current.caches.rowsMeta.heights;
50
42
  const lastMeasuredRowIndex = React.useRef(-1);
51
43
  const hasRowWithAutoHeight = React.useRef(false);
44
+ const isHeightMetaValid = React.useRef(false);
52
45
  const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
53
46
  const filterModel = useGridSelector(apiRef, gridFilterModelSelector);
54
47
  const paginationState = useGridSelector(apiRef, gridPaginationSelector);
55
48
  const sortModel = useGridSelector(apiRef, gridSortModelSelector);
56
49
  const currentPage = useGridVisibleRows(apiRef, props);
57
50
  const pinnedRows = useGridSelector(apiRef, gridPinnedRowsSelector);
58
- const validRowHeight = getValidRowHeight(props.rowHeight, DATA_GRID_PROPS_DEFAULT_VALUES.rowHeight, rowHeightWarning);
59
- const rowHeight = Math.floor(validRowHeight * densityFactor);
60
- const hydrateRowsMeta = React.useCallback(() => {
61
- hasRowWithAutoHeight.current = false;
62
- const calculateRowProcessedSizes = row => {
63
- if (!rowsHeightLookup.current[row.id]) {
64
- rowsHeightLookup.current[row.id] = {
65
- sizes: {
66
- baseCenter: rowHeight
67
- },
68
- isResized: false,
69
- autoHeight: false,
70
- needsFirstMeasurement: true // Assume all rows will need to be measured by default
71
- };
72
- }
73
- const {
74
- isResized,
75
- needsFirstMeasurement,
76
- sizes
77
- } = rowsHeightLookup.current[row.id];
78
- let baseRowHeight = typeof rowHeight === 'number' && rowHeight > 0 ? rowHeight : 52;
79
- const existingBaseRowHeight = sizes.baseCenter;
80
- if (isResized) {
81
- // Do not recalculate resized row height and use the value from the lookup
82
- baseRowHeight = existingBaseRowHeight;
83
- } else if (getRowHeightProp) {
84
- const rowHeightFromUser = getRowHeightProp(_extends({}, row, {
85
- densityFactor
86
- }));
87
- if (rowHeightFromUser === 'auto') {
88
- if (needsFirstMeasurement) {
89
- const estimatedRowHeight = getEstimatedRowHeight ? getEstimatedRowHeight(_extends({}, row, {
90
- densityFactor
91
- })) : rowHeight;
51
+ const rowHeight = useGridSelector(apiRef, () => gridDimensionsSelector(apiRef.current.state).rowHeight);
52
+ const getRowHeightEntry = rowId => {
53
+ let entry = heightCache.get(rowId);
54
+ if (entry === undefined) {
55
+ entry = {
56
+ content: rowHeight,
57
+ spacingTop: 0,
58
+ spacingBottom: 0,
59
+ detail: 0,
60
+ autoHeight: false,
61
+ needsFirstMeasurement: true
62
+ };
63
+ heightCache.set(rowId, entry);
64
+ }
65
+ return entry;
66
+ };
67
+ const processHeightEntry = React.useCallback(row => {
68
+ // HACK: rowHeight trails behind the most up-to-date value just enough to
69
+ // mess the initial rowsMeta hydration :/
70
+ const baseRowHeight = gridDimensionsSelector(apiRef.current.state).rowHeight;
71
+ eslintUseValue(rowHeight);
72
+ const entry = apiRef.current.getRowHeightEntry(row.id);
73
+ if (!getRowHeightProp) {
74
+ entry.content = baseRowHeight;
75
+ entry.needsFirstMeasurement = false;
76
+ } else {
77
+ const rowHeightFromUser = getRowHeightProp(_extends({}, row, {
78
+ densityFactor
79
+ }));
80
+ if (rowHeightFromUser === 'auto') {
81
+ if (entry.needsFirstMeasurement) {
82
+ const estimatedRowHeight = getEstimatedRowHeight ? getEstimatedRowHeight(_extends({}, row, {
83
+ densityFactor
84
+ })) : baseRowHeight;
92
85
 
93
- // If the row was not measured yet use the estimated row height
94
- baseRowHeight = estimatedRowHeight ?? rowHeight;
95
- } else {
96
- baseRowHeight = existingBaseRowHeight;
97
- }
98
- hasRowWithAutoHeight.current = true;
99
- rowsHeightLookup.current[row.id].autoHeight = true;
100
- } else {
101
- // Default back to base rowHeight if getRowHeight returns invalid value.
102
- baseRowHeight = getValidRowHeight(rowHeightFromUser, rowHeight, getRowHeightWarning);
103
- rowsHeightLookup.current[row.id].needsFirstMeasurement = false;
104
- rowsHeightLookup.current[row.id].autoHeight = false;
86
+ // If the row was not measured yet use the estimated row height
87
+ entry.content = estimatedRowHeight ?? baseRowHeight;
105
88
  }
89
+ hasRowWithAutoHeight.current = true;
90
+ entry.autoHeight = true;
106
91
  } else {
107
- rowsHeightLookup.current[row.id].needsFirstMeasurement = false;
108
- }
109
- const initialHeights = {
110
- baseCenter: baseRowHeight
111
- };
112
- if (getRowSpacing) {
113
- const indexRelativeToCurrentPage = apiRef.current.getRowIndexRelativeToVisibleRows(row.id);
114
- const spacing = getRowSpacing(_extends({}, row, {
115
- isFirstVisible: indexRelativeToCurrentPage === 0,
116
- isLastVisible: indexRelativeToCurrentPage === currentPage.rows.length - 1,
117
- indexRelativeToCurrentPage
118
- }));
119
- initialHeights.spacingTop = spacing.top ?? 0;
120
- initialHeights.spacingBottom = spacing.bottom ?? 0;
92
+ // Default back to base rowHeight if getRowHeight returns invalid value.
93
+ entry.content = getValidRowHeight(rowHeightFromUser, baseRowHeight, getRowHeightWarning);
94
+ entry.needsFirstMeasurement = false;
95
+ entry.autoHeight = false;
121
96
  }
122
- const processedSizes = apiRef.current.unstable_applyPipeProcessors('rowHeight', initialHeights, row);
123
- rowsHeightLookup.current[row.id].sizes = processedSizes;
124
- return processedSizes;
125
- };
97
+ }
98
+ if (getRowSpacing) {
99
+ const indexRelativeToCurrentPage = apiRef.current.getRowIndexRelativeToVisibleRows(row.id);
100
+ const spacing = getRowSpacing(_extends({}, row, {
101
+ isFirstVisible: indexRelativeToCurrentPage === 0,
102
+ isLastVisible: indexRelativeToCurrentPage === currentPage.rows.length - 1,
103
+ indexRelativeToCurrentPage
104
+ }));
105
+ entry.spacingTop = spacing.top ?? 0;
106
+ entry.spacingBottom = spacing.bottom ?? 0;
107
+ } else {
108
+ entry.spacingTop = 0;
109
+ entry.spacingBottom = 0;
110
+ }
111
+ apiRef.current.unstable_applyPipeProcessors('rowHeight', entry, row);
112
+ return entry;
113
+ }, [apiRef, currentPage.rows.length, getRowHeightProp, getEstimatedRowHeight, rowHeight, getRowSpacing, densityFactor]);
114
+ const hydrateRowsMeta = React.useCallback(() => {
115
+ hasRowWithAutoHeight.current = false;
116
+ pinnedRows.top.forEach(processHeightEntry);
117
+ pinnedRows.bottom.forEach(processHeightEntry);
126
118
  const positions = [];
127
119
  const currentPageTotalHeight = currentPage.rows.reduce((acc, row) => {
128
120
  positions.push(acc);
129
- let otherSizes = 0;
130
- const processedSizes = calculateRowProcessedSizes(row);
131
- /* eslint-disable-next-line guard-for-in */
132
- for (const key in processedSizes) {
133
- const value = processedSizes[key];
134
- if (key !== 'baseCenter') {
135
- otherSizes += value;
136
- }
137
- }
138
- return acc + processedSizes.baseCenter + otherSizes;
121
+ const entry = processHeightEntry(row);
122
+ const total = entry.content + entry.spacingTop + entry.spacingBottom + entry.detail;
123
+ return acc + total;
139
124
  }, 0);
140
- pinnedRows?.top?.forEach(row => {
141
- calculateRowProcessedSizes(row);
142
- });
143
- pinnedRows?.bottom?.forEach(row => {
144
- calculateRowProcessedSizes(row);
145
- });
125
+ if (!hasRowWithAutoHeight.current) {
126
+ // No row has height=auto, so all rows are already measured
127
+ lastMeasuredRowIndex.current = Infinity;
128
+ }
146
129
  apiRef.current.setState(state => {
147
130
  return _extends({}, state, {
148
131
  rowsMeta: {
@@ -151,70 +134,68 @@ export const useGridRowsMeta = (apiRef, props) => {
151
134
  }
152
135
  });
153
136
  });
154
- if (!hasRowWithAutoHeight.current) {
155
- // No row has height=auto, so all rows are already measured
156
- lastMeasuredRowIndex.current = Infinity;
157
- }
158
- apiRef.current.forceUpdate();
159
- }, [apiRef, currentPage.rows, rowHeight, getRowHeightProp, getRowSpacing, getEstimatedRowHeight, pinnedRows, densityFactor]);
160
- const getRowHeight = React.useCallback(rowId => {
161
- const height = rowsHeightLookup.current[rowId];
162
- return height ? height.sizes.baseCenter : rowHeight;
163
- }, [rowHeight]);
164
- const getRowInternalSizes = rowId => rowsHeightLookup.current[rowId]?.sizes;
165
- const setRowHeight = React.useCallback((id, height) => {
166
- rowsHeightLookup.current[id].sizes.baseCenter = height;
167
- rowsHeightLookup.current[id].isResized = true;
168
- rowsHeightLookup.current[id].needsFirstMeasurement = false;
169
- hydrateRowsMeta();
170
- }, [hydrateRowsMeta]);
171
- const debouncedHydrateRowsMeta = React.useMemo(() => debounce(hydrateRowsMeta, props.rowPositionsDebounceMs), [hydrateRowsMeta, props.rowPositionsDebounceMs]);
172
- const storeMeasuredRowHeight = React.useCallback((id, height) => {
173
- if (!rowsHeightLookup.current[id] || !rowsHeightLookup.current[id].autoHeight) {
174
- return;
175
- }
176
-
177
- // Only trigger hydration if the value is different, otherwise we trigger a loop
178
- const needsHydration = rowsHeightLookup.current[id].sizes.baseCenter !== height;
179
- rowsHeightLookup.current[id].needsFirstMeasurement = false;
180
- rowsHeightLookup.current[id].sizes.baseCenter = height;
181
- if (needsHydration) {
182
- debouncedHydrateRowsMeta();
183
- }
184
- }, [debouncedHydrateRowsMeta]);
185
- const rowHasAutoHeight = React.useCallback(id => {
186
- return rowsHeightLookup.current[id]?.autoHeight || false;
187
- }, []);
188
- const getLastMeasuredRowIndex = React.useCallback(() => {
137
+ isHeightMetaValid.current = true;
138
+ }, [apiRef, pinnedRows, currentPage.rows, processHeightEntry]);
139
+ const getRowHeight = rowId => {
140
+ return heightCache.get(rowId)?.content ?? rowHeight;
141
+ };
142
+ const storeRowHeightMeasurement = (id, height) => {
143
+ const entry = apiRef.current.getRowHeightEntry(id);
144
+ const didChange = entry.content !== height;
145
+ entry.needsFirstMeasurement = false;
146
+ entry.content = height;
147
+ isHeightMetaValid.current &&= !didChange;
148
+ };
149
+ const rowHasAutoHeight = id => {
150
+ return heightCache.get(id)?.autoHeight ?? false;
151
+ };
152
+ const getLastMeasuredRowIndex = () => {
189
153
  return lastMeasuredRowIndex.current;
190
- }, []);
191
- const setLastMeasuredRowIndex = React.useCallback(index => {
154
+ };
155
+ const setLastMeasuredRowIndex = index => {
192
156
  if (hasRowWithAutoHeight.current && index > lastMeasuredRowIndex.current) {
193
157
  lastMeasuredRowIndex.current = index;
194
158
  }
195
- }, []);
196
- const resetRowHeights = React.useCallback(() => {
197
- rowsHeightLookup.current = {};
159
+ };
160
+ const resetRowHeights = () => {
161
+ heightCache.clear();
198
162
  hydrateRowsMeta();
199
- }, [hydrateRowsMeta]);
163
+ };
164
+ const resizeObserver = useLazyRef(() => new ResizeObserver(entries => {
165
+ for (let i = 0; i < entries.length; i += 1) {
166
+ const entry = entries[i];
167
+ const height = entry.borderBoxSize && entry.borderBoxSize.length > 0 ? entry.borderBoxSize[0].blockSize : entry.contentRect.height;
168
+ const rowId = entry.target.__mui_id;
169
+ apiRef.current.unstable_storeRowHeightMeasurement(rowId, height);
170
+ }
171
+ if (!isHeightMetaValid.current) {
172
+ apiRef.current.requestPipeProcessorsApplication('rowHeight');
173
+ }
174
+ })).current;
175
+ const observeRowHeight = (element, rowId) => {
176
+ element.__mui_id = rowId;
177
+ resizeObserver.observe(element);
178
+ return () => resizeObserver.unobserve(element);
179
+ };
180
+ useGridRegisterPipeApplier(apiRef, 'rowHeight', hydrateRowsMeta);
200
181
 
201
182
  // The effect is used to build the rows meta data - currentPageTotalHeight and positions.
202
183
  // Because of variable row height this is needed for the virtualization
203
184
  React.useEffect(() => {
204
185
  hydrateRowsMeta();
205
- }, [rowHeight, filterModel, paginationState, sortModel, hydrateRowsMeta]);
206
- useGridRegisterPipeApplier(apiRef, 'rowHeight', hydrateRowsMeta);
186
+ }, [filterModel, paginationState, sortModel, hydrateRowsMeta]);
207
187
  const rowsMetaApi = {
208
- unstable_setLastMeasuredRowIndex: setLastMeasuredRowIndex,
209
188
  unstable_getRowHeight: getRowHeight,
210
- unstable_getRowInternalSizes: getRowInternalSizes,
211
- unstable_setRowHeight: setRowHeight,
212
- unstable_storeRowHeightMeasurement: storeMeasuredRowHeight,
189
+ unstable_setLastMeasuredRowIndex: setLastMeasuredRowIndex,
190
+ unstable_storeRowHeightMeasurement: storeRowHeightMeasurement,
213
191
  resetRowHeights
214
192
  };
215
193
  const rowsMetaPrivateApi = {
216
- getLastMeasuredRowIndex,
217
- rowHasAutoHeight
194
+ hydrateRowsMeta,
195
+ observeRowHeight,
196
+ rowHasAutoHeight,
197
+ getRowHeightEntry,
198
+ getLastMeasuredRowIndex
218
199
  };
219
200
  useGridApiMethod(apiRef, rowsMetaApi, 'public');
220
201
  useGridApiMethod(apiRef, rowsMetaPrivateApi, 'private');
@@ -9,4 +9,4 @@ import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
9
9
  * @requires useGridFilter (state)
10
10
  * @requires useGridColumnSpanning (method)
11
11
  */
12
- export declare const useGridScroll: (apiRef: React.MutableRefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, "pagination">) => void;
12
+ export declare const useGridScroll: (apiRef: React.MutableRefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, "pagination" | "unstable_listView">) => void;
@@ -9,6 +9,7 @@ import { gridRowsMetaSelector } from "../rows/gridRowsMetaSelector.js";
9
9
  import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
10
10
  import { gridExpandedSortedRowEntriesSelector } from "../filter/gridFilterSelector.js";
11
11
  import { gridDimensionsSelector } from "../dimensions/index.js";
12
+ import { gridListColumnSelector } from "../listView/gridListViewSelectors.js";
12
13
 
13
14
  // Logic copied from https://www.w3.org/TR/wai-aria-practices/examples/listbox/js/listbox.js
14
15
  // Similar to https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
@@ -53,7 +54,7 @@ export const useGridScroll = (apiRef, props) => {
53
54
  const scrollToIndexes = React.useCallback(params => {
54
55
  const dimensions = gridDimensionsSelector(apiRef.current.state);
55
56
  const totalRowCount = gridRowCountSelector(apiRef);
56
- const visibleColumns = gridVisibleColumnDefinitionsSelector(apiRef);
57
+ const visibleColumns = props.unstable_listView ? [gridListColumnSelector(apiRef.current.state)] : gridVisibleColumnDefinitionsSelector(apiRef);
57
58
  const scrollToHeader = params.rowIndex == null;
58
59
  if (!scrollToHeader && totalRowCount === 0 || visibleColumns.length === 0) {
59
60
  return false;
@@ -100,7 +101,7 @@ export const useGridScroll = (apiRef, props) => {
100
101
  return true;
101
102
  }
102
103
  return false;
103
- }, [logger, apiRef, virtualScrollerRef, props.pagination, visibleSortedRows]);
104
+ }, [logger, apiRef, virtualScrollerRef, props.pagination, visibleSortedRows, props.unstable_listView]);
104
105
  const scroll = React.useCallback(params => {
105
106
  if (virtualScrollerRef.current && virtualScrollbarHorizontalRef.current && params.left !== undefined && colRef.current) {
106
107
  const direction = isRtl ? -1 : 1;
@@ -25,6 +25,7 @@ import { getMinimalContentHeight } from "../rows/gridRowsUtils.js";
25
25
  import { gridRenderContextSelector, gridVirtualizationRowEnabledSelector, gridVirtualizationColumnEnabledSelector } from "./gridVirtualizationSelectors.js";
26
26
  import { EMPTY_RENDER_CONTEXT } from "./useGridVirtualization.js";
27
27
  import { gridRowSpanningHiddenCellsOriginMapSelector } from "../rows/gridRowSpanningSelectors.js";
28
+ import { gridListColumnSelector } from "../listView/gridListViewSelectors.js";
28
29
  import { jsx as _jsx } from "react/jsx-runtime";
29
30
  const MINIMUM_COLUMN_WIDTH = 50;
30
31
  var ScrollDirection = /*#__PURE__*/function (ScrollDirection) {
@@ -55,13 +56,20 @@ try {
55
56
  export const useGridVirtualScroller = () => {
56
57
  const apiRef = useGridPrivateApiContext();
57
58
  const rootProps = useGridRootProps();
58
- const visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
59
+ const {
60
+ unstable_listView: listView
61
+ } = rootProps;
62
+ const visibleColumns = useGridSelector(apiRef, () => listView ? [gridListColumnSelector(apiRef.current.state)] : gridVisibleColumnDefinitionsSelector(apiRef));
59
63
  const enabledForRows = useGridSelector(apiRef, gridVirtualizationRowEnabledSelector) && !isJSDOM;
60
64
  const enabledForColumns = useGridSelector(apiRef, gridVirtualizationColumnEnabledSelector) && !isJSDOM;
61
65
  const dimensions = useGridSelector(apiRef, gridDimensionsSelector);
62
66
  const outerSize = dimensions.viewportOuterSize;
63
67
  const pinnedRows = useGridSelector(apiRef, gridPinnedRowsSelector);
64
- const pinnedColumns = useGridSelector(apiRef, gridVisiblePinnedColumnDefinitionsSelector);
68
+ const pinnedColumnDefinitions = useGridSelector(apiRef, gridVisiblePinnedColumnDefinitionsSelector);
69
+ const pinnedColumns = listView ? {
70
+ left: [],
71
+ right: []
72
+ } : pinnedColumnDefinitions;
65
73
  const hasBottomPinnedRows = pinnedRows.bottom.length > 0;
66
74
  const [panels, setPanels] = React.useState(EMPTY_DETAIL_PANELS);
67
75
  const isRtl = useRtl();
@@ -128,7 +136,7 @@ export const useGridVirtualScroller = () => {
128
136
  }
129
137
  previousContextScrollPosition.current = scrollPosition.current;
130
138
  }, [apiRef, dimensions.isReady]);
131
- const triggerUpdateRenderContext = () => {
139
+ const triggerUpdateRenderContext = useEventCallback(() => {
132
140
  const newScroll = {
133
141
  top: scrollerRef.current.scrollTop,
134
142
  left: scrollerRef.current.scrollLeft
@@ -176,7 +184,7 @@ export const useGridVirtualScroller = () => {
176
184
  });
177
185
  scrollTimeout.start(1000, triggerUpdateRenderContext);
178
186
  return nextRenderContext;
179
- };
187
+ });
180
188
  const forceUpdateRenderContext = () => {
181
189
  const inputs = inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns);
182
190
  const nextRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
@@ -362,15 +370,16 @@ export const useGridVirtualScroller = () => {
362
370
  });
363
371
  return rows;
364
372
  };
365
- const needsHorizontalScrollbar = outerSize.width && columnsTotalWidth >= outerSize.width;
373
+ const needsHorizontalScrollbar = outerSize.width && columnsTotalWidth > outerSize.width;
366
374
  const scrollerStyle = React.useMemo(() => ({
367
- overflowX: !needsHorizontalScrollbar ? 'hidden' : undefined,
375
+ overflowX: !needsHorizontalScrollbar || listView ? 'hidden' : undefined,
368
376
  overflowY: rootProps.autoHeight ? 'hidden' : undefined
369
- }), [needsHorizontalScrollbar, rootProps.autoHeight]);
377
+ }), [needsHorizontalScrollbar, rootProps.autoHeight, listView]);
370
378
  const contentSize = React.useMemo(() => {
371
379
  const size = {
372
380
  width: needsHorizontalScrollbar ? columnsTotalWidth : 'auto',
373
- height: contentHeight
381
+ flexBasis: contentHeight,
382
+ flexShrink: 0
374
383
  };
375
384
  if (rootProps.autoHeight && currentPage.rows.length === 0) {
376
385
  size.height = getMinimalContentHeight(apiRef); // Give room to show the overlay when there no rows.
@@ -393,6 +402,11 @@ export const useGridVirtualScroller = () => {
393
402
  scrollerRef.current.scrollTop = 0;
394
403
  }
395
404
  }, [enabledForColumns, enabledForRows, gridRootRef, scrollerRef]);
405
+ useEnhancedEffect(() => {
406
+ if (listView) {
407
+ scrollerRef.current.scrollLeft = 0;
408
+ }
409
+ }, [listView, scrollerRef]);
396
410
  useRunOnce(outerSize.width !== 0, () => {
397
411
  const inputs = inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns);
398
412
  const initialRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
@@ -447,7 +461,7 @@ export const useGridVirtualScroller = () => {
447
461
  function inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns) {
448
462
  const dimensions = gridDimensionsSelector(apiRef.current.state);
449
463
  const currentPage = getVisibleRows(apiRef, rootProps);
450
- const visibleColumns = gridVisibleColumnDefinitionsSelector(apiRef);
464
+ const visibleColumns = rootProps.unstable_listView ? [gridListColumnSelector(apiRef.current.state)] : gridVisibleColumnDefinitionsSelector(apiRef);
451
465
  const hiddenCellsOriginMap = gridRowSpanningHiddenCellsOriginMapSelector(apiRef);
452
466
  const lastRowId = apiRef.current.state.rows.dataRowIds.at(-1);
453
467
  const lastColumn = visibleColumns.at(-1);
@@ -470,7 +484,8 @@ function inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns) {
470
484
  range: currentPage.range,
471
485
  pinnedColumns: gridVisiblePinnedColumnDefinitionsSelector(apiRef),
472
486
  visibleColumns,
473
- hiddenCellsOriginMap
487
+ hiddenCellsOriginMap,
488
+ listView: rootProps.unstable_listView ?? false
474
489
  };
475
490
  }
476
491
  function computeRenderContext(inputs, scrollPosition, scrollCache) {
@@ -1,7 +1,8 @@
1
1
  import * as React from 'react';
2
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
2
3
  export function useGridApiMethod(privateApiRef, apiMethods, visibility) {
3
4
  const isFirstRender = React.useRef(true);
4
- React.useEffect(() => {
5
+ useEnhancedEffect(() => {
5
6
  isFirstRender.current = false;
6
7
  privateApiRef.current.register(visibility, apiMethods);
7
8
  }, [privateApiRef, visibility, apiMethods]);
package/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export { useGridRootProps } from './hooks/utils/useGridRootProps';
6
6
  export * from './DataGrid';
7
7
  export * from './components';
8
8
  export * from './constants';
9
+ export * from './constants/dataGridPropsDefaultValues';
9
10
  export * from './hooks';
10
11
  export * from './models';
11
12
  export * from './context';
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v7.20.0
2
+ * @mui/x-data-grid v7.22.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -11,6 +11,7 @@ export { useGridRootProps } from "./hooks/utils/useGridRootProps.js";
11
11
  export * from "./DataGrid/index.js";
12
12
  export * from "./components/index.js";
13
13
  export * from "./constants/index.js";
14
+ export * from "./constants/dataGridPropsDefaultValues.js";
14
15
  export * from "./hooks/index.js";
15
16
  export * from "./models/index.js";
16
17
  export * from "./context/index.js";
@@ -66,6 +66,7 @@ export { useGridVirtualScroller, EMPTY_DETAIL_PANELS, } from '../hooks/features/
66
66
  export * from '../hooks/features/virtualization';
67
67
  export { useGridColumnResize, columnResizeStateInitializer, } from '../hooks/features/columnResize/useGridColumnResize';
68
68
  export { ROW_SELECTION_PROPAGATION_DEFAULT } from '../hooks/features/rowSelection/utils';
69
+ export { useGridListView, listViewStateInitializer, } from '../hooks/features/listView/useGridListView';
69
70
  export { useTimeout } from '../hooks/utils/useTimeout';
70
71
  export { useGridVisibleRows, getVisibleRows } from '../hooks/utils/useGridVisibleRows';
71
72
  export { useGridInitializeState } from '../hooks/utils/useGridInitializeState';
@@ -78,7 +79,7 @@ export { createSelector, createSelectorV8, createSelectorMemoized, createSelecto
78
79
  export { useGridSelectorV8 } from '../hooks/utils/useGridSelector';
79
80
  export { gridRowGroupsToFetchSelector } from '../hooks/features/rows/gridRowsSelector';
80
81
  export { findParentElementFromClassName, getActiveElement, isEventTargetInPortal, } from '../utils/domUtils';
81
- export { isNavigationKey, isPasteShortcut } from '../utils/keyboardUtils';
82
+ export { isNavigationKey, isPasteShortcut, isCopyShortcut } from '../utils/keyboardUtils';
82
83
  export * from '../utils/utils';
83
84
  export { exportAs } from '../utils/exportAs';
84
85
  export * from '../utils/getPublicApiRef';
@@ -54,6 +54,7 @@ export { useGridVirtualScroller, EMPTY_DETAIL_PANELS } from "../hooks/features/v
54
54
  export * from "../hooks/features/virtualization/index.js";
55
55
  export { useGridColumnResize, columnResizeStateInitializer } from "../hooks/features/columnResize/useGridColumnResize.js";
56
56
  export { ROW_SELECTION_PROPAGATION_DEFAULT } from "../hooks/features/rowSelection/utils.js";
57
+ export { useGridListView, listViewStateInitializer } from "../hooks/features/listView/useGridListView.js";
57
58
  export { useTimeout } from "../hooks/utils/useTimeout.js";
58
59
  export { useGridVisibleRows, getVisibleRows } from "../hooks/utils/useGridVisibleRows.js";
59
60
  export { useGridInitializeState } from "../hooks/utils/useGridInitializeState.js";
@@ -63,7 +64,7 @@ export { createSelector, createSelectorV8, createSelectorMemoized, createSelecto
63
64
  export { useGridSelectorV8 } from "../hooks/utils/useGridSelector.js";
64
65
  export { gridRowGroupsToFetchSelector } from "../hooks/features/rows/gridRowsSelector.js";
65
66
  export { findParentElementFromClassName, getActiveElement, isEventTargetInPortal } from "../utils/domUtils.js";
66
- export { isNavigationKey, isPasteShortcut } from "../utils/keyboardUtils.js";
67
+ export { isNavigationKey, isPasteShortcut, isCopyShortcut } from "../utils/keyboardUtils.js";
67
68
  export * from "../utils/utils.js";
68
69
  export { exportAs } from "../utils/exportAs.js";
69
70
  export * from "../utils/getPublicApiRef.js";