Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(uni): use uni formula controller to regiter commands
Wenzhao Hud2ba71e9e9be
diff --git a/packages-experimental/uni-formula/src/controller/uni-formula.controller.ts b/packages-experimental/uni-formula/src/controller/uni-formula.controller.tsnew file mode 100644index 0000000000..bf8d85bb13--- /dev/null+++ b/packages-experimental/uni-formula/src/controller/uni-formula.controller.ts@@ -0,0 +1,34 @@+/**+ * 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.+ */++import { ICommandService } from '@univerjs/core';+import { AddDocUniFormulaMutation, RemoveDocUniFormulaMutation, UpdateDocUniFormulaMutation } from '../commands/mutation';++export class UniFormulaController {+ constructor(+ @ICommandService private readonly _commandSrv: ICommandService+ ) {+ this._initCommands();+ }++ private _initCommands(): void {+ [+ AddDocUniFormulaMutation,+ UpdateDocUniFormulaMutation,+ RemoveDocUniFormulaMutation,+ ].forEach((command) => this._commandSrv.registerCommand(command));+ }+}diff --git a/packages-experimental/uni-formula/src/services/uni-formula.service.ts b/packages-experimental/uni-formula/src/services/uni-formula.service.tsindex 05b85011ef..ba67573152 100644--- a/packages-experimental/uni-formula/src/services/uni-formula.service.ts+++ b/packages-experimental/uni-formula/src/services/uni-formula.service.ts@@ -26,7 +26,6 @@ import {import { type IDocFormulaCache, type IDocFormulaData, type IDocFormulaReference, toJson } from '../models/doc-formula';import { DOC_FORMULA_PLUGIN_NAME } from '../const';-import { AddDocUniFormulaMutation, RemoveDocUniFormulaMutation, UpdateDocUniFormulaMutation } from '../commands/mutation';export interface IUniFormulaService {getFormulaWithRangeId(unitId: string, rangeId: string): Nullable<IDocFormulaReference>;@@ -48,7 +47,6 @@ export class DumbUniFormulaService implements IUniFormulaService {@ICommandService protected readonly _commandSrv: ICommandService,@IUniverInstanceService protected readonly _instanceSrv: IUniverInstanceService) {- this._initCommands();this._initDocFormulaResources(resourceManagerService);this._instanceSrv.getTypeOfUnitDisposed$(UniverInstanceType.UNIVER_DOC).subscribe((doc) => {@@ -77,14 +75,6 @@ export class DumbUniFormulaService implements IUniFormulaService {return true;}- private _initCommands(): void {- [- AddDocUniFormulaMutation,- UpdateDocUniFormulaMutation,- RemoveDocUniFormulaMutation,- ].forEach((command) => this._commandSrv.registerCommand(command));- }-/*** Remove all formulas under a doc.*/diff --git a/packages-experimental/uni-formula/src/uni-formula.plugin.ts b/packages-experimental/uni-formula/src/uni-formula.plugin.tsindex 01cfb1eab0..f14cff9317 100644--- a/packages-experimental/uni-formula/src/uni-formula.plugin.ts+++ b/packages-experimental/uni-formula/src/uni-formula.plugin.ts@@ -18,6 +18,7 @@ import type { Dependency } from '@univerjs/core';import { Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';import { DumbUniFormulaService, IUniFormulaService } from './services/uni-formula.service';import { DOC_FORMULA_PLUGIN_NAME } from './const';+import { UniFormulaController } from './controller/uni-formula.controller';export class UniverDocUniFormulaPlugin extends Plugin {static override pluginName: string = DOC_FORMULA_PLUGIN_NAME;@@ -33,6 +34,9 @@ export class UniverDocUniFormulaPlugin extends Plugin {}override onStarting(): void {+ this._injector.add([UniFormulaController]);+ this._injector.get(UniFormulaController);+if (this._config?.playDumb) {this._injector.add([IUniFormulaService, { useClass: DumbUniFormulaService }] as Dependency);this._injector.get(IUniFormulaService);