@univerjs/engine-formula 1.0.0-alpha.3 → 1.0.0-alpha.5

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,6 +1,6 @@
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, generateRandomId, getNumfmtParseValueFilter, hashAlgorithm, isFormulaId, isFormulaString, isNullCell, isRealNum, isTextFormat, isValidRange, merge, moveRangeByOffset, numfmt, regexp, 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, LifecycleStages, LocaleService, LocaleType, MAX_COLUMN_COUNT, MAX_ROW_COUNT, ObjectMatrix, Optional, Plugin, RANGE_TYPE, RTree, Rectangle, RichTextBuilder, Styles, Tools, UniverInstanceType, cellToRange, columnLabelToNumber, createIdentifier, generateRandomId, getNumfmtParseValueFilter, hashAlgorithm, isFormulaId, isFormulaString, isNodeEnv, isNullCell, isRealNum, isTextFormat, isValidRange, merge, moveRangeByOffset, numfmt, regexp, requestImmediateMacroTask, sortRules, toDisposable, touchDependencies } from "@univerjs/core";
2
2
  import IntervalTree from "@flatten-js/interval-tree";
3
- import { BehaviorSubject, Observable, Subject, bufferWhen, combineLatest, distinctUntilChanged, filter, map, shareReplay, skip } from "rxjs";
3
+ import { BehaviorSubject, Observable, Subject, bufferWhen, combineLatest, distinctUntilChanged, filter, map, shareReplay, skip, take } from "rxjs";
4
4
  import Decimal from "decimal.js";
5
5
  import { DataSyncPrimaryController } from "@univerjs/rpc";
6
6
 
@@ -1453,10 +1453,11 @@ const TABLE_NAME_REGEX = "((?![~!@#$%^&*()_+<>?:,./;’,。、‘:“《》
1453
1453
  const TABLE_TITLE_REGEX = "\\[#.+\\]\\s*?,\\s*?";
1454
1454
  const TABLE_CONTENT_REGEX = "\\[((?<!#)[\\s\\S])*\\]";
1455
1455
  const TABLE_MULTIPLE_COLUMN_REGEX = `${TABLE_CONTENT_REGEX}${RANGE_SYMBOL}${TABLE_CONTENT_REGEX}`;
1456
- const REFERENCE_TABLE_ALL_COLUMN_REGEX = `^(${UNIT_NAME_REGEX})?${TABLE_NAME_REGEX}$`;
1457
- const REFERENCE_TABLE_SINGLE_COLUMN_REGEX = `^(${UNIT_NAME_REGEX})?${TABLE_NAME_REGEX}(${TABLE_CONTENT_REGEX}|\\[${TABLE_TITLE_REGEX}${TABLE_CONTENT_REGEX}\\])+$`;
1458
- const REFERENCE_TABLE_MULTIPLE_COLUMN_REGEX = `^(${UNIT_NAME_REGEX})?${TABLE_NAME_REGEX}(\\[${TABLE_MULTIPLE_COLUMN_REGEX}\\])?$|^${TABLE_NAME_REGEX}(\\[${TABLE_TITLE_REGEX}${TABLE_MULTIPLE_COLUMN_REGEX}\\])?$`;
1459
- const REFERENCE_TABLE_TITLE_ONLY_ANY_HASH_REGEX = `^(${UNIT_NAME_REGEX})?${TABLE_NAME_REGEX}\\[\\s*#([^\\]]+)\\s*\\]$`;
1456
+ const TABLE_UNIT_QUALIFIER_REGEX = `(?:(?:${UNIT_NAME_REGEX}|'(?:[^']|'')+'|[^\\s!\\[\\]]+)!)?(?:${UNIT_NAME_REGEX})?`;
1457
+ const REFERENCE_TABLE_ALL_COLUMN_REGEX = `^${TABLE_UNIT_QUALIFIER_REGEX}${TABLE_NAME_REGEX}$`;
1458
+ const REFERENCE_TABLE_SINGLE_COLUMN_REGEX = `^${TABLE_UNIT_QUALIFIER_REGEX}${TABLE_NAME_REGEX}(${TABLE_CONTENT_REGEX}|\\[${TABLE_TITLE_REGEX}${TABLE_CONTENT_REGEX}\\])+$`;
1459
+ const REFERENCE_TABLE_MULTIPLE_COLUMN_REGEX = `^${TABLE_UNIT_QUALIFIER_REGEX}${TABLE_NAME_REGEX}(\\[${TABLE_MULTIPLE_COLUMN_REGEX}\\])?$|^${TABLE_UNIT_QUALIFIER_REGEX}${TABLE_NAME_REGEX}(\\[${TABLE_TITLE_REGEX}${TABLE_MULTIPLE_COLUMN_REGEX}\\])?$`;
1460
+ const REFERENCE_TABLE_TITLE_ONLY_ANY_HASH_REGEX = `^${TABLE_UNIT_QUALIFIER_REGEX}${TABLE_NAME_REGEX}\\[\\s*#([^\\]]+)\\s*\\]$`;
1460
1461
  const REFERENCE_TABLE_ALL_COLUMN_REGEX_PRECOMPILING = new RegExp(REFERENCE_TABLE_ALL_COLUMN_REGEX);
1461
1462
  const REFERENCE_TABLE_SINGLE_COLUMN_REGEX_PRECOMPILING = new RegExp(REFERENCE_TABLE_SINGLE_COLUMN_REGEX);
1462
1463
  const REFERENCE_TABLE_MULTIPLE_COLUMN_REGEX_PRECOMPILING = new RegExp(REFERENCE_TABLE_MULTIPLE_COLUMN_REGEX);
@@ -1707,10 +1708,10 @@ function singleReferenceToGrid(refBody) {
1707
1708
  }
