@fileverse-dev/fortune-core 1.2.86 → 1.2.87

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/api/sheet.d.ts CHANGED
@@ -8,3 +8,4 @@ export declare function hideSheet(ctx: Context, sheetId: string): void;
8
8
  export declare function showSheet(ctx: Context, sheetId: string): void;
9
9
  export declare function copySheet(ctx: Context, sheetId: string): void;
10
10
  export declare function calculateSheetFromula(ctx: Context, id: string): void;
11
+ export declare function calculateReferencedCellSheetFromula(ctx: Context, id: string, refCell?: string[]): void;
package/es/api/sheet.js CHANGED
@@ -3,6 +3,43 @@ import { v4 as uuidv4 } from "uuid";
3
3
  import { dataToCelldata, getSheet } from "./common";
4
4
  import { getSheetIndex } from "../utils";
5
5
  import { api, execfunction, getFlowdata, insertUpdateFunctionGroup, locale, spillSortResult } from "..";
6
+ function isCellReferenced(formulaString, cell) {
7
+ function colToNumber(col) {
8
+ var num = 0;
9
+ for (var i = 0; i < col.length; i += 1) {
10
+ num = num * 26 + (col.charCodeAt(i) - 64);
11
+ }
12
+ return num;
13
+ }
14
+ function parseCell(cellRef) {
15
+ var match = cellRef.match(/^([A-Z]+)(\d+)$/);
16
+ if (!match) return null;
17
+ return {
18
+ col: colToNumber(match[1]),
19
+ row: Number(match[2])
20
+ };
21
+ }
22
+ var target = parseCell(cell.toUpperCase());
23
+ if (!target) return false;
24
+ var formula = formulaString.toUpperCase();
25
+ var rangeRegex = /([A-Z]+\d+):([A-Z]+\d+)/g;
26
+ var match;
27
+ while ((match = rangeRegex.exec(formula)) !== null) {
28
+ var start = parseCell(match[1]);
29
+ var end = parseCell(match[2]);
30
+ if (target.col >= Math.min(start.col, end.col) && target.col <= Math.max(start.col, end.col) && target.row >= Math.min(start.row, end.row) && target.row <= Math.max(start.row, end.row)) {
31
+ return true;
32
+ }
33
+ }
34
+ var cleanedFormula = formula.replace(rangeRegex, "");
35
+ var cellRegex = /([A-Z]+\d+)/g;
36
+ while ((match = cellRegex.exec(cleanedFormula)) !== null) {
37
+ if (match[1] === cell.toUpperCase()) {
38
+ return true;
39
+ }
40
+ }
41
+ return false;
42
+ }
6
43
  export function getAllSheets(ctx) {
7
44
  return ctx.luckysheetfile;
8
45
  }
@@ -134,4 +171,42 @@ export function calculateSheetFromula(ctx, id) {
134
171
  insertUpdateFunctionGroup(ctx, r, c, id);
135
172
  }
136
173
  }
