@fileverse-dev/fortune-core 1.2.56-patch-3 → 1.2.56-patch-4

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.
@@ -77,19 +77,24 @@ export function adjustFormulaForPaste(formula, srcCol, srcRow, destCol, destRow)
77
77
  var colOffset = destCol - srcCol;
78
78
  var rowOffset = destRow - srcRow;
79
79
  var hadInvalid = false;
80
- var result = formula.replace(/\b(\$?)([A-Z]+)(\$?)(\d+)\b/g, function (__, absCol, colLetters, absRow, rowNum) {
81
- var colIndex = columnLabelIndex(colLetters);
82
- var rowIndex = parseInt(rowNum, 10);
83
- if (!absCol) colIndex += colOffset;
84
- if (!absRow) rowIndex += rowOffset;
85
- if (colIndex < 0 || rowIndex <= 0) {
86
- hadInvalid = true;
87
- var invalidCol = colIndex < 0 ? "".concat(absCol ? "$" : "").concat(colLetters).concat(colIndex) : "".concat(absCol ? "$" : "").concat(indexToColumnLabel(colIndex));
88
- var invalidRow = rowIndex.toString();
89
- return "".concat(invalidCol).concat(invalidRow);
90
- }
91
- var newCol = indexToColumnLabel(colIndex);
92
- return "".concat(absCol ? "$" : "").concat(newCol).concat(absRow ? "$" : "").concat(rowIndex);
80
+ var cellRefRegex = /\b(\$?)([A-Z]+)(\$?)(\d+)\b/g;
81
+ var stringOrCellRef = /"(?:\\.|[^"])*"|(\b\$?[A-Z]+\$?\d+\b)/g;
82
+ var result = formula.replace(stringOrCellRef, function (m, cellRef) {
83
+ if (!cellRef) return m;
84
+ return cellRef.replace(cellRefRegex, function (__, absCol, colLetters, absRow, rowNum) {
85
+ var colIndex = columnLabelIndex(colLetters);
86
+ var rowIndex = parseInt(rowNum, 10);
87
+ if (!absCol) colIndex += colOffset;
88
+ if (!absRow) rowIndex += rowOffset;
89
+ if (colIndex < 0 || rowIndex <= 0) {
90
+ hadInvalid = true;
91
+ var invalidCol = colIndex < 0 ? "".concat(absCol ? "$" : "").concat(colLetters).concat(colIndex) : "".concat(absCol ? "$" : "").concat(indexToColumnLabel(colIndex));
92
+ var invalidRow = rowIndex.toString();
93
+ return "".concat(invalidCol).concat(invalidRow);
94
+ }
95
+ var newCol = indexToColumnLabel(colIndex);
96
+ return "".concat(absCol ? "$" : "").concat(newCol).concat(absRow ? "$" : "").concat(rowIndex);
97
+ });
93
98
  });
94
99
  if (hadInvalid) {
95
100
  var brokenFormula = "=".concat(result.replace(/^=/, ""));
@@ -980,6 +985,7 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
980
985
  }
981
986
  if (!isError) {
982
987
  var funcV = execfunction(ctx, adjustedFormula, h, c, undefined, undefined, true);
988
+ console.log(funcV, adjustedFormula);
983
989
  value.f = adjustedFormula;
984
990
  if (!(funcV[1] instanceof Promise) && !funcV[3]) {
985
991
  if (Array.isArray(funcV[1])) {
@@ -90,19 +90,24 @@ function adjustFormulaForPaste(formula, srcCol, srcRow, destCol, destRow) {
90
90
  var colOffset = destCol - srcCol;
91
91
  var rowOffset = destRow - srcRow;
92
92
  var hadInvalid = false;
93
- var result = formula.replace(/\b(\$?)([A-Z]+)(\$?)(\d+)\b/g, function (__, absCol, colLetters, absRow, rowNum) {
94
- var colIndex = columnLabelIndex(colLetters);
95
- var rowIndex = parseInt(rowNum, 10);
96
- if (!absCol) colIndex += colOffset;
97
- if (!absRow) rowIndex += rowOffset;
98
- if (colIndex < 0 || rowIndex <= 0) {
99
- hadInvalid = true;
100
- var invalidCol = colIndex < 0 ? "".concat(absCol ? "$" : "").concat(colLetters).concat(colIndex) : "".concat(absCol ? "$" : "").concat(indexToColumnLabel(colIndex));
101
- var invalidRow = rowIndex.toString();
102
- return "".concat(invalidCol).concat(invalidRow);
103
- }
104
- var newCol = indexToColumnLabel(colIndex);
105
- return "".concat(absCol ? "$" : "").concat(newCol).concat(absRow ? "$" : "").concat(rowIndex);
93
+ var cellRefRegex = /\b(\$?)([A-Z]+)(\$?)(\d+)\b/g;
94
+ var stringOrCellRef = /"(?:\\.|[^"])*"|(\b\$?[A-Z]+\$?\d+\b)/g;
95
+ var result = formula.replace(stringOrCellRef, function (m, cellRef) {
96
+ if (!cellRef) return m;
97
+ return cellRef.replace(cellRefRegex, function (__, absCol, colLetters, absRow, rowNum) {
98
+ var colIndex = columnLabelIndex(colLetters);
99
+ var rowIndex = parseInt(rowNum, 10);
100
+ if (!absCol) colIndex += colOffset;
101
+ if (!absRow) rowIndex += rowOffset;
102
+ if (colIndex < 0 || rowIndex <= 0) {
103
+ hadInvalid = true;
104
+ var invalidCol = colIndex < 0 ? "".concat(absCol ? "$" : "").concat(colLetters).concat(colIndex) : "".concat(absCol ? "$" : "").concat(indexToColumnLabel(colIndex));
105
+ var invalidRow = rowIndex.toString();
106
+ return "".concat(invalidCol).concat(invalidRow);
107
+ }
108
+ var newCol = indexToColumnLabel(colIndex);
109
+ return "".concat(absCol ? "$" : "").concat(newCol).concat(absRow ? "$" : "").concat(rowIndex);
110
+ });
106
111
  });
107
112
  if (hadInvalid) {
108
113
  var brokenFormula = "=".concat(result.replace(/^=/, ""));
@@ -993,6 +998,7 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
993
998
  }
994
999
  if (!isError) {
995
1000
  var funcV = (0, _formula.execfunction)(ctx, adjustedFormula, h, c, undefined, undefined, true);
1001
+ console.log(funcV, adjustedFormula);
996
1002
  value.f = adjustedFormula;
997
1003
  if (!(funcV[1] instanceof Promise) && !funcV[3]) {
998
1004
  if (Array.isArray(funcV[1])) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.2.56-patch-3",
3
+ "version": "1.2.56-patch-4",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",