UNPKG

4.26 kBTypeScriptView Raw
1import { CommandRegistry } from '@lumino/commands';
2import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
3import { IDisposable } from '@lumino/disposable';
4import { ElementDataset } from '@lumino/virtualdom';
5/**
6 * A static class that provides helper methods to generate clickable nodes that
7 * execute registered commands with pre-populated arguments.
8 */
9export declare class CommandLinker implements IDisposable {
10 /**
11 * Instantiate a new command linker.
12 */
13 constructor(options: CommandLinker.IOptions);
14 /**
15 * Test whether the linker is disposed.
16 */
17 get isDisposed(): boolean;
18 /**
19 * Dispose of the resources held by the linker.
20 */
21 dispose(): void;
22 /**
23 * Connect a command/argument pair to a given node so that when it is clicked,
24 * the command will execute.
25 *
26 * @param node - The node being connected.
27 *
28 * @param command - The command ID to execute upon click.
29 *
30 * @param args - The arguments with which to invoke the command.
31 *
32 * @returns The same node that was passed in, after it has been connected.
33 *
34 * #### Notes
35 * Only `click` events will execute the command on a connected node. So, there
36 * are two considerations that are relevant:
37 * 1. If a node is connected, the default click action will be prevented.
38 * 2. The `HTMLElement` passed in should be clickable.
39 */
40 connectNode(node: HTMLElement, command: string, args?: ReadonlyPartialJSONObject): HTMLElement;
41 /**
42 * Disconnect a node that has been connected to execute a command on click.
43 *
44 * @param node - The node being disconnected.
45 *
46 * @returns The same node that was passed in, after it has been disconnected.
47 *
48 * #### Notes
49 * This method is safe to call multiple times and is safe to call on nodes
50 * that were never connected.
51 *
52 * This method can be called on rendered virtual DOM nodes that were populated
53 * using the `populateVNodeDataset` method in order to disconnect them from
54 * executing their command/argument pair.
55 */
56 disconnectNode(node: HTMLElement): HTMLElement;
57 /**
58 * Handle the DOM events for the command linker helper class.
59 *
60 * @param event - The DOM event sent to the class.
61 *
62 * #### Notes
63 * This method implements the DOM `EventListener` interface and is
64 * called in response to events on the panel's DOM node. It should
65 * not be called directly by user code.
66 */
67 handleEvent(event: Event): void;
68 /**
69 * Populate the `dataset` attribute within the collection of attributes used
70 * to instantiate a virtual DOM node with the values necessary for its
71 * rendered DOM node to respond to clicks by executing a command/argument
72 * pair.
73 *
74 * @param command - The command ID to execute upon click.
75 *
76 * @param args - The arguments with which to invoke the command.
77 *
78 * @returns A `dataset` collection for use within virtual node attributes.
79 *
80 * #### Notes
81 * The return value can be used on its own as the value for the `dataset`
82 * attribute of a virtual element, or it can be added to an existing `dataset`
83 * as in the example below.
84 *
85 * #### Example
86 * ```typescript
87 * let command = 'some:command-id';
88 * let args = { alpha: 'beta' };
89 * let anchor = h.a({
90 * className: 'some-class',
91 * dataset: {
92 * foo: '1',
93 * bar: '2',
94 * ../...linker.populateVNodeDataset(command, args)
95 * }
96 * }, 'some text');
97 * ```
98 */
99 populateVNodeDataset(command: string, args?: ReadonlyPartialJSONObject): ElementDataset;
100 /**
101 * The global click handler that deploys commands/argument pairs that are
102 * attached to the node being clicked.
103 */
104 private _evtClick;
105 private _commands;
106 private _isDisposed;
107}
108/**
109 * A namespace for command linker statics.
110 */
111export declare namespace CommandLinker {
112 /**
113 * The instantiation options for a command linker.
114 */
115 interface IOptions {
116 /**
117 * The command registry instance that all linked commands will use.
118 */
119 commands: CommandRegistry;
120 }
121}
122
\No newline at end of file