@univerjs/engine-formula 0.2.11 → 0.2.12
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/lib/cjs/index.js +2 -2
- package/lib/es/index.js +202 -58
- package/lib/types/controller/config.schema.d.ts +10 -0
- package/lib/types/controller/formula.controller.d.ts +3 -5
- package/lib/types/engine/dependency/dependency-tree.d.ts +20 -0
- package/lib/types/engine/dependency/range-block-util.d.ts +15 -0
- package/lib/types/functions/information/isformula/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/information/isformula/index.d.ts +9 -0
- package/lib/types/functions/information/n/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/information/n/index.d.ts +7 -0
- package/lib/types/functions/information/na/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/information/na/index.d.ts +7 -0
- package/lib/types/plugin.d.ts +5 -10
- package/lib/types/services/dependency-manager.service.d.ts +1 -6
- package/lib/umd/index.js +2 -2
- package/package.json +6 -6
package/lib/es/index.js
CHANGED
|
@@ -1013,7 +1013,7 @@ const FORMULA_CACHE_LRU_COUNT$2 = 1e5, FormulaLexerNodeCache = new FormulaAstLRU
|
|
|
1013
1013
|
this._pushNodeToChildren(currentString), this._openBracket(
|
|
1014
1014
|
0
|
|
1015
1015
|
/* NORMAL */
|
|
1016
|
-
);
|
|
1016
|
+
), this._resetSegment();
|
|
1017
1017
|
else if (currentString === matchToken.CLOSE_BRACKET && this.isSingleQuotationClose() && this.isDoubleQuotationClose()) {
|
|
1018
1018
|
this._pushNodeToChildren(this._segment), this._resetSegment();
|
|
1019
1019
|
const currentBracket = this._getCurrentBracket();
|
|
@@ -9606,9 +9606,9 @@ function calculateOddFPrice(settlementSerialNumber, maturitySerialNumber, issueS
|
|
|
9606
9606
|
__name(calculateOddFPrice, "calculateOddFPrice");
|
|
9607
9607
|
function calculateOddShortFirstCoupon(settlementSerialNumber, maturitySerialNumber, issueSerialNumber, firstCouponSerialNumber, rate, yld, redemption, frequency, basis, DFC, E) {
|
|
9608
9608
|
let result = 0;
|
|
9609
|
-
const
|
|
9610
|
-
result += redemption / (1 + yld / frequency) ** (
|
|
9611
|
-
for (let k = 2; k <=
|
|
9609
|
+
const N2 = calculateCoupnum(settlementSerialNumber, maturitySerialNumber, frequency), DSC = getPositiveDaysBetween(settlementSerialNumber, firstCouponSerialNumber, basis);
|
|
9610
|
+
result += redemption / (1 + yld / frequency) ** (N2 - 1 + DSC / E), result += 100 * rate / frequency * DFC / E / (1 + yld / frequency) ** (DSC / E);
|
|
9611
|
+
for (let k = 2; k <= N2; k++)
|
|
9612
9612
|
result += 100 * rate / frequency / (1 + yld / frequency) ** (k - 1 + DSC / E);
|
|
9613
9613
|
const A = getPositiveDaysBetween(issueSerialNumber, settlementSerialNumber, basis);
|
|
9614
9614
|
return result -= 100 * rate / frequency * A / E, result;
|
|
@@ -9616,7 +9616,7 @@ function calculateOddShortFirstCoupon(settlementSerialNumber, maturitySerialNumb
|
|
|
9616
9616
|
__name(calculateOddShortFirstCoupon, "calculateOddShortFirstCoupon");
|
|
9617
9617
|
function calculateOddLongFirstCoupon(settlementSerialNumber, maturitySerialNumber, issueSerialNumber, firstCouponSerialNumber, rate, yld, redemption, frequency, basis, E) {
|
|
9618
9618
|
let result = 0;
|
|
9619
|
-
const
|
|
9619
|
+
const N2 = calculateCoupnum(firstCouponSerialNumber, maturitySerialNumber, frequency), Nq = getCouponsNumber(firstCouponSerialNumber, settlementSerialNumber, 12 / frequency, !0);
|
|
9620
9620
|
let DSC;
|
|
9621
9621
|
if (basis === 2 || basis === 3) {
|
|
9622
9622
|
const coupncd = calculateCoupncd(settlementSerialNumber, firstCouponSerialNumber, frequency);
|
|
@@ -9625,7 +9625,7 @@ function calculateOddLongFirstCoupon(settlementSerialNumber, maturitySerialNumbe
|
|
|
9625
9625
|
const couppcd = calculateCouppcd(settlementSerialNumber, firstCouponSerialNumber, frequency), { days } = getTwoDateDaysByBasis(couppcd, settlementSerialNumber, basis);
|
|
9626
9626
|
DSC = E - days;
|
|
9627
9627
|
}
|
|
9628
|
-
result += redemption / (1 + yld / frequency) ** (
|
|
9628
|
+
result += redemption / (1 + yld / frequency) ** (N2 + Nq + DSC / E);
|
|
9629
9629
|
const NC = calculateCoupnum(issueSerialNumber, firstCouponSerialNumber, frequency);
|
|
9630
9630
|
let lateCoupon = firstCouponSerialNumber, DCiDivNLiSum = 0, AiDivNLiSum = 0;
|
|
9631
9631
|
for (let index = NC; index >= 1; index--) {
|
|
@@ -9635,7 +9635,7 @@ function calculateOddLongFirstCoupon(settlementSerialNumber, maturitySerialNumbe
|
|
|
9635
9635
|
AiDivNLiSum += Ai / NLi, lateCoupon = earlyCoupon;
|
|
9636
9636
|
}
|
|
9637
9637
|
result += 100 * rate / frequency * DCiDivNLiSum / (1 + yld / frequency) ** (Nq + DSC / E);
|
|
9638
|
-
for (let k = 1; k <=
|
|
9638
|
+
for (let k = 1; k <= N2; k++)
|
|
9639
9639
|
result += 100 * rate / frequency / (1 + yld / frequency) ** (k + Nq + DSC / E);
|
|
9640
9640
|
return result -= 100 * rate / frequency * AiDivNLiSum, result;
|
|
9641
9641
|
}
|
|
@@ -9710,14 +9710,14 @@ function guessIsNaNorInfinity(guess, iterF) {
|
|
|
9710
9710
|
}
|
|
9711
9711
|
__name(guessIsNaNorInfinity, "guessIsNaNorInfinity");
|
|
9712
9712
|
function calculatePrice(settlementSerialNumber, maturitySerialNumber, rate, yld, redemption, frequency, basis) {
|
|
9713
|
-
const
|
|
9714
|
-
if (
|
|
9713
|
+
const N2 = calculateCoupnum(settlementSerialNumber, maturitySerialNumber, frequency), E = calculateCoupdays(settlementSerialNumber, maturitySerialNumber, frequency, basis), A = calculateCoupdaybs(settlementSerialNumber, maturitySerialNumber, frequency, basis);
|
|
9714
|
+
if (N2 === 1) {
|
|
9715
9715
|
const DSR = E - A, T1 = 100 * rate / frequency + redemption, T2 = yld / frequency * DSR / E + 1, T3 = 100 * rate / frequency * A / E;
|
|
9716
9716
|
return T1 / T2 - T3;
|
|
9717
9717
|
}
|
|
9718
9718
|
const DSC = E - A;
|
|
9719
|
-
let result = redemption / (1 + yld / frequency) ** (
|
|
9720
|
-
for (let k = 1; k <=
|
|
9719
|
+
let result = redemption / (1 + yld / frequency) ** (N2 - 1 + DSC / E);
|
|
9720
|
+
for (let k = 1; k <= N2; k++)
|
|
9721
9721
|
result += 100 * rate / frequency / (1 + yld / frequency) ** (k - 1 + DSC / E);
|
|
9722
9722
|
return result -= 100 * rate / frequency * A / E, result;
|
|
9723
9723
|
}
|
|
@@ -12171,6 +12171,29 @@ const _Iseven = class _Iseven extends BaseFunction {
|
|
|
12171
12171
|
};
|
|
12172
12172
|
__name(_Iseven, "Iseven");
|
|
12173
12173
|
let Iseven = _Iseven;
|
|
12174
|
+
const _Isformula = class _Isformula extends BaseFunction {
|
|
12175
|
+
constructor() {
|
|
12176
|
+
super(...arguments);
|
|
12177
|
+
__publicField(this, "minParams", 1);
|
|
12178
|
+
__publicField(this, "maxParams", 1);
|
|
12179
|
+
__publicField(this, "needsReferenceObject", !0);
|
|
12180
|
+
}
|
|
12181
|
+
calculate(reference) {
|
|
12182
|
+
var _a25;
|
|
12183
|
+
if (reference.isError())
|
|
12184
|
+
return reference;
|
|
12185
|
+
if (!reference.isReferenceObject())
|
|
12186
|
+
return ErrorValueObject.create(ErrorType$1.NA);
|
|
12187
|
+
const cellDataMatrix = (_a25 = reference.getCurrentActiveSheetData()) == null ? void 0 : _a25.cellData.getMatrix(), { startRow, startColumn } = reference.getRangePosition(), _reference = reference.toArrayValueObject(), resultArray = _reference.mapValue((valueObject, rowIndex, columnIndex) => {
|
|
12188
|
+
var _a26;
|
|
12189
|
+
const cellData = (_a26 = cellDataMatrix == null ? void 0 : cellDataMatrix[startRow + rowIndex]) == null ? void 0 : _a26[startColumn + columnIndex];
|
|
12190
|
+
return cellData != null && cellData.f || cellData != null && cellData.si ? BooleanValueObject.create(!0) : BooleanValueObject.create(!1);
|
|
12191
|
+
});
|
|
12192
|
+
return _reference.getRowCount() === 1 && _reference.getColumnCount() === 1 ? resultArray.get(0, 0) : resultArray;
|
|
12193
|
+
}
|
|
12194
|
+
};
|
|
12195
|
+
__name(_Isformula, "Isformula");
|
|
12196
|
+
let Isformula = _Isformula;
|
|
12174
12197
|
const _Islogical = class _Islogical extends BaseFunction {
|
|
12175
12198
|
constructor() {
|
|
12176
12199
|
super(...arguments);
|
|
@@ -12271,6 +12294,36 @@ const _Istext = class _Istext extends BaseFunction {
|
|
|
12271
12294
|
};
|
|
12272
12295
|
__name(_Istext, "Istext");
|
|
12273
12296
|
let Istext = _Istext;
|
|
12297
|
+
const _N = class _N extends BaseFunction {
|
|
12298
|
+
constructor() {
|
|
12299
|
+
super(...arguments);
|
|
12300
|
+
__publicField(this, "minParams", 1);
|
|
12301
|
+
__publicField(this, "maxParams", 1);
|
|
12302
|
+
}
|
|
12303
|
+
calculate(value) {
|
|
12304
|
+
let _value = value;
|
|
12305
|
+
if (value.isArray() && (_value = value.get(0, 0)), _value.isError())
|
|
12306
|
+
return _value;
|
|
12307
|
+
if (_value.isString())
|
|
12308
|
+
return NumberValueObject.create(0);
|
|
12309
|
+
const val = +_value.getValue();
|
|
12310
|
+
return NumberValueObject.create(val);
|
|
12311
|
+
}
|
|
12312
|
+
};
|
|
12313
|
+
__name(_N, "N");
|
|
12314
|
+
let N = _N;
|
|
12315
|
+
const _Na = class _Na extends BaseFunction {
|
|
12316
|
+
constructor() {
|
|
12317
|
+
super(...arguments);
|
|
12318
|
+
__publicField(this, "minParams", 0);
|
|
12319
|
+
__publicField(this, "maxParams", 0);
|
|
12320
|
+
}
|
|
12321
|
+
calculate() {
|
|
12322
|
+
return ErrorValueObject.create(ErrorType$1.NA);
|
|
12323
|
+
}
|
|
12324
|
+
};
|
|
12325
|
+
__name(_Na, "Na");
|
|
12326
|
+
let Na = _Na;
|
|
12274
12327
|
const _Type = class _Type extends BaseFunction {
|
|
12275
12328
|
constructor() {
|
|
12276
12329
|
super(...arguments);
|
|
@@ -12317,6 +12370,7 @@ const functionInformation = [
|
|
|
12317
12370
|
[Iserr, FUNCTION_NAMES_INFORMATION.ISERR],
|
|
12318
12371
|
[Iserror, FUNCTION_NAMES_INFORMATION.ISERROR],
|
|
12319
12372
|
[Iseven, FUNCTION_NAMES_INFORMATION.ISEVEN],
|
|
12373
|
+
[Isformula, FUNCTION_NAMES_INFORMATION.ISFORMULA],
|
|
12320
12374
|
[Islogical, FUNCTION_NAMES_INFORMATION.ISLOGICAL],
|
|
12321
12375
|
[Isna, FUNCTION_NAMES_INFORMATION.ISNA],
|
|
12322
12376
|
[Isnontext, FUNCTION_NAMES_INFORMATION.ISNONTEXT],
|
|
@@ -12324,6 +12378,8 @@ const functionInformation = [
|
|
|
12324
12378
|
[Isodd, FUNCTION_NAMES_INFORMATION.ISODD],
|
|
12325
12379
|
[Isref, FUNCTION_NAMES_INFORMATION.ISREF],
|
|
12326
12380
|
[Istext, FUNCTION_NAMES_INFORMATION.ISTEXT],
|
|
12381
|
+
[N, FUNCTION_NAMES_INFORMATION.N],
|
|
12382
|
+
[Na, FUNCTION_NAMES_INFORMATION.NA],
|
|
12327
12383
|
[Type, FUNCTION_NAMES_INFORMATION.TYPE]
|
|
12328
12384
|
];
|
|
12329
12385
|
var FUNCTION_NAMES_LOGICAL = /* @__PURE__ */ ((FUNCTION_NAMES_LOGICAL2) => (FUNCTION_NAMES_LOGICAL2.AND = "AND", FUNCTION_NAMES_LOGICAL2.BYCOL = "BYCOL", FUNCTION_NAMES_LOGICAL2.BYROW = "BYROW", FUNCTION_NAMES_LOGICAL2.FALSE = "FALSE", FUNCTION_NAMES_LOGICAL2.IF = "IF", FUNCTION_NAMES_LOGICAL2.IFERROR = "IFERROR", FUNCTION_NAMES_LOGICAL2.IFNA = "IFNA", FUNCTION_NAMES_LOGICAL2.IFS = "IFS", FUNCTION_NAMES_LOGICAL2.LAMBDA = "LAMBDA", FUNCTION_NAMES_LOGICAL2.LET = "LET", FUNCTION_NAMES_LOGICAL2.MAKEARRAY = "MAKEARRAY", FUNCTION_NAMES_LOGICAL2.MAP = "MAP", FUNCTION_NAMES_LOGICAL2.NOT = "NOT", FUNCTION_NAMES_LOGICAL2.OR = "OR", FUNCTION_NAMES_LOGICAL2.REDUCE = "REDUCE", FUNCTION_NAMES_LOGICAL2.SCAN = "SCAN", FUNCTION_NAMES_LOGICAL2.SWITCH = "SWITCH", FUNCTION_NAMES_LOGICAL2.TRUE = "TRUE", FUNCTION_NAMES_LOGICAL2.XOR = "XOR", FUNCTION_NAMES_LOGICAL2))(FUNCTION_NAMES_LOGICAL || {});
|
|
@@ -19825,7 +19881,7 @@ const IOtherFormulaManagerService = createIdentifier(
|
|
|
19825
19881
|
"univer.formula.other-formula-manager.service"
|
|
19826
19882
|
), _FormulaDependencyTree = class _FormulaDependencyTree extends Disposable {
|
|
19827
19883
|
constructor() {
|
|
19828
|
-
super(
|
|
19884
|
+
super();
|
|
19829
19885
|
__publicField(this, "node");
|
|
19830
19886
|
__publicField(this, "children", []);
|
|
19831
19887
|
__publicField(this, "parents", []);
|
|
@@ -19840,8 +19896,16 @@ const IOtherFormulaManagerService = createIdentifier(
|
|
|
19840
19896
|
__publicField(this, "formulaId");
|
|
19841
19897
|
__publicField(this, "featureId");
|
|
19842
19898
|
__publicField(this, "isPassive", !0);
|
|
19899
|
+
__publicField(this, "_childIds", /* @__PURE__ */ new Set());
|
|
19900
|
+
// the left top cell , which means the position of the FormulaDependencyTree
|
|
19901
|
+
__publicField(this, "anchorToken", "");
|
|
19843
19902
|
__publicField(this, "getDirtyData");
|
|
19844
19903
|
__publicField(this, "_state", 0);
|
|
19904
|
+
__publicField(this, "_id");
|
|
19905
|
+
this._id = `${Math.random().toString(36).slice(3)}-${Math.random().toString(36).slice(3)}`;
|
|
19906
|
+
}
|
|
19907
|
+
get id() {
|
|
19908
|
+
return this._id;
|
|
19845
19909
|
}
|
|
19846
19910
|
dispose() {
|
|
19847
19911
|
var _a25;
|
|
@@ -19907,7 +19971,10 @@ const IOtherFormulaManagerService = createIdentifier(
|
|
|
19907
19971
|
return !1;
|
|
19908
19972
|
}
|
|
19909
19973
|
pushChildren(tree) {
|
|
19910
|
-
this.children.push(tree), tree._pushParent(this);
|
|
19974
|
+
this.children.push(tree), tree._pushParent(this), this._childIds.add(tree.id);
|
|
19975
|
+
}
|
|
19976
|
+
hasChild(tree) {
|
|
19977
|
+
return this._childIds.has(tree.id);
|
|
19911
19978
|
}
|
|
19912
19979
|
/**
|
|
19913
19980
|
* Add the range corresponding to the current ast node.
|
|
@@ -19940,6 +20007,11 @@ const _FormulaDependencyTreeCache = class _FormulaDependencyTreeCache extends Di
|
|
|
19940
20007
|
constructor() {
|
|
19941
20008
|
super(...arguments);
|
|
19942
20009
|
__publicField(this, "_cacheItems", /* @__PURE__ */ new Map());
|
|
20010
|
+
__publicField(this, "_map", /* @__PURE__ */ new Map());
|
|
20011
|
+
__publicField(this, "_dependencyMap", /* @__PURE__ */ new Map());
|
|
20012
|
+
__publicField(this, "_parentIdMap", /* @__PURE__ */ new Map());
|
|
20013
|
+
// use for mark the first cell of the range
|
|
20014
|
+
__publicField(this, "_rangeTokens", /* @__PURE__ */ new Set());
|
|
19943
20015
|
}
|
|
19944
20016
|
dispose() {
|
|
19945
20017
|
this.clear();
|
|
@@ -19947,6 +20019,12 @@ const _FormulaDependencyTreeCache = class _FormulaDependencyTreeCache extends Di
|
|
|
19947
20019
|
size() {
|
|
19948
20020
|
return this._cacheItems.size;
|
|
19949
20021
|
}
|
|
20022
|
+
getDependencyMap() {
|
|
20023
|
+
return this._dependencyMap;
|
|
20024
|
+
}
|
|
20025
|
+
getDependencyTree(id) {
|
|
20026
|
+
return this._dependencyMap.get(id);
|
|
20027
|
+
}
|
|
19950
20028
|
get length() {
|
|
19951
20029
|
return this._cacheItems.size;
|
|
19952
20030
|
}
|
|
@@ -19955,14 +20033,38 @@ const _FormulaDependencyTreeCache = class _FormulaDependencyTreeCache extends Di
|
|
|
19955
20033
|
if (!this._cacheItems.has(token)) {
|
|
19956
20034
|
this._cacheItems.set(token, {
|
|
19957
20035
|
unitRangeWithToken,
|
|
19958
|
-
treeList: [tree]
|
|
20036
|
+
treeList: [tree],
|
|
20037
|
+
ids: /* @__PURE__ */ new Set([tree.id])
|
|
19959
20038
|
});
|
|
19960
20039
|
return;
|
|
19961
20040
|
}
|
|
19962
|
-
this._cacheItems.get(token)
|
|
20041
|
+
const cacheItem = this._cacheItems.get(token);
|
|
20042
|
+
cacheItem.treeList.push(tree), cacheItem.ids.add(tree.id);
|
|
20043
|
+
const { gridRange } = unitRangeWithToken, { range } = gridRange;
|
|
20044
|
+
range.startRow === range.endRow && range.startColumn === range.endColumn || this._rangeTokens.add(token);
|
|
20045
|
+
}
|
|
20046
|
+
addDependencyMap(tree) {
|
|
20047
|
+
this._dependencyMap.set(tree.id, tree);
|
|
20048
|
+
}
|
|
20049
|
+
updateParent(tree) {
|
|
20050
|
+
const ids = /* @__PURE__ */ new Set(), unitId = tree.unitId, sheetId = tree.subUnitId, testCacheItems = this._cacheItems.get(tree.anchorToken);
|
|
20051
|
+
if (testCacheItems) {
|
|
20052
|
+
this._parentIdMap.set(tree.id, [...testCacheItems.ids]);
|
|
20053
|
+
return;
|
|
20054
|
+
}
|
|
20055
|
+
for (const token of this._rangeTokens) {
|
|
20056
|
+
const cacheItem = this._cacheItems.get(token);
|
|
20057
|
+
if (cacheItem) {
|
|
20058
|
+
const { unitRangeWithToken, treeList } = cacheItem, { gridRange } = unitRangeWithToken;
|
|
20059
|
+
if (gridRange.unitId === unitId && gridRange.sheetId === sheetId && tree.inRangeData(gridRange.range))
|
|
20060
|
+
for (const tree2 of treeList)
|
|
20061
|
+
ids.add(tree2.id);
|
|
20062
|
+
}
|
|
20063
|
+
}
|
|
20064
|
+
this._parentIdMap.set(tree.id, [...ids]);
|
|
19963
20065
|
}
|
|
19964
20066
|
clear() {
|
|
19965
|
-
this._cacheItems.clear();
|
|
20067
|
+
this._cacheItems.clear(), this._map.clear(), this._dependencyMap.clear();
|
|
19966
20068
|
}
|
|
19967
20069
|
remove(token, tree) {
|
|
19968
20070
|
if (!this._cacheItems.has(token))
|
|
@@ -19973,6 +20075,35 @@ const _FormulaDependencyTreeCache = class _FormulaDependencyTreeCache extends Di
|
|
|
19973
20075
|
delete(token) {
|
|
19974
20076
|
this._cacheItems.delete(token);
|
|
19975
20077
|
}
|
|
20078
|
+
getDependencyId(dependenceTree, ids) {
|
|
20079
|
+
const parentIdList = this._parentIdMap.get(dependenceTree.id);
|
|
20080
|
+
if (parentIdList)
|
|
20081
|
+
for (const parentId of parentIdList) {
|
|
20082
|
+
ids.add(parentId);
|
|
20083
|
+
const tree = this._dependencyMap.get(parentId);
|
|
20084
|
+
tree && this.getDependencyId(tree, ids);
|
|
20085
|
+
}
|
|
20086
|
+
}
|
|
20087
|
+
/**
|
|
20088
|
+
* Determine whether range is dependent on other trees.
|
|
20089
|
+
* @param dependenceTree
|
|
20090
|
+
*/
|
|
20091
|
+
dependencyUseParentId(dependenceTree) {
|
|
20092
|
+
let ids = /* @__PURE__ */ new Set();
|
|
20093
|
+
this.getDependencyId(dependenceTree, ids);
|
|
20094
|
+
for (const parentId of ids) {
|
|
20095
|
+
const tree = this._dependencyMap.get(parentId);
|
|
20096
|
+
if (tree && tree.hasChild(dependenceTree) && tree.rangeList) {
|
|
20097
|
+
for (const rangeItem of tree.rangeList)
|
|
20098
|
+
if (rangeItem.gridRange.unitId === dependenceTree.unitId && rangeItem.gridRange.sheetId === dependenceTree.subUnitId) {
|
|
20099
|
+
tree.pushChildren(dependenceTree);
|
|
20100
|
+
break;
|
|
20101
|
+
}
|
|
20102
|
+
}
|
|
20103
|
+
tree && !tree.hasChild(dependenceTree) && tree.pushChildren(dependenceTree);
|
|
20104
|
+
}
|
|
20105
|
+
ids.clear(), ids = null;
|
|
20106
|
+
}
|
|
19976
20107
|
/**
|
|
19977
20108
|
* Determine whether range is dependent on other trees.
|
|
19978
20109
|
* @param dependenceTree
|
|
@@ -20028,7 +20159,21 @@ const _DependencyManagerService = class _DependencyManagerService extends Dispos
|
|
|
20028
20159
|
}
|
|
20029
20160
|
buildDependencyTree(shouldBeBuildTrees, dependencyTrees) {
|
|
20030
20161
|
const allTrees = this.getAllTree();
|
|
20031
|
-
return shouldBeBuildTrees
|
|
20162
|
+
return shouldBeBuildTrees instanceof FormulaDependencyTreeCache ? this._buildDependencyTreeWithCache(allTrees, shouldBeBuildTrees, dependencyTrees || []) : this._buildDependencyTree(allTrees, shouldBeBuildTrees, shouldBeBuildTrees), allTrees;
|
|
20163
|
+
}
|
|
20164
|
+
_buildDependencyTreeWithCache(allTrees, formulaDependencyTreeCache, dependencyTrees) {
|
|
20165
|
+
const cache = new FormulaDependencyTreeCache();
|
|
20166
|
+
for (const tree of allTrees.concat(dependencyTrees)) {
|
|
20167
|
+
const rangeList = tree.rangeList;
|
|
20168
|
+
for (const range of rangeList)
|
|
20169
|
+
cache.add(range, tree), cache.addDependencyMap(tree);
|
|
20170
|
+
}
|
|
20171
|
+
const treeMap = cache.getDependencyMap();
|
|
20172
|
+
for (const tree of treeMap.values())
|
|
20173
|
+
cache.updateParent(tree);
|
|
20174
|
+
for (const tree of treeMap.values())
|
|
20175
|
+
cache.dependencyUseParentId(tree);
|
|
20176
|
+
cache.dispose();
|
|
20032
20177
|
}
|
|
20033
20178
|
/**
|
|
20034
20179
|
* Build the dependency relationship between the trees.
|
|
@@ -20036,27 +20181,18 @@ const _DependencyManagerService = class _DependencyManagerService extends Dispos
|
|
|
20036
20181
|
* @param shouldBeBuildTrees FormulaDependencyTree[] | FormulaDependencyTreeCache
|
|
20037
20182
|
*/
|
|
20038
20183
|
_buildDependencyTree(allTrees, shouldBeBuildTrees, dependencyTrees) {
|
|
20039
|
-
|
|
20040
|
-
|
|
20041
|
-
|
|
20042
|
-
|
|
20043
|
-
|
|
20044
|
-
|
|
20045
|
-
|
|
20046
|
-
|
|
20047
|
-
|
|
20048
|
-
|
|
20049
|
-
|
|
20050
|
-
|
|
20051
|
-
*/
|
|
20052
|
-
_buildReverseDependency(allTrees, dependencyTrees) {
|
|
20053
|
-
allTrees.forEach((tree) => {
|
|
20054
|
-
dependencyTrees == null || dependencyTrees.forEach((dependencyTree) => {
|
|
20055
|
-
if (tree === dependencyTree || tree.children.includes(dependencyTree))
|
|
20056
|
-
return !0;
|
|
20057
|
-
tree.dependency(dependencyTree) && tree.pushChildren(dependencyTree);
|
|
20058
|
-
});
|
|
20059
|
-
});
|
|
20184
|
+
const cache = new FormulaDependencyTreeCache();
|
|
20185
|
+
for (const tree of allTrees.concat(shouldBeBuildTrees, dependencyTrees)) {
|
|
20186
|
+
const rangeList = tree.rangeList;
|
|
20187
|
+
for (const range of rangeList)
|
|
20188
|
+
cache.add(range, tree), cache.addDependencyMap(tree);
|
|
20189
|
+
}
|
|
20190
|
+
const treeMap = cache.getDependencyMap();
|
|
20191
|
+
for (const tree of treeMap.values())
|
|
20192
|
+
cache.updateParent(tree);
|
|
20193
|
+
for (const tree of treeMap.values())
|
|
20194
|
+
cache.dependencyUseParentId(tree);
|
|
20195
|
+
cache.dispose();
|
|
20060
20196
|
}
|
|
20061
20197
|
/**
|
|
20062
20198
|
* Clear the dependency relationship of the tree.
|
|
@@ -20253,7 +20389,18 @@ let FormulaDependencyGenerator = (_a15 = class extends Disposable {
|
|
|
20253
20389
|
if (this._dependencyManagerService.hasFormulaDependency(unitId, sheetId, row, column))
|
|
20254
20390
|
return !0;
|
|
20255
20391
|
const node = this._generateAstNode(unitId, formulaString, x, y), FDtree = new FormulaDependencyTree(), sheetItem = unitData[unitId][sheetId];
|
|
20256
|
-
FDtree.node = node, FDtree.formula = formulaString, FDtree.unitId = unitId, FDtree.subUnitId = sheetId, FDtree.row = row, FDtree.column = column
|
|
20392
|
+
FDtree.node = node, FDtree.formula = formulaString, FDtree.unitId = unitId, FDtree.subUnitId = sheetId, FDtree.row = row, FDtree.column = column;
|
|
20393
|
+
const range = {
|
|
20394
|
+
range: {
|
|
20395
|
+
startRow: row,
|
|
20396
|
+
startColumn: column,
|
|
20397
|
+
endRow: row,
|
|
20398
|
+
endColumn: column
|
|
20399
|
+
},
|
|
20400
|
+
unitId,
|
|
20401
|
+
sheetId
|
|
20402
|
+
};
|
|
20403
|
+
FDtree.anchorToken = serializeRangeToRefString({ ...range, sheetName: this._currentConfigService.getSheetName(unitId, sheetId) }), FDtree.rowCount = sheetItem.rowCount, FDtree.columnCount = sheetItem.columnCount, this._dependencyManagerService.addFormulaDependency(unitId, sheetId, row, column, FDtree), treeList.push(FDtree);
|
|
20257
20404
|
});
|
|
20258
20405
|
}
|
|
20259
20406
|
}
|
|
@@ -20819,15 +20966,15 @@ const RegisterFunctionMutation = {
|
|
|
20819
20966
|
id: "formula.mutation.set-super-table-option",
|
|
20820
20967
|
type: CommandType.MUTATION,
|
|
20821
20968
|
handler: /* @__PURE__ */ __name(() => !0, "handler")
|
|
20822
|
-
};
|
|
20969
|
+
}, PLUGIN_CONFIG_KEY = "engine-formula.config", defaultPluginConfig = {};
|
|
20823
20970
|
var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
20824
20971
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
20825
20972
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
20826
20973
|
return kind && result && __defProp$6(target, key, result), result;
|
|
20827
20974
|
}, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a18;
|
|
20828
20975
|
let FormulaController = (_a18 = class extends Disposable {
|
|
20829
|
-
constructor(
|
|
20830
|
-
super(), this.
|
|
20976
|
+
constructor(_commandService, _functionService, _configService, _dataSyncPrimaryController) {
|
|
20977
|
+
super(), this._commandService = _commandService, this._functionService = _functionService, this._configService = _configService, this._dataSyncPrimaryController = _dataSyncPrimaryController, this._initialize();
|
|
20831
20978
|
}
|
|
20832
20979
|
_initialize() {
|
|
20833
20980
|
this._registerCommands(), this._registerFunctions();
|
|
@@ -20856,7 +21003,8 @@ let FormulaController = (_a18 = class extends Disposable {
|
|
|
20856
21003
|
});
|
|
20857
21004
|
}
|
|
20858
21005
|
_registerFunctions() {
|
|
20859
|
-
|
|
21006
|
+
var _a25;
|
|
21007
|
+
const config2 = this._configService.getConfig(PLUGIN_CONFIG_KEY), functions = [
|
|
20860
21008
|
...functionArray,
|
|
20861
21009
|
...functionCompatibility,
|
|
20862
21010
|
...functionCube,
|
|
@@ -20873,7 +21021,7 @@ let FormulaController = (_a18 = class extends Disposable {
|
|
|
20873
21021
|
...functionText,
|
|
20874
21022
|
...functionUniver,
|
|
20875
21023
|
...functionWeb
|
|
20876
|
-
].concat(
|
|
21024
|
+
].concat((_a25 = config2 == null ? void 0 : config2.function) != null ? _a25 : []).map((registerObject) => {
|
|
20877
21025
|
const Func = registerObject[0], name = registerObject[1];
|
|
20878
21026
|
return new Func(name);
|
|
20879
21027
|
});
|
|
@@ -20882,8 +21030,9 @@ let FormulaController = (_a18 = class extends Disposable {
|
|
|
20882
21030
|
}, __name(_a18, "FormulaController"), _a18);
|
|
20883
21031
|
FormulaController = __decorateClass$6([
|
|
20884
21032
|
OnLifecycle(LifecycleStages.Ready, FormulaController),
|
|
20885
|
-
__decorateParam$6(
|
|
20886
|
-
__decorateParam$6(
|
|
21033
|
+
__decorateParam$6(0, ICommandService),
|
|
21034
|
+
__decorateParam$6(1, IFunctionService),
|
|
21035
|
+
__decorateParam$6(2, IConfigService),
|
|
20887
21036
|
__decorateParam$6(3, Optional(DataSyncPrimaryController))
|
|
20888
21037
|
], FormulaController);
|
|
20889
21038
|
var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
@@ -21161,8 +21310,10 @@ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnProperty
|
|
|
21161
21310
|
const PLUGIN_NAME = "base-formula-engine";
|
|
21162
21311
|
var _a24;
|
|
21163
21312
|
let UniverFormulaEnginePlugin = (_a24 = class extends Plugin {
|
|
21164
|
-
constructor(_config, _injector) {
|
|
21165
|
-
super(), this._config = _config, this._injector = _injector;
|
|
21313
|
+
constructor(_config = defaultPluginConfig, _injector, _configService) {
|
|
21314
|
+
super(), this._config = _config, this._injector = _injector, this._configService = _configService;
|
|
21315
|
+
const { ...rest } = this._config;
|
|
21316
|
+
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
|
|
21166
21317
|
}
|
|
21167
21318
|
onStarting() {
|
|
21168
21319
|
this._initialize();
|
|
@@ -21180,15 +21331,7 @@ let UniverFormulaEnginePlugin = (_a24 = class extends Plugin {
|
|
|
21180
21331
|
// Engine
|
|
21181
21332
|
[LexerTreeBuilder],
|
|
21182
21333
|
//Controllers
|
|
21183
|
-
[
|
|
21184
|
-
FormulaController,
|
|
21185
|
-
{
|
|
21186
|
-
useFactory: /* @__PURE__ */ __name(() => {
|
|
21187
|
-
var _a26;
|
|
21188
|
-
return this._injector.createInstance(FormulaController, (_a26 = this._config) == null ? void 0 : _a26.function);
|
|
21189
|
-
}, "useFactory")
|
|
21190
|
-
}
|
|
21191
|
-
],
|
|
21334
|
+
[FormulaController],
|
|
21192
21335
|
[SetDefinedNameController],
|
|
21193
21336
|
[SetSuperTableController]
|
|
21194
21337
|
];
|
|
@@ -21225,7 +21368,8 @@ let UniverFormulaEnginePlugin = (_a24 = class extends Plugin {
|
|
|
21225
21368
|
}
|
|
21226
21369
|
}, __name(_a24, "UniverFormulaEnginePlugin"), __publicField(_a24, "pluginName", PLUGIN_NAME), _a24);
|
|
21227
21370
|
UniverFormulaEnginePlugin = __decorateClass([
|
|
21228
|
-
__decorateParam(1, Inject(Injector))
|
|
21371
|
+
__decorateParam(1, Inject(Injector)),
|
|
21372
|
+
__decorateParam(2, IConfigService)
|
|
21229
21373
|
], UniverFormulaEnginePlugin);
|
|
21230
21374
|
export {
|
|
21231
21375
|
ActiveDirtyManagerService,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Ctor } from '@univerjs/core';
|
|
2
|
+
import { BaseFunction } from '../functions/base-function';
|
|
3
|
+
import { IFunctionNames } from '../basics/function';
|
|
4
|
+
export declare const PLUGIN_CONFIG_KEY = "engine-formula.config";
|
|
5
|
+
export declare const configSymbol: unique symbol;
|
|
6
|
+
export interface IUniverEngineFormulaConfig {
|
|
7
|
+
notExecuteFormula?: boolean;
|
|
8
|
+
function?: Array<[Ctor<BaseFunction>, IFunctionNames]>;
|
|
9
|
+
}
|
|
10
|
+
export declare const defaultPluginConfig: IUniverEngineFormulaConfig;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { Disposable, ICommandService,
|
|
1
|
+
import { Disposable, ICommandService, IConfigService } from '@univerjs/core';
|
|
2
2
|
import { DataSyncPrimaryController } from '@univerjs/rpc';
|
|
3
|
-
import { IFunctionNames } from '../basics/function';
|
|
4
|
-
import { BaseFunction } from '../functions/base-function';
|
|
5
3
|
import { IFunctionService } from '../services/function.service';
|
|
6
4
|
export declare class FormulaController extends Disposable {
|
|
7
|
-
private _function;
|
|
8
5
|
private readonly _commandService;
|
|
9
6
|
private readonly _functionService;
|
|
7
|
+
private readonly _configService;
|
|
10
8
|
private readonly _dataSyncPrimaryController?;
|
|
11
|
-
constructor(
|
|
9
|
+
constructor(_commandService: ICommandService, _functionService: IFunctionService, _configService: IConfigService, _dataSyncPrimaryController?: DataSyncPrimaryController | undefined);
|
|
12
10
|
private _initialize;
|
|
13
11
|
private _registerCommands;
|
|
14
12
|
private _registerFunctions;
|
|
@@ -31,11 +31,16 @@ export declare class FormulaDependencyTree extends Disposable {
|
|
|
31
31
|
formulaId: Nullable<string>;
|
|
32
32
|
featureId: Nullable<string>;
|
|
33
33
|
isPassive: boolean;
|
|
34
|
+
_childIds: Set<string>;
|
|
35
|
+
anchorToken: string;
|
|
34
36
|
getDirtyData: Nullable<(dirtyData: IFormulaDirtyData, runtimeData: IAllRuntimeData) => {
|
|
35
37
|
runtimeCellData: IRuntimeUnitDataType;
|
|
36
38
|
dirtyRanges: IFeatureDirtyRangeType;
|
|
37
39
|
}>;
|
|
38
40
|
private _state;
|
|
41
|
+
private _id;
|
|
42
|
+
constructor();
|
|
43
|
+
get id(): string;
|
|
39
44
|
dispose(): void;
|
|
40
45
|
disposeWithChildren(): void;
|
|
41
46
|
resetState(): void;
|
|
@@ -51,6 +56,7 @@ export declare class FormulaDependencyTree extends Disposable {
|
|
|
51
56
|
*/
|
|
52
57
|
dependencyRange(dependencyRangeList: Map<string, Map<string, IRange[]>>, dirtyUnitSheetNameMap: IDirtyUnitSheetNameMap, unitExcludedCell: Nullable<IUnitExcludedCell>): boolean;
|
|
53
58
|
pushChildren(tree: FormulaDependencyTree): void;
|
|
59
|
+
hasChild(tree: FormulaDependencyTree): boolean;
|
|
54
60
|
/**
|
|
55
61
|
* Add the range corresponding to the current ast node.
|
|
56
62
|
* @param range
|
|
@@ -65,13 +71,27 @@ export declare class FormulaDependencyTree extends Disposable {
|
|
|
65
71
|
}
|
|
66
72
|
export declare class FormulaDependencyTreeCache extends Disposable {
|
|
67
73
|
private _cacheItems;
|
|
74
|
+
private _map;
|
|
75
|
+
private _dependencyMap;
|
|
76
|
+
private _parentIdMap;
|
|
77
|
+
private _rangeTokens;
|
|
68
78
|
dispose(): void;
|
|
69
79
|
size(): number;
|
|
80
|
+
getDependencyMap(): Map<string, FormulaDependencyTree>;
|
|
81
|
+
getDependencyTree(id: string): FormulaDependencyTree | undefined;
|
|
70
82
|
get length(): number;
|
|
71
83
|
add(unitRangeWithToken: IUnitRangeWithToken, tree: FormulaDependencyTree): void;
|
|
84
|
+
addDependencyMap(tree: FormulaDependencyTree): void;
|
|
85
|
+
updateParent(tree: FormulaDependencyTree): void;
|
|
72
86
|
clear(): void;
|
|
73
87
|
remove(token: string, tree: FormulaDependencyTree): void;
|
|
74
88
|
delete(token: string): void;
|
|
89
|
+
getDependencyId(dependenceTree: FormulaDependencyTree, ids: Set<string>): void;
|
|
90
|
+
/**
|
|
91
|
+
* Determine whether range is dependent on other trees.
|
|
92
|
+
* @param dependenceTree
|
|
93
|
+
*/
|
|
94
|
+
dependencyUseParentId(dependenceTree: FormulaDependencyTree): void;
|
|
75
95
|
/**
|
|
76
96
|
* Determine whether range is dependent on other trees.
|
|
77
97
|
* @param dependenceTree
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
|
|
2
|
+
import { BaseValueObject } from '../../../engine/value-object/base-value-object';
|
|
3
|
+
import { BaseFunction } from '../../base-function';
|
|
4
|
+
export declare class Isformula extends BaseFunction {
|
|
5
|
+
minParams: number;
|
|
6
|
+
maxParams: number;
|
|
7
|
+
needsReferenceObject: boolean;
|
|
8
|
+
calculate(reference: FunctionVariantType): BaseValueObject;
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BaseValueObject } from '../../../engine/value-object/base-value-object';
|
|
2
|
+
import { BaseFunction } from '../../base-function';
|
|
3
|
+
export declare class N extends BaseFunction {
|
|
4
|
+
minParams: number;
|
|
5
|
+
maxParams: number;
|
|
6
|
+
calculate(value: BaseValueObject): BaseValueObject;
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|