import { IIterable, IIterator } from '../algorithm/iteration'; import { IDisposable } from '../core/disposable'; import { ConflatableMessage, IMessageHandler, Message } from '../core/messaging'; import { ISignal } from '../core/signaling'; import { Title } from './title'; /** * The base class of the Phosphor widget hierarchy. * * #### Notes * This class will typically be subclassed in order to create a useful * widget. However, it can be used directly to host externally created * content. */ export declare class Widget implements IDisposable, IMessageHandler { /** * Construct a new widget. * * @param options - The options for initializing the widget. */ constructor(options?: Widget.IOptions); /** * Dispose of the widget and its descendant widgets. * * #### Notes * It is unsafe to use the widget after it has been disposed. * * All calls made to this method after the first are a no-op. */ dispose(): void; /** * A signal emitted when the widget is disposed. */ disposed: ISignal; /** * Test whether the widget has been disposed. * * #### Notes * This is a read-only property. */ readonly isDisposed: boolean; /** * Test whether the widget's node is attached to the DOM. * * #### Notes * This is a read-only property. */ readonly isAttached: boolean; /** * Test whether the widget is explicitly hidden. * * #### Notes * This is a read-only property. */ readonly isHidden: boolean; /** * Test whether the widget is visible. * * #### Notes * A widget is visible when it is attached to the DOM, is not * explicitly hidden, and has no explicitly hidden ancestors. * * This is a read-only property. */ readonly isVisible: boolean; /** * Get the DOM node owned by the widget. * * #### Notes * This is a read-only property. */ readonly node: HTMLElement; /** * Get the id of the widget's DOM node. */ /** * Set the id of the widget's DOM node. */ id: string; /** * Get the title object for the widget. * * #### Notes * The title object is used by some container widgets when displaying * the widget alongside some title, such as a tab panel or side bar. * * Since not all widgets will use the title, it is created on demand. * * The `owner` property of the title is set to this widget. * * This is a read-only property. */ readonly title: Title; /** * Get the parent of the widget. * * #### Notes * This will be `null` if the widget does not have a parent. */ /** * Set the parent of the widget. * * #### Notes * Children are typically added to a widget by using a layout, which * means user code will not normally set the parent widget directly. * * The widget will be automatically removed from its old parent. * * This is a no-op if there is no effective parent change. */ parent: Widget; /** * Get the layout for the widget. * * #### Notes * This will be `null` if the widget does not have a layout. */ /** * Set the layout for the widget. * * #### Notes * The layout is single-use only. It cannot be set to `null` and it * cannot be changed after the first assignment. * * The layout is disposed automatically when the widget is disposed. */ layout: Layout; /** * Create an iterator over the widget's children. * * @returns A new iterator over the children of the widget. * * #### Notes * The widget must have a populated layout in order to have children. * * If a layout is not installed, the returned iterator will be empty. */ children(): IIterator; /** * Test whether a widget is a descendant of this widget. * * @param widget - The descendant widget of interest. * * @returns `true` if the widget is a descendant, `false` otherwise. */ contains(widget: Widget): boolean; /** * Test whether the widget's DOM node has the given class name. * * @param name - The class name of interest. * * @returns `true` if the node has the class, `false` otherwise. */ hasClass(name: string): boolean; /** * Add a class name to the widget's DOM node. * * @param name - The class name to add to the node. * * #### Notes * If the class name is already added to the node, this is a no-op. * * The class name must not contain whitespace. */ addClass(name: string): void; /** * Remove a class name from the widget's DOM node. * * @param name - The class name to remove from the node. * * #### Notes * If the class name is not yet added to the node, this is a no-op. * * The class name must not contain whitespace. */ removeClass(name: string): void; /** * Toggle a class name on the widget's DOM node. * * @param name - The class name to toggle on the node. * * @param force - Whether to force add the class (`true`) or force * remove the class (`false`). If not provided, the presence of * the class will be toggled from its current state. * * @returns `true` if the class is now present, `false` otherwise. * * #### Notes * The class name must not contain whitespace. */ toggleClass(name: string, force?: boolean): boolean; /** * Post an `'update-request'` message to the widget. * * #### Notes * This is a simple convenience method for posting the message. */ update(): void; /** * Post a `'fit-request'` message to the widget. * * #### Notes * This is a simple convenience method for posting the message. */ fit(): void; /** * Post an `'activate-request'` message to the widget. * * #### Notes * This is a simple convenience method for posting the message. */ activate(): void; /** * Send a `'close-request'` message to the widget. * * #### Notes * This is a simple convenience method for sending the message. */ close(): void; /** * Show the widget and make it visible to its parent widget. * * #### Notes * This causes the [[isHidden]] property to be `false`. * * If the widget is not explicitly hidden, this is a no-op. */ show(): void; /** * Hide the widget and make it hidden to its parent widget. * * #### Notes * This causes the [[isHidden]] property to be `true`. * * If the widget is explicitly hidden, this is a no-op. */ hide(): void; /** * Show or hide the widget according to a boolean value. * * @param hidden - `true` to hide the widget, or `false` to show it. * * #### Notes * This is a convenience method for `hide()` and `show()`. */ setHidden(hidden: boolean): void; /** * Test whether the given widget flag is set. * * #### Notes * This will not typically be called directly by user code. */ testFlag(flag: WidgetFlag): boolean; /** * Set the given widget flag. * * #### Notes * This will not typically be called directly by user code. */ setFlag(flag: WidgetFlag): void; /** * Clear the given widget flag. * * #### Notes * This will not typically be called directly by user code. */ clearFlag(flag: WidgetFlag): void; /** * Process a message sent to the widget. * * @param msg - The message sent to the widget. * * #### Notes * Subclasses may reimplement this method as needed. */ processMessage(msg: Message): void; /** * Invoke the message processing routine of the widget's layout. * * @param msg - The message to dispatch to the layout. * * #### Notes * This is a no-op if the widget does not have a layout. * * This will not typically be called directly by user code. */ protected notifyLayout(msg: Message): void; /** * A message handler invoked on a `'close-request'` message. * * #### Notes * The default implementation unparents or detaches the widget. */ protected onCloseRequest(msg: Message): void; /** * A message handler invoked on a `'resize'` message. * * #### Notes * The default implementation of this handler is a no-op. */ protected onResize(msg: ResizeMessage): void; /** * A message handler invoked on an `'update-request'` message. * * #### Notes * The default implementation of this handler is a no-op. */ protected onUpdateRequest(msg: Message): void; /** * A message handler invoked on an `'activate-request'` message. * * #### Notes * The default implementation of this handler is a no-op. */ protected onActivateRequest(msg: Message): void; /** * A message handler invoked on an `'after-show'` message. * * #### Notes * The default implementation of this handler is a no-op. */ protected onAfterShow(msg: Message): void; /** * A message handler invoked on a `'before-hide'` message. * * #### Notes * The default implementation of this handler is a no-op. */ protected onBeforeHide(msg: Message): void; /** * A message handler invoked on an `'after-attach'` message. * * #### Notes * The default implementation of this handler is a no-op. */ protected onAfterAttach(msg: Message): void; /** * A message handler invoked on a `'before-detach'` message. * * #### Notes * The default implementation of this handler is a no-op. */ protected onBeforeDetach(msg: Message): void; /** * A message handler invoked on a `'child-added'` message. * * #### Notes * The default implementation of this handler is a no-op. */ protected onChildAdded(msg: ChildMessage): void; /** * A message handler invoked on a `'child-removed'` message. * * #### Notes * The default implementation of this handler is a no-op. */ protected onChildRemoved(msg: ChildMessage): void; private _flags; private _node; private _layout; private _parent; } /** * The namespace for the `Widget` class statics. */ export declare namespace Widget { /** * An options object for initializing a widget. */ interface IOptions { /** * The optional node to use for the widget. * * If a node is provided, the widget will assume full ownership * and control of the node, as if it had created the node itself. * * The default is a new `
`. */ node?: HTMLElement; } /** * Attach a widget to a host DOM node. * * @param widget - The widget of interest. * * @param host - The DOM node to use as the widget's host. * * #### Notes * This will throw an error if the widget is not a root widget, if * the widget is already attached, or if the host is not attached * to the DOM. */ function attach(widget: Widget, host: HTMLElement): void; /** * Detach the widget from its host DOM node. * * @param widget - The widget of interest. * * #### Notes * This will throw an error if the widget is not a root widget, or * if the widget is not attached to the DOM. */ function detach(widget: Widget): void; /** * Prepare a widget for absolute layout geometry. * * @param widget - The widget of interest. * * #### Notes * This sets the inline style position of the widget to `absolute`. */ function prepareGeometry(widget: Widget): void; /** * Reset the layout geometry of a widget. * * @param widget - The widget of interest. * * #### Notes * This clears the inline style position and geometry of the widget. */ function resetGeometry(widget: Widget): void; /** * Set the absolute layout geometry of a widget. * * @param widget - The widget of interest. * * @param left - The desired offset left position of the widget. * * @param top - The desired offset top position of the widget. * * @param width - The desired offset width of the widget. * * @param height - The desired offset height of the widget. * * #### Notes * All dimensions are assumed to be pixels with coordinates relative * to the origin of the widget's offset parent. * * The widget's node is assumed to be position `absolute`. * * If the widget is resized from its previous size, a `ResizeMessage` * will be automatically sent to the widget. */ function setGeometry(widget: Widget, left: number, top: number, width: number, height: number): void; } /** * An abstract base class for creating Phosphor layouts. * * #### Notes * A layout is used to add widgets to a parent and to arrange those * widgets within the parent's DOM node. * * This class implements the base functionality which is required of * nearly all layouts. It must be subclassed in order to be useful. * * Notably, this class does not define a uniform interface for adding * widgets to the layout. A subclass should define that API in a way * which is meaningful for its intended use. */ export declare abstract class Layout implements IIterable, IDisposable { /** * Create an iterator over the widgets in the layout. * * @returns A new iterator over the widgets in the layout. * * #### Notes * This abstract method must be implemented by a subclass. */ abstract iter(): IIterator; /** * Remove a widget from the layout. * * @param widget - The widget to remove from the layout. * * #### Notes * A widget is automatically removed from the layout when its `parent` * is set to `null`. This method should only be invoked directly when * removing a widget from a layout which has yet to be installed on a * parent widget. * * This method should *not* modify the widget's `parent`. */ abstract removeWidget(widget: Widget): void; /** * Dispose of the resources held by the layout. * * #### Notes * This should be reimplemented to clear and dispose of the widgets. * * All reimplementations should call the superclass method. * * This method is called automatically when the parent is disposed. */ dispose(): void; /** * Test whether the layout is disposed. * * #### Notes * This is a read-only property. */ readonly isDisposed: boolean; /** * Get the parent widget of the layout. */ /** * Set the parent widget of the layout. * * #### Notes * This is set automatically when installing the layout on the parent * widget. The parent widget should not be set directly by user code. */ parent: Widget; /** * Process a message sent to the parent widget. * * @param msg - The message sent to the parent widget. * * #### Notes * This method is called by the parent widget to process a message. * * Subclasses may reimplement this method as needed. */ processParentMessage(msg: Message): void; /** * Perform layout initialization which requires the parent widget. * * #### Notes * This method is invoked immediately after the layout is installed * on the parent widget. * * The default implementation reparents all of the widgets to the * layout parent widget. * * Subclasses should reimplement this method and attach the child * widget nodes to the parent widget's node. */ protected init(): void; /** * A message handler invoked on a `'resize'` message. * * #### Notes * The layout should ensure that its widgets are resized according * to the specified layout space, and that they are sent a `'resize'` * message if appropriate. * * The default implementation of this method sends an `UnknownSize` * resize message to all widgets. * * This may be reimplemented by subclasses as needed. */ protected onResize(msg: ResizeMessage): void; /** * A message handler invoked on an `'update-request'` message. * * #### Notes * The layout should ensure that its widgets are resized according * to the available layout space, and that they are sent a `'resize'` * message if appropriate. * * The default implementation of this method sends an `UnknownSize` * resize message to all widgets. * * This may be reimplemented by subclasses as needed. */ protected onUpdateRequest(msg: Message): void; /** * A message handler invoked on an `'after-attach'` message. * * #### Notes * The default implementation of this method forwards the message * to all widgets. It assumes all widget nodes are attached to the * parent widget node. * * This may be reimplemented by subclasses as needed. */ protected onAfterAttach(msg: Message): void; /** * A message handler invoked on a `'before-detach'` message. * * #### Notes * The default implementation of this method forwards the message * to all widgets. It assumes all widget nodes are attached to the * parent widget node. * * This may be reimplemented by subclasses as needed. */ protected onBeforeDetach(msg: Message): void; /** * A message handler invoked on an `'after-show'` message. * * #### Notes * The default implementation of this method forwards the message to * all non-hidden widgets. It assumes all widget nodes are attached * to the parent widget node. * * This may be reimplemented by subclasses as needed. */ protected onAfterShow(msg: Message): void; /** * A message handler invoked on a `'before-hide'` message. * * #### Notes * The default implementation of this method forwards the message to * all non-hidden widgets. It assumes all widget nodes are attached * to the parent widget node. * * This may be reimplemented by subclasses as needed. */ protected onBeforeHide(msg: Message): void; /** * A message handler invoked on a `'child-removed'` message. * * #### Notes * This will remove the child widget from the layout. * * Subclasses should **not** typically reimplement this method. */ protected onChildRemoved(msg: ChildMessage): void; /** * A message handler invoked on a `'fit-request'` message. * * #### Notes * The default implementation of this handler is a no-op. */ protected onFitRequest(msg: Message): void; /** * A message handler invoked on a `'child-shown'` message. * * #### Notes * The default implementation of this handler is a no-op. */ protected onChildShown(msg: ChildMessage): void; /** * A message handler invoked on a `'child-hidden'` message. * * #### Notes * The default implementation of this handler is a no-op. */ protected onChildHidden(msg: ChildMessage): void; private _disposed; private _parent; } /** * An enum of widget bit flags. */ export declare enum WidgetFlag { /** * The widget has been disposed. */ IsDisposed = 1, /** * The widget is attached to the DOM. */ IsAttached = 2, /** * The widget is hidden. */ IsHidden = 4, /** * The widget is visible. */ IsVisible = 8, /** * A layout cannot be set on the widget. */ DisallowLayout = 16, } /** * A collection of stateless messages related to widgets. */ export declare namespace WidgetMessage { /** * A singleton `'after-show'` message. * * #### Notes * This message is sent to a widget after it becomes visible. * * This message is **not** sent when the widget is being attached. */ const AfterShow: Message; /** * A singleton `'before-hide'` message. * * #### Notes * This message is sent to a widget before it becomes not-visible. * * This message is **not** sent when the widget is being detached. */ const BeforeHide: Message; /** * A singleton `'after-attach'` message. * * #### Notes * This message is sent to a widget after it is attached. */ const AfterAttach: Message; /** * A singleton `'before-detach'` message. * * #### Notes * This message is sent to a widget before it is detached. */ const BeforeDetach: Message; /** * A singleton `'parent-changed'` message. * * #### Notes * This message is sent to a widget when its parent has changed. */ const ParentChanged: Message; /** * A singleton conflatable `'update-request'` message. * * #### Notes * This message can be dispatched to supporting widgets in order to * update their content based on the current widget state. Not all * widgets will respond to messages of this type. * * For widgets with a layout, this message will inform the layout to * update the position and size of its child widgets. */ const UpdateRequest: ConflatableMessage; /** * A singleton conflatable `'fit-request'` message. * * #### Notes * For widgets with a layout, this message will inform the layout to * recalculate its size constraints to fit the space requirements of * its child widgets, and to update their position and size. Not all * layouts will respond to messages of this type. */ const FitRequest: ConflatableMessage; /** * A singleton conflatable `'activate-request'` message. * * #### Notes * This message should be dispatched to a widget when it should * perform the actions necessary to activate the widget, which * may include focusing its node or descendant node. */ const ActivateRequest: ConflatableMessage; /** * A singleton conflatable `'close-request'` message. * * #### Notes * This message should be dispatched to a widget when it should close * and remove itself from the widget hierarchy. */ const CloseRequest: ConflatableMessage; } /** * A message class for child related messages. */ export declare class ChildMessage extends Message { /** * Construct a new child message. * * @param type - The message type. * * @param child - The child widget for the message. */ constructor(type: string, child: Widget); /** * The child widget for the message. * * #### Notes * This is a read-only property. */ readonly child: Widget; private _child; } /** * A message class for `'resize'` messages. */ export declare class ResizeMessage extends Message { /** * Construct a new resize message. * * @param width - The **offset width** of the widget, or `-1` if * the width is not known. * * @param height - The **offset height** of the widget, or `-1` if * the height is not known. */ constructor(width: number, height: number); /** * The offset width of the widget. * * #### Notes * This will be `-1` if the width is unknown. * * This is a read-only property. */ readonly width: number; /** * The offset height of the widget. * * #### Notes * This will be `-1` if the height is unknown. * * This is a read-only property. */ readonly height: number; private _width; private _height; } /** * The namespace for the `ResizeMessage` class statics. */ export declare namespace ResizeMessage { /** * A singleton `'resize'` message with an unknown size. */ const UnknownSize: ResizeMessage; }