@fileverse-dev/fortune-core 1.2.56-patch-2 → 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(/(\$?)([A-Z]+)(\$?)(\d+)/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])) {
@@ -1253,7 +1259,6 @@ export function handlePaste(ctx, e) {
1253
1259
  } else if (txtdata.indexOf("fortune-copy-action-image") > -1) {} else {
1254
1260
  if (txtdata.indexOf("table") > -1) {
1255
1261
  handlePastedTable(ctx, txtdata, pasteHandler);
1256
- resizePastedCellsToContent(ctx);
1257
1262
  } else if (clipboardData.files.length === 1 && clipboardData.files[0].type.indexOf("image") > -1) {} else {
1258
1263
  txtdata = clipboardData.getData("text/plain");
1259
1264
  var isExcelFormula = txtdata.startsWith("=");
@@ -14,7 +14,7 @@ import { locale } from "./locale";
14
14
  import { getQKBorder, saveHyperlink } from "./modules";
15
15
  import { genarate } from "./modules/format";
16
16
  import { getSheetIndex } from "./utils";
17
- import { setRowHeight } from "./api";
17
+ import { setRowHeight, setColumnWidth } from "./api";
18
18
  export var DEFAULT_FONT_SIZE = 12;
19
19
  var parseStylesheetPairs = function parseStylesheetPairs(styleInner) {
20
20
  var patternReg = /{([^}]*)}/g;
@@ -128,7 +128,7 @@ function brToNewline(str) {
128
128
  }
129
129
  var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
130
130
  var _a;
131
- var _b, _c, _d;
131
+ var _b, _c, _d, _e;
132
132
  var cell = {};
133
133
  var rawText = (td.innerText || td.innerHTML || "").trim();
134
134
  var isLineBreak = rawText.includes("<br />");
@@ -157,6 +157,13 @@ var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
157
157
  cell.v = rawText;
158
158
  }
159
159
  }
160
+ if (((_b = td.style) === null || _b === void 0 ? void 0 : _b.alignItems) === "center") {
161
+ cell.vt = 0;
162
+ } else if (((_c = td.style) === null || _c === void 0 ? void 0 : _c.alignItems) === "flex-end") {
163
+ cell.vt = 2;
164
+ } else if (((_d = td.style) === null || _d === void 0 ? void 0 : _d.alignItems) === "flex-start") {
165
+ cell.vt = 1;
166
+ }
160
167
  var styleBlock = typeof classStyles[".".concat(td.className)] === "string" ? classStyles[".".concat(td.className)] : "";
161
168
  var styles = parseInlineStyleBlock(styleBlock);
162
169
  if (!_.isNil(styles.border)) td.style.border = styles.border;
@@ -181,17 +188,7 @@ var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
181
188
  } else {
182
189
  cell.ht = 1;
183
190
  }
