@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
@@ -8,8 +8,10 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.useGridRowsMeta = exports.rowsMetaStateInitializer = void 0;
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
10
  var React = _interopRequireWildcard(require("react"));
11
- var _utils = require("@mui/utils");
11
+ var _useLazyRef = _interopRequireDefault(require("@mui/utils/useLazyRef"));
12
+ var _ResizeObserver = require("../../../utils/ResizeObserver");
12
13
  var _useGridVisibleRows = require("../../utils/useGridVisibleRows");
14
+ var _utils = require("../../../utils/utils");
13
15
  var _useGridApiMethod = require("../../utils/useGridApiMethod");
14
16
  var _useGridSelector = require("../../utils/useGridSelector");
15
17
  var _densitySelector = require("../density/densitySelector");
@@ -18,139 +20,121 @@ var _gridPaginationSelector = require("../pagination/gridPaginationSelector");
18
20
  var _gridSortingSelector = require("../sorting/gridSortingSelector");
19
21
  var _pipeProcessing = require("../../core/pipeProcessing");
20
22
  var _gridRowsSelector = require("./gridRowsSelector");
21
- var _useDataGridProps = require("../../../DataGrid/useDataGridProps");
22
- // TODO: I think the row heights can now be encoded as a single `size` instead of `sizes.baseXxxx`
23
+ var _gridDimensionsSelectors = require("../dimensions/gridDimensionsSelectors");
24
+ var _gridRowsUtils = require("./gridRowsUtils");
25
+ /* eslint-disable no-underscore-dangle */
23
26
 
