@fileverse-dev/fortune-core 1.2.84 → 1.2.86-maitra-xl

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++) {
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
  }
@@ -126,7 +126,7 @@ export function getCurrentRules(fileC) {
126
126
  return currentRules;
127
127
  }
128
128
  export function setConditionRules(ctx, protection, generalDialog, conditionformat, rules, edit, editKey) {
129
- var _a, _b;
129
+ var _a, _b, _c, _d, _e, _f;
130
130
  if (!checkProtectionFormatCells(ctx)) {
131
131
  return;
132
132
  }
@@ -259,17 +259,17 @@ export function setConditionRules(ctx, protection, generalDialog, conditionforma
259
259
  format: {
260
260
  textColor: textColor,
261
261
  cellColor: cellColor,
262
- bold: rules.font.bold,
263
- italic: rules.font.italic,
264
- underline: rules.font.underline,
265
- strikethrough: rules.font.strikethrough
262
+ bold: (_b = rules === null || rules === void 0 ? void 0 : rules.font) === null || _b === void 0 ? void 0 : _b.bold,
263
+ italic: (_c = rules === null || rules === void 0 ? void 0 : rules.font) === null || _c === void 0 ? void 0 : _c.italic,
264
+ underline: (_d = rules === null || rules === void 0 ? void 0 : rules.font) === null || _d === void 0 ? void 0 : _d.underline,
265
+ strikethrough: (_e = rules === null || rules === void 0 ? void 0 : rules.font) === null || _e === void 0 ? void 0 : _e.strikethrough
266
266
  },
267
267
  conditionName: conditionName,
268
268
  conditionRange: conditionRange,
269
269
  conditionValue: conditionValue
270
270
  };
271
271
  var index = getSheetIndex(ctx, ctx.currentSheetId);
272
- var ruleArr = (_b = ctx.luckysheetfile[index].luckysheet_conditionformat_save) !== null && _b !== void 0 ? _b : [];
272
+ var ruleArr = (_f = ctx.luckysheetfile[index].luckysheet_conditionformat_save) !== null && _f !== void 0 ? _f : [];
273
273
  if (edit) {
274
274
  ruleArr.splice(Number(editKey), 1, rule);
275
275
  } else {
@@ -1007,7 +1007,7 @@ export function compute(ctx, ruleArr, d) {
1007
1007
  return computeMap;
1008
1008
  }
1009
1009
  export function getComputeMap(ctx) {
1010
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1010
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
1011
1011
  var index = getSheetIndex(ctx, ctx.currentSheetId);
1012
1012
  var ruleArr = ((_a = ctx.luckysheetfile[index]) === null || _a === void 0 ? void 0 : _a.luckysheet_conditionformat_save) ? __spreadArray([], (_b = ctx.luckysheetfile[index]) === null || _b === void 0 ? void 0 : _b.luckysheet_conditionformat_save, true) : [];
1013
1013
  var data = ctx.luckysheetfile[index].data;
@@ -1023,14 +1023,14 @@ export function getComputeMap(ctx) {
1023
1023
  format: {
1024
1024
  textColor: (_e = ctx.luckysheetfile[index].conditionRules) === null || _e === void 0 ? void 0 : _e.textColor.color,
1025
1025
  cellColor: (_f = ctx.luckysheetfile[index].conditionRules) === null || _f === void 0 ? void 0 : _f.cellColor.color,
1026
- bold: (_g = ctx.luckysheetfile[index].conditionRules) === null || _g === void 0 ? void 0 : _g.font.bold,
1027
- italic: (_h = ctx.luckysheetfile[index].conditionRules) === null || _h === void 0 ? void 0 : _h.font.italic,
1028
- underline: (_j = ctx.luckysheetfile[index].conditionRules) === null || _j === void 0 ? void 0 : _j.font.underline,
1029
- strikethrough: (_k = ctx.luckysheetfile[index].conditionRules) === null || _k === void 0 ? void 0 : _k.font.strikethrough
1026
+ bold: (_h = (_g = ctx.luckysheetfile[index].conditionRules) === null || _g === void 0 ? void 0 : _g.font) === null || _h === void 0 ? void 0 : _h.bold,
1027
+ italic: (_k = (_j = ctx.luckysheetfile[index].conditionRules) === null || _j === void 0 ? void 0 : _j.font) === null || _k === void 0 ? void 0 : _k.italic,
1028
+ underline: (_m = (_l = ctx.luckysheetfile[index].conditionRules) === null || _l === void 0 ? void 0 : _l.font) === null || _m === void 0 ? void 0 : _m.underline,
1029
+ strikethrough: (_p = (_o = ctx.luckysheetfile[index].conditionRules) === null || _o === void 0 ? void 0 : _o.font) === null || _p === void 0 ? void 0 : _p.strikethrough
1030
1030
  },
1031
- conditionName: (_l = ctx.luckysheetfile[index].conditionRules) === null || _l === void 0 ? void 0 : _l.rulesType,
1031
+ conditionName: (_q = ctx.luckysheetfile[index].conditionRules) === null || _q === void 0 ? void 0 : _q.rulesType,
1032
1032
  conditionRange: [],
1033
- conditionValue: [(_m = ctx.luckysheetfile[index].conditionRules) === null || _m === void 0 ? void 0 : _m.rulesValue]
1033
+ conditionValue: [(_r = ctx.luckysheetfile[index].conditionRules) === null || _r === void 0 ? void 0 : _r.rulesValue]
1034
1034
  });
1035
1035
  }
1036
1036
  var computeMap = compute(ctx, ruleArr, data);
@@ -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++) {
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
  }
