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