@mui/x-data-grid 7.13.0 → 7.15.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 (91) hide show
  1. package/CHANGELOG.md +151 -2
  2. package/components/cell/GridActionsCell.js +3 -3
  3. package/components/cell/GridCell.js +11 -12
  4. package/components/cell/GridEditSingleSelectCell.js +2 -3
  5. package/components/menu/columnMenu/GridColumnMenuContainer.js +2 -2
  6. package/components/panel/GridPanel.d.ts +1 -1
  7. package/components/panel/GridPanel.js +1 -2
  8. package/components/panel/filterPanel/GridFilterForm.js +9 -4
  9. package/components/toolbar/GridToolbarDensitySelector.js +2 -2
  10. package/components/toolbar/GridToolbarExportContainer.js +2 -2
  11. package/components/toolbar/GridToolbarQuickFilter.js +5 -3
  12. package/hooks/core/gridCoreSelector.d.ts +1 -1
  13. package/hooks/core/gridCoreSelector.js +1 -1
  14. package/hooks/core/useGridInitialization.js +2 -2
  15. package/hooks/core/{useGridTheme.d.ts → useGridIsRtl.d.ts} +1 -1
  16. package/hooks/core/{useGridTheme.js → useGridIsRtl.js} +7 -7
  17. package/hooks/features/columnHeaders/useGridColumnHeaders.js +4 -3
  18. package/hooks/features/columnResize/useGridColumnResize.js +5 -5
  19. package/hooks/features/columns/gridColumnsSelector.js +3 -3
  20. package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +19 -20
  21. package/hooks/features/rows/useGridParamsApi.js +2 -1
  22. package/hooks/features/scroll/useGridScroll.js +4 -4
  23. package/hooks/features/virtualization/useGridVirtualScroller.d.ts +1 -2
  24. package/hooks/features/virtualization/useGridVirtualScroller.js +13 -13
  25. package/hooks/utils/useGridSelector.d.ts +4 -1
  26. package/hooks/utils/useGridSelector.js +38 -0
  27. package/index.js +1 -1
  28. package/internals/index.d.ts +2 -1
  29. package/internals/index.js +2 -1
  30. package/locales/csCZ.js +4 -5
  31. package/locales/heIL.js +4 -5
  32. package/models/gridDataSource.d.ts +6 -6
  33. package/models/gridStateCommunity.d.ts +1 -2
  34. package/models/params/gridCellParams.d.ts +4 -0
  35. package/modern/components/cell/GridActionsCell.js +3 -3
  36. package/modern/components/cell/GridCell.js +11 -12
  37. package/modern/components/cell/GridEditSingleSelectCell.js +2 -3
  38. package/modern/components/menu/columnMenu/GridColumnMenuContainer.js +2 -2
  39. package/modern/components/panel/GridPanel.js +1 -2
  40. package/modern/components/panel/filterPanel/GridFilterForm.js +9 -4
  41. package/modern/components/toolbar/GridToolbarDensitySelector.js +2 -2
  42. package/modern/components/toolbar/GridToolbarExportContainer.js +2 -2
  43. package/modern/components/toolbar/GridToolbarQuickFilter.js +5 -3
  44. package/modern/hooks/core/gridCoreSelector.js +1 -1
  45. package/modern/hooks/core/useGridInitialization.js +2 -2
  46. package/modern/hooks/core/{useGridTheme.js → useGridIsRtl.js} +7 -7
  47. package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +4 -3
  48. package/modern/hooks/features/columnResize/useGridColumnResize.js +5 -5
  49. package/modern/hooks/features/columns/gridColumnsSelector.js +3 -3
  50. package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +19 -20
  51. package/modern/hooks/features/rows/useGridParamsApi.js +2 -1
  52. package/modern/hooks/features/scroll/useGridScroll.js +4 -4
  53. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +13 -13
  54. package/modern/hooks/utils/useGridSelector.js +38 -0
  55. package/modern/index.js +1 -1
  56. package/modern/internals/index.js +2 -1
  57. package/modern/locales/csCZ.js +4 -5
  58. package/modern/locales/heIL.js +4 -5
  59. package/modern/utils/createSelector.js +116 -0
  60. package/modern/utils/keyboardUtils.js +1 -11
  61. package/node/components/cell/GridActionsCell.js +3 -3
  62. package/node/components/cell/GridCell.js +11 -12
  63. package/node/components/cell/GridEditSingleSelectCell.js +2 -3
  64. package/node/components/menu/columnMenu/GridColumnMenuContainer.js +1 -1
  65. package/node/components/panel/GridPanel.js +1 -2
  66. package/node/components/panel/filterPanel/GridFilterForm.js +9 -4
  67. package/node/components/toolbar/GridToolbarDensitySelector.js +1 -1
  68. package/node/components/toolbar/GridToolbarExportContainer.js +1 -1
  69. package/node/components/toolbar/GridToolbarQuickFilter.js +5 -3
  70. package/node/hooks/core/gridCoreSelector.js +3 -3
  71. package/node/hooks/core/useGridInitialization.js +2 -2
  72. package/node/hooks/core/{useGridTheme.js → useGridIsRtl.js} +9 -9
  73. package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +3 -2
  74. package/node/hooks/features/columnResize/useGridColumnResize.js +5 -5
  75. package/node/hooks/features/columns/gridColumnsSelector.js +2 -2
  76. package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +19 -20
  77. package/node/hooks/features/rows/useGridParamsApi.js +2 -1
  78. package/node/hooks/features/scroll/useGridScroll.js +4 -4
  79. package/node/hooks/features/virtualization/useGridVirtualScroller.js +13 -13
  80. package/node/hooks/utils/useGridSelector.js +41 -2
  81. package/node/index.js +1 -1
  82. package/node/internals/index.js +22 -0
  83. package/node/locales/csCZ.js +4 -5
  84. package/node/locales/heIL.js +4 -5
  85. package/node/utils/createSelector.js +119 -2
  86. package/node/utils/keyboardUtils.js +2 -15
  87. package/package.json +6 -6
  88. package/utils/createSelector.d.ts +19 -0
  89. package/utils/createSelector.js +116 -0
  90. package/utils/keyboardUtils.d.ts +1 -9
  91. package/utils/keyboardUtils.js +1 -11
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { useTheme } from '@mui/material/styles';
2
+ import { useRtl } from '@mui/system/RtlProvider';
3
3
  import { gridVisibleColumnDefinitionsSelector } from '../columns/gridColumnsSelector';
