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.

fix(slide): fix slide demo (#232)

Wenzhao Hu89d1c48cd696
diff --git a/examples/univer-slide-ts/public/index.html b/examples/univer-slide-ts/public/index.html
index ab06811946..8558b36367 100644
--- a/examples/univer-slide-ts/public/index.html
+++ b/examples/univer-slide-ts/public/index.html
@@ -1,33 +1,33 @@
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
- <meta charset="utf-8" />
- <meta content="width=device-width, initial-scale=1" name="viewport" />
- <title>UniverSlide</title>
-
- <link rel="stylesheet" href="./main.css" />
- <style>
- html,
- body {
- height: 100%;
- margin: 0;
- }
- </style>
-
-
- <script>
- new EventSource('/esbuild').addEventListener('change', () => {
- location.reload()
- })
- </script>
-</head>
-
-<body>
- <div id="app" style="z-index: 1; position: fixed; font-size: 20px; color: green;"></div>
- <div id="universlide" style="height: 100%;"></div>
-
- <script src="./main.js"></script>
-</body>
-
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+ <meta charset="utf-8" />
+ <meta content="width=device-width, initial-scale=1" name="viewport" />
+ <title>UniverSlide</title>
+
+ <link rel="stylesheet" href="./main.css" />
+ <style>
+ html,
+ body {
+ height: 100%;
+ margin: 0;
+ }
+ </style>
+
+
+ <script>
+ new EventSource('/esbuild').addEventListener('change', () => {
+ location.reload()
+ })
+ </script>
+</head>
+
+<body>
+ <div id="app" style="z-index: 1; position: fixed; font-size: 20px; color: green;"></div>
+ <div id="univer-container" style="height: 100%;"></div>
+
+ <script src="./main.js"></script>
+</body>
+
</html>
\ No newline at end of file
diff --git a/examples/univer-slide-ts/src/main.tsx b/examples/univer-slide-ts/src/main.tsx
index 36c04c2066..6fe932ffec 100644
--- a/examples/univer-slide-ts/src/main.tsx
+++ b/examples/univer-slide-ts/src/main.tsx
@@ -1,5 +1,6 @@
import { RenderEngine } from '@univerjs/base-render';
import { SlidePlugin } from '@univerjs/base-slides';
+import { greenTheme, UIPlugin } from '@univerjs/base-ui';
import { DEFAULT_SLIDE_DATA } from '@univerjs/common-plugin-data';
import { LocaleType, Univer } from '@univerjs/core';
import { SlideUIPlugin } from '@univerjs/ui-plugin-slides';
@@ -7,21 +8,22 @@ import { SlideUIPlugin } from '@univerjs/ui-plugin-slides';
// univer
const univer = new Univer({
locale: LocaleType.EN,
+ theme: greenTheme,
});
-univer.createUniverSlide(DEFAULT_SLIDE_DATA);
-
// base-render
univer.registerPlugin(RenderEngine);
-univer.registerPlugin(SlidePlugin);
-univer.registerPlugin(SlideUIPlugin, {
- container: 'universlide',
- layout: {
- slideContainerConfig: {
- innerLeft: true,
- },
- },
+univer.registerPlugin(UIPlugin, {
+ container: 'univer-container',
+ header: true,
+ toolbar: true,
+ footer: true,
+ innerLeft: true,
});
+univer.registerPlugin(SlidePlugin);
+univer.registerPlugin(SlideUIPlugin);
+
+univer.createUniverSlide(DEFAULT_SLIDE_DATA);
// use for console test
declare global {
diff --git a/packages/base-docs/src/View/Render/CanvasView.ts b/packages/base-docs/src/View/Render/CanvasView.ts
index 2e9a0ca7f6..ab6adec946 100644
--- a/packages/base-docs/src/View/Render/CanvasView.ts
+++ b/packages/base-docs/src/View/Render/CanvasView.ts
@@ -22,7 +22,6 @@ export class CanvasView {
/** @deprecated This a temporary solution. CanvasView should not be a singleton. */
private standalone = true,
@IRenderManagerService private readonly _rms: RenderManagerService,
- // @IRenderingEngine private readonly _engine: Engine,
@Inject(Injector) private readonly _injector: Injector
) {
this._initialize();
diff --git a/packages/base-slides/src/Controller/InfoBarController.ts b/packages/base-slides/src/Controller/InfoBarController.ts
deleted file mode 100644
index e2f2ecfe55..0000000000
--- a/packages/base-slides/src/Controller/InfoBarController.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-// import { InfoBar } from '@univerjs/ui-plugin-slides/src/View/InfoBar/InfoBar';
-import { InfoBarModel } from '../Model/InfoBarModel';
-import { SlidePlugin } from '../SlidePlugin';
-
-type IProps = {
- locale?: string;
- label?: string;
- onBlur?: (e: FocusEvent) => void;
-};
-
-export interface BaseInfoBarProps {
- back: IProps;
- update: IProps;
- save: IProps;
- rename: IProps;
- sheet: IProps;
-}
-
-export class InfoBarController {
- private _infoBarModel: InfoBarModel;
-
- // private _infoBar: InfoBar;
-
- private _plugin: SlidePlugin;
-
- private _infoList: BaseInfoBarProps;
-
- constructor(plugin: SlidePlugin) {
- this._plugin = plugin;
-
- // TODO get name from config
- const name = 'UniverSlide Demo';
- this._infoBarModel = new InfoBarModel(name);
-
- this._infoList = {
- back: {
- locale: 'info.return',
- },
- update: {
- locale: 'info.detailUpdate',
- },
- save: {
- locale: 'info.detailSave',
- },
- rename: {
- locale: 'info.tips',
- },
- sheet: {
- label: name,
- onBlur: (e) => {
- this.setSlideName(e);
- },
- },
- };
- }
-
- resetInfoList(list: BaseInfoBarProps) {
- // const locale = this._plugin.context.getLocale();
- // for (let k in list) {
- // if (list[k].locale) {
- // list[k].label = locale.get(list[k].locale);
- // }
- // }
- // this._infoBar.setInfoList(list);
- }
-
- setSlideName(e: FocusEvent) {
- const target = e.target as HTMLInputElement;
- const name = target.value;
- this._infoBarModel.setName(name);
- }
-}
diff --git a/packages/base-slides/src/Controller/ToolbarController.ts b/packages/base-slides/src/Controller/ToolbarController.ts
deleted file mode 100644
index eef2b81e5d..0000000000
--- a/packages/base-slides/src/Controller/ToolbarController.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import { BorderType } from '@univerjs/core';
-
-import { SlidePlugin } from '../SlidePlugin';
-
-export interface BorderInfo {
- type: BorderType;
- color: string;
- style: number;
-}
-
-/**
- *
- */
-export class ToolbarController {
- private _plugin: SlidePlugin;
-
- constructor(plugin: SlidePlugin) {
- this._plugin = plugin;
- }
-
- listenEventManager() {}
-}
diff --git a/packages/base-slides/src/Controller/index.ts b/packages/base-slides/src/Controller/index.ts
deleted file mode 100644
index 47f1b56674..0000000000
--- a/packages/base-slides/src/Controller/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-// @index(['./*.ts','./**/index.ts'], f => `export * from '${f.path}'`)
-export * from './ToolbarController';
-// @endindex
diff --git a/packages/base-slides/src/SlidePlugin.ts b/packages/base-slides/src/SlidePlugin.ts
index 199c74977e..2d45f63de3 100644
--- a/packages/base-slides/src/SlidePlugin.ts
+++ b/packages/base-slides/src/SlidePlugin.ts
@@ -2,7 +2,6 @@ import { Engine, IRenderingEngine } from '@univerjs/base-render';
import { ICurrentUniverService, ILanguagePack, LocaleService, Plugin, PLUGIN_NAMES, PluginType } from '@univerjs/core';
import { Dependency, Inject, Injector } from '@wendellhu/redi';
-import { ToolbarController } from './Controller';
import { en } from './Locale';
import { CanvasView } from './View/Render';
@@ -19,8 +18,6 @@ export class SlidePlugin extends Plugin {
private _canvasView: CanvasView | null = null;
- private _toolbarController: ToolbarController | null = null;
-
constructor(
config: Partial<ISlidePluginConfig> = {},
@ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,
@@ -37,7 +34,6 @@ export class SlidePlugin extends Plugin {
this._localeService.getLocale().load({
en: en as unknown as ILanguagePack,
});
- this.initController();
this.initCanvasEngine();
}
@@ -45,10 +41,6 @@ export class SlidePlugin extends Plugin {
return this._config;
}
- initController() {
- this._toolbarController = this._injector.get(ToolbarController);
- }
-
initCanvasEngine() {
this._canvasEngine = this._injector.get(IRenderingEngine);
}
@@ -70,7 +62,7 @@ export class SlidePlugin extends Plugin {
}
private _initializeDependencies(slideInjector: Injector) {
- const dependencies: Dependency[] = [[CanvasView], [ToolbarController]];
+ const dependencies: Dependency[] = [[CanvasView]];
dependencies.forEach((d) => {
slideInjector.add(d);
diff --git a/packages/base-slides/src/View/Render/CanvasView.ts b/packages/base-slides/src/View/Render/CanvasView.ts
index 909f449da2..be446aacdf 100644
--- a/packages/base-slides/src/View/Render/CanvasView.ts
+++ b/packages/base-slides/src/View/Render/CanvasView.ts
@@ -2,8 +2,10 @@ import {
Engine,
EVENT_TYPE,
IRenderingEngine,
+ IRenderManagerService,
IWheelEvent,
Rect,
+ RenderManagerService,
Scene,
ScrollBar,
Slide,
@@ -34,7 +36,8 @@ export class CanvasView {
constructor(
@ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,
@Inject(Injector) private readonly _injector: Injector,
- @IRenderingEngine private readonly _engine: Engine
+ @IRenderingEngine private readonly _engine: Engine,
+ @IRenderManagerService private readonly _rms: RenderManagerService
) {
this._initializeDependencies(this._injector);
this._initialize();
@@ -129,7 +132,7 @@ export class CanvasView {
}
private _initialize() {
- const engine = this._engine;
+ const engine = this._rms.defaultEngine;
const scene = new Scene(SLIDE_KEY.SCENE, engine, {
width: 2400,
diff --git a/packages/base-slides/src/index.ts b/packages/base-slides/src/index.ts
index f49b533fbe..7250119410 100644
--- a/packages/base-slides/src/index.ts
+++ b/packages/base-slides/src/index.ts
@@ -1,4 +1,3 @@
-export * from './Controller';
export * from './Locale';
export * from './SlidePlugin';
export * from './View/Render';
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 03c9cae91e..ae04ae6255 100644
--- a/packages/base-ui/src/controllers/ui/ui-desktop.controller.tsx
+++ b/packages/base-ui/src/controllers/ui/ui-desktop.controller.tsx
@@ -15,13 +15,22 @@ import { IUIController, IWorkbenchOptions } from './ui.controller';
export interface IDesktopUIController extends IUIController {
componentRegistered$: Observable<void>;
+ // provides multi methods for business to register workbench custom components
+ // TODO@wzhudev: in the future we may bind components to different business types
+
+ // footer bar
registerFooterComponent(component: () => ComponentType): IDisposable;
getFooterComponents(): Set<() => ComponentType>;
+
+ registerSidebarComponent(component: () => ComponentType): IDisposable;
+ getSidebarComponents(): Set<() => ComponentType>;
}
export class DesktopUIController extends Disposable implements IDesktopUIController {
private _footerComponents: Set<() => ComponentType> = new Set();
+ private _sidebarComponents: Set<() => ComponentType> = new Set();
+
private _componentRegistered$ = new Subject<void>();
componentRegistered$ = this._componentRegistered$.asObservable();
@@ -52,6 +61,16 @@ export class DesktopUIController extends Disposable implements IDesktopUIControl
getFooterComponents(): Set<() => ComponentType> {
return new Set([...this._footerComponents]);
}
+
+ registerSidebarComponent(component: () => ComponentType): IDisposable {
+ this._sidebarComponents.add(component);
+ this._componentRegistered$.next();
+ return toDisposable(() => this._footerComponents.delete(component));
+ }
+
+ getSidebarComponents(): Set<() => React.ComponentType> {
+ return new Set([...this._sidebarComponents]);
+ }
}
function bootStrap(
@@ -82,7 +101,15 @@ function bootStrap(
const desktopUIController = injector.get(IUIController) as IDesktopUIController;
const updateSubscription = desktopUIController.componentRegistered$.subscribe(() => {
const footerComponents = desktopUIController.getFooterComponents();
- root.render(<ConnectedApp {...options} footerComponents={footerComponents} onRendered={callback} />);
+ const sidebarComponents = desktopUIController.getSidebarComponents();
+ root.render(
+ <ConnectedApp
+ {...options}
+ footerComponents={footerComponents}
+ sidebarComponents={sidebarComponents}
+ onRendered={callback}
+ />
+ );
});
return toDisposable(() => {
diff --git a/packages/base-ui/src/views/app.tsx b/packages/base-ui/src/views/app.tsx
index bdfc4cb50b..e72ecf87f8 100644
--- a/packages/base-ui/src/views/app.tsx
+++ b/packages/base-ui/src/views/app.tsx
@@ -15,6 +15,7 @@ import { Toolbar } from './components/toolbar/toolbar';
export interface IUniverAppProps extends IWorkbenchOptions {
footerComponents?: Set<() => ComponentType>;
+ sidebarComponents?: Set<() => ComponentType>;
onRendered?: (container: HTMLElement) => void;
}
@@ -28,7 +29,9 @@ export function App(props: IUniverAppProps) {
const containerRef = useRef<HTMLDivElement>(null);
- const { footerComponents, onRendered } = props;
+ const { footerComponents, sidebarComponents, onRendered } = props;
+
+ console.log('debug', sidebarComponents);
useEffect(() => {
if (!themeService.getCurrentTheme()) {
@@ -100,7 +103,16 @@ export function App(props: IUniverAppProps) {
</Header>
{/* content */}
<Layout>
- <Sider style={{ display: props.innerLeft ? 'block' : 'none' }}>{/* inner left */}</Sider>
+ <Sider
+ style={{ display: props.innerLeft ? 'block' : 'none' }}
+ className={style.contentInnerLeftContainer}
+ >
+ {/* inner left */}
+ {sidebarComponents &&
+ Array.from(sidebarComponents.values()).map((component, index) =>
+ React.createElement(component(), { key: `${index}` })
+ )}
+ </Sider>
<Content className={style.contentContainerHorizontal}>
{/* FIXME: context menu component shouldn't have to mount on this position */}
<Container
diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.ts
index ccc22157eb..2738d819b8 100644
--- a/packages/core/src/Basics/Univer.ts
+++ b/packages/core/src/Basics/Univer.ts
@@ -88,12 +88,10 @@ export class Univer {
createUniverSlide(config: Partial<ISlideData>): UniverSlide {
const slide = this._univerInjector.createInstance(UniverSlide, config);
-
this._currentUniverService.addSlide(slide);
this.initializePluginsForSlide(slide);
-
this._tryProgressToReady();
-
+ slide.onReady();
return slide;
}
diff --git a/packages/core/src/Basics/UniverSlide.ts b/packages/core/src/Basics/UniverSlide.ts
index 8ade6dc973..b62744ce9d 100644
--- a/packages/core/src/Basics/UniverSlide.ts
+++ b/packages/core/src/Basics/UniverSlide.ts
@@ -1,60 +1,41 @@
-import { Ctor, Dependency, Injector, Optional } from '@wendellhu/redi';
+import { Ctor, Dependency, Inject, Injector, Optional } from '@wendellhu/redi';
import { Plugin, PluginCtor, PluginStore } from '../plugin/plugin';
-import { GenName, IOHttp, IOHttpConfig, Logger } from '../Shared';
-import { ColorBuilder } from '../Shared/color/ColorBuilder';
+import { CommandService, ICommandService } from '../services/command/command.service';
+import { LifecycleStages } from '../services/lifecycle/lifecycle';
+import { LifecycleInitializerService, LifecycleService } from '../services/lifecycle/lifecycle.service';
+import { GenName } from '../Shared';
import { SlideModel } from '../Slides/Domain';
import { ISlideData } from '../Types/Interfaces';
-import { VersionCode, VersionEnv } from './Version';
/**
* Externally provided UniverSlide root instance
*/
export class UniverSlide {
- UniverSlideConfig: Partial<ISlideData>;
+ _univerSlideConfig: Partial<ISlideData>;
- private readonly _slideInjector: Injector;
+ private readonly _injector: Injector;
private readonly _slideModel: SlideModel;
private readonly _pluginStore = new PluginStore();
- constructor(UniverSlideData: Partial<ISlideData> = {}, @Optional(Injector) parentInjector?: Injector) {
- this.UniverSlideConfig = UniverSlideData;
-
- this._slideInjector = this._initializeDependencies(parentInjector);
-
- this._slideModel = this._slideInjector.createInstance(SlideModel, UniverSlideData);
- }
-
- static newInstance(UniverSlideData: Partial<ISlideData> = {}): UniverSlide {
- Logger.capsule(VersionEnv, VersionCode, 'powered by :: UniverSlide :: ');
- return new UniverSlide(UniverSlideData);
- }
-
- /**
- *
- * Request data
- *
- * @example
- * Get data for all tables, including core and plugin data
- *
- * @param config
- */
- static get<T = void>(config: Omit<IOHttpConfig, 'type'>): Promise<T> {
- return IOHttp({ ...config, type: 'GET' });
- }
-
- /**
- * Submit data
- * @param config
- */
- static post<T = void>(config: Omit<IOHttpConfig, 'type'>): Promise<T> {
- return IOHttp({ ...config, type: 'POST' });
- }
-
- static newColor(): ColorBuilder {
- return new ColorBuilder();
+ constructor(
+ UniverSlideData: Partial<ISlideData> = {},
+ @Optional(Injector) parentInjector: Injector,
+ @Inject(LifecycleService) private readonly _lifecycleService: LifecycleService
+ ) {
+ this._univerSlideConfig = UniverSlideData;
+ this._injector = this._initializeDependencies(parentInjector);
+ this._slideModel = this._injector.createInstance(SlideModel, UniverSlideData);
+
+ this._lifecycleService.lifecycle$.subscribe((stage) => {
+ if (stage === LifecycleStages.Rendered) {
+ this._pluginStore.forEachPlugin((p) => p.onRendered());
+ }
+ });
+
+ this._injector.get(LifecycleInitializerService).start();
}
getUnitId(): string {
@@ -70,18 +51,26 @@ export class UniverSlide {
* @internal
*/
addPlugin<T extends Plugin>(plugin: PluginCtor<T>, options: any): void {
- const pluginInstance: Plugin = this._slideInjector.createInstance(plugin as unknown as Ctor<any>, options);
+ const pluginInstance: Plugin = this._injector.createInstance(plugin as unknown as Ctor<any>, options);
pluginInstance.onRendered();
this._pluginStore.addPlugin(pluginInstance);
}
+ onReady(): void {
+ this._pluginStore.forEachPlugin((p) => p.onReady());
+ }
+
getSlideModel() {
return this._slideModel;
}
private _initializeDependencies(parentInjector?: Injector): Injector {
- const dependencies: Dependency[] = [[GenName]];
+ const dependencies: Dependency[] = [
+ [GenName],
+ [LifecycleInitializerService],
+ [ICommandService, { useClass: CommandService }],
+ ];
return parentInjector ? parentInjector.createChild(dependencies) : new Injector(dependencies);
}
}
diff --git a/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts b/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts
index ec6de64ac3..1bbfb26669 100644
--- a/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts
+++ b/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts
@@ -120,11 +120,10 @@ export class SheetUIController extends Disposable {
) {
super();
- this._initialize();
- this._initUI();
+ this._init();
}
- private _initialize(): void {
+ private _init(): void {
// init custom component
const componentManager = this._componentManager;
@@ -246,11 +245,8 @@ export class SheetUIController extends Disposable {
].forEach((item) => {
this.disposeWithMe(this._shortcutService.registerShortcut(item));
});
- }
- private _initUI(): void {
this.disposeWithMe(
- // WTF: redi type error
this._uiController.registerFooterComponent(() => connectInjector(RenderSheetFooter, this._injector))
);
}
diff --git a/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts b/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
index 27d3cfd7bc..e73dd36790 100644
--- a/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
+++ b/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
@@ -45,7 +45,7 @@ export class SheetUIPlugin extends Plugin {
).forEach((d) => injector.add(d));
}
- override onRendered(): void {
+ override onReady(): void {
this._markSheetAsFocused();
}
diff --git a/packages/ui-plugin-slides/src/Controller/AppUIController.ts b/packages/ui-plugin-slides/src/Controller/AppUIController.ts
index dafe169438..8ca615d7c0 100644
--- a/packages/ui-plugin-slides/src/Controller/AppUIController.ts
+++ b/packages/ui-plugin-slides/src/Controller/AppUIController.ts
@@ -17,6 +17,8 @@ export class AppUIController {
this._slideContainerUIController = this._injector.createInstance(SlideContainerUIController, config);
this._injector.add([SlideContainerUIController, { useValue: this._slideContainerUIController }]);
const UIConfig = this._slideContainerUIController.getUIConfig();
+
+ // TODO: put sidebar UI to the base-ui workbench container
}
/**
diff --git a/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts b/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts
index 98fe2274fb..d8e35c94a6 100644
--- a/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts
+++ b/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts
@@ -1,4 +1,3 @@
-import { BorderInfo } from '@univerjs/base-slides';
import { BaseSelectChildrenProps, BaseSelectProps, ColorPicker, ComponentManager } from '@univerjs/base-ui';
import {
BorderType,
@@ -36,6 +35,12 @@ export interface IToolbarItemProps extends BaseToolbarSelectProps {
suffix?: React.ReactNode;
}
+interface BorderInfo {
+ type: BorderType;
+ color: string;
+ style: number;
+}
+
export class ToolbarUIController {
private _toolbar?: Toolbar;
diff --git a/packages/ui-plugin-slides/src/Controller/slide-ui.controller.ts b/packages/ui-plugin-slides/src/Controller/slide-ui.controller.ts
new file mode 100644
index 0000000000..be676426be
--- /dev/null
+++ b/packages/ui-plugin-slides/src/Controller/slide-ui.controller.ts
@@ -0,0 +1,25 @@
+import { IDesktopUIController, IUIController } from '@univerjs/base-ui';
+import { Disposable, LifecycleStages, OnLifecycle } from '@univerjs/core';
+import { Inject, Injector } from '@wendellhu/redi';
+import { connectInjector } from '@wendellhu/redi/react-bindings';
+
+import { SlideBar } from '../View/SlideBar/SlideBar';
+
+/**
+ * This controller registers UI parts of slide workbench to the base-ui workbench.
+ */
+@OnLifecycle(LifecycleStages.Ready, SlideUIController)
+export class SlideUIController extends Disposable {
+ constructor(
+ @Inject(Injector) private readonly _injector: Injector,
+ @IUIController private readonly _uiController: IDesktopUIController
+ ) {
+ super();
+
+ this._init();
+ }
+
+ private _init(): void {
+ this._uiController.registerSidebarComponent(() => connectInjector(SlideBar, this._injector));
+ }
+}
diff --git a/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx b/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx
index cc2eec4ffd..3da957df41 100644
--- a/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx
+++ b/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx
@@ -1,5 +1,5 @@
-import { AppContext, BaseComponentProps, Button } from '@univerjs/base-ui';
-import { ISlidePage } from '@univerjs/core';
+import { AppContext, BaseComponentProps } from '@univerjs/base-ui';
+import { ICurrentUniverService, ISlidePage } from '@univerjs/core';
import { Component, createRef } from 'react';
import styles from './index.module.less';
@@ -14,24 +14,23 @@ interface IProps extends BaseComponentProps {
activeSlide: (pageId: string) => void;
}
-export class SlideBar extends Component<IProps, SlideBarState> {
+export class SlideBar extends Component<{}, SlideBarState> {
static override contextType = AppContext;
+ declare context: React.ContextType<typeof AppContext>;
+
slideBarRef = createRef<HTMLDivElement>();
- constructor(props: IProps) {
+ constructor(props: {}) {
super(props);
- this.initialize();
- }
- initialize() {
this.state = {
slideList: [],
};
}
override componentDidMount() {
- this.props.getComponent?.(this);
+ this._init();
}
isActive(pageId: string, index: number = 0) {
@@ -62,12 +61,33 @@ export class SlideBar extends Component<IProps, SlideBarState> {
activePageId: pageId,
});
- this.props.activeSlide(pageId);
+ // this.props.activeSlide(pageId);
+ }
+
+ private _init(): void {
+ // TODO: should subscribe to active slide change event
+ const currentUniverService = this.context.injector.get(ICurrentUniverService);
+ const model = currentUniverService.getCurrentUniverSlideInstance().getSlideModel();
+ const pages = model.getPages();
+ const pageOrder = model.getPageOrder();
+ if (!pages || !pageOrder) {
+ return;
+ }
+
+ const p: ISlidePage[] = [];
+ pageOrder.forEach((pageKey) => {
+ p.push(pages[pageKey]);
+ });
+
+ this.setState({
+ slideList: p,
+ });
}
override render() {
- const { addSlide } = this.props;
+ // const { addSlide } = this.props;
const { slideList } = this.state;
+ // TODO@wzhudev: manage slides in a SlideService
return (
<div className={styles.slideBar} ref={this.slideBarRef}>
@@ -83,9 +103,9 @@ export class SlideBar extends Component<IProps, SlideBarState> {
</div>
))}
</div>
- <div className={styles.slideAddButton}>
+ {/* <div className={styles.slideAddButton}>
<Button onClick={addSlide}>+</Button>
- </div>
+ </div> */}
</div>
);
}
diff --git a/packages/ui-plugin-slides/src/index.ts b/packages/ui-plugin-slides/src/index.ts
index bd5a757ea6..ccc1e646eb 100644
--- a/packages/ui-plugin-slides/src/index.ts
+++ b/packages/ui-plugin-slides/src/index.ts
@@ -1,2 +1,2 @@
export * from './Basics';
-export * from './SlideUIPlugin';
+export * from './slide-ui-plugin';
diff --git a/packages/ui-plugin-slides/src/SlideUIPlugin.ts b/packages/ui-plugin-slides/src/slide-ui-plugin.ts
similarity index 55%
rename from packages/ui-plugin-slides/src/SlideUIPlugin.ts
rename to packages/ui-plugin-slides/src/slide-ui-plugin.ts
index 489e78682d..532e75d63b 100644
--- a/packages/ui-plugin-slides/src/SlideUIPlugin.ts
+++ b/packages/ui-plugin-slides/src/slide-ui-plugin.ts
@@ -1,13 +1,12 @@
-import { IRenderingEngine } from '@univerjs/base-render';
-import { CanvasView } from '@univerjs/base-slides';
import { ComponentManager } from '@univerjs/base-ui';
-import { LocaleService, Plugin, PluginType, Tools } from '@univerjs/core';
+import { ICurrentUniverService, LocaleService, Plugin, PluginType, Tools } from '@univerjs/core';
import { Inject, Injector } from '@wendellhu/redi';
import { DefaultSlideUIConfig, ISlideUIPluginConfig } from './Basics';
import { SLIDE_UI_PLUGIN_NAME } from './Basics/Const/PLUGIN_NAME';
import { IToolbarItemProps } from './Controller';
import { AppUIController } from './Controller/AppUIController';
+import { SlideUIController } from './Controller/slide-ui.controller';
import { en } from './Locale';
export class SlideUIPlugin extends Plugin {
@@ -23,7 +22,7 @@ export class SlideUIPlugin extends Plugin {
config: Partial<ISlideUIPluginConfig> = {},
@Inject(Injector) override readonly _injector: Injector,
@Inject(LocaleService) private readonly _localeService: LocaleService,
- @Inject(CanvasView) private readonly _canvasView: CanvasView
+ @ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService
) {
super(SLIDE_UI_PLUGIN_NAME);
this._config = Tools.deepMerge({}, DefaultSlideUIConfig, config);
@@ -31,53 +30,20 @@ export class SlideUIPlugin extends Plugin {
this.initializeDependencies();
}
- initialize(): void {
- /**
- * load more Locale object
- */
- this._localeService.getLocale().load({
- en,
- });
-
- // AppUIController initializes the DOM as an asynchronous rendering process, and must wait for the UI rendering to complete before starting to render the canvas
- this.UIDidMount(() => {
- this.initRender();
- });
- }
-
getConfig() {
return this._config;
}
- initRender() {
- const engine = this._injector.get(IRenderingEngine);
- const container = this._appUIController!.getSlideContainerController().getContentRef().current;
- if (!container) {
- throw new Error('container is not ready');
- }
-
- // mount canvas to DOM container
- engine.setContainer(container);
-
- window.addEventListener('resize', () => {
- engine.resize();
+ override onStarting(): void {
+ this._localeService.getLocale().load({
+ en,
});
-
- // should be clear
- setTimeout(() => {
- engine.resize();
- this._canvasView.scrollToCenter();
- }, 0);
}
- initUI() {}
-
- override onRendered(): void {
- this.initialize();
+ override onReady(): void {
+ this._markSlideAsFocused();
}
- override onDestroy(): void {}
-
getAppUIController() {
return this._appUIController;
}
@@ -86,15 +52,6 @@ export class SlideUIPlugin extends Plugin {
return this._componentManager;
}
- /**
- * This API is used in plugins for initialization that depends on UI rendering
- * @param cb
- * @returns
- */
- UIDidMount(cb: Function) {
- this._appUIController!.getSlideContainerController().UIDidMount(cb);
- }
-
addToolButton(config: IToolbarItemProps) {
this._appUIController!.getSlideContainerController().getToolbarController().addToolbarConfig(config);
}
@@ -105,8 +62,15 @@ export class SlideUIPlugin extends Plugin {
private initializeDependencies(): void {
this._injector.add([ComponentManager]);
+ this._injector.add([SlideUIController]);
this._componentManager = this._injector.get(ComponentManager);
this._appUIController = this._injector.createInstance(AppUIController, this._config);
}
+
+ private _markSlideAsFocused() {
+ const currentService = this._currentUniverService;
+ const c = currentService.getCurrentUniverSlideInstance();
+ currentService.focusUniverInstance(c.getUnitId());
+ }
}