@univerjs/sheets-formula 1.3.1 → 1.5.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 (79) hide show
  1. package/README.md +19 -7
  2. package/lib/cjs/facade.js +4 -9
  3. package/lib/cjs/index.js +436 -490
  4. package/lib/cjs/locale/ar-SA.js +1 -2
  5. package/lib/cjs/locale/ca-ES.js +1 -2
  6. package/lib/cjs/locale/de-DE.js +1 -2
  7. package/lib/cjs/locale/en-US.js +1 -2
  8. package/lib/cjs/locale/es-ES.js +1 -2
  9. package/lib/cjs/locale/fa-IR.js +1 -2
  10. package/lib/cjs/locale/fr-FR.js +1 -2
  11. package/lib/cjs/locale/id-ID.js +1 -2
  12. package/lib/cjs/locale/it-IT.js +1 -2
  13. package/lib/cjs/locale/ja-JP.js +1 -2
  14. package/lib/cjs/locale/ko-KR.js +1 -2
  15. package/lib/cjs/locale/pl-PL.js +1 -2
  16. package/lib/cjs/locale/pt-BR.js +1 -2
  17. package/lib/cjs/locale/ru-RU.js +1 -2
  18. package/lib/cjs/locale/sk-SK.js +1 -2
  19. package/lib/cjs/locale/vi-VN.js +1 -2
  20. package/lib/cjs/locale/zh-CN.js +1 -2
  21. package/lib/cjs/locale/zh-HK.js +1 -2
  22. package/lib/cjs/locale/zh-TW.js +1 -2
  23. package/lib/cjs/remote-register-function.service-D0P1G4Uh.js +212 -0
  24. package/lib/cjs/worker.js +52 -0
  25. package/lib/es/facade.js +4 -8
  26. package/lib/es/index.js +353 -401
  27. package/lib/es/locale/ar-SA.js +1 -2
  28. package/lib/es/locale/ca-ES.js +1 -2
  29. package/lib/es/locale/de-DE.js +1 -2
  30. package/lib/es/locale/en-US.js +1 -2
  31. package/lib/es/locale/es-ES.js +1 -2
  32. package/lib/es/locale/fa-IR.js +1 -2
  33. package/lib/es/locale/fr-FR.js +1 -2
  34. package/lib/es/locale/id-ID.js +1 -2
  35. package/lib/es/locale/it-IT.js +1 -2
  36. package/lib/es/locale/ja-JP.js +1 -2
  37. package/lib/es/locale/ko-KR.js +1 -2
  38. package/lib/es/locale/pl-PL.js +1 -2
  39. package/lib/es/locale/pt-BR.js +1 -2
  40. package/lib/es/locale/ru-RU.js +1 -2
  41. package/lib/es/locale/sk-SK.js +1 -2
  42. package/lib/es/locale/vi-VN.js +1 -2
  43. package/lib/es/locale/zh-CN.js +1 -2
  44. package/lib/es/locale/zh-HK.js +1 -2
  45. package/lib/es/locale/zh-TW.js +1 -2
  46. package/lib/es/remote-register-function.service-CaKs4mpz.js +135 -0
  47. package/lib/es/worker.js +46 -0
  48. package/lib/facade.js +4 -8
  49. package/lib/index.js +353 -401
  50. package/lib/locale/ar-SA.js +1 -2
  51. package/lib/locale/ca-ES.js +1 -2
  52. package/lib/locale/de-DE.js +1 -2
  53. package/lib/locale/en-US.js +1 -2
  54. package/lib/locale/es-ES.js +1 -2
  55. package/lib/locale/fa-IR.js +1 -2
  56. package/lib/locale/fr-FR.js +1 -2
  57. package/lib/locale/id-ID.js +1 -2
  58. package/lib/locale/it-IT.js +1 -2
  59. package/lib/locale/ja-JP.js +1 -2
  60. package/lib/locale/ko-KR.js +1 -2
  61. package/lib/locale/pl-PL.js +1 -2
  62. package/lib/locale/pt-BR.js +1 -2
  63. package/lib/locale/ru-RU.js +1 -2
  64. package/lib/locale/sk-SK.js +1 -2
  65. package/lib/locale/vi-VN.js +1 -2
  66. package/lib/locale/zh-CN.js +1 -2
  67. package/lib/locale/zh-HK.js +1 -2
  68. package/lib/locale/zh-TW.js +1 -2
  69. package/lib/remote-register-function.service-CaKs4mpz.js +135 -0
  70. package/lib/types/controllers/trigger-calculation.controller.d.ts +2 -0
  71. package/lib/types/controllers/update-formula.controller.d.ts +4 -0
  72. package/lib/types/index.d.ts +1 -1
  73. package/lib/types/plugin.d.ts +1 -12
  74. package/lib/types/services/formula-ref-range.service.d.ts +8 -0
  75. package/lib/types/services/remote/remote-register-function.service.d.ts +1 -1
  76. package/lib/types/worker.d.ts +28 -0
  77. package/lib/umd/index.js +1 -1
  78. package/lib/worker.js +46 -0
  79. package/package.json +17 -12
package/lib/cjs/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_remote_register_function_service = require("./remote-register-function.service-D0P1G4Uh.js");
2
3
  let _univerjs_core = require("@univerjs/core");
3
4
  let _univerjs_sheets = require("@univerjs/sheets");
4
5
  let _univerjs_engine_formula = require("@univerjs/engine-formula");
@@ -6,7 +7,7 @@ let _univerjs_docs = require("@univerjs/docs");
6
7
  let rxjs = require("rxjs");
7
8
  let _univerjs_rpc = require("@univerjs/rpc");
8
9
 
9
- //#region src/commands/commands/insert-function.command.ts
10
+ // src/commands/commands/insert-function.command.ts
10
11
  const InsertFunctionCommand = {
11
12
  id: "formula.command.insert-function",
12
13
  type: _univerjs_core.CommandType.COMMAND,
@@ -34,60 +35,7 @@ const InsertFunctionCommand = {
34
35
  }
35
36
  };
36
37
 
37
- //#endregion
38
- //#region src/config/config.ts
39
- /**
40
- * Base configuration for the plugin.
41
- */
42
- const PLUGIN_CONFIG_KEY_BASE = "sheets-formula.base.config";
43
- const configSymbolBase = Symbol(PLUGIN_CONFIG_KEY_BASE);
44
- let CalculationMode = /* @__PURE__ */ function(CalculationMode) {
45
- /**
46
- * Force calculation of all formulas
47
- */
48
- CalculationMode[CalculationMode["FORCED"] = 0] = "FORCED";
49
- /**
50
- * Partial calculation, only cells with formulas but no v values are calculated
51
- */
52
- CalculationMode[CalculationMode["WHEN_EMPTY"] = 1] = "WHEN_EMPTY";
53
- /**
54
- * All formulas are not calculated
55
- */
56
- CalculationMode[CalculationMode["NO_CALCULATION"] = 2] = "NO_CALCULATION";
57
- return CalculationMode;
58
- }({});
59
- const defaultPluginBaseConfig = {};
60
- /**
61
- * Remote configuration for the plugin.
62
- */
63
- const PLUGIN_CONFIG_KEY_REMOTE = "sheets-formula.remote.config";
64
- const configSymbolRemote = Symbol(PLUGIN_CONFIG_KEY_REMOTE);
65
- const defaultPluginRemoteConfig = {};
66
- /**
67
- * Mobile configuration for the plugin.
68
- */
69
- const PLUGIN_CONFIG_KEY_MOBILE = "sheets-formula.mobile.config";
70
- const configSymbolMobile = Symbol(PLUGIN_CONFIG_KEY_MOBILE);
71
-
72
- //#endregion
73
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
74
- function __decorateParam(paramIndex, decorator) {
75
- return function(target, key) {
76
- decorator(target, key, paramIndex);
77
- };
78
- }
79
-
80
- //#endregion
81
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
82
- function __decorate(decorators, target, key, desc) {
83
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
84
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
85
- 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;
86
- return c > 3 && r && Object.defineProperty(target, key, r), r;
87
- }
88
-
89
- //#endregion
90
- //#region src/controllers/formula-auto-fill.controller.ts
38
+ // src/controllers/formula-auto-fill.controller.ts
91
39
  let FormulaAutoFillController = class FormulaAutoFillController extends _univerjs_core.Disposable {
92
40
  constructor(_autoFillService, _lexerTreeBuilder) {
93
41
  super();
@@ -157,7 +105,7 @@ let FormulaAutoFillController = class FormulaAutoFillController extends _univerj
157
105
  return applyData;
158
106
  }
159
107
  };
160
- FormulaAutoFillController = __decorate([__decorateParam(0, _univerjs_sheets.IAutoFillService), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder))], FormulaAutoFillController);
108
+ FormulaAutoFillController = require_remote_register_function_service.__decorate([require_remote_register_function_service.__decorateParam(0, _univerjs_sheets.IAutoFillService), require_remote_register_function_service.__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder))], FormulaAutoFillController);
161
109
  function directionToOffset(step, len, direction, location, sourceIndex) {
162
110
  const { source, target } = location;
163
111
  const { rows: targetRows } = target;
@@ -189,8 +137,7 @@ function getDataLength(copyDataPiece) {
189
137
  return length;
190
138
  }
191
139
 
192
- //#endregion
193
- //#region src/controllers/formula-reorder.controller.ts
140
+ // src/controllers/formula-reorder.controller.ts
194
141
  let FormulaReorderController = class FormulaReorderController extends _univerjs_core.Disposable {
195
142
  constructor(_sheetInterceptorService, _univerInstanceService, _formulaDataModel, _lexerTreeBuilder) {
196
143
  super();
@@ -264,68 +211,25 @@ let FormulaReorderController = class FormulaReorderController extends _univerjs_
264
211
  };
265
212
  }
266
213
  };
267
- FormulaReorderController = __decorate([
268
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
269
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService)),
270
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel)),
271
- __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder))
214
+ FormulaReorderController = require_remote_register_function_service.__decorate([
215
+ require_remote_register_function_service.__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
216
+ require_remote_register_function_service.__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService)),
217
+ require_remote_register_function_service.__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel)),
218
+ require_remote_register_function_service.__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder))
272
219
  ], FormulaReorderController);
273
220
 
