@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.
- package/README.md +19 -7
- package/lib/cjs/facade.js +4 -9
- package/lib/cjs/index.js +436 -490
- package/lib/cjs/locale/ar-SA.js +1 -2
- package/lib/cjs/locale/ca-ES.js +1 -2
- package/lib/cjs/locale/de-DE.js +1 -2
- package/lib/cjs/locale/en-US.js +1 -2
- package/lib/cjs/locale/es-ES.js +1 -2
- package/lib/cjs/locale/fa-IR.js +1 -2
- package/lib/cjs/locale/fr-FR.js +1 -2
- package/lib/cjs/locale/id-ID.js +1 -2
- package/lib/cjs/locale/it-IT.js +1 -2
- package/lib/cjs/locale/ja-JP.js +1 -2
- package/lib/cjs/locale/ko-KR.js +1 -2
- package/lib/cjs/locale/pl-PL.js +1 -2
- package/lib/cjs/locale/pt-BR.js +1 -2
- package/lib/cjs/locale/ru-RU.js +1 -2
- package/lib/cjs/locale/sk-SK.js +1 -2
- package/lib/cjs/locale/vi-VN.js +1 -2
- package/lib/cjs/locale/zh-CN.js +1 -2
- package/lib/cjs/locale/zh-HK.js +1 -2
- package/lib/cjs/locale/zh-TW.js +1 -2
- package/lib/cjs/remote-register-function.service-D0P1G4Uh.js +212 -0
- package/lib/cjs/worker.js +52 -0
- package/lib/es/facade.js +4 -8
- package/lib/es/index.js +353 -401
- package/lib/es/locale/ar-SA.js +1 -2
- package/lib/es/locale/ca-ES.js +1 -2
- package/lib/es/locale/de-DE.js +1 -2
- package/lib/es/locale/en-US.js +1 -2
- package/lib/es/locale/es-ES.js +1 -2
- package/lib/es/locale/fa-IR.js +1 -2
- package/lib/es/locale/fr-FR.js +1 -2
- package/lib/es/locale/id-ID.js +1 -2
- package/lib/es/locale/it-IT.js +1 -2
- package/lib/es/locale/ja-JP.js +1 -2
- package/lib/es/locale/ko-KR.js +1 -2
- package/lib/es/locale/pl-PL.js +1 -2
- package/lib/es/locale/pt-BR.js +1 -2
- package/lib/es/locale/ru-RU.js +1 -2
- package/lib/es/locale/sk-SK.js +1 -2
- package/lib/es/locale/vi-VN.js +1 -2
- package/lib/es/locale/zh-CN.js +1 -2
- package/lib/es/locale/zh-HK.js +1 -2
- package/lib/es/locale/zh-TW.js +1 -2
- package/lib/es/remote-register-function.service-CaKs4mpz.js +135 -0
- package/lib/es/worker.js +46 -0
- package/lib/facade.js +4 -8
- package/lib/index.js +353 -401
- package/lib/locale/ar-SA.js +1 -2
- package/lib/locale/ca-ES.js +1 -2
- package/lib/locale/de-DE.js +1 -2
- package/lib/locale/en-US.js +1 -2
- package/lib/locale/es-ES.js +1 -2
- package/lib/locale/fa-IR.js +1 -2
- package/lib/locale/fr-FR.js +1 -2
- package/lib/locale/id-ID.js +1 -2
- package/lib/locale/it-IT.js +1 -2
- package/lib/locale/ja-JP.js +1 -2
- package/lib/locale/ko-KR.js +1 -2
- package/lib/locale/pl-PL.js +1 -2
- package/lib/locale/pt-BR.js +1 -2
- package/lib/locale/ru-RU.js +1 -2
- package/lib/locale/sk-SK.js +1 -2
- package/lib/locale/vi-VN.js +1 -2
- package/lib/locale/zh-CN.js +1 -2
- package/lib/locale/zh-HK.js +1 -2
- package/lib/locale/zh-TW.js +1 -2
- package/lib/remote-register-function.service-CaKs4mpz.js +135 -0
- package/lib/types/controllers/trigger-calculation.controller.d.ts +2 -0
- package/lib/types/controllers/update-formula.controller.d.ts +4 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/plugin.d.ts +1 -12
- package/lib/types/services/formula-ref-range.service.d.ts +8 -0
- package/lib/types/services/remote/remote-register-function.service.d.ts +1 -1
- package/lib/types/worker.d.ts +28 -0
- package/lib/umd/index.js +1 -1
- package/lib/worker.js +46 -0
- package/package.json +17 -12
package/lib/es/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { a as version, c as __decorateParam, f as defaultPluginBaseConfig, i as name, l as CalculationMode, n as RemoteRegisterFunctionService, o as _defineProperty, r as RemoteRegisterFunctionServiceName, s as __decorate, t as IRemoteRegisterFunctionService, u as PLUGIN_CONFIG_KEY_BASE } from "./remote-register-function.service-CaKs4mpz.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,
|
|
7
|
+
import { IRPCChannelService, toModule } from "@univerjs/rpc";
|
|
7
8
|
|
|
8
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
@@ -539,6 +442,12 @@ let TriggerCalculationController = class TriggerCalculationController extends Di
|
|
|
539
442
|
_initialExecuteFormulaProcessListener() {
|
|
540
443
|
let startDependencyTimer = null;
|
|
541
444
|
let calculationProcessCount = 0;
|
|
445
|
+
this.disposeWithMe(() => {
|
|
446
|
+
if (startDependencyTimer !== null) {
|
|
447
|
+
clearTimeout(startDependencyTimer);
|
|
448
|
+
startDependencyTimer = null;
|
|
449
|
+
}
|
|
450
|
+
});
|
|
542
451
|
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
543
452
|
if (command.id === SetFormulaCalculationStopMutation.id) this.clearProgress();
|
|
544
453
|
if (command.id !== SetFormulaCalculationNotificationMutation.id) return;
|
|
@@ -557,43 +466,11 @@ let TriggerCalculationController = class TriggerCalculationController extends Di
|
|
|
557
466
|
startDependencyTimer = null;
|
|
558
467
|
this._startProgress();
|
|
559
468
|
}, 1e3);
|
|
560
|
-
} else
|
|
561
|
-
this._executionInProgressParams = params.stageInfo;
|
|
562
|
-
if (startDependencyTimer === null) {
|
|
563
|
-
const calculating = this._localeService.t("sheets-formula.progress.calculating");
|
|
564
|
-
this._calculateProgress(calculating);
|
|
565
|
-
}
|
|
566
|
-
} else if (stage === FormulaExecuteStageType.START_DEPENDENCY_ARRAY_FORMULA) {
|
|
567
|
-
this._executionInProgressParams = params.stageInfo;
|
|
568
|
-
if (startDependencyTimer === null) {
|
|
569
|
-
const arrayAnalysis = this._localeService.t("sheets-formula.progress.array-analysis");
|
|
570
|
-
this._calculateProgress(arrayAnalysis);
|
|
571
|
-
}
|
|
572
|
-
} else if (stage === FormulaExecuteStageType.CURRENTLY_CALCULATING_ARRAY_FORMULA) {
|
|
573
|
-
this._executionInProgressParams = params.stageInfo;
|
|
574
|
-
if (startDependencyTimer === null) {
|
|
575
|
-
const arrayCalculation = this._localeService.t("sheets-formula.progress.array-calculation");
|
|
576
|
-
this._calculateProgress(arrayCalculation);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
469
|
+
} else this._updateCalculationProgress(params.stageInfo, startDependencyTimer === null);
|
|
579
470
|
} else {
|
|
580
471
|
const state = params.functionsExecutedState;
|
|
581
|
-
|
|
582
|
-
calculationProcessCount
|
|
583
|
-
switch (state) {
|
|
584
|
-
case FormulaExecutedStateType.NOT_EXECUTED:
|
|
585
|
-
result = "No tasks are being executed anymore";
|
|
586
|
-
break;
|
|
587
|
-
case FormulaExecutedStateType.STOP_EXECUTION:
|
|
588
|
-
result = "The execution of the formula has been stopped";
|
|
589
|
-
calculationProcessCount = 0;
|
|
590
|
-
break;
|
|
591
|
-
case FormulaExecutedStateType.SUCCESS:
|
|
592
|
-
result = "Formula calculation succeeded";
|
|
593
|
-
if (calculationProcessCount === 0 || calculationProcessCount === -1) result += `. Total time consumed: ${performance.now() - this._startExecutionTime} ms`;
|
|
594
|
-
break;
|
|
595
|
-
case FormulaExecutedStateType.INITIAL: result = "Waiting for calculation";
|
|
596
|
-
}
|
|
472
|
+
calculationProcessCount = state === FormulaExecutedStateType.STOP_EXECUTION ? 0 : calculationProcessCount - 1;
|
|
473
|
+
const result = this._getCalculationResultMessage(state, calculationProcessCount);
|
|
597
474
|
if (calculationProcessCount === 0 || calculationProcessCount === -1) {
|
|
598
475
|
if (startDependencyTimer) {
|
|
599
476
|
clearTimeout(startDependencyTimer);
|
|
@@ -609,6 +486,34 @@ let TriggerCalculationController = class TriggerCalculationController extends Di
|
|
|
609
486
|
}
|
|
610
487
|
}));
|
|
611
488
|
}
|
|
489
|
+
_updateCalculationProgress(stageInfo, showProgress) {
|
|
490
|
+
let label;
|
|
491
|
+
switch (stageInfo.stage) {
|
|
492
|
+
case FormulaExecuteStageType.CURRENTLY_CALCULATING:
|
|
493
|
+
label = "sheets-formula.progress.calculating";
|
|
494
|
+
break;
|
|
495
|
+
case FormulaExecuteStageType.START_DEPENDENCY_ARRAY_FORMULA:
|
|
496
|
+
label = "sheets-formula.progress.array-analysis";
|
|
497
|
+
break;
|
|
498
|
+
case FormulaExecuteStageType.CURRENTLY_CALCULATING_ARRAY_FORMULA:
|
|
499
|
+
label = "sheets-formula.progress.array-calculation";
|
|
500
|
+
break;
|
|
501
|
+
default: return;
|
|
502
|
+
}
|
|
503
|
+
this._executionInProgressParams = stageInfo;
|
|
504
|
+
if (showProgress) this._calculateProgress(this._localeService.t(label));
|
|
505
|
+
}
|
|
506
|
+
_getCalculationResultMessage(state, calculationProcessCount) {
|
|
507
|
+
switch (state) {
|
|
508
|
+
case FormulaExecutedStateType.NOT_EXECUTED: return "No tasks are being executed anymore";
|
|
509
|
+
case FormulaExecutedStateType.STOP_EXECUTION: return "The execution of the formula has been stopped";
|
|
510
|
+
case FormulaExecutedStateType.SUCCESS:
|
|
511
|
+
if (calculationProcessCount === 0 || calculationProcessCount === -1) return `Formula calculation succeeded. Total time consumed: ${performance.now() - this._startExecutionTime} ms`;
|
|
512
|
+
return "Formula calculation succeeded";
|
|
513
|
+
case FormulaExecutedStateType.INITIAL: return "Waiting for calculation";
|
|
514
|
+
default: return "";
|
|
515
|
+
}
|
|
516
|
+
}
|
|
612
517
|
_initialExecuteFormula() {
|
|
613
518
|
const calculationMode = this._getCalculationMode();
|
|
614
519
|
if (calculationMode !== 2) {
|
|
@@ -638,8 +543,7 @@ TriggerCalculationController = __decorate([
|
|
|
638
543
|
__decorateParam(5, Inject(LocaleService))
|
|
639
544
|
], TriggerCalculationController);
|
|
640
545
|
|
|
641
|
-
|
|
642
|
-
//#region src/controllers/unit-qualifier-rename.controller.ts
|
|
546
|
+
// src/controllers/unit-qualifier-rename.controller.ts
|
|
643
547
|
function collectUnitQualifierFormulaPatches(workbook, oldName, newName) {
|
|
644
548
|
const unitId = workbook.getUnitId();
|
|
645
549
|
return workbook.getSheets().flatMap((sheet) => {
|
|
@@ -738,8 +642,7 @@ UnitQualifierRenameController = __decorate([
|
|
|
738
642
|
__decorateParam(3, IDefinedNamesService)
|
|
739
643
|
], UnitQualifierRenameController);
|
|
740
644
|
|
|
741
|
-
|
|
742
|
-
//#region src/controllers/utils/offset-formula-data.ts
|
|
645
|
+
// src/controllers/utils/offset-formula-data.ts
|
|
743
646
|
function checkFormulaDataNull(formulaData, unitId, sheetId) {
|
|
744
647
|
var _formulaData$unitId;
|
|
745
648
|
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 +661,7 @@ function removeFormulaData(formulaData, unitId, sheetId) {
|
|
|
758
661
|
}
|
|
759
662
|
}
|
|
760
663
|
|
|
761
|
-
|
|
762
|
-
//#region src/controllers/utils/ref-range-formula.ts
|
|
664
|
+
// src/controllers/utils/ref-range-formula.ts
|
|
763
665
|
const formulaReferenceSheetList = [
|
|
764
666
|
11,
|
|
765
667
|
12,
|
|
@@ -1230,8 +1132,7 @@ function updateRefOffset(sequenceNodes, refChangeIds, refOffsetX = 0, refOffsetY
|
|
|
1230
1132
|
return newSequenceNodes;
|
|
1231
1133
|
}
|
|
1232
1134
|
|
|
1233
|
-
|
|
1234
|
-
//#region src/controllers/utils/ref-range-move.ts
|
|
1135
|
+
// src/controllers/utils/ref-range-move.ts
|
|
1235
1136
|
function getNewRangeByMoveParam(unitRangeWidthOffset, formulaReferenceMoveParam, currentFormulaUnitId, currentFormulaSheetId, options = {}) {
|
|
1236
1137
|
const { type, unitId: userUnitId, sheetId: userSheetId, targetUnitId, targetSheetId, targetSheetName, range, from, to, rangeFilteredRows } = formulaReferenceMoveParam;
|
|
1237
1138
|
const { range: unitRange, sheetId: sequenceRangeSheetId, unitId: sequenceRangeUnitId, sheetName: sequenceRangeSheetName, refOffsetX, refOffsetY } = unitRangeWidthOffset;
|
|
@@ -1556,8 +1457,7 @@ function getStartEndValue(range) {
|
|
|
1556
1457
|
};
|
|
1557
1458
|
}
|
|
1558
1459
|
|
|
1559
|
-
|
|
1560
|
-
//#region src/controllers/utils/ref-range-param.ts
|
|
1460
|
+
// src/controllers/utils/ref-range-param.ts
|
|
1561
1461
|
const SET_SHEET_TABLE_COMMAND_ID = "sheet.command.set-table-config";
|
|
1562
1462
|
const DELETE_SHEET_TABLE_COMMAND_ID = "sheet.command.delete-table";
|
|
1563
1463
|
const REMOVE_SHEET_TABLE_COLUMN_AT_COMMAND_ID = "sheet.command.table-remove-column-at";
|
|
@@ -1911,8 +1811,7 @@ function handleRefRemoveSheetTableColumn(command, workbook) {
|
|
|
1911
1811
|
};
|
|
1912
1812
|
}
|
|
1913
1813
|
|
|
1914
|
-
|
|
1915
|
-
//#region src/controllers/update-defined-name.controller.ts
|
|
1814
|
+
// src/controllers/update-defined-name.controller.ts
|
|
1916
1815
|
let UpdateDefinedNameController = class UpdateDefinedNameController extends Disposable {
|
|
1917
1816
|
constructor(_definedNamesService, _univerInstanceService, _sheetInterceptorService, _lexerTreeBuilder) {
|
|
1918
1817
|
super();
|
|
@@ -2061,8 +1960,7 @@ UpdateDefinedNameController = __decorate([
|
|
|
2061
1960
|
__decorateParam(3, Inject(LexerTreeBuilder))
|
|
2062
1961
|
], UpdateDefinedNameController);
|
|
2063
1962
|
|
|
2064
|
-
|
|
2065
|
-
//#region src/controllers/update-formula.controller.ts
|
|
1963
|
+
// src/controllers/update-formula.controller.ts
|
|
2066
1964
|
let UpdateFormulaController = class UpdateFormulaController extends Disposable {
|
|
2067
1965
|
constructor(_univerInstanceService, _commandService, _lexerTreeBuilder, _formulaDataModel, _sheetInterceptorService, _definedNamesService, _configService, _injector) {
|
|
2068
1966
|
super();
|
|
@@ -2095,12 +1993,30 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
|
|
|
2095
1993
|
this.disposeWithMe(this._univerInstanceService.getTypeOfUnitAdded$(UniverInstanceType.UNIVER_SHEET).subscribe((event) => this._handleWorkbookAdded(event.unit)));
|
|
2096
1994
|
this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(UniverInstanceType.UNIVER_SHEET).pipe(map((unit) => unit.getUnitId())).subscribe((unitId) => this._handleWorkbookDisposed(unitId)));
|
|
2097
1995
|
}
|
|
1996
|
+
_getEditedArrayFormulaDirtyRanges(params) {
|
|
1997
|
+
var _this$_formulaDataMod;
|
|
1998
|
+
const { subUnitId: sheetId, unitId, cellValue } = params;
|
|
1999
|
+
const previousRanges = (_this$_formulaDataMod = this._formulaDataModel.getArrayFormulaRange()[unitId]) === null || _this$_formulaDataMod === void 0 ? void 0 : _this$_formulaDataMod[sheetId];
|
|
2000
|
+
const dirtyRanges = [];
|
|
2001
|
+
if (previousRanges) new ObjectMatrix(cellValue).forValue((row, column) => {
|
|
2002
|
+
var _previousRanges$row;
|
|
2003
|
+
const range = (_previousRanges$row = previousRanges[row]) === null || _previousRanges$row === void 0 ? void 0 : _previousRanges$row[column];
|
|
2004
|
+
if (range && (range.startRow !== range.endRow || range.startColumn !== range.endColumn)) dirtyRanges.push({
|
|
2005
|
+
unitId,
|
|
2006
|
+
sheetId,
|
|
2007
|
+
range
|
|
2008
|
+
});
|
|
2009
|
+
});
|
|
2010
|
+
return dirtyRanges;
|
|
2011
|
+
}
|
|
2098
2012
|
_handleSetRangeValuesMutation(params) {
|
|
2099
2013
|
const { subUnitId: sheetId, unitId, cellValue } = params;
|
|
2100
2014
|
if (cellValue == null) return;
|
|
2015
|
+
const dirtyRanges = this._getEditedArrayFormulaDirtyRanges(params);
|
|
2101
2016
|
const newSheetFormulaData = this._formulaDataModel.updateFormulaData(unitId, sheetId, cellValue);
|
|
2102
2017
|
const arrayFormulaCellDataChanged = this._formulaDataModel.updateArrayFormulaCellData(unitId, sheetId, cellValue);
|
|
2103
2018
|
const arrayFormulaRangeChanged = this._formulaDataModel.updateArrayFormulaRange(unitId, sheetId, cellValue);
|
|
2019
|
+
if (dirtyRanges.length > 0) this._commandService.syncExecuteCommand(SetTriggerFormulaCalculationStartMutation.id, { dirtyRanges }, { onlyLocal: true });
|
|
2104
2020
|
if (Object.keys(newSheetFormulaData).length === 0) {
|
|
2105
2021
|
if (arrayFormulaCellDataChanged || arrayFormulaRangeChanged) this._commandService.executeCommand(SetArrayFormulaDataMutation.id, {
|
|
2106
2022
|
arrayFormulaRange: this._formulaDataModel.getArrayFormulaRange(),
|
|
@@ -2212,175 +2128,116 @@ let UpdateFormulaController = class UpdateFormulaController extends Disposable {
|
|
|
2212
2128
|
const formulaDataKeys = Object.keys(formulaData);
|
|
2213
2129
|
if (formulaDataKeys.length === 0) return { newFormulaData: {} };
|
|
2214
2130
|
const newFormulaData = Object.create(null);
|
|
2215
|
-
const { unitId: fromUnitId, sheetId: fromSheetId, sheetName: fromSheetName, targetUnitId, targetSheetId, type, from, to } = formulaReferenceMoveParam;
|
|
2216
2131
|
const inCrossSheetCutRangeNewFormulas = [];
|
|
2132
|
+
const { type, unitId: affectedUnitId, sheetId: affectedSheetId } = formulaReferenceMoveParam;
|
|
2133
|
+
const isRemovingSheet = type === 13;
|
|
2217
2134
|
for (const unitId of formulaDataKeys) {
|
|
2218
2135
|
const sheetData = formulaData[unitId];
|
|
2219
2136
|
if (sheetData == null) continue;
|
|
2220
2137
|
const sheetDataKeys = Object.keys(sheetData);
|
|
2221
2138
|
if (!Tools.isDefine(newFormulaData[unitId])) newFormulaData[unitId] = Object.create(null);
|
|
2222
2139
|
for (const sheetId of sheetDataKeys) {
|
|
2140
|
+
if (isRemovingSheet && unitId === affectedUnitId && sheetId === affectedSheetId) continue;
|
|
2223
2141
|
const matrixData = new ObjectMatrix(sheetData[sheetId] || {});
|
|
2224
2142
|
const newFormulaDataItem = new ObjectMatrix();
|
|
2225
|
-
const
|
|
2143
|
+
const context = {
|
|
2144
|
+
unitId,
|
|
2145
|
+
sheetId,
|
|
2146
|
+
unitSheetNameMap,
|
|
2147
|
+
params: formulaReferenceMoveParam,
|
|
2148
|
+
modifiedSharedFormulaIds: []
|
|
2149
|
+
};
|
|
2226
2150
|
matrixData.forValue((row, column, formulaDataItem) => {
|
|
2227
|
-
|
|
2228
|
-
|
|
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)}` });
|
|
2151
|
+
const formula = this._getMovedFormula(formulaDataItem, row, column, context, inCrossSheetCutRangeNewFormulas);
|
|
2152
|
+
if (formula != null) newFormulaDataItem.setValue(row, column, { f: formula });
|
|
2368
2153
|
});
|
|
2369
2154
|
if (newFormulaData[unitId]) newFormulaData[unitId][sheetId] = newFormulaDataItem.clone();
|
|
2370
2155
|
}
|
|
2371
2156
|
}
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2157
|
+
appendCrossSheetCutFormulas(newFormulaData, inCrossSheetCutRangeNewFormulas, formulaReferenceMoveParam);
|
|
2158
|
+
return { newFormulaData };
|
|
2159
|
+
}
|
|
2160
|
+
_getMovedFormula(item, row, column, context, crossSheetFormulas) {
|
|
2161
|
+
if (!item) return null;
|
|
2162
|
+
const { f: formulaString, x, y } = item;
|
|
2163
|
+
const { unitId, sheetId, params, modifiedSharedFormulaIds } = context;
|
|
2164
|
+
if (params.type === 12) {
|
|
2165
|
+
const { oldUnitName, unitName } = params;
|
|
2166
|
+
if (!oldUnitName || !unitName) return null;
|
|
2167
|
+
const nextFormula = refactorFormulaUnitQualifier(formulaString, oldUnitName, unitName);
|
|
2168
|
+
return nextFormula !== formulaString ? nextFormula : null;
|
|
2169
|
+
}
|
|
2170
|
+
const sequenceNodes = this._lexerTreeBuilder.sequenceNodesBuilder(formulaString);
|
|
2171
|
+
if (sequenceNodes == null) return null;
|
|
2172
|
+
const refChangeIds = [];
|
|
2173
|
+
const inCrossSheetCutRange = isInCrossSheetCutRange(unitId, sheetId, row, column, params);
|
|
2174
|
+
const crossSheetNodes = [...sequenceNodes];
|
|
2175
|
+
if (!this._updateFormulaReferenceNodes(sequenceNodes, item, context, refChangeIds, inCrossSheetCutRange ? crossSheetNodes : null) && !shouldUnpackSharedFormula(item, row, column, params, modifiedSharedFormulaIds)) return null;
|
|
2176
|
+
const newSequenceNodes = updateRefOffset(inCrossSheetCutRange ? crossSheetNodes : sequenceNodes, refChangeIds, x, y);
|
|
2177
|
+
const formula = `=${generateStringWithSequence(newSequenceNodes)}`;
|
|
2178
|
+
if (inCrossSheetCutRange) {
|
|
2179
|
+
crossSheetFormulas.push({
|
|
2180
|
+
fromRow: row,
|
|
2181
|
+
fromColumn: column,
|
|
2182
|
+
formulaString: formula
|
|
2183
|
+
});
|
|
2184
|
+
return null;
|
|
2185
|
+
}
|
|
2186
|
+
return formula;
|
|
2187
|
+
}
|
|
2188
|
+
_updateFormulaReferenceNodes(sequenceNodes, item, context, refChangeIds, crossSheetNodes) {
|
|
2189
|
+
const { unitId, sheetId, params, modifiedSharedFormulaIds } = context;
|
|
2190
|
+
const { x, y, si } = item;
|
|
2191
|
+
let shouldModify = false;
|
|
2192
|
+
for (let i = 0, len = sequenceNodes.length; i < len; i++) {
|
|
2193
|
+
const node = sequenceNodes[i];
|
|
2194
|
+
if (typeof node === "string") continue;
|
|
2195
|
+
const definedNameToken = this._getDefinedNameReferenceToken(node, unitId, params);
|
|
2196
|
+
if (definedNameToken != null) {
|
|
2197
|
+
sequenceNodes[i] = {
|
|
2198
|
+
...node,
|
|
2199
|
+
token: definedNameToken
|
|
2200
|
+
};
|
|
2201
|
+
shouldModify = true;
|
|
2202
|
+
refChangeIds.push(i);
|
|
2203
|
+
continue;
|
|
2204
|
+
}
|
|
2205
|
+
if (updateTableReference(sequenceNodes, i, node, params)) {
|
|
2206
|
+
shouldModify = true;
|
|
2207
|
+
refChangeIds.push(i);
|
|
2208
|
+
continue;
|
|
2209
|
+
}
|
|
2210
|
+
if (node.nodeType !== sequenceNodeType.REFERENCE) continue;
|
|
2211
|
+
const reference = getReferenceWithOffset(node.token, item, context);
|
|
2212
|
+
if (reference == null) continue;
|
|
2213
|
+
const newRefString = getMovedReferenceToken(reference, params, unitId, sheetId, crossSheetNodes != null);
|
|
2214
|
+
if (newRefString != null) {
|
|
2215
|
+
sequenceNodes[i] = {
|
|
2216
|
+
...node,
|
|
2217
|
+
token: newRefString
|
|
2218
|
+
};
|
|
2219
|
+
shouldModify = true;
|
|
2220
|
+
refChangeIds.push(i);
|
|
2221
|
+
if (si && (x ?? 0) === 0 && (y ?? 0) === 0) modifiedSharedFormulaIds.push(si);
|
|
2222
|
+
}
|
|
2223
|
+
if (crossSheetNodes != null) {
|
|
2224
|
+
const movedNode = getCrossSheetCutReference(node, reference, newRefString, params);
|
|
2225
|
+
if (movedNode != null) {
|
|
2226
|
+
crossSheetNodes[i] = movedNode;
|
|
2227
|
+
shouldModify = true;
|
|
2228
|
+
}
|
|
2381
2229
|
}
|
|
2382
2230
|
}
|
|
2383
|
-
return
|
|
2231
|
+
return shouldModify;
|
|
2232
|
+
}
|
|
2233
|
+
_getDefinedNameReferenceToken(node, unitId, params) {
|
|
2234
|
+
const { type, definedNameId, definedName } = params;
|
|
2235
|
+
if (type !== 14 && type !== 15) return null;
|
|
2236
|
+
if (node.nodeType !== sequenceNodeType.DEFINED_NAME && node.nodeType !== sequenceNodeType.FUNCTION) return null;
|
|
2237
|
+
if (definedNameId === void 0 || definedName === void 0) return null;
|
|
2238
|
+
const oldDefinedName = this._definedNamesService.getValueById(unitId, definedNameId);
|
|
2239
|
+
if (oldDefinedName == null || oldDefinedName.name !== node.token) return null;
|
|
2240
|
+
return type === 14 ? definedName : ErrorType.REF;
|
|
2384
2241
|
}
|
|
2385
2242
|
};
|
|
2386
2243
|
UpdateFormulaController = __decorate([
|
|
@@ -2393,6 +2250,99 @@ UpdateFormulaController = __decorate([
|
|
|
2393
2250
|
__decorateParam(6, IConfigService),
|
|
2394
2251
|
__decorateParam(7, Inject(Injector))
|
|
2395
2252
|
], UpdateFormulaController);
|
|
2253
|
+
function getReferenceWithOffset(token, item, context) {
|
|
2254
|
+
var _unitSheetNameMap$map;
|
|
2255
|
+
const { unitId, sheetId, unitSheetNameMap, params } = context;
|
|
2256
|
+
const { range, sheetName, unitId: sequenceUnitId } = deserializeRangeWithSheetWithCache(token);
|
|
2257
|
+
const mapUnitId = sequenceUnitId == null || sequenceUnitId.length === 0 ? unitId : sequenceUnitId;
|
|
2258
|
+
const sequenceSheetId = (unitSheetNameMap === null || unitSheetNameMap === void 0 || (_unitSheetNameMap$map = unitSheetNameMap[mapUnitId]) === null || _unitSheetNameMap$map === void 0 ? void 0 : _unitSheetNameMap$map[sheetName]) || "";
|
|
2259
|
+
if (!checkIsSameUnitAndSheet(params.unitId, params.sheetId, unitId, sheetId, sequenceUnitId, sequenceSheetId)) return null;
|
|
2260
|
+
return {
|
|
2261
|
+
range,
|
|
2262
|
+
sheetId: sequenceSheetId,
|
|
2263
|
+
unitId: sequenceUnitId,
|
|
2264
|
+
sheetName,
|
|
2265
|
+
refOffsetX: item.x || 0,
|
|
2266
|
+
refOffsetY: item.y || 0
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2269
|
+
function appendCrossSheetCutFormulas(data, formulas, params) {
|
|
2270
|
+
const { targetUnitId, targetSheetId, from, to } = params;
|
|
2271
|
+
if (formulas.length === 0 || !targetUnitId || !targetSheetId) return;
|
|
2272
|
+
if (!data[targetUnitId]) data[targetUnitId] = Object.create(null);
|
|
2273
|
+
if (!data[targetUnitId][targetSheetId]) data[targetUnitId][targetSheetId] = Object.create(null);
|
|
2274
|
+
for (const { fromRow, fromColumn, formulaString } of formulas) {
|
|
2275
|
+
const targetRow = fromRow + (((to === null || to === void 0 ? void 0 : to.startRow) ?? 0) - ((from === null || from === void 0 ? void 0 : from.startRow) ?? 0));
|
|
2276
|
+
const targetColumn = fromColumn + (((to === null || to === void 0 ? void 0 : to.startColumn) ?? 0) - ((from === null || from === void 0 ? void 0 : from.startColumn) ?? 0));
|
|
2277
|
+
if (!data[targetUnitId][targetSheetId][targetRow]) data[targetUnitId][targetSheetId][targetRow] = Object.create(null);
|
|
2278
|
+
data[targetUnitId][targetSheetId][targetRow][targetColumn] = { f: formulaString };
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
function isInCrossSheetCutRange(unitId, sheetId, row, column, params) {
|
|
2282
|
+
const { type, unitId: fromUnitId, sheetId: fromSheetId, targetUnitId, targetSheetId, from } = params;
|
|
2283
|
+
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;
|
|
2284
|
+
}
|
|
2285
|
+
function updateTableReference(sequenceNodes, index, node, params) {
|
|
2286
|
+
const { type, oldTableName, tableName, tableColumnNames } = params;
|
|
2287
|
+
if (type !== 16 && type !== 17 && type !== 18) return false;
|
|
2288
|
+
if (node.nodeType !== sequenceNodeType.TABLE && node.nodeType !== sequenceNodeType.FUNCTION) return false;
|
|
2289
|
+
if (oldTableName === void 0 || type === 16 && tableName === void 0) return false;
|
|
2290
|
+
const { tableName: tokenTableName, columnStruct = "" } = splitTableStructuredRef(node.token);
|
|
2291
|
+
if (tokenTableName !== oldTableName) return false;
|
|
2292
|
+
if (type === 18 && !tableReferenceContainsColumn(columnStruct, tableColumnNames)) return false;
|
|
2293
|
+
sequenceNodes[index] = {
|
|
2294
|
+
...node,
|
|
2295
|
+
token: type === 16 ? `${tableName}${columnStruct}` : ErrorType.REF
|
|
2296
|
+
};
|
|
2297
|
+
const nextNode = sequenceNodes[index + 1];
|
|
2298
|
+
if ((type === 17 || type === 18) && typeof nextNode === "string" && nextNode.startsWith("]")) sequenceNodes[index + 1] = nextNode.slice(1);
|
|
2299
|
+
return true;
|
|
2300
|
+
}
|
|
2301
|
+
function getMovedReferenceToken(reference, params, unitId, sheetId, inCrossSheetCutRange) {
|
|
2302
|
+
const { type, sheetId: affectedSheetId, sheetName } = params;
|
|
2303
|
+
if (type === 11 || type === 13) {
|
|
2304
|
+
if (!reference.sheetId || affectedSheetId !== reference.sheetId) return null;
|
|
2305
|
+
if (type === 13) return ErrorType.REF;
|
|
2306
|
+
if (sheetName == null) return null;
|
|
2307
|
+
return serializeRangeToRefString({
|
|
2308
|
+
range: reference.range,
|
|
2309
|
+
sheetName,
|
|
2310
|
+
unitId: reference.unitId
|
|
2311
|
+
});
|
|
2312
|
+
}
|
|
2313
|
+
if (type === 14) return null;
|
|
2314
|
+
return getNewRangeByMoveParam(reference, params, unitId, sheetId, { inCrossSheetCutRange });
|
|
2315
|
+
}
|
|
2316
|
+
function getCrossSheetCutReference(node, reference, newRefString, params) {
|
|
2317
|
+
if (newRefString != null) return {
|
|
2318
|
+
...node,
|
|
2319
|
+
token: newRefString
|
|
2320
|
+
};
|
|
2321
|
+
const { unitId, sheetId, targetUnitId, sheetName } = params;
|
|
2322
|
+
if (reference.unitId && reference.unitId !== unitId || reference.sheetId && reference.sheetId !== sheetId) return null;
|
|
2323
|
+
return {
|
|
2324
|
+
...node,
|
|
2325
|
+
token: serializeRangeToRefString({
|
|
2326
|
+
range: Rectangle.moveOffset(reference.range, reference.refOffsetX || 0, reference.refOffsetY || 0),
|
|
2327
|
+
sheetName: sheetName || reference.sheetName,
|
|
2328
|
+
unitId: targetUnitId !== unitId ? unitId : ""
|
|
2329
|
+
})
|
|
2330
|
+
};
|
|
2331
|
+
}
|
|
2332
|
+
function shouldUnpackSharedFormula(item, row, column, params, modifiedIds) {
|
|
2333
|
+
const { si, x, y } = item;
|
|
2334
|
+
const { type, from } = params;
|
|
2335
|
+
if (!si || ![
|
|
2336
|
+
1,
|
|
2337
|
+
2,
|
|
2338
|
+
0
|
|
2339
|
+
].includes(type)) return false;
|
|
2340
|
+
if (from && from.startRow <= row && row <= from.endRow && from.startColumn <= column && column <= from.endColumn) {
|
|
2341
|
+
if ((x ?? 0) === 0 && (y ?? 0) === 0) modifiedIds.push(si);
|
|
2342
|
+
return true;
|
|
2343
|
+
}
|
|
2344
|
+
return modifiedIds.includes(si);
|
|
2345
|
+
}
|
|
2396
2346
|
/**
|
|
2397
2347
|
* Whether to skip the formula update when the setRangeValues mutation is executed.
|
|
2398
2348
|
* The style-only cell value does not affect the formula calculation, so it can be skipped.
|
|
@@ -2438,13 +2388,7 @@ function tableReferenceContainsColumn(columnStruct, columnNames) {
|
|
|
2438
2388
|
return false;
|
|
2439
2389
|
}
|
|
2440
2390
|
|
|
2441
|
-
|
|
2442
|
-
//#region package.json
|
|
2443
|
-
var name = "@univerjs/sheets-formula";
|
|
2444
|
-
var version = "1.3.1";
|
|
2445
|
-
|
|
2446
|
-
//#endregion
|
|
2447
|
-
//#region src/common/plugin-name.ts
|
|
2391
|
+
// src/common/plugin-name.ts
|
|
2448
2392
|
/**
|
|
2449
2393
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2450
2394
|
*
|
|
@@ -2462,8 +2406,7 @@ var version = "1.3.1";
|
|
|
2462
2406
|
*/
|
|
2463
2407
|
const SHEETS_FORMULA_PLUGIN_NAME = "SHEETS_FORMULA_PLUGIN";
|
|
2464
2408
|
|
|
2465
|
-
|
|
2466
|
-
//#region src/controllers/active-dirty.controller.ts
|
|
2409
|
+
// src/controllers/active-dirty.controller.ts
|
|
2467
2410
|
let ActiveDirtyController = class ActiveDirtyController extends Disposable {
|
|
2468
2411
|
constructor(_activeDirtyManagerService, _univerInstanceService, _formulaDataModel) {
|
|
2469
2412
|
super();
|
|
@@ -2546,6 +2489,10 @@ let ActiveDirtyController = class ActiveDirtyController extends Disposable {
|
|
|
2546
2489
|
});
|
|
2547
2490
|
}
|
|
2548
2491
|
_initialRowAndColumn() {
|
|
2492
|
+
for (const mutation of [SetWorksheetRowCountMutation, SetWorksheetColumnCountMutation]) this._activeDirtyManagerService.register(mutation.id, {
|
|
2493
|
+
commandId: mutation.id,
|
|
2494
|
+
getDirtyData: (command) => ({ dirtyReferenceUnits: [command.params.unitId] })
|
|
2495
|
+
});
|
|
2549
2496
|
this._activeDirtyManagerService.register(RemoveRowMutation.id, {
|
|
2550
2497
|
commandId: RemoveRowMutation.id,
|
|
2551
2498
|
getDirtyData: (command) => {
|
|
@@ -2604,6 +2551,13 @@ let ActiveDirtyController = class ActiveDirtyController extends Disposable {
|
|
|
2604
2551
|
});
|
|
2605
2552
|
}
|
|
2606
2553
|
_initialSheet() {
|
|
2554
|
+
this._activeDirtyManagerService.register(SetWorksheetOrderMutation.id, {
|
|
2555
|
+
commandId: SetWorksheetOrderMutation.id,
|
|
2556
|
+
getDirtyData: (command) => {
|
|
2557
|
+
const { unitId, fromOrder, toOrder } = command.params;
|
|
2558
|
+
return { dirtyReferenceUnits: fromOrder === toOrder ? [] : [unitId] };
|
|
2559
|
+
}
|
|
2560
|
+
});
|
|
2607
2561
|
this._activeDirtyManagerService.register(RemoveSheetMutation.id, {
|
|
2608
2562
|
commandId: RemoveSheetMutation.id,
|
|
2609
2563
|
getDirtyData: (command) => {
|
|
@@ -2787,8 +2741,7 @@ ActiveDirtyController = __decorate([
|
|
|
2787
2741
|
__decorateParam(2, Inject(FormulaDataModel))
|
|
2788
2742
|
], ActiveDirtyController);
|
|
2789
2743
|
|
|
2790
|
-
|
|
2791
|
-
//#region src/controllers/array-formula-cell-interceptor.controller.ts
|
|
2744
|
+
// src/controllers/array-formula-cell-interceptor.controller.ts
|
|
2792
2745
|
let ArrayFormulaCellInterceptorController = class ArrayFormulaCellInterceptorController extends Disposable {
|
|
2793
2746
|
constructor(_commandService, _sheetInterceptorService, _formulaDataModel) {
|
|
2794
2747
|
super();
|
|
@@ -2847,8 +2800,7 @@ ArrayFormulaCellInterceptorController = __decorate([
|
|
|
2847
2800
|
__decorateParam(2, Inject(FormulaDataModel))
|
|
2848
2801
|
], ArrayFormulaCellInterceptorController);
|
|
2849
2802
|
|
|
2850
|
-
|
|
2851
|
-
//#region src/controllers/defined-name.controller.ts
|
|
2803
|
+
// src/controllers/defined-name.controller.ts
|
|
2852
2804
|
let DefinedNameController = class DefinedNameController extends Disposable {
|
|
2853
2805
|
constructor(_descriptionService, _definedNamesService, _univerInstanceService, _commandService) {
|
|
2854
2806
|
super();
|
|
@@ -2990,8 +2942,7 @@ DefinedNameController = __decorate([
|
|
|
2990
2942
|
__decorateParam(3, ICommandService)
|
|
2991
2943
|
], DefinedNameController);
|
|
2992
2944
|
|
|
2993
|
-
|
|
2994
|
-
//#region src/controllers/formula.controller.ts
|
|
2945
|
+
// src/controllers/formula.controller.ts
|
|
2995
2946
|
/**
|
|
2996
2947
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2997
2948
|
*
|
|
@@ -3016,8 +2967,7 @@ let FormulaController = class FormulaController extends Disposable {
|
|
|
3016
2967
|
};
|
|
3017
2968
|
FormulaController = __decorate([__decorateParam(0, ICommandService)], FormulaController);
|
|
3018
2969
|
|
|
3019
|
-
|
|
3020
|
-
//#region src/controllers/sheet-formula-calculation-result-apply.controller.ts
|
|
2970
|
+
// src/controllers/sheet-formula-calculation-result-apply.controller.ts
|
|
3021
2971
|
/**
|
|
3022
2972
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3023
2973
|
*
|
|
@@ -3045,8 +2995,7 @@ let SheetFormulaCalculationResultApplyController = class SheetFormulaCalculation
|
|
|
3045
2995
|
};
|
|
3046
2996
|
SheetFormulaCalculationResultApplyController = __decorate([__decorateParam(0, ICommandService), __decorateParam(1, Inject(FormulaCalculationSessionService))], SheetFormulaCalculationResultApplyController);
|
|
3047
2997
|
|
|
3048
|
-
|
|
3049
|
-
//#region src/controllers/super-table.controller.ts
|
|
2998
|
+
// src/controllers/super-table.controller.ts
|
|
3050
2999
|
let SuperTableController = class SuperTableController extends Disposable {
|
|
3051
3000
|
constructor(_descriptionService, _univerInstanceService, _commandService, _superTableService) {
|
|
3052
3001
|
super();
|
|
@@ -3174,8 +3123,39 @@ SuperTableController = __decorate([
|
|
|
3174
3123
|
__decorateParam(3, ISuperTableService)
|
|
3175
3124
|
], SuperTableController);
|
|
3176
3125
|
|
|
3177
|
-
|
|
3178
|
-
|
|
3126
|
+
// src/services/formula-ref-range.service.ts
|
|
3127
|
+
/**
|
|
3128
|
+
* An inserted row or column that lands inside a registered range stays part of that range, the
|
|
3129
|
+
* same way {@link handleCommonDefaultRangeChangeWithEffectRefCommands} expands a range when the
|
|
3130
|
+
* insertion happens inside it. `registerRangeFormula` splits a range into the segments that are
|
|
3131
|
+
* affected by a command, and an inserted block is not part of any segment, so it has to be
|
|
3132
|
+
* collected separately, otherwise the inserted cells would silently drop out of the range.
|
|
3133
|
+
*/
|
|
3134
|
+
function getInsertedBlocks(command, ranges) {
|
|
3135
|
+
const params = command.params;
|
|
3136
|
+
if (!(params === null || params === void 0 ? void 0 : params.range)) return [];
|
|
3137
|
+
switch (command.id) {
|
|
3138
|
+
case EffectRefRangId.InsertRowCommandId: {
|
|
3139
|
+
const { startRow, endRow } = params.range;
|
|
3140
|
+
return ranges.filter((range) => startRow > range.startRow && startRow <= range.endRow).map((range) => ({
|
|
3141
|
+
startRow,
|
|
3142
|
+
endRow,
|
|
3143
|
+
startColumn: range.startColumn,
|
|
3144
|
+
endColumn: range.endColumn
|
|
3145
|
+
}));
|
|
3146
|
+
}
|
|
3147
|
+
case EffectRefRangId.InsertColCommandId: {
|
|
3148
|
+
const { startColumn, endColumn } = params.range;
|
|
3149
|
+
return ranges.filter((range) => startColumn > range.startColumn && startColumn <= range.endColumn).map((range) => ({
|
|
3150
|
+
startRow: range.startRow,
|
|
3151
|
+
endRow: range.endRow,
|
|
3152
|
+
startColumn,
|
|
3153
|
+
endColumn
|
|
3154
|
+
}));
|
|
3155
|
+
}
|
|
3156
|
+
default: return [];
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3179
3159
|
function getFormulaKeyOffset(lexerTreeBuilder, formulaString, refOffsetX, refOffsetY) {
|
|
3180
3160
|
const sequenceNodes = lexerTreeBuilder.sequenceNodesBuilder(formulaString);
|
|
3181
3161
|
if (sequenceNodes == null) return formulaString;
|
|
@@ -3324,6 +3304,8 @@ let FormulaRefRangeService = class FormulaRefRangeService extends Disposable {
|
|
|
3324
3304
|
const disposableCollection = new DisposableCollection();
|
|
3325
3305
|
const formulaDeps = formulas.map((formula) => this._getFormulaDependcy(unitId, subUnitId, formula, oldRanges));
|
|
3326
3306
|
const handleRangeChange = (commandInfo) => {
|
|
3307
|
+
const wholeRangeResult = this._transformWholeRangeFormulas(unitId, subUnitId, oldRanges, formulas, commandInfo);
|
|
3308
|
+
if (wholeRangeResult) return callback(wholeRangeResult);
|
|
3327
3309
|
const effectedRanges = getSeparateEffectedRangesOnCommand(this._injector, commandInfo);
|
|
3328
3310
|
if (!effectedRanges) return {
|
|
3329
3311
|
undos: [],
|
|
@@ -3415,6 +3397,7 @@ let FormulaRefRangeService = class FormulaRefRangeService extends Disposable {
|
|
|
3415
3397
|
if (keyMap.has(item.key)) keyMap.get(item.key).push(item);
|
|
3416
3398
|
else keyMap.set(item.key, [item]);
|
|
3417
3399
|
}
|
|
3400
|
+
this._appendInsertedBlockItems(keyMap, commandInfo, oldRanges, formulas, oldRanges[0], originKey);
|
|
3418
3401
|
const res = [];
|
|
3419
3402
|
const keys = Array.from(keyMap.keys());
|
|
3420
3403
|
for (let i = keys.length - 1; i >= 0; i--) {
|
|
@@ -3448,6 +3431,40 @@ let FormulaRefRangeService = class FormulaRefRangeService extends Disposable {
|
|
|
3448
3431
|
});
|
|
3449
3432
|
return disposableCollection;
|
|
3450
3433
|
}
|
|
3434
|
+
/**
|
|
3435
|
+
* A whole column/row/sheet range keeps its anchor, so it is adjusted as a single range:
|
|
3436
|
+
* segmenting it would both split the rule and drop the range type.
|
|
3437
|
+
*
|
|
3438
|
+
* @returns the single rule range to apply, or `undefined` when the regular segmentation applies
|
|
3439
|
+
*/
|
|
3440
|
+
_transformWholeRangeFormulas(unitId, subUnitId, oldRanges, formulas, commandInfo) {
|
|
3441
|
+
var _oldRanges$;
|
|
3442
|
+
const ruleRangeType = ((_oldRanges$ = oldRanges[0]) === null || _oldRanges$ === void 0 ? void 0 : _oldRanges$.rangeType) ?? RANGE_TYPE.NORMAL;
|
|
3443
|
+
if (ruleRangeType === RANGE_TYPE.NORMAL || !oldRanges.every((range) => range.rangeType === ruleRangeType)) return;
|
|
3444
|
+
const ranges = handleCommonDefaultRangeChangeWithEffectRefCommands(oldRanges[0], commandInfo);
|
|
3445
|
+
if (!ranges.length) return [];
|
|
3446
|
+
return [{
|
|
3447
|
+
formulas: formulas.map((formula) => isFormulaString(formula) ? this.transformFormulaByEffectCommand(unitId, subUnitId, formula, commandInfo) : formula),
|
|
3448
|
+
ranges
|
|
3449
|
+
}];
|
|
3450
|
+
}
|
|
3451
|
+
_appendInsertedBlockItems(keyMap, commandInfo, oldRanges, formulas, origin, originKey) {
|
|
3452
|
+
for (const block of getInsertedBlocks(commandInfo, oldRanges)) {
|
|
3453
|
+
const offsetRow = block.startRow - origin.startRow;
|
|
3454
|
+
const offsetColumn = block.startColumn - origin.startColumn;
|
|
3455
|
+
const item = {
|
|
3456
|
+
formulas: formulas.map((formula) => ({
|
|
3457
|
+
newFormula: isFormulaString(formula) ? this._lexerTreeBuilder.moveFormulaRefOffset(formula, offsetColumn, offsetRow) : formula,
|
|
3458
|
+
orginFormula: formula
|
|
3459
|
+
})),
|
|
3460
|
+
ranges: [block],
|
|
3461
|
+
key: originKey
|
|
3462
|
+
};
|
|
3463
|
+
const items = keyMap.get(item.key);
|
|
3464
|
+
if (items) items.push(item);
|
|
3465
|
+
else keyMap.set(item.key, [item]);
|
|
3466
|
+
}
|
|
3467
|
+
}
|
|
3451
3468
|
};
|
|
3452
3469
|
FormulaRefRangeService = __decorate([
|
|
3453
3470
|
__decorateParam(0, Inject(RefRangeService)),
|
|
@@ -3456,72 +3473,7 @@ FormulaRefRangeService = __decorate([
|
|
|
3456
3473
|
__decorateParam(3, Inject(Injector))
|
|
3457
3474
|
], FormulaRefRangeService);
|
|
3458
3475
|
|
|
3459
|
-
|
|
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);
|
|
3476
|
+
// src/plugin.ts
|
|
3525
3477
|
let UniverSheetsFormulaPlugin = class UniverSheetsFormulaPlugin extends Plugin {
|
|
3526
3478
|
constructor(_config = defaultPluginBaseConfig, _injector, _configService) {
|
|
3527
3479
|
super();
|
|
@@ -3552,7 +3504,9 @@ let UniverSheetsFormulaPlugin = class UniverSheetsFormulaPlugin extends Plugin {
|
|
|
3552
3504
|
];
|
|
3553
3505
|
if (this._config.notExecuteFormula) {
|
|
3554
3506
|
const rpcChannelService = j.get(IRPCChannelService);
|
|
3555
|
-
dependencies.push([IRemoteRegisterFunctionService, { useFactory:
|
|
3507
|
+
dependencies.push([IRemoteRegisterFunctionService, { useFactory: function createChannelService() {
|
|
3508
|
+
return toModule(rpcChannelService.requestChannel(RemoteRegisterFunctionServiceName));
|
|
3509
|
+
} }]);
|
|
3556
3510
|
}
|
|
3557
3511
|
dependencies.forEach((dependency) => j.add(dependency));
|
|
3558
3512
|
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 +3541,7 @@ UniverSheetsFormulaPlugin = __decorate([
|
|
|
3587
3541
|
__decorateParam(2, IConfigService)
|
|
3588
3542
|
], UniverSheetsFormulaPlugin);
|
|
3589
3543
|
|
|
3590
|
-
|
|
3591
|
-
//#region src/util/calculate.ts
|
|
3544
|
+
// src/util/calculate.ts
|
|
3592
3545
|
function calculateFormula(inject, formulaString, unitId, sheetData) {
|
|
3593
3546
|
const formulaCurrentConfigService = inject.get(IFormulaCurrentConfigService);
|
|
3594
3547
|
const lexer = inject.get(Lexer);
|
|
@@ -3613,5 +3566,4 @@ function calculateFormula(inject, formulaString, unitId, sheetData) {
|
|
|
3613
3566
|
return getObjectValue(result);
|
|
3614
3567
|
}
|
|
3615
3568
|
|
|
3616
|
-
|
|
3617
|
-
export { CalculationMode, FormulaAutoFillController, FormulaRefRangeService, FormulaReorderController, IRemoteRegisterFunctionService, ImageFormulaCellInterceptorController, InsertFunctionCommand, PLUGIN_CONFIG_KEY_BASE, RemoteRegisterFunctionService, TriggerCalculationController, UnitQualifierRenameController, UniverRemoteSheetsFormulaPlugin, UniverSheetsFormulaPlugin, UpdateDefinedNameController, UpdateFormulaController, calculateFormula, collectUnitQualifierFormulaPatches };
|
|
3569
|
+
export { CalculationMode, FormulaAutoFillController, FormulaRefRangeService, FormulaReorderController, IRemoteRegisterFunctionService, ImageFormulaCellInterceptorController, InsertFunctionCommand, PLUGIN_CONFIG_KEY_BASE, RemoteRegisterFunctionService, TriggerCalculationController, UnitQualifierRenameController, UniverSheetsFormulaPlugin, UpdateDefinedNameController, UpdateFormulaController, calculateFormula, collectUnitQualifierFormulaPatches };
|