@univerjs/sheets-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/cjs/index.js CHANGED
@@ -3,6 +3,7 @@ let _univerjs_core = require("@univerjs/core");
3
3
  let _univerjs_sheets = require("@univerjs/sheets");
4
4
  let _univerjs_engine_formula = require("@univerjs/engine-formula");
5
5
  let rxjs = require("rxjs");
6
+ let _univerjs_docs = require("@univerjs/docs");
6
7
  let _univerjs_rpc = require("@univerjs/rpc");
7
8
 
8
9
  //#region src/commands/commands/insert-function.command.ts
@@ -600,6 +601,7 @@ let ImageFormulaCellInterceptorController = class ImageFormulaCellInterceptorCon
600
601
  if (isErrorImage) return next(this._errorValueCell);
601
602
  const finalWidth = width || imageNaturalWidth;
602
603
  const finalHeight = height || imageNaturalHeight;
604
+ if (!finalWidth || !finalHeight) return next(this._errorValueCell);
603
605
  const docDataModel = (0, _univerjs_core.createDocumentModelWithStyle)("", {});
604
606
  const docDrawingParam = {
605
607
  unitId,
@@ -614,21 +616,7 @@ let ImageFormulaCellInterceptorController = class ImageFormulaCellInterceptorCon
614
616
  width: finalWidth,
615
617
  height: finalHeight
616
618
  },
617
- docTransform: {
618
- size: {
619
- width: finalWidth,
620
- height: finalHeight
621
- },
622
- positionH: {
623
- relativeFrom: _univerjs_core.ObjectRelativeFromH.PAGE,
624
- posOffset: 0
625
- },
626
- positionV: {
627
- relativeFrom: _univerjs_core.ObjectRelativeFromV.PARAGRAPH,
628
- posOffset: 0
629
- },
630
- angle: 0
631
- },
619
+ docTransform: (0, _univerjs_docs.buildDocTransform)(finalWidth, finalHeight),
632
620
  behindDoc: _univerjs_core.BooleanNumber.FALSE,
633
621
  title: "",
634
622
  description: "",
@@ -742,7 +730,7 @@ let TriggerCalculationController = class TriggerCalculationController extends _u
742
730
  this._totalCalculationTaskCount = 0;
743
731
  this._emitProgress();
744
732
  }
745
- constructor(_commandService, _univerInstanceService, formulaCalculationTriggerService, _logService, _configService, _formulaDataModel, _localeService, _registerOtherFormulaService) {
733
+ constructor(_commandService, _univerInstanceService, _logService, _configService, _formulaDataModel, _localeService, _registerOtherFormulaService) {
746
734
  super();
747
735
  this._commandService = _commandService;
748
736
  this._univerInstanceService = _univerInstanceService;
@@ -880,14 +868,114 @@ let TriggerCalculationController = class TriggerCalculationController extends _u
880
868
  TriggerCalculationController = __decorate([
881
869
  __decorateParam(0, _univerjs_core.ICommandService),
882
870
  __decorateParam(1, _univerjs_core.IUniverInstanceService),
883
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaCalculationTriggerService)),
884
- __decorateParam(3, _univerjs_core.ILogService),
885
- __decorateParam(4, _univerjs_core.IConfigService),
886
- __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel)),
887
- __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
888
- __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_engine_formula.RegisterOtherFormulaService))
871
+ __decorateParam(2, _univerjs_core.ILogService),
872
+ __decorateParam(3, _univerjs_core.IConfigService),
873
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel)),
874
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
875
+ __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_engine_formula.RegisterOtherFormulaService))
889
876
  ], TriggerCalculationController);
890
877
 
