@mui/x-data-grid 8.7.0 → 8.9.1

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 (112) hide show
  1. package/CHANGELOG.md +229 -24
  2. package/DataGrid/index.d.ts +0 -1
  3. package/DataGrid/useDataGridComponent.js +8 -0
  4. package/components/GridScrollArea.d.ts +1 -1
  5. package/components/GridScrollArea.js +134 -28
  6. package/components/containers/GridRootStyles.js +41 -0
  7. package/components/virtualization/GridVirtualScroller.js +4 -0
  8. package/constants/gridClasses.d.ts +20 -0
  9. package/constants/gridClasses.js +3 -1
  10. package/esm/DataGrid/index.d.ts +0 -1
  11. package/esm/DataGrid/useDataGridComponent.js +8 -0
  12. package/esm/components/GridScrollArea.d.ts +1 -1
  13. package/esm/components/GridScrollArea.js +134 -28
  14. package/esm/components/containers/GridRootStyles.js +41 -0
  15. package/esm/components/virtualization/GridVirtualScroller.js +4 -0
  16. package/esm/constants/gridClasses.d.ts +20 -0
  17. package/esm/constants/gridClasses.js +3 -1
  18. package/esm/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +5 -0
  19. package/esm/hooks/core/pipeProcessing/useGridPipeProcessing.js +20 -5
  20. package/esm/hooks/core/useGridProps.d.ts +2 -2
  21. package/esm/hooks/core/useGridProps.js +3 -1
  22. package/esm/hooks/features/columnGrouping/gridColumnGroupsInterfaces.d.ts +4 -1
  23. package/esm/hooks/features/columnGrouping/gridColumnGroupsUtils.js +35 -32
  24. package/esm/hooks/features/columnGrouping/useGridColumnGrouping.js +18 -13
  25. package/esm/hooks/features/columns/gridColumnsInterfaces.d.ts +3 -3
  26. package/esm/hooks/features/columns/gridColumnsSelector.js +6 -2
  27. package/esm/hooks/features/columns/gridColumnsUtils.js +6 -4
  28. package/esm/hooks/features/columns/useGridColumns.js +8 -10
  29. package/esm/hooks/features/dataSource/useGridDataSourceBase.d.ts +1 -1
  30. package/esm/hooks/features/dataSource/useGridDataSourceBase.js +3 -0
  31. package/esm/hooks/features/dataSource/utils.js +3 -0
  32. package/esm/hooks/features/export/utils.js +1 -1
  33. package/esm/hooks/features/filter/useGridFilter.js +3 -3
  34. package/esm/hooks/features/keyboardNavigation/useGridKeyboardNavigation.d.ts +1 -1
  35. package/esm/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +5 -9
  36. package/esm/hooks/features/listView/gridListViewSelectors.d.ts +8 -1
  37. package/esm/hooks/features/listView/gridListViewSelectors.js +7 -0
  38. package/esm/hooks/features/rowSelection/useGridRowSelection.js +5 -4
  39. package/esm/hooks/features/rows/gridRowsUtils.d.ts +1 -1
  40. package/esm/hooks/features/rows/gridRowsUtils.js +5 -2
  41. package/esm/hooks/features/rows/useGridRows.js +4 -3
  42. package/esm/hooks/features/scroll/useGridScroll.d.ts +1 -1
  43. package/esm/hooks/features/scroll/useGridScroll.js +2 -3
  44. package/esm/hooks/features/virtualization/useGridVirtualScroller.js +3 -6
  45. package/esm/hooks/utils/index.d.ts +1 -0
  46. package/esm/hooks/utils/index.js +2 -1
  47. package/esm/hooks/utils/useGridInitializeState.d.ts +1 -1
  48. package/esm/hooks/utils/useGridInitializeState.js +6 -1
  49. package/esm/hooks/utils/useGridSelector.js +4 -0
  50. package/esm/hooks/utils/useRunOncePerLoop.d.ts +1 -0
  51. package/esm/hooks/utils/useRunOncePerLoop.js +26 -0
  52. package/esm/index.js +1 -1
  53. package/esm/internals/utils/cache.d.ts +9 -0
  54. package/esm/internals/utils/cache.js +19 -0
  55. package/esm/internals/utils/index.d.ts +2 -1
  56. package/esm/internals/utils/index.js +2 -1
  57. package/esm/locales/idID.d.ts +4 -0
  58. package/esm/locales/idID.js +261 -0
  59. package/esm/locales/index.d.ts +2 -1
  60. package/esm/locales/index.js +2 -1
  61. package/esm/models/api/gridRowApi.d.ts +5 -0
  62. package/esm/models/events/gridEventLookup.d.ts +2 -1
  63. package/esm/models/gridApiCaches.d.ts +8 -2
  64. package/esm/models/gridStateCommunity.d.ts +2 -2
  65. package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +5 -0
  66. package/hooks/core/pipeProcessing/useGridPipeProcessing.js +20 -5
  67. package/hooks/core/useGridProps.d.ts +2 -2
  68. package/hooks/core/useGridProps.js +3 -1
  69. package/hooks/features/columnGrouping/gridColumnGroupsInterfaces.d.ts +4 -1
  70. package/hooks/features/columnGrouping/gridColumnGroupsUtils.js +35 -32
  71. package/hooks/features/columnGrouping/useGridColumnGrouping.js +18 -13
  72. package/hooks/features/columns/gridColumnsInterfaces.d.ts +3 -3
  73. package/hooks/features/columns/gridColumnsSelector.js +6 -2
  74. package/hooks/features/columns/gridColumnsUtils.js +6 -4
  75. package/hooks/features/columns/useGridColumns.js +8 -10
  76. package/hooks/features/dataSource/useGridDataSourceBase.d.ts +1 -1
  77. package/hooks/features/dataSource/useGridDataSourceBase.js +3 -0
  78. package/hooks/features/dataSource/utils.js +3 -0
  79. package/hooks/features/export/utils.js +1 -1
  80. package/hooks/features/filter/useGridFilter.js +3 -3
  81. package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.d.ts +1 -1
  82. package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +5 -9
  83. package/hooks/features/listView/gridListViewSelectors.d.ts +8 -1
  84. package/hooks/features/listView/gridListViewSelectors.js +8 -1
  85. package/hooks/features/rowSelection/useGridRowSelection.js +5 -4
  86. package/hooks/features/rows/gridRowsUtils.d.ts +1 -1
  87. package/hooks/features/rows/gridRowsUtils.js +5 -2
  88. package/hooks/features/rows/useGridRows.js +4 -3
  89. package/hooks/features/scroll/useGridScroll.d.ts +1 -1
  90. package/hooks/features/scroll/useGridScroll.js +2 -3
  91. package/hooks/features/virtualization/useGridVirtualScroller.js +3 -6
  92. package/hooks/utils/index.d.ts +1 -0
  93. package/hooks/utils/index.js +12 -0
  94. package/hooks/utils/useGridInitializeState.d.ts +1 -1
  95. package/hooks/utils/useGridInitializeState.js +6 -1
  96. package/hooks/utils/useGridSelector.js +4 -0
  97. package/hooks/utils/useRunOncePerLoop.d.ts +1 -0
  98. package/hooks/utils/useRunOncePerLoop.js +33 -0
  99. package/index.js +1 -1
  100. package/internals/utils/cache.d.ts +9 -0
  101. package/internals/utils/cache.js +26 -0
  102. package/internals/utils/index.d.ts +2 -1
  103. package/internals/utils/index.js +11 -0
  104. package/locales/idID.d.ts +4 -0
  105. package/locales/idID.js +267 -0
  106. package/locales/index.d.ts +2 -1
  107. package/locales/index.js +11 -0
  108. package/models/api/gridRowApi.d.ts +5 -0
  109. package/models/events/gridEventLookup.d.ts +2 -1
  110. package/models/gridApiCaches.d.ts +8 -2
  111. package/models/gridStateCommunity.d.ts +2 -2
  112. package/package.json +3 -3
