import { JSONObject } from '../algorithm/json'; import { ISequence } from '../algorithm/sequence'; import { Message } from '../core/messaging'; import { CommandRegistry } from './commandregistry'; import { Keymap } from './keymap'; import { Widget } from './widget'; /** * A widget which displays command items as a searchable palette. */ export declare class CommandPalette extends Widget { /** * Construct a new command palette. * * @param options - The options for initializing the palette. */ constructor(options: CommandPalette.IOptions); /** * Dispose of the resources held by the command palette. */ dispose(): void; /** * Get the command palette search node. * * #### Notes * This is the node which contains the search-related elements. * * This is a read-only property. */ readonly searchNode: HTMLDivElement; /** * Get the command palette input node. * * #### Notes * This is a read-only property. */ readonly inputNode: HTMLInputElement; /** * Get the command palette content node. * * #### Notes * This is the node which holds the command item nodes. * * Modifying this node directly can lead to undefined behavior. * * This is a read-only property. */ readonly contentNode: HTMLUListElement; /** * A read-only sequence of the command items in the palette. * * #### Notes * This is a read-only property. */ readonly items: ISequence; /** * The command registry used by the command palette. * * #### Notes * This is a read-only property. */ readonly commands: CommandRegistry; /** * The keymap used by the command palette. * * #### Notes * This is a read-only property. */ readonly keymap: Keymap; /** * The renderer used by the command palette. * * #### Notes * This is a read-only property. */ readonly renderer: CommandPalette.IRenderer; /** * Add a command item to the command palette. * * @param options - The options for creating the command item. * * @returns The command item added to the palette. */ addItem(options: CommandPalette.IItemOptions): CommandPalette.IItem; /** * Remove an item from the command palette. * * @param item - The item to remove from the palette. * * @returns The index occupied by the item, or `-1` if the item * was not contained in the menu. */ removeItem(item: CommandPalette.IItem): number; /** * Remove the item at a given index from the command palette. * * @param index - The index of the item to remove. * * @returns The item occupying the index, or `null` if the index * is out of range. */ removeItemAt(index: number): CommandPalette.IItem; /** * Remove all command items from the command palette. */ clearItems(): void; /** * Handle the DOM events for the command palette. * * @param event - The DOM event sent to the command palette. * * #### Notes * This method implements the DOM `EventListener` interface and is * called in response to events on the command palette's DOM node. * It should not be called directly by user code. */ handleEvent(event: Event): void; /** * A message handler invoked on a `'after-attach'` message. */ protected onAfterAttach(msg: Message): void; /** * A message handler invoked on a `'before-detach'` message. */ protected onBeforeDetach(msg: Message): void; /** * A message handler invoked on an `'activate-request'` message. */ protected onActivateRequest(msg: Message): void; /** * A message handler invoked on an `'update-request'` message. */ protected onUpdateRequest(msg: Message): void; /** * Handle the `'click'` event for the command palette. */ private _evtClick(event); /** * Handle the `'keydown'` event for the command palette. */ private _evtKeyDown(event); /** * Activate the node at the given render index. * * If the node is scrolled out of view, it will be scrolled into * view and aligned according to the `alignTop` parameter. */ private _activate(index); /** * Activate the next enabled index of the given kind. */ private _activateNext(kind); /** * Activate the previous enabled index of the given kind. */ private _activatePrev(kind); /** * Trigger the result part at the active index. * * If the part is an enabled command it will be executed. If the * part is a header, the category search term will be toggled. */ private _triggerActive(); /** * A signal handler for commands and keymap changes. */ private _onGenericChange(); private _activeIndex; private _keymap; private _commands; private _renderer; private _itemNodes; private _headerNodes; private _items; private _result; } /** * The namespace for the `CommandPalette` class statics. */ export declare namespace CommandPalette { /** * An options object for creating a command palette. */ interface IOptions { /** * The command registry for use with the command palette. */ commands: CommandRegistry; /** * The keymap for use with the command palette. */ keymap: Keymap; /** * A custom renderer for use with the command palette. * * The default is a shared renderer instance. */ renderer?: IRenderer; } /** * An options object for creating a command item. */ interface IItemOptions { /** * The command to execute when the item is triggered. */ command: string; /** * The arguments for the command. * * The default value is `null`. */ args?: JSONObject; /** * The category for the item. * * The default value is `'general'`. */ category?: string; } /** * An object which represents an item in a command palette. * * #### Notes * An item is an immutable object created by a command palette. */ interface IItem { /** * The command to execute when the item is triggered. */ command: string; /** * The arguments for the command. */ args: JSONObject; /** * The category for the command item. */ category: string; /** * The display label for the command item. */ label: string; /** * The display caption for the command item. */ caption: string; /** * The extra class name for the command item. */ className: string; /** * Whether the command item is enabled. */ isEnabled: boolean; /** * Whether the command item is toggled. */ isToggled: boolean; /** * Whether the command item is visible. */ isVisible: boolean; /** * The key binding for the command item. */ keyBinding: Keymap.IBinding; } /** * A renderer for use with a command palette. */ interface IRenderer { /** * Create a node for a section header. * * @returns A new node for a section header. * * #### Notes * The data in the node should be uninitialized. * * The `updateHeaderNode` method will be called for initialization. */ createHeaderNode(): HTMLLIElement; /** * Create a node for a command item. * * @returns A new node for a command item. * * #### Notes * The data in the node should be uninitialized. * * The `updateItemNode` method will be called for initialization. */ createItemNode(): HTMLLIElement; /** * Update a header node to reflect the given data.. * * @param node - A node created by a call to `createHeaderNode`. * * @param markup - The markup for the header text. This is the * section category text interpolated with `` tags for * the matching search characters. * * #### Notes * This method should completely reset the state of the node to * reflect the data for the header. */ updateHeaderNode(node: HTMLLIElement, markup: string): void; /** * Update an item node to reflect the state of a command item. * * @param node - A node created by a call to `createItemNode`. * * @param item - The command item holding the data for the node. * * @param markup - The markup for the item label. This is the * item label text interpolated with `` tags for the * matching search characters. * * #### Notes * This method should completely reset the state of the node to * reflect the data for the command item. */ updateItemNode(node: HTMLLIElement, item: CommandPalette.IItem, markup: string): void; } /** * The default implementation of `IRenderer`. */ class Renderer implements IRenderer { /** * Create a node for a section header. * * @returns A new node for a section header. */ createHeaderNode(): HTMLLIElement; /** * Create a node for a command item. * * @returns A new node for a command item. */ createItemNode(): HTMLLIElement; /** * Update a header node to reflect the given data. * * @param node - A node created by a call to `createHeaderNode`. * * @param markup - The markup for the header text. This is the * section category text interpolated with `` tags for * the matching search characters. */ updateHeaderNode(node: HTMLLIElement, markup: string): void; /** * Update an item node to reflect the state of a command item. * * @param node - A node created by a call to `createItemNode`. * * @param item - The command item holding the data for the node. * * @param markup - The markup for the item label. This is the * item label text interpolated with `` tags for the * matching search characters. */ updateItemNode(node: HTMLLIElement, item: CommandPalette.IItem, markup: string): void; /** * Format a key binding into shortcut text for display. * * @param binding - The key binding to format. This may be `null`. * * @returns The formatted shortcut text for display. */ formatShortcut(binding: Keymap.IBinding): string; } /** * The default `Renderer` instance. */ const defaultRenderer: Renderer; /** * Split a query string into its category and text components. * * @param query - A query string of the form `(::)?`. * * @returns The `category` and `text` components of the query with * leading and trailing whitespace removed. */ function splitQuery(query: string): { category: string; text: string; }; /** * Join category and text components into a query string. * * @param category - The category for the query or an empty string. * * @param text - The text for the query or an empty string. * * @returns The joined query string for the components. */ function joinQuery(category: string, text: string): string; }