@mui/x-data-grid 8.8.0 → 8.9.2
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.
- package/CHANGELOG.md +225 -24
- package/DataGrid/DataGrid.js +5 -0
- package/DataGrid/index.d.ts +0 -1
- package/DataGrid/useDataGridComponent.js +10 -0
- package/colDef/gridCheckboxSelectionColDef.js +1 -0
- package/components/GridDetailPanels.d.ts +2 -2
- package/components/GridPinnedRows.d.ts +2 -2
- package/components/GridRow.js +5 -0
- package/components/GridScrollArea.js +1 -1
- package/components/cell/GridCell.js +7 -5
- package/components/cell/GridEditSingleSelectCell.js +1 -1
- package/components/columnsManagement/GridColumnsManagement.d.ts +6 -0
- package/components/columnsManagement/GridColumnsManagement.js +17 -5
- package/components/containers/GridRootStyles.d.ts +1 -1
- package/components/containers/GridRootStyles.js +39 -0
- package/components/toolbarV8/Toolbar.d.ts +1 -1
- package/components/virtualization/GridVirtualScroller.js +5 -5
- package/constants/dataGridPropsDefaultValues.js +1 -0
- package/constants/gridClasses.d.ts +12 -0
- package/constants/gridClasses.js +3 -1
- package/esm/DataGrid/DataGrid.js +5 -0
- package/esm/DataGrid/index.d.ts +0 -1
- package/esm/DataGrid/useDataGridComponent.js +10 -0
- package/esm/colDef/gridCheckboxSelectionColDef.js +1 -0
- package/esm/components/GridDetailPanels.d.ts +2 -2
- package/esm/components/GridPinnedRows.d.ts +2 -2
- package/esm/components/GridRow.js +5 -0
- package/esm/components/GridScrollArea.js +1 -1
- package/esm/components/cell/GridCell.js +7 -5
- package/esm/components/cell/GridEditSingleSelectCell.js +1 -1
- package/esm/components/columnsManagement/GridColumnsManagement.d.ts +6 -0
- package/esm/components/columnsManagement/GridColumnsManagement.js +17 -5
- package/esm/components/containers/GridRootStyles.d.ts +1 -1
- package/esm/components/containers/GridRootStyles.js +39 -0
- package/esm/components/toolbarV8/Toolbar.d.ts +1 -1
- package/esm/components/virtualization/GridVirtualScroller.js +5 -5
- package/esm/constants/dataGridPropsDefaultValues.js +1 -0
- package/esm/constants/gridClasses.d.ts +12 -0
- package/esm/constants/gridClasses.js +3 -1
- package/esm/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +5 -0
- package/esm/hooks/core/pipeProcessing/useGridPipeProcessing.js +20 -5
- package/esm/hooks/core/useGridProps.d.ts +2 -2
- package/esm/hooks/core/useGridProps.js +3 -1
- package/esm/hooks/core/useGridVirtualizer.d.ts +9 -0
- package/esm/hooks/core/useGridVirtualizer.js +223 -0
- package/esm/hooks/features/columnGrouping/gridColumnGroupsInterfaces.d.ts +4 -1
- package/esm/hooks/features/columnGrouping/gridColumnGroupsUtils.js +35 -32
- package/esm/hooks/features/columnGrouping/useGridColumnGrouping.js +18 -13
- package/esm/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +1 -1
- package/esm/hooks/features/columnHeaders/useGridColumnHeaders.js +3 -2
- package/esm/hooks/features/columns/gridColumnsInterfaces.d.ts +3 -3
- package/esm/hooks/features/columns/gridColumnsSelector.js +6 -2
- package/esm/hooks/features/columns/gridColumnsUtils.js +6 -4
- package/esm/hooks/features/columns/useGridColumnSpanning.js +5 -90
- package/esm/hooks/features/columns/useGridColumns.js +8 -10
- package/esm/hooks/features/dimensions/useGridDimensions.js +18 -188
- package/esm/hooks/features/export/utils.js +1 -1
- package/esm/hooks/features/filter/useGridFilter.js +3 -3
- package/esm/hooks/features/keyboardNavigation/useGridKeyboardNavigation.d.ts +1 -1
- package/esm/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +6 -10
- package/esm/hooks/features/keyboardNavigation/utils.d.ts +3 -3
- package/esm/hooks/features/keyboardNavigation/utils.js +5 -5
- package/esm/hooks/features/listView/gridListViewSelectors.d.ts +8 -1
- package/esm/hooks/features/listView/gridListViewSelectors.js +7 -0
- package/esm/hooks/features/pivoting/gridPivotingInterfaces.d.ts +0 -1
- package/esm/hooks/features/pivoting/gridPivotingSelectors.d.ts +1 -4
- package/esm/hooks/features/pivoting/gridPivotingSelectors.js +1 -2
- package/esm/hooks/features/rowSelection/useGridRowSelection.js +5 -4
- package/esm/hooks/features/rows/gridRowsMetaInterfaces.d.ts +2 -8
- package/esm/hooks/features/rows/gridRowsMetaState.d.ts +2 -18
- package/esm/hooks/features/rows/gridRowsUtils.d.ts +1 -1
- package/esm/hooks/features/rows/gridRowsUtils.js +5 -2
- package/esm/hooks/features/rows/useGridRowAriaAttributes.js +3 -1
- package/esm/hooks/features/rows/useGridRowSpanning.d.ts +2 -12
- package/esm/hooks/features/rows/useGridRowSpanning.js +54 -85
- package/esm/hooks/features/rows/useGridRows.js +4 -3
- package/esm/hooks/features/rows/useGridRowsMeta.d.ts +1 -1
- package/esm/hooks/features/rows/useGridRowsMeta.js +17 -187
- package/esm/hooks/features/scroll/useGridScroll.d.ts +1 -1
- package/esm/hooks/features/scroll/useGridScroll.js +2 -3
- package/esm/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +1 -1
- package/esm/hooks/features/virtualization/index.d.ts +1 -0
- package/esm/hooks/features/virtualization/index.js +1 -0
- package/esm/hooks/features/virtualization/useGridVirtualization.d.ts +5 -16
- package/esm/hooks/features/virtualization/useGridVirtualization.js +41 -22
- package/esm/hooks/utils/index.d.ts +2 -1
- package/esm/hooks/utils/index.js +2 -1
- package/esm/hooks/utils/useFirstRender.d.ts +1 -1
- package/esm/hooks/utils/useFirstRender.js +1 -8
- package/esm/hooks/utils/useGridInitializeState.d.ts +1 -1
- package/esm/hooks/utils/useGridInitializeState.js +6 -1
- package/esm/hooks/utils/useRunOncePerLoop.d.ts +1 -0
- package/esm/hooks/utils/useRunOncePerLoop.js +26 -0
- package/esm/index.js +1 -1
- package/esm/internals/index.d.ts +1 -1
- package/esm/internals/index.js +1 -1
- package/esm/internals/utils/getPinnedCellOffset.js +5 -0
- package/esm/locales/frFR.js +18 -21
- package/esm/locales/heIL.js +12 -12
- package/esm/locales/plPL.js +22 -24
- package/esm/models/api/gridApiCommon.d.ts +4 -1
- package/esm/models/api/gridColumnSpanning.d.ts +5 -11
- package/esm/models/api/gridRowApi.d.ts +5 -0
- package/esm/models/events/gridEventLookup.d.ts +2 -1
- package/esm/models/gridApiCaches.d.ts +8 -2
- package/esm/models/gridStateCommunity.d.ts +2 -2
- package/esm/models/props/DataGridProps.d.ts +5 -0
- package/esm/utils/roundToDecimalPlaces.d.ts +1 -1
- package/esm/utils/roundToDecimalPlaces.js +1 -3
- package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +5 -0
- package/hooks/core/pipeProcessing/useGridPipeProcessing.js +20 -5
- package/hooks/core/useGridProps.d.ts +2 -2
- package/hooks/core/useGridProps.js +3 -1
- package/hooks/core/useGridVirtualizer.d.ts +9 -0
- package/hooks/core/useGridVirtualizer.js +231 -0
- package/hooks/features/columnGrouping/gridColumnGroupsInterfaces.d.ts +4 -1
- package/hooks/features/columnGrouping/gridColumnGroupsUtils.js +35 -32
- package/hooks/features/columnGrouping/useGridColumnGrouping.js +18 -13
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +1 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +4 -3
- package/hooks/features/columns/gridColumnsInterfaces.d.ts +3 -3
- package/hooks/features/columns/gridColumnsSelector.js +6 -2
- package/hooks/features/columns/gridColumnsUtils.js +6 -4
- package/hooks/features/columns/useGridColumnSpanning.js +5 -91
- package/hooks/features/columns/useGridColumns.js +8 -10
- package/hooks/features/dimensions/useGridDimensions.js +18 -188
- package/hooks/features/export/utils.js +1 -1
- package/hooks/features/filter/useGridFilter.js +3 -3
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.d.ts +1 -1
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +6 -10
- package/hooks/features/keyboardNavigation/utils.d.ts +3 -3
- package/hooks/features/keyboardNavigation/utils.js +5 -5
- package/hooks/features/listView/gridListViewSelectors.d.ts +8 -1
- package/hooks/features/listView/gridListViewSelectors.js +8 -1
- package/hooks/features/pivoting/gridPivotingInterfaces.d.ts +0 -1
- package/hooks/features/pivoting/gridPivotingSelectors.d.ts +1 -4
- package/hooks/features/pivoting/gridPivotingSelectors.js +2 -3
- package/hooks/features/rowSelection/useGridRowSelection.js +5 -4
- package/hooks/features/rows/gridRowsMetaInterfaces.d.ts +2 -8
- package/hooks/features/rows/gridRowsMetaState.d.ts +2 -18
- package/hooks/features/rows/gridRowsUtils.d.ts +1 -1
- package/hooks/features/rows/gridRowsUtils.js +5 -2
- package/hooks/features/rows/useGridRowAriaAttributes.js +3 -1
- package/hooks/features/rows/useGridRowSpanning.d.ts +2 -12
- package/hooks/features/rows/useGridRowSpanning.js +54 -85
- package/hooks/features/rows/useGridRows.js +4 -3
- package/hooks/features/rows/useGridRowsMeta.d.ts +1 -1
- package/hooks/features/rows/useGridRowsMeta.js +15 -186
- package/hooks/features/scroll/useGridScroll.d.ts +1 -1
- package/hooks/features/scroll/useGridScroll.js +2 -3
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +1 -1
- package/hooks/features/virtualization/index.d.ts +1 -0
- package/hooks/features/virtualization/index.js +12 -0
- package/hooks/features/virtualization/useGridVirtualization.d.ts +5 -16
- package/hooks/features/virtualization/useGridVirtualization.js +42 -24
- package/hooks/utils/index.d.ts +2 -1
- package/hooks/utils/index.js +16 -4
- package/hooks/utils/useFirstRender.d.ts +1 -1
- package/hooks/utils/useFirstRender.js +11 -11
- package/hooks/utils/useGridInitializeState.d.ts +1 -1
- package/hooks/utils/useGridInitializeState.js +6 -1
- package/hooks/utils/useRunOncePerLoop.d.ts +1 -0
- package/hooks/utils/useRunOncePerLoop.js +33 -0
- package/index.js +1 -1
- package/internals/index.d.ts +1 -1
- package/internals/index.js +4 -11
- package/internals/utils/getPinnedCellOffset.js +5 -0
- package/locales/frFR.js +18 -21
- package/locales/heIL.js +12 -12
- package/locales/plPL.js +22 -24
- package/models/api/gridApiCommon.d.ts +4 -1
- package/models/api/gridColumnSpanning.d.ts +5 -11
- package/models/api/gridRowApi.d.ts +5 -0
- package/models/events/gridEventLookup.d.ts +2 -1
- package/models/gridApiCaches.d.ts +8 -2
- package/models/gridStateCommunity.d.ts +2 -2
- package/models/props/DataGridProps.d.ts +5 -0
- package/package.json +5 -5
- package/utils/roundToDecimalPlaces.d.ts +1 -1
- package/utils/roundToDecimalPlaces.js +7 -4
- package/esm/hooks/features/rows/gridRowSpanningSelectors.d.ts +0 -10
- package/esm/hooks/features/rows/gridRowSpanningSelectors.js +0 -5
- package/esm/hooks/features/virtualization/useGridVirtualScroller.d.ts +0 -56
- package/esm/hooks/features/virtualization/useGridVirtualScroller.js +0 -846
- package/esm/hooks/utils/useRunOnce.d.ts +0 -5
- package/esm/hooks/utils/useRunOnce.js +0 -18
- package/esm/utils/platform.d.ts +0 -1
- package/esm/utils/platform.js +0 -2
- package/hooks/features/rows/gridRowSpanningSelectors.d.ts +0 -10
- package/hooks/features/rows/gridRowSpanningSelectors.js +0 -11
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +0 -56
- package/hooks/features/virtualization/useGridVirtualScroller.js +0 -857
- package/hooks/utils/useRunOnce.d.ts +0 -5
- package/hooks/utils/useRunOnce.js +0 -27
- package/utils/platform.d.ts +0 -1
- package/utils/platform.js +0 -8
|
@@ -1,12 +1,6 @@
|
|
|
1
|
+
import type { HeightEntry } from '@mui/x-virtualizer/models';
|
|
1
2
|
import { GridRowId } from "../../../models/gridRows.js";
|
|
2
|
-
export type HeightEntry
|
|
3
|
-
content: number;
|
|
4
|
-
spacingTop: number;
|
|
5
|
-
spacingBottom: number;
|
|
6
|
-
detail: number;
|
|
7
|
-
autoHeight: boolean;
|
|
8
|
-
needsFirstMeasurement: boolean;
|
|
9
|
-
};
|
|
3
|
+
export type { HeightEntry } from '@mui/x-virtualizer/models';
|
|
10
4
|
export type HeightCache = Map<GridRowId, HeightEntry>;
|
|
11
5
|
export interface GridRowsMetaInternalCache {
|
|
12
6
|
/**
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
+
import { RowsMetaState } from '@mui/x-virtualizer/models';
|
|
1
2
|
/**
|
|
2
3
|
* The grid rows total height and row positions.
|
|
3
4
|
*/
|
|
4
|
-
export interface GridRowsMetaState {
|
|
5
|
-
/**
|
|
6
|
-
* The sum of all visible grid rows in the current rows.
|
|
7
|
-
*/
|
|
8
|
-
currentPageTotalHeight: number;
|
|
9
|
-
/**
|
|
10
|
-
* The grid rows positions.
|
|
11
|
-
*/
|
|
12
|
-
positions: number[];
|
|
13
|
-
/**
|
|
14
|
-
* The total height of the pinned top rows.
|
|
15
|
-
*/
|
|
16
|
-
pinnedTopRowsTotalHeight: number;
|
|
17
|
-
/**
|
|
18
|
-
* The total height of the pinned bottom rows.
|
|
19
|
-
*/
|
|
20
|
-
pinnedBottomRowsTotalHeight: number;
|
|
21
|
-
}
|
|
5
|
+
export interface GridRowsMetaState extends RowsMetaState {}
|
|
@@ -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
|
-
|
|
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
|
}
|
|
@@ -9,7 +9,9 @@ export const useGridRowAriaAttributes = () => {
|
|
|
9
9
|
const ariaAttributes = {};
|
|
10
10
|
const ariaRowIndex = index + headerGroupingMaxDepth + 2; // 1 for the header row and 1 as it's 1-based
|
|
11
11
|
ariaAttributes['aria-rowindex'] = ariaRowIndex;
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
// XXX: fix this properly
|
|
14
|
+
if (rowNode && apiRef.current.isRowSelectable(rowNode.id)) {
|
|
13
15
|
ariaAttributes['aria-selected'] = apiRef.current.isRowSelected(rowNode.id);
|
|
14
16
|
}
|
|
15
17
|
return ariaAttributes;
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
import { RefObject } from '@mui/x-internals/types';
|
|
2
|
-
import
|
|
3
|
-
import type { GridRowId } from "../../../models/gridRows.js";
|
|
2
|
+
import { RowSpanningState } from '@mui/x-virtualizer/models';
|
|
4
3
|
import type { DataGridProcessedProps } from "../../../models/props/DataGridProps.js";
|
|
5
4
|
import type { GridPrivateApiCommunity } from "../../../models/api/gridApiCommunity.js";
|
|
6
5
|
import type { GridStateInitializer } from "../../utils/useGridInitializeState.js";
|
|
7
|
-
export interface GridRowSpanningState {
|
|
8
|
-
spannedCells: Record<GridRowId, Record<GridColDef['field'], number>>;
|
|
9
|
-
hiddenCells: Record<GridRowId, Record<GridColDef['field'], boolean>>;
|
|
10
|
-
/**
|
|
11
|
-
* For each hidden cell, it contains the row index corresponding to the cell that is
|
|
12
|
-
* the origin of the hidden cell. i.e. the cell which is spanned.
|
|
13
|
-
* Used by the virtualization to properly keep the spanned cells in view.
|
|
14
|
-
*/
|
|
15
|
-
hiddenCellOriginMap: Record<number, Record<GridColDef['field'], number>>;
|
|
16
|
-
}
|
|
6
|
+
export interface GridRowSpanningState extends RowSpanningState {}
|
|
17
7
|
export type RowRange = {
|
|
18
8
|
firstRowIndex: number;
|
|
19
9
|
lastRowIndex: number;
|
|
@@ -2,18 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import
|
|
6
|
-
import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from "../../../internals/constants.js";
|
|
5
|
+
import { Rowspan } from '@mui/x-virtualizer/features';
|
|
7
6
|
import { gridVisibleColumnDefinitionsSelector } from "../columns/gridColumnsSelector.js";
|
|
8
7
|
import { getVisibleRows } from "../../utils/useGridVisibleRows.js";
|
|
9
8
|
import { gridRenderContextSelector } from "../virtualization/gridVirtualizationSelectors.js";
|
|
10
9
|
import { getUnprocessedRange, isRowContextInitialized, getCellValue } from "./gridRowSpanningUtils.js";
|
|
11
|
-
import { GRID_CHECKBOX_SELECTION_FIELD } from "../../../colDef/gridCheckboxSelectionColDef.js";
|
|
12
10
|
import { useGridEvent } from "../../utils/useGridEvent.js";
|
|
13
11
|
import { runIf } from "../../../utils/utils.js";
|
|
14
12
|
import { gridPageSizeSelector } from "../pagination/index.js";
|
|
15
13
|
import { gridDataRowIdsSelector } from "./gridRowsSelector.js";
|
|
16
|
-
const
|
|
14
|
+
const EMPTY_CACHES = {
|
|
17
15
|
spannedCells: {},
|
|
18
16
|
hiddenCells: {},
|
|
19
17
|
hiddenCellOriginMap: {}
|
|
@@ -22,27 +20,31 @@ const EMPTY_RANGE = {
|
|
|
22
20
|
firstRowIndex: 0,
|
|
23
21
|
lastRowIndex: 0
|
|
24
22
|
};
|
|
25
|
-
const
|
|
23
|
+
const EMPTY_STATE = {
|
|
24
|
+
caches: EMPTY_CACHES,
|
|
25
|
+
processedRange: EMPTY_RANGE
|
|
26
|
+
};
|
|
27
|
+
|
|
26
28
|
/**
|
|
27
29
|
* Default number of rows to process during state initialization to avoid flickering.
|
|
28
30
|
* Number `20` is arbitrarily chosen to be large enough to cover most of the cases without
|
|
29
31
|
* compromising performance.
|
|
30
32
|
*/
|
|
31
33
|
const DEFAULT_ROWS_TO_PROCESS = 20;
|
|
32
|
-
const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToProcess, resetState
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToProcess, resetState) => {
|
|
35
|
+
const virtualizer = apiRef.current.virtualizer;
|
|
36
|
+
const previousState = resetState ? EMPTY_STATE : Rowspan.selectors.state(virtualizer.store.state);
|
|
37
|
+
const spannedCells = _extends({}, previousState.caches.spannedCells);
|
|
38
|
+
const hiddenCells = _extends({}, previousState.caches.hiddenCells);
|
|
39
|
+
const hiddenCellOriginMap = _extends({}, previousState.caches.hiddenCellOriginMap);
|
|
40
|
+
const processedRange = {
|
|
41
|
+
firstRowIndex: Math.min(previousState.processedRange.firstRowIndex, rangeToProcess.firstRowIndex),
|
|
42
|
+
lastRowIndex: Math.max(previousState.processedRange.lastRowIndex, rangeToProcess.lastRowIndex)
|
|
43
|
+
};
|
|
44
|
+
colDefs.forEach((colDef, columnIndex) => {
|
|
43
45
|
for (let index = rangeToProcess.firstRowIndex; index < rangeToProcess.lastRowIndex; index += 1) {
|
|
44
46
|
const row = visibleRows[index];
|
|
45
|
-
if (hiddenCells[row.id]?.[
|
|
47
|
+
if (hiddenCells[row.id]?.[columnIndex]) {
|
|
46
48
|
continue;
|
|
47
49
|
}
|
|
48
50
|
const cellValue = getCellValue(row.model, colDef, apiRef);
|
|
@@ -61,10 +63,10 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
|
|
|
61
63
|
while (prevIndex >= range.firstRowIndex && prevRowEntry && getCellValue(prevRowEntry.model, colDef, apiRef) === cellValue) {
|
|
62
64
|
const currentRow = visibleRows[prevIndex + 1];
|
|
63
65
|
if (hiddenCells[currentRow.id]) {
|
|
64
|
-
hiddenCells[currentRow.id][
|
|
66
|
+
hiddenCells[currentRow.id][columnIndex] = true;
|
|
65
67
|
} else {
|
|
66
68
|
hiddenCells[currentRow.id] = {
|
|
67
|
-
[
|
|
69
|
+
[columnIndex]: true
|
|
68
70
|
};
|
|
69
71
|
}
|
|
70
72
|
backwardsHiddenCells.push(index);
|
|
@@ -77,10 +79,10 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
|
|
|
77
79
|
}
|
|
78
80
|
backwardsHiddenCells.forEach(hiddenCellIndex => {
|
|
79
81
|
if (hiddenCellOriginMap[hiddenCellIndex]) {
|
|
80
|
-
hiddenCellOriginMap[hiddenCellIndex][
|
|
82
|
+
hiddenCellOriginMap[hiddenCellIndex][columnIndex] = spannedRowIndex;
|
|
81
83
|
} else {
|
|
82
84
|
hiddenCellOriginMap[hiddenCellIndex] = {
|
|
83
|
-
[
|
|
85
|
+
[columnIndex]: spannedRowIndex
|
|
84
86
|
};
|
|
85
87
|
}
|
|
86
88
|
});
|
|
@@ -90,17 +92,17 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
|
|
|
90
92
|
while (relativeIndex <= range.lastRowIndex && visibleRows[relativeIndex] && getCellValue(visibleRows[relativeIndex].model, colDef, apiRef) === cellValue) {
|
|
91
93
|
const currentRow = visibleRows[relativeIndex];
|
|
92
94
|
if (hiddenCells[currentRow.id]) {
|
|
93
|
-
hiddenCells[currentRow.id][
|
|
95
|
+
hiddenCells[currentRow.id][columnIndex] = true;
|
|
94
96
|
} else {
|
|
95
97
|
hiddenCells[currentRow.id] = {
|
|
96
|
-
[
|
|
98
|
+
[columnIndex]: true
|
|
97
99
|
};
|
|
98
100
|
}
|
|
99
101
|
if (hiddenCellOriginMap[relativeIndex]) {
|
|
100
|
-
hiddenCellOriginMap[relativeIndex][
|
|
102
|
+
hiddenCellOriginMap[relativeIndex][columnIndex] = spannedRowIndex;
|
|
101
103
|
} else {
|
|
102
104
|
hiddenCellOriginMap[relativeIndex] = {
|
|
103
|
-
[
|
|
105
|
+
[columnIndex]: spannedRowIndex
|
|
104
106
|
};
|
|
105
107
|
}
|
|
106
108
|
relativeIndex += 1;
|
|
@@ -108,23 +110,21 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
|
|
|
108
110
|
}
|
|
109
111
|
if (rowSpan > 0) {
|
|
110
112
|
if (spannedCells[spannedRowId]) {
|
|
111
|
-
spannedCells[spannedRowId][
|
|
113
|
+
spannedCells[spannedRowId][columnIndex] = rowSpan + 1;
|
|
112
114
|
} else {
|
|
113
115
|
spannedCells[spannedRowId] = {
|
|
114
|
-
[
|
|
116
|
+
[columnIndex]: rowSpan + 1
|
|
115
117
|
};
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
|
-
processedRange = {
|
|
120
|
-
firstRowIndex: Math.min(processedRange.firstRowIndex, rangeToProcess.firstRowIndex),
|
|
121
|
-
lastRowIndex: Math.max(processedRange.lastRowIndex, rangeToProcess.lastRowIndex)
|
|
122
|
-
};
|
|
123
121
|
});
|
|
124
122
|
return {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
caches: {
|
|
124
|
+
spannedCells,
|
|
125
|
+
hiddenCells,
|
|
126
|
+
hiddenCellOriginMap
|
|
127
|
+
},
|
|
128
128
|
processedRange
|
|
129
129
|
};
|
|
130
130
|
};
|
|
@@ -174,71 +174,42 @@ export const rowSpanningStateInitializer = (state, props, apiRef) => {
|
|
|
174
174
|
model: dataRowIdToModelLookup[id]
|
|
175
175
|
}));
|
|
176
176
|
const colDefs = orderedFields.map(field => columnsLookup[field]);
|
|
177
|
-
const
|
|
178
|
-
spannedCells,
|
|
179
|
-
hiddenCells,
|
|
180
|
-
hiddenCellOriginMap
|
|
181
|
-
} = computeRowSpanningState(apiRef, colDefs, rows, rangeToProcess, rangeToProcess, true, EMPTY_RANGE);
|
|
177
|
+
const rowSpanning = computeRowSpanningState(apiRef, colDefs, rows, rangeToProcess, rangeToProcess, true);
|
|
182
178
|
return _extends({}, state, {
|
|
183
|
-
rowSpanning
|
|
184
|
-
spannedCells,
|
|
185
|
-
hiddenCells,
|
|
186
|
-
hiddenCellOriginMap
|
|
187
|
-
}
|
|
179
|
+
rowSpanning
|
|
188
180
|
});
|
|
189
181
|
};
|
|
190
182
|
export const useGridRowSpanning = (apiRef, props) => {
|
|
191
|
-
const
|
|
192
|
-
return apiRef.current.state.rowSpanning !== EMPTY_STATE ? getInitialRangeToProcess(props, apiRef) : EMPTY_RANGE;
|
|
193
|
-
});
|
|
183
|
+
const store = apiRef.current.virtualizer.store;
|
|
194
184
|
const updateRowSpanningState = React.useCallback((renderContext, resetState = false) => {
|
|
195
185
|
const {
|
|
196
186
|
range,
|
|
197
187
|
rows: visibleRows
|
|
198
|
-
} = getVisibleRows(apiRef
|
|
199
|
-
pagination: props.pagination,
|
|
200
|
-
paginationMode: props.paginationMode
|
|
201
|
-
});
|
|
188
|
+
} = getVisibleRows(apiRef);
|
|
202
189
|
if (range === null || !isRowContextInitialized(renderContext)) {
|
|
203
190
|
return;
|
|
204
191
|
}
|
|
205
|
-
|
|
206
|
-
processedRange.current = EMPTY_RANGE;
|
|
207
|
-
}
|
|
192
|
+
const previousState = resetState ? EMPTY_STATE : Rowspan.selectors.state(store.state);
|
|
208
193
|
const rangeToProcess = getUnprocessedRange({
|
|
209
194
|
firstRowIndex: renderContext.firstRowIndex,
|
|
210
|
-
lastRowIndex: Math.min(renderContext.lastRowIndex, range.lastRowIndex + 1)
|
|
211
|
-
}, processedRange
|
|
195
|
+
lastRowIndex: Math.min(renderContext.lastRowIndex, range.lastRowIndex - range.firstRowIndex + 1)
|
|
196
|
+
}, previousState.processedRange);
|
|
212
197
|
if (rangeToProcess === null) {
|
|
213
198
|
return;
|
|
214
199
|
}
|
|
215
200
|
const colDefs = gridVisibleColumnDefinitionsSelector(apiRef);
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const newSpannedCellsCount = Object.keys(spannedCells).length;
|
|
224
|
-
const newHiddenCellsCount = Object.keys(hiddenCells).length;
|
|
225
|
-
const currentSpannedCellsCount = Object.keys(apiRef.current.state.rowSpanning.spannedCells).length;
|
|
226
|
-
const currentHiddenCellsCount = Object.keys(apiRef.current.state.rowSpanning.hiddenCells).length;
|
|
227
|
-
const shouldUpdateState = resetState || newSpannedCellsCount !== currentSpannedCellsCount || newHiddenCellsCount !== currentHiddenCellsCount;
|
|
228
|
-
const hasNoSpannedCells = newSpannedCellsCount === 0 && currentSpannedCellsCount === 0;
|
|
201
|
+
const newState = computeRowSpanningState(apiRef, colDefs, visibleRows, range, rangeToProcess, resetState);
|
|
202
|
+
const newSpannedCellsCount = Object.keys(newState.caches.spannedCells).length;
|
|
203
|
+
const newHiddenCellsCount = Object.keys(newState.caches.hiddenCells).length;
|
|
204
|
+
const previousSpannedCellsCount = Object.keys(previousState.caches.spannedCells).length;
|
|
205
|
+
const previousHiddenCellsCount = Object.keys(previousState.caches.hiddenCells).length;
|
|
206
|
+
const shouldUpdateState = resetState || newSpannedCellsCount !== previousSpannedCellsCount || newHiddenCellsCount !== previousHiddenCellsCount;
|
|
207
|
+
const hasNoSpannedCells = newSpannedCellsCount === 0 && previousSpannedCellsCount === 0;
|
|
229
208
|
if (!shouldUpdateState || hasNoSpannedCells) {
|
|
230
209
|
return;
|
|
231
210
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
rowSpanning: {
|
|
235
|
-
spannedCells,
|
|
236
|
-
hiddenCells,
|
|
237
|
-
hiddenCellOriginMap
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
}, [apiRef, processedRange, props.pagination, props.paginationMode]);
|
|
211
|
+
store.set('rowSpanning', newState);
|
|
212
|
+
}, [apiRef, store]);
|
|
242
213
|
|
|
243
214
|
// Reset events trigger a full re-computation of the row spanning state:
|
|
244
215
|
// - The `unstable_rowSpanning` prop is updated (feature flag)
|
|
@@ -260,13 +231,11 @@ export const useGridRowSpanning = (apiRef, props) => {
|
|
|
260
231
|
useGridEvent(apiRef, 'columnsChange', runIf(props.rowSpanning, resetRowSpanningState));
|
|
261
232
|
React.useEffect(() => {
|
|
262
233
|
if (!props.rowSpanning) {
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
rowSpanning: EMPTY_STATE
|
|
266
|
-
}));
|
|
234
|
+
if (store.state.rowSpanning !== EMPTY_STATE) {
|
|
235
|
+
store.set('rowSpanning', EMPTY_STATE);
|
|
267
236
|
}
|
|
268
|
-
} else if (
|
|
237
|
+
} else if (store.state.rowSpanning.caches === EMPTY_CACHES) {
|
|
269
238
|
resetRowSpanningState();
|
|
270
239
|
}
|
|
271
|
-
}, [apiRef, resetRowSpanningState, props.rowSpanning]);
|
|
240
|
+
}, [apiRef, store, resetRowSpanningState, props.rowSpanning]);
|
|
272
241
|
};
|
|
@@ -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);
|
|
@@ -7,4 +7,4 @@ export declare const rowsMetaStateInitializer: GridStateInitializer;
|
|
|
7
7
|
* @requires useGridPageSize (method)
|
|
8
8
|
* @requires useGridPage (method)
|
|
9
9
|
*/
|
|
10
|
-
export declare const useGridRowsMeta: (apiRef: RefObject<GridPrivateApiCommunity>,
|
|
10
|
+
export declare const useGridRowsMeta: (apiRef: RefObject<GridPrivateApiCommunity>, _props: Pick<DataGridProcessedProps, "getRowHeight" | "getEstimatedRowHeight" | "getRowSpacing" | "pagination" | "paginationMode" | "rowHeight">) => void;
|
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import useLazyRef from '@mui/utils/useLazyRef';
|
|
4
|
-
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
5
|
-
import { ResizeObserver } from "../../../utils/ResizeObserver.js";
|
|
6
|
-
import { useGridVisibleRows } from "../../utils/useGridVisibleRows.js";
|
|
7
|
-
import { eslintUseValue } from "../../../utils/utils.js";
|
|
8
2
|
import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
|
|
9
|
-
import { useGridSelector } from "../../utils/useGridSelector.js";
|
|
10
|
-
import { gridDensityFactorSelector } from "../density/densitySelector.js";
|
|
11
3
|
import { gridPaginationSelector } from "../pagination/gridPaginationSelector.js";
|
|
12
4
|
import { useGridRegisterPipeApplier } from "../../core/pipeProcessing/index.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { getValidRowHeight, getRowHeightWarning } from "./gridRowsUtils.js";
|
|
16
|
-
import { gridFocusedVirtualCellSelector } from "../virtualization/gridFocusedVirtualCellSelector.js";
|
|
17
|
-
/* eslint-disable no-underscore-dangle */
|
|
18
|
-
|
|
5
|
+
import { gridRowCountSelector } from "./gridRowsSelector.js";
|
|
6
|
+
import { gridRowHeightSelector } from "../dimensions/gridDimensionsSelectors.js";
|
|
19
7
|
export const rowsMetaStateInitializer = (state, props, apiRef) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
// FIXME: This should be handled in the virtualizer eventually, but there are interdependencies
|
|
9
|
+
// between state initializers that need to be untangled carefully.
|
|
10
|
+
|
|
23
11
|
const baseRowHeight = gridRowHeightSelector(apiRef);
|
|
24
12
|
const dataRowCount = gridRowCountSelector(apiRef);
|
|
25
13
|
const pagination = gridPaginationSelector(apiRef);
|
|
@@ -40,178 +28,20 @@ export const rowsMetaStateInitializer = (state, props, apiRef) => {
|
|
|
40
28
|
* @requires useGridPageSize (method)
|
|
41
29
|
* @requires useGridPage (method)
|
|
42
30
|
*/
|
|
43
|
-
export const useGridRowsMeta = (apiRef,
|
|
31
|
+
export const useGridRowsMeta = (apiRef, _props) => {
|
|
32
|
+
const virtualizer = apiRef.current.virtualizer;
|
|
44
33
|
const {
|
|
45
|
-
getRowHeight
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const pinnedRows = useGridSelector(apiRef, gridPinnedRowsSelector);
|
|
56
|
-
const rowHeight = useGridSelector(apiRef, gridRowHeightSelector);
|
|
57
|
-
const getRowHeightEntry = rowId => {
|
|
58
|
-
let entry = heightCache.get(rowId);
|
|
59
|
-
if (entry === undefined) {
|
|
60
|
-
entry = {
|
|
61
|
-
content: rowHeight,
|
|
62
|
-
spacingTop: 0,
|
|
63
|
-
spacingBottom: 0,
|
|
64
|
-
detail: 0,
|
|
65
|
-
autoHeight: false,
|
|
66
|
-
needsFirstMeasurement: true
|
|
67
|
-
};
|
|
68
|
-
heightCache.set(rowId, entry);
|
|
69
|
-
}
|
|
70
|
-
return entry;
|
|
71
|
-
};
|
|
72
|
-
const processHeightEntry = React.useCallback(row => {
|
|
73
|
-
// HACK: rowHeight trails behind the most up-to-date value just enough to
|
|
74
|
-
// mess the initial rowsMeta hydration :/
|
|
75
|
-
const baseRowHeight = gridDimensionsSelector(apiRef).rowHeight;
|
|
76
|
-
eslintUseValue(rowHeight);
|
|
77
|
-
const entry = apiRef.current.getRowHeightEntry(row.id);
|
|
78
|
-
if (!getRowHeightProp) {
|
|
79
|
-
entry.content = baseRowHeight;
|
|
80
|
-
entry.needsFirstMeasurement = false;
|
|
81
|
-
} else {
|
|
82
|
-
const rowHeightFromUser = getRowHeightProp(_extends({}, row, {
|
|
83
|
-
densityFactor
|
|
84
|
-
}));
|
|
85
|
-
if (rowHeightFromUser === 'auto') {
|
|
86
|
-
if (entry.needsFirstMeasurement) {
|
|
87
|
-
const estimatedRowHeight = getEstimatedRowHeight ? getEstimatedRowHeight(_extends({}, row, {
|
|
88
|
-
densityFactor
|
|
89
|
-
})) : baseRowHeight;
|
|
90
|
-
|
|
91
|
-
// If the row was not measured yet use the estimated row height
|
|
92
|
-
entry.content = estimatedRowHeight ?? baseRowHeight;
|
|
93
|
-
}
|
|
94
|
-
hasRowWithAutoHeight.current = true;
|
|
95
|
-
entry.autoHeight = true;
|
|
96
|
-
} else {
|
|
97
|
-
// Default back to base rowHeight if getRowHeight returns invalid value.
|
|
98
|
-
entry.content = getValidRowHeight(rowHeightFromUser, baseRowHeight, getRowHeightWarning);
|
|
99
|
-
entry.needsFirstMeasurement = false;
|
|
100
|
-
entry.autoHeight = false;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (getRowSpacing) {
|
|
104
|
-
const indexRelativeToCurrentPage = apiRef.current.getRowIndexRelativeToVisibleRows(row.id);
|
|
105
|
-
const spacing = getRowSpacing(_extends({}, row, {
|
|
106
|
-
isFirstVisible: indexRelativeToCurrentPage === 0,
|
|
107
|
-
isLastVisible: indexRelativeToCurrentPage === currentPage.rows.length - 1,
|
|
108
|
-
indexRelativeToCurrentPage
|
|
109
|
-
}));
|
|
110
|
-
entry.spacingTop = spacing.top ?? 0;
|
|
111
|
-
entry.spacingBottom = spacing.bottom ?? 0;
|
|
112
|
-
} else {
|
|
113
|
-
entry.spacingTop = 0;
|
|
114
|
-
entry.spacingBottom = 0;
|
|
115
|
-
}
|
|
116
|
-
apiRef.current.unstable_applyPipeProcessors('rowHeight', entry, row);
|
|
117
|
-
return entry;
|
|
118
|
-
}, [apiRef, currentPage.rows, getRowHeightProp, getEstimatedRowHeight, rowHeight, getRowSpacing, densityFactor]);
|
|
119
|
-
const hydrateRowsMeta = React.useCallback(() => {
|
|
120
|
-
hasRowWithAutoHeight.current = false;
|
|
121
|
-
const pinnedTopRowsTotalHeight = pinnedRows.top.reduce((acc, row) => {
|
|
122
|
-
const entry = processHeightEntry(row);
|
|
123
|
-
return acc + entry.content + entry.spacingTop + entry.spacingBottom + entry.detail;
|
|
124
|
-
}, 0);
|
|
125
|
-
const pinnedBottomRowsTotalHeight = pinnedRows.bottom.reduce((acc, row) => {
|
|
126
|
-
const entry = processHeightEntry(row);
|
|
127
|
-
return acc + entry.content + entry.spacingTop + entry.spacingBottom + entry.detail;
|
|
128
|
-
}, 0);
|
|
129
|
-
const positions = [];
|
|
130
|
-
const currentPageTotalHeight = currentPage.rows.reduce((acc, row) => {
|
|
131
|
-
positions.push(acc);
|
|
132
|
-
const entry = processHeightEntry(row);
|
|
133
|
-
const total = entry.content + entry.spacingTop + entry.spacingBottom + entry.detail;
|
|
134
|
-
return acc + total;
|
|
135
|
-
}, 0);
|
|
136
|
-
if (!hasRowWithAutoHeight.current) {
|
|
137
|
-
// No row has height=auto, so all rows are already measured
|
|
138
|
-
lastMeasuredRowIndex.current = Infinity;
|
|
139
|
-
}
|
|
140
|
-
const didHeightsChange = pinnedTopRowsTotalHeight !== apiRef.current.state.rowsMeta.pinnedTopRowsTotalHeight || pinnedBottomRowsTotalHeight !== apiRef.current.state.rowsMeta.pinnedBottomRowsTotalHeight || currentPageTotalHeight !== apiRef.current.state.rowsMeta.currentPageTotalHeight;
|
|
141
|
-
const rowsMeta = {
|
|
142
|
-
currentPageTotalHeight,
|
|
143
|
-
positions,
|
|
144
|
-
pinnedTopRowsTotalHeight,
|
|
145
|
-
pinnedBottomRowsTotalHeight
|
|
146
|
-
};
|
|
147
|
-
apiRef.current.setState(state => {
|
|
148
|
-
return _extends({}, state, {
|
|
149
|
-
rowsMeta
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
if (didHeightsChange) {
|
|
153
|
-
apiRef.current.updateDimensions();
|
|
154
|
-
}
|
|
155
|
-
isHeightMetaValid.current = true;
|
|
156
|
-
}, [apiRef, pinnedRows, currentPage.rows, processHeightEntry]);
|
|
157
|
-
const getRowHeight = rowId => {
|
|
158
|
-
return heightCache.get(rowId)?.content ?? rowHeight;
|
|
159
|
-
};
|
|
160
|
-
const storeRowHeightMeasurement = (id, height) => {
|
|
161
|
-
const entry = apiRef.current.getRowHeightEntry(id);
|
|
162
|
-
const didChange = entry.content !== height;
|
|
163
|
-
entry.needsFirstMeasurement = false;
|
|
164
|
-
entry.content = height;
|
|
165
|
-
isHeightMetaValid.current &&= !didChange;
|
|
166
|
-
};
|
|
167
|
-
const rowHasAutoHeight = id => {
|
|
168
|
-
return heightCache.get(id)?.autoHeight ?? false;
|
|
169
|
-
};
|
|
170
|
-
const getLastMeasuredRowIndex = () => {
|
|
171
|
-
return lastMeasuredRowIndex.current;
|
|
172
|
-
};
|
|
173
|
-
const setLastMeasuredRowIndex = index => {
|
|
174
|
-
if (hasRowWithAutoHeight.current && index > lastMeasuredRowIndex.current) {
|
|
175
|
-
lastMeasuredRowIndex.current = index;
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
const resetRowHeights = () => {
|
|
179
|
-
heightCache.clear();
|
|
180
|
-
hydrateRowsMeta();
|
|
181
|
-
};
|
|
182
|
-
const resizeObserver = useLazyRef(() => new ResizeObserver(entries => {
|
|
183
|
-
for (let i = 0; i < entries.length; i += 1) {
|
|
184
|
-
const entry = entries[i];
|
|
185
|
-
const height = entry.borderBoxSize && entry.borderBoxSize.length > 0 ? entry.borderBoxSize[0].blockSize : entry.contentRect.height;
|
|
186
|
-
const rowId = entry.target.__mui_id;
|
|
187
|
-
const focusedVirtualRowId = gridFocusedVirtualCellSelector(apiRef)?.id;
|
|
188
|
-
if (focusedVirtualRowId === rowId && height === 0) {
|
|
189
|
-
// Focused virtual row has 0 height.
|
|
190
|
-
// We don't want to store it to avoid scroll jumping.
|
|
191
|
-
// https://github.com/mui/mui-x/issues/14726
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
apiRef.current.unstable_storeRowHeightMeasurement(rowId, height);
|
|
195
|
-
}
|
|
196
|
-
if (!isHeightMetaValid.current) {
|
|
197
|
-
// Avoids "ResizeObserver loop completed with undelivered notifications" error
|
|
198
|
-
requestAnimationFrame(() => {
|
|
199
|
-
apiRef.current.requestPipeProcessorsApplication('rowHeight');
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
})).current;
|
|
203
|
-
const observeRowHeight = (element, rowId) => {
|
|
204
|
-
element.__mui_id = rowId;
|
|
205
|
-
resizeObserver.observe(element);
|
|
206
|
-
return () => resizeObserver.unobserve(element);
|
|
207
|
-
};
|
|
34
|
+
getRowHeight,
|
|
35
|
+
setLastMeasuredRowIndex,
|
|
36
|
+
storeRowHeightMeasurement,
|
|
37
|
+
resetRowHeights,
|
|
38
|
+
hydrateRowsMeta,
|
|
39
|
+
observeRowHeight,
|
|
40
|
+
rowHasAutoHeight,
|
|
41
|
+
getRowHeightEntry,
|
|
42
|
+
getLastMeasuredRowIndex
|
|
43
|
+
} = virtualizer.api.rowsMeta;
|
|
208
44
|
useGridRegisterPipeApplier(apiRef, 'rowHeight', hydrateRowsMeta);
|
|
209
|
-
|
|
210
|
-
// The effect is used to build the rows meta data - currentPageTotalHeight and positions.
|
|
211
|
-
// Because of variable row height this is needed for the virtualization
|
|
212
|
-
useEnhancedEffect(() => {
|
|
213
|
-
hydrateRowsMeta();
|
|
214
|
-
}, [hydrateRowsMeta]);
|
|
215
45
|
const rowsMetaApi = {
|
|
216
46
|
unstable_getRowHeight: getRowHeight,
|
|
217
47
|
unstable_setLastMeasuredRowIndex: setLastMeasuredRowIndex,
|
|
@@ -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"
|
|
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 =
|
|
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
|
|
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;
|
|
@@ -34,7 +34,7 @@ export declare const gridVirtualizationRowEnabledSelector: (args_0: import("reac
|
|
|
34
34
|
*/
|
|
35
35
|
export declare const gridRenderContextSelector: (args_0: import("react").RefObject<{
|
|
36
36
|
state: GridStateCommunity;
|
|
37
|
-
} | null>) => import("@mui/x-
|
|
37
|
+
} | null>) => import("@mui/x-virtualizer/models").RenderContext;
|
|
38
38
|
/**
|
|
39
39
|
* Get the render context, with only columns filled in.
|
|
40
40
|
* This is cached, so it can be used to only re-render when the column interval changes.
|