@mui/x-data-grid 5.12.1 → 5.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/CHANGELOG.md +45 -2
  2. package/colDef/gridCheckboxSelectionColDef.d.ts +1 -0
  3. package/colDef/gridCheckboxSelectionColDef.js +2 -1
  4. package/colDef/gridDateOperators.d.ts +1 -1
  5. package/colDef/gridNumericColDef.js +1 -1
  6. package/components/columnHeaders/GridColumnHeaderItem.js +5 -3
  7. package/components/columnSelection/GridCellCheckboxRenderer.js +0 -1
  8. package/components/columnSelection/GridHeaderCheckbox.js +0 -1
  9. package/components/containers/GridRootStyles.js +1 -1
  10. package/components/panel/GridColumnsPanel.js +2 -5
  11. package/components/panel/filterPanel/GridFilterPanel.js +1 -2
  12. package/components/toolbar/GridToolbarColumnsButton.js +0 -1
  13. package/components/toolbar/GridToolbarDensitySelector.js +0 -1
  14. package/components/toolbar/GridToolbarExportContainer.js +0 -1
  15. package/components/toolbar/GridToolbarFilterButton.js +0 -1
  16. package/constants/localeTextConstants.js +1 -0
  17. package/hooks/features/columns/useGridColumnSpanning.d.ts +1 -1
  18. package/hooks/features/columns/useGridColumnSpanning.js +1 -1
  19. package/hooks/features/columns/useGridColumns.d.ts +1 -1
  20. package/hooks/features/dimensions/gridDimensionsApi.d.ts +5 -0
  21. package/hooks/features/dimensions/useGridDimensions.js +9 -8
  22. package/hooks/features/filter/gridFilterState.d.ts +1 -1
  23. package/hooks/features/filter/useGridFilter.d.ts +1 -1
  24. package/hooks/features/rows/useGridRowsMeta.js +79 -77
  25. package/hooks/features/selection/useGridSelectionPreProcessors.js +8 -6
  26. package/hooks/features/sorting/useGridSorting.d.ts +1 -1
  27. package/hooks/features/virtualization/useGridVirtualScroller.d.ts +1 -1
  28. package/hooks/features/virtualization/useGridVirtualScroller.js +42 -8
  29. package/index.js +1 -1
  30. package/legacy/colDef/gridCheckboxSelectionColDef.js +2 -1
  31. package/legacy/colDef/gridNumericColDef.js +1 -1
  32. package/legacy/components/columnHeaders/GridColumnHeaderItem.js +5 -3
  33. package/legacy/components/columnSelection/GridCellCheckboxRenderer.js +0 -1
  34. package/legacy/components/columnSelection/GridHeaderCheckbox.js +0 -1
  35. package/legacy/components/containers/GridRootStyles.js +1 -1
  36. package/legacy/components/panel/GridColumnsPanel.js +2 -5
  37. package/legacy/components/panel/filterPanel/GridFilterPanel.js +1 -2
  38. package/legacy/components/toolbar/GridToolbarColumnsButton.js +0 -1
  39. package/legacy/components/toolbar/GridToolbarDensitySelector.js +0 -1
  40. package/legacy/components/toolbar/GridToolbarExportContainer.js +0 -1
  41. package/legacy/components/toolbar/GridToolbarFilterButton.js +0 -1
  42. package/legacy/constants/localeTextConstants.js +1 -0
  43. package/legacy/hooks/features/columns/useGridColumnSpanning.js +1 -1
  44. package/legacy/hooks/features/dimensions/useGridDimensions.js +9 -8
  45. package/legacy/hooks/features/rows/useGridRowsMeta.js +81 -77
  46. package/legacy/hooks/features/selection/useGridSelectionPreProcessors.js +8 -6
  47. package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +42 -8
  48. package/legacy/index.js +1 -1
  49. package/legacy/locales/arSD.js +1 -0
  50. package/legacy/locales/bgBG.js +1 -0
  51. package/legacy/locales/csCZ.js +1 -0
  52. package/legacy/locales/daDK.js +1 -0
  53. package/legacy/locales/deDE.js +1 -0
  54. package/legacy/locales/elGR.js +1 -0
  55. package/legacy/locales/esES.js +1 -0
  56. package/legacy/locales/faIR.js +1 -0
  57. package/legacy/locales/fiFI.js +1 -0
  58. package/legacy/locales/frFR.js +1 -0
  59. package/legacy/locales/heIL.js +1 -0
  60. package/legacy/locales/huHU.js +1 -0
  61. package/legacy/locales/itIT.js +1 -0
  62. package/legacy/locales/jaJP.js +1 -0
  63. package/legacy/locales/koKR.js +1 -0
  64. package/legacy/locales/nbNO.js +1 -0
  65. package/legacy/locales/nlNL.js +1 -0
  66. package/legacy/locales/plPL.js +1 -0
  67. package/legacy/locales/ptBR.js +1 -0
  68. package/legacy/locales/ruRU.js +1 -0
  69. package/legacy/locales/skSK.js +1 -0
  70. package/legacy/locales/trTR.js +1 -0
  71. package/legacy/locales/ukUA.js +1 -0
  72. package/legacy/locales/viVN.js +1 -0
  73. package/legacy/locales/zhCN.js +1 -0
  74. package/locales/arSD.js +1 -0
  75. package/locales/bgBG.js +1 -0
  76. package/locales/csCZ.js +1 -0
  77. package/locales/daDK.js +1 -0
  78. package/locales/deDE.js +1 -0
  79. package/locales/elGR.js +1 -0
  80. package/locales/esES.js +1 -0
  81. package/locales/faIR.js +1 -0
  82. package/locales/fiFI.js +1 -0
  83. package/locales/frFR.js +1 -0
  84. package/locales/heIL.js +1 -0
  85. package/locales/huHU.js +1 -0
  86. package/locales/itIT.js +1 -0
  87. package/locales/jaJP.js +1 -0
  88. package/locales/koKR.js +1 -0
  89. package/locales/nbNO.js +1 -0
  90. package/locales/nlNL.js +1 -0
  91. package/locales/plPL.js +1 -0
  92. package/locales/ptBR.js +1 -0
  93. package/locales/ruRU.js +1 -0
  94. package/locales/skSK.js +1 -0
  95. package/locales/trTR.js +1 -0
  96. package/locales/ukUA.js +1 -0
  97. package/locales/viVN.js +1 -0
  98. package/locales/zhCN.js +1 -0
  99. package/models/api/gridLocaleTextApi.d.ts +1 -0
  100. package/models/colDef/gridColDef.d.ts +1 -1
  101. package/modern/colDef/gridCheckboxSelectionColDef.js +2 -1
  102. package/modern/colDef/gridNumericColDef.js +1 -1
  103. package/modern/components/columnHeaders/GridColumnHeaderItem.js +5 -3
  104. package/modern/components/columnSelection/GridCellCheckboxRenderer.js +0 -1
  105. package/modern/components/columnSelection/GridHeaderCheckbox.js +0 -1
  106. package/modern/components/containers/GridRootStyles.js +1 -1
  107. package/modern/components/panel/GridColumnsPanel.js +2 -5
  108. package/modern/components/panel/filterPanel/GridFilterPanel.js +1 -2
  109. package/modern/components/toolbar/GridToolbarColumnsButton.js +0 -1
  110. package/modern/components/toolbar/GridToolbarDensitySelector.js +0 -1
  111. package/modern/components/toolbar/GridToolbarExportContainer.js +0 -1
  112. package/modern/components/toolbar/GridToolbarFilterButton.js +0 -1
  113. package/modern/constants/localeTextConstants.js +1 -0
  114. package/modern/hooks/features/columns/useGridColumnSpanning.js +1 -1
  115. package/modern/hooks/features/dimensions/useGridDimensions.js +9 -8
  116. package/modern/hooks/features/rows/useGridRowsMeta.js +77 -75
  117. package/modern/hooks/features/selection/useGridSelectionPreProcessors.js +8 -6
  118. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +42 -8
  119. package/modern/index.js +1 -1
  120. package/modern/locales/arSD.js +1 -0
  121. package/modern/locales/bgBG.js +1 -0
  122. package/modern/locales/csCZ.js +1 -0
  123. package/modern/locales/daDK.js +1 -0
  124. package/modern/locales/deDE.js +1 -0
  125. package/modern/locales/elGR.js +1 -0
  126. package/modern/locales/esES.js +1 -0
  127. package/modern/locales/faIR.js +1 -0
  128. package/modern/locales/fiFI.js +1 -0
  129. package/modern/locales/frFR.js +1 -0
  130. package/modern/locales/heIL.js +1 -0
  131. package/modern/locales/huHU.js +1 -0
  132. package/modern/locales/itIT.js +1 -0
  133. package/modern/locales/jaJP.js +1 -0
  134. package/modern/locales/koKR.js +1 -0
  135. package/modern/locales/nbNO.js +1 -0
  136. package/modern/locales/nlNL.js +1 -0
  137. package/modern/locales/plPL.js +1 -0
  138. package/modern/locales/ptBR.js +1 -0
  139. package/modern/locales/ruRU.js +1 -0
  140. package/modern/locales/skSK.js +1 -0
  141. package/modern/locales/trTR.js +1 -0
  142. package/modern/locales/ukUA.js +1 -0
  143. package/modern/locales/viVN.js +1 -0
  144. package/modern/locales/zhCN.js +1 -0
  145. package/node/colDef/gridCheckboxSelectionColDef.js +4 -2
  146. package/node/colDef/gridNumericColDef.js +1 -1
  147. package/node/components/columnHeaders/GridColumnHeaderItem.js +5 -3
  148. package/node/components/columnSelection/GridCellCheckboxRenderer.js +0 -1
  149. package/node/components/columnSelection/GridHeaderCheckbox.js +0 -1
  150. package/node/components/containers/GridRootStyles.js +1 -1
  151. package/node/components/panel/GridColumnsPanel.js +2 -5
  152. package/node/components/panel/filterPanel/GridFilterPanel.js +1 -2
  153. package/node/components/toolbar/GridToolbarColumnsButton.js +0 -1
  154. package/node/components/toolbar/GridToolbarDensitySelector.js +0 -1
  155. package/node/components/toolbar/GridToolbarExportContainer.js +0 -1
  156. package/node/components/toolbar/GridToolbarFilterButton.js +0 -1
  157. package/node/constants/localeTextConstants.js +1 -0
  158. package/node/hooks/features/columns/useGridColumnSpanning.js +11 -16
  159. package/node/hooks/features/dimensions/useGridDimensions.js +9 -8
  160. package/node/hooks/features/rows/useGridRowsMeta.js +80 -77
  161. package/node/hooks/features/selection/useGridSelectionPreProcessors.js +7 -5
  162. package/node/hooks/features/virtualization/useGridVirtualScroller.js +42 -9
  163. package/node/index.js +1 -1
  164. package/node/locales/arSD.js +1 -0
  165. package/node/locales/bgBG.js +1 -0
  166. package/node/locales/csCZ.js +1 -0
  167. package/node/locales/daDK.js +1 -0
  168. package/node/locales/deDE.js +1 -0
  169. package/node/locales/elGR.js +1 -0
  170. package/node/locales/esES.js +1 -0
  171. package/node/locales/faIR.js +1 -0
  172. package/node/locales/fiFI.js +1 -0
  173. package/node/locales/frFR.js +1 -0
  174. package/node/locales/heIL.js +1 -0
  175. package/node/locales/huHU.js +1 -0
  176. package/node/locales/itIT.js +1 -0
  177. package/node/locales/jaJP.js +1 -0
  178. package/node/locales/koKR.js +1 -0
  179. package/node/locales/nbNO.js +1 -0
  180. package/node/locales/nlNL.js +1 -0
  181. package/node/locales/plPL.js +1 -0
  182. package/node/locales/ptBR.js +1 -0
  183. package/node/locales/ruRU.js +1 -0
  184. package/node/locales/skSK.js +1 -0
  185. package/node/locales/trTR.js +1 -0
  186. package/node/locales/ukUA.js +1 -0
  187. package/node/locales/viVN.js +1 -0
  188. package/node/locales/zhCN.js +1 -0
  189. package/package.json +1 -1
