Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

refactor: refactor lifecycle services (#168)

Wenzhao Hu726b004dfb6b
diff --git a/cli/src/templates/base/src/SortPlugin.tsx b/cli/src/templates/base/src/SortPlugin.tsx
index 88eabfdf4b..eb24eee5a6 100644
--- a/cli/src/templates/base/src/SortPlugin.tsx
+++ b/cli/src/templates/base/src/SortPlugin.tsx
@@ -35,7 +35,7 @@ export class <%= projectUpperValue %>Plugin extends Plugin {
this._<%= projectValue %>Controller = new <%= projectUpperValue %>Controller(this);
}
- onMounted(): void {
+ onRendered(): void {
this.initialize()
}
diff --git a/cli/src/templates/common-plugin/src/SortPlugin.tsx b/cli/src/templates/common-plugin/src/SortPlugin.tsx
index b9edc4ae9d..b61dc93aef 100644
--- a/cli/src/templates/common-plugin/src/SortPlugin.tsx
+++ b/cli/src/templates/common-plugin/src/SortPlugin.tsx
@@ -36,7 +36,7 @@ export class <%= projectUpperValue %>Plugin extends Plugin {
}
- onMounted(): void {
+ onRendered(): void {
this.initialize()
}
diff --git a/cli/src/templates/docs-plugin/src/SortPlugin.tsx b/cli/src/templates/docs-plugin/src/SortPlugin.tsx
index 3e988342db..95c8a09ce9 100644
--- a/cli/src/templates/docs-plugin/src/SortPlugin.tsx
+++ b/cli/src/templates/docs-plugin/src/SortPlugin.tsx
@@ -35,7 +35,7 @@ export class <%= projectUpperValue %>Plugin extends Plugin<any, DocContext> {
this._<%= projectValue %>Controller = new <%= projectUpperValue %>Controller(this);
}
- onMounted(): void {
+ onRendered(): void {
this.initialize()
}
diff --git a/cli/src/templates/sheets-plugin/src/SortPlugin.tsx b/cli/src/templates/sheets-plugin/src/SortPlugin.tsx
index 6a45083695..5ccaefa41b 100644
--- a/cli/src/templates/sheets-plugin/src/SortPlugin.tsx
+++ b/cli/src/templates/sheets-plugin/src/SortPlugin.tsx
@@ -35,7 +35,7 @@ export class <%= projectUpperValue %>Plugin extends Plugin<any, SheetContext> {
this._<%= projectValue %>Controller = new <%= projectUpperValue %>Controller(this);
}
- onMounted(): void {
+ onRendered(): void {
this.initialize()
}
diff --git a/cli/src/templates/slides-plugin/src/SortPlugin.tsx b/cli/src/templates/slides-plugin/src/SortPlugin.tsx
index a30f4054cc..9a916feea6 100644
--- a/cli/src/templates/slides-plugin/src/SortPlugin.tsx
+++ b/cli/src/templates/slides-plugin/src/SortPlugin.tsx
@@ -35,7 +35,7 @@ export class <%= projectUpperValue %>Plugin extends Plugin<any, SlideContext> {
this._<%= projectValue %>Controller = new <%= projectUpperValue %>Controller(this);
}
- onMounted(): void {
+ onRendered(): void {
this.initialize()
}
diff --git a/docs/implementation-of-front-end-plug-in-architecture-in-univer-zh.md b/docs/implementation-of-front-end-plug-in-architecture-in-univer-zh.md
index 13044fb260..026a02e266 100644
--- a/docs/implementation-of-front-end-plug-in-architecture-in-univer-zh.md
+++ b/docs/implementation-of-front-end-plug-in-architecture-in-univer-zh.md
@@ -28,7 +28,7 @@ Luckysheet 2.0 很少用到设计模式,扩展性不好,模块拆分不够
首先我们在核心构造一个`Plugin`基类,将插件要用到基础属性和方法放在这里,比如插件名称,插件的生命周期。
-初始化即安装时调用 `onMounted` 方法,卸载时调用 `onDestroy` 方法。
+初始化即安装时调用 `onRendered` 方法,卸载时调用 `onDestroy` 方法。
> 为便于理解,以下部分代码经过简化,我们主要讲解下思路
@@ -44,7 +44,7 @@ export abstract class Plugin {
return this._name;
}
- onMounted(): void;
+ onRendered(): void;
onDestroy(): void;
@@ -61,7 +61,7 @@ export class SortPlugin extends Plugin {
}
// 初始化
- onMounted(): void {
+ onRendered(): void {
// 插件具体初始化逻辑
}
@@ -86,7 +86,7 @@ export class PluginManager {
_initialize(plugins: Plugin[]) {
plugins.forEach((plugin: Plugin) => {
- plugin.onMounted();
+ plugin.onRendered();
});
}
@@ -160,7 +160,7 @@ export abstract class Plugin {
return this._context;
}
- onMounted(ctx: SheetContext): void;
+ onRendered(ctx: SheetContext): void;
onDestroy(): void;
@@ -188,7 +188,7 @@ export abstract class Plugin<O = any> {
this._observeNames = [];
}
- onMounted(context: SheetContext): void {}
+ onRendered(context: SheetContext): void {}
onDestroy(): void {
this.deleteObserve(...this._observeNames);
diff --git a/packages/base-docs/package.json b/packages/base-docs/package.json
index 2aa9b81d47..3420d42688 100644
--- a/packages/base-docs/package.json
+++ b/packages/base-docs/package.json
@@ -42,7 +42,7 @@
"@univerjs/base-ui": "workspace:^0.0.1",
"@univerjs/common-plugin-data": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"css-vars-ponyfill": "^2.4.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
diff --git a/packages/base-docs/src/DocPlugin.ts b/packages/base-docs/src/DocPlugin.ts
index cf42873b40..5e965c49b7 100644
--- a/packages/base-docs/src/DocPlugin.ts
+++ b/packages/base-docs/src/DocPlugin.ts
@@ -180,7 +180,7 @@ export class DocPlugin extends Plugin<DocPluginObserve> {
return this._documentController;
}
- override onMounted(): void {
+ override onRendered(): void {
this.initialize();
}
diff --git a/packages/base-formula-engine/package.json b/packages/base-formula-engine/package.json
index e10ff2f9e0..1e9c8ff654 100644
--- a/packages/base-formula-engine/package.json
+++ b/packages/base-formula-engine/package.json
@@ -39,7 +39,7 @@
},
"dependencies": {
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
diff --git a/packages/base-formula-engine/src/FormulaEnginePlugin.ts b/packages/base-formula-engine/src/FormulaEnginePlugin.ts
index aa2696bf10..0d971995cd 100644
--- a/packages/base-formula-engine/src/FormulaEnginePlugin.ts
+++ b/packages/base-formula-engine/src/FormulaEnginePlugin.ts
@@ -12,7 +12,7 @@ export class FormulaEnginePlugin extends Plugin<FormulaEnginePluginObserver> {
initialize(): void {}
- override onMounted(ctx: SheetContext): void {
+ override onRendered(ctx: SheetContext): void {
this.initialize();
}
diff --git a/packages/base-render/package.json b/packages/base-render/package.json
index 5c87e66464..2278374867 100644
--- a/packages/base-render/package.json
+++ b/packages/base-render/package.json
@@ -44,7 +44,7 @@
"dependencies": {
"@ctrl/tinycolor": "^4.0.2",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rxjs": "^7.8.1"
diff --git a/packages/base-render/src/Custom/BlockPlugin.ts b/packages/base-render/src/Custom/BlockPlugin.ts
index 38c41b8c9d..3b4c01142c 100644
--- a/packages/base-render/src/Custom/BlockPlugin.ts
+++ b/packages/base-render/src/Custom/BlockPlugin.ts
@@ -19,7 +19,7 @@ export class BlockPlugin extends Plugin<BlockPluginObserve> {
return [];
}
- override onMounted(ctx: SheetContext): void {}
+ override onRendered(ctx: SheetContext): void {}
override onDestroy(): void {}
}
diff --git a/packages/base-render/src/Custom/BulletPlugin.ts b/packages/base-render/src/Custom/BulletPlugin.ts
index b44ff21b95..f7754d7e4c 100644
--- a/packages/base-render/src/Custom/BulletPlugin.ts
+++ b/packages/base-render/src/Custom/BulletPlugin.ts
@@ -10,7 +10,7 @@ export class BulletPlugin extends Plugin<BulletPluginObserve> {
return '';
}
- override onMounted(ctx: SheetContext): void {}
+ override onRendered(ctx: SheetContext): void {}
override onDestroy(): void {}
}
diff --git a/packages/base-sheets/package.json b/packages/base-sheets/package.json
index 954d61f7e1..be8591755d 100644
--- a/packages/base-sheets/package.json
+++ b/packages/base-sheets/package.json
@@ -43,7 +43,7 @@
"dependencies": {
"@univerjs/base-render": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rxjs": "^7.8.1"
diff --git a/packages/base-sheets/src/SheetPlugin.ts b/packages/base-sheets/src/SheetPlugin.ts
index 17afe18109..9b2990172f 100644
--- a/packages/base-sheets/src/SheetPlugin.ts
+++ b/packages/base-sheets/src/SheetPlugin.ts
@@ -11,7 +11,7 @@ import {
} from '@univerjs/core';
import { Dependency, Inject, Injector } from '@wendellhu/redi';
-import { DEFAULT_SPREADSHEET_PLUGIN_DATA, install, ISheetPluginConfig } from './Basics';
+import { DEFAULT_SPREADSHEET_PLUGIN_DATA, ISheetPluginConfig } from './Basics';
import { SheetPluginObserve, uninstall } from './Basics/Observer';
import { SetSelectionsOperation } from './Commands/Operations/selection.operation';
import { BasicWorkbookController, CountBarController, SheetContainerController } from './Controller';
@@ -56,7 +56,7 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
en,
});
- install(this);
+ // install(this);
this.initConfig();
this.initController();
@@ -94,10 +94,12 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
this._injector.get(BasicWorkbookController);
}
- override onMounted(): void {
+ override onStarting(): void {
this.initialize();
}
+ override onRendered(): void {}
+
override onDestroy(): void {
super.onDestroy();
diff --git a/packages/base-slides/package.json b/packages/base-slides/package.json
index 48f1612d7f..343f70fd9d 100644
--- a/packages/base-slides/package.json
+++ b/packages/base-slides/package.json
@@ -40,7 +40,7 @@
"@univerjs/base-render": "workspace:^0.0.1",
"@univerjs/base-ui": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"css-vars-ponyfill": "^2.4.6",
"react": "^18.2.0",
"react-dom": "^18.2.0"
diff --git a/packages/base-slides/src/SlidePlugin.ts b/packages/base-slides/src/SlidePlugin.ts
index 9eff4bd791..3594165f7d 100644
--- a/packages/base-slides/src/SlidePlugin.ts
+++ b/packages/base-slides/src/SlidePlugin.ts
@@ -60,7 +60,7 @@ export class SlidePlugin extends Plugin<SlidePluginObserve> {
this._canvasEngine = this._injector.get(IRenderingEngine);
}
- override onMounted(): void {
+ override onRendered(): void {
this.initialize();
}
diff --git a/packages/base-ui/package.json b/packages/base-ui/package.json
index 316c29310b..6e6b4e3386 100644
--- a/packages/base-ui/package.json
+++ b/packages/base-ui/package.json
@@ -44,7 +44,7 @@
"dependencies": {
"@univerjs/base-render": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"react": "^18.2.0",
"react-colorful": "^5.3.0",
"react-dom": "^18.2.0",
diff --git a/packages/base-ui/src/Components/Menu/Menu.tsx b/packages/base-ui/src/Components/Menu/Menu.tsx
index ade17eceff..1adc7c1d9b 100644
--- a/packages/base-ui/src/Components/Menu/Menu.tsx
+++ b/packages/base-ui/src/Components/Menu/Menu.tsx
@@ -347,7 +347,16 @@ import React, { useContext, useEffect, useRef, useState } from 'react';
import { Subscription } from 'rxjs';
import { AppContext } from '../../Common/AppContext';
-import { ICustomComponentOption, IDisplayMenuItem, IMenuButtonItem, IMenuItem, IMenuSelectorItem, isValueOptions, IValueOption, MenuItemType } from '../../services/menu/menu';
+import {
+ ICustomComponentOption,
+ IDisplayMenuItem,
+ IMenuButtonItem,
+ IMenuItem,
+ IMenuSelectorItem,
+ isValueOptions,
+ IValueOption,
+ MenuItemType,
+} from '../../services/menu/menu';
import { IMenuService } from '../../services/menu/menu.service';
import { joinClassNames } from '../../Utils';
import { CustomLabel, NeoCustomLabel } from '../CustomLabel/CustomLabel';
@@ -432,7 +441,21 @@ export type BaseMenuStyle = {
// }
export const Menu = (props: BaseMenuProps) => {
- const { display, menuId, value, options, onOptionSelect, parent, onClick, deep = 0, menu = [], className = '', style = {}, show = false, clientPosition } = props;
+ const {
+ display,
+ menuId,
+ value,
+ options,
+ onOptionSelect,
+ parent,
+ onClick,
+ deep = 0,
+ menu = [],
+ className = '',
+ style = {},
+ show = false,
+ clientPosition,
+ } = props;
const context = useContext(AppContext);
const [isShow, setIsShow] = useState(show);
const [posStyle, setPosStyle] = useState<BaseMenuStyle>({});
@@ -553,7 +576,11 @@ export const Menu = (props: BaseMenuProps) => {
};
return (
- <ul className={joinClassNames(styles.colsMenu, className)} style={{ ...style, ...posStyle, display: isShow ? 'block' : 'none' }} ref={MenuRef}>
+ <ul
+ className={joinClassNames(styles.colsMenu, className)}
+ style={{ ...style, ...posStyle, display: isShow ? 'block' : 'none' }}
+ ref={MenuRef}
+ >
{/* legacy: render selections */}
{options?.map((option: IValueOption | ICustomComponentOption, index: number) => {
const isValueOption = isValueOptions(option);
@@ -561,7 +588,10 @@ export const Menu = (props: BaseMenuProps) => {
return (
<li
key={index}
- className={joinClassNames(styles.colsMenuitem, option.disabled ? styles.colsMenuitemDisabled : '')}
+ className={joinClassNames(
+ styles.colsMenuitem,
+ option.disabled ? styles.colsMenuitemDisabled : ''
+ )}
onClick={() => {
if (option.value) {
onOptionSelect?.(option);
@@ -582,7 +612,13 @@ export const Menu = (props: BaseMenuProps) => {
const CustomComponent = context.componentManager?.get(option.id) as React.ComponentType<any>;
return (
- <li key={index} className={joinClassNames(styles.colsMenuitem, option.disabled ? styles.colsMenuitemDisabled : '')}>
+ <li
+ key={index}
+ className={joinClassNames(
+ styles.colsMenuitem,
+ option.disabled ? styles.colsMenuitemDisabled : ''
+ )}
+ >
<CustomComponent
onValueChange={(v: string | number) => {
onOptionSelect?.({ value: v, label: option.id });
@@ -719,7 +755,14 @@ export function MenuItem({ menuItem, index, onClick }: IMenuItemProps) {
onMouseLeave={(e) => mouseLeave(e, index)}
// onClick={(e) => handleClick(e, item, index)} // Nested select without click events, like border style
>
- <NeoCustomLabel title={item.title} value={value} onChange={onChange} icon={item.icon} display={item.display} label={item.label}></NeoCustomLabel>
+ <NeoCustomLabel
+ title={item.title}
+ value={value}
+ onChange={onChange}
+ icon={item.icon}
+ display={item.display}
+ label={item.label}
+ ></NeoCustomLabel>
{item.shortcut && ` (${item.shortcut})`}
{(menuItems.length > 0 || (item as IMenuSelectorItem<unknown>).selections?.length) && (
<Menu
@@ -749,9 +792,21 @@ export function MenuItem({ menuItem, index, onClick }: IMenuItemProps) {
onMouseLeave={(e) => mouseLeave(e, index)}
// onClick={(e) => handleClick(e, item, index)} // Nested menus without click events, like right menu delete cell
>
- <NeoCustomLabel title={item.title} value={item.title} icon={item.icon} display={item.display} label={item.label}></NeoCustomLabel>
+ <NeoCustomLabel
+ title={item.title}
+ value={item.title}
+ icon={item.icon}
+ display={item.display}
+ label={item.label}
+ ></NeoCustomLabel>
{(menuItems.length > 0 || (item as IMenuSelectorItem<unknown>).selections?.length) && (
- <Menu show={itemShow} menuId={item.id} display={item.display} parent={true} onOptionSelect={onClick}></Menu>
+ <Menu
+ show={itemShow}
+ menuId={item.id}
+ display={item.display}
+ parent={true}
+ onOptionSelect={onClick}
+ ></Menu>
)}
</li>
);
diff --git a/packages/base-ui/src/base-ui-plugin.ts b/packages/base-ui/src/base-ui-plugin.ts
index 9d1ff4837b..27aa5d1e90 100644
--- a/packages/base-ui/src/base-ui-plugin.ts
+++ b/packages/base-ui/src/base-ui-plugin.ts
@@ -32,9 +32,12 @@ export class UIPlugin extends Plugin {
this._injector = injector;
}
- override onMounted(): void {
+ override onStarting(): void {
this._initDependencies();
this._initModules();
+ }
+
+ override onReady(): void {
this._initUI();
}
diff --git a/packages/base-ui/src/controllers/ui/ui-desktop.controller.tsx b/packages/base-ui/src/controllers/ui/ui-desktop.controller.tsx
index 1bc127c66a..83950bc5ce 100644
--- a/packages/base-ui/src/controllers/ui/ui-desktop.controller.tsx
+++ b/packages/base-ui/src/controllers/ui/ui-desktop.controller.tsx
@@ -1,5 +1,5 @@
import { Engine, IRenderingEngine } from '@univerjs/base-render';
-import { Disposable, toDisposable } from '@univerjs/core';
+import { Disposable, LifecycleService, LifecycleStages, toDisposable } from '@univerjs/core';
import { IDisposable, Inject, Injector } from '@wendellhu/redi';
import { connectInjector } from '@wendellhu/redi/react-bindings';
import React, { ComponentType } from 'react';
@@ -26,12 +26,21 @@ export class DesktopUIController extends Disposable implements IDesktopUIControl
componentRegistered$ = this._componentRegistered$.asObservable();
- constructor(@Inject(Injector) private readonly _injector: Injector, @IRenderingEngine private readonly _renderingEngine: Engine) {
+ constructor(
+ @Inject(Injector) private readonly _injector: Injector,
+ @Inject(LifecycleService) private readonly _lifecycleService: LifecycleService,
+ @IRenderingEngine private readonly _renderingEngine: Engine
+ ) {
super();
}
bootstrapWorkbench(options: IWorkbenchOptions): void {
- this.disposeWithMe(bootStrap(this._injector, options, (element) => this._renderingEngine.setContainer(element)));
+ this.disposeWithMe(
+ bootStrap(this._injector, options, (element) => {
+ this._renderingEngine.setContainer(element);
+ this._lifecycleService.stage = LifecycleStages.Rendered;
+ })
+ );
}
registerFooterComponent(component: () => ComponentType): IDisposable {
@@ -45,7 +54,11 @@ export class DesktopUIController extends Disposable implements IDesktopUIControl
}
}
-function bootStrap(injector: Injector, options: IWorkbenchOptions, callback: (containerEl: HTMLElement) => void): IDisposable {
+function bootStrap(
+ injector: Injector,
+ options: IWorkbenchOptions,
+ callback: (containerEl: HTMLElement) => void
+): IDisposable {
let mountContainer: HTMLElement;
const container = options.container;
diff --git a/packages/base-ui/src/services/menu/menu.service.ts b/packages/base-ui/src/services/menu/menu.service.ts
index d4c901cd5b..6b0e575b93 100644
--- a/packages/base-ui/src/services/menu/menu.service.ts
+++ b/packages/base-ui/src/services/menu/menu.service.ts
@@ -1,5 +1,6 @@
import { Disposable, toDisposable } from '@univerjs/core';
import { createIdentifier, IDisposable } from '@wendellhu/redi';
+import { debounceTime, Observable, Subject } from 'rxjs';
// TODO@wzhudev: this props should be moved to menu.service.ts to break cycle import
import { BaseSelectChildrenProps } from '../../Components/Select/Select';
@@ -34,6 +35,8 @@ export interface CustomLabel {
export const IMenuService = createIdentifier<IMenuService>('univer.menu-service');
export interface IMenuService {
+ menuChanged$: Observable<void>;
+
addMenuItem(item: IMenuItem): IDisposable;
/** Get menu items for display at a given position or a submenu. */
@@ -46,12 +49,17 @@ export class DesktopMenuService extends Disposable implements IMenuService {
private readonly _menuByPositions = new Map<MenuPosition | string, Array<[string, IMenuItem]>>();
+ private _menuChanged$ = new Subject<void>();
+
+ menuChanged$ = this._menuChanged$.asObservable().pipe(debounceTime(0));
+
constructor(@IShortcutService private readonly _shortcutService: IShortcutService) {
super();
}
override dispose(): void {
this._menuItemMap.clear();
+ this._menuChanged$.complete();
}
addMenuItem(item: IMenuItem): IDisposable {
@@ -67,6 +75,8 @@ export class DesktopMenuService extends Disposable implements IMenuService {
this.appendMenuToPosition(item, item.positions);
}
+ this._menuChanged$.next();
+
return toDisposable(() => {
this._menuItemMap.delete(item.id);
@@ -93,6 +103,8 @@ export class DesktopMenuService extends Disposable implements IMenuService {
menus.splice(index, 1);
}
}
+
+ this._menuChanged$.next();
});
}
diff --git a/packages/base-ui/src/views/components/toolbar/toolbar.tsx b/packages/base-ui/src/views/components/toolbar/toolbar.tsx
index cf52c8f072..b8aef54a52 100644
--- a/packages/base-ui/src/views/components/toolbar/toolbar.tsx
+++ b/packages/base-ui/src/views/components/toolbar/toolbar.tsx
@@ -44,10 +44,17 @@ export class Toolbar extends Component<IToolbarProps, IToolbarState> {
override componentDidMount() {
this.props.getComponent?.(this); // pass the UI to the controller, which is not good...
+
const menuService = this.context.injector!.get(IMenuService);
- this.setState({
- menuItems: menuService.getMenuItems(MenuPosition.TOOLBAR),
- });
+ const update = () => {
+ this.setState({
+ menuItems: menuService.getMenuItems(MenuPosition.TOOLBAR),
+ });
+ };
+
+ // TODO: dispose
+ menuService.menuChanged$.subscribe(() => update());
+ update();
}
override render() {
diff --git a/packages/core/package.json b/packages/core/package.json
index 74eedeb03d..fc78824d36 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -54,7 +54,7 @@
"url": "https://github.com/dream-num/univer.git"
},
"dependencies": {
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"dayjs": "^1.11.9",
"es6-proxy-polyfill": "^2.1.1",
"nanoid": "4.0.0",
diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.ts
index 0ac72899ba..9486bae328 100644
--- a/packages/core/src/Basics/Univer.ts
+++ b/packages/core/src/Basics/Univer.ts
@@ -1,10 +1,12 @@
import { Ctor, Injector } from '@wendellhu/redi';
import { ObserverManager } from '../Observer';
-import { Plugin, PluginCtor, PluginRegistry, PluginStore, PluginType } from '../Plugin';
+import { Plugin, PluginCtor, PluginRegistry, PluginStore, PluginType } from '../plugin/plugin';
import { CommandService, ICommandService } from '../services/command/command.service';
import { ContextService, IContextService } from '../services/context/context.service';
import { CurrentUniverService, ICurrentUniverService } from '../services/current.service';
+import { LifecycleStages } from '../services/lifecycle/lifecycle';
+import { LifecycleService } from '../services/lifecycle/lifecycle.service';
import { LocaleService } from '../services/locale.service';
import { DesktopLogService, ILogService } from '../services/log/log.service';
import { DesktopPermissionService, IPermissionService } from '../services/permission/permission.service';
@@ -28,7 +30,7 @@ export class Univer {
private readonly _univerPluginRegistry = new PluginRegistry();
constructor(univerData: Partial<IUniverData> = {}) {
- this._univerInjector = this._initializeDependencies();
+ this._univerInjector = this._initDependencies();
this._setObserver();
// initialize localization info
@@ -72,6 +74,8 @@ export class Univer {
this._currentUniverService.addSheet(sheet);
this.initializePluginsForSheet(sheet);
+ this._tryProgressToReady();
+
return sheet;
}
@@ -81,6 +85,8 @@ export class Univer {
this._currentUniverService.addDoc(doc);
this.initializePluginsForDoc(doc);
+ this._tryProgressToReady();
+
return doc;
}
@@ -90,6 +96,8 @@ export class Univer {
this._currentUniverService.addSlide(slide);
this.initializePluginsForSlide(slide);
+ this._tryProgressToReady();
+
return slide;
}
@@ -137,7 +145,7 @@ export class Univer {
new UniverObserverImpl().install(this._univerInjector.get(ObserverManager));
}
- private _initializeDependencies(): Injector {
+ private _initDependencies(): Injector {
return new Injector([
[ObserverManager],
[
@@ -150,6 +158,7 @@ export class Univer {
},
],
[LocaleService],
+ [LifecycleService],
[ILogService, { useClass: DesktopLogService, lazy: true }],
[ICommandService, { useClass: CommandService, lazy: true }],
[IUndoRedoService, { useClass: LocalUndoRedoService, lazy: true }],
@@ -158,12 +167,19 @@ export class Univer {
]);
}
+ private _tryProgressToReady(): void {
+ const lifecycleService = this._univerInjector.get(LifecycleService);
+ if (lifecycleService.stage < LifecycleStages.Ready) {
+ this._univerPluginStore.forEachPlugin((p) => p.onReady());
+ // TODO: call UniverSheet etc on ready.
+ this._univerInjector.get(LifecycleService).stage = LifecycleStages.Ready;
+ }
+ }
+
private registerUniverPlugin<T extends Plugin>(plugin: PluginCtor<T>, options?: any): void {
// For plugins at Univer level. Plugins would be initialized immediately so they can register dependencies.
const pluginInstance: Plugin = this._univerInjector.createInstance(plugin as unknown as Ctor<any>, options);
-
- pluginInstance.onMounted();
-
+ pluginInstance.onStarting(this._univerInjector);
this._univerPluginStore.addPlugin(pluginInstance);
}
diff --git a/packages/core/src/Basics/UniverDoc.ts b/packages/core/src/Basics/UniverDoc.ts
index 3f97c31714..c72a37abec 100644
--- a/packages/core/src/Basics/UniverDoc.ts
+++ b/packages/core/src/Basics/UniverDoc.ts
@@ -1,7 +1,7 @@
import { Ctor, Dependency, Injector, Optional } from '@wendellhu/redi';
import { DocumentModel } from '../Docs';
-import { Plugin, PluginCtor, PluginStore } from '../Plugin';
+import { Plugin, PluginCtor, PluginStore } from '../plugin/plugin';
import { CommandService, ICommandService } from '../services/command/command.service';
import { IDocumentData } from '../Types/Interfaces';
@@ -36,17 +36,10 @@ export class UniverDoc {
addPlugin<T extends Plugin>(pluginCtor: PluginCtor<T>, options: any): void {
const pluginInstance: Plugin = this._injector.createInstance(pluginCtor as unknown as Ctor<any>, options);
-
- pluginInstance.onMounted();
+ pluginInstance.onStarting(this._injector);
this._pluginStore.addPlugin(pluginInstance);
}
- mount(): void {
- // this._pluginStore.forEachPlugin((plugin) => {
- // plugin.onMounted();
- // });
- }
-
private _initializeDependencies(parentInjector?: Injector): Injector {
const dependencies: Dependency[] = [[ICommandService, { useClass: CommandService }]];
return parentInjector ? parentInjector.createChild(dependencies) : new Injector(dependencies);
diff --git a/packages/core/src/Basics/UniverSheet.ts b/packages/core/src/Basics/UniverSheet.ts
index d176a5df47..87bf5b334c 100644
--- a/packages/core/src/Basics/UniverSheet.ts
+++ b/packages/core/src/Basics/UniverSheet.ts
@@ -1,8 +1,9 @@
import { Ctor, Dependency, IDisposable, Injector, Optional } from '@wendellhu/redi';
import { ObserverManager } from '../Observer';
-import { Plugin, PluginCtor, PluginStore } from '../Plugin';
+import { Plugin, PluginCtor, PluginStore } from '../plugin/plugin';
import { CommandService, ICommandService } from '../services/command/command.service';
+import { LifecycleInitializerService } from '../services/lifecycle/lifecycle.service';
import { GenName, Logger } from '../Shared';
import { Workbook } from '../Sheets/Domain';
import { IWorkbookConfig } from '../Types/Interfaces';
@@ -25,9 +26,10 @@ export class UniverSheet implements IDisposable {
constructor(univerSheetData: Partial<IWorkbookConfig> = {}, @Optional(Injector) parentInjector?: Injector) {
this.univerSheetConfig = univerSheetData;
- this._sheetInjector = this._initializeDependencies(parentInjector);
+ this._sheetInjector = this._initDependencies(parentInjector);
this.setObserver();
this._workbook = this._sheetInjector.createInstance(Workbook, univerSheetData);
+ this._sheetInjector.get(LifecycleInitializerService).start();
}
static newInstance(univerSheetData: Partial<IWorkbookConfig> = {}): UniverSheet {
@@ -58,15 +60,15 @@ export class UniverSheet implements IDisposable {
*/
addPlugin<T extends Plugin>(plugin: PluginCtor<T>, options: any): void {
const pluginInstance: Plugin = this._sheetInjector.createInstance(plugin as unknown as Ctor<any>, options);
-
- pluginInstance.onMounted();
+ pluginInstance.onStarting(this._sheetInjector);
this._pluginStore.addPlugin(pluginInstance);
}
- private _initializeDependencies(parentInjector?: Injector): Injector {
+ private _initDependencies(parentInjector?: Injector): Injector {
const dependencies: Dependency[] = [
[ObserverManager],
[GenName],
+ [LifecycleInitializerService],
[
ICommandService,
{
@@ -74,9 +76,13 @@ export class UniverSheet implements IDisposable {
},
],
];
+
return parentInjector ? parentInjector.createChild(dependencies) : new Injector(dependencies);
}
+ /**
+ * @deprecated
+ */
private setObserver(): void {
new WorkBookObserverImpl().install(this._sheetInjector.get(ObserverManager));
}
diff --git a/packages/core/src/Basics/UniverSlide.ts b/packages/core/src/Basics/UniverSlide.ts
index efe7ef054a..d44c640094 100644
--- a/packages/core/src/Basics/UniverSlide.ts
+++ b/packages/core/src/Basics/UniverSlide.ts
@@ -1,7 +1,7 @@
import { Ctor, Dependency, Injector, Optional } from '@wendellhu/redi';
import { ObserverManager } from '../Observer';
-import { Plugin, PluginCtor, PluginStore } from '../Plugin';
+import { Plugin, PluginCtor, PluginStore } from '../plugin/plugin';
import { GenName, IOHttp, IOHttpConfig, Logger } from '../Shared';
import { ColorBuilder } from '../Sheets/Domain/ColorBuilder';
import { SlideModel } from '../Slides/Domain';
@@ -73,7 +73,7 @@ export class UniverSlide {
addPlugin<T extends Plugin>(plugin: PluginCtor<T>, options: any): void {
const pluginInstance: Plugin = this._slideInjector.createInstance(plugin as unknown as Ctor<any>, options);
- pluginInstance.onMounted();
+ pluginInstance.onRendered();
this._pluginStore.addPlugin(pluginInstance);
}
diff --git a/packages/core/src/Plugin/index.ts b/packages/core/src/Plugin/index.ts
deleted file mode 100644
index a40b4944c5..0000000000
--- a/packages/core/src/Plugin/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-// @index('./*.ts', f => `export * from '${f.path}'`)
-export * from './Plugin';
-// @endindex
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 13da6af39c..baa387b95e 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -15,11 +15,21 @@
export * from './Basics';
export * from './Docs/Domain';
export * from './Observer';
-export * from './Plugin';
-export { CommandType, ICommand, ICommandInfo, ICommandService, IMultiCommand, IMutation, IOperation } from './services/command/command.service';
+export { Plugin, PluginType } from './plugin/plugin';
+export {
+ CommandType,
+ ICommand,
+ ICommandInfo,
+ ICommandService,
+ IMultiCommand,
+ IMutation,
+ IOperation,
+} from './services/command/command.service';
export { FOCUSING_DOC, FOCUSING_SHEET, FOCUSING_SLIDE } from './services/context/context';
export { IContextService } from './services/context/context.service';
export { ICurrentUniverService } from './services/current.service';
+export { LifecycleStages, OnLifecycle } from './services/lifecycle/lifecycle';
+export { LifecycleService } from './services/lifecycle/lifecycle.service';
export { LocaleService } from './services/locale.service';
export { DesktopLogService, ILogService } from './services/log/log.service';
export { DesktopPermissionService, IPermissionService } from './services/permission/permission.service';
diff --git a/packages/core/src/Plugin/Plugin.ts b/packages/core/src/plugin/plugin.ts
similarity index 75%
rename from packages/core/src/Plugin/Plugin.ts
rename to packages/core/src/plugin/plugin.ts
index 6728d9a61f..37c74b67f7 100644
--- a/packages/core/src/Plugin/Plugin.ts
+++ b/packages/core/src/plugin/plugin.ts
@@ -1,7 +1,7 @@
import { Ctor, Injector } from '@wendellhu/redi';
-import { Nullable } from '../common/type-utils';
-import { Observable, ObserverManager } from '../Observer';
+import { Observable } from '../Observer/Observable';
+import { ObserverManager } from '../Observer/ObserverManager';
export type PluginCtor<T extends Plugin> = Ctor<T> & { type: PluginType };
@@ -13,26 +13,10 @@ export enum PluginType {
Slide,
}
-export interface IPlugin {
- getPluginName(): string;
-
- /**
- * Could setup initialization works at this lifecycle stage.
- */
- onMounted(): void;
-
- /**
- * Could do some initialization works at this lifecycle stage.
- */
- onDestroy(): void;
-
- getPluginByName<T extends IPlugin>(name: string): Nullable<T>;
-}
-
/**
* Plug-in base class, all plug-ins must inherit from this base class. Provide basic methods.
*/
-export abstract class Plugin<Obs = any> implements IPlugin {
+export abstract class Plugin<Obs = any> {
static type: PluginType;
_injector: Injector;
@@ -46,16 +30,15 @@ export abstract class Plugin<Obs = any> implements IPlugin {
this._observeNames = [];
}
- /** @deprecated this method will be removed */
- getPluginByName<T extends IPlugin>(name: string): Nullable<T> {
- throw new Error('Method not implemented.');
- }
+ onStarting(injector: Injector): void {}
- onMounted(): void {}
+ onReady(): void {}
- onDestroy(): void {
- this.deleteObserve(...this._observeNames);
- }
+ onRendered(): void {}
+
+ onSteady(): void {}
+
+ onDestroy(): void {}
getPluginName(): string {
return this._name;
diff --git a/packages/core/src/services/lifecycle/lifecycle.service.ts b/packages/core/src/services/lifecycle/lifecycle.service.ts
index 9a1a1fe811..940c872219 100644
--- a/packages/core/src/services/lifecycle/lifecycle.service.ts
+++ b/packages/core/src/services/lifecycle/lifecycle.service.ts
@@ -1,5 +1,57 @@
-import { LifecycleStages } from './lifecycle';
+import { Inject, Injector } from '@wendellhu/redi';
+import { BehaviorSubject } from 'rxjs';
-export class LifecycleService {
- stage: LifecycleStages = LifecycleStages.Staring;
+import { Disposable, toDisposable } from '../../Shared/lifecycle';
+import { ILogService } from '../log/log.service';
+import { LifecycleStages, LifecycleToModules } from './lifecycle';
+
+export class LifecycleService extends Disposable {
+ private _lifecycle$ = new BehaviorSubject<LifecycleStages>(LifecycleStages.Staring);
+
+ lifecycle$ = this._lifecycle$.asObservable();
+
+ constructor(@ILogService private readonly _logService: ILogService) {
+ super();
+ }
+
+ get stage(): LifecycleStages {
+ return this._lifecycle$.getValue();
+ }
+
+ set stage(stage: LifecycleStages) {
+ if (stage < this.stage) {
+ throw new Error('[LifecycleService]: lifecycle stage cannot go backward!');
+ }
+
+ if (stage === this.stage) {
+ return;
+ }
+
+ this._logService.log('[LifecycleService]: lifecycle progressed to ', stage, ' .');
+ this._lifecycle$.next(stage);
+ }
+}
+
+export class LifecycleInitializerService extends Disposable {
+ constructor(
+ @Inject(LifecycleService) private _lifecycleService: LifecycleService,
+ @Inject(Injector) private readonly _injector: Injector
+ ) {
+ super();
+ }
+
+ start(): void {
+ this.disposeWithMe(
+ toDisposable(this._lifecycleService.lifecycle$.subscribe((stage) => this._initModulesOnStage(stage)))
+ );
+ }
+
+ private _initModulesOnStage(stage: LifecycleStages): void {
+ const modules = LifecycleToModules.get(stage);
+ modules?.forEach((m) => {
+ if (this._injector.has(m)) {
+ this._injector.get(m);
+ }
+ });
+ }
}
diff --git a/packages/core/src/services/lifecycle/lifecycle.ts b/packages/core/src/services/lifecycle/lifecycle.ts
index 605b877815..cb3150652f 100644
--- a/packages/core/src/services/lifecycle/lifecycle.ts
+++ b/packages/core/src/services/lifecycle/lifecycle.ts
@@ -1,3 +1,5 @@
+import { Ctor, DependencyIdentifier } from '@wendellhu/redi';
+
/**
* This enum defines multiple lifecycle stages in Univer SDK.
*/
@@ -9,7 +11,7 @@ export const enum LifecycleStages {
/**
* Univer business instances (UniverDoc / UniverSheet / UniverSlide) are created and services or controllers provided by
- * plugins get intialized. The application is ready to do the first-time rendering.
+ * plugins get initialized. The application is ready to do the first-time rendering.
*/
Ready,
@@ -23,3 +25,18 @@ export const enum LifecycleStages {
*/
Steady,
}
+
+export const LifecycleToModules = new Map<LifecycleStages, Array<DependencyIdentifier<unknown>>>();
+
+// register some modules here that will automatically run when Univer progressed to a certain lifecycle stage
+export function OnLifecycle(lifecycleStage: LifecycleStages, identifier: DependencyIdentifier<unknown>) {
+ const decorator = function decorator(_registerTarget: Ctor<unknown>) {
+ if (!LifecycleToModules.has(lifecycleStage)) {
+ LifecycleToModules.set(lifecycleStage, []);
+ }
+
+ LifecycleToModules.get(lifecycleStage)!.push(identifier);
+ };
+
+ return decorator;
+}
diff --git a/packages/sheets-plugin-filter/src/FilterPlugin.tsx b/packages/sheets-plugin-filter/src/FilterPlugin.tsx
index 1318950802..1b6369bfc4 100644
--- a/packages/sheets-plugin-filter/src/FilterPlugin.tsx
+++ b/packages/sheets-plugin-filter/src/FilterPlugin.tsx
@@ -13,7 +13,7 @@ export class FilterPlugin extends Plugin {
this._filterList = FilterList.fromSequence(config || {});
}
- override onMounted(): void {
+ override onRendered(): void {
// const config: IConfig = {
// context,
// };
diff --git a/packages/sheets-plugin-find/package.json b/packages/sheets-plugin-find/package.json
index 0abe9f1c46..057c3b1feb 100644
--- a/packages/sheets-plugin-find/package.json
+++ b/packages/sheets-plugin-find/package.json
@@ -44,7 +44,7 @@
"@univerjs/common-plugin-data": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
diff --git a/packages/sheets-plugin-find/src/FindPlugin.ts b/packages/sheets-plugin-find/src/FindPlugin.ts
index 7fd6a85491..12532b5ab4 100644
--- a/packages/sheets-plugin-find/src/FindPlugin.ts
+++ b/packages/sheets-plugin-find/src/FindPlugin.ts
@@ -66,7 +66,7 @@ export class FindPlugin extends Plugin<FindPluginObserve> {
// // return new TextFinder(workSheet, type, text);
// }
- override onMounted(): void {
+ override onRendered(): void {
this.initialize();
}
diff --git a/packages/sheets-plugin-formula/package.json b/packages/sheets-plugin-formula/package.json
index 545685d543..a9192c03d4 100644
--- a/packages/sheets-plugin-formula/package.json
+++ b/packages/sheets-plugin-formula/package.json
@@ -44,7 +44,7 @@
"@univerjs/base-ui": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
diff --git a/packages/sheets-plugin-formula/src/FormulaPlugin.tsx b/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
index 24372ac1ba..8bd4c0d4a3 100644
--- a/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
+++ b/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
@@ -87,7 +87,7 @@ export class FormulaPlugin extends Plugin<FormulaPluginObserve> {
// );
}
- override onMounted(): void {
+ override onRendered(): void {
install(this);
this.initialize();
diff --git a/packages/sheets-plugin-image/package.json b/packages/sheets-plugin-image/package.json
index ecec6e6e1f..f375be87cf 100644
--- a/packages/sheets-plugin-image/package.json
+++ b/packages/sheets-plugin-image/package.json
@@ -44,7 +44,7 @@
"@univerjs/common-plugin-data": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
diff --git a/packages/sheets-plugin-image/src/ImagePlugin.tsx b/packages/sheets-plugin-image/src/ImagePlugin.tsx
index 9c55cfd11a..b09db076a9 100644
--- a/packages/sheets-plugin-image/src/ImagePlugin.tsx
+++ b/packages/sheets-plugin-image/src/ImagePlugin.tsx
@@ -36,7 +36,7 @@ export class ImagePlugin extends Plugin {
this._injector.add([IImagePluginData, { useFactory: () => this._imagePluginData }]);
}
- override onMounted(): void {
+ override onRendered(): void {
install(this);
const sheetContainerUIController = this._injector.get(SheetContainerUIController);
sheetContainerUIController.UIDidMount(() => {
diff --git a/packages/sheets-plugin-import-xlsx/package.json b/packages/sheets-plugin-import-xlsx/package.json
index 18459d261d..f8a907c4b0 100644
--- a/packages/sheets-plugin-import-xlsx/package.json
+++ b/packages/sheets-plugin-import-xlsx/package.json
@@ -44,7 +44,7 @@
"@univerjs/common-plugin-data": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"luckyexcel": "^1.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
diff --git a/packages/sheets-plugin-import-xlsx/src/ImportXlsxPlugin.tsx b/packages/sheets-plugin-import-xlsx/src/ImportXlsxPlugin.tsx
index 1a42de1e73..5f528587a6 100644
--- a/packages/sheets-plugin-import-xlsx/src/ImportXlsxPlugin.tsx
+++ b/packages/sheets-plugin-import-xlsx/src/ImportXlsxPlugin.tsx
@@ -42,7 +42,7 @@ export class ImportXlsxPlugin extends Plugin<any> {
// dragAndDropRegister.add(this._dragAndDropExtensionFactory);
}
- override onMounted(): void {
+ override onRendered(): void {
this.initialize();
}
diff --git a/packages/sheets-plugin-numfmt/package.json b/packages/sheets-plugin-numfmt/package.json
index aa5c18041d..bf94a8c205 100644
--- a/packages/sheets-plugin-numfmt/package.json
+++ b/packages/sheets-plugin-numfmt/package.json
@@ -44,7 +44,7 @@
"@univerjs/common-plugin-data": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
diff --git a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts
index 78b43b8b5d..1af84cd37f 100644
--- a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts
+++ b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts
@@ -1,8 +1,7 @@
import { ISelectionRange, LocaleService, ObjectMatrixPrimitiveType, Plugin, PluginType } from '@univerjs/core';
-import { SheetContainerUIController } from '@univerjs/ui-plugin-sheets';
import { Dependency, Inject, Injector } from '@wendellhu/redi';
-import { install, NUMFMT_PLUGIN_NAME, NumfmtActionExtensionFactory, NumfmtPluginObserve } from './Basics';
+import { install, NUMFMT_PLUGIN_NAME, NumfmtActionExtensionFactory } from './Basics';
import { NumfmtController, NumfmtModalController } from './Controller';
import { INumfmtPluginConfig } from './Interfaces';
import en from './Locale/en';
@@ -10,7 +9,7 @@ import { NumfmtModel } from './Model';
import { NumfmtService } from './services/numfmt.service';
import { INumfmtPluginData } from './Symbol';
-export class NumfmtPlugin extends Plugin<NumfmtPluginObserve> {
+export class NumfmtPlugin extends Plugin {
static override type = PluginType.Sheet;
private _numfmtModalController: NumfmtModalController;
@@ -30,18 +29,14 @@ export class NumfmtPlugin extends Plugin<NumfmtPluginObserve> {
this._numfmtPluginData = new NumfmtModel();
this._injector.add([INumfmtPluginData, { useFactory: () => this._numfmtPluginData }]);
-
- const sheetContainerUIController = this._injector.get(SheetContainerUIController);
- sheetContainerUIController.UIDidMount(() => {
- this.initializeDependencies(_injector);
- this.registerExtension();
- this._numfmtController = this._injector.get(NumfmtController);
- this._numfmtModalController = this._injector.get(NumfmtModalController);
- });
}
- override onMounted(): void {
+ override onRendered(): void {
install(this);
+ this.initializeDependencies(this._injector);
+ this.registerExtension();
+ this._numfmtController = this._injector.get(NumfmtController);
+ this._numfmtModalController = this._injector.get(NumfmtModalController);
this._localeService.getLocale().load({ en });
// const actionRegister = this._commandManager.getActionExtensionManager().getRegister();
// actionRegister.add(this._numfmtActionExtensionFactory);
diff --git a/packages/sheets-plugin-operation/package.json b/packages/sheets-plugin-operation/package.json
index 485af5645e..04cfe26e6a 100644
--- a/packages/sheets-plugin-operation/package.json
+++ b/packages/sheets-plugin-operation/package.json
@@ -44,7 +44,7 @@
"@univerjs/common-plugin-data": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
diff --git a/packages/sheets-plugin-operation/src/OperationPlugin.ts b/packages/sheets-plugin-operation/src/OperationPlugin.ts
index e760d403e4..2ef29f4496 100644
--- a/packages/sheets-plugin-operation/src/OperationPlugin.ts
+++ b/packages/sheets-plugin-operation/src/OperationPlugin.ts
@@ -100,7 +100,7 @@ export class OperationPlugin extends Plugin {
// copyRegister.delete(this._copyImageExtensionFactory);
}
- override onMounted(): void {
+ override onRendered(): void {
this.initialize();
}
diff --git a/packages/ui-plugin-docs/package.json b/packages/ui-plugin-docs/package.json
index 01d32cd717..5d8238e35d 100644
--- a/packages/ui-plugin-docs/package.json
+++ b/packages/ui-plugin-docs/package.json
@@ -52,7 +52,7 @@
"@univerjs/base-render": "workspace:^0.0.1",
"@univerjs/base-ui": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"css-vars-ponyfill": "^2.4.6",
"react": "^18.2.0",
"react-dom": "^18.2.0"
diff --git a/packages/ui-plugin-docs/src/doc-ui-plugin.ts b/packages/ui-plugin-docs/src/doc-ui-plugin.ts
index b102300319..2d2dd7091e 100644
--- a/packages/ui-plugin-docs/src/doc-ui-plugin.ts
+++ b/packages/ui-plugin-docs/src/doc-ui-plugin.ts
@@ -22,7 +22,7 @@ export class DocUIPlugin extends Plugin<any> {
this._initDependencies(_injector);
}
- override onMounted(): void {
+ override onRendered(): void {
this._localService.getLocale().load({
en,
});
diff --git a/packages/ui-plugin-sheets/package.json b/packages/ui-plugin-sheets/package.json
index c703ee8cd6..d759d1a390 100644
--- a/packages/ui-plugin-sheets/package.json
+++ b/packages/ui-plugin-sheets/package.json
@@ -47,7 +47,7 @@
"@univerjs/base-docs": "workspace:^0.0.1",
"@univerjs/base-ui": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"css-vars-ponyfill": "^2.4.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
diff --git a/packages/ui-plugin-sheets/src/Controller/AppUIController.ts b/packages/ui-plugin-sheets/src/Controller/AppUIController.ts
index d478dc0cda..dda689cd7c 100644
--- a/packages/ui-plugin-sheets/src/Controller/AppUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/AppUIController.ts
@@ -1,5 +1,5 @@
import { IDesktopUIController, IUIController } from '@univerjs/base-ui';
-import { Disposable, LocaleService, LocaleType, ObserverManager } from '@univerjs/core';
+import { Disposable, LifecycleStages, LocaleService, LocaleType, ObserverManager, OnLifecycle } from '@univerjs/core';
import { Inject, Injector, SkipSelf } from '@wendellhu/redi';
import { connectInjector } from '@wendellhu/redi/react-bindings';
@@ -7,6 +7,7 @@ import { ISheetUIPluginConfig } from '../Basics';
import { RenderSheetFooter } from '../View/SheetContainer/SheetContainer';
import { SheetContainerUIController } from './SheetContainerUIController';
+@OnLifecycle(LifecycleStages.Rendered, AppUIController)
export class AppUIController extends Disposable {
private _sheetContainerController: SheetContainerUIController;
@@ -22,7 +23,9 @@ export class AppUIController extends Disposable {
this._sheetContainerController = this._injector.createInstance(SheetContainerUIController, config);
this._injector.add([SheetContainerUIController, { useValue: this._sheetContainerController }]);
- this.disposeWithMe(this._uiController.registerFooterComponent(() => connectInjector(RenderSheetFooter, this._injector)));
+ this.disposeWithMe(
+ this._uiController.registerFooterComponent(() => connectInjector(RenderSheetFooter, this._injector))
+ );
}
/**
diff --git a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
index a2adcc89ea..f92bc21dc4 100644
--- a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
@@ -1,4 +1,11 @@
-import { BaseSelectChildrenProps, BaseSelectProps, ColorPicker, ComponentManager, IMenuService, MenuPosition } from '@univerjs/base-ui';
+import {
+ BaseSelectChildrenProps,
+ BaseSelectProps,
+ ColorPicker,
+ ComponentManager,
+ IMenuService,
+ MenuPosition,
+} from '@univerjs/base-ui';
import { IMenuItemFactory } from '@univerjs/base-ui/src/services/menu/menu';
import { Disposable } from '@univerjs/core';
import { Inject, Injector } from '@wendellhu/redi';
diff --git a/packages/ui-plugin-sheets/src/Controller/shortcut.controller.ts b/packages/ui-plugin-sheets/src/Controller/shortcut.controller.ts
index 73fb8b7917..1d70912bcc 100644
--- a/packages/ui-plugin-sheets/src/Controller/shortcut.controller.ts
+++ b/packages/ui-plugin-sheets/src/Controller/shortcut.controller.ts
@@ -9,7 +9,7 @@ import {
SetUnderlineCommand,
} from '@univerjs/base-sheets';
import { IShortcutService } from '@univerjs/base-ui';
-import { Disposable, ICommandService } from '@univerjs/core';
+import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { QuitCellEditorCommand } from '../services/cell-editor/cell-editor.command';
import { QuitCellEditorShortcutItem } from '../services/shortcuts/shortcuts';
@@ -40,6 +40,7 @@ import {
} from './shortcuts/style.shortcut';
import { ClearSelectionValueShortcutItem } from './shortcuts/value.shortcut';
+@OnLifecycle(LifecycleStages.Rendered, DesktopSheetShortcutController)
export class DesktopSheetShortcutController extends Disposable {
constructor(
@IShortcutService private readonly _shortcutService: IShortcutService,
diff --git a/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor-desktop.service.ts b/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor-desktop.service.ts
index c8429d9148..0e9b2cca5b 100644
--- a/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor-desktop.service.ts
+++ b/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor-desktop.service.ts
@@ -30,7 +30,9 @@ import {
ISelectionCell,
ISelectionRange,
IStyleData,
+ LifecycleStages,
Nullable,
+ OnLifecycle,
toDisposable,
} from '@univerjs/core';
import { Inject, Injector } from '@wendellhu/redi';
@@ -47,6 +49,7 @@ const SHEET_CELL_EDITOR_MODEL_ID = 'sheet.model.cell-editor';
/**
* Cell editor for Univer on desktop. Reuse by multi univer sheet documents.
*/
+@OnLifecycle(LifecycleStages.Rendered, ICellEditorService)
export class DesktopCellEditorService extends Disposable implements ICellEditorService {
private _containerElement: HTMLDivElement;
@@ -71,9 +74,7 @@ export class DesktopCellEditorService extends Disposable implements ICellEditorS
@IContextService private readonly _contextService: IContextService
) {
super();
- }
- initialize(): void {
this._mountCellEditor();
this._initListeners();
this._focusCurrentSheet();
diff --git a/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor.service.ts b/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor.service.ts
index 8adf89dcc3..f0e10dcdae 100644
--- a/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor.service.ts
+++ b/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor.service.ts
@@ -4,7 +4,6 @@ import { createIdentifier } from '@wendellhu/redi';
// stack. So cell editor service must be an abstract dependency.
export interface ICellEditorService {
- initialize(): void;
enterEditing(): void;
quitEditing(): void;
}
diff --git a/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts b/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
index c00161ea6c..0b5035be14 100644
--- a/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
+++ b/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
@@ -1,14 +1,8 @@
import { DragManager, SlotManager, ZIndexManager } from '@univerjs/base-ui';
-import { ICurrentUniverService, IUndoRedoService, LocaleService, Plugin, PluginType, Tools } from '@univerjs/core';
+import { ICurrentUniverService, LocaleService, Plugin, PluginType, Tools } from '@univerjs/core';
import { Dependency, Inject, Injector } from '@wendellhu/redi';
-import {
- DefaultSheetUIConfig,
- installObserver,
- ISheetUIPluginConfig,
- SHEET_UI_PLUGIN_NAME,
- SheetUIPluginObserve,
-} from './Basics';
+import { DefaultSheetUIConfig, ISheetUIPluginConfig, SHEET_UI_PLUGIN_NAME, SheetUIPluginObserve } from './Basics';
import { AppUIController } from './Controller/AppUIController';
import { SheetClipboardController } from './Controller/clipboard/clipboard.controller';
import { DesktopSheetShortcutController } from './Controller/shortcut.controller';
@@ -39,9 +33,7 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve> {
this._config = Tools.deepMerge({}, DefaultSheetUIConfig, config);
}
- override onMounted(): void {
- installObserver(this);
-
+ override onStarting(): void {
/**
* load more Locale object
*
@@ -109,11 +101,6 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve> {
this._dragManager = this._injector.get(DragManager);
this._zIndexManager = this._injector.get(ZIndexManager);
-
- this._injector.get(IUndoRedoService);
- this._injector.get(DesktopSheetShortcutController);
- this._injector.get(ICellEditorService).initialize();
- this._injector.get(AppUIController);
}
private _initModules(): void {
diff --git a/packages/ui-plugin-slides/package.json b/packages/ui-plugin-slides/package.json
index 74b479df97..561c0914f6 100644
--- a/packages/ui-plugin-slides/package.json
+++ b/packages/ui-plugin-slides/package.json
@@ -41,7 +41,7 @@
"@univerjs/base-slides": "workspace:^0.0.1",
"@univerjs/base-ui": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.12.7",
+ "@wendellhu/redi": "^0.12.8",
"css-vars-ponyfill": "^2.4.6",
"react": "^18.2.0",
"react-dom": "^18.2.0"
diff --git a/packages/ui-plugin-slides/src/Controller/AppUIController.ts b/packages/ui-plugin-slides/src/Controller/AppUIController.ts
index c70a14b053..5b96276567 100644
--- a/packages/ui-plugin-slides/src/Controller/AppUIController.ts
+++ b/packages/ui-plugin-slides/src/Controller/AppUIController.ts
@@ -3,7 +3,6 @@ import { LocaleService, LocaleType, ObserverManager } from '@univerjs/core';
import { Inject, Injector, SkipSelf } from '@wendellhu/redi';
import { ISlideUIPluginConfig } from '../Basics';
-import { UI } from '../View';
import { SlideContainerUIController } from './SlideContainerUIController';
export class AppUIController {
@@ -19,15 +18,6 @@ export class AppUIController {
this._slideContainerUIController = this._injector.createInstance(SlideContainerUIController, config);
this._injector.add([SlideContainerUIController, { useValue: this._slideContainerUIController }]);
const UIConfig = this._slideContainerUIController.getUIConfig();
-
- UI.create({
- injector: this._injector,
- locale: this._localeService.getLocale().getCurrentLocale(),
- componentManager: this._componentManager,
- changeLocale: this.changeLocale,
- UIConfig,
- container: config.container,
- });
}
/**
diff --git a/packages/ui-plugin-slides/src/SlideUIPlugin.ts b/packages/ui-plugin-slides/src/SlideUIPlugin.ts
index b1936f622e..b25de22b44 100644
--- a/packages/ui-plugin-slides/src/SlideUIPlugin.ts
+++ b/packages/ui-plugin-slides/src/SlideUIPlugin.ts
@@ -75,7 +75,7 @@ export class SlideUIPlugin extends Plugin<SlideUIPluginObserve> {
initUI() {}
- override onMounted(): void {
+ override onRendered(): void {
this.initialize();
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 4a6e16eded..97384daae0 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -342,8 +342,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
css-vars-ponyfill:
specifier: ^2.4.6
version: 2.4.6
@@ -391,8 +391,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
react:
specifier: ^18.2.0
version: 18.2.0
@@ -486,8 +486,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
react:
specifier: ^18.2.0
version: 18.2.0
@@ -541,8 +541,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
react:
specifier: ^18.2.0
version: 18.2.0
@@ -599,8 +599,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
css-vars-ponyfill:
specifier: ^2.4.6
version: 2.4.6
@@ -648,8 +648,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
react:
specifier: ^18.2.0
version: 18.2.0
@@ -743,8 +743,8 @@ importers:
packages/core:
dependencies:
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
dayjs:
specifier: ^1.11.9
version: 1.11.9
@@ -856,8 +856,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../ui-plugin-sheets
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
react:
specifier: ^18.2.0
version: 18.2.0
@@ -920,8 +920,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../ui-plugin-sheets
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
react:
specifier: ^18.2.0
version: 18.2.0
@@ -984,8 +984,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../ui-plugin-sheets
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
react:
specifier: ^18.2.0
version: 18.2.0
@@ -1048,8 +1048,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../ui-plugin-sheets
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
luckyexcel:
specifier: ^1.0.1
version: 1.0.1
@@ -1115,8 +1115,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../ui-plugin-sheets
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
react:
specifier: ^18.2.0
version: 18.2.0
@@ -1176,8 +1176,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../ui-plugin-sheets
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
react:
specifier: ^18.2.0
version: 18.2.0
@@ -1225,8 +1225,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
css-vars-ponyfill:
specifier: ^2.4.6
version: 2.4.6
@@ -1283,8 +1283,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
css-vars-ponyfill:
specifier: ^2.4.6
version: 2.4.6
@@ -1344,8 +1344,8 @@ importers:
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.7
- version: 0.12.7
+ specifier: ^0.12.8
+ version: 0.12.8
css-vars-ponyfill:
specifier: ^2.4.6
version: 2.4.6
@@ -6046,8 +6046,8 @@ packages:
- supports-color
dev: true
- /@wendellhu/[email protected]:
- resolution: {integrity: sha512-HAJhOfAqD1E7O/FGEnz27psFjDq6h3xBbmN9b/j2ijAslleb71WLnHUrhRtMCgIWEm7Ktb8fkk0aK80pJsTlng==}
+ /@wendellhu/[email protected]:
+ resolution: {integrity: sha512-piEmRbwzIZ9SsHDlEUh3thk+kMdLImVHzgvn00C8/dqSbSg/Pgc8J5na7Juh9GGEuI9JR33uc4b8ZzVazchQIg==}
dev: false