@stenajs-webui/grid-export 17.5.0 → 17.8.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 (34) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/common/CellFormatters.d.ts +2 -2
  3. package/dist/features/grid-copy-to-clipboard/components/StandardTableHtmlCopyToClipboardButton.d.ts +12 -12
  4. package/dist/features/grid-copy-to-clipboard/transformers/AlignmentTransformer.d.ts +1 -1
  5. package/dist/features/grid-copy-to-clipboard/transformers/CellTransformer.d.ts +3 -3
  6. package/dist/features/grid-copy-to-clipboard/transformers/ConfigTransformer.d.ts +3 -3
  7. package/dist/features/grid-copy-to-clipboard/transformers/HeaderTransformer.d.ts +3 -3
  8. package/dist/features/grid-copy-to-clipboard/transformers/RowTransformer.d.ts +4 -4
  9. package/dist/features/grid-copy-to-clipboard/transformers/__mocks__/CopyToClipboardTestData.d.ts +12 -12
  10. package/dist/features/grid-copy-to-clipboard/util/CopyContentToClipboard.d.ts +3 -3
  11. package/dist/features/grid-copy-to-clipboard/util/HtmlRenderer.d.ts +3 -3
  12. package/dist/features/grid-excel-export/components/StandardTableExcelExportButton.d.ts +10 -10
  13. package/dist/features/grid-excel-export/transformers/CellTransformer.d.ts +4 -4
  14. package/dist/features/grid-excel-export/transformers/ConfigTransformer.d.ts +4 -4
  15. package/dist/features/grid-excel-export/transformers/HeaderTransformer.d.ts +5 -5
  16. package/dist/features/grid-excel-export/transformers/RowTransformer.d.ts +5 -5
  17. package/dist/features/grid-excel-export/transformers/__mocks__/ExcelExportTestData.d.ts +12 -12
  18. package/dist/features/grid-excel-export/util/ExcelDownloader.d.ts +3 -3
  19. package/dist/index.d.ts +6 -6
  20. package/dist/index.es.js +219 -328
  21. package/dist/index.es.js.map +1 -1
  22. package/dist/index.js +1 -373
  23. package/dist/index.js.map +1 -1
  24. package/package.json +8 -9
  25. package/dist/features/grid-copy-to-clipboard/stories/StandardTableWithClipboardCopyButton.stories.d.ts +0 -11
  26. package/dist/features/grid-copy-to-clipboard/transformers/__tests__/CellTransformer.test.d.ts +0 -1
  27. package/dist/features/grid-copy-to-clipboard/transformers/__tests__/ConfigTransformer.test.d.ts +0 -1
  28. package/dist/features/grid-copy-to-clipboard/transformers/__tests__/HeaderTransformer.test.d.ts +0 -1
  29. package/dist/features/grid-copy-to-clipboard/transformers/__tests__/RowTransformer.test.d.ts +0 -1
  30. package/dist/features/grid-excel-export/stories/StandardTableWithExport.stories.d.ts +0 -9
  31. package/dist/features/grid-excel-export/transformers/__tests__/CellTransformer.test.d.ts +0 -1
  32. package/dist/features/grid-excel-export/transformers/__tests__/ConfigTransformer.test.d.ts +0 -1
  33. package/dist/features/grid-excel-export/transformers/__tests__/HeaderTransformer.test.d.ts +0 -1
  34. package/dist/features/grid-excel-export/transformers/__tests__/RowTransformer.test.d.ts +0 -1
