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