@univerjs/engine-formula 0.4.0-alpha.1 → 0.4.0-experimental.d7288c0-20241017
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 +59 -20
- package/lib/types/engine/value-object/primitive-object.d.ts +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +4 -4
- package/LICENSE +0 -176
package/lib/es/index.js
CHANGED
|
@@ -263,7 +263,7 @@ function deserializeRangeWithSheet(refString) {
|
|
|
263
263
|
}
|
|
264
264
|
};
|
|
265
265
|
}
|
|
266
|
-
const refStartString = refBody.substring(0, colonIndex), refEndString = refBody.substring(colonIndex + 1), startGrid = singleReferenceToGrid(refStartString), endGrid = singleReferenceToGrid(refEndString), startRow = startGrid.row, startColumn = startGrid.column, endRow = endGrid.row, endColumn = endGrid.column;
|
|
266
|
+
const refStartString = refBody.substring(0, colonIndex), refEndString = refBody.substring(colonIndex + 1), startGrid = singleReferenceToGrid(refStartString), endGrid = singleReferenceToGrid(refEndString), startRow = startGrid.row > endGrid.row ? endGrid.row : startGrid.row, startColumn = startGrid.column > endGrid.column ? endGrid.column : startGrid.column, endRow = startGrid.row > endGrid.row ? startGrid.row : endGrid.row, endColumn = startGrid.column > endGrid.column ? startGrid.column : endGrid.column;
|
|
267
267
|
let rangeType = RANGE_TYPE.NORMAL;
|
|
268
268
|
return Number.isNaN(startRow) && Number.isNaN(endRow) ? rangeType = RANGE_TYPE.COLUMN : Number.isNaN(startColumn) && Number.isNaN(endColumn) && (rangeType = RANGE_TYPE.ROW), {
|
|
269
269
|
unitId,
|
|
@@ -4353,16 +4353,21 @@ const NUMBER_CACHE_LRU_COUNT = 2e5, NumberValueObjectCache = new FormulaAstLRU(N
|
|
|
4353
4353
|
pow(valueObject) {
|
|
4354
4354
|
if (valueObject.isArray())
|
|
4355
4355
|
return valueObject.powInverse(this);
|
|
4356
|
-
|
|
4357
|
-
|
|
4356
|
+
if (this.isError())
|
|
4357
|
+
return this;
|
|
4358
|
+
const currentValue = this.getValue();
|
|
4359
|
+
let _valueObject = valueObject;
|
|
4360
|
+
if (valueObject.isString() && (_valueObject = valueObject.convertToNumberObjectValue()), _valueObject.isError())
|
|
4361
|
+
return _valueObject;
|
|
4362
|
+
const value = +_valueObject.getValue();
|
|
4363
|
+
if (Number.isNaN(value))
|
|
4358
4364
|
return ErrorValueObject.create(ErrorType$1.VALUE);
|
|
4359
|
-
if (
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
return typeof value == "boolean" ? _NumberValueObject.create(pow(currentValue, value ? 1 : 0)) : this;
|
|
4365
|
+
if (!Number.isFinite(currentValue) || !Number.isFinite(value))
|
|
4366
|
+
return ErrorValueObject.create(ErrorType$1.NUM);
|
|
4367
|
+
if (currentValue === 0)
|
|
4368
|
+
return value < 0 ? ErrorValueObject.create(ErrorType$1.DIV_BY_ZERO) : value === 0 ? ErrorValueObject.create(ErrorType$1.NUM) : _NumberValueObject.create(0);
|
|
4369
|
+
const result = pow(currentValue, value);
|
|
4370
|
+
return Number.isFinite(result) ? _NumberValueObject.create(result) : ErrorValueObject.create(ErrorType$1.NUM);
|
|
4366
4371
|
}
|
|
4367
4372
|
sqrt() {
|
|
4368
4373
|
const currentValue = this.getValue();
|
|
@@ -5478,6 +5483,8 @@ const _ArrayValueObject = class _ArrayValueObject extends BaseValueObject {
|
|
|
5478
5483
|
valueObject.getValue()
|
|
5479
5484
|
);
|
|
5480
5485
|
rowPositions != null && rowPositions.forEach((row) => {
|
|
5486
|
+
if (row < startRow || row > startRow + rowCount - 1)
|
|
5487
|
+
return;
|
|
5481
5488
|
const r = row - startRow;
|
|
5482
5489
|
result[r] == null && (result[r] = []), result[r][column] = BooleanValueObject.create(!0);
|
|
5483
5490
|
});
|
|
@@ -6079,7 +6086,13 @@ let FormulaRuntimeService = (_a5 = class extends Disposable {
|
|
|
6079
6086
|
const objectValueRefOrArray = functionVariant, { startRow, startColumn, endRow, endColumn } = objectValueRefOrArray.getRangePosition();
|
|
6080
6087
|
if (startRow === endRow && startColumn === endColumn) {
|
|
6081
6088
|
const firstCell = objectValueRefOrArray.getFirstCell(), valueObject = objectValueToCellValue(firstCell);
|
|
6082
|
-
sheetData.setValue(row, column, valueObject), clearArrayUnitData.setValue(row, column, valueObject)
|
|
6089
|
+
sheetData.setValue(row, column, valueObject), clearArrayUnitData.setValue(row, column, valueObject), CELL_INVERTED_INDEX_CACHE.set(
|
|
6090
|
+
unitId,
|
|
6091
|
+
sheetId,
|
|
6092
|
+
column,
|
|
6093
|
+
firstCell.getValue(),
|
|
6094
|
+
row
|
|
6095
|
+
);
|
|
6083
6096
|
return;
|
|
6084
6097
|
}
|
|
6085
6098
|
const arrayRange = {
|
|
@@ -6090,7 +6103,13 @@ let FormulaRuntimeService = (_a5 = class extends Disposable {
|
|
|
6090
6103
|
};
|
|
6091
6104
|
if (arrayData.setValue(row, column, arrayRange), arrayFormulaRange[sheetId] = arrayData.getData(), this._checkIfArrayFormulaRangeHasData(unitId, sheetId, row, column, arrayRange) || this._checkIfArrayFormulaExceeded(rowCount, columnCount, arrayRange)) {
|
|
6092
6105
|
const errorObject = objectValueToCellValue(ErrorValueObject.create(ErrorType$1.SPILL));
|
|
6093
|
-
sheetData.setValue(row, column, errorObject), clearArrayUnitData.setValue(row, column, errorObject)
|
|
6106
|
+
sheetData.setValue(row, column, errorObject), clearArrayUnitData.setValue(row, column, errorObject), CELL_INVERTED_INDEX_CACHE.set(
|
|
6107
|
+
unitId,
|
|
6108
|
+
sheetId,
|
|
6109
|
+
column,
|
|
6110
|
+
ErrorType$1.SPILL,
|
|
6111
|
+
row
|
|
6112
|
+
);
|
|
6094
6113
|
const unitData2 = this._currentConfigService.getUnitData();
|
|
6095
6114
|
objectValueRefOrArray.iterator((_, rowIndex, columnIndex) => {
|
|
6096
6115
|
var _a27, _b;
|
|
@@ -6108,6 +6127,13 @@ let FormulaRuntimeService = (_a5 = class extends Disposable {
|
|
|
6108
6127
|
} else {
|
|
6109
6128
|
const spillError = ErrorValueObject.create(ErrorType$1.SPILL);
|
|
6110
6129
|
objectValueRefOrArray.iterator((valueObject, rowIndex, columnIndex) => {
|
|
6130
|
+
CELL_INVERTED_INDEX_CACHE.set(
|
|
6131
|
+
unitId,
|
|
6132
|
+
sheetId,
|
|
6133
|
+
column - startColumn + columnIndex,
|
|
6134
|
+
valueObject ? valueObject.getValue() : 0,
|
|
6135
|
+
row - startRow + rowIndex
|
|
6136
|
+
);
|
|
6111
6137
|
const value = objectValueToCellValue(valueObject);
|
|
6112
6138
|
if (rowIndex === startRow && columnIndex === startColumn) {
|
|
6113
6139
|
if (valueObject != null && valueObject.isError() && valueObject.isEqualType(spillError))
|
|
@@ -6120,7 +6146,13 @@ let FormulaRuntimeService = (_a5 = class extends Disposable {
|
|
|
6120
6146
|
}
|
|
6121
6147
|
} else {
|
|
6122
6148
|
const valueObject = objectValueToCellValue(functionVariant);
|
|
6123
|
-
sheetData.setValue(row, column, valueObject),
|
|
6149
|
+
sheetData.setValue(row, column, valueObject), CELL_INVERTED_INDEX_CACHE.set(
|
|
6150
|
+
unitId,
|
|
6151
|
+
sheetId,
|
|
6152
|
+
column,
|
|
6153
|
+
functionVariant.getValue(),
|
|
6154
|
+
row
|
|
6155
|
+
), clearArrayUnitData.setValue(row, column, valueObject);
|
|
6124
6156
|
}
|
|
6125
6157
|
}
|
|
6126
6158
|
getUnitData() {
|
|
@@ -11401,23 +11433,30 @@ const _Datedif = class _Datedif extends BaseFunction {
|
|
|
11401
11433
|
}
|
|
11402
11434
|
_getResultByUnit(startDateSerialNumber, endDateSerialNumber, unit) {
|
|
11403
11435
|
const startDateDate = excelSerialToDate(startDateSerialNumber), startYear = startDateDate.getUTCFullYear(), startMonth = startDateDate.getUTCMonth() + 1, startDay = startDateDate.getUTCDate(), endDateDate = excelSerialToDate(endDateSerialNumber), endYear = endDateDate.getUTCFullYear(), endMonth = endDateDate.getUTCMonth() + 1, endDay = endDateDate.getUTCDate(), unitValue = `${unit.getValue()}`.toLocaleUpperCase();
|
|
11404
|
-
let
|
|
11436
|
+
let diff = 0, newDate;
|
|
11405
11437
|
switch (unitValue) {
|
|
11406
11438
|
case "Y":
|
|
11407
|
-
|
|
11439
|
+
diff = endYear - startYear, (endMonth < startMonth || endMonth === startMonth && endDay < startDay) && (diff -= 1);
|
|
11440
|
+
break;
|
|
11408
11441
|
case "M":
|
|
11409
|
-
|
|
11442
|
+
diff = (endYear - startYear) * 12 + endMonth - startMonth, endDay < startDay && (diff -= 1);
|
|
11443
|
+
break;
|
|
11410
11444
|
case "D":
|
|
11411
|
-
|
|
11445
|
+
diff = Math.floor(endDateSerialNumber) - Math.floor(startDateSerialNumber);
|
|
11446
|
+
break;
|
|
11412
11447
|
case "MD":
|
|
11413
|
-
|
|
11448
|
+
diff = endDay - startDay, endDay < startDay && (newDate = new Date(Date.UTC(endYear, endMonth - 1, 0)), diff += getDaysInMonth(newDate.getUTCFullYear(), newDate.getUTCMonth()));
|
|
11449
|
+
break;
|
|
11414
11450
|
case "YM":
|
|
11415
|
-
|
|
11451
|
+
diff = endMonth - startMonth, (endMonth < startMonth || endMonth === startMonth && endDay < startDay) && (diff += 12), endDay < startDay && (diff -= 1);
|
|
11452
|
+
break;
|
|
11416
11453
|
case "YD":
|
|
11417
|
-
|
|
11454
|
+
newDate = new Date(Date.UTC(startYear, endMonth - 1, endDay)), (endMonth < startMonth || endMonth === startMonth && endDay < startDay) && (newDate = new Date(Date.UTC(startYear + 1, endMonth - 1, endDay))), diff = Math.floor(excelDateSerial(newDate)) - Math.floor(startDateSerialNumber);
|
|
11455
|
+
break;
|
|
11418
11456
|
default:
|
|
11419
11457
|
return ErrorValueObject.create(ErrorType$1.NUM);
|
|
11420
11458
|
}
|
|
11459
|
+
return NumberValueObject.create(diff);
|
|
11421
11460
|
}
|
|
11422
11461
|
};
|
|
11423
11462
|
__name(_Datedif, "Datedif");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { compareToken } from '../../basics/token';
|
|
2
1
|
import { FormulaAstLRU } from '../../basics/cache-lru';
|
|
2
|
+
import { compareToken } from '../../basics/token';
|
|
3
3
|
import { BaseValueObject, ErrorValueObject } from './base-value-object';
|
|
4
4
|
export type PrimitiveValueType = string | boolean | number | null;
|
|
5
5
|
export declare class NullValueObject extends BaseValueObject {
|