274
- //#endregion
275
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
276
- function _typeof(o) {
277
- "@babel/helpers - typeof";
278
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
279
- return typeof o;
280
- } : function(o) {
281
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
282
- }, _typeof(o);
283
- }
284
-
285
- //#endregion
286
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
287
- function toPrimitive(t, r) {
288
- if ("object" != _typeof(t) || !t) return t;
289
- var e = t[Symbol.toPrimitive];
290
- if (void 0 !== e) {
291
- var i = e.call(t, r || "default");
292
- if ("object" != _typeof(i)) return i;
293
- throw new TypeError("@@toPrimitive must return a primitive value.");
294
- }
295
- return ("string" === r ? String : Number)(t);
296
- }
297
-
298
- //#endregion
299
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
300
- function toPropertyKey(t) {
301
- var i = toPrimitive(t, "string");
302
- return "symbol" == _typeof(i) ? i : i + "";
303
- }
304
-
305
- //#endregion
306
- //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
307
- function _defineProperty(e, r, t) {
308
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
309
- value: t,
310
- enumerable: !0,
311
- configurable: !0,
312
- writable: !0
313
- }) : e[r] = t, e;
314
- }
315
-
316
- //#endregion
317
- //#region src/controllers/image-formula-cell-interceptor.controller.ts
221
+ // src/controllers/image-formula-cell-interceptor.controller.ts
318
222
  let ImageFormulaCellInterceptorController = class ImageFormulaCellInterceptorController extends _univerjs_core.Disposable {
319
223
  constructor(_commandService, _sheetInterceptorService, _formulaDataModel) {
320
224
  super();
321
225
  this._commandService = _commandService;
322
226
  this._sheetInterceptorService = _sheetInterceptorService;
323
227
  this._formulaDataModel = _formulaDataModel;
324
- _defineProperty(this, "_errorValueCell", {
228
+ require_remote_register_function_service._defineProperty(this, "_errorValueCell", {
325
229
  v: _univerjs_engine_formula.ErrorType.VALUE,
326
230
  t: _univerjs_core.CellValueType.STRING
327
231
  });
328
- _defineProperty(this, "_refreshRender", void 0);
232
+ require_remote_register_function_service._defineProperty(this, "_refreshRender", void 0);
329
233
  this._initialize();
330
234
  }
331
235
  _initialize() {
@@ -451,14 +355,13 @@ let ImageFormulaCellInterceptorController = class ImageFormulaCellInterceptorCon
451
355
  this._refreshRender = refreshRender;
452
356
  }
453
357
  };
454
- ImageFormulaCellInterceptorController = __decorate([
455
- __decorateParam(0, _univerjs_core.ICommandService),
456
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
457
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel))
358
+ ImageFormulaCellInterceptorController = require_remote_register_function_service.__decorate([
359
+ require_remote_register_function_service.__decorateParam(0, _univerjs_core.ICommandService),
360
+ require_remote_register_function_service.__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
361
+ require_remote_register_function_service.__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel))
458
362
  ], ImageFormulaCellInterceptorController);
459
363
 
460
- //#endregion
461
- //#region src/controllers/trigger-calculation.controller.ts
364
+ // src/controllers/trigger-calculation.controller.ts
462
365
  const NilProgress = {
463
366
  done: 0,
464
367
  count: 0
@@ -505,12 +408,12 @@ let TriggerCalculationController = class TriggerCalculationController extends _u
505
408
  this._configService = _configService;
506
409
  this._formulaDataModel = _formulaDataModel;
507
410
  this._localeService = _localeService;
508
- _defineProperty(this, "_startExecutionTime", 0);
509
- _defineProperty(this, "_totalCalculationTaskCount", 0);
510
- _defineProperty(this, "_doneCalculationTaskCount", 0);
511
- _defineProperty(this, "_executionInProgressParams", null);
512
- _defineProperty(this, "_progress$", new rxjs.BehaviorSubject(NilProgress));
513
- _defineProperty(this, "progress$", this._progress$.asObservable());
411
+ require_remote_register_function_service._defineProperty(this, "_startExecutionTime", 0);
412
+ require_remote_register_function_service._defineProperty(this, "_totalCalculationTaskCount", 0);
413
+ require_remote_register_function_service._defineProperty(this, "_doneCalculationTaskCount", 0);
414
+ require_remote_register_function_service._defineProperty(this, "_executionInProgressParams", null);
415
+ require_remote_register_function_service._defineProperty(this, "_progress$", new rxjs.BehaviorSubject(NilProgress));
416
+ require_remote_register_function_service._defineProperty(this, "progress$", this._progress$.asObservable());
514
417
  this._commandExecutedListener();
515
418
  this._initialExecuteFormulaProcessListener();
516
419
  this._initialExecuteFormula();
@@ -524,7 +427,7 @@ let TriggerCalculationController = class TriggerCalculationController extends _u
524
427
  this._progress$.complete();
525
428
  }
526
429
  _getCalculationMode() {
527
- const config = this._configService.getConfig(PLUGIN_CONFIG_KEY_BASE);
430
+ const config = this._configService.getConfig(require_remote_register_function_service.PLUGIN_CONFIG_KEY_BASE);
528
431
  return (config === null || config === void 0 ? void 0 : config.initialFormulaComputing) ?? 1;
529
432
  }
530
433
  _commandExecutedListener() {
@@ -540,6 +443,12 @@ let TriggerCalculationController = class TriggerCalculationController extends _u
540
443
  _initialExecuteFormulaProcessListener() {
541
444
  let startDependencyTimer = null;
542
445
  let calculationProcessCount = 0;
446
+ this.disposeWithMe(() => {
447
+ if (startDependencyTimer !== null) {
448
+ clearTimeout(startDependencyTimer);
449
+ startDependencyTimer = null;
450
+ }
451
+ });
543
452
  this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
544
453
  if (command.id === _univerjs_engine_formula.SetFormulaCalculationStopMutation.id) this.clearProgress();
545
454
  if (command.id !== _univerjs_engine_formula.SetFormulaCalculationNotificationMutation.id) return;
@@ -558,43 +467,11 @@ let TriggerCalculationController = class TriggerCalculationController extends _u
558
467
  startDependencyTimer = null;
559
468
  this._startProgress();
560
469
  }, 1e3);
561
- } else if (stage === _univerjs_engine_formula.FormulaExecuteStageType.CURRENTLY_CALCULATING) {
562
- this._executionInProgressParams = params.stageInfo;
563
- if (startDependencyTimer === null) {
564
- const calculating = this._localeService.t("sheets-formula.progress.calculating");
565
- this._calculateProgress(calculating);
566
- }
567
- } else if (stage === _univerjs_engine_formula.FormulaExecuteStageType.START_DEPENDENCY_ARRAY_FORMULA) {
568
- this._executionInProgressParams = params.stageInfo;
569
- if (startDependencyTimer === null) {
570
- const arrayAnalysis = this._localeService.t("sheets-formula.progress.array-analysis");
571
- this._calculateProgress(arrayAnalysis);
572
- }
573
- } else if (stage === _univerjs_engine_formula.FormulaExecuteStageType.CURRENTLY_CALCULATING_ARRAY_FORMULA) {
574
- this._executionInProgressParams = params.stageInfo;
575
- if (startDependencyTimer === null) {
576
- const arrayCalculation = this._localeService.t("sheets-formula.progress.array-calculation");
577
- this._calculateProgress(arrayCalculation);
578
- }
579
- }
470
+ } else this._updateCalculationProgress(params.stageInfo, startDependencyTimer === null);
580
471
  } else {
581
472
  const state = params.functionsExecutedState;
582
- let result = "";
583
- calculationProcessCount--;
584
- switch (state) {
585
- case _univerjs_engine_formula.FormulaExecutedStateType.NOT_EXECUTED:
586
- result = "No tasks are being executed anymore";
587
- break;
588
- case _univerjs_engine_formula.FormulaExecutedStateType.STOP_EXECUTION:
589
- result = "The execution of the formula has been stopped";
590
- calculationProcessCount = 0;
591
- break;
592
- case _univerjs_engine_formula.FormulaExecutedStateType.SUCCESS:
593
- result = "Formula calculation succeeded";
594
- if (calculationProcessCount === 0 || calculationProcessCount === -1) result += `. Total time consumed: ${performance.now() - this._startExecutionTime} ms`;
595
- break;
596
- case _univerjs_engine_formula.FormulaExecutedStateType.INITIAL: result = "Waiting for calculation";
597
- }
473
+ calculationProcessCount = state === _univerjs_engine_formula.FormulaExecutedStateType.STOP_EXECUTION ? 0 : calculationProcessCount - 1;
474
+ const result = this._getCalculationResultMessage(state, calculationProcessCount);
598
475
  if (calculationProcessCount === 0 || calculationProcessCount === -1) {
599
476
  if (startDependencyTimer) {
600
477
  clearTimeout(startDependencyTimer);
@@ -610,6 +487,34 @@ let TriggerCalculationController = class TriggerCalculationController extends _u
610
487
  }
611
488
  }));
612
489
  }
490
+ _updateCalculationProgress(stageInfo, showProgress) {
491
+ let label;
492
+ switch (stageInfo.stage) {
493
+ case _univerjs_engine_formula.FormulaExecuteStageType.CURRENTLY_CALCULATING:
494
+ label = "sheets-formula.progress.calculating";
495
+ break;
496
+ case _univerjs_engine_formula.FormulaExecuteStageType.START_DEPENDENCY_ARRAY_FORMULA:
497
+ label = "sheets-formula.progress.array-analysis";
498
+ break;
499
+ case _univerjs_engine_formula.FormulaExecuteStageType.CURRENTLY_CALCULATING_ARRAY_FORMULA:
500
+ label = "sheets-formula.progress.array-calculation";
501
+ break;
502
+ default: return;
503
+ }
504
+ this._executionInProgressParams = stageInfo;
505
+ if (showProgress) this._calculateProgress(this._localeService.t(label));
506
+ }
507
+ _getCalculationResultMessage(state, calculationProcessCount) {
508
+ switch (state) {
509
+ case _univerjs_engine_formula.FormulaExecutedStateType.NOT_EXECUTED: return "No tasks are being executed anymore";
510
+ case _univerjs_engine_formula.FormulaExecutedStateType.STOP_EXECUTION: return "The execution of the formula has been stopped";
511
+ case _univerjs_engine_formula.FormulaExecutedStateType.SUCCESS:
512
+ if (calculationProcessCount === 0 || calculationProcessCount === -1) return `Formula calculation succeeded. Total time consumed: ${performance.now() - this._startExecutionTime} ms`;
513
+ return "Formula calculation succeeded";
514
+ case _univerjs_engine_formula.FormulaExecutedStateType.INITIAL: return "Waiting for calculation";
515
+ default: return "";
516
+ }
517
+ }
613
518
  _initialExecuteFormula() {
614
519
  const calculationMode = this._getCalculationMode();
615
520
  if (calculationMode !== 2) {
@@ -630,17 +535,16 @@ let TriggerCalculationController = class TriggerCalculationController extends _u
630
535
  };
631
536
  }
632
537
  };
