@visactor/vtable-sheet 1.22.6-alpha.2 → 1.22.6

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 (67) hide show
  1. package/cjs/components/vtable-sheet.js +1 -1
  2. package/cjs/components/vtable-sheet.js.map +1 -1
  3. package/cjs/core/WorkSheet.d.ts +8 -3
  4. package/cjs/core/WorkSheet.js +80 -10
  5. package/cjs/core/WorkSheet.js.map +1 -1
  6. package/cjs/core/table-plugins.d.ts +1 -1
  7. package/cjs/core/table-plugins.js +47 -3
  8. package/cjs/core/table-plugins.js.map +1 -1
  9. package/cjs/formula/formula-paste-processor.d.ts +31 -0
  10. package/cjs/formula/formula-paste-processor.js +72 -0
  11. package/cjs/formula/formula-paste-processor.js.map +1 -0
  12. package/cjs/formula/formula-range-selector.js +3 -3
  13. package/cjs/formula/formula-range-selector.js.map +1 -1
  14. package/cjs/formula/formula-reference-adjustor.d.ts +29 -0
  15. package/cjs/formula/formula-reference-adjustor.js +107 -0
  16. package/cjs/formula/formula-reference-adjustor.js.map +1 -0
  17. package/cjs/formula/formula-ui-manager.js +13 -12
  18. package/cjs/formula/formula-ui-manager.js.map +1 -1
  19. package/cjs/formula/index.d.ts +4 -0
  20. package/cjs/formula/index.js +21 -3
  21. package/cjs/formula/index.js.map +1 -1
  22. package/cjs/index.d.ts +1 -1
  23. package/cjs/index.js +1 -1
  24. package/cjs/index.js.map +1 -1
  25. package/cjs/managers/formula-manager.d.ts +2 -2
  26. package/cjs/managers/formula-manager.js.map +1 -1
  27. package/cjs/tools/index.js +1 -2
  28. package/cjs/ts-types/event.js +2 -1
  29. package/cjs/ts-types/formula.d.ts +16 -11
  30. package/cjs/ts-types/formula.js.map +1 -1
  31. package/cjs/ts-types/sheet.d.ts +2 -2
  32. package/cjs/ts-types/sheet.js.map +1 -1
  33. package/dist/vtable-sheet.js +1082 -449
  34. package/dist/vtable-sheet.min.js +1 -1
  35. package/es/components/vtable-sheet.js +1 -1
  36. package/es/components/vtable-sheet.js.map +1 -1
  37. package/es/core/WorkSheet.d.ts +8 -3
  38. package/es/core/WorkSheet.js +81 -9
  39. package/es/core/WorkSheet.js.map +1 -1
  40. package/es/core/table-plugins.d.ts +1 -1
  41. package/es/core/table-plugins.js +47 -3
  42. package/es/core/table-plugins.js.map +1 -1
  43. package/es/formula/formula-paste-processor.d.ts +31 -0
  44. package/es/formula/formula-paste-processor.js +64 -0
  45. package/es/formula/formula-paste-processor.js.map +1 -0
  46. package/es/formula/formula-range-selector.js +3 -3
  47. package/es/formula/formula-range-selector.js.map +1 -1
  48. package/es/formula/formula-reference-adjustor.d.ts +29 -0
  49. package/es/formula/formula-reference-adjustor.js +101 -0
  50. package/es/formula/formula-reference-adjustor.js.map +1 -0
  51. package/es/formula/formula-ui-manager.js +13 -12
  52. package/es/formula/formula-ui-manager.js.map +1 -1
  53. package/es/formula/index.d.ts +4 -0
  54. package/es/formula/index.js +4 -0
  55. package/es/formula/index.js.map +1 -1
  56. package/es/index.d.ts +1 -1
  57. package/es/index.js +1 -1
  58. package/es/index.js.map +1 -1
  59. package/es/managers/formula-manager.d.ts +2 -2
  60. package/es/managers/formula-manager.js.map +1 -1
  61. package/es/tools/index.js +1 -2
  62. package/es/ts-types/event.js +2 -1
  63. package/es/ts-types/formula.d.ts +16 -11
  64. package/es/ts-types/formula.js.map +1 -1
  65. package/es/ts-types/sheet.d.ts +2 -2
  66. package/es/ts-types/sheet.js.map +1 -1
  67. package/package.json +7 -7
@@ -2294,8 +2294,8 @@
2294
2294
  }
2295
2295
  const ranges = [];
2296
2296
  for (const range of selections) {
2297
- const startAddr = addressFromCoord(range.startRow, range.startCol);
2298
- const endAddr = addressFromCoord(range.endRow, range.endCol);
2297
+ const startAddr = addressFromCoord(range.startCol, range.startRow);
2298
+ const endAddr = addressFromCoord(range.endCol, range.endRow);
2299
2299
  if (range.startRow === range.endRow && range.startCol === range.endCol) {
2300
2300
  ranges.push(startAddr);
2301
2301
  }
@@ -2514,7 +2514,7 @@
2514
2514
  const newValue = event.newValue;
2515
2515
  if (typeof newValue === 'string' && newValue.startsWith('=') && newValue.length > 1) {
2516
2516
  try {
2517
- const currentCellAddress = activeWorkSheet.addressFromCoord(event.row, event.col);
2517
+ const currentCellAddress = activeWorkSheet.addressFromCoord(event.col, event.row);
2518
2518
  const cellRegex = new RegExp(`(^|[^A-Za-z0-9])${currentCellAddress}([^A-Za-z0-9]|$)`);
2519
2519
  if (cellRegex.test(newValue)) {
2520
2520
  activeWorkSheet.tableInstance?.changeCellValue(event.col, event.row, '#CYCLE!', true, false);
@@ -2609,7 +2609,7 @@
2609
2609
  }
2610
2610
  const editCell = formulaManager.formulaWorkingOnCell;
2611
2611
  const safeSelections = this.formulaManager.sheet.excludeEditCellFromSelection(todoSelection, editCell?.row || 0, editCell?.col || 0);
2612
- this.handleSelectionChanged([safeSelections], formulaInput, isCtrlAddSelection, (row, col) => activeWorkSheet.addressFromCoord(row, col));
2612
+ this.handleSelectionChanged([safeSelections], formulaInput, isCtrlAddSelection, (col, row) => activeWorkSheet.addressFromCoord(col, row));
2613
2613
  }
2614
2614
  hasFormulaDependents(cell) {
2615
2615
  try {
@@ -10227,10 +10227,10 @@
10227
10227
  }
10228
10228
  ResourceLoader.cache = new Map(), ResourceLoader.isLoading = !1, ResourceLoader.toLoadAueue = [], ResourceLoader.onLoadSuccessCb = [];
10229
10229
 
10230
- var Edge$1;
10230
+ var Edge;
10231
10231
  !function (Edge) {
10232
10232
  Edge[Edge.Top = 1] = "Top", Edge[Edge.Right = 2] = "Right", Edge[Edge.Bottom = 4] = "Bottom", Edge[Edge.Left = 8] = "Left", Edge[Edge.ALL = 15] = "ALL";
10233
- }(Edge$1 || (Edge$1 = {}));
10233
+ }(Edge || (Edge = {}));
10234
10234
  const _strokeVec4 = [!1, !1, !1, !1];
10235
10235
  const parseStroke = stroke => {
10236
10236
  var _a;
@@ -23773,16 +23773,16 @@
23773
23773
  };
23774
23774
  decompressFrames_1 = lib$1.decompressFrames = decompressFrames;
23775
23775
 
23776
- const browser$1 = isBrowserEnv();
23776
+ const browser = isBrowserEnv();
23777
23777
 
23778
23778
  function _registerArc() {
23779
- _registerArc.__loaded || (_registerArc.__loaded = !0, registerArcGraphic(), container.load(arcModule), container.load(browser$1 ? arcCanvasPickModule : arcMathPickModule));
23779
+ _registerArc.__loaded || (_registerArc.__loaded = !0, registerArcGraphic(), container.load(arcModule), container.load(browser ? arcCanvasPickModule : arcMathPickModule));
23780
23780
  }
23781
23781
  _registerArc.__loaded = !1;
23782
23782
  const registerArc = _registerArc;
23783
23783
 
23784
23784
  function _registerCircle() {
23785
- _registerCircle.__loaded || (_registerCircle.__loaded = !0, registerCircleGraphic(), container.load(circleModule), container.load(browser$1 ? circleCanvasPickModule : circleMathPickModule));
23785
+ _registerCircle.__loaded || (_registerCircle.__loaded = !0, registerCircleGraphic(), container.load(circleModule), container.load(browser ? circleCanvasPickModule : circleMathPickModule));
23786
23786
  }
23787
23787
  _registerCircle.__loaded = !1;
23788
23788
  const registerCircle = _registerCircle;
@@ -23794,37 +23794,37 @@
23794
23794
  const registerGroup = _registerGroup;
23795
23795
 
23796
23796
  function _registerImage() {
23797
- _registerImage.__loaded || (_registerImage.__loaded = !0, registerImageGraphic(), container.load(imageModule), container.load(browser$1 ? imageCanvasPickModule : imageMathPickModule));
23797
+ _registerImage.__loaded || (_registerImage.__loaded = !0, registerImageGraphic(), container.load(imageModule), container.load(browser ? imageCanvasPickModule : imageMathPickModule));
23798
23798
  }
23799
23799
  _registerImage.__loaded = !1;
23800
23800
  const registerImage = _registerImage;
23801
23801
 
23802
23802
  function _registerLine() {
23803
- _registerLine.__loaded || (_registerLine.__loaded = !0, registerLineGraphic(), container.load(lineModule), container.load(browser$1 ? lineCanvasPickModule : lineMathPickModule));
23803
+ _registerLine.__loaded || (_registerLine.__loaded = !0, registerLineGraphic(), container.load(lineModule), container.load(browser ? lineCanvasPickModule : lineMathPickModule));
23804
23804
  }
23805
23805
  _registerLine.__loaded = !1;
23806
23806
  const registerLine = _registerLine;
23807
23807
 
23808
23808
  function _registerPath() {
23809
- _registerPath.__loaded || (_registerPath.__loaded = !0, registerPathGraphic(), container.load(pathModule), container.load(browser$1 ? pathCanvasPickModule : pathMathPickModule));
23809
+ _registerPath.__loaded || (_registerPath.__loaded = !0, registerPathGraphic(), container.load(pathModule), container.load(browser ? pathCanvasPickModule : pathMathPickModule));
23810
23810
  }
23811
23811
  _registerPath.__loaded = !1;
23812
23812
  const registerPath = _registerPath;
23813
23813
 
23814
23814
  function _registerPolygon() {
23815
- _registerPolygon.__loaded || (_registerPolygon.__loaded = !0, registerPolygonGraphic(), container.load(polygonModule), container.load(browser$1 ? polygonCanvasPickModule : polygonMathPickModule));
23815
+ _registerPolygon.__loaded || (_registerPolygon.__loaded = !0, registerPolygonGraphic(), container.load(polygonModule), container.load(browser ? polygonCanvasPickModule : polygonMathPickModule));
23816
23816
  }
23817
23817
  _registerPolygon.__loaded = !1;
23818
23818
  const registerPolygon = _registerPolygon;
23819
23819
 
23820
23820
  function _registerRect() {
23821
- _registerRect.__loaded || (_registerRect.__loaded = !0, registerRectGraphic(), container.load(rectModule), container.load(browser$1 ? rectCanvasPickModule : rectMathPickModule));
23821
+ _registerRect.__loaded || (_registerRect.__loaded = !0, registerRectGraphic(), container.load(rectModule), container.load(browser ? rectCanvasPickModule : rectMathPickModule));
23822
23822
  }
23823
23823
  _registerRect.__loaded = !1;
23824
23824
  const registerRect = _registerRect;
23825
23825
 
23826
23826
  function _registerRichtext() {
23827
- _registerRichtext.__loaded || (_registerRichtext.__loaded = !0, registerRichtextGraphic(), container.load(richtextModule), container.load(browser$1 ? richtextCanvasPickModule : richTextMathPickModule));
23827
+ _registerRichtext.__loaded || (_registerRichtext.__loaded = !0, registerRichtextGraphic(), container.load(richtextModule), container.load(browser ? richtextCanvasPickModule : richTextMathPickModule));
23828
23828
  }
23829
23829
  _registerRichtext.__loaded = !1;
23830
23830
  const registerRichtext = _registerRichtext;
@@ -23836,13 +23836,13 @@
23836
23836
  const registerShadowRoot = _registerShadowRoot;
23837
23837
 
23838
23838
  function _registerSymbol() {
23839
- _registerSymbol.__loaded || (_registerSymbol.__loaded = !0, registerSymbolGraphic(), container.load(symbolModule), container.load(browser$1 ? symbolCanvasPickModule : symbolMathPickModule));
23839
+ _registerSymbol.__loaded || (_registerSymbol.__loaded = !0, registerSymbolGraphic(), container.load(symbolModule), container.load(browser ? symbolCanvasPickModule : symbolMathPickModule));
23840
23840
  }
23841
23841
  _registerSymbol.__loaded = !1;
23842
23842
  const registerSymbol = _registerSymbol;
23843
23843
 
23844
23844
  function _registerText() {
23845
- _registerText.__loaded || (_registerText.__loaded = !0, registerTextGraphic(), container.load(textModule), container.load(browser$1 ? textCanvasPickModule : textMathPickModule));
23845
+ _registerText.__loaded || (_registerText.__loaded = !0, registerTextGraphic(), container.load(textModule), container.load(browser ? textCanvasPickModule : textMathPickModule));
23846
23846
  }
23847
23847
  _registerText.__loaded = !1;
23848
23848
  const registerText = _registerText;
@@ -37741,13 +37741,7 @@
37741
37741
  Safari: ua.indexOf("safari") > -1 && -1 === ua.indexOf("edge")
37742
37742
  };
37743
37743
  }
37744
- const {
37745
- IE: IE,
37746
- Chrome: Chrome,
37747
- Firefox: Firefox,
37748
- Edge: Edge,
37749
- Safari: Safari
37750
- } = analyzeUserAgent();
37744
+ analyzeUserAgent();
37751
37745
  function isObject$7(obj) {
37752
37746
  return obj === Object(obj);
37753
37747
  }
@@ -37837,14 +37831,6 @@
37837
37831
  }
37838
37832
  return !1;
37839
37833
  }
37840
- const browser = {
37841
- IE: IE,
37842
- Edge: Edge,
37843
- Chrome: Chrome,
37844
- Firefox: Firefox,
37845
- Safari: Safari,
37846
- heightLimit: Chrome ? 33554431 : Firefox ? 17895588 : 10737433
37847
- };
37848
37834
  const obj = {
37849
37835
  isObject: isObject$7
37850
37836
  };
@@ -43763,6 +43749,19 @@
43763
43749
  };
43764
43750
  }
43765
43751
  const regIndexReg = /radio-\d+-\d+-(\d+)/;
43752
+ function setDataToHTML(data) {
43753
+ const result = ["<table>"],
43754
+ META_HEAD = ['<meta name="author" content="Visactor"/>', '<style type="text/css">td{white-space:normal}br{mso-data-placement:same-cell}</style>'].join(""),
43755
+ rows = data.split("\r\n");
43756
+ return rows.forEach(function (rowCells, rowIndex) {
43757
+ const cells = rowCells.split("\t"),
43758
+ rowValues = [];
43759
+ 0 === rowIndex && result.push("<tbody>"), cells.forEach(function (cell, cellIndex) {
43760
+ const parsedCellData = cell ? cell.toString().replace(/&/g, "&amp;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br>").replace(/(<br(\s*|\/)>(\r\n|\n)?|\r\n|\n)/g, "<br>\r\n").replace(/\x20{2,}/gi, substring => `<span style="mso-spacerun: yes">${"&nbsp;".repeat(substring.length - 1)} </span>`).replace(/\t/gi, "&#9;") : " ";
43761
+ rowValues.push(`<td>${parsedCellData}</td>`);
43762
+ }), result.push("<tr>", ...rowValues, "</tr>"), rowIndex === rows.length - 1 && result.push("</tbody>");
43763
+ }), result.push("</table>"), [META_HEAD, result.join("")].join("");
43764
+ }
43766
43765
 
43767
43766
  const CUSTOM_MERGE_PRE_NAME = "_custom_";
43768
43767
  const CUSTOM_CONTAINER_NAME = "custom-container";
@@ -47903,8 +47902,11 @@
47903
47902
  }, axisOption, {
47904
47903
  orient: "left",
47905
47904
  type: null !== (_e = null == axisOption ? void 0 : axisOption.type) && void 0 !== _e ? _e : "band",
47906
- __vtableChartTheme: theme,
47905
+ label: {
47906
+ flush: !0
47907
+ },
47907
47908
  inverse: transformInverse(axisOption, "horizontal" === (null !== (_f = null == spec ? void 0 : spec.direction) && void 0 !== _f ? _f : "scatter" === chartType ? "vertical" : "horizontal")),
47909
+ __vtableChartTheme: theme,
47908
47910
  __vtableBodyChartCellPadding: bodyChartCellPadding
47909
47911
  });
47910
47912
  }
@@ -48031,6 +48033,9 @@
48031
48033
  }, axisOption, {
48032
48034
  orient: "bottom",
48033
48035
  type: null !== (_o = null == axisOption ? void 0 : axisOption.type) && void 0 !== _o ? _o : "band",
48036
+ label: {
48037
+ flush: !0
48038
+ },
48034
48039
  __vtableChartTheme: theme,
48035
48040
  __vtableBodyChartCellPadding: bodyChartCellPadding
48036
48041
  });
@@ -48395,7 +48400,7 @@
48395
48400
  releaseColumnChartInstance = !0,
48396
48401
  releaseRowChartInstance = !0