package/dist/index.es.js CHANGED
@@ -1,343 +1,234 @@
1
- import * as React from 'react';
2
- import { useCallback, useState } from 'react';
3
- import zipcelx from 'zipcelx';
4
- import { formatColumnIdToHeaderCellLabel, createGroupConfigAndIdsForRows } from '@stenajs-webui/grid';
5
- import { flatten } from 'lodash';
6
- import { format } from 'date-fns';
7
- import { FlatButton } from '@stenajs-webui/elements';
8
- import { faFileDownload } from '@fortawesome/free-solid-svg-icons/faFileDownload';
9
- import * as clipboard from 'clipboard-polyfill';
10
-
11
- /*! *****************************************************************************
12
- Copyright (c) Microsoft Corporation.
13
-
14
- Permission to use, copy, modify, and/or distribute this software for any
15
- purpose with or without fee is hereby granted.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
18
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
20
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
21
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23
- PERFORMANCE OF THIS SOFTWARE.
24
- ***************************************************************************** */
25
-
26
- function __awaiter(thisArg, _arguments, P, generator) {
27
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
- return new (P || (P = Promise))(function (resolve, reject) {
29
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
- step((generator = generator.apply(thisArg, _arguments || [])).next());
33
- });
34
- }
35
-
36
- function __generator(thisArg, body) {
37
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
38
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
39
- function verb(n) { return function (v) { return step([n, v]); }; }
40
- function step(op) {
41
- if (f) throw new TypeError("Generator is already executing.");
42
- while (_) try {
43
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
44
- if (y = 0, t) op = [op[0] & 2, t.value];
45
- switch (op[0]) {
46
- case 0: case 1: t = op; break;
47
- case 4: _.label++; return { value: op[1], done: false };
48
- case 5: _.label++; y = op[1]; op = [0]; continue;
49
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
50
- default:
51
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
52
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
53
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
54
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
55
- if (t[2]) _.ops.pop();
56
- _.trys.pop(); continue;
57
- }
58
- op = body.call(thisArg, _);
59
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
60
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
61
- }
62
- }
63
-
64
- function __spreadArray(to, from, pack) {
65
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
66
- if (ar || !(i in from)) {
67
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
68
- ar[i] = from[i];
69
- }
70
- }
71
- return to.concat(ar || Array.prototype.slice.call(from));
72
- }
73
-
74
- var transformTableHeaders$1 = function (config, groupConfigs) {
75
- return flatten(groupConfigs.map(function (groupConfig) {
76
- return groupConfig.columnOrder.map(function (columnId) {
77
- var _a;
78
- var columnConfig = config.columns[columnId];
79
- return {
80
- type: "string",
81
- value: (_a = columnConfig.columnLabel) !== null && _a !== void 0 ? _a : formatColumnIdToHeaderCellLabel(String(columnId)),
82
- };
83
- });
84
- }));
85
- };
86
- var transformGroupHeaders$1 = function (groupConfigs) {
87
- return flatten(groupConfigs.map(function (groupConfig) {
88
- return groupConfig.columnOrder.map(function (_, index) {
89
- var _a;
90
- return {
91
- type: "string",
92
- value: index === 0 ? (_a = groupConfig.label) !== null && _a !== void 0 ? _a : "" : "",
93
- };
94
- });
95
- }));
1
+ (function(){ try {var elementStyle = document.createElement('style'); elementStyle.appendChild(document.createTextNode("")); document.head.appendChild(elementStyle);} catch(e) {console.error('vite-plugin-css-injected-by-js', e);} })();import { useCallback, useState } from "react";
2
+ import zipcelx from "zipcelx";
3
+ import { formatColumnIdToHeaderCellLabel, createGroupConfigAndIdsForRows } from "@stenajs-webui/grid";
4
+ import { flatten } from "lodash";
5
+ import { format } from "date-fns";
6
+ import { FlatButton } from "@stenajs-webui/elements";
7
+ import { faFileDownload } from "@fortawesome/free-solid-svg-icons/faFileDownload";
8
+ import { jsx } from "react/jsx-runtime";
9
+ import * as clipboard from "clipboard-polyfill";
10
+ const transformTableHeaders$1 = (config, groupConfigs) => {
11
+ return flatten(groupConfigs.map((groupConfig) => groupConfig.columnOrder.map((columnId) => {
12
+ var _a;
13
+ const columnConfig = config.columns[columnId];
14
+ return {
15
+ type: "string",
16
+ value: (_a = columnConfig.columnLabel) != null ? _a : formatColumnIdToHeaderCellLabel(String(columnId))
17
+ };
18
+ })));
19
+ };
20
+ const transformGroupHeaders$1 = (groupConfigs) => {
21
+ return flatten(groupConfigs.map((groupConfig) => groupConfig.columnOrder.map((_, index) => {
22
+ var _a;
23
+ return {
24
+ type: "string",
25
+ value: index === 0 ? (_a = groupConfig.label) != null ? _a : "" : ""
26
+ };
27
+ })));
28
+ };
29
+ const transformItemToCell$1 = (item, itemValueResolver, itemLabelFormatter, formatter) => {
30
+ if (formatter) {
31
+ return createCell$1(formatter(item));
32
+ }
33
+ const value = itemValueResolver(item);
34
+ if (itemLabelFormatter) {
35
+ const label = itemLabelFormatter == null ? void 0 : itemLabelFormatter(value, item);
36
+ return createCell$1(label);
37
+ }
38
+ if (typeof value === "number" || typeof value === "string") {
39
+ return createCell$1(value);
40
+ }
41
+ if (typeof value === "boolean") {
42
+ return createCell$1(value ? "Y" : "");
43
+ }
44
+ if (value instanceof Date) {
45
+ return createCell$1(format(value, "yyyy-MM-dd HH:mm"));
46
+ }
47
+ if (value == null) {
48
+ return createCell$1("");
49
+ }
50
+ return createCell$1(String(value));
51
+ };
52
+ const createCell$1 = (value) => {
53
+ const type = typeof value === "number" ? "number" : "string";
54
+ return {
55
+ type,
56
+ value
57
+ };
58
+ };
59
+ const transformTableRow$1 = (item, config, groupConfigs, formatters) => {
60
+ return flatten(groupConfigs.map((groupConfig) => groupConfig.columnOrder.map((columnId) => transformCell$1(item, columnId, config, formatters))));
61
+ };
62
+ const transformCell$1 = (item, columnId, config, formatters) => {
63
+ const columnConfig = config.columns[columnId];
64
+ const formatter = formatters == null ? void 0 : formatters[columnId];
65
+ return transformItemToCell$1(item, columnConfig.itemValueResolver, columnConfig.itemLabelFormatter, formatter);
66
+ };
67
+ const createZipcelxConfig = (filename, config, items, formatters) => {
68
+ const groupConfigsAndIds = createGroupConfigAndIdsForRows("columnGroups" in config ? config.columnGroups : void 0, "columnGroupOrder" in config ? config.columnGroupOrder : void 0, "columnOrder" in config ? config.columnOrder : void 0);
69
+ const headerRows = [];
70
+ const groupConfigs = groupConfigsAndIds.map((p) => p.groupConfig);
71
+ if ("columnGroups" in config) {
72
+ headerRows.push(transformGroupHeaders$1(groupConfigs));
73
+ }
74
+ headerRows.push(transformTableHeaders$1(config, groupConfigs));
75
+ return {
76
+ filename,
77
+ sheet: {
78
+ data: [
79
+ ...headerRows,
80
+ ...items.map((item) => transformTableRow$1(item, config, groupConfigs, formatters))
81
+ ]
82
+ }
83
+ };
84
+ };
85
+ const downloadExcelForStandardTable = async (filename, config, items, formatters) => {
86
+ const excelConfig = createZipcelxConfig(filename, config, items, formatters);
87
+ await zipcelx(excelConfig);
96
88
  };
97
-
98
- var transformItemToCell$1 = function (item, itemValueResolver, itemLabelFormatter, formatter) {
99
- if (formatter) {
100
- return createCell$1(formatter(item));
101
- }
102
- var value = itemValueResolver(item);
103
- if (itemLabelFormatter) {
104
- var label = itemLabelFormatter === null || itemLabelFormatter === void 0 ? void 0 : itemLabelFormatter(value, item);
105
- return createCell$1(label);
106
- }
107
- if (typeof value === "number" || typeof value === "string") {
108
- return createCell$1(value);
109
- }
110
- if (typeof value === "boolean") {
111
- return createCell$1(value ? "Y" : "");
112
- }
113
- if (value instanceof Date) {
114
- return createCell$1(format(value, "yyyy-MM-dd HH:mm"));
115
- }
116
- if (value == null) {
117
- return createCell$1("");
118
- }
119
- return createCell$1(String(value));
120
- };
121
- var createCell$1 = function (value) {
122
- var type = typeof value === "number" ? "number" : "string";
123
- return {
124
- type: type,
125
- value: value,
126
- };
89
+ const StandardTableExcelExportButton = function StandardTableExcelExportButton2({
90
+ config,
91
+ size,
92
+ items,
93
+ filename = "exported-spreadsheet",
94
+ formatters
95
+ }) {
96
+ const onClickExportExcel = useCallback(async () => {
97
+ if (items && items.length) {
98
+ await downloadExcelForStandardTable(filename, config, items, formatters);
99
+ }
100
+ }, [config, items, filename, formatters]);
101
+ return /* @__PURE__ */ jsx(FlatButton, {
102
+ size,
103
+ leftIcon: faFileDownload,
104
+ onClick: onClickExportExcel,
105
+ disabled: !items || !items.length
106
+ });
127
107
  };
128
-
129
- var transformTableRow$1 = function (item, config, groupConfigs, formatters) {
130
- return flatten(groupConfigs.map(function (groupConfig) {
131
- return groupConfig.columnOrder.map(function (columnId) {
132
- return transformCell$1(item, columnId, config, formatters);
133
- });
134
- }));
135
- };
136
- var transformCell$1 = function (item, columnId, config, formatters) {
137
- var columnConfig = config.columns[columnId];
138
- var formatter = formatters === null || formatters === void 0 ? void 0 : formatters[columnId];
139
- return transformItemToCell$1(item, columnConfig.itemValueResolver, columnConfig.itemLabelFormatter, formatter);
108
+ const transformJustifyContentToTextAlign = (justifyContent) => {
109
+ switch (justifyContent == null ? void 0 : justifyContent.toLowerCase()) {
110
+ case "left":
111
+ case "start":
112
+ case "flex-start":
113
+ return "text-align: left";
114
+ case "right":
115
+ case "end":
116
+ case "flex-end":
117
+ return "text-align: right";
118
+ case "center":
119
+ return "text-align: center";
120
+ default:
121
+ return void 0;
122
+ }
140
123
  };
141
-
142
- var createZipcelxConfig = function (filename, config, items, formatters) {
143
- var groupConfigsAndIds = createGroupConfigAndIdsForRows("columnGroups" in config ? config.columnGroups : undefined, "columnGroupOrder" in config ? config.columnGroupOrder : undefined, "columnOrder" in config ? config.columnOrder : undefined);
144
- var headerRows = [];
145
- var groupConfigs = groupConfigsAndIds.map(function (p) { return p.groupConfig; });
146
- if ("columnGroups" in config) {
147
- headerRows.push(transformGroupHeaders$1(groupConfigs));
148
- }
149
- headerRows.push(transformTableHeaders$1(config, groupConfigs));
150
- return {
151
- filename: filename,
152
- sheet: {
153
- data: __spreadArray(__spreadArray([], headerRows, true), items.map(function (item) {
154
- return transformTableRow$1(item, config, groupConfigs, formatters);
155
- }), true),
156
- },
157
- };
124
+ const transformTableHeaders = (config, groupConfigs) => {
125
+ return flatten(groupConfigs.map((groupConfig) => groupConfig.columnOrder.map((columnId) => {
126
+ var _a, _b;
127
+ const columnConfig = config.columns[columnId];
128
+ if (columnConfig.justifyContentHeader) {
129
+ const styleProperty = transformJustifyContentToTextAlign(columnConfig.justifyContentHeader);
130
+ return `<th${styleProperty ? ' style="' + styleProperty + '"' : ""}>${(_a = columnConfig.columnLabel) != null ? _a : formatColumnIdToHeaderCellLabel(String(columnId))}</th>`;
131
+ }
132
+ return `<th>${(_b = columnConfig.columnLabel) != null ? _b : formatColumnIdToHeaderCellLabel(String(columnId))}</th>`;
133
+ })));
158
134
  };
159
-
160
- var downloadExcelForStandardTable = function (filename, config, items, formatters) { return __awaiter(void 0, void 0, void 0, function () {
161
- var excelConfig;
162
- return __generator(this, function (_a) {
163
- switch (_a.label) {
164
- case 0:
165
- excelConfig = createZipcelxConfig(filename, config, items, formatters);
166
- return [4 /*yield*/, zipcelx(excelConfig)];
167
- case 1:
168
- _a.sent();
169
- return [2 /*return*/];
170
- }
171
- });
172
- }); };
173
-
174
- var StandardTableExcelExportButton = function StandardTableExcelExportButton(_a) {
175
- var _this = this;
176
- var config = _a.config, size = _a.size, items = _a.items, _b = _a.filename, filename = _b === void 0 ? "exported-spreadsheet" : _b, formatters = _a.formatters;
177
- var onClickExportExcel = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
178
- return __generator(this, function (_a) {
179
- switch (_a.label) {
180
- case 0:
181
- if (!(items && items.length)) return [3 /*break*/, 2];
182
- return [4 /*yield*/, downloadExcelForStandardTable(filename, config, items, formatters)];
183
- case 1:
184
- _a.sent();
185
- _a.label = 2;
186
- case 2: return [2 /*return*/];
187
- }
188
- });
189
- }); }, [config, items, filename, formatters]);
190
- return (React.createElement(FlatButton, { size: size, leftIcon: faFileDownload, onClick: onClickExportExcel, disabled: !items || !items.length }));
135
+ const transformGroupHeaders = (groupConfigs) => {
136
+ return flatten(groupConfigs.map((groupConfig) => {
137
+ var _a;
138
+ return `<th style="text-align: left" colspan="${groupConfig.columnOrder.length}">${(_a = groupConfig.label) != null ? _a : ""}</th>`;
139
+ }));
191
140
  };
192
-
193
- var transformJustifyContentToTextAlign = function (justifyContent) {
194
- switch (justifyContent === null || justifyContent === void 0 ? void 0 : justifyContent.toLowerCase()) {
195
- case "left":
196
- case "start":
197
- case "flex-start":
198
- return "text-align: left";
199
- case "right":
200
- case "end":
201
- case "flex-end":
202
- return "text-align: right";
203
- case "center":
204
- return "text-align: center";
205
- default:
206
- return undefined;
207
- }
141
+ const transformItemToCell = (item, itemValueResolver, justifyContentCell, itemLabelFormatter, formatter) => {
142
+ if (formatter) {
143
+ return createCell(formatter(item), justifyContentCell);
144
+ }
145
+ const value = itemValueResolver(item);
146
+ if (itemLabelFormatter) {
147
+ const label = itemLabelFormatter == null ? void 0 : itemLabelFormatter(value, item);
148
+ return createCell(label, justifyContentCell);
149
+ }
150
+ if (typeof value === "number" || typeof value === "string") {
151
+ return createCell(value, justifyContentCell);
152
+ }
153
+ if (typeof value === "boolean") {
154
+ return createCell(value ? "Y" : "", justifyContentCell);
155
+ }
156
+ if (value instanceof Date) {
157
+ return createCell(format(value, "yyyy-MM-dd HH:mm"), justifyContentCell);
158
+ }
159
+ if (value == null) {
160
+ return createCell("", justifyContentCell);
161
+ }
162
+ return createCell(String(value), justifyContentCell);
208
163
  };
209
-
210
- var transformTableHeaders = function (config, groupConfigs) {
211
- return flatten(groupConfigs.map(function (groupConfig) {
212
- return groupConfig.columnOrder.map(function (columnId) {
213
- var _a, _b;
214
- var columnConfig = config.columns[columnId];
215
- if (columnConfig.justifyContentHeader) {
216
- var styleProperty = transformJustifyContentToTextAlign(columnConfig.justifyContentHeader);
217
- return "<th".concat(styleProperty ? ' style="' + styleProperty + '"' : "", ">").concat((_a = columnConfig.columnLabel) !== null && _a !== void 0 ? _a : formatColumnIdToHeaderCellLabel(String(columnId)), "</th>");
218
- }
219
- return "<th>".concat((_b = columnConfig.columnLabel) !== null && _b !== void 0 ? _b : formatColumnIdToHeaderCellLabel(String(columnId)), "</th>");
220
- });
221
- }));
222
- };
223
- var transformGroupHeaders = function (groupConfigs) {
224
- return flatten(groupConfigs.map(function (groupConfig) {
225
- var _a;
226
- return "<th style=\"text-align: left\" colspan=\"".concat(groupConfig.columnOrder.length, "\">").concat((_a = groupConfig.label) !== null && _a !== void 0 ? _a : "", "</th>");
227
- }));
164
+ const createCell = (value, justifyContentCell) => {
165
+ if (justifyContentCell) {
166
+ const styleProperty = transformJustifyContentToTextAlign(justifyContentCell);
167
+ return `<td${styleProperty ? ' style="' + styleProperty + '"' : ""}>${value}</td>`;
168
+ }
169
+ return `<td>${value}</td>`;
228
170
  };
229
-
230
- var transformItemToCell = function (item, itemValueResolver, justifyContentCell, itemLabelFormatter, formatter) {
231
- if (formatter) {
232
- return createCell(formatter(item), justifyContentCell);
233
- }
234
- var value = itemValueResolver(item);
235
- if (itemLabelFormatter) {
236
- var label = itemLabelFormatter === null || itemLabelFormatter === void 0 ? void 0 : itemLabelFormatter(value, item);
237
- return createCell(label, justifyContentCell);
238
- }
239
- if (typeof value === "number" || typeof value === "string") {
240
- return createCell(value, justifyContentCell);
241
- }
242
- if (typeof value === "boolean") {
243
- return createCell(value ? "Y" : "", justifyContentCell);
244
- }
245
- if (value instanceof Date) {
246
- return createCell(format(value, "yyyy-MM-dd HH:mm"), justifyContentCell);
247
- }
248
- if (value == null) {
249
- return createCell("", justifyContentCell);
250
- }
251
- return createCell(String(value), justifyContentCell);
252
- };
253
- var createCell = function (value, justifyContentCell) {
254
- if (justifyContentCell) {
255
- var styleProperty = transformJustifyContentToTextAlign(justifyContentCell);
256
- return "<td".concat(styleProperty ? ' style="' + styleProperty + '"' : "", ">").concat(value, "</td>");
257
- }
258
- return "<td>".concat(value, "</td>");
171
+ const transformTableRow = (item, config, groupConfigs, formatters) => {
172
+ return flatten(groupConfigs.map((groupConfig) => groupConfig.columnOrder.map((columnId) => transformCell(item, columnId, config, formatters)))).join("");
259
173
  };
260
-
261
- var transformTableRow = function (item, config, groupConfigs, formatters) {
262
- return flatten(groupConfigs.map(function (groupConfig) {
263
- return groupConfig.columnOrder.map(function (columnId) {
264
- return transformCell(item, columnId, config, formatters);
265
- });
266
- })).join("");
267
- };
268
- var transformCell = function (item, columnId, config, formatters) {
269
- var columnConfig = config.columns[columnId];
270
- var formatter = formatters === null || formatters === void 0 ? void 0 : formatters[columnId];
271
- return transformItemToCell(item, columnConfig.itemValueResolver, columnConfig.justifyContentCell, columnConfig.itemLabelFormatter, formatter);
174
+ const transformCell = (item, columnId, config, formatters) => {
175
+ const columnConfig = config.columns[columnId];
176
+ const formatter = formatters == null ? void 0 : formatters[columnId];
177
+ return transformItemToCell(item, columnConfig.itemValueResolver, columnConfig.justifyContentCell, columnConfig.itemLabelFormatter, formatter);
272
178
  };
273
-
274
- var createHtmlConfig = function (config, items, formatters) {
275
- var groupConfigsAndIds = createGroupConfigAndIdsForRows("columnGroups" in config ? config.columnGroups : undefined, "columnGroupOrder" in config ? config.columnGroupOrder : undefined, "columnOrder" in config ? config.columnOrder : undefined);
276
- var headerRows = [];
277
- var groupConfigs = groupConfigsAndIds.map(function (p) { return p.groupConfig; });
278
- if ("columnGroups" in config) {
279
- headerRows.push(transformGroupHeaders(groupConfigs).join(""));
280
- }
281
- headerRows.push(transformTableHeaders(config, groupConfigs).join(""));
282
- var header = "<thead>".concat(headerRows
283
- .map(function (headerRow) { return "<tr>".concat(headerRow, "</tr>"); })
284
- .join(""), "</thead>");
285
- var tbodyRows = items
286
- .map(function (item) { return transformTableRow(item, config, groupConfigs, formatters); })
287
- .map(function (row) { return "<tr>".concat(row, "</tr>"); });
288
- var body = "<tbody>".concat(tbodyRows.join(""), "</tbody>");
289
- return "<table>".concat(header).concat(body, "</table>");
179
+ const createHtmlConfig = (config, items, formatters) => {
180
+ const groupConfigsAndIds = createGroupConfigAndIdsForRows("columnGroups" in config ? config.columnGroups : void 0, "columnGroupOrder" in config ? config.columnGroupOrder : void 0, "columnOrder" in config ? config.columnOrder : void 0);
181
+ const headerRows = [];
182
+ const groupConfigs = groupConfigsAndIds.map((p) => p.groupConfig);
183
+ if ("columnGroups" in config) {
184
+ headerRows.push(transformGroupHeaders(groupConfigs).join(""));
185
+ }
186
+ headerRows.push(transformTableHeaders(config, groupConfigs).join(""));
187
+ const header = `<thead>${headerRows.map((headerRow) => `<tr>${headerRow}</tr>`).join("")}</thead>`;
188
+ const tbodyRows = items.map((item) => transformTableRow(item, config, groupConfigs, formatters)).map((row) => `<tr>${row}</tr>`);
189
+ const body = `<tbody>${tbodyRows.join("")}</tbody>`;
190
+ return `<table>${header}${body}</table>`;
290
191
  };
291
-
292
- var renderHtmlForStandardTable = function (config, items, formatters) {
293
- return createHtmlConfig(config, items, formatters);
192
+ const renderHtmlForStandardTable = (config, items, formatters) => {
193
+ return createHtmlConfig(config, items, formatters);
294
194
  };
295
-
296
- function copyContentToClipboard(items, config, formatters, renderContent) {
297
- return __awaiter(this, void 0, void 0, function () {
298
- var htmlToCopy, item;
299
- return __generator(this, function (_a) {
300
- switch (_a.label) {
301
- case 0:
302
- htmlToCopy = "";
303
- if (items && items.length) {
304
- htmlToCopy = renderHtmlForStandardTable(config, items, formatters);
305
- }
306
- if (renderContent) {
307
- htmlToCopy = renderContent(htmlToCopy);
308
- }
309
- if (!htmlToCopy) return [3 /*break*/, 2];
310
- item = new clipboard.ClipboardItem({
311
- "text/html": new Blob([htmlToCopy], { type: "text/html" }),
312
- });
313
- return [4 /*yield*/, clipboard.write([item])];
314
- case 1:
315
- _a.sent();
316
- _a.label = 2;
317
- case 2: return [2 /*return*/];
318
- }
319
- });
320
- });
195
+ async function copyContentToClipboard(items, config, formatters, renderContent) {
196
+ let htmlToCopy = "";
197
+ if (items && items.length) {
198
+ htmlToCopy = renderHtmlForStandardTable(config, items, formatters);
199
+ }
200
+ if (renderContent) {
201
+ htmlToCopy = renderContent(htmlToCopy);
202
+ }
203
+ if (htmlToCopy) {
204
+ const item = new clipboard.ClipboardItem({
205
+ "text/html": new Blob([htmlToCopy], { type: "text/html" })
206
+ });
207
+ await clipboard.write([item]);
208
+ }
321
209
  }
322
-
323
- function StandardTableHtmlCopyToClipboardButton(_a) {
324
- var _this = this;
325
- var config = _a.config, renderContent = _a.renderContent, size = _a.size, items = _a.items, formatters = _a.formatters, _b = _a.label, label = _b === void 0 ? "Copy to clipboard" : _b, _c = _a.labelAfterCopy, labelAfterCopy = _c === void 0 ? "Content copied!" : _c, _d = _a.numTimeToRevertLabel, numTimeToRevertLabel = _d === void 0 ? 2000 : _d;
326
- var _e = useState(false), contentCopied = _e[0], setContentCopied = _e[1];
327
- var onClickExportHtml = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
328
- return __generator(this, function (_a) {
329
- switch (_a.label) {
330
- case 0: return [4 /*yield*/, copyContentToClipboard(items, config, formatters, renderContent)];
331
- case 1:
332
- _a.sent();
333
- setContentCopied(true);
334
- setTimeout(function () { return setContentCopied(false); }, numTimeToRevertLabel);
335
- return [2 /*return*/];
336
- }
337
- });
338
- }); }, [config, items, formatters, numTimeToRevertLabel, renderContent]);
339
- return (React.createElement(FlatButton, { size: size, onClick: onClickExportHtml, disabled: !items || !items.length, label: contentCopied ? labelAfterCopy : label }));
210
+ function StandardTableHtmlCopyToClipboardButton({
211
+ config,
212
+ renderContent,
213
+ size,
214
+ items,
215
+ formatters,
216
+ label = "Copy to clipboard",
217
+ labelAfterCopy = "Content copied!",
218
+ numTimeToRevertLabel = 2e3
219
+ }) {
220
+ const [contentCopied, setContentCopied] = useState(false);
221
+ const onClickExportHtml = useCallback(async () => {
222
+ await copyContentToClipboard(items, config, formatters, renderContent);
223
+ setContentCopied(true);
224
+ setTimeout(() => setContentCopied(false), numTimeToRevertLabel);
225
+ }, [config, items, formatters, numTimeToRevertLabel, renderContent]);
226
+ return /* @__PURE__ */ jsx(FlatButton, {
227
+ size,
228
+ onClick: onClickExportHtml,
229
+ disabled: !items || !items.length,
230
+ label: contentCopied ? labelAfterCopy : label
231
+ });
340
232
  }
341
-
342
233
  export { StandardTableExcelExportButton, StandardTableHtmlCopyToClipboardButton, createHtmlConfig, createZipcelxConfig, downloadExcelForStandardTable };
343
234
  //# sourceMappingURL=index.es.js.map