@mui/x-data-grid 7.24.1 → 7.25.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 +77 -0
- package/DataGrid/DataGrid.js +1 -7
- package/components/GridRow.d.ts +0 -1
- package/components/GridRow.js +25 -19
- package/components/cell/GridCell.d.ts +9 -6
- package/components/cell/GridCell.js +29 -52
- package/components/containers/GridRootStyles.js +135 -37
- 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 +18 -5
- package/components/virtualization/GridVirtualScrollerContent.js +11 -2
- package/hooks/features/columnResize/useGridColumnResize.js +2 -1
- package/hooks/features/columns/useGridColumns.js +7 -3
- package/hooks/features/dimensions/useGridDimensions.js +6 -8
- package/hooks/features/editing/gridEditingSelectors.d.ts +6 -0
- package/hooks/features/editing/gridEditingSelectors.js +7 -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 +5 -6
- 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/rowSelection/useGridRowSelection.js +3 -3
- 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 +3 -2
- package/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +9 -1
- package/hooks/features/virtualization/useGridVirtualScroller.js +31 -45
- package/index.js +1 -1
- package/models/api/gridApiCommon.d.ts +2 -2
- package/models/api/gridParamsApi.d.ts +29 -2
- package/models/api/index.d.ts +1 -1
- package/models/api/index.js +0 -1
- package/modern/DataGrid/DataGrid.js +1 -7
- package/modern/components/GridRow.js +25 -19
- package/modern/components/cell/GridCell.js +29 -52
- package/modern/components/containers/GridRootStyles.js +135 -37
- 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 +18 -5
- package/modern/components/virtualization/GridVirtualScrollerContent.js +11 -2
- package/modern/hooks/features/columnResize/useGridColumnResize.js +2 -1
- package/modern/hooks/features/columns/useGridColumns.js +7 -3
- package/modern/hooks/features/dimensions/useGridDimensions.js +6 -8
- package/modern/hooks/features/editing/gridEditingSelectors.js +7 -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 +5 -6
- 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/rowSelection/useGridRowSelection.js +3 -3
- 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 +3 -2
- package/modern/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +31 -45
- package/modern/index.js +1 -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/components/GridRow.js +22 -16
- package/node/components/cell/GridCell.js +27 -50
- package/node/components/containers/GridRootStyles.js +135 -37
- 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 +18 -5
- package/node/components/virtualization/GridVirtualScrollerContent.js +11 -2
- package/node/hooks/features/columnResize/useGridColumnResize.js +2 -1
- package/node/hooks/features/columns/useGridColumns.js +7 -3
- package/node/hooks/features/dimensions/useGridDimensions.js +6 -8
- package/node/hooks/features/editing/gridEditingSelectors.js +8 -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 +3 -4
- 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/rowSelection/useGridRowSelection.js +2 -2
- 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 +5 -4
- package/node/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +31 -45
- package/node/index.js +1 -1
- 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 +2 -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
|
@@ -39,7 +39,6 @@ export const useGridRows = (apiRef, props) => {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
const logger = useGridLogger(apiRef, 'useGridRows');
|
|
42
|
-
const currentPage = getVisibleRows(apiRef);
|
|
43
42
|
const lastUpdateMs = React.useRef(Date.now());
|
|
44
43
|
const lastRowCount = React.useRef(props.rowCount);
|
|
45
44
|
const timeout = useTimeout();
|
|
@@ -66,12 +65,6 @@ export const useGridRows = (apiRef, props) => {
|
|
|
66
65
|
}
|
|
67
66
|
return row.id;
|
|
68
67
|
}, [getRowIdProp]);
|
|
69
|
-
const lookup = React.useMemo(() => currentPage.rows.reduce((acc, {
|
|
70
|
-
id
|
|
71
|
-
}, index) => {
|
|
72
|
-
acc[id] = index;
|
|
73
|
-
return acc;
|
|
74
|
-
}, {}), [currentPage.rows]);
|
|
75
68
|
const throttledRowsChange = React.useCallback(({
|
|
76
69
|
cache,
|
|
77
70
|
throttle
|
|
@@ -170,7 +163,13 @@ export const useGridRows = (apiRef, props) => {
|
|
|
170
163
|
}, [apiRef]);
|
|
171
164
|
const getRowsCount = React.useCallback(() => gridRowCountSelector(apiRef), [apiRef]);
|
|
172
165
|
const getAllRowIds = React.useCallback(() => gridDataRowIdsSelector(apiRef), [apiRef]);
|
|
173
|
-
const getRowIndexRelativeToVisibleRows = React.useCallback(id =>
|
|
166
|
+
const getRowIndexRelativeToVisibleRows = React.useCallback(id => {
|
|
167
|
+
const row = apiRef.current.getRow(id);
|
|
168
|
+
const {
|
|
169
|
+
rowToIndexMap
|
|
170
|
+
} = getVisibleRows(apiRef);
|
|
171
|
+
return rowToIndexMap.get(row);
|
|
172
|
+
}, [apiRef]);
|
|
174
173
|
const setRowChildrenExpansion = React.useCallback((id, isExpanded) => {
|
|
175
174
|
const currentNode = apiRef.current.getRowNode(id);
|
|
176
175
|
if (!currentNode) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import useLazyRef from '@mui/utils/useLazyRef';
|
|
4
|
+
import { unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
4
5
|
import { ResizeObserver } from "../../../utils/ResizeObserver.js";
|
|
5
6
|
import { useGridVisibleRows } from "../../utils/useGridVisibleRows.js";
|
|
6
7
|
import { eslintUseValue } from "../../../utils/utils.js";
|
|
@@ -110,7 +111,7 @@ export const useGridRowsMeta = (apiRef, props) => {
|
|
|
110
111
|
}
|
|
111
112
|
apiRef.current.unstable_applyPipeProcessors('rowHeight', entry, row);
|
|
112
113
|
return entry;
|
|
113
|
-
}, [apiRef, currentPage.rows
|
|
114
|
+
}, [apiRef, currentPage.rows, getRowHeightProp, getEstimatedRowHeight, rowHeight, getRowSpacing, densityFactor]);
|
|
114
115
|
const hydrateRowsMeta = React.useCallback(() => {
|
|
115
116
|
hasRowWithAutoHeight.current = false;
|
|
116
117
|
pinnedRows.top.forEach(processHeightEntry);
|
|
@@ -181,7 +182,7 @@ export const useGridRowsMeta = (apiRef, props) => {
|
|
|
181
182
|
|
|
182
183
|
// The effect is used to build the rows meta data - currentPageTotalHeight and positions.
|
|
183
184
|
// Because of variable row height this is needed for the virtualization
|
|
184
|
-
|
|
185
|
+
useEnhancedEffect(() => {
|
|
185
186
|
hydrateRowsMeta();
|
|
186
187
|
}, [filterModel, paginationState, sortModel, hydrateRowsMeta]);
|
|
187
188
|
const rowsMetaApi = {
|
|
@@ -6,7 +6,7 @@ import { gridRenderContextSelector } from "./gridVirtualizationSelectors.js";
|
|
|
6
6
|
import { gridFocusCellSelector } from "../focus/index.js";
|
|
7
7
|
import { gridVisibleRowsSelector } from "../pagination/index.js";
|
|
8
8
|
import { gridRowsLookupSelector } from "../rows/index.js";
|
|
9
|
-
const
|
|
9
|
+
const gridIsFocusedCellOutOfContext = createSelector(gridFocusCellSelector, gridRenderContextSelector, gridVisibleRowsSelector, gridVisibleColumnDefinitionsSelector, gridRowsLookupSelector, (focusedCell, renderContext, currentPage, visibleColumns, rows) => {
|
|
10
10
|
if (!focusedCell) {
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
@@ -19,7 +19,7 @@ const gridIsFocusedCellOutOfContex = createSelector(gridFocusCellSelector, gridR
|
|
|
19
19
|
const isInRenderContext = rowIndex !== undefined && columnIndex !== -1 && rowIndex >= renderContext.firstRowIndex && rowIndex <= renderContext.lastRowIndex;
|
|
20
20
|
return !isInRenderContext;
|
|
21
21
|
});
|
|
22
|
-
export const gridFocusedVirtualCellSelector = createSelectorMemoized(
|
|
22
|
+
export const gridFocusedVirtualCellSelector = createSelectorMemoized(gridIsFocusedCellOutOfContext, gridVisibleColumnDefinitionsSelector, gridVisibleRowsSelector, gridRowsLookupSelector, gridFocusCellSelector, (isFocusedCellOutOfRenderContext, visibleColumns, currentPage, rows, focusedCell) => {
|
|
23
23
|
if (!isFocusedCellOutOfRenderContext) {
|
|
24
24
|
return null;
|
|
25
25
|
}
|
|
@@ -16,7 +16,7 @@ export declare const useGridVirtualScroller: () => {
|
|
|
16
16
|
};
|
|
17
17
|
getScrollerProps: () => {
|
|
18
18
|
ref: React.RefObject<HTMLDivElement | null>;
|
|
19
|
-
onScroll: (
|
|
19
|
+
onScroll: () => void;
|
|
20
20
|
onWheel: (event: React.WheelEvent) => void;
|
|
21
21
|
onTouchMove: (event: React.TouchEvent) => void;
|
|
22
22
|
style: React.CSSProperties;
|
|
@@ -34,10 +34,18 @@ export declare const useGridVirtualScroller: () => {
|
|
|
34
34
|
getScrollbarVerticalProps: () => {
|
|
35
35
|
ref: React.RefObject<HTMLDivElement | null>;
|
|
36
36
|
role: string;
|
|
37
|
+
scrollPosition: React.RefObject<{
|
|
38
|
+
top: number;
|
|
39
|
+
left: number;
|
|
40
|
+
}>;
|
|
37
41
|
};
|
|
38
42
|
getScrollbarHorizontalProps: () => {
|
|
39
43
|
ref: React.RefObject<HTMLDivElement | null>;
|
|
40
44
|
role: string;
|
|
45
|
+
scrollPosition: React.RefObject<{
|
|
46
|
+
top: number;
|
|
47
|
+
left: number;
|
|
48
|
+
}>;
|
|
41
49
|
};
|
|
42
50
|
};
|
|
43
51
|
export declare function areRenderContextsEqual(context1: GridRenderContext, context2: GridRenderContext): boolean;
|
|
@@ -25,7 +25,9 @@ import { EMPTY_RENDER_CONTEXT } from "./useGridVirtualization.js";
|
|
|
25
25
|
import { gridRowSpanningHiddenCellsOriginMapSelector } from "../rows/gridRowSpanningSelectors.js";
|
|
26
26
|
import { gridListColumnSelector } from "../listView/gridListViewSelectors.js";
|
|
27
27
|
import { minimalContentHeight } from "../rows/gridRowsUtils.js";
|
|
28
|
+
import { EMPTY_PINNED_COLUMN_FIELDS } from "../columns/index.js";
|
|
28
29
|
import { gridFocusedVirtualCellSelector } from "./gridFocusedVirtualCellSelector.js";
|
|
30
|
+
import { roundToDecimalPlaces } from "../../../utils/roundToDecimalPlaces.js";
|
|
29
31
|
import { isJSDOM } from "../../../utils/isJSDOM.js";
|
|
30
32
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
31
33
|
const MINIMUM_COLUMN_WIDTH = 50;
|
|
@@ -58,17 +60,13 @@ export const useGridVirtualScroller = () => {
|
|
|
58
60
|
const dimensions = useGridSelector(apiRef, gridDimensionsSelector);
|
|
59
61
|
const outerSize = dimensions.viewportOuterSize;
|
|
60
62
|
const pinnedRows = useGridSelector(apiRef, gridPinnedRowsSelector);
|
|
61
|
-
const pinnedColumnDefinitions =
|
|
62
|
-
const pinnedColumns = listView ?
|
|
63
|
-
left: [],
|
|
64
|
-
right: []
|
|
65
|
-
} : pinnedColumnDefinitions;
|
|
63
|
+
const pinnedColumnDefinitions = gridVisiblePinnedColumnDefinitionsSelector(apiRef);
|
|
64
|
+
const pinnedColumns = listView ? EMPTY_PINNED_COLUMN_FIELDS : pinnedColumnDefinitions;
|
|
66
65
|
const hasBottomPinnedRows = pinnedRows.bottom.length > 0;
|
|
67
66
|
const [panels, setPanels] = React.useState(EMPTY_DETAIL_PANELS);
|
|
68
67
|
const isRtl = useRtl();
|
|
69
|
-
const rowsMeta = useGridSelector(apiRef, gridRowsMetaSelector);
|
|
70
68
|
const selectedRowsLookup = useGridSelector(apiRef, selectedIdsLookupSelector);
|
|
71
|
-
const currentPage = useGridVisibleRows(apiRef
|
|
69
|
+
const currentPage = useGridVisibleRows(apiRef);
|
|
72
70
|
const mainRef = apiRef.current.mainElementRef;
|
|
73
71
|
const scrollerRef = apiRef.current.virtualScrollerRef;
|
|
74
72
|
const scrollbarVerticalRef = apiRef.current.virtualScrollbarVerticalRef;
|
|
@@ -84,7 +82,10 @@ export const useGridVirtualScroller = () => {
|
|
|
84
82
|
return undefined;
|
|
85
83
|
}
|
|
86
84
|
const initialRect = node.getBoundingClientRect();
|
|
87
|
-
let lastSize =
|
|
85
|
+
let lastSize = {
|
|
86
|
+
width: roundToDecimalPlaces(initialRect.width, 1),
|
|
87
|
+
height: roundToDecimalPlaces(initialRect.height, 1)
|
|
88
|
+
};
|
|
88
89
|
if (!previousSize.current || lastSize.width !== previousSize.current.width && lastSize.height !== previousSize.current.height) {
|
|
89
90
|
previousSize.current = lastSize;
|
|
90
91
|
apiRef.current.publishEvent('resize', lastSize);
|
|
@@ -97,7 +98,10 @@ export const useGridVirtualScroller = () => {
|
|
|
97
98
|
if (!entry) {
|
|
98
99
|
return;
|
|
99
100
|
}
|
|
100
|
-
const newSize =
|
|
101
|
+
const newSize = {
|
|
102
|
+
width: roundToDecimalPlaces(entry.contentRect.width, 1),
|
|
103
|
+
height: roundToDecimalPlaces(entry.contentRect.height, 1)
|
|
104
|
+
};
|
|
101
105
|
if (newSize.width === lastSize.width && newSize.height === lastSize.height) {
|
|
102
106
|
return;
|
|
103
107
|
}
|
|
@@ -165,9 +169,13 @@ export const useGridVirtualScroller = () => {
|
|
|
165
169
|
if (!scroller) {
|
|
166
170
|
return undefined;
|
|
167
171
|
}
|
|
172
|
+
const maxScrollTop = Math.ceil(dimensions.minimumSize.height - dimensions.viewportOuterSize.height);
|
|
173
|
+
const maxScrollLeft = Math.ceil(dimensions.minimumSize.width - dimensions.viewportInnerSize.width);
|
|
174
|
+
|
|
175
|
+
// Clamp the scroll position to the viewport to avoid re-calculating the render context for scroll bounce
|
|
168
176
|
const newScroll = {
|
|
169
|
-
top: scroller.scrollTop,
|
|
170
|
-
left: scroller.scrollLeft
|
|
177
|
+
top: clamp(scroller.scrollTop, 0, maxScrollTop),
|
|
178
|
+
left: isRtl ? clamp(scroller.scrollLeft, -maxScrollLeft, 0) : clamp(scroller.scrollLeft, 0, maxScrollLeft)
|
|
171
179
|
};
|
|
172
180
|
const dx = newScroll.left - scrollPosition.current.left;
|
|
173
181
|
const dy = newScroll.top - scrollPosition.current.top;
|
|
@@ -220,34 +228,15 @@ export const useGridVirtualScroller = () => {
|
|
|
220
228
|
frozenContext.current = undefined;
|
|
221
229
|
updateRenderContext(nextRenderContext);
|
|
222
230
|
};
|
|
223
|
-
const handleScroll = useEventCallback(
|
|
231
|
+
const handleScroll = useEventCallback(() => {
|
|
224
232
|
if (ignoreNextScrollEvent.current) {
|
|
225
233
|
ignoreNextScrollEvent.current = false;
|
|
226
234
|
return;
|
|
227
235
|
}
|
|
228
|
-
const {
|
|
229
|
-
scrollTop,
|
|
230
|
-
scrollLeft
|
|
231
|
-
} = event.currentTarget;
|
|
232
|
-
|
|
233
|
-
// On iOS and macOS, negative offsets are possible when swiping past the start
|
|
234
|
-
if (scrollTop < 0) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
if (!isRtl) {
|
|
238
|
-
if (scrollLeft < 0) {
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (isRtl) {
|
|
243
|
-
if (scrollLeft > 0) {
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
236
|
const nextRenderContext = triggerUpdateRenderContext();
|
|
248
237
|
apiRef.current.publishEvent('scrollPositionChange', {
|
|
249
|
-
top:
|
|
250
|
-
left:
|
|
238
|
+
top: scrollPosition.current.top,
|
|
239
|
+
left: scrollPosition.current.left,
|
|
251
240
|
renderContext: nextRenderContext
|
|
252
241
|
});
|
|
253
242
|
});
|
|
@@ -369,7 +358,6 @@ export const useGridVirtualScroller = () => {
|
|
|
369
358
|
rowId: id,
|
|
370
359
|
index: rowIndex,
|
|
371
360
|
selected: isSelected,
|
|
372
|
-
offsetTop: params.rows ? undefined : rowsMeta.positions[rowIndexInPage],
|
|
373
361
|
offsetLeft: offsetLeft,
|
|
374
362
|
columnsTotalWidth: dimensions.columnsTotalWidth,
|
|
375
363
|
rowHeight: baseRowHeight,
|
|
@@ -527,11 +515,13 @@ export const useGridVirtualScroller = () => {
|
|
|
527
515
|
}),
|
|
528
516
|
getScrollbarVerticalProps: () => ({
|
|
529
517
|
ref: scrollbarVerticalRef,
|
|
530
|
-
role: 'presentation'
|
|
518
|
+
role: 'presentation',
|
|
519
|
+
scrollPosition
|
|
531
520
|
}),
|
|
532
521
|
getScrollbarHorizontalProps: () => ({
|
|
533
522
|
ref: scrollbarHorizontalRef,
|
|
534
|
-
role: 'presentation'
|
|
523
|
+
role: 'presentation',
|
|
524
|
+
scrollPosition
|
|
535
525
|
})
|
|
536
526
|
};
|
|
537
527
|
};
|
|
@@ -573,6 +563,11 @@ function computeRenderContext(inputs, scrollPosition, scrollCache) {
|
|
|
573
563
|
firstColumnIndex: 0,
|
|
574
564
|
lastColumnIndex: inputs.visibleColumns.length
|
|
575
565
|
};
|
|
566
|
+
if (inputs.listView) {
|
|
567
|
+
return _extends({}, renderContext, {
|
|
568
|
+
lastColumnIndex: 1
|
|
569
|
+
});
|
|
570
|
+
}
|
|
576
571
|
const {
|
|
577
572
|
top,
|
|
578
573
|
left
|
|
@@ -824,13 +819,4 @@ function bufferForDirection(isRtl, direction, rowBufferPx, columnBufferPx, verti
|
|
|
824
819
|
// eslint unable to figure out enum exhaustiveness
|
|
825
820
|
throw new Error('unreachable');
|
|
826
821
|
}
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
// Round to avoid issues with subpixel rendering
|
|
830
|
-
// https://github.com/mui/mui-x/issues/15721
|
|
831
|
-
function roundDimensions(dimensions) {
|
|
832
|
-
return {
|
|
833
|
-
width: Math.round(dimensions.width * 10) / 10,
|
|
834
|
-
height: Math.round(dimensions.height * 10) / 10
|
|
835
|
-
};
|
|
836
822
|
}
|
package/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { GridEditingApi, GridEditingPrivateApi } from './gridEditingApi';
|
|
|
7
7
|
import type { GridFilterApi } from './gridFilterApi';
|
|
8
8
|
import { GridFocusApi, GridFocusPrivateApi } from './gridFocusApi';
|
|
9
9
|
import type { GridLocaleTextApi } from './gridLocaleTextApi';
|
|
10
|
-
import type { GridParamsApi } from './gridParamsApi';
|
|
10
|
+
import type { GridParamsApi, GridParamsPrivateApi } from './gridParamsApi';
|
|
11
11
|
import { GridPreferencesPanelApi } from './gridPreferencesPanelApi';
|
|
12
12
|
import { GridPrintExportApi } from './gridPrintExportApi';
|
|
13
13
|
import { GridRowApi, GridRowProPrivateApi } from './gridRowApi';
|
|
@@ -31,7 +31,7 @@ import type { DataGridProcessedProps } from '../props/DataGridProps';
|
|
|
31
31
|
import type { GridColumnResizeApi } from '../../hooks/features/columnResize';
|
|
32
32
|
export interface GridApiCommon<GridState extends GridStateCommunity = any, GridInitialState extends GridInitialStateCommunity = any> extends GridCoreApi, GridPipeProcessingApi, GridDensityApi, GridDimensionsApi, GridRowApi, GridRowsMetaApi, GridEditingApi, GridParamsApi, GridColumnApi, GridRowSelectionApi, GridSortApi, GridPaginationApi, GridCsvExportApi, GridFocusApi, GridFilterApi, GridColumnMenuApi, GridPreferencesPanelApi, GridPrintExportApi, GridVirtualizationApi, GridLocaleTextApi, GridScrollApi, GridColumnSpanningApi, GridStateApi<GridState>, GridStatePersistenceApi<GridInitialState>, GridColumnGroupingApi, GridHeaderFilteringApi, GridColumnResizeApi {
|
|
33
33
|
}
|
|
34
|
-
export interface GridPrivateOnlyApiCommon<Api extends GridApiCommon, PrivateApi extends GridPrivateApiCommon, Props extends DataGridProcessedProps> extends GridCorePrivateApi<Api, PrivateApi, Props>, GridStatePrivateApi<PrivateApi['state']>, GridPipeProcessingPrivateApi, GridStrategyProcessingApi, GridColumnSpanningPrivateApi, GridRowsMetaPrivateApi, GridDimensionsPrivateApi, GridEditingPrivateApi, GridLoggerApi, GridFocusPrivateApi, GridHeaderFilteringPrivateApi, GridVirtualizationPrivateApi, GridRowProPrivateApi {
|
|
34
|
+
export interface GridPrivateOnlyApiCommon<Api extends GridApiCommon, PrivateApi extends GridPrivateApiCommon, Props extends DataGridProcessedProps> extends GridCorePrivateApi<Api, PrivateApi, Props>, GridStatePrivateApi<PrivateApi['state']>, GridPipeProcessingPrivateApi, GridStrategyProcessingApi, GridColumnSpanningPrivateApi, GridRowsMetaPrivateApi, GridDimensionsPrivateApi, GridEditingPrivateApi, GridLoggerApi, GridFocusPrivateApi, GridHeaderFilteringPrivateApi, GridVirtualizationPrivateApi, GridRowProPrivateApi, GridParamsPrivateApi {
|
|
35
35
|
}
|
|
36
36
|
export interface GridPrivateApiCommon extends GridApiCommon, GridPrivateOnlyApiCommon<GridApiCommon, GridPrivateApiCommon, DataGridProcessedProps> {
|
|
37
37
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { GridColDef } from '../colDef';
|
|
2
|
+
import { GridStateColDef } from '../colDef/gridColDef';
|
|
3
|
+
import { GridCellMode } from '../gridCell';
|
|
2
4
|
import { GridValidRowModel, GridRowId, GridTreeNode, GridRowModel } from '../gridRows';
|
|
3
5
|
import { GridCellParams } from '../params/gridCellParams';
|
|
4
6
|
import { GridColumnHeaderParams } from '../params/gridColumnHeaderParams';
|
|
@@ -33,10 +35,10 @@ export interface GridParamsApi {
|
|
|
33
35
|
*/
|
|
34
36
|
getRowFormattedValue: <V extends any = any>(row: GridRowModel, colDef: GridColDef) => V;
|
|
35
37
|
/**
|
|
36
|
-
* Gets the
|
|
38
|
+
* Gets the [[GridCellParams]] object that is passed as argument in events.
|
|
37
39
|
* @param {GridRowId} id The id of the row.
|
|
38
40
|
* @param {string} field The column field.
|
|
39
|
-
* @returns {
|
|
41
|
+
* @returns {GridCellParams} The cell params.
|
|
40
42
|
*/
|
|
41
43
|
getCellElement: (id: GridRowId, field: string) => HTMLDivElement | null;
|
|
42
44
|
/**
|
|
@@ -72,3 +74,28 @@ export interface GridParamsApi {
|
|
|
72
74
|
*/
|
|
73
75
|
getColumnHeaderParams: (field: string) => GridColumnHeaderParams;
|
|
74
76
|
}
|
|
77
|
+
export interface GridParamsPrivateApi {
|
|
78
|
+
/**
|
|
79
|
+
* @typedef {Object} CellParamsOverrides
|
|
80
|
+
* @property {GridCellMode} cellMode - The mode of the cell.
|
|
81
|
+
* @property {GridStateColDef} colDef - The column definition.
|
|
82
|
+
* @property {boolean} hasFocus - Indicates if the cell is in focus.
|
|
83
|
+
* @property {GridTreeNode} rowNode - The node of the row that the current cell belongs to.
|
|
84
|
+
* @property {0|-1} tabIndex - The tabIndex value.
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* Used internally to render the cell based on existing row data provided by the GridRow.
|
|
88
|
+
* @param {GridRowId} id The id of the row.
|
|
89
|
+
* @param {string} field The column field.
|
|
90
|
+
* @param {GridValidRowModel} row The row model.
|
|
91
|
+
* @param {CellParamsOverrides} cellParams The cell params.
|
|
92
|
+
* @returns {GridCellParams} The cell params.
|
|
93
|
+
*/
|
|
94
|
+
getCellParamsForRow: <R extends GridValidRowModel = any, V = unknown, F = V, N extends GridTreeNode = GridTreeNode>(id: GridRowId, field: string, row: R, { cellMode, colDef, hasFocus, rowNode, tabIndex, }: {
|
|
95
|
+
cellMode: GridCellMode;
|
|
96
|
+
colDef: GridStateColDef;
|
|
97
|
+
hasFocus: boolean;
|
|
98
|
+
rowNode: N;
|
|
99
|
+
tabIndex: 0 | -1;
|
|
100
|
+
}) => GridCellParams<R, V, F, N>;
|
|
101
|
+
}
|
package/models/api/index.d.ts
CHANGED
package/models/api/index.js
CHANGED
|
@@ -18,17 +18,11 @@ const configuration = {
|
|
|
18
18
|
useGridRowAriaAttributes
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
-
let propValidators;
|
|
22
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
23
|
-
propValidators = [...propValidatorsDataGrid,
|
|
24
|
-
// Only validate in MIT version
|
|
25
|
-
props => props.columns && props.columns.some(column => column.resizable) && [`MUI X: \`column.resizable = true\` is not a valid prop.`, 'Column resizing is not available in the MIT version.', '', 'You need to upgrade to DataGridPro or DataGridPremium component to unlock this feature.'].join('\n') || undefined];
|
|
26
|
-
}
|
|
27
21
|
const DataGridRaw = forwardRef(function DataGrid(inProps, ref) {
|
|
28
22
|
const props = useDataGridProps(inProps);
|
|
29
23
|
const privateApiRef = useDataGridComponent(props.apiRef, props);
|
|
30
24
|
if (process.env.NODE_ENV !== 'production') {
|
|
31
|
-
validateProps(props,
|
|
25
|
+
validateProps(props, propValidatorsDataGrid);
|
|
32
26
|
}
|
|
33
27
|
return /*#__PURE__*/_jsx(GridContextProvider, {
|
|
34
28
|
privateApiRef: privateApiRef,
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["selected", "rowId", "row", "index", "style", "rowHeight", "className", "visibleColumns", "pinnedColumns", "
|
|
3
|
+
const _excluded = ["selected", "rowId", "row", "index", "style", "rowHeight", "className", "visibleColumns", "pinnedColumns", "offsetLeft", "columnsTotalWidth", "firstColumnIndex", "lastColumnIndex", "focusedColumnIndex", "isFirstVisible", "isLastVisible", "isNotVisible", "showBottomBorder", "scrollbarWidth", "gridHasFiller", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave", "onMouseOut", "onMouseOver"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
import { unstable_useForkRef as useForkRef } from '@mui/utils';
|
|
8
8
|
import { fastMemo } from '@mui/x-internals/fastMemo';
|
|
9
9
|
import { forwardRef } from '@mui/x-internals/forwardRef';
|
|
10
|
-
import {
|
|
10
|
+
import { isObjectEmpty } from '@mui/x-internals/isObjectEmpty';
|
|
11
|
+
import { GridEditModes, GridCellModes } from "../models/gridEditRowModel.js";
|
|
11
12
|
import { gridClasses } from "../constants/gridClasses.js";
|
|
12
13
|
import { composeGridClasses } from "../utils/composeGridClasses.js";
|
|
13
14
|
import { useGridRootProps } from "../hooks/utils/useGridRootProps.js";
|
|
14
15
|
import { shouldCellShowLeftBorder, shouldCellShowRightBorder } from "../utils/cellBorderUtils.js";
|
|
15
16
|
import { gridColumnPositionsSelector } from "../hooks/features/columns/gridColumnsSelector.js";
|
|
16
|
-
import { useGridSelector, objectShallowCompare } from "../hooks/utils/useGridSelector.js";
|
|
17
|
+
import { useGridSelector, objectShallowCompare, useGridSelectorV8 } from "../hooks/utils/useGridSelector.js";
|
|
17
18
|
import { useGridVisibleRows } from "../hooks/utils/useGridVisibleRows.js";
|
|
18
19
|
import { findParentElementFromClassName, isEventTargetInPortal } from "../utils/domUtils.js";
|
|
19
20
|
import { GRID_CHECKBOX_SELECTION_COL_DEF } from "../colDef/gridCheckboxSelectionColDef.js";
|
|
@@ -21,12 +22,20 @@ import { GRID_ACTIONS_COLUMN_TYPE } from "../colDef/gridActionsColDef.js";
|
|
|
21
22
|
import { GRID_DETAIL_PANEL_TOGGLE_FIELD, PinnedColumnPosition } from "../internals/constants.js";
|
|
22
23
|
import { gridSortModelSelector } from "../hooks/features/sorting/gridSortingSelector.js";
|
|
23
24
|
import { gridRowMaximumTreeDepthSelector } from "../hooks/features/rows/gridRowsSelector.js";
|
|
24
|
-
import { gridEditRowsStateSelector } from "../hooks/features/editing/gridEditingSelectors.js";
|
|
25
|
+
import { gridEditRowsStateSelector, gridRowIsEditingSelector } from "../hooks/features/editing/gridEditingSelectors.js";
|
|
25
26
|
import { GridScrollbarFillerCell as ScrollbarFiller } from "./GridScrollbarFillerCell.js";
|
|
26
27
|
import { getPinnedCellOffset } from "../internals/utils/getPinnedCellOffset.js";
|
|
27
28
|
import { useGridConfiguration } from "../hooks/utils/useGridConfiguration.js";
|
|
28
29
|
import { useGridPrivateApiContext } from "../hooks/utils/useGridPrivateApiContext.js";
|
|
30
|
+
import { createSelectorV8 } from "../utils/createSelector.js";
|
|
29
31
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
32
|
+
const isRowReorderingEnabledSelector = createSelectorV8(gridEditRowsStateSelector, (editRows, rowReordering) => {
|
|
33
|
+
if (!rowReordering) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const isEditingRows = !isObjectEmpty(editRows);
|
|
37
|
+
return !isEditingRows;
|
|
38
|
+
});
|
|
30
39
|
const GridRow = forwardRef(function GridRow(props, refProp) {
|
|
31
40
|
const {
|
|
32
41
|
selected,
|
|
@@ -65,10 +74,11 @@ const GridRow = forwardRef(function GridRow(props, refProp) {
|
|
|
65
74
|
const sortModel = useGridSelector(apiRef, gridSortModelSelector);
|
|
66
75
|
const treeDepth = useGridSelector(apiRef, gridRowMaximumTreeDepthSelector);
|
|
67
76
|
const columnPositions = useGridSelector(apiRef, gridColumnPositionsSelector);
|
|
68
|
-
const
|
|
77
|
+
const rowReordering = rootProps.rowReordering;
|
|
78
|
+
const isRowReorderingEnabled = useGridSelectorV8(apiRef, isRowReorderingEnabledSelector, rowReordering);
|
|
69
79
|
const handleRef = useForkRef(ref, refProp);
|
|
70
80
|
const rowNode = apiRef.current.getRowNode(rowId);
|
|
71
|
-
const editing = apiRef
|
|
81
|
+
const editing = useGridSelectorV8(apiRef, gridRowIsEditingSelector, rowId);
|
|
72
82
|
const editable = rootProps.editMode === GridEditModes.Row;
|
|
73
83
|
const hasFocusCell = focusedColumnIndex !== undefined;
|
|
74
84
|
const hasVirtualFocusCellLeft = hasFocusCell && focusedColumnIndex >= pinnedColumns.left.length && focusedColumnIndex < firstColumnIndex;
|
|
@@ -145,7 +155,6 @@ const GridRow = forwardRef(function GridRow(props, refProp) {
|
|
|
145
155
|
slotProps,
|
|
146
156
|
disableColumnReorder
|
|
147
157
|
} = rootProps;
|
|
148
|
-
const rowReordering = rootProps.rowReordering;
|
|
149
158
|
const heightEntry = useGridSelector(apiRef, () => _extends({}, apiRef.current.getRowHeightEntry(rowId)), objectShallowCompare);
|
|
150
159
|
const style = React.useMemo(() => {
|
|
151
160
|
if (isNotVisible) {
|
|
@@ -188,6 +197,11 @@ const GridRow = forwardRef(function GridRow(props, refProp) {
|
|
|
188
197
|
});
|
|
189
198
|
rowClassNames.push(rootProps.getRowClassName(rowParams));
|
|
190
199
|
}
|
|
200
|
+
|
|
201
|
+
/* Start of rendering */
|
|
202
|
+
if (!rowNode) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
191
205
|
const getCell = (column, indexInSection, indexRelativeToAllColumns, sectionLength, pinnedPosition = PinnedColumnPosition.NONE) => {
|
|
192
206
|
const cellColSpanInfo = apiRef.current.unstable_getCellColSpanInfo(rowId, indexRelativeToAllColumns);
|
|
193
207
|
if (cellColSpanInfo?.spannedByColSpan) {
|
|
@@ -205,14 +219,12 @@ const GridRow = forwardRef(function GridRow(props, refProp) {
|
|
|
205
219
|
align: column.align
|
|
206
220
|
}, column.field);
|
|
207
221
|
}
|
|
208
|
-
const editCellState = editRowsState[rowId]?.[column.field] ?? null;
|
|
209
222
|
|
|
210
223
|
// when the cell is a reorder cell we are not allowing to reorder the col
|
|
211
224
|
// fixes https://github.com/mui/mui-x/issues/11126
|
|
212
225
|
const isReorderCell = column.field === '__reorder__';
|
|
213
|
-
const isEditingRows = Object.keys(editRowsState).length > 0;
|
|
214
226
|
const canReorderColumn = !(disableColumnReorder || column.disableReorder);
|
|
215
|
-
const canReorderRow =
|
|
227
|
+
const canReorderRow = isRowReorderingEnabled && !sortModel.length && treeDepth <= 1;
|
|
216
228
|
const disableDragEvents = !(canReorderColumn || isReorderCell && canReorderRow);
|
|
217
229
|
const cellIsNotVisible = pinnedPosition === PinnedColumnPosition.VIRTUAL;
|
|
218
230
|
const showLeftBorder = shouldCellShowLeftBorder(pinnedPosition, indexInSection);
|
|
@@ -225,20 +237,15 @@ const GridRow = forwardRef(function GridRow(props, refProp) {
|
|
|
225
237
|
colIndex: indexRelativeToAllColumns,
|
|
226
238
|
colSpan: colSpan,
|
|
227
239
|
disableDragEvents: disableDragEvents,
|
|
228
|
-
editCellState: editCellState,
|
|
229
240
|
isNotVisible: cellIsNotVisible,
|
|
230
241
|
pinnedOffset: pinnedOffset,
|
|
231
242
|
pinnedPosition: pinnedPosition,
|
|
232
243
|
showLeftBorder: showLeftBorder,
|
|
233
|
-
showRightBorder: showRightBorder
|
|
244
|
+
showRightBorder: showRightBorder,
|
|
245
|
+
row: row,
|
|
246
|
+
rowNode: rowNode
|
|
234
247
|
}, slotProps?.cell), column.field);
|
|
235
248
|
};
|
|
236
|
-
|
|
237
|
-
/* Start of rendering */
|
|
238
|
-
|
|
239
|
-
if (!rowNode) {
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
249
|
const leftCells = pinnedColumns.left.map((column, i) => {
|
|
243
250
|
const indexRelativeToAllColumns = i;
|
|
244
251
|
return getCell(column, i, indexRelativeToAllColumns, pinnedColumns.left.length, PinnedColumnPosition.LEFT);
|
|
@@ -316,7 +323,6 @@ process.env.NODE_ENV !== "production" ? GridRow.propTypes = {
|
|
|
316
323
|
isNotVisible: PropTypes.bool.isRequired,
|
|
317
324
|
lastColumnIndex: PropTypes.number.isRequired,
|
|
318
325
|
offsetLeft: PropTypes.number.isRequired,
|
|
319
|
-
offsetTop: PropTypes.number,
|
|
320
326
|
onClick: PropTypes.func,
|
|
321
327
|
onDoubleClick: PropTypes.func,
|
|
322
328
|
onMouseEnter: PropTypes.func,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["column", "rowId", "
|
|
3
|
+
const _excluded = ["column", "row", "rowId", "rowNode", "align", "children", "colIndex", "width", "className", "style", "colSpan", "disableDragEvents", "isNotVisible", "pinnedOffset", "pinnedPosition", "showRightBorder", "showLeftBorder", "onClick", "onDoubleClick", "onMouseDown", "onMouseUp", "onMouseOver", "onKeyDown", "onKeyUp", "onDragEnter", "onDragOver"],
|
|
4
4
|
_excluded2 = ["changeReason", "unstable_updateValueOnRender"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
@@ -12,13 +12,14 @@ import { forwardRef } from '@mui/x-internals/forwardRef';
|
|
|
12
12
|
import { doesSupportPreventScroll } from "../../utils/doesSupportPreventScroll.js";
|
|
13
13
|
import { getDataGridUtilityClass, gridClasses } from "../../constants/gridClasses.js";
|
|
14
14
|
import { GridCellModes } from "../../models/index.js";
|
|
15
|
-
import { useGridSelector,
|
|
16
|
-
import { useGridApiContext } from "../../hooks/utils/useGridApiContext.js";
|
|
15
|
+
import { useGridSelector, useGridSelectorV8 } from "../../hooks/utils/useGridSelector.js";
|
|
17
16
|
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.js";
|
|
18
|
-
import { gridFocusCellSelector } from "../../hooks/features/focus/gridFocusStateSelector.js";
|
|
17
|
+
import { gridFocusCellSelector, gridTabIndexCellSelector } from "../../hooks/features/focus/gridFocusStateSelector.js";
|
|
19
18
|
import { GridPinnedColumnPosition } from "../../hooks/features/columns/gridColumnsInterfaces.js";
|
|
20
19
|
import { PinnedColumnPosition } from "../../internals/constants.js";
|
|
21
20
|
import { gridRowSpanningHiddenCellsSelector, gridRowSpanningSpannedCellsSelector } from "../../hooks/features/rows/gridRowSpanningSelectors.js";
|
|
21
|
+
import { useGridPrivateApiContext } from "../../hooks/utils/useGridPrivateApiContext.js";
|
|
22
|
+
import { gridEditCellStateSelector } from "../../hooks/features/editing/gridEditingSelectors.js";
|
|
22
23
|
import { attachPinnedStyle } from "../../internals/utils/index.js";
|
|
23
24
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
25
|
export const gridPinnedColumnPositionLookup = {
|
|
@@ -27,30 +28,6 @@ export const gridPinnedColumnPositionLookup = {
|
|
|
27
28
|
[PinnedColumnPosition.NONE]: undefined,
|
|
28
29
|
[PinnedColumnPosition.VIRTUAL]: undefined
|
|
29
30
|
};
|
|
30
|
-
const EMPTY_CELL_PARAMS = {
|
|
31
|
-
id: -1,
|
|
32
|
-
field: '__unset__',
|
|
33
|
-
row: {},
|
|
34
|
-
rowNode: {
|
|
35
|
-
id: -1,
|
|
36
|
-
depth: 0,
|
|
37
|
-
type: 'leaf',
|
|
38
|
-
parent: -1,
|
|
39
|
-
groupingKey: null
|
|
40
|
-
},
|
|
41
|
-
colDef: {
|
|
42
|
-
type: 'string',
|
|
43
|
-
field: '__unset__',
|
|
44
|
-
computedWidth: 0
|
|
45
|
-
},
|
|
46
|
-
cellMode: GridCellModes.View,
|
|
47
|
-
hasFocus: false,
|
|
48
|
-
tabIndex: -1,
|
|
49
|
-
value: null,
|
|
50
|
-
formattedValue: '__unset__',
|
|
51
|
-
isEditable: false,
|
|
52
|
-
api: {}
|
|
53
|
-
};
|
|
54
31
|
const useUtilityClasses = ownerState => {
|
|
55
32
|
const {
|
|
56
33
|
align,
|
|
@@ -74,8 +51,9 @@ let warnedOnce = false;
|
|
|
74
51
|
const GridCell = forwardRef(function GridCell(props, ref) {
|
|
75
52
|
const {
|
|
76
53
|
column,
|
|
54
|
+
row,
|
|
77
55
|
rowId,
|
|
78
|
-
|
|
56
|
+
rowNode,
|
|
79
57
|
align,
|
|
80
58
|
colIndex,
|
|
81
59
|
width,
|
|
@@ -99,22 +77,29 @@ const GridCell = forwardRef(function GridCell(props, ref) {
|
|
|
99
77
|
onDragOver
|
|
100
78
|
} = props,
|
|
101
79
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
102
|
-
const apiRef =
|
|
80
|
+
const apiRef = useGridPrivateApiContext();
|
|
103
81
|
const rootProps = useGridRootProps();
|
|
104
82
|
const isRtl = useRtl();
|
|
105
83
|
const field = column.field;
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
84
|
+
const editCellState = useGridSelectorV8(apiRef, gridEditCellStateSelector, {
|
|
85
|
+
rowId,
|
|
86
|
+
field
|
|
87
|
+
});
|
|
88
|
+
const cellMode = editCellState ? GridCellModes.Edit : GridCellModes.View;
|
|
89
|
+
const cellParams = apiRef.current.getCellParamsForRow(rowId, field, row, {
|
|
90
|
+
colDef: column,
|
|
91
|
+
cellMode,
|
|
92
|
+
rowNode: rowNode,
|
|
93
|
+
tabIndex: useGridSelector(apiRef, () => {
|
|
94
|
+
const cellTabIndex = gridTabIndexCellSelector(apiRef);
|
|
95
|
+
return cellTabIndex && cellTabIndex.field === field && cellTabIndex.id === rowId ? 0 : -1;
|
|
96
|
+
}),
|
|
97
|
+
hasFocus: useGridSelector(apiRef, () => {
|
|
98
|
+
const focus = gridFocusCellSelector(apiRef);
|
|
99
|
+
return focus?.id === rowId && focus.field === field;
|
|
100
|
+
})
|
|
101
|
+
});
|
|
102
|
+
cellParams.api = apiRef.current;
|
|
118
103
|
const isSelected = useGridSelector(apiRef, () => apiRef.current.unstable_applyPipeProcessors('isCellSelected', false, {
|
|
119
104
|
id: rowId,
|
|
120
105
|
field
|
|
@@ -122,7 +107,6 @@ const GridCell = forwardRef(function GridCell(props, ref) {
|
|
|
122
107
|
const hiddenCells = useGridSelector(apiRef, gridRowSpanningHiddenCellsSelector);
|
|
123
108
|
const spannedCells = useGridSelector(apiRef, gridRowSpanningSpannedCellsSelector);
|
|
124
109
|
const {
|
|
125
|
-
cellMode,
|
|
126
110
|
hasFocus,
|
|
127
111
|
isEditable = false,
|
|
128
112
|
value
|
|
@@ -244,9 +228,6 @@ const GridCell = forwardRef(function GridCell(props, ref) {
|
|
|
244
228
|
}, style)
|
|
245
229
|
});
|
|
246
230
|
}
|
|
247
|
-
if (cellParams === EMPTY_CELL_PARAMS) {
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
250
231
|
let handleFocus = other.onFocus;
|
|
251
232
|
if (process.env.NODE_ENV === 'test' && rootProps.experimentalFeatures?.warnIfFocusStateIsNotSynced) {
|
|
252
233
|
handleFocus = event => {
|
|
@@ -330,16 +311,12 @@ process.env.NODE_ENV !== "production" ? GridCell.propTypes = {
|
|
|
330
311
|
colSpan: PropTypes.number,
|
|
331
312
|
column: PropTypes.object.isRequired,
|
|
332
313
|
disableDragEvents: PropTypes.bool,
|
|
333
|
-
editCellState: PropTypes.shape({
|
|
334
|
-
changeReason: PropTypes.oneOf(['debouncedSetEditCellValue', 'setEditCellValue']),
|
|
335
|
-
isProcessingProps: PropTypes.bool,
|
|
336
|
-
isValidating: PropTypes.bool,
|
|
337
|
-
value: PropTypes.any
|
|
338
|
-
}),
|
|
339
314
|
isNotVisible: PropTypes.bool.isRequired,
|
|
340
315
|
pinnedOffset: PropTypes.number,
|
|
341
316
|
pinnedPosition: PropTypes.oneOf([0, 1, 2, 3]).isRequired,
|
|
317
|
+
row: PropTypes.object.isRequired,
|
|
342
318
|
rowId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
319
|
+
rowNode: PropTypes.object.isRequired,
|
|
343
320
|
showLeftBorder: PropTypes.bool.isRequired,
|
|
344
321
|
showRightBorder: PropTypes.bool.isRequired,
|
|
345
322
|
width: PropTypes.number.isRequired
|