/** * Copyright 2023-present DreamNum Co., Ltd. * * 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 type { IAccessor } from '@univerjs/core'; import type { Observable } from 'rxjs'; import type { IMenuItem, MenuConfig } from './menu'; import { Disposable, IConfigService, Injector } from '@univerjs/core'; import { Subject } from 'rxjs'; export declare const IMenuManagerService: import("@wendellhu/redi").IdentifierDecorator; export type ContextMenuQuickLayout = 'icon' | 'tile'; export type ContextMenuQuickLayoutVariant = 'default' | 'compact'; export type MobileMenuLayout = 'grid' | 'list'; export interface IRibbonGridLayout { /** 1-based row within the ribbon group's two rows. */ row: number; /** 1-based column within the ribbon group. */ column: number; /** Number of rows occupied. Defaults to 1; use 2 for a large button. */ rowSpan?: number; /** Number of columns occupied. Defaults to 1. */ columnSpan?: number; /** Whether to display the menu title alongside its icon. */ showLabel?: boolean; /** Width in pixels. */ width?: number; /** Icon size in pixels. */ iconSize?: number; } export interface IMenuSchema { key: string; order: number; title?: string; contextual?: boolean; item?: IMenuItem; headerActionItem?: IMenuItem; children?: IMenuSchema[]; quickLayout?: ContextMenuQuickLayout; quickColumns?: number; quickLayoutVariant?: ContextMenuQuickLayoutVariant; mobileLayout?: MobileMenuLayout; tiny?: boolean; gridLayout?: IRibbonGridLayout; } export interface IMenuManagerService { readonly menuChanged$: Observable; mergeMenu(source: MenuSchemaType, target?: MenuSchemaType): void; appendRootMenu(source: MenuSchemaType): void; updateMenuConfig(config: MenuConfig): void; getMenuByPositionKey(position: string): IMenuSchema[]; getFlatMenuByPositionKey(position: string): IMenuSchema[]; } export type MenuSchemaType = { order?: number; replace?: boolean; menuItemFactory?: (accessor: IAccessor) => IMenuItem; headerActionMenuItemFactory?: (accessor: IAccessor) => IMenuItem; title?: string; contextual?: boolean; quickLayout?: ContextMenuQuickLayout; quickColumns?: number; quickLayoutVariant?: ContextMenuQuickLayoutVariant; mobileLayout?: MobileMenuLayout; tiny?: boolean; gridLayout?: IRibbonGridLayout; } | { [key: string]: MenuSchemaType; }; export declare class MenuManagerService extends Disposable implements IMenuManagerService { private readonly _injector; private readonly _configService; readonly menuChanged$: Subject; private _menu; constructor(_injector: Injector, _configService: IConfigService); dispose(): void; /** * Merge source menu to target menu recursively * @param source * @param target default is root menu */ mergeMenu(source: MenuSchemaType, target?: MenuSchemaType): void; appendRootMenu(source: MenuSchemaType): void; updateMenuConfig(config: MenuConfig): void; createScoped(injector: Injector): IMenuManagerService; private _buildMenuSchema; /** * Get menu schema by position key * @param key * @returns Menu schema array or empty array if not found */ getMenuByPositionKey(key: string): IMenuSchema[]; /** * Get flat menu schema by position key * @param key * @returns Flat menu schema array or empty array if not found */ getFlatMenuByPositionKey(key: string): IMenuSchema[]; }