4
4
  import { useGridLogger } from '../../utils/useGridLogger';
5
5
  import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
@@ -24,13 +24,13 @@ const getLeftColumnIndex = ({
24
24
  currentColIndex,
25
25
  firstColIndex,
26
26
  lastColIndex,
27
- direction
27
+ isRtl
28
28
  }) => {
29
- if (direction === 'rtl') {
29
+ if (isRtl) {
30
30
  if (currentColIndex < lastColIndex) {
31
31
  return currentColIndex + 1;
32
32
  }
33
- } else if (direction === 'ltr') {
33
+ } else if (!isRtl) {
34
34
  if (currentColIndex > firstColIndex) {
35
35
  return currentColIndex - 1;
36
36
  }
@@ -41,13 +41,13 @@ const getRightColumnIndex = ({
41
41
  currentColIndex,
42
42
  firstColIndex,
43
43
  lastColIndex,
44
- direction
44
+ isRtl
45
45
  }) => {
46
- if (direction === 'rtl') {
46
+ if (isRtl) {
47
47
  if (currentColIndex > firstColIndex) {
48
48
  return currentColIndex - 1;
49
49
  }
50
- } else if (direction === 'ltr') {
50
+ } else if (!isRtl) {
51
51
  if (currentColIndex < lastColIndex) {
52
52
  return currentColIndex + 1;
53
53
  }
@@ -67,7 +67,7 @@ const getRightColumnIndex = ({
67
67
  export const useGridKeyboardNavigation = (apiRef, props) => {
68
68
  const logger = useGridLogger(apiRef, 'useGridKeyboardNavigation');
69
69
  const initialCurrentPageRows = useGridVisibleRows(apiRef, props).rows;
70
- const theme = useTheme();
70
+ const isRtl = useRtl();
71
71
  const currentPageRows = React.useMemo(() => enrichPageRowsWithPinnedRows(apiRef, initialCurrentPageRows), [apiRef, initialCurrentPageRows]);
72
72
  const headerFilteringEnabled = props.signature !== 'DataGrid' && props.headerFilters;
73
73
 
@@ -161,7 +161,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
161
161
  currentColIndex: colIndexBefore,
162
162
  firstColIndex,
163
163
  lastColIndex,
164
- direction: theme.direction
164
+ isRtl
165
165
  });
166
166
  if (rightColIndex !== null) {
167
167
  goToHeader(rightColIndex, event);
@@ -174,7 +174,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
174
174
  currentColIndex: colIndexBefore,
175
175
  firstColIndex,
176
176
  lastColIndex,
177
- direction: theme.direction
177
+ isRtl
178
178
  });
179
179
  if (leftColIndex !== null) {
180
180
  goToHeader(leftColIndex, event);
@@ -225,7 +225,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
225
225
  if (shouldPreventDefault) {
226
226
  event.preventDefault();
227
227
  }
228
- }, [apiRef, currentPageRows.length, headerFilteringEnabled, goToHeaderFilter, goToCell, getRowIdFromIndex, theme.direction, goToHeader, goToGroupHeader]);
228
+ }, [apiRef, currentPageRows.length, headerFilteringEnabled, goToHeaderFilter, goToCell, getRowIdFromIndex, isRtl, goToHeader, goToGroupHeader]);
229
229
  const handleHeaderFilterKeyDown = React.useCallback((params, event) => {
230
230
  const isEditing = gridHeaderFilteringEditFieldSelector(apiRef) === params.field;
231
231
  const isHeaderMenuOpen = gridHeaderFilteringMenuSelector(apiRef) === params.field;
@@ -254,7 +254,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
254
254
  currentColIndex: colIndexBefore,
255
255
  firstColIndex,
256
256
  lastColIndex,
257
- direction: theme.direction
257
+ isRtl
258
258
  });
259
259
  if (rightColIndex !== null) {
260
260
  goToHeaderFilter(rightColIndex, event);
@@ -267,7 +267,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
267
267
  currentColIndex: colIndexBefore,
268
268
  firstColIndex,
269
269
  lastColIndex,
270
- direction: theme.direction
270
+ isRtl
271
271
  });
272
272
  if (leftColIndex !== null) {
273
273
  goToHeaderFilter(leftColIndex, event);
@@ -311,7 +311,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
311
311
  if (shouldPreventDefault) {
312
312
  event.preventDefault();
313
313
  }
314
- }, [apiRef, currentPageRows.length, goToHeaderFilter, theme.direction, goToHeader, goToCell, getRowIdFromIndex]);
314
+ }, [apiRef, currentPageRows.length, goToHeaderFilter, isRtl, goToHeader, goToCell, getRowIdFromIndex]);
315
315
  const handleColumnGroupHeaderKeyDown = React.useCallback((params, event) => {
316
316
  const focusedColumnGroup = gridFocusColumnGroupHeaderSelector(apiRef);
317
317
  if (focusedColumnGroup === null) {
@@ -419,7 +419,6 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
419
419
  if (currentPageRows.length === 0) {
420
420
  return;
421
421
  }
422
- const direction = theme.direction;
423
422
  const viewportPageSize = apiRef.current.getViewportPageSize();
424
423
  const colIndexBefore = params.field ? apiRef.current.getColumnIndex(params.field) : 0;
425
424
  const rowIndexBefore = currentPageRows.findIndex(row => row.id === params.id);
@@ -454,10 +453,10 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
454
453
  currentColIndex: colIndexBefore,
455
454
  firstColIndex,
456
455
  lastColIndex,
457
- direction
456
+ isRtl
458
457
  });
459
458
  if (rightColIndex !== null) {
460
- goToCell(rightColIndex, getRowIdFromIndex(rowIndexBefore), direction === 'rtl' ? 'left' : 'right');
459
+ goToCell(rightColIndex, getRowIdFromIndex(rowIndexBefore), isRtl ? 'left' : 'right');
461
460
  }
462
461
  break;
463
462
  }