@@ -165,6 +165,7 @@ function GridColumnHeaderItem(props) {
165
165
  field: column.field,
166
166
  colDef: column
167
167
  }) : column.headerClassName;
168
+ const label = column.headerName ?? column.field;
168
169
  return /*#__PURE__*/_jsxs("div", _extends({
169
170
  ref: headerCellRef,
170
171
  className: clsx(classes.root, headerClassName),
@@ -177,7 +178,8 @@ function GridColumnHeaderItem(props) {
177
178
  role: "columnheader",
178
179
  tabIndex: tabIndex,
179
180
  "aria-colindex": colIndex + 1,
180
- "aria-sort": ariaSort
181
+ "aria-sort": ariaSort,
182
+ "aria-label": column.renderHeader && headerComponent == null ? label : undefined
181
183
  }, mouseEventsHandlers, {
182
184
  children: [/*#__PURE__*/_jsxs("div", _extends({
183
185
  className: classes.draggableContainer,
@@ -187,8 +189,8 @@ function GridColumnHeaderItem(props) {
187
189
  className: classes.titleContainer,
188
190
  children: [/*#__PURE__*/_jsx("div", {
189
191
  className: classes.titleContainerContent,
190
- children: headerComponent || /*#__PURE__*/_jsx(GridColumnHeaderTitle, {
191
- label: column.headerName ?? column.field,
192
+ children: column.renderHeader ? headerComponent : /*#__PURE__*/_jsx(GridColumnHeaderTitle, {
193
+ label: label,
192
194
  description: column.description,
193
195
  columnWidth: width
194
196
  })
@@ -81,7 +81,6 @@ const GridCellCheckboxForwardRef = /*#__PURE__*/React.forwardRef(function GridCe
81
81
  checked: isChecked,
82
82
  onChange: handleChange,
83
83
  className: classes.root,
84
- color: "primary",
85
84
  inputProps: {
86
85
  'aria-label': label
87
86
  },
@@ -109,7 +109,6 @@ const GridHeaderCheckbox = /*#__PURE__*/React.forwardRef(function GridHeaderChec
109
109
  checked: isChecked,
110
110
  onChange: handleChange,
111
111
  className: classes.root,
112
- color: "primary",
113
112
  inputProps: {
114
113
  'aria-label': label
115
114
  },
@@ -165,7 +165,7 @@ export const GridRootStyles = styled('div', {
165
165
  minWidth: 0,
166
166
  flex: 1,
167
167
  whiteSpace: 'nowrap',
168
- overflow: 'hidden'
168
+ overflowX: 'hidden'
169
169
  },
170
170
  [`& .${gridClasses.columnHeaderTitleContainerContent}`]: {
171
171
  overflow: 'hidden',
@@ -130,7 +130,6 @@ export function GridColumnsPanel(props) {
130
130
  checked: columnVisibilityModel[column.field] !== false,
131
131
  onClick: toggleColumn,
132
132
  name: column.field,
133
- color: "primary",
134
133
  size: "small"
135
134
  }, rootProps.componentsProps?.baseSwitch)),
136
135
  label: column.headerName || column.field
@@ -146,13 +145,11 @@ export function GridColumnsPanel(props) {
146
145
  })
147
146
  }), /*#__PURE__*/_jsxs(GridPanelFooter, {
148
147
  children: [/*#__PURE__*/_jsx(rootProps.components.BaseButton, _extends({
149
- onClick: () => toggleAllColumns(false),
150
- color: "primary"
148
+ onClick: () => toggleAllColumns(false)
151
149
  }, rootProps.componentsProps?.baseButton, {
152
150
  children: apiRef.current.getLocaleText('columnsPanelHideAllButton')
153
151
  })), /*#__PURE__*/_jsx(rootProps.components.BaseButton, _extends({
154
- onClick: () => toggleAllColumns(true),
155
- color: "primary"
152
+ onClick: () => toggleAllColumns(true)
156
153
  }, rootProps.componentsProps?.baseButton, {
157
154
  children: apiRef.current.getLocaleText('columnsPanelShowAllButton')
158
155
  }))]
@@ -107,8 +107,7 @@ const GridFilterPanel = /*#__PURE__*/React.forwardRef(function GridFilterPanel(p
107
107
  }), !rootProps.disableMultipleColumnsFiltering && /*#__PURE__*/_jsx(GridPanelFooter, {
108
108
  children: /*#__PURE__*/_jsx(rootProps.components.BaseButton, _extends({
109
109
  onClick: addNewFilter,
110
- startIcon: /*#__PURE__*/_jsx(GridAddIcon, {}),
111
- color: "primary"
110
+ startIcon: /*#__PURE__*/_jsx(GridAddIcon, {})
112
111
  }, rootProps.componentsProps?.baseButton, {
113
112
  children: apiRef.current.getLocaleText('filterPanelAddFilter')
114
113
  }))
@@ -39,7 +39,6 @@ export const GridToolbarColumnsButton = /*#__PURE__*/React.forwardRef(function G
39
39
  return /*#__PURE__*/_jsx(rootProps.components.BaseButton, _extends({
40
40
  ref: ref,
41
41
  size: "small",
42
- color: "primary",
43
42
  "aria-label": apiRef.current.getLocaleText('toolbarColumnsLabel'),
44
43
  startIcon: /*#__PURE__*/_jsx(rootProps.components.ColumnSelectorIcon, {})
45
44
  }, other, {
@@ -93,7 +93,6 @@ export const GridToolbarDensitySelector = /*#__PURE__*/React.forwardRef(function
93
93
  return /*#__PURE__*/_jsxs(React.Fragment, {
94
94
  children: [/*#__PURE__*/_jsx(rootProps.components.BaseButton, _extends({
95
95
  ref: handleRef,
96
- color: "primary",
97
96
  size: "small",
98
97
  startIcon: startIcon,
99
98
  "aria-label": apiRef.current.getLocaleText('toolbarDensityLabel'),
@@ -50,7 +50,6 @@ export const GridToolbarExportContainer = /*#__PURE__*/React.forwardRef(function
50
50
  return /*#__PURE__*/_jsxs(React.Fragment, {
51
51
  children: [/*#__PURE__*/_jsx(rootProps.components.BaseButton, _extends({
52
52
  ref: handleRef,
53
- color: "primary",
54
53
  size: "small",
55
54
  startIcon: /*#__PURE__*/_jsx(rootProps.components.ExportIcon, {}),
56
55
  "aria-expanded": open ? 'true' : undefined,
@@ -104,7 +104,6 @@ const GridToolbarFilterButton = /*#__PURE__*/React.forwardRef(function GridToolb
104
104
  children: /*#__PURE__*/_jsx(rootProps.components.BaseButton, _extends({
105
105
  ref: ref,
106
106
  size: "small",
107
- color: "primary",
108
107
  "aria-label": apiRef.current.getLocaleText('toolbarFiltersLabel'),
109
108
  startIcon: /*#__PURE__*/_jsx(Badge, {
110
109
  badgeContent: activeFilters.length,
@@ -105,6 +105,7 @@ export const GRID_DEFAULT_LOCALE_TEXT = {
105
105
  groupColumn: name => `Group by ${name}`,
106
106
  unGroupColumn: name => `Stop grouping by ${name}`,
107
107
  // Master/detail
108
+ detailPanelToggle: 'Detail panel toggle',
108
109
  expandDetailPanel: 'Expand',
109
110
  collapseDetailPanel: 'Collapse',
110
111
  // Used core components translation keys
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import * as React from 'react';
2
2
  import { useGridApiMethod } from '../../utils/useGridApiMethod';
3
3
  import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
4
4
 
@@ -37,7 +37,7 @@ const hasScroll = ({
37
37
 
38
38
  export function useGridDimensions(apiRef, props) {
39
39
  const logger = useGridLogger(apiRef, 'useResizeContainer');
40
- const warningShown = React.useRef(false);
40
+ const errorShown = React.useRef(false);
41
41
  const rootDimensionsRef = React.useRef(null);
42
42
  const fullDimensionsRef = React.useRef(null);
43
43
  const rowsMeta = useGridSelector(apiRef, gridRowsMetaSelector);
@@ -92,7 +92,8 @@ export function useGridDimensions(apiRef, props) {
92
92
  viewportOuterSize,
93
93
  viewportInnerSize,
94
94
  hasScrollX,
95
- hasScrollY
95
+ hasScrollY,
96
+ scrollBarSize
96
97
  };
97
98
  const prevDimensions = fullDimensionsRef.current;
98
99
  fullDimensionsRef.current = newFullDimensions;
@@ -142,14 +143,14 @@ export function useGridDimensions(apiRef, props) {
142
143
 
143
144
  const isJSDOM = /jsdom/.test(window.navigator.userAgent);
144
145
 
145
- if (size.height === 0 && !warningShown.current && !props.autoHeight && !isJSDOM) {
146
- logger.warn(['The parent of the grid has an empty height.', 'You need to make sure the container has an intrinsic height.', 'The grid displays with a height of 0px.', '', 'You can find a solution in the docs:', 'https://mui.com/x/react-data-grid/layout/'].join('\n'));
147
- warningShown.current = true;
146
+ if (size.height === 0 && !errorShown.current && !props.autoHeight && !isJSDOM) {
147
+ 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'));
148
+ errorShown.current = true;
148
149
  }
149
150
 
150
- if (size.width === 0 && !warningShown.current && !isJSDOM) {
151
- logger.warn(['The parent of the grid has an empty width.', 'You need to make sure the container has an intrinsic width.', 'The grid displays with a width of 0px.', '', 'You can find a solution in the docs:', 'https://mui.com/x/react-data-grid/layout/'].join('\n'));
152
- warningShown.current = true;
151
+ if (size.width === 0 && !errorShown.current && !isJSDOM) {
152
+ 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'));
153
+ errorShown.current = true;
153
154
  }
154
155
 
155
156
  if (isTestEnvironment) {
@@ -1,5 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
+ import { debounce } from '@mui/material/utils';
3
4
  import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
4
5
  import { useGridApiMethod } from '../../utils/useGridApiMethod';
5
6
  import { useGridSelector } from '../../utils/useGridSelector';
@@ -36,84 +37,84 @@ export const useGridRowsMeta = (apiRef, props) => {
36
37
  const currentPage = useGridVisibleRows(apiRef, props);
37
38
  const hydrateRowsMeta = React.useCallback(() => {
38
39
  hasRowWithAutoHeight.current = false;
39
- apiRef.current.setState(state => {
40
- const densityFactor = gridDensityFactorSelector(state, apiRef.current.instanceId);
41
- const positions = [];
42
- const currentPageTotalHeight = currentPage.rows.reduce((acc, row) => {
43
- positions.push(acc);
44
-
45
- if (!rowsHeightLookup.current[row.id]) {
46
- rowsHeightLookup.current[row.id] = {
47
- sizes: {
48
- base: rowHeightFromDensity
49
- },
50
- isResized: false,
51
- autoHeight: false,
52
- needsFirstMeasurement: true // Assume all rows will need to be measured by default
53
-
54
- };
55
- }
40
+ const densityFactor = gridDensityFactorSelector(apiRef.current.state, apiRef.current.instanceId);
41
+ const positions = [];
42
+ const currentPageTotalHeight = currentPage.rows.reduce((acc, row) => {
43
+ positions.push(acc);
44
+
45
+ if (!rowsHeightLookup.current[row.id]) {
46
+ rowsHeightLookup.current[row.id] = {
47
+ sizes: {
48
+ base: rowHeightFromDensity
49
+ },
50
+ isResized: false,
51
+ autoHeight: false,
52
+ needsFirstMeasurement: true // Assume all rows will need to be measured by default
56
53
 
57
- const {
58
- isResized,
59
- needsFirstMeasurement,
60
- sizes
61
- } = rowsHeightLookup.current[row.id];
62
- let baseRowHeight = rowHeightFromDensity;
63
- const existingBaseRowHeight = sizes.base;
64
-
65
- if (isResized) {
66
- // Do not recalculate resized row height and use the value from the lookup
67
- baseRowHeight = existingBaseRowHeight;
68
- } else if (getRowHeightProp) {
69
- const rowHeightFromUser = getRowHeightProp(_extends({}, row, {
70
- densityFactor
71
- }));
72
-
73
- if (rowHeightFromUser === 'auto') {
74
- if (needsFirstMeasurement) {
75
- const estimatedRowHeight = getEstimatedRowHeight ? getEstimatedRowHeight(_extends({}, row, {
76
- densityFactor
77
- })) : rowHeightFromDensity; // If the row was not measured yet use the estimated row height
78
-
79
- baseRowHeight = estimatedRowHeight ?? rowHeightFromDensity;
80
- } else {
81
- baseRowHeight = existingBaseRowHeight;
82
- }
83
-
84
- hasRowWithAutoHeight.current = true;
85
- rowsHeightLookup.current[row.id].autoHeight = true;
54
+ };
55
+ }
56
+
57
+ const {
58
+ isResized,
59
+ needsFirstMeasurement,
60
+ sizes
61
+ } = rowsHeightLookup.current[row.id];
62
+ let baseRowHeight = rowHeightFromDensity;
63
+ const existingBaseRowHeight = sizes.base;
64
+
65
+ if (isResized) {
66
+ // Do not recalculate resized row height and use the value from the lookup
67
+ baseRowHeight = existingBaseRowHeight;
68
+ } else if (getRowHeightProp) {
69
+ const rowHeightFromUser = getRowHeightProp(_extends({}, row, {
70
+ densityFactor
71
+ }));
72
+
73
+ if (rowHeightFromUser === 'auto') {
74
+ if (needsFirstMeasurement) {
75
+ const estimatedRowHeight = getEstimatedRowHeight ? getEstimatedRowHeight(_extends({}, row, {
76
+ densityFactor
77
+ })) : rowHeightFromDensity; // If the row was not measured yet use the estimated row height
78
+
79
+ baseRowHeight = estimatedRowHeight ?? rowHeightFromDensity;
86
80
  } else {
87
- // Default back to base rowHeight if getRowHeight returns null or undefined.
88
- baseRowHeight = rowHeightFromUser ?? rowHeightFromDensity;
89
- rowsHeightLookup.current[row.id].needsFirstMeasurement = false;
90
- rowsHeightLookup.current[row.id].autoHeight = false;
81
+ baseRowHeight = existingBaseRowHeight;
91
82
  }
83
+
84
+ hasRowWithAutoHeight.current = true;
85
+ rowsHeightLookup.current[row.id].autoHeight = true;
92
86
  } else {
87
+ // Default back to base rowHeight if getRowHeight returns null or undefined.
88
+ baseRowHeight = rowHeightFromUser ?? rowHeightFromDensity;
93
89
  rowsHeightLookup.current[row.id].needsFirstMeasurement = false;
94
- } // We use an object to make simple to check if a height is already added or not
95
-
96
-
97
- const initialHeights = {
98
- base: baseRowHeight
99
- };
100
-
101
- if (getRowSpacing) {
102
- const indexRelativeToCurrentPage = apiRef.current.getRowIndexRelativeToVisibleRows(row.id);
103
- const spacing = getRowSpacing(_extends({}, row, {
104
- isFirstVisible: indexRelativeToCurrentPage === 0,
105
- isLastVisible: indexRelativeToCurrentPage === currentPage.rows.length - 1,
106
- indexRelativeToCurrentPage
107
- }));
108
- initialHeights.spacingTop = spacing.top ?? 0;
109
- initialHeights.spacingBottom = spacing.bottom ?? 0;
90
+ rowsHeightLookup.current[row.id].autoHeight = false;
110
91
  }
111
-
112
- const processedSizes = apiRef.current.unstable_applyPipeProcessors('rowHeight', initialHeights, row);
113
- rowsHeightLookup.current[row.id].sizes = processedSizes;
114
- const finalRowHeight = Object.values(processedSizes).reduce((acc2, value) => acc2 + value, 0);
115
- return acc + finalRowHeight;
116
- }, 0);
92
+ } else {
93
+ rowsHeightLookup.current[row.id].needsFirstMeasurement = false;
94
+ } // We use an object to make simple to check if a height is already added or not
95
+
96
+
97
+ const initialHeights = {
98
+ base: baseRowHeight
99
+ };
100
+
101
+ if (getRowSpacing) {
102
+ const indexRelativeToCurrentPage = apiRef.current.getRowIndexRelativeToVisibleRows(row.id);
103
+ const spacing = getRowSpacing(_extends({}, row, {
104
+ isFirstVisible: indexRelativeToCurrentPage === 0,
105
+ isLastVisible: indexRelativeToCurrentPage === currentPage.rows.length - 1,
106
+ indexRelativeToCurrentPage
107
+ }));
108
+ initialHeights.spacingTop = spacing.top ?? 0;
109
+ initialHeights.spacingBottom = spacing.bottom ?? 0;
110
+ }
111
+
112
+ const processedSizes = apiRef.current.unstable_applyPipeProcessors('rowHeight', initialHeights, row);
113
+ rowsHeightLookup.current[row.id].sizes = processedSizes;
114
+ const finalRowHeight = Object.values(processedSizes).reduce((acc2, value) => acc2 + value, 0);
115
+ return acc + finalRowHeight;
116
+ }, 0);
117
+ apiRef.current.setState(state => {
117
118
  return _extends({}, state, {
118
119
  rowsMeta: {
119
120
  currentPageTotalHeight,
@@ -142,6 +143,7 @@ export const useGridRowsMeta = (apiRef, props) => {
142
143
  rowsHeightLookup.current[id].needsFirstMeasurement = false;
143
144
  hydrateRowsMeta();
144
145
  }, [hydrateRowsMeta]);
146
+ const debouncedHydrateRowsMeta = React.useMemo(() => debounce(hydrateRowsMeta), [hydrateRowsMeta]);
145
147
  const storeMeasuredRowHeight = React.useCallback((id, height) => {
146
148
  if (!rowsHeightLookup.current[id] || !rowsHeightLookup.current[id].autoHeight) {
147
149
  return;
@@ -153,9 +155,9 @@ export const useGridRowsMeta = (apiRef, props) => {
153
155
  rowsHeightLookup.current[id].sizes.base = height;
154
156
 
155
157
  if (needsHydration) {
156
- hydrateRowsMeta();
158
+ debouncedHydrateRowsMeta();
157
159
  }
158
- }, [hydrateRowsMeta]);
160
+ }, [debouncedHydrateRowsMeta]);
159
161
  const rowHasAutoHeight = React.useCallback(id => {
160
162
  return rowsHeightLookup.current[id]?.autoHeight || false;
161
163
  }, []);
@@ -163,7 +165,7 @@ export const useGridRowsMeta = (apiRef, props) => {
163
165
  return lastMeasuredRowIndex.current;
164
166
  }, []);
165
167
  const setLastMeasuredRowIndex = React.useCallback(index => {
166
- if (hasRowWithAutoHeight.current) {
168
+ if (hasRowWithAutoHeight.current && index > lastMeasuredRowIndex.current) {
167
169
  lastMeasuredRowIndex.current = index;
168
170
  }
169
171
  }, []); // The effect is used to build the rows meta data - currentPageTotalHeight and positions.
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import { unstable_composeClasses as composeClasses } from '@mui/material';
4
4
  import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
5
5
  import { getDataGridUtilityClass } from '../../../constants';
6
- import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../../../colDef';
6
+ import { GRID_CHECKBOX_SELECTION_COL_DEF, GRID_CHECKBOX_SELECTION_FIELD } from '../../../colDef';
7
7
 
8
8
  const useUtilityClasses = ownerState => {
9
9
  const {
@@ -31,14 +31,16 @@ export const useGridSelectionPreProcessors = (apiRef, props) => {
31
31
  });
32
32
 
33
33
  const shouldHaveSelectionColumn = props.checkboxSelection;
34
- const haveSelectionColumn = columnsState.lookup[selectionColumn.field] != null;
34
+ const haveSelectionColumn = columnsState.lookup[GRID_CHECKBOX_SELECTION_FIELD] != null;
35
35
 
36
36
  if (shouldHaveSelectionColumn && !haveSelectionColumn) {
37
- columnsState.lookup[selectionColumn.field] = selectionColumn;
38
- columnsState.all = [selectionColumn.field, ...columnsState.all];
37
+ columnsState.lookup[GRID_CHECKBOX_SELECTION_FIELD] = selectionColumn;
38
+ columnsState.all = [GRID_CHECKBOX_SELECTION_FIELD, ...columnsState.all];
39
39
  } else if (!shouldHaveSelectionColumn && haveSelectionColumn) {
40
- delete columnsState.lookup[selectionColumn.field];
41
- columnsState.all = columnsState.all.filter(field => field !== selectionColumn.field);
40
+ delete columnsState.lookup[GRID_CHECKBOX_SELECTION_FIELD];
41
+ columnsState.all = columnsState.all.filter(field => field !== GRID_CHECKBOX_SELECTION_FIELD);
42
+ } else if (shouldHaveSelectionColumn && haveSelectionColumn) {
43
+ columnsState.lookup[GRID_CHECKBOX_SELECTION_FIELD] = _extends({}, selectionColumn, columnsState.lookup[GRID_CHECKBOX_SELECTION_FIELD]);
42
44
  }
43
45
 
44
46
  return columnsState;
@@ -19,7 +19,7 @@ import { gridRowsMetaSelector } from '../rows/gridRowsMetaSelector';
19
19
  import { getFirstNonSpannedColumnToRender } from '../columns/gridColumnsUtils'; // Uses binary search to avoid looping through all possible positions
20
20
 
21
21
  import { jsx as _jsx } from "react/jsx-runtime";
22
- export function getIndexFromScroll(offset, positions, sliceStart = 0, sliceEnd = positions.length) {
22
+ export function binarySearch(offset, positions, sliceStart = 0, sliceEnd = positions.length) {
23
23
  if (positions.length <= 0) {
24
24
  return -1;
25
25
  }
@@ -30,8 +30,20 @@ export function getIndexFromScroll(offset, positions, sliceStart = 0, sliceEnd =
30
30
 
31
31
  const pivot = sliceStart + Math.floor((sliceEnd - sliceStart) / 2);
32
32
  const itemOffset = positions[pivot];
33
- return offset <= itemOffset ? getIndexFromScroll(offset, positions, sliceStart, pivot) : getIndexFromScroll(offset, positions, pivot + 1, sliceEnd);
33
+ return offset <= itemOffset ? binarySearch(offset, positions, sliceStart, pivot) : binarySearch(offset, positions, pivot + 1, sliceEnd);
34
34
  }
35
+
36
+ function exponentialSearch(offset, positions, index) {
37
+ let interval = 1;
38
+
39
+ while (index < positions.length && positions[index] < offset) {
40
+ index += interval;
41
+ interval *= 2;
42
+ }
43
+
44
+ return binarySearch(offset, positions, Math.floor(index / 2), Math.min(index, positions.length));
45
+ }
46
+
35
47
  export const getRenderableIndexes = ({
36
48
  firstIndex,
37
49
  lastIndex,
@@ -73,6 +85,22 @@ export const useGridVirtualScroller = props => {
73
85
  });
74
86
  const [containerWidth, setContainerWidth] = React.useState(null);
75
87
  const prevTotalWidth = React.useRef(columnsTotalWidth);
88
+ const getNearestIndexToRender = React.useCallback(offset => {
89
+ const lastMeasuredIndex = Math.max(0, apiRef.current.unstable_getLastMeasuredRowIndex());
90
+ const allRowsMeasured = lastMeasuredIndex === Infinity;
91
+
92
+ if (allRowsMeasured || rowsMeta.positions[lastMeasuredIndex] >= offset) {
93
+ // If all rows were measured (when no row has "auto" as height) or all rows before the offset
94
+ // were measured, then use a binary search because it's faster.
95
+ return binarySearch(offset, rowsMeta.positions);
96
+ } // Otherwise, use an exponential search.
97
+ // If rows have "auto" as height, their positions will be based on estimated heights.
98
+ // In this case, we can skip several steps until we find a position higher than the offset.
99
+ // Inspired by https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/utils/CellSizeAndPositionManager.js
100
+
101
+
102
+ return exponentialSearch(offset, rowsMeta.positions, lastMeasuredIndex);
103
+ }, [apiRef, rowsMeta.positions]);
76
104
  const computeRenderContext = React.useCallback(() => {
77
105
  if (disableVirtualization) {
78
106
  return {
@@ -86,9 +114,11 @@ export const useGridVirtualScroller = props => {
86
114
  const {
87
115
  top,
88
116
  left
89
- } = scrollPosition.current;
90
- const firstRowIndex = Math.min(Math.max(0, apiRef.current.unstable_getLastMeasuredRowIndex()), getIndexFromScroll(top, rowsMeta.positions));
91
- const lastRowIndex = rootProps.autoHeight ? firstRowIndex + currentPage.rows.length : getIndexFromScroll(top + rootRef.current.clientHeight, rowsMeta.positions);
117
+ } = scrollPosition.current; // Clamp the value because the search may return an index out of bounds.
118
+ // In the last index, this is not needed because Array.slice doesn't include it.
119
+
120
+ const firstRowIndex = Math.min(getNearestIndexToRender(top), rowsMeta.positions.length - 1);
121
+ const lastRowIndex = rootProps.autoHeight ? firstRowIndex + currentPage.rows.length : getNearestIndexToRender(top + rootRef.current.clientHeight);
92
122
  let hasRowWithAutoHeight = false;
93
123
  let firstColumnIndex = 0;
94
124
  let lastColumnIndex = columnPositions.length;
@@ -106,8 +136,8 @@ export const useGridVirtualScroller = props => {
106
136
  }
107
137
 
108
138
  if (!hasRowWithAutoHeight) {
109
- firstColumnIndex = getIndexFromScroll(left, columnPositions);
110
- lastColumnIndex = getIndexFromScroll(left + containerWidth, columnPositions);
139
+ firstColumnIndex = binarySearch(left, columnPositions);
140
+ lastColumnIndex = binarySearch(left + containerWidth, columnPositions);
111
141
  }
112
142
 
113
143
  return {
@@ -116,7 +146,7 @@ export const useGridVirtualScroller = props => {
116
146
  firstColumnIndex,
117
147
  lastColumnIndex
118
148
  };
119
- }, [disableVirtualization, rowsMeta.positions, rootProps.autoHeight, rootProps.rowBuffer, currentPage.rows, columnPositions, visibleColumns.length, apiRef, containerWidth]);
149
+ }, [disableVirtualization, getNearestIndexToRender, rowsMeta.positions.length, rootProps.autoHeight, rootProps.rowBuffer, currentPage.rows, columnPositions, visibleColumns.length, apiRef, containerWidth]);
120
150
  React.useEffect(() => {
121
151
  if (disableVirtualization) {
122
152
  renderZoneRef.current.style.transform = `translate3d(0px, 0px, 0px)`;
@@ -372,6 +402,10 @@ export const useGridVirtualScroller = props => {
372
402
  rootStyle.overflowX = 'hidden';
373
403
  }
374
404
 
405
+ if (rootProps.autoHeight) {
406
+ rootStyle.overflowY = 'hidden';
407
+ }
408
+
375
409
  const getRenderContext = React.useCallback(() => {
376
410
  return prevRenderContext.current;
377
411
  }, []);
package/modern/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.12.1
1
+ /** @license MUI v5.12.2
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -107,6 +107,7 @@ const arSDGrid = {
107
107
  groupColumn: name => `تجميع حسب ${name}`,
108
108
  unGroupColumn: name => `إيقاف التجميع حسب ${name}`,
109
109
  // Master/detail
110
+ // detailPanelToggle: 'Detail panel toggle',
110
111
  expandDetailPanel: 'توسيع',
111
112
  collapseDetailPanel: 'طوي' // Row reordering text
112
113
  // rowReorderingHeaderName: 'Row reordering',
@@ -107,6 +107,7 @@ const bgBGGrid = {
107
107
  groupColumn: name => `Групирай по ${name}`,
108
108
  unGroupColumn: name => `Спри групиране по ${name}`,
109
109
  // Master/detail
110
+ // detailPanelToggle: 'Detail panel toggle',
110
111
  expandDetailPanel: 'Разгъване',
111
112
  collapseDetailPanel: 'Свиване' // Row reordering text
112
113
  // rowReorderingHeaderName: 'Row reordering',
@@ -141,6 +141,7 @@ const csCZGrid = {
141
141
  groupingColumnHeaderName: 'Skupina',
142
142
  groupColumn: name => `Zoskupit podle ${name}`,
143
143
  unGroupColumn: name => `Přestat zoskupovat podle ${name}` // Master/detail
144
+ // detailPanelToggle: 'Detail panel toggle',
144
145
  // expandDetailPanel: 'Expand',
145
146
  // collapseDetailPanel: 'Collapse',
146
147
  // Row reordering text
@@ -107,6 +107,7 @@ const daDKGrid = {
107
107
  groupColumn: name => `Gruppér efter ${name}`,
108
108
  unGroupColumn: name => `Fjern gruppéring efter ${name}`,
109
109
  // Master/detail
110
+ // detailPanelToggle: 'Detail panel toggle',
110
111
  expandDetailPanel: 'Udvid',
111
112
  collapseDetailPanel: 'Kollaps' // Row reordering text
112
113
  // rowReorderingHeaderName: 'Row reordering',
@@ -107,6 +107,7 @@ const deDEGrid = {
107
107
  groupColumn: name => `Gruppieren nach ${name}`,
108
108
  unGroupColumn: name => `Gruppierung nach ${name} aufheben`,
109
109
  // Master/detail
110
+ // detailPanelToggle: 'Detail panel toggle',
110
111
  expandDetailPanel: 'Aufklappen',
111
112
  collapseDetailPanel: 'Zuklappen',
112
113
  // Row reordering text
@@ -105,6 +105,7 @@ const elGRGrid = {
105
105
  // groupColumn: name => `Group by ${name}`,
106
106
  // unGroupColumn: name => `Stop grouping by ${name}`,
107
107
  // Master/detail
108
+ // detailPanelToggle: 'Detail panel toggle',
108
109
  // expandDetailPanel: 'Expand',
109
110
  // collapseDetailPanel: 'Collapse',
110
111
  // Row reordering text
@@ -106,6 +106,7 @@ const esESGrid = {
106
106
  // groupColumn: name => `Group by ${name}`,
107
107
  // unGroupColumn: name => `Stop grouping by ${name}`,
108
108
  // Master/detail
109
+ // detailPanelToggle: 'Detail panel toggle',
109
110
  // expandDetailPanel: 'Expand',
110
111
  // collapseDetailPanel: 'Collapse',
111
112
  // Row reordering text
@@ -107,6 +107,7 @@ const faIRGrid = {
107
107
  groupColumn: name => `گروه‌بندی براساس ${name}`,
108
108
  unGroupColumn: name => `لغو گروه‌بندی براساس ${name}`,
109
109
  // Master/detail
110
+ // detailPanelToggle: 'Detail panel toggle',
110
111
  expandDetailPanel: 'بازکردن پنل جزئیات',
111
112
  collapseDetailPanel: 'بستن پنل جزئیات' // Row reordering text
112
113
  // rowReorderingHeaderName: 'Row reordering',
@@ -106,6 +106,7 @@ const fiFIGrid = {
106
106
  // groupColumn: name => `Group by ${name}`,
107
107
  // unGroupColumn: name => `Stop grouping by ${name}`,
108
108
  // Master/detail
109
+ // detailPanelToggle: 'Detail panel toggle',
109
110
  // expandDetailPanel: 'Expand',
110
111
  // collapseDetailPanel: 'Collapse',
111
112
  // Row reordering text
@@ -106,6 +106,7 @@ const frFRGrid = {
106
106
  groupingColumnHeaderName: 'Groupe',
107
107
  groupColumn: name => `Grouper par ${name}`,
108
108
  unGroupColumn: name => `Arrêter de grouper par ${name}` // Master/detail
109
+ // detailPanelToggle: 'Detail panel toggle',
109
110
  // expandDetailPanel: 'Expand',
110
111
  // collapseDetailPanel: 'Collapse',
111
112
  // Row reordering text
@@ -107,6 +107,7 @@ const heILGrid = {
107
107
  groupColumn: name => `קבץ לפי ${name}`,
108
108
  unGroupColumn: name => `הפסק לקבץ לפי ${name}`,
109
109
  // Master/detail
110
+ // detailPanelToggle: 'Detail panel toggle',
110
111
  expandDetailPanel: 'הרחב',
111
112
  collapseDetailPanel: 'כווץ',
112
113
  // Row reordering text
@@ -107,6 +107,7 @@ const huHUGrid = {
107
107
  groupColumn: name => `Csoportosítás ${name} szerint`,
108
108
  unGroupColumn: name => `${name} szerinti csoportosítás törlése`,
109
109
  // Master/detail
110
+ // detailPanelToggle: 'Detail panel toggle',
110
111
  expandDetailPanel: 'Kibontás',
111
112
  collapseDetailPanel: 'Összecsukás' // Row reordering text
112
113
  // rowReorderingHeaderName: 'Row reordering',
@@ -106,6 +106,7 @@ const itITGrid = {
106
106
  groupingColumnHeaderName: 'Gruppo',
107
107
  groupColumn: name => `Raggruppa per ${name}`,
108
108
  unGroupColumn: name => `Annulla raggruppamento per ${name}` // Master/detail
109
+ // detailPanelToggle: 'Detail panel toggle',
109
110
  // expandDetailPanel: 'Expand',
110
111
  // collapseDetailPanel: 'Collapse',
111
112
  // Row reordering text