/** * The menu class lets you create content menus. Context menus can contain custom menu items, and a number of existing UI elements, including Actions, Tools, etc. * * ## Example * ``` * document.addEventListener('contextmenu', event => { * let items = [ * 'open_model', * { * name: 'Example', * icon: 'house', * click() { * console.log('Hello World') * } * } * ]; * new Menu(items).open(event); * }) * ``` * @module */ export interface CustomMenuItem { name: string; id?: string; icon: IconString | boolean | ((context: any) => (IconString | boolean)); color?: string; description?: string; condition?: ConditionResolvable; /** * Keybind or string to display in the menu, won't work as an actual keybinding by default */ keybind?: Keybind | string; /** * If true, mark the menu item as the selected one (underlined text in default theme) */ marked?: boolean | ((context: any) => boolean); /** * Adds a search bar to the menu or submenu */ searchable?: boolean; children?: MenuItem[] | ((context: any) => MenuItem[]); click?(context?: any, event?: Event): void; } export type MenuItem = CustomMenuItem | Action | BarSelect | MenuSeparator | string | ((context: any) => MenuItem); export type MenuOpenPositionAnchor = MouseEvent | HTMLElement | { clientX: number; clientY: number; } | 'mouse'; export interface MenuOptions { onOpen?(position: MenuOpenPositionAnchor, context?: any): void; onClose?(): void; keep_open?: boolean; searchable?: boolean; class?: string | string[]; } export declare class MenuSeparator { id: string; label?: string; menu_node: HTMLLIElement; constructor(id?: string, label?: string); } /** * Use the Menu class to create a context menu. Menus can contain custom entries and hierarchy, or existing actions and tools. */ export declare class Menu implements Deletable { id: string; children: []; structure: MenuItem[] | ((context: any) => MenuItem[]); options?: MenuOptions; condition?: ConditionResolvable; onOpen?(position: MenuOpenPositionAnchor, context?: any): void; onClose?(): void; node: HTMLUListElement; highlight_action?: MenuItem; anchor_tool?: HTMLElement; type: string; /** * Creates a new context menu */ constructor(template: MenuItem[] | ((context?: any) => MenuItem[]), options?: MenuOptions); constructor(id: string, template: MenuItem[] | ((context?: any) => MenuItem[]), options?: MenuOptions); hover(node: HTMLElement, event?: Event, expand?: boolean): void; /** * Trigger keyboard navigation * @param e Event * @returns True if the input was used for navigation * @private */ keyNavigate(e: KeyboardEvent): boolean; /** * Opens the menu somewhere * @param position Position where to open the menu. Can be a mouse event, or a node that the menu is spawned below. * @param context Context for the click events inside the menu */ open(position?: MenuOpenPositionAnchor, context?: any): this; /** * Alias for .open() */ show(position?: MenuOpenPositionAnchor, context?: any): this; /** * Closes the menu if it's open */ hide(): this; /** * @deprecated */ conditionMet(): boolean; /** * Adds an action to the menu structure * @param action Action to add * @param path Path pointing to the location. Use the ID of each level of the menu, or index within a level, separated by a point. For example, `export.0` places the action at the top position of the Export submenu. */ addAction(action: Action | CustomMenuItem | '_', path?: string | number): void; /** * Remove an action or menu item from the menu * @param path Path pointing to the location. Use the ID of each level of the menu, or index within a level, or item ID, separated by a point. For example, `export.export_special_format` removes the action "Export Special Format" from the Export submenu. */ removeAction(path: string | Action): void; /** * @deprecated Use removeAction instead */ deleteItem(rm_item: Action): void; delete(): void; static open: Menu | null; static closed_in_this_click?: string; } export declare function preventContextMenu(): void; declare const global: { MenuSeparator: typeof import("./menu").MenuSeparator; Menu: typeof import("./menu").Menu; preventContextMenu: typeof import("./menu").preventContextMenu; open_menu: any; }; declare global { type Menu = import('./menu').Menu; const Menu: typeof global.Menu; type MenuSeparator = import('./menu').MenuSeparator; const MenuSeparator: typeof global.MenuSeparator; function preventContextMenu(): void; let open_menu: Menu | null; interface Window { open_menu: Menu | null; } } export {};