1 | import { CommandRegistry } from '@phosphor/commands';
|
2 | import { IDisposable } from '@phosphor/disposable';
|
3 | import { 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 | */
|
13 | export 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 _idTick;
|
47 | private _items;
|
48 | }
|
49 | /**
|
50 | * The namespace for the `ContextMenu` class statics.
|
51 | */
|
52 | export declare namespace ContextMenu {
|
53 | /**
|
54 | * An options object for initializing a context menu.
|
55 | */
|
56 | interface IOptions {
|
57 | /**
|
58 | * The command registry to use with the context menu.
|
59 | */
|
60 | commands: CommandRegistry;
|
61 | /**
|
62 | * A custom renderer for use with the context menu.
|
63 | */
|
64 | renderer?: Menu.IRenderer;
|
65 | }
|
66 | /**
|
67 | * An options object for creating a context menu item.
|
68 | */
|
69 | interface IItemOptions extends Menu.IItemOptions {
|
70 | /**
|
71 | * The CSS selector for the context menu item.
|
72 | *
|
73 | * The context menu item will only be displayed in the context menu
|
74 | * when the selector matches a node on the propagation path of the
|
75 | * contextmenu event. This allows the menu item to be restricted to
|
76 | * user-defined contexts.
|
77 | *
|
78 | * The selector must not contain commas.
|
79 | */
|
80 | selector: string;
|
81 | /**
|
82 | * The rank for the item.
|
83 | *
|
84 | * The rank is used as a tie-breaker when ordering context menu
|
85 | * items for display. Items are sorted in the following order:
|
86 | * 1. Depth in the DOM tree (deeper is better)
|
87 | * 2. Selector specificity (higher is better)
|
88 | * 3. Rank (lower is better)
|
89 | * 4. Insertion order
|
90 | *
|
91 | * The default rank is `Infinity`.
|
92 | */
|
93 | rank?: number;
|
94 | }
|
95 | }
|