import { JSONObject } from '@phosphor/coreutils'; import { IDisposable } from '@phosphor/disposable'; import { Token } from '@phosphor/application'; import { CommandRegistry } from '@phosphor/commands'; import { ElementAttrs } from '@phosphor/virtualdom'; /** * The command linker token. */ export declare const ICommandLinker: Token; /** * A helper class to generate clickables that execute commands. */ export interface ICommandLinker extends IDisposable { /** * Connect a command/argument pair to a given node so that when it is clicked, * the command will execute. * * @param node - The node being connected. * * @param command - The command ID to execute upon click. * * @param args - The arguments with which to invoke the command. * * @returns The same node that was passed in, after it has been connected. * * #### Notes * Only `click` events will execute the command on a connected node. So, there * are two considerations that are relevant: * 1. If a node is connected, the default click action will be prevented. * 2. The `HTMLElement` passed in should be clickable. */ connectNode(node: HTMLElement, command: string, args: JSONObject): HTMLElement; /** * Disconnect a node that has been connected to execute a command on click. * * @param node - The node being disconnected. * * @returns The same node that was passed in, after it has been disconnected. * * #### Notes * This method is safe to call multiple times and is safe to call on nodes * that were never connected. * * This method can be called on rendered virtual DOM nodes that were populated * using the `populateVirtualNodeAttributes` method in order to disconnect them from * executing their command/argument pair. */ disconnectNode(node: HTMLElement): HTMLElement; /** * Populate the attributes used to instantiate a virtual DOM node with the * data set values necessary for its rendered DOM node to respond to clicks by * executing a command/argument pair * * @param attrs - The attributes that will eventually be used to instantiate * a virtual DOM node. * * @param command - The command ID to execute upon click. * * @param args - The arguments with which to invoke the command. * * @returns The same attributes that were passed in. * * #### Notes * The attributes instance that is returned is identical to the attributes * instance that was passed in, i.e., this method mutates the original. */ populateVirtualNodeAttrs(attrs: ElementAttrs, command: string, args: JSONObject): ElementAttrs; } /** * A static class that provides helper methods to generate clickable nodes that * execute registered commands with pre-populated arguments. */ export declare class CommandLinker implements ICommandLinker { /** * Instantiate a new command linker. */ constructor(options: CommandLinker.IOptions); /** * Test whether the linker is disposed. */ readonly isDisposed: boolean; /** * Dispose of the resources held by the linker. */ dispose(): void; /** * Connect a command/argument pair to a given node so that when it is clicked, * the command will execute. * * @param node - The node being connected. * * @param command - The command ID to execute upon click. * * @param args - The arguments with which to invoke the command. * * @returns The same node that was passed in, after it has been connected. * * #### Notes * Only `click` events will execute the command on a connected node. So, there * are two considerations that are relevant: * 1. If a node is connected, the default click action will be prevented. * 2. The `HTMLElement` passed in should be clickable. */ connectNode(node: HTMLElement, command: string, args: JSONObject): HTMLElement; /** * Disconnect a node that has been connected to execute a command on click. * * @param node - The node being disconnected. * * @returns The same node that was passed in, after it has been disconnected. * * #### Notes * This method is safe to call multiple times and is safe to call on nodes * that were never connected. * * This method can be called on rendered virtual DOM nodes that were populated * using the `populateVirtualNodeAttributes` method in order to disconnect them from * executing their command/argument pair. */ disconnectNode(node: HTMLElement): HTMLElement; /** * Handle the DOM events for the command linker helper class. * * @param event - The DOM event sent to the class. * * #### Notes * This method implements the DOM `EventListener` interface and is * called in response to events on the panel's DOM node. It should * not be called directly by user code. */ handleEvent(event: Event): void; /** * Populate the attributes used to instantiate a virtual DOM node with the * data set values necessary for its rendered DOM node to respond to clicks by * executing a command/argument pair * * @param attrs - The attributes that will eventually be used to instantiate * a virtual DOM node. * * @param command - The command ID to execute upon click. * * @param args - The arguments with which to invoke the command. * * @returns The same attributes that were passed in. * * #### Notes * The attributes instance that is returned is identical to the attributes * instance that was passed in, i.e., this method mutates the original. */ populateVirtualNodeAttrs(attrs: ElementAttrs, command: string, args: JSONObject): ElementAttrs; /** * The global click handler that deploys commands/argument pairs that are * attached to the node being clicked. */ private _evtClick(event); private _commands; } /** * A namespace for command linker statics. */ export declare namespace CommandLinker { /** * The instantiation options for a command linker. */ interface IOptions { /** * The command registry instance that all linked commands will use. */ commands: CommandRegistry; } }