@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/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import { AbsoluteRefType, BooleanNumber, BuildTextUtils, CellValueType, CommandType, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, ICommandService, IConfigService, ILogService, IUniverInstanceService, ImageSourceType, Inject, Injector, InterceptorEffectEnum, LocaleService, ObjectMatrix, ObjectRelativeFromH, ObjectRelativeFromV, Plugin, PositionedObjectLayoutType, RANGE_TYPE, Rectangle, Tools, UniverInstanceType, WrapTextType, cellToRange, createDocumentModelWithStyle, createIdentifier, generateRandomId, getIntersectRange, isFormulaId, isFormulaString, isNodeEnv, isRealNum, merge, moveRangeByOffset, sequenceExecuteAsync, toDisposable, touchDependencies } from "@univerjs/core";
2
- import { AUTO_FILL_APPLY_TYPE, AUTO_FILL_DATA_TYPE, ClearSelectionFormatCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, EffectRefRangId, IAutoFillService, INTERCEPTOR_POINT, InsertColCommand, InsertColMutation, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, InsertRowCommand, InsertRowMutation, InsertSheetMutation, InterceptCellContentPriority, MoveColsCommand, MoveColsMutation, MoveRangeCommand, MoveRangeMutation, MoveRowsCommand, MoveRowsMutation, RefRangeService, RemoveColCommand, RemoveColMutation, RemoveDefinedNameCommand, RemoveRowCommand, RemoveRowMutation, RemoveSheetCommand, RemoveSheetMutation, ReorderRangeMutation, SCOPE_WORKBOOK_VALUE_DEFINED_NAME, SetBorderCommand, SetDefinedNameCommand, SetRangeCustomMetadataCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetRowHiddenMutation, SetRowVisibleMutation, SetSelectionsOperation, SetStyleCommand, SetWorksheetActiveOperation, SetWorksheetNameCommand, SheetInterceptorService, SheetsSelectionsService, UniverSheetsPlugin, alignToMergedCellsBorders, expandToContinuousRange, findFirstNonEmptyCell, getSeparateEffectedRangesOnCommand, getSheetCommandTarget, handleCommonDefaultRangeChangeWithEffectRefCommands, handleDefaultRangeChangeWithEffectRefCommands, handleDeleteRangeMoveLeft, handleDeleteRangeMoveUp, handleIRemoveCol, handleIRemoveRow, handleInsertCol, handleInsertRangeMoveDown, handleInsertRangeMoveRight, handleInsertRow, handleMoveCols, handleMoveRange, handleMoveRows, runRefRangeMutations } from "@univerjs/sheets";
3
- import { ALL_IMPLEMENTED_FUNCTIONS_SET, AstTreeBuilder, AsyncCustomFunction, CustomFunction, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, ErrorType, 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_WEB, FormulaCalculationTriggerService, FormulaDataModel, FormulaExecuteStageType, FormulaExecutedStateType, FunctionType, IActiveDirtyManagerService, IDefinedNamesService, IFormulaCurrentConfigService, IFunctionService, ISuperTableService, Interpreter, Lexer, LexerTreeBuilder, OtherFormulaMarkDirty, RegisterOtherFormulaService, RemoveDefinedNameMutation, RemoveSuperTableMutation, SetArrayFormulaDataMutation, SetDefinedNameMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDataMutation, SetFormulaStringBatchCalculationMutation, SetImageFormulaDataMutation, SetSuperTableMutation, SetTriggerFormulaCalculationStartMutation, UniverFormulaEnginePlugin, deserializeRangeWithSheetWithCache, generateExecuteAstNodeData, generateStringWithSequence, getObjectValue, initSheetFormulaData, isReferenceStrings, sequenceNodeType, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet, splitTableStructuredRef, stripErrorMargin } from "@univerjs/engine-formula";
1
+ import { AbsoluteRefType, BooleanNumber, BuildTextUtils, CellValueType, CommandType, DependentOn, Direction, Disposable, DisposableCollection, DrawingTypeEnum, ICommandService, IConfigService, ILogService, IUndoRedoService, IUniverInstanceService, ImageSourceType, Inject, Injector, InterceptorEffectEnum, LocaleService, ObjectMatrix, Plugin, PositionedObjectLayoutType, RANGE_TYPE, Rectangle, Tools, UniverInstanceType, WrapTextType, cellToRange, createDocumentModelWithStyle, createIdentifier, generateRandomId, getIntersectRange, isFormulaId, isFormulaString, isNodeEnv, isRealNum, merge, moveRangeByOffset, sequenceExecute, sequenceExecuteAsync, toDisposable, touchDependencies } from "@univerjs/core";
2
+ import { AUTO_FILL_APPLY_TYPE, AUTO_FILL_DATA_TYPE, ClearSelectionFormatCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, EffectRefRangId, IAutoFillService, INTERCEPTOR_POINT, InsertColCommand, InsertColMutation, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, InsertRowCommand, InsertRowMutation, InsertSheetMutation, InterceptCellContentPriority, MoveColsCommand, MoveColsMutation, MoveRangeCommand, MoveRangeMutation, MoveRowsCommand, MoveRowsMutation, RefRangeService, RemoveColCommand, RemoveColMutation, RemoveDefinedNameCommand, RemoveRowCommand, RemoveRowMutation, RemoveSheetCommand, RemoveSheetMutation, ReorderRangeMutation, SCOPE_WORKBOOK_VALUE_DEFINED_NAME, SetBorderCommand, SetDefinedNameCommand, SetRangeCustomMetadataCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetRowHiddenMutation, SetRowVisibleMutation, SetSelectionsOperation, SetStyleCommand, SetWorkbookNameCommand, SetWorksheetActiveOperation, SetWorksheetNameCommand, SheetInterceptorService, SheetsSelectionsService, UniverSheetsPlugin, alignToMergedCellsBorders, expandToContinuousRange, findFirstNonEmptyCell, getSeparateEffectedRangesOnCommand, getSheetCommandTarget, handleCommonDefaultRangeChangeWithEffectRefCommands, handleDefaultRangeChangeWithEffectRefCommands, handleDeleteRangeMoveLeft, handleDeleteRangeMoveUp, handleIRemoveCol, handleIRemoveRow, handleInsertCol, handleInsertRangeMoveDown, handleInsertRangeMoveRight, handleInsertRow, handleMoveCols, handleMoveRange, handleMoveRows, runRefRangeMutations } from "@univerjs/sheets";
3
+ import { ALL_IMPLEMENTED_FUNCTIONS_SET, AstTreeBuilder, AsyncCustomFunction, CustomFunction, ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, ErrorType, 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_WEB, FormulaDataModel, FormulaExecuteStageType, FormulaExecutedStateType, FunctionType, IActiveDirtyManagerService, IDefinedNamesService, IFormulaCurrentConfigService, IFunctionService, ISuperTableService, Interpreter, Lexer, LexerTreeBuilder, OtherFormulaMarkDirty, RegisterOtherFormulaService, RemoveDefinedNameMutation, RemoveSuperTableMutation, SetArrayFormulaDataMutation, SetDefinedNameMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDataMutation, SetFormulaStringBatchCalculationMutation, SetImageFormulaDataMutation, SetSuperTableMutation, SetTriggerFormulaCalculationStartMutation, UniverFormulaEnginePlugin, deserializeRangeWithSheetWithCache, generateExecuteAstNodeData, generateStringWithSequence, getObjectValue, initSheetFormulaData, isReferenceStrings, refactorFormulaUnitQualifier, sequenceNodeType, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet, splitTableStructuredRef, stripErrorMargin } from "@univerjs/engine-formula";
4
4
  import { BehaviorSubject, Subject, map } from "rxjs";
