@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
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { unstable_ownerDocument as ownerDocument, unstable_useEventCallback as useEventCallback } from '@mui/utils';
|
|
4
|
+
import { useTheme } from '@mui/material/styles';
|
|
5
|
+
import { findGridCellElementsFromCol, findGridElement, findLeftPinnedCellsAfterCol, findRightPinnedCellsBeforeCol, getFieldFromHeaderElem, findHeaderElementFromField, findGroupHeaderElementsFromField, findGridHeader, findGridCells, findParentElementFromClassName, findLeftPinnedHeadersAfterCol, findRightPinnedHeadersBeforeCol } from '../../../utils/domUtils';
|
|
6
|
+
import { DEFAULT_GRID_AUTOSIZE_OPTIONS } from './gridColumnResizeApi';
|
|
7
|
+
import { gridClasses } from '../../../constants/gridClasses';
|
|
8
|
+
import { useGridApiEventHandler, useGridApiMethod, useGridApiOptionHandler, useGridLogger, useGridNativeEventListener, useGridSelector, useOnMount } from '../../utils';
|
|
9
|
+
import { gridVirtualizationColumnEnabledSelector } from '../virtualization';
|
|
10
|
+
import { createControllablePromise } from '../../../utils/createControllablePromise';
|
|
11
|
+
import { clamp } from '../../../utils/utils';
|
|
12
|
+
import { useTimeout } from '../../utils/useTimeout';
|
|
13
|
+
import { GridPinnedColumnPosition } from '../columns/gridColumnsInterfaces';
|
|
14
|
+
import { gridColumnsStateSelector } from '../columns';
|
|
15
|
+
// TODO: remove support for Safari < 13.
|
|
16
|
+
// https://caniuse.com/#search=touch-action
|
|
17
|
+
//
|
|
18
|
+
// Safari, on iOS, supports touch action since v13.
|
|
19
|
+
// Over 80% of the iOS phones are compatible
|
|
20
|
+
// in August 2020.
|
|
21
|
+
// Utilizing the CSS.supports method to check if touch-action is supported.
|
|
22
|
+
// Since CSS.supports is supported on all but Edge@12 and IE and touch-action
|
|
23
|
+
// is supported on both Edge@12 and IE if CSS.supports is not available that means that
|
|
24
|
+
// touch-action will be supported
|
|
25
|
+
let cachedSupportsTouchActionNone = false;
|
|
26
|
+
function doesSupportTouchActionNone() {
|
|
27
|
+
if (cachedSupportsTouchActionNone === undefined) {
|
|
28
|
+
if (typeof CSS !== 'undefined' && typeof CSS.supports === 'function') {
|
|
29
|
+
cachedSupportsTouchActionNone = CSS.supports('touch-action', 'none');
|
|
30
|
+
} else {
|
|
31
|
+
cachedSupportsTouchActionNone = true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return cachedSupportsTouchActionNone;
|
|
35
|
+
}
|
|
36
|
+
function trackFinger(event, currentTouchId) {
|
|
37
|
+
if (currentTouchId !== undefined && event.changedTouches) {
|
|
38
|
+
for (let i = 0; i < event.changedTouches.length; i += 1) {
|
|
39
|
+
const touch = event.changedTouches[i];
|
|
40
|
+
if (touch.identifier === currentTouchId) {
|
|
41
|
+
return {
|
|
42
|
+
x: touch.clientX,
|
|
43
|
+
y: touch.clientY
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
x: event.clientX,
|
|
51
|
+
y: event.clientY
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function computeNewWidth(initialOffsetToSeparator, clickX, columnBounds, resizeDirection) {
|
|
55
|
+
let newWidth = initialOffsetToSeparator;
|
|
56
|
+
if (resizeDirection === 'Right') {
|
|
57
|
+
newWidth += clickX - columnBounds.left;
|
|
58
|
+
} else {
|
|
59
|
+
newWidth += columnBounds.right - clickX;
|
|
60
|
+
}
|
|
61
|
+
return newWidth;
|
|
62
|
+
}
|
|
63
|
+
function computeOffsetToSeparator(clickX, columnBounds, resizeDirection) {
|
|
64
|
+
if (resizeDirection === 'Left') {
|
|
65
|
+
return clickX - columnBounds.left;
|
|
66
|
+
}
|
|
67
|
+
return columnBounds.right - clickX;
|
|
68
|
+
}
|
|
69
|
+
function flipResizeDirection(side) {
|
|
70
|
+
if (side === 'Right') {
|
|
71
|
+
return 'Left';
|
|
72
|
+
}
|
|
73
|
+
return 'Right';
|
|
74
|
+
}
|
|
75
|
+
function getResizeDirection(separator, direction) {
|
|
76
|
+
const side = separator.classList.contains(gridClasses['columnSeparator--sideRight']) ? 'Right' : 'Left';
|
|
77
|
+
if (direction === 'rtl') {
|
|
78
|
+
// Resizing logic should be mirrored in the RTL case
|
|
79
|
+
return flipResizeDirection(side);
|
|
80
|
+
}
|
|
81
|
+
return side;
|
|
82
|
+
}
|
|
83
|
+
function preventClick(event) {
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
event.stopImmediatePropagation();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Checker that returns a promise that resolves when the column virtualization
|
|
90
|
+
* is disabled.
|
|
91
|
+
*/
|
|
92
|
+
function useColumnVirtualizationDisabled(apiRef) {
|
|
93
|
+
const promise = React.useRef();
|
|
94
|
+
const selector = () => gridVirtualizationColumnEnabledSelector(apiRef);
|
|
95
|
+
const value = useGridSelector(apiRef, selector);
|
|
96
|
+
React.useEffect(() => {
|
|
97
|
+
if (promise.current && value === false) {
|
|
98
|
+
promise.current.resolve();
|
|
99
|
+
promise.current = undefined;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
const asyncCheck = () => {
|
|
103
|
+
if (!promise.current) {
|
|
104
|
+
if (selector() === false) {
|
|
105
|
+
return Promise.resolve();
|
|
106
|
+
}
|
|
107
|
+
promise.current = createControllablePromise();
|
|
108
|
+
}
|
|
109
|
+
return promise.current;
|
|
110
|
+
};
|
|
111
|
+
return asyncCheck;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Basic statistical outlier detection, checks if the value is `F * IQR` away from
|
|
116
|
+
* the Q1 and Q3 boundaries. IQR: interquartile range.
|
|
117
|
+
*/
|
|
118
|
+
function excludeOutliers(inputValues, factor) {
|
|
119
|
+
if (inputValues.length < 4) {
|
|
120
|
+
return inputValues;
|
|
121
|
+
}
|
|
122
|
+
const values = inputValues.slice();
|
|
123
|
+
values.sort((a, b) => a - b);
|
|
124
|
+
const q1 = values[Math.floor(values.length * 0.25)];
|
|
125
|
+
const q3 = values[Math.floor(values.length * 0.75) - 1];
|
|
126
|
+
const iqr = q3 - q1;
|
|
127
|
+
|
|
128
|
+
// We make a small adjustment if `iqr < 5` for the cases where the IQR is
|
|
129
|
+
// very small (for example zero) due to very close by values in the input data.
|
|
130
|
+
// Otherwise, with an IQR of `0`, anything outside that would be considered
|
|
131
|
+
// an outlier, but it makes more sense visually to allow for this 5px variance
|
|
132
|
+
// rather than showing a cropped cell.
|
|
133
|
+
const deviation = iqr < 5 ? 5 : iqr * factor;
|
|
134
|
+
return values.filter(v => v > q1 - deviation && v < q3 + deviation);
|
|
135
|
+
}
|
|
136
|
+
function extractColumnWidths(apiRef, options, columns) {
|
|
137
|
+
const widthByField = {};
|
|
138
|
+
const root = apiRef.current.rootElementRef.current;
|
|
139
|
+
root.classList.add(gridClasses.autosizing);
|
|
140
|
+
columns.forEach(column => {
|
|
141
|
+
const cells = findGridCells(apiRef.current, column.field);
|
|
142
|
+
const widths = cells.map(cell => {
|
|
143
|
+
return cell.getBoundingClientRect().width ?? 0;
|
|
144
|
+
});
|
|
145
|
+
const filteredWidths = options.includeOutliers ? widths : excludeOutliers(widths, options.outliersFactor);
|
|
146
|
+
if (options.includeHeaders) {
|
|
147
|
+
const header = findGridHeader(apiRef.current, column.field);
|
|
148
|
+
if (header) {
|
|
149
|
+
const title = header.querySelector(`.${gridClasses.columnHeaderTitle}`);
|
|
150
|
+
const content = header.querySelector(`.${gridClasses.columnHeaderTitleContainerContent}`);
|
|
151
|
+
const iconContainer = header.querySelector(`.${gridClasses.iconButtonContainer}`);
|
|
152
|
+
const menuContainer = header.querySelector(`.${gridClasses.menuIcon}`);
|
|
153
|
+
const element = title ?? content;
|
|
154
|
+
const style = window.getComputedStyle(header, null);
|
|
155
|
+
const paddingWidth = parseInt(style.paddingLeft, 10) + parseInt(style.paddingRight, 10);
|
|
156
|
+
const contentWidth = element.scrollWidth + 1;
|
|
157
|
+
const width = contentWidth + paddingWidth + (iconContainer?.clientWidth ?? 0) + (menuContainer?.clientWidth ?? 0);
|
|
158
|
+
filteredWidths.push(width);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const hasColumnMin = column.minWidth !== -Infinity && column.minWidth !== undefined;
|
|
162
|
+
const hasColumnMax = column.maxWidth !== Infinity && column.maxWidth !== undefined;
|
|
163
|
+
const min = hasColumnMin ? column.minWidth : 0;
|
|
164
|
+
const max = hasColumnMax ? column.maxWidth : Infinity;
|
|
165
|
+
const maxContent = filteredWidths.length === 0 ? 0 : Math.max(...filteredWidths);
|
|
166
|
+
widthByField[column.field] = clamp(maxContent, min, max);
|
|
167
|
+
});
|
|
168
|
+
root.classList.remove(gridClasses.autosizing);
|
|
169
|
+
return widthByField;
|
|
170
|
+
}
|
|
171
|
+
export const columnResizeStateInitializer = state => _extends({}, state, {
|
|
172
|
+
columnResize: {
|
|
173
|
+
resizingColumnField: ''
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
/**
|
|
177
|
+
* @requires useGridColumns (method, event)
|
|
178
|
+
* TODO: improve experience for last column
|
|
179
|
+
*/
|
|
180
|
+
export const useGridColumnResize = (apiRef, props) => {
|
|
181
|
+
const theme = useTheme();
|
|
182
|
+
const logger = useGridLogger(apiRef, 'useGridColumnResize');
|
|
183
|
+
const colDefRef = React.useRef();
|
|
184
|
+
const previousMouseClickEvent = React.useRef();
|
|
185
|
+
const columnHeaderElementRef = React.useRef();
|
|
186
|
+
const headerFilterElementRef = React.useRef();
|
|
187
|
+
const groupHeaderElementsRef = React.useRef([]);
|
|
188
|
+
const cellElementsRef = React.useRef([]);
|
|
189
|
+
const leftPinnedCellsAfterRef = React.useRef([]);
|
|
190
|
+
const rightPinnedCellsBeforeRef = React.useRef([]);
|
|
191
|
+
const fillerLeftRef = React.useRef();
|
|
192
|
+
const fillerRightRef = React.useRef();
|
|
193
|
+
const leftPinnedHeadersAfterRef = React.useRef([]);
|
|
194
|
+
const rightPinnedHeadersBeforeRef = React.useRef([]);
|
|
195
|
+
|
|
196
|
+
// To improve accessibility, the separator has padding on both sides.
|
|
197
|
+
// Clicking inside the padding area should be treated as a click in the separator.
|
|
198
|
+
// This ref stores the offset between the click and the separator.
|
|
199
|
+
const initialOffsetToSeparator = React.useRef();
|
|
200
|
+
const resizeDirection = React.useRef();
|
|
201
|
+
const stopResizeEventTimeout = useTimeout();
|
|
202
|
+
const touchId = React.useRef();
|
|
203
|
+
const updateWidth = newWidth => {
|
|
204
|
+
logger.debug(`Updating width to ${newWidth} for col ${colDefRef.current.field}`);
|
|
205
|
+
const prevWidth = columnHeaderElementRef.current.offsetWidth;
|
|
206
|
+
const widthDiff = newWidth - prevWidth;
|
|
207
|
+
colDefRef.current.computedWidth = newWidth;
|
|
208
|
+
colDefRef.current.width = newWidth;
|
|
209
|
+
colDefRef.current.flex = 0;
|
|
210
|
+
columnHeaderElementRef.current.style.width = `${newWidth}px`;
|
|
211
|
+
columnHeaderElementRef.current.style.minWidth = `${newWidth}px`;
|
|
212
|
+
columnHeaderElementRef.current.style.maxWidth = `${newWidth}px`;
|
|
213
|
+
const headerFilterElement = headerFilterElementRef.current;
|
|
214
|
+
if (headerFilterElement) {
|
|
215
|
+
headerFilterElement.style.width = `${newWidth}px`;
|
|
216
|
+
headerFilterElement.style.minWidth = `${newWidth}px`;
|
|
217
|
+
headerFilterElement.style.maxWidth = `${newWidth}px`;
|
|
218
|
+
}
|
|
219
|
+
groupHeaderElementsRef.current.forEach(element => {
|
|
220
|
+
const div = element;
|
|
221
|
+
let finalWidth;
|
|
222
|
+
if (div.getAttribute('aria-colspan') === '1') {
|
|
223
|
+
finalWidth = `${newWidth}px`;
|
|
224
|
+
} else {
|
|
225
|
+
// Cell with colspan > 1 cannot be just updated width new width.
|
|
226
|
+
// Instead, we add width diff to the current width.
|
|
227
|
+
finalWidth = `${div.offsetWidth + widthDiff}px`;
|
|
228
|
+
}
|
|
229
|
+
div.style.width = finalWidth;
|
|
230
|
+
div.style.minWidth = finalWidth;
|
|
231
|
+
div.style.maxWidth = finalWidth;
|
|
232
|
+
});
|
|
233
|
+
cellElementsRef.current.forEach(element => {
|
|
234
|
+
const div = element;
|
|
235
|
+
let finalWidth;
|
|
236
|
+
if (div.getAttribute('aria-colspan') === '1') {
|
|
237
|
+
finalWidth = `${newWidth}px`;
|
|
238
|
+
} else {
|
|
239
|
+
// Cell with colspan > 1 cannot be just updated width new width.
|
|
240
|
+
// Instead, we add width diff to the current width.
|
|
241
|
+
finalWidth = `${div.offsetWidth + widthDiff}px`;
|
|
242
|
+
}
|
|
243
|
+
div.style.setProperty('--width', finalWidth);
|
|
244
|
+
});
|
|
245
|
+
const pinnedPosition = apiRef.current.unstable_applyPipeProcessors('isColumnPinned', false, colDefRef.current.field);
|
|
246
|
+
if (pinnedPosition === GridPinnedColumnPosition.LEFT) {
|
|
247
|
+
updateProperty(fillerLeftRef.current, 'width', widthDiff);
|
|
248
|
+
leftPinnedCellsAfterRef.current.forEach(cell => {
|
|
249
|
+
updateProperty(cell, 'left', widthDiff);
|
|
250
|
+
});
|
|
251
|
+
leftPinnedHeadersAfterRef.current.forEach(header => {
|
|
252
|
+
updateProperty(header, 'left', widthDiff);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if (pinnedPosition === GridPinnedColumnPosition.RIGHT) {
|
|
256
|
+
updateProperty(fillerRightRef.current, 'width', widthDiff);
|
|
257
|
+
rightPinnedCellsBeforeRef.current.forEach(cell => {
|
|
258
|
+
updateProperty(cell, 'right', widthDiff);
|
|
259
|
+
});
|
|
260
|
+
rightPinnedHeadersBeforeRef.current.forEach(header => {
|
|
261
|
+
updateProperty(header, 'right', widthDiff);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const finishResize = nativeEvent => {
|
|
266
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
267
|
+
stopListening();
|
|
268
|
+
|
|
269
|
+
// Prevent double-clicks from being interpreted as two separate clicks
|
|
270
|
+
if (previousMouseClickEvent.current) {
|
|
271
|
+
const prevEvent = previousMouseClickEvent.current;
|
|
272
|
+
const prevTimeStamp = prevEvent.timeStamp;
|
|
273
|
+
const prevClientX = prevEvent.clientX;
|
|
274
|
+
const prevClientY = prevEvent.clientY;
|
|
275
|
+
|
|
276
|
+
// Check if the current event is part of a double-click
|
|
277
|
+
if (nativeEvent.timeStamp - prevTimeStamp < 300 && nativeEvent.clientX === prevClientX && nativeEvent.clientY === prevClientY) {
|
|
278
|
+
previousMouseClickEvent.current = undefined;
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (colDefRef.current) {
|
|
283
|
+
apiRef.current.setColumnWidth(colDefRef.current.field, colDefRef.current.width);
|
|
284
|
+
logger.debug(`Updating col ${colDefRef.current.field} with new width: ${colDefRef.current.width}`);
|
|
285
|
+
}
|
|
286
|
+
stopResizeEventTimeout.start(0, () => {
|
|
287
|
+
apiRef.current.publishEvent('columnResizeStop', null, nativeEvent);
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
const storeReferences = (colDef, separator, xStart) => {
|
|
291
|
+
const root = apiRef.current.rootElementRef.current;
|
|
292
|
+
colDefRef.current = colDef;
|
|
293
|
+
columnHeaderElementRef.current = findHeaderElementFromField(apiRef.current.columnHeadersContainerRef.current, colDef.field);
|
|
294
|
+
const headerFilterElement = root.querySelector(`.${gridClasses.headerFilterRow} [data-field="${colDef.field}"]`);
|
|
295
|
+
if (headerFilterElement) {
|
|
296
|
+
headerFilterElementRef.current = headerFilterElement;
|
|
297
|
+
}
|
|
298
|
+
groupHeaderElementsRef.current = findGroupHeaderElementsFromField(apiRef.current.columnHeadersContainerRef?.current, colDef.field);
|
|
299
|
+
cellElementsRef.current = findGridCellElementsFromCol(columnHeaderElementRef.current, apiRef.current);
|
|
300
|
+
fillerLeftRef.current = findGridElement(apiRef.current, 'filler--pinnedLeft');
|
|
301
|
+
fillerRightRef.current = findGridElement(apiRef.current, 'filler--pinnedRight');
|
|
302
|
+
const pinnedPosition = apiRef.current.unstable_applyPipeProcessors('isColumnPinned', false, colDefRef.current.field);
|
|
303
|
+
leftPinnedCellsAfterRef.current = pinnedPosition !== GridPinnedColumnPosition.LEFT ? [] : findLeftPinnedCellsAfterCol(apiRef.current, columnHeaderElementRef.current);
|
|
304
|
+
rightPinnedCellsBeforeRef.current = pinnedPosition !== GridPinnedColumnPosition.RIGHT ? [] : findRightPinnedCellsBeforeCol(apiRef.current, columnHeaderElementRef.current);
|
|
305
|
+
leftPinnedHeadersAfterRef.current = pinnedPosition !== GridPinnedColumnPosition.LEFT ? [] : findLeftPinnedHeadersAfterCol(apiRef.current, columnHeaderElementRef.current);
|
|
306
|
+
rightPinnedHeadersBeforeRef.current = pinnedPosition !== GridPinnedColumnPosition.RIGHT ? [] : findRightPinnedHeadersBeforeCol(apiRef.current, columnHeaderElementRef.current);
|
|
307
|
+
resizeDirection.current = getResizeDirection(separator, theme.direction);
|
|
308
|
+
initialOffsetToSeparator.current = computeOffsetToSeparator(xStart, columnHeaderElementRef.current.getBoundingClientRect(), resizeDirection.current);
|
|
309
|
+
};
|
|
310
|
+
const handleResizeMouseUp = useEventCallback(finishResize);
|
|
311
|
+
const handleResizeMouseMove = useEventCallback(nativeEvent => {
|
|
312
|
+
// Cancel move in case some other element consumed a mouseup event and it was not fired.
|
|
313
|
+
if (nativeEvent.buttons === 0) {
|
|
314
|
+
handleResizeMouseUp(nativeEvent);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
let newWidth = computeNewWidth(initialOffsetToSeparator.current, nativeEvent.clientX, columnHeaderElementRef.current.getBoundingClientRect(), resizeDirection.current);
|
|
318
|
+
newWidth = clamp(newWidth, colDefRef.current.minWidth, colDefRef.current.maxWidth);
|
|
319
|
+
updateWidth(newWidth);
|
|
320
|
+
const params = {
|
|
321
|
+
element: columnHeaderElementRef.current,
|
|
322
|
+
colDef: colDefRef.current,
|
|
323
|
+
width: newWidth
|
|
324
|
+
};
|
|
325
|
+
apiRef.current.publishEvent('columnResize', params, nativeEvent);
|
|
326
|
+
});
|
|
327
|
+
const handleTouchEnd = useEventCallback(nativeEvent => {
|
|
328
|
+
const finger = trackFinger(nativeEvent, touchId.current);
|
|
329
|
+
if (!finger) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
finishResize(nativeEvent);
|
|
333
|
+
});
|
|
334
|
+
const handleTouchMove = useEventCallback(nativeEvent => {
|
|
335
|
+
const finger = trackFinger(nativeEvent, touchId.current);
|
|
336
|
+
if (!finger) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Cancel move in case some other element consumed a touchmove event and it was not fired.
|
|
341
|
+
if (nativeEvent.type === 'mousemove' && nativeEvent.buttons === 0) {
|
|
342
|
+
handleTouchEnd(nativeEvent);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
let newWidth = computeNewWidth(initialOffsetToSeparator.current, finger.x, columnHeaderElementRef.current.getBoundingClientRect(), resizeDirection.current);
|
|
346
|
+
newWidth = clamp(newWidth, colDefRef.current.minWidth, colDefRef.current.maxWidth);
|
|
347
|
+
updateWidth(newWidth);
|
|
348
|
+
const params = {
|
|
349
|
+
element: columnHeaderElementRef.current,
|
|
350
|
+
colDef: colDefRef.current,
|
|
351
|
+
width: newWidth
|
|
352
|
+
};
|
|
353
|
+
apiRef.current.publishEvent('columnResize', params, nativeEvent);
|
|
354
|
+
});
|
|
355
|
+
const handleTouchStart = useEventCallback(event => {
|
|
356
|
+
const cellSeparator = findParentElementFromClassName(event.target, gridClasses['columnSeparator--resizable']);
|
|
357
|
+
// Let the event bubble if the target is not a col separator
|
|
358
|
+
if (!cellSeparator) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
// If touch-action: none; is not supported we need to prevent the scroll manually.
|
|
362
|
+
if (!doesSupportTouchActionNone()) {
|
|
363
|
+
event.preventDefault();
|
|
364
|
+
}
|
|
365
|
+
const touch = event.changedTouches[0];
|
|
366
|
+
if (touch != null) {
|
|
367
|
+
// A number that uniquely identifies the current finger in the touch session.
|
|
368
|
+
touchId.current = touch.identifier;
|
|
369
|
+
}
|
|
370
|
+
const columnHeaderElement = findParentElementFromClassName(event.target, gridClasses.columnHeader);
|
|
371
|
+
const field = getFieldFromHeaderElem(columnHeaderElement);
|
|
372
|
+
const colDef = apiRef.current.getColumn(field);
|
|
373
|
+
logger.debug(`Start Resize on col ${colDef.field}`);
|
|
374
|
+
apiRef.current.publishEvent('columnResizeStart', {
|
|
375
|
+
field
|
|
376
|
+
}, event);
|
|
377
|
+
storeReferences(colDef, cellSeparator, touch.clientX);
|
|
378
|
+
const doc = ownerDocument(event.currentTarget);
|
|
379
|
+
doc.addEventListener('touchmove', handleTouchMove);
|
|
380
|
+
doc.addEventListener('touchend', handleTouchEnd);
|
|
381
|
+
});
|
|
382
|
+
const stopListening = React.useCallback(() => {
|
|
383
|
+
const doc = ownerDocument(apiRef.current.rootElementRef.current);
|
|
384
|
+
doc.body.style.removeProperty('cursor');
|
|
385
|
+
doc.removeEventListener('mousemove', handleResizeMouseMove);
|
|
386
|
+
doc.removeEventListener('mouseup', handleResizeMouseUp);
|
|
387
|
+
doc.removeEventListener('touchmove', handleTouchMove);
|
|
388
|
+
doc.removeEventListener('touchend', handleTouchEnd);
|
|
389
|
+
// The click event runs right after the mouseup event, we want to wait until it
|
|
390
|
+
// has been canceled before removing our handler.
|
|
391
|
+
setTimeout(() => {
|
|
392
|
+
doc.removeEventListener('click', preventClick, true);
|
|
393
|
+
}, 100);
|
|
394
|
+
if (columnHeaderElementRef.current) {
|
|
395
|
+
columnHeaderElementRef.current.style.pointerEvents = 'unset';
|
|
396
|
+
}
|
|
397
|
+
}, [apiRef, columnHeaderElementRef, handleResizeMouseMove, handleResizeMouseUp, handleTouchMove, handleTouchEnd]);
|
|
398
|
+
const handleResizeStart = React.useCallback(({
|
|
399
|
+
field
|
|
400
|
+
}) => {
|
|
401
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
402
|
+
columnResize: _extends({}, state.columnResize, {
|
|
403
|
+
resizingColumnField: field
|
|
404
|
+
})
|
|
405
|
+
}));
|
|
406
|
+
apiRef.current.forceUpdate();
|
|
407
|
+
}, [apiRef]);
|
|
408
|
+
const handleResizeStop = React.useCallback(() => {
|
|
409
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
410
|
+
columnResize: _extends({}, state.columnResize, {
|
|
411
|
+
resizingColumnField: ''
|
|
412
|
+
})
|
|
413
|
+
}));
|
|
414
|
+
apiRef.current.forceUpdate();
|
|
415
|
+
}, [apiRef]);
|
|
416
|
+
const handleColumnResizeMouseDown = useEventCallback(({
|
|
417
|
+
colDef
|
|
418
|
+
}, event) => {
|
|
419
|
+
// Only handle left clicks
|
|
420
|
+
if (event.button !== 0) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// Skip if the column isn't resizable
|
|
425
|
+
if (!event.currentTarget.classList.contains(gridClasses['columnSeparator--resizable'])) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Avoid text selection
|
|
430
|
+
event.preventDefault();
|
|
431
|
+
logger.debug(`Start Resize on col ${colDef.field}`);
|
|
432
|
+
apiRef.current.publishEvent('columnResizeStart', {
|
|
433
|
+
field: colDef.field
|
|
434
|
+
}, event);
|
|
435
|
+
storeReferences(colDef, event.currentTarget, event.clientX);
|
|
436
|
+
const doc = ownerDocument(apiRef.current.rootElementRef.current);
|
|
437
|
+
doc.body.style.cursor = 'col-resize';
|
|
438
|
+
previousMouseClickEvent.current = event.nativeEvent;
|
|
439
|
+
doc.addEventListener('mousemove', handleResizeMouseMove);
|
|
440
|
+
doc.addEventListener('mouseup', handleResizeMouseUp);
|
|
441
|
+
|
|
442
|
+
// Prevent the click event if we have resized the column.
|
|
443
|
+
// Fixes https://github.com/mui/mui-x/issues/4777
|
|
444
|
+
doc.addEventListener('click', preventClick, true);
|
|
445
|
+
});
|
|
446
|
+
const handleColumnSeparatorDoubleClick = useEventCallback((params, event) => {
|
|
447
|
+
if (props.disableAutosize) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// Only handle left clicks
|
|
452
|
+
if (event.button !== 0) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const column = apiRef.current.state.columns.lookup[params.field];
|
|
456
|
+
if (column.resizable === false) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
apiRef.current.autosizeColumns(_extends({}, props.autosizeOptions, {
|
|
460
|
+
columns: [column.field]
|
|
461
|
+
}));
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* API METHODS
|
|
466
|
+
*/
|
|
467
|
+
|
|
468
|
+
const columnVirtualizationDisabled = useColumnVirtualizationDisabled(apiRef);
|
|
469
|
+
const isAutosizingRef = React.useRef(false);
|
|
470
|
+
const autosizeColumns = React.useCallback(async userOptions => {
|
|
471
|
+
const root = apiRef.current.rootElementRef?.current;
|
|
472
|
+
if (!root) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
if (isAutosizingRef.current) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
isAutosizingRef.current = true;
|
|
479
|
+
const state = gridColumnsStateSelector(apiRef.current.state);
|
|
480
|
+
const options = _extends({}, DEFAULT_GRID_AUTOSIZE_OPTIONS, userOptions, {
|
|
481
|
+
columns: userOptions?.columns ?? state.orderedFields
|
|
482
|
+
});
|
|
483
|
+
options.columns = options.columns.filter(c => state.columnVisibilityModel[c] !== false);
|
|
484
|
+
const columns = options.columns.map(c => apiRef.current.state.columns.lookup[c]);
|
|
485
|
+
try {
|
|
486
|
+
apiRef.current.unstable_setColumnVirtualization(false);
|
|
487
|
+
await columnVirtualizationDisabled();
|
|
488
|
+
const widthByField = extractColumnWidths(apiRef, options, columns);
|
|
489
|
+
const newColumns = columns.map(column => _extends({}, column, {
|
|
490
|
+
width: widthByField[column.field],
|
|
491
|
+
computedWidth: widthByField[column.field]
|
|
492
|
+
}));
|
|
493
|
+
if (options.expand) {
|
|
494
|
+
const visibleColumns = state.orderedFields.map(field => state.lookup[field]).filter(c => state.columnVisibilityModel[c.field] !== false);
|
|
495
|
+
const totalWidth = visibleColumns.reduce((total, column) => total + (widthByField[column.field] ?? column.computedWidth ?? column.width), 0);
|
|
496
|
+
const availableWidth = apiRef.current.getRootDimensions().viewportInnerSize.width;
|
|
497
|
+
const remainingWidth = availableWidth - totalWidth;
|
|
498
|
+
if (remainingWidth > 0) {
|
|
499
|
+
const widthPerColumn = remainingWidth / (newColumns.length || 1);
|
|
500
|
+
newColumns.forEach(column => {
|
|
501
|
+
column.width += widthPerColumn;
|
|
502
|
+
column.computedWidth += widthPerColumn;
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
apiRef.current.updateColumns(newColumns);
|
|
507
|
+
newColumns.forEach((newColumn, index) => {
|
|
508
|
+
if (newColumn.width !== columns[index].width) {
|
|
509
|
+
const width = newColumn.width;
|
|
510
|
+
apiRef.current.publishEvent('columnWidthChange', {
|
|
511
|
+
element: apiRef.current.getColumnHeaderElement(newColumn.field),
|
|
512
|
+
colDef: newColumn,
|
|
513
|
+
width
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
} finally {
|
|
518
|
+
apiRef.current.unstable_setColumnVirtualization(true);
|
|
519
|
+
isAutosizingRef.current = false;
|
|
520
|
+
}
|
|
521
|
+
}, [apiRef, columnVirtualizationDisabled]);
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* EFFECTS
|
|
525
|
+
*/
|
|
526
|
+
|
|
527
|
+
React.useEffect(() => stopListening, [stopListening]);
|
|
528
|
+
useOnMount(() => {
|
|
529
|
+
if (props.autosizeOnMount) {
|
|
530
|
+
Promise.resolve().then(() => {
|
|
531
|
+
apiRef.current.autosizeColumns(props.autosizeOptions);
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
useGridNativeEventListener(apiRef, () => apiRef.current.columnHeadersContainerRef?.current, 'touchstart', handleTouchStart, {
|
|
536
|
+
passive: doesSupportTouchActionNone()
|
|
537
|
+
});
|
|
538
|
+
useGridApiMethod(apiRef, {
|
|
539
|
+
autosizeColumns
|
|
540
|
+
}, 'public');
|
|
541
|
+
useGridApiEventHandler(apiRef, 'columnResizeStop', handleResizeStop);
|
|
542
|
+
useGridApiEventHandler(apiRef, 'columnResizeStart', handleResizeStart);
|
|
543
|
+
useGridApiEventHandler(apiRef, 'columnSeparatorMouseDown', handleColumnResizeMouseDown);
|
|
544
|
+
useGridApiEventHandler(apiRef, 'columnSeparatorDoubleClick', handleColumnSeparatorDoubleClick);
|
|
545
|
+
useGridApiOptionHandler(apiRef, 'columnResize', props.onColumnResize);
|
|
546
|
+
useGridApiOptionHandler(apiRef, 'columnWidthChange', props.onColumnWidthChange);
|
|
547
|
+
};
|
|
548
|
+
function updateProperty(element, property, delta) {
|
|
549
|
+
if (!element) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
element.style[property] = `${parseInt(element.style[property], 10) + delta}px`;
|
|
553
|
+
}
|
|
@@ -64,11 +64,10 @@ export const gridVisiblePinnedColumnDefinitionsSelector = createSelectorMemoized
|
|
|
64
64
|
return visiblePinnedColumns;
|
|
65
65
|
});
|
|
66
66
|
function filterVisibleColumns(pinnedColumns, columns, invert) {
|
|
67
|
-
var _pinnedColumns$left, _pinnedColumns$right;
|
|
68
67
|
if (!Array.isArray(pinnedColumns.left) && !Array.isArray(pinnedColumns.right)) {
|
|
69
68
|
return EMPTY_PINNED_COLUMN_FIELDS;
|
|
70
69
|
}
|
|
71
|
-
if (
|
|
70
|
+
if (pinnedColumns.left?.length === 0 && pinnedColumns.right?.length === 0) {
|
|
72
71
|
return EMPTY_PINNED_COLUMN_FIELDS;
|
|
73
72
|
}
|
|
74
73
|
const filter = (newPinnedColumns, remainingColumns) => {
|
|
@@ -51,13 +51,4 @@ export declare function getFirstNonSpannedColumnToRender({ firstColumnToRender,
|
|
|
51
51
|
lastRowToRender: number;
|
|
52
52
|
visibleRows: GridRowEntry[];
|
|
53
53
|
}): number;
|
|
54
|
-
export declare function getFirstColumnIndexToRender({ firstColumnIndex, minColumnIndex, columnBuffer, firstRowToRender, lastRowToRender, apiRef, visibleRows, }: {
|
|
55
|
-
firstColumnIndex: number;
|
|
56
|
-
minColumnIndex: number;
|
|
57
|
-
columnBuffer: number;
|
|
58
|
-
apiRef: React.MutableRefObject<GridApiCommon>;
|
|
59
|
-
firstRowToRender: number;
|
|
60
|
-
lastRowToRender: number;
|
|
61
|
-
visibleRows: GridRowEntry[];
|
|
62
|
-
}): number;
|
|
63
54
|
export declare function getTotalHeaderHeight(apiRef: React.MutableRefObject<GridApiCommunity>, headerHeight: number): number;
|
|
@@ -3,6 +3,7 @@ import { DEFAULT_GRID_COL_TYPE_KEY, GRID_STRING_COL_DEF, getGridDefaultColumnTyp
|
|
|
3
3
|
import { gridColumnsStateSelector, gridColumnVisibilityModelSelector } from './gridColumnsSelector';
|
|
4
4
|
import { clamp } from '../../../utils/utils';
|
|
5
5
|
import { gridDensityFactorSelector } from '../density/densitySelector';
|
|
6
|
+
import { gridHeaderFilteringEnabledSelector } from '../headerFiltering/gridHeaderFilteringSelectors';
|
|
6
7
|
import { gridColumnGroupsHeaderMaxDepthSelector } from '../columnGrouping/gridColumnGroupsSelector';
|
|
7
8
|
export const COLUMNS_DIMENSION_PROPERTIES = ['maxWidth', 'minWidth', 'width', 'flex'];
|
|
8
9
|
const COLUMN_TYPES = getGridDefaultColumnTypes();
|
|
@@ -212,7 +213,6 @@ export const createColumnsState = ({
|
|
|
212
213
|
columnVisibilityModel = gridColumnVisibilityModelSelector(apiRef),
|
|
213
214
|
keepOnlyColumnsToUpsert = false
|
|
214
215
|
}) => {
|
|
215
|
-
var _apiRef$current$getRo, _apiRef$current$getRo2, _apiRef$current;
|
|
216
216
|
const isInsideStateInitializer = !apiRef.current.state.columns;
|
|
217
217
|
let columnsState;
|
|
218
218
|
if (isInsideStateInitializer) {
|
|
@@ -282,7 +282,7 @@ export const createColumnsState = ({
|
|
|
282
282
|
}
|
|
283
283
|
const columnsStateWithPreProcessing = apiRef.current.unstable_applyPipeProcessors('hydrateColumns', columnsState);
|
|
284
284
|
const columnsStateWithPortableColumns = applyInitialState(columnsStateWithPreProcessing, initialState);
|
|
285
|
-
return hydrateColumnsWidth(columnsStateWithPortableColumns,
|
|
285
|
+
return hydrateColumnsWidth(columnsStateWithPortableColumns, apiRef.current.getRootDimensions?.().viewportInnerSize.width ?? 0);
|
|
286
286
|
};
|
|
287
287
|
export function getFirstNonSpannedColumnToRender({
|
|
288
288
|
firstColumnToRender,
|
|
@@ -304,27 +304,10 @@ export function getFirstNonSpannedColumnToRender({
|
|
|
304
304
|
}
|
|
305
305
|
return firstNonSpannedColumnToRender;
|
|
306
306
|
}
|
|
307
|
-
export function getFirstColumnIndexToRender({
|
|
308
|
-
firstColumnIndex,
|
|
309
|
-
minColumnIndex,
|
|
310
|
-
columnBuffer,
|
|
311
|
-
firstRowToRender,
|
|
312
|
-
lastRowToRender,
|
|
313
|
-
apiRef,
|
|
314
|
-
visibleRows
|
|
315
|
-
}) {
|
|
316
|
-
const initialFirstColumnToRender = Math.max(firstColumnIndex - columnBuffer, minColumnIndex);
|
|
317
|
-
const firstColumnToRender = getFirstNonSpannedColumnToRender({
|
|
318
|
-
firstColumnToRender: initialFirstColumnToRender,
|
|
319
|
-
apiRef,
|
|
320
|
-
firstRowToRender,
|
|
321
|
-
lastRowToRender,
|
|
322
|
-
visibleRows
|
|
323
|
-
});
|
|
324
|
-
return firstColumnToRender;
|
|
325
|
-
}
|
|
326
307
|
export function getTotalHeaderHeight(apiRef, headerHeight) {
|
|
327
308
|
const densityFactor = gridDensityFactorSelector(apiRef);
|
|
328
309
|
const maxDepth = gridColumnGroupsHeaderMaxDepthSelector(apiRef);
|
|
329
|
-
|
|
310
|
+
const isHeaderFilteringEnabled = gridHeaderFilteringEnabledSelector(apiRef);
|
|
311
|
+
const multiplicationFactor = isHeaderFilteringEnabled ? 2 : 1;
|
|
312
|
+
return Math.floor(headerHeight * densityFactor) * ((maxDepth ?? 0) + multiplicationFactor);
|
|
330
313
|
}
|
|
@@ -8,8 +8,7 @@ import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
|
8
8
|
export const useGridColumnSpanning = apiRef => {
|
|
9
9
|
const lookup = React.useRef({});
|
|
10
10
|
const getCellColSpanInfo = (rowId, columnIndex) => {
|
|
11
|
-
|
|
12
|
-
return (_lookup$current$rowId = lookup.current[rowId]) == null ? void 0 : _lookup$current$rowId[columnIndex];
|
|
11
|
+
return lookup.current[rowId]?.[columnIndex];
|
|
13
12
|
};
|
|
14
13
|
|
|
15
14
|
// Calculate `colSpan` for each cell in the row
|