184
- var regex = /vertical-align:\s*(.*?);/;
185
- var vtStyle = typeof classStyles.td === "string" && ((_c = (_b = classStyles.td.match(regex)) === null || _b === void 0 ? void 0 : _b[1]) !== null && _c !== void 0 ? _c : "") || "top";
186
- var vt = td.style.verticalAlign || styles["vertical-align"] || vtStyle;
187
- if (vt === "middle") {
188
- cell.vt = 0;
189
- } else if (vt === "top" || vt === "text-top") {
190
- cell.vt = 1;
191
- } else {
192
- cell.vt = 2;
193
- }
194
- if (((_d = td === null || td === void 0 ? void 0 : td.style) === null || _d === void 0 ? void 0 : _d["overflow-wrap"]) === "anywhere") {
191
+ if (((_e = td === null || td === void 0 ? void 0 : td.style) === null || _e === void 0 ? void 0 : _e["overflow-wrap"]) === "anywhere") {
195
192
  cell.tb = "2";
196
193
  } else {
197
194
  cell.tb = "2";
@@ -213,6 +210,15 @@ export function handlePastedTable(ctx, html, pasteHandler) {
213
210
  if (!html.includes("table")) return;
214
211
  var containerDiv = document.createElement("div");
215
212
  containerDiv.innerHTML = html;
213
+ var tableColGropup = containerDiv.querySelectorAll("colgroup");
214
+ tableColGropup.forEach(function (colGroup, index) {
215
+ var _a;
216
+ var colWidth = colGroup === null || colGroup === void 0 ? void 0 : colGroup.getAttribute("width");
217
+ var intColWidth = parseInt(colWidth || "0", 10);
218
+ var anchorCol = ctx.luckysheet_select_save[0].column[0];
219
+ var absoluteCol = anchorCol + index;
220
+ setColumnWidth(ctx, (_a = {}, _a[absoluteCol] = intColWidth, _a));
221
+ });
216
222
  var tableRows = containerDiv.querySelectorAll("table tr");
217
223
  if (tableRows.length === 0) {
218
224
  containerDiv.remove();
@@ -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(/(\$?)([A-Z]+)(\$?)(\d+)/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])) {
@@ -1266,7 +1272,6 @@ function handlePaste(ctx, e) {
1266
1272
  } else if (txtdata.indexOf("fortune-copy-action-image") > -1) {} else {
1267
1273
  if (txtdata.indexOf("table") > -1) {
1268
1274
  (0, _pasteTableHelpers.handlePastedTable)(ctx, txtdata, pasteHandler);
1269
- resizePastedCellsToContent(ctx);
1270
1275
  } else if (clipboardData.files.length === 1 && clipboardData.files[0].type.indexOf("image") > -1) {} else {
1271
1276
  txtdata = clipboardData.getData("text/plain");
1272
1277
  var isExcelFormula = txtdata.startsWith("=");
@@ -136,7 +136,7 @@ function brToNewline(str) {
136
136
  }
137
137
  var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
138
138
  var _a;
139
- var _b, _c, _d;
139
+ var _b, _c, _d, _e;
140
140
  var cell = {};
141
141
  var rawText = (td.innerText || td.innerHTML || "").trim();
142
142
  var isLineBreak = rawText.includes("<br />");
@@ -165,6 +165,13 @@ var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
165
165
  cell.v = rawText;
166
166
  }
167
167
  }
168
+ if (((_b = td.style) === null || _b === void 0 ? void 0 : _b.alignItems) === "center") {
169
+ cell.vt = 0;
170
+ } else if (((_c = td.style) === null || _c === void 0 ? void 0 : _c.alignItems) === "flex-end") {
171
+ cell.vt = 2;
172
+ } else if (((_d = td.style) === null || _d === void 0 ? void 0 : _d.alignItems) === "flex-start") {
173
+ cell.vt = 1;
174
+ }
168
175
  var styleBlock = typeof classStyles[".".concat(td.className)] === "string" ? classStyles[".".concat(td.className)] : "";
169
176
  var styles = parseInlineStyleBlock(styleBlock);
170
177
  if (!_lodash.default.isNil(styles.border)) td.style.border = styles.border;
@@ -189,17 +196,7 @@ var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
189
196
  } else {
190
197
  cell.ht = 1;
191
198
  }
192
- var regex = /vertical-align:\s*(.*?);/;
193
- var vtStyle = typeof classStyles.td === "string" && ((_c = (_b = classStyles.td.match(regex)) === null || _b === void 0 ? void 0 : _b[1]) !== null && _c !== void 0 ? _c : "") || "top";
194
- var vt = td.style.verticalAlign || styles["vertical-align"] || vtStyle;
195
- if (vt === "middle") {
196
- cell.vt = 0;
197
- } else if (vt === "top" || vt === "text-top") {
198
- cell.vt = 1;
199
- } else {
200
- cell.vt = 2;
201
- }
202
- if (((_d = td === null || td === void 0 ? void 0 : td.style) === null || _d === void 0 ? void 0 : _d["overflow-wrap"]) === "anywhere") {
199
+ if (((_e = td === null || td === void 0 ? void 0 : td.style) === null || _e === void 0 ? void 0 : _e["overflow-wrap"]) === "anywhere") {
203
200
  cell.tb = "2";
204
201
  } else {
205
202
  cell.tb = "2";
@@ -221,6 +218,15 @@ function handlePastedTable(ctx, html, pasteHandler) {
221
218
  if (!html.includes("table")) return;
222
219
  var containerDiv = document.createElement("div");
223
220
  containerDiv.innerHTML = html;
221
+ var tableColGropup = containerDiv.querySelectorAll("colgroup");
222
+ tableColGropup.forEach(function (colGroup, index) {
223
+ var _a;
224
+ var colWidth = colGroup === null || colGroup === void 0 ? void 0 : colGroup.getAttribute("width");
225
+ var intColWidth = parseInt(colWidth || "0", 10);
226
+ var anchorCol = ctx.luckysheet_select_save[0].column[0];
227
+ var absoluteCol = anchorCol + index;
228
+ (0, _api.setColumnWidth)(ctx, (_a = {}, _a[absoluteCol] = intColWidth, _a));
229
+ });
224
230
  var tableRows = containerDiv.querySelectorAll("table tr");
225
231
  if (tableRows.length === 0) {
226
232
  containerDiv.remove();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.2.56-patch-2",
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",