import { Widget } from '@phosphor/widgets'; import { ILogger, Emitter, Event, ContributionProvider, MaybePromise, WaitUntilEvent } from '../common'; export declare const WidgetFactory: unique symbol; /** * A {@link WidgetFactory} is used to create new widgets. Factory-specific information (options) can be passed as serializable JSON data. * The common {@link WidgetManager} collects `WidgetFactory` contributions and delegates to the corresponding factory when * a widget should be created or restored. To identify widgets the `WidgetManager` uses a description composed of the factory id and the options. * The `WidgetFactory` does support both, synchronous and asynchronous widget creation. * * ### Example usage * * ```typescript * export class MyWidget extends BaseWidget { * } * * @injectable() * export class MyWidgetFactory implements WidgetFactory { * id = 'myWidgetFactory'; * * createWidget(): MaybePromise { * return new MyWidget(); * } * } * ``` */ export interface WidgetFactory { /** * The factory id. */ readonly id: string; /** * Creates a widget using the given options. * @param options factory specific information as serializable JSON data. * * @returns the newly created widget or a promise of the widget */ createWidget(options?: any): MaybePromise; } /** * Representation of the `WidgetConstructionOptions`. * Defines a serializable description to create widgets. */ export interface WidgetConstructionOptions { /** * The id of the widget factory to use. */ factoryId: string; /** * The widget factory specific information. */ options?: any; } /** * Representation of a `willCreateWidgetEvent`. */ export interface WillCreateWidgetEvent extends WaitUntilEvent { /** * The widget which will be created. */ readonly widget: Widget; /** * The widget factory id. */ readonly factoryId: string; } /** * Representation of a `didCreateWidgetEvent`. */ export interface DidCreateWidgetEvent { /** * The widget which was created. */ readonly widget: Widget; /** * The widget factory id. */ readonly factoryId: string; } /** * The {@link WidgetManager} is the common component responsible for creating and managing widgets. Additional widget factories * can be registered by using the {@link WidgetFactory} contribution point. To identify a widget, created by a factory, the factory id and * the creation options are used. This key is commonly referred to as `description` of the widget. */ export declare class WidgetManager { protected _cachedFactories: Map; protected readonly widgets: Map; protected readonly pendingWidgetPromises: Map>; protected readonly factoryProvider: ContributionProvider; protected readonly logger: ILogger; protected readonly onWillCreateWidgetEmitter: Emitter; /** * An event can be used to participate in the widget creation. * Listeners may not dispose the given widget. */ readonly onWillCreateWidget: Event; protected readonly onDidCreateWidgetEmitter: Emitter; readonly onDidCreateWidget: Event; /** * Get the list of widgets created by the given widget factory. * @param factoryId the widget factory id. * * @returns the list of widgets created by the factory with the given id. */ getWidgets(factoryId: string): Widget[]; /** * Try to get the existing widget for the given description. * @param factoryId The widget factory id. * @param options The widget factory specific information. * * @returns the widget if available, else `undefined`. * * The widget is 'available' if it has been created with the same {@link factoryId} and {@link options} by the {@link WidgetManager}. * If the widget's creation is asynchronous, it is only available when the associated `Promise` is resolved. */ tryGetWidget(factoryId: string, options?: any): T | undefined; /** * Try to get the existing widget for the given description. * @param factoryId The widget factory id. * @param options The widget factory specific information. * * @returns A promise that resolves to the widget, if any exists. The promise may be pending, so be cautious when assuming that it will not reject. */ tryGetPendingWidget(factoryId: string, options?: any): MaybePromise | undefined; /** * Get the widget for the given description. * @param factoryId The widget factory id. * @param options The widget factory specific information. * * @returns a promise resolving to the widget if available, else `undefined`. */ getWidget(factoryId: string, options?: any): Promise; protected doGetWidget(key: string): MaybePromise | undefined; /** * Creates a new widget or returns the existing widget for the given description. * @param factoryId the widget factory id. * @param options the widget factory specific information. * * @returns a promise resolving to the widget. */ getOrCreateWidget(factoryId: string, options?: any): Promise; /** * Get the widget construction options. * @param widget the widget. * * @returns the widget construction options if the widget was created through the manager, else `undefined`. */ getDescription(widget: Widget): WidgetConstructionOptions | undefined; /** * Convert the widget construction options to string. * @param options the widget construction options. * * @returns the widget construction options represented as a string. */ protected toKey(options: WidgetConstructionOptions): string; /** * Convert the key into the widget construction options object. * @param key the key. * * @returns the widget construction options object. */ protected fromKey(key: string): WidgetConstructionOptions; protected get factories(): Map; } //# sourceMappingURL=widget-manager.d.ts.map