@visactor/vtable 1.26.7 → 1.26.8

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 (183) hide show
  1. package/cjs/ListTable.d.ts +1 -1
  2. package/cjs/ListTable.js +21 -13
  3. package/cjs/ListTable.js.map +1 -1
  4. package/cjs/PivotChart.js +16 -16
  5. package/cjs/PivotChart.js.map +1 -1
  6. package/cjs/PivotTable.d.ts +1 -1
  7. package/cjs/PivotTable.js +65 -63
  8. package/cjs/PivotTable.js.map +1 -1
  9. package/cjs/body-helper/body-helper.js +2 -1
  10. package/cjs/components/index.js +1 -2
  11. package/cjs/core/BaseTable.js +2 -2
  12. package/cjs/core/BaseTable.js.map +1 -1
  13. package/cjs/core/record-helper.d.ts +1 -1
  14. package/cjs/core/record-helper.js +60 -12
  15. package/cjs/core/record-helper.js.map +1 -1
  16. package/cjs/core/tableHelper.js +2 -1
  17. package/cjs/data/DataSource.d.ts +3 -1
  18. package/cjs/data/DataSource.js +71 -23
  19. package/cjs/data/DataSource.js.map +1 -1
  20. package/cjs/dataset/dataset.d.ts +9 -1
  21. package/cjs/dataset/dataset.js +344 -187
  22. package/cjs/dataset/dataset.js.map +1 -1
  23. package/cjs/event/event.d.ts +94 -8
  24. package/cjs/event/event.js +698 -191
  25. package/cjs/event/event.js.map +1 -1
  26. package/cjs/event/helper.js +1 -1
  27. package/cjs/event/media-click.js +4 -1
  28. package/cjs/event/media-click.js.map +1 -1
  29. package/cjs/event/scroll.js +1 -1
  30. package/cjs/event/sparkline-event.js +1 -2
  31. package/cjs/event/util.js +2 -2
  32. package/cjs/event/util.js.map +1 -1
  33. package/cjs/index.d.ts +1 -1
  34. package/cjs/index.js +1 -1
  35. package/cjs/index.js.map +1 -1
  36. package/cjs/layout/pivot-header-layout.js +33 -17
  37. package/cjs/layout/pivot-header-layout.js.map +1 -1
  38. package/cjs/plugins/custom-cell-style.js +1 -1
  39. package/cjs/plugins/index.js +2 -1
  40. package/cjs/plugins/interface.js +1 -1
  41. package/cjs/plugins/invert-highlight.js +1 -1
  42. package/cjs/plugins/list-tree-stick-cell.js +1 -1
  43. package/cjs/plugins/plugin-manager.js +1 -1
  44. package/cjs/scenegraph/group-creater/cell-helper.js +27 -10
  45. package/cjs/scenegraph/group-creater/cell-helper.js.map +1 -1
  46. package/cjs/scenegraph/group-creater/cell-type/text-cell.d.ts +1 -1
  47. package/cjs/scenegraph/group-creater/cell-type/text-cell.js +14 -10
  48. package/cjs/scenegraph/group-creater/cell-type/text-cell.js.map +1 -1
  49. package/cjs/scenegraph/group-creater/progress/create-group-for-first-screen.js +17 -4
  50. package/cjs/scenegraph/group-creater/progress/create-group-for-first-screen.js.map +1 -1
  51. package/cjs/scenegraph/layout/compute-col-width.js +6 -1
  52. package/cjs/scenegraph/layout/compute-col-width.js.map +1 -1
  53. package/cjs/scenegraph/layout/compute-row-height.js +11 -3
  54. package/cjs/scenegraph/layout/compute-row-height.js.map +1 -1
  55. package/cjs/scenegraph/layout/update-height.d.ts +4 -3
  56. package/cjs/scenegraph/layout/update-height.js +43 -29
  57. package/cjs/scenegraph/layout/update-height.js.map +1 -1
  58. package/cjs/scenegraph/layout/update-width.d.ts +2 -1
  59. package/cjs/scenegraph/layout/update-width.js +49 -37
  60. package/cjs/scenegraph/layout/update-width.js.map +1 -1
  61. package/cjs/scenegraph/scenegraph.d.ts +2 -2
  62. package/cjs/scenegraph/scenegraph.js +6 -5
  63. package/cjs/scenegraph/scenegraph.js.map +1 -1
  64. package/cjs/scenegraph/utils/corner-custom-merge.d.ts +10 -0
  65. package/cjs/scenegraph/utils/corner-custom-merge.js +68 -0
  66. package/cjs/scenegraph/utils/corner-custom-merge.js.map +1 -0
  67. package/cjs/state/resize/update-resize-column.js +25 -13
  68. package/cjs/state/resize/update-resize-column.js.map +1 -1
  69. package/cjs/state/resize/update-resize-row.js +24 -12
  70. package/cjs/state/resize/update-resize-row.js.map +1 -1
  71. package/cjs/themes.d.ts +4 -2
  72. package/cjs/themes.js +12 -4
  73. package/cjs/themes.js.map +1 -1
  74. package/cjs/tools/get-data-path/create-dataset.js +4 -4
  75. package/cjs/tools/get-data-path/create-dataset.js.map +1 -1
  76. package/cjs/tools/get-data-path/index.js +4 -4
  77. package/cjs/tools/get-data-path/index.js.map +1 -1
  78. package/cjs/tools/style.d.ts +3 -1
  79. package/cjs/tools/style.js +2 -2
  80. package/cjs/tools/style.js.map +1 -1
  81. package/cjs/ts-types/common.d.ts +1 -0
  82. package/cjs/ts-types/common.js.map +1 -1
  83. package/cjs/ts-types/dataset/aggregation.d.ts +1 -0
  84. package/cjs/ts-types/dataset/aggregation.js +21 -3
  85. package/cjs/ts-types/dataset/aggregation.js.map +1 -1
  86. package/cjs/ts-types/new-data-set.d.ts +1 -0
  87. package/cjs/ts-types/new-data-set.js.map +1 -1
  88. package/cjs/ts-types/table-engine.d.ts +3 -2
  89. package/cjs/ts-types/table-engine.js.map +1 -1
  90. package/cjs/vrender.js.map +1 -1
  91. package/dist/vtable.js +2224 -779
  92. package/dist/vtable.min.js +1 -1
  93. package/es/ListTable.d.ts +1 -1
  94. package/es/ListTable.js +21 -15
  95. package/es/ListTable.js.map +1 -1
  96. package/es/PivotChart.js +16 -16
  97. package/es/PivotChart.js.map +1 -1
  98. package/es/PivotTable.d.ts +1 -1
  99. package/es/PivotTable.js +65 -63
  100. package/es/PivotTable.js.map +1 -1
  101. package/es/body-helper/body-helper.js +2 -1
  102. package/es/components/index.js +1 -2
  103. package/es/core/BaseTable.js +2 -2
  104. package/es/core/BaseTable.js.map +1 -1
  105. package/es/core/record-helper.d.ts +1 -1
  106. package/es/core/record-helper.js +60 -12
  107. package/es/core/record-helper.js.map +1 -1
  108. package/es/core/tableHelper.js +2 -1
  109. package/es/data/DataSource.d.ts +3 -1
  110. package/es/data/DataSource.js +70 -23
  111. package/es/data/DataSource.js.map +1 -1
  112. package/es/dataset/dataset.d.ts +9 -1
  113. package/es/dataset/dataset.js +341 -187
  114. package/es/dataset/dataset.js.map +1 -1
  115. package/es/event/event.d.ts +94 -8
  116. package/es/event/event.js +696 -191
  117. package/es/event/event.js.map +1 -1
  118. package/es/event/helper.js +1 -1
  119. package/es/event/media-click.js +4 -1
  120. package/es/event/media-click.js.map +1 -1
  121. package/es/event/scroll.js +1 -1
  122. package/es/event/sparkline-event.js +1 -2
  123. package/es/event/util.js +2 -2
  124. package/es/event/util.js.map +1 -1
  125. package/es/index.d.ts +1 -1
  126. package/es/index.js +1 -1
  127. package/es/index.js.map +1 -1
  128. package/es/layout/pivot-header-layout.js +29 -17
  129. package/es/layout/pivot-header-layout.js.map +1 -1
  130. package/es/plugins/custom-cell-style.js +1 -1
  131. package/es/plugins/index.js +2 -1
  132. package/es/plugins/interface.js +1 -1
  133. package/es/plugins/invert-highlight.js +1 -1
  134. package/es/plugins/list-tree-stick-cell.js +1 -1
  135. package/es/plugins/plugin-manager.js +1 -1
  136. package/es/scenegraph/group-creater/cell-helper.js +23 -9
  137. package/es/scenegraph/group-creater/cell-helper.js.map +1 -1
  138. package/es/scenegraph/group-creater/cell-type/text-cell.d.ts +1 -1
  139. package/es/scenegraph/group-creater/cell-type/text-cell.js +13 -8
  140. package/es/scenegraph/group-creater/cell-type/text-cell.js.map +1 -1
  141. package/es/scenegraph/group-creater/progress/create-group-for-first-screen.js +17 -5
  142. package/es/scenegraph/group-creater/progress/create-group-for-first-screen.js.map +1 -1
  143. package/es/scenegraph/layout/compute-col-width.js +6 -1
  144. package/es/scenegraph/layout/compute-col-width.js.map +1 -1
  145. package/es/scenegraph/layout/compute-row-height.js +11 -3
  146. package/es/scenegraph/layout/compute-row-height.js.map +1 -1
  147. package/es/scenegraph/layout/update-height.d.ts +4 -3
  148. package/es/scenegraph/layout/update-height.js +40 -26
  149. package/es/scenegraph/layout/update-height.js.map +1 -1
  150. package/es/scenegraph/layout/update-width.d.ts +2 -1
  151. package/es/scenegraph/layout/update-width.js +46 -34
  152. package/es/scenegraph/layout/update-width.js.map +1 -1
  153. package/es/scenegraph/scenegraph.d.ts +2 -2
  154. package/es/scenegraph/scenegraph.js +7 -5
  155. package/es/scenegraph/scenegraph.js.map +1 -1
  156. package/es/scenegraph/utils/corner-custom-merge.d.ts +10 -0
  157. package/es/scenegraph/utils/corner-custom-merge.js +59 -0
  158. package/es/scenegraph/utils/corner-custom-merge.js.map +1 -0
  159. package/es/state/resize/update-resize-column.js +19 -10
  160. package/es/state/resize/update-resize-column.js.map +1 -1
  161. package/es/state/resize/update-resize-row.js +19 -9
  162. package/es/state/resize/update-resize-row.js.map +1 -1
  163. package/es/themes.d.ts +4 -2
  164. package/es/themes.js +11 -3
  165. package/es/themes.js.map +1 -1
  166. package/es/tools/get-data-path/create-dataset.js +4 -4
  167. package/es/tools/get-data-path/create-dataset.js.map +1 -1
  168. package/es/tools/get-data-path/index.js +4 -4
  169. package/es/tools/get-data-path/index.js.map +1 -1
  170. package/es/tools/style.d.ts +3 -1
  171. package/es/tools/style.js +2 -2
  172. package/es/tools/style.js.map +1 -1
  173. package/es/ts-types/common.d.ts +1 -0
  174. package/es/ts-types/common.js.map +1 -1
  175. package/es/ts-types/dataset/aggregation.d.ts +1 -0
  176. package/es/ts-types/dataset/aggregation.js +21 -3
  177. package/es/ts-types/dataset/aggregation.js.map +1 -1
  178. package/es/ts-types/new-data-set.d.ts +1 -0
  179. package/es/ts-types/new-data-set.js.map +1 -1
  180. package/es/ts-types/table-engine.d.ts +3 -2
  181. package/es/ts-types/table-engine.js.map +1 -1
  182. package/es/vrender.js.map +1 -1
  183. package/package.json +9 -9
