@mui/x-data-grid 7.24.1 → 7.25.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 (118) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/DataGrid/DataGrid.js +1 -7
  3. package/components/GridRow.d.ts +0 -1
  4. package/components/GridRow.js +25 -19
  5. package/components/cell/GridCell.d.ts +9 -6
  6. package/components/cell/GridCell.js +29 -52
  7. package/components/containers/GridRootStyles.js +135 -37
  8. package/components/toolbar/GridToolbarColumnsButton.js +5 -4
  9. package/components/toolbar/GridToolbarDensitySelector.js +2 -2
  10. package/components/toolbar/GridToolbarExportContainer.js +2 -2
  11. package/components/toolbar/GridToolbarFilterButton.js +4 -3
  12. package/components/virtualization/GridMainContainer.d.ts +10 -0
  13. package/components/virtualization/GridMainContainer.js +10 -2
  14. package/components/virtualization/GridVirtualScrollbar.d.ts +4 -0
  15. package/components/virtualization/GridVirtualScrollbar.js +5 -5
  16. package/components/virtualization/GridVirtualScroller.js +18 -5
  17. package/components/virtualization/GridVirtualScrollerContent.js +11 -2
  18. package/hooks/features/columnResize/useGridColumnResize.js +2 -1
  19. package/hooks/features/columns/useGridColumns.js +7 -3
  20. package/hooks/features/dimensions/useGridDimensions.js +6 -8
  21. package/hooks/features/editing/gridEditingSelectors.d.ts +6 -0
  22. package/hooks/features/editing/gridEditingSelectors.js +7 -1
  23. package/hooks/features/editing/index.d.ts +1 -1
  24. package/hooks/features/editing/index.js +1 -1
  25. package/hooks/features/editing/useGridCellEditing.js +3 -3
  26. package/hooks/features/editing/useGridRowEditing.js +5 -6
  27. package/hooks/features/focus/useGridFocus.js +3 -2
  28. package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +24 -16
  29. package/hooks/features/keyboardNavigation/utils.d.ts +1 -2
  30. package/hooks/features/keyboardNavigation/utils.js +0 -5
  31. package/hooks/features/listView/useGridListView.js +2 -1
  32. package/hooks/features/rowSelection/useGridRowSelection.js +3 -3
  33. package/hooks/features/rows/useGridParamsApi.d.ts +1 -1
  34. package/hooks/features/rows/useGridParamsApi.js +33 -14
  35. package/hooks/features/rows/useGridRowSpanning.js +94 -91
  36. package/hooks/features/rows/useGridRows.js +7 -8
  37. package/hooks/features/rows/useGridRowsMeta.js +3 -2
  38. package/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
  39. package/hooks/features/virtualization/useGridVirtualScroller.d.ts +9 -1
  40. package/hooks/features/virtualization/useGridVirtualScroller.js +31 -45
  41. package/index.js +1 -1
  42. package/models/api/gridApiCommon.d.ts +2 -2
  43. package/models/api/gridParamsApi.d.ts +29 -2
  44. package/models/api/index.d.ts +1 -1
  45. package/models/api/index.js +0 -1
  46. package/modern/DataGrid/DataGrid.js +1 -7
  47. package/modern/components/GridRow.js +25 -19
  48. package/modern/components/cell/GridCell.js +29 -52
  49. package/modern/components/containers/GridRootStyles.js +135 -37
  50. package/modern/components/toolbar/GridToolbarColumnsButton.js +5 -4
  51. package/modern/components/toolbar/GridToolbarDensitySelector.js +2 -2
  52. package/modern/components/toolbar/GridToolbarExportContainer.js +2 -2
  53. package/modern/components/toolbar/GridToolbarFilterButton.js +4 -3
  54. package/modern/components/virtualization/GridMainContainer.js +10 -2
  55. package/modern/components/virtualization/GridVirtualScrollbar.js +5 -5
  56. package/modern/components/virtualization/GridVirtualScroller.js +18 -5
  57. package/modern/components/virtualization/GridVirtualScrollerContent.js +11 -2
  58. package/modern/hooks/features/columnResize/useGridColumnResize.js +2 -1
  59. package/modern/hooks/features/columns/useGridColumns.js +7 -3
  60. package/modern/hooks/features/dimensions/useGridDimensions.js +6 -8
  61. package/modern/hooks/features/editing/gridEditingSelectors.js +7 -1
  62. package/modern/hooks/features/editing/index.js +1 -1
  63. package/modern/hooks/features/editing/useGridCellEditing.js +3 -3
  64. package/modern/hooks/features/editing/useGridRowEditing.js +5 -6
  65. package/modern/hooks/features/focus/useGridFocus.js +3 -2
  66. package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +24 -16
  67. package/modern/hooks/features/keyboardNavigation/utils.js +0 -5
  68. package/modern/hooks/features/listView/useGridListView.js +2 -1
  69. package/modern/hooks/features/rowSelection/useGridRowSelection.js +3 -3
  70. package/modern/hooks/features/rows/useGridParamsApi.js +33 -14
  71. package/modern/hooks/features/rows/useGridRowSpanning.js +94 -91
  72. package/modern/hooks/features/rows/useGridRows.js +7 -8
  73. package/modern/hooks/features/rows/useGridRowsMeta.js +3 -2
  74. package/modern/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
  75. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +31 -45
  76. package/modern/index.js +1 -1
  77. package/modern/models/api/index.js +0 -1
  78. package/modern/utils/roundToDecimalPlaces.js +3 -0
  79. package/modern/utils/utils.js +6 -1
  80. package/node/DataGrid/DataGrid.js +1 -7
  81. package/node/components/GridRow.js +22 -16
  82. package/node/components/cell/GridCell.js +27 -50
  83. package/node/components/containers/GridRootStyles.js +135 -37
  84. package/node/components/toolbar/GridToolbarColumnsButton.js +5 -4
  85. package/node/components/toolbar/GridToolbarDensitySelector.js +2 -2
  86. package/node/components/toolbar/GridToolbarExportContainer.js +2 -2
  87. package/node/components/toolbar/GridToolbarFilterButton.js +4 -3
  88. package/node/components/virtualization/GridMainContainer.js +10 -2
  89. package/node/components/virtualization/GridVirtualScrollbar.js +5 -5
  90. package/node/components/virtualization/GridVirtualScroller.js +18 -5
  91. package/node/components/virtualization/GridVirtualScrollerContent.js +11 -2
  92. package/node/hooks/features/columnResize/useGridColumnResize.js +2 -1
  93. package/node/hooks/features/columns/useGridColumns.js +7 -3
  94. package/node/hooks/features/dimensions/useGridDimensions.js +6 -8
  95. package/node/hooks/features/editing/gridEditingSelectors.js +8 -2
  96. package/node/hooks/features/editing/index.js +7 -11
  97. package/node/hooks/features/editing/useGridCellEditing.js +2 -2
  98. package/node/hooks/features/editing/useGridRowEditing.js +3 -4
  99. package/node/hooks/features/focus/useGridFocus.js +3 -2
  100. package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +24 -15
  101. package/node/hooks/features/keyboardNavigation/utils.js +0 -6
  102. package/node/hooks/features/listView/useGridListView.js +2 -1
  103. package/node/hooks/features/rowSelection/useGridRowSelection.js +2 -2
  104. package/node/hooks/features/rows/useGridParamsApi.js +33 -14
  105. package/node/hooks/features/rows/useGridRowSpanning.js +92 -89
  106. package/node/hooks/features/rows/useGridRows.js +7 -8
  107. package/node/hooks/features/rows/useGridRowsMeta.js +5 -4
  108. package/node/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
  109. package/node/hooks/features/virtualization/useGridVirtualScroller.js +31 -45
  110. package/node/index.js +1 -1
  111. package/node/models/api/index.js +0 -11
  112. package/node/utils/roundToDecimalPlaces.js +9 -0
  113. package/node/utils/utils.js +8 -1
  114. package/package.json +2 -2
  115. package/utils/roundToDecimalPlaces.d.ts +1 -0
  116. package/utils/roundToDecimalPlaces.js +3 -0
  117. package/utils/utils.d.ts +1 -0
  118. package/utils/utils.js +6 -1