1708
1709
  function handleRefStringInfo(refString) {
1709
1710
  const unitIdMatch = UNIT_NAME_REGEX_PRECOMPILING.exec(refString);
1710
- let unitId = "";
1711
+ let unitQualifier = "";
1711
1712
  if (unitIdMatch != null) {
1712
- unitId = unitIdMatch[0].trim();
1713
- unitId = unquoteSheetName(unitId.slice(1, unitId.length - 1));
1713
+ unitQualifier = unitIdMatch[0].trim();
1714
+ unitQualifier = unquoteSheetName(unitQualifier.slice(1, unitQualifier.length - 1));
1714
1715
  refString = refString.replace(UNIT_NAME_REGEX_PRECOMPILING, "");
1715
1716
  }
1716
1717
  const sheetNameIndex = refString.indexOf("!");
@@ -1725,11 +1726,13 @@ function handleRefStringInfo(refString) {
1725
1726
  return {
1726
1727
  refBody,
1727
1728
  sheetName,
1728
- unitId
1729
+ unitQualifier,
1730
+ /** @deprecated Use unitQualifier. Kept for reference-grid compatibility. */
1731
+ unitId: unitQualifier
1729
1732
  };
1730
1733
  }
1731
1734
  function deserializeRangeWithSheet(refString) {
1732
- const { refBody, sheetName, unitId } = handleRefStringInfo(refString);
1735
+ const { refBody, sheetName, unitQualifier } = handleRefStringInfo(refString);
1733
1736
  const colonIndex = refBody.indexOf(":");
1734
1737
  if (colonIndex === -1) {
1735
1738
  const grid = singleReferenceToGrid(refBody);
@@ -1737,7 +1740,7 @@ function deserializeRangeWithSheet(refString) {
1737
1740
  const column = grid.column;
1738
1741
  const absoluteRefType = grid.absoluteRefType;
1739
1742
  return {
1740
- unitId,
1743
+ unitId: unitQualifier,
1741
1744
  sheetName,
1742
1745
  range: {
1743
1746
  startRow: row,
@@ -1761,7 +1764,7 @@ function deserializeRangeWithSheet(refString) {
1761
1764
  if (Number.isNaN(startRow) && Number.isNaN(endRow)) rangeType = RANGE_TYPE.COLUMN;
1762
1765
  else if (Number.isNaN(startColumn) && Number.isNaN(endColumn)) rangeType = RANGE_TYPE.ROW;
1763
1766
  return {
1764
- unitId,
1767
+ unitId: unitQualifier,
1765
1768
  sheetName,
1766
1769
  range: {
1767
1770
  startRow,
@@ -1895,14 +1898,49 @@ function startsWithNonAlphabetic(name) {
1895
1898
  return !/^\p{Letter}/u.test(name.charAt(0));
1896
1899
  }
1897
1900
  function splitTableStructuredRef(ref) {
1898
- const idx = ref.indexOf("[");
1901
+ let unitQualifier = "";
1902
+ let tableRef = ref.trim();
1903
+ let quoteOpen = false;
1904
+ let bracketDepth = 0;
1905
+ let qualifierEnd = -1;
1906
+ for (let i = 0; i < tableRef.length; i++) {
1907
+ const char = tableRef[i];
1908
+ if (char === "'") {
1909
+ if (quoteOpen && tableRef[i + 1] === "'") {
1910
+ i++;
1911
+ continue;
1912
+ }
1913
+ quoteOpen = !quoteOpen;
1914
+ } else if (!quoteOpen && char === "[") bracketDepth++;
1915
+ else if (!quoteOpen && char === "]") bracketDepth--;
1916
+ else if (!quoteOpen && bracketDepth === 0 && char === "!") {
1917
+ qualifierEnd = i;
1918
+ break;
1919
+ }
1920
+ }
1921
+ if (qualifierEnd >= 0) {
1922
+ unitQualifier = tableRef.slice(0, qualifierEnd).trim();
1923
+ tableRef = tableRef.slice(qualifierEnd + 1);
1924
+ if (unitQualifier.startsWith("'") && unitQualifier.endsWith("'")) unitQualifier = unitQualifier.slice(1, -1);
1925
+ if (unitQualifier.startsWith("[") && unitQualifier.endsWith("]")) unitQualifier = unitQualifier.slice(1, -1);
1926
+ unitQualifier = unquoteSheetName(unitQualifier);
1927
+ } else if (tableRef.startsWith("[")) {
1928
+ const legacyQualifierEnd = tableRef.indexOf("]");
1929
+ if (legacyQualifierEnd > 0) {
1930
+ unitQualifier = unquoteSheetName(tableRef.slice(1, legacyQualifierEnd));
1931
+ tableRef = tableRef.slice(legacyQualifierEnd + 1);
1932
+ }
1933
+ }
1934
+ const idx = tableRef.indexOf("[");
1899
1935
  if (idx === -1) return {
1900
- tableName: ref,
1901
- struct: ""
1936
+ unitQualifier,
1937
+ tableName: tableRef,
1938
+ columnStruct: ""
1902
1939
  };
1903
1940
  return {
1904
- tableName: ref.slice(0, idx),
1905
- columnStruct: ref.slice(idx)
1941
+ unitQualifier,
1942
+ tableName: tableRef.slice(0, idx),
1943
+ columnStruct: tableRef.slice(idx)
1906
1944
  };
1907
1945
  }
1908
1946
 
@@ -5130,8 +5168,13 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
5130
5168
  const allUnitData = {};
5131
5169
  const unitStylesData = {};
5132
5170
  const unitSheetNameMap = {};
5171
+ const unitNameMap = {};
5133
5172
  for (const workbook of unitAllSheet) {
5134
5173
  const unitId = workbook.getUnitId();
5174
+ unitNameMap[unitId] = {
5175
+ name: workbook.name,
5176
+ unitType: UniverInstanceType.UNIVER_SHEET
5177
+ };
5135
5178
  const sheets = workbook.getSheets();
5136
5179
  const sheetData = {};
5137
5180
  const sheetNameMap = {};
@@ -5157,6 +5200,10 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
5157
5200
  for (const base of unitAllBases) {
5158
5201
  const snapshot = base.getSnapshot();
5159
5202
  const unitId = base.getUnitId();
5203
+ unitNameMap[unitId] = {
5204
+ name: snapshot.name,
5205
+ unitType: UniverInstanceType.UNIVER_BASE
5206
+ };
5160
5207
  const baseData = {};
5161
5208
  const tableNameMap = {};
5162
5209
  for (const table of Object.values(snapshot.tables)) {
@@ -5177,7 +5224,8 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
5177
5224
  return {
5178
5225
  allUnitData,
5179
5226
  unitStylesData,
5180
- unitSheetNameMap
5227
+ unitSheetNameMap,
5228
+ unitNameMap
5181
5229
  };
5182
5230
  }
5183
5231
  /**
@@ -5205,18 +5253,51 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
5205
5253
  return rowData;
5206
5254
  }
5207
5255
  updateFormulaData(unitId, sheetId, cellValue) {
5256
+ var _this$_univerInstance, _formulaData$unitId$s, _formulaData$unitId;
5208
5257
  const cellMatrix = new ObjectMatrix(cellValue);
5209
- const formulaIdMap = this._getSheetFormulaIdMap(unitId, sheetId);
5210
- const deleteFormulaIdMap = /* @__PURE__ */ new Map();
5211
- const formulaData = this.getFormulaData();
5212
- if (formulaData[unitId] == null) formulaData[unitId] = {};
5213
- const workbookFormulaData = formulaData[unitId];
5214
- if (workbookFormulaData[sheetId] == null) workbookFormulaData[sheetId] = {};
5215
- const sheetFormulaDataMatrix = new ObjectMatrix(workbookFormulaData[sheetId] || {});
5216
5258
  const newSheetFormulaDataMatrix = new ObjectMatrix();
5259
+ const worksheetCellMatrix = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance === void 0 || (_this$_univerInstance = _this$_univerInstance.getSheetBySheetId(sheetId)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getCellMatrix();
5260
+ const affectedFormulaIds = /* @__PURE__ */ new Set();
5217
5261
  cellMatrix.forValue((r, c, cell) => {
5262
+ const currentCell = worksheetCellMatrix === null || worksheetCellMatrix === void 0 ? void 0 : worksheetCellMatrix.getValue(r, c);
5263
+ const currentFormulaId = currentCell === null || currentCell === void 0 ? void 0 : currentCell.si;
5264
+ const formulaId = cell === null || cell === void 0 ? void 0 : cell.si;
5265
+ const hasCurrentFormulaId = isFormulaId(currentFormulaId);
5266
+ const hasFormulaId = isFormulaId(formulaId);
5267
+ const formulaString = cell === null || cell === void 0 ? void 0 : cell.f;
5268
+ if (hasCurrentFormulaId) affectedFormulaIds.add(String(currentFormulaId));
5269
+ if (hasFormulaId) affectedFormulaIds.add(String(formulaId));
5270
+ if (!hasCurrentFormulaId && !hasFormulaId) {
5271
+ if (typeof formulaString === "string" && isFormulaString(formulaString)) newSheetFormulaDataMatrix.setValue(r, c, { f: formulaString });
5272
+ else if (isFormulaString(currentCell === null || currentCell === void 0 ? void 0 : currentCell.f)) newSheetFormulaDataMatrix.setValue(r, c, null);
5273
+ }
5274
+ });
5275
+ if (affectedFormulaIds.size === 0) return newSheetFormulaDataMatrix.getMatrix();
5276
+ const formulaIdMap = {};
5277
+ const sharedFormulaCellMatrix = new ObjectMatrix();
5278
+ worksheetCellMatrix === null || worksheetCellMatrix === void 0 || worksheetCellMatrix.forValue((r, c, cell) => {
5279
+ const formulaId = cell === null || cell === void 0 ? void 0 : cell.si;
5280
+ if (!isFormulaId(formulaId) || !affectedFormulaIds.has(String(formulaId))) return;
5281
+ sharedFormulaCellMatrix.setValue(r, c, cell);
5282
+ if (typeof (cell === null || cell === void 0 ? void 0 : cell.f) === "string" && isFormulaString(cell.f)) formulaIdMap[String(formulaId)] = {
5283
+ f: cell.f,
5284
+ r,
5285
+ c
5286
+ };
5287
+ });
5288
+ const formulaData = {};
5289
+ initSheetFormulaData(formulaData, unitId, sheetId, sharedFormulaCellMatrix);
5290
+ const deleteFormulaIdMap = /* @__PURE__ */ new Map();
5291
+ const sheetFormulaDataMatrix = new ObjectMatrix((_formulaData$unitId$s = (_formulaData$unitId = formulaData[unitId]) === null || _formulaData$unitId === void 0 ? void 0 : _formulaData$unitId[sheetId]) !== null && _formulaData$unitId$s !== void 0 ? _formulaData$unitId$s : {});
5292
+ cellMatrix.forValue((r, c, cell) => {
5293
+ var _worksheetCellMatrix$;
5294
+ if (!isFormulaId(worksheetCellMatrix === null || worksheetCellMatrix === void 0 || (_worksheetCellMatrix$ = worksheetCellMatrix.getValue(r, c)) === null || _worksheetCellMatrix$ === void 0 ? void 0 : _worksheetCellMatrix$.si) && !isFormulaId(cell === null || cell === void 0 ? void 0 : cell.si)) return;
5218
5295
  updateFormulaDataByCellValue(sheetFormulaDataMatrix, newSheetFormulaDataMatrix, formulaIdMap, deleteFormulaIdMap, r, c, cell);
5219
5296
  });
5297
+ this._rebindSharedFormulaData(sheetFormulaDataMatrix, newSheetFormulaDataMatrix, formulaIdMap, deleteFormulaIdMap);
5298
+ return newSheetFormulaDataMatrix.getMatrix();
5299
+ }
5300
+ _rebindSharedFormulaData(sheetFormulaDataMatrix, newSheetFormulaDataMatrix, formulaIdMap, deleteFormulaIdMap) {
5220
5301
  sheetFormulaDataMatrix.forValue((r, c, cell) => {
5221
5302
  const formulaString = (cell === null || cell === void 0 ? void 0 : cell.f) || "";
5222
5303
  const formulaId = (cell === null || cell === void 0 ? void 0 : cell.si) || "";
@@ -5274,7 +5355,6 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
5274
5355
  }
5275
5356
  }
5276
5357
  });
5277
- return newSheetFormulaDataMatrix.getMatrix();
5278
5358
  }
5279
5359
  updateArrayFormulaRange(unitId, sheetId, cellValue) {
5280
5360
  var _this$_arrayFormulaRa5;
@@ -5396,23 +5476,6 @@ let FormulaDataModel = class FormulaDataModel extends Disposable {
5396
5476
  }
5397
5477
  return dirtyRanges;
5398
5478
  }
5399
- _getSheetFormulaIdMap(unitId, sheetId) {
5400
- const formulaIdMap = {};
5401
- const workbook = this._univerInstanceService.getUnit(unitId);
5402
- if (workbook == null) return formulaIdMap;
5403
- const worksheet = workbook.getSheetBySheetId(sheetId);
5404
- if (worksheet == null) return formulaIdMap;
5405
- worksheet.getCellMatrix().forValue((r, c, cell) => {
5406
- if (cell == null) return true;
5407
- const { f, si } = cell;
5408
- if (isFormulaString(f) && isFormulaId(si)) formulaIdMap[si] = {
5409
- f,
5410
- r,
5411
- c
5412
- };
5413
- });
5414
- return formulaIdMap;
5415
- }
5416
5479
  _initSheetArrayFormulaData(unitId, sheetId, cellMatrix) {
5417
5480
  let arrayFormulaRangeMatrix;
5418
5481
  let arrayFormulaCellDataMatrix;
@@ -5498,12 +5561,13 @@ function initSheetFormulaData(formulaData, unitId, sheetId, cellMatrix) {
5498
5561
  const BASE_LEGACY_FIELD_REF_PATTERN = /\{([^}]+)\}/g;
5499
5562
  const BASE_TABLE_FIELD_REF_PATTERN = /\b([A-Z_]\w*)\[([^\]]+)\]/gi;
5500
5563
  const BASE_BRACKET_FIELD_REF_PATTERN = /(^|[^A-Za-z0-9_\]\[])\[([^\]]+)\]/g;
5564
+ const BASE_EXTERNAL_A1_REF_PATTERN = /(?:'\[[^\]]+\](?:[^']|'')+'|\[[^\]]+\][^\s'!]+)!\$?[A-Z]{1,3}\$?\d+(?::\$?[A-Z]{1,3}\$?\d+)?/gi;
5501
5565
  function normalizeBaseFormulaForEngine(formula, currentTable, snapshot) {
5502
5566
  const refs = [];
5503
5567
  const hold = (ref) => {
5504
5568
  return `__BASE_FORMULA_REF_${refs.push(ref) - 1}__`;
5505
5569
  };
5506
- return formula.replace(BASE_LEGACY_FIELD_REF_PATTERN, (_match, fieldName) => hold(createEngineThisRowRef(currentTable, fieldName, snapshot))).replace(BASE_TABLE_FIELD_REF_PATTERN, (_match, sourceTableName, fieldName) => {
5570
+ return formula.replace(BASE_EXTERNAL_A1_REF_PATTERN, (reference) => hold(reference)).replace(BASE_LEGACY_FIELD_REF_PATTERN, (_match, fieldName) => hold(createEngineThisRowRef(currentTable, fieldName, snapshot))).replace(BASE_TABLE_FIELD_REF_PATTERN, (_match, sourceTableName, fieldName) => {
5507
5571
  const targetTable = resolveBaseFormulaTable(sourceTableName, currentTable, snapshot);
5508
5572
  return targetTable ? hold(createEngineThisRowRef(targetTable, fieldName, snapshot)) : `${sourceTableName}[${fieldName}]`;
5509
5573
  }).replace(BASE_BRACKET_FIELD_REF_PATTERN, (_match, prefix, fieldName) => `${prefix}${hold(createEngineThisRowRef(currentTable, fieldName, snapshot))}`).replace(/__BASE_FORMULA_REF_(\d+)__/g, (_match, index) => {
@@ -5669,6 +5733,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5669
5733
  _defineProperty(this, "_arrayFormulaRange", {});
5670
5734
  _defineProperty(this, "_formulaData", {});
5671
5735
  _defineProperty(this, "_sheetNameMap", {});
5736
+ _defineProperty(this, "_unitNameMap", {});
5672
5737
  _defineProperty(this, "_forceCalculate", false);
5673
5738
  _defineProperty(this, "_clearDependencyTreeCache", {});
5674
5739
  _defineProperty(this, "_dirtyRanges", []);
@@ -5690,6 +5755,7 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5690
5755
  this._arrayFormulaRange = {};
5691
5756
  this._formulaData = {};
5692
5757
  this._sheetNameMap = {};
5758
+ this._unitNameMap = {};
5693
5759
  this._clearDependencyTreeCache = {};
5694
5760
  this._dirtyRanges = [];
5695
5761
  this._dirtyNameMap = {};
@@ -5733,6 +5799,9 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5733
5799
  getSheetNameMap() {
5734
5800
  return this._sheetNameMap;
5735
5801
  }
5802
+ getUnitNameMap() {
5803
+ return this._unitNameMap;
5804
+ }
5736
5805
  isForceCalculate() {
5737
5806
  return this._forceCalculate;
5738
5807
  }
@@ -5798,11 +5867,13 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5798
5867
  this._unitData = config.allUnitData;
5799
5868
  this._unitStylesData = config.unitStylesData;
5800
5869
  this._sheetNameMap = config.unitSheetNameMap;
5870
+ this._unitNameMap = config.unitNameMap || {};
5801
5871
  } else {
5802
- const { allUnitData, unitSheetNameMap, unitStylesData } = this._loadSheetData();
5872
+ const { allUnitData, unitNameMap, unitSheetNameMap, unitStylesData } = this._loadSheetData();
5803
5873
  this._unitData = allUnitData;
5804
5874
  this._unitStylesData = unitStylesData;
5805
5875
  this._sheetNameMap = unitSheetNameMap;
5876
+ this._unitNameMap = unitNameMap;
5806
5877
  }
5807
5878
  if (config.rowData) this._applyUnitRowData(config.rowData);
5808
5879
  this._formulaData = config.formulaData;
@@ -5820,10 +5891,11 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5820
5891
  this._mergeNameMap(this._sheetNameMap, this._dirtyNameMap);
5821
5892
  }
5822
5893
  loadDataLite(rowData) {
5823
- const { allUnitData, unitSheetNameMap, unitStylesData } = this._loadSheetData();
5894
+ const { allUnitData, unitNameMap, unitSheetNameMap, unitStylesData } = this._loadSheetData();
5824
5895
  this._unitData = allUnitData;
5825
5896
  this._unitStylesData = unitStylesData;
5826
5897
  this._sheetNameMap = unitSheetNameMap;
5898
+ this._unitNameMap = unitNameMap;
5827
5899
  this._formulaData = this._formulaDataModel.getFormulaData();
5828
5900
  this._arrayFormulaCellData = convertUnitDataToRuntime(this._formulaDataModel.getArrayFormulaCellData());
5829
5901
  this._arrayFormulaRange = this._formulaDataModel.getArrayFormulaRange();
@@ -5858,6 +5930,9 @@ let FormulaCurrentConfigService = class FormulaCurrentConfigService extends Disp
5858
5930
  registerSheetNameMap(sheetNameMap) {
5859
5931
  this._sheetNameMap = sheetNameMap;
5860
5932
  }
5933
+ registerUnitNameMap(unitNameMap) {
5934
+ this._unitNameMap = unitNameMap;
5935
+ }
5861
5936
  _mergeNameMap(unitSheetNameMap, dirtyNameMap) {
5862
5937
  Object.keys(dirtyNameMap).forEach((unitId) => {
5863
5938
  if (dirtyNameMap[unitId]) Object.keys(dirtyNameMap[unitId]).forEach((sheetId) => {
@@ -8476,6 +8551,7 @@ var BaseReferenceObject = class extends ObjectClassType {
8476
8551
  _defineProperty(this, "_filteredOutRows", []);
8477
8552
  _defineProperty(this, "_defaultUnitId", "");
8478
8553
  _defineProperty(this, "_forcedUnitId", "");
8554
+ _defineProperty(this, "_unitQualifier", "");
8479
8555
  _defineProperty(this, "_runtimeData", {});
8480
8556
  _defineProperty(this, "_arrayFormulaCellData", {});
8481
8557
  _defineProperty(this, "_arrayFormulaRange", {});
@@ -8582,6 +8658,12 @@ var BaseReferenceObject = class extends ObjectClassType {
8582
8658
  setForcedUnitIdDirect(unitId) {
8583
8659
  if (unitId.length > 0) this._forcedUnitId = unitId;
8584
8660
  }
8661
+ setUnitQualifier(unitQualifier) {
8662
+ this._unitQualifier = unitQualifier;
8663
+ }
8664
+ getUnitQualifier() {
8665
+ return this._unitQualifier;
8666
+ }
8585
8667
  getForcedUnitId() {
8586
8668
  return this._forcedUnitId;
8587
8669
  }
@@ -8969,6 +9051,7 @@ var CellReferenceObject = class extends BaseReferenceObject {
8969
9051
  constructor(token) {
8970
9052
  super(token);
8971
9053
  const grid = deserializeRangeWithSheetWithCache(token);
9054
+ this.setUnitQualifier(grid.unitId);
8972
9055
  this.setForcedUnitIdDirect(grid.unitId);
8973
9056
  this.setForcedSheetName(grid.sheetName);
8974
9057
  this.setRangeData(grid.range);
@@ -9044,6 +9127,7 @@ var ColumnReferenceObject = class extends BaseReferenceObject {
9044
9127
  constructor(token) {
9045
9128
  super(token);
9046
9129
  const grid = deserializeRangeWithSheetWithCache(token);
9130
+ this.setUnitQualifier(grid.unitId);
9047
9131
  this.setForcedUnitIdDirect(grid.unitId);
9048
9132
  this.setForcedSheetName(grid.sheetName);
9049
9133
  const range = {
@@ -9086,6 +9170,7 @@ var RowReferenceObject = class extends BaseReferenceObject {
9086
9170
  constructor(token) {
9087
9171
  super(token);
9088
9172
  const grid = deserializeRangeWithSheetWithCache(token);
9173
+ this.setUnitQualifier(grid.unitId);
9089
9174
  this.setForcedUnitIdDirect(grid.unitId);
9090
9175
  this.setForcedSheetName(grid.sheetName);
9091
9176
  const range = {
@@ -10461,6 +10546,49 @@ var FunctionService = class extends Disposable {
10461
10546
  }
10462
10547
  };
10463
10548
 
10549
+ //#endregion
10550
+ //#region src/services/unit-reference-resolver.service.ts
10551
+ const IFormulaUnitReferenceResolver = createIdentifier("univer.formula.unit-reference-resolver");
10552
+ const EXCEL_WORKBOOK_EXTENSION = /\.(?:xlsx|xlsm|xlsb|xltx|xltm|xls)$/i;
10553
+ function normalizeFormulaUnitName(name) {
10554
+ return name.replace(EXCEL_WORKBOOK_EXTENSION, "").toLowerCase();
10555
+ }
10556
+ let FormulaUnitReferenceResolver = class FormulaUnitReferenceResolver {
10557
+ constructor(_currentConfigService) {
10558
+ this._currentConfigService = _currentConfigService;
10559
+ }
10560
+ resolve({ hostUnitId, qualifier, referenceKind }) {
10561
+ const unitNameMap = this._currentConfigService.getUnitNameMap();
10562
+ const unitData = this._currentConfigService.getUnitData();
10563
+ const address = qualifier || hostUnitId;
10564
+ const direct = unitNameMap[address];
10565
+ if (direct || unitData[address]) return this._validateReferenceKind(hostUnitId, referenceKind, {
10566
+ unitId: address,
10567
+ unitType: direct === null || direct === void 0 ? void 0 : direct.unitType
10568
+ }, unitNameMap);
10569
+ if (!qualifier) return "#REF!";
10570
+ const namedUnits = Object.entries(unitNameMap).filter(([, item]) => item.name.length > 0);
10571
+ const normalizedQualifier = qualifier.toLowerCase();
10572
+ const exactMatches = namedUnits.filter(([, item]) => item.name.toLowerCase() === normalizedQualifier);
10573
+ const matches = exactMatches.length > 0 ? exactMatches : namedUnits.filter(([, item]) => normalizeFormulaUnitName(item.name) === normalizeFormulaUnitName(qualifier));
10574
+ if (matches.length !== 1) return "#REF!";
10575
+ const [unitId, item] = matches[0];
10576
+ return this._validateReferenceKind(hostUnitId, referenceKind, {
10577
+ unitId,
10578
+ unitType: item.unitType
10579
+ }, unitNameMap);
10580
+ }
10581
+ _validateReferenceKind(hostUnitId, referenceKind, resolution, unitNameMap) {
10582
+ var _unitNameMap$hostUnit;
10583
+ if (referenceKind !== "a1" || resolution.unitId === hostUnitId) return resolution;
10584
+ const hostType = (_unitNameMap$hostUnit = unitNameMap[hostUnitId]) === null || _unitNameMap$hostUnit === void 0 ? void 0 : _unitNameMap$hostUnit.unitType;
10585
+ if (resolution.unitType === UniverInstanceType.UNIVER_BASE) return "#REF!";
10586
+ if (hostType === UniverInstanceType.UNIVER_BASE && resolution.unitType !== UniverInstanceType.UNIVER_SHEET) return "#REF!";
10587
+ return resolution;
10588
+ }
10589
+ };
10590
+ FormulaUnitReferenceResolver = __decorate([__decorateParam(0, IFormulaCurrentConfigService)], FormulaUnitReferenceResolver);
10591
+
10464
10592
  //#endregion
10465
10593
  //#region src/engine/ast-node/prefix-node.ts
10466
10594
  var PrefixNode = class extends BaseAstNode {
@@ -10577,18 +10705,20 @@ function prefixHandler(tokenTrimParam, functionService, runtimeService) {
10577
10705
  //#endregion
10578
10706
  //#region src/engine/ast-node/function-node.ts
10579
10707
  var FunctionNode = class extends BaseAstNode {
10580
- constructor(token, _functionExecutor, _currentConfigService, _runtimeService, _definedNamesService, _formulaDataModel) {
10708
+ constructor(token, _functionExecutor, _currentConfigService, _runtimeService, _definedNamesService, _formulaDataModel, _unitReferenceResolver) {
10581
10709
  super(token);
10582
10710
  this._functionExecutor = _functionExecutor;
10583
10711
  this._currentConfigService = _currentConfigService;
10584
10712
  this._runtimeService = _runtimeService;
10585
10713
  this._definedNamesService = _definedNamesService;
10586
10714
  this._formulaDataModel = _formulaDataModel;
10715
+ this._unitReferenceResolver = _unitReferenceResolver;
10587
10716
  if (this._functionExecutor.isAsync()) this.setAsync();
10588
10717
  if (this._functionExecutor.isAddress()) this.setAddress();
10589
10718
  if (this._functionExecutor.needsLocale) this._setLocale();
10590
10719
  if (this._functionExecutor.needsSheetsInfo) this._setSheetsInfo();
10591
10720
  if (this._functionExecutor.needsFormulaDataModel) this._functionExecutor.setFormulaDataModel(this._formulaDataModel);
10721
+ if (this._functionExecutor.needsUnitReferenceResolver) this._functionExecutor.setUnitReferenceResolver(this._unitReferenceResolver);
10592
10722
  }
10593
10723
  get nodeType() {
10594
10724
  return 4;
@@ -10816,7 +10946,7 @@ var ErrorFunctionNode = class extends BaseAstNode {
10816
10946
  }
10817
10947
  };
10818
10948
  let FunctionNodeFactory = class FunctionNodeFactory extends BaseAstNodeFactory {
10819
- constructor(_functionService, _currentConfigService, _runtimeService, _definedNamesService, _injector, _formulaDataModel) {
10949
+ constructor(_functionService, _currentConfigService, _runtimeService, _definedNamesService, _injector, _formulaDataModel, _unitReferenceResolver) {
10820
10950
  super();
10821
10951
  this._functionService = _functionService;
10822
10952
  this._currentConfigService = _currentConfigService;
@@ -10824,6 +10954,7 @@ let FunctionNodeFactory = class FunctionNodeFactory extends BaseAstNodeFactory {
10824
10954
  this._definedNamesService = _definedNamesService;
10825
10955
  this._injector = _injector;
10826
10956
  this._formulaDataModel = _formulaDataModel;
10957
+ this._unitReferenceResolver = _unitReferenceResolver;
10827
10958
  }
10828
10959
  get zIndex() {
10829
10960
  return NODE_ORDER_MAP.get(4) || 100;
@@ -10834,7 +10965,7 @@ let FunctionNodeFactory = class FunctionNodeFactory extends BaseAstNodeFactory {
10834
10965
  console.error(`No function ${token}`);
10835
10966
  return ErrorNode.create("#NAME?");
10836
10967
  }
10837
- return new FunctionNode(token, functionExecutor, this._currentConfigService, this._runtimeService, this._definedNamesService, this._formulaDataModel);
10968
+ return new FunctionNode(token, functionExecutor, this._currentConfigService, this._runtimeService, this._definedNamesService, this._formulaDataModel, this._unitReferenceResolver);
10838
10969
  }
10839
10970
  checkAndCreateNodeType(param) {
10840
10971
  if (typeof param === "string") return;
@@ -10861,7 +10992,8 @@ FunctionNodeFactory = __decorate([
10861
10992
  __decorateParam(2, IFormulaRuntimeService),
10862
10993
  __decorateParam(3, IDefinedNamesService),
10863
10994
  __decorateParam(4, Inject(Injector)),
10864
- __decorateParam(5, Inject(FormulaDataModel))
10995
+ __decorateParam(5, Inject(FormulaDataModel)),
10996
+ __decorateParam(6, IFormulaUnitReferenceResolver)
10865
10997
  ], FunctionNodeFactory);
10866
10998
  function normalizeFunctionToken(token) {
10867
10999
  if (token === "REGEXTEST" || token === "_XLFN.REGEXTEST") return "REGEXMATCH";
@@ -11565,6 +11697,7 @@ var TableReferenceObject = class extends BaseReferenceObject {
11565
11697
  const { startColumn, endColumn, type } = this._parseStructuredRef(this._columnDataString, titleMap);
11566
11698
  const tableStartRow = range.startRow;
11567
11699
  const tableEndRow = range.endRow;
11700
+ const dataStartRow = tableStartRow + (this._tableData.showHeader === false ? 0 : 1);
11568
11701
  let startRow = -1;
11569
11702
  let endRow = -1;
11570
11703
  switch (type) {
@@ -11573,10 +11706,15 @@ var TableReferenceObject = class extends BaseReferenceObject {
11573
11706
  endRow = tableEndRow;
11574
11707
  break;
11575
11708
  case "#Data":
11576
- startRow = tableStartRow + 1;
11709
+ startRow = dataStartRow;
11577
11710
  endRow = tableEndRow;
11578
11711
  break;
11579
11712
  case "#Headers":
11713
+ if (this._tableData.showHeader === false) {
11714
+ startRow = -1;
11715
+ endRow = -1;
11716
+ break;
11717
+ }
11580
11718
  startRow = tableStartRow;
11581
11719
  endRow = tableStartRow;
11582
11720
  break;
@@ -11591,7 +11729,7 @@ var TableReferenceObject = class extends BaseReferenceObject {
11591
11729
  break;
11592
11730
  }
11593
11731
  default:
11594
- startRow = tableStartRow + 1;
11732
+ startRow = dataStartRow;
11595
11733
  endRow = tableEndRow;
11596
11734
  break;
11597
11735
  }
@@ -11616,6 +11754,13 @@ var TableReferenceObject = class extends BaseReferenceObject {
11616
11754
  }
11617
11755
  return rangeData;
11618
11756
  }
11757
+ getCellData(row, column) {
11758
+ if (this._isCurrentRowForRange) {
11759
+ const { startRow, endRow } = this._tableData.range;
11760
+ if (row < startRow || row > endRow) return { v: "#N/A" };
11761
+ }
11762
+ return super.getCellData(row, column);
11763
+ }
11619
11764
  getRefOffset() {
11620
11765
  return {
11621
11766
  x: 0,
@@ -11812,13 +11957,15 @@ var TableReferenceObject = class extends BaseReferenceObject {
11812
11957
  //#endregion
11813
11958
  //#region src/engine/ast-node/reference-node.ts
11814
11959
  var ReferenceNode = class extends BaseAstNode {
11815
- constructor(_currentConfigService, _runtimeService, operatorString, _referenceObjectType, _isPrepareMerge = false, _tableReferenceObject) {
11960
+ constructor(_currentConfigService, _runtimeService, operatorString, _referenceObjectType, _unitReferenceResolver, _superTableService, _isPrepareMerge = false, _tableReference) {
11816
11961
  super(operatorString);
11817
11962
  this._currentConfigService = _currentConfigService;
11818
11963
  this._runtimeService = _runtimeService;
11819
11964
  this._referenceObjectType = _referenceObjectType;
11965
+ this._unitReferenceResolver = _unitReferenceResolver;
11966
+ this._superTableService = _superTableService;
11820
11967
  this._isPrepareMerge = _isPrepareMerge;
11821
- this._tableReferenceObject = _tableReferenceObject;
11968
+ this._tableReference = _tableReference;
11822
11969
  _defineProperty(this, "_refOffsetX", 0);
11823
11970
  _defineProperty(this, "_refOffsetY", 0);
11824
11971
  }
@@ -11828,7 +11975,49 @@ var ReferenceNode = class extends BaseAstNode {
11828
11975
  execute() {
11829
11976
  const currentConfigService = this._currentConfigService;
11830
11977
  const runtimeService = this._runtimeService;
11831
- const referenceObject = this._tableReferenceObject || getReferenceObjectFromCache(this.getToken(), this._referenceObjectType);
11978
+ let referenceObject;
11979
+ if (this._tableReference) {
11980
+ var _Array$from$find;
11981
+ const { unitQualifier, tableName, columnStruct } = this._tableReference;
11982
+ const resolution = this._unitReferenceResolver.resolve({
11983
+ hostUnitId: runtimeService.currentUnitId,
11984
+ qualifier: unitQualifier,
11985
+ referenceKind: "table"
11986
+ });
11987
+ if (typeof resolution === "string") {
11988
+ this.setValue(ErrorValueObject.create(resolution));
11989
+ return;
11990
+ }
11991
+ const tableMap = this._superTableService.getTableMap(resolution.unitId);
11992
+ const tableData = (_Array$from$find = Array.from((tableMap === null || tableMap === void 0 ? void 0 : tableMap.entries()) || []).find(([name]) => name.toLocaleLowerCase() === tableName.toLocaleLowerCase())) === null || _Array$from$find === void 0 ? void 0 : _Array$from$find[1];
11993
+ if (!tableData) {
11994
+ this.setValue(ErrorValueObject.create("#REF!"));
11995
+ return;
11996
+ }
11997
+ referenceObject = new TableReferenceObject(this.getToken(), tableData, columnStruct, this._superTableService.getTableOptionMap());
11998
+ referenceObject.setUnitQualifier(unitQualifier);
11999
+ referenceObject.setForcedUnitIdDirect(resolution.unitId);
12000
+ } else {
12001
+ referenceObject = getReferenceObjectFromCache(this.getToken(), this._referenceObjectType);
12002
+ const unitQualifier = referenceObject.getUnitQualifier();
12003
+ if (unitQualifier) {
12004
+ const resolution = this._unitReferenceResolver.resolve({
12005
+ hostUnitId: runtimeService.currentUnitId,
12006
+ qualifier: unitQualifier,
12007
+ referenceKind: "a1"
12008
+ });
12009
+ if (typeof resolution === "string") {
12010
+ this.setValue(ErrorValueObject.create(resolution));
12011
+ return;
12012
+ }
12013
+ referenceObject.setForcedUnitIdDirect(resolution.unitId);
12014
+ }
12015
+ }
12016
+ this._configureReferenceObject(referenceObject, currentConfigService, runtimeService);
12017
+ if (!this._isPrepareMerge && referenceObject.isExceedRange()) this.setValue(ErrorValueObject.create("#NAME?"));
12018
+ else this.setValue(referenceObject);
12019
+ }
12020
+ _configureReferenceObject(referenceObject, currentConfigService, runtimeService) {
11832
12021
  referenceObject.setDefaultUnitId(runtimeService.currentUnitId);
11833
12022
  referenceObject.setDefaultSheetId(runtimeService.currentSubUnitId);
11834
12023
  referenceObject.setForcedSheetId(currentConfigService.getSheetNameMap());
@@ -11840,13 +12029,9 @@ var ReferenceNode = class extends BaseAstNode {
11840
12029
  referenceObject.setRuntimeArrayFormulaCellData(runtimeService.getRuntimeArrayFormulaCellData());
11841
12030
  referenceObject.setRuntimeArrayFormulaRange(runtimeService.getUnitArrayFormula());
11842
12031
  referenceObject.setRuntimeFeatureCellData(runtimeService.getRuntimeFeatureCellData());
11843
- const currentRow = runtimeService.currentRow;
11844
- const currentCol = runtimeService.currentColumn;
11845
- referenceObject.setCurrentRowAndColumn(currentRow, currentCol);
12032
+ referenceObject.setCurrentRowAndColumn(runtimeService.currentRow, runtimeService.currentColumn);
11846
12033
  const { x, y } = this.getRefOffset();
11847
12034
  referenceObject.setRefOffset(x, y);
11848
- if (!this._isPrepareMerge && referenceObject.isExceedRange()) this.setValue(ErrorValueObject.create("#NAME?"));
11849
- else this.setValue(referenceObject);
11850
12035
  }
11851
12036
  setRefOffset(x = 0, y = 0) {
11852
12037
  this._refOffsetX = x;
@@ -11860,12 +12045,13 @@ var ReferenceNode = class extends BaseAstNode {
11860
12045
  }
11861
12046
  };
11862
12047
  let ReferenceNodeFactory = class ReferenceNodeFactory extends BaseAstNodeFactory {
11863
- constructor(_currentConfigService, _formulaRuntimeService, _functionService, _superTableService) {
12048
+ constructor(_currentConfigService, _formulaRuntimeService, _functionService, _superTableService, _unitReferenceResolver) {
11864
12049
  super();
11865
12050
  this._currentConfigService = _currentConfigService;
11866
12051
  this._formulaRuntimeService = _formulaRuntimeService;
11867
12052
  this._functionService = _functionService;
11868
12053
  this._superTableService = _superTableService;
12054
+ this._unitReferenceResolver = _unitReferenceResolver;
11869
12055
  }
11870
12056
  get zIndex() {
11871
12057
  return NODE_ORDER_MAP.get(1) || 100;
@@ -11902,25 +12088,25 @@ let ReferenceNodeFactory = class ReferenceNodeFactory extends BaseAstNodeFactory
11902
12088
  var _tableMap$has;
11903
12089
  const currentConfigService = this._currentConfigService;
11904
12090
  const runtimeService = this._formulaRuntimeService;
11905
- const makeRef = (type) => new ReferenceNode(currentConfigService, runtimeService, tokenTrim, type, isPrepareMerge);
12091
+ const makeRef = (type) => new ReferenceNode(currentConfigService, runtimeService, tokenTrim, type, this._unitReferenceResolver, this._superTableService, isPrepareMerge);
11906
12092
  const tableMap = this._getTableMap();
11907
- if ((_tableMap$has = tableMap === null || tableMap === void 0 ? void 0 : tableMap.has(tokenTrim)) !== null && _tableMap$has !== void 0 ? _tableMap$has : false) return this._getTableReferenceNode(tokenTrim, isLexerNode, isPrepareMerge, true);
12093
+ if ((_tableMap$has = tableMap === null || tableMap === void 0 ? void 0 : tableMap.has(tokenTrim)) !== null && _tableMap$has !== void 0 ? _tableMap$has : false) return this._getTableReferenceNode(tokenTrim, isPrepareMerge, true);
11908
12094
  if (regexTestSingeRange(tokenTrim)) return makeRef(0);
11909
12095
  const parentIsUnion = isLexerNode && this._checkParentIsUnionOperator(param);
11910
12096
  if (parentIsUnion && regexTestSingleRow(tokenTrim)) return makeRef(2);
11911
12097
  if (parentIsUnion && regexTestSingleColumn(tokenTrim)) return makeRef(1);
11912
- return this._getTableReferenceNode(tokenTrim, isLexerNode, isPrepareMerge, false);
12098
+ return this._getTableReferenceNode(tokenTrim, isPrepareMerge, false);
11913
12099
  }
11914
- _getTableReferenceNode(tokenTrim, isLexerNode, isPrepareMerge, isSuperTableDirectly = false) {
12100
+ _getTableReferenceNode(tokenTrim, isPrepareMerge, isSuperTableDirectly = false) {
11915
12101
  if (!this._checkTokenIsTableReference(tokenTrim) && !isSuperTableDirectly) return;
11916
- const { tableName, columnStruct } = splitTableStructuredRef(tokenTrim);
12102
+ const { unitQualifier, tableName, columnStruct } = splitTableStructuredRef(tokenTrim);
11917
12103
  const tableMap = this._getTableMap();
11918
- if (!isLexerNode && (tableMap === null || tableMap === void 0 ? void 0 : tableMap.has(tableName))) {
11919
- const columnDataString = columnStruct;
11920
- const tableData = tableMap.get(tableName);
11921
- const tableOption = this._superTableService.getTableOptionMap();
11922
- return new ReferenceNode(this._currentConfigService, this._formulaRuntimeService, tokenTrim, 1, isPrepareMerge, new TableReferenceObject(tokenTrim, tableData, columnDataString, tableOption));
11923
- }
12104
+ const hasLocalTable = Array.from((tableMap === null || tableMap === void 0 ? void 0 : tableMap.keys()) || []).some((name) => name.toLocaleLowerCase() === tableName.toLocaleLowerCase());
12105
+ if (unitQualifier || hasLocalTable) return new ReferenceNode(this._currentConfigService, this._formulaRuntimeService, tokenTrim, 1, this._unitReferenceResolver, this._superTableService, isPrepareMerge, {
12106
+ unitQualifier,
12107
+ tableName,
12108
+ columnStruct
12109
+ });
11924
12110
  }
11925
12111
  _checkTokenIsTableReference(token) {
11926
12112
  return regexTestReferenceTableAllColumn(token) || regexTestReferenceTableSingleColumn(token) || regexTestReferenceTableMultipleColumn(token) || regexTestReferenceTableTitleOnlyAnyHash(token);
@@ -11934,7 +12120,8 @@ ReferenceNodeFactory = __decorate([
11934
12120
  __decorateParam(0, IFormulaCurrentConfigService),
11935
12121
  __decorateParam(1, IFormulaRuntimeService),
11936
12122
  __decorateParam(2, IFunctionService),
11937
- __decorateParam(3, ISuperTableService)
12123
+ __decorateParam(3, ISuperTableService),
12124
+ __decorateParam(4, IFormulaUnitReferenceResolver)
11938
12125
  ], ReferenceNodeFactory);
11939
12126
 
11940
12127
  //#endregion
@@ -14226,9 +14413,10 @@ let CalculateFormulaService = class CalculateFormulaService extends Disposable {
14226
14413
  this._executeLock.acquire("FORMULA_EXECUTION_LOCK", async () => {
14227
14414
  for (let i = 0; i < cycleReferenceCount; i++) {
14228
14415
  this._runtimeService.setFormulaCycleIndex(i);
14229
- await this._executeStep();
14416
+ const executed = await this._executeStep();
14230
14417
  FORMULA_REF_TO_ARRAY_CACHE.clear();
14231
- if (!this._runtimeService.isCycleDependency()) break;
14418
+ const isCycleDependency = this._runtimeService.isCycleDependency();
14419
+ if (!executed || !isCycleDependency) break;
14232
14420
  }
14233
14421
  this._runtimeService.setFormulaExecuteStage(8);
14234
14422
  this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());
@@ -14339,7 +14527,6 @@ let CalculateFormulaService = class CalculateFormulaService extends Disposable {
14339
14527
  if (this._runtimeService.isStopExecution() || nodeData == null && getDirtyData == null) {
14340
14528
  this._runtimeService.setFormulaExecuteStage(0);
14341
14529
  this._runtimeService.markedAsStopFunctionsExecuted();
14342
- this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());
14343
14530
  return;
14344
14531
  }
14345
14532
  }
@@ -14724,7 +14911,7 @@ function singleReference(refBody, currentRow = 0, currentColumn = 0) {
14724
14911
  };
14725
14912
  }
14726
14913
  function deserializeRangeForR1C1(refString, currentRow = 0, currentColumn = 0) {
14727
- const { refBody, sheetName, unitId } = handleRefStringInfo(refString);
14914
+ const { refBody, sheetName, unitQualifier } = handleRefStringInfo(refString);
14728
14915
  const colonIndex = refBody.indexOf(":");
14729
14916
  if (colonIndex === -1) {
14730
14917
  const grid = singleReference(refBody, currentRow, currentColumn);
@@ -14732,7 +14919,7 @@ function deserializeRangeForR1C1(refString, currentRow = 0, currentColumn = 0) {
14732
14919
  const column = grid.column;
14733
14920
  const absoluteRefType = grid.absoluteRefType;
14734
14921
  return {
14735
- unitId,
14922
+ unitId: unitQualifier,
14736
14923
  sheetName,
14737
14924
  range: {
14738
14925
  startRow: row,
@@ -14749,7 +14936,7 @@ function deserializeRangeForR1C1(refString, currentRow = 0, currentColumn = 0) {
14749
14936
  const startGrid = singleReference(refStartString, currentRow, currentColumn);
14750
14937
  const endGrid = singleReference(refEndString, currentRow, currentColumn);
14751
14938
  return {
14752
- unitId,
14939
+ unitId: unitQualifier,
14753
14940
  sheetName,
14754
14941
  range: {
14755
14942
  startRow: startGrid.row,
@@ -14779,6 +14966,91 @@ function getR1C1Ref(index, absoluteRefType = AbsoluteRefType.ALL, isRow) {
14779
14966
  }
14780
14967
  }
14781
14968
 
14969
+ //#endregion
14970
+ //#region src/engine/utils/unit-qualifier.ts
14971
+ /**
14972
+ * Copyright 2023-present DreamNum Co., Ltd.
14973
+ *
14974
+ * Licensed under the Apache License, Version 2.0 (the "License");
14975
+ * you may not use this file except in compliance with the License.
14976
+ * You may obtain a copy of the License at
14977
+ *
14978
+ * http://www.apache.org/licenses/LICENSE-2.0
14979
+ *
14980
+ * Unless required by applicable law or agreed to in writing, software
14981
+ * distributed under the License is distributed on an "AS IS" BASIS,
14982
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14983
+ * See the License for the specific language governing permissions and
14984
+ * limitations under the License.
14985
+ */
14986
+ const A1_UNIT_QUALIFIER = /('?)\[([^\]]+)\]((?:[^']|'')+)\1!(?=\$?[A-Z]{1,3}\$?\d+)/gi;
14987
+ const TABLE_UNIT_QUALIFIER = /(^|[^\w.])(?:'((?:[^']|'')+)'|\[([^\]]+)\]|([A-Za-z0-9_.-]+))!(?=[^\s!\[\]]+\[)/g;
14988
+ const INDIRECT_LITERAL = /\bINDIRECT\s*\(\s*"((?:[^"]|"")*)"/gi;
14989
+ function equalsQualifier(actual, expected) {
14990
+ return actual.replace(/''/g, "'").toLocaleLowerCase() === expected.toLocaleLowerCase();
14991
+ }
14992
+ function quoteQualifier(name) {
14993
+ return /^[A-Za-z0-9_.-]+$/.test(name) ? name : `'${name.replace(/'/g, "''")}'`;
14994
+ }
14995
+ function refactorReferenceSegment(segment, oldName, newName) {
14996
+ return segment.replace(A1_UNIT_QUALIFIER, (token, quote, qualifier, sheetName) => {
14997
+ if (!equalsQualifier(qualifier, oldName)) return token;
14998
+ const escapedName = newName.replace(/'/g, "''");
14999
+ return quote ? `'[${escapedName}]${sheetName}'!` : `[${newName}]${sheetName}!`;
15000
+ }).replace(TABLE_UNIT_QUALIFIER, (token, boundary, quoted, bracketed, plain) => {
15001
+ var _ref, _ref2;
15002
+ if (!equalsQualifier((_ref = (_ref2 = quoted !== null && quoted !== void 0 ? quoted : bracketed) !== null && _ref2 !== void 0 ? _ref2 : plain) !== null && _ref !== void 0 ? _ref : "", oldName)) return token;
15003
+ if (quoted != null) return `${boundary}'${newName.replace(/'/g, "''")}'!`;
15004
+ if (bracketed != null) return `${boundary}[${newName}]!`;
15005
+ return `${boundary}${quoteQualifier(newName)}!`;
15006
+ });
15007
+ }
15008
+ function refactorOutsideStrings(formula, oldName, newName) {
15009
+ let result = "";
15010
+ let chunk = "";
15011
+ let inString = false;
15012
+ for (let index = 0; index < formula.length; index++) {
15013
+ const character = formula[index];
15014
+ if (character !== "\"") {
15015
+ chunk += character;
15016
+ continue;
15017
+ }
15018
+ if (inString && formula[index + 1] === "\"") {
15019
+ chunk += "\"\"";
15020
+ index++;
15021
+ continue;
15022
+ }
15023
+ result += inString ? chunk : refactorReferenceSegment(chunk, oldName, newName);
15024
+ result += "\"";
15025
+ chunk = "";
15026
+ inString = !inString;
15027
+ }
15028
+ return result + (inString ? chunk : refactorReferenceSegment(chunk, oldName, newName));
15029
+ }
15030
+ /** Refactors only parsed reference qualifiers and INDIRECT literal references, never arbitrary text. */
15031
+ function refactorFormulaUnitQualifier(formula, oldName, newName) {
15032
+ if (!oldName || oldName === newName) return formula;
15033
+ return refactorOutsideStrings(formula.replace(INDIRECT_LITERAL, (token, literal) => {
15034
+ const next = refactorReferenceSegment(literal.replace(/""/g, "\""), oldName, newName).replace(/"/g, "\"\"");
15035
+ return token.replace(literal, next);
15036
+ }), oldName, newName);
15037
+ }
15038
+ /**
15039
+ * Copyright 2023-present DreamNum Co., Ltd.
15040
+ *
15041
+ * Licensed under the Apache License, Version 2.0 (the "License");
15042
+ * you may not use this file except in compliance with the License.
15043
+ * You may obtain a copy of the License at
15044
+ *
15045
+ * http://www.apache.org/licenses/LICENSE-2.0
15046
+ *
15047
+ * Unless required by applicable law or agreed to in writing, software
15048
+ * distributed under the License is distributed on an "AS IS" BASIS,
15049
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15050
+ * See the License for the specific language governing permissions and
15051
+ * limitations under the License.
15052
+ */
15053
+
14782
15054
  //#endregion
14783
15055
  //#region src/engine/utils/check-variant-error.ts
14784
15056
  function checkVariantErrorIsArray(variant) {
@@ -14883,6 +15155,7 @@ var BaseFunction = class {
14883
15155
  _defineProperty(this, "_sheetOrder", void 0);
14884
15156
  _defineProperty(this, "_sheetNameMap", void 0);
14885
15157
  _defineProperty(this, "_formulaDataModel", void 0);
15158
+ _defineProperty(this, "_unitReferenceResolver", void 0);
14886
15159
  _defineProperty(this, "_rowCount", -1);
14887
15160
  _defineProperty(this, "_columnCount", -1);
14888
15161
  _defineProperty(
@@ -14925,6 +15198,12 @@ var BaseFunction = class {
14925
15198
  "needsFormulaDataModel",
14926
15199
  false
14927
15200
  );
15201
+ _defineProperty(
15202
+ this,
15203
+ /** Whether the function resolves external Unit qualifiers. */
15204
+ "needsUnitReferenceResolver",
15205
+ false
15206
+ );
14928
15207
  _defineProperty(
14929
15208
  this,
14930
15209
  /**
@@ -15033,6 +15312,9 @@ var BaseFunction = class {
15033
15312
  setFormulaDataModel(_formulaDataModel) {
15034
15313
  this._formulaDataModel = _formulaDataModel;
15035
15314
  }
15315
+ setUnitReferenceResolver(unitReferenceResolver) {
15316
+ this._unitReferenceResolver = unitReferenceResolver;
15317
+ }
15036
15318
  setSheetRowColumnCount(rowCount, columnCount) {
15037
15319
  this._rowCount = rowCount;
15038
15320
  this._columnCount = columnCount;
@@ -30194,6 +30476,7 @@ var Indirect = class extends BaseFunction {
30194
30476
  super(..._args);
30195
30477
  _defineProperty(this, "minParams", 1);
30196
30478
  _defineProperty(this, "maxParams", 2);
30479
+ _defineProperty(this, "needsUnitReferenceResolver", true);
30197
30480
  }
30198
30481
  isAddress() {
30199
30482
  return true;
@@ -30223,6 +30506,7 @@ var Indirect = class extends BaseFunction {
30223
30506
  if (a1Value === 0) {
30224
30507
  const { range, sheetName, unitId } = deserializeRangeForR1C1(refTextV);
30225
30508
  const rangeReferenceObject = new RangeReferenceObject(range);
30509
+ rangeReferenceObject.setUnitQualifier(unitId);
30226
30510
  rangeReferenceObject.setForcedUnitIdDirect(unitId);
30227
30511
  rangeReferenceObject.setForcedSheetName(sheetName);
30228
30512
  return this._setDefault(rangeReferenceObject);
@@ -30233,12 +30517,23 @@ var Indirect = class extends BaseFunction {
30233
30517
  const { range, sheetName, unitId } = deserializeRangeWithSheetWithCache(refTextV);
30234
30518
  if (Number.isNaN(range.startRow) || range.endRow + 1 > MAX_ROW_COUNT || Number.isNaN(range.startColumn) || range.endColumn + 1 > MAX_COLUMN_COUNT) return ErrorValueObject.create("#REF!");
30235
30519
  const rangeReferenceObject = new RangeReferenceObject(range);
30520
+ rangeReferenceObject.setUnitQualifier(unitId);
30236
30521
  rangeReferenceObject.setForcedUnitIdDirect(unitId);
30237
30522
  rangeReferenceObject.setForcedSheetName(sheetName);
30238
30523
  return this._setDefault(rangeReferenceObject);
30239
30524
  }
30240
30525
  _setDefault(object) {
30241
30526
  if (this.unitId == null || this.subUnitId == null) return ErrorValueObject.create("#REF!");
30527
+ const unitQualifier = object.getUnitQualifier();
30528
+ if (unitQualifier && this._unitReferenceResolver) {
30529
+ const resolution = this._unitReferenceResolver.resolve({
30530
+ hostUnitId: this.unitId,
30531
+ qualifier: unitQualifier,
30532
+ referenceKind: "a1"
30533
+ });
30534
+ if (typeof resolution === "string") return ErrorValueObject.create(resolution);
30535
+ object.setForcedUnitIdDirect(resolution.unitId);
30536
+ }
30242
30537
  object.setDefaultUnitId(this.unitId);
30243
30538
  object.setDefaultSheetId(this.subUnitId);
30244
30539
  return object;
@@ -41780,7 +42075,7 @@ function getObjectValue(result, isUseStrip = false) {
41780
42075
  //#endregion
41781
42076
  //#region package.json
41782
42077
  var name = "@univerjs/engine-formula";
41783
- var version = "1.0.0-alpha.3";
42078
+ var version = "1.0.0-alpha.5";
41784
42079
 
41785
42080
  //#endregion
41786
42081
  //#region src/services/global-computing-status.service.ts
@@ -41849,6 +42144,242 @@ let ComputingStatusReporterController = class ComputingStatusReporterController
41849
42144
  };
41850
42145
  ComputingStatusReporterController = __decorate([__decorateParam(0, ICommandService), __decorateParam(1, Inject(GlobalComputingStatusService))], ComputingStatusReporterController);
41851
42146
 
42147
+ //#endregion
42148
+ //#region src/services/formula-calculation-trigger.service.ts
42149
+ const LOCAL_ONLY = { onlyLocal: true };
42150
+ const CALCULATION_DEBOUNCE_TIME = 10;
42151
+ let FormulaCalculationTriggerService = class FormulaCalculationTriggerService extends Disposable {
42152
+ constructor(_commandService, _activeDirtyManagerService) {
42153
+ super();
42154
+ this._commandService = _commandService;
42155
+ this._activeDirtyManagerService = _activeDirtyManagerService;
42156
+ _defineProperty(this, "_waitingCommandQueue", []);
42157
+ _defineProperty(this, "_pendingDirtyData", createEmptyDirtyData());
42158
+ _defineProperty(this, "_runningDirtyData", createEmptyDirtyData());
42159
+ _defineProperty(this, "_timer", void 0);
42160
+ _defineProperty(this, "_started", false);
42161
+ _defineProperty(this, "_executionInProgress", false);
42162
+ _defineProperty(this, "_hasPendingCalculation", false);
42163
+ _defineProperty(this, "_stopRequested", false);
42164
+ this._initialize();
42165
+ }
42166
+ start() {
42167
+ if (this._started) return;
42168
+ this._started = true;
42169
+ this._scheduleFlush();
42170
+ }
42171
+ dispose() {
42172
+ clearTimeout(this._timer);
42173
+ this._waitingCommandQueue = [];
42174
+ this._pendingDirtyData = createEmptyDirtyData();
42175
+ this._runningDirtyData = createEmptyDirtyData();
42176
+ super.dispose();
42177
+ }
42178
+ _initialize() {
42179
+ this.disposeWithMe(this._commandService.onCommandExecuted((command, options) => {
42180
+ var _conversion$shouldTri;
42181
+ if (command.id === SetFormulaCalculationStartMutation.id) {
42182
+ this._executionInProgress = true;
42183
+ return;
42184
+ }
42185
+ if (command.id === SetFormulaCalculationNotificationMutation.id) {
42186
+ this._handleCalculationNotification(command.params);
42187
+ return;
42188
+ }
42189
+ const conversion = this._activeDirtyManagerService.get(command.id);
42190
+ if (!conversion) return;
42191
+ if (((_conversion$shouldTri = conversion.shouldTrigger) === null || _conversion$shouldTri === void 0 ? void 0 : _conversion$shouldTri.call(conversion, command, options)) === false) return;
42192
+ this._waitingCommandQueue.push(command);
42193
+ this._scheduleFlush();
42194
+ }));
42195
+ }
42196
+ _scheduleFlush() {
42197
+ if (!this._started || this._waitingCommandQueue.length === 0 && !this._hasPendingCalculation) return;
42198
+ clearTimeout(this._timer);
42199
+ this._timer = setTimeout(() => this._flush(), CALCULATION_DEBOUNCE_TIME);
42200
+ }
42201
+ _flush() {
42202
+ const commands = this._waitingCommandQueue;
42203
+ const dirtyData = this._generateDirty(commands);
42204
+ this._waitingCommandQueue = [];
42205
+ this._timer = void 0;
42206
+ if (hasDirtyData(dirtyData) || commands.some(({ id }) => id === SetTriggerFormulaCalculationStartMutation.id)) {
42207
+ this._pendingDirtyData = mergeDirtyData(this._pendingDirtyData, dirtyData);
42208
+ this._hasPendingCalculation = true;
42209
+ }
42210
+ if (!this._hasPendingCalculation) return;
42211
+ if (this._executionInProgress) {
42212
+ if (!this._stopRequested && dirtyDataIntersects(this._runningDirtyData, this._pendingDirtyData)) {
42213
+ this._stopRequested = true;
42214
+ this._commandService.executeCommand(SetFormulaCalculationStopMutation.id, {}, LOCAL_ONLY);
42215
+ }
42216
+ return;
42217
+ }
42218
+ this._startCalculation();
42219
+ }
42220
+ _startCalculation() {
42221
+ this._runningDirtyData = this._pendingDirtyData;
42222
+ this._pendingDirtyData = createEmptyDirtyData();
42223
+ this._hasPendingCalculation = false;
42224
+ this._executionInProgress = true;
42225
+ this._stopRequested = false;
42226
+ this._commandService.executeCommand(SetFormulaCalculationStartMutation.id, { ...this._runningDirtyData }, LOCAL_ONLY);
42227
+ }
42228
+ _handleCalculationNotification(params) {
42229
+ if (params.stageInfo != null) {
42230
+ this._executionInProgress = true;
42231
+ return;
42232
+ }
42233
+ const state = params.functionsExecutedState;
42234
+ if (state == null) return;
42235
+ if (!(state === 1 || state === 3 || state === 2) || !this._executionInProgress) return;
42236
+ this._executionInProgress = false;
42237
+ this._stopRequested = false;
42238
+ if (state === 1) this._pendingDirtyData = mergeDirtyData(this._runningDirtyData, this._pendingDirtyData);
42239
+ this._runningDirtyData = createEmptyDirtyData();
42240
+ if (this._hasPendingCalculation || this._waitingCommandQueue.length > 0) this._scheduleFlush();
42241
+ }
42242
+ _generateDirty(commands) {
42243
+ return commands.reduce((result, command) => {
42244
+ const conversion = this._activeDirtyManagerService.get(command.id);
42245
+ return conversion ? mergeDirtyData(result, conversion.getDirtyData(command)) : result;
42246
+ }, createEmptyDirtyData());
42247
+ }
42248
+ };
42249
+ FormulaCalculationTriggerService = __decorate([__decorateParam(0, ICommandService), __decorateParam(1, IActiveDirtyManagerService)], FormulaCalculationTriggerService);
42250
+ function createEmptyDirtyData() {
42251
+ return {
42252
+ forceCalculation: false,
42253
+ dirtyRanges: [],
42254
+ dirtyNameMap: {},
42255
+ dirtyDefinedNameMap: {},
42256
+ dirtySuperTableMap: {},
42257
+ dirtyUnitFeatureMap: {},
42258
+ dirtyUnitOtherFormulaMap: {},
42259
+ clearDependencyTreeCache: {}
42260
+ };
42261
+ }
42262
+ function mergeDirtyData(left, right) {
42263
+ var _right$dirtyRanges, _left$dirtySuperTable;
42264
+ const dirtyRanges = [...left.dirtyRanges];
42265
+ mergeDirtyRanges(dirtyRanges, (_right$dirtyRanges = right.dirtyRanges) !== null && _right$dirtyRanges !== void 0 ? _right$dirtyRanges : []);
42266
+ return {
42267
+ dirtyRanges,
42268
+ dirtyNameMap: mergeDirtyUnitStringMap(left.dirtyNameMap, right.dirtyNameMap),
42269
+ dirtyDefinedNameMap: mergeDirtyUnitStringMap(left.dirtyDefinedNameMap, right.dirtyDefinedNameMap),
42270
+ dirtySuperTableMap: mergeDirtyUnitStringMap((_left$dirtySuperTable = left.dirtySuperTableMap) !== null && _left$dirtySuperTable !== void 0 ? _left$dirtySuperTable : {}, right.dirtySuperTableMap),
42271
+ dirtyUnitFeatureMap: mergeDirtyUnitNestedMap(left.dirtyUnitFeatureMap, right.dirtyUnitFeatureMap),
42272
+ dirtyUnitOtherFormulaMap: mergeDirtyUnitNestedMap(left.dirtyUnitOtherFormulaMap, right.dirtyUnitOtherFormulaMap),
42273
+ clearDependencyTreeCache: mergeDirtyUnitStringMap(left.clearDependencyTreeCache, right.clearDependencyTreeCache),
42274
+ forceCalculation: left.forceCalculation || Boolean(right.forceCalculation)
42275
+ };
42276
+ }
42277
+ function mergeDirtyRanges(target, source) {
42278
+ const keys = new Set(target.map(getDirtyRangeKey));
42279
+ source.forEach((range) => {
42280
+ const key = getDirtyRangeKey(range);
42281
+ if (!keys.has(key)) {
42282
+ keys.add(key);
42283
+ target.push(range);
42284
+ }
42285
+ });
42286
+ }
42287
+ function getDirtyRangeKey({ unitId, sheetId, range }) {
42288
+ return JSON.stringify([
42289
+ unitId,
42290
+ sheetId,
42291
+ range.startRow,
42292
+ range.startColumn,
42293
+ range.endRow,
42294
+ range.endColumn,
42295
+ range.rangeType
42296
+ ]);
42297
+ }
42298
+ function mergeDirtyUnitStringMap(left, right) {
42299
+ const result = { ...left };
42300
+ Object.entries(right !== null && right !== void 0 ? right : {}).forEach(([unitId, values]) => {
42301
+ result[unitId] = {
42302
+ ...result[unitId],
42303
+ ...values
42304
+ };
42305
+ });
42306
+ return result;
42307
+ }
42308
+ function mergeDirtyUnitNestedMap(left, right) {
42309
+ const result = { ...left };
42310
+ Object.entries(right !== null && right !== void 0 ? right : {}).forEach(([unitId, sheets]) => {
42311
+ const unitResult = { ...result[unitId] };
42312
+ Object.entries(sheets !== null && sheets !== void 0 ? sheets : {}).forEach(([sheetId, values]) => {
42313
+ unitResult[sheetId] = {
42314
+ ...unitResult[sheetId],
42315
+ ...values
42316
+ };
42317
+ });
42318
+ result[unitId] = unitResult;
42319
+ });
42320
+ return result;
42321
+ }
42322
+ function hasDirtyData(dirtyData) {
42323
+ return dirtyData.forceCalculation || dirtyData.dirtyRanges.length > 0 || hasNestedValue(dirtyData.dirtyNameMap) || hasNestedValue(dirtyData.dirtyDefinedNameMap) || hasNestedValue(dirtyData.dirtySuperTableMap) || hasNestedValue(dirtyData.dirtyUnitFeatureMap) || hasNestedValue(dirtyData.dirtyUnitOtherFormulaMap) || hasNestedValue(dirtyData.clearDependencyTreeCache);
42324
+ }
42325
+ function hasNestedValue(value) {
42326
+ if (value == null) return false;
42327
+ if (typeof value !== "object") return true;
42328
+ return Object.values(value).some(hasNestedValue);
42329
+ }
42330
+ function dirtyDataIntersects(left, right) {
42331
+ if (left.forceCalculation || right.forceCalculation) return true;
42332
+ if (left.dirtyRanges.some((leftRange) => right.dirtyRanges.some((rightRange) => leftRange.unitId === rightRange.unitId && leftRange.sheetId === rightRange.sheetId && Rectangle.intersects(leftRange.range, rightRange.range))) || clearedSheetIntersects(left, right) || clearedSheetIntersects(right, left)) return true;
42333
+ return [
42334
+ [left.dirtyNameMap, right.dirtyNameMap],
42335
+ [left.dirtyDefinedNameMap, right.dirtyDefinedNameMap],
42336
+ [left.dirtySuperTableMap, right.dirtySuperTableMap],
42337
+ [left.dirtyUnitFeatureMap, right.dirtyUnitFeatureMap],
42338
+ [left.dirtyUnitOtherFormulaMap, right.dirtyUnitOtherFormulaMap],
42339
+ [left.clearDependencyTreeCache, right.clearDependencyTreeCache]
42340
+ ].some(([leftMap, rightMap]) => hasSameNestedKey(leftMap, rightMap));
42341
+ }
42342
+ function clearedSheetIntersects(cleared, dirty) {
42343
+ return Object.entries(cleared.clearDependencyTreeCache).some(([unitId, sheets]) => Object.keys(sheets !== null && sheets !== void 0 ? sheets : {}).some((sheetId) => {
42344
+ var _dirty$dirtyNameMap$u, _dirty$dirtyUnitFeatu, _dirty$dirtyUnitOther;
42345
+ return dirty.dirtyRanges.some((range) => range.unitId === unitId && range.sheetId === sheetId) || ((_dirty$dirtyNameMap$u = dirty.dirtyNameMap[unitId]) === null || _dirty$dirtyNameMap$u === void 0 ? void 0 : _dirty$dirtyNameMap$u[sheetId]) != null || ((_dirty$dirtyUnitFeatu = dirty.dirtyUnitFeatureMap[unitId]) === null || _dirty$dirtyUnitFeatu === void 0 ? void 0 : _dirty$dirtyUnitFeatu[sheetId]) != null || ((_dirty$dirtyUnitOther = dirty.dirtyUnitOtherFormulaMap[unitId]) === null || _dirty$dirtyUnitOther === void 0 ? void 0 : _dirty$dirtyUnitOther[sheetId]) != null;
42346
+ }));
42347
+ }
42348
+ function hasSameNestedKey(left, right) {
42349
+ if (left == null || right == null || typeof left !== "object" || typeof right !== "object") return left != null && right != null;
42350
+ const rightRecord = right;
42351
+ return Object.entries(left).some(([key, value]) => Object.prototype.hasOwnProperty.call(rightRecord, key) && hasSameNestedKey(value, rightRecord[key]));
42352
+ }
42353
+
42354
+ //#endregion
42355
+ //#region src/controllers/formula-calculation-trigger.controller.ts
42356
+ /**
42357
+ * Copyright 2023-present DreamNum Co., Ltd.
42358
+ *
42359
+ * Licensed under the Apache License, Version 2.0 (the "License");
42360
+ * you may not use this file except in compliance with the License.
42361
+ * You may obtain a copy of the License at
42362
+ *
42363
+ * http://www.apache.org/licenses/LICENSE-2.0
42364
+ *
42365
+ * Unless required by applicable law or agreed to in writing, software
42366
+ * distributed under the License is distributed on an "AS IS" BASIS,
42367
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42368
+ * See the License for the specific language governing permissions and
42369
+ * limitations under the License.
42370
+ */
42371
+ let FormulaCalculationTriggerController = class FormulaCalculationTriggerController extends Disposable {
42372
+ constructor(formulaCalculationTriggerService, lifecycleService) {
42373
+ super();
42374
+ if (isNodeEnv()) {
42375
+ formulaCalculationTriggerService.start();
42376
+ return;
42377
+ }
42378
+ this.disposeWithMe(lifecycleService.lifecycle$.pipe(filter((stage) => stage >= LifecycleStages.Rendered), take(1)).subscribe(() => formulaCalculationTriggerService.start()));
42379
+ }
42380
+ };
42381
+ FormulaCalculationTriggerController = __decorate([__decorateParam(0, Inject(FormulaCalculationTriggerService)), __decorateParam(1, Inject(LifecycleService))], FormulaCalculationTriggerController);
42382
+
41852
42383
  //#endregion
41853
42384
  //#region src/controllers/formula.controller.ts
41854
42385
  let FormulaController = class FormulaController extends Disposable {
@@ -42070,153 +42601,6 @@ SetOtherFormulaController = __decorate([
42070
42601
  __decorateParam(2, IDependencyManagerService)
42071
42602
  ], SetOtherFormulaController);
42072
42603
 
42073
- //#endregion
42074
- //#region src/services/formula-calculation-trigger.service.ts
42075
- const LOCAL_ONLY = { onlyLocal: true };
42076
- const CALCULATION_DEBOUNCE_TIME = 100;
42077
- let FormulaCalculationTriggerService = class FormulaCalculationTriggerService extends Disposable {
42078
- constructor(_commandService, _activeDirtyManagerService) {
42079
- super();
42080
- this._commandService = _commandService;
42081
- this._activeDirtyManagerService = _activeDirtyManagerService;
42082
- _defineProperty(this, "_waitingCommandQueue", []);
42083
- _defineProperty(this, "_executingDirtyData", createEmptyDirtyData());
42084
- _defineProperty(this, "_timer", void 0);
42085
- _defineProperty(this, "_executionInProgress", false);
42086
- _defineProperty(this, "_restartCalculation", false);
42087
- this._initialize();
42088
- }
42089
- dispose() {
42090
- clearTimeout(this._timer);
42091
- this._waitingCommandQueue = [];
42092
- this._executingDirtyData = createEmptyDirtyData();
42093
- super.dispose();
42094
- }
42095
- _initialize() {
42096
- this.disposeWithMe(this._commandService.onCommandExecuted((command, options) => {
42097
- var _conversion$shouldTri;
42098
- if (command.id === SetFormulaCalculationStartMutation.id) {
42099
- this._executionInProgress = true;
42100
- return;
42101
- }
42102
- if (command.id === SetFormulaCalculationNotificationMutation.id) {
42103
- this._handleCalculationNotification(command.params);
42104
- return;
42105
- }
42106
- const conversion = this._activeDirtyManagerService.get(command.id);
42107
- if (!conversion) return;
42108
- if (((_conversion$shouldTri = conversion.shouldTrigger) === null || _conversion$shouldTri === void 0 ? void 0 : _conversion$shouldTri.call(conversion, command, options)) === false) return;
42109
- this._waitingCommandQueue.push(command);
42110
- clearTimeout(this._timer);
42111
- this._timer = setTimeout(() => this._flush(), CALCULATION_DEBOUNCE_TIME);
42112
- }));
42113
- }
42114
- _flush() {
42115
- const dirtyData = this._generateDirty(this._waitingCommandQueue);
42116
- this._waitingCommandQueue = [];
42117
- this._timer = void 0;
42118
- if (!hasDirtyData(dirtyData)) return;
42119
- this._executingDirtyData = mergeDirtyData(this._executingDirtyData, dirtyData);
42120
- if (this._executionInProgress) {
42121
- this._restartCalculation = true;
42122
- this._commandService.executeCommand(SetFormulaCalculationStopMutation.id, {}, LOCAL_ONLY);
42123
- return;
42124
- }
42125
- this._startCalculation();
42126
- }
42127
- _startCalculation() {
42128
- this._executionInProgress = true;
42129
- this._commandService.executeCommand(SetFormulaCalculationStartMutation.id, { ...this._executingDirtyData }, LOCAL_ONLY);
42130
- }
42131
- _handleCalculationNotification(params) {
42132
- if (params.stageInfo != null) {
42133
- this._executionInProgress = true;
42134
- return;
42135
- }
42136
- const state = params.functionsExecutedState;
42137
- if (state == null) return;
42138
- this._executionInProgress = false;
42139
- if (state === 1 && this._restartCalculation) {
42140
- this._restartCalculation = false;
42141
- this._startCalculation();
42142
- return;
42143
- }
42144
- this._restartCalculation = false;
42145
- this._executingDirtyData = createEmptyDirtyData();
42146
- }
42147
- _generateDirty(commands) {
42148
- return commands.reduce((result, command) => {
42149
- const conversion = this._activeDirtyManagerService.get(command.id);
42150
- return conversion ? mergeDirtyData(result, conversion.getDirtyData(command)) : result;
42151
- }, createEmptyDirtyData());
42152
- }
42153
- };
42154
- FormulaCalculationTriggerService = __decorate([__decorateParam(0, ICommandService), __decorateParam(1, IActiveDirtyManagerService)], FormulaCalculationTriggerService);
42155
- function createEmptyDirtyData() {
42156
- return {
42157
- forceCalculation: false,
42158
- dirtyRanges: [],
42159
- dirtyNameMap: {},
42160
- dirtyDefinedNameMap: {},
42161
- dirtySuperTableMap: {},
42162
- dirtyUnitFeatureMap: {},
42163
- dirtyUnitOtherFormulaMap: {},
42164
- clearDependencyTreeCache: {}
42165
- };
42166
- }
42167
- function mergeDirtyData(left, right) {
42168
- var _right$dirtyRanges, _left$dirtySuperTable;
42169
- const dirtyRanges = [...left.dirtyRanges];
42170
- mergeDirtyRanges(dirtyRanges, (_right$dirtyRanges = right.dirtyRanges) !== null && _right$dirtyRanges !== void 0 ? _right$dirtyRanges : []);
42171
- return {
42172
- dirtyRanges,
42173
- dirtyNameMap: mergeDirtyUnitStringMap(left.dirtyNameMap, right.dirtyNameMap),
42174
- dirtyDefinedNameMap: mergeDirtyUnitStringMap(left.dirtyDefinedNameMap, right.dirtyDefinedNameMap),
42175
- dirtySuperTableMap: mergeDirtyUnitStringMap((_left$dirtySuperTable = left.dirtySuperTableMap) !== null && _left$dirtySuperTable !== void 0 ? _left$dirtySuperTable : {}, right.dirtySuperTableMap),
42176
- dirtyUnitFeatureMap: mergeDirtyUnitNestedMap(left.dirtyUnitFeatureMap, right.dirtyUnitFeatureMap),
42177
- dirtyUnitOtherFormulaMap: mergeDirtyUnitNestedMap(left.dirtyUnitOtherFormulaMap, right.dirtyUnitOtherFormulaMap),
42178
- clearDependencyTreeCache: mergeDirtyUnitStringMap(left.clearDependencyTreeCache, right.clearDependencyTreeCache),
42179
- forceCalculation: left.forceCalculation || Boolean(right.forceCalculation)
42180
- };
42181
- }
42182
- function mergeDirtyRanges(target, source) {
42183
- source.forEach((range) => {
42184
- if (!target.some((item) => item.unitId === range.unitId && item.sheetId === range.sheetId && item.range.startRow === range.range.startRow && item.range.startColumn === range.range.startColumn && item.range.endRow === range.range.endRow && item.range.endColumn === range.range.endColumn)) target.push(range);
42185
- });
42186
- }
42187
- function mergeDirtyUnitStringMap(left, right) {
42188
- const result = { ...left };
42189
- Object.entries(right !== null && right !== void 0 ? right : {}).forEach(([unitId, values]) => {
42190
- result[unitId] = {
42191
- ...result[unitId],
42192
- ...values
42193
- };
42194
- });
42195
- return result;
42196
- }
42197
- function mergeDirtyUnitNestedMap(left, right) {
42198
- const result = { ...left };
42199
- Object.entries(right !== null && right !== void 0 ? right : {}).forEach(([unitId, sheets]) => {
42200
- const unitResult = { ...result[unitId] };
42201
- Object.entries(sheets !== null && sheets !== void 0 ? sheets : {}).forEach(([sheetId, values]) => {
42202
- unitResult[sheetId] = {
42203
- ...unitResult[sheetId],
42204
- ...values
42205
- };
42206
- });
42207
- result[unitId] = unitResult;
42208
- });
42209
- return result;
42210
- }
42211
- function hasDirtyData(dirtyData) {
42212
- return dirtyData.forceCalculation || dirtyData.dirtyRanges.length > 0 || hasNestedValue(dirtyData.dirtyNameMap) || hasNestedValue(dirtyData.dirtyDefinedNameMap) || hasNestedValue(dirtyData.dirtySuperTableMap) || hasNestedValue(dirtyData.dirtyUnitFeatureMap) || hasNestedValue(dirtyData.dirtyUnitOtherFormulaMap) || hasNestedValue(dirtyData.clearDependencyTreeCache);
42213
- }
42214
- function hasNestedValue(value) {
42215
- if (value == null) return false;
42216
- if (typeof value !== "object") return true;
42217
- return Object.values(value).some(hasNestedValue);
42218
- }
42219
-
42220
42604
  //#endregion
42221
42605
  //#region src/services/formula-common.ts
42222
42606
  let FormulaResultStatus = /* @__PURE__ */ function(FormulaResultStatus) {
@@ -42417,7 +42801,11 @@ let UniverFormulaEnginePlugin = class UniverFormulaEnginePlugin extends Plugin {
42417
42801
  }
42418
42802
  onReady() {
42419
42803
  var _this$_config;
42420
- touchDependencies(this._injector, [[FormulaController], [SuperTableActiveDirtyController]]);
42804
+ touchDependencies(this._injector, [
42805
+ [FormulaController],
42806
+ [FormulaCalculationTriggerController],
42807
+ [SuperTableActiveDirtyController]
42808
+ ]);
42421
42809
  if (!((_this$_config = this._config) === null || _this$_config === void 0 ? void 0 : _this$_config.notExecuteFormula)) touchDependencies(this._injector, [
42422
42810
  [SetOtherFormulaController],
42423
42811
  [SetFeatureCalculationController],
@@ -42443,6 +42831,7 @@ let UniverFormulaEnginePlugin = class UniverFormulaEnginePlugin extends Plugin {
42443
42831
  [GlobalComputingStatusService],
42444
42832
  [FormulaDataModel],
42445
42833
  [FormulaController],
42834
+ [FormulaCalculationTriggerController],
42446
42835
  [SuperTableActiveDirtyController],
42447
42836
  [ComputingStatusReporterController]
42448
42837
  ];
@@ -42455,7 +42844,8 @@ let UniverFormulaEnginePlugin = class UniverFormulaEnginePlugin extends Plugin {
42455
42844
  if (!((_this$_config3 = this._config) === null || _this$_config3 === void 0 ? void 0 : _this$_config3.notExecuteFormula)) [
42456
42845
  [ICalculateFormulaService, { useClass: CalculateFormulaService }],
42457
42846
  [IDependencyManagerService, { useClass: DependencyManagerService }],
42458
- [IFormulaDependencyGenerator, { useClass: FormulaDependencyGenerator }]
42847
+ [IFormulaDependencyGenerator, { useClass: FormulaDependencyGenerator }],
42848
+ [IFormulaUnitReferenceResolver, { useClass: FormulaUnitReferenceResolver }]
42459
42849
  ].forEach((dependency) => this._injector.add(dependency));
42460
42850
  }
42461
42851
  };
@@ -42465,4 +42855,4 @@ _defineProperty(UniverFormulaEnginePlugin, "version", version);
42465
42855
  UniverFormulaEnginePlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverFormulaEnginePlugin);
42466
42856
 
42467
42857
  //#endregion
42468
- export { ALL_IMPLEMENTED_FUNCTIONS, ALL_IMPLEMENTED_FUNCTIONS_SET, ActiveDirtyManagerService, ArrayValueObject, AstRootNodeFactory, AstTreeBuilder, AsyncArrayObject, AsyncCustomFunction, AsyncObject, BaseFunction, BaseReferenceObject, BaseValueObject, BooleanValue, BooleanValueObject, CELL_INVERTED_INDEX_CACHE, CalculateController, CalculateFormulaService, CustomFunction, DEFAULT_CYCLE_REFERENCE_COUNT, DEFAULT_INTERVAL_COUNT, DEFAULT_TOKEN_LAMBDA_FUNCTION_NAME, DEFAULT_TOKEN_LET_FUNCTION_NAME, DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER, DEFAULT_TOKEN_TYPE_PARAMETER, DEFAULT_TOKEN_TYPE_ROOT, DefinedNamesService, DependencyManagerBaseService, DependencyManagerService, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_PLUGIN_CONFIG_KEY, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, ERROR_TYPE_SET, ErrorType, ErrorValueObject, FORMULA_REF_TO_ARRAY_CACHE, FUNCTION_NAMES_ARRAY, FUNCTION_NAMES_COMPATIBILITY, FUNCTION_NAMES_CUBE, FUNCTION_NAMES_DATABASE, FUNCTION_NAMES_DATE, FUNCTION_NAMES_ENGINEERING, FUNCTION_NAMES_FINANCIAL, FUNCTION_NAMES_INFORMATION, FUNCTION_NAMES_LOGICAL, FUNCTION_NAMES_LOOKUP, FUNCTION_NAMES_MATH, FUNCTION_NAMES_STATISTICAL, FUNCTION_NAMES_TEXT, FUNCTION_NAMES_UNIVER, FUNCTION_NAMES_WEB, FeatureCalculationManagerService, FormulaCalculationTriggerService, FormulaCurrentConfigService, FormulaDataModel, FormulaDependencyGenerator, FormulaDependencyTree, FormulaDependencyTreeModel, FormulaDependencyTreeType, FormulaDependencyTreeVirtual, FormulaExecuteStageType, FormulaExecutedStateType, FormulaResultStatus, FormulaRuntimeService, FunctionNodeFactory, FunctionService, FunctionType, GlobalComputingStatusService, HyperlinkEngineFormulaService, IActiveDirtyManagerService, ICalculateFormulaService, IDefinedNamesService, IDependencyManagerService, IFeatureCalculationManagerService, IFormulaCurrentConfigService, IFormulaDependencyGenerator, IFormulaRuntimeService, IFunctionService, IHyperlinkEngineFormulaService, IOtherFormulaManagerService, ISheetRowFilteredService, ISuperTableService, Interpreter, LambdaNodeFactory, LambdaParameterNodeFactory, LambdaValueObjectObject, Lexer, LexerNode, LexerTreeBuilder, NEW_EXCEL_FUNCTIONS, NullValueObject, NumberValueObject, OPERATOR_TOKEN_SET, OperatorNodeFactory, OtherFormulaBizType, OtherFormulaManagerService, OtherFormulaMarkDirty, PrefixNodeFactory, RangeReferenceObject, ReferenceNodeFactory, RegisterFunctionMutation, RegisterOtherFormulaService, RemoveDefinedNameMutation, RemoveFeatureCalculationMutation, RemoveOtherFormulaMutation, RemoveSuperTableMutation, SUFFIX_TOKEN_SET, SetArrayFormulaDataMutation, SetCellFormulaDependencyCalculationMutation, SetCellFormulaDependencyCalculationResultMutation, SetDefinedNameMutation, SetDefinedNameMutationFactory, SetFeatureCalculationMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDataMutation, SetFormulaDependencyCalculationMutation, SetFormulaDependencyCalculationResultMutation, SetFormulaStringBatchCalculationMutation, SetFormulaStringBatchCalculationResultMutation, SetImageFormulaDataMutation, SetOtherFormulaMutation, SetQueryFormulaDependencyAllMutation, SetQueryFormulaDependencyAllResultMutation, SetQueryFormulaDependencyMutation, SetQueryFormulaDependencyResultMutation, SetSuperTableMutation, SetSuperTableOptionMutation, SetTriggerFormulaCalculationStartMutation, SheetRowFilteredService, StringValueObject, SuffixNodeFactory, SuperTableActiveDirtyController, SuperTableService, UnionNodeFactory, UniverFormulaEnginePlugin, ValueNodeFactory, ValueObjectFactory, compareToken, convertUnitDataToRuntime, deserializeRangeForR1C1, deserializeRangeWithSheet, deserializeRangeWithSheetWithCache, excelDateSerial, extractFormulaError, functionArray, functionCompatibility, functionCube, functionDatabase, functionDate, functionEngineering, functionFinancial, functionInformation, functionLogical, functionLookup, functionMath, functionMeta, functionStatistical, functionText, functionUniver, functionWeb, generateAstNode, generateExecuteAstNodeData, generateRandomDependencyTreeId, generateStringWithSequence, getAbsoluteRefTypeWitString, getAbsoluteRefTypeWithSingleString, getObjectValue, getRangeWithRefsString, handleNumfmtInCell, handleRefStringInfo, includeFormulaLexerToken, initSheetFormulaData, isFormulaLexerToken, isInDirtyRange, isReferenceString, isReferenceStringWithEffectiveColumn, isReferenceStrings, matchRefDrawToken, matchToken, needsQuoting, normalizeSheetName, operatorToken, prefixToken, quoteSheetName, sequenceNodeType, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet, singleReferenceToGrid, splitTableStructuredRef, strip, stripErrorMargin, unquoteSheetName };
42858
+ export { ALL_IMPLEMENTED_FUNCTIONS, ALL_IMPLEMENTED_FUNCTIONS_SET, ActiveDirtyManagerService, ArrayValueObject, AstRootNodeFactory, AstTreeBuilder, AsyncArrayObject, AsyncCustomFunction, AsyncObject, BaseFunction, BaseReferenceObject, BaseValueObject, BooleanValue, BooleanValueObject, CELL_INVERTED_INDEX_CACHE, CalculateController, CalculateFormulaService, CustomFunction, DEFAULT_CYCLE_REFERENCE_COUNT, DEFAULT_INTERVAL_COUNT, DEFAULT_TOKEN_LAMBDA_FUNCTION_NAME, DEFAULT_TOKEN_LET_FUNCTION_NAME, DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER, DEFAULT_TOKEN_TYPE_PARAMETER, DEFAULT_TOKEN_TYPE_ROOT, DefinedNamesService, DependencyManagerBaseService, DependencyManagerService, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_PLUGIN_CONFIG_KEY, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, ERROR_TYPE_SET, ErrorType, ErrorValueObject, FORMULA_REF_TO_ARRAY_CACHE, FUNCTION_NAMES_ARRAY, FUNCTION_NAMES_COMPATIBILITY, FUNCTION_NAMES_CUBE, FUNCTION_NAMES_DATABASE, FUNCTION_NAMES_DATE, FUNCTION_NAMES_ENGINEERING, FUNCTION_NAMES_FINANCIAL, FUNCTION_NAMES_INFORMATION, FUNCTION_NAMES_LOGICAL, FUNCTION_NAMES_LOOKUP, FUNCTION_NAMES_MATH, FUNCTION_NAMES_STATISTICAL, FUNCTION_NAMES_TEXT, FUNCTION_NAMES_UNIVER, FUNCTION_NAMES_WEB, FeatureCalculationManagerService, FormulaCalculationTriggerService, FormulaCurrentConfigService, FormulaDataModel, FormulaDependencyGenerator, FormulaDependencyTree, FormulaDependencyTreeModel, FormulaDependencyTreeType, FormulaDependencyTreeVirtual, FormulaExecuteStageType, FormulaExecutedStateType, FormulaResultStatus, FormulaRuntimeService, FormulaUnitReferenceResolver, FunctionNodeFactory, FunctionService, FunctionType, GlobalComputingStatusService, HyperlinkEngineFormulaService, IActiveDirtyManagerService, ICalculateFormulaService, IDefinedNamesService, IDependencyManagerService, IFeatureCalculationManagerService, IFormulaCurrentConfigService, IFormulaDependencyGenerator, IFormulaRuntimeService, IFormulaUnitReferenceResolver, IFunctionService, IHyperlinkEngineFormulaService, IOtherFormulaManagerService, ISheetRowFilteredService, ISuperTableService, Interpreter, LambdaNodeFactory, LambdaParameterNodeFactory, LambdaValueObjectObject, Lexer, LexerNode, LexerTreeBuilder, NEW_EXCEL_FUNCTIONS, NullValueObject, NumberValueObject, OPERATOR_TOKEN_SET, OperatorNodeFactory, OtherFormulaBizType, OtherFormulaManagerService, OtherFormulaMarkDirty, PrefixNodeFactory, RangeReferenceObject, ReferenceNodeFactory, RegisterFunctionMutation, RegisterOtherFormulaService, RemoveDefinedNameMutation, RemoveFeatureCalculationMutation, RemoveOtherFormulaMutation, RemoveSuperTableMutation, SUFFIX_TOKEN_SET, SetArrayFormulaDataMutation, SetCellFormulaDependencyCalculationMutation, SetCellFormulaDependencyCalculationResultMutation, SetDefinedNameMutation, SetDefinedNameMutationFactory, SetFeatureCalculationMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDataMutation, SetFormulaDependencyCalculationMutation, SetFormulaDependencyCalculationResultMutation, SetFormulaStringBatchCalculationMutation, SetFormulaStringBatchCalculationResultMutation, SetImageFormulaDataMutation, SetOtherFormulaMutation, SetQueryFormulaDependencyAllMutation, SetQueryFormulaDependencyAllResultMutation, SetQueryFormulaDependencyMutation, SetQueryFormulaDependencyResultMutation, SetSuperTableMutation, SetSuperTableOptionMutation, SetTriggerFormulaCalculationStartMutation, SheetRowFilteredService, StringValueObject, SuffixNodeFactory, SuperTableActiveDirtyController, SuperTableService, UnionNodeFactory, UniverFormulaEnginePlugin, ValueNodeFactory, ValueObjectFactory, compareToken, convertUnitDataToRuntime, deserializeRangeForR1C1, deserializeRangeWithSheet, deserializeRangeWithSheetWithCache, excelDateSerial, extractFormulaError, functionArray, functionCompatibility, functionCube, functionDatabase, functionDate, functionEngineering, functionFinancial, functionInformation, functionLogical, functionLookup, functionMath, functionMeta, functionStatistical, functionText, functionUniver, functionWeb, generateAstNode, generateExecuteAstNodeData, generateRandomDependencyTreeId, generateStringWithSequence, getAbsoluteRefTypeWitString, getAbsoluteRefTypeWithSingleString, getObjectValue, getRangeWithRefsString, handleNumfmtInCell, handleRefStringInfo, includeFormulaLexerToken, initSheetFormulaData, isFormulaLexerToken, isInDirtyRange, isReferenceString, isReferenceStringWithEffectiveColumn, isReferenceStrings, matchRefDrawToken, matchToken, needsQuoting, normalizeFormulaUnitName, normalizeSheetName, operatorToken, prefixToken, quoteSheetName, refactorFormulaUnitQualifier, sequenceNodeType, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet, singleReferenceToGrid, splitTableStructuredRef, strip, stripErrorMargin, unquoteSheetName };