@fileverse-dev/fortune-core 1.2.86 → 1.2.88
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 +1 -0
- package/es/api/sheet.js +75 -0
- package/es/events/keyboard.js +3 -2
- package/es/modules/formula.js +2 -1
- package/lib/api/sheet.d.ts +1 -0
- package/lib/api/sheet.js +76 -0
- package/lib/events/keyboard.js +3 -2
- package/lib/modules/formula.js +2 -1
- package/package.json +1 -1
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
|
}
|
package/es/events/keyboard.js
CHANGED
|
@@ -423,12 +423,12 @@ export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUnd
|
|
|
423
423
|
isFxInput = (_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.contains("fortune-fx-input");
|
|
424
424
|
ignoredKeys = new Set(isFxInput ? ["Enter", "Tab", "ArrowLeft", "ArrowRight"] : ["Enter", "Tab", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
|
|
425
425
|
restCod = !ignoredKeys.has(kstr);
|
|
426
|
-
if (ctx.luckysheetCellUpdate.length > 0 && restCod) {
|
|
426
|
+
if (ctx.luckysheetCellUpdate.length > 0 && restCod && (window.CompositData === "" || window.CompositData === undefined)) {
|
|
427
427
|
return [2];
|
|
428
428
|
}
|
|
429
429
|
if (kstr === "Enter") {
|
|
430
430
|
if (!allowEdit) return [2];
|
|
431
|
-
handleGlobalEnter(ctx, cellInput, e, canvas);
|
|
431
|
+
if (window.CompositData === "" || window.CompositData === undefined) handleGlobalEnter(ctx, cellInput, e, canvas);
|
|
432
432
|
} else if (kstr === "Tab") {
|
|
433
433
|
if (ctx.luckysheetCellUpdate.length > 0) {
|
|
434
434
|
updateCell(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput, undefined, canvas);
|
|
@@ -466,6 +466,7 @@ export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUnd
|
|
|
466
466
|
} else if (kstr === "Escape") {
|
|
467
467
|
ctx.contextMenu = {};
|
|
468
468
|
} else if (kstr === "Delete" || kstr === "Backspace") {
|
|
469
|
+
console.log("Delete");
|
|
469
470
|
if (!allowEdit) return [2];
|
|
470
471
|
if (ctx.activeImg != null) {
|
|
471
472
|
removeActiveImage(ctx);
|
package/es/modules/formula.js
CHANGED
|
@@ -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) {
|
|
@@ -1597,6 +1597,7 @@ export function handleFormulaInput(ctx, $copyTo, $editor, kcode, preText, refres
|
|
|
1597
1597
|
if (refreshRangeSelect === void 0) {
|
|
1598
1598
|
refreshRangeSelect = true;
|
|
1599
1599
|
}
|
|
1600
|
+
if (!$editor) return;
|
|
1600
1601
|
try {
|
|
1601
1602
|
var value1 = void 0;
|
|
1602
1603
|
var value1txt = preText !== null && preText !== void 0 ? preText : $editor.innerText;
|
package/lib/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/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
|
}
|
package/lib/events/keyboard.js
CHANGED
|
@@ -433,12 +433,12 @@ function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUndo, hand
|
|
|
433
433
|
isFxInput = (_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.contains("fortune-fx-input");
|
|
434
434
|
ignoredKeys = new Set(isFxInput ? ["Enter", "Tab", "ArrowLeft", "ArrowRight"] : ["Enter", "Tab", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
|
|
435
435
|
restCod = !ignoredKeys.has(kstr);
|
|
436
|
-
if (ctx.luckysheetCellUpdate.length > 0 && restCod) {
|
|
436
|
+
if (ctx.luckysheetCellUpdate.length > 0 && restCod && (window.CompositData === "" || window.CompositData === undefined)) {
|
|
437
437
|
return [2];
|
|
438
438
|
}
|
|
439
439
|
if (kstr === "Enter") {
|
|
440
440
|
if (!allowEdit) return [2];
|
|
441
|
-
handleGlobalEnter(ctx, cellInput, e, canvas);
|
|
441
|
+
if (window.CompositData === "" || window.CompositData === undefined) handleGlobalEnter(ctx, cellInput, e, canvas);
|
|
442
442
|
} else if (kstr === "Tab") {
|
|
443
443
|
if (ctx.luckysheetCellUpdate.length > 0) {
|
|
444
444
|
(0, _cell.updateCell)(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput, undefined, canvas);
|
|
@@ -476,6 +476,7 @@ function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUndo, hand
|
|
|
476
476
|
} else if (kstr === "Escape") {
|
|
477
477
|
ctx.contextMenu = {};
|
|
478
478
|
} else if (kstr === "Delete" || kstr === "Backspace") {
|
|
479
|
+
console.log("Delete");
|
|
479
480
|
if (!allowEdit) return [2];
|
|
480
481
|
if (ctx.activeImg != null) {
|
|
481
482
|
(0, _2.removeActiveImage)(ctx);
|
package/lib/modules/formula.js
CHANGED
|
@@ -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) {
|
|
@@ -1627,6 +1627,7 @@ function handleFormulaInput(ctx, $copyTo, $editor, kcode, preText, refreshRangeS
|
|
|
1627
1627
|
if (refreshRangeSelect === void 0) {
|
|
1628
1628
|
refreshRangeSelect = true;
|
|
1629
1629
|
}
|
|
1630
|
+
if (!$editor) return;
|
|
1630
1631
|
try {
|
|
1631
1632
|
var value1 = void 0;
|
|
1632
1633
|
var value1txt = preText !== null && preText !== void 0 ? preText : $editor.innerText;
|