From a3dd11cae65832515cc60c0dcbd1636c1573eb74 Mon Sep 17 00:00:00 2001 From: Wenzhao Hu <12122021+wzhudev@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:57:22 +0800 Subject: [PATCH] refactor: optimize formula code --- .../mutations/set-defined-name.mutation.ts | 4 +- .../set-feature-calculation.mutation.ts | 9 +- .../mutations/set-other-formula.mutation.ts | 9 +- .../formula-scheduler.controller.ts | 25 ++++ .../src/controller/formula.controller.ts | 29 +++-- .../controller/set-defined-name.controller.ts | 67 +++++------ .../controller/set-dependency.controller.ts | 20 +--- .../set-feature-calculation.controller.ts | 12 +- .../set-other-formula.controller.ts | 53 ++++----- .../controller/set-super-table.controller.ts | 68 +++++------ .../__tests__/create-command-test-bed.ts | 33 +++--- .../analysis/__tests__/dependency.spec.ts | 10 +- .../engine/analysis/__tests__/lexer.spec.ts | 16 +-- .../engine/analysis/__tests__/parser.spec.ts | 12 +- .../src/engine/analysis/lexer.ts | 15 ++- .../src/engine/analysis/parser.ts | 4 +- .../src/engine/ast-node/function-node.ts | 23 ++-- .../src/engine/ast-node/lambda-node.ts | 4 +- .../src/engine/ast-node/operator-node.ts | 13 ++- .../src/engine/ast-node/prefix-node.ts | 8 +- .../src/engine/ast-node/reference-node.ts | 15 +-- .../src/engine/ast-node/suffix-node.ts | 18 +-- .../src/engine/ast-node/union-node.ts | 7 +- .../engine/dependency/formula-dependency.ts | 26 ++--- .../src/engine/interpreter/interpreter.ts | 6 +- .../src/engine/utils/prefixHandler.ts | 4 +- .../__tests__/create-function-test-bed.ts | 35 +++--- .../__tests__/nested-functions.spec.ts | 12 +- .../rank/__tests__/index.spec.ts | 12 +- .../information/cell/__tests__/index.spec.ts | 12 +- .../isformula/__tests__/index.spec.ts | 12 +- .../information/isref/__tests__/index.spec.ts | 12 +- .../logical/bycol/__test__/index.spec.ts | 4 +- .../logical/byrow/__test__/index.spec.ts | 4 +- .../logical/makearray/__test__/index.spec.ts | 4 +- .../logical/map/__test__/index.spec.ts | 4 +- .../logical/reduce/__test__/index.spec.ts | 4 +- .../logical/scan/__test__/index.spec.ts | 4 +- .../lookup/column/__tests__/index.spec.ts | 12 +- .../lookup/columns/__tests__/index.spec.ts | 12 +- .../lookup/index/__test__/index.spec.ts | 12 +- .../lookup/indirect/__test__/index.spec.ts | 12 +- .../lookup/offset/__tests__/index.spec.ts | 12 +- .../lookup/row/__tests__/index.spec.ts | 12 +- .../lookup/rows/__tests__/index.spec.ts | 12 +- .../math/subtotal/__tests__/index.spec.ts | 12 +- .../averageif/__tests__/index.spec.ts | 12 +- .../rank-avg/__tests__/index.spec.ts | 12 +- .../rank-eq/__tests__/index.spec.ts | 12 +- packages/engine-formula/src/index.ts | 16 +-- .../__tests__/create-command-test-bed.ts | 14 +-- .../src/models/formula-data.model.ts | 3 + packages/engine-formula/src/plugin.ts | 77 ++++++------- .../services/active-dirty-manager.service.ts | 41 +------ .../src/services/calculate-formula.service.ts | 15 ++- .../src/services/current-data.service.ts | 68 +---------- .../src/services/defined-names.service.ts | 57 ++-------- .../services/dependency-manager.service.ts | 58 +--------- .../feature-calculation-manager.service.ts | 31 +---- .../src/services/function.service.ts | 61 ++++------ .../services/other-formula-manager.service.ts | 38 +------ .../src/services/runtime.service.ts | 107 +----------------- .../src/services/super-table.service.ts | 24 +--- .../src/apis/__tests__/create-test-bed.ts | 6 +- .../__tests__/create-formula-test-bed.ts | 19 ++-- .../__tests__/create-worksheet-test-bed.ts | 6 +- .../src/services/__test__/test.util.ts | 14 +-- .../conditional-formatting-formula.service.ts | 4 +- .../__tests__/create-command-test-bed.ts | 8 +- .../update-defined-name.controller.spec.ts | 4 +- .../commands/mutations/formula.mutation.ts | 3 + .../controllers/active-dirty.controller.ts | 24 ++-- .../controllers/defined-name.controller.ts | 4 +- .../trigger-calculation.controller.ts | 12 +- .../update-defined-name.controller.ts | 8 +- .../controllers/update-formula.controller.ts | 6 +- .../src/services/description.service.ts | 4 +- .../src/services/register-function.service.ts | 6 +- .../register-other-formula.service.ts | 56 +++++---- .../remote-register-function.service.ts | 4 +- .../src/sheets-formula.plugin.ts | 18 +-- .../src/services/resolver.service.ts | 4 +- .../src/views/CellLinkEdit/index.tsx | 4 +- .../defined-name/defined-name.controller.ts | 4 +- .../editor/editing.render-controller.ts | 6 +- ...-permission-interceptor-base.controller.ts | 4 +- .../src/controllers/utils/char-tools.ts | 8 +- .../clipboard/__tests__/clipboard-test-bed.ts | 14 +-- .../src/views/defined-name/DefinedName.tsx | 4 +- .../defined-name/DefinedNameContainer.tsx | 12 +- .../views/defined-name/DefinedNameInput.tsx | 10 +- .../views/defined-name/DefinedNameOverlay.tsx | 10 +- .../commands/set-defined-name.command.ts | 2 +- .../defined-name-data.controller.ts | 4 +- 94 files changed, 640 insertions(+), 1023 deletions(-) create mode 100644 packages/engine-formula/src/controller/formula-scheduler.controller.ts diff --git a/packages/engine-formula/src/commands/mutations/set-defined-name.mutation.ts b/packages/engine-formula/src/commands/mutations/set-defined-name.mutation.ts index fa20a3051a0..5b3c53ea52c 100644 --- a/packages/engine-formula/src/commands/mutations/set-defined-name.mutation.ts +++ b/packages/engine-formula/src/commands/mutations/set-defined-name.mutation.ts @@ -16,7 +16,7 @@ import type { IAccessor, IMutation } from '@univerjs/core'; import { CommandType } from '@univerjs/core'; -import { IDefinedNamesService } from '../../services/defined-names.service'; +import { DefinedNamesService } from '../../services/defined-names.service'; export interface ISetDefinedNameMutationSearchParam { unitId: string; @@ -42,7 +42,7 @@ export const SetDefinedNameMutationFactory = ( params: ISetDefinedNameMutationParam ): ISetDefinedNameMutationParam => { const { unitId, id } = params; - const definedNamesService = accessor.get(IDefinedNamesService); + const definedNamesService = accessor.get(DefinedNamesService); const definedName = definedNamesService.getValueById(unitId, id); diff --git a/packages/engine-formula/src/commands/mutations/set-feature-calculation.mutation.ts b/packages/engine-formula/src/commands/mutations/set-feature-calculation.mutation.ts index 254687a7fe3..019f664ce9f 100644 --- a/packages/engine-formula/src/commands/mutations/set-feature-calculation.mutation.ts +++ b/packages/engine-formula/src/commands/mutations/set-feature-calculation.mutation.ts @@ -15,10 +15,10 @@ */ import type { IMutation } from '@univerjs/core'; -import { CommandType } from '@univerjs/core'; - import type { IFeatureCalculationManagerParam } from '../../services/feature-calculation-manager.service'; +import { CommandType } from '@univerjs/core'; + export interface ISetFeatureCalculationMutation { featureId: string; calculationParam: IFeatureCalculationManagerParam; @@ -26,6 +26,8 @@ export interface ISetFeatureCalculationMutation { /** * In the formula engine, the mutation is solely responsible for communication between the worker and the main thread. * It requires setting local to true during execution. + * + * @deprecated anti pattern */ export const SetFeatureCalculationMutation: IMutation = { id: 'formula.mutation.set-feature-calculation', @@ -39,6 +41,9 @@ export interface IRemoveFeatureCalculationMutationParam { subUnitId: string; } +/** + * @deprecated anti pattern + */ export const RemoveFeatureCalculationMutation: IMutation = { id: 'formula.mutation.remove-feature-calculation', type: CommandType.MUTATION, diff --git a/packages/engine-formula/src/commands/mutations/set-other-formula.mutation.ts b/packages/engine-formula/src/commands/mutations/set-other-formula.mutation.ts index 4f97ef3d11d..fb38c1dce5d 100644 --- a/packages/engine-formula/src/commands/mutations/set-other-formula.mutation.ts +++ b/packages/engine-formula/src/commands/mutations/set-other-formula.mutation.ts @@ -15,10 +15,10 @@ */ import type { IMutation } from '@univerjs/core'; -import { CommandType } from '@univerjs/core'; - import type { IFormulaDataItem } from '../../basics/common'; +import { CommandType } from '@univerjs/core'; + export interface ISetOtherFormulaMutationParams { unitId: string; subUnitId: string; @@ -35,6 +35,8 @@ export interface IRemoveOtherFormulaMutationParams { /** * In the formula engine, the mutation is solely responsible for communication between the worker and the main thread. * It requires setting local to true during execution. + * + * @deprecated anti-pattern */ export const SetOtherFormulaMutation: IMutation = { id: 'formula.mutation.set-other-formula', @@ -42,6 +44,9 @@ export const SetOtherFormulaMutation: IMutation handler: () => true, }; +/** + * @deprecated anti-pattern + */ export const RemoveOtherFormulaMutation: IMutation = { id: 'formula.mutation.remove-other-formula', type: CommandType.MUTATION, diff --git a/packages/engine-formula/src/controller/formula-scheduler.controller.ts b/packages/engine-formula/src/controller/formula-scheduler.controller.ts new file mode 100644 index 00000000000..bc0dc042e1a --- /dev/null +++ b/packages/engine-formula/src/controller/formula-scheduler.controller.ts @@ -0,0 +1,25 @@ +/** + * Copyright 2023-present DreamNum Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This controller dispose necessary API to upper layer plugins to call the formula engine, without knowing if the + * formula engine is running in the same process or in a different process. + */ +export class FormulaSchedulerController { + constructor() { + + } +} diff --git a/packages/engine-formula/src/controller/formula.controller.ts b/packages/engine-formula/src/controller/formula.controller.ts index 8dd2071e0d1..c8a7886c4be 100644 --- a/packages/engine-formula/src/controller/formula.controller.ts +++ b/packages/engine-formula/src/controller/formula.controller.ts @@ -18,7 +18,7 @@ import type { IFunctionNames } from '../basics/function'; import type { BaseFunction } from '../functions/base-function'; import type { IUniverEngineFormulaConfig } from './config.schema'; -import { Disposable, ICommandService, IConfigService } from '@univerjs/core'; +import { Disposable, ICommandService, IConfigService, Inject } from '@univerjs/core'; import { type Ctor, Optional } from '@univerjs/core'; import { DataSyncPrimaryController } from '@univerjs/rpc'; import { RegisterFunctionMutation } from '../commands/mutations/register-function.mutation'; @@ -57,26 +57,28 @@ import { functionStatistical } from '../functions/statistical/function-map'; import { functionText } from '../functions/text/function-map'; import { functionUniver } from '../functions/univer/function-map'; import { functionWeb } from '../functions/web/function-map'; -import { IFunctionService } from '../services/function.service'; +import { FunctionService } from '../services/function.service'; import { PLUGIN_CONFIG_KEY } from './config.schema'; +/** + * This controller register commands for running formula and built-in functions. + */ export class FormulaController extends Disposable { constructor( @ICommandService private readonly _commandService: ICommandService, - @IFunctionService private readonly _functionService: IFunctionService, + @Inject(FunctionService) private readonly _functionService: FunctionService, @IConfigService private readonly _configService: IConfigService, @Optional(DataSyncPrimaryController) private readonly _dataSyncPrimaryController?: DataSyncPrimaryController ) { super(); - this._initialize(); - } - - private _initialize(): void { this._registerCommands(); this._registerFunctions(); } + // DEBT@wzhudev: some mutations are mutations just be be synced into the web worker + // they **should not** be mutations in the first place. + private _registerCommands(): void { [ SetFormulaDataMutation, @@ -125,14 +127,11 @@ export class FormulaController extends Disposable { ...functionUniver, ...functionWeb, ] as Array<[Ctor, IFunctionNames]> - ) - .concat(config?.function ?? []) - .map((registerObject) => { - const Func = registerObject[0] as Ctor; - const name = registerObject[1] as IFunctionNames; - - return new Func(name); - }); + ).concat(config?.function ?? []).map((registerObject) => { + const Func = registerObject[0] as Ctor; + const name = registerObject[1] as IFunctionNames; + return new Func(name); + }); this._functionService.registerExecutors(...functions); } diff --git a/packages/engine-formula/src/controller/set-defined-name.controller.ts b/packages/engine-formula/src/controller/set-defined-name.controller.ts index 9ce75b9a1bf..1c51f7a7391 100644 --- a/packages/engine-formula/src/controller/set-defined-name.controller.ts +++ b/packages/engine-formula/src/controller/set-defined-name.controller.ts @@ -20,50 +20,45 @@ import type { ISetDefinedNameMutationSearchParam, } from '../commands/mutations/set-defined-name.mutation'; -import { Disposable, ICommandService } from '@univerjs/core'; +import { Disposable, ICommandService, Inject } from '@univerjs/core'; import { RemoveDefinedNameMutation, SetDefinedNameMutation } from '../commands/mutations/set-defined-name.mutation'; -import { IDefinedNamesService } from '../services/defined-names.service'; +import { DefinedNamesService } from '../services/defined-names.service'; +/** + * This controller is for syncing defined names between the host thread and the worker thread. + * + * @deprecated Should be under formula interface. + */ export class SetDefinedNameController extends Disposable { constructor( @ICommandService private readonly _commandService: ICommandService, - @IDefinedNamesService private readonly _definedNamesService: IDefinedNamesService + @Inject(DefinedNamesService) private readonly _definedNamesService: DefinedNamesService ) { super(); - this._initialize(); - } - - private _initialize(): void { - this._commandExecutedListener(); - } - - private _commandExecutedListener() { - this.disposeWithMe( - this._commandService.onCommandExecuted((command: ICommandInfo) => { - if (command.id === SetDefinedNameMutation.id) { - const params = command.params as ISetDefinedNameMutationParam; - if (params == null) { - return; - } - const { id, unitId, name, formulaOrRefString, comment, hidden, localSheetId } = params; - this._definedNamesService.registerDefinedName(unitId, { - id, - name: name.trim(), - formulaOrRefString: formulaOrRefString.trim(), - comment: comment?.trim(), - hidden, - localSheetId, - }); - } else if (command.id === RemoveDefinedNameMutation.id) { - const params = command.params as ISetDefinedNameMutationSearchParam; - if (params == null) { - return; - } - const { unitId, id } = params; - this._definedNamesService.removeDefinedName(unitId, id); + this.disposeWithMe(this._commandService.onCommandExecuted((command: ICommandInfo) => { + if (command.id === SetDefinedNameMutation.id) { + const params = command.params as ISetDefinedNameMutationParam; + if (params == null) { + return; + } + const { id, unitId, name, formulaOrRefString, comment, hidden, localSheetId } = params; + this._definedNamesService.registerDefinedName(unitId, { + id, + name: name.trim(), + formulaOrRefString: formulaOrRefString.trim(), + comment: comment?.trim(), + hidden, + localSheetId, + }); + } else if (command.id === RemoveDefinedNameMutation.id) { + const params = command.params as ISetDefinedNameMutationSearchParam; + if (params == null) { + return; } - }) - ); + const { unitId, id } = params; + this._definedNamesService.removeDefinedName(unitId, id); + } + })); } } diff --git a/packages/engine-formula/src/controller/set-dependency.controller.ts b/packages/engine-formula/src/controller/set-dependency.controller.ts index 617de477f7d..e512680b8dd 100644 --- a/packages/engine-formula/src/controller/set-dependency.controller.ts +++ b/packages/engine-formula/src/controller/set-dependency.controller.ts @@ -22,7 +22,7 @@ import type { ISetFeatureCalculationMutation } from '../commands/mutations/set-feature-calculation.mutation'; import type { ISetFormulaDataMutationParams } from '../commands/mutations/set-formula-data.mutation'; import type { IRemoveOtherFormulaMutationParams, ISetOtherFormulaMutationParams } from '../commands/mutations/set-other-formula.mutation'; -import { Disposable, ICommandService, ObjectMatrix } from '@univerjs/core'; +import { Disposable, ICommandService, Inject, ObjectMatrix } from '@univerjs/core'; import { SetDefinedNameMutation } from '../commands/mutations/set-defined-name.mutation'; import { RemoveFeatureCalculationMutation, @@ -30,23 +30,17 @@ import { } from '../commands/mutations/set-feature-calculation.mutation'; import { SetFormulaDataMutation } from '../commands/mutations/set-formula-data.mutation'; import { RemoveOtherFormulaMutation, SetOtherFormulaMutation } from '../commands/mutations/set-other-formula.mutation'; -import { IDependencyManagerService } from '../services/dependency-manager.service'; -import { IFeatureCalculationManagerService } from '../services/feature-calculation-manager.service'; +import { DependencyManagerService } from '../services/dependency-manager.service'; +import { FeatureCalculationManagerService } from '../services/feature-calculation-manager.service'; export class SetDependencyController extends Disposable { constructor( @ICommandService private readonly _commandService: ICommandService, - @IFeatureCalculationManagerService - @IDependencyManagerService private readonly _dependencyManagerService: IDependencyManagerService, - @IFeatureCalculationManagerService private readonly _featureCalculationManagerService: IFeatureCalculationManagerService) { + @Inject(DependencyManagerService) private readonly _dependencyManagerService: DependencyManagerService, + @Inject(FeatureCalculationManagerService) private readonly _featureCalculationManagerService: FeatureCalculationManagerService) { super(); - this._initialize(); - } - - private _initialize(): void { this._commandExecutedListener(); - this._featureCalculationManagerServiceListener(); } @@ -135,9 +129,7 @@ export class SetDependencyController extends Disposable { ); } - private _handleSetDefinedName( - command: ICommandInfo - ): void { + private _handleSetDefinedName(command: ICommandInfo): void { const params = command.params as ISetDefinedNameMutationParam; if (params == null) { return; diff --git a/packages/engine-formula/src/controller/set-feature-calculation.controller.ts b/packages/engine-formula/src/controller/set-feature-calculation.controller.ts index a15a33c328f..5a3f1acbf52 100644 --- a/packages/engine-formula/src/controller/set-feature-calculation.controller.ts +++ b/packages/engine-formula/src/controller/set-feature-calculation.controller.ts @@ -19,25 +19,21 @@ import type { IRemoveFeatureCalculationMutationParam, ISetFeatureCalculationMutation, } from '../commands/mutations/set-feature-calculation.mutation'; -import { Disposable, ICommandService } from '@univerjs/core'; +import { Disposable, ICommandService, Inject } from '@univerjs/core'; import { RemoveFeatureCalculationMutation, SetFeatureCalculationMutation, } from '../commands/mutations/set-feature-calculation.mutation'; -import { IFeatureCalculationManagerService } from '../services/feature-calculation-manager.service'; +import { FeatureCalculationManagerService } from '../services/feature-calculation-manager.service'; export class SetFeatureCalculationController extends Disposable { constructor( @ICommandService private readonly _commandService: ICommandService, - @IFeatureCalculationManagerService - private readonly _featureCalculationManagerService: IFeatureCalculationManagerService + @Inject(FeatureCalculationManagerService) + private readonly _featureCalculationManagerService: FeatureCalculationManagerService ) { super(); - this._initialize(); - } - - private _initialize(): void { this._commandExecutedListener(); } diff --git a/packages/engine-formula/src/controller/set-other-formula.controller.ts b/packages/engine-formula/src/controller/set-other-formula.controller.ts index 9f1bf54c203..b31eb71c16b 100644 --- a/packages/engine-formula/src/controller/set-other-formula.controller.ts +++ b/packages/engine-formula/src/controller/set-other-formula.controller.ts @@ -16,50 +16,39 @@ import type { ICommandInfo } from '@univerjs/core'; import type { IRemoveOtherFormulaMutationParams, ISetOtherFormulaMutationParams } from '../commands/mutations/set-other-formula.mutation'; - -import { Disposable, ICommandService } from '@univerjs/core'; +import { Disposable, ICommandService, Inject } from '@univerjs/core'; import { RemoveOtherFormulaMutation, SetOtherFormulaMutation } from '../commands/mutations/set-other-formula.mutation'; -import { IDependencyManagerService } from '../services/dependency-manager.service'; -import { - IOtherFormulaManagerService, -} from '../services/other-formula-manager.service'; +import { OtherFormulaManagerService } from '../services/other-formula-manager.service'; export class SetOtherFormulaController extends Disposable { constructor( @ICommandService private readonly _commandService: ICommandService, - @IOtherFormulaManagerService private readonly _otherFormulaManagerService: IOtherFormulaManagerService, - @IDependencyManagerService private readonly _dependencyManagerService: IDependencyManagerService + @Inject(OtherFormulaManagerService) private readonly _otherFormulaManagerService: OtherFormulaManagerService ) { super(); - this._initialize(); - } - - private _initialize(): void { this._commandExecutedListener(); } private _commandExecutedListener() { - this.disposeWithMe( - this._commandService.onCommandExecuted((command: ICommandInfo) => { - if (command.id === SetOtherFormulaMutation.id) { - const params = command.params as ISetOtherFormulaMutationParams; - if (params == null) { - return; - } - const config = { [params.unitId]: { [params.subUnitId]: params.formulaMap } }; - this._otherFormulaManagerService.batchRegister(config); - } else if (command.id === RemoveOtherFormulaMutation.id) { - const params = command.params as IRemoveOtherFormulaMutationParams; - if (params == null) { - return; - } - const obj: Record = {}; - params.formulaIdList.forEach((id) => obj[id] = true); - const config = { [params.unitId]: { [params.subUnitId]: obj } }; - this._otherFormulaManagerService.batchRemove(config); + this.disposeWithMe(this._commandService.onCommandExecuted((command: ICommandInfo) => { + if (command.id === SetOtherFormulaMutation.id) { + const params = command.params as ISetOtherFormulaMutationParams; + if (params == null) { + return; + } + const config = { [params.unitId]: { [params.subUnitId]: params.formulaMap } }; + this._otherFormulaManagerService.batchRegister(config); + } else if (command.id === RemoveOtherFormulaMutation.id) { + const params = command.params as IRemoveOtherFormulaMutationParams; + if (params == null) { + return; } - }) - ); + const obj: Record = {}; + params.formulaIdList.forEach((id) => obj[id] = true); + const config = { [params.unitId]: { [params.subUnitId]: obj } }; + this._otherFormulaManagerService.batchRemove(config); + } + })); } } diff --git a/packages/engine-formula/src/controller/set-super-table.controller.ts b/packages/engine-formula/src/controller/set-super-table.controller.ts index f790977ab1f..7b8ca3a69ae 100644 --- a/packages/engine-formula/src/controller/set-super-table.controller.ts +++ b/packages/engine-formula/src/controller/set-super-table.controller.ts @@ -15,57 +15,51 @@ */ import type { ICommandInfo } from '@univerjs/core'; -import type { ISuperTableOptionParam } from '../services/super-table.service'; +import { Disposable, ICommandService, Inject } from '@univerjs/core'; -import { Disposable, ICommandService } from '@univerjs/core'; import { RemoveDefinedNameMutation, SetDefinedNameMutation } from '../commands/mutations/set-defined-name.mutation'; import { type ISetSuperTableMutationParam, type ISetSuperTableMutationSearchParam, SetSuperTableOptionMutation, } from '../commands/mutations/set-super-table.mutation'; -import { ISuperTableService } from '../services/super-table.service'; +import { type ISuperTableOptionParam, SuperTableService } from '../services/super-table.service'; +/** + * This controller is for syncing super tables between the host thread and the worker thread. + * + * @deprecated Should be under formula interface. + */ export class SetSuperTableController extends Disposable { constructor( @ICommandService private readonly _commandService: ICommandService, - @ISuperTableService private readonly _superTableService: ISuperTableService + @Inject(SuperTableService) private readonly _superTableService: SuperTableService ) { super(); - this._initialize(); - } - - private _initialize(): void { - this._commandExecutedListener(); - } - - private _commandExecutedListener() { - this.disposeWithMe( - this._commandService.onCommandExecuted((command: ICommandInfo) => { - if (command.id === SetDefinedNameMutation.id) { - const params = command.params as ISetSuperTableMutationParam; - if (params == null) { - return; - } - const { unitId, tableName, reference } = params; - this._superTableService.registerTable(unitId, tableName, reference); - } else if (command.id === RemoveDefinedNameMutation.id) { - const params = command.params as ISetSuperTableMutationSearchParam; - if (params == null) { - return; - } - const { unitId, tableName } = params; - this._superTableService.remove(unitId, tableName); - } else if (command.id === SetSuperTableOptionMutation.id) { - const params = command.params as ISuperTableOptionParam; - if (params == null) { - return; - } - const { tableOption, tableOptionType } = params; - this._superTableService.registerTableOptionMap(tableOption, tableOptionType); + this.disposeWithMe(this._commandService.onCommandExecuted((command: ICommandInfo) => { + if (command.id === SetDefinedNameMutation.id) { + const params = command.params as ISetSuperTableMutationParam; + if (params == null) { + return; + } + const { unitId, tableName, reference } = params; + this._superTableService.registerTable(unitId, tableName, reference); + } else if (command.id === RemoveDefinedNameMutation.id) { + const params = command.params as ISetSuperTableMutationSearchParam; + if (params == null) { + return; + } + const { unitId, tableName } = params; + this._superTableService.remove(unitId, tableName); + } else if (command.id === SetSuperTableOptionMutation.id) { + const params = command.params as ISuperTableOptionParam; + if (params == null) { + return; } - }) - ); + const { tableOption, tableOptionType } = params; + this._superTableService.registerTableOptionMap(tableOption, tableOptionType); + } + })); } } diff --git a/packages/engine-formula/src/engine/analysis/__tests__/create-command-test-bed.ts b/packages/engine-formula/src/engine/analysis/__tests__/create-command-test-bed.ts index 90cc14454cd..e7334321cee 100644 --- a/packages/engine-formula/src/engine/analysis/__tests__/create-command-test-bed.ts +++ b/packages/engine-formula/src/engine/analysis/__tests__/create-command-test-bed.ts @@ -32,17 +32,13 @@ import { UniverInstanceType, } from '@univerjs/core'; import { CalculateFormulaService } from '../../../services/calculate-formula.service'; -import { FormulaCurrentConfigService, IFormulaCurrentConfigService } from '../../../services/current-data.service'; -import { DefinedNamesService, IDefinedNamesService } from '../../../services/defined-names.service'; -import { DependencyManagerService, IDependencyManagerService } from '../../../services/dependency-manager.service'; -import { FeatureCalculationManagerService, IFeatureCalculationManagerService } from '../../../services/feature-calculation-manager.service'; -import { FunctionService, IFunctionService } from '../../../services/function.service'; -import { - IOtherFormulaManagerService, - OtherFormulaManagerService, -} from '../../../services/other-formula-manager.service'; -import { FormulaRuntimeService, IFormulaRuntimeService } from '../../../services/runtime.service'; -import { ISuperTableService, SuperTableService } from '../../../services/super-table.service'; +import { FormulaCurrentConfigService } from '../../../services/current-data.service'; +import { DefinedNamesService } from '../../../services/defined-names.service'; +import { DependencyManagerService } from '../../../services/dependency-manager.service'; +import { FeatureCalculationManagerService } from '../../../services/feature-calculation-manager.service'; +import { FunctionService } from '../../../services/function.service'; +import { OtherFormulaManagerService } from '../../../services/other-formula-manager.service'; +import { FormulaRuntimeService } from '../../../services/runtime.service'; import { AstRootNodeFactory } from '../../ast-node/ast-root-node'; import { FunctionNodeFactory } from '../../ast-node/function-node'; import { LambdaNodeFactory } from '../../ast-node/lambda-node'; @@ -295,14 +291,13 @@ function registerFormulaDependencies(injector: Injector) { injector.add([Lexer]); injector.add([LexerTreeBuilder]); - injector.add([IFormulaCurrentConfigService, { useClass: FormulaCurrentConfigService }]); - injector.add([IFormulaRuntimeService, { useClass: FormulaRuntimeService }]); - injector.add([IFunctionService, { useClass: FunctionService }]); - injector.add([IOtherFormulaManagerService, { useClass: OtherFormulaManagerService }]); - injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]); - injector.add([ISuperTableService, { useClass: SuperTableService }]); - injector.add([IFeatureCalculationManagerService, { useClass: FeatureCalculationManagerService }]); - injector.add([IDependencyManagerService, { useClass: DependencyManagerService }]); + injector.add([FormulaCurrentConfigService]); + injector.add([FormulaRuntimeService]); + injector.add([FunctionService]); + injector.add([OtherFormulaManagerService]); + injector.add([DefinedNamesService]); + injector.add([FeatureCalculationManagerService]); + injector.add([DependencyManagerService]); injector.add([FormulaDependencyGenerator]); injector.add([Interpreter]); diff --git a/packages/engine-formula/src/engine/analysis/__tests__/dependency.spec.ts b/packages/engine-formula/src/engine/analysis/__tests__/dependency.spec.ts index 64b4d1dd7fc..4e9ebb8f42d 100644 --- a/packages/engine-formula/src/engine/analysis/__tests__/dependency.spec.ts +++ b/packages/engine-formula/src/engine/analysis/__tests__/dependency.spec.ts @@ -17,15 +17,15 @@ import type { Injector } from '@univerjs/core'; import { beforeEach, describe, expect, it } from 'vitest'; -import { IFormulaCurrentConfigService } from '../../../services/current-data.service'; -import { IFormulaRuntimeService } from '../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../services/current-data.service'; +import { FormulaRuntimeService } from '../../../services/runtime.service'; import { FormulaDependencyGenerator } from '../../dependency/formula-dependency'; import { createCommandTestBed } from './create-command-test-bed'; describe('Test indirect', () => { let get: Injector['get']; let formulaDependencyGenerator: FormulaDependencyGenerator; - let formulaCurrentConfigService: IFormulaCurrentConfigService; + let formulaCurrentConfigService: FormulaCurrentConfigService; let testUnitId = 'test'; let testSheetId = 'sheet1'; let testSheetData = {}; @@ -36,9 +36,9 @@ describe('Test indirect', () => { formulaDependencyGenerator = get(FormulaDependencyGenerator); - formulaCurrentConfigService = get(IFormulaCurrentConfigService); + formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); const sheetItem = testBed.sheetData[testBed.sheetId]; diff --git a/packages/engine-formula/src/engine/analysis/__tests__/lexer.spec.ts b/packages/engine-formula/src/engine/analysis/__tests__/lexer.spec.ts index f5214dfb58a..f730e1e0574 100644 --- a/packages/engine-formula/src/engine/analysis/__tests__/lexer.spec.ts +++ b/packages/engine-formula/src/engine/analysis/__tests__/lexer.spec.ts @@ -15,14 +15,14 @@ */ import type { Injector, IWorkbookData, Univer, Workbook } from '@univerjs/core'; +import type { LexerNode } from '../lexer-node'; import { LocaleType } from '@univerjs/core'; -import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { IDefinedNamesService } from '../../../services/defined-names.service'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +import { FormulaCurrentConfigService } from '../../../services/current-data.service'; +import { DefinedNamesService } from '../../../services/defined-names.service'; import { Lexer } from '../lexer'; -import type { LexerNode } from '../lexer-node'; import { LexerTreeBuilder } from '../lexer-tree-builder'; -import { IFormulaCurrentConfigService } from '../../../services/current-data.service'; import { createCommandTestBed } from './create-command-test-bed'; const TEST_WORKBOOK_DATA: IWorkbookData = { @@ -66,8 +66,8 @@ describe('lexer test', () => { let lexer: Lexer; let get: Injector['get']; let workbook: Workbook; - let definedNamesService: IDefinedNamesService; - let formulaCurrentConfigService: IFormulaCurrentConfigService; + let definedNamesService: DefinedNamesService; + let formulaCurrentConfigService: FormulaCurrentConfigService; let lexerTreeBuilder: LexerTreeBuilder; beforeEach(() => { @@ -76,8 +76,8 @@ describe('lexer test', () => { workbook = testBed.sheet; get = testBed.get; - definedNamesService = get(IDefinedNamesService); - formulaCurrentConfigService = get(IFormulaCurrentConfigService); + definedNamesService = get(DefinedNamesService); + formulaCurrentConfigService = get(FormulaCurrentConfigService); lexerTreeBuilder = get(LexerTreeBuilder); formulaCurrentConfigService.setExecuteUnitId('test'); diff --git a/packages/engine-formula/src/engine/analysis/__tests__/parser.spec.ts b/packages/engine-formula/src/engine/analysis/__tests__/parser.spec.ts index 722f416657b..2fc13593ad0 100644 --- a/packages/engine-formula/src/engine/analysis/__tests__/parser.spec.ts +++ b/packages/engine-formula/src/engine/analysis/__tests__/parser.spec.ts @@ -29,9 +29,9 @@ import { Divided } from '../../../functions/meta/divided'; import { FUNCTION_NAMES_META } from '../../../functions/meta/function-names'; import { Minus } from '../../../functions/meta/minus'; import { Plus } from '../../../functions/meta/plus'; -import { IFormulaCurrentConfigService } from '../../../services/current-data.service'; -import { IFunctionService } from '../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../services/current-data.service'; +import { FunctionService } from '../../../services/function.service'; +import { FormulaRuntimeService } from '../../../services/runtime.service'; import { Interpreter } from '../../interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../utils/ast-node-tool'; import { Lexer } from '../lexer'; @@ -53,11 +53,11 @@ describe('Test indirect', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/engine/analysis/lexer.ts b/packages/engine-formula/src/engine/analysis/lexer.ts index 0ac32cc9ca3..857fa0b94c0 100644 --- a/packages/engine-formula/src/engine/analysis/lexer.ts +++ b/packages/engine-formula/src/engine/analysis/lexer.ts @@ -14,21 +14,20 @@ * limitations under the License. */ -import { Disposable, Inject } from '@univerjs/core'; - -import { IDefinedNamesService } from '../../services/defined-names.service'; import type { ISequenceArray } from '../utils/sequence'; -import { sequenceNodeType } from '../utils/sequence'; -import { operatorToken } from '../../basics/token'; -import { IFormulaCurrentConfigService } from '../../services/current-data.service'; +import { Disposable, Inject } from '@univerjs/core'; import { ErrorType } from '../../basics/error-type'; +import { operatorToken } from '../../basics/token'; +import { FormulaCurrentConfigService } from '../../services/current-data.service'; +import { DefinedNamesService } from '../../services/defined-names.service'; +import { sequenceNodeType } from '../utils/sequence'; import { LexerTreeBuilder } from './lexer-tree-builder'; export class Lexer extends Disposable { constructor( - @IDefinedNamesService private readonly _definedNamesService: IDefinedNamesService, + @Inject(DefinedNamesService) private readonly _definedNamesService: DefinedNamesService, @Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder, - @IFormulaCurrentConfigService private readonly _formulaCurrentConfigService: IFormulaCurrentConfigService + @Inject(FormulaCurrentConfigService) private readonly _formulaCurrentConfigService: FormulaCurrentConfigService ) { super(); } diff --git a/packages/engine-formula/src/engine/analysis/parser.ts b/packages/engine-formula/src/engine/analysis/parser.ts index ce8bf40e0ed..91a72b67fe2 100644 --- a/packages/engine-formula/src/engine/analysis/parser.ts +++ b/packages/engine-formula/src/engine/analysis/parser.ts @@ -28,7 +28,7 @@ import { DEFAULT_TOKEN_TYPE_ROOT, FORCED_RECALCULATION_FUNCTION_NAME, } from '../../basics/token-type'; -import { IFormulaRuntimeService } from '../../services/runtime.service'; +import { FormulaRuntimeService } from '../../services/runtime.service'; import { AstRootNode, AstRootNodeFactory } from '../ast-node/ast-root-node'; import { ErrorNode } from '../ast-node/base-ast-node'; import { ErrorFunctionNode, FunctionNodeFactory } from '../ast-node/function-node'; @@ -55,7 +55,7 @@ export class AstTreeBuilder extends Disposable { private _refOffsetY = 0; constructor( - @IFormulaRuntimeService private readonly _runtimeService: IFormulaRuntimeService, + @Inject(FormulaRuntimeService) private readonly _runtimeService: FormulaRuntimeService, @Inject(AstRootNodeFactory) private readonly _astRootNodeFactory: AstRootNodeFactory, @Inject(FunctionNodeFactory) private readonly _functionNodeFactory: FunctionNodeFactory, @Inject(LambdaNodeFactory) private readonly _lambdaNodeFactory: LambdaNodeFactory, diff --git a/packages/engine-formula/src/engine/ast-node/function-node.ts b/packages/engine-formula/src/engine/ast-node/function-node.ts index 281782e003a..92284c7525d 100644 --- a/packages/engine-formula/src/engine/ast-node/function-node.ts +++ b/packages/engine-formula/src/engine/ast-node/function-node.ts @@ -15,7 +15,6 @@ */ import type { BaseFunction } from '../../functions/base-function'; - import type { LexerNode } from '../analysis/lexer-node'; import type { AsyncArrayObject, @@ -28,10 +27,10 @@ import { Inject, Injector } from '@univerjs/core'; import { AstNodePromiseType } from '../../basics/common'; import { ErrorType } from '../../basics/error-type'; import { matchToken } from '../../basics/token'; -import { IFormulaCurrentConfigService } from '../../services/current-data.service'; -import { IDefinedNamesService } from '../../services/defined-names.service'; -import { IFunctionService } from '../../services/function.service'; -import { IFormulaRuntimeService } from '../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../services/current-data.service'; +import { DefinedNamesService } from '../../services/defined-names.service'; +import { FunctionService } from '../../services/function.service'; +import { FormulaRuntimeService } from '../../services/runtime.service'; import { prefixHandler } from '../utils/prefixHandler'; import { ArrayValueObject, transformToValueObject, ValueObjectFactory } from '../value-object/array-value-object'; import { type BaseValueObject, ErrorValueObject } from '../value-object/base-value-object'; @@ -43,9 +42,9 @@ export class FunctionNode extends BaseAstNode { constructor( token: string, private _functionExecutor: BaseFunction, - private _currentConfigService: IFormulaCurrentConfigService, - private _runtimeService: IFormulaRuntimeService, - private _definedNamesService: IDefinedNamesService + private _currentConfigService: FormulaCurrentConfigService, + private _runtimeService: FormulaRuntimeService, + private _definedNamesService: DefinedNamesService ) { super(token); @@ -300,10 +299,10 @@ export class ErrorFunctionNode extends BaseAstNode { export class FunctionNodeFactory extends BaseAstNodeFactory { constructor( - @IFunctionService private readonly _functionService: IFunctionService, - @IFormulaCurrentConfigService private readonly _currentConfigService: IFormulaCurrentConfigService, - @IFormulaRuntimeService private readonly _runtimeService: IFormulaRuntimeService, - @IDefinedNamesService private readonly _definedNamesService: IDefinedNamesService, + @Inject(FunctionService) private readonly _functionService: FunctionService, + @Inject(FormulaCurrentConfigService) private readonly _currentConfigService: FormulaCurrentConfigService, + @Inject(FormulaRuntimeService) private readonly _runtimeService: FormulaRuntimeService, + @Inject(DefinedNamesService) private readonly _definedNamesService: DefinedNamesService, @Inject(Injector) private readonly _injector: Injector ) { super(); diff --git a/packages/engine-formula/src/engine/ast-node/lambda-node.ts b/packages/engine-formula/src/engine/ast-node/lambda-node.ts index 5890b7d9d63..eebf3ef3dc7 100644 --- a/packages/engine-formula/src/engine/ast-node/lambda-node.ts +++ b/packages/engine-formula/src/engine/ast-node/lambda-node.ts @@ -24,7 +24,7 @@ import { DEFAULT_TOKEN_TYPE_LAMBDA_OMIT_PARAMETER, DEFAULT_TOKEN_TYPE_LAMBDA_PARAMETER, } from '../../basics/token-type'; -import { IFormulaRuntimeService } from '../../services/runtime.service'; +import { FormulaRuntimeService } from '../../services/runtime.service'; import { LexerNode } from '../analysis/lexer-node'; import { Interpreter } from '../interpreter/interpreter'; import { updateLambdaStatement } from '../utils/update-lambda-statement'; @@ -90,7 +90,7 @@ export class LambdaNode extends BaseAstNode { export class LambdaNodeFactory extends BaseAstNodeFactory { constructor( - @IFormulaRuntimeService private readonly _runtimeService: IFormulaRuntimeService, + @Inject(FormulaRuntimeService) private readonly _runtimeService: FormulaRuntimeService, @Inject(Interpreter) private readonly _interpreter: Interpreter ) { super(); diff --git a/packages/engine-formula/src/engine/ast-node/operator-node.ts b/packages/engine-formula/src/engine/ast-node/operator-node.ts index 2f5a9807cd6..afcff88a3bd 100644 --- a/packages/engine-formula/src/engine/ast-node/operator-node.ts +++ b/packages/engine-formula/src/engine/ast-node/operator-node.ts @@ -14,17 +14,18 @@ * limitations under the License. */ -import { ErrorType } from '../../basics/error-type'; import type { compareToken } from '../../basics/token'; -import { OPERATOR_TOKEN_COMPARE_SET, OPERATOR_TOKEN_SET, operatorToken } from '../../basics/token'; import type { BaseFunction } from '../../functions/base-function'; -import { FUNCTION_NAMES_MATH } from '../../functions/math/function-names'; import type { Compare } from '../../functions/meta/compare'; +import type { BaseReferenceObject, FunctionVariantType } from '../reference-object/base-reference-object'; +import { Inject } from '@univerjs/core'; +import { ErrorType } from '../../basics/error-type'; +import { OPERATOR_TOKEN_COMPARE_SET, OPERATOR_TOKEN_SET, operatorToken } from '../../basics/token'; +import { FUNCTION_NAMES_MATH } from '../../functions/math/function-names'; import { FUNCTION_NAMES_META } from '../../functions/meta/function-names'; import { FUNCTION_NAMES_TEXT } from '../../functions/text/function-names'; -import { IFunctionService } from '../../services/function.service'; +import { FunctionService } from '../../services/function.service'; import { LexerNode } from '../analysis/lexer-node'; -import type { BaseReferenceObject, FunctionVariantType } from '../reference-object/base-reference-object'; import { type BaseValueObject, ErrorValueObject } from '../value-object/base-value-object'; import { NullValueObject } from '../value-object/primitive-object'; import { BaseAstNode, ErrorNode } from './base-ast-node'; @@ -84,7 +85,7 @@ export class OperatorNode extends BaseAstNode { } export class OperatorNodeFactory extends BaseAstNodeFactory { - constructor(@IFunctionService private readonly _functionService: IFunctionService) { + constructor(@Inject(FunctionService) private readonly _functionService: FunctionService) { super(); } diff --git a/packages/engine-formula/src/engine/ast-node/prefix-node.ts b/packages/engine-formula/src/engine/ast-node/prefix-node.ts index e99c53279b1..045a9000f7a 100644 --- a/packages/engine-formula/src/engine/ast-node/prefix-node.ts +++ b/packages/engine-formula/src/engine/ast-node/prefix-node.ts @@ -23,8 +23,8 @@ import { Inject, Injector } from '@univerjs/core'; import { ErrorType } from '../../basics/error-type'; import { prefixToken } from '../../basics/token'; import { FUNCTION_NAMES_META } from '../../functions/meta/function-names'; -import { IFunctionService } from '../../services/function.service'; -import { IFormulaRuntimeService } from '../../services/runtime.service'; +import { FunctionService } from '../../services/function.service'; +import { FormulaRuntimeService } from '../../services/runtime.service'; import { LexerNode } from '../analysis/lexer-node'; import { ErrorValueObject } from '../value-object/base-value-object'; import { NumberValueObject } from '../value-object/primitive-object'; @@ -80,7 +80,7 @@ export class PrefixNode extends BaseAstNode { return ErrorValueObject.create(ErrorType.VALUE); } - const runtimeService = this._accessor.get(IFormulaRuntimeService); + const runtimeService = this._accessor.get(FormulaRuntimeService); const currentRow = runtimeService.currentRow || 0; const currentColumn = runtimeService.currentColumn || 0; @@ -114,7 +114,7 @@ export class PrefixNode extends BaseAstNode { export class PrefixNodeFactory extends BaseAstNodeFactory { constructor( - @IFunctionService private readonly _functionService: IFunctionService, + @Inject(FunctionService) private readonly _functionService: FunctionService, @Inject(Injector) private readonly _injector: Injector ) { super(); diff --git a/packages/engine-formula/src/engine/ast-node/reference-node.ts b/packages/engine-formula/src/engine/ast-node/reference-node.ts index f03637a9bb8..4eaa72a44ad 100644 --- a/packages/engine-formula/src/engine/ast-node/reference-node.ts +++ b/packages/engine-formula/src/engine/ast-node/reference-node.ts @@ -25,10 +25,9 @@ import { regexTestSingleRow, } from '../../basics/regex'; import { matchToken } from '../../basics/token'; -import { IFormulaCurrentConfigService } from '../../services/current-data.service'; -import { IFunctionService } from '../../services/function.service'; -import { IFormulaRuntimeService } from '../../services/runtime.service'; -import { ISuperTableService } from '../../services/super-table.service'; +import { FormulaCurrentConfigService } from '../../services/current-data.service'; +import { FunctionService } from '../../services/function.service'; +import { FormulaRuntimeService } from '../../services/runtime.service'; import { LexerNode } from '../analysis/lexer-node'; import { CellReferenceObject } from '../reference-object/cell-reference-object'; import { ColumnReferenceObject } from '../reference-object/column-reference-object'; @@ -57,8 +56,8 @@ export class ReferenceNode extends BaseAstNode { } override execute() { - const currentConfigService = this._accessor.get(IFormulaCurrentConfigService); - const runtimeService = this._accessor.get(IFormulaRuntimeService); + const currentConfigService = this._accessor.get(FormulaCurrentConfigService); + const runtimeService = this._accessor.get(FormulaRuntimeService); this._referenceObject.setDefaultUnitId(runtimeService.currentUnitId); @@ -104,9 +103,7 @@ export class ReferenceNode extends BaseAstNode { export class ReferenceNodeFactory extends BaseAstNodeFactory { constructor( - @ISuperTableService private readonly _superTableService: ISuperTableService, - @IFormulaRuntimeService private readonly _formulaRuntimeService: IFormulaRuntimeService, - @IFunctionService private readonly _functionService: IFunctionService, + @Inject(FunctionService) private readonly _functionService: FunctionService, @Inject(Injector) private readonly _injector: Injector ) { super(); diff --git a/packages/engine-formula/src/engine/ast-node/suffix-node.ts b/packages/engine-formula/src/engine/ast-node/suffix-node.ts index 14b3c58873e..f66d1f55ef5 100644 --- a/packages/engine-formula/src/engine/ast-node/suffix-node.ts +++ b/packages/engine-formula/src/engine/ast-node/suffix-node.ts @@ -15,19 +15,19 @@ */ import type { IAccessor } from '@univerjs/core'; -import { Inject, Injector } from '@univerjs/core'; +import type { BaseFunction } from '../../functions/base-function'; +import type { BaseReferenceObject, FunctionVariantType } from '../reference-object/base-reference-object'; +import type { CellReferenceObject } from '../reference-object/cell-reference-object'; +import type { BaseValueObject } from '../value-object/base-value-object'; +import { Inject, Injector } from '@univerjs/core'; import { ErrorType } from '../../basics/error-type'; import { suffixToken } from '../../basics/token'; -import type { BaseFunction } from '../../functions/base-function'; import { FUNCTION_NAMES_META } from '../../functions/meta/function-names'; -import { IFormulaCurrentConfigService } from '../../services/current-data.service'; -import { IFunctionService } from '../../services/function.service'; +import { FormulaCurrentConfigService } from '../../services/current-data.service'; +import { FunctionService } from '../../services/function.service'; import { Lexer } from '../analysis/lexer'; import { LexerNode } from '../analysis/lexer-node'; -import type { BaseReferenceObject, FunctionVariantType } from '../reference-object/base-reference-object'; -import type { CellReferenceObject } from '../reference-object/cell-reference-object'; -import type { BaseValueObject } from '../value-object/base-value-object'; import { ErrorValueObject } from '../value-object/base-value-object'; import { NumberValueObject } from '../value-object/primitive-object'; import { BaseAstNode, ErrorNode } from './base-ast-node'; @@ -91,7 +91,7 @@ export class SuffixNode extends BaseAstNode { return ErrorValueObject.create(ErrorType.VALUE); } - const currentConfigService = this._accessor.get(IFormulaCurrentConfigService); + const currentConfigService = this._accessor.get(FormulaCurrentConfigService); const lexer = this._accessor.get(Lexer); @@ -116,7 +116,7 @@ export class SuffixNode extends BaseAstNode { export class SuffixNodeFactory extends BaseAstNodeFactory { constructor( - @IFunctionService private readonly _functionService: IFunctionService, + @Inject(FunctionService) private readonly _functionService: FunctionService, @Inject(Injector) private readonly _injector: Injector ) { super(); diff --git a/packages/engine-formula/src/engine/ast-node/union-node.ts b/packages/engine-formula/src/engine/ast-node/union-node.ts index a44885903e0..dedaac69cdb 100644 --- a/packages/engine-formula/src/engine/ast-node/union-node.ts +++ b/packages/engine-formula/src/engine/ast-node/union-node.ts @@ -14,11 +14,12 @@ * limitations under the License. */ +import type { BaseReferenceObject, FunctionVariantType } from '../reference-object/base-reference-object'; +import { Inject } from '@univerjs/core'; import { ErrorType } from '../../basics/error-type'; import { matchToken } from '../../basics/token'; -import { IFunctionService } from '../../services/function.service'; +import { FunctionService } from '../../services/function.service'; import { LexerNode } from '../analysis/lexer-node'; -import type { BaseReferenceObject, FunctionVariantType } from '../reference-object/base-reference-object'; import { ErrorValueObject } from '../value-object/base-value-object'; import { BaseAstNode } from './base-ast-node'; import { BaseAstNodeFactory, DEFAULT_AST_NODE_FACTORY_Z_INDEX } from './base-ast-node-factory'; @@ -82,7 +83,7 @@ export class UnionNode extends BaseAstNode { } export class UnionNodeFactory extends BaseAstNodeFactory { - constructor(@IFunctionService private readonly _functionService: IFunctionService) { + constructor(@Inject(FunctionService) private readonly _functionService: FunctionService) { super(); } diff --git a/packages/engine-formula/src/engine/dependency/formula-dependency.ts b/packages/engine-formula/src/engine/dependency/formula-dependency.ts index 2beecb0e920..8faece68292 100644 --- a/packages/engine-formula/src/engine/dependency/formula-dependency.ts +++ b/packages/engine-formula/src/engine/dependency/formula-dependency.ts @@ -18,9 +18,6 @@ import type { IRange, IUnitRange, Nullable } from '@univerjs/core'; import type { IFeatureDirtyRangeType, IFormulaData, IOtherFormulaData, IUnitData } from '../../basics/common'; import type { ErrorType } from '../../basics/error-type'; -import type { IFormulaDirtyData } from '../../services/current-data.service'; -import type { IFeatureCalculationManagerParam } from '../../services/feature-calculation-manager.service'; -import type { IAllRuntimeData } from '../../services/runtime.service'; import type { LexerNode } from '../analysis/lexer-node'; import type { AstRootNode, FunctionNode, PrefixNode, SuffixNode } from '../ast-node'; import type { BaseAstNode } from '../ast-node/base-ast-node'; @@ -30,11 +27,11 @@ import { Disposable, Inject, moveRangeByOffset, ObjectMatrix } from '@univerjs/c import { FormulaAstLRU } from '../../basics/cache-lru'; import { ERROR_TYPE_SET } from '../../basics/error-type'; import { prefixToken, suffixToken } from '../../basics/token'; -import { IFormulaCurrentConfigService } from '../../services/current-data.service'; -import { IDependencyManagerService } from '../../services/dependency-manager.service'; -import { IFeatureCalculationManagerService } from '../../services/feature-calculation-manager.service'; -import { IOtherFormulaManagerService } from '../../services/other-formula-manager.service'; -import { IFormulaRuntimeService } from '../../services/runtime.service'; +import { FormulaCurrentConfigService, type IFormulaDirtyData } from '../../services/current-data.service'; +import { DependencyManagerService } from '../../services/dependency-manager.service'; +import { FeatureCalculationManagerService, type IFeatureCalculationManagerParam } from '../../services/feature-calculation-manager.service'; +import { OtherFormulaManagerService } from '../../services/other-formula-manager.service'; +import { FormulaRuntimeService, type IAllRuntimeData } from '../../services/runtime.service'; import { Lexer } from '../analysis/lexer'; import { AstTreeBuilder } from '../analysis/parser'; import { ErrorNode } from '../ast-node/base-ast-node'; @@ -51,7 +48,7 @@ interface IFeatureFormulaParam { featureId: string; } -function generateRandomDependencyTreeId(dependencyManagerService: IDependencyManagerService): string { +function generateRandomDependencyTreeId(dependencyManagerService: DependencyManagerService): string { const idNum = dependencyManagerService.getLastTreeId() || 0; return idNum.toString(); } @@ -61,15 +58,14 @@ export class FormulaDependencyGenerator extends Disposable { private _updateRangeFlattenCache = new Map>(); constructor( - @IFormulaCurrentConfigService private readonly _currentConfigService: IFormulaCurrentConfigService, - @IFormulaRuntimeService private readonly _runtimeService: IFormulaRuntimeService, - @IOtherFormulaManagerService private readonly _otherFormulaManagerService: IOtherFormulaManagerService, - @IFeatureCalculationManagerService - private readonly _featureCalculationManagerService: IFeatureCalculationManagerService, + @Inject(FormulaCurrentConfigService) private readonly _currentConfigService: FormulaCurrentConfigService, + @Inject(FormulaRuntimeService) private readonly _runtimeService: FormulaRuntimeService, + @Inject(OtherFormulaManagerService) private readonly _otherFormulaManagerService: OtherFormulaManagerService, + @Inject(FeatureCalculationManagerService) private readonly _featureCalculationManagerService: FeatureCalculationManagerService, @Inject(Interpreter) private readonly _interpreter: Interpreter, @Inject(AstTreeBuilder) private readonly _astTreeBuilder: AstTreeBuilder, @Inject(Lexer) private readonly _lexer: Lexer, - @IDependencyManagerService private readonly _dependencyManagerService: IDependencyManagerService + @Inject(DependencyManagerService) private readonly _dependencyManagerService: DependencyManagerService ) { super(); } diff --git a/packages/engine-formula/src/engine/interpreter/interpreter.ts b/packages/engine-formula/src/engine/interpreter/interpreter.ts index 8497524d284..892e86b1f68 100644 --- a/packages/engine-formula/src/engine/interpreter/interpreter.ts +++ b/packages/engine-formula/src/engine/interpreter/interpreter.ts @@ -21,16 +21,16 @@ import type { ReferenceNode } from '../ast-node/reference-node'; import type { FunctionVariantType } from '../reference-object/base-reference-object'; import type { IExecuteAstNodeData } from '../utils/ast-node-tool'; import type { PreCalculateNodeType } from '../utils/node-type'; -import { Disposable } from '@univerjs/core'; +import { Disposable, Inject } from '@univerjs/core'; import { AstNodePromiseType } from '../../basics/common'; import { ErrorType } from '../../basics/error-type'; import { DEFAULT_TOKEN_LAMBDA_FUNCTION_NAME } from '../../basics/token-type'; -import { IFormulaRuntimeService } from '../../services/runtime.service'; +import { FormulaRuntimeService } from '../../services/runtime.service'; import { NodeType } from '../ast-node/node-type'; import { ErrorValueObject } from '../value-object/base-value-object'; export class Interpreter extends Disposable { - constructor(@IFormulaRuntimeService private readonly _runtimeService: IFormulaRuntimeService) { + constructor(@Inject(FormulaRuntimeService) private readonly _runtimeService: FormulaRuntimeService) { super(); } diff --git a/packages/engine-formula/src/engine/utils/prefixHandler.ts b/packages/engine-formula/src/engine/utils/prefixHandler.ts index 6857ebd68f6..ebf2cd8d275 100644 --- a/packages/engine-formula/src/engine/utils/prefixHandler.ts +++ b/packages/engine-formula/src/engine/utils/prefixHandler.ts @@ -15,7 +15,7 @@ */ import type { Injector, Nullable } from '@univerjs/core'; -import type { IFunctionService } from '../../services/function.service'; +import type { FunctionService } from '../../services/function.service'; import { prefixToken } from '../../basics/token'; import { FUNCTION_NAMES_META } from '../../functions/meta/function-names'; import { PrefixNode } from '../ast-node/prefix-node'; @@ -23,7 +23,7 @@ import { PrefixNode } from '../ast-node/prefix-node'; const minusRegExp = new RegExp(prefixToken.MINUS, 'g'); const atRegExp = new RegExp(prefixToken.AT, 'g'); -export function prefixHandler(tokenTrimParam: string, functionService: IFunctionService, injector: Injector) { +export function prefixHandler(tokenTrimParam: string, functionService: FunctionService, injector: Injector) { let minusPrefixNode: Nullable; let atPrefixNode: Nullable; let tokenTrim = tokenTrimParam; diff --git a/packages/engine-formula/src/functions/__tests__/create-function-test-bed.ts b/packages/engine-formula/src/functions/__tests__/create-function-test-bed.ts index db94152e21c..4b26c975f97 100644 --- a/packages/engine-formula/src/functions/__tests__/create-function-test-bed.ts +++ b/packages/engine-formula/src/functions/__tests__/create-function-test-bed.ts @@ -17,6 +17,11 @@ /* eslint-disable max-lines-per-function */ import type { Dependency, IWorkbookData, Workbook } from '@univerjs/core'; +import type { ISheetData } from '../../basics/common'; +import type { BaseReferenceObject, FunctionVariantType } from '../../engine/reference-object/base-reference-object'; +import type { ArrayValueObject } from '../../engine/value-object/array-value-object'; +import type { BaseValueObject, ErrorValueObject } from '../../engine/value-object/base-value-object'; +import type { FormulaDataModel } from '../../models/formula-data.model'; import { CellValueType, ILogService, @@ -30,8 +35,6 @@ import { Univer, UniverInstanceType, } from '@univerjs/core'; - -import type { ISheetData } from '../../basics/common'; import { Lexer } from '../../engine/analysis/lexer'; import { LexerTreeBuilder } from '../../engine/analysis/lexer-tree-builder'; import { AstTreeBuilder } from '../../engine/analysis/parser'; @@ -47,18 +50,13 @@ import { UnionNodeFactory } from '../../engine/ast-node/union-node'; import { ValueNodeFactory } from '../../engine/ast-node/value-node'; import { FormulaDependencyGenerator } from '../../engine/dependency/formula-dependency'; import { Interpreter } from '../../engine/interpreter/interpreter'; -import type { FormulaDataModel } from '../../models/formula-data.model'; -import { CalculateFormulaService } from '../../services/calculate-formula.service'; -import { FormulaCurrentConfigService, IFormulaCurrentConfigService } from '../../services/current-data.service'; -import { DefinedNamesService, IDefinedNamesService } from '../../services/defined-names.service'; -import { FunctionService, IFunctionService } from '../../services/function.service'; -import { IOtherFormulaManagerService, OtherFormulaManagerService } from '../../services/other-formula-manager.service'; -import { FormulaRuntimeService, IFormulaRuntimeService } from '../../services/runtime.service'; -import { ISuperTableService, SuperTableService } from '../../services/super-table.service'; -import type { BaseValueObject, ErrorValueObject } from '../../engine/value-object/base-value-object'; -import type { BaseReferenceObject, FunctionVariantType } from '../../engine/reference-object/base-reference-object'; -import type { ArrayValueObject } from '../../engine/value-object/array-value-object'; import { stripErrorMargin } from '../../engine/utils/math-kit'; +import { CalculateFormulaService } from '../../services/calculate-formula.service'; +import { FormulaCurrentConfigService } from '../../services/current-data.service'; +import { DefinedNamesService } from '../../services/defined-names.service'; +import { FunctionService } from '../../services/function.service'; +import { OtherFormulaManagerService } from '../../services/other-formula-manager.service'; +import { FormulaRuntimeService } from '../../services/runtime.service'; const getTestWorkbookData = (): IWorkbookData => { return { @@ -177,12 +175,11 @@ export function createFunctionTestBed(workbookData?: IWorkbookData, dependencies injector.add([Lexer]); injector.add([LexerTreeBuilder]); - injector.add([IFormulaCurrentConfigService, { useClass: FormulaCurrentConfigService }]); - injector.add([IFormulaRuntimeService, { useClass: FormulaRuntimeService }]); - injector.add([IFunctionService, { useClass: FunctionService }]); - injector.add([IOtherFormulaManagerService, { useClass: OtherFormulaManagerService }]); - injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]); - injector.add([ISuperTableService, { useClass: SuperTableService }]); + injector.add([FormulaCurrentConfigService]); + injector.add([FormulaRuntimeService]); + injector.add([FunctionService]); + injector.add([OtherFormulaManagerService]); + injector.add([DefinedNamesService]); injector.add([FormulaDependencyGenerator]); injector.add([Interpreter]); diff --git a/packages/engine-formula/src/functions/__tests__/nested-functions.spec.ts b/packages/engine-formula/src/functions/__tests__/nested-functions.spec.ts index a7e1fcc6383..f0e7ae0c9b8 100644 --- a/packages/engine-formula/src/functions/__tests__/nested-functions.spec.ts +++ b/packages/engine-formula/src/functions/__tests__/nested-functions.spec.ts @@ -25,9 +25,9 @@ import { Lexer } from '../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../engine/analysis/parser'; import { Interpreter } from '../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../services/current-data.service'; -import { IFunctionService } from '../../services/function.service'; -import { IFormulaRuntimeService } from '../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../services/current-data.service'; +import { FunctionService } from '../../services/function.service'; +import { FormulaRuntimeService } from '../../services/runtime.service'; import { Day } from '../date/day'; import { Edate } from '../date/edate'; import { FUNCTION_NAMES_DATE } from '../date/function-names'; @@ -271,11 +271,11 @@ describe('Test nested functions', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/compatibility/rank/__tests__/index.spec.ts b/packages/engine-formula/src/functions/compatibility/rank/__tests__/index.spec.ts index d60f63053ff..be49a12d480 100644 --- a/packages/engine-formula/src/functions/compatibility/rank/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/compatibility/rank/__tests__/index.spec.ts @@ -25,9 +25,9 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed, getObjectValue } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_COMPATIBILITY } from '../../function-names'; import { Rank } from '../index'; @@ -96,11 +96,11 @@ describe('Test rank function', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/information/cell/__tests__/index.spec.ts b/packages/engine-formula/src/functions/information/cell/__tests__/index.spec.ts index 4ade2ba6f1d..058c58d624d 100644 --- a/packages/engine-formula/src/functions/information/cell/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/information/cell/__tests__/index.spec.ts @@ -27,9 +27,9 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_INFORMATION } from '../../function-names'; import { Cell } from '../index'; @@ -158,11 +158,11 @@ describe('Test cell function', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/information/isformula/__tests__/index.spec.ts b/packages/engine-formula/src/functions/information/isformula/__tests__/index.spec.ts index 658083714e4..703b6a06559 100644 --- a/packages/engine-formula/src/functions/information/isformula/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/information/isformula/__tests__/index.spec.ts @@ -27,9 +27,9 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_INFORMATION } from '../../function-names'; import { Isformula } from '../index'; @@ -96,11 +96,11 @@ describe('Test isformula function', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/information/isref/__tests__/index.spec.ts b/packages/engine-formula/src/functions/information/isref/__tests__/index.spec.ts index 29309526039..4b73f2ca516 100644 --- a/packages/engine-formula/src/functions/information/isref/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/information/isref/__tests__/index.spec.ts @@ -26,9 +26,9 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_INFORMATION } from '../../function-names'; import { Isref } from '../index'; @@ -156,11 +156,11 @@ describe('Test isref function', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/logical/bycol/__test__/index.spec.ts b/packages/engine-formula/src/functions/logical/bycol/__test__/index.spec.ts index fe50b8c46ed..ba3156e74dd 100644 --- a/packages/engine-formula/src/functions/logical/bycol/__test__/index.spec.ts +++ b/packages/engine-formula/src/functions/logical/bycol/__test__/index.spec.ts @@ -24,7 +24,7 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFunctionService } from '../../../../services/function.service'; +import { FunctionService } from '../../../../services/function.service'; import { createFunctionTestBed, getObjectValue } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_META } from '../../../meta/function-names'; import { Multiply } from '../../../meta/multiply'; @@ -48,7 +48,7 @@ describe('Test bycol', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); functionService.registerExecutors( new Bycol(FUNCTION_NAMES_LOGICAL.BYCOL), diff --git a/packages/engine-formula/src/functions/logical/byrow/__test__/index.spec.ts b/packages/engine-formula/src/functions/logical/byrow/__test__/index.spec.ts index 6f67ef9e1fb..88fbe9f5847 100644 --- a/packages/engine-formula/src/functions/logical/byrow/__test__/index.spec.ts +++ b/packages/engine-formula/src/functions/logical/byrow/__test__/index.spec.ts @@ -24,7 +24,7 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFunctionService } from '../../../../services/function.service'; +import { FunctionService } from '../../../../services/function.service'; import { createFunctionTestBed, getObjectValue } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_META } from '../../../meta/function-names'; import { Multiply } from '../../../meta/multiply'; @@ -48,7 +48,7 @@ describe('Test byrow', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); functionService.registerExecutors( new Byrow(FUNCTION_NAMES_LOGICAL.BYROW), diff --git a/packages/engine-formula/src/functions/logical/makearray/__test__/index.spec.ts b/packages/engine-formula/src/functions/logical/makearray/__test__/index.spec.ts index 9c62b862ea7..c3bf479953d 100644 --- a/packages/engine-formula/src/functions/logical/makearray/__test__/index.spec.ts +++ b/packages/engine-formula/src/functions/logical/makearray/__test__/index.spec.ts @@ -25,7 +25,7 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFunctionService } from '../../../../services/function.service'; +import { FunctionService } from '../../../../services/function.service'; import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_META } from '../../../meta/function-names'; import { Multiply } from '../../../meta/multiply'; @@ -49,7 +49,7 @@ describe('Test makearray', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); functionService.registerExecutors( new Makearray(FUNCTION_NAMES_LOGICAL.MAKEARRAY), diff --git a/packages/engine-formula/src/functions/logical/map/__test__/index.spec.ts b/packages/engine-formula/src/functions/logical/map/__test__/index.spec.ts index 2a3b9aaf66d..afa4092ab35 100644 --- a/packages/engine-formula/src/functions/logical/map/__test__/index.spec.ts +++ b/packages/engine-formula/src/functions/logical/map/__test__/index.spec.ts @@ -24,7 +24,7 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFunctionService } from '../../../../services/function.service'; +import { FunctionService } from '../../../../services/function.service'; import { createFunctionTestBed, getObjectValue } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_META } from '../../../meta/function-names'; import { Multiply } from '../../../meta/multiply'; @@ -48,7 +48,7 @@ describe('Test map', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); functionService.registerExecutors( new Map(FUNCTION_NAMES_LOGICAL.MAP), diff --git a/packages/engine-formula/src/functions/logical/reduce/__test__/index.spec.ts b/packages/engine-formula/src/functions/logical/reduce/__test__/index.spec.ts index eeedeca1c78..d1f75126e57 100644 --- a/packages/engine-formula/src/functions/logical/reduce/__test__/index.spec.ts +++ b/packages/engine-formula/src/functions/logical/reduce/__test__/index.spec.ts @@ -24,7 +24,7 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFunctionService } from '../../../../services/function.service'; +import { FunctionService } from '../../../../services/function.service'; import { createFunctionTestBed, getObjectValue } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_META } from '../../../meta/function-names'; import { Multiply } from '../../../meta/multiply'; @@ -48,7 +48,7 @@ describe('Test reduce', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); functionService.registerExecutors( new Reduce(FUNCTION_NAMES_LOGICAL.REDUCE), diff --git a/packages/engine-formula/src/functions/logical/scan/__test__/index.spec.ts b/packages/engine-formula/src/functions/logical/scan/__test__/index.spec.ts index aedfc866e80..39116a864c4 100644 --- a/packages/engine-formula/src/functions/logical/scan/__test__/index.spec.ts +++ b/packages/engine-formula/src/functions/logical/scan/__test__/index.spec.ts @@ -24,7 +24,7 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFunctionService } from '../../../../services/function.service'; +import { FunctionService } from '../../../../services/function.service'; import { createFunctionTestBed, getObjectValue } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_META } from '../../../meta/function-names'; import { Multiply } from '../../../meta/multiply'; @@ -48,7 +48,7 @@ describe('Test scan', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); functionService.registerExecutors( new Scan(FUNCTION_NAMES_LOGICAL.SCAN), diff --git a/packages/engine-formula/src/functions/lookup/column/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/column/__tests__/index.spec.ts index 44cdc6def59..28d9ea02e94 100644 --- a/packages/engine-formula/src/functions/lookup/column/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/lookup/column/__tests__/index.spec.ts @@ -26,9 +26,9 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_LOOKUP } from '../../function-names'; import { Column } from '../index'; @@ -48,11 +48,11 @@ describe('Test column', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/lookup/columns/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/columns/__tests__/index.spec.ts index 0c4e0da2fea..e7c01bbeaca 100644 --- a/packages/engine-formula/src/functions/lookup/columns/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/lookup/columns/__tests__/index.spec.ts @@ -25,9 +25,9 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_LOOKUP } from '../../function-names'; import { Columns } from '../index'; @@ -47,11 +47,11 @@ describe('Test columns', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/lookup/index/__test__/index.spec.ts b/packages/engine-formula/src/functions/lookup/index/__test__/index.spec.ts index fe2f6675d72..ffb8b1d3cd6 100644 --- a/packages/engine-formula/src/functions/lookup/index/__test__/index.spec.ts +++ b/packages/engine-formula/src/functions/lookup/index/__test__/index.spec.ts @@ -25,9 +25,9 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed, getObjectValue } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_LOOKUP } from '../../function-names'; import { Index } from '../index'; @@ -155,11 +155,11 @@ describe('Test index', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/lookup/indirect/__test__/index.spec.ts b/packages/engine-formula/src/functions/lookup/indirect/__test__/index.spec.ts index 653f52f0f6a..e13f933ab6e 100644 --- a/packages/engine-formula/src/functions/lookup/indirect/__test__/index.spec.ts +++ b/packages/engine-formula/src/functions/lookup/indirect/__test__/index.spec.ts @@ -26,9 +26,9 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_META } from '../../../meta/function-names'; import { Multiply } from '../../../meta/multiply'; @@ -51,11 +51,11 @@ describe('Test indirect', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/lookup/offset/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/offset/__tests__/index.spec.ts index f3f99b92bee..f6383b3cee0 100644 --- a/packages/engine-formula/src/functions/lookup/offset/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/lookup/offset/__tests__/index.spec.ts @@ -25,9 +25,9 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed, getObjectValue } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_LOOKUP } from '../../function-names'; import { Offset } from '../index'; @@ -150,11 +150,11 @@ describe('Test offset', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/lookup/row/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/row/__tests__/index.spec.ts index e71fe924a7b..23adf483aee 100644 --- a/packages/engine-formula/src/functions/lookup/row/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/lookup/row/__tests__/index.spec.ts @@ -26,9 +26,9 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_LOOKUP } from '../../function-names'; import { Row } from '../index'; @@ -48,11 +48,11 @@ describe('Test row', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/lookup/rows/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/rows/__tests__/index.spec.ts index da0986705b2..3fdf6e78736 100644 --- a/packages/engine-formula/src/functions/lookup/rows/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/lookup/rows/__tests__/index.spec.ts @@ -25,9 +25,9 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_LOOKUP } from '../../function-names'; import { Rows } from '../index'; @@ -47,11 +47,11 @@ describe('Test rows', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/math/subtotal/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/subtotal/__tests__/index.spec.ts index db9370347bc..c346f63c099 100644 --- a/packages/engine-formula/src/functions/math/subtotal/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/math/subtotal/__tests__/index.spec.ts @@ -28,9 +28,9 @@ import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; import { stripErrorMargin } from '../../../../engine/utils/math-kit'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_MATH } from '../../function-names'; import { Subtotal } from '../index'; @@ -148,11 +148,11 @@ describe('Test subtotal', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/statistical/averageif/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/averageif/__tests__/index.spec.ts index 5e2a96d5d61..918a2901c98 100644 --- a/packages/engine-formula/src/functions/statistical/averageif/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/statistical/averageif/__tests__/index.spec.ts @@ -27,9 +27,9 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_STATISTICAL } from '../../function-names'; import { Averageif } from '../index'; @@ -167,11 +167,11 @@ describe('Test isref function', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/statistical/rank-avg/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/rank-avg/__tests__/index.spec.ts index 35454d6a93f..0e3469996e6 100644 --- a/packages/engine-formula/src/functions/statistical/rank-avg/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/statistical/rank-avg/__tests__/index.spec.ts @@ -25,9 +25,9 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed, getObjectValue } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_STATISTICAL } from '../../function-names'; import { RankAvg } from '../index'; @@ -104,11 +104,11 @@ describe('Test rank function', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/functions/statistical/rank-eq/__tests__/index.spec.ts b/packages/engine-formula/src/functions/statistical/rank-eq/__tests__/index.spec.ts index ab5d20726a7..f57e639da17 100644 --- a/packages/engine-formula/src/functions/statistical/rank-eq/__tests__/index.spec.ts +++ b/packages/engine-formula/src/functions/statistical/rank-eq/__tests__/index.spec.ts @@ -25,9 +25,9 @@ import { Lexer } from '../../../../engine/analysis/lexer'; import { AstTreeBuilder } from '../../../../engine/analysis/parser'; import { Interpreter } from '../../../../engine/interpreter/interpreter'; import { generateExecuteAstNodeData } from '../../../../engine/utils/ast-node-tool'; -import { IFormulaCurrentConfigService } from '../../../../services/current-data.service'; -import { IFunctionService } from '../../../../services/function.service'; -import { IFormulaRuntimeService } from '../../../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../../../services/current-data.service'; +import { FunctionService } from '../../../../services/function.service'; +import { FormulaRuntimeService } from '../../../../services/runtime.service'; import { createFunctionTestBed, getObjectValue } from '../../../__tests__/create-function-test-bed'; import { FUNCTION_NAMES_STATISTICAL } from '../../function-names'; import { RankEq } from '../index'; @@ -104,11 +104,11 @@ describe('Test rank function', () => { astTreeBuilder = get(AstTreeBuilder); interpreter = get(Interpreter); - const functionService = get(IFunctionService); + const functionService = get(FunctionService); - const formulaCurrentConfigService = get(IFormulaCurrentConfigService); + const formulaCurrentConfigService = get(FormulaCurrentConfigService); - const formulaRuntimeService = get(IFormulaRuntimeService); + const formulaRuntimeService = get(FormulaRuntimeService); formulaCurrentConfigService.load({ formulaData: {}, diff --git a/packages/engine-formula/src/index.ts b/packages/engine-formula/src/index.ts index c1279af7ab4..1618b0f37ae 100644 --- a/packages/engine-formula/src/index.ts +++ b/packages/engine-formula/src/index.ts @@ -118,10 +118,8 @@ export { functionEngineering } from './functions/engineering/function-map'; export { FUNCTION_NAMES_ENGINEERING } from './functions/engineering/function-names'; export { functionFinancial } from './functions/financial/function-map'; export { FUNCTION_NAMES_FINANCIAL } from './functions/financial/function-names'; - export { functionInformation } from './functions/information/function-map'; export { FUNCTION_NAMES_INFORMATION } from './functions/information/function-names'; - export { functionLogical } from './functions/logical/function-map'; export { FUNCTION_NAMES_LOGICAL } from './functions/logical/function-names'; export { functionLookup } from './functions/lookup/function-map'; @@ -141,19 +139,15 @@ export { FormulaDataModel } from './models/formula-data.model'; export { initSheetFormulaData } from './models/formula-data.model'; export type { IRangeChange } from './models/formula-data.model'; export { UniverFormulaEnginePlugin } from './plugin'; -export { IActiveDirtyManagerService } from './services/active-dirty-manager.service'; export { ActiveDirtyManagerService } from './services/active-dirty-manager.service'; export { CalculateFormulaService } from './services/calculate-formula.service'; -export { FormulaCurrentConfigService, IFormulaCurrentConfigService, type IFormulaDirtyData } from './services/current-data.service'; -export { DefinedNamesService, type IDefinedNameMapItem, IDefinedNamesService, type IDefinedNamesServiceParam } from './services/defined-names.service'; -export { IDependencyManagerService } from './services/dependency-manager.service'; +export { FormulaCurrentConfigService, type IFormulaDirtyData } from './services/current-data.service'; +export { DefinedNamesService, type DefinedNamesServiceParam, type IDefinedNameMapItem } from './services/defined-names.service'; export { DependencyManagerService } from './services/dependency-manager.service'; -export { FeatureCalculationManagerService, IFeatureCalculationManagerService } from './services/feature-calculation-manager.service'; +export { FeatureCalculationManagerService } from './services/feature-calculation-manager.service'; export { FunctionService } from './services/function.service'; -export { IFunctionService } from './services/function.service'; -export { IOtherFormulaManagerService, OtherFormulaManagerService } from './services/other-formula-manager.service'; +export { OtherFormulaManagerService } from './services/other-formula-manager.service'; export { FormulaExecuteStageType, type IExecutionInProgressParams } from './services/runtime.service'; export { FormulaExecutedStateType, type IAllRuntimeData } from './services/runtime.service'; -export { FormulaRuntimeService, IFormulaRuntimeService } from './services/runtime.service'; -export { ISuperTableService } from './services/super-table.service'; +export { FormulaRuntimeService } from './services/runtime.service'; export { SuperTableService } from './services/super-table.service'; diff --git a/packages/engine-formula/src/models/__tests__/create-command-test-bed.ts b/packages/engine-formula/src/models/__tests__/create-command-test-bed.ts index d85915e4be1..2454ff5362d 100644 --- a/packages/engine-formula/src/models/__tests__/create-command-test-bed.ts +++ b/packages/engine-formula/src/models/__tests__/create-command-test-bed.ts @@ -17,13 +17,13 @@ import type { Dependency, IWorkbookData } from '@univerjs/core'; import { ILogService, Inject, Injector, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core'; +import { Lexer } from '../../engine/analysis/lexer'; import { LexerTreeBuilder } from '../../engine/analysis/lexer-tree-builder'; import { CalculateFormulaService } from '../../services/calculate-formula.service'; -import { FormulaCurrentConfigService, IFormulaCurrentConfigService } from '../../services/current-data.service'; -import { DefinedNamesService, IDefinedNamesService } from '../../services/defined-names.service'; -import { FormulaRuntimeService, IFormulaRuntimeService } from '../../services/runtime.service'; +import { FormulaCurrentConfigService } from '../../services/current-data.service'; +import { DefinedNamesService } from '../../services/defined-names.service'; +import { FormulaRuntimeService } from '../../services/runtime.service'; import { FormulaDataModel } from '../formula-data.model'; -import { Lexer } from '../../engine/analysis/lexer'; const TEST_WORKBOOK_DATA: IWorkbookData = { id: 'test', @@ -73,9 +73,9 @@ export function createCommandTestBed(workbookData?: IWorkbookData, dependencies? injector.add([FormulaDataModel]); injector.add([LexerTreeBuilder]); injector.add([Lexer]); - injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]); - injector.add([IFormulaRuntimeService, { useClass: FormulaRuntimeService }]); - injector.add([IFormulaCurrentConfigService, { useClass: FormulaCurrentConfigService }]); + injector.add([DefinedNamesService]); + injector.add([FormulaRuntimeService]); + injector.add([FormulaCurrentConfigService]); dependencies?.forEach((d) => injector.add(d)); } diff --git a/packages/engine-formula/src/models/formula-data.model.ts b/packages/engine-formula/src/models/formula-data.model.ts index 9f0ca74f9a7..e7b1c2c7d72 100644 --- a/packages/engine-formula/src/models/formula-data.model.ts +++ b/packages/engine-formula/src/models/formula-data.model.ts @@ -37,6 +37,9 @@ export interface IRangeChange { newCell: IRange | null; } +/** + * This model is for caching formula data and array formula data. + */ export class FormulaDataModel extends Disposable { private _formulaData: IFormulaData = {}; diff --git a/packages/engine-formula/src/plugin.ts b/packages/engine-formula/src/plugin.ts index 3a8dffd91ef..a0740de8701 100644 --- a/packages/engine-formula/src/plugin.ts +++ b/packages/engine-formula/src/plugin.ts @@ -16,7 +16,7 @@ import type { Dependency } from '@univerjs/core'; import type { IUniverEngineFormulaConfig } from './controller/config.schema'; -import { IConfigService, Inject, Injector, Plugin } from '@univerjs/core'; +import { IConfigService, Inject, Injector, Plugin, registerDependencies, touchDependencies } from '@univerjs/core'; import { CalculateController } from './controller/calculate.controller'; import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controller/config.schema'; import { FormulaController } from './controller/formula.controller'; @@ -41,19 +41,15 @@ import { ValueNodeFactory } from './engine/ast-node/value-node'; import { FormulaDependencyGenerator } from './engine/dependency/formula-dependency'; import { Interpreter } from './engine/interpreter/interpreter'; import { FormulaDataModel } from './models/formula-data.model'; -import { ActiveDirtyManagerService, IActiveDirtyManagerService } from './services/active-dirty-manager.service'; +import { ActiveDirtyManagerService } from './services/active-dirty-manager.service'; import { CalculateFormulaService } from './services/calculate-formula.service'; -import { FormulaCurrentConfigService, IFormulaCurrentConfigService } from './services/current-data.service'; -import { DefinedNamesService, IDefinedNamesService } from './services/defined-names.service'; -import { DependencyManagerService, IDependencyManagerService } from './services/dependency-manager.service'; -import { - FeatureCalculationManagerService, - IFeatureCalculationManagerService, -} from './services/feature-calculation-manager.service'; -import { FunctionService, IFunctionService } from './services/function.service'; -import { IOtherFormulaManagerService, OtherFormulaManagerService } from './services/other-formula-manager.service'; -import { FormulaRuntimeService, IFormulaRuntimeService } from './services/runtime.service'; -import { ISuperTableService, SuperTableService } from './services/super-table.service'; +import { FormulaCurrentConfigService } from './services/current-data.service'; +import { DefinedNamesService } from './services/defined-names.service'; +import { DependencyManagerService } from './services/dependency-manager.service'; +import { FeatureCalculationManagerService } from './services/feature-calculation-manager.service'; +import { FunctionService } from './services/function.service'; +import { OtherFormulaManagerService } from './services/other-formula-manager.service'; +import { FormulaRuntimeService } from './services/runtime.service'; const PLUGIN_NAME = 'UNIVER_ENGINE_FORMULA_PLUGIN'; @@ -77,63 +73,54 @@ export class UniverFormulaEnginePlugin extends Plugin { } override onReady(): void { - this._injector.get(FormulaController); - this._injector.get(SetDefinedNameController); - this._injector.get(SetSuperTableController); - - if (!this._config?.notExecuteFormula) { - this._injector.get(SetOtherFormulaController); - this._injector.get(SetFeatureCalculationController); - this._injector.get(SetDependencyController); - this._injector.get(CalculateController); - } + touchDependencies(this._injector, [ + [FormulaController], + [SetDefinedNameController], + [SetSuperTableController], + [SetOtherFormulaController], + [SetFeatureCalculationController], + [SetDependencyController], + [CalculateController], + ]); } override onRendered(): void { - if (!this._config?.notExecuteFormula) { - this._injector.get(CalculateFormulaService); - this._injector.get(FormulaDependencyGenerator); - } + touchDependencies(this._injector, [ + [CalculateFormulaService], + [FormulaDependencyGenerator], + ]); } private _initialize() { - // worker and main thread const dependencies: Dependency[] = [ // Services - [IFunctionService, { useClass: FunctionService }], - [IDefinedNamesService, { useClass: DefinedNamesService }], - [IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }], - [ISuperTableService, { useClass: SuperTableService }], - + [FunctionService], + [DefinedNamesService], + [ActiveDirtyManagerService], // Models [FormulaDataModel], - // Engine [LexerTreeBuilder], - - //Controllers [FormulaController], [SetDefinedNameController], [SetSuperTableController], ]; if (!this._config?.notExecuteFormula) { - // only worker + // Dependencies for computing. dependencies.push( // Services [CalculateFormulaService], - [IOtherFormulaManagerService, { useClass: OtherFormulaManagerService }], - [IFormulaRuntimeService, { useClass: FormulaRuntimeService }], - [IFormulaCurrentConfigService, { useClass: FormulaCurrentConfigService }], - [IDependencyManagerService, { useClass: DependencyManagerService }], - [IFeatureCalculationManagerService, { useClass: FeatureCalculationManagerService }], - + [OtherFormulaManagerService], + [FormulaRuntimeService], + [FormulaCurrentConfigService], + [DependencyManagerService], + [FeatureCalculationManagerService], //Controller [CalculateController], [SetOtherFormulaController], [SetDependencyController], [SetFeatureCalculationController], - // Calculation engine [FormulaDependencyGenerator], [Interpreter], @@ -153,6 +140,6 @@ export class UniverFormulaEnginePlugin extends Plugin { ); } - dependencies.forEach((dependency) => this._injector.add(dependency)); + registerDependencies(this._injector, dependencies); } } 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 7e6245a3f77..596381dcb47 100644 --- a/packages/engine-formula/src/services/active-dirty-manager.service.ts +++ b/packages/engine-formula/src/services/active-dirty-manager.service.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import type { ICommandInfo, IUnitRange, Nullable } from '@univerjs/core'; +import type { ICommandInfo, IUnitRange } from '@univerjs/core'; import type { IDirtyUnitFeatureMap, IDirtyUnitOtherFormulaMap, IDirtyUnitSheetDefinedNameMap, IDirtyUnitSheetNameMap } from '../basics/common'; -import { createIdentifier, Disposable } from '@univerjs/core'; +import { Disposable } from '@univerjs/core'; export interface IDirtyConversionManagerParams { commandId: string; @@ -30,52 +30,23 @@ export interface IDirtyConversionManagerParams { }; } -export interface IActiveDirtyManagerService { - dispose(): void; - - remove(commandId: string): void; - - get(commandId: string): Nullable; - - has(featureId: string): boolean; - - register(featureId: string, dirtyConversion: IDirtyConversionManagerParams): void; - - getDirtyConversionMap(): Map; -} - /** - * Actively mark as dirty, calculate the dirty area based on the command, - * and plugins can register the ref range they affect into the formula engine. + * This service expose a API for plugins to tell the formula engine what areas could be dirty when + * a mutation is triggered. */ -export class ActiveDirtyManagerService extends Disposable implements IActiveDirtyManagerService { +export class ActiveDirtyManagerService extends Disposable { private _dirtyConversionMap: Map = new Map(); override dispose(): void { + super.dispose(); this._dirtyConversionMap.clear(); } - remove(commandId: string) { - this._dirtyConversionMap.delete(commandId); - } - get(commandId: string) { return this._dirtyConversionMap.get(commandId); } - has(commandId: string) { - return this._dirtyConversionMap.has(commandId); - } - register(commandId: string, dirtyConversion: IDirtyConversionManagerParams) { this._dirtyConversionMap.set(commandId, dirtyConversion); } - - getDirtyConversionMap() { - return this._dirtyConversionMap; - } } - -export const IActiveDirtyManagerService = createIdentifier( - 'univer.formula.active-dirty-manager.service' -); diff --git a/packages/engine-formula/src/services/calculate-formula.service.ts b/packages/engine-formula/src/services/calculate-formula.service.ts index 23ecec92d7a..ffba85524cd 100644 --- a/packages/engine-formula/src/services/calculate-formula.service.ts +++ b/packages/engine-formula/src/services/calculate-formula.service.ts @@ -23,7 +23,6 @@ import type { IUnitExcludedCell, } from '../basics/common'; import type { LexerNode } from '../engine/analysis/lexer-node'; - import type { IAllRuntimeData, IExecutionInProgressParams } from './runtime.service'; import { Disposable, @@ -41,8 +40,8 @@ import { ErrorNode } from '../engine/ast-node/base-ast-node'; import { FormulaDependencyGenerator } from '../engine/dependency/formula-dependency'; import { Interpreter } from '../engine/interpreter/interpreter'; import { FORMULA_REF_TO_ARRAY_CACHE, type FunctionVariantType } from '../engine/reference-object/base-reference-object'; -import { IFormulaCurrentConfigService } from './current-data.service'; -import { FormulaExecuteStageType, IFormulaRuntimeService } from './runtime.service'; +import { FormulaCurrentConfigService } from './current-data.service'; +import { FormulaExecuteStageType, FormulaRuntimeService } from './runtime.service'; export const DEFAULT_CYCLE_REFERENCE_COUNT = 1; @@ -50,24 +49,24 @@ export const CYCLE_REFERENCE_COUNT = 'cycleReferenceCount'; export const EVERY_N_FUNCTION_EXECUTION_PAUSE = 100; +/** + * This service is for scheduling the calculation of formulas and reporting calculation progress. + */ export class CalculateFormulaService extends Disposable { private readonly _executionStartListener$ = new Subject(); - readonly executionStartListener$ = this._executionStartListener$.asObservable(); private readonly _executionCompleteListener$ = new Subject(); - readonly executionCompleteListener$ = this._executionCompleteListener$.asObservable(); private readonly _executionInProgressListener$ = new Subject(); - readonly executionInProgressListener$ = this._executionInProgressListener$.asObservable(); constructor( @IConfigService private readonly _configService: IConfigService, @Inject(Lexer) private readonly _lexer: Lexer, - @IFormulaCurrentConfigService private readonly _currentConfigService: IFormulaCurrentConfigService, - @IFormulaRuntimeService private readonly _runtimeService: IFormulaRuntimeService, + @Inject(FormulaCurrentConfigService) private readonly _currentConfigService: FormulaCurrentConfigService, + @Inject(FormulaRuntimeService) private readonly _runtimeService: FormulaRuntimeService, @Inject(FormulaDependencyGenerator) private readonly _formulaDependencyGenerator: FormulaDependencyGenerator, @Inject(Interpreter) private readonly _interpreter: Interpreter, @Inject(AstTreeBuilder) private readonly _astTreeBuilder: AstTreeBuilder diff --git a/packages/engine-formula/src/services/current-data.service.ts b/packages/engine-formula/src/services/current-data.service.ts index f8a7a03a2bb..a54ccead5a1 100644 --- a/packages/engine-formula/src/services/current-data.service.ts +++ b/packages/engine-formula/src/services/current-data.service.ts @@ -14,10 +14,7 @@ * limitations under the License. */ -import { createIdentifier, Disposable, Inject, IUniverInstanceService, LocaleService, ObjectMatrix, UniverInstanceType } from '@univerjs/core'; -import type { IUnitRange, LocaleType, Nullable, Workbook } from '@univerjs/core'; - -import { convertUnitDataToRuntime } from '../basics/runtime'; +import type { IUnitRange, Nullable, Workbook } from '@univerjs/core'; import type { IArrayFormulaRangeType, IDirtyUnitFeatureMap, @@ -34,6 +31,8 @@ import type { IUnitSheetNameMap, IUnitStylesData, } from '../basics/common'; +import { Disposable, Inject, IUniverInstanceService, LocaleService, ObjectMatrix, UniverInstanceType } from '@univerjs/core'; +import { convertUnitDataToRuntime } from '../basics/runtime'; export interface IFormulaDirtyData { forceCalculation: boolean; @@ -45,62 +44,7 @@ export interface IFormulaDirtyData { clearDependencyTreeCache: IDirtyUnitSheetNameMap; // unitId -> sheetId } -export interface IFormulaCurrentConfigService { - load(config: IFormulaDatasetConfig): void; - - getUnitData(): IUnitData; - - /** - * Get the unit styles data. - */ - getUnitStylesData(): IUnitStylesData; - - getFormulaData(): IFormulaData; - - getSheetNameMap(): IUnitSheetNameMap; - - isForceCalculate(): boolean; - - getDirtyRanges(): IUnitRange[]; - - getDirtyNameMap(): IDirtyUnitSheetNameMap; - - getDirtyDefinedNameMap(): IDirtyUnitSheetDefinedNameMap; - - getDirtyUnitFeatureMap(): IDirtyUnitFeatureMap; - - registerUnitData(unitData: IUnitData): void; - - registerFormulaData(formulaData: IFormulaData): void; - - registerSheetNameMap(sheetNameMap: IUnitSheetNameMap): void; - - getExcludedRange(): Nullable; - - loadDirtyRangesAndExcludedCell(dirtyRanges: IUnitRange[], excludedCell?: IUnitExcludedCell): void; - - getArrayFormulaCellData(): IRuntimeUnitDataType; - - getArrayFormulaRange(): IArrayFormulaRangeType; - - getSheetName(unitId: string, sheetId: string): string; - - getDirtyUnitOtherFormulaMap(): IDirtyUnitOtherFormulaMap; - - getExecuteUnitId(): Nullable; - getExecuteSubUnitId(): Nullable; - - setExecuteUnitId(unitId: string): void; - setExecuteSubUnitId(subUnitId: string): void; - - getDirtyData(): IFormulaDirtyData; - - getClearDependencyTreeCache(): IDirtyUnitSheetNameMap; - - getLocale(): LocaleType; -} - -export class FormulaCurrentConfigService extends Disposable implements IFormulaCurrentConfigService { +export class FormulaCurrentConfigService extends Disposable { private _unitData: IUnitData = {}; private _unitStylesData: IUnitStylesData = {}; @@ -471,7 +415,3 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaC }; } } - -export const IFormulaCurrentConfigService = createIdentifier( - 'univer.formula.current-data.service' -); diff --git a/packages/engine-formula/src/services/defined-names.service.ts b/packages/engine-formula/src/services/defined-names.service.ts index 3c0829c9ebf..ea12f90af06 100644 --- a/packages/engine-formula/src/services/defined-names.service.ts +++ b/packages/engine-formula/src/services/defined-names.service.ts @@ -14,13 +14,12 @@ * limitations under the License. */ -import type { IUnitRange, Nullable, Workbook, Worksheet } from '@univerjs/core'; -import type { Observable } from 'rxjs'; -import { createIdentifier, Disposable, IUniverInstanceService } from '@univerjs/core'; +import type { IUnitRange, Workbook } from '@univerjs/core'; +import { Disposable, IUniverInstanceService } from '@univerjs/core'; import { Subject } from 'rxjs'; import { handleRefStringInfo, serializeRange } from '../engine/utils/reference'; -export interface IDefinedNamesServiceParam { +export interface DefinedNamesServiceParam { id: string; name: string; formulaOrRefString: string; @@ -30,7 +29,7 @@ export interface IDefinedNamesServiceParam { } -export interface IDefinedNamesServiceFocusParam extends IDefinedNamesServiceParam { +export interface DefinedNamesServiceFocusParam extends DefinedNamesServiceParam { unitId: string; } @@ -39,45 +38,15 @@ export interface IDefinedNameMap { } export interface IDefinedNameMapItem { - [id: string]: IDefinedNamesServiceParam; + [id: string]: DefinedNamesServiceParam; } -export interface IDefinedNamesService { - registerDefinedName(unitId: string, param: IDefinedNamesServiceParam): void; +// DEBT@wzhudev: this service expose too much API that seems redundant. - registerDefinedNames(unitId: string, params: IDefinedNameMapItem): void; - - getDefinedNameMap(unitId: string): Nullable; - - getValueByName(unitId: string, name: string): Nullable; - - getValueById(unitId: string, id: string): Nullable; - - removeDefinedName(unitId: string, name: string): void; - - removeUnitDefinedName(unitId: string): void; - - hasDefinedName(unitId: string): boolean; - - setCurrentRange(range: IUnitRange): void; - - getCurrentRange(): IUnitRange; - - getCurrentRangeForString(): string; - - currentRange$: Observable; - - update$: Observable; - - focusRange$: Observable; - - focusRange(unitId: string, id: string): void; - - getWorksheetByRef(unitId: string, ref: string): Nullable; - -} - -export class DefinedNamesService extends Disposable implements IDefinedNamesService { +/** + * This service is for storing data for "Define Names" feature. + */ +export class DefinedNamesService extends Disposable { // 18.2.6 definedNames (Defined Names) private _definedNameMap: IDefinedNameMap = {}; @@ -96,7 +65,7 @@ export class DefinedNamesService extends Disposable implements IDefinedNamesServ private readonly _currentRange$ = new Subject(); readonly currentRange$ = this._currentRange$.asObservable(); - private readonly _focusRange$ = new Subject(); + private readonly _focusRange$ = new Subject(); readonly focusRange$ = this._focusRange$.asObservable(); constructor(@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService) { @@ -140,7 +109,7 @@ export class DefinedNamesService extends Disposable implements IDefinedNamesServ this._update(); } - registerDefinedName(unitId: string, param: IDefinedNamesServiceParam) { + registerDefinedName(unitId: string, param: DefinedNamesServiceParam) { const unitMap = this._definedNameMap[unitId]; if (unitMap == null) { @@ -191,5 +160,3 @@ export class DefinedNamesService extends Disposable implements IDefinedNamesServ this._update$.next(null); } } - -export const IDefinedNamesService = createIdentifier('univer.formula.defined-names.service'); diff --git a/packages/engine-formula/src/services/dependency-manager.service.ts b/packages/engine-formula/src/services/dependency-manager.service.ts index 329af685711..d9b55a3ec48 100644 --- a/packages/engine-formula/src/services/dependency-manager.service.ts +++ b/packages/engine-formula/src/services/dependency-manager.service.ts @@ -16,7 +16,7 @@ import type { IUnitRange, Nullable } from '@univerjs/core'; import type { FormulaDependencyTree } from '../engine/dependency/dependency-tree'; -import { createIdentifier, Disposable, ObjectMatrix, RTree } from '@univerjs/core'; +import { Disposable, ObjectMatrix, RTree } from '@univerjs/core'; export interface IOtherFormulaDependencyParam { [unitId: string]: Nullable<{ [sheetId: string]: { [formulaId: string]: Nullable } }>; @@ -30,63 +30,13 @@ export interface IFormulaDependencyParam { [unitId: string]: Nullable<{ [sheetId: string]: ObjectMatrix< string> }>; } -export interface IDependencyManagerService { - dispose(): void; - - getAllTree(): FormulaDependencyTree[]; - - buildDependencyTree(shouldBeBuildTrees: FormulaDependencyTree[], dependencyTrees?: FormulaDependencyTree[]): FormulaDependencyTree[]; - - clearDependencyForTree(shouldBeClearTree: Nullable): void; - - reset(): void; - - addOtherFormulaDependency(unitId: string, sheetId: string, formulaId: string, dependencyTree: FormulaDependencyTree): void; - - removeOtherFormulaDependency(unitId: string, sheetId: string, formulaId: string[]): void; - - getOtherFormulaDependency(unitId: string, sheetId: string, formulaId: string): Nullable; - - addFeatureFormulaDependency(unitId: string, sheetId: string, featureId: string, dependencyTree: FormulaDependencyTree): void; - - removeFeatureFormulaDependency(unitId: string, sheetId: string, featureIds: string[]): void; - - getFeatureFormulaDependency(unitId: string, sheetId: string, featureId: string): Nullable; - - addFormulaDependency(unitId: string, sheetId: string, row: number, column: number, dependencyTree: FormulaDependencyTree): void; - - removeFormulaDependency(unitId: string, sheetId: string, row: number, column: number): void; - - getFormulaDependency(unitId: string, sheetId: string, row: number, column: number): Nullable; - - removeFormulaDependencyByDefinedName(unitId: string, definedName: string): void; - - clearFormulaDependency(unitId: string, sheetId?: string): void; - - addDependencyRTreeCache(tree: FormulaDependencyTree): void; - - searchDependency(search: IUnitRange[]): Set; - - getLastTreeId(): number; - - clearDependencyAll(): void; - - clearOtherFormulaDependency(unitId: string, sheetId?: string): void; - clearFeatureFormulaDependency(unitId: string, sheetId?: string): void; - - openKdTree(): void; - closeKdTree(): void; - - getTreeById(treeId: string): Nullable; -} - /** * Passively marked as dirty, register the reference and execution actions of the feature plugin. * After execution, a dirty area and calculated data will be returned, * causing the formula to be marked dirty again, * thereby completing the calculation of the entire dependency tree. */ -export class DependencyManagerService extends Disposable implements IDependencyManagerService { +export class DependencyManagerService extends Disposable { private _otherFormulaData: IOtherFormulaDependencyParam = {}; private _featureFormulaData: IFeatureFormulaDependencyParam = {}; @@ -560,7 +510,3 @@ export class DependencyManagerService extends Disposable implements IDependencyM this._allTreeMap.delete(treeId || ''); } } - -export const IDependencyManagerService = createIdentifier( - 'univer.formula.dependency-manager.service' -); diff --git a/packages/engine-formula/src/services/feature-calculation-manager.service.ts b/packages/engine-formula/src/services/feature-calculation-manager.service.ts index 36ac9cbb2d3..e1643b166a2 100644 --- a/packages/engine-formula/src/services/feature-calculation-manager.service.ts +++ b/packages/engine-formula/src/services/feature-calculation-manager.service.ts @@ -14,15 +14,14 @@ * limitations under the License. */ -import type { IUnitRange, Nullable } from '@univerjs/core'; -import { createIdentifier, Disposable } from '@univerjs/core'; +import type { IUnitRange } from '@univerjs/core'; -import type { Observable } from 'rxjs'; -import { Subject } from 'rxjs'; import type { IFeatureDirtyRangeType, IRuntimeUnitDataType } from '../basics/common'; import type { IRemoveFeatureCalculationMutationParam } from '../commands/mutations/set-feature-calculation.mutation'; -import type { IAllRuntimeData } from './runtime.service'; import type { IFormulaDirtyData } from './current-data.service'; +import type { IAllRuntimeData } from './runtime.service'; +import { Disposable } from '@univerjs/core'; +import { Subject } from 'rxjs'; export interface IFeatureCalculationManagerParam { unitId: string; @@ -34,29 +33,13 @@ export interface IFeatureCalculationManagerParam { }; } -export interface IFeatureCalculationManagerService { - dispose(): void; - - remove(unitId: string, subUnitId: string, featureIds: string[]): void; - - get(unitId: string, subUnitId: string, featureId: string): Nullable; - - has(unitId: string, subUnitId: string, featureId: string): boolean; - - register(unitId: string, subUnitId: string, featureId: string, referenceExecutor: IFeatureCalculationManagerParam): void; - - getReferenceExecutorMap(): Map>>; - - onChanged$: Observable; -} - /** * Passively marked as dirty, register the reference and execution actions of the feature plugin. * After execution, a dirty area and calculated data will be returned, * causing the formula to be marked dirty again, * thereby completing the calculation of the entire dependency tree. */ -export class FeatureCalculationManagerService extends Disposable implements IFeatureCalculationManagerService { +export class FeatureCalculationManagerService extends Disposable { private _referenceExecutorMap: Map>> = new Map(); // unitId -> subUnitId -> featureId -> IFeatureCalculationManagerParam private _onChanged$ = new Subject(); @@ -114,7 +97,3 @@ export class FeatureCalculationManagerService extends Disposable implements IFea return this._referenceExecutorMap; } } - -export const IFeatureCalculationManagerService = createIdentifier( - 'univer.formula.feature-calculation-manager.service' -); diff --git a/packages/engine-formula/src/services/function.service.ts b/packages/engine-formula/src/services/function.service.ts index 6c7bb5e3588..cdfa0e352ee 100644 --- a/packages/engine-formula/src/services/function.service.ts +++ b/packages/engine-formula/src/services/function.service.ts @@ -14,51 +14,17 @@ * limitations under the License. */ -import type { IDisposable, Nullable } from '@univerjs/core'; -import { createIdentifier, Disposable, toDisposable } from '@univerjs/core'; - +import type { IDisposable } from '@univerjs/core'; import type { IFunctionInfo, IFunctionNames } from '../basics/function'; import type { BaseFunction } from '../functions/base-function'; +import { Disposable, toDisposable } from '@univerjs/core'; -export interface IFunctionService { - /** - * Use register to register a function, new CustomFunction(inject, name) - */ - registerExecutors(...functions: BaseFunction[]): void; - - getExecutors(): Map; - - /** - * Obtain the operator of the function to reuse the calculation logic. - * The argument type accepted by the function is: FunctionVariantType. - * For instance, the sum formula capability is needed for the statistics bar. - * You can obtain the calculation result by using - * const sum = formulaService.getExecutor(FUNCTION_NAMES_MATH.SUM); - * sum.calculate(new RangeReferenceObject(range, sheetId, unitId), ref2, re3). - * @param functionName Function name, which can be obtained through the FUNCTION_NAMES enumeration. - * @returns - */ - getExecutor(functionToken: IFunctionNames): Nullable; - - hasExecutor(functionToken: IFunctionNames): boolean; - - unregisterExecutors(...functionTokens: IFunctionNames[]): void; - - registerDescriptions(...functions: IFunctionInfo[]): IDisposable; - - getDescriptions(): Map; - - getDescription(functionToken: IFunctionNames): Nullable; - - hasDescription(functionToken: IFunctionNames): boolean; - - unregisterDescriptions(...functionTokens: IFunctionNames[]): void; -} -export const IFunctionService = createIdentifier('univer.formula-function.service'); - -export class FunctionService extends Disposable implements IFunctionService { +/** + * This stores function executors and descriptions. It both resident in host process and worker process, though + * descriptions will not be registered in the worker process. + */ +export class FunctionService extends Disposable { private _functionExecutors: Map = new Map(); - private _functionDescriptions: Map = new Map(); override dispose(): void { @@ -66,6 +32,9 @@ export class FunctionService extends Disposable implements IFunctionService { this._functionDescriptions.clear(); } + /** + * Use register to register a function, new CustomFunction(inject, name) + */ registerExecutors(...functions: BaseFunction[]) { for (let i = 0; i < functions.length; i++) { const func = functions[i]; @@ -77,6 +46,16 @@ export class FunctionService extends Disposable implements IFunctionService { return this._functionExecutors; } + /** + * Obtain the operator of the function to reuse the calculation logic. + * The argument type accepted by the function is: FunctionVariantType. + * For instance, the sum formula capability is needed for the statistics bar. + * You can obtain the calculation result by using + * const sum = formulaService.getExecutor(FUNCTION_NAMES_MATH.SUM); + * sum.calculate(new RangeReferenceObject(range, sheetId, unitId), ref2, re3). + * @param functionName Function name, which can be obtained through the FUNCTION_NAMES enumeration. + * @returns + */ getExecutor(functionToken: IFunctionNames) { return this._functionExecutors.get(functionToken); } diff --git a/packages/engine-formula/src/services/other-formula-manager.service.ts b/packages/engine-formula/src/services/other-formula-manager.service.ts index 5e78dd2b72c..291ffe616fa 100644 --- a/packages/engine-formula/src/services/other-formula-manager.service.ts +++ b/packages/engine-formula/src/services/other-formula-manager.service.ts @@ -14,10 +14,8 @@ * limitations under the License. */ -import type { Nullable } from '@univerjs/core'; -import { createIdentifier, Disposable } from '@univerjs/core'; - import type { IDirtyUnitOtherFormulaMap, IFormulaDataItem, IOtherFormulaData } from '../basics/common'; +import { Disposable } from '@univerjs/core'; export interface IOtherFormulaManagerSearchParam { unitId: string; @@ -29,31 +27,12 @@ export interface IOtherFormulaManagerInsertParam extends IOtherFormulaManagerSea item: IFormulaDataItem; } -export interface IOtherFormulaManagerService { - dispose(): void; - - remove(searchParam: IOtherFormulaManagerSearchParam): void; - - get(searchParam: IOtherFormulaManagerSearchParam): Nullable; - - has(searchParam: IOtherFormulaManagerSearchParam): boolean; - - register(insertParam: IOtherFormulaManagerInsertParam): void; - - getOtherFormulaData(): IOtherFormulaData; - - batchRegister(formulaData: IOtherFormulaData): void; - - batchRemove(formulaData: IDirtyUnitOtherFormulaMap): void; -} +// NOTE@wzhudev: if this service really necessary? /** - * Passively marked as dirty, register the reference and execution actions of the feature plugin. - * After execution, a dirty area and calculated data will be returned, - * causing the formula to be marked dirty again, - * thereby completing the calculation of the entire dependency tree. + * A simple map to register formulas from upper layer features. */ -export class OtherFormulaManagerService extends Disposable implements IOtherFormulaManagerService { +export class OtherFormulaManagerService extends Disposable { private _otherFormulaData: IOtherFormulaData = {}; override dispose(): void { @@ -70,11 +49,6 @@ export class OtherFormulaManagerService extends Disposable implements IOtherForm return this._otherFormulaData[unitId]?.[subUnitId]?.[formulaId]; } - has(searchParam: IOtherFormulaManagerSearchParam) { - const { unitId, subUnitId, formulaId } = searchParam; - return this._otherFormulaData[unitId]?.[subUnitId]?.[formulaId] != null; - } - register(insertParam: IOtherFormulaManagerInsertParam) { const { unitId, subUnitId, formulaId, item } = insertParam; if (!this._otherFormulaData[unitId]) { @@ -142,7 +116,3 @@ export class OtherFormulaManagerService extends Disposable implements IOtherForm return this._otherFormulaData; } } - -export const IOtherFormulaManagerService = createIdentifier( - 'univer.formula.other-formula-manager.service' -); diff --git a/packages/engine-formula/src/services/runtime.service.ts b/packages/engine-formula/src/services/runtime.service.ts index 9be2de3a515..4c8b6774759 100644 --- a/packages/engine-formula/src/services/runtime.service.ts +++ b/packages/engine-formula/src/services/runtime.service.ts @@ -21,20 +21,18 @@ import type { IRuntimeOtherUnitDataType, IRuntimeUnitDataType, } from '../basics/common'; - import type { BaseAstNode } from '../engine/ast-node/base-ast-node'; import type { BaseReferenceObject, FunctionVariantType } from '../engine/reference-object/base-reference-object'; import type { ArrayValueObject } from '../engine/value-object/array-value-object'; -import { createIdentifier, Disposable, isNullCell, ObjectMatrix } from '@univerjs/core'; +import { Disposable, Inject, isNullCell, ObjectMatrix } from '@univerjs/core'; import { isInDirtyRange } from '../basics/dirty'; import { ErrorType } from '../basics/error-type'; import { getRuntimeFeatureCell } from '../engine/utils/get-runtime-feature-cell'; import { clearNumberFormatTypeCache, clearStringToNumberPatternCache } from '../engine/utils/numfmt-kit'; - import { clearReferenceToRangeCache } from '../engine/utils/reference-cache'; import { objectValueToCellValue } from '../engine/utils/value-object'; import { type BaseValueObject, ErrorValueObject } from '../engine/value-object/base-value-object'; -import { IFormulaCurrentConfigService } from './current-data.service'; +import { FormulaCurrentConfigService } from './current-data.service'; /** * IDLE: Idle phase of the formula engine. @@ -87,100 +85,7 @@ export interface IExecutionInProgressParams { stage: FormulaExecuteStageType; } -export interface IFormulaRuntimeService { - currentRow: number; - - currentColumn: number; - - currentSubUnitId: string; - - currentUnitId: string; - - dispose(): void; - - reset(): void; - - setCurrent( - row: number, - column: number, - rowCount: number, - columnCount: number, - sheetId: string, - unitId: string - ): void; - - registerFunctionDefinitionPrivacyVar(lambdaId: string, lambdaVar: Map>): void; - - getFunctionDefinitionPrivacyVar(lambdaId: string): Nullable>>; - - setRuntimeData(functionVariant: FunctionVariantType): void; - - getUnitData(): IRuntimeUnitDataType; - - getUnitArrayFormula(): IArrayFormulaRangeType; - - stopExecution(): void; - - setFormulaExecuteStage(type: FormulaExecuteStageType): void; - - setFormulaCycleIndex(index: number): void; - - isStopExecution(): boolean; - - getFormulaExecuteStage(): FormulaExecuteStageType; - - setRuntimeOtherData(formulaId: string, functionVariant: FunctionVariantType): void; - - getRuntimeOtherData(): IRuntimeOtherUnitDataType; - - getAllRuntimeData(): IAllRuntimeData; - - markedAsSuccessfullyExecuted(): void; - - markedAsNoFunctionsExecuted(): void; - - markedAsStopFunctionsExecuted(): void; - - markedAsInitialFunctionsExecuted(): void; - - setTotalFormulasToCalculate(value: number): void; - - getTotalFormulasToCalculate(): number; - - setCompletedFormulasCount(value: number): void; - - getCompletedFormulasCount(): number; - - getRuntimeState(): IExecutionInProgressParams; - - setTotalArrayFormulasToCalculate(value: number): void; - - getTotalArrayFormulasToCalculate(): number; - - setCompletedArrayFormulasCount(value: number): void; - - getCompletedArrayFormulasCount(): number; - - enableCycleDependency(): void; - - disableCycleDependency(): void; - - isCycleDependency(): boolean; - - getRuntimeArrayFormulaCellData(): IRuntimeUnitDataType; - - getRuntimeFeatureRange(): { [featureId: string]: IFeatureDirtyRangeType }; - - getRuntimeFeatureCellData(): { [featureId: string]: IRuntimeUnitDataType }; - - setRuntimeFeatureCellData(featureId: string, featureData: IRuntimeUnitDataType): void; - - setRuntimeFeatureRange(featureId: string, featureRange: IFeatureDirtyRangeType): void; - - clearReferenceAndNumberformatCache(): void; -} - -export class FormulaRuntimeService extends Disposable implements IFormulaRuntimeService { +export class FormulaRuntimeService extends Disposable { private _formulaExecuteStage: FormulaExecuteStageType = FormulaExecuteStageType.IDLE; private _stopState = false; @@ -225,7 +130,9 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime private _isCycleDependency: boolean = false; - constructor(@IFormulaCurrentConfigService private readonly _currentConfigService: IFormulaCurrentConfigService) { + constructor( + @Inject(FormulaCurrentConfigService) private readonly _currentConfigService: FormulaCurrentConfigService + ) { super(); } @@ -787,5 +694,3 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime return isInDirtyRange(dirtyRanges, unitId, sheetId, row, column); } } - -export const IFormulaRuntimeService = createIdentifier('univer.formula.runtime.service'); diff --git a/packages/engine-formula/src/services/super-table.service.ts b/packages/engine-formula/src/services/super-table.service.ts index 384368417c8..88efdfc9e50 100644 --- a/packages/engine-formula/src/services/super-table.service.ts +++ b/packages/engine-formula/src/services/super-table.service.ts @@ -14,29 +14,16 @@ * limitations under the License. */ -import type { Nullable } from '@univerjs/core'; -import { createIdentifier, Disposable } from '@univerjs/core'; - import type { ISuperTable, TableOptionType } from '../basics/common'; +import { Disposable } from '@univerjs/core'; + export interface ISuperTableOptionParam { tableOption: string; tableOptionType: TableOptionType; } -export interface ISuperTableService { - getTableMap(unitId: string): Nullable>; - - getTableOptionMap(): Map; - - registerTable(unitId: string, tableName: string, reference: ISuperTable): void; - - registerTableOptionMap(tableOption: string, tableOptionType: TableOptionType): void; - - remove(unitId: string, tableName: string): void; -} - -export class SuperTableService extends Disposable implements ISuperTableService { +export class SuperTableService extends Disposable { // 18.5.1.2 table (Table) private _tableMap: Map> = new Map(); @@ -57,10 +44,6 @@ export class SuperTableService extends Disposable implements ISuperTableService return this._tableMap.get(unitId); } - getTableOptionMap() { - return this._tableOptionMap; - } - registerTable(unitId: string, tableName: string, reference: ISuperTable) { if (this._tableMap.get(unitId) == null) { this._tableMap.set(unitId, new Map()); @@ -73,4 +56,3 @@ export class SuperTableService extends Disposable implements ISuperTableService } } -export const ISuperTableService = createIdentifier('univer.formula.super-table.service'); diff --git a/packages/facade/src/apis/__tests__/create-test-bed.ts b/packages/facade/src/apis/__tests__/create-test-bed.ts index bae3cf55938..102954796d4 100644 --- a/packages/facade/src/apis/__tests__/create-test-bed.ts +++ b/packages/facade/src/apis/__tests__/create-test-bed.ts @@ -32,7 +32,7 @@ import { UniverInstanceType, } from '@univerjs/core'; import { UniverDataValidationPlugin } from '@univerjs/data-validation'; -import { ActiveDirtyManagerService, FormulaDataModel, FunctionService, IActiveDirtyManagerService, IFunctionService, LexerTreeBuilder } from '@univerjs/engine-formula'; +import { ActiveDirtyManagerService, FormulaDataModel, FunctionService, LexerTreeBuilder } from '@univerjs/engine-formula'; import { Engine, IRenderingEngine, IRenderManagerService, RenderManagerService } from '@univerjs/engine-render'; import { ISocketService, WebSocketService } from '@univerjs/network'; import { @@ -155,7 +155,7 @@ export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?: }, ]); - injector.add([IFunctionService, { useClass: FunctionService }]); + injector.add([FunctionService, { useClass: FunctionService }]); injector.add([ISocketService, { useClass: WebSocketService }]); injector.add([IRenderingEngine, { useFactory: () => new Engine() }]); injector.add([IRenderManagerService, { useClass: RenderManagerServiceTestBed }]); @@ -190,7 +190,7 @@ export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?: [DataValidationFormulaService], [DataValidationCustomFormulaService], [RegisterOtherFormulaService], - [IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }], + [ActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }], [SheetsDataValidationValidatorService], [SheetDataValidationModel], diff --git a/packages/facade/src/apis/sheets/__tests__/create-formula-test-bed.ts b/packages/facade/src/apis/sheets/__tests__/create-formula-test-bed.ts index 307ffe73507..c51bdf826bd 100644 --- a/packages/facade/src/apis/sheets/__tests__/create-formula-test-bed.ts +++ b/packages/facade/src/apis/sheets/__tests__/create-formula-test-bed.ts @@ -27,7 +27,7 @@ import { Univer, UniverInstanceType, } from '@univerjs/core'; -import { ActiveDirtyManagerService, AstRootNodeFactory, AstTreeBuilder, CalculateController, CalculateFormulaService, DefinedNamesService, DependencyManagerService, FeatureCalculationManagerService, FormulaCurrentConfigService, FormulaDataModel, FormulaDependencyGenerator, FormulaRuntimeService, FunctionNodeFactory, FunctionService, IActiveDirtyManagerService, IDefinedNamesService, IDependencyManagerService, IFeatureCalculationManagerService, IFormulaCurrentConfigService, IFormulaRuntimeService, IFunctionService, Interpreter, IOtherFormulaManagerService, ISuperTableService, LambdaNodeFactory, LambdaParameterNodeFactory, Lexer, LexerTreeBuilder, OperatorNodeFactory, OtherFormulaManagerService, PrefixNodeFactory, ReferenceNodeFactory, SuffixNodeFactory, SuperTableService, UnionNodeFactory, ValueNodeFactory } from '@univerjs/engine-formula'; +import { ActiveDirtyManagerService, AstRootNodeFactory, AstTreeBuilder, CalculateController, CalculateFormulaService, DefinedNamesService, DependencyManagerService, FeatureCalculationManagerService, FormulaCurrentConfigService, FormulaDataModel, FormulaDependencyGenerator, FormulaRuntimeService, FunctionNodeFactory, FunctionService, Interpreter, LambdaNodeFactory, LambdaParameterNodeFactory, Lexer, LexerTreeBuilder, OperatorNodeFactory, OtherFormulaManagerService, PrefixNodeFactory, ReferenceNodeFactory, SuffixNodeFactory, UnionNodeFactory, ValueNodeFactory } from '@univerjs/engine-formula'; import { IRenderManagerService, RenderManagerService } from '@univerjs/engine-render'; import { ISocketService, WebSocketService } from '@univerjs/network'; import { SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets'; @@ -149,22 +149,21 @@ function registerFormulaDependencies(injector: Injector) { ]); injector.add([FormulaDataModel]); - injector.add([IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }]); + injector.add([ActiveDirtyManagerService]); injector.add([CalculateFormulaService]); injector.add([Lexer]); injector.add([LexerTreeBuilder]); - injector.add([IFormulaCurrentConfigService, { useClass: FormulaCurrentConfigService }]); - injector.add([IDependencyManagerService, { useClass: DependencyManagerService }]); - injector.add([IFormulaRuntimeService, { useClass: FormulaRuntimeService }]); - injector.add([IFunctionService, { useClass: FunctionService }]); - injector.add([IOtherFormulaManagerService, { useClass: OtherFormulaManagerService }]); - injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]); - injector.add([ISuperTableService, { useClass: SuperTableService }]); + injector.add([FormulaCurrentConfigService]); + injector.add([DependencyManagerService]); + injector.add([FormulaRuntimeService]); + injector.add([FunctionService]); + injector.add([OtherFormulaManagerService]); + injector.add([DefinedNamesService]); injector.add([CalculateController]); - injector.add([IFeatureCalculationManagerService, { useClass: FeatureCalculationManagerService }]); + injector.add([FeatureCalculationManagerService]); injector.add([FormulaDependencyGenerator]); injector.add([Interpreter]); injector.add([AstTreeBuilder]); diff --git a/packages/facade/src/apis/sheets/__tests__/create-worksheet-test-bed.ts b/packages/facade/src/apis/sheets/__tests__/create-worksheet-test-bed.ts index 3d6b59b9f2d..16e4d30b930 100644 --- a/packages/facade/src/apis/sheets/__tests__/create-worksheet-test-bed.ts +++ b/packages/facade/src/apis/sheets/__tests__/create-worksheet-test-bed.ts @@ -31,7 +31,7 @@ import { UniverInstanceType, } from '@univerjs/core'; import { UniverDataValidationPlugin } from '@univerjs/data-validation'; -import { ActiveDirtyManagerService, FormulaDataModel, FunctionService, IActiveDirtyManagerService, IFunctionService, LexerTreeBuilder } from '@univerjs/engine-formula'; +import { ActiveDirtyManagerService, FormulaDataModel, FunctionService, LexerTreeBuilder } from '@univerjs/engine-formula'; import { Engine, IRenderingEngine, IRenderManagerService, RenderManagerService } from '@univerjs/engine-render'; import { ISocketService, WebSocketService } from '@univerjs/network'; import { @@ -143,7 +143,7 @@ export function createWorksheetTestBed(workbookData?: IWorkbookData, dependencie }, ]); - injector.add([IFunctionService, { useClass: FunctionService }]); + injector.add([FunctionService, { useClass: FunctionService }]); injector.add([ISocketService, { useClass: WebSocketService }]); injector.add([IRenderingEngine, { useFactory: () => new Engine() }]); injector.add([IRenderManagerService, { useClass: RenderManagerService }]); @@ -178,7 +178,7 @@ export function createWorksheetTestBed(workbookData?: IWorkbookData, dependencie [DataValidationFormulaService], [DataValidationCustomFormulaService], [RegisterOtherFormulaService], - [IActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }], + [ActiveDirtyManagerService, { useClass: ActiveDirtyManagerService }], [SheetsDataValidationValidatorService], [SheetDataValidationModel], diff --git a/packages/sheets-conditional-formatting/src/services/__test__/test.util.ts b/packages/sheets-conditional-formatting/src/services/__test__/test.util.ts index c442123d2f0..77723ba980f 100644 --- a/packages/sheets-conditional-formatting/src/services/__test__/test.util.ts +++ b/packages/sheets-conditional-formatting/src/services/__test__/test.util.ts @@ -16,20 +16,20 @@ import type { Dependency, IWorkbookData } from '@univerjs/core'; import { ICommandService, Inject, Injector, IUniverInstanceService, LocaleType, Plugin, Univer, UniverInstanceType } from '@univerjs/core'; +import { ActiveDirtyManagerService } from '@univerjs/engine-formula'; + import { SheetInterceptorService, } from '@univerjs/sheets'; - -import { IActiveDirtyManagerService } from '@univerjs/engine-formula'; -import { ConditionalFormattingService } from '../conditional-formatting.service'; -import { ConditionalFormattingFormulaService } from '../conditional-formatting-formula.service'; -import { ConditionalFormattingRuleModel } from '../../models/conditional-formatting-rule-model'; -import { ConditionalFormattingViewModel } from '../../models/conditional-formatting-view-model'; import { AddConditionalRuleMutation } from '../../commands/mutations/add-conditional-rule.mutation'; import { DeleteConditionalRuleMutation } from '../../commands/mutations/delete-conditional-rule.mutation'; import { ConditionalFormattingFormulaMarkDirty } from '../../commands/mutations/formula-mark-dirty.mutation'; import { MoveConditionalRuleMutation } from '../../commands/mutations/move-conditional-rule.mutation'; import { SetConditionalRuleMutation } from '../../commands/mutations/set-conditional-rule.mutation'; +import { ConditionalFormattingRuleModel } from '../../models/conditional-formatting-rule-model'; +import { ConditionalFormattingViewModel } from '../../models/conditional-formatting-view-model'; +import { ConditionalFormattingService } from '../conditional-formatting.service'; +import { ConditionalFormattingFormulaService } from '../conditional-formatting-formula.service'; const TEST_WORKBOOK_DATA_DEMO: () => IWorkbookData = () => ({ id: 'test', @@ -82,7 +82,7 @@ export const createTestBed = (dependencies?: Dependency[]) => { this._injector.add([ConditionalFormattingFormulaService]); this._injector.add([ConditionalFormattingRuleModel]); this._injector.add([ConditionalFormattingViewModel]); - this._injector.add([IActiveDirtyManagerService, { useFactory: () => ({ register: () => { /* empty */ } } as any) }]); + this._injector.add([ActiveDirtyManagerService, { useFactory: () => ({ register: () => { /* empty */ } } as any) }]); this._injector.get(ConditionalFormattingService); } } diff --git a/packages/sheets-conditional-formatting/src/services/conditional-formatting-formula.service.ts b/packages/sheets-conditional-formatting/src/services/conditional-formatting-formula.service.ts index 3800b394823..fd20e5930d0 100644 --- a/packages/sheets-conditional-formatting/src/services/conditional-formatting-formula.service.ts +++ b/packages/sheets-conditional-formatting/src/services/conditional-formatting-formula.service.ts @@ -20,7 +20,7 @@ import type { IConditionalFormattingFormulaMarkDirtyParams } from '../commands/m import { BooleanNumber, CellValueType, Disposable, ICommandService, Inject, Injector, RefAlias, toDisposable, Tools } from '@univerjs/core'; import { - IActiveDirtyManagerService, + ActiveDirtyManagerService, RemoveOtherFormulaMutation, SetFormulaCalculationResultMutation, SetOtherFormulaMutation, @@ -66,7 +66,7 @@ export class ConditionalFormattingFormulaService extends Disposable { constructor( @Inject(ICommandService) private _commandService: ICommandService, @Inject(Injector) private _injector: Injector, - @Inject(IActiveDirtyManagerService) private _activeDirtyManagerService: IActiveDirtyManagerService, + @Inject(ActiveDirtyManagerService) private _activeDirtyManagerService: ActiveDirtyManagerService, @Inject(ConditionalFormattingViewModel) private _conditionalFormattingViewModel: ConditionalFormattingViewModel, @Inject(ConditionalFormattingRuleModel) private _conditionalFormattingRuleModel: ConditionalFormattingRuleModel diff --git a/packages/sheets-formula-ui/src/controllers/__tests__/create-command-test-bed.ts b/packages/sheets-formula-ui/src/controllers/__tests__/create-command-test-bed.ts index e8e588a6464..eaee0bba4a6 100644 --- a/packages/sheets-formula-ui/src/controllers/__tests__/create-command-test-bed.ts +++ b/packages/sheets-formula-ui/src/controllers/__tests__/create-command-test-bed.ts @@ -18,7 +18,7 @@ import type { Dependency, IWorkbookData, Workbook } from '@univerjs/core'; import { ILogService, Inject, Injector, IUniverInstanceService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core'; import { DocSelectionManagerService } from '@univerjs/docs'; import { EditorService, IEditorService } from '@univerjs/docs-ui'; -import { CalculateFormulaService, DefinedNamesService, FormulaCurrentConfigService, FormulaDataModel, FormulaRuntimeService, IDefinedNamesService, IFormulaCurrentConfigService, IFormulaRuntimeService, LexerTreeBuilder } from '@univerjs/engine-formula'; +import { CalculateFormulaService, DefinedNamesService, FormulaCurrentConfigService, FormulaDataModel, FormulaRuntimeService, LexerTreeBuilder } from '@univerjs/engine-formula'; import { IRenderManagerService, RenderManagerService } from '@univerjs/engine-render'; import { DefinedNameDataController, IRefSelectionsService, RangeProtectionRuleModel, SheetInterceptorService, SheetsSelectionsService, WorkbookPermissionService, WorksheetPermissionService, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '@univerjs/sheets'; import { EditorBridgeService, IEditorBridgeService, SheetSkeletonManagerService } from '@univerjs/sheets-ui'; @@ -89,10 +89,10 @@ export function createCommandTestBed(workbookData?: IWorkbookData, dependencies? injector.add([FormulaDataModel]); injector.add([LexerTreeBuilder]); injector.add([DocSelectionManagerService]); - injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]); + injector.add([DefinedNamesService]); injector.add([DefinedNameDataController]); - injector.add([IFormulaRuntimeService, { useClass: FormulaRuntimeService }]); - injector.add([IFormulaCurrentConfigService, { useClass: FormulaCurrentConfigService }]); + injector.add([FormulaRuntimeService]); + injector.add([FormulaCurrentConfigService]); injector.add([SheetSkeletonManagerService]); injector.add([IEditorBridgeService, { useClass: EditorBridgeService }]); injector.add([IEditorService, { useClass: EditorService }]); diff --git a/packages/sheets-formula-ui/src/controllers/__tests__/update-defined-name.controller.spec.ts b/packages/sheets-formula-ui/src/controllers/__tests__/update-defined-name.controller.spec.ts index 6e41e8478f0..965fe532ca2 100644 --- a/packages/sheets-formula-ui/src/controllers/__tests__/update-defined-name.controller.spec.ts +++ b/packages/sheets-formula-ui/src/controllers/__tests__/update-defined-name.controller.spec.ts @@ -17,7 +17,7 @@ import type { ICellData, Injector, IWorkbookData, Nullable, Univer } from '@univerjs/core'; import type { IDeleteRangeMoveLeftCommandParams, IDeleteRangeMoveUpCommandParams, IInsertColCommandParams, IInsertRowCommandParams, IMoveColsCommandParams, IMoveRangeCommandParams, IMoveRowsCommandParams, InsertRangeMoveDownCommandParams, InsertRangeMoveRightCommandParams, IRemoveRowColCommandParams, IRemoveSheetCommandParams, ISetWorksheetNameCommandParams } from '@univerjs/sheets'; import { Direction, ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE, RedoCommand, UndoCommand } from '@univerjs/core'; -import { IDefinedNamesService, RemoveDefinedNameMutation, SetArrayFormulaDataMutation, SetDefinedNameController, SetDefinedNameMutation, SetFormulaDataMutation } from '@univerjs/engine-formula'; +import { DefinedNamesService, RemoveDefinedNameMutation, SetArrayFormulaDataMutation, SetDefinedNameController, SetDefinedNameMutation, SetFormulaDataMutation } from '@univerjs/engine-formula'; import { DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, InsertColCommand, InsertColMutation, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, InsertRowCommand, InsertRowMutation, MoveColsCommand, MoveColsMutation, MoveRangeCommand, MoveRangeMutation, MoveRowsCommand, MoveRowsMutation, RemoveColCommand, RemoveColMutation, RemoveRowCommand, RemoveRowMutation, RemoveSheetCommand, RemoveSheetMutation, SetDefinedNameCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetSelectionsOperation, SetWorksheetNameCommand, SetWorksheetNameMutation, SheetsSelectionsService } from '@univerjs/sheets'; import { UpdateDefinedNameController } from '@univerjs/sheets-formula'; @@ -132,7 +132,7 @@ describe('Test update defined name', () => { .getValues(); getDefinedNameRef = (name: string = 'DefinedName1') => { - const definedNameService = get(IDefinedNamesService); + const definedNameService = get(DefinedNamesService); const definedName = definedNameService.getValueByName('test', name); if (definedName) { return definedName.formulaOrRefString; diff --git a/packages/sheets-formula/src/commands/mutations/formula.mutation.ts b/packages/sheets-formula/src/commands/mutations/formula.mutation.ts index fb1892ec794..7bc4c7763e7 100644 --- a/packages/sheets-formula/src/commands/mutations/formula.mutation.ts +++ b/packages/sheets-formula/src/commands/mutations/formula.mutation.ts @@ -19,6 +19,9 @@ import { CommandType } from '@univerjs/core'; export interface IOtherFormulaMarkDirtyParams { [unitId: string]: { [sunUnitId: string]: { [formulaId: string]: boolean } } } +/** + * @deprecated anti-pattern, and why is this not in the engine-formula package? + */ export const OtherFormulaMarkDirty: IMutation = { type: CommandType.MUTATION, id: 'sheet.mutation.data-validation-formula-mark-dirty', diff --git a/packages/sheets-formula/src/controllers/active-dirty.controller.ts b/packages/sheets-formula/src/controllers/active-dirty.controller.ts index d1094829abb..9e572b65d54 100644 --- a/packages/sheets-formula/src/controllers/active-dirty.controller.ts +++ b/packages/sheets-formula/src/controllers/active-dirty.controller.ts @@ -37,7 +37,7 @@ import { IUniverInstanceService, ObjectMatrix, } from '@univerjs/core'; -import { FormulaDataModel, IActiveDirtyManagerService, RemoveDefinedNameMutation, SetDefinedNameMutation } from '@univerjs/engine-formula'; +import { ActiveDirtyManagerService, FormulaDataModel, RemoveDefinedNameMutation, SetDefinedNameMutation } from '@univerjs/engine-formula'; import { InsertColMutation, InsertRowMutation, @@ -55,20 +55,24 @@ import { export class ActiveDirtyController extends Disposable { constructor( - @IActiveDirtyManagerService private readonly _activeDirtyManagerService: IActiveDirtyManagerService, + @Inject(ActiveDirtyManagerService) private readonly _activeDirtyManagerService: ActiveDirtyManagerService, @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService, @Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel ) { super(); - this._initialize(); + this._init(); } - private _initialize(): void { - this._initialConversion(); + private _init() { + this._initSetRangeValues(); + this._initialMove(); + this._initialRowAndColumn(); + this._initialSheet(); + this._initialDefinedName(); } - private _initialConversion() { + private _initSetRangeValues(): void { this._activeDirtyManagerService.register(SetRangeValuesMutation.id, { commandId: SetRangeValuesMutation.id, getDirtyData: (command: ICommandInfo) => { @@ -86,14 +90,6 @@ export class ActiveDirtyController extends Disposable { }; }, }); - - this._initialMove(); - - this._initialRowAndColumn(); - - this._initialSheet(); - - this._initialDefinedName(); } private _initialMove() { diff --git a/packages/sheets-formula/src/controllers/defined-name.controller.ts b/packages/sheets-formula/src/controllers/defined-name.controller.ts index e8132ec995e..1515cad1a3a 100644 --- a/packages/sheets-formula/src/controllers/defined-name.controller.ts +++ b/packages/sheets-formula/src/controllers/defined-name.controller.ts @@ -23,7 +23,7 @@ import { toDisposable, UniverInstanceType, } from '@univerjs/core'; -import { FunctionType, IDefinedNamesService, RemoveDefinedNameMutation, SetDefinedNameMutation } from '@univerjs/engine-formula'; +import { DefinedNamesService, FunctionType, RemoveDefinedNameMutation, SetDefinedNameMutation } from '@univerjs/engine-formula'; import { SetWorksheetActiveOperation } from '@univerjs/sheets'; import { IDescriptionService } from '../services/description.service'; @@ -39,7 +39,7 @@ export class DefinedNameController extends Disposable { constructor( @IDescriptionService private readonly _descriptionService: IDescriptionService, - @IDefinedNamesService private readonly _definedNamesService: IDefinedNamesService, + @Inject(DefinedNamesService) private readonly _definedNamesService: DefinedNamesService, @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService, @ICommandService private readonly _commandService: ICommandService diff --git a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts index c2a819f0bca..0d7ed289e1f 100644 --- a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts +++ b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts @@ -26,9 +26,9 @@ import type { import type { ISetRangeValuesMutationParams } from '@univerjs/sheets'; import { Disposable, ICommandService, throttle } from '@univerjs/core'; import { + ActiveDirtyManagerService, FormulaExecutedStateType, FormulaExecuteStageType, - IActiveDirtyManagerService, SetFormulaCalculationNotificationMutation, SetFormulaCalculationStartMutation, SetFormulaCalculationStopMutation, @@ -51,7 +51,7 @@ export interface ICalculationProgress { } const NilProgress: ICalculationProgress = { done: 0, count: 0 }; -const lo = { onlyLocal: true }; +const onlyLocal = { onlyLocal: true }; export class TriggerCalculationController extends Disposable { private _waitingCommandQueue: ICommandInfo[] = []; @@ -83,7 +83,7 @@ export class TriggerCalculationController extends Disposable { constructor( @ICommandService private readonly _commandService: ICommandService, - @IActiveDirtyManagerService private readonly _activeDirtyManagerService: IActiveDirtyManagerService + @Inject(ActiveDirtyManagerService) private readonly _activeDirtyManagerService: ActiveDirtyManagerService ) { super(); @@ -129,7 +129,7 @@ export class TriggerCalculationController extends Disposable { this._executingDirtyData = this._mergeDirty(this._executingDirtyData, dirtyData); if (this._executionInProgressParams == null) { - this._commandService.executeCommand(SetFormulaCalculationStartMutation.id, { ...this._executingDirtyData }, lo); + this._commandService.executeCommand(SetFormulaCalculationStartMutation.id, { ...this._executingDirtyData }, onlyLocal); } else { this._restartCalculation = true; this._commandService.executeCommand(SetFormulaCalculationStopMutation.id); @@ -396,7 +396,7 @@ export class TriggerCalculationController extends Disposable { { ...this._executingDirtyData, }, - lo + onlyLocal ); } else { this._executionInProgressParams = null; @@ -427,7 +427,7 @@ export class TriggerCalculationController extends Disposable { commands: [], forceCalculation: true, }, - lo + onlyLocal ); } diff --git a/packages/sheets-formula/src/controllers/update-defined-name.controller.ts b/packages/sheets-formula/src/controllers/update-defined-name.controller.ts index 268d3a813bd..59dafd2aa37 100644 --- a/packages/sheets-formula/src/controllers/update-defined-name.controller.ts +++ b/packages/sheets-formula/src/controllers/update-defined-name.controller.ts @@ -15,7 +15,7 @@ */ import type { IMutationInfo, Nullable, Workbook } from '@univerjs/core'; -import type { IDefinedNamesServiceParam, ISetDefinedNameMutationParam } from '@univerjs/engine-formula'; +import type { DefinedNamesServiceParam, ISetDefinedNameMutationParam } from '@univerjs/engine-formula'; import type { IUnitRangeWithOffset } from './utils/ref-range-move'; import { Disposable, @@ -23,7 +23,7 @@ import { IUniverInstanceService, UniverInstanceType, } from '@univerjs/core'; -import { deserializeRangeWithSheet, ErrorType, generateStringWithSequence, IDefinedNamesService, LexerTreeBuilder, sequenceNodeType, serializeRangeToRefString, SetDefinedNameMutation } from '@univerjs/engine-formula'; +import { DefinedNamesService, deserializeRangeWithSheet, ErrorType, generateStringWithSequence, LexerTreeBuilder, sequenceNodeType, serializeRangeToRefString, SetDefinedNameMutation } from '@univerjs/engine-formula'; import { RemoveDefinedNameCommand, SetDefinedNameCommand, SheetInterceptorService } from '@univerjs/sheets'; import { FormulaReferenceMoveType, type IFormulaReferenceMoveParam, updateRefOffset } from './utils/ref-range-formula'; import { getNewRangeByMoveParam } from './utils/ref-range-move'; @@ -31,7 +31,7 @@ import { getReferenceMoveParams } from './utils/ref-range-param'; export class UpdateDefinedNameController extends Disposable { constructor( - @IDefinedNamesService private readonly _definedNamesService: IDefinedNamesService, + @Inject(DefinedNamesService) private readonly _definedNamesService: DefinedNamesService, @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService, @Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService, @Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder @@ -206,7 +206,7 @@ export class UpdateDefinedNameController extends Disposable { }; } - private _removeSheet(item: IDefinedNamesServiceParam, unitId: string, subUnitId: string) { + private _removeSheet(item: DefinedNamesServiceParam, unitId: string, subUnitId: string) { const { formulaOrRefString } = item; const sheetId = this._definedNamesService.getWorksheetByRef(unitId, formulaOrRefString)?.getSheetId(); diff --git a/packages/sheets-formula/src/controllers/update-formula.controller.ts b/packages/sheets-formula/src/controllers/update-formula.controller.ts index b4ca43b85c0..015a1ebe6e1 100644 --- a/packages/sheets-formula/src/controllers/update-formula.controller.ts +++ b/packages/sheets-formula/src/controllers/update-formula.controller.ts @@ -40,11 +40,11 @@ import { UniverInstanceType, } from '@univerjs/core'; -import { deserializeRangeWithSheet, +import { DefinedNamesService, + deserializeRangeWithSheet, ErrorType, FormulaDataModel, generateStringWithSequence, - IDefinedNamesService, initSheetFormulaData, LexerTreeBuilder, sequenceNodeType, @@ -87,7 +87,7 @@ export class UpdateFormulaController extends Disposable { @Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder, @Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel, @Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService, - @IDefinedNamesService private readonly _definedNamesService: IDefinedNamesService, + @Inject(DefinedNamesService) private readonly _definedNamesService: DefinedNamesService, @Inject(Injector) readonly _injector: Injector ) { super(); diff --git a/packages/sheets-formula/src/services/description.service.ts b/packages/sheets-formula/src/services/description.service.ts index 91cab1cd291..fe6be1dad54 100644 --- a/packages/sheets-formula/src/services/description.service.ts +++ b/packages/sheets-formula/src/services/description.service.ts @@ -32,12 +32,12 @@ import { functionLookup, functionMath, functionMeta, + FunctionService, functionStatistical, functionText, FunctionType, functionUniver, functionWeb, - IFunctionService, isReferenceStrings, } from '@univerjs/engine-formula'; import { PLUGIN_CONFIG_KEY_BASE } from '../controllers/config.schema'; @@ -121,7 +121,7 @@ export class DescriptionService implements IDescriptionService, IDisposable { private _descriptions: IFunctionInfo[] = []; constructor( - @IFunctionService private readonly _functionService: IFunctionService, + @Inject(FunctionService) private readonly _functionService: FunctionService, @Inject(LocaleService) private readonly _localeService: LocaleService, @IConfigService private readonly _configService: IConfigService ) { diff --git a/packages/sheets-formula/src/services/register-function.service.ts b/packages/sheets-formula/src/services/register-function.service.ts index fcfdf8ab6fc..1c08fce44d0 100644 --- a/packages/sheets-formula/src/services/register-function.service.ts +++ b/packages/sheets-formula/src/services/register-function.service.ts @@ -15,9 +15,9 @@ */ import type { IDisposable, ILocales } from '@univerjs/core'; -import { createIdentifier, Disposable, DisposableCollection, Inject, LocaleService, Optional, toDisposable } from '@univerjs/core'; import type { IFunctionInfo, PrimitiveValueType } from '@univerjs/engine-formula'; -import { CustomFunction, FunctionType, IFunctionService } from '@univerjs/engine-formula'; +import { createIdentifier, Disposable, DisposableCollection, Inject, LocaleService, Optional, toDisposable } from '@univerjs/core'; +import { CustomFunction, FunctionService, FunctionType } from '@univerjs/engine-formula'; import { IDescriptionService } from './description.service'; import { IRemoteRegisterFunctionService } from './remote/remote-register-function.service'; @@ -91,7 +91,7 @@ export class RegisterFunctionService extends Disposable implements IRegisterFunc constructor( @Inject(LocaleService) private readonly _localeService: LocaleService, @Inject(IDescriptionService) private readonly _descriptionService: IDescriptionService, - @IFunctionService private readonly _functionService: IFunctionService, + @Inject(FunctionService) private readonly _functionService: FunctionService, @Optional(IRemoteRegisterFunctionService) private readonly _remoteRegisterFunctionService?: IRemoteRegisterFunctionService ) { diff --git a/packages/sheets-formula/src/services/register-other-formula.service.ts b/packages/sheets-formula/src/services/register-other-formula.service.ts index 88010fb4466..0ed5868321d 100644 --- a/packages/sheets-formula/src/services/register-other-formula.service.ts +++ b/packages/sheets-formula/src/services/register-other-formula.service.ts @@ -15,11 +15,11 @@ */ import type { Nullable } from '@univerjs/core'; -import { Disposable, ICommandService, Tools } from '@univerjs/core'; import type { IRemoveOtherFormulaMutationParams, ISetFormulaCalculationResultMutation, ISetOtherFormulaMutationParams } from '@univerjs/engine-formula'; -import { IActiveDirtyManagerService, RemoveOtherFormulaMutation, SetFormulaCalculationResultMutation, SetOtherFormulaMutation } from '@univerjs/engine-formula'; -import { bufferTime, filter, map, Subject } from 'rxjs'; import type { IOtherFormulaMarkDirtyParams } from '../commands/mutations/formula.mutation'; +import { Disposable, ICommandService, Tools } from '@univerjs/core'; +import { ActiveDirtyManagerService, RemoveOtherFormulaMutation, SetFormulaCalculationResultMutation, SetOtherFormulaMutation } from '@univerjs/engine-formula'; +import { bufferTime, filter, map, Subject } from 'rxjs'; import { OtherFormulaMarkDirty } from '../commands/mutations/formula.mutation'; import { FormulaResultStatus, type IOtherFormulaResult } from './formula-common'; @@ -27,7 +27,6 @@ export class RegisterOtherFormulaService extends Disposable { private _formulaCacheMap: Map>> = new Map(); private _formulaChange$ = new Subject<{ unitId: string; subUnitId: string; formulaText: string; formulaId: string }>(); - public formulaChange$ = this._formulaChange$.asObservable(); // FIXME: this design could be improved. @@ -36,9 +35,10 @@ export class RegisterOtherFormulaService extends Disposable { constructor( @ICommandService private readonly _commandService: ICommandService, - @IActiveDirtyManagerService private _activeDirtyManagerService: IActiveDirtyManagerService + @Inject(ActiveDirtyManagerService) private _activeDirtyManagerService: ActiveDirtyManagerService ) { super(); + this._initFormulaRegister(); this._initFormulaCalculationResultChange(); } @@ -68,10 +68,6 @@ export class RegisterOtherFormulaService extends Disposable { return subUnitMap; } - private _createFormulaId(unitId: string, subUnitId: string) { - return `formula.${unitId}_${subUnitId}_${Tools.generateRandomId(8)}`; - } - private _initFormulaRegister() { this._activeDirtyManagerService.register(OtherFormulaMarkDirty.id, { @@ -84,23 +80,27 @@ export class RegisterOtherFormulaService extends Disposable { }, }); - this.formulaChange$.pipe(bufferTime(16), filter((list) => !!list.length), map((list) => { - return list.reduce((result, cur) => { - const { unitId, subUnitId, formulaId, formulaText } = cur; - if (!result[unitId]) { - result[unitId] = {}; - } - if (!result[unitId][subUnitId]) { - result[unitId][subUnitId] = {}; - } - result[unitId][subUnitId][formulaId] = { f: formulaText }; - return result; - }, {} as { [unitId: string]: { [sunUnitId: string]: { [formulaId: string]: { f: string } } } }); - })).subscribe((result) => { + this._formulaChange$.pipe( + bufferTime(16), + filter((list) => !!list.length), + map((list) => { + return list.reduce((result, cur) => { + const { unitId, subUnitId, formulaId, formulaText } = cur; + if (!result[unitId]) { + result[unitId] = {}; + } + if (!result[unitId][subUnitId]) { + result[unitId][subUnitId] = {}; + } + result[unitId][subUnitId][formulaId] = { f: formulaText }; + return result; + }, {} as { [unitId: string]: { [sunUnitId: string]: { [formulaId: string]: { f: string } } } }); + })).subscribe((result) => { for (const unitId in result) { for (const subUnitId in result[unitId]) { const value = result[unitId][subUnitId]; const config: ISetOtherFormulaMutationParams = { unitId, subUnitId, formulaMap: value }; + // FIXME@wzhudev: when we set other formula mutation, we should automatically set them as dirty this._commandService.executeCommand(SetOtherFormulaMutation.id, config).then(() => { this._commandService.executeCommand(OtherFormulaMarkDirty.id, { [unitId]: { [subUnitId]: value } } as unknown as IOtherFormulaMarkDirtyParams); @@ -116,6 +116,8 @@ export class RegisterOtherFormulaService extends Disposable { if (commandInfo.id === SetFormulaCalculationResultMutation.id) { const params = commandInfo.params as ISetFormulaCalculationResultMutation; + // 这里的性能问题究竟如何呢? + const { unitOtherData } = params; const results: Record> = {}; for (const unitId in unitOtherData) { @@ -142,13 +144,14 @@ export class RegisterOtherFormulaService extends Disposable { } } } + this._formulaResult$.next(results); } })); } registerFormula(unitId: string, subUnitId: string, formulaText: string, extra?: Record) { - const formulaId = this._createFormulaId(unitId, subUnitId); + const formulaId = createFormulaId(unitId, subUnitId); const cacheMap = this._ensureCacheMap(unitId, subUnitId); cacheMap.set(formulaId, { @@ -158,12 +161,15 @@ export class RegisterOtherFormulaService extends Disposable { callbacks: new Set(), extra, }); + this._formulaChange$.next({ unitId, subUnitId, formulaText, formulaId, }); + + // TODO: 这里应该 return observable 以返回计算结果 return formulaId; } @@ -201,3 +207,7 @@ export class RegisterOtherFormulaService extends Disposable { return cacheMap.get(formulaId); } } + +function createFormulaId(unitId: string, subUnitId: string) { + return `formula.${unitId}_${subUnitId}_${Tools.generateRandomId(8)}`; +} diff --git a/packages/sheets-formula/src/services/remote/remote-register-function.service.ts b/packages/sheets-formula/src/services/remote/remote-register-function.service.ts index f89dff96177..2abaec4e060 100644 --- a/packages/sheets-formula/src/services/remote/remote-register-function.service.ts +++ b/packages/sheets-formula/src/services/remote/remote-register-function.service.ts @@ -15,8 +15,8 @@ */ import type { BaseFunction } from '@univerjs/engine-formula'; -import { CustomFunction, IFunctionService } from '@univerjs/engine-formula'; import { createIdentifier } from '@univerjs/core'; +import { CustomFunction, FunctionService } from '@univerjs/engine-formula'; export interface IRemoteRegisterFunctionService { registerFunctions(serializedFuncs: Array<[string, string]>): Promise; @@ -31,7 +31,7 @@ export const IRemoteRegisterFunctionService = createIdentifier): Promise { diff --git a/packages/sheets-formula/src/sheets-formula.plugin.ts b/packages/sheets-formula/src/sheets-formula.plugin.ts index a45e8bf9b50..eaf484e326c 100644 --- a/packages/sheets-formula/src/sheets-formula.plugin.ts +++ b/packages/sheets-formula/src/sheets-formula.plugin.ts @@ -19,7 +19,7 @@ import type { IUniverSheetsFormulaBaseConfig, IUniverSheetsFormulaRemoteConfig, } from './controllers/config.schema'; -import { DependentOn, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core'; +import { DependentOn, IConfigService, Inject, Injector, Plugin, registerDependencies, touchDependencies, UniverInstanceType } from '@univerjs/core'; import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula'; import { fromModule, IRPCChannelService, toModule } from '@univerjs/rpc'; @@ -113,16 +113,18 @@ export class UniverSheetsFormulaPlugin extends Plugin { }]); } - dependencies.forEach((dependency) => j.add(dependency)); + registerDependencies(j, dependencies); } override onReady(): void { - this._injector.get(FormulaController); - this._injector.get(TriggerCalculationController); - this._injector.get(ActiveDirtyController); - this._injector.get(ArrayFormulaCellInterceptorController); - this._injector.get(UpdateFormulaController); - this._injector.get(UpdateDefinedNameController); + touchDependencies(this._injector, [ + [FormulaController], + [TriggerCalculationController], + [ActiveDirtyController], + [ArrayFormulaCellInterceptorController], + [UpdateFormulaController], + [UpdateDefinedNameController], + ]); } override onRendered(): void { diff --git a/packages/sheets-hyper-link-ui/src/services/resolver.service.ts b/packages/sheets-hyper-link-ui/src/services/resolver.service.ts index 4fd039698f5..75377bd05fb 100644 --- a/packages/sheets-hyper-link-ui/src/services/resolver.service.ts +++ b/packages/sheets-hyper-link-ui/src/services/resolver.service.ts @@ -21,7 +21,7 @@ import type { ISheetHyperLinkInfo } from '../types/interfaces/i-sheet-hyper-link import type { ISheetUrlParams } from '../types/interfaces/i-sheet-url-params'; import { ICommandService, IConfigService, Inject, isValidRange, IUniverInstanceService, LocaleService, RANGE_TYPE, Rectangle, UniverInstanceType } from '@univerjs/core'; import { MessageType } from '@univerjs/design'; -import { deserializeRangeWithSheet, IDefinedNamesService, serializeRange, serializeRangeWithSheet } from '@univerjs/engine-formula'; +import { DefinedNamesService, deserializeRangeWithSheet, serializeRange, serializeRangeWithSheet } from '@univerjs/engine-formula'; import { SetSelectionsOperation, SetWorksheetActiveOperation } from '@univerjs/sheets'; import { ERROR_RANGE, SheetHyperLinkType } from '@univerjs/sheets-hyper-link'; import { ScrollToRangeOperation } from '@univerjs/sheets-ui'; @@ -58,7 +58,7 @@ export class SheetsHyperLinkResolverService { constructor( @IUniverInstanceService private _univerInstanceService: IUniverInstanceService, @ICommandService private _commandService: ICommandService, - @IDefinedNamesService private _definedNamesService: IDefinedNamesService, + @Inject(DefinedNamesService) private _definedNamesService: DefinedNamesService, @IMessageService private _messageService: IMessageService, @Inject(LocaleService) private _localeService: LocaleService, @IConfigService private _configService: IConfigService diff --git a/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx b/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx index 4f5d81b8e8d..3f996496f76 100644 --- a/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx +++ b/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx @@ -20,7 +20,7 @@ import { BuildTextUtils, ColorKit, CustomRangeType, DisposableCollection, DOCS_Z import { Button, FormLayout, Input, Select } from '@univerjs/design'; import { DocSelectionManagerService } from '@univerjs/docs'; import { DocBackScrollRenderController, DocSelectionRenderService } from '@univerjs/docs-ui'; -import { deserializeRangeWithSheet, IDefinedNamesService, serializeRange, serializeRangeToRefString, serializeRangeWithSheet } from '@univerjs/engine-formula'; +import { DefinedNamesService, deserializeRangeWithSheet, serializeRange, serializeRangeToRefString, serializeRangeWithSheet } from '@univerjs/engine-formula'; import { IRenderManagerService } from '@univerjs/engine-render'; import { SetSelectionsOperation, SetWorksheetActiveOperation } from '@univerjs/sheets'; @@ -48,7 +48,7 @@ export const CellLinkEdit = () => { const [payload, setPayload] = useState(''); const localeService = useDependency(LocaleService); - const definedNameService = useDependency(IDefinedNamesService); + const definedNameService = useDependency(DefinedNamesService); const editorBridgeService = useDependency(IEditorBridgeService); const univerInstanceService = useDependency(IUniverInstanceService); const popupService = useDependency(SheetsHyperLinkPopupService); diff --git a/packages/sheets-ui/src/controllers/defined-name/defined-name.controller.ts b/packages/sheets-ui/src/controllers/defined-name/defined-name.controller.ts index 93ad3c2dd3c..fd2e6b573e0 100644 --- a/packages/sheets-ui/src/controllers/defined-name/defined-name.controller.ts +++ b/packages/sheets-ui/src/controllers/defined-name/defined-name.controller.ts @@ -17,7 +17,7 @@ import type { Workbook } from '@univerjs/core'; import type { ISelectionWithStyle } from '@univerjs/sheets'; import { Disposable, ICommandService, Inject, IUniverInstanceService, ThemeService, UniverInstanceType } from '@univerjs/core'; -import { deserializeRangeWithSheet, IDefinedNamesService, isReferenceStrings, operatorToken } from '@univerjs/engine-formula'; +import { DefinedNamesService, deserializeRangeWithSheet, isReferenceStrings, operatorToken } from '@univerjs/engine-formula'; import { getNormalSelectionStyle, getPrimaryForRange, ScrollToCellOperation, SetWorksheetActivateCommand, SheetsSelectionsService } from '@univerjs/sheets'; import { filter, merge } from 'rxjs'; @@ -27,7 +27,7 @@ export class SheetsDefinedNameController extends Disposable { @Inject(ThemeService) private readonly _themeService: ThemeService, @IUniverInstanceService private readonly _instanceSrv: IUniverInstanceService, @ICommandService private readonly _cmdSrv: ICommandService, - @IDefinedNamesService private readonly _definedNamesService: IDefinedNamesService + @Inject(DefinedNamesService) private readonly _definedNamesService: DefinedNamesService ) { super(); diff --git a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts index 0cb417d979f..90bca54f3e7 100644 --- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts +++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts @@ -48,7 +48,7 @@ import { RichTextEditingMutation, } from '@univerjs/docs'; import { VIEWPORT_KEY as DOC_VIEWPORT_KEY, DocSelectionRenderService, IEditorService, MoveCursorOperation, MoveSelectionOperation } from '@univerjs/docs-ui'; -import { IFunctionService, LexerTreeBuilder, matchToken } from '@univerjs/engine-formula'; +import { FunctionService, LexerTreeBuilder, matchToken } from '@univerjs/engine-formula'; import { convertTextRotation, DeviceInputEventType, @@ -102,7 +102,7 @@ export class EditingRenderController extends Disposable implements IRenderModule @IEditorBridgeService private readonly _editorBridgeService: IEditorBridgeService, @ICellEditorManagerService private readonly _cellEditorManagerService: ICellEditorManagerService, @Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder, - @IFunctionService private readonly _functionService: IFunctionService, + @Inject(FunctionService) private readonly _functionService: FunctionService, @Inject(DocSelectionManagerService) private readonly _textSelectionManagerService: DocSelectionManagerService, @ICommandService private readonly _commandService: ICommandService, @Inject(LocaleService) protected readonly _localService: LocaleService, @@ -727,7 +727,7 @@ export function getCellDataByInput( lexerTreeBuilder: LexerTreeBuilder, getSnapshot: (data: DocumentDataModel) => IDocumentData, localeService: LocaleService, - functionService: IFunctionService + functionService: FunctionService ) { cellData = Tools.deepClone(cellData); diff --git a/packages/sheets-ui/src/controllers/permission/sheet-permission-interceptor-base.controller.ts b/packages/sheets-ui/src/controllers/permission/sheet-permission-interceptor-base.controller.ts index 7b7fa631d00..6fef0ff96c7 100644 --- a/packages/sheets-ui/src/controllers/permission/sheet-permission-interceptor-base.controller.ts +++ b/packages/sheets-ui/src/controllers/permission/sheet-permission-interceptor-base.controller.ts @@ -23,7 +23,7 @@ import type { ISheetPasteParams } from '../../commands/commands/clipboard.comman import type { IEditorBridgeServiceVisibleParam } from '../../services/editor-bridge.service'; import { CustomCommandExecutionError, Disposable, DisposableCollection, FOCUSING_EDITOR_STANDALONE, ICommandService, IContextService, Inject, IPermissionService, isICellData, IUniverInstanceService, LocaleService, ObjectMatrix, Rectangle, Tools, UniverInstanceType } from '@univerjs/core'; import { IMEInputCommand, InsertCommand } from '@univerjs/docs-ui'; -import { deserializeRangeWithSheet, IDefinedNamesService, LexerTreeBuilder, operatorToken, sequenceNodeType } from '@univerjs/engine-formula'; +import { DefinedNamesService, deserializeRangeWithSheet, LexerTreeBuilder, operatorToken, sequenceNodeType } from '@univerjs/engine-formula'; import { UnitAction } from '@univerjs/protocol'; import { ClearSelectionContentCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, DeltaColumnWidthCommand, DeltaRowHeightCommand, getSheetCommandTarget, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, MoveColsCommand, MoveRangeCommand, MoveRowsCommand, RangeProtectionPermissionEditPoint, RangeProtectionPermissionViewPoint, RangeProtectionRuleModel, SetBackgroundColorCommand, SetColWidthCommand, SetRangeValuesCommand, SetRowHeightCommand, SetSelectedColsVisibleCommand, SetSelectedRowsVisibleCommand, SetSpecificColsVisibleCommand, SetSpecificRowsVisibleCommand, SetWorksheetNameCommand, SetWorksheetNameMutation, SetWorksheetOrderCommand, SetWorksheetRowIsAutoHeightCommand, SetWorksheetShowCommand, SheetsSelectionsService, WorkbookCopyPermission, WorkbookEditablePermission, WorkbookHideSheetPermission, WorkbookManageCollaboratorPermission, WorkbookMoveSheetPermission, WorkbookRenameSheetPermission, WorksheetCopyPermission, WorksheetEditPermission, WorksheetProtectionRuleModel, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission, WorksheetSetColumnStylePermission, WorksheetSetRowStylePermission, WorksheetViewPermission } from '@univerjs/sheets'; import { IDialogService } from '@univerjs/ui'; @@ -58,7 +58,7 @@ export class SheetPermissionInterceptorBaseController extends Disposable { @Inject(LocaleService) private readonly _localeService: LocaleService, @Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder, @IContextService private readonly _contextService: IContextService, - @IDefinedNamesService private readonly _definedNamesService: IDefinedNamesService + @Inject(DefinedNamesService) private readonly _definedNamesService: DefinedNamesService ) { super(); this._initialize(); diff --git a/packages/sheets-ui/src/controllers/utils/char-tools.ts b/packages/sheets-ui/src/controllers/utils/char-tools.ts index dfcbcf5c2da..c0e999b337f 100644 --- a/packages/sheets-ui/src/controllers/utils/char-tools.ts +++ b/packages/sheets-ui/src/controllers/utils/char-tools.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import type { IFunctionService, ISequenceNode, LexerTreeBuilder } from '@univerjs/engine-formula'; +import type { FunctionService, ISequenceNode, LexerTreeBuilder } from '@univerjs/engine-formula'; import { LocaleType, numfmt } from '@univerjs/core'; import { matchToken, sequenceNodeType } from '@univerjs/engine-formula'; @@ -68,7 +68,7 @@ export function isCJKLocale(locale: LocaleType) { * @param lexerTreeBuilder * @returns */ -export function normalizeString(str: string, lexerTreeBuilder: LexerTreeBuilder, currentLocale: LocaleType, functionService: IFunctionService) { +export function normalizeString(str: string, lexerTreeBuilder: LexerTreeBuilder, currentLocale: LocaleType, functionService: FunctionService) { let normalStr = str; if (isCJKLocale(currentLocale)) { @@ -98,7 +98,7 @@ export function normalizeString(str: string, lexerTreeBuilder: LexerTreeBuilder, return parsedValue == null ? str : normalStr; } -function normalizeFormulaString(str: string, normalStr: string, lexerTreeBuilder: LexerTreeBuilder, functionService: IFunctionService) { +function normalizeFormulaString(str: string, normalStr: string, lexerTreeBuilder: LexerTreeBuilder, functionService: FunctionService) { const nodes = lexerTreeBuilder.sequenceNodesBuilder(normalStr); if (!nodes) return str; @@ -146,7 +146,7 @@ function normalizeFormulaString(str: string, normalStr: string, lexerTreeBuilder return _normalStr; } -function hasFunctionName(name: string, functionService: IFunctionService, nodes: (string | ISequenceNode)[], index: number) { +function hasFunctionName(name: string, functionService: FunctionService, nodes: (string | ISequenceNode)[], index: number) { const functionList = functionService.getDescriptions(); if (nodes[index + 1] !== matchToken.OPEN_BRACKET) { diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-test-bed.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-test-bed.ts index e794406e80f..677e2ceca8d 100644 --- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-test-bed.ts +++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-test-bed.ts @@ -18,8 +18,10 @@ import type { Dependency, IDisposable, IWorkbookData } from '@univerjs/core'; import { DisposableCollection, ILogService, Inject, Injector, IUniverInstanceService, LocaleService, LocaleType, LogLevel, Plugin, Univer, UniverInstanceType } from '@univerjs/core'; +import { CalculateFormulaService, DefinedNamesService, FormulaCurrentConfigService, FormulaDataModel, FormulaRuntimeService, LexerTreeBuilder } from '@univerjs/engine-formula'; import { IRenderManagerService, RenderManagerService } from '@univerjs/engine-render'; import { SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets'; + import { BrowserClipboardService, DesktopMessageService, @@ -28,14 +30,12 @@ import { INotificationService, IPlatformService, } from '@univerjs/ui'; - -import { CalculateFormulaService, DefinedNamesService, FormulaCurrentConfigService, FormulaDataModel, FormulaRuntimeService, IDefinedNamesService, IFormulaCurrentConfigService, IFormulaRuntimeService, LexerTreeBuilder } from '@univerjs/engine-formula'; import { SheetClipboardController } from '../../../controllers/clipboard/clipboard.controller'; import { IMarkSelectionService } from '../../mark-selection/mark-selection.service'; +import { ISheetSelectionRenderService } from '../../selection/base-selection-render.service'; import { SheetSelectionRenderService } from '../../selection/selection-render.service'; -import { ISheetClipboardService, SheetClipboardService } from '../clipboard.service'; import { SheetSkeletonManagerService } from '../../sheet-skeleton-manager.service'; -import { ISheetSelectionRenderService } from '../../selection/base-selection-render.service'; +import { ISheetClipboardService, SheetClipboardService } from '../clipboard.service'; const cellData = { 0: { @@ -563,9 +563,9 @@ export function clipboardTestBed(workbookData?: IWorkbookData, dependencies?: De injector.add([CalculateFormulaService]); injector.add([FormulaDataModel]); injector.add([LexerTreeBuilder]); - injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]); - injector.add([IFormulaRuntimeService, { useClass: FormulaRuntimeService }]); - injector.add([IFormulaCurrentConfigService, { useClass: FormulaCurrentConfigService }]); + injector.add([DefinedNamesService]); + injector.add([FormulaRuntimeService]); + injector.add([FormulaCurrentConfigService]); dependencies?.forEach((d) => injector.add(d)); diff --git a/packages/sheets-ui/src/views/defined-name/DefinedName.tsx b/packages/sheets-ui/src/views/defined-name/DefinedName.tsx index 21872abca36..7bf6220723b 100644 --- a/packages/sheets-ui/src/views/defined-name/DefinedName.tsx +++ b/packages/sheets-ui/src/views/defined-name/DefinedName.tsx @@ -17,7 +17,7 @@ import { useDependency } from '@univerjs/core'; import { Dropdown, Input } from '@univerjs/design'; -import { IDefinedNamesService } from '@univerjs/engine-formula'; +import { DefinedNamesService } from '@univerjs/engine-formula'; import { MoreDownSingle } from '@univerjs/icons'; import clsx from 'clsx'; import React, { useEffect } from 'react'; @@ -26,7 +26,7 @@ import styles from './index.module.less'; export function DefinedName({ disable }: { disable: boolean }) { const [rangeString, setRangeString] = React.useState(''); - const definedNamesService = useDependency(IDefinedNamesService); + const definedNamesService = useDependency(DefinedNamesService); useEffect(() => { const subscription = definedNamesService.currentRange$.subscribe(() => { diff --git a/packages/sheets-ui/src/views/defined-name/DefinedNameContainer.tsx b/packages/sheets-ui/src/views/defined-name/DefinedNameContainer.tsx index 06c877020e7..5b650c592a9 100644 --- a/packages/sheets-ui/src/views/defined-name/DefinedNameContainer.tsx +++ b/packages/sheets-ui/src/views/defined-name/DefinedNameContainer.tsx @@ -16,10 +16,10 @@ import type { Nullable, Workbook } from '@univerjs/core'; -import type { IDefinedNamesServiceParam, ISetDefinedNameMutationParam } from '@univerjs/engine-formula'; +import type { DefinedNamesServiceParam, ISetDefinedNameMutationParam } from '@univerjs/engine-formula'; import { ICommandService, IUniverInstanceService, LocaleService, Tools, UniverInstanceType, useDependency } from '@univerjs/core'; import { Confirm, Tooltip } from '@univerjs/design'; -import { IDefinedNamesService, serializeRangeWithSheet } from '@univerjs/engine-formula'; +import { DefinedNamesService, serializeRangeWithSheet } from '@univerjs/engine-formula'; import { CheckMarkSingle, DeleteSingle, IncreaseSingle } from '@univerjs/icons'; import { InsertDefinedNameCommand, RemoveDefinedNameCommand, SetDefinedNameCommand, SetWorksheetShowCommand, SheetsSelectionsService } from '@univerjs/sheets'; import clsx from 'clsx'; @@ -33,7 +33,7 @@ export const DefinedNameContainer = () => { const univerInstanceService = useDependency(IUniverInstanceService); const workbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)!; const localeService = useDependency(LocaleService); - const definedNamesService = useDependency(IDefinedNamesService); + const definedNamesService = useDependency(DefinedNamesService); const selectionManagerService = useDependency(SheetsSelectionsService); if (workbook == null) { @@ -51,7 +51,7 @@ export const DefinedNameContainer = () => { }; const [editState, setEditState] = useState(false); - const [definedNames, setDefinedNames] = useState(getDefinedNameMap()); + const [definedNames, setDefinedNames] = useState(getDefinedNameMap()); const [editorKey, setEditorKey] = useState>(null); const [deleteConformKey, setDeleteConformKey] = useState>(); @@ -65,7 +65,7 @@ export const DefinedNameContainer = () => { }; }, []); - const insertConfirm = (param: IDefinedNamesServiceParam) => { + const insertConfirm = (param: DefinedNamesServiceParam) => { const { name, formulaOrRefString, comment, localSheetId, hidden } = param; let id = param.id; @@ -94,7 +94,7 @@ export const DefinedNameContainer = () => { setDeleteConformKey(null); } - const focusDefinedName = async (definedName: IDefinedNamesServiceParam) => { + const focusDefinedName = async (definedName: DefinedNamesServiceParam) => { // The worksheet may be hidden, so we need to show it first const { formulaOrRefString, id } = definedName; const worksheet = definedNamesService.getWorksheetByRef(unitId, formulaOrRefString); diff --git a/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx b/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx index ca77b6638f2..c2d33b50987 100644 --- a/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx +++ b/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx @@ -19,7 +19,7 @@ import type { Nullable, Workbook } from '@univerjs/core'; import { AbsoluteRefType, createInternalEditorID, IUniverInstanceService, LocaleService, Tools, UniverInstanceType, useDependency } from '@univerjs/core'; import { Button, Input, Radio, RadioGroup, Select } from '@univerjs/design'; import { TextEditor } from '@univerjs/docs-ui'; -import { IDefinedNamesService, type IDefinedNamesServiceParam, IFunctionService, isReferenceStrings, isReferenceStringWithEffectiveColumn, LexerTreeBuilder, operatorToken } from '@univerjs/engine-formula'; +import { DefinedNamesService, type DefinedNamesServiceParam, FunctionService, isReferenceStrings, isReferenceStringWithEffectiveColumn, LexerTreeBuilder, operatorToken } from '@univerjs/engine-formula'; import { hasCJKText } from '@univerjs/engine-render'; import { ErrorSingle } from '@univerjs/icons'; import { ComponentManager } from '@univerjs/ui'; @@ -29,11 +29,11 @@ import { SCOPE_WORKBOOK_VALUE } from './component-name'; import styles from './index.module.less'; -export interface IDefinedNameInputProps extends Omit { +export interface IDefinedNameInputProps extends Omit { inputId: string; type?: string; state: boolean; - confirm?: (param: IDefinedNamesServiceParam) => void; + confirm?: (param: DefinedNamesServiceParam) => void; cancel?: () => void; id?: string; } @@ -60,8 +60,8 @@ export const DefinedNameInput = (props: IDefinedNameInputProps) => { const univerInstanceService = useDependency(IUniverInstanceService); const workbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)!; const localeService = useDependency(LocaleService); - const definedNamesService = useDependency(IDefinedNamesService); - const functionService = useDependency(IFunctionService); + const definedNamesService = useDependency(DefinedNamesService); + const functionService = useDependency(FunctionService); const lexerTreeBuilder = useDependency(LexerTreeBuilder); const componentManager = useDependency(ComponentManager); diff --git a/packages/sheets-ui/src/views/defined-name/DefinedNameOverlay.tsx b/packages/sheets-ui/src/views/defined-name/DefinedNameOverlay.tsx index 29e4c8301a2..317fbf25f61 100644 --- a/packages/sheets-ui/src/views/defined-name/DefinedNameOverlay.tsx +++ b/packages/sheets-ui/src/views/defined-name/DefinedNameOverlay.tsx @@ -16,9 +16,9 @@ import type { Workbook } from '@univerjs/core'; -import type { IDefinedNamesServiceParam } from '@univerjs/engine-formula'; +import type { DefinedNamesServiceParam } from '@univerjs/engine-formula'; import { ICommandService, IUniverInstanceService, LocaleService, UniverInstanceType, useDependency } from '@univerjs/core'; -import { IDefinedNamesService } from '@univerjs/engine-formula'; +import { DefinedNamesService } from '@univerjs/engine-formula'; import { SetWorksheetShowCommand } from '@univerjs/sheets'; import { ISidebarService } from '@univerjs/ui'; import React, { useEffect, useState } from 'react'; @@ -33,7 +33,7 @@ export interface IDefinedNameOverlayProps { export function DefinedNameOverlay(props: IDefinedNameOverlayProps) { const commandService = useDependency(ICommandService); const localeService = useDependency(LocaleService); - const definedNamesService = useDependency(IDefinedNamesService); + const definedNamesService = useDependency(DefinedNamesService); const univerInstanceService = useDependency(IUniverInstanceService); const sidebarService = useDependency(ISidebarService); @@ -48,7 +48,7 @@ export function DefinedNameOverlay(props: IDefinedNameOverlayProps) { return []; }; - const [definedNames, setDefinedNames] = useState(getDefinedNameMap()); + const [definedNames, setDefinedNames] = useState(getDefinedNameMap()); useEffect(() => { const definedNamesSubscription = definedNamesService.update$.subscribe(() => { @@ -80,7 +80,7 @@ export function DefinedNameOverlay(props: IDefinedNameOverlayProps) { commandService.executeCommand(SidebarDefinedNameOperation.id, { value: 'open' }); }; - const focusDefinedName = async (definedName: IDefinedNamesServiceParam) => { + const focusDefinedName = async (definedName: DefinedNamesServiceParam) => { // The worksheet may be hidden, so we need to show it first const { formulaOrRefString, id } = definedName; const worksheet = definedNamesService.getWorksheetByRef(unitId, formulaOrRefString); diff --git a/packages/sheets/src/commands/commands/set-defined-name.command.ts b/packages/sheets/src/commands/commands/set-defined-name.command.ts index 223b4204ee4..621aa1ffce2 100644 --- a/packages/sheets/src/commands/commands/set-defined-name.command.ts +++ b/packages/sheets/src/commands/commands/set-defined-name.command.ts @@ -27,7 +27,7 @@ import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet- /** * The command to update defined name * - * 1. The old defined name can be obtained through IDefinedNamesService, and does not need to be passed in from the outside, making the command input more concise + * 1. The old defined name can be obtained through DefinedNamesService, and does not need to be passed in from the outside, making the command input more concise 2. Unlike InsertDefinedNameCommand, the old defined name needs to be deleted here at the same time. Because the command interception in UpdateDefinedNameController will add SetDefinedNameMutation or RemoveDefinedNameMutation, it results in that in DefinedNameController, only mutations can be listened to to update Function Description (commands cannot be listened to), so it is necessary to ensure that each mutation triggered by the command has completed all work. */ diff --git a/packages/sheets/src/controllers/defined-name-data.controller.ts b/packages/sheets/src/controllers/defined-name-data.controller.ts index 59a9bbcd789..ac324cfa024 100644 --- a/packages/sheets/src/controllers/defined-name-data.controller.ts +++ b/packages/sheets/src/controllers/defined-name-data.controller.ts @@ -20,13 +20,13 @@ import { IResourceManagerService, UniverInstanceType, } from '@univerjs/core'; -import { IDefinedNamesService } from '@univerjs/engine-formula'; +import { DefinedNamesService } from '@univerjs/engine-formula'; const SHEET_DEFINED_NAME_PLUGIN = 'SHEET_DEFINED_NAME_PLUGIN'; export class DefinedNameDataController extends Disposable { constructor( - @IDefinedNamesService private readonly _definedNamesService: IDefinedNamesService, + @Inject(DefinedNamesService) private readonly _definedNamesService: DefinedNamesService, @IResourceManagerService private _resourceManagerService: IResourceManagerService ) { super();