package/es/event/event.js CHANGED
@@ -73,10 +73,14 @@ import { clearActiveCellRangeState, setActiveCellRangeState } from "../tools/sty
73
73
  export class EventManager {
74
74
  constructor(table) {
75
75
  this.isDown = !1, this.isDraging = !1, this.globalEventListeners = [], this._enableTableScroll = !0,
76
- this.cutWaitPaste = !1, this.clipboardCheckTimer = null, this.cutOperationTime = 0,
77
- this.lastClipboardContent = "", this.cutCellRange = null, this.cutRanges = null,
78
- this.copySourceRange = null, this.table = table, this.handleTextStickBindId = [],
79
- this.inertiaScroll = new InertiaScroll(table.stateManager), "node" === Env.mode || table.options.disableInteraction || (this.bindOuterEvent(),
76
+ this.cutWaitPaste = !1, this.clipboardCheckTimer = null, this.cutOperationId = 0,
77
+ this.clipboardOperationId = 0, this.pasteOperationId = 0, this.pasteWriteInProgress = !1,
78
+ this.pasteWritePromise = Promise.resolve(), this.clipboardWritePromise = Promise.resolve(),
79
+ this.lastCopiedClipboardData = null, this.internalFormulaHtmlMarkerId = 0, this.fieldKeyIds = new WeakMap,
80
+ this.fieldKeyId = 0, this.activeCutState = null, this.lastClipboardContent = "",
81
+ this.cutCellRange = null, this.cutRanges = null, this.copySourceRange = null, this.table = table,
82
+ this.handleTextStickBindId = [], this.inertiaScroll = new InertiaScroll(table.stateManager),
83
+ "node" === Env.mode || table.options.disableInteraction || (this.bindOuterEvent(),
80
84
  setTimeout((() => {
81
85
  this.bindSelfEvent();
82
86
  }), 0));
@@ -281,7 +285,8 @@ export class EventManager {
281
285
  }
282
286
  release() {
283
287
  var _a;
284
- null === (_a = this.gesture) || void 0 === _a || _a.release(), this.globalEventListeners.forEach((item => {
288
+ this.clipboardOperationId++, this.pasteOperationId++, this.resetCutState(), null === (_a = this.gesture) || void 0 === _a || _a.release(),
289
+ this.globalEventListeners.forEach((item => {
285
290
  "document" === item.env ? document.removeEventListener(item.name, item.callback) : "body" === item.env ? document.body.removeEventListener(item.name, item.callback) : "window" === item.env ? window.removeEventListener(item.name, item.callback) : "vglobal" === item.env && vglobal.removeEventListener(item.name, item.callback);
286
291
  })), this.globalEventListeners = [];
287
292
  }
@@ -294,65 +299,328 @@ export class EventManager {
294
299
  handleCopy(e, isCut = !1) {
295
300
  var _a, _b, _c, _d, _e, _f;
296
301
  return __awaiter(this, void 0, void 0, (function*() {
297
- const table = this.table;
298
- !isCut && (this.cutWaitPaste = !1), this.copySourceRange = null;
299
- const sourceRanges = table.stateManager.select.ranges;
300
- if (sourceRanges && 1 === sourceRanges.length) {
301
- const sourceRange = sourceRanges[0];
302
- this.copySourceRange = {
303
- startCol: Math.min(sourceRange.start.col, sourceRange.end.col),
304
- startRow: Math.min(sourceRange.start.row, sourceRange.end.row)
305
- };
306
- } else if (!(null == sourceRanges ? void 0 : sourceRanges.length)) return void (this.copySourceRange = null);
302
+ const table = this.table, operationId = ++this.clipboardOperationId;
303
+ this.pasteOperationId++, isCut || this.resetCutState();
304
+ const copySnapshot = this.getCopySnapshot(isCut);
305
+ if (this.copySourceRange = null, this.lastCopiedClipboardData = null, !copySnapshot) return this.copySourceRange = null,
306
+ null;
307
307
  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);
308
- if (isValid(data)) {
308
+ if (!isValid(data)) return null;
309
+ {
309
310
  e.preventDefault();
311
+ let copySucceeded = !1, copiedClipboardData = null;
312
+ const canUseAsyncClipboard = window.isSecureContext && !!(null === (_c = navigator.clipboard) || void 0 === _c ? void 0 : _c.writeText), canWriteRichClipboard = window.isSecureContext && !!(null === (_d = navigator.clipboard) || void 0 === _d ? void 0 : _d.write) && !!window.ClipboardItem, hasEventClipboard = !!e.clipboardData, dataHTML = !canUseAsyncClipboard || canWriteRichClipboard || hasEventClipboard ? this.getCopyDataHTML(data) : null, formulaClipboardData = this.getCopyFormulaPlainData(data, isCut);
313
+ if (null === formulaClipboardData) return null;
314
+ const plainClipboardData = data, internalFormulaText = formulaClipboardData !== plainClipboardData ? formulaClipboardData : void 0, internalFormulaHtmlMarker = internalFormulaText ? this.createInternalFormulaHtmlMarker() : void 0, clipboardHTML = dataHTML && internalFormulaHtmlMarker ? this.attachInternalFormulaHtmlMarker(dataHTML, internalFormulaHtmlMarker) : dataHTML, eventClipboardWriteData = hasEventClipboard ? this.setCopyDataToEventClipboard(plainClipboardData, clipboardHTML, e, internalFormulaText, internalFormulaHtmlMarker) : null;
315
+ if (eventClipboardWriteData) return copiedClipboardData = eventClipboardWriteData,
316
+ this.lastCopiedClipboardData = copiedClipboardData, isCut && (this.lastClipboardContent = this.getClipboardSignature(copiedClipboardData),
317
+ copySnapshot.clipboardData = copiedClipboardData, copySnapshot.clipboardSignature = this.lastClipboardContent),
318
+ this.copySourceRange = copySnapshot.copySourceRange, this.afterCopyData(data, isCut, copySnapshot, !isCut),
319
+ isCut && (null === (_e = table.keyboardOptions) || void 0 === _e ? void 0 : _e.showCopyCellBorder) && window.setTimeout((() => {
320
+ this.isClipboardOperationCurrent(operationId) && (setActiveCellRangeState(table, copySnapshot.ranges),
321
+ table.clearSelected());
322
+ }), 0), copySnapshot;
310
323
  const element = table.getElement();
311
- element && element !== document.activeElement && (element.focus(), yield new Promise((resolve => setTimeout(resolve, 10))));
324
+ if (element && element !== document.activeElement && (element.focus(), yield new Promise((resolve => setTimeout(resolve, 10))),
325
+ !this.isClipboardOperationCurrent(operationId))) return null;
312
326
  try {
313
327
  if (navigator.clipboard && navigator.clipboard.writeText) {
314
328
  let hasPermission = !0;
315
329
  if (navigator.permissions && navigator.permissions.query) try {
316
- hasPermission = "granted" === (yield navigator.permissions.query({
330
+ if (hasPermission = "granted" === (yield navigator.permissions.query({
317
331
  name: "clipboard-write"
318
- })).state;
332
+ })).state, !this.isClipboardOperationCurrent(operationId)) return null;
319
333
  } catch (permissionError) {
320
334
  hasPermission = !0;
321
335
  }
322
336
  if (hasPermission) try {
323
- if (window.ClipboardItem) {
324
- let htmlValues = data;
325
- 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));
326
- const dataHTML = setDataToHTML(htmlValues);
327
- yield navigator.clipboard.write([ new ClipboardItem({
328
- "text/html": new Blob([ dataHTML ], {
337
+ if (!this.isClipboardOperationCurrent(operationId)) return null;
338
+ copiedClipboardData = yield this.queueClipboardWrite((() => __awaiter(this, void 0, void 0, (function*() {
339
+ return this.isClipboardOperationCurrent(operationId) ? canWriteRichClipboard && clipboardHTML ? (yield navigator.clipboard.write([ new ClipboardItem({
340
+ "text/html": new Blob([ clipboardHTML ], {
329
341
  type: "text/html"
330
342
  }),
331
- "text/plain": new Blob([ data ], {
343
+ "text/plain": new Blob([ plainClipboardData ], {
332
344
  type: "text/plain"
333
345
  })
334
- }) ]);
335
- } else yield navigator.clipboard.writeText(data);
346
+ }) ]), {
347
+ html: clipboardHTML,
348
+ text: plainClipboardData,
349
+ hasHtml: !0,
350
+ hasText: !0,
351
+ internalFormulaText: internalFormulaText,
352
+ internalFormulaHtmlMarker: internalFormulaHtmlMarker
353
+ }) : (yield navigator.clipboard.writeText(plainClipboardData), {
354
+ html: "",
355
+ text: plainClipboardData,
356
+ hasText: !0,
357
+ internalFormulaText: internalFormulaText
358
+ }) : null;
359
+ })))), copiedClipboardData && (copySucceeded = !0);
336
360
  } catch (clipboardError) {
337
- this.fallbackCopyToClipboard(data, e);
338
- } else this.fallbackCopyToClipboard(data, e);
339
- } else this.fallbackCopyToClipboard(data, e);
340
- table.fireListeners(TABLE_EVENT_TYPE.COPY_DATA, {
341
- cellRange: table.stateManager.select.ranges,
342
- copyData: data,
343
- isCut: isCut
361
+ if (!this.isClipboardOperationCurrent(operationId)) return null;
362
+ if (copySucceeded = this.fallbackCopyToClipboard(plainClipboardData), !this.isClipboardOperationCurrent(operationId)) return null;
363
+ copySucceeded && (copiedClipboardData = {
364
+ html: "",
365
+ text: plainClipboardData,
366
+ hasText: !0,
367
+ internalFormulaText: internalFormulaText
368
+ });
369
+ } else copySucceeded = this.fallbackCopyToClipboard(plainClipboardData), copySucceeded && (copiedClipboardData = {
370
+ html: "",
371
+ text: plainClipboardData,
372
+ hasText: !0,
373
+ internalFormulaText: internalFormulaText
374
+ });
375
+ } else copySucceeded = this.fallbackCopyToClipboard(plainClipboardData), copySucceeded && (copiedClipboardData = {
376
+ html: "",
377
+ text: plainClipboardData,
378
+ hasText: !0,
379
+ internalFormulaText: internalFormulaText
344
380
  });
381
+ if (!copySucceeded) return null;
382
+ if (!this.isClipboardOperationCurrent(operationId)) return null;
383
+ this.lastCopiedClipboardData = copiedClipboardData, isCut && (this.lastClipboardContent = this.getClipboardSignature(copiedClipboardData),
384
+ copySnapshot.clipboardData = copiedClipboardData, copySnapshot.clipboardSignature = this.lastClipboardContent),
385
+ this.copySourceRange = copySnapshot.copySourceRange, this.afterCopyData(data, isCut, copySnapshot, !1);
345
386
  } catch (error) {
346
- this.fallbackCopyToClipboard(data, e);
387
+ if (!this.isClipboardOperationCurrent(operationId)) return null;
388
+ if (!this.fallbackCopyToClipboard(plainClipboardData)) return null;
389
+ if (!this.isClipboardOperationCurrent(operationId)) return null;
390
+ this.lastCopiedClipboardData = {
391
+ html: "",
392
+ text: plainClipboardData,
393
+ hasText: !0,
394
+ internalFormulaText: internalFormulaText
395
+ }, isCut && (this.lastClipboardContent = this.getClipboardSignature(this.lastCopiedClipboardData),
396
+ copySnapshot.clipboardData = this.lastCopiedClipboardData, copySnapshot.clipboardSignature = this.lastClipboardContent),
397
+ this.copySourceRange = copySnapshot.copySourceRange, this.afterCopyData(data, isCut, copySnapshot, !1);
347
398
  }
348
399
  }
349
- (null === (_f = table.keyboardOptions) || void 0 === _f ? void 0 : _f.showCopyCellBorder) && (setActiveCellRangeState(table),
350
- table.clearSelected());
400
+ return (null === (_f = table.keyboardOptions) || void 0 === _f ? void 0 : _f.showCopyCellBorder) && (setActiveCellRangeState(table, copySnapshot.ranges),
401
+ table.clearSelected()), copySnapshot;
402
+ }));
403
+ }
404
+ afterCopyData(data, isCut, copySnapshot, updateCopyCellBorder = !0) {
405
+ var _a;
406
+ const table = this.table;
407
+ try {
408
+ table.fireListeners(TABLE_EVENT_TYPE.COPY_DATA, {
409
+ cellRange: this.cloneRanges(copySnapshot.ranges),
410
+ copyData: data,
411
+ isCut: isCut
412
+ });
413
+ } catch (error) {}
414
+ updateCopyCellBorder && (null === (_a = table.keyboardOptions) || void 0 === _a ? void 0 : _a.showCopyCellBorder) && (setActiveCellRangeState(table, copySnapshot.ranges),
415
+ table.clearSelected());
416
+ }
417
+ getCopySnapshot(includeCellInfos) {
418
+ const ranges = this.table.stateManager.select.ranges;
419
+ if (!(null == ranges ? void 0 : ranges.length)) return null;
420
+ const clonedRanges = ranges.map((range => ({
421
+ start: {
422
+ col: range.start.col,
423
+ row: range.start.row
424
+ },
425
+ end: {
426
+ col: range.end.col,
427
+ row: range.end.row
428
+ }
429
+ }))), sourceRange = 1 === ranges.length ? ranges[0] : null, sourceCellMatrix = this.getSourceCellMatrix(clonedRanges), sourceCells = this.getSourceCells(sourceCellMatrix), sourceSize = this.getSourceSize(clonedRanges, sourceCellMatrix);
430
+ return {
431
+ ranges: clonedRanges,
432
+ copySourceRange: sourceRange ? {
433
+ startCol: Math.min(sourceRange.start.col, sourceRange.end.col),
434
+ startRow: Math.min(sourceRange.start.row, sourceRange.end.row)
435
+ } : null,
436
+ cellInfos: includeCellInfos ? this.table.getSelectedCellInfos() : null,
437
+ sourceCells: sourceCells,
438
+ sourceCellMatrix: sourceCellMatrix,
439
+ sourceColCount: sourceSize.colCount,
440
+ sourceRowCount: sourceSize.rowCount,
441
+ clipboardData: null,
442
+ clipboardSignature: ""
443
+ };
444
+ }
445
+ cloneRanges(ranges) {
446
+ return ranges.map((range => ({
447
+ start: {
448
+ col: range.start.col,
449
+ row: range.start.row
450
+ },
451
+ end: {
452
+ col: range.end.col,
453
+ row: range.end.row
454
+ }
455
+ })));
456
+ }
457
+ getSourceCellMatrix(ranges) {
458
+ const table = this.table, createSourceCell = (col, row) => {
459
+ var _a, _b, _c, _d, _e, _f, _g, _h;
460
+ const recordShowIndex = null === (_a = table.getRecordShowIndexByCell) || void 0 === _a ? void 0 : _a.call(table, col, row);
461
+ return {
462
+ col: col,
463
+ row: row,
464
+ recordIndex: recordShowIndex >= 0 ? null === (_c = null === (_b = table.dataSource) || void 0 === _b ? void 0 : _b.getIndexKey) || void 0 === _c ? void 0 : _c.call(_b, recordShowIndex) : void 0,
465
+ field: null === (_g = null === (_f = null === (_e = null === (_d = table.internalProps) || void 0 === _d ? void 0 : _d.layoutMap) || void 0 === _e ? void 0 : _e.getBody) || void 0 === _f ? void 0 : _f.call(_e, col, row)) || void 0 === _g ? void 0 : _g.field,
466
+ value: null === (_h = table.getCellOriginValue) || void 0 === _h ? void 0 : _h.call(table, col, row)
467
+ };
468
+ };
469
+ if (1 === ranges.length) {
470
+ const range = ranges[0], startCol = Math.min(range.start.col, range.end.col), endCol = Math.max(range.start.col, range.end.col), startRow = Math.min(range.start.row, range.end.row), endRow = Math.max(range.start.row, range.end.row), sourceCellMatrix = [];
471
+ for (let row = startRow; row <= endRow; row++) {
472
+ const rowCells = [];
473
+ for (let col = startCol; col <= endCol; col++) rowCells.push(createSourceCell(col, row));
474
+ sourceCellMatrix.push(rowCells);
475
+ }
476
+ return sourceCellMatrix;
477
+ }
478
+ let minCol = Math.min(ranges[0].start.col, ranges[0].end.col), maxCol = Math.max(ranges[0].start.col, ranges[0].end.col), minRow = Math.min(ranges[0].start.row, ranges[0].end.row), maxRow = Math.max(ranges[0].start.row, ranges[0].end.row);
479
+ ranges.forEach((range => {
480
+ minCol = Math.min(minCol, range.start.col, range.end.col), maxCol = Math.max(maxCol, range.start.col, range.end.col),
481
+ minRow = Math.min(minRow, range.start.row, range.end.row), maxRow = Math.max(maxRow, range.start.row, range.end.row);
482
+ }));
483
+ const isExistDataInRow = row => ranges.some((range => {
484
+ const startRow = Math.min(range.start.row, range.end.row), endRow = Math.max(range.start.row, range.end.row);
485
+ return startRow <= row && endRow >= row;
486
+ })), isExistDataInCol = col => ranges.some((range => {
487
+ const startCol = Math.min(range.start.col, range.end.col), endCol = Math.max(range.start.col, range.end.col);
488
+ return startCol <= col && endCol >= col;
489
+ })), getRangeExistDataInCell = (col, row) => ranges.some((range => {
490
+ const startRow = Math.min(range.start.row, range.end.row), endRow = Math.max(range.start.row, range.end.row), startCol = Math.min(range.start.col, range.end.col), endCol = Math.max(range.start.col, range.end.col);
491
+ return startCol <= col && endCol >= col && startRow <= row && endRow >= row;
492
+ })), sourceCellMatrix = [];
493
+ for (let row = minRow; row <= maxRow; row++) {
494
+ if (!isExistDataInRow(row)) continue;
495
+ const rowCells = [];
496
+ for (let col = minCol; col <= maxCol; col++) isExistDataInCol(col) && rowCells.push(getRangeExistDataInCell(col, row) ? createSourceCell(col, row) : null);
497
+ sourceCellMatrix.push(rowCells);
498
+ }
499
+ return sourceCellMatrix;
500
+ }
501
+ getSourceCells(sourceCellMatrix) {
502
+ const sourceCells = [];
503
+ for (let row = 0; row < sourceCellMatrix.length; row++) for (let col = 0; col < sourceCellMatrix[row].length; col++) {
504
+ const sourceCell = sourceCellMatrix[row][col];
505
+ sourceCell && sourceCells.push(sourceCell);
506
+ }
507
+ return sourceCells;
508
+ }
509
+ getSourceSize(ranges, sourceCellMatrix) {
510
+ var _a, _b;
511
+ if (sourceCellMatrix.length) return {
512
+ colCount: null !== (_b = null === (_a = sourceCellMatrix[0]) || void 0 === _a ? void 0 : _a.length) && void 0 !== _b ? _b : 0,
513
+ rowCount: sourceCellMatrix.length
514
+ };
515
+ if (1 === ranges.length) {
516
+ const range = ranges[0];
517
+ return {
518
+ colCount: Math.abs(range.end.col - range.start.col) + 1,
519
+ rowCount: Math.abs(range.end.row - range.start.row) + 1
520
+ };
521
+ }
522
+ return {
523
+ colCount: 0,
524
+ rowCount: 0
525
+ };
526
+ }
527
+ getClipboardSignature(data) {
528
+ return data ? JSON.stringify({
529
+ html: data.hasHtml ? data.html : null,
530
+ text: data.hasText ? data.text : null
531
+ }) : "";
532
+ }
533
+ isClipboardOperationCurrent(operationId) {
534
+ return operationId === this.clipboardOperationId && !this.table.isReleased;
535
+ }
536
+ isPasteOperationCurrent(operationId) {
537
+ return (void 0 === operationId || operationId === this.pasteOperationId) && !this.table.isReleased;
538
+ }
539
+ queueClipboardWrite(write) {
540
+ return __awaiter(this, void 0, void 0, (function*() {
541
+ const previousWrite = this.clipboardWritePromise;
542
+ let settleCurrentWrite = () => {};
543
+ this.clipboardWritePromise = previousWrite.catch((() => {})).then((() => new Promise((resolve => {
544
+ settleCurrentWrite = resolve;
545
+ })))), yield previousWrite.catch((() => {}));
546
+ try {
547
+ return yield write();
548
+ } finally {
549
+ settleCurrentWrite();
550
+ }
351
551
  }));
352
552
  }
353
- fallbackCopyToClipboard(data, e) {
553
+ isClipboardDataChanged(clipboardData, cutState) {
554
+ if (!clipboardData || clipboardData.readFailed) return null;
555
+ const sourceData = cutState.clipboardData;
556
+ if (!sourceData) return this.getClipboardSignature(clipboardData) !== cutState.clipboardSignature;
557
+ if (sourceData.hasHtml && !clipboardData.hasHtml) return null;
558
+ if (sourceData.hasText && !clipboardData.hasText) return null;
559
+ let hasComparableType = !1;
560
+ return !(!clipboardData.hasHtml || !sourceData.hasHtml || (hasComparableType = !0,
561
+ clipboardData.html === sourceData.html)) || (!(!clipboardData.hasText || !sourceData.hasText || (hasComparableType = !0,
562
+ clipboardData.text === sourceData.text)) || !hasComparableType && null);
563
+ }
564
+ isClipboardDataSameAsLastCopy(clipboardData) {
565
+ const sourceData = this.lastCopiedClipboardData;
566
+ return !(!clipboardData || clipboardData.readFailed || !sourceData) && this.isClipboardDataSameBySignature(clipboardData, sourceData);
567
+ }
568
+ isClipboardDataSameBySignature(clipboardData, sourceData) {
569
+ return !(sourceData.hasHtml !== clipboardData.hasHtml || sourceData.hasText !== clipboardData.hasText || sourceData.hasHtml && sourceData.html !== clipboardData.html || sourceData.hasText && sourceData.text !== clipboardData.text);
570
+ }
571
+ getCopyFormulaPlainData(data, isCut) {
572
+ var _a, _b;
573
+ const table = this.table;
574
+ if (1 !== table.stateManager.select.ranges.length || !(null === (_b = null === (_a = table.options.keyboardOptions) || void 0 === _a ? void 0 : _a.getCopyCellValue) || void 0 === _b ? void 0 : _b.html)) return data;
575
+ try {
576
+ return this.table.getCopyValue(table.options.keyboardOptions.getCopyCellValue.html);
577
+ } catch (error) {
578
+ return isCut ? null : data;
579
+ }
580
+ }
581
+ getCopyDataHTML(data) {
582
+ var _a, _b, _c;
583
+ const table = this.table;
584
+ let htmlValues = data;
585
+ try {
586
+ return 1 === table.stateManager.select.ranges.length && (null === (_b = null === (_a = table.options.keyboardOptions) || void 0 === _a ? void 0 : _a.getCopyCellValue) || void 0 === _b ? void 0 : _b.html) && (htmlValues = this.table.getCopyValue(null === (_c = table.options.keyboardOptions) || void 0 === _c ? void 0 : _c.getCopyCellValue.html)),
587
+ setDataToHTML(htmlValues);
588
+ } catch (error) {
589
+ try {
590
+ return setDataToHTML(data);
591
+ } catch (fallbackError) {
592
+ return null;
593
+ }
594
+ }
595
+ }
596
+ createInternalFormulaHtmlMarker() {
597
+ return `vtable-formula-${Date.now()}-${++this.internalFormulaHtmlMarkerId}`;
598
+ }
599
+ attachInternalFormulaHtmlMarker(html, marker) {
600
+ return `${html}\x3c!--${marker}--\x3e`;
601
+ }
602
+ setCopyDataToEventClipboard(data, dataHTML, e, internalFormulaText, internalFormulaHtmlMarker) {
603
+ const clipboardData = e.clipboardData;
604
+ if (!clipboardData) return null;
605
+ try {
606
+ clipboardData.setData("text/plain", data);
607
+ const copiedClipboardData = {
608
+ html: "",
609
+ text: data,
610
+ hasText: !0,
611
+ internalFormulaText: internalFormulaText
612
+ };
613
+ if (dataHTML) try {
614
+ clipboardData.setData("text/html", dataHTML), copiedClipboardData.html = dataHTML,
615
+ copiedClipboardData.hasHtml = !0, copiedClipboardData.internalFormulaHtmlMarker = internalFormulaHtmlMarker;
616
+ } catch (error) {}
617
+ return copiedClipboardData;
618
+ } catch (error) {
619
+ return null;
620
+ }
621
+ }
622
+ fallbackCopyToClipboard(data) {
354
623
  try {
355
- if (e.clipboardData) return void e.clipboardData.setData("text/plain", data);
356
624
  document.activeElement && document.activeElement !== document.body && document.activeElement.blur();
357
625
  const textArea = document.createElement("textarea");
358
626
  textArea.value = data, textArea.style.position = "fixed", textArea.style.left = "-999999px",
@@ -360,197 +628,430 @@ export class EventManager {
360
628
  textArea.setAttribute("aria-hidden", "true"), document.body.appendChild(textArea),
361
629
  textArea.focus(), textArea.select(), textArea.setSelectionRange(0, data.length);
362
630
  try {
363
- document.execCommand("copy");
631
+ const successful = document.execCommand("copy");
632
+ return successful;
364
633
  } catch (execError) {} finally {
365
634
  document.body.removeChild(textArea);
366
635
  }
367
636
  } catch (error) {}
637
+ return !1;
368
638
  }
369
639
  handleCut(e) {
370
- var _a;
371
640
  return __awaiter(this, void 0, void 0, (function*() {
372
- this.handleCopy(e, !0), this.cutWaitPaste = !0, this.cutCellRange = this.table.getSelectedCellInfos(),
373
- this.cutRanges = null === (_a = this.table.stateManager.select.ranges) || void 0 === _a ? void 0 : _a.map((r => ({
374
- start: {
375
- col: r.start.col,
376
- row: r.start.row
377
- },
378
- end: {
379
- col: r.end.col,
380
- row: r.end.row
381
- }
382
- }))), this.clipboardCheckTimer && clearTimeout(this.clipboardCheckTimer), this.clipboardCheckTimer = window.setTimeout((() => {
383
- this.cutWaitPaste && (this.cutWaitPaste = !1, this.cutCellRange = null, this.cutRanges = null,
384
- this.clipboardCheckTimer = null);
385
- }), 3e4), this.saveClipboardContent();
641
+ const copySnapshot = yield this.handleCopy(e, !0);
642
+ if (!copySnapshot) return;
643
+ const cutState = {
644
+ id: ++this.cutOperationId,
645
+ ranges: this.cloneRanges(copySnapshot.ranges),
646
+ cellInfos: copySnapshot.cellInfos,
647
+ sourceCells: copySnapshot.sourceCells,
648
+ sourceCellMatrix: copySnapshot.sourceCellMatrix,
649
+ sourceColCount: copySnapshot.sourceColCount,
650
+ sourceRowCount: copySnapshot.sourceRowCount,
651
+ clipboardData: copySnapshot.clipboardData,
652
+ clipboardSignature: copySnapshot.clipboardSignature,
653
+ copySourceRange: copySnapshot.copySourceRange,
654
+ isSingleRange: 1 === copySnapshot.ranges.length
655
+ };
656
+ this.cutWaitPaste = !0, this.activeCutState = cutState, this.cutCellRange = cutState.cellInfos,
657
+ this.cutRanges = cutState.ranges, this.clipboardCheckTimer && clearTimeout(this.clipboardCheckTimer),
658
+ this.clipboardCheckTimer = window.setTimeout((() => {
659
+ this.cutWaitPaste && this.resetCutState();
660
+ }), 3e4), this.lastClipboardContent = cutState.clipboardSignature;
386
661
  }));
387
662
  }
388
663
  handlePaste(e) {
389
- this.cutWaitPaste ? this.checkClipboardChanged().then((changed => {
390
- this.executePaste(e), changed || this.clearCutArea(this.table), this.cutWaitPaste && (this.cutWaitPaste = !1,
391
- this.cutCellRange = null, this.cutRanges = null, this.clipboardCheckTimer && (clearTimeout(this.clipboardCheckTimer),
392
- this.clipboardCheckTimer = null));
393
- })).catch((() => {
394
- this.executePaste(e), this.cutWaitPaste && (this.cutWaitPaste = !1, this.cutCellRange = null,
395
- this.clipboardCheckTimer && (clearTimeout(this.clipboardCheckTimer), this.clipboardCheckTimer = null));
396
- })) : this.executePaste(e);
397
- }
398
- executePaste(e) {
399
- var _a, _b, _c;
664
+ const pasteOperationId = ++this.pasteOperationId, pasteRange = this.getPasteRange();
665
+ if (!pasteRange) return;
666
+ const eventClipboardData = this.getEventClipboardData(e), pasteCopySourceRange = this.copySourceRange;
667
+ if (!this.cutWaitPaste) return void this.readClipboardDataForPaste(eventClipboardData).then((clipboardData => {
668
+ if (!this.isPasteOperationCurrent(pasteOperationId)) return;
669
+ const copySourceRange = this.isClipboardDataSameAsLastCopy(clipboardData) ? pasteCopySourceRange : null;
670
+ this.executePaste(clipboardData, {
671
+ pasteRange: pasteRange,
672
+ copySourceRange: copySourceRange,
673
+ pasteOperationId: pasteOperationId
674
+ });
675
+ })).catch((error => {}));
676
+ const cutState = this.activeCutState;
677
+ cutState ? this.readClipboardDataForPaste(eventClipboardData).then((clipboardData => __awaiter(this, void 0, void 0, (function*() {
678
+ var _a, _b, _c, _d, _e;
679
+ if (!this.isPasteOperationCurrent(pasteOperationId) || (null === (_a = this.activeCutState) || void 0 === _a ? void 0 : _a.id) !== cutState.id) return;
680
+ const changed = this.isClipboardDataChanged(clipboardData, cutState);
681
+ if (null === changed) return void (yield this.executePaste(clipboardData, {
682
+ pasteRange: pasteRange,
683
+ copySourceRange: this.isClipboardDataSameAsLastCopy(clipboardData) ? pasteCopySourceRange : null,
684
+ pasteOperationId: pasteOperationId
685
+ }));
686
+ const pasteResult = yield this.executePaste(clipboardData, {
687
+ pasteRange: pasteRange,
688
+ copySourceRange: changed ? null : cutState.copySourceRange,
689
+ cutState: changed ? null : cutState,
690
+ pasteOperationId: pasteOperationId
691
+ });
692
+ if (this.isPasteOperationCurrent(pasteOperationId) && (null === (_b = this.activeCutState) || void 0 === _b ? void 0 : _b.id) === cutState.id) if (changed || !pasteResult.pasted || (null === (_c = this.activeCutState) || void 0 === _c ? void 0 : _c.id) !== cutState.id) changed && (null === (_e = this.activeCutState) || void 0 === _e ? void 0 : _e.id) === cutState.id && this.resetCutState(); else if (pasteResult.migratedSourceCells.length === cutState.sourceCells.length) {
693
+ if (!(yield this.clearCutArea(pasteResult.migratedSourceCells, pasteResult.changedCells))) return void this.resetCutState();
694
+ (null === (_d = this.activeCutState) || void 0 === _d ? void 0 : _d.id) === cutState.id && this.resetCutState();
695
+ }
696
+ })))).catch((() => __awaiter(this, void 0, void 0, (function*() {
697
+ this.isPasteOperationCurrent(pasteOperationId) && (yield this.executePaste(eventClipboardData, {
698
+ pasteRange: pasteRange,
699
+ copySourceRange: this.isClipboardDataSameAsLastCopy(eventClipboardData) ? pasteCopySourceRange : null,
700
+ pasteOperationId: pasteOperationId
701
+ }));
702
+ })))) : this.executePaste(eventClipboardData, {
703
+ pasteRange: pasteRange,
704
+ copySourceRange: this.isClipboardDataSameAsLastCopy(eventClipboardData) ? pasteCopySourceRange : null,
705
+ pasteOperationId: pasteOperationId
706
+ });
707
+ }
708
+ executePaste(clipboardData, pasteContext) {
709
+ var _a, _b, _c, _d;
400
710
  return __awaiter(this, void 0, void 0, (function*() {
401
- const table = this.table;
402
- if (!(null === (_a = table.editorManager) || void 0 === _a ? void 0 : _a.editingEditor)) {
403
- if (table.changeCellValues && (null === (_b = table.stateManager.select.ranges) || void 0 === _b ? void 0 : _b.length) > 0) try {
404
- if (navigator.clipboard && navigator.clipboard.read) try {
405
- const clipboardItems = yield navigator.clipboard.read();
406
- let handled = !1;
407
- for (const item of clipboardItems) {
408
- if (item.types.includes("text/html")) {
409
- yield this.pasteHtmlToTable(item), handled = !0;
410
- break;
411
- }
412
- if (item.types.includes("text/plain")) {
413
- yield this.pasteTextToTable(item), handled = !0;
414
- break;
415
- }
416
- }
417
- handled || (yield this.fallbackPasteFromClipboard(e));
418
- } catch (clipboardError) {
419
- yield this.fallbackPasteFromClipboard(e);
420
- } else yield this.fallbackPasteFromClipboard(e);
711
+ const table = this.table, emptyResult = this.getEmptyPasteResult(), pasteClipboardData = this.getPasteClipboardData(clipboardData, pasteContext);
712
+ if (!this.isPasteOperationCurrent(pasteContext.pasteOperationId) || (null === (_a = table.editorManager) || void 0 === _a ? void 0 : _a.editingEditor)) return emptyResult;
713
+ if (this.pasteWriteInProgress && (yield this.pasteWritePromise.catch((() => {})),
714
+ !this.isPasteOperationCurrent(pasteContext.pasteOperationId) || (null === (_b = table.editorManager) || void 0 === _b ? void 0 : _b.editingEditor))) return emptyResult;
715
+ let pasteResult = emptyResult, settlePasteWrite = () => {};
716
+ this.pasteWritePromise = new Promise((resolve => {
717
+ settlePasteWrite = resolve;
718
+ })), this.pasteWriteInProgress = !0;
719
+ try {
720
+ if (table.changeCellValues) try {
721
+ if (null == pasteClipboardData ? void 0 : pasteClipboardData.html) try {
722
+ const htmlResult = yield this.processPastedHTML(pasteClipboardData.html, pasteContext);
723
+ if (htmlResult.pasted) return pasteResult = htmlResult, pasteResult;
724
+ } catch (error) {
725
+ if (/<table\b/i.test(pasteClipboardData.html)) return emptyResult;
726
+ }
727
+ if ((null == pasteClipboardData ? void 0 : pasteClipboardData.hasText) || (null == pasteClipboardData ? void 0 : pasteClipboardData.text)) return pasteResult = yield this.processPastedText(null !== (_c = pasteClipboardData.internalFormulaText) && void 0 !== _c ? _c : pasteClipboardData.text, pasteContext),
728
+ pasteResult;
421
729
  } catch (error) {
422
- yield this.fallbackPasteFromClipboard(e);
730
+ pasteContext.cutState && this.resetCutState();
423
731
  }
424
- (null === (_c = table.keyboardOptions) || void 0 === _c ? void 0 : _c.showCopyCellBorder) && clearActiveCellRangeState(table);
732
+ return pasteResult;
733
+ } finally {
734
+ this.pasteWriteInProgress = !1, settlePasteWrite(), !pasteContext.cutState && (null === (_d = table.keyboardOptions) || void 0 === _d ? void 0 : _d.showCopyCellBorder) && clearActiveCellRangeState(table);
425
735
  }
426
736
  }));
427
737
  }
428
- fallbackPasteFromClipboard(e) {
738
+ getPasteClipboardData(clipboardData, pasteContext) {
739
+ var _a, _b;
740
+ if (!clipboardData || !pasteContext.copySourceRange) return clipboardData;
741
+ const sourceData = null !== (_b = null === (_a = pasteContext.cutState) || void 0 === _a ? void 0 : _a.clipboardData) && void 0 !== _b ? _b : this.lastCopiedClipboardData;
742
+ return (null == sourceData ? void 0 : sourceData.internalFormulaText) && sourceData.internalFormulaHtmlMarker && sourceData.hasHtml && clipboardData.hasHtml && this.isClipboardDataSameBySignature(clipboardData, sourceData) && clipboardData.html.includes(sourceData.internalFormulaHtmlMarker) ? Object.assign(Object.assign({}, clipboardData), {
743
+ internalFormulaText: sourceData.internalFormulaText
744
+ }) : clipboardData;
745
+ }
746
+ getPasteRange() {
747
+ const ranges = this.table.stateManager.select.ranges;
748
+ if (!(null == ranges ? void 0 : ranges.length)) return null;
749
+ const range = ranges[ranges.length - 1];
750
+ return {
751
+ col: Math.min(range.start.col, range.end.col),
752
+ row: Math.min(range.start.row, range.end.row),
753
+ maxCol: Math.max(range.start.col, range.end.col),
754
+ maxRow: Math.max(range.start.row, range.end.row)
755
+ };
756
+ }
757
+ getEventClipboardData(e) {
758
+ var _a;
759
+ const clipboardData = e.clipboardData || window.clipboardData;
760
+ if (!clipboardData) return null;
761
+ try {
762
+ const types = Array.from(null !== (_a = clipboardData.types) && void 0 !== _a ? _a : []), html = clipboardData.getData("text/html") || "", text = clipboardData.getData("text/plain") || clipboardData.getData("text") || clipboardData.getData("Text") || "", hasHtml = types.includes("text/html") || !!html;
763
+ return {
764
+ html: html,
765
+ text: text,
766
+ hasHtml: hasHtml,
767
+ hasText: types.includes("text/plain") || types.includes("text") || types.includes("Text") || !!text
768
+ };
769
+ } catch (error) {
770
+ return {
771
+ html: "",
772
+ text: "",
773
+ readFailed: !0
774
+ };
775
+ }
776
+ }
777
+ readClipboardDataForPaste(eventClipboardData) {
778
+ var _a, _b;
429
779
  return __awaiter(this, void 0, void 0, (function*() {
430
- 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);
431
- try {
432
- const element = table.getElement();
433
- element && element !== document.activeElement && (element.focus(), yield new Promise((resolve => setTimeout(resolve, 10))));
434
- const clipboardData = e.clipboardData || window.clipboardData || window.Clipboard;
435
- if (clipboardData) {
436
- const pastedData = clipboardData.getData("text") || clipboardData.getData("Text");
437
- if (pastedData) return void (yield this.processPastedText(pastedData, col, row));
780
+ if ((null == eventClipboardData ? void 0 : eventClipboardData.readFailed) || (null == eventClipboardData ? void 0 : eventClipboardData.hasHtml) || (null == eventClipboardData ? void 0 : eventClipboardData.hasText)) return eventClipboardData;
781
+ if (null === (_a = navigator.clipboard) || void 0 === _a ? void 0 : _a.read) try {
782
+ const clipboardItems = yield navigator.clipboard.read(), clipboardData = {
783
+ html: "",
784
+ text: ""
785
+ };
786
+ for (const item of clipboardItems) {
787
+ if (!clipboardData.html && item.types.includes("text/html")) try {
788
+ clipboardData.html = yield (yield item.getType("text/html")).text(), clipboardData.hasHtml = !0;
789
+ } catch (error) {}
790
+ if (!clipboardData.text && item.types.includes("text/plain")) try {
791
+ clipboardData.text = yield (yield item.getType("text/plain")).text(), clipboardData.hasText = !0;
792
+ } catch (error) {}
438
793
  }
794
+ if (clipboardData.hasHtml || clipboardData.hasText) return clipboardData;
439
795
  } catch (error) {}
796
+ if (null === (_b = navigator.clipboard) || void 0 === _b ? void 0 : _b.readText) try {
797
+ return {
798
+ html: "",
799
+ text: yield navigator.clipboard.readText(),
800
+ hasText: !0
801
+ };
802
+ } catch (error) {}
803
+ return null != eventClipboardData ? eventClipboardData : {
804
+ html: "",
805
+ text: "",
806
+ readFailed: !0
807
+ };
440
808
  }));
441
809
  }
442
- processPastedText(pastedData, col, row) {
810
+ decodeHTMLCellValue(cellHTML) {
443
811
  var _a;
444
- return __awaiter(this, void 0, void 0, (function*() {
445
- const table = this.table, rows = pastedData.split("\n"), values = [];
446
- let processedValues;
447
- rows.forEach((function(rowCells) {
448
- const cells = rowCells.split("\t"), rowValues = [];
449
- values.push(rowValues), cells.forEach((function(cell, cellIndex) {
450
- cellIndex === cells.length - 1 && (cell = cell.trim()), rowValues.push(cell);
451
- }));
452
- })), (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));
453
- const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
454
- table.hasListeners(TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE.PASTED_DATA, {
455
- col: col,
456
- row: row,
457
- pasteData: processedValues || values,
458
- changedCellResults: changedCellResults
459
- });
460
- }));
812
+ const template = document.createElement("template");
813
+ return template.innerHTML = cellHTML.replace(/<br\b[^>]*>(?:\r\n|\r|\n)?/gim, "\n").replace(/&nbsp;/gi, " "),
814
+ null !== (_a = template.content.textContent) && void 0 !== _a ? _a : "";
461
815
  }
462
- clearCutArea(table) {
463
- try {
464
- const ranges = this.cutRanges;
465
- if (!ranges || 0 === ranges.length) return;
466
- table.changeCellValuesByRanges(ranges, "");
467
- } catch (error) {}
468
- }
469
- checkClipboardChanged() {
816
+ processPastedHTML(pastedData, pasteContext) {
817
+ var _a, _b, _c;
470
818
  return __awaiter(this, void 0, void 0, (function*() {
471
- if (!navigator.clipboard || !navigator.clipboard.readText) return !1;
472
- try {
473
- return (yield navigator.clipboard.readText()) !== this.lastClipboardContent;
474
- } catch (err) {
475
- return !1;
819
+ const cellRegex = /<t[dh][^>]*>([\s\S]*?)<\/t[dh]>/gi, table = this.table, pasteRange = pasteContext.pasteRange, {col: col, row: row, maxCol: maxCol, maxRow: maxRow} = pasteRange;
820
+ let pasteValuesColCount = 0, pasteValuesRowCount = 0, values = [];
821
+ if (!pastedData || !/<table\b/i.test(pastedData)) return this.getEmptyPasteResult();
822
+ const matches = Array.from(pastedData.matchAll(/<tr[^>]*>([\s\S]*?)<\/tr>/gi));
823
+ for (const match of matches) {
824
+ const rowContent = match[1], cellMatches = Array.from(rowContent.matchAll(cellRegex));
825
+ if (!cellMatches.length) continue;
826
+ const rowValues = cellMatches.map((cellMatch => this.decodeHTMLCellValue(cellMatch[1])));
827
+ values.push(rowValues), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
476
828
  }
829
+ if (pasteValuesRowCount = null !== (_b = values.length) && void 0 !== _b ? _b : 0,
830
+ !pasteValuesRowCount || !pasteValuesColCount) return this.getEmptyPasteResult();
831
+ let processedValues;
832
+ values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1),
833
+ (null === (_c = table.options.keyboardOptions) || void 0 === _c ? void 0 : _c.processFormulaBeforePaste) && pasteContext.copySourceRange && (processedValues = table.options.keyboardOptions.processFormulaBeforePaste(values, pasteContext.copySourceRange.startCol, pasteContext.copySourceRange.startRow, col, row));
834
+ const valuesToPaste = processedValues || values, targetCells = this.getPasteTargetCells(pasteRange, valuesToPaste);
835
+ if (!this.isPasteOperationCurrent(pasteContext.pasteOperationId)) return this.getEmptyPasteResult();
836
+ if (pasteContext.cutState) {
837
+ const validatedCellResults = yield this.validatePasteTargetCells(pasteRange, valuesToPaste);
838
+ if (!this.isPasteOperationCurrent(pasteContext.pasteOperationId)) return this.getEmptyPasteResult();
839
+ if (!this.isFullPasteAllowed(valuesToPaste, validatedCellResults)) return this.getEmptyPasteResult(validatedCellResults);
840
+ }
841
+ const rawChangedCellResults = yield table.changeCellValues(col, row, valuesToPaste, !pasteContext.cutState, !0, void 0, (() => !this.isPasteOperationCurrent(pasteContext.pasteOperationId)));
842
+ if (!this.isPasteOperationCurrent(pasteContext.pasteOperationId)) return this.getEmptyPasteResult();
843
+ const changedCellResults = this.normalizeChangedCellResults(rawChangedCellResults, pasteRange, valuesToPaste), changedCells = this.getChangedCells(targetCells, changedCellResults), migratedSourceCells = this.getMigratedSourceCells(pasteContext.cutState, changedCellResults);
844
+ return changedCells.length ? (this.firePastedDataEvent(col, row, valuesToPaste, changedCellResults),
845
+ {
846
+ pasted: !0,
847
+ changedCellResults: changedCellResults,
848
+ changedCells: changedCells,
849
+ migratedSourceCells: migratedSourceCells
850
+ }) : this.getEmptyPasteResult(changedCellResults);
477
851
  }));
478
852
  }
479
- saveClipboardContent() {
480
- navigator.clipboard && navigator.clipboard.readText && setTimeout((() => {
481
- navigator.clipboard.readText().then((text => {
482
- this.lastClipboardContent = text;
483
- })).catch((err => {}));
484
- }), 50);
485
- }
486
- pasteHtmlToTable(item) {
487
- const regex = /<tr[^>]*>([\s\S]*?)<\/tr>/g, cellRegex = /<td[^>]*>([\s\S]*?)<\/td>/g, 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);
488
- let pasteValuesColCount = 0, pasteValuesRowCount = 0, values = [];
489
- item.getType("text/html").then((blob => {
490
- blob.text().then((pastedData => __awaiter(this, void 0, void 0, (function*() {
491
- var _a, _b, _c;
492
- if (pastedData && /(<table)|(<TABLE)/g.test(pastedData)) {
493
- const matches = Array.from(pastedData.matchAll(regex));
494
- for (const match of matches) {
495
- 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, " ")));
496
- values.push(rowValues), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
497
- }
498
- let processedValues;
499
- pasteValuesRowCount = null !== (_b = values.length) && void 0 !== _b ? _b : 0, values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1),
500
- (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));
501
- const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
502
- table.hasListeners(TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE.PASTED_DATA, {
503
- col: col,
504
- row: row,
505
- pasteData: processedValues || values,
506
- changedCellResults: changedCellResults
507
- });
508
- } else navigator.clipboard.read().then((clipboardItems => {
509
- for (const item of clipboardItems) item.types.includes("text/plain") && item.getType("text/plain").then((blob => {
510
- blob.text().then((data => this._pasteValue(data)));
511
- }));
512
- }));
513
- }))));
514
- }));
515
- }
516
- _pasteValue(pastedData) {
517
- var _a, _b;
853
+ processPastedText(pastedData, pasteContext) {
854
+ var _a;
518
855
  return __awaiter(this, void 0, void 0, (function*() {
519
- 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);
520
- let pasteValuesColCount = 0, pasteValuesRowCount = 0, values = [];
856
+ const table = this.table, pasteRange = pasteContext.pasteRange, {col: col, row: row, maxCol: maxCol, maxRow: maxRow} = pasteRange;
857
+ let values = this.parsePlainTextPastedData(pastedData);
858
+ const pasteValuesRowCount = values.length, pasteValuesColCount = Math.max(...values.map((rowValues => rowValues.length)));
859
+ if (!pasteValuesRowCount || !pasteValuesColCount) return this.getEmptyPasteResult();
521
860
  let processedValues;
522
- pastedData.split("\n").forEach((function(rowCells, rowIndex) {
523
- var _a;
524
- const cells = rowCells.split("\t"), rowValues = [];
525
- values.push(rowValues), cells.forEach((function(cell, cellIndex) {
526
- cellIndex === cells.length - 1 && (cell = cell.trim()), rowValues.push(cell);
527
- })), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
528
- })), pasteValuesRowCount = null !== (_a = values.length) && void 0 !== _a ? _a : 0,
529
861
  values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1),
530
- (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));
531
- const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
532
- table.hasListeners(TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE.PASTED_DATA, {
862
+ (null === (_a = table.options.keyboardOptions) || void 0 === _a ? void 0 : _a.processFormulaBeforePaste) && pasteContext.copySourceRange && (processedValues = table.options.keyboardOptions.processFormulaBeforePaste(values, pasteContext.copySourceRange.startCol, pasteContext.copySourceRange.startRow, col, row));
863
+ const valuesToPaste = processedValues || values, targetCells = this.getPasteTargetCells(pasteRange, valuesToPaste);
864
+ if (!this.isPasteOperationCurrent(pasteContext.pasteOperationId)) return this.getEmptyPasteResult();
865
+ if (pasteContext.cutState) {
866
+ const validatedCellResults = yield this.validatePasteTargetCells(pasteRange, valuesToPaste);
867
+ if (!this.isPasteOperationCurrent(pasteContext.pasteOperationId)) return this.getEmptyPasteResult();
868
+ if (!this.isFullPasteAllowed(valuesToPaste, validatedCellResults)) return this.getEmptyPasteResult(validatedCellResults);
869
+ }
870
+ const rawChangedCellResults = yield table.changeCellValues(col, row, valuesToPaste, !pasteContext.cutState, !0, void 0, (() => !this.isPasteOperationCurrent(pasteContext.pasteOperationId)));
871
+ if (!this.isPasteOperationCurrent(pasteContext.pasteOperationId)) return this.getEmptyPasteResult();
872
+ const changedCellResults = this.normalizeChangedCellResults(rawChangedCellResults, pasteRange, valuesToPaste), changedCells = this.getChangedCells(targetCells, changedCellResults), migratedSourceCells = this.getMigratedSourceCells(pasteContext.cutState, changedCellResults);
873
+ return changedCells.length ? (this.firePastedDataEvent(col, row, valuesToPaste, changedCellResults),
874
+ {
875
+ pasted: !0,
876
+ changedCellResults: changedCellResults,
877
+ changedCells: changedCells,
878
+ migratedSourceCells: migratedSourceCells
879
+ }) : this.getEmptyPasteResult(changedCellResults);
880
+ }));
881
+ }
882
+ firePastedDataEvent(col, row, pasteData, changedCellResults) {
883
+ const table = this.table;
884
+ if (table.hasListeners(TABLE_EVENT_TYPE.PASTED_DATA)) try {
885
+ table.fireListeners(TABLE_EVENT_TYPE.PASTED_DATA, {
533
886
  col: col,
534
887
  row: row,
535
- pasteData: processedValues || values,
888
+ pasteData: pasteData,
536
889
  changedCellResults: changedCellResults
537
890
  });
891
+ } catch (error) {}
892
+ }
893
+ getEmptyPasteResult(changedCellResults = []) {
894
+ return {
895
+ pasted: !1,
896
+ changedCellResults: changedCellResults,
897
+ changedCells: [],
898
+ migratedSourceCells: []
899
+ };
900
+ }
901
+ getPasteTargetCells(pasteRange, values) {
902
+ const targetCells = [];
903
+ for (let rowIndex = 0; rowIndex < values.length; rowIndex++) {
904
+ targetCells[rowIndex] = [];
905
+ for (let colIndex = 0; colIndex < values[rowIndex].length; colIndex++) targetCells[rowIndex][colIndex] = this.getCellIdentity(pasteRange.col + colIndex, pasteRange.row + rowIndex);
906
+ }
907
+ return targetCells;
908
+ }
909
+ getChangedCells(targetCells, changedCellResults) {
910
+ var _a, _b, _c;
911
+ const changedCells = [];
912
+ for (let rowIndex = 0; rowIndex < changedCellResults.length; rowIndex++) for (let colIndex = 0; colIndex < (null !== (_b = null === (_a = changedCellResults[rowIndex]) || void 0 === _a ? void 0 : _a.length) && void 0 !== _b ? _b : 0); colIndex++) changedCellResults[rowIndex][colIndex] && (null === (_c = targetCells[rowIndex]) || void 0 === _c ? void 0 : _c[colIndex]) && changedCells.push(targetCells[rowIndex][colIndex]);
913
+ return changedCells;
914
+ }
915
+ normalizeChangedCellResults(changedCellResults, pasteRange, values) {
916
+ if (Array.isArray(changedCellResults)) return changedCellResults;
917
+ const table = this.table;
918
+ return values.map(((rowValues, rowIndex) => rowValues.map(((_value, colIndex) => {
919
+ const targetCol = pasteRange.col + colIndex, targetRow = pasteRange.row + rowIndex;
920
+ return targetCol < table.colCount && targetRow < table.rowCount && (!table.isHasEditorDefine || table.isHasEditorDefine(targetCol, targetRow));
921
+ }))));
922
+ }
923
+ validatePasteTargetCells(pasteRange, values) {
924
+ var _a, _b, _c, _d;
925
+ return __awaiter(this, void 0, void 0, (function*() {
926
+ const table = this.table, changedCellResults = [];
927
+ for (let rowIndex = 0; rowIndex < values.length; rowIndex++) {
928
+ changedCellResults[rowIndex] = [];
929
+ for (let colIndex = 0; colIndex < values[rowIndex].length; colIndex++) {
930
+ const targetCol = pasteRange.col + colIndex, targetRow = pasteRange.row + rowIndex, tableAny = table;
931
+ let canChange = targetCol < tableAny.colCount && targetRow < tableAny.rowCount && (!tableAny.isHasEditorDefine || tableAny.isHasEditorDefine(targetCol, targetRow));
932
+ if (canChange) {
933
+ const editor = null === (_a = tableAny.getEditor) || void 0 === _a ? void 0 : _a.call(tableAny, targetCol, targetRow), oldValue = null === (_b = table.getCellOriginValue) || void 0 === _b ? void 0 : _b.call(table, targetCol, targetRow), validateResult = null === (_d = null === (_c = null == editor ? void 0 : editor.validateValue) || void 0 === _c ? void 0 : _c.call(editor, values[rowIndex][colIndex], oldValue, {
934
+ col: targetCol,
935
+ row: targetRow
936
+ }, table)) || void 0 === _d || _d, resolvedValidateResult = validateResult && "function" == typeof validateResult.then ? yield validateResult : validateResult;
937
+ canChange = !0 === resolvedValidateResult || "validate-exit" === resolvedValidateResult || "validate-not-exit" === resolvedValidateResult;
938
+ }
939
+ changedCellResults[rowIndex][colIndex] = canChange;
940
+ }
941
+ }
942
+ return changedCellResults;
538
943
  }));
539
944
  }
540
- pasteTextToTable(item) {
945
+ isFullPasteAllowed(values, changedCellResults) {
946
+ return values.every(((rowValues, rowIndex) => rowValues.every(((_value, colIndex) => {
947
+ var _a;
948
+ return !0 === (null === (_a = changedCellResults[rowIndex]) || void 0 === _a ? void 0 : _a[colIndex]);
949
+ }))));
950
+ }
951
+ getMigratedSourceCells(cutState, changedCellResults) {
952
+ var _a, _b, _c, _d, _e;
953
+ if (!(null == cutState ? void 0 : cutState.sourceCells.length) || !cutState.sourceColCount || !cutState.sourceRowCount) return [];
954
+ const migratedSourceCells = [], migratedKeys = new Set;
955
+ if (!cutState.isSingleRange) {
956
+ for (let rowIndex = 0; rowIndex < changedCellResults.length; rowIndex++) for (let colIndex = 0; colIndex < (null !== (_b = null === (_a = changedCellResults[rowIndex]) || void 0 === _a ? void 0 : _a.length) && void 0 !== _b ? _b : 0); colIndex++) {
957
+ if (!changedCellResults[rowIndex][colIndex]) continue;
958
+ const sourceRow = rowIndex % cutState.sourceRowCount, sourceCol = colIndex % cutState.sourceColCount, sourceCell = null === (_c = cutState.sourceCellMatrix[sourceRow]) || void 0 === _c ? void 0 : _c[sourceCol];
959
+ if (!sourceCell) continue;
960
+ const sourceKey = this.getCellKey(sourceCell);
961
+ migratedKeys.has(sourceKey) || (migratedKeys.add(sourceKey), migratedSourceCells.push(sourceCell));
962
+ }
963
+ return migratedSourceCells.length === cutState.sourceCells.length ? migratedSourceCells : [];
964
+ }
965
+ for (let rowIndex = 0; rowIndex < changedCellResults.length; rowIndex++) for (let colIndex = 0; colIndex < (null !== (_e = null === (_d = changedCellResults[rowIndex]) || void 0 === _d ? void 0 : _d.length) && void 0 !== _e ? _e : 0); colIndex++) {
966
+ if (!changedCellResults[rowIndex][colIndex]) continue;
967
+ const sourceRow = rowIndex % cutState.sourceRowCount, sourceCol = colIndex % cutState.sourceColCount, sourceIndex = sourceRow * cutState.sourceColCount + sourceCol, sourceCell = cutState.sourceCells[sourceIndex];
968
+ if (!sourceCell) continue;
969
+ const sourceKey = this.getCellKey(sourceCell);
970
+ migratedKeys.has(sourceKey) || (migratedKeys.add(sourceKey), migratedSourceCells.push(sourceCell));
971
+ }
972
+ return migratedSourceCells;
973
+ }
974
+ getCellIdentity(col, row) {
975
+ var _a, _b, _c, _d, _e, _f, _g;
976
+ const table = this.table, recordShowIndex = null === (_a = table.getRecordShowIndexByCell) || void 0 === _a ? void 0 : _a.call(table, col, row);
977
+ return {
978
+ col: col,
979
+ row: row,
980
+ recordIndex: recordShowIndex >= 0 ? null === (_c = null === (_b = table.dataSource) || void 0 === _b ? void 0 : _b.getIndexKey) || void 0 === _c ? void 0 : _c.call(_b, recordShowIndex) : void 0,
981
+ field: null === (_g = null === (_f = null === (_e = null === (_d = table.internalProps) || void 0 === _d ? void 0 : _d.layoutMap) || void 0 === _e ? void 0 : _e.getBody) || void 0 === _f ? void 0 : _f.call(_e, col, row)) || void 0 === _g ? void 0 : _g.field
982
+ };
983
+ }
984
+ clearCutArea(migratedSourceCells, changedTargetCells) {
985
+ var _a, _b;
541
986
  return __awaiter(this, void 0, void 0, (function*() {
542
- 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);
543
987
  try {
544
- 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);
545
- table.hasListeners(TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE.PASTED_DATA, {
546
- col: col,
547
- row: row,
548
- pasteData: processedValues,
549
- changedCellResults: changedCellResults
988
+ const table = this.table, changedTargetKeys = new Set;
989
+ changedTargetCells.forEach((cell => {
990
+ changedTargetKeys.add(this.getCellKey(cell)), changedTargetKeys.add(this.getCoordKey(cell));
991
+ }));
992
+ const clearedKeys = new Set, sourceChanges = [], coordChanges = [];
993
+ for (let i = 0; i < migratedSourceCells.length; i++) {
994
+ const sourceCell = migratedSourceCells[i], sourceKey = this.getCellKey(sourceCell);
995
+ if (clearedKeys.has(sourceKey) || changedTargetKeys.has(sourceKey) || changedTargetKeys.has(this.getCoordKey(sourceCell))) continue;
996
+ const currentAddress = this.getCurrentCellAddress(sourceCell);
997
+ currentAddress && (this.isSourceCellUnchanged(sourceCell, currentAddress) && (void 0 !== sourceCell.recordIndex && void 0 !== sourceCell.field && table.changeCellValuesByRecords ? sourceChanges.push({
998
+ recordIndex: sourceCell.recordIndex,
999
+ field: sourceCell.field,
1000
+ value: ""
1001
+ }) : coordChanges.push(currentAddress), clearedKeys.add(sourceKey)));
1002
+ }
1003
+ sourceChanges.length && table.changeCellValuesByRecords(sourceChanges, {
1004
+ triggerEvent: !0,
1005
+ autoRefresh: !1
550
1006
  });
551
- } catch (error) {}
1007
+ for (let i = 0; i < coordChanges.length; i++) yield table.changeCellValues(coordChanges[i].col, coordChanges[i].row, [ [ "" ] ], !1);
1008
+ return sourceChanges.length && (null === (_b = (_a = table).refreshAfterSourceChange) || void 0 === _b || _b.call(_a)),
1009
+ !0;
1010
+ } catch (error) {
1011
+ return !1;
1012
+ }
552
1013
  }));
553
1014
  }
1015
+ isSourceCellUnchanged(sourceCell, currentAddress) {
1016
+ var _a;
1017
+ const table = this.table;
1018
+ return Object.is(null === (_a = table.getCellOriginValue) || void 0 === _a ? void 0 : _a.call(table, currentAddress.col, currentAddress.row), sourceCell.value);
1019
+ }
1020
+ getCurrentCellAddress(sourceCell) {
1021
+ const table = this.table;
1022
+ if (void 0 !== sourceCell.recordIndex && void 0 !== sourceCell.field && table.getCellAddrByFieldRecord) {
1023
+ const address = table.getCellAddrByFieldRecord(sourceCell.field, sourceCell.recordIndex);
1024
+ return address && address.col >= 0 && address.row >= 0 ? address : null;
1025
+ }
1026
+ return {
1027
+ col: sourceCell.col,
1028
+ row: sourceCell.row
1029
+ };
1030
+ }
1031
+ getCellKey(cell) {
1032
+ return void 0 !== cell.recordIndex && void 0 !== cell.field ? `record:${this.getStableKeyPart(cell.recordIndex)}:${this.getStableKeyPart(cell.field)}` : this.getCoordKey(cell);
1033
+ }
1034
+ getCoordKey(cell) {
1035
+ return `coord:${cell.col}:${cell.row}`;
1036
+ }
1037
+ getStableKeyPart(value) {
1038
+ if (null === value) return "null";
1039
+ const valueType = typeof value;
1040
+ if ("string" === valueType || "number" === valueType || "boolean" === valueType) return `${valueType}:${JSON.stringify(value)}`;
1041
+ if (Array.isArray(value)) return `array:[${value.map((item => this.getStableKeyPart(item))).join(",")}]`;
1042
+ if ("object" === valueType || "function" === valueType) {
1043
+ let id = this.fieldKeyIds.get(value);
1044
+ return void 0 === id && (id = ++this.fieldKeyId, this.fieldKeyIds.set(value, id)),
1045
+ `${valueType}:#${id}`;
1046
+ }
1047
+ return `${valueType}:${String(value)}`;
1048
+ }
1049
+ resetCutState() {
1050
+ var _a;
1051
+ this.cutWaitPaste = !1, this.activeCutState = null, this.cutCellRange = null, this.cutRanges = null,
1052
+ (null === (_a = this.table.keyboardOptions) || void 0 === _a ? void 0 : _a.showCopyCellBorder) && clearActiveCellRangeState(this.table),
1053
+ this.clipboardCheckTimer && (clearTimeout(this.clipboardCheckTimer), this.clipboardCheckTimer = null);
1054
+ }
554
1055
  parsePastedData(pastedData) {
555
1056
  const rows = pastedData.replace(/\r(?!\n)/g, "\r\n").split("\r\n"), values = [];
556
1057
  return rows.length > 1 && "" === rows[rows.length - 1] && rows.pop(), rows.forEach((rowCells => {
@@ -558,6 +1059,10 @@ export class EventManager {
558
1059
  values.push(rowValues);
559
1060
  })), values;
560
1061
  }
1062
+ parsePlainTextPastedData(pastedData) {
1063
+ const rows = pastedData.replace(/\r\n|\r/g, "\n").split("\n");
1064
+ return rows.length > 1 && "" === rows[rows.length - 1] && rows.pop(), rows.map((rowCells => rowCells.split("\t")));
1065
+ }
561
1066
  processCellValue(cell) {
562
1067
  cell.includes("\n") && (cell = cell.replace(/^"(.*)"$/, "$1").replace(/["]*/g, (match => new Array(Math.floor(match.length / 2)).fill('"').join(""))));
563
1068
  const numValue = Number(cell);
@@ -582,4 +1087,4 @@ export class EventManager {
582
1087
  return values;
583
1088
  }
584
1089
  }
585
- //# sourceMappingURL=event.js.map
1090
+ //# sourceMappingURL=event.js.map