1 | import { CommandEvent, CompositeDisposable, Disposable } from "../index";
|
2 |
|
3 | export interface CommandRegistryTargetMap extends HTMLElementTagNameMap {
|
4 | [key: string]: EventTarget;
|
5 | }
|
6 |
|
7 | export type CommandRegistryListener<TargetType extends EventTarget> =
|
8 | | {
|
9 | didDispatch(event: CommandEvent<TargetType>): void | Promise<void>;
|
10 | displayName?: string | undefined;
|
11 | description?: string | undefined;
|
12 | hiddenInCommandPalette?: boolean | undefined;
|
13 | }
|
14 | | ((event: CommandEvent<TargetType>) => void | Promise<void>);
|
15 |
|
16 | /**
|
17 | * Associates listener functions with commands in a context-sensitive way
|
18 | * using CSS selectors.
|
19 | */
|
20 | export interface CommandRegistry {
|
21 | /** Register a single command. */
|
22 | add<T extends keyof CommandRegistryTargetMap>(
|
23 | target: T,
|
24 | commandName: string,
|
25 | listener: CommandRegistryListener<CommandRegistryTargetMap[T]>,
|
26 | ): Disposable;
|
27 | /** Register a single command. */
|
28 | add<T extends Node>(target: T, commandName: string, listener: CommandRegistryListener<T>): Disposable;
|
29 |
|
30 | /** Register multiple commands. */
|
31 | add<T extends keyof CommandRegistryTargetMap>(
|
32 | target: T,
|
33 | commands: {
|
34 | [key: string]: CommandRegistryListener<CommandRegistryTargetMap[T]>;
|
35 | },
|
36 | ): CompositeDisposable;
|
37 | /** Register multiple commands. */
|
38 | add<T extends Node>(
|
39 | target: T,
|
40 | commands: {
|
41 | [key: string]: CommandRegistryListener<T>;
|
42 | },
|
43 | ): CompositeDisposable;
|
44 |
|
45 | /** Find all registered commands matching a query. */
|
46 | findCommands(params: {
|
47 | target: string | Node;
|
48 | }): Array<{
|
49 | name: string;
|
50 | displayName: string;
|
51 | description?: string | undefined;
|
52 | tags?: string[] | undefined;
|
53 | }>;
|
54 |
|
55 | /**
|
56 | * Simulate the dispatch of a command on a DOM node.
|
57 | * @return Either a Promise that resolves after all handlers complete or null if
|
58 | * no handlers were matched.
|
59 | */
|
60 | dispatch(target: Node, commandName: string): Promise<void> | null;
|
61 |
|
62 | /** Invoke the given callback before dispatching a command event. */
|
63 | onWillDispatch(callback: (event: CommandEvent) => void): Disposable;
|
64 |
|
65 | /** Invoke the given callback after dispatching a command event. */
|
66 | onDidDispatch(callback: (event: CommandEvent) => void): Disposable;
|
67 | }
|
68 |
|
\ | No newline at end of file |