@mui/x-data-grid 6.7.0 → 6.9.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 (205) hide show
  1. package/CHANGELOG.md +145 -5541
  2. package/components/GridColumnHeaders.d.ts +2 -2
  3. package/components/GridColumnHeaders.js +3 -1
  4. package/components/GridPagination.d.ts +2 -2
  5. package/components/GridRow.d.ts +2 -2
  6. package/components/GridRow.js +33 -79
  7. package/components/cell/GridCell.d.ts +24 -15
  8. package/components/cell/GridCell.js +422 -45
  9. package/components/cell/GridEditInputCell.js +9 -9
  10. package/components/cell/index.d.ts +2 -1
  11. package/components/cell/index.js +1 -1
  12. package/components/containers/GridRootStyles.js +30 -16
  13. package/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
  14. package/components/panel/GridPanel.d.ts +1 -1
  15. package/components/toolbar/GridToolbar.js +2 -2
  16. package/components/virtualization/GridVirtualScroller.js +4 -9
  17. package/components/virtualization/GridVirtualScrollerContent.js +11 -20
  18. package/constants/defaultGridSlotsComponents.js +6 -2
  19. package/hooks/core/useGridApiInitialization.js +4 -1
  20. package/hooks/core/useGridStateInitialization.js +2 -9
  21. package/hooks/features/clipboard/useGridClipboard.js +1 -4
  22. package/hooks/features/columnGrouping/gridColumnGroupsSelector.js +4 -4
  23. package/hooks/features/columnHeaders/useGridColumnHeaders.js +9 -3
  24. package/hooks/features/columns/gridColumnsSelector.js +7 -7
  25. package/hooks/features/dimensions/useGridDimensions.js +6 -12
  26. package/hooks/features/editing/useGridCellEditing.js +5 -3
  27. package/hooks/features/editing/useGridRowEditing.js +14 -6
  28. package/hooks/features/filter/gridFilterSelector.js +8 -8
  29. package/hooks/features/filter/gridFilterUtils.d.ts +4 -1
  30. package/hooks/features/filter/gridFilterUtils.js +19 -13
  31. package/hooks/features/filter/useGridFilter.js +2 -1
  32. package/hooks/features/focus/useGridFocus.js +9 -4
  33. package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +2 -3
  34. package/hooks/features/pagination/gridPaginationSelector.js +4 -4
  35. package/hooks/features/rowSelection/gridRowSelectionSelector.js +3 -3
  36. package/hooks/features/rows/gridRowsSelector.js +3 -3
  37. package/hooks/features/rows/useGridParamsApi.d.ts +2 -0
  38. package/hooks/features/rows/useGridParamsApi.js +7 -15
  39. package/hooks/features/sorting/gridSortingSelector.js +3 -3
  40. package/hooks/features/virtualization/useGridVirtualScroller.d.ts +8 -816
  41. package/hooks/features/virtualization/useGridVirtualScroller.js +40 -38
  42. package/hooks/utils/index.d.ts +1 -1
  43. package/hooks/utils/index.js +1 -1
  44. package/hooks/utils/useGridSelector.d.ts +3 -1
  45. package/hooks/utils/useGridSelector.js +37 -6
  46. package/hooks/utils/useLazyRef.d.ts +2 -0
  47. package/hooks/utils/useLazyRef.js +9 -0
  48. package/hooks/utils/useOnMount.d.ts +2 -0
  49. package/hooks/utils/useOnMount.js +7 -0
  50. package/index.js +1 -1
  51. package/internals/index.d.ts +1 -1
  52. package/internals/index.js +1 -1
  53. package/legacy/components/GridColumnHeaders.js +3 -1
  54. package/legacy/components/GridRow.js +35 -79
  55. package/legacy/components/cell/GridCell.js +425 -46
  56. package/legacy/components/cell/GridEditInputCell.js +9 -9
  57. package/legacy/components/cell/index.js +1 -1
  58. package/legacy/components/containers/GridRootStyles.js +20 -17
  59. package/legacy/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
  60. package/legacy/components/toolbar/GridToolbar.js +2 -2
  61. package/legacy/components/virtualization/GridVirtualScroller.js +4 -7
  62. package/legacy/components/virtualization/GridVirtualScrollerContent.js +10 -17
  63. package/legacy/constants/defaultGridSlotsComponents.js +6 -2
  64. package/legacy/hooks/core/useGridApiInitialization.js +4 -1
  65. package/legacy/hooks/core/useGridStateInitialization.js +2 -7
  66. package/legacy/hooks/features/clipboard/useGridClipboard.js +1 -4
  67. package/legacy/hooks/features/columnGrouping/gridColumnGroupsSelector.js +4 -4
  68. package/legacy/hooks/features/columnHeaders/useGridColumnHeaders.js +9 -3
  69. package/legacy/hooks/features/columns/gridColumnsSelector.js +7 -7
  70. package/legacy/hooks/features/dimensions/useGridDimensions.js +6 -12
  71. package/legacy/hooks/features/editing/useGridCellEditing.js +5 -3
  72. package/legacy/hooks/features/editing/useGridRowEditing.js +15 -7
  73. package/legacy/hooks/features/filter/gridFilterSelector.js +8 -8
  74. package/legacy/hooks/features/filter/gridFilterUtils.js +23 -19
  75. package/legacy/hooks/features/filter/useGridFilter.js +2 -1
  76. package/legacy/hooks/features/focus/useGridFocus.js +9 -4
  77. package/legacy/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +2 -3
  78. package/legacy/hooks/features/pagination/gridPaginationSelector.js +4 -4
  79. package/legacy/hooks/features/rowSelection/gridRowSelectionSelector.js +3 -3
  80. package/legacy/hooks/features/rows/gridRowsSelector.js +3 -3
  81. package/legacy/hooks/features/rows/useGridParamsApi.js +23 -15
  82. package/legacy/hooks/features/sorting/gridSortingSelector.js +3 -3
  83. package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +38 -34
  84. package/legacy/hooks/utils/index.js +1 -1
  85. package/legacy/hooks/utils/useGridSelector.js +43 -5
  86. package/legacy/hooks/utils/useLazyRef.js +9 -0
  87. package/legacy/hooks/utils/useOnMount.js +7 -0
  88. package/legacy/index.js +1 -1
  89. package/legacy/internals/index.js +1 -1
  90. package/legacy/locales/elGR.js +70 -79
  91. package/legacy/locales/ptBR.js +12 -13
  92. package/legacy/utils/Store.js +34 -0
  93. package/legacy/utils/createSelector.js +74 -6
  94. package/legacy/utils/doesSupportPreventScroll.js +13 -0
  95. package/legacy/utils/fastMemo.js +5 -0
  96. package/legacy/utils/fastObjectShallowCompare.js +32 -0
  97. package/legacy/utils/keyboardUtils.js +4 -2
  98. package/locales/elGR.js +66 -79
  99. package/locales/ptBR.js +12 -13
  100. package/models/api/gridCoreApi.d.ts +6 -0
  101. package/models/colDef/gridColDef.d.ts +4 -3
  102. package/models/colDef/gridColType.d.ts +3 -1
  103. package/models/events/gridEventLookup.d.ts +3 -3
  104. package/modern/components/GridColumnHeaders.js +3 -1
  105. package/modern/components/GridRow.js +32 -79
  106. package/modern/components/cell/GridCell.js +421 -45
  107. package/modern/components/cell/GridEditInputCell.js +9 -9
  108. package/modern/components/cell/index.js +1 -1
  109. package/modern/components/containers/GridRootStyles.js +30 -16
  110. package/modern/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
  111. package/modern/components/toolbar/GridToolbar.js +2 -2
  112. package/modern/components/virtualization/GridVirtualScroller.js +4 -9
  113. package/modern/components/virtualization/GridVirtualScrollerContent.js +10 -20
  114. package/modern/constants/defaultGridSlotsComponents.js +6 -2
  115. package/modern/hooks/core/useGridApiInitialization.js +4 -1
  116. package/modern/hooks/core/useGridStateInitialization.js +2 -9
  117. package/modern/hooks/features/clipboard/useGridClipboard.js +1 -4
  118. package/modern/hooks/features/columnGrouping/gridColumnGroupsSelector.js +4 -4
  119. package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +9 -3
  120. package/modern/hooks/features/columns/gridColumnsSelector.js +7 -7
  121. package/modern/hooks/features/dimensions/useGridDimensions.js +6 -12
  122. package/modern/hooks/features/editing/useGridCellEditing.js +5 -3
  123. package/modern/hooks/features/editing/useGridRowEditing.js +14 -6
  124. package/modern/hooks/features/filter/gridFilterSelector.js +8 -8
  125. package/modern/hooks/features/filter/gridFilterUtils.js +17 -12
  126. package/modern/hooks/features/filter/useGridFilter.js +2 -1
  127. package/modern/hooks/features/focus/useGridFocus.js +8 -4
  128. package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +2 -3
  129. package/modern/hooks/features/pagination/gridPaginationSelector.js +4 -4
  130. package/modern/hooks/features/rowSelection/gridRowSelectionSelector.js +3 -3
  131. package/modern/hooks/features/rows/gridRowsSelector.js +3 -3
  132. package/modern/hooks/features/rows/useGridParamsApi.js +7 -15
  133. package/modern/hooks/features/sorting/gridSortingSelector.js +3 -3
  134. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +40 -38
  135. package/modern/hooks/utils/index.js +1 -1
  136. package/modern/hooks/utils/useGridSelector.js +37 -6
  137. package/modern/hooks/utils/useLazyRef.js +9 -0
  138. package/modern/hooks/utils/useOnMount.js +7 -0
  139. package/modern/index.js +1 -1
  140. package/modern/internals/index.js +1 -1
  141. package/modern/locales/elGR.js +66 -79
  142. package/modern/locales/ptBR.js +12 -13
  143. package/modern/utils/Store.js +24 -0
  144. package/modern/utils/createSelector.js +74 -6
  145. package/modern/utils/doesSupportPreventScroll.js +13 -0
  146. package/modern/utils/fastMemo.js +5 -0
  147. package/modern/utils/fastObjectShallowCompare.js +32 -0
  148. package/modern/utils/keyboardUtils.js +4 -2
  149. package/node/components/GridColumnHeaders.js +4 -2
  150. package/node/components/GridRow.js +32 -79
  151. package/node/components/cell/GridCell.js +424 -47
  152. package/node/components/cell/GridEditInputCell.js +9 -9
  153. package/node/components/cell/index.js +17 -10
  154. package/node/components/containers/GridRootStyles.js +30 -16
  155. package/node/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
  156. package/node/components/toolbar/GridToolbar.js +2 -2
  157. package/node/components/virtualization/GridVirtualScroller.js +4 -9
  158. package/node/components/virtualization/GridVirtualScrollerContent.js +10 -20
  159. package/node/constants/defaultGridSlotsComponents.js +4 -1
  160. package/node/hooks/core/useGridApiInitialization.js +4 -1
  161. package/node/hooks/core/useGridStateInitialization.js +2 -9
  162. package/node/hooks/features/clipboard/useGridClipboard.js +1 -4
  163. package/node/hooks/features/columnGrouping/gridColumnGroupsSelector.js +3 -3
  164. package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +8 -2
  165. package/node/hooks/features/columns/gridColumnsSelector.js +6 -6
  166. package/node/hooks/features/dimensions/useGridDimensions.js +6 -12
  167. package/node/hooks/features/editing/useGridCellEditing.js +5 -3
  168. package/node/hooks/features/editing/useGridRowEditing.js +14 -6
  169. package/node/hooks/features/filter/gridFilterSelector.js +7 -7
  170. package/node/hooks/features/filter/gridFilterUtils.js +17 -12
  171. package/node/hooks/features/filter/useGridFilter.js +2 -1
  172. package/node/hooks/features/focus/useGridFocus.js +8 -4
  173. package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +2 -3
  174. package/node/hooks/features/pagination/gridPaginationSelector.js +3 -3
  175. package/node/hooks/features/rowSelection/gridRowSelectionSelector.js +2 -2
  176. package/node/hooks/features/rows/gridRowsSelector.js +2 -2
  177. package/node/hooks/features/rows/useGridParamsApi.js +9 -15
  178. package/node/hooks/features/sorting/gridSortingSelector.js +2 -2
  179. package/node/hooks/features/virtualization/useGridVirtualScroller.js +40 -36
  180. package/node/hooks/utils/index.js +14 -10
  181. package/node/hooks/utils/useGridSelector.js +41 -7
  182. package/node/hooks/utils/useLazyRef.js +17 -0
  183. package/node/hooks/utils/useOnMount.js +15 -0
  184. package/node/index.js +1 -1
  185. package/node/internals/index.js +7 -0
  186. package/node/locales/elGR.js +66 -79
  187. package/node/locales/ptBR.js +12 -13
  188. package/node/utils/Store.js +31 -0
  189. package/node/utils/createSelector.js +77 -8
  190. package/node/utils/doesSupportPreventScroll.js +19 -0
  191. package/node/utils/fastMemo.js +13 -0
  192. package/node/utils/fastObjectShallowCompare.js +38 -0
  193. package/node/utils/keyboardUtils.js +4 -2
  194. package/package.json +2 -2
  195. package/utils/Store.d.ts +11 -0
  196. package/utils/Store.js +24 -0
  197. package/utils/createSelector.d.ts +1 -0
  198. package/utils/createSelector.js +74 -6
  199. package/utils/doesSupportPreventScroll.d.ts +1 -0
  200. package/utils/doesSupportPreventScroll.js +13 -0
  201. package/utils/fastMemo.d.ts +1 -0
  202. package/utils/fastMemo.js +5 -0
  203. package/utils/fastObjectShallowCompare.d.ts +1 -0
  204. package/utils/fastObjectShallowCompare.js +32 -0
  205. package/utils/keyboardUtils.js +4 -2