633
- TriggerCalculationController = __decorate([
634
- __decorateParam(0, _univerjs_core.ICommandService),
635
- __decorateParam(1, _univerjs_core.IUniverInstanceService),
636
- __decorateParam(2, _univerjs_core.ILogService),
637
- __decorateParam(3, _univerjs_core.IConfigService),
638
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel)),
639
- __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService))
538
+ TriggerCalculationController = require_remote_register_function_service.__decorate([
539
+ require_remote_register_function_service.__decorateParam(0, _univerjs_core.ICommandService),
540
+ require_remote_register_function_service.__decorateParam(1, _univerjs_core.IUniverInstanceService),
541
+ require_remote_register_function_service.__decorateParam(2, _univerjs_core.ILogService),
542
+ require_remote_register_function_service.__decorateParam(3, _univerjs_core.IConfigService),
543
+ require_remote_register_function_service.__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel)),
544
+ require_remote_register_function_service.__decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService))
640
545
  ], TriggerCalculationController);
641
546
 
642
- //#endregion
643
- //#region src/controllers/unit-qualifier-rename.controller.ts
547
+ // src/controllers/unit-qualifier-rename.controller.ts
644
548
  function collectUnitQualifierFormulaPatches(workbook, oldName, newName) {
645
549
  const unitId = workbook.getUnitId();
646
550
  return workbook.getSheets().flatMap((sheet) => {
@@ -665,7 +569,7 @@ let UnitQualifierRenameController = class UnitQualifierRenameController extends
665
569
  this._undoRedoService = _undoRedoService;
666
570
  this._univerInstanceService = _univerInstanceService;
667
571
  this._definedNamesService = _definedNamesService;
668
- _defineProperty(this, "_names", /* @__PURE__ */ new Map());
572
+ require_remote_register_function_service._defineProperty(this, "_names", /* @__PURE__ */ new Map());
669
573
  this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_BASE).forEach((unit) => this._watch(unit));
670
574
  this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_BASE).subscribe(({ unit }) => this._watch(unit)));
671
575
  this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_BASE).subscribe((unit) => this._names.delete(unit.getUnitId())));
@@ -732,15 +636,14 @@ let UnitQualifierRenameController = class UnitQualifierRenameController extends
732
636
  });
733
637
  }
734
638
  };
735
- UnitQualifierRenameController = __decorate([
736
- __decorateParam(0, _univerjs_core.ICommandService),
737
- __decorateParam(1, _univerjs_core.IUndoRedoService),
738
- __decorateParam(2, _univerjs_core.IUniverInstanceService),
739
- __decorateParam(3, _univerjs_engine_formula.IDefinedNamesService)
639
+ UnitQualifierRenameController = require_remote_register_function_service.__decorate([
640
+ require_remote_register_function_service.__decorateParam(0, _univerjs_core.ICommandService),
641
+ require_remote_register_function_service.__decorateParam(1, _univerjs_core.IUndoRedoService),
642
+ require_remote_register_function_service.__decorateParam(2, _univerjs_core.IUniverInstanceService),
643
+ require_remote_register_function_service.__decorateParam(3, _univerjs_engine_formula.IDefinedNamesService)
740
644
  ], UnitQualifierRenameController);
741
645
 
742
- //#endregion
743
- //#region src/controllers/utils/offset-formula-data.ts
646
+ // src/controllers/utils/offset-formula-data.ts
744
647
  function checkFormulaDataNull(formulaData, unitId, sheetId) {
745
648
  var _formulaData$unitId;
746
649
  if (formulaData == null || formulaData[unitId] == null || ((_formulaData$unitId = formulaData[unitId]) === null || _formulaData$unitId === void 0 ? void 0 : _formulaData$unitId[sheetId]) == null) return true;
@@ -759,8 +662,7 @@ function removeFormulaData(formulaData, unitId, sheetId) {
759
662
  }
760
663
  }
761
664
 
762
- //#endregion
763
- //#region src/controllers/utils/ref-range-formula.ts
665
+ // src/controllers/utils/ref-range-formula.ts
764
666
  const formulaReferenceSheetList = [
765
667
  11,
766
668
  12,
@@ -1231,8 +1133,7 @@ function updateRefOffset(sequenceNodes, refChangeIds, refOffsetX = 0, refOffsetY
1231
1133
  return newSequenceNodes;
1232
1134
  }
1233
1135
 
1234
- //#endregion
1235
- //#region src/controllers/utils/ref-range-move.ts
1136
+ // src/controllers/utils/ref-range-move.ts
1236
1137
  function getNewRangeByMoveParam(unitRangeWidthOffset, formulaReferenceMoveParam, currentFormulaUnitId, currentFormulaSheetId, options = {}) {
1237
1138
  const { type, unitId: userUnitId, sheetId: userSheetId, targetUnitId, targetSheetId, targetSheetName, range, from, to, rangeFilteredRows } = formulaReferenceMoveParam;
1238
1139
  const { range: unitRange, sheetId: sequenceRangeSheetId, unitId: sequenceRangeUnitId, sheetName: sequenceRangeSheetName, refOffsetX, refOffsetY } = unitRangeWidthOffset;
@@ -1557,8 +1458,7 @@ function getStartEndValue(range) {
1557
1458
  };
1558
1459
  }
1559
1460
 
1560
- //#endregion
1561
- //#region src/controllers/utils/ref-range-param.ts
1461
+ // src/controllers/utils/ref-range-param.ts
1562
1462
  const SET_SHEET_TABLE_COMMAND_ID = "sheet.command.set-table-config";
1563
1463
  const DELETE_SHEET_TABLE_COMMAND_ID = "sheet.command.delete-table";
1564
1464
  const REMOVE_SHEET_TABLE_COLUMN_AT_COMMAND_ID = "sheet.command.table-remove-column-at";
@@ -1912,8 +1812,7 @@ function handleRefRemoveSheetTableColumn(command, workbook) {
1912
1812
  };
1913
1813
  }
1914
1814
 
1915
- //#endregion
1916
- //#region src/controllers/update-defined-name.controller.ts
1815
+ // src/controllers/update-defined-name.controller.ts
1917
1816
  let UpdateDefinedNameController = class UpdateDefinedNameController extends _univerjs_core.Disposable {
1918
1817
  constructor(_definedNamesService, _univerInstanceService, _sheetInterceptorService, _lexerTreeBuilder) {
1919
1818
  super();
@@ -2055,15 +1954,14 @@ let UpdateDefinedNameController = class UpdateDefinedNameController extends _uni
2055
1954
  return null;
2056
1955
  }
2057
1956
  };
2058
- UpdateDefinedNameController = __decorate([
2059
- __decorateParam(0, _univerjs_engine_formula.IDefinedNamesService),
2060
- __decorateParam(1, _univerjs_core.IUniverInstanceService),
2061
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
2062
- __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder))
1957
+ UpdateDefinedNameController = require_remote_register_function_service.__decorate([
1958
+ require_remote_register_function_service.__decorateParam(0, _univerjs_engine_formula.IDefinedNamesService),
1959
+ require_remote_register_function_service.__decorateParam(1, _univerjs_core.IUniverInstanceService),
1960
+ require_remote_register_function_service.__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
1961
+ require_remote_register_function_service.__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder))
2063
1962
  ], UpdateDefinedNameController);
2064
1963
 
2065
- //#endregion
2066
- //#region src/controllers/update-formula.controller.ts
1964
+ // src/controllers/update-formula.controller.ts
2067
1965
  let UpdateFormulaController = class UpdateFormulaController extends _univerjs_core.Disposable {
2068
1966
  constructor(_univerInstanceService, _commandService, _lexerTreeBuilder, _formulaDataModel, _sheetInterceptorService, _definedNamesService, _configService, _injector) {
2069
1967
  super();
@@ -2096,12 +1994,30 @@ let UpdateFormulaController = class UpdateFormulaController extends _univerjs_co
2096
1994
  this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe((event) => this._handleWorkbookAdded(event.unit)));
2097
1995
  this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.map)((unit) => unit.getUnitId())).subscribe((unitId) => this._handleWorkbookDisposed(unitId)));
2098
1996
  }
