@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/cjs/facade.js CHANGED
@@ -4,7 +4,7 @@ let _univerjs_core = require("@univerjs/core");
4
4
  let _univerjs_engine_formula = require("@univerjs/engine-formula");
5
5
  let rxjs = require("rxjs");
6
6
 
7
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
7
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/decorateParam.js
8
8
  function __decorateParam(paramIndex, decorator) {
9
9
  return function(target, key) {
10
10
  decorator(target, key, paramIndex);
@@ -12,7 +12,7 @@ function __decorateParam(paramIndex, decorator) {
12
12
  }
13
13
 
14
14
  //#endregion
15
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
15
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/decorate.js
16
16
  function __decorate(decorators, target, key, desc) {
17
17
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
18
18
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -147,7 +147,7 @@ let FFormula = class FFormula extends _univerjs_core_facade.FBase {
147
147
  });
148
148
  }
149
149
  /**
150
- * @deprecated Use `onCalculationEnd` instead.
150
+ * @deprecated Use `onCalculationResultApplied` instead.
151
151
  */
152
152
  whenComputingCompleteAsync(timeout) {
153
153
  const gcss = this._injector.get(_univerjs_engine_formula.GlobalComputingStatusService);
@@ -155,8 +155,7 @@ let FFormula = class FFormula extends _univerjs_core_facade.FBase {
155
155
  return (0, rxjs.firstValueFrom)((0, rxjs.race)(gcss.computingStatus$.pipe((0, rxjs.filter)((computing) => computing)), (0, rxjs.timer)(timeout !== null && timeout !== void 0 ? timeout : 3e4).pipe((0, rxjs.map)(() => false))));
156
156
  }
157
157
  /**
158
- * Waits for the formula calculation to complete.
159
- * @returns {Promise<void>} This method returns a promise that resolves when the calculation is complete.
158
+ * @deprecated Use `onCalculationResultApplied` instead.
160
159
  */
161
160
  onCalculationEnd() {
162
161
  return new Promise((resolve, reject) => {
package/lib/cjs/index.js CHANGED
@@ -42,7 +42,7 @@ let BooleanValue = /* @__PURE__ */ function(BooleanValue) {
42
42
  }({});
43
43
 
44
44
  //#endregion
45
- //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
45
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/typeof.js
46
46
  function _typeof(o) {
47
47
  "@babel/helpers - typeof";
48
48
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -53,7 +53,7 @@ function _typeof(o) {
53
53
  }
54
54
 
55
55
  //#endregion
56
- //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
56
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPrimitive.js
57
57
  function toPrimitive(t, r) {
58
58
  if ("object" != _typeof(t) || !t) return t;
59
59
  var e = t[Symbol.toPrimitive];
@@ -66,14 +66,14 @@ function toPrimitive(t, r) {
66
66
  }
67
67
 
68
68
  //#endregion
69
- //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
69
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPropertyKey.js
70
70
  function toPropertyKey(t) {
71
71
  var i = toPrimitive(t, "string");
72
72
  return "symbol" == _typeof(i) ? i : i + "";
73
73
  }
74
74
 
75
75
  //#endregion
76
- //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
76
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/defineProperty.js
77
77
  function _defineProperty(e, r, t) {
78
78
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
79
79
  value: t,
@@ -875,7 +875,7 @@ function getWeekDayByDateSerialNumber(dateSerialNumber) {
875
875
  let date = excelSerialToDate(dateSerialNumber);
876
876
  const leapDayDateTime = Date.UTC(1900, 1, 28);
877
877
  const dateTime = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
878
- if (!isDate19000229 && dateTime <= leapDayDateTime) date = new Date(dateTime - perDayMilliseconds);
878
+ if (!isDate19000229 && dateTime <= leapDayDateTime) date = /* @__PURE__ */ new Date(dateTime - perDayMilliseconds);
879
879
  return date.getUTCDay();
880
880
  }
881
881
  function getTwoDateDaysByBasis(startDateSerialNumber, endDateSerialNumber, basis) {
@@ -1877,7 +1877,7 @@ function splitTableStructuredRef(ref) {
1877
1877
  }
1878
1878
 
1879
1879
  //#endregion
1880
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
1880
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/decorateParam.js
1881
1881
  function __decorateParam(paramIndex, decorator) {
1882
1882
  return function(target, key) {
1883
1883
  decorator(target, key, paramIndex);
@@ -1885,7 +1885,7 @@ function __decorateParam(paramIndex, decorator) {
1885
1885
  }
1886
1886
 
1887
1887
  //#endregion
1888
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
1888
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/decorate.js
1889
1889
  function __decorate(decorators, target, key, desc) {
1890
1890
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1891
1891
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -4938,9 +4938,7 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
4938
4938
  }
4939
4939
  getFormulaData() {
4940
4940
  const formulaData = {};
4941
- const allSheets = this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
4942
- if (allSheets.length === 0) return formulaData;
4943
- allSheets.forEach((workbook) => {
4941
+ this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).forEach((workbook) => {
4944
4942
  const unitId = workbook.getUnitId();
4945
4943
  formulaData[unitId] = {};
4946
4944
  workbook.getSheets().forEach((worksheet) => {
@@ -4948,6 +4946,32 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
4948
4946
  initSheetFormulaData(formulaData, unitId, worksheet.getSheetId(), cellMatrix);
4949
4947
  });
4950
4948
  });
4949
+ this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_BASE).forEach((base) => {
4950
+ const snapshot = base.getSnapshot();
4951
+ const unitId = base.getUnitId();
4952
+ formulaData[unitId] = {};
4953
+ Object.values(snapshot.tables).filter((table) => !table.deleted).forEach((table) => {
4954
+ var _table$recordOrder;
4955
+ const tableFormulaData = {};
4956
+ (_table$recordOrder = table.recordOrder) === null || _table$recordOrder === void 0 || _table$recordOrder.forEach((recordId, row) => {
4957
+ const record = table.records[recordId];
4958
+ if (!record || record.deleted) return;
4959
+ table.fieldOrder.forEach((fieldId, col) => {
4960
+ var _field$config$formula, _field$config, _tableFormulaData$row;
4961
+ const field = table.fields[fieldId];
4962
+ if (!field || field.deleted || field.type !== "formula") return;
4963
+ 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();
4964
+ if (!formula) return;
4965
+ (_tableFormulaData$row = tableFormulaData[row]) !== null && _tableFormulaData$row !== void 0 || (tableFormulaData[row] = {});
4966
+ tableFormulaData[row][col] = {
4967
+ f: normalizeBaseFormulaForEngine(formula, table, snapshot),
4968
+ si: field.id
4969
+ };
4970
+ });
4971
+ });
4972
+ formulaData[unitId][table.id] = tableFormulaData;
4973
+ });
4974
+ });
4951
4975
  return formulaData;
4952
4976
  }
4953
4977
  getSheetFormulaData(unitId, sheetId) {
@@ -5051,6 +5075,33 @@ let FormulaDataModel = class FormulaDataModel extends _univerjs_core.Disposable
5051
5075
  unitStylesData[unitId] = workbook.getStyles();
5052
5076
  unitSheetNameMap[unitId] = sheetNameMap;
5053
5077
  }
5078
+ const unitAllBases = this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_BASE);
5079
+ for (const base of unitAllBases) {
5080
+ const snapshot = base.getSnapshot();
5081
+ const unitId = base.getUnitId();
5082
+ const baseData = {};
5083
+ const tableNameMap = {};
5084
+ for (const table of Object.values(snapshot.tables).filter((item) => !item.deleted)) {
5085
+ var _table$recordOrder$fi, _table$recordOrder2;
5086
+ baseData[table.id] = {
5087
+ cellData: new _univerjs_core.ObjectMatrix(buildBaseRuntimeCellData(table)),
5088
+ rowCount: (_table$recordOrder$fi = (_table$recordOrder2 = table.recordOrder) === null || _table$recordOrder2 === void 0 ? void 0 : _table$recordOrder2.filter((recordId) => {
5089
+ var _table$records$record;
5090
+ return !((_table$records$record = table.records[recordId]) === null || _table$records$record === void 0 ? void 0 : _table$records$record.deleted);
5091
+ }).length) !== null && _table$recordOrder$fi !== void 0 ? _table$recordOrder$fi : 0,
5092
+ columnCount: table.fieldOrder.filter((fieldId) => {
5093
+ var _table$fields$fieldId;
5094
+ return !((_table$fields$fieldId = table.fields[fieldId]) === null || _table$fields$fieldId === void 0 ? void 0 : _table$fields$fieldId.deleted);
5095
+ }).length,
5096
+ rowData: {},
5097
+ columnData: {}
5098
+ };
5099
+ tableNameMap[table.name] = table.id;
5100
+ }
5101
+ allUnitData[unitId] = baseData;
5102
+ unitStylesData[unitId] = new _univerjs_core.Styles();
5103
+ unitSheetNameMap[unitId] = tableNameMap;
5104
+ }
5054
5105
  return {
5055
5106
  allUnitData,
5056
5107
  unitStylesData,
@@ -5339,6 +5390,95 @@ function initSheetFormulaData(formulaData, unitId, sheetId, cellMatrix) {
5339
5390
  const newSheetFormulaData = sheetFormulaDataMatrix.getMatrix();
5340
5391
  return { [unitId]: { [sheetId]: newSheetFormulaData } };
5341
5392
  }
5393
+ const BASE_LEGACY_FIELD_REF_PATTERN = /\{([^}]+)\}/g;
5394
+ const BASE_TABLE_FIELD_REF_PATTERN = /\b([A-Z_]\w*)\[([^\]]+)\]/gi;
5395
+ const BASE_BRACKET_FIELD_REF_PATTERN = /(^|[^A-Za-z0-9_\]\[])\[([^\]]+)\]/g;
5396
+ function normalizeBaseFormulaForEngine(formula, currentTable, snapshot) {
5397
+ const refs = [];
5398
+ const hold = (ref) => {
5399
+ return `__BASE_FORMULA_REF_${refs.push(ref) - 1}__`;
5400
+ };
5401
+ return formula.replace(BASE_LEGACY_FIELD_REF_PATTERN, (_match, fieldName) => hold(createEngineThisRowRef(currentTable, fieldName, snapshot))).replace(BASE_TABLE_FIELD_REF_PATTERN, (_match, sourceTableName, fieldName) => {
5402
+ const targetTable = resolveBaseFormulaTable(sourceTableName, currentTable, snapshot);
5403
+ return targetTable ? hold(createEngineThisRowRef(targetTable, fieldName, snapshot)) : `${sourceTableName}[${fieldName}]`;
5404
+ }).replace(BASE_BRACKET_FIELD_REF_PATTERN, (_match, prefix, fieldName) => `${prefix}${hold(createEngineThisRowRef(currentTable, fieldName, snapshot))}`).replace(/__BASE_FORMULA_REF_(\d+)__/g, (_match, index) => {
5405
+ var _refs$Number;
5406
+ return (_refs$Number = refs[Number(index)]) !== null && _refs$Number !== void 0 ? _refs$Number : "";
5407
+ });
5408
+ }
5409
+ function createEngineThisRowRef(table, fieldName, snapshot) {
5410
+ return `${getEngineBaseTableName(table, snapshot)}[[#This Row],[${fieldName}]]`;
5411
+ }
5412
+ function getEngineBaseTableName(table, snapshot) {
5413
+ return Object.values(snapshot.tables).filter((item) => !item.deleted && item.name === table.name).length === 1 ? table.name : table.id;
5414
+ }
5415
+ function buildBaseRuntimeCellData(table) {
5416
+ var _table$recordOrder$fi2, _table$recordOrder3, _table$records;
5417
+ const cellData = { ...table.cellData };
5418
+ const fieldOrder = table.fieldOrder.filter((fieldId) => table.fields[fieldId] && !table.fields[fieldId].deleted);
5419
+ ((_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) => {
5420
+ const record = table.records[recordId];
5421
+ if (!record || record.deleted) return;
5422
+ cellData[row] = { ...cellData[row] };
5423
+ fieldOrder.forEach((fieldId, col) => {
5424
+ var _record$values;
5425
+ if (!Object.prototype.hasOwnProperty.call((_record$values = record.values) !== null && _record$values !== void 0 ? _record$values : {}, fieldId)) return;
5426
+ cellData[row][col] = toBaseRuntimeCellData(record.values[fieldId], table.fields[fieldId]);
5427
+ });
5428
+ });
5429
+ return cellData;
5430
+ }
5431
+ function toBaseRuntimeCellData(value, field) {
5432
+ if (isBaseCellData(value)) return normalizeBaseCellData(value);
5433
+ if ((field === null || field === void 0 ? void 0 : field.type) === "attachment") return {
5434
+ v: "",
5435
+ t: _univerjs_core.CellValueType.STRING
5436
+ };
5437
+ if (Array.isArray(value)) return {
5438
+ v: value.join(", "),
5439
+ t: _univerjs_core.CellValueType.STRING
5440
+ };
5441
+ if ((field === null || field === void 0 ? void 0 : field.type) === "link" && value && typeof value === "object") {
5442
+ var _ref, _link$text;
5443
+ const link = value;
5444
+ return {
5445
+ v: String((_ref = (_link$text = link.text) !== null && _link$text !== void 0 ? _link$text : link.url) !== null && _ref !== void 0 ? _ref : ""),
5446
+ t: _univerjs_core.CellValueType.STRING
5447
+ };
5448
+ }
5449
+ if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") return {
5450
+ v: value,
5451
+ t: inferBaseRuntimeCellType(value)
5452
+ };
5453
+ return {
5454
+ v: null,
5455
+ t: null
5456
+ };
5457
+ }
5458
+ function normalizeBaseCellData(cell) {
5459
+ var _cell$v;
5460
+ const type = inferBaseRuntimeCellType((_cell$v = cell.v) !== null && _cell$v !== void 0 ? _cell$v : null);
5461
+ return {
5462
+ ...cell,
5463
+ t: type
5464
+ };
5465
+ }
5466
+ function inferBaseRuntimeCellType(value) {
5467
+ if (typeof value === "number") return _univerjs_core.CellValueType.NUMBER;
5468
+ if (typeof value === "boolean") return _univerjs_core.CellValueType.BOOLEAN;
5469
+ if (typeof value === "string") return _univerjs_core.CellValueType.STRING;
5470
+ return null;
5471
+ }
5472
+ function isBaseCellData(value) {
5473
+ 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"));
5474
+ }
5475
+ function resolveBaseFormulaTable(tableName, currentTable, snapshot) {
5476
+ if (!tableName || tableName === "table" || tableName === currentTable.id || tableName === currentTable.name) return currentTable;
5477
+ const byId = snapshot.tables[tableName];
5478
+ if (byId && !byId.deleted) return byId;
5479
+ const matches = Object.values(snapshot.tables).filter((table) => !table.deleted && table.name === tableName);
5480
+ return matches.length === 1 ? matches[0] : void 0;
5481
+ }
5342
5482
 
5343
5483
  //#endregion
5344
5484
  //#region src/services/sheet-row-filtered.service.ts
@@ -5393,6 +5533,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
5393
5533
  _defineProperty(this, "_dirtyRanges", []);
5394
5534
  _defineProperty(this, "_dirtyNameMap", {});
5395
5535
  _defineProperty(this, "_dirtyDefinedNameMap", {});
5536
+ _defineProperty(this, "_dirtySuperTableMap", {});
5396
5537
  _defineProperty(this, "_dirtyUnitFeatureMap", {});
5397
5538
  _defineProperty(this, "_dirtyUnitOtherFormulaMap", {});
5398
5539
  _defineProperty(this, "_excludedCell", void 0);
@@ -5412,6 +5553,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
5412
5553
  this._dirtyRanges = [];
5413
5554
  this._dirtyNameMap = {};
5414
5555
  this._dirtyDefinedNameMap = {};
5556
+ this._dirtySuperTableMap = {};
5415
5557
  this._dirtyUnitFeatureMap = {};
5416
5558
  this._dirtyUnitOtherFormulaMap = {};
5417
5559
  this._excludedCell = {};
@@ -5462,6 +5604,9 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
5462
5604
  getDirtyDefinedNameMap() {
5463
5605
  return this._dirtyDefinedNameMap;
5464
5606
  }
5607
+ getDirtySuperTableMap() {
5608
+ return this._dirtySuperTableMap;
5609
+ }
5465
5610
  getDirtyUnitFeatureMap() {
5466
5611
  return this._dirtyUnitFeatureMap;
5467
5612
  }
@@ -5527,6 +5672,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
5527
5672
  this._dirtyRanges = config.dirtyRanges;
5528
5673
  this._dirtyNameMap = config.dirtyNameMap;
5529
5674
  this._dirtyDefinedNameMap = config.dirtyDefinedNameMap;
5675
+ this._dirtySuperTableMap = config.dirtySuperTableMap || {};
5530
5676
  this._dirtyUnitFeatureMap = config.dirtyUnitFeatureMap;
5531
5677
  this._dirtyUnitOtherFormulaMap = config.dirtyUnitOtherFormulaMap;
5532
5678
  this._excludedCell = config.excludedCell;
@@ -5548,6 +5694,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
5548
5694
  dirtyRanges: this._dirtyRanges,
5549
5695
  dirtyNameMap: this._dirtyNameMap,
5550
5696
  dirtyDefinedNameMap: this._dirtyDefinedNameMap,
5697
+ dirtySuperTableMap: this._dirtySuperTableMap,
5551
5698
  dirtyUnitFeatureMap: this._dirtyUnitFeatureMap,
5552
5699
  dirtyUnitOtherFormulaMap: this._dirtyUnitOtherFormulaMap,
5553
5700
  clearDependencyTreeCache: this._clearDependencyTreeCache
@@ -5586,10 +5733,13 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
5586
5733
  });
5587
5734
  }
5588
5735
  _loadSheetData() {
5736
+ var _workbook$getUnitId, _worksheet$getSheetId;
5589
5737
  const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
5590
5738
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
5591
- this._executeUnitId = workbook === null || workbook === void 0 ? void 0 : workbook.getUnitId();
5592
- this._executeSubUnitId = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId();
5739
+ const base = workbook ? null : this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_BASE);
5740
+ const table = base ? getFirstLiveBaseTable(base.getSnapshot().tables, base.getSnapshot().tableOrder) : null;
5741
+ 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();
5742
+ 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;
5593
5743
  return this._formulaDataModel.getCalculateData();
5594
5744
  }
5595
5745
  /**
@@ -5620,6 +5770,14 @@ FormulaCurrentConfigService = __decorate([
5620
5770
  __decorateParam(2, (0, _univerjs_core.Inject)(FormulaDataModel)),
5621
5771
  __decorateParam(3, (0, _univerjs_core.Inject)(ISheetRowFilteredService))
5622
5772
  ], FormulaCurrentConfigService);
5773
+ function getFirstLiveBaseTable(tables, tableOrder) {
5774
+ var _Object$values$find;
5775
+ for (const tableId of tableOrder) {
5776
+ const table = tables[tableId];
5777
+ if (table && !table.deleted) return table;
5778
+ }
5779
+ return (_Object$values$find = Object.values(tables).find((table) => !table.deleted)) !== null && _Object$values$find !== void 0 ? _Object$values$find : null;
5780
+ }
5623
5781
  const IFormulaCurrentConfigService = (0, _univerjs_core.createIdentifier)("univer.formula.current-data.service");
5624
5782
 
5625
5783
  //#endregion
@@ -5662,22 +5820,6 @@ Lexer = __decorate([
5662
5820
  __decorateParam(2, IFormulaCurrentConfigService)
5663
5821
  ], Lexer);
5664
5822
 
5665
- //#endregion
5666
- //#region src/basics/is-null-cell.ts
5667
- /**
5668
- * Examine if a cell is empty (null) in the formula-related modules. This is not
5669
- * interchangable with {@link isNullCell} from the core package, because for
5670
- * formulas, "custom" field is meaningless.
5671
- */
5672
- function isNullCellForFormula(cell) {
5673
- if (cell == null) return true;
5674
- const { v, f, si, p } = cell;
5675
- if (!(v == null || typeof v === "string" && v.length === 0)) return false;
5676
- if (f != null && f.length > 0 || si != null && si.length > 0) return false;
5677
- if (p != null) return false;
5678
- return true;
5679
- }
5680
-
5681
5823
  //#endregion
5682
5824
  //#region src/engine/utils/cell.ts
5683
5825
  function getCellValue(cell) {
@@ -5729,7 +5871,7 @@ function isWildcard(str) {
5729
5871
  return str.indexOf("*") > -1 || str.indexOf("?") > -1;
5730
5872
  }
5731
5873
  function isMatchWildcard(currentValue, value) {
5732
- const pattern = escapeRegExp(value).replace(/~?[*?]/g, (match) => {
5874
+ const pattern = escapeRegExpForWildcard(value).replace(/~?[*?]/g, (match) => {
5733
5875
  if (match.startsWith("~")) return `\\${match.substring(1)}`;
5734
5876
  if (match === "*") return ".*";
5735
5877
  if (match === "?") return ".";
@@ -5764,7 +5906,7 @@ function compareWithWildcard(currentValue, value, operator) {
5764
5906
  }
5765
5907
  return result;
5766
5908
  }
5767
- function escapeRegExp(str) {
5909
+ function escapeRegExpForWildcard(str) {
5768
5910
  return str.replace(/[.+^${}()|[\]\\]/g, "\\$&");
5769
5911
  }
5770
5912
  function getMatchModeValue(matchModeValue) {
@@ -5813,11 +5955,20 @@ const localeCurrencySymbolMap = new Map([
5813
5955
  [_univerjs_core.LocaleType.VI_VN, "₫"],
5814
5956
  [_univerjs_core.LocaleType.ZH_CN, "¥"],
5815
5957
  [_univerjs_core.LocaleType.ZH_TW, "NT$"],
5958
+ [_univerjs_core.LocaleType.ZH_HK, "HK$"],
5816
5959
  [_univerjs_core.LocaleType.FR_FR, "€"],
5817
5960
  [_univerjs_core.LocaleType.FA_IR, "﷼"],
5818
5961
  [_univerjs_core.LocaleType.KO_KR, "₩"],
5819
5962
  [_univerjs_core.LocaleType.ES_ES, "€"],
5820
- [_univerjs_core.LocaleType.CA_ES, "€"]
5963
+ [_univerjs_core.LocaleType.CA_ES, "€"],
5964
+ [_univerjs_core.LocaleType.SK_SK, "€"],
5965
+ [_univerjs_core.LocaleType.JA_JP, "¥"],
5966
+ [_univerjs_core.LocaleType.PT_BR, "R$"],
5967
+ [_univerjs_core.LocaleType.DE_DE, "€"],
5968
+ [_univerjs_core.LocaleType.IT_IT, "€"],
5969
+ [_univerjs_core.LocaleType.ID_ID, "Rp"],
5970
+ [_univerjs_core.LocaleType.PL_PL, "zł"],
5971
+ [_univerjs_core.LocaleType.AR_SA, "﷼"]
5821
5972
  ]);
5822
5973
  function getCurrencySymbol(locale) {
5823
5974
  return localeCurrencySymbolMap.get(locale) || "$";
@@ -8245,7 +8396,7 @@ var BaseReferenceObject = class extends ObjectClassType {
8245
8396
  if (r < 0 || c < 0) return callback(ErrorValueObject.create("#REF!"), r, c);
8246
8397
  const cell = this.getCellData(r, c);
8247
8398
  let result = false;
8248
- if (isNullCellForFormula(cell)) {
8399
+ if ((0, _univerjs_core.isNullCell)(cell)) {
8249
8400
  result = callback(null, r, c);
8250
8401
  continue;
8251
8402
  }
@@ -9692,10 +9843,10 @@ let FormulaRuntimeService = class FormulaRuntimeService extends _univerjs_core.D
9692
9843
  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);
9693
9844
  const featureCell = this._getRuntimeFeatureCellValue(r, c, formulaSheetId, formulaUnitId);
9694
9845
  const isPreviousCellOfCurrentArrayFormula = this._arrayCellHasData(arrayDataCell) && this._isInArrayFormulaRange(previousArrayFormulaRange, r, c) && (currentCell == null || this._isSameCellValue(currentCell, arrayDataCell));
9695
- const hasRuntimeCell = !isNullCellForFormula(cell);
9846
+ const hasRuntimeCell = !(0, _univerjs_core.isNullCell)(cell);
9696
9847
  const isInOtherArrayFormulaRange = this._isInOtherArrayFormulaRange(formulaUnitId, formulaSheetId, formulaRow, formulaColumn, r, c);
9697
- const currentCellBlocks = !isNullCellForFormula(currentCell) && !isPreviousCellOfCurrentArrayFormula;
9698
- const featureCellBlocks = !isNullCellForFormula(featureCell);
9848
+ const currentCellBlocks = !(0, _univerjs_core.isNullCell)(currentCell) && !isPreviousCellOfCurrentArrayFormula;
9849
+ const featureCellBlocks = !(0, _univerjs_core.isNullCell)(featureCell);
9699
9850
  if (hasRuntimeCell || isInOtherArrayFormulaRange || currentCellBlocks || featureCellBlocks) return true;
9700
9851
  }
9701
9852
  return false;
@@ -9968,9 +10119,11 @@ const COLUMN_LIKE_FUNCTION_NAMES = new Set(ALL_GROUPS.flatMap((g) => Object.valu
9968
10119
  //#region src/engine/utils/generate-ast-node.ts
9969
10120
  const FORMULA_CACHE_LRU_COUNT = 5e3;
9970
10121
  const FORMULA_AST_CACHE = new FormulaAstLRU(FORMULA_CACHE_LRU_COUNT);
10122
+ const DIRTY_DEFINED_NAME_SET_CACHE = /* @__PURE__ */ new WeakMap();
10123
+ const DIRTY_SUPER_TABLE_PATTERN_CACHE = /* @__PURE__ */ new WeakMap();
9971
10124
  function generateAstNode(unitId, formulaString, lexer, astTreeBuilder, currentConfigService) {
9972
10125
  let astNode = FORMULA_AST_CACHE.get(`${unitId}${formulaString}`);
9973
- const noCache = checkIsChangedByDefinedName(unitId, formulaString, currentConfigService);
10126
+ const noCache = checkIsChangedByDefinedName(unitId, formulaString, currentConfigService) || checkIsChangedBySuperTable(unitId, formulaString, currentConfigService);
9974
10127
  if (!noCache && astNode && !isDirtyDefinedForNode(astNode, currentConfigService)) return astNode;
9975
10128
  const lexerNode = lexer.treeBuilder(formulaString);
9976
10129
  if (ERROR_TYPE_SET.has(lexerNode)) return ErrorNode.create(lexerNode);
@@ -9985,14 +10138,37 @@ function generateAstNode(unitId, formulaString, lexer, astTreeBuilder, currentCo
9985
10138
  function checkIsChangedByDefinedName(unitId, formula, currentConfigService) {
9986
10139
  const unitDefinedNameMap = currentConfigService.getDirtyDefinedNameMap()[unitId];
9987
10140
  if (unitDefinedNameMap == null) return false;
9988
- const formulaText = normalizeFormulaText(formula);
9989
- const names = Object.keys(unitDefinedNameMap);
9990
- for (let i = 0, len = names.length; i < len; i++) if (normalizeFormulaText(names[i]) === formulaText) return true;
9991
- return false;
10141
+ return getNormalizedDirtyDefinedNameSet(unitDefinedNameMap).has(normalizeFormulaText(formula));
9992
10142
  }
9993
10143
  function normalizeFormulaText(formula) {
9994
10144
  return formula.startsWith("=") ? formula.slice(1) : formula;
9995
10145
  }
10146
+ function checkIsChangedBySuperTable(unitId, formula, currentConfigService) {
10147
+ var _currentConfigService, _tableReferencePatter;
10148
+ const getDirtySuperTableMap = (_currentConfigService = currentConfigService.getDirtySuperTableMap) === null || _currentConfigService === void 0 ? void 0 : _currentConfigService.bind(currentConfigService);
10149
+ const changedSuperTableMap = getDirtySuperTableMap === null || getDirtySuperTableMap === void 0 ? void 0 : getDirtySuperTableMap();
10150
+ const unitSuperTableMap = changedSuperTableMap === null || changedSuperTableMap === void 0 ? void 0 : changedSuperTableMap[unitId];
10151
+ if (unitSuperTableMap == null) return false;
10152
+ const tableReferencePattern = getDirtySuperTableReferencePattern(unitSuperTableMap);
10153
+ return (_tableReferencePatter = tableReferencePattern === null || tableReferencePattern === void 0 ? void 0 : tableReferencePattern.test(normalizeFormulaText(formula))) !== null && _tableReferencePatter !== void 0 ? _tableReferencePatter : false;
10154
+ }
10155
+ function getNormalizedDirtyDefinedNameSet(unitDefinedNameMap) {
10156
+ let normalizedNameSet = DIRTY_DEFINED_NAME_SET_CACHE.get(unitDefinedNameMap);
10157
+ if (normalizedNameSet == null) {
10158
+ normalizedNameSet = new Set(Object.keys(unitDefinedNameMap).map(normalizeFormulaText));
10159
+ DIRTY_DEFINED_NAME_SET_CACHE.set(unitDefinedNameMap, normalizedNameSet);
10160
+ }
10161
+ return normalizedNameSet;
10162
+ }
10163
+ function getDirtySuperTableReferencePattern(unitSuperTableMap) {
10164
+ let tableReferencePattern = DIRTY_SUPER_TABLE_PATTERN_CACHE.get(unitSuperTableMap);
10165
+ if (tableReferencePattern === void 0) {
10166
+ const escapedTableNames = Object.keys(unitSuperTableMap).filter((tableName) => tableName.length > 0).map(_univerjs_core.escapeRegExp);
10167
+ tableReferencePattern = escapedTableNames.length > 0 ? new RegExp(`(^|[^A-Za-z0-9_])(?:${escapedTableNames.join("|")})(\\s*\\[|$|[^A-Za-z0-9_])`, "i") : null;
10168
+ DIRTY_SUPER_TABLE_PATTERN_CACHE.set(unitSuperTableMap, tableReferencePattern);
10169
+ }
10170
+ return tableReferencePattern;
10171
+ }
9996
10172
  function isDirtyDefinedForNode(node, currentConfigService) {
9997
10173
  const definedNameMap = currentConfigService.getDirtyDefinedNameMap();
9998
10174
  const executeUnitId = currentConfigService.getExecuteUnitId();
@@ -11790,9 +11966,7 @@ var DependencyManagerBaseService = class extends _univerjs_core.Disposable {
11790
11966
  clearFormulaDependency(unitId, sheetId) {
11791
11967
  throw new Error("Method not implemented.");
11792
11968
  }
11793
- removeFormulaDependencyByDefinedName(unitId, definedName) {
11794
- throw new Error("Method not implemented.");
11795
- }
11969
+ removeFormulaDependencyByDefinedName(unitId, definedName) {}
11796
11970
  searchDependency(search, exceptTreeIds) {
11797
11971
  return this._dependencyRTreeCache.bulkSearch(search, exceptTreeIds);
11798
11972
  }
@@ -13901,7 +14075,7 @@ let CalculateController = class CalculateController extends _univerjs_core.Dispo
13901
14075
  }));
13902
14076
  }
13903
14077
  async _calculate(formulaDirtyData) {
13904
- const { forceCalculation: forceCalculate = false, dirtyRanges = [], dirtyNameMap = {}, dirtyDefinedNameMap = {}, dirtyUnitFeatureMap = {}, dirtyUnitOtherFormulaMap = {}, clearDependencyTreeCache = {}, maxIteration = 1, rowData, isCalculateTreeModel = false } = formulaDirtyData;
14078
+ const { forceCalculation: forceCalculate = false, dirtyRanges = [], dirtyNameMap = {}, dirtyDefinedNameMap = {}, dirtySuperTableMap = {}, dirtyUnitFeatureMap = {}, dirtyUnitOtherFormulaMap = {}, clearDependencyTreeCache = {}, maxIteration = 1, rowData, isCalculateTreeModel = false } = formulaDirtyData;
13905
14079
  const formulaData = this._formulaDataModel.getFormulaData();
13906
14080
  const arrayFormulaCellData = this._formulaDataModel.getArrayFormulaCellData();
13907
14081
  const arrayFormulaRange = this._formulaDataModel.getArrayFormulaRange();
@@ -13913,6 +14087,7 @@ let CalculateController = class CalculateController extends _univerjs_core.Dispo
13913
14087
  dirtyRanges,
13914
14088
  dirtyNameMap,
13915
14089
  dirtyDefinedNameMap,
14090
+ dirtySuperTableMap,
13916
14091
  dirtyUnitFeatureMap,
13917
14092
  dirtyUnitOtherFormulaMap,
13918
14093
  clearDependencyTreeCache,
@@ -24140,14 +24315,14 @@ function guessIsNaNorInfinity(guess, iterF) {
24140
24315
  const max = Number.MAX_VALUE;
24141
24316
  const min = -1;
24142
24317
  const step = 1.6;
24143
- let low = guess - .01 <= min ? min + g_Eps : guess - .01;
24318
+ let low = guess - .01 <= min ? -.9999999 : guess - .01;
24144
24319
  let high = guess + .01 >= max ? max - g_Eps : guess + .01;
24145
24320
  let xBegin;
24146
24321
  let xEnd;
24147
24322
  let currentIter = 0;
24148
24323
  if (guess <= min || guess >= max) return ErrorValueObject.create("#NUM!");
24149
24324
  for (let i = 0; i < nIM; i++) {
24150
- xBegin = low <= min ? min + g_Eps : low;
24325
+ xBegin = low <= min ? -.9999999 : low;
24151
24326
  xEnd = high >= max ? max - g_Eps : high;
24152
24327
  const x = iterF(xBegin);
24153
24328
  const y = iterF(xEnd);
@@ -32743,7 +32918,7 @@ var Roundbank = class extends BaseFunction {
32743
32918
  const integerPart = Math.floor(adjustedNum);
32744
32919
  const decimalPart = adjustedNum - integerPart;
32745
32920
  let result = Math.round(adjustedNum);
32746
- if (decimalPart > .5 - EPSILON && decimalPart < .5 + EPSILON) result = integerPart % 2 === 0 ? integerPart : integerPart + 1;
32921
+ if (decimalPart > .5 - EPSILON && decimalPart < .50000001) result = integerPart % 2 === 0 ? integerPart : integerPart + 1;
32747
32922
  return numDigits ? result / multiplier : result;
32748
32923
  }
32749
32924
  };
@@ -40061,10 +40236,7 @@ var Textsplit = class extends BaseFunction {
40061
40236
  if (valueObject.isNull()) value = "\\s";
40062
40237
  if (valueObject.isBoolean()) value = value ? "TRUE" : "FALSE";
40063
40238
  value += "";
40064
- return this._escapeRegExp(value);
40065
- }
40066
- _escapeRegExp(string) {
40067
- return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
40239
+ return (0, _univerjs_core.escapeRegExp)(value);
40068
40240
  }
40069
40241
  };
40070
40242
 
@@ -40447,7 +40619,7 @@ function getObjectValue(result, isUseStrip = false) {
40447
40619
  //#endregion
40448
40620
  //#region package.json
40449
40621
  var name = "@univerjs/engine-formula";
40450
- var version = "0.24.0";
40622
+ var version = "0.25.0-insiders.20260608-e4336f7";
40451
40623
 
40452
40624
  //#endregion
40453
40625
  //#region src/services/global-computing-status.service.ts
@@ -40505,7 +40677,7 @@ let ComputingStatusReporterController = class ComputingStatusReporterController
40505
40677
  const params = command.params;
40506
40678
  if (params.stageInfo) return observe.next(params.stageInfo.stage === 0 || params.stageInfo.stage === 8);
40507
40679
  });
40508
- }).pipe((0, rxjs.distinctUntilChanged)(), (0, rxjs.shareReplay)()));
40680
+ }).pipe((0, rxjs.distinctUntilChanged)(), (0, rxjs.shareReplay)({ refCount: true })));
40509
40681
  const disposables = new _univerjs_core.DisposableCollection();
40510
40682
  const subject = new rxjs.BehaviorSubject(true);
40511
40683
  disposables.add(this._globalComputingSrv.pushComputingStatusSubject(subject));
package/lib/es/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) => {