@fileverse-dev/fortune-core 1.1.66-error-2 → 1.1.66-error-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.
package/es/canvas.js CHANGED
@@ -1122,29 +1122,29 @@ var Canvas = function () {
1122
1122
  endY: cellsize[3] + cellsize[1]
1123
1123
  }, renderCtx);
1124
1124
  if (cell === null || cell === void 0 ? void 0 : cell.error) {
1125
- var errorColor = "#FB3449";
1126
- var bw = 1;
1127
- var L = Math.round(startX + offsetLeft - 1 + bodrder05);
1128
- var T = Math.round(startY + offsetTop - 1 + bodrder05);
1129
- var R = Math.round(endX + offsetLeft - 2 + bodrder05);
1130
- var B = Math.round(endY + offsetTop - 2 + bodrder05);
1131
- var wInside = R - L;
1132
- var hInside = B - T;
1133
- var ctx2 = renderCtx;
1134
- ctx2.save();
1135
- ctx2.fillStyle = errorColor;
1136
- ctx2.fillRect(L, T, wInside, bw);
1137
- ctx2.fillRect(L, B - bw, wInside, bw);
1138
- ctx2.fillRect(L, T, bw, hInside);
1139
- ctx2.fillRect(R - bw, T, bw, hInside);
1140
- var ribbon = 8 * this.sheetCtx.zoomRatio;
1141
- ctx2.beginPath();
1142
- ctx2.moveTo(L + bw, T + bw);
1143
- ctx2.lineTo(L + bw + ribbon, T + bw);
1144
- ctx2.lineTo(L + bw, T + bw + ribbon);
1145
- ctx2.closePath();
1146
- ctx2.fill();
1147
- ctx2.restore();
1125
+ var errorBorderColor = "#FB3449";
1126
+ var borderThicknessInPixels = 1;
1127
+ var leftCellBoundary = Math.round(startX + offsetLeft - 3 + bodrder05);
1128
+ var topCellBoundary = Math.round(startY + offsetTop - 3 + bodrder05);
1129
+ var rightCellBoundary = Math.round(endX + offsetLeft - 3 + bodrder05);
1130
+ var bottomCellBoundary = Math.round(endY + offsetTop - 3 + bodrder05);
1131
+ var innerCellWidth = rightCellBoundary - leftCellBoundary;
1132
+ var innerCellHeight = bottomCellBoundary - topCellBoundary;
1133
+ var renderingContext = renderCtx;
1134
+ renderingContext.save();
1135
+ renderingContext.fillStyle = errorBorderColor;
1136
+ renderingContext.fillRect(leftCellBoundary, topCellBoundary, innerCellWidth, borderThicknessInPixels);
1137
+ renderingContext.fillRect(leftCellBoundary, bottomCellBoundary - borderThicknessInPixels, innerCellWidth, borderThicknessInPixels);
1138
+ renderingContext.fillRect(leftCellBoundary, topCellBoundary, borderThicknessInPixels, innerCellHeight);
1139
+ renderingContext.fillRect(rightCellBoundary - borderThicknessInPixels, topCellBoundary, borderThicknessInPixels, innerCellHeight);
1140
+ var errorRibbonSize = 8 * this.sheetCtx.zoomRatio;
1141
+ renderingContext.beginPath();
1142
+ renderingContext.moveTo(leftCellBoundary + borderThicknessInPixels, topCellBoundary + borderThicknessInPixels);
1143
+ renderingContext.lineTo(leftCellBoundary + borderThicknessInPixels + errorRibbonSize, topCellBoundary + borderThicknessInPixels);
1144
+ renderingContext.lineTo(leftCellBoundary + borderThicknessInPixels, topCellBoundary + borderThicknessInPixels + errorRibbonSize);
1145
+ renderingContext.closePath();
1146
+ renderingContext.fill();
1147
+ renderingContext.restore();
1148
1148
  }
1149
1149
  };
