@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
@@ -35,10 +35,14 @@ const vrender_1 = require("./../vrender"), TABLE_EVENT_TYPE_1 = require("../core
35
35
  class EventManager {
36
36
  constructor(table) {
37
37
  this.isDown = !1, this.isDraging = !1, this.globalEventListeners = [], this._enableTableScroll = !0,
38
- this.cutWaitPaste = !1, this.clipboardCheckTimer = null, this.cutOperationTime = 0,
39
- this.lastClipboardContent = "", this.cutCellRange = null, this.cutRanges = null,
40
- this.copySourceRange = null, this.table = table, this.handleTextStickBindId = [],
41
- this.inertiaScroll = new scroll_1.InertiaScroll(table.stateManager), "node" === env_1.Env.mode || table.options.disableInteraction || (this.bindOuterEvent(),
38
+ this.cutWaitPaste = !1, this.clipboardCheckTimer = null, this.cutOperationId = 0,
39
+ this.clipboardOperationId = 0, this.pasteOperationId = 0, this.pasteWriteInProgress = !1,
40
+ this.pasteWritePromise = Promise.resolve(), this.clipboardWritePromise = Promise.resolve(),
41
+ this.lastCopiedClipboardData = null, this.internalFormulaHtmlMarkerId = 0, this.fieldKeyIds = new WeakMap,
42
+ this.fieldKeyId = 0, this.activeCutState = null, this.lastClipboardContent = "",
43
+ this.cutCellRange = null, this.cutRanges = null, this.copySourceRange = null, this.table = table,
44
+ this.handleTextStickBindId = [], this.inertiaScroll = new scroll_1.InertiaScroll(table.stateManager),
45
+ "node" === env_1.Env.mode || table.options.disableInteraction || (this.bindOuterEvent(),
42
46
  setTimeout((() => {
43
47
  this.bindSelfEvent();
44
48
  }), 0));
@@ -245,7 +249,8 @@ class EventManager {
245
249
  }
246
250
  release() {
247
251
  var _a;
248
- null === (_a = this.gesture) || void 0 === _a || _a.release(), this.globalEventListeners.forEach((item => {
252
+ this.clipboardOperationId++, this.pasteOperationId++, this.resetCutState(), null === (_a = this.gesture) || void 0 === _a || _a.release(),
253
+ this.globalEventListeners.forEach((item => {
249
254
  "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 && vrender_1.vglobal.removeEventListener(item.name, item.callback);
250
255
  })), this.globalEventListeners = [];
251
256
  }
@@ -258,65 +263,329 @@ class EventManager {
258
263
  handleCopy(e, isCut = !1) {
259
264
  var _a, _b, _c, _d, _e, _f;
260
265
  return __awaiter(this, void 0, void 0, (function*() {
261
- const table = this.table;
262
- !isCut && (this.cutWaitPaste = !1), this.copySourceRange = null;
263
- const sourceRanges = table.stateManager.select.ranges;
264
- if (sourceRanges && 1 === sourceRanges.length) {
265
- const sourceRange = sourceRanges[0];
266
- this.copySourceRange = {
267
- startCol: Math.min(sourceRange.start.col, sourceRange.end.col),
268
- startRow: Math.min(sourceRange.start.row, sourceRange.end.row)
269
- };
270
- } else if (!(null == sourceRanges ? void 0 : sourceRanges.length)) return void (this.copySourceRange = null);
266
+ const table = this.table, operationId = ++this.clipboardOperationId;
267
+ this.pasteOperationId++, isCut || this.resetCutState();
268
+ const copySnapshot = this.getCopySnapshot(isCut);
269
+ if (this.copySourceRange = null, this.lastCopiedClipboardData = null, !copySnapshot) return this.copySourceRange = null,
270
+ null;
271
271
  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);
272
- if ((0, vutils_1.isValid)(data)) {
272
+ if (!(0, vutils_1.isValid)(data)) return null;
273
+ {
273
274
  e.preventDefault();
275
+ let copySucceeded = !1, copiedClipboardData = null;
276
+ 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);
277
+ if (null === formulaClipboardData) return null;
278
+ 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;
279
+ if (eventClipboardWriteData) return copiedClipboardData = eventClipboardWriteData,
280
+ this.lastCopiedClipboardData = copiedClipboardData, isCut && (this.lastClipboardContent = this.getClipboardSignature(copiedClipboardData),
281
+ copySnapshot.clipboardData = copiedClipboardData, copySnapshot.clipboardSignature = this.lastClipboardContent),
282
+ this.copySourceRange = copySnapshot.copySourceRange, this.afterCopyData(data, isCut, copySnapshot, !isCut),
283
+ isCut && (null === (_e = table.keyboardOptions) || void 0 === _e ? void 0 : _e.showCopyCellBorder) && window.setTimeout((() => {
284
+ this.isClipboardOperationCurrent(operationId) && ((0, style_1.setActiveCellRangeState)(table, copySnapshot.ranges),
285
+ table.clearSelected());
286
+ }), 0), copySnapshot;
274
287
  const element = table.getElement();
275
- element && element !== document.activeElement && (element.focus(), yield new Promise((resolve => setTimeout(resolve, 10))));
288
+ if (element && element !== document.activeElement && (element.focus(), yield new Promise((resolve => setTimeout(resolve, 10))),
289
+ !this.isClipboardOperationCurrent(operationId))) return null;
276
290
  try {
277
291
  if (navigator.clipboard && navigator.clipboard.writeText) {
278
292
  let hasPermission = !0;
279
293
  if (navigator.permissions && navigator.permissions.query) try {
280
- hasPermission = "granted" === (yield navigator.permissions.query({
294
+ if (hasPermission = "granted" === (yield navigator.permissions.query({
281
295
  name: "clipboard-write"
282
- })).state;
296
+ })).state, !this.isClipboardOperationCurrent(operationId)) return null;
283
297
  } catch (permissionError) {
284
298
  hasPermission = !0;
285
299
  }
286
300
  if (hasPermission) try {
287
- if (window.ClipboardItem) {
288
- let htmlValues = data;
289
- 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));
290
- const dataHTML = (0, util_1.setDataToHTML)(htmlValues);
291
- yield navigator.clipboard.write([ new ClipboardItem({
292
- "text/html": new Blob([ dataHTML ], {
301
+ if (!this.isClipboardOperationCurrent(operationId)) return null;
302
+ copiedClipboardData = yield this.queueClipboardWrite((() => __awaiter(this, void 0, void 0, (function*() {
303
+ return this.isClipboardOperationCurrent(operationId) ? canWriteRichClipboard && clipboardHTML ? (yield navigator.clipboard.write([ new ClipboardItem({
304
+ "text/html": new Blob([ clipboardHTML ], {
293
305
  type: "text/html"
294
306
  }),
295
- "text/plain": new Blob([ data ], {
307
+ "text/plain": new Blob([ plainClipboardData ], {
296
308
  type: "text/plain"
297
309
  })
298
- }) ]);
299
- } else yield navigator.clipboard.writeText(data);
310
+ }) ]), {
311
+ html: clipboardHTML,
312
+ text: plainClipboardData,
313
+ hasHtml: !0,
314
+ hasText: !0,
315
+ internalFormulaText: internalFormulaText,
316
+ internalFormulaHtmlMarker: internalFormulaHtmlMarker
317
+ }) : (yield navigator.clipboard.writeText(plainClipboardData), {
318
+ html: "",
319
+ text: plainClipboardData,
320
+ hasText: !0,
321
+ internalFormulaText: internalFormulaText
322
+ }) : null;
323
+ })))), copiedClipboardData && (copySucceeded = !0);
300
324
  } catch (clipboardError) {
301
- this.fallbackCopyToClipboard(data, e);
302
- } else this.fallbackCopyToClipboard(data, e);
303
- } else this.fallbackCopyToClipboard(data, e);
304
- table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.COPY_DATA, {
305
- cellRange: table.stateManager.select.ranges,
306
- copyData: data,
307
- isCut: isCut
325
+ if (!this.isClipboardOperationCurrent(operationId)) return null;
326
+ if (copySucceeded = this.fallbackCopyToClipboard(plainClipboardData), !this.isClipboardOperationCurrent(operationId)) return null;
327
+ copySucceeded && (copiedClipboardData = {
328
+ html: "",
329
+ text: plainClipboardData,
330
+ hasText: !0,
331
+ internalFormulaText: internalFormulaText
332
+ });
333
+ } else copySucceeded = this.fallbackCopyToClipboard(plainClipboardData), copySucceeded && (copiedClipboardData = {
334
+ html: "",
335
+ text: plainClipboardData,
336
+ hasText: !0,
337
+ internalFormulaText: internalFormulaText
338
+ });
339
+ } else copySucceeded = this.fallbackCopyToClipboard(plainClipboardData), copySucceeded && (copiedClipboardData = {
340
+ html: "",
341
+ text: plainClipboardData,
342
+ hasText: !0,
343
+ internalFormulaText: internalFormulaText
308
344
  });
345
+ if (!copySucceeded) return null;
346
+ if (!this.isClipboardOperationCurrent(operationId)) return null;
347
+ this.lastCopiedClipboardData = copiedClipboardData, isCut && (this.lastClipboardContent = this.getClipboardSignature(copiedClipboardData),
348
+ copySnapshot.clipboardData = copiedClipboardData, copySnapshot.clipboardSignature = this.lastClipboardContent),
349
+ this.copySourceRange = copySnapshot.copySourceRange, this.afterCopyData(data, isCut, copySnapshot, !1);
309
350
  } catch (error) {
310
- this.fallbackCopyToClipboard(data, e);
351
+ if (!this.isClipboardOperationCurrent(operationId)) return null;
352
+ if (!this.fallbackCopyToClipboard(plainClipboardData)) return null;
353
+ if (!this.isClipboardOperationCurrent(operationId)) return null;
354
+ this.lastCopiedClipboardData = {
355
+ html: "",
356
+ text: plainClipboardData,
357
+ hasText: !0,
358
+ internalFormulaText: internalFormulaText
359
+ }, isCut && (this.lastClipboardContent = this.getClipboardSignature(this.lastCopiedClipboardData),
360
+ copySnapshot.clipboardData = this.lastCopiedClipboardData, copySnapshot.clipboardSignature = this.lastClipboardContent),
361
+ this.copySourceRange = copySnapshot.copySourceRange, this.afterCopyData(data, isCut, copySnapshot, !1);
311
362
  }
312
363
  }
313
- (null === (_f = table.keyboardOptions) || void 0 === _f ? void 0 : _f.showCopyCellBorder) && ((0,
314
- style_1.setActiveCellRangeState)(table), table.clearSelected());
364
+ return (null === (_f = table.keyboardOptions) || void 0 === _f ? void 0 : _f.showCopyCellBorder) && ((0,
365
+ style_1.setActiveCellRangeState)(table, copySnapshot.ranges), table.clearSelected()),
366
+ copySnapshot;
367
+ }));
368
+ }
369
+ afterCopyData(data, isCut, copySnapshot, updateCopyCellBorder = !0) {
370
+ var _a;
371
+ const table = this.table;
372
+ try {
373
+ table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.COPY_DATA, {
374
+ cellRange: this.cloneRanges(copySnapshot.ranges),
375
+ copyData: data,
376
+ isCut: isCut
377
+ });
378
+ } catch (error) {}
379
+ updateCopyCellBorder && (null === (_a = table.keyboardOptions) || void 0 === _a ? void 0 : _a.showCopyCellBorder) && ((0,
380
+ style_1.setActiveCellRangeState)(table, copySnapshot.ranges), table.clearSelected());
381
+ }
382
+ getCopySnapshot(includeCellInfos) {
383
+ const ranges = this.table.stateManager.select.ranges;
384
+ if (!(null == ranges ? void 0 : ranges.length)) return null;
385
+ const clonedRanges = ranges.map((range => ({
386
+ start: {
387
+ col: range.start.col,
388
+ row: range.start.row
389
+ },
390
+ end: {
391
+ col: range.end.col,
392
+ row: range.end.row
393
+ }
394
+ }))), sourceRange = 1 === ranges.length ? ranges[0] : null, sourceCellMatrix = this.getSourceCellMatrix(clonedRanges), sourceCells = this.getSourceCells(sourceCellMatrix), sourceSize = this.getSourceSize(clonedRanges, sourceCellMatrix);
395
+ return {
396
+ ranges: clonedRanges,
397
+ copySourceRange: sourceRange ? {
398
+ startCol: Math.min(sourceRange.start.col, sourceRange.end.col),
399
+ startRow: Math.min(sourceRange.start.row, sourceRange.end.row)
400
+ } : null,
401
+ cellInfos: includeCellInfos ? this.table.getSelectedCellInfos() : null,
402
+ sourceCells: sourceCells,
403
+ sourceCellMatrix: sourceCellMatrix,
404
+ sourceColCount: sourceSize.colCount,
405
+ sourceRowCount: sourceSize.rowCount,
406
+ clipboardData: null,
407
+ clipboardSignature: ""
408
+ };
409
+ }
410
+ cloneRanges(ranges) {
411
+ return ranges.map((range => ({
412
+ start: {
413
+ col: range.start.col,
414
+ row: range.start.row
415
+ },
416
+ end: {
417
+ col: range.end.col,
418
+ row: range.end.row
419
+ }
420
+ })));
421
+ }
422
+ getSourceCellMatrix(ranges) {
423
+ const table = this.table, createSourceCell = (col, row) => {
424
+ var _a, _b, _c, _d, _e, _f, _g, _h;
425
+ const recordShowIndex = null === (_a = table.getRecordShowIndexByCell) || void 0 === _a ? void 0 : _a.call(table, col, row);
426
+ return {
427
+ col: col,
428
+ row: row,
429
+ 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,
430
+ 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,
431
+ value: null === (_h = table.getCellOriginValue) || void 0 === _h ? void 0 : _h.call(table, col, row)
432
+ };
433
+ };
434
+ if (1 === ranges.length) {
435
+ 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 = [];
436
+ for (let row = startRow; row <= endRow; row++) {
437
+ const rowCells = [];
438
+ for (let col = startCol; col <= endCol; col++) rowCells.push(createSourceCell(col, row));
439
+ sourceCellMatrix.push(rowCells);
440
+ }
441
+ return sourceCellMatrix;
442
+ }
443
+ 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);
444
+ ranges.forEach((range => {
445
+ minCol = Math.min(minCol, range.start.col, range.end.col), maxCol = Math.max(maxCol, range.start.col, range.end.col),
446
+ minRow = Math.min(minRow, range.start.row, range.end.row), maxRow = Math.max(maxRow, range.start.row, range.end.row);
447
+ }));
448
+ const isExistDataInRow = row => ranges.some((range => {
449
+ const startRow = Math.min(range.start.row, range.end.row), endRow = Math.max(range.start.row, range.end.row);
450
+ return startRow <= row && endRow >= row;
451
+ })), isExistDataInCol = col => ranges.some((range => {
452
+ const startCol = Math.min(range.start.col, range.end.col), endCol = Math.max(range.start.col, range.end.col);
453
+ return startCol <= col && endCol >= col;
454
+ })), getRangeExistDataInCell = (col, row) => ranges.some((range => {
455
+ 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);
456
+ return startCol <= col && endCol >= col && startRow <= row && endRow >= row;
457
+ })), sourceCellMatrix = [];
458
+ for (let row = minRow; row <= maxRow; row++) {
459
+ if (!isExistDataInRow(row)) continue;
460
+ const rowCells = [];
461
+ for (let col = minCol; col <= maxCol; col++) isExistDataInCol(col) && rowCells.push(getRangeExistDataInCell(col, row) ? createSourceCell(col, row) : null);
462
+ sourceCellMatrix.push(rowCells);
463
+ }
464
+ return sourceCellMatrix;
465
+ }
466
+ getSourceCells(sourceCellMatrix) {
467
+ const sourceCells = [];
468
+ for (let row = 0; row < sourceCellMatrix.length; row++) for (let col = 0; col < sourceCellMatrix[row].length; col++) {
469
+ const sourceCell = sourceCellMatrix[row][col];
470
+ sourceCell && sourceCells.push(sourceCell);
471
+ }
472
+ return sourceCells;
473
+ }
474
+ getSourceSize(ranges, sourceCellMatrix) {
475
+ var _a, _b;
476
+ if (sourceCellMatrix.length) return {
477
+ colCount: null !== (_b = null === (_a = sourceCellMatrix[0]) || void 0 === _a ? void 0 : _a.length) && void 0 !== _b ? _b : 0,
478
+ rowCount: sourceCellMatrix.length
479
+ };
480
+ if (1 === ranges.length) {
481
+ const range = ranges[0];
482
+ return {
483
+ colCount: Math.abs(range.end.col - range.start.col) + 1,
484
+ rowCount: Math.abs(range.end.row - range.start.row) + 1
485
+ };
486
+ }
487
+ return {
488
+ colCount: 0,
489
+ rowCount: 0
490
+ };
491
+ }
492
+ getClipboardSignature(data) {
493
+ return data ? JSON.stringify({
494
+ html: data.hasHtml ? data.html : null,
495
+ text: data.hasText ? data.text : null
496
+ }) : "";
497
+ }
498
+ isClipboardOperationCurrent(operationId) {
499
+ return operationId === this.clipboardOperationId && !this.table.isReleased;
500
+ }
501
+ isPasteOperationCurrent(operationId) {
502
+ return (void 0 === operationId || operationId === this.pasteOperationId) && !this.table.isReleased;
503
+ }
504
+ queueClipboardWrite(write) {
505
+ return __awaiter(this, void 0, void 0, (function*() {
506
+ const previousWrite = this.clipboardWritePromise;
507
+ let settleCurrentWrite = () => {};
508
+ this.clipboardWritePromise = previousWrite.catch((() => {})).then((() => new Promise((resolve => {
509
+ settleCurrentWrite = resolve;
510
+ })))), yield previousWrite.catch((() => {}));
511
+ try {
512
+ return yield write();
513
+ } finally {
514
+ settleCurrentWrite();
515
+ }
315
516
  }));
316
517
  }
317
- fallbackCopyToClipboard(data, e) {
518
+ isClipboardDataChanged(clipboardData, cutState) {
519
+ if (!clipboardData || clipboardData.readFailed) return null;
520
+ const sourceData = cutState.clipboardData;
521
+ if (!sourceData) return this.getClipboardSignature(clipboardData) !== cutState.clipboardSignature;
522
+ if (sourceData.hasHtml && !clipboardData.hasHtml) return null;
523
+ if (sourceData.hasText && !clipboardData.hasText) return null;
524
+ let hasComparableType = !1;
525
+ return !(!clipboardData.hasHtml || !sourceData.hasHtml || (hasComparableType = !0,
526
+ clipboardData.html === sourceData.html)) || (!(!clipboardData.hasText || !sourceData.hasText || (hasComparableType = !0,
527
+ clipboardData.text === sourceData.text)) || !hasComparableType && null);
528
+ }
529
+ isClipboardDataSameAsLastCopy(clipboardData) {
530
+ const sourceData = this.lastCopiedClipboardData;
531
+ return !(!clipboardData || clipboardData.readFailed || !sourceData) && this.isClipboardDataSameBySignature(clipboardData, sourceData);
532
+ }
533
+ isClipboardDataSameBySignature(clipboardData, sourceData) {
534
+ return !(sourceData.hasHtml !== clipboardData.hasHtml || sourceData.hasText !== clipboardData.hasText || sourceData.hasHtml && sourceData.html !== clipboardData.html || sourceData.hasText && sourceData.text !== clipboardData.text);
535
+ }
536
+ getCopyFormulaPlainData(data, isCut) {
537
+ var _a, _b;
538
+ const table = this.table;
539
+ 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;
540
+ try {
541
+ return this.table.getCopyValue(table.options.keyboardOptions.getCopyCellValue.html);
542
+ } catch (error) {
543
+ return isCut ? null : data;
544
+ }
545
+ }
546
+ getCopyDataHTML(data) {
547
+ var _a, _b, _c;
548
+ const table = this.table;
549
+ let htmlValues = data;
550
+ try {
551
+ 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)),
552
+ (0, util_1.setDataToHTML)(htmlValues);
553
+ } catch (error) {
554
+ try {
555
+ return (0, util_1.setDataToHTML)(data);
556
+ } catch (fallbackError) {
557
+ return null;
558
+ }
559
+ }
560
+ }
561
+ createInternalFormulaHtmlMarker() {
562
+ return `vtable-formula-${Date.now()}-${++this.internalFormulaHtmlMarkerId}`;
563
+ }
564
+ attachInternalFormulaHtmlMarker(html, marker) {
565
+ return `${html}\x3c!--${marker}--\x3e`;
566
+ }
567
+ setCopyDataToEventClipboard(data, dataHTML, e, internalFormulaText, internalFormulaHtmlMarker) {
568
+ const clipboardData = e.clipboardData;
569
+ if (!clipboardData) return null;
570
+ try {
571
+ clipboardData.setData("text/plain", data);
572
+ const copiedClipboardData = {
573
+ html: "",
574
+ text: data,
575
+ hasText: !0,
576
+ internalFormulaText: internalFormulaText
577
+ };
578
+ if (dataHTML) try {
579
+ clipboardData.setData("text/html", dataHTML), copiedClipboardData.html = dataHTML,
580
+ copiedClipboardData.hasHtml = !0, copiedClipboardData.internalFormulaHtmlMarker = internalFormulaHtmlMarker;
581
+ } catch (error) {}
582
+ return copiedClipboardData;
583
+ } catch (error) {
584
+ return null;
585
+ }
586
+ }
587
+ fallbackCopyToClipboard(data) {
318
588
  try {
319
- if (e.clipboardData) return void e.clipboardData.setData("text/plain", data);
320
589
  document.activeElement && document.activeElement !== document.body && document.activeElement.blur();
321
590
  const textArea = document.createElement("textarea");
322
591
  textArea.value = data, textArea.style.position = "fixed", textArea.style.left = "-999999px",
@@ -324,198 +593,432 @@ class EventManager {
324
593
  textArea.setAttribute("aria-hidden", "true"), document.body.appendChild(textArea),
325
594
  textArea.focus(), textArea.select(), textArea.setSelectionRange(0, data.length);
326
595
  try {
327
- document.execCommand("copy");
596
+ const successful = document.execCommand("copy");
597
+ return successful;
328
598
  } catch (execError) {} finally {
329
599
  document.body.removeChild(textArea);
330
600
  }
331
601
  } catch (error) {}
602
+ return !1;
332
603
  }
333
604
  handleCut(e) {
334
- var _a;
335
605
  return __awaiter(this, void 0, void 0, (function*() {
336
- this.handleCopy(e, !0), this.cutWaitPaste = !0, this.cutCellRange = this.table.getSelectedCellInfos(),
337
- this.cutRanges = null === (_a = this.table.stateManager.select.ranges) || void 0 === _a ? void 0 : _a.map((r => ({
338
- start: {
339
- col: r.start.col,
340
- row: r.start.row
341
- },
342
- end: {
343
- col: r.end.col,
344
- row: r.end.row
345
- }
346
- }))), this.clipboardCheckTimer && clearTimeout(this.clipboardCheckTimer), this.clipboardCheckTimer = window.setTimeout((() => {
347
- this.cutWaitPaste && (this.cutWaitPaste = !1, this.cutCellRange = null, this.cutRanges = null,
348
- this.clipboardCheckTimer = null);
349
- }), 3e4), this.saveClipboardContent();
606
+ const copySnapshot = yield this.handleCopy(e, !0);
607
+ if (!copySnapshot) return;
608
+ const cutState = {
609
+ id: ++this.cutOperationId,
610
+ ranges: this.cloneRanges(copySnapshot.ranges),
611
+ cellInfos: copySnapshot.cellInfos,
612
+ sourceCells: copySnapshot.sourceCells,
613
+ sourceCellMatrix: copySnapshot.sourceCellMatrix,
614
+ sourceColCount: copySnapshot.sourceColCount,
615
+ sourceRowCount: copySnapshot.sourceRowCount,
616
+ clipboardData: copySnapshot.clipboardData,
617
+ clipboardSignature: copySnapshot.clipboardSignature,
618
+ copySourceRange: copySnapshot.copySourceRange,
619
+ isSingleRange: 1 === copySnapshot.ranges.length
620
+ };
621
+ this.cutWaitPaste = !0, this.activeCutState = cutState, this.cutCellRange = cutState.cellInfos,
622
+ this.cutRanges = cutState.ranges, this.clipboardCheckTimer && clearTimeout(this.clipboardCheckTimer),
623
+ this.clipboardCheckTimer = window.setTimeout((() => {
624
+ this.cutWaitPaste && this.resetCutState();
625
+ }), 3e4), this.lastClipboardContent = cutState.clipboardSignature;
350
626
  }));
351
627
  }
352
628
  handlePaste(e) {
353
- this.cutWaitPaste ? this.checkClipboardChanged().then((changed => {
354
- this.executePaste(e), changed || this.clearCutArea(this.table), this.cutWaitPaste && (this.cutWaitPaste = !1,
355
- this.cutCellRange = null, this.cutRanges = null, this.clipboardCheckTimer && (clearTimeout(this.clipboardCheckTimer),
356
- this.clipboardCheckTimer = null));
357
- })).catch((() => {
358
- this.executePaste(e), this.cutWaitPaste && (this.cutWaitPaste = !1, this.cutCellRange = null,
359
- this.clipboardCheckTimer && (clearTimeout(this.clipboardCheckTimer), this.clipboardCheckTimer = null));
360
- })) : this.executePaste(e);
361
- }
362
- executePaste(e) {
363
- var _a, _b, _c;
629
+ const pasteOperationId = ++this.pasteOperationId, pasteRange = this.getPasteRange();
630
+ if (!pasteRange) return;
631
+ const eventClipboardData = this.getEventClipboardData(e), pasteCopySourceRange = this.copySourceRange;
632
+ if (!this.cutWaitPaste) return void this.readClipboardDataForPaste(eventClipboardData).then((clipboardData => {
633
+ if (!this.isPasteOperationCurrent(pasteOperationId)) return;
634
+ const copySourceRange = this.isClipboardDataSameAsLastCopy(clipboardData) ? pasteCopySourceRange : null;
635
+ this.executePaste(clipboardData, {
636
+ pasteRange: pasteRange,
637
+ copySourceRange: copySourceRange,
638
+ pasteOperationId: pasteOperationId
639
+ });
640
+ })).catch((error => {}));
641
+ const cutState = this.activeCutState;
642
+ cutState ? this.readClipboardDataForPaste(eventClipboardData).then((clipboardData => __awaiter(this, void 0, void 0, (function*() {
643
+ var _a, _b, _c, _d, _e;
644
+ if (!this.isPasteOperationCurrent(pasteOperationId) || (null === (_a = this.activeCutState) || void 0 === _a ? void 0 : _a.id) !== cutState.id) return;
645
+ const changed = this.isClipboardDataChanged(clipboardData, cutState);
646
+ if (null === changed) return void (yield this.executePaste(clipboardData, {
647
+ pasteRange: pasteRange,
648
+ copySourceRange: this.isClipboardDataSameAsLastCopy(clipboardData) ? pasteCopySourceRange : null,
649
+ pasteOperationId: pasteOperationId
650
+ }));
651
+ const pasteResult = yield this.executePaste(clipboardData, {
652
+ pasteRange: pasteRange,
653
+ copySourceRange: changed ? null : cutState.copySourceRange,
654
+ cutState: changed ? null : cutState,
655
+ pasteOperationId: pasteOperationId
656
+ });
657
+ 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) {
658
+ if (!(yield this.clearCutArea(pasteResult.migratedSourceCells, pasteResult.changedCells))) return void this.resetCutState();
659
+ (null === (_d = this.activeCutState) || void 0 === _d ? void 0 : _d.id) === cutState.id && this.resetCutState();
660
+ }
661
+ })))).catch((() => __awaiter(this, void 0, void 0, (function*() {
662
+ this.isPasteOperationCurrent(pasteOperationId) && (yield this.executePaste(eventClipboardData, {
663
+ pasteRange: pasteRange,
664
+ copySourceRange: this.isClipboardDataSameAsLastCopy(eventClipboardData) ? pasteCopySourceRange : null,
665
+ pasteOperationId: pasteOperationId
666
+ }));
667
+ })))) : this.executePaste(eventClipboardData, {
668
+ pasteRange: pasteRange,
669
+ copySourceRange: this.isClipboardDataSameAsLastCopy(eventClipboardData) ? pasteCopySourceRange : null,
670
+ pasteOperationId: pasteOperationId
671
+ });
672
+ }
673
+ executePaste(clipboardData, pasteContext) {
674
+ var _a, _b, _c, _d;
364
675
  return __awaiter(this, void 0, void 0, (function*() {
365
- const table = this.table;
366
- if (!(null === (_a = table.editorManager) || void 0 === _a ? void 0 : _a.editingEditor)) {
367
- if (table.changeCellValues && (null === (_b = table.stateManager.select.ranges) || void 0 === _b ? void 0 : _b.length) > 0) try {
368
- if (navigator.clipboard && navigator.clipboard.read) try {
369
- const clipboardItems = yield navigator.clipboard.read();
370
- let handled = !1;
371
- for (const item of clipboardItems) {
372
- if (item.types.includes("text/html")) {
373
- yield this.pasteHtmlToTable(item), handled = !0;
374
- break;
375
- }
376
- if (item.types.includes("text/plain")) {
377
- yield this.pasteTextToTable(item), handled = !0;
378
- break;
379
- }
380
- }
381
- handled || (yield this.fallbackPasteFromClipboard(e));
382
- } catch (clipboardError) {
383
- yield this.fallbackPasteFromClipboard(e);
384
- } else yield this.fallbackPasteFromClipboard(e);
676
+ const table = this.table, emptyResult = this.getEmptyPasteResult(), pasteClipboardData = this.getPasteClipboardData(clipboardData, pasteContext);
677
+ if (!this.isPasteOperationCurrent(pasteContext.pasteOperationId) || (null === (_a = table.editorManager) || void 0 === _a ? void 0 : _a.editingEditor)) return emptyResult;
678
+ if (this.pasteWriteInProgress && (yield this.pasteWritePromise.catch((() => {})),
679
+ !this.isPasteOperationCurrent(pasteContext.pasteOperationId) || (null === (_b = table.editorManager) || void 0 === _b ? void 0 : _b.editingEditor))) return emptyResult;
680
+ let pasteResult = emptyResult, settlePasteWrite = () => {};
681
+ this.pasteWritePromise = new Promise((resolve => {
682
+ settlePasteWrite = resolve;
683
+ })), this.pasteWriteInProgress = !0;
684
+ try {
685
+ if (table.changeCellValues) try {
686
+ if (null == pasteClipboardData ? void 0 : pasteClipboardData.html) try {
687
+ const htmlResult = yield this.processPastedHTML(pasteClipboardData.html, pasteContext);
688
+ if (htmlResult.pasted) return pasteResult = htmlResult, pasteResult;
689
+ } catch (error) {
690
+ if (/<table\b/i.test(pasteClipboardData.html)) return emptyResult;
691
+ }
692
+ 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),
693
+ pasteResult;
385
694
  } catch (error) {
386
- yield this.fallbackPasteFromClipboard(e);
695
+ pasteContext.cutState && this.resetCutState();
387
696
  }
388
- (null === (_c = table.keyboardOptions) || void 0 === _c ? void 0 : _c.showCopyCellBorder) && (0,
697
+ return pasteResult;
698
+ } finally {
699
+ this.pasteWriteInProgress = !1, settlePasteWrite(), !pasteContext.cutState && (null === (_d = table.keyboardOptions) || void 0 === _d ? void 0 : _d.showCopyCellBorder) && (0,
389
700
  style_1.clearActiveCellRangeState)(table);
390
701
  }
391
702
  }));
392
703
  }
393
- fallbackPasteFromClipboard(e) {
704
+ getPasteClipboardData(clipboardData, pasteContext) {
705
+ var _a, _b;
706
+ if (!clipboardData || !pasteContext.copySourceRange) return clipboardData;
707
+ const sourceData = null !== (_b = null === (_a = pasteContext.cutState) || void 0 === _a ? void 0 : _a.clipboardData) && void 0 !== _b ? _b : this.lastCopiedClipboardData;
708
+ 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), {
709
+ internalFormulaText: sourceData.internalFormulaText
710
+ }) : clipboardData;
711
+ }
712
+ getPasteRange() {
713
+ const ranges = this.table.stateManager.select.ranges;
714
+ if (!(null == ranges ? void 0 : ranges.length)) return null;
715
+ const range = ranges[ranges.length - 1];
716
+ return {
717
+ col: Math.min(range.start.col, range.end.col),
718
+ row: Math.min(range.start.row, range.end.row),
719
+ maxCol: Math.max(range.start.col, range.end.col),
720
+ maxRow: Math.max(range.start.row, range.end.row)
721
+ };
722
+ }
723
+ getEventClipboardData(e) {
724
+ var _a;
725
+ const clipboardData = e.clipboardData || window.clipboardData;
726
+ if (!clipboardData) return null;
727
+ try {
728
+ 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;
729
+ return {
730
+ html: html,
731
+ text: text,
732
+ hasHtml: hasHtml,
733
+ hasText: types.includes("text/plain") || types.includes("text") || types.includes("Text") || !!text
734
+ };
735
+ } catch (error) {
736
+ return {
737
+ html: "",
738
+ text: "",
739
+ readFailed: !0
740
+ };
741
+ }
742
+ }
743
+ readClipboardDataForPaste(eventClipboardData) {
744
+ var _a, _b;
394
745
  return __awaiter(this, void 0, void 0, (function*() {
395
- 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);
396
- try {
397
- const element = table.getElement();
398
- element && element !== document.activeElement && (element.focus(), yield new Promise((resolve => setTimeout(resolve, 10))));
399
- const clipboardData = e.clipboardData || window.clipboardData || window.Clipboard;
400
- if (clipboardData) {
401
- const pastedData = clipboardData.getData("text") || clipboardData.getData("Text");
402
- if (pastedData) return void (yield this.processPastedText(pastedData, col, row));
746
+ if ((null == eventClipboardData ? void 0 : eventClipboardData.readFailed) || (null == eventClipboardData ? void 0 : eventClipboardData.hasHtml) || (null == eventClipboardData ? void 0 : eventClipboardData.hasText)) return eventClipboardData;
747
+ if (null === (_a = navigator.clipboard) || void 0 === _a ? void 0 : _a.read) try {
748
+ const clipboardItems = yield navigator.clipboard.read(), clipboardData = {
749
+ html: "",
750
+ text: ""
751
+ };
752
+ for (const item of clipboardItems) {
753
+ if (!clipboardData.html && item.types.includes("text/html")) try {
754
+ clipboardData.html = yield (yield item.getType("text/html")).text(), clipboardData.hasHtml = !0;
755
+ } catch (error) {}
756
+ if (!clipboardData.text && item.types.includes("text/plain")) try {
757
+ clipboardData.text = yield (yield item.getType("text/plain")).text(), clipboardData.hasText = !0;
758
+ } catch (error) {}
403
759
  }
760
+ if (clipboardData.hasHtml || clipboardData.hasText) return clipboardData;
404
761
  } catch (error) {}
762
+ if (null === (_b = navigator.clipboard) || void 0 === _b ? void 0 : _b.readText) try {
763
+ return {
764
+ html: "",
765
+ text: yield navigator.clipboard.readText(),
766
+ hasText: !0
767
+ };
768
+ } catch (error) {}
769
+ return null != eventClipboardData ? eventClipboardData : {
770
+ html: "",
771
+ text: "",
772
+ readFailed: !0
773
+ };
405
774
  }));
406
775
  }
407
- processPastedText(pastedData, col, row) {
776
+ decodeHTMLCellValue(cellHTML) {
408
777
  var _a;
409
- return __awaiter(this, void 0, void 0, (function*() {
410
- const table = this.table, rows = pastedData.split("\n"), values = [];
411
- let processedValues;
412
- rows.forEach((function(rowCells) {
413
- const cells = rowCells.split("\t"), rowValues = [];
414
- values.push(rowValues), cells.forEach((function(cell, cellIndex) {
415
- cellIndex === cells.length - 1 && (cell = cell.trim()), rowValues.push(cell);
416
- }));
417
- })), (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));
418
- const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
419
- table.hasListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA, {
420
- col: col,
421
- row: row,
422
- pasteData: processedValues || values,
423
- changedCellResults: changedCellResults
424
- });
425
- }));
778
+ const template = document.createElement("template");
779
+ return template.innerHTML = cellHTML.replace(/<br\b[^>]*>(?:\r\n|\r|\n)?/gim, "\n").replace(/&nbsp;/gi, " "),
780
+ null !== (_a = template.content.textContent) && void 0 !== _a ? _a : "";
426
781
  }
427
- clearCutArea(table) {
428
- try {
429
- const ranges = this.cutRanges;
430
- if (!ranges || 0 === ranges.length) return;
431
- table.changeCellValuesByRanges(ranges, "");
432
- } catch (error) {}
433
- }
434
- checkClipboardChanged() {
782
+ processPastedHTML(pastedData, pasteContext) {
783
+ var _a, _b, _c;
435
784
  return __awaiter(this, void 0, void 0, (function*() {
436
- if (!navigator.clipboard || !navigator.clipboard.readText) return !1;
437
- try {
438
- return (yield navigator.clipboard.readText()) !== this.lastClipboardContent;
439
- } catch (err) {
440
- return !1;
785
+ const cellRegex = /<t[dh][^>]*>([\s\S]*?)<\/t[dh]>/gi, table = this.table, pasteRange = pasteContext.pasteRange, {col: col, row: row, maxCol: maxCol, maxRow: maxRow} = pasteRange;
786
+ let pasteValuesColCount = 0, pasteValuesRowCount = 0, values = [];
787
+ if (!pastedData || !/<table\b/i.test(pastedData)) return this.getEmptyPasteResult();
788
+ const matches = Array.from(pastedData.matchAll(/<tr[^>]*>([\s\S]*?)<\/tr>/gi));
789
+ for (const match of matches) {
790
+ const rowContent = match[1], cellMatches = Array.from(rowContent.matchAll(cellRegex));
791
+ if (!cellMatches.length) continue;
792
+ const rowValues = cellMatches.map((cellMatch => this.decodeHTMLCellValue(cellMatch[1])));
793
+ values.push(rowValues), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
441
794
  }
795
+ if (pasteValuesRowCount = null !== (_b = values.length) && void 0 !== _b ? _b : 0,
796
+ !pasteValuesRowCount || !pasteValuesColCount) return this.getEmptyPasteResult();
797
+ let processedValues;
798
+ values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1),
799
+ (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));
800
+ const valuesToPaste = processedValues || values, targetCells = this.getPasteTargetCells(pasteRange, valuesToPaste);
801
+ if (!this.isPasteOperationCurrent(pasteContext.pasteOperationId)) return this.getEmptyPasteResult();
802
+ if (pasteContext.cutState) {
803
+ const validatedCellResults = yield this.validatePasteTargetCells(pasteRange, valuesToPaste);
804
+ if (!this.isPasteOperationCurrent(pasteContext.pasteOperationId)) return this.getEmptyPasteResult();
805
+ if (!this.isFullPasteAllowed(valuesToPaste, validatedCellResults)) return this.getEmptyPasteResult(validatedCellResults);
806
+ }
807
+ const rawChangedCellResults = yield table.changeCellValues(col, row, valuesToPaste, !pasteContext.cutState, !0, void 0, (() => !this.isPasteOperationCurrent(pasteContext.pasteOperationId)));
808
+ if (!this.isPasteOperationCurrent(pasteContext.pasteOperationId)) return this.getEmptyPasteResult();
809
+ const changedCellResults = this.normalizeChangedCellResults(rawChangedCellResults, pasteRange, valuesToPaste), changedCells = this.getChangedCells(targetCells, changedCellResults), migratedSourceCells = this.getMigratedSourceCells(pasteContext.cutState, changedCellResults);
810
+ return changedCells.length ? (this.firePastedDataEvent(col, row, valuesToPaste, changedCellResults),
811
+ {
812
+ pasted: !0,
813
+ changedCellResults: changedCellResults,
814
+ changedCells: changedCells,
815
+ migratedSourceCells: migratedSourceCells
816
+ }) : this.getEmptyPasteResult(changedCellResults);
442
817
  }));
443
818
  }
444
- saveClipboardContent() {
445
- navigator.clipboard && navigator.clipboard.readText && setTimeout((() => {
446
- navigator.clipboard.readText().then((text => {
447
- this.lastClipboardContent = text;
448
- })).catch((err => {}));
449
- }), 50);
450
- }
451
- pasteHtmlToTable(item) {
452
- 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);
453
- let pasteValuesColCount = 0, pasteValuesRowCount = 0, values = [];
454
- item.getType("text/html").then((blob => {
455
- blob.text().then((pastedData => __awaiter(this, void 0, void 0, (function*() {
456
- var _a, _b, _c;
457
- if (pastedData && /(<table)|(<TABLE)/g.test(pastedData)) {
458
- const matches = Array.from(pastedData.matchAll(regex));
459
- for (const match of matches) {
460
- 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, " ")));
461
- values.push(rowValues), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
462
- }
463
- let processedValues;
464
- pasteValuesRowCount = null !== (_b = values.length) && void 0 !== _b ? _b : 0, values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1),
465
- (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));
466
- const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
467
- table.hasListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA, {
468
- col: col,
469
- row: row,
470
- pasteData: processedValues || values,
471
- changedCellResults: changedCellResults
472
- });
473
- } else navigator.clipboard.read().then((clipboardItems => {
474
- for (const item of clipboardItems) item.types.includes("text/plain") && item.getType("text/plain").then((blob => {
475
- blob.text().then((data => this._pasteValue(data)));
476
- }));
477
- }));
478
- }))));
479
- }));
480
- }
481
- _pasteValue(pastedData) {
482
- var _a, _b;
819
+ processPastedText(pastedData, pasteContext) {
820
+ var _a;
483
821
  return __awaiter(this, void 0, void 0, (function*() {
484
- 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);
485
- let pasteValuesColCount = 0, pasteValuesRowCount = 0, values = [];
822
+ const table = this.table, pasteRange = pasteContext.pasteRange, {col: col, row: row, maxCol: maxCol, maxRow: maxRow} = pasteRange;
823
+ let values = this.parsePlainTextPastedData(pastedData);
824
+ const pasteValuesRowCount = values.length, pasteValuesColCount = Math.max(...values.map((rowValues => rowValues.length)));
825
+ if (!pasteValuesRowCount || !pasteValuesColCount) return this.getEmptyPasteResult();
486
826
  let processedValues;
487
- pastedData.split("\n").forEach((function(rowCells, rowIndex) {
488
- var _a;
489
- const cells = rowCells.split("\t"), rowValues = [];
490
- values.push(rowValues), cells.forEach((function(cell, cellIndex) {
491
- cellIndex === cells.length - 1 && (cell = cell.trim()), rowValues.push(cell);
492
- })), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
493
- })), pasteValuesRowCount = null !== (_a = values.length) && void 0 !== _a ? _a : 0,
494
827
  values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1),
495
- (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));
496
- const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
497
- table.hasListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA, {
828
+ (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));
829
+ const valuesToPaste = processedValues || values, targetCells = this.getPasteTargetCells(pasteRange, valuesToPaste);
830
+ if (!this.isPasteOperationCurrent(pasteContext.pasteOperationId)) return this.getEmptyPasteResult();
831
+ if (pasteContext.cutState) {
832
+ const validatedCellResults = yield this.validatePasteTargetCells(pasteRange, valuesToPaste);
833
+ if (!this.isPasteOperationCurrent(pasteContext.pasteOperationId)) return this.getEmptyPasteResult();
834
+ if (!this.isFullPasteAllowed(valuesToPaste, validatedCellResults)) return this.getEmptyPasteResult(validatedCellResults);
835
+ }
836
+ const rawChangedCellResults = yield table.changeCellValues(col, row, valuesToPaste, !pasteContext.cutState, !0, void 0, (() => !this.isPasteOperationCurrent(pasteContext.pasteOperationId)));
837
+ if (!this.isPasteOperationCurrent(pasteContext.pasteOperationId)) return this.getEmptyPasteResult();
838
+ const changedCellResults = this.normalizeChangedCellResults(rawChangedCellResults, pasteRange, valuesToPaste), changedCells = this.getChangedCells(targetCells, changedCellResults), migratedSourceCells = this.getMigratedSourceCells(pasteContext.cutState, changedCellResults);
839
+ return changedCells.length ? (this.firePastedDataEvent(col, row, valuesToPaste, changedCellResults),
840
+ {
841
+ pasted: !0,
842
+ changedCellResults: changedCellResults,
843
+ changedCells: changedCells,
844
+ migratedSourceCells: migratedSourceCells
845
+ }) : this.getEmptyPasteResult(changedCellResults);
846
+ }));
847
+ }
848
+ firePastedDataEvent(col, row, pasteData, changedCellResults) {
849
+ const table = this.table;
850
+ if (table.hasListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA)) try {
851
+ table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA, {
498
852
  col: col,
499
853
  row: row,
500
- pasteData: processedValues || values,
854
+ pasteData: pasteData,
501
855
  changedCellResults: changedCellResults
502
856
  });
