@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
|
@@ -307,12 +307,13 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
307
307
|
}
|
|
308
308
|
const currentSelection = (0, _gridRowSelectionSelector.gridRowSelectionStateSelector)(apiRef);
|
|
309
309
|
const rowsLookup = (0, _gridRowsSelector.gridRowsLookupSelector)(apiRef);
|
|
310
|
+
const rowTree = (0, _gridRowsSelector.gridRowTreeSelector)(apiRef);
|
|
310
311
|
const filteredRowsLookup = (0, _gridFilterSelector.gridFilteredRowsLookupSelector)(apiRef);
|
|
311
312
|
const isNonExistent = id => {
|
|
312
313
|
if (props.filterMode === 'server') {
|
|
313
314
|
return !rowsLookup[id];
|
|
314
315
|
}
|
|
315
|
-
return !
|
|
316
|
+
return !rowTree[id] || filteredRowsLookup[id] === false;
|
|
316
317
|
};
|
|
317
318
|
const newSelectionModel = {
|
|
318
319
|
type: currentSelection.type,
|
|
@@ -438,15 +439,15 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
438
439
|
const filterModel = (0, _gridFilterSelector.gridFilterModelSelector)(apiRef);
|
|
439
440
|
const quickFilterModel = (0, _gridFilterSelector.gridQuickFilterValuesSelector)(apiRef);
|
|
440
441
|
const hasFilters = filterModel.items.length > 0 || quickFilterModel?.some(val => val.length);
|
|
441
|
-
if (!props.isRowSelectable && !props.checkboxSelectionVisibleOnly &&
|
|
442
|
+
if (!props.isRowSelectable && !props.checkboxSelectionVisibleOnly && (!isNestedData || props.rowSelectionPropagation?.descendants) && !hasFilters) {
|
|
442
443
|
apiRef.current.setRowSelectionModel({
|
|
443
444
|
type: value ? 'exclude' : 'include',
|
|
444
445
|
ids: new Set()
|
|
445
|
-
});
|
|
446
|
+
}, 'multipleRowsSelection');
|
|
446
447
|
} else {
|
|
447
448
|
apiRef.current.selectRows(getRowsToBeSelected(), value);
|
|
448
449
|
}
|
|
449
|
-
}, [apiRef,
|
|
450
|
+
}, [apiRef, getRowsToBeSelected, props.checkboxSelectionVisibleOnly, props.isRowSelectable, props.rowSelectionPropagation?.descendants, isNestedData]);
|
|
450
451
|
const handleHeaderSelectionCheckboxChange = React.useCallback(params => {
|
|
451
452
|
toggleAllRows(params.value);
|
|
452
453
|
}, [toggleAllRows]);
|
|
@@ -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,
|
|
@@ -145,7 +145,7 @@ const isAutogeneratedRow = row => GRID_ID_AUTOGENERATED in row;
|
|
|
145
145
|
exports.isAutogeneratedRow = isAutogeneratedRow;
|
|
146
146
|
const isAutogeneratedRowNode = rowNode => rowNode.type === 'skeletonRow' || rowNode.type === 'footer' || rowNode.type === 'group' && rowNode.isAutoGenerated || rowNode.type === 'pinnedRow' && rowNode.isAutoGenerated;
|
|
147
147
|
exports.isAutogeneratedRowNode = isAutogeneratedRowNode;
|
|
148
|
-
const getTreeNodeDescendants = (tree, parentId, skipAutoGeneratedRows) => {
|
|
148
|
+
const getTreeNodeDescendants = (tree, parentId, skipAutoGeneratedRows, directChildrenOnly) => {
|
|
149
149
|
const node = tree[parentId];
|
|
150
150
|
if (node.type !== 'group') {
|
|
151
151
|
return [];
|
|
@@ -156,7 +156,10 @@ const getTreeNodeDescendants = (tree, parentId, skipAutoGeneratedRows) => {
|
|
|
156
156
|
if (!skipAutoGeneratedRows || !isAutogeneratedRowNode(tree[child])) {
|
|
157
157
|
validDescendants.push(child);
|
|
158
158
|
}
|
|
159
|
-
|
|
159
|
+
if (directChildrenOnly) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const childDescendants = getTreeNodeDescendants(tree, child, skipAutoGeneratedRows, directChildrenOnly);
|
|
160
163
|
for (let j = 0; j < childDescendants.length; j += 1) {
|
|
161
164
|
validDescendants.push(childDescendants[j]);
|
|
162
165
|
}
|
|
@@ -16,7 +16,9 @@ const useGridRowAriaAttributes = () => {
|
|
|
16
16
|
const ariaAttributes = {};
|
|
17
17
|
const ariaRowIndex = index + headerGroupingMaxDepth + 2; // 1 for the header row and 1 as it's 1-based
|
|
18
18
|
ariaAttributes['aria-rowindex'] = ariaRowIndex;
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
// XXX: fix this properly
|
|
21
|
+
if (rowNode && apiRef.current.isRowSelectable(rowNode.id)) {
|
|
20
22
|
ariaAttributes['aria-selected'] = apiRef.current.isRowSelected(rowNode.id);
|
|
21
23
|
}
|
|
22
24
|
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;
|
|
@@ -9,18 +9,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
9
9
|
exports.useGridRowSpanning = exports.rowSpanningStateInitializer = void 0;
|
|
10
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
11
|
var React = _interopRequireWildcard(require("react"));
|
|
12
|
-
var
|
|
13
|
-
var _constants = require("../../../internals/constants");
|
|
12
|
+
var _features = require("@mui/x-virtualizer/features");
|
|
14
13
|
var _gridColumnsSelector = require("../columns/gridColumnsSelector");
|
|
15
14
|
var _useGridVisibleRows = require("../../utils/useGridVisibleRows");
|
|
16
15
|
var _gridVirtualizationSelectors = require("../virtualization/gridVirtualizationSelectors");
|
|
17
16
|
var _gridRowSpanningUtils = require("./gridRowSpanningUtils");
|
|
18
|
-
var _gridCheckboxSelectionColDef = require("../../../colDef/gridCheckboxSelectionColDef");
|
|
19
17
|
var _useGridEvent = require("../../utils/useGridEvent");
|
|
20
18
|
var _utils = require("../../../utils/utils");
|
|
21
19
|
var _pagination = require("../pagination");
|
|
22
20
|
var _gridRowsSelector = require("./gridRowsSelector");
|
|
23
|
-
const
|
|
21
|
+
const EMPTY_CACHES = {
|
|
24
22
|
spannedCells: {},
|
|
25
23
|
hiddenCells: {},
|
|
26
24
|
hiddenCellOriginMap: {}
|
|
@@ -29,27 +27,31 @@ const EMPTY_RANGE = {
|
|
|
29
27
|
firstRowIndex: 0,
|
|
30
28
|
lastRowIndex: 0
|
|
31
29
|
};
|
|
32
|
-
const
|
|
30
|
+
const EMPTY_STATE = {
|
|
31
|
+
caches: EMPTY_CACHES,
|
|
32
|
+
processedRange: EMPTY_RANGE
|
|
33
|
+
};
|
|
34
|
+
|
|
33
35
|
/**
|
|
34
36
|
* Default number of rows to process during state initialization to avoid flickering.
|
|
35
37
|
* Number `20` is arbitrarily chosen to be large enough to cover most of the cases without
|
|
36
38
|
* compromising performance.
|
|
37
39
|
*/
|
|
38
40
|
const DEFAULT_ROWS_TO_PROCESS = 20;
|
|
39
|
-
const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToProcess, resetState
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToProcess, resetState) => {
|
|
42
|
+
const virtualizer = apiRef.current.virtualizer;
|
|
43
|
+
const previousState = resetState ? EMPTY_STATE : _features.Rowspan.selectors.state(virtualizer.store.state);
|
|
44
|
+
const spannedCells = (0, _extends2.default)({}, previousState.caches.spannedCells);
|
|
45
|
+
const hiddenCells = (0, _extends2.default)({}, previousState.caches.hiddenCells);
|
|
46
|
+
const hiddenCellOriginMap = (0, _extends2.default)({}, previousState.caches.hiddenCellOriginMap);
|
|
47
|
+
const processedRange = {
|
|
48
|
+
firstRowIndex: Math.min(previousState.processedRange.firstRowIndex, rangeToProcess.firstRowIndex),
|
|
49
|
+
lastRowIndex: Math.max(previousState.processedRange.lastRowIndex, rangeToProcess.lastRowIndex)
|
|
50
|
+
};
|
|
51
|
+
colDefs.forEach((colDef, columnIndex) => {
|
|
50
52
|
for (let index = rangeToProcess.firstRowIndex; index < rangeToProcess.lastRowIndex; index += 1) {
|
|
51
53
|
const row = visibleRows[index];
|
|
52
|
-
if (hiddenCells[row.id]?.[
|
|
54
|
+
if (hiddenCells[row.id]?.[columnIndex]) {
|
|
53
55
|
continue;
|
|
54
56
|
}
|
|
55
57
|
const cellValue = (0, _gridRowSpanningUtils.getCellValue)(row.model, colDef, apiRef);
|
|
@@ -68,10 +70,10 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
|
|
|
68
70
|
while (prevIndex >= range.firstRowIndex && prevRowEntry && (0, _gridRowSpanningUtils.getCellValue)(prevRowEntry.model, colDef, apiRef) === cellValue) {
|
|
69
71
|
const currentRow = visibleRows[prevIndex + 1];
|
|
70
72
|
if (hiddenCells[currentRow.id]) {
|
|
71
|
-
hiddenCells[currentRow.id][
|
|
73
|
+
hiddenCells[currentRow.id][columnIndex] = true;
|
|
72
74
|
} else {
|
|
73
75
|
hiddenCells[currentRow.id] = {
|
|
74
|
-
[
|
|
76
|
+
[columnIndex]: true
|
|
75
77
|
};
|
|
76
78
|
}
|
|
77
79
|
backwardsHiddenCells.push(index);
|
|
@@ -84,10 +86,10 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
|
|
|
84
86
|
}
|
|
85
87
|
backwardsHiddenCells.forEach(hiddenCellIndex => {
|
|
86
88
|
if (hiddenCellOriginMap[hiddenCellIndex]) {
|
|
87
|
-
hiddenCellOriginMap[hiddenCellIndex][
|
|
89
|
+
hiddenCellOriginMap[hiddenCellIndex][columnIndex] = spannedRowIndex;
|
|
88
90
|
} else {
|
|
89
91
|
hiddenCellOriginMap[hiddenCellIndex] = {
|
|
90
|
-
[
|
|
92
|
+
[columnIndex]: spannedRowIndex
|
|
91
93
|
};
|
|
92
94
|
}
|
|
93
95
|
});
|
|
@@ -97,17 +99,17 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
|
|
|
97
99
|
while (relativeIndex <= range.lastRowIndex && visibleRows[relativeIndex] && (0, _gridRowSpanningUtils.getCellValue)(visibleRows[relativeIndex].model, colDef, apiRef) === cellValue) {
|
|
98
100
|
const currentRow = visibleRows[relativeIndex];
|
|
99
101
|
if (hiddenCells[currentRow.id]) {
|
|
100
|
-
hiddenCells[currentRow.id][
|
|
102
|
+
hiddenCells[currentRow.id][columnIndex] = true;
|
|
101
103
|
} else {
|
|
102
104
|
hiddenCells[currentRow.id] = {
|
|
103
|
-
[
|
|
105
|
+
[columnIndex]: true
|
|
104
106
|
};
|
|
105
107
|
}
|
|
106
108
|
if (hiddenCellOriginMap[relativeIndex]) {
|
|
107
|
-
hiddenCellOriginMap[relativeIndex][
|
|
109
|
+
hiddenCellOriginMap[relativeIndex][columnIndex] = spannedRowIndex;
|
|
108
110
|
} else {
|
|
109
111
|
hiddenCellOriginMap[relativeIndex] = {
|
|
110
|
-
[
|
|
112
|
+
[columnIndex]: spannedRowIndex
|
|
111
113
|
};
|
|
112
114
|
}
|
|
113
115
|
relativeIndex += 1;
|
|
@@ -115,23 +117,21 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
|
|
|
115
117
|
}
|
|
116
118
|
if (rowSpan > 0) {
|
|
117
119
|
if (spannedCells[spannedRowId]) {
|
|
118
|
-
spannedCells[spannedRowId][
|
|
120
|
+
spannedCells[spannedRowId][columnIndex] = rowSpan + 1;
|
|
119
121
|
} else {
|
|
120
122
|
spannedCells[spannedRowId] = {
|
|
121
|
-
[
|
|
123
|
+
[columnIndex]: rowSpan + 1
|
|
122
124
|
};
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
|
-
processedRange = {
|
|
127
|
-
firstRowIndex: Math.min(processedRange.firstRowIndex, rangeToProcess.firstRowIndex),
|
|
128
|
-
lastRowIndex: Math.max(processedRange.lastRowIndex, rangeToProcess.lastRowIndex)
|
|
129
|
-
};
|
|
130
128
|
});
|
|
131
129
|
return {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
caches: {
|
|
131
|
+
spannedCells,
|
|
132
|
+
hiddenCells,
|
|
133
|
+
hiddenCellOriginMap
|
|
134
|
+
},
|
|
135
135
|
processedRange
|
|
136
136
|
};
|
|
137
137
|
};
|
|
@@ -181,72 +181,43 @@ const rowSpanningStateInitializer = (state, props, apiRef) => {
|
|
|
181
181
|
model: dataRowIdToModelLookup[id]
|
|
182
182
|
}));
|
|
183
183
|
const colDefs = orderedFields.map(field => columnsLookup[field]);
|
|
184
|
-
const
|
|
185
|
-
spannedCells,
|
|
186
|
-
hiddenCells,
|
|
187
|
-
hiddenCellOriginMap
|
|
188
|
-
} = computeRowSpanningState(apiRef, colDefs, rows, rangeToProcess, rangeToProcess, true, EMPTY_RANGE);
|
|
184
|
+
const rowSpanning = computeRowSpanningState(apiRef, colDefs, rows, rangeToProcess, rangeToProcess, true);
|
|
189
185
|
return (0, _extends2.default)({}, state, {
|
|
190
|
-
rowSpanning
|
|
191
|
-
spannedCells,
|
|
192
|
-
hiddenCells,
|
|
193
|
-
hiddenCellOriginMap
|
|
194
|
-
}
|
|
186
|
+
rowSpanning
|
|
195
187
|
});
|
|
196
188
|
};
|
|
197
189
|
exports.rowSpanningStateInitializer = rowSpanningStateInitializer;
|
|
198
190
|
const useGridRowSpanning = (apiRef, props) => {
|
|
199
|
-
const
|
|
200
|
-
return apiRef.current.state.rowSpanning !== EMPTY_STATE ? getInitialRangeToProcess(props, apiRef) : EMPTY_RANGE;
|
|
201
|
-
});
|
|
191
|
+
const store = apiRef.current.virtualizer.store;
|
|
202
192
|
const updateRowSpanningState = React.useCallback((renderContext, resetState = false) => {
|
|
203
193
|
const {
|
|
204
194
|
range,
|
|
205
195
|
rows: visibleRows
|
|
206
|
-
} = (0, _useGridVisibleRows.getVisibleRows)(apiRef
|
|
207
|
-
pagination: props.pagination,
|
|
208
|
-
paginationMode: props.paginationMode
|
|
209
|
-
});
|
|
196
|
+
} = (0, _useGridVisibleRows.getVisibleRows)(apiRef);
|
|
210
197
|
if (range === null || !(0, _gridRowSpanningUtils.isRowContextInitialized)(renderContext)) {
|
|
211
198
|
return;
|
|
212
199
|
}
|
|
213
|
-
|
|
214
|
-
processedRange.current = EMPTY_RANGE;
|
|
215
|
-
}
|
|
200
|
+
const previousState = resetState ? EMPTY_STATE : _features.Rowspan.selectors.state(store.state);
|
|
216
201
|
const rangeToProcess = (0, _gridRowSpanningUtils.getUnprocessedRange)({
|
|
217
202
|
firstRowIndex: renderContext.firstRowIndex,
|
|
218
|
-
lastRowIndex: Math.min(renderContext.lastRowIndex, range.lastRowIndex + 1)
|
|
219
|
-
}, processedRange
|
|
203
|
+
lastRowIndex: Math.min(renderContext.lastRowIndex, range.lastRowIndex - range.firstRowIndex + 1)
|
|
204
|
+
}, previousState.processedRange);
|
|
220
205
|
if (rangeToProcess === null) {
|
|
221
206
|
return;
|
|
222
207
|
}
|
|
223
208
|
const colDefs = (0, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector)(apiRef);
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const newSpannedCellsCount = Object.keys(spannedCells).length;
|
|
232
|
-
const newHiddenCellsCount = Object.keys(hiddenCells).length;
|
|
233
|
-
const currentSpannedCellsCount = Object.keys(apiRef.current.state.rowSpanning.spannedCells).length;
|
|
234
|
-
const currentHiddenCellsCount = Object.keys(apiRef.current.state.rowSpanning.hiddenCells).length;
|
|
235
|
-
const shouldUpdateState = resetState || newSpannedCellsCount !== currentSpannedCellsCount || newHiddenCellsCount !== currentHiddenCellsCount;
|
|
236
|
-
const hasNoSpannedCells = newSpannedCellsCount === 0 && currentSpannedCellsCount === 0;
|
|
209
|
+
const newState = computeRowSpanningState(apiRef, colDefs, visibleRows, range, rangeToProcess, resetState);
|
|
210
|
+
const newSpannedCellsCount = Object.keys(newState.caches.spannedCells).length;
|
|
211
|
+
const newHiddenCellsCount = Object.keys(newState.caches.hiddenCells).length;
|
|
212
|
+
const previousSpannedCellsCount = Object.keys(previousState.caches.spannedCells).length;
|
|
213
|
+
const previousHiddenCellsCount = Object.keys(previousState.caches.hiddenCells).length;
|
|
214
|
+
const shouldUpdateState = resetState || newSpannedCellsCount !== previousSpannedCellsCount || newHiddenCellsCount !== previousHiddenCellsCount;
|
|
215
|
+
const hasNoSpannedCells = newSpannedCellsCount === 0 && previousSpannedCellsCount === 0;
|
|
237
216
|
if (!shouldUpdateState || hasNoSpannedCells) {
|
|
238
217
|
return;
|
|
239
218
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
rowSpanning: {
|
|
243
|
-
spannedCells,
|
|
244
|
-
hiddenCells,
|
|
245
|
-
hiddenCellOriginMap
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
}, [apiRef, processedRange, props.pagination, props.paginationMode]);
|
|
219
|
+
store.set('rowSpanning', newState);
|
|
220
|
+
}, [apiRef, store]);
|
|
250
221
|
|
|
251
222
|
// Reset events trigger a full re-computation of the row spanning state:
|
|
252
223
|
// - The `unstable_rowSpanning` prop is updated (feature flag)
|
|
@@ -268,14 +239,12 @@ const useGridRowSpanning = (apiRef, props) => {
|
|
|
268
239
|
(0, _useGridEvent.useGridEvent)(apiRef, 'columnsChange', (0, _utils.runIf)(props.rowSpanning, resetRowSpanningState));
|
|
269
240
|
React.useEffect(() => {
|
|
270
241
|
if (!props.rowSpanning) {
|
|
271
|
-
if (
|
|
272
|
-
|
|
273
|
-
rowSpanning: EMPTY_STATE
|
|
274
|
-
}));
|
|
242
|
+
if (store.state.rowSpanning !== EMPTY_STATE) {
|
|
243
|
+
store.set('rowSpanning', EMPTY_STATE);
|
|
275
244
|
}
|
|
276
|
-
} else if (
|
|
245
|
+
} else if (store.state.rowSpanning.caches === EMPTY_CACHES) {
|
|
277
246
|
resetRowSpanningState();
|
|
278
247
|
}
|
|
279
|
-
}, [apiRef, resetRowSpanningState, props.rowSpanning]);
|
|
248
|
+
}, [apiRef, store, resetRowSpanningState, props.rowSpanning]);
|
|
280
249
|
};
|
|
281
250
|
exports.useGridRowSpanning = useGridRowSpanning;
|
|
@@ -206,7 +206,8 @@ const useGridRows = (apiRef, props) => {
|
|
|
206
206
|
skipAutoGeneratedRows = true,
|
|
207
207
|
groupId,
|
|
208
208
|
applySorting,
|
|
209
|
-
applyFiltering
|
|
209
|
+
applyFiltering,
|
|
210
|
+
directChildrenOnly = false
|
|
210
211
|
}) => {
|
|
211
212
|
const tree = (0, _gridRowsSelector.gridRowTreeSelector)(apiRef);
|
|
212
213
|
let children;
|
|
@@ -218,14 +219,14 @@ const useGridRows = (apiRef, props) => {
|
|
|
218
219
|
const sortedRowIds = (0, _gridSortingSelector.gridSortedRowIdsSelector)(apiRef);
|
|
219
220
|
children = [];
|
|
220
221
|
const startIndex = sortedRowIds.findIndex(id => id === groupId) + 1;
|
|
221
|
-
for (let index = startIndex; index < sortedRowIds.length && tree[sortedRowIds[index]].depth > groupNode.depth; index += 1) {
|
|
222
|
+
for (let index = startIndex; index < sortedRowIds.length && (directChildrenOnly ? tree[sortedRowIds[index]].depth === groupNode.depth + 1 : tree[sortedRowIds[index]].depth > groupNode.depth); index += 1) {
|
|
222
223
|
const id = sortedRowIds[index];
|
|
223
224
|
if (!skipAutoGeneratedRows || !(0, _gridRowsUtils.isAutogeneratedRowNode)(tree[id])) {
|
|
224
225
|
children.push(id);
|
|
225
226
|
}
|
|
226
227
|
}
|
|
227
228
|
} else {
|
|
228
|
-
children = (0, _gridRowsUtils.getTreeNodeDescendants)(tree, groupId, skipAutoGeneratedRows);
|
|
229
|
+
children = (0, _gridRowsUtils.getTreeNodeDescendants)(tree, groupId, skipAutoGeneratedRows, directChildrenOnly);
|
|
229
230
|
}
|
|
230
231
|
if (applyFiltering) {
|
|
231
232
|
const filteredRowsLookup = (0, _gridFilterSelector.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,33 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.useGridRowsMeta = exports.rowsMetaStateInitializer = void 0;
|
|
9
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
-
var React = _interopRequireWildcard(require("react"));
|
|
11
|
-
var _useLazyRef = _interopRequireDefault(require("@mui/utils/useLazyRef"));
|
|
12
|
-
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
|
|
13
|
-
var _ResizeObserver = require("../../../utils/ResizeObserver");
|
|
14
|
-
var _useGridVisibleRows = require("../../utils/useGridVisibleRows");
|
|
15
|
-
var _utils = require("../../../utils/utils");
|
|
16
9
|
var _useGridApiMethod = require("../../utils/useGridApiMethod");
|
|
17
|
-
var _useGridSelector = require("../../utils/useGridSelector");
|
|
18
|
-
var _densitySelector = require("../density/densitySelector");
|
|
19
10
|
var _gridPaginationSelector = require("../pagination/gridPaginationSelector");
|
|
20
11
|
var _pipeProcessing = require("../../core/pipeProcessing");
|
|
21
12
|
var _gridRowsSelector = require("./gridRowsSelector");
|
|
22
13
|
var _gridDimensionsSelectors = require("../dimensions/gridDimensionsSelectors");
|
|
23
|
-
var _gridRowsUtils = require("./gridRowsUtils");
|
|
24
|
-
var _gridFocusedVirtualCellSelector = require("../virtualization/gridFocusedVirtualCellSelector");
|
|
25
|
-
/* eslint-disable no-underscore-dangle */
|
|
26
|
-
|
|
27
14
|
const rowsMetaStateInitializer = (state, props, apiRef) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
// FIXME: This should be handled in the virtualizer eventually, but there are interdependencies
|
|
16
|
+
// between state initializers that need to be untangled carefully.
|
|
17
|
+
|
|
31
18
|
const baseRowHeight = (0, _gridDimensionsSelectors.gridRowHeightSelector)(apiRef);
|
|
32
19
|
const dataRowCount = (0, _gridRowsSelector.gridRowCountSelector)(apiRef);
|
|
33
20
|
const pagination = (0, _gridPaginationSelector.gridPaginationSelector)(apiRef);
|
|
@@ -49,178 +36,20 @@ const rowsMetaStateInitializer = (state, props, apiRef) => {
|
|
|
49
36
|
* @requires useGridPage (method)
|
|
50
37
|
*/
|
|
51
38
|
exports.rowsMetaStateInitializer = rowsMetaStateInitializer;
|
|
52
|
-
const useGridRowsMeta = (apiRef,
|
|
39
|
+
const useGridRowsMeta = (apiRef, _props) => {
|
|
40
|
+
const virtualizer = apiRef.current.virtualizer;
|
|
53
41
|
const {
|
|
54
|
-
getRowHeight
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const pinnedRows = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowsSelector.gridPinnedRowsSelector);
|
|
65
|
-
const rowHeight = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridRowHeightSelector);
|
|
66
|
-
const getRowHeightEntry = rowId => {
|
|
67
|
-
let entry = heightCache.get(rowId);
|
|
68
|
-
if (entry === undefined) {
|
|
69
|
-
entry = {
|
|
70
|
-
content: rowHeight,
|
|
71
|
-
spacingTop: 0,
|
|
72
|
-
spacingBottom: 0,
|
|
73
|
-
detail: 0,
|
|
74
|
-
autoHeight: false,
|
|
75
|
-
needsFirstMeasurement: true
|
|
76
|
-
};
|
|
77
|
-
heightCache.set(rowId, entry);
|
|
78
|
-
}
|
|
79
|
-
return entry;
|
|
80
|
-
};
|
|
81
|
-
const processHeightEntry = React.useCallback(row => {
|
|
82
|
-
// HACK: rowHeight trails behind the most up-to-date value just enough to
|
|
83
|
-
// mess the initial rowsMeta hydration :/
|
|
84
|
-
const baseRowHeight = (0, _gridDimensionsSelectors.gridDimensionsSelector)(apiRef).rowHeight;
|
|
85
|
-
(0, _utils.eslintUseValue)(rowHeight);
|
|
86
|
-
const entry = apiRef.current.getRowHeightEntry(row.id);
|
|
87
|
-
if (!getRowHeightProp) {
|
|
88
|
-
entry.content = baseRowHeight;
|
|
89
|
-
entry.needsFirstMeasurement = false;
|
|
90
|
-
} else {
|
|
91
|
-
const rowHeightFromUser = getRowHeightProp((0, _extends2.default)({}, row, {
|
|
92
|
-
densityFactor
|
|
93
|
-
}));
|
|
94
|
-
if (rowHeightFromUser === 'auto') {
|
|
95
|
-
if (entry.needsFirstMeasurement) {
|
|
96
|
-
const estimatedRowHeight = getEstimatedRowHeight ? getEstimatedRowHeight((0, _extends2.default)({}, row, {
|
|
97
|
-
densityFactor
|
|
98
|
-
})) : baseRowHeight;
|
|
99
|
-
|
|
100
|
-
// If the row was not measured yet use the estimated row height
|
|
101
|
-
entry.content = estimatedRowHeight ?? baseRowHeight;
|
|
102
|
-
}
|
|
103
|
-
hasRowWithAutoHeight.current = true;
|
|
104
|
-
entry.autoHeight = true;
|
|
105
|
-
} else {
|
|
106
|
-
// Default back to base rowHeight if getRowHeight returns invalid value.
|
|
107
|
-
entry.content = (0, _gridRowsUtils.getValidRowHeight)(rowHeightFromUser, baseRowHeight, _gridRowsUtils.getRowHeightWarning);
|
|
108
|
-
entry.needsFirstMeasurement = false;
|
|
109
|
-
entry.autoHeight = false;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (getRowSpacing) {
|
|
113
|
-
const indexRelativeToCurrentPage = apiRef.current.getRowIndexRelativeToVisibleRows(row.id);
|
|
114
|
-
const spacing = getRowSpacing((0, _extends2.default)({}, row, {
|
|
115
|
-
isFirstVisible: indexRelativeToCurrentPage === 0,
|
|
116
|
-
isLastVisible: indexRelativeToCurrentPage === currentPage.rows.length - 1,
|
|
117
|
-
indexRelativeToCurrentPage
|
|
118
|
-
}));
|
|
119
|
-
entry.spacingTop = spacing.top ?? 0;
|
|
120
|
-
entry.spacingBottom = spacing.bottom ?? 0;
|
|
121
|
-
} else {
|
|
122
|
-
entry.spacingTop = 0;
|
|
123
|
-
entry.spacingBottom = 0;
|
|
124
|
-
}
|
|
125
|
-
apiRef.current.unstable_applyPipeProcessors('rowHeight', entry, row);
|
|
126
|
-
return entry;
|
|
127
|
-
}, [apiRef, currentPage.rows, getRowHeightProp, getEstimatedRowHeight, rowHeight, getRowSpacing, densityFactor]);
|
|
128
|
-
const hydrateRowsMeta = React.useCallback(() => {
|
|
129
|
-
hasRowWithAutoHeight.current = false;
|
|
130
|
-
const pinnedTopRowsTotalHeight = pinnedRows.top.reduce((acc, row) => {
|
|
131
|
-
const entry = processHeightEntry(row);
|
|
132
|
-
return acc + entry.content + entry.spacingTop + entry.spacingBottom + entry.detail;
|
|
133
|
-
}, 0);
|
|
134
|
-
const pinnedBottomRowsTotalHeight = pinnedRows.bottom.reduce((acc, row) => {
|
|
135
|
-
const entry = processHeightEntry(row);
|
|
136
|
-
return acc + entry.content + entry.spacingTop + entry.spacingBottom + entry.detail;
|
|
137
|
-
}, 0);
|
|
138
|
-
const positions = [];
|
|
139
|
-
const currentPageTotalHeight = currentPage.rows.reduce((acc, row) => {
|
|
140
|
-
positions.push(acc);
|
|
141
|
-
const entry = processHeightEntry(row);
|
|
142
|
-
const total = entry.content + entry.spacingTop + entry.spacingBottom + entry.detail;
|
|
143
|
-
return acc + total;
|
|
144
|
-
}, 0);
|
|
145
|
-
if (!hasRowWithAutoHeight.current) {
|
|
146
|
-
// No row has height=auto, so all rows are already measured
|
|
147
|
-
lastMeasuredRowIndex.current = Infinity;
|
|
148
|
-
}
|
|
149
|
-
const didHeightsChange = pinnedTopRowsTotalHeight !== apiRef.current.state.rowsMeta.pinnedTopRowsTotalHeight || pinnedBottomRowsTotalHeight !== apiRef.current.state.rowsMeta.pinnedBottomRowsTotalHeight || currentPageTotalHeight !== apiRef.current.state.rowsMeta.currentPageTotalHeight;
|
|
150
|
-
const rowsMeta = {
|
|
151
|
-
currentPageTotalHeight,
|
|
152
|
-
positions,
|
|
153
|
-
pinnedTopRowsTotalHeight,
|
|
154
|
-
pinnedBottomRowsTotalHeight
|
|
155
|
-
};
|
|
156
|
-
apiRef.current.setState(state => {
|
|
157
|
-
return (0, _extends2.default)({}, state, {
|
|
158
|
-
rowsMeta
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
if (didHeightsChange) {
|
|
162
|
-
apiRef.current.updateDimensions();
|
|
163
|
-
}
|
|
164
|
-
isHeightMetaValid.current = true;
|
|
165
|
-
}, [apiRef, pinnedRows, currentPage.rows, processHeightEntry]);
|
|
166
|
-
const getRowHeight = rowId => {
|
|
167
|
-
return heightCache.get(rowId)?.content ?? rowHeight;
|
|
168
|
-
};
|
|
169
|
-
const storeRowHeightMeasurement = (id, height) => {
|
|
170
|
-
const entry = apiRef.current.getRowHeightEntry(id);
|
|
171
|
-
const didChange = entry.content !== height;
|
|
172
|
-
entry.needsFirstMeasurement = false;
|
|
173
|
-
entry.content = height;
|
|
174
|
-
isHeightMetaValid.current && (isHeightMetaValid.current = !didChange);
|
|
175
|
-
};
|
|
176
|
-
const rowHasAutoHeight = id => {
|
|
177
|
-
return heightCache.get(id)?.autoHeight ?? false;
|
|
178
|
-
};
|
|
179
|
-
const getLastMeasuredRowIndex = () => {
|
|
180
|
-
return lastMeasuredRowIndex.current;
|
|
181
|
-
};
|
|
182
|
-
const setLastMeasuredRowIndex = index => {
|
|
183
|
-
if (hasRowWithAutoHeight.current && index > lastMeasuredRowIndex.current) {
|
|
184
|
-
lastMeasuredRowIndex.current = index;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
const resetRowHeights = () => {
|
|
188
|
-
heightCache.clear();
|
|
189
|
-
hydrateRowsMeta();
|
|
190
|
-
};
|
|
191
|
-
const resizeObserver = (0, _useLazyRef.default)(() => new _ResizeObserver.ResizeObserver(entries => {
|
|
192
|
-
for (let i = 0; i < entries.length; i += 1) {
|
|
193
|
-
const entry = entries[i];
|
|
194
|
-
const height = entry.borderBoxSize && entry.borderBoxSize.length > 0 ? entry.borderBoxSize[0].blockSize : entry.contentRect.height;
|
|
195
|
-
const rowId = entry.target.__mui_id;
|
|
196
|
-
const focusedVirtualRowId = (0, _gridFocusedVirtualCellSelector.gridFocusedVirtualCellSelector)(apiRef)?.id;
|
|
197
|
-
if (focusedVirtualRowId === rowId && height === 0) {
|
|
198
|
-
// Focused virtual row has 0 height.
|
|
199
|
-
// We don't want to store it to avoid scroll jumping.
|
|
200
|
-
// https://github.com/mui/mui-x/issues/14726
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
apiRef.current.unstable_storeRowHeightMeasurement(rowId, height);
|
|
204
|
-
}
|
|
205
|
-
if (!isHeightMetaValid.current) {
|
|
206
|
-
// Avoids "ResizeObserver loop completed with undelivered notifications" error
|
|
207
|
-
requestAnimationFrame(() => {
|
|
208
|
-
apiRef.current.requestPipeProcessorsApplication('rowHeight');
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
})).current;
|
|
212
|
-
const observeRowHeight = (element, rowId) => {
|
|
213
|
-
element.__mui_id = rowId;
|
|
214
|
-
resizeObserver.observe(element);
|
|
215
|
-
return () => resizeObserver.unobserve(element);
|
|
216
|
-
};
|
|
42
|
+
getRowHeight,
|
|
43
|
+
setLastMeasuredRowIndex,
|
|
44
|
+
storeRowHeightMeasurement,
|
|
45
|
+
resetRowHeights,
|
|
46
|
+
hydrateRowsMeta,
|
|
47
|
+
observeRowHeight,
|
|
48
|
+
rowHasAutoHeight,
|
|
49
|
+
getRowHeightEntry,
|
|
50
|
+
getLastMeasuredRowIndex
|
|
51
|
+
} = virtualizer.api.rowsMeta;
|
|
217
52
|
(0, _pipeProcessing.useGridRegisterPipeApplier)(apiRef, 'rowHeight', hydrateRowsMeta);
|
|
218
|
-
|
|
219
|
-
// The effect is used to build the rows meta data - currentPageTotalHeight and positions.
|
|
220
|
-
// Because of variable row height this is needed for the virtualization
|
|
221
|
-
(0, _useEnhancedEffect.default)(() => {
|
|
222
|
-
hydrateRowsMeta();
|
|
223
|
-
}, [hydrateRowsMeta]);
|
|
224
53
|
const rowsMetaApi = {
|
|
225
54
|
unstable_getRowHeight: getRowHeight,
|
|
226
55
|
unstable_setLastMeasuredRowIndex: setLastMeasuredRowIndex,
|