@univerjs/engine-formula 0.23.0 → 0.24.0-insiders.20260528-29f582d

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
@@ -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
@@ -1781,7 +1781,7 @@ function replaceRefPrefixString(token) {
1781
1781
  /**
1782
1782
  * implement getSheetIdByName
1783
1783
  * function getSheetIdByName(name: string) {
1784
- return univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetName(name)?.getSheetId() || '';
1784
+ return univerInstanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetName(name)?.getSheetId() || '';
1785
1785
  }
1786
1786
  */
1787
1787
  function getRangeWithRefsString(refString, getSheetIdByName) {
@@ -5393,6 +5393,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
5393
5393
  _defineProperty(this, "_dirtyRanges", []);
5394
5394
  _defineProperty(this, "_dirtyNameMap", {});
5395
5395
  _defineProperty(this, "_dirtyDefinedNameMap", {});
5396
+ _defineProperty(this, "_dirtySuperTableMap", {});
5396
5397
  _defineProperty(this, "_dirtyUnitFeatureMap", {});
5397
5398
  _defineProperty(this, "_dirtyUnitOtherFormulaMap", {});
5398
5399
  _defineProperty(this, "_excludedCell", void 0);
@@ -5412,6 +5413,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
5412
5413
  this._dirtyRanges = [];
5413
5414
  this._dirtyNameMap = {};
5414
5415
  this._dirtyDefinedNameMap = {};
5416
+ this._dirtySuperTableMap = {};
5415
5417
  this._dirtyUnitFeatureMap = {};
5416
5418
  this._dirtyUnitOtherFormulaMap = {};
5417
5419
  this._excludedCell = {};
@@ -5462,6 +5464,9 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
5462
5464
  getDirtyDefinedNameMap() {
5463
5465
  return this._dirtyDefinedNameMap;
5464
5466
  }
5467
+ getDirtySuperTableMap() {
5468
+ return this._dirtySuperTableMap;
5469
+ }
5465
5470
  getDirtyUnitFeatureMap() {
5466
5471
  return this._dirtyUnitFeatureMap;
5467
5472
  }
@@ -5482,7 +5487,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
5482
5487
  return this._localeService.getCurrentLocale();
5483
5488
  }
5484
5489
  getSheetsInfo() {
5485
- const { id, sheetOrder } = this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).getSnapshot();
5490
+ const { id, sheetOrder } = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).getSnapshot();
5486
5491
  return {
5487
5492
  sheetOrder,
5488
5493
  sheetNameMap: this._sheetIdToNameMap[id]
@@ -5527,6 +5532,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
5527
5532
  this._dirtyRanges = config.dirtyRanges;
5528
5533
  this._dirtyNameMap = config.dirtyNameMap;
5529
5534
  this._dirtyDefinedNameMap = config.dirtyDefinedNameMap;
5535
+ this._dirtySuperTableMap = config.dirtySuperTableMap || {};
5530
5536
  this._dirtyUnitFeatureMap = config.dirtyUnitFeatureMap;
5531
5537
  this._dirtyUnitOtherFormulaMap = config.dirtyUnitOtherFormulaMap;
5532
5538
  this._excludedCell = config.excludedCell;
@@ -5548,6 +5554,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
5548
5554
  dirtyRanges: this._dirtyRanges,
5549
5555
  dirtyNameMap: this._dirtyNameMap,
5550
5556
  dirtyDefinedNameMap: this._dirtyDefinedNameMap,
5557
+ dirtySuperTableMap: this._dirtySuperTableMap,
5551
5558
  dirtyUnitFeatureMap: this._dirtyUnitFeatureMap,
5552
5559
  dirtyUnitOtherFormulaMap: this._dirtyUnitOtherFormulaMap,
5553
5560
  clearDependencyTreeCache: this._clearDependencyTreeCache
@@ -5586,7 +5593,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends _uni
5586
5593
  });
5587
5594
  }