@@ -16,7 +16,6 @@ import { gridHeaderFilteringEditFieldSelector, gridHeaderFilteringMenuSelector }
16
16
  import { useGridRegisterPipeProcessor } from "../../core/pipeProcessing/index.js";
17
17
  import { isEventTargetInPortal } from "../../../utils/domUtils.js";
18
18
  import { getLeftColumnIndex, getRightColumnIndex, findNonRowSpannedCell } from "./utils.js";
19
- import { gridListColumnSelector } from "../listView/gridListViewSelectors.js";
20
19
  import { createSelectorMemoized } from "../../../utils/createSelector.js";
21
20
  import { gridVisibleRowsSelector } from "../pagination/index.js";
22
21
  import { gridPinnedRowsSelector } from "../rows/gridRowsSelector.js";
@@ -36,7 +35,6 @@ const gridVisibleRowsWithPinnedRowsSelector = createSelectorMemoized(gridVisible
36
35
  export const useGridKeyboardNavigation = (apiRef, props) => {
37
36
  const logger = useGridLogger(apiRef, 'useGridKeyboardNavigation');
38
37
  const isRtl = useRtl();
39
- const listView = props.listView;
40
38
  const getCurrentPageRows = React.useCallback(() => {
41
39
  return gridVisibleRowsWithPinnedRowsSelector(apiRef);
42
40
  }, [apiRef]);
@@ -59,7 +57,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
59
57
  colIndex = nextCellColSpanInfo.rightVisibleCellIndex;
60
58
  }
61
59
  }
