@visactor/vtable 1.26.7 → 1.26.9-alpha.0

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