@univerjs/engine-formula 0.24.0 → 0.25.0-insiders.20260608-e4336f7

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, generateRandomId, getNumfmtParseValueFilter, hashAlgorithm, isFormulaId, isFormulaString, 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.129.0/helpers/typeof.js
15
+ //#region \0@oxc-project+runtime@0.134.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.129.0/helpers/toPrimitive.js
26
+ //#region \0@oxc-project+runtime@0.134.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.129.0/helpers/toPropertyKey.js
39
+ //#region \0@oxc-project+runtime@0.134.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.129.0/helpers/defineProperty.js
46
+ //#region \0@oxc-project+runtime@0.134.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,
@@ -845,7 +845,7 @@ function getWeekDayByDateSerialNumber(dateSerialNumber) {
845
845
  let date = excelSerialToDate(dateSerialNumber);
846
846
  const leapDayDateTime = Date.UTC(1900, 1, 28);
847
847
  const dateTime = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
848
- if (!isDate19000229 && dateTime <= leapDayDateTime) date = new Date(dateTime - perDayMilliseconds);
848
+ if (!isDate19000229 && dateTime <= leapDayDateTime) date = /* @__PURE__ */ new Date(dateTime - perDayMilliseconds);
849
849
  return date.getUTCDay();
850
850
  }
851
851
  function getTwoDateDaysByBasis(startDateSerialNumber, endDateSerialNumber, basis) {
@@ -1847,7 +1847,7 @@ function splitTableStructuredRef(ref) {
1847
1847
  }
1848
1848
 
1849
1849
  //#endregion
1850
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
1850
+ //#region \0@oxc-project+runtime@0.134.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.129.0/helpers/decorate.js
1858
+ //#region \0@oxc-project+runtime@0.134.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);
@@ -4908,9 +4908,7 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
4908
4908
  }
4909
4909
  getFormulaData() {
4910
4910
  const formulaData = {};
4911
- const allSheets = this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_SHEET);
4912
- if (allSheets.length === 0) return formulaData;
4913
- allSheets.forEach((workbook) => {
4911
+ this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_SHEET).forEach((workbook) => {
4914
4912
  const unitId = workbook.getUnitId();
4915
4913
  formulaData[unitId] = {};
4916
4914
  workbook.getSheets().forEach((worksheet) => {
@@ -4918,6 +4916,32 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
4918
4916
  initSheetFormulaData(formulaData, unitId, worksheet.getSheetId(), cellMatrix);
4919
4917
  });
4920
4918
  });
4919
+ this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_BASE).forEach((base) => {
4920
+ const snapshot = base.getSnapshot();
4921
+ const unitId = base.getUnitId();
4922
+ formulaData[unitId] = {};
4923
+ Object.values(snapshot.tables).filter((table) => !table.deleted).forEach((table) => {
4924
+ var _table$recordOrder;
4925
+ const tableFormulaData = {};
4926
+ (_table$recordOrder = table.recordOrder) === null || _table$recordOrder === void 0 || _table$recordOrder.forEach((recordId, row) => {
4927
+ const record = table.records[recordId];
4928
+ if (!record || record.deleted) return;
4929
+ table.fieldOrder.forEach((fieldId, col) => {
4930
+ var _field$config$formula, _field$config, _tableFormulaData$row;
4931
+ const field = table.fields[fieldId];
4932
+ if (!field || field.deleted || field.type !== "formula") return;
4933
+ 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();
4934
+ if (!formula) return;
4935
+ (_tableFormulaData$row = tableFormulaData[row]) !== null && _tableFormulaData$row !== void 0 || (tableFormulaData[row] = {});
4936
+ tableFormulaData[row][col] = {
4937
+ f: normalizeBaseFormulaForEngine(formula, table, snapshot),
4938
+ si: field.id
4939
+ };
4940
+ });
4941
+ });
4942
+ formulaData[unitId][table.id] = tableFormulaData;
4943
+ });
4944
+ });
4921
4945
  return formulaData;
4922
4946
  }
4923
4947
  getSheetFormulaData(unitId, sheetId) {
@@ -5021,6 +5045,33 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
5021
5045
  unitStylesData[unitId] = workbook.getStyles();
5022
5046
  unitSheetNameMap[unitId] = sheetNameMap;
5023
5047
  }
