@univerjs/sheets-formula 1.3.0 → 1.4.0

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.
Files changed (76) hide show
  1. package/lib/cjs/facade.js +4 -9
  2. package/lib/cjs/index.js +328 -450
  3. package/lib/cjs/locale/ar-SA.js +1 -2
  4. package/lib/cjs/locale/ca-ES.js +1 -2
  5. package/lib/cjs/locale/de-DE.js +1 -2
  6. package/lib/cjs/locale/en-US.js +1 -2
  7. package/lib/cjs/locale/es-ES.js +1 -2
  8. package/lib/cjs/locale/fa-IR.js +1 -2
  9. package/lib/cjs/locale/fr-FR.js +1 -2
  10. package/lib/cjs/locale/id-ID.js +1 -2
  11. package/lib/cjs/locale/it-IT.js +1 -2
  12. package/lib/cjs/locale/ja-JP.js +1 -2
  13. package/lib/cjs/locale/ko-KR.js +1 -2
  14. package/lib/cjs/locale/pl-PL.js +1 -2
  15. package/lib/cjs/locale/pt-BR.js +1 -2
  16. package/lib/cjs/locale/ru-RU.js +1 -2
  17. package/lib/cjs/locale/sk-SK.js +1 -2
  18. package/lib/cjs/locale/vi-VN.js +1 -2
  19. package/lib/cjs/locale/zh-CN.js +1 -2
  20. package/lib/cjs/locale/zh-HK.js +1 -2
  21. package/lib/cjs/locale/zh-TW.js +1 -2
  22. package/lib/cjs/worker-Ds9TzMsD.js +248 -0
  23. package/lib/cjs/worker.js +9 -0
  24. package/lib/es/facade.js +4 -8
  25. package/lib/es/index.js +243 -365
  26. package/lib/es/locale/ar-SA.js +1 -2
  27. package/lib/es/locale/ca-ES.js +1 -2
  28. package/lib/es/locale/de-DE.js +1 -2
  29. package/lib/es/locale/en-US.js +1 -2
  30. package/lib/es/locale/es-ES.js +1 -2
  31. package/lib/es/locale/fa-IR.js +1 -2
  32. package/lib/es/locale/fr-FR.js +1 -2
  33. package/lib/es/locale/id-ID.js +1 -2
  34. package/lib/es/locale/it-IT.js +1 -2
  35. package/lib/es/locale/ja-JP.js +1 -2
  36. package/lib/es/locale/ko-KR.js +1 -2
  37. package/lib/es/locale/pl-PL.js +1 -2
  38. package/lib/es/locale/pt-BR.js +1 -2
  39. package/lib/es/locale/ru-RU.js +1 -2
  40. package/lib/es/locale/sk-SK.js +1 -2
  41. package/lib/es/locale/vi-VN.js +1 -2
  42. package/lib/es/locale/zh-CN.js +1 -2
  43. package/lib/es/locale/zh-HK.js +1 -2
  44. package/lib/es/locale/zh-TW.js +1 -2
  45. package/lib/es/worker-m5XIUFq5.js +177 -0
  46. package/lib/es/worker.js +3 -0
  47. package/lib/facade.js +4 -8
  48. package/lib/index.js +243 -365
  49. package/lib/locale/ar-SA.js +1 -2
  50. package/lib/locale/ca-ES.js +1 -2
  51. package/lib/locale/de-DE.js +1 -2
  52. package/lib/locale/en-US.js +1 -2
  53. package/lib/locale/es-ES.js +1 -2
  54. package/lib/locale/fa-IR.js +1 -2
  55. package/lib/locale/fr-FR.js +1 -2
  56. package/lib/locale/id-ID.js +1 -2
  57. package/lib/locale/it-IT.js +1 -2
  58. package/lib/locale/ja-JP.js +1 -2
  59. package/lib/locale/ko-KR.js +1 -2
  60. package/lib/locale/pl-PL.js +1 -2
  61. package/lib/locale/pt-BR.js +1 -2
  62. package/lib/locale/ru-RU.js +1 -2
  63. package/lib/locale/sk-SK.js +1 -2
  64. package/lib/locale/vi-VN.js +1 -2
  65. package/lib/locale/zh-CN.js +1 -2
  66. package/lib/locale/zh-HK.js +1 -2
  67. package/lib/locale/zh-TW.js +1 -2
  68. package/lib/types/controllers/update-formula.controller.d.ts +4 -0
  69. package/lib/types/index.d.ts +4 -1
  70. package/lib/types/plugin.d.ts +1 -12
  71. package/lib/types/services/remote/remote-register-function.service.d.ts +1 -1
  72. package/lib/types/worker.d.ts +28 -0
  73. package/lib/umd/index.js +1 -1
  74. package/lib/worker-m5XIUFq5.js +177 -0
  75. package/lib/worker.js +3 -0
  76. package/package.json +17 -12
