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
refactor: make uni formula abstract (#2948)
Wenzhao Hu4e11f313802f
diff --git a/packages-experimental/uni-formula-ui/package.json b/packages-experimental/uni-formula-ui/package.jsonindex a17b2552f8..25215cae82 100644--- a/packages-experimental/uni-formula-ui/package.json+++ b/packages-experimental/uni-formula-ui/package.json@@ -63,6 +63,7 @@"@univerjs/docs": "workspace:*","@univerjs/docs-ui": "workspace:*","@univerjs/icons": "^0.1.72",+ "@univerjs/rpc": "workspace:*","@univerjs/sheets-formula": "workspace:*","@univerjs/ui": "workspace:*","@univerjs/uni-formula": "workspace:*",@@ -76,6 +77,7 @@"@univerjs/docs": "workspace:*","@univerjs/docs-ui": "workspace:*","@univerjs/icons": "^0.1.72",+ "@univerjs/rpc": "workspace:*","@univerjs/shared": "workspace:*","@univerjs/sheets-formula": "workspace:*","@univerjs/ui": "workspace:*",diff --git a/packages-experimental/uni-formula-ui/src/index.ts b/packages-experimental/uni-formula-ui/src/index.tsindex 64ff0daf1c..ab953e95da 100644--- a/packages-experimental/uni-formula-ui/src/index.ts+++ b/packages-experimental/uni-formula-ui/src/index.ts@@ -15,3 +15,4 @@*/export { UniverDocUniFormulaUIPlugin } from './uni-formula-ui.plugin';+export { UniFormulaService } from './services/uni-formula.service';diff --git a/packages-experimental/uni-formula-ui/src/services/formula-popup.service.ts b/packages-experimental/uni-formula-ui/src/services/formula-popup.service.tsindex 67ac92afb2..2bf7639329 100644--- a/packages-experimental/uni-formula-ui/src/services/formula-popup.service.ts+++ b/packages-experimental/uni-formula-ui/src/services/formula-popup.service.ts@@ -22,7 +22,7 @@ import { BehaviorSubject, Subject } from 'rxjs';import type { IShortcutItem } from '@univerjs/ui';import { IShortcutService, KeyCode } from '@univerjs/ui';import { FORMULA_PROMPT_ACTIVATED } from '@univerjs/sheets-formula';-import { UniFormulaService } from '@univerjs/uni-formula';+import { IUniFormulaService } from '@univerjs/uni-formula';import type { IAddDocUniFormulaCommandParams } from '../commands/command';import { AddDocUniFormulaCommand } from '../commands/command';import { ConfirmFormulaPopupCommand } from '../commands/operation';@@ -57,7 +57,7 @@ export class DocFormulaPopupService extends Disposable {constructor(@Inject(DocCanvasPopManagerService) private readonly _docCanvasPopupManagerService: DocCanvasPopManagerService,- @Inject(UniFormulaService) private readonly _uniFormulaService: UniFormulaService,+ @IUniFormulaService private readonly _uniFormulaService: IUniFormulaService,@IContextService private readonly _contextService: IContextService,@ILogService private readonly _logService: ILogService,@ICommandService private readonly _commandService: ICommandService,diff --git a/packages-experimental/uni-formula-ui/src/services/uni-formula.service.ts b/packages-experimental/uni-formula-ui/src/services/uni-formula.service.tsnew file mode 100644index 0000000000..7de8ce41df--- /dev/null+++ b/packages-experimental/uni-formula-ui/src/services/uni-formula.service.ts@@ -0,0 +1,194 @@+/**+ * 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 type {+ ICellData,+ IDisposable,+ Nullable } from '@univerjs/core';+import {+ ICommandService,+ Inject,+ IResourceManagerService,+ IUniverInstanceService,+ LifecycleStages,+ OnLifecycle,+ Optional,+ RCDisposable,+ toDisposable,+} from '@univerjs/core';+import { DataSyncPrimaryController } from '@univerjs/rpc';+import { RegisterOtherFormulaService } from '@univerjs/sheets-formula';+import type {+ IDocFormulaCache,+ IDocFormulaReference,+ IUniFormulaService,+ IUpdateDocUniFormulaCacheMutationParams } from '@univerjs/uni-formula';+import {+ DumbUniFormulaService,+ UpdateDocUniFormulaCacheMutation,+} from '@univerjs/uni-formula';++const DOC_PSEUDO_SUBUNIT = 'DOC_PSEUDO_SUBUNIT';++/**+ * This service provides methods for docs and slides to register a formula into Univer's formula system.+ * And it also manages formula resources fields of docs and slides. `SHEETS_FORMULA_REMOTE_PLUGIN`+ * is not required but optional here.+ */+@OnLifecycle(LifecycleStages.Steady, UniFormulaService)+export class UniFormulaService extends DumbUniFormulaService implements IUniFormulaService {+ private readonly _formulaIdToKey = new Map<string, string>();++ constructor(+ @IResourceManagerService resourceManagerService: IResourceManagerService,+ @ICommandService _commandSrv: ICommandService,+ @IUniverInstanceService _instanceSrv: IUniverInstanceService,+ @Inject(RegisterOtherFormulaService) private readonly _registerOtherFormulaSrv: RegisterOtherFormulaService,+ @Optional(DataSyncPrimaryController) private readonly _dataSyncPrimaryController?: DataSyncPrimaryController+ ) {+ super(resourceManagerService, _commandSrv, _instanceSrv);+ }++ getFormulaWithRangeId(unitId: string, rangeId: string): Nullable<IDocFormulaReference> {+ return this._docFormulas.get(getDocFormulaKey(unitId, rangeId)) ?? null;+ }++ /**+ * Register a doc formula into the formula system.+ */+ override registerDocFormula(unitId: string, rangeId: string, f: string, v: ICellData['v'], t: ICellData['t']): IDisposable {+ const key = getDocFormulaKey(unitId, rangeId);+ if (this._docFormulas.has(key)) {+ throw new Error(`[UniFormulaService]: cannot register formula ${key} when it is already registered!`);+ }++ const pseudoId = getPseudoUnitKey(unitId);+ this._checkSyncingUnit(pseudoId);+ this._checkResultSubscription();++ const id = this._registerOtherFormulaSrv.registerFormula(pseudoId, DOC_PSEUDO_SUBUNIT, f);+ this._docFormulas.set(key, { unitId, rangeId, f, formulaId: id, v, t });+ this._formulaIdToKey.set(id, key);++ return toDisposable(() => this.unregisterDocFormula(unitId, rangeId));+ }++ override unregisterDocFormula(unitId: string, rangeId: string): void {+ const key = getDocFormulaKey(unitId, rangeId);+ const item = this._docFormulas.get(key);+ if (!item) {+ return;+ }++ const pseudoId = getPseudoUnitKey(unitId);+ this._checkDisposingResultSubscription();+ this._dataSyncDisposables.get(pseudoId)?.dec();++ this._registerOtherFormulaSrv.deleteFormula(pseudoId, DOC_PSEUDO_SUBUNIT, [item.formulaId]);+ this._docFormulas.delete(key);+ this._formulaIdToKey.delete(item.formulaId);+ }++ hasFocFormula(unitId: string, formulaId: string): boolean {+ return this._docFormulas.has(getDocFormulaKey(unitId, formulaId));+ }++ updateFormulaResults(unitId: string, formulaIds: string[], v: IDocFormulaCache[]): boolean {+ formulaIds.forEach((id, index) => {+ const formulaData = this._docFormulas.get(getDocFormulaKey(unitId, id));+ if (!formulaData) return true;++ formulaData.v = v[index].v;+ formulaData.t = v[index].t;+ return true;+ });++ return true;+ }++ private _dataSyncDisposables = new Map<string, RCDisposable>();+ private _checkSyncingUnit(unitId: string): void {+ if (!this._dataSyncPrimaryController) return;++ if (!this._dataSyncDisposables.has(unitId)) {+ this._dataSyncPrimaryController.syncUnit(unitId);+ this._dataSyncDisposables.set(unitId, new RCDisposable(toDisposable(() => this._dataSyncDisposables.delete(unitId))));+ }++ this._dataSyncDisposables.get(unitId)!.inc();+ }++ private _resultSubscription: Nullable<IDisposable>;+ private _checkResultSubscription(): void {+ if (this._resultSubscription || !this._registerOtherFormulaSrv) return;++ this._resultSubscription = toDisposable(this._registerOtherFormulaSrv.formulaResult$.subscribe((resultMap) => {+ for (const resultOfUnit in resultMap) {+ const results = resultMap[resultOfUnit][DOC_PSEUDO_SUBUNIT];+ if (results) {+ const mutationParam = results.map((result) => {+ const formulaId = result.formulaId;+ const key = this._formulaIdToKey.get(formulaId);+ if (!key) return null;++ const item = this._docFormulas.get(key);+ if (!item) return null;++ const r = result.result?.[0][0];+ if (item.v === r?.v && item.t === r?.t) return null;++ return { id: item.rangeId, unitId: item.unitId, cache: r };+ }).reduce((previous, curr) => {+ if (!curr || !curr.cache) return previous;++ if (!previous.unitId) previous.unitId = curr.unitId;+ previous.ids.push(curr.id);+ previous.cache.push(curr.cache);++ return previous;+ }, {+ unitId: '',+ ids: [] as string[],+ cache: [] as Pick<ICellData, 'v' | 't'>[],+ });++ if (mutationParam.ids.length === 0) return;++ this._commandSrv.executeCommand(UpdateDocUniFormulaCacheMutation.id, mutationParam as IUpdateDocUniFormulaCacheMutationParams);+ }+ }+ }));+ }++ private _checkDisposingResultSubscription(): void {+ if (this._docFormulas.size === 0) this._disposeResultSubscription();+ }++ private _disposeResultSubscription(): void {+ if (this._resultSubscription) {+ this._resultSubscription.dispose();+ this._resultSubscription = null;+ }+ }+}++function getPseudoUnitKey(unitId: string): string {+ return `pseudo-${unitId}`;+}++function getDocFormulaKey(unitId: string, formulaId: string): string {+ return `pseudo-${unitId}-${formulaId}`;+}diff --git a/packages-experimental/uni-formula-ui/src/uni-formula-ui.plugin.ts b/packages-experimental/uni-formula-ui/src/uni-formula-ui.plugin.tsindex 3f1cefccec..de26e0cf72 100644--- a/packages-experimental/uni-formula-ui/src/uni-formula-ui.plugin.ts+++ b/packages-experimental/uni-formula-ui/src/uni-formula-ui.plugin.ts@@ -16,10 +16,12 @@import type { Dependency } from '@univerjs/core';import { DependentOn, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';-import { UniverDocUniFormulaPlugin } from '@univerjs/uni-formula';+import { IUniFormulaService, UniverDocUniFormulaPlugin } from '@univerjs/uni-formula';+import { DOC_FORMULA_UI_PLUGIN_NAME } from './const';import { DocFormulaPopupService } from './services/formula-popup.service';import { DocUniFormulaController } from './controllers/formula-input.controller';+import { UniFormulaService } from './services/uni-formula.service';@DependentOn(UniverDocUniFormulaPlugin)export class UniverDocUniFormulaUIPlugin extends Plugin {@@ -37,6 +39,7 @@ export class UniverDocUniFormulaUIPlugin extends Plugin {([[DocUniFormulaController],[DocFormulaPopupService],+ [IUniFormulaService, { useClass: UniFormulaService }],] as Dependency[]).forEach((d) => injector.add(d));}}diff --git a/packages-experimental/uni-formula/package.json b/packages-experimental/uni-formula/package.jsonindex ca7e9a9c9c..5013503345 100644--- a/packages-experimental/uni-formula/package.json+++ b/packages-experimental/uni-formula/package.json@@ -61,9 +61,7 @@},"peerDependencies": {"@univerjs/core": "workspace:*",- "@univerjs/docs": "workspace:*",- "@univerjs/rpc": "workspace:*",- "@univerjs/sheets-formula": "workspace:*"+ "@univerjs/docs": "workspace:*"},"dependencies": {"@univerjs/icons": "^0.1.72"@@ -71,10 +69,7 @@"devDependencies": {"@univerjs/core": "workspace:*","@univerjs/docs": "workspace:*",- "@univerjs/rpc": "workspace:*","@univerjs/shared": "workspace:*",- "@univerjs/sheets-formula": "workspace:*",- "@univerjs/ui": "workspace:*","clsx": "^2.1.1","rxjs": "^7.8.1","typescript": "^5.5.4",diff --git a/packages-experimental/uni-formula/src/commands/mutation.ts b/packages-experimental/uni-formula/src/commands/mutation.tsindex 2678fc9546..d8b15e86fb 100644--- a/packages-experimental/uni-formula/src/commands/mutation.ts+++ b/packages-experimental/uni-formula/src/commands/mutation.ts@@ -16,7 +16,8 @@import type { IMutation } from '@univerjs/core';import { CommandType } from '@univerjs/core';-import { UniFormulaService } from '../services/uni-formula.service';++import { IUniFormulaService } from '../services/uni-formula.service';export interface IAddDocUniFormulaMutationParams {unitId: string;@@ -32,7 +33,7 @@ export const AddDocUniFormulaMutation: IMutation<IAddDocUniFormulaMutationParamsid: 'doc.mutation.add-doc-uni-formula',handler(accessor, params: IAddDocUniFormulaMutationParams) {const { unitId, f, rangeId: id } = params;- const uniFormulaService = accessor.get(UniFormulaService);+ const uniFormulaService = accessor.get(IUniFormulaService);uniFormulaService.registerDocFormula(unitId, id, f);@@ -48,7 +49,7 @@ export const UpdateDocUniFormulaMutation: IMutation<IUpdateDocUniFormulaMutationid: 'doc.mutation.update-doc-uni-formula',handler(accessor, params: IUpdateDocUniFormulaMutationParams) {const { unitId, f, rangeId: id } = params;- const uniFormulaService = accessor.get(UniFormulaService);+ const uniFormulaService = accessor.get(IUniFormulaService);if (!uniFormulaService.hasFocFormula(unitId, id)) return false;@@ -68,7 +69,7 @@ export const RemoveDocUniFormulaMutation: IMutation<IRemoveDocUniFormulaMutationid: 'doc.mutation.remove-doc-uni-formula',handler(accessor, params: IRemoveDocUniFormulaMutationParams) {const { unitId, rangeId: id } = params;- const uniFormulaService = accessor.get(UniFormulaService);+ const uniFormulaService = accessor.get(IUniFormulaService);if (!uniFormulaService.hasFocFormula(unitId, id)) {return false;diff --git a/packages-experimental/uni-formula/src/index.ts b/packages-experimental/uni-formula/src/index.tsindex cefdb3cc95..57975245ed 100644--- a/packages-experimental/uni-formula/src/index.ts+++ b/packages-experimental/uni-formula/src/index.ts@@ -15,8 +15,9 @@*/export { UniverDocUniFormulaPlugin } from './uni-formula.plugin';-export { UniFormulaService, type IUpdateDocUniFormulaCacheMutationParams } from './services/uni-formula.service';+export { IUniFormulaService, DumbUniFormulaService, UpdateDocUniFormulaCacheMutation, type IUpdateDocUniFormulaCacheMutationParams } from './services/uni-formula.service';export { DOC_FORMULA_PLUGIN_NAME } from './const';+export { type IDocFormulaCache, type IDocFormulaData, type IDocFormulaReference } from './models/doc-formula';// #region - all commandsdiff --git a/packages-experimental/uni-formula/src/services/uni-formula.service.ts b/packages-experimental/uni-formula/src/services/uni-formula.service.tsindex b782ee5747..4a21ccda06 100644--- a/packages-experimental/uni-formula/src/services/uni-formula.service.ts+++ b/packages-experimental/uni-formula/src/services/uni-formula.service.ts@@ -14,21 +14,15 @@* limitations under the License.*/-import { DataSyncPrimaryController } from '@univerjs/rpc';-import { RegisterOtherFormulaService } from '@univerjs/sheets-formula';import type { DocumentDataModel, ICellData, IDisposable, IDocumentBody, IMutation, Nullable } from '@univerjs/core';import {CommandType,+ createIdentifier,CustomRangeType,- Disposable,ICommandService,IResourceManagerService,IUniverInstanceService,- LifecycleStages,makeCustomRangeStream,- OnLifecycle,- Optional,- RCDisposable,toDisposable,UniverInstanceType,} from '@univerjs/core';@@ -38,8 +32,6 @@ import { type IDocFormulaCache, type IDocFormulaData, type IDocFormulaReference,import { DOC_FORMULA_PLUGIN_NAME } from '../const';import { AddDocUniFormulaMutation, RemoveDocUniFormulaMutation, UpdateDocUniFormulaMutation } from '../commands/mutation';-const DOC_PSEUDO_SUBUNIT = 'DOC_PSEUDO_SUBUNIT';-/*** Update calculating result in a batch.*/@@ -64,7 +56,7 @@ export const UpdateDocUniFormulaCacheMutation: IMutation<IUpdateDocUniFormulaCachandler(accessor, params: IUpdateDocUniFormulaCacheMutationParams) {const { unitId, ids, cache } = params;- const uniFormulaService = accessor.get(UniFormulaService);+ const uniFormulaService = accessor.get(IUniFormulaService);const instanceService = accessor.get(IUniverInstanceService);const commandService = accessor.get(ICommandService);@@ -112,26 +104,26 @@ export const UpdateDocUniFormulaCacheMutation: IMutation<IUpdateDocUniFormulaCac},};-/**- * This service provides methods for docs and slides to register a formula into Univer's formula system.- * And it also manages formula resources fields of docs and slides. `SHEETS_FORMULA_REMOTE_PLUGIN`- * is not required but optional here.- */-@OnLifecycle(LifecycleStages.Steady, UniFormulaService)-export class UniFormulaService extends Disposable {+export interface IUniFormulaService {+ getFormulaWithRangeId(unitId: string, rangeId: string): Nullable<IDocFormulaReference>;+ registerDocFormula(unitId: string, rangeId: string, f: string, v: ICellData['v'], t: ICellData['t']): IDisposable;++ unregisterDocFormula(unitId: string, rangeId: string): void;+ hasFocFormula(unitId: string, formulaId: string): boolean;+ updateFormulaResults(unitId: string, formulaIds: string[], v: IDocFormulaCache[]): boolean;+}++export const IUniFormulaService = createIdentifier<IUniFormulaService>('uni-formula.uni-formula.service');++export class DumbUniFormulaService {/** This data maps doc formula key to the formula id in the formula system. */- private readonly _docFormulas = new Map<string, IDocFormulaReference>();- private readonly _formulaIdToKey = new Map<string, string>();+ protected readonly _docFormulas = new Map<string, IDocFormulaReference>();constructor(@IResourceManagerService resourceManagerService: IResourceManagerService,- @ICommandService private readonly _commandSrv: ICommandService,- @IUniverInstanceService private readonly _instanceSrv: IUniverInstanceService,- @Optional(RegisterOtherFormulaService) private readonly _registerOtherFormulaSrv?: RegisterOtherFormulaService,- @Optional(DataSyncPrimaryController) private readonly _dataSyncPrimaryController?: DataSyncPrimaryController+ @ICommandService protected readonly _commandSrv: ICommandService,+ @IUniverInstanceService protected readonly _instanceSrv: IUniverInstanceService) {- super();-this._initCommands();this._initDocFormulaResources(resourceManagerService);@@ -159,10 +151,6 @@ export class UniFormulaService extends Disposable {});}- getFormulaWithRangeId(unitId: string, rangeId: string): Nullable<IDocFormulaReference> {- return this._docFormulas.get(getDocFormulaKey(unitId, rangeId)) ?? null;- }-/*** Register a doc formula into the formula system.*/@@ -172,17 +160,7 @@ export class UniFormulaService extends Disposable {throw new Error(`[UniFormulaService]: cannot register formula ${key} when it is already registered!`);}- if (this._registerOtherFormulaSrv) {- const pseudoId = getPseudoUnitKey(unitId);- this._checkSyncingUnit(pseudoId);- this._checkResultSubscription();-- const id = this._registerOtherFormulaSrv.registerFormula(pseudoId, DOC_PSEUDO_SUBUNIT, f);- this._docFormulas.set(key, { unitId, rangeId, f, formulaId: id, v, t });- this._formulaIdToKey.set(id, key);- } else {- this._docFormulas.set(key, { unitId, rangeId, f, formulaId: '', v, t });- }+ this._docFormulas.set(key, { unitId, rangeId, f, formulaId: '', v, t });return toDisposable(() => this.unregisterDocFormula(unitId, rangeId));}@@ -190,100 +168,8 @@ export class UniFormulaService extends Disposable {unregisterDocFormula(unitId: string, rangeId: string): void {const key = getDocFormulaKey(unitId, rangeId);const item = this._docFormulas.get(key);- if (!item) {- return;- }-- const pseudoId = getPseudoUnitKey(unitId);- this._checkDisposingResultSubscription();- this._dataSyncDisposables.get(pseudoId)?.dec();-- if (this._registerOtherFormulaSrv) {- this._registerOtherFormulaSrv.deleteFormula(pseudoId, DOC_PSEUDO_SUBUNIT, [item.formulaId]);+ if (item) {this._docFormulas.delete(key);- this._formulaIdToKey.delete(item.formulaId);- }- }-- hasFocFormula(unitId: string, formulaId: string): boolean {- return this._docFormulas.has(getDocFormulaKey(unitId, formulaId));- }-- updateFormulaResults(unitId: string, formulaIds: string[], v: IDocFormulaCache[]): boolean {- formulaIds.forEach((id, index) => {- const formulaData = this._docFormulas.get(getDocFormulaKey(unitId, id));- if (!formulaData) return true;-- formulaData.v = v[index].v;- formulaData.t = v[index].t;- return true;- });-- return true;- }-- private _dataSyncDisposables = new Map<string, RCDisposable>();- private _checkSyncingUnit(unitId: string): void {- if (!this._dataSyncPrimaryController) return;-- if (!this._dataSyncDisposables.has(unitId)) {- this._dataSyncPrimaryController.syncUnit(unitId);- this._dataSyncDisposables.set(unitId, new RCDisposable(toDisposable(() => this._dataSyncDisposables.delete(unitId))));- }-- this._dataSyncDisposables.get(unitId)!.inc();- }-- private _resultSubscription: Nullable<IDisposable>;- private _checkResultSubscription(): void {- if (this._resultSubscription || !this._registerOtherFormulaSrv) return;-- this._resultSubscription = toDisposable(this._registerOtherFormulaSrv.formulaResult$.subscribe((resultMap) => {- for (const resultOfUnit in resultMap) {- const results = resultMap[resultOfUnit][DOC_PSEUDO_SUBUNIT];- if (results) {- const mutationParam = results.map((result) => {- const formulaId = result.formulaId;- const key = this._formulaIdToKey.get(formulaId);- if (!key) return null;-- const item = this._docFormulas.get(key);- if (!item) return null;-- const r = result.result?.[0][0];- if (item.v === r?.v && item.t === r?.t) return null;-- return { id: item.rangeId, unitId: item.unitId, cache: r };- }).reduce((previous, curr) => {- if (!curr || !curr.cache) return previous;-- if (!previous.unitId) previous.unitId = curr.unitId;- previous.ids.push(curr.id);- previous.cache.push(curr.cache);-- return previous;- }, {- unitId: '',- ids: [] as string[],- cache: [] as Pick<ICellData, 'v' | 't'>[],- });-- if (mutationParam.ids.length === 0) return;-- this._commandSrv.executeCommand(UpdateDocUniFormulaCacheMutation.id, mutationParam as IUpdateDocUniFormulaCacheMutationParams);- }- }- }));- }-- private _checkDisposingResultSubscription(): void {- if (this._docFormulas.size === 0) this._disposeResultSubscription();- }-- private _disposeResultSubscription(): void {- if (this._resultSubscription) {- this._resultSubscription.dispose();- this._resultSubscription = null;}}@@ -314,10 +200,10 @@ export class UniFormulaService extends Disposable {}}-function getPseudoUnitKey(unitId: string): string {+export function getPseudoUnitKey(unitId: string): string {return `pseudo-${unitId}`;}-function getDocFormulaKey(unitId: string, formulaId: string): string {+export function getDocFormulaKey(unitId: string, formulaId: string): string {return `pseudo-${unitId}-${formulaId}`;}diff --git a/packages-experimental/uni-formula/src/uni-formula.plugin.ts b/packages-experimental/uni-formula/src/uni-formula.plugin.tsindex 07b2ec1da0..360c038351 100644--- a/packages-experimental/uni-formula/src/uni-formula.plugin.ts+++ b/packages-experimental/uni-formula/src/uni-formula.plugin.ts@@ -14,8 +14,9 @@* limitations under the License.*/+import type { Dependency } from '@univerjs/core';import { Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';-import { UniFormulaService } from './services/uni-formula.service';+import { DumbUniFormulaService, IUniFormulaService } from './services/uni-formula.service';import { DOC_FORMULA_PLUGIN_NAME } from './const';export class UniverDocUniFormulaPlugin extends Plugin {@@ -25,13 +26,21 @@ export class UniverDocUniFormulaPlugin extends Plugin {static override type: UniverInstanceType = UniverInstanceType.UNIVER_SHEET;constructor(- _config: unknown,+ private readonly _config: { playDumb: boolean } | undefined,@Inject(Injector) protected readonly _injector: Injector) {super();}override onStarting(): void {- this._injector.add([UniFormulaService]);+ if (this._config?.playDumb) {+ this._injector.add([IUniFormulaService, { useClass: DumbUniFormulaService }] as Dependency);+ }+ }++ override onReady(): void {+ if (this._config?.playDumb) {+ this._injector.get(IUniFormulaService);+ }}}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 0abcf02a76..359e4ddfce 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -459,18 +459,9 @@ importers:'@univerjs/docs':specifier: workspace:*version: link:../../packages/docs- '@univerjs/rpc':- specifier: workspace:*- version: link:../../packages/rpc'@univerjs/shared':specifier: workspace:*version: link:../../common/shared- '@univerjs/sheets-formula':- specifier: workspace:*- version: link:../../packages/sheets-formula- '@univerjs/ui':- specifier: workspace:*- version: link:../../packages/uiclsx:specifier: ^2.1.1version: 2.1.1@@ -508,6 +499,9 @@ importers:'@univerjs/icons':specifier: ^0.1.72+ '@univerjs/rpc':+ specifier: workspace:*+ version: link:../../packages/rpc'@univerjs/shared':specifier: workspace:*version: link:../../common/shared