@mui/x-data-grid 7.24.1 → 7.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +148 -0
- package/DataGrid/DataGrid.js +1 -7
- package/DataGrid/useDataGridComponent.js +2 -2
- package/components/GridRow.d.ts +0 -1
- package/components/GridRow.js +32 -20
- package/components/GridScrollArea.d.ts +5 -2
- package/components/GridScrollArea.js +32 -25
- package/components/GridSkeletonLoadingOverlay.js +2 -1
- package/components/cell/GridCell.d.ts +9 -6
- package/components/cell/GridCell.js +29 -52
- package/components/containers/GridRoot.js +11 -9
- package/components/containers/GridRootStyles.js +138 -40
- package/components/toolbar/GridToolbarColumnsButton.js +5 -4
- package/components/toolbar/GridToolbarDensitySelector.js +2 -2
- package/components/toolbar/GridToolbarExportContainer.js +2 -2
- package/components/toolbar/GridToolbarFilterButton.js +4 -3
- package/components/virtualization/GridMainContainer.d.ts +10 -0
- package/components/virtualization/GridMainContainer.js +10 -2
- package/components/virtualization/GridVirtualScrollbar.d.ts +4 -0
- package/components/virtualization/GridVirtualScrollbar.js +5 -5
- package/components/virtualization/GridVirtualScroller.js +36 -16
- package/components/virtualization/GridVirtualScrollerContent.js +11 -2
- package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.d.ts +1 -1
- package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +6 -4
- package/hooks/core/useGridStateInitialization.js +3 -2
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +10 -14
- package/hooks/features/columnResize/useGridColumnResize.js +2 -1
- package/hooks/features/columns/gridColumnsSelector.d.ts +0 -5
- package/hooks/features/columns/gridColumnsSelector.js +0 -12
- package/hooks/features/columns/useGridColumns.js +7 -3
- package/hooks/features/dimensions/gridDimensionsSelectors.d.ts +16 -0
- package/hooks/features/dimensions/gridDimensionsSelectors.js +26 -1
- package/hooks/features/dimensions/index.d.ts +1 -1
- package/hooks/features/dimensions/index.js +1 -2
- package/hooks/features/dimensions/useGridDimensions.js +102 -77
- package/hooks/features/editing/gridEditingSelectors.d.ts +10 -0
- package/hooks/features/editing/gridEditingSelectors.js +12 -1
- package/hooks/features/editing/index.d.ts +1 -1
- package/hooks/features/editing/index.js +1 -1
- package/hooks/features/editing/useGridCellEditing.js +3 -3
- package/hooks/features/editing/useGridRowEditing.js +8 -9
- package/hooks/features/filter/gridFilterState.d.ts +5 -0
- package/hooks/features/filter/gridFilterState.js +5 -0
- package/hooks/features/filter/useGridFilter.js +6 -13
- package/hooks/features/focus/useGridFocus.js +3 -2
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +24 -16
- package/hooks/features/keyboardNavigation/utils.d.ts +1 -2
- package/hooks/features/keyboardNavigation/utils.js +0 -5
- package/hooks/features/listView/useGridListView.js +2 -1
- package/hooks/features/pagination/useGridPagination.js +1 -1
- package/hooks/features/rowSelection/useGridRowSelection.js +4 -4
- package/hooks/features/rowSelection/utils.js +1 -1
- package/hooks/features/rows/gridRowsMetaState.d.ts +8 -0
- package/hooks/features/rows/gridRowsUtils.d.ts +0 -4
- package/hooks/features/rows/gridRowsUtils.js +0 -16
- package/hooks/features/rows/useGridParamsApi.d.ts +1 -1
- package/hooks/features/rows/useGridParamsApi.js +33 -14
- package/hooks/features/rows/useGridRowSpanning.js +94 -91
- package/hooks/features/rows/useGridRows.js +7 -8
- package/hooks/features/rows/useGridRowsMeta.js +36 -19
- package/hooks/features/sorting/gridSortingSelector.js +10 -9
- package/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +15 -1
- package/hooks/features/virtualization/useGridVirtualScroller.js +74 -72
- package/hooks/utils/useGridSelector.d.ts +8 -1
- package/hooks/utils/useGridSelector.js +42 -8
- package/hooks/utils/useIsSSR.d.ts +1 -0
- package/hooks/utils/useIsSSR.js +5 -0
- package/index.js +1 -1
- package/internals/index.d.ts +2 -1
- package/internals/index.js +2 -1
- package/models/api/gridApiCommon.d.ts +2 -2
- package/models/api/gridParamsApi.d.ts +29 -2
- package/models/api/gridStateApi.d.ts +1 -0
- package/models/api/index.d.ts +1 -1
- package/models/api/index.js +0 -1
- package/models/events/gridEventLookup.d.ts +6 -0
- package/modern/DataGrid/DataGrid.js +1 -7
- package/modern/DataGrid/useDataGridComponent.js +2 -2
- package/modern/components/GridRow.js +32 -20
- package/modern/components/GridScrollArea.js +32 -25
- package/modern/components/GridSkeletonLoadingOverlay.js +2 -1
- package/modern/components/cell/GridCell.js +29 -52
- package/modern/components/containers/GridRoot.js +11 -9
- package/modern/components/containers/GridRootStyles.js +138 -40
- package/modern/components/toolbar/GridToolbarColumnsButton.js +5 -4
- package/modern/components/toolbar/GridToolbarDensitySelector.js +2 -2
- package/modern/components/toolbar/GridToolbarExportContainer.js +2 -2
- package/modern/components/toolbar/GridToolbarFilterButton.js +4 -3
- package/modern/components/virtualization/GridMainContainer.js +10 -2
- package/modern/components/virtualization/GridVirtualScrollbar.js +5 -5
- package/modern/components/virtualization/GridVirtualScroller.js +36 -16
- package/modern/components/virtualization/GridVirtualScrollerContent.js +11 -2
- package/modern/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +6 -4
- package/modern/hooks/core/useGridStateInitialization.js +3 -2
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +10 -14
- package/modern/hooks/features/columnResize/useGridColumnResize.js +2 -1
- package/modern/hooks/features/columns/gridColumnsSelector.js +0 -12
- package/modern/hooks/features/columns/useGridColumns.js +7 -3
- package/modern/hooks/features/dimensions/gridDimensionsSelectors.js +26 -1
- package/modern/hooks/features/dimensions/index.js +1 -2
- package/modern/hooks/features/dimensions/useGridDimensions.js +102 -77
- package/modern/hooks/features/editing/gridEditingSelectors.js +12 -1
- package/modern/hooks/features/editing/index.js +1 -1
- package/modern/hooks/features/editing/useGridCellEditing.js +3 -3
- package/modern/hooks/features/editing/useGridRowEditing.js +8 -9
- package/modern/hooks/features/filter/gridFilterState.js +5 -0
- package/modern/hooks/features/filter/useGridFilter.js +6 -13
- package/modern/hooks/features/focus/useGridFocus.js +3 -2
- package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +24 -16
- package/modern/hooks/features/keyboardNavigation/utils.js +0 -5
- package/modern/hooks/features/listView/useGridListView.js +2 -1
- package/modern/hooks/features/pagination/useGridPagination.js +1 -1
- package/modern/hooks/features/rowSelection/useGridRowSelection.js +4 -4
- package/modern/hooks/features/rowSelection/utils.js +1 -1
- package/modern/hooks/features/rows/gridRowsUtils.js +0 -16
- package/modern/hooks/features/rows/useGridParamsApi.js +33 -14
- package/modern/hooks/features/rows/useGridRowSpanning.js +94 -91
- package/modern/hooks/features/rows/useGridRows.js +7 -8
- package/modern/hooks/features/rows/useGridRowsMeta.js +36 -19
- package/modern/hooks/features/sorting/gridSortingSelector.js +10 -9
- package/modern/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +74 -72
- package/modern/hooks/utils/useGridSelector.js +42 -8
- package/modern/hooks/utils/useIsSSR.js +5 -0
- package/modern/index.js +1 -1
- package/modern/internals/index.js +2 -1
- package/modern/models/api/index.js +0 -1
- package/modern/utils/roundToDecimalPlaces.js +3 -0
- package/modern/utils/utils.js +6 -1
- package/node/DataGrid/DataGrid.js +1 -7
- package/node/DataGrid/useDataGridComponent.js +2 -2
- package/node/components/GridRow.js +28 -17
- package/node/components/GridScrollArea.js +31 -24
- package/node/components/GridSkeletonLoadingOverlay.js +2 -1
- package/node/components/cell/GridCell.js +27 -50
- package/node/components/containers/GridRoot.js +10 -8
- package/node/components/containers/GridRootStyles.js +138 -40
- package/node/components/toolbar/GridToolbarColumnsButton.js +5 -4
- package/node/components/toolbar/GridToolbarDensitySelector.js +2 -2
- package/node/components/toolbar/GridToolbarExportContainer.js +2 -2
- package/node/components/toolbar/GridToolbarFilterButton.js +4 -3
- package/node/components/virtualization/GridMainContainer.js +10 -2
- package/node/components/virtualization/GridVirtualScrollbar.js +5 -5
- package/node/components/virtualization/GridVirtualScroller.js +36 -16
- package/node/components/virtualization/GridVirtualScrollerContent.js +11 -2
- package/node/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +6 -4
- package/node/hooks/core/useGridStateInitialization.js +3 -2
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +10 -14
- package/node/hooks/features/columnResize/useGridColumnResize.js +2 -1
- package/node/hooks/features/columns/gridColumnsSelector.js +1 -13
- package/node/hooks/features/columns/useGridColumns.js +7 -3
- package/node/hooks/features/dimensions/gridDimensionsSelectors.js +38 -2
- package/node/hooks/features/dimensions/index.js +13 -11
- package/node/hooks/features/dimensions/useGridDimensions.js +99 -74
- package/node/hooks/features/editing/gridEditingSelectors.js +12 -2
- package/node/hooks/features/editing/index.js +7 -11
- package/node/hooks/features/editing/useGridCellEditing.js +2 -2
- package/node/hooks/features/editing/useGridRowEditing.js +6 -7
- package/node/hooks/features/filter/gridFilterState.js +6 -1
- package/node/hooks/features/filter/useGridFilter.js +5 -12
- package/node/hooks/features/focus/useGridFocus.js +3 -2
- package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +24 -15
- package/node/hooks/features/keyboardNavigation/utils.js +0 -6
- package/node/hooks/features/listView/useGridListView.js +2 -1
- package/node/hooks/features/pagination/useGridPagination.js +1 -1
- package/node/hooks/features/rowSelection/useGridRowSelection.js +3 -3
- package/node/hooks/features/rowSelection/utils.js +1 -1
- package/node/hooks/features/rows/gridRowsUtils.js +0 -17
- package/node/hooks/features/rows/useGridParamsApi.js +33 -14
- package/node/hooks/features/rows/useGridRowSpanning.js +92 -89
- package/node/hooks/features/rows/useGridRows.js +7 -8
- package/node/hooks/features/rows/useGridRowsMeta.js +36 -19
- package/node/hooks/features/sorting/gridSortingSelector.js +10 -9
- package/node/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +73 -71
- package/node/hooks/utils/useGridSelector.js +42 -8
- package/node/hooks/utils/useIsSSR.js +12 -0
- package/node/index.js +1 -1
- package/node/internals/index.js +20 -7
- package/node/models/api/index.js +0 -11
- package/node/utils/roundToDecimalPlaces.js +9 -0
- package/node/utils/utils.js +8 -1
- package/package.json +3 -2
- package/utils/roundToDecimalPlaces.d.ts +1 -0
- package/utils/roundToDecimalPlaces.js +3 -0
- package/utils/utils.d.ts +1 -0
- package/utils/utils.js +6 -1
|
@@ -2,20 +2,23 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { unstable_ownerDocument as ownerDocument, unstable_useEnhancedEffect as useEnhancedEffect, unstable_useEventCallback as useEventCallback, unstable_ownerWindow as ownerWindow } from '@mui/utils';
|
|
4
4
|
import { throttle } from '@mui/x-internals/throttle';
|
|
5
|
-
import {
|
|
5
|
+
import { useGridApiOptionHandler } from "../../utils/useGridApiEventHandler.js";
|
|
6
6
|
import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
|
|
7
|
+
import { createSelector } from "../../../utils/createSelector.js";
|
|
7
8
|
import { useGridLogger } from "../../utils/useGridLogger.js";
|
|
8
|
-
import {
|
|
9
|
+
import { gridColumnPositionsSelector, gridVisibleColumnDefinitionsSelector, gridVisiblePinnedColumnDefinitionsSelector } from "../columns/index.js";
|
|
9
10
|
import { gridDimensionsSelector } from "./gridDimensionsSelectors.js";
|
|
10
11
|
import { gridDensityFactorSelector } from "../density/index.js";
|
|
11
12
|
import { gridRenderContextSelector } from "../virtualization/index.js";
|
|
12
13
|
import { useGridSelector } from "../../utils/index.js";
|
|
13
14
|
import { getVisibleRows } from "../../utils/useGridVisibleRows.js";
|
|
14
15
|
import { gridRowsMetaSelector } from "../rows/gridRowsMetaSelector.js";
|
|
15
|
-
import {
|
|
16
|
+
import { getValidRowHeight, rowHeightWarning } from "../rows/gridRowsUtils.js";
|
|
16
17
|
import { getTotalHeaderHeight } from "../columns/gridColumnsUtils.js";
|
|
17
18
|
import { DATA_GRID_PROPS_DEFAULT_VALUES } from "../../../constants/dataGridPropsDefaultValues.js";
|
|
19
|
+
import { roundToDecimalPlaces } from "../../../utils/roundToDecimalPlaces.js";
|
|
18
20
|
import { isJSDOM } from "../../../utils/isJSDOM.js";
|
|
21
|
+
import { isDeepEqual } from "../../../utils/utils.js";
|
|
19
22
|
const EMPTY_SIZE = {
|
|
20
23
|
width: 0,
|
|
21
24
|
height: 0
|
|
@@ -42,39 +45,47 @@ const EMPTY_DIMENSIONS = {
|
|
|
42
45
|
topContainerHeight: 0,
|
|
43
46
|
bottomContainerHeight: 0
|
|
44
47
|
};
|
|
45
|
-
export const dimensionsStateInitializer = state => {
|
|
48
|
+
export const dimensionsStateInitializer = (state, props, apiRef) => {
|
|
46
49
|
const dimensions = EMPTY_DIMENSIONS;
|
|
50
|
+
const density = gridDensityFactorSelector(apiRef);
|
|
47
51
|
return _extends({}, state, {
|
|
48
|
-
dimensions
|
|
52
|
+
dimensions: _extends({}, dimensions, getStaticDimensions(props, apiRef, density, gridVisiblePinnedColumnDefinitionsSelector(apiRef)))
|
|
49
53
|
});
|
|
50
54
|
};
|
|
55
|
+
const columnsTotalWidthSelector = createSelector(gridVisibleColumnDefinitionsSelector, gridColumnPositionsSelector, (visibleColumns, positions) => {
|
|
56
|
+
const colCount = visibleColumns.length;
|
|
57
|
+
if (colCount === 0) {
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
return roundToDecimalPlaces(positions[colCount - 1] + visibleColumns[colCount - 1].computedWidth, 1);
|
|
61
|
+
});
|
|
51
62
|
export function useGridDimensions(apiRef, props) {
|
|
52
63
|
const logger = useGridLogger(apiRef, 'useResizeContainer');
|
|
53
64
|
const errorShown = React.useRef(false);
|
|
54
65
|
const rootDimensionsRef = React.useRef(EMPTY_SIZE);
|
|
55
|
-
const dimensionsState = useGridSelector(apiRef, gridDimensionsSelector);
|
|
56
|
-
const rowsMeta = useGridSelector(apiRef, gridRowsMetaSelector);
|
|
57
66
|
const pinnedColumns = useGridSelector(apiRef, gridVisiblePinnedColumnDefinitionsSelector);
|
|
58
67
|
const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
React.useEffect(() => debouncedSetSavedSize.clear, [debouncedSetSavedSize]);
|
|
68
|
+
const columnsTotalWidth = useGridSelector(apiRef, columnsTotalWidthSelector);
|
|
69
|
+
const isFirstSizing = React.useRef(true);
|
|
70
|
+
const {
|
|
71
|
+
rowHeight,
|
|
72
|
+
headerHeight,
|
|
73
|
+
groupHeaderHeight,
|
|
74
|
+
headerFilterHeight,
|
|
75
|
+
headersTotalHeight,
|
|
76
|
+
leftPinnedWidth,
|
|
77
|
+
rightPinnedWidth
|
|
78
|
+
} = getStaticDimensions(props, apiRef, densityFactor, pinnedColumns);
|
|
71
79
|
const previousSize = React.useRef(undefined);
|
|
72
|
-
const getRootDimensions = () => apiRef.current.state
|
|
73
|
-
const setDimensions =
|
|
80
|
+
const getRootDimensions = React.useCallback(() => gridDimensionsSelector(apiRef.current.state), [apiRef]);
|
|
81
|
+
const setDimensions = React.useCallback(dimensions => {
|
|
74
82
|
apiRef.current.setState(state => _extends({}, state, {
|
|
75
83
|
dimensions
|
|
76
84
|
}));
|
|
77
|
-
|
|
85
|
+
if (apiRef.current.rootElementRef.current) {
|
|
86
|
+
setCSSVariables(apiRef.current.rootElementRef.current, gridDimensionsSelector(apiRef.current.state));
|
|
87
|
+
}
|
|
88
|
+
}, [apiRef]);
|
|
78
89
|
const resize = React.useCallback(() => {
|
|
79
90
|
const element = apiRef.current.mainElementRef.current;
|
|
80
91
|
if (!element) {
|
|
@@ -95,10 +106,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
95
106
|
if (!dimensions.isReady) {
|
|
96
107
|
return 0;
|
|
97
108
|
}
|
|
98
|
-
const currentPage = getVisibleRows(apiRef
|
|
99
|
-
pagination: props.pagination,
|
|
100
|
-
paginationMode: props.paginationMode
|
|
101
|
-
});
|
|
109
|
+
const currentPage = getVisibleRows(apiRef);
|
|
102
110
|
|
|
103
111
|
// TODO: Use a combination of scrollTop, dimensions.viewportInnerSize.height and rowsMeta.possitions
|
|
104
112
|
// to find out the maximum number of rows that can fit in the visible part of the grid
|
|
@@ -109,17 +117,23 @@ export function useGridDimensions(apiRef, props) {
|
|
|
109
117
|
}
|
|
110
118
|
const maximumPageSizeWithoutScrollBar = Math.floor(dimensions.viewportInnerSize.height / rowHeight);
|
|
111
119
|
return Math.min(maximumPageSizeWithoutScrollBar, currentPage.rows.length);
|
|
112
|
-
}, [apiRef, props.
|
|
120
|
+
}, [apiRef, props.getRowHeight, rowHeight]);
|
|
113
121
|
const updateDimensions = React.useCallback(() => {
|
|
122
|
+
if (isFirstSizing.current) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
// All the floating point dimensions should be rounded to .1 decimal places to avoid subpixel rendering issues
|
|
126
|
+
// https://github.com/mui/mui-x/issues/9550#issuecomment-1619020477
|
|
127
|
+
// https://github.com/mui/mui-x/issues/15721
|
|
114
128
|
const rootElement = apiRef.current.rootElementRef.current;
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
const topContainerHeight = headersTotalHeight +
|
|
118
|
-
const bottomContainerHeight =
|
|
129
|
+
const scrollbarSize = measureScrollbarSize(rootElement, props.scrollbarSize);
|
|
130
|
+
const rowsMeta = gridRowsMetaSelector(apiRef.current.state);
|
|
131
|
+
const topContainerHeight = headersTotalHeight + rowsMeta.pinnedTopRowsTotalHeight;
|
|
132
|
+
const bottomContainerHeight = rowsMeta.pinnedBottomRowsTotalHeight;
|
|
119
133
|
const nonPinnedColumnsTotalWidth = columnsTotalWidth - leftPinnedWidth - rightPinnedWidth;
|
|
120
134
|
const contentSize = {
|
|
121
135
|
width: nonPinnedColumnsTotalWidth,
|
|
122
|
-
height: rowsMeta.currentPageTotalHeight
|
|
136
|
+
height: roundToDecimalPlaces(rowsMeta.currentPageTotalHeight, 1)
|
|
123
137
|
};
|
|
124
138
|
let viewportOuterSize;
|
|
125
139
|
let viewportInnerSize;
|
|
@@ -193,12 +207,21 @@ export function useGridDimensions(apiRef, props) {
|
|
|
193
207
|
bottomContainerHeight
|
|
194
208
|
};
|
|
195
209
|
const prevDimensions = apiRef.current.state.dimensions;
|
|
210
|
+
if (isDeepEqual(prevDimensions, newDimensions)) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
196
213
|
setDimensions(newDimensions);
|
|
197
214
|
if (!areElementSizesEqual(newDimensions.viewportInnerSize, prevDimensions.viewportInnerSize)) {
|
|
198
215
|
apiRef.current.publishEvent('viewportInnerSizeChange', newDimensions.viewportInnerSize);
|
|
199
216
|
}
|
|
200
217
|
apiRef.current.updateRenderContext?.();
|
|
201
|
-
}, [apiRef, setDimensions, props.scrollbarSize, props.autoHeight,
|
|
218
|
+
}, [apiRef, setDimensions, props.scrollbarSize, props.autoHeight, rowHeight, headerHeight, groupHeaderHeight, headerFilterHeight, columnsTotalWidth, headersTotalHeight, leftPinnedWidth, rightPinnedWidth]);
|
|
219
|
+
const updateDimensionCallback = useEventCallback(updateDimensions);
|
|
220
|
+
const debouncedUpdateDimensions = React.useMemo(() => props.resizeThrottleMs > 0 ? throttle(() => {
|
|
221
|
+
updateDimensionCallback();
|
|
222
|
+
apiRef.current.publishEvent('debouncedResize', rootDimensionsRef.current);
|
|
223
|
+
}, props.resizeThrottleMs) : undefined, [apiRef, props.resizeThrottleMs, updateDimensionCallback]);
|
|
224
|
+
React.useEffect(() => debouncedUpdateDimensions?.clear, [debouncedUpdateDimensions]);
|
|
202
225
|
const apiPublic = {
|
|
203
226
|
resize,
|
|
204
227
|
getRootDimensions
|
|
@@ -207,35 +230,12 @@ export function useGridDimensions(apiRef, props) {
|
|
|
207
230
|
updateDimensions,
|
|
208
231
|
getViewportPageSize
|
|
209
232
|
};
|
|
233
|
+
useEnhancedEffect(updateDimensions, [updateDimensions]);
|
|
210
234
|
useGridApiMethod(apiRef, apiPublic, 'public');
|
|
211
235
|
useGridApiMethod(apiRef, apiPrivate, 'private');
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
apiRef.current.publishEvent('debouncedResize', rootDimensionsRef.current);
|
|
216
|
-
}
|
|
217
|
-
}, [apiRef, savedSize, updateDimensions]);
|
|
218
|
-
const root = apiRef.current.rootElementRef.current;
|
|
219
|
-
useEnhancedEffect(() => {
|
|
220
|
-
if (!root) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const set = (k, v) => root.style.setProperty(k, v);
|
|
224
|
-
set('--DataGrid-width', `${dimensionsState.viewportOuterSize.width}px`);
|
|
225
|
-
set('--DataGrid-hasScrollX', `${Number(dimensionsState.hasScrollX)}`);
|
|
226
|
-
set('--DataGrid-hasScrollY', `${Number(dimensionsState.hasScrollY)}`);
|
|
227
|
-
set('--DataGrid-scrollbarSize', `${dimensionsState.scrollbarSize}px`);
|
|
228
|
-
set('--DataGrid-rowWidth', `${dimensionsState.rowWidth}px`);
|
|
229
|
-
set('--DataGrid-columnsTotalWidth', `${dimensionsState.columnsTotalWidth}px`);
|
|
230
|
-
set('--DataGrid-leftPinnedWidth', `${dimensionsState.leftPinnedWidth}px`);
|
|
231
|
-
set('--DataGrid-rightPinnedWidth', `${dimensionsState.rightPinnedWidth}px`);
|
|
232
|
-
set('--DataGrid-headerHeight', `${dimensionsState.headerHeight}px`);
|
|
233
|
-
set('--DataGrid-headersTotalHeight', `${dimensionsState.headersTotalHeight}px`);
|
|
234
|
-
set('--DataGrid-topContainerHeight', `${dimensionsState.topContainerHeight}px`);
|
|
235
|
-
set('--DataGrid-bottomContainerHeight', `${dimensionsState.bottomContainerHeight}px`);
|
|
236
|
-
set('--height', `${dimensionsState.rowHeight}px`);
|
|
237
|
-
}, [root, dimensionsState]);
|
|
238
|
-
const isFirstSizing = React.useRef(true);
|
|
236
|
+
const handleRootMount = React.useCallback(root => {
|
|
237
|
+
setCSSVariables(root, gridDimensionsSelector(apiRef.current.state));
|
|
238
|
+
}, [apiRef]);
|
|
239
239
|
const handleResize = React.useCallback(size => {
|
|
240
240
|
rootDimensionsRef.current = size;
|
|
241
241
|
if (size.height === 0 && !errorShown.current && !props.autoHeight && !isJSDOM) {
|
|
@@ -246,28 +246,58 @@ export function useGridDimensions(apiRef, props) {
|
|
|
246
246
|
logger.error(['The parent DOM element of the Data Grid has an empty width.', 'Please make sure that this element has an intrinsic width.', 'The grid displays with a width of 0px.', '', 'More details: https://mui.com/r/x-data-grid-no-dimensions.'].join('\n'));
|
|
247
247
|
errorShown.current = true;
|
|
248
248
|
}
|
|
249
|
-
if (isFirstSizing.current) {
|
|
249
|
+
if (isFirstSizing.current || !debouncedUpdateDimensions) {
|
|
250
250
|
// We want to initialize the grid dimensions as soon as possible to avoid flickering
|
|
251
|
-
setSavedSize(size);
|
|
252
251
|
isFirstSizing.current = false;
|
|
252
|
+
updateDimensions();
|
|
253
253
|
return;
|
|
254
254
|
}
|
|
255
|
-
|
|
256
|
-
}, [props.autoHeight,
|
|
257
|
-
|
|
258
|
-
useGridApiOptionHandler(apiRef, '
|
|
259
|
-
useGridApiOptionHandler(apiRef, 'paginationModelChange', updateDimensions);
|
|
260
|
-
useGridApiOptionHandler(apiRef, 'columnsChange', updateDimensions);
|
|
261
|
-
useGridApiEventHandler(apiRef, 'resize', handleResize);
|
|
255
|
+
debouncedUpdateDimensions();
|
|
256
|
+
}, [updateDimensions, props.autoHeight, debouncedUpdateDimensions, logger]);
|
|
257
|
+
useGridApiOptionHandler(apiRef, 'rootMount', handleRootMount);
|
|
258
|
+
useGridApiOptionHandler(apiRef, 'resize', handleResize);
|
|
262
259
|
useGridApiOptionHandler(apiRef, 'debouncedResize', props.onResize);
|
|
263
260
|
}
|
|
264
|
-
function
|
|
261
|
+
function setCSSVariables(root, dimensions) {
|
|
262
|
+
const set = (k, v) => root.style.setProperty(k, v);
|
|
263
|
+
set('--DataGrid-hasScrollX', `${Number(dimensions.hasScrollX)}`);
|
|
264
|
+
set('--DataGrid-hasScrollY', `${Number(dimensions.hasScrollY)}`);
|
|
265
|
+
set('--DataGrid-scrollbarSize', `${dimensions.scrollbarSize}px`);
|
|
266
|
+
set('--DataGrid-rowWidth', `${dimensions.rowWidth}px`);
|
|
267
|
+
set('--DataGrid-columnsTotalWidth', `${dimensions.columnsTotalWidth}px`);
|
|
268
|
+
set('--DataGrid-leftPinnedWidth', `${dimensions.leftPinnedWidth}px`);
|
|
269
|
+
set('--DataGrid-rightPinnedWidth', `${dimensions.rightPinnedWidth}px`);
|
|
270
|
+
set('--DataGrid-headerHeight', `${dimensions.headerHeight}px`);
|
|
271
|
+
set('--DataGrid-headersTotalHeight', `${dimensions.headersTotalHeight}px`);
|
|
272
|
+
set('--DataGrid-topContainerHeight', `${dimensions.topContainerHeight}px`);
|
|
273
|
+
set('--DataGrid-bottomContainerHeight', `${dimensions.bottomContainerHeight}px`);
|
|
274
|
+
set('--height', `${dimensions.rowHeight}px`);
|
|
275
|
+
}
|
|
276
|
+
function getStaticDimensions(props, apiRef, density, pinnedColumnns) {
|
|
277
|
+
const validRowHeight = getValidRowHeight(props.rowHeight, DATA_GRID_PROPS_DEFAULT_VALUES.rowHeight, rowHeightWarning);
|
|
278
|
+
return {
|
|
279
|
+
rowHeight: Math.floor(validRowHeight * density),
|
|
280
|
+
headerHeight: Math.floor(props.columnHeaderHeight * density),
|
|
281
|
+
groupHeaderHeight: Math.floor((props.columnGroupHeaderHeight ?? props.columnHeaderHeight) * density),
|
|
282
|
+
headerFilterHeight: Math.floor((props.headerFilterHeight ?? props.columnHeaderHeight) * density),
|
|
283
|
+
columnsTotalWidth: columnsTotalWidthSelector(apiRef),
|
|
284
|
+
headersTotalHeight: getTotalHeaderHeight(apiRef, props),
|
|
285
|
+
leftPinnedWidth: pinnedColumnns.left.reduce((w, col) => w + col.computedWidth, 0),
|
|
286
|
+
rightPinnedWidth: pinnedColumnns.right.reduce((w, col) => w + col.computedWidth, 0)
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
const scrollbarSizeCache = new WeakMap();
|
|
290
|
+
function measureScrollbarSize(rootElement, scrollbarSize) {
|
|
265
291
|
if (scrollbarSize !== undefined) {
|
|
266
292
|
return scrollbarSize;
|
|
267
293
|
}
|
|
268
|
-
if (rootElement === null
|
|
294
|
+
if (rootElement === null) {
|
|
269
295
|
return 0;
|
|
270
296
|
}
|
|
297
|
+
const cachedSize = scrollbarSizeCache.get(rootElement);
|
|
298
|
+
if (cachedSize !== undefined) {
|
|
299
|
+
return cachedSize;
|
|
300
|
+
}
|
|
271
301
|
const doc = ownerDocument(rootElement);
|
|
272
302
|
const scrollDiv = doc.createElement('div');
|
|
273
303
|
scrollDiv.style.width = '99px';
|
|
@@ -278,14 +308,9 @@ function measureScrollbarSize(rootElement, columnsTotalWidth, scrollbarSize) {
|
|
|
278
308
|
rootElement.appendChild(scrollDiv);
|
|
279
309
|
const size = scrollDiv.offsetWidth - scrollDiv.clientWidth;
|
|
280
310
|
rootElement.removeChild(scrollDiv);
|
|
311
|
+
scrollbarSizeCache.set(rootElement, size);
|
|
281
312
|
return size;
|
|
282
313
|
}
|
|
283
|
-
|
|
284
|
-
// Get rid of floating point imprecision errors
|
|
285
|
-
// https://github.com/mui/mui-x/issues/9550#issuecomment-1619020477
|
|
286
|
-
function roundToDecimalPlaces(value, decimals) {
|
|
287
|
-
return Math.round(value * 10 ** decimals) / 10 ** decimals;
|
|
288
|
-
}
|
|
289
314
|
function areElementSizesEqual(a, b) {
|
|
290
315
|
return a.width === b.width && a.height === b.height;
|
|
291
316
|
}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { GridStateCommunity } from '../../../models/gridStateCommunity';
|
|
2
|
+
import { GridRowId } from '../../../models/gridRows';
|
|
3
|
+
import { GridEditMode } from '../../../models/gridEditRowModel';
|
|
2
4
|
/**
|
|
3
5
|
* Select the row editing state.
|
|
4
6
|
*/
|
|
5
7
|
export declare const gridEditRowsStateSelector: (state: GridStateCommunity) => import("../../..").GridEditingState;
|
|
8
|
+
export declare const gridRowIsEditingSelector: import("../../../utils/createSelector").OutputSelectorV8<GridStateCommunity, {
|
|
9
|
+
rowId: GridRowId;
|
|
10
|
+
editMode: GridEditMode;
|
|
11
|
+
}, boolean>;
|
|
12
|
+
export declare const gridEditCellStateSelector: import("../../../utils/createSelector").OutputSelectorV8<GridStateCommunity, {
|
|
13
|
+
rowId: GridRowId;
|
|
14
|
+
field: string;
|
|
15
|
+
}, import("../../..").GridEditCellProps<any>>;
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
import { createSelectorV8 } from "../../../utils/createSelector.js";
|
|
2
|
+
import { GridEditModes } from "../../../models/gridEditRowModel.js";
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Select the row editing state.
|
|
3
6
|
*/
|
|
4
|
-
export const gridEditRowsStateSelector = state => state.editRows;
|
|
7
|
+
export const gridEditRowsStateSelector = state => state.editRows;
|
|
8
|
+
export const gridRowIsEditingSelector = createSelectorV8(gridEditRowsStateSelector, (editRows, {
|
|
9
|
+
rowId,
|
|
10
|
+
editMode
|
|
11
|
+
}) => editMode === GridEditModes.Row && Boolean(editRows[rowId]));
|
|
12
|
+
export const gridEditCellStateSelector = createSelectorV8(gridEditRowsStateSelector, (editRows, {
|
|
13
|
+
rowId,
|
|
14
|
+
field
|
|
15
|
+
}) => editRows[rowId]?.[field] ?? null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { gridEditRowsStateSelector } from './gridEditingSelectors';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { gridEditRowsStateSelector } from "./gridEditingSelectors.js";
|
|
@@ -11,7 +11,7 @@ import { GridEditModes, GridCellModes } from "../../../models/gridEditRowModel.j
|
|
|
11
11
|
import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
|
|
12
12
|
import { gridEditRowsStateSelector } from "./gridEditingSelectors.js";
|
|
13
13
|
import { isPrintableKey, isPasteShortcut } from "../../../utils/keyboardUtils.js";
|
|
14
|
-
import {
|
|
14
|
+
import { gridRowsLookupSelector } from "../rows/gridRowsSelector.js";
|
|
15
15
|
import { deepClone } from "../../../utils/utils.js";
|
|
16
16
|
import { GridCellEditStartReasons, GridCellEditStopReasons } from "../../../models/params/gridEditCellParams.js";
|
|
17
17
|
import { getDefaultCellValue } from "./utils.js";
|
|
@@ -442,7 +442,7 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
442
442
|
|
|
443
443
|
// Run this effect synchronously so that the keyboard event can impact the yet-to-be-rendered input.
|
|
444
444
|
useEnhancedEffect(() => {
|
|
445
|
-
const
|
|
445
|
+
const rowsLookup = gridRowsLookupSelector(apiRef);
|
|
446
446
|
|
|
447
447
|
// Update the ref here because updateStateToStopCellEditMode may change it later
|
|
448
448
|
const copyOfPrevCellModes = prevCellModesModel.current;
|
|
@@ -451,7 +451,7 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
451
451
|
Object.entries(cellModesModel).forEach(([id, fields]) => {
|
|
452
452
|
Object.entries(fields).forEach(([field, params]) => {
|
|
453
453
|
const prevMode = copyOfPrevCellModes[id]?.[field]?.mode || GridCellModes.View;
|
|
454
|
-
const originalId =
|
|
454
|
+
const originalId = rowsLookup[id] ? apiRef.current.getRowId(rowsLookup[id]) : id;
|
|
455
455
|
if (params.mode === GridCellModes.Edit && prevMode === GridCellModes.View) {
|
|
456
456
|
updateStateToStartCellEditMode(_extends({
|
|
457
457
|
id: originalId,
|
|
@@ -9,10 +9,10 @@ import { warnOnce } from '@mui/x-internals/warning';
|
|
|
9
9
|
import { useGridApiEventHandler, useGridApiOptionHandler } from "../../utils/useGridApiEventHandler.js";
|
|
10
10
|
import { GridEditModes, GridRowModes } from "../../../models/gridEditRowModel.js";
|
|
11
11
|
import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
|
|
12
|
-
import { gridEditRowsStateSelector } from "./gridEditingSelectors.js";
|
|
12
|
+
import { gridEditRowsStateSelector, gridRowIsEditingSelector } from "./gridEditingSelectors.js";
|
|
13
13
|
import { isPrintableKey, isPasteShortcut } from "../../../utils/keyboardUtils.js";
|
|
14
14
|
import { gridColumnFieldsSelector, gridVisibleColumnFieldsSelector } from "../columns/gridColumnsSelector.js";
|
|
15
|
-
import {
|
|
15
|
+
import { gridRowsLookupSelector } from "../rows/gridRowsSelector.js";
|
|
16
16
|
import { deepClone } from "../../../utils/utils.js";
|
|
17
17
|
import { GridRowEditStopReasons, GridRowEditStartReasons } from "../../../models/params/gridRowParams.js";
|
|
18
18
|
import { GRID_ACTIONS_COLUMN_TYPE } from "../../../colDef/index.js";
|
|
@@ -232,11 +232,10 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
232
232
|
useGridApiOptionHandler(apiRef, 'rowEditStart', props.onRowEditStart);
|
|
233
233
|
useGridApiOptionHandler(apiRef, 'rowEditStop', props.onRowEditStop);
|
|
234
234
|
const getRowMode = React.useCallback(id => {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const isEditing = editingState[id] && Object.keys(editingState[id]).length > 0;
|
|
235
|
+
const isEditing = gridRowIsEditingSelector(apiRef, {
|
|
236
|
+
rowId: id,
|
|
237
|
+
editMode: props.editMode
|
|
238
|
+
});
|
|
240
239
|
return isEditing ? GridRowModes.Edit : GridRowModes.View;
|
|
241
240
|
}, [apiRef, props.editMode]);
|
|
242
241
|
const updateRowModesModel = useEventCallback(newModel => {
|
|
@@ -571,7 +570,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
571
570
|
|
|
572
571
|
// Run this effect synchronously so that the keyboard event can impact the yet-to-be-rendered input.
|
|
573
572
|
useEnhancedEffect(() => {
|
|
574
|
-
const
|
|
573
|
+
const rowsLookup = gridRowsLookupSelector(apiRef);
|
|
575
574
|
|
|
576
575
|
// Update the ref here because updateStateToStopRowEditMode may change it later
|
|
577
576
|
const copyOfPrevRowModesModel = prevRowModesModel.current;
|
|
@@ -583,7 +582,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
583
582
|
mode: GridRowModes.View
|
|
584
583
|
};
|
|
585
584
|
const prevMode = copyOfPrevRowModesModel[id]?.mode || GridRowModes.View;
|
|
586
|
-
const originalId =
|
|
585
|
+
const originalId = rowsLookup[id] ? apiRef.current.getRowId(rowsLookup[id]) : id;
|
|
587
586
|
if (params.mode === GridRowModes.Edit && prevMode === GridRowModes.View) {
|
|
588
587
|
updateStateToStartRowEditMode(_extends({
|
|
589
588
|
id: originalId
|
|
@@ -7,6 +7,11 @@ export type GridFilterItemResult = {
|
|
|
7
7
|
export type GridQuickFilterValueResult = {
|
|
8
8
|
[key: string]: boolean;
|
|
9
9
|
};
|
|
10
|
+
export declare const defaultGridFilterLookup: {
|
|
11
|
+
filteredRowsLookup: {};
|
|
12
|
+
filteredChildrenCountLookup: {};
|
|
13
|
+
filteredDescendantCountLookup: {};
|
|
14
|
+
};
|
|
10
15
|
export declare const getDefaultGridFilterModel: () => GridFilterModel;
|
|
11
16
|
export interface GridFilterState {
|
|
12
17
|
filterModel: GridFilterModel;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { GridLogicOperator } from "../../../models/gridFilterItem.js";
|
|
2
|
+
export const defaultGridFilterLookup = {
|
|
3
|
+
filteredRowsLookup: {},
|
|
4
|
+
filteredChildrenCountLookup: {},
|
|
5
|
+
filteredDescendantCountLookup: {}
|
|
6
|
+
};
|
|
2
7
|
export const getDefaultGridFilterModel = () => ({
|
|
3
8
|
items: [],
|
|
4
9
|
logicOperator: GridLogicOperator.And,
|
|
@@ -8,7 +8,7 @@ import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
|
|
|
8
8
|
import { useGridLogger } from "../../utils/useGridLogger.js";
|
|
9
9
|
import { gridColumnLookupSelector } from "../columns/gridColumnsSelector.js";
|
|
10
10
|
import { GridPreferencePanelsValue } from "../preferencesPanel/gridPreferencePanelsValue.js";
|
|
11
|
-
import { getDefaultGridFilterModel } from "./gridFilterState.js";
|
|
11
|
+
import { defaultGridFilterLookup, getDefaultGridFilterModel } from "./gridFilterState.js";
|
|
12
12
|
import { gridFilterModelSelector } from "./gridFilterSelector.js";
|
|
13
13
|
import { useFirstRender } from "../../utils/useFirstRender.js";
|
|
14
14
|
import { gridRowsLookupSelector } from "../rows/index.js";
|
|
@@ -20,12 +20,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
20
20
|
export const filterStateInitializer = (state, props, apiRef) => {
|
|
21
21
|
const filterModel = props.filterModel ?? props.initialState?.filter?.filterModel ?? getDefaultGridFilterModel();
|
|
22
22
|
return _extends({}, state, {
|
|
23
|
-
filter: {
|
|
24
|
-
filterModel: sanitizeFilterModel(filterModel, props.disableMultipleColumnsFiltering, apiRef)
|
|
25
|
-
|
|
26
|
-
filteredChildrenCountLookup: {},
|
|
27
|
-
filteredDescendantCountLookup: {}
|
|
28
|
-
},
|
|
23
|
+
filter: _extends({
|
|
24
|
+
filterModel: sanitizeFilterModel(filterModel, props.disableMultipleColumnsFiltering, apiRef)
|
|
25
|
+
}, defaultGridFilterLookup),
|
|
29
26
|
visibleRowsLookup: {}
|
|
30
27
|
});
|
|
31
28
|
};
|
|
@@ -271,12 +268,8 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
271
268
|
} = props;
|
|
272
269
|
const getRowsRef = useLazyRef(createMemoizedValues);
|
|
273
270
|
const flatFilteringMethod = React.useCallback(params => {
|
|
274
|
-
if (props.filterMode !== 'client' || !params.isRowMatchingFilters) {
|
|
275
|
-
return
|
|
276
|
-
filteredRowsLookup: {},
|
|
277
|
-
filteredChildrenCountLookup: {},
|
|
278
|
-
filteredDescendantCountLookup: {}
|
|
279
|
-
};
|
|
271
|
+
if (props.filterMode !== 'client' || !params.isRowMatchingFilters || !params.filterModel.items.length && !params.filterModel.quickFilterValues?.length) {
|
|
272
|
+
return defaultGridFilterLookup;
|
|
280
273
|
}
|
|
281
274
|
const dataRowIdToModelLookup = gridRowsLookupSelector(apiRef);
|
|
282
275
|
const filteredRowsLookup = {};
|
|
@@ -326,10 +326,11 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
326
326
|
// If the focused cell is in a row which does not exist anymore,
|
|
327
327
|
// focus previous row or remove the focus
|
|
328
328
|
if (cell && !apiRef.current.getRow(cell.id)) {
|
|
329
|
-
const lastFocusedRowId =
|
|
329
|
+
const lastFocusedRowId = cell.id;
|
|
330
330
|
let nextRowId = null;
|
|
331
331
|
if (typeof lastFocusedRowId !== 'undefined') {
|
|
332
|
-
const
|
|
332
|
+
const rowEl = apiRef.current.getRowElement(lastFocusedRowId);
|
|
333
|
+
const lastFocusedRowIndex = rowEl?.dataset.rowindex ? Number(rowEl?.dataset.rowindex) : 0;
|
|
333
334
|
const currentPage = getVisibleRows(apiRef, {
|
|
334
335
|
pagination: props.pagination,
|
|
335
336
|
paginationMode: props.paginationMode
|
|
@@ -6,7 +6,6 @@ import { gridVisibleColumnDefinitionsSelector, gridVisibleColumnFieldsSelector }
|
|
|
6
6
|
import { useGridLogger } from "../../utils/useGridLogger.js";
|
|
7
7
|
import { useGridApiEventHandler } from "../../utils/useGridApiEventHandler.js";
|
|
8
8
|
import { gridExpandedSortedRowEntriesSelector } from "../filter/gridFilterSelector.js";
|
|
9
|
-
import { useGridVisibleRows } from "../../utils/useGridVisibleRows.js";
|
|
10
9
|
import { GRID_CHECKBOX_SELECTION_COL_DEF } from "../../../colDef/gridCheckboxSelectionColDef.js";
|
|
11
10
|
import { gridClasses } from "../../../constants/gridClasses.js";
|
|
12
11
|
import { GridCellModes } from "../../../models/gridEditRowModel.js";
|
|
@@ -16,8 +15,14 @@ import { gridColumnGroupsHeaderMaxDepthSelector } from "../columnGrouping/gridCo
|
|
|
16
15
|
import { gridHeaderFilteringEditFieldSelector, gridHeaderFilteringMenuSelector } from "../headerFiltering/gridHeaderFilteringSelectors.js";
|
|
17
16
|
import { useGridRegisterPipeProcessor } from "../../core/pipeProcessing/index.js";
|
|
18
17
|
import { isEventTargetInPortal } from "../../../utils/domUtils.js";
|
|
19
|
-
import {
|
|
18
|
+
import { getLeftColumnIndex, getRightColumnIndex, findNonRowSpannedCell } from "./utils.js";
|
|
20
19
|
import { gridListColumnSelector } from "../listView/gridListViewSelectors.js";
|
|
20
|
+
import { createSelectorMemoized } from "../../../utils/createSelector.js";
|
|
21
|
+
import { gridVisibleRowsSelector } from "../pagination/index.js";
|
|
22
|
+
import { gridPinnedRowsSelector } from "../rows/gridRowsSelector.js";
|
|
23
|
+
const gridVisibleRowsWithPinnedRowsSelector = createSelectorMemoized(gridVisibleRowsSelector, gridPinnedRowsSelector, (visibleRows, pinnedRows) => {
|
|
24
|
+
return (pinnedRows.top || []).concat(visibleRows.rows, pinnedRows.bottom || []);
|
|
25
|
+
});
|
|
21
26
|
|
|
22
27
|
/**
|
|
23
28
|
* @requires useGridSorting (method) - can be after
|
|
@@ -30,10 +35,11 @@ import { gridListColumnSelector } from "../listView/gridListViewSelectors.js";
|
|
|
30
35
|
*/
|
|
31
36
|
export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
32
37
|
const logger = useGridLogger(apiRef, 'useGridKeyboardNavigation');
|
|
33
|
-
const initialCurrentPageRows = useGridVisibleRows(apiRef, props).rows;
|
|
34
38
|
const isRtl = useRtl();
|
|
35
39
|
const listView = props.unstable_listView;
|
|
36
|
-
const
|
|
40
|
+
const getCurrentPageRows = React.useCallback(() => {
|
|
41
|
+
return gridVisibleRowsWithPinnedRowsSelector(apiRef);
|
|
42
|
+
}, [apiRef]);
|
|
37
43
|
const headerFilteringEnabled = props.signature !== 'DataGrid' && props.headerFilters;
|
|
38
44
|
|
|
39
45
|
/**
|
|
@@ -92,8 +98,8 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
92
98
|
apiRef.current.setColumnGroupHeaderFocus(field, depth, event);
|
|
93
99
|
}, [apiRef, logger]);
|
|
94
100
|
const getRowIdFromIndex = React.useCallback(rowIndex => {
|
|
95
|
-
return
|
|
96
|
-
}, [
|
|
101
|
+
return getCurrentPageRows()[rowIndex]?.id;
|
|
102
|
+
}, [getCurrentPageRows]);
|
|
97
103
|
const handleColumnHeaderKeyDown = React.useCallback((params, event) => {
|
|
98
104
|
const headerTitleNode = event.currentTarget.querySelector(`.${gridClasses.columnHeaderTitleContainerContent}`);
|
|
99
105
|
const isFromInsideContent = !!headerTitleNode && headerTitleNode.contains(event.target);
|
|
@@ -102,6 +108,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
102
108
|
// There is one exception for the checkBoxHeader
|
|
103
109
|
return;
|
|
104
110
|
}
|
|
111
|
+
const currentPageRows = getCurrentPageRows();
|
|
105
112
|
const viewportPageSize = apiRef.current.getViewportPageSize();
|
|
106
113
|
const colIndexBefore = params.field ? apiRef.current.getColumnIndex(params.field) : 0;
|
|
107
114
|
const firstRowIndexInPage = currentPageRows.length > 0 ? 0 : null;
|
|
@@ -113,12 +120,10 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
113
120
|
switch (event.key) {
|
|
114
121
|
case 'ArrowDown':
|
|
115
122
|
{
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
goToCell(colIndexBefore, getRowIdFromIndex(firstRowIndexInPage));
|
|
121
|
-
}
|
|
123
|
+
if (headerFilteringEnabled) {
|
|
124
|
+
goToHeaderFilter(colIndexBefore, event);
|
|
125
|
+
} else if (firstRowIndexInPage !== null) {
|
|
126
|
+
goToCell(colIndexBefore, getRowIdFromIndex(firstRowIndexInPage));
|
|
122
127
|
}
|
|
123
128
|
break;
|
|
124
129
|
}
|
|
@@ -192,13 +197,14 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
192
197
|
if (shouldPreventDefault) {
|
|
193
198
|
event.preventDefault();
|
|
194
199
|
}
|
|
195
|
-
}, [apiRef,
|
|
200
|
+
}, [apiRef, getCurrentPageRows, headerFilteringEnabled, goToHeaderFilter, goToCell, getRowIdFromIndex, isRtl, goToHeader, goToGroupHeader]);
|
|
196
201
|
const handleHeaderFilterKeyDown = React.useCallback((params, event) => {
|
|
197
202
|
const isEditing = gridHeaderFilteringEditFieldSelector(apiRef) === params.field;
|
|
198
203
|
const isHeaderMenuOpen = gridHeaderFilteringMenuSelector(apiRef) === params.field;
|
|
199
204
|
if (isEditing || isHeaderMenuOpen || !isNavigationKey(event.key)) {
|
|
200
205
|
return;
|
|
201
206
|
}
|
|
207
|
+
const currentPageRows = getCurrentPageRows();
|
|
202
208
|
const viewportPageSize = apiRef.current.getViewportPageSize();
|
|
203
209
|
const colIndexBefore = params.field ? apiRef.current.getColumnIndex(params.field) : 0;
|
|
204
210
|
const firstRowIndexInPage = 0;
|
|
@@ -278,7 +284,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
278
284
|
if (shouldPreventDefault) {
|
|
279
285
|
event.preventDefault();
|
|
280
286
|
}
|
|
281
|
-
}, [apiRef,
|
|
287
|
+
}, [apiRef, getCurrentPageRows, goToHeaderFilter, isRtl, goToHeader, goToCell, getRowIdFromIndex]);
|
|
282
288
|
const handleColumnGroupHeaderKeyDown = React.useCallback((params, event) => {
|
|
283
289
|
const focusedColumnGroup = gridFocusColumnGroupHeaderSelector(apiRef);
|
|
284
290
|
if (focusedColumnGroup === null) {
|
|
@@ -293,6 +299,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
293
299
|
depth,
|
|
294
300
|
maxDepth
|
|
295
301
|
} = params;
|
|
302
|
+
const currentPageRows = getCurrentPageRows();
|
|
296
303
|
const viewportPageSize = apiRef.current.getViewportPageSize();
|
|
297
304
|
const currentColIndex = apiRef.current.getColumnIndex(currentField);
|
|
298
305
|
const colIndexBefore = currentField ? apiRef.current.getColumnIndex(currentField) : 0;
|
|
@@ -364,7 +371,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
364
371
|
if (shouldPreventDefault) {
|
|
365
372
|
event.preventDefault();
|
|
366
373
|
}
|
|
367
|
-
}, [apiRef,
|
|
374
|
+
}, [apiRef, getCurrentPageRows, goToHeader, goToGroupHeader, goToCell, getRowIdFromIndex]);
|
|
368
375
|
const handleCellKeyDown = React.useCallback((params, event) => {
|
|
369
376
|
// Ignore portal
|
|
370
377
|
if (isEventTargetInPortal(event)) {
|
|
@@ -383,6 +390,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
383
390
|
if (!canUpdateFocus) {
|
|
384
391
|
return;
|
|
385
392
|
}
|
|
393
|
+
const currentPageRows = getCurrentPageRows();
|
|
386
394
|
if (currentPageRows.length === 0) {
|
|
387
395
|
return;
|
|
388
396
|
}
|
|
@@ -511,7 +519,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
511
519
|
if (shouldPreventDefault) {
|
|
512
520
|
event.preventDefault();
|
|
513
521
|
}
|
|
514
|
-
}, [apiRef,
|
|
522
|
+
}, [apiRef, getCurrentPageRows, isRtl, goToCell, getRowIdFromIndex, headerFilteringEnabled, goToHeaderFilter, goToHeader, listView]);
|
|
515
523
|
const checkIfCanStartEditing = React.useCallback((initialValue, {
|
|
516
524
|
event
|
|
517
525
|
}) => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { RefObject } from '@mui/x-internals/types';
|
|
2
|
-
import { GridColDef,
|
|
2
|
+
import { GridColDef, GridRowId } from '../../../models';
|
|
3
3
|
import { GridApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
4
|
-
export declare function enrichPageRowsWithPinnedRows(apiRef: RefObject<GridApiCommunity>, rows: GridRowEntry[]): GridRowEntry<import("../../..").GridValidRowModel>[];
|
|
5
4
|
export declare const getLeftColumnIndex: ({ currentColIndex, firstColIndex, lastColIndex, isRtl, }: {
|
|
6
5
|
currentColIndex: number;
|
|
7
6
|
firstColIndex: number;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { gridFilteredSortedRowIdsSelector } from "../filter/gridFilterSelector.js";
|
|
2
2
|
import { gridRowSpanningHiddenCellsSelector } from "../rows/gridRowSpanningSelectors.js";
|
|
3
|
-
import { gridPinnedRowsSelector } from "../rows/gridRowsSelector.js";
|
|
4
|
-
export function enrichPageRowsWithPinnedRows(apiRef, rows) {
|
|
5
|
-
const pinnedRows = gridPinnedRowsSelector(apiRef) || {};
|
|
6
|
-
return [...(pinnedRows.top || []), ...rows, ...(pinnedRows.bottom || [])];
|
|
7
|
-
}
|
|
8
3
|
export const getLeftColumnIndex = ({
|
|
9
4
|
currentColIndex,
|
|
10
5
|
firstColIndex,
|