5588
5595
  _loadSheetData() {
5589
- const workbook = this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
5596
+ const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
5590
5597
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
5591
5598
  this._executeUnitId = workbook === null || workbook === void 0 ? void 0 : workbook.getUnitId();
5592
5599
  this._executeSubUnitId = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId();
@@ -5662,22 +5669,6 @@ Lexer = __decorate([
5662
5669
  __decorateParam(2, IFormulaCurrentConfigService)
5663
5670
  ], Lexer);
5664
5671
 
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
5672
  //#endregion
5682
5673
  //#region src/engine/utils/cell.ts
5683
5674
  function getCellValue(cell) {
@@ -5729,7 +5720,7 @@ function isWildcard(str) {
5729
5720
  return str.indexOf("*") > -1 || str.indexOf("?") > -1;
5730
5721
  }
5731
5722
  function isMatchWildcard(currentValue, value) {
5732
- const pattern = escapeRegExp(value).replace(/~?[*?]/g, (match) => {
5723
+ const pattern = escapeRegExpForWildcard(value).replace(/~?[*?]/g, (match) => {
5733
5724
  if (match.startsWith("~")) return `\\${match.substring(1)}`;
5734
5725
  if (match === "*") return ".*";
5735
5726
  if (match === "?") return ".";
@@ -5764,7 +5755,7 @@ function compareWithWildcard(currentValue, value, operator) {
5764
5755
  }
5765
5756
  return result;
5766
5757
  }
5767
- function escapeRegExp(str) {
5758
+ function escapeRegExpForWildcard(str) {
5768
5759
  return str.replace(/[.+^${}()|[\]\\]/g, "\\$&");
5769
5760
  }
5770
5761
  function getMatchModeValue(matchModeValue) {
@@ -5813,11 +5804,20 @@ const localeCurrencySymbolMap = new Map([
5813
5804
  [_univerjs_core.LocaleType.VI_VN, "₫"],
5814
5805
  [_univerjs_core.LocaleType.ZH_CN, "¥"],
5815
5806
  [_univerjs_core.LocaleType.ZH_TW, "NT$"],
5807
+ [_univerjs_core.LocaleType.ZH_HK, "HK$"],
5816
5808
  [_univerjs_core.LocaleType.FR_FR, "€"],
5817
5809
  [_univerjs_core.LocaleType.FA_IR, "﷼"],
5818
5810
  [_univerjs_core.LocaleType.KO_KR, "₩"],
5819
5811
  [_univerjs_core.LocaleType.ES_ES, "€"],
5820
- [_univerjs_core.LocaleType.CA_ES, "€"]
5812
+ [_univerjs_core.LocaleType.CA_ES, "€"],
5813
+ [_univerjs_core.LocaleType.SK_SK, "€"],
5814
+ [_univerjs_core.LocaleType.JA_JP, "¥"],
5815
+ [_univerjs_core.LocaleType.PT_BR, "R$"],
5816
+ [_univerjs_core.LocaleType.DE_DE, "€"],
5817
+ [_univerjs_core.LocaleType.IT_IT, "€"],
5818
+ [_univerjs_core.LocaleType.ID_ID, "Rp"],
5819
+ [_univerjs_core.LocaleType.PL_PL, "zł"],
5820
+ [_univerjs_core.LocaleType.AR_SA, "﷼"]
5821
5821
  ]);
5822
5822
  function getCurrencySymbol(locale) {
5823
5823
  return localeCurrencySymbolMap.get(locale) || "$";
@@ -8245,7 +8245,7 @@ var BaseReferenceObject = class extends ObjectClassType {
8245
8245
  if (r < 0 || c < 0) return callback(ErrorValueObject.create("#REF!"), r, c);
8246
8246
  const cell = this.getCellData(r, c);
8247
8247
  let result = false;
8248
- if (isNullCellForFormula(cell)) {
8248
+ if ((0, _univerjs_core.isNullCell)(cell)) {
8249
8249
  result = callback(null, r, c);
8250
8250
  continue;
8251
8251
  }
@@ -9692,10 +9692,10 @@ let FormulaRuntimeService = class FormulaRuntimeService extends _univerjs_core.D
9692
9692
  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
9693
  const featureCell = this._getRuntimeFeatureCellValue(r, c, formulaSheetId, formulaUnitId);
9694
9694
  const isPreviousCellOfCurrentArrayFormula = this._arrayCellHasData(arrayDataCell) && this._isInArrayFormulaRange(previousArrayFormulaRange, r, c) && (currentCell == null || this._isSameCellValue(currentCell, arrayDataCell));
9695
- const hasRuntimeCell = !isNullCellForFormula(cell);
9695
+ const hasRuntimeCell = !(0, _univerjs_core.isNullCell)(cell);
9696
9696
  const isInOtherArrayFormulaRange = this._isInOtherArrayFormulaRange(formulaUnitId, formulaSheetId, formulaRow, formulaColumn, r, c);
9697
- const currentCellBlocks = !isNullCellForFormula(currentCell) && !isPreviousCellOfCurrentArrayFormula;
9698
- const featureCellBlocks = !isNullCellForFormula(featureCell);
9697
+ const currentCellBlocks = !(0, _univerjs_core.isNullCell)(currentCell) && !isPreviousCellOfCurrentArrayFormula;
9698
+ const featureCellBlocks = !(0, _univerjs_core.isNullCell)(featureCell);
9699
9699
  if (hasRuntimeCell || isInOtherArrayFormulaRange || currentCellBlocks || featureCellBlocks) return true;
9700
9700
  }
9701
9701
  return false;
@@ -9968,9 +9968,11 @@ const COLUMN_LIKE_FUNCTION_NAMES = new Set(ALL_GROUPS.flatMap((g) => Object.valu
9968
9968
  //#region src/engine/utils/generate-ast-node.ts
9969
9969
  const FORMULA_CACHE_LRU_COUNT = 5e3;
9970
9970
  const FORMULA_AST_CACHE = new FormulaAstLRU(FORMULA_CACHE_LRU_COUNT);
9971
+ const DIRTY_DEFINED_NAME_SET_CACHE = /* @__PURE__ */ new WeakMap();
9972
+ const DIRTY_SUPER_TABLE_PATTERN_CACHE = /* @__PURE__ */ new WeakMap();
9971
9973
  function generateAstNode(unitId, formulaString, lexer, astTreeBuilder, currentConfigService) {
9972
9974
  let astNode = FORMULA_AST_CACHE.get(`${unitId}${formulaString}`);
9973
- const noCache = checkIsChangedByDefinedName(unitId, formulaString, currentConfigService);
9975
+ const noCache = checkIsChangedByDefinedName(unitId, formulaString, currentConfigService) || checkIsChangedBySuperTable(unitId, formulaString, currentConfigService);
9974
9976
  if (!noCache && astNode && !isDirtyDefinedForNode(astNode, currentConfigService)) return astNode;
9975
9977
  const lexerNode = lexer.treeBuilder(formulaString);
9976
9978
  if (ERROR_TYPE_SET.has(lexerNode)) return ErrorNode.create(lexerNode);
@@ -9985,14 +9987,37 @@ function generateAstNode(unitId, formulaString, lexer, astTreeBuilder, currentCo
9985
9987
  function checkIsChangedByDefinedName(unitId, formula, currentConfigService) {
9986
9988
  const unitDefinedNameMap = currentConfigService.getDirtyDefinedNameMap()[unitId];
9987
9989
  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;
9990
+ return getNormalizedDirtyDefinedNameSet(unitDefinedNameMap).has(normalizeFormulaText(formula));
9992
9991
  }
9993
9992
  function normalizeFormulaText(formula) {
9994
9993
  return formula.startsWith("=") ? formula.slice(1) : formula;
9995
9994
  }
9995
+ function checkIsChangedBySuperTable(unitId, formula, currentConfigService) {
9996
+ var _currentConfigService, _tableReferencePatter;
9997
+ const getDirtySuperTableMap = (_currentConfigService = currentConfigService.getDirtySuperTableMap) === null || _currentConfigService === void 0 ? void 0 : _currentConfigService.bind(currentConfigService);
9998
+ const changedSuperTableMap = getDirtySuperTableMap === null || getDirtySuperTableMap === void 0 ? void 0 : getDirtySuperTableMap();
9999
+ const unitSuperTableMap = changedSuperTableMap === null || changedSuperTableMap === void 0 ? void 0 : changedSuperTableMap[unitId];
10000
+ if (unitSuperTableMap == null) return false;
10001
+ const tableReferencePattern = getDirtySuperTableReferencePattern(unitSuperTableMap);
10002
+ return (_tableReferencePatter = tableReferencePattern === null || tableReferencePattern === void 0 ? void 0 : tableReferencePattern.test(normalizeFormulaText(formula))) !== null && _tableReferencePatter !== void 0 ? _tableReferencePatter : false;
10003
+ }
10004
+ function getNormalizedDirtyDefinedNameSet(unitDefinedNameMap) {
10005
+ let normalizedNameSet = DIRTY_DEFINED_NAME_SET_CACHE.get(unitDefinedNameMap);
10006
+ if (normalizedNameSet == null) {
10007
+ normalizedNameSet = new Set(Object.keys(unitDefinedNameMap).map(normalizeFormulaText));
10008
+ DIRTY_DEFINED_NAME_SET_CACHE.set(unitDefinedNameMap, normalizedNameSet);
10009
+ }
10010
+ return normalizedNameSet;
10011
+ }
10012
+ function getDirtySuperTableReferencePattern(unitSuperTableMap) {
10013
+ let tableReferencePattern = DIRTY_SUPER_TABLE_PATTERN_CACHE.get(unitSuperTableMap);
10014
+ if (tableReferencePattern === void 0) {
10015
+ const escapedTableNames = Object.keys(unitSuperTableMap).filter((tableName) => tableName.length > 0).map(_univerjs_core.escapeRegExp);
10016
+ tableReferencePattern = escapedTableNames.length > 0 ? new RegExp(`(^|[^A-Za-z0-9_])(?:${escapedTableNames.join("|")})(\\s*\\[|$|[^A-Za-z0-9_])`, "i") : null;
10017
+ DIRTY_SUPER_TABLE_PATTERN_CACHE.set(unitSuperTableMap, tableReferencePattern);
10018
+ }
10019
+ return tableReferencePattern;
10020
+ }
9996
10021
  function isDirtyDefinedForNode(node, currentConfigService) {
9997
10022
  const definedNameMap = currentConfigService.getDirtyDefinedNameMap();
9998
10023
  const executeUnitId = currentConfigService.getExecuteUnitId();
@@ -11790,9 +11815,7 @@ var DependencyManagerBaseService = class extends _univerjs_core.Disposable {
11790
11815
  clearFormulaDependency(unitId, sheetId) {
11791
11816
  throw new Error("Method not implemented.");
11792
11817
  }
11793
- removeFormulaDependencyByDefinedName(unitId, definedName) {
11794
- throw new Error("Method not implemented.");
11795
- }
11818
+ removeFormulaDependencyByDefinedName(unitId, definedName) {}
11796
11819
  searchDependency(search, exceptTreeIds) {
11797
11820
  return this._dependencyRTreeCache.bulkSearch(search, exceptTreeIds);
11798
11821
  }
@@ -13901,7 +13924,7 @@ let CalculateController = class CalculateController extends _univerjs_core.Dispo
13901
13924
  }));
13902
13925
  }
13903
13926
  async _calculate(formulaDirtyData) {
13904
- const { forceCalculation: forceCalculate = false, dirtyRanges = [], dirtyNameMap = {}, dirtyDefinedNameMap = {}, dirtyUnitFeatureMap = {}, dirtyUnitOtherFormulaMap = {}, clearDependencyTreeCache = {}, maxIteration = 1, rowData, isCalculateTreeModel = false } = formulaDirtyData;
13927
+ const { forceCalculation: forceCalculate = false, dirtyRanges = [], dirtyNameMap = {}, dirtyDefinedNameMap = {}, dirtySuperTableMap = {}, dirtyUnitFeatureMap = {}, dirtyUnitOtherFormulaMap = {}, clearDependencyTreeCache = {}, maxIteration = 1, rowData, isCalculateTreeModel = false } = formulaDirtyData;
13905
13928
  const formulaData = this._formulaDataModel.getFormulaData();
13906
13929
  const arrayFormulaCellData = this._formulaDataModel.getArrayFormulaCellData();
13907
13930
  const arrayFormulaRange = this._formulaDataModel.getArrayFormulaRange();
@@ -13913,6 +13936,7 @@ let CalculateController = class CalculateController extends _univerjs_core.Dispo
13913
13936
  dirtyRanges,
13914
13937
  dirtyNameMap,
13915
13938
  dirtyDefinedNameMap,
13939
+ dirtySuperTableMap,
13916
13940
  dirtyUnitFeatureMap,
13917
13941
  dirtyUnitOtherFormulaMap,
13918
13942
  clearDependencyTreeCache,
@@ -40061,10 +40085,7 @@ var Textsplit = class extends BaseFunction {
40061
40085
  if (valueObject.isNull()) value = "\\s";
40062
40086
  if (valueObject.isBoolean()) value = value ? "TRUE" : "FALSE";
40063
40087
  value += "";
40064
- return this._escapeRegExp(value);
40065
- }
40066
- _escapeRegExp(string) {
40067
- return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
40088
+ return (0, _univerjs_core.escapeRegExp)(value);
40068
40089
  }
40069
40090
  };
40070
40091
 
@@ -40447,7 +40468,7 @@ function getObjectValue(result, isUseStrip = false) {
40447
40468
  //#endregion
40448
40469
  //#region package.json
40449
40470
  var name = "@univerjs/engine-formula";
40450
- var version = "0.23.0";
40471
+ var version = "0.24.0-insiders.20260528-29f582d";
40451
40472
 
40452
40473
  //#endregion
40453
40474
  //#region src/services/global-computing-status.service.ts
package/lib/es/facade.js CHANGED
@@ -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) => {
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, 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";
@@ -1751,7 +1751,7 @@ function replaceRefPrefixString(token) {
1751
1751
  /**
1752
1752
  * implement getSheetIdByName
1753
1753
  * function getSheetIdByName(name: string) {
1754
- return univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetName(name)?.getSheetId() || '';
1754
+ return univerInstanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetName(name)?.getSheetId() || '';
1755
1755
  }
1756
1756
  */
1757
1757
  function getRangeWithRefsString(refString, getSheetIdByName) {
@@ -5363,6 +5363,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5363
5363
  _defineProperty(this, "_dirtyRanges", []);
5364
5364
  _defineProperty(this, "_dirtyNameMap", {});
5365
5365
  _defineProperty(this, "_dirtyDefinedNameMap", {});
5366
+ _defineProperty(this, "_dirtySuperTableMap", {});
5366
5367
  _defineProperty(this, "_dirtyUnitFeatureMap", {});
5367
5368
  _defineProperty(this, "_dirtyUnitOtherFormulaMap", {});
5368
5369
  _defineProperty(this, "_excludedCell", void 0);
@@ -5382,6 +5383,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5382
5383
  this._dirtyRanges = [];
5383
5384
  this._dirtyNameMap = {};
5384
5385
  this._dirtyDefinedNameMap = {};
5386
+ this._dirtySuperTableMap = {};
5385
5387
  this._dirtyUnitFeatureMap = {};
5386
5388
  this._dirtyUnitOtherFormulaMap = {};
5387
5389
  this._excludedCell = {};
@@ -5432,6 +5434,9 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5432
5434
  getDirtyDefinedNameMap() {
5433
5435
  return this._dirtyDefinedNameMap;
5434
5436
  }
5437
+ getDirtySuperTableMap() {
5438
+ return this._dirtySuperTableMap;
5439
+ }
5435
5440
  getDirtyUnitFeatureMap() {
5436
5441
  return this._dirtyUnitFeatureMap;
5437
5442
  }
@@ -5452,7 +5457,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5452
5457
  return this._localeService.getCurrentLocale();
5453
5458
  }
5454
5459
  getSheetsInfo() {
5455
- const { id, sheetOrder } = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET).getSnapshot();
5460
+ const { id, sheetOrder } = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET).getSnapshot();
5456
5461
  return {
5457
5462
  sheetOrder,
5458
5463
  sheetNameMap: this._sheetIdToNameMap[id]
@@ -5497,6 +5502,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5497
5502
  this._dirtyRanges = config.dirtyRanges;
5498
5503
  this._dirtyNameMap = config.dirtyNameMap;
5499
5504
  this._dirtyDefinedNameMap = config.dirtyDefinedNameMap;
5505
+ this._dirtySuperTableMap = config.dirtySuperTableMap || {};
5500
5506
  this._dirtyUnitFeatureMap = config.dirtyUnitFeatureMap;
5501
5507
  this._dirtyUnitOtherFormulaMap = config.dirtyUnitOtherFormulaMap;
5502
5508
  this._excludedCell = config.excludedCell;
@@ -5518,6 +5524,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5518
5524
  dirtyRanges: this._dirtyRanges,
5519
5525
  dirtyNameMap: this._dirtyNameMap,
5520
5526
  dirtyDefinedNameMap: this._dirtyDefinedNameMap,
5527
+ dirtySuperTableMap: this._dirtySuperTableMap,
5521
5528
  dirtyUnitFeatureMap: this._dirtyUnitFeatureMap,
5522
5529
  dirtyUnitOtherFormulaMap: this._dirtyUnitOtherFormulaMap,
5523
5530
  clearDependencyTreeCache: this._clearDependencyTreeCache
@@ -5556,7 +5563,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5556
5563
  });
5557
5564
  }
5558
5565
  _loadSheetData() {
5559
- const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
5566
+ const workbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
5560
5567
  const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
5561
5568
  this._executeUnitId = workbook === null || workbook === void 0 ? void 0 : workbook.getUnitId();
5562
5569
  this._executeSubUnitId = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId();
@@ -5632,22 +5639,6 @@ Lexer = __decorate([
5632
5639
  __decorateParam(2, IFormulaCurrentConfigService)
5633
5640
  ], Lexer);
5634
5641
 
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
5642
  //#endregion
5652
5643
  //#region src/engine/utils/cell.ts
5653
5644
  function getCellValue(cell) {
@@ -5699,7 +5690,7 @@ function isWildcard(str) {
5699
5690
  return str.indexOf("*") > -1 || str.indexOf("?") > -1;
5700
5691
  }
5701
5692
  function isMatchWildcard(currentValue, value) {
5702
- const pattern = escapeRegExp(value).replace(/~?[*?]/g, (match) => {
5693
+ const pattern = escapeRegExpForWildcard(value).replace(/~?[*?]/g, (match) => {
5703
5694
  if (match.startsWith("~")) return `\\${match.substring(1)}`;
5704
5695
  if (match === "*") return ".*";
5705
5696
  if (match === "?") return ".";
@@ -5734,7 +5725,7 @@ function compareWithWildcard(currentValue, value, operator) {
5734
5725
  }
5735
5726
  return result;
5736
5727
  }
5737
- function escapeRegExp(str) {
5728
+ function escapeRegExpForWildcard(str) {
5738
5729
  return str.replace(/[.+^${}()|[\]\\]/g, "\\$&");
5739
5730
  }
5740
5731
  function getMatchModeValue(matchModeValue) {
@@ -5783,11 +5774,20 @@ const localeCurrencySymbolMap = new Map([
5783
5774
  [LocaleType.VI_VN, "₫"],
5784
5775
  [LocaleType.ZH_CN, "¥"],
5785
5776
  [LocaleType.ZH_TW, "NT$"],
5777
+ [LocaleType.ZH_HK, "HK$"],
5786
5778
  [LocaleType.FR_FR, "€"],
5787
5779
  [LocaleType.FA_IR, "﷼"],
5788
5780
  [LocaleType.KO_KR, "₩"],
5789
5781
  [LocaleType.ES_ES, "€"],
5790
- [LocaleType.CA_ES, "€"]
5782
+ [LocaleType.CA_ES, "€"],
5783
+ [LocaleType.SK_SK, "€"],
5784
+ [LocaleType.JA_JP, "¥"],
5785
+ [LocaleType.PT_BR, "R$"],
5786
+ [LocaleType.DE_DE, "€"],
5787
+ [LocaleType.IT_IT, "€"],
5788
+ [LocaleType.ID_ID, "Rp"],
5789
+ [LocaleType.PL_PL, "zł"],
5790
+ [LocaleType.AR_SA, "﷼"]
5791
5791
  ]);
5792
5792
  function getCurrencySymbol(locale) {
5793
5793
  return localeCurrencySymbolMap.get(locale) || "$";
@@ -8215,7 +8215,7 @@ var BaseReferenceObject = class extends ObjectClassType {
8215
8215
  if (r < 0 || c < 0) return callback(ErrorValueObject.create("#REF!"), r, c);
8216
8216
  const cell = this.getCellData(r, c);
8217
8217
  let result = false;
8218
- if (isNullCellForFormula(cell)) {
8218
+ if (isNullCell(cell)) {
8219
8219
  result = callback(null, r, c);
8220
8220
  continue;
8221
8221
  }
@@ -9662,10 +9662,10 @@ let FormulaRuntimeService = class FormulaRuntimeService extends Disposable {
9662
9662
  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
9663
  const featureCell = this._getRuntimeFeatureCellValue(r, c, formulaSheetId, formulaUnitId);
9664
9664
  const isPreviousCellOfCurrentArrayFormula = this._arrayCellHasData(arrayDataCell) && this._isInArrayFormulaRange(previousArrayFormulaRange, r, c) && (currentCell == null || this._isSameCellValue(currentCell, arrayDataCell));
9665
- const hasRuntimeCell = !isNullCellForFormula(cell);
9665
+ const hasRuntimeCell = !isNullCell(cell);
9666
9666
  const isInOtherArrayFormulaRange = this._isInOtherArrayFormulaRange(formulaUnitId, formulaSheetId, formulaRow, formulaColumn, r, c);
9667
- const currentCellBlocks = !isNullCellForFormula(currentCell) && !isPreviousCellOfCurrentArrayFormula;
9668
- const featureCellBlocks = !isNullCellForFormula(featureCell);
9667
+ const currentCellBlocks = !isNullCell(currentCell) && !isPreviousCellOfCurrentArrayFormula;
9668
+ const featureCellBlocks = !isNullCell(featureCell);
9669
9669
  if (hasRuntimeCell || isInOtherArrayFormulaRange || currentCellBlocks || featureCellBlocks) return true;
9670
9670
  }
9671
9671
  return false;
@@ -9938,9 +9938,11 @@ const COLUMN_LIKE_FUNCTION_NAMES = new Set(ALL_GROUPS.flatMap((g) => Object.valu
9938
9938
  //#region src/engine/utils/generate-ast-node.ts
9939
9939
  const FORMULA_CACHE_LRU_COUNT = 5e3;
9940
9940
  const FORMULA_AST_CACHE = new FormulaAstLRU(FORMULA_CACHE_LRU_COUNT);
9941
+ const DIRTY_DEFINED_NAME_SET_CACHE = /* @__PURE__ */ new WeakMap();
9942
+ const DIRTY_SUPER_TABLE_PATTERN_CACHE = /* @__PURE__ */ new WeakMap();
9941
9943
  function generateAstNode(unitId, formulaString, lexer, astTreeBuilder, currentConfigService) {
9942
9944
  let astNode = FORMULA_AST_CACHE.get(`${unitId}${formulaString}`);
9943
- const noCache = checkIsChangedByDefinedName(unitId, formulaString, currentConfigService);
9945
+ const noCache = checkIsChangedByDefinedName(unitId, formulaString, currentConfigService) || checkIsChangedBySuperTable(unitId, formulaString, currentConfigService);
9944
9946
  if (!noCache && astNode && !isDirtyDefinedForNode(astNode, currentConfigService)) return astNode;
9945
9947
  const lexerNode = lexer.treeBuilder(formulaString);
9946
9948
  if (ERROR_TYPE_SET.has(lexerNode)) return ErrorNode.create(lexerNode);
@@ -9955,14 +9957,37 @@ function generateAstNode(unitId, formulaString, lexer, astTreeBuilder, currentCo
9955
9957
  function checkIsChangedByDefinedName(unitId, formula, currentConfigService) {
9956
9958
  const unitDefinedNameMap = currentConfigService.getDirtyDefinedNameMap()[unitId];
9957
9959
  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;
9960
+ return getNormalizedDirtyDefinedNameSet(unitDefinedNameMap).has(normalizeFormulaText(formula));
9962
9961
  }
9963
9962
  function normalizeFormulaText(formula) {
9964
9963
  return formula.startsWith("=") ? formula.slice(1) : formula;
9965
9964
  }
9965
+ function checkIsChangedBySuperTable(unitId, formula, currentConfigService) {
9966
+ var _currentConfigService, _tableReferencePatter;
9967
+ const getDirtySuperTableMap = (_currentConfigService = currentConfigService.getDirtySuperTableMap) === null || _currentConfigService === void 0 ? void 0 : _currentConfigService.bind(currentConfigService);
9968
+ const changedSuperTableMap = getDirtySuperTableMap === null || getDirtySuperTableMap === void 0 ? void 0 : getDirtySuperTableMap();
9969
+ const unitSuperTableMap = changedSuperTableMap === null || changedSuperTableMap === void 0 ? void 0 : changedSuperTableMap[unitId];
9970
+ if (unitSuperTableMap == null) return false;
9971
+ const tableReferencePattern = getDirtySuperTableReferencePattern(unitSuperTableMap);
9972
+ return (_tableReferencePatter = tableReferencePattern === null || tableReferencePattern === void 0 ? void 0 : tableReferencePattern.test(normalizeFormulaText(formula))) !== null && _tableReferencePatter !== void 0 ? _tableReferencePatter : false;
9973
+ }
9974
+ function getNormalizedDirtyDefinedNameSet(unitDefinedNameMap) {
9975
+ let normalizedNameSet = DIRTY_DEFINED_NAME_SET_CACHE.get(unitDefinedNameMap);
9976
+ if (normalizedNameSet == null) {
9977
+ normalizedNameSet = new Set(Object.keys(unitDefinedNameMap).map(normalizeFormulaText));
9978
+ DIRTY_DEFINED_NAME_SET_CACHE.set(unitDefinedNameMap, normalizedNameSet);
9979
+ }
9980
+ return normalizedNameSet;
9981
+ }
9982
+ function getDirtySuperTableReferencePattern(unitSuperTableMap) {
9983
+ let tableReferencePattern = DIRTY_SUPER_TABLE_PATTERN_CACHE.get(unitSuperTableMap);
9984
+ if (tableReferencePattern === void 0) {
9985
+ const escapedTableNames = Object.keys(unitSuperTableMap).filter((tableName) => tableName.length > 0).map(escapeRegExp);
9986
+ tableReferencePattern = escapedTableNames.length > 0 ? new RegExp(`(^|[^A-Za-z0-9_])(?:${escapedTableNames.join("|")})(\\s*\\[|$|[^A-Za-z0-9_])`, "i") : null;
9987
+ DIRTY_SUPER_TABLE_PATTERN_CACHE.set(unitSuperTableMap, tableReferencePattern);
9988
+ }
9989
+ return tableReferencePattern;
9990
+ }
9966
9991
  function isDirtyDefinedForNode(node, currentConfigService) {
9967
9992
  const definedNameMap = currentConfigService.getDirtyDefinedNameMap();
9968
9993
  const executeUnitId = currentConfigService.getExecuteUnitId();
@@ -11760,9 +11785,7 @@ var DependencyManagerBaseService = class extends Disposable {
11760
11785
  clearFormulaDependency(unitId, sheetId) {
11761
11786
  throw new Error("Method not implemented.");
11762
11787
  }
11763
- removeFormulaDependencyByDefinedName(unitId, definedName) {
11764
- throw new Error("Method not implemented.");
11765
- }
11788
+ removeFormulaDependencyByDefinedName(unitId, definedName) {}
11766
11789
  searchDependency(search, exceptTreeIds) {
11767
11790
  return this._dependencyRTreeCache.bulkSearch(search, exceptTreeIds);
11768
11791
  }
@@ -13871,7 +13894,7 @@ let CalculateController = class CalculateController extends Disposable {
13871
13894
  }));
13872
13895
  }
13873
13896
  async _calculate(formulaDirtyData) {
13874
- const { forceCalculation: forceCalculate = false, dirtyRanges = [], dirtyNameMap = {}, dirtyDefinedNameMap = {}, dirtyUnitFeatureMap = {}, dirtyUnitOtherFormulaMap = {}, clearDependencyTreeCache = {}, maxIteration = 1, rowData, isCalculateTreeModel = false } = formulaDirtyData;
13897
+ const { forceCalculation: forceCalculate = false, dirtyRanges = [], dirtyNameMap = {}, dirtyDefinedNameMap = {}, dirtySuperTableMap = {}, dirtyUnitFeatureMap = {}, dirtyUnitOtherFormulaMap = {}, clearDependencyTreeCache = {}, maxIteration = 1, rowData, isCalculateTreeModel = false } = formulaDirtyData;
13875
13898
  const formulaData = this._formulaDataModel.getFormulaData();
13876
13899
  const arrayFormulaCellData = this._formulaDataModel.getArrayFormulaCellData();
13877
13900
  const arrayFormulaRange = this._formulaDataModel.getArrayFormulaRange();
@@ -13883,6 +13906,7 @@ let CalculateController = class CalculateController extends Disposable {
13883
13906
  dirtyRanges,
13884
13907
  dirtyNameMap,
13885
13908
  dirtyDefinedNameMap,
13909
+ dirtySuperTableMap,
13886
13910
  dirtyUnitFeatureMap,
13887
13911
  dirtyUnitOtherFormulaMap,
13888
13912
  clearDependencyTreeCache,
@@ -40031,10 +40055,7 @@ var Textsplit = class extends BaseFunction {
40031
40055
  if (valueObject.isNull()) value = "\\s";
40032
40056
  if (valueObject.isBoolean()) value = value ? "TRUE" : "FALSE";
40033
40057
  value += "";
40034
- return this._escapeRegExp(value);
40035
- }
40036
- _escapeRegExp(string) {
40037
- return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
40058
+ return escapeRegExp(value);
40038
40059
  }
40039
40060
  };
40040
40061
 
@@ -40417,7 +40438,7 @@ function getObjectValue(result, isUseStrip = false) {
40417
40438
  //#endregion
40418
40439
  //#region package.json
40419
40440
  var name = "@univerjs/engine-formula";
40420
- var version = "0.23.0";
40441
+ var version = "0.24.0-insiders.20260528-29f582d";
40421
40442
 
40422
40443
  //#endregion
40423
40444
  //#region src/services/global-computing-status.service.ts
package/lib/facade.js CHANGED
@@ -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) => {