5048
+ const unitAllBases = this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_BASE);
5049
+ for (const base of unitAllBases) {
5050
+ const snapshot = base.getSnapshot();
5051
+ const unitId = base.getUnitId();
5052
+ const baseData = {};
5053
+ const tableNameMap = {};
5054
+ for (const table of Object.values(snapshot.tables).filter((item) => !item.deleted)) {
5055
+ var _table$recordOrder$fi, _table$recordOrder2;
5056
+ baseData[table.id] = {
5057
+ cellData: new ObjectMatrix(buildBaseRuntimeCellData(table)),
5058
+ rowCount: (_table$recordOrder$fi = (_table$recordOrder2 = table.recordOrder) === null || _table$recordOrder2 === void 0 ? void 0 : _table$recordOrder2.filter((recordId) => {
5059
+ var _table$records$record;
5060
+ return !((_table$records$record = table.records[recordId]) === null || _table$records$record === void 0 ? void 0 : _table$records$record.deleted);
5061
+ }).length) !== null && _table$recordOrder$fi !== void 0 ? _table$recordOrder$fi : 0,
5062
+ columnCount: table.fieldOrder.filter((fieldId) => {
5063
+ var _table$fields$fieldId;
5064
+ return !((_table$fields$fieldId = table.fields[fieldId]) === null || _table$fields$fieldId === void 0 ? void 0 : _table$fields$fieldId.deleted);
5065
+ }).length,
5066
+ rowData: {},
5067
+ columnData: {}
5068
+ };
5069
+ tableNameMap[table.name] = table.id;
5070
+ }
5071
+ allUnitData[unitId] = baseData;
5072
+ unitStylesData[unitId] = new Styles();
5073
+ unitSheetNameMap[unitId] = tableNameMap;
5074
+ }
5024
5075
  return {
5025
5076
  allUnitData,
5026
5077
  unitStylesData,
@@ -5309,6 +5360,95 @@ function initSheetFormulaData(formulaData, unitId, sheetId, cellMatrix) {
5309
5360
  const newSheetFormulaData = sheetFormulaDataMatrix.getMatrix();
5310
5361
  return { [unitId]: { [sheetId]: newSheetFormulaData } };
5311
5362
  }
5363
+ const BASE_LEGACY_FIELD_REF_PATTERN = /\{([^}]+)\}/g;
5364
+ const BASE_TABLE_FIELD_REF_PATTERN = /\b([A-Z_]\w*)\[([^\]]+)\]/gi;
5365
+ const BASE_BRACKET_FIELD_REF_PATTERN = /(^|[^A-Za-z0-9_\]\[])\[([^\]]+)\]/g;
5366
+ function normalizeBaseFormulaForEngine(formula, currentTable, snapshot) {
5367
+ const refs = [];
5368
+ const hold = (ref) => {
5369
+ return `__BASE_FORMULA_REF_${refs.push(ref) - 1}__`;
5370
+ };
5371
+ return formula.replace(BASE_LEGACY_FIELD_REF_PATTERN, (_match, fieldName) => hold(createEngineThisRowRef(currentTable, fieldName, snapshot))).replace(BASE_TABLE_FIELD_REF_PATTERN, (_match, sourceTableName, fieldName) => {
5372
+ const targetTable = resolveBaseFormulaTable(sourceTableName, currentTable, snapshot);
5373
+ return targetTable ? hold(createEngineThisRowRef(targetTable, fieldName, snapshot)) : `${sourceTableName}[${fieldName}]`;
5374
+ }).replace(BASE_BRACKET_FIELD_REF_PATTERN, (_match, prefix, fieldName) => `${prefix}${hold(createEngineThisRowRef(currentTable, fieldName, snapshot))}`).replace(/__BASE_FORMULA_REF_(\d+)__/g, (_match, index) => {
5375
+ var _refs$Number;
5376
+ return (_refs$Number = refs[Number(index)]) !== null && _refs$Number !== void 0 ? _refs$Number : "";
5377
+ });
5378
+ }
5379
+ function createEngineThisRowRef(table, fieldName, snapshot) {
5380
+ return `${getEngineBaseTableName(table, snapshot)}[[#This Row],[${fieldName}]]`;
5381
+ }
5382
+ function getEngineBaseTableName(table, snapshot) {
5383
+ return Object.values(snapshot.tables).filter((item) => !item.deleted && item.name === table.name).length === 1 ? table.name : table.id;
5384
+ }
5385
+ function buildBaseRuntimeCellData(table) {
5386
+ var _table$recordOrder$fi2, _table$recordOrder3, _table$records;
5387
+ const cellData = { ...table.cellData };
5388
+ const fieldOrder = table.fieldOrder.filter((fieldId) => table.fields[fieldId] && !table.fields[fieldId].deleted);
5389
+ ((_table$recordOrder$fi2 = (_table$recordOrder3 = table.recordOrder) === null || _table$recordOrder3 === void 0 ? void 0 : _table$recordOrder3.filter((recordId) => table.records[recordId] && !table.records[recordId].deleted)) !== null && _table$recordOrder$fi2 !== void 0 ? _table$recordOrder$fi2 : Object.values((_table$records = table.records) !== null && _table$records !== void 0 ? _table$records : {}).filter((record) => !record.deleted).sort((a, b) => a.orderKey.localeCompare(b.orderKey)).map((record) => record.id)).forEach((recordId, row) => {
5390
+ const record = table.records[recordId];
5391
+ if (!record || record.deleted) return;
5392
+ cellData[row] = { ...cellData[row] };
5393
+ fieldOrder.forEach((fieldId, col) => {
5394
+ var _record$values;
5395
+ if (!Object.prototype.hasOwnProperty.call((_record$values = record.values) !== null && _record$values !== void 0 ? _record$values : {}, fieldId)) return;
5396
+ cellData[row][col] = toBaseRuntimeCellData(record.values[fieldId], table.fields[fieldId]);
5397
+ });
5398
+ });
5399
+ return cellData;
5400
+ }
5401
+ function toBaseRuntimeCellData(value, field) {
5402
+ if (isBaseCellData(value)) return normalizeBaseCellData(value);
5403
+ if ((field === null || field === void 0 ? void 0 : field.type) === "attachment") return {
5404
+ v: "",
5405
+ t: CellValueType.STRING
5406
+ };
5407
+ if (Array.isArray(value)) return {
5408
+ v: value.join(", "),
5409
+ t: CellValueType.STRING
5410
+ };
5411
+ if ((field === null || field === void 0 ? void 0 : field.type) === "link" && value && typeof value === "object") {
5412
+ var _ref, _link$text;
5413
+ const link = value;
5414
+ return {
5415
+ v: String((_ref = (_link$text = link.text) !== null && _link$text !== void 0 ? _link$text : link.url) !== null && _ref !== void 0 ? _ref : ""),
5416
+ t: CellValueType.STRING
5417
+ };
5418
+ }
5419
+ if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") return {
5420
+ v: value,
5421
+ t: inferBaseRuntimeCellType(value)
5422
+ };
5423
+ return {
5424
+ v: null,
5425
+ t: null
5426
+ };
5427
+ }
5428
+ function normalizeBaseCellData(cell) {
5429
+ var _cell$v;
5430
+ const type = inferBaseRuntimeCellType((_cell$v = cell.v) !== null && _cell$v !== void 0 ? _cell$v : null);
5431
+ return {
5432
+ ...cell,
5433
+ t: type
5434
+ };
5435
+ }
5436
+ function inferBaseRuntimeCellType(value) {
5437
+ if (typeof value === "number") return CellValueType.NUMBER;
5438
+ if (typeof value === "boolean") return CellValueType.BOOLEAN;
5439
+ if (typeof value === "string") return CellValueType.STRING;
5440
+ return null;
5441
+ }
5442
+ function isBaseCellData(value) {
5443
+ 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"));
5444
+ }
5445
+ function resolveBaseFormulaTable(tableName, currentTable, snapshot) {
5446
+ if (!tableName || tableName === "table" || tableName === currentTable.id || tableName === currentTable.name) return currentTable;
5447
+ const byId = snapshot.tables[tableName];
5448
+ if (byId && !byId.deleted) return byId;
5449
+ const matches = Object.values(snapshot.tables).filter((table) => !table.deleted && table.name === tableName);
5450
+ return matches.length === 1 ? matches[0] : void 0;
5451
+ }
5312
5452
 
