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(ui): adapt to new menu design

Dushusir3df180af50e9
diff --git a/packages/base-ui/src/Components/Menu/Menu.tsx b/packages/base-ui/src/Components/Menu/Menu.tsx
index 8243896c4d..6c3312ae28 100644
--- a/packages/base-ui/src/Components/Menu/Menu.tsx
+++ b/packages/base-ui/src/Components/Menu/Menu.tsx
@@ -216,13 +216,7 @@ export class Menu extends Component<BaseMenuProps, IBaseMenuState> {
}
private getSubMenus() {
- const { menuId, menu } = this.props;
-
- // TODO@Dushusir remove menu
- if (menu) {
- this.setState({ menuItems: menu as Array<IDisplayMenuItem<IMenuItem>> });
- return;
- }
+ const { menuId } = this.props;
if (menuId) {
const menuService: IMenuService = this.context.injector.get(IMenuService);
@@ -328,6 +322,8 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {
case MenuItemType.DROPDOWN:
case MenuItemType.SELECTOR:
return this.renderSelectorType();
+ case MenuItemType.SUBITEMS:
+ return this.renderSubItemsType();
default:
return this.renderButtonType();
}
@@ -340,7 +336,7 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {
return (
<li className={joinClassNames(styles.colsMenuitem, disabled ? styles.colsMenuitemDisabled : '')}>
- {/* FIXME use title*/}
+ {/* FIXME after translate title,use title for value display*/}
<NeoCustomLabel value={item.title} onChange={this.onChange}></NeoCustomLabel>
</li>
);
@@ -375,6 +371,37 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {
);
}
+ private renderSubItemsType(): ComponentChild {
+ const { menuItem, index } = this.props;
+ const { disabled, menuItems, value } = this.state;
+ const item = menuItem as IDisplayMenuItem<IMenuSelectorItem<unknown>>;
+ const commandService: ICommandService = this.context.injector.get(ICommandService);
+
+ return (
+ <li
+ className={joinClassNames(styles.colsMenuitem, disabled ? styles.colsMenuitemDisabled : '')}
+ onMouseEnter={(e) => this.mouseEnter(e, index)}
+ onMouseLeave={(e) => this.mouseLeave(e, index)}
+ onClick={(e) => this.handleClick(e, item, index)}
+ >
+
+ {/* FIXME after translate title,use title for value display */}
+ <NeoCustomLabel title={item.title} value={item.title} onChange={this.onChange} icon={item.icon} display={item.display}></NeoCustomLabel>
+ {item.shortcut && ` (${item.shortcut})`}
+ {(menuItems.length > 0 || (item as IMenuSelectorItem<unknown>).selections?.length) && (
+ <Menu
+ ref={(ele: Menu) => (this._refs[index] = ele)}
+ // onOptionSelect={(v) => commandService.executeCommand(item.id, { value: v.value })}
+ menuId={item.id}
+ // options={item.selections}
+ // display={item.display}
+ parent={this}
+ ></Menu>
+ )}
+ </li>
+ );
+ }
+
private getSubMenus() {
const { menuItem } = this.props;
const { id } = menuItem;
diff --git a/packages/base-ui/src/services/menu/menu.ts b/packages/base-ui/src/services/menu/menu.ts
index 03389aedec..d1c2ee57d7 100644
--- a/packages/base-ui/src/services/menu/menu.ts
+++ b/packages/base-ui/src/services/menu/menu.ts
@@ -20,8 +20,9 @@ export const enum MenuItemType {
/** Button style menu item. */
BUTTON,
/** Menu item with submenus. Submenus could be other IMenuItem or an ID of a registered component. */
- SELECTOR,
+ SELECTOR, // Multiple sub-options share one command
DROPDOWN,
+ SUBITEMS, // Multiple sub-menu items have different commands
}
interface IMenuItemBase {
@@ -88,7 +89,7 @@ export function isCustomComponentOption(v: IValueOption | ICustomComponentOption
}
export interface IMenuSelectorItem<V> extends IMenuItemBase {
- type: MenuItemType.SELECTOR | MenuItemType.DROPDOWN;
+ type: MenuItemType.SELECTOR | MenuItemType.DROPDOWN | MenuItemType.SUBITEMS;
/** Determines how the label of the selector should display. */
display?: DisplayTypes;
@@ -108,7 +109,7 @@ export interface IMenuSelectorItem<V> extends IMenuItemBase {
}
export function isMenuSelectorItem<T>(v: IMenuItem): v is IMenuSelectorItem<T> {
- return v.type === MenuItemType.SELECTOR || v.type === MenuItemType.DROPDOWN;
+ return v.type === MenuItemType.SELECTOR || v.type === MenuItemType.DROPDOWN || v.type === MenuItemType.SUBITEMS;
}
export type IMenuItem = IMenuButtonItem | IMenuSelectorItem<unknown>;
diff --git a/packages/ui-plugin-sheets/src/Controller/menu.ts b/packages/ui-plugin-sheets/src/Controller/menu.ts
index de3845e7e8..2fa29cb3f4 100644
--- a/packages/ui-plugin-sheets/src/Controller/menu.ts
+++ b/packages/ui-plugin-sheets/src/Controller/menu.ts
@@ -30,7 +30,7 @@ import {
SetWorksheetRowHideCommand,
SetWorksheetRowShowCommand,
} from '@univerjs/base-sheets';
-import { ColorPicker, DisplayTypes, IMenuButtonItem, IMenuItem, IMenuSelectorItem, MenuItemType, MenuPosition, SelectTypes, IDisplayMenuItem } from '@univerjs/base-ui';
+import { ColorPicker, DisplayTypes, IMenuButtonItem, IMenuItem, IMenuSelectorItem, MenuItemType, MenuPosition, SelectTypes, IDisplayMenuItem, IValueOption, ICustomComponentOption } from '@univerjs/base-ui';
import { FontItalic, FontWeight, ICommandService, IPermissionService, IUndoRedoService, RedoCommand, UndoCommand } from '@univerjs/core';
import { IAccessor } from '@wendellhu/redi';
@@ -571,60 +571,74 @@ export function ClearSelectionMenuItemFactory(accessor: IAccessor): IMenuButtonI
type: MenuItemType.BUTTON,
title: 'rightClick.clearContent',
positions: [MenuPosition.CONTEXT_MENU],
+ parentId: 'right-menu'
};
}
export function InsertRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: InsertRowCommand.id,
+ type: MenuItemType.BUTTON,
positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.insertRow',
+ parentId: 'right-menu'
};
}
export function InsertColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: InsertColCommand.id,
+ type: MenuItemType.BUTTON,
positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.insertColumn',
+ parentId: 'right-menu'
};
}
export function RemoveRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: RemoveRowCommand.id,
+ type: MenuItemType.BUTTON,
positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.deleteSelectedRow',
+ parentId: 'right-menu'
};
}
export function HideRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: SetWorksheetRowHideCommand.id,
+ type: MenuItemType.BUTTON,
positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.hideSelectedRow',
+ parentId: 'right-menu'
};
}
export function ShowRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: SetWorksheetRowShowCommand.id,
+ type: MenuItemType.BUTTON,
positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.showHideRow',
+ parentId: 'right-menu'
};
}
export function RemoveColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: RemoveColCommand.id,
+ type: MenuItemType.BUTTON,
positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.deleteSelectedColumn',
+ parentId: 'right-menu'
};
}
export function SetRowHeightMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: SetWorksheetRowHeightCommand.id,
+ type: MenuItemType.BUTTON,
positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.rowHeight',
label: {
@@ -634,12 +648,14 @@ export function SetRowHeightMenuItemFactory(accessor: IAccessor): IMenuButtonIte
suffix: 'px',
},
},
+ parentId: 'right-menu'
};
}
export function SetColWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: SetWorksheetColWidthCommand.id,
+ type: MenuItemType.BUTTON,
positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.columnWidth',
label: {
@@ -649,20 +665,24 @@ export function SetColWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItem
suffix: 'px',
},
},
+ parentId: 'right-menu',
};
}
export function DeleteRangeMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
return {
id: DeleteRangeCommand.id,
+ type: MenuItemType.SUBITEMS, // 子菜单也需要单独command id,无法使用selector的selections
positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.deleteCell',
+ parentId: 'right-menu',
};
}
export function DeleteRangeMoveLeftMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: DeleteRangeMoveLeftCommand.id,
+ type: MenuItemType.BUTTON,
positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.moveLeft',
parentId: DeleteRangeCommand.id,
@@ -672,6 +692,7 @@ export function DeleteRangeMoveLeftMenuItemFactory(accessor: IAccessor): IMenuBu
export function DeleteRangeMoveUpMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: DeleteRangeMoveUpCommand.id,
+ type: MenuItemType.BUTTON,
positions: [MenuPosition.CONTEXT_MENU],
title: 'rightClick.moveUp',
parentId: DeleteRangeCommand.id,
diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
index 4cdb3badc0..8684472152 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
@@ -159,7 +159,7 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
e.preventDefault();
}}
>
- <Menu ref={this.ulRef} menu={this.state.menuItems} onClick={this.handleClick}></Menu>
+ <Menu ref={this.ulRef} menuId={'right-menu'} onClick={this.handleClick}></Menu>
</div>
)
);