jupyterlab-emrys
Version:
A computational environment for Jupyter. Powered by Emrys
160 lines (159 loc) • 4.85 kB
TypeScript
import { Message } from 'phosphor-messaging';
import { ISignal } from 'phosphor-signaling';
import { Widget } from 'phosphor-widget';
import { ICompletionModel, ICompletionItem } from './model';
/**
* A widget that enables text completion.
*/
export declare class CompletionWidget extends Widget {
/**
* Create the DOM node for a text completion menu.
*/
static createNode(): HTMLElement;
/**
* Construct a text completion menu widget.
*/
constructor(options?: CompletionWidget.IOptions);
/**
* A signal emitted when a selection is made from the completion menu.
*/
selected: ISignal<CompletionWidget, string>;
/**
* A signal emitted when the completion widget's visibility changes.
*
* #### Notes
* This signal is useful when there are multiple floating widgets that may
* contend with the same space and ought to be mutually exclusive.
*/
visibilityChanged: ISignal<CompletionWidget, void>;
/**
* The model used by the completion widget.
*
* #### Notes
* This is a read-only property.
*/
model: ICompletionModel;
/**
* The semantic parent of the completion widget, its anchor element. An
* event listener will peg the position of the completion widget to the
* anchor element's scroll position. Other event listeners will guarantee
* the completion widget behaves like a child of the reference element even
* if it does not appear as a descendant in the DOM.
*/
anchor: HTMLElement;
/**
* Dispose of the resources held by the completion widget.
*/
dispose(): void;
/**
* Reset the widget.
*/
reset(): void;
/**
* Handle the DOM events for the widget.
*
* @param event - The DOM event sent to the widget.
*
* #### Notes
* This method implements the DOM `EventListener` interface and is
* called in response to events on the dock panel's node. It should
* not be called directly by user code.
*/
handleEvent(event: Event): void;
/**
* Handle `after_attach` messages for the widget.
*/
protected onAfterAttach(msg: Message): void;
/**
* Handle `before_detach` messages for the widget.
*/
protected onBeforeDetach(msg: Message): void;
/**
* Handle model state changes.
*/
protected onModelStateChanged(): void;
/**
* Handle `update_request` messages.
*/
protected onUpdateRequest(msg: Message): void;
/**
* Cycle through the available completion items.
*/
private _cycle(direction);
/**
* Handle keydown events for the widget.
*/
private _evtKeydown(event);
/**
* Handle mousedown events for the widget.
*/
private _evtMousedown(event);
/**
* Handle scroll events for the widget
*/
private _evtScroll(event);
/**
* Populate the completion up to the longest initial subset of items.
*
* @returns `true` if a subset match was found and populated.
*/
private _populateSubset();
/**
* Set the visible dimensions of the widget.
*/
private _setGeometry();
/**
* Emit the selected signal for the current active item and reset.
*/
private _selectActive();
private _anchor;
private _anchorPoint;
private _activeIndex;
private _model;
private _renderer;
}
export declare namespace CompletionWidget {
/**
* The initialization options for a completion widget.
*/
interface IOptions {
/**
* The model for the completion widget.
*/
model?: ICompletionModel;
/**
* The semantic parent of the completion widget, its anchor element. An
* event listener will peg the position of the completion widget to the
* anchor element's scroll position. Other event listeners will guarantee
* the completion widget behaves like a child of the reference element even
* if it does not appear as a descendant in the DOM.
*/
anchor?: HTMLElement;
/**
* The renderer for the completion widget nodes.
*/
renderer?: IRenderer;
}
/**
* A renderer for completion widget nodes.
*/
interface IRenderer {
/**
* Create an item node (an `li` element) for a text completion menu.
*/
createItemNode(item: ICompletionItem): HTMLLIElement;
}
/**
* The default implementation of an `IRenderer`.
*/
class Renderer implements IRenderer {
/**
* Create an item node for a text completion menu.
*/
createItemNode(item: ICompletionItem): HTMLLIElement;
}
/**
* The default `IRenderer` instance.
*/
const defaultRenderer: Renderer;
}