@mui/x-data-grid-premium 7.26.0 → 7.27.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 +62 -0
- package/DataGridPremium/DataGridPremium.js +6 -0
- package/DataGridPremium/useDataGridPremiumComponent.js +1 -1
- package/esm/DataGridPremium/DataGridPremium.js +6 -0
- package/esm/DataGridPremium/useDataGridPremiumComponent.js +1 -1
- package/esm/hooks/features/clipboard/useGridClipboardImport.js +2 -2
- package/esm/hooks/features/export/index.js +1 -1
- package/esm/hooks/features/export/serializer/excelSerializer.js +69 -180
- package/esm/hooks/features/export/serializer/setupExcelExportWebWorker.js +53 -0
- package/esm/hooks/features/export/serializer/utils.js +93 -0
- package/esm/hooks/features/export/useGridExcelExport.js +11 -5
- package/esm/setupExcelExportWebWorker.js +1 -0
- package/esm/utils/releaseInfo.js +1 -1
- package/hooks/features/clipboard/useGridClipboardImport.js +2 -2
- package/hooks/features/export/index.d.ts +1 -1
- package/hooks/features/export/index.js +2 -2
- package/hooks/features/export/serializer/excelSerializer.d.ts +3 -31
- package/hooks/features/export/serializer/excelSerializer.js +74 -187
- package/hooks/features/export/serializer/setupExcelExportWebWorker.d.ts +2 -0
- package/hooks/features/export/serializer/setupExcelExportWebWorker.js +59 -0
- package/hooks/features/export/serializer/utils.d.ts +36 -0
- package/hooks/features/export/serializer/utils.js +106 -0
- package/hooks/features/export/useGridExcelExport.js +10 -3
- package/index.js +1 -1
- package/modern/DataGridPremium/DataGridPremium.js +6 -0
- package/modern/DataGridPremium/useDataGridPremiumComponent.js +1 -1
- package/modern/hooks/features/clipboard/useGridClipboardImport.js +2 -2
- package/modern/hooks/features/export/index.js +1 -1
- package/modern/hooks/features/export/serializer/excelSerializer.js +69 -180
- package/modern/hooks/features/export/serializer/setupExcelExportWebWorker.js +53 -0
- package/modern/hooks/features/export/serializer/utils.js +93 -0
- package/modern/hooks/features/export/useGridExcelExport.js +11 -5
- package/modern/index.js +1 -1
- package/modern/setupExcelExportWebWorker.js +1 -0
- package/modern/utils/releaseInfo.js +1 -1
- package/package.json +3 -3
- package/setupExcelExportWebWorker.d.ts +1 -0
- package/setupExcelExportWebWorker.js +12 -0
- package/utils/releaseInfo.js +1 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
export const getExcelJs = async () => {
|
|
3
|
+
const excelJsModule = await import('exceljs');
|
|
4
|
+
return excelJsModule.default ?? excelJsModule;
|
|
5
|
+
};
|
|
6
|
+
export const addColumnGroupingHeaders = (worksheet, columns, columnGroupPaths, columnGroupDetails) => {
|
|
7
|
+
const maxDepth = Math.max(...columns.map(({
|
|
8
|
+
key
|
|
9
|
+
}) => columnGroupPaths[key]?.length ?? 0));
|
|
10
|
+
if (maxDepth === 0) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
for (let rowIndex = 0; rowIndex < maxDepth; rowIndex += 1) {
|
|
14
|
+
const row = columns.map(({
|
|
15
|
+
key
|
|
16
|
+
}) => {
|
|
17
|
+
const groupingPath = columnGroupPaths[key];
|
|
18
|
+
if (groupingPath.length <= rowIndex) {
|
|
19
|
+
return {
|
|
20
|
+
groupId: null,
|
|
21
|
+
parents: groupingPath
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return _extends({}, columnGroupDetails[groupingPath[rowIndex]], {
|
|
25
|
+
parents: groupingPath.slice(0, rowIndex)
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
const newRow = worksheet.addRow(row.map(group => group.groupId === null ? null : group?.headerName ?? group.groupId));
|
|
29
|
+
|
|
30
|
+
// use `rowCount`, since worksheet can have additional rows added in `exceljsPreProcess`
|
|
31
|
+
const lastRowIndex = newRow.worksheet.rowCount;
|
|
32
|
+
let leftIndex = 0;
|
|
33
|
+
let rightIndex = 1;
|
|
34
|
+
while (rightIndex < columns.length) {
|
|
35
|
+
const {
|
|
36
|
+
groupId: leftGroupId,
|
|
37
|
+
parents: leftParents
|
|
38
|
+
} = row[leftIndex];
|
|
39
|
+
const {
|
|
40
|
+
groupId: rightGroupId,
|
|
41
|
+
parents: rightParents
|
|
42
|
+
} = row[rightIndex];
|
|
43
|
+
const areInSameGroup = leftGroupId === rightGroupId && leftParents.length === rightParents.length && leftParents.every((leftParent, index) => rightParents[index] === leftParent);
|
|
44
|
+
if (areInSameGroup) {
|
|
45
|
+
rightIndex += 1;
|
|
46
|
+
} else {
|
|
47
|
+
if (rightIndex - leftIndex > 1) {
|
|
48
|
+
worksheet.mergeCells(lastRowIndex, leftIndex + 1, lastRowIndex, rightIndex);
|
|
49
|
+
}
|
|
50
|
+
leftIndex = rightIndex;
|
|
51
|
+
rightIndex += 1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (rightIndex - leftIndex > 1) {
|
|
55
|
+
worksheet.mergeCells(lastRowIndex, leftIndex + 1, lastRowIndex, rightIndex);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
export function addSerializedRowToWorksheet(serializedRow, worksheet) {
|
|
60
|
+
const {
|
|
61
|
+
row,
|
|
62
|
+
dataValidation,
|
|
63
|
+
outlineLevel,
|
|
64
|
+
mergedCells
|
|
65
|
+
} = serializedRow;
|
|
66
|
+
const newRow = worksheet.addRow(row);
|
|
67
|
+
Object.keys(dataValidation).forEach(field => {
|
|
68
|
+
newRow.getCell(field).dataValidation = _extends({}, dataValidation[field]);
|
|
69
|
+
});
|
|
70
|
+
if (outlineLevel) {
|
|
71
|
+
newRow.outlineLevel = outlineLevel;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// use `rowCount`, since worksheet can have additional rows added in `exceljsPreProcess`
|
|
75
|
+
const lastRowIndex = newRow.worksheet.rowCount;
|
|
76
|
+
mergedCells.forEach(mergedCell => {
|
|
77
|
+
worksheet.mergeCells(lastRowIndex, mergedCell.leftIndex, lastRowIndex, mergedCell.rightIndex);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export async function createValueOptionsSheetIfNeeded(valueOptionsData, sheetName, workbook) {
|
|
81
|
+
if (Object.keys(valueOptionsData).length === 0) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const valueOptionsWorksheet = workbook.addWorksheet(sheetName);
|
|
85
|
+
valueOptionsWorksheet.columns = Object.keys(valueOptionsData).map(key => ({
|
|
86
|
+
key
|
|
87
|
+
}));
|
|
88
|
+
Object.entries(valueOptionsData).forEach(([field, {
|
|
89
|
+
values
|
|
90
|
+
}]) => {
|
|
91
|
+
valueOptionsWorksheet.getColumn(field).values = values;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
@@ -5,7 +5,7 @@ import { useGridApiMethod, useGridLogger, useGridApiOptionHandler } from '@mui/x
|
|
|
5
5
|
import { useGridRegisterPipeProcessor, exportAs, getColumnsToExport, defaultGetRowsToExport } from '@mui/x-data-grid/internals';
|
|
6
6
|
import { buildExcel, getDataForValueOptionsSheet, serializeColumns, serializeRowUnsafe } from "./serializer/excelSerializer.js";
|
|
7
7
|
import { GridExcelExportMenuItem } from "../../../components/index.js";
|
|
8
|
-
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
9
|
/**
|
|
10
10
|
* @requires useGridColumns (state)
|
|
11
11
|
* @requires useGridFilter (state)
|
|
@@ -13,7 +13,6 @@ import { GridExcelExportMenuItem } from "../../../components/index.js";
|
|
|
13
13
|
* @requires useGridSelection (state)
|
|
14
14
|
* @requires useGridParamsApi (method)
|
|
15
15
|
*/
|
|
16
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
16
|
export const useGridExcelExport = (apiRef, props) => {
|
|
18
17
|
const logger = useGridLogger(apiRef, 'useGridExcelExport');
|
|
19
18
|
const getDataAsExcel = React.useCallback((options = {}) => {
|
|
@@ -89,15 +88,22 @@ export const useGridExcelExport = (apiRef, props) => {
|
|
|
89
88
|
const valueOptionsData = await getDataForValueOptionsSheet(exportedColumns, valueOptionsSheetName, apiRef.current);
|
|
90
89
|
const serializedColumns = serializeColumns(exportedColumns, options.columnsStyles || {});
|
|
91
90
|
apiRef.current.resetColSpan();
|
|
92
|
-
const serializedRows =
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
const serializedRows = [];
|
|
92
|
+
for (let i = 0; i < exportedRowIds.length; i += 1) {
|
|
93
|
+
const id = exportedRowIds[i];
|
|
94
|
+
const serializedRow = serializeRowUnsafe(id, exportedColumns, apiRef, valueOptionsData, {
|
|
95
|
+
escapeFormulas: options.escapeFormulas ?? true
|
|
96
|
+
});
|
|
97
|
+
serializedRows.push(serializedRow);
|
|
98
|
+
}
|
|
95
99
|
apiRef.current.resetColSpan();
|
|
96
100
|
const columnGroupPaths = exportedColumns.reduce((acc, column) => {
|
|
97
101
|
acc[column.field] = apiRef.current.getColumnGroupPath(column.field);
|
|
98
102
|
return acc;
|
|
99
103
|
}, {});
|
|
100
104
|
const message = {
|
|
105
|
+
// workers share the pub-sub channel namespace. Use this property to filter out messages.
|
|
106
|
+
namespace: 'mui-x-data-grid-export',
|
|
101
107
|
serializedColumns,
|
|
102
108
|
serializedRows,
|
|
103
109
|
valueOptionsData,
|
package/modern/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { setupExcelExportWebWorker } from "./hooks/features/export/serializer/setupExcelExportWebWorker.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ponyfillGlobal } from '@mui/utils';
|
|
2
2
|
export const getReleaseInfo = () => {
|
|
3
|
-
const releaseInfo = "
|
|
3
|
+
const releaseInfo = "MTczOTc0NjgwMDAwMA==";
|
|
4
4
|
if (process.env.NODE_ENV !== 'production') {
|
|
5
5
|
// A simple hack to set the value in the test environment (has no build step).
|
|
6
6
|
// eslint-disable-next-line no-useless-concat
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-data-grid-premium",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.27.0",
|
|
4
4
|
"description": "The Premium plan edition of the Data Grid Components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"exceljs": "^4.4.0",
|
|
41
41
|
"prop-types": "^15.8.1",
|
|
42
42
|
"reselect": "^5.1.1",
|
|
43
|
-
"@mui/x-data-grid
|
|
43
|
+
"@mui/x-data-grid": "7.27.0",
|
|
44
|
+
"@mui/x-data-grid-pro": "7.27.0",
|
|
44
45
|
"@mui/x-license": "7.26.0",
|
|
45
|
-
"@mui/x-data-grid": "7.26.0",
|
|
46
46
|
"@mui/x-internals": "7.26.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { setupExcelExportWebWorker } from './hooks/features/export/serializer/setupExcelExportWebWorker';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "setupExcelExportWebWorker", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _setupExcelExportWebWorker.setupExcelExportWebWorker;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _setupExcelExportWebWorker = require("./hooks/features/export/serializer/setupExcelExportWebWorker");
|
package/utils/releaseInfo.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getReleaseInfo = void 0;
|
|
7
7
|
var _utils = require("@mui/utils");
|
|
8
8
|
const getReleaseInfo = () => {
|
|
9
|
-
const releaseInfo = "
|
|
9
|
+
const releaseInfo = "MTczOTc0NjgwMDAwMA==";
|
|
10
10
|
if (process.env.NODE_ENV !== 'production') {
|
|
11
11
|
// A simple hack to set the value in the test environment (has no build step).
|
|
12
12
|
// eslint-disable-next-line no-useless-concat
|