@univerjs/engine-formula 1.1.0 → 1.2.0
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
CHANGED
|
@@ -8753,7 +8753,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8753
8753
|
const row = [];
|
|
8754
8754
|
for (let c = 0; c < columnArrayCount; c++) {
|
|
8755
8755
|
const cellRaw = columnArray[c].trim();
|
|
8756
|
-
row.push(ValueObjectFactory.create(cellRaw, false, dateSystem));
|
|
8756
|
+
row.push(ValueObjectFactory.createNumberLiteral(cellRaw, dateSystem) ?? ValueObjectFactory.create(cellRaw, false, dateSystem));
|
|
8757
8757
|
}
|
|
8758
8758
|
result.push(row);
|
|
8759
8759
|
}
|
|
@@ -8778,6 +8778,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8778
8778
|
return ArrayValueObject.create(arrayValueObjectData, this.getDateSystem());
|
|
8779
8779
|
}
|
|
8780
8780
|
};
|
|
8781
|
+
const NUMBER_LITERAL_REGEX = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
8781
8782
|
var ValueObjectFactory = class {
|
|
8782
8783
|
static create(rawValue, isIgnoreNumberPattern = false, dateSystem = _univerjs_core.DateSystem.Date1900) {
|
|
8783
8784
|
if (rawValue == null) return NullValueObject.create();
|
|
@@ -8799,6 +8800,19 @@ var ValueObjectFactory = class {
|
|
|
8799
8800
|
if (typeof rawValue === "number") return createNumberValueObjectByRawValue(rawValue).withDateSystem(dateSystem);
|
|
8800
8801
|
return ErrorValueObject.create("#VALUE!");
|
|
8801
8802
|
}
|
|
8803
|
+
/**
|
|
8804
|
+
* Create a number from a number literal written in formula source, such as `12.50`, `.5`, `007` or `1E3`.
|
|
8805
|
+
* Unlike cell text, where "000123456" must stay a string, a number literal in a formula is always a number.
|
|
8806
|
+
*
|
|
8807
|
+
* @param token The unquoted token from the formula source.
|
|
8808
|
+
* @param dateSystem The workbook date system.
|
|
8809
|
+
* @returns The number value object, a NUM error on overflow, or null when the token is not a number literal.
|
|
8810
|
+
*/
|
|
8811
|
+
static createNumberLiteral(token, dateSystem = _univerjs_core.DateSystem.Date1900) {
|
|
8812
|
+
const tokenTrim = token.trim();
|
|
8813
|
+
if (!NUMBER_LITERAL_REGEX.test(tokenTrim)) return null;
|
|
8814
|
+
return createNumberValueObjectByRawValue(Number(tokenTrim)).withDateSystem(dateSystem);
|
|
8815
|
+
}
|
|
8802
8816
|
};
|
|
8803
8817
|
function isStringWrappedByDoubleQuotes(input) {
|
|
8804
8818
|
const trimmedInput = input.trim();
|
|
@@ -9174,6 +9188,16 @@ var BaseReferenceObject = class extends ObjectClassType {
|
|
|
9174
9188
|
getRuntimeFeatureCellValue(row, column) {
|
|
9175
9189
|
return getRuntimeFeatureCell(row, column, this.getSheetId(), this.getUnitId(), this._runtimeFeatureCellData);
|
|
9176
9190
|
}
|
|
9191
|
+
isCellBlank(row, column) {
|
|
9192
|
+
var _this$getCurrentActiv5, _this$getCurrentRunti, _this$getCurrentActiv6, _this$getCurrentRunti2;
|
|
9193
|
+
const cell = this.getCellData(row, column);
|
|
9194
|
+
if (!(0, _univerjs_core.isNullCell)(cell)) return false;
|
|
9195
|
+
const originalCell = (_this$getCurrentActiv5 = this.getCurrentActiveSheetData()) === null || _this$getCurrentActiv5 === void 0 ? void 0 : _this$getCurrentActiv5.cellData.getValue(row, column);
|
|
9196
|
+
if ((0, _univerjs_core.isFormulaString)(originalCell === null || originalCell === void 0 ? void 0 : originalCell.f) || (0, _univerjs_core.isFormulaId)(originalCell === null || originalCell === void 0 ? void 0 : originalCell.si)) return false;
|
|
9197
|
+
if (!cell) return true;
|
|
9198
|
+
if (cell === ((_this$getCurrentRunti = this.getCurrentRuntimeActiveArrayFormulaCellData()) === null || _this$getCurrentRunti === void 0 ? void 0 : _this$getCurrentRunti.getValue(row, column)) || cell === ((_this$getCurrentActiv6 = this.getCurrentActiveArrayFormulaCellData()) === null || _this$getCurrentActiv6 === void 0 ? void 0 : _this$getCurrentActiv6.getValue(row, column)) || cell === this.getRuntimeFeatureCellValue(row, column)) return false;
|
|
9199
|
+
return originalCell != null || cell !== ((_this$getCurrentRunti2 = this.getCurrentRuntimeSheetData()) === null || _this$getCurrentRunti2 === void 0 ? void 0 : _this$getCurrentRunti2.getValue(row, column));
|
|
9200
|
+
}
|
|
9177
9201
|
getCellByPosition(rowRaw, columnRaw) {
|
|
9178
9202
|
const range = this.getRangePosition();
|
|
9179
9203
|
const row = rowRaw ?? range.startRow;
|
|
@@ -12854,6 +12878,21 @@ UnionNodeFactory = __decorate([__decorateParam(0, IFunctionService), __decorateP
|
|
|
12854
12878
|
|
|
12855
12879
|
//#endregion
|
|
12856
12880
|
//#region src/engine/ast-node/value-node.ts
|
|
12881
|
+
/**
|
|
12882
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
12883
|
+
*
|
|
12884
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12885
|
+
* you may not use this file except in compliance with the License.
|
|
12886
|
+
* You may obtain a copy of the License at
|
|
12887
|
+
*
|
|
12888
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12889
|
+
*
|
|
12890
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12891
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12892
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12893
|
+
* See the License for the specific language governing permissions and
|
|
12894
|
+
* limitations under the License.
|
|
12895
|
+
*/
|
|
12857
12896
|
var ValueNode = class extends BaseAstNode {
|
|
12858
12897
|
constructor(operatorString) {
|
|
12859
12898
|
super(operatorString);
|
|
@@ -12868,6 +12907,11 @@ var ValueNode = class extends BaseAstNode {
|
|
|
12868
12907
|
this.setValue(StringValueObject.create(tokenTrim.slice(1, -1).replace(/""/g, "\"")).withDateSystem(dateSystem));
|
|
12869
12908
|
return;
|
|
12870
12909
|
}
|
|
12910
|
+
const numberLiteral = ValueObjectFactory.createNumberLiteral(tokenTrim, dateSystem);
|
|
12911
|
+
if (numberLiteral) {
|
|
12912
|
+
this.setValue(numberLiteral);
|
|
12913
|
+
return;
|
|
12914
|
+
}
|
|
12871
12915
|
const parent = this.getParent();
|
|
12872
12916
|
let isIgnoreNumberPattern = true;
|
|
12873
12917
|
if ((parent === null || parent === void 0 ? void 0 : parent.nodeType) === 4) {
|
|
@@ -30077,7 +30121,8 @@ var Isblank = class extends BaseFunction {
|
|
|
30077
30121
|
}
|
|
30078
30122
|
calculate(value) {
|
|
30079
30123
|
if (value instanceof BaseReferenceObject) {
|
|
30080
|
-
const
|
|
30124
|
+
const { startRow, startColumn } = value.getRangePosition();
|
|
30125
|
+
const array = value.toArrayValueObject(false).mapValue((valueObject, row, column) => BooleanValueObject.create(!valueObject.isError() && value.isCellBlank(startRow + row, startColumn + column)));
|
|
30081
30126
|
return array.getRowCount() === 1 && array.getColumnCount() === 1 ? array.getFirstCell() : array;
|
|
30082
30127
|
}
|
|
30083
30128
|
if (value.isNull()) return BooleanValueObject.create(true);
|
|
@@ -33644,7 +33689,7 @@ var Unique = class extends BaseFunction {
|
|
|
33644
33689
|
const valueObject = item.valueObject;
|
|
33645
33690
|
let value = valueObject.getValue();
|
|
33646
33691
|
if (valueObject.isNull()) value = null;
|
|
33647
|
-
else if (valueObject.isString()
|
|
33692
|
+
else if (valueObject.isString()) value = (0, _univerjs_core.isRealNum)(value) ? +value : normalizeTextForComparison(value);
|
|
33648
33693
|
if (!valueMap.has(value)) valueMap.set(value, [r]);
|
|
33649
33694
|
else {
|
|
33650
33695
|
const valueMapItem = valueMap.get(value);
|
|
@@ -37476,7 +37521,7 @@ var Average = class extends BaseFunction {
|
|
|
37476
37521
|
_legacyImplicitDerivedArray(variant) {
|
|
37477
37522
|
if (!variant.isArray()) return variant;
|
|
37478
37523
|
const array = variant;
|
|
37479
|
-
if (array.usesInvertedIndexCache()) return variant;
|
|
37524
|
+
if (array.usesInvertedIndexCache() || !array.usesLegacyImplicitForAggregate()) return variant;
|
|
37480
37525
|
const startRow = array.getCurrentRow();
|
|
37481
37526
|
const startColumn = array.getCurrentColumn();
|
|
37482
37527
|
if (startRow < 0 || startColumn < 0) return variant;
|
|
@@ -42095,7 +42140,7 @@ var Proper = class extends BaseFunction {
|
|
|
42095
42140
|
}
|
|
42096
42141
|
_handleSingleObject(text) {
|
|
42097
42142
|
if (text.isError() || text.isNull() || text.isBoolean() || text.isNumber()) return text;
|
|
42098
|
-
const result = text.getValue().toLocaleString().toLocaleLowerCase().replace(/(
|
|
42143
|
+
const result = text.getValue().toLocaleString().toLocaleLowerCase().replace(/(^|[^\p{L}])(\p{L})/gu, (_, before, letter) => before + letter.toLocaleUpperCase());
|
|
42099
42144
|
return StringValueObject.create(result);
|
|
42100
42145
|
}
|
|
42101
42146
|
};
|
|
@@ -44044,7 +44089,7 @@ function getObjectValue(result, isUseStrip = false) {
|
|
|
44044
44089
|
//#endregion
|
|
44045
44090
|
//#region package.json
|
|
44046
44091
|
var name = "@univerjs/engine-formula";
|
|
44047
|
-
var version = "1.
|
|
44092
|
+
var version = "1.2.0";
|
|
44048
44093
|
|
|
44049
44094
|
//#endregion
|
|
44050
44095
|
//#region src/services/global-computing-status.service.ts
|
package/lib/es/index.js
CHANGED
|
@@ -8723,7 +8723,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8723
8723
|
const row = [];
|
|
8724
8724
|
for (let c = 0; c < columnArrayCount; c++) {
|
|
8725
8725
|
const cellRaw = columnArray[c].trim();
|
|
8726
|
-
row.push(ValueObjectFactory.create(cellRaw, false, dateSystem));
|
|
8726
|
+
row.push(ValueObjectFactory.createNumberLiteral(cellRaw, dateSystem) ?? ValueObjectFactory.create(cellRaw, false, dateSystem));
|
|
8727
8727
|
}
|
|
8728
8728
|
result.push(row);
|
|
8729
8729
|
}
|
|
@@ -8748,6 +8748,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8748
8748
|
return ArrayValueObject.create(arrayValueObjectData, this.getDateSystem());
|
|
8749
8749
|
}
|
|
8750
8750
|
};
|
|
8751
|
+
const NUMBER_LITERAL_REGEX = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
8751
8752
|
var ValueObjectFactory = class {
|
|
8752
8753
|
static create(rawValue, isIgnoreNumberPattern = false, dateSystem = DateSystem.Date1900) {
|
|
8753
8754
|
if (rawValue == null) return NullValueObject.create();
|
|
@@ -8769,6 +8770,19 @@ var ValueObjectFactory = class {
|
|
|
8769
8770
|
if (typeof rawValue === "number") return createNumberValueObjectByRawValue(rawValue).withDateSystem(dateSystem);
|
|
8770
8771
|
return ErrorValueObject.create("#VALUE!");
|
|
8771
8772
|
}
|
|
8773
|
+
/**
|
|
8774
|
+
* Create a number from a number literal written in formula source, such as `12.50`, `.5`, `007` or `1E3`.
|
|
8775
|
+
* Unlike cell text, where "000123456" must stay a string, a number literal in a formula is always a number.
|
|
8776
|
+
*
|
|
8777
|
+
* @param token The unquoted token from the formula source.
|
|
8778
|
+
* @param dateSystem The workbook date system.
|
|
8779
|
+
* @returns The number value object, a NUM error on overflow, or null when the token is not a number literal.
|
|
8780
|
+
*/
|
|
8781
|
+
static createNumberLiteral(token, dateSystem = DateSystem.Date1900) {
|
|
8782
|
+
const tokenTrim = token.trim();
|
|
8783
|
+
if (!NUMBER_LITERAL_REGEX.test(tokenTrim)) return null;
|
|
8784
|
+
return createNumberValueObjectByRawValue(Number(tokenTrim)).withDateSystem(dateSystem);
|
|
8785
|
+
}
|
|
8772
8786
|
};
|
|
8773
8787
|
function isStringWrappedByDoubleQuotes(input) {
|
|
8774
8788
|
const trimmedInput = input.trim();
|
|
@@ -9144,6 +9158,16 @@ var BaseReferenceObject = class extends ObjectClassType {
|
|
|
9144
9158
|
getRuntimeFeatureCellValue(row, column) {
|
|
9145
9159
|
return getRuntimeFeatureCell(row, column, this.getSheetId(), this.getUnitId(), this._runtimeFeatureCellData);
|
|
9146
9160
|
}
|
|
9161
|
+
isCellBlank(row, column) {
|
|
9162
|
+
var _this$getCurrentActiv5, _this$getCurrentRunti, _this$getCurrentActiv6, _this$getCurrentRunti2;
|
|
9163
|
+
const cell = this.getCellData(row, column);
|
|
9164
|
+
if (!isNullCell(cell)) return false;
|
|
9165
|
+
const originalCell = (_this$getCurrentActiv5 = this.getCurrentActiveSheetData()) === null || _this$getCurrentActiv5 === void 0 ? void 0 : _this$getCurrentActiv5.cellData.getValue(row, column);
|
|
9166
|
+
if (isFormulaString(originalCell === null || originalCell === void 0 ? void 0 : originalCell.f) || isFormulaId(originalCell === null || originalCell === void 0 ? void 0 : originalCell.si)) return false;
|
|
9167
|
+
if (!cell) return true;
|
|
9168
|
+
if (cell === ((_this$getCurrentRunti = this.getCurrentRuntimeActiveArrayFormulaCellData()) === null || _this$getCurrentRunti === void 0 ? void 0 : _this$getCurrentRunti.getValue(row, column)) || cell === ((_this$getCurrentActiv6 = this.getCurrentActiveArrayFormulaCellData()) === null || _this$getCurrentActiv6 === void 0 ? void 0 : _this$getCurrentActiv6.getValue(row, column)) || cell === this.getRuntimeFeatureCellValue(row, column)) return false;
|
|
9169
|
+
return originalCell != null || cell !== ((_this$getCurrentRunti2 = this.getCurrentRuntimeSheetData()) === null || _this$getCurrentRunti2 === void 0 ? void 0 : _this$getCurrentRunti2.getValue(row, column));
|
|
9170
|
+
}
|
|
9147
9171
|
getCellByPosition(rowRaw, columnRaw) {
|
|
9148
9172
|
const range = this.getRangePosition();
|
|
9149
9173
|
const row = rowRaw ?? range.startRow;
|
|
@@ -12824,6 +12848,21 @@ UnionNodeFactory = __decorate([__decorateParam(0, IFunctionService), __decorateP
|
|
|
12824
12848
|
|
|
12825
12849
|
//#endregion
|
|
12826
12850
|
//#region src/engine/ast-node/value-node.ts
|
|
12851
|
+
/**
|
|
12852
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
12853
|
+
*
|
|
12854
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12855
|
+
* you may not use this file except in compliance with the License.
|
|
12856
|
+
* You may obtain a copy of the License at
|
|
12857
|
+
*
|
|
12858
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12859
|
+
*
|
|
12860
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12861
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12862
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12863
|
+
* See the License for the specific language governing permissions and
|
|
12864
|
+
* limitations under the License.
|
|
12865
|
+
*/
|
|
12827
12866
|
var ValueNode = class extends BaseAstNode {
|
|
12828
12867
|
constructor(operatorString) {
|
|
12829
12868
|
super(operatorString);
|
|
@@ -12838,6 +12877,11 @@ var ValueNode = class extends BaseAstNode {
|
|
|
12838
12877
|
this.setValue(StringValueObject.create(tokenTrim.slice(1, -1).replace(/""/g, "\"")).withDateSystem(dateSystem));
|
|
12839
12878
|
return;
|
|
12840
12879
|
}
|
|
12880
|
+
const numberLiteral = ValueObjectFactory.createNumberLiteral(tokenTrim, dateSystem);
|
|
12881
|
+
if (numberLiteral) {
|
|
12882
|
+
this.setValue(numberLiteral);
|
|
12883
|
+
return;
|
|
12884
|
+
}
|
|
12841
12885
|
const parent = this.getParent();
|
|
12842
12886
|
let isIgnoreNumberPattern = true;
|
|
12843
12887
|
if ((parent === null || parent === void 0 ? void 0 : parent.nodeType) === 4) {
|
|
@@ -30047,7 +30091,8 @@ var Isblank = class extends BaseFunction {
|
|
|
30047
30091
|
}
|
|
30048
30092
|
calculate(value) {
|
|
30049
30093
|
if (value instanceof BaseReferenceObject) {
|
|
30050
|
-
const
|
|
30094
|
+
const { startRow, startColumn } = value.getRangePosition();
|
|
30095
|
+
const array = value.toArrayValueObject(false).mapValue((valueObject, row, column) => BooleanValueObject.create(!valueObject.isError() && value.isCellBlank(startRow + row, startColumn + column)));
|
|
30051
30096
|
return array.getRowCount() === 1 && array.getColumnCount() === 1 ? array.getFirstCell() : array;
|
|
30052
30097
|
}
|
|
30053
30098
|
if (value.isNull()) return BooleanValueObject.create(true);
|
|
@@ -33614,7 +33659,7 @@ var Unique = class extends BaseFunction {
|
|
|
33614
33659
|
const valueObject = item.valueObject;
|
|
33615
33660
|
let value = valueObject.getValue();
|
|
33616
33661
|
if (valueObject.isNull()) value = null;
|
|
33617
|
-
else if (valueObject.isString()
|
|
33662
|
+
else if (valueObject.isString()) value = isRealNum(value) ? +value : normalizeTextForComparison(value);
|
|
33618
33663
|
if (!valueMap.has(value)) valueMap.set(value, [r]);
|
|
33619
33664
|
else {
|
|
33620
33665
|
const valueMapItem = valueMap.get(value);
|
|
@@ -37446,7 +37491,7 @@ var Average = class extends BaseFunction {
|
|
|
37446
37491
|
_legacyImplicitDerivedArray(variant) {
|
|
37447
37492
|
if (!variant.isArray()) return variant;
|
|
37448
37493
|
const array = variant;
|
|
37449
|
-
if (array.usesInvertedIndexCache()) return variant;
|
|
37494
|
+
if (array.usesInvertedIndexCache() || !array.usesLegacyImplicitForAggregate()) return variant;
|
|
37450
37495
|
const startRow = array.getCurrentRow();
|
|
37451
37496
|
const startColumn = array.getCurrentColumn();
|
|
37452
37497
|
if (startRow < 0 || startColumn < 0) return variant;
|
|
@@ -42065,7 +42110,7 @@ var Proper = class extends BaseFunction {
|
|
|
42065
42110
|
}
|
|
42066
42111
|
_handleSingleObject(text) {
|
|
42067
42112
|
if (text.isError() || text.isNull() || text.isBoolean() || text.isNumber()) return text;
|
|
42068
|
-
const result = text.getValue().toLocaleString().toLocaleLowerCase().replace(/(
|
|
42113
|
+
const result = text.getValue().toLocaleString().toLocaleLowerCase().replace(/(^|[^\p{L}])(\p{L})/gu, (_, before, letter) => before + letter.toLocaleUpperCase());
|
|
42069
42114
|
return StringValueObject.create(result);
|
|
42070
42115
|
}
|
|
42071
42116
|
};
|
|
@@ -44014,7 +44059,7 @@ function getObjectValue(result, isUseStrip = false) {
|
|
|
44014
44059
|
//#endregion
|
|
44015
44060
|
//#region package.json
|
|
44016
44061
|
var name = "@univerjs/engine-formula";
|
|
44017
|
-
var version = "1.
|
|
44062
|
+
var version = "1.2.0";
|
|
44018
44063
|
|
|
44019
44064
|
//#endregion
|
|
44020
44065
|
//#region src/services/global-computing-status.service.ts
|
package/lib/index.js
CHANGED
|
@@ -8723,7 +8723,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8723
8723
|
const row = [];
|
|
8724
8724
|
for (let c = 0; c < columnArrayCount; c++) {
|
|
8725
8725
|
const cellRaw = columnArray[c].trim();
|
|
8726
|
-
row.push(ValueObjectFactory.create(cellRaw, false, dateSystem));
|
|
8726
|
+
row.push(ValueObjectFactory.createNumberLiteral(cellRaw, dateSystem) ?? ValueObjectFactory.create(cellRaw, false, dateSystem));
|
|
8727
8727
|
}
|
|
8728
8728
|
result.push(row);
|
|
8729
8729
|
}
|
|
@@ -8748,6 +8748,7 @@ var ArrayValueObject = class ArrayValueObject extends BaseValueObject {
|
|
|
8748
8748
|
return ArrayValueObject.create(arrayValueObjectData, this.getDateSystem());
|
|
8749
8749
|
}
|
|
8750
8750
|
};
|
|
8751
|
+
const NUMBER_LITERAL_REGEX = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
8751
8752
|
var ValueObjectFactory = class {
|
|
8752
8753
|
static create(rawValue, isIgnoreNumberPattern = false, dateSystem = DateSystem.Date1900) {
|
|
8753
8754
|
if (rawValue == null) return NullValueObject.create();
|
|
@@ -8769,6 +8770,19 @@ var ValueObjectFactory = class {
|
|
|
8769
8770
|
if (typeof rawValue === "number") return createNumberValueObjectByRawValue(rawValue).withDateSystem(dateSystem);
|
|
8770
8771
|
return ErrorValueObject.create("#VALUE!");
|
|
8771
8772
|
}
|
|
8773
|
+
/**
|
|
8774
|
+
* Create a number from a number literal written in formula source, such as `12.50`, `.5`, `007` or `1E3`.
|
|
8775
|
+
* Unlike cell text, where "000123456" must stay a string, a number literal in a formula is always a number.
|
|
8776
|
+
*
|
|
8777
|
+
* @param token The unquoted token from the formula source.
|
|
8778
|
+
* @param dateSystem The workbook date system.
|
|
8779
|
+
* @returns The number value object, a NUM error on overflow, or null when the token is not a number literal.
|
|
8780
|
+
*/
|
|
8781
|
+
static createNumberLiteral(token, dateSystem = DateSystem.Date1900) {
|
|
8782
|
+
const tokenTrim = token.trim();
|
|
8783
|
+
if (!NUMBER_LITERAL_REGEX.test(tokenTrim)) return null;
|
|
8784
|
+
return createNumberValueObjectByRawValue(Number(tokenTrim)).withDateSystem(dateSystem);
|
|
8785
|
+
}
|
|
8772
8786
|
};
|
|
8773
8787
|
function isStringWrappedByDoubleQuotes(input) {
|
|
8774
8788
|
const trimmedInput = input.trim();
|
|
@@ -9144,6 +9158,16 @@ var BaseReferenceObject = class extends ObjectClassType {
|
|
|
9144
9158
|
getRuntimeFeatureCellValue(row, column) {
|
|
9145
9159
|
return getRuntimeFeatureCell(row, column, this.getSheetId(), this.getUnitId(), this._runtimeFeatureCellData);
|
|
9146
9160
|
}
|
|
9161
|
+
isCellBlank(row, column) {
|
|
9162
|
+
var _this$getCurrentActiv5, _this$getCurrentRunti, _this$getCurrentActiv6, _this$getCurrentRunti2;
|
|
9163
|
+
const cell = this.getCellData(row, column);
|
|
9164
|
+
if (!isNullCell(cell)) return false;
|
|
9165
|
+
const originalCell = (_this$getCurrentActiv5 = this.getCurrentActiveSheetData()) === null || _this$getCurrentActiv5 === void 0 ? void 0 : _this$getCurrentActiv5.cellData.getValue(row, column);
|
|
9166
|
+
if (isFormulaString(originalCell === null || originalCell === void 0 ? void 0 : originalCell.f) || isFormulaId(originalCell === null || originalCell === void 0 ? void 0 : originalCell.si)) return false;
|
|
9167
|
+
if (!cell) return true;
|
|
9168
|
+
if (cell === ((_this$getCurrentRunti = this.getCurrentRuntimeActiveArrayFormulaCellData()) === null || _this$getCurrentRunti === void 0 ? void 0 : _this$getCurrentRunti.getValue(row, column)) || cell === ((_this$getCurrentActiv6 = this.getCurrentActiveArrayFormulaCellData()) === null || _this$getCurrentActiv6 === void 0 ? void 0 : _this$getCurrentActiv6.getValue(row, column)) || cell === this.getRuntimeFeatureCellValue(row, column)) return false;
|
|
9169
|
+
return originalCell != null || cell !== ((_this$getCurrentRunti2 = this.getCurrentRuntimeSheetData()) === null || _this$getCurrentRunti2 === void 0 ? void 0 : _this$getCurrentRunti2.getValue(row, column));
|
|
9170
|
+
}
|
|
9147
9171
|
getCellByPosition(rowRaw, columnRaw) {
|
|
9148
9172
|
const range = this.getRangePosition();
|
|
9149
9173
|
const row = rowRaw ?? range.startRow;
|
|
@@ -12824,6 +12848,21 @@ UnionNodeFactory = __decorate([__decorateParam(0, IFunctionService), __decorateP
|
|
|
12824
12848
|
|
|
12825
12849
|
//#endregion
|
|
12826
12850
|
//#region src/engine/ast-node/value-node.ts
|
|
12851
|
+
/**
|
|
12852
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
12853
|
+
*
|
|
12854
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12855
|
+
* you may not use this file except in compliance with the License.
|
|
12856
|
+
* You may obtain a copy of the License at
|
|
12857
|
+
*
|
|
12858
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12859
|
+
*
|
|
12860
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12861
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12862
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12863
|
+
* See the License for the specific language governing permissions and
|
|
12864
|
+
* limitations under the License.
|
|
12865
|
+
*/
|
|
12827
12866
|
var ValueNode = class extends BaseAstNode {
|
|
12828
12867
|
constructor(operatorString) {
|
|
12829
12868
|
super(operatorString);
|
|
@@ -12838,6 +12877,11 @@ var ValueNode = class extends BaseAstNode {
|
|
|
12838
12877
|
this.setValue(StringValueObject.create(tokenTrim.slice(1, -1).replace(/""/g, "\"")).withDateSystem(dateSystem));
|
|
12839
12878
|
return;
|
|
12840
12879
|
}
|
|
12880
|
+
const numberLiteral = ValueObjectFactory.createNumberLiteral(tokenTrim, dateSystem);
|
|
12881
|
+
if (numberLiteral) {
|
|
12882
|
+
this.setValue(numberLiteral);
|
|
12883
|
+
return;
|
|
12884
|
+
}
|
|
12841
12885
|
const parent = this.getParent();
|
|
12842
12886
|
let isIgnoreNumberPattern = true;
|
|
12843
12887
|
if ((parent === null || parent === void 0 ? void 0 : parent.nodeType) === 4) {
|
|
@@ -30047,7 +30091,8 @@ var Isblank = class extends BaseFunction {
|
|
|
30047
30091
|
}
|
|
30048
30092
|
calculate(value) {
|
|
30049
30093
|
if (value instanceof BaseReferenceObject) {
|
|
30050
|
-
const
|
|
30094
|
+
const { startRow, startColumn } = value.getRangePosition();
|
|
30095
|
+
const array = value.toArrayValueObject(false).mapValue((valueObject, row, column) => BooleanValueObject.create(!valueObject.isError() && value.isCellBlank(startRow + row, startColumn + column)));
|
|
30051
30096
|
return array.getRowCount() === 1 && array.getColumnCount() === 1 ? array.getFirstCell() : array;
|
|
30052
30097
|
}
|
|
30053
30098
|
if (value.isNull()) return BooleanValueObject.create(true);
|
|
@@ -33614,7 +33659,7 @@ var Unique = class extends BaseFunction {
|
|
|
33614
33659
|
const valueObject = item.valueObject;
|
|
33615
33660
|
let value = valueObject.getValue();
|
|
33616
33661
|
if (valueObject.isNull()) value = null;
|
|
33617
|
-
else if (valueObject.isString()
|
|
33662
|
+
else if (valueObject.isString()) value = isRealNum(value) ? +value : normalizeTextForComparison(value);
|
|
33618
33663
|
if (!valueMap.has(value)) valueMap.set(value, [r]);
|
|
33619
33664
|
else {
|
|
33620
33665
|
const valueMapItem = valueMap.get(value);
|
|
@@ -37446,7 +37491,7 @@ var Average = class extends BaseFunction {
|
|
|
37446
37491
|
_legacyImplicitDerivedArray(variant) {
|
|
37447
37492
|
if (!variant.isArray()) return variant;
|
|
37448
37493
|
const array = variant;
|
|
37449
|
-
if (array.usesInvertedIndexCache()) return variant;
|
|
37494
|
+
if (array.usesInvertedIndexCache() || !array.usesLegacyImplicitForAggregate()) return variant;
|
|
37450
37495
|
const startRow = array.getCurrentRow();
|
|
37451
37496
|
const startColumn = array.getCurrentColumn();
|
|
37452
37497
|
if (startRow < 0 || startColumn < 0) return variant;
|
|
@@ -42065,7 +42110,7 @@ var Proper = class extends BaseFunction {
|
|
|
42065
42110
|
}
|
|
42066
42111
|
_handleSingleObject(text) {
|
|
42067
42112
|
if (text.isError() || text.isNull() || text.isBoolean() || text.isNumber()) return text;
|
|
42068
|
-
const result = text.getValue().toLocaleString().toLocaleLowerCase().replace(/(
|
|
42113
|
+
const result = text.getValue().toLocaleString().toLocaleLowerCase().replace(/(^|[^\p{L}])(\p{L})/gu, (_, before, letter) => before + letter.toLocaleUpperCase());
|
|
42069
42114
|
return StringValueObject.create(result);
|
|
42070
42115
|
}
|
|
42071
42116
|
};
|
|
@@ -44014,7 +44059,7 @@ function getObjectValue(result, isUseStrip = false) {
|
|
|
44014
44059
|
//#endregion
|
|
44015
44060
|
//#region package.json
|
|
44016
44061
|
var name = "@univerjs/engine-formula";
|
|
44017
|
-
var version = "1.
|
|
44062
|
+
var version = "1.2.0";
|
|
44018
44063
|
|
|
44019
44064
|
//#endregion
|
|
44020
44065
|
//#region src/services/global-computing-status.service.ts
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import type { ICellData, IRange, IUnitRange, Nullable } from '@univerjs/core';
|
|
17
|
+
import { DateSystem, ObjectMatrix } from '@univerjs/core';
|
|
17
18
|
import type { IArrayFormulaRangeType, IRuntimeUnitDataType, IUnitData, IUnitSheetNameMap, IUnitStylesData } from '../../basics/common';
|
|
18
19
|
import type { BaseValueObject } from '../value-object/base-value-object';
|
|
19
|
-
import { DateSystem, ObjectMatrix } from '@univerjs/core';
|
|
20
20
|
import { FormulaAstLRU } from '../../basics/cache-lru';
|
|
21
21
|
import { ObjectClassType } from '../../basics/object-class-type';
|
|
22
22
|
import { ArrayValueObject } from '../value-object/array-value-object';
|
|
@@ -130,6 +130,7 @@ export declare class BaseReferenceObject extends ObjectClassType {
|
|
|
130
130
|
getCurrentRuntimeActiveArrayFormulaRange(): import("@univerjs/core").IObjectMatrixPrimitiveType<IRange> | undefined;
|
|
131
131
|
getCellData(row: number, column: number): Nullable<ICellData>;
|
|
132
132
|
getRuntimeFeatureCellValue(row: number, column: number): ICellData | undefined;
|
|
133
|
+
isCellBlank(row: number, column: number): boolean;
|
|
133
134
|
getCellByPosition(rowRaw?: number, columnRaw?: number): BaseValueObject;
|
|
134
135
|
setCurrentRowAndColumn(row: number, column: number): void;
|
|
135
136
|
getCurrentRow(): number | undefined;
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import type { Nullable } from '@univerjs/core';
|
|
17
|
-
import type { callbackMapFnType, IArrayValueObject } from './base-value-object';
|
|
18
17
|
import { DateSystem } from '@univerjs/core';
|
|
18
|
+
import type { callbackMapFnType, IArrayValueObject } from './base-value-object';
|
|
19
19
|
import { compareToken } from '../../basics/token';
|
|
20
20
|
import { ArrayBinarySearchType, ArrayOrderSearchType } from '../utils/compare';
|
|
21
21
|
import { BaseValueObject } from './base-value-object';
|
|
@@ -253,4 +253,13 @@ export declare class ArrayValueObject extends BaseValueObject {
|
|
|
253
253
|
}
|
|
254
254
|
export declare class ValueObjectFactory {
|
|
255
255
|
static create(rawValue: string | number | boolean | null, isIgnoreNumberPattern?: boolean, dateSystem?: DateSystem): BaseValueObject;
|
|
256
|
+
/**
|
|
257
|
+
* Create a number from a number literal written in formula source, such as `12.50`, `.5`, `007` or `1E3`.
|
|
258
|
+
* Unlike cell text, where "000123456" must stay a string, a number literal in a formula is always a number.
|
|
259
|
+
*
|
|
260
|
+
* @param token The unquoted token from the formula source.
|
|
261
|
+
* @param dateSystem The workbook date system.
|
|
262
|
+
* @returns The number value object, a NUM error on overflow, or null when the token is not a number literal.
|
|
263
|
+
*/
|
|
264
|
+
static createNumberLiteral(token: string, dateSystem?: DateSystem): Nullable<BaseValueObject>;
|
|
256
265
|
}
|