857
+ } catch (error) {}
858
+ }
859
+ getEmptyPasteResult(changedCellResults = []) {
860
+ return {
861
+ pasted: !1,
862
+ changedCellResults: changedCellResults,
863
+ changedCells: [],
864
+ migratedSourceCells: []
865
+ };
866
+ }
867
+ getPasteTargetCells(pasteRange, values) {
868
+ const targetCells = [];
869
+ for (let rowIndex = 0; rowIndex < values.length; rowIndex++) {
870
+ targetCells[rowIndex] = [];
871
+ for (let colIndex = 0; colIndex < values[rowIndex].length; colIndex++) targetCells[rowIndex][colIndex] = this.getCellIdentity(pasteRange.col + colIndex, pasteRange.row + rowIndex);
872
+ }
873
+ return targetCells;
874
+ }
875
+ getChangedCells(targetCells, changedCellResults) {
876
+ var _a, _b, _c;
877
+ const changedCells = [];
878
+ 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]);
879
+ return changedCells;
880
+ }
881
+ normalizeChangedCellResults(changedCellResults, pasteRange, values) {
882
+ if (Array.isArray(changedCellResults)) return changedCellResults;
883
+ const table = this.table;
884
+ return values.map(((rowValues, rowIndex) => rowValues.map(((_value, colIndex) => {
885
+ const targetCol = pasteRange.col + colIndex, targetRow = pasteRange.row + rowIndex;
886
+ return targetCol < table.colCount && targetRow < table.rowCount && (!table.isHasEditorDefine || table.isHasEditorDefine(targetCol, targetRow));
887
+ }))));
888
+ }
889
+ validatePasteTargetCells(pasteRange, values) {
890
+ var _a, _b, _c, _d;
891
+ return __awaiter(this, void 0, void 0, (function*() {
892
+ const table = this.table, changedCellResults = [];
893
+ for (let rowIndex = 0; rowIndex < values.length; rowIndex++) {
894
+ changedCellResults[rowIndex] = [];
895
+ for (let colIndex = 0; colIndex < values[rowIndex].length; colIndex++) {
896
+ const targetCol = pasteRange.col + colIndex, targetRow = pasteRange.row + rowIndex, tableAny = table;
897
+ let canChange = targetCol < tableAny.colCount && targetRow < tableAny.rowCount && (!tableAny.isHasEditorDefine || tableAny.isHasEditorDefine(targetCol, targetRow));
898
+ if (canChange) {
899
+ 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, {
900
+ col: targetCol,
901
+ row: targetRow
902
+ }, table)) || void 0 === _d || _d, resolvedValidateResult = validateResult && "function" == typeof validateResult.then ? yield validateResult : validateResult;
903
+ canChange = !0 === resolvedValidateResult || "validate-exit" === resolvedValidateResult || "validate-not-exit" === resolvedValidateResult;
904
+ }
905
+ changedCellResults[rowIndex][colIndex] = canChange;
906
+ }
907
+ }
908
+ return changedCellResults;
503
909
  }));