@@ -1,11 +1,10 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
3
  const _excluded = ["style"],
4
- _excluded2 = ["style"],
5
- _excluded3 = ["style"];
4
+ _excluded2 = ["style"];
6
5
  import * as React from 'react';
7
6
  import * as ReactDOM from 'react-dom';
8
- import { unstable_useForkRef as useForkRef, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
7
+ import { unstable_useForkRef as useForkRef, unstable_useEnhancedEffect as useEnhancedEffect, unstable_useEventCallback as useEventCallback } from '@mui/utils';
9
8
  import { useTheme } from '@mui/material/styles';
10
9
  import { defaultMemoize } from 'reselect';
11
10
  import { useGridPrivateApiContext } from '../../utils/useGridPrivateApiContext';
@@ -50,12 +49,17 @@ export const getRenderableIndexes = ({
50
49
  }) => {
51
50
  return [clamp(firstIndex - buffer, minFirstIndex, maxLastIndex), clamp(lastIndex + buffer, minFirstIndex, maxLastIndex)];
52
51
  };
53
- const areRenderContextsEqual = (context1, context2) => {
52
+ export const areRenderContextsEqual = (context1, context2) => {
54
53
  if (context1 === context2) {
55
54
  return true;
56
55
  }
57
56
  return context1.firstRowIndex === context2.firstRowIndex && context1.lastRowIndex === context2.lastRowIndex && context1.firstColumnIndex === context2.firstColumnIndex && context1.lastColumnIndex === context2.lastColumnIndex;
58
57
  };
58
+ // The `maxSize` is 3 so that reselect caches the `renderedColumns` values for the pinned left,
59
+ // unpinned, and pinned right sections.
60
+ const MEMOIZE_OPTIONS = {
61
+ maxSize: 3
62
+ };
59
63
  export const useGridVirtualScroller = props => {
60
64
  var _currentPage$range3, _currentPage$range4;
61
65
  const apiRef = useGridPrivateApiContext();
@@ -96,7 +100,7 @@ export const useGridVirtualScroller = props => {
96
100
  const prevRootRowStyle = React.useRef();
97
101
  const getRenderedColumnsRef = React.useRef(defaultMemoize((columns, firstColumnToRender, lastColumnToRender) => {
98
102
  return columns.slice(firstColumnToRender, lastColumnToRender);
99
- }));
103
+ }, MEMOIZE_OPTIONS));
100
104
  const getNearestIndexToRender = React.useCallback(offset => {
101
105
  var _currentPage$range, _currentPage$range2;
102
106
  const lastMeasuredIndexRelativeToAllRows = apiRef.current.getLastMeasuredRowIndex();
@@ -255,7 +259,7 @@ export const useGridVirtualScroller = props => {
255
259
  };
256
260
  apiRef.current.publishEvent('scrollPositionChange', params);
257
261
  }, [apiRef, computeRenderContext, containerDimensions.width, updateRenderContext]);
258
- const handleScroll = event => {
262
+ const handleScroll = useEventCallback(event => {
259
263
  const {
260
264
  scrollTop,
261
265
  scrollLeft
@@ -297,13 +301,13 @@ export const useGridVirtualScroller = props => {
297
301
  });
298
302
  prevTotalWidth.current = columnsTotalWidth;
299
303
  }
300
- };
301
- const handleWheel = event => {
304
+ });
305
+ const handleWheel = useEventCallback(event => {
302
306
  apiRef.current.publishEvent('virtualScrollerWheel', {}, event);
303
- };
304
- const handleTouchMove = event => {
307
+ });
308
+ const handleTouchMove = useEventCallback(event => {
305
309
  apiRef.current.publishEvent('virtualScrollerTouchMove', {}, event);
306
- };
310
+ });
307
311
  const getRows = (params = {
308
312
  renderContext
309
313
  }) => {
@@ -450,22 +454,25 @@ export const useGridVirtualScroller = props => {
450
454
  height,
451
455
  minHeight: shouldExtendContent ? '100%' : 'auto'
452
456
  };
457
+ if (rootProps.autoHeight && currentPage.rows.length === 0) {
458
+ size.height = getMinimalContentHeight(apiRef, rootProps.rowHeight); // Give room to show the overlay when there no rows.
459
+ }
460
+
453
461
  return size;
454
- }, [rootRef, columnsTotalWidth, rowsMeta.currentPageTotalHeight, needsHorizontalScrollbar]);
462
+ }, [apiRef, rootRef, columnsTotalWidth, rowsMeta.currentPageTotalHeight, needsHorizontalScrollbar, rootProps.autoHeight, rootProps.rowHeight, currentPage.rows.length]);
455
463
  React.useEffect(() => {
456
464
  apiRef.current.publishEvent('virtualScrollerContentSizeChange');
457
465
  }, [apiRef, contentSize]);
