UNPKG

2.07 kBTypeScriptView Raw
1import { Disposable } from '../index';
2
3/** Provides a registry for commands that you'd like to appear in the context menu. */
4export interface ContextMenuManager {
5 /** Add context menu items scoped by CSS selectors. */
6 add(itemsBySelector: { [key: string]: ReadonlyArray<ContextMenuOptions> }): Disposable;
7}
8
9export type ContextMenuOptions = ContextMenuItemOptions | { type: 'separator' };
10
11export interface ContextMenuItemOptions {
12 /** The menu item's label. */
13 label?: string | undefined;
14
15 /**
16 * The command to invoke on the target of the right click that invoked the
17 * context menu.
18 */
19 command?: string | undefined;
20
21 /**
22 * Whether the menu item should be clickable. Disabled menu items typically
23 * appear grayed out. Defaults to true.
24 */
25 enabled?: boolean | undefined;
26
27 /** An array of additional items. */
28 submenu?: ReadonlyArray<ContextMenuOptions> | undefined;
29
30 /** Whether the menu item should appear in the menu. Defaults to true. */
31 visible?: boolean | undefined;
32
33 /**
34 * A function that is called on the item each time a context menu is created
35 * via a right click.
36 */
37 created?(event: Event): void;
38
39 /**
40 * A function that is called to determine whether to display this item on a
41 * given context menu deployment.
42 */
43 shouldDisplay?(event: Event): void;
44
45 /** Place this menu item before the menu items representing the given commands. */
46 before?: ReadonlyArray<string> | undefined;
47
48 /** Place this menu item after the menu items representing the given commands. */
49 after?: ReadonlyArray<string> | undefined;
50
51 /**
52 * Place this menu item's group before the containing group of the menu items
53 * representing the given commands.
54 */
55 beforeGroupContaining?: ReadonlyArray<string> | undefined;
56
57 /**
58 * Place this menu item's group after the containing group of the menu items
59 * representing the given commands.
60 */
61 afterGroupContaining?: ReadonlyArray<string> | undefined;
62}