/** * 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'; 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 } 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?: string; description?: string; icon?: string | Observable; tooltip?: string; slot?: boolean; type: MenuItemType; /** * Custom label component id. */ label?: string | { name: string; hoverable?: boolean; selectable?: boolean; props?: Record; }; hidden$?: Observable; disabled$?: Observable; params?: any | Function; /** 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?: any; slot?: boolean; label?: string | { name: string; hoverable?: boolean; selectable?: boolean; props?: Record>; }; icon?: string; tooltip?: string; 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 declare function isMenuSelectorItem(v: IMenuItem): v is IMenuSelectorItem; export declare function isMenuButtonSelectorItem(v: IMenuItem): v is IMenuSelectorItem; export type MenuItemDefaultValueType = string | number | undefined; export type IMenuItem = IMenuButtonItem | IMenuSelectorItem; export type IDisplayMenuItem = T & { shortcut?: string; }; export type MenuItemConfig = Partial & { hidden?: boolean; disabled?: boolean; activated?: boolean; }>; export type MenuConfig = Record; export type IMenuItemFactory = (accessor: IAccessor, menuConfig?: MenuConfig) => IMenuItem; export {};