5
+ import { buildDocTransform } from "@univerjs/docs";
5
6
  import { IRPCChannelService, fromModule, toModule } from "@univerjs/rpc";
6
7
 
7
8
  //#region src/commands/commands/insert-function.command.ts
@@ -599,6 +600,7 @@ let ImageFormulaCellInterceptorController = class ImageFormulaCellInterceptorCon
599
600
  if (isErrorImage) return next(this._errorValueCell);
600
601
  const finalWidth = width || imageNaturalWidth;
601
602
  const finalHeight = height || imageNaturalHeight;
603
+ if (!finalWidth || !finalHeight) return next(this._errorValueCell);
602
604
  const docDataModel = createDocumentModelWithStyle("", {});
603
605
  const docDrawingParam = {
604
606
  unitId,
@@ -613,21 +615,7 @@ let ImageFormulaCellInterceptorController = class ImageFormulaCellInterceptorCon
613
615
  width: finalWidth,
614
616
  height: finalHeight
615
617
  },
616
- docTransform: {
617
- size: {
618
- width: finalWidth,
619
- height: finalHeight
620
- },
621
- positionH: {
622
- relativeFrom: ObjectRelativeFromH.PAGE,
623
- posOffset: 0
624
- },
625
- positionV: {
626
- relativeFrom: ObjectRelativeFromV.PARAGRAPH,
627
- posOffset: 0
628
- },
629
- angle: 0
630
- },
618
+ docTransform: buildDocTransform(finalWidth, finalHeight),
631
619
  behindDoc: BooleanNumber.FALSE,
632
620
  title: "",
633
621
  description: "",
@@ -741,7 +729,7 @@ let TriggerCalculationController = class TriggerCalculationController extends Di
741
729
  this._totalCalculationTaskCount = 0;
742
730
  this._emitProgress();
743
731
  }
