1 | import { Message } from '@lumino/messaging';
|
2 | import { ElementARIAAttrs, ElementDataset, h, VirtualElement } from '@lumino/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 | get childMenu(): Menu | null;
|
31 | /**
|
32 | * The overflow index of the menu bar.
|
33 | */
|
34 | get overflowIndex(): number;
|
35 | /**
|
36 | * The overflow menu of the menu bar.
|
37 | */
|
38 | get overflowMenu(): Menu | null;
|
39 | /**
|
40 | * Get the menu bar content node.
|
41 | *
|
42 | * #### Notes
|
43 | * This is the node which holds the menu title nodes.
|
44 | *
|
45 | * Modifying this node directly can lead to undefined behavior.
|
46 | */
|
47 | get contentNode(): HTMLUListElement;
|
48 | /**
|
49 | * Get the currently active menu.
|
50 | */
|
51 | get activeMenu(): Menu | null;
|
52 | /**
|
53 | * Set the currently active menu.
|
54 | *
|
55 | * #### Notes
|
56 | * If the menu does not exist, the menu will be set to `null`.
|
57 | */
|
58 | set activeMenu(value: Menu | null);
|
59 | /**
|
60 | * Get the index of the currently active menu.
|
61 | *
|
62 | * #### Notes
|
63 | * This will be `-1` if no menu is active.
|
64 | */
|
65 | get activeIndex(): number;
|
66 | /**
|
67 | * Set the index of the currently active menu.
|
68 | *
|
69 | * #### Notes
|
70 | * If the menu cannot be activated, the index will be set to `-1`.
|
71 | */
|
72 | set activeIndex(value: number);
|
73 | /**
|
74 | * A read-only array of the menus in the menu bar.
|
75 | */
|
76 | get menus(): ReadonlyArray<Menu>;
|
77 | /**
|
78 | * Open the active menu and activate its first menu item.
|
79 | *
|
80 | * #### Notes
|
81 | * If there is no active menu, this is a no-op.
|
82 | */
|
83 | openActiveMenu(): void;
|
84 | /**
|
85 | * Add a menu to the end of the menu bar.
|
86 | *
|
87 | * @param menu - The menu to add to the menu bar.
|
88 | *
|
89 | * #### Notes
|
90 | * If the menu is already added to the menu bar, it will be moved.
|
91 | */
|
92 | addMenu(menu: Menu, update?: boolean): void;
|
93 | /**
|
94 | * Insert a menu into the menu bar at the specified index.
|
95 | *
|
96 | * @param index - The index at which to insert the menu.
|
97 | *
|
98 | * @param menu - The menu to insert into the menu bar.
|
99 | *
|
100 | * #### Notes
|
101 | * The index will be clamped to the bounds of the menus.
|
102 | *
|
103 | * If the menu is already added to the menu bar, it will be moved.
|
104 | */
|
105 | insertMenu(index: number, menu: Menu, update?: boolean): void;
|
106 | /**
|
107 | * Remove a menu from the menu bar.
|
108 | *
|
109 | * @param menu - The menu to remove from the menu bar.
|
110 | *
|
111 | * #### Notes
|
112 | * This is a no-op if the menu is not in the menu bar.
|
113 | */
|
114 | removeMenu(menu: Menu, update?: boolean): void;
|
115 | /**
|
116 | * Remove the menu at a given index from the menu bar.
|
117 | *
|
118 | * @param index - The index of the menu to remove.
|
119 | *
|
120 | * #### Notes
|
121 | * This is a no-op if the index is out of range.
|
122 | */
|
123 | removeMenuAt(index: number, update?: boolean): void;
|
124 | /**
|
125 | * Remove all menus from the menu bar.
|
126 | */
|
127 | clearMenus(): void;
|
128 | /**
|
129 | * Handle the DOM events for the menu bar.
|
130 | *
|
131 | * @param event - The DOM event sent to the menu bar.
|
132 | *
|
133 | * #### Notes
|
134 | * This method implements the DOM `EventListener` interface and is
|
135 | * called in response to events on the menu bar's DOM nodes. It
|
136 | * should not be called directly by user code.
|
137 | */
|
138 | handleEvent(event: Event): void;
|
139 | /**
|
140 | * A message handler invoked on a `'before-attach'` message.
|
141 | */
|
142 | protected onBeforeAttach(msg: Message): void;
|
143 | /**
|
144 | * A message handler invoked on an `'after-detach'` message.
|
145 | */
|
146 | protected onAfterDetach(msg: Message): void;
|
147 | /**
|
148 | * A message handler invoked on an `'activate-request'` message.
|
149 | */
|
150 | protected onActivateRequest(msg: Message): void;
|
151 | /**
|
152 | * A message handler invoked on a `'resize'` message.
|
153 | */
|
154 | protected onResize(msg: Widget.ResizeMessage): void;
|
155 | /**
|
156 | * A message handler invoked on an `'update-request'` message.
|
157 | */
|
158 | protected onUpdateRequest(msg: Message): void;
|
159 | /**
|
160 | * Calculate and update the current overflow index.
|
161 | */
|
162 | private _updateOverflowIndex;
|
163 | /**
|
164 | * Handle the `'keydown'` event for the menu bar.
|
165 | *
|
166 | * #### Notes
|
167 | * All keys are trapped except the tab key that is ignored.
|
168 | */
|
169 | private _evtKeyDown;
|
170 | /**
|
171 | * Handle the `'mousedown'` event for the menu bar.
|
172 | */
|
173 | private _evtMouseDown;
|
174 | /**
|
175 | * Handle the `'mousemove'` event for the menu bar.
|
176 | */
|
177 | private _evtMouseMove;
|
178 | /**
|
179 | * Find initial position for the menu based on menubar item position.
|
180 | *
|
181 | * NOTE: this should be called before updating active index to avoid
|
182 | * an additional layout and style invalidation as changing active
|
183 | * index modifies DOM.
|
184 | */
|
185 | private _positionForMenu;
|
186 | /**
|
187 | * Handle the `'focusout'` event for the menu bar.
|
188 | */
|
189 | private _evtFocusOut;
|
190 | /**
|
191 | * Focus an item in the menu bar.
|
192 | *
|
193 | * #### Notes
|
194 | * Does not open the associated menu.
|
195 | */
|
196 | private _focusItemAt;
|
197 | /**
|
198 | * Open the child menu at the active index immediately.
|
199 | *
|
200 | * If a different child menu is already open, it will be closed,
|
201 | * even if there is no active menu.
|
202 | */
|
203 | private _openChildMenu;
|
204 | /**
|
205 | * Close the child menu immediately.
|
206 | *
|
207 | * This is a no-op if a child menu is not open.
|
208 | */
|
209 | private _closeChildMenu;
|
210 | /**
|
211 | * Handle the `aboutToClose` signal of a menu.
|
212 | */
|
213 | private _onMenuAboutToClose;
|
214 | /**
|
215 | * Handle the `menuRequested` signal of a child menu.
|
216 | */
|
217 | private _onMenuMenuRequested;
|
218 | /**
|
219 | * Handle the `changed` signal of a title object.
|
220 | */
|
221 | private _onTitleChanged;
|
222 | private _activeIndex;
|
223 | private _tabFocusIndex;
|
224 | private _forceItemsPosition;
|
225 | private _overflowMenuOptions;
|
226 | private _menus;
|
227 | private _childMenu;
|
228 | private _overflowMenu;
|
229 | private _menuItemSizes;
|
230 | private _overflowIndex;
|
231 | }
|
232 | /**
|
233 | * The namespace for the `MenuBar` class statics.
|
234 | */
|
235 | export declare namespace MenuBar {
|
236 | |
237 |
|
238 |
|
239 | interface IOptions {
|
240 | |
241 |
|
242 |
|
243 |
|
244 |
|
245 | renderer?: IRenderer;
|
246 | |
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 | forceItemsPosition?: Menu.IOpenOptions;
|
256 | |
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 | overflowMenuOptions?: IOverflowMenuOptions;
|
265 | }
|
266 | |
267 |
|
268 |
|
269 | interface IRenderData {
|
270 | |
271 |
|
272 |
|
273 | readonly title: Title<Widget>;
|
274 | |
275 |
|
276 |
|
277 | readonly active: boolean;
|
278 | |
279 |
|
280 |
|
281 | readonly tabbable: boolean;
|
282 | |
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 | readonly disabled?: boolean;
|
290 | readonly onfocus?: (event: FocusEvent) => void;
|
291 | }
|
292 | |
293 |
|
294 |
|
295 | interface IRenderer {
|
296 | |
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 | renderItem(data: IRenderData): VirtualElement;
|
304 | }
|
305 | |
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 | class Renderer implements IRenderer {
|
312 | |
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 | renderItem(data: IRenderData): VirtualElement;
|
320 | |
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 | renderIcon(data: IRenderData): VirtualElement;
|
328 | |
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 | renderLabel(data: IRenderData): VirtualElement;
|
336 | |
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 | createItemClass(data: IRenderData): string;
|
344 | |
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 | createItemDataset(data: IRenderData): ElementDataset;
|
352 | |
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 | createItemARIA(data: IRenderData): ElementARIAAttrs;
|
360 | |
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 | createIconClass(data: IRenderData): string;
|
368 | |
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 | formatLabel(data: IRenderData): h.Child;
|
376 | }
|
377 | |
378 |
|
379 |
|
380 | const defaultRenderer: Renderer;
|
381 | }
|
382 |
|
383 |
|
384 |
|
385 | export interface IOverflowMenuOptions {
|
386 | |
387 |
|
388 |
|
389 |
|
390 |
|
391 | isVisible: boolean;
|
392 | |
393 |
|
394 |
|
395 |
|
396 |
|
397 | title?: string;
|
398 | }
|