@visactor/vtable 1.22.6-alpha.3 → 1.22.7-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/cjs/PivotChart.js +2 -2
  2. package/cjs/PivotChart.js.map +1 -1
  3. package/cjs/core/BaseTable.d.ts +3 -3
  4. package/cjs/core/BaseTable.js +7 -7
  5. package/cjs/core/BaseTable.js.map +1 -1
  6. package/cjs/dataset/dataset.js +2 -1
  7. package/cjs/dataset/dataset.js.map +1 -1
  8. package/cjs/event/event.d.ts +9 -0
  9. package/cjs/event/event.js +158 -84
  10. package/cjs/event/event.js.map +1 -1
  11. package/cjs/event/util.d.ts +1 -0
  12. package/cjs/event/util.js +13 -2
  13. package/cjs/event/util.js.map +1 -1
  14. package/cjs/index.d.ts +1 -1
  15. package/cjs/index.js +1 -1
  16. package/cjs/index.js.map +1 -1
  17. package/cjs/layout/chart-helper/get-axis-config.js +7 -1
  18. package/cjs/layout/chart-helper/get-axis-config.js.map +1 -1
  19. package/cjs/layout/pivot-header-layout.js +5 -3
  20. package/cjs/layout/pivot-header-layout.js.map +1 -1
  21. package/cjs/scenegraph/graphic/active-cell-chart-list.js +62 -44
  22. package/cjs/scenegraph/graphic/active-cell-chart-list.js.map +1 -1
  23. package/cjs/scenegraph/graphic/chart.js +14 -3
  24. package/cjs/scenegraph/graphic/chart.js.map +1 -1
  25. package/cjs/scenegraph/graphic/contributions/chart-render-helper.js +2 -1
  26. package/cjs/scenegraph/graphic/contributions/chart-render-helper.js.map +1 -1
  27. package/cjs/scenegraph/graphic/contributions/chart-render.js +1 -1
  28. package/cjs/scenegraph/graphic/contributions/chart-render.js.map +1 -1
  29. package/cjs/ts-types/base-table.d.ts +3 -3
  30. package/cjs/ts-types/base-table.js.map +1 -1
  31. package/cjs/ts-types/table-engine.d.ts +7 -2
  32. package/cjs/ts-types/table-engine.js.map +1 -1
  33. package/cjs/vrender.js.map +1 -1
  34. package/dist/vtable.js +456 -256
  35. package/dist/vtable.min.js +2 -2
  36. package/es/PivotChart.js +2 -2
  37. package/es/PivotChart.js.map +1 -1
  38. package/es/core/BaseTable.d.ts +3 -3
  39. package/es/core/BaseTable.js +7 -7
  40. package/es/core/BaseTable.js.map +1 -1
  41. package/es/dataset/dataset.js +1 -1
  42. package/es/dataset/dataset.js.map +1 -1
  43. package/es/event/event.d.ts +9 -0
  44. package/es/event/event.js +158 -84
  45. package/es/event/event.js.map +1 -1
  46. package/es/event/util.d.ts +1 -0
  47. package/es/event/util.js +11 -0
  48. package/es/event/util.js.map +1 -1
  49. package/es/index.d.ts +1 -1
  50. package/es/index.js +1 -1
  51. package/es/index.js.map +1 -1
  52. package/es/layout/chart-helper/get-axis-config.js +7 -1
  53. package/es/layout/chart-helper/get-axis-config.js.map +1 -1
  54. package/es/layout/pivot-header-layout.js +5 -3
  55. package/es/layout/pivot-header-layout.js.map +1 -1
  56. package/es/scenegraph/graphic/active-cell-chart-list.js +62 -44
  57. package/es/scenegraph/graphic/active-cell-chart-list.js.map +1 -1
  58. package/es/scenegraph/graphic/chart.js +14 -3
  59. package/es/scenegraph/graphic/chart.js.map +1 -1
  60. package/es/scenegraph/graphic/contributions/chart-render-helper.js +2 -1
  61. package/es/scenegraph/graphic/contributions/chart-render-helper.js.map +1 -1
  62. package/es/scenegraph/graphic/contributions/chart-render.js +1 -1
  63. package/es/scenegraph/graphic/contributions/chart-render.js.map +1 -1
  64. package/es/ts-types/base-table.d.ts +3 -3
  65. package/es/ts-types/base-table.js.map +1 -1
  66. package/es/ts-types/table-engine.d.ts +7 -2
  67. package/es/ts-types/table-engine.js.map +1 -1
  68. package/es/vrender.js.map +1 -1
  69. package/package.json +5 -5