878
+ //#endregion
879
+ //#region src/controllers/unit-qualifier-rename.controller.ts
880
+ function collectUnitQualifierFormulaPatches(workbook, oldName, newName) {
881
+ const unitId = workbook.getUnitId();
882
+ return workbook.getSheets().flatMap((sheet) => {
883
+ const updates = new _univerjs_core.ObjectMatrix();
884
+ sheet.getCellMatrix().forValue((row, column, cell) => {
885
+ if (!(cell === null || cell === void 0 ? void 0 : cell.f)) return;
886
+ const formula = (0, _univerjs_engine_formula.refactorFormulaUnitQualifier)(cell.f, oldName, newName);
887
+ if (formula !== cell.f) updates.setValue(row, column, { f: formula });
888
+ });
889
+ const cellValue = updates.getData();
890
+ return Object.keys(cellValue).length > 0 ? [{
891
+ unitId,
892
+ subUnitId: sheet.getSheetId(),
893
+ cellValue
894
+ }] : [];
895
+ });
896
+ }
897
+ let UnitQualifierRenameController = class UnitQualifierRenameController extends _univerjs_core.Disposable {
898
+ constructor(_commandService, _undoRedoService, _univerInstanceService, _definedNamesService) {
899
+ super();
900
+ this._commandService = _commandService;
901
+ this._undoRedoService = _undoRedoService;
902
+ this._univerInstanceService = _univerInstanceService;
903
+ this._definedNamesService = _definedNamesService;
904
+ _defineProperty(this, "_names", /* @__PURE__ */ new Map());
905
+ this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_BASE).forEach((unit) => this._watch(unit));
906
+ this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_BASE).subscribe(({ unit }) => this._watch(unit)));
907
+ this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_BASE).subscribe((unit) => this._names.delete(unit.getUnitId())));
908
+ }
909
+ _watch(unit) {
910
+ const unitId = unit.getUnitId();
911
+ this.disposeWithMe(unit.name$.subscribe((name) => {
912
+ const oldName = this._names.get(unitId);
913
+ this._names.set(unitId, name);
914
+ if (!oldName || oldName === name) return;
915
+ this._refactor(unitId, oldName, name);
916
+ }));
917
+ }
918
+ _refactor(renamedUnitId, oldName, newName) {
919
+ const redos = [];
920
+ const undos = [];
921
+ for (const workbook of this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)) {
922
+ for (const patch of collectUnitQualifierFormulaPatches(workbook, oldName, newName)) {
923
+ const sheet = workbook.getSheetBySheetId(patch.subUnitId);
924
+ if (!sheet) continue;
925
+ const undoCellValue = new _univerjs_core.ObjectMatrix();
926
+ new _univerjs_core.ObjectMatrix(patch.cellValue).forValue((row, column) => {
927
+ var _sheet$getCellRaw;
928
+ undoCellValue.setValue(row, column, (_sheet$getCellRaw = sheet.getCellRaw(row, column)) !== null && _sheet$getCellRaw !== void 0 ? _sheet$getCellRaw : null);
929
+ });
930
+ redos.push({
931
+ id: _univerjs_sheets.SetRangeValuesMutation.id,
932
+ params: patch
933
+ });
934
+ undos.unshift({
935
+ id: _univerjs_sheets.SetRangeValuesMutation.id,
936
+ params: {
937
+ ...patch,
938
+ cellValue: undoCellValue.getData()
939
+ }
940
+ });
941
+ }
942
+ const definedNames = this._definedNamesService.getDefinedNameMap(workbook.getUnitId());
943
+ for (const item of Object.values(definedNames !== null && definedNames !== void 0 ? definedNames : {})) {
944
+ const formulaOrRefString = (0, _univerjs_engine_formula.refactorFormulaUnitQualifier)(item.formulaOrRefString, oldName, newName);
945
+ if (formulaOrRefString !== item.formulaOrRefString) {
946
+ redos.push({
947
+ id: _univerjs_engine_formula.SetDefinedNameMutation.id,
948
+ params: {
949
+ unitId: workbook.getUnitId(),
950
+ ...item,
951
+ formulaOrRefString
952
+ }
953
+ });
954
+ undos.unshift({
955
+ id: _univerjs_engine_formula.SetDefinedNameMutation.id,
956
+ params: {
957
+ unitId: workbook.getUnitId(),
958
+ ...item
959
+ }
960
+ });
961
+ }
962
+ }
963
+ }
964
+ if (!redos.length || !(0, _univerjs_core.sequenceExecute)(redos, this._commandService).result) return;
965
+ this._undoRedoService.pushUndoRedo({
966
+ unitID: renamedUnitId,
967
+ undoMutations: undos,
968
+ redoMutations: redos
969
+ });
970
+ }
971
+ };
972
+ UnitQualifierRenameController = __decorate([
973
+ __decorateParam(0, _univerjs_core.ICommandService),
974
+ __decorateParam(1, _univerjs_core.IUndoRedoService),
975
+ __decorateParam(2, _univerjs_core.IUniverInstanceService),
976
+ __decorateParam(3, _univerjs_engine_formula.IDefinedNamesService)
977
+ ], UnitQualifierRenameController);
978
+
891
979
  //#endregion
892
980
  //#region src/controllers/utils/offset-formula-data.ts
