handsontable 0.0.0-next-50e428d-20231026 → 0.0.0-next-42d5bd7-20231027
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of handsontable might be problematic. Click here for more details.
- package/3rdparty/walkontable/src/renderer/columnHeaders.js +3 -0
- package/3rdparty/walkontable/src/renderer/columnHeaders.mjs +4 -1
- package/3rdparty/walkontable/src/renderer/rowHeaders.js +3 -0
- package/3rdparty/walkontable/src/renderer/rowHeaders.mjs +4 -1
- package/base.js +2 -2
- package/base.mjs +2 -2
- package/core.js +1 -1
- package/core.mjs +1 -1
- package/dist/handsontable.css +45 -63
- package/dist/handsontable.full.css +45 -63
- package/dist/handsontable.full.js +3599 -2080
- package/dist/handsontable.full.min.css +5 -5
- package/dist/handsontable.full.min.js +70 -63
- package/dist/handsontable.js +3601 -2082
- package/dist/handsontable.min.css +5 -5
- package/dist/handsontable.min.js +25 -18
- package/dist/languages/all.js +24 -2
- package/dist/languages/all.min.js +1 -1
- package/dist/languages/en-US.js +12 -1
- package/dist/languages/en-US.min.js +1 -1
- package/dist/languages/pl-PL.js +12 -1
- package/dist/languages/pl-PL.min.js +1 -1
- package/helpers/a11y.js +2 -0
- package/helpers/a11y.mjs +1 -0
- package/helpers/dom/element.js +29 -0
- package/helpers/dom/element.mjs +28 -0
- package/helpers/mixed.js +1 -1
- package/helpers/mixed.mjs +1 -1
- package/i18n/constants.js +27 -1
- package/i18n/constants.mjs +14 -1
- package/i18n/languages/en-US.js +12 -1
- package/i18n/languages/en-US.mjs +12 -1
- package/i18n/languages/pl-PL.js +12 -1
- package/i18n/languages/pl-PL.mjs +12 -1
- package/languages/all.js +24 -2
- package/languages/en-US.js +12 -1
- package/languages/en-US.mjs +12 -1
- package/languages/index.js +24 -2
- package/languages/pl-PL.js +12 -1
- package/languages/pl-PL.mjs +12 -1
- package/package.json +1 -1
- package/pluginHooks.d.ts +28 -6
- package/pluginHooks.js +116 -62
- package/pluginHooks.mjs +116 -62
- package/plugins/collapsibleColumns/collapsibleColumns.js +3 -2
- package/plugins/collapsibleColumns/collapsibleColumns.mjs +4 -3
- package/plugins/columnSorting/columnSorting.js +29 -3
- package/plugins/columnSorting/columnSorting.mjs +31 -5
- package/plugins/contextMenu/menu/menuItemRenderer.js +12 -0
- package/plugins/contextMenu/menu/menuItemRenderer.mjs +14 -2
- package/plugins/copyPaste/clipboardData/clipboardData.js +517 -0
- package/plugins/copyPaste/clipboardData/clipboardData.mjs +512 -0
- package/plugins/copyPaste/clipboardData/copyClipboardData.js +69 -0
- package/plugins/copyPaste/clipboardData/copyClipboardData.mjs +65 -0
- package/plugins/copyPaste/clipboardData/index.js +9 -0
- package/plugins/copyPaste/clipboardData/index.mjs +4 -0
- package/plugins/copyPaste/clipboardData/pasteClipboardData.js +81 -0
- package/plugins/copyPaste/clipboardData/pasteClipboardData.mjs +77 -0
- package/plugins/copyPaste/copyPaste.js +38 -92
- package/plugins/copyPaste/copyPaste.mjs +40 -94
- package/plugins/dropdownMenu/dropdownMenu.js +2 -1
- package/plugins/dropdownMenu/dropdownMenu.mjs +3 -2
- package/plugins/filters/ui/input.js +0 -3
- package/plugins/filters/ui/input.mjs +0 -3
- package/plugins/filters/ui/select.js +6 -0
- package/plugins/filters/ui/select.mjs +6 -0
- package/plugins/hiddenColumns/hiddenColumns.js +48 -3
- package/plugins/hiddenColumns/hiddenColumns.mjs +47 -2
- package/plugins/hiddenRows/hiddenRows.js +48 -3
- package/plugins/hiddenRows/hiddenRows.mjs +47 -2
- package/plugins/multiColumnSorting/multiColumnSorting.js +21 -0
- package/plugins/multiColumnSorting/multiColumnSorting.mjs +22 -1
- package/plugins/nestedHeaders/nestedHeaders.js +21 -22
- package/plugins/nestedHeaders/nestedHeaders.mjs +21 -22
- package/plugins/nestedRows/nestedRows.js +2 -1
- package/plugins/nestedRows/nestedRows.mjs +2 -1
- package/plugins/nestedRows/ui/headers.js +3 -3
- package/plugins/nestedRows/ui/headers.mjs +4 -4
- package/utils/parseTable.js +527 -83
- package/utils/parseTable.mjs +523 -82
- package/plugins/copyPaste/clipboardData.js +0 -18
- package/plugins/copyPaste/clipboardData.mjs +0 -14
- package/plugins/copyPaste/pasteEvent.js +0 -14
- package/plugins/copyPaste/pasteEvent.mjs +0 -9
package/utils/parseTable.js
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
exports.__esModule = true;
|
4
|
-
exports.
|
4
|
+
exports.getDataByCoords = getDataByCoords;
|
5
|
+
exports.getDataWithHeadersByConfig = getDataWithHeadersByConfig;
|
6
|
+
exports.getHTMLByCoords = getHTMLByCoords;
|
7
|
+
exports.getHTMLFromConfig = getHTMLFromConfig;
|
5
8
|
exports.htmlToGridSettings = htmlToGridSettings;
|
6
9
|
exports.instanceToHTML = instanceToHTML;
|
7
10
|
require("core-js/modules/es.array.push.js");
|
11
|
+
require("core-js/modules/es.string.replace-all.js");
|
8
12
|
var _mixed = require("./../helpers/mixed");
|
13
|
+
var _object = require("./../helpers/object");
|
14
|
+
var _number = require("../helpers/number");
|
9
15
|
const ESCAPED_HTML_CHARS = {
|
10
16
|
' ': '\x20',
|
11
17
|
'&': '&',
|
@@ -24,102 +30,539 @@ function isHTMLTable(element) {
|
|
24
30
|
return (element && element.nodeName || '') === 'TABLE';
|
25
31
|
}
|
26
32
|
|
33
|
+
/**
|
34
|
+
* Parses empty values to an empty string or leave them untouched otherwise.
|
35
|
+
*
|
36
|
+
* @private
|
37
|
+
* @param {string} cellValue Parsed cell value.
|
38
|
+
* @returns {string}
|
39
|
+
*/
|
40
|
+
function parseEmptyValues(cellValue) {
|
41
|
+
if ((0, _mixed.isEmpty)(cellValue)) {
|
42
|
+
return '';
|
43
|
+
}
|
44
|
+
return cellValue;
|
45
|
+
}
|
46
|
+
|
27
47
|
/**
|
28
48
|
* Converts Handsontable into HTMLTableElement.
|
29
49
|
*
|
30
|
-
* @param {Core}
|
50
|
+
* @param {Core} hotInstance The Handsontable instance.
|
31
51
|
* @returns {string} OuterHTML of the HTMLTableElement.
|
32
52
|
*/
|
33
|
-
function instanceToHTML(
|
34
|
-
const
|
35
|
-
const
|
36
|
-
const
|
37
|
-
|
38
|
-
|
39
|
-
const
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
function instanceToHTML(hotInstance) {
|
54
|
+
const startColumn = hotInstance.hasRowHeaders() ? -1 : 0;
|
55
|
+
const startRow = hotInstance.hasColHeaders() ? -1 : 0;
|
56
|
+
const rows = Array.from({
|
57
|
+
length: hotInstance.countRows() + Math.abs(startRow)
|
58
|
+
}, (_, i) => i + startRow);
|
59
|
+
const columns = Array.from({
|
60
|
+
length: hotInstance.countCols() + Math.abs(startColumn)
|
61
|
+
}, (_, i) => i + startColumn);
|
62
|
+
return getHTMLByCoords(hotInstance, {
|
63
|
+
rows,
|
64
|
+
columns
|
65
|
+
});
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Converts Handsontable's coordinates into HTMLTableElement.
|
70
|
+
*
|
71
|
+
* @param {Core} hotInstance The Handsontable instance.
|
72
|
+
* @param {object} config Configuration for building HTMLTableElement.
|
73
|
+
* @param {Array<number>} config.rows List of row indexes which should be taken into account when creating the table.
|
74
|
+
* @param {Array<number>} config.columns List of column indexes which should be taken into account when creating the table.
|
75
|
+
* @returns {string} OuterHTML of the HTMLTableElement.
|
76
|
+
*/
|
77
|
+
function getHTMLByCoords(hotInstance, config) {
|
78
|
+
return ['<table>', ...getHeadersHTMLByCoords(hotInstance, config), ...getBodyHTMLByCoords(hotInstance, config), '</table>'].join('');
|
79
|
+
}
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Converts Handsontable's coordinates into list of cell values.
|
83
|
+
*
|
84
|
+
* @param {Core} hotInstance The Handsontable instance.
|
85
|
+
* @param {object} config Configuration for building the cell value list.
|
86
|
+
* @param {Array<number>} config.rows List of row indexes which should be taken into account when creating the
|
87
|
+
* cell value list.
|
88
|
+
* @param {Array<number>} config.columns List of column indexes which should be taken into account when creating the
|
89
|
+
* cell value list.
|
90
|
+
* @returns {Array<Array<string>>} List of displayed cell values.
|
91
|
+
*/
|
92
|
+
function getDataByCoords(hotInstance, config) {
|
93
|
+
return [...getHeadersDataByCoords(hotInstance, config), ...getBodyDataByCoords(hotInstance, config)];
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Converts config into HTMLTableElement.
|
98
|
+
*
|
99
|
+
* @param {object} config Configuration for building HTMLTableElement.
|
100
|
+
* @param {Array<number>} [config.excludedRows] List of row indexes which should be excluded when creating the table.
|
101
|
+
* @param {Array<number>} [config.excludedColumns] List of column indexes which should be excluded when creating the table.
|
102
|
+
* @param {Array<Array<string>>} [config.data] List of cell data.
|
103
|
+
* @param {Array<object>} [config.mergeCells] List of merged cells.
|
104
|
+
* @param {Array<Array<string|object>>} [config.nestedHeaders] List of headers and corresponding information about some
|
105
|
+
* nested elements.
|
106
|
+
* @param {Array<string>} [config.colHeaders] List of first level header values.
|
107
|
+
* @returns {string} OuterHTML of the HTMLTableElement.
|
108
|
+
*/
|
109
|
+
function getHTMLFromConfig(config) {
|
110
|
+
return ['<table>', ...getHeadersHTMLByConfig(config), ...getBodyHTMLByConfig(config), '</table>'].join('');
|
111
|
+
}
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Get list of filtered nested headers.
|
115
|
+
*
|
116
|
+
* @param {Array<Array<string|object>>} nestedHeaders List of nested headers which will be filtered.
|
117
|
+
* @param {Array<number>} excludedHeaders List of headers which should be excluded when creating the HTMLTableElement.tHead.
|
118
|
+
* @param {Array<number>} excludedColumns List of column indexes which should be excluded when creating the HTMLTableElement.tHead.
|
119
|
+
* @returns {*}
|
120
|
+
*/
|
121
|
+
function getFilteredNestedHeaders(nestedHeaders, excludedHeaders, excludedColumns) {
|
122
|
+
return nestedHeaders.reduce((listOfHeaders, headerValues, rowIndex) => {
|
123
|
+
if (excludedHeaders.includes(rowIndex - nestedHeaders.length)) {
|
124
|
+
return listOfHeaders;
|
125
|
+
}
|
126
|
+
const filteredNestedHeader = headerValues.filter((columnData, columnIndex) => excludedColumns.includes(columnIndex) === false);
|
127
|
+
if (filteredNestedHeader.length > 0) {
|
128
|
+
return listOfHeaders.concat([filteredNestedHeader]);
|
129
|
+
}
|
130
|
+
return listOfHeaders;
|
131
|
+
}, []);
|
132
|
+
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* Get HTML for nested headers.
|
136
|
+
*
|
137
|
+
* @param {Array<Array<string|object>>} nestedHeaders List of nested headers which will be filtered.
|
138
|
+
* @param {Array<number>} excludedHeaders List of headers which should be excluded when creating the HTMLTableElement.tHead.
|
139
|
+
* @param {Array<number>} excludedColumns List of column indexes which should be excluded when creating the HTMLTableElement.tHead.
|
140
|
+
* @returns {Array<string>}
|
141
|
+
*/
|
142
|
+
function getNestedHeadersHTML(nestedHeaders, excludedHeaders, excludedColumns) {
|
143
|
+
const headersHTML = [];
|
144
|
+
getFilteredNestedHeaders(nestedHeaders, excludedHeaders, excludedColumns).forEach(listOfHeaders => {
|
145
|
+
const rowHTML = ['<tr>'];
|
146
|
+
for (let i = 0; i < listOfHeaders.length; i += 1) {
|
147
|
+
const header = listOfHeaders[i];
|
148
|
+
let headerValue = header;
|
149
|
+
let colspanAttribute = '';
|
150
|
+
if ((0, _object.isObject)(header)) {
|
151
|
+
const {
|
152
|
+
colspan,
|
153
|
+
label
|
154
|
+
} = header;
|
155
|
+
headerValue = label;
|
156
|
+
colspanAttribute = ` colspan=${colspan}`;
|
157
|
+
}
|
158
|
+
rowHTML.push(`<th${colspanAttribute}>${encodeHTMLEntities(parseEmptyValues(headerValue))}</th>`);
|
159
|
+
}
|
160
|
+
rowHTML.push('</tr>');
|
161
|
+
headersHTML.push(...rowHTML);
|
162
|
+
});
|
163
|
+
return headersHTML;
|
164
|
+
}
|
165
|
+
|
166
|
+
/**
|
167
|
+
* Get HTML for first level header.
|
168
|
+
*
|
169
|
+
* @param {Array<string>} columnHeaders List of header values which will be filtered.
|
170
|
+
* @param {Array<number>} excludedHeaders List of headers which should be excluded when creating the HTMLTableElement.tHead.
|
171
|
+
* @param {Array<number>} excludedColumns List of column indexes which should be excluded when creating the HTMLTableElement.tHead.
|
172
|
+
* @returns {*[]}
|
173
|
+
*/
|
174
|
+
function getSimpleHeadersHTML(columnHeaders, excludedHeaders, excludedColumns) {
|
175
|
+
if (excludedHeaders.includes(-1)) {
|
176
|
+
return [];
|
177
|
+
}
|
178
|
+
const filteredColumnHeaders = columnHeaders.filter((columnHeaderValue, columnIndex) => excludedColumns.includes(columnIndex) === false);
|
179
|
+
if (filteredColumnHeaders.length === 0) {
|
180
|
+
return [];
|
181
|
+
}
|
182
|
+
return ['<tr>', ...filteredColumnHeaders.map(columnHeader => `<th>${encodeHTMLEntities(parseEmptyValues(columnHeader))}</th>`), '</tr>'];
|
183
|
+
}
|
184
|
+
|
185
|
+
/**
|
186
|
+
* Get list of cells filtered by list of excluded rows and columns.
|
187
|
+
*
|
188
|
+
* @private
|
189
|
+
* @param {Array<Array<string>>} data List of cells values which will be filtered.
|
190
|
+
* @param {Array<number>} excludedRows List of row indexes which should be excluded when creating the HTMLTableElement.tHead.
|
191
|
+
* @param {Array<number>} excludedColumns List of column indexes which should be excluded when creating the HTMLTableElement.tHead.
|
192
|
+
* @returns {Array<string>} List of cell values.
|
193
|
+
*/
|
194
|
+
function getFilteredCells(data, excludedRows, excludedColumns) {
|
195
|
+
if (Array.isArray(data) === false) {
|
196
|
+
return [];
|
197
|
+
}
|
198
|
+
return data.reduce((listOfCells, rowData, rowIndex) => {
|
199
|
+
if (excludedRows.includes(rowIndex)) {
|
200
|
+
return listOfCells;
|
201
|
+
}
|
202
|
+
const filteredRowData = rowData.filter((cellData, columnIndex) => excludedColumns.includes(columnIndex) === false);
|
203
|
+
if (filteredRowData.length > 0) {
|
204
|
+
return listOfCells.concat([filteredRowData]);
|
205
|
+
}
|
206
|
+
return listOfCells;
|
207
|
+
}, []);
|
208
|
+
}
|
209
|
+
|
210
|
+
/**
|
211
|
+
* Prepare information about merged areas to reduce complexity of calculations.
|
212
|
+
*
|
213
|
+
* @private
|
214
|
+
* @param {Array<object>} mergedCellsConfig List of merged cells.
|
215
|
+
* @returns {{mergedCellsMap: Map<any, any>, mergedArea: Set<any>}}
|
216
|
+
*/
|
217
|
+
function getMergedCellsInformation(mergedCellsConfig) {
|
218
|
+
const mergedCellsMap = new Map();
|
219
|
+
const mergedArea = new Set();
|
220
|
+
let mergedRows = 1;
|
221
|
+
let mergedColumns = 1;
|
222
|
+
mergedCellsConfig === null || mergedCellsConfig === void 0 || mergedCellsConfig.forEach(mergeArea => {
|
223
|
+
const {
|
224
|
+
row,
|
225
|
+
col,
|
226
|
+
rowspan,
|
227
|
+
colspan
|
228
|
+
} = mergeArea;
|
229
|
+
mergedCellsMap.set(`${row}x${col}`, {
|
230
|
+
rowspan,
|
231
|
+
colspan
|
232
|
+
});
|
233
|
+
if (Number.isInteger(rowspan)) {
|
234
|
+
mergedRows = rowspan;
|
235
|
+
}
|
236
|
+
if (Number.isInteger(colspan)) {
|
237
|
+
mergedColumns = colspan;
|
238
|
+
}
|
239
|
+
(0, _number.rangeEach)(row, row + mergedRows - 1, rowIndex => {
|
240
|
+
(0, _number.rangeEach)(col, col + mergedColumns - 1, columnIndex => {
|
241
|
+
// Other than start point.
|
242
|
+
if (rowIndex !== row || columnIndex !== col) {
|
243
|
+
mergedArea.add(`${rowIndex}x${columnIndex}`);
|
244
|
+
}
|
245
|
+
});
|
246
|
+
});
|
247
|
+
});
|
248
|
+
return {
|
249
|
+
mergedCellsMap,
|
250
|
+
mergedArea
|
251
|
+
};
|
252
|
+
}
|
253
|
+
|
254
|
+
/**
|
255
|
+
* Converts config with information about cells into HTMLTableElement.tBodies.
|
256
|
+
*
|
257
|
+
* @private
|
258
|
+
* @param {object} config Configuration for building HTMLTableElement.tBodies.
|
259
|
+
* @param {Array<Array<string>>} config.data List of cell data.
|
260
|
+
* @param {Array<number>} [config.excludedRows] List of row indexes which should be excluded when creating the HTMLTableElement.tBodies.
|
261
|
+
* @param {Array<number>} [config.excludedColumns] List of column indexes which should be excluded when creating the HTMLTableElement.tBodies.
|
262
|
+
* @param {Array<object>} [config.mergeCells] List of merged cells.
|
263
|
+
* @returns {Array<string>} List of HTMLElements stored as strings.
|
264
|
+
*/
|
265
|
+
function getBodyHTMLByConfig(config) {
|
266
|
+
const excludedColumns = config.excludedColumns || [];
|
267
|
+
const excludedRows = config.excludedRows || [];
|
268
|
+
const {
|
269
|
+
data,
|
270
|
+
mergeCells
|
271
|
+
} = config;
|
272
|
+
const ignoredCellRows = excludedRows.filter(rowIndex => rowIndex >= 0);
|
273
|
+
const filteredData = getFilteredCells(data, ignoredCellRows, excludedColumns);
|
274
|
+
const cells = [];
|
275
|
+
if (filteredData.length === 0) {
|
276
|
+
return [];
|
277
|
+
}
|
278
|
+
const {
|
279
|
+
mergedCellsMap,
|
280
|
+
mergedArea
|
281
|
+
} = getMergedCellsInformation(mergeCells);
|
282
|
+
filteredData.forEach((rowData, rowIndex) => {
|
283
|
+
const rowHTML = ['<tr>'];
|
284
|
+
rowData.forEach((cellData, columnIndex) => {
|
285
|
+
const attrs = [];
|
286
|
+
const checkedMergeCoordinate = `${rowIndex}x${columnIndex}`;
|
287
|
+
const mergeParent = mergedCellsMap.get(checkedMergeCoordinate);
|
288
|
+
if (mergeParent !== undefined) {
|
57
289
|
const {
|
58
|
-
hidden,
|
59
290
|
rowspan,
|
60
291
|
colspan
|
61
|
-
} =
|
62
|
-
if (
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
}
|
67
|
-
if (colspan) {
|
68
|
-
attrs.push(`colspan="${colspan}"`);
|
69
|
-
}
|
70
|
-
if ((0, _mixed.isEmpty)(cellData)) {
|
71
|
-
cell = `<td ${attrs.join(' ')}></td>`;
|
72
|
-
} else {
|
73
|
-
const value = cellData.toString().replace('<', '<').replace('>', '>').replace(/(<br(\s*|\/)>(\r\n|\n)?|\r\n|\n)/g, '<br>\r\n').replace(/\x20/gi, ' ').replace(/\t/gi, '	');
|
74
|
-
cell = `<td ${attrs.join(' ')}>${value}</td>`;
|
75
|
-
}
|
292
|
+
} = mergeParent;
|
293
|
+
if (Number.isInteger(rowspan) && rowspan > 1) {
|
294
|
+
attrs.push(` rowspan="${rowspan}"`);
|
295
|
+
}
|
296
|
+
if (Number.isInteger(colspan) && colspan > 1) {
|
297
|
+
attrs.push(` colspan="${colspan}"`);
|
76
298
|
}
|
299
|
+
} else if (mergedArea.has(checkedMergeCoordinate)) {
|
300
|
+
return;
|
77
301
|
}
|
78
|
-
|
79
|
-
}
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
302
|
+
rowHTML.push(`<td${attrs.join('')}>${encodeHTMLEntities(parseEmptyValues(cellData))}</td>`);
|
303
|
+
});
|
304
|
+
rowHTML.push('</tr>');
|
305
|
+
cells.push(...rowHTML);
|
306
|
+
});
|
307
|
+
return ['<tbody>', ...cells, '</tbody>'];
|
308
|
+
}
|
309
|
+
|
310
|
+
/**
|
311
|
+
* Converts config with information about headers into HTMLTableElement.tHead.
|
312
|
+
*
|
313
|
+
* @private
|
314
|
+
* @param {object} config Configuration for building HTMLTableElement.tHead.
|
315
|
+
* @param {Array<Array<string|object>>} [config.nestedHeaders] List of headers and corresponding information about some
|
316
|
+
* nested elements.
|
317
|
+
* @param {Array<string>} [config.colHeaders] List of first level header values.
|
318
|
+
* @param {Array<number>} [config.excludedRows] List of row indexes which should be excluded when creating the HTMLTableElement.tHead.
|
319
|
+
* @param {Array<number>} [config.excludedColumns] List of column indexes which should be excluded when creating the HTMLTableElement.tHead.
|
320
|
+
* @returns {Array<string>} List of HTMLElements stored as strings.
|
321
|
+
*/
|
322
|
+
function getHeadersHTMLByConfig(config) {
|
323
|
+
const headersHTML = [];
|
324
|
+
const excludedColumns = Array.isArray(config === null || config === void 0 ? void 0 : config.excludedColumns) ? config.excludedColumns : [];
|
325
|
+
const excludedRows = Array.isArray(config === null || config === void 0 ? void 0 : config.excludedRows) ? config.excludedRows : [];
|
326
|
+
const {
|
327
|
+
nestedHeaders,
|
328
|
+
colHeaders
|
329
|
+
} = config;
|
330
|
+
const excludedHeaders = excludedRows.filter(rowIndex => rowIndex < 0);
|
331
|
+
if (Array.isArray(nestedHeaders)) {
|
332
|
+
headersHTML.push(...getNestedHeadersHTML(nestedHeaders, excludedHeaders, excludedColumns));
|
333
|
+
} else if (Array.isArray(colHeaders)) {
|
334
|
+
headersHTML.push(...getSimpleHeadersHTML(colHeaders, excludedHeaders, excludedColumns));
|
86
335
|
}
|
87
|
-
|
88
|
-
|
336
|
+
if (headersHTML.length > 0) {
|
337
|
+
return ['<thead>', ...headersHTML, '</thead>'];
|
338
|
+
}
|
339
|
+
return [];
|
89
340
|
}
|
90
341
|
|
91
342
|
/**
|
92
|
-
* Converts
|
343
|
+
* Converts config with information about cells and headers into list of values.
|
93
344
|
*
|
94
|
-
* @param {
|
95
|
-
* @
|
345
|
+
* @param {object} config Configuration for building list of values.
|
346
|
+
* @param {Array<number>} [config.excludedRows] List of row indexes which should be excluded when creating the value list.
|
347
|
+
* @param {Array<number>} [config.excludedColumns] List of column indexes which should be excluded when creating the value list.
|
348
|
+
* @param {Array<Array<string|object>>} [config.nestedHeaders] List of headers and information about some nested elements.
|
349
|
+
* @param {Array<string>} [config.colHeaders] List of first level header values.
|
350
|
+
* @returns {string[][]} List of values.
|
96
351
|
*/
|
97
|
-
|
98
|
-
|
99
|
-
const
|
100
|
-
const
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
352
|
+
function getDataWithHeadersByConfig(config) {
|
353
|
+
const dataWithHeaders = [];
|
354
|
+
const excludedColumns = Array.isArray(config === null || config === void 0 ? void 0 : config.excludedColumns) ? config.excludedColumns : [];
|
355
|
+
const excludedRows = Array.isArray(config === null || config === void 0 ? void 0 : config.excludedRows) ? config.excludedRows : [];
|
356
|
+
const {
|
357
|
+
data,
|
358
|
+
nestedHeaders,
|
359
|
+
colHeaders
|
360
|
+
} = config;
|
361
|
+
const excludedHeaders = excludedRows.filter(rowIndex => rowIndex < 0);
|
362
|
+
if (Array.isArray(nestedHeaders)) {
|
363
|
+
dataWithHeaders.push(...getFilteredNestedHeaders(nestedHeaders, excludedHeaders, excludedColumns).map(listOfHeaders => {
|
364
|
+
return listOfHeaders.reduce((headers, header) => {
|
365
|
+
if ((0, _object.isObject)(header)) {
|
366
|
+
headers.push(header.label, ...new Array(header.colspan - 1).fill(''));
|
367
|
+
} else {
|
368
|
+
headers.push(header);
|
369
|
+
}
|
370
|
+
return headers;
|
371
|
+
}, []);
|
372
|
+
}));
|
373
|
+
} else if (Array.isArray(colHeaders)) {
|
374
|
+
dataWithHeaders.push([...colHeaders.filter((columnHeaderData, columnIndex) => excludedColumns.includes(columnIndex) === false)]);
|
375
|
+
}
|
376
|
+
dataWithHeaders.push(...getFilteredCells(data, excludedRows.filter(rowIndex => rowIndex >= 0), excludedColumns.filter(columnIndex => columnIndex >= 0)));
|
377
|
+
return dataWithHeaders;
|
378
|
+
}
|
379
|
+
|
380
|
+
/**
|
381
|
+
* Encode text to HTML.
|
382
|
+
*
|
383
|
+
* @param {string} text Text to prepare.
|
384
|
+
* @returns {string}
|
385
|
+
*/
|
386
|
+
function encodeHTMLEntities(text) {
|
387
|
+
return `${text}`.replace(/&/g, '&').replace('<', '<').replace('>', '>').replace(/(<br(\s*|\/)>(\r\n|\n)?|\r\n|\n)/g, '<br>\r\n').replace(/\x20{2,}/gi, substring => {
|
388
|
+
// The way how Excel serializes data with at least two spaces.
|
389
|
+
return `<span style="mso-spacerun: yes">${' '.repeat(substring.length - 1)} </span>`;
|
390
|
+
}).replace(/\t/gi, '	');
|
391
|
+
}
|
392
|
+
|
393
|
+
/**
|
394
|
+
* Decode HTML to simple text.
|
395
|
+
*
|
396
|
+
* @param {string} html HTML for handling.
|
397
|
+
* @returns {string}
|
398
|
+
*/
|
399
|
+
function decodeHTMLEntities(html) {
|
400
|
+
return html.replace(regEscapedChars, match => ESCAPED_HTML_CHARS[match])
|
401
|
+
// The way how Excel serializes data with at least two spaces.
|
402
|
+
.replace(/<span style="mso-spacerun: yes">(.+?)<\/span>/, '$1').replaceAll(' ', ' ');
|
403
|
+
}
|
404
|
+
|
405
|
+
/**
|
406
|
+
* Converts Handsontable's header coordinates into HTMLTableElement.tHead.
|
407
|
+
*
|
408
|
+
* @param {Core} hotInstance The Handsontable instance.
|
409
|
+
* @param {object} config Configuration for building HTMLTableElement.tHead.
|
410
|
+
* @param {Array<number>} config.rows List of row indexes which should be taken into account when creating
|
411
|
+
* the HTMLTableElement.tHead.
|
412
|
+
* @param {Array<number>} config.columns List of column indexes which should be taken into account when creating
|
413
|
+
* the HTMLTableElement.tHead.
|
414
|
+
* @returns {Array<string>} List of HTMLElements stored as strings.
|
415
|
+
*/
|
416
|
+
function getHeadersHTMLByCoords(hotInstance, config) {
|
417
|
+
const {
|
418
|
+
rows,
|
419
|
+
columns
|
420
|
+
} = config;
|
421
|
+
const headers = rows.filter(rowIndex => rowIndex < 0);
|
422
|
+
const headersHTML = [];
|
423
|
+
if (headers.length === 0 || columns.length === 0) {
|
424
|
+
return [];
|
425
|
+
}
|
426
|
+
headers.forEach(rowIndex => {
|
427
|
+
const rowHTML = ['<tr>'];
|
428
|
+
for (let i = 0; i < columns.length; i += 1) {
|
429
|
+
const columnIndex = columns[i];
|
430
|
+
const headerCell = hotInstance.getCell(rowIndex, columnIndex);
|
431
|
+
const colspan = headerCell === null || headerCell === void 0 ? void 0 : headerCell.getAttribute('colspan');
|
432
|
+
let colspanAttribute = '';
|
433
|
+
if (colspan) {
|
434
|
+
const parsedColspan = parseInt(colspan, 10);
|
435
|
+
colspanAttribute = ` colspan=${parsedColspan}`;
|
436
|
+
i += parsedColspan - 1;
|
437
|
+
}
|
438
|
+
rowHTML.push(`<th${colspanAttribute}>${encodeHTMLEntities(parseEmptyValues(hotInstance.getColHeader(columnIndex, rowIndex)))}</th>`);
|
115
439
|
}
|
116
|
-
|
117
|
-
|
118
|
-
|
440
|
+
rowHTML.push('</tr>');
|
441
|
+
headersHTML.push(...rowHTML);
|
442
|
+
});
|
443
|
+
return ['<thead>', ...headersHTML, '</thead>'];
|
444
|
+
}
|
445
|
+
|
446
|
+
/**
|
447
|
+
* Converts Handsontable's coordinates into list of values for cells being headers.
|
448
|
+
*
|
449
|
+
* @param {Core} hotInstance The Handsontable instance.
|
450
|
+
* @param {object} config Configuration for building the cell value list.
|
451
|
+
* @param {Array<number>} config.rows List of row indexes which should be taken into account when creating the
|
452
|
+
* cell value list.
|
453
|
+
* @param {Array<number>} config.columns List of column indexes which should be taken into account when creating the
|
454
|
+
* cell value list.
|
455
|
+
* @returns {Array[]} List of displayed cell values.
|
456
|
+
*/
|
457
|
+
function getHeadersDataByCoords(hotInstance, config) {
|
458
|
+
const headersData = [];
|
459
|
+
const {
|
460
|
+
columns,
|
461
|
+
rows
|
462
|
+
} = config;
|
463
|
+
const headers = rows.filter(rowIndex => rowIndex < 0);
|
464
|
+
headers.forEach(rowIndex => {
|
465
|
+
const rowData = [];
|
466
|
+
for (let i = 0; i < columns.length; i += 1) {
|
467
|
+
const columnIndex = columns[i];
|
468
|
+
const headerCell = hotInstance.getCell(rowIndex, columnIndex);
|
469
|
+
const colspan = headerCell === null || headerCell === void 0 ? void 0 : headerCell.getAttribute('colspan');
|
470
|
+
rowData.push(hotInstance.getColHeader(columnIndex, rowIndex));
|
471
|
+
if (colspan) {
|
472
|
+
const parsedColspan = parseInt(colspan, 10);
|
473
|
+
rowData.push(...new Array(parsedColspan - 1).fill(''));
|
474
|
+
i += parsedColspan - 1;
|
475
|
+
}
|
119
476
|
}
|
477
|
+
headersData.push(rowData);
|
478
|
+
});
|
479
|
+
return headersData;
|
480
|
+
}
|
481
|
+
|
482
|
+
/**
|
483
|
+
* Converts Handsontable's header coordinates into HTMLTableElement.tBodies.
|
484
|
+
*
|
485
|
+
* @param {Core} hotInstance The Handsontable instance.
|
486
|
+
* @param {object} config Configuration for building HTMLTableElement.
|
487
|
+
* @param {Array<number>} config.rows List of row indexes which should be taken into account when creating the table.
|
488
|
+
* @param {Array<number>} config.columns List of column indexes which should be taken into account when creating the table.
|
489
|
+
* @returns {Array<string>} List of HTMLElements stored as strings.
|
490
|
+
*/
|
491
|
+
function getBodyHTMLByCoords(hotInstance, config) {
|
492
|
+
const {
|
493
|
+
columns,
|
494
|
+
rows
|
495
|
+
} = config;
|
496
|
+
const bodyRows = rows.filter(rowIndex => rowIndex >= 0);
|
497
|
+
const cells = [];
|
498
|
+
if (bodyRows.length === 0 || columns.length === 0) {
|
499
|
+
return [];
|
120
500
|
}
|
121
|
-
|
122
|
-
|
501
|
+
bodyRows.forEach((rowIndex, nthRow) => {
|
502
|
+
const rowHTML = ['<tr>'];
|
503
|
+
columns.forEach((columnIndex, nthColumn) => {
|
504
|
+
if (columnIndex < 0) {
|
505
|
+
rowHTML.push(`<th>${encodeHTMLEntities(parseEmptyValues(hotInstance.getRowHeader(rowIndex)))}</th>`);
|
506
|
+
return;
|
507
|
+
}
|
508
|
+
const cellValue = hotInstance.getCopyableData(rowIndex, columnIndex);
|
509
|
+
const cellValueParsed = encodeHTMLEntities(parseEmptyValues(cellValue));
|
510
|
+
const {
|
511
|
+
hidden,
|
512
|
+
rowspan,
|
513
|
+
colspan
|
514
|
+
} = hotInstance.getCellMeta(rowIndex, columnIndex);
|
515
|
+
if (!hidden) {
|
516
|
+
const attrs = [];
|
517
|
+
if (rowspan) {
|
518
|
+
const recalculatedRowSpan = Math.min(rowspan, bodyRows.slice(nthRow).length);
|
519
|
+
if (recalculatedRowSpan > 1) {
|
520
|
+
attrs.push(` rowspan="${recalculatedRowSpan}"`);
|
521
|
+
}
|
522
|
+
}
|
523
|
+
if (colspan) {
|
524
|
+
const recalculatedColumnSpan = Math.min(colspan, columns.slice(nthColumn).length);
|
525
|
+
if (recalculatedColumnSpan > 1) {
|
526
|
+
attrs.push(` colspan="${recalculatedColumnSpan}"`);
|
527
|
+
}
|
528
|
+
}
|
529
|
+
rowHTML.push(`<td${attrs.join('')}>${cellValueParsed}</td>`);
|
530
|
+
}
|
531
|
+
});
|
532
|
+
rowHTML.push('</tr>');
|
533
|
+
cells.push(...rowHTML);
|
534
|
+
});
|
535
|
+
return ['<tbody>', ...cells, '</tbody>'];
|
536
|
+
}
|
537
|
+
|
538
|
+
/**
|
539
|
+
* Converts Handsontable's coordinates into list of values for cells not being headers.
|
540
|
+
*
|
541
|
+
* @param {Core} hotInstance The Handsontable instance.
|
542
|
+
* @param {object} config Configuration for building the cell value list.
|
543
|
+
* @param {Array<number>} config.rows List of row indexes which should be taken into account when creating the
|
544
|
+
* cell value list.
|
545
|
+
* @param {Array<number>} config.columns List of column indexes which should be taken into account when creating the
|
546
|
+
* cell value list.
|
547
|
+
* @returns {Array[]} List of displayed cell values.
|
548
|
+
*/
|
549
|
+
function getBodyDataByCoords(hotInstance, config) {
|
550
|
+
const cells = [];
|
551
|
+
const {
|
552
|
+
columns,
|
553
|
+
rows
|
554
|
+
} = config;
|
555
|
+
const bodyRows = rows.filter(rowIndex => rowIndex >= 0);
|
556
|
+
bodyRows.forEach(rowIndex => {
|
557
|
+
const rowData = [];
|
558
|
+
columns.forEach(columnIndex => {
|
559
|
+
const cellValue = hotInstance.getCopyableData(rowIndex, columnIndex);
|
560
|
+
const cellValueParsed = (0, _mixed.isEmpty)(cellValue) ? '' : cellValue;
|
561
|
+
rowData.push(cellValueParsed);
|
562
|
+
});
|
563
|
+
cells.push(rowData);
|
564
|
+
});
|
565
|
+
return cells;
|
123
566
|
}
|
124
567
|
|
125
568
|
/**
|
@@ -167,18 +610,19 @@ function htmlToGridSettings(element) {
|
|
167
610
|
}
|
168
611
|
return !isDataRow;
|
169
612
|
});
|
613
|
+
const isAnyNested = thRows.find(tr => tr.querySelector('th[colspan]') !== null) !== undefined;
|
170
614
|
thRowsLen = thRows.length;
|
171
615
|
hasColHeaders = thRowsLen > 0;
|
172
|
-
if (thRowsLen > 1) {
|
616
|
+
if (thRowsLen > 1 || isAnyNested) {
|
173
617
|
settingsObj.nestedHeaders = Array.from(thRows).reduce((rows, row) => {
|
174
618
|
const headersRow = Array.from(row.cells).reduce((headers, header, currentIndex) => {
|
175
619
|
if (hasRowHeaders && currentIndex === 0) {
|
176
620
|
return headers;
|
177
621
|
}
|
178
622
|
const {
|
179
|
-
colSpan: colspan
|
180
|
-
innerHTML
|
623
|
+
colSpan: colspan
|
181
624
|
} = header;
|
625
|
+
const innerHTML = decodeHTMLEntities(header.innerHTML);
|
182
626
|
const nextHeader = colspan > 1 ? {
|
183
627
|
label: innerHTML,
|
184
628
|
colspan
|
@@ -194,7 +638,7 @@ function htmlToGridSettings(element) {
|
|
194
638
|
if (hasRowHeaders && index === 0) {
|
195
639
|
return headers;
|
196
640
|
}
|
197
|
-
headers.push(header.innerHTML);
|
641
|
+
headers.push(decodeHTMLEntities(header.innerHTML));
|
198
642
|
return headers;
|
199
643
|
}, []);
|
200
644
|
}
|
@@ -255,7 +699,7 @@ function htmlToGridSettings(element) {
|
|
255
699
|
} else {
|
256
700
|
cellValue = innerHTML.replace(/<br(\s*|\/)>[\r\n]?/gim, '\r\n');
|
257
701
|
}
|
258
|
-
dataArr[row][col] = cellValue
|
702
|
+
dataArr[row][col] = decodeHTMLEntities(cellValue);
|
259
703
|
} else {
|
260
704
|
rowHeaders.push(innerHTML);
|
261
705
|
}
|