@leankylin-sheet/core 4.0.59 → 4.0.61
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/dist/api/sheet.d.ts +5 -0
- package/dist/index.esm.js +97 -9
- package/dist/index.js +97 -9
- package/package.json +2 -2
package/dist/api/sheet.d.ts
CHANGED
|
@@ -9,3 +9,8 @@ export declare function hideSheet(ctx: Context, sheetId: string): void;
|
|
|
9
9
|
export declare function showSheet(ctx: Context, sheetId: string): void;
|
|
10
10
|
export declare function copySheet(ctx: Context, sheetId: string, hooks: Hooks): void;
|
|
11
11
|
export declare function calculateSheetFromula(ctx: Context, id: string): void;
|
|
12
|
+
export declare function calculateSheetByCells(ctx: Context, cells: {
|
|
13
|
+
r: number;
|
|
14
|
+
c: number;
|
|
15
|
+
id: string;
|
|
16
|
+
}[]): void;
|
package/dist/index.esm.js
CHANGED
|
@@ -46539,6 +46539,7 @@ function copySheet(ctx, sheetId, hooks) {
|
|
|
46539
46539
|
(_hooks$onCopySheet = hooks.onCopySheet) === null || _hooks$onCopySheet === void 0 ? void 0 : _hooks$onCopySheet.call(hooks, sheetId, copyId);
|
|
46540
46540
|
}
|
|
46541
46541
|
function calculateSheetFromula(ctx, id) {
|
|
46542
|
+
console.time("calcTime:".concat(id));
|
|
46542
46543
|
var index$1 = getSheetIndex(ctx, id);
|
|
46543
46544
|
var luckysheetfile = ctx.luckysheetfile;
|
|
46544
46545
|
var file = luckysheetfile[index$1];
|
|
@@ -46549,29 +46550,115 @@ function calculateSheetFromula(ctx, id) {
|
|
|
46549
46550
|
if (!ctx.luckysheetfile[index$1].data) return;
|
|
46550
46551
|
for (var r = 0; r < ctx.luckysheetfile[index$1].data.length; r += 1) {
|
|
46551
46552
|
for (var c = 0; c < ctx.luckysheetfile[index$1].data[r].length; c += 1) {
|
|
46552
|
-
var
|
|
46553
|
-
if (!(
|
|
46553
|
+
var cell = ctx.luckysheetfile[index$1].data[r][c];
|
|
46554
|
+
if (!(cell === null || cell === void 0 ? void 0 : cell.f)) {
|
|
46554
46555
|
continue;
|
|
46555
46556
|
}
|
|
46556
|
-
var result = execfunction(ctx, (_ctx$luckysheetfile$i2 = ctx.luckysheetfile[index$1].data[r][c]) === null || _ctx$luckysheetfile$i2 === void 0 ? void 0 : _ctx$luckysheetfile$i2.f, r, c, id, undefined, true);
|
|
46557
|
-
setCellValue$1(ctx, r, c, result[1], null, {
|
|
46558
|
-
id: id
|
|
46559
|
-
});
|
|
46560
|
-
if (_.isNil(id)) {
|
|
46561
|
-
id = ctx.currentSheetId;
|
|
46562
|
-
}
|
|
46563
46557
|
var cc = {
|
|
46564
46558
|
r: r,
|
|
46565
46559
|
c: c,
|
|
46566
46560
|
id: id
|
|
46567
46561
|
};
|
|
46568
46562
|
calcChain.push(cc);
|
|
46563
|
+
var result = execfunction(ctx, cell === null || cell === void 0 ? void 0 : cell.f, r, c, id, undefined, true);
|
|
46564
|
+
var newV = result[1];
|
|
46565
|
+
if (newV === cell.v) {
|
|
46566
|
+
continue;
|
|
46567
|
+
}
|
|
46568
|
+
setCellValue$1(ctx, r, c, result[1], null, {
|
|
46569
|
+
id: id
|
|
46570
|
+
});
|
|
46569
46571
|
}
|
|
46570
46572
|
}
|
|
46571
46573
|
file.calcChain = uniqBy(calcChain, function (item) {
|
|
46572
46574
|
return item.r + item.c + item.id;
|
|
46573
46575
|
});
|
|
46574
46576
|
ctx.luckysheetfile = luckysheetfile;
|
|
46577
|
+
console.timeEnd("calcTime:".concat(id));
|
|
46578
|
+
}
|
|
46579
|
+
function parseCellReferences(expression) {
|
|
46580
|
+
if (typeof expression !== "string" || expression.trim() === "") {
|
|
46581
|
+
return [];
|
|
46582
|
+
}
|
|
46583
|
+
var cellRegex = /([A-Za-z0-9_]+!)?[A-Za-z]+\d+/g;
|
|
46584
|
+
var matches = expression.match(cellRegex) || [];
|
|
46585
|
+
var uniqueCells = matches.map(function (cell) {
|
|
46586
|
+
return cell.trim().toUpperCase();
|
|
46587
|
+
});
|
|
46588
|
+
return uniqueCells;
|
|
46589
|
+
}
|
|
46590
|
+
function calculateSheetByCells(ctx, cells) {
|
|
46591
|
+
console.time("calculateSheetByCellsTime");
|
|
46592
|
+
var fileList = ctx.luckysheetfile;
|
|
46593
|
+
var sheetIdNameMap = {};
|
|
46594
|
+
for (var ffIndex = 0; ffIndex < fileList.length; ffIndex++) {
|
|
46595
|
+
var _f$name;
|
|
46596
|
+
var f = fileList[ffIndex];
|
|
46597
|
+
sheetIdNameMap[f.id] = (_f$name = f.name) === null || _f$name === void 0 ? void 0 : _f$name.toLocaleUpperCase();
|
|
46598
|
+
}
|
|
46599
|
+
var needUpdateCell = [];
|
|
46600
|
+
var updatedMap = {};
|
|
46601
|
+
for (var index$1 = 0; index$1 < cells.length; index$1++) {
|
|
46602
|
+
var _cells$index = cells[index$1],
|
|
46603
|
+
r = _cells$index.r,
|
|
46604
|
+
c = _cells$index.c,
|
|
46605
|
+
id = _cells$index.id;
|
|
46606
|
+
updatedMap["".concat(sheetIdNameMap[id], "!").concat(indexToColumnChar(c) + (r + 1))] = true;
|
|
46607
|
+
}
|
|
46608
|
+
var _loop = function _loop() {
|
|
46609
|
+
var file = fileList[fIndex];
|
|
46610
|
+
var sheetId = file.id;
|
|
46611
|
+
var _file$calcChain = file.calcChain,
|
|
46612
|
+
calcChain = _file$calcChain === void 0 ? [] : _file$calcChain;
|
|
46613
|
+
for (var _index = 0; _index < calcChain.length; _index++) {
|
|
46614
|
+
var _parseCellReferences;
|
|
46615
|
+
var _calcChain$_index = calcChain[_index],
|
|
46616
|
+
_r2 = _calcChain$_index.r,
|
|
46617
|
+
_c2 = _calcChain$_index.c;
|
|
46618
|
+
var cell = file.data[_r2][_c2];
|
|
46619
|
+
if (!(cell === null || cell === void 0 ? void 0 : cell.f)) {
|
|
46620
|
+
continue;
|
|
46621
|
+
}
|
|
46622
|
+
var devCell = (_parseCellReferences = parseCellReferences(cell.f)) === null || _parseCellReferences === void 0 ? void 0 : _parseCellReferences.map(function (item) {
|
|
46623
|
+
return item.includes("!") ? item : "".concat(sheetIdNameMap[sheetId], "!").concat(item);
|
|
46624
|
+
});
|
|
46625
|
+
var n = devCell === null || devCell === void 0 ? void 0 : devCell.some(function (item) {
|
|
46626
|
+
return updatedMap["".concat(item)];
|
|
46627
|
+
});
|
|
46628
|
+
if (n) {
|
|
46629
|
+
needUpdateCell.push({
|
|
46630
|
+
r: _r2,
|
|
46631
|
+
c: _c2,
|
|
46632
|
+
id: sheetId,
|
|
46633
|
+
f: cell.f,
|
|
46634
|
+
v: cell.v
|
|
46635
|
+
});
|
|
46636
|
+
}
|
|
46637
|
+
}
|
|
46638
|
+
};
|
|
46639
|
+
for (var fIndex = 0; fIndex < fileList.length; fIndex++) {
|
|
46640
|
+
_loop();
|
|
46641
|
+
}
|
|
46642
|
+
needUpdateCell = uniqBy(needUpdateCell, function (item) {
|
|
46643
|
+
return "".concat(item.r, "_").concat(item.c, "_").concat(item.id);
|
|
46644
|
+
});
|
|
46645
|
+
for (var nIndex = 0; nIndex < needUpdateCell.length; nIndex++) {
|
|
46646
|
+
var _needUpdateCell$nInde = needUpdateCell[nIndex],
|
|
46647
|
+
_r = _needUpdateCell$nInde.r,
|
|
46648
|
+
_c = _needUpdateCell$nInde.c,
|
|
46649
|
+
_id = _needUpdateCell$nInde.id,
|
|
46650
|
+
_f = _needUpdateCell$nInde.f,
|
|
46651
|
+
v = _needUpdateCell$nInde.v;
|
|
46652
|
+
var result = execfunction(ctx, _f, _r, _c, _id, undefined, true);
|
|
46653
|
+
var newV = result[1];
|
|
46654
|
+
if (newV === v) {
|
|
46655
|
+
continue;
|
|
46656
|
+
}
|
|
46657
|
+
setCellValue$1(ctx, _r, _c, result[1], null, {
|
|
46658
|
+
id: _id
|
|
46659
|
+
});
|
|
46660
|
+
}
|
|
46661
|
+
console.timeEnd("calculateSheetByCellsTime");
|
|
46575
46662
|
}
|
|
46576
46663
|
|
|
46577
46664
|
function storeSheetParam(ctx) {
|
|
@@ -56230,6 +56317,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
56230
56317
|
showSheet: showSheet,
|
|
56231
56318
|
copySheet: copySheet,
|
|
56232
56319
|
calculateSheetFromula: calculateSheetFromula,
|
|
56320
|
+
calculateSheetByCells: calculateSheetByCells,
|
|
56233
56321
|
addSheet: addSheet$1,
|
|
56234
56322
|
deleteSheet: deleteSheet$1,
|
|
56235
56323
|
updateSheet: updateSheet$1,
|
package/dist/index.js
CHANGED
|
@@ -46549,6 +46549,7 @@ function copySheet(ctx, sheetId, hooks) {
|
|
|
46549
46549
|
(_hooks$onCopySheet = hooks.onCopySheet) === null || _hooks$onCopySheet === void 0 ? void 0 : _hooks$onCopySheet.call(hooks, sheetId, copyId);
|
|
46550
46550
|
}
|
|
46551
46551
|
function calculateSheetFromula(ctx, id) {
|
|
46552
|
+
console.time("calcTime:".concat(id));
|
|
46552
46553
|
var index$1 = getSheetIndex(ctx, id);
|
|
46553
46554
|
var luckysheetfile = ctx.luckysheetfile;
|
|
46554
46555
|
var file = luckysheetfile[index$1];
|
|
@@ -46559,29 +46560,115 @@ function calculateSheetFromula(ctx, id) {
|
|
|
46559
46560
|
if (!ctx.luckysheetfile[index$1].data) return;
|
|
46560
46561
|
for (var r = 0; r < ctx.luckysheetfile[index$1].data.length; r += 1) {
|
|
46561
46562
|
for (var c = 0; c < ctx.luckysheetfile[index$1].data[r].length; c += 1) {
|
|
46562
|
-
var
|
|
46563
|
-
if (!(
|
|
46563
|
+
var cell = ctx.luckysheetfile[index$1].data[r][c];
|
|
46564
|
+
if (!(cell === null || cell === void 0 ? void 0 : cell.f)) {
|
|
46564
46565
|
continue;
|
|
46565
46566
|
}
|
|
46566
|
-
var result = execfunction(ctx, (_ctx$luckysheetfile$i2 = ctx.luckysheetfile[index$1].data[r][c]) === null || _ctx$luckysheetfile$i2 === void 0 ? void 0 : _ctx$luckysheetfile$i2.f, r, c, id, undefined, true);
|
|
46567
|
-
setCellValue$1(ctx, r, c, result[1], null, {
|
|
46568
|
-
id: id
|
|
46569
|
-
});
|
|
46570
|
-
if (___default['default'].isNil(id)) {
|
|
46571
|
-
id = ctx.currentSheetId;
|
|
46572
|
-
}
|
|
46573
46567
|
var cc = {
|
|
46574
46568
|
r: r,
|
|
46575
46569
|
c: c,
|
|
46576
46570
|
id: id
|
|
46577
46571
|
};
|
|
46578
46572
|
calcChain.push(cc);
|
|
46573
|
+
var result = execfunction(ctx, cell === null || cell === void 0 ? void 0 : cell.f, r, c, id, undefined, true);
|
|
46574
|
+
var newV = result[1];
|
|
46575
|
+
if (newV === cell.v) {
|
|
46576
|
+
continue;
|
|
46577
|
+
}
|
|
46578
|
+
setCellValue$1(ctx, r, c, result[1], null, {
|
|
46579
|
+
id: id
|
|
46580
|
+
});
|
|
46579
46581
|
}
|
|
46580
46582
|
}
|
|
46581
46583
|
file.calcChain = _.uniqBy(calcChain, function (item) {
|
|
46582
46584
|
return item.r + item.c + item.id;
|
|
46583
46585
|
});
|
|
46584
46586
|
ctx.luckysheetfile = luckysheetfile;
|
|
46587
|
+
console.timeEnd("calcTime:".concat(id));
|
|
46588
|
+
}
|
|
46589
|
+
function parseCellReferences(expression) {
|
|
46590
|
+
if (typeof expression !== "string" || expression.trim() === "") {
|
|
46591
|
+
return [];
|
|
46592
|
+
}
|
|
46593
|
+
var cellRegex = /([A-Za-z0-9_]+!)?[A-Za-z]+\d+/g;
|
|
46594
|
+
var matches = expression.match(cellRegex) || [];
|
|
46595
|
+
var uniqueCells = matches.map(function (cell) {
|
|
46596
|
+
return cell.trim().toUpperCase();
|
|
46597
|
+
});
|
|
46598
|
+
return uniqueCells;
|
|
46599
|
+
}
|
|
46600
|
+
function calculateSheetByCells(ctx, cells) {
|
|
46601
|
+
console.time("calculateSheetByCellsTime");
|
|
46602
|
+
var fileList = ctx.luckysheetfile;
|
|
46603
|
+
var sheetIdNameMap = {};
|
|
46604
|
+
for (var ffIndex = 0; ffIndex < fileList.length; ffIndex++) {
|
|
46605
|
+
var _f$name;
|
|
46606
|
+
var f = fileList[ffIndex];
|
|
46607
|
+
sheetIdNameMap[f.id] = (_f$name = f.name) === null || _f$name === void 0 ? void 0 : _f$name.toLocaleUpperCase();
|
|
46608
|
+
}
|
|
46609
|
+
var needUpdateCell = [];
|
|
46610
|
+
var updatedMap = {};
|
|
46611
|
+
for (var index$1 = 0; index$1 < cells.length; index$1++) {
|
|
46612
|
+
var _cells$index = cells[index$1],
|
|
46613
|
+
r = _cells$index.r,
|
|
46614
|
+
c = _cells$index.c,
|
|
46615
|
+
id = _cells$index.id;
|
|
46616
|
+
updatedMap["".concat(sheetIdNameMap[id], "!").concat(indexToColumnChar(c) + (r + 1))] = true;
|
|
46617
|
+
}
|
|
46618
|
+
var _loop = function _loop() {
|
|
46619
|
+
var file = fileList[fIndex];
|
|
46620
|
+
var sheetId = file.id;
|
|
46621
|
+
var _file$calcChain = file.calcChain,
|
|
46622
|
+
calcChain = _file$calcChain === void 0 ? [] : _file$calcChain;
|
|
46623
|
+
for (var _index = 0; _index < calcChain.length; _index++) {
|
|
46624
|
+
var _parseCellReferences;
|
|
46625
|
+
var _calcChain$_index = calcChain[_index],
|
|
46626
|
+
_r2 = _calcChain$_index.r,
|
|
46627
|
+
_c2 = _calcChain$_index.c;
|
|
46628
|
+
var cell = file.data[_r2][_c2];
|
|
46629
|
+
if (!(cell === null || cell === void 0 ? void 0 : cell.f)) {
|
|
46630
|
+
continue;
|
|
46631
|
+
}
|
|
46632
|
+
var devCell = (_parseCellReferences = parseCellReferences(cell.f)) === null || _parseCellReferences === void 0 ? void 0 : _parseCellReferences.map(function (item) {
|
|
46633
|
+
return item.includes("!") ? item : "".concat(sheetIdNameMap[sheetId], "!").concat(item);
|
|
46634
|
+
});
|
|
46635
|
+
var n = devCell === null || devCell === void 0 ? void 0 : devCell.some(function (item) {
|
|
46636
|
+
return updatedMap["".concat(item)];
|
|
46637
|
+
});
|
|
46638
|
+
if (n) {
|
|
46639
|
+
needUpdateCell.push({
|
|
46640
|
+
r: _r2,
|
|
46641
|
+
c: _c2,
|
|
46642
|
+
id: sheetId,
|
|
46643
|
+
f: cell.f,
|
|
46644
|
+
v: cell.v
|
|
46645
|
+
});
|
|
46646
|
+
}
|
|
46647
|
+
}
|
|
46648
|
+
};
|
|
46649
|
+
for (var fIndex = 0; fIndex < fileList.length; fIndex++) {
|
|
46650
|
+
_loop();
|
|
46651
|
+
}
|
|
46652
|
+
needUpdateCell = _.uniqBy(needUpdateCell, function (item) {
|
|
46653
|
+
return "".concat(item.r, "_").concat(item.c, "_").concat(item.id);
|
|
46654
|
+
});
|
|
46655
|
+
for (var nIndex = 0; nIndex < needUpdateCell.length; nIndex++) {
|
|
46656
|
+
var _needUpdateCell$nInde = needUpdateCell[nIndex],
|
|
46657
|
+
_r = _needUpdateCell$nInde.r,
|
|
46658
|
+
_c = _needUpdateCell$nInde.c,
|
|
46659
|
+
_id = _needUpdateCell$nInde.id,
|
|
46660
|
+
_f = _needUpdateCell$nInde.f,
|
|
46661
|
+
v = _needUpdateCell$nInde.v;
|
|
46662
|
+
var result = execfunction(ctx, _f, _r, _c, _id, undefined, true);
|
|
46663
|
+
var newV = result[1];
|
|
46664
|
+
if (newV === v) {
|
|
46665
|
+
continue;
|
|
46666
|
+
}
|
|
46667
|
+
setCellValue$1(ctx, _r, _c, result[1], null, {
|
|
46668
|
+
id: _id
|
|
46669
|
+
});
|
|
46670
|
+
}
|
|
46671
|
+
console.timeEnd("calculateSheetByCellsTime");
|
|
46585
46672
|
}
|
|
46586
46673
|
|
|
46587
46674
|
function storeSheetParam(ctx) {
|
|
@@ -56240,6 +56327,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
56240
56327
|
showSheet: showSheet,
|
|
56241
56328
|
copySheet: copySheet,
|
|
56242
56329
|
calculateSheetFromula: calculateSheetFromula,
|
|
56330
|
+
calculateSheetByCells: calculateSheetByCells,
|
|
56243
56331
|
addSheet: addSheet$1,
|
|
56244
56332
|
deleteSheet: deleteSheet$1,
|
|
56245
56333
|
updateSheet: updateSheet$1,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leankylin-sheet/core",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.61",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.esm.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"build": "father-build"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@leankylin-sheet/formula-parser": "4.0.
|
|
16
|
+
"@leankylin-sheet/formula-parser": "4.0.61",
|
|
17
17
|
"dayjs": "^1.11.0",
|
|
18
18
|
"immer": "^9.0.12",
|
|
19
19
|
"lodash": "^4.17.21",
|