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.

feat(facade): add ui facade (#4452)

zhangw6b723c9db0f8
diff --git a/packages/ui/src/facade/f-univer.ts b/packages/ui/src/facade/f-univer.ts
index 022646424d..1e44b372ec 100644
--- a/packages/ui/src/facade/f-univer.ts
+++ b/packages/ui/src/facade/f-univer.ts
@@ -18,7 +18,7 @@ import type { IDisposable } from '@univerjs/core';
import type { IMessageProps } from '@univerjs/design';
import type { BuiltInUIPart, IDialogPartMethodOptions, ISidebarMethodOptions } from '@univerjs/ui';
import type { IFacadeMenuItem, IFacadeSubmenuItem } from './f-menu-builder';
-import { FUniver } from '@univerjs/core';
+import { connectInjector, FUniver } from '@univerjs/core';
import { ComponentManager, CopyCommand, IDialogService, IMessageService, ISidebarService, IUIPartsService, PasteCommand } from '@univerjs/ui';
import { FMenu, FSubmenu } from './f-menu-builder';
import { FShortcut } from './f-shortcut';
@@ -44,7 +44,6 @@ export interface IFUniverUIMixin {
/**
* Create a menu build object. You can insert new menus into the UI.
* @param {IFacadeMenuItem} menuItem the menu item
- *
* @example
* ```ts
* univerAPI.createMenu({
@@ -53,14 +52,12 @@ export interface IFUniverUIMixin {
* action: () => {},
* }).appendTo('ribbon.start.others');
* ```
- *
* @returns the {@link FMenu} object
*/
createMenu(menuItem: IFacadeMenuItem): FMenu;
/**
* Create a menu that contains submenus, and later you can append this menu and its submenus to the UI.
* @param submenuItem the submenu item
- *
* @example
* ```ts
* univerAPI.createSubmenu({ id: 'custom-submenu', title: 'Custom Submenu' })
@@ -71,13 +68,11 @@ export interface IFUniverUIMixin {
* )
* .appendTo('contextMenu.others');
* ```
- *
* @returns the {@link FSubmenu} object
*/
createSubmenu(submenuItem: IFacadeSubmenuItem): FSubmenu;
/**
* Open a sidebar.
- *
* @deprecated Please use `openSidebar` instead.
* @param params the sidebar options
* @returns the disposable object
@@ -85,7 +80,6 @@ export interface IFUniverUIMixin {
openSiderbar(params: ISidebarMethodOptions): IDisposable;
/**
* Open a sidebar.
- *
* @deprecated Please use `openSidebar` instead.
* @param params the sidebar options
* @returns the disposable object
@@ -104,7 +98,6 @@ export interface IFUniverUIMixin {
getComponentManager(): ComponentManager;
/**
* Show a message.
- *
* @example
* ```ts
* const message = univerAPI.showMessage({ key: 'my-message', content: 'Warning', duration: 0 });
@@ -136,6 +129,17 @@ export interface IFUniverUIMixin {
* ```
*/
isUIVisible(key: BuiltInUIPart): boolean;
+
+ /**
+ * register an component to a built-in UI part
+ * @param key the built-in UI part
+ * @param component the react component
+ * @example
+ * ```ts
+ * univerAPI.registerUIPart(BuiltInUIPart.CUSTOM_HEADER, () => React.createElement('h1', null, 'Custom Header'));
+ * ```
+ */
+ registerUIPart(key: BuiltInUIPart, component: any): IDisposable;
}
export class FUniverUIMixin extends FUniver implements IFUniverUIMixin {
@@ -203,6 +207,11 @@ export class FUniverUIMixin extends FUniver implements IFUniverUIMixin {
const uiPartService = this._injector.get(IUIPartsService);
return uiPartService.isUIVisible(ui);
}
+
+ override registerUIPart(key: BuiltInUIPart, component: any): IDisposable {
+ const uiPartService = this._injector.get(IUIPartsService);
+ return uiPartService.registerComponent(key, () => connectInjector(component, this._injector));
+ }
}
FUniver.extend(FUniverUIMixin);
diff --git a/packages/ui/src/services/parts/parts.service.ts b/packages/ui/src/services/parts/parts.service.ts
index aeb64f93cb..79926e40ef 100644
--- a/packages/ui/src/services/parts/parts.service.ts
+++ b/packages/ui/src/services/parts/parts.service.ts
@@ -32,6 +32,9 @@ export enum BuiltInUIPart {
FLOATING = 'floating',
UNIT = 'unit',
CUSTOM_HEADER = 'custom-header',
+ CUSTOM_LEFT = 'custom-left',
+ CUSTOM_RIGHT = 'custom-right',
+ CUSTOM_FOOTER = 'custom-footer',
}
export interface IUIPartsService {