@mui/x-data-grid 7.0.0-beta.6 → 7.0.0-beta.7
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 +117 -1
- package/DataGrid/DataGrid.js +44 -0
- package/DataGrid/useDataGridComponent.js +3 -0
- package/DataGrid/useDataGridProps.js +3 -2
- package/components/GridColumnHeaders.d.ts +1 -2
- package/components/GridColumnHeaders.js +6 -17
- package/components/GridHeaders.js +1 -4
- package/components/GridPagination.js +2 -7
- package/components/GridRow.d.ts +1 -1
- package/components/GridRow.js +4 -19
- package/components/GridScrollArea.d.ts +10 -0
- package/components/GridScrollArea.js +150 -0
- package/components/cell/GridCell.d.ts +7 -0
- package/components/cell/GridCell.js +11 -3
- package/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
- package/components/columnHeaders/GridColumnGroupHeader.d.ts +5 -0
- package/components/columnHeaders/GridColumnGroupHeader.js +18 -8
- package/components/columnHeaders/GridColumnHeaderItem.d.ts +5 -0
- package/components/columnHeaders/GridColumnHeaderItem.js +21 -6
- package/components/columnHeaders/GridGenericColumnHeaderItem.d.ts +1 -0
- package/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
- package/components/containers/GridRootStyles.js +12 -20
- package/components/virtualization/GridVirtualScrollbar.js +4 -0
- package/components/virtualization/GridVirtualScroller.js +6 -1
- package/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/constants/gridClasses.d.ts +6 -32
- package/constants/gridClasses.js +1 -1
- package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +5 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +23 -7
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +186 -99
- 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 +563 -0
- package/hooks/features/columns/gridColumnsUtils.js +4 -1
- package/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/hooks/features/editing/useGridCellEditing.js +21 -2
- package/hooks/features/export/useGridPrintExport.js +8 -7
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.d.ts +1 -0
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +6 -0
- package/hooks/features/headerFiltering/useGridHeaderFiltering.js +30 -7
- package/hooks/features/index.d.ts +1 -0
- package/hooks/features/index.js +1 -0
- package/hooks/features/pagination/gridPaginationInterfaces.d.ts +19 -2
- package/hooks/features/pagination/gridPaginationSelector.d.ts +5 -0
- package/hooks/features/pagination/gridPaginationSelector.js +8 -2
- package/hooks/features/pagination/useGridPagination.d.ts +1 -6
- package/hooks/features/pagination/useGridPagination.js +9 -157
- package/hooks/features/pagination/useGridPaginationModel.d.ts +11 -0
- package/hooks/features/pagination/useGridPaginationModel.js +170 -0
- package/hooks/features/pagination/useGridRowCount.d.ts +8 -0
- package/hooks/features/pagination/useGridRowCount.js +97 -0
- package/hooks/features/scroll/useGridScroll.js +1 -1
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +4 -4
- package/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +2 -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 +1 -1
- package/internals/index.js +1 -1
- package/internals/utils/getPinnedCellOffset.d.ts +3 -0
- package/internals/utils/getPinnedCellOffset.js +17 -0
- package/joy/joySlots.js +13 -52
- 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/events/gridEventLookup.d.ts +6 -0
- package/models/gridHeaderFilteringModel.d.ts +1 -0
- package/models/gridSlotsComponent.d.ts +0 -5
- package/models/gridStateCommunity.d.ts +2 -0
- package/models/params/gridScrollParams.d.ts +5 -3
- package/models/props/DataGridProps.d.ts +35 -1
- package/modern/DataGrid/DataGrid.js +44 -0
- package/modern/DataGrid/useDataGridComponent.js +3 -0
- package/modern/DataGrid/useDataGridProps.js +3 -2
- package/modern/components/GridColumnHeaders.js +6 -17
- package/modern/components/GridHeaders.js +1 -4
- package/modern/components/GridPagination.js +2 -4
- package/modern/components/GridRow.js +4 -19
- package/modern/components/GridScrollArea.js +150 -0
- 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/GridRootStyles.js +12 -20
- 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/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 -1
- package/modern/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/modern/hooks/features/editing/useGridCellEditing.js +21 -2
- package/modern/hooks/features/export/useGridPrintExport.js +8 -7
- 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/scroll/useGridScroll.js +1 -1
- package/modern/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- 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 +1 -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/utils/cellBorderUtils.js +8 -0
- package/modern/utils/domUtils.js +144 -0
- package/node/DataGrid/DataGrid.js +44 -0
- package/node/DataGrid/useDataGridComponent.js +3 -0
- package/node/DataGrid/useDataGridProps.js +3 -2
- package/node/components/GridColumnHeaders.js +6 -16
- package/node/components/GridHeaders.js +1 -4
- package/node/components/GridPagination.js +1 -3
- package/node/components/GridRow.js +3 -18
- package/node/components/GridScrollArea.js +158 -0
- 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/GridRootStyles.js +12 -20
- 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/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 -1
- package/node/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/node/hooks/features/editing/useGridCellEditing.js +21 -2
- package/node/hooks/features/export/useGridPrintExport.js +8 -7
- 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/scroll/useGridScroll.js +1 -1
- package/node/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- 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 +15 -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/utils/cellBorderUtils.js +16 -0
- package/node/utils/domUtils.js +155 -0
- package/package.json +1 -1
- package/utils/cellBorderUtils.d.ts +3 -0
- package/utils/cellBorderUtils.js +8 -0
- package/utils/domUtils.d.ts +14 -1
- package/utils/domUtils.js +147 -0
- 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 (e.g. 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
|
+
}
|
|
@@ -16,6 +16,7 @@ var _colDef = require("../../../colDef");
|
|
|
16
16
|
var _gridColumnsSelector = require("./gridColumnsSelector");
|
|
17
17
|
var _utils = require("../../../utils/utils");
|
|
18
18
|
var _densitySelector = require("../density/densitySelector");
|
|
19
|
+
var _gridHeaderFilteringSelectors = require("../headerFiltering/gridHeaderFilteringSelectors");
|
|
19
20
|
var _gridColumnGroupsSelector = require("../columnGrouping/gridColumnGroupsSelector");
|
|
20
21
|
const COLUMNS_DIMENSION_PROPERTIES = exports.COLUMNS_DIMENSION_PROPERTIES = ['maxWidth', 'minWidth', 'width', 'flex'];
|
|
21
22
|
const COLUMN_TYPES = (0, _colDef.getGridDefaultColumnTypes)();
|
|
@@ -341,5 +342,7 @@ function getFirstColumnIndexToRender({
|
|
|
341
342
|
function getTotalHeaderHeight(apiRef, headerHeight) {
|
|
342
343
|
const densityFactor = (0, _densitySelector.gridDensityFactorSelector)(apiRef);
|
|
343
344
|
const maxDepth = (0, _gridColumnGroupsSelector.gridColumnGroupsHeaderMaxDepthSelector)(apiRef);
|
|
344
|
-
|
|
345
|
+
const isHeaderFilteringEnabled = (0, _gridHeaderFilteringSelectors.gridHeaderFilteringEnabledSelector)(apiRef);
|
|
346
|
+
const multiplicationFactor = isHeaderFilteringEnabled ? 2 : 1;
|
|
347
|
+
return Math.floor(headerHeight * densityFactor) * ((maxDepth ?? 0) + multiplicationFactor);
|
|
345
348
|
}
|
|
@@ -64,9 +64,7 @@ function useGridDimensions(apiRef, props) {
|
|
|
64
64
|
const rowHeight = Math.floor(props.rowHeight * densityFactor);
|
|
65
65
|
const headerHeight = Math.floor(props.columnHeaderHeight * densityFactor);
|
|
66
66
|
const columnsTotalWidth = roundToDecimalPlaces((0, _columns.gridColumnsTotalWidthSelector)(apiRef), 6);
|
|
67
|
-
|
|
68
|
-
const hasHeaderFilters = Boolean(props.headerFilters);
|
|
69
|
-
const headersTotalHeight = (0, _gridColumnsUtils.getTotalHeaderHeight)(apiRef, props.columnHeaderHeight) + Number(hasHeaderFilters) * headerHeight;
|
|
67
|
+
const headersTotalHeight = (0, _gridColumnsUtils.getTotalHeaderHeight)(apiRef, props.columnHeaderHeight);
|
|
70
68
|
const leftPinnedWidth = pinnedColumns.left.reduce((w, col) => w + col.computedWidth, 0);
|
|
71
69
|
const rightPinnedWidth = pinnedColumns.right.reduce((w, col) => w + col.computedWidth, 0);
|
|
72
70
|
const [savedSize, setSavedSize] = React.useState();
|
|
@@ -123,8 +121,9 @@ function useGridDimensions(apiRef, props) {
|
|
|
123
121
|
const scrollbarSize = measureScrollbarSize(rootElement, columnsTotalWidth, props.scrollbarSize);
|
|
124
122
|
const topContainerHeight = headersTotalHeight + pinnedRowsHeight.top;
|
|
125
123
|
const bottomContainerHeight = pinnedRowsHeight.bottom;
|
|
124
|
+
const nonPinnedColumnsTotalWidth = columnsTotalWidth - leftPinnedWidth - rightPinnedWidth;
|
|
126
125
|
const contentSize = {
|
|
127
|
-
width:
|
|
126
|
+
width: nonPinnedColumnsTotalWidth,
|
|
128
127
|
height: rowsMeta.currentPageTotalHeight
|
|
129
128
|
};
|
|
130
129
|
let viewportOuterSize;
|
|
@@ -173,7 +172,7 @@ function useGridDimensions(apiRef, props) {
|
|
|
173
172
|
}
|
|
174
173
|
const rowWidth = Math.max(viewportOuterSize.width, columnsTotalWidth + (hasScrollY ? scrollbarSize : 0));
|
|
175
174
|
const minimumSize = {
|
|
176
|
-
width:
|
|
175
|
+
width: columnsTotalWidth,
|
|
177
176
|
height: topContainerHeight + contentSize.height + bottomContainerHeight
|
|
178
177
|
};
|
|
179
178
|
const newDimensions = {
|
|
@@ -243,8 +243,27 @@ const useGridCellEditing = (apiRef, props) => {
|
|
|
243
243
|
initialValue
|
|
244
244
|
} = params;
|
|
245
245
|
let newValue = apiRef.current.getCellValue(id, field);
|
|
246
|
-
if (deleteValue
|
|
247
|
-
|
|
246
|
+
if (deleteValue) {
|
|
247
|
+
const fieldType = apiRef.current.getColumn(field).type;
|
|
248
|
+
switch (fieldType) {
|
|
249
|
+
case 'boolean':
|
|
250
|
+
newValue = false;
|
|
251
|
+
break;
|
|
252
|
+
case 'date':
|
|
253
|
+
case 'dateTime':
|
|
254
|
+
case 'number':
|
|
255
|
+
newValue = undefined;
|
|
256
|
+
break;
|
|
257
|
+
case 'singleSelect':
|
|
258
|
+
newValue = null;
|
|
259
|
+
break;
|
|
260
|
+
case 'string':
|
|
261
|
+
default:
|
|
262
|
+
newValue = '';
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
} else if (initialValue) {
|
|
266
|
+
newValue = initialValue;
|
|
248
267
|
}
|
|
249
268
|
const newProps = {
|
|
250
269
|
value: newValue,
|
|
@@ -15,7 +15,7 @@ var _gridClasses = require("../../../constants/gridClasses");
|
|
|
15
15
|
var _useGridApiMethod = require("../../utils/useGridApiMethod");
|
|
16
16
|
var _gridRowsMetaSelector = require("../rows/gridRowsMetaSelector");
|
|
17
17
|
var _utils2 = require("./utils");
|
|
18
|
-
var
|
|
18
|
+
var _useGridPaginationModel = require("../pagination/useGridPaginationModel");
|
|
19
19
|
var _pipeProcessing = require("../../core/pipeProcessing");
|
|
20
20
|
var _GridToolbarExport = require("../../../components/toolbar/GridToolbarExport");
|
|
21
21
|
var _gridColumnsUtils = require("../columns/gridColumnsUtils");
|
|
@@ -104,9 +104,6 @@ const useGridPrintExport = (apiRef, props) => {
|
|
|
104
104
|
|
|
105
105
|
// See https://support.google.com/chrome/thread/191619088?hl=en&msgid=193009642
|
|
106
106
|
gridClone.style.contain = 'size';
|
|
107
|
-
const columnHeaders = gridClone.querySelector(`.${_gridClasses.gridClasses.columnHeaders}`);
|
|
108
|
-
const columnHeadersInner = columnHeaders.querySelector(`.${_gridClasses.gridClasses.columnHeadersInner}`);
|
|
109
|
-
columnHeadersInner.style.width = '100%';
|
|
110
107
|
let gridToolbarElementHeight = gridRootElement.querySelector(`.${_gridClasses.gridClasses.toolbarContainer}`)?.offsetHeight || 0;
|
|
111
108
|
let gridFooterElementHeight = gridRootElement.querySelector(`.${_gridClasses.gridClasses.footerContainer}`)?.offsetHeight || 0;
|
|
112
109
|
if (normalizeOptions.hideToolbar) {
|
|
@@ -227,9 +224,13 @@ const useGridPrintExport = (apiRef, props) => {
|
|
|
227
224
|
page: 0,
|
|
228
225
|
pageSize: visibleRowCount
|
|
229
226
|
};
|
|
230
|
-
apiRef.current.
|
|
231
|
-
|
|
232
|
-
|
|
227
|
+
apiRef.current.setState(state => (0, _extends2.default)({}, state, {
|
|
228
|
+
pagination: (0, _extends2.default)({}, state.pagination, {
|
|
229
|
+
paginationModel: (0, _useGridPaginationModel.getDerivedPaginationModel)(state.pagination,
|
|
230
|
+
// Using signature `DataGridPro` to allow more than 100 rows in the print export
|
|
231
|
+
'DataGridPro', paginationModel)
|
|
232
|
+
})
|
|
233
|
+
}));
|
|
233
234
|
apiRef.current.forceUpdate();
|
|
234
235
|
}
|
|
235
236
|
await updateGridColumnsForPrint(options?.fields, options?.allColumns, options?.includeCheckboxes);
|