UNPKG

3.71 kBTypeScriptView Raw
1import { CommandRegistry } from '@lumino/commands';
2import { IDisposable } from '@lumino/disposable';
3import { Menu } from './menu';
4/**
5 * An object which implements a universal context menu.
6 *
7 * #### Notes
8 * The items shown in the context menu are determined by CSS selector
9 * matching against the DOM hierarchy at the site of the mouse click.
10 * This is similar in concept to how keyboard shortcuts are matched
11 * in the command registry.
12 */
13export declare class ContextMenu {
14 /**
15 * Construct a new context menu.
16 *
17 * @param options - The options for initializing the menu.
18 */
19 constructor(options: ContextMenu.IOptions);
20 /**
21 * The menu widget which displays the matched context items.
22 */
23 readonly menu: Menu;
24 /**
25 * Add an item to the context menu.
26 *
27 * @param options - The options for creating the item.
28 *
29 * @returns A disposable which will remove the item from the menu.
30 */
31 addItem(options: ContextMenu.IItemOptions): IDisposable;
32 /**
33 * Open the context menu in response to a `'contextmenu'` event.
34 *
35 * @param event - The `'contextmenu'` event of interest.
36 *
37 * @returns `true` if the menu was opened, or `false` if no items
38 * matched the event and the menu was not opened.
39 *
40 * #### Notes
41 * This method will populate the context menu with items which match
42 * the propagation path of the event, then open the menu at the mouse
43 * position indicated by the event.
44 */
45 open(event: MouseEvent): boolean;
46 private _groupByTarget;
47 private _idTick;
48 private _items;
49 private _sortBySelector;
50}
51/**
52 * The namespace for the `ContextMenu` class statics.
53 */
54export declare namespace ContextMenu {
55 /**
56 * An options object for initializing a context menu.
57 */
58 interface IOptions {
59 /**
60 * The command registry to use with the context menu.
61 */
62 commands: CommandRegistry;
63 /**
64 * A custom renderer for use with the context menu.
65 */
66 renderer?: Menu.IRenderer;
67 /**
68 * Whether to sort by selector and rank or only rank.
69 *
70 * Default true.
71 */
72 sortBySelector?: boolean;
73 /**
74 * Whether to group items following the DOM hierarchy.
75 *
76 * Default true.
77 *
78 * #### Note
79 * If true, when the mouse event occurs on element `span` within `div.top`,
80 * the items matching `div.top` will be shown before the ones matching `body`.
81 */
82 groupByTarget?: boolean;
83 }
84 /**
85 * An options object for creating a context menu item.
86 */
87 interface IItemOptions extends Menu.IItemOptions {
88 /**
89 * The CSS selector for the context menu item.
90 *
91 * The context menu item will only be displayed in the context menu
92 * when the selector matches a node on the propagation path of the
93 * contextmenu event. This allows the menu item to be restricted to
94 * user-defined contexts.
95 *
96 * The selector must not contain commas.
97 */
98 selector: string;
99 /**
100 * The rank for the item.
101 *
102 * The rank is used as a tie-breaker when ordering context menu
103 * items for display. Items are sorted in the following order:
104 * 1. Depth in the DOM tree (deeper is better)
105 * 2. Selector specificity (higher is better)
106 * 3. Rank (lower is better)
107 * 4. Insertion order
108 *
109 * The default rank is `Infinity`.
110 */
111 rank?: number;
112 }
113}
114//# sourceMappingURL=contextmenu.d.ts.map
\No newline at end of file