893
981
  function checkFormulaDataNull(formulaData, unitId, sheetId) {
@@ -916,11 +1004,12 @@ const formulaReferenceSheetList = [
916
1004
  13,
917
1005
  14,
918
1006
  15,
919
- 16
1007
+ 16,
1008
+ 17
920
1009
  ];
921
1010
  function getFormulaReferenceMoveUndoRedo(oldFormulaData, newFormulaData, formulaReferenceMoveParam) {
922
1011
  const { type } = formulaReferenceMoveParam;
923
- if (formulaReferenceSheetList.includes(type) || type === 17 && formulaReferenceMoveParam.range == null) return getFormulaReferenceSheet(oldFormulaData, newFormulaData);
1012
+ if (formulaReferenceSheetList.includes(type) || type === 18 && formulaReferenceMoveParam.range == null) return getFormulaReferenceSheet(oldFormulaData, newFormulaData);
924
1013
  else return getFormulaReferenceRange(oldFormulaData, newFormulaData, formulaReferenceMoveParam);
925
1014
  }
926
1015
  function getFormulaReferenceSheet(oldFormulaData, newFormulaData) {
@@ -1125,7 +1214,7 @@ function handleInsertDelete(oldCell, formulaReferenceMoveParam) {
1125
1214
  newCell = handleRefRemoveRow$1(range, oldCell, rangeFilteredRows);
1126
1215
  break;
1127
1216
  case 6:
1128
- case 17:
1217
+ case 18:
1129
1218
  newCell = handleRefRemoveCol$1(range, oldCell);
1130
1219
  break;
1131
1220
  case 7:
@@ -1725,6 +1814,9 @@ function getReferenceMoveParams(workbook, command) {
1725
1814
  case _univerjs_sheets.SetWorksheetNameCommand.id:
1726
1815
  result = handleRefSetWorksheetName(command, workbook);
1727
1816
  break;
1817
+ case _univerjs_sheets.SetWorkbookNameCommand.id:
1818
+ result = handleRefSetWorkbookName(command);
1819
+ break;
1728
1820
  case _univerjs_sheets.RemoveSheetCommand.id:
1729
1821
  result = handleRefRemoveWorksheet(command, workbook);
1730
1822
  break;
@@ -1947,13 +2039,23 @@ function handleRefSetWorksheetName(command, workbook) {
1947
2039
  sheetName: name
1948
2040
  };
1949
2041
  }
2042
+ function handleRefSetWorkbookName(command) {
2043
+ const { params } = command;
2044
+ if (!params) return null;
2045
+ return {
2046
+ type: 12,
2047
+ unitId: params.unitId,
2048
+ sheetId: "",
2049
+ unitName: params.name
2050
+ };
2051
+ }
1950
2052
  function handleRefRemoveWorksheet(command, workbook) {
1951
2053
  const { params } = command;
1952
2054
  if (!params) return null;
1953
2055
  const { unitId, subUnitId } = params;
1954
2056
  const { unitId: workbookId, sheetId } = getCurrentSheetInfo(workbook);
1955
2057
  return {
1956
- type: 12,
2058
+ type: 13,
1957
2059
  unitId: unitId || workbookId,
1958
2060
  sheetId: subUnitId || sheetId
1959
2061
  };
@@ -1964,7 +2066,7 @@ function handleRefSetDefinedName(command, workbook) {
1964
2066
  const { unitId, name, id } = params;
1965
2067
  const { sheetId } = getCurrentSheetInfo(workbook);
1966
2068
  return {
1967
- type: 13,
2069
+ type: 14,
1968
2070
  unitId,
1969
2071
  sheetId,
1970
2072
  definedName: name,
@@ -1977,7 +2079,7 @@ function handleRefRemoveDefinedName(command, workbook) {
1977
2079
  const { unitId, name, id } = params;
1978
2080
  const { sheetId } = getCurrentSheetInfo(workbook);
1979
2081
  return {
1980
- type: 14,
2082
+ type: 15,
1981
2083
  unitId,
1982
2084
  sheetId,
1983
2085
  definedName: name,
@@ -1990,7 +2092,7 @@ function handleRefSetSheetTableName(command, workbook) {
1990
2092
  const { unitId, name: tableName, oldTableName } = params;
1991
2093
  const { sheetId } = getCurrentSheetInfo(workbook);
1992
2094
  return {
1993
- type: 15,
2095
+ type: 16,
1994
2096
  unitId,
1995
2097
  sheetId,
1996
2098
  tableName,
@@ -2003,7 +2105,7 @@ function handleRefRemoveSheetTableName(command, workbook) {
2003
2105
  const { unitId, tableName } = params;
2004
2106
  const { sheetId } = getCurrentSheetInfo(workbook);
2005
2107
  return {
2006
- type: 16,
2108
+ type: 17,
2007
2109
  unitId,
2008
2110
  sheetId,
2009
2111
  oldTableName: tableName
@@ -2016,7 +2118,7 @@ function handleRefRemoveSheetTableColumn(command, workbook) {
2016
2118
  const { unitId, subUnitId, range, tableName, removedColumnNames } = params;
2017
2119
  const { sheetId } = getCurrentSheetInfo(workbook);
2018
2120
  return {
2019
- type: 17,
2121
+ type: 18,
2020
2122
  unitId,
2021
2123
  sheetId: subUnitId || sheetId,
2022
2124
  range,
@@ -2055,6 +2157,10 @@ let UpdateDefinedNameController = class UpdateDefinedNameController extends _uni
2055
2157
  redos: [],
2056
2158
  undos: []
2057
2159
  };
2160
+ if (result.type === 12) {
2161
+ var _this$_univerInstance;
2162
+ result.oldUnitName = (_this$_univerInstance = this._univerInstanceService.getUnit(result.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getName();
2163
+ }
2058
2164
  return this._getUpdateDefinedNameMutations(workbook, result);
2059
2165
  } }));
2060
2166
  }
@@ -2069,6 +2175,28 @@ let UpdateDefinedNameController = class UpdateDefinedNameController extends _uni
2069
2175
  const undoMutations = [];
2070
2176
  Object.values(definedNames).forEach((item) => {
2071
2177
  const { formulaOrRefString } = item;
2178
+ if (type === 12) {
2179
+ const { oldUnitName, unitName } = moveParams;
2180
+ if (!oldUnitName || !unitName) return true;
2181
+ const nextFormula = (0, _univerjs_engine_formula.refactorFormulaUnitQualifier)(formulaOrRefString, oldUnitName, unitName);
2182
+ if (nextFormula === formulaOrRefString) return true;
2183
+ redoMutations.push({
2184
+ id: _univerjs_engine_formula.SetDefinedNameMutation.id,
2185
+ params: {
2186
+ unitId,
2187
+ ...item,
2188
+ formulaOrRefString: nextFormula
2189
+ }
2190
+ });
2191
+ undoMutations.push({
2192
+ id: _univerjs_engine_formula.SetDefinedNameMutation.id,
2193
+ params: {
2194
+ unitId,
2195
+ ...item
2196
+ }
2197
+ });
2198
+ return true;
2199
+ }
2072
2200
  const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaOrRefString);
2073
2201
  if (sequenceNodes == null) return true;
2074
2202
  let shouldModify = false;
@@ -2089,7 +2217,7 @@ let UpdateDefinedNameController = class UpdateDefinedNameController extends _uni
2089
2217
  refOffsetY: 0
2090
2218
  };
2091
2219
  let newRefString = null;
2092
- if (type === 12) newRefString = this._removeSheet(item, unitId, sheetId);
2220
+ if (type === 13) newRefString = this._removeSheet(item, unitId, sheetId);
2093
2221
  else if (type === 11) {
2094
2222
  const { sheetId: userSheetId, sheetName: newSheetName } = moveParams;
2095
2223
  if (newSheetName == null) continue;
@@ -2274,7 +2402,11 @@ let UpdateFormulaController = class UpdateFormulaController extends _univerjs_co
2274
2402
  };
2275
2403
  const result = getReferenceMoveParams(workbook, command);
2276
2404
  if (result) {
2277
- const { unitSheetNameMap } = this._formulaDataModel.getCalculateData();
2405
+ const { unitNameMap, unitSheetNameMap } = this._formulaDataModel.getCalculateData();
2406
+ if (result.type === 12) {
2407
+ var _unitNameMap$result$u;
2408
+ result.oldUnitName = unitNameMap === null || unitNameMap === void 0 || (_unitNameMap$result$u = unitNameMap[result.unitId]) === null || _unitNameMap$result$u === void 0 ? void 0 : _unitNameMap$result$u.name;
2409
+ }
2278
2410
  const oldFormulaData = this._formulaDataModel.getFormulaData();
2279
2411
  const { newFormulaData } = this._getFormulaReferenceMoveInfo(oldFormulaData, unitSheetNameMap, result);
2280
2412
  const { undos, redos } = getFormulaReferenceMoveUndoRedo(oldFormulaData, newFormulaData, result);
@@ -2307,6 +2439,13 @@ let UpdateFormulaController = class UpdateFormulaController extends _univerjs_co
2307
2439
  matrixData.forValue((row, column, formulaDataItem) => {
2308
2440
  if (!formulaDataItem) return true;
2309
2441
  const { f: formulaString, x, y, si } = formulaDataItem;
2442
+ if (type === 12) {
2443
+ const { oldUnitName, unitName } = formulaReferenceMoveParam;
2444
+ if (!oldUnitName || !unitName) return true;
2445
+ const nextFormula = (0, _univerjs_engine_formula.refactorFormulaUnitQualifier)(formulaString, oldUnitName, unitName);
2446
+ if (nextFormula !== formulaString) newFormulaDataItem.setValue(row, column, { f: nextFormula });
2447
+ return true;
2448
+ }
2310
2449
  const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);
2311
2450
  if (sequenceNodes == null) return true;
2312
2451
  let shouldModify = false;
@@ -2318,7 +2457,7 @@ let UpdateFormulaController = class UpdateFormulaController extends _univerjs_co
2318
2457
  const node = sequenceNodes[i];
2319
2458
  if (typeof node === "string") continue;
2320
2459
  const { token, nodeType } = node;
2321
- if ((type === 13 || type === 14) && (nodeType === _univerjs_engine_formula.sequenceNodeType.DEFINED_NAME || nodeType === _univerjs_engine_formula.sequenceNodeType.FUNCTION)) {
2460
+ if ((type === 14 || type === 15) && (nodeType === _univerjs_engine_formula.sequenceNodeType.DEFINED_NAME || nodeType === _univerjs_engine_formula.sequenceNodeType.FUNCTION)) {
2322
2461
  const { definedNameId, definedName } = formulaReferenceMoveParam;
2323
2462
  if (definedNameId === void 0 || definedName === void 0) continue;
2324
2463
  const oldDefinedName = this._definedNamesService.getValueById(unitId, definedNameId);
@@ -2326,23 +2465,23 @@ let UpdateFormulaController = class UpdateFormulaController extends _univerjs_co
2326
2465
  if (oldDefinedName.name !== token) continue;
2327
2466
  sequenceNodes[i] = {
2328
2467
  ...node,
2329
- token: type === 13 ? definedName : _univerjs_engine_formula.ErrorType.REF
2468
+ token: type === 14 ? definedName : _univerjs_engine_formula.ErrorType.REF
2330
2469
  };
2331
2470
  shouldModify = true;
2332
2471
  refChangeIds.push(i);
2333
2472
  continue;
2334
- } else if ((type === 15 || type === 16 || type === 17) && (nodeType === _univerjs_engine_formula.sequenceNodeType.TABLE || nodeType === _univerjs_engine_formula.sequenceNodeType.FUNCTION)) {
2473
+ } else if ((type === 16 || type === 17 || type === 18) && (nodeType === _univerjs_engine_formula.sequenceNodeType.TABLE || nodeType === _univerjs_engine_formula.sequenceNodeType.FUNCTION)) {
2335
2474
  const { oldTableName, tableName, tableColumnNames } = formulaReferenceMoveParam;
2336
- if (oldTableName === void 0 || type === 15 && tableName === void 0) continue;
2475
+ if (oldTableName === void 0 || type === 16 && tableName === void 0) continue;
2337
2476
  const { tableName: tokenTableName, columnStruct = "" } = (0, _univerjs_engine_formula.splitTableStructuredRef)(token);
2338
2477
  if (tokenTableName !== oldTableName) continue;
2339
- if (type === 17 && !tableReferenceContainsColumn(columnStruct, tableColumnNames)) continue;
2478
+ if (type === 18 && !tableReferenceContainsColumn(columnStruct, tableColumnNames)) continue;
2340
2479
  sequenceNodes[i] = {
2341
2480
  ...node,
2342
- token: type === 15 ? `${tableName}${columnStruct}` : _univerjs_engine_formula.ErrorType.REF
2481
+ token: type === 16 ? `${tableName}${columnStruct}` : _univerjs_engine_formula.ErrorType.REF
2343
2482
  };
2344
2483
  const nextNode = sequenceNodes[i + 1];
2345
- if ((type === 16 || type === 17) && typeof nextNode === "string" && nextNode.startsWith("]")) sequenceNodes[i + 1] = nextNode.slice(1);
2484
+ if ((type === 17 || type === 18) && typeof nextNode === "string" && nextNode.startsWith("]")) sequenceNodes[i + 1] = nextNode.slice(1);
2346
2485
  shouldModify = true;
2347
2486
  refChangeIds.push(i);
2348
2487
  continue;
@@ -2370,12 +2509,12 @@ let UpdateFormulaController = class UpdateFormulaController extends _univerjs_co
2370
2509
  sheetName: newSheetName,
2371
2510
  unitId: sequenceUnitId
2372
2511
  });
2373
- } else if (type === 12) {
2512
+ } else if (type === 13) {
2374
2513
  const { unitId: userUnitId, sheetId: userSheetId, sheetName: newSheetName } = formulaReferenceMoveParam;
2375
2514
  if (sequenceSheetId == null || sequenceSheetId.length === 0) continue;
2376
2515
  if (userSheetId !== sequenceSheetId) continue;
2377
2516
  newRefString = _univerjs_engine_formula.ErrorType.REF;
2378
- } else if (type !== 13) newRefString = getNewRangeByMoveParam(sequenceUnitRangeWidthOffset, formulaReferenceMoveParam, unitId, sheetId, { inCrossSheetCutRange });
2517
+ } else if (type !== 14) newRefString = getNewRangeByMoveParam(sequenceUnitRangeWidthOffset, formulaReferenceMoveParam, unitId, sheetId, { inCrossSheetCutRange });
2379
2518
  if (newRefString != null) {
2380
2519
  sequenceNodes[i] = {
2381
2520
  ...node,
@@ -2515,7 +2654,7 @@ function tableReferenceContainsColumn(columnStruct, columnNames) {
2515
2654
  //#endregion
2516
2655
  //#region package.json
2517
2656
  var name = "@univerjs/sheets-formula";
2518
- var version = "1.0.0-alpha.3";
2657
+ var version = "1.0.0-alpha.5";
2519
2658
 
2520
2659
  //#endregion
2521
2660
  //#region src/common/plugin-name.ts
@@ -2863,16 +3002,11 @@ ActiveDirtyController = __decorate([
2863
3002
  //#endregion
2864
3003
  //#region src/controllers/array-formula-cell-interceptor.controller.ts
2865
3004
  let ArrayFormulaCellInterceptorController = class ArrayFormulaCellInterceptorController extends _univerjs_core.Disposable {
2866
- constructor(_commandService, _configService, _univerInstanceService, _sheetInterceptorService, _formulaDataModel, _lexerTreeBuilder, _functionService, _definedNamesService) {
3005
+ constructor(_commandService, _sheetInterceptorService, _formulaDataModel) {
2867
3006
  super();
2868
3007
  this._commandService = _commandService;
2869
- this._configService = _configService;
2870
- this._univerInstanceService = _univerInstanceService;
2871
3008
  this._sheetInterceptorService = _sheetInterceptorService;
2872
3009
  this._formulaDataModel = _formulaDataModel;
2873
- this._lexerTreeBuilder = _lexerTreeBuilder;
2874
- this._functionService = _functionService;
2875
- this._definedNamesService = _definedNamesService;
2876
3010
  this._initialize();
2877
3011
  }
2878
3012
  _initialize() {
@@ -2881,133 +3015,15 @@ let ArrayFormulaCellInterceptorController = class ArrayFormulaCellInterceptorCon
2881
3015
  }
2882
3016
  _commandExecutedListener() {
2883
3017
  this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
2884
- var _this$_configService$;
2885
- const isSSC = (_this$_configService$ = this._configService.getConfig("sheets-formula.base.config")) === null || _this$_configService$ === void 0 ? void 0 : _this$_configService$.writeArrayFormulaToSnapshot;
2886
3018
  if (command.id === _univerjs_engine_formula.SetArrayFormulaDataMutation.id) {
2887
3019
  const params = command.params;
2888
3020
  if (params == null) return;
2889
- const { arrayFormulaRange, arrayFormulaCellData, arrayFormulaEmbedded } = params;
3021
+ const { arrayFormulaRange, arrayFormulaCellData } = params;
2890
3022
  this._formulaDataModel.setArrayFormulaRange(arrayFormulaRange);
2891
3023
  this._formulaDataModel.setArrayFormulaCellData(arrayFormulaCellData);
2892
- if (isSSC) this._writeArrayFormulaToSnapshot(arrayFormulaRange, arrayFormulaCellData, arrayFormulaEmbedded);
2893
- } else if (command.id === _univerjs_engine_formula.SetFormulaCalculationResultMutation.id && isSSC) {
2894
- this._addPrefixToFunctionSnapshot();
2895
- this._addPrefixToDefinedNamesFunctionSnapshot();
2896
3024
  }
2897
3025
  }));
2898
3026
  }
2899
- _addPrefixToDefinedNamesFunctionSnapshot() {
2900
- const allDefinedNames = this._definedNamesService.getAllDefinedNames();
2901
- Object.entries(allDefinedNames).forEach(([unitId, definedNames]) => {
2902
- definedNames && Array.from(Object.entries(definedNames)).forEach(([_, definedName]) => {
2903
- const { formulaOrRefString } = definedName;
2904
- if (formulaOrRefString.substring(0, 1) === "=") {
2905
- const newFormula = this._lexerTreeBuilder.getNewFormulaWithPrefix(formulaOrRefString, this._functionService.hasExecutor.bind(this._functionService));
2906
- if (newFormula) this._commandService.executeCommand(_univerjs_engine_formula.SetDefinedNameMutation.id, {
2907
- ...definedName,
2908
- unitId,
2909
- formulaOrRefStringWithPrefix: newFormula
2910
- }, {
2911
- onlyLocal: true,
2912
- fromFormula: true
2913
- });
2914
- }
2915
- });
2916
- });
2917
- }
2918
- _addPrefixToFunctionSnapshot() {
2919
- const dataModel = this._formulaDataModel.getFormulaData();
2920
- const cacheMap = /* @__PURE__ */ new Map();
2921
- this._forEachSheetSnapshotData(dataModel, (unitId, subUnitId, formulaDataItem) => {
2922
- if (!formulaDataItem) return;
2923
- const cellValue = new _univerjs_core.ObjectMatrix();
2924
- new _univerjs_core.ObjectMatrix(formulaDataItem).forValue((row, col, value) => {
2925
- const functionText = value === null || value === void 0 ? void 0 : value.f;
2926
- if ((value === null || value === void 0 ? void 0 : value.x) != null || !functionText || functionText.length === 0) return;
2927
- if (cacheMap.has(functionText)) {
2928
- const cachedFormula = cacheMap.get(functionText);
2929
- cellValue.setValue(row, col, { xf: cachedFormula });
2930
- return;
2931
- }
2932
- const newFormula = this._lexerTreeBuilder.getNewFormulaWithPrefix(functionText, this._functionService.hasExecutor.bind(this._functionService));
2933
- if (newFormula) {
2934
- cellValue.setValue(row, col, { xf: newFormula });
2935
- cacheMap.set(functionText, newFormula);
2936
- }
2937
- });
2938
- this._commandService.executeCommand(_univerjs_sheets.SetRangeValuesMutation.id, {
2939
- unitId,
2940
- subUnitId,
2941
- cellValue: cellValue.getMatrix()
2942
- }, {
2943
- onlyLocal: true,
2944
- fromFormula: true
2945
- });
2946
- });
2947
- cacheMap.clear();
2948
- }
2949
- _forEachSheetSnapshotData(snapshotData, iterator) {
2950
- if (!snapshotData) return;
2951
- const workbooks = this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
2952
- for (const workbook of workbooks) {
2953
- const unitId = workbook.getUnitId();
2954
- const subUnitData = snapshotData[unitId];
2955
- if (!subUnitData) continue;
2956
- for (const worksheet of workbook.getSheets()) {
2957
- const subUnitId = worksheet.getSheetId();
2958
- const data = subUnitData[subUnitId];
2959
- if (data == null) continue;
2960
- iterator(unitId, subUnitId, data);
2961
- }
2962
- }
2963
- }
2964
- _writeArrayFormulaToSnapshot(arrayFormulaRange, arrayFormulaCellData, arrayFormulaEmbedded) {
2965
- this._forEachSheetSnapshotData(arrayFormulaRange, (unitId, subUnitId, rangeData) => {
2966
- const cellValue = new _univerjs_core.ObjectMatrix();
2967
- new _univerjs_core.ObjectMatrix(rangeData).forValue((row, col, value) => {
2968
- cellValue.setValue(row, col, { ref: (0, _univerjs_engine_formula.serializeRange)(value) });
2969
- });
2970
- this._commandService.executeCommand(_univerjs_sheets.SetRangeValuesMutation.id, {
2971
- unitId,
2972
- subUnitId,
2973
- cellValue: cellValue.getMatrix()
2974
- }, {
2975
- onlyLocal: true,
2976
- fromFormula: true
2977
- });
2978
- });
2979
- this._forEachSheetSnapshotData(arrayFormulaEmbedded, (unitId, subUnitId, rangeData) => {
2980
- const cellValue = new _univerjs_core.ObjectMatrix();
2981
- new _univerjs_core.ObjectMatrix(rangeData).forValue((row, col) => {
2982
- var _arrayFormulaRange$un;
2983
- if (arrayFormulaRange === null || arrayFormulaRange === void 0 || (_arrayFormulaRange$un = arrayFormulaRange[unitId]) === null || _arrayFormulaRange$un === void 0 || (_arrayFormulaRange$un = _arrayFormulaRange$un[subUnitId]) === null || _arrayFormulaRange$un === void 0 || (_arrayFormulaRange$un = _arrayFormulaRange$un[row]) === null || _arrayFormulaRange$un === void 0 ? void 0 : _arrayFormulaRange$un[col]) return;
2984
- cellValue.setValue(row, col, { ref: (0, _univerjs_engine_formula.serializeRange)({
2985
- startRow: row,
2986
- endRow: row,
2987
- startColumn: col,
2988
- endColumn: col
2989
- }) });
2990
- });
2991
- this._commandService.executeCommand(_univerjs_sheets.SetRangeValuesMutation.id, {
2992
- unitId,
2993
- subUnitId,
2994
- cellValue: cellValue.getMatrix()
2995
- }, {
2996
- onlyLocal: true,
2997
- fromFormula: true
2998
- });
2999
- });
3000
- this._forEachSheetSnapshotData(arrayFormulaCellData, (unitId, subUnitId, rowData) => {
3001
- this._commandService.executeCommand(_univerjs_sheets.SetRangeValuesMutation.id, {
3002
- unitId,
3003
- subUnitId,
3004
- cellValue: rowData
3005
- }, {
3006
- onlyLocal: true,
3007
- fromFormula: true
3008
- });
3009
- });
3010
- }
3011
3027
  _initInterceptorCellContent() {
3012
3028
  this.disposeWithMe(this._sheetInterceptorService.intercept(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, {
3013
3029
  priority: 100,
@@ -3038,13 +3054,8 @@ let ArrayFormulaCellInterceptorController = class ArrayFormulaCellInterceptorCon
3038
3054
  };
3039
3055
  ArrayFormulaCellInterceptorController = __decorate([
3040
3056
  __decorateParam(0, _univerjs_core.ICommandService),
3041
- __decorateParam(1, _univerjs_core.IConfigService),
3042
- __decorateParam(2, _univerjs_core.IUniverInstanceService),
3043
- __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
3044
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel)),
3045
- __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder)),
3046
- __decorateParam(6, _univerjs_engine_formula.IFunctionService),
3047
- __decorateParam(7, _univerjs_engine_formula.IDefinedNamesService)
3057
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
3058
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel))
3048
3059
  ], ArrayFormulaCellInterceptorController);
3049
3060
 
3050
3061
  //#endregion
@@ -16807,7 +16818,8 @@ let UniverSheetsFormulaPlugin = class UniverSheetsFormulaPlugin extends _univerj
16807
16818
  [DefinedNameController],
16808
16819
  [UpdateDefinedNameController],
16809
16820
  [SuperTableController],
16810
- [FormulaAutoFillController]
16821
+ [FormulaAutoFillController],
16822
+ [UnitQualifierRenameController]
16811
16823
  ];
16812
16824
  if (this._config.notExecuteFormula) {
16813
16825
  const rpcChannelService = j.get(_univerjs_rpc.IRPCChannelService);
@@ -16823,7 +16835,8 @@ let UniverSheetsFormulaPlugin = class UniverSheetsFormulaPlugin extends _univerj
16823
16835
  [ImageFormulaCellInterceptorController],
16824
16836
  [UpdateFormulaController],
16825
16837
  [UpdateDefinedNameController],
16826
- [FormulaAutoFillController]
16838
+ [FormulaAutoFillController],
16839
+ [UnitQualifierRenameController]
16827
16840
  ]);
16828
16841
  if ((0, _univerjs_core.isNodeEnv)()) (0, _univerjs_core.touchDependencies)(this._injector, [[TriggerCalculationController], [FormulaCalculationSessionController]]);
16829
16842
  }
@@ -16924,6 +16937,12 @@ Object.defineProperty(exports, 'TriggerCalculationController', {
16924
16937
  return TriggerCalculationController;
16925
16938
  }
16926
16939
  });
16940
+ Object.defineProperty(exports, 'UnitQualifierRenameController', {
16941
+ enumerable: true,
16942
+ get: function () {
16943
+ return UnitQualifierRenameController;
16944
+ }
16945
+ });
16927
16946
  Object.defineProperty(exports, 'UniverRemoteSheetsFormulaPlugin', {
16928
16947
  enumerable: true,
16929
16948
  get: function () {
@@ -16948,4 +16967,5 @@ Object.defineProperty(exports, 'UpdateFormulaController', {
16948
16967
  return UpdateFormulaController;
16949
16968
  }
16950
16969
  });
16951
- exports.calculateFormula = calculateFormula;
16970
+ exports.calculateFormula = calculateFormula;
16971
+ exports.collectUnitQualifierFormulaPatches = collectUnitQualifierFormulaPatches;