@mui/x-data-grid 7.0.0-beta.4 → 7.0.0-beta.5

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 (90) hide show
  1. package/CHANGELOG.md +138 -14
  2. package/DataGrid/DataGrid.js +2 -0
  3. package/colDef/gridBooleanOperators.js +1 -1
  4. package/components/GridRow.d.ts +7 -9
  5. package/components/GridRow.js +36 -47
  6. package/components/cell/GridCell.d.ts +2 -1
  7. package/components/cell/GridCell.js +7 -3
  8. package/components/cell/GridSkeletonCell.d.ts +3 -2
  9. package/components/cell/GridSkeletonCell.js +14 -6
  10. package/components/columnSelection/GridCellCheckboxRenderer.js +6 -4
  11. package/components/columnsManagement/GridColumnsManagement.js +1 -1
  12. package/components/containers/GridRootStyles.js +9 -2
  13. package/components/virtualization/GridBottomContainer.js +1 -1
  14. package/components/virtualization/GridTopContainer.js +1 -1
  15. package/components/virtualization/GridVirtualScroller.js +2 -2
  16. package/components/virtualization/GridVirtualScrollerRenderZone.js +9 -3
  17. package/hooks/features/columnHeaders/useGridColumnHeaders.js +11 -8
  18. package/hooks/features/columns/gridColumnsSelector.d.ts +6 -0
  19. package/hooks/features/columns/gridColumnsSelector.js +8 -1
  20. package/hooks/features/columns/useGridColumns.js +4 -0
  21. package/hooks/features/editing/useGridRowEditing.js +1 -2
  22. package/hooks/features/filter/useGridFilter.js +2 -2
  23. package/hooks/features/rows/useGridRows.js +8 -4
  24. package/hooks/features/rows/useGridRowsMeta.js +5 -13
  25. package/hooks/features/sorting/gridSortingUtils.js +9 -1
  26. package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +0 -9
  27. package/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -7
  28. package/hooks/features/virtualization/useGridVirtualScroller.d.ts +3 -0
  29. package/hooks/features/virtualization/useGridVirtualScroller.js +82 -138
  30. package/hooks/features/virtualization/useGridVirtualization.d.ts +0 -8
  31. package/hooks/features/virtualization/useGridVirtualization.js +1 -6
  32. package/hooks/utils/useTimeout.d.ts +5 -3
  33. package/hooks/utils/useTimeout.js +13 -5
  34. package/index.js +1 -1
  35. package/models/colDef/gridColDef.d.ts +7 -0
  36. package/modern/DataGrid/DataGrid.js +2 -0
  37. package/modern/colDef/gridBooleanOperators.js +1 -1
  38. package/modern/components/GridRow.js +35 -46
  39. package/modern/components/cell/GridCell.js +7 -3
  40. package/modern/components/cell/GridSkeletonCell.js +14 -6
  41. package/modern/components/columnSelection/GridCellCheckboxRenderer.js +6 -4
  42. package/modern/components/columnsManagement/GridColumnsManagement.js +1 -1
  43. package/modern/components/containers/GridRootStyles.js +9 -2
  44. package/modern/components/virtualization/GridBottomContainer.js +1 -1
  45. package/modern/components/virtualization/GridTopContainer.js +1 -1
  46. package/modern/components/virtualization/GridVirtualScroller.js +2 -2
  47. package/modern/components/virtualization/GridVirtualScrollerRenderZone.js +8 -3
  48. package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +11 -8
  49. package/modern/hooks/features/columns/gridColumnsSelector.js +8 -1
  50. package/modern/hooks/features/columns/useGridColumns.js +2 -0
  51. package/modern/hooks/features/editing/useGridRowEditing.js +1 -2
  52. package/modern/hooks/features/filter/useGridFilter.js +2 -2
  53. package/modern/hooks/features/rows/useGridRows.js +8 -4
  54. package/modern/hooks/features/rows/useGridRowsMeta.js +5 -13
  55. package/modern/hooks/features/sorting/gridSortingUtils.js +9 -1
  56. package/modern/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -7
  57. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +80 -136
  58. package/modern/hooks/features/virtualization/useGridVirtualization.js +1 -6
  59. package/modern/hooks/utils/useTimeout.js +13 -5
  60. package/modern/index.js +1 -1
  61. package/modern/utils/utils.js +9 -0
  62. package/node/DataGrid/DataGrid.js +1 -0
  63. package/node/colDef/gridBooleanOperators.js +1 -1
  64. package/node/components/GridRow.js +35 -46
  65. package/node/components/cell/GridCell.js +7 -3
  66. package/node/components/cell/GridSkeletonCell.js +15 -7
  67. package/node/components/columnSelection/GridCellCheckboxRenderer.js +6 -4
  68. package/node/components/columnsManagement/GridColumnsManagement.js +1 -1
  69. package/node/components/containers/GridRootStyles.js +9 -2
  70. package/node/components/virtualization/GridBottomContainer.js +1 -1
  71. package/node/components/virtualization/GridTopContainer.js +1 -1
  72. package/node/components/virtualization/GridVirtualScroller.js +2 -2
  73. package/node/components/virtualization/GridVirtualScrollerRenderZone.js +7 -2
  74. package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +8 -5
  75. package/node/hooks/features/columns/gridColumnsSelector.js +9 -2
  76. package/node/hooks/features/columns/useGridColumns.js +2 -0
  77. package/node/hooks/features/editing/useGridRowEditing.js +1 -2
  78. package/node/hooks/features/filter/useGridFilter.js +2 -2
  79. package/node/hooks/features/rows/useGridRows.js +8 -4
  80. package/node/hooks/features/rows/useGridRowsMeta.js +5 -13
  81. package/node/hooks/features/sorting/gridSortingUtils.js +9 -1
  82. package/node/hooks/features/virtualization/gridVirtualizationSelectors.js +1 -8
  83. package/node/hooks/features/virtualization/useGridVirtualScroller.js +81 -136
  84. package/node/hooks/features/virtualization/useGridVirtualization.js +2 -7
  85. package/node/hooks/utils/useTimeout.js +13 -4
  86. package/node/index.js +1 -1
  87. package/node/utils/utils.js +12 -1
  88. package/package.json +1 -1
  89. package/utils/utils.d.ts +4 -0
  90. package/utils/utils.js +9 -0