744
- constructor(_commandService, _univerInstanceService, formulaCalculationTriggerService, _logService, _configService, _formulaDataModel, _localeService, _registerOtherFormulaService) {
732
+ constructor(_commandService, _univerInstanceService, _logService, _configService, _formulaDataModel, _localeService, _registerOtherFormulaService) {
745
733
  super();
746
734
  this._commandService = _commandService;
747
735
  this._univerInstanceService = _univerInstanceService;
@@ -879,14 +867,114 @@ let TriggerCalculationController = class TriggerCalculationController extends Di
879
867
  TriggerCalculationController = __decorate([
880
868
  __decorateParam(0, ICommandService),
881
869
  __decorateParam(1, IUniverInstanceService),
882
- __decorateParam(2, Inject(FormulaCalculationTriggerService)),
883
- __decorateParam(3, ILogService),
884
- __decorateParam(4, IConfigService),
885
- __decorateParam(5, Inject(FormulaDataModel)),
886
- __decorateParam(6, Inject(LocaleService)),
887
- __decorateParam(7, Inject(RegisterOtherFormulaService))
870
+ __decorateParam(2, ILogService),
871
+ __decorateParam(3, IConfigService),
872
+ __decorateParam(4, Inject(FormulaDataModel)),
873
+ __decorateParam(5, Inject(LocaleService)),
874
+ __decorateParam(6, Inject(RegisterOtherFormulaService))
888
875
  ], TriggerCalculationController);
889
876
 
877
+ //#endregion
878
+ //#region src/controllers/unit-qualifier-rename.controller.ts
879
+ function collectUnitQualifierFormulaPatches(workbook, oldName, newName) {
880
+ const unitId = workbook.getUnitId();
881
+ return workbook.getSheets().flatMap((sheet) => {
882
+ const updates = new ObjectMatrix();
883
+ sheet.getCellMatrix().forValue((row, column, cell) => {
884
+ if (!(cell === null || cell === void 0 ? void 0 : cell.f)) return;
885
+ const formula = refactorFormulaUnitQualifier(cell.f, oldName, newName);
886
+ if (formula !== cell.f) updates.setValue(row, column, { f: formula });
887
+ });
888
+ const cellValue = updates.getData();
889
+ return Object.keys(cellValue).length > 0 ? [{
890
+ unitId,
891
+ subUnitId: sheet.getSheetId(),
892
+ cellValue
893
+ }] : [];
894
+ });
895
+ }
896
+ let UnitQualifierRenameController = class UnitQualifierRenameController extends Disposable {
897
+ constructor(_commandService, _undoRedoService, _univerInstanceService, _definedNamesService) {
898
+ super();
899
+ this._commandService = _commandService;
900
+ this._undoRedoService = _undoRedoService;
901
+ this._univerInstanceService = _univerInstanceService;
902
+ this._definedNamesService = _definedNamesService;
903
+ _defineProperty(this, "_names", /* @__PURE__ */ new Map());
904
+ this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_BASE).forEach((unit) => this._watch(unit));
905
+ this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(UniverInstanceType.UNIVER_BASE).subscribe(({ unit }) => this._watch(unit)));
906
+ this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(UniverInstanceType.UNIVER_BASE).subscribe((unit) => this._names.delete(unit.getUnitId())));
907
+ }
908
+ _watch(unit) {
909
+ const unitId = unit.getUnitId();
910
+ this.disposeWithMe(unit.name$.subscribe((name) => {
911
+ const oldName = this._names.get(unitId);
912
+ this._names.set(unitId, name);
913
+ if (!oldName || oldName === name) return;
914
+ this._refactor(unitId, oldName, name);
915
+ }));
916
+ }
917
+ _refactor(renamedUnitId, oldName, newName) {
918
+ const redos = [];
919
+ const undos = [];
920
+ for (const workbook of this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_SHEET)) {
921
+ for (const patch of collectUnitQualifierFormulaPatches(workbook, oldName, newName)) {
922
+ const sheet = workbook.getSheetBySheetId(patch.subUnitId);
923
+ if (!sheet) continue;
924
+ const undoCellValue = new ObjectMatrix();
925
+ new ObjectMatrix(patch.cellValue).forValue((row, column) => {
926
+ var _sheet$getCellRaw;
927
+ undoCellValue.setValue(row, column, (_sheet$getCellRaw = sheet.getCellRaw(row, column)) !== null && _sheet$getCellRaw !== void 0 ? _sheet$getCellRaw : null);
928
+ });
929
+ redos.push({
930
+ id: SetRangeValuesMutation.id,
931
+ params: patch
932
+ });
933
+ undos.unshift({
934
+ id: SetRangeValuesMutation.id,
935
+ params: {
936
+ ...patch,
937
+ cellValue: undoCellValue.getData()
938
+ }
939
+ });
940
+ }
941
+ const definedNames = this._definedNamesService.getDefinedNameMap(workbook.getUnitId());
942
+ for (const item of Object.values(definedNames !== null && definedNames !== void 0 ? definedNames : {})) {
943
+ const formulaOrRefString = refactorFormulaUnitQualifier(item.formulaOrRefString, oldName, newName);
944
+ if (formulaOrRefString !== item.formulaOrRefString) {
945
+ redos.push({
946
+ id: SetDefinedNameMutation.id,
947
+ params: {
948
+ unitId: workbook.getUnitId(),
949
+ ...item,
950
+ formulaOrRefString
951
+ }
952
+ });
953
+ undos.unshift({
954
+ id: SetDefinedNameMutation.id,
955
+ params: {
956
+ unitId: workbook.getUnitId(),
957
+ ...item
958
+ }
959
+ });
960
+ }
961
+ }
962
+ }
963
+ if (!redos.length || !sequenceExecute(redos, this._commandService).result) return;
964
+ this._undoRedoService.pushUndoRedo({
965
+ unitID: renamedUnitId,
966
+ undoMutations: undos,
967
+ redoMutations: redos
968
+ });
969
+ }
970
+ };
971
+ UnitQualifierRenameController = __decorate([
972
+ __decorateParam(0, ICommandService),
973
+ __decorateParam(1, IUndoRedoService),
974
+ __decorateParam(2, IUniverInstanceService),
975
+ __decorateParam(3, IDefinedNamesService)
976
+ ], UnitQualifierRenameController);
977
+
890
978
  //#endregion
891
979
  //#region src/controllers/utils/offset-formula-data.ts
