@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
382 lines • 19 kB
TypeScript
import { PerfectScrollbar } from '../widgets/perfect-scrollbar.js';
import { TabBar, Title, Widget } from '@lumino/widgets';
import { VirtualElement, ElementInlineStyle } from '@lumino/virtualdom';
import { DisposableCollection, MenuPath, SelectionService, CommandService } from '../../common/index.js';
import { ContextMenuRenderer } from '../context-menu-renderer.js';
import { Signal } from '@lumino/signaling';
import { Message } from '@lumino/messaging';
import { TabBarToolbarRegistry, TabBarToolbar } from './tab-bar-toolbar/index.js';
import { TheiaDockPanel } from './theia-dock-panel.js';
import { WidgetDecoration } from '../widget-decoration.js';
import { TabBarDecoratorService } from './tab-bar-decorator.js';
import { IconThemeService } from '../icon-theme-service.js';
import { BreadcrumbsRenderer, BreadcrumbsRendererFactory } from '../breadcrumbs/breadcrumbs-renderer.js';
import { Drag } from '@lumino/dragdrop';
import { CorePreferences } from '../../common/core-preferences.js';
import { HoverService } from '../hover-service.js';
import { Root } from 'react-dom/client';
import { NativeTabDragService } from './native-tab-drag-service.js';
import { TabDropHelper } from './tab-drop-helper.js';
import { ContextKeyService } from '../context-key-service.js';
/** Menu path for tab bars used throughout the application shell. */
export declare const SHELL_TABBAR_CONTEXT_MENU: MenuPath;
export declare const SHELL_TABBAR_CONTEXT_CLOSE: MenuPath;
export declare const SHELL_TABBAR_CONTEXT_COPY: MenuPath;
export declare const SHELL_TABBAR_CONTEXT_HIDE: MenuPath;
export declare const SHELL_TABBAR_CONTEXT_PIN: MenuPath;
export declare const SHELL_TABBAR_CONTEXT_SPLIT: MenuPath;
export declare const TabBarRendererFactory: unique symbol;
export type TabBarRendererFactory = () => TabBarRenderer;
/**
* Size information of DOM elements used for rendering tabs in side bars.
*/
export interface SizeData {
width: number;
height: number;
}
/**
* Extension of the rendering data used for tabs in side bars of the application shell.
*/
export interface SideBarRenderData extends TabBar.IRenderData<Widget> {
labelSize?: SizeData;
iconSize?: SizeData;
paddingTop?: number;
paddingBottom?: number;
visible?: boolean;
/** Leaves the tab out of the side bar while keeping its DOM position aligned with its title index. */
hidden?: boolean;
}
export interface ScrollableRenderData extends TabBar.IRenderData<Widget> {
tabWidth?: number;
}
/**
* A tab bar renderer that offers a context menu. In addition, this renderer is able to
* set an explicit position and size on the icon and label of each tab in a side bar.
* This is necessary because the elements of side bar tabs are rotated using the CSS
* `transform` property, disrupting the browser's ability to arrange those elements
* automatically.
*/
export declare class TabBarRenderer extends TabBar.Renderer {
protected readonly contextMenuRenderer?: ContextMenuRenderer | undefined;
protected readonly decoratorService?: TabBarDecoratorService | undefined;
protected readonly iconThemeService?: IconThemeService | undefined;
protected readonly selectionService?: SelectionService | undefined;
protected readonly commandService?: CommandService | undefined;
protected readonly corePreferences?: CorePreferences | undefined;
protected readonly hoverService?: HoverService | undefined;
protected readonly contextKeyService?: ContextKeyService | undefined;
/**
* The menu path used to render the context menu.
*/
contextMenuPath?: MenuPath;
protected readonly toDispose: DisposableCollection;
constructor(contextMenuRenderer?: ContextMenuRenderer | undefined, decoratorService?: TabBarDecoratorService | undefined, iconThemeService?: IconThemeService | undefined, selectionService?: SelectionService | undefined, commandService?: CommandService | undefined, corePreferences?: CorePreferences | undefined, hoverService?: HoverService | undefined, contextKeyService?: ContextKeyService | undefined);
dispose(): void;
protected _tabBar?: TabBar<Widget>;
protected readonly toDisposeOnTabBar: DisposableCollection;
/**
* A reference to the tab bar is required in order to activate it when a context menu
* is requested.
*/
set tabBar(tabBar: TabBar<Widget> | undefined);
get tabBar(): TabBar<Widget> | undefined;
/**
* Render tabs with the default DOM structure, but additionally register a context menu listener.
* @param {SideBarRenderData} data Data used to render the tab.
* @param {boolean} isInSidePanel An optional check which determines if the tab is in the side-panel.
* @param {boolean} isPartOfHiddenTabBar An optional check which determines if the tab is in the hidden horizontal tab bar.
* @returns {VirtualElement} The virtual element of the rendered tab.
*/
renderTab(data: SideBarRenderData, isInSidePanel?: boolean, isPartOfHiddenTabBar?: boolean): VirtualElement;
createTabClass(data: SideBarRenderData): string;
/**
* Generate ID for an entry in the tab bar
* @param {Title<Widget>} title Title of the widget controlled by this tab bar
* @param {boolean} isPartOfHiddenTabBar Tells us if this entry is part of the hidden horizontal tab bar.
* If yes, add a suffix to differentiate it's ID from the entry in the visible tab bar
* @returns {string} DOM element ID
*/
createTabId(title: Title<Widget>, isPartOfHiddenTabBar?: boolean): string;
/**
* If size information is available for the label and icon, set an explicit height on the tab.
* The height value also considers padding, which should be derived from CSS settings.
*/
createTabStyle(data: SideBarRenderData & ScrollableRenderData): ElementInlineStyle;
/**
* If size information is available for the label, set it as inline style.
* Tab padding and icon size are also considered in the `top` position.
* @param {SideBarRenderData} data Data used to render the tab.
* @param {boolean} isInSidePanel An optional check which determines if the tab is in the side-panel.
* @returns {VirtualElement} The virtual element of the rendered label.
*/
renderLabel(data: SideBarRenderData, isInSidePanel?: boolean): VirtualElement;
protected renderTailDecorations(renderData: SideBarRenderData, isInSidePanel?: boolean): VirtualElement[];
renderBadge(data: SideBarRenderData, isInSidePanel?: boolean): VirtualElement;
renderLock(data: SideBarRenderData, isInSidePanel?: boolean): VirtualElement;
protected readonly decorations: Map<Title<Widget>, WidgetDecoration.Data[]>;
protected resetDecorations(title?: Title<Widget>): void;
/**
* Get all available decorations of a given tab.
* @param {string} title The widget title.
*/
protected getDecorations(title: Title<Widget>): WidgetDecoration.Data[];
/**
* Get the decoration data given the tab URI and the decoration data type.
* @param {string} title The title.
* @param {K} key The type of the decoration data.
*/
protected getDecorationData<K extends keyof WidgetDecoration.Data>(title: Title<Widget>, key: K): WidgetDecoration.Data[K][];
/**
* Get the class of an icon.
* @param {string | string[]} iconName The name of the icon.
* @param {string[]} additionalClasses Additional classes of the icon.
*/
protected getIconClass(iconName: string | string[], additionalClasses?: string[]): string;
/**
* Find duplicate labels from the currently opened tabs in the tab bar.
* Return the appropriate partial paths that can distinguish the identical labels.
*
* E.g., a/p/index.ts => a/..., b/p/index.ts => b/...
*
* To prevent excessively long path displayed, show at maximum three levels from the end by default.
* @param {Title<Widget>[]} titles Array of titles in the current tab bar.
* @returns {Map<string, string>} A map from each tab's original path to its displayed partial path.
*/
findDuplicateLabels(titles: Title<Widget>[]): Map<string, string>;
/**
* If size information is available for the icon, set it as inline style. Tab padding
* is also considered in the `top` position.
* @param {SideBarRenderData} data Data used to render the tab icon.
* @param {boolean} isInSidePanel An optional check which determines if the tab is in the side-panel.
*/
renderIcon(data: SideBarRenderData, isInSidePanel?: boolean): VirtualElement;
protected renderEnhancedPreview(title: Title<Widget>): HTMLDivElement;
protected renderVisualPreview(desiredWidth: number, title: Title<Widget>): HTMLElement | undefined;
protected handleMouseEnterEvent: (event: MouseEvent) => void;
protected handleContextMenuEvent: (event: MouseEvent) => void;
protected handleCloseClickEvent: (event: MouseEvent) => void;
protected handleDblClickEvent: (event: MouseEvent) => void;
}
export interface TabBarPrivateMethods {
_releaseMouse(): void;
}
/**
* A specialized tab bar for the main and bottom areas.
*/
export declare class ScrollableTabBar extends TabBar<Widget> {
protected readonly scrollbarOptions?: PerfectScrollbar.Options | undefined;
protected scrollBar: PerfectScrollbar | undefined;
protected pendingReveal?: Promise<void>;
protected isMouseOver: boolean;
protected needsRecompute: boolean;
protected tabSize: number;
protected _dynamicTabOptions?: ScrollableTabBar.Options;
protected contentContainer: HTMLElement;
protected topRow: HTMLElement;
protected readonly toDispose: DisposableCollection;
protected openTabsContainer: HTMLDivElement;
protected openTabsRoot: Root;
constructor(options?: TabBar.IOptions<Widget>, scrollbarOptions?: PerfectScrollbar.Options | undefined, dynamicTabOptions?: ScrollableTabBar.Options);
set dynamicTabOptions(options: ScrollableTabBar.Options | undefined);
get dynamicTabOptions(): ScrollableTabBar.Options | undefined;
dispose(): void;
protected onBeforeAttach(msg: Message): void;
protected onAfterDetach(msg: Message): void;
protected doReleaseMouse(): void;
protected onAfterAttach(msg: Message): void;
protected onBeforeDetach(msg: Message): void;
protected onUpdateRequest(msg: Message): void;
protected updateTabs(): void;
protected onResize(msg: Widget.ResizeMessage): void;
/**
* Reveal the tab with the given index by moving the scroll bar if necessary.
*/
revealTab(index: number): Promise<void>;
}
export declare namespace ScrollableTabBar {
interface Options {
minimumTabSize: number;
defaultTabSize: number;
}
namespace Styles {
const TAB_BAR_CONTENT_CONTAINER = "lm-TabBar-content-container";
}
}
/**
* Specialized scrollable tab-bar which comes with toolbar support.
* Instead of the following DOM structure.
*
* +-------------------------+
* |[TAB_0][TAB_1][TAB_2][TAB|
* +-------------Scrollable--+
*
* There is a dedicated HTML element for toolbar which does **not** contained in the scrollable element.
*
* +-------------------------+-----------------+
* |[TAB_0][TAB_1][TAB_2][TAB| Toolbar |
* +-------------Scrollable--+-Non-Scrollable-+
*
*/
export declare class ToolbarAwareTabBar extends ScrollableTabBar {
protected readonly tabBarToolbarRegistry: TabBarToolbarRegistry;
protected readonly tabBarToolbarFactory: () => TabBarToolbar;
protected readonly breadcrumbsRendererFactory: BreadcrumbsRendererFactory;
protected toolbar: TabBarToolbar | undefined;
protected breadcrumbsContainer: HTMLElement;
protected readonly breadcrumbsRenderer: BreadcrumbsRenderer;
protected dockPanel: TheiaDockPanel;
constructor(tabBarToolbarRegistry: TabBarToolbarRegistry, tabBarToolbarFactory: () => TabBarToolbar, breadcrumbsRendererFactory: BreadcrumbsRendererFactory, options?: TabBar.IOptions<Widget>, scrollbarOptions?: PerfectScrollbar.Options, dynamicTabOptions?: ScrollableTabBar.Options);
setDockPanel(panel: TheiaDockPanel): void;
/**
* The service used to drag tabs with native drag and drop. Tabs are only dragged natively once
* {@link enableNativeTabDrag} has been called.
*/
nativeTabDragService: NativeTabDragService | undefined;
protected nativeTabDragEnabled: boolean;
get isNativeTabDragEnabled(): boolean;
/**
* Drags tabs with native drag and drop instead of Lumino's tab dragging, which allows dragging them to other windows.
* Does nothing if no {@link nativeTabDragService} is set.
*/
enableNativeTabDrag(): void;
protected handleNativeTabDragEvent(event: Event): void;
/**
* Whether Lumino handles the given event as a press on a tab that may start a drag, i.e. a left button press that
* hits a tab and not its title input. Uses the same hit test as `TabBar._evtPointerDown`.
*/
protected isTabPress(event: MouseEvent): boolean;
/**
* Without preventing the default action of a press on a tab, the browser moves the focus away from the widget that Lumino activated on the press.
*/
protected restoreFocusAfterTabPress(): void;
protected startNativeTabDrag(event: DragEvent): void;
protected updateBreadcrumbs(): Promise<void>;
protected onAfterAttach(msg: Message): void;
protected onBeforeDetach(msg: Message): void;
protected onUpdateRequest(msg: Message): void;
protected updateToolbar(): void;
handleEvent(event: Event): void;
protected isOver(event: Event, element: Element): boolean;
}
/**
* A specialized tab bar for side areas.
*/
export declare class SideTabBar extends ScrollableTabBar {
protected static readonly DRAG_THRESHOLD = 5;
/**
* Emitted when a tab is added to the tab bar.
*/
readonly tabAdded: Signal<this, {
title: Title<Widget>;
}>;
/**
* Side panels can be collapsed by clicking on the currently selected tab. This signal is
* emitted when the mouse is released on the selected tab without initiating a drag.
*/
readonly collapseRequested: Signal<this, Title<Widget>>;
/**
* Emitted when the set of overflowing/hidden tabs changes.
*/
readonly tabsOverflowChanged: Signal<this, {
titles: Title<Widget>[];
startIndex: number;
}>;
/**
* Emitted when a widget is dragged onto the tab bar and dropped. Its tab is to be inserted before the tab at `index`,
* or appended if `index` is the number of tabs.
*/
readonly widgetDropped: Signal<this, {
widget: Widget;
index: number;
}>;
protected readonly widgetDropHelper: TabDropHelper;
protected mouseData?: {
pressX: number;
pressY: number;
mouseDownTabIndex: number;
};
protected tabsOverflowData?: {
titles: Title<Widget>[];
startIndex: number;
};
/**
* Tabs for which this returns `true` are not rendered in the side bar unless they are current.
* Call `update()` after the outcome changes.
*/
shouldHideTitle: (title: Title<Widget>) => boolean;
constructor(options?: TabBar.IOptions<Widget> & PerfectScrollbar.Options);
/**
* Tab bars of the left and right side panel are arranged vertically by rotating their labels.
* Rotation is realized with the CSS `transform` property, which disrupts the browser's ability
* to arrange the involved elements automatically. Therefore the elements are arranged explicitly
* by the TabBarRenderer using inline `height` and `top` styles. However, the size of labels
* must still be computed by the browser, so the rendering is performed in two steps: first the
* tab bar is rendered horizontally inside a _hidden content node_, then it is rendered again
* vertically inside the proper content node. After the first step, size information is gathered
* from all labels so it can be applied during the second step.
*/
get hiddenContentNode(): HTMLUListElement;
insertTab(index: number, value: Title<Widget> | Title.IOptions<Widget>): Title<Widget>;
protected onAfterAttach(msg: Message): void;
protected onAfterDetach(msg: Message): void;
protected onUpdateRequest(msg: Message): void;
protected onResize(msg: Widget.ResizeMessage): void;
/**
* Reveal the tab with the given index by moving it into the non-overflowing tabBar section
* if necessary.
*/
revealTab(index: number): Promise<void>;
/**
* Render the tab bar in the _hidden content node_ (see `hiddenContentNode` for explanation),
* then gather size information for labels and render it again in the proper content node.
*/
protected updateTabs(): void;
protected computeOverflowingTabsData(): void;
/**
* Hide overflowing tabs and return the index of the first hidden tab.
*/
protected hideOverflowingTabs(): number;
/**
* Whether the tab of the given title is currently left out of the side bar.
*/
isHiddenTab(title: Title<Widget>): boolean;
/**
* Whether the given title can be hidden. The last title that is not hidden stays, so the
* side bar never loses every tab.
*/
canHideTitle(title: Title<Widget>): boolean;
/**
* Render the tab bar using the given DOM element as host. The optional `renderData` is forwarded
* to the TabBarRenderer.
*/
protected renderTabs(host: HTMLElement, renderData?: Partial<SideBarRenderData>[]): void;
/**
* The following event processing is used to generate `collapseRequested` signals
* when the mouse goes up on the currently selected tab without too much movement
* between `mousedown` and `mouseup`. The movement threshold is the same that
* is used by the superclass to detect a drag event. The `allowDeselect` option
* of the TabBar constructor cannot be used here because it is triggered when the
* mouse goes down, and thus collides with dragging.
*/
handleEvent(event: Event): void;
protected onMouseDown(event: MouseEvent): void;
protected onMouseUp(event: MouseEvent): void;
protected onMouseMove(event: MouseEvent): void;
toCancelViewContainerDND: DisposableCollection;
protected cancelViewContainerDND: () => void;
/**
* Handles `viewContainerPart` drag enter.
*/
protected onDragEnter: (event: Drag.Event) => void;
/**
* Handle `viewContainerPart` drag over,
* Defines the appropriate `dropAction` and opens the tab on which the mouse stands on for more than 800 ms.
*/
protected onDragOver: (event: Drag.Event) => void;
/**
* Handles dragging a widget, e.g. the tab of an editor or of a view in another side panel, over the tab bar.
*/
protected onWidgetDragOver(event: Drag.Event): void;
protected onWidgetDrop(event: Drag.Event): void;
}
//# sourceMappingURL=tab-bars.d.ts.map