@@ -6,17 +6,16 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.EMPTY_DETAIL_PANELS = void 0;
8
8
  exports.areRenderContextsEqual = areRenderContextsEqual;
9
+ exports.computeOffsetLeft = computeOffsetLeft;
9
10
  exports.useGridVirtualScroller = void 0;
10
11
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
12
  var React = _interopRequireWildcard(require("react"));
12
13
  var ReactDOM = _interopRequireWildcard(require("react-dom"));
13
14
  var _utils = require("@mui/utils");
14
15
  var _styles = require("@mui/material/styles");
15
- var _reselect = require("reselect");
16
16
  var _useGridPrivateApiContext = require("../../utils/useGridPrivateApiContext");
17
17
  var _useGridRootProps = require("../../utils/useGridRootProps");
18
18
  var _useGridSelector = require("../../utils/useGridSelector");
19
- var _useLazyRef = require("../../utils/useLazyRef");
20
19
  var _useResizeObserver = require("../../utils/useResizeObserver");
21
20
  var _useRunOnce = require("../../utils/useRunOnce");
22
21
  var _gridColumnsSelector = require("../columns/gridColumnsSelector");
@@ -24,7 +23,8 @@ var _gridDimensionsSelectors = require("../dimensions/gridDimensionsSelectors");
24
23
  var _gridRowsSelector = require("../rows/gridRowsSelector");
25
24
  var _gridFocusStateSelector = require("../focus/gridFocusStateSelector");
26
25
  var _useGridVisibleRows = require("../../utils/useGridVisibleRows");
27
- var _utils2 = require("../../../utils/utils");
26
+ var _utils2 = require("../../utils");
27
+ var _utils3 = require("../../../utils/utils");
28
28
  var _gridRowSelectionSelector = require("../rowSelection/gridRowSelectionSelector");
29
29
  var _gridRowsMetaSelector = require("../rows/gridRowsMetaSelector");
30
30
  var _gridColumnsUtils = require("../columns/gridColumnsUtils");