5313
5453
  //#endregion
5314
5454
  //#region src/services/sheet-row-filtered.service.ts
@@ -5363,6 +5503,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5363
5503
  _defineProperty(this, "_dirtyRanges", []);
5364
5504
  _defineProperty(this, "_dirtyNameMap", {});
5365
5505
  _defineProperty(this, "_dirtyDefinedNameMap", {});
5506
+ _defineProperty(this, "_dirtySuperTableMap", {});
5366
5507
  _defineProperty(this, "_dirtyUnitFeatureMap", {});
5367
5508
  _defineProperty(this, "_dirtyUnitOtherFormulaMap", {});
5368
5509
  _defineProperty(this, "_excludedCell", void 0);
@@ -5382,6 +5523,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5382
5523
  this._dirtyRanges = [];
5383
5524
  this._dirtyNameMap = {};
5384
5525
  this._dirtyDefinedNameMap = {};
5526
+ this._dirtySuperTableMap = {};
5385
5527
  this._dirtyUnitFeatureMap = {};
5386
5528
  this._dirtyUnitOtherFormulaMap = {};
5387
5529
  this._excludedCell = {};
@@ -5432,6 +5574,9 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5432
5574
  getDirtyDefinedNameMap() {
5433
5575
  return this._dirtyDefinedNameMap;
5434
5576
  }