package/lib/es/index.js CHANGED
@@ -1,11 +1,12 @@
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, Range, Rectangle, Tools, UniverInstanceType, WrapTextType, cellToRange, createDocumentModelWithStyle, createIdentifier, generateRandomId, getIntersectRange, isFormulaId, isFormulaString, isNodeEnv, isRealNum, merge, moveRangeByOffset, sequenceExecute, 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, ReorderRangeCommand, ReorderRangeMutation, SCOPE_WORKBOOK_VALUE_DEFINED_NAME, SetBorderCommand, SetDefinedNameCommand, SetRangeCustomMetadataCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetRowHiddenMutation, SetRowVisibleMutation, SetStyleCommand, SetWorkbookCalculationSettingsMutation, SetWorkbookNameCommand, SetWorksheetActiveOperation, SetWorksheetNameCommand, SheetInterceptorService, UniverSheetsPlugin, getSeparateEffectedRangesOnCommand, getSheetCommandTarget, handleCommonDefaultRangeChangeWithEffectRefCommands, handleDefaultRangeChangeWithEffectRefCommands, handleDeleteRangeMoveLeft, handleDeleteRangeMoveUp, handleIRemoveCol, handleIRemoveRow, handleInsertCol, handleInsertRangeMoveDown, handleInsertRangeMoveRight, handleInsertRow, handleMoveCols, handleMoveRange, handleMoveRows, runRefRangeMutations } from "@univerjs/sheets";
3
- import { AstTreeBuilder, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, ErrorType, FormulaCalculationSessionService, FormulaDataModel, FormulaExecuteStageType, FormulaExecutedStateType, FormulaResultApplicationType, FunctionType, IActiveDirtyManagerService, IDefinedNamesService, IDescriptionService, IFormulaCurrentConfigService, IFunctionService, ISuperTableService, Interpreter, Lexer, LexerTreeBuilder, RemoveDefinedNameMutation, RemoveSuperTableMutation, SetArrayFormulaDataMutation, SetDefinedNameMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDataMutation, SetFormulaStringBatchCalculationMutation, SetImageFormulaDataMutation, SetSuperTableMutation, SetTriggerFormulaCalculationStartMutation, UniverFormulaEnginePlugin, deserializeRangeWithSheetWithCache, generateExecuteAstNodeData, generateStringWithSequence, getObjectValue, refactorFormulaUnitQualifier, sequenceNodeType, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet, splitTableStructuredRef, stripErrorMargin } from "@univerjs/engine-formula";
1
+ import { a as name, c as __decorate, d as PLUGIN_CONFIG_KEY_BASE, f as defaultPluginBaseConfig, i as RemoteRegisterFunctionServiceName, l as __decorateParam, n as IRemoteRegisterFunctionService, o as version, r as RemoteRegisterFunctionService, s as _defineProperty, t as UniverRemoteSheetsFormulaPlugin, u as CalculationMode } from "./worker-m5XIUFq5.js";
2
+ 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, Range, Rectangle, Tools, UniverInstanceType, WrapTextType, cellToRange, createDocumentModelWithStyle, generateRandomId, getIntersectRange, isFormulaId, isFormulaString, isNodeEnv, isRealNum, merge, moveRangeByOffset, sequenceExecute, toDisposable, touchDependencies } from "@univerjs/core";
3
+ 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, ReorderRangeCommand, ReorderRangeMutation, SCOPE_WORKBOOK_VALUE_DEFINED_NAME, SetBorderCommand, SetDefinedNameCommand, SetRangeCustomMetadataCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetRowHiddenMutation, SetRowVisibleMutation, SetStyleCommand, SetWorkbookCalculationSettingsMutation, SetWorkbookNameCommand, SetWorksheetActiveOperation, SetWorksheetColumnCountMutation, SetWorksheetNameCommand, SetWorksheetOrderMutation, SetWorksheetRowCountMutation, SheetInterceptorService, UniverSheetsPlugin, getSeparateEffectedRangesOnCommand, getSheetCommandTarget, handleCommonDefaultRangeChangeWithEffectRefCommands, handleDefaultRangeChangeWithEffectRefCommands, handleDeleteRangeMoveLeft, handleDeleteRangeMoveUp, handleIRemoveCol, handleIRemoveRow, handleInsertCol, handleInsertRangeMoveDown, handleInsertRangeMoveRight, handleInsertRow, handleMoveCols, handleMoveRange, handleMoveRows, runRefRangeMutations } from "@univerjs/sheets";
4
+ import { AstTreeBuilder, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, ErrorType, FormulaCalculationSessionService, FormulaDataModel, FormulaExecuteStageType, FormulaExecutedStateType, FormulaResultApplicationType, FunctionType, IActiveDirtyManagerService, IDefinedNamesService, IDescriptionService, IFormulaCurrentConfigService, ISuperTableService, Interpreter, Lexer, LexerTreeBuilder, RemoveDefinedNameMutation, RemoveSuperTableMutation, SetArrayFormulaDataMutation, SetDefinedNameMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDataMutation, SetFormulaStringBatchCalculationMutation, SetImageFormulaDataMutation, SetSuperTableMutation, SetTriggerFormulaCalculationStartMutation, UniverFormulaEnginePlugin, deserializeRangeWithSheetWithCache, generateExecuteAstNodeData, generateStringWithSequence, getObjectValue, refactorFormulaUnitQualifier, sequenceNodeType, serializeRange, serializeRangeToRefString, serializeRangeWithSheet, serializeRangeWithSpreadsheet, splitTableStructuredRef, stripErrorMargin } from "@univerjs/engine-formula";
4
5
  import { buildDocTransform } from "@univerjs/docs";
5
6
  import { BehaviorSubject, map } from "rxjs";
6
- import { IRPCChannelService, fromModule, toModule } from "@univerjs/rpc";
7
+ import { IRPCChannelService, toModule } from "@univerjs/rpc";
7
8
 
8
- //#region src/commands/commands/insert-function.command.ts
9
+ // src/commands/commands/insert-function.command.ts
9
10
  const InsertFunctionCommand = {
10
11
  id: "formula.command.insert-function",
11
12
  type: CommandType.COMMAND,
@@ -33,60 +34,7 @@ const InsertFunctionCommand = {
33
34
  }
34
35
  };
35
36
 