@@ -43,6 +43,10 @@ export declare class EventManager {
43
43
  private cutOperationTime;
44
44
  lastClipboardContent: string;
45
45
  cutCellRange: CellInfo[][] | null;
46
+ copySourceRange: {
47
+ startCol: number;
48
+ startRow: number;
49
+ } | null;
46
50
  constructor(table: BaseTableAPI);
47
51
  bindOuterEvent(): void;
48
52
  updateEventBinder(): void;
@@ -68,14 +72,19 @@ export declare class EventManager {
68
72
  enableScroll(): void;
69
73
  disableScroll(): void;
70
74
  handleCopy(e: KeyboardEvent, isCut?: boolean): Promise<void>;
75
+ private fallbackCopyToClipboard;
71
76
  handleCut(e: KeyboardEvent): Promise<void>;
72
77
  handlePaste(e: KeyboardEvent): void;
73
78
  private executePaste;
79
+ private fallbackPasteFromClipboard;
80
+ private processPastedText;
74
81
  private clearCutArea;
75
82
  private checkClipboardChanged;
76
83
  private saveClipboardContent;
77
84
  private pasteHtmlToTable;
78
85
  private _pasteValue;
79
86
  private pasteTextToTable;
87
+ private parsePastedData;
88
+ private processCellValue;
80
89
  private handlePasteValues;
81
90
  }
@@ -30,14 +30,15 @@ Object.defineProperty(exports, "__esModule", {
30
30
  value: !0
31
31
  }), exports.EventManager = void 0;
32
32
 
33
- const vrender_1 = require("./../vrender"), TABLE_EVENT_TYPE_1 = require("../core/TABLE_EVENT_TYPE"), media_click_1 = require("./media-click"), drill_1 = require("./drill"), sparkline_event_1 = require("./sparkline-event"), stick_text_1 = require("../scenegraph/stick-text"), table_group_1 = require("./listener/table-group"), scroll_bar_1 = require("./listener/scroll-bar"), container_dom_1 = require("./listener/container-dom"), touch_1 = require("./listener/touch"), axis_click_1 = require("./self-event-listener/pivot-chart/axis-click"), axis_hover_1 = require("./self-event-listener/pivot-chart/axis-hover"), env_1 = require("../tools/env"), vutils_1 = require("@visactor/vutils"), scroll_1 = require("./scroll"), is_cell_select_highlight_1 = require("../state/select/is-cell-select-highlight"), checkbox_1 = require("./self-event-listener/list-table/checkbox"), button_1 = require("./component/button"), icon_1 = require("./self-event-listener/base-table/icon"), dropdown_menu_1 = require("./self-event-listener/base-table/dropdown-menu"), dbclick_auto_column_width_1 = require("./self-event-listener/base-table/dbclick-auto-column-width"), helper_1 = require("../tools/helper"), style_1 = require("../tools/style");
33
+ const vrender_1 = require("./../vrender"), TABLE_EVENT_TYPE_1 = require("../core/TABLE_EVENT_TYPE"), media_click_1 = require("./media-click"), drill_1 = require("./drill"), sparkline_event_1 = require("./sparkline-event"), stick_text_1 = require("../scenegraph/stick-text"), table_group_1 = require("./listener/table-group"), scroll_bar_1 = require("./listener/scroll-bar"), container_dom_1 = require("./listener/container-dom"), touch_1 = require("./listener/touch"), util_1 = require("./util"), axis_click_1 = require("./self-event-listener/pivot-chart/axis-click"), axis_hover_1 = require("./self-event-listener/pivot-chart/axis-hover"), env_1 = require("../tools/env"), vutils_1 = require("@visactor/vutils"), scroll_1 = require("./scroll"), is_cell_select_highlight_1 = require("../state/select/is-cell-select-highlight"), checkbox_1 = require("./self-event-listener/list-table/checkbox"), button_1 = require("./component/button"), icon_1 = require("./self-event-listener/base-table/icon"), dropdown_menu_1 = require("./self-event-listener/base-table/dropdown-menu"), dbclick_auto_column_width_1 = require("./self-event-listener/base-table/dbclick-auto-column-width"), style_1 = require("../tools/style");
34
34
 
35
35
  class EventManager {
36
36
  constructor(table) {
37
37
  this.isDown = !1, this.isDraging = !1, this.globalEventListeners = [], this._enableTableScroll = !0,
38
38
  this.cutWaitPaste = !1, this.clipboardCheckTimer = null, this.cutOperationTime = 0,
39
- this.lastClipboardContent = "", this.cutCellRange = null, this.table = table, this.handleTextStickBindId = [],
40
- this.inertiaScroll = new scroll_1.InertiaScroll(table.stateManager), "node" === env_1.Env.mode || table.options.disableInteraction || (this.bindOuterEvent(),
39
+ this.lastClipboardContent = "", this.cutCellRange = null, this.copySourceRange = null,
40
+ this.table = table, this.handleTextStickBindId = [], this.inertiaScroll = new scroll_1.InertiaScroll(table.stateManager),
41
+ "node" === env_1.Env.mode || table.options.disableInteraction || (this.bindOuterEvent(),
41
42
  setTimeout((() => {
42
43
  this.bindSelfEvent();
43
44
  }), 0));
@@ -251,46 +252,80 @@ class EventManager {
251
252
  this._enableTableScroll = !1;
252
253
  }
253
254
  handleCopy(e, isCut = !1) {
254
- var _a, _b;
255
+ var _a, _b, _c, _d, _e, _f;
255
256
  return __awaiter(this, void 0, void 0, (function*() {
256
257
  const table = this.table;
257
- !isCut && (this.cutWaitPaste = !1);
258
- const data = this.table.getCopyValue();
258
+ !isCut && (this.cutWaitPaste = !1), this.copySourceRange = null;
259
+ const sourceRanges = table.stateManager.select.ranges;
260
+ if (sourceRanges && 1 === sourceRanges.length) {
261
+ const sourceRange = sourceRanges[0];
262
+ this.copySourceRange = {
263
+ startCol: Math.min(sourceRange.start.col, sourceRange.end.col),
264
+ startRow: Math.min(sourceRange.start.row, sourceRange.end.row)
265
+ };
266
+ } else if (!(null == sourceRanges ? void 0 : sourceRanges.length)) return void (this.copySourceRange = null);
267
+ const data = this.table.getCopyValue(null === (_b = null === (_a = table.options.keyboardOptions) || void 0 === _a ? void 0 : _a.getCopyCellValue) || void 0 === _b ? void 0 : _b.value);
259
268
  if ((0, vutils_1.isValid)(data)) {
260
269
  e.preventDefault();
261
- const permissionState = yield navigator.permissions.query({
262
- name: "clipboard-write"
263
- });
264
- if ((null === (_a = navigator.clipboard) || void 0 === _a ? void 0 : _a.write) && "granted" === permissionState.state) {
265
- const setDataToHTML = data => {
266
- const result = [ "<table>" ], META_HEAD = [ '<meta name="author" content="Visactor"/>', '<style type="text/css">td{white-space:normal}br{mso-data-placement:same-cell}</style>' ].join(""), rows = data.split("\r\n");
267
- return rows.forEach((function(rowCells, rowIndex) {
268
- const cells = rowCells.split("\t"), rowValues = [];
269
- 0 === rowIndex && result.push("<tbody>"), cells.forEach((function(cell, cellIndex) {
270
- const parsedCellData = cell ? cell.toString().replace(/&/g, "&amp;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br>").replace(/(<br(\s*|\/)>(\r\n|\n)?|\r\n|\n)/g, "<br>\r\n").replace(/\x20{2,}/gi, (substring => `<span style="mso-spacerun: yes">${"&nbsp;".repeat(substring.length - 1)} </span>`)).replace(/\t/gi, "&#9;") : " ";
271
- rowValues.push(`<td>${parsedCellData}</td>`);
272
- })), result.push("<tr>", ...rowValues, "</tr>"), rowIndex === rows.length - 1 && result.push("</tbody>");
273
- })), result.push("</table>"), [ META_HEAD, result.join("") ].join("");
274
- }, dataHTML = setDataToHTML(data);
275
- navigator.clipboard.write([ new ClipboardItem({
276
- "text/html": new Blob([ dataHTML ], {
277
- type: "text/html"
278
- }),
279
- "text/plain": new Blob([ data ], {
280
- type: "text/plain"
281
- })
282
- }) ]);
283
- } else helper_1.browser.IE ? window.clipboardData.setData("Text", data) : e.clipboardData.setData("text/plain", data);
284
- table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.COPY_DATA, {
285
- cellRange: table.stateManager.select.ranges,
286
- copyData: data,
287
- isCut: isCut
288
- });
270
+ const element = table.getElement();
271
+ element && element !== document.activeElement && (element.focus(), yield new Promise((resolve => setTimeout(resolve, 10))));
272
+ try {
273
+ if (navigator.clipboard && navigator.clipboard.writeText) {
274
+ let hasPermission = !0;
275
+ if (navigator.permissions && navigator.permissions.query) try {
276
+ hasPermission = "granted" === (yield navigator.permissions.query({
277
+ name: "clipboard-write"
278
+ })).state;
279
+ } catch (permissionError) {
280
+ hasPermission = !0;
281
+ }
282
+ if (hasPermission) try {
283
+ if (window.ClipboardItem) {
284
+ let htmlValues = data;
285
+ 1 === table.stateManager.select.ranges.length && (null === (_d = null === (_c = table.options.keyboardOptions) || void 0 === _c ? void 0 : _c.getCopyCellValue) || void 0 === _d ? void 0 : _d.html) && (htmlValues = this.table.getCopyValue(null === (_e = table.options.keyboardOptions) || void 0 === _e ? void 0 : _e.getCopyCellValue.html));
286
+ const dataHTML = (0, util_1.setDataToHTML)(htmlValues);
287
+ yield navigator.clipboard.write([ new ClipboardItem({
288
+ "text/html": new Blob([ dataHTML ], {
289
+ type: "text/html"
290
+ }),
291
+ "text/plain": new Blob([ data ], {
292
+ type: "text/plain"
293
+ })
294
+ }) ]);
295
+ } else yield navigator.clipboard.writeText(data);
296
+ } catch (clipboardError) {
297
+ this.fallbackCopyToClipboard(data, e);
298
+ } else this.fallbackCopyToClipboard(data, e);
299
+ } else this.fallbackCopyToClipboard(data, e);
300
+ table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.COPY_DATA, {
301
+ cellRange: table.stateManager.select.ranges,
302
+ copyData: data,
303
+ isCut: isCut
304
+ });
305
+ } catch (error) {
306
+ this.fallbackCopyToClipboard(data, e);
307
+ }
289
308
  }
290
- (null === (_b = table.keyboardOptions) || void 0 === _b ? void 0 : _b.showCopyCellBorder) && ((0,
309
+ (null === (_f = table.keyboardOptions) || void 0 === _f ? void 0 : _f.showCopyCellBorder) && ((0,
291
310
  style_1.setActiveCellRangeState)(table), table.clearSelected());
292
311
  }));
293
312
  }
313
+ fallbackCopyToClipboard(data, e) {
314
+ try {
315
+ if (e.clipboardData) return void e.clipboardData.setData("text/plain", data);
316
+ document.activeElement && document.activeElement !== document.body && document.activeElement.blur();
317
+ const textArea = document.createElement("textarea");
318
+ textArea.value = data, textArea.style.position = "fixed", textArea.style.left = "-999999px",
319
+ textArea.style.top = "-999999px", textArea.style.opacity = "0", textArea.setAttribute("readonly", ""),
320
+ textArea.setAttribute("aria-hidden", "true"), document.body.appendChild(textArea),
321
+ textArea.focus(), textArea.select(), textArea.setSelectionRange(0, data.length);
322
+ try {
323
+ document.execCommand("copy");
324
+ } catch (execError) {} finally {
325
+ document.body.removeChild(textArea);
326
+ }
327
+ } catch (error) {}
328
+ }
294
329
  handleCut(e) {
295
330
  return __awaiter(this, void 0, void 0, (function*() {
296
331
  this.handleCopy(e, !0), this.cutWaitPaste = !0, this.cutCellRange = this.table.getSelectedCellInfos(),
@@ -310,32 +345,68 @@ class EventManager {
310
345
  })) : this.executePaste(e);
311
346
  }
312
347
  executePaste(e) {
313
- var _a, _b, _c, _d;
348
+ var _a, _b, _c;
314
349
  return __awaiter(this, void 0, void 0, (function*() {
315
350
  const table = this.table;
316
- if (table.changeCellValues) {
317
- if (null === (_a = table.editorManager) || void 0 === _a ? void 0 : _a.editingEditor) return;
318
- if ((null === (_b = table.stateManager.select.ranges) || void 0 === _b ? void 0 : _b.length) > 0) if (null === (_c = navigator.clipboard) || void 0 === _c ? void 0 : _c.read) navigator.clipboard.read().then((clipboardItems => {
319
- for (const item of clipboardItems) item.types.includes("text/html") ? this.pasteHtmlToTable(item) : 1 === item.types.length && "text/plain" === item.types[0] && this.pasteTextToTable(item);
320
- })); else {
321
- const ranges = table.stateManager.select.ranges, col = Math.min(ranges[0].start.col, ranges[0].end.col), row = Math.min(ranges[0].start.row, ranges[0].end.row), rows = (e.clipboardData || window.Clipboard).getData("text").split("\n"), values = [];
322
- rows.forEach((function(rowCells, rowIndex) {
323
- const cells = rowCells.split("\t"), rowValues = [];
324
- values.push(rowValues), cells.forEach((function(cell, cellIndex) {
325
- cellIndex === cells.length - 1 && (cell = cell.trim()), rowValues.push(cell);
326
- }));
327
- }));
328
- const changedCellResults = yield table.changeCellValues(col, row, values, !0);
329
- table.hasListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA, {
330
- col: col,
331
- row: row,
332
- pasteData: values,
333
- changedCellResults: changedCellResults
334
- });
351
+ if (!(null === (_a = table.editorManager) || void 0 === _a ? void 0 : _a.editingEditor)) {
352
+ if (table.changeCellValues && (null === (_b = table.stateManager.select.ranges) || void 0 === _b ? void 0 : _b.length) > 0) try {
353
+ if (navigator.clipboard && navigator.clipboard.read) try {
354
+ const clipboardItems = yield navigator.clipboard.read();
355
+ let handled = !1;
356
+ for (const item of clipboardItems) {
357
+ if (item.types.includes("text/html")) {
358
+ yield this.pasteHtmlToTable(item), handled = !0;
359
+ break;
360
+ }
361
+ if (item.types.includes("text/plain")) {
362
+ yield this.pasteTextToTable(item), handled = !0;
363
+ break;
364
+ }
365
+ }
366
+ handled || (yield this.fallbackPasteFromClipboard(e));
367
+ } catch (clipboardError) {
368
+ yield this.fallbackPasteFromClipboard(e);
369
+ } else yield this.fallbackPasteFromClipboard(e);
370
+ } catch (error) {
371
+ yield this.fallbackPasteFromClipboard(e);
335
372
  }
373
+ (null === (_c = table.keyboardOptions) || void 0 === _c ? void 0 : _c.showCopyCellBorder) && (0,
374
+ style_1.clearActiveCellRangeState)(table);
336
375
  }
337
- (null === (_d = table.keyboardOptions) || void 0 === _d ? void 0 : _d.showCopyCellBorder) && (0,
338
- style_1.clearActiveCellRangeState)(table);
376
+ }));
377
+ }
378
+ fallbackPasteFromClipboard(e) {
379
+ return __awaiter(this, void 0, void 0, (function*() {
380
+ const table = this.table, ranges = table.stateManager.select.ranges, col = Math.min(ranges[0].start.col, ranges[0].end.col), row = Math.min(ranges[0].start.row, ranges[0].end.row);
381
+ try {
382
+ const element = table.getElement();
383
+ element && element !== document.activeElement && (element.focus(), yield new Promise((resolve => setTimeout(resolve, 10))));
384
+ const clipboardData = e.clipboardData || window.clipboardData || window.Clipboard;
385
+ if (clipboardData) {
386
+ const pastedData = clipboardData.getData("text") || clipboardData.getData("Text");
387
+ if (pastedData) return void (yield this.processPastedText(pastedData, col, row));
388
+ }
389
+ } catch (error) {}
390
+ }));
391
+ }
392
+ processPastedText(pastedData, col, row) {
393
+ var _a;
394
+ return __awaiter(this, void 0, void 0, (function*() {
395
+ const table = this.table, rows = pastedData.split("\n"), values = [];
396
+ let processedValues;
397
+ rows.forEach((function(rowCells) {
398
+ const cells = rowCells.split("\t"), rowValues = [];
399
+ values.push(rowValues), cells.forEach((function(cell, cellIndex) {
400
+ cellIndex === cells.length - 1 && (cell = cell.trim()), rowValues.push(cell);
401
+ }));
402
+ })), (null === (_a = table.options.keyboardOptions) || void 0 === _a ? void 0 : _a.processFormulaBeforePaste) && this.copySourceRange && (processedValues = table.options.keyboardOptions.processFormulaBeforePaste(values, this.copySourceRange.startCol, this.copySourceRange.startRow, col, row));
403
+ const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
404
+ table.hasListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA, {
405
+ col: col,
406
+ row: row,
407
+ pasteData: processedValues || values,
408
+ changedCellResults: changedCellResults
409
+ });
339
410
  }));
340
411
  }
341
412
  clearCutArea(table) {
@@ -367,19 +438,21 @@ class EventManager {
367
438
  let pasteValuesColCount = 0, pasteValuesRowCount = 0, values = [];
368
439
  item.getType("text/html").then((blob => {
369
440
  blob.text().then((pastedData => __awaiter(this, void 0, void 0, (function*() {
370
- var _a, _b;
441
+ var _a, _b, _c;
371
442
  if (pastedData && /(<table)|(<TABLE)/g.test(pastedData)) {
372
443
  const matches = Array.from(pastedData.matchAll(regex));
373
444
  for (const match of matches) {
374
445
  const rowContent = match[1], rowValues = Array.from(rowContent.matchAll(cellRegex)).map((cellMatch => cellMatch[1].replace(/(<(?!br)([^>]+)>)/gi, "").replace(/<br(\s*|\/)>[\r\n]?/gim, "\n").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&#9;/gi, "\t").replace(/&nbsp;/g, " ")));
375
446
  values.push(rowValues), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
376
447
  }
377
- pasteValuesRowCount = null !== (_b = values.length) && void 0 !== _b ? _b : 0, values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1);
378
- const changedCellResults = yield table.changeCellValues(col, row, values, !0);
448
+ let processedValues;
449
+ pasteValuesRowCount = null !== (_b = values.length) && void 0 !== _b ? _b : 0, values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1),
450
+ (null === (_c = table.options.keyboardOptions) || void 0 === _c ? void 0 : _c.processFormulaBeforePaste) && this.copySourceRange && (processedValues = table.options.keyboardOptions.processFormulaBeforePaste(values, this.copySourceRange.startCol, this.copySourceRange.startRow, col, row));
451
+ const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
379
452
  table.hasListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA, {
380
453
  col: col,
381
454
  row: row,
382
- pasteData: values,
455
+ pasteData: processedValues || values,
383
456
  changedCellResults: changedCellResults
384
457
  });
385
458
  } else navigator.clipboard.read().then((clipboardItems => {
@@ -391,10 +464,11 @@ class EventManager {
391
464
  }));
392
465
  }
393
466
  _pasteValue(pastedData) {
394
- var _a;
467
+ var _a, _b;
395
468
  return __awaiter(this, void 0, void 0, (function*() {
396
469
  const table = this.table, ranges = table.stateManager.select.ranges, selectRangeLength = ranges.length, col = Math.min(ranges[selectRangeLength - 1].start.col, ranges[selectRangeLength - 1].end.col), row = Math.min(ranges[selectRangeLength - 1].start.row, ranges[selectRangeLength - 1].end.row), maxCol = Math.max(ranges[selectRangeLength - 1].start.col, ranges[selectRangeLength - 1].end.col), maxRow = Math.max(ranges[selectRangeLength - 1].start.row, ranges[selectRangeLength - 1].end.row);
397
470
  let pasteValuesColCount = 0, pasteValuesRowCount = 0, values = [];
471
+ let processedValues;
398
472
  pastedData.split("\n").forEach((function(rowCells, rowIndex) {
399
473
  var _a;
400
474
  const cells = rowCells.split("\t"), rowValues = [];
@@ -402,43 +476,43 @@ class EventManager {
402
476
  cellIndex === cells.length - 1 && (cell = cell.trim()), rowValues.push(cell);
403
477
  })), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
404
478
  })), pasteValuesRowCount = null !== (_a = values.length) && void 0 !== _a ? _a : 0,
405
- values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1);
406
- const changedCellResults = yield table.changeCellValues(col, row, values, !0);
479
+ values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1),
480
+ (null === (_b = table.options.keyboardOptions) || void 0 === _b ? void 0 : _b.processFormulaBeforePaste) && this.copySourceRange && (processedValues = table.options.keyboardOptions.processFormulaBeforePaste(values, this.copySourceRange.startCol, this.copySourceRange.startRow, col, row));
481
+ const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
407
482
  table.hasListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA, {
408
483
  col: col,
409
484
  row: row,
410
- pasteData: values,
485
+ pasteData: processedValues || values,
411
486
  changedCellResults: changedCellResults
412
487
  });
413
488
  }));
414
489
  }
415
490
  pasteTextToTable(item) {
416
- const table = this.table, ranges = table.stateManager.select.ranges, selectRangeLength = ranges.length, col = Math.min(ranges[selectRangeLength - 1].start.col, ranges[selectRangeLength - 1].end.col), row = Math.min(ranges[selectRangeLength - 1].start.row, ranges[selectRangeLength - 1].end.row), maxCol = Math.max(ranges[selectRangeLength - 1].start.col, ranges[selectRangeLength - 1].end.col), maxRow = Math.max(ranges[selectRangeLength - 1].start.row, ranges[selectRangeLength - 1].end.row);
417
- let pasteValuesColCount = 0, pasteValuesRowCount = 0;
418
- item.getType("text/plain").then((blob => {
419
- blob.text().then((pastedData => __awaiter(this, void 0, void 0, (function*() {
420
- var _a;
421
- const rows = pastedData.replace(/\r(?!\n)/g, "\r\n").split("\r\n");
422
- let values = [];
423
- rows.length > 1 && "" === rows[rows.length - 1] && rows.pop(), rows.forEach((function(rowCells, rowIndex) {
424
- var _a;
425
- const cells = rowCells.split("\t"), rowValues = [];
426
- values.push(rowValues), cells.forEach((function(cell, cellIndex) {
427
- cell.includes("\n") && (cell = cell.replace(/^"(.*)"$/, "$1").replace(/["]*/g, (match => new Array(Math.floor(match.length / 2)).fill('"').join("")))),
428
- rowValues.push(cell);
429
- })), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
430
- })), pasteValuesRowCount = null !== (_a = values.length) && void 0 !== _a ? _a : 0,
431
- values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1);
432
- const changedCellResults = yield table.changeCellValues(col, row, values, !0);
491
+ return __awaiter(this, void 0, void 0, (function*() {
492
+ const table = this.table, ranges = table.stateManager.select.ranges, selectRangeLength = ranges.length, col = Math.min(ranges[selectRangeLength - 1].start.col, ranges[selectRangeLength - 1].end.col), row = Math.min(ranges[selectRangeLength - 1].start.row, ranges[selectRangeLength - 1].end.row), maxCol = Math.max(ranges[selectRangeLength - 1].start.col, ranges[selectRangeLength - 1].end.col), maxRow = Math.max(ranges[selectRangeLength - 1].start.row, ranges[selectRangeLength - 1].end.row);
493
+ try {
494
+ const blob = yield item.getType("text/plain"), pastedData = yield blob.text(), values = this.parsePastedData(pastedData), pasteValuesRowCount = values.length, pasteValuesColCount = Math.max(...values.map((row => row.length)), 0), processedValues = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1), changedCellResults = yield table.changeCellValues(col, row, processedValues, !0);
433
495
  table.hasListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA, {
434
496
  col: col,
435
497
  row: row,
436
- pasteData: values,
498
+ pasteData: processedValues,
437
499
  changedCellResults: changedCellResults
438
500
  });
439
- }))));
501
+ } catch (error) {}
440
502
  }));
441
503
  }
504
+ parsePastedData(pastedData) {
505
+ const rows = pastedData.replace(/\r(?!\n)/g, "\r\n").split("\r\n"), values = [];
506
+ return rows.length > 1 && "" === rows[rows.length - 1] && rows.pop(), rows.forEach((rowCells => {
507
+ const rowValues = rowCells.split("\t").map((cell => this.processCellValue(cell)));
508
+ values.push(rowValues);
509
+ })), values;
510
+ }
511
+ processCellValue(cell) {
512
+ cell.includes("\n") && (cell = cell.replace(/^"(.*)"$/, "$1").replace(/["]*/g, (match => new Array(Math.floor(match.length / 2)).fill('"').join(""))));
513
+ const numValue = Number(cell);
514
+ return isNaN(numValue) ? cell : numValue;
515
+ }
442
516
  handlePasteValues(values, rowCount, colCount, selectedRowCount, selectedColCount) {
443
517
  if (selectedColCount > colCount || selectedRowCount > rowCount) {
444
518
  if (selectedColCount % colCount == 0 && selectedRowCount % rowCount == 0) {