import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-editor-types'; /** * Context Menu options for ContextMenu plugin */ export interface ContextMenuOptions { /** * Render function for the context menu * @param container The container HTML element, it will be located at the mouse click position, * so the callback just need to render menu content into this container * @param onDismiss The onDismiss callback, some menu render need to know this callback so that * it can handle the dismiss event */ render: (container: HTMLElement, items: (T | null)[], onDismiss: () => void) => void; /** * Dismiss function for the context menu, it will be called when user wants to dismiss this context menu * e.g. user click away so the menu should be dismissed * @param container The container HTML element */ dismiss?: (container: HTMLElement) => void; /** * Whether the default context menu is allowed. @default false */ allowDefaultMenu?: boolean; } /** * An editor plugin that support showing a context menu using render() function from options parameter */ export default class ContextMenu implements EditorPlugin { private options; private container; private editor; private isMenuShowing; /** * Create a new instance of ContextMenu class * @param options An options object to determine how to show/hide the context menu */ constructor(options: ContextMenuOptions); /** * Get a friendly name of this plugin */ getName(): string; /** * Initialize this plugin * @param editor The editor instance */ initialize(editor: IEditor): void; /** * Dispose this plugin */ dispose(): void; /** * Handle events triggered from editor * @param event PluginEvent object */ onPluginEvent(event: PluginEvent): void; private initContainer; private onDismiss; }