458
- if (rootProps.autoHeight && currentPage.rows.length === 0) {
459
- contentSize.height = getMinimalContentHeight(apiRef, rootProps.rowHeight); // Give room to show the overlay when there no rows.
460
- }
461
-
462
- const rootStyle = {};
463
- if (!needsHorizontalScrollbar) {
464
- rootStyle.overflowX = 'hidden';
465
- }
466
- if (rootProps.autoHeight) {
467
- rootStyle.overflowY = 'hidden';
468
- }
466
+ const rootStyle = React.useMemo(() => {
467
+ const style = {};
468
+ if (!needsHorizontalScrollbar) {
469
+ style.overflowX = 'hidden';
470
+ }
471
+ if (rootProps.autoHeight) {
472
+ style.overflowY = 'hidden';
473
+ }
474
+ return style;
475
+ }, [needsHorizontalScrollbar, rootProps.autoHeight]);
469
476
  const getRenderContext = React.useCallback(() => {
470
477
  return prevRenderContext.current;
471
478
  }, []);
@@ -476,23 +483,18 @@ export const useGridVirtualScroller = props => {
476
483
  renderContext,
477
484
  updateRenderZonePosition,
478
485
  getRows,
479
- getRootProps: (_ref3 = {}) => {
480
- let {
481
- style = {}
482
- } = _ref3,
483
- other = _objectWithoutPropertiesLoose(_ref3, _excluded3);
484
- return _extends({
485
- ref: handleRef,
486
- onScroll: handleScroll,
487
- onWheel: handleWheel,
488
- onTouchMove: handleTouchMove,
489
- style: _extends({}, style, rootStyle)
490
- }, other);
491
- },
486
+ getRootProps: (inputProps = {}) => _extends({
487
+ ref: handleRef,
488
+ onScroll: handleScroll,
489
+ onWheel: handleWheel,
490
+ onTouchMove: handleTouchMove
491
+ }, inputProps, {
492
+ style: inputProps.style ? _extends({}, inputProps.style, rootStyle) : rootStyle
493
+ }),
492
494
  getContentProps: ({
493
- style = {}
495
+ style
494
496
  } = {}) => ({
495
- style: _extends({}, style, contentSize)
497
+ style: style ? _extends({}, style, contentSize) : contentSize
496
498
  }),
497
499
  getRenderZoneProps: () => ({
498
500
  ref: renderZoneRef
@@ -1,6 +1,6 @@
1
1
  export * from './useGridApiEventHandler';
2
2
  export * from './useGridApiMethod';
3
3
  export * from './useGridLogger';
4
- export * from './useGridSelector';
4
+ export { useGridSelector } from './useGridSelector';
5
5
  export * from './useGridNativeEventListener';
6
6
  export * from './useFirstRender';
@@ -1,6 +1,6 @@
1
1
  export * from './useGridApiEventHandler';
2
2
  export * from './useGridApiMethod';
3
3
  export * from './useGridLogger';
4
- export * from './useGridSelector';
4
+ export { useGridSelector } from './useGridSelector';
5
5
  export * from './useGridNativeEventListener';
6
6
  export * from './useFirstRender';
@@ -1,4 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { GridApiCommon } from '../../models/api/gridApiCommon';
3
3
  import { OutputSelector } from '../../utils/createSelector';
4
- export declare const useGridSelector: <Api extends GridApiCommon<any, any>, T>(apiRef: React.MutableRefObject<Api>, selector: OutputSelector<Api["state"], T> | ((state: Api["state"]) => T)) => T;
4
+ import { fastObjectShallowCompare } from '../../utils/fastObjectShallowCompare';
5
+ export declare const objectShallowCompare: typeof fastObjectShallowCompare;
6
+ export declare const useGridSelector: <Api extends GridApiCommon<any, any>, T>(apiRef: React.MutableRefObject<Api>, selector: OutputSelector<Api["state"], T> | ((state: Api["state"]) => T), equals?: (a: T, b: T) => boolean) => T;
@@ -1,16 +1,47 @@
1
+ import * as React from 'react';
2
+ import { useLazyRef } from './useLazyRef';
3
+ import { useOnMount } from './useOnMount';
1
4
  import { buildWarning } from '../../utils/warning';
5
+ import { fastObjectShallowCompare } from '../../utils/fastObjectShallowCompare';
6
+ const stateNotInitializedWarning = buildWarning(['MUI: `useGridSelector` has been called before the initialization of the state.', 'This hook can only be used inside the context of the grid.']);
2
7
  function isOutputSelector(selector) {
3
8
  return selector.acceptsApiRef;
4
9
  }
5
- const stateNotInitializedWarning = buildWarning(['MUI: `useGridSelector` has been called before the initialization of the state.', 'This hook can only be used inside the context of the grid.']);
6
- export const useGridSelector = (apiRef, selector) => {
10
+ function applySelector(apiRef, selector) {
11
+ if (isOutputSelector(selector)) {
12
+ return selector(apiRef);
13
+ }
14
+ return selector(apiRef.current.state);
15
+ }
16
+ const defaultCompare = Object.is;
17
+ export const objectShallowCompare = fastObjectShallowCompare;
18
+ const createRefs = () => ({
19
+ state: null,
20
+ equals: null,
21
+ selector: null
22
+ });
23
+ export const useGridSelector = (apiRef, selector, equals = defaultCompare) => {
7
24
  if (process.env.NODE_ENV !== 'production') {
8
25
  if (!apiRef.current.state) {
9
26
  stateNotInitializedWarning();
10
27
  }
11
28
  }
12
- if (isOutputSelector(selector)) {
13
- return selector(apiRef);
14
- }
15
- return selector(apiRef.current.state);
29
+ const refs = useLazyRef(createRefs);
30
+ const didInit = refs.current.selector !== null;
31
+ const [state, setState] = React.useState(
32
+ // We don't use an initialization function to avoid allocations
33
+ didInit ? null : applySelector(apiRef, selector));
34
+ refs.current.state = state;
35
+ refs.current.equals = equals;
36
+ refs.current.selector = selector;
37
+ useOnMount(() => {
38
+ return apiRef.current.store.subscribe(() => {
39
+ const newState = applySelector(apiRef, refs.current.selector);
40
+ if (!refs.current.equals(refs.current.state, newState)) {
41
+ refs.current.state = newState;
42
+ setState(newState);
43
+ }
44
+ });
45
+ });
46
+ return state;
16
47
  };
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ export declare function useLazyRef<T, U>(init: (arg?: U) => T, initArg?: U): React.MutableRefObject<T>;
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ const UNINITIALIZED = {};
3
+ export function useLazyRef(init, initArg) {
4
+ const ref = React.useRef(UNINITIALIZED);
5
+ if (ref.current === UNINITIALIZED) {
6
+ ref.current = init(initArg);
7
+ }
8
+ return ref;
9
+ }
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ export declare function useOnMount(fn: React.EffectCallback): void;
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ const EMPTY = [];
3
+ export function useOnMount(fn) {
4
+ /* eslint-disable react-hooks/exhaustive-deps */
5
+ React.useEffect(fn, EMPTY);
6
+ /* eslint-enable react-hooks/exhaustive-deps */
7
+ }
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v6.7.0
2
+ * @mui/x-data-grid v6.9.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -61,7 +61,7 @@ export { useGridInitializeState } from '../hooks/utils/useGridInitializeState';
61
61
  export type { GridStateInitializer } from '../hooks/utils/useGridInitializeState';
62
62
  export type { GridExperimentalFeatures, DataGridPropsWithoutDefaultValue, DataGridPropsWithDefaultValues, DataGridPropsWithComplexDefaultValueAfterProcessing, DataGridPropsWithComplexDefaultValueBeforeProcessing, } from '../models/props/DataGridProps';
63
63
  export { getColumnsToExport, defaultGetRowsToExport } from '../hooks/features/export/utils';
64
- export { createSelector, unstable_resetCreateSelectorCache } from '../utils/createSelector';
64
+ export { createSelector, createSelectorMemoized, unstable_resetCreateSelectorCache, } from '../utils/createSelector';
65
65
  export { findParentElementFromClassName, getActiveElement } from '../utils/domUtils';
66
66
  export { isNavigationKey } from '../utils/keyboardUtils';
67
67
  export { clamp, isDeepEqual, isNumber, isFunction, isObject } from '../utils/utils';
@@ -48,7 +48,7 @@ export { useGridVirtualScroller, getRenderableIndexes } from '../hooks/features/
48
48
  export { useGridVisibleRows, getVisibleRows } from '../hooks/utils/useGridVisibleRows';
49
49
  export { useGridInitializeState } from '../hooks/utils/useGridInitializeState';
50
50
  export { getColumnsToExport, defaultGetRowsToExport } from '../hooks/features/export/utils';
51
- export { createSelector, unstable_resetCreateSelectorCache } from '../utils/createSelector';
51
+ export { createSelector, createSelectorMemoized, unstable_resetCreateSelectorCache } from '../utils/createSelector';
52
52
  export { findParentElementFromClassName, getActiveElement } from '../utils/domUtils';
53
53
  export { isNavigationKey } from '../utils/keyboardUtils';
54
54
  export { clamp, isDeepEqual, isNumber, isFunction, isObject } from '../utils/utils';
@@ -3,6 +3,7 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
3
3
  var _excluded = ["innerRef", "className", "visibleColumns", "sortColumnLookup", "filterColumnLookup", "columnPositions", "columnHeaderTabIndexState", "columnGroupHeaderTabIndexState", "columnHeaderFocus", "columnGroupHeaderFocus", "densityFactor", "headerGroupingMaxDepth", "columnMenuState", "columnVisibility", "columnGroupsHeaderStructure", "hasOtherElementInTabSequence"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
+ import { fastMemo } from '../utils/fastMemo';
6
7
  import { useGridColumnHeaders } from '../hooks/features/columnHeaders/useGridColumnHeaders';
7
8
  import { GridBaseColumnHeaders } from './columnHeaders/GridBaseColumnHeaders';
8
9
  import { GridColumnHeadersInner } from './columnHeaders/GridColumnHeadersInner';
@@ -98,4 +99,5 @@ process.env.NODE_ENV !== "production" ? GridColumnHeaders.propTypes = {
98
99
  sortColumnLookup: PropTypes.object.isRequired,
99
100
  visibleColumns: PropTypes.arrayOf(PropTypes.object).isRequired
100
101
  } : void 0;
101
- export { GridColumnHeaders };
102
+ var MemoizedGridColumnHeaders = fastMemo(GridColumnHeaders);
103
+ export { MemoizedGridColumnHeaders as GridColumnHeaders };
@@ -2,18 +2,18 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
- var _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "isLastVisible", "focusedCell", "tabbableCell", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"],
6
- _excluded2 = ["changeReason", "unstable_updateValueOnRender"];
5
+ var _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "isLastVisible", "focusedCell", "tabbableCell", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"];
7
6
  import * as React from 'react';
8
7
  import PropTypes from 'prop-types';
9
8
  import clsx from 'clsx';
10
9
  import { unstable_composeClasses as composeClasses, unstable_useForkRef as useForkRef } from '@mui/utils';
10
+ import { fastMemo } from '../utils/fastMemo';
11
11
  import { GridEditModes, GridRowModes, GridCellModes } from '../models/gridEditRowModel';
12
12
  import { useGridApiContext } from '../hooks/utils/useGridApiContext';
13
13
  import { getDataGridUtilityClass, gridClasses } from '../constants/gridClasses';
14
14
  import { useGridRootProps } from '../hooks/utils/useGridRootProps';
15
15
  import { gridColumnsTotalWidthSelector } from '../hooks/features/columns/gridColumnsSelector';
16
- import { useGridSelector } from '../hooks/utils/useGridSelector';
16
+ import { useGridSelector, objectShallowCompare } from '../hooks/utils/useGridSelector';
17
17
  import { useGridVisibleRows } from '../hooks/utils/useGridVisibleRows';
18
18
  import { findParentElementFromClassName } from '../utils/domUtils';
19
19
  import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../colDef/gridCheckboxSelectionColDef';
@@ -23,6 +23,7 @@ import { gridSortModelSelector } from '../hooks/features/sorting/gridSortingSele
23
23
  import { gridRowMaximumTreeDepthSelector } from '../hooks/features/rows/gridRowsSelector';
24
24
  import { gridColumnGroupsHeaderMaxDepthSelector } from '../hooks/features/columnGrouping/gridColumnGroupsSelector';
25
25
  import { randomNumberBetween } from '../utils/utils';
26
+ import { GridCellWrapper, GridCellV7 } from './cell/GridCell';
26
27
  import { gridEditRowsStateSelector } from '../hooks/features/editing/gridEditingSelectors';
27
28
  import { jsx as _jsx } from "react/jsx-runtime";
28
29
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -187,79 +188,29 @@ var GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
187
188
  }, [apiRef, onClick, publish, rowId]);
188
189
  var slots = rootProps.slots,
189
190
  slotProps = rootProps.slotProps,
190
- rootClasses = rootProps.classes,
191
- disableColumnReorder = rootProps.disableColumnReorder,
192
- getCellClassName = rootProps.getCellClassName;
191
+ disableColumnReorder = rootProps.disableColumnReorder;
192
+ var CellComponent = slots.cell === GridCellV7 ? GridCellV7 : GridCellWrapper;
193
193
  var rowReordering = rootProps.rowReordering;
194
- var CellComponent = slots.cell;
195
- var getCell = React.useCallback(function (column, cellProps) {
196
- var cellParams = apiRef.current.getCellParams(rowId, column.field);
197
- var classNames = apiRef.current.unstable_applyPipeProcessors('cellClassName', [], {
198
- id: rowId,
199
- field: column.field
200
- });
194
+ var getCell = function getCell(column, cellProps) {
195
+ var _editRowsState$rowId$, _editRowsState$rowId;
201
196
  var disableDragEvents = disableColumnReorder && column.disableReorder || !rowReordering && !!sortModel.length && treeDepth > 1 && Object.keys(editRowsState).length > 0;
202
- if (column.cellClassName) {
203
- classNames.push(clsx(typeof column.cellClassName === 'function' ? column.cellClassName(cellParams) : column.cellClassName));
204
- }
205
- var editCellState = editRowsState[rowId] ? editRowsState[rowId][column.field] : null;
206
- var content;
207
- if (editCellState == null && column.renderCell) {
208
- content = column.renderCell(_extends({}, cellParams, {
209
- api: apiRef.current
210
- }));
211
- // TODO move to GridCell
212
- classNames.push(clsx(gridClasses['cell--withRenderer'], rootClasses == null ? void 0 : rootClasses['cell--withRenderer']));
213
- }
214
- if (editCellState != null && column.renderEditCell) {
215
- var updatedRow = apiRef.current.getRowWithUpdatedValues(rowId, column.field);
216
-
217
- // eslint-disable-next-line @typescript-eslint/naming-convention
218
- var changeReason = editCellState.changeReason,
219
- unstable_updateValueOnRender = editCellState.unstable_updateValueOnRender,
220
- editCellStateRest = _objectWithoutProperties(editCellState, _excluded2);
221
- var params = _extends({}, cellParams, {
222
- row: updatedRow
223
- }, editCellStateRest, {
224
- api: apiRef.current
225
- });
226
- content = column.renderEditCell(params);
227
- // TODO move to GridCell
228
- classNames.push(clsx(gridClasses['cell--editing'], rootClasses == null ? void 0 : rootClasses['cell--editing']));
229
- }
230
- if (getCellClassName) {
231
- // TODO move to GridCell
232
- classNames.push(getCellClassName(cellParams));
233
- }
234
- var hasFocus = focusedCell === column.field;
235
- var tabIndex = tabbableCell === column.field ? 0 : -1;
236
- var isSelected = apiRef.current.unstable_applyPipeProcessors('isCellSelected', false, {
237
- id: rowId,
238
- field: column.field
239
- });
197
+ var editCellState = (_editRowsState$rowId$ = (_editRowsState$rowId = editRowsState[rowId]) == null ? void 0 : _editRowsState$rowId[column.field]) != null ? _editRowsState$rowId$ : null;
240
198
  return /*#__PURE__*/_jsx(CellComponent, _extends({
241
- value: cellParams.value,
242
- field: column.field,
199
+ column: column,
243
200
  width: cellProps.width,
244
201
  rowId: rowId,
245
202
  height: rowHeight,
246
203
  showRightBorder: cellProps.showRightBorder,
247
- formattedValue: cellParams.formattedValue,
248
204
  align: column.align || 'left',
249
- cellMode: cellParams.cellMode,
250
205
  colIndex: cellProps.indexRelativeToAllColumns,
251
- isEditable: cellParams.isEditable,
252
- isSelected: isSelected,
253
- hasFocus: hasFocus,
254
- tabIndex: tabIndex,
255
- className: clsx(classNames),
256
206
  colSpan: cellProps.colSpan,
257
- disableDragEvents: disableDragEvents
258
- }, slotProps == null ? void 0 : slotProps.cell, {
259
- children: content
260
- }), column.field);
261
- }, [apiRef, rowId, disableColumnReorder, rowReordering, sortModel.length, treeDepth, editRowsState, getCellClassName, focusedCell, tabbableCell, CellComponent, rowHeight, slotProps == null ? void 0 : slotProps.cell, rootClasses]);
262
- var sizes = apiRef.current.unstable_getRowInternalSizes(rowId);
207
+ disableDragEvents: disableDragEvents,
208
+ editCellState: editCellState
209
+ }, slotProps == null ? void 0 : slotProps.cell), column.field);
210
+ };
211
+ var sizes = useGridSelector(apiRef, function () {
212
+ return _extends({}, apiRef.current.unstable_getRowInternalSizes(rowId));
213
+ }, objectShallowCompare);
263
214
  var minHeight = rowHeight;
