@univerjs/engine-formula 0.25.0 → 1.0.0-alpha.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/facade.js +2 -2
- package/lib/cjs/index.js +228 -26
- package/lib/es/facade.js +2 -2
- package/lib/es/index.js +229 -27
- package/lib/facade.js +2 -2
- package/lib/index.js +229 -27
- package/lib/types/index.d.ts +40 -25
- package/lib/umd/index.js +2 -2
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbsoluteRefType, AsyncLock, BooleanNumber, BuildTextUtils, CellValueType, CommandType, DataStreamTreeTokenType, Disposable, DisposableCollection, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, LRUMap, LifecycleService, LocaleService, LocaleType, MAX_COLUMN_COUNT, MAX_ROW_COUNT, ObjectMatrix, Optional, Plugin, RANGE_TYPE, RTree, Rectangle, RichTextBuilder, Tools, UniverInstanceType, cellToRange, columnLabelToNumber, createIdentifier, escapeRegExp, generateRandomId, getNumfmtParseValueFilter, hashAlgorithm, isFormulaId, isFormulaString, isNullCell, isRealNum, isTextFormat, isValidRange, merge, moveRangeByOffset, numfmt, requestImmediateMacroTask, sortRules, toDisposable, touchDependencies } from "@univerjs/core";
|
|
1
|
+
import { AbsoluteRefType, AsyncLock, BooleanNumber, BuildTextUtils, CellValueType, CommandType, DataStreamTreeTokenType, Disposable, DisposableCollection, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, LRUMap, LifecycleService, LocaleService, LocaleType, MAX_COLUMN_COUNT, MAX_ROW_COUNT, ObjectMatrix, Optional, Plugin, RANGE_TYPE, RTree, Rectangle, RichTextBuilder, Styles, Tools, UniverInstanceType, cellToRange, columnLabelToNumber, createIdentifier, escapeRegExp, generateRandomId, getNumfmtParseValueFilter, hashAlgorithm, isFormulaId, isFormulaString, isNullCell, isRealNum, isTextFormat, isValidRange, merge, moveRangeByOffset, numfmt, requestImmediateMacroTask, sortRules, toDisposable, touchDependencies } from "@univerjs/core";
|
|
2
2
|
import IntervalTree from "@flatten-js/interval-tree";
|
|
3
3
|
import { BehaviorSubject, Observable, Subject, bufferWhen, combineLatest, distinctUntilChanged, filter, map, shareReplay, skip } from "rxjs";
|
|
4
4
|
import Decimal from "decimal.js";
|
|
@@ -12,7 +12,7 @@ let BooleanValue = /* @__PURE__ */ function(BooleanValue) {
|
|
|
12
12
|
}({});
|
|
13
13
|
|
|
14
14
|
//#endregion
|
|
15
|
-
//#region \0@oxc-project+runtime@0.
|
|
15
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
16
16
|
function _typeof(o) {
|
|
17
17
|
"@babel/helpers - typeof";
|
|
18
18
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -23,7 +23,7 @@ function _typeof(o) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
//#endregion
|
|
26
|
-
//#region \0@oxc-project+runtime@0.
|
|
26
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
27
27
|
function toPrimitive(t, r) {
|
|
28
28
|
if ("object" != _typeof(t) || !t) return t;
|
|
29
29
|
var e = t[Symbol.toPrimitive];
|
|
@@ -36,14 +36,14 @@ function toPrimitive(t, r) {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
//#endregion
|
|
39
|
-
//#region \0@oxc-project+runtime@0.
|
|
39
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
40
40
|
function toPropertyKey(t) {
|
|
41
41
|
var i = toPrimitive(t, "string");
|
|
42
42
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
//#endregion
|
|
46
|
-
//#region \0@oxc-project+runtime@0.
|
|
46
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
47
47
|
function _defineProperty(e, r, t) {
|
|
48
48
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
49
49
|
value: t,
|
|
@@ -238,7 +238,7 @@ let compareToken = /* @__PURE__ */ function(compareToken) {
|
|
|
238
238
|
compareToken["LESS_THAN_OR_EQUAL"] = "<=";
|
|
239
239
|
return compareToken;
|
|
240
240
|
}({});
|
|
241
|
-
const OPERATOR_TOKEN_PRIORITY = new Map([
|
|
241
|
+
const OPERATOR_TOKEN_PRIORITY = /* @__PURE__ */ new Map([
|
|
242
242
|
["<>", 4],
|
|
243
243
|
["<", 4],
|
|
244
244
|
[">=", 4],
|
|
@@ -253,7 +253,7 @@ const OPERATOR_TOKEN_PRIORITY = new Map([
|
|
|
253
253
|
["^", 0]
|
|
254
254
|
]);
|
|
255
255
|
const OPERATOR_TOKEN_SET = new Set(OPERATOR_TOKEN_PRIORITY.keys());
|
|
256
|
-
const OPERATOR_TOKEN_COMPARE_SET = new Set([
|
|
256
|
+
const OPERATOR_TOKEN_COMPARE_SET = /* @__PURE__ */ new Set([
|
|
257
257
|
"=",
|
|
258
258
|
"<>",
|
|
259
259
|
">",
|
|
@@ -279,7 +279,7 @@ let suffixToken = /* @__PURE__ */ function(suffixToken) {
|
|
|
279
279
|
suffixToken["POUND"] = "#";
|
|
280
280
|
return suffixToken;
|
|
281
281
|
}({});
|
|
282
|
-
const SUFFIX_TOKEN_SET = new Set(["%", "#"]);
|
|
282
|
+
const SUFFIX_TOKEN_SET = /* @__PURE__ */ new Set(["%", "#"]);
|
|
283
283
|
let prefixToken = /* @__PURE__ */ function(prefixToken) {
|
|
284
284
|
prefixToken["AT"] = "@";
|
|
285
285
|
prefixToken["MINUS"] = "-";
|
|
@@ -1319,7 +1319,7 @@ function normalizeSheetName(sheetName) {
|
|
|
1319
1319
|
function matchRefDrawToken(char) {
|
|
1320
1320
|
return isFormulaLexerToken(char) && char !== "}" && char !== ")" && char !== "'" && char !== "\"" || char === " ";
|
|
1321
1321
|
}
|
|
1322
|
-
const TOKEN_CANNOT_BE_AT_END_SET = new Set([
|
|
1322
|
+
const TOKEN_CANNOT_BE_AT_END_SET = /* @__PURE__ */ new Set([
|
|
1323
1323
|
"+",
|
|
1324
1324
|
"-",
|
|
1325
1325
|
"*",
|
|
@@ -1341,7 +1341,7 @@ const TOKEN_CANNOT_BE_AT_END_SET = new Set([
|
|
|
1341
1341
|
function isTokenCannotBeAtEnd(token) {
|
|
1342
1342
|
return TOKEN_CANNOT_BE_AT_END_SET.has(token);
|
|
1343
1343
|
}
|
|
1344
|
-
const TOKEN_CANNOT_PRECEDE_SUFFIX_TOKEN_SET = new Set([
|
|
1344
|
+
const TOKEN_CANNOT_PRECEDE_SUFFIX_TOKEN_SET = /* @__PURE__ */ new Set([
|
|
1345
1345
|
"+",
|
|
1346
1346
|
"-",
|
|
1347
1347
|
"*",
|
|
@@ -1512,7 +1512,7 @@ const DEFAULT_TOKEN_TYPE_LAMBDA_OMIT_PARAMETER = "LO_1";
|
|
|
1512
1512
|
const DEFAULT_TOKEN_LET_FUNCTION_NAME = "LET";
|
|
1513
1513
|
const DEFAULT_TOKEN_LAMBDA_FUNCTION_NAME = "LAMBDA";
|
|
1514
1514
|
const DEFAULT_TOKEN_CUBE_FUNCTION_NAME = "CUBE";
|
|
1515
|
-
const FORCED_RECALCULATION_FUNCTION_NAME = new Set([
|
|
1515
|
+
const FORCED_RECALCULATION_FUNCTION_NAME = /* @__PURE__ */ new Set([
|
|
1516
1516
|
"RAND",
|
|
1517
1517
|
"RANDBETWEEN",
|
|
1518
1518
|
"NOW",
|
|
@@ -1847,7 +1847,7 @@ function splitTableStructuredRef(ref) {
|
|
|
1847
1847
|
}
|
|
1848
1848
|
|
|
1849
1849
|
//#endregion
|
|
1850
|
-
//#region \0@oxc-project+runtime@0.
|
|
1850
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
|
|
1851
1851
|
function __decorateParam(paramIndex, decorator) {
|
|
1852
1852
|
return function(target, key) {
|
|
1853
1853
|
decorator(target, key, paramIndex);
|
|
@@ -1855,7 +1855,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
1855
1855
|
}
|
|
1856
1856
|
|
|
1857
1857
|
//#endregion
|
|
1858
|
-
//#region \0@oxc-project+runtime@0.
|
|
1858
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
|
|
1859
1859
|
function __decorate(decorators, target, key, desc) {
|
|
1860
1860
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1861
1861
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2999,7 +2999,7 @@ let FUNCTION_NAMES_WEB = /* @__PURE__ */ function(FUNCTION_NAMES_WEB) {
|
|
|
2999
2999
|
|
|
3000
3000
|
//#endregion
|
|
3001
3001
|
//#region src/functions/new-excel-functions.ts
|
|
3002
|
-
const NEW_EXCEL_FUNCTIONS = new Set([
|
|
3002
|
+
const NEW_EXCEL_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
3003
3003
|
"ACOT",
|
|
3004
3004
|
"ACOTH",
|
|
3005
3005
|
"ARABIC",
|
|
@@ -4909,15 +4909,54 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
|
|
|
4909
4909
|
getFormulaData() {
|
|
4910
4910
|
const formulaData = {};
|
|
4911
4911
|
const allSheets = this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_SHEET);
|
|
4912
|
-
|
|
4913
|
-
|
|
4912
|
+
for (let i = 0; i < allSheets.length; i++) {
|
|
4913
|
+
const workbook = allSheets[i];
|
|
4914
4914
|
const unitId = workbook.getUnitId();
|
|
4915
4915
|
formulaData[unitId] = {};
|
|
4916
|
-
workbook.getSheets()
|
|
4916
|
+
const worksheets = workbook.getSheets();
|
|
4917
|
+
for (let j = 0; j < worksheets.length; j++) {
|
|
4918
|
+
const worksheet = worksheets[j];
|
|
4917
4919
|
const cellMatrix = worksheet.getCellMatrix();
|
|
4918
4920
|
initSheetFormulaData(formulaData, unitId, worksheet.getSheetId(), cellMatrix);
|
|
4919
|
-
}
|
|
4920
|
-
}
|
|
4921
|
+
}
|
|
4922
|
+
}
|
|
4923
|
+
const allBases = this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_BASE);
|
|
4924
|
+
for (let i = 0; i < allBases.length; i++) {
|
|
4925
|
+
const base = allBases[i];
|
|
4926
|
+
const snapshot = base.getSnapshot();
|
|
4927
|
+
const unitId = base.getUnitId();
|
|
4928
|
+
formulaData[unitId] = {};
|
|
4929
|
+
const tables = Object.values(snapshot.tables);
|
|
4930
|
+
for (let j = 0; j < tables.length; j++) {
|
|
4931
|
+
const table = tables[j];
|
|
4932
|
+
if (table.deleted) continue;
|
|
4933
|
+
const tableFormulaData = {};
|
|
4934
|
+
const recordOrder = table.recordOrder;
|
|
4935
|
+
if (!recordOrder) {
|
|
4936
|
+
formulaData[unitId][table.id] = tableFormulaData;
|
|
4937
|
+
continue;
|
|
4938
|
+
}
|
|
4939
|
+
for (let row = 0; row < recordOrder.length; row++) {
|
|
4940
|
+
const recordId = recordOrder[row];
|
|
4941
|
+
const record = table.records[recordId];
|
|
4942
|
+
if (!record || record.deleted) continue;
|
|
4943
|
+
for (let col = 0; col < table.fieldOrder.length; col++) {
|
|
4944
|
+
var _field$config$formula, _field$config, _row, _tableFormulaData$_ro;
|
|
4945
|
+
const fieldId = table.fieldOrder[col];
|
|
4946
|
+
const field = table.fields[fieldId];
|
|
4947
|
+
if (!field || field.deleted || field.type !== "formula") continue;
|
|
4948
|
+
const formula = String((_field$config$formula = (_field$config = field.config) === null || _field$config === void 0 ? void 0 : _field$config.formula) !== null && _field$config$formula !== void 0 ? _field$config$formula : "").trim();
|
|
4949
|
+
if (!formula) continue;
|
|
4950
|
+
(_tableFormulaData$_ro = tableFormulaData[_row = row]) !== null && _tableFormulaData$_ro !== void 0 || (tableFormulaData[_row] = {});
|
|
4951
|
+
tableFormulaData[row][col] = {
|
|
4952
|
+
f: normalizeBaseFormulaForEngine(formula, table, snapshot),
|
|
4953
|
+
si: field.id
|
|
4954
|
+
};
|
|
4955
|
+
}
|
|
4956
|
+
}
|
|
4957
|
+
formulaData[unitId][table.id] = tableFormulaData;
|
|
4958
|
+
}
|
|
4959
|
+
}
|
|
4921
4960
|
return formulaData;
|
|
4922
4961
|
}
|
|
4923
4962
|
getSheetFormulaData(unitId, sheetId) {
|
|
@@ -5021,6 +5060,33 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
|
|
|
5021
5060
|
unitStylesData[unitId] = workbook.getStyles();
|
|
5022
5061
|
unitSheetNameMap[unitId] = sheetNameMap;
|
|
5023
5062
|
}
|
|
5063
|
+
const unitAllBases = this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_BASE);
|
|
5064
|
+
for (const base of unitAllBases) {
|
|
5065
|
+
const snapshot = base.getSnapshot();
|
|
5066
|
+
const unitId = base.getUnitId();
|
|
5067
|
+
const baseData = {};
|
|
5068
|
+
const tableNameMap = {};
|
|
5069
|
+
for (const table of Object.values(snapshot.tables).filter((item) => !item.deleted)) {
|
|
5070
|
+
var _table$recordOrder$fi, _table$recordOrder;
|
|
5071
|
+
baseData[table.id] = {
|
|
5072
|
+
cellData: new ObjectMatrix(buildBaseRuntimeCellData(table)),
|
|
5073
|
+
rowCount: (_table$recordOrder$fi = (_table$recordOrder = table.recordOrder) === null || _table$recordOrder === void 0 ? void 0 : _table$recordOrder.filter((recordId) => {
|
|
5074
|
+
var _table$records$record;
|
|
5075
|
+
return !((_table$records$record = table.records[recordId]) === null || _table$records$record === void 0 ? void 0 : _table$records$record.deleted);
|
|
5076
|
+
}).length) !== null && _table$recordOrder$fi !== void 0 ? _table$recordOrder$fi : 0,
|
|
5077
|
+
columnCount: table.fieldOrder.filter((fieldId) => {
|
|
5078
|
+
var _table$fields$fieldId;
|
|
5079
|
+
return !((_table$fields$fieldId = table.fields[fieldId]) === null || _table$fields$fieldId === void 0 ? void 0 : _table$fields$fieldId.deleted);
|
|
5080
|
+
}).length,
|
|
5081
|
+
rowData: {},
|
|
5082
|
+
columnData: {}
|
|
5083
|
+
};
|
|
5084
|
+
tableNameMap[table.name] = table.id;
|
|
5085
|
+
}
|
|
5086
|
+
allUnitData[unitId] = baseData;
|
|
5087
|
+
unitStylesData[unitId] = new Styles();
|
|
5088
|
+
unitSheetNameMap[unitId] = tableNameMap;
|
|
5089
|
+
}
|
|
5024
5090
|
return {
|
|
5025
5091
|
allUnitData,
|
|
5026
5092
|
unitStylesData,
|
|
@@ -5309,6 +5375,131 @@ function initSheetFormulaData(formulaData, unitId, sheetId, cellMatrix) {
|
|
|
5309
5375
|
const newSheetFormulaData = sheetFormulaDataMatrix.getMatrix();
|
|
5310
5376
|
return { [unitId]: { [sheetId]: newSheetFormulaData } };
|
|
5311
5377
|
}
|
|
5378
|
+
const BASE_LEGACY_FIELD_REF_PATTERN = /\{([^}]+)\}/g;
|
|
5379
|
+
const BASE_TABLE_FIELD_REF_PATTERN = /\b([A-Z_]\w*)\[([^\]]+)\]/gi;
|
|
5380
|
+
const BASE_BRACKET_FIELD_REF_PATTERN = /(^|[^A-Za-z0-9_\]\[])\[([^\]]+)\]/g;
|
|
5381
|
+
function normalizeBaseFormulaForEngine(formula, currentTable, snapshot) {
|
|
5382
|
+
const refs = [];
|
|
5383
|
+
const hold = (ref) => {
|
|
5384
|
+
return `__BASE_FORMULA_REF_${refs.push(ref) - 1}__`;
|
|
5385
|
+
};
|
|
5386
|
+
return formula.replace(BASE_LEGACY_FIELD_REF_PATTERN, (_match, fieldName) => hold(createEngineThisRowRef(currentTable, fieldName, snapshot))).replace(BASE_TABLE_FIELD_REF_PATTERN, (_match, sourceTableName, fieldName) => {
|
|
5387
|
+
const targetTable = resolveBaseFormulaTable(sourceTableName, currentTable, snapshot);
|
|
5388
|
+
return targetTable ? hold(createEngineThisRowRef(targetTable, fieldName, snapshot)) : `${sourceTableName}[${fieldName}]`;
|
|
5389
|
+
}).replace(BASE_BRACKET_FIELD_REF_PATTERN, (_match, prefix, fieldName) => `${prefix}${hold(createEngineThisRowRef(currentTable, fieldName, snapshot))}`).replace(/__BASE_FORMULA_REF_(\d+)__/g, (_match, index) => {
|
|
5390
|
+
var _refs$Number;
|
|
5391
|
+
return (_refs$Number = refs[Number(index)]) !== null && _refs$Number !== void 0 ? _refs$Number : "";
|
|
5392
|
+
});
|
|
5393
|
+
}
|
|
5394
|
+
function createEngineThisRowRef(table, fieldName, snapshot) {
|
|
5395
|
+
return `${getEngineBaseTableName(table, snapshot)}[[#This Row],[${fieldName}]]`;
|
|
5396
|
+
}
|
|
5397
|
+
function getEngineBaseTableName(table, snapshot) {
|
|
5398
|
+
const tables = Object.values(snapshot.tables);
|
|
5399
|
+
let sameNameCount = 0;
|
|
5400
|
+
for (let i = 0; i < tables.length; i++) {
|
|
5401
|
+
const item = tables[i];
|
|
5402
|
+
if (!item.deleted && item.name === table.name) {
|
|
5403
|
+
sameNameCount++;
|
|
5404
|
+
if (sameNameCount > 1) break;
|
|
5405
|
+
}
|
|
5406
|
+
}
|
|
5407
|
+
return sameNameCount === 1 ? table.name : table.id;
|
|
5408
|
+
}
|
|
5409
|
+
function buildBaseRuntimeCellData(table) {
|
|
5410
|
+
const cellData = { ...table.cellData };
|
|
5411
|
+
const fieldOrder = [];
|
|
5412
|
+
for (let i = 0; i < table.fieldOrder.length; i++) {
|
|
5413
|
+
const fieldId = table.fieldOrder[i];
|
|
5414
|
+
if (table.fields[fieldId] && !table.fields[fieldId].deleted) fieldOrder.push(fieldId);
|
|
5415
|
+
}
|
|
5416
|
+
let recordOrder;
|
|
5417
|
+
if (table.recordOrder) {
|
|
5418
|
+
recordOrder = [];
|
|
5419
|
+
for (let i = 0; i < table.recordOrder.length; i++) {
|
|
5420
|
+
const recordId = table.recordOrder[i];
|
|
5421
|
+
if (table.records[recordId] && !table.records[recordId].deleted) recordOrder.push(recordId);
|
|
5422
|
+
}
|
|
5423
|
+
} else {
|
|
5424
|
+
var _table$records;
|
|
5425
|
+
const allRecords = Object.values((_table$records = table.records) !== null && _table$records !== void 0 ? _table$records : {});
|
|
5426
|
+
const records = [];
|
|
5427
|
+
for (let i = 0; i < allRecords.length; i++) {
|
|
5428
|
+
const record = allRecords[i];
|
|
5429
|
+
if (!record.deleted) records.push(record);
|
|
5430
|
+
}
|
|
5431
|
+
records.sort((a, b) => a.orderKey.localeCompare(b.orderKey));
|
|
5432
|
+
recordOrder = [];
|
|
5433
|
+
for (let i = 0; i < records.length; i++) {
|
|
5434
|
+
const record = records[i];
|
|
5435
|
+
recordOrder.push(record.id);
|
|
5436
|
+
}
|
|
5437
|
+
}
|
|
5438
|
+
for (let row = 0; row < recordOrder.length; row++) {
|
|
5439
|
+
const recordId = recordOrder[row];
|
|
5440
|
+
const record = table.records[recordId];
|
|
5441
|
+
if (!record || record.deleted) continue;
|
|
5442
|
+
cellData[row] = { ...cellData[row] };
|
|
5443
|
+
for (let col = 0; col < fieldOrder.length; col++) {
|
|
5444
|
+
var _record$values;
|
|
5445
|
+
const fieldId = fieldOrder[col];
|
|
5446
|
+
if (!Object.prototype.hasOwnProperty.call((_record$values = record.values) !== null && _record$values !== void 0 ? _record$values : {}, fieldId)) continue;
|
|
5447
|
+
cellData[row][col] = toBaseRuntimeCellData(record.values[fieldId], table.fields[fieldId]);
|
|
5448
|
+
}
|
|
5449
|
+
}
|
|
5450
|
+
return cellData;
|
|
5451
|
+
}
|
|
5452
|
+
function toBaseRuntimeCellData(value, field) {
|
|
5453
|
+
if (isBaseCellData(value)) return normalizeBaseCellData(value);
|
|
5454
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === "attachment") return {
|
|
5455
|
+
v: "",
|
|
5456
|
+
t: CellValueType.STRING
|
|
5457
|
+
};
|
|
5458
|
+
if (Array.isArray(value)) return {
|
|
5459
|
+
v: value.join(", "),
|
|
5460
|
+
t: CellValueType.STRING
|
|
5461
|
+
};
|
|
5462
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === "link" && value && typeof value === "object") {
|
|
5463
|
+
var _ref, _link$text;
|
|
5464
|
+
const link = value;
|
|
5465
|
+
return {
|
|
5466
|
+
v: String((_ref = (_link$text = link.text) !== null && _link$text !== void 0 ? _link$text : link.url) !== null && _ref !== void 0 ? _ref : ""),
|
|
5467
|
+
t: CellValueType.STRING
|
|
5468
|
+
};
|
|
5469
|
+
}
|
|
5470
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") return {
|
|
5471
|
+
v: value,
|
|
5472
|
+
t: inferBaseRuntimeCellType(value)
|
|
5473
|
+
};
|
|
5474
|
+
return {
|
|
5475
|
+
v: null,
|
|
5476
|
+
t: null
|
|
5477
|
+
};
|
|
5478
|
+
}
|
|
5479
|
+
function normalizeBaseCellData(cell) {
|
|
5480
|
+
var _cell$v;
|
|
5481
|
+
const type = inferBaseRuntimeCellType((_cell$v = cell.v) !== null && _cell$v !== void 0 ? _cell$v : null);
|
|
5482
|
+
return {
|
|
5483
|
+
...cell,
|
|
5484
|
+
t: type
|
|
5485
|
+
};
|
|
5486
|
+
}
|
|
5487
|
+
function inferBaseRuntimeCellType(value) {
|
|
5488
|
+
if (typeof value === "number") return CellValueType.NUMBER;
|
|
5489
|
+
if (typeof value === "boolean") return CellValueType.BOOLEAN;
|
|
5490
|
+
if (typeof value === "string") return CellValueType.STRING;
|
|
5491
|
+
return null;
|
|
5492
|
+
}
|
|
5493
|
+
function isBaseCellData(value) {
|
|
5494
|
+
return !!value && typeof value === "object" && (Object.prototype.hasOwnProperty.call(value, "v") || Object.prototype.hasOwnProperty.call(value, "t") || Object.prototype.hasOwnProperty.call(value, "p") || Object.prototype.hasOwnProperty.call(value, "f") || Object.prototype.hasOwnProperty.call(value, "si"));
|
|
5495
|
+
}
|
|
5496
|
+
function resolveBaseFormulaTable(tableName, currentTable, snapshot) {
|
|
5497
|
+
if (!tableName || tableName === "table" || tableName === currentTable.id || tableName === currentTable.name) return currentTable;
|
|
5498
|
+
const byId = snapshot.tables[tableName];
|
|
5499
|
+
if (byId && !byId.deleted) return byId;
|
|
5500
|
+
const matches = Object.values(snapshot.tables).filter((table) => !table.deleted && table.name === tableName);
|
|
5501
|
+
return matches.length === 1 ? matches[0] : void 0;
|
|
5502
|
+
}
|
|
5312
5503
|
|
|
5313
5504
|
//#endregion
|
|
5314
5505
|
//#region src/services/sheet-row-filtered.service.ts
|
|
@@ -5563,10 +5754,13 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
|
|
|
5563
5754
|
});
|
|
5564
5755
|
}
|
|
5565
5756
|
_loadSheetData() {
|
|
5757
|
+
var _workbook$getUnitId, _worksheet$getSheetId;
|
|
5566
5758
|
const workbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
|
|
5567
5759
|
const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
|
|
5568
|
-
|
|
5569
|
-
|
|
5760
|
+
const base = workbook ? null : this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_BASE);
|
|
5761
|
+
const table = base ? getFirstLiveBaseTable(base.getSnapshot().tables, base.getSnapshot().tableOrder) : null;
|
|
5762
|
+
this._executeUnitId = (_workbook$getUnitId = workbook === null || workbook === void 0 ? void 0 : workbook.getUnitId()) !== null && _workbook$getUnitId !== void 0 ? _workbook$getUnitId : base === null || base === void 0 ? void 0 : base.getUnitId();
|
|
5763
|
+
this._executeSubUnitId = (_worksheet$getSheetId = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId()) !== null && _worksheet$getSheetId !== void 0 ? _worksheet$getSheetId : table === null || table === void 0 ? void 0 : table.id;
|
|
5570
5764
|
return this._formulaDataModel.getCalculateData();
|
|
5571
5765
|
}
|
|
5572
5766
|
/**
|
|
@@ -5597,6 +5791,14 @@ FormulaCurrentConfigService = __decorate([
|
|
|
5597
5791
|
__decorateParam(2, Inject(FormulaDataModel)),
|
|
5598
5792
|
__decorateParam(3, Inject(ISheetRowFilteredService))
|
|
5599
5793
|
], FormulaCurrentConfigService);
|
|
5794
|
+
function getFirstLiveBaseTable(tables, tableOrder) {
|
|
5795
|
+
var _Object$values$find;
|
|
5796
|
+
for (const tableId of tableOrder) {
|
|
5797
|
+
const table = tables[tableId];
|
|
5798
|
+
if (table && !table.deleted) return table;
|
|
5799
|
+
}
|
|
5800
|
+
return (_Object$values$find = Object.values(tables).find((table) => !table.deleted)) !== null && _Object$values$find !== void 0 ? _Object$values$find : null;
|
|
5801
|
+
}
|
|
5600
5802
|
const IFormulaCurrentConfigService = createIdentifier("univer.formula.current-data.service");
|
|
5601
5803
|
|
|
5602
5804
|
//#endregion
|
|
@@ -5768,7 +5970,7 @@ function clearNumberFormatTypeCache() {
|
|
|
5768
5970
|
/**
|
|
5769
5971
|
* Get the currency symbol based on the locale
|
|
5770
5972
|
*/
|
|
5771
|
-
const localeCurrencySymbolMap = new Map([
|
|
5973
|
+
const localeCurrencySymbolMap = /* @__PURE__ */ new Map([
|
|
5772
5974
|
[LocaleType.EN_US, "$"],
|
|
5773
5975
|
[LocaleType.RU_RU, "₽"],
|
|
5774
5976
|
[LocaleType.VI_VN, "₫"],
|
|
@@ -9726,7 +9928,7 @@ const IFormulaRuntimeService = createIdentifier("univer.formula.runtime.service"
|
|
|
9726
9928
|
|
|
9727
9929
|
//#endregion
|
|
9728
9930
|
//#region src/engine/ast-node/node-type.ts
|
|
9729
|
-
const NODE_ORDER_MAP = new Map([
|
|
9931
|
+
const NODE_ORDER_MAP = /* @__PURE__ */ new Map([
|
|
9730
9932
|
[1, 7],
|
|
9731
9933
|
[2, 9],
|
|
9732
9934
|
[3, 8],
|
|
@@ -15487,7 +15689,7 @@ function getMatrixSumProductOfCols(matrix, startCol, endCol, row1, row2) {
|
|
|
15487
15689
|
for (let i = startCol; i < endCol; i++) sum += matrix[row1][i] * matrix[row2][i];
|
|
15488
15690
|
return sum;
|
|
15489
15691
|
}
|
|
15490
|
-
const romanToArabicMap = new Map([
|
|
15692
|
+
const romanToArabicMap = /* @__PURE__ */ new Map([
|
|
15491
15693
|
["I", 1],
|
|
15492
15694
|
["V", 5],
|
|
15493
15695
|
["X", 10],
|
|
@@ -15496,7 +15698,7 @@ const romanToArabicMap = new Map([
|
|
|
15496
15698
|
["D", 500],
|
|
15497
15699
|
["M", 1e3]
|
|
15498
15700
|
]);
|
|
15499
|
-
const arabicToRomanMap = new Map([
|
|
15701
|
+
const arabicToRomanMap = /* @__PURE__ */ new Map([
|
|
15500
15702
|
[1, "I"],
|
|
15501
15703
|
[4, "IV"],
|
|
15502
15704
|
[5, "V"],
|
|
@@ -26886,7 +27088,7 @@ var ErrorType$1 = class extends BaseFunction {
|
|
|
26886
27088
|
super(..._args);
|
|
26887
27089
|
_defineProperty(this, "minParams", 1);
|
|
26888
27090
|
_defineProperty(this, "maxParams", 1);
|
|
26889
|
-
_defineProperty(this, "_errorTypeValueMap", new Map([
|
|
27091
|
+
_defineProperty(this, "_errorTypeValueMap", /* @__PURE__ */ new Map([
|
|
26890
27092
|
["#NULL!", 1],
|
|
26891
27093
|
["#DIV/0!", 2],
|
|
26892
27094
|
["#VALUE!", 3],
|
|
@@ -40438,7 +40640,7 @@ function getObjectValue(result, isUseStrip = false) {
|
|
|
40438
40640
|
//#endregion
|
|
40439
40641
|
//#region package.json
|
|
40440
40642
|
var name = "@univerjs/engine-formula";
|
|
40441
|
-
var version = "0.
|
|
40643
|
+
var version = "1.0.0-alpha.0";
|
|
40442
40644
|
|
|
40443
40645
|
//#endregion
|
|
40444
40646
|
//#region src/services/global-computing-status.service.ts
|
package/lib/types/index.d.ts
CHANGED
|
@@ -21,28 +21,36 @@ export { excelDateSerial } from './basics/date';
|
|
|
21
21
|
export { isInDirtyRange } from './basics/dirty';
|
|
22
22
|
export { ERROR_TYPE_SET, ErrorType } from './basics/error-type';
|
|
23
23
|
export { type ISheetFormulaError } from './basics/error-type';
|
|
24
|
-
export { FunctionType
|
|
24
|
+
export { FunctionType } from './basics/function';
|
|
25
|
+
export type { IFunctionInfo, IFunctionParam } from './basics/function';
|
|
25
26
|
export { type IFunctionNames } from './basics/function';
|
|
26
27
|
export { CELL_INVERTED_INDEX_CACHE } from './basics/inverted-index-cache';
|
|
27
28
|
export { includeFormulaLexerToken, isFormulaLexerToken, normalizeSheetName } from './basics/match-token';
|
|
28
29
|
export { matchRefDrawToken } from './basics/match-token';
|
|
29
30
|
export { isReferenceString } from './basics/regex';
|
|
30
31
|
export { convertUnitDataToRuntime } from './basics/runtime';
|
|
31
|
-
export { compareToken, matchToken, OPERATOR_TOKEN_SET, operatorToken, prefixToken, SUFFIX_TOKEN_SET } from './basics/token';
|
|
32
|
-
export { DEFAULT_TOKEN_LAMBDA_FUNCTION_NAME, DEFAULT_TOKEN_LET_FUNCTION_NAME, DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER, DEFAULT_TOKEN_TYPE_PARAMETER, DEFAULT_TOKEN_TYPE_ROOT } from './basics/token-type';
|
|
32
|
+
export { compareToken, matchToken, OPERATOR_TOKEN_SET, operatorToken, prefixToken, SUFFIX_TOKEN_SET, } from './basics/token';
|
|
33
|
+
export { DEFAULT_TOKEN_LAMBDA_FUNCTION_NAME, DEFAULT_TOKEN_LET_FUNCTION_NAME, DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER, DEFAULT_TOKEN_TYPE_PARAMETER, DEFAULT_TOKEN_TYPE_ROOT, } from './basics/token-type';
|
|
33
34
|
export { OtherFormulaMarkDirty } from './commands/mutations/formula.mutation';
|
|
34
35
|
export { RegisterFunctionMutation } from './commands/mutations/register-function.mutation';
|
|
35
|
-
export {
|
|
36
|
-
export
|
|
36
|
+
export { SetArrayFormulaDataMutation } from './commands/mutations/set-array-formula-data.mutation';
|
|
37
|
+
export type { ISetArrayFormulaDataMutationParams } from './commands/mutations/set-array-formula-data.mutation';
|
|
38
|
+
export { RemoveDefinedNameMutation, SetDefinedNameMutation } from './commands/mutations/set-defined-name.mutation';
|
|
39
|
+
export type { ISetDefinedNameMutationParam, ISetDefinedNameMutationSearchParam, } from './commands/mutations/set-defined-name.mutation';
|
|
37
40
|
export { SetDefinedNameMutationFactory } from './commands/mutations/set-defined-name.mutation';
|
|
38
|
-
export { RemoveFeatureCalculationMutation, SetFeatureCalculationMutation } from './commands/mutations/set-feature-calculation.mutation';
|
|
39
|
-
export {
|
|
40
|
-
export {
|
|
41
|
-
export {
|
|
42
|
-
export
|
|
43
|
-
export {
|
|
44
|
-
export type {
|
|
45
|
-
export {
|
|
41
|
+
export { RemoveFeatureCalculationMutation, SetFeatureCalculationMutation, } from './commands/mutations/set-feature-calculation.mutation';
|
|
42
|
+
export { SetCellFormulaDependencyCalculationMutation, SetCellFormulaDependencyCalculationResultMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDependencyCalculationMutation, SetFormulaDependencyCalculationResultMutation, SetFormulaStringBatchCalculationMutation, SetFormulaStringBatchCalculationResultMutation, SetQueryFormulaDependencyAllMutation, SetQueryFormulaDependencyAllResultMutation, SetQueryFormulaDependencyMutation, SetQueryFormulaDependencyResultMutation, SetTriggerFormulaCalculationStartMutation, } from './commands/mutations/set-formula-calculation.mutation';
|
|
43
|
+
export type { ISetCellFormulaDependencyCalculationResultMutation, ISetFormulaCalculationNotificationMutation, ISetFormulaCalculationResultMutation, ISetFormulaCalculationStartMutation, ISetFormulaDependencyCalculationMutation, ISetFormulaDependencyCalculationResultMutation, ISetFormulaStringBatchCalculationResultMutation, ISetQueryFormulaDependencyAllResultMutation, ISetQueryFormulaDependencyResultMutation, } from './commands/mutations/set-formula-calculation.mutation';
|
|
44
|
+
export { SetFormulaDataMutation } from './commands/mutations/set-formula-data.mutation';
|
|
45
|
+
export type { ISetFormulaDataMutationParams } from './commands/mutations/set-formula-data.mutation';
|
|
46
|
+
export { SetImageFormulaDataMutation } from './commands/mutations/set-image-formula-data.mutation';
|
|
47
|
+
export type { ISetImageFormulaDataMutationParams } from './commands/mutations/set-image-formula-data.mutation';
|
|
48
|
+
export { RemoveOtherFormulaMutation, SetOtherFormulaMutation } from './commands/mutations/set-other-formula.mutation';
|
|
49
|
+
export type { IRemoveOtherFormulaMutationParams, ISetOtherFormulaMutationParams, } from './commands/mutations/set-other-formula.mutation';
|
|
50
|
+
export { RemoveSuperTableMutation, SetSuperTableMutation, SetSuperTableOptionMutation, } from './commands/mutations/set-super-table.mutation';
|
|
51
|
+
export type { ISetSuperTableMutationParam, ISetSuperTableMutationSearchParam, } from './commands/mutations/set-super-table.mutation';
|
|
52
|
+
export { DEFAULT_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_PLUGIN_CONFIG_KEY, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, } from './config/config';
|
|
53
|
+
export type { IUniverEngineFormulaConfig } from './config/config';
|
|
46
54
|
export { CalculateController } from './controllers/calculate.controller';
|
|
47
55
|
export { Lexer } from './engine/analysis/lexer';
|
|
48
56
|
export { LexerNode } from './engine/analysis/lexer-node';
|
|
@@ -59,14 +67,16 @@ export { ReferenceNodeFactory } from './engine/ast-node/reference-node';
|
|
|
59
67
|
export { SuffixNodeFactory } from './engine/ast-node/suffix-node';
|
|
60
68
|
export { UnionNodeFactory } from './engine/ast-node/union-node';
|
|
61
69
|
export { ValueNodeFactory } from './engine/ast-node/value-node';
|
|
62
|
-
export { FormulaDependencyTree, FormulaDependencyTreeModel
|
|
70
|
+
export { FormulaDependencyTree, FormulaDependencyTreeModel } from './engine/dependency/dependency-tree';
|
|
71
|
+
export type { IFormulaDependencyTree, IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson, IFormulaDependentsAndInRangeResults, } from './engine/dependency/dependency-tree';
|
|
63
72
|
export { FormulaDependencyTreeType } from './engine/dependency/dependency-tree';
|
|
64
73
|
export { FormulaDependencyTreeVirtual } from './engine/dependency/dependency-tree';
|
|
65
74
|
export { FormulaDependencyGenerator, IFormulaDependencyGenerator } from './engine/dependency/formula-dependency';
|
|
66
75
|
export { generateRandomDependencyTreeId } from './engine/dependency/formula-dependency';
|
|
67
76
|
export { Interpreter } from './engine/interpreter/interpreter';
|
|
68
|
-
export { BaseReferenceObject
|
|
69
|
-
export {
|
|
77
|
+
export { BaseReferenceObject } from './engine/reference-object/base-reference-object';
|
|
78
|
+
export type { FunctionVariantType } from './engine/reference-object/base-reference-object';
|
|
79
|
+
export { AsyncArrayObject, AsyncObject, FORMULA_REF_TO_ARRAY_CACHE, } from './engine/reference-object/base-reference-object';
|
|
70
80
|
export { RangeReferenceObject } from './engine/reference-object/range-reference-object';
|
|
71
81
|
export { generateExecuteAstNodeData } from './engine/utils/ast-node-tool';
|
|
72
82
|
export { extractFormulaError } from './engine/utils/cell';
|
|
@@ -74,15 +84,17 @@ export { generateAstNode } from './engine/utils/generate-ast-node';
|
|
|
74
84
|
export { strip, stripErrorMargin } from './engine/utils/math-kit';
|
|
75
85
|
export { handleNumfmtInCell } from './engine/utils/numfmt-kit';
|
|
76
86
|
export { deserializeRangeForR1C1 } from './engine/utils/r1c1-reference';
|
|
77
|
-
export { deserializeRangeWithSheet, getAbsoluteRefTypeWithSingleString, getAbsoluteRefTypeWitString, getRangeWithRefsString,
|
|
87
|
+
export { deserializeRangeWithSheet, getAbsoluteRefTypeWithSingleString, getAbsoluteRefTypeWitString, getRangeWithRefsString, isReferenceStrings, isReferenceStringWithEffectiveColumn, needsQuoting, quoteSheetName, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet, singleReferenceToGrid, splitTableStructuredRef, unquoteSheetName, } from './engine/utils/reference';
|
|
88
|
+
export type { IAbsoluteRefTypeForRange } from './engine/utils/reference';
|
|
78
89
|
export { handleRefStringInfo } from './engine/utils/reference';
|
|
79
90
|
export { deserializeRangeWithSheetWithCache } from './engine/utils/reference-cache';
|
|
80
|
-
export { generateStringWithSequence,
|
|
91
|
+
export { generateStringWithSequence, sequenceNodeType } from './engine/utils/sequence';
|
|
92
|
+
export type { ISequenceNode } from './engine/utils/sequence';
|
|
81
93
|
export { ArrayValueObject, ValueObjectFactory } from './engine/value-object/array-value-object';
|
|
82
94
|
export { BaseValueObject, ErrorValueObject } from './engine/value-object/base-value-object';
|
|
83
95
|
export { LambdaValueObjectObject } from './engine/value-object/lambda-value-object';
|
|
84
|
-
export type { FormulaFunctionResultValueType, FormulaFunctionValueType, IImageFormulaInfo, PrimitiveValueType } from './engine/value-object/primitive-object';
|
|
85
|
-
export { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from './engine/value-object/primitive-object';
|
|
96
|
+
export type { FormulaFunctionResultValueType, FormulaFunctionValueType, IImageFormulaInfo, PrimitiveValueType, } from './engine/value-object/primitive-object';
|
|
97
|
+
export { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject, } from './engine/value-object/primitive-object';
|
|
86
98
|
export { functionArray } from './functions/array/function-map';
|
|
87
99
|
export { FUNCTION_NAMES_ARRAY } from './functions/array/function-names';
|
|
88
100
|
export { BaseFunction } from './functions/base-function';
|
|
@@ -126,22 +138,25 @@ export { UniverFormulaEnginePlugin } from './plugin';
|
|
|
126
138
|
export { ActiveDirtyManagerService, IActiveDirtyManagerService } from './services/active-dirty-manager.service';
|
|
127
139
|
export { CalculateFormulaService, ICalculateFormulaService } from './services/calculate-formula.service';
|
|
128
140
|
export { DEFAULT_INTERVAL_COUNT } from './services/calculate-formula.service';
|
|
129
|
-
export { FormulaCurrentConfigService, IFormulaCurrentConfigService
|
|
130
|
-
export
|
|
141
|
+
export { FormulaCurrentConfigService, IFormulaCurrentConfigService } from './services/current-data.service';
|
|
142
|
+
export type { IFormulaDirtyData } from './services/current-data.service';
|
|
143
|
+
export { DefinedNamesService, IDefinedNamesService } from './services/defined-names.service';
|
|
144
|
+
export type { IDefinedNameMapItem, IDefinedNamesServiceParam, IDefinedNamesUpdateEvent, } from './services/defined-names.service';
|
|
131
145
|
export { IDependencyManagerService } from './services/dependency-manager.service';
|
|
132
146
|
export { DependencyManagerService } from './services/dependency-manager.service';
|
|
133
147
|
export { DependencyManagerBaseService } from './services/dependency-manager.service';
|
|
134
|
-
export { FeatureCalculationManagerService, IFeatureCalculationManagerService } from './services/feature-calculation-manager.service';
|
|
148
|
+
export { FeatureCalculationManagerService, IFeatureCalculationManagerService, } from './services/feature-calculation-manager.service';
|
|
135
149
|
export type { IFeatureCalculationManagerParam } from './services/feature-calculation-manager.service';
|
|
136
150
|
export type { IFormulaInfo, IOtherFormulaResult } from './services/formula-common';
|
|
137
151
|
export { FormulaResultStatus } from './services/formula-common';
|
|
138
152
|
export { FunctionService } from './services/function.service';
|
|
139
153
|
export { IFunctionService } from './services/function.service';
|
|
140
154
|
export { GlobalComputingStatusService } from './services/global-computing-status.service';
|
|
141
|
-
export { HyperlinkEngineFormulaService, IHyperlinkEngineFormulaService } from './services/hyperlink-engine-formula.service';
|
|
155
|
+
export { HyperlinkEngineFormulaService, IHyperlinkEngineFormulaService, } from './services/hyperlink-engine-formula.service';
|
|
142
156
|
export { IOtherFormulaManagerService, OtherFormulaManagerService } from './services/other-formula-manager.service';
|
|
143
157
|
export { OtherFormulaBizType, RegisterOtherFormulaService } from './services/register-other-formula.service';
|
|
144
|
-
export { FormulaExecutedStateType, FormulaExecuteStageType, FormulaRuntimeService,
|
|
158
|
+
export { FormulaExecutedStateType, FormulaExecuteStageType, FormulaRuntimeService, IFormulaRuntimeService, } from './services/runtime.service';
|
|
159
|
+
export type { IAllRuntimeData, IExecutionInProgressParams } from './services/runtime.service';
|
|
145
160
|
export { ISheetRowFilteredService, SheetRowFilteredService } from './services/sheet-row-filtered.service';
|
|
146
161
|
export { ISuperTableService } from './services/super-table.service';
|
|
147
162
|
export { SuperTableService } from './services/super-table.service';
|