@fileverse-dev/fortune-core 1.1.47 → 1.1.49

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.
@@ -128,12 +128,10 @@ export function setCellValue(ctx, r, c, d, v) {
128
128
  vupdate = v;
129
129
  }
130
130
  var commaPresent = false;
131
- var decimalPresent = false;
132
131
  if (vupdate && typeof vupdate === "string" && vupdate.includes(",")) {
133
132
  commaPresent = vupdate.includes(",");
134
- decimalPresent = vupdate.includes(".");
135
133
  var removeCommasValidated = function removeCommasValidated(str) {
136
- return /^[\d,\.]+$/.test(str) ? str === null || str === void 0 ? void 0 : str.replace(/,/g, "") : str;
134
+ return /^[\d,.]+$/.test(str) ? str === null || str === void 0 ? void 0 : str.replace(/,/g, "") : str;
137
135
  };
138
136
  vupdate = removeCommasValidated(vupdate);
139
137
  }
@@ -503,7 +501,7 @@ export function cancelNormalSelected(ctx) {
503
501
  ctx.formulaCache.rangedrag_row_start = false;
504
502
  }
505
503
  export function updateCell(ctx, r, c, $input, value, canvas) {
506
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
504
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
507
505
  console.log("updateCell", r, c, $input, value);
508
506
  var inputText = $input === null || $input === void 0 ? void 0 : $input.innerText;
509
507
  var inputHtml = $input === null || $input === void 0 ? void 0 : $input.innerHTML;
@@ -673,8 +671,8 @@ export function updateCell(ctx, r, c, $input, value, canvas) {
673
671
  f: v[2]
674
672
  };
675
673
  if (/^[\d.,]+$/.test(value.v)) {
676
- var args = getContentInParentheses(value === null || value === void 0 ? void 0 : value.f).split(",");
677
- var cellRefs = args.map(function (arg) {
674
+ var args = (_k = getContentInParentheses(value === null || value === void 0 ? void 0 : value.f)) === null || _k === void 0 ? void 0 : _k.split(",");
675
+ var cellRefs = args === null || args === void 0 ? void 0 : args.map(function (arg) {
678
676
  return arg.trim().toUpperCase();
679
677
  });
680
678
  var formatted = processArray(cellRefs, d, flowdata);
@@ -725,8 +723,8 @@ export function updateCell(ctx, r, c, $input, value, canvas) {
725
723
  isRunExecFunction = false;
726
724
  }
727
725
  }
728
- var decemialCount = ((_k = oldValue === null || oldValue === void 0 ? void 0 : oldValue.m) === null || _k === void 0 ? void 0 : _k.toString().includes(".")) ? (_m = (_l = oldValue === null || oldValue === void 0 ? void 0 : oldValue.m) === null || _l === void 0 ? void 0 : _l.toString().split(" ")[0].split(".")[1]) === null || _m === void 0 ? void 0 : _m.length : 0;
729
- var coin = (_o = oldValue === null || oldValue === void 0 ? void 0 : oldValue.m) === null || _o === void 0 ? void 0 : _o.toString().split(" ")[1];
726
+ var decemialCount = ((_l = oldValue === null || oldValue === void 0 ? void 0 : oldValue.m) === null || _l === void 0 ? void 0 : _l.toString().includes(".")) ? (_o = (_m = oldValue === null || oldValue === void 0 ? void 0 : oldValue.m) === null || _m === void 0 ? void 0 : _m.toString().split(" ")[0].split(".")[1]) === null || _o === void 0 ? void 0 : _o.length : 0;
727
+ var coin = (_p = oldValue === null || oldValue === void 0 ? void 0 : oldValue.m) === null || _p === void 0 ? void 0 : _p.toString().split(" ")[1];
730
728
  if (_typeof(value) === "object" && value.baseValue && !(value === null || value === void 0 ? void 0 : value.m)) {
731
729
  value.m = "".concat((parseFloat(value === null || value === void 0 ? void 0 : value.v) / (oldValue === null || oldValue === void 0 ? void 0 : oldValue.baseCurrencyPrice)).toFixed(decemialCount || 2), " ").concat(coin);
732
730
  }
@@ -742,7 +740,7 @@ export function updateCell(ctx, r, c, $input, value, canvas) {
742
740
  } else if (_typeof(value) === "object" && !value.tb) {
743
741
  value.tb = "1";
744
742
  }
745
- var isValueArray = Array.isArray((_p = value === null || value === void 0 ? void 0 : value.v) === null || _p === void 0 ? void 0 : _p[0]);
743
+ var isValueArray = Array.isArray((_q = value === null || value === void 0 ? void 0 : value.v) === null || _q === void 0 ? void 0 : _q[0]);
746
744
  try {
747
745
  if (isValueArray) {
748
746
  if (spillSortResult(ctx, r, c, value, d)) {
@@ -766,8 +764,8 @@ export function updateCell(ctx, r, c, $input, value, canvas) {
766
764
  if ((curv === null || curv === void 0 ? void 0 : curv.tb) === "2" && curv.v || isInlineStringCell(d[r][c])) {
767
765
  var defaultrowlen = ctx.defaultrowlen;
768
766
  var cfg = ctx.luckysheetfile[getSheetIndex(ctx, ctx.currentSheetId)].config || {};
769
- if (!(((_q = cfg.columnlen) === null || _q === void 0 ? void 0 : _q[c]) && ((_r = cfg.rowlen) === null || _r === void 0 ? void 0 : _r[r]))) {
770
- var cellWidth = ((_s = cfg.columnlen) === null || _s === void 0 ? void 0 : _s[c]) || ctx.defaultcollen;
767
+ if (!(((_r = cfg.columnlen) === null || _r === void 0 ? void 0 : _r[c]) && ((_s = cfg.rowlen) === null || _s === void 0 ? void 0 : _s[r]))) {
768
+ var cellWidth = ((_t = cfg.columnlen) === null || _t === void 0 ? void 0 : _t[c]) || ctx.defaultcollen;
771
769
  var textInfo = canvas ? getCellTextInfo(d[r][c], canvas, ctx, {
772
770
  r: r,
773
771
  c: c,
@@ -778,7 +776,7 @@ export function updateCell(ctx, r, c, $input, value, canvas) {
778
776
  currentRowLen = textInfo.textHeightAll + 2;
779
777
  }
780
778
  var previousRowHeight = getRowHeight(ctx, [r])[r];
781
- if (currentRowLen > defaultrowlen && !((_t = cfg.customHeight) === null || _t === void 0 ? void 0 : _t[r]) && previousRowHeight < currentRowLen) {
779
+ if (currentRowLen > defaultrowlen && !((_u = cfg.customHeight) === null || _u === void 0 ? void 0 : _u[r]) && previousRowHeight < currentRowLen) {
782
780
  if (_.isNil(cfg.rowlen)) cfg.rowlen = {};
783
781
  cfg.rowlen[r] = currentRowLen;
784
782
  }
@@ -39,6 +39,7 @@ export declare function createFormulaRangeSelect(ctx: Context, select: {
39
39
  rangeIndex: number;
40
40
  } & Rect): void;
41
41
  export declare function createRangeHightlight(ctx: Context, inputInnerHtmlStr: string, ignoreRangeIndex?: number): void;
42
+ export declare function moveCursorToEnd(editableDiv: HTMLDivElement): void;
42
43
  export declare function setCaretPosition(ctx: Context, textDom: HTMLElement, children: number, pos: number): void;
43
44
  export declare function getrangeseleciton(): ParentNode | ChildNode | null | undefined;
44
45
  export declare function rangeHightlightselected(ctx: Context, $editor: HTMLDivElement): void;
@@ -24,7 +24,6 @@ import { getFlowdata } from "../context";
24
24
  import { columnCharToIndex, escapeScriptTag, getSheetIndex, indexToColumnChar, getSheetIdByName, escapeHTMLTag } from "../utils";
25
25
  import { getcellFormula, getRangetxt, mergeMoveMain, setCellValue } from "./cell";
26
26
  import { error } from "./validation";
27
- import { moveToEnd } from "./cursor";
28
27
  import { locale } from "../locale";
29
28
  import { colors } from "./color";
30
29
  import { colLocation, mousePosition, rowLocation } from "./location";
@@ -1217,6 +1216,17 @@ export function createRangeHightlight(ctx, inputInnerHtmlStr, ignoreRangeIndex)
1217
1216
  });
1218
1217
  ctx.formulaRangeHighlight = formulaRanges;
1219
1218
  }
1219
+ export function moveCursorToEnd(editableDiv) {
1220
+ editableDiv.focus();
1221
+ var range = document.createRange();
1222
+ var selection = window.getSelection();
1223
+ range.selectNodeContents(editableDiv);
1224
+ range.collapse(false);
1225
+ if (selection) {
1226
+ selection.removeAllRanges();
1227
+ selection.addRange(range);
1228
+ }
1229
+ }
1220
1230
  export function setCaretPosition(ctx, textDom, children, pos) {
1221
1231
  var _a, _b;
1222
1232
  try {
@@ -1237,7 +1247,7 @@ export function setCaretPosition(ctx, textDom, children, pos) {
1237
1247
  el.focus();
1238
1248
  } catch (err) {
1239
1249
  console.error(err);
1240
- moveToEnd(ctx.formulaCache.rangeResizeTo[0]);
1250
+ moveCursorToEnd(textDom);
1241
1251
  }
1242
1252
  }
1243
1253
  function functionRange(ctx, obj, v, vp) {
package/es/utils/index.js CHANGED
@@ -212,8 +212,16 @@ export function removeLastSpan(htmlString) {
212
212
  }
213
213
  export function getContentInParentheses(str) {
214
214
  if (!str) return null;
215
- var match = str.match(/\(([^)]+)\)/);
216
- return match ? match[1] : null;
215
+ var parenMatch = str.match(/\(([^)]+)\)/);
216
+ if (parenMatch) return parenMatch[1];
217
+ var formulaMatch = str.match(/^=([\w\d:+\-*/]+)$/);
218
+ if (formulaMatch) {
219
+ var refs = formulaMatch[1].split(/[\+\-\*\/]/).map(function (part) {
220
+ return part.trim();
221
+ }).filter(Boolean);
222
+ return refs.join(",");
223
+ }
224
+ return null;
217
225
  }
218
226
  export function processArray(cellReferences, d, flowData) {
219
227
  function isValidCellReference(cell) {
@@ -238,7 +246,7 @@ export function processArray(cellReferences, d, flowData) {
238
246
  row: row
239
247
  };
240
248
  }
241
- var validCellReferences = cellReferences.filter(function (cellRef) {
249
+ var validCellReferences = cellReferences === null || cellReferences === void 0 ? void 0 : cellReferences.filter(function (cellRef) {
242
250
  if (cellRef.includes(":")) {
243
251
  var _a = cellRef.split(":"),
244
252
  startCell = _a[0],
@@ -248,7 +256,7 @@ export function processArray(cellReferences, d, flowData) {
248
256
  return isValidCellReference(cellRef.trim());
249
257
  });
250
258
  var expandedCellReferences = [];
251
- validCellReferences.forEach(function (cellRef) {
259
+ validCellReferences === null || validCellReferences === void 0 ? void 0 : validCellReferences.forEach(function (cellRef) {
252
260
  if (cellRef.includes(":")) {
253
261
  var _a = cellRef.split(":"),
254
262
  startCell = _a[0],
@@ -158,12 +158,10 @@ function setCellValue(ctx, r, c, d, v) {
158
158
  vupdate = v;
159
159
  }
160
160
  var commaPresent = false;
161
- var decimalPresent = false;
162
161
  if (vupdate && typeof vupdate === "string" && vupdate.includes(",")) {
163
162
  commaPresent = vupdate.includes(",");
164
- decimalPresent = vupdate.includes(".");
165
163
  var removeCommasValidated = function removeCommasValidated(str) {
166
- return /^[\d,\.]+$/.test(str) ? str === null || str === void 0 ? void 0 : str.replace(/,/g, "") : str;
164
+ return /^[\d,.]+$/.test(str) ? str === null || str === void 0 ? void 0 : str.replace(/,/g, "") : str;
167
165
  };
168
166
  vupdate = removeCommasValidated(vupdate);
169
167
  }
@@ -533,7 +531,7 @@ function cancelNormalSelected(ctx) {
533
531
  ctx.formulaCache.rangedrag_row_start = false;
534
532
  }
535
533
  function updateCell(ctx, r, c, $input, value, canvas) {
536
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
534
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
537
535
  console.log("updateCell", r, c, $input, value);
538
536
  var inputText = $input === null || $input === void 0 ? void 0 : $input.innerText;
539
537
  var inputHtml = $input === null || $input === void 0 ? void 0 : $input.innerHTML;
@@ -703,8 +701,8 @@ function updateCell(ctx, r, c, $input, value, canvas) {
703
701
  f: v[2]
704
702
  };
705
703
  if (/^[\d.,]+$/.test(value.v)) {
706
- var args = (0, _utils.getContentInParentheses)(value === null || value === void 0 ? void 0 : value.f).split(",");
707
- var cellRefs = args.map(function (arg) {
704
+ var args = (_k = (0, _utils.getContentInParentheses)(value === null || value === void 0 ? void 0 : value.f)) === null || _k === void 0 ? void 0 : _k.split(",");
705
+ var cellRefs = args === null || args === void 0 ? void 0 : args.map(function (arg) {
708
706
  return arg.trim().toUpperCase();
709
707
  });
710
708
  var formatted = (0, _utils.processArray)(cellRefs, d, flowdata);
@@ -755,8 +753,8 @@ function updateCell(ctx, r, c, $input, value, canvas) {
755
753
  isRunExecFunction = false;
756
754
  }
757
755
  }
758
- var decemialCount = ((_k = oldValue === null || oldValue === void 0 ? void 0 : oldValue.m) === null || _k === void 0 ? void 0 : _k.toString().includes(".")) ? (_m = (_l = oldValue === null || oldValue === void 0 ? void 0 : oldValue.m) === null || _l === void 0 ? void 0 : _l.toString().split(" ")[0].split(".")[1]) === null || _m === void 0 ? void 0 : _m.length : 0;
759
- var coin = (_o = oldValue === null || oldValue === void 0 ? void 0 : oldValue.m) === null || _o === void 0 ? void 0 : _o.toString().split(" ")[1];
756
+ var decemialCount = ((_l = oldValue === null || oldValue === void 0 ? void 0 : oldValue.m) === null || _l === void 0 ? void 0 : _l.toString().includes(".")) ? (_o = (_m = oldValue === null || oldValue === void 0 ? void 0 : oldValue.m) === null || _m === void 0 ? void 0 : _m.toString().split(" ")[0].split(".")[1]) === null || _o === void 0 ? void 0 : _o.length : 0;
757
+ var coin = (_p = oldValue === null || oldValue === void 0 ? void 0 : oldValue.m) === null || _p === void 0 ? void 0 : _p.toString().split(" ")[1];
760
758
  if (_typeof(value) === "object" && value.baseValue && !(value === null || value === void 0 ? void 0 : value.m)) {
761
759
  value.m = "".concat((parseFloat(value === null || value === void 0 ? void 0 : value.v) / (oldValue === null || oldValue === void 0 ? void 0 : oldValue.baseCurrencyPrice)).toFixed(decemialCount || 2), " ").concat(coin);
762
760
  }
@@ -772,7 +770,7 @@ function updateCell(ctx, r, c, $input, value, canvas) {
772
770
  } else if (_typeof(value) === "object" && !value.tb) {
773
771
  value.tb = "1";
774
772
  }
775
- var isValueArray = Array.isArray((_p = value === null || value === void 0 ? void 0 : value.v) === null || _p === void 0 ? void 0 : _p[0]);
773
+ var isValueArray = Array.isArray((_q = value === null || value === void 0 ? void 0 : value.v) === null || _q === void 0 ? void 0 : _q[0]);
776
774
  try {
777
775
  if (isValueArray) {
778
776
  if ((0, _sort.spillSortResult)(ctx, r, c, value, d)) {
@@ -796,8 +794,8 @@ function updateCell(ctx, r, c, $input, value, canvas) {
796
794
  if ((curv === null || curv === void 0 ? void 0 : curv.tb) === "2" && curv.v || (0, _inlineString.isInlineStringCell)(d[r][c])) {
797
795
  var defaultrowlen = ctx.defaultrowlen;
798
796
  var cfg = ctx.luckysheetfile[(0, _utils.getSheetIndex)(ctx, ctx.currentSheetId)].config || {};
799
- if (!(((_q = cfg.columnlen) === null || _q === void 0 ? void 0 : _q[c]) && ((_r = cfg.rowlen) === null || _r === void 0 ? void 0 : _r[r]))) {
800
- var cellWidth = ((_s = cfg.columnlen) === null || _s === void 0 ? void 0 : _s[c]) || ctx.defaultcollen;
797
+ if (!(((_r = cfg.columnlen) === null || _r === void 0 ? void 0 : _r[c]) && ((_s = cfg.rowlen) === null || _s === void 0 ? void 0 : _s[r]))) {
798
+ var cellWidth = ((_t = cfg.columnlen) === null || _t === void 0 ? void 0 : _t[c]) || ctx.defaultcollen;
801
799
  var textInfo = canvas ? (0, _text.getCellTextInfo)(d[r][c], canvas, ctx, {
802
800
  r: r,
803
801
  c: c,
@@ -808,7 +806,7 @@ function updateCell(ctx, r, c, $input, value, canvas) {
808
806
  currentRowLen = textInfo.textHeightAll + 2;
809
807
  }
810
808
  var previousRowHeight = (0, _api.getRowHeight)(ctx, [r])[r];
811
- if (currentRowLen > defaultrowlen && !((_t = cfg.customHeight) === null || _t === void 0 ? void 0 : _t[r]) && previousRowHeight < currentRowLen) {
809
+ if (currentRowLen > defaultrowlen && !((_u = cfg.customHeight) === null || _u === void 0 ? void 0 : _u[r]) && previousRowHeight < currentRowLen) {
812
810
  if (_lodash.default.isNil(cfg.rowlen)) cfg.rowlen = {};
813
811
  cfg.rowlen[r] = currentRowLen;
814
812
  }
@@ -39,6 +39,7 @@ export declare function createFormulaRangeSelect(ctx: Context, select: {
39
39
  rangeIndex: number;
40
40
  } & Rect): void;
41
41
  export declare function createRangeHightlight(ctx: Context, inputInnerHtmlStr: string, ignoreRangeIndex?: number): void;
42
+ export declare function moveCursorToEnd(editableDiv: HTMLDivElement): void;
42
43
  export declare function setCaretPosition(ctx: Context, textDom: HTMLElement, children: number, pos: number): void;
43
44
  export declare function getrangeseleciton(): ParentNode | ChildNode | null | undefined;
44
45
  export declare function rangeHightlightselected(ctx: Context, $editor: HTMLDivElement): void;
@@ -20,6 +20,7 @@ exports.handleFormulaInput = handleFormulaInput;
20
20
  exports.insertUpdateFunctionGroup = insertUpdateFunctionGroup;
21
21
  exports.iscelldata = iscelldata;
22
22
  exports.israngeseleciton = israngeseleciton;
23
+ exports.moveCursorToEnd = moveCursorToEnd;
23
24
  exports.onFormulaRangeDragEnd = onFormulaRangeDragEnd;
24
25
  exports.rangeDrag = rangeDrag;
25
26
  exports.rangeDragColumn = rangeDragColumn;
@@ -33,7 +34,6 @@ var _context = require("../context");
33
34
  var _utils = require("../utils");
34
35
  var _cell = require("./cell");
35
36
  var _validation = require("./validation");
36
- var _cursor = require("./cursor");
37
37
  var _locale = require("../locale");
38
38
  var _color = require("./color");
39
39
  var _location = require("./location");
@@ -1246,6 +1246,17 @@ function createRangeHightlight(ctx, inputInnerHtmlStr, ignoreRangeIndex) {
1246
1246
  });
1247
1247
  ctx.formulaRangeHighlight = formulaRanges;
1248
1248
  }
1249
+ function moveCursorToEnd(editableDiv) {
1250
+ editableDiv.focus();
1251
+ var range = document.createRange();
1252
+ var selection = window.getSelection();
1253
+ range.selectNodeContents(editableDiv);
1254
+ range.collapse(false);
1255
+ if (selection) {
1256
+ selection.removeAllRanges();
1257
+ selection.addRange(range);
1258
+ }
1259
+ }
1249
1260
  function setCaretPosition(ctx, textDom, children, pos) {
1250
1261
  var _a, _b;
1251
1262
  try {
@@ -1266,7 +1277,7 @@ function setCaretPosition(ctx, textDom, children, pos) {
1266
1277
  el.focus();
1267
1278
  } catch (err) {
1268
1279
  console.error(err);
1269
- (0, _cursor.moveToEnd)(ctx.formulaCache.rangeResizeTo[0]);
1280
+ moveCursorToEnd(textDom);
1270
1281
  }
1271
1282
  }
1272
1283
  function functionRange(ctx, obj, v, vp) {
@@ -280,8 +280,16 @@ function removeLastSpan(htmlString) {
280
280
  }
281
281
  function getContentInParentheses(str) {
282
282
  if (!str) return null;
283
- var match = str.match(/\(([^)]+)\)/);
284
- return match ? match[1] : null;
283
+ var parenMatch = str.match(/\(([^)]+)\)/);
284
+ if (parenMatch) return parenMatch[1];
285
+ var formulaMatch = str.match(/^=([\w\d:+\-*/]+)$/);
286
+ if (formulaMatch) {
287
+ var refs = formulaMatch[1].split(/[\+\-\*\/]/).map(function (part) {
288
+ return part.trim();
289
+ }).filter(Boolean);
290
+ return refs.join(",");
291
+ }
292
+ return null;
285
293
  }
286
294
  function processArray(cellReferences, d, flowData) {
287
295
  function isValidCellReference(cell) {
@@ -306,7 +314,7 @@ function processArray(cellReferences, d, flowData) {
306
314
  row: row
307
315
  };
308
316
  }
309
- var validCellReferences = cellReferences.filter(function (cellRef) {
317
+ var validCellReferences = cellReferences === null || cellReferences === void 0 ? void 0 : cellReferences.filter(function (cellRef) {
310
318
  if (cellRef.includes(":")) {
311
319
  var _a = cellRef.split(":"),
312
320
  startCell = _a[0],
@@ -316,7 +324,7 @@ function processArray(cellReferences, d, flowData) {
316
324
  return isValidCellReference(cellRef.trim());
317
325
  });
318
326
  var expandedCellReferences = [];
319
- validCellReferences.forEach(function (cellRef) {
327
+ validCellReferences === null || validCellReferences === void 0 ? void 0 : validCellReferences.forEach(function (cellRef) {
320
328
  if (cellRef.includes(":")) {
321
329
  var _a = cellRef.split(":"),
322
330
  startCell = _a[0],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.1.47",
3
+ "version": "1.1.49",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",