1150
1150
  Canvas.prototype.cellOverflowRender = function (r, c, stc, edc, renderCtx, scrollHeight, scrollWidth, offsetLeft, offsetTop, afCompute, cfCompute) {
@@ -3,7 +3,3 @@ import { CellError } from "../types";
3
3
  export declare function overShowError(ctx: Context, e: MouseEvent, scrollX: HTMLDivElement, scrollY: HTMLDivElement, container: HTMLDivElement): void;
4
4
  export declare function setCellError(ctx: Context, r: number, c: number, err: CellError): void;
5
5
  export declare function clearCellError(ctx: Context, r: number, c: number): void;
6
- export declare function showErrors(ctx: Context, errorShowCells: {
7
- r: number;
8
- c: number;
9
- }[]): void;
@@ -10,7 +10,6 @@ var __assign = this && this.__assign || function () {
10
10
  };
11
11
  import _ from "lodash";
12
12
  import { getFlowdata } from "../context";
13
- import { getCommentBoxByRC } from "./comment";
14
13
  import { colLocation, rowLocation } from "./location";
15
14
  import { mergeBorder } from "./cell";
16
15
  export function overShowError(ctx, e, scrollX, scrollY, container) {
@@ -80,14 +79,4 @@ export function clearCellError(ctx, r, c) {
80
79
  var flow = getFlowdata(ctx);
81
80
  if (!((_a = flow === null || flow === void 0 ? void 0 : flow[r]) === null || _a === void 0 ? void 0 : _a[c])) return;
82
81
  delete flow[r][c].error;
83
- }
84
- export function showErrors(ctx, errorShowCells) {
85
- var flowdata = getFlowdata(ctx);
86
- if (!flowdata) return;
87
- var errorBoxes = errorShowCells.map(function (_a) {
88
- var r = _a.r,
89
- c = _a.c;
90
- return getCommentBoxByRC(ctx, flowdata, r, c);
91
- });
92
- ctx.errorBoxes = errorBoxes;
93
82
  }
@@ -18,12 +18,12 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
18
18
  }
19
19
  return to.concat(ar || Array.prototype.slice.call(from));
20
20
  };
21
- import _ from "lodash";
22
21
  import { Parser, ERROR_REF } from "@fileverse-dev/formula-parser";
22
+ import _ from "lodash";
23
23
  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
- import { error } from "./validation";
26
+ import { customErrorMessage, error, detectErrorFromValue } from "./validation";
27
27
  import { locale } from "../locale";
28
28
  import { colors } from "./color";
29
29
  import { colLocation, mousePosition, rowLocation } from "./location";
@@ -730,16 +730,17 @@ export function execfunction(ctx, txt, r, c, id, calcChainSet, isrefresh, notIns
730
730
  finalResult = "".concat(resultStr, " ").concat(ctx.formulaCache.parser.cryptoDenomination);
731
731
  }
732
732
  var isError = !_.isNil(formulaError);
733
- if (isError) {
733
+ var detectedErrorFromValue = detectErrorFromValue(finalResult === null || finalResult === void 0 ? void 0 : finalResult.toString());
734
+ if (isError || detectedErrorFromValue) {
734
735
  setCellError(ctx, r, c, {
735
736
  row_column: "".concat(r, "_").concat(c),
736
737
  title: "Error",
737
- message: (formulaError === null || formulaError === void 0 ? void 0 : formulaError.toString()) || "Unknown Error"
738
+ message: (formulaError === null || formulaError === void 0 ? void 0 : formulaError.toString()) || detectedErrorFromValue || "Unknown Error"
738
739
  });
739
740
  } else {
740
741
  clearCellError(ctx, r, c);
741
742
  }
742
- return [true, !isError ? finalResult : formulaError, txt];
743
+ return [true, !isError ? finalResult : customErrorMessage(formulaError), txt];
743
744
  }
