@mui/x-data-grid 5.6.0 → 5.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/DataGrid/DataGrid.js +18 -3
- package/DataGrid/useDataGridComponent.js +19 -15
- package/DataGrid/useDataGridProps.js +3 -2
- package/colDef/gridNumericOperators.d.ts +1 -1
- package/colDef/gridNumericOperators.js +1 -1
- package/components/ErrorBoundary.d.ts +2 -2
- package/components/GridRow.js +29 -3
- package/components/base/GridErrorHandler.d.ts +8 -2
- package/components/base/GridErrorHandler.js +13 -2
- package/components/cell/GridBooleanCell.d.ts +2 -1
- package/components/cell/GridCell.js +4 -2
- package/components/cell/GridEditBooleanCell.d.ts +2 -1
- package/components/cell/GridEditDateCell.d.ts +2 -1
- package/components/cell/GridEditInputCell.d.ts +2 -1
- package/components/cell/GridEditSingleSelectCell.d.ts +2 -1
- package/components/cell/GridEditSingleSelectCell.js +2 -1
- package/components/columnHeaders/GridColumnHeaderItem.js +5 -3
- package/components/containers/GridRootStyles.js +1 -1
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.d.ts +2 -1
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +27 -23
- package/components/panel/filterPanel/filterPanelUtils.d.ts +2 -2
- package/components/virtualization/GridVirtualScrollerRenderZone.js +4 -1
- package/constants/gridClasses.d.ts +5 -1
- package/constants/gridClasses.js +1 -1
- package/context/GridContextProvider.d.ts +9 -6
- package/hooks/features/columnMenu/useGridColumnMenu.d.ts +2 -0
- package/hooks/features/columnMenu/useGridColumnMenu.js +6 -7
- package/hooks/features/columns/gridColumnsSelector.d.ts +8 -8
- package/hooks/features/columns/gridColumnsSelector.js +11 -10
- package/hooks/features/columns/gridColumnsUtils.js +7 -5
- package/hooks/features/density/useGridDensity.d.ts +2 -0
- package/hooks/features/density/useGridDensity.js +3 -4
- package/hooks/features/dimensions/useGridDimensions.js +2 -2
- package/hooks/features/editRows/useGridEditing.d.ts +2 -0
- package/hooks/features/editRows/useGridEditing.js +3 -4
- package/hooks/features/export/serializers/csvSerializer.js +4 -4
- package/hooks/features/filter/gridFilterSelector.d.ts +1 -0
- package/hooks/features/filter/gridFilterSelector.js +1 -0
- package/hooks/features/focus/useGridFocus.d.ts +2 -0
- package/hooks/features/focus/useGridFocus.js +10 -11
- package/hooks/features/keyboard/useGridKeyboardNavigation.js +2 -2
- package/hooks/features/pagination/useGridPage.d.ts +1 -2
- package/hooks/features/pagination/useGridPage.js +5 -17
- package/hooks/features/pagination/useGridPageSize.d.ts +1 -2
- package/hooks/features/pagination/useGridPageSize.js +5 -26
- package/hooks/features/pagination/useGridPagination.d.ts +2 -0
- package/hooks/features/pagination/useGridPagination.js +25 -2
- package/hooks/features/preferencesPanel/useGridPreferencesPanel.d.ts +3 -1
- package/hooks/features/preferencesPanel/useGridPreferencesPanel.js +10 -11
- package/hooks/features/rows/useGridParamsApi.js +3 -10
- package/hooks/features/rows/useGridRows.js +14 -6
- package/hooks/features/rows/useGridRowsMeta.d.ts +3 -1
- package/hooks/features/rows/useGridRowsMeta.js +42 -24
- package/hooks/features/selection/gridSelectionSelector.d.ts +1 -1
- package/hooks/features/selection/useGridSelection.d.ts +2 -0
- package/hooks/features/selection/useGridSelection.js +28 -16
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +8 -3
- package/hooks/features/virtualization/useGridVirtualScroller.js +4 -4
- package/hooks/utils/useGridApi.js +10 -1
- package/hooks/utils/useGridInitializeState.d.ts +2 -1
- package/hooks/utils/useGridSelector.js +4 -4
- package/hooks/utils/useGridState.js +10 -1
- package/hooks/utils/{useCurrentPageRows.d.ts → useGridVisibleRows.d.ts} +7 -6
- package/hooks/utils/{useCurrentPageRows.js → useGridVisibleRows.js} +8 -7
- package/index.js +1 -1
- package/internals/index.d.ts +9 -12
- package/internals/index.js +9 -12
- package/legacy/DataGrid/DataGrid.js +18 -3
- package/legacy/DataGrid/useDataGridComponent.js +19 -15
- package/legacy/DataGrid/useDataGridProps.js +8 -2
- package/legacy/colDef/gridNumericOperators.js +1 -1
- package/legacy/components/GridRow.js +30 -3
- package/legacy/components/base/GridErrorHandler.js +13 -2
- package/legacy/components/cell/GridCell.js +4 -2
- package/legacy/components/cell/GridEditSingleSelectCell.js +10 -9
- package/legacy/components/columnHeaders/GridColumnHeaderItem.js +5 -3
- package/legacy/components/containers/GridRootStyles.js +1 -1
- package/legacy/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +29 -26
- package/legacy/components/virtualization/GridVirtualScrollerRenderZone.js +4 -1
- package/legacy/constants/gridClasses.js +1 -1
- package/legacy/hooks/features/columnMenu/useGridColumnMenu.js +8 -9
- package/legacy/hooks/features/columns/gridColumnsSelector.js +13 -12
- package/legacy/hooks/features/columns/gridColumnsUtils.js +7 -5
- package/legacy/hooks/features/density/useGridDensity.js +5 -6
- package/legacy/hooks/features/dimensions/useGridDimensions.js +2 -2
- package/legacy/hooks/features/editRows/useGridEditing.js +5 -6
- package/legacy/hooks/features/export/serializers/csvSerializer.js +4 -4
- package/legacy/hooks/features/filter/gridFilterSelector.js +1 -0
- package/legacy/hooks/features/focus/useGridFocus.js +12 -13
- package/legacy/hooks/features/keyboard/useGridKeyboardNavigation.js +2 -2
- package/legacy/hooks/features/pagination/useGridPage.js +5 -17
- package/legacy/hooks/features/pagination/useGridPageSize.js +5 -26
- package/legacy/hooks/features/pagination/useGridPagination.js +25 -2
- package/legacy/hooks/features/preferencesPanel/useGridPreferencesPanel.js +10 -11
- package/legacy/hooks/features/rows/useGridParamsApi.js +3 -10
- package/legacy/hooks/features/rows/useGridRows.js +17 -6
- package/legacy/hooks/features/rows/useGridRowsMeta.js +44 -26
- package/legacy/hooks/features/selection/useGridSelection.js +29 -19
- package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +4 -4
- package/legacy/hooks/utils/useGridApi.js +7 -0
- package/legacy/hooks/utils/useGridSelector.js +4 -4
- package/legacy/hooks/utils/useGridState.js +7 -0
- package/legacy/hooks/utils/{useCurrentPageRows.js → useGridVisibleRows.js} +8 -7
- package/legacy/index.js +1 -1
- package/legacy/internals/index.js +9 -12
- package/legacy/models/colDef/gridDefaultColumnTypes.js +4 -4
- package/legacy/utils/createSelector.js +4 -4
- package/legacy/utils/getGridLocalization.js +2 -2
- package/lib/lodash/_baseGetAllKeys.d.ts +1 -1
- package/lib/lodash/_baseIsEqual.d.ts +1 -1
- package/lib/lodash/_baseIsEqualDeep.d.ts +1 -1
- package/lib/lodash/_baseKeys.d.ts +1 -1
- package/lib/lodash/_cacheHas.d.ts +1 -1
- package/lib/lodash/_equalArrays.d.ts +1 -1
- package/lib/lodash/_equalByTag.d.ts +1 -1
- package/lib/lodash/_equalObjects.d.ts +1 -1
- package/lib/lodash/_getAllKeys.d.ts +1 -1
- package/lib/lodash/_getMapData.d.ts +1 -1
- package/lib/lodash/_getNative.d.ts +1 -1
- package/lib/lodash/_getValue.d.ts +1 -1
- package/lib/lodash/_hashSet.d.ts +1 -1
- package/lib/lodash/_listCacheSet.d.ts +1 -1
- package/lib/lodash/_mapCacheSet.d.ts +1 -1
- package/lib/lodash/_mapToArray.d.ts +1 -1
- package/lib/lodash/_setCacheAdd.d.ts +1 -1
- package/lib/lodash/_setToArray.d.ts +1 -1
- package/lib/lodash/_stackSet.d.ts +1 -1
- package/lib/lodash/keys.d.ts +1 -1
- package/models/api/gridRowApi.d.ts +6 -0
- package/models/api/gridRowsMetaApi.d.ts +7 -0
- package/models/api/gridSortApi.d.ts +1 -0
- package/models/colDef/gridColDef.d.ts +1 -2
- package/models/colDef/gridDefaultColumnTypes.js +2 -2
- package/models/gridRows.d.ts +8 -2
- package/models/params/gridRowParams.d.ts +29 -1
- package/models/props/DataGridProps.d.ts +20 -4
- package/modern/DataGrid/DataGrid.js +18 -3
- package/modern/DataGrid/useDataGridComponent.js +19 -15
- package/modern/DataGrid/useDataGridProps.js +3 -2
- package/modern/colDef/gridNumericOperators.js +1 -1
- package/modern/components/GridRow.js +29 -3
- package/modern/components/base/GridErrorHandler.js +13 -2
- package/modern/components/cell/GridCell.js +2 -2
- package/modern/components/cell/GridEditSingleSelectCell.js +2 -1
- package/modern/components/columnHeaders/GridColumnHeaderItem.js +5 -3
- package/modern/components/containers/GridRootStyles.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +27 -23
- package/modern/components/virtualization/GridVirtualScrollerRenderZone.js +4 -1
- package/modern/constants/gridClasses.js +1 -1
- package/modern/hooks/features/columnMenu/useGridColumnMenu.js +6 -7
- package/modern/hooks/features/columns/gridColumnsSelector.js +11 -10
- package/modern/hooks/features/columns/gridColumnsUtils.js +7 -5
- package/modern/hooks/features/density/useGridDensity.js +3 -4
- package/modern/hooks/features/dimensions/useGridDimensions.js +2 -2
- package/modern/hooks/features/editRows/useGridEditing.js +3 -4
- package/modern/hooks/features/export/serializers/csvSerializer.js +4 -4
- package/modern/hooks/features/filter/gridFilterSelector.js +1 -0
- package/modern/hooks/features/focus/useGridFocus.js +10 -11
- package/modern/hooks/features/keyboard/useGridKeyboardNavigation.js +2 -2
- package/modern/hooks/features/pagination/useGridPage.js +1 -9
- package/modern/hooks/features/pagination/useGridPageSize.js +1 -20
- package/modern/hooks/features/pagination/useGridPagination.js +23 -2
- package/modern/hooks/features/preferencesPanel/useGridPreferencesPanel.js +6 -7
- package/modern/hooks/features/rows/useGridParamsApi.js +3 -10
- package/modern/hooks/features/rows/useGridRows.js +14 -6
- package/modern/hooks/features/rows/useGridRowsMeta.js +36 -24
- package/modern/hooks/features/selection/useGridSelection.js +24 -16
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +4 -4
- package/modern/hooks/utils/useGridApi.js +10 -1
- package/modern/hooks/utils/useGridSelector.js +4 -4
- package/modern/hooks/utils/useGridState.js +10 -1
- package/modern/hooks/utils/{useCurrentPageRows.js → useGridVisibleRows.js} +8 -7
- package/modern/index.js +1 -1
- package/modern/internals/index.js +9 -12
- package/modern/models/colDef/gridDefaultColumnTypes.js +2 -2
- package/modern/utils/createSelector.js +4 -4
- package/modern/utils/getGridLocalization.js +1 -1
- package/node/DataGrid/DataGrid.js +18 -3
- package/node/DataGrid/useDataGridComponent.js +11 -9
- package/node/DataGrid/useDataGridProps.js +3 -2
- package/node/colDef/gridNumericOperators.js +1 -1
- package/node/components/GridRow.js +28 -3
- package/node/components/base/GridErrorHandler.js +11 -1
- package/node/components/cell/GridCell.js +4 -2
- package/node/components/cell/GridEditSingleSelectCell.js +2 -1
- package/node/components/columnHeaders/GridColumnHeaderItem.js +5 -3
- package/node/components/containers/GridRootStyles.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +27 -23
- package/node/components/virtualization/GridVirtualScrollerRenderZone.js +4 -1
- package/node/constants/gridClasses.js +1 -1
- package/node/hooks/features/columnMenu/useGridColumnMenu.js +10 -8
- package/node/hooks/features/columns/gridColumnsSelector.js +11 -9
- package/node/hooks/features/columns/gridColumnsUtils.js +7 -5
- package/node/hooks/features/density/useGridDensity.js +7 -6
- package/node/hooks/features/dimensions/useGridDimensions.js +2 -2
- package/node/hooks/features/editRows/useGridEditing.js +8 -5
- package/node/hooks/features/export/serializers/csvSerializer.js +5 -4
- package/node/hooks/features/filter/gridFilterSelector.js +1 -0
- package/node/hooks/features/focus/useGridFocus.js +15 -13
- package/node/hooks/features/keyboard/useGridKeyboardNavigation.js +2 -2
- package/node/hooks/features/pagination/useGridPage.js +7 -20
- package/node/hooks/features/pagination/useGridPageSize.js +6 -26
- package/node/hooks/features/pagination/useGridPagination.js +31 -1
- package/node/hooks/features/preferencesPanel/useGridPreferencesPanel.js +15 -13
- package/node/hooks/features/rows/useGridParamsApi.js +4 -10
- package/node/hooks/features/rows/useGridRows.js +15 -6
- package/node/hooks/features/rows/useGridRowsMeta.js +47 -26
- package/node/hooks/features/selection/useGridSelection.js +32 -18
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +4 -4
- package/node/hooks/utils/useGridApi.js +11 -1
- package/node/hooks/utils/useGridSelector.js +6 -4
- package/node/hooks/utils/useGridState.js +11 -1
- package/node/hooks/utils/{useCurrentPageRows.js → useGridVisibleRows.js} +11 -10
- package/node/index.js +1 -1
- package/node/internals/index.js +45 -21
- package/node/models/colDef/gridDefaultColumnTypes.js +2 -2
- package/node/utils/createSelector.js +5 -4
- package/node/utils/getGridLocalization.js +2 -2
- package/package.json +2 -2
- package/utils/createSelector.js +4 -4
- package/utils/getGridLocalization.d.ts +2 -1
- package/utils/getGridLocalization.js +2 -2
- package/utils/keyboardUtils.d.ts +1 -1
- package/utils/warning.d.ts +1 -1
- package/hooks/utils/useGridStateInit.d.ts +0 -7
- package/hooks/utils/useGridStateInit.js +0 -9
- package/legacy/hooks/utils/useGridStateInit.js +0 -9
- package/modern/hooks/utils/useGridStateInit.js +0 -9
- package/node/hooks/utils/useGridStateInit.js +0 -23
|
@@ -2,24 +2,23 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
4
4
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
5
|
-
import { useGridStateInit } from '../../utils/useGridStateInit';
|
|
6
5
|
import { useGridRegisterPreProcessor } from '../../core/preProcessing';
|
|
7
6
|
import { gridPreferencePanelStateSelector } from './gridPreferencePanelSelector';
|
|
7
|
+
export const preferencePanelStateInitializer = (state, props) => {
|
|
8
|
+
var _props$initialState$p, _props$initialState;
|
|
9
|
+
|
|
10
|
+
return _extends({}, state, {
|
|
11
|
+
preferencePanel: (_props$initialState$p = (_props$initialState = props.initialState) == null ? void 0 : _props$initialState.preferencePanel) != null ? _props$initialState$p : {
|
|
12
|
+
open: false
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
8
16
|
/**
|
|
9
17
|
* TODO: Add a single `setPreferencePanel` method to avoid multiple `setState`
|
|
10
18
|
*/
|
|
11
19
|
|
|
12
|
-
export const useGridPreferencesPanel =
|
|
20
|
+
export const useGridPreferencesPanel = apiRef => {
|
|
13
21
|
const logger = useGridLogger(apiRef, 'useGridPreferencesPanel');
|
|
14
|
-
useGridStateInit(apiRef, state => {
|
|
15
|
-
var _props$initialState$p, _props$initialState;
|
|
16
|
-
|
|
17
|
-
return _extends({}, state, {
|
|
18
|
-
preferencePanel: (_props$initialState$p = (_props$initialState = props.initialState) == null ? void 0 : _props$initialState.preferencePanel) != null ? _props$initialState$p : {
|
|
19
|
-
open: false
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
22
|
const hideTimeout = React.useRef();
|
|
24
23
|
const immediateTimeout = React.useRef();
|
|
25
24
|
/**
|
|
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { getGridCellElement, getGridColumnHeaderElement, getGridRowElement } from '../../../utils/domUtils';
|
|
3
3
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
4
4
|
import { gridFocusCellSelector, gridTabIndexCellSelector } from '../focus/gridFocusStateSelector';
|
|
5
|
+
import { buildWarning } from '../../../utils/warning';
|
|
5
6
|
let warnedOnceMissingColumn = false;
|
|
6
7
|
|
|
7
8
|
function warnMissingColumn(field) {
|
|
@@ -9,12 +10,7 @@ function warnMissingColumn(field) {
|
|
|
9
10
|
warnedOnceMissingColumn = true;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function warnGetValue() {
|
|
15
|
-
console.warn([`MUI: You are calling getValue. This method is deprecated and will be removed in the next major version.`, `Instead, you can access the data from \`params.row}\`.`].join('\n'));
|
|
16
|
-
warnedOnceGetValue = true;
|
|
17
|
-
}
|
|
13
|
+
const getCellValueWarning = buildWarning([`MUI: You are calling getValue. This method is deprecated and will be removed in the next major version.`, 'Instead, you can access the data from `params.row`.']);
|
|
18
14
|
/**
|
|
19
15
|
* @requires useGridColumns (method)
|
|
20
16
|
* @requires useGridRows (method)
|
|
@@ -24,7 +20,6 @@ function warnGetValue() {
|
|
|
24
20
|
* TODO: Impossible priority - useGridFocus also needs to be after useGridParamsApi
|
|
25
21
|
*/
|
|
26
22
|
|
|
27
|
-
|
|
28
23
|
export function useGridParamsApi(apiRef) {
|
|
29
24
|
const getColumnHeaderParams = React.useCallback(field => ({
|
|
30
25
|
field,
|
|
@@ -36,9 +31,7 @@ export function useGridParamsApi(apiRef) {
|
|
|
36
31
|
|
|
37
32
|
const getCellValueWithDeprecationWarning = React.useCallback((...args) => {
|
|
38
33
|
if (process.env.NODE_ENV !== 'production') {
|
|
39
|
-
|
|
40
|
-
warnGetValue();
|
|
41
|
-
}
|
|
34
|
+
getCellValueWarning();
|
|
42
35
|
}
|
|
43
36
|
|
|
44
37
|
return apiRef.current.getCellValue(...args);
|
|
@@ -6,6 +6,7 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
|
6
6
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
7
7
|
import { gridRowCountSelector, gridRowsLookupSelector, gridRowTreeSelector, gridRowIdsSelector } from './gridRowsSelector';
|
|
8
8
|
import { GridSignature, useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
9
|
+
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
|
|
9
10
|
|
|
10
11
|
function getGridRowId(rowModel, getRowId, detailErrorMessage) {
|
|
11
12
|
const id = getRowId ? getRowId(rowModel) : rowModel.id;
|
|
@@ -50,12 +51,10 @@ const getRowsStateFromCache = (rowsCache, previousTree, apiRef, rowCountProp) =>
|
|
|
50
51
|
const groupingResponse = apiRef.current.unstable_groupRows(_extends({}, value, {
|
|
51
52
|
previousTree
|
|
52
53
|
}));
|
|
53
|
-
const dataTopLevelRowCount = Object.values(groupingResponse.tree).filter(node => node.parent == null).length;
|
|
54
|
-
const totalRowCount = rowCount > groupingResponse.ids.length ? rowCount : groupingResponse.ids.length;
|
|
55
|
-
const totalTopLevelRowCount = rowCount > dataTopLevelRowCount ? rowCount : dataTopLevelRowCount;
|
|
54
|
+
const dataTopLevelRowCount = groupingResponse.treeDepth === 1 ? groupingResponse.ids.length : Object.values(groupingResponse.tree).filter(node => node.parent == null).length;
|
|
56
55
|
return _extends({}, groupingResponse, {
|
|
57
|
-
totalRowCount,
|
|
58
|
-
totalTopLevelRowCount
|
|
56
|
+
totalRowCount: Math.max(rowCount, groupingResponse.ids.length),
|
|
57
|
+
totalTopLevelRowCount: Math.max(rowCount, dataTopLevelRowCount)
|
|
59
58
|
});
|
|
60
59
|
};
|
|
61
60
|
|
|
@@ -94,11 +93,19 @@ export const useGridRows = (apiRef, props) => {
|
|
|
94
93
|
const logger = useGridLogger(apiRef, 'useGridRows');
|
|
95
94
|
const rowsCache = React.useRef(apiRef.current.state.rowsCache); // To avoid listing rowsCache as useEffect dep
|
|
96
95
|
|
|
96
|
+
const currentPage = useGridVisibleRows(apiRef, props);
|
|
97
97
|
const getRow = React.useCallback(id => {
|
|
98
98
|
var _gridRowsLookupSelect;
|
|
99
99
|
|
|
100
100
|
return (_gridRowsLookupSelect = gridRowsLookupSelector(apiRef)[id]) != null ? _gridRowsLookupSelect : null;
|
|
101
101
|
}, [apiRef]);
|
|
102
|
+
const lookup = React.useMemo(() => currentPage.rows.reduce((acc, {
|
|
103
|
+
id
|
|
104
|
+
}, index) => {
|
|
105
|
+
acc[id] = index;
|
|
106
|
+
return acc;
|
|
107
|
+
}, {}), [currentPage.rows]);
|
|
108
|
+
const getRowIndexRelativeToVisibleRows = React.useCallback(id => lookup[id], [lookup]);
|
|
102
109
|
const throttledRowsChange = React.useCallback((newState, throttle) => {
|
|
103
110
|
const run = () => {
|
|
104
111
|
rowsCache.current.timeout = null;
|
|
@@ -284,7 +291,8 @@ export const useGridRows = (apiRef, props) => {
|
|
|
284
291
|
setRows,
|
|
285
292
|
updateRows,
|
|
286
293
|
setRowChildrenExpansion,
|
|
287
|
-
getRowNode
|
|
294
|
+
getRowNode,
|
|
295
|
+
getRowIndexRelativeToVisibleRows
|
|
288
296
|
};
|
|
289
297
|
useGridApiMethod(apiRef, rowApi, 'GridRowApi');
|
|
290
298
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { GridApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
3
3
|
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
4
|
+
import { GridStateInitializer } from '../../utils/useGridInitializeState';
|
|
5
|
+
export declare const rowsMetaStateInitializer: GridStateInitializer;
|
|
4
6
|
/**
|
|
5
7
|
* @requires useGridPageSize (method)
|
|
6
8
|
* @requires useGridPage (method)
|
|
7
9
|
*/
|
|
8
|
-
export declare const useGridRowsMeta: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'getRowHeight' | 'pagination' | 'paginationMode'>) => void;
|
|
10
|
+
export declare const useGridRowsMeta: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'getRowHeight' | 'getRowSpacing' | 'pagination' | 'paginationMode'>) => void;
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
|
|
4
4
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
5
5
|
import { useGridSelector } from '../../utils/useGridSelector';
|
|
6
6
|
import { gridDensityRowHeightSelector, gridDensityFactorSelector } from '../density/densitySelector';
|
|
7
7
|
import { gridFilterStateSelector } from '../filter/gridFilterSelector';
|
|
8
8
|
import { gridPaginationSelector } from '../pagination/gridPaginationSelector';
|
|
9
9
|
import { gridSortingStateSelector } from '../sorting/gridSortingSelector';
|
|
10
|
-
import { useGridStateInit } from '../../utils/useGridStateInit';
|
|
11
10
|
import { GridEvents } from '../../../models/events/gridEvents';
|
|
12
11
|
import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
12
|
+
export const rowsMetaStateInitializer = state => _extends({}, state, {
|
|
13
|
+
rowsMeta: {
|
|
14
|
+
currentPageTotalHeight: 0,
|
|
15
|
+
positions: []
|
|
16
|
+
}
|
|
17
|
+
});
|
|
13
18
|
/**
|
|
14
19
|
* @requires useGridPageSize (method)
|
|
15
20
|
* @requires useGridPage (method)
|
|
@@ -18,32 +23,20 @@ import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
|
18
23
|
export const useGridRowsMeta = (apiRef, props) => {
|
|
19
24
|
const {
|
|
20
25
|
getRowHeight,
|
|
21
|
-
|
|
22
|
-
paginationMode
|
|
26
|
+
getRowSpacing
|
|
23
27
|
} = props;
|
|
24
28
|
const rowsHeightLookup = React.useRef({});
|
|
25
29
|
const rowHeight = useGridSelector(apiRef, gridDensityRowHeightSelector);
|
|
26
30
|
const filterState = useGridSelector(apiRef, gridFilterStateSelector);
|
|
27
31
|
const paginationState = useGridSelector(apiRef, gridPaginationSelector);
|
|
28
32
|
const sortingState = useGridSelector(apiRef, gridSortingStateSelector);
|
|
29
|
-
|
|
30
|
-
rowsMeta: {
|
|
31
|
-
currentPageTotalHeight: 0,
|
|
32
|
-
positions: []
|
|
33
|
-
}
|
|
34
|
-
}));
|
|
33
|
+
const currentPage = useGridVisibleRows(apiRef, props);
|
|
35
34
|
const hydrateRowsMeta = React.useCallback(() => {
|
|
36
|
-
const {
|
|
37
|
-
rows
|
|
38
|
-
} = getCurrentPageRows(apiRef, {
|
|
39
|
-
pagination,
|
|
40
|
-
paginationMode
|
|
41
|
-
});
|
|
42
35
|
apiRef.current.setState(state => {
|
|
43
36
|
const positions = [];
|
|
44
37
|
const densityFactor = gridDensityFactorSelector(state, apiRef.current.instanceId);
|
|
45
38
|
const currentRowHeight = gridDensityRowHeightSelector(state, apiRef.current.instanceId);
|
|
46
|
-
const currentPageTotalHeight = rows.reduce((acc, row) => {
|
|
39
|
+
const currentPageTotalHeight = currentPage.rows.reduce((acc, row) => {
|
|
47
40
|
positions.push(acc);
|
|
48
41
|
let baseRowHeight;
|
|
49
42
|
const isResized = rowsHeightLookup.current[row.id] && rowsHeightLookup.current[row.id].isResized || false;
|
|
@@ -62,15 +55,30 @@ export const useGridRowsMeta = (apiRef, props) => {
|
|
|
62
55
|
densityFactor
|
|
63
56
|
}))) != null ? _getRowHeight : currentRowHeight;
|
|
64
57
|
}
|
|
65
|
-
}
|
|
58
|
+
} // We use an object to make simple to check if a height is already added or not
|
|
66
59
|
|
|
67
|
-
|
|
60
|
+
|
|
61
|
+
const initialHeights = {
|
|
68
62
|
base: baseRowHeight
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
if (getRowSpacing) {
|
|
66
|
+
var _spacing$top, _spacing$bottom;
|
|
67
|
+
|
|
68
|
+
const index = apiRef.current.getRowIndexRelativeToVisibleRows(row.id);
|
|
69
|
+
const spacing = getRowSpacing(_extends({}, row, {
|
|
70
|
+
isFirstVisible: index === 0,
|
|
71
|
+
isLastVisible: index === currentPage.rows.length - 1
|
|
72
|
+
}));
|
|
73
|
+
initialHeights.spacingTop = (_spacing$top = spacing.top) != null ? _spacing$top : 0;
|
|
74
|
+
initialHeights.spacingBottom = (_spacing$bottom = spacing.bottom) != null ? _spacing$bottom : 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const sizes = apiRef.current.unstable_applyPreProcessors('rowHeight', initialHeights, row);
|
|
78
|
+
const finalRowHeight = Object.values(sizes).reduce((acc2, value) => acc2 + value, 0);
|
|
72
79
|
rowsHeightLookup.current[row.id] = {
|
|
73
80
|
value: baseRowHeight,
|
|
81
|
+
sizes,
|
|
74
82
|
isResized
|
|
75
83
|
};
|
|
76
84
|
return acc + finalRowHeight;
|
|
@@ -83,7 +91,7 @@ export const useGridRowsMeta = (apiRef, props) => {
|
|
|
83
91
|
});
|
|
84
92
|
});
|
|
85
93
|
apiRef.current.forceUpdate();
|
|
86
|
-
}, [apiRef,
|
|
94
|
+
}, [apiRef, currentPage.rows, getRowSpacing, getRowHeight]);
|
|
87
95
|
|
|
88
96
|
const getTargetRowHeight = rowId => {
|
|
89
97
|
var _rowsHeightLookup$cur;
|
|
@@ -91,10 +99,19 @@ export const useGridRowsMeta = (apiRef, props) => {
|
|
|
91
99
|
return ((_rowsHeightLookup$cur = rowsHeightLookup.current[rowId]) == null ? void 0 : _rowsHeightLookup$cur.value) || rowHeight;
|
|
92
100
|
};
|
|
93
101
|
|
|
102
|
+
const getRowInternalSizes = rowId => {
|
|
103
|
+
var _rowsHeightLookup$cur2;
|
|
104
|
+
|
|
105
|
+
return (_rowsHeightLookup$cur2 = rowsHeightLookup.current[rowId]) == null ? void 0 : _rowsHeightLookup$cur2.sizes;
|
|
106
|
+
};
|
|
107
|
+
|
|
94
108
|
const setRowHeight = React.useCallback((id, height) => {
|
|
95
109
|
rowsHeightLookup.current[id] = {
|
|
96
110
|
value: height,
|
|
97
|
-
isResized: true
|
|
111
|
+
isResized: true,
|
|
112
|
+
sizes: _extends({}, rowsHeightLookup.current[id].sizes, {
|
|
113
|
+
base: height
|
|
114
|
+
})
|
|
98
115
|
};
|
|
99
116
|
hydrateRowsMeta();
|
|
100
117
|
}, [hydrateRowsMeta]); // The effect is used to build the rows meta data - currentPageTotalHeight and positions.
|
|
@@ -113,6 +130,7 @@ export const useGridRowsMeta = (apiRef, props) => {
|
|
|
113
130
|
useGridApiEventHandler(apiRef, GridEvents.preProcessorRegister, handlePreProcessorRegister);
|
|
114
131
|
const rowsMetaApi = {
|
|
115
132
|
unstable_getRowHeight: getTargetRowHeight,
|
|
133
|
+
unstable_getRowInternalSizes: getRowInternalSizes,
|
|
116
134
|
unstable_setRowHeight: setRowHeight
|
|
117
135
|
};
|
|
118
136
|
useGridApiMethod(apiRef, rowsMetaApi, 'GridRowsMetaApi');
|
|
@@ -5,4 +5,4 @@ export declare const selectedGridRowsCountSelector: import("../../../utils/creat
|
|
|
5
5
|
export declare const selectedGridRowsSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, Map<GridRowId, {
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}>>;
|
|
8
|
-
export declare const selectedIdsLookupSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity,
|
|
8
|
+
export declare const selectedIdsLookupSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, Record<GridRowId, GridRowId>>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
3
3
|
import { GridApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
4
|
+
import { GridStateInitializer } from '../../utils/useGridInitializeState';
|
|
5
|
+
export declare const selectionStateInitializer: GridStateInitializer<Pick<DataGridProcessedProps, 'selectionModel'>>;
|
|
4
6
|
/**
|
|
5
7
|
* @requires useGridRows (state, method)
|
|
6
8
|
* @requires useGridParamsApi (method)
|
|
@@ -10,10 +10,33 @@ import { gridSelectionStateSelector, selectedGridRowsSelector, selectedIdsLookup
|
|
|
10
10
|
import { gridPaginatedVisibleSortedGridRowIdsSelector } from '../pagination';
|
|
11
11
|
import { gridVisibleSortedRowIdsSelector } from '../filter/gridFilterSelector';
|
|
12
12
|
import { GRID_CHECKBOX_SELECTION_COL_DEF, GRID_ACTIONS_COLUMN_TYPE } from '../../../colDef';
|
|
13
|
-
import { useGridStateInit } from '../../utils/useGridStateInit';
|
|
14
13
|
import { GridCellModes } from '../../../models/gridEditRowModel';
|
|
15
14
|
import { isKeyboardEvent } from '../../../utils/keyboardUtils';
|
|
16
|
-
import {
|
|
15
|
+
import { getVisibleRows } from '../../utils/useGridVisibleRows';
|
|
16
|
+
|
|
17
|
+
const getSelectionModelPropValue = (selectionModelProp, prevSelectionModel) => {
|
|
18
|
+
if (selectionModelProp == null) {
|
|
19
|
+
return selectionModelProp;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (Array.isArray(selectionModelProp)) {
|
|
23
|
+
return selectionModelProp;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (prevSelectionModel && prevSelectionModel[0] === selectionModelProp) {
|
|
27
|
+
return prevSelectionModel;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return [selectionModelProp];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const selectionStateInitializer = (state, props) => {
|
|
34
|
+
var _getSelectionModelPro;
|
|
35
|
+
|
|
36
|
+
return _extends({}, state, {
|
|
37
|
+
selection: (_getSelectionModelPro = getSelectionModelPropValue(props.selectionModel)) != null ? _getSelectionModelPro : []
|
|
38
|
+
});
|
|
39
|
+
};
|
|
17
40
|
/**
|
|
18
41
|
* @requires useGridRows (state, method)
|
|
19
42
|
* @requires useGridParamsApi (method)
|
|
@@ -22,19 +45,8 @@ import { getCurrentPageRows } from '../../utils/useCurrentPageRows';
|
|
|
22
45
|
export const useGridSelection = (apiRef, props) => {
|
|
23
46
|
const logger = useGridLogger(apiRef, 'useGridSelection');
|
|
24
47
|
const propSelectionModel = React.useMemo(() => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (Array.isArray(props.selectionModel)) {
|
|
30
|
-
return props.selectionModel;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return [props.selectionModel];
|
|
34
|
-
}, [props.selectionModel]);
|
|
35
|
-
useGridStateInit(apiRef, state => _extends({}, state, {
|
|
36
|
-
selection: propSelectionModel != null ? propSelectionModel : []
|
|
37
|
-
}));
|
|
48
|
+
return getSelectionModelPropValue(props.selectionModel, gridSelectionStateSelector(apiRef.current.state));
|
|
49
|
+
}, [apiRef, props.selectionModel]);
|
|
38
50
|
const lastRowToggled = React.useRef(null);
|
|
39
51
|
apiRef.current.unstable_updateControlState({
|
|
40
52
|
stateId: 'selection',
|
|
@@ -323,7 +335,7 @@ export const useGridSelection = (apiRef, props) => {
|
|
|
323
335
|
if (!canHaveMultipleSelection && currentSelection.length > 1) {
|
|
324
336
|
const {
|
|
325
337
|
rows: currentPageRows
|
|
326
|
-
} =
|
|
338
|
+
} = getVisibleRows(apiRef, {
|
|
327
339
|
pagination,
|
|
328
340
|
paginationMode
|
|
329
341
|
});
|
|
@@ -40,6 +40,7 @@ export declare const useGridVirtualScroller: (props: UseGridVirtualScrollerProps
|
|
|
40
40
|
animationIterationCount?: import("csstype").Property.AnimationIterationCount | undefined;
|
|
41
41
|
animationName?: import("csstype").Property.AnimationName | undefined;
|
|
42
42
|
animationPlayState?: import("csstype").Property.AnimationPlayState | undefined;
|
|
43
|
+
animationTimeline?: import("csstype").Property.AnimationTimeline | undefined;
|
|
43
44
|
animationTimingFunction?: import("csstype").Property.AnimationTimingFunction | undefined;
|
|
44
45
|
appearance?: import("csstype").Property.Appearance | undefined;
|
|
45
46
|
aspectRatio?: import("csstype").Property.AspectRatio | undefined;
|
|
@@ -114,7 +115,7 @@ export declare const useGridVirtualScroller: (props: UseGridVirtualScrollerProps
|
|
|
114
115
|
clear?: import("csstype").Property.Clear | undefined;
|
|
115
116
|
clipPath?: import("csstype").Property.ClipPath | undefined;
|
|
116
117
|
color?: import("csstype").Property.Color | undefined;
|
|
117
|
-
colorAdjust?: import("csstype").Property.
|
|
118
|
+
colorAdjust?: import("csstype").Property.PrintColorAdjust | undefined;
|
|
118
119
|
colorScheme?: import("csstype").Property.ColorScheme | undefined;
|
|
119
120
|
columnCount?: import("csstype").Property.ColumnCount | undefined;
|
|
120
121
|
columnFill?: import("csstype").Property.ColumnFill | undefined;
|
|
@@ -153,6 +154,7 @@ export declare const useGridVirtualScroller: (props: UseGridVirtualScrollerProps
|
|
|
153
154
|
fontStyle?: import("csstype").Property.FontStyle | undefined;
|
|
154
155
|
fontSynthesis?: import("csstype").Property.FontSynthesis | undefined;
|
|
155
156
|
fontVariant?: import("csstype").Property.FontVariant | undefined;
|
|
157
|
+
fontVariantAlternates?: import("csstype").Property.FontVariantAlternates | undefined;
|
|
156
158
|
fontVariantCaps?: import("csstype").Property.FontVariantCaps | undefined;
|
|
157
159
|
fontVariantEastAsian?: import("csstype").Property.FontVariantEastAsian | undefined;
|
|
158
160
|
fontVariantLigatures?: import("csstype").Property.FontVariantLigatures | undefined;
|
|
@@ -173,12 +175,14 @@ export declare const useGridVirtualScroller: (props: UseGridVirtualScrollerProps
|
|
|
173
175
|
gridTemplateRows?: import("csstype").Property.GridTemplateRows<string | number> | undefined;
|
|
174
176
|
hangingPunctuation?: import("csstype").Property.HangingPunctuation | undefined;
|
|
175
177
|
height?: import("csstype").Property.Height<string | number> | undefined;
|
|
178
|
+
hyphenateCharacter?: import("csstype").Property.HyphenateCharacter | undefined;
|
|
176
179
|
hyphens?: import("csstype").Property.Hyphens | undefined;
|
|
177
180
|
imageOrientation?: import("csstype").Property.ImageOrientation | undefined;
|
|
178
181
|
imageRendering?: import("csstype").Property.ImageRendering | undefined;
|
|
179
182
|
imageResolution?: import("csstype").Property.ImageResolution | undefined;
|
|
180
183
|
initialLetter?: import("csstype").Property.InitialLetter | undefined;
|
|
181
184
|
inlineSize?: import("csstype").Property.InlineSize<string | number> | undefined;
|
|
185
|
+
inputSecurity?: import("csstype").Property.InputSecurity | undefined;
|
|
182
186
|
inset?: import("csstype").Property.Inset<string | number> | undefined;
|
|
183
187
|
insetBlock?: import("csstype").Property.InsetBlock<string | number> | undefined;
|
|
184
188
|
insetBlockEnd?: import("csstype").Property.InsetBlockEnd<string | number> | undefined;
|
|
@@ -283,6 +287,7 @@ export declare const useGridVirtualScroller: (props: UseGridVirtualScrollerProps
|
|
|
283
287
|
placeContent?: import("csstype").Property.PlaceContent | undefined;
|
|
284
288
|
pointerEvents?: import("csstype").Property.PointerEvents | undefined;
|
|
285
289
|
position?: import("csstype").Property.Position | undefined;
|
|
290
|
+
printColorAdjust?: import("csstype").Property.PrintColorAdjust | undefined;
|
|
286
291
|
quotes?: import("csstype").Property.Quotes | undefined;
|
|
287
292
|
resize?: import("csstype").Property.Resize | undefined;
|
|
288
293
|
right?: import("csstype").Property.Right<string | number> | undefined;
|
|
@@ -591,6 +596,7 @@ export declare const useGridVirtualScroller: (props: UseGridVirtualScrollerProps
|
|
|
591
596
|
WebkitFontKerning?: import("csstype").Property.FontKerning | undefined;
|
|
592
597
|
WebkitFontSmoothing?: import("csstype").Property.FontSmooth<string | number> | undefined;
|
|
593
598
|
WebkitFontVariantLigatures?: import("csstype").Property.FontVariantLigatures | undefined;
|
|
599
|
+
WebkitHyphenateCharacter?: import("csstype").Property.HyphenateCharacter | undefined;
|
|
594
600
|
WebkitHyphens?: import("csstype").Property.Hyphens | undefined;
|
|
595
601
|
WebkitInitialLetter?: import("csstype").Property.InitialLetter | undefined;
|
|
596
602
|
WebkitJustifyContent?: import("csstype").Property.JustifyContent | undefined;
|
|
@@ -622,7 +628,7 @@ export declare const useGridVirtualScroller: (props: UseGridVirtualScrollerProps
|
|
|
622
628
|
WebkitPaddingStart?: import("csstype").Property.PaddingInlineStart<string | number> | undefined;
|
|
623
629
|
WebkitPerspective?: import("csstype").Property.Perspective<string | number> | undefined;
|
|
624
630
|
WebkitPerspectiveOrigin?: import("csstype").Property.PerspectiveOrigin<string | number> | undefined;
|
|
625
|
-
WebkitPrintColorAdjust?: import("csstype").Property.
|
|
631
|
+
WebkitPrintColorAdjust?: import("csstype").Property.PrintColorAdjust | undefined;
|
|
626
632
|
WebkitRubyPosition?: import("csstype").Property.RubyPosition | undefined;
|
|
627
633
|
WebkitScrollSnapType?: import("csstype").Property.ScrollSnapType | undefined;
|
|
628
634
|
WebkitShapeMargin?: import("csstype").Property.ShapeMargin<string | number> | undefined;
|
|
@@ -687,7 +693,6 @@ export declare const useGridVirtualScroller: (props: UseGridVirtualScrollerProps
|
|
|
687
693
|
boxOrient?: import("csstype").Property.BoxOrient | undefined;
|
|
688
694
|
boxPack?: import("csstype").Property.BoxPack | undefined;
|
|
689
695
|
clip?: import("csstype").Property.Clip | undefined;
|
|
690
|
-
fontVariantAlternates?: import("csstype").Property.FontVariantAlternates | undefined;
|
|
691
696
|
gridColumnGap?: import("csstype").Property.GridColumnGap<string | number> | undefined;
|
|
692
697
|
gridGap?: import("csstype").Property.GridGap<string | number> | undefined;
|
|
693
698
|
gridRowGap?: import("csstype").Property.GridRowGap<string | number> | undefined;
|
|
@@ -10,7 +10,7 @@ import { gridVisibleColumnDefinitionsSelector, gridColumnsTotalWidthSelector, gr
|
|
|
10
10
|
import { gridDensityRowHeightSelector } from '../density/densitySelector';
|
|
11
11
|
import { gridFocusCellSelector, gridTabIndexCellSelector } from '../focus/gridFocusStateSelector';
|
|
12
12
|
import { gridEditRowsStateSelector } from '../editRows/gridEditRowsSelector';
|
|
13
|
-
import {
|
|
13
|
+
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
|
|
14
14
|
import { GridEvents } from '../../../models/events';
|
|
15
15
|
import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
16
16
|
import { clamp } from '../../../utils/utils';
|
|
@@ -53,7 +53,7 @@ export const useGridVirtualScroller = props => {
|
|
|
53
53
|
const rowsMeta = useGridSelector(apiRef, gridRowsMetaSelector);
|
|
54
54
|
const editRowsState = useGridSelector(apiRef, gridEditRowsStateSelector);
|
|
55
55
|
const selectedRowsLookup = useGridSelector(apiRef, selectedIdsLookupSelector);
|
|
56
|
-
const currentPage =
|
|
56
|
+
const currentPage = useGridVisibleRows(apiRef, rootProps);
|
|
57
57
|
const renderZoneRef = React.useRef(null);
|
|
58
58
|
const rootRef = React.useRef(null);
|
|
59
59
|
const handleRef = useForkRef(ref, rootRef);
|
|
@@ -126,7 +126,7 @@ export const useGridVirtualScroller = props => {
|
|
|
126
126
|
firstIndex: nextRenderContext.firstRowIndex,
|
|
127
127
|
lastIndex: nextRenderContext.lastRowIndex,
|
|
128
128
|
minFirstIndex: 0,
|
|
129
|
-
maxLastIndex: (_currentPage$range = currentPage.range) == null ? void 0 : _currentPage$range.lastRowIndex,
|
|
129
|
+
maxLastIndex: ((_currentPage$range = currentPage.range) == null ? void 0 : _currentPage$range.lastRowIndex) || 0,
|
|
130
130
|
buffer: rootProps.rowBuffer
|
|
131
131
|
});
|
|
132
132
|
const [firstColumnToRender] = getRenderableIndexes({
|
|
@@ -271,7 +271,7 @@ export const useGridVirtualScroller = props => {
|
|
|
271
271
|
firstColumnToRender: firstColumnToRender,
|
|
272
272
|
lastColumnToRender: lastColumnToRender,
|
|
273
273
|
selected: isSelected,
|
|
274
|
-
index: currentPage.range.firstRowIndex +
|
|
274
|
+
index: currentPage.range.firstRowIndex + firstRowToRender + i,
|
|
275
275
|
containerWidth: availableSpace,
|
|
276
276
|
isLastVisible: lastVisibleRowIndex
|
|
277
277
|
}, typeof getRowProps === 'function' ? getRowProps(id, model) : {}, (_rootProps$components = rootProps.componentsProps) == null ? void 0 : _rootProps$components.row), id));
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
import { buildWarning } from '../../utils/warning';
|
|
2
|
+
const deprecationWarning = buildWarning(['MUI: The hook useGridApi is deprecated and will be removed in the next major version.', 'Access the ref content with apiRef.current instead']);
|
|
1
3
|
/**
|
|
2
4
|
* @deprecated Use `apiRef.current` instead.
|
|
3
5
|
*/
|
|
4
|
-
|
|
6
|
+
|
|
7
|
+
export const useGridApi = apiRef => {
|
|
8
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
9
|
+
deprecationWarning();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return apiRef.current;
|
|
13
|
+
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { GridApiCommon } from '../../models/api/gridApiCommon';
|
|
3
3
|
import { GridApiCommunity } from '../../models/api/gridApiCommunity';
|
|
4
|
+
import { DataGridProcessedProps } from '../../models/props/DataGridProps';
|
|
4
5
|
declare type DeepPartial<T> = {
|
|
5
6
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
6
7
|
};
|
|
7
|
-
export declare type GridStateInitializer<P, Api extends GridApiCommon = GridApiCommunity> = (state: DeepPartial<Api['state']>, props: P, apiRef: React.MutableRefObject<Api>) => DeepPartial<Api['state']>;
|
|
8
|
+
export declare type GridStateInitializer<P extends Partial<DataGridProcessedProps> = DataGridProcessedProps, Api extends GridApiCommon = GridApiCommunity> = (state: DeepPartial<Api['state']>, props: P, apiRef: React.MutableRefObject<Api>) => DeepPartial<Api['state']>;
|
|
8
9
|
export declare const useGridInitializeState: <P, Api extends GridApiCommon = GridApiCommunity>(initializer: GridStateInitializer<P, Api>, apiRef: React.MutableRefObject<Api>, props: P) => void;
|
|
9
10
|
export {};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { buildWarning } from '../../utils/warning';
|
|
2
2
|
|
|
3
3
|
function isOutputSelector(selector) {
|
|
4
4
|
return selector.cache;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
const stateNotInitializedWarning = buildWarning(['MUI: `useGridSelector` has been called before the initialization of the state.', 'This hook can only be used inside the context of the grid.']);
|
|
7
8
|
export const useGridSelector = (apiRef, selector) => {
|
|
8
9
|
if (process.env.NODE_ENV !== 'production') {
|
|
9
|
-
if (!
|
|
10
|
-
|
|
11
|
-
console.warn(['MUI: `useGridSelector` has been called before the initialization of the state.', 'This hook can only be used inside the context of the grid.'].join('\n'));
|
|
10
|
+
if (!apiRef.current.state) {
|
|
11
|
+
stateNotInitializedWarning();
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
import { buildWarning } from '../../utils/warning';
|
|
2
|
+
const deprecationWarning = buildWarning(['MUI: The hook useGridState is deprecated and will be removed in the next major version.', 'The two lines below are equivalent', '', 'const [state, setState, forceUpdate] = useGridState(apiRef);', 'const { state, setState, forceUpdate } = apiRef.current']);
|
|
1
3
|
/**
|
|
2
4
|
* @deprecated Use `apiRef.current.state`, `apiRef.current.setState` and `apiRef.current.forceUpdate` instead.
|
|
3
5
|
*/
|
|
4
|
-
|
|
6
|
+
|
|
7
|
+
export const useGridState = apiRef => {
|
|
8
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
9
|
+
deprecationWarning();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return [apiRef.current.state, apiRef.current.setState, apiRef.current.forceUpdate];
|
|
13
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { DataGridProcessedProps } from '../../models/props/DataGridProps';
|
|
3
3
|
import type { GridApiCommon, GridRowEntry } from '../../models';
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const getVisibleRows: <Api extends GridApiCommon>(apiRef: React.MutableRefObject<Api>, props: Pick<DataGridProcessedProps, 'pagination' | 'paginationMode'>) => {
|
|
5
5
|
rows: GridRowEntry[];
|
|
6
6
|
range: {
|
|
7
7
|
firstRowIndex: number;
|
|
@@ -9,12 +9,13 @@ export declare const getCurrentPageRows: <Api extends GridApiCommon>(apiRef: Rea
|
|
|
9
9
|
} | null;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* - If the
|
|
15
|
-
* - If the row tree
|
|
12
|
+
* Computes the list of rows that are reachable by scroll.
|
|
13
|
+
* Depending on whether pagination is enabled, it will return the rows in the current page.
|
|
14
|
+
* - If the pagination is disabled or in server mode, it equals all the visible rows.
|
|
15
|
+
* - If the row tree has several layers, it contains up to `state.pageSize` top level rows and all their descendants.
|
|
16
|
+
* - If the row tree is flat, it only contains up to `state.pageSize` rows.
|
|
16
17
|
*/
|
|
17
|
-
export declare const
|
|
18
|
+
export declare const useGridVisibleRows: <Api extends GridApiCommon>(apiRef: React.MutableRefObject<Api>, props: Pick<DataGridProcessedProps, 'pagination' | 'paginationMode'>) => {
|
|
18
19
|
rows: GridRowEntry[];
|
|
19
20
|
range: {
|
|
20
21
|
firstRowIndex: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { gridPaginationRowRangeSelector, gridPaginatedVisibleSortedGridRowEntriesSelector } from '../features/pagination/gridPaginationSelector';
|
|
3
3
|
import { gridVisibleSortedRowEntriesSelector } from '../features/filter/gridFilterSelector';
|
|
4
|
-
export const
|
|
4
|
+
export const getVisibleRows = (apiRef, props) => {
|
|
5
5
|
let rows;
|
|
6
6
|
let range;
|
|
7
7
|
|
|
@@ -27,14 +27,15 @@ export const getCurrentPageRows = (apiRef, props) => {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* - If the
|
|
33
|
-
* - If the row tree
|
|
30
|
+
* Computes the list of rows that are reachable by scroll.
|
|
31
|
+
* Depending on whether pagination is enabled, it will return the rows in the current page.
|
|
32
|
+
* - If the pagination is disabled or in server mode, it equals all the visible rows.
|
|
33
|
+
* - If the row tree has several layers, it contains up to `state.pageSize` top level rows and all their descendants.
|
|
34
|
+
* - If the row tree is flat, it only contains up to `state.pageSize` rows.
|
|
34
35
|
*/
|
|
35
36
|
|
|
36
|
-
export const
|
|
37
|
-
const response =
|
|
37
|
+
export const useGridVisibleRows = (apiRef, props) => {
|
|
38
|
+
const response = getVisibleRows(apiRef, props);
|
|
38
39
|
return React.useMemo(() => ({
|
|
39
40
|
rows: response.rows,
|
|
40
41
|
range: response.range
|
package/index.js
CHANGED