@mui/x-data-grid-premium 6.0.0-beta.4 → 6.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 +204 -29
- package/DataGridPremium/DataGridPremium.js +21 -4
- package/DataGridPremium/useDataGridPremiumComponent.js +1 -1
- package/DataGridPremium/useDataGridPremiumProps.js +26 -19
- package/components/GridAggregationHeader.js +3 -2
- package/components/GridColumnMenuAggregationItem.js +1 -1
- package/components/GridColumnMenuRowGroupItem.js +1 -1
- package/components/GridColumnMenuRowUngroupItem.js +2 -2
- package/components/GridExcelExportMenuItem.js +2 -1
- package/components/GridFooterCell.js +1 -3
- package/components/GridGroupingCriteriaCell.js +4 -4
- package/components/index.d.ts +1 -1
- package/components/index.js +1 -1
- package/constants/dataGridPremiumDefaultSlotsComponents.d.ts +1 -2
- package/constants/dataGridPremiumDefaultSlotsComponents.js +2 -7
- package/hooks/features/aggregation/gridAggregationInterfaces.d.ts +2 -0
- package/hooks/features/aggregation/useGridAggregationPreProcessors.d.ts +1 -1
- package/hooks/features/export/gridExcelExportInterface.d.ts +11 -0
- package/hooks/features/export/index.d.ts +1 -0
- package/hooks/features/export/index.js +2 -1
- package/hooks/features/export/serializer/excelSerializer.d.ts +52 -3
- package/hooks/features/export/serializer/excelSerializer.js +137 -51
- package/hooks/features/export/useGridExcelExport.d.ts +2 -1
- package/hooks/features/export/useGridExcelExport.js +67 -12
- package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
- package/index.d.ts +1 -0
- package/index.js +2 -1
- package/legacy/DataGridPremium/DataGridPremium.js +21 -4
- package/legacy/DataGridPremium/useDataGridPremiumComponent.js +1 -1
- package/legacy/DataGridPremium/useDataGridPremiumProps.js +21 -20
- package/legacy/components/GridAggregationHeader.js +3 -2
- package/legacy/components/GridColumnMenuAggregationItem.js +1 -1
- package/legacy/components/GridColumnMenuRowGroupItem.js +1 -1
- package/legacy/components/GridColumnMenuRowUngroupItem.js +2 -2
- package/legacy/components/GridExcelExportMenuItem.js +2 -1
- package/legacy/components/GridFooterCell.js +1 -3
- package/legacy/components/GridGroupingCriteriaCell.js +4 -4
- package/legacy/components/index.js +1 -1
- package/legacy/constants/dataGridPremiumDefaultSlotsComponents.js +2 -7
- package/legacy/hooks/features/export/index.js +2 -1
- package/legacy/hooks/features/export/serializer/excelSerializer.js +227 -72
- package/legacy/hooks/features/export/useGridExcelExport.js +125 -36
- package/legacy/index.js +2 -1
- package/legacy/material/index.js +9 -0
- package/legacy/utils/releaseInfo.js +1 -1
- package/material/index.d.ts +7 -0
- package/material/index.js +9 -0
- package/material/package.json +6 -0
- package/models/dataGridPremiumProps.d.ts +13 -3
- package/models/gridPremiumSlotsComponent.d.ts +4 -1
- package/modern/DataGridPremium/DataGridPremium.js +21 -4
- package/modern/DataGridPremium/useDataGridPremiumComponent.js +1 -1
- package/modern/DataGridPremium/useDataGridPremiumProps.js +21 -17
- package/modern/components/GridAggregationHeader.js +3 -2
- package/modern/components/GridColumnMenuAggregationItem.js +1 -1
- package/modern/components/GridColumnMenuRowGroupItem.js +1 -1
- package/modern/components/GridColumnMenuRowUngroupItem.js +2 -2
- package/modern/components/GridExcelExportMenuItem.js +2 -1
- package/modern/components/GridFooterCell.js +1 -3
- package/modern/components/GridGroupingCriteriaCell.js +3 -3
- package/modern/components/index.js +1 -1
- package/modern/constants/dataGridPremiumDefaultSlotsComponents.js +2 -7
- package/modern/hooks/features/export/index.js +2 -1
- package/modern/hooks/features/export/serializer/excelSerializer.js +131 -47
- package/modern/hooks/features/export/useGridExcelExport.js +67 -12
- package/modern/index.js +2 -1
- package/modern/material/index.js +9 -0
- package/modern/utils/releaseInfo.js +1 -1
- package/node/DataGridPremium/DataGridPremium.js +19 -2
- package/node/DataGridPremium/useDataGridPremiumComponent.js +1 -1
- package/node/DataGridPremium/useDataGridPremiumProps.js +21 -17
- package/node/components/GridAggregationHeader.js +3 -2
- package/node/components/GridColumnMenuAggregationItem.js +1 -1
- package/node/components/GridColumnMenuRowGroupItem.js +1 -1
- package/node/components/GridColumnMenuRowUngroupItem.js +2 -2
- package/node/components/GridExcelExportMenuItem.js +2 -1
- package/node/components/GridFooterCell.js +1 -3
- package/node/components/GridGroupingCriteriaCell.js +3 -3
- package/node/components/index.js +1 -1
- package/node/constants/dataGridPremiumDefaultSlotsComponents.js +3 -9
- package/node/hooks/features/export/index.js +12 -1
- package/node/hooks/features/export/serializer/excelSerializer.js +136 -45
- package/node/hooks/features/export/useGridExcelExport.js +66 -10
- package/node/index.js +9 -1
- package/node/material/index.js +17 -0
- package/node/utils/releaseInfo.js +1 -1
- package/package.json +4 -4
- package/typeOverloads/modules.d.ts +6 -0
- package/utils/releaseInfo.js +1 -1
- /package/legacy/{components → material}/icons.js +0 -0
- /package/{components → material}/icons.d.ts +0 -0
- /package/{components → material}/icons.js +0 -0
- /package/modern/{components → material}/icons.js +0 -0
- /package/node/{components → material}/icons.js +0 -0
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
var _excluded = ["components", "componentsProps"];
|
|
3
4
|
import * as React from 'react';
|
|
4
5
|
import { useThemeProps } from '@mui/material/styles';
|
|
5
6
|
import { DATA_GRID_PRO_PROPS_DEFAULT_VALUES, GRID_DEFAULT_LOCALE_TEXT } from '@mui/x-data-grid-pro';
|
|
7
|
+
import { computeSlots, uncapitalizeObjectKeys } from '@mui/x-data-grid-pro/internals';
|
|
6
8
|
import { GRID_AGGREGATION_FUNCTIONS } from '../hooks/features/aggregation';
|
|
7
9
|
import { DATA_GRID_PREMIUM_DEFAULT_SLOTS_COMPONENTS } from '../constants/dataGridPremiumDefaultSlotsComponents';
|
|
8
10
|
|
|
@@ -20,33 +22,32 @@ export var DATA_GRID_PREMIUM_PROPS_DEFAULT_VALUES = _extends({}, DATA_GRID_PRO_P
|
|
|
20
22
|
return groupNode.depth === -1 ? 'footer' : 'inline';
|
|
21
23
|
}
|
|
22
24
|
});
|
|
25
|
+
var defaultSlots = uncapitalizeObjectKeys(DATA_GRID_PREMIUM_DEFAULT_SLOTS_COMPONENTS);
|
|
23
26
|
export var useDataGridPremiumProps = function useDataGridPremiumProps(inProps) {
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
var _useThemeProps = useThemeProps({
|
|
28
|
+
props: inProps,
|
|
29
|
+
name: 'MuiDataGrid'
|
|
30
|
+
}),
|
|
31
|
+
components = _useThemeProps.components,
|
|
32
|
+
componentsProps = _useThemeProps.componentsProps,
|
|
33
|
+
themedProps = _objectWithoutProperties(_useThemeProps, _excluded);
|
|
28
34
|
var localeText = React.useMemo(function () {
|
|
29
35
|
return _extends({}, GRID_DEFAULT_LOCALE_TEXT, themedProps.localeText);
|
|
30
36
|
}, [themedProps.localeText]);
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var mergedComponents = {};
|
|
37
|
-
Object.entries(DATA_GRID_PREMIUM_DEFAULT_SLOTS_COMPONENTS).forEach(function (_ref) {
|
|
38
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
39
|
-
key = _ref2[0],
|
|
40
|
-
defaultComponent = _ref2[1];
|
|
41
|
-
mergedComponents[key] = overrides[key] === undefined ? defaultComponent : overrides[key];
|
|
37
|
+
var slots = React.useMemo(function () {
|
|
38
|
+
return computeSlots({
|
|
39
|
+
defaultSlots: defaultSlots,
|
|
40
|
+
components: components,
|
|
41
|
+
slots: themedProps.slots
|
|
42
42
|
});
|
|
43
|
-
|
|
44
|
-
}, [themedProps.components]);
|
|
43
|
+
}, [components, themedProps.slots]);
|
|
45
44
|
return React.useMemo(function () {
|
|
45
|
+
var _themedProps$slotProp;
|
|
46
46
|
return _extends({}, DATA_GRID_PREMIUM_PROPS_DEFAULT_VALUES, themedProps, {
|
|
47
|
+
slotProps: (_themedProps$slotProp = themedProps.slotProps) != null ? _themedProps$slotProp : componentsProps,
|
|
47
48
|
localeText: localeText,
|
|
48
|
-
|
|
49
|
+
slots: slots,
|
|
49
50
|
signature: 'DataGridPremium'
|
|
50
51
|
});
|
|
51
|
-
}, [themedProps, localeText,
|
|
52
|
+
}, [themedProps, componentsProps, localeText, slots]);
|
|
52
53
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
3
|
var _styled;
|
|
3
4
|
import * as React from 'react';
|
|
@@ -56,10 +57,10 @@ function GridAggregationHeader(props) {
|
|
|
56
57
|
aggregation = props.aggregation;
|
|
57
58
|
var apiRef = useGridApiContext();
|
|
58
59
|
var rootProps = useGridRootProps();
|
|
59
|
-
var ownerState = {
|
|
60
|
+
var ownerState = _extends({}, rootProps, {
|
|
60
61
|
classes: rootProps.classes,
|
|
61
62
|
colDef: colDef
|
|
62
|
-
};
|
|
63
|
+
});
|
|
63
64
|
var classes = useUtilityClasses(ownerState);
|
|
64
65
|
if (!aggregation) {
|
|
65
66
|
return null;
|
|
@@ -59,7 +59,7 @@ function GridColumnMenuAggregationItem(props) {
|
|
|
59
59
|
return /*#__PURE__*/_jsxs(MenuItem, {
|
|
60
60
|
disableRipple: true,
|
|
61
61
|
children: [/*#__PURE__*/_jsx(ListItemIcon, {
|
|
62
|
-
children: /*#__PURE__*/_jsx(rootProps.
|
|
62
|
+
children: /*#__PURE__*/_jsx(rootProps.slots.columnMenuAggregationIcon, {
|
|
63
63
|
fontSize: "small"
|
|
64
64
|
})
|
|
65
65
|
}), /*#__PURE__*/_jsx(ListItemText, {
|
|
@@ -27,7 +27,7 @@ function GridColumnMenuRowGroupItem(props) {
|
|
|
27
27
|
return /*#__PURE__*/_jsxs(MenuItem, {
|
|
28
28
|
onClick: ungroupColumn,
|
|
29
29
|
children: [/*#__PURE__*/_jsx(ListItemIcon, {
|
|
30
|
-
children: /*#__PURE__*/_jsx(rootProps.
|
|
30
|
+
children: /*#__PURE__*/_jsx(rootProps.slots.columnMenuUngroupIcon, {
|
|
31
31
|
fontSize: "small"
|
|
32
32
|
})
|
|
33
33
|
}), /*#__PURE__*/_jsx(ListItemText, {
|
|
@@ -33,7 +33,7 @@ function GridColumnMenuRowUngroupItem(props) {
|
|
|
33
33
|
return /*#__PURE__*/_jsxs(MenuItem, {
|
|
34
34
|
onClick: ungroupColumn,
|
|
35
35
|
children: [/*#__PURE__*/_jsx(ListItemIcon, {
|
|
36
|
-
children: /*#__PURE__*/_jsx(rootProps.
|
|
36
|
+
children: /*#__PURE__*/_jsx(rootProps.slots.columnMenuUngroupIcon, {
|
|
37
37
|
fontSize: "small"
|
|
38
38
|
})
|
|
39
39
|
}), /*#__PURE__*/_jsx(ListItemText, {
|
|
@@ -44,7 +44,7 @@ function GridColumnMenuRowUngroupItem(props) {
|
|
|
44
44
|
return /*#__PURE__*/_jsxs(MenuItem, {
|
|
45
45
|
onClick: groupColumn,
|
|
46
46
|
children: [/*#__PURE__*/_jsx(ListItemIcon, {
|
|
47
|
-
children: /*#__PURE__*/_jsx(rootProps.
|
|
47
|
+
children: /*#__PURE__*/_jsx(rootProps.slots.columnMenuGroupIcon, {
|
|
48
48
|
fontSize: "small"
|
|
49
49
|
})
|
|
50
50
|
}), /*#__PURE__*/_jsx(ListItemText, {
|
|
@@ -37,7 +37,8 @@ process.env.NODE_ENV !== "production" ? GridExcelExportMenuItem.propTypes = {
|
|
|
37
37
|
getRowsToExport: PropTypes.func,
|
|
38
38
|
includeColumnGroupsHeaders: PropTypes.bool,
|
|
39
39
|
includeHeaders: PropTypes.bool,
|
|
40
|
-
valueOptionsSheetName: PropTypes.string
|
|
40
|
+
valueOptionsSheetName: PropTypes.string,
|
|
41
|
+
worker: PropTypes.func
|
|
41
42
|
})
|
|
42
43
|
} : void 0;
|
|
43
44
|
export { GridExcelExportMenuItem };
|
|
@@ -44,9 +44,7 @@ function GridFooterCell(props) {
|
|
|
44
44
|
isEditable = props.isEditable,
|
|
45
45
|
other = _objectWithoutProperties(props, _excluded);
|
|
46
46
|
var rootProps = useGridRootProps();
|
|
47
|
-
var ownerState =
|
|
48
|
-
classes: rootProps.classes
|
|
49
|
-
};
|
|
47
|
+
var ownerState = rootProps;
|
|
50
48
|
var classes = useUtilityClasses(ownerState);
|
|
51
49
|
return /*#__PURE__*/_jsx(GridFooterCellRoot, _extends({
|
|
52
50
|
ownerState: ownerState,
|
|
@@ -16,7 +16,7 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
|
16
16
|
return composeClasses(slots, getDataGridUtilityClass, classes);
|
|
17
17
|
};
|
|
18
18
|
export function GridGroupingCriteriaCell(props) {
|
|
19
|
-
var _filteredDescendantCo, _rootProps$
|
|
19
|
+
var _filteredDescendantCo, _rootProps$slotProps;
|
|
20
20
|
var id = props.id,
|
|
21
21
|
field = props.field,
|
|
22
22
|
rowNode = props.rowNode,
|
|
@@ -30,7 +30,7 @@ export function GridGroupingCriteriaCell(props) {
|
|
|
30
30
|
var classes = useUtilityClasses(ownerState);
|
|
31
31
|
var filteredDescendantCountLookup = useGridSelector(apiRef, gridFilteredDescendantCountLookupSelector);
|
|
32
32
|
var filteredDescendantCount = (_filteredDescendantCo = filteredDescendantCountLookup[rowNode.id]) != null ? _filteredDescendantCo : 0;
|
|
33
|
-
var Icon = rowNode.childrenExpanded ? rootProps.
|
|
33
|
+
var Icon = rowNode.childrenExpanded ? rootProps.slots.groupingCriteriaCollapseIcon : rootProps.slots.groupingCriteriaExpandIcon;
|
|
34
34
|
var handleKeyDown = function handleKeyDown(event) {
|
|
35
35
|
if (event.key === ' ') {
|
|
36
36
|
// We call event.stopPropagation to avoid unfolding the row and also scrolling to bottom
|
|
@@ -65,13 +65,13 @@ export function GridGroupingCriteriaCell(props) {
|
|
|
65
65
|
},
|
|
66
66
|
children: [/*#__PURE__*/_jsx("div", {
|
|
67
67
|
className: classes.toggle,
|
|
68
|
-
children: filteredDescendantCount > 0 && /*#__PURE__*/_jsx(rootProps.
|
|
68
|
+
children: filteredDescendantCount > 0 && /*#__PURE__*/_jsx(rootProps.slots.baseIconButton, _extends({
|
|
69
69
|
size: "small",
|
|
70
70
|
onClick: handleClick,
|
|
71
71
|
onKeyDown: handleKeyDown,
|
|
72
72
|
tabIndex: -1,
|
|
73
73
|
"aria-label": rowNode.childrenExpanded ? apiRef.current.getLocaleText('treeDataCollapse') : apiRef.current.getLocaleText('treeDataExpand')
|
|
74
|
-
}, (_rootProps$
|
|
74
|
+
}, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseIconButton, {
|
|
75
75
|
children: /*#__PURE__*/_jsx(Icon, {
|
|
76
76
|
fontSize: "inherit"
|
|
77
77
|
})
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import { DATA_GRID_PRO_DEFAULT_SLOTS_COMPONENTS } from '@mui/x-data-grid-pro/internals';
|
|
3
|
-
import { GridWorkspacesIcon, GridGroupWorkIcon, GridFunctionsIcon } from '../components';
|
|
4
3
|
import { GridPremiumColumnMenu } from '../components/GridPremiumColumnMenu';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
ColumnMenuGroupIcon: GridGroupWorkIcon,
|
|
8
|
-
ColumnMenuAggregationIcon: GridFunctionsIcon
|
|
9
|
-
};
|
|
10
|
-
export var DATA_GRID_PREMIUM_DEFAULT_SLOTS_COMPONENTS = _extends({}, DATA_GRID_PRO_DEFAULT_SLOTS_COMPONENTS, DEFAULT_GRID_PREMIUM_ICON_SLOTS_COMPONENTS, {
|
|
4
|
+
import materialSlots from '../material';
|
|
5
|
+
export var DATA_GRID_PREMIUM_DEFAULT_SLOTS_COMPONENTS = _extends({}, DATA_GRID_PRO_DEFAULT_SLOTS_COMPONENTS, materialSlots, {
|
|
11
6
|
ColumnMenu: GridPremiumColumnMenu
|
|
12
7
|
});
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './gridExcelExportInterface';
|
|
1
|
+
export * from './gridExcelExportInterface';
|
|
2
|
+
export { setupExcelExportWebWorker } from './serializer/excelSerializer';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
1
2
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
4
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
@@ -54,7 +55,7 @@ var getFormattedValueOptions = function getFormattedValueOptions(colDef, valueOp
|
|
|
54
55
|
return _typeof(option) === 'object' ? option.label : option;
|
|
55
56
|
});
|
|
56
57
|
};
|
|
57
|
-
var serializeRow = function serializeRow(id, columns, api, defaultValueOptionsFormulae) {
|
|
58
|
+
export var serializeRow = function serializeRow(id, columns, api, defaultValueOptionsFormulae) {
|
|
58
59
|
var row = {};
|
|
59
60
|
var dataValidation = {};
|
|
60
61
|
var mergedCells = [];
|
|
@@ -101,11 +102,13 @@ var serializeRow = function serializeRow(id, columns, api, defaultValueOptionsFo
|
|
|
101
102
|
}).join(','), "\"")]
|
|
102
103
|
};
|
|
103
104
|
} else {
|
|
105
|
+
var address = defaultValueOptionsFormulae[column.field].address;
|
|
106
|
+
|
|
104
107
|
// If value option is defined for the column, refer to another sheet
|
|
105
108
|
dataValidation[castColumn.field] = {
|
|
106
109
|
type: 'list',
|
|
107
110
|
allowBlank: true,
|
|
108
|
-
formulae: [
|
|
111
|
+
formulae: [address]
|
|
109
112
|
};
|
|
110
113
|
}
|
|
111
114
|
var formattedValue = api.getCellParams(id, castColumn.field).formattedValue;
|
|
@@ -164,11 +167,13 @@ var defaultColumnsStyles = (_defaultColumnsStyles = {}, _defineProperty(_default
|
|
|
164
167
|
}), _defineProperty(_defaultColumnsStyles, GRID_DATETIME_COL_DEF.type, {
|
|
165
168
|
numFmt: 'dd.mm.yyyy hh:mm'
|
|
166
169
|
}), _defaultColumnsStyles);
|
|
167
|
-
var serializeColumn = function serializeColumn(column, columnsStyles) {
|
|
170
|
+
export var serializeColumn = function serializeColumn(column, columnsStyles) {
|
|
171
|
+
var _column$headerName;
|
|
168
172
|
var field = column.field,
|
|
169
173
|
type = column.type;
|
|
170
174
|
return {
|
|
171
175
|
key: field,
|
|
176
|
+
headerText: (_column$headerName = column.headerName) != null ? _column$headerName : column.field,
|
|
172
177
|
// Excel width must stay between 0 and 255 (https://support.microsoft.com/en-us/office/change-the-column-width-and-row-height-72f5e3cc-994d-43e8-ae58-9774a0905f46)
|
|
173
178
|
// From the example of column width behavior (https://docs.microsoft.com/en-US/office/troubleshoot/excel/determine-column-widths#example-of-column-width-behavior)
|
|
174
179
|
// a value of 10 corresponds to 75px. This is an approximation, because column width depends on the the font-size
|
|
@@ -176,20 +181,19 @@ var serializeColumn = function serializeColumn(column, columnsStyles) {
|
|
|
176
181
|
style: _extends({}, type && (defaultColumnsStyles == null ? void 0 : defaultColumnsStyles[type]), columnsStyles == null ? void 0 : columnsStyles[field])
|
|
177
182
|
};
|
|
178
183
|
};
|
|
179
|
-
var addColumnGroupingHeaders = function addColumnGroupingHeaders(worksheet, columns,
|
|
184
|
+
var addColumnGroupingHeaders = function addColumnGroupingHeaders(worksheet, columns, columnGroupPaths, columnGroupDetails) {
|
|
180
185
|
var maxDepth = Math.max.apply(Math, _toConsumableArray(columns.map(function (_ref2) {
|
|
181
|
-
var
|
|
182
|
-
var
|
|
183
|
-
return (
|
|
186
|
+
var _columnGroupPaths$key, _columnGroupPaths$key2;
|
|
187
|
+
var key = _ref2.key;
|
|
188
|
+
return (_columnGroupPaths$key = (_columnGroupPaths$key2 = columnGroupPaths[key]) == null ? void 0 : _columnGroupPaths$key2.length) != null ? _columnGroupPaths$key : 0;
|
|
184
189
|
})));
|
|
185
190
|
if (maxDepth === 0) {
|
|
186
191
|
return;
|
|
187
192
|
}
|
|
188
|
-
var columnGroupDetails = api.unstable_getAllGroupDetails();
|
|
189
193
|
var _loop = function _loop(rowIndex) {
|
|
190
194
|
var row = columns.map(function (_ref3) {
|
|
191
|
-
var
|
|
192
|
-
var groupingPath =
|
|
195
|
+
var key = _ref3.key;
|
|
196
|
+
var groupingPath = columnGroupPaths[key];
|
|
193
197
|
if (groupingPath.length <= rowIndex) {
|
|
194
198
|
return {
|
|
195
199
|
groupId: null,
|
|
@@ -240,102 +244,253 @@ var addColumnGroupingHeaders = function addColumnGroupingHeaders(worksheet, colu
|
|
|
240
244
|
_loop(rowIndex);
|
|
241
245
|
}
|
|
242
246
|
};
|
|
243
|
-
export function
|
|
247
|
+
export function serializeColumns(columns, styles) {
|
|
248
|
+
return columns.map(function (column) {
|
|
249
|
+
return serializeColumn(column, styles);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
export function getDataForValueOptionsSheet(_x, _x2, _x3) {
|
|
253
|
+
return _getDataForValueOptionsSheet.apply(this, arguments);
|
|
254
|
+
}
|
|
255
|
+
function _getDataForValueOptionsSheet() {
|
|
256
|
+
_getDataForValueOptionsSheet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(columns, valueOptionsSheetName, api) {
|
|
257
|
+
var candidateColumns, excelJS, workbook, worksheet;
|
|
258
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
259
|
+
while (1) {
|
|
260
|
+
switch (_context3.prev = _context3.next) {
|
|
261
|
+
case 0:
|
|
262
|
+
candidateColumns = columns.filter(function (column) {
|
|
263
|
+
return isSingleSelectColDef(column) && Array.isArray(column.valueOptions);
|
|
264
|
+
}); // Creates a temp worksheet to obtain the column letters
|
|
265
|
+
_context3.next = 3;
|
|
266
|
+
return getExcelJs();
|
|
267
|
+
case 3:
|
|
268
|
+
excelJS = _context3.sent;
|
|
269
|
+
workbook = new excelJS.Workbook();
|
|
270
|
+
worksheet = workbook.addWorksheet('Sheet1');
|
|
271
|
+
worksheet.columns = candidateColumns.map(function (column) {
|
|
272
|
+
return {
|
|
273
|
+
key: column.field
|
|
274
|
+
};
|
|
275
|
+
});
|
|
276
|
+
return _context3.abrupt("return", candidateColumns.reduce(function (acc, column) {
|
|
277
|
+
var _column$headerName2;
|
|
278
|
+
var singleSelectColumn = column;
|
|
279
|
+
var formattedValueOptions = getFormattedValueOptions(singleSelectColumn, singleSelectColumn.valueOptions, api);
|
|
280
|
+
var header = (_column$headerName2 = column.headerName) != null ? _column$headerName2 : column.field;
|
|
281
|
+
var values = [header].concat(_toConsumableArray(formattedValueOptions));
|
|
282
|
+
var letter = worksheet.getColumn(column.field).letter;
|
|
283
|
+
var address = "".concat(valueOptionsSheetName, "!$").concat(letter, "$2:$").concat(letter, "$").concat(values.length);
|
|
284
|
+
acc[column.field] = {
|
|
285
|
+
values: values,
|
|
286
|
+
address: address
|
|
287
|
+
};
|
|
288
|
+
return acc;
|
|
289
|
+
}, {}));
|
|
290
|
+
case 8:
|
|
291
|
+
case "end":
|
|
292
|
+
return _context3.stop();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}, _callee3);
|
|
296
|
+
}));
|
|
297
|
+
return _getDataForValueOptionsSheet.apply(this, arguments);
|
|
298
|
+
}
|
|
299
|
+
function addSerializedRowToWorksheet(serializedRow, worksheet) {
|
|
300
|
+
var row = serializedRow.row,
|
|
301
|
+
dataValidation = serializedRow.dataValidation,
|
|
302
|
+
outlineLevel = serializedRow.outlineLevel,
|
|
303
|
+
mergedCells = serializedRow.mergedCells;
|
|
304
|
+
var newRow = worksheet.addRow(row);
|
|
305
|
+
Object.keys(dataValidation).forEach(function (field) {
|
|
306
|
+
newRow.getCell(field).dataValidation = _extends({}, dataValidation[field]);
|
|
307
|
+
});
|
|
308
|
+
if (outlineLevel) {
|
|
309
|
+
newRow.outlineLevel = outlineLevel;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// use `rowCount`, since worksheet can have additional rows added in `exceljsPreProcess`
|
|
313
|
+
var lastRowIndex = newRow.worksheet.rowCount;
|
|
314
|
+
mergedCells.forEach(function (mergedCell) {
|
|
315
|
+
worksheet.mergeCells(lastRowIndex, mergedCell.leftIndex, lastRowIndex, mergedCell.rightIndex);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
function createValueOptionsSheetIfNeeded(_x4, _x5, _x6) {
|
|
319
|
+
return _createValueOptionsSheetIfNeeded.apply(this, arguments);
|
|
320
|
+
}
|
|
321
|
+
function _createValueOptionsSheetIfNeeded() {
|
|
322
|
+
_createValueOptionsSheetIfNeeded = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(valueOptionsData, sheetName, workbook) {
|
|
323
|
+
var valueOptionsWorksheet;
|
|
324
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
325
|
+
while (1) {
|
|
326
|
+
switch (_context4.prev = _context4.next) {
|
|
327
|
+
case 0:
|
|
328
|
+
if (!(Object.keys(valueOptionsData).length === 0)) {
|
|
329
|
+
_context4.next = 2;
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
return _context4.abrupt("return");
|
|
333
|
+
case 2:
|
|
334
|
+
valueOptionsWorksheet = workbook.addWorksheet(sheetName);
|
|
335
|
+
valueOptionsWorksheet.columns = Object.keys(valueOptionsData).map(function (key) {
|
|
336
|
+
return {
|
|
337
|
+
key: key
|
|
338
|
+
};
|
|
339
|
+
});
|
|
340
|
+
Object.entries(valueOptionsData).forEach(function (_ref5) {
|
|
341
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
342
|
+
field = _ref6[0],
|
|
343
|
+
values = _ref6[1].values;
|
|
344
|
+
valueOptionsWorksheet.getColumn(field).values = values;
|
|
345
|
+
});
|
|
346
|
+
case 5:
|
|
347
|
+
case "end":
|
|
348
|
+
return _context4.stop();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}, _callee4);
|
|
352
|
+
}));
|
|
353
|
+
return _createValueOptionsSheetIfNeeded.apply(this, arguments);
|
|
354
|
+
}
|
|
355
|
+
export function buildExcel(_x7, _x8) {
|
|
244
356
|
return _buildExcel.apply(this, arguments);
|
|
245
357
|
}
|
|
246
358
|
function _buildExcel() {
|
|
247
|
-
_buildExcel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
248
|
-
var columns, rowIds, includeHeaders, includeColumnGroupsHeaders, valueOptionsSheetName, exceljsPreProcess, exceljsPostProcess, _options$columnsStyle, columnsStyles, excelJS, workbook, worksheet,
|
|
249
|
-
return _regeneratorRuntime.wrap(function
|
|
359
|
+
_buildExcel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(options, api) {
|
|
360
|
+
var columns, rowIds, includeHeaders, includeColumnGroupsHeaders, _options$valueOptions, valueOptionsSheetName, exceljsPreProcess, exceljsPostProcess, _options$columnsStyle, columnsStyles, excelJS, workbook, worksheet, serializedColumns, columnGroupPaths, valueOptionsData;
|
|
361
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
250
362
|
while (1) {
|
|
251
|
-
switch (
|
|
363
|
+
switch (_context5.prev = _context5.next) {
|
|
252
364
|
case 0:
|
|
253
|
-
columns = options.columns, rowIds = options.rowIds, includeHeaders = options.includeHeaders, includeColumnGroupsHeaders = options.includeColumnGroupsHeaders,
|
|
254
|
-
|
|
365
|
+
columns = options.columns, rowIds = options.rowIds, includeHeaders = options.includeHeaders, includeColumnGroupsHeaders = options.includeColumnGroupsHeaders, _options$valueOptions = options.valueOptionsSheetName, valueOptionsSheetName = _options$valueOptions === void 0 ? 'Options' : _options$valueOptions, exceljsPreProcess = options.exceljsPreProcess, exceljsPostProcess = options.exceljsPostProcess, _options$columnsStyle = options.columnsStyles, columnsStyles = _options$columnsStyle === void 0 ? {} : _options$columnsStyle;
|
|
366
|
+
_context5.next = 3;
|
|
255
367
|
return getExcelJs();
|
|
256
368
|
case 3:
|
|
257
|
-
excelJS =
|
|
369
|
+
excelJS = _context5.sent;
|
|
258
370
|
workbook = new excelJS.Workbook();
|
|
259
371
|
worksheet = workbook.addWorksheet('Sheet1');
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
});
|
|
372
|
+
serializedColumns = serializeColumns(columns, columnsStyles);
|
|
373
|
+
worksheet.columns = serializedColumns;
|
|
263
374
|
if (!exceljsPreProcess) {
|
|
264
|
-
|
|
375
|
+
_context5.next = 11;
|
|
265
376
|
break;
|
|
266
377
|
}
|
|
267
|
-
|
|
378
|
+
_context5.next = 11;
|
|
268
379
|
return exceljsPreProcess({
|
|
269
380
|
workbook: workbook,
|
|
270
381
|
worksheet: worksheet
|
|
271
382
|
});
|
|
272
|
-
case
|
|
383
|
+
case 11:
|
|
273
384
|
if (includeColumnGroupsHeaders) {
|
|
274
|
-
|
|
385
|
+
columnGroupPaths = columns.reduce(function (acc, column) {
|
|
386
|
+
acc[column.field] = api.unstable_getColumnGroupPath(column.field);
|
|
387
|
+
return acc;
|
|
388
|
+
}, {});
|
|
389
|
+
addColumnGroupingHeaders(worksheet, serializedColumns, columnGroupPaths, api.unstable_getAllGroupDetails());
|
|
275
390
|
}
|
|
276
391
|
if (includeHeaders) {
|
|
277
392
|
worksheet.addRow(columns.map(function (column) {
|
|
278
|
-
var _column$
|
|
279
|
-
return (_column$
|
|
393
|
+
var _column$headerName3;
|
|
394
|
+
return (_column$headerName3 = column.headerName) != null ? _column$headerName3 : column.field;
|
|
280
395
|
}));
|
|
281
396
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
valueOptionsWorksheet = workbook.addWorksheet(valueOptionsSheetName);
|
|
288
|
-
valueOptionsWorksheet.columns = columnsWithArrayValueOptions.map(function (_ref4) {
|
|
289
|
-
var field = _ref4.field;
|
|
290
|
-
return {
|
|
291
|
-
key: field
|
|
292
|
-
};
|
|
293
|
-
});
|
|
294
|
-
columnsWithArrayValueOptions.forEach(function (column) {
|
|
295
|
-
var _column$headerName2;
|
|
296
|
-
var formattedValueOptions = getFormattedValueOptions(column, column.valueOptions, api);
|
|
297
|
-
valueOptionsWorksheet.getColumn(column.field).values = [(_column$headerName2 = column.headerName) != null ? _column$headerName2 : column.field].concat(_toConsumableArray(formattedValueOptions));
|
|
298
|
-
var columnLetter = valueOptionsWorksheet.getColumn(column.field).letter;
|
|
299
|
-
defaultValueOptionsFormulae[column.field] = "".concat(valueOptionsSheetName, "!$").concat(columnLetter, "$2:$").concat(columnLetter, "$").concat(1 + formattedValueOptions.length);
|
|
300
|
-
});
|
|
301
|
-
}
|
|
397
|
+
_context5.next = 15;
|
|
398
|
+
return getDataForValueOptionsSheet(columns, valueOptionsSheetName, api);
|
|
399
|
+
case 15:
|
|
400
|
+
valueOptionsData = _context5.sent;
|
|
401
|
+
createValueOptionsSheetIfNeeded(valueOptionsData, valueOptionsSheetName, workbook);
|
|
302
402
|
rowIds.forEach(function (id) {
|
|
303
|
-
var
|
|
304
|
-
|
|
305
|
-
dataValidation = _serializeRow.dataValidation,
|
|
306
|
-
outlineLevel = _serializeRow.outlineLevel,
|
|
307
|
-
mergedCells = _serializeRow.mergedCells;
|
|
308
|
-
var newRow = worksheet.addRow(row);
|
|
309
|
-
Object.keys(dataValidation).forEach(function (field) {
|
|
310
|
-
newRow.getCell(field).dataValidation = _extends({}, dataValidation[field]);
|
|
311
|
-
});
|
|
312
|
-
if (outlineLevel) {
|
|
313
|
-
newRow.outlineLevel = outlineLevel;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// use `rowCount`, since worksheet can have additional rows added in `exceljsPreProcess`
|
|
317
|
-
var lastRowIndex = newRow.worksheet.rowCount;
|
|
318
|
-
mergedCells.forEach(function (mergedCell) {
|
|
319
|
-
worksheet.mergeCells(lastRowIndex, mergedCell.leftIndex, lastRowIndex, mergedCell.rightIndex);
|
|
320
|
-
});
|
|
403
|
+
var serializedRow = serializeRow(id, columns, api, valueOptionsData);
|
|
404
|
+
addSerializedRowToWorksheet(serializedRow, worksheet);
|
|
321
405
|
});
|
|
322
406
|
if (!exceljsPostProcess) {
|
|
323
|
-
|
|
407
|
+
_context5.next = 21;
|
|
324
408
|
break;
|
|
325
409
|
}
|
|
326
|
-
|
|
410
|
+
_context5.next = 21;
|
|
327
411
|
return exceljsPostProcess({
|
|
328
412
|
workbook: workbook,
|
|
329
413
|
worksheet: worksheet
|
|
330
414
|
});
|
|
331
|
-
case
|
|
332
|
-
return
|
|
333
|
-
case
|
|
415
|
+
case 21:
|
|
416
|
+
return _context5.abrupt("return", workbook);
|
|
417
|
+
case 22:
|
|
334
418
|
case "end":
|
|
335
|
-
return
|
|
419
|
+
return _context5.stop();
|
|
336
420
|
}
|
|
337
421
|
}
|
|
338
|
-
},
|
|
422
|
+
}, _callee5);
|
|
339
423
|
}));
|
|
340
424
|
return _buildExcel.apply(this, arguments);
|
|
425
|
+
}
|
|
426
|
+
export function setupExcelExportWebWorker() {
|
|
427
|
+
var workerOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
428
|
+
// eslint-disable-next-line no-restricted-globals
|
|
429
|
+
addEventListener('message', /*#__PURE__*/function () {
|
|
430
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(event) {
|
|
431
|
+
var _options$includeHeade;
|
|
432
|
+
var _event$data, serializedColumns, serializedRows, options, valueOptionsSheetName, valueOptionsData, columnGroupDetails, columnGroupPaths, exceljsPostProcess, exceljsPreProcess, excelJS, workbook, worksheet, includeHeaders;
|
|
433
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
434
|
+
while (1) {
|
|
435
|
+
switch (_context2.prev = _context2.next) {
|
|
436
|
+
case 0:
|
|
437
|
+
_event$data = event.data, serializedColumns = _event$data.serializedColumns, serializedRows = _event$data.serializedRows, options = _event$data.options, valueOptionsSheetName = _event$data.valueOptionsSheetName, valueOptionsData = _event$data.valueOptionsData, columnGroupDetails = _event$data.columnGroupDetails, columnGroupPaths = _event$data.columnGroupPaths;
|
|
438
|
+
exceljsPostProcess = workerOptions.exceljsPostProcess, exceljsPreProcess = workerOptions.exceljsPreProcess;
|
|
439
|
+
_context2.next = 4;
|
|
440
|
+
return getExcelJs();
|
|
441
|
+
case 4:
|
|
442
|
+
excelJS = _context2.sent;
|
|
443
|
+
workbook = new excelJS.Workbook();
|
|
444
|
+
worksheet = workbook.addWorksheet('Sheet1');
|
|
445
|
+
worksheet.columns = serializedColumns;
|
|
446
|
+
if (!exceljsPreProcess) {
|
|
447
|
+
_context2.next = 11;
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
_context2.next = 11;
|
|
451
|
+
return exceljsPreProcess({
|
|
452
|
+
workbook: workbook,
|
|
453
|
+
worksheet: worksheet
|
|
454
|
+
});
|
|
455
|
+
case 11:
|
|
456
|
+
if (options.includeColumnGroupsHeaders) {
|
|
457
|
+
addColumnGroupingHeaders(worksheet, serializedColumns, columnGroupPaths, columnGroupDetails);
|
|
458
|
+
}
|
|
459
|
+
includeHeaders = (_options$includeHeade = options.includeHeaders) != null ? _options$includeHeade : true;
|
|
460
|
+
if (includeHeaders) {
|
|
461
|
+
worksheet.addRow(serializedColumns.map(function (column) {
|
|
462
|
+
return column.headerText;
|
|
463
|
+
}));
|
|
464
|
+
}
|
|
465
|
+
createValueOptionsSheetIfNeeded(valueOptionsData, valueOptionsSheetName, workbook);
|
|
466
|
+
serializedRows.forEach(function (serializedRow) {
|
|
467
|
+
addSerializedRowToWorksheet(serializedRow, worksheet);
|
|
468
|
+
});
|
|
469
|
+
if (!exceljsPostProcess) {
|
|
470
|
+
_context2.next = 19;
|
|
471
|
+
break;
|
|
472
|
+
}
|
|
473
|
+
_context2.next = 19;
|
|
474
|
+
return exceljsPostProcess({
|
|
475
|
+
workbook: workbook,
|
|
476
|
+
worksheet: worksheet
|
|
477
|
+
});
|
|
478
|
+
case 19:
|
|
479
|
+
_context2.t0 = postMessage;
|
|
480
|
+
_context2.next = 22;
|
|
481
|
+
return workbook.xlsx.writeBuffer();
|
|
482
|
+
case 22:
|
|
483
|
+
_context2.t1 = _context2.sent;
|
|
484
|
+
(0, _context2.t0)(_context2.t1);
|
|
485
|
+
case 24:
|
|
486
|
+
case "end":
|
|
487
|
+
return _context2.stop();
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}, _callee2);
|
|
491
|
+
}));
|
|
492
|
+
return function (_x9) {
|
|
493
|
+
return _ref4.apply(this, arguments);
|
|
494
|
+
};
|
|
495
|
+
}());
|
|
341
496
|
}
|