Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
refactor: remove legacy menu service (#4068)
白熱85301bde4871
diff --git a/examples-node/.gitignore b/examples-node/.gitignoreindex 849ddff3b7..68c21795a7 100644--- a/examples-node/.gitignore+++ b/examples-node/.gitignore@@ -1 +1,2 @@dist/+src/locales.tsdiff --git a/examples-node/package.json b/examples-node/package.jsonindex 6c73a9ac52..96c159e6e9 100644--- a/examples-node/package.json+++ b/examples-node/package.json@@ -9,8 +9,9 @@"./*": "./src/*"},"scripts": {+ "prepare": "node ./scripts/generate-locales.mjs","build:demo": "node ./esbuild.config.mjs",- "lint:types": "node ./scripts/generate-locales.mjs && tsc --noEmit"+ "lint:types": "tsc --noEmit"},"dependencies": {"@univerjs/core": "workspace:*",diff --git a/examples-node/src/locales.ts b/examples-node/src/locales.tsdeleted file mode 100644index 76e38a9078..0000000000--- a/examples-node/src/locales.ts+++ /dev/null@@ -1,61 +0,0 @@-/**- * Copyright 2023-present DreamNum Inc.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import { Tools } from '@univerjs/core';--import sheetsenUS from '@univerjs/sheets/locale/en-US';-import sheetsfaIR from '@univerjs/sheets/locale/fa-IR';-import sheetsruRU from '@univerjs/sheets/locale/ru-RU';-import sheetsviVN from '@univerjs/sheets/locale/vi-VN';-import sheetszhCN from '@univerjs/sheets/locale/zh-CN';-import sheetszhTW from '@univerjs/sheets/locale/zh-TW';-import sheetssortenUS from '@univerjs/sheets-sort/locale/en-US';-import sheetssortfaIR from '@univerjs/sheets-sort/locale/fa-IR';-import sheetssortruRU from '@univerjs/sheets-sort/locale/ru-RU';-import sheetssortviVN from '@univerjs/sheets-sort/locale/vi-VN';-import sheetssortzhCN from '@univerjs/sheets-sort/locale/zh-CN';-import sheetssortzhTW from '@univerjs/sheets-sort/locale/zh-TW';--export const enUS = Tools.deepMerge(- {},- sheetsenUS,- sheetssortenUS-);-export const ruRU = Tools.deepMerge(- {},- sheetsruRU,- sheetssortruRU-);-export const zhCN = Tools.deepMerge(- {},- sheetszhCN,- sheetssortzhCN-);-export const zhTW = Tools.deepMerge(- {},- sheetszhTW,- sheetssortzhTW-);-export const viVN = Tools.deepMerge(- {},- sheetsviVN,- sheetssortviVN-);-export const faIR = Tools.deepMerge(- {},- sheetsfaIR,- sheetssortfaIR-);diff --git a/packages-experimental/uniui/src/plugin.ts b/packages-experimental/uniui/src/plugin.tsindex 99714e4a0a..ea1827d308 100644--- a/packages-experimental/uniui/src/plugin.ts+++ b/packages-experimental/uniui/src/plugin.ts@@ -48,7 +48,6 @@ import {ILeftSidebarService,ILocalFileService,IMenuManagerService,- IMenuService,IMessageService,INotificationService,IPlatformService,@@ -58,7 +57,6 @@ import {IUIPartsService,IZenZoneService,MenuManagerService,- MenuService,PlatformService,SharedController,ShortcutPanelController,@@ -109,7 +107,6 @@ export class UniverUniUIPlugin extends Plugin {[ILayoutService, { useClass: DesktopLayoutService }],[IShortcutService, { useClass: ShortcutService }],[IPlatformService, { useClass: PlatformService }],- [IMenuService, { useClass: MenuService }],[IMenuManagerService, { useClass: MenuManagerService }],[IContextMenuService, { useClass: ContextMenuService }],[IClipboardInterfaceService, { useClass: BrowserClipboardService, lazy: true }],diff --git a/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.stories.tsx b/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.stories.tsxindex 8b5ce3eccf..68dca8f0fd 100644--- a/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.stories.tsx+++ b/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.stories.tsx@@ -21,7 +21,7 @@ import { CommandType, ICommandService, ILogService, LocaleService, LocaleType, Limport { RefRangeService, SheetInterceptorService, SheetsSelectionsService, WorksheetProtectionPointModel } from '@univerjs/sheets';import { ClearSheetsFilterCriteriaCommand, ReCalcSheetsFilterCommand, SetSheetsFilterCriteriaCommand, SmartToggleSheetsFilterCommand, UniverSheetsFilterPlugin } from '@univerjs/sheets-filter';import { SetCellEditVisibleOperation } from '@univerjs/sheets-ui';-import { IMenuService, IShortcutService, MenuService, ShortcutService } from '@univerjs/ui';+import { IShortcutService, ShortcutService } from '@univerjs/ui';import React, { useState } from 'react';import { WithCustomFilterModelFactory, WithValuesFilterModelFactory } from '../../__testing__/data';import { ChangeFilterByOperation, CloseFilterPanelOperation, OpenFilterPanelOperation } from '../../commands/operations/sheets-filter.operation';@@ -61,7 +61,6 @@ function createFilterStorybookBed(workbookData: IWorkbookData, locale: LocaleTypconst injector = this._injector;injector.add([SheetsSelectionsService]);injector.add([IShortcutService, { useClass: ShortcutService }]);- injector.add([IMenuService, { useClass: MenuService }]);injector.add([WorksheetProtectionPointModel]);injector.add([SheetInterceptorService]);injector.add([SheetsFilterPanelService]);diff --git a/packages/sheets-hyper-link-ui/src/controllers/menu.ts b/packages/sheets-hyper-link-ui/src/controllers/menu.tsindex ae263907e6..c4c15999a7 100644--- a/packages/sheets-hyper-link-ui/src/controllers/menu.ts+++ b/packages/sheets-hyper-link-ui/src/controllers/menu.ts@@ -22,7 +22,7 @@ import { DocSelectionRenderService } from '@univerjs/docs-ui';import { IRenderManagerService } from '@univerjs/engine-render';import { getSheetCommandTarget, RangeProtectionPermissionEditPoint, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetInsertHyperlinkPermission, WorksheetSetCellValuePermission } from '@univerjs/sheets';import { getCurrentRangeDisable$, IEditorBridgeService, whenSheetEditorFocused } from '@univerjs/sheets-ui';-import { getMenuHiddenObservable, KeyCode, MenuGroup, MenuItemType, MenuPosition, MetaKeys } from '@univerjs/ui';+import { getMenuHiddenObservable, KeyCode, MenuItemType, MetaKeys } from '@univerjs/ui';import { combineLatest, distinctUntilChanged, filter, map, of, switchMap } from 'rxjs';import { InsertHyperLinkOperation, InsertHyperLinkToolbarOperation } from '../commands/operations/popup.operations';import { getShouldDisableCellLink, shouldDisableAddLink } from '../utils';@@ -112,7 +112,6 @@ const getLinkDisable$ = (accessor: IAccessor) => {const linkMenu = {commandId: InsertHyperLinkOperation.id,type: MenuItemType.BUTTON,- positions: [MenuPosition.CONTEXT_MENU],title: 'hyperLink.menu.add',icon: 'LinkSingle',};@@ -140,8 +139,6 @@ export const zenEditorInsertLinkMenuFactory = (accessor: IAccessor) => {const linkToolbarMenu = {tooltip: 'hyperLink.form.addTitle',- positions: MenuPosition.TOOLBAR_START,- group: MenuGroup.TOOLBAR_OTHERS,commandId: InsertHyperLinkToolbarOperation.id,type: MenuItemType.BUTTON,icon: 'LinkSingle',diff --git a/packages/ui/src/common/menu-merge-configs.ts b/packages/ui/src/common/menu-merge-configs.tsindex 3b1b7b960b..d8f840456e 100644--- a/packages/ui/src/common/menu-merge-configs.ts+++ b/packages/ui/src/common/menu-merge-configs.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import { BehaviorSubject, Observable, switchMap } from 'rxjs';import type { MenuConfig, MenuItemConfig } from '../services/menu/menu';+import { BehaviorSubject, Observable, switchMap } from 'rxjs';export function mergeMenuConfigs<T = MenuConfig>(baseConfig: T, additionalConfig: MenuItemConfig | null): T {if (!additionalConfig || !baseConfig) return baseConfig;@@ -24,7 +24,7 @@ export function mergeMenuConfigs<T = MenuConfig>(baseConfig: T, additionalConfigconst { hidden, disabled, activated } = additionalConfig;// Update properties directly if they exist in additionalConfig- const properties: (keyof MenuItemConfig)[] = ['group', 'type', 'icon', 'title', 'tooltip', 'positions'];+ const properties: (keyof MenuItemConfig)[] = ['type', 'icon', 'title', 'tooltip'];properties.forEach((prop) => {if (additionalConfig[prop] !== undefined) {// Use type assertion to assure TypeScript about the operation's safetydiff --git a/packages/ui/src/index.ts b/packages/ui/src/index.tsindex 8839e32724..80e56361fa 100644--- a/packages/ui/src/index.ts+++ b/packages/ui/src/index.ts@@ -74,12 +74,9 @@ export {type IMenuSelectorItem,type IValueOption,type MenuConfig,- MenuGroup,type MenuItemDefaultValueType,MenuItemType,- MenuPosition,} from './services/menu/menu';-export { IMenuService, MenuService } from './services/menu/menu.service';export { IMenuManagerService, MenuManagerService, type MenuSchemaType } from './services/menu/menu-manager.service';export { type IMenuSchema } from './services/menu/menu-manager.service';export {@@ -128,7 +125,7 @@ export { FloatDom } from './views/components/dom/FloatDom';export { GlobalZone } from './views/components/global-zone/GlobalZone';export { CanvasPopup } from './views/components/popup/CanvasPopup';export { ToolbarButton } from './views/components/ribbon/Button/ToolbarButton';-export { type IMenuGroup, useSimpleToolbarGroups, useToolbarGroups, useToolbarItemStatus } from './views/components/ribbon/hook';+export { useToolbarItemStatus } from './views/components/ribbon/hook';export { Ribbon } from './views/components/ribbon/Ribbon';export { ToolbarItem } from './views/components/ribbon/ToolbarItem';export { type ISidebarMethodOptions } from './views/components/sidebar/interface';diff --git a/packages/ui/src/mobile-ui-plugin.ts b/packages/ui/src/mobile-ui-plugin.tsindex 0d30ae5676..24c64db754 100644--- a/packages/ui/src/mobile-ui-plugin.ts+++ b/packages/ui/src/mobile-ui-plugin.ts@@ -36,7 +36,6 @@ import { DesktopGlobalZoneService } from './services/global-zone/desktop-global-import { IGlobalZoneService } from './services/global-zone/global-zone.service';import { DesktopLayoutService, ILayoutService } from './services/layout/layout.service';import { DesktopLocalStorageService } from './services/local-storage/local-storage.service';-import { IMenuService, MenuService } from './services/menu/menu.service';import { IMenuManagerService, MenuManagerService } from './services/menu/menu-manager.service';import { DesktopMessageService } from './services/message/desktop-message.service';import { IMessageService } from './services/message/message.service';@@ -79,7 +78,6 @@ export class UniverMobileUIPlugin extends Plugin {[ILayoutService, { useClass: DesktopLayoutService }],[IShortcutService, { useClass: ShortcutService }],[IPlatformService, { useClass: PlatformService }],- [IMenuService, { useClass: MenuService }],[IMenuManagerService, { useClass: MenuManagerService }],[IContextMenuService, { useClass: ContextMenuService }],[IClipboardInterfaceService, { useClass: BrowserClipboardService, lazy: true }],diff --git a/packages/ui/src/services/menu/menu.service.ts b/packages/ui/src/services/menu/menu.service.tsdeleted file mode 100644index 3d5c7721e2..0000000000--- a/packages/ui/src/services/menu/menu.service.ts+++ /dev/null@@ -1,267 +0,0 @@-/**- * Copyright 2023-present DreamNum Inc.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import { createIdentifier, Disposable, ILogService, toDisposable } from '@univerjs/core';-import type { IDisposable } from '@univerjs/core';-import type { Observable } from 'rxjs';-import { BehaviorSubject } from 'rxjs';--import { IShortcutService } from '../shortcut/shortcut.service';-import { mergeMenuConfigs } from '../../common/menu-merge-configs';-import type { IDisplayMenuItem, IMenuItem, MenuConfig } from './menu';-import { MenuPosition } from './menu';-import { IMenuManagerService } from './menu-manager.service';-import { ContextMenuGroup, RibbonOthersGroup } from './types';--/** @deprecated */-export const IMenuService = createIdentifier<IMenuService>('univer.menu-service');--/**- * Breaking changes to IMenuService are expected in the next version. Use with caution. by @jikkai- * @deprecated- */-export interface IMenuService {- menuChanged$: Observable<void>;-- /** @deprecated */- addMenuItem(item: IMenuItem, config: MenuConfig): IDisposable;-- /** @deprecated */- setMenuItem(item: IMenuItem): void;-- /** Get menu items for display at a given position or a submenu. */- /** @deprecated */- getMenuItems(position: MenuPosition | string): Array<IDisplayMenuItem<IMenuItem>>;- /** @deprecated */- getMenuItem(id: string): IMenuItem | null;-}--/** @deprecated */-export class MenuService extends Disposable implements IMenuService {- /** @deprecated */- private readonly _menuItemMap = new Map<string, IMenuItem>();-- /** @deprecated */- private readonly _menuByPositions = new Map<MenuPosition | string, Array<[string, IMenuItem]>>();-- /** @deprecated */- private readonly _menuConfigs = new Map<string, MenuConfig>();-- private _menuChanged$ = new BehaviorSubject<void>(undefined);-- menuChanged$: Observable<void> = this._menuChanged$.asObservable();-- constructor(- @IShortcutService private readonly _shortcutService: IShortcutService,- @IMenuManagerService private readonly _menuManagerService: IMenuManagerService,- @ILogService protected readonly _logService: ILogService- ) {- super();- }-- override dispose(): void {- this._menuItemMap.clear();- this._menuChanged$.complete();- }-- /** @deprecated */- addMenuItem(item: IMenuItem, config: MenuConfig): IDisposable {- this._logService.warn('[MenuService]: MenuService is deprecated, please use MenuManagerService instead.');- if (this._menuItemMap.has(item.id)) {- throw new Error(`Menu item with the same id ${item.id} has already been added!`);- }-- const menuItemConfig = config?.[item.id];-- this._menuItemMap.set(item.id, mergeMenuConfigs(item, menuItemConfig));-- if (Array.isArray(item.positions)) {- item.positions.forEach((menu) => this._appendMenuToPosition(item, menu));- } else if (item.positions) {- this._appendMenuToPosition(item, item.positions);- }-- // TODO: Compatible with old menu service- [- MenuPosition.TOOLBAR_START,- MenuPosition.TOOLBAR_INSERT,- MenuPosition.TOOLBAR_FORMULAS,- MenuPosition.TOOLBAR_DATA,- MenuPosition.TOOLBAR_VIEW,- MenuPosition.TOOLBAR_OTHERS,- MenuPosition.CONTEXT_MENU,- ].forEach((position) => {- if (position !== MenuPosition.CONTEXT_MENU) {- const menus = this.getMenuItems(position);- menus.forEach((menu) => {- this._menuManagerService.mergeMenu({- [position]: {- [menu.group ?? RibbonOthersGroup.OTHERS]: {- [menu.id]: {- menuItemFactory: () => menu,- },- },- },- });- });- } else {- const menus = this.getMenuItems(position);- menus.forEach((menu) => {- this._menuManagerService.mergeMenu({- [position]: {- [menu.group ?? ContextMenuGroup.OTHERS]: {- [menu.id]: {- menuItemFactory: () => menu,- },- },- },- });- });- }- });-- this._menuChanged$.next();-- return toDisposable(() => {- this._menuItemMap.delete(item.id);-- if (Array.isArray(item.positions)) {- item.positions.forEach((menu) => {- const menus = this._menuByPositions.get(menu);- if (!menus) {- return;- }-- const index = menus.findIndex((m) => m[0] === item.id);- if (index > -1) {- menus.splice(index, 1);- }- });- } else if (item.positions) {- const menus = this._menuByPositions.get(item.positions);- if (!menus) {- return;- }-- const index = menus.findIndex((m) => m[0] === item.id);- if (index > -1) {- menus.splice(index, 1);- }- }-- this._menuChanged$.next();- });- }-- /** @deprecated */- getMenuItems(positions: MenuPosition | string): Array<IDisplayMenuItem<IMenuItem>> {- this._logService.warn('[MenuService]: MenuService is deprecated, please use MenuManagerService instead.');- // TODO: @wzhudev: compose shortcut to returned menu items.- if (this._menuByPositions.has(positions)) {- const menuItems = this._menuByPositions.get(positions);-- if (menuItems) {- return [...menuItems.values()].map((menu) => this._getDisplayMenuItems(menu[1]));- }- }-- return [] as Array<IDisplayMenuItem<IMenuItem>>;- }-- /** @deprecated */- setMenuItem(item: IMenuItem): void {- this._logService.warn('[MenuService]: MenuService is deprecated, please use MenuManagerService instead.');- this._menuItemMap.set(item.id, item);- if (Array.isArray(item.positions)) {- item.positions.forEach((menu) => this._updateMenuItems(item, menu));- } else if (item.positions) {- this._updateMenuItems(item, item.positions);- }-- this._menuChanged$.next();- }-- /** @deprecated */- getMenuItem(id: string): IMenuItem | null {- this._logService.warn('[MenuService]: MenuService is deprecated, please use MenuManagerService instead.');- if (this._menuItemMap.has(id)) {- return this._menuItemMap.get(id)!;- }-- return null;- }-- /** @deprecated */- setMenuConfigs(id: string, config: MenuConfig): void {- this._logService.warn('[MenuService]: MenuService is deprecated, please use MenuManagerService instead.');- this._menuConfigs.set(id, config);- }-- /** @deprecated */- getMenuConfig(id: string): MenuConfig | null {- this._logService.warn('[MenuService]: MenuService is deprecated, please use MenuManagerService instead.');- if (this._menuConfigs.has(id)) {- return this._menuConfigs.get(id)!;- }-- return null;- }-- /** @deprecated */- private _getDisplayMenuItems(menuItem: IMenuItem): IDisplayMenuItem<IMenuItem> {- this._logService.warn('[MenuService]: MenuService is deprecated, please use MenuManagerService instead.');- const shortcut = this._shortcutService.getShortcutDisplayOfCommand(menuItem.id);- if (!shortcut) {- return menuItem;- }-- return {- ...menuItem,- shortcut,- };- }-- /** @deprecated */- private _appendMenuToPosition(menu: IMenuItem, position: MenuPosition | string) {- this._logService.warn('[MenuService]: MenuService is deprecated, please use MenuManagerService instead.');- if (!this._menuByPositions.has(position)) {- this._menuByPositions.set(position, []);- }-- const menuList = this._menuByPositions.get(position)!;- if (menuList.findIndex((m) => m[0] === menu.id) > -1) {- throw new Error(`Menu item with the same id ${menu.id} has already been added!`);- }-- menuList.push([menu.id, menu]);- }-- /** @deprecated */- private _updateMenuItems(menu: IMenuItem, position: MenuPosition | string) {- this._logService.warn('[MenuService]: MenuService is deprecated, please use MenuManagerService instead.');- if (!this._menuByPositions.has(position)) {- this._menuByPositions.set(position, []);- }-- const menuList = this._menuByPositions.get(position)!;- const index = menuList.findIndex((m) => m[0] === menu.id);- if (index > -1) {- menuList[index] = [menu.id, menu];- } else {- menuList.push([menu.id, menu]);- }- }-}diff --git a/packages/ui/src/services/menu/menu.ts b/packages/ui/src/services/menu/menu.tsindex 3e774d3b38..1b59831416 100644--- a/packages/ui/src/services/menu/menu.ts+++ b/packages/ui/src/services/menu/menu.ts@@ -16,46 +16,9 @@import type { IAccessor } from '@univerjs/core';import type { Observable } from 'rxjs';-import { ContextMenuPosition, RibbonPosition } from './types';export type OneOrMany<T> = T | T[];-/** @deprecated */-export enum MenuPosition {- VOID = 'void',- // TOOLBAR_START = 'uiToolbar.start',- // TOOLBAR_INSERT = 'uiToolbar.insert',- // TOOLBAR_FORMULAS = 'uiToolbar.formulas',- // TOOLBAR_DATA = 'uiToolbar.data',- // TOOLBAR_VIEW = 'uiToolbar.view',- // TOOLBAR_OTHERS = 'uiToolbar.others',- // CONTEXT_MENU = 'contextMenu',- TOOLBAR_START = RibbonPosition.START,- TOOLBAR_INSERT = RibbonPosition.INSERT,- TOOLBAR_FORMULAS = RibbonPosition.FORMULAS,- TOOLBAR_DATA = RibbonPosition.DATA,- TOOLBAR_VIEW = RibbonPosition.VIEW,- TOOLBAR_OTHERS = RibbonPosition.OTHERS,- CONTEXT_MENU = ContextMenuPosition.MAIN_AREA,- FOOTER = 'footer',-}--/** @deprecated */-export enum MenuGroup {- TOOLBAR_HISTORY,- TOOLBAR_FORMAT,- TOOLBAR_LAYOUT,- TOOLBAR_FORMULAS_INSERT,- TOOLBAR_FORMULAS_VIEW,- TOOLBAR_FILE,- TOOLBAR_OTHERS,-- CONTEXT_MENU_FORMAT,- CONTEXT_MENU_LAYOUT,- CONTEXT_MENU_DATA,- CONTEXT_MENU_OTHERS,-}-export enum MenuItemType {/** Button style menu item. */BUTTON,@@ -83,14 +46,6 @@ interface IMenuItemBase<V> {icon?: string | Observable<string>;tooltip?: string;- /** The group that the item belongs to. */- /** @deprecated group will be removed in the future. */- group?: MenuGroup;-- /** In what menu should the item display. */- /** @deprecated positions will be removed in the future. */- positions?: OneOrMany<MenuPosition | string>;-type: MenuItemType;/**@@ -173,7 +128,6 @@ export type IDisplayMenuItem<T extends IMenuItem> = T & {};export type MenuItemConfig<T extends MenuItemDefaultValueType = MenuItemDefaultValueType> = Partial<Omit<IMenuItem, 'id' | 'subId' | 'value$' | 'hidden$' | 'disabled$' | 'activated$' | 'icon$'> & {- // defaultValue?: T;hidden?: boolean;disabled?: boolean;activated?: boolean;diff --git a/packages/ui/src/ui-plugin.ts b/packages/ui/src/ui-plugin.tsindex 785464588d..17999e3522 100644--- a/packages/ui/src/ui-plugin.ts+++ b/packages/ui/src/ui-plugin.ts@@ -41,7 +41,6 @@ import { DesktopLayoutService, ILayoutService } from './services/layout/layout.simport { DesktopLocalFileService } from './services/local-file/desktop-local-file.service';import { ILocalFileService } from './services/local-file/local-file.service';import { DesktopLocalStorageService } from './services/local-storage/local-storage.service';-import { IMenuService, MenuService } from './services/menu/menu.service';import { IMenuManagerService, MenuManagerService } from './services/menu/menu-manager.service';import { DesktopMessageService } from './services/message/desktop-message.service';import { IMessageService } from './services/message/message.service';@@ -96,7 +95,6 @@ export class UniverUIPlugin extends Plugin {[ILayoutService, { useClass: DesktopLayoutService }],[IShortcutService, { useClass: ShortcutService }],[IPlatformService, { useClass: PlatformService }],- [IMenuService, { useClass: MenuService }],[IMenuManagerService, { useClass: MenuManagerService }],[IContextMenuService, { useClass: ContextMenuService }],[IClipboardInterfaceService, { useClass: BrowserClipboardService, lazy: true }],diff --git a/packages/ui/src/views/components/ribbon/hook.ts b/packages/ui/src/views/components/ribbon/hook.tsindex a3d1396ece..bca952a4ae 100644--- a/packages/ui/src/views/components/ribbon/hook.ts+++ b/packages/ui/src/views/components/ribbon/hook.ts@@ -14,114 +14,9 @@* limitations under the License.*/-import { useEffect, useMemo, useState } from 'react';import type { Subscription } from 'rxjs';-import { combineLatest, map, Observable } from 'rxjs';-import { useDependency } from '@univerjs/core';-import { type IDisplayMenuItem, type IMenuItem, MenuGroup, MenuPosition } from '../../../services/menu/menu';-import { IMenuService } from '../../../services/menu/menu.service';--type MenuPositionWithCustom = MenuPosition | string;--export interface IMenuGroup {- name: MenuPositionWithCustom;- menuItems: Array<IDisplayMenuItem<IMenuItem>>;-}--export interface IToolbarRenderHookHandler {- /** The activated category. */- category: MenuPositionWithCustom;-- /** Update current activate category. */- setCategory: (position: MenuPositionWithCustom) => void;-- visibleItems: IDisplayMenuItem<IMenuItem>[];-- /** Menu grouped in this category. */- groups: IMenuGroup[];-- groupsByKey: Record<MenuGroup, Array<IDisplayMenuItem<IMenuItem>>>;-}--export function useSimpleToolbarGroups(category: MenuPositionWithCustom): IDisplayMenuItem<IMenuItem>[] {- const menuService = useDependency(IMenuService);- const [visibleItems, setVisibleItems] = useState<IDisplayMenuItem<IMenuItem>[]>([]);-- useEffect(() => {- const s = menuService.menuChanged$.subscribe(() => {- const menuItems = menuService.getMenuItems(category);- setVisibleItems(menuItems);- });-- return () => s.unsubscribe();- }, [menuService, category]);-- return visibleItems;-}--/**- * If your custom toolbar component need to render menu items by their category,- * you can use this hook to get the toolbar status.- * @returns toolbar status- */-export function useToolbarGroups(categories: MenuPositionWithCustom[], initCategory?: string): IToolbarRenderHookHandler {- const menuService = useDependency(IMenuService);- const [category, setCategory] = useState<MenuPositionWithCustom>(initCategory ?? MenuPosition.TOOLBAR_START);- const [groups, setGroups] = useState<IMenuGroup[]>([]);- const [visibleItems, setVisibleItems] = useState<IDisplayMenuItem<IMenuItem>[]>([]);-- // Update visible menu items when the active group changes or the visibility of an item (hidden$) changes.- useEffect(() => {- const activeItems = groups.find((g) => g.name === category)?.menuItems ?? [];- const filteredItems$ = combineLatest(- activeItems.map((item) => item.hidden$ ?? new Observable((observer) => observer.next(false)))- ).pipe(map((hiddenValues) => activeItems.filter((_, index) => !hiddenValues[index])));-- const s = filteredItems$.subscribe((items) => setVisibleItems(items));- return () => s.unsubscribe();- }, [groups, category]);-- // Update menu items when new items get registered or old items get unregistered.- useEffect(() => {- const s = menuService.menuChanged$.subscribe(() => {- const group: IMenuGroup[] = [];- for (const position of categories) {- const menuItems = menuService.getMenuItems(position);- if (menuItems.length) {- group.push({ name: position, menuItems });- }- }-- setGroups(group);- });-- return () => s.unsubscribe();- }, [menuService, category, categories]);-- // groupsByKey see menu/menu.ts @MenuGroup- const groupsByKey = useMemo(() => {- return groups.find((g) => g.name === category)?.menuItems.reduce(- (acc, item) => {- const key = item.group ?? MenuGroup.TOOLBAR_OTHERS;- if (!acc[key]) {- acc[key] = [];- }-- acc[key].push(item);- return acc;- },- {} as Record<MenuGroup, Array<IDisplayMenuItem<IMenuItem>>>- ) ?? ({} as Record<MenuGroup, Array<IDisplayMenuItem<IMenuItem>>>);- }, [groups, category]);-- return {- setCategory,- category,- visibleItems,- groups,- groupsByKey,- };-}+import type { IDisplayMenuItem, IMenuItem } from '../../../services/menu/menu';+import { useEffect, useState } from 'react';export interface IToolbarItemStatus {disabled: boolean;