48397
48402
  } = {}) {
48398
- var _a, _b, _c, _d, _e, _f;
48403
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
48399
48404
  if (this.activeChartInstanceHoverOnMark = null, this.justShowMarkTooltip = void 0, this.justShowMarkTooltipTimer = Date.now(), clearTimeout(this.delayRunDimensionHoverTimer), this.delayRunDimensionHoverTimer = void 0, releaseChartInstance) {
48400
48405
  null === (_a = this.activeChartInstance) || void 0 === _a || _a.updateViewBox({
48401
48406
  x1: -1e3,
@@ -48404,11 +48409,16 @@
48404
48409
  y2: -800
48405
48410
  }, !1, !1), null === (_b = this.activeChartInstance) || void 0 === _b || _b.release(), this.activeChartInstance = null;
48406
48411
  const {
48407
- col: col,
48408
- row: row
48409
- } = this.parent,
48410
- table = this.stage.table;
48412
+ col: col,
48413
+ row: row
48414
+ } = this.parent;
48411
48415
  table.internalProps.layoutMap.isAxisCell(table.rowHeaderLevelCount - 1, row) && (null === (_d = (_c = table.scenegraph.getCell(table.rowHeaderLevelCount - 1, row).firstChild).hideLabelHoverOnAxis) || void 0 === _d || _d.call(_c)), table.internalProps.layoutMap.isAxisCell(col, table.rowCount - table.bottomFrozenRowCount) && (null === (_f = (_e = table.scenegraph.getCell(col, table.rowCount - table.bottomFrozenRowCount).firstChild).hideLabelHoverOnAxis) || void 0 === _f || _f.call(_e));
48416
+ } else {
48417
+ const {
48418
+ col: col,
48419
+ row: row
48420
+ } = this.parent;
48421
+ releaseColumnChartInstance && table.internalProps.layoutMap.isAxisCell(col, table.rowCount - table.bottomFrozenRowCount) && (null === (_h = (_g = table.scenegraph.getCell(col, table.rowCount - table.bottomFrozenRowCount).firstChild).hideLabelHoverOnAxis) || void 0 === _h || _h.call(_g)), releaseRowChartInstance && table.internalProps.layoutMap.isAxisCell(table.rowHeaderLevelCount - 1, row) && (null === (_k = (_j = table.scenegraph.getCell(table.rowHeaderLevelCount - 1, row).firstChild).hideLabelHoverOnAxis) || void 0 === _k || _k.call(_j));
48412
48422
  }
48413
48423
  releaseColumnChartInstance && clearChartInstanceListByColumnDirection(this.parent.col, "scatter" === this.attribute.spec.type ? this.parent.row : void 0, table), releaseRowChartInstance && clearChartInstanceListByRowDirection(this.parent.row, "scatter" === this.attribute.spec.type ? this.parent.col : void 0, table);
48414
48424
  }
@@ -48533,7 +48543,7 @@
48533
48543
  tickMode: null === (_e = axis.tick) || void 0 === _e ? void 0 : _e.tickMode
48534
48544
  }
48535
48545
  }, !0);
