Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(formula): start calculation trigger (#6321)

Univere52201a7d730
diff --git a/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts b/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts
index cda13bebea..7c46d9be8c 100644
--- a/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts
+++ b/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts
@@ -77,6 +77,12 @@ export const SetFormulaCalculationStartMutation: IMutation<ISetFormulaCalculatio
handler: () => true,
};
+export const SetTriggerFormulaCalculationStartMutation: IMutation<ISetFormulaCalculationStartMutation> = {
+ id: 'formula.mutation.set-trigger-formula-calculation-start',
+ type: CommandType.MUTATION,
+ handler: () => true,
+};
+
export const SetFormulaStringBatchCalculationMutation: IMutation<ISetFormulaStringBatchCalculationMutation> = {
id: 'formula.mutation.set-formula-string-batch-calculation',
type: CommandType.MUTATION,
diff --git a/packages/engine-formula/src/controller/formula.controller.ts b/packages/engine-formula/src/controller/formula.controller.ts
index 972177987b..7593227368 100644
--- a/packages/engine-formula/src/controller/formula.controller.ts
+++ b/packages/engine-formula/src/controller/formula.controller.ts
@@ -37,6 +37,7 @@ import {
SetFormulaStringBatchCalculationResultMutation,
SetQueryFormulaDependencyMutation,
SetQueryFormulaDependencyResultMutation,
+ SetTriggerFormulaCalculationStartMutation,
} from '../commands/mutations/set-formula-calculation.mutation';
import { SetFormulaDataMutation } from '../commands/mutations/set-formula-data.mutation';
import { SetImageFormulaDataMutation } from '../commands/mutations/set-image-formula-data.mutation';
@@ -84,6 +85,7 @@ export class FormulaController extends Disposable {
SetArrayFormulaDataMutation,
SetImageFormulaDataMutation,
SetFormulaCalculationStartMutation,
+ SetTriggerFormulaCalculationStartMutation,
SetFormulaStringBatchCalculationMutation,
SetFormulaStringBatchCalculationResultMutation,
SetQueryFormulaDependencyMutation,
diff --git a/packages/engine-formula/src/facade/f-formula.ts b/packages/engine-formula/src/facade/f-formula.ts
index 3631561715..60168cae21 100644
--- a/packages/engine-formula/src/facade/f-formula.ts
+++ b/packages/engine-formula/src/facade/f-formula.ts
@@ -18,7 +18,7 @@ import type { ICommandInfo, IDisposable, IUnitRange } from '@univerjs/core';
import type { FormulaExecutedStateType, IExecutionInProgressParams, IExprTreeNode, IFormulaDependencyTreeFullJson, IFormulaDependencyTreeJson, IFormulaExecuteResultMap, IFormulaStringMap, ISequenceNode, ISetCellFormulaDependencyCalculationResultMutation, ISetFormulaCalculationNotificationMutation, ISetFormulaCalculationResultMutation, ISetFormulaCalculationStartMutation, ISetFormulaDependencyCalculationResultMutation, ISetFormulaStringBatchCalculationResultMutation } from '@univerjs/engine-formula';
import { ICommandService, IConfigService, Inject, Injector } from '@univerjs/core';
import { FBase } from '@univerjs/core/facade';
-import { ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, GlobalComputingStatusService, IDefinedNamesService, IFunctionService, ISuperTableService, LexerTreeBuilder, SetCellFormulaDependencyCalculationMutation, SetCellFormulaDependencyCalculationResultMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDependencyCalculationMutation, SetFormulaDependencyCalculationResultMutation, SetFormulaStringBatchCalculationMutation, SetFormulaStringBatchCalculationResultMutation, SetQueryFormulaDependencyMutation, SetQueryFormulaDependencyResultMutation } from '@univerjs/engine-formula';
+import { ENGINE_FORMULA_CYCLE_REFERENCE_COUNT, ENGINE_FORMULA_RETURN_DEPENDENCY_TREE, GlobalComputingStatusService, IDefinedNamesService, IFunctionService, ISuperTableService, LexerTreeBuilder, SetCellFormulaDependencyCalculationMutation, SetCellFormulaDependencyCalculationResultMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetFormulaDependencyCalculationMutation, SetFormulaDependencyCalculationResultMutation, SetFormulaStringBatchCalculationMutation, SetFormulaStringBatchCalculationResultMutation, SetQueryFormulaDependencyMutation, SetQueryFormulaDependencyResultMutation, SetTriggerFormulaCalculationStartMutation } from '@univerjs/engine-formula';
import { filter, firstValueFrom, map, race, timer } from 'rxjs';
/**
@@ -100,7 +100,7 @@ export class FFormula extends FBase {
* ```
*/
executeCalculation(): void {
- this._commandService.executeCommand(SetFormulaCalculationStartMutation.id, { commands: [], forceCalculation: true }, { onlyLocal: true });
+ this._commandService.executeCommand(SetTriggerFormulaCalculationStartMutation.id, { commands: [], forceCalculation: true }, { onlyLocal: true });
}
/**
diff --git a/packages/engine-formula/src/index.ts b/packages/engine-formula/src/index.ts
index e1e54aa06d..afc08a2155 100644
--- a/packages/engine-formula/src/index.ts
+++ b/packages/engine-formula/src/index.ts
@@ -75,6 +75,7 @@ export {
SetFormulaStringBatchCalculationResultMutation,
SetQueryFormulaDependencyMutation,
SetQueryFormulaDependencyResultMutation,
+ SetTriggerFormulaCalculationStartMutation,
} from './commands/mutations/set-formula-calculation.mutation';
export { type ISetFormulaDataMutationParams, SetFormulaDataMutation } from './commands/mutations/set-formula-data.mutation';
export { type ISetImageFormulaDataMutationParams, SetImageFormulaDataMutation } from './commands/mutations/set-image-formula-data.mutation';
diff --git a/packages/engine-formula/src/services/active-dirty-manager.service.ts b/packages/engine-formula/src/services/active-dirty-manager.service.ts
index 1a235a2f56..ec480dcc46 100644
--- a/packages/engine-formula/src/services/active-dirty-manager.service.ts
+++ b/packages/engine-formula/src/services/active-dirty-manager.service.ts
@@ -21,6 +21,7 @@ import { createIdentifier, Disposable } from '@univerjs/core';
export interface IDirtyConversionManagerParams {
commandId: string;
getDirtyData: (command: ICommandInfo) => {
+ forceCalculation?: boolean;
dirtyRanges?: IUnitRange[];
dirtyNameMap?: IDirtyUnitSheetNameMap;
dirtyDefinedNameMap?: IDirtyUnitSheetDefinedNameMap;
diff --git a/packages/sheets-formula-ui/src/facade/__tests__/f-formula.spec.ts b/packages/sheets-formula-ui/src/facade/__tests__/f-formula.spec.ts
index 4aa2619d71..5813b35e4d 100644
--- a/packages/sheets-formula-ui/src/facade/__tests__/f-formula.spec.ts
+++ b/packages/sheets-formula-ui/src/facade/__tests__/f-formula.spec.ts
@@ -18,7 +18,7 @@ import type { Injector } from '@univerjs/core';
import type { FUniver } from '@univerjs/core/facade';
import type { IUniverSheetsFormulaBaseConfig } from '@univerjs/sheets-formula';
import { ICommandService, IConfigService } from '@univerjs/core';
-import { SetArrayFormulaDataMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation } from '@univerjs/engine-formula';
+import { SetArrayFormulaDataMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetTriggerFormulaCalculationStartMutation } from '@univerjs/engine-formula';
import { CalculationMode, PLUGIN_CONFIG_KEY_BASE } from '@univerjs/sheets-formula';
import { beforeEach, describe, expect, it } from 'vitest';
import { createFormulaTestBed } from './create-formula-test-bed';
@@ -35,6 +35,7 @@ describe('Test FFormula', () => {
commandService = get(ICommandService);
commandService.registerCommand(SetFormulaCalculationStartMutation);
+ commandService.registerCommand(SetTriggerFormulaCalculationStartMutation);
commandService.registerCommand(SetFormulaCalculationStopMutation);
commandService.registerCommand(SetFormulaCalculationNotificationMutation);
commandService.registerCommand(SetFormulaCalculationResultMutation);
diff --git a/packages/sheets-formula/src/controllers/active-dirty.controller.ts b/packages/sheets-formula/src/controllers/active-dirty.controller.ts
index cf943e4a4c..6aad13c65a 100644
--- a/packages/sheets-formula/src/controllers/active-dirty.controller.ts
+++ b/packages/sheets-formula/src/controllers/active-dirty.controller.ts
@@ -15,7 +15,7 @@
*/
import type { ICellData, ICommandInfo, IObjectMatrixPrimitiveType, IRange, IUnitRange, Nullable } from '@univerjs/core';
-import type { IDirtyUnitSheetDefinedNameMap, IDirtyUnitSheetNameMap, ISetDefinedNameMutationParam } from '@univerjs/engine-formula';
+import type { IDirtyUnitSheetDefinedNameMap, IDirtyUnitSheetNameMap, IFormulaDirtyData, ISetDefinedNameMutationParam } from '@univerjs/engine-formula';
import type {
IInsertColMutationParams,
IInsertRowMutationParams,
@@ -37,7 +37,7 @@ import {
IUniverInstanceService,
ObjectMatrix,
} from '@univerjs/core';
-import { FormulaDataModel, IActiveDirtyManagerService, RemoveDefinedNameMutation, SetDefinedNameMutation } from '@univerjs/engine-formula';
+import { FormulaDataModel, IActiveDirtyManagerService, RemoveDefinedNameMutation, SetDefinedNameMutation, SetTriggerFormulaCalculationStartMutation } from '@univerjs/engine-formula';
import {
InsertColMutation,
InsertRowMutation,
@@ -255,6 +255,16 @@ export class ActiveDirtyController extends Disposable {
}
private _initialSheet() {
+ this._activeDirtyManagerService.register(SetTriggerFormulaCalculationStartMutation.id, {
+ commandId: SetTriggerFormulaCalculationStartMutation.id,
+ getDirtyData: (command: ICommandInfo) => {
+ const params = command.params as IFormulaDirtyData;
+ return {
+ ...params,
+ };
+ },
+ });
+
this._activeDirtyManagerService.register(RemoveSheetMutation.id, {
commandId: RemoveSheetMutation.id,
getDirtyData: (command: ICommandInfo) => {
diff --git a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
index eacb5e3aae..2df2bf2604 100644
--- a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
+++ b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
@@ -38,6 +38,7 @@ import {
SetFormulaCalculationStartMutation,
SetFormulaCalculationStopMutation,
SetFormulaStringBatchCalculationMutation,
+ SetTriggerFormulaCalculationStartMutation,
} from '@univerjs/engine-formula';
import {
ClearSelectionFormatCommand,
@@ -90,11 +91,6 @@ export class TriggerCalculationController extends Disposable {
private _restartCalculation = false;
- /**
- * The mark of forced calculation. If a new mutation triggers dirty area calculation during the forced calculation process, forced calculation is still required.
- */
- private _forceCalculating = false;
-
private readonly _progress$ = new BehaviorSubject<ICalculationProgress>(NilProgress);
readonly progress$ = this._progress$.asObservable();
@@ -232,6 +228,7 @@ export class TriggerCalculationController extends Disposable {
const allDirtyUnitFeatureMap: IDirtyUnitFeatureMap = {};
const allDirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap = {};
const allClearDependencyTreeCache: IDirtyUnitSheetNameMap = {};
+ let allForceCalculation = false;
// const numfmtItemMap: INumfmtItemMap = Tools.deepClone(this._formulaDataModel.getNumfmtItemMap());
@@ -244,7 +241,7 @@ export class TriggerCalculationController extends Disposable {
const params = conversion.getDirtyData(command);
- const { dirtyRanges, dirtyNameMap, dirtyDefinedNameMap, dirtyUnitFeatureMap, dirtyUnitOtherFormulaMap, clearDependencyTreeCache } = params;
+ const { dirtyRanges, dirtyNameMap, dirtyDefinedNameMap, dirtyUnitFeatureMap, dirtyUnitOtherFormulaMap, clearDependencyTreeCache, forceCalculation = false } = params;
if (dirtyRanges != null) {
this._mergeDirtyRanges(allDirtyRanges, dirtyRanges);
@@ -269,6 +266,8 @@ export class TriggerCalculationController extends Disposable {
if (clearDependencyTreeCache != null) {
this._mergeDirtyNameMap(allClearDependencyTreeCache, clearDependencyTreeCache);
}
+
+ allForceCalculation = allForceCalculation || forceCalculation;
}
return {
@@ -277,7 +276,7 @@ export class TriggerCalculationController extends Disposable {
dirtyDefinedNameMap: allDirtyDefinedNameMap,
dirtyUnitFeatureMap: allDirtyUnitFeatureMap,
dirtyUnitOtherFormulaMap: allDirtyUnitOtherFormulaMap,
- forceCalculation: false,
+ forceCalculation: allForceCalculation,
clearDependencyTreeCache: allClearDependencyTreeCache,
// numfmtItemMap,
};
@@ -297,13 +296,15 @@ export class TriggerCalculationController extends Disposable {
this._mergeDirtyUnitFeatureOrOtherFormulaMap(allDirtyUnitOtherFormulaMap, dirtyData2.dirtyUnitOtherFormulaMap);
this._mergeDirtyNameMap(allClearDependencyTreeCache, dirtyData2.clearDependencyTreeCache);
+ const allForceCalculating = dirtyData1.forceCalculation || dirtyData2.forceCalculation;
+
return {
dirtyRanges: allDirtyRanges,
dirtyNameMap: allDirtyNameMap,
dirtyDefinedNameMap: allDirtyDefinedNameMap,
dirtyUnitFeatureMap: allDirtyUnitFeatureMap,
dirtyUnitOtherFormulaMap: allDirtyUnitOtherFormulaMap,
- forceCalculation: !!this._forceCalculating,
+ forceCalculation: allForceCalculating,
clearDependencyTreeCache: allClearDependencyTreeCache,
};
}
@@ -383,13 +384,7 @@ export class TriggerCalculationController extends Disposable {
// eslint-disable-next-line max-lines-per-function, complexity
this._commandService.onCommandExecuted((command: ICommandInfo) => {
- if (command.id === SetFormulaCalculationStartMutation.id) {
- const { forceCalculation = false } = command.params as ISetFormulaCalculationStartMutation;
-
- if (forceCalculation) {
- this._forceCalculating = true;
- }
- } else if (command.id === SetFormulaCalculationStopMutation.id) {
+ if (command.id === SetFormulaCalculationStopMutation.id) {
this.clearProgress();
}
@@ -493,7 +488,6 @@ export class TriggerCalculationController extends Disposable {
calculationProcessCount = 0;
this._doneCalculationTaskCount = 0;
this._totalCalculationTaskCount = 0;
- this._forceCalculating = false;
}
if (state === FormulaExecutedStateType.STOP_EXECUTION && this._restartCalculation) {
@@ -530,7 +524,7 @@ export class TriggerCalculationController extends Disposable {
private _initialExecuteFormula() {
const calculationMode = this._getCalculationMode();
const params = this._getDirtyDataByCalculationMode(calculationMode);
- this._commandService.executeCommand(SetFormulaCalculationStartMutation.id, params, lo);
+ this._commandService.executeCommand(SetTriggerFormulaCalculationStartMutation.id, params, lo);
this._registerOtherFormulaService.calculateStarted$.next(true);
}
diff --git a/packages/sheets-formula/src/controllers/update-formula.controller.ts b/packages/sheets-formula/src/controllers/update-formula.controller.ts
index f0673f8de3..fdc6aa9fe2 100644
--- a/packages/sheets-formula/src/controllers/update-formula.controller.ts
+++ b/packages/sheets-formula/src/controllers/update-formula.controller.ts
@@ -42,7 +42,7 @@ import {
Tools,
UniverInstanceType,
} from '@univerjs/core';
-import { deserializeRangeWithSheetWithCache, ErrorType, FormulaDataModel, generateStringWithSequence, IDefinedNamesService, initSheetFormulaData, LexerTreeBuilder, sequenceNodeType, serializeRangeToRefString, SetArrayFormulaDataMutation, SetFormulaCalculationStartMutation, SetFormulaDataMutation } from '@univerjs/engine-formula';
+import { deserializeRangeWithSheetWithCache, ErrorType, FormulaDataModel, generateStringWithSequence, IDefinedNamesService, initSheetFormulaData, LexerTreeBuilder, sequenceNodeType, serializeRangeToRefString, SetArrayFormulaDataMutation, SetFormulaDataMutation, SetTriggerFormulaCalculationStartMutation } from '@univerjs/engine-formula';
import {
ClearSelectionFormatCommand,
InsertSheetMutation,
@@ -271,7 +271,7 @@ export class UpdateFormulaController extends Disposable {
const calculationMode = config?.initialFormulaComputing ?? CalculationMode.WHEN_EMPTY;
const params = this._getDirtyDataByCalculationMode(calculationMode);
- this._commandService.executeCommand(SetFormulaCalculationStartMutation.id, params, { onlyLocal: true });
+ this._commandService.executeCommand(SetTriggerFormulaCalculationStartMutation.id, params, { onlyLocal: true });
}
private _getDirtyDataByCalculationMode(calculationMode: CalculationMode): IFormulaDirtyData {
diff --git a/packages/sheets-formula/src/facade/f-formula.ts b/packages/sheets-formula/src/facade/f-formula.ts
index 1aba2e27ed..2b3a98bccc 100644
--- a/packages/sheets-formula/src/facade/f-formula.ts
+++ b/packages/sheets-formula/src/facade/f-formula.ts
@@ -19,7 +19,7 @@ import type { IDisposable, ILocales } from '@univerjs/core';
import type { IFunctionInfo } from '@univerjs/engine-formula';
import type { CalculationMode, IRegisterAsyncFunction, IRegisterFunction, ISingleFunctionRegisterParams, IUniverSheetsFormulaBaseConfig } from '@univerjs/sheets-formula';
import { debounce, IConfigService, ILogService, LifecycleService, LifecycleStages } from '@univerjs/core';
-import { SetFormulaCalculationStartMutation } from '@univerjs/engine-formula';
+import { SetTriggerFormulaCalculationStartMutation } from '@univerjs/engine-formula';
import { FFormula } from '@univerjs/engine-formula/facade';
import { IRegisterFunctionService, PLUGIN_CONFIG_KEY_BASE, RegisterFunctionService } from '@univerjs/sheets-formula';
@@ -286,7 +286,7 @@ export class FFormulaSheetsMixin extends FFormula implements IFFormulaSheetsMixi
override _initialize(): void {
this._debouncedFormulaCalculation = debounce(() => {
this._commandService.executeCommand(
- SetFormulaCalculationStartMutation.id,
+ SetTriggerFormulaCalculationStartMutation.id,
{
commands: [],
forceCalculation: true,
diff --git a/packages/sheets-formula/src/facade/f-univer.ts b/packages/sheets-formula/src/facade/f-univer.ts
index 7b16a2f327..0d688a0d3e 100644
--- a/packages/sheets-formula/src/facade/f-univer.ts
+++ b/packages/sheets-formula/src/facade/f-univer.ts
@@ -18,7 +18,7 @@ import type { IDisposable } from '@univerjs/core';
import type { IRegisterFunctionParams } from '@univerjs/sheets-formula';
import { debounce } from '@univerjs/core';
import { FUniver } from '@univerjs/core/facade';
-import { SetFormulaCalculationStartMutation } from '@univerjs/engine-formula';
+import { SetTriggerFormulaCalculationStartMutation } from '@univerjs/engine-formula';
import { IRegisterFunctionService, RegisterFunctionService } from '@univerjs/sheets-formula';
/**
@@ -50,7 +50,7 @@ export class FUniverSheetsFormulaMixin extends FUniver implements IFUniverSheets
override _initialize(): void {
this._debouncedFormulaCalculation = debounce(() => {
this._commandService.executeCommand(
- SetFormulaCalculationStartMutation.id,
+ SetTriggerFormulaCalculationStartMutation.id,
{
commands: [],
forceCalculation: true,
diff --git a/packages/sheets/src/controllers/__tests__/formula/aggregate.spec.ts b/packages/sheets/src/controllers/__tests__/formula/aggregate.spec.ts
index a776848de9..abd2e7f696 100644
--- a/packages/sheets/src/controllers/__tests__/formula/aggregate.spec.ts
+++ b/packages/sheets/src/controllers/__tests__/formula/aggregate.spec.ts
@@ -18,7 +18,7 @@ import type { CellValue, Ctor, Injector, IWorkbookData, Nullable, Worksheet } fr
import type { BaseFunction, IFunctionNames } from '@univerjs/engine-formula';
import type { FFormula } from '@univerjs/engine-formula/facade';
import { ICommandService, LocaleType } from '@univerjs/core';
-import { functionLogical, functionLookup, functionMath, functionMeta, functionStatistical, IFormulaCurrentConfigService, IFormulaRuntimeService, IFunctionService, SetArrayFormulaDataMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation } from '@univerjs/engine-formula';
+import { functionLogical, functionLookup, functionMath, functionMeta, functionStatistical, IFormulaCurrentConfigService, IFormulaRuntimeService, IFunctionService, SetArrayFormulaDataMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetTriggerFormulaCalculationStartMutation } from '@univerjs/engine-formula';
import { beforeEach, describe, expect, it } from 'vitest';
import { SetRangeValuesMutation } from '../../../commands/mutations/set-range-values.mutation';
import { createFunctionTestBed } from './create-function-test-bed';
@@ -361,6 +361,7 @@ describe('Test AGGREGATE formula', () => {
commandService = get(ICommandService);
commandService.registerCommand(SetFormulaCalculationStartMutation);
+ commandService.registerCommand(SetTriggerFormulaCalculationStartMutation);
commandService.registerCommand(SetFormulaCalculationStopMutation);
commandService.registerCommand(SetFormulaCalculationResultMutation);
commandService.registerCommand(SetFormulaCalculationNotificationMutation);
@@ -418,7 +419,7 @@ describe('Test AGGREGATE formula', () => {
...functions
);
- formulaEngine.executeCalculation();
+ commandService.syncExecuteCommand(SetFormulaCalculationStartMutation.id, { forceCalculation: true }, { onlyLocal: true });
await formulaEngine.onCalculationEnd();
getCellValue = (row: number, column: number) => {
diff --git a/packages/sheets/src/controllers/__tests__/formula/aggregate2.spec.ts b/packages/sheets/src/controllers/__tests__/formula/aggregate2.spec.ts
index be164019e6..5317e92c20 100644
--- a/packages/sheets/src/controllers/__tests__/formula/aggregate2.spec.ts
+++ b/packages/sheets/src/controllers/__tests__/formula/aggregate2.spec.ts
@@ -18,7 +18,7 @@ import type { CellValue, Ctor, Injector, IWorkbookData, Nullable, Worksheet } fr
import type { BaseFunction, IFunctionNames } from '@univerjs/engine-formula';
import type { FFormula } from '@univerjs/engine-formula/facade';
import { ICommandService, LocaleType } from '@univerjs/core';
-import { functionLogical, functionLookup, functionMath, functionMeta, functionStatistical, IFormulaCurrentConfigService, IFormulaRuntimeService, IFunctionService, SetArrayFormulaDataMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation } from '@univerjs/engine-formula';
+import { functionLogical, functionLookup, functionMath, functionMeta, functionStatistical, IFormulaCurrentConfigService, IFormulaRuntimeService, IFunctionService, SetArrayFormulaDataMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetTriggerFormulaCalculationStartMutation } from '@univerjs/engine-formula';
import { beforeEach, describe, expect, it } from 'vitest';
import { SetRangeValuesMutation } from '../../../commands/mutations/set-range-values.mutation';
import { createFunctionTestBed } from './create-function-test-bed';
@@ -3339,6 +3339,7 @@ describe('Test AGGREGATE formula 2', () => {
commandService = get(ICommandService);
commandService.registerCommand(SetFormulaCalculationStartMutation);
+ commandService.registerCommand(SetTriggerFormulaCalculationStartMutation);
commandService.registerCommand(SetFormulaCalculationStopMutation);
commandService.registerCommand(SetFormulaCalculationResultMutation);
commandService.registerCommand(SetFormulaCalculationNotificationMutation);
@@ -3396,7 +3397,7 @@ describe('Test AGGREGATE formula 2', () => {
...functions
);
- formulaEngine.executeCalculation();
+ commandService.syncExecuteCommand(SetFormulaCalculationStartMutation.id, { forceCalculation: true }, { onlyLocal: true });
await formulaEngine.onCalculationEnd();
getCellValue = (row: number, column: number) => {
diff --git a/packages/sheets/src/controllers/__tests__/formula/aggregate3.spec.ts b/packages/sheets/src/controllers/__tests__/formula/aggregate3.spec.ts
index d30e963f20..7d2f1ea078 100644
--- a/packages/sheets/src/controllers/__tests__/formula/aggregate3.spec.ts
+++ b/packages/sheets/src/controllers/__tests__/formula/aggregate3.spec.ts
@@ -18,7 +18,7 @@ import type { CellValue, Ctor, Injector, IWorkbookData, Nullable, Worksheet } fr
import type { BaseFunction, IFunctionNames } from '@univerjs/engine-formula';
import type { FFormula } from '@univerjs/engine-formula/facade';
import { ICommandService, LocaleType } from '@univerjs/core';
-import { functionLogical, functionLookup, functionMath, functionMeta, functionStatistical, IFormulaCurrentConfigService, IFormulaRuntimeService, IFunctionService, SetArrayFormulaDataMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation } from '@univerjs/engine-formula';
+import { functionLogical, functionLookup, functionMath, functionMeta, functionStatistical, IFormulaCurrentConfigService, IFormulaRuntimeService, IFunctionService, SetArrayFormulaDataMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetTriggerFormulaCalculationStartMutation } from '@univerjs/engine-formula';
import { beforeEach, describe, expect, it } from 'vitest';
import { SetRangeValuesMutation } from '../../../commands/mutations/set-range-values.mutation';
import { createFunctionTestBed } from './create-function-test-bed';
@@ -199,6 +199,7 @@ describe('Test AGGREGATE formula 3', () => {
commandService = get(ICommandService);
commandService.registerCommand(SetFormulaCalculationStartMutation);
+ commandService.registerCommand(SetTriggerFormulaCalculationStartMutation);
commandService.registerCommand(SetFormulaCalculationStopMutation);
commandService.registerCommand(SetFormulaCalculationResultMutation);
commandService.registerCommand(SetFormulaCalculationNotificationMutation);
@@ -256,7 +257,7 @@ describe('Test AGGREGATE formula 3', () => {
...functions
);
- formulaEngine.executeCalculation();
+ commandService.syncExecuteCommand(SetFormulaCalculationStartMutation.id, { forceCalculation: true }, { onlyLocal: true });
await formulaEngine.onCalculationEnd();
getCellValue = (row: number, column: number) => {
diff --git a/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache.spec.ts b/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache.spec.ts
index d7e55c70f0..8f6c1e4d23 100644
--- a/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache.spec.ts
+++ b/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache.spec.ts
@@ -35,6 +35,7 @@ import {
SetFormulaCalculationResultMutation,
SetFormulaCalculationStartMutation,
SetFormulaCalculationStopMutation,
+ SetTriggerFormulaCalculationStartMutation,
} from '@univerjs/engine-formula';
import { beforeEach, describe, expect, it } from 'vitest';
import { SetRangeValuesMutation } from '../../../commands/mutations/set-range-values.mutation';
@@ -243,6 +244,7 @@ describe('Test inverted index cache 1', () => {
commandService = get(ICommandService);
commandService.registerCommand(SetFormulaCalculationStartMutation);
+ commandService.registerCommand(SetTriggerFormulaCalculationStartMutation);
commandService.registerCommand(SetFormulaCalculationStopMutation);
commandService.registerCommand(SetFormulaCalculationResultMutation);
commandService.registerCommand(SetFormulaCalculationNotificationMutation);
@@ -299,7 +301,7 @@ describe('Test inverted index cache 1', () => {
...functions
);
- formulaEngine.executeCalculation();
+ commandService.syncExecuteCommand(SetFormulaCalculationStartMutation.id, { forceCalculation: true }, { onlyLocal: true });
await formulaEngine.onCalculationEnd();
getCellValue = (row: number, column: number) => {
@@ -335,7 +337,7 @@ describe('Test inverted index cache 1', () => {
},
},
});
- formulaEngine.executeCalculation();
+ commandService.syncExecuteCommand(SetFormulaCalculationStartMutation.id, { forceCalculation: true }, { onlyLocal: true });
await formulaEngine.onCalculationEnd();
// now result should be 1
diff --git a/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache2.spec.ts b/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache2.spec.ts
index 560ec1e10b..f91f5737e5 100644
--- a/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache2.spec.ts
+++ b/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache2.spec.ts
@@ -33,6 +33,7 @@ import {
SetFormulaCalculationResultMutation,
SetFormulaCalculationStartMutation,
SetFormulaCalculationStopMutation,
+ SetTriggerFormulaCalculationStartMutation,
} from '@univerjs/engine-formula';
import { beforeEach, describe, expect, it } from 'vitest';
import { SetRangeValuesMutation } from '../../../commands/mutations/set-range-values.mutation';
@@ -178,6 +179,7 @@ describe('Test inverted index cache 2', () => {
commandService = get(ICommandService);
commandService.registerCommand(SetFormulaCalculationStartMutation);
+ commandService.registerCommand(SetTriggerFormulaCalculationStartMutation);
commandService.registerCommand(SetFormulaCalculationStopMutation);
commandService.registerCommand(SetFormulaCalculationResultMutation);
commandService.registerCommand(SetFormulaCalculationNotificationMutation);
diff --git a/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache3.spec.ts b/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache3.spec.ts
index 702af340f4..3cd78a6b20 100644
--- a/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache3.spec.ts
+++ b/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache3.spec.ts
@@ -31,6 +31,7 @@ import {
SetFormulaCalculationResultMutation,
SetFormulaCalculationStartMutation,
SetFormulaCalculationStopMutation,
+ SetTriggerFormulaCalculationStartMutation,
} from '@univerjs/engine-formula';
import { beforeEach, describe, expect, it } from 'vitest';
import { SetRangeValuesMutation } from '../../../commands/mutations/set-range-values.mutation';
@@ -195,6 +196,7 @@ describe('Test inverted index cache 3', () => {
commandService = get(ICommandService);
commandService.registerCommand(SetFormulaCalculationStartMutation);
+ commandService.registerCommand(SetTriggerFormulaCalculationStartMutation);
commandService.registerCommand(SetFormulaCalculationStopMutation);
commandService.registerCommand(SetFormulaCalculationResultMutation);
commandService.registerCommand(SetFormulaCalculationNotificationMutation);
@@ -251,7 +253,7 @@ describe('Test inverted index cache 3', () => {
...functions
);
- formulaEngine.executeCalculation();
+ commandService.syncExecuteCommand(SetFormulaCalculationStartMutation.id, { forceCalculation: true }, { onlyLocal: true });
await formulaEngine.onCalculationEnd();
getCellValue = (row: number, column: number) => {
diff --git a/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache4.spec.ts b/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache4.spec.ts
index 52ab27754d..57b47f66d2 100644
--- a/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache4.spec.ts
+++ b/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache4.spec.ts
@@ -31,6 +31,7 @@ import {
SetFormulaCalculationResultMutation,
SetFormulaCalculationStartMutation,
SetFormulaCalculationStopMutation,
+ SetTriggerFormulaCalculationStartMutation,
} from '@univerjs/engine-formula';
import { beforeEach, describe, expect, it } from 'vitest';
import { SetRangeValuesMutation } from '../../../commands/mutations/set-range-values.mutation';
@@ -140,6 +141,7 @@ describe('Test inverted index cache 4', () => {
commandService = get(ICommandService);
commandService.registerCommand(SetFormulaCalculationStartMutation);
+ commandService.registerCommand(SetTriggerFormulaCalculationStartMutation);
commandService.registerCommand(SetFormulaCalculationStopMutation);
commandService.registerCommand(SetFormulaCalculationResultMutation);
commandService.registerCommand(SetFormulaCalculationNotificationMutation);
@@ -196,7 +198,7 @@ describe('Test inverted index cache 4', () => {
...functions
);
- formulaEngine.executeCalculation();
+ commandService.syncExecuteCommand(SetFormulaCalculationStartMutation.id, { forceCalculation: true }, { onlyLocal: true });
await formulaEngine.onCalculationEnd();
getCellValue = (row: number, column: number) => {
diff --git a/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache5.spec.ts b/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache5.spec.ts
index 4e4fc8a021..cc0fe3214e 100644
--- a/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache5.spec.ts
+++ b/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache5.spec.ts
@@ -29,6 +29,7 @@ import {
SetFormulaCalculationResultMutation,
SetFormulaCalculationStartMutation,
SetFormulaCalculationStopMutation,
+ SetTriggerFormulaCalculationStartMutation,
} from '@univerjs/engine-formula';
import { beforeEach, describe, expect, it } from 'vitest';
import { SetRangeValuesMutation } from '../../../commands/mutations/set-range-values.mutation';
@@ -1790,6 +1791,7 @@ describe('Test inverted index cache 5', () => {
commandService = get(ICommandService);
commandService.registerCommand(SetFormulaCalculationStartMutation);
+ commandService.registerCommand(SetTriggerFormulaCalculationStartMutation);
commandService.registerCommand(SetFormulaCalculationStopMutation);
commandService.registerCommand(SetFormulaCalculationResultMutation);
commandService.registerCommand(SetFormulaCalculationNotificationMutation);
@@ -1844,7 +1846,7 @@ describe('Test inverted index cache 5', () => {
...functions
);
- formulaEngine.executeCalculation();
+ commandService.syncExecuteCommand(SetFormulaCalculationStartMutation.id, { forceCalculation: true }, { onlyLocal: true });
await formulaEngine.onCalculationEnd();
getCellValue = (row: number, column: number) => {
diff --git a/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache6.spec.ts b/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache6.spec.ts
index 811a604a6d..9ecf70a6d3 100644
--- a/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache6.spec.ts
+++ b/packages/sheets/src/controllers/__tests__/formula/array-inverted-index-cache6.spec.ts
@@ -18,7 +18,7 @@ import type { CellValue, CellValueType, Ctor, Injector, IWorkbookData, Nullable,
import type { BaseFunction, IFunctionNames } from '@univerjs/engine-formula';
import type { FFormula } from '@univerjs/engine-formula/facade';
import { ICommandService, LocaleType } from '@univerjs/core';
-import { FormulaDataModel, functionMeta, IFormulaCurrentConfigService, IFormulaRuntimeService, IFunctionService, SetArrayFormulaDataMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation } from '@univerjs/engine-formula';
+import { FormulaDataModel, functionMeta, IFormulaCurrentConfigService, IFormulaRuntimeService, IFunctionService, SetArrayFormulaDataMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetTriggerFormulaCalculationStartMutation } from '@univerjs/engine-formula';
import { beforeEach, describe, expect, it } from 'vitest';
import { SetRangeValuesMutation } from '../../../commands/mutations/set-range-values.mutation';
import { createFunctionTestBed } from './create-function-test-bed';
@@ -326,6 +326,7 @@ describe('Test inverted index cache 6', () => {
commandService = get(ICommandService);
commandService.registerCommand(SetFormulaCalculationStartMutation);
+ commandService.registerCommand(SetTriggerFormulaCalculationStartMutation);
commandService.registerCommand(SetFormulaCalculationStopMutation);
commandService.registerCommand(SetFormulaCalculationResultMutation);
commandService.registerCommand(SetFormulaCalculationNotificationMutation);
@@ -379,7 +380,7 @@ describe('Test inverted index cache 6', () => {
...functions
);
- formulaEngine.executeCalculation();
+ commandService.syncExecuteCommand(SetFormulaCalculationStartMutation.id, { forceCalculation: true }, { onlyLocal: true });
await formulaEngine.onCalculationEnd();
getArrayFormulaResult = (row: number, column: number) => {
diff --git a/packages/sheets/src/controllers/__tests__/formula/countifs.spec.ts b/packages/sheets/src/controllers/__tests__/formula/countifs.spec.ts
index bb6a04bfc6..d179ad3b31 100644
--- a/packages/sheets/src/controllers/__tests__/formula/countifs.spec.ts
+++ b/packages/sheets/src/controllers/__tests__/formula/countifs.spec.ts
@@ -33,6 +33,7 @@ import {
SetFormulaCalculationResultMutation,
SetFormulaCalculationStartMutation,
SetFormulaCalculationStopMutation,
+ SetTriggerFormulaCalculationStartMutation,
} from '@univerjs/engine-formula';
import { beforeEach, describe, expect, it } from 'vitest';
import { SetRangeValuesMutation } from '../../../commands/mutations/set-range-values.mutation';
@@ -147,6 +148,7 @@ describe('Test inverted index cache', () => {
commandService = get(ICommandService);
commandService.registerCommand(SetFormulaCalculationStartMutation);
+ commandService.registerCommand(SetTriggerFormulaCalculationStartMutation);
commandService.registerCommand(SetFormulaCalculationStopMutation);
commandService.registerCommand(SetFormulaCalculationResultMutation);
commandService.registerCommand(SetFormulaCalculationNotificationMutation);
@@ -201,7 +203,7 @@ describe('Test inverted index cache', () => {
...functions
);
- formulaEngine.executeCalculation();
+ commandService.syncExecuteCommand(SetFormulaCalculationStartMutation.id, { forceCalculation: true }, { onlyLocal: true });
await formulaEngine.onCalculationEnd();
getCellValue = (row: number, column: number) => {
diff --git a/packages/sheets/src/controllers/__tests__/formula/subtotal-offset.spec.ts b/packages/sheets/src/controllers/__tests__/formula/subtotal-offset.spec.ts
index e126c7ac64..fd403d759f 100644
--- a/packages/sheets/src/controllers/__tests__/formula/subtotal-offset.spec.ts
+++ b/packages/sheets/src/controllers/__tests__/formula/subtotal-offset.spec.ts
@@ -17,7 +17,7 @@
import type { Ctor, Injector, IWorkbookData } from '@univerjs/core';
import type { BaseAstNode, BaseFunction, IFunctionNames, LexerNode } from '@univerjs/engine-formula';
import { ICommandService, LocaleType } from '@univerjs/core';
-import { AstTreeBuilder, ErrorType, functionLookup, functionMath, functionMeta, functionStatistical, generateExecuteAstNodeData, getObjectValue, IFormulaCurrentConfigService, IFormulaRuntimeService, IFunctionService, Interpreter, Lexer, SetArrayFormulaDataMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation } from '@univerjs/engine-formula';
+import { AstTreeBuilder, ErrorType, functionLookup, functionMath, functionMeta, functionStatistical, generateExecuteAstNodeData, getObjectValue, IFormulaCurrentConfigService, IFormulaRuntimeService, IFunctionService, Interpreter, Lexer, SetArrayFormulaDataMutation, SetFormulaCalculationNotificationMutation, SetFormulaCalculationResultMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, SetTriggerFormulaCalculationStartMutation } from '@univerjs/engine-formula';
import { beforeEach, describe, expect, it } from 'vitest';
import { SetRangeValuesMutation } from '../../../commands/mutations/set-range-values.mutation';
import { createFunctionTestBed } from './create-function-test-bed';
@@ -1015,6 +1015,7 @@ describe('Test SUBTOTAL formula', () => {
commandService = get(ICommandService);
commandService.registerCommand(SetFormulaCalculationStartMutation);
+ commandService.registerCommand(SetTriggerFormulaCalculationStartMutation);
commandService.registerCommand(SetFormulaCalculationStopMutation);
commandService.registerCommand(SetFormulaCalculationResultMutation);
commandService.registerCommand(SetFormulaCalculationNotificationMutation);
diff --git a/packages/sheets/src/controllers/__tests__/formula/sumifs.spec.ts b/packages/sheets/src/controllers/__tests__/formula/sumifs.spec.ts
index db233d5236..6185198159 100644
--- a/packages/sheets/src/controllers/__tests__/formula/sumifs.spec.ts
+++ b/packages/sheets/src/controllers/__tests__/formula/sumifs.spec.ts
@@ -35,6 +35,7 @@ import {
SetFormulaCalculationResultMutation,
SetFormulaCalculationStartMutation,
SetFormulaCalculationStopMutation,
+ SetTriggerFormulaCalculationStartMutation,
} from '@univerjs/engine-formula';
import { beforeEach, describe, expect, it } from 'vitest';
import { SetRangeValuesMutation } from '../../../commands/mutations/set-range-values.mutation';
@@ -391,6 +392,7 @@ describe('Test inverted index cache', () => {
commandService = get(ICommandService);
commandService.registerCommand(SetFormulaCalculationStartMutation);
+ commandService.registerCommand(SetTriggerFormulaCalculationStartMutation);
commandService.registerCommand(SetFormulaCalculationStopMutation);
commandService.registerCommand(SetFormulaCalculationResultMutation);
commandService.registerCommand(SetFormulaCalculationNotificationMutation);
@@ -447,7 +449,7 @@ describe('Test inverted index cache', () => {
...functions
);
- formulaEngine.executeCalculation();
+ commandService.syncExecuteCommand(SetFormulaCalculationStartMutation.id, { forceCalculation: true }, { onlyLocal: true });
await formulaEngine.onCalculationEnd();
getCellValue = (subUnitId: string, row: number, column: number) => {