24
- const rowsMetaStateInitializer = state => (0, _extends2.default)({}, state, {
25
- rowsMeta: {
26
- currentPageTotalHeight: 0,
27
- positions: []
28
- }
29
- });
30
- exports.rowsMetaStateInitializer = rowsMetaStateInitializer;
31
- let warnedOnceInvalidRowHeight = false;
32
- const getValidRowHeight = (rowHeightProp, defaultRowHeight, warningMessage) => {
33
- if (typeof rowHeightProp === 'number' && rowHeightProp > 0) {
34
- return rowHeightProp;
35
- }
36
- if (process.env.NODE_ENV !== 'production' && !warnedOnceInvalidRowHeight && typeof rowHeightProp !== 'undefined' && rowHeightProp !== null) {
37
- console.warn(warningMessage);
38
- warnedOnceInvalidRowHeight = true;
39
- }
40
- return defaultRowHeight;
27
+ const rowsMetaStateInitializer = (state, props, apiRef) => {
28
+ apiRef.current.caches.rowsMeta = {
29
+ heights: new Map()
30
+ };
31
+ return (0, _extends2.default)({}, state, {
32
+ rowsMeta: {
33
+ currentPageTotalHeight: 0,
34
+ positions: []
35
+ }
36
+ });
41
37
  };
42
- const rowHeightWarning = [`MUI X: The \`rowHeight\` prop should be a number greater than 0.`, `The default value will be used instead.`].join('\n');
43
- 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');
44
38
 
45
39
  /**
46
40
  * @requires useGridPageSize (method)
47
41
  * @requires useGridPage (method)
48
42
  */
43
+ exports.rowsMetaStateInitializer = rowsMetaStateInitializer;
49
44
  const useGridRowsMeta = (apiRef, props) => {
50
45
  const {
51
46
  getRowHeight: getRowHeightProp,
52
47
  getRowSpacing,
53
48
  getEstimatedRowHeight
54
49
  } = props;
55
- const rowsHeightLookup = React.useRef(Object.create(null));
56
-
57
- // Inspired by https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/utils/CellSizeAndPositionManager.js
50
+ const heightCache = apiRef.current.caches.rowsMeta.heights;
58
51
  const lastMeasuredRowIndex = React.useRef(-1);
59
52
  const hasRowWithAutoHeight = React.useRef(false);
53
+ const isHeightMetaValid = React.useRef(false);
60
54
  const densityFactor = (0, _useGridSelector.useGridSelector)(apiRef, _densitySelector.gridDensityFactorSelector);
61
55
  const filterModel = (0, _useGridSelector.useGridSelector)(apiRef, _gridFilterSelector.gridFilterModelSelector);
62
56
  const paginationState = (0, _useGridSelector.useGridSelector)(apiRef, _gridPaginationSelector.gridPaginationSelector);
63
57
  const sortModel = (0, _useGridSelector.useGridSelector)(apiRef, _gridSortingSelector.gridSortModelSelector);
64
58
  const currentPage = (0, _useGridVisibleRows.useGridVisibleRows)(apiRef, props);
65
59
  const pinnedRows = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowsSelector.gridPinnedRowsSelector);
66
- const validRowHeight = getValidRowHeight(props.rowHeight, _useDataGridProps.DATA_GRID_PROPS_DEFAULT_VALUES.rowHeight, rowHeightWarning);
67
- const rowHeight = Math.floor(validRowHeight * densityFactor);
68
- const hydrateRowsMeta = React.useCallback(() => {
69
- hasRowWithAutoHeight.current = false;
70
- const calculateRowProcessedSizes = row => {
71
- if (!rowsHeightLookup.current[row.id]) {
72
- rowsHeightLookup.current[row.id] = {
73
- sizes: {
74
- baseCenter: rowHeight
75
- },
76
- isResized: false,
77
- autoHeight: false,
78
- needsFirstMeasurement: true // Assume all rows will need to be measured by default
79
- };
80
- }
81
- const {
82
- isResized,
83
- needsFirstMeasurement,
84
- sizes
85
- } = rowsHeightLookup.current[row.id];
86
- let baseRowHeight = typeof rowHeight === 'number' && rowHeight > 0 ? rowHeight : 52;
87
- const existingBaseRowHeight = sizes.baseCenter;
88
- if (isResized) {
89
- // Do not recalculate resized row height and use the value from the lookup
90
- baseRowHeight = existingBaseRowHeight;
91
- } else if (getRowHeightProp) {
92
- const rowHeightFromUser = getRowHeightProp((0, _extends2.default)({}, row, {
93
- densityFactor
94
- }));
95
- if (rowHeightFromUser === 'auto') {
96
- if (needsFirstMeasurement) {
97
- const estimatedRowHeight = getEstimatedRowHeight ? getEstimatedRowHeight((0, _extends2.default)({}, row, {
98
- densityFactor
99
- })) : rowHeight;
60
+ const rowHeight = (0, _useGridSelector.useGridSelector)(apiRef, () => (0, _gridDimensionsSelectors.gridDimensionsSelector)(apiRef.current.state).rowHeight);
61
+ const getRowHeightEntry = rowId => {
62
+ let entry = heightCache.get(rowId);
63
+ if (entry === undefined) {
64
+ entry = {
65
+ content: rowHeight,
66
+ spacingTop: 0,
67
+ spacingBottom: 0,
68
+ detail: 0,
69
+ autoHeight: false,
70
+ needsFirstMeasurement: true
71
+ };
72
+ heightCache.set(rowId, entry);
73
+ }
74
+ return entry;
75
+ };
76
+ const processHeightEntry = React.useCallback(row => {
77
+ // HACK: rowHeight trails behind the most up-to-date value just enough to
78
+ // mess the initial rowsMeta hydration :/
79
+ const baseRowHeight = (0, _gridDimensionsSelectors.gridDimensionsSelector)(apiRef.current.state).rowHeight;
80
+ (0, _utils.eslintUseValue)(rowHeight);
81
+ const entry = apiRef.current.getRowHeightEntry(row.id);
82
+ if (!getRowHeightProp) {
83
+ entry.content = baseRowHeight;
84
+ entry.needsFirstMeasurement = false;
85
+ } else {
86
+ const rowHeightFromUser = getRowHeightProp((0, _extends2.default)({}, row, {
87
+ densityFactor
88
+ }));
89
+ if (rowHeightFromUser === 'auto') {
90
+ if (entry.needsFirstMeasurement) {
91
+ const estimatedRowHeight = getEstimatedRowHeight ? getEstimatedRowHeight((0, _extends2.default)({}, row, {
92
+ densityFactor
93
+ })) : baseRowHeight;
100
94
 
101
- // If the row was not measured yet use the estimated row height
102
- baseRowHeight = estimatedRowHeight ?? rowHeight;
103
- } else {
104
- baseRowHeight = existingBaseRowHeight;
105
- }
106
- hasRowWithAutoHeight.current = true;
107
- rowsHeightLookup.current[row.id].autoHeight = true;
108
- } else {
109
- // Default back to base rowHeight if getRowHeight returns invalid value.
110
- baseRowHeight = getValidRowHeight(rowHeightFromUser, rowHeight, getRowHeightWarning);
111
- rowsHeightLookup.current[row.id].needsFirstMeasurement = false;
112
- rowsHeightLookup.current[row.id].autoHeight = false;
95
+ // If the row was not measured yet use the estimated row height
96
+ entry.content = estimatedRowHeight ?? baseRowHeight;
113
97
  }
98
+ hasRowWithAutoHeight.current = true;
99
+ entry.autoHeight = true;
114
100
  } else {
115
- rowsHeightLookup.current[row.id].needsFirstMeasurement = false;
101
+ // Default back to base rowHeight if getRowHeight returns invalid value.
102
+ entry.content = (0, _gridRowsUtils.getValidRowHeight)(rowHeightFromUser, baseRowHeight, _gridRowsUtils.getRowHeightWarning);
103
+ entry.needsFirstMeasurement = false;
104
+ entry.autoHeight = false;
116
105
  }
117
- const initialHeights = {
118
- baseCenter: baseRowHeight
119
- };
120
- if (getRowSpacing) {
121
- const indexRelativeToCurrentPage = apiRef.current.getRowIndexRelativeToVisibleRows(row.id);
122
- const spacing = getRowSpacing((0, _extends2.default)({}, row, {
123
- isFirstVisible: indexRelativeToCurrentPage === 0,
124
- isLastVisible: indexRelativeToCurrentPage === currentPage.rows.length - 1,
125
- indexRelativeToCurrentPage
126
- }));
127
- initialHeights.spacingTop = spacing.top ?? 0;
128
- initialHeights.spacingBottom = spacing.bottom ?? 0;
129
- }
130
- const processedSizes = apiRef.current.unstable_applyPipeProcessors('rowHeight', initialHeights, row);
131
- rowsHeightLookup.current[row.id].sizes = processedSizes;
132
- return processedSizes;
133
- };
106
+ }
107
+ if (getRowSpacing) {
108
+ const indexRelativeToCurrentPage = apiRef.current.getRowIndexRelativeToVisibleRows(row.id);
109
+ const spacing = getRowSpacing((0, _extends2.default)({}, row, {
110
+ isFirstVisible: indexRelativeToCurrentPage === 0,
111
+ isLastVisible: indexRelativeToCurrentPage === currentPage.rows.length - 1,
112
+ indexRelativeToCurrentPage
113
+ }));
114
+ entry.spacingTop = spacing.top ?? 0;
115
+ entry.spacingBottom = spacing.bottom ?? 0;
116
+ } else {
117
+ entry.spacingTop = 0;
118
+ entry.spacingBottom = 0;
119
+ }
120
+ apiRef.current.unstable_applyPipeProcessors('rowHeight', entry, row);
121
+ return entry;
122
+ }, [apiRef, currentPage.rows.length, getRowHeightProp, getEstimatedRowHeight, rowHeight, getRowSpacing, densityFactor]);
123
+ const hydrateRowsMeta = React.useCallback(() => {
124
+ hasRowWithAutoHeight.current = false;
125
+ pinnedRows.top.forEach(processHeightEntry);
126
+ pinnedRows.bottom.forEach(processHeightEntry);
134
127
  const positions = [];
135
128
  const currentPageTotalHeight = currentPage.rows.reduce((acc, row) => {
136
129
  positions.push(acc);
137
- let otherSizes = 0;
138
- const processedSizes = calculateRowProcessedSizes(row);
139
- /* eslint-disable-next-line guard-for-in */
140
- for (const key in processedSizes) {
141
- const value = processedSizes[key];
142
- if (key !== 'baseCenter') {
143
- otherSizes += value;
144
- }
145
- }
146
- return acc + processedSizes.baseCenter + otherSizes;
130
+ const entry = processHeightEntry(row);
131
+ const total = entry.content + entry.spacingTop + entry.spacingBottom + entry.detail;
132
+ return acc + total;
147
133
  }, 0);
148
- pinnedRows?.top?.forEach(row => {
149
- calculateRowProcessedSizes(row);
150
- });
151
- pinnedRows?.bottom?.forEach(row => {
152
- calculateRowProcessedSizes(row);
153
- });
134
+ if (!hasRowWithAutoHeight.current) {
135
+ // No row has height=auto, so all rows are already measured
136
+ lastMeasuredRowIndex.current = Infinity;
137
+ }
154
138
  apiRef.current.setState(state => {
155
139
  return (0, _extends2.default)({}, state, {
156
140
  rowsMeta: {
@@ -159,70 +143,68 @@ const useGridRowsMeta = (apiRef, props) => {
159
143
  }
160
144
  });
161
145
  });
162
- if (!hasRowWithAutoHeight.current) {
163
- // No row has height=auto, so all rows are already measured
164
- lastMeasuredRowIndex.current = Infinity;
165
- }
166
- apiRef.current.forceUpdate();
167
- }, [apiRef, currentPage.rows, rowHeight, getRowHeightProp, getRowSpacing, getEstimatedRowHeight, pinnedRows, densityFactor]);
168
- const getRowHeight = React.useCallback(rowId => {
169
- const height = rowsHeightLookup.current[rowId];
170
- return height ? height.sizes.baseCenter : rowHeight;
171
- }, [rowHeight]);
172
- const getRowInternalSizes = rowId => rowsHeightLookup.current[rowId]?.sizes;
173
- const setRowHeight = React.useCallback((id, height) => {
174
- rowsHeightLookup.current[id].sizes.baseCenter = height;
175
- rowsHeightLookup.current[id].isResized = true;
176
- rowsHeightLookup.current[id].needsFirstMeasurement = false;
177
- hydrateRowsMeta();
178
- }, [hydrateRowsMeta]);
179
- const debouncedHydrateRowsMeta = React.useMemo(() => (0, _utils.unstable_debounce)(hydrateRowsMeta, props.rowPositionsDebounceMs), [hydrateRowsMeta, props.rowPositionsDebounceMs]);
180
- const storeMeasuredRowHeight = React.useCallback((id, height) => {
181
- if (!rowsHeightLookup.current[id] || !rowsHeightLookup.current[id].autoHeight) {
182
- return;
183
- }
184
-
185
- // Only trigger hydration if the value is different, otherwise we trigger a loop
186
- const needsHydration = rowsHeightLookup.current[id].sizes.baseCenter !== height;
187
- rowsHeightLookup.current[id].needsFirstMeasurement = false;
188
- rowsHeightLookup.current[id].sizes.baseCenter = height;
189
- if (needsHydration) {
190
- debouncedHydrateRowsMeta();
191
- }
192
- }, [debouncedHydrateRowsMeta]);
193
- const rowHasAutoHeight = React.useCallback(id => {
194
- return rowsHeightLookup.current[id]?.autoHeight || false;
195
- }, []);
196
- const getLastMeasuredRowIndex = React.useCallback(() => {
146
+ isHeightMetaValid.current = true;
147
+ }, [apiRef, pinnedRows, currentPage.rows, processHeightEntry]);
148
+ const getRowHeight = rowId => {
149
+ return heightCache.get(rowId)?.content ?? rowHeight;
150
+ };
151
+ const storeRowHeightMeasurement = (id, height) => {
152
+ const entry = apiRef.current.getRowHeightEntry(id);
153
+ const didChange = entry.content !== height;
154
+ entry.needsFirstMeasurement = false;
155
+ entry.content = height;
156
+ isHeightMetaValid.current && (isHeightMetaValid.current = !didChange);
157
+ };
158
+ const rowHasAutoHeight = id => {
159
+ return heightCache.get(id)?.autoHeight ?? false;
160
+ };
161
+ const getLastMeasuredRowIndex = () => {
197
162
  return lastMeasuredRowIndex.current;
198
- }, []);
199
- const setLastMeasuredRowIndex = React.useCallback(index => {
163
+ };
164
+ const setLastMeasuredRowIndex = index => {
200
165
  if (hasRowWithAutoHeight.current && index > lastMeasuredRowIndex.current) {
201
166
  lastMeasuredRowIndex.current = index;
202
167
  }
203
- }, []);
204
- const resetRowHeights = React.useCallback(() => {
205
- rowsHeightLookup.current = {};
168
+ };
169
+ const resetRowHeights = () => {
170
+ heightCache.clear();
206
171
  hydrateRowsMeta();
207
- }, [hydrateRowsMeta]);
172
+ };
173
+ const resizeObserver = (0, _useLazyRef.default)(() => new _ResizeObserver.ResizeObserver(entries => {
174
+ for (let i = 0; i < entries.length; i += 1) {
175
+ const entry = entries[i];
176
+ const height = entry.borderBoxSize && entry.borderBoxSize.length > 0 ? entry.borderBoxSize[0].blockSize : entry.contentRect.height;
177
+ const rowId = entry.target.__mui_id;
178
+ apiRef.current.unstable_storeRowHeightMeasurement(rowId, height);
179
+ }
180
+ if (!isHeightMetaValid.current) {
181
+ apiRef.current.requestPipeProcessorsApplication('rowHeight');
182
+ }
183
+ })).current;
184
+ const observeRowHeight = (element, rowId) => {
185
+ element.__mui_id = rowId;
186
+ resizeObserver.observe(element);
187
+ return () => resizeObserver.unobserve(element);
188
+ };
189
+ (0, _pipeProcessing.useGridRegisterPipeApplier)(apiRef, 'rowHeight', hydrateRowsMeta);
208
190
 
209
191
  // The effect is used to build the rows meta data - currentPageTotalHeight and positions.
210
192
  // Because of variable row height this is needed for the virtualization
211
193
  React.useEffect(() => {
212
194
  hydrateRowsMeta();
213
- }, [rowHeight, filterModel, paginationState, sortModel, hydrateRowsMeta]);
214
- (0, _pipeProcessing.useGridRegisterPipeApplier)(apiRef, 'rowHeight', hydrateRowsMeta);
195
+ }, [filterModel, paginationState, sortModel, hydrateRowsMeta]);
215
196
  const rowsMetaApi = {
216
- unstable_setLastMeasuredRowIndex: setLastMeasuredRowIndex,
217
197
  unstable_getRowHeight: getRowHeight,
218
- unstable_getRowInternalSizes: getRowInternalSizes,
219
- unstable_setRowHeight: setRowHeight,
220
- unstable_storeRowHeightMeasurement: storeMeasuredRowHeight,
198
+ unstable_setLastMeasuredRowIndex: setLastMeasuredRowIndex,
199
+ unstable_storeRowHeightMeasurement: storeRowHeightMeasurement,
221
200
  resetRowHeights
222
201
  };
223
202
  const rowsMetaPrivateApi = {
224
- getLastMeasuredRowIndex,
225
- rowHasAutoHeight
203
+ hydrateRowsMeta,
204
+ observeRowHeight,
205
+ rowHasAutoHeight,
206
+ getRowHeightEntry,
207
+ getLastMeasuredRowIndex
226
208
  };
227
209
  (0, _useGridApiMethod.useGridApiMethod)(apiRef, rowsMetaApi, 'public');
228
210
  (0, _useGridApiMethod.useGridApiMethod)(apiRef, rowsMetaPrivateApi, 'private');
@@ -16,6 +16,7 @@ var _gridRowsMetaSelector = require("../rows/gridRowsMetaSelector");
16
16
  var _useGridApiMethod = require("../../utils/useGridApiMethod");
17
17
  var _gridFilterSelector = require("../filter/gridFilterSelector");
18
18
  var _dimensions = require("../dimensions");
19
+ var _gridListViewSelectors = require("../listView/gridListViewSelectors");
19
20
  // Logic copied from https://www.w3.org/TR/wai-aria-practices/examples/listbox/js/listbox.js
20
21
  // Similar to https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
21
22
  function scrollIntoView(dimensions) {
@@ -59,7 +60,7 @@ const useGridScroll = (apiRef, props) => {
59
60
  const scrollToIndexes = React.useCallback(params => {
60
61
  const dimensions = (0, _dimensions.gridDimensionsSelector)(apiRef.current.state);
61
62
  const totalRowCount = (0, _gridRowsSelector.gridRowCountSelector)(apiRef);
62
- const visibleColumns = (0, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector)(apiRef);
63
+ const visibleColumns = props.unstable_listView ? [(0, _gridListViewSelectors.gridListColumnSelector)(apiRef.current.state)] : (0, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector)(apiRef);
63
64
  const scrollToHeader = params.rowIndex == null;
64
65
  if (!scrollToHeader && totalRowCount === 0 || visibleColumns.length === 0) {
65
66
  return false;
@@ -106,7 +107,7 @@ const useGridScroll = (apiRef, props) => {
106
107
  return true;
107
108
  }
108
109
  return false;
109
- }, [logger, apiRef, virtualScrollerRef, props.pagination, visibleSortedRows]);
110
+ }, [logger, apiRef, virtualScrollerRef, props.pagination, visibleSortedRows, props.unstable_listView]);
110
111
  const scroll = React.useCallback(params => {
111
112
  if (virtualScrollerRef.current && virtualScrollbarHorizontalRef.current && params.left !== undefined && colRef.current) {
112
113
  const direction = isRtl ? -1 : 1;
@@ -36,6 +36,7 @@ var _gridRowsUtils = require("../rows/gridRowsUtils");
36
36
  var _gridVirtualizationSelectors = require("./gridVirtualizationSelectors");
37
37
  var _useGridVirtualization = require("./useGridVirtualization");
38
38
  var _gridRowSpanningSelectors = require("../rows/gridRowSpanningSelectors");
39
+ var _gridListViewSelectors = require("../listView/gridListViewSelectors");
39
40
  var _jsxRuntime = require("react/jsx-runtime");
40
41
  const MINIMUM_COLUMN_WIDTH = 50;
41
42
  var ScrollDirection = /*#__PURE__*/function (ScrollDirection) {
@@ -66,13 +67,20 @@ try {
66
67
  const useGridVirtualScroller = () => {
67
68
  const apiRef = (0, _useGridPrivateApiContext.useGridPrivateApiContext)();
68
69
  const rootProps = (0, _useGridRootProps.useGridRootProps)();
69
- const visibleColumns = (0, _useGridSelector.useGridSelector)(apiRef, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector);
70
+ const {
71
+ unstable_listView: listView
72
+ } = rootProps;
73
+ const visibleColumns = (0, _useGridSelector.useGridSelector)(apiRef, () => listView ? [(0, _gridListViewSelectors.gridListColumnSelector)(apiRef.current.state)] : (0, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector)(apiRef));
70
74
  const enabledForRows = (0, _useGridSelector.useGridSelector)(apiRef, _gridVirtualizationSelectors.gridVirtualizationRowEnabledSelector) && !isJSDOM;
71
75
  const enabledForColumns = (0, _useGridSelector.useGridSelector)(apiRef, _gridVirtualizationSelectors.gridVirtualizationColumnEnabledSelector) && !isJSDOM;
72
76
  const dimensions = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridDimensionsSelector);
73
77
  const outerSize = dimensions.viewportOuterSize;
74
78
  const pinnedRows = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowsSelector.gridPinnedRowsSelector);
75
- const pinnedColumns = (0, _useGridSelector.useGridSelector)(apiRef, _gridColumnsSelector.gridVisiblePinnedColumnDefinitionsSelector);
79
+ const pinnedColumnDefinitions = (0, _useGridSelector.useGridSelector)(apiRef, _gridColumnsSelector.gridVisiblePinnedColumnDefinitionsSelector);
80
+ const pinnedColumns = listView ? {
81
+ left: [],
82
+ right: []
83
+ } : pinnedColumnDefinitions;
76
84
  const hasBottomPinnedRows = pinnedRows.bottom.length > 0;
77
85
  const [panels, setPanels] = React.useState(EMPTY_DETAIL_PANELS);
78
86
  const isRtl = (0, _RtlProvider.useRtl)();
@@ -139,7 +147,7 @@ const useGridVirtualScroller = () => {
139
147
  }
140
148
  previousContextScrollPosition.current = scrollPosition.current;
141
149
  }, [apiRef, dimensions.isReady]);
142
- const triggerUpdateRenderContext = () => {
150
+ const triggerUpdateRenderContext = (0, _utils.unstable_useEventCallback)(() => {
143
151
  const newScroll = {
144
152
  top: scrollerRef.current.scrollTop,
145
153
  left: scrollerRef.current.scrollLeft
@@ -187,7 +195,7 @@ const useGridVirtualScroller = () => {
187
195
  });
188
196
  scrollTimeout.start(1000, triggerUpdateRenderContext);
189
197
  return nextRenderContext;
190
- };
198
+ });
191
199
  const forceUpdateRenderContext = () => {
192
200
  const inputs = inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns);
193
201
  const nextRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
@@ -373,15 +381,16 @@ const useGridVirtualScroller = () => {
373
381
  });
374
382
  return rows;
375
383
  };
376
- const needsHorizontalScrollbar = outerSize.width && columnsTotalWidth >= outerSize.width;
384
+ const needsHorizontalScrollbar = outerSize.width && columnsTotalWidth > outerSize.width;
377
385
  const scrollerStyle = React.useMemo(() => ({
378
- overflowX: !needsHorizontalScrollbar ? 'hidden' : undefined,
386
+ overflowX: !needsHorizontalScrollbar || listView ? 'hidden' : undefined,
379
387
  overflowY: rootProps.autoHeight ? 'hidden' : undefined
380
- }), [needsHorizontalScrollbar, rootProps.autoHeight]);
388
+ }), [needsHorizontalScrollbar, rootProps.autoHeight, listView]);
381
389
  const contentSize = React.useMemo(() => {
382
390
  const size = {
383
391
  width: needsHorizontalScrollbar ? columnsTotalWidth : 'auto',
384
- height: contentHeight
392
+ flexBasis: contentHeight,
393
+ flexShrink: 0
385
394
  };
386
395
  if (rootProps.autoHeight && currentPage.rows.length === 0) {
387
396
  size.height = (0, _gridRowsUtils.getMinimalContentHeight)(apiRef); // Give room to show the overlay when there no rows.
@@ -404,6 +413,11 @@ const useGridVirtualScroller = () => {
404
413
  scrollerRef.current.scrollTop = 0;
405
414
  }
406
415
  }, [enabledForColumns, enabledForRows, gridRootRef, scrollerRef]);
416
+ (0, _utils.unstable_useEnhancedEffect)(() => {
417
+ if (listView) {
418
+ scrollerRef.current.scrollLeft = 0;
419
+ }
420
+ }, [listView, scrollerRef]);
407
421
  (0, _useRunOnce.useRunOnce)(outerSize.width !== 0, () => {
408
422
  const inputs = inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns);
409
423
  const initialRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
@@ -459,7 +473,7 @@ exports.useGridVirtualScroller = useGridVirtualScroller;
459
473
  function inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns) {
460
474
  const dimensions = (0, _gridDimensionsSelectors.gridDimensionsSelector)(apiRef.current.state);
461
475
  const currentPage = (0, _useGridVisibleRows.getVisibleRows)(apiRef, rootProps);
462
- const visibleColumns = (0, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector)(apiRef);
476
+ const visibleColumns = rootProps.unstable_listView ? [(0, _gridListViewSelectors.gridListColumnSelector)(apiRef.current.state)] : (0, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector)(apiRef);
463
477
  const hiddenCellsOriginMap = (0, _gridRowSpanningSelectors.gridRowSpanningHiddenCellsOriginMapSelector)(apiRef);
464
478
  const lastRowId = apiRef.current.state.rows.dataRowIds.at(-1);
465
479
  const lastColumn = visibleColumns.at(-1);
@@ -482,7 +496,8 @@ function inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns) {
482
496
  range: currentPage.range,
483
497
  pinnedColumns: (0, _gridColumnsSelector.gridVisiblePinnedColumnDefinitionsSelector)(apiRef),
484
498
  visibleColumns,
485
- hiddenCellsOriginMap
499
+ hiddenCellsOriginMap,
500
+ listView: rootProps.unstable_listView ?? false
486
501
  };
487
502
  }