744
745
  function insertUpdateDynamicArray(ctx, dynamicArrayItem) {
745
746
  var r = dynamicArrayItem.r,
@@ -9,6 +9,9 @@ export declare const error: {
9
9
  nl: string;
10
10
  sp: string;
11
11
  };
12
+ export declare const errorMessagesFromValue: Record<string, string>;
13
+ export declare function detectErrorFromValue(input: string): string;
14
+ export declare function customErrorMessage(errorMessage: string): string;
12
15
  export declare function valueIsError(value: string): boolean;
13
16
  export declare function isRealNull(val: any): boolean;
14
17
  export declare function isHexValue(str: string): boolean;
@@ -1,5 +1,7 @@
1
+ var _a;
1
2
  import dayjs from "dayjs";
2
3
  import _ from "lodash";
4
+ import { error as cellErrorMessages, ERROR_NAME, ERROR_DIV_ZERO, ERROR_NULL, ERROR_NUM, ERROR_REF, ERROR_VALUE, ERROR } from "@fileverse-dev/formula-parser";
3
5
  import { hasChinaword } from "./text";
4
6
  export var error = {
5
7
  v: "#VALUE!",
@@ -11,6 +13,16 @@ export var error = {
11
13
  nl: "#NULL!",
12
14
  sp: "#SPILL!"
13
15
  };
16
+ export var errorMessagesFromValue = (_a = {}, _a[ERROR_DIV_ZERO] = "Invalid calculation: the divisor (second value) cannot be zero", _a[ERROR_NAME] = "Wrong function name or parameter", _a[ERROR_NULL] = "Formula returned null", _a[ERROR_NUM] = "Invalid number", _a[ERROR_REF] = "Invalid reference", _a[ERROR_VALUE] = "Invalid value", _a[ERROR] = "Unknown error", _a);
17
+ export function detectErrorFromValue(input) {
18
+ return errorMessagesFromValue[input];
19
+ }
20
+ export function customErrorMessage(errorMessage) {
21
+ if (errorMessage === cellErrorMessages(ERROR_NAME)) {
22
+ return "#ERROR";
23
+ }
24
+ return errorMessage;
25
+ }
14
26
  var errorValues = Object.values(error);
15
27
  export function valueIsError(value) {
16
28
  return errorValues.includes(value);
package/lib/canvas.js CHANGED
@@ -1129,29 +1129,29 @@ var Canvas = exports.Canvas = function () {
1129
1129
  endY: cellsize[3] + cellsize[1]
1130
1130
  }, renderCtx);
1131
1131
  if (cell === null || cell === void 0 ? void 0 : cell.error) {
1132
- var errorColor = "#FB3449";
1133
- var bw = 1;
1134
- var L = Math.round(startX + offsetLeft - 1 + bodrder05);
1135
- var T = Math.round(startY + offsetTop - 1 + bodrder05);
1136
- var R = Math.round(endX + offsetLeft - 2 + bodrder05);
1137
- var B = Math.round(endY + offsetTop - 2 + bodrder05);
1138
- var wInside = R - L;
1139
- var hInside = B - T;
1140
- var ctx2 = renderCtx;
1141
- ctx2.save();
1142
- ctx2.fillStyle = errorColor;
1143
- ctx2.fillRect(L, T, wInside, bw);
1144
- ctx2.fillRect(L, B - bw, wInside, bw);
1145
- ctx2.fillRect(L, T, bw, hInside);
1146
- ctx2.fillRect(R - bw, T, bw, hInside);
1147
- var ribbon = 8 * this.sheetCtx.zoomRatio;
1148
- ctx2.beginPath();
1149
- ctx2.moveTo(L + bw, T + bw);
1150
- ctx2.lineTo(L + bw + ribbon, T + bw);
1151
- ctx2.lineTo(L + bw, T + bw + ribbon);
1152
- ctx2.closePath();
1153
- ctx2.fill();
1154
- ctx2.restore();
1132
+ var errorBorderColor = "#FB3449";
1133
+ var borderThicknessInPixels = 1;
1134
+ var leftCellBoundary = Math.round(startX + offsetLeft - 3 + bodrder05);
1135
+ var topCellBoundary = Math.round(startY + offsetTop - 3 + bodrder05);
1136
+ var rightCellBoundary = Math.round(endX + offsetLeft - 3 + bodrder05);
1137
+ var bottomCellBoundary = Math.round(endY + offsetTop - 3 + bodrder05);
1138
+ var innerCellWidth = rightCellBoundary - leftCellBoundary;
1139
+ var innerCellHeight = bottomCellBoundary - topCellBoundary;
1140
+ var renderingContext = renderCtx;
1141
+ renderingContext.save();
1142
+ renderingContext.fillStyle = errorBorderColor;
1143
+ renderingContext.fillRect(leftCellBoundary, topCellBoundary, innerCellWidth, borderThicknessInPixels);
1144
+ renderingContext.fillRect(leftCellBoundary, bottomCellBoundary - borderThicknessInPixels, innerCellWidth, borderThicknessInPixels);
1145
+ renderingContext.fillRect(leftCellBoundary, topCellBoundary, borderThicknessInPixels, innerCellHeight);
1146
+ renderingContext.fillRect(rightCellBoundary - borderThicknessInPixels, topCellBoundary, borderThicknessInPixels, innerCellHeight);
1147
+ var errorRibbonSize = 8 * this.sheetCtx.zoomRatio;
1148
+ renderingContext.beginPath();
1149
+ renderingContext.moveTo(leftCellBoundary + borderThicknessInPixels, topCellBoundary + borderThicknessInPixels);
1150
+ renderingContext.lineTo(leftCellBoundary + borderThicknessInPixels + errorRibbonSize, topCellBoundary + borderThicknessInPixels);
1151
+ renderingContext.lineTo(leftCellBoundary + borderThicknessInPixels, topCellBoundary + borderThicknessInPixels + errorRibbonSize);
1152
+ renderingContext.closePath();
1153
+ renderingContext.fill();
1154
+ renderingContext.restore();
1155
1155
  }
1156
1156
  };
1157
1157
  Canvas.prototype.cellOverflowRender = function (r, c, stc, edc, renderCtx, scrollHeight, scrollWidth, offsetLeft, offsetTop, afCompute, cfCompute) {
@@ -3,7 +3,3 @@ import { CellError } from "../types";
3
3
  export declare function overShowError(ctx: Context, e: MouseEvent, scrollX: HTMLDivElement, scrollY: HTMLDivElement, container: HTMLDivElement): void;
4
4
  export declare function setCellError(ctx: Context, r: number, c: number, err: CellError): void;
5
5
  export declare function clearCellError(ctx: Context, r: number, c: number): void;
6
- export declare function showErrors(ctx: Context, errorShowCells: {
7
- r: number;
8
- c: number;
9
- }[]): void;
@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.clearCellError = clearCellError;
7
7
  exports.overShowError = overShowError;
8
8
  exports.setCellError = setCellError;
9
- exports.showErrors = showErrors;
10
9
  var _lodash = _interopRequireDefault(require("lodash"));
11
10
  var _context = require("../context");
12
- var _comment = require("./comment");
13
11
  var _location = require("./location");
14
12
  var _cell = require("./cell");
15
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -90,14 +88,4 @@ function clearCellError(ctx, r, c) {
90
88
  var flow = (0, _context.getFlowdata)(ctx);
91
89
  if (!((_a = flow === null || flow === void 0 ? void 0 : flow[r]) === null || _a === void 0 ? void 0 : _a[c])) return;
92
90
  delete flow[r][c].error;
93
- }
94
- function showErrors(ctx, errorShowCells) {
95
- var flowdata = (0, _context.getFlowdata)(ctx);
96
- if (!flowdata) return;
97
- var errorBoxes = errorShowCells.map(function (_a) {
98
- var r = _a.r,
99
- c = _a.c;
100
- return (0, _comment.getCommentBoxByRC)(ctx, flowdata, r, c);
101
- });
102
- ctx.errorBoxes = errorBoxes;
103
91
  }
@@ -28,8 +28,8 @@ exports.rangeDragRow = rangeDragRow;
28
28
  exports.rangeHightlightselected = rangeHightlightselected;
29
29
  exports.rangeSetValue = rangeSetValue;
30
30
  exports.setCaretPosition = setCaretPosition;
31
- var _lodash = _interopRequireDefault(require("lodash"));
32
31
  var _formulaParser = require("@fileverse-dev/formula-parser");
32
+ var _lodash = _interopRequireDefault(require("lodash"));
33
33
  var _context = require("../context");
34
34
  var _utils = require("../utils");
35
35
  var _cell = require("./cell");
@@ -760,16 +760,17 @@ function execfunction(ctx, txt, r, c, id, calcChainSet, isrefresh, notInsertFunc
760
760
  finalResult = "".concat(resultStr, " ").concat(ctx.formulaCache.parser.cryptoDenomination);
761
761
  }
762
762
  var isError = !_lodash.default.isNil(formulaError);
763
- if (isError) {
763
+ var detectedErrorFromValue = (0, _validation.detectErrorFromValue)(finalResult === null || finalResult === void 0 ? void 0 : finalResult.toString());
764
+ if (isError || detectedErrorFromValue) {
764
765
  (0, _2.setCellError)(ctx, r, c, {
765
766
  row_column: "".concat(r, "_").concat(c),
766
767
  title: "Error",
767
- message: (formulaError === null || formulaError === void 0 ? void 0 : formulaError.toString()) || "Unknown Error"
768
+ message: (formulaError === null || formulaError === void 0 ? void 0 : formulaError.toString()) || detectedErrorFromValue || "Unknown Error"
768
769
  });
769
770
  } else {
770
771
  (0, _2.clearCellError)(ctx, r, c);
771
772
  }
772
- return [true, !isError ? finalResult : formulaError, txt];
773
+ return [true, !isError ? finalResult : (0, _validation.customErrorMessage)(formulaError), txt];
773
774
  }
774
775
  function insertUpdateDynamicArray(ctx, dynamicArrayItem) {
775
776
  var r = dynamicArrayItem.r,
@@ -9,6 +9,9 @@ export declare const error: {
9
9
  nl: string;
10
10
  sp: string;
11
11
  };
12
+ export declare const errorMessagesFromValue: Record<string, string>;
13
+ export declare function detectErrorFromValue(input: string): string;
14
+ export declare function customErrorMessage(errorMessage: string): string;
12
15
  export declare function valueIsError(value: string): boolean;
13
16
  export declare function isRealNull(val: any): boolean;
14
17
  export declare function isHexValue(str: string): boolean;
@@ -3,8 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.customErrorMessage = customErrorMessage;
7
+ exports.detectErrorFromValue = detectErrorFromValue;
6
8
  exports.diff = diff;
7
- exports.error = void 0;
9
+ exports.errorMessagesFromValue = exports.error = void 0;
8
10
  exports.hasPartMC = hasPartMC;
9
11
  exports.isHexValue = isHexValue;
10
12
  exports.isRealNull = isRealNull;
@@ -15,8 +17,10 @@ exports.isdatetime = isdatetime;
15
17
  exports.valueIsError = valueIsError;
16
18
  var _dayjs = _interopRequireDefault(require("dayjs"));
17
19
  var _lodash = _interopRequireDefault(require("lodash"));
20
+ var _formulaParser = require("@fileverse-dev/formula-parser");
18
21
  var _text = require("./text");
19
22
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
23
+ var _a;
20
24
  var error = exports.error = {
21
25
  v: "#VALUE!",
22
26
  n: "#NAME?",
@@ -27,6 +31,16 @@ var error = exports.error = {
27
31
  nl: "#NULL!",
28
32
  sp: "#SPILL!"
29
33
  };
34
+ var errorMessagesFromValue = exports.errorMessagesFromValue = (_a = {}, _a[_formulaParser.ERROR_DIV_ZERO] = "Invalid calculation: the divisor (second value) cannot be zero", _a[_formulaParser.ERROR_NAME] = "Wrong function name or parameter", _a[_formulaParser.ERROR_NULL] = "Formula returned null", _a[_formulaParser.ERROR_NUM] = "Invalid number", _a[_formulaParser.ERROR_REF] = "Invalid reference", _a[_formulaParser.ERROR_VALUE] = "Invalid value", _a[_formulaParser.ERROR] = "Unknown error", _a);
35
+ function detectErrorFromValue(input) {
36
+ return errorMessagesFromValue[input];
37
+ }
38
+ function customErrorMessage(errorMessage) {
39
+ if (errorMessage === (0, _formulaParser.error)(_formulaParser.ERROR_NAME)) {
40
+ return "#ERROR";
41
+ }
42
+ return errorMessage;
43
+ }
30
44
  var errorValues = Object.values(error);
31
45
  function valueIsError(value) {
32
46
  return errorValues.includes(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.1.66-error-2",
3
+ "version": "1.1.66-error-4",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",