5577
+ getDirtySuperTableMap() {
5578
+ return this._dirtySuperTableMap;
5579
+ }
5435
5580
  getDirtyUnitFeatureMap() {
5436
5581
  return this._dirtyUnitFeatureMap;
5437
5582
  }
@@ -5497,6 +5642,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5497
5642
  this._dirtyRanges = config.dirtyRanges;
5498
5643
  this._dirtyNameMap = config.dirtyNameMap;
5499
5644
  this._dirtyDefinedNameMap = config.dirtyDefinedNameMap;
5645
+ this._dirtySuperTableMap = config.dirtySuperTableMap || {};
5500
5646
  this._dirtyUnitFeatureMap = config.dirtyUnitFeatureMap;
5501
5647
  this._dirtyUnitOtherFormulaMap = config.dirtyUnitOtherFormulaMap;
5502
5648
  this._excludedCell = config.excludedCell;
@@ -5518,6 +5664,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5518
5664
  dirtyRanges: this._dirtyRanges,
5519
5665
  dirtyNameMap: this._dirtyNameMap,
5520
5666
  dirtyDefinedNameMap: this._dirtyDefinedNameMap,
5667
+ dirtySuperTableMap: this._dirtySuperTableMap,
5521
5668
  dirtyUnitFeatureMap: this._dirtyUnitFeatureMap,
5522
5669
  dirtyUnitOtherFormulaMap: this._dirtyUnitOtherFormulaMap,
5523
5670
  clearDependencyTreeCache: this._clearDependencyTreeCache
@@ -5556,10 +5703,13 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5556
5703
  });
5557
5704
  }
5558
5705
  _loadSheetData() {
5706
+ var _workbook$getUnitId, _worksheet$getSheetId;
5559
5707
  const workbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
5560
5708
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
5561
- this._executeUnitId = workbook === null || workbook === void 0 ? void 0 : workbook.getUnitId();
5562
- this._executeSubUnitId = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId();
5709
+ const base = workbook ? null : this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_BASE);
5710
+ const table = base ? getFirstLiveBaseTable(base.getSnapshot().tables, base.getSnapshot().tableOrder) : null;
5711
+ 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();
5712
+ 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;
5563
5713
  return this._formulaDataModel.getCalculateData();
5564
5714
  }
5565
5715
  /**
@@ -5590,6 +5740,14 @@ FormulaCurrentConfigService = __decorate([
5590
5740
  __decorateParam(2, Inject(FormulaDataModel)),
5591
5741
  __decorateParam(3, Inject(ISheetRowFilteredService))
5592
5742
  ], FormulaCurrentConfigService);
5743
+ function getFirstLiveBaseTable(tables, tableOrder) {
5744
+ var _Object$values$find;
5745
+ for (const tableId of tableOrder) {
5746
+ const table = tables[tableId];
5747
+ if (table && !table.deleted) return table;
5748
+ }
5749
+ return (_Object$values$find = Object.values(tables).find((table) => !table.deleted)) !== null && _Object$values$find !== void 0 ? _Object$values$find : null;
5750
+ }
5593
5751
  const IFormulaCurrentConfigService = createIdentifier("univer.formula.current-data.service");
5594
5752
 
5595
5753
  //#endregion
@@ -5632,22 +5790,6 @@ Lexer = __decorate([
5632
5790
  __decorateParam(2, IFormulaCurrentConfigService)
5633
5791
  ], Lexer);
5634
5792
 
5635
- //#endregion
5636
- //#region src/basics/is-null-cell.ts
5637
- /**
5638
- * Examine if a cell is empty (null) in the formula-related modules. This is not
5639
- * interchangable with {@link isNullCell} from the core package, because for
5640
- * formulas, "custom" field is meaningless.
5641
- */
5642
- function isNullCellForFormula(cell) {
5643
- if (cell == null) return true;
5644
- const { v, f, si, p } = cell;
5645
- if (!(v == null || typeof v === "string" && v.length === 0)) return false;
5646
- if (f != null && f.length > 0 || si != null && si.length > 0) return false;
5647
- if (p != null) return false;
5648
- return true;
5649
- }
5650
-
5651
5793
  //#endregion