1997
+ _getEditedArrayFormulaDirtyRanges(params) {
1998
+ var _this$_formulaDataMod;
1999
+ const { subUnitId: sheetId, unitId, cellValue } = params;
2000
+ const previousRanges = (_this$_formulaDataMod = this._formulaDataModel.getArrayFormulaRange()[unitId]) === null || _this$_formulaDataMod === void 0 ? void 0 : _this$_formulaDataMod[sheetId];
2001
+ const dirtyRanges = [];
2002
+ if (previousRanges) new _univerjs_core.ObjectMatrix(cellValue).forValue((row, column) => {
2003
+ var _previousRanges$row;
2004
+ const range = (_previousRanges$row = previousRanges[row]) === null || _previousRanges$row === void 0 ? void 0 : _previousRanges$row[column];
2005
+ if (range && (range.startRow !== range.endRow || range.startColumn !== range.endColumn)) dirtyRanges.push({
2006
+ unitId,
2007
+ sheetId,
2008
+ range
2009
+ });
2010
+ });
2011
+ return dirtyRanges;
2012
+ }
2099
2013
  _handleSetRangeValuesMutation(params) {
2100
2014
  const { subUnitId: sheetId, unitId, cellValue } = params;
2101
2015
  if (cellValue == null) return;
2016
+ const dirtyRanges = this._getEditedArrayFormulaDirtyRanges(params);
2102
2017
  const newSheetFormulaData = this._formulaDataModel.updateFormulaData(unitId, sheetId, cellValue);
2103
2018
  const arrayFormulaCellDataChanged = this._formulaDataModel.updateArrayFormulaCellData(unitId, sheetId, cellValue);
2104
2019
  const arrayFormulaRangeChanged = this._formulaDataModel.updateArrayFormulaRange(unitId, sheetId, cellValue);
2020
+ if (dirtyRanges.length > 0) this._commandService.syncExecuteCommand(_univerjs_engine_formula.SetTriggerFormulaCalculationStartMutation.id, { dirtyRanges }, { onlyLocal: true });
2105
2021
  if (Object.keys(newSheetFormulaData).length === 0) {
2106
2022
  if (arrayFormulaCellDataChanged || arrayFormulaRangeChanged) this._commandService.executeCommand(_univerjs_engine_formula.SetArrayFormulaDataMutation.id, {
2107
2023
  arrayFormulaRange: this._formulaDataModel.getArrayFormulaRange(),
@@ -2165,7 +2081,7 @@ let UpdateFormulaController = class UpdateFormulaController extends _univerjs_co
2165
2081
  newFormulaData[unitId][sheetId] = (_currentSheetData$uni = currentSheetData[unitId]) === null || _currentSheetData$uni === void 0 ? void 0 : _currentSheetData$uni[sheetId];
2166
2082
  });
2167
2083
  this._commandService.executeCommand(_univerjs_engine_formula.SetFormulaDataMutation.id, { formulaData: newFormulaData }, { onlyLocal: true });
2168
- const config = this._configService.getConfig(PLUGIN_CONFIG_KEY_BASE);
2084
+ const config = this._configService.getConfig(require_remote_register_function_service.PLUGIN_CONFIG_KEY_BASE);
2169
2085
  const calculationMode = (config === null || config === void 0 ? void 0 : config.initialFormulaComputing) ?? 1;
2170
2086
  if (calculationMode === 2) return;
2171
2087
  const params = this._getDirtyDataByCalculationMode(calculationMode);
@@ -2213,187 +2129,221 @@ let UpdateFormulaController = class UpdateFormulaController extends _univerjs_co
2213
2129
  const formulaDataKeys = Object.keys(formulaData);
2214
2130
  if (formulaDataKeys.length === 0) return { newFormulaData: {} };
2215
2131
  const newFormulaData = Object.create(null);
2216
- const { unitId: fromUnitId, sheetId: fromSheetId, sheetName: fromSheetName, targetUnitId, targetSheetId, type, from, to } = formulaReferenceMoveParam;
2217
2132
  const inCrossSheetCutRangeNewFormulas = [];
2133
+ const { type, unitId: affectedUnitId, sheetId: affectedSheetId } = formulaReferenceMoveParam;
2134
+ const isRemovingSheet = type === 13;
2218
2135
  for (const unitId of formulaDataKeys) {
2219
2136
  const sheetData = formulaData[unitId];
2220
2137
  if (sheetData == null) continue;
2221
2138
  const sheetDataKeys = Object.keys(sheetData);
2222
2139
  if (!_univerjs_core.Tools.isDefine(newFormulaData[unitId])) newFormulaData[unitId] = Object.create(null);
2223
2140
  for (const sheetId of sheetDataKeys) {
2141
+ if (isRemovingSheet && unitId === affectedUnitId && sheetId === affectedSheetId) continue;
2224
2142
  const matrixData = new _univerjs_core.ObjectMatrix(sheetData[sheetId] || {});
2225
2143
  const newFormulaDataItem = new _univerjs_core.ObjectMatrix();
2226
- const shouldModifySi = [];
2144
+ const context = {
2145
+ unitId,
2146
+ sheetId,
2147
+ unitSheetNameMap,
2148
+ params: formulaReferenceMoveParam,
2149
+ modifiedSharedFormulaIds: []
2150
+ };
2227
2151
  matrixData.forValue((row, column, formulaDataItem) => {
2228
- if (!formulaDataItem) return true;
2229
- const { f: formulaString, x, y, si } = formulaDataItem;
2230
- if (type === 12) {
2231
- const { oldUnitName, unitName } = formulaReferenceMoveParam;
2232
- if (!oldUnitName || !unitName) return true;
2233
- const nextFormula = (0, _univerjs_engine_formula.refactorFormulaUnitQualifier)(formulaString, oldUnitName, unitName);
2234
- if (nextFormula !== formulaString) newFormulaDataItem.setValue(row, column, { f: nextFormula });
2235
- return true;
2236
- }
2237
- const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);
2238
- if (sequenceNodes == null) return true;
2239
- let shouldModify = false;
2240
- const refChangeIds = [];
2241
- 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;
2242
- const inCrossSheetCutRangeSequenceNodes = [...sequenceNodes];
2243
- for (let i = 0, len = sequenceNodes.length; i < len; i++) {
2244
- var _unitSheetNameMap$map;
2245
- const node = sequenceNodes[i];
2246
- if (typeof node === "string") continue;
2247
- const { token, nodeType } = node;
2248
- if ((type === 14 || type === 15) && (nodeType === _univerjs_engine_formula.sequenceNodeType.DEFINED_NAME || nodeType === _univerjs_engine_formula.sequenceNodeType.FUNCTION)) {
2249
- const { definedNameId, definedName } = formulaReferenceMoveParam;
2250
- if (definedNameId === void 0 || definedName === void 0) continue;
2251
- const oldDefinedName = this._definedNamesService.getValueById(unitId, definedNameId);
2252
- if (oldDefinedName === void 0 || oldDefinedName === null) continue;
2253
- if (oldDefinedName.name !== token) continue;
2254
- sequenceNodes[i] = {
2255
- ...node,
2256
- token: type === 14 ? definedName : _univerjs_engine_formula.ErrorType.REF
2257
- };
2258
- shouldModify = true;
2259
- refChangeIds.push(i);
2260
- continue;
2261
- } else if ((type === 16 || type === 17 || type === 18) && (nodeType === _univerjs_engine_formula.sequenceNodeType.TABLE || nodeType === _univerjs_engine_formula.sequenceNodeType.FUNCTION)) {
2262
- const { oldTableName, tableName, tableColumnNames } = formulaReferenceMoveParam;
2263
- if (oldTableName === void 0 || type === 16 && tableName === void 0) continue;
2264
- const { tableName: tokenTableName, columnStruct = "" } = (0, _univerjs_engine_formula.splitTableStructuredRef)(token);
2265
- if (tokenTableName !== oldTableName) continue;
2266
- if (type === 18 && !tableReferenceContainsColumn(columnStruct, tableColumnNames)) continue;
2267
- sequenceNodes[i] = {
2268
- ...node,
2269
- token: type === 16 ? `${tableName}${columnStruct}` : _univerjs_engine_formula.ErrorType.REF
2270
- };
2271
- const nextNode = sequenceNodes[i + 1];
2272
- if ((type === 17 || type === 18) && typeof nextNode === "string" && nextNode.startsWith("]")) sequenceNodes[i + 1] = nextNode.slice(1);
2273
- shouldModify = true;
2274
- refChangeIds.push(i);
2275
- continue;
2276
- } else if (nodeType !== _univerjs_engine_formula.sequenceNodeType.REFERENCE) continue;
2277
- const { range, sheetName, unitId: sequenceUnitId } = (0, _univerjs_engine_formula.deserializeRangeWithSheetWithCache)(token);
2278
- const mapUnitId = sequenceUnitId == null || sequenceUnitId.length === 0 ? unitId : sequenceUnitId;
2279
- const sequenceSheetId = (unitSheetNameMap === null || unitSheetNameMap === void 0 || (_unitSheetNameMap$map = unitSheetNameMap[mapUnitId]) === null || _unitSheetNameMap$map === void 0 ? void 0 : _unitSheetNameMap$map[sheetName]) || "";
2280
- if (!checkIsSameUnitAndSheet(formulaReferenceMoveParam.unitId, formulaReferenceMoveParam.sheetId, unitId, sheetId, sequenceUnitId, sequenceSheetId)) continue;
2281
- const sequenceUnitRangeWidthOffset = {
2282
- range,
2283
- sheetId: sequenceSheetId,
2284
- unitId: sequenceUnitId,
2285
- sheetName,
2286
- refOffsetX: x || 0,
2287
- refOffsetY: y || 0
2288
- };
2289
- let newRefString = null;
2290
- if (type === 11) {
2291
- const { unitId: userUnitId, sheetId: userSheetId, sheetName: newSheetName } = formulaReferenceMoveParam;
2292
- if (newSheetName == null) continue;
2293
- if (sequenceSheetId == null || sequenceSheetId.length === 0) continue;
2294
- if (userSheetId !== sequenceSheetId) continue;
2295
- newRefString = (0, _univerjs_engine_formula.serializeRangeToRefString)({
2296
- range,
2297
- sheetName: newSheetName,
2298
- unitId: sequenceUnitId
2299
- });
2300
- } else if (type === 13) {
2301
- const { unitId: userUnitId, sheetId: userSheetId, sheetName: newSheetName } = formulaReferenceMoveParam;
2302
- if (sequenceSheetId == null || sequenceSheetId.length === 0) continue;
2303
- if (userSheetId !== sequenceSheetId) continue;
2304
- newRefString = _univerjs_engine_formula.ErrorType.REF;
2305
- } else if (type !== 14) newRefString = getNewRangeByMoveParam(sequenceUnitRangeWidthOffset, formulaReferenceMoveParam, unitId, sheetId, { inCrossSheetCutRange });
2306
- if (newRefString != null) {
2307
- sequenceNodes[i] = {
2308
- ...node,
2309
- token: newRefString
2310
- };
2311
- shouldModify = true;
2312
- refChangeIds.push(i);
2313
- if (si && (x ?? 0) === 0 && (y ?? 0) === 0) shouldModifySi.push(si);
2314
- }
2315
- /**
2316
- * 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.
2317
- * 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.
2318
- */
2319
- if (inCrossSheetCutRange) {
2320
- if (newRefString != null) inCrossSheetCutRangeSequenceNodes[i] = {
2321
- ...node,
2322
- token: newRefString
2323
- };
2324
- else if ((!sequenceUnitId || sequenceUnitId === fromUnitId) && (!sequenceSheetId || sequenceSheetId === fromSheetId)) {
2325
- /**
2326
- * 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.
2327
- * 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.
2328
- */
2329
- const sequenceRange = _univerjs_core.Rectangle.moveOffset(range, x || 0, y || 0);
2330
- inCrossSheetCutRangeSequenceNodes[i] = {
2331
- ...node,
2332
- token: (0, _univerjs_engine_formula.serializeRangeToRefString)({
2333
- range: sequenceRange,
2334
- sheetName: fromSheetName || sheetName,
2335
- unitId: targetUnitId !== fromUnitId ? fromUnitId : ""
2336
- })
2337
- };
2338
- shouldModify = true;
2339
- }
2340
- }
2341
- }
2342
- if (!shouldModify) {
2343
- /**
2344
- * 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.
2345
- * Or the source formula cell is in the moved range.
2346
- * This is to ensure that the si formula can be recalculated correctly after the move.
2347
- */
2348
- if (si && [
2349
- 1,
2350
- 2,
2351
- 0
2352
- ].includes(type)) {
2353
- if (from && from.startRow <= row && row <= from.endRow && from.startColumn <= column && column <= from.endColumn) {
2354
- if ((x ?? 0) === 0 && (y ?? 0) === 0) shouldModifySi.push(si);
2355
- } else if (!shouldModifySi.includes(si)) return true;
2356
- } else return true;
2357
- }
2358
- if (inCrossSheetCutRange) {
2359
- const newSequenceNodes = updateRefOffset(inCrossSheetCutRangeSequenceNodes, refChangeIds, x, y);
2360
- inCrossSheetCutRangeNewFormulas.push({
2361
- fromRow: row,
2362
- fromColumn: column,
2363
- formulaString: `=${(0, _univerjs_engine_formula.generateStringWithSequence)(newSequenceNodes)}`
2364
- });
2365
- return true;
2366
- }
2367
- const newSequenceNodes = updateRefOffset(sequenceNodes, refChangeIds, x, y);
2368
- newFormulaDataItem.setValue(row, column, { f: `=${(0, _univerjs_engine_formula.generateStringWithSequence)(newSequenceNodes)}` });
2152
+ const formula = this._getMovedFormula(formulaDataItem, row, column, context, inCrossSheetCutRangeNewFormulas);
2153
+ if (formula != null) newFormulaDataItem.setValue(row, column, { f: formula });
2369
2154
  });
2370
2155
  if (newFormulaData[unitId]) newFormulaData[unitId][sheetId] = newFormulaDataItem.clone();
2371
2156
  }
2372
2157
  }
2373
- if (inCrossSheetCutRangeNewFormulas.length > 0 && targetUnitId && targetSheetId) {
2374
- if (!newFormulaData[targetUnitId]) newFormulaData[targetUnitId] = Object.create(null);
2375
- if (!newFormulaData[targetUnitId][targetSheetId]) newFormulaData[targetUnitId][targetSheetId] = Object.create(null);
2376
- for (const newFormula of inCrossSheetCutRangeNewFormulas) {
2377
- const { fromRow, fromColumn, formulaString } = newFormula;
2378
- const targetRow = fromRow + (((to === null || to === void 0 ? void 0 : to.startRow) ?? 0) - ((from === null || from === void 0 ? void 0 : from.startRow) ?? 0));
2379
- const targetColumn = fromColumn + (((to === null || to === void 0 ? void 0 : to.startColumn) ?? 0) - ((from === null || from === void 0 ? void 0 : from.startColumn) ?? 0));
2380
- if (!newFormulaData[targetUnitId][targetSheetId][targetRow]) newFormulaData[targetUnitId][targetSheetId][targetRow] = Object.create(null);
2381
- newFormulaData[targetUnitId][targetSheetId][targetRow][targetColumn] = { f: formulaString };
2158
+ appendCrossSheetCutFormulas(newFormulaData, inCrossSheetCutRangeNewFormulas, formulaReferenceMoveParam);
2159
+ return { newFormulaData };
2160
+ }
2161
+ _getMovedFormula(item, row, column, context, crossSheetFormulas) {
2162
+ if (!item) return null;
2163
+ const { f: formulaString, x, y } = item;
2164
+ const { unitId, sheetId, params, modifiedSharedFormulaIds } = context;
2165
+ if (params.type === 12) {
2166
+ const { oldUnitName, unitName } = params;
2167
+ if (!oldUnitName || !unitName) return null;
2168
+ const nextFormula = (0, _univerjs_engine_formula.refactorFormulaUnitQualifier)(formulaString, oldUnitName, unitName);
2169
+ return nextFormula !== formulaString ? nextFormula : null;
2170
+ }
2171
+ const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);
2172
+ if (sequenceNodes == null) return null;
2173
+ const refChangeIds = [];
2174
+ const inCrossSheetCutRange = isInCrossSheetCutRange(unitId, sheetId, row, column, params);
2175
+ const crossSheetNodes = [...sequenceNodes];
2176
+ if (!this._updateFormulaReferenceNodes(sequenceNodes, item, context, refChangeIds, inCrossSheetCutRange ? crossSheetNodes : null) && !shouldUnpackSharedFormula(item, row, column, params, modifiedSharedFormulaIds)) return null;
2177
+ const newSequenceNodes = updateRefOffset(inCrossSheetCutRange ? crossSheetNodes : sequenceNodes, refChangeIds, x, y);
2178
+ const formula = `=${(0, _univerjs_engine_formula.generateStringWithSequence)(newSequenceNodes)}`;
2179
+ if (inCrossSheetCutRange) {
2180
+ crossSheetFormulas.push({
2181
+ fromRow: row,
2182
+ fromColumn: column,
2183
+ formulaString: formula
2184
+ });
2185
+ return null;
2186
+ }
2187
+ return formula;
2188
+ }
2189
+ _updateFormulaReferenceNodes(sequenceNodes, item, context, refChangeIds, crossSheetNodes) {
2190
+ const { unitId, sheetId, params, modifiedSharedFormulaIds } = context;
2191
+ const { x, y, si } = item;
2192
+ let shouldModify = false;
2193
+ for (let i = 0, len = sequenceNodes.length; i < len; i++) {
2194
+ const node = sequenceNodes[i];
2195
+ if (typeof node === "string") continue;
2196
+ const definedNameToken = this._getDefinedNameReferenceToken(node, unitId, params);
2197
+ if (definedNameToken != null) {
2198
+ sequenceNodes[i] = {
2199
+ ...node,
2200
+ token: definedNameToken
2201
+ };
2202
+ shouldModify = true;
2203
+ refChangeIds.push(i);
2204
+ continue;
2205
+ }
2206
+ if (updateTableReference(sequenceNodes, i, node, params)) {
2207
+ shouldModify = true;
2208
+ refChangeIds.push(i);
2209
+ continue;
2210
+ }
2211
+ if (node.nodeType !== _univerjs_engine_formula.sequenceNodeType.REFERENCE) continue;
2212
+ const reference = getReferenceWithOffset(node.token, item, context);
2213
+ if (reference == null) continue;
2214
+ const newRefString = getMovedReferenceToken(reference, params, unitId, sheetId, crossSheetNodes != null);
2215
+ if (newRefString != null) {
2216
+ sequenceNodes[i] = {
2217
+ ...node,
2218
+ token: newRefString
2219
+ };
2220
+ shouldModify = true;
2221
+ refChangeIds.push(i);
2222
+ if (si && (x ?? 0) === 0 && (y ?? 0) === 0) modifiedSharedFormulaIds.push(si);
2223
+ }
2224
+ if (crossSheetNodes != null) {
2225
+ const movedNode = getCrossSheetCutReference(node, reference, newRefString, params);
2226
+ if (movedNode != null) {
2227
+ crossSheetNodes[i] = movedNode;
2228
+ shouldModify = true;
2229
+ }
2382
2230
  }
2383
2231
  }
2384
- return { newFormulaData };
2232
+ return shouldModify;
2233
+ }
2234
+ _getDefinedNameReferenceToken(node, unitId, params) {
2235
+ const { type, definedNameId, definedName } = params;
2236
+ if (type !== 14 && type !== 15) return null;
2237
+ if (node.nodeType !== _univerjs_engine_formula.sequenceNodeType.DEFINED_NAME && node.nodeType !== _univerjs_engine_formula.sequenceNodeType.FUNCTION) return null;
2238
+ if (definedNameId === void 0 || definedName === void 0) return null;
2239
+ const oldDefinedName = this._definedNamesService.getValueById(unitId, definedNameId);
2240
+ if (oldDefinedName == null || oldDefinedName.name !== node.token) return null;
2241
+ return type === 14 ? definedName : _univerjs_engine_formula.ErrorType.REF;
2385
2242
  }
2386
2243
  };
