@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.
- package/cjs/PivotChart.js +2 -2
- package/cjs/PivotChart.js.map +1 -1
- package/cjs/core/BaseTable.d.ts +3 -3
- package/cjs/core/BaseTable.js +7 -7
- package/cjs/core/BaseTable.js.map +1 -1
- package/cjs/dataset/dataset.js +2 -1
- package/cjs/dataset/dataset.js.map +1 -1
- package/cjs/event/event.d.ts +9 -0
- package/cjs/event/event.js +158 -84
- package/cjs/event/event.js.map +1 -1
- package/cjs/event/util.d.ts +1 -0
- package/cjs/event/util.js +13 -2
- package/cjs/event/util.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/layout/chart-helper/get-axis-config.js +7 -1
- package/cjs/layout/chart-helper/get-axis-config.js.map +1 -1
- package/cjs/layout/pivot-header-layout.js +5 -3
- package/cjs/layout/pivot-header-layout.js.map +1 -1
- package/cjs/scenegraph/graphic/active-cell-chart-list.js +62 -44
- package/cjs/scenegraph/graphic/active-cell-chart-list.js.map +1 -1
- package/cjs/scenegraph/graphic/chart.js +14 -3
- package/cjs/scenegraph/graphic/chart.js.map +1 -1
- package/cjs/scenegraph/graphic/contributions/chart-render-helper.js +2 -1
- package/cjs/scenegraph/graphic/contributions/chart-render-helper.js.map +1 -1
- package/cjs/scenegraph/graphic/contributions/chart-render.js +1 -1
- package/cjs/scenegraph/graphic/contributions/chart-render.js.map +1 -1
- package/cjs/ts-types/base-table.d.ts +3 -3
- package/cjs/ts-types/base-table.js.map +1 -1
- package/cjs/ts-types/table-engine.d.ts +7 -2
- package/cjs/ts-types/table-engine.js.map +1 -1
- package/cjs/vrender.js.map +1 -1
- package/dist/vtable.js +456 -256
- package/dist/vtable.min.js +2 -2
- package/es/PivotChart.js +2 -2
- package/es/PivotChart.js.map +1 -1
- package/es/core/BaseTable.d.ts +3 -3
- package/es/core/BaseTable.js +7 -7
- package/es/core/BaseTable.js.map +1 -1
- package/es/dataset/dataset.js +1 -1
- package/es/dataset/dataset.js.map +1 -1
- package/es/event/event.d.ts +9 -0
- package/es/event/event.js +158 -84
- package/es/event/event.js.map +1 -1
- package/es/event/util.d.ts +1 -0
- package/es/event/util.js +11 -0
- package/es/event/util.js.map +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/layout/chart-helper/get-axis-config.js +7 -1
- package/es/layout/chart-helper/get-axis-config.js.map +1 -1
- package/es/layout/pivot-header-layout.js +5 -3
- package/es/layout/pivot-header-layout.js.map +1 -1
- package/es/scenegraph/graphic/active-cell-chart-list.js +62 -44
- package/es/scenegraph/graphic/active-cell-chart-list.js.map +1 -1
- package/es/scenegraph/graphic/chart.js +14 -3
- package/es/scenegraph/graphic/chart.js.map +1 -1
- package/es/scenegraph/graphic/contributions/chart-render-helper.js +2 -1
- package/es/scenegraph/graphic/contributions/chart-render-helper.js.map +1 -1
- package/es/scenegraph/graphic/contributions/chart-render.js +1 -1
- package/es/scenegraph/graphic/contributions/chart-render.js.map +1 -1
- package/es/ts-types/base-table.d.ts +3 -3
- package/es/ts-types/base-table.js.map +1 -1
- package/es/ts-types/table-engine.d.ts +7 -2
- package/es/ts-types/table-engine.js.map +1 -1
- package/es/vrender.js.map +1 -1
- package/package.json +5 -5
package/es/event/event.d.ts
CHANGED
|
@@ -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
|
}
|
package/es/event/event.js
CHANGED
|
@@ -44,6 +44,8 @@ import { bindContainerDomListener } from "./listener/container-dom";
|
|
|
44
44
|
|
|
45
45
|
import { bindTouchListener } from "./listener/touch";
|
|
46
46
|
|
|
47
|
+
import { setDataToHTML } from "./util";
|
|
48
|
+
|
|
47
49
|
import { bindAxisClickEvent } from "./self-event-listener/pivot-chart/axis-click";
|
|
48
50
|
|
|
49
51
|
import { bindAxisHoverEvent } from "./self-event-listener/pivot-chart/axis-hover";
|
|
@@ -66,16 +68,15 @@ import { bindDropdownMenuEvent } from "./self-event-listener/base-table/dropdown
|
|
|
66
68
|
|
|
67
69
|
import { bindDBClickAutoColumnWidthEvent } from "./self-event-listener/base-table/dbclick-auto-column-width";
|
|
68
70
|
|
|
69
|
-
import { browser } from "../tools/helper";
|
|
70
|
-
|
|
71
71
|
import { clearActiveCellRangeState, setActiveCellRangeState } from "../tools/style";
|
|
72
72
|
|
|
73
73
|
export class EventManager {
|
|
74
74
|
constructor(table) {
|
|
75
75
|
this.isDown = !1, this.isDraging = !1, this.globalEventListeners = [], this._enableTableScroll = !0,
|
|
76
76
|
this.cutWaitPaste = !1, this.clipboardCheckTimer = null, this.cutOperationTime = 0,
|
|
77
|
-
this.lastClipboardContent = "", this.cutCellRange = null, this.
|
|
78
|
-
this.
|
|
77
|
+
this.lastClipboardContent = "", this.cutCellRange = null, this.copySourceRange = null,
|
|
78
|
+
this.table = table, this.handleTextStickBindId = [], this.inertiaScroll = new InertiaScroll(table.stateManager),
|
|
79
|
+
"node" === Env.mode || table.options.disableInteraction || (this.bindOuterEvent(),
|
|
79
80
|
setTimeout((() => {
|
|
80
81
|
this.bindSelfEvent();
|
|
81
82
|
}), 0));
|
|
@@ -287,46 +288,80 @@ export class EventManager {
|
|
|
287
288
|
this._enableTableScroll = !1;
|
|
288
289
|
}
|
|
289
290
|
handleCopy(e, isCut = !1) {
|
|
290
|
-
var _a, _b;
|
|
291
|
+
var _a, _b, _c, _d, _e, _f;
|
|
291
292
|
return __awaiter(this, void 0, void 0, (function*() {
|
|
292
293
|
const table = this.table;
|
|
293
|
-
!isCut && (this.cutWaitPaste = !1);
|
|
294
|
-
const
|
|
294
|
+
!isCut && (this.cutWaitPaste = !1), this.copySourceRange = null;
|
|
295
|
+
const sourceRanges = table.stateManager.select.ranges;
|
|
296
|
+
if (sourceRanges && 1 === sourceRanges.length) {
|
|
297
|
+
const sourceRange = sourceRanges[0];
|
|
298
|
+
this.copySourceRange = {
|
|
299
|
+
startCol: Math.min(sourceRange.start.col, sourceRange.end.col),
|
|
300
|
+
startRow: Math.min(sourceRange.start.row, sourceRange.end.row)
|
|
301
|
+
};
|
|
302
|
+
} else if (!(null == sourceRanges ? void 0 : sourceRanges.length)) return void (this.copySourceRange = null);
|
|
303
|
+
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);
|
|
295
304
|
if (isValid(data)) {
|
|
296
305
|
e.preventDefault();
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
306
|
+
const element = table.getElement();
|
|
307
|
+
element && element !== document.activeElement && (element.focus(), yield new Promise((resolve => setTimeout(resolve, 10))));
|
|
308
|
+
try {
|
|
309
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
310
|
+
let hasPermission = !0;
|
|
311
|
+
if (navigator.permissions && navigator.permissions.query) try {
|
|
312
|
+
hasPermission = "granted" === (yield navigator.permissions.query({
|
|
313
|
+
name: "clipboard-write"
|
|
314
|
+
})).state;
|
|
315
|
+
} catch (permissionError) {
|
|
316
|
+
hasPermission = !0;
|
|
317
|
+
}
|
|
318
|
+
if (hasPermission) try {
|
|
319
|
+
if (window.ClipboardItem) {
|
|
320
|
+
let htmlValues = data;
|
|
321
|
+
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));
|
|
322
|
+
const dataHTML = setDataToHTML(htmlValues);
|
|
323
|
+
yield navigator.clipboard.write([ new ClipboardItem({
|
|
324
|
+
"text/html": new Blob([ dataHTML ], {
|
|
325
|
+
type: "text/html"
|
|
326
|
+
}),
|
|
327
|
+
"text/plain": new Blob([ data ], {
|
|
328
|
+
type: "text/plain"
|
|
329
|
+
})
|
|
330
|
+
}) ]);
|
|
331
|
+
} else yield navigator.clipboard.writeText(data);
|
|
332
|
+
} catch (clipboardError) {
|
|
333
|
+
this.fallbackCopyToClipboard(data, e);
|
|
334
|
+
} else this.fallbackCopyToClipboard(data, e);
|
|
335
|
+
} else this.fallbackCopyToClipboard(data, e);
|
|
336
|
+
table.fireListeners(TABLE_EVENT_TYPE.COPY_DATA, {
|
|
337
|
+
cellRange: table.stateManager.select.ranges,
|
|
338
|
+
copyData: data,
|
|
339
|
+
isCut: isCut
|
|
340
|
+
});
|
|
341
|
+
} catch (error) {
|
|
342
|
+
this.fallbackCopyToClipboard(data, e);
|
|
343
|
+
}
|
|
325
344
|
}
|
|
326
|
-
(null === (
|
|
345
|
+
(null === (_f = table.keyboardOptions) || void 0 === _f ? void 0 : _f.showCopyCellBorder) && (setActiveCellRangeState(table),
|
|
327
346
|
table.clearSelected());
|
|
328
347
|
}));
|
|
329
348
|
}
|
|
349
|
+
fallbackCopyToClipboard(data, e) {
|
|
350
|
+
try {
|
|
351
|
+
if (e.clipboardData) return void e.clipboardData.setData("text/plain", data);
|
|
352
|
+
document.activeElement && document.activeElement !== document.body && document.activeElement.blur();
|
|
353
|
+
const textArea = document.createElement("textarea");
|
|
354
|
+
textArea.value = data, textArea.style.position = "fixed", textArea.style.left = "-999999px",
|
|
355
|
+
textArea.style.top = "-999999px", textArea.style.opacity = "0", textArea.setAttribute("readonly", ""),
|
|
356
|
+
textArea.setAttribute("aria-hidden", "true"), document.body.appendChild(textArea),
|
|
357
|
+
textArea.focus(), textArea.select(), textArea.setSelectionRange(0, data.length);
|
|
358
|
+
try {
|
|
359
|
+
document.execCommand("copy");
|
|
360
|
+
} catch (execError) {} finally {
|
|
361
|
+
document.body.removeChild(textArea);
|
|
362
|
+
}
|
|
363
|
+
} catch (error) {}
|
|
364
|
+
}
|
|
330
365
|
handleCut(e) {
|
|
331
366
|
return __awaiter(this, void 0, void 0, (function*() {
|
|
332
367
|
this.handleCopy(e, !0), this.cutWaitPaste = !0, this.cutCellRange = this.table.getSelectedCellInfos(),
|
|
@@ -346,31 +381,67 @@ export class EventManager {
|
|
|
346
381
|
})) : this.executePaste(e);
|
|
347
382
|
}
|
|
348
383
|
executePaste(e) {
|
|
349
|
-
var _a, _b, _c
|
|
384
|
+
var _a, _b, _c;
|
|
350
385
|
return __awaiter(this, void 0, void 0, (function*() {
|
|
351
386
|
const table = this.table;
|
|
352
|
-
if (table.
|
|
353
|
-
if (null === (
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
});
|
|
387
|
+
if (!(null === (_a = table.editorManager) || void 0 === _a ? void 0 : _a.editingEditor)) {
|
|
388
|
+
if (table.changeCellValues && (null === (_b = table.stateManager.select.ranges) || void 0 === _b ? void 0 : _b.length) > 0) try {
|
|
389
|
+
if (navigator.clipboard && navigator.clipboard.read) try {
|
|
390
|
+
const clipboardItems = yield navigator.clipboard.read();
|
|
391
|
+
let handled = !1;
|
|
392
|
+
for (const item of clipboardItems) {
|
|
393
|
+
if (item.types.includes("text/html")) {
|
|
394
|
+
yield this.pasteHtmlToTable(item), handled = !0;
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
if (item.types.includes("text/plain")) {
|
|
398
|
+
yield this.pasteTextToTable(item), handled = !0;
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
handled || (yield this.fallbackPasteFromClipboard(e));
|
|
403
|
+
} catch (clipboardError) {
|
|
404
|
+
yield this.fallbackPasteFromClipboard(e);
|
|
405
|
+
} else yield this.fallbackPasteFromClipboard(e);
|
|
406
|
+
} catch (error) {
|
|
407
|
+
yield this.fallbackPasteFromClipboard(e);
|
|
371
408
|
}
|
|
409
|
+
(null === (_c = table.keyboardOptions) || void 0 === _c ? void 0 : _c.showCopyCellBorder) && clearActiveCellRangeState(table);
|
|
372
410
|
}
|
|
373
|
-
|
|
411
|
+
}));
|
|
412
|
+
}
|
|
413
|
+
fallbackPasteFromClipboard(e) {
|
|
414
|
+
return __awaiter(this, void 0, void 0, (function*() {
|
|
415
|
+
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);
|
|
416
|
+
try {
|
|
417
|
+
const element = table.getElement();
|
|
418
|
+
element && element !== document.activeElement && (element.focus(), yield new Promise((resolve => setTimeout(resolve, 10))));
|
|
419
|
+
const clipboardData = e.clipboardData || window.clipboardData || window.Clipboard;
|
|
420
|
+
if (clipboardData) {
|
|
421
|
+
const pastedData = clipboardData.getData("text") || clipboardData.getData("Text");
|
|
422
|
+
if (pastedData) return void (yield this.processPastedText(pastedData, col, row));
|
|
423
|
+
}
|
|
424
|
+
} catch (error) {}
|
|
425
|
+
}));
|
|
426
|
+
}
|
|
427
|
+
processPastedText(pastedData, col, row) {
|
|
428
|
+
var _a;
|
|
429
|
+
return __awaiter(this, void 0, void 0, (function*() {
|
|
430
|
+
const table = this.table, rows = pastedData.split("\n"), values = [];
|
|
431
|
+
let processedValues;
|
|
432
|
+
rows.forEach((function(rowCells) {
|
|
433
|
+
const cells = rowCells.split("\t"), rowValues = [];
|
|
434
|
+
values.push(rowValues), cells.forEach((function(cell, cellIndex) {
|
|
435
|
+
cellIndex === cells.length - 1 && (cell = cell.trim()), rowValues.push(cell);
|
|
436
|
+
}));
|
|
437
|
+
})), (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));
|
|
438
|
+
const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
|
|
439
|
+
table.hasListeners(TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE.PASTED_DATA, {
|
|
440
|
+
col: col,
|
|
441
|
+
row: row,
|
|
442
|
+
pasteData: processedValues || values,
|
|
443
|
+
changedCellResults: changedCellResults
|
|
444
|
+
});
|
|
374
445
|
}));
|
|
375
446
|
}
|
|
376
447
|
clearCutArea(table) {
|
|
@@ -402,19 +473,21 @@ export class EventManager {
|
|
|
402
473
|
let pasteValuesColCount = 0, pasteValuesRowCount = 0, values = [];
|
|
403
474
|
item.getType("text/html").then((blob => {
|
|
404
475
|
blob.text().then((pastedData => __awaiter(this, void 0, void 0, (function*() {
|
|
405
|
-
var _a, _b;
|
|
476
|
+
var _a, _b, _c;
|
|
406
477
|
if (pastedData && /(<table)|(<TABLE)/g.test(pastedData)) {
|
|
407
478
|
const matches = Array.from(pastedData.matchAll(regex));
|
|
408
479
|
for (const match of matches) {
|
|
409
480
|
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(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/	/gi, "\t").replace(/ /g, " ")));
|
|
410
481
|
values.push(rowValues), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
|
|
411
482
|
}
|
|
412
|
-
|
|
413
|
-
|
|
483
|
+
let processedValues;
|
|
484
|
+
pasteValuesRowCount = null !== (_b = values.length) && void 0 !== _b ? _b : 0, values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1),
|
|
485
|
+
(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));
|
|
486
|
+
const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
|
|
414
487
|
table.hasListeners(TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE.PASTED_DATA, {
|
|
415
488
|
col: col,
|
|
416
489
|
row: row,
|
|
417
|
-
pasteData: values,
|
|
490
|
+
pasteData: processedValues || values,
|
|
418
491
|
changedCellResults: changedCellResults
|
|
419
492
|
});
|
|
420
493
|
} else navigator.clipboard.read().then((clipboardItems => {
|
|
@@ -426,10 +499,11 @@ export class EventManager {
|
|
|
426
499
|
}));
|
|
427
500
|
}
|
|
428
501
|
_pasteValue(pastedData) {
|
|
429
|
-
var _a;
|
|
502
|
+
var _a, _b;
|
|
430
503
|
return __awaiter(this, void 0, void 0, (function*() {
|
|
431
504
|
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);
|
|
432
505
|
let pasteValuesColCount = 0, pasteValuesRowCount = 0, values = [];
|
|
506
|
+
let processedValues;
|
|
433
507
|
pastedData.split("\n").forEach((function(rowCells, rowIndex) {
|
|
434
508
|
var _a;
|
|
435
509
|
const cells = rowCells.split("\t"), rowValues = [];
|
|
@@ -437,43 +511,43 @@ export class EventManager {
|
|
|
437
511
|
cellIndex === cells.length - 1 && (cell = cell.trim()), rowValues.push(cell);
|
|
438
512
|
})), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
|
|
439
513
|
})), pasteValuesRowCount = null !== (_a = values.length) && void 0 !== _a ? _a : 0,
|
|
440
|
-
values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1)
|
|
441
|
-
|
|
514
|
+
values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1),
|
|
515
|
+
(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));
|
|
516
|
+
const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
|
|
442
517
|
table.hasListeners(TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE.PASTED_DATA, {
|
|
443
518
|
col: col,
|
|
444
519
|
row: row,
|
|
445
|
-
pasteData: values,
|
|
520
|
+
pasteData: processedValues || values,
|
|
446
521
|
changedCellResults: changedCellResults
|
|
447
522
|
});
|
|
448
523
|
}));
|
|
449
524
|
}
|
|
450
525
|
pasteTextToTable(item) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
var _a;
|
|
456
|
-
const rows = pastedData.replace(/\r(?!\n)/g, "\r\n").split("\r\n");
|
|
457
|
-
let values = [];
|
|
458
|
-
rows.length > 1 && "" === rows[rows.length - 1] && rows.pop(), rows.forEach((function(rowCells, rowIndex) {
|
|
459
|
-
var _a;
|
|
460
|
-
const cells = rowCells.split("\t"), rowValues = [];
|
|
461
|
-
values.push(rowValues), cells.forEach((function(cell, cellIndex) {
|
|
462
|
-
cell.includes("\n") && (cell = cell.replace(/^"(.*)"$/, "$1").replace(/["]*/g, (match => new Array(Math.floor(match.length / 2)).fill('"').join("")))),
|
|
463
|
-
rowValues.push(cell);
|
|
464
|
-
})), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
|
|
465
|
-
})), pasteValuesRowCount = null !== (_a = values.length) && void 0 !== _a ? _a : 0,
|
|
466
|
-
values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1);
|
|
467
|
-
const changedCellResults = yield table.changeCellValues(col, row, values, !0);
|
|
526
|
+
return __awaiter(this, void 0, void 0, (function*() {
|
|
527
|
+
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);
|
|
528
|
+
try {
|
|
529
|
+
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);
|
|
468
530
|
table.hasListeners(TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE.PASTED_DATA, {
|
|
469
531
|
col: col,
|
|
470
532
|
row: row,
|
|
471
|
-
pasteData:
|
|
533
|
+
pasteData: processedValues,
|
|
472
534
|
changedCellResults: changedCellResults
|
|
473
535
|
});
|
|
474
|
-
})
|
|
536
|
+
} catch (error) {}
|
|
475
537
|
}));
|
|
476
538
|
}
|
|
539
|
+
parsePastedData(pastedData) {
|
|
540
|
+
const rows = pastedData.replace(/\r(?!\n)/g, "\r\n").split("\r\n"), values = [];
|
|
541
|
+
return rows.length > 1 && "" === rows[rows.length - 1] && rows.pop(), rows.forEach((rowCells => {
|
|
542
|
+
const rowValues = rowCells.split("\t").map((cell => this.processCellValue(cell)));
|
|
543
|
+
values.push(rowValues);
|
|
544
|
+
})), values;
|
|
545
|
+
}
|
|
546
|
+
processCellValue(cell) {
|
|
547
|
+
cell.includes("\n") && (cell = cell.replace(/^"(.*)"$/, "$1").replace(/["]*/g, (match => new Array(Math.floor(match.length / 2)).fill('"').join(""))));
|
|
548
|
+
const numValue = Number(cell);
|
|
549
|
+
return isNaN(numValue) ? cell : numValue;
|
|
550
|
+
}
|
|
477
551
|
handlePasteValues(values, rowCount, colCount, selectedRowCount, selectedColCount) {
|
|
478
552
|
if (selectedColCount > colCount || selectedRowCount > rowCount) {
|
|
479
553
|
if (selectedColCount % colCount == 0 && selectedRowCount % rowCount == 0) {
|