264
215
  if (minHeight === 'auto' && sizes) {
265
216
  var numberOfBaseSizes = 0;
@@ -312,7 +263,11 @@ var GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
312
263
  rowClassNames.push(rootProps.getRowClassName(rowParams));
313
264
  }
314
265
  var randomNumber = randomNumberBetween(10000, 20, 80);
315
- var rowType = apiRef.current.getRowNode(rowId).type;
266
+ var rowNode = apiRef.current.getRowNode(rowId);
267
+ if (!rowNode) {
268
+ return null;
269
+ }
270
+ var rowType = rowNode.type;
316
271
  var cells = [];
317
272
  for (var i = 0; i < renderedColumns.length; i += 1) {
318
273
  var column = renderedColumns[i];
@@ -333,7 +288,7 @@ var GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
333
288
  } else {
334
289
  var _width = cellColSpanInfo.cellProps.width;
335
290
  var contentWidth = Math.round(randomNumber());
336
- cells.push( /*#__PURE__*/_jsx(rootProps.slots.skeletonCell, {
291
+ cells.push( /*#__PURE__*/_jsx(slots.skeletonCell, {
337
292
  width: _width,
338
293
  contentWidth: contentWidth,
339
294
  field: column.field,
@@ -369,8 +324,8 @@ process.env.NODE_ENV !== "production" ? GridRow.propTypes = {
369
324
  // | These PropTypes are generated from the TypeScript type definitions |
370
325
  // | To update them edit the TypeScript types and run "yarn proptypes" |
371
326
  // ----------------------------------------------------------------------
372
- containerWidth: PropTypes.number,
373
- firstColumnToRender: PropTypes.number,
327
+ containerWidth: PropTypes.number.isRequired,
328
+ firstColumnToRender: PropTypes.number.isRequired,
374
329
  /**
375
330
  * Determines which cell has focus.
376
331
  * If `null`, no cell in this row has focus.
@@ -380,24 +335,25 @@ process.env.NODE_ENV !== "production" ? GridRow.propTypes = {
380
335
  * Index of the row in the whole sorted and filtered dataset.
381
336
  * If some rows above have expanded children, this index also take those children into account.
382
337
  */
383
- index: PropTypes.number,
338
+ index: PropTypes.number.isRequired,
384
339
  isLastVisible: PropTypes.bool,
385
- lastColumnToRender: PropTypes.number,
340
+ lastColumnToRender: PropTypes.number.isRequired,
386
341
  onClick: PropTypes.func,
387
342
  onDoubleClick: PropTypes.func,
388
343
  onMouseEnter: PropTypes.func,
389
344
  onMouseLeave: PropTypes.func,
390
- position: PropTypes.oneOf(['center', 'left', 'right']),
391
- renderedColumns: PropTypes.arrayOf(PropTypes.object),
345
+ position: PropTypes.oneOf(['center', 'left', 'right']).isRequired,
346
+ renderedColumns: PropTypes.arrayOf(PropTypes.object).isRequired,
392
347
  row: PropTypes.object,
393
- rowHeight: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
394
- rowId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
395
- selected: PropTypes.bool,
348
+ rowHeight: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]).isRequired,
349
+ rowId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
350
+ selected: PropTypes.bool.isRequired,
396
351
  /**
397
352
  * Determines which cell should be tabbable by having tabIndex=0.
398
353
  * If `null`, no cell in this row is in the tab sequence.
399
354
  */
400
355
  tabbableCell: PropTypes.string,
401
- visibleColumns: PropTypes.arrayOf(PropTypes.object)
356
+ visibleColumns: PropTypes.arrayOf(PropTypes.object).isRequired
402
357
  } : void 0;
403
- export { GridRow };
358
+ var MemoizedGridRow = fastMemo(GridRow);
359
+ export { MemoizedGridRow as GridRow };