1 | import { Message } from '@phosphor/messaging';
|
2 | import { ElementDataset, VirtualElement, h } from '@phosphor/virtualdom';
|
3 | import { Menu } from './menu';
|
4 | import { Title } from './title';
|
5 | import { Widget } from './widget';
|
6 |
|
7 |
|
8 |
|
9 | export declare class MenuBar extends Widget {
|
10 | |
11 |
|
12 |
|
13 |
|
14 |
|
15 | constructor(options?: MenuBar.IOptions);
|
16 | /**
|
17 | * Dispose of the resources held by the widget.
|
18 | */
|
19 | dispose(): void;
|
20 | /**
|
21 | * The renderer used by the menu bar.
|
22 | */
|
23 | readonly renderer: MenuBar.IRenderer;
|
24 | /**
|
25 | * The child menu of the menu bar.
|
26 | *
|
27 | * #### Notes
|
28 | * This will be `null` if the menu bar does not have an open menu.
|
29 | */
|
30 | readonly childMenu: Menu | null;
|
31 | /**
|
32 | * Get the menu bar content node.
|
33 | *
|
34 | * #### Notes
|
35 | * This is the node which holds the menu title nodes.
|
36 | *
|
37 | * Modifying this node directly can lead to undefined behavior.
|
38 | */
|
39 | readonly contentNode: HTMLUListElement;
|
40 | /**
|
41 | * Get the currently active menu.
|
42 | */
|
43 | /**
|
44 | * Set the currently active menu.
|
45 | *
|
46 | * #### Notes
|
47 | * If the menu does not exist, the menu will be set to `null`.
|
48 | */
|
49 | activeMenu: Menu | null;
|
50 | /**
|
51 | * Get the index of the currently active menu.
|
52 | *
|
53 | * #### Notes
|
54 | * This will be `-1` if no menu is active.
|
55 | */
|
56 | /**
|
57 | * Set the index of the currently active menu.
|
58 | *
|
59 | * #### Notes
|
60 | * If the menu cannot be activated, the index will be set to `-1`.
|
61 | */
|
62 | activeIndex: number;
|
63 | /**
|
64 | * A read-only array of the menus in the menu bar.
|
65 | */
|
66 | readonly menus: ReadonlyArray<Menu>;
|
67 | /**
|
68 | * Open the active menu and activate its first menu item.
|
69 | *
|
70 | * #### Notes
|
71 | * If there is no active menu, this is a no-op.
|
72 | */
|
73 | openActiveMenu(): void;
|
74 | /**
|
75 | * Add a menu to the end of the menu bar.
|
76 | *
|
77 | * @param menu - The menu to add to the menu bar.
|
78 | *
|
79 | * #### Notes
|
80 | * If the menu is already added to the menu bar, it will be moved.
|
81 | */
|
82 | addMenu(menu: Menu): void;
|
83 | /**
|
84 | * Insert a menu into the menu bar at the specified index.
|
85 | *
|
86 | * @param index - The index at which to insert the menu.
|
87 | *
|
88 | * @param menu - The menu to insert into the menu bar.
|
89 | *
|
90 | * #### Notes
|
91 | * The index will be clamped to the bounds of the menus.
|
92 | *
|
93 | * If the menu is already added to the menu bar, it will be moved.
|
94 | */
|
95 | insertMenu(index: number, menu: Menu): void;
|
96 | /**
|
97 | * Remove a menu from the menu bar.
|
98 | *
|
99 | * @param menu - The menu to remove from the menu bar.
|
100 | *
|
101 | * #### Notes
|
102 | * This is a no-op if the menu is not in the menu bar.
|
103 | */
|
104 | removeMenu(menu: Menu): void;
|
105 | /**
|
106 | * Remove the menu at a given index from the menu bar.
|
107 | *
|
108 | * @param index - The index of the menu to remove.
|
109 | *
|
110 | * #### Notes
|
111 | * This is a no-op if the index is out of range.
|
112 | */
|
113 | removeMenuAt(index: number): void;
|
114 | /**
|
115 | * Remove all menus from the menu bar.
|
116 | */
|
117 | clearMenus(): void;
|
118 | /**
|
119 | * Handle the DOM events for the menu bar.
|
120 | *
|
121 | * @param event - The DOM event sent to the menu bar.
|
122 | *
|
123 | * #### Notes
|
124 | * This method implements the DOM `EventListener` interface and is
|
125 | * called in response to events on the menu bar's DOM nodes. It
|
126 | * should not be called directly by user code.
|
127 | */
|
128 | handleEvent(event: Event): void;
|
129 | /**
|
130 | * A message handler invoked on a `'before-attach'` message.
|
131 | */
|
132 | protected onBeforeAttach(msg: Message): void;
|
133 | /**
|
134 | * A message handler invoked on an `'after-detach'` message.
|
135 | */
|
136 | protected onAfterDetach(msg: Message): void;
|
137 | /**
|
138 | * A message handler invoked on an `'activate-request'` message.
|
139 | */
|
140 | protected onActivateRequest(msg: Message): void;
|
141 | /**
|
142 | * A message handler invoked on an `'update-request'` message.
|
143 | */
|
144 | protected onUpdateRequest(msg: Message): void;
|
145 | /**
|
146 | * Handle the `'keydown'` event for the menu bar.
|
147 | */
|
148 | private _evtKeyDown;
|
149 | /**
|
150 | * Handle the `'mousedown'` event for the menu bar.
|
151 | */
|
152 | private _evtMouseDown;
|
153 | /**
|
154 | * Handle the `'mousemove'` event for the menu bar.
|
155 | */
|
156 | private _evtMouseMove;
|
157 | /**
|
158 | * Handle the `'mouseleave'` event for the menu bar.
|
159 | */
|
160 | private _evtMouseLeave;
|
161 | /**
|
162 | * Open the child menu at the active index immediately.
|
163 | *
|
164 | * If a different child menu is already open, it will be closed,
|
165 | * even if there is no active menu.
|
166 | */
|
167 | private _openChildMenu;
|
168 | /**
|
169 | * Close the child menu immediately.
|
170 | *
|
171 | * This is a no-op if a child menu is not open.
|
172 | */
|
173 | private _closeChildMenu;
|
174 | /**
|
175 | * Handle the `aboutToClose` signal of a menu.
|
176 | */
|
177 | private _onMenuAboutToClose;
|
178 | /**
|
179 | * Handle the `menuRequested` signal of a child menu.
|
180 | */
|
181 | private _onMenuMenuRequested;
|
182 | /**
|
183 | * Handle the `changed` signal of a title object.
|
184 | */
|
185 | private _onTitleChanged;
|
186 | private _activeIndex;
|
187 | private _menus;
|
188 | private _childMenu;
|
189 | }
|
190 | /**
|
191 | * The namespace for the `MenuBar` class statics.
|
192 | */
|
193 | export declare namespace MenuBar {
|
194 | |
195 |
|
196 |
|
197 | interface IOptions {
|
198 | |
199 |
|
200 |
|
201 |
|
202 |
|
203 | renderer?: IRenderer;
|
204 | }
|
205 | |
206 |
|
207 |
|
208 | interface IRenderData {
|
209 | |
210 |
|
211 |
|
212 | readonly title: Title<Widget>;
|
213 | |
214 |
|
215 |
|
216 | readonly active: boolean;
|
217 | }
|
218 | |
219 |
|
220 |
|
221 | interface IRenderer {
|
222 | |
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 | renderItem(data: IRenderData): VirtualElement;
|
230 | }
|
231 | |
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 | class Renderer implements IRenderer {
|
238 | |
239 |
|
240 |
|
241 | constructor();
|
242 | /**
|
243 | * Render the virtual element for a menu bar item.
|
244 | *
|
245 | * @param data - The data to use for rendering the item.
|
246 | *
|
247 | * @returns A virtual element representing the item.
|
248 | */
|
249 | renderItem(data: IRenderData): VirtualElement;
|
250 | /**
|
251 | * Render the icon element for a menu bar item.
|
252 | *
|
253 | * @param data - The data to use for rendering the icon.
|
254 | *
|
255 | * @returns A virtual element representing the item icon.
|
256 | */
|
257 | renderIcon(data: IRenderData): VirtualElement;
|
258 | /**
|
259 | * Render the label element for a menu item.
|
260 | *
|
261 | * @param data - The data to use for rendering the label.
|
262 | *
|
263 | * @returns A virtual element representing the item label.
|
264 | */
|
265 | renderLabel(data: IRenderData): VirtualElement;
|
266 | /**
|
267 | * Create the class name for the menu bar item.
|
268 | *
|
269 | * @param data - The data to use for the class name.
|
270 | *
|
271 | * @returns The full class name for the menu item.
|
272 | */
|
273 | createItemClass(data: IRenderData): string;
|
274 | /**
|
275 | * Create the dataset for a menu bar item.
|
276 | *
|
277 | * @param data - The data to use for the item.
|
278 | *
|
279 | * @returns The dataset for the menu bar item.
|
280 | */
|
281 | createItemDataset(data: IRenderData): ElementDataset;
|
282 | /**
|
283 | * Create the class name for the menu bar item icon.
|
284 | *
|
285 | * @param data - The data to use for the class name.
|
286 | *
|
287 | * @returns The full class name for the item icon.
|
288 | */
|
289 | createIconClass(data: IRenderData): string;
|
290 | /**
|
291 | * Create the render content for the label node.
|
292 | *
|
293 | * @param data - The data to use for the label content.
|
294 | *
|
295 | * @returns The content to add to the label node.
|
296 | */
|
297 | formatLabel(data: IRenderData): h.Child;
|
298 | }
|
299 | /**
|
300 | * The default `Renderer` instance.
|
301 | */
|
302 | const defaultRenderer: Renderer;
|
303 | }
|