892
980
  function checkFormulaDataNull(formulaData, unitId, sheetId) {
@@ -915,11 +1003,12 @@ const formulaReferenceSheetList = [
915
1003
  13,
916
1004
  14,
917
1005
  15,
918
- 16
1006
+ 16,
1007
+ 17
919
1008
  ];
920
1009
  function getFormulaReferenceMoveUndoRedo(oldFormulaData, newFormulaData, formulaReferenceMoveParam) {
921
1010
  const { type } = formulaReferenceMoveParam;
922
- if (formulaReferenceSheetList.includes(type) || type === 17 && formulaReferenceMoveParam.range == null) return getFormulaReferenceSheet(oldFormulaData, newFormulaData);
1011
+ if (formulaReferenceSheetList.includes(type) || type === 18 && formulaReferenceMoveParam.range == null) return getFormulaReferenceSheet(oldFormulaData, newFormulaData);
923
1012
  else return getFormulaReferenceRange(oldFormulaData, newFormulaData, formulaReferenceMoveParam);
924
1013
  }
925
1014
  function getFormulaReferenceSheet(oldFormulaData, newFormulaData) {
@@ -1124,7 +1213,7 @@ function handleInsertDelete(oldCell, formulaReferenceMoveParam) {
1124
1213
  newCell = handleRefRemoveRow$1(range, oldCell, rangeFilteredRows);
1125
1214
  break;
1126
1215
  case 6:
1127
- case 17:
1216
+ case 18:
1128
1217
  newCell = handleRefRemoveCol$1(range, oldCell);
1129
1218
  break;
1130
1219
  case 7:
@@ -1724,6 +1813,9 @@ function getReferenceMoveParams(workbook, command) {
1724
1813
  case SetWorksheetNameCommand.id:
1725
1814
  result = handleRefSetWorksheetName(command, workbook);
1726
1815
  break;
1816
+ case SetWorkbookNameCommand.id:
1817
+ result = handleRefSetWorkbookName(command);
1818
+ break;
1727
1819
  case RemoveSheetCommand.id:
1728
1820
  result = handleRefRemoveWorksheet(command, workbook);
1729
1821
  break;
@@ -1946,13 +2038,23 @@ function handleRefSetWorksheetName(command, workbook) {
1946
2038
  sheetName: name
1947
2039
  };
1948
2040
  }
2041
+ function handleRefSetWorkbookName(command) {
2042
+ const { params } = command;
2043
+ if (!params) return null;
2044
+ return {
2045
+ type: 12,
2046
+ unitId: params.unitId,
2047
+ sheetId: "",
2048
+ unitName: params.name
2049
+ };
2050
+ }
1949
2051
  function handleRefRemoveWorksheet(command, workbook) {
1950
2052
  const { params } = command;
1951
2053
  if (!params) return null;
1952
2054
  const { unitId, subUnitId } = params;
1953
2055
  const { unitId: workbookId, sheetId } = getCurrentSheetInfo(workbook);
1954
2056
  return {
1955
- type: 12,
2057
+ type: 13,
1956
2058
  unitId: unitId || workbookId,
1957
2059
  sheetId: subUnitId || sheetId
1958
2060
  };
@@ -1963,7 +2065,7 @@ function handleRefSetDefinedName(command, workbook) {
1963
2065
  const { unitId, name, id } = params;
1964
2066
  const { sheetId } = getCurrentSheetInfo(workbook);
1965
2067
  return {
1966
- type: 13,
2068
+ type: 14,
1967
2069
  unitId,
1968
2070
  sheetId,
1969
2071
  definedName: name,
@@ -1976,7 +2078,7 @@ function handleRefRemoveDefinedName(command, workbook) {
1976
2078
  const { unitId, name, id } = params;
1977
2079
  const { sheetId } = getCurrentSheetInfo(workbook);
1978
2080
  return {
1979
- type: 14,
2081
+ type: 15,
1980
2082
  unitId,
1981
2083
  sheetId,
1982
2084
  definedName: name,
@@ -1989,7 +2091,7 @@ function handleRefSetSheetTableName(command, workbook) {
1989
2091
  const { unitId, name: tableName, oldTableName } = params;
1990
2092
  const { sheetId } = getCurrentSheetInfo(workbook);
1991
2093
  return {
1992
- type: 15,
2094
+ type: 16,
1993
2095
  unitId,
1994
2096
  sheetId,
1995
2097
  tableName,
@@ -2002,7 +2104,7 @@ function handleRefRemoveSheetTableName(command, workbook) {
2002
2104
  const { unitId, tableName } = params;
2003
2105
  const { sheetId } = getCurrentSheetInfo(workbook);
2004
2106
  return {
2005
- type: 16,
2107
+ type: 17,
2006
2108
  unitId,
2007
2109
  sheetId,
2008
2110
  oldTableName: tableName
@@ -2015,7 +2117,7 @@ function handleRefRemoveSheetTableColumn(command, workbook) {
2015
2117
  const { unitId, subUnitId, range, tableName, removedColumnNames } = params;
2016
2118
  const { sheetId } = getCurrentSheetInfo(workbook);
2017
2119
  return {
2018
- type: 17,
2120
+ type: 18,
2019
2121
  unitId,
2020
2122
  sheetId: subUnitId || sheetId,
2021
2123
  range,
@@ -2054,6 +2156,10 @@ let UpdateDefinedNameController = class UpdateDefinedNameController extends Disp
2054
2156
  redos: [],
2055
2157
  undos: []
2056
2158
  };
2159
+ if (result.type === 12) {
2160
+ var _this$_univerInstance;
2161
+ result.oldUnitName = (_this$_univerInstance = this._univerInstanceService.getUnit(result.unitId, UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getName();
2162
+ }
2057
2163
  return this._getUpdateDefinedNameMutations(workbook, result);
2058
2164
  } }));
2059
2165
  }
@@ -2068,6 +2174,28 @@ let UpdateDefinedNameController = class UpdateDefinedNameController extends Disp
2068
2174
  const undoMutations = [];
2069
2175
  Object.values(definedNames).forEach((item) => {
2070
2176
  const { formulaOrRefString } = item;
2177
+ if (type === 12) {
2178
+ const { oldUnitName, unitName } = moveParams;
2179
+ if (!oldUnitName || !unitName) return true;
2180
+ const nextFormula = refactorFormulaUnitQualifier(formulaOrRefString, oldUnitName, unitName);
2181
+ if (nextFormula === formulaOrRefString) return true;
2182
+ redoMutations.push({
2183
+ id: SetDefinedNameMutation.id,
2184
+ params: {
2185
+ unitId,
2186
+ ...item,
2187
+ formulaOrRefString: nextFormula
2188
+ }
2189
+ });
2190
+ undoMutations.push({
2191
+ id: SetDefinedNameMutation.id,
2192
+ params: {
2193
+ unitId,
2194
+ ...item
2195
+ }
2196
+ });
2197
+ return true;
2198
+ }
2071
2199
  const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaOrRefString);
2072
2200
  if (sequenceNodes == null) return true;
2073
2201
  let shouldModify = false;
@@ -2088,7 +2216,7 @@ let UpdateDefinedNameController = class UpdateDefinedNameController extends Disp
2088
2216
  refOffsetY: 0
2089
2217
  };
2090
2218
  let newRefString = null;
2091
- if (type === 12) newRefString = this._removeSheet(item, unitId, sheetId);
2219
+ if (type === 13) newRefString = this._removeSheet(item, unitId, sheetId);
2092
2220
  else if (type === 11) {
2093
2221
  const { sheetId: userSheetId, sheetName: newSheetName } = moveParams;
2094
2222
  if (newSheetName == null) continue;
@@ -2273,7 +2401,11 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
2273
2401
  };
2274
2402
  const result = getReferenceMoveParams(workbook, command);
2275
2403
  if (result) {
2276
- const { unitSheetNameMap } = this._formulaDataModel.getCalculateData();
2404
+ const { unitNameMap, unitSheetNameMap } = this._formulaDataModel.getCalculateData();
2405
+ if (result.type === 12) {
2406
+ var _unitNameMap$result$u;
2407
+ 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;
2408
+ }
2277
2409
  const oldFormulaData = this._formulaDataModel.getFormulaData();
2278
2410
  const { newFormulaData } = this._getFormulaReferenceMoveInfo(oldFormulaData, unitSheetNameMap, result);
2279
2411
  const { undos, redos } = getFormulaReferenceMoveUndoRedo(oldFormulaData, newFormulaData, result);
@@ -2306,6 +2438,13 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
2306
2438
  matrixData.forValue((row, column, formulaDataItem) => {
2307
2439
  if (!formulaDataItem) return true;
2308
2440
  const { f: formulaString, x, y, si } = formulaDataItem;
2441
+ if (type === 12) {
2442
+ const { oldUnitName, unitName } = formulaReferenceMoveParam;
2443
+ if (!oldUnitName || !unitName) return true;
2444
+ const nextFormula = refactorFormulaUnitQualifier(formulaString, oldUnitName, unitName);
2445
+ if (nextFormula !== formulaString) newFormulaDataItem.setValue(row, column, { f: nextFormula });
2446
+ return true;
2447
+ }
2309
2448
  const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);
2310
2449
  if (sequenceNodes == null) return true;
2311
2450
  let shouldModify = false;
@@ -2317,7 +2456,7 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
2317
2456
  const node = sequenceNodes[i];
2318
2457
  if (typeof node === "string") continue;
2319
2458
  const { token, nodeType } = node;
2320
- if ((type === 13 || type === 14) && (nodeType === sequenceNodeType.DEFINED_NAME || nodeType === sequenceNodeType.FUNCTION)) {
2459
+ if ((type === 14 || type === 15) && (nodeType === sequenceNodeType.DEFINED_NAME || nodeType === sequenceNodeType.FUNCTION)) {
2321
2460
  const { definedNameId, definedName } = formulaReferenceMoveParam;
2322
2461
  if (definedNameId === void 0 || definedName === void 0) continue;
2323
2462
  const oldDefinedName = this._definedNamesService.getValueById(unitId, definedNameId);
@@ -2325,23 +2464,23 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
2325
2464
  if (oldDefinedName.name !== token) continue;
2326
2465
  sequenceNodes[i] = {
2327
2466
  ...node,
2328
- token: type === 13 ? definedName : ErrorType.REF
2467
+ token: type === 14 ? definedName : ErrorType.REF
2329
2468
  };
2330
2469
  shouldModify = true;
2331
2470
  refChangeIds.push(i);
2332
2471
  continue;
2333
- } else if ((type === 15 || type === 16 || type === 17) && (nodeType === sequenceNodeType.TABLE || nodeType === sequenceNodeType.FUNCTION)) {
2472
+ } else if ((type === 16 || type === 17 || type === 18) && (nodeType === sequenceNodeType.TABLE || nodeType === sequenceNodeType.FUNCTION)) {
2334
2473
  const { oldTableName, tableName, tableColumnNames } = formulaReferenceMoveParam;
2335
- if (oldTableName === void 0 || type === 15 && tableName === void 0) continue;
2474
+ if (oldTableName === void 0 || type === 16 && tableName === void 0) continue;
2336
2475
  const { tableName: tokenTableName, columnStruct = "" } = splitTableStructuredRef(token);
2337
2476
  if (tokenTableName !== oldTableName) continue;
2338
- if (type === 17 && !tableReferenceContainsColumn(columnStruct, tableColumnNames)) continue;
2477
+ if (type === 18 && !tableReferenceContainsColumn(columnStruct, tableColumnNames)) continue;
2339
2478
  sequenceNodes[i] = {
2340
2479
  ...node,
2341
- token: type === 15 ? `${tableName}${columnStruct}` : ErrorType.REF
2480
+ token: type === 16 ? `${tableName}${columnStruct}` : ErrorType.REF
2342
2481
  };
2343
2482
  const nextNode = sequenceNodes[i + 1];
2344
- if ((type === 16 || type === 17) && typeof nextNode === "string" && nextNode.startsWith("]")) sequenceNodes[i + 1] = nextNode.slice(1);
2483
+ if ((type === 17 || type === 18) && typeof nextNode === "string" && nextNode.startsWith("]")) sequenceNodes[i + 1] = nextNode.slice(1);
2345
2484
  shouldModify = true;
2346
2485
  refChangeIds.push(i);
2347
2486
  continue;
@@ -2369,12 +2508,12 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
2369
2508
  sheetName: newSheetName,
2370
2509
  unitId: sequenceUnitId
2371
2510
  });
2372
- } else if (type === 12) {
2511
+ } else if (type === 13) {
2373
2512
  const { unitId: userUnitId, sheetId: userSheetId, sheetName: newSheetName } = formulaReferenceMoveParam;
2374
2513
  if (sequenceSheetId == null || sequenceSheetId.length === 0) continue;
2375
2514
  if (userSheetId !== sequenceSheetId) continue;
2376
2515
  newRefString = ErrorType.REF;
2377
- } else if (type !== 13) newRefString = getNewRangeByMoveParam(sequenceUnitRangeWidthOffset, formulaReferenceMoveParam, unitId, sheetId, { inCrossSheetCutRange });
2516
+ } else if (type !== 14) newRefString = getNewRangeByMoveParam(sequenceUnitRangeWidthOffset, formulaReferenceMoveParam, unitId, sheetId, { inCrossSheetCutRange });
2378
2517
  if (newRefString != null) {
2379
2518
  sequenceNodes[i] = {
2380
2519
  ...node,
@@ -2514,7 +2653,7 @@ function tableReferenceContainsColumn(columnStruct, columnNames) {
2514
2653
  //#endregion
2515
2654
  //#region package.json
2516
2655
  var name = "@univerjs/sheets-formula";
2517
- var version = "1.0.0-alpha.3";
2656
+ var version = "1.0.0-alpha.5";
2518
2657
 
2519
2658
  //#endregion
2520
2659
  //#region src/common/plugin-name.ts
@@ -2862,16 +3001,11 @@ ActiveDirtyController = __decorate([
2862
3001
  //#endregion
2863
3002
  //#region src/controllers/array-formula-cell-interceptor.controller.ts
2864
3003
  let ArrayFormulaCellInterceptorController = class ArrayFormulaCellInterceptorController extends Disposable {
2865
- constructor(_commandService, _configService, _univerInstanceService, _sheetInterceptorService, _formulaDataModel, _lexerTreeBuilder, _functionService, _definedNamesService) {
3004
+ constructor(_commandService, _sheetInterceptorService, _formulaDataModel) {
2866
3005
  super();
2867
3006
  this._commandService = _commandService;
2868
- this._configService = _configService;
2869
- this._univerInstanceService = _univerInstanceService;
2870
3007
  this._sheetInterceptorService = _sheetInterceptorService;
2871
3008
  this._formulaDataModel = _formulaDataModel;
2872
- this._lexerTreeBuilder = _lexerTreeBuilder;
2873
- this._functionService = _functionService;
2874
- this._definedNamesService = _definedNamesService;
2875
3009
  this._initialize();
2876
3010
  }
2877
3011
  _initialize() {
@@ -2880,133 +3014,15 @@ let ArrayFormulaCellInterceptorController = class ArrayFormulaCellInterceptorCon
2880
3014
  }
2881
3015
  _commandExecutedListener() {
2882
3016
  this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
2883
- var _this$_configService$;
2884
- const isSSC = (_this$_configService$ = this._configService.getConfig("sheets-formula.base.config")) === null || _this$_configService$ === void 0 ? void 0 : _this$_configService$.writeArrayFormulaToSnapshot;
2885
3017
  if (command.id === SetArrayFormulaDataMutation.id) {
2886
3018
  const params = command.params;
2887
3019
  if (params == null) return;
2888
- const { arrayFormulaRange, arrayFormulaCellData, arrayFormulaEmbedded } = params;
3020
+ const { arrayFormulaRange, arrayFormulaCellData } = params;
2889
3021
  this._formulaDataModel.setArrayFormulaRange(arrayFormulaRange);
2890
3022
  this._formulaDataModel.setArrayFormulaCellData(arrayFormulaCellData);
2891
- if (isSSC) this._writeArrayFormulaToSnapshot(arrayFormulaRange, arrayFormulaCellData, arrayFormulaEmbedded);
2892
- } else if (command.id === SetFormulaCalculationResultMutation.id && isSSC) {
2893
- this._addPrefixToFunctionSnapshot();
2894
- this._addPrefixToDefinedNamesFunctionSnapshot();
2895
3023
  }
2896
3024
  }));
2897
3025
  }
2898
- _addPrefixToDefinedNamesFunctionSnapshot() {
2899
- const allDefinedNames = this._definedNamesService.getAllDefinedNames();
2900
- Object.entries(allDefinedNames).forEach(([unitId, definedNames]) => {
2901
- definedNames && Array.from(Object.entries(definedNames)).forEach(([_, definedName]) => {
2902
- const { formulaOrRefString } = definedName;
2903
- if (formulaOrRefString.substring(0, 1) === "=") {
2904
- const newFormula = this._lexerTreeBuilder.getNewFormulaWithPrefix(formulaOrRefString, this._functionService.hasExecutor.bind(this._functionService));
2905
- if (newFormula) this._commandService.executeCommand(SetDefinedNameMutation.id, {
2906
- ...definedName,
2907
- unitId,
2908
- formulaOrRefStringWithPrefix: newFormula
2909
- }, {
2910
- onlyLocal: true,
2911
- fromFormula: true
2912
- });
2913
- }
2914
- });
2915
- });
2916
- }
2917
- _addPrefixToFunctionSnapshot() {
2918
- const dataModel = this._formulaDataModel.getFormulaData();
2919
- const cacheMap = /* @__PURE__ */ new Map();
2920
- this._forEachSheetSnapshotData(dataModel, (unitId, subUnitId, formulaDataItem) => {
2921
- if (!formulaDataItem) return;
2922
- const cellValue = new ObjectMatrix();
2923
- new ObjectMatrix(formulaDataItem).forValue((row, col, value) => {
2924
- const functionText = value === null || value === void 0 ? void 0 : value.f;
2925
- if ((value === null || value === void 0 ? void 0 : value.x) != null || !functionText || functionText.length === 0) return;
2926
- if (cacheMap.has(functionText)) {
2927
- const cachedFormula = cacheMap.get(functionText);
2928
- cellValue.setValue(row, col, { xf: cachedFormula });
2929
- return;
2930
- }
2931
- const newFormula = this._lexerTreeBuilder.getNewFormulaWithPrefix(functionText, this._functionService.hasExecutor.bind(this._functionService));
2932
- if (newFormula) {
2933
- cellValue.setValue(row, col, { xf: newFormula });
2934
- cacheMap.set(functionText, newFormula);
2935
- }
2936
- });
2937
- this._commandService.executeCommand(SetRangeValuesMutation.id, {
2938
- unitId,
2939
- subUnitId,
2940
- cellValue: cellValue.getMatrix()
2941
- }, {
2942
- onlyLocal: true,
2943
- fromFormula: true
2944
- });
2945
- });
2946
- cacheMap.clear();
2947
- }
2948
- _forEachSheetSnapshotData(snapshotData, iterator) {
2949
- if (!snapshotData) return;
2950
- const workbooks = this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_SHEET);
2951
- for (const workbook of workbooks) {
2952
- const unitId = workbook.getUnitId();
2953
- const subUnitData = snapshotData[unitId];
2954
- if (!subUnitData) continue;
2955
- for (const worksheet of workbook.getSheets()) {
2956
- const subUnitId = worksheet.getSheetId();
2957
- const data = subUnitData[subUnitId];
2958
- if (data == null) continue;
2959
- iterator(unitId, subUnitId, data);
2960
- }
2961
- }
2962
- }
2963
- _writeArrayFormulaToSnapshot(arrayFormulaRange, arrayFormulaCellData, arrayFormulaEmbedded) {
2964
- this._forEachSheetSnapshotData(arrayFormulaRange, (unitId, subUnitId, rangeData) => {
2965
- const cellValue = new ObjectMatrix();
2966
- new ObjectMatrix(rangeData).forValue((row, col, value) => {
2967
- cellValue.setValue(row, col, { ref: serializeRange(value) });
2968
- });
2969
- this._commandService.executeCommand(SetRangeValuesMutation.id, {
2970
- unitId,
2971
- subUnitId,
2972
- cellValue: cellValue.getMatrix()
2973
- }, {
2974
- onlyLocal: true,
2975
- fromFormula: true
2976
- });
2977
- });
2978
- this._forEachSheetSnapshotData(arrayFormulaEmbedded, (unitId, subUnitId, rangeData) => {
2979
- const cellValue = new ObjectMatrix();
2980
- new ObjectMatrix(rangeData).forValue((row, col) => {
2981
- var _arrayFormulaRange$un;
2982
- 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;
2983
- cellValue.setValue(row, col, { ref: serializeRange({
2984
- startRow: row,
2985
- endRow: row,
2986
- startColumn: col,
2987
- endColumn: col
2988
- }) });
2989
- });
2990
- this._commandService.executeCommand(SetRangeValuesMutation.id, {
2991
- unitId,
2992
- subUnitId,
2993
- cellValue: cellValue.getMatrix()
2994
- }, {
2995
- onlyLocal: true,
2996
- fromFormula: true
2997
- });
2998
- });
2999
- this._forEachSheetSnapshotData(arrayFormulaCellData, (unitId, subUnitId, rowData) => {
3000
- this._commandService.executeCommand(SetRangeValuesMutation.id, {
3001
- unitId,
3002
- subUnitId,
3003
- cellValue: rowData
3004
- }, {
3005
- onlyLocal: true,
3006
- fromFormula: true
3007
- });
3008
- });
3009
- }
3010
3026
  _initInterceptorCellContent() {
3011
3027
  this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
3012
3028
  priority: 100,
@@ -3037,13 +3053,8 @@ let ArrayFormulaCellInterceptorController = class ArrayFormulaCellInterceptorCon
3037
3053
  };
3038
3054
  ArrayFormulaCellInterceptorController = __decorate([
3039
3055
  __decorateParam(0, ICommandService),
3040
- __decorateParam(1, IConfigService),
3041
- __decorateParam(2, IUniverInstanceService),
3042
- __decorateParam(3, Inject(SheetInterceptorService)),
3043
- __decorateParam(4, Inject(FormulaDataModel)),
3044
- __decorateParam(5, Inject(LexerTreeBuilder)),
3045
- __decorateParam(6, IFunctionService),
3046
- __decorateParam(7, IDefinedNamesService)
3056
+ __decorateParam(1, Inject(SheetInterceptorService)),
3057
+ __decorateParam(2, Inject(FormulaDataModel))
3047
3058
  ], ArrayFormulaCellInterceptorController);
3048
3059
 
3049
3060
  //#endregion
@@ -16806,7 +16817,8 @@ let UniverSheetsFormulaPlugin = class UniverSheetsFormulaPlugin extends Plugin {
16806
16817
  [DefinedNameController],
16807
16818
  [UpdateDefinedNameController],
16808
16819
  [SuperTableController],
16809
- [FormulaAutoFillController]
16820
+ [FormulaAutoFillController],
16821
+ [UnitQualifierRenameController]
16810
16822
  ];
16811
16823
  if (this._config.notExecuteFormula) {
16812
16824
  const rpcChannelService = j.get(IRPCChannelService);
@@ -16822,7 +16834,8 @@ let UniverSheetsFormulaPlugin = class UniverSheetsFormulaPlugin extends Plugin {
16822
16834
  [ImageFormulaCellInterceptorController],
16823
16835
  [UpdateFormulaController],
16824
16836
  [UpdateDefinedNameController],
16825
- [FormulaAutoFillController]
16837
+ [FormulaAutoFillController],
16838
+ [UnitQualifierRenameController]
16826
16839
  ]);
16827
16840
  if (isNodeEnv()) touchDependencies(this._injector, [[TriggerCalculationController], [FormulaCalculationSessionController]]);
16828
16841
  }
@@ -16867,4 +16880,4 @@ function calculateFormula(inject, formulaString, unitId, sheetData) {
16867
16880
  }
16868
16881
 
16869
16882
  //#endregion
16870
- export { CalculationMode, DescriptionService, FormulaAutoFillController, FormulaCalculationSessionController, FormulaCalculationSessionService, FormulaRefRangeService, IDescriptionService, IRegisterFunctionService, IRemoteRegisterFunctionService, ImageFormulaCellInterceptorController, InsertFunctionCommand, PLUGIN_CONFIG_KEY_BASE, QuickSumCommand, RegisterFunctionService, RemoteRegisterFunctionService, TriggerCalculationController, UniverRemoteSheetsFormulaPlugin, UniverSheetsFormulaPlugin, UpdateDefinedNameController, UpdateFormulaController, calculateFormula };
16883
+ export { CalculationMode, DescriptionService, FormulaAutoFillController, FormulaCalculationSessionController, FormulaCalculationSessionService, FormulaRefRangeService, IDescriptionService, IRegisterFunctionService, IRemoteRegisterFunctionService, ImageFormulaCellInterceptorController, InsertFunctionCommand, PLUGIN_CONFIG_KEY_BASE, QuickSumCommand, RegisterFunctionService, RemoteRegisterFunctionService, TriggerCalculationController, UnitQualifierRenameController, UniverRemoteSheetsFormulaPlugin, UniverSheetsFormulaPlugin, UpdateDefinedNameController, UpdateFormulaController, calculateFormula, collectUnitQualifierFormulaPatches };
@@ -42,10 +42,6 @@ export interface IUniverSheetsFormulaBaseConfig {
42
42
  * Define the calculation mode during initialization, default is `WHEN_EMPTY`
43
43
  */
44
44
  initialFormulaComputing?: CalculationMode;
45
- /**
46
- * If true, the plugin will write array formula results to the snapshot. Normally you should not set this value.
47
- */
48
- writeArrayFormulaToSnapshot?: boolean;
49
45
  }
50
46
  export declare const defaultPluginBaseConfig: IUniverSheetsFormulaBaseConfig;
51
47
  /**
@@ -13,24 +13,15 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Disposable, ICommandService, IConfigService, IUniverInstanceService } from '@univerjs/core';
17
- import { FormulaDataModel, IDefinedNamesService, IFunctionService, LexerTreeBuilder } from '@univerjs/engine-formula';
16
+ import { Disposable, ICommandService } from '@univerjs/core';
17
+ import { FormulaDataModel } from '@univerjs/engine-formula';
18
18
  import { SheetInterceptorService } from '@univerjs/sheets';
19
19
  export declare class ArrayFormulaCellInterceptorController extends Disposable {
20
20
  private readonly _commandService;
21
- private readonly _configService;
22
- private readonly _univerInstanceService;
23
21
  private _sheetInterceptorService;
24
22
  private readonly _formulaDataModel;
25
- private readonly _lexerTreeBuilder;
26
- private readonly _functionService;
27
- private readonly _definedNamesService;
28
- constructor(_commandService: ICommandService, _configService: IConfigService, _univerInstanceService: IUniverInstanceService, _sheetInterceptorService: SheetInterceptorService, _formulaDataModel: FormulaDataModel, _lexerTreeBuilder: LexerTreeBuilder, _functionService: IFunctionService, _definedNamesService: IDefinedNamesService);
23
+ constructor(_commandService: ICommandService, _sheetInterceptorService: SheetInterceptorService, _formulaDataModel: FormulaDataModel);
29
24
  private _initialize;
30
25
  private _commandExecutedListener;
31
- private _addPrefixToDefinedNamesFunctionSnapshot;
32
- private _addPrefixToFunctionSnapshot;
33
- private _forEachSheetSnapshotData;
34
- private _writeArrayFormulaToSnapshot;
35
26
  private _initInterceptorCellContent;
36
27
  }
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { Disposable, ICommandService, IConfigService, ILogService, IUniverInstanceService, LocaleService } from '@univerjs/core';
17
- import { FormulaCalculationTriggerService, FormulaDataModel, RegisterOtherFormulaService } from '@univerjs/engine-formula';
17
+ import { FormulaDataModel, RegisterOtherFormulaService } from '@univerjs/engine-formula';
18
18
  /**
19
19
  * This interface is for the progress bar to display the calculation progress.
20
20
  */
@@ -45,7 +45,7 @@ export declare class TriggerCalculationController extends Disposable {
45
45
  private _calculateProgress;
46
46
  private _completeProgress;
47
47
  clearProgress(): void;
48
- constructor(_commandService: ICommandService, _univerInstanceService: IUniverInstanceService, formulaCalculationTriggerService: FormulaCalculationTriggerService, _logService: ILogService, _configService: IConfigService, _formulaDataModel: FormulaDataModel, _localeService: LocaleService, _registerOtherFormulaService: RegisterOtherFormulaService);
48
+ constructor(_commandService: ICommandService, _univerInstanceService: IUniverInstanceService, _logService: ILogService, _configService: IConfigService, _formulaDataModel: FormulaDataModel, _localeService: LocaleService, _registerOtherFormulaService: RegisterOtherFormulaService);
49
49
  dispose(): void;
50
50
  private _getCalculationMode;
51
51
  private _commandExecutedListener;