handsontable 0.0.0-next-abfe462-20231207 → 0.0.0-next-3d099da-20231208
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 +6 -11
- package/3rdparty/walkontable/src/calculator/index.mjs +3 -5
- package/3rdparty/walkontable/src/calculator/viewportColumns.js +122 -1
- package/3rdparty/walkontable/src/calculator/viewportColumns.mjs +124 -2
- package/3rdparty/walkontable/src/calculator/viewportRows.js +1 -1
- package/3rdparty/walkontable/src/calculator/viewportRows.mjs +3 -2
- package/3rdparty/walkontable/src/core/_base.js +12 -0
- package/3rdparty/walkontable/src/core/_base.mjs +12 -0
- package/3rdparty/walkontable/src/core/core.js +2 -0
- package/3rdparty/walkontable/src/core/core.mjs +2 -0
- package/3rdparty/walkontable/src/facade/core.js +9 -0
- package/3rdparty/walkontable/src/facade/core.mjs +9 -0
- package/3rdparty/walkontable/src/index.js +4 -3
- package/3rdparty/walkontable/src/index.mjs +2 -1
- package/3rdparty/walkontable/src/overlays.js +3 -0
- package/3rdparty/walkontable/src/overlays.mjs +4 -0
- package/3rdparty/walkontable/src/renderer/colGroup.js +0 -10
- package/3rdparty/walkontable/src/renderer/colGroup.mjs +0 -10
- package/3rdparty/walkontable/src/renderer/rows.js +3 -4
- package/3rdparty/walkontable/src/renderer/rows.mjs +3 -4
- package/3rdparty/walkontable/src/selection/manager.js +1 -0
- package/3rdparty/walkontable/src/selection/manager.mjs +1 -0
- package/3rdparty/walkontable/src/settings.js +0 -3
- package/3rdparty/walkontable/src/settings.mjs +0 -2
- package/3rdparty/walkontable/src/table.js +1 -0
- package/3rdparty/walkontable/src/table.mjs +1 -0
- package/3rdparty/walkontable/src/utils/column.js +12 -27
- package/3rdparty/walkontable/src/utils/column.mjs +12 -27
- package/3rdparty/walkontable/src/viewport.js +17 -22
- package/3rdparty/walkontable/src/viewport.mjs +18 -23
- package/base.js +2 -4
- package/base.mjs +2 -2
- package/core/focusCatcher/index.js +6 -44
- package/core/focusCatcher/index.mjs +6 -44
- package/core.js +11 -0
- package/core.mjs +11 -0
- package/dataMap/dataMap.js +0 -1
- package/dataMap/metaManager/metaSchema.js +2 -28
- package/dataMap/metaManager/metaSchema.mjs +2 -28
- package/dataMap/metaManager/mods/extendMetaProperties.js +0 -12
- package/dataMap/metaManager/mods/extendMetaProperties.mjs +0 -12
- package/dist/handsontable.css +2 -2
- package/dist/handsontable.full.css +2 -2
- package/dist/handsontable.full.js +3902 -2639
- package/dist/handsontable.full.min.css +2 -2
- package/dist/handsontable.full.min.js +70 -66
- package/dist/handsontable.js +3905 -2642
- package/dist/handsontable.min.css +2 -2
- package/dist/handsontable.min.js +39 -35
- package/editorManager.js +4 -3
- package/editorManager.mjs +4 -3
- package/editors/autocompleteEditor/autocompleteEditor.js +2 -0
- package/editors/autocompleteEditor/autocompleteEditor.mjs +2 -0
- package/editors/handsontableEditor/handsontableEditor.js +1 -0
- package/editors/handsontableEditor/handsontableEditor.mjs +1 -0
- package/editors/textEditor/textEditor.js +4 -0
- package/editors/textEditor/textEditor.mjs +4 -0
- package/helpers/mixed.js +1 -1
- package/helpers/mixed.mjs +1 -1
- package/package.json +1 -1
- package/pluginHooks.d.ts +29 -6
- package/pluginHooks.js +123 -65
- package/pluginHooks.mjs +122 -62
- package/plugins/copyPaste/clipboardData/clipboardData.js +588 -0
- package/plugins/copyPaste/clipboardData/clipboardData.mjs +584 -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 +51 -129
- package/plugins/copyPaste/copyPaste.mjs +54 -132
- package/plugins/copyPaste/copyableRanges.js +7 -43
- package/plugins/copyPaste/copyableRanges.mjs +7 -42
- package/plugins/copyPaste/pasteEvent.mjs +1 -1
- package/plugins/customBorders/customBorders.js +5 -0
- package/plugins/customBorders/customBorders.mjs +5 -0
- package/plugins/customBorders/utils.js +1 -0
- package/plugins/customBorders/utils.mjs +1 -0
- package/plugins/formulas/formulas.js +2 -0
- package/plugins/formulas/formulas.mjs +2 -0
- package/plugins/formulas/indexSyncer/axisSyncer.js +1 -0
- package/plugins/formulas/indexSyncer/axisSyncer.mjs +1 -0
- package/plugins/manualColumnResize/manualColumnResize.js +1 -0
- package/plugins/manualColumnResize/manualColumnResize.mjs +1 -0
- package/plugins/mergeCells/mergeCells.js +127 -1
- package/plugins/mergeCells/mergeCells.mjs +127 -1
- package/plugins/nestedHeaders/nestedHeaders.js +87 -41
- package/plugins/nestedHeaders/nestedHeaders.mjs +88 -42
- package/plugins/nestedHeaders/stateManager/headersTree.js +1 -0
- package/plugins/nestedHeaders/stateManager/headersTree.mjs +1 -0
- package/plugins/undoRedo/undoRedo.js +2 -0
- package/plugins/undoRedo/undoRedo.mjs +2 -0
- package/renderers/autocompleteRenderer/autocompleteRenderer.js +1 -0
- package/renderers/autocompleteRenderer/autocompleteRenderer.mjs +1 -0
- package/renderers/checkboxRenderer/checkboxRenderer.js +2 -0
- package/renderers/checkboxRenderer/checkboxRenderer.mjs +2 -0
- package/selection/highlight/highlight.js +1 -0
- package/selection/highlight/highlight.mjs +1 -0
- package/selection/index.js +3 -1
- package/selection/index.mjs +2 -2
- package/selection/utils.js +34 -0
- package/selection/utils.mjs +33 -0
- package/settings.d.ts +0 -1
- package/tableView.js +2 -1
- package/tableView.mjs +2 -1
- package/translations/indexMapper.js +1 -2
- package/utils/parseTable.js +538 -84
- package/utils/parseTable.mjs +534 -83
- package/validators/timeValidator/timeValidator.js +1 -0
- package/validators/timeValidator/timeValidator.mjs +1 -0
- package/3rdparty/walkontable/src/calculator/renderAllColumns.js +0 -50
- package/3rdparty/walkontable/src/calculator/renderAllColumns.mjs +0 -46
- package/3rdparty/walkontable/src/calculator/renderAllRows.js +0 -50
- package/3rdparty/walkontable/src/calculator/renderAllRows.mjs +0 -46
- package/3rdparty/walkontable/src/utils/columnStretching.js +0 -219
- package/3rdparty/walkontable/src/utils/columnStretching.mjs +0 -215
- package/plugins/copyPaste/clipboardData.js +0 -18
- package/plugins/copyPaste/clipboardData.mjs +0 -14
@@ -0,0 +1,588 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
exports.__esModule = true;
|
4
|
+
require("core-js/modules/es.error.cause.js");
|
5
|
+
var _mixed = require("../../../helpers/mixed");
|
6
|
+
var _object = require("../../../helpers/object");
|
7
|
+
var _templateLiteralTag = require("../../../helpers/templateLiteralTag");
|
8
|
+
var _console = require("../../../helpers/console");
|
9
|
+
var _parseTable = require("../../../utils/parseTable");
|
10
|
+
var _array = require("../../../helpers/array");
|
11
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
13
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
14
|
+
const META_HEAD = exports.META_HEAD = ['<meta name="generator" content="Handsontable"/>', '<style type="text/css">td{white-space:normal}br{mso-data-placement:same-cell}</style>'].join('');
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Creates an object containing information about performed action: copy, cut (performing also copying) or paste.
|
18
|
+
*
|
19
|
+
* @private
|
20
|
+
*/
|
21
|
+
class ClipboardData {
|
22
|
+
constructor() {
|
23
|
+
/**
|
24
|
+
* Sanitized data of "text/html" type inside the clipboard.
|
25
|
+
*
|
26
|
+
* @private
|
27
|
+
* @type {string}
|
28
|
+
*/
|
29
|
+
_defineProperty(this, "html", void 0);
|
30
|
+
/**
|
31
|
+
* Copied data stored as array of arrays.
|
32
|
+
*
|
33
|
+
* @private
|
34
|
+
* @type {string[][]}
|
35
|
+
*/
|
36
|
+
_defineProperty(this, "data", void 0);
|
37
|
+
if (this.constructor === ClipboardData) {
|
38
|
+
throw new Error('The `ClipboardData` is an abstract class and it can\'t be instantiated. Please use ' + '`CopyClipboardData` or `PasteClipboardData` classes instead.');
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Gets copied data stored as array of arrays.
|
44
|
+
*
|
45
|
+
* @returns {string[][]}
|
46
|
+
*/
|
47
|
+
getData() {
|
48
|
+
return (0, _object.deepClone)(this.data);
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Gets meta information about copied data.
|
53
|
+
*
|
54
|
+
* @returns {object} Object containing `data`, `colHeaders`, `rowHeaders`, `nestedHeaders`, `mergeCells` keys and
|
55
|
+
* the corresponding values.
|
56
|
+
*/
|
57
|
+
getMetaInfo() {
|
58
|
+
return (0, _parseTable.htmlToGridSettings)(this.html);
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Sets meta information for certain property.
|
63
|
+
*
|
64
|
+
* @private
|
65
|
+
* @param {string} property Property for which the meta information will be changed.
|
66
|
+
* @param {*} value New meta information value.
|
67
|
+
*/
|
68
|
+
setMetaInfo(property, value) {
|
69
|
+
const metaInfo = this.getMetaInfo();
|
70
|
+
if (value === null) {
|
71
|
+
delete metaInfo[property];
|
72
|
+
} else {
|
73
|
+
metaInfo[property] = value;
|
74
|
+
}
|
75
|
+
this.overwriteInfo(metaInfo);
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Overwrite stored data basing on handled configuration.
|
80
|
+
*
|
81
|
+
* @private
|
82
|
+
* @param {object} config Configuration.
|
83
|
+
*/
|
84
|
+
overwriteInfo(config) {
|
85
|
+
this.html = [this.isSerializedHandsontable() ? META_HEAD : '', (0, _parseTable.getHTMLFromConfig)(config)].join('');
|
86
|
+
this.data = (0, _parseTable.getDataWithHeadersByConfig)(config);
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Adjust information about merged cells after removing some columns.
|
91
|
+
*
|
92
|
+
* Note: Used indexes refers to processed data, not to the instance of Handsontable.
|
93
|
+
*
|
94
|
+
* @private
|
95
|
+
* @param {object} metaInfo Object containing `data`, `colHeaders`, `rowHeaders`, `nestedHeaders`, `mergeCells`
|
96
|
+
* keys and the corresponding values, which will be changed by the reference.
|
97
|
+
* @param {number[]} removedColumns List of column indexes which should be excluded when creating copy/cut/paste data.
|
98
|
+
*/
|
99
|
+
adjustAfterColumnsRemoval(metaInfo, removedColumns) {
|
100
|
+
const mergedCells = metaInfo.mergeCells;
|
101
|
+
if ((0, _mixed.isDefined)(mergedCells) === false) {
|
102
|
+
return;
|
103
|
+
}
|
104
|
+
metaInfo.mergeCells = mergedCells.reduce((filteredNestedCells, mergeArea) => {
|
105
|
+
const {
|
106
|
+
col: mergeStartColumn,
|
107
|
+
colspan
|
108
|
+
} = mergeArea;
|
109
|
+
const removedMergedColumns = removedColumns.filter(column => column >= mergeStartColumn && column < mergeStartColumn + colspan);
|
110
|
+
const removedMergedColumnsLength = removedMergedColumns.length;
|
111
|
+
if (removedMergedColumnsLength === colspan) {
|
112
|
+
return filteredNestedCells;
|
113
|
+
} else if (colspan - removedMergedColumnsLength === 1) {
|
114
|
+
delete mergeArea.colspan;
|
115
|
+
} else if (removedMergedColumnsLength > 0) {
|
116
|
+
mergeArea.colspan = colspan - removedMergedColumnsLength;
|
117
|
+
}
|
118
|
+
if (Number.isInteger(mergeArea.rowspan) || Number.isInteger(mergeArea.colspan)) {
|
119
|
+
return filteredNestedCells.concat(mergeArea);
|
120
|
+
}
|
121
|
+
return filteredNestedCells;
|
122
|
+
}, []);
|
123
|
+
metaInfo.mergeCells.forEach(mergeArea => {
|
124
|
+
const shiftedColumns = removedColumns.filter(column => column < mergeArea.col);
|
125
|
+
const shifterColumnsLength = shiftedColumns.length;
|
126
|
+
mergeArea.col = mergeArea.col - shifterColumnsLength;
|
127
|
+
});
|
128
|
+
if (metaInfo.mergeCells.length === 0) {
|
129
|
+
delete metaInfo.mergeCells;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Adjust information about merged cells after removing some rows.
|
135
|
+
*
|
136
|
+
* Note: Used indexes refers to processed data, not to the instance of Handsontable.
|
137
|
+
*
|
138
|
+
* @private
|
139
|
+
* @param {object} metaInfo Object containing `data`, `colHeaders`, `rowHeaders`, `nestedHeaders`, `mergeCells`
|
140
|
+
* keys and the corresponding values, which will be changed by the reference.
|
141
|
+
* @param {number[]} removedRows List of row indexes which should be excluded when creating copy/cut/paste data.
|
142
|
+
*/
|
143
|
+
adjustAfterRowRemoval(metaInfo, removedRows) {
|
144
|
+
const mergedCells = metaInfo.mergeCells;
|
145
|
+
if ((0, _mixed.isDefined)(mergedCells) === false) {
|
146
|
+
return;
|
147
|
+
}
|
148
|
+
metaInfo.mergeCells = mergedCells.reduce((filteredNestedCells, mergeArea) => {
|
149
|
+
const {
|
150
|
+
row: mergeStartRow,
|
151
|
+
rowspan
|
152
|
+
} = mergeArea;
|
153
|
+
const removedMergedRows = removedRows.filter(row => row >= mergeStartRow && row < mergeStartRow + rowspan);
|
154
|
+
const removedMergedRowsLength = removedMergedRows.length;
|
155
|
+
if (removedMergedRowsLength === rowspan) {
|
156
|
+
return filteredNestedCells;
|
157
|
+
} else if (rowspan - removedMergedRowsLength === 1) {
|
158
|
+
delete mergeArea.rowspan;
|
159
|
+
} else if (removedMergedRowsLength > 0) {
|
160
|
+
mergeArea.rowspan = rowspan - removedMergedRowsLength;
|
161
|
+
}
|
162
|
+
if (Number.isInteger(mergeArea.rowspan) || Number.isInteger(mergeArea.colspan)) {
|
163
|
+
return filteredNestedCells.concat(mergeArea);
|
164
|
+
}
|
165
|
+
return filteredNestedCells;
|
166
|
+
}, []);
|
167
|
+
metaInfo.mergeCells.forEach(mergeArea => {
|
168
|
+
const shiftedRows = removedRows.filter(row => row < mergeArea.row);
|
169
|
+
const shifterRowsLength = shiftedRows.length;
|
170
|
+
mergeArea.row = mergeArea.row - shifterRowsLength;
|
171
|
+
});
|
172
|
+
if (metaInfo.mergeCells.length === 0) {
|
173
|
+
delete metaInfo.mergeCells;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
177
|
+
/**
|
178
|
+
* Remove rows from the serialized dataset.
|
179
|
+
*
|
180
|
+
* Note: Used indexes refers to processed data, not to the instance of Handsontable. Please keep in mind that headers
|
181
|
+
* are handled separately from cells and they are recognised using negative indexes.
|
182
|
+
*
|
183
|
+
* @param {number[]} rows List of row indexes which should be excluded when creating copy/cut/paste data.
|
184
|
+
*/
|
185
|
+
removeRows(rows) {
|
186
|
+
if (this.isSerializedTable() === false) {
|
187
|
+
return;
|
188
|
+
}
|
189
|
+
const metaInfo = this.getMetaInfo();
|
190
|
+
this.adjustAfterRowRemoval(metaInfo, rows);
|
191
|
+
const config = {
|
192
|
+
...metaInfo,
|
193
|
+
excludedRows: rows
|
194
|
+
};
|
195
|
+
this.overwriteInfo(config);
|
196
|
+
}
|
197
|
+
|
198
|
+
/**
|
199
|
+
* Remove columns from the serialized dataset.
|
200
|
+
*
|
201
|
+
* Note: Used indexes refers to processed data, not to the instance of Handsontable. Please keep in mind that headers
|
202
|
+
* are handled separately from cells and they are recognised using negative indexes.
|
203
|
+
*
|
204
|
+
* @param {number[]} columns List of column indexes which should be excluded when creating copy/cut/paste data.
|
205
|
+
*/
|
206
|
+
removeColumns(columns) {
|
207
|
+
if (this.isSerializedTable() === false) {
|
208
|
+
return;
|
209
|
+
}
|
210
|
+
const metaInfo = this.getMetaInfo();
|
211
|
+
const {
|
212
|
+
nestedHeaders,
|
213
|
+
colHeaders
|
214
|
+
} = metaInfo;
|
215
|
+
if (Array.isArray(nestedHeaders) && columns.length > 0) {
|
216
|
+
(0, _console.warn)('It\'s not possible to modify copied dataset containing nested headers.');
|
217
|
+
return;
|
218
|
+
}
|
219
|
+
if (Array.isArray(colHeaders) && columns.length > 0) {
|
220
|
+
metaInfo.colHeaders = colHeaders.filter(columnIndex => columns.includes(columnIndex) === false);
|
221
|
+
}
|
222
|
+
this.adjustAfterColumnsRemoval(metaInfo, columns);
|
223
|
+
const config = {
|
224
|
+
...metaInfo,
|
225
|
+
excludedColumns: columns
|
226
|
+
};
|
227
|
+
this.overwriteInfo(config);
|
228
|
+
}
|
229
|
+
|
230
|
+
/**
|
231
|
+
* Get warning message when there is some problem with row insertion or undefined otherwise.
|
232
|
+
*
|
233
|
+
* @private
|
234
|
+
* @param {number} rowIndex An index of the row at which the new values will be inserted.
|
235
|
+
* @param {string[]} values List of values.
|
236
|
+
* @returns {undefined|string}
|
237
|
+
*/
|
238
|
+
getRowInsertionWarn(rowIndex, values) {
|
239
|
+
const metaInfo = this.getMetaInfo();
|
240
|
+
const data = metaInfo.data;
|
241
|
+
const insertedElementsCount = values.length;
|
242
|
+
if (Array.isArray(data) === false) {
|
243
|
+
const {
|
244
|
+
nestedHeaders,
|
245
|
+
colHeaders
|
246
|
+
} = metaInfo;
|
247
|
+
if (rowIndex > 0) {
|
248
|
+
return (0, _templateLiteralTag.toSingleLine)`Invalid row insertion done inside some \`CopyPaste\` hook. There is no possibility to\x20
|
249
|
+
expand an empty dataset at position higher than zero.`;
|
250
|
+
}
|
251
|
+
if (Array.isArray(nestedHeaders) && nestedHeaders[0].length !== insertedElementsCount || Array.isArray(colHeaders) && colHeaders.length !== insertedElementsCount) {
|
252
|
+
return (0, _templateLiteralTag.toSingleLine)`Invalid row insertion done inside some \`CopyPaste\` hook. Please provide proper number\x20
|
253
|
+
of elements (corresponding to size of the dataset in other rows) for inserted rows.`;
|
254
|
+
}
|
255
|
+
return;
|
256
|
+
}
|
257
|
+
const numberOfRows = data.length;
|
258
|
+
const numberOfColumns = data[0].length;
|
259
|
+
if (rowIndex > numberOfRows) {
|
260
|
+
return (0, _templateLiteralTag.toSingleLine)`Invalid row insertion done inside some \`CopyPaste\` hook. Please provide an valid row\x20
|
261
|
+
index (not too high) for row data insertion.`;
|
262
|
+
}
|
263
|
+
if (numberOfColumns !== insertedElementsCount) {
|
264
|
+
return (0, _templateLiteralTag.toSingleLine)`Invalid row insertion done inside some \`CopyPaste\` hook. Please provide proper number of\x20
|
265
|
+
elements (corresponding to size of the dataset in other rows) for inserted rows.`;
|
266
|
+
}
|
267
|
+
}
|
268
|
+
|
269
|
+
/**
|
270
|
+
* Adjust information about merged cells after row insertion.
|
271
|
+
*
|
272
|
+
* Note: Used index refers to processed data, not to the instance of Handsontable.
|
273
|
+
*
|
274
|
+
* @private
|
275
|
+
* @param {object} metaInfo Object containing `data`, `colHeaders`, `rowHeaders`, `nestedHeaders`, `mergeCells`
|
276
|
+
* keys and the corresponding values, which will be changed by the reference.
|
277
|
+
* @param {number} rowIndex An index of the row at which the new values have been inserted.
|
278
|
+
*/
|
279
|
+
adjustAfterRowInsertion(metaInfo, rowIndex) {
|
280
|
+
const {
|
281
|
+
mergeCells: mergedCells,
|
282
|
+
data
|
283
|
+
} = metaInfo;
|
284
|
+
mergedCells === null || mergedCells === void 0 || mergedCells.forEach(mergeArea => {
|
285
|
+
const {
|
286
|
+
row: mergeStartRow,
|
287
|
+
col: mergeStartColumn,
|
288
|
+
rowspan,
|
289
|
+
colspan
|
290
|
+
} = mergeArea;
|
291
|
+
if (rowIndex > mergeStartRow && rowIndex < mergeStartRow + rowspan) {
|
292
|
+
mergeArea.rowspan += 1;
|
293
|
+
for (let i = 0; i < colspan; i += 1) {
|
294
|
+
data[rowIndex][mergeStartColumn + i] = '';
|
295
|
+
}
|
296
|
+
}
|
297
|
+
});
|
298
|
+
mergedCells === null || mergedCells === void 0 || mergedCells.forEach(mergeArea => {
|
299
|
+
if (rowIndex <= mergeArea.row) {
|
300
|
+
mergeArea.row += 1;
|
301
|
+
}
|
302
|
+
});
|
303
|
+
}
|
304
|
+
|
305
|
+
/**
|
306
|
+
* Insert values at row index.
|
307
|
+
*
|
308
|
+
* Note: Used index refers to processed data, not to the instance of Handsontable.
|
309
|
+
*
|
310
|
+
* @param {number} rowIndex An index of the row at which the new values will be inserted.
|
311
|
+
* @param {string[]} values List of values.
|
312
|
+
*/
|
313
|
+
insertAtRow(rowIndex, values) {
|
314
|
+
if (this.isSerializedTable() === false) {
|
315
|
+
return;
|
316
|
+
}
|
317
|
+
const metaInfo = this.getMetaInfo();
|
318
|
+
const data = metaInfo.data || [];
|
319
|
+
const rowInsertionWarn = this.getRowInsertionWarn(rowIndex, values);
|
320
|
+
if ((0, _mixed.isDefined)(rowInsertionWarn)) {
|
321
|
+
(0, _console.warn)(rowInsertionWarn);
|
322
|
+
return;
|
323
|
+
}
|
324
|
+
metaInfo.data = [...data.slice(0, rowIndex), values, ...data.slice(rowIndex)];
|
325
|
+
this.adjustAfterRowInsertion(metaInfo, rowIndex);
|
326
|
+
this.overwriteInfo(metaInfo);
|
327
|
+
}
|
328
|
+
|
329
|
+
/**
|
330
|
+
* Get warning message when there is some problem with row insertion or undefined otherwise.
|
331
|
+
*
|
332
|
+
* @private
|
333
|
+
* @param {number} columnIndex An index of the column at which the new values will be inserted or removed.
|
334
|
+
* @param {string[]} values List of values.
|
335
|
+
* @returns {undefined|string}
|
336
|
+
*/
|
337
|
+
getColumnInsertionWarn(columnIndex, values) {
|
338
|
+
const {
|
339
|
+
nestedHeaders,
|
340
|
+
data,
|
341
|
+
colHeaders
|
342
|
+
} = this.getMetaInfo();
|
343
|
+
const headerLevels = (0, _mixed.isDefined)(colHeaders) ? 1 : 0;
|
344
|
+
if (Array.isArray(nestedHeaders)) {
|
345
|
+
return (0, _templateLiteralTag.toSingleLine)`Invalid column insertion done inside some \`CopyPaste\` hook. It's not possible to modify\x20
|
346
|
+
copied dataset containing nested headers`;
|
347
|
+
}
|
348
|
+
if (Array.isArray(data) === false) {
|
349
|
+
return;
|
350
|
+
}
|
351
|
+
const numberOfRows = data.length + headerLevels;
|
352
|
+
const numberOfColumns = data[0].length;
|
353
|
+
if (columnIndex > numberOfColumns) {
|
354
|
+
return (0, _templateLiteralTag.toSingleLine)`Invalid column insertion done inside some \`CopyPaste\` hook. Please provide an valid\x20
|
355
|
+
column index (not too high) for column data insertion.`;
|
356
|
+
}
|
357
|
+
if (values.length !== numberOfRows) {
|
358
|
+
return (0, _templateLiteralTag.toSingleLine)`Invalid column insertion done inside some \`CopyPaste\` hook. Please provide proper number\x20
|
359
|
+
of elements (corresponding to size of the dataset in other columns, including headers) for inserted columns.`;
|
360
|
+
}
|
361
|
+
}
|
362
|
+
|
363
|
+
/**
|
364
|
+
* Adjust information about merged cells after column insertion.
|
365
|
+
*
|
366
|
+
* Note: Used index refers to processed data, not to the instance of Handsontable.
|
367
|
+
*
|
368
|
+
* @private
|
369
|
+
* @param {object} metaInfo Object containing `data`, `colHeaders`, `rowHeaders`, `nestedHeaders`, `mergeCells`
|
370
|
+
* keys and the corresponding values, which will be changed by the reference.
|
371
|
+
* @param {number} columnIndex An index of the column at which the new values have been inserted.
|
372
|
+
*/
|
373
|
+
adjustAfterColumnInsertion(metaInfo, columnIndex) {
|
374
|
+
const {
|
375
|
+
mergeCells: mergedCells,
|
376
|
+
data
|
377
|
+
} = metaInfo;
|
378
|
+
mergedCells === null || mergedCells === void 0 || mergedCells.forEach(mergeArea => {
|
379
|
+
const {
|
380
|
+
row: mergeStartRow,
|
381
|
+
col: mergeStartColumn,
|
382
|
+
colspan,
|
383
|
+
rowspan
|
384
|
+
} = mergeArea;
|
385
|
+
if (columnIndex > mergeStartColumn && columnIndex < mergeStartColumn + colspan) {
|
386
|
+
mergeArea.colspan += 1;
|
387
|
+
for (let i = 0; i < rowspan; i += 1) {
|
388
|
+
data[mergeStartRow + i][columnIndex] = '';
|
389
|
+
}
|
390
|
+
}
|
391
|
+
});
|
392
|
+
mergedCells === null || mergedCells === void 0 || mergedCells.forEach(mergeArea => {
|
393
|
+
if (columnIndex <= mergeArea.col) {
|
394
|
+
mergeArea.col += 1;
|
395
|
+
}
|
396
|
+
});
|
397
|
+
}
|
398
|
+
|
399
|
+
/**
|
400
|
+
* Insert values at column index.
|
401
|
+
*
|
402
|
+
* Note: Used index refers to processed data, not to the instance of Handsontable.
|
403
|
+
*
|
404
|
+
* @param {number} columnIndex An index of the column at which the new values will be inserted or removed.
|
405
|
+
* @param {string[]} values List of values.
|
406
|
+
*/
|
407
|
+
insertAtColumn(columnIndex, values) {
|
408
|
+
if (this.isSerializedTable() === false) {
|
409
|
+
return;
|
410
|
+
}
|
411
|
+
const metaInfo = this.getMetaInfo();
|
412
|
+
const {
|
413
|
+
data,
|
414
|
+
colHeaders
|
415
|
+
} = metaInfo;
|
416
|
+
const headerLevels = (0, _mixed.isDefined)(colHeaders) ? 1 : 0;
|
417
|
+
const columnInsertionWarn = this.getColumnInsertionWarn(columnIndex, values);
|
418
|
+
if ((0, _mixed.isDefined)(columnInsertionWarn)) {
|
419
|
+
(0, _console.warn)(columnInsertionWarn);
|
420
|
+
return;
|
421
|
+
}
|
422
|
+
if (headerLevels > 0) {
|
423
|
+
colHeaders.splice(columnIndex, 0, values[0]);
|
424
|
+
}
|
425
|
+
data === null || data === void 0 || data.forEach((rowData, rowIndex) => {
|
426
|
+
rowData.splice(columnIndex, 0, values[rowIndex + headerLevels]);
|
427
|
+
});
|
428
|
+
this.adjustAfterColumnInsertion(metaInfo, columnIndex);
|
429
|
+
this.overwriteInfo(metaInfo);
|
430
|
+
}
|
431
|
+
|
432
|
+
/**
|
433
|
+
* Get internal column index for nested header with certain row and column indexes.
|
434
|
+
*
|
435
|
+
* @private
|
436
|
+
* @param {number} row Row index related to level of the nested headers.
|
437
|
+
* @param {number} column Column index for certain row.
|
438
|
+
* @returns {*}
|
439
|
+
*/
|
440
|
+
getNestedHeaderColumn(row, column) {
|
441
|
+
const {
|
442
|
+
nestedHeaders
|
443
|
+
} = this.getMetaInfo();
|
444
|
+
const rowRelative = row + nestedHeaders.length;
|
445
|
+
const nestedHeadersForLevel = nestedHeaders[rowRelative];
|
446
|
+
let indexInHeadersArray;
|
447
|
+
let currentColumnIndex = 0;
|
448
|
+
if (Array.isArray(nestedHeadersForLevel) === false) {
|
449
|
+
return;
|
450
|
+
}
|
451
|
+
(0, _array.arrayEach)(nestedHeadersForLevel, (nestedHeaderInfo, index) => {
|
452
|
+
const isSimpleHeader = typeof nestedHeaderInfo === 'string';
|
453
|
+
if (isSimpleHeader === true) {
|
454
|
+
if (currentColumnIndex === column) {
|
455
|
+
indexInHeadersArray = index;
|
456
|
+
return false;
|
457
|
+
}
|
458
|
+
currentColumnIndex += 1;
|
459
|
+
} else {
|
460
|
+
const {
|
461
|
+
colspan
|
462
|
+
} = nestedHeaderInfo;
|
463
|
+
if (column < currentColumnIndex + colspan) {
|
464
|
+
indexInHeadersArray = index;
|
465
|
+
return false;
|
466
|
+
}
|
467
|
+
currentColumnIndex += colspan;
|
468
|
+
}
|
469
|
+
});
|
470
|
+
return indexInHeadersArray;
|
471
|
+
}
|
472
|
+
|
473
|
+
/**
|
474
|
+
* Change headers or cells in the serialized dataset.
|
475
|
+
*
|
476
|
+
* Note: Used indexes refers to processed data, not to the instance of Handsontable. Please keep in mind that headers
|
477
|
+
* are handled separately from cells and they are recognised using negative indexes.
|
478
|
+
*
|
479
|
+
* @param {number} row Row index of cell which should be changed.
|
480
|
+
* @param {number} column Column index of cell which should be changed.
|
481
|
+
* @param {string} value Value for particular index.
|
482
|
+
*/
|
483
|
+
setCellAt(row, column, value) {
|
484
|
+
if (this.isSerializedTable() === false) {
|
485
|
+
return;
|
486
|
+
}
|
487
|
+
const config = this.getMetaInfo();
|
488
|
+
const {
|
489
|
+
data,
|
490
|
+
nestedHeaders,
|
491
|
+
colHeaders
|
492
|
+
} = config;
|
493
|
+
if (row < 0) {
|
494
|
+
if (Array.isArray(nestedHeaders)) {
|
495
|
+
const rowRelative = row + nestedHeaders.length;
|
496
|
+
const nestedHeaderColumn = this.getNestedHeaderColumn(row, column);
|
497
|
+
if ((0, _mixed.isDefined)(nestedHeaderColumn) === false) {
|
498
|
+
return;
|
499
|
+
}
|
500
|
+
const header = nestedHeaders[rowRelative][nestedHeaderColumn];
|
501
|
+
if ((0, _object.isObject)(header)) {
|
502
|
+
header.label = value;
|
503
|
+
} else {
|
504
|
+
nestedHeaders[rowRelative][nestedHeaderColumn] = value;
|
505
|
+
}
|
506
|
+
} else if (Array.isArray(colHeaders)) {
|
507
|
+
if ((0, _mixed.isDefined)(colHeaders[column])) {
|
508
|
+
colHeaders[column] = value;
|
509
|
+
}
|
510
|
+
}
|
511
|
+
} else if (row >= 0 && Array.isArray(data) && Array.isArray(data[row]) && (0, _mixed.isDefined)(data[row][column])) {
|
512
|
+
data[row][column] = value;
|
513
|
+
}
|
514
|
+
this.overwriteInfo(config);
|
515
|
+
}
|
516
|
+
|
517
|
+
/**
|
518
|
+
* Gets header or cell values from the serialized dataset.
|
519
|
+
*
|
520
|
+
* Note: Used indexes refers to processed data, not to the instance of Handsontable. Please keep in mind that headers
|
521
|
+
* are handled separately from cells and they are recognised using negative indexes.
|
522
|
+
*
|
523
|
+
* @param {number} row Row index of cell which should be get.
|
524
|
+
* @param {number} column Column index of cell which should be get.
|
525
|
+
* @returns {undefined|string}
|
526
|
+
*/
|
527
|
+
getCellAt(row, column) {
|
528
|
+
if (this.isSerializedTable() === false) {
|
529
|
+
return;
|
530
|
+
}
|
531
|
+
const config = this.getMetaInfo();
|
532
|
+
const {
|
533
|
+
data,
|
534
|
+
nestedHeaders,
|
535
|
+
colHeaders
|
536
|
+
} = config;
|
537
|
+
if (row < 0) {
|
538
|
+
if (Array.isArray(nestedHeaders)) {
|
539
|
+
const rowRelative = row + nestedHeaders.length;
|
540
|
+
const nestedHeaderColumn = this.getNestedHeaderColumn(row, column);
|
541
|
+
if ((0, _mixed.isDefined)(nestedHeaderColumn) === false) {
|
542
|
+
return;
|
543
|
+
}
|
544
|
+
const header = nestedHeaders[rowRelative][nestedHeaderColumn];
|
545
|
+
if ((0, _object.isObject)(header)) {
|
546
|
+
return header.label;
|
547
|
+
}
|
548
|
+
return header;
|
549
|
+
} else if (Array.isArray(colHeaders)) {
|
550
|
+
if ((0, _mixed.isDefined)(colHeaders[column])) {
|
551
|
+
return colHeaders[column];
|
552
|
+
}
|
553
|
+
}
|
554
|
+
} else if (row >= 0 && Array.isArray(data) && Array.isArray(data[row]) && (0, _mixed.isDefined)(data[row][column])) {
|
555
|
+
return data[row][column];
|
556
|
+
}
|
557
|
+
}
|
558
|
+
|
559
|
+
/**
|
560
|
+
* Checks whether serialized data is an array.
|
561
|
+
*
|
562
|
+
* @private
|
563
|
+
* @returns {boolean}
|
564
|
+
*/
|
565
|
+
isSerializedTable() {
|
566
|
+
return true;
|
567
|
+
}
|
568
|
+
|
569
|
+
/**
|
570
|
+
* Checks whether serialized data is a Handsontable.
|
571
|
+
*
|
572
|
+
* @private
|
573
|
+
* @returns {boolean}
|
574
|
+
*/
|
575
|
+
isSerializedHandsontable() {
|
576
|
+
return true;
|
577
|
+
}
|
578
|
+
|
579
|
+
/**
|
580
|
+
* Gets source of the copied data.
|
581
|
+
*
|
582
|
+
* @returns {string}
|
583
|
+
*/
|
584
|
+
getType() {
|
585
|
+
return 'handsontable';
|
586
|
+
}
|
587
|
+
}
|
588
|
+
exports.ClipboardData = ClipboardData;
|