2387
- UpdateFormulaController = __decorate([
2388
- __decorateParam(0, _univerjs_core.IUniverInstanceService),
2389
- __decorateParam(1, _univerjs_core.ICommandService),
2390
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder)),
2391
- __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel)),
2392
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
2393
- __decorateParam(5, _univerjs_engine_formula.IDefinedNamesService),
2394
- __decorateParam(6, _univerjs_core.IConfigService),
2395
- __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
2244
+ UpdateFormulaController = require_remote_register_function_service.__decorate([
2245
+ require_remote_register_function_service.__decorateParam(0, _univerjs_core.IUniverInstanceService),
2246
+ require_remote_register_function_service.__decorateParam(1, _univerjs_core.ICommandService),
2247
+ require_remote_register_function_service.__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder)),
2248
+ require_remote_register_function_service.__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel)),
2249
+ require_remote_register_function_service.__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
2250
+ require_remote_register_function_service.__decorateParam(5, _univerjs_engine_formula.IDefinedNamesService),
2251
+ require_remote_register_function_service.__decorateParam(6, _univerjs_core.IConfigService),
2252
+ require_remote_register_function_service.__decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
2396
2253
  ], UpdateFormulaController);
2254
+ function getReferenceWithOffset(token, item, context) {
2255
+ var _unitSheetNameMap$map;
2256
+ const { unitId, sheetId, unitSheetNameMap, params } = context;
2257
+ const { range, sheetName, unitId: sequenceUnitId } = (0, _univerjs_engine_formula.deserializeRangeWithSheetWithCache)(token);
2258
+ const mapUnitId = sequenceUnitId == null || sequenceUnitId.length === 0 ? unitId : sequenceUnitId;
2259
+ const sequenceSheetId = (unitSheetNameMap === null || unitSheetNameMap === void 0 || (_unitSheetNameMap$map = unitSheetNameMap[mapUnitId]) === null || _unitSheetNameMap$map === void 0 ? void 0 : _unitSheetNameMap$map[sheetName]) || "";
2260
+ if (!checkIsSameUnitAndSheet(params.unitId, params.sheetId, unitId, sheetId, sequenceUnitId, sequenceSheetId)) return null;
2261
+ return {
2262
+ range,
2263
+ sheetId: sequenceSheetId,
2264
+ unitId: sequenceUnitId,
2265
+ sheetName,
2266
+ refOffsetX: item.x || 0,
2267
+ refOffsetY: item.y || 0
2268
+ };
2269
+ }
2270
+ function appendCrossSheetCutFormulas(data, formulas, params) {
2271
+ const { targetUnitId, targetSheetId, from, to } = params;
2272
+ if (formulas.length === 0 || !targetUnitId || !targetSheetId) return;
2273
+ if (!data[targetUnitId]) data[targetUnitId] = Object.create(null);
2274
+ if (!data[targetUnitId][targetSheetId]) data[targetUnitId][targetSheetId] = Object.create(null);
2275
+ for (const { fromRow, fromColumn, formulaString } of formulas) {
2276
+ const targetRow = fromRow + (((to === null || to === void 0 ? void 0 : to.startRow) ?? 0) - ((from === null || from === void 0 ? void 0 : from.startRow) ?? 0));
2277
+ const targetColumn = fromColumn + (((to === null || to === void 0 ? void 0 : to.startColumn) ?? 0) - ((from === null || from === void 0 ? void 0 : from.startColumn) ?? 0));
2278
+ if (!data[targetUnitId][targetSheetId][targetRow]) data[targetUnitId][targetSheetId][targetRow] = Object.create(null);
2279
+ data[targetUnitId][targetSheetId][targetRow][targetColumn] = { f: formulaString };
2280
+ }
2281
+ }
2282
+ function isInCrossSheetCutRange(unitId, sheetId, row, column, params) {
2283
+ const { type, unitId: fromUnitId, sheetId: fromSheetId, targetUnitId, targetSheetId, from } = params;
2284
+ 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;
2285
+ }
2286
+ function updateTableReference(sequenceNodes, index, node, params) {
2287
+ const { type, oldTableName, tableName, tableColumnNames } = params;
2288
+ if (type !== 16 && type !== 17 && type !== 18) return false;
2289
+ if (node.nodeType !== _univerjs_engine_formula.sequenceNodeType.TABLE && node.nodeType !== _univerjs_engine_formula.sequenceNodeType.FUNCTION) return false;
2290
+ if (oldTableName === void 0 || type === 16 && tableName === void 0) return false;
2291
+ const { tableName: tokenTableName, columnStruct = "" } = (0, _univerjs_engine_formula.splitTableStructuredRef)(node.token);
2292
+ if (tokenTableName !== oldTableName) return false;
2293
+ if (type === 18 && !tableReferenceContainsColumn(columnStruct, tableColumnNames)) return false;
2294
+ sequenceNodes[index] = {
2295
+ ...node,
2296
+ token: type === 16 ? `${tableName}${columnStruct}` : _univerjs_engine_formula.ErrorType.REF
2297
+ };
2298
+ const nextNode = sequenceNodes[index + 1];
2299
+ if ((type === 17 || type === 18) && typeof nextNode === "string" && nextNode.startsWith("]")) sequenceNodes[index + 1] = nextNode.slice(1);
2300
+ return true;
2301
+ }
2302
+ function getMovedReferenceToken(reference, params, unitId, sheetId, inCrossSheetCutRange) {
2303
+ const { type, sheetId: affectedSheetId, sheetName } = params;
2304
+ if (type === 11 || type === 13) {
2305
+ if (!reference.sheetId || affectedSheetId !== reference.sheetId) return null;
2306
+ if (type === 13) return _univerjs_engine_formula.ErrorType.REF;
2307
+ if (sheetName == null) return null;
2308
+ return (0, _univerjs_engine_formula.serializeRangeToRefString)({
2309
+ range: reference.range,
2310
+ sheetName,
2311
+ unitId: reference.unitId
2312
+ });
2313
+ }
2314
+ if (type === 14) return null;
2315
+ return getNewRangeByMoveParam(reference, params, unitId, sheetId, { inCrossSheetCutRange });
2316
+ }
2317
+ function getCrossSheetCutReference(node, reference, newRefString, params) {
2318
+ if (newRefString != null) return {
2319
+ ...node,
2320
+ token: newRefString
2321
+ };
2322
+ const { unitId, sheetId, targetUnitId, sheetName } = params;
2323
+ if (reference.unitId && reference.unitId !== unitId || reference.sheetId && reference.sheetId !== sheetId) return null;
2324
+ return {
2325
+ ...node,
2326
+ token: (0, _univerjs_engine_formula.serializeRangeToRefString)({
2327
+ range: _univerjs_core.Rectangle.moveOffset(reference.range, reference.refOffsetX || 0, reference.refOffsetY || 0),
2328
+ sheetName: sheetName || reference.sheetName,
2329
+ unitId: targetUnitId !== unitId ? unitId : ""
2330
+ })
2331
+ };
2332
+ }
2333
+ function shouldUnpackSharedFormula(item, row, column, params, modifiedIds) {
2334
+ const { si, x, y } = item;
2335
+ const { type, from } = params;
2336
+ if (!si || ![
2337
+ 1,
2338
+ 2,
2339
+ 0
2340
+ ].includes(type)) return false;
2341
+ if (from && from.startRow <= row && row <= from.endRow && from.startColumn <= column && column <= from.endColumn) {
2342
+ if ((x ?? 0) === 0 && (y ?? 0) === 0) modifiedIds.push(si);
2343
+ return true;
2344
+ }
2345
+ return modifiedIds.includes(si);
2346
+ }
2397
2347
  /**
2398
2348
  * Whether to skip the formula update when the setRangeValues mutation is executed.
2399
2349
  * The style-only cell value does not affect the formula calculation, so it can be skipped.
@@ -2439,13 +2389,7 @@ function tableReferenceContainsColumn(columnStruct, columnNames) {
2439
2389
  return false;
2440
2390
  }
2441
2391
 
2442
- //#endregion
2443
- //#region package.json
2444
- var name = "@univerjs/sheets-formula";
2445
- var version = "1.3.1";
2446
-
2447
- //#endregion
2448
- //#region src/common/plugin-name.ts
2392
+ // src/common/plugin-name.ts
2449
2393
  /**
2450
2394
  * Copyright 2023-present DreamNum Co., Ltd.
2451
2395
  *
@@ -2463,8 +2407,7 @@ var version = "1.3.1";
2463
2407
  */