@@ -467,10 +466,10 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
467
466
  currentColIndex: colIndexBefore,
468
467
  firstColIndex,
469
468
  lastColIndex,
470
- direction
469
+ isRtl
471
470
  });
472
471
  if (leftColIndex !== null) {
473
- goToCell(leftColIndex, getRowIdFromIndex(rowIndexBefore), direction === 'rtl' ? 'right' : 'left');
472
+ goToCell(leftColIndex, getRowIdFromIndex(rowIndexBefore), isRtl ? 'right' : 'left');
474
473
  }
475
474
  break;
476
475
  }
@@ -545,7 +544,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
545
544
  if (shouldPreventDefault) {
546
545
  event.preventDefault();
547
546
  }
548
- }, [apiRef, currentPageRows, theme.direction, goToCell, getRowIdFromIndex, headerFilteringEnabled, goToHeaderFilter, goToHeader]);
547
+ }, [apiRef, currentPageRows, isRtl, goToCell, getRowIdFromIndex, headerFilteringEnabled, goToHeaderFilter, goToHeader]);
549
548
  const checkIfCanStartEditing = React.useCallback((initialValue, {
550
549
  event
551
550
  }) => {
@@ -51,7 +51,8 @@ export function useGridParamsApi(apiRef) {
51
51
  tabIndex: cellTabIndex && cellTabIndex.field === field && cellTabIndex.id === id ? 0 : -1,
52
52
  value,
53
53
  formattedValue: value,
54
- isEditable: false
54
+ isEditable: false,
55
+ api: {}
55
56
  };
56
57
  if (colDef && colDef.valueFormatter) {
57
58
  params.formattedValue = colDef.valueFormatter(value, row, colDef, apiRef);
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { useTheme } from '@mui/material/styles';
2
+ import { useRtl } from '@mui/system/RtlProvider';
3
3
  import { useGridLogger } from '../../utils/useGridLogger';
4
4
  import { gridColumnPositionsSelector, gridVisibleColumnDefinitionsSelector } from '../columns/gridColumnsSelector';
5
5
  import { useGridSelector } from '../../utils/useGridSelector';
@@ -43,7 +43,7 @@ function scrollIntoView(dimensions) {
43
43
  * @requires useGridColumnSpanning (method)
44
44
  */
45
45
  export const useGridScroll = (apiRef, props) => {
46
- const theme = useTheme();
46
+ const isRtl = useRtl();
47
47
  const logger = useGridLogger(apiRef, 'useGridScroll');
48
48
  const colRef = apiRef.current.columnHeadersContainerRef;
49
49
  const virtualScrollerRef = apiRef.current.virtualScrollerRef;
@@ -101,7 +101,7 @@ export const useGridScroll = (apiRef, props) => {
101
101
  }, [logger, apiRef, virtualScrollerRef, props.pagination, visibleSortedRows]);
102
102
  const scroll = React.useCallback(params => {
103
103
  if (virtualScrollerRef.current && params.left !== undefined && colRef.current) {
104
- const direction = theme.direction === 'rtl' ? -1 : 1;
104
+ const direction = isRtl ? -1 : 1;
105
105
  colRef.current.scrollLeft = params.left;
106
106
  virtualScrollerRef.current.scrollLeft = direction * params.left;
107
107
  logger.debug(`Scrolling left: ${params.left}`);
@@ -111,7 +111,7 @@ export const useGridScroll = (apiRef, props) => {
111
111
  logger.debug(`Scrolling top: ${params.top}`);
112
112
  }
113
113
  logger.debug(`Scrolling, updating container, and viewport`);
114
- }, [virtualScrollerRef, theme.direction, colRef, logger]);
114
+ }, [virtualScrollerRef, isRtl, colRef, logger]);
115
115
  const getScrollPosition = React.useCallback(() => {
116
116
  if (!virtualScrollerRef?.current) {
117
117
  return {
@@ -1,5 +1,4 @@
1
1
  import * as React from 'react';
2
- import { Theme } from '@mui/material/styles';
3
2
  import { GridPinnedRowsPosition } from '../rows/gridRowsInterfaces';
4
3
  import type { GridRenderContext, GridColumnsRenderContext, GridRowEntry, GridRowId } from '../../../models';
5
4
  export type VirtualScroller = ReturnType<typeof useGridVirtualScroller>;
@@ -41,4 +40,4 @@ export declare const useGridVirtualScroller: () => {
41
40
  };
42
41
  };
43
42
  export declare function areRenderContextsEqual(context1: GridRenderContext, context2: GridRenderContext): boolean;
44
- export declare function computeOffsetLeft(columnPositions: number[], renderContext: GridColumnsRenderContext, direction: Theme['direction'], pinnedLeftLength: number): number;
43
+ export declare function computeOffsetLeft(columnPositions: number[], renderContext: GridColumnsRenderContext, isRtl: boolean, pinnedLeftLength: number): number;
@@ -5,7 +5,7 @@ import { unstable_useEnhancedEffect as useEnhancedEffect, unstable_useEventCallb
5
5
  import useLazyRef from '@mui/utils/useLazyRef';
6
6
  import useTimeout from '@mui/utils/useTimeout';
7
7
  import { useResizeObserver } from '@mui/x-internals/useResizeObserver';
8
- import { useTheme } from '@mui/material/styles';
8
+ import { useRtl } from '@mui/system/RtlProvider';
9
9
  import { useGridPrivateApiContext } from '../../utils/useGridPrivateApiContext';
10
10
  import { useGridRootProps } from '../../utils/useGridRootProps';
11
11
  import { useGridSelector } from '../../utils/useGridSelector';
@@ -39,9 +39,9 @@ const EMPTY_SCROLL_POSITION = {
39
39
  left: 0
40
40
  };
41
41
  export const EMPTY_DETAIL_PANELS = Object.freeze(new Map());
42
- const createScrollCache = (mode, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer) => ({
42
+ const createScrollCache = (isRtl, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer) => ({
43
43
  direction: ScrollDirection.NONE,
44
- buffer: bufferForDirection(mode, ScrollDirection.NONE, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer)
44
+ buffer: bufferForDirection(isRtl, ScrollDirection.NONE, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer)
45
45
  });
46
46
  let isJSDOM = false;
47
47
  try {
@@ -63,7 +63,7 @@ export const useGridVirtualScroller = () => {
63
63
  const pinnedColumns = useGridSelector(apiRef, gridVisiblePinnedColumnDefinitionsSelector);
64
64
  const hasBottomPinnedRows = pinnedRows.bottom.length > 0;
65
65
  const [panels, setPanels] = React.useState(EMPTY_DETAIL_PANELS);
66
- const theme = useTheme();
66
+ const isRtl = useRtl();
67
67
  const cellFocus = useGridSelector(apiRef, gridFocusCellSelector);
68
68
  const cellTabIndex = useGridSelector(apiRef, gridTabIndexCellSelector);
69
69
  const rowsMeta = useGridSelector(apiRef, gridRowsMetaSelector);
@@ -100,7 +100,7 @@ export const useGridVirtualScroller = () => {
100
100
  const renderContext = useGridSelector(apiRef, gridRenderContextSelector);
101
101
  const scrollTimeout = useTimeout();
102
102
  const frozenContext = React.useRef(undefined);
103
- const scrollCache = useLazyRef(() => createScrollCache(theme.direction, rootProps.rowBufferPx, rootProps.columnBufferPx, dimensions.rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6)).current;
103
+ const scrollCache = useLazyRef(() => createScrollCache(isRtl, rootProps.rowBufferPx, rootProps.columnBufferPx, dimensions.rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6)).current;
104
104
  const focusedCell = {
105
105
  rowIndex: React.useMemo(() => cellFocus ? currentPage.rows.findIndex(row => row.id === cellFocus.id) : -1, [cellFocus, currentPage.rows]),
106
106
  columnIndex: React.useMemo(() => cellFocus ? visibleColumns.findIndex(column => column.field === cellFocus.field) : -1, [cellFocus, visibleColumns])
@@ -165,7 +165,7 @@ export const useGridVirtualScroller = () => {
165
165
  }
166
166
  }
167
167
  scrollCache.direction = direction;
168
- scrollCache.buffer = bufferForDirection(theme.direction, direction, rootProps.rowBufferPx, rootProps.columnBufferPx, dimensions.rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6);
168
+ scrollCache.buffer = bufferForDirection(isRtl, direction, rootProps.rowBufferPx, rootProps.columnBufferPx, dimensions.rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6);
169
169
  const inputs = inputsSelector(apiRef, rootProps, enabled, enabledForColumns);
170
170
  const nextRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
171
171
 
@@ -193,12 +193,12 @@ export const useGridVirtualScroller = () => {
193
193
  if (scrollTop < 0) {
194
194
  return;
195
195
  }
196
- if (theme.direction === 'ltr') {
196
+ if (!isRtl) {
197
197
  if (scrollLeft < 0) {
198
198
  return;
199
199
  }
200
200
  }
201
- if (theme.direction === 'rtl') {
201
+ if (isRtl) {
202
202
  if (scrollLeft > 0) {
203
203
  return;
204
204
  }
@@ -325,7 +325,7 @@ export const useGridVirtualScroller = () => {
325
325
  if (!isPinnedSection && frozenContext.current && rowIndexInPage >= frozenContext.current.firstRowIndex && rowIndexInPage < frozenContext.current.lastRowIndex) {
326
326
  currentRenderContext = frozenContext.current;
327
327
  }
328
- const offsetLeft = computeOffsetLeft(columnPositions, currentRenderContext, theme.direction, pinnedColumns.left.length);
328
+ const offsetLeft = computeOffsetLeft(columnPositions, currentRenderContext, isRtl, pinnedColumns.left.length);
329
329
  const showBottomBorder = isLastVisibleInSection && params.position === 'top';
330
330
  rows.push( /*#__PURE__*/_jsx(rootProps.slots.row, _extends({
331
331
  row: model,
@@ -645,8 +645,8 @@ export function areRenderContextsEqual(context1, context2) {
645
645
  }
646
646
  return context1.firstRowIndex === context2.firstRowIndex && context1.lastRowIndex === context2.lastRowIndex && context1.firstColumnIndex === context2.firstColumnIndex && context1.lastColumnIndex === context2.lastColumnIndex;
647
647
  }
648
- export function computeOffsetLeft(columnPositions, renderContext, direction, pinnedLeftLength) {
649
- const factor = direction === 'ltr' ? 1 : -1;
648
+ export function computeOffsetLeft(columnPositions, renderContext, isRtl, pinnedLeftLength) {
649
+ const factor = isRtl ? -1 : 1;
650
650
  const left = factor * (columnPositions[renderContext.firstColumnIndex] ?? 0) - (columnPositions[pinnedLeftLength] ?? 0);
651
651
  return Math.abs(left);
652
652
  }
@@ -670,8 +670,8 @@ function directionForDelta(dx, dy) {
670
670
  }
671
671
  /* eslint-enable */
672
672
  }
673
- function bufferForDirection(mode, direction, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer) {
674
- if (mode === 'rtl') {
673
+ function bufferForDirection(isRtl, direction, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer) {
674
+ if (isRtl) {
675
675
  switch (direction) {
676
676
  case ScrollDirection.LEFT:
677
677
  direction = ScrollDirection.RIGHT;
@@ -1,6 +1,9 @@
1
1
  import * as React from 'react';
2
2
  import { fastObjectShallowCompare } from '@mui/x-internals/fastObjectShallowCompare';
3
3
  import type { GridApiCommon } from '../../models/api/gridApiCommon';
4
- import { OutputSelector } from '../../utils/createSelector';
4
+ import { OutputSelector, OutputSelectorV8 } from '../../utils/createSelector';
5
+ type Selector<Api extends GridApiCommon, Args, T> = ((state: Api['state']) => T) | OutputSelectorV8<Api['state'], Args, T>;
5
6
  export declare const objectShallowCompare: typeof fastObjectShallowCompare;
6
7
  export declare const useGridSelector: <Api extends GridApiCommon, T>(apiRef: React.MutableRefObject<Api>, selector: ((state: Api["state"]) => T) | OutputSelector<Api["state"], T>, equals?: (a: T, b: T) => boolean) => T;
8
+ export declare const useGridSelectorV8: <Api extends GridApiCommon, Args, T>(apiRef: React.MutableRefObject<Api>, selector: Selector<Api, Args, T>, args?: Args, equals?: (a: T, b: T) => boolean) => T;
9
+ export {};
@@ -6,12 +6,21 @@ import { warnOnce } from '../../internals/utils/warning';
6
6
  function isOutputSelector(selector) {
7
7
  return selector.acceptsApiRef;
8
8
  }
9
+ // TODO v8: Remove this function
9
10
  function applySelector(apiRef, selector) {
10
11
  if (isOutputSelector(selector)) {
11
12
  return selector(apiRef);
12
13
  }
13
14
  return selector(apiRef.current.state);
14
15
  }
16
+
17
+ // TODO v8: Rename this function to `applySelector`
18
+ function applySelectorV8(apiRef, selector, args, instanceId) {
19
+ if (isOutputSelector(selector)) {
20
+ return selector(apiRef, args);
21
+ }
22
+ return selector(apiRef.current.state, instanceId);
23
+ }
15
24
  const defaultCompare = Object.is;
16
25
  export const objectShallowCompare = fastObjectShallowCompare;
17
26
  const createRefs = () => ({
@@ -19,6 +28,8 @@ const createRefs = () => ({
19
28
  equals: null,
20
29
  selector: null
21
30
  });
31
+
32
+ // TODO v8: Remove this function
22
33
  export const useGridSelector = (apiRef, selector, equals = defaultCompare) => {
23
34
  if (process.env.NODE_ENV !== 'production') {
24
35
  if (!apiRef.current.state) {
@@ -43,4 +54,31 @@ export const useGridSelector = (apiRef, selector, equals = defaultCompare) => {
43
54
  });
44
55
  });
45
56
  return state;
57
+ };
58
+
59
+ // TODO v8: Rename this function to `useGridSelector`
60
+ export const useGridSelectorV8 = (apiRef, selector, args = undefined, equals = defaultCompare) => {
61
+ if (process.env.NODE_ENV !== 'production') {
62
+ if (!apiRef.current.state) {
63
+ warnOnce(['MUI X: `useGridSelector` has been called before the initialization of the state.', 'This hook can only be used inside the context of the grid.']);
64
+ }
65
+ }
66
+ const refs = useLazyRef(createRefs);
67
+ const didInit = refs.current.selector !== null;
68
+ const [state, setState] = React.useState(
69
+ // We don't use an initialization function to avoid allocations
70
+ didInit ? null : applySelectorV8(apiRef, selector, args, apiRef.current.instanceId));
71
+ refs.current.state = state;
72
+ refs.current.equals = equals;
73
+ refs.current.selector = selector;
74
+ useOnMount(() => {
75
+ return apiRef.current.store.subscribe(() => {
76
+ const newState = applySelectorV8(apiRef, refs.current.selector, args, apiRef.current.instanceId);
77
+ if (!refs.current.equals(refs.current.state, newState)) {
78
+ refs.current.state = newState;
79
+ setState(newState);
80
+ }
81
+ });
82
+ });
83
+ return state;
46
84
  };
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v7.13.0
2
+ * @mui/x-data-grid v7.15.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -72,7 +72,8 @@ export type * from '../models/props/DataGridProps';
72
72
  export type * from '../models/gridDataSource';
73
73
  export { getColumnsToExport, defaultGetRowsToExport } from '../hooks/features/export/utils';
74
74
  export * from '../utils/createControllablePromise';
75
- export { createSelector, createSelectorMemoized } from '../utils/createSelector';
75
+ export { createSelector, createSelectorV8, createSelectorMemoized, createSelectorMemoizedV8, } from '../utils/createSelector';
76
+ export { useGridSelectorV8 } from '../hooks/utils/useGridSelector';
76
77
  export { gridRowGroupsToFetchSelector } from '../hooks/features/rows/gridRowsSelector';
77
78
  export { findParentElementFromClassName, getActiveElement, isEventTargetInPortal, } from '../utils/domUtils';
78
79
  export { isNavigationKey, isPasteShortcut } from '../utils/keyboardUtils';
@@ -57,7 +57,8 @@ export { useGridVisibleRows, getVisibleRows } from '../hooks/utils/useGridVisibl
57
57
  export { useGridInitializeState } from '../hooks/utils/useGridInitializeState';
58
58
  export { getColumnsToExport, defaultGetRowsToExport } from '../hooks/features/export/utils';
59
59
  export * from '../utils/createControllablePromise';
60
- export { createSelector, createSelectorMemoized } from '../utils/createSelector';
60
+ export { createSelector, createSelectorV8, createSelectorMemoized, createSelectorMemoizedV8 } from '../utils/createSelector';
61
+ export { useGridSelectorV8 } from '../hooks/utils/useGridSelector';
61
62
  export { gridRowGroupsToFetchSelector } from '../hooks/features/rows/gridRowsSelector';
62
63
  export { findParentElementFromClassName, getActiveElement, isEventTargetInPortal } from '../utils/domUtils';
63
64
  export { isNavigationKey, isPasteShortcut } from '../utils/keyboardUtils';
package/locales/csCZ.js CHANGED
@@ -38,11 +38,10 @@ const csCZGrid = {
38
38
  toolbarExportPrint: 'Vytisknout',
39
39
  toolbarExportExcel: 'Stáhnout jako Excel',
40
40
  // Columns management text
41
- // columnsManagementSearchTitle: 'Search',
42
- // columnsManagementNoColumns: 'No columns',
43
- // columnsManagementShowHideAllText: 'Show/Hide All',
44
- // columnsManagementReset: 'Reset',
45
-
41
+ columnsManagementSearchTitle: 'Hledat sloupce',
42
+ columnsManagementNoColumns: 'Žádné sloupce',
43
+ columnsManagementShowHideAllText: 'Zobrazit/skrýt vše',
44
+ columnsManagementReset: 'Resetovat',
46
45
  // Filter panel text
47
46
  filterPanelAddFilter: 'Přidat filtr',
48
47
  filterPanelRemoveAll: 'Odstranit vše',
package/locales/heIL.js CHANGED
@@ -30,11 +30,10 @@ const heILGrid = {
30
30
  toolbarExportPrint: 'הדפסה',
31
31
  toolbarExportExcel: 'ייצוא ל- Excel',
32
32
  // Columns management text
33
- // columnsManagementSearchTitle: 'Search',
34
- // columnsManagementNoColumns: 'No columns',
35
- // columnsManagementShowHideAllText: 'Show/Hide All',
36
- // columnsManagementReset: 'Reset',
37
-
33
+ columnsManagementSearchTitle: 'חיפוש',
34
+ columnsManagementNoColumns: 'אין עמודות',
35
+ columnsManagementShowHideAllText: 'הצג/הסתר הכל',
36
+ columnsManagementReset: 'אתחול',
38
37
  // Filter panel text
39
38
  filterPanelAddFilter: 'הוסף מסנן',
40
39
  filterPanelRemoveAll: 'מחק הכל',
@@ -43,19 +43,19 @@ export interface GridGetRowsResponse {
43
43
  }
44
44
  export interface GridDataSource {
45
45
  /**
46
- * This method will be called when the grid needs to fetch some rows
46
+ * This method will be called when the grid needs to fetch some rows.
47
47
  * @param {GridGetRowsParams} params The parameters required to fetch the rows
48
48
  * @returns {Promise<GridGetRowsResponse>} A promise that resolves to the data of type [GridGetRowsResponse]
49
49
  */
50
50
  getRows(params: GridGetRowsParams): Promise<GridGetRowsResponse>;
51
51
  /**
52
- * This method will be called when the user updates a row [Not yet implemented]
52
+ * This method will be called when the user updates a row [Not yet implemented].
53
53
  * @param {GridRowModel} updatedRow The updated row
54
54
  * @returns {Promise<any>} If resolved (synced on the backend), the grid will update the row and mutate the cache
55
55
  */
56
56
  updateRow?(updatedRow: GridRowModel): Promise<any>;
57
57
  /**
58
- * Used to group rows by their parent group. Replaces `getTreeDataPath` used in client side tree-data .
58
+ * Used to group rows by their parent group. Replaces `getTreeDataPath` used in client side tree-data.
59
59
  * @param {GridRowModel} row The row to get the group key of
60
60
  * @returns {string} The group key for the row
61
61
  */
@@ -70,19 +70,19 @@ export interface GridDataSource {
70
70
  }
71
71
  export interface GridDataSourceCache {
72
72
  /**
73
- * Set the cache entry for the given key
73
+ * Set the cache entry for the given key.
74
74
  * @param {GridGetRowsParams} key The key of type `GridGetRowsParams`
75
75
  * @param {GridGetRowsResponse} value The value to be stored in the cache
76
76
  */
77
77
  set: (key: GridGetRowsParams, value: GridGetRowsResponse) => void;
78
78
  /**
79
- * Get the cache entry for the given key
79
+ * Get the cache entry for the given key.
80
80
  * @param {GridGetRowsParams} key The key of type `GridGetRowsParams`
81
81
  * @returns {GridGetRowsResponse} The value stored in the cache
82
82
  */
83
83
  get: (key: GridGetRowsParams) => GridGetRowsResponse | undefined;
84
84
  /**
85
- * Clear the cache
85
+ * Clear the cache.
86
86
  */
87
87
  clear: () => void;
88
88
  }
@@ -1,4 +1,3 @@
1
- import type { Theme } from '@mui/material/styles';
2
1
  import type { GridColumnMenuState, GridColumnsInitialState, GridColumnsState, GridColumnsGroupingState, GridColumnPinningState, GridDensityState, GridDimensionsState, GridFilterInitialState, GridFilterState, GridFocusState, GridPaginationInitialState, GridPaginationState, GridPreferencePanelInitialState, GridPreferencePanelState, GridRowsState, GridSortingInitialState, GridSortingState, GridTabIndexState, GridVirtualizationState } from '../hooks';
3
2
  import type { GridRowsMetaState } from '../hooks/features/rows/gridRowsMetaState';
4
3
  import type { GridEditingState } from './gridEditRowModel';
@@ -10,7 +9,7 @@ import type { GridColumnResizeState } from '../hooks/features/columnResize';
10
9
  * The state of `DataGrid`.
11
10
  */
12
11
  export interface GridStateCommunity {
13
- theme: Theme;
12
+ isRtl: boolean;
14
13
  dimensions: GridDimensionsState;
15
14
  rows: GridRowsState;
16
15
  visibleRowsLookup: GridVisibleRowsLookupState;
@@ -53,6 +53,10 @@ export interface GridCellParams<R extends GridValidRowModel = any, V = unknown,
53
53
  * the tabIndex value.
54
54
  */
55
55
  tabIndex: 0 | -1;
56
+ /**
57
+ * GridApi that let you manipulate the grid.
58
+ */
59
+ api: GridApiCommunity;
56
60
  }
57
61
  export interface FocusElement {
58
62
  focus(): void;
@@ -4,7 +4,7 @@ const _excluded = ["api", "colDef", "id", "hasFocus", "isEditable", "field", "va
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import MenuList from '@mui/material/MenuList';
7
- import { useTheme } from '@mui/material/styles';
7
+ import { useRtl } from '@mui/system/RtlProvider';
8
8
  import { unstable_useId as useId } from '@mui/utils';
9
9
  import { gridClasses } from '../../constants/gridClasses';
10
10
  import { GridMenu } from '../menu/GridMenu';
@@ -29,7 +29,7 @@ function GridActionsCell(props) {
29
29
  const buttonRef = React.useRef(null);
30
30
  const ignoreCallToFocus = React.useRef(false);
31
31
  const touchRippleRefs = React.useRef({});
32
- const theme = useTheme();
32
+ const isRtl = useRtl();
33
33
  const menuId = useId();
34
34
  const buttonId = useId();
35
35
  const rootProps = useGridRootProps();
@@ -110,7 +110,7 @@ function GridActionsCell(props) {
110
110
  }
111
111
 
112
112
  // for rtl mode we need to reverse the direction
113
- const rtlMod = theme.direction === 'rtl' ? -1 : 1;
113
+ const rtlMod = isRtl ? -1 : 1;
114
114
  const indexMod = (direction === 'left' ? -1 : 1) * rtlMod;
115
115
 
116
116
  // if the button that should receive focus is disabled go one more step
@@ -107,13 +107,12 @@ const GridCell = /*#__PURE__*/React.forwardRef(function GridCell(props, ref) {
107
107
  const apiRef = useGridApiContext();
108
108
  const rootProps = useGridRootProps();
109
109
  const field = column.field;
110
- const cellParamsWithAPI = useGridSelector(apiRef, () => {
110
+ const cellParams = useGridSelector(apiRef, () => {
111
111
  // This is required because `.getCellParams` tries to get the `state.rows.tree` entry
112
112
  // associated with `rowId`/`fieldId`, but this selector runs after the state has been
113
113
  // updated, while `rowId`/`fieldId` reference an entry in the old state.
114
114
  try {
115
- const cellParams = apiRef.current.getCellParams(rowId, field);
116
- const result = cellParams;
115
+ const result = apiRef.current.getCellParams(rowId, field);
117
116
  result.api = apiRef.current;
118
117
  return result;
119
118
  } catch (e) {
@@ -132,9 +131,9 @@ const GridCell = /*#__PURE__*/React.forwardRef(function GridCell(props, ref) {
132
131
  hasFocus,
133
132
  isEditable = false,
134
133
  value
135
- } = cellParamsWithAPI;
134
+ } = cellParams;
136
135
  const canManageOwnFocus = column.type === 'actions' && column.getActions?.(apiRef.current.getRowParams(rowId)).some(action => !action.props.disabled);
137
- const tabIndex = (cellMode === 'view' || !isEditable) && !canManageOwnFocus ? cellParamsWithAPI.tabIndex : -1;
136
+ const tabIndex = (cellMode === 'view' || !isEditable) && !canManageOwnFocus ? cellParams.tabIndex : -1;
138
137
  const {
139
138
  classes: rootClasses,
140
139
  getCellClassName
@@ -147,15 +146,15 @@ const GridCell = /*#__PURE__*/React.forwardRef(function GridCell(props, ref) {
147
146
  }).filter(Boolean).join(' '));
148
147
  const classNames = [pipesClassName];
149
148
  if (column.cellClassName) {
150
- classNames.push(typeof column.cellClassName === 'function' ? column.cellClassName(cellParamsWithAPI) : column.cellClassName);
149
+ classNames.push(typeof column.cellClassName === 'function' ? column.cellClassName(cellParams) : column.cellClassName);
151
150
  }
152
151
  if (column.display === 'flex') {
153
152
  classNames.push(gridClasses['cell--flex']);
154
153
  }
155
154
  if (getCellClassName) {
156
- classNames.push(getCellClassName(cellParamsWithAPI));
155
+ classNames.push(getCellClassName(cellParams));
157
156
  }
158
- const valueToRender = cellParamsWithAPI.formattedValue ?? value;
157
+ const valueToRender = cellParams.formattedValue ?? value;
159
158
  const cellRef = React.useRef(null);
160
159
  const handleRef = useForkRef(ref, cellRef);
161
160
  const focusElementRef = React.useRef(null);
@@ -238,7 +237,7 @@ const GridCell = /*#__PURE__*/React.forwardRef(function GridCell(props, ref) {
238
237
  }
239
238
  }
240
239
  }, [hasFocus, cellMode, apiRef]);
241
- if (cellParamsWithAPI === EMPTY_CELL_PARAMS) {
240
+ if (cellParams === EMPTY_CELL_PARAMS) {
242
241
  return null;
243
242
  }
244
243
  let handleFocus = other.onFocus;
@@ -260,15 +259,15 @@ const GridCell = /*#__PURE__*/React.forwardRef(function GridCell(props, ref) {
260
259
  let children;
261
260
  let title;
262
261
  if (editCellState === null && column.renderCell) {
263
- children = column.renderCell(cellParamsWithAPI);
262
+ children = column.renderCell(cellParams);
264
263
  }
265
264
  if (editCellState !== null && column.renderEditCell) {
266
265
  const updatedRow = apiRef.current.getRowWithUpdatedValues(rowId, column.field);
267
266
 
268
267
  // eslint-disable-next-line @typescript-eslint/naming-convention
269
268
  const editCellStateRest = _objectWithoutPropertiesLoose(editCellState, _excluded2);
270
- const formattedValue = column.valueFormatter ? column.valueFormatter(editCellState.value, updatedRow, column, apiRef) : cellParamsWithAPI.formattedValue;
271
- const params = _extends({}, cellParamsWithAPI, {
269
+ const formattedValue = column.valueFormatter ? column.valueFormatter(editCellState.value, updatedRow, column, apiRef) : cellParams.formattedValue;
270
+ const params = _extends({}, cellParams, {
272
271
  row: updatedRow,
273
272
  formattedValue
274
273
  }, editCellStateRest);
@@ -6,7 +6,6 @@ import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import { unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
8
8
  import { GridCellEditStopReasons } from '../../models/params/gridEditCellParams';
9
- import { isEscapeKey } from '../../utils/keyboardUtils';
10
9
  import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
11
10
  import { GridEditModes } from '../../models/gridEditRowModel';
12
11
  import { getValueFromValueOptions, getValueOptions, isSingleSelectColDef } from '../panel/filterPanel/filterPanelUtils';
@@ -80,10 +79,10 @@ function GridEditSingleSelectCell(props) {
80
79
  setOpen(false);
81
80
  return;
82
81
  }
83
- if (reason === 'backdropClick' || isEscapeKey(event.key)) {
82
+ if (reason === 'backdropClick' || event.key === 'Escape') {
84
83
  const params = apiRef.current.getCellParams(id, field);
85
84
  apiRef.current.publishEvent('cellEditStop', _extends({}, params, {
86
- reason: isEscapeKey(event.key) ? GridCellEditStopReasons.escapeKeyDown : GridCellEditStopReasons.cellFocusOut
85
+ reason: event.key === 'Escape' ? GridCellEditStopReasons.escapeKeyDown : GridCellEditStopReasons.cellFocusOut
87
86
  }));
88
87
  }
89
88
  };