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