@mui/x-data-grid 7.0.0-beta.6 → 7.0.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 +311 -12
- package/DataGrid/DataGrid.js +57 -17
- package/DataGrid/useDataGridComponent.js +3 -0
- package/DataGrid/useDataGridProps.js +6 -7
- package/README.md +1 -1
- package/components/GridColumnHeaders.d.ts +1 -2
- package/components/GridColumnHeaders.js +6 -17
- package/components/GridFooter.js +2 -3
- package/components/GridHeader.js +1 -2
- package/components/GridHeaders.js +1 -4
- package/components/GridPagination.d.ts +6 -5
- package/components/GridPagination.js +14 -11
- package/components/GridRow.d.ts +1 -1
- package/components/GridRow.js +17 -36
- package/components/GridScrollArea.d.ts +10 -0
- package/components/GridScrollArea.js +150 -0
- package/components/base/GridFooterPlaceholder.js +1 -2
- package/components/base/GridOverlays.js +3 -6
- package/components/cell/GridActionsCell.js +4 -6
- package/components/cell/GridActionsCellItem.d.ts +8 -25
- package/components/cell/GridActionsCellItem.js +8 -5
- package/components/cell/GridBooleanCell.d.ts +1 -0
- package/components/cell/GridBooleanCell.js +3 -2
- package/components/cell/GridCell.d.ts +7 -0
- package/components/cell/GridCell.js +18 -11
- package/components/cell/GridEditBooleanCell.js +1 -2
- package/components/cell/GridEditDateCell.js +2 -3
- package/components/cell/GridEditInputCell.js +2 -2
- package/components/cell/GridEditSingleSelectCell.js +5 -8
- package/components/columnHeaders/ColumnHeaderMenuIcon.js +2 -3
- package/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
- package/components/columnHeaders/GridColumnGroupHeader.d.ts +5 -0
- package/components/columnHeaders/GridColumnGroupHeader.js +22 -13
- package/components/columnHeaders/GridColumnHeaderFilterIconButton.js +2 -3
- package/components/columnHeaders/GridColumnHeaderItem.d.ts +5 -0
- package/components/columnHeaders/GridColumnHeaderItem.js +26 -12
- package/components/columnHeaders/GridColumnHeaderSortIcon.js +1 -2
- package/components/columnHeaders/GridColumnHeaderTitle.js +2 -3
- package/components/columnHeaders/GridGenericColumnHeaderItem.d.ts +1 -0
- package/components/columnHeaders/GridGenericColumnHeaderItem.js +7 -6
- package/components/columnSelection/GridCellCheckboxRenderer.js +3 -5
- package/components/columnSelection/GridHeaderCheckbox.js +1 -2
- package/components/columnsManagement/GridColumnsManagement.js +17 -21
- package/components/containers/GridRoot.js +3 -3
- package/components/containers/GridRootStyles.js +12 -20
- package/components/menu/GridMenu.js +4 -6
- package/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
- package/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.js +2 -3
- package/components/panel/GridColumnsPanel.js +1 -2
- package/components/panel/GridPanel.d.ts +1 -10
- package/components/panel/GridPanel.js +1 -2
- package/components/panel/GridPreferencesPanel.js +2 -3
- package/components/panel/filterPanel/GridFilterForm.js +24 -27
- package/components/panel/filterPanel/GridFilterInputBoolean.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputBoolean.js +6 -7
- package/components/panel/filterPanel/GridFilterInputDate.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputDate.js +3 -4
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +11 -15
- package/components/panel/filterPanel/GridFilterInputMultipleValue.js +10 -14
- package/components/panel/filterPanel/GridFilterInputSingleSelect.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputSingleSelect.js +10 -11
- package/components/panel/filterPanel/GridFilterInputValue.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputValue.js +5 -7
- package/components/panel/filterPanel/GridFilterPanel.js +5 -9
- package/components/panel/filterPanel/filterPanelUtils.js +1 -1
- package/components/toolbar/GridToolbarColumnsButton.js +3 -5
- package/components/toolbar/GridToolbarDensitySelector.js +8 -10
- package/components/toolbar/GridToolbarExport.js +2 -2
- package/components/toolbar/GridToolbarExportContainer.js +3 -5
- package/components/toolbar/GridToolbarFilterButton.js +3 -5
- package/components/toolbar/GridToolbarQuickFilter.js +4 -5
- package/components/virtualization/GridVirtualScrollbar.js +4 -0
- package/components/virtualization/GridVirtualScroller.js +6 -1
- package/components/virtualization/GridVirtualScrollerContent.js +1 -2
- package/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/components/virtualization/GridVirtualScrollerRenderZone.js +1 -2
- package/constants/gridClasses.d.ts +6 -32
- package/constants/gridClasses.js +1 -1
- package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +5 -1
- package/hooks/core/strategyProcessing/useGridStrategyProcessing.js +1 -2
- package/hooks/core/useGridApiInitialization.js +4 -6
- package/hooks/features/clipboard/useGridClipboard.js +6 -5
- package/hooks/features/columnGrouping/gridColumnGroupsSelector.js +4 -16
- package/hooks/features/columnGrouping/gridColumnGroupsUtils.js +4 -8
- package/hooks/features/columnGrouping/useGridColumnGrouping.js +12 -23
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +23 -7
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +186 -101
- package/hooks/features/columnMenu/useGridColumnMenuSlots.js +2 -2
- package/hooks/features/columnResize/columnResizeSelector.d.ts +3 -0
- package/hooks/features/columnResize/columnResizeSelector.js +3 -0
- package/hooks/features/columnResize/columnResizeState.d.ts +3 -0
- package/hooks/features/columnResize/columnResizeState.js +1 -0
- package/hooks/features/columnResize/gridColumnResizeApi.d.ts +44 -0
- package/hooks/features/columnResize/gridColumnResizeApi.js +10 -0
- package/hooks/features/columnResize/index.d.ts +3 -0
- package/hooks/features/columnResize/index.js +3 -0
- package/hooks/features/columnResize/useGridColumnResize.d.ts +10 -0
- package/hooks/features/columnResize/useGridColumnResize.js +553 -0
- package/hooks/features/columns/gridColumnsSelector.js +1 -2
- package/hooks/features/columns/gridColumnsUtils.d.ts +0 -9
- package/hooks/features/columns/gridColumnsUtils.js +5 -22
- package/hooks/features/columns/useGridColumnSpanning.js +1 -2
- package/hooks/features/columns/useGridColumns.js +11 -19
- package/hooks/features/density/densitySelector.d.ts +4 -2
- package/hooks/features/density/densitySelector.js +8 -2
- package/hooks/features/density/densityState.d.ts +1 -4
- package/hooks/features/density/useGridDensity.d.ts +2 -4
- package/hooks/features/density/useGridDensity.js +21 -29
- package/hooks/features/dimensions/useGridDimensions.js +7 -10
- package/hooks/features/editing/useGridCellEditing.js +25 -8
- package/hooks/features/editing/useGridEditing.js +1 -2
- package/hooks/features/editing/useGridRowEditing.js +4 -6
- package/hooks/features/export/serializers/csvSerializer.d.ts +2 -0
- package/hooks/features/export/serializers/csvSerializer.js +25 -16
- package/hooks/features/export/useGridCsvExport.js +9 -10
- package/hooks/features/export/useGridPrintExport.js +17 -22
- package/hooks/features/export/utils.js +2 -3
- package/hooks/features/filter/gridFilterSelector.js +15 -22
- package/hooks/features/filter/gridFilterUtils.js +10 -16
- package/hooks/features/filter/useGridFilter.js +9 -15
- package/hooks/features/focus/useGridFocus.js +5 -6
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.d.ts +1 -0
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +3 -0
- package/hooks/features/headerFiltering/useGridHeaderFiltering.js +23 -5
- package/hooks/features/index.d.ts +1 -0
- package/hooks/features/index.js +1 -0
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +1 -2
- package/hooks/features/pagination/gridPaginationInterfaces.d.ts +19 -2
- package/hooks/features/pagination/gridPaginationSelector.d.ts +5 -0
- package/hooks/features/pagination/gridPaginationSelector.js +9 -4
- package/hooks/features/pagination/useGridPagination.d.ts +1 -6
- package/hooks/features/pagination/useGridPagination.js +9 -158
- package/hooks/features/pagination/useGridPaginationModel.d.ts +11 -0
- package/hooks/features/pagination/useGridPaginationModel.js +165 -0
- package/hooks/features/pagination/useGridRowCount.d.ts +8 -0
- package/hooks/features/pagination/useGridRowCount.js +94 -0
- package/hooks/features/preferencesPanel/useGridPreferencesPanel.js +7 -12
- package/hooks/features/rowSelection/useGridRowSelection.js +11 -16
- package/hooks/features/rows/gridRowsSelector.js +11 -19
- package/hooks/features/rows/gridRowsUtils.js +7 -9
- package/hooks/features/rows/useGridParamsApi.js +1 -1
- package/hooks/features/rows/useGridRows.js +4 -13
- package/hooks/features/rows/useGridRowsMeta.js +7 -13
- package/hooks/features/scroll/useGridScroll.js +3 -4
- package/hooks/features/sorting/gridSortingSelector.js +4 -7
- package/hooks/features/sorting/useGridSorting.js +8 -14
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +4 -4
- package/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +3 -3
- package/hooks/features/virtualization/useGridVirtualScroller.js +220 -71
- package/hooks/utils/useGridApiEventHandler.js +5 -10
- package/hooks/utils/useGridNativeEventListener.js +1 -2
- package/hooks/utils/useLazyRef.d.ts +1 -2
- package/hooks/utils/useLazyRef.js +1 -11
- package/hooks/utils/useOnMount.d.ts +1 -2
- package/hooks/utils/useOnMount.js +1 -7
- package/hooks/utils/useTimeout.d.ts +1 -11
- package/hooks/utils/useTimeout.js +1 -36
- package/index.js +1 -1
- package/internals/index.d.ts +3 -1
- package/internals/index.js +2 -1
- package/internals/utils/getPinnedCellOffset.d.ts +3 -0
- package/internals/utils/getPinnedCellOffset.js +17 -0
- package/internals/utils/useProps.js +1 -2
- package/joy/joySlots.js +18 -63
- package/locales/jaJP.js +3 -4
- package/material/index.js +0 -2
- package/models/api/gridApiCommon.d.ts +3 -3
- package/models/api/gridCoreApi.d.ts +1 -5
- package/models/api/gridRowsMetaApi.d.ts +1 -1
- package/models/api/index.d.ts +1 -1
- package/models/api/index.js +0 -1
- package/models/events/gridEventLookup.d.ts +13 -0
- package/models/gridExport.d.ts +6 -0
- package/models/gridHeaderFilteringModel.d.ts +1 -0
- package/models/gridSlotsComponent.d.ts +0 -5
- package/models/gridStateCommunity.d.ts +3 -0
- package/models/params/gridScrollParams.d.ts +5 -3
- package/models/props/DataGridProps.d.ts +58 -28
- package/modern/DataGrid/DataGrid.js +57 -17
- package/modern/DataGrid/useDataGridComponent.js +3 -0
- package/modern/DataGrid/useDataGridProps.js +6 -7
- package/modern/components/GridColumnHeaders.js +6 -17
- package/modern/components/GridHeaders.js +1 -4
- package/modern/components/GridPagination.js +13 -6
- package/modern/components/GridRow.js +4 -19
- package/modern/components/GridScrollArea.js +150 -0
- package/modern/components/cell/GridActionsCell.js +1 -1
- package/modern/components/cell/GridActionsCellItem.js +4 -0
- package/modern/components/cell/GridBooleanCell.js +3 -2
- package/modern/components/cell/GridCell.js +11 -3
- package/modern/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
- package/modern/components/columnHeaders/GridColumnGroupHeader.js +18 -8
- package/modern/components/columnHeaders/GridColumnHeaderItem.js +21 -6
- package/modern/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
- package/modern/components/containers/GridRoot.js +3 -3
- package/modern/components/containers/GridRootStyles.js +12 -20
- package/modern/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputDate.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputSingleSelect.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputValue.js +1 -1
- package/modern/components/toolbar/GridToolbarDensitySelector.js +5 -5
- package/modern/components/virtualization/GridVirtualScrollbar.js +4 -0
- package/modern/components/virtualization/GridVirtualScroller.js +6 -1
- package/modern/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/modern/constants/gridClasses.js +1 -1
- package/modern/hooks/features/clipboard/useGridClipboard.js +4 -2
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +184 -97
- package/modern/hooks/features/columnResize/columnResizeSelector.js +3 -0
- package/modern/hooks/features/columnResize/columnResizeState.js +1 -0
- package/modern/hooks/features/columnResize/gridColumnResizeApi.js +10 -0
- package/modern/hooks/features/columnResize/index.js +3 -0
- package/modern/hooks/features/columnResize/useGridColumnResize.js +553 -0
- package/modern/hooks/features/columns/gridColumnsUtils.js +4 -20
- package/modern/hooks/features/density/densitySelector.js +8 -2
- package/modern/hooks/features/density/useGridDensity.js +21 -29
- package/modern/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/modern/hooks/features/editing/useGridCellEditing.js +22 -3
- package/modern/hooks/features/editing/useGridRowEditing.js +1 -1
- package/modern/hooks/features/export/serializers/csvSerializer.js +23 -12
- package/modern/hooks/features/export/useGridCsvExport.js +2 -1
- package/modern/hooks/features/export/useGridPrintExport.js +8 -7
- package/modern/hooks/features/filter/gridFilterUtils.js +1 -1
- package/modern/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +3 -0
- package/modern/hooks/features/headerFiltering/useGridHeaderFiltering.js +21 -2
- package/modern/hooks/features/index.js +1 -0
- package/modern/hooks/features/pagination/gridPaginationSelector.js +8 -2
- package/modern/hooks/features/pagination/useGridPagination.js +8 -149
- package/modern/hooks/features/pagination/useGridPaginationModel.js +165 -0
- package/modern/hooks/features/pagination/useGridRowCount.js +94 -0
- package/modern/hooks/features/rowSelection/useGridRowSelection.js +3 -2
- package/modern/hooks/features/scroll/useGridScroll.js +1 -1
- package/modern/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +211 -57
- package/modern/hooks/utils/useLazyRef.js +1 -11
- package/modern/hooks/utils/useOnMount.js +1 -7
- package/modern/hooks/utils/useTimeout.js +1 -36
- package/modern/index.js +1 -1
- package/modern/internals/index.js +2 -1
- package/modern/internals/utils/getPinnedCellOffset.js +17 -0
- package/modern/joy/joySlots.js +11 -50
- package/modern/locales/jaJP.js +3 -4
- package/modern/material/index.js +0 -2
- package/modern/models/api/index.js +0 -1
- package/modern/utils/cellBorderUtils.js +8 -0
- package/modern/utils/createSelector.js +1 -1
- package/modern/utils/domUtils.js +144 -0
- package/modern/utils/keyboardUtils.js +1 -1
- package/node/DataGrid/DataGrid.js +57 -17
- package/node/DataGrid/useDataGridComponent.js +3 -0
- package/node/DataGrid/useDataGridProps.js +6 -7
- package/node/components/GridColumnHeaders.js +6 -16
- package/node/components/GridHeaders.js +1 -4
- package/node/components/GridPagination.js +10 -4
- package/node/components/GridRow.js +3 -18
- package/node/components/GridScrollArea.js +158 -0
- package/node/components/cell/GridActionsCell.js +1 -1
- package/node/components/cell/GridActionsCellItem.js +4 -0
- package/node/components/cell/GridBooleanCell.js +3 -2
- package/node/components/cell/GridCell.js +12 -4
- package/node/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
- package/node/components/columnHeaders/GridColumnGroupHeader.js +18 -8
- package/node/components/columnHeaders/GridColumnHeaderItem.js +21 -6
- package/node/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
- package/node/components/containers/GridRoot.js +2 -2
- package/node/components/containers/GridRootStyles.js +12 -20
- package/node/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputDate.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputSingleSelect.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputValue.js +1 -1
- package/node/components/toolbar/GridToolbarDensitySelector.js +4 -4
- package/node/components/virtualization/GridVirtualScrollbar.js +4 -0
- package/node/components/virtualization/GridVirtualScroller.js +6 -1
- package/node/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/node/constants/gridClasses.js +1 -1
- package/node/hooks/features/clipboard/useGridClipboard.js +4 -2
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +190 -103
- package/node/hooks/features/columnResize/columnResizeSelector.js +10 -0
- package/node/hooks/features/columnResize/columnResizeState.js +5 -0
- package/node/hooks/features/columnResize/gridColumnResizeApi.js +16 -0
- package/node/hooks/features/columnResize/index.js +38 -0
- package/node/hooks/features/columnResize/useGridColumnResize.js +564 -0
- package/node/hooks/features/columns/gridColumnsUtils.js +4 -21
- package/node/hooks/features/density/densitySelector.js +9 -3
- package/node/hooks/features/density/useGridDensity.js +22 -30
- package/node/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/node/hooks/features/editing/useGridCellEditing.js +22 -3
- package/node/hooks/features/editing/useGridRowEditing.js +1 -1
- package/node/hooks/features/export/serializers/csvSerializer.js +23 -12
- package/node/hooks/features/export/useGridCsvExport.js +2 -1
- package/node/hooks/features/export/useGridPrintExport.js +8 -7
- package/node/hooks/features/filter/gridFilterUtils.js +1 -1
- package/node/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +4 -1
- package/node/hooks/features/headerFiltering/useGridHeaderFiltering.js +21 -2
- package/node/hooks/features/index.js +11 -0
- package/node/hooks/features/pagination/gridPaginationSelector.js +8 -2
- package/node/hooks/features/pagination/useGridPagination.js +9 -153
- package/node/hooks/features/pagination/useGridPaginationModel.js +176 -0
- package/node/hooks/features/pagination/useGridRowCount.js +103 -0
- package/node/hooks/features/rowSelection/useGridRowSelection.js +2 -1
- package/node/hooks/features/scroll/useGridScroll.js +1 -1
- package/node/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +211 -57
- package/node/hooks/utils/useLazyRef.js +7 -13
- package/node/hooks/utils/useOnMount.js +8 -10
- package/node/hooks/utils/useTimeout.js +7 -37
- package/node/index.js +1 -1
- package/node/internals/index.js +27 -8
- package/node/internals/utils/getPinnedCellOffset.js +24 -0
- package/node/joy/joySlots.js +11 -50
- package/node/locales/jaJP.js +3 -4
- package/node/material/index.js +0 -2
- package/node/models/api/index.js +0 -11
- package/node/utils/cellBorderUtils.js +16 -0
- package/node/utils/createSelector.js +1 -1
- package/node/utils/domUtils.js +155 -0
- package/node/utils/keyboardUtils.js +1 -1
- package/package.json +4 -4
- package/utils/cellBorderUtils.d.ts +3 -0
- package/utils/cellBorderUtils.js +8 -0
- package/utils/createSelector.js +9 -9
- package/utils/domUtils.d.ts +14 -1
- package/utils/domUtils.js +144 -0
- package/utils/getGridLocalization.js +9 -12
- package/utils/keyboardUtils.js +1 -1
- package/components/columnHeaders/GridColumnHeadersInner.d.ts +0 -8
- package/components/columnHeaders/GridColumnHeadersInner.js +0 -58
- package/modern/components/columnHeaders/GridColumnHeadersInner.js +0 -58
- package/node/components/columnHeaders/GridColumnHeadersInner.js +0 -67
|
@@ -2,6 +2,8 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import * as ReactDOM from 'react-dom';
|
|
4
4
|
import { unstable_useEnhancedEffect as useEnhancedEffect, unstable_useEventCallback as useEventCallback } from '@mui/utils';
|
|
5
|
+
import useLazyRef from '@mui/utils/useLazyRef';
|
|
6
|
+
import useTimeout from '@mui/utils/useTimeout';
|
|
5
7
|
import { useTheme } from '@mui/material/styles';
|
|
6
8
|
import { useGridPrivateApiContext } from '../../utils/useGridPrivateApiContext';
|
|
7
9
|
import { useGridRootProps } from '../../utils/useGridRootProps';
|
|
@@ -22,13 +24,31 @@ import { getMinimalContentHeight } from '../rows/gridRowsUtils';
|
|
|
22
24
|
import { gridRenderContextSelector, gridVirtualizationEnabledSelector, gridVirtualizationColumnEnabledSelector } from './gridVirtualizationSelectors';
|
|
23
25
|
import { EMPTY_RENDER_CONTEXT } from './useGridVirtualization';
|
|
24
26
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
27
|
+
const MINIMUM_COLUMN_WIDTH = 50;
|
|
28
|
+
var ScrollDirection = /*#__PURE__*/function (ScrollDirection) {
|
|
29
|
+
ScrollDirection[ScrollDirection["NONE"] = 0] = "NONE";
|
|
30
|
+
ScrollDirection[ScrollDirection["UP"] = 1] = "UP";
|
|
31
|
+
ScrollDirection[ScrollDirection["DOWN"] = 2] = "DOWN";
|
|
32
|
+
ScrollDirection[ScrollDirection["LEFT"] = 3] = "LEFT";
|
|
33
|
+
ScrollDirection[ScrollDirection["RIGHT"] = 4] = "RIGHT";
|
|
34
|
+
return ScrollDirection;
|
|
35
|
+
}(ScrollDirection || {});
|
|
36
|
+
const EMPTY_SCROLL_POSITION = {
|
|
37
|
+
top: 0,
|
|
38
|
+
left: 0
|
|
39
|
+
};
|
|
25
40
|
export const EMPTY_DETAIL_PANELS = Object.freeze(new Map());
|
|
41
|
+
const createScrollCache = (rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer) => ({
|
|
42
|
+
direction: ScrollDirection.NONE,
|
|
43
|
+
buffer: bufferForDirection(ScrollDirection.NONE, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer)
|
|
44
|
+
});
|
|
45
|
+
const isJSDOM = typeof window !== 'undefined' ? /jsdom/.test(window.navigator.userAgent) : false;
|
|
26
46
|
export const useGridVirtualScroller = () => {
|
|
27
47
|
const apiRef = useGridPrivateApiContext();
|
|
28
48
|
const rootProps = useGridRootProps();
|
|
29
49
|
const visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
|
|
30
|
-
const enabled = useGridSelector(apiRef, gridVirtualizationEnabledSelector);
|
|
31
|
-
const enabledForColumns = useGridSelector(apiRef, gridVirtualizationColumnEnabledSelector);
|
|
50
|
+
const enabled = useGridSelector(apiRef, gridVirtualizationEnabledSelector) && !isJSDOM;
|
|
51
|
+
const enabledForColumns = useGridSelector(apiRef, gridVirtualizationColumnEnabledSelector) && !isJSDOM;
|
|
32
52
|
const dimensions = useGridSelector(apiRef, gridDimensionsSelector);
|
|
33
53
|
const outerSize = dimensions.viewportOuterSize;
|
|
34
54
|
const pinnedRows = useGridSelector(apiRef, gridPinnedRowsSelector);
|
|
@@ -50,19 +70,34 @@ export const useGridVirtualScroller = () => {
|
|
|
50
70
|
const columnsTotalWidth = dimensions.columnsTotalWidth;
|
|
51
71
|
const hasColSpan = useGridSelector(apiRef, gridHasColSpanSelector);
|
|
52
72
|
useResizeObserver(mainRef, () => apiRef.current.resize());
|
|
53
|
-
|
|
73
|
+
|
|
74
|
+
/*
|
|
75
|
+
* Scroll context logic
|
|
76
|
+
* ====================
|
|
77
|
+
* We only render the cells contained in the `renderContext`. However, when the user starts scrolling the grid
|
|
78
|
+
* in a direction, we want to render as many cells as possible in that direction, as to avoid presenting white
|
|
79
|
+
* areas if the user scrolls too fast/far and the viewport ends up in a region we haven't rendered yet. To render
|
|
80
|
+
* more cells, we store some offsets to add to the viewport in `scrollCache.buffer`. Those offsets make the render
|
|
81
|
+
* context wider in the direction the user is going, but also makes the buffer around the viewport `0` for the
|
|
82
|
+
* dimension (horizontal or vertical) in which the user is not scrolling. So if the normal viewport is 8 columns
|
|
83
|
+
* wide, with a 1 column buffer (10 columns total), then we want it to be exactly 8 columns wide during vertical
|
|
84
|
+
* scroll.
|
|
85
|
+
* However, we don't want the rows in the old context to re-render from e.g. 10 columns to 8 columns, because that's
|
|
86
|
+
* work that's not necessary. Thus we store the context at the start of the scroll in `frozenContext`, and the rows
|
|
87
|
+
* that are part of this old context will keep their same render context as to avoid re-rendering.
|
|
88
|
+
*/
|
|
89
|
+
const scrollPosition = React.useRef(EMPTY_SCROLL_POSITION);
|
|
90
|
+
const previousContextScrollPosition = React.useRef(EMPTY_SCROLL_POSITION);
|
|
54
91
|
const previousRowContext = React.useRef(EMPTY_RENDER_CONTEXT);
|
|
55
92
|
const renderContext = useGridSelector(apiRef, gridRenderContextSelector);
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}).current;
|
|
60
|
-
const prevTotalWidth = React.useRef(columnsTotalWidth);
|
|
93
|
+
const scrollTimeout = useTimeout();
|
|
94
|
+
const frozenContext = React.useRef(undefined);
|
|
95
|
+
const scrollCache = useLazyRef(() => createScrollCache(rootProps.rowBufferPx, rootProps.columnBufferPx, dimensions.rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6)).current;
|
|
61
96
|
const focusedCell = {
|
|
62
97
|
rowIndex: React.useMemo(() => cellFocus ? currentPage.rows.findIndex(row => row.id === cellFocus.id) : -1, [cellFocus, currentPage.rows]),
|
|
63
98
|
columnIndex: React.useMemo(() => cellFocus ? visibleColumns.findIndex(column => column.field === cellFocus.field) : -1, [cellFocus, visibleColumns])
|
|
64
99
|
};
|
|
65
|
-
const updateRenderContext = React.useCallback(
|
|
100
|
+
const updateRenderContext = React.useCallback(nextRenderContext => {
|
|
66
101
|
if (areRenderContextsEqual(nextRenderContext, apiRef.current.state.virtualization.renderContext)) {
|
|
67
102
|
return;
|
|
68
103
|
}
|
|
@@ -82,41 +117,67 @@ export const useGridVirtualScroller = () => {
|
|
|
82
117
|
previousRowContext.current = nextRenderContext;
|
|
83
118
|
apiRef.current.publishEvent('renderedRowsIntervalChange', nextRenderContext);
|
|
84
119
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}, [apiRef, dimensions.isReady, dimensions.columnsTotalWidth]);
|
|
120
|
+
previousContextScrollPosition.current = scrollPosition.current;
|
|
121
|
+
}, [apiRef, dimensions.isReady]);
|
|
88
122
|
const triggerUpdateRenderContext = () => {
|
|
89
|
-
const
|
|
90
|
-
|
|
123
|
+
const newScroll = {
|
|
124
|
+
top: scrollerRef.current.scrollTop,
|
|
125
|
+
left: scrollerRef.current.scrollLeft
|
|
126
|
+
};
|
|
127
|
+
const dx = newScroll.left - scrollPosition.current.left;
|
|
128
|
+
const dy = newScroll.top - scrollPosition.current.top;
|
|
129
|
+
const isScrolling = dx !== 0 || dy !== 0;
|
|
130
|
+
scrollPosition.current = newScroll;
|
|
131
|
+
const direction = isScrolling ? directionForDelta(dx, dy) : ScrollDirection.NONE;
|
|
91
132
|
|
|
92
133
|
// Since previous render, we have scrolled...
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
134
|
+
const rowScroll = Math.abs(scrollPosition.current.top - previousContextScrollPosition.current.top);
|
|
135
|
+
const columnScroll = Math.abs(scrollPosition.current.left - previousContextScrollPosition.current.left);
|
|
136
|
+
|
|
137
|
+
// PERF: use the computed minimum column width instead of a static one
|
|
138
|
+
const didCrossThreshold = rowScroll >= dimensions.rowHeight || columnScroll >= MINIMUM_COLUMN_WIDTH;
|
|
139
|
+
const didChangeDirection = scrollCache.direction !== direction;
|
|
140
|
+
const shouldUpdate = didCrossThreshold || didChangeDirection;
|
|
98
141
|
if (!shouldUpdate) {
|
|
99
|
-
return
|
|
142
|
+
return renderContext;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Render a new context
|
|
146
|
+
|
|
147
|
+
if (didChangeDirection) {
|
|
148
|
+
switch (direction) {
|
|
149
|
+
case ScrollDirection.NONE:
|
|
150
|
+
case ScrollDirection.LEFT:
|
|
151
|
+
case ScrollDirection.RIGHT:
|
|
152
|
+
frozenContext.current = undefined;
|
|
153
|
+
break;
|
|
154
|
+
default:
|
|
155
|
+
frozenContext.current = renderContext;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
100
158
|
}
|
|
159
|
+
scrollCache.direction = direction;
|
|
160
|
+
scrollCache.buffer = bufferForDirection(direction, rootProps.rowBufferPx, rootProps.columnBufferPx, dimensions.rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6);
|
|
161
|
+
const inputs = inputsSelector(apiRef, rootProps, enabled, enabledForColumns);
|
|
162
|
+
const nextRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
|
|
101
163
|
|
|
102
164
|
// Prevents batching render context changes
|
|
103
165
|
ReactDOM.flushSync(() => {
|
|
104
|
-
updateRenderContext(nextRenderContext
|
|
166
|
+
updateRenderContext(nextRenderContext);
|
|
105
167
|
});
|
|
168
|
+
scrollTimeout.start(1000, triggerUpdateRenderContext);
|
|
106
169
|
return nextRenderContext;
|
|
107
170
|
};
|
|
108
171
|
const forceUpdateRenderContext = () => {
|
|
109
172
|
const inputs = inputsSelector(apiRef, rootProps, enabled, enabledForColumns);
|
|
110
|
-
const
|
|
111
|
-
updateRenderContext(nextRenderContext
|
|
173
|
+
const nextRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
|
|
174
|
+
updateRenderContext(nextRenderContext);
|
|
112
175
|
};
|
|
113
176
|
const handleScroll = useEventCallback(event => {
|
|
114
177
|
const {
|
|
115
178
|
scrollTop,
|
|
116
179
|
scrollLeft
|
|
117
180
|
} = event.currentTarget;
|
|
118
|
-
scrollPosition.top = scrollTop;
|
|
119
|
-
scrollPosition.left = scrollLeft;
|
|
120
181
|
|
|
121
182
|
// On iOS and macOS, negative offsets are possible when swiping past the start
|
|
122
183
|
if (scrollTop < 0) {
|
|
@@ -149,8 +210,7 @@ export const useGridVirtualScroller = () => {
|
|
|
149
210
|
if (!params.rows && !currentPage.range) {
|
|
150
211
|
return [];
|
|
151
212
|
}
|
|
152
|
-
const
|
|
153
|
-
const currentRenderContext = params.renderContext ?? renderContext;
|
|
213
|
+
const baseRenderContext = params.renderContext ?? renderContext;
|
|
154
214
|
const isLastSection = !hasBottomPinnedRows && params.position === undefined || hasBottomPinnedRows && params.position === 'bottom';
|
|
155
215
|
const isPinnedSection = params.position !== undefined;
|
|
156
216
|
let rowIndexOffset;
|
|
@@ -168,8 +228,8 @@ export const useGridVirtualScroller = () => {
|
|
|
168
228
|
break;
|
|
169
229
|
}
|
|
170
230
|
const rowModels = params.rows ?? currentPage.rows;
|
|
171
|
-
const firstRowToRender =
|
|
172
|
-
const lastRowToRender = Math.min(
|
|
231
|
+
const firstRowToRender = baseRenderContext.firstRowIndex;
|
|
232
|
+
const lastRowToRender = Math.min(baseRenderContext.lastRowIndex, rowModels.length);
|
|
173
233
|
const rowIndexes = params.rows ? range(0, params.rows.length) : range(firstRowToRender, lastRowToRender);
|
|
174
234
|
let virtualRowIndex = -1;
|
|
175
235
|
if (!isPinnedSection && focusedCell.rowIndex !== -1) {
|
|
@@ -184,6 +244,7 @@ export const useGridVirtualScroller = () => {
|
|
|
184
244
|
}
|
|
185
245
|
const rows = [];
|
|
186
246
|
const rowProps = rootProps.slotProps?.row;
|
|
247
|
+
const columnPositions = gridColumnPositionsSelector(apiRef);
|
|
187
248
|
rowIndexes.forEach(rowIndexInPage => {
|
|
188
249
|
const {
|
|
189
250
|
id,
|
|
@@ -248,6 +309,10 @@ export const useGridVirtualScroller = () => {
|
|
|
248
309
|
const cellParams = apiRef.current.getCellParams(id, cellTabIndex.field);
|
|
249
310
|
tabbableCell = cellParams.cellMode === 'view' ? cellTabIndex.field : null;
|
|
250
311
|
}
|
|
312
|
+
let currentRenderContext = baseRenderContext;
|
|
313
|
+
if (!isPinnedSection && frozenContext.current && rowIndexInPage >= frozenContext.current.firstRowIndex && rowIndexInPage < frozenContext.current.lastRowIndex) {
|
|
314
|
+
currentRenderContext = frozenContext.current;
|
|
315
|
+
}
|
|
251
316
|
const offsetLeft = computeOffsetLeft(columnPositions, currentRenderContext, theme.direction, pinnedColumns.left.length);
|
|
252
317
|
const rowIndex = (currentPage?.range?.firstRowIndex || 0) + rowIndexOffset + rowIndexInPage;
|
|
253
318
|
rows.push( /*#__PURE__*/_jsx(rootProps.slots.row, _extends({
|
|
@@ -319,11 +384,11 @@ export const useGridVirtualScroller = () => {
|
|
|
319
384
|
}, [enabled, gridRootRef, scrollerRef]);
|
|
320
385
|
useRunOnce(outerSize.width !== 0, () => {
|
|
321
386
|
const inputs = inputsSelector(apiRef, rootProps, enabled, enabledForColumns);
|
|
322
|
-
const
|
|
323
|
-
updateRenderContext(initialRenderContext
|
|
387
|
+
const initialRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
|
|
388
|
+
updateRenderContext(initialRenderContext);
|
|
324
389
|
apiRef.current.publishEvent('scrollPositionChange', {
|
|
325
|
-
top: scrollPosition.top,
|
|
326
|
-
left: scrollPosition.left,
|
|
390
|
+
top: scrollPosition.current.top,
|
|
391
|
+
left: scrollPosition.current.left,
|
|
327
392
|
renderContext: initialRenderContext
|
|
328
393
|
});
|
|
329
394
|
});
|
|
@@ -369,26 +434,31 @@ export const useGridVirtualScroller = () => {
|
|
|
369
434
|
function inputsSelector(apiRef, rootProps, enabled, enabledForColumns) {
|
|
370
435
|
const dimensions = gridDimensionsSelector(apiRef.current.state);
|
|
371
436
|
const currentPage = getVisibleRows(apiRef, rootProps);
|
|
437
|
+
const visibleColumns = gridVisibleColumnDefinitionsSelector(apiRef);
|
|
438
|
+
const lastRowId = apiRef.current.state.rows.dataRowIds.at(-1);
|
|
439
|
+
const lastColumn = visibleColumns.at(-1);
|
|
372
440
|
return {
|
|
373
441
|
enabled,
|
|
374
442
|
enabledForColumns,
|
|
375
443
|
apiRef,
|
|
376
444
|
autoHeight: rootProps.autoHeight,
|
|
377
|
-
|
|
378
|
-
|
|
445
|
+
rowBufferPx: rootProps.rowBufferPx,
|
|
446
|
+
columnBufferPx: rootProps.columnBufferPx,
|
|
379
447
|
leftPinnedWidth: dimensions.leftPinnedWidth,
|
|
380
448
|
columnsTotalWidth: dimensions.columnsTotalWidth,
|
|
381
449
|
viewportInnerWidth: dimensions.viewportInnerSize.width,
|
|
382
450
|
viewportInnerHeight: dimensions.viewportInnerSize.height,
|
|
451
|
+
lastRowHeight: lastRowId !== undefined ? apiRef.current.unstable_getRowHeight(lastRowId) : 0,
|
|
452
|
+
lastColumnWidth: lastColumn?.computedWidth ?? 0,
|
|
383
453
|
rowsMeta: gridRowsMetaSelector(apiRef.current.state),
|
|
384
454
|
columnPositions: gridColumnPositionsSelector(apiRef),
|
|
385
455
|
rows: currentPage.rows,
|
|
386
456
|
range: currentPage.range,
|
|
387
457
|
pinnedColumns: gridVisiblePinnedColumnDefinitionsSelector(apiRef),
|
|
388
|
-
visibleColumns
|
|
458
|
+
visibleColumns
|
|
389
459
|
};
|
|
390
460
|
}
|
|
391
|
-
function computeRenderContext(inputs, scrollPosition) {
|
|
461
|
+
function computeRenderContext(inputs, scrollPosition, scrollCache) {
|
|
392
462
|
let renderContext;
|
|
393
463
|
if (!inputs.enabled) {
|
|
394
464
|
renderContext = {
|
|
@@ -406,7 +476,10 @@ function computeRenderContext(inputs, scrollPosition) {
|
|
|
406
476
|
|
|
407
477
|
// Clamp the value because the search may return an index out of bounds.
|
|
408
478
|
// In the last index, this is not needed because Array.slice doesn't include it.
|
|
409
|
-
const firstRowIndex = Math.min(getNearestIndexToRender(inputs, top
|
|
479
|
+
const firstRowIndex = Math.min(getNearestIndexToRender(inputs, top, {
|
|
480
|
+
atStart: true,
|
|
481
|
+
lastPosition: inputs.rowsMeta.positions[inputs.rowsMeta.positions.length - 1] + inputs.lastRowHeight
|
|
482
|
+
}), inputs.rowsMeta.positions.length - 1);
|
|
410
483
|
const lastRowIndex = inputs.autoHeight ? firstRowIndex + inputs.rows.length : getNearestIndexToRender(inputs, top + inputs.viewportInnerHeight);
|
|
411
484
|
let firstColumnIndex = 0;
|
|
412
485
|
let lastColumnIndex = inputs.columnPositions.length;
|
|
@@ -417,7 +490,10 @@ function computeRenderContext(inputs, scrollPosition) {
|
|
|
417
490
|
lastIndex: lastRowIndex,
|
|
418
491
|
minFirstIndex: 0,
|
|
419
492
|
maxLastIndex: inputs.rows.length,
|
|
420
|
-
|
|
493
|
+
bufferBefore: scrollCache.buffer.rowBefore,
|
|
494
|
+
bufferAfter: scrollCache.buffer.rowAfter,
|
|
495
|
+
positions: inputs.rowsMeta.positions,
|
|
496
|
+
lastSize: inputs.lastRowHeight
|
|
421
497
|
});
|
|
422
498
|
for (let i = firstRowToRender; i < lastRowToRender && !hasRowWithAutoHeight; i += 1) {
|
|
423
499
|
const row = inputs.rows[i];
|
|
@@ -438,10 +514,10 @@ function computeRenderContext(inputs, scrollPosition) {
|
|
|
438
514
|
lastColumnIndex
|
|
439
515
|
};
|
|
440
516
|
}
|
|
441
|
-
const actualRenderContext = deriveRenderContext(inputs
|
|
442
|
-
return
|
|
517
|
+
const actualRenderContext = deriveRenderContext(inputs, renderContext, scrollCache);
|
|
518
|
+
return actualRenderContext;
|
|
443
519
|
}
|
|
444
|
-
function getNearestIndexToRender(inputs, offset) {
|
|
520
|
+
function getNearestIndexToRender(inputs, offset, options) {
|
|
445
521
|
const lastMeasuredIndexRelativeToAllRows = inputs.apiRef.current.getLastMeasuredRowIndex();
|
|
446
522
|
let allRowsMeasured = lastMeasuredIndexRelativeToAllRows === Infinity;
|
|
447
523
|
if (inputs.range?.lastRowIndex && !allRowsMeasured) {
|
|
@@ -452,14 +528,14 @@ function getNearestIndexToRender(inputs, offset) {
|
|
|
452
528
|
if (allRowsMeasured || inputs.rowsMeta.positions[lastMeasuredIndexRelativeToCurrentPage] >= offset) {
|
|
453
529
|
// If all rows were measured (when no row has "auto" as height) or all rows before the offset
|
|
454
530
|
// were measured, then use a binary search because it's faster.
|
|
455
|
-
return binarySearch(offset, inputs.rowsMeta.positions);
|
|
531
|
+
return binarySearch(offset, inputs.rowsMeta.positions, options);
|
|
456
532
|
}
|
|
457
533
|
|
|
458
534
|
// Otherwise, use an exponential search.
|
|
459
535
|
// If rows have "auto" as height, their positions will be based on estimated heights.
|
|
460
536
|
// In this case, we can skip several steps until we find a position higher than the offset.
|
|
461
537
|
// Inspired by https://github.com/bvaughn/react-virtualized/blob/master/source/Grid/utils/CellSizeAndPositionManager.js
|
|
462
|
-
return exponentialSearch(offset, inputs.rowsMeta.positions, lastMeasuredIndexRelativeToCurrentPage);
|
|
538
|
+
return exponentialSearch(offset, inputs.rowsMeta.positions, lastMeasuredIndexRelativeToCurrentPage, options);
|
|
463
539
|
}
|
|
464
540
|
|
|
465
541
|
/**
|
|
@@ -467,27 +543,33 @@ function getNearestIndexToRender(inputs, offset) {
|
|
|
467
543
|
* computes the actual render context based on pinned elements, buffer dimensions and
|
|
468
544
|
* spanning.
|
|
469
545
|
*/
|
|
470
|
-
function deriveRenderContext(
|
|
546
|
+
function deriveRenderContext(inputs, nextRenderContext, scrollCache) {
|
|
471
547
|
const [firstRowToRender, lastRowToRender] = getIndexesToRender({
|
|
472
548
|
firstIndex: nextRenderContext.firstRowIndex,
|
|
473
549
|
lastIndex: nextRenderContext.lastRowIndex,
|
|
474
550
|
minFirstIndex: 0,
|
|
475
|
-
maxLastIndex: rows.length,
|
|
476
|
-
|
|
551
|
+
maxLastIndex: inputs.rows.length,
|
|
552
|
+
bufferBefore: scrollCache.buffer.rowBefore,
|
|
553
|
+
bufferAfter: scrollCache.buffer.rowAfter,
|
|
554
|
+
positions: inputs.rowsMeta.positions,
|
|
555
|
+
lastSize: inputs.lastRowHeight
|
|
477
556
|
});
|
|
478
557
|
const [initialFirstColumnToRender, lastColumnToRender] = getIndexesToRender({
|
|
479
558
|
firstIndex: nextRenderContext.firstColumnIndex,
|
|
480
559
|
lastIndex: nextRenderContext.lastColumnIndex,
|
|
481
|
-
minFirstIndex: pinnedColumns.left.length,
|
|
482
|
-
maxLastIndex: visibleColumns.length - pinnedColumns.right.length,
|
|
483
|
-
|
|
560
|
+
minFirstIndex: inputs.pinnedColumns.left.length,
|
|
561
|
+
maxLastIndex: inputs.visibleColumns.length - inputs.pinnedColumns.right.length,
|
|
562
|
+
bufferBefore: scrollCache.buffer.columnBefore,
|
|
563
|
+
bufferAfter: scrollCache.buffer.columnAfter,
|
|
564
|
+
positions: inputs.columnPositions,
|
|
565
|
+
lastSize: inputs.lastColumnWidth
|
|
484
566
|
});
|
|
485
567
|
const firstColumnToRender = getFirstNonSpannedColumnToRender({
|
|
486
568
|
firstColumnToRender: initialFirstColumnToRender,
|
|
487
|
-
apiRef,
|
|
569
|
+
apiRef: inputs.apiRef,
|
|
488
570
|
firstRowToRender,
|
|
489
571
|
lastRowToRender,
|
|
490
|
-
visibleRows: rows
|
|
572
|
+
visibleRows: inputs.rows
|
|
491
573
|
});
|
|
492
574
|
return {
|
|
493
575
|
firstRowIndex: firstRowToRender,
|
|
@@ -520,22 +602,32 @@ function binarySearch(offset, positions, options = undefined, sliceStart = 0, sl
|
|
|
520
602
|
}
|
|
521
603
|
return isBefore ? binarySearch(offset, positions, options, sliceStart, pivot) : binarySearch(offset, positions, options, pivot + 1, sliceEnd);
|
|
522
604
|
}
|
|
523
|
-
function exponentialSearch(offset, positions, index) {
|
|
605
|
+
function exponentialSearch(offset, positions, index, options = undefined) {
|
|
524
606
|
let interval = 1;
|
|
525
607
|
while (index < positions.length && Math.abs(positions[index]) < offset) {
|
|
526
608
|
index += interval;
|
|
527
609
|
interval *= 2;
|
|
528
610
|
}
|
|
529
|
-
return binarySearch(offset, positions,
|
|
611
|
+
return binarySearch(offset, positions, options, Math.floor(index / 2), Math.min(index, positions.length));
|
|
530
612
|
}
|
|
531
613
|
function getIndexesToRender({
|
|
532
614
|
firstIndex,
|
|
533
615
|
lastIndex,
|
|
534
|
-
|
|
616
|
+
bufferBefore,
|
|
617
|
+
bufferAfter,
|
|
535
618
|
minFirstIndex,
|
|
536
|
-
maxLastIndex
|
|
619
|
+
maxLastIndex,
|
|
620
|
+
positions,
|
|
621
|
+
lastSize
|
|
537
622
|
}) {
|
|
538
|
-
|
|
623
|
+
const firstPosition = positions[firstIndex] - bufferBefore;
|
|
624
|
+
const lastPosition = positions[lastIndex] + bufferAfter;
|
|
625
|
+
const firstIndexPadded = binarySearch(firstPosition, positions, {
|
|
626
|
+
atStart: true,
|
|
627
|
+
lastPosition: positions[positions.length - 1] + lastSize
|
|
628
|
+
});
|
|
629
|
+
const lastIndexPadded = binarySearch(lastPosition, positions);
|
|
630
|
+
return [clamp(firstIndexPadded, minFirstIndex, maxLastIndex), clamp(lastIndexPadded, minFirstIndex, maxLastIndex)];
|
|
539
631
|
}
|
|
540
632
|
export function areRenderContextsEqual(context1, context2) {
|
|
541
633
|
if (context1 === context2) {
|
|
@@ -547,4 +639,66 @@ export function computeOffsetLeft(columnPositions, renderContext, direction, pin
|
|
|
547
639
|
const factor = direction === 'ltr' ? 1 : -1;
|
|
548
640
|
const left = factor * (columnPositions[renderContext.firstColumnIndex] ?? 0) - (columnPositions[pinnedLeftLength] ?? 0);
|
|
549
641
|
return left;
|
|
642
|
+
}
|
|
643
|
+
function directionForDelta(dx, dy) {
|
|
644
|
+
if (dx === 0 && dy === 0) {
|
|
645
|
+
return ScrollDirection.NONE;
|
|
646
|
+
}
|
|
647
|
+
/* eslint-disable */
|
|
648
|
+
if (Math.abs(dy) >= Math.abs(dx)) {
|
|
649
|
+
if (dy > 0) {
|
|
650
|
+
return ScrollDirection.DOWN;
|
|
651
|
+
} else {
|
|
652
|
+
return ScrollDirection.UP;
|
|
653
|
+
}
|
|
654
|
+
} else {
|
|
655
|
+
if (dx > 0) {
|
|
656
|
+
return ScrollDirection.RIGHT;
|
|
657
|
+
} else {
|
|
658
|
+
return ScrollDirection.LEFT;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
/* eslint-enable */
|
|
662
|
+
}
|
|
663
|
+
function bufferForDirection(direction, rowBufferPx, columnBufferPx, verticalBuffer, horizontalBuffer) {
|
|
664
|
+
switch (direction) {
|
|
665
|
+
case ScrollDirection.NONE:
|
|
666
|
+
return {
|
|
667
|
+
rowAfter: rowBufferPx,
|
|
668
|
+
rowBefore: rowBufferPx,
|
|
669
|
+
columnAfter: columnBufferPx,
|
|
670
|
+
columnBefore: columnBufferPx
|
|
671
|
+
};
|
|
672
|
+
case ScrollDirection.LEFT:
|
|
673
|
+
return {
|
|
674
|
+
rowAfter: 0,
|
|
675
|
+
rowBefore: 0,
|
|
676
|
+
columnAfter: 0,
|
|
677
|
+
columnBefore: horizontalBuffer
|
|
678
|
+
};
|
|
679
|
+
case ScrollDirection.RIGHT:
|
|
680
|
+
return {
|
|
681
|
+
rowAfter: 0,
|
|
682
|
+
rowBefore: 0,
|
|
683
|
+
columnAfter: horizontalBuffer,
|
|
684
|
+
columnBefore: 0
|
|
685
|
+
};
|
|
686
|
+
case ScrollDirection.UP:
|
|
687
|
+
return {
|
|
688
|
+
rowAfter: 0,
|
|
689
|
+
rowBefore: verticalBuffer,
|
|
690
|
+
columnAfter: 0,
|
|
691
|
+
columnBefore: 0
|
|
692
|
+
};
|
|
693
|
+
case ScrollDirection.DOWN:
|
|
694
|
+
return {
|
|
695
|
+
rowAfter: verticalBuffer,
|
|
696
|
+
rowBefore: 0,
|
|
697
|
+
columnAfter: 0,
|
|
698
|
+
columnBefore: 0
|
|
699
|
+
};
|
|
700
|
+
default:
|
|
701
|
+
// eslint unable to figure out enum exhaustiveness
|
|
702
|
+
throw new Error('unreachable');
|
|
703
|
+
}
|
|
550
704
|
}
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const UNINITIALIZED = {};
|
|
3
|
-
|
|
4
|
-
// See https://github.com/facebook/react/issues/14490 for when to use this.
|
|
5
|
-
export function useLazyRef(init, initArg) {
|
|
6
|
-
const ref = React.useRef(UNINITIALIZED);
|
|
7
|
-
if (ref.current === UNINITIALIZED) {
|
|
8
|
-
ref.current = init(initArg);
|
|
9
|
-
}
|
|
10
|
-
return ref;
|
|
11
|
-
}
|
|
1
|
+
export { default as useLazyRef } from '@mui/utils/useLazyRef';
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const EMPTY = [];
|
|
3
|
-
export function useOnMount(fn) {
|
|
4
|
-
/* eslint-disable react-hooks/exhaustive-deps */
|
|
5
|
-
React.useEffect(fn, EMPTY);
|
|
6
|
-
/* eslint-enable react-hooks/exhaustive-deps */
|
|
7
|
-
}
|
|
1
|
+
export { default as useOnMount } from '@mui/utils/useOnMount';
|
|
@@ -1,36 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { useLazyRef } from './useLazyRef';
|
|
4
|
-
import { useOnMount } from './useOnMount';
|
|
5
|
-
export class Timeout {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.currentId = null;
|
|
8
|
-
this.clear = () => {
|
|
9
|
-
if (this.currentId !== null) {
|
|
10
|
-
clearTimeout(this.currentId);
|
|
11
|
-
this.currentId = null;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
this.disposeEffect = () => {
|
|
15
|
-
return this.clear;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
static create() {
|
|
19
|
-
return new Timeout();
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Executes `fn` after `delay`, clearing any previously scheduled call.
|
|
23
|
-
*/
|
|
24
|
-
start(delay, fn) {
|
|
25
|
-
this.clear();
|
|
26
|
-
this.currentId = setTimeout(() => {
|
|
27
|
-
this.currentId = null;
|
|
28
|
-
fn();
|
|
29
|
-
}, delay);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export function useTimeout() {
|
|
33
|
-
const timeout = useLazyRef(Timeout.create).current;
|
|
34
|
-
useOnMount(timeout.disposeEffect);
|
|
35
|
-
return timeout;
|
|
36
|
-
}
|
|
1
|
+
export { default as useTimeout } from '@mui/utils/useTimeout';
|
package/modern/index.js
CHANGED
|
@@ -3,7 +3,6 @@ export { GridVirtualScrollerContent } from '../components/virtualization/GridVir
|
|
|
3
3
|
export { GridVirtualScrollerRenderZone } from '../components/virtualization/GridVirtualScrollerRenderZone';
|
|
4
4
|
export { GridHeaders } from '../components/GridHeaders';
|
|
5
5
|
export { GridBaseColumnHeaders } from '../components/columnHeaders/GridBaseColumnHeaders';
|
|
6
|
-
export { GridColumnHeadersInner } from '../components/columnHeaders/GridColumnHeadersInner';
|
|
7
6
|
export { DATA_GRID_DEFAULT_SLOTS_COMPONENTS } from '../constants/defaultGridSlotsComponents';
|
|
8
7
|
export { getGridFilter } from '../components/panel/filterPanel/GridFilterPanel';
|
|
9
8
|
export { useGridRegisterPipeProcessor } from '../hooks/core/pipeProcessing';
|
|
@@ -49,6 +48,7 @@ export { dimensionsStateInitializer, useGridDimensions } from '../hooks/features
|
|
|
49
48
|
export { useGridStatePersistence } from '../hooks/features/statePersistence/useGridStatePersistence';
|
|
50
49
|
export { useGridVirtualScroller, EMPTY_DETAIL_PANELS } from '../hooks/features/virtualization/useGridVirtualScroller';
|
|
51
50
|
export * from '../hooks/features/virtualization';
|
|
51
|
+
export { useGridColumnResize, columnResizeStateInitializer } from '../hooks/features/columnResize/useGridColumnResize';
|
|
52
52
|
export { useTimeout } from '../hooks/utils/useTimeout';
|
|
53
53
|
export { useGridVisibleRows, getVisibleRows } from '../hooks/utils/useGridVisibleRows';
|
|
54
54
|
export { useGridInitializeState } from '../hooks/utils/useGridInitializeState';
|
|
@@ -62,6 +62,7 @@ export * from '../utils/fastMemo';
|
|
|
62
62
|
export { buildWarning } from '../utils/warning';
|
|
63
63
|
export { exportAs } from '../utils/exportAs';
|
|
64
64
|
export * from '../utils/getPublicApiRef';
|
|
65
|
+
export * from '../utils/cellBorderUtils';
|
|
65
66
|
export { useGridPrivateApiContext } from '../hooks/utils/useGridPrivateApiContext';
|
|
66
67
|
export * from '../hooks/utils';
|
|
67
68
|
export { serializeCellValue } from '../hooks/features/export/serializers/csvSerializer';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GridPinnedColumnPosition } from '../../hooks/features/columns';
|
|
2
|
+
export const getPinnedCellOffset = (pinnedPosition, computedWidth, columnIndex, columnPositions, dimensions) => {
|
|
3
|
+
const scrollbarWidth = dimensions.hasScrollY ? dimensions.scrollbarSize : 0;
|
|
4
|
+
let pinnedOffset;
|
|
5
|
+
switch (pinnedPosition) {
|
|
6
|
+
case GridPinnedColumnPosition.LEFT:
|
|
7
|
+
pinnedOffset = columnPositions[columnIndex];
|
|
8
|
+
break;
|
|
9
|
+
case GridPinnedColumnPosition.RIGHT:
|
|
10
|
+
pinnedOffset = dimensions.columnsTotalWidth - columnPositions[columnIndex] - computedWidth + scrollbarWidth;
|
|
11
|
+
break;
|
|
12
|
+
default:
|
|
13
|
+
pinnedOffset = 0;
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
return pinnedOffset;
|
|
17
|
+
};
|