@univerjs/engine-formula 0.25.1 → 1.0.0-alpha.1

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/es/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.133.0/helpers/esm/typeof.js
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.133.0/helpers/esm/toPrimitive.js
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.133.0/helpers/esm/toPropertyKey.js
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.133.0/helpers/esm/defineProperty.js
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.133.0/helpers/esm/decorateParam.js
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.133.0/helpers/esm/decorate.js
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
- if (allSheets.length === 0) return formulaData;
4913
- allSheets.forEach((workbook) => {
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().forEach((worksheet) => {
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
- this._executeUnitId = workbook === null || workbook === void 0 ? void 0 : workbook.getUnitId();
5569
- this._executeSubUnitId = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId();
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],
@@ -14275,12 +14477,11 @@ var BaseFunction = class {
14275
14477
  * =INDIRECT("DefinedName1")
14276
14478
  */
14277
14479
  getDefinedName(name) {
14278
- var _Array$from$filter;
14279
14480
  const nameMap = this._definedNames;
14280
14481
  if (nameMap == null) return null;
14281
- return (_Array$from$filter = Array.from(Object.values(nameMap)).filter((value) => {
14482
+ return Object.values(nameMap).find((value) => {
14282
14483
  return value.name === name;
14283
- })) === null || _Array$from$filter === void 0 ? void 0 : _Array$from$filter[0];
14484
+ });
14284
14485
  }
14285
14486
  setDefinedNames(definedNames) {
14286
14487
  this._definedNames = definedNames;
@@ -15487,7 +15688,7 @@ function getMatrixSumProductOfCols(matrix, startCol, endCol, row1, row2) {
15487
15688
  for (let i = startCol; i < endCol; i++) sum += matrix[row1][i] * matrix[row2][i];
15488
15689
  return sum;
15489
15690
  }
15490
- const romanToArabicMap = new Map([
15691
+ const romanToArabicMap = /* @__PURE__ */ new Map([
15491
15692
  ["I", 1],
15492
15693
  ["V", 5],
15493
15694
  ["X", 10],
@@ -15496,7 +15697,7 @@ const romanToArabicMap = new Map([
15496
15697
  ["D", 500],
15497
15698
  ["M", 1e3]
15498
15699
  ]);
15499
- const arabicToRomanMap = new Map([
15700
+ const arabicToRomanMap = /* @__PURE__ */ new Map([
15500
15701
  [1, "I"],
15501
15702
  [4, "IV"],
15502
15703
  [5, "V"],
@@ -26886,7 +27087,7 @@ var ErrorType$1 = class extends BaseFunction {
26886
27087
  super(..._args);
26887
27088
  _defineProperty(this, "minParams", 1);
26888
27089
  _defineProperty(this, "maxParams", 1);
26889
- _defineProperty(this, "_errorTypeValueMap", new Map([
27090
+ _defineProperty(this, "_errorTypeValueMap", /* @__PURE__ */ new Map([
26890
27091
  ["#NULL!", 1],
26891
27092
  ["#DIV/0!", 2],
26892
27093
  ["#VALUE!", 3],
@@ -39690,24 +39891,28 @@ var Textafter = class extends BaseFunction {
39690
39891
  let matchNum = 0;
39691
39892
  let preDelimiterLength = 0;
39692
39893
  for (let i = 0; i < Math.abs(instanceNumValue); i++) if (instanceNumValue < 0) {
39693
- const delimiterItem = _delimiterValue.map((item) => {
39694
- return {
39695
- index: substrText.lastIndexOf(item),
39894
+ let delimiterItem;
39895
+ for (const item of _delimiterValue) {
39896
+ const index = substrText.lastIndexOf(item);
39897
+ if (index !== -1 && (!delimiterItem || index > delimiterItem.index)) delimiterItem = {
39898
+ index,
39696
39899
  length: item.length
39697
39900
  };
39698
- }).filter((item) => item.index !== -1).sort((a, b) => b.index - a.index)[0];
39901
+ }
39699
39902
  if (!delimiterItem) break;
39700
39903
  resultIndex = delimiterItem.index;
39701
39904
  substrText = substrText.substr(0, delimiterItem.index);
39702
39905
  preDelimiterLength = delimiterItem.length;
39703
39906
  matchNum++;
39704
39907
  } else {
39705
- const delimiterItem = _delimiterValue.map((item) => {
39706
- return {
39707
- index: substrText.indexOf(item),
39908
+ let delimiterItem;
39909
+ for (const item of _delimiterValue) {
39910
+ const index = substrText.indexOf(item);
39911
+ if (index !== -1 && (!delimiterItem || index < delimiterItem.index)) delimiterItem = {
39912
+ index,
39708
39913
  length: item.length
39709
39914
  };
39710
- }).filter((item) => item.index !== -1).sort((a, b) => a.index - b.index)[0];
39915
+ }
39711
39916
  if (!delimiterItem) break;
39712
39917
  resultIndex += delimiterItem.index + preDelimiterLength;
39713
39918
  substrText = substrText.substr(delimiterItem.index + delimiterItem.length);
@@ -39829,23 +40034,27 @@ var Textbefore = class extends BaseFunction {
39829
40034
  let matchNum = 0;
39830
40035
  let preDelimiterLength = 0;
39831
40036
  for (let i = 0; i < Math.abs(instanceNumValue); i++) if (instanceNumValue < 0) {
39832
- const delimiterItem = _delimiterValue.map((item) => {
39833
- return {
39834
- index: substrText.lastIndexOf(item),
40037
+ let delimiterItem;
40038
+ for (const item of _delimiterValue) {
40039
+ const index = substrText.lastIndexOf(item);
40040
+ if (index !== -1 && (!delimiterItem || index > delimiterItem.index)) delimiterItem = {
40041
+ index,
39835
40042
  length: item.length
39836
40043
  };
39837
- }).filter((item) => item.index !== -1).sort((a, b) => b.index - a.index)[0];
40044
+ }
39838
40045
  if (!delimiterItem) break;
39839
40046
  resultIndex = delimiterItem.index;
39840
40047
  substrText = substrText.substr(0, delimiterItem.index);
39841
40048
  matchNum++;
39842
40049
  } else {
39843
- const delimiterItem = _delimiterValue.map((item) => {
39844
- return {
39845
- index: substrText.indexOf(item),
40050
+ let delimiterItem;
40051
+ for (const item of _delimiterValue) {
40052
+ const index = substrText.indexOf(item);
40053
+ if (index !== -1 && (!delimiterItem || index < delimiterItem.index)) delimiterItem = {
40054
+ index,
39846
40055
  length: item.length
39847
40056
  };
39848
- }).filter((item) => item.index !== -1).sort((a, b) => a.index - b.index)[0];
40057
+ }
39849
40058
  if (!delimiterItem) break;
39850
40059
  resultIndex += delimiterItem.index + preDelimiterLength;
39851
40060
  substrText = substrText.substr(delimiterItem.index + delimiterItem.length);
@@ -40438,7 +40647,7 @@ function getObjectValue(result, isUseStrip = false) {
40438
40647
  //#endregion
40439
40648
  //#region package.json
40440
40649
  var name = "@univerjs/engine-formula";
40441
- var version = "0.25.1";
40650
+ var version = "1.0.0-alpha.1";
40442
40651
 
40443
40652
  //#endregion
40444
40653
  //#region src/services/global-computing-status.service.ts
package/lib/facade.js CHANGED
@@ -3,7 +3,7 @@ import { ICommandService, IConfigService, Inject, Injector } from "@univerjs/cor
3
3
  import { ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, GlobalComputingStatusService, IDefinedNamesService, IFunctionService, ISuperTableService, LexerTreeBuilder, SetCellFormulaDependencyCalculationMutation, SetCellFormulaDependencyCalculationResultMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDependencyCalculationMutation, SetFormulaDependencyCalculationResultMutation, SetFormulaStringBatchCalculationMutation, SetFormulaStringBatchCalculationResultMutation, SetQueryFormulaDependencyAllMutation, SetQueryFormulaDependencyAllResultMutation, SetQueryFormulaDependencyMutation, SetQueryFormulaDependencyResultMutation, SetTriggerFormulaCalculationStartMutation } from "@univerjs/engine-formula";
4
4
  import { filter, firstValueFrom, map, race, timer } from "rxjs";
5
5
 
6
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
6
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
7
7
  function __decorateParam(paramIndex, decorator) {
8
8
  return function(target, key) {
9
9
  decorator(target, key, paramIndex);
@@ -11,7 +11,7 @@ function __decorateParam(paramIndex, decorator) {
11
11
  }
12
12
 
13
13
  //#endregion
14
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
14
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
15
15
  function __decorate(decorators, target, key, desc) {
16
16
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
17
17
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);