@@ -13,7 +13,7 @@ var _gridVirtualizationSelectors = require("./gridVirtualizationSelectors");
13
13
  var _focus = require("../focus");
14
14
  var _pagination = require("../pagination");
15
15
  var _rows = require("../rows");
16
- const gridIsFocusedCellOutOfContex = (0, _reselect.createSelector)(_focus.gridFocusCellSelector, _gridVirtualizationSelectors.gridRenderContextSelector, _pagination.gridVisibleRowsSelector, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector, _rows.gridRowsLookupSelector, (focusedCell, renderContext, currentPage, visibleColumns, rows) => {
16
+ const gridIsFocusedCellOutOfContext = (0, _reselect.createSelector)(_focus.gridFocusCellSelector, _gridVirtualizationSelectors.gridRenderContextSelector, _pagination.gridVisibleRowsSelector, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector, _rows.gridRowsLookupSelector, (focusedCell, renderContext, currentPage, visibleColumns, rows) => {
17
17
  if (!focusedCell) {
18
18
  return false;
19
19
  }
@@ -26,7 +26,7 @@ const gridIsFocusedCellOutOfContex = (0, _reselect.createSelector)(_focus.gridFo
26
26
  const isInRenderContext = rowIndex !== undefined && columnIndex !== -1 && rowIndex >= renderContext.firstRowIndex && rowIndex <= renderContext.lastRowIndex;
27
27
  return !isInRenderContext;
28
28
  });
29
- const gridFocusedVirtualCellSelector = exports.gridFocusedVirtualCellSelector = (0, _createSelector.createSelectorMemoized)(gridIsFocusedCellOutOfContex, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector, _pagination.gridVisibleRowsSelector, _rows.gridRowsLookupSelector, _focus.gridFocusCellSelector, (isFocusedCellOutOfRenderContext, visibleColumns, currentPage, rows, focusedCell) => {
29
+ const gridFocusedVirtualCellSelector = exports.gridFocusedVirtualCellSelector = (0, _createSelector.createSelectorMemoized)(gridIsFocusedCellOutOfContext, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector, _pagination.gridVisibleRowsSelector, _rows.gridRowsLookupSelector, _focus.gridFocusCellSelector, (isFocusedCellOutOfRenderContext, visibleColumns, currentPage, rows, focusedCell) => {
30
30
  if (!isFocusedCellOutOfRenderContext) {
31
31
  return null;
32
32
  }
@@ -36,7 +36,9 @@ var _useGridVirtualization = require("./useGridVirtualization");
36
36
  var _gridRowSpanningSelectors = require("../rows/gridRowSpanningSelectors");
37
37
  var _gridListViewSelectors = require("../listView/gridListViewSelectors");
38
38
  var _gridRowsUtils = require("../rows/gridRowsUtils");
39
+ var _columns = require("../columns");
39
40
  var _gridFocusedVirtualCellSelector = require("./gridFocusedVirtualCellSelector");
41
+ var _roundToDecimalPlaces = require("../../../utils/roundToDecimalPlaces");
40
42
  var _isJSDOM = require("../../../utils/isJSDOM");
41
43
  var _jsxRuntime = require("react/jsx-runtime");
42
44
  const MINIMUM_COLUMN_WIDTH = 50;
@@ -69,17 +71,13 @@ const useGridVirtualScroller = () => {
69
71
  const dimensions = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridDimensionsSelector);
70
72
  const outerSize = dimensions.viewportOuterSize;
71
73
  const pinnedRows = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowsSelector.gridPinnedRowsSelector);
72
- const pinnedColumnDefinitions = (0, _useGridSelector.useGridSelector)(apiRef, _gridColumnsSelector.gridVisiblePinnedColumnDefinitionsSelector);
73
- const pinnedColumns = listView ? {
74
- left: [],
75
- right: []
76
- } : pinnedColumnDefinitions;
74
+ const pinnedColumnDefinitions = (0, _gridColumnsSelector.gridVisiblePinnedColumnDefinitionsSelector)(apiRef);
75
+ const pinnedColumns = listView ? _columns.EMPTY_PINNED_COLUMN_FIELDS : pinnedColumnDefinitions;
77
76
  const hasBottomPinnedRows = pinnedRows.bottom.length > 0;
78
77
  const [panels, setPanels] = React.useState(EMPTY_DETAIL_PANELS);
79
78
  const isRtl = (0, _RtlProvider.useRtl)();
80
- const rowsMeta = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowsMetaSelector.gridRowsMetaSelector);
81
79
  const selectedRowsLookup = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowSelectionSelector.selectedIdsLookupSelector);
82
- const currentPage = (0, _useGridVisibleRows.useGridVisibleRows)(apiRef, rootProps);
80
+ const currentPage = (0, _useGridVisibleRows.useGridVisibleRows)(apiRef);
83
81
  const mainRef = apiRef.current.mainElementRef;
84
82
  const scrollerRef = apiRef.current.virtualScrollerRef;
85
83
  const scrollbarVerticalRef = apiRef.current.virtualScrollbarVerticalRef;
@@ -95,7 +93,10 @@ const useGridVirtualScroller = () => {
95
93
  return undefined;
96
94
  }
97
95
  const initialRect = node.getBoundingClientRect();
98
- let lastSize = roundDimensions(initialRect);
96
+ let lastSize = {
97
+ width: (0, _roundToDecimalPlaces.roundToDecimalPlaces)(initialRect.width, 1),
98
+ height: (0, _roundToDecimalPlaces.roundToDecimalPlaces)(initialRect.height, 1)
99
+ };
99
100
  if (!previousSize.current || lastSize.width !== previousSize.current.width && lastSize.height !== previousSize.current.height) {
100
101
  previousSize.current = lastSize;
101
102
  apiRef.current.publishEvent('resize', lastSize);
@@ -108,7 +109,10 @@ const useGridVirtualScroller = () => {
108
109
  if (!entry) {
109
110
  return;
110
111
  }
111
- const newSize = roundDimensions(entry.contentRect);
112
+ const newSize = {
113
+ width: (0, _roundToDecimalPlaces.roundToDecimalPlaces)(entry.contentRect.width, 1),
114
+ height: (0, _roundToDecimalPlaces.roundToDecimalPlaces)(entry.contentRect.height, 1)
115
+ };
112
116
  if (newSize.width === lastSize.width && newSize.height === lastSize.height) {
113
117
  return;
114
118
  }
@@ -176,9 +180,13 @@ const useGridVirtualScroller = () => {
176
180
  if (!scroller) {
177
181
  return undefined;
178
182
  }
183
+ const maxScrollTop = Math.ceil(dimensions.minimumSize.height - dimensions.viewportOuterSize.height);
184
+ const maxScrollLeft = Math.ceil(dimensions.minimumSize.width - dimensions.viewportInnerSize.width);
185
+
186
+ // Clamp the scroll position to the viewport to avoid re-calculating the render context for scroll bounce
179
187
  const newScroll = {
180
- top: scroller.scrollTop,
181
- left: scroller.scrollLeft
188
+ top: (0, _utils3.clamp)(scroller.scrollTop, 0, maxScrollTop),
189
+ left: isRtl ? (0, _utils3.clamp)(scroller.scrollLeft, -maxScrollLeft, 0) : (0, _utils3.clamp)(scroller.scrollLeft, 0, maxScrollLeft)
182
190
  };
183
191
  const dx = newScroll.left - scrollPosition.current.left;
184
192
  const dy = newScroll.top - scrollPosition.current.top;
@@ -231,34 +239,15 @@ const useGridVirtualScroller = () => {
231
239
  frozenContext.current = undefined;
232
240
  updateRenderContext(nextRenderContext);
233
241
  };
234
- const handleScroll = (0, _utils.unstable_useEventCallback)(event => {
242
+ const handleScroll = (0, _utils.unstable_useEventCallback)(() => {
235
243
  if (ignoreNextScrollEvent.current) {
236
244
  ignoreNextScrollEvent.current = false;
237
245
  return;
238
246
  }
239
- const {
240
- scrollTop,
241
- scrollLeft
242
- } = event.currentTarget;
243
-
244
- // On iOS and macOS, negative offsets are possible when swiping past the start
245
- if (scrollTop < 0) {
246
- return;
247
- }
248
- if (!isRtl) {
249
- if (scrollLeft < 0) {
250
- return;
251
- }
252
- }
253
- if (isRtl) {
254
- if (scrollLeft > 0) {
255
- return;
256
- }
257
- }
258
247
  const nextRenderContext = triggerUpdateRenderContext();
259
248
  apiRef.current.publishEvent('scrollPositionChange', {
260
- top: scrollTop,
261
- left: scrollLeft,
249
+ top: scrollPosition.current.top,
250
+ left: scrollPosition.current.left,
262
251
  renderContext: nextRenderContext
263
252
  });
264
253
  });
@@ -380,7 +369,6 @@ const useGridVirtualScroller = () => {
380
369
  rowId: id,
381
370
  index: rowIndex,
382
371
  selected: isSelected,
383
- offsetTop: params.rows ? undefined : rowsMeta.positions[rowIndexInPage],
384
372
  offsetLeft: offsetLeft,
385
373
  columnsTotalWidth: dimensions.columnsTotalWidth,
386
374
  rowHeight: baseRowHeight,
@@ -538,11 +526,13 @@ const useGridVirtualScroller = () => {
538
526
  }),
539
527
  getScrollbarVerticalProps: () => ({
540
528
  ref: scrollbarVerticalRef,
541
- role: 'presentation'
529
+ role: 'presentation',
530
+ scrollPosition
542
531
  }),
543
532
  getScrollbarHorizontalProps: () => ({
544
533
  ref: scrollbarHorizontalRef,
545
- role: 'presentation'
534
+ role: 'presentation',
535
+ scrollPosition
546
536
  })
547
537
  };
548
538
  };
@@ -585,6 +575,11 @@ function computeRenderContext(inputs, scrollPosition, scrollCache) {
585
575
  firstColumnIndex: 0,
586
576
  lastColumnIndex: inputs.visibleColumns.length
587
577
  };
578
+ if (inputs.listView) {
579
+ return (0, _extends2.default)({}, renderContext, {
580
+ lastColumnIndex: 1
581
+ });
582
+ }
588
583
  const {
589
584
  top,
590
585
  left
@@ -836,13 +831,4 @@ function bufferForDirection(isRtl, direction, rowBufferPx, columnBufferPx, verti
836
831
  // eslint unable to figure out enum exhaustiveness
837
832
  throw new Error('unreachable');
838
833
  }
839
- }
840
-
841
- // Round to avoid issues with subpixel rendering
842
- // https://github.com/mui/mui-x/issues/15721
843
- function roundDimensions(dimensions) {
844
- return {
845
- width: Math.round(dimensions.width * 10) / 10,
846
- height: Math.round(dimensions.height * 10) / 10
847
- };
848
834
  }
package/node/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v7.24.1
2
+ * @mui/x-data-grid v7.25.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -3,17 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var _gridParamsApi = require("./gridParamsApi");
7
- Object.keys(_gridParamsApi).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _gridParamsApi[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _gridParamsApi[key];
14
- }
15
- });
16
- });
17
6
  var _gridColumnApi = require("./gridColumnApi");
18
7
  Object.keys(_gridColumnApi).forEach(function (key) {
19
8
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.roundToDecimalPlaces = roundToDecimalPlaces;
7
+ function roundToDecimalPlaces(value, decimals) {
8
+ return Math.round(value * 10 ** decimals) / 10 ** decimals;
9
+ }
@@ -14,6 +14,7 @@ exports.isNumber = isNumber;
14
14
  exports.isObject = isObject;
15
15
  exports.localStorageAvailable = localStorageAvailable;
16
16
  exports.range = range;
17
+ exports.runIf = void 0;
17
18
  function isNumber(value) {
18
19
  return typeof value === 'number' && !Number.isNaN(value);
19
20
  }
@@ -213,4 +214,10 @@ function deepClone(obj) {
213
214
  * of a `eslint-disable-next-line react-hooks/exhaustive-deps` because
214
215
  * that hint disables checks on all values instead of just one.
215
216
  */
216
- function eslintUseValue(_) {}
217
+ function eslintUseValue(_) {}
218
+ const runIf = (condition, fn) => params => {
219
+ if (condition) {
220
+ fn(params);
221
+ }
222
+ };
223
+ exports.runIf = runIf;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-data-grid",
3
- "version": "7.24.1",
3
+ "version": "7.25.0",
4
4
  "description": "The Community plan edition of the Data Grid components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./node/index.js",
@@ -42,7 +42,7 @@
42
42
  "clsx": "^2.1.1",
43
43
  "prop-types": "^15.8.1",
44
44
  "reselect": "^5.1.1",
45
- "@mui/x-internals": "7.24.1"
45
+ "@mui/x-internals": "7.25.0"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@emotion/react": "^11.9.0",
@@ -0,0 +1 @@
1
+ export declare function roundToDecimalPlaces(value: number, decimals: number): number;
@@ -0,0 +1,3 @@
1
+ export function roundToDecimalPlaces(value, decimals) {
2
+ return Math.round(value * 10 ** decimals) / 10 ** decimals;
3
+ }
package/utils/utils.d.ts CHANGED
@@ -54,3 +54,4 @@ export declare function deepClone(obj: Record<string, any>): any;
54
54
  * that hint disables checks on all values instead of just one.
55
55
  */
56
56
  export declare function eslintUseValue(_: any): void;
57
+ export declare const runIf: (condition: boolean, fn: Function) => (params: unknown) => void;
package/utils/utils.js CHANGED
@@ -196,4 +196,9 @@ export function deepClone(obj) {
196
196
  * of a `eslint-disable-next-line react-hooks/exhaustive-deps` because
197
197
  * that hint disables checks on all values instead of just one.
198
198
  */
199
- export function eslintUseValue(_) {}
199
+ export function eslintUseValue(_) {}
200
+ export const runIf = (condition, fn) => params => {
201
+ if (condition) {
202
+ fn(params);
203
+ }
204
+ };