@@ -60,40 +60,29 @@ const useGridVirtualScroller = () => {
60
60
  const scrollbarHorizontalRef = React.useRef(null);
61
61
  const contentHeight = dimensions.contentSize.height;
62
62
  const columnsTotalWidth = dimensions.columnsTotalWidth;
63
+ const hasColSpan = (0, _useGridSelector.useGridSelector)(apiRef, _gridColumnsSelector.gridHasColSpanSelector);
63
64
  (0, _useResizeObserver.useResizeObserver)(mainRef, () => apiRef.current.resize());
64
65
  const previousContext = React.useRef(_useGridVirtualization.EMPTY_RENDER_CONTEXT);
65
66
  const previousRowContext = React.useRef(_useGridVirtualization.EMPTY_RENDER_CONTEXT);
66
- const offsets = (0, _useGridSelector.useGridSelector)(apiRef, _gridVirtualizationSelectors.gridOffsetsSelector);
67
67
  const renderContext = (0, _useGridSelector.useGridSelector)(apiRef, _gridVirtualizationSelectors.gridRenderContextSelector);
68
68
  const scrollPosition = React.useRef({
69
69
  top: 0,
70
70
  left: 0
71
71
  }).current;
72
72
  const prevTotalWidth = React.useRef(columnsTotalWidth);
73
- const getRenderedColumns = (0, _useLazyRef.useLazyRef)(createGetRenderedColumns).current;
74
- const indexOfRowWithFocusedCell = React.useMemo(() => {
75
- if (cellFocus !== null) {
76
- return currentPage.rows.findIndex(row => row.id === cellFocus.id);
77
- }
78
- return -1;
79
- }, [cellFocus, currentPage.rows]);
80
- const indexOfColumnWithFocusedCell = React.useMemo(() => {
81
- if (cellFocus !== null) {
82
- return visibleColumns.findIndex(column => column.field === cellFocus.field);
83
- }
84
- return -1;
85
- }, [cellFocus, visibleColumns]);
73
+ const focusedCell = {
74
+ rowIndex: React.useMemo(() => cellFocus ? currentPage.rows.findIndex(row => row.id === cellFocus.id) : -1, [cellFocus, currentPage.rows]),
75
+ columnIndex: React.useMemo(() => cellFocus ? visibleColumns.findIndex(column => column.field === cellFocus.field) : -1, [cellFocus, visibleColumns])
76
+ };
86
77
  const updateRenderContext = React.useCallback((nextRenderContext, rawRenderContext) => {
87
78
  if (areRenderContextsEqual(nextRenderContext, apiRef.current.state.virtualization.renderContext)) {
88
79
  return;
89
80
  }
90
81
  const didRowsIntervalChange = nextRenderContext.firstRowIndex !== previousRowContext.current.firstRowIndex || nextRenderContext.lastRowIndex !== previousRowContext.current.lastRowIndex;
91
- const nextOffsets = computeOffsets(apiRef, nextRenderContext, theme.direction, pinnedColumns.left.length);
92
82
  apiRef.current.setState(state => {
93
83
  return (0, _extends2.default)({}, state, {
94
84
  virtualization: (0, _extends2.default)({}, state.virtualization, {
95
- renderContext: nextRenderContext,
96
- offsets: nextOffsets
85
+ renderContext: nextRenderContext
97
86
  })
98
87
  });
99
88
  });
@@ -107,7 +96,7 @@ const useGridVirtualScroller = () => {
107
96
  }
108
97
  previousContext.current = rawRenderContext;
109
98
  prevTotalWidth.current = dimensions.columnsTotalWidth;
110
- }, [apiRef, pinnedColumns.left.length, theme.direction, dimensions.isReady, dimensions.columnsTotalWidth]);
99
+ }, [apiRef, dimensions.isReady, dimensions.columnsTotalWidth]);
111
100
  const triggerUpdateRenderContext = () => {
112
101
  const inputs = inputsSelector(apiRef, rootProps, enabled, enabledForColumns);
113
102
  const [nextRenderContext, rawRenderContext] = computeRenderContext(inputs, scrollPosition);
@@ -168,9 +157,12 @@ const useGridVirtualScroller = () => {
168
157
  const handleTouchMove = (0, _utils.unstable_useEventCallback)(event => {
169
158
  apiRef.current.publishEvent('virtualScrollerTouchMove', {}, event);
170
159
  });
171
- const minFirstColumn = pinnedColumns.left.length;
172
- const maxLastColumn = visibleColumns.length - pinnedColumns.right.length;
173
160
  const getRows = (params = {}) => {
161
+ if (!params.rows && !currentPage.range) {
162
+ return [];
163
+ }
164
+ const columnPositions = (0, _gridColumnsSelector.gridColumnPositionsSelector)(apiRef);
165
+ const currentRenderContext = params.renderContext ?? renderContext;
174
166
  const isLastSection = !hasBottomPinnedRows && params.position === undefined || hasBottomPinnedRows && params.position === 'bottom';
175
167
  const isPinnedSection = params.position !== undefined;
176
168
  let rowIndexOffset;
@@ -187,77 +179,57 @@ const useGridVirtualScroller = () => {
187
179
  rowIndexOffset = pinnedRows.top.length;
188
180
  break;
189
181
  }
190
- const firstRowToRender = renderContext.firstRowIndex;
191
- const lastRowToRender = renderContext.lastRowIndex;
192
- const firstColumnToRender = renderContext.firstColumnIndex;
193
- const lastColumnToRender = renderContext.lastColumnIndex;
194
- if (!params.rows && !currentPage.range) {
195
- return [];
196
- }
197
- const renderedRows = params.rows ?? currentPage.rows.slice(firstRowToRender, lastRowToRender);
198
-
199
- // If the selected row is not within the current range of rows being displayed,
200
- // we need to render it at either the top or bottom of the rows,
201
- // depending on whether it is above or below the range.
202
- let isRowWithFocusedCellNotInRange = false;
203
- if (!isPinnedSection && indexOfRowWithFocusedCell > -1 && (firstRowToRender > indexOfRowWithFocusedCell || lastRowToRender < indexOfRowWithFocusedCell)) {
204
- isRowWithFocusedCellNotInRange = true;
205
- const rowWithFocusedCell = currentPage.rows[indexOfRowWithFocusedCell];
206
- if (indexOfRowWithFocusedCell > firstRowToRender) {
207
- renderedRows.push(rowWithFocusedCell);
208
- } else {
209
- renderedRows.unshift(rowWithFocusedCell);
210
- }
211
- }
212
- let isColumnWihFocusedCellNotInRange = false;
213
- if (!isPinnedSection && (firstColumnToRender > indexOfColumnWithFocusedCell || lastColumnToRender < indexOfColumnWithFocusedCell)) {
214
- isColumnWihFocusedCellNotInRange = true;
215
- }
216
- const {
217
- focusedCellColumnIndexNotInRange,
218
- renderedColumns
219
- } = getRenderedColumns(visibleColumns, firstColumnToRender, lastColumnToRender, minFirstColumn, maxLastColumn, isColumnWihFocusedCellNotInRange ? indexOfColumnWithFocusedCell : -1);
220
- renderedRows.forEach(row => {
221
- apiRef.current.calculateColSpan({
222
- rowId: row.id,
223
- minFirstColumn,
224
- maxLastColumn,
225
- columns: visibleColumns
226
- });
227
- if (pinnedColumns.left.length > 0) {
228
- apiRef.current.calculateColSpan({
229
- rowId: row.id,
230
- minFirstColumn: 0,
231
- maxLastColumn: pinnedColumns.left.length,
232
- columns: visibleColumns
233
- });
182
+ const rowModels = params.rows ?? currentPage.rows;
183
+ const firstRowToRender = currentRenderContext.firstRowIndex;
184
+ const lastRowToRender = Math.min(currentRenderContext.lastRowIndex, rowModels.length);
185
+ const rowIndexes = params.rows ? (0, _utils3.range)(0, params.rows.length) : (0, _utils3.range)(firstRowToRender, lastRowToRender);
186
+ let virtualRowIndex = -1;
187
+ if (!isPinnedSection && focusedCell.rowIndex !== -1) {
188
+ if (focusedCell.rowIndex < firstRowToRender) {
189
+ virtualRowIndex = focusedCell.rowIndex;
190
+ rowIndexes.unshift(virtualRowIndex);
234
191
  }
235
- if (pinnedColumns.right.length > 0) {
236
- apiRef.current.calculateColSpan({
237
- rowId: row.id,
238
- minFirstColumn: visibleColumns.length - pinnedColumns.right.length,
239
- maxLastColumn: visibleColumns.length,
240
- columns: visibleColumns
241
- });
192
+ if (focusedCell.rowIndex >= lastRowToRender) {
193
+ virtualRowIndex = focusedCell.rowIndex;
194
+ rowIndexes.push(virtualRowIndex);
242
195
  }
243
- });
196
+ }
244
197
  const rows = [];
245
198
  const rowProps = rootProps.slotProps?.row;
246
- let isRowWithFocusedCellRendered = false;
247
- for (let i = 0; i < renderedRows.length; i += 1) {
199
+ rowIndexes.forEach(rowIndexInPage => {
248
200
  const {
249
201
  id,
250
202
  model
251
- } = renderedRows[i];
252
- const rowIndexInPage = (currentPage?.range?.firstRowIndex || 0) + firstRowToRender + i;
253
- let index = rowIndexOffset + rowIndexInPage;
254
- if (isRowWithFocusedCellNotInRange && cellFocus?.id === id) {
255
- index = indexOfRowWithFocusedCell;
256
- isRowWithFocusedCellRendered = true;
257
- } else if (isRowWithFocusedCellRendered) {
258
- index -= 1;
203
+ } = rowModels[rowIndexInPage];
204
+
205
+ // NOTE: This is an expensive feature, the colSpan code could be optimized.
206
+ if (hasColSpan) {
207
+ const minFirstColumn = pinnedColumns.left.length;
208
+ const maxLastColumn = visibleColumns.length - pinnedColumns.right.length;
209
+ apiRef.current.calculateColSpan({
210
+ rowId: id,
211
+ minFirstColumn,
212
+ maxLastColumn,
213
+ columns: visibleColumns
214
+ });
215
+ if (pinnedColumns.left.length > 0) {
216
+ apiRef.current.calculateColSpan({
217
+ rowId: id,
218
+ minFirstColumn: 0,
219
+ maxLastColumn: pinnedColumns.left.length,
220
+ columns: visibleColumns
221
+ });
222
+ }
223
+ if (pinnedColumns.right.length > 0) {
224
+ apiRef.current.calculateColSpan({
225
+ rowId: id,
226
+ minFirstColumn: visibleColumns.length - pinnedColumns.right.length,
227
+ maxLastColumn: visibleColumns.length,
228
+ columns: visibleColumns
229
+ });
230
+ }
259
231
  }
260
- const isRowNotVisible = isRowWithFocusedCellNotInRange && cellFocus.id === id;
232
+ const hasFocus = cellFocus?.id === id;
261
233
  const baseRowHeight = !apiRef.current.rowHasAutoHeight(id) ? apiRef.current.unstable_getRowHeight(id) : 'auto';
262
234
  let isSelected;
263
235
  if (selectedRowsLookup[id] == null) {
@@ -273,47 +245,46 @@ const useGridVirtualScroller = () => {
273
245
  if (isLastSection) {
274
246
  if (!isPinnedSection) {
275
247
  const lastIndex = currentPage.rows.length - 1;
276
- const isLastVisibleRowIndex = isRowWithFocusedCellNotInRange ? firstRowToRender + i === lastIndex + 1 : firstRowToRender + i === lastIndex;
248
+ const isLastVisibleRowIndex = rowIndexInPage === lastIndex;
277
249
  if (isLastVisibleRowIndex) {
278
250
  isLastVisible = true;
279
251
  }
280
252
  } else {
281
- isLastVisible = i === renderedRows.length - 1;
253
+ isLastVisible = rowIndexInPage === rowModels.length - 1;
282
254
  }
283
255
  }
284
- const focusedCell = cellFocus !== null && cellFocus.id === id ? cellFocus.field : null;
285
- const columnWithFocusedCellNotInRange = focusedCellColumnIndexNotInRange !== undefined && visibleColumns[focusedCellColumnIndexNotInRange];
286
- const renderedColumnsWithFocusedCell = columnWithFocusedCellNotInRange && focusedCell ? [columnWithFocusedCellNotInRange, ...renderedColumns] : renderedColumns;
256
+ const isVirtualRow = rowIndexInPage === virtualRowIndex;
257
+ const isNotVisible = isVirtualRow;
287
258
  let tabbableCell = null;
288
259
  if (cellTabIndex !== null && cellTabIndex.id === id) {
289
260
  const cellParams = apiRef.current.getCellParams(id, cellTabIndex.field);
290
261
  tabbableCell = cellParams.cellMode === 'view' ? cellTabIndex.field : null;
291
262
  }
263
+ const offsetLeft = computeOffsetLeft(columnPositions, currentRenderContext, theme.direction, pinnedColumns.left.length);
264
+ const rowIndex = (currentPage?.range?.firstRowIndex || 0) + rowIndexOffset + rowIndexInPage;
292
265
  rows.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.row, (0, _extends2.default)({
293
266
  row: model,
294
267
  rowId: id,
295
- index: index,
268
+ index: rowIndex,
269
+ selected: isSelected,
270
+ offsetTop: params.rows ? undefined : rowsMeta.positions[rowIndexInPage],
271
+ offsetLeft: offsetLeft,
272
+ dimensions: dimensions,
296
273
  rowHeight: baseRowHeight,
297
- focusedCell: focusedCell,
298
274
  tabbableCell: tabbableCell,
299
- focusedCellColumnIndexNotInRange: focusedCellColumnIndexNotInRange,
300
- renderedColumns: renderedColumnsWithFocusedCell,
301
- visibleColumns: visibleColumns,
302
275
  pinnedColumns: pinnedColumns,
303
- firstColumnToRender: firstColumnToRender,
304
- lastColumnToRender: lastColumnToRender,
305
- selected: isSelected,
306
- offsets: offsets,
307
- dimensions: dimensions,
276
+ visibleColumns: visibleColumns,
277
+ renderContext: currentRenderContext,
278
+ focusedColumnIndex: hasFocus ? focusedCell.columnIndex : undefined,
308
279
  isFirstVisible: isFirstVisible,
309
280
  isLastVisible: isLastVisible,
310
- isNotVisible: isRowNotVisible
281
+ isNotVisible: isNotVisible
311
282
  }, rowProps), id));
312
283
  const panel = panels.get(id);
313
284
  if (panel) {
314
285
  rows.push(panel);
315
286
  }
316
- }
287
+ });
317
288
  return rows;
318
289
  };
319
290
  const needsHorizontalScrollbar = outerSize.width && columnsTotalWidth >= outerSize.width;
@@ -366,6 +337,9 @@ const useGridVirtualScroller = () => {
366
337
  apiRef.current.register('private', {
367
338
  updateRenderContext: forceUpdateRenderContext
368
339
  });
340
+ (0, _utils2.useGridApiEventHandler)(apiRef, 'columnsChange', forceUpdateRenderContext);
341
+ (0, _utils2.useGridApiEventHandler)(apiRef, 'filteredRowsSet', forceUpdateRenderContext);
342
+ (0, _utils2.useGridApiEventHandler)(apiRef, 'rowExpansionChange', forceUpdateRenderContext);
369
343
  return {
370
344
  renderContext,
371
345
  setPanels,
@@ -400,29 +374,6 @@ const useGridVirtualScroller = () => {
400
374
  };
401
375
  };
402
376
  exports.useGridVirtualScroller = useGridVirtualScroller;
403
- function createGetRenderedColumns() {
404
- return (0, _reselect.defaultMemoize)((columns, firstColumnToRender, lastColumnToRender, minFirstColumn, maxLastColumn, indexOfColumnWithFocusedCell) => {
405
- // If the selected column is not within the current range of columns being displayed,
406
- // we need to render it at either the left or right of the columns,
407
- // depending on whether it is above or below the range.
408
- let focusedCellColumnIndexNotInRange;
409
- const renderedColumns = columns.slice(firstColumnToRender, lastColumnToRender);
410
- if (indexOfColumnWithFocusedCell > -1) {
411
- // check if it is not on the left pinned column.
412
- if (firstColumnToRender > indexOfColumnWithFocusedCell && indexOfColumnWithFocusedCell >= minFirstColumn) {
413
- focusedCellColumnIndexNotInRange = indexOfColumnWithFocusedCell;
414
- }
415
- // check if it is not on the right pinned column.
416
- else if (lastColumnToRender < indexOfColumnWithFocusedCell && indexOfColumnWithFocusedCell < maxLastColumn) {
417
- focusedCellColumnIndexNotInRange = indexOfColumnWithFocusedCell;
418
- }
419
- }
420
- return {
421
- focusedCellColumnIndexNotInRange,
422
- renderedColumns
423
- };
424
- });
425
- }
426
377
  function inputsSelector(apiRef, rootProps, enabled, enabledForColumns) {
427
378
  const dimensions = (0, _gridDimensionsSelectors.gridDimensionsSelector)(apiRef.current.state);
428
379
  const currentPage = (0, _useGridVisibleRows.getVisibleRows)(apiRef, rootProps);
@@ -505,7 +456,7 @@ function getNearestIndexToRender(inputs, offset) {
505
456
  // Check if all rows in this page are already measured
506
457
  allRowsMeasured = lastMeasuredIndexRelativeToAllRows >= inputs.range.lastRowIndex;
507
458
  }
508
- const lastMeasuredIndexRelativeToCurrentPage = (0, _utils2.clamp)(lastMeasuredIndexRelativeToAllRows - (inputs.range?.firstRowIndex || 0), 0, inputs.rowsMeta.positions.length);
459
+ const lastMeasuredIndexRelativeToCurrentPage = (0, _utils3.clamp)(lastMeasuredIndexRelativeToAllRows - (inputs.range?.firstRowIndex || 0), 0, inputs.rowsMeta.positions.length);
509
460
  if (allRowsMeasured || inputs.rowsMeta.positions[lastMeasuredIndexRelativeToCurrentPage] >= offset) {
510
461
  // If all rows were measured (when no row has "auto" as height) or all rows before the offset
511
462
  // were measured, then use a binary search because it's faster.
@@ -592,7 +543,7 @@ function getIndexesToRender({
592
543
  minFirstIndex,
593
544
  maxLastIndex
594
545
  }) {
595
- return [(0, _utils2.clamp)(firstIndex - buffer, minFirstIndex, maxLastIndex), (0, _utils2.clamp)(lastIndex + buffer, minFirstIndex, maxLastIndex)];
546
+ return [(0, _utils3.clamp)(firstIndex - buffer, minFirstIndex, maxLastIndex), (0, _utils3.clamp)(lastIndex + buffer, minFirstIndex, maxLastIndex)];
596
547
  }
597
548
  function areRenderContextsEqual(context1, context2) {
598
549
  if (context1 === context2) {
@@ -600,14 +551,8 @@ function areRenderContextsEqual(context1, context2) {
600
551
  }
601
552
  return context1.firstRowIndex === context2.firstRowIndex && context1.lastRowIndex === context2.lastRowIndex && context1.firstColumnIndex === context2.firstColumnIndex && context1.lastColumnIndex === context2.lastColumnIndex;
602
553
  }
603
- function computeOffsets(apiRef, renderContext, direction, pinnedLeftLength) {
554
+ function computeOffsetLeft(columnPositions, renderContext, direction, pinnedLeftLength) {
604
555
  const factor = direction === 'ltr' ? 1 : -1;
605
- const rowPositions = (0, _gridRowsMetaSelector.gridRowsMetaSelector)(apiRef.current.state).positions;
606
- const columnPositions = (0, _gridColumnsSelector.gridColumnPositionsSelector)(apiRef);
607
- const top = rowPositions[renderContext.firstRowIndex] ?? 0;
608
556
  const left = factor * (columnPositions[renderContext.firstColumnIndex] ?? 0) - (columnPositions[pinnedLeftLength] ?? 0);
609
- return {
610
- top,
611
- left
612
- };
557
+ return left;
613
558
  }
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.EMPTY_RENDER_CONTEXT = exports.EMPTY_OFFSETS = void 0;
7
+ exports.EMPTY_RENDER_CONTEXT = void 0;
8
8
  exports.useGridVirtualization = useGridVirtualization;
9
9
  exports.virtualizationStateInitializer = void 0;
10
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
@@ -12,10 +12,6 @@ var React = _interopRequireWildcard(require("react"));
12
12
  var _useGridApiMethod = require("../../utils/useGridApiMethod");
13
13
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
14
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
- const EMPTY_OFFSETS = exports.EMPTY_OFFSETS = {
16
- top: 0,
17
- left: 0
18
- };
19
15
  const EMPTY_RENDER_CONTEXT = exports.EMPTY_RENDER_CONTEXT = {
20
16
  firstRowIndex: 0,
21
17
  lastRowIndex: 0,
@@ -26,8 +22,7 @@ const virtualizationStateInitializer = (state, props) => {
26
22
  const virtualization = {
27
23
  enabled: !props.disableVirtualization,
28
24
  enabledForColumns: true,
29
- renderContext: EMPTY_RENDER_CONTEXT,
30
- offsets: EMPTY_OFFSETS
25
+ renderContext: EMPTY_RENDER_CONTEXT
31
26
  };
32
27
  return (0, _extends2.default)({}, state, {
33
28
  virtualization
@@ -1,18 +1,20 @@
1
1
  "use strict";
2
+ 'use client';
2
3
 
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
7
+ exports.Timeout = void 0;
6
8
  exports.useTimeout = useTimeout;
7
9
  var _useLazyRef = require("./useLazyRef");
8
10
  var _useOnMount = require("./useOnMount");
9
11
  class Timeout {
10
12
  constructor() {
11
- this.currentId = 0;
13
+ this.currentId = null;
12
14
  this.clear = () => {
13
- if (this.currentId !== 0) {
15
+ if (this.currentId !== null) {
14
16
  clearTimeout(this.currentId);
15
- this.currentId = 0;
17
+ this.currentId = null;
16
18
  }
17
19
  };
18
20
  this.disposeEffect = () => {
@@ -22,11 +24,18 @@ class Timeout {
22
24
  static create() {
23
25
  return new Timeout();
24
26
  }
27
+ /**
28
+ * Executes `fn` after `delay`, clearing any previously scheduled call.
29
+ */
25
30
  start(delay, fn) {
26
31
  this.clear();
27
- this.currentId = setTimeout(fn, delay);
32
+ this.currentId = setTimeout(() => {
33
+ this.currentId = null;
34
+ fn();
35
+ }, delay);
28
36
  }
29
37
  }
38
+ exports.Timeout = Timeout;
30
39
  function useTimeout() {
31
40
  const timeout = (0, _useLazyRef.useLazyRef)(Timeout.create).current;
32
41
  (0, _useOnMount.useOnMount)(timeout.disposeEffect);
package/node/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v7.0.0-beta.4
2
+ * @mui/x-data-grid v7.0.0-beta.5
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -13,6 +13,7 @@ exports.isNumber = isNumber;
13
13
  exports.isObject = isObject;
14
14
  exports.localStorageAvailable = localStorageAvailable;
15
15
  exports.randomNumberBetween = randomNumberBetween;
16
+ exports.range = range;
16
17
  function isNumber(value) {
17
18
  return typeof value === 'number' && !Number.isNaN(value);
18
19
  }
@@ -45,6 +46,16 @@ function escapeRegExp(value) {
45
46
  */
46
47
  const clamp = (value, min, max) => Math.max(min, Math.min(max, value));
47
48
 
49
+ /**
50
+ * Create an array containing the range [from, to[
51
+ */
52
+ exports.clamp = clamp;
53
+ function range(from, to) {
54
+ return Array.from({
55
+ length: to - from
56
+ }).map((_, i) => from + i);
57
+ }
58
+
48
59
  /**
49
60
  * Based on `fast-deep-equal`
50
61
  *
@@ -71,7 +82,7 @@ const clamp = (value, min, max) => Math.max(min, Math.min(max, value));
71
82
  * SOFTWARE.
72
83
  * We only type the public interface to avoid dozens of `as` in the function.
73
84
  */
74
- exports.clamp = clamp;
85
+
75
86
  function isDeepEqual(a, b) {
76
87
  if (a === b) {
77
88
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-data-grid",
3
- "version": "7.0.0-beta.4",
3
+ "version": "7.0.0-beta.5",
4
4
  "description": "The community edition of the data grid component (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./node/index.js",
package/utils/utils.d.ts CHANGED
@@ -8,6 +8,10 @@ export declare function escapeRegExp(value: string): string;
8
8
  * If min > max, then the min have priority
9
9
  */
10
10
  export declare const clamp: (value: number, min: number, max: number) => number;
11
+ /**
12
+ * Create an array containing the range [from, to[
13
+ */
14
+ export declare function range(from: number, to: number): number[];
11
15
  /**
12
16
  * Based on `fast-deep-equal`
13
17
  *
package/utils/utils.js CHANGED
@@ -30,6 +30,15 @@ export function escapeRegExp(value) {
30
30
  */
31
31
  export const clamp = (value, min, max) => Math.max(min, Math.min(max, value));
32
32
 
33
+ /**
34
+ * Create an array containing the range [from, to[
35
+ */
36
+ export function range(from, to) {
37
+ return Array.from({
38
+ length: to - from
39
+ }).map((_, i) => from + i);
40
+ }
41
+
33
42
  /**
34
43
  * Based on `fast-deep-equal`
35
44
  *