2464
2408
  const SHEETS_FORMULA_PLUGIN_NAME = "SHEETS_FORMULA_PLUGIN";
2465
2409
 
2466
- //#endregion
2467
- //#region src/controllers/active-dirty.controller.ts
2410
+ // src/controllers/active-dirty.controller.ts
2468
2411
  let ActiveDirtyController = class ActiveDirtyController extends _univerjs_core.Disposable {
2469
2412
  constructor(_activeDirtyManagerService, _univerInstanceService, _formulaDataModel) {
2470
2413
  super();
@@ -2547,6 +2490,10 @@ let ActiveDirtyController = class ActiveDirtyController extends _univerjs_core.D
2547
2490
  });
2548
2491
  }
2549
2492
  _initialRowAndColumn() {
2493
+ for (const mutation of [_univerjs_sheets.SetWorksheetRowCountMutation, _univerjs_sheets.SetWorksheetColumnCountMutation]) this._activeDirtyManagerService.register(mutation.id, {
2494
+ commandId: mutation.id,
2495
+ getDirtyData: (command) => ({ dirtyReferenceUnits: [command.params.unitId] })
2496
+ });
2550
2497
  this._activeDirtyManagerService.register(_univerjs_sheets.RemoveRowMutation.id, {
2551
2498
  commandId: _univerjs_sheets.RemoveRowMutation.id,
2552
2499
  getDirtyData: (command) => {
@@ -2605,6 +2552,13 @@ let ActiveDirtyController = class ActiveDirtyController extends _univerjs_core.D
2605
2552
  });
2606
2553
  }
2607
2554
  _initialSheet() {
2555
+ this._activeDirtyManagerService.register(_univerjs_sheets.SetWorksheetOrderMutation.id, {
2556
+ commandId: _univerjs_sheets.SetWorksheetOrderMutation.id,
2557
+ getDirtyData: (command) => {
2558
+ const { unitId, fromOrder, toOrder } = command.params;
2559
+ return { dirtyReferenceUnits: fromOrder === toOrder ? [] : [unitId] };
2560
+ }
2561
+ });
2608
2562
  this._activeDirtyManagerService.register(_univerjs_sheets.RemoveSheetMutation.id, {
2609
2563
  commandId: _univerjs_sheets.RemoveSheetMutation.id,
2610
2564
  getDirtyData: (command) => {
@@ -2782,14 +2736,13 @@ let ActiveDirtyController = class ActiveDirtyController extends _univerjs_core.D
2782
2736
  return dirtyRanges;
2783
2737
  }
2784
2738
  };
2785
- ActiveDirtyController = __decorate([
2786
- __decorateParam(0, _univerjs_engine_formula.IActiveDirtyManagerService),
2787
- __decorateParam(1, _univerjs_core.IUniverInstanceService),
2788
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel))
2739
+ ActiveDirtyController = require_remote_register_function_service.__decorate([
2740
+ require_remote_register_function_service.__decorateParam(0, _univerjs_engine_formula.IActiveDirtyManagerService),
2741
+ require_remote_register_function_service.__decorateParam(1, _univerjs_core.IUniverInstanceService),
2742
+ require_remote_register_function_service.__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel))
2789
2743
  ], ActiveDirtyController);
2790
2744
 
2791
- //#endregion
2792
- //#region src/controllers/array-formula-cell-interceptor.controller.ts
2745
+ // src/controllers/array-formula-cell-interceptor.controller.ts
2793
2746
  let ArrayFormulaCellInterceptorController = class ArrayFormulaCellInterceptorController extends _univerjs_core.Disposable {
2794
2747
  constructor(_commandService, _sheetInterceptorService, _formulaDataModel) {
2795
2748
  super();
@@ -2842,14 +2795,13 @@ let ArrayFormulaCellInterceptorController = class ArrayFormulaCellInterceptorCon
2842
2795
  }));
2843
2796
  }
2844
2797
  };
2845
- ArrayFormulaCellInterceptorController = __decorate([
2846
- __decorateParam(0, _univerjs_core.ICommandService),
2847
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
2848
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel))
2798
+ ArrayFormulaCellInterceptorController = require_remote_register_function_service.__decorate([
2799
+ require_remote_register_function_service.__decorateParam(0, _univerjs_core.ICommandService),
2800
+ require_remote_register_function_service.__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
2801
+ require_remote_register_function_service.__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaDataModel))
2849
2802
  ], ArrayFormulaCellInterceptorController);
2850
2803
 
2851
- //#endregion
2852
- //#region src/controllers/defined-name.controller.ts
2804
+ // src/controllers/defined-name.controller.ts
2853
2805
  let DefinedNameController = class DefinedNameController extends _univerjs_core.Disposable {
2854
2806
  constructor(_descriptionService, _definedNamesService, _univerInstanceService, _commandService) {
2855
2807
  super();
@@ -2857,7 +2809,7 @@ let DefinedNameController = class DefinedNameController extends _univerjs_core.D
2857
2809
  this._definedNamesService = _definedNamesService;
2858
2810
  this._univerInstanceService = _univerInstanceService;
2859
2811
  this._commandService = _commandService;
2860
- _defineProperty(this, "_preUnitId", null);
2812
+ require_remote_register_function_service._defineProperty(this, "_preUnitId", null);
2861
2813
  this._initialize();
2862
2814
  }
2863
2815
  _initialize() {
@@ -2984,15 +2936,14 @@ let DefinedNameController = class DefinedNameController extends _univerjs_core.D
2984
2936
  this._descriptionService.unregisterDescriptions(functionList);
2985
2937
  }
2986
2938
  };