174
+ }
175
+ export function calculateReferencedCellSheetFromula(ctx, id, refCell) {
176
+ var _a, _b, _c, _d, _e, _f;
177
+ var index = getSheetIndex(ctx, id);
178
+ if (!ctx.luckysheetfile[index].data) return;
179
+ var _loop_1 = function _loop_1(r) {
180
+ var _loop_2 = function _loop_2(c) {
181
+ console.log(refCell, (_a = ctx.luckysheetfile[index].data[r][c]) === null || _a === void 0 ? void 0 : _a.f);
182
+ var isRef = false;
183
+ if (refCell && ((_b = ctx.luckysheetfile[index].data[r][c]) === null || _b === void 0 ? void 0 : _b.f) && !((_c = ctx.luckysheetfile[index].data[r][c]) === null || _c === void 0 ? void 0 : _c.isDataBlockFormula)) {
184
+ isRef = refCell.some(function (cell) {
185
+ var _a;
186
+ return isCellReferenced((_a = ctx.luckysheetfile[index].data[r][c]) === null || _a === void 0 ? void 0 : _a.f, cell);
187
+ });
188
+ }
189
+ if (!isRef || !((_d = ctx.luckysheetfile[index].data[r][c]) === null || _d === void 0 ? void 0 : _d.f) || ((_e = ctx.luckysheetfile[index].data[r][c]) === null || _e === void 0 ? void 0 : _e.isDataBlockFormula)) {
190
+ return "continue";
191
+ }
192
+ var result = execfunction(ctx, (_f = ctx.luckysheetfile[index].data[r][c]) === null || _f === void 0 ? void 0 : _f.f, r, c, id);
193
+ var isValueArray = Array.isArray(result[1]);
194
+ if (isValueArray) {
195
+ var value = {
196
+ f: result[2],
197
+ v: result[1]
198
+ };
199
+ spillSortResult(ctx, r, c, value, getFlowdata(ctx));
200
+ } else {
201
+ api.setCellValue(ctx, r, c, result[1], null);
202
+ }
203
+ insertUpdateFunctionGroup(ctx, r, c, id);
204
+ };
205
+ for (var c = 0; c < ctx.luckysheetfile[index].data[r].length; c += 1) {
206
+ _loop_2(c);
207
+ }
208
+ };
209
+ for (var r = 0; r < ctx.luckysheetfile[index].data.length; r += 1) {
210
+ _loop_1(r);
211
+ }
137
212
  }
@@ -705,7 +705,7 @@ export function execfunction(ctx, txt, r, c, id, calcChainSet, isrefresh, notIns
705
705
  id: id
706
706
  });
707
707
  var originalTxt = txt;