504
910
  }
505
- pasteTextToTable(item) {
911
+ isFullPasteAllowed(values, changedCellResults) {
912
+ return values.every(((rowValues, rowIndex) => rowValues.every(((_value, colIndex) => {
913
+ var _a;
914
+ return !0 === (null === (_a = changedCellResults[rowIndex]) || void 0 === _a ? void 0 : _a[colIndex]);
915
+ }))));
916
+ }
917
+ getMigratedSourceCells(cutState, changedCellResults) {
918
+ var _a, _b, _c, _d, _e;
919
+ if (!(null == cutState ? void 0 : cutState.sourceCells.length) || !cutState.sourceColCount || !cutState.sourceRowCount) return [];
920
+ const migratedSourceCells = [], migratedKeys = new Set;
921
+ if (!cutState.isSingleRange) {
922
+ 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++) {
923
+ if (!changedCellResults[rowIndex][colIndex]) continue;
924
+ const sourceRow = rowIndex % cutState.sourceRowCount, sourceCol = colIndex % cutState.sourceColCount, sourceCell = null === (_c = cutState.sourceCellMatrix[sourceRow]) || void 0 === _c ? void 0 : _c[sourceCol];
925
+ if (!sourceCell) continue;
926
+ const sourceKey = this.getCellKey(sourceCell);
927
+ migratedKeys.has(sourceKey) || (migratedKeys.add(sourceKey), migratedSourceCells.push(sourceCell));
928
+ }
929
+ return migratedSourceCells.length === cutState.sourceCells.length ? migratedSourceCells : [];
930
+ }
931
+ 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++) {
932
+ if (!changedCellResults[rowIndex][colIndex]) continue;
933
+ const sourceRow = rowIndex % cutState.sourceRowCount, sourceCol = colIndex % cutState.sourceColCount, sourceIndex = sourceRow * cutState.sourceColCount + sourceCol, sourceCell = cutState.sourceCells[sourceIndex];
934
+ if (!sourceCell) continue;
935
+ const sourceKey = this.getCellKey(sourceCell);
936
+ migratedKeys.has(sourceKey) || (migratedKeys.add(sourceKey), migratedSourceCells.push(sourceCell));
937
+ }
938
+ return migratedSourceCells;
939
+ }
940
+ getCellIdentity(col, row) {
941
+ var _a, _b, _c, _d, _e, _f, _g;
942
+ const table = this.table, recordShowIndex = null === (_a = table.getRecordShowIndexByCell) || void 0 === _a ? void 0 : _a.call(table, col, row);
943
+ return {
944
+ col: col,
945
+ row: row,
946
+ 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,
947
+ 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
948
+ };
949
+ }
950
+ clearCutArea(migratedSourceCells, changedTargetCells) {
951
+ var _a, _b;
506
952
  return __awaiter(this, void 0, void 0, (function*() {
507
- 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);
508
953
  try {
509
- 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);
510
- table.hasListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE_1.TABLE_EVENT_TYPE.PASTED_DATA, {
511
- col: col,
512
- row: row,
513
- pasteData: processedValues,
514
- changedCellResults: changedCellResults
954
+ const table = this.table, changedTargetKeys = new Set;
955
+ changedTargetCells.forEach((cell => {
956
+ changedTargetKeys.add(this.getCellKey(cell)), changedTargetKeys.add(this.getCoordKey(cell));
957
+ }));
958
+ const clearedKeys = new Set, sourceChanges = [], coordChanges = [];
959
+ for (let i = 0; i < migratedSourceCells.length; i++) {
960
+ const sourceCell = migratedSourceCells[i], sourceKey = this.getCellKey(sourceCell);
961
+ if (clearedKeys.has(sourceKey) || changedTargetKeys.has(sourceKey) || changedTargetKeys.has(this.getCoordKey(sourceCell))) continue;
962
+ const currentAddress = this.getCurrentCellAddress(sourceCell);
963
+ currentAddress && (this.isSourceCellUnchanged(sourceCell, currentAddress) && (void 0 !== sourceCell.recordIndex && void 0 !== sourceCell.field && table.changeCellValuesByRecords ? sourceChanges.push({
964
+ recordIndex: sourceCell.recordIndex,
965
+ field: sourceCell.field,
966
+ value: ""
967
+ }) : coordChanges.push(currentAddress), clearedKeys.add(sourceKey)));
968
+ }
969
+ sourceChanges.length && table.changeCellValuesByRecords(sourceChanges, {
970
+ triggerEvent: !0,
971
+ autoRefresh: !1
515
972
  });
516
- } catch (error) {}
973
+ for (let i = 0; i < coordChanges.length; i++) yield table.changeCellValues(coordChanges[i].col, coordChanges[i].row, [ [ "" ] ], !1);
974
+ return sourceChanges.length && (null === (_b = (_a = table).refreshAfterSourceChange) || void 0 === _b || _b.call(_a)),
975
+ !0;
976
+ } catch (error) {
977
+ return !1;
978
+ }
517
979
  }));