2987
- DefinedNameController = __decorate([
2988
- __decorateParam(0, _univerjs_engine_formula.IDescriptionService),
2989
- __decorateParam(1, _univerjs_engine_formula.IDefinedNamesService),
2990
- __decorateParam(2, _univerjs_core.IUniverInstanceService),
2991
- __decorateParam(3, _univerjs_core.ICommandService)
2939
+ DefinedNameController = require_remote_register_function_service.__decorate([
2940
+ require_remote_register_function_service.__decorateParam(0, _univerjs_engine_formula.IDescriptionService),
2941
+ require_remote_register_function_service.__decorateParam(1, _univerjs_engine_formula.IDefinedNamesService),
2942
+ require_remote_register_function_service.__decorateParam(2, _univerjs_core.IUniverInstanceService),
2943
+ require_remote_register_function_service.__decorateParam(3, _univerjs_core.ICommandService)
2992
2944
  ], DefinedNameController);
2993
2945
 
2994
- //#endregion
2995
- //#region src/controllers/formula.controller.ts
2946
+ // src/controllers/formula.controller.ts
2996
2947
  /**
2997
2948
  * Copyright 2023-present DreamNum Co., Ltd.
2998
2949
  *
@@ -3015,10 +2966,9 @@ let FormulaController = class FormulaController extends _univerjs_core.Disposabl
3015
2966
  this._commandService.registerCommand(InsertFunctionCommand);
3016
2967
  }
3017
2968
  };
3018
- FormulaController = __decorate([__decorateParam(0, _univerjs_core.ICommandService)], FormulaController);
2969
+ FormulaController = require_remote_register_function_service.__decorate([require_remote_register_function_service.__decorateParam(0, _univerjs_core.ICommandService)], FormulaController);
3019
2970
 
3020
- //#endregion
3021
- //#region src/controllers/sheet-formula-calculation-result-apply.controller.ts
2971
+ // src/controllers/sheet-formula-calculation-result-apply.controller.ts
3022
2972
  /**
3023
2973
  * Copyright 2023-present DreamNum Co., Ltd.
3024
2974
  *
@@ -3044,10 +2994,9 @@ let SheetFormulaCalculationResultApplyController = class SheetFormulaCalculation
3044
2994
  }));
3045
2995
  }
3046
2996
  };
3047
- SheetFormulaCalculationResultApplyController = __decorate([__decorateParam(0, _univerjs_core.ICommandService), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaCalculationSessionService))], SheetFormulaCalculationResultApplyController);
2997
+ SheetFormulaCalculationResultApplyController = require_remote_register_function_service.__decorate([require_remote_register_function_service.__decorateParam(0, _univerjs_core.ICommandService), require_remote_register_function_service.__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_engine_formula.FormulaCalculationSessionService))], SheetFormulaCalculationResultApplyController);
3048
2998
 
3049
- //#endregion
3050
- //#region src/controllers/super-table.controller.ts
2999
+ // src/controllers/super-table.controller.ts
3051
3000
  let SuperTableController = class SuperTableController extends _univerjs_core.Disposable {
3052
3001
  constructor(_descriptionService, _univerInstanceService, _commandService, _superTableService) {
3053
3002
  super();
@@ -3055,7 +3004,7 @@ let SuperTableController = class SuperTableController extends _univerjs_core.Dis
3055
3004
  this._univerInstanceService = _univerInstanceService;
3056
3005
  this._commandService = _commandService;
3057
3006
  this._superTableService = _superTableService;
3058
- _defineProperty(this, "_preUnitId", null);
3007
+ require_remote_register_function_service._defineProperty(this, "_preUnitId", null);
3059
3008
  this._initialize();
3060
3009
  }
3061
3010
  _initialize() {
@@ -3168,15 +3117,46 @@ let SuperTableController = class SuperTableController extends _univerjs_core.Dis
3168
3117
  this._descriptionService.unregisterDescriptions(functionList);
3169
3118
  }
3170
3119
  };
3171
- SuperTableController = __decorate([
3172
- __decorateParam(0, _univerjs_engine_formula.IDescriptionService),
3173
- __decorateParam(1, _univerjs_core.IUniverInstanceService),
3174
- __decorateParam(2, _univerjs_core.ICommandService),
3175
- __decorateParam(3, _univerjs_engine_formula.ISuperTableService)
3120
+ SuperTableController = require_remote_register_function_service.__decorate([
3121
+ require_remote_register_function_service.__decorateParam(0, _univerjs_engine_formula.IDescriptionService),
3122
+ require_remote_register_function_service.__decorateParam(1, _univerjs_core.IUniverInstanceService),
3123
+ require_remote_register_function_service.__decorateParam(2, _univerjs_core.ICommandService),
3124
+ require_remote_register_function_service.__decorateParam(3, _univerjs_engine_formula.ISuperTableService)
3176
3125
  ], SuperTableController);
3177
3126
 
3178
- //#endregion
3179
- //#region src/services/formula-ref-range.service.ts
3127
+ // src/services/formula-ref-range.service.ts
3128
+ /**
3129
+ * An inserted row or column that lands inside a registered range stays part of that range, the
3130
+ * same way {@link handleCommonDefaultRangeChangeWithEffectRefCommands} expands a range when the
3131
+ * insertion happens inside it. `registerRangeFormula` splits a range into the segments that are
3132
+ * affected by a command, and an inserted block is not part of any segment, so it has to be
3133
+ * collected separately, otherwise the inserted cells would silently drop out of the range.
3134
+ */
3135
+ function getInsertedBlocks(command, ranges) {
3136
+ const params = command.params;
3137
+ if (!(params === null || params === void 0 ? void 0 : params.range)) return [];
3138
+ switch (command.id) {
3139
+ case _univerjs_sheets.EffectRefRangId.InsertRowCommandId: {
3140
+ const { startRow, endRow } = params.range;
3141
+ return ranges.filter((range) => startRow > range.startRow && startRow <= range.endRow).map((range) => ({
3142
+ startRow,
3143
+ endRow,
3144
+ startColumn: range.startColumn,
3145
+ endColumn: range.endColumn
3146
+ }));
3147
+ }
3148
+ case _univerjs_sheets.EffectRefRangId.InsertColCommandId: {
3149
+ const { startColumn, endColumn } = params.range;
3150
+ return ranges.filter((range) => startColumn > range.startColumn && startColumn <= range.endColumn).map((range) => ({
3151
+ startRow: range.startRow,
3152
+ endRow: range.endRow,
3153
+ startColumn,
3154
+ endColumn
3155
+ }));
3156
+ }
3157
+ default: return [];
3158
+ }
3159
+ }
3180
3160
  function getFormulaKeyOffset(lexerTreeBuilder, formulaString, refOffsetX, refOffsetY) {
3181
3161
  const sequenceNodes = lexerTreeBuilder.sequenceNodesBuilder(formulaString);
3182
3162
  if (sequenceNodes == null) return formulaString;
@@ -3325,6 +3305,8 @@ let FormulaRefRangeService = class FormulaRefRangeService extends _univerjs_core
3325
3305
  const disposableCollection = new _univerjs_core.DisposableCollection();
3326
3306
  const formulaDeps = formulas.map((formula) => this._getFormulaDependcy(unitId, subUnitId, formula, oldRanges));
3327
3307
  const handleRangeChange = (commandInfo) => {
3308
+ const wholeRangeResult = this._transformWholeRangeFormulas(unitId, subUnitId, oldRanges, formulas, commandInfo);
3309
+ if (wholeRangeResult) return callback(wholeRangeResult);
3328
3310
  const effectedRanges = (0, _univerjs_sheets.getSeparateEffectedRangesOnCommand)(this._injector, commandInfo);
3329
3311
  if (!effectedRanges) return {
3330
3312
  undos: [],
@@ -3416,6 +3398,7 @@ let FormulaRefRangeService = class FormulaRefRangeService extends _univerjs_core
3416
3398
  if (keyMap.has(item.key)) keyMap.get(item.key).push(item);
3417
3399
  else keyMap.set(item.key, [item]);
3418
3400
  }
3401
+ this._appendInsertedBlockItems(keyMap, commandInfo, oldRanges, formulas, oldRanges[0], originKey);
3419
3402
  const res = [];
3420
3403
  const keys = Array.from(keyMap.keys());
3421
3404
  for (let i = keys.length - 1; i >= 0; i--) {
@@ -3449,88 +3432,57 @@ let FormulaRefRangeService = class FormulaRefRangeService extends _univerjs_core
3449
3432
  });
3450
3433
  return disposableCollection;
3451
3434
  }
3452
- };
3453
- FormulaRefRangeService = __decorate([
3454
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.RefRangeService)),
3455
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder)),
3456
- __decorateParam(2, _univerjs_core.IUniverInstanceService),
3457
- __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
3458
- ], FormulaRefRangeService);
3459
-
3460
- //#endregion
3461
- //#region src/services/remote/remote-register-function.service.ts
3462
- /**
3463
- * Copyright 2023-present DreamNum Co., Ltd.
3464
- *
3465
- * Licensed under the Apache License, Version 2.0 (the "License");
3466
- * you may not use this file except in compliance with the License.
3467
- * You may obtain a copy of the License at
3468
- *
3469
- * http://www.apache.org/licenses/LICENSE-2.0
3470
- *
3471
- * Unless required by applicable law or agreed to in writing, software
3472
- * distributed under the License is distributed on an "AS IS" BASIS,
3473
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3474
- * See the License for the specific language governing permissions and
3475
- * limitations under the License.
3476
- */
3477
- const RemoteRegisterFunctionServiceName = "sheets-formula.remote-register-function.service";
3478
- const IRemoteRegisterFunctionService = (0, _univerjs_core.createIdentifier)(RemoteRegisterFunctionServiceName);
3479
- let RemoteRegisterFunctionService = class RemoteRegisterFunctionService {
3480
- constructor(_functionService) {
3481
- this._functionService = _functionService;
3482
- }
3483
- async registerFunctions(serializedFuncs) {
3484
- rejectRemoteCustomFunctionRegistration(serializedFuncs);
3485
- }
3486
- async registerAsyncFunctions(serializedFuncs) {
3487
- rejectRemoteCustomFunctionRegistration(serializedFuncs);
3488
- }
3489
- async unregisterFunctions(names) {
3490
- this._functionService.unregisterExecutors(...names);
3491
- this._functionService.unregisterDescriptions(...names);
3492
- this._functionService.deleteFormulaAstCacheKey(...names);
3435
+ /**
3436
+ * A whole column/row/sheet range keeps its anchor, so it is adjusted as a single range:
3437
+ * segmenting it would both split the rule and drop the range type.
3438
+ *
3439
+ * @returns the single rule range to apply, or `undefined` when the regular segmentation applies
3440
+ */
3441
+ _transformWholeRangeFormulas(unitId, subUnitId, oldRanges, formulas, commandInfo) {
3442
+ var _oldRanges$;
3443
+ const ruleRangeType = ((_oldRanges$ = oldRanges[0]) === null || _oldRanges$ === void 0 ? void 0 : _oldRanges$.rangeType) ?? _univerjs_core.RANGE_TYPE.NORMAL;
3444
+ if (ruleRangeType === _univerjs_core.RANGE_TYPE.NORMAL || !oldRanges.every((range) => range.rangeType === ruleRangeType)) return;
3445
+ const ranges = (0, _univerjs_sheets.handleCommonDefaultRangeChangeWithEffectRefCommands)(oldRanges[0], commandInfo);
3446
+ if (!ranges.length) return [];
3447
+ return [{
3448
+ formulas: formulas.map((formula) => (0, _univerjs_core.isFormulaString)(formula) ? this.transformFormulaByEffectCommand(unitId, subUnitId, formula, commandInfo) : formula),
3449
+ ranges
3450
+ }];
3451
+ }
3452
+ _appendInsertedBlockItems(keyMap, commandInfo, oldRanges, formulas, origin, originKey) {
3453
+ for (const block of getInsertedBlocks(commandInfo, oldRanges)) {
3454
+ const offsetRow = block.startRow - origin.startRow;
3455
+ const offsetColumn = block.startColumn - origin.startColumn;
3456
+ const item = {
3457
+ formulas: formulas.map((formula) => ({
3458
+ newFormula: (0, _univerjs_core.isFormulaString)(formula) ? this._lexerTreeBuilder.moveFormulaRefOffset(formula, offsetColumn, offsetRow) : formula,
3459
+ orginFormula: formula
3460
+ })),
3461
+ ranges: [block],
3462
+ key: originKey
3463
+ };
3464
+ const items = keyMap.get(item.key);
3465
+ if (items) items.push(item);
3466
+ else keyMap.set(item.key, [item]);
3467
+ }
3493
3468
  }
3494
3469
  };
3495
- RemoteRegisterFunctionService = __decorate([__decorateParam(0, _univerjs_engine_formula.IFunctionService)], RemoteRegisterFunctionService);
3496
- function rejectRemoteCustomFunctionRegistration(serializedFuncs) {
3497
- if (serializedFuncs.length === 0) return;
3498
- throw new Error("Remote custom function registration is disabled because function deserialization over RPC is unsafe.");
3499
- }
3470
+ FormulaRefRangeService = require_remote_register_function_service.__decorate([
3471
+ require_remote_register_function_service.__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.RefRangeService)),
3472
+ require_remote_register_function_service.__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_engine_formula.LexerTreeBuilder)),
3473
+ require_remote_register_function_service.__decorateParam(2, _univerjs_core.IUniverInstanceService),
3474
+ require_remote_register_function_service.__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
3475
+ ], FormulaRefRangeService);
3500
3476
 