488
503
  function computeRenderContext(inputs, scrollPosition, scrollCache) {
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
3
4
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.useGridApiMethod = useGridApiMethod;
8
9
  var React = _interopRequireWildcard(require("react"));
10
+ var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
9
11
  function useGridApiMethod(privateApiRef, apiMethods, visibility) {
10
12
  const isFirstRender = React.useRef(true);
11
- React.useEffect(() => {
13
+ (0, _useEnhancedEffect.default)(() => {
12
14
  isFirstRender.current = false;
13
15
  privateApiRef.current.register(visibility, apiMethods);
14
16
  }, [privateApiRef, visibility, apiMethods]);
package/node/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
@@ -100,6 +100,18 @@ Object.keys(_constants).forEach(function (key) {
100
100
  }
101
101
  });
102
102
  });
103
+ var _dataGridPropsDefaultValues = require("./constants/dataGridPropsDefaultValues");
104
+ Object.keys(_dataGridPropsDefaultValues).forEach(function (key) {
105
+ if (key === "default" || key === "__esModule") return;
106
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
107
+ if (key in exports && exports[key] === _dataGridPropsDefaultValues[key]) return;
108
+ Object.defineProperty(exports, key, {
109
+ enumerable: true,
110
+ get: function () {
111
+ return _dataGridPropsDefaultValues[key];
112
+ }
113
+ });
114
+ });
103
115
  var _hooks = require("./hooks");
104
116
  Object.keys(_hooks).forEach(function (key) {
105
117
  if (key === "default" || key === "__esModule") return;
@@ -81,6 +81,8 @@ var _exportNames = {
81
81
  useGridColumnResize: true,
82
82
  columnResizeStateInitializer: true,
83
83
  ROW_SELECTION_PROPAGATION_DEFAULT: true,
84
+ useGridListView: true,
85
+ listViewStateInitializer: true,
84
86
  useTimeout: true,
85
87
  useGridVisibleRows: true,
86
88
  getVisibleRows: true,
@@ -97,6 +99,7 @@ var _exportNames = {
97
99
  isEventTargetInPortal: true,
98
100
  isNavigationKey: true,
99
101
  isPasteShortcut: true,
102
+ isCopyShortcut: true,
100
103
  exportAs: true,
101
104
  useGridPrivateApiContext: true,
102
105
  serializeCellValue: true
@@ -359,6 +362,12 @@ Object.defineProperty(exports, "headerFilteringStateInitializer", {
359
362
  return _useGridHeaderFiltering.headerFilteringStateInitializer;
360
363
  }
361
364
  });
365
+ Object.defineProperty(exports, "isCopyShortcut", {
366
+ enumerable: true,
367
+ get: function () {
368
+ return _keyboardUtils.isCopyShortcut;
369
+ }
370
+ });
362
371
  Object.defineProperty(exports, "isEventTargetInPortal", {
363
372
  enumerable: true,
364
373
  get: function () {
@@ -383,6 +392,12 @@ Object.defineProperty(exports, "isSingleSelectColDef", {
383
392
  return _filterPanelUtils.isSingleSelectColDef;
384
393
  }
385
394
  });
395
+ Object.defineProperty(exports, "listViewStateInitializer", {
396
+ enumerable: true,
397
+ get: function () {
398
+ return _useGridListView.listViewStateInitializer;
399
+ }
400
+ });
386
401
  Object.defineProperty(exports, "paginationStateInitializer", {
387
402
  enumerable: true,
388
403
  get: function () {
@@ -551,6 +566,12 @@ Object.defineProperty(exports, "useGridKeyboardNavigation", {
551
566
  return _useGridKeyboardNavigation.useGridKeyboardNavigation;
552
567
  }
553
568
  });
569
+ Object.defineProperty(exports, "useGridListView", {
570
+ enumerable: true,
571
+ get: function () {
572
+ return _useGridListView.useGridListView;
573
+ }
574
+ });
554
575
  Object.defineProperty(exports, "useGridPagination", {
555
576
  enumerable: true,
556
577
  get: function () {
@@ -775,6 +796,7 @@ Object.keys(_virtualization).forEach(function (key) {
775
796
  });
776
797
  var _useGridColumnResize = require("../hooks/features/columnResize/useGridColumnResize");
777
798
  var _utils = require("../hooks/features/rowSelection/utils");
799
+ var _useGridListView = require("../hooks/features/listView/useGridListView");
778
800
  var _useTimeout = require("../hooks/utils/useTimeout");
779
801
  var _useGridVisibleRows = require("../hooks/utils/useGridVisibleRows");
780
802
  var _useGridInitializeState = require("../hooks/utils/useGridInitializeState");