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.

refactor(formula): remove formula plugin (#665)

Univerc960e64b6382
diff --git a/examples/sheets/package.json b/examples/sheets/package.json
index a225bcad2f..8643b5f203 100644
--- a/examples/sheets/package.json
+++ b/examples/sheets/package.json
@@ -17,7 +17,6 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/rpc": "workspace:*",
- "@univerjs/formula": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
"@univerjs/sheets-numfmt": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
diff --git a/examples/sheets/src/main.ts b/examples/sheets/src/main.ts
index f35d1279f9..1b9321551e 100644
--- a/examples/sheets/src/main.ts
+++ b/examples/sheets/src/main.ts
@@ -3,7 +3,6 @@ import { greenTheme } from '@univerjs/design';
import { DocsPlugin, RichTextEditingMutation } from '@univerjs/docs';
import { BaseFormulaEnginePlugin } from '@univerjs/engine-formula';
import { RenderEngine } from '@univerjs/engine-render';
-import { FormulaPlugin } from '@univerjs/formula';
import type { IUniverRPCMainThreadPluginConfig } from '@univerjs/rpc';
import { UniverRPCMainThreadPlugin } from '@univerjs/rpc';
import { SheetsPlugin } from '@univerjs/sheets';
@@ -37,17 +36,21 @@ univer.registerPlugin(UIPlugin, {
toolbar: true,
footer: true,
});
-univer.registerPlugin(SheetsPlugin);
+univer.registerPlugin(SheetsPlugin, {
+ notExecuteFormula: true,
+});
univer.registerPlugin(SheetsUIPlugin);
// sheet feature plugins
univer.registerPlugin(NumfmtPlugin);
univer.registerPlugin(DebuggerPlugin);
-univer.registerPlugin(BaseFormulaEnginePlugin);
-univer.registerPlugin(FormulaPlugin, {
+univer.registerPlugin(BaseFormulaEnginePlugin, {
notExecuteFormula: true,
});
+// univer.registerPlugin(FormulaPlugin, {
+// notExecuteFormula: true,
+// });
univer.registerPlugin(FormulaUIPlugin);
univer.registerPlugin(UniverRPCMainThreadPlugin, {
workerURL: './worker.js',
diff --git a/examples/sheets/src/worker.ts b/examples/sheets/src/worker.ts
index 6fef84c458..595bbb8d43 100644
--- a/examples/sheets/src/worker.ts
+++ b/examples/sheets/src/worker.ts
@@ -2,7 +2,6 @@
import { LocaleType, Univer } from '@univerjs/core';
import { BaseFormulaEnginePlugin } from '@univerjs/engine-formula';
-import { FormulaPlugin } from '@univerjs/formula';
import { UniverRPCWorkerThreadPlugin } from '@univerjs/rpc';
import { SheetsPlugin } from '@univerjs/sheets';
@@ -14,7 +13,7 @@ const univer = new Univer({
univer.registerPlugin(SheetsPlugin);
univer.registerPlugin(BaseFormulaEnginePlugin);
univer.registerPlugin(UniverRPCWorkerThreadPlugin);
-univer.registerPlugin(FormulaPlugin);
+// univer.registerPlugin(FormulaPlugin);
declare let self: WorkerGlobalScope & typeof globalThis & { univer: Univer };
self.univer = univer;
diff --git a/packages/formula/src/commands/mutations/set-array-formula-data.mutation.ts b/packages/engine-formula/src/commands/mutations/set-array-formula-data.mutation.ts
similarity index 97%
rename from packages/formula/src/commands/mutations/set-array-formula-data.mutation.ts
rename to packages/engine-formula/src/commands/mutations/set-array-formula-data.mutation.ts
index a27cb0eb35..eff6a5a6d3 100644
--- a/packages/formula/src/commands/mutations/set-array-formula-data.mutation.ts
+++ b/packages/engine-formula/src/commands/mutations/set-array-formula-data.mutation.ts
@@ -1,8 +1,8 @@
import type { IMutation } from '@univerjs/core';
import { CommandType, Tools } from '@univerjs/core';
-import type { IArrayFormulaRangeType, IArrayFormulaUnitCellType } from '@univerjs/engine-formula';
import type { IAccessor } from '@wendellhu/redi';
+import type { IArrayFormulaRangeType, IArrayFormulaUnitCellType } from '../../basics/common';
import { FormulaDataModel } from '../../models/formula-data.model';
export interface ISetArrayFormulaDataMutationParams {
diff --git a/packages/formula/src/commands/mutations/set-formula-calculation.mutation.ts b/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts
similarity index 67%
rename from packages/formula/src/commands/mutations/set-formula-calculation.mutation.ts
rename to packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts
index a664785376..0900839d6d 100644
--- a/packages/formula/src/commands/mutations/set-formula-calculation.mutation.ts
+++ b/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts
@@ -1,10 +1,13 @@
-import type { ICommandInfo, IMutation } from '@univerjs/core';
+import type { ICommandInfo, IExecutionOptions, IMutation, Nullable } from '@univerjs/core';
import { CommandType } from '@univerjs/core';
-import type { FormulaExecutedStateType, IExecutionInProgressParams } from '@univerjs/engine-formula';
import type { IAccessor } from '@wendellhu/redi';
+import type { IRuntimeOtherUnitDataType, IRuntimeUnitDataType } from '../../basics/common';
+import type { FormulaExecutedStateType, IExecutionInProgressParams } from '../../services/runtime.service';
+
export interface ISetFormulaCalculationStartMutation {
commands: ICommandInfo[];
+ options: Nullable<IExecutionOptions>;
forceCalculation?: boolean;
}
/**
@@ -35,3 +38,14 @@ export const SetFormulaCalculationNotificationMutation: IMutation<ISetFormulaCal
type: CommandType.MUTATION,
handler: (accessor: IAccessor, params: ISetFormulaCalculationNotificationMutation) => true,
};
+
+export interface ISetFormulaCalculationResultMutation {
+ unitData: IRuntimeUnitDataType;
+ unitOtherData: IRuntimeOtherUnitDataType;
+}
+
+export const SetFormulaCalculationResultMutation: IMutation<ISetFormulaCalculationResultMutation> = {
+ id: 'formula.mutation.set-formula-calculation-result',
+ type: CommandType.MUTATION,
+ handler: (accessor: IAccessor, params: ISetFormulaCalculationResultMutation) => true,
+};
diff --git a/packages/formula/src/commands/mutations/set-formula-data.mutation.ts b/packages/engine-formula/src/commands/mutations/set-formula-data.mutation.ts
similarity index 91%
rename from packages/formula/src/commands/mutations/set-formula-data.mutation.ts
rename to packages/engine-formula/src/commands/mutations/set-formula-data.mutation.ts
index 7ee2e90f4c..6939345bc4 100644
--- a/packages/formula/src/commands/mutations/set-formula-data.mutation.ts
+++ b/packages/engine-formula/src/commands/mutations/set-formula-data.mutation.ts
@@ -1,8 +1,8 @@
import type { IMutation } from '@univerjs/core';
import { CommandType } from '@univerjs/core';
-import type { IFormulaData } from '@univerjs/engine-formula';
import type { IAccessor } from '@wendellhu/redi';
+import type { IFormulaData } from '../../basics/common';
import { FormulaDataModel } from '../../models/formula-data.model';
export interface ISetFormulaDataMutationParams {
diff --git a/packages/formula/src/controllers/calculate.controller.ts b/packages/engine-formula/src/controller/calculate.controller.ts
similarity index 79%
rename from packages/formula/src/controllers/calculate.controller.ts
rename to packages/engine-formula/src/controller/calculate.controller.ts
index b7522990ce..3b614f27a0 100644
--- a/packages/formula/src/controllers/calculate.controller.ts
+++ b/packages/engine-formula/src/controller/calculate.controller.ts
@@ -1,29 +1,24 @@
import type { ICommandInfo, IUnitRange } from '@univerjs/core';
import { Disposable, ICommandService, IUniverInstanceService, LifecycleStages, OnLifecycle } from '@univerjs/core';
-import type {
- IAllRuntimeData,
- IDirtyUnitFeatureMap,
- IDirtyUnitSheetNameMap,
- IFormulaData,
-} from '@univerjs/engine-formula';
-import { FormulaEngineService, FormulaExecutedStateType, IActiveDirtyManagerService } from '@univerjs/engine-formula';
-import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
-import { SetRangeValuesMutation } from '@univerjs/sheets';
import { Inject } from '@wendellhu/redi';
+import type { IDirtyUnitFeatureMap, IDirtyUnitSheetNameMap, IFormulaData } from '../basics/common';
import type { ISetArrayFormulaDataMutationParams } from '../commands/mutations/set-array-formula-data.mutation';
import { SetArrayFormulaDataMutation } from '../commands/mutations/set-array-formula-data.mutation';
import type { ISetFormulaCalculationStartMutation } from '../commands/mutations/set-formula-calculation.mutation';
import {
SetFormulaCalculationNotificationMutation,
+ SetFormulaCalculationResultMutation,
SetFormulaCalculationStartMutation,
SetFormulaCalculationStopMutation,
} from '../commands/mutations/set-formula-calculation.mutation';
import type { ISetFormulaDataMutationParams } from '../commands/mutations/set-formula-data.mutation';
import { SetFormulaDataMutation } from '../commands/mutations/set-formula-data.mutation';
import { FormulaDataModel } from '../models/formula-data.model';
-import type { FormulaService } from '../services/formula.service';
-import { IFormulaService } from '../services/formula.service';
+import { IActiveDirtyManagerService } from '../services/active-dirty-manager.service';
+import { FormulaEngineService } from '../services/formula-engine.service';
+import type { IAllRuntimeData } from '../services/runtime.service';
+import { FormulaExecutedStateType } from '../services/runtime.service';
@OnLifecycle(LifecycleStages.Ready, CalculateController)
export class CalculateController extends Disposable {
@@ -31,7 +26,6 @@ export class CalculateController extends Disposable {
@ICommandService private readonly _commandService: ICommandService,
@Inject(FormulaEngineService) private readonly _formulaEngineService: FormulaEngineService,
@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,
- @Inject(IFormulaService) private readonly _formulaService: FormulaService,
@Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel,
@IActiveDirtyManagerService private readonly _activeDirtyManagerService: IActiveDirtyManagerService
) {
@@ -43,13 +37,13 @@ export class CalculateController extends Disposable {
private _initialize(): void {
this._commandExecutedListener();
this._initialExecuteFormulaListener();
- this._registerFunctions();
+
this._initialExecuteFormulaProcessListener();
}
private _commandExecutedListener() {
this.disposeWithMe(
- this._commandService.onCommandExecuted((command: ICommandInfo) => {
+ this._commandService.onCommandExecuted((command: ICommandInfo, options) => {
if (command.id === SetFormulaCalculationStopMutation.id) {
this._formulaEngineService.stopFormulaExecution();
} else if (command.id === SetFormulaDataMutation.id) {
@@ -197,9 +191,15 @@ export class CalculateController extends Disposable {
break;
}
- this._commandService.executeCommand(SetFormulaCalculationNotificationMutation.id, {
- functionsExecutedState,
- });
+ this._commandService.executeCommand(
+ SetFormulaCalculationNotificationMutation.id,
+ {
+ functionsExecutedState,
+ },
+ {
+ local: true,
+ }
+ );
});
}
@@ -226,14 +226,20 @@ export class CalculateController extends Disposable {
);
}
- this._commandService.executeCommand(SetFormulaCalculationNotificationMutation.id, {
- stageInfo: data,
- });
+ this._commandService.executeCommand(
+ SetFormulaCalculationNotificationMutation.id,
+ {
+ stageInfo: data,
+ },
+ {
+ local: true,
+ }
+ );
});
}
private async _applyFormula(data: IAllRuntimeData) {
- const { unitData, arrayFormulaRange, arrayFormulaCellData, clearArrayFormulaCellData } = data;
+ const { unitData, unitOtherData, arrayFormulaRange, arrayFormulaCellData, clearArrayFormulaCellData } = data;
if (!unitData) {
console.error('No sheetData from Formula Engine!');
@@ -250,46 +256,27 @@ export class CalculateController extends Disposable {
this._formulaDataModel.mergeArrayFormulaRange(arrayFormulaRange);
// Synchronous to the main thread
- this._commandService.executeCommand(SetArrayFormulaDataMutation.id, {
- arrayFormulaRange: this._formulaDataModel.getArrayFormulaRange(),
- arrayFormulaCellData: this._formulaDataModel.getArrayFormulaCellData(),
- });
+ this._commandService.executeCommand(
+ SetArrayFormulaDataMutation.id,
+ {
+ arrayFormulaRange: this._formulaDataModel.getArrayFormulaRange(),
+ arrayFormulaCellData: this._formulaDataModel.getArrayFormulaCellData(),
+ },
+ {
+ local: true,
+ }
+ );
}
- const unitIds = Object.keys(unitData);
-
- // Update each calculated value, possibly involving all cells
- const redoMutationsInfo: ICommandInfo[] = [];
-
- unitIds.forEach((unitId) => {
- const sheetData = unitData[unitId];
-
- const sheetIds = Object.keys(sheetData);
-
- sheetIds.forEach((sheetId) => {
- const cellData = sheetData[sheetId];
-
- // const arrayFormula = arrayFormulaRange[unitId][sheetId];
-
- const setRangeValuesMutation: ISetRangeValuesMutationParams = {
- worksheetId: sheetId,
- workbookId: unitId,
- cellValue: cellData.getData(),
- isFormulaUpdate: true,
- };
-
- redoMutationsInfo.push({
- id: SetRangeValuesMutation.id,
- params: setRangeValuesMutation,
- });
- });
- });
-
- const result = redoMutationsInfo.every((m) => this._commandService.executeCommand(m.id, m.params));
- return result;
- }
-
- private _registerFunctions() {
- this._formulaService.registerFunctions();
+ this._commandService.executeCommand(
+ SetFormulaCalculationResultMutation.id,
+ {
+ unitData,
+ unitOtherData,
+ },
+ {
+ local: true,
+ }
+ );
}
}
diff --git a/packages/formula/src/controllers/formula.controller.ts b/packages/engine-formula/src/controller/formula.controller.ts
similarity index 92%
rename from packages/formula/src/controllers/formula.controller.ts
rename to packages/engine-formula/src/controller/formula.controller.ts
index e8e9e02aef..60bf629357 100644
--- a/packages/formula/src/controllers/formula.controller.ts
+++ b/packages/engine-formula/src/controller/formula.controller.ts
@@ -3,6 +3,7 @@ import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univ
import { SetArrayFormulaDataMutation } from '../commands/mutations/set-array-formula-data.mutation';
import {
SetFormulaCalculationNotificationMutation,
+ SetFormulaCalculationResultMutation,
SetFormulaCalculationStartMutation,
SetFormulaCalculationStopMutation,
} from '../commands/mutations/set-formula-calculation.mutation';
@@ -27,6 +28,7 @@ export class FormulaController extends Disposable {
SetFormulaCalculationStartMutation,
SetFormulaCalculationStopMutation,
SetFormulaCalculationNotificationMutation,
+ SetFormulaCalculationResultMutation,
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
}
}
diff --git a/packages/formula/src/services/function-list/array/function-names.ts b/packages/engine-formula/src/functions/array/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/array/function-names.ts
rename to packages/engine-formula/src/functions/array/function-names.ts
diff --git a/packages/formula/src/services/function-list/compatibility/function-names.ts b/packages/engine-formula/src/functions/compatibility/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/compatibility/function-names.ts
rename to packages/engine-formula/src/functions/compatibility/function-names.ts
diff --git a/packages/formula/src/services/function-list/cube/function-names.ts b/packages/engine-formula/src/functions/cube/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/cube/function-names.ts
rename to packages/engine-formula/src/functions/cube/function-names.ts
diff --git a/packages/formula/src/services/function-list/database/function-names.ts b/packages/engine-formula/src/functions/database/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/database/function-names.ts
rename to packages/engine-formula/src/functions/database/function-names.ts
diff --git a/packages/formula/src/services/function-list/date/function-names.ts b/packages/engine-formula/src/functions/date/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/date/function-names.ts
rename to packages/engine-formula/src/functions/date/function-names.ts
diff --git a/packages/formula/src/services/function-list/engineering/function-names.ts b/packages/engine-formula/src/functions/engineering/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/engineering/function-names.ts
rename to packages/engine-formula/src/functions/engineering/function-names.ts
diff --git a/packages/formula/src/services/function-list/financial/function-names.ts b/packages/engine-formula/src/functions/financial/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/financial/function-names.ts
rename to packages/engine-formula/src/functions/financial/function-names.ts
diff --git a/packages/formula/src/services/function-list/information/function-names.ts b/packages/engine-formula/src/functions/information/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/information/function-names.ts
rename to packages/engine-formula/src/functions/information/function-names.ts
diff --git a/packages/formula/src/services/function-list/logical/function-names.ts b/packages/engine-formula/src/functions/logical/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/logical/function-names.ts
rename to packages/engine-formula/src/functions/logical/function-names.ts
diff --git a/packages/formula/src/services/function-list/lookup/function-names.ts b/packages/engine-formula/src/functions/lookup/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/lookup/function-names.ts
rename to packages/engine-formula/src/functions/lookup/function-names.ts
diff --git a/packages/formula/src/services/function-list/math/function-names.ts b/packages/engine-formula/src/functions/math/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/math/function-names.ts
rename to packages/engine-formula/src/functions/math/function-names.ts
diff --git a/packages/formula/src/services/function-list/math/sumif/__tests__/sumif.spec.ts b/packages/engine-formula/src/functions/math/sumif/__tests__/sumif.spec.ts
similarity index 100%
rename from packages/formula/src/services/function-list/math/sumif/__tests__/sumif.spec.ts
rename to packages/engine-formula/src/functions/math/sumif/__tests__/sumif.spec.ts
diff --git a/packages/formula/src/services/function-list/math/sumif/sumif.ts b/packages/engine-formula/src/functions/math/sumif/sumif.ts
similarity index 77%
rename from packages/formula/src/services/function-list/math/sumif/sumif.ts
rename to packages/engine-formula/src/functions/math/sumif/sumif.ts
index ed420ef90d..cb7c5d4706 100644
--- a/packages/formula/src/services/function-list/math/sumif/sumif.ts
+++ b/packages/engine-formula/src/functions/math/sumif/sumif.ts
@@ -1,12 +1,12 @@
-import type {
- ArrayValueObject,
- BaseReferenceObject,
- BaseValueObject,
- BooleanValueObject,
- compareToken,
- FunctionVariantType,
-} from '@univerjs/engine-formula';
-import { BaseFunction, ErrorType, ErrorValueObject, NumberValueObject } from '@univerjs/engine-formula';
+import { ErrorType } from '../../../basics/error-type';
+import type { compareToken } from '../../../basics/token';
+import { ErrorValueObject } from '../../../engine/other-object/error-value-object';
+import type { BaseReferenceObject, FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';
+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';
+import type { BooleanValueObject } from '../../../engine/value-object/primitive-object';
+import { NumberValueObject } from '../../../engine/value-object/primitive-object';
+import { BaseFunction } from '../../base-function';
export class Sumif extends BaseFunction {
override calculate(...variants: FunctionVariantType[]) {
diff --git a/packages/formula/src/services/function-list/math/sumifs/__tests__/sumifs.spec.ts b/packages/engine-formula/src/functions/math/sumifs/__tests__/sumifs.spec.ts
similarity index 100%
rename from packages/formula/src/services/function-list/math/sumifs/__tests__/sumifs.spec.ts
rename to packages/engine-formula/src/functions/math/sumifs/__tests__/sumifs.spec.ts
diff --git a/packages/engine-formula/src/functions/math/sumifs/sumifs.ts b/packages/engine-formula/src/functions/math/sumifs/sumifs.ts
new file mode 100644
index 0000000000..506c9f62c8
--- /dev/null
+++ b/packages/engine-formula/src/functions/math/sumifs/sumifs.ts
@@ -0,0 +1,10 @@
+import { ErrorType } from '../../../basics/error-type';
+import { ErrorValueObject } from '../../../engine/other-object/error-value-object';
+import type { FunctionVariantType } from '../../../engine/reference-object/base-reference-object';
+import { BaseFunction } from '../../base-function';
+
+export class Sumifs extends BaseFunction {
+ override calculate(...variants: FunctionVariantType[]) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+}
diff --git a/packages/formula/src/services/function-list/statistical/function-names.ts b/packages/engine-formula/src/functions/statistical/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/statistical/function-names.ts
rename to packages/engine-formula/src/functions/statistical/function-names.ts
diff --git a/packages/formula/src/services/function-list/text/function-names.ts b/packages/engine-formula/src/functions/text/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/text/function-names.ts
rename to packages/engine-formula/src/functions/text/function-names.ts
diff --git a/packages/formula/src/services/function-list/univer/function-names.ts b/packages/engine-formula/src/functions/univer/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/univer/function-names.ts
rename to packages/engine-formula/src/functions/univer/function-names.ts
diff --git a/packages/formula/src/services/function-list/web/function-names.ts b/packages/engine-formula/src/functions/web/function-names.ts
similarity index 100%
rename from packages/formula/src/services/function-list/web/function-names.ts
rename to packages/engine-formula/src/functions/web/function-names.ts
diff --git a/packages/engine-formula/src/index.ts b/packages/engine-formula/src/index.ts
index fdaa897a56..febd8e6241 100644
--- a/packages/engine-formula/src/index.ts
+++ b/packages/engine-formula/src/index.ts
@@ -17,6 +17,24 @@ export { FUNCTION_NAMES, FunctionType, type IFunctionInfo, type IFunctionParam }
export { includeFormulaLexerToken, isFormulaLexerToken, normalizeSheetName } from './basics/match-token';
export { matchToken } from './basics/token';
export { compareToken } from './basics/token';
+export {
+ type ISetArrayFormulaDataMutationParams,
+ SetArrayFormulaDataMutation,
+ SetArrayFormulaDataUndoMutationFactory,
+} from './commands/mutations/set-array-formula-data.mutation';
+export {
+ type ISetFormulaCalculationNotificationMutation,
+ type ISetFormulaCalculationResultMutation,
+ type ISetFormulaCalculationStartMutation,
+ SetFormulaCalculationNotificationMutation,
+ SetFormulaCalculationResultMutation,
+ SetFormulaCalculationStartMutation,
+ SetFormulaCalculationStopMutation,
+} from './commands/mutations/set-formula-calculation.mutation';
+export {
+ type ISetFormulaDataMutationParams,
+ SetFormulaDataMutation,
+} from './commands/mutations/set-formula-data.mutation';
export { LexerNode } from './engine/analysis/lexer-node';
export { ErrorValueObject } from './engine/other-object/error-value-object';
export { BaseReferenceObject, type FunctionVariantType } from './engine/reference-object/base-reference-object';
@@ -28,6 +46,8 @@ export { NumberValueObject } from './engine/value-object/primitive-object';
export { BooleanValueObject } from './engine/value-object/primitive-object';
export { StringValueObject } from './engine/value-object/primitive-object';
export { BaseFunction } from './functions/base-function';
+export { FUNCTION_NAMES_MATH } from './functions/math/function-names';
+export { FormulaDataModel } from './models/formula-data.model';
export { BaseFormulaEnginePlugin } from './plugin';
export { IActiveDirtyManagerService } from './services/active-dirty-manager.service';
export { FormulaEngineService } from './services/formula-engine.service';
diff --git a/packages/formula/src/models/formula-data.model.ts b/packages/engine-formula/src/models/formula-data.model.ts
similarity index 99%
rename from packages/formula/src/models/formula-data.model.ts
rename to packages/engine-formula/src/models/formula-data.model.ts
index 9a2a7991e9..40a5911235 100644
--- a/packages/formula/src/models/formula-data.model.ts
+++ b/packages/engine-formula/src/models/formula-data.model.ts
@@ -7,6 +7,7 @@ import {
IUniverInstanceService,
ObjectMatrix,
} from '@univerjs/core';
+
import type {
IArrayFormulaRangeType,
IArrayFormulaUnitCellType,
@@ -16,7 +17,7 @@ import type {
ISheetData,
IUnitData,
IUnitSheetNameMap,
-} from '@univerjs/engine-formula';
+} from '../basics/common';
export interface IFormulaConfig {
notExecuteFormula?: boolean;
diff --git a/packages/engine-formula/src/plugin.ts b/packages/engine-formula/src/plugin.ts
index 4e9ac30cf4..f59d8b4ed0 100644
--- a/packages/engine-formula/src/plugin.ts
+++ b/packages/engine-formula/src/plugin.ts
@@ -1,21 +1,66 @@
import { Plugin } from '@univerjs/core';
+import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
+import { CalculateController } from './controller/calculate.controller';
+import { FormulaController } from './controller/formula.controller';
+import { FormulaDataModel } from './models/formula-data.model';
import { ActiveDirtyManagerService, IActiveDirtyManagerService } from './services/active-dirty-manager.service';
+import { FormulaService, IFormulaService } from './services/formula.service';
import { FormulaEngineService } from './services/formula-engine.service';
+import { IPassiveDirtyManagerService, PassiveDirtyManagerService } from './services/passive-dirty-manager.service';
const PLUGIN_NAME = 'base-formula-engine';
+interface IBaseFormulaEnginePlugin {
+ notExecuteFormula?: boolean;
+}
+
export class BaseFormulaEnginePlugin extends Plugin {
+ private _formulaDataModel: FormulaDataModel | null = null;
+
constructor(
- _config: undefined,
+ private _config: IBaseFormulaEnginePlugin,
@Inject(Injector) protected override _injector: Injector
) {
super(PLUGIN_NAME);
}
- override onStarting(injector: Injector): void {
- injector.add([FormulaEngineService]);
- injector.add([IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }]);
+ override onStarting(): void {
+ this._initialize();
+ }
+
+ private _initialize() {
+ this._formulaDataModel = this._injector.createInstance(FormulaDataModel);
+
+ const dependencies: Dependency[] = [
+ // Services
+ [FormulaEngineService],
+ [IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }],
+ [IPassiveDirtyManagerService, { useClass: PassiveDirtyManagerService }],
+ // [IFormulaService, { useClass: FormulaService }],
+
+ // Models
+ [FormulaDataModel, { useValue: this._formulaDataModel }],
+
+ //Controllers
+ [FormulaController],
+ ];
+
+ if (!this._config?.notExecuteFormula) {
+ // only worker
+ dependencies.push([IFormulaService, { useClass: FormulaService }]);
+ dependencies.push([CalculateController]);
+ }
+
+ dependencies.forEach((dependency) => this._injector.add(dependency));
+ }
+
+ override onReady(): void {
+ this._formulaDataModel?.initFormulaData();
+
+ if (!this._config?.notExecuteFormula) {
+ this._injector.get(IFormulaService).registerFunctions();
+ }
}
}
diff --git a/packages/engine-formula/src/services/formula-engine.service.ts b/packages/engine-formula/src/services/formula-engine.service.ts
index 2549a7f323..86e031b96c 100644
--- a/packages/engine-formula/src/services/formula-engine.service.ts
+++ b/packages/engine-formula/src/services/formula-engine.service.ts
@@ -59,7 +59,6 @@ import type { BaseFunction } from '../functions/base-function';
import { FormulaCurrentConfigService, IFormulaCurrentConfigService } from './current-data.service';
import { DefinedNamesService, IDefinedNamesService } from './defined-names.service';
import { FunctionService, IFunctionService } from './function.service';
-import { IPassiveDirtyManagerService, PassiveDirtyManagerService } from './passive-dirty-manager.service';
import type { IAllRuntimeData, IExecutionInProgressParams } from './runtime.service';
import { FormulaExecuteStageType, FormulaRuntimeService, IFormulaRuntimeService } from './runtime.service';
import { ISuperTableService, SuperTableService } from './super-table.service';
@@ -131,10 +130,6 @@ export class FormulaEngineService extends Disposable {
return this._injector.get(LexerTreeBuilder);
}
- get PassiveDirtyManagerService() {
- return this._injector.get(IPassiveDirtyManagerService);
- }
-
/**
* Use register to register a function, new CustomFunction(inject, name)
*/
@@ -481,7 +476,6 @@ export class FormulaEngineService extends Disposable {
[ISuperTableService, { useClass: SuperTableService }],
[IDefinedNamesService, { useClass: DefinedNamesService }],
[IFunctionService, { useClass: FunctionService }],
- [IPassiveDirtyManagerService, { useClass: PassiveDirtyManagerService }],
// [IPassiveDirtyManagerService, { useClass: PassiveDirtyManagerService }],
diff --git a/packages/formula/src/services/formula.service.ts b/packages/engine-formula/src/services/formula.service.ts
similarity index 50%
rename from packages/formula/src/services/formula.service.ts
rename to packages/engine-formula/src/services/formula.service.ts
index 6844fa2ddc..3b589965ac 100644
--- a/packages/formula/src/services/formula.service.ts
+++ b/packages/engine-formula/src/services/formula.service.ts
@@ -1,28 +1,28 @@
import { LifecycleStages, OnLifecycle } from '@univerjs/core';
-import type { BaseFunction } from '@univerjs/engine-formula';
-import { FormulaEngineService } from '@univerjs/engine-formula';
import type { Ctor, IDisposable } from '@wendellhu/redi';
import { createIdentifier, Inject, Injector } from '@wendellhu/redi';
-import { functionArray } from './function-list/array/function-names';
-import { functionCompatibility } from './function-list/compatibility/function-names';
-import { functionCube } from './function-list/cube/function-names';
-import { functionDatabase } from './function-list/database/function-names';
-import { functionDate } from './function-list/date/function-names';
-import { functionEngineering } from './function-list/engineering/function-names';
-import { functionFinancial } from './function-list/financial/function-names';
-import { functionInformation } from './function-list/information/function-names';
-import { functionLogical } from './function-list/logical/function-names';
-import { functionLookup } from './function-list/lookup/function-names';
-import { functionMath } from './function-list/math/function-names';
-import { functionStatistical } from './function-list/statistical/function-names';
-import { functionText } from './function-list/text/function-names';
-import { functionUniver } from './function-list/univer/function-names';
-import { functionWeb } from './function-list/web/function-names';
-
-export interface IFormulaService {}
-
-export const IFormulaService = createIdentifier<IFormulaService>('formula-calculate.formula-service');
+import { functionArray } from '../functions/array/function-names';
+import type { BaseFunction } from '../functions/base-function';
+import { functionCompatibility } from '../functions/compatibility/function-names';
+import { functionCube } from '../functions/cube/function-names';
+import { functionDatabase } from '../functions/database/function-names';
+import { functionDate } from '../functions/date/function-names';
+import { functionEngineering } from '../functions/engineering/function-names';
+import { functionFinancial } from '../functions/financial/function-names';
+import { functionInformation } from '../functions/information/function-names';
+import { functionLogical } from '../functions/logical/function-names';
+import { functionLookup } from '../functions/lookup/function-names';
+import { functionMath } from '../functions/math/function-names';
+import { functionStatistical } from '../functions/statistical/function-names';
+import { functionText } from '../functions/text/function-names';
+import { functionUniver } from '../functions/univer/function-names';
+import { functionWeb } from '../functions/web/function-names';
+import { FormulaEngineService } from './formula-engine.service';
+
+export interface IFormulaService {
+ registerFunctions(): void;
+}
@OnLifecycle(LifecycleStages.Starting, FormulaService)
export class FormulaService implements IFormulaService, IDisposable {
@@ -60,3 +60,5 @@ export class FormulaService implements IFormulaService, IDisposable {
this._formulaEngineService.registerFunction(...functions);
}
}
+
+export const IFormulaService = createIdentifier<FormulaService>('formula-calculate.formula-service');
diff --git a/packages/formula/README.md b/packages/formula/README.md
deleted file mode 100644
index 4ddc4e1a88..0000000000
--- a/packages/formula/README.md
+++ /dev/null
@@ -1,16 +0,0 @@
-# @univerjs/formula
-
-[![npm version](https://img.shields.io/npm/v/@univerjs/formula)](https://npmjs.org/packages/@univerjs/formula)
-[![license](https://img.shields.io/npm/l/@univerjs/formula)](https://img.shields.io/npm/l/@univerjs/formula)
-
-## Introduction
-
-> Formula plugin for Univer.
-
-## Usage
-
-### Installation
-
-```shell
-npm i @univerjs/formula
-```
diff --git a/packages/formula/docs/zh/model.md b/packages/formula/docs/zh/model.md
deleted file mode 100644
index 67ec47ff0c..0000000000
--- a/packages/formula/docs/zh/model.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# 公式的模型层设计
-
-公式字符串并不像其他的功能一样作为插件 model 单独存储,而是直接存储在 `ICellData` 的 `f` 字段中,并且在 `setRangeValues` mutation 中对公式内容进行处理。
-
-把公式完全从内核中抽离出来可能是不适当的,例如不好处理并发编辑时,写入公式和写入普通 value 冲突的问题。
diff --git a/packages/formula/esbuild.config.mjs b/packages/formula/esbuild.config.mjs
deleted file mode 100644
index f6cadb4c7c..0000000000
--- a/packages/formula/esbuild.config.mjs
+++ /dev/null
@@ -1,18 +0,0 @@
-import esbuild from 'esbuild';
-
-// eslint-disable-next-line import/no-relative-packages
-import baseConfig, { postBuild } from '../../esbuild.config.mjs';
-
-for (const format of ['cjs', 'esm']) {
- await esbuild.build({
- ...baseConfig,
- globalName: 'UniverFormula',
- entryPoints: {
- index: './src/index.ts',
- },
- outdir: `./lib/${format}`,
- format,
- });
-
- await postBuild(format);
-}
diff --git a/packages/formula/package.json b/packages/formula/package.json
deleted file mode 100644
index b20d26e127..0000000000
--- a/packages/formula/package.json
+++ /dev/null
@@ -1,59 +0,0 @@
-{
- "name": "@univerjs/formula",
- "version": "0.1.0-alpha.1",
- "author": "DreamNum <[email protected]>",
- "license": "MIT",
- "main": "./lib/cjs/index.js",
- "module": "./lib/esm/index.js",
- "types": "./lib/types/index.d.ts",
- "publishConfig": {
- "access": "public",
- "main": "./lib/cjs/index.js",
- "module": "./lib/esm/index.js",
- "exports": {
- ".": {
- "import": "./lib/esm/index.js",
- "require": "./lib/cjs/index.js",
- "types": "./lib/types/index.d.ts"
- },
- "./*": {
- "import": "./lib/esm/*",
- "require": "./lib/cjs/*",
- "types": "./lib/types/index.d.ts"
- }
- }
- },
- "exports": {
- ".": "./src/index.ts",
- "./*": "./src/*"
- },
- "directories": {
- "lib": "lib"
- },
- "files": [
- "lib"
- ],
- "private": false,
- "scripts": {
- "esbuild": "node ./esbuild.config.mjs && tsc -p tsconfig.esbuild.json",
- "test": "vitest run",
- "test:watch": "vitest",
- "coverage": "vitest run --coverage"
- },
- "dependencies": {
- "@univerjs/engine-formula": "workspace:*",
- "@univerjs/sheets": "workspace:*",
- "@univerjs/core": "workspace:*",
- "@wendellhu/redi": "^0.12.11",
- "rxjs": "^7.8.1"
- },
- "devDependencies": {
- "@vitest/coverage-istanbul": "^0.34.6",
- "esbuild": "^0.19.8",
- "happy-dom": "^12.10.3",
- "less": "^4.2.0",
- "ts-node": "^10.9.1",
- "vitest": "^0.34.6",
- "typescript": "^5.3.2"
- }
-}
diff --git a/packages/formula/src/common/plugin-name.ts b/packages/formula/src/common/plugin-name.ts
deleted file mode 100644
index 272dbd75b8..0000000000
--- a/packages/formula/src/common/plugin-name.ts
+++ /dev/null
@@ -1 +0,0 @@
-export const FORMULA_PLUGIN_NAME = 'formula';
diff --git a/packages/formula/src/controllers/__tests__/create-command-test-bed.ts b/packages/formula/src/controllers/__tests__/create-command-test-bed.ts
deleted file mode 100644
index 1bf5d8c94b..0000000000
--- a/packages/formula/src/controllers/__tests__/create-command-test-bed.ts
+++ /dev/null
@@ -1,80 +0,0 @@
-import type { IWorkbookData } from '@univerjs/core';
-import { ILogService, IUniverInstanceService, LocaleType, Plugin, PluginType, Univer } from '@univerjs/core';
-import { FormulaEngineService } from '@univerjs/engine-formula';
-import { SelectionManagerService } from '@univerjs/sheets';
-import type { Dependency } from '@wendellhu/redi';
-import { Inject, Injector } from '@wendellhu/redi';
-
-const TEST_WORKBOOK_DATA_DEMO: IWorkbookData = {
- id: 'test',
- appVersion: '3.0.0-alpha',
- sheets: {
- sheet1: {
- id: 'sheet1',
- cellData: {
- '1': {
- '1': {
- v: 1,
- },
- },
- },
- },
- },
- locale: LocaleType.EN_US,
- name: '',
- sheetOrder: [],
- styles: {},
-};
-
-export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencies?: Dependency[]) {
- const univer = new Univer();
-
- let get: Injector['get'] | undefined;
-
- /**
- * This plugin hooks into Sheet's DI system to expose API to test scripts
- */
- class TestSpyPlugin extends Plugin {
- static override type = PluginType.Sheet;
-
- constructor(
- _config: undefined,
- @Inject(Injector) override readonly _injector: Injector
- ) {
- super('test-plugin');
-
- this._injector = _injector;
- get = this._injector.get.bind(this._injector);
- }
-
- override onStarting(injector: Injector): void {
- injector.add([SelectionManagerService]);
- injector.add([FormulaEngineService]);
-
- dependencies?.forEach((d) => injector.add(d));
- }
-
- override onDestroy(): void {
- get = undefined;
- }
- }
-
- univer.registerPlugin(TestSpyPlugin);
- const sheet = univer.createUniverSheet(workbookConfig || TEST_WORKBOOK_DATA_DEMO);
-
- if (get === undefined) {
- throw new Error('[TestPlugin]: not hooked on!');
- }
-
- const univerInstanceService = get(IUniverInstanceService);
- univerInstanceService.focusUniverInstance('test');
-
- const logService = get(ILogService);
- logService.toggleLogEnabled(false); // change this to `true` to debug tests via logs
-
- return {
- univer,
- get,
- sheet,
- };
-}
diff --git a/packages/formula/src/formula-plugin.ts b/packages/formula/src/formula-plugin.ts
deleted file mode 100644
index 1ab593c7df..0000000000
--- a/packages/formula/src/formula-plugin.ts
+++ /dev/null
@@ -1,64 +0,0 @@
-import { Plugin, PluginType } from '@univerjs/core';
-import type { Dependency } from '@wendellhu/redi';
-import { Inject, Injector } from '@wendellhu/redi';
-
-import { FORMULA_PLUGIN_NAME } from './common/plugin-name';
-import { ArrayFormulaDisplayController } from './controllers/array-formula-display.controller';
-import { CalculateController } from './controllers/calculate.controller';
-import { DirtyConversionController } from './controllers/dirty-conversion.controller';
-import { FormulaController } from './controllers/formula.controller';
-import { ReferenceExecutorRegisterController } from './controllers/reference-executor-register.controller';
-import { TriggerCalculationController } from './controllers/trigger-calculation.controller';
-import { UpdateFormulaController } from './controllers/update-formula.controller';
-import type { IFormulaConfig } from './models/formula-data.model';
-import { FormulaDataModel } from './models/formula-data.model';
-import { FormulaService, IFormulaService } from './services/formula.service';
-
-export class FormulaPlugin extends Plugin {
- static override type = PluginType.Sheet;
-
- private _formulaDataModel: FormulaDataModel | null = null;
-
- constructor(
- private _config: IFormulaConfig | undefined,
- @Inject(Injector) override readonly _injector: Injector
- ) {
- super(FORMULA_PLUGIN_NAME);
- }
-
- initialize(): void {
- this._formulaDataModel = this._injector.createInstance(FormulaDataModel);
-
- // main thread and worker
- const dependencies: Dependency[] = [
- // [IFormulaService, { useFactory: () => this._injector.createInstance(FormulaService) }],
- // models
- [FormulaDataModel, { useValue: this._formulaDataModel }],
- // controllers
- [FormulaController],
- [DirtyConversionController],
- ];
-
- if (!this._config?.notExecuteFormula) {
- // only worker
- dependencies.push([IFormulaService, { useClass: FormulaService }]);
- dependencies.push([CalculateController]);
- dependencies.push([ReferenceExecutorRegisterController]);
- } else {
- // only main thread
- dependencies.push([UpdateFormulaController]);
- dependencies.push([ArrayFormulaDisplayController]);
- dependencies.push([TriggerCalculationController]);
- }
-
- dependencies.forEach((dependency) => this._injector.add(dependency));
- }
-
- override onStarting(): void {
- this.initialize();
- }
-
- override onReady(): void {
- this._formulaDataModel?.initFormulaData();
- }
-}
diff --git a/packages/formula/src/index.ts b/packages/formula/src/index.ts
deleted file mode 100644
index ae61b70012..0000000000
--- a/packages/formula/src/index.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-export { FormulaPlugin } from './formula-plugin';
-export { FUNCTION_NAMES_ARRAY } from './services/function-list/array/function-names';
-export { FUNCTION_NAMES_COMPATIBILITY } from './services/function-list/compatibility/function-names';
-export { FUNCTION_NAMES_CUBE } from './services/function-list/cube/function-names';
-export { FUNCTION_NAMES_DATABASE } from './services/function-list/database/function-names';
-export { FUNCTION_NAMES_ENGINEERING } from './services/function-list/engineering/function-names';
-export { FUNCTION_NAMES_FINANCIAL } from './services/function-list/financial/function-names';
-export { FUNCTION_NAMES_INFORMATION } from './services/function-list/information/function-names';
-export { FUNCTION_NAMES_LOOKUP } from './services/function-list/lookup/function-names';
-export { FUNCTION_NAMES_MATH } from './services/function-list/math/function-names';
-export { FUNCTION_NAMES_STATISTICAL } from './services/function-list/statistical/function-names';
-export { FUNCTION_NAMES_TEXT } from './services/function-list/text/function-names';
-export { FUNCTION_NAMES_UNIVER } from './services/function-list/univer/function-names';
-export { FUNCTION_NAMES_WEB } from './services/function-list/web/function-names';
diff --git a/packages/formula/src/services/function-list/math/sumifs/sumifs.ts b/packages/formula/src/services/function-list/math/sumifs/sumifs.ts
deleted file mode 100644
index 31395ac7ed..0000000000
--- a/packages/formula/src/services/function-list/math/sumifs/sumifs.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-import type { FunctionVariantType } from '@univerjs/engine-formula';
-import { BaseFunction, ErrorType, ErrorValueObject } from '@univerjs/engine-formula';
-
-export class Sumifs extends BaseFunction {
- override calculate(...variants: FunctionVariantType[]) {
- return ErrorValueObject.create(ErrorType.VALUE);
- }
-}
diff --git a/packages/formula/tsconfig.esbuild.json b/packages/formula/tsconfig.esbuild.json
deleted file mode 100644
index fc1f1714b9..0000000000
--- a/packages/formula/tsconfig.esbuild.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "extends": "./tsconfig.json",
- "compilerOptions": {
- "rootDir": "./src",
- "outDir": "./lib/types",
- "declaration": true,
- "declarationDir": "./lib/types",
- "declarationMap": true,
- "emitDeclarationOnly": true,
- "isolatedModules": false
- },
- "exclude": ["**/*.test.ts", "**/*.test.tsx", "**/*.stories.tsx"]
-}
diff --git a/packages/formula/tsconfig.json b/packages/formula/tsconfig.json
deleted file mode 100644
index 32d857ca72..0000000000
--- a/packages/formula/tsconfig.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "extends": "../../tsconfig.json",
- "compilerOptions": {
- "rootDir": "./src",
- "outDir": "lib",
- "esModuleInterop": true,
- "strictPropertyInitialization": false
- },
- "include": ["src/**/*"]
-}
diff --git a/packages/formula/vitest.config.ts b/packages/formula/vitest.config.ts
deleted file mode 100644
index 3c74cf802f..0000000000
--- a/packages/formula/vitest.config.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { defineConfig } from 'vitest/config';
-
-export default defineConfig({
- test: {
- coverage: {
- provider: 'istanbul',
- },
- },
-});
diff --git a/packages/sheets-formula/package.json b/packages/sheets-formula/package.json
index af9f866709..d6c83ce9cf 100644
--- a/packages/sheets-formula/package.json
+++ b/packages/sheets-formula/package.json
@@ -47,7 +47,6 @@
"@ctrl/tinycolor": "^4.0.2",
"@univerjs/docs": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
- "@univerjs/formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/ui": "workspace:*",
diff --git a/packages/sheets-formula/src/controllers/__tests__/create-command-test-bed.ts b/packages/sheets-formula/src/controllers/__tests__/create-command-test-bed.ts
index 5f6d7cfeb3..9b87f7edce 100644
--- a/packages/sheets-formula/src/controllers/__tests__/create-command-test-bed.ts
+++ b/packages/sheets-formula/src/controllers/__tests__/create-command-test-bed.ts
@@ -1,5 +1,6 @@
import type { IWorkbookData, Workbook } from '@univerjs/core';
import { ILogService, IUniverInstanceService, LocaleType, Plugin, PluginType, Univer } from '@univerjs/core';
+import { FormulaEngineService } from '@univerjs/engine-formula';
import { SelectionManagerService } from '@univerjs/sheets';
import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
@@ -19,6 +20,11 @@ const TEST_WORKBOOK_DATA_DEMO: IWorkbookData = {
f: '=SUM(A1)',
},
},
+ '1': {
+ '1': {
+ v: 1,
+ },
+ },
},
},
},
@@ -38,6 +44,8 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
const univer = new Univer();
const injector = univer.__getInjector();
+ let get: Injector['get'] | undefined;
+
class TestSpyPlugin extends Plugin {
static override type = PluginType.Sheet;
@@ -48,27 +56,118 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
super('test-plugin');
this._injector = _injector;
+ get = this._injector.get.bind(this._injector);
}
override onStarting(injector: Injector): void {
injector.add([SelectionManagerService]);
+ injector.add([FormulaEngineService]);
dependencies?.forEach((d) => injector.add(d));
}
+
+ override onDestroy(): void {
+ get = undefined;
+ }
}
univer.registerPlugin(TestSpyPlugin);
const sheet = univer.createUniverSheet(workbookConfig || TEST_WORKBOOK_DATA_DEMO);
+ if (get === undefined) {
+ throw new Error('[TestPlugin]: not hooked on!');
+ }
+
const univerInstanceService = injector.get(IUniverInstanceService);
univerInstanceService.focusUniverInstance('test');
- const logService = injector.get(ILogService);
+ const logService = injector.get(ILogService);
logService.toggleLogEnabled(false); // change this to `true` to debug tests via logs
return {
univer,
- get: injector.get.bind(injector),
+ get,
sheet,
};
}
+
+// import type { IWorkbookData } from '@univerjs/core';
+// import { ILogService, IUniverInstanceService, LocaleType, Plugin, PluginType, Univer } from '@univerjs/core';
+// import { FormulaEngineService } from '@univerjs/engine-formula';
+// import { SelectionManagerService } from '@univerjs/sheets';
+// import type { Dependency } from '@wendellhu/redi';
+// import { Inject, Injector } from '@wendellhu/redi';
+
+// const TEST_WORKBOOK_DATA_DEMO: IWorkbookData = {
+// id: 'test',
+// appVersion: '3.0.0-alpha',
+// sheets: {
+// sheet1: {
+// id: 'sheet1',
+// cellData: {
+// '1': {
+// '1': {
+// v: 1,
+// },
+// },
+// },
+// },
+// },
+// locale: LocaleType.EN_US,
+// name: '',
+// sheetOrder: [],
+// styles: {},
+// };
+
+// export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencies?: Dependency[]) {
+// const univer = new Univer();
+
+// let get: Injector['get'] | undefined;
+
+// /**
+// * This plugin hooks into Sheet's DI system to expose API to test scripts
+// */
+// class TestSpyPlugin extends Plugin {
+// static override type = PluginType.Sheet;
+
+// constructor(
+// _config: undefined,
+// @Inject(Injector) override readonly _injector: Injector
+// ) {
+// super('test-plugin');
+
+// this._injector = _injector;
+// get = this._injector.get.bind(this._injector);
+// }
+
+// override onStarting(injector: Injector): void {
+// injector.add([SelectionManagerService]);
+// injector.add([FormulaEngineService]);
+
+// dependencies?.forEach((d) => injector.add(d));
+// }
+
+// override onDestroy(): void {
+// get = undefined;
+// }
+// }
+
+// univer.registerPlugin(TestSpyPlugin);
+// const sheet = univer.createUniverSheet(workbookConfig || TEST_WORKBOOK_DATA_DEMO);
+
+// if (get === undefined) {
+// throw new Error('[TestPlugin]: not hooked on!');
+// }
+
+// const univerInstanceService = get(IUniverInstanceService);
+// univerInstanceService.focusUniverInstance('test');
+
+// const logService = get(ILogService);
+// logService.toggleLogEnabled(false); // change this to `true` to debug tests via logs
+
+// return {
+// univer,
+// get,
+// sheet,
+// };
+// }
diff --git a/packages/formula/src/controllers/__tests__/update-formula.controller.spec.ts b/packages/sheets-formula/src/controllers/__tests__/update-formula.controller.spec.ts
similarity index 100%
rename from packages/formula/src/controllers/__tests__/update-formula.controller.spec.ts
rename to packages/sheets-formula/src/controllers/__tests__/update-formula.controller.spec.ts
diff --git a/packages/formula/src/controllers/__tests__/utils.spec.ts b/packages/sheets-formula/src/controllers/__tests__/utils.spec.ts
similarity index 100%
rename from packages/formula/src/controllers/__tests__/utils.spec.ts
rename to packages/sheets-formula/src/controllers/__tests__/utils.spec.ts
diff --git a/packages/formula/src/controllers/array-formula-display.controller.ts b/packages/sheets-formula/src/controllers/array-formula-display.controller.ts
similarity index 90%
rename from packages/formula/src/controllers/array-formula-display.controller.ts
rename to packages/sheets-formula/src/controllers/array-formula-display.controller.ts
index 7e28d3aed3..4a7814147e 100644
--- a/packages/formula/src/controllers/array-formula-display.controller.ts
+++ b/packages/sheets-formula/src/controllers/array-formula-display.controller.ts
@@ -1,12 +1,10 @@
import type { ICommandInfo } from '@univerjs/core';
import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
+import type { ISetArrayFormulaDataMutationParams } from '@univerjs/engine-formula';
+import { FormulaDataModel, SetArrayFormulaDataMutation } from '@univerjs/engine-formula';
import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';
import { Inject } from '@wendellhu/redi';
-import type { ISetArrayFormulaDataMutationParams } from '../commands/mutations/set-array-formula-data.mutation';
-import { SetArrayFormulaDataMutation } from '../commands/mutations/set-array-formula-data.mutation';
-import { FormulaDataModel } from '../models/formula-data.model';
-
@OnLifecycle(LifecycleStages.Ready, ArrayFormulaDisplayController)
export class ArrayFormulaDisplayController extends Disposable {
constructor(
diff --git a/packages/sheets-formula/src/controllers/prompt.controller.ts b/packages/sheets-formula/src/controllers/prompt.controller.ts
index d3fbd4eba9..0fca83f649 100644
--- a/packages/sheets-formula/src/controllers/prompt.controller.ts
+++ b/packages/sheets-formula/src/controllers/prompt.controller.ts
@@ -876,7 +876,7 @@ export class PromptController extends Disposable {
const refSheetId = this._getSheetIdByName(unitId, sheetName.trim());
- if (refSheetId !== sheetId) {
+ if (sheetName.length !== 0 && refSheetId !== sheetId) {
continue;
}
diff --git a/packages/formula/src/controllers/trigger-calculation.controller.ts b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
similarity index 85%
rename from packages/formula/src/controllers/trigger-calculation.controller.ts
rename to packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
index 6e0cca16b3..7d639ff1f1 100644
--- a/packages/formula/src/controllers/trigger-calculation.controller.ts
+++ b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
@@ -1,14 +1,14 @@
import type { ICommandInfo } from '@univerjs/core';
import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
-import { FormulaExecutedStateType, IActiveDirtyManagerService } from '@univerjs/engine-formula';
-import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
-import { SetRangeValuesMutation, SetStyleCommand } from '@univerjs/sheets';
-
-import type { ISetFormulaCalculationNotificationMutation } from '../commands/mutations/set-formula-calculation.mutation';
+import type { ISetFormulaCalculationNotificationMutation } from '@univerjs/engine-formula';
import {
+ FormulaExecutedStateType,
+ IActiveDirtyManagerService,
SetFormulaCalculationNotificationMutation,
SetFormulaCalculationStartMutation,
-} from '../commands/mutations/set-formula-calculation.mutation';
+} from '@univerjs/engine-formula';
+import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
+import { SetRangeValuesMutation, SetStyleCommand } from '@univerjs/sheets';
const globalObject = typeof self !== 'undefined' ? self : window;
@@ -53,7 +53,7 @@ export class TriggerCalculationController extends Disposable {
// ];
this.disposeWithMe(
- this._commandService.onCommandExecuted((command: ICommandInfo) => {
+ this._commandService.onCommandExecuted((command: ICommandInfo, options) => {
if (!this._activeDirtyManagerService.get(command.id)) {
return;
}
@@ -61,7 +61,7 @@ export class TriggerCalculationController extends Disposable {
if (command.id === SetRangeValuesMutation.id) {
const params = command.params as ISetRangeValuesMutationParams;
- if (params.isFormulaUpdate === true || params.trigger === SetStyleCommand.id) {
+ if ((options && options.local === true) || params.trigger === SetStyleCommand.id) {
return;
}
}
@@ -71,9 +71,15 @@ export class TriggerCalculationController extends Disposable {
globalObject.clearTimeout(this._setTimeoutKey);
this._setTimeoutKey = globalObject.setTimeout(() => {
- this._commandService.executeCommand(SetFormulaCalculationStartMutation.id, {
- commands: this._waitingCommandQueue,
- });
+ this._commandService.executeCommand(
+ SetFormulaCalculationStartMutation.id,
+ {
+ commands: this._waitingCommandQueue,
+ },
+ {
+ local: true,
+ }
+ );
this._startExecutionTime = performance.now();
}, 100);
@@ -137,9 +143,15 @@ export class TriggerCalculationController extends Disposable {
}
private _initialExecuteFormula() {
- this._commandService.executeCommand(SetFormulaCalculationStartMutation.id, {
- commands: [],
- forceCalculation: true,
- });
+ this._commandService.executeCommand(
+ SetFormulaCalculationStartMutation.id,
+ {
+ commands: [],
+ forceCalculation: true,
+ },
+ {
+ local: true,
+ }
+ );
}
}
diff --git a/packages/formula/src/controllers/update-formula.controller.ts b/packages/sheets-formula/src/controllers/update-formula.controller.ts
similarity index 97%
rename from packages/formula/src/controllers/update-formula.controller.ts
rename to packages/sheets-formula/src/controllers/update-formula.controller.ts
index 7430a2e83f..be8f94fd3a 100644
--- a/packages/formula/src/controllers/update-formula.controller.ts
+++ b/packages/sheets-formula/src/controllers/update-formula.controller.ts
@@ -15,7 +15,14 @@ import {
Tools,
} from '@univerjs/core';
import type { IFormulaData, IFormulaDataItem, ISequenceNode, IUnitSheetNameMap } from '@univerjs/engine-formula';
-import { FormulaEngineService, generateStringWithSequence, sequenceNodeType } from '@univerjs/engine-formula';
+import {
+ FormulaDataModel,
+ FormulaEngineService,
+ generateStringWithSequence,
+ sequenceNodeType,
+ SetArrayFormulaDataMutation,
+ SetFormulaDataMutation,
+} from '@univerjs/engine-formula';
import type {
IDeleteRangeMoveLeftCommandParams,
IDeleteRangeMoveUpCommandParams,
@@ -61,9 +68,6 @@ import {
} from '@univerjs/sheets';
import { Inject, Injector } from '@wendellhu/redi';
-import { SetArrayFormulaDataMutation } from '../commands/mutations/set-array-formula-data.mutation';
-import { SetFormulaDataMutation } from '../commands/mutations/set-formula-data.mutation';
-import { FormulaDataModel } from '../models/formula-data.model';
import { offsetArrayFormula, offsetFormula } from './utils';
interface IUnitRangeWithOffset extends IUnitRange {
@@ -131,22 +135,28 @@ export class UpdateFormulaController extends Disposable {
);
this.disposeWithMe(
- this._commandService.onCommandExecuted((command: ICommandInfo) => {
+ this._commandService.onCommandExecuted((command: ICommandInfo, options) => {
// Synchronous data from worker
if (command.id === SetRangeValuesMutation.id) {
const params = command.params as ISetRangeValuesMutationParams;
- const { worksheetId: sheetId, workbookId: unitId, cellValue, isFormulaUpdate } = params;
+ const { worksheetId: sheetId, workbookId: unitId, cellValue } = params;
- if (isFormulaUpdate === true || cellValue == null) {
+ if ((options && options.local === true) || cellValue == null) {
return;
}
this._formulaDataModel.updateFormulaData(unitId, sheetId, cellValue);
- this._commandService.executeCommand(SetFormulaDataMutation.id, {
- formulaData: this._formulaDataModel.getFormulaData(),
- });
+ this._commandService.executeCommand(
+ SetFormulaDataMutation.id,
+ {
+ formulaData: this._formulaDataModel.getFormulaData(),
+ },
+ {
+ local: true,
+ }
+ );
}
})
);
@@ -222,10 +232,16 @@ export class UpdateFormulaController extends Disposable {
);
// Synchronous to the worker thread
- this._commandService.executeCommand(SetArrayFormulaDataMutation.id, {
- arrayFormulaRange: offsetArrayFormulaRange,
- arrayFormulaCellData: offsetArrayFormulaCellData,
- });
+ this._commandService.executeCommand(
+ SetArrayFormulaDataMutation.id,
+ {
+ arrayFormulaRange: offsetArrayFormulaRange,
+ arrayFormulaCellData: offsetArrayFormulaCellData,
+ },
+ {
+ local: true,
+ }
+ );
// offset formulaData
oldFormulaData = offsetFormula(oldFormulaData, command, unitId, sheetId, selections);
diff --git a/packages/formula/src/controllers/utils.ts b/packages/sheets-formula/src/controllers/utils.ts
similarity index 100%
rename from packages/formula/src/controllers/utils.ts
rename to packages/sheets-formula/src/controllers/utils.ts
diff --git a/packages/sheets-formula/src/formula-ui-plugin.ts b/packages/sheets-formula/src/formula-ui-plugin.ts
index 2e3bbb6549..eb2afb0a81 100644
--- a/packages/sheets-formula/src/formula-ui-plugin.ts
+++ b/packages/sheets-formula/src/formula-ui-plugin.ts
@@ -4,11 +4,14 @@ import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import { FORMULA_UI_PLUGIN_NAME } from './common/plugin-name';
+import { ArrayFormulaDisplayController } from './controllers/array-formula-display.controller';
import { FormulaAutoFillController } from './controllers/formula-auto-fill.controller';
import { FormulaClipboardController } from './controllers/formula-clipboard.controller';
import { FormulaInputController } from './controllers/formula-input.controller';
import { FormulaUIController } from './controllers/formula-ui.controller';
import { PromptController } from './controllers/prompt.controller';
+import { TriggerCalculationController } from './controllers/trigger-calculation.controller';
+import { UpdateFormulaController } from './controllers/update-formula.controller';
import { enUS } from './locale';
import { DescriptionService, IDescriptionService } from './services/description.service';
import { FormulaInputService, IFormulaInputService } from './services/formula-input.service';
@@ -52,6 +55,9 @@ export class FormulaUIPlugin extends Plugin {
[FormulaInputController],
[FormulaAutoFillController],
[FormulaClipboardController],
+ [ArrayFormulaDisplayController],
+ [TriggerCalculationController],
+ [UpdateFormulaController],
];
dependencies.forEach((dependency) => this._injector.add(dependency));
diff --git a/packages/sheets-formula/src/services/function-list/math.ts b/packages/sheets-formula/src/services/function-list/math.ts
index e191500c6d..c3f03f1453 100644
--- a/packages/sheets-formula/src/services/function-list/math.ts
+++ b/packages/sheets-formula/src/services/function-list/math.ts
@@ -1,6 +1,5 @@
import type { IFunctionInfo } from '@univerjs/engine-formula';
-import { FUNCTION_NAMES, FunctionType } from '@univerjs/engine-formula';
-import { FUNCTION_NAMES_MATH } from '@univerjs/formula';
+import { FUNCTION_NAMES, FUNCTION_NAMES_MATH, FunctionType } from '@univerjs/engine-formula';
export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
{
diff --git a/packages/sheets/package.json b/packages/sheets/package.json
index ad9c694e7a..1d0fee3f33 100644
--- a/packages/sheets/package.json
+++ b/packages/sheets/package.json
@@ -52,6 +52,7 @@
"@ctrl/tinycolor": "^4.0.2",
"@univerjs/engine-render": "workspace:*",
"@univerjs/core": "workspace:*",
+ "@univerjs/engine-formula": "workspace:*",
"@wendellhu/redi": "^0.12.11",
"rxjs": "^7.8.1"
},
diff --git a/packages/sheets/src/commands/mutations/set-range-values.mutation.ts b/packages/sheets/src/commands/mutations/set-range-values.mutation.ts
index 82945a0d4a..52cc23de07 100644
--- a/packages/sheets/src/commands/mutations/set-range-values.mutation.ts
+++ b/packages/sheets/src/commands/mutations/set-range-values.mutation.ts
@@ -31,10 +31,10 @@ export interface ISetRangeValuesMutationParams extends IMutationCommonParams {
*/
options?: ICopyToOptionsData;
- /**
- * for formula calculate
- */
- isFormulaUpdate?: boolean;
+ // /**
+ // * for formula calculate
+ // */
+ // isFormulaUpdate?: boolean;
}
export interface ISetRangeValuesRangeMutationParams extends ISetRangeValuesMutationParams {
diff --git a/packages/formula/src/controllers/dirty-conversion.controller.ts b/packages/sheets/src/controllers/active-dirty.controller.ts
similarity index 91%
rename from packages/formula/src/controllers/dirty-conversion.controller.ts
rename to packages/sheets/src/controllers/active-dirty.controller.ts
index 3c05b4a62a..2fe03c393e 100644
--- a/packages/formula/src/controllers/dirty-conversion.controller.ts
+++ b/packages/sheets/src/controllers/active-dirty.controller.ts
@@ -8,38 +8,35 @@ import {
OnLifecycle,
} from '@univerjs/core';
import type { IDirtyUnitSheetNameMap } from '@univerjs/engine-formula';
-import { IActiveDirtyManagerService } from '@univerjs/engine-formula';
+import { FormulaDataModel, IActiveDirtyManagerService } from '@univerjs/engine-formula';
+import { Inject } from '@wendellhu/redi';
+
import type {
IDeleteRangeMutationParams,
IInsertRangeMutationParams,
IInsertSheetMutationParams,
- IMoveColumnsMutationParams,
- IMoveRangeMutationParams,
- IMoveRowsMutationParams,
IRemoveColMutationParams,
IRemoveRowsMutationParams,
IRemoveSheetMutationParams,
- ISetRangeValuesMutationParams,
-} from '@univerjs/sheets';
-import {
- DeleteRangeMutation,
- InsertRangeMutation,
- InsertSheetMutation,
- MoveColsMutation,
- MoveRangeMutation,
- MoveRowsMutation,
- RemoveColMutation,
- RemoveRowMutation,
- RemoveSheetMutation,
- SetRangeValuesMutation,
- SetStyleCommand,
-} from '@univerjs/sheets';
-import { Inject } from '@wendellhu/redi';
-
-import { FormulaDataModel } from '../models/formula-data.model';
-
-@OnLifecycle(LifecycleStages.Ready, DirtyConversionController)
-export class DirtyConversionController extends Disposable {
+} from '../basics/interfaces/mutation-interface';
+import { SetStyleCommand } from '../commands/commands/set-style.command';
+import { DeleteRangeMutation } from '../commands/mutations/delete-range.mutation';
+import { InsertRangeMutation } from '../commands/mutations/insert-range.mutation';
+import { InsertSheetMutation } from '../commands/mutations/insert-sheet.mutation';
+import type { IMoveRangeMutationParams } from '../commands/mutations/move-range.mutation';
+import { MoveRangeMutation } from '../commands/mutations/move-range.mutation';
+import type {
+ IMoveColumnsMutationParams,
+ IMoveRowsMutationParams,
+} from '../commands/mutations/move-rows-cols.mutation';
+import { MoveColsMutation, MoveRowsMutation } from '../commands/mutations/move-rows-cols.mutation';
+import { RemoveColMutation, RemoveRowMutation } from '../commands/mutations/remove-row-col.mutation';
+import { RemoveSheetMutation } from '../commands/mutations/remove-sheet.mutation';
+import type { ISetRangeValuesMutationParams } from '../commands/mutations/set-range-values.mutation';
+import { SetRangeValuesMutation } from '../commands/mutations/set-range-values.mutation';
+
+@OnLifecycle(LifecycleStages.Ready, ActiveDirtyController)
+export class ActiveDirtyController extends Disposable {
constructor(
@IActiveDirtyManagerService private readonly _activeDirtyManagerService: IActiveDirtyManagerService,
@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,
@@ -77,7 +74,7 @@ export class DirtyConversionController extends Disposable {
* Changes in the cell value caused by the formula or style
* will not trigger the formula to be marked as dirty for calculation.
*/
- if (params.isFormulaUpdate === true || params.trigger === SetStyleCommand.id) {
+ if (params.trigger === SetStyleCommand.id) {
return {};
}
diff --git a/packages/sheets/src/controllers/calculate-result-apply.controller.ts b/packages/sheets/src/controllers/calculate-result-apply.controller.ts
new file mode 100644
index 0000000000..a3fb07162f
--- /dev/null
+++ b/packages/sheets/src/controllers/calculate-result-apply.controller.ts
@@ -0,0 +1,72 @@
+import type { ICommandInfo } from '@univerjs/core';
+import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
+import type { ISetFormulaCalculationResultMutation } from '@univerjs/engine-formula';
+import { SetFormulaCalculationResultMutation } from '@univerjs/engine-formula';
+
+import { SetRangeValuesMutation } from '../commands/mutations/set-range-values.mutation';
+
+@OnLifecycle(LifecycleStages.Ready, CalculateResultApplyController)
+export class CalculateResultApplyController extends Disposable {
+ constructor(@ICommandService private readonly _commandService: ICommandService) {
+ super();
+
+ this._initialize();
+ }
+
+ private _initialize(): void {
+ this._commandExecutedListener();
+ }
+
+ private _commandExecutedListener() {
+ this.disposeWithMe(
+ this._commandService.onCommandExecuted((command: ICommandInfo) => {
+ if (command.id !== SetFormulaCalculationResultMutation.id) {
+ return;
+ }
+
+ const params = command.params as ISetFormulaCalculationResultMutation;
+
+ const { unitData, unitOtherData } = params;
+
+ const unitIds = Object.keys(unitData);
+
+ // Update each calculated value, possibly involving all cells
+ const redoMutationsInfo: ICommandInfo[] = [];
+
+ unitIds.forEach((unitId) => {
+ const sheetData = unitData[unitId];
+
+ const sheetIds = Object.keys(sheetData);
+
+ sheetIds.forEach((sheetId) => {
+ const cellData = sheetData[sheetId];
+
+ // const arrayFormula = arrayFormulaRange[unitId][sheetId];
+
+ if (cellData == null) {
+ return true;
+ }
+
+ const setRangeValuesMutation = {
+ worksheetId: sheetId,
+ workbookId: unitId,
+ cellValue: cellData.getData(),
+ };
+
+ redoMutationsInfo.push({
+ id: SetRangeValuesMutation.id,
+ params: setRangeValuesMutation,
+ });
+ });
+ });
+
+ const result = redoMutationsInfo.every((m) =>
+ this._commandService.executeCommand(m.id, m.params, {
+ local: true,
+ })
+ );
+ return result;
+ })
+ );
+ }
+}
diff --git a/packages/formula/src/controllers/reference-executor-register.controller.ts b/packages/sheets/src/controllers/passive-dirty.controller.ts
similarity index 88%
rename from packages/formula/src/controllers/reference-executor-register.controller.ts
rename to packages/sheets/src/controllers/passive-dirty.controller.ts
index 331a1b18fd..de7130d35d 100644
--- a/packages/formula/src/controllers/reference-executor-register.controller.ts
+++ b/packages/sheets/src/controllers/passive-dirty.controller.ts
@@ -6,13 +6,11 @@ import {
ObjectMatrix,
OnLifecycle,
} from '@univerjs/core';
-import { IActiveDirtyManagerService, IPassiveDirtyManagerService } from '@univerjs/engine-formula';
+import { FormulaDataModel, IActiveDirtyManagerService, IPassiveDirtyManagerService } from '@univerjs/engine-formula';
import { Inject } from '@wendellhu/redi';
-import { FormulaDataModel } from '../models/formula-data.model';
-
-@OnLifecycle(LifecycleStages.Ready, ReferenceExecutorRegisterController)
-export class ReferenceExecutorRegisterController extends Disposable {
+@OnLifecycle(LifecycleStages.Ready, PassiveDirtyController)
+export class PassiveDirtyController extends Disposable {
constructor(
@ICommandService private readonly _commandService: ICommandService,
@IPassiveDirtyManagerService
diff --git a/packages/sheets/src/sheets-plugin.ts b/packages/sheets/src/sheets-plugin.ts
index d61a5ff8d0..e1bab7dc55 100644
--- a/packages/sheets/src/sheets-plugin.ts
+++ b/packages/sheets/src/sheets-plugin.ts
@@ -2,8 +2,11 @@ import { ICommandService, LocaleService, Plugin, PluginType } from '@univerjs/co
import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
+import { ActiveDirtyController } from './controllers/active-dirty.controller';
import { BasicWorksheetController } from './controllers/basic-worksheet.controller';
+import { CalculateResultApplyController } from './controllers/calculate-result-apply.controller';
import { MergeCellController } from './controllers/merge-cell.controller';
+import { PassiveDirtyController } from './controllers/passive-dirty.controller';
import { enUS } from './locale';
import { BorderStyleManagerService } from './services/border-style-manager.service';
import { NumfmtService } from './services/numfmt/numfmt.service';
@@ -15,6 +18,10 @@ import { SheetInterceptorService } from './services/sheet-interceptor/sheet-inte
const PLUGIN_NAME = 'sheet';
+interface ISheetsPluginConfig {
+ notExecuteFormula?: boolean;
+}
+
/**
* The main sheet base, construct the sheet container and layout, mount the rendering engine
*/
@@ -22,7 +29,7 @@ export class SheetsPlugin extends Plugin {
static override type = PluginType.Sheet;
constructor(
- config: undefined,
+ private _config: ISheetsPluginConfig,
@ICommandService private readonly _commandService: ICommandService,
@Inject(LocaleService) private readonly _localeService: LocaleService,
@Inject(Injector) override readonly _injector: Injector
@@ -51,8 +58,14 @@ export class SheetsPlugin extends Plugin {
// controllers
[BasicWorksheetController],
[MergeCellController],
+ [ActiveDirtyController],
+ [PassiveDirtyController],
];
+ if (!this._config?.notExecuteFormula) {
+ dependencies.push([CalculateResultApplyController]);
+ }
+
dependencies.forEach((d) => {
sheetInjector.add(d);
});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 34d057b705..99550c6f44 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -274,9 +274,6 @@ importers:
'@univerjs/engine-render':
specifier: workspace:*
version: link:../../packages/engine-render
- '@univerjs/formula':
- specifier: workspace:*
- version: link:../../packages/formula
'@univerjs/rpc':
specifier: workspace:*
version: link:../../packages/rpc
@@ -689,46 +686,6 @@ importers:
specifier: ^0.34.6
- packages/formula:
- dependencies:
- '@univerjs/core':
- specifier: workspace:*
- version: link:../core
- '@univerjs/engine-formula':
- specifier: workspace:*
- version: link:../engine-formula
- '@univerjs/sheets':
- specifier: workspace:*
- version: link:../sheets
- '@wendellhu/redi':
- specifier: ^0.12.11
- version: 0.12.11
- rxjs:
- specifier: ^7.8.1
- version: 7.8.1
- devDependencies:
- '@vitest/coverage-istanbul':
- specifier: ^0.34.6
- version: 0.34.6([email protected])
- esbuild:
- specifier: ^0.19.8
- version: 0.19.8
- happy-dom:
- specifier: ^12.10.3
- version: 12.10.3
- less:
- specifier: ^4.2.0
- version: 4.2.0
- ts-node:
- specifier: ^10.9.1
- typescript:
- specifier: ^5.3.2
- version: 5.3.2
- vitest:
- specifier: ^0.34.6
-
packages/image:
dependencies:
'@univerjs/core':
@@ -824,6 +781,9 @@ importers:
'@univerjs/core':
specifier: workspace:*
version: link:../core
+ '@univerjs/engine-formula':
+ specifier: workspace:*
+ version: link:../engine-formula
'@univerjs/engine-render':
specifier: workspace:*
version: link:../engine-render
@@ -925,9 +885,6 @@ importers:
'@univerjs/engine-render':
specifier: workspace:*
version: link:../engine-render
- '@univerjs/formula':
- specifier: workspace:*
- version: link:../formula
'@univerjs/icons':
specifier: ^0.1.14
diff --git a/tsconfig.json b/tsconfig.json
index 77ef32d88f..87e8975791 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -46,9 +46,6 @@
{
"path": "./packages/engine-render"
},
- {
- "path": "./packages/formula"
- },
{
"path": "./packages/image"
},