5652
5794
  //#region src/engine/utils/cell.ts
5653
5795
  function getCellValue(cell) {
@@ -5699,7 +5841,7 @@ function isWildcard(str) {
5699
5841
  return str.indexOf("*") > -1 || str.indexOf("?") > -1;
5700
5842
  }
5701
5843
  function isMatchWildcard(currentValue, value) {
5702
- const pattern = escapeRegExp(value).replace(/~?[*?]/g, (match) => {
5844
+ const pattern = escapeRegExpForWildcard(value).replace(/~?[*?]/g, (match) => {
5703
5845
  if (match.startsWith("~")) return `\\${match.substring(1)}`;
5704
5846
  if (match === "*") return ".*";
5705
5847
  if (match === "?") return ".";
@@ -5734,7 +5876,7 @@ function compareWithWildcard(currentValue, value, operator) {
5734
5876
  }
5735
5877
  return result;
5736
5878
  }
5737
- function escapeRegExp(str) {
5879
+ function escapeRegExpForWildcard(str) {
5738
5880
  return str.replace(/[.+^${}()|[\]\\]/g, "\\$&");
5739
5881
  }
5740
5882
  function getMatchModeValue(matchModeValue) {
@@ -5783,11 +5925,20 @@ const localeCurrencySymbolMap = new Map([
5783
5925
  [LocaleType.VI_VN, "₫"],
5784
5926
  [LocaleType.ZH_CN, "¥"],
5785
5927
  [LocaleType.ZH_TW, "NT$"],
5928
+ [LocaleType.ZH_HK, "HK$"],
5786
5929
  [LocaleType.FR_FR, "€"],
5787
5930
  [LocaleType.FA_IR, "﷼"],
5788
5931
  [LocaleType.KO_KR, "₩"],
5789
5932
  [LocaleType.ES_ES, "€"],
5790
- [LocaleType.CA_ES, "€"]
5933
+ [LocaleType.CA_ES, "€"],
5934
+ [LocaleType.SK_SK, "€"],
5935
+ [LocaleType.JA_JP, "¥"],
5936
+ [LocaleType.PT_BR, "R$"],
5937
+ [LocaleType.DE_DE, "€"],
5938
+ [LocaleType.IT_IT, "€"],
5939
+ [LocaleType.ID_ID, "Rp"],
5940
+ [LocaleType.PL_PL, "zł"],
5941
+ [LocaleType.AR_SA, "﷼"]
5791
5942
  ]);
5792
5943
  function getCurrencySymbol(locale) {
5793
5944
  return localeCurrencySymbolMap.get(locale) || "$";
@@ -8215,7 +8366,7 @@ var BaseReferenceObject = class extends ObjectClassType {
8215
8366
  if (r < 0 || c < 0) return callback(ErrorValueObject.create("#REF!"), r, c);
8216
8367
  const cell = this.getCellData(r, c);
8217
8368
  let result = false;
8218
- if (isNullCellForFormula(cell)) {
8369
+ if (isNullCell(cell)) {
8219
8370
  result = callback(null, r, c);
8220
8371
  continue;
8221
8372
  }
@@ -9662,10 +9813,10 @@ let FormulaRuntimeService = class FormulaRuntimeService extends Disposable {
9662
9813
  const currentCell = unitData === null || unitData === void 0 || (_unitData$formulaUnit = unitData[formulaUnitId]) === null || _unitData$formulaUnit === void 0 || (_unitData$formulaUnit = _unitData$formulaUnit[formulaSheetId]) === null || _unitData$formulaUnit === void 0 || (_unitData$formulaUnit = _unitData$formulaUnit.cellData) === null || _unitData$formulaUnit === void 0 ? void 0 : _unitData$formulaUnit.getValue(r, c);
9663
9814
  const featureCell = this._getRuntimeFeatureCellValue(r, c, formulaSheetId, formulaUnitId);
9664
9815
  const isPreviousCellOfCurrentArrayFormula = this._arrayCellHasData(arrayDataCell) && this._isInArrayFormulaRange(previousArrayFormulaRange, r, c) && (currentCell == null || this._isSameCellValue(currentCell, arrayDataCell));
9665
- const hasRuntimeCell = !isNullCellForFormula(cell);
9816
+ const hasRuntimeCell = !isNullCell(cell);
9666
9817
  const isInOtherArrayFormulaRange = this._isInOtherArrayFormulaRange(formulaUnitId, formulaSheetId, formulaRow, formulaColumn, r, c);
9667
- const currentCellBlocks = !isNullCellForFormula(currentCell) && !isPreviousCellOfCurrentArrayFormula;
9668
- const featureCellBlocks = !isNullCellForFormula(featureCell);
9818
+ const currentCellBlocks = !isNullCell(currentCell) && !isPreviousCellOfCurrentArrayFormula;
9819
+ const featureCellBlocks = !isNullCell(featureCell);
9669
9820
  if (hasRuntimeCell || isInOtherArrayFormulaRange || currentCellBlocks || featureCellBlocks) return true;
9670
9821
  }
9671
9822
  return false;
@@ -9938,9 +10089,11 @@ const COLUMN_LIKE_FUNCTION_NAMES = new Set(ALL_GROUPS.flatMap((g) => Object.valu
9938
10089
  //#region src/engine/utils/generate-ast-node.ts
9939
10090
  const FORMULA_CACHE_LRU_COUNT = 5e3;
9940
10091
  const FORMULA_AST_CACHE = new FormulaAstLRU(FORMULA_CACHE_LRU_COUNT);
10092
+ const DIRTY_DEFINED_NAME_SET_CACHE = /* @__PURE__ */ new WeakMap();
10093
+ const DIRTY_SUPER_TABLE_PATTERN_CACHE = /* @__PURE__ */ new WeakMap();
9941
10094
  function generateAstNode(unitId, formulaString, lexer, astTreeBuilder, currentConfigService) {
9942
10095
  let astNode = FORMULA_AST_CACHE.get(`${unitId}${formulaString}`);
9943
- const noCache = checkIsChangedByDefinedName(unitId, formulaString, currentConfigService);
10096
+ const noCache = checkIsChangedByDefinedName(unitId, formulaString, currentConfigService) || checkIsChangedBySuperTable(unitId, formulaString, currentConfigService);
9944
10097
  if (!noCache && astNode && !isDirtyDefinedForNode(astNode, currentConfigService)) return astNode;
9945
10098
  const lexerNode = lexer.treeBuilder(formulaString);
9946
10099
  if (ERROR_TYPE_SET.has(lexerNode)) return ErrorNode.create(lexerNode);
@@ -9955,14 +10108,37 @@ function generateAstNode(unitId, formulaString, lexer, astTreeBuilder, currentCo
9955
10108
  function checkIsChangedByDefinedName(unitId, formula, currentConfigService) {
9956
10109
  const unitDefinedNameMap = currentConfigService.getDirtyDefinedNameMap()[unitId];
9957
10110
  if (unitDefinedNameMap == null) return false;
9958
- const formulaText = normalizeFormulaText(formula);
9959
- const names = Object.keys(unitDefinedNameMap);
9960
- for (let i = 0, len = names.length; i < len; i++) if (normalizeFormulaText(names[i]) === formulaText) return true;
9961
- return false;
10111
+ return getNormalizedDirtyDefinedNameSet(unitDefinedNameMap).has(normalizeFormulaText(formula));
9962
10112
  }
9963
10113
  function normalizeFormulaText(formula) {
9964
10114
  return formula.startsWith("=") ? formula.slice(1) : formula;
9965
10115
  }
10116
+ function checkIsChangedBySuperTable(unitId, formula, currentConfigService) {
10117
+ var _currentConfigService, _tableReferencePatter;
10118
+ const getDirtySuperTableMap = (_currentConfigService = currentConfigService.getDirtySuperTableMap) === null || _currentConfigService === void 0 ? void 0 : _currentConfigService.bind(currentConfigService);
10119
+ const changedSuperTableMap = getDirtySuperTableMap === null || getDirtySuperTableMap === void 0 ? void 0 : getDirtySuperTableMap();
10120
+ const unitSuperTableMap = changedSuperTableMap === null || changedSuperTableMap === void 0 ? void 0 : changedSuperTableMap[unitId];
10121
+ if (unitSuperTableMap == null) return false;
10122
+ const tableReferencePattern = getDirtySuperTableReferencePattern(unitSuperTableMap);
10123
+ return (_tableReferencePatter = tableReferencePattern === null || tableReferencePattern === void 0 ? void 0 : tableReferencePattern.test(normalizeFormulaText(formula))) !== null && _tableReferencePatter !== void 0 ? _tableReferencePatter : false;
10124
+ }
10125
+ function getNormalizedDirtyDefinedNameSet(unitDefinedNameMap) {
10126
+ let normalizedNameSet = DIRTY_DEFINED_NAME_SET_CACHE.get(unitDefinedNameMap);
10127
+ if (normalizedNameSet == null) {
10128
+ normalizedNameSet = new Set(Object.keys(unitDefinedNameMap).map(normalizeFormulaText));
10129
+ DIRTY_DEFINED_NAME_SET_CACHE.set(unitDefinedNameMap, normalizedNameSet);
10130
+ }
10131
+ return normalizedNameSet;
10132
+ }
10133
+ function getDirtySuperTableReferencePattern(unitSuperTableMap) {
10134
+ let tableReferencePattern = DIRTY_SUPER_TABLE_PATTERN_CACHE.get(unitSuperTableMap);
10135
+ if (tableReferencePattern === void 0) {
10136
+ const escapedTableNames = Object.keys(unitSuperTableMap).filter((tableName) => tableName.length > 0).map(escapeRegExp);
10137
+ tableReferencePattern = escapedTableNames.length > 0 ? new RegExp(`(^|[^A-Za-z0-9_])(?:${escapedTableNames.join("|")})(\\s*\\[|$|[^A-Za-z0-9_])`, "i") : null;
10138
+ DIRTY_SUPER_TABLE_PATTERN_CACHE.set(unitSuperTableMap, tableReferencePattern);
10139
+ }
10140
+ return tableReferencePattern;
10141
+ }
9966
10142
  function isDirtyDefinedForNode(node, currentConfigService) {
9967
10143
  const definedNameMap = currentConfigService.getDirtyDefinedNameMap();
9968
10144
  const executeUnitId = currentConfigService.getExecuteUnitId();
@@ -11760,9 +11936,7 @@ var DependencyManagerBaseService = class extends Disposable {
11760
11936
  clearFormulaDependency(unitId, sheetId) {
11761
11937
  throw new Error("Method not implemented.");
11762
11938
  }
11763
- removeFormulaDependencyByDefinedName(unitId, definedName) {
11764
- throw new Error("Method not implemented.");
11765
- }
11939
+ removeFormulaDependencyByDefinedName(unitId, definedName) {}
11766
11940
  searchDependency(search, exceptTreeIds) {
11767
11941
  return this._dependencyRTreeCache.bulkSearch(search, exceptTreeIds);
11768
11942
  }
@@ -13871,7 +14045,7 @@ let CalculateController = class CalculateController extends Disposable {
13871
14045
  }));
13872
14046
  }
13873
14047
  async _calculate(formulaDirtyData) {
13874
- const { forceCalculation: forceCalculate = false, dirtyRanges = [], dirtyNameMap = {}, dirtyDefinedNameMap = {}, dirtyUnitFeatureMap = {}, dirtyUnitOtherFormulaMap = {}, clearDependencyTreeCache = {}, maxIteration = 1, rowData, isCalculateTreeModel = false } = formulaDirtyData;
14048
+ const { forceCalculation: forceCalculate = false, dirtyRanges = [], dirtyNameMap = {}, dirtyDefinedNameMap = {}, dirtySuperTableMap = {}, dirtyUnitFeatureMap = {}, dirtyUnitOtherFormulaMap = {}, clearDependencyTreeCache = {}, maxIteration = 1, rowData, isCalculateTreeModel = false } = formulaDirtyData;
13875
14049
  const formulaData = this._formulaDataModel.getFormulaData();
13876
14050
  const arrayFormulaCellData = this._formulaDataModel.getArrayFormulaCellData();
13877
14051
  const arrayFormulaRange = this._formulaDataModel.getArrayFormulaRange();
@@ -13883,6 +14057,7 @@ let CalculateController = class CalculateController extends Disposable {
13883
14057
  dirtyRanges,
13884
14058
  dirtyNameMap,
13885
14059
  dirtyDefinedNameMap,
14060
+ dirtySuperTableMap,
13886
14061
  dirtyUnitFeatureMap,
13887
14062
  dirtyUnitOtherFormulaMap,
13888
14063
  clearDependencyTreeCache,
@@ -24110,14 +24285,14 @@ function guessIsNaNorInfinity(guess, iterF) {
24110
24285
  const max = Number.MAX_VALUE;
24111
24286
  const min = -1;
24112
24287
  const step = 1.6;
24113
- let low = guess - .01 <= min ? min + g_Eps : guess - .01;
24288
+ let low = guess - .01 <= min ? -.9999999 : guess - .01;
24114
24289
  let high = guess + .01 >= max ? max - g_Eps : guess + .01;
24115
24290
  let xBegin;
24116
24291
  let xEnd;
24117
24292
  let currentIter = 0;
24118
24293
  if (guess <= min || guess >= max) return ErrorValueObject.create("#NUM!");
24119
24294
  for (let i = 0; i < nIM; i++) {
24120
- xBegin = low <= min ? min + g_Eps : low;
24295
+ xBegin = low <= min ? -.9999999 : low;
24121
24296
  xEnd = high >= max ? max - g_Eps : high;
24122
24297
  const x = iterF(xBegin);
24123
24298
  const y = iterF(xEnd);
@@ -32713,7 +32888,7 @@ var Roundbank = class extends BaseFunction {
32713
32888
  const integerPart = Math.floor(adjustedNum);
32714
32889
  const decimalPart = adjustedNum - integerPart;
32715
32890
  let result = Math.round(adjustedNum);
32716
- if (decimalPart > .5 - EPSILON && decimalPart < .5 + EPSILON) result = integerPart % 2 === 0 ? integerPart : integerPart + 1;
32891
+ if (decimalPart > .5 - EPSILON && decimalPart < .50000001) result = integerPart % 2 === 0 ? integerPart : integerPart + 1;
32717
32892
  return numDigits ? result / multiplier : result;
32718
32893
  }
32719
32894
  };
@@ -40031,10 +40206,7 @@ var Textsplit = class extends BaseFunction {
40031
40206
  if (valueObject.isNull()) value = "\\s";
40032
40207
  if (valueObject.isBoolean()) value = value ? "TRUE" : "FALSE";
40033
40208
  value += "";
40034
- return this._escapeRegExp(value);
40035
- }
40036
- _escapeRegExp(string) {
40037
- return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
40209
+ return escapeRegExp(value);
40038
40210
  }
40039
40211
  };
40040
40212
 
@@ -40417,7 +40589,7 @@ function getObjectValue(result, isUseStrip = false) {
40417
40589
  //#endregion
40418
40590
  //#region package.json
40419
40591
  var name = "@univerjs/engine-formula";
40420
- var version = "0.24.0";
40592
+ var version = "0.25.0-insiders.20260608-e4336f7";
40421
40593
 
40422
40594
  //#endregion
40423
40595
  //#region src/services/global-computing-status.service.ts
@@ -40475,7 +40647,7 @@ let ComputingStatusReporterController = class ComputingStatusReporterController
40475
40647
  const params = command.params;
40476
40648
  if (params.stageInfo) return observe.next(params.stageInfo.stage === 0 || params.stageInfo.stage === 8);
40477
40649
  });
40478
- }).pipe(distinctUntilChanged(), shareReplay()));
40650
+ }).pipe(distinctUntilChanged(), shareReplay({ refCount: true })));
40479
40651
  const disposables = new DisposableCollection();
40480
40652
  const subject = new BehaviorSubject(true);
40481
40653
  disposables.add(this._globalComputingSrv.pushComputingStatusSubject(subject));
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.129.0/helpers/decorateParam.js
6
+ //#region \0@oxc-project+runtime@0.134.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.129.0/helpers/decorate.js
14
+ //#region \0@oxc-project+runtime@0.134.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);
@@ -146,7 +146,7 @@ let FFormula = class FFormula extends FBase {
146
146
  });
147
147
  }
148
148
  /**
149
- * @deprecated Use `onCalculationEnd` instead.
149
+ * @deprecated Use `onCalculationResultApplied` instead.
150
150
  */
151
151
  whenComputingCompleteAsync(timeout) {
152
152
  const gcss = this._injector.get(GlobalComputingStatusService);
@@ -154,8 +154,7 @@ let FFormula = class FFormula extends FBase {
154
154
  return firstValueFrom(race(gcss.computingStatus$.pipe(filter((computing) => computing)), timer(timeout !== null && timeout !== void 0 ? timeout : 3e4).pipe(map(() => false))));
155
155
  }
156
156
  /**
157
- * Waits for the formula calculation to complete.
158
- * @returns {Promise<void>} This method returns a promise that resolves when the calculation is complete.
157
+ * @deprecated Use `onCalculationResultApplied` instead.
159
158
  */
160
159
  onCalculationEnd() {
161
160
  return new Promise((resolve, reject) => {