36
- //#endregion
37
- //#region src/config/config.ts
38
- /**
39
- * Base configuration for the plugin.
40
- */
41
- const PLUGIN_CONFIG_KEY_BASE = "sheets-formula.base.config";
42
- const configSymbolBase = Symbol(PLUGIN_CONFIG_KEY_BASE);
43
- let CalculationMode = /* @__PURE__ */ function(CalculationMode) {
44
- /**
45
- * Force calculation of all formulas
46
- */
47
- CalculationMode[CalculationMode["FORCED"] = 0] = "FORCED";
48
- /**
49
- * Partial calculation, only cells with formulas but no v values are calculated
50
- */
51
- CalculationMode[CalculationMode["WHEN_EMPTY"] = 1] = "WHEN_EMPTY";
52
- /**
53
- * All formulas are not calculated
54
- */
55
- CalculationMode[CalculationMode["NO_CALCULATION"] = 2] = "NO_CALCULATION";
56
- return CalculationMode;
57
- }({});
58
- const defaultPluginBaseConfig = {};
59
- /**
60
- * Remote configuration for the plugin.
61
- */
62
- const PLUGIN_CONFIG_KEY_REMOTE = "sheets-formula.remote.config";
63
- const configSymbolRemote = Symbol(PLUGIN_CONFIG_KEY_REMOTE);
64
- const defaultPluginRemoteConfig = {};
65
- /**
66
- * Mobile configuration for the plugin.
67
- */
68
- const PLUGIN_CONFIG_KEY_MOBILE = "sheets-formula.mobile.config";
69
- const configSymbolMobile = Symbol(PLUGIN_CONFIG_KEY_MOBILE);
70
-
71
- //#endregion
72
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
73
- function __decorateParam(paramIndex, decorator) {
74
- return function(target, key) {
75
- decorator(target, key, paramIndex);
76
- };
77
- }
78
-
79
- //#endregion
80
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
81
- function __decorate(decorators, target, key, desc) {
82
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
83
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
84
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
85
- return c > 3 && r && Object.defineProperty(target, key, r), r;
86
- }
87
-
88
- //#endregion
89
- //#region src/controllers/formula-auto-fill.controller.ts
37
+ // src/controllers/formula-auto-fill.controller.ts
90
38
  let FormulaAutoFillController = class FormulaAutoFillController extends Disposable {
91
39
  constructor(_autoFillService, _lexerTreeBuilder) {
92
40
  super();
@@ -188,8 +136,7 @@ function getDataLength(copyDataPiece) {
188
136
  return length;
189
137
  }
190
138
 
191
- //#endregion
192
- //#region src/controllers/formula-reorder.controller.ts
139
+ // src/controllers/formula-reorder.controller.ts
193
140
  let FormulaReorderController = class FormulaReorderController extends Disposable {
194
141
  constructor(_sheetInterceptorService, _univerInstanceService, _formulaDataModel, _lexerTreeBuilder) {
195
142
  super();
@@ -270,50 +217,7 @@ FormulaReorderController = __decorate([
270
217
  __decorateParam(3, Inject(LexerTreeBuilder))
271
218
  ], FormulaReorderController);
272
219
 
273
- //#endregion
274
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
275
- function _typeof(o) {
276
- "@babel/helpers - typeof";
277
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
278
- return typeof o;
279
- } : function(o) {
280
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
281
- }, _typeof(o);
282
- }
283
-
284
- //#endregion
285
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
286
- function toPrimitive(t, r) {
287
- if ("object" != _typeof(t) || !t) return t;
288
- var e = t[Symbol.toPrimitive];
289
- if (void 0 !== e) {
290
- var i = e.call(t, r || "default");
291
- if ("object" != _typeof(i)) return i;
292
- throw new TypeError("@@toPrimitive must return a primitive value.");
293
- }
294
- return ("string" === r ? String : Number)(t);
295
- }
296
-
297
- //#endregion
298
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
299
- function toPropertyKey(t) {
300
- var i = toPrimitive(t, "string");
301
- return "symbol" == _typeof(i) ? i : i + "";
302
- }
303
-
304
- //#endregion
305
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
306
- function _defineProperty(e, r, t) {
307
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
308
- value: t,
309
- enumerable: !0,
310
- configurable: !0,
311
- writable: !0
312
- }) : e[r] = t, e;
313
- }
314
-
315
- //#endregion
316
- //#region src/controllers/image-formula-cell-interceptor.controller.ts
220
+ // src/controllers/image-formula-cell-interceptor.controller.ts
317
221
  let ImageFormulaCellInterceptorController = class ImageFormulaCellInterceptorController extends Disposable {
318
222
  constructor(_commandService, _sheetInterceptorService, _formulaDataModel) {
319
223
  super();
@@ -456,8 +360,7 @@ ImageFormulaCellInterceptorController = __decorate([
456
360
  __decorateParam(2, Inject(FormulaDataModel))
457
361
  ], ImageFormulaCellInterceptorController);
458
362
 
459
- //#endregion
460
- //#region src/controllers/trigger-calculation.controller.ts
363
+ // src/controllers/trigger-calculation.controller.ts
461
364
  const NilProgress = {
462
365
  done: 0,
463
366
  count: 0
@@ -638,8 +541,7 @@ TriggerCalculationController = __decorate([
638
541
  __decorateParam(5, Inject(LocaleService))
639
542
  ], TriggerCalculationController);
640
543
 
641
- //#endregion
642
- //#region src/controllers/unit-qualifier-rename.controller.ts
544
+ // src/controllers/unit-qualifier-rename.controller.ts
643
545
  function collectUnitQualifierFormulaPatches(workbook, oldName, newName) {
644
546
  const unitId = workbook.getUnitId();
645
547
  return workbook.getSheets().flatMap((sheet) => {
@@ -738,8 +640,7 @@ UnitQualifierRenameController = __decorate([
738
640
  __decorateParam(3, IDefinedNamesService)
739
641
  ], UnitQualifierRenameController);
740
642
 
741
- //#endregion
742
- //#region src/controllers/utils/offset-formula-data.ts
643
+ // src/controllers/utils/offset-formula-data.ts
743
644
  function checkFormulaDataNull(formulaData, unitId, sheetId) {
744
645
  var _formulaData$unitId;
745
646
  if (formulaData == null || formulaData[unitId] == null || ((_formulaData$unitId = formulaData[unitId]) === null || _formulaData$unitId === void 0 ? void 0 : _formulaData$unitId[sheetId]) == null) return true;
@@ -758,8 +659,7 @@ function removeFormulaData(formulaData, unitId, sheetId) {
758
659
  }
759
660
  }
760
661
 
761
- //#endregion
762
- //#region src/controllers/utils/ref-range-formula.ts
662
+ // src/controllers/utils/ref-range-formula.ts
763
663
  const formulaReferenceSheetList = [
764
664
  11,
765
665
  12,
@@ -1230,8 +1130,7 @@ function updateRefOffset(sequenceNodes, refChangeIds, refOffsetX = 0, refOffsetY
1230
1130
  return newSequenceNodes;
1231
1131
  }
1232
1132
 
1233
- //#endregion
1234
- //#region src/controllers/utils/ref-range-move.ts
1133
+ // src/controllers/utils/ref-range-move.ts
1235
1134
  function getNewRangeByMoveParam(unitRangeWidthOffset, formulaReferenceMoveParam, currentFormulaUnitId, currentFormulaSheetId, options = {}) {
1236
1135
  const { type, unitId: userUnitId, sheetId: userSheetId, targetUnitId, targetSheetId, targetSheetName, range, from, to, rangeFilteredRows } = formulaReferenceMoveParam;
1237
1136
  const { range: unitRange, sheetId: sequenceRangeSheetId, unitId: sequenceRangeUnitId, sheetName: sequenceRangeSheetName, refOffsetX, refOffsetY } = unitRangeWidthOffset;
@@ -1556,8 +1455,7 @@ function getStartEndValue(range) {
1556
1455
  };
1557
1456
  }
1558
1457
 
1559
- //#endregion
1560
- //#region src/controllers/utils/ref-range-param.ts
1458
+ // src/controllers/utils/ref-range-param.ts
1561
1459
  const SET_SHEET_TABLE_COMMAND_ID = "sheet.command.set-table-config";
1562
1460
  const DELETE_SHEET_TABLE_COMMAND_ID = "sheet.command.delete-table";
1563
1461
  const REMOVE_SHEET_TABLE_COLUMN_AT_COMMAND_ID = "sheet.command.table-remove-column-at";
@@ -1911,8 +1809,7 @@ function handleRefRemoveSheetTableColumn(command, workbook) {
1911
1809
  };
1912
1810
  }
1913
1811
 
1914
- //#endregion
1915
- //#region src/controllers/update-defined-name.controller.ts
1812
+ // src/controllers/update-defined-name.controller.ts
1916
1813
  let UpdateDefinedNameController = class UpdateDefinedNameController extends Disposable {
1917
1814
  constructor(_definedNamesService, _univerInstanceService, _sheetInterceptorService, _lexerTreeBuilder) {
1918
1815
  super();
@@ -2061,8 +1958,7 @@ UpdateDefinedNameController = __decorate([
2061
1958
  __decorateParam(3, Inject(LexerTreeBuilder))
2062
1959
  ], UpdateDefinedNameController);
2063
1960
 
2064
- //#endregion
2065
- //#region src/controllers/update-formula.controller.ts
1961
+ // src/controllers/update-formula.controller.ts
2066
1962
  let UpdateFormulaController = class UpdateFormulaController extends Disposable {
2067
1963
  constructor(_univerInstanceService, _commandService, _lexerTreeBuilder, _formulaDataModel, _sheetInterceptorService, _definedNamesService, _configService, _injector) {
2068
1964
  super();
@@ -2095,12 +1991,30 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
2095
1991
  this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(UniverInstanceType.UNIVER_SHEET).subscribe((event) => this._handleWorkbookAdded(event.unit)));
2096
1992
  this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(UniverInstanceType.UNIVER_SHEET).pipe(map((unit) => unit.getUnitId())).subscribe((unitId) => this._handleWorkbookDisposed(unitId)));
2097
1993
  }
1994
+ _getEditedArrayFormulaDirtyRanges(params) {
1995
+ var _this$_formulaDataMod;
1996
+ const { subUnitId: sheetId, unitId, cellValue } = params;
1997
+ const previousRanges = (_this$_formulaDataMod = this._formulaDataModel.getArrayFormulaRange()[unitId]) === null || _this$_formulaDataMod === void 0 ? void 0 : _this$_formulaDataMod[sheetId];
1998
+ const dirtyRanges = [];
1999
+ if (previousRanges) new ObjectMatrix(cellValue).forValue((row, column) => {
2000
+ var _previousRanges$row;
2001
+ const range = (_previousRanges$row = previousRanges[row]) === null || _previousRanges$row === void 0 ? void 0 : _previousRanges$row[column];
2002
+ if (range && (range.startRow !== range.endRow || range.startColumn !== range.endColumn)) dirtyRanges.push({
2003
+ unitId,
2004
+ sheetId,
2005
+ range
2006
+ });
2007
+ });
2008
+ return dirtyRanges;
2009
+ }
2098
2010
  _handleSetRangeValuesMutation(params) {
2099
2011
  const { subUnitId: sheetId, unitId, cellValue } = params;
2100
2012
  if (cellValue == null) return;
2013
+ const dirtyRanges = this._getEditedArrayFormulaDirtyRanges(params);
2101
2014
  const newSheetFormulaData = this._formulaDataModel.updateFormulaData(unitId, sheetId, cellValue);
2102
2015
  const arrayFormulaCellDataChanged = this._formulaDataModel.updateArrayFormulaCellData(unitId, sheetId, cellValue);
2103
2016
  const arrayFormulaRangeChanged = this._formulaDataModel.updateArrayFormulaRange(unitId, sheetId, cellValue);
2017
+ if (dirtyRanges.length > 0) this._commandService.syncExecuteCommand(SetTriggerFormulaCalculationStartMutation.id, { dirtyRanges }, { onlyLocal: true });
2104
2018
  if (Object.keys(newSheetFormulaData).length === 0) {
2105
2019
  if (arrayFormulaCellDataChanged || arrayFormulaRangeChanged) this._commandService.executeCommand(SetArrayFormulaDataMutation.id, {
2106
2020
  arrayFormulaRange: this._formulaDataModel.getArrayFormulaRange(),
@@ -2212,7 +2126,6 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
2212
2126
  const formulaDataKeys = Object.keys(formulaData);
2213
2127
  if (formulaDataKeys.length === 0) return { newFormulaData: {} };
2214
2128
  const newFormulaData = Object.create(null);
2215
- const { unitId: fromUnitId, sheetId: fromSheetId, sheetName: fromSheetName, targetUnitId, targetSheetId, type, from, to } = formulaReferenceMoveParam;
2216
2129
  const inCrossSheetCutRangeNewFormulas = [];
2217
2130
  for (const unitId of formulaDataKeys) {
2218
2131
  const sheetData = formulaData[unitId];
@@ -2222,165 +2135,104 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
2222
2135
  for (const sheetId of sheetDataKeys) {
2223
2136
  const matrixData = new ObjectMatrix(sheetData[sheetId] || {});
2224
2137
  const newFormulaDataItem = new ObjectMatrix();
2225
- const shouldModifySi = [];
2138
+ const context = {
2139
+ unitId,
2140
+ sheetId,
2141
+ unitSheetNameMap,
2142
+ params: formulaReferenceMoveParam,
2143
+ modifiedSharedFormulaIds: []
2144
+ };
2226
2145
  matrixData.forValue((row, column, formulaDataItem) => {
2227
- if (!formulaDataItem) return true;
2228
- const { f: formulaString, x, y, si } = formulaDataItem;
2229
- if (type === 12) {
2230
- const { oldUnitName, unitName } = formulaReferenceMoveParam;
2231
- if (!oldUnitName || !unitName) return true;
2232
- const nextFormula = refactorFormulaUnitQualifier(formulaString, oldUnitName, unitName);
2233
- if (nextFormula !== formulaString) newFormulaDataItem.setValue(row, column, { f: nextFormula });
2234
- return true;
2235
- }
2236
- const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);
2237
- if (sequenceNodes == null) return true;
2238
- let shouldModify = false;
2239
- const refChangeIds = [];
2240
- const inCrossSheetCutRange = type === 0 && (targetUnitId !== fromUnitId || targetSheetId !== fromSheetId) && unitId === fromUnitId && sheetId === fromSheetId && from && from.startRow <= row && row <= from.endRow && from.startColumn <= column && column <= from.endColumn;
2241
- const inCrossSheetCutRangeSequenceNodes = [...sequenceNodes];
2242
- for (let i = 0, len = sequenceNodes.length; i < len; i++) {
2243
- var _unitSheetNameMap$map;
2244
- const node = sequenceNodes[i];
2245
- if (typeof node === "string") continue;
2246
- const { token, nodeType } = node;
2247
- if ((type === 14 || type === 15) && (nodeType === sequenceNodeType.DEFINED_NAME || nodeType === sequenceNodeType.FUNCTION)) {
2248
- const { definedNameId, definedName } = formulaReferenceMoveParam;
2249
- if (definedNameId === void 0 || definedName === void 0) continue;
2250
- const oldDefinedName = this._definedNamesService.getValueById(unitId, definedNameId);
2251
- if (oldDefinedName === void 0 || oldDefinedName === null) continue;
2252
- if (oldDefinedName.name !== token) continue;
2253
- sequenceNodes[i] = {
2254
- ...node,
2255
- token: type === 14 ? definedName : ErrorType.REF
2256
- };
2257
- shouldModify = true;
2258
- refChangeIds.push(i);
2259
- continue;
2260
- } else if ((type === 16 || type === 17 || type === 18) && (nodeType === sequenceNodeType.TABLE || nodeType === sequenceNodeType.FUNCTION)) {
2261
- const { oldTableName, tableName, tableColumnNames } = formulaReferenceMoveParam;
2262
- if (oldTableName === void 0 || type === 16 && tableName === void 0) continue;
2263
- const { tableName: tokenTableName, columnStruct = "" } = splitTableStructuredRef(token);
2264
- if (tokenTableName !== oldTableName) continue;
2265
- if (type === 18 && !tableReferenceContainsColumn(columnStruct, tableColumnNames)) continue;
2266
- sequenceNodes[i] = {
2267
- ...node,
2268
- token: type === 16 ? `${tableName}${columnStruct}` : ErrorType.REF
2269
- };
2270
- const nextNode = sequenceNodes[i + 1];
2271
- if ((type === 17 || type === 18) && typeof nextNode === "string" && nextNode.startsWith("]")) sequenceNodes[i + 1] = nextNode.slice(1);
2272
- shouldModify = true;
2273
- refChangeIds.push(i);
2274
- continue;
2275
- } else if (nodeType !== sequenceNodeType.REFERENCE) continue;
2276
- const { range, sheetName, unitId: sequenceUnitId } = deserializeRangeWithSheetWithCache(token);
2277
- const mapUnitId = sequenceUnitId == null || sequenceUnitId.length === 0 ? unitId : sequenceUnitId;
2278
- const sequenceSheetId = (unitSheetNameMap === null || unitSheetNameMap === void 0 || (_unitSheetNameMap$map = unitSheetNameMap[mapUnitId]) === null || _unitSheetNameMap$map === void 0 ? void 0 : _unitSheetNameMap$map[sheetName]) || "";
2279
- if (!checkIsSameUnitAndSheet(formulaReferenceMoveParam.unitId, formulaReferenceMoveParam.sheetId, unitId, sheetId, sequenceUnitId, sequenceSheetId)) continue;
2280
- const sequenceUnitRangeWidthOffset = {
2281
- range,
2282
- sheetId: sequenceSheetId,
2283
- unitId: sequenceUnitId,
2284
- sheetName,
2285
- refOffsetX: x || 0,
2286
- refOffsetY: y || 0
2287
- };
2288
- let newRefString = null;
2289
- if (type === 11) {
2290
- const { unitId: userUnitId, sheetId: userSheetId, sheetName: newSheetName } = formulaReferenceMoveParam;
2291
- if (newSheetName == null) continue;
2292
- if (sequenceSheetId == null || sequenceSheetId.length === 0) continue;
2293
- if (userSheetId !== sequenceSheetId) continue;
2294
- newRefString = serializeRangeToRefString({
2295
- range,
2296
- sheetName: newSheetName,
2297
- unitId: sequenceUnitId
2298
- });
2299
- } else if (type === 13) {
2300
- const { unitId: userUnitId, sheetId: userSheetId, sheetName: newSheetName } = formulaReferenceMoveParam;
2301
- if (sequenceSheetId == null || sequenceSheetId.length === 0) continue;
2302
- if (userSheetId !== sequenceSheetId) continue;
2303
- newRefString = ErrorType.REF;
2304
- } else if (type !== 14) newRefString = getNewRangeByMoveParam(sequenceUnitRangeWidthOffset, formulaReferenceMoveParam, unitId, sheetId, { inCrossSheetCutRange });
2305
- if (newRefString != null) {
2306
- sequenceNodes[i] = {
2307
- ...node,
2308
- token: newRefString
2309
- };
2310
- shouldModify = true;
2311
- refChangeIds.push(i);
2312
- if (si && (x ?? 0) === 0 && (y ?? 0) === 0) shouldModifySi.push(si);
2313
- }
2314
- /**
2315
- * If the reference sequence range is not affected by the move, and the move is a cross-worksheet cut operation, it may be necessary to rewrite the sheet name in the ref string after move, to make sure the ref still works after move.
2316
- * For example, if a formula cell is `=SUM(A1:A5)` in Sheet1, and formula cell cut to Sheet2, the formula should be rewritten to `=SUM(Sheet1!A1:A5)`, otherwise it will become `=SUM(A1:A5)` and reference the wrong range in Sheet2.
2317
- */
2318
- if (inCrossSheetCutRange) {
2319
- if (newRefString != null) inCrossSheetCutRangeSequenceNodes[i] = {
2320
- ...node,
2321
- token: newRefString
2322
- };
2323
- else if ((!sequenceUnitId || sequenceUnitId === fromUnitId) && (!sequenceSheetId || sequenceSheetId === fromSheetId)) {
2324
- /**
2325
- * Only the reference range is in the from worksheet need to rewrite the sheet name, otherwise the ref string will be rewritten unnecessarily when moving between other worksheets.
2326
- * For example, if a formula cell is `=SUM(Sheet3!A1:A5)` in Sheet1, and formula cell cut to Sheet2, the formula should not be rewritten, otherwise it will become `=SUM(Sheet1!A1:A5)` and reference the wrong range in Sheet1, while the original ref is referencing Sheet3 and should not be affected by the move between Sheet1 and Sheet2.
2327
- */
2328
- const sequenceRange = Rectangle.moveOffset(range, x || 0, y || 0);
2329
- inCrossSheetCutRangeSequenceNodes[i] = {
2330
- ...node,
2331
- token: serializeRangeToRefString({
2332
- range: sequenceRange,
2333
- sheetName: fromSheetName || sheetName,
2334
- unitId: targetUnitId !== fromUnitId ? fromUnitId : ""
2335
- })
2336
- };
2337
- shouldModify = true;
2338
- }
2339
- }
2340
- }
2341
- if (!shouldModify) {
2342
- /**
2343
- * If the operation is a move type, and the formula cell has si and is the same as the current shouldModifySi, unpack the si to f.
2344
- * Or the source formula cell is in the moved range.
2345
- * This is to ensure that the si formula can be recalculated correctly after the move.
2346
- */
2347
- if (si && [
2348
- 1,
2349
- 2,
2350
- 0
2351
- ].includes(type)) {
2352
- if (from && from.startRow <= row && row <= from.endRow && from.startColumn <= column && column <= from.endColumn) {
2353
- if ((x ?? 0) === 0 && (y ?? 0) === 0) shouldModifySi.push(si);
2354
- } else if (!shouldModifySi.includes(si)) return true;
2355
- } else return true;
2356
- }
2357
- if (inCrossSheetCutRange) {
2358
- const newSequenceNodes = updateRefOffset(inCrossSheetCutRangeSequenceNodes, refChangeIds, x, y);
2359
- inCrossSheetCutRangeNewFormulas.push({
2360
- fromRow: row,
2361
- fromColumn: column,
2362
- formulaString: `=${generateStringWithSequence(newSequenceNodes)}`
2363
- });
2364
- return true;
2365
- }
2366
- const newSequenceNodes = updateRefOffset(sequenceNodes, refChangeIds, x, y);
2367
- newFormulaDataItem.setValue(row, column, { f: `=${generateStringWithSequence(newSequenceNodes)}` });
2146
+ const formula = this._getMovedFormula(formulaDataItem, row, column, context, inCrossSheetCutRangeNewFormulas);
2147
+ if (formula != null) newFormulaDataItem.setValue(row, column, { f: formula });
2368
2148
  });
2369
2149
  if (newFormulaData[unitId]) newFormulaData[unitId][sheetId] = newFormulaDataItem.clone();
2370
2150
  }
2371
2151
  }
2372
- if (inCrossSheetCutRangeNewFormulas.length > 0 && targetUnitId && targetSheetId) {
2373
- if (!newFormulaData[targetUnitId]) newFormulaData[targetUnitId] = Object.create(null);
2374
- if (!newFormulaData[targetUnitId][targetSheetId]) newFormulaData[targetUnitId][targetSheetId] = Object.create(null);
2375
- for (const newFormula of inCrossSheetCutRangeNewFormulas) {
2376
- const { fromRow, fromColumn, formulaString } = newFormula;
2377
- const targetRow = fromRow + (((to === null || to === void 0 ? void 0 : to.startRow) ?? 0) - ((from === null || from === void 0 ? void 0 : from.startRow) ?? 0));
2378
- const targetColumn = fromColumn + (((to === null || to === void 0 ? void 0 : to.startColumn) ?? 0) - ((from === null || from === void 0 ? void 0 : from.startColumn) ?? 0));
2379
- if (!newFormulaData[targetUnitId][targetSheetId][targetRow]) newFormulaData[targetUnitId][targetSheetId][targetRow] = Object.create(null);
2380
- newFormulaData[targetUnitId][targetSheetId][targetRow][targetColumn] = { f: formulaString };
2152
+ appendCrossSheetCutFormulas(newFormulaData, inCrossSheetCutRangeNewFormulas, formulaReferenceMoveParam);
2153
+ return { newFormulaData };
2154
+ }
2155
+ _getMovedFormula(item, row, column, context, crossSheetFormulas) {
2156
+ if (!item) return null;
2157
+ const { f: formulaString, x, y } = item;
2158
+ const { unitId, sheetId, params, modifiedSharedFormulaIds } = context;
2159
+ if (params.type === 12) {
2160
+ const { oldUnitName, unitName } = params;
2161
+ if (!oldUnitName || !unitName) return null;
2162
+ const nextFormula = refactorFormulaUnitQualifier(formulaString, oldUnitName, unitName);
2163
+ return nextFormula !== formulaString ? nextFormula : null;
2164
+ }
2165
+ const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);
2166
+ if (sequenceNodes == null) return null;
2167
+ const refChangeIds = [];
2168
+ const inCrossSheetCutRange = isInCrossSheetCutRange(unitId, sheetId, row, column, params);
2169
+ const crossSheetNodes = [...sequenceNodes];
2170
+ if (!this._updateFormulaReferenceNodes(sequenceNodes, item, context, refChangeIds, inCrossSheetCutRange ? crossSheetNodes : null) && !shouldUnpackSharedFormula(item, row, column, params, modifiedSharedFormulaIds)) return null;
2171
+ const newSequenceNodes = updateRefOffset(inCrossSheetCutRange ? crossSheetNodes : sequenceNodes, refChangeIds, x, y);
2172
+ const formula = `=${generateStringWithSequence(newSequenceNodes)}`;
2173
+ if (inCrossSheetCutRange) {
2174
+ crossSheetFormulas.push({
2175
+ fromRow: row,
2176
+ fromColumn: column,
2177
+ formulaString: formula
2178
+ });
2179
+ return null;
2180
+ }
2181
+ return formula;
2182
+ }
2183
+ _updateFormulaReferenceNodes(sequenceNodes, item, context, refChangeIds, crossSheetNodes) {
2184
+ const { unitId, sheetId, params, modifiedSharedFormulaIds } = context;
2185
+ const { x, y, si } = item;
2186
+ let shouldModify = false;
2187
+ for (let i = 0, len = sequenceNodes.length; i < len; i++) {
2188
+ const node = sequenceNodes[i];
2189
+ if (typeof node === "string") continue;
2190
+ const definedNameToken = this._getDefinedNameReferenceToken(node, unitId, params);
2191
+ if (definedNameToken != null) {
2192
+ sequenceNodes[i] = {
2193
+ ...node,
2194
+ token: definedNameToken
2195
+ };
2196
+ shouldModify = true;
2197
+ refChangeIds.push(i);
2198
+ continue;
2199
+ }
2200
+ if (updateTableReference(sequenceNodes, i, node, params)) {
2201
+ shouldModify = true;
2202
+ refChangeIds.push(i);
2203
+ continue;
2204
+ }
2205
+ if (node.nodeType !== sequenceNodeType.REFERENCE) continue;
2206
+ const reference = getReferenceWithOffset(node.token, item, context);
2207
+ if (reference == null) continue;
2208
+ const newRefString = getMovedReferenceToken(reference, params, unitId, sheetId, crossSheetNodes != null);
2209
+ if (newRefString != null) {
2210
+ sequenceNodes[i] = {
2211
+ ...node,
2212
+ token: newRefString
2213
+ };
2214
+ shouldModify = true;
2215
+ refChangeIds.push(i);
2216
+ if (si && (x ?? 0) === 0 && (y ?? 0) === 0) modifiedSharedFormulaIds.push(si);
2217
+ }
2218
+ if (crossSheetNodes != null) {
2219
+ const movedNode = getCrossSheetCutReference(node, reference, newRefString, params);
2220
+ if (movedNode != null) {
2221
+ crossSheetNodes[i] = movedNode;
2222
+ shouldModify = true;
2223
+ }
2381
2224
  }
2382
2225
  }
2383
- return { newFormulaData };
2226
+ return shouldModify;
2227
+ }
2228
+ _getDefinedNameReferenceToken(node, unitId, params) {
2229
+ const { type, definedNameId, definedName } = params;
2230
+ if (type !== 14 && type !== 15) return null;
2231
+ if (node.nodeType !== sequenceNodeType.DEFINED_NAME && node.nodeType !== sequenceNodeType.FUNCTION) return null;
2232
+ if (definedNameId === void 0 || definedName === void 0) return null;
2233
+ const oldDefinedName = this._definedNamesService.getValueById(unitId, definedNameId);
2234
+ if (oldDefinedName == null || oldDefinedName.name !== node.token) return null;
2235
+ return type === 14 ? definedName : ErrorType.REF;
2384
2236
  }
2385
2237
  };
2386
2238
  UpdateFormulaController = __decorate([
@@ -2393,6 +2245,99 @@ UpdateFormulaController = __decorate([
2393
2245
  __decorateParam(6, IConfigService),
2394
2246
  __decorateParam(7, Inject(Injector))
2395
2247
  ], UpdateFormulaController);
2248
+ function getReferenceWithOffset(token, item, context) {
2249
+ var _unitSheetNameMap$map;
2250
+ const { unitId, sheetId, unitSheetNameMap, params } = context;
2251
+ const { range, sheetName, unitId: sequenceUnitId } = deserializeRangeWithSheetWithCache(token);
2252
+ const mapUnitId = sequenceUnitId == null || sequenceUnitId.length === 0 ? unitId : sequenceUnitId;
2253
+ const sequenceSheetId = (unitSheetNameMap === null || unitSheetNameMap === void 0 || (_unitSheetNameMap$map = unitSheetNameMap[mapUnitId]) === null || _unitSheetNameMap$map === void 0 ? void 0 : _unitSheetNameMap$map[sheetName]) || "";
2254
+ if (!checkIsSameUnitAndSheet(params.unitId, params.sheetId, unitId, sheetId, sequenceUnitId, sequenceSheetId)) return null;
2255
+ return {
2256
+ range,
2257
+ sheetId: sequenceSheetId,
2258
+ unitId: sequenceUnitId,
2259
+ sheetName,
2260
+ refOffsetX: item.x || 0,
2261
+ refOffsetY: item.y || 0
2262
+ };
2263
+ }
2264
+ function appendCrossSheetCutFormulas(data, formulas, params) {
2265
+ const { targetUnitId, targetSheetId, from, to } = params;
2266
+ if (formulas.length === 0 || !targetUnitId || !targetSheetId) return;
2267
+ if (!data[targetUnitId]) data[targetUnitId] = Object.create(null);
2268
+ if (!data[targetUnitId][targetSheetId]) data[targetUnitId][targetSheetId] = Object.create(null);
2269
+ for (const { fromRow, fromColumn, formulaString } of formulas) {
2270
+ const targetRow = fromRow + (((to === null || to === void 0 ? void 0 : to.startRow) ?? 0) - ((from === null || from === void 0 ? void 0 : from.startRow) ?? 0));
2271
+ const targetColumn = fromColumn + (((to === null || to === void 0 ? void 0 : to.startColumn) ?? 0) - ((from === null || from === void 0 ? void 0 : from.startColumn) ?? 0));
2272
+ if (!data[targetUnitId][targetSheetId][targetRow]) data[targetUnitId][targetSheetId][targetRow] = Object.create(null);
2273
+ data[targetUnitId][targetSheetId][targetRow][targetColumn] = { f: formulaString };
2274
+ }
2275
+ }
2276
+ function isInCrossSheetCutRange(unitId, sheetId, row, column, params) {
2277
+ const { type, unitId: fromUnitId, sheetId: fromSheetId, targetUnitId, targetSheetId, from } = params;
2278
+ return type === 0 && (targetUnitId !== fromUnitId || targetSheetId !== fromSheetId) && unitId === fromUnitId && sheetId === fromSheetId && from != null && from.startRow <= row && row <= from.endRow && from.startColumn <= column && column <= from.endColumn;
2279
+ }
2280
+ function updateTableReference(sequenceNodes, index, node, params) {
2281
+ const { type, oldTableName, tableName, tableColumnNames } = params;
2282
+ if (type !== 16 && type !== 17 && type !== 18) return false;
2283
+ if (node.nodeType !== sequenceNodeType.TABLE && node.nodeType !== sequenceNodeType.FUNCTION) return false;
2284
+ if (oldTableName === void 0 || type === 16 && tableName === void 0) return false;
2285
+ const { tableName: tokenTableName, columnStruct = "" } = splitTableStructuredRef(node.token);
2286
+ if (tokenTableName !== oldTableName) return false;
2287
+ if (type === 18 && !tableReferenceContainsColumn(columnStruct, tableColumnNames)) return false;
2288
+ sequenceNodes[index] = {
2289
+ ...node,
2290
+ token: type === 16 ? `${tableName}${columnStruct}` : ErrorType.REF
2291
+ };
2292
+ const nextNode = sequenceNodes[index + 1];
2293
+ if ((type === 17 || type === 18) && typeof nextNode === "string" && nextNode.startsWith("]")) sequenceNodes[index + 1] = nextNode.slice(1);
2294
+ return true;
2295
+ }
2296
+ function getMovedReferenceToken(reference, params, unitId, sheetId, inCrossSheetCutRange) {
2297
+ const { type, sheetId: affectedSheetId, sheetName } = params;
2298
+ if (type === 11 || type === 13) {
2299
+ if (!reference.sheetId || affectedSheetId !== reference.sheetId) return null;
2300
+ if (type === 13) return ErrorType.REF;
2301
+ if (sheetName == null) return null;
2302
+ return serializeRangeToRefString({
2303
+ range: reference.range,
2304
+ sheetName,
2305
+ unitId: reference.unitId
2306
+ });
2307
+ }
2308
+ if (type === 14) return null;
2309
+ return getNewRangeByMoveParam(reference, params, unitId, sheetId, { inCrossSheetCutRange });
2310
+ }
2311
+ function getCrossSheetCutReference(node, reference, newRefString, params) {
2312
+ if (newRefString != null) return {
2313
+ ...node,
2314
+ token: newRefString
2315
+ };
2316
+ const { unitId, sheetId, targetUnitId, sheetName } = params;
2317
+ if (reference.unitId && reference.unitId !== unitId || reference.sheetId && reference.sheetId !== sheetId) return null;
2318
+ return {
2319
+ ...node,
2320
+ token: serializeRangeToRefString({
2321
+ range: Rectangle.moveOffset(reference.range, reference.refOffsetX || 0, reference.refOffsetY || 0),
2322
+ sheetName: sheetName || reference.sheetName,
2323
+ unitId: targetUnitId !== unitId ? unitId : ""
2324
+ })
2325
+ };
2326
+ }
2327
+ function shouldUnpackSharedFormula(item, row, column, params, modifiedIds) {
2328
+ const { si, x, y } = item;
2329
+ const { type, from } = params;
2330
+ if (!si || ![
2331
+ 1,
2332
+ 2,
2333
+ 0
2334
+ ].includes(type)) return false;
2335
+ if (from && from.startRow <= row && row <= from.endRow && from.startColumn <= column && column <= from.endColumn) {
2336
+ if ((x ?? 0) === 0 && (y ?? 0) === 0) modifiedIds.push(si);
2337
+ return true;
2338
+ }
2339
+ return modifiedIds.includes(si);
2340
+ }
2396
2341
  /**
2397
2342
  * Whether to skip the formula update when the setRangeValues mutation is executed.
2398
2343
  * The style-only cell value does not affect the formula calculation, so it can be skipped.
@@ -2438,13 +2383,7 @@ function tableReferenceContainsColumn(columnStruct, columnNames) {
2438
2383
  return false;
2439
2384
  }
2440
2385
 
2441
- //#endregion
2442
- //#region package.json
2443
- var name = "@univerjs/sheets-formula";
2444
- var version = "1.3.0";
2445
-
2446
- //#endregion
2447
- //#region src/common/plugin-name.ts
2386
+ // src/common/plugin-name.ts
2448
2387
  /**
2449
2388
  * Copyright 2023-present DreamNum Co., Ltd.
2450
2389
  *
@@ -2462,8 +2401,7 @@ var version = "1.3.0";
2462
2401
  */
2463
2402
  const SHEETS_FORMULA_PLUGIN_NAME = "SHEETS_FORMULA_PLUGIN";
2464
2403
 
2465
- //#endregion
2466
- //#region src/controllers/active-dirty.controller.ts
2404
+ // src/controllers/active-dirty.controller.ts
2467
2405
  let ActiveDirtyController = class ActiveDirtyController extends Disposable {
2468
2406
  constructor(_activeDirtyManagerService, _univerInstanceService, _formulaDataModel) {
2469
2407
  super();
@@ -2546,6 +2484,10 @@ let ActiveDirtyController = class ActiveDirtyController extends Disposable {
2546
2484
  });
2547
2485
  }
2548
2486
  _initialRowAndColumn() {
2487
+ for (const mutation of [SetWorksheetRowCountMutation, SetWorksheetColumnCountMutation]) this._activeDirtyManagerService.register(mutation.id, {
2488
+ commandId: mutation.id,
2489
+ getDirtyData: (command) => ({ dirtyReferenceUnits: [command.params.unitId] })
2490
+ });
2549
2491
  this._activeDirtyManagerService.register(RemoveRowMutation.id, {
2550
2492
  commandId: RemoveRowMutation.id,
2551
2493
  getDirtyData: (command) => {
@@ -2604,6 +2546,13 @@ let ActiveDirtyController = class ActiveDirtyController extends Disposable {
2604
2546
  });
2605
2547
  }
2606
2548
  _initialSheet() {
2549
+ this._activeDirtyManagerService.register(SetWorksheetOrderMutation.id, {
2550
+ commandId: SetWorksheetOrderMutation.id,
2551
+ getDirtyData: (command) => {
2552
+ const { unitId, fromOrder, toOrder } = command.params;
2553
+ return { dirtyReferenceUnits: fromOrder === toOrder ? [] : [unitId] };
2554
+ }
2555
+ });
2607
2556
  this._activeDirtyManagerService.register(RemoveSheetMutation.id, {
2608
2557
  commandId: RemoveSheetMutation.id,
2609
2558
  getDirtyData: (command) => {
@@ -2787,8 +2736,7 @@ ActiveDirtyController = __decorate([
2787
2736
  __decorateParam(2, Inject(FormulaDataModel))
2788
2737
  ], ActiveDirtyController);
2789
2738
 
2790
- //#endregion
2791
- //#region src/controllers/array-formula-cell-interceptor.controller.ts
2739
+ // src/controllers/array-formula-cell-interceptor.controller.ts
2792
2740
  let ArrayFormulaCellInterceptorController = class ArrayFormulaCellInterceptorController extends Disposable {
2793
2741
  constructor(_commandService, _sheetInterceptorService, _formulaDataModel) {
2794
2742
  super();
@@ -2847,8 +2795,7 @@ ArrayFormulaCellInterceptorController = __decorate([
2847
2795
  __decorateParam(2, Inject(FormulaDataModel))
2848
2796
  ], ArrayFormulaCellInterceptorController);
2849
2797
 
2850
- //#endregion
2851
- //#region src/controllers/defined-name.controller.ts
2798
+ // src/controllers/defined-name.controller.ts
2852
2799
  let DefinedNameController = class DefinedNameController extends Disposable {
2853
2800
  constructor(_descriptionService, _definedNamesService, _univerInstanceService, _commandService) {
2854
2801
  super();
@@ -2990,8 +2937,7 @@ DefinedNameController = __decorate([
2990
2937
  __decorateParam(3, ICommandService)
2991
2938
  ], DefinedNameController);
2992
2939
 
2993
- //#endregion
2994
- //#region src/controllers/formula.controller.ts
2940
+ // src/controllers/formula.controller.ts
2995
2941
  /**
2996
2942
  * Copyright 2023-present DreamNum Co., Ltd.
2997
2943
  *
@@ -3016,8 +2962,7 @@ let FormulaController = class FormulaController extends Disposable {
3016
2962
  };
3017
2963
  FormulaController = __decorate([__decorateParam(0, ICommandService)], FormulaController);
3018
2964
 
3019
- //#endregion
3020
- //#region src/controllers/sheet-formula-calculation-result-apply.controller.ts
2965
+ // src/controllers/sheet-formula-calculation-result-apply.controller.ts
3021
2966
  /**
3022
2967
  * Copyright 2023-present DreamNum Co., Ltd.
3023
2968
  *
@@ -3045,8 +2990,7 @@ let SheetFormulaCalculationResultApplyController = class SheetFormulaCalculation
3045
2990
  };
3046
2991
  SheetFormulaCalculationResultApplyController = __decorate([__decorateParam(0, ICommandService), __decorateParam(1, Inject(FormulaCalculationSessionService))], SheetFormulaCalculationResultApplyController);
3047
2992
 
3048
- //#endregion
3049
- //#region src/controllers/super-table.controller.ts
2993
+ // src/controllers/super-table.controller.ts
3050
2994
  let SuperTableController = class SuperTableController extends Disposable {
3051
2995
  constructor(_descriptionService, _univerInstanceService, _commandService, _superTableService) {
3052
2996
  super();
@@ -3174,8 +3118,7 @@ SuperTableController = __decorate([
3174
3118
  __decorateParam(3, ISuperTableService)
3175
3119
  ], SuperTableController);
3176
3120
 
3177
- //#endregion
3178
- //#region src/services/formula-ref-range.service.ts
3121
+ // src/services/formula-ref-range.service.ts
3179
3122
  function getFormulaKeyOffset(lexerTreeBuilder, formulaString, refOffsetX, refOffsetY) {
3180
3123
  const sequenceNodes = lexerTreeBuilder.sequenceNodesBuilder(formulaString);
3181
3124
  if (sequenceNodes == null) return formulaString;
@@ -3456,72 +3399,7 @@ FormulaRefRangeService = __decorate([
3456
3399
  __decorateParam(3, Inject(Injector))
3457
3400
  ], FormulaRefRangeService);
3458
3401
 
3459
- //#endregion
3460
- //#region src/services/remote/remote-register-function.service.ts
3461
- /**
3462
- * Copyright 2023-present DreamNum Co., Ltd.
3463
- *
3464
- * Licensed under the Apache License, Version 2.0 (the "License");
3465
- * you may not use this file except in compliance with the License.
3466
- * You may obtain a copy of the License at
3467
- *
3468
- * http://www.apache.org/licenses/LICENSE-2.0
3469
- *
3470
- * Unless required by applicable law or agreed to in writing, software
3471
- * distributed under the License is distributed on an "AS IS" BASIS,
3472
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3473
- * See the License for the specific language governing permissions and
3474
- * limitations under the License.
3475
- */
3476
- const RemoteRegisterFunctionServiceName = "sheets-formula.remote-register-function.service";
3477
- const IRemoteRegisterFunctionService = createIdentifier(RemoteRegisterFunctionServiceName);
3478
- let RemoteRegisterFunctionService = class RemoteRegisterFunctionService {
3479
- constructor(_functionService) {
3480
- this._functionService = _functionService;
3481
- }
3482
- async registerFunctions(serializedFuncs) {
3483
- rejectRemoteCustomFunctionRegistration(serializedFuncs);
3484
- }
3485
- async registerAsyncFunctions(serializedFuncs) {
3486
- rejectRemoteCustomFunctionRegistration(serializedFuncs);
3487
- }
3488
- async unregisterFunctions(names) {
3489
- this._functionService.unregisterExecutors(...names);
3490
- this._functionService.unregisterDescriptions(...names);
3491
- this._functionService.deleteFormulaAstCacheKey(...names);
3492
- }
3493
- };
3494
- RemoteRegisterFunctionService = __decorate([__decorateParam(0, IFunctionService)], RemoteRegisterFunctionService);
3495
- function rejectRemoteCustomFunctionRegistration(serializedFuncs) {
3496
- if (serializedFuncs.length === 0) return;
3497
- throw new Error("Remote custom function registration is disabled because function deserialization over RPC is unsafe.");
3498
- }
3499
-
3500
- //#endregion
3501
- //#region src/plugin.ts
3502
- let UniverRemoteSheetsFormulaPlugin = class UniverRemoteSheetsFormulaPlugin extends Plugin {
3503
- constructor(_config = defaultPluginRemoteConfig, _injector, _configService) {
3504
- super();
3505
- this._config = _config;
3506
- this._injector = _injector;
3507
- this._configService = _configService;
3508
- const { ...rest } = merge({}, defaultPluginRemoteConfig, this._config);
3509
- this._configService.setConfig(PLUGIN_CONFIG_KEY_REMOTE, rest);
3510
- }
3511
- onStarting() {
3512
- this._injector.add([RemoteRegisterFunctionService]);
3513
- this._injector.get(IRPCChannelService).registerChannel(RemoteRegisterFunctionServiceName, fromModule(this._injector.get(RemoteRegisterFunctionService)));
3514
- }
3515
- };
3516
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "pluginName", "SHEET_FORMULA_REMOTE_PLUGIN");
3517
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "packageName", name);
3518
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "version", version);
3519
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "type", UniverInstanceType.UNIVER_SHEET);
3520
- UniverRemoteSheetsFormulaPlugin = __decorate([
3521
- DependentOn(UniverFormulaEnginePlugin),
3522
- __decorateParam(1, Inject(Injector)),
3523
- __decorateParam(2, IConfigService)
3524
- ], UniverRemoteSheetsFormulaPlugin);
3402
+ // src/plugin.ts
3525
3403
  let UniverSheetsFormulaPlugin = class UniverSheetsFormulaPlugin extends Plugin {
3526
3404
  constructor(_config = defaultPluginBaseConfig, _injector, _configService) {
3527
3405
  super();
@@ -3552,7 +3430,9 @@ let UniverSheetsFormulaPlugin = class UniverSheetsFormulaPlugin extends Plugin {
3552
3430
  ];
3553
3431
  if (this._config.notExecuteFormula) {
3554
3432
  const rpcChannelService = j.get(IRPCChannelService);
3555
- dependencies.push([IRemoteRegisterFunctionService, { useFactory: () => toModule(rpcChannelService.requestChannel(RemoteRegisterFunctionServiceName)) }]);
3433
+ dependencies.push([IRemoteRegisterFunctionService, { useFactory: function createChannelService() {
3434
+ return toModule(rpcChannelService.requestChannel(RemoteRegisterFunctionServiceName));
3435
+ } }]);
3556
3436
  }
3557
3437
  dependencies.forEach((dependency) => j.add(dependency));
3558
3438
  if ((_this$_config$descrip = this._config.description) === null || _this$_config$descrip === void 0 ? void 0 : _this$_config$descrip.length) this.disposeWithMe(j.get(IDescriptionService).registerDescriptions(this._config.description));
@@ -3587,8 +3467,7 @@ UniverSheetsFormulaPlugin = __decorate([
3587
3467
  __decorateParam(2, IConfigService)
3588
3468
  ], UniverSheetsFormulaPlugin);
3589
3469
 
3590
- //#endregion
3591
- //#region src/util/calculate.ts
3470
+ // src/util/calculate.ts
3592
3471
  function calculateFormula(inject, formulaString, unitId, sheetData) {
3593
3472
  const formulaCurrentConfigService = inject.get(IFormulaCurrentConfigService);
3594
3473
  const lexer = inject.get(Lexer);
@@ -3613,5 +3492,4 @@ function calculateFormula(inject, formulaString, unitId, sheetData) {
3613
3492
  return getObjectValue(result);
3614
3493
  }
3615
3494
 
3616
- //#endregion
3617
3495
  export { CalculationMode, FormulaAutoFillController, FormulaRefRangeService, FormulaReorderController, IRemoteRegisterFunctionService, ImageFormulaCellInterceptorController, InsertFunctionCommand, PLUGIN_CONFIG_KEY_BASE, RemoteRegisterFunctionService, TriggerCalculationController, UnitQualifierRenameController, UniverRemoteSheetsFormulaPlugin, UniverSheetsFormulaPlugin, UpdateDefinedNameController, UpdateFormulaController, calculateFormula, collectUnitQualifierFormulaPatches };