518
980
  }
981
+ isSourceCellUnchanged(sourceCell, currentAddress) {
982
+ var _a;
983
+ const table = this.table;
984
+ return Object.is(null === (_a = table.getCellOriginValue) || void 0 === _a ? void 0 : _a.call(table, currentAddress.col, currentAddress.row), sourceCell.value);
985
+ }
986
+ getCurrentCellAddress(sourceCell) {
987
+ const table = this.table;
988
+ if (void 0 !== sourceCell.recordIndex && void 0 !== sourceCell.field && table.getCellAddrByFieldRecord) {
989
+ const address = table.getCellAddrByFieldRecord(sourceCell.field, sourceCell.recordIndex);
990
+ return address && address.col >= 0 && address.row >= 0 ? address : null;
991
+ }
992
+ return {
993
+ col: sourceCell.col,
994
+ row: sourceCell.row
995
+ };
996
+ }
997
+ getCellKey(cell) {
998
+ return void 0 !== cell.recordIndex && void 0 !== cell.field ? `record:${this.getStableKeyPart(cell.recordIndex)}:${this.getStableKeyPart(cell.field)}` : this.getCoordKey(cell);
999
+ }
1000
+ getCoordKey(cell) {
1001
+ return `coord:${cell.col}:${cell.row}`;
1002
+ }
1003
+ getStableKeyPart(value) {
1004
+ if (null === value) return "null";
1005
+ const valueType = typeof value;
1006
+ if ("string" === valueType || "number" === valueType || "boolean" === valueType) return `${valueType}:${JSON.stringify(value)}`;
1007
+ if (Array.isArray(value)) return `array:[${value.map((item => this.getStableKeyPart(item))).join(",")}]`;
1008
+ if ("object" === valueType || "function" === valueType) {
1009
+ let id = this.fieldKeyIds.get(value);
1010
+ return void 0 === id && (id = ++this.fieldKeyId, this.fieldKeyIds.set(value, id)),
1011
+ `${valueType}:#${id}`;
1012
+ }
1013
+ return `${valueType}:${String(value)}`;
1014
+ }
1015
+ resetCutState() {
1016
+ var _a;
1017
+ this.cutWaitPaste = !1, this.activeCutState = null, this.cutCellRange = null, this.cutRanges = null,
1018
+ (null === (_a = this.table.keyboardOptions) || void 0 === _a ? void 0 : _a.showCopyCellBorder) && (0,
1019
+ style_1.clearActiveCellRangeState)(this.table), this.clipboardCheckTimer && (clearTimeout(this.clipboardCheckTimer),
1020
+ this.clipboardCheckTimer = null);
1021
+ }
519
1022
  parsePastedData(pastedData) {
520
1023
  const rows = pastedData.replace(/\r(?!\n)/g, "\r\n").split("\r\n"), values = [];
521
1024
  return rows.length > 1 && "" === rows[rows.length - 1] && rows.pop(), rows.forEach((rowCells => {
@@ -523,6 +1026,10 @@ class EventManager {
523
1026
  values.push(rowValues);
524
1027
  })), values;
525
1028
  }
1029
+ parsePlainTextPastedData(pastedData) {
1030
+ const rows = pastedData.replace(/\r\n|\r/g, "\n").split("\n");
1031
+ return rows.length > 1 && "" === rows[rows.length - 1] && rows.pop(), rows.map((rowCells => rowCells.split("\t")));
1032
+ }
526
1033
  processCellValue(cell) {
527
1034
  cell.includes("\n") && (cell = cell.replace(/^"(.*)"$/, "$1").replace(/["]*/g, (match => new Array(Math.floor(match.length / 2)).fill('"').join(""))));
528
1035
  const numValue = Number(cell);
@@ -549,4 +1056,4 @@ class EventManager {
549
1056
  }
550
1057
 
551
1058
  exports.EventManager = EventManager;
552
- //# sourceMappingURL=event.js.map
1059
+ //# sourceMappingURL=event.js.map