708
- if (txt.toUpperCase().includes("NETWORKDAYS.INTL") || txt.toUpperCase().includes("WORKDAY.INTL")) {
708
+ if ((txt === null || txt === void 0 ? void 0 : txt.toUpperCase().includes("NETWORKDAYS.INTL")) || (txt === null || txt === void 0 ? void 0 : txt.toUpperCase().includes("WORKDAY.INTL"))) {
709
709
  txt = replaceDotsInFunctionName(txt);
710
710
  }
711
711
  if (txt.indexOf(error.r) > -1) {
@@ -8,3 +8,4 @@ export declare function hideSheet(ctx: Context, sheetId: string): void;
8
8
  export declare function showSheet(ctx: Context, sheetId: string): void;
9
9
  export declare function copySheet(ctx: Context, sheetId: string): void;
10
10
  export declare function calculateSheetFromula(ctx: Context, id: string): void;
11
+ export declare function calculateReferencedCellSheetFromula(ctx: Context, id: string, refCell?: string[]): void;
package/lib/api/sheet.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.calculateReferencedCellSheetFromula = calculateReferencedCellSheetFromula;
6
7
  exports.calculateSheetFromula = calculateSheetFromula;
7
8
  exports.copySheet = copySheet;
8
9
  exports.getAllSheets = getAllSheets;
@@ -21,6 +22,43 @@ var _common = require("./common");
21
22
  var _utils = require("../utils");
22
23
  var _2 = require("..");
23
24
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
25
+ function isCellReferenced(formulaString, cell) {
26
+ function colToNumber(col) {
27
+ var num = 0;
28
+ for (var i = 0; i < col.length; i += 1) {
29
+ num = num * 26 + (col.charCodeAt(i) - 64);
30
+ }
31
+ return num;
32
+ }
33
+ function parseCell(cellRef) {
34
+ var match = cellRef.match(/^([A-Z]+)(\d+)$/);
35
+ if (!match) return null;
36
+ return {
37
+ col: colToNumber(match[1]),
38
+ row: Number(match[2])
39
+ };
40
+ }
41
+ var target = parseCell(cell.toUpperCase());
42
+ if (!target) return false;
43
+ var formula = formulaString.toUpperCase();
44
+ var rangeRegex = /([A-Z]+\d+):([A-Z]+\d+)/g;
45
+ var match;
46
+ while ((match = rangeRegex.exec(formula)) !== null) {
47
+ var start = parseCell(match[1]);
48
+ var end = parseCell(match[2]);
49
+ if (target.col >= Math.min(start.col, end.col) && target.col <= Math.max(start.col, end.col) && target.row >= Math.min(start.row, end.row) && target.row <= Math.max(start.row, end.row)) {
50
+ return true;
51
+ }
52
+ }
53
+ var cleanedFormula = formula.replace(rangeRegex, "");
54
+ var cellRegex = /([A-Z]+\d+)/g;
55
+ while ((match = cellRegex.exec(cleanedFormula)) !== null) {
56
+ if (match[1] === cell.toUpperCase()) {
57
+ return true;
58
+ }
59
+ }
60
+ return false;
61
+ }
24
62
  function getAllSheets(ctx) {
25
63
  return ctx.luckysheetfile;
26
64
  }
@@ -151,4 +189,42 @@ function calculateSheetFromula(ctx, id) {
151
189
  (0, _2.insertUpdateFunctionGroup)(ctx, r, c, id);
152
190
  }
153
191
  }
192
+ }
193
+ function calculateReferencedCellSheetFromula(ctx, id, refCell) {
194
+ var _a, _b, _c, _d, _e, _f;
195
+ var index = (0, _utils.getSheetIndex)(ctx, id);
196
+ if (!ctx.luckysheetfile[index].data) return;
197
+ var _loop_1 = function _loop_1(r) {
198
+ var _loop_2 = function _loop_2(c) {
199
+ console.log(refCell, (_a = ctx.luckysheetfile[index].data[r][c]) === null || _a === void 0 ? void 0 : _a.f);
200
+ var isRef = false;
201
+ if (refCell && ((_b = ctx.luckysheetfile[index].data[r][c]) === null || _b === void 0 ? void 0 : _b.f) && !((_c = ctx.luckysheetfile[index].data[r][c]) === null || _c === void 0 ? void 0 : _c.isDataBlockFormula)) {
202
+ isRef = refCell.some(function (cell) {
203
+ var _a;
204
+ return isCellReferenced((_a = ctx.luckysheetfile[index].data[r][c]) === null || _a === void 0 ? void 0 : _a.f, cell);
205
+ });
206
+ }
207
+ if (!isRef || !((_d = ctx.luckysheetfile[index].data[r][c]) === null || _d === void 0 ? void 0 : _d.f) || ((_e = ctx.luckysheetfile[index].data[r][c]) === null || _e === void 0 ? void 0 : _e.isDataBlockFormula)) {
208
+ return "continue";
209
+ }
210
+ var result = (0, _2.execfunction)(ctx, (_f = ctx.luckysheetfile[index].data[r][c]) === null || _f === void 0 ? void 0 : _f.f, r, c, id);
211
+ var isValueArray = Array.isArray(result[1]);
212
+ if (isValueArray) {
213
+ var value = {
214
+ f: result[2],
215
+ v: result[1]
216
+ };
217
+ (0, _2.spillSortResult)(ctx, r, c, value, (0, _2.getFlowdata)(ctx));
218
+ } else {
219
+ _2.api.setCellValue(ctx, r, c, result[1], null);
220
+ }
221
+ (0, _2.insertUpdateFunctionGroup)(ctx, r, c, id);
222
+ };
223
+ for (var c = 0; c < ctx.luckysheetfile[index].data[r].length; c += 1) {
224
+ _loop_2(c);
225
+ }
226
+ };
227
+ for (var r = 0; r < ctx.luckysheetfile[index].data.length; r += 1) {
228
+ _loop_1(r);
229
+ }
154
230
  }
@@ -735,7 +735,7 @@ function execfunction(ctx, txt, r, c, id, calcChainSet, isrefresh, notInsertFunc
735
735
  id: id
736
736
  });
737
737
  var originalTxt = txt;
738
- if (txt.toUpperCase().includes("NETWORKDAYS.INTL") || txt.toUpperCase().includes("WORKDAY.INTL")) {
738
+ if ((txt === null || txt === void 0 ? void 0 : txt.toUpperCase().includes("NETWORKDAYS.INTL")) || (txt === null || txt === void 0 ? void 0 : txt.toUpperCase().includes("WORKDAY.INTL"))) {
739
739
  txt = replaceDotsInFunctionName(txt);
740
740
  }
741
741
  if (txt.indexOf(_validation.error.r) > -1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.2.86",
3
+ "version": "1.2.87",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",