@mui/x-data-grid-premium 5.11.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.
Files changed (199) hide show
  1. package/CHANGELOG.md +4052 -0
  2. package/DataGridPremium/DataGridPremium.d.ts +9 -0
  3. package/DataGridPremium/DataGridPremium.js +986 -0
  4. package/DataGridPremium/index.d.ts +2 -0
  5. package/DataGridPremium/index.js +2 -0
  6. package/DataGridPremium/package.json +6 -0
  7. package/DataGridPremium/useDataGridPremiumComponent.d.ts +4 -0
  8. package/DataGridPremium/useDataGridPremiumComponent.js +78 -0
  9. package/DataGridPremium/useDataGridPremiumProps.d.ts +6 -0
  10. package/DataGridPremium/useDataGridPremiumProps.js +37 -0
  11. package/LICENSE +12 -0
  12. package/README.md +31 -0
  13. package/components/GridExcelExportMenuItem.d.ts +9 -0
  14. package/components/GridExcelExportMenuItem.js +32 -0
  15. package/components/GridGroupingColumnLeafCell.d.ts +4 -0
  16. package/components/GridGroupingColumnLeafCell.js +22 -0
  17. package/components/GridGroupingCriteriaCell.d.ts +7 -0
  18. package/components/GridGroupingCriteriaCell.js +78 -0
  19. package/components/GridRowGroupableColumnMenuItems.d.ts +11 -0
  20. package/components/GridRowGroupableColumnMenuItems.js +63 -0
  21. package/components/GridRowGroupingColumnMenuItems.d.ts +11 -0
  22. package/components/GridRowGroupingColumnMenuItems.js +58 -0
  23. package/components/index.d.ts +1 -0
  24. package/components/index.js +1 -0
  25. package/components/package.json +6 -0
  26. package/hooks/features/export/gridExcelExportInterface.d.ts +58 -0
  27. package/hooks/features/export/gridExcelExportInterface.js +1 -0
  28. package/hooks/features/export/index.d.ts +1 -0
  29. package/hooks/features/export/index.js +1 -0
  30. package/hooks/features/export/serializer/excelSerializer.d.ts +14 -0
  31. package/hooks/features/export/serializer/excelSerializer.js +218 -0
  32. package/hooks/features/export/useGridExcelExport.d.ts +10 -0
  33. package/hooks/features/export/useGridExcelExport.js +77 -0
  34. package/hooks/features/index.d.ts +2 -0
  35. package/hooks/features/index.js +3 -0
  36. package/hooks/features/rowGrouping/createGroupingColDef.d.ts +42 -0
  37. package/hooks/features/rowGrouping/createGroupingColDef.js +318 -0
  38. package/hooks/features/rowGrouping/gridRowGroupingInterfaces.d.ts +37 -0
  39. package/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
  40. package/hooks/features/rowGrouping/gridRowGroupingSelector.d.ts +4 -0
  41. package/hooks/features/rowGrouping/gridRowGroupingSelector.js +5 -0
  42. package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +27 -0
  43. package/hooks/features/rowGrouping/gridRowGroupingUtils.js +139 -0
  44. package/hooks/features/rowGrouping/index.d.ts +3 -0
  45. package/hooks/features/rowGrouping/index.js +3 -0
  46. package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +11 -0
  47. package/hooks/features/rowGrouping/useGridRowGrouping.js +200 -0
  48. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.d.ts +4 -0
  49. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +201 -0
  50. package/hooks/index.d.ts +2 -0
  51. package/hooks/index.js +3 -0
  52. package/hooks/package.json +6 -0
  53. package/hooks/utils/index.d.ts +1 -0
  54. package/hooks/utils/index.js +1 -0
  55. package/hooks/utils/useGridApiContext.d.ts +4 -0
  56. package/hooks/utils/useGridApiContext.js +2 -0
  57. package/hooks/utils/useGridApiRef.d.ts +4 -0
  58. package/hooks/utils/useGridApiRef.js +2 -0
  59. package/hooks/utils/useGridRootProps.d.ts +2 -0
  60. package/hooks/utils/useGridRootProps.js +2 -0
  61. package/hooks/utils/useKeepGroupedColumnsHidden.d.ts +12 -0
  62. package/hooks/utils/useKeepGroupedColumnsHidden.js +50 -0
  63. package/index.d.ts +22 -0
  64. package/index.js +25 -0
  65. package/legacy/DataGridPremium/DataGridPremium.js +986 -0
  66. package/legacy/DataGridPremium/index.js +2 -0
  67. package/legacy/DataGridPremium/useDataGridPremiumComponent.js +78 -0
  68. package/legacy/DataGridPremium/useDataGridPremiumProps.js +46 -0
  69. package/legacy/components/GridExcelExportMenuItem.js +30 -0
  70. package/legacy/components/GridGroupingColumnLeafCell.js +20 -0
  71. package/legacy/components/GridGroupingCriteriaCell.js +74 -0
  72. package/legacy/components/GridRowGroupableColumnMenuItems.js +61 -0
  73. package/legacy/components/GridRowGroupingColumnMenuItems.js +56 -0
  74. package/legacy/components/index.js +1 -0
  75. package/legacy/hooks/features/export/gridExcelExportInterface.js +1 -0
  76. package/legacy/hooks/features/export/index.js +1 -0
  77. package/legacy/hooks/features/export/serializer/excelSerializer.js +260 -0
  78. package/legacy/hooks/features/export/useGridExcelExport.js +111 -0
  79. package/legacy/hooks/features/index.js +3 -0
  80. package/legacy/hooks/features/rowGrouping/createGroupingColDef.js +319 -0
  81. package/legacy/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
  82. package/legacy/hooks/features/rowGrouping/gridRowGroupingSelector.js +13 -0
  83. package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +147 -0
  84. package/legacy/hooks/features/rowGrouping/index.js +3 -0
  85. package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +206 -0
  86. package/legacy/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +215 -0
  87. package/legacy/hooks/index.js +3 -0
  88. package/legacy/hooks/utils/index.js +1 -0
  89. package/legacy/hooks/utils/useGridApiContext.js +2 -0
  90. package/legacy/hooks/utils/useGridApiRef.js +2 -0
  91. package/legacy/hooks/utils/useGridRootProps.js +2 -0
  92. package/legacy/hooks/utils/useKeepGroupedColumnsHidden.js +50 -0
  93. package/legacy/index.js +25 -0
  94. package/legacy/models/dataGridPremiumProps.js +1 -0
  95. package/legacy/models/gridApiPremium.js +1 -0
  96. package/legacy/models/gridGroupingValueGetterParams.js +1 -0
  97. package/legacy/models/gridStatePremium.js +1 -0
  98. package/legacy/models/index.js +1 -0
  99. package/legacy/typeOverloads/index.js +1 -0
  100. package/legacy/typeOverloads/modules.js +33 -0
  101. package/legacy/typeOverloads/reexports.js +6 -0
  102. package/legacy/utils/releaseInfo.js +15 -0
  103. package/models/dataGridPremiumProps.d.ts +64 -0
  104. package/models/dataGridPremiumProps.js +1 -0
  105. package/models/gridApiPremium.d.ts +13 -0
  106. package/models/gridApiPremium.js +1 -0
  107. package/models/gridGroupingValueGetterParams.d.ts +31 -0
  108. package/models/gridGroupingValueGetterParams.js +1 -0
  109. package/models/gridStatePremium.d.ts +14 -0
  110. package/models/gridStatePremium.js +1 -0
  111. package/models/index.d.ts +1 -0
  112. package/models/index.js +1 -0
  113. package/models/package.json +6 -0
  114. package/modern/DataGridPremium/DataGridPremium.js +986 -0
  115. package/modern/DataGridPremium/index.js +2 -0
  116. package/modern/DataGridPremium/useDataGridPremiumComponent.js +76 -0
  117. package/modern/DataGridPremium/useDataGridPremiumProps.js +37 -0
  118. package/modern/components/GridExcelExportMenuItem.js +32 -0
  119. package/modern/components/GridGroupingColumnLeafCell.js +20 -0
  120. package/modern/components/GridGroupingCriteriaCell.js +76 -0
  121. package/modern/components/GridRowGroupableColumnMenuItems.js +61 -0
  122. package/modern/components/GridRowGroupingColumnMenuItems.js +56 -0
  123. package/modern/components/index.js +1 -0
  124. package/modern/hooks/features/export/gridExcelExportInterface.js +1 -0
  125. package/modern/hooks/features/export/index.js +1 -0
  126. package/modern/hooks/features/export/serializer/excelSerializer.js +216 -0
  127. package/modern/hooks/features/export/useGridExcelExport.js +73 -0
  128. package/modern/hooks/features/index.js +3 -0
  129. package/modern/hooks/features/rowGrouping/createGroupingColDef.js +302 -0
  130. package/modern/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
  131. package/modern/hooks/features/rowGrouping/gridRowGroupingSelector.js +5 -0
  132. package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +137 -0
  133. package/modern/hooks/features/rowGrouping/index.js +3 -0
  134. package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +192 -0
  135. package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +201 -0
  136. package/modern/hooks/index.js +3 -0
  137. package/modern/hooks/utils/index.js +1 -0
  138. package/modern/hooks/utils/useGridApiContext.js +2 -0
  139. package/modern/hooks/utils/useGridApiRef.js +2 -0
  140. package/modern/hooks/utils/useGridRootProps.js +2 -0
  141. package/modern/hooks/utils/useKeepGroupedColumnsHidden.js +46 -0
  142. package/modern/index.js +25 -0
  143. package/modern/models/dataGridPremiumProps.js +1 -0
  144. package/modern/models/gridApiPremium.js +1 -0
  145. package/modern/models/gridGroupingValueGetterParams.js +1 -0
  146. package/modern/models/gridStatePremium.js +1 -0
  147. package/modern/models/index.js +1 -0
  148. package/modern/typeOverloads/index.js +1 -0
  149. package/modern/typeOverloads/modules.js +33 -0
  150. package/modern/typeOverloads/reexports.js +6 -0
  151. package/modern/utils/releaseInfo.js +15 -0
  152. package/node/DataGridPremium/DataGridPremium.js +1009 -0
  153. package/node/DataGridPremium/index.js +30 -0
  154. package/node/DataGridPremium/useDataGridPremiumComponent.js +91 -0
  155. package/node/DataGridPremium/useDataGridPremiumProps.js +57 -0
  156. package/node/components/GridExcelExportMenuItem.js +49 -0
  157. package/node/components/GridGroupingColumnLeafCell.js +38 -0
  158. package/node/components/GridGroupingCriteriaCell.js +99 -0
  159. package/node/components/GridRowGroupableColumnMenuItems.js +82 -0
  160. package/node/components/GridRowGroupingColumnMenuItems.js +78 -0
  161. package/node/components/index.js +18 -0
  162. package/node/hooks/features/export/gridExcelExportInterface.js +5 -0
  163. package/node/hooks/features/export/index.js +18 -0
  164. package/node/hooks/features/export/serializer/excelSerializer.js +233 -0
  165. package/node/hooks/features/export/useGridExcelExport.js +95 -0
  166. package/node/hooks/features/index.js +31 -0
  167. package/node/hooks/features/rowGrouping/createGroupingColDef.js +341 -0
  168. package/node/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +5 -0
  169. package/node/hooks/features/rowGrouping/gridRowGroupingSelector.js +18 -0
  170. package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +172 -0
  171. package/node/hooks/features/rowGrouping/index.js +51 -0
  172. package/node/hooks/features/rowGrouping/useGridRowGrouping.js +228 -0
  173. package/node/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +223 -0
  174. package/node/hooks/index.js +31 -0
  175. package/node/hooks/utils/index.js +18 -0
  176. package/node/hooks/utils/useGridApiContext.js +11 -0
  177. package/node/hooks/utils/useGridApiRef.js +11 -0
  178. package/node/hooks/utils/useGridRootProps.js +11 -0
  179. package/node/hooks/utils/useKeepGroupedColumnsHidden.js +66 -0
  180. package/node/index.js +272 -0
  181. package/node/models/dataGridPremiumProps.js +5 -0
  182. package/node/models/gridApiPremium.js +5 -0
  183. package/node/models/gridGroupingValueGetterParams.js +5 -0
  184. package/node/models/gridStatePremium.js +5 -0
  185. package/node/models/index.js +18 -0
  186. package/node/typeOverloads/index.js +3 -0
  187. package/node/typeOverloads/modules.js +34 -0
  188. package/node/typeOverloads/reexports.js +29 -0
  189. package/node/utils/releaseInfo.js +25 -0
  190. package/package.json +63 -0
  191. package/typeOverloads/index.d.ts +1 -0
  192. package/typeOverloads/index.js +1 -0
  193. package/typeOverloads/modules.d.ts +0 -0
  194. package/typeOverloads/modules.js +33 -0
  195. package/typeOverloads/package.json +6 -0
  196. package/typeOverloads/reexports.d.ts +22 -0
  197. package/typeOverloads/reexports.js +6 -0
  198. package/utils/releaseInfo.d.ts +1 -0
  199. package/utils/releaseInfo.js +15 -0
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.buildExcel = buildExcel;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _xDataGridPro = require("@mui/x-data-grid-pro");
13
+
14
+ var _internals = require("@mui/x-data-grid/internals");
15
+
16
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
+
18
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
+
20
+ const getExcelJs = () => Promise.resolve().then(() => _interopRequireWildcard(require('exceljs')));
21
+
22
+ const warnInvalidFormattedValue = (0, _internals.buildWarning)(['MUI: When the value of a field is an object or a `renderCell` is provided, the Excel export might not display the value correctly.', 'You can provide a `valueFormatter` with a string representation to be used.']);
23
+
24
+ const getFormattedValueOptions = (colDef, valueOptions, api) => {
25
+ if (!colDef.valueOptions) {
26
+ return [];
27
+ }
28
+
29
+ let valueOptionsFormatted = valueOptions;
30
+
31
+ if (colDef.valueFormatter) {
32
+ valueOptionsFormatted = valueOptionsFormatted.map(option => {
33
+ if (typeof option === 'object') {
34
+ return option;
35
+ }
36
+
37
+ const params = {
38
+ field: colDef.field,
39
+ api,
40
+ value: option
41
+ };
42
+ return String(colDef.valueFormatter(params));
43
+ });
44
+ }
45
+
46
+ return valueOptionsFormatted.map(option => typeof option === 'object' ? option.label : option);
47
+ };
48
+
49
+ const serializeRow = (id, columns, api, defaultValueOptionsFormulae) => {
50
+ const row = {};
51
+ const dataValidation = {};
52
+ const firstCellParams = api.getCellParams(id, columns[0].field);
53
+ const outlineLevel = firstCellParams.rowNode.depth;
54
+ columns.forEach(column => {
55
+ const cellParams = api.getCellParams(id, column.field);
56
+
57
+ switch (cellParams.colDef.type) {
58
+ case 'singleSelect':
59
+ {
60
+ var _formattedValue$label;
61
+
62
+ if (typeof cellParams.colDef.valueOptions === 'function') {
63
+ // If value option depends on the row, set specific options to the cell
64
+ // This dataValidation is buggy with LibreOffice and does not allow to have coma
65
+ const valueOptions = cellParams.colDef.valueOptions({
66
+ id,
67
+ row,
68
+ field: cellParams.field
69
+ });
70
+ const formattedValueOptions = getFormattedValueOptions(cellParams.colDef, valueOptions, api);
71
+ dataValidation[column.field] = {
72
+ type: 'list',
73
+ allowBlank: true,
74
+ formulae: [`"${formattedValueOptions.map(x => x.toString().replaceAll(',', 'CHAR(44)')).join(',')}"`]
75
+ };
76
+ } else {
77
+ // If value option is defined for the column, refer to another sheet
78
+ dataValidation[column.field] = {
79
+ type: 'list',
80
+ allowBlank: true,
81
+ formulae: [defaultValueOptionsFormulae[column.field]]
82
+ };
83
+ }
84
+
85
+ const formattedValue = api.getCellParams(id, column.field).formattedValue;
86
+
87
+ if (process.env.NODE_ENV !== 'production') {
88
+ if (String(cellParams.formattedValue) === '[object Object]') {
89
+ warnInvalidFormattedValue();
90
+ }
91
+ }
92
+
93
+ row[column.field] = (_formattedValue$label = formattedValue == null ? void 0 : formattedValue.label) != null ? _formattedValue$label : formattedValue;
94
+ break;
95
+ }
96
+
97
+ case 'boolean':
98
+ case 'number':
99
+ row[column.field] = api.getCellParams(id, column.field).value;
100
+ break;
101
+
102
+ case 'date':
103
+ case 'dateTime':
104
+ {
105
+ // Excel does not do any timezone conversion, so we create a date using UTC instead of local timezone
106
+ // Solution from: https://github.com/exceljs/exceljs/issues/486#issuecomment-432557582
107
+ // About Date.UTC(): https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC#exemples
108
+ const date = api.getCellParams(id, column.field).value; // value may be `undefined` in auto-generated grouping rows
109
+
110
+ if (!date) {
111
+ break;
112
+ }
113
+
114
+ const utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()));
115
+ row[column.field] = utcDate;
116
+ break;
117
+ }
118
+
119
+ case 'actions':
120
+ break;
121
+
122
+ default:
123
+ row[column.field] = api.getCellParams(id, column.field).formattedValue;
124
+
125
+ if (process.env.NODE_ENV !== 'production') {
126
+ if (String(cellParams.formattedValue) === '[object Object]') {
127
+ warnInvalidFormattedValue();
128
+ }
129
+ }
130
+
131
+ break;
132
+ }
133
+ });
134
+ return {
135
+ row,
136
+ dataValidation,
137
+ outlineLevel
138
+ };
139
+ };
140
+
141
+ const defaultColumnsStyles = {
142
+ [_xDataGridPro.GRID_DATE_COL_DEF.type]: {
143
+ numFmt: 'dd.mm.yyyy'
144
+ },
145
+ [_xDataGridPro.GRID_DATETIME_COL_DEF.type]: {
146
+ numFmt: 'dd.mm.yyyy hh:mm'
147
+ }
148
+ };
149
+
150
+ const serializeColumn = (column, columnsStyles) => {
151
+ const {
152
+ field,
153
+ type
154
+ } = column;
155
+ return {
156
+ key: field,
157
+ // 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)
158
+ // From the example of column width behavior (https://docs.microsoft.com/en-US/office/troubleshoot/excel/determine-column-widths#example-of-column-width-behavior)
159
+ // a value of 10 corresponds to 75px. This is an approximation, because column width depends on the the font-size
160
+ width: Math.min(255, column.width ? column.width / 7.5 : 8.43),
161
+ style: (0, _extends2.default)({}, type && (defaultColumnsStyles == null ? void 0 : defaultColumnsStyles[type]), columnsStyles == null ? void 0 : columnsStyles[field])
162
+ };
163
+ };
164
+
165
+ async function buildExcel(options, api) {
166
+ const {
167
+ columns,
168
+ rowIds,
169
+ includeHeaders,
170
+ valueOptionsSheetName,
171
+ exceljsPreProcess,
172
+ exceljsPostProcess,
173
+ columnsStyles = {}
174
+ } = options;
175
+ const excelJS = await getExcelJs();
176
+ const workbook = new excelJS.Workbook();
177
+ const worksheet = workbook.addWorksheet('Sheet1');
178
+ worksheet.columns = columns.map(column => serializeColumn(column, columnsStyles));
179
+
180
+ if (exceljsPreProcess) {
181
+ await exceljsPreProcess({
182
+ workbook,
183
+ worksheet
184
+ });
185
+ }
186
+
187
+ if (includeHeaders) {
188
+ worksheet.addRow(columns.map(column => column.headerName || column.field));
189
+ }
190
+
191
+ const columnsWithArrayValueOptions = columns.filter(column => column.type === 'singleSelect' && column.valueOptions && typeof column.valueOptions !== 'function');
192
+ const defaultValueOptionsFormulae = {};
193
+
194
+ if (columnsWithArrayValueOptions.length) {
195
+ const valueOptionsWorksheet = workbook.addWorksheet(valueOptionsSheetName);
196
+ valueOptionsWorksheet.columns = columnsWithArrayValueOptions.map(({
197
+ field
198
+ }) => ({
199
+ key: field
200
+ }));
201
+ columnsWithArrayValueOptions.forEach(column => {
202
+ const formattedValueOptions = getFormattedValueOptions(column, column.valueOptions, api);
203
+ valueOptionsWorksheet.getColumn(column.field).values = [column.headerName || column.field, ...formattedValueOptions];
204
+ const columnLetter = valueOptionsWorksheet.getColumn(column.field).letter;
205
+ defaultValueOptionsFormulae[column.field] = `${valueOptionsSheetName}!$${columnLetter}$2:$${columnLetter}$${1 + formattedValueOptions.length}`;
206
+ });
207
+ }
208
+
209
+ rowIds.forEach(id => {
210
+ const {
211
+ row,
212
+ dataValidation,
213
+ outlineLevel
214
+ } = serializeRow(id, columns, api, defaultValueOptionsFormulae);
215
+ const newRow = worksheet.addRow(row);
216
+ Object.keys(dataValidation).forEach(field => {
217
+ newRow.getCell(field).dataValidation = (0, _extends2.default)({}, dataValidation[field]);
218
+ });
219
+
220
+ if (outlineLevel) {
221
+ newRow.outlineLevel = outlineLevel;
222
+ }
223
+ });
224
+
225
+ if (exceljsPostProcess) {
226
+ await exceljsPostProcess({
227
+ workbook,
228
+ worksheet
229
+ });
230
+ }
231
+
232
+ return workbook;
233
+ }
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useGridExcelExport = void 0;
7
+
8
+ var React = _interopRequireWildcard(require("react"));
9
+
10
+ var _xDataGrid = require("@mui/x-data-grid");
11
+
12
+ var _internals = require("@mui/x-data-grid/internals");
13
+
14
+ var _excelSerializer = require("./serializer/excelSerializer");
15
+
16
+ var _components = require("../../../components");
17
+
18
+ var _jsxRuntime = require("react/jsx-runtime");
19
+
20
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
+
22
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
+
24
+ /**
25
+ * @requires useGridColumns (state)
26
+ * @requires useGridFilter (state)
27
+ * @requires useGridSorting (state)
28
+ * @requires useGridSelection (state)
29
+ * @requires useGridParamsApi (method)
30
+ */
31
+ const useGridExcelExport = apiRef => {
32
+ const logger = (0, _xDataGrid.useGridLogger)(apiRef, 'useGridExcelExport');
33
+ const getDataAsExcel = React.useCallback((options = {}) => {
34
+ var _options$getRowsToExp, _options$includeHeade;
35
+
36
+ logger.debug(`Get data as excel`);
37
+ const getRowsToExport = (_options$getRowsToExp = options.getRowsToExport) != null ? _options$getRowsToExp : _internals.defaultGetRowsToExport;
38
+ const exportedRowIds = getRowsToExport({
39
+ apiRef
40
+ });
41
+ const exportedColumns = (0, _internals.getColumnsToExport)({
42
+ apiRef,
43
+ options
44
+ });
45
+ return (0, _excelSerializer.buildExcel)({
46
+ columns: exportedColumns,
47
+ rowIds: exportedRowIds,
48
+ includeHeaders: (_options$includeHeade = options.includeHeaders) != null ? _options$includeHeade : true,
49
+ valueOptionsSheetName: (options == null ? void 0 : options.valueOptionsSheetName) || 'Options',
50
+ columnsStyles: options == null ? void 0 : options.columnsStyles,
51
+ exceljsPreProcess: options == null ? void 0 : options.exceljsPreProcess,
52
+ exceljsPostProcess: options == null ? void 0 : options.exceljsPostProcess
53
+ }, apiRef.current);
54
+ }, [logger, apiRef]);
55
+ const exportDataAsExcel = React.useCallback(async options => {
56
+ logger.debug(`Export data as excel`);
57
+ const workbook = await getDataAsExcel(options);
58
+
59
+ if (workbook === null) {
60
+ return;
61
+ }
62
+
63
+ const content = await workbook.xlsx.writeBuffer();
64
+ const blob = new Blob([content], {
65
+ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
66
+ });
67
+ (0, _internals.exportAs)(blob, 'xlsx', options == null ? void 0 : options.fileName);
68
+ }, [logger, getDataAsExcel]);
69
+ const excelExportApi = {
70
+ getDataAsExcel,
71
+ exportDataAsExcel
72
+ };
73
+ (0, _xDataGrid.useGridApiMethod)(apiRef, excelExportApi, 'GridExcelExportApi');
74
+ /**
75
+ * PRE-PROCESSING
76
+ */
77
+
78
+ const addExportMenuButtons = React.useCallback((initialValue, options) => {
79
+ var _options$excelOptions;
80
+
81
+ if ((_options$excelOptions = options.excelOptions) != null && _options$excelOptions.disableToolbarButton) {
82
+ return initialValue;
83
+ }
84
+
85
+ return [...initialValue, {
86
+ component: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.GridExcelExportMenuItem, {
87
+ options: options.excelOptions
88
+ }),
89
+ componentName: 'excelExport'
90
+ }];
91
+ }, []);
92
+ (0, _internals.useGridRegisterPipeProcessor)(apiRef, 'exportMenu', addExportMenuButtons);
93
+ };
94
+
95
+ exports.useGridExcelExport = useGridExcelExport;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _rowGrouping = require("./rowGrouping");
8
+
9
+ Object.keys(_rowGrouping).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _rowGrouping[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _rowGrouping[key];
16
+ }
17
+ });
18
+ });
19
+
20
+ var _export = require("./export");
21
+
22
+ Object.keys(_export).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _export[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _export[key];
29
+ }
30
+ });
31
+ });