62
- const field = listView ? gridListColumnSelector(apiRef).field : gridVisibleColumnFieldsSelector(apiRef)[colIndex];
60
+ const field = gridVisibleColumnFieldsSelector(apiRef)[colIndex];
63
61
  const nonRowSpannedRowId = findNonRowSpannedCell(apiRef, rowId, field, rowSpanScanDirection);
64
62
  // `scrollToIndexes` requires a rowIndex relative to all visible rows.
65
63
  // Those rows do not include pinned rows, but pinned rows do not need scroll anyway.
@@ -70,7 +68,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
70
68
  rowIndex: rowIndexRelativeToAllRows
71
69
  });
72
70
  apiRef.current.setCellFocus(nonRowSpannedRowId, field);
73
- }, [apiRef, logger, listView]);
71
+ }, [apiRef, logger]);
74
72
  const goToHeader = React.useCallback((colIndex, event) => {
75
73
  logger.debug(`Navigating to header col ${colIndex}`);
76
74
  apiRef.current.scrollToIndexes({
@@ -395,14 +393,12 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
395
393
  return;
396
394
  }
397
395
  const viewportPageSize = apiRef.current.getViewportPageSize();
398
- const getColumnIndexFn = listView ? () => 0 : apiRef.current.getColumnIndex;
399
- const colIndexBefore = params.field ? getColumnIndexFn(params.field) : 0;
396
+ const colIndexBefore = params.field ? apiRef.current.getColumnIndex(params.field) : 0;
400
397
  const rowIndexBefore = currentPageRows.findIndex(row => row.id === params.id);
401
398
  const firstRowIndexInPage = 0;
402
399
  const lastRowIndexInPage = currentPageRows.length - 1;
403
400
  const firstColIndex = 0;
404
- const visibleColumns = listView ? [gridListColumnSelector(apiRef)] : gridVisibleColumnDefinitionsSelector(apiRef);
405
- const lastColIndex = visibleColumns.length - 1;
401
+ const lastColIndex = gridVisibleColumnDefinitionsSelector(apiRef).length - 1;
406
402
  let shouldPreventDefault = true;
407
403
  switch (event.key) {
408
404
  case 'ArrowDown':
@@ -519,7 +515,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
519
515
  if (shouldPreventDefault) {
520
516
  event.preventDefault();
521
517
  }
522
- }, [apiRef, getCurrentPageRows, isRtl, goToCell, getRowIdFromIndex, headerFilteringEnabled, goToHeaderFilter, goToHeader, listView]);
518
+ }, [apiRef, getCurrentPageRows, isRtl, goToCell, getRowIdFromIndex, headerFilteringEnabled, goToHeaderFilter, goToHeader]);
523
519
  const checkIfCanStartEditing = React.useCallback((initialValue, {
524
520
  event
525
521
  }) => {
@@ -1,7 +1,14 @@
1
1
  import { GridStateCommunity } from "../../../models/gridStateCommunity.js";
2
+ import type { GridStateColDef } from "../../../models/colDef/gridColDef.js";
3
+ /**
4
+ * Get the list view state
5
+ * @category List View
6
+ * @ignore - Do not document
7
+ */
8
+ export declare const gridListViewSelector: import("@mui/x-data-grid").OutputSelector<GridStateCommunity, unknown, boolean>;
2
9
  /**
3
10
  * Get the list column definition
4
11
  * @category List View
5
12
  * @ignore - Do not document
6
13
  */
7
- export declare const gridListColumnSelector: import("@mui/x-data-grid").OutputSelector<GridStateCommunity, unknown, import("./useGridListView.js").GridListViewState>;
14
+ export declare const gridListColumnSelector: import("@mui/x-data-grid").OutputSelector<GridStateCommunity, unknown, GridStateColDef>;
@@ -1,4 +1,11 @@
1
1
  import { createRootSelector } from "../../../utils/createSelector.js";
2
+ /**
3
+ * Get the list view state
4
+ * @category List View
5
+ * @ignore - Do not document
6
+ */
7
+ export const gridListViewSelector = createRootSelector(state => state.props.listView ?? false);
8
+
2
9
  /**
3
10
  * Get the list column definition
4
11
  * @category List View
@@ -299,12 +299,13 @@ export const useGridRowSelection = (apiRef, props) => {
299
299
  }
300
300
  const currentSelection = gridRowSelectionStateSelector(apiRef);
301
301
  const rowsLookup = gridRowsLookupSelector(apiRef);
302
+ const rowTree = gridRowTreeSelector(apiRef);
302
303
  const filteredRowsLookup = gridFilteredRowsLookupSelector(apiRef);
303
304
  const isNonExistent = id => {
304
305
  if (props.filterMode === 'server') {
305
306
  return !rowsLookup[id];
306
307
  }
307
- return !rowsLookup[id] || filteredRowsLookup[id] === false;
308
+ return !rowTree[id] || filteredRowsLookup[id] === false;
308
309
  };
309
310
  const newSelectionModel = {
310
311
  type: currentSelection.type,
@@ -430,15 +431,15 @@ export const useGridRowSelection = (apiRef, props) => {
430
431
  const filterModel = gridFilterModelSelector(apiRef);
431
432
  const quickFilterModel = gridQuickFilterValuesSelector(apiRef);
432
433
  const hasFilters = filterModel.items.length > 0 || quickFilterModel?.some(val => val.length);
433
- if (!props.isRowSelectable && !props.checkboxSelectionVisibleOnly && applyAutoSelection && !hasFilters) {
434
+ if (!props.isRowSelectable && !props.checkboxSelectionVisibleOnly && (!isNestedData || props.rowSelectionPropagation?.descendants) && !hasFilters) {
434
435
  apiRef.current.setRowSelectionModel({
435
436
  type: value ? 'exclude' : 'include',
436
437
  ids: new Set()
437
- });
438
+ }, 'multipleRowsSelection');
438
439
  } else {
439
440
  apiRef.current.selectRows(getRowsToBeSelected(), value);
440
441
  }
441
- }, [apiRef, applyAutoSelection, getRowsToBeSelected, props.checkboxSelectionVisibleOnly, props.isRowSelectable]);
442
+ }, [apiRef, getRowsToBeSelected, props.checkboxSelectionVisibleOnly, props.isRowSelectable, props.rowSelectionPropagation?.descendants, isNestedData]);
442
443
  const handleHeaderSelectionCheckboxChange = React.useCallback(params => {
443
444
  toggleAllRows(params.value);
444
445
  }, [toggleAllRows]);
@@ -42,7 +42,7 @@ export declare const getRowsStateFromCache: ({
42
42
  }) => GridRowsState;
43
43
  export declare const isAutogeneratedRow: (row: GridRowModel) => boolean;
44
44
  export declare const isAutogeneratedRowNode: (rowNode: GridTreeNode) => rowNode is GridFooterNode | GridSkeletonRowNode | GridAutoGeneratedGroupNode | GridAutoGeneratedPinnedRowNode;
45
- export declare const getTreeNodeDescendants: (tree: GridRowTreeConfig, parentId: GridRowId, skipAutoGeneratedRows: boolean) => GridRowId[];
45
+ export declare const getTreeNodeDescendants: (tree: GridRowTreeConfig, parentId: GridRowId, skipAutoGeneratedRows: boolean, directChildrenOnly?: boolean) => GridRowId[];
46
46
  export declare const updateCacheWithNewRows: ({
47
47
  previousCache,
48
48
  getRowId,
@@ -127,7 +127,7 @@ export const getRowsStateFromCache = ({
127
127
  };
128
128
  export const isAutogeneratedRow = row => GRID_ID_AUTOGENERATED in row;
129
129
  export const isAutogeneratedRowNode = rowNode => rowNode.type === 'skeletonRow' || rowNode.type === 'footer' || rowNode.type === 'group' && rowNode.isAutoGenerated || rowNode.type === 'pinnedRow' && rowNode.isAutoGenerated;
130
- export const getTreeNodeDescendants = (tree, parentId, skipAutoGeneratedRows) => {
130
+ export const getTreeNodeDescendants = (tree, parentId, skipAutoGeneratedRows, directChildrenOnly) => {
131
131
  const node = tree[parentId];
132
132
  if (node.type !== 'group') {
133
133
  return [];
@@ -138,7 +138,10 @@ export const getTreeNodeDescendants = (tree, parentId, skipAutoGeneratedRows) =>
138
138
  if (!skipAutoGeneratedRows || !isAutogeneratedRowNode(tree[child])) {
139
139
  validDescendants.push(child);
140
140
  }
141
- const childDescendants = getTreeNodeDescendants(tree, child, skipAutoGeneratedRows);
141
+ if (directChildrenOnly) {
142
+ continue;
143
+ }
144
+ const childDescendants = getTreeNodeDescendants(tree, child, skipAutoGeneratedRows, directChildrenOnly);
142
145
  for (let j = 0; j < childDescendants.length; j += 1) {
143
146
  validDescendants.push(childDescendants[j]);
144
147
  }
@@ -198,7 +198,8 @@ export const useGridRows = (apiRef, props) => {
198
198
  skipAutoGeneratedRows = true,
199
199
  groupId,
200
200
  applySorting,
201
- applyFiltering
201
+ applyFiltering,
202
+ directChildrenOnly = false
202
203
  }) => {
203
204
  const tree = gridRowTreeSelector(apiRef);
204
205
  let children;
@@ -210,14 +211,14 @@ export const useGridRows = (apiRef, props) => {
210
211
  const sortedRowIds = gridSortedRowIdsSelector(apiRef);
211
212
  children = [];
212
213
  const startIndex = sortedRowIds.findIndex(id => id === groupId) + 1;
213
- for (let index = startIndex; index < sortedRowIds.length && tree[sortedRowIds[index]].depth > groupNode.depth; index += 1) {
214
+ for (let index = startIndex; index < sortedRowIds.length && (directChildrenOnly ? tree[sortedRowIds[index]].depth === groupNode.depth + 1 : tree[sortedRowIds[index]].depth > groupNode.depth); index += 1) {
214
215
  const id = sortedRowIds[index];
215
216
  if (!skipAutoGeneratedRows || !isAutogeneratedRowNode(tree[id])) {
216
217
  children.push(id);
217
218
  }
218
219
  }
219
220
  } else {
220
- children = getTreeNodeDescendants(tree, groupId, skipAutoGeneratedRows);
221
+ children = getTreeNodeDescendants(tree, groupId, skipAutoGeneratedRows, directChildrenOnly);
221
222
  }
222
223
  if (applyFiltering) {
223
224
  const filteredRowsLookup = gridFilteredRowsLookupSelector(apiRef);
@@ -9,4 +9,4 @@ import { DataGridProcessedProps } from "../../../models/props/DataGridProps.js";
9
9
  * @requires useGridFilter (state)
10
10
  * @requires useGridColumnSpanning (method)
11
11
  */
12
- export declare const useGridScroll: (apiRef: RefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, "pagination" | "listView">) => void;
12
+ export declare const useGridScroll: (apiRef: RefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, "pagination">) => void;
@@ -9,7 +9,6 @@ import { gridRowsMetaSelector } from "../rows/gridRowsMetaSelector.js";
9
9
  import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
10
10
  import { gridExpandedSortedRowEntriesSelector } from "../filter/gridFilterSelector.js";
11
11
  import { gridDimensionsSelector } from "../dimensions/index.js";
12
- import { gridListColumnSelector } from "../listView/gridListViewSelectors.js";
13
12
 
14
13
  // Logic copied from https://www.w3.org/TR/wai-aria-practices/examples/listbox/js/listbox.js
15
14
  // Similar to https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
@@ -52,7 +51,7 @@ export const useGridScroll = (apiRef, props) => {
52
51
  const scrollToIndexes = React.useCallback(params => {
53
52
  const dimensions = gridDimensionsSelector(apiRef);
54
53
  const totalRowCount = gridRowCountSelector(apiRef);
55
- const visibleColumns = props.listView ? [gridListColumnSelector(apiRef)] : gridVisibleColumnDefinitionsSelector(apiRef);
54
+ const visibleColumns = gridVisibleColumnDefinitionsSelector(apiRef);
56
55
  const scrollToHeader = params.rowIndex == null;
57
56
  if (!scrollToHeader && totalRowCount === 0 || visibleColumns.length === 0) {
58
57
  return false;
@@ -99,7 +98,7 @@ export const useGridScroll = (apiRef, props) => {
99
98
  return true;
100
99
  }
101
100
  return false;
102
- }, [logger, apiRef, virtualScrollerRef, props.pagination, visibleSortedRows, props.listView]);
101
+ }, [logger, apiRef, virtualScrollerRef, props.pagination, visibleSortedRows]);
103
102
  const scroll = React.useCallback(params => {
104
103
  if (virtualScrollerRef.current && params.left !== undefined && colRef.current) {
105
104
  const direction = isRtl ? -1 : 1;
@@ -25,9 +25,7 @@ import { getFirstNonSpannedColumnToRender } from "../columns/gridColumnsUtils.js
25
25
  import { gridRenderContextSelector, gridVirtualizationRowEnabledSelector, gridVirtualizationColumnEnabledSelector } from "./gridVirtualizationSelectors.js";
26
26
  import { EMPTY_RENDER_CONTEXT } from "./useGridVirtualization.js";
27
27
  import { gridRowSpanningHiddenCellsOriginMapSelector } from "../rows/gridRowSpanningSelectors.js";
28
- import { gridListColumnSelector } from "../listView/gridListViewSelectors.js";
29
28
  import { minimalContentHeight } from "../rows/gridRowsUtils.js";
30
- import { EMPTY_PINNED_COLUMN_FIELDS } from "../columns/index.js";
31
29
  import { gridFocusedVirtualCellSelector } from "./gridFocusedVirtualCellSelector.js";
32
30
  import { roundToDecimalPlaces } from "../../../utils/roundToDecimalPlaces.js";
33
31
  import { isJSDOM } from "../../../utils/isJSDOM.js";
@@ -57,12 +55,11 @@ export const useGridVirtualScroller = () => {
57
55
  const {
58
56
  listView
59
57
  } = rootProps;
60
- const visibleColumns = useGridSelector(apiRef, () => listView ? [gridListColumnSelector(apiRef)] : gridVisibleColumnDefinitionsSelector(apiRef));
58
+ const visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
61
59
  const enabledForRows = useGridSelector(apiRef, gridVirtualizationRowEnabledSelector) && !isJSDOM;
62
60
  const enabledForColumns = useGridSelector(apiRef, gridVirtualizationColumnEnabledSelector) && !isJSDOM;
63
61
  const pinnedRows = useGridSelector(apiRef, gridPinnedRowsSelector);
64
- const pinnedColumnDefinitions = gridVisiblePinnedColumnDefinitionsSelector(apiRef);
65
- const pinnedColumns = listView ? EMPTY_PINNED_COLUMN_FIELDS : pinnedColumnDefinitions;
62
+ const pinnedColumns = gridVisiblePinnedColumnDefinitionsSelector(apiRef);
66
63
  const hasBottomPinnedRows = pinnedRows.bottom.length > 0;
67
64
  const [panels, setPanels] = React.useState(EMPTY_DETAIL_PANELS);
68
65
  const isRtl = useRtl();
@@ -552,7 +549,7 @@ function needsHorizontalScrollbarSelector(apiRef) {
552
549
  function inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns) {
553
550
  const dimensions = gridDimensionsSelector(apiRef);
554
551
  const currentPage = getVisibleRows(apiRef, rootProps);
555
- const visibleColumns = rootProps.listView ? [gridListColumnSelector(apiRef)] : gridVisibleColumnDefinitionsSelector(apiRef);
552
+ const visibleColumns = gridVisibleColumnDefinitionsSelector(apiRef);
556
553
  const hiddenCellsOriginMap = gridRowSpanningHiddenCellsOriginMapSelector(apiRef);
557
554
  const lastRowId = apiRef.current.state.rows.dataRowIds.at(-1);
558
555
  const lastColumn = visibleColumns.at(-1);
@@ -6,4 +6,5 @@ export * from "./useGridNativeEventListener.js";
6
6
  export * from "./useFirstRender.js";
7
7
  export * from "./useOnMount.js";
8
8
  export * from "./useRunOnce.js";
9
+ export * from "./useRunOncePerLoop.js";
9
10
  export type { RenderProp } from '@mui/x-internals/useComponentRenderer';
@@ -5,4 +5,5 @@ export { useGridSelector } from "./useGridSelector.js";
5
5
  export * from "./useGridNativeEventListener.js";
6
6
  export * from "./useFirstRender.js";
7
7
  export * from "./useOnMount.js";
8
- export * from "./useRunOnce.js";
8
+ export * from "./useRunOnce.js";
9
+ export * from "./useRunOncePerLoop.js";
@@ -4,5 +4,5 @@ import { GridPrivateApiCommunity } from "../../models/api/gridApiCommunity.js";
4
4
  import { DataGridProcessedProps } from "../../models/props/DataGridProps.js";
5
5
  type DeepPartial<T> = { [P in keyof T]?: DeepPartial<T[P]> };
6
6
  export type GridStateInitializer<P extends Partial<DataGridProcessedProps> = DataGridProcessedProps, PrivateApi extends GridPrivateApiCommon = GridPrivateApiCommunity> = (state: DeepPartial<PrivateApi['state']>, props: P, privateApiRef: RefObject<PrivateApi>) => DeepPartial<PrivateApi['state']>;
7
- export declare const useGridInitializeState: <P extends Partial<DataGridProcessedProps>, PrivateApi extends GridPrivateApiCommon = GridPrivateApiCommunity>(initializer: GridStateInitializer<P, PrivateApi>, privateApiRef: RefObject<PrivateApi>, props: P) => void;
7
+ export declare const useGridInitializeState: <P extends Partial<DataGridProcessedProps>, PrivateApi extends GridPrivateApiCommon = GridPrivateApiCommunity>(initializer: GridStateInitializer<P, PrivateApi>, privateApiRef: RefObject<PrivateApi>, props: P, key?: string) => void;
8
8
  export {};
@@ -1,6 +1,11 @@
1
1
  import * as React from 'react';
2
- export const useGridInitializeState = (initializer, privateApiRef, props) => {
2
+ export const useGridInitializeState = (initializer, privateApiRef, props, key) => {
3
+ const previousKey = React.useRef(key);
3
4
  const isInitialized = React.useRef(false);
5
+ if (key !== previousKey.current) {
6
+ isInitialized.current = false;
7
+ previousKey.current = key;
8
+ }
4
9
  if (!isInitialized.current) {
5
10
  privateApiRef.current.state = initializer(privateApiRef.current.state, props, privateApiRef);
6
11
  isInitialized.current = true;
@@ -69,6 +69,10 @@ export function useGridSelector(apiRef, selector, args = undefined, equals = def
69
69
  // eslint-disable-next-line react-hooks/exhaustive-deps
70
70
  EMPTY);
71
71
  const unsubscribe = React.useCallback(() => {
72
+ // Fixes issue in React Strict Mode, where getSnapshot is not called
73
+ if (!refs.current.subscription) {
74
+ subscribe();
75
+ }
72
76
  return () => {
73
77
  if (refs.current.subscription) {
74
78
  refs.current.subscription();
@@ -0,0 +1 @@
1
+ export declare function useRunOncePerLoop<T extends (...args: any[]) => void>(callback: T, nextFrame?: boolean): (...args: Parameters<T>) => void;
@@ -0,0 +1,26 @@
1
+ import * as React from 'react';
2
+ export function useRunOncePerLoop(callback, nextFrame = false) {
3
+ const scheduledRef = React.useRef(false);
4
+ const schedule = React.useCallback((...args) => {
5
+ if (scheduledRef.current) {
6
+ return;
7
+ }
8
+ scheduledRef.current = true;
9
+ const runner = () => {
10
+ scheduledRef.current = false;
11
+ callback(...args);
12
+ };
13
+ if (nextFrame) {
14
+ if (typeof requestAnimationFrame === 'function') {
15
+ requestAnimationFrame(runner);
16
+ }
17
+ return;
18
+ }
19
+ if (typeof queueMicrotask === 'function') {
20
+ queueMicrotask(runner);
21
+ } else {
22
+ Promise.resolve().then(runner);
23
+ }
24
+ }, [callback, nextFrame]);
25
+ return schedule;
26
+ }
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v8.7.0
2
+ * @mui/x-data-grid v8.9.1
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -0,0 +1,9 @@
1
+ import { GridGetRowsParams, GridGetRowsResponse } from "../../models/gridDataSource.js";
2
+ export declare class TestCache {
3
+ private cache;
4
+ constructor();
5
+ set(key: GridGetRowsParams, value: GridGetRowsResponse): void;
6
+ get(key: GridGetRowsParams): GridGetRowsResponse | undefined;
7
+ size(): number;
8
+ clear(): void;
9
+ }
@@ -0,0 +1,19 @@
1
+ import { getKeyDefault } from "../../hooks/features/dataSource/cache.js";
2
+ export class TestCache {
3
+ constructor() {
4
+ this.cache = void 0;
5
+ this.cache = new Map();
6
+ }
7
+ set(key, value) {
8
+ this.cache.set(getKeyDefault(key), value);
9
+ }
10
+ get(key) {
11
+ return this.cache.get(getKeyDefault(key));
12
+ }
13
+ size() {
14
+ return this.cache.size;
15
+ }
16
+ clear() {
17
+ this.cache.clear();
18
+ }
19
+ }
@@ -1,4 +1,5 @@
1
1
  export * from "./computeSlots.js";
2
2
  export * from "./propValidation.js";
3
3
  export * from "./gridRowGroupingUtils.js";
4
- export * from "./attachPinnedStyle.js";
4
+ export * from "./attachPinnedStyle.js";
5
+ export * from "./cache.js";
@@ -1,4 +1,5 @@
1
1
  export * from "./computeSlots.js";
2
2
  export * from "./propValidation.js";
3
3
  export * from "./gridRowGroupingUtils.js";
4
- export * from "./attachPinnedStyle.js";
4
+ export * from "./attachPinnedStyle.js";
5
+ export * from "./cache.js";
@@ -0,0 +1,4 @@
1
+ import { GridLocaleText } from "../models/api/gridLocaleTextApi.js";
2
+ import { Localization } from "../utils/getGridLocalization.js";
3
+ export declare const idIDGrid: GridLocaleText;
4
+ export declare const idID: Localization;