3501
- //#endregion
3502
- //#region src/plugin.ts
3503
- let UniverRemoteSheetsFormulaPlugin = class UniverRemoteSheetsFormulaPlugin extends _univerjs_core.Plugin {
3504
- constructor(_config = defaultPluginRemoteConfig, _injector, _configService) {
3505
- super();
3506
- this._config = _config;
3507
- this._injector = _injector;
3508
- this._configService = _configService;
3509
- const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginRemoteConfig, this._config);
3510
- this._configService.setConfig(PLUGIN_CONFIG_KEY_REMOTE, rest);
3511
- }
3512
- onStarting() {
3513
- this._injector.add([RemoteRegisterFunctionService]);
3514
- this._injector.get(_univerjs_rpc.IRPCChannelService).registerChannel(RemoteRegisterFunctionServiceName, (0, _univerjs_rpc.fromModule)(this._injector.get(RemoteRegisterFunctionService)));
3515
- }
3516
- };
3517
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "pluginName", "SHEET_FORMULA_REMOTE_PLUGIN");
3518
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "packageName", name);
3519
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "version", version);
3520
- _defineProperty(UniverRemoteSheetsFormulaPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
3521
- UniverRemoteSheetsFormulaPlugin = __decorate([
3522
- (0, _univerjs_core.DependentOn)(_univerjs_engine_formula.UniverFormulaEnginePlugin),
3523
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
3524
- __decorateParam(2, _univerjs_core.IConfigService)
3525
- ], UniverRemoteSheetsFormulaPlugin);
3477
+ // src/plugin.ts
3526
3478
  let UniverSheetsFormulaPlugin = class UniverSheetsFormulaPlugin extends _univerjs_core.Plugin {
3527
- constructor(_config = defaultPluginBaseConfig, _injector, _configService) {
3479
+ constructor(_config = require_remote_register_function_service.defaultPluginBaseConfig, _injector, _configService) {
3528
3480
  super();
3529
3481
  this._config = _config;
3530
3482
  this._injector = _injector;
3531
3483
  this._configService = _configService;
3532
- const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginBaseConfig, this._config);
3533
- this._configService.setConfig(PLUGIN_CONFIG_KEY_BASE, rest, { merge: true });
3484
+ const { ...rest } = (0, _univerjs_core.merge)({}, require_remote_register_function_service.defaultPluginBaseConfig, this._config);
3485
+ this._configService.setConfig(require_remote_register_function_service.PLUGIN_CONFIG_KEY_BASE, rest, { merge: true });
3534
3486
  }
3535
3487
  onStarting() {
3536
3488
  var _this$_config$descrip;
@@ -3553,7 +3505,9 @@ let UniverSheetsFormulaPlugin = class UniverSheetsFormulaPlugin extends _univerj
3553
3505
  ];
3554
3506
  if (this._config.notExecuteFormula) {
3555
3507
  const rpcChannelService = j.get(_univerjs_rpc.IRPCChannelService);
3556
- dependencies.push([IRemoteRegisterFunctionService, { useFactory: () => (0, _univerjs_rpc.toModule)(rpcChannelService.requestChannel(RemoteRegisterFunctionServiceName)) }]);
3508
+ dependencies.push([require_remote_register_function_service.IRemoteRegisterFunctionService, { useFactory: function createChannelService() {
3509
+ return (0, _univerjs_rpc.toModule)(rpcChannelService.requestChannel(require_remote_register_function_service.RemoteRegisterFunctionServiceName));
3510
+ } }]);
3557
3511
  }
3558
3512
  dependencies.forEach((dependency) => j.add(dependency));
3559
3513
  if ((_this$_config$descrip = this._config.description) === null || _this$_config$descrip === void 0 ? void 0 : _this$_config$descrip.length) this.disposeWithMe(j.get(_univerjs_engine_formula.IDescriptionService).registerDescriptions(this._config.description));
@@ -3578,18 +3532,17 @@ let UniverSheetsFormulaPlugin = class UniverSheetsFormulaPlugin extends _univerj
3578
3532
  if (!(0, _univerjs_core.isNodeEnv)()) (0, _univerjs_core.touchDependencies)(this._injector, [[TriggerCalculationController]]);
3579
3533
  }
3580
3534
  };
3581
- _defineProperty(UniverSheetsFormulaPlugin, "pluginName", SHEETS_FORMULA_PLUGIN_NAME);
3582
- _defineProperty(UniverSheetsFormulaPlugin, "packageName", name);
3583
- _defineProperty(UniverSheetsFormulaPlugin, "version", version);
3584
- _defineProperty(UniverSheetsFormulaPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
3585
- UniverSheetsFormulaPlugin = __decorate([
3535
+ require_remote_register_function_service._defineProperty(UniverSheetsFormulaPlugin, "pluginName", SHEETS_FORMULA_PLUGIN_NAME);
3536
+ require_remote_register_function_service._defineProperty(UniverSheetsFormulaPlugin, "packageName", require_remote_register_function_service.name);
3537
+ require_remote_register_function_service._defineProperty(UniverSheetsFormulaPlugin, "version", require_remote_register_function_service.version);
3538
+ require_remote_register_function_service._defineProperty(UniverSheetsFormulaPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
3539
+ UniverSheetsFormulaPlugin = require_remote_register_function_service.__decorate([
3586
3540
  (0, _univerjs_core.DependentOn)(_univerjs_engine_formula.UniverFormulaEnginePlugin, _univerjs_sheets.UniverSheetsPlugin),
3587
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
3588
- __decorateParam(2, _univerjs_core.IConfigService)
3541
+ require_remote_register_function_service.__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
3542
+ require_remote_register_function_service.__decorateParam(2, _univerjs_core.IConfigService)
3589
3543
  ], UniverSheetsFormulaPlugin);
3590
3544
 
3591
- //#endregion
3592
- //#region src/util/calculate.ts
3545
+ // src/util/calculate.ts
3593
3546
  function calculateFormula(inject, formulaString, unitId, sheetData) {
3594
3547
  const formulaCurrentConfigService = inject.get(_univerjs_engine_formula.IFormulaCurrentConfigService);
3595
3548
  const lexer = inject.get(_univerjs_engine_formula.Lexer);
@@ -3614,8 +3567,7 @@ function calculateFormula(inject, formulaString, unitId, sheetData) {
3614
3567
  return (0, _univerjs_engine_formula.getObjectValue)(result);
3615
3568
  }
3616
3569
 
3617
- //#endregion
3618
- exports.CalculationMode = CalculationMode;
3570
+ exports.CalculationMode = require_remote_register_function_service.CalculationMode;
3619
3571
  Object.defineProperty(exports, "FormulaAutoFillController", {
3620
3572
  enumerable: true,
3621
3573
  get: function () {
@@ -3634,7 +3586,7 @@ Object.defineProperty(exports, "FormulaReorderController", {
3634
3586
  return FormulaReorderController;
3635
3587
  }
3636
3588
  });
3637
- exports.IRemoteRegisterFunctionService = IRemoteRegisterFunctionService;
3589
+ exports.IRemoteRegisterFunctionService = require_remote_register_function_service.IRemoteRegisterFunctionService;
3638
3590
  Object.defineProperty(exports, "ImageFormulaCellInterceptorController", {
3639
3591
  enumerable: true,
3640
3592
  get: function () {
@@ -3642,11 +3594,11 @@ Object.defineProperty(exports, "ImageFormulaCellInterceptorController", {
3642
3594
  }
3643
3595
  });
3644
3596
  exports.InsertFunctionCommand = InsertFunctionCommand;
3645
- exports.PLUGIN_CONFIG_KEY_BASE = PLUGIN_CONFIG_KEY_BASE;
3597
+ exports.PLUGIN_CONFIG_KEY_BASE = require_remote_register_function_service.PLUGIN_CONFIG_KEY_BASE;
3646
3598
  Object.defineProperty(exports, "RemoteRegisterFunctionService", {
3647
3599
  enumerable: true,
3648
3600
  get: function () {
3649
- return RemoteRegisterFunctionService;
3601
+ return require_remote_register_function_service.RemoteRegisterFunctionService;
3650
3602
  }
3651
3603
  });
3652
3604
  Object.defineProperty(exports, "TriggerCalculationController", {
@@ -3661,12 +3613,6 @@ Object.defineProperty(exports, "UnitQualifierRenameController", {
3661
3613
  return UnitQualifierRenameController;
3662
3614
  }
3663
3615
  });
3664
- Object.defineProperty(exports, "UniverRemoteSheetsFormulaPlugin", {
3665
- enumerable: true,
3666
- get: function () {
3667
- return UniverRemoteSheetsFormulaPlugin;
3668
- }
3669
- });
3670
3616
  Object.defineProperty(exports, "UniverSheetsFormulaPlugin", {
3671
3617
  enumerable: true,
3672
3618
  get: function () {