UNPKG

@theia/core

Version:

Theia is a cloud & desktop IDE framework implemented in TypeScript.

141 lines • 6.99 kB
import { MimeData } from '@lumino/coreutils'; import { Drag } from '@lumino/dragdrop'; import { TabBar, Title, Widget } from '@lumino/widgets'; import { Disposable } from '../../common/disposable.js'; import { Emitter, Event } from '../../common/event.js'; /** * The mime type that Lumino drop targets, e.g. dock panels, expect for dragged widgets. */ export declare const WIDGET_FACTORY_MIME_TYPE = "application/vnd.lumino.widget-factory"; export interface TabDropOutsideWindowsEvent { /** The title of the dragged tab. */ title: Title<Widget>; /** The horizontal screen coordinate at which the tab was released. */ screenX: number; /** The vertical screen coordinate at which the tab was released. */ screenY: number; } export interface TabDropEvent { /** The title of the dropped tab. */ title: Title<Widget>; /** The window in which the tab has been dropped. */ window: Window; } type LuminoDragEventType = 'lm-dragenter' | 'lm-dragover' | 'lm-dragleave' | 'lm-dragexit' | 'lm-drop'; interface NativeTabDragSession { readonly title: Title<Widget>; readonly source: Widget; readonly mimeData: MimeData; } interface WindowDragState { readonly window: Window; /** The Lumino drag object used to create the Lumino drag events dispatched in this window. */ drag?: Drag; /** The element under the pointer during the last drag event. */ currentElement?: Element; /** The element that accepted the Lumino `lm-dragenter` event. */ currentTarget?: Element; /** The drop action of the last `lm-dragover` event. */ dropAction: Drag.DropAction; /** Whether the pointer is currently over this window. */ inside: boolean; leaveTimeout?: number; } /** * Drags the tabs of dock panels with native HTML drag and drop instead of Lumino's pointer based drag and drop. * Native drags work across windows, e.g. secondary windows, and show the drag image outside of the window as well. * * Drop targets are not aware of this: the native drag events are translated to the Lumino drag events * (`lm-dragenter`, `lm-dragover`, `lm-dragleave` and `lm-drop`) that Lumino drop targets handle. */ export declare class NativeTabDragService { static readonly MIME_TYPE = "application/vnd.theia.dock-panel-tab"; /** * The time without native drag events in a window after which the pointer is considered to have left the window. * Native `dragleave` events are also fired when the pointer moves between the elements of a window, * while native `dragover` events are fired continuously as long as the pointer is over a window. */ protected static readonly LEAVE_DELAY = 150; protected session: NativeTabDragSession | undefined; protected readonly windows: Map<Window, WindowDragState>; protected readonly onDidDropTabOutsideWindowsEmitter: Emitter<TabDropOutsideWindowsEvent>; /** * Emitted when a tab is released outside of all windows of the application, e.g. over the desktop. */ readonly onDidDropTabOutsideWindows: Event<TabDropOutsideWindowsEvent>; protected readonly onDidDropTabEmitter: Emitter<TabDropEvent>; /** * Emitted when a tab has been dropped on a drop target in one of the windows of the application. */ readonly onDidDropTab: Event<TabDropEvent>; protected readonly onDidStartDragEmitter: Emitter<DragEvent>; /** * Emitted when a tab drag has started, with its `dragstart` event. */ readonly onDidStartDrag: Event<DragEvent>; protected readonly onDidEndDragEmitter: Emitter<DragEvent>; /** * Emitted when a tab drag has ended, with its `dragend` event, or with the `drop` event of a successful drop. * Native drags end without a `mouseup` event. */ readonly onDidEndDrag: Event<DragEvent>; protected init(): void; /** * Translates the native drag events of tab drags in the given window to Lumino drag events. */ installWindow(win: Window): Disposable; /** * Starts dragging the given tab. To be called from the `dragstart` event of the tab. * * @param source the widget that is reported as the source of the Lumino drag events, i.e. the dock panel containing the tab bar */ startDrag(event: DragEvent, tabBar: TabBar<Widget>, title: Title<Widget>, source: Widget): void; /** * Ends the current tab drag. To be called from the `dragend` event of the tab. */ endDrag(event: DragEvent): void; protected handleDragEvent(state: WindowDragState, event: DragEvent): void; protected handleDragOver(state: WindowDragState, event: DragEvent): void; protected handleDrop(state: WindowDragState, event: DragEvent): void; /** * Ends the current drag session and notifies the drop targets under the pointer that the drag has left them. * * @param event the event that ends the drag, i.e. its `dragend` event or the `drop` event of a successful drop */ protected endSession(event: DragEvent): void; /** * @returns whether the pointer is over one of the windows at the end of the given drag event */ protected isInsideWindows(event: DragEvent): boolean; protected containsScreenPoint(win: Window, screenX: number, screenY: number): boolean; /** * Updates the Lumino drop target under the pointer, following `Drag._updateCurrentTarget` in `@lumino/dragdrop`. */ protected updateCurrentTarget(state: WindowDragState, event: DragEvent): void; /** * Follows `Private.dispatchDragEnter` in `@lumino/dragdrop`. */ protected dispatchDragEnter(state: WindowDragState, currElem: Element | undefined, currTarget: Element | undefined, event: DragEvent): Element | undefined; /** * The ancestors of the drop targets, see {@link rememberAncestors}. */ protected readonly targetAncestors: WeakMap<Element, Element[]>; /** * Drop targets are often elements that are replaced while dragging, e.g. the lines of an editor that is re-rendered * because a side panel expands. Lumino drag events dispatched to a removed element don't reach the drop target that * handles them, e.g. the dock panel that has to hide its drop overlay. Such events are dispatched to the nearest * ancestor that is still attached instead. */ protected rememberAncestors(target: Element): void; protected dispatch(state: WindowDragState, type: LuminoDragEventType, target: Element, event: DragEvent, related: Element | undefined): Drag.Event; protected getDrag(state: WindowDragState): Drag; protected scheduleLeave(state: WindowDragState): void; protected cancelLeave(state: WindowDragState): void; /** * Notifies the current drop target, if any, that the pointer has left the window. */ protected leaveWindow(state: WindowDragState): void; protected resetWindow(state: WindowDragState): void; } export {}; //# sourceMappingURL=native-tab-drag-service.d.ts.map