handsontable 14.0.0-next-c22ab6f-20231030 → 14.0.0-next-f88c253-20231106
Sign up to get free protection for your applications and to get access to all the features.
- package/base.js +2 -2
- package/base.mjs +2 -2
- package/dist/handsontable.css +8 -2
- package/dist/handsontable.full.css +8 -2
- package/dist/handsontable.full.js +2084 -3359
- package/dist/handsontable.full.min.css +3 -3
- package/dist/handsontable.full.min.js +59 -66
- package/dist/handsontable.js +2086 -3361
- package/dist/handsontable.min.css +3 -3
- package/dist/handsontable.min.js +16 -23
- package/helpers/mixed.js +2 -2
- package/helpers/mixed.mjs +2 -2
- package/package.json +1 -1
- package/pluginHooks.d.ts +6 -28
- package/pluginHooks.js +63 -117
- package/pluginHooks.mjs +63 -117
- package/plugins/copyPaste/clipboardData.js +18 -0
- package/plugins/copyPaste/clipboardData.mjs +14 -0
- package/plugins/copyPaste/copyPaste.js +92 -38
- package/plugins/copyPaste/copyPaste.mjs +94 -40
- package/plugins/copyPaste/pasteEvent.js +14 -0
- package/plugins/copyPaste/pasteEvent.mjs +9 -0
- package/plugins/mergeCells/mergeCells.js +14 -0
- package/plugins/mergeCells/mergeCells.mjs +14 -0
- package/plugins/nestedHeaders/nestedHeaders.js +22 -21
- package/plugins/nestedHeaders/nestedHeaders.mjs +22 -21
- package/utils/parseTable.js +83 -527
- package/utils/parseTable.mjs +82 -523
- package/plugins/copyPaste/clipboardData/clipboardData.js +0 -516
- package/plugins/copyPaste/clipboardData/clipboardData.mjs +0 -512
- 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
@@ -1,512 +0,0 @@
|
|
1
|
-
import "core-js/modules/es.error.cause.js";
|
2
|
-
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; }
|
3
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
4
|
-
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); }
|
5
|
-
import { isDefined } from "../../../helpers/mixed.mjs";
|
6
|
-
import { deepClone } from "../../../helpers/object.mjs";
|
7
|
-
import { toSingleLine } from "../../../helpers/templateLiteralTag.mjs";
|
8
|
-
import { warn } from "../../../helpers/console.mjs";
|
9
|
-
import { getDataWithHeadersByConfig, getHTMLFromConfig, htmlToGridSettings } from "../../../utils/parseTable.mjs";
|
10
|
-
export const META_HEAD = ['<meta name="generator" content="Handsontable"/>', '<style type="text/css">td{white-space:normal}br{mso-data-placement:same-cell}</style>'].join('');
|
11
|
-
|
12
|
-
/**
|
13
|
-
* Creates an object containing information about performed action: copy, cut (performing also copying) or paste.
|
14
|
-
*
|
15
|
-
* @private
|
16
|
-
*/
|
17
|
-
export class ClipboardData {
|
18
|
-
constructor() {
|
19
|
-
/**
|
20
|
-
* Sanitized data of "text/html" type inside the clipboard.
|
21
|
-
*
|
22
|
-
* @private
|
23
|
-
* @type {string}
|
24
|
-
*/
|
25
|
-
_defineProperty(this, "html", void 0);
|
26
|
-
/**
|
27
|
-
* Copied data stored as array of arrays.
|
28
|
-
*
|
29
|
-
* @private
|
30
|
-
* @type {string[][]}
|
31
|
-
*/
|
32
|
-
_defineProperty(this, "data", void 0);
|
33
|
-
if (this.constructor === ClipboardData) {
|
34
|
-
throw new Error('The `ClipboardData` is an abstract class and it can\'t be instantiated. Please use ' + '`CopyClipboardData` or `PasteClipboardData` classes instead.');
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
/**
|
39
|
-
* Gets copied data stored as array of arrays.
|
40
|
-
*
|
41
|
-
* @returns {string[][]}
|
42
|
-
*/
|
43
|
-
getData() {
|
44
|
-
return deepClone(this.data);
|
45
|
-
}
|
46
|
-
|
47
|
-
/**
|
48
|
-
* Gets meta information about copied data.
|
49
|
-
*
|
50
|
-
* @returns {object} Object containing `data`, `colHeaders`, `rowHeaders`, `nestedHeaders`, `mergeCells` keys and
|
51
|
-
* the corresponding values.
|
52
|
-
*/
|
53
|
-
getMetaInfo() {
|
54
|
-
return htmlToGridSettings(this.html);
|
55
|
-
}
|
56
|
-
|
57
|
-
/**
|
58
|
-
* Overwrite stored data basing on handled configuration.
|
59
|
-
*
|
60
|
-
* @private
|
61
|
-
* @param {object} config Configuration.
|
62
|
-
*/
|
63
|
-
overwriteInfo(config) {
|
64
|
-
this.html = [this.isSerializedHandsontable() ? META_HEAD : '', getHTMLFromConfig(config)].join('');
|
65
|
-
this.data = getDataWithHeadersByConfig(config);
|
66
|
-
}
|
67
|
-
|
68
|
-
/**
|
69
|
-
* Adjust information about merged cells after removing some columns.
|
70
|
-
*
|
71
|
-
* Note: Used indexes refers to processed data, not to the instance of Handsontable.
|
72
|
-
*
|
73
|
-
* @private
|
74
|
-
* @param {object} metaInfo Object containing `data`, `colHeaders`, `rowHeaders`, `nestedHeaders`, `mergeCells`
|
75
|
-
* keys and the corresponding values, which will be changed by the reference.
|
76
|
-
* @param {number[]} removedColumns List of column indexes which should be excluded when creating copy/cut/paste data.
|
77
|
-
*/
|
78
|
-
adjustAfterColumnsRemoval(metaInfo, removedColumns) {
|
79
|
-
const mergedCells = metaInfo.mergeCells;
|
80
|
-
if (isDefined(mergedCells) === false) {
|
81
|
-
return;
|
82
|
-
}
|
83
|
-
metaInfo.mergeCells = mergedCells.reduce((filteredNestedCells, mergeArea) => {
|
84
|
-
const {
|
85
|
-
col: mergeStartColumn,
|
86
|
-
colspan
|
87
|
-
} = mergeArea;
|
88
|
-
const removedMergedColumns = removedColumns.filter(column => column >= mergeStartColumn && column < mergeStartColumn + colspan);
|
89
|
-
const removedMergedColumnsLength = removedMergedColumns.length;
|
90
|
-
if (removedMergedColumnsLength === colspan) {
|
91
|
-
return filteredNestedCells;
|
92
|
-
} else if (colspan - removedMergedColumnsLength === 1) {
|
93
|
-
delete mergeArea.colspan;
|
94
|
-
} else if (removedMergedColumnsLength > 0) {
|
95
|
-
mergeArea.colspan = colspan - removedMergedColumnsLength;
|
96
|
-
}
|
97
|
-
if (Number.isInteger(mergeArea.rowspan) || Number.isInteger(mergeArea.colspan)) {
|
98
|
-
return filteredNestedCells.concat(mergeArea);
|
99
|
-
}
|
100
|
-
return filteredNestedCells;
|
101
|
-
}, []);
|
102
|
-
metaInfo.mergeCells.forEach(mergeArea => {
|
103
|
-
const shiftedColumns = removedColumns.filter(column => column < mergeArea.col);
|
104
|
-
const shifterColumnsLength = shiftedColumns.length;
|
105
|
-
mergeArea.col = mergeArea.col - shifterColumnsLength;
|
106
|
-
});
|
107
|
-
if (metaInfo.mergeCells.length === 0) {
|
108
|
-
delete metaInfo.mergeCells;
|
109
|
-
}
|
110
|
-
}
|
111
|
-
|
112
|
-
/**
|
113
|
-
* Adjust information about merged cells after removing some rows.
|
114
|
-
*
|
115
|
-
* Note: Used indexes refers to processed data, not to the instance of Handsontable.
|
116
|
-
*
|
117
|
-
* @private
|
118
|
-
* @param {object} metaInfo Object containing `data`, `colHeaders`, `rowHeaders`, `nestedHeaders`, `mergeCells`
|
119
|
-
* keys and the corresponding values, which will be changed by the reference.
|
120
|
-
* @param {number[]} removedRows List of row indexes which should be excluded when creating copy/cut/paste data.
|
121
|
-
*/
|
122
|
-
adjustAfterRowRemoval(metaInfo, removedRows) {
|
123
|
-
const mergedCells = metaInfo.mergeCells;
|
124
|
-
if (isDefined(mergedCells) === false) {
|
125
|
-
return;
|
126
|
-
}
|
127
|
-
metaInfo.mergeCells = mergedCells.reduce((filteredNestedCells, mergeArea) => {
|
128
|
-
const {
|
129
|
-
row: mergeStartRow,
|
130
|
-
rowspan
|
131
|
-
} = mergeArea;
|
132
|
-
const removedMergedRows = removedRows.filter(row => row >= mergeStartRow && row < mergeStartRow + rowspan);
|
133
|
-
const removedMergedRowsLength = removedMergedRows.length;
|
134
|
-
if (removedMergedRowsLength === rowspan) {
|
135
|
-
return filteredNestedCells;
|
136
|
-
} else if (rowspan - removedMergedRowsLength === 1) {
|
137
|
-
delete mergeArea.rowspan;
|
138
|
-
} else if (removedMergedRowsLength > 0) {
|
139
|
-
mergeArea.rowspan = rowspan - removedMergedRowsLength;
|
140
|
-
}
|
141
|
-
if (Number.isInteger(mergeArea.rowspan) || Number.isInteger(mergeArea.colspan)) {
|
142
|
-
return filteredNestedCells.concat(mergeArea);
|
143
|
-
}
|
144
|
-
return filteredNestedCells;
|
145
|
-
}, []);
|
146
|
-
metaInfo.mergeCells.forEach(mergeArea => {
|
147
|
-
const shiftedRows = removedRows.filter(row => row < mergeArea.row);
|
148
|
-
const shifterRowsLength = shiftedRows.length;
|
149
|
-
mergeArea.row = mergeArea.row - shifterRowsLength;
|
150
|
-
});
|
151
|
-
if (metaInfo.mergeCells.length === 0) {
|
152
|
-
delete metaInfo.mergeCells;
|
153
|
-
}
|
154
|
-
}
|
155
|
-
|
156
|
-
/**
|
157
|
-
* Remove rows from the serialized dataset.
|
158
|
-
*
|
159
|
-
* Note: Used indexes refers to processed data, not to the instance of Handsontable. Please keep in mind that headers
|
160
|
-
* are handled separately from cells and they are recognised using negative indexes.
|
161
|
-
*
|
162
|
-
* @param {number[]} rows List of row indexes which should be excluded when creating copy/cut/paste data.
|
163
|
-
*/
|
164
|
-
removeRows(rows) {
|
165
|
-
if (this.isSerializedTable() === false) {
|
166
|
-
return;
|
167
|
-
}
|
168
|
-
const metaInfo = this.getMetaInfo();
|
169
|
-
this.adjustAfterRowRemoval(metaInfo, rows);
|
170
|
-
const config = {
|
171
|
-
...metaInfo,
|
172
|
-
excludedRows: rows
|
173
|
-
};
|
174
|
-
this.overwriteInfo(config);
|
175
|
-
}
|
176
|
-
|
177
|
-
/**
|
178
|
-
* Remove columns 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[]} columns List of column indexes which should be excluded when creating copy/cut/paste data.
|
184
|
-
*/
|
185
|
-
removeColumns(columns) {
|
186
|
-
if (this.isSerializedTable() === false) {
|
187
|
-
return;
|
188
|
-
}
|
189
|
-
const metaInfo = this.getMetaInfo();
|
190
|
-
const {
|
191
|
-
nestedHeaders,
|
192
|
-
colHeaders
|
193
|
-
} = metaInfo;
|
194
|
-
if (Array.isArray(nestedHeaders) && columns.length > 0) {
|
195
|
-
warn('It\'s not possible to modify copied dataset containing nested headers.');
|
196
|
-
return;
|
197
|
-
}
|
198
|
-
if (Array.isArray(colHeaders) && columns.length > 0) {
|
199
|
-
metaInfo.colHeaders = colHeaders.filter(columnIndex => columns.includes(columnIndex) === false);
|
200
|
-
}
|
201
|
-
this.adjustAfterColumnsRemoval(metaInfo, columns);
|
202
|
-
const config = {
|
203
|
-
...metaInfo,
|
204
|
-
excludedColumns: columns
|
205
|
-
};
|
206
|
-
this.overwriteInfo(config);
|
207
|
-
}
|
208
|
-
|
209
|
-
/**
|
210
|
-
* Get warning message when there is some problem with row insertion or undefined otherwise.
|
211
|
-
*
|
212
|
-
* @private
|
213
|
-
* @param {number} rowIndex An index of the row at which the new values will be inserted.
|
214
|
-
* @param {string[]} values List of values.
|
215
|
-
* @returns {undefined|string}
|
216
|
-
*/
|
217
|
-
getRowInsertionWarn(rowIndex, values) {
|
218
|
-
const metaInfo = this.getMetaInfo();
|
219
|
-
const data = metaInfo.data;
|
220
|
-
const insertedElementsCount = values.length;
|
221
|
-
if (Array.isArray(data) === false) {
|
222
|
-
const {
|
223
|
-
nestedHeaders,
|
224
|
-
colHeaders
|
225
|
-
} = metaInfo;
|
226
|
-
if (rowIndex > 0) {
|
227
|
-
return toSingleLine`Invalid row insertion done inside some \`CopyPaste\` hook. There is no possibility to\x20
|
228
|
-
expand an empty dataset at position higher than zero.`;
|
229
|
-
}
|
230
|
-
if (Array.isArray(nestedHeaders) && nestedHeaders[0].length !== insertedElementsCount || Array.isArray(colHeaders) && colHeaders.length !== insertedElementsCount) {
|
231
|
-
return toSingleLine`Invalid row insertion done inside some \`CopyPaste\` hook. Please provide proper number\x20
|
232
|
-
of elements (corresponding to size of the dataset in other rows) for inserted rows.`;
|
233
|
-
}
|
234
|
-
return;
|
235
|
-
}
|
236
|
-
const numberOfRows = data.length;
|
237
|
-
const numberOfColumns = data[0].length;
|
238
|
-
if (rowIndex > numberOfRows) {
|
239
|
-
return toSingleLine`Invalid row insertion done inside some \`CopyPaste\` hook. Please provide an valid row\x20
|
240
|
-
index (not too high) for row data insertion.`;
|
241
|
-
}
|
242
|
-
if (numberOfColumns !== insertedElementsCount) {
|
243
|
-
return toSingleLine`Invalid row insertion done inside some \`CopyPaste\` hook. Please provide proper number of\x20
|
244
|
-
elements (corresponding to size of the dataset in other rows) for inserted rows.`;
|
245
|
-
}
|
246
|
-
}
|
247
|
-
|
248
|
-
/**
|
249
|
-
* Adjust information about merged cells after row insertion.
|
250
|
-
*
|
251
|
-
* Note: Used index refers to processed data, not to the instance of Handsontable.
|
252
|
-
*
|
253
|
-
* @private
|
254
|
-
* @param {object} metaInfo Object containing `data`, `colHeaders`, `rowHeaders`, `nestedHeaders`, `mergeCells`
|
255
|
-
* keys and the corresponding values, which will be changed by the reference.
|
256
|
-
* @param {number} rowIndex An index of the row at which the new values have been inserted.
|
257
|
-
*/
|
258
|
-
adjustAfterRowInsertion(metaInfo, rowIndex) {
|
259
|
-
const {
|
260
|
-
mergeCells: mergedCells,
|
261
|
-
data
|
262
|
-
} = metaInfo;
|
263
|
-
mergedCells === null || mergedCells === void 0 || mergedCells.forEach(mergeArea => {
|
264
|
-
const {
|
265
|
-
row: mergeStartRow,
|
266
|
-
col: mergeStartColumn,
|
267
|
-
rowspan,
|
268
|
-
colspan
|
269
|
-
} = mergeArea;
|
270
|
-
if (rowIndex > mergeStartRow && rowIndex < mergeStartRow + rowspan) {
|
271
|
-
mergeArea.rowspan += 1;
|
272
|
-
for (let i = 0; i < colspan; i += 1) {
|
273
|
-
data[rowIndex][mergeStartColumn + i] = '';
|
274
|
-
}
|
275
|
-
}
|
276
|
-
});
|
277
|
-
mergedCells === null || mergedCells === void 0 || mergedCells.forEach(mergeArea => {
|
278
|
-
if (rowIndex <= mergeArea.row) {
|
279
|
-
mergeArea.row += 1;
|
280
|
-
}
|
281
|
-
});
|
282
|
-
}
|
283
|
-
|
284
|
-
/**
|
285
|
-
* Insert values at row index.
|
286
|
-
*
|
287
|
-
* Note: Used index refers to processed data, not to the instance of Handsontable.
|
288
|
-
*
|
289
|
-
* @param {number} rowIndex An index of the row at which the new values will be inserted.
|
290
|
-
* @param {string[]} values List of values.
|
291
|
-
*/
|
292
|
-
insertAtRow(rowIndex, values) {
|
293
|
-
if (this.isSerializedTable() === false) {
|
294
|
-
return;
|
295
|
-
}
|
296
|
-
const metaInfo = this.getMetaInfo();
|
297
|
-
const data = metaInfo.data || [];
|
298
|
-
const rowInsertionWarn = this.getRowInsertionWarn(rowIndex, values);
|
299
|
-
if (isDefined(rowInsertionWarn)) {
|
300
|
-
warn(rowInsertionWarn);
|
301
|
-
return;
|
302
|
-
}
|
303
|
-
metaInfo.data = [...data.slice(0, rowIndex), values, ...data.slice(rowIndex)];
|
304
|
-
this.adjustAfterRowInsertion(metaInfo, rowIndex);
|
305
|
-
this.overwriteInfo(metaInfo);
|
306
|
-
}
|
307
|
-
|
308
|
-
/**
|
309
|
-
* Get warning message when there is some problem with row insertion or undefined otherwise.
|
310
|
-
*
|
311
|
-
* @private
|
312
|
-
* @param {number} columnIndex An index of the column at which the new values will be inserted or removed.
|
313
|
-
* @param {string[]} values List of values.
|
314
|
-
* @returns {undefined|string}
|
315
|
-
*/
|
316
|
-
getColumnInsertionWarn(columnIndex, values) {
|
317
|
-
const {
|
318
|
-
nestedHeaders,
|
319
|
-
data,
|
320
|
-
colHeaders
|
321
|
-
} = this.getMetaInfo();
|
322
|
-
const headerLevels = isDefined(colHeaders) ? 1 : 0;
|
323
|
-
if (Array.isArray(nestedHeaders)) {
|
324
|
-
return toSingleLine`Invalid column insertion done inside some \`CopyPaste\` hook. It's not possible to modify\x20
|
325
|
-
copied dataset containing nested headers`;
|
326
|
-
}
|
327
|
-
if (Array.isArray(data) === false) {
|
328
|
-
return;
|
329
|
-
}
|
330
|
-
const numberOfRows = data.length + headerLevels;
|
331
|
-
const numberOfColumns = data[0].length;
|
332
|
-
if (columnIndex > numberOfColumns) {
|
333
|
-
return toSingleLine`Invalid column insertion done inside some \`CopyPaste\` hook. Please provide an valid\x20
|
334
|
-
column index (not too high) for column data insertion.`;
|
335
|
-
}
|
336
|
-
if (values.length !== numberOfRows) {
|
337
|
-
return toSingleLine`Invalid column insertion done inside some \`CopyPaste\` hook. Please provide proper number\x20
|
338
|
-
of elements (corresponding to size of the dataset in other columns, including headers) for inserted columns.`;
|
339
|
-
}
|
340
|
-
}
|
341
|
-
|
342
|
-
/**
|
343
|
-
* Adjust information about merged cells after column insertion.
|
344
|
-
*
|
345
|
-
* Note: Used index refers to processed data, not to the instance of Handsontable.
|
346
|
-
*
|
347
|
-
* @private
|
348
|
-
* @param {object} metaInfo Object containing `data`, `colHeaders`, `rowHeaders`, `nestedHeaders`, `mergeCells`
|
349
|
-
* keys and the corresponding values, which will be changed by the reference.
|
350
|
-
* @param {number} columnIndex An index of the column at which the new values have been inserted.
|
351
|
-
*/
|
352
|
-
adjustAfterColumnInsertion(metaInfo, columnIndex) {
|
353
|
-
const {
|
354
|
-
mergeCells: mergedCells,
|
355
|
-
data
|
356
|
-
} = metaInfo;
|
357
|
-
mergedCells === null || mergedCells === void 0 || mergedCells.forEach(mergeArea => {
|
358
|
-
const {
|
359
|
-
row: mergeStartRow,
|
360
|
-
col: mergeStartColumn,
|
361
|
-
colspan,
|
362
|
-
rowspan
|
363
|
-
} = mergeArea;
|
364
|
-
if (columnIndex > mergeStartColumn && columnIndex < mergeStartColumn + colspan) {
|
365
|
-
mergeArea.colspan += 1;
|
366
|
-
for (let i = 0; i < rowspan; i += 1) {
|
367
|
-
data[mergeStartRow + i][columnIndex] = '';
|
368
|
-
}
|
369
|
-
}
|
370
|
-
});
|
371
|
-
mergedCells === null || mergedCells === void 0 || mergedCells.forEach(mergeArea => {
|
372
|
-
if (columnIndex <= mergeArea.col) {
|
373
|
-
mergeArea.col += 1;
|
374
|
-
}
|
375
|
-
});
|
376
|
-
}
|
377
|
-
|
378
|
-
/**
|
379
|
-
* Insert values at column index.
|
380
|
-
*
|
381
|
-
* Note: Used index refers to processed data, not to the instance of Handsontable.
|
382
|
-
*
|
383
|
-
* @param {number} columnIndex An index of the column at which the new values will be inserted or removed.
|
384
|
-
* @param {string[]} values List of values.
|
385
|
-
*/
|
386
|
-
insertAtColumn(columnIndex, values) {
|
387
|
-
if (this.isSerializedTable() === false) {
|
388
|
-
return;
|
389
|
-
}
|
390
|
-
const metaInfo = this.getMetaInfo();
|
391
|
-
const {
|
392
|
-
data,
|
393
|
-
colHeaders
|
394
|
-
} = metaInfo;
|
395
|
-
const headerLevels = isDefined(colHeaders) ? 1 : 0;
|
396
|
-
const columnInsertionWarn = this.getColumnInsertionWarn(columnIndex, values);
|
397
|
-
if (isDefined(columnInsertionWarn)) {
|
398
|
-
warn(columnInsertionWarn);
|
399
|
-
return;
|
400
|
-
}
|
401
|
-
if (headerLevels > 0) {
|
402
|
-
colHeaders.splice(columnIndex, 0, values[0]);
|
403
|
-
}
|
404
|
-
data === null || data === void 0 || data.forEach((rowData, rowIndex) => {
|
405
|
-
rowData.splice(columnIndex, 0, values[rowIndex + headerLevels]);
|
406
|
-
});
|
407
|
-
this.adjustAfterColumnInsertion(metaInfo, columnIndex);
|
408
|
-
this.overwriteInfo(metaInfo);
|
409
|
-
}
|
410
|
-
|
411
|
-
/**
|
412
|
-
* Change headers or cells in the serialized dataset.
|
413
|
-
*
|
414
|
-
* Note: Used indexes refers to processed data, not to the instance of Handsontable. Please keep in mind that headers
|
415
|
-
* are handled separately from cells and they are recognised using negative indexes.
|
416
|
-
*
|
417
|
-
* @param {number} row Row index of cell which should be changed.
|
418
|
-
* @param {number} column Column index of cell which should be changed.
|
419
|
-
* @param {string} value Value for particular indexes.
|
420
|
-
*/
|
421
|
-
setCellAt(row, column, value) {
|
422
|
-
if (this.isSerializedTable() === false) {
|
423
|
-
return;
|
424
|
-
}
|
425
|
-
const config = this.getMetaInfo();
|
426
|
-
const {
|
427
|
-
data,
|
428
|
-
nestedHeaders,
|
429
|
-
colHeaders
|
430
|
-
} = config;
|
431
|
-
if (row < 0) {
|
432
|
-
if (Array.isArray(nestedHeaders)) {
|
433
|
-
const rowRelative = row + nestedHeaders.length;
|
434
|
-
if (Array.isArray(nestedHeaders[rowRelative]) && isDefined(nestedHeaders[rowRelative][column])) {
|
435
|
-
nestedHeaders[rowRelative][column] = value;
|
436
|
-
}
|
437
|
-
} else if (Array.isArray(colHeaders)) {
|
438
|
-
if (isDefined(colHeaders[column])) {
|
439
|
-
colHeaders[column] = value;
|
440
|
-
}
|
441
|
-
}
|
442
|
-
} else if (row >= 0 && Array.isArray(data) && Array.isArray(data[row]) && isDefined(data[row][column])) {
|
443
|
-
data[row][column] = value;
|
444
|
-
}
|
445
|
-
this.overwriteInfo(config);
|
446
|
-
}
|
447
|
-
|
448
|
-
/**
|
449
|
-
* Gets header or cell values from the serialized dataset.
|
450
|
-
*
|
451
|
-
* Note: Used indexes refers to processed data, not to the instance of Handsontable. Please keep in mind that headers
|
452
|
-
* are handled separately from cells and they are recognised using negative indexes.
|
453
|
-
*
|
454
|
-
* @param {number} row Row index of cell which should be get.
|
455
|
-
* @param {number} column Column index of cell which should be get.
|
456
|
-
* @returns {undefined|string}
|
457
|
-
*/
|
458
|
-
getCellAt(row, column) {
|
459
|
-
if (this.isSerializedTable() === false) {
|
460
|
-
return;
|
461
|
-
}
|
462
|
-
const config = this.getMetaInfo();
|
463
|
-
const {
|
464
|
-
data,
|
465
|
-
nestedHeaders,
|
466
|
-
colHeaders
|
467
|
-
} = config;
|
468
|
-
if (row < 0) {
|
469
|
-
if (Array.isArray(nestedHeaders)) {
|
470
|
-
const rowRelative = row + nestedHeaders.length;
|
471
|
-
if (Array.isArray(nestedHeaders[rowRelative]) && isDefined(nestedHeaders[rowRelative][column])) {
|
472
|
-
return nestedHeaders[rowRelative][column];
|
473
|
-
}
|
474
|
-
} else if (Array.isArray(colHeaders)) {
|
475
|
-
if (isDefined(colHeaders[column])) {
|
476
|
-
return colHeaders[column];
|
477
|
-
}
|
478
|
-
}
|
479
|
-
} else if (row >= 0 && Array.isArray(data) && Array.isArray(data[row]) && isDefined(data[row][column])) {
|
480
|
-
return data[row][column];
|
481
|
-
}
|
482
|
-
}
|
483
|
-
|
484
|
-
/**
|
485
|
-
* Checks whether serialized data is an array.
|
486
|
-
*
|
487
|
-
* @private
|
488
|
-
* @returns {boolean}
|
489
|
-
*/
|
490
|
-
isSerializedTable() {
|
491
|
-
return true;
|
492
|
-
}
|
493
|
-
|
494
|
-
/**
|
495
|
-
* Checks whether serialized data is a Handsontable.
|
496
|
-
*
|
497
|
-
* @private
|
498
|
-
* @returns {boolean}
|
499
|
-
*/
|
500
|
-
isSerializedHandsontable() {
|
501
|
-
return true;
|
502
|
-
}
|
503
|
-
|
504
|
-
/**
|
505
|
-
* Gets source of the copied data.
|
506
|
-
*
|
507
|
-
* @returns {string}
|
508
|
-
*/
|
509
|
-
getType() {
|
510
|
-
return 'handsontable';
|
511
|
-
}
|
512
|
-
}
|
@@ -1,69 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
exports.__esModule = true;
|
4
|
-
require("core-js/modules/es.error.cause.js");
|
5
|
-
var _clipboardData = require("./clipboardData");
|
6
|
-
var _copyableRanges = require("../copyableRanges");
|
7
|
-
var _parseTable = require("../../../utils/parseTable");
|
8
|
-
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; }
|
9
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
10
|
-
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); }
|
11
|
-
/**
|
12
|
-
* Creates an object containing information about copy/cut action.
|
13
|
-
*
|
14
|
-
* @private
|
15
|
-
*/
|
16
|
-
class CopyClipboardData extends _clipboardData.ClipboardData {
|
17
|
-
/**
|
18
|
-
* @param {Core} instance Handsontable instance (used only while copying data).
|
19
|
-
* @param {Array<{startRow: number, startCol: number, endRow: number, endCol: number}>} copyableRanges Cell
|
20
|
-
* ranges related to instance of Handsontable (used only while copying data).
|
21
|
-
*/
|
22
|
-
constructor(instance, copyableRanges) {
|
23
|
-
super();
|
24
|
-
/**
|
25
|
-
* Sanitized data of "text/html" type inside the clipboard.
|
26
|
-
*
|
27
|
-
* @private
|
28
|
-
* @type {string}
|
29
|
-
*/
|
30
|
-
_defineProperty(this, "html", void 0);
|
31
|
-
/**
|
32
|
-
* Copied data stored as array of arrays.
|
33
|
-
*
|
34
|
-
* @private
|
35
|
-
* @type {string[][]}
|
36
|
-
*/
|
37
|
-
_defineProperty(this, "data", void 0);
|
38
|
-
/**
|
39
|
-
* Copied cell ranges related to instance of Handsontable.
|
40
|
-
*
|
41
|
-
* @private
|
42
|
-
* @type {Array<{startRow: number, startCol: number, endRow: number, endCol: number}>}
|
43
|
-
*/
|
44
|
-
_defineProperty(this, "copyableRanges", void 0);
|
45
|
-
const {
|
46
|
-
rows,
|
47
|
-
columns
|
48
|
-
} = (0, _copyableRanges.normalizeRanges)(copyableRanges);
|
49
|
-
this.html = [_clipboardData.META_HEAD, (0, _parseTable.getHTMLByCoords)(instance, {
|
50
|
-
rows,
|
51
|
-
columns
|
52
|
-
})].join('');
|
53
|
-
this.data = (0, _parseTable.getDataByCoords)(instance, {
|
54
|
-
rows,
|
55
|
-
columns
|
56
|
-
});
|
57
|
-
this.copyableRanges = copyableRanges;
|
58
|
-
}
|
59
|
-
|
60
|
-
/**
|
61
|
-
* Gets ranges related to copied part of Handsontable.
|
62
|
-
*
|
63
|
-
* @returns {Array<{startRow: number, startCol: number, endRow: number, endCol: number}>}
|
64
|
-
*/
|
65
|
-
getRanges() {
|
66
|
-
return this.copyableRanges;
|
67
|
-
}
|
68
|
-
}
|
69
|
-
exports.CopyClipboardData = CopyClipboardData;
|
@@ -1,65 +0,0 @@
|
|
1
|
-
import "core-js/modules/es.error.cause.js";
|
2
|
-
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; }
|
3
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
4
|
-
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); }
|
5
|
-
import { META_HEAD, ClipboardData } from "./clipboardData.mjs";
|
6
|
-
import { normalizeRanges } from "../copyableRanges.mjs";
|
7
|
-
import { getDataByCoords, getHTMLByCoords } from "../../../utils/parseTable.mjs";
|
8
|
-
/**
|
9
|
-
* Creates an object containing information about copy/cut action.
|
10
|
-
*
|
11
|
-
* @private
|
12
|
-
*/
|
13
|
-
export class CopyClipboardData extends ClipboardData {
|
14
|
-
/**
|
15
|
-
* @param {Core} instance Handsontable instance (used only while copying data).
|
16
|
-
* @param {Array<{startRow: number, startCol: number, endRow: number, endCol: number}>} copyableRanges Cell
|
17
|
-
* ranges related to instance of Handsontable (used only while copying data).
|
18
|
-
*/
|
19
|
-
constructor(instance, copyableRanges) {
|
20
|
-
super();
|
21
|
-
/**
|
22
|
-
* Sanitized data of "text/html" type inside the clipboard.
|
23
|
-
*
|
24
|
-
* @private
|
25
|
-
* @type {string}
|
26
|
-
*/
|
27
|
-
_defineProperty(this, "html", void 0);
|
28
|
-
/**
|
29
|
-
* Copied data stored as array of arrays.
|
30
|
-
*
|
31
|
-
* @private
|
32
|
-
* @type {string[][]}
|
33
|
-
*/
|
34
|
-
_defineProperty(this, "data", void 0);
|
35
|
-
/**
|
36
|
-
* Copied cell ranges related to instance of Handsontable.
|
37
|
-
*
|
38
|
-
* @private
|
39
|
-
* @type {Array<{startRow: number, startCol: number, endRow: number, endCol: number}>}
|
40
|
-
*/
|
41
|
-
_defineProperty(this, "copyableRanges", void 0);
|
42
|
-
const {
|
43
|
-
rows,
|
44
|
-
columns
|
45
|
-
} = normalizeRanges(copyableRanges);
|
46
|
-
this.html = [META_HEAD, getHTMLByCoords(instance, {
|
47
|
-
rows,
|
48
|
-
columns
|
49
|
-
})].join('');
|
50
|
-
this.data = getDataByCoords(instance, {
|
51
|
-
rows,
|
52
|
-
columns
|
53
|
-
});
|
54
|
-
this.copyableRanges = copyableRanges;
|
55
|
-
}
|
56
|
-
|
57
|
-
/**
|
58
|
-
* Gets ranges related to copied part of Handsontable.
|
59
|
-
*
|
60
|
-
* @returns {Array<{startRow: number, startCol: number, endRow: number, endCol: number}>}
|
61
|
-
*/
|
62
|
-
getRanges() {
|
63
|
-
return this.copyableRanges;
|
64
|
-
}
|
65
|
-
}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
exports.__esModule = true;
|
4
|
-
var _copyClipboardData = require("./copyClipboardData");
|
5
|
-
exports.CopyClipboardData = _copyClipboardData.CopyClipboardData;
|
6
|
-
var _pasteClipboardData = require("./pasteClipboardData");
|
7
|
-
exports.PasteClipboardData = _pasteClipboardData.PasteClipboardData;
|
8
|
-
var _clipboardData = require("./clipboardData");
|
9
|
-
exports.META_HEAD = _clipboardData.META_HEAD;
|