import { BasePlugin } from '../base'; import { CommandExecutor } from './commandExecutor'; import { ItemsFactory } from './itemsFactory'; import { Menu } from './menu'; export type PredefinedMenuItemKey = 'row_above' | 'row_below' | 'col_left' | 'col_right' | '---------' | 'remove_row' | 'remove_col' | 'clear_column' | 'undo' | 'redo' | 'make_read_only' | 'alignment' | 'cut' | 'copy' | 'copy_column_headers_only' | 'copy_with_column_group_headers' | 'copy_with_column_headers' | 'freeze_column' | 'unfreeze_column' | 'borders' | 'commentsAddEdit' | 'commentsRemove' | 'commentsReadOnly' | 'mergeCells' | 'add_child' | 'detach_from_parent' | 'hidden_columns_hide' | 'hidden_columns_show' | 'hidden_rows_hide' | 'hidden_rows_show' | 'filter_by_condition' | 'filter_operators' | 'filter_by_condition2' | 'filter_by_value' | 'filter_action_bar'; export interface MenuItemConfig { key?: string; name: string | (() => string); hidden?: boolean | (() => boolean); disabled?: boolean | (() => boolean); callback?: (key: string, selection: unknown[], clickEvent: MouseEvent) => void; renderer?: (hot: unknown, wrapper: HTMLElement, row: number, col: number, prop: string | number, itemValue: string) => HTMLElement; submenu?: { items: MenuItemConfig[]; }; [key: string]: unknown; } export declare const PLUGIN_KEY = "contextMenu"; export declare const PLUGIN_PRIORITY = 70; /** * @class ContextMenu * @description * This plugin creates the Handsontable Context Menu. It allows to create a new row or column at any place in the * grid among [other features](@/guides/accessories-and-menus/context-menu/context-menu.md#context-menu-with-specific-options). * Possible values: * * `true` (to enable default options), * * `false` (to disable completely) * * `{ uiContainer: containerDomElement }` (to declare a container for all of the Context Menu's dom elements to be placed in). * * An array of [the available strings](@/guides/accessories-and-menus/context-menu/context-menu.md#context-menu-with-specific-options) * * See [the context menu demo](@/guides/accessories-and-menus/context-menu/context-menu.md) for examples. * * @example * ```js * // as a boolean * contextMenu: true * // as a array * contextMenu: ['row_above', 'row_below', '---------', 'undo', 'redo'] * ``` * * @plugin ContextMenu */ export declare class ContextMenu extends BasePlugin { #private; /** * Returns the plugin key used to identify this plugin in Handsontable settings. */ static get PLUGIN_KEY(): string; /** * Returns the priority order used to determine the order in which plugins are initialized. */ static get PLUGIN_PRIORITY(): number; /** * Returns the list of plugin dependencies required before this plugin can be initialized. */ static get PLUGIN_DEPS(): string[]; /** * Context menu default items order when `contextMenu` options is set as `true`. * * @returns {string[]} */ static get DEFAULT_ITEMS(): string[]; /** * Instance of {@link CommandExecutor}. * * @private * @type {CommandExecutor} */ commandExecutor: CommandExecutor; /** * Instance of {@link ItemsFactory}. * * @private * @type {ItemsFactory} */ itemsFactory: ItemsFactory | null; /** * Instance of {@link Menu}. * * @private * @type {Menu} */ menu: Menu | null; /** * Checks if the plugin is enabled in the handsontable settings. This method is executed in {@link Hooks#beforeInit} * hook and if it returns `true` then the {@link ContextMenu#enablePlugin} method is called. * * @returns {boolean} */ isEnabled(): boolean; /** * Enables the plugin functionality for this Handsontable instance. */ enablePlugin(): void; /** * Updates the plugin's state. * * This method is executed when [`updateSettings()`](@/api/core.md#updatesettings) is invoked with any of the following configuration options: * - [`contextMenu`](@/api/options.md#contextmenu) */ updatePlugin(): void; /** * Disables the plugin functionality for this Handsontable instance. */ disablePlugin(): void; /** * Register shortcuts responsible for toggling context menu. * * @private */ registerShortcuts(): void; /** * Unregister shortcuts responsible for toggling context menu. * * @private */ unregisterShortcuts(): void; /** * Opens the menu and positions it based on the passed coordinates. * * @param {{ top: number, left: number }|Event} position An object with `top` and `left` properties * (coordinates relative to the browser viewport, without scroll offsets), or a native browser * `Event` instance (e.g., a `MouseEvent`). * @param {{ above: number, below: number, left: number, right: number }} offset An object that applies * an offset to the menu position. * @fires Hooks#beforeContextMenuShow * @fires Hooks#afterContextMenuShow * @example * ```js * const menu = hot.getPlugin('contextMenu'); * * hot.selectCell(0, 0); * menu.open({ top: 50, left: 50 }); * ``` */ open(position: Record | Event, offset?: { above?: number; below?: number; left?: number; right?: number; }): void; /** * Closes the menu. */ close(): void; /** * Execute context menu command. * * The `executeCommand()` method works only for selected cells. * * When no cells are selected, `executeCommand()` doesn't do anything. * * You can execute all predefined commands: * * `'row_above'` - Insert row above * * `'row_below'` - Insert row below * * `'col_left'` - Insert column left * * `'col_right'` - Insert column right * * `'clear_column'` - Clear selected column * * `'remove_row'` - Remove row * * `'remove_col'` - Remove column * * `'undo'` - Undo last action * * `'redo'` - Redo last action * * `'make_read_only'` - Make cell read only * * `'alignment:left'` - Alignment to the left * * `'alignment:top'` - Alignment to the top * * `'alignment:right'` - Alignment to the right * * `'alignment:bottom'` - Alignment to the bottom * * `'alignment:middle'` - Alignment to the middle * * `'alignment:center'` - Alignment to the center (justify). * * Or you can execute command registered in settings where `key` is your command name. * * @param {string} commandName The command name to be executed. * @param {*} params Additional parameters passed to command executor module. */ executeCommand(commandName: string, ...params: unknown[]): void; /** * Prepares available contextMenu's items list and registers them in commandExecutor. * * @private * @fires Hooks#afterContextMenuDefaultOptions * @fires Hooks#beforeContextMenuSetItems */ prepareMenuItems(): void; /** * Destroys the plugin instance. */ destroy(): void; }