48536
- }), null === (_c = null === (_b = table.internalProps.layoutMap) || void 0 === _b ? void 0 : _b.updateDataStateToActiveChartInstance) || void 0 === _c || _c.call(_b, chartInstance), "string" == typeof dataId) chartInstance.getChart().setLayoutTag(!0), chartInstance.updateDataSync(dataId, null != data ? data : []);else {
48546
+ }), null === (_c = null === (_b = table.internalProps.layoutMap) || void 0 === _b ? void 0 : _b.updateDataStateToActiveChartInstance) || void 0 === _c || _c.call(_b, chartInstance), "string" == typeof dataId || "number" == typeof dataId) chartInstance.getChart().setLayoutTag(!0), chartInstance.updateDataSync(dataId, null != data ? data : []);else {
48537
48547
  const dataBatch = [];
48538
48548
  for (const dataIdStr in dataId) {
48539
48549
  const dataIdAndField = dataId[dataIdStr],
@@ -48685,7 +48695,7 @@
48685
48695
  chartStage.needRender = !0;
48686
48696
  const matrix = chart.globalTransMatrix.clone(),
48687
48697
  stageMatrix = chart.stage.window.getViewBoxTransform().clone();
48688
- if (stageMatrix.multiply(matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f), chartStage.window.setViewBoxTransform(stageMatrix.a, stageMatrix.b, stageMatrix.c, stageMatrix.d, stageMatrix.e, stageMatrix.f), "string" == typeof dataId) activeChartInstance.updateDataSync(dataId, null != data ? data : []);else {
48698
+ if (stageMatrix.multiply(matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f), chartStage.window.setViewBoxTransform(stageMatrix.a, stageMatrix.b, stageMatrix.c, stageMatrix.d, stageMatrix.e, stageMatrix.f), "string" == typeof dataId || "number" == typeof dataId) activeChartInstance.updateDataSync(dataId, null != data ? data : []);else {
48689
48699
  const dataBatch = [];
48690
48700
  for (const dataIdStr in dataId) {
48691
48701
  const dataIdAndField = dataId[dataIdStr],
@@ -57112,7 +57122,7 @@
57112
57122
  };
57113
57123
  let EventManager$1 = class EventManager {
57114
57124
  constructor(table) {
57115
- this.isDown = !1, this.isDraging = !1, this.globalEventListeners = [], this._enableTableScroll = !0, this.cutWaitPaste = !1, this.clipboardCheckTimer = null, this.cutOperationTime = 0, this.lastClipboardContent = "", this.cutCellRange = null, this.table = table, this.handleTextStickBindId = [], this.inertiaScroll = new InertiaScroll(table.stateManager), "node" === Env$1.mode || table.options.disableInteraction || (this.bindOuterEvent(), setTimeout(() => {
57125
+ this.isDown = !1, this.isDraging = !1, this.globalEventListeners = [], this._enableTableScroll = !0, this.cutWaitPaste = !1, this.clipboardCheckTimer = null, this.cutOperationTime = 0, this.lastClipboardContent = "", this.cutCellRange = null, this.copySourceRange = null, this.table = table, this.handleTextStickBindId = [], this.inertiaScroll = new InertiaScroll(table.stateManager), "node" === Env$1.mode || table.options.disableInteraction || (this.bindOuterEvent(), setTimeout(() => {
57116
57126
  this.bindSelfEvent();
57117
57127
  }, 0));
57118
57128
  }
@@ -57342,49 +57352,76 @@
57342
57352
  this._enableTableScroll = !1;
57343
57353
  }
57344
57354
  handleCopy(e, isCut = !1) {
57345
- var _a, _b;
57355
+ var _a, _b, _c, _d, _e, _f;
57346
57356
  return __awaiter$1(this, void 0, void 0, function* () {
57347
57357
  const table = this.table;
57348
- !isCut && (this.cutWaitPaste = !1);
57349
- const data = this.table.getCopyValue();
57358
+ !isCut && (this.cutWaitPaste = !1), this.copySourceRange = null;
57359
+ const sourceRanges = table.stateManager.select.ranges;
57360
+ if (sourceRanges && 1 === sourceRanges.length) {
57361
+ const sourceRange = sourceRanges[0];
57362
+ this.copySourceRange = {
57363
+ startCol: Math.min(sourceRange.start.col, sourceRange.end.col),
57364
+ startRow: Math.min(sourceRange.start.row, sourceRange.end.row)
57365
+ };
57366
+ } else if (!(null == sourceRanges ? void 0 : sourceRanges.length)) return void (this.copySourceRange = null);
57367
+ 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);
57350
57368
  if (isValid$4(data)) {
57351
57369
  e.preventDefault();
57352
- const permissionState = yield navigator.permissions.query({
57353
- name: "clipboard-write"
57354
- });
57355
- if ((null === (_a = navigator.clipboard) || void 0 === _a ? void 0 : _a.write) && "granted" === permissionState.state) {
57356
- const setDataToHTML = data => {
57357
- const result = ["<table>"],
57358
- META_HEAD = ['<meta name="author" content="Visactor"/>', '<style type="text/css">td{white-space:normal}br{mso-data-placement:same-cell}</style>'].join(""),
57359
- rows = data.split("\r\n");
57360
- return rows.forEach(function (rowCells, rowIndex) {
57361
- const cells = rowCells.split("\t"),
57362
- rowValues = [];
57363
- 0 === rowIndex && result.push("<tbody>"), cells.forEach(function (cell, cellIndex) {
57364
- const parsedCellData = cell ? cell.toString().replace(/&/g, "&amp;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br>").replace(/(<br(\s*|\/)>(\r\n|\n)?|\r\n|\n)/g, "<br>\r\n").replace(/\x20{2,}/gi, substring => `<span style="mso-spacerun: yes">${"&nbsp;".repeat(substring.length - 1)} </span>`).replace(/\t/gi, "&#9;") : " ";
57365
- rowValues.push(`<td>${parsedCellData}</td>`);
57366
- }), result.push("<tr>", ...rowValues, "</tr>"), rowIndex === rows.length - 1 && result.push("</tbody>");
57367
- }), result.push("</table>"), [META_HEAD, result.join("")].join("");
57368
- },
57369
- dataHTML = setDataToHTML(data);
57370
- navigator.clipboard.write([new ClipboardItem({
57371
- "text/html": new Blob([dataHTML], {
57372
- type: "text/html"
57373
- }),
57374
- "text/plain": new Blob([data], {
57375
- type: "text/plain"
57376
- })
57377
- })]);
57378
- } else browser.IE ? window.clipboardData.setData("Text", data) : e.clipboardData.setData("text/plain", data);
57379
- table.fireListeners(TABLE_EVENT_TYPE.COPY_DATA, {
57380
- cellRange: table.stateManager.select.ranges,
57381
- copyData: data,
57382
- isCut: isCut
57383
- });
57370
+ const element = table.getElement();
57371
+ element && element !== document.activeElement && (element.focus(), yield new Promise(resolve => setTimeout(resolve, 10)));
57372
+ try {
57373
+ if (navigator.clipboard && navigator.clipboard.writeText) {
57374
+ let hasPermission = !0;
57375
+ if (navigator.permissions && navigator.permissions.query) try {
57376
+ hasPermission = "granted" === (yield navigator.permissions.query({
57377
+ name: "clipboard-write"
57378
+ })).state;
57379
+ } catch (permissionError) {
57380
+ hasPermission = !0;
57381
+ }
57382
+ if (hasPermission) try {
57383
+ if (window.ClipboardItem) {
57384
+ let htmlValues = data;
57385
+ 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));
57386
+ const dataHTML = setDataToHTML(htmlValues);
57387
+ yield navigator.clipboard.write([new ClipboardItem({
57388
+ "text/html": new Blob([dataHTML], {
57389
+ type: "text/html"
57390
+ }),
57391
+ "text/plain": new Blob([data], {
57392
+ type: "text/plain"
57393
+ })
57394
+ })]);
57395
+ } else yield navigator.clipboard.writeText(data);
57396
+ } catch (clipboardError) {
57397
+ this.fallbackCopyToClipboard(data, e);
57398
+ } else this.fallbackCopyToClipboard(data, e);
57399
+ } else this.fallbackCopyToClipboard(data, e);
57400
+ table.fireListeners(TABLE_EVENT_TYPE.COPY_DATA, {
57401
+ cellRange: table.stateManager.select.ranges,
57402
+ copyData: data,
57403
+ isCut: isCut
57404
+ });
57405
+ } catch (error) {
57406
+ this.fallbackCopyToClipboard(data, e);
57407
+ }
57384
57408
  }
57385
- (null === (_b = table.keyboardOptions) || void 0 === _b ? void 0 : _b.showCopyCellBorder) && (setActiveCellRangeState(table), table.clearSelected());
57409
+ (null === (_f = table.keyboardOptions) || void 0 === _f ? void 0 : _f.showCopyCellBorder) && (setActiveCellRangeState(table), table.clearSelected());
57386
57410
  });
57387
57411
  }
57412
+ fallbackCopyToClipboard(data, e) {
57413
+ try {
57414
+ if (e.clipboardData) return void e.clipboardData.setData("text/plain", data);
57415
+ document.activeElement && document.activeElement !== document.body && document.activeElement.blur();
57416
+ const textArea = document.createElement("textarea");
57417
+ textArea.value = data, textArea.style.position = "fixed", textArea.style.left = "-999999px", textArea.style.top = "-999999px", textArea.style.opacity = "0", textArea.setAttribute("readonly", ""), textArea.setAttribute("aria-hidden", "true"), document.body.appendChild(textArea), textArea.focus(), textArea.select(), textArea.setSelectionRange(0, data.length);
57418
+ try {
57419
+ document.execCommand("copy");
57420
+ } catch (execError) {} finally {
57421
+ document.body.removeChild(textArea);
57422
+ }
57423
+ } catch (error) {}
57424
+ }
57388
57425
  handleCut(e) {
57389
57426
  return __awaiter$1(this, void 0, void 0, function* () {
57390
57427
  this.handleCopy(e, !0), this.cutWaitPaste = !0, this.cutCellRange = this.table.getSelectedCellInfos(), this.clipboardCheckTimer && clearTimeout(this.clipboardCheckTimer), this.clipboardCheckTimer = window.setTimeout(() => {
@@ -57400,36 +57437,73 @@
57400
57437
  }) : this.executePaste(e);
57401
57438
  }
57402
57439
  executePaste(e) {
57403
- var _a, _b, _c, _d;
57440
+ var _a, _b, _c;
57404
57441
  return __awaiter$1(this, void 0, void 0, function* () {
57405
57442
  const table = this.table;
57406
- if (table.changeCellValues) {
57407
- if (null === (_a = table.editorManager) || void 0 === _a ? void 0 : _a.editingEditor) return;
57408
- if ((null === (_b = table.stateManager.select.ranges) || void 0 === _b ? void 0 : _b.length) > 0) if (null === (_c = navigator.clipboard) || void 0 === _c ? void 0 : _c.read) navigator.clipboard.read().then(clipboardItems => {
57409
- for (const item of clipboardItems) item.types.includes("text/html") ? this.pasteHtmlToTable(item) : 1 === item.types.length && "text/plain" === item.types[0] && this.pasteTextToTable(item);
57410
- });else {
57411
- const ranges = table.stateManager.select.ranges,
57412
- col = Math.min(ranges[0].start.col, ranges[0].end.col),
57413
- row = Math.min(ranges[0].start.row, ranges[0].end.row),
57414
- rows = (e.clipboardData || window.Clipboard).getData("text").split("\n"),
57415
- values = [];
57416
- rows.forEach(function (rowCells, rowIndex) {
57417
- const cells = rowCells.split("\t"),
57418
- rowValues = [];
57419
- values.push(rowValues), cells.forEach(function (cell, cellIndex) {
57420
- cellIndex === cells.length - 1 && (cell = cell.trim()), rowValues.push(cell);
57421
- });
57422
- });
57423
- const changedCellResults = yield table.changeCellValues(col, row, values, !0);
57424
- table.hasListeners(TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE.PASTED_DATA, {
57425
- col: col,
57426
- row: row,
57427
- pasteData: values,
57428
- changedCellResults: changedCellResults
57429
- });
57443
+ if (!(null === (_a = table.editorManager) || void 0 === _a ? void 0 : _a.editingEditor)) {
57444
+ if (table.changeCellValues && (null === (_b = table.stateManager.select.ranges) || void 0 === _b ? void 0 : _b.length) > 0) try {
57445
+ if (navigator.clipboard && navigator.clipboard.read) try {
57446
+ const clipboardItems = yield navigator.clipboard.read();
57447
+ let handled = !1;
57448
+ for (const item of clipboardItems) {
57449
+ if (item.types.includes("text/html")) {
57450
+ yield this.pasteHtmlToTable(item), handled = !0;
57451
+ break;
57452
+ }
57453
+ if (item.types.includes("text/plain")) {
57454
+ yield this.pasteTextToTable(item), handled = !0;
57455
+ break;
57456
+ }
57457
+ }
57458
+ handled || (yield this.fallbackPasteFromClipboard(e));
57459
+ } catch (clipboardError) {
57460
+ yield this.fallbackPasteFromClipboard(e);
57461
+ } else yield this.fallbackPasteFromClipboard(e);
57462
+ } catch (error) {
57463
+ yield this.fallbackPasteFromClipboard(e);
57430
57464
  }
57465
+ (null === (_c = table.keyboardOptions) || void 0 === _c ? void 0 : _c.showCopyCellBorder) && clearActiveCellRangeState(table);
57431
57466
  }
57432
- (null === (_d = table.keyboardOptions) || void 0 === _d ? void 0 : _d.showCopyCellBorder) && clearActiveCellRangeState(table);
57467
+ });
57468
+ }
57469
+ fallbackPasteFromClipboard(e) {
57470
+ return __awaiter$1(this, void 0, void 0, function* () {
57471
+ const table = this.table,
57472
+ ranges = table.stateManager.select.ranges,
57473
+ col = Math.min(ranges[0].start.col, ranges[0].end.col),
57474
+ row = Math.min(ranges[0].start.row, ranges[0].end.row);
57475
+ try {
57476
+ const element = table.getElement();
57477
+ element && element !== document.activeElement && (element.focus(), yield new Promise(resolve => setTimeout(resolve, 10)));
57478
+ const clipboardData = e.clipboardData || window.clipboardData || window.Clipboard;
57479
+ if (clipboardData) {
57480
+ const pastedData = clipboardData.getData("text") || clipboardData.getData("Text");
57481
+ if (pastedData) return void (yield this.processPastedText(pastedData, col, row));
57482
+ }
57483
+ } catch (error) {}
57484
+ });
57485
+ }
57486
+ processPastedText(pastedData, col, row) {
57487
+ var _a;
57488
+ return __awaiter$1(this, void 0, void 0, function* () {
57489
+ const table = this.table,
57490
+ rows = pastedData.split("\n"),
57491
+ values = [];
57492
+ let processedValues;
57493
+ rows.forEach(function (rowCells) {
57494
+ const cells = rowCells.split("\t"),
57495
+ rowValues = [];
57496
+ values.push(rowValues), cells.forEach(function (cell, cellIndex) {
57497
+ cellIndex === cells.length - 1 && (cell = cell.trim()), rowValues.push(cell);
57498
+ });
57499
+ }), (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));
57500
+ const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
57501
+ table.hasListeners(TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE.PASTED_DATA, {
57502
+ col: col,
57503
+ row: row,
57504
+ pasteData: processedValues || values,
57505
+ changedCellResults: changedCellResults
57506
+ });
57433
57507
  });
57434
57508
  }
57435
57509
  clearCutArea(table) {
@@ -57471,7 +57545,7 @@
57471
57545
  values = [];
57472
57546
  item.getType("text/html").then(blob => {
57473
57547
  blob.text().then(pastedData => __awaiter$1(this, void 0, void 0, function* () {
57474
- var _a, _b;
57548
+ var _a, _b, _c;
57475
57549
  if (pastedData && /(<table)|(<TABLE)/g.test(pastedData)) {
57476
57550
  const matches = Array.from(pastedData.matchAll(regex));
57477
57551
  for (const match of matches) {
@@ -57479,12 +57553,13 @@
57479
57553
  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, " "));
57480
57554
  values.push(rowValues), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
57481
57555
  }
57482
- pasteValuesRowCount = null !== (_b = values.length) && void 0 !== _b ? _b : 0, values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1);
57483
- const changedCellResults = yield table.changeCellValues(col, row, values, !0);
57556
+ let processedValues;
57557
+ pasteValuesRowCount = null !== (_b = values.length) && void 0 !== _b ? _b : 0, values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1), (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));
57558
+ const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
57484
57559
  table.hasListeners(TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE.PASTED_DATA, {
57485
57560
  col: col,
57486
57561
  row: row,
57487
- pasteData: values,
57562
+ pasteData: processedValues || values,
57488
57563
  changedCellResults: changedCellResults
57489
57564
  });
57490
57565
  } else navigator.clipboard.read().then(clipboardItems => {
@@ -57496,7 +57571,7 @@
57496
57571
  });
57497
57572
  }
57498
57573
  _pasteValue(pastedData) {
57499
- var _a;
57574
+ var _a, _b;
57500
57575
  return __awaiter$1(this, void 0, void 0, function* () {
57501
57576
  const table = this.table,
57502
57577
  ranges = table.stateManager.select.ranges,
@@ -57508,6 +57583,7 @@
57508
57583
  let pasteValuesColCount = 0,
57509
57584
  pasteValuesRowCount = 0,
57510
57585
  values = [];
57586
+ let processedValues;
57511
57587
  pastedData.split("\n").forEach(function (rowCells, rowIndex) {
57512
57588
  var _a;
57513
57589
  const cells = rowCells.split("\t"),
@@ -57515,49 +57591,55 @@
57515
57591
  values.push(rowValues), cells.forEach(function (cell, cellIndex) {
57516
57592
  cellIndex === cells.length - 1 && (cell = cell.trim()), rowValues.push(cell);
57517
57593
  }), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
57518
- }), pasteValuesRowCount = null !== (_a = values.length) && void 0 !== _a ? _a : 0, values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1);
57519
- const changedCellResults = yield table.changeCellValues(col, row, values, !0);
57594
+ }), pasteValuesRowCount = null !== (_a = values.length) && void 0 !== _a ? _a : 0, values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1), (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));
57595
+ const changedCellResults = yield table.changeCellValues(col, row, processedValues || values, !0);
57520
57596
  table.hasListeners(TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE.PASTED_DATA, {
57521
57597
  col: col,
57522
57598
  row: row,
57523
- pasteData: values,
57599
+ pasteData: processedValues || values,
57524
57600
  changedCellResults: changedCellResults
57525
57601
  });
57526
57602
  });
57527
57603
  }
57528
57604
  pasteTextToTable(item) {
57529
- const table = this.table,
57530
- ranges = table.stateManager.select.ranges,
57531
- selectRangeLength = ranges.length,
57532
- col = Math.min(ranges[selectRangeLength - 1].start.col, ranges[selectRangeLength - 1].end.col),
57533
- row = Math.min(ranges[selectRangeLength - 1].start.row, ranges[selectRangeLength - 1].end.row),
57534
- maxCol = Math.max(ranges[selectRangeLength - 1].start.col, ranges[selectRangeLength - 1].end.col),
57535
- maxRow = Math.max(ranges[selectRangeLength - 1].start.row, ranges[selectRangeLength - 1].end.row);
57536
- let pasteValuesColCount = 0,
57537
- pasteValuesRowCount = 0;
57538
- item.getType("text/plain").then(blob => {
57539
- blob.text().then(pastedData => __awaiter$1(this, void 0, void 0, function* () {
57540
- var _a;
57541
- const rows = pastedData.replace(/\r(?!\n)/g, "\r\n").split("\r\n");
57542
- let values = [];
57543
- rows.length > 1 && "" === rows[rows.length - 1] && rows.pop(), rows.forEach(function (rowCells, rowIndex) {
57544
- var _a;
57545
- const cells = rowCells.split("\t"),
57546
- rowValues = [];
57547
- values.push(rowValues), cells.forEach(function (cell, cellIndex) {
57548
- cell.includes("\n") && (cell = cell.replace(/^"(.*)"$/, "$1").replace(/["]*/g, match => new Array(Math.floor(match.length / 2)).fill('"').join(""))), rowValues.push(cell);
57549
- }), pasteValuesColCount = Math.max(pasteValuesColCount, null !== (_a = null == rowValues ? void 0 : rowValues.length) && void 0 !== _a ? _a : 0);
57550
- }), pasteValuesRowCount = null !== (_a = values.length) && void 0 !== _a ? _a : 0, values = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1);
57551
- const changedCellResults = yield table.changeCellValues(col, row, values, !0);
57605
+ return __awaiter$1(this, void 0, void 0, function* () {
57606
+ const table = this.table,
57607
+ ranges = table.stateManager.select.ranges,
57608
+ selectRangeLength = ranges.length,
57609
+ col = Math.min(ranges[selectRangeLength - 1].start.col, ranges[selectRangeLength - 1].end.col),
57610
+ row = Math.min(ranges[selectRangeLength - 1].start.row, ranges[selectRangeLength - 1].end.row),
57611
+ maxCol = Math.max(ranges[selectRangeLength - 1].start.col, ranges[selectRangeLength - 1].end.col),
57612
+ maxRow = Math.max(ranges[selectRangeLength - 1].start.row, ranges[selectRangeLength - 1].end.row);
57613
+ try {
57614
+ const blob = yield item.getType("text/plain"),
57615
+ pastedData = yield blob.text(),
57616
+ values = this.parsePastedData(pastedData),
57617
+ pasteValuesRowCount = values.length,
57618
+ pasteValuesColCount = Math.max(...values.map(row => row.length), 0),
57619
+ processedValues = this.handlePasteValues(values, pasteValuesRowCount, pasteValuesColCount, maxRow - row + 1, maxCol - col + 1),
57620
+ changedCellResults = yield table.changeCellValues(col, row, processedValues, !0);
57552
57621
  table.hasListeners(TABLE_EVENT_TYPE.PASTED_DATA) && table.fireListeners(TABLE_EVENT_TYPE.PASTED_DATA, {
57553
57622
  col: col,
57554
57623
  row: row,
57555
- pasteData: values,
57624
+ pasteData: processedValues,
57556
57625
  changedCellResults: changedCellResults
57557
57626
  });
57558
- }));
57627
+ } catch (error) {}
57559
57628
  });
57560
57629
  }
57630
+ parsePastedData(pastedData) {
57631
+ const rows = pastedData.replace(/\r(?!\n)/g, "\r\n").split("\r\n"),
57632
+ values = [];
57633
+ return rows.length > 1 && "" === rows[rows.length - 1] && rows.pop(), rows.forEach(rowCells => {
57634
+ const rowValues = rowCells.split("\t").map(cell => this.processCellValue(cell));
57635
+ values.push(rowValues);
57636
+ }), values;
57637
+ }
57638
+ processCellValue(cell) {
57639
+ cell.includes("\n") && (cell = cell.replace(/^"(.*)"$/, "$1").replace(/["]*/g, match => new Array(Math.floor(match.length / 2)).fill('"').join("")));
57640
+ const numValue = Number(cell);
57641
+ return isNaN(numValue) ? cell : numValue;
57642
+ }
57561
57643
  handlePasteValues(values, rowCount, colCount, selectedRowCount, selectedColCount) {
57562
57644
  if (selectedColCount > colCount || selectedRowCount > rowCount) {
57563
57645
  if (selectedColCount % colCount == 0 && selectedRowCount % rowCount == 0) {
@@ -59664,7 +59746,7 @@
59664
59746
  }
59665
59747
  constructor(container, options = {}) {
59666
59748
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
59667
- if (super(), this.showFrozenIcon = !0, this.version = "1.22.6-alpha.2", this.id = `VTable${Date.now()}`, this.isReleased = !1, this._chartEventMap = {}, this.throttleInvalidate = throttle2(this.render.bind(this), 200), "node" === Env$1.mode ? (options = container, container = null) : container instanceof HTMLElement || (options = container, container = container.container ? container.container : null), !container && "node" !== options.mode && !options.canvas) throw new Error("vtable's container is undefined");
59749
+ if (super(), this.showFrozenIcon = !0, this.version = "1.22.6", this.id = `VTable${Date.now()}`, this.isReleased = !1, this._chartEventMap = {}, this.throttleInvalidate = throttle2(this.render.bind(this), 200), "node" === Env$1.mode ? (options = container, container = null) : container instanceof HTMLElement || (options = container, container = container.container ? container.container : null), !container && "node" !== options.mode && !options.canvas) throw new Error("vtable's container is undefined");
59668
59750
  this.pluginManager = new PluginManager(this, options), this.fireListeners(TABLE_EVENT_TYPE.BEFORE_INIT, {
59669
59751
  options: options,
59670
59752
  container: container
@@ -61323,7 +61405,7 @@
61323
61405
  end_row = this.rowCount - 1;
61324
61406
  return Array(end_row - start_row + 1).fill(0).map((_, i) => Array(end_col - start_col + 1).fill(0).map((_, j) => this.getCellInfo(j + start_col, i + start_row)));
61325
61407
  }
61326
- getCopyValue() {
61408
+ getCopyValue(getCellValueFunction) {
61327
61409
  var _a, _b, _c;
61328
61410
  if ((null === (_b = null === (_a = this.stateManager.select) || void 0 === _a ? void 0 : _a.ranges) || void 0 === _b ? void 0 : _b.length) > 0) {
61329
61411
  const ranges = this.stateManager.select.ranges;
@@ -61370,7 +61452,7 @@
61370
61452
  copyStartCol = Math.max(rangeMinCol, cellRange.start.col), copyStartRow = Math.max(rangeMinRow, cellRange.start.row);
61371
61453
  }
61372
61454
  if (copyStartCol !== col || copyStartRow !== row) return "";
61373
- return this.getCellValue(col, row);
61455
+ return getCellValueFunction ? getCellValueFunction(col, row) : this.getCellValue(col, row);
61374
61456
  };
61375
61457
  let copyValue = "";
61376
61458
  for (let r = minRow; r <= maxRow; r++) {
@@ -70676,7 +70758,8 @@
70676
70758
  document.addEventListener("keydown", this.handleKeyDown.bind(this), !0);
70677
70759
  }
70678
70760
  handleKeyDown(event) {
70679
- if (this.table.editorManager && this.isExcelShortcutKey(event)) {
70761
+ var _a, _b, _c;
70762
+ if ((null === (_a = this.table) || void 0 === _a ? void 0 : _a.editorManager) && this.isExcelShortcutKey(event)) {
70680
70763
  const eventKey = event.key.toLowerCase();
70681
70764
  if (this.table.editorManager.editingEditor && "keydown" === this.table.editorManager.beginTriggerEditCellMode) {
70682
70765
  const {
@@ -70692,7 +70775,7 @@
70692
70775
  if (!this.table.editorManager.editingEditor || eventKey !== ExcelEditCellKeyboardResponse.ENTER && eventKey !== ExcelEditCellKeyboardResponse.TAB) {
70693
70776
  if (!this.table.editorManager.editingEditor && (eventKey === ExcelEditCellKeyboardResponse.DELETE || eventKey === ExcelEditCellKeyboardResponse.BACKSPACE)) {
70694
70777
  const selectCells = this.table.getSelectedCellInfos();
70695
- (null == selectCells ? void 0 : selectCells.length) > 0 && document.activeElement === this.table.getElement() && (deleteSelectRange(selectCells, this.table), event.stopPropagation(), event.preventDefault());
70778
+ (null == selectCells ? void 0 : selectCells.length) > 0 && document.activeElement === this.table.getElement() && (deleteSelectRange(selectCells, this.table, null === (_c = null === (_b = this.pluginOptions) || void 0 === _b ? void 0 : _b.deleteWorkOnEditableCell) || void 0 === _c || _c), event.stopPropagation(), event.preventDefault());
70696
70779
  }
70697
70780
  } else this.table.editorManager.completeEdit(), this.table.getElement().focus(), eventKey === ExcelEditCellKeyboardResponse.ENTER ? this.table.selectCell(col, row + 1) : eventKey === ExcelEditCellKeyboardResponse.TAB && this.table.selectCell(col + 1, row), event.stopPropagation(), event.preventDefault();
70698
70781
  }
@@ -70714,8 +70797,8 @@
70714
70797
  document.removeEventListener("keydown", this.handleKeyDown, !0);
70715
70798
  }
70716
70799
  }
70717
- function deleteSelectRange(selectCells, tableInstance) {
70718
- for (let i = 0; i < selectCells.length; i++) for (let j = 0; j < selectCells[i].length; j++) tableInstance.changeCellValue(selectCells[i][j].col, selectCells[i][j].row, "");
70800
+ function deleteSelectRange(selectCells, tableInstance, workOnEditableCell = !1) {
70801
+ for (let i = 0; i < selectCells.length; i++) for (let j = 0; j < selectCells[i].length; j++) tableInstance.changeCellValue(selectCells[i][j].col, selectCells[i][j].row, "", workOnEditableCell);
70719
70802
  }
70720
70803
 
70721
70804
  const MENU_CONTAINER_CLASS = "vtable-context-menu-container";
@@ -72705,7 +72788,7 @@
72705
72788
  this.engine.applyFilter(this.state, this.table);
72706
72789
  }
72707
72790
  shouldApplyFilter(action) {
72708
- return [FilterActionType.REMOVE_FILTER, FilterActionType.ENABLE_FILTER, FilterActionType.DISABLE_FILTER, FilterActionType.CLEAR_ALL_FILTERS, FilterActionType.APPLY_FILTERS].includes(action.type) || action.payload.enable;
72791
+ return [FilterActionType.REMOVE_FILTER, FilterActionType.ENABLE_FILTER, FilterActionType.DISABLE_FILTER, FilterActionType.CLEAR_ALL_FILTERS, FilterActionType.APPLY_FILTERS].includes(action.type);
72709
72792
  }
72710
72793
  }
72711
72794
 
@@ -72849,191 +72932,98 @@
72849
72932
 
72850
72933
  class ValueFilter {
72851
72934
  constructor(table, filterStateManager) {
72852
- this.uniqueKeys = new Map(), this.displayToRawValueMap = new Map(), this.valueFilterOptionList = new Map(), this.table = table, this.filterStateManager = filterStateManager, this.filterStateManager.subscribe(state => {
72853
- const filterState = state.filters.get(this.selectedField);
72854
- filterState && "byValue" === filterState.type && this.updateUI(filterState);
72855
- });
72856
- }
72857
- updateUI(filterState) {
72858
- this.syncCheckboxesWithFilterState(filterState), this.syncSelectAllWithFilterState(filterState);
72935
+ this.selectedKeys = new Map(), this.candidateKeys = new Map(), this.formatFnCache = new Map(), this.toUnformattedCache = new Map(), this.valueFilterOptionList = new Map(), this.table = table, this.filterStateManager = filterStateManager;
72859
72936
  }
72860
72937
  setSelectedField(fieldId) {
72861
- this.selectedField = fieldId, this.collectUniqueColumnValues(fieldId);
72862
- }
72863
- collectUniqueColumnValues(fieldId) {
72864
- var _a;
72865
- const isEnable = null === (_a = this.filterStateManager.getFilterState(fieldId)) || void 0 === _a ? void 0 : _a.enable,
72866
- displayValueMap = new Map(),
72867
- rawToDisplayMap = new Map(),
72868
- displayToRawMap = new Map();
72869
- let targetCol = -1;
72870
- for (let col = 0; col < this.table.colCount; col++) {
72871
- for (let row = this.table.columnHeaderLevelCount; row < this.table.rowCount; row++) if (!this.table.internalProps.layoutMap.isHeader(col, row)) {
72872
- const bodyInfo = this.table.internalProps.layoutMap.getBody(col, row);
72873
- if (bodyInfo && bodyInfo.field === fieldId) {
72874
- targetCol = col;
72875
- break;
72876
- }
72877
- }
72878
- if (-1 !== targetCol) break;
72879
- }
72880
- if (isEnable) {
72881
- const records = this.table.internalProps.records,
72882
- recordsLength = records.length;
72883
- for (let i = 0; i < recordsLength; i++) {
72884
- let rawValue, displayValue;
72885
- if (-1 !== targetCol) {
72886
- const row = this.table.columnHeaderLevelCount + i;
72887
- rawValue = records[i][fieldId];
72888
- const bodyInfo = this.table.internalProps.layoutMap.getBody(targetCol, row);
72889
- displayValue = bodyInfo && "fieldFormat" in bodyInfo && bodyInfo.fieldFormat && "function" == typeof bodyInfo.fieldFormat ? bodyInfo.fieldFormat({
72890
- [fieldId]: rawValue
72891
- }) : rawValue;
72892
- }
72893
- null != rawValue && (displayValueMap.set(displayValue, (displayValueMap.get(displayValue) || 0) + 1), rawToDisplayMap.set(rawValue, displayValue), displayToRawMap.set(displayValue, rawValue));
72894
- }
72895
- } else {
72896
- const currentLength = this.table.internalProps.dataSource.length;
72897
- for (let i = 0; i < currentLength; i++) {
72898
- let rawValue, displayValue;
72899
- if (-1 !== targetCol) {
72900
- const row = this.table.columnHeaderLevelCount + i;
72901
- row < this.table.rowCount && (rawValue = this.table.getCellOriginValue(targetCol, row), displayValue = this.table.getCellValue(targetCol, row));
72902
- } else rawValue = this.table.getFieldData(String(fieldId), -1 !== targetCol ? targetCol : 0, this.table.columnHeaderLevelCount + i), displayValue = rawValue;
72903
- null != rawValue && (displayValueMap.set(displayValue, (displayValueMap.get(displayValue) || 0) + 1), rawToDisplayMap.set(rawValue, displayValue), displayToRawMap.set(displayValue, rawValue));
72904
- }
72905
- }
72906
- this.displayToRawValueMap.set(fieldId, displayToRawMap);
72907
- const uniqueValues = Array.from(displayValueMap.entries()).map(([displayValue, count]) => ({
72908
- value: displayValue,
72909
- count: count,
72910
- rawValue: displayToRawMap.get(displayValue)
72911
- }));
72912
- this.uniqueKeys.set(fieldId, uniqueValues);
72913
- }
72914
- onValueSelect(fieldId, displayValue, selected) {
72915
- const displayToRawMap = this.displayToRawValueMap.get(fieldId),
72916
- rawValue = displayToRawMap ? displayToRawMap.get(displayValue) : displayValue,
72917
- filter = this.filterStateManager.getFilterState(fieldId);
72918
- if (filter) {
72919
- const updatedValues = selected ? [...(filter.values || []), rawValue] : (filter.values || []).filter(v => v !== rawValue);
72920
- this.filterStateManager.dispatch({
72921
- type: FilterActionType.UPDATE_FILTER,
72922
- payload: {
72923
- field: fieldId,
72924
- values: updatedValues
72925
- }
72926
- });
72927
- } else this.filterStateManager.dispatch({
72928
- type: FilterActionType.ADD_FILTER,
72929
- payload: {
72930
- field: fieldId,
72931
- type: "byValue",
72932
- values: [rawValue]
72933
- }
72934
- });
72938
+ this.selectedField = fieldId;
72939
+ }
72940
+ getFormatFnCache(fieldId) {
72941
+ let formatFn = this.formatFnCache.get(fieldId);
72942
+ if (null != formatFn) return formatFn;
72943
+ const headerAddress = this.table.internalProps.layoutMap.getHeaderCellAddressByField(String(fieldId)),
72944
+ bodyInfo = this.table.internalProps.layoutMap.getBody(null == headerAddress ? void 0 : headerAddress.col, null == headerAddress ? void 0 : headerAddress.row);
72945
+ return formatFn = bodyInfo && "fieldFormat" in bodyInfo && "function" == typeof bodyInfo.fieldFormat ? bodyInfo.fieldFormat : bodyInfo && "format" in bodyInfo && "function" == typeof bodyInfo.format ? bodyInfo.format : record => record[fieldId], this.formatFnCache.set(fieldId, formatFn), formatFn;
72946
+ }
72947
+ collectCandidateKeysForUnfilteredColumn(fieldId) {
72948
+ const countMap = new Map(),
72949
+ records = this.table.internalProps.dataSource.records,
72950
+ formatFn = this.getFormatFnCache(fieldId),
72951
+ toUnformatted = new Map();
72952
+ records.forEach(record => {
72953
+ const originalValue = record[fieldId],
72954
+ formattedValue = formatFn(record);
72955
+ if (null != formattedValue) {
72956
+ countMap.set(formattedValue, (countMap.get(formattedValue) || 0) + 1);
72957
+ const unformattedSet = toUnformatted.get(formattedValue);
72958
+ null != unformattedSet ? unformattedSet.add(originalValue) : toUnformatted.set(formattedValue, new Set([originalValue]));
72959
+ }
72960
+ }), this.candidateKeys.set(fieldId, countMap), this.toUnformattedCache.set(fieldId, toUnformatted);
72961
+ }
72962
+ collectCandidateKeysForFilteredColumn(candidateField) {
72963
+ const filteredFields = this.filterStateManager.getActiveFilterFields().filter(field => field !== candidateField),
72964
+ toUnformatted = new Map(),
72965
+ formatFn = this.getFormatFnCache(candidateField),
72966
+ countMap = new Map();
72967
+ this.table.internalProps.records.filter(record => filteredFields.every(field => this.selectedKeys.get(field).has(record[field]))).forEach(record => {
72968
+ const originalValue = record[candidateField],
72969
+ formattedValue = formatFn(record);
72970
+ if (countMap.set(formattedValue, (countMap.get(formattedValue) || 0) + 1), null != formattedValue) {
72971
+ const unformattedSet = toUnformatted.get(formattedValue);
72972
+ null != unformattedSet ? unformattedSet.add(originalValue) : toUnformatted.set(formattedValue, new Set([originalValue]));
72973
+ }
72974
+ }), this.candidateKeys.set(candidateField, countMap), this.toUnformattedCache.set(candidateField, toUnformatted);
72935
72975
  }
72936
72976
  toggleSelectAll(fieldId, selected) {
72937
- var _a;
72938
- const filter = this.filterStateManager.getFilterState(fieldId),
72939
- rawValuesToUpdate = selected && (null === (_a = this.uniqueKeys.get(fieldId)) || void 0 === _a ? void 0 : _a.map(item => item.rawValue)) || [];
72940
- if (filter) {
72941
- const updatedValues = selected ? rawValuesToUpdate : [];
72942
- this.filterStateManager.dispatch({
72943
- type: FilterActionType.UPDATE_FILTER,
72944
- payload: {
72945
- field: fieldId,
72946
- values: updatedValues
72947
- }
72948
- });
72949
- } else this.filterStateManager.dispatch({
72950
- type: FilterActionType.ADD_FILTER,
72951
- payload: {
72952
- field: fieldId,
72953
- type: "byValue",
72954
- values: rawValuesToUpdate,
72955
- enable: !0
72956
- }
72977
+ this.valueFilterOptionList.get(fieldId).forEach(option => {
72978
+ option.checkbox.checked = selected;
72957
72979
  });
72958
72980
  }
72981
+ syncSelectAllCheckbox(fieldId) {
72982
+ const options = this.valueFilterOptionList.get(fieldId) || [],
72983
+ allChecked = options.every(o => o.checkbox.checked),
72984
+ noneChecked = options.every(o => !o.checkbox.checked);
72985
+ this.selectAllCheckbox.checked = allChecked, this.selectAllCheckbox.indeterminate = !allChecked && !noneChecked;
72986
+ }
72959
72987
  onSearch(fieldId, value) {
72960
- const filterKeywords = value.toUpperCase().split(" ").filter(s => s),
72961
- items = this.valueFilterOptionList.get(fieldId);
72988
+ const items = this.valueFilterOptionList.get(fieldId),
72989
+ filterKeywords = value.toUpperCase().split(" ").filter(s => s);
72962
72990
  for (const item of items) {
72963
72991
  const txtValue = item.id.toUpperCase() || "",
72964
- match = filterKeywords.some(keyword => txtValue.includes(keyword));
72965
- item.itemContainer.style.display = 0 === filterKeywords.length || match ? "flex" : "none";
72992
+ match = filterKeywords.some(keyword => txtValue.includes(keyword)),
72993
+ isVisible = 0 === filterKeywords.length || match;
72994
+ item.itemContainer.style.display = isVisible ? "flex" : "none";
72966
72995
  }
72967
72996
  }
72968
72997
  initFilterStateFromTableData(fieldId) {
72969
- const filter = this.filterStateManager.getFilterState(fieldId),
72970
- selectedRawValues = new Set(),
72971
- displayToRawMap = this.displayToRawValueMap.get(fieldId);
72972
- let targetCol = -1;
72973
- for (let col = 0; col < this.table.colCount; col++) {
72974
- for (let row = this.table.columnHeaderLevelCount; row < this.table.rowCount; row++) if (!this.table.internalProps.layoutMap.isHeader(col, row)) {
72975
- const bodyInfo = this.table.internalProps.layoutMap.getBody(col, row);
72976
- if (bodyInfo && bodyInfo.field === fieldId) {
72977
- targetCol = col;
72978
- break;
72979
- }
72980
- }
72981
- if (-1 !== targetCol) break;
72982
- }
72983
- const currentLength = this.table.internalProps.dataSource.length;
72984
- for (let i = 0; i < currentLength; i++) {
72985
- let displayValue, rawValue;
72986
- if (-1 !== targetCol) {
72987
- const row = this.table.columnHeaderLevelCount + i;
72988
- row < this.table.rowCount && (displayValue = this.table.getCellValue(targetCol, row), rawValue = displayToRawMap ? displayToRawMap.get(displayValue) : displayValue);
72989
- } else displayValue = this.table.getFieldData(String(fieldId), -1 !== targetCol ? targetCol : 0, this.table.columnHeaderLevelCount + i), rawValue = displayToRawMap ? displayToRawMap.get(displayValue) : displayValue;
72990
- null != rawValue && selectedRawValues.add(rawValue);
72991
- }
72992
- (!filter || !arrayEqual(filter.values, Array.from(selectedRawValues))) && (filter ? this.filterStateManager.dispatch({
72993
- type: FilterActionType.UPDATE_FILTER,
72994
- payload: {
72995
- field: fieldId,
72996
- type: "byValue",
72997
- values: Array.from(selectedRawValues)
72998
- }
72999
- }) : this.filterStateManager.dispatch({
72998
+ if (this.filterStateManager.getActiveFilterFields()) return;
72999
+ const selectedValues = new Set(),
73000
+ originalValues = new Set();
73001
+ this.table.internalProps.dataSource.records.forEach(record => {
73002
+ selectedValues.add(record[fieldId]);
73003
+ });
73004
+ this.table.internalProps.records.forEach(record => {
73005
+ originalValues.add(record[fieldId]);
73006
+ });
73007
+ !arrayEqual(Array.from(originalValues), Array.from(selectedValues)) && (this.selectedKeys.set(fieldId, selectedValues), this.filterStateManager.dispatch({
73000
73008
  type: FilterActionType.ADD_FILTER,
73001
73009
  payload: {
73002
73010
  field: fieldId,
73003
73011
  type: "byValue",
73004
- values: Array.from(selectedRawValues)
73012
+ values: Array.from(selectedValues),
73013
+ enable: !0
73005
73014
  }
73006
73015
  }));
73007
73016
  }
73008
- syncCheckboxesWithFilterState(filter) {
73009
- if (!filter) return;
73010
- const selectedRawValues = filter.values || [],
73011
- displayToRawMap = this.displayToRawValueMap.get(filter.field),
73012
- optionDomList = this.valueFilterOptionList.get(filter.field);
73013
- null == optionDomList || optionDomList.forEach(optionDom => {
73014
- var _a, _b;
73015
- const displayValue = optionDom.originalValue,
73016
- rawValue = displayToRawMap ? displayToRawMap.get(displayValue) : displayValue;
73017
- optionDom.checkbox.checked = selectedRawValues.some(v => v === rawValue);
73018
- const count = (null === (_b = null === (_a = this.uniqueKeys.get(filter.field)) || void 0 === _a ? void 0 : _a.find(key => String(key.value) === optionDom.id)) || void 0 === _b ? void 0 : _b.count) || 0;
73019
- optionDom.countSpan.textContent = String(count), optionDom.itemContainer.style.display = 0 === count ? "none" : "flex";
73020
- });
73021
- }
73022
- syncSelectAllWithFilterState(filter) {
73023
- var _a;
73024
- if (!filter || !filter.values) return this.selectAllCheckbox.checked = !1, void (this.selectAllCheckbox.indeterminate = !1);
73025
- const uniqueValuesCount = (null === (_a = this.uniqueKeys.get(filter.field)) || void 0 === _a ? void 0 : _a.length) || 0;
73026
- 0 === uniqueValuesCount || 0 === filter.values.length ? (this.selectAllCheckbox.checked = !1, this.selectAllCheckbox.indeterminate = !1) : filter.values.length === uniqueValuesCount ? (this.selectAllCheckbox.checked = !0, this.selectAllCheckbox.indeterminate = !1) : (this.selectAllCheckbox.checked = !1, this.selectAllCheckbox.indeterminate = !0);
73027
- }
73028
73017
  applyFilter(fieldId = this.selectedField) {
73029
- var _a, _b;
73030
- const selectedKeys = (null === (_a = this.filterStateManager.getFilterState(fieldId)) || void 0 === _a ? void 0 : _a.values) || [];
73031
- selectedKeys.length > 0 && selectedKeys.length < (null === (_b = this.uniqueKeys.get(fieldId)) || void 0 === _b ? void 0 : _b.length) ? this.filterStateManager.dispatch({
73018
+ const options = this.valueFilterOptionList.get(fieldId);
73019
+ if (!options || 0 === options.length) return;
73020
+ const selections = options.map(option => option.checkbox.checked ? option.originalValue : null).filter(key => null !== key).flat();
73021
+ this.selectedKeys.set(fieldId, new Set(selections)), selections.length > 0 && selections.length < this.valueFilterOptionList.get(fieldId).length ? this.filterStateManager.dispatch({
73032
73022
  type: FilterActionType.APPLY_FILTERS,
73033
73023
  payload: {
73034
73024
  field: fieldId,
73035
73025
  type: "byValue",
73036
- values: selectedKeys,
73026
+ values: selections,
73037
73027
  enable: !0
73038
73028
  }
73039
73029
  }) : this.filterStateManager.dispatch({
@@ -73060,57 +73050,58 @@
73060
73050
  const selectAllItemDiv = document.createElement("div");
73061
73051
  applyStyles(selectAllItemDiv, filterStyles.optionItem);
73062
73052
  const selectAllLabel = document.createElement("label");
73063
- applyStyles(selectAllLabel, filterStyles.optionLabel), this.selectAllCheckbox = document.createElement("input"), this.selectAllCheckbox.type = "checkbox", this.selectAllCheckbox.checked = !0, applyStyles(this.selectAllCheckbox, filterStyles.checkbox), selectAllLabel.append(this.selectAllCheckbox, " 全选"), selectAllItemDiv.appendChild(selectAllLabel), this.filterItemsContainer = document.createElement("div"), optionsContainer.append(selectAllItemDiv, this.filterItemsContainer), this.filterByValuePanel.append(searchContainer, optionsContainer), container.appendChild(this.filterByValuePanel), this.bindEventForFilterByValue();
73053
+ applyStyles(selectAllLabel, filterStyles.optionLabel), this.selectAllCheckbox = document.createElement("input"), this.selectAllCheckbox.type = "checkbox", this.selectAllCheckbox.checked = !0, applyStyles(this.selectAllCheckbox, filterStyles.checkbox), this.totalCountSpan = document.createElement("span"), this.totalCountSpan.textContent = "", applyStyles(this.totalCountSpan, filterStyles.countSpan), selectAllLabel.append(this.selectAllCheckbox, " 全选"), selectAllItemDiv.append(selectAllLabel, this.totalCountSpan), this.filterItemsContainer = document.createElement("div"), optionsContainer.append(selectAllItemDiv, this.filterItemsContainer), this.filterByValuePanel.append(searchContainer, optionsContainer), container.appendChild(this.filterByValuePanel), this.bindEventForFilterByValue();
73064
73054
  }
73065
73055
  renderFilterOptions(field) {
73066
- var _a, _b;
73056
+ var _a, _b, _c;
73067
73057
  this.filterItemsContainer.innerHTML = "", this.valueFilterOptionList.delete(field), this.valueFilterOptionList.set(field, []);
73068
- const selectedRawValues = (null === (_a = this.filterStateManager.getFilterState(field)) || void 0 === _a ? void 0 : _a.values) || [],
73069
- selectedRawValueSet = new Set(selectedRawValues),
73070
- itemDomList = [];
73071
- null === (_b = this.uniqueKeys.get(field)) || void 0 === _b || _b.forEach(({
73072
- value: value,
73073
- count: count,
73074
- rawValue: rawValue
73075
- }) => {
73076
- const itemDiv = document.createElement("div");
73077
- applyStyles(itemDiv, filterStyles.optionItem);
73058
+ let totalCount = 0,
73059
+ allChecked = !0,
73060
+ noneChecked = !0;
73061
+ const selectedKeysSet = this.selectedKeys.get(field),
73062
+ itemDomList = [],
73063
+ isFiltered = null === (_a = this.filterStateManager.getFilterState(field)) || void 0 === _a ? void 0 : _a.enable,
73064
+ toUnformatted = this.toUnformattedCache.get(field),
73065
+ candidates = this.candidateKeys.get(field);
73066
+ if (!candidates || 0 === candidates.size) return;
73067
+ const candidatesArr = [...candidates.entries()],
73068
+ sortedCandidatesArr = "number" == typeof candidatesArr[0][0] ? null === (_b = [...candidatesArr]) || void 0 === _b ? void 0 : _b.sort(([a], [b]) => Number(a) - Number(b)) : null === (_c = [...candidatesArr]) || void 0 === _c ? void 0 : _c.sort(([a], [b]) => String(a).localeCompare(String(b)));
73069
+ null == sortedCandidatesArr || sortedCandidatesArr.forEach(([val, count]) => {
73070
+ totalCount += count;
73071
+ const unformattedArr = Array.from(toUnformatted.get(val) || new Set()),
73072
+ itemDiv = document.createElement("div");
73073
+ applyStyles(itemDiv, filterStyles.optionItem), itemDiv.style.display = "flex";
73078
73074
  const label = document.createElement("label");
73079
73075
  applyStyles(label, filterStyles.optionLabel);
73080
73076
  const checkbox = document.createElement("input");
73081
- checkbox.type = "checkbox", checkbox.value = String(value), checkbox.checked = selectedRawValueSet.has(rawValue), applyStyles(checkbox, filterStyles.checkbox);
73077
+ checkbox.type = "checkbox", checkbox.value = String(val), checkbox.checked = !isFiltered || unformattedArr.some(v => null == selectedKeysSet ? void 0 : selectedKeysSet.has(v)), applyStyles(checkbox, filterStyles.checkbox), checkbox.checked ? noneChecked = !1 : allChecked = !1;
73082
73078
  const countSpan = document.createElement("span");
73083
- countSpan.textContent = String(count), applyStyles(countSpan, filterStyles.countSpan), label.append(checkbox, ` ${value}`), itemDiv.append(label, countSpan), this.filterItemsContainer.appendChild(itemDiv);
73079
+ countSpan.textContent = String(count), applyStyles(countSpan, filterStyles.countSpan), label.append(checkbox, ` ${val}`), itemDiv.append(label, countSpan), this.filterItemsContainer.appendChild(itemDiv);
73084
73080
  const itemDom = {
73085
- id: String(value),
73086
- originalValue: value,
73081
+ id: String(val),
73082
+ originalValue: unformattedArr,
73087
73083
  itemContainer: itemDiv,
73088
73084
  checkbox: checkbox,
73089
73085
  countSpan: countSpan
73090
73086
  };
73091
73087
  itemDomList.push(itemDom);
73092
- }), this.valueFilterOptionList.set(field, itemDomList);
73088
+ }), this.valueFilterOptionList.set(field, itemDomList), this.selectAllCheckbox.checked = allChecked, this.selectAllCheckbox.indeterminate = !allChecked && !noneChecked, this.totalCountSpan.textContent = String(totalCount);
73093
73089
  }
73094
73090
  bindEventForFilterByValue() {
73095
- this.filterByValuePanel.addEventListener("keyup", event => {
73091
+ this._onInputKeyUpHandler = event => {
73096
73092
  const target = event.target;
73097
73093
  if (target instanceof HTMLInputElement && "text" === target.type) {
73098
73094
  const value = target.value;
73099
73095
  this.onSearch(this.selectedField, value);
73100
73096
  }
73101
- }), this.filterByValuePanel.addEventListener("change", event => {
73102
- var _a, _b;
73097
+ }, this._onCheckboxChangeHandler = event => {
73103
73098
  const target = event.target;
73104
- if (target instanceof HTMLInputElement && "checkbox" === target.type) if (target === this.selectAllCheckbox) this.toggleSelectAll(this.selectedField, this.selectAllCheckbox.checked);else {
73105
- const checkbox = target,
73106
- checked = checkbox.checked,
73107
- value = null === (_b = null === (_a = this.valueFilterOptionList.get(this.selectedField)) || void 0 === _a ? void 0 : _a.find(item => item.id === checkbox.value)) || void 0 === _b ? void 0 : _b.originalValue;
73108
- this.onValueSelect(this.selectedField, value, checked);
73109
- }
73110
- });
73099
+ target instanceof HTMLInputElement && "checkbox" === target.type && (target === this.selectAllCheckbox ? this.toggleSelectAll(this.selectedField, this.selectAllCheckbox.checked) : this.syncSelectAllCheckbox(this.selectedField));
73100
+ }, this.filterByValuePanel.addEventListener("keyup", this._onInputKeyUpHandler), this.filterByValuePanel.addEventListener("change", this._onCheckboxChangeHandler);
73111
73101
  }
73112
73102
  show() {
73113
- this.initFilterStateFromTableData(this.selectedField), this.renderFilterOptions(this.selectedField), this.filterByValuePanel.style.display = "block";
73103
+ var _a;
73104
+ (null === (_a = this.filterStateManager.getFilterState(this.selectedField)) || void 0 === _a ? void 0 : _a.enable) ? this.collectCandidateKeysForFilteredColumn(this.selectedField) : this.collectCandidateKeysForUnfilteredColumn(this.selectedField), this.initFilterStateFromTableData(this.selectedField), this.filterByValueSearchInput && (this.filterByValueSearchInput.value = ""), this.renderFilterOptions(this.selectedField), this.filterByValuePanel.style.display = "block";
73114
73105
  }
73115
73106
  hide() {
73116
73107
  this.filterByValuePanel.style.display = "none";
@@ -73118,6 +73109,13 @@
73118
73109
  clearSearchInputValue() {
73119
73110
  this.filterByValueSearchInput.value = "";
73120
73111
  }
73112
+ destroy() {
73113
+ if (this.filterByValuePanel && (this._onInputKeyUpHandler && this.filterByValuePanel.removeEventListener("keyup", this._onInputKeyUpHandler), this._onCheckboxChangeHandler && this.filterByValuePanel.removeEventListener("change", this._onCheckboxChangeHandler)), this._onInputKeyUpHandler = void 0, this._onCheckboxChangeHandler = void 0, this.filterByValuePanel) {
73114
+ const parent = this.filterByValuePanel.parentElement;
73115
+ parent ? parent.removeChild(this.filterByValuePanel) : this.filterByValuePanel.remove();
73116
+ }
73117
+ this.filterItemsContainer && (this.filterItemsContainer.innerHTML = ""), this.filterByValueSearchInput && (this.filterByValueSearchInput.value = ""), this.selectedKeys && this.selectedKeys.clear(), this.candidateKeys && this.candidateKeys.clear(), this.formatFnCache && this.formatFnCache.clear(), this.toUnformattedCache && this.toUnformattedCache.clear(), this.valueFilterOptionList && this.valueFilterOptionList.clear(), this.filterByValuePanel = void 0, this.filterByValueSearchInput = void 0, this.selectAllCheckbox = void 0, this.totalCountSpan = void 0, this.filterItemsContainer = void 0;
73118
+ }
73121
73119
  }
73122
73120
 
73123
73121
  class ConditionFilter {
@@ -73360,7 +73358,9 @@
73360
73358
 
73361
73359
  class FilterToolbar {
73362
73360
  constructor(table, filterStateManager) {
73363
- this.valueFilter = null, this.conditionFilter = null, this.activeTab = "byValue", this.isVisible = !1, this.selectedField = null, this.filterModes = [], this.table = table, this.filterStateManager = filterStateManager, this.valueFilter = new ValueFilter(this.table, this.filterStateManager), this.conditionFilter = new ConditionFilter(this.table, this.filterStateManager), this.filterMenuWidth = 300;
73361
+ this.valueFilter = null, this.conditionFilter = null, this.activeTab = "byValue", this.isVisible = !1, this.selectedField = null, this.filterModes = [], this.table = table, this.filterStateManager = filterStateManager, this.valueFilter = new ValueFilter(this.table, this.filterStateManager), this.conditionFilter = new ConditionFilter(this.table, this.filterStateManager), this.filterMenuWidth = 300, this.filterStateManager.subscribe(state => {
73362
+ this.isVisible && null !== this.selectedField && this.updateClearFilterButtonState(this.selectedField);
73363
+ });
73364
73364
  }
73365
73365
  onTabSwitch(tab) {
73366
73366
  this.activeTab = tab, "byValue" === tab ? (this.valueFilter.show(), this.conditionFilter.hide()) : (this.conditionFilter.show(), this.valueFilter.hide());
@@ -73376,6 +73376,11 @@
73376
73376
  clearFilter(field) {
73377
73377
  this.valueFilter && this.valueFilter.clearFilter(field), this.conditionFilter && this.conditionFilter.clearFilter(field), this.hide();
73378
73378
  }
73379
+ updateClearFilterButtonState(field) {
73380
+ const currentFilter = this.filterStateManager.getFilterState(field),
73381
+ hasActiveFilter = currentFilter && currentFilter.enable;
73382
+ this.clearFilterOptionLink.style.display = "inline", this.clearFilterOptionLink.style.opacity = hasActiveFilter ? "1" : "0.5", this.clearFilterOptionLink.style.pointerEvents = hasActiveFilter ? "auto" : "none", this.clearFilterOptionLink.style.cursor = hasActiveFilter ? "pointer" : "not-allowed";
73383
+ }
73379
73384
  render(container) {
73380
73385
  this.filterMenu = document.createElement("div"), applyStyles(this.filterMenu, filterStyles.filterMenu), this.filterMenu.style.width = `${this.filterMenuWidth}px`;
73381
73386
  const filterTabsContainer = document.createElement("div");
@@ -73417,7 +73422,7 @@
73417
73422
  const field = this.table.internalProps.layoutMap.getHeaderField(col, row);
73418
73423
  this.updateSelectedField(field);
73419
73424
  const currentFilter = this.filterStateManager.getFilterState(field);
73420
- currentFilter && "byCondition" === currentFilter.type ? this.onTabSwitch("byCondition") : this.onTabSwitch("byValue"), setTimeout(() => {
73425
+ currentFilter && "byCondition" === currentFilter.type ? this.onTabSwitch("byCondition") : this.onTabSwitch("byValue"), this.updateClearFilterButtonState(field), setTimeout(() => {
73421
73426
  this.isVisible = !0;
73422
73427
  }, 0);
73423
73428
  }
@@ -73542,7 +73547,7 @@
73542
73547
  }));
73543
73548
  }
73544
73549
  release() {
73545
- this.table = null, this.filterEngine = null, this.filterStateManager = null, this.filterToolbar = null;
73550
+ this.table = null, this.filterEngine = null, this.filterStateManager = null, this.filterToolbar.valueFilter.destroy(), this.filterToolbar = null;
73546
73551
  }
73547
73552
  }
73548
73553
 
@@ -73563,6 +73568,136 @@
73563
73568
  DATA_TYPE.NUMBER = "number", DATA_TYPE.DATE = "date", DATA_TYPE.EXTEND_NUMBER = "extendNumber", DATA_TYPE.CHN_NUMBER = "chnNumber", DATA_TYPE.CHN_WEEK2 = "chnWeek2", DATA_TYPE.CHN_WEEK3 = "chnWeek3", DATA_TYPE.LOOP_SERIES = "loopSeries", DATA_TYPE.FORMULA = "formula", DATA_TYPE.OTHER = "other";
73564
73569
  }(DATA_TYPE || (DATA_TYPE = {}));
73565
73570
 
73571
+ function getSelectedRangeArray(selectedRange) {
73572
+ const minCol = Math.min(selectedRange.start.col, selectedRange.end.col),
73573
+ minRow = Math.min(selectedRange.start.row, selectedRange.end.row),
73574
+ maxCol = Math.max(selectedRange.start.col, selectedRange.end.col),
73575
+ maxRow = Math.max(selectedRange.start.row, selectedRange.end.row),
73576
+ cols = [],
73577
+ rows = [];
73578
+ for (let i = minCol; i <= maxCol; i++) cols.push(i);
73579
+ for (let i = minRow; i <= maxRow; i++) rows.push(i);
73580
+ return {
73581
+ cols: cols,
73582
+ rows: rows
73583
+ };
73584
+ }
73585
+ function getTargetRange(direction, sourceRange, selectedRange) {
73586
+ return direction === Direction.DOWN || direction === Direction.UP ? {
73587
+ cols: selectedRange.cols,
73588
+ rows: selectedRange.rows.filter(row => !sourceRange.rows.includes(row))
73589
+ } : {
73590
+ cols: selectedRange.cols.filter(col => !sourceRange.cols.includes(col)),
73591
+ rows: selectedRange.rows
73592
+ };
73593
+ }
73594
+ function openAutoFillMenu(tableInstance, endCol, endRow) {
73595
+ const rect = tableInstance.scenegraph.highPerformanceGetCell(endCol, endRow).globalAABBBounds;
73596
+ tableInstance.showDropDownMenu(endCol, endRow, {
73597
+ content: [{
73598
+ type: "item",
73599
+ text: "复制填充",
73600
+ icon: {
73601
+ width: 16,
73602
+ height: 16,
73603
+ svg: '<svg t="1756136702877" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1474" width="200" height="200"><path d="M853.333333 981.333333h-384c-72.533333 0-128-55.466667-128-128v-384c0-72.533333 55.466667-128 128-128h384c72.533333 0 128 55.466667 128 128v384c0 72.533333-55.466667 128-128 128z m-384-554.666666c-25.6 0-42.666667 17.066667-42.666666 42.666666v384c0 25.6 17.066667 42.666667 42.666666 42.666667h384c25.6 0 42.666667-17.066667 42.666667-42.666667v-384c0-25.6-17.066667-42.666667-42.666667-42.666666h-384z" p-id="1475"></path><path d="M213.333333 682.666667H170.666667c-72.533333 0-128-55.466667-128-128V170.666667c0-72.533333 55.466667-128 128-128h384c72.533333 0 128 55.466667 128 128v42.666666c0 25.6-17.066667 42.666667-42.666667 42.666667s-42.666667-17.066667-42.666667-42.666667V170.666667c0-25.6-17.066667-42.666667-42.666666-42.666667H170.666667c-25.6 0-42.666667 17.066667-42.666667 42.666667v384c0 25.6 17.066667 42.666667 42.666667 42.666666h42.666666c25.6 0 42.666667 17.066667 42.666667 42.666667s-17.066667 42.666667-42.666667 42.666667z" p-id="1476"></path></svg>'
73604
+ }
73605
+ }, {
73606
+ type: "item",
73607
+ text: "序列填充",
73608
+ icon: {
73609
+ width: 16,
73610
+ height: 16,
73611
+ svg: '<svg t="1756136788547" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2463" width="200" height="200"><path d="M312.832482 65.167035H959.204489c35.706211 0 64.64232 29.473622 64.64232 65.832527 0 36.346107-28.936109 65.832527-64.629522 65.832527H312.819684c-35.693413 0-64.629522-29.473622-64.629522-65.832527 0-36.346107 28.936109-65.832527 64.629522-65.832527z m0 394.982363H959.204489c35.706211 0 64.64232 29.460824 64.64232 65.819729 0 36.358905-28.936109 65.832527-64.629522 65.832527H312.819684c-35.693413 0-64.629522-29.473622-64.629522-65.832527 0-36.346107 28.936109-65.819729 64.629522-65.819729z m0 394.969566H959.204489c35.706211 0 64.64232 29.473622 64.64232 65.819729 0 36.358905-28.936109 65.832527-64.629522 65.832527H312.819684c-35.693413 0-64.629522-29.473622-64.629522-65.832527 0-36.346107 28.936109-65.819729 64.629522-65.819729zM12.286008 69.108796V38.176211c9.892796 0.767876 19.836784 0.767876 29.72958 0A41.823619 41.823619 0 0 0 63.989626 25.672638c4.261709-4.671243 7.358807-10.315128 9.048133-16.458132 0.37114-3.058704 0.37114-6.143004 0-9.214506H114.413451v229.748352H65.93491V69.108796H12.286008z m0 510.176487a130.730805 130.730805 0 0 1 45.240665-49.374395 334.537763 334.537763 0 0 0 40.070304-32.250771 48.47854 48.47854 0 0 0 14.218495-33.581756 37.31875 37.31875 0 0 0-7.755543-24.354451 28.193829 28.193829 0 0 0-23.266628-9.879998 27.643518 27.643518 0 0 0-31.02217 15.139945 78.27211 78.27211 0 0 0-5.170362 28.30901H2.585181a114.311067 114.311067 0 0 1 10.340723-48.056208c12.388392-24.124089 38.086625-37.984242 64.629522-34.887144a79.897447 79.897447 0 0 1 57.539472 20.41269 71.783562 71.783562 0 0 1 21.321343 53.981648 74.637499 74.637499 0 0 1-14.858391 46.072531 152.16733 152.16733 0 0 1-32.967455 29.627197L90.481331 553.625443l-23.266628 17.763521c-4.082538 3.583419-7.563574 7.806734-10.353522 12.51637h99.542262v40.147092H0a110.945213 110.945213 0 0 1 10.340724-45.419837l1.945284 0.665492zM44.600769 948.582211a53.495327 53.495327 0 0 0 4.517668 23.036265 30.279891 30.279891 0 0 0 29.742378 17.110826c7.422797 0.255959 14.717614-2.073264 20.681447-6.578133 6.7829-6.962071 10.315128-16.547717 9.688029-26.325332a30.356678 30.356678 0 0 0-18.096266-30.945383 91.735527 91.735527 0 0 0-32.314761-8.561812V883.440772a83.903197 83.903197 0 0 0 30.382274-4.607253 27.106005 27.106005 0 0 0 14.858391-28.30901 30.612637 30.612637 0 0 0-7.755542-21.730877 27.528337 27.528337 0 0 0-21.321344-8.549014 26.939632 26.939632 0 0 0-23.279425 10.532692 44.063256 44.063256 0 0 0-7.102849 27.643519H2.585181a117.101015 117.101015 0 0 1 5.823056-32.916264 74.381541 74.381541 0 0 1 17.443572-25.019944 60.534186 60.534186 0 0 1 20.681447-12.503572 89.55988 89.55988 0 0 1 29.742378-3.289067A78.540867 78.540867 0 0 1 129.259044 801.79001a57.744238 57.744238 0 0 1 20.041551 46.085328 51.921182 51.921182 0 0 1-12.286008 34.887144c-4.159326 5.170362-9.470465 9.227304-15.511086 11.850879 6.7829 1.510155 12.900309 5.208756 17.45637 10.532692a57.821026 57.821026 0 0 1 17.443572 44.10165 75.136618 75.136618 0 0 1-20.028753 52.010768 76.122059 76.122059 0 0 1-59.471958 22.383571 71.962733 71.962733 0 0 1-64.629522-32.250771A97.52019 97.52019 0 0 1 1.279793 946.611331l43.308178 1.97088z" fill="#515151" p-id="2464"></path></svg>'
73612
+ }
73613
+ }],
73614
+ referencePosition: {
73615
+ rect: {
73616
+ right: rect.x2 + 110,
73617
+ bottom: rect.y2
73618
+ }
73619
+ }
73620
+ });
73621
+ }
73622
+ function getCellMatrix(table) {
73623
+ return {
73624
+ getValue: (row, col) => {
73625
+ const value = table.getCellValue(col, row);
73626
+ return "number" != typeof value && isNaN(Number(value)) ? {
73627
+ v: value || "",
73628
+ t: CellValueType.STRING
73629
+ } : {
73630
+ v: value,
73631
+ t: CellValueType.NUMBER
73632
+ };
73633
+ },
73634
+ getMaxRows: () => table.records.length,
73635
+ getMaxColumns: () => table.columns.length
73636
+ };
73637
+ }
73638
+ function isMergeCell(table, col, row) {
73639
+ const cellRange = table.getCellRange(col, row);
73640
+ return cellRange.start.col !== cellRange.end.col || cellRange.start.row !== cellRange.end.row ? cellRange : null;
73641
+ }
73642
+
73643
+ class DefaultFormulaAdapter {
73644
+ constructor(table) {
73645
+ this.table = table;
73646
+ }
73647
+ isFormulaCell(col, row) {
73648
+ const cellValue = this.table.getCellValue(col, row);
73649
+ return "string" == typeof cellValue && cellValue.startsWith("=");
73650
+ }
73651
+ getCellFormula(col, row) {
73652
+ const cellValue = this.table.getCellValue(col, row);
73653
+ if ("string" == typeof cellValue && cellValue.startsWith("=")) return cellValue;
73654
+ }
73655
+ setCellFormula(col, row, formula) {
73656
+ this.table.changeCellValue(col, row, formula);
73657
+ }
73658
+ getCalculatedValue(col, row) {
73659
+ return this.table.getCellValue(col, row);
73660
+ }
73661
+ refreshFormulas() {}
73662
+ hasFormulaEngine() {
73663
+ return !1;
73664
+ }
73665
+ }
73666
+ function createFormulaAdapter(table, customIsFormulaCell, customGetCellFormula, customSetCellFormula) {
73667
+ return customIsFormulaCell || customGetCellFormula || customSetCellFormula ? new CustomFormulaAdapter(table, customIsFormulaCell, customGetCellFormula, customSetCellFormula) : new DefaultFormulaAdapter(table);
73668
+ }
73669
+ class CustomFormulaAdapter {
73670
+ constructor(table, isFormulaCellFn, getCellFormulaFn, setCellFormulaFn) {
73671
+ this.table = table, this.isFormulaCellFn = isFormulaCellFn, this.getCellFormulaFn = getCellFormulaFn, this.setCellFormulaFn = setCellFormulaFn;
73672
+ }
73673
+ isFormulaCell(col, row) {
73674
+ if (this.isFormulaCellFn) {
73675
+ const cellData = this.table.getCellValue(col, row);
73676
+ return this.isFormulaCellFn(col, row, cellData, this.table);
73677
+ }
73678
+ const cellValue = this.table.getCellValue(col, row);
73679
+ return "string" == typeof cellValue && cellValue.startsWith("=");
73680
+ }
73681
+ getCellFormula(col, row) {
73682
+ if (this.getCellFormulaFn) {
73683
+ const cellData = this.table.getCellValue(col, row);
73684
+ return this.getCellFormulaFn(col, row, cellData, this.table);
73685
+ }
73686
+ const cellValue = this.table.getCellValue(col, row);
73687
+ if ("string" == typeof cellValue && cellValue.startsWith("=")) return cellValue;
73688
+ }
73689
+ setCellFormula(col, row, formula) {
73690
+ this.setCellFormulaFn ? this.setCellFormulaFn(col, row, formula, this.table) : this.table.changeCellValue(col, row, formula);
73691
+ }
73692
+ getCalculatedValue(col, row) {
73693
+ return this.table.getCellValue(col, row);
73694
+ }
73695
+ refreshFormulas() {}
73696
+ hasFormulaEngine() {
73697
+ return !1;
73698
+ }
73699
+ }
73700
+
73566
73701
  /**
73567
73702
  * A specialized version of `_.forEach` for arrays without support for
73568
73703
  * iteratee shorthands.
@@ -75130,13 +75265,146 @@
75130
75265
  function reverseIfNeed(data, reverse) {
75131
75266
  return reverse ? data.reverse() : data;
75132
75267
  }
75268
+ const formulaRule = {
75269
+ type: DATA_TYPE.FORMULA,
75270
+ priority: 1200,
75271
+ match: (cellData, accessor) => "string" == typeof (null == cellData ? void 0 : cellData.v) && cellData.v.startsWith("="),
75272
+ isContinue: (prev, cur) => {
75273
+ var _a;
75274
+ return !(prev.type !== DATA_TYPE.FORMULA || !(null === (_a = null == cur ? void 0 : cur.v) || void 0 === _a ? void 0 : _a.startsWith("=")));
75275
+ },
75276
+ applyFunctions: {
75277
+ [APPLY_TYPE.COPY]: (dataWithIndex, len, direction, copyDataPiece, location) => {
75278
+ const {
75279
+ data: data
75280
+ } = dataWithIndex;
75281
+ return fillCopy(data, len);
75282
+ },
75283
+ [APPLY_TYPE.SERIES]: (dataWithIndex, len, direction, copyDataPiece, location) => {
75284
+ const {
75285
+ data: data
75286
+ } = dataWithIndex;
75287
+ if (1 === data.length) return adjustFormulaReferences(data, len, direction);
75288
+ const adjustedFormulas = adjustFormulaReferencesInSeries(data, len);
75289
+ return adjustedFormulas || fillCopy(data, len);
75290
+ }
75291
+ }
75292
+ };
75293
+ function adjustFormulaReferences(formulas, len, direction, location) {
75294
+ var _a, _b;
75295
+ const result = [],
75296
+ baseFormula = (null === (_a = formulas[0]) || void 0 === _a ? void 0 : _a.v) || "";
75297
+ for (let i = 0; i < len; i++) {
75298
+ let newFormula = baseFormula,
75299
+ rowOffset = 0,
75300
+ colOffset = 0;
75301
+ switch (direction) {
75302
+ case Direction.DOWN:
75303
+ rowOffset = i + 1;
75304
+ break;
75305
+ case Direction.UP:
75306
+ rowOffset = -(i + 1);
75307
+ break;
75308
+ case Direction.RIGHT:
75309
+ colOffset = i + 1;
75310
+ break;
75311
+ case Direction.LEFT:
75312
+ colOffset = -(i + 1);
75313
+ }
75314
+ newFormula = adjustCellReferencesInFormula(baseFormula, rowOffset, colOffset), result.push({
75315
+ v: newFormula,
75316
+ t: null === (_b = formulas[0]) || void 0 === _b ? void 0 : _b.t
75317
+ });
75318
+ }
75319
+ return result;
75320
+ }
75321
+ function adjustFormulaReferencesInSeries(formulas, len, direction, location) {
75322
+ var _a, _b, _c;
75323
+ if (formulas.length < 2) return null;
75324
+ const baseFormula1 = (null === (_a = formulas[0]) || void 0 === _a ? void 0 : _a.v) || "",
75325
+ pattern = detectFormulaPattern(baseFormula1, (null === (_b = formulas[1]) || void 0 === _b ? void 0 : _b.v) || "");
75326
+ if (!pattern) return null;
75327
+ const result = [];
75328
+ for (let i = 0; i < len; i++) {
75329
+ let newFormula = baseFormula1;
75330
+ newFormula = applyFormulaPattern(newFormula, pattern, i + 1), result.push({
75331
+ v: newFormula,
75332
+ t: null === (_c = formulas[0]) || void 0 === _c ? void 0 : _c.t
75333
+ });
75334
+ }
75335
+ return result;
75336
+ }
75337
+ function detectFormulaPattern(formula1, formula2) {
75338
+ const cellRefRegex = /\$?([A-Z]+)\$?(\d+)/g,
75339
+ matches1 = [...formula1.matchAll(cellRefRegex)],
75340
+ matches2 = [...formula2.matchAll(cellRefRegex)];
75341
+ if (matches1.length !== matches2.length || 0 === matches1.length) return null;
75342
+ let totalRowOffset = 0,
75343
+ totalColOffset = 0,
75344
+ validMatches = 0;
75345
+ for (let i = 0; i < matches1.length; i++) {
75346
+ const col1 = matches1[i][1],
75347
+ row1 = parseInt(matches1[i][2], 10),
75348
+ col2 = matches2[i][1],
75349
+ row2 = parseInt(matches2[i][2], 10),
75350
+ colOffset = columnToNumber(col2) - columnToNumber(col1),
75351
+ rowOffset = row2 - row1;
75352
+ Math.abs(colOffset) < 100 && Math.abs(rowOffset) < 1e4 && (totalColOffset += colOffset, totalRowOffset += rowOffset, validMatches++);
75353
+ }
75354
+ return 0 === validMatches ? null : {
75355
+ rowOffset: totalRowOffset / validMatches,
75356
+ colOffset: totalColOffset / validMatches
75357
+ };
75358
+ }
75359
+ function applyFormulaPattern(formula, pattern, multiplier, direction) {
75360
+ return formula.replace(/\$?([A-Z]+)\$?(\d+)/g, (match, colStr, rowStr) => {
75361
+ const isColAbsolute = match.startsWith("$") && match.indexOf(colStr) > 0,
75362
+ isRowAbsolute = match.includes("$" + rowStr);
75363
+ let newCol = colStr,
75364
+ newRow = rowStr;
75365
+ if (!isColAbsolute && 0 !== pattern.colOffset) {
75366
+ newCol = numberToColumn(columnToNumber(colStr) + pattern.colOffset * multiplier);
75367
+ }
75368
+ if (!isRowAbsolute && 0 !== pattern.rowOffset) {
75369
+ newRow = (parseInt(rowStr, 10) + pattern.rowOffset * multiplier).toString();
75370
+ }
75371
+ let result = "";
75372
+ return isColAbsolute && (result += "$"), result += newCol, isRowAbsolute && (result += "$"), result += newRow, result;
75373
+ });
75374
+ }
75375
+ function adjustCellReferencesInFormula(formula, rowOffset, colOffset) {
75376
+ return formula.replace(/\$?([A-Z]+)\$?(\d+)/g, (match, colStr, rowStr) => {
75377
+ const isColAbsolute = match.startsWith("$") && match.indexOf(colStr) > 0,
75378
+ isRowAbsolute = match.includes("$" + rowStr);
75379
+ let newCol = colStr,
75380
+ newRow = rowStr;
75381
+ if (!isColAbsolute && 0 !== colOffset) {
75382
+ newCol = numberToColumn(columnToNumber(colStr) + colOffset);
75383
+ }
75384
+ if (!isRowAbsolute && 0 !== rowOffset) {
75385
+ newRow = (parseInt(rowStr, 10) + rowOffset).toString();
75386
+ }
75387
+ let result = "";
75388
+ return isColAbsolute && (result += "$"), result += newCol, isRowAbsolute && (result += "$"), result += newRow, result;
75389
+ });
75390
+ }
75391
+ function columnToNumber(col) {
75392
+ let result = 0;
75393
+ for (let i = 0; i < col.length; i++) result = 26 * result + (col.charCodeAt(i) - "A".charCodeAt(0) + 1);
75394
+ return result;
75395
+ }
75396
+ function numberToColumn(num) {
75397
+ let result = "";
75398
+ for (; num > 0;) num--, result = String.fromCharCode("A".charCodeAt(0) + num % 26) + result, num = Math.floor(num / 26);
75399
+ return result;
75400
+ }
75133
75401
 
75134
75402
  class AutoFillService {
75135
75403
  constructor() {
75136
75404
  this._rules = [], this._init();
75137
75405
  }
75138
75406
  _init() {
75139
- this._rules = [dateRule, numberRule, extendNumberRule, chnNumberRule, chnWeek2Rule, chnWeek3Rule, loopSeriesRule, otherRule].sort((a, b) => b.priority - a.priority);
75407
+ this._rules = [formulaRule, dateRule, numberRule, extendNumberRule, chnNumberRule, chnWeek2Rule, chnWeek3Rule, loopSeriesRule, otherRule].sort((a, b) => b.priority - a.priority);
75140
75408
  }
75141
75409
  registerRule(rule) {
75142
75410
  if (this._rules.find(r => r.type === rule.type)) throw new Error(`Registry rule failed, type '${rule.type}' already exist!`);
@@ -75148,87 +75416,16 @@
75148
75416
  }
75149
75417
  }
75150
75418
 
75151
- function getSelectedRangeArray(selectedRange) {
75152
- const minCol = Math.min(selectedRange.start.col, selectedRange.end.col),
75153
- minRow = Math.min(selectedRange.start.row, selectedRange.end.row),
75154
- maxCol = Math.max(selectedRange.start.col, selectedRange.end.col),
75155
- maxRow = Math.max(selectedRange.start.row, selectedRange.end.row),
75156
- cols = [],
75157
- rows = [];
75158
- for (let i = minCol; i <= maxCol; i++) cols.push(i);
75159
- for (let i = minRow; i <= maxRow; i++) rows.push(i);
75160
- return {
75161
- cols: cols,
75162
- rows: rows
75163
- };
75164
- }
75165
- function getTargetRange(direction, sourceRange, selectedRange) {
75166
- return direction === Direction.DOWN || direction === Direction.UP ? {
75167
- cols: selectedRange.cols,
75168
- rows: selectedRange.rows.filter(row => !sourceRange.rows.includes(row))
75169
- } : {
75170
- cols: selectedRange.cols.filter(col => !sourceRange.cols.includes(col)),
75171
- rows: selectedRange.rows
75172
- };
75173
- }
75174
- function openAutoFillMenu(tableInstance, endCol, endRow) {
75175
- const rect = tableInstance.scenegraph.highPerformanceGetCell(endCol, endRow).globalAABBBounds;
75176
- tableInstance.showDropDownMenu(endCol, endRow, {
75177
- content: [{
75178
- type: "item",
75179
- text: "复制填充",
75180
- icon: {
75181
- width: 16,
75182
- height: 16,
75183
- svg: '<svg t="1756136702877" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1474" width="200" height="200"><path d="M853.333333 981.333333h-384c-72.533333 0-128-55.466667-128-128v-384c0-72.533333 55.466667-128 128-128h384c72.533333 0 128 55.466667 128 128v384c0 72.533333-55.466667 128-128 128z m-384-554.666666c-25.6 0-42.666667 17.066667-42.666666 42.666666v384c0 25.6 17.066667 42.666667 42.666666 42.666667h384c25.6 0 42.666667-17.066667 42.666667-42.666667v-384c0-25.6-17.066667-42.666667-42.666667-42.666666h-384z" p-id="1475"></path><path d="M213.333333 682.666667H170.666667c-72.533333 0-128-55.466667-128-128V170.666667c0-72.533333 55.466667-128 128-128h384c72.533333 0 128 55.466667 128 128v42.666666c0 25.6-17.066667 42.666667-42.666667 42.666667s-42.666667-17.066667-42.666667-42.666667V170.666667c0-25.6-17.066667-42.666667-42.666666-42.666667H170.666667c-25.6 0-42.666667 17.066667-42.666667 42.666667v384c0 25.6 17.066667 42.666667 42.666667 42.666666h42.666666c25.6 0 42.666667 17.066667 42.666667 42.666667s-17.066667 42.666667-42.666667 42.666667z" p-id="1476"></path></svg>'
75184
- }
75185
- }, {
75186
- type: "item",
75187
- text: "序列填充",
75188
- icon: {
75189
- width: 16,
75190
- height: 16,
75191
- svg: '<svg t="1756136788547" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2463" width="200" height="200"><path d="M312.832482 65.167035H959.204489c35.706211 0 64.64232 29.473622 64.64232 65.832527 0 36.346107-28.936109 65.832527-64.629522 65.832527H312.819684c-35.693413 0-64.629522-29.473622-64.629522-65.832527 0-36.346107 28.936109-65.832527 64.629522-65.832527z m0 394.982363H959.204489c35.706211 0 64.64232 29.460824 64.64232 65.819729 0 36.358905-28.936109 65.832527-64.629522 65.832527H312.819684c-35.693413 0-64.629522-29.473622-64.629522-65.832527 0-36.346107 28.936109-65.819729 64.629522-65.819729z m0 394.969566H959.204489c35.706211 0 64.64232 29.473622 64.64232 65.819729 0 36.358905-28.936109 65.832527-64.629522 65.832527H312.819684c-35.693413 0-64.629522-29.473622-64.629522-65.832527 0-36.346107 28.936109-65.819729 64.629522-65.819729zM12.286008 69.108796V38.176211c9.892796 0.767876 19.836784 0.767876 29.72958 0A41.823619 41.823619 0 0 0 63.989626 25.672638c4.261709-4.671243 7.358807-10.315128 9.048133-16.458132 0.37114-3.058704 0.37114-6.143004 0-9.214506H114.413451v229.748352H65.93491V69.108796H12.286008z m0 510.176487a130.730805 130.730805 0 0 1 45.240665-49.374395 334.537763 334.537763 0 0 0 40.070304-32.250771 48.47854 48.47854 0 0 0 14.218495-33.581756 37.31875 37.31875 0 0 0-7.755543-24.354451 28.193829 28.193829 0 0 0-23.266628-9.879998 27.643518 27.643518 0 0 0-31.02217 15.139945 78.27211 78.27211 0 0 0-5.170362 28.30901H2.585181a114.311067 114.311067 0 0 1 10.340723-48.056208c12.388392-24.124089 38.086625-37.984242 64.629522-34.887144a79.897447 79.897447 0 0 1 57.539472 20.41269 71.783562 71.783562 0 0 1 21.321343 53.981648 74.637499 74.637499 0 0 1-14.858391 46.072531 152.16733 152.16733 0 0 1-32.967455 29.627197L90.481331 553.625443l-23.266628 17.763521c-4.082538 3.583419-7.563574 7.806734-10.353522 12.51637h99.542262v40.147092H0a110.945213 110.945213 0 0 1 10.340724-45.419837l1.945284 0.665492zM44.600769 948.582211a53.495327 53.495327 0 0 0 4.517668 23.036265 30.279891 30.279891 0 0 0 29.742378 17.110826c7.422797 0.255959 14.717614-2.073264 20.681447-6.578133 6.7829-6.962071 10.315128-16.547717 9.688029-26.325332a30.356678 30.356678 0 0 0-18.096266-30.945383 91.735527 91.735527 0 0 0-32.314761-8.561812V883.440772a83.903197 83.903197 0 0 0 30.382274-4.607253 27.106005 27.106005 0 0 0 14.858391-28.30901 30.612637 30.612637 0 0 0-7.755542-21.730877 27.528337 27.528337 0 0 0-21.321344-8.549014 26.939632 26.939632 0 0 0-23.279425 10.532692 44.063256 44.063256 0 0 0-7.102849 27.643519H2.585181a117.101015 117.101015 0 0 1 5.823056-32.916264 74.381541 74.381541 0 0 1 17.443572-25.019944 60.534186 60.534186 0 0 1 20.681447-12.503572 89.55988 89.55988 0 0 1 29.742378-3.289067A78.540867 78.540867 0 0 1 129.259044 801.79001a57.744238 57.744238 0 0 1 20.041551 46.085328 51.921182 51.921182 0 0 1-12.286008 34.887144c-4.159326 5.170362-9.470465 9.227304-15.511086 11.850879 6.7829 1.510155 12.900309 5.208756 17.45637 10.532692a57.821026 57.821026 0 0 1 17.443572 44.10165 75.136618 75.136618 0 0 1-20.028753 52.010768 76.122059 76.122059 0 0 1-59.471958 22.383571 71.962733 71.962733 0 0 1-64.629522-32.250771A97.52019 97.52019 0 0 1 1.279793 946.611331l43.308178 1.97088z" fill="#515151" p-id="2464"></path></svg>'
75192
- }
75193
- }],
75194
- referencePosition: {
75195
- rect: {
75196
- right: rect.x2 + 110,
75197
- bottom: rect.y2
75198
- }
75199
- }
75200
- });
75201
- }
75202
- function getCellMatrix(table) {
75203
- return {
75204
- getValue: (row, col) => {
75205
- const value = table.getCellValue(col, row);
75206
- return "number" != typeof value && isNaN(Number(value)) ? {
75207
- v: value || "",
75208
- t: CellValueType.STRING
75209
- } : {
75210
- v: value,
75211
- t: CellValueType.NUMBER
75212
- };
75213
- },
75214
- getMaxRows: () => table.records.length,
75215
- getMaxColumns: () => table.columns.length
75216
- };
75217
- }
75218
- function isMergeCell(table, col, row) {
75219
- const cellRange = table.getCellRange(col, row);
75220
- return cellRange.start.col !== cellRange.end.col || cellRange.start.row !== cellRange.end.row ? cellRange : null;
75221
- }
75222
-
75223
75419
  class AutoFillManager {
75224
75420
  constructor(options) {
75225
- this.sourceData = [], this.options = options, this.autoFillService = new AutoFillService();
75421
+ this.sourceData = [], this.options = options, this.autoFillService = new AutoFillService(), this.formulaAdapter = new DefaultFormulaAdapter({});
75226
75422
  }
75227
75423
  setTable(table) {
75424
+ var _a, _b, _c;
75228
75425
  this.headers = {
75229
75426
  row: new Set(),
75230
75427
  col: new Set()
75231
- }, this.tableInstance = table, table.on(TABLE_EVENT_TYPE.DROPDOWN_MENU_CLICK, args => {
75428
+ }, this.tableInstance = table, this.formulaAdapter = createFormulaAdapter(table, null === (_a = this.options) || void 0 === _a ? void 0 : _a.isFormulaCell, null === (_b = this.options) || void 0 === _b ? void 0 : _b.getCellFormula, null === (_c = this.options) || void 0 === _c ? void 0 : _c.setCellFormula), table.on(TABLE_EVENT_TYPE.DROPDOWN_MENU_CLICK, args => {
75232
75429
  "复制填充" === args.text ? this.fillData(APPLY_TYPE.COPY) : "序列填充" === args.text && this.fillData(APPLY_TYPE.SERIES);
75233
75430
  });
75234
75431
  const rowHeaderCells = this.tableInstance.getAllRowHeaderCells()[0];
@@ -75285,11 +75482,19 @@
75285
75482
  };
75286
75483
  bArray.forEach(b => {
75287
75484
  let data;
75288
- data = isVertical ? matrix.getValue(b, a) : matrix.getValue(a, b);
75289
- const {
75290
- type: type,
75291
- isContinue: isContinue
75292
- } = rules.find(r => r.match(data, null)) || otherRule;
75485
+ const col = isVertical ? a : b,
75486
+ row = isVertical ? b : a;
75487
+ if (data = isVertical ? matrix.getValue(b, a) : matrix.getValue(a, b), data && this.formulaAdapter.isFormulaCell(col, row)) {
75488
+ const formula = this.formulaAdapter.getCellFormula(col, row);
75489
+ formula && (data = Object.assign(Object.assign({}, data), {
75490
+ v: formula
75491
+ }));
75492
+ }
75493
+ const ruleMatch = rules.find(r => r.match(data, null)) || otherRule,
75494
+ {
75495
+ type: type,
75496
+ isContinue: isContinue
75497
+ } = ruleMatch;
75293
75498
  if (isContinue(prevData, data)) {
75294
75499
  const typeInfo = sourceDataPiece[type],
75295
75500
  last = typeInfo[typeInfo.length - 1];
@@ -75393,18 +75598,32 @@
75393
75598
  applyDatas.push(row);
75394
75599
  });
75395
75600
  }
75396
- const values = [];
75601
+ const values = [],
75602
+ formulaUpdates = [];
75397
75603
  targetRows.forEach((row, rowIndex) => {
75398
75604
  const rowValues = [];
75399
75605
  targetCols.forEach((col, colIndex) => {
75400
- var _a;
75401
75606
  const range = isMergeCell(this.tableInstance, col, row);
75402
- range && this.tableInstance.unmergeCells(range.start.col, range.start.row, range.end.col, range.end.row), applyDatas[rowIndex][colIndex] && rowValues.push((null === (_a = applyDatas[rowIndex][colIndex]) || void 0 === _a ? void 0 : _a.v) + "");
75607
+ if (range && this.tableInstance.unmergeCells(range.start.col, range.start.row, range.end.col, range.end.row), applyDatas[rowIndex][colIndex]) {
75608
+ const cellData = applyDatas[rowIndex][colIndex],
75609
+ cellValue = (null == cellData ? void 0 : cellData.v) + "";
75610
+ cellData && "string" == typeof cellData.v && cellData.v.startsWith("=") ? (formulaUpdates.push({
75611
+ col: col,
75612
+ row: row,
75613
+ formula: cellData.v
75614
+ }), rowValues.push(cellValue)) : rowValues.push(cellValue);
75615
+ }
75403
75616
  }), values.push(rowValues);
75404
75617
  });
75405
75618
  const minRow = Math.min(...targetRows),
75406
75619
  minCol = Math.min(...targetCols);
75407
- this.tableInstance.changeCellValues(minCol, minRow, values);
75620
+ this.tableInstance.changeCellValues(minCol, minRow, values), formulaUpdates.length > 0 && (formulaUpdates.forEach(({
75621
+ col: col,
75622
+ row: row,
75623
+ formula: formula
75624
+ }) => {
75625
+ this.formulaAdapter.setCellFormula(col, row, formula);
75626
+ }), this.formulaAdapter.hasFormulaEngine() && this.formulaAdapter.refreshFormulas());
75408
75627
  }
75409
75628
  getApplyData(sourceDataPiece, csLen, asLen, direction, applyType, location) {
75410
75629
  const applyData = [],
@@ -75464,7 +75683,7 @@
75464
75683
  run(...args) {
75465
75684
  var _a, _b;
75466
75685
  if (args[1] === TABLE_EVENT_TYPE.MOUSEDOWN_FILL_HANDLE) {
75467
- const [_, __, table] = args;
75686
+ const [,, table] = args;
75468
75687
  this.table = table, this.autoFillManager.setTable(this.table), this.autoFillManager.handleStartDrag(null === (_a = this.table) || void 0 === _a ? void 0 : _a.getSelectedCellRanges()[0]);
75469
75688
  } else if (args[1] === TABLE_EVENT_TYPE.DRAG_FILL_HANDLE_END) {
75470
75689
  const [{
@@ -76206,10 +76425,10 @@
76206
76425
  const value = formulaInput.value;
76207
76426
  if (value.startsWith('=') && value.length > 1) {
76208
76427
  try {
76209
- const currentCellAddress = activeWorkSheet.addressFromCoord(selection.row, selection.col);
76428
+ const currentCellAddress = activeWorkSheet.addressFromCoord(selection.col, selection.row);
76210
76429
  const cellRegex = new RegExp(`(^|[^A-Za-z0-9])${currentCellAddress}([^A-Za-z0-9]|$)`);
76211
76430
  if (cellRegex.test(value)) {
76212
- activeWorkSheet.setCellValue(selection.row, selection.col, '#CYCLE!');
76431
+ activeWorkSheet.setCellValue(selection.col, selection.row, '#CYCLE!');
76213
76432
  activeWorkSheet.tableInstance?.changeCellValue(selection.col, selection.row, '#CYCLE!');
76214
76433
  formulaInput.value = '';
76215
76434
  formulaInput.blur();
@@ -76225,14 +76444,14 @@
76225
76444
  row: selection.row,
76226
76445
  col: selection.col
76227
76446
  });
76228
- activeWorkSheet.setCellValue(selection.row, selection.col, result.value);
76447
+ activeWorkSheet.setCellValue(selection.col, selection.row, result.value);
76229
76448
  }
76230
76449
  catch (error) {
76231
- activeWorkSheet.setCellValue(selection.row, selection.col, '#ERROR!');
76450
+ activeWorkSheet.setCellValue(selection.col, selection.row, '#ERROR!');
76232
76451
  }
76233
76452
  }
76234
76453
  else {
76235
- activeWorkSheet.setCellValue(selection.row, selection.col, value);
76454
+ activeWorkSheet.setCellValue(selection.col, selection.row, value);
76236
76455
  }
76237
76456
  }
76238
76457
  }
@@ -76262,7 +76481,7 @@
76262
76481
  }
76263
76482
  const cellAddressBox = this.formulaBarElement.querySelector('.vtable-sheet-cell-address');
76264
76483
  if (cellAddressBox) {
76265
- cellAddressBox.textContent = activeWorkSheet.addressFromCoord(selection.startRow, selection.startCol);
76484
+ cellAddressBox.textContent = activeWorkSheet.addressFromCoord(selection.startCol, selection.startRow);
76266
76485
  }
76267
76486
  const formulaInput = this.formulaInput;
76268
76487
  if (formulaInput) {
@@ -76284,7 +76503,7 @@
76284
76503
  formulaInput.value = displayFormula;
76285
76504
  }
76286
76505
  else {
76287
- const cellValue = activeWorkSheet.getCellValue(selection.startRow, selection.startCol);
76506
+ const cellValue = activeWorkSheet.getCellValue(selection.startCol, selection.startRow);
76288
76507
  formulaInput.value = cellValue !== undefined && cellValue !== null ? String(cellValue) : '';
76289
76508
  }
76290
76509
  }
@@ -76354,10 +76573,10 @@
76354
76573
  const value = input.value;
76355
76574
  if (value.startsWith('=') && value.length > 1) {
76356
76575
  try {
76357
- const currentCellAddress = activeWorkSheet.addressFromCoord(editingCell.row, editingCell.col);
76576
+ const currentCellAddress = activeWorkSheet.addressFromCoord(editingCell.col, editingCell.row);
76358
76577
  const cellRegex = new RegExp(`(^|[^A-Za-z0-9])${currentCellAddress}([^A-Za-z0-9]|$)`);
76359
76578
  if (cellRegex.test(value)) {
76360
- activeWorkSheet.setCellValue(editingCell.row, editingCell.col, '#CYCLE!');
76579
+ activeWorkSheet.setCellValue(editingCell.col, editingCell.row, '#CYCLE!');
76361
76580
  activeWorkSheet.tableInstance?.changeCellValue(editingCell.col, editingCell.row, '#CYCLE!');
76362
76581
  this.sheet.formulaManager.formulaWorkingOnCell = null;
76363
76582
  input.value = '';
@@ -76385,13 +76604,13 @@
76385
76604
  }, 0);
76386
76605
  }
76387
76606
  catch (error) {
76388
- activeWorkSheet.setCellValue(editingCell.row, editingCell.col, '#ERROR!');
76607
+ activeWorkSheet.setCellValue(editingCell.col, editingCell.row, '#ERROR!');
76389
76608
  activeWorkSheet.tableInstance?.changeCellValue(editingCell.col, editingCell.row, '#ERROR!');
76390
76609
  this.sheet.formulaManager.formulaWorkingOnCell = null;
76391
76610
  }
76392
76611
  }
76393
76612
  else {
76394
- activeWorkSheet.setCellValue(editingCell.row, editingCell.col, value);
76613
+ activeWorkSheet.setCellValue(editingCell.col, editingCell.row, value);
76395
76614
  activeWorkSheet.tableInstance?.changeCellValue(editingCell.col, editingCell.row, value);
76396
76615
  this.sheet.formulaManager.formulaWorkingOnCell = null;
76397
76616
  }
@@ -76611,6 +76830,246 @@
76611
76830
  }
76612
76831
  }
76613
76832
 
76833
+ class FormulaReferenceAdjustor {
76834
+ static CELL_REF_REGEX = /(\$?[A-Z]+\$?\d+(?::\$?[A-Z]+\$?\d+)?)/gi;
76835
+ static SINGLE_CELL_REGEX = /(\$?)([A-Z]+)(\$?)(\d+)/i;
76836
+ static parseCellReference(ref) {
76837
+ const match = ref.match(this.SINGLE_CELL_REGEX);
76838
+ if (!match) {
76839
+ return null;
76840
+ }
76841
+ const [, colAbsolute, colStr, rowAbsolute, rowStr] = match;
76842
+ const col = this.columnToNumber(colStr);
76843
+ const row = parseInt(rowStr, 10) - 1;
76844
+ let type;
76845
+ if (colAbsolute && rowAbsolute) {
76846
+ type = 'absolute';
76847
+ }
76848
+ else if (colAbsolute && !rowAbsolute) {
76849
+ type = 'mixed_col';
76850
+ }
76851
+ else if (!colAbsolute && rowAbsolute) {
76852
+ type = 'mixed_row';
76853
+ }
76854
+ else {
76855
+ type = 'relative';
76856
+ }
76857
+ return {
76858
+ type,
76859
+ col,
76860
+ row,
76861
+ originalColRef: colAbsolute + colStr,
76862
+ originalRowRef: rowAbsolute + rowStr,
76863
+ fullReference: ref
76864
+ };
76865
+ }
76866
+ static columnToNumber(col) {
76867
+ let result = 0;
76868
+ for (let i = 0; i < col.length; i++) {
76869
+ result = result * 26 + (col.charCodeAt(i) - 'A'.charCodeAt(0) + 1);
76870
+ }
76871
+ return result - 1;
76872
+ }
76873
+ static numberToColumn(num) {
76874
+ let result = '';
76875
+ let n = num + 1;
76876
+ while (n > 0) {
76877
+ n--;
76878
+ result = String.fromCharCode('A'.charCodeAt(0) + (n % 26)) + result;
76879
+ n = Math.floor(n / 26);
76880
+ }
76881
+ return result;
76882
+ }
76883
+ static adjustCellReference(ref, offset) {
76884
+ let newCol = ref.col;
76885
+ let newRow = ref.row;
76886
+ switch (ref.type) {
76887
+ case 'relative':
76888
+ newCol += offset.colOffset;
76889
+ newRow += offset.rowOffset;
76890
+ break;
76891
+ case 'mixed_row':
76892
+ newCol += offset.colOffset;
76893
+ newRow = ref.row;
76894
+ break;
76895
+ case 'mixed_col':
76896
+ newCol = ref.col;
76897
+ newRow += offset.rowOffset;
76898
+ break;
76899
+ case 'absolute':
76900
+ newCol = ref.col;
76901
+ newRow = ref.row;
76902
+ break;
76903
+ }
76904
+ if (newCol < 0) {
76905
+ newCol = 0;
76906
+ }
76907
+ if (newRow < 0) {
76908
+ newRow = 0;
76909
+ }
76910
+ let result = '';
76911
+ if (ref.type === 'absolute' || ref.type === 'mixed_col') {
76912
+ result += '$';
76913
+ }
76914
+ result += this.numberToColumn(newCol);
76915
+ if (ref.type === 'absolute' || ref.type === 'mixed_row') {
76916
+ result += '$';
76917
+ }
76918
+ result += newRow + 1;
76919
+ return result;
76920
+ }
76921
+ static adjustFormulaReferences(formula, colOffset, rowOffset) {
76922
+ const offset = {
76923
+ colOffset: colOffset,
76924
+ rowOffset: rowOffset
76925
+ };
76926
+ return typeof formula === 'string'
76927
+ ? formula.replace(this.CELL_REF_REGEX, match => {
76928
+ if (match.includes(':')) {
76929
+ const parts = match.split(':');
76930
+ const startRef = this.parseCellReference(parts[0]);
76931
+ const endRef = this.parseCellReference(parts[1]);
76932
+ if (startRef && endRef) {
76933
+ const newStart = this.adjustCellReference(startRef, offset);
76934
+ const newEnd = this.adjustCellReference(endRef, offset);
76935
+ return `${newStart}:${newEnd}`;
76936
+ }
76937
+ return match;
76938
+ }
76939
+ const ref = this.parseCellReference(match);
76940
+ if (ref) {
76941
+ return this.adjustCellReference(ref, offset);
76942
+ }
76943
+ return match;
76944
+ })
76945
+ : formula;
76946
+ }
76947
+ static isFormula(value) {
76948
+ return typeof value === 'string' && value.startsWith('=');
76949
+ }
76950
+ static extractReferences(formula) {
76951
+ const references = [];
76952
+ const matches = formula.match(this.CELL_REF_REGEX);
76953
+ if (matches) {
76954
+ matches.forEach(match => {
76955
+ if (match.includes(':')) {
76956
+ const parts = match.split(':');
76957
+ const startRef = this.parseCellReference(parts[0]);
76958
+ const endRef = this.parseCellReference(parts[1]);
76959
+ if (startRef) {
76960
+ references.push(startRef);
76961
+ }
76962
+ if (endRef) {
76963
+ references.push(endRef);
76964
+ }
76965
+ }
76966
+ else {
76967
+ const ref = this.parseCellReference(match);
76968
+ if (ref) {
76969
+ references.push(ref);
76970
+ }
76971
+ }
76972
+ });
76973
+ }
76974
+ return references;
76975
+ }
76976
+ static getFormulaReferenceBounds(formula) {
76977
+ const references = this.extractReferences(formula);
76978
+ if (references.length === 0) {
76979
+ return null;
76980
+ }
76981
+ let minCol = Infinity;
76982
+ let maxCol = -Infinity;
76983
+ let minRow = Infinity;
76984
+ let maxRow = -Infinity;
76985
+ references.forEach(ref => {
76986
+ minCol = Math.min(minCol, ref.col);
76987
+ maxCol = Math.max(maxCol, ref.col);
76988
+ minRow = Math.min(minRow, ref.row);
76989
+ maxRow = Math.max(maxRow, ref.row);
76990
+ });
76991
+ return {
76992
+ minCol,
76993
+ maxCol,
76994
+ minRow,
76995
+ maxRow
76996
+ };
76997
+ }
76998
+ }
76999
+
77000
+ class FormulaPasteProcessor {
77001
+ static adjustFormulaForPaste(formula, context) {
77002
+ if (!FormulaReferenceAdjustor.isFormula(formula)) {
77003
+ return formula;
77004
+ }
77005
+ const colOffset = context.targetCell.col - context.sourceCell.col;
77006
+ const rowOffset = context.targetCell.row - context.sourceCell.row;
77007
+ return FormulaReferenceAdjustor.adjustFormulaReferences(formula, colOffset, rowOffset);
77008
+ }
77009
+ static adjustFormulasForPaste(formulas, context) {
77010
+ const colOffset = context.targetRange.startCol - context.sourceRange.startCol;
77011
+ const rowOffset = context.targetRange.startRow - context.sourceRange.startRow;
77012
+ return this.adjustFormulasForPasteWithOffset(formulas, colOffset, rowOffset);
77013
+ }
77014
+ static adjustFormulasForPasteWithOffset(formulas, colOffset, rowOffset) {
77015
+ const result = [];
77016
+ for (let row = 0; row < formulas.length; row++) {
77017
+ const newRow = [];
77018
+ for (let col = 0; col < formulas[row].length; col++) {
77019
+ const formula = formulas[row][col];
77020
+ if (FormulaReferenceAdjustor.isFormula(formula)) {
77021
+ const adjustedFormula = FormulaReferenceAdjustor.adjustFormulaReferences(formula, colOffset, rowOffset);
77022
+ newRow.push(adjustedFormula);
77023
+ }
77024
+ else {
77025
+ newRow.push(formula);
77026
+ }
77027
+ }
77028
+ result.push(newRow);
77029
+ }
77030
+ return result;
77031
+ }
77032
+ static needsFormulaAdjustment(value) {
77033
+ return FormulaReferenceAdjustor.isFormula(value);
77034
+ }
77035
+ static getFormulaReferences(formula) {
77036
+ return FormulaReferenceAdjustor.extractReferences(formula);
77037
+ }
77038
+ static validateFormulaReferences(formula, maxCol, maxRow) {
77039
+ const references = FormulaReferenceAdjustor.extractReferences(formula);
77040
+ for (const ref of references) {
77041
+ if (ref.col < 0 || ref.col > maxCol || ref.row < 0 || ref.row > maxRow) {
77042
+ return false;
77043
+ }
77044
+ }
77045
+ return true;
77046
+ }
77047
+ static createPasteContext(sourceStartCol, sourceStartRow, targetStartCol, targetStartRow, sourceCols, sourceRows, targetCols, targetRows) {
77048
+ return {
77049
+ sourceRange: {
77050
+ startCol: sourceStartCol,
77051
+ startRow: sourceStartRow,
77052
+ endCol: sourceStartCol + sourceCols - 1,
77053
+ endRow: sourceStartRow + sourceRows - 1
77054
+ },
77055
+ targetRange: {
77056
+ startCol: targetStartCol,
77057
+ startRow: targetStartRow,
77058
+ endCol: targetStartCol + targetCols - 1,
77059
+ endRow: targetStartRow + targetRows - 1
77060
+ },
77061
+ sourceCell: {
77062
+ col: sourceStartCol,
77063
+ row: sourceStartRow
77064
+ },
77065
+ targetCell: {
77066
+ col: targetStartCol,
77067
+ row: targetStartRow
77068
+ }
77069
+ };
77070
+ }
77071
+ }
77072
+
76614
77073
  const DEFAULT_FORMULA_ENGINE_CONFIG = {
76615
77074
  precisionRounding: 14,
76616
77075
  caseSensitive: false,
@@ -77539,6 +77998,10 @@
77539
77998
  const keyboardOptions = {
77540
77999
  ...this.options.keyboardOptions,
77541
78000
  copySelected: true,
78001
+ getCopyCellValue: {
78002
+ html: this.getCellValueConsiderFormula.bind(this)
78003
+ },
78004
+ processFormulaBeforePaste: this.processFormulaPaste.bind(this),
77542
78005
  pasteValueToCell: true,
77543
78006
  showCopyCellBorder: true,
77544
78007
  cutSelected: true
@@ -77848,7 +78311,7 @@
77848
78311
  getCopiedData() {
77849
78312
  return this.getData().map(row => (Array.isArray(row) ? row.slice() : []));
77850
78313
  }
77851
- getCellValue(row, col) {
78314
+ getCellValue(col, row) {
77852
78315
  if (this.tableInstance) {
77853
78316
  try {
77854
78317
  const value = this.tableInstance.getCellValue(col, row);
@@ -77863,7 +78326,28 @@
77863
78326
  }
77864
78327
  return null;
77865
78328
  }
77866
- setCellValue(row, col, value) {
78329
+ getCellValueConsiderFormula(col, row) {
78330
+ if (this.tableInstance) {
78331
+ try {
78332
+ if (this.vtableSheet.formulaManager.isCellFormula({
78333
+ sheet: this.getKey(),
78334
+ row,
78335
+ col
78336
+ })) {
78337
+ return this.vtableSheet.formulaManager.getCellFormula({
78338
+ sheet: this.getKey(),
78339
+ row,
78340
+ col
78341
+ });
78342
+ }
78343
+ return this.getCellValue(col, row);
78344
+ }
78345
+ catch (error) {
78346
+ }
78347
+ return null;
78348
+ }
78349
+ }
78350
+ setCellValue(col, row, value) {
77867
78351
  const data = this.getData();
77868
78352
  if (data && data[row]) {
77869
78353
  const oldValue = data[row][col];
@@ -77884,28 +78368,28 @@
77884
78368
  const coord = this.coordFromAddress(address);
77885
78369
  return {
77886
78370
  coord,
77887
- value: this.getCellValue(coord.row, coord.col)
78371
+ value: this.getCellValue(coord.col, coord.row)
77888
78372
  };
77889
78373
  }
77890
- addressFromCoord(coordOrRow, col) {
77891
- let row;
77892
- let colNum;
77893
- if (typeof coordOrRow === 'object') {
77894
- row = coordOrRow.row;
77895
- colNum = coordOrRow.col;
78374
+ addressFromCoord(coordOrCol, row) {
78375
+ let col;
78376
+ let rowNum;
78377
+ if (typeof coordOrCol === 'object') {
78378
+ col = coordOrCol.col;
78379
+ rowNum = coordOrCol.row;
77896
78380
  }
77897
78381
  else {
77898
- row = coordOrRow;
77899
- colNum = col;
78382
+ col = coordOrCol;
78383
+ rowNum = row;
77900
78384
  }
77901
78385
  let colStr = '';
77902
- let tempCol = colNum + 1;
78386
+ let tempCol = col + 1;
77903
78387
  do {
77904
78388
  tempCol -= 1;
77905
78389
  colStr = String.fromCharCode(65 + (tempCol % 26)) + colStr;
77906
78390
  tempCol = Math.floor(tempCol / 26);
77907
78391
  } while (tempCol > 0);
77908
- return `${colStr}${row + 1}`;
78392
+ return `${colStr}${rowNum + 1}`;
77909
78393
  }
77910
78394
  coordFromAddress(address) {
77911
78395
  const match = address.match(/^([A-Z]+)([0-9]+)$/);
@@ -77965,6 +78449,92 @@
77965
78449
  records: data
77966
78450
  });
77967
78451
  }
78452
+ processFormulaPaste(formulas, sourceStartCol, sourceStartRow, targetStartCol, targetStartRow) {
78453
+ if (!formulas || formulas.length === 0) {
78454
+ return formulas;
78455
+ }
78456
+ const colOffset = targetStartCol - sourceStartCol;
78457
+ const rowOffset = targetStartRow - sourceStartRow;
78458
+ return FormulaPasteProcessor.adjustFormulasForPasteWithOffset(formulas, colOffset, rowOffset);
78459
+ }
78460
+ getCopyData() {
78461
+ const selections = this.getMultipleSelections();
78462
+ if (selections.length === 0) {
78463
+ return [];
78464
+ }
78465
+ const data = this.getData();
78466
+ const result = [];
78467
+ const selection = selections[0];
78468
+ const rows = selection.endRow - selection.startRow + 1;
78469
+ const cols = selection.endCol - selection.startCol + 1;
78470
+ for (let row = 0; row < rows; row++) {
78471
+ const rowData = [];
78472
+ for (let col = 0; col < cols; col++) {
78473
+ const actualRow = selection.startRow + row;
78474
+ const actualCol = selection.startCol + col;
78475
+ if (data[actualRow] && data[actualRow][actualCol] !== undefined) {
78476
+ if (this.vtableSheet.formulaManager.isCellFormula({
78477
+ sheet: this.getKey(),
78478
+ row: actualRow,
78479
+ col: actualCol
78480
+ })) {
78481
+ const formula = this.vtableSheet.formulaManager.getCellFormula({
78482
+ sheet: this.getKey(),
78483
+ row: actualRow,
78484
+ col: actualCol
78485
+ });
78486
+ rowData.push(formula);
78487
+ }
78488
+ else {
78489
+ rowData.push(data[actualRow][actualCol]);
78490
+ }
78491
+ }
78492
+ else {
78493
+ rowData.push('');
78494
+ }
78495
+ }
78496
+ result.push(rowData);
78497
+ }
78498
+ return result;
78499
+ }
78500
+ pasteData(data, targetStartCol, targetStartRow) {
78501
+ if (!data || data.length === 0) {
78502
+ return;
78503
+ }
78504
+ const selections = this.getMultipleSelections();
78505
+ if (selections.length === 0) {
78506
+ return;
78507
+ }
78508
+ const sourceSelection = selections[0];
78509
+ const sourceStartCol = sourceSelection.startCol;
78510
+ const sourceStartRow = sourceSelection.startRow;
78511
+ const processedData = this.processFormulaPaste(data, sourceStartCol, sourceStartRow, targetStartCol, targetStartRow);
78512
+ const dataArray = this.getData();
78513
+ for (let row = 0; row < processedData.length; row++) {
78514
+ for (let col = 0; col < processedData[row].length; col++) {
78515
+ const targetRow = targetStartRow + row;
78516
+ const targetCol = targetStartCol + col;
78517
+ if (targetRow < dataArray.length && targetCol < dataArray[targetRow].length) {
78518
+ const value = processedData[row][col];
78519
+ if (FormulaPasteProcessor.needsFormulaAdjustment(value)) {
78520
+ this.setCellFormula(targetRow, targetCol, value);
78521
+ }
78522
+ else {
78523
+ this.setCellValue(targetRow, targetCol, value);
78524
+ }
78525
+ }
78526
+ }
78527
+ }
78528
+ }
78529
+ setCellFormula(row, col, formula) {
78530
+ if (this.vtableSheet.formulaManager) {
78531
+ this.vtableSheet.formulaManager.setCellContent({
78532
+ sheet: this.getKey(),
78533
+ row,
78534
+ col
78535
+ }, formula);
78536
+ }
78537
+ }
77968
78538
  release() {
77969
78539
  if (this.tableInstance) {
77970
78540
  this.tableInstance.release();
@@ -77976,7 +78546,7 @@
77976
78546
  }
77977
78547
  }
77978
78548
 
77979
- function getTablePlugins(sheetDefine, options) {
78549
+ function getTablePlugins(sheetDefine, options, vtableSheet) {
77980
78550
  const plugins = [];
77981
78551
  const disabledPluginsUserSetted = options?.VTablePluginModules?.filter(module => module.disabled);
77982
78552
  let enabledPluginsUserSetted = options?.VTablePluginModules?.filter(module => !module.disabled);
@@ -78027,7 +78597,12 @@
78027
78597
  enabledPluginsUserSetted = enabledPluginsUserSetted?.filter(module => module.module !== ExcelEditCellKeyboardPlugin);
78028
78598
  }
78029
78599
  if (!disabledPluginsUserSetted?.some(module => module.module === AutoFillPlugin)) {
78030
- const autoFillPlugin = new AutoFillPlugin();
78600
+ const userPluginOptions = enabledPluginsUserSetted?.find(module => module.module === AutoFillPlugin)?.moduleOptions;
78601
+ const formulaDetectionOptions = createFormulaDetectionOptions(sheetDefine, options, vtableSheet);
78602
+ const autoFillPlugin = new AutoFillPlugin({
78603
+ ...userPluginOptions,
78604
+ ...formulaDetectionOptions
78605
+ });
78031
78606
  plugins.push(autoFillPlugin);
78032
78607
  enabledPluginsUserSetted = enabledPluginsUserSetted?.filter(module => module.module !== AutoFillPlugin);
78033
78608
  }
@@ -78203,6 +78778,64 @@
78203
78778
  });
78204
78779
  table.scenegraph.updateNextFrame();
78205
78780
  }
78781
+ function createFormulaDetectionOptions(sheetDefine, options, vtableSheet) {
78782
+ return {
78783
+ isFormulaCell: (col, row, cellData, table) => {
78784
+ if (vtableSheet?.formulaManager) {
78785
+ try {
78786
+ const sheetName = vtableSheet.sheetManager?._activeSheetKey || 'Sheet1';
78787
+ return vtableSheet.formulaManager.isCellFormula({
78788
+ sheet: sheetName,
78789
+ row: row,
78790
+ col: col
78791
+ });
78792
+ }
78793
+ catch (error) {
78794
+ }
78795
+ }
78796
+ if (typeof cellData === 'string' && cellData.startsWith('=')) {
78797
+ return true;
78798
+ }
78799
+ const cellValue = table.getCellValue(col, row);
78800
+ return typeof cellValue === 'string' && cellValue.startsWith('=');
78801
+ },
78802
+ getCellFormula: (col, row, cellData, table) => {
78803
+ if (vtableSheet?.formulaManager) {
78804
+ try {
78805
+ const sheetName = vtableSheet.sheetManager?._activeSheetKey || 'Sheet1';
78806
+ return vtableSheet.formulaManager.getCellFormula({
78807
+ sheet: sheetName,
78808
+ row: row,
78809
+ col: col
78810
+ });
78811
+ }
78812
+ catch (error) {
78813
+ }
78814
+ }
78815
+ const cellValue = table.getCellValue(col, row);
78816
+ if (typeof cellValue === 'string' && cellValue.startsWith('=')) {
78817
+ return cellValue;
78818
+ }
78819
+ return undefined;
78820
+ },
78821
+ setCellFormula: (col, row, formula, table) => {
78822
+ if (vtableSheet?.formulaManager) {
78823
+ try {
78824
+ const sheetName = vtableSheet.sheetManager?._activeSheetKey || 'Sheet1';
78825
+ vtableSheet.formulaManager.setCellContent({
78826
+ sheet: sheetName,
78827
+ row: row,
78828
+ col: col
78829
+ }, formula);
78830
+ return;
78831
+ }
78832
+ catch (error) {
78833
+ }
78834
+ }
78835
+ table.changeCellValue(col, row, formula);
78836
+ }
78837
+ };
78838
+ }
78206
78839
 
78207
78840
  class EventManager {
78208
78841
  sheet;
@@ -79149,7 +79782,7 @@
79149
79782
  defaultRowHeight: this.options.defaultRowHeight,
79150
79783
  defaultColWidth: this.options.defaultColWidth,
79151
79784
  dragOrder: sheetDefine.dragOrder,
79152
- plugins: getTablePlugins(sheetDefine, this.options),
79785
+ plugins: getTablePlugins(sheetDefine, this.options, this),
79153
79786
  headerEditor: 'formula',
79154
79787
  editor: 'formula',
79155
79788
  select: {
@@ -80853,7 +81486,7 @@
80853
81486
  importStyle();
80854
81487
  }
80855
81488
 
80856
- const version = "1.22.6-alpha.2";
81489
+ const version = "1.22.6";
80857
81490
  importStyles();
80858
81491
 
80859
81492
  exports.TYPES = index;