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: fix formula input controller startup too early (#540)
Wenzhao Hu4ba1e36f83b0
diff --git a/examples/univer-sheet-ts/src/main.tsx b/examples/univer-sheet-ts/src/main.tsxindex 6d30d51b6d..09afd7557f 100644--- a/examples/univer-sheet-ts/src/main.tsx+++ b/examples/univer-sheet-ts/src/main.tsx@@ -1,4 +1,4 @@-import { DocPlugin } from '@univerjs/base-docs';+import { DocPlugin, RichTextEditingMutation } from '@univerjs/base-docs';import { BaseFormulaEnginePlugin } from '@univerjs/base-formula-engine';import { RenderEngine } from '@univerjs/base-render';import { SheetPlugin } from '@univerjs/base-sheets';@@ -7,12 +7,8 @@ import { DEFAULT_WORKBOOK_DATA_DEMO } from '@univerjs/common-plugin-data';import { LocaleType, Univer } from '@univerjs/core';import { greenTheme } from '@univerjs/design';import { IUniverRPCMainThreadPluginConfig, UniverRPCMainThreadPlugin } from '@univerjs/rpc';-// import { FindPlugin } from '@univerjs/sheets-plugin-find';import { FormulaPlugin } from '@univerjs/sheets-plugin-formula';import { FormulaUIPlugin } from '@univerjs/sheets-plugin-formula-ui';-// import { ImagePlugin } from '@univerjs/sheets-plugin-image';-// import { ImportXlsxPlugin } from '@univerjs/sheets-plugin-import-xlsx';-// import { NumfmtPlugin } from '@univerjs/sheets-plugin-numfmt';import { SheetUIPlugin } from '@univerjs/ui-plugin-sheets';import { locales } from './locales';@@ -42,8 +38,6 @@ univer.registerPlugin(SheetUIPlugin);// sheet feature pluginsuniver.registerPlugin(DebuggerPlugin);-// univer.registerPlugin(NumfmtPlugin);-// univer.registerPlugin(FindPlugin);univer.registerPlugin(BaseFormulaEnginePlugin);univer.registerPlugin(FormulaPlugin, {notExecuteFormula: true,@@ -51,9 +45,8 @@ univer.registerPlugin(FormulaPlugin, {univer.registerPlugin(FormulaUIPlugin);univer.registerPlugin(UniverRPCMainThreadPlugin, {workerURL: './worker.js',+ unsyncMutations: new Set([RichTextEditingMutation.id]),} as IUniverRPCMainThreadPluginConfig);-// univer.registerPlugin(ImportXlsxPlugin);-// univer.registerPlugin(ImagePlugin);// create univer sheet instanceuniver.createUniverSheet(DEFAULT_WORKBOOK_DATA_DEMO);diff --git a/packages/rpc/src/controllers/data-sync/data-sync-primary.controller.ts b/packages/rpc/src/controllers/data-sync/data-sync-primary.controller.tsindex 8b8d9bb788..8817b56d59 100644--- a/packages/rpc/src/controllers/data-sync/data-sync-primary.controller.ts+++ b/packages/rpc/src/controllers/data-sync/data-sync-primary.controller.ts@@ -22,6 +22,7 @@ import {@OnLifecycle(LifecycleStages.Starting, DataSyncPrimaryController)export class DataSyncPrimaryController extends RxDisposable {constructor(+ private readonly _unsyncMutations: Set<string>,@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,@IRemoteInstanceService private readonly _remoteInstanceService: IRemoteInstanceService,@ICommandService private readonly _commandService: ICommandService@@ -51,7 +52,11 @@ export class DataSyncPrimaryController extends RxDisposable {this.disposeWithMe(// Mutations executed on the main thread should be synced to the worker thread.this._commandService.onCommandExecuted((commandInfo, options) => {- if (commandInfo.type === CommandType.MUTATION && !(options as IRemoteSyncMutationOptions)?.fromSync) {+ if (+ commandInfo.type === CommandType.MUTATION &&+ !(options as IRemoteSyncMutationOptions)?.fromSync &&+ !this._unsyncMutations.has(commandInfo.id)+ ) {this._remoteInstanceService.syncMutation({mutationInfo: commandInfo as IMutationInfo,});diff --git a/packages/rpc/src/plugin.ts b/packages/rpc/src/plugin.tsindex 85c624ee17..fa3a44f01a 100644--- a/packages/rpc/src/plugin.ts+++ b/packages/rpc/src/plugin.ts@@ -19,6 +19,7 @@ import { ChannelClient, ChannelServer, fromModule, toModule } from './services/rexport interface IUniverRPCMainThreadPluginConfig {workerURL: string | URL;+ unsyncMutations?: Set<string>;}interface ITestService {@@ -47,7 +48,13 @@ export class UniverRPCMainThreadPlugin extends Plugin {const server = new ChannelServer(messageProtocol);const dependencies: Dependency[] = [- [DataSyncPrimaryController],+ [+ DataSyncPrimaryController,+ {+ useFactory: () =>+ injector.createInstance(DataSyncPrimaryController, this._config?.unsyncMutations ?? new Set()),+ },+ ],[IRemoteInstanceService,{ useFactory: () => toModule<IRemoteInstanceService>(client.getChannel(RemoteInstanceServiceName)) },diff --git a/packages/sheets-plugin-formula-ui/src/controllers/formula-input.controller.ts b/packages/sheets-plugin-formula-ui/src/controllers/formula-input.controller.tsindex 50470163c7..f2af6a194f 100644--- a/packages/sheets-plugin-formula-ui/src/controllers/formula-input.controller.ts+++ b/packages/sheets-plugin-formula-ui/src/controllers/formula-input.controller.ts@@ -34,7 +34,7 @@ import { IDescriptionService } from '../services/description.service';import { IFormulaInputService } from '../services/formula-input.service';import { IFormulaPromptService } from '../services/prompt.service';-@OnLifecycle(LifecycleStages.Ready, FormulaInputController)+@OnLifecycle(LifecycleStages.Steady, FormulaInputController)export class FormulaInputController extends Disposable {private _userCursorMove: boolean = false;