/** * 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 { IRibbonGridLayout } from './menu-manager.service'; export type OneOrMany = T | T[]; export declare enum MenuItemType { /** Button style menu item. */ BUTTON = 0, /** Menu item with submenus. Submenus could be other IMenuItem or an ID of a registered component. */ SELECTOR = 1, /** Button style menu item with a dropdown menu. */ BUTTON_SELECTOR = 2, /** Submenus have to specific features and do not invoke commands. */ SUBITEMS = 3 } type MenuLabel = string | { name: string; hoverable?: boolean; selectable?: boolean; props?: Record; }; export type IMenuCommandParams = Record; interface IMenuItemBase { /** ID of the menu item. Normally it should be the same as the ID of the command that it would invoke. */ id: string; /** * If two menus reuse the same command (e.g. copy & paste command). They should have the same command * id and different ids. */ commandId?: string; subId?: string; title?: TLocaleKey; description?: string; icon?: string | Observable; tooltip?: TLocaleKey; slot?: boolean; type: MenuItemType; /** * Custom label component id. */ label?: MenuLabel; hidden$?: Observable; disabled$?: Observable; params?: IMenuCommandParams | (() => IMenuCommandParams | undefined); /** On observable value that should emit the value of the corresponding selection component. */ value$?: Observable; } export interface IMenuButtonItem extends IMenuItemBase { type: MenuItemType.BUTTON; activated$?: Observable; } export interface IValueOption { id?: string; value?: string | number; value$?: Observable; params?: IMenuCommandParams | ((value?: string | number) => IMenuCommandParams | undefined); slot?: boolean; label?: MenuLabel; icon?: string; tooltip?: TLocaleKey; style?: object; disabled?: boolean; commandId?: string; } export interface ICustomComponentProps { value: T; onChange: (v: T) => void; } export interface IMenuSelectorItem extends IMenuItemBase { type: MenuItemType.SELECTOR | MenuItemType.BUTTON_SELECTOR | MenuItemType.SUBITEMS; /** * If this property is set, changing the value of the selection will trigger the command with this id, * instead of {@link IMenuItemBase.id} or {@link IMenuItemBase.commandId}. At the same title, * clicking the button will trigger IMenuItemBase.id or IMenuItemBase.commandId. */ selectionsCommandId?: string; /** Options or IDs of registered components. */ selections?: Array> | Observable>>; /** If `type` is `MenuItemType.BUTTON_SELECTOR`, this determines if the button is activated. */ activated$?: Observable; } export type MenuItemDefaultValueType = string | number | undefined; export type IMenuItem = IMenuButtonItem | IMenuSelectorItem; export declare function isMenuSelectorItem(v: IMenuItem): v is IMenuSelectorItem; export declare function isMenuButtonSelectorItem(v: IMenuItem): v is IMenuSelectorItem; export type IDisplayMenuItem = T & { shortcut?: string; }; export type MenuItemConfig = Partial, 'id' | 'subId' | 'value$' | 'hidden$' | 'disabled$' | 'activated$' | 'icon$'> & { hidden?: boolean; disabled?: boolean; activated?: boolean; /** Display order among sibling menu items, ribbon tabs, or groups. Lower values come first. */ order?: number; /** Placement within a ribbon group when ribbonType is 'grid'. Rows and columns start at 1. */ gridLayout?: IRibbonGridLayout; }>; /** Overrides keyed by menu item ID, ribbon tab key, or ribbon group key. */ export type MenuConfig = Record>; export type IMenuItemFactory = (accessor: IAccessor, menuConfig?: MenuConfig) => IMenuItem; export {};