UNPKG

21.3 kBTypeScriptView Raw
1import { Message } from '@lumino/messaging';
2import { ISignal } from '@lumino/signaling';
3import { ElementARIAAttrs, ElementBaseAttrs, ElementDataset, ElementInlineStyle, VirtualElement } from '@lumino/virtualdom';
4import { Title } from './title';
5import { Widget } from './widget';
6/**
7 * A widget which displays titles as a single row or column of tabs.
8 *
9 * #### Notes
10 * If CSS transforms are used to rotate nodes for vertically oriented
11 * text, then tab dragging will not work correctly. The `tabsMovable`
12 * property should be set to `false` when rotating nodes from CSS.
13 */
14export declare class TabBar<T> extends Widget {
15 /**
16 * Construct a new tab bar.
17 *
18 * @param options - The options for initializing the tab bar.
19 */
20 constructor(options?: TabBar.IOptions<T>);
21 /**
22 * Dispose of the resources held by the widget.
23 */
24 dispose(): void;
25 /**
26 * A signal emitted when the current tab is changed.
27 *
28 * #### Notes
29 * This signal is emitted when the currently selected tab is changed
30 * either through user or programmatic interaction.
31 *
32 * Notably, this signal is not emitted when the index of the current
33 * tab changes due to tabs being inserted, removed, or moved. It is
34 * only emitted when the actual current tab node is changed.
35 */
36 get currentChanged(): ISignal<this, TabBar.ICurrentChangedArgs<T>>;
37 /**
38 * A signal emitted when a tab is moved by the user.
39 *
40 * #### Notes
41 * This signal is emitted when a tab is moved by user interaction.
42 *
43 * This signal is not emitted when a tab is moved programmatically.
44 */
45 get tabMoved(): ISignal<this, TabBar.ITabMovedArgs<T>>;
46 /**
47 * A signal emitted when a tab is clicked by the user.
48 *
49 * #### Notes
50 * If the clicked tab is not the current tab, the clicked tab will be
51 * made current and the `currentChanged` signal will be emitted first.
52 *
53 * This signal is emitted even if the clicked tab is the current tab.
54 */
55 get tabActivateRequested(): ISignal<this, TabBar.ITabActivateRequestedArgs<T>>;
56 /**
57 * A signal emitted when the tab bar add button is clicked.
58 */
59 get addRequested(): ISignal<this, void>;
60 /**
61 * A signal emitted when a tab close icon is clicked.
62 *
63 * #### Notes
64 * This signal is not emitted unless the tab title is `closable`.
65 */
66 get tabCloseRequested(): ISignal<this, TabBar.ITabCloseRequestedArgs<T>>;
67 /**
68 * A signal emitted when a tab is dragged beyond the detach threshold.
69 *
70 * #### Notes
71 * This signal is emitted when the user drags a tab with the mouse,
72 * and mouse is dragged beyond the detach threshold.
73 *
74 * The consumer of the signal should call `releaseMouse` and remove
75 * the tab in order to complete the detach.
76 *
77 * This signal is only emitted once per drag cycle.
78 */
79 get tabDetachRequested(): ISignal<this, TabBar.ITabDetachRequestedArgs<T>>;
80 /**
81 * The renderer used by the tab bar.
82 */
83 readonly renderer: TabBar.IRenderer<T>;
84 /**
85 * The document to use with the tab bar.
86 *
87 * The default is the global `document` instance.
88 */
89 get document(): Document | ShadowRoot;
90 /**
91 * Whether the tabs are movable by the user.
92 *
93 * #### Notes
94 * Tabs can always be moved programmatically.
95 */
96 tabsMovable: boolean;
97 /**
98 * Whether the titles can be user-edited.
99 *
100 */
101 get titlesEditable(): boolean;
102 /**
103 * Set whether titles can be user edited.
104 *
105 */
106 set titlesEditable(value: boolean);
107 /**
108 * Whether a tab can be deselected by the user.
109 *
110 * #### Notes
111 * Tabs can be always be deselected programmatically.
112 */
113 allowDeselect: boolean;
114 /**
115 * The selection behavior when inserting a tab.
116 */
117 insertBehavior: TabBar.InsertBehavior;
118 /**
119 * The selection behavior when removing a tab.
120 */
121 removeBehavior: TabBar.RemoveBehavior;
122 /**
123 * Get the currently selected title.
124 *
125 * #### Notes
126 * This will be `null` if no tab is selected.
127 */
128 get currentTitle(): Title<T> | null;
129 /**
130 * Set the currently selected title.
131 *
132 * #### Notes
133 * If the title does not exist, the title will be set to `null`.
134 */
135 set currentTitle(value: Title<T> | null);
136 /**
137 * Get the index of the currently selected tab.
138 *
139 * #### Notes
140 * This will be `-1` if no tab is selected.
141 */
142 get currentIndex(): number;
143 /**
144 * Set the index of the currently selected tab.
145 *
146 * #### Notes
147 * If the value is out of range, the index will be set to `-1`.
148 */
149 set currentIndex(value: number);
150 /**
151 * Get the name of the tab bar.
152 */
153 get name(): string;
154 /**
155 * Set the name of the tab bar.
156 */
157 set name(value: string);
158 /**
159 * Get the orientation of the tab bar.
160 *
161 * #### Notes
162 * This controls whether the tabs are arranged in a row or column.
163 */
164 get orientation(): TabBar.Orientation;
165 /**
166 * Set the orientation of the tab bar.
167 *
168 * #### Notes
169 * This controls whether the tabs are arranged in a row or column.
170 */
171 set orientation(value: TabBar.Orientation);
172 /**
173 * Whether the add button is enabled.
174 */
175 get addButtonEnabled(): boolean;
176 /**
177 * Set whether the add button is enabled.
178 */
179 set addButtonEnabled(value: boolean);
180 /**
181 * A read-only array of the titles in the tab bar.
182 */
183 get titles(): ReadonlyArray<Title<T>>;
184 /**
185 * The tab bar content node.
186 *
187 * #### Notes
188 * This is the node which holds the tab nodes.
189 *
190 * Modifying this node directly can lead to undefined behavior.
191 */
192 get contentNode(): HTMLUListElement;
193 /**
194 * The tab bar add button node.
195 *
196 * #### Notes
197 * This is the node which holds the add button.
198 *
199 * Modifying this node directly can lead to undefined behavior.
200 */
201 get addButtonNode(): HTMLDivElement;
202 /**
203 * Add a tab to the end of the tab bar.
204 *
205 * @param value - The title which holds the data for the tab,
206 * or an options object to convert to a title.
207 *
208 * @returns The title object added to the tab bar.
209 *
210 * #### Notes
211 * If the title is already added to the tab bar, it will be moved.
212 */
213 addTab(value: Title<T> | Title.IOptions<T>): Title<T>;
214 /**
215 * Insert a tab into the tab bar at the specified index.
216 *
217 * @param index - The index at which to insert the tab.
218 *
219 * @param value - The title which holds the data for the tab,
220 * or an options object to convert to a title.
221 *
222 * @returns The title object added to the tab bar.
223 *
224 * #### Notes
225 * The index will be clamped to the bounds of the tabs.
226 *
227 * If the title is already added to the tab bar, it will be moved.
228 */
229 insertTab(index: number, value: Title<T> | Title.IOptions<T>): Title<T>;
230 /**
231 * Remove a tab from the tab bar.
232 *
233 * @param title - The title for the tab to remove.
234 *
235 * #### Notes
236 * This is a no-op if the title is not in the tab bar.
237 */
238 removeTab(title: Title<T>): void;
239 /**
240 * Remove the tab at a given index from the tab bar.
241 *
242 * @param index - The index of the tab to remove.
243 *
244 * #### Notes
245 * This is a no-op if the index is out of range.
246 */
247 removeTabAt(index: number): void;
248 /**
249 * Remove all tabs from the tab bar.
250 */
251 clearTabs(): void;
252 /**
253 * Release the mouse and restore the non-dragged tab positions.
254 *
255 * #### Notes
256 * This will cause the tab bar to stop handling mouse events and to
257 * restore the tabs to their non-dragged positions.
258 */
259 releaseMouse(): void;
260 /**
261 * Handle the DOM events for the tab bar.
262 *
263 * @param event - The DOM event sent to the tab bar.
264 *
265 * #### Notes
266 * This method implements the DOM `EventListener` interface and is
267 * called in response to events on the tab bar's DOM node.
268 *
269 * This should not be called directly by user code.
270 */
271 handleEvent(event: Event): void;
272 /**
273 * A message handler invoked on a `'before-attach'` message.
274 */
275 protected onBeforeAttach(msg: Message): void;
276 /**
277 * A message handler invoked on an `'after-detach'` message.
278 */
279 protected onAfterDetach(msg: Message): void;
280 /**
281 * A message handler invoked on an `'update-request'` message.
282 */
283 protected onUpdateRequest(msg: Message): void;
284 /**
285 * Get the index of the tab which handles tabindex="0".
286 * If the add button handles tabindex="0", -1 is returned.
287 * If none of the previous handles tabindex="0", null is returned.
288 */
289 private _getCurrentTabindex;
290 /**
291 * Handle the `'dblclick'` event for the tab bar.
292 */
293 private _evtDblClick;
294 /**
295 * Handle the `'keydown'` event for the tab bar at capturing phase.
296 */
297 private _evtKeyDownCapturing;
298 /**
299 * Handle the `'keydown'` event for the tab bar at target phase.
300 */
301 private _evtKeyDown;
302 /**
303 * Handle the `'pointerdown'` event for the tab bar.
304 */
305 private _evtPointerDown;
306 /**
307 * Handle the `'pointermove'` event for the tab bar.
308 */
309 private _evtPointerMove;
310 /**
311 * Handle the `'pointerup'` event for the document.
312 */
313 private _evtPointerUp;
314 /**
315 * Release the mouse and restore the non-dragged tab positions.
316 */
317 private _releaseMouse;
318 /**
319 * Adjust the current index for a tab insert operation.
320 *
321 * This method accounts for the tab bar's insertion behavior when
322 * adjusting the current index and emitting the changed signal.
323 */
324 private _adjustCurrentForInsert;
325 /**
326 * Adjust the current index for a tab move operation.
327 *
328 * This method will not cause the actual current tab to change.
329 * It silently adjusts the index to account for the given move.
330 */
331 private _adjustCurrentForMove;
332 /**
333 * Adjust the current index for a tab remove operation.
334 *
335 * This method accounts for the tab bar's remove behavior when
336 * adjusting the current index and emitting the changed signal.
337 */
338 private _adjustCurrentForRemove;
339 /**
340 * Handle the `changed` signal of a title object.
341 */
342 private _onTitleChanged;
343 private _name;
344 private _currentIndex;
345 private _titles;
346 private _orientation;
347 private _document;
348 private _titlesEditable;
349 private _previousTitle;
350 private _dragData;
351 private _addButtonEnabled;
352 private _tabMoved;
353 private _currentChanged;
354 private _addRequested;
355 private _tabCloseRequested;
356 private _tabDetachRequested;
357 private _tabActivateRequested;
358}
359/**
360 * The namespace for the `TabBar` class statics.
361 */
362export declare namespace TabBar {
363 /**
364 * A type alias for a tab bar orientation.
365 */
366 type Orientation = /**
367 * The tabs are arranged in a single row, left-to-right.
368 *
369 * The tab text orientation is horizontal.
370 */ 'horizontal'
371 /**
372 * The tabs are arranged in a single column, top-to-bottom.
373 *
374 * The tab text orientation is horizontal.
375 */
376 | 'vertical';
377 /**
378 * A type alias for the selection behavior on tab insert.
379 */
380 type InsertBehavior = /**
381 * The selected tab will not be changed.
382 */ 'none'
383 /**
384 * The inserted tab will be selected.
385 */
386 | 'select-tab'
387 /**
388 * The inserted tab will be selected if the current tab is null.
389 */
390 | 'select-tab-if-needed';
391 /**
392 * A type alias for the selection behavior on tab remove.
393 */
394 type RemoveBehavior = /**
395 * No tab will be selected.
396 */ 'none'
397 /**
398 * The tab after the removed tab will be selected if possible.
399 */
400 | 'select-tab-after'
401 /**
402 * The tab before the removed tab will be selected if possible.
403 */
404 | 'select-tab-before'
405 /**
406 * The previously selected tab will be selected if possible.
407 */
408 | 'select-previous-tab';
409 /**
410 * An options object for creating a tab bar.
411 */
412 interface IOptions<T> {
413 /**
414 * The document to use with the tab bar.
415 *
416 * The default is the global `document` instance.
417 */
418 document?: Document | ShadowRoot;
419 /**
420 * Name of the tab bar.
421 *
422 * This is used for accessibility reasons. The default is the empty string.
423 */
424 name?: string;
425 /**
426 * The layout orientation of the tab bar.
427 *
428 * The default is `horizontal`.
429 */
430 orientation?: TabBar.Orientation;
431 /**
432 * Whether the tabs are movable by the user.
433 *
434 * The default is `false`.
435 */
436 tabsMovable?: boolean;
437 /**
438 * Whether a tab can be deselected by the user.
439 *
440 * The default is `false`.
441 */
442 allowDeselect?: boolean;
443 /**
444 * Whether the titles can be directly edited by the user.
445 *
446 * The default is `false`.
447 */
448 titlesEditable?: boolean;
449 /**
450 * Whether the add button is enabled.
451 *
452 * The default is `false`.
453 */
454 addButtonEnabled?: boolean;
455 /**
456 * The selection behavior when inserting a tab.
457 *
458 * The default is `'select-tab-if-needed'`.
459 */
460 insertBehavior?: TabBar.InsertBehavior;
461 /**
462 * The selection behavior when removing a tab.
463 *
464 * The default is `'select-tab-after'`.
465 */
466 removeBehavior?: TabBar.RemoveBehavior;
467 /**
468 * A renderer to use with the tab bar.
469 *
470 * The default is a shared renderer instance.
471 */
472 renderer?: IRenderer<T>;
473 }
474 /**
475 * The arguments object for the `currentChanged` signal.
476 */
477 interface ICurrentChangedArgs<T> {
478 /**
479 * The previously selected index.
480 */
481 readonly previousIndex: number;
482 /**
483 * The previously selected title.
484 */
485 readonly previousTitle: Title<T> | null;
486 /**
487 * The currently selected index.
488 */
489 readonly currentIndex: number;
490 /**
491 * The currently selected title.
492 */
493 readonly currentTitle: Title<T> | null;
494 }
495 /**
496 * The arguments object for the `tabMoved` signal.
497 */
498 interface ITabMovedArgs<T> {
499 /**
500 * The previous index of the tab.
501 */
502 readonly fromIndex: number;
503 /**
504 * The current index of the tab.
505 */
506 readonly toIndex: number;
507 /**
508 * The title for the tab.
509 */
510 readonly title: Title<T>;
511 }
512 /**
513 * The arguments object for the `tabActivateRequested` signal.
514 */
515 interface ITabActivateRequestedArgs<T> {
516 /**
517 * The index of the tab to activate.
518 */
519 readonly index: number;
520 /**
521 * The title for the tab.
522 */
523 readonly title: Title<T>;
524 }
525 /**
526 * The arguments object for the `tabCloseRequested` signal.
527 */
528 interface ITabCloseRequestedArgs<T> {
529 /**
530 * The index of the tab to close.
531 */
532 readonly index: number;
533 /**
534 * The title for the tab.
535 */
536 readonly title: Title<T>;
537 }
538 /**
539 * The arguments object for the `tabDetachRequested` signal.
540 */
541 interface ITabDetachRequestedArgs<T> {
542 /**
543 * The index of the tab to detach.
544 */
545 readonly index: number;
546 /**
547 * The title for the tab.
548 */
549 readonly title: Title<T>;
550 /**
551 * The node representing the tab.
552 */
553 readonly tab: HTMLElement;
554 /**
555 * The current client X position of the mouse.
556 */
557 readonly clientX: number;
558 /**
559 * The current client Y position of the mouse.
560 */
561 readonly clientY: number;
562 /**
563 * The mouse position in the tab coordinate.
564 */
565 readonly offset?: {
566 x: number;
567 y: number;
568 };
569 }
570 /**
571 * An object which holds the data to render a tab.
572 */
573 interface IRenderData<T> {
574 /**
575 * The title associated with the tab.
576 */
577 readonly title: Title<T>;
578 /**
579 * Whether the tab is the current tab.
580 */
581 readonly current: boolean;
582 /**
583 * The z-index for the tab.
584 */
585 readonly zIndex: number;
586 /**
587 * The tabindex value for the tab.
588 */
589 readonly tabIndex?: number;
590 }
591 /**
592 * A renderer for use with a tab bar.
593 */
594 interface IRenderer<T> {
595 /**
596 * A selector which matches the close icon node in a tab.
597 */
598 readonly closeIconSelector: string;
599 /**
600 * Render the virtual element for a tab.
601 *
602 * @param data - The data to use for rendering the tab.
603 *
604 * @returns A virtual element representing the tab.
605 */
606 renderTab(data: IRenderData<T>): VirtualElement;
607 }
608 /**
609 * The default implementation of `IRenderer`.
610 *
611 * #### Notes
612 * Subclasses are free to reimplement rendering methods as needed.
613 */
614 class Renderer implements IRenderer<any> {
615 constructor();
616 /**
617 * A selector which matches the close icon node in a tab.
618 */
619 readonly closeIconSelector = ".lm-TabBar-tabCloseIcon";
620 /**
621 * Render the virtual element for a tab.
622 *
623 * @param data - The data to use for rendering the tab.
624 *
625 * @returns A virtual element representing the tab.
626 */
627 renderTab(data: IRenderData<any>): VirtualElement;
628 /**
629 * Render the icon element for a tab.
630 *
631 * @param data - The data to use for rendering the tab.
632 *
633 * @returns A virtual element representing the tab icon.
634 */
635 renderIcon(data: IRenderData<any>): VirtualElement;
636 /**
637 * Render the label element for a tab.
638 *
639 * @param data - The data to use for rendering the tab.
640 *
641 * @returns A virtual element representing the tab label.
642 */
643 renderLabel(data: IRenderData<any>): VirtualElement;
644 /**
645 * Render the close icon element for a tab.
646 *
647 * @param data - The data to use for rendering the tab.
648 *
649 * @returns A virtual element representing the tab close icon.
650 */
651 renderCloseIcon(data: IRenderData<any>): VirtualElement;
652 /**
653 * Create a unique render key for the tab.
654 *
655 * @param data - The data to use for the tab.
656 *
657 * @returns The unique render key for the tab.
658 *
659 * #### Notes
660 * This method caches the key against the tab title the first time
661 * the key is generated. This enables efficient rendering of moved
662 * tabs and avoids subtle hover style artifacts.
663 */
664 createTabKey(data: IRenderData<any>): string;
665 /**
666 * Create the inline style object for a tab.
667 *
668 * @param data - The data to use for the tab.
669 *
670 * @returns The inline style data for the tab.
671 */
672 createTabStyle(data: IRenderData<any>): ElementInlineStyle;
673 /**
674 * Create the class name for the tab.
675 *
676 * @param data - The data to use for the tab.
677 *
678 * @returns The full class name for the tab.
679 */
680 createTabClass(data: IRenderData<any>): string;
681 /**
682 * Create the dataset for a tab.
683 *
684 * @param data - The data to use for the tab.
685 *
686 * @returns The dataset for the tab.
687 */
688 createTabDataset(data: IRenderData<any>): ElementDataset;
689 /**
690 * Create the ARIA attributes for a tab.
691 *
692 * @param data - The data to use for the tab.
693 *
694 * @returns The ARIA attributes for the tab.
695 */
696 createTabARIA(data: IRenderData<any>): ElementARIAAttrs | ElementBaseAttrs;
697 /**
698 * Create the class name for the tab icon.
699 *
700 * @param data - The data to use for the tab.
701 *
702 * @returns The full class name for the tab icon.
703 */
704 createIconClass(data: IRenderData<any>): string;
705 private static _nInstance;
706 private readonly _uuid;
707 private _tabID;
708 private _tabKeys;
709 }
710 /**
711 * The default `Renderer` instance.
712 */
713 const defaultRenderer: Renderer;
714 /**
715 * A selector which matches the add button node in the tab bar.
716 */
717 const addButtonSelector = ".lm-TabBar-addButton";
718}