@@ -141,7 +141,7 @@ function getCurrentRules(fileC) {
141
141
  return currentRules;
142
142
  }
143
143
  function setConditionRules(ctx, protection, generalDialog, conditionformat, rules, edit, editKey) {
144
- var _a, _b;
144
+ var _a, _b, _c, _d, _e, _f;
145
145
  if (!(0, _protection.checkProtectionFormatCells)(ctx)) {
146
146
  return;
147
147
  }
@@ -274,17 +274,17 @@ function setConditionRules(ctx, protection, generalDialog, conditionformat, rule
274
274
  format: {
275
275
  textColor: textColor,
276
276
  cellColor: cellColor,
277
- bold: rules.font.bold,
278
- italic: rules.font.italic,
279
- underline: rules.font.underline,
280
- strikethrough: rules.font.strikethrough
277
+ bold: (_b = rules === null || rules === void 0 ? void 0 : rules.font) === null || _b === void 0 ? void 0 : _b.bold,
278
+ italic: (_c = rules === null || rules === void 0 ? void 0 : rules.font) === null || _c === void 0 ? void 0 : _c.italic,
279
+ underline: (_d = rules === null || rules === void 0 ? void 0 : rules.font) === null || _d === void 0 ? void 0 : _d.underline,
280
+ strikethrough: (_e = rules === null || rules === void 0 ? void 0 : rules.font) === null || _e === void 0 ? void 0 : _e.strikethrough
281
281
  },
282
282
  conditionName: conditionName,
283
283
  conditionRange: conditionRange,
284
284
  conditionValue: conditionValue
285
285
  };
286
286
  var index = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
287
- var ruleArr = (_b = ctx.luckysheetfile[index].luckysheet_conditionformat_save) !== null && _b !== void 0 ? _b : [];
287
+ var ruleArr = (_f = ctx.luckysheetfile[index].luckysheet_conditionformat_save) !== null && _f !== void 0 ? _f : [];
288
288
  if (edit) {
289
289
  ruleArr.splice(Number(editKey), 1, rule);
290
290
  } else {
@@ -1022,7 +1022,7 @@ function compute(ctx, ruleArr, d) {
1022
1022
  return computeMap;
1023
1023
  }
1024
1024
  function getComputeMap(ctx) {
1025
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1025
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
1026
1026
  var index = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
1027
1027
  var ruleArr = ((_a = ctx.luckysheetfile[index]) === null || _a === void 0 ? void 0 : _a.luckysheet_conditionformat_save) ? __spreadArray([], (_b = ctx.luckysheetfile[index]) === null || _b === void 0 ? void 0 : _b.luckysheet_conditionformat_save, true) : [];
1028
1028
  var data = ctx.luckysheetfile[index].data;
@@ -1038,14 +1038,14 @@ function getComputeMap(ctx) {
1038
1038
  format: {
1039
1039
  textColor: (_e = ctx.luckysheetfile[index].conditionRules) === null || _e === void 0 ? void 0 : _e.textColor.color,
1040
1040
  cellColor: (_f = ctx.luckysheetfile[index].conditionRules) === null || _f === void 0 ? void 0 : _f.cellColor.color,
1041
- bold: (_g = ctx.luckysheetfile[index].conditionRules) === null || _g === void 0 ? void 0 : _g.font.bold,
1042
- italic: (_h = ctx.luckysheetfile[index].conditionRules) === null || _h === void 0 ? void 0 : _h.font.italic,
1043
- underline: (_j = ctx.luckysheetfile[index].conditionRules) === null || _j === void 0 ? void 0 : _j.font.underline,
1044
- strikethrough: (_k = ctx.luckysheetfile[index].conditionRules) === null || _k === void 0 ? void 0 : _k.font.strikethrough
1041
+ bold: (_h = (_g = ctx.luckysheetfile[index].conditionRules) === null || _g === void 0 ? void 0 : _g.font) === null || _h === void 0 ? void 0 : _h.bold,
1042
+ italic: (_k = (_j = ctx.luckysheetfile[index].conditionRules) === null || _j === void 0 ? void 0 : _j.font) === null || _k === void 0 ? void 0 : _k.italic,
1043
+ underline: (_m = (_l = ctx.luckysheetfile[index].conditionRules) === null || _l === void 0 ? void 0 : _l.font) === null || _m === void 0 ? void 0 : _m.underline,
1044
+ strikethrough: (_p = (_o = ctx.luckysheetfile[index].conditionRules) === null || _o === void 0 ? void 0 : _o.font) === null || _p === void 0 ? void 0 : _p.strikethrough
1045
1045
  },
1046
- conditionName: (_l = ctx.luckysheetfile[index].conditionRules) === null || _l === void 0 ? void 0 : _l.rulesType,
1046
+ conditionName: (_q = ctx.luckysheetfile[index].conditionRules) === null || _q === void 0 ? void 0 : _q.rulesType,
1047
1047
  conditionRange: [],
1048
- conditionValue: [(_m = ctx.luckysheetfile[index].conditionRules) === null || _m === void 0 ? void 0 : _m.rulesValue]
1048
+ conditionValue: [(_r = ctx.luckysheetfile[index].conditionRules) === null || _r === void 0 ? void 0 : _r.rulesValue]
1049
1049
  });
1050
1050
  }
1051
1051
  var computeMap = compute(ctx, ruleArr, data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.2.84",
3
+ "version": "1.2.86-maitra-xl",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",