UNPKG

14.5 kBTypeScriptView Raw
1import PerfectScrollbar from 'perfect-scrollbar';
2import { TabBar, Title, Widget } from '@phosphor/widgets';
3import { VirtualElement, ElementInlineStyle } from '@phosphor/virtualdom';
4import { DisposableCollection, MenuPath, SelectionService, CommandService } from '../../common';
5import { ContextMenuRenderer } from '../context-menu-renderer';
6import { Signal } from '@phosphor/signaling';
7import { Message } from '@phosphor/messaging';
8import { TabBarToolbarRegistry, TabBarToolbar } from './tab-bar-toolbar';
9import { WidgetDecoration } from '../widget-decoration';
10import { TabBarDecoratorService } from './tab-bar-decorator';
11import { IconThemeService } from '../icon-theme-service';
12import { BreadcrumbsRenderer, BreadcrumbsRendererFactory } from '../breadcrumbs/breadcrumbs-renderer';
13import { IDragEvent } from '@phosphor/dragdrop';
14import { CorePreferences } from '../core-preferences';
15import { HoverService } from '../hover-service';
16/** Menu path for tab bars used throughout the application shell. */
17export declare const SHELL_TABBAR_CONTEXT_MENU: MenuPath;
18export declare const SHELL_TABBAR_CONTEXT_CLOSE: MenuPath;
19export declare const SHELL_TABBAR_CONTEXT_COPY: MenuPath;
20export declare const SHELL_TABBAR_CONTEXT_PIN: MenuPath;
21export declare const SHELL_TABBAR_CONTEXT_SPLIT: MenuPath;
22export declare const TabBarRendererFactory: unique symbol;
23export declare type TabBarRendererFactory = () => TabBarRenderer;
24/**
25 * Size information of DOM elements used for rendering tabs in side bars.
26 */
27export interface SizeData {
28 width: number;
29 height: number;
30}
31/**
32 * Extension of the rendering data used for tabs in side bars of the application shell.
33 */
34export interface SideBarRenderData extends TabBar.IRenderData<Widget> {
35 labelSize?: SizeData;
36 iconSize?: SizeData;
37 paddingTop?: number;
38 paddingBottom?: number;
39}
40/**
41 * A tab bar renderer that offers a context menu. In addition, this renderer is able to
42 * set an explicit position and size on the icon and label of each tab in a side bar.
43 * This is necessary because the elements of side bar tabs are rotated using the CSS
44 * `transform` property, disrupting the browser's ability to arrange those elements
45 * automatically.
46 */
47export declare class TabBarRenderer extends TabBar.Renderer {
48 protected readonly contextMenuRenderer?: ContextMenuRenderer | undefined;
49 protected readonly decoratorService?: TabBarDecoratorService | undefined;
50 protected readonly iconThemeService?: IconThemeService | undefined;
51 protected readonly selectionService?: SelectionService | undefined;
52 protected readonly commandService?: CommandService | undefined;
53 protected readonly corePreferences?: CorePreferences | undefined;
54 protected readonly hoverService?: HoverService | undefined;
55 /**
56 * The menu path used to render the context menu.
57 */
58 contextMenuPath?: MenuPath;
59 protected readonly toDispose: DisposableCollection;
60 constructor(contextMenuRenderer?: ContextMenuRenderer | undefined, decoratorService?: TabBarDecoratorService | undefined, iconThemeService?: IconThemeService | undefined, selectionService?: SelectionService | undefined, commandService?: CommandService | undefined, corePreferences?: CorePreferences | undefined, hoverService?: HoverService | undefined);
61 dispose(): void;
62 protected _tabBar?: TabBar<Widget>;
63 protected readonly toDisposeOnTabBar: DisposableCollection;
64 /**
65 * A reference to the tab bar is required in order to activate it when a context menu
66 * is requested.
67 */
68 set tabBar(tabBar: TabBar<Widget> | undefined);
69 get tabBar(): TabBar<Widget> | undefined;
70 /**
71 * Render tabs with the default DOM structure, but additionally register a context menu listener.
72 * @param {SideBarRenderData} data Data used to render the tab.
73 * @param {boolean} isInSidePanel An optional check which determines if the tab is in the side-panel.
74 * @param {boolean} isPartOfHiddenTabBar An optional check which determines if the tab is in the hidden horizontal tab bar.
75 * @returns {VirtualElement} The virtual element of the rendered tab.
76 */
77 renderTab(data: SideBarRenderData, isInSidePanel?: boolean, isPartOfHiddenTabBar?: boolean): VirtualElement;
78 /**
79 * Generate ID for an entry in the tab bar
80 * @param {Title<Widget>} title Title of the widget controlled by this tab bar
81 * @param {boolean} isPartOfHiddenTabBar Tells us if this entry is part of the hidden horizontal tab bar.
82 * If yes, add a suffix to differentiate it's ID from the entry in the visible tab bar
83 * @returns {string} DOM element ID
84 */
85 createTabId(title: Title<Widget>, isPartOfHiddenTabBar?: boolean): string;
86 /**
87 * If size information is available for the label and icon, set an explicit height on the tab.
88 * The height value also considers padding, which should be derived from CSS settings.
89 */
90 createTabStyle(data: SideBarRenderData): ElementInlineStyle;
91 /**
92 * If size information is available for the label, set it as inline style.
93 * Tab padding and icon size are also considered in the `top` position.
94 * @param {SideBarRenderData} data Data used to render the tab.
95 * @param {boolean} isInSidePanel An optional check which determines if the tab is in the side-panel.
96 * @returns {VirtualElement} The virtual element of the rendered label.
97 */
98 renderLabel(data: SideBarRenderData, isInSidePanel?: boolean): VirtualElement;
99 renderBadge(data: SideBarRenderData, isInSidePanel?: boolean): VirtualElement;
100 renderLock(data: SideBarRenderData, isInSidePanel?: boolean): VirtualElement;
101 protected readonly decorations: Map<Title<Widget>, WidgetDecoration.Data[]>;
102 protected resetDecorations(title?: Title<Widget>): void;
103 /**
104 * Get all available decorations of a given tab.
105 * @param {string} title The widget title.
106 */
107 protected getDecorations(title: Title<Widget>): WidgetDecoration.Data[];
108 /**
109 * Get the decoration data given the tab URI and the decoration data type.
110 * @param {string} title The title.
111 * @param {K} key The type of the decoration data.
112 */
113 protected getDecorationData<K extends keyof WidgetDecoration.Data>(title: Title<Widget>, key: K): WidgetDecoration.Data[K][];
114 /**
115 * Get the class of an icon.
116 * @param {string | string[]} iconName The name of the icon.
117 * @param {string[]} additionalClasses Additional classes of the icon.
118 */
119 private getIconClass;
120 /**
121 * Find duplicate labels from the currently opened tabs in the tab bar.
122 * Return the appropriate partial paths that can distinguish the identical labels.
123 *
124 * E.g., a/p/index.ts => a/..., b/p/index.ts => b/...
125 *
126 * To prevent excessively long path displayed, show at maximum three levels from the end by default.
127 * @param {Title<Widget>[]} titles Array of titles in the current tab bar.
128 * @returns {Map<string, string>} A map from each tab's original path to its displayed partial path.
129 */
130 findDuplicateLabels(titles: Title<Widget>[]): Map<string, string>;
131 /**
132 * If size information is available for the icon, set it as inline style. Tab padding
133 * is also considered in the `top` position.
134 * @param {SideBarRenderData} data Data used to render the tab icon.
135 * @param {boolean} isInSidePanel An optional check which determines if the tab is in the side-panel.
136 */
137 renderIcon(data: SideBarRenderData, isInSidePanel?: boolean): VirtualElement;
138 protected handleMouseEnterEvent: (event: MouseEvent) => void;
139 protected handleContextMenuEvent: (event: MouseEvent) => void;
140 protected handleCloseClickEvent: (event: MouseEvent) => void;
141 protected handleDblClickEvent: (event: MouseEvent) => void;
142}
143/**
144 * A specialized tab bar for the main and bottom areas.
145 */
146export declare class ScrollableTabBar extends TabBar<Widget> {
147 protected scrollBar?: PerfectScrollbar;
148 private scrollBarFactory;
149 private pendingReveal?;
150 protected readonly toDispose: DisposableCollection;
151 constructor(options?: TabBar.IOptions<Widget> & PerfectScrollbar.Options);
152 dispose(): void;
153 protected onAfterAttach(msg: Message): void;
154 protected onBeforeDetach(msg: Message): void;
155 protected onUpdateRequest(msg: Message): void;
156 protected onResize(msg: Widget.ResizeMessage): void;
157 /**
158 * Reveal the tab with the given index by moving the scroll bar if necessary.
159 */
160 revealTab(index: number): Promise<void>;
161 protected get scrollbarHost(): HTMLElement;
162}
163/**
164 * Specialized scrollable tab-bar which comes with toolbar support.
165 * Instead of the following DOM structure.
166 *
167 * +-------------------------+
168 * |[TAB_0][TAB_1][TAB_2][TAB|
169 * +-------------Scrollable--+
170 *
171 * There is a dedicated HTML element for toolbar which does **not** contained in the scrollable element.
172 *
173 * +-------------------------+-----------------+
174 * |[TAB_0][TAB_1][TAB_2][TAB| Toolbar |
175 * +-------------Scrollable--+-Non-Scrollable-+
176 *
177 */
178export declare class ToolbarAwareTabBar extends ScrollableTabBar {
179 protected readonly tabBarToolbarRegistry: TabBarToolbarRegistry;
180 protected readonly tabBarToolbarFactory: () => TabBarToolbar;
181 protected readonly breadcrumbsRendererFactory: BreadcrumbsRendererFactory;
182 protected readonly options?: (TabBar.IOptions<Widget> & PerfectScrollbar.Options) | undefined;
183 protected contentContainer: HTMLElement;
184 protected toolbar: TabBarToolbar | undefined;
185 protected breadcrumbsContainer: HTMLElement;
186 protected readonly breadcrumbsRenderer: BreadcrumbsRenderer;
187 protected topRow: HTMLElement;
188 constructor(tabBarToolbarRegistry: TabBarToolbarRegistry, tabBarToolbarFactory: () => TabBarToolbar, breadcrumbsRendererFactory: BreadcrumbsRendererFactory, options?: (TabBar.IOptions<Widget> & PerfectScrollbar.Options) | undefined);
189 /**
190 * Overrides the `contentNode` property getter in PhosphorJS' TabBar.
191 */
192 get contentNode(): HTMLUListElement;
193 /**
194 * Overrides the scrollable host from the parent class.
195 */
196 protected get scrollbarHost(): HTMLElement;
197 protected get tabBarContainer(): HTMLElement;
198 protected updateBreadcrumbs(): Promise<void>;
199 protected onAfterAttach(msg: Message): void;
200 protected onBeforeDetach(msg: Message): void;
201 protected onUpdateRequest(msg: Message): void;
202 protected updateToolbar(): void;
203 handleEvent(event: Event): void;
204 /**
205 * Restructures the DOM defined in PhosphorJS.
206 *
207 * By default the tabs (`li`) are contained in the `this.contentNode` (`ul`) which is wrapped in a `div` (`this.node`).
208 * Instead of this structure, we add a container for the `this.contentNode` and for the toolbar.
209 * The scrollbar will only work for the `ul` part but it does not affect the toolbar, so it can be on the right hand-side.
210 */
211 protected rewireDOM(): void;
212}
213export declare namespace ToolbarAwareTabBar {
214 namespace Styles {
215 const TAB_BAR_CONTENT = "p-TabBar-content";
216 const TAB_BAR_CONTENT_CONTAINER = "p-TabBar-content-container";
217 }
218}
219/**
220 * A specialized tab bar for side areas.
221 */
222export declare class SideTabBar extends ScrollableTabBar {
223 private static readonly DRAG_THRESHOLD;
224 /**
225 * Emitted when a tab is added to the tab bar.
226 */
227 readonly tabAdded: Signal<this, {
228 title: Title<Widget>;
229 }>;
230 /**
231 * Side panels can be collapsed by clicking on the currently selected tab. This signal is
232 * emitted when the mouse is released on the selected tab without initiating a drag.
233 */
234 readonly collapseRequested: Signal<this, Title<Widget>>;
235 private mouseData?;
236 constructor(options?: TabBar.IOptions<Widget> & PerfectScrollbar.Options);
237 /**
238 * Tab bars of the left and right side panel are arranged vertically by rotating their labels.
239 * Rotation is realized with the CSS `transform` property, which disrupts the browser's ability
240 * to arrange the involved elements automatically. Therefore the elements are arranged explicitly
241 * by the TabBarRenderer using inline `height` and `top` styles. However, the size of labels
242 * must still be computed by the browser, so the rendering is performed in two steps: first the
243 * tab bar is rendered horizontally inside a _hidden content node_, then it is rendered again
244 * vertically inside the proper content node. After the first step, size information is gathered
245 * from all labels so it can be applied during the second step.
246 */
247 get hiddenContentNode(): HTMLUListElement;
248 insertTab(index: number, value: Title<Widget> | Title.IOptions<Widget>): Title<Widget>;
249 protected onAfterAttach(msg: Message): void;
250 protected onAfterDetach(msg: Message): void;
251 protected onUpdateRequest(msg: Message): void;
252 /**
253 * Render the tab bar in the _hidden content node_ (see `hiddenContentNode` for explanation),
254 * then gather size information for labels and render it again in the proper content node.
255 */
256 protected renderTabBar(): void;
257 /**
258 * Render the tab bar using the given DOM element as host. The optional `renderData` is forwarded
259 * to the TabBarRenderer.
260 */
261 protected renderTabs(host: HTMLElement, renderData?: Partial<SideBarRenderData>[]): void;
262 /**
263 * The following event processing is used to generate `collapseRequested` signals
264 * when the mouse goes up on the currently selected tab without too much movement
265 * between `mousedown` and `mouseup`. The movement threshold is the same that
266 * is used by the superclass to detect a drag event. The `allowDeselect` option
267 * of the TabBar constructor cannot be used here because it is triggered when the
268 * mouse goes down, and thus collides with dragging.
269 */
270 handleEvent(event: Event): void;
271 private onMouseDown;
272 private onMouseUp;
273 private onMouseMove;
274 toCancelViewContainerDND: DisposableCollection;
275 protected cancelViewContainerDND: () => void;
276 /**
277 * Handles `viewContainerPart` drag enter.
278 */
279 protected onDragEnter: (event: IDragEvent) => void;
280 /**
281 * Handle `viewContainerPart` drag over,
282 * Defines the appropriate `dropAction` and opens the tab on which the mouse stands on for more than 800 ms.
283 */
284 protected onDragOver: (event: IDragEvent) => void;
285}
286//# sourceMappingURL=tab-bars.d.ts.map
\No newline at end of file