phosphor-widget
Advanced tools
Comparing version 1.0.0-beta.2 to 1.0.0-beta.3
@@ -0,2 +1,5 @@ | ||
export * from './layout'; | ||
export * from './messages'; | ||
export * from './panel'; | ||
export * from './title'; | ||
export * from './widget'; |
@@ -12,5 +12,8 @@ /*----------------------------------------------------------------------------- | ||
} | ||
__export(require('./layout')); | ||
__export(require('./messages')); | ||
__export(require('./panel')); | ||
__export(require('./title')); | ||
__export(require('./widget')); | ||
require('./index.css'); | ||
//# sourceMappingURL=index.js.map |
import { Message } from 'phosphor-messaging'; | ||
import { ChildMessage, ResizeMessage, Widget } from './widget'; | ||
import { Layout } from './layout'; | ||
import { ChildMessage, ResizeMessage } from './messages'; | ||
import { Widget } from './widget'; | ||
/** | ||
* An abstract base class for creating widgets which support children. | ||
* A simple and convenient panel widget class. | ||
* | ||
* #### Notes | ||
* This class implements core functionality which is required by nearly | ||
* all widgets which support children. It is a good starting point for | ||
* creating custom panel widgets. | ||
* This class is suitable as a base class for implementing a variety of | ||
* convenience panels, but can also be used directly in combination with | ||
* CSS to arrange a collection of widgets. | ||
* | ||
* For custom panels which cannot express child access with an index | ||
* based API, the `Widget` class may still be used as the base class, | ||
* but such a panel is responsible for **all** child messaging. | ||
* This class provides a convenience wrapper around a [[PanelLayout]]. | ||
*/ | ||
export declare abstract class AbstractPanel extends Widget { | ||
export declare class Panel extends Widget { | ||
/** | ||
* Get the number of children in the panel. | ||
* Create a panel layout to use with a panel. | ||
* | ||
* @returns A new panel layout to use with a panel. | ||
* | ||
* #### Notes | ||
* This may be reimplemented by a subclass to create custom layouts. | ||
*/ | ||
static createLayout(): PanelLayout; | ||
/** | ||
* Construct a new panel. | ||
*/ | ||
constructor(); | ||
/** | ||
* Get the number of child widgets in the panel. | ||
* | ||
* @returns The number of child widgets in the panel. | ||
*/ | ||
childCount(): number; | ||
/** | ||
* Get the child widget at the specified index. | ||
* | ||
* @param index - The index of the child widget of interest. | ||
* | ||
* @returns The child at the specified index, or `undefined`. | ||
*/ | ||
childAt(index: number): Widget; | ||
/** | ||
* Get the index of the specified child widget. | ||
* | ||
* @param child - The child widget of interest. | ||
* | ||
* @returns The index of the specified child, or `-1`. | ||
*/ | ||
childIndex(child: Widget): number; | ||
/** | ||
* Add a child widget to the end of the panel. | ||
* | ||
* @param child - The child widget to add to the panel. | ||
*/ | ||
addChild(child: Widget): void; | ||
/** | ||
* Insert a child widget at the specified index. | ||
* | ||
* @param index - The index at which to insert the child. | ||
* | ||
* @param child - The child widget to insert into to the panel. | ||
*/ | ||
insertChild(index: number, child: Widget): void; | ||
} | ||
/** | ||
* An abstract base class for creating index-based layouts. | ||
* | ||
* #### Notes | ||
* This class implements core functionality which is required by nearly | ||
* all layouts which can be expressed using index-based storage. It is | ||
* a good starting point for creating advanced custom layouts. | ||
* | ||
* This class must be subclassed to make a fully functioning layout. | ||
* | ||
* **See also:** [[PanelLayout]], [[Panel]] | ||
*/ | ||
export declare abstract class AbstractPanelLayout extends Layout { | ||
/** | ||
* Get the number of child widgets in the layout. | ||
* | ||
* @returns The number of child widgets in the layout. | ||
* | ||
* #### Notes | ||
@@ -28,2 +91,4 @@ * This abstract method must be implemented by a subclass. | ||
* | ||
* @param index - The index of the child widget of interest. | ||
* | ||
* @returns The child at the specified index, or `undefined`. | ||
@@ -36,23 +101,24 @@ * | ||
/** | ||
* Remove the specified child from the panel. | ||
* Get the index of the specified child widget. | ||
* | ||
* @param child - The child widget to remove. | ||
* @param child - The child widget of interest. | ||
* | ||
* #### Notes | ||
* This abstract method must be implemented by a subclass. | ||
* @returns The index of the specified child, or `-1`. | ||
*/ | ||
childIndex(child: Widget): number; | ||
/** | ||
* Send a message to all children in the layout. | ||
* | ||
* This method is called automatically as needed. It should not be | ||
* invoked directly by user code. | ||
* @param msg - The message to send to the children. | ||
*/ | ||
protected abstract removeChild(child: Widget): void; | ||
protected sendToAllChildren(msg: Message): void; | ||
/** | ||
* Dispose and clear all children of the panel. | ||
* Send a message to some children in the layout. | ||
* | ||
* #### Notes | ||
* This abstract method must be implemented by a subclass. | ||
* @param msg - The message to send to the children. | ||
* | ||
* This method is called automatically as needed. It should not be | ||
* invoked directly by user code. | ||
* @param pred - A predicate filter function. The message will only | ||
* be send to the children which pass the filter. | ||
*/ | ||
protected abstract disposeChildren(): void; | ||
protected sendToSomeChildren(msg: Message, pred: (child: Widget) => boolean): void; | ||
/** | ||
@@ -62,8 +128,6 @@ * A message handler invoked on a `'resize'` message. | ||
* #### Notes | ||
* The default implementation of this handler sends an [[UnknownSize]] | ||
* resize message to each child. This ensures that the resize messages | ||
* propagate through all widgets in the hierarchy. | ||
* The default implementation of this method sends an `UnknownSize` | ||
* resize message to all children. | ||
* | ||
* Subclasses may reimplement this method as needed, but they must | ||
* dispatch `'resize'` messages to their children as appropriate. | ||
* This may be reimplemented by subclasses as needed. | ||
*/ | ||
@@ -75,76 +139,66 @@ protected onResize(msg: ResizeMessage): void; | ||
* #### Notes | ||
* The default implementation of this handler sends an [[UnknownSize]] | ||
* resize message to each child. This ensures that the all widgets in | ||
* the hierarchy remain correctly sized on updates. | ||
* The default implementation of this method sends an `UnknownSize` | ||
* resize message to all children. | ||
* | ||
* Subclasses may reimplement this method as needed, but they should | ||
* dispatch `'resize'` messages to their children if appropriate. | ||
* This may be reimplemented by subclasses as needed. | ||
*/ | ||
protected onUpdateRequest(msg: Message): void; | ||
/** | ||
* A message handler invoked on an `'after-show'` message. | ||
* A message handler invoked on an `'after-attach'` message. | ||
* | ||
* #### Notes | ||
* The default implementation of this handler forwards the message | ||
* to all of its non-hidden children. | ||
* The default implementation of this method forwards the message | ||
* to all children. | ||
* | ||
* Subclasses may reimplement this method as needed, but they should | ||
* either call the superclass implementation or forward the message | ||
* to their non-hidden children as appropriate. | ||
* This may be reimplemented by subclasses as needed. | ||
*/ | ||
protected onAfterShow(msg: Message): void; | ||
protected onAfterAttach(msg: Message): void; | ||
/** | ||
* A message handler invoked on a `'before-hide'` message. | ||
* A message handler invoked on a `'before-detach'` message. | ||
* | ||
* #### Notes | ||
* The default implementation of this handler forwards the message | ||
* to all of its non-hidden children. | ||
* The default implementation of this method forwards the message | ||
* to all children. | ||
* | ||
* Subclasses may reimplement this method as needed, but they should | ||
* either call the superclass implementation or forward the message | ||
* to their children as appropriate. | ||
* This may be reimplemented by subclasses as needed. | ||
*/ | ||
protected onBeforeHide(msg: Message): void; | ||
protected onBeforeDetach(msg: Message): void; | ||
/** | ||
* A message handler invoked on an `'after-attach'` message. | ||
* A message handler invoked on an `'after-show'` message. | ||
* | ||
* #### Notes | ||
* The default implementation of this handler forwards the message | ||
* to all of its children. | ||
* The default implementation of this method forwards the message | ||
* to all non-hidden children. | ||
* | ||
* Subclasses may reimplement this method as needed, but they should | ||
* either call the superclass implementation or forward the message | ||
* to their children as appropriate. | ||
* This may be reimplemented by subclasses as needed. | ||
*/ | ||
protected onAfterAttach(msg: Message): void; | ||
protected onAfterShow(msg: Message): void; | ||
/** | ||
* A message handler invoked on a `'before-detach'` message. | ||
* A message handler invoked on a `'before-hide'` message. | ||
* | ||
* #### Notes | ||
* The default implementation of this handler forwards the message | ||
* to all of its children. | ||
* The default implementation of this method forwards the message | ||
* to all non-hidden children. | ||
* | ||
* Subclasses may reimplement this method as needed, but they should | ||
* either call the superclass implementation or forward the message | ||
* to their children as appropriate. | ||
* This may be reimplemented by subclasses as needed. | ||
*/ | ||
protected onBeforeDetach(msg: Message): void; | ||
protected onBeforeHide(msg: Message): void; | ||
} | ||
/** | ||
* A simple and convenient concrete panel widget class. | ||
* A concrete layout implementation suitable for many use cases. | ||
* | ||
* #### Notes | ||
* This class is suitable as a base class for implementing a variety of | ||
* layout panels, but can also be used directly in combination with CSS | ||
* in order to layout a collection of widgets. | ||
* layouts, but can also be used directly in combination with CSS in to | ||
* layout a collection of widgets. | ||
*/ | ||
export declare class Panel extends AbstractPanel { | ||
export declare class PanelLayout extends AbstractPanelLayout { | ||
/** | ||
* Construct a new panel. | ||
* Dispose of the resources held by the layout. | ||
*/ | ||
constructor(); | ||
dispose(): void; | ||
/** | ||
* Get the number of children in the panel. | ||
* Get the number of child widgets in the layout. | ||
* | ||
* @returns The number of child widgets in the panel. | ||
* @returns The number of child widgets in the layout. | ||
*/ | ||
@@ -155,2 +209,4 @@ childCount(): number; | ||
* | ||
* @param index - The index of the child widget of interest. | ||
* | ||
* @returns The child at the specified index, or `undefined`. | ||
@@ -160,123 +216,109 @@ */ | ||
/** | ||
* Add a child widget to the end of the panel. | ||
* Add a child widget to the end of the layout. | ||
* | ||
* @param child - The child widget to add to the panel. | ||
* @param child - The child widget to add to the layout. | ||
*/ | ||
addChild(child: Widget): void; | ||
/** | ||
* Insert a child widget at the specified index. | ||
* Insert a child widget into the layout at the specified index. | ||
* | ||
* @param index - The index at which to insert the child. | ||
* @param index - The index at which to insert the child widget. | ||
* | ||
* @param child - The child widget to add to the panel. | ||
* @param child - The child widget to insert into the layout. | ||
*/ | ||
insertChild(index: number, child: Widget): void; | ||
/** | ||
* Process a message sent to the panel. | ||
* Initialize the children of the layout. | ||
* | ||
* @param msg - The message sent to the panel. | ||
* #### Notes | ||
* This method is called automatically when the layout is installed | ||
* on its parent widget. It will reparent all child widgets to the | ||
* layout parent and add invoke the [[attachChild]] method. | ||
* | ||
* #### Notes | ||
* Subclasses may reimplement this method as needed. | ||
* This may be reimplemented by subclasses as needed. | ||
*/ | ||
processMessage(msg: Message): void; | ||
protected initialize(): void; | ||
/** | ||
* Remove the specified child from the panel. | ||
* Attach a child widget to the parent's DOM node. | ||
* | ||
* @param child - The child widget to remove. | ||
* @param index - The index of the child in the layout. | ||
* | ||
* #### Notes | ||
* This method is called automatically as needed. It should not be | ||
* invoked directly by user code. | ||
*/ | ||
protected removeChild(child: Widget): void; | ||
/** | ||
* Dispose and clear all children of the panel. | ||
* @param child - The child widget to attach to the parent. | ||
* | ||
* #### Notes | ||
* This method is called automatically as needed. It should not be | ||
* invoked directly by user code. | ||
*/ | ||
protected disposeChildren(): void; | ||
/** | ||
* A message handler invoked on a `'child-added'` message. | ||
* This method is called automatically by the panel layout at the | ||
* appropriate time. It should not be called directly by user code. | ||
* | ||
* #### Notes | ||
* The default implementation adds the child node to the panel node | ||
* at the proper location and sends an `'after-attach'` message to | ||
* the child if the panel is attached to the DOM. | ||
* The default implementation adds the child's node to the parent's | ||
* node at the proper location, and sends an `'after-attach'` message | ||
* to the child if the parent is attached to the DOM. | ||
* | ||
* Subclasses may reimplement this method to control how the child | ||
* node is added to the panel node, but a reimplementation must send | ||
* an `'after-attach'` message to the child if the panel is attached | ||
* to the DOM. | ||
* Subclasses may reimplement this method to control how the child's | ||
* node is added to the parent's node, but the reimplementation must | ||
* send an `'after-attach'` message to the child if the parent is | ||
* attached to the DOM. | ||
*/ | ||
protected onChildAdded(msg: ChildIndexMessage): void; | ||
protected attachChild(index: number, child: Widget): void; | ||
/** | ||
* A message handler invoked on a `'child-moved'` message. | ||
* Move a child widget in the parent's DOM node. | ||
* | ||
* #### Notes | ||
* The default implementation moves the child node to the proper | ||
* location in the panel node and sends both `'before-detach'` and | ||
* `'after-attach'` message to the child if the panel is attached | ||
* to the DOM. | ||
* @param index - The index of the child in the layout. | ||
* | ||
* Subclasses may reimplement this method to control how the child | ||
* node is moved in the panel node, but a reimplementation must send | ||
* both `'before-detach'` and `'after-attach'` message to the child | ||
* if the panel is attached to the DOM. | ||
*/ | ||
protected onChildMoved(msg: ChildIndexMessage): void; | ||
/** | ||
* A message handler invoked on a `'child-removed'` message. | ||
* @param child - The child widget to detach from the parent. | ||
* | ||
* #### Notes | ||
* The default implementation removes the child node from the panel | ||
* node and sends a `'before-detach'` message to the child if the | ||
* panel is attached to the DOM. | ||
* This method is called automatically by the panel layout at the | ||
* appropriate time. It should not be called directly by user code. | ||
* | ||
* Subclasses may reimplement this method to control how the child | ||
* node is removed from the panel node, but a reimplementation must | ||
* send a `'before-detach'` message to the child if the panel is | ||
* The default implementation moves the child's node to the proper | ||
* location in the parent's node and sends both a `'before-detach'` | ||
* and an `'after-attach'` message to the child if the parent is | ||
* attached to the DOM. | ||
* | ||
* Subclasses may reimplement this method to control how the child's | ||
* node is moved in the parent's node, but the reimplementation must | ||
* send both a `'before-detach'` and an `'after-attach'` message to | ||
* the child if the parent is attached to the DOM. | ||
*/ | ||
protected onChildRemoved(msg: ChildIndexMessage): void; | ||
private _children; | ||
} | ||
/** | ||
* A message class for child messages with index information. | ||
*/ | ||
export declare class ChildIndexMessage extends ChildMessage { | ||
protected moveChild(fromIndex: number, toIndex: number, child: Widget): void; | ||
/** | ||
* Construct a new child message. | ||
* Detach a child widget from the parent's DOM node. | ||
* | ||
* @param type - The message type. | ||
* @param index - The index of the child in the layout. | ||
* | ||
* @param child - The child widget for the message. | ||
* @param child - The child widget to detach from the parent. | ||
* | ||
* @param previousIndex - The previous index of the child, or `-1`. | ||
* #### Notes | ||
* This method is called automatically by the panel layout at the | ||
* appropriate time. It should not be called directly by user code. | ||
* | ||
* @param currentIndex - The current index of the child, or `-1`. | ||
* The default implementation removes the child's node from the | ||
* parent's node, and sends a `'before-detach'` message to the child | ||
* if the parent is attached to the DOM. | ||
* | ||
* Subclasses may reimplement this method to control how the child's | ||
* node is removed from the parent's node, but the reimplementation | ||
* must send a `'before-detach'` message to the child if the parent | ||
* is attached to the DOM. | ||
*/ | ||
constructor(type: string, child: Widget, previousIndex: number, currentIndex: number); | ||
protected detachChild(index: number, child: Widget): void; | ||
/** | ||
* The current index of the child. | ||
* A message handler invoked on a `'child-removed'` message. | ||
* | ||
* #### Notes | ||
* This will be `-1` if the current index is unknown. | ||
* This will remove the child from the layout. | ||
* | ||
* This is a read-only property. | ||
* Subclasses should **not** typically reimplement this method. | ||
*/ | ||
currentIndex: number; | ||
protected onChildRemoved(msg: ChildMessage): void; | ||
/** | ||
* The previous index of the child. | ||
* A message handler invoked on a `'layout-request'` message. | ||
* | ||
* #### Notes | ||
* This will be `-1` if the previous index is unknown. | ||
* The default implementation of this method is a no-op. | ||
* | ||
* This is a read-only property. | ||
* Subclasses may reimplement this method as needed. | ||
*/ | ||
previousIndex: number; | ||
private _currentIndex; | ||
private _previousIndex; | ||
protected onLayoutRequest(msg: Message): void; | ||
private _children; | ||
} |
533
lib/panel.js
@@ -16,3 +16,6 @@ /*----------------------------------------------------------------------------- | ||
var phosphor_messaging_1 = require('phosphor-messaging'); | ||
var layout_1 = require('./layout'); | ||
var messages_1 = require('./messages'); | ||
var widget_1 = require('./widget'); | ||
// TODO - need better solution for storing these class names | ||
/** | ||
@@ -23,31 +26,148 @@ * The class name added to Panel instances. | ||
/** | ||
* An abstract base class for creating widgets which support children. | ||
* A simple and convenient panel widget class. | ||
* | ||
* #### Notes | ||
* This class is suitable as a base class for implementing a variety of | ||
* convenience panels, but can also be used directly in combination with | ||
* CSS to arrange a collection of widgets. | ||
* | ||
* This class provides a convenience wrapper around a [[PanelLayout]]. | ||
*/ | ||
var Panel = (function (_super) { | ||
__extends(Panel, _super); | ||
/** | ||
* Construct a new panel. | ||
*/ | ||
function Panel() { | ||
_super.call(this); | ||
this.addClass(PANEL_CLASS); | ||
this.layout = this.constructor.createLayout(); | ||
} | ||
/** | ||
* Create a panel layout to use with a panel. | ||
* | ||
* @returns A new panel layout to use with a panel. | ||
* | ||
* #### Notes | ||
* This may be reimplemented by a subclass to create custom layouts. | ||
*/ | ||
Panel.createLayout = function () { | ||
return new PanelLayout(); | ||
}; | ||
/** | ||
* Get the number of child widgets in the panel. | ||
* | ||
* @returns The number of child widgets in the panel. | ||
*/ | ||
Panel.prototype.childCount = function () { | ||
return this.layout.childCount(); | ||
}; | ||
/** | ||
* Get the child widget at the specified index. | ||
* | ||
* @param index - The index of the child widget of interest. | ||
* | ||
* @returns The child at the specified index, or `undefined`. | ||
*/ | ||
Panel.prototype.childAt = function (index) { | ||
return this.layout.childAt(index); | ||
}; | ||
/** | ||
* Get the index of the specified child widget. | ||
* | ||
* @param child - The child widget of interest. | ||
* | ||
* @returns The index of the specified child, or `-1`. | ||
*/ | ||
Panel.prototype.childIndex = function (child) { | ||
return this.layout.childIndex(child); | ||
}; | ||
/** | ||
* Add a child widget to the end of the panel. | ||
* | ||
* @param child - The child widget to add to the panel. | ||
*/ | ||
Panel.prototype.addChild = function (child) { | ||
this.layout.addChild(child); | ||
}; | ||
/** | ||
* Insert a child widget at the specified index. | ||
* | ||
* @param index - The index at which to insert the child. | ||
* | ||
* @param child - The child widget to insert into to the panel. | ||
*/ | ||
Panel.prototype.insertChild = function (index, child) { | ||
this.layout.insertChild(index, child); | ||
}; | ||
return Panel; | ||
})(widget_1.Widget); | ||
exports.Panel = Panel; | ||
/** | ||
* An abstract base class for creating index-based layouts. | ||
* | ||
* #### Notes | ||
* This class implements core functionality which is required by nearly | ||
* all widgets which support children. It is a good starting point for | ||
* creating custom panel widgets. | ||
* all layouts which can be expressed using index-based storage. It is | ||
* a good starting point for creating advanced custom layouts. | ||
* | ||
* For custom panels which cannot express child access with an index | ||
* based API, the `Widget` class may still be used as the base class, | ||
* but such a panel is responsible for **all** child messaging. | ||
* This class must be subclassed to make a fully functioning layout. | ||
* | ||
* **See also:** [[PanelLayout]], [[Panel]] | ||
*/ | ||
var AbstractPanel = (function (_super) { | ||
__extends(AbstractPanel, _super); | ||
function AbstractPanel() { | ||
var AbstractPanelLayout = (function (_super) { | ||
__extends(AbstractPanelLayout, _super); | ||
function AbstractPanelLayout() { | ||
_super.apply(this, arguments); | ||
} | ||
/** | ||
* Get the index of the specified child widget. | ||
* | ||
* @param child - The child widget of interest. | ||
* | ||
* @returns The index of the specified child, or `-1`. | ||
*/ | ||
AbstractPanelLayout.prototype.childIndex = function (child) { | ||
for (var i = 0, n = this.childCount(); i < n; ++i) { | ||
if (this.childAt(i) === child) | ||
return i; | ||
} | ||
return -1; | ||
}; | ||
/** | ||
* Send a message to all children in the layout. | ||
* | ||
* @param msg - The message to send to the children. | ||
*/ | ||
AbstractPanelLayout.prototype.sendToAllChildren = function (msg) { | ||
for (var i = 0; i < this.childCount(); ++i) { | ||
phosphor_messaging_1.sendMessage(this.childAt(i), msg); | ||
} | ||
}; | ||
/** | ||
* Send a message to some children in the layout. | ||
* | ||
* @param msg - The message to send to the children. | ||
* | ||
* @param pred - A predicate filter function. The message will only | ||
* be send to the children which pass the filter. | ||
*/ | ||
AbstractPanelLayout.prototype.sendToSomeChildren = function (msg, pred) { | ||
for (var i = 0; i < this.childCount(); ++i) { | ||
var child = this.childAt(i); | ||
if (pred(child)) | ||
phosphor_messaging_1.sendMessage(child, msg); | ||
} | ||
}; | ||
/** | ||
* A message handler invoked on a `'resize'` message. | ||
* | ||
* #### Notes | ||
* The default implementation of this handler sends an [[UnknownSize]] | ||
* resize message to each child. This ensures that the resize messages | ||
* propagate through all widgets in the hierarchy. | ||
* The default implementation of this method sends an `UnknownSize` | ||
* resize message to all children. | ||
* | ||
* Subclasses may reimplement this method as needed, but they must | ||
* dispatch `'resize'` messages to their children as appropriate. | ||
* This may be reimplemented by subclasses as needed. | ||
*/ | ||
AbstractPanel.prototype.onResize = function (msg) { | ||
sendToChildren(this, widget_1.ResizeMessage.UnknownSize); | ||
AbstractPanelLayout.prototype.onResize = function (msg) { | ||
this.sendToAllChildren(messages_1.ResizeMessage.UnknownSize); | ||
}; | ||
@@ -58,95 +178,90 @@ /** | ||
* #### Notes | ||
* The default implementation of this handler sends an [[UnknownSize]] | ||
* resize message to each child. This ensures that the all widgets in | ||
* the hierarchy remain correctly sized on updates. | ||
* The default implementation of this method sends an `UnknownSize` | ||
* resize message to all children. | ||
* | ||
* Subclasses may reimplement this method as needed, but they should | ||
* dispatch `'resize'` messages to their children if appropriate. | ||
* This may be reimplemented by subclasses as needed. | ||
*/ | ||
AbstractPanel.prototype.onUpdateRequest = function (msg) { | ||
sendToChildren(this, widget_1.ResizeMessage.UnknownSize); | ||
AbstractPanelLayout.prototype.onUpdateRequest = function (msg) { | ||
this.sendToAllChildren(messages_1.ResizeMessage.UnknownSize); | ||
}; | ||
/** | ||
* A message handler invoked on an `'after-show'` message. | ||
* A message handler invoked on an `'after-attach'` message. | ||
* | ||
* #### Notes | ||
* The default implementation of this handler forwards the message | ||
* to all of its non-hidden children. | ||
* The default implementation of this method forwards the message | ||
* to all children. | ||
* | ||
* Subclasses may reimplement this method as needed, but they should | ||
* either call the superclass implementation or forward the message | ||
* to their non-hidden children as appropriate. | ||
* This may be reimplemented by subclasses as needed. | ||
*/ | ||
AbstractPanel.prototype.onAfterShow = function (msg) { | ||
sendToNonHiddenChildren(this, msg); | ||
AbstractPanelLayout.prototype.onAfterAttach = function (msg) { | ||
this.sendToAllChildren(msg); | ||
}; | ||
/** | ||
* A message handler invoked on a `'before-hide'` message. | ||
* A message handler invoked on a `'before-detach'` message. | ||
* | ||
* #### Notes | ||
* The default implementation of this handler forwards the message | ||
* to all of its non-hidden children. | ||
* The default implementation of this method forwards the message | ||
* to all children. | ||
* | ||
* Subclasses may reimplement this method as needed, but they should | ||
* either call the superclass implementation or forward the message | ||
* to their children as appropriate. | ||
* This may be reimplemented by subclasses as needed. | ||
*/ | ||
AbstractPanel.prototype.onBeforeHide = function (msg) { | ||
sendToNonHiddenChildren(this, msg); | ||
AbstractPanelLayout.prototype.onBeforeDetach = function (msg) { | ||
this.sendToAllChildren(msg); | ||
}; | ||
/** | ||
* A message handler invoked on an `'after-attach'` message. | ||
* A message handler invoked on an `'after-show'` message. | ||
* | ||
* #### Notes | ||
* The default implementation of this handler forwards the message | ||
* to all of its children. | ||
* The default implementation of this method forwards the message | ||
* to all non-hidden children. | ||
* | ||
* Subclasses may reimplement this method as needed, but they should | ||
* either call the superclass implementation or forward the message | ||
* to their children as appropriate. | ||
* This may be reimplemented by subclasses as needed. | ||
*/ | ||
AbstractPanel.prototype.onAfterAttach = function (msg) { | ||
sendToChildren(this, msg); | ||
AbstractPanelLayout.prototype.onAfterShow = function (msg) { | ||
this.sendToSomeChildren(msg, function (child) { return !child.isHidden; }); | ||
}; | ||
/** | ||
* A message handler invoked on a `'before-detach'` message. | ||
* A message handler invoked on a `'before-hide'` message. | ||
* | ||
* #### Notes | ||
* The default implementation of this handler forwards the message | ||
* to all of its children. | ||
* The default implementation of this method forwards the message | ||
* to all non-hidden children. | ||
* | ||
* Subclasses may reimplement this method as needed, but they should | ||
* either call the superclass implementation or forward the message | ||
* to their children as appropriate. | ||
* This may be reimplemented by subclasses as needed. | ||
*/ | ||
AbstractPanel.prototype.onBeforeDetach = function (msg) { | ||
sendToChildren(this, msg); | ||
AbstractPanelLayout.prototype.onBeforeHide = function (msg) { | ||
this.sendToSomeChildren(msg, function (child) { return !child.isHidden; }); | ||
}; | ||
return AbstractPanel; | ||
})(widget_1.Widget); | ||
exports.AbstractPanel = AbstractPanel; | ||
return AbstractPanelLayout; | ||
})(layout_1.Layout); | ||
exports.AbstractPanelLayout = AbstractPanelLayout; | ||
/** | ||
* A simple and convenient concrete panel widget class. | ||
* A concrete layout implementation suitable for many use cases. | ||
* | ||
* #### Notes | ||
* This class is suitable as a base class for implementing a variety of | ||
* layout panels, but can also be used directly in combination with CSS | ||
* in order to layout a collection of widgets. | ||
* layouts, but can also be used directly in combination with CSS in to | ||
* layout a collection of widgets. | ||
*/ | ||
var Panel = (function (_super) { | ||
__extends(Panel, _super); | ||
/** | ||
* Construct a new panel. | ||
*/ | ||
function Panel() { | ||
_super.call(this); | ||
var PanelLayout = (function (_super) { | ||
__extends(PanelLayout, _super); | ||
function PanelLayout() { | ||
_super.apply(this, arguments); | ||
this._children = []; | ||
this.addClass(PANEL_CLASS); | ||
} | ||
/** | ||
* Get the number of children in the panel. | ||
* Dispose of the resources held by the layout. | ||
*/ | ||
PanelLayout.prototype.dispose = function () { | ||
while (this._children.length > 0) { | ||
this._children.pop().dispose(); | ||
} | ||
_super.prototype.dispose.call(this); | ||
}; | ||
/** | ||
* Get the number of child widgets in the layout. | ||
* | ||
* @returns The number of child widgets in the panel. | ||
* @returns The number of child widgets in the layout. | ||
*/ | ||
Panel.prototype.childCount = function () { | ||
PanelLayout.prototype.childCount = function () { | ||
return this._children.length; | ||
@@ -157,126 +272,142 @@ }; | ||
* | ||
* @param index - The index of the child widget of interest. | ||
* | ||
* @returns The child at the specified index, or `undefined`. | ||
*/ | ||
Panel.prototype.childAt = function (index) { | ||
PanelLayout.prototype.childAt = function (index) { | ||
return this._children[index]; | ||
}; | ||
/** | ||
* Add a child widget to the end of the panel. | ||
* Add a child widget to the end of the layout. | ||
* | ||
* @param child - The child widget to add to the panel. | ||
* @param child - The child widget to add to the layout. | ||
*/ | ||
Panel.prototype.addChild = function (child) { | ||
this.insertChild(this._children.length, child); | ||
PanelLayout.prototype.addChild = function (child) { | ||
this.insertChild(this.childCount(), child); | ||
}; | ||
/** | ||
* Insert a child widget at the specified index. | ||
* Insert a child widget into the layout at the specified index. | ||
* | ||
* @param index - The index at which to insert the child. | ||
* @param index - The index at which to insert the child widget. | ||
* | ||
* @param child - The child widget to add to the panel. | ||
* @param child - The child widget to insert into the layout. | ||
*/ | ||
Panel.prototype.insertChild = function (index, child) { | ||
index = Math.max(0, Math.min(index | 0, this._children.length)); | ||
if (child.parent === this) { | ||
var i = this._children.indexOf(child); | ||
var j = i < index ? index - 1 : index; | ||
PanelLayout.prototype.insertChild = function (index, child) { | ||
child.parent = this.parent; | ||
var i = this.childIndex(child); | ||
var j = Math.max(0, Math.min(index | 0, this.childCount())); | ||
if (i !== -1) { | ||
if (i < j) | ||
j--; | ||
if (i === j) | ||
return; | ||
arrays.move(this._children, i, j); | ||
phosphor_messaging_1.sendMessage(this, new ChildIndexMessage('child-moved', child, i, j)); | ||
if (this.parent) | ||
this.moveChild(i, j, child); | ||
} | ||
else { | ||
this.adoptChild(child); | ||
arrays.insert(this._children, index, child); | ||
phosphor_messaging_1.sendMessage(this, new ChildIndexMessage('child-added', child, -1, index)); | ||
arrays.insert(this._children, j, child); | ||
if (this.parent) | ||
this.attachChild(j, child); | ||
} | ||
}; | ||
/** | ||
* Process a message sent to the panel. | ||
* Initialize the children of the layout. | ||
* | ||
* @param msg - The message sent to the panel. | ||
* #### Notes | ||
* This method is called automatically when the layout is installed | ||
* on its parent widget. It will reparent all child widgets to the | ||
* layout parent and add invoke the [[attachChild]] method. | ||
* | ||
* #### Notes | ||
* Subclasses may reimplement this method as needed. | ||
* This may be reimplemented by subclasses as needed. | ||
*/ | ||
Panel.prototype.processMessage = function (msg) { | ||
switch (msg.type) { | ||
case 'child-added': | ||
this.onChildAdded(msg); | ||
break; | ||
case 'child-moved': | ||
this.onChildMoved(msg); | ||
break; | ||
case 'child-removed': | ||
this.onChildRemoved(msg); | ||
break; | ||
default: | ||
_super.prototype.processMessage.call(this, msg); | ||
PanelLayout.prototype.initialize = function () { | ||
for (var i = 0; i < this.childCount(); ++i) { | ||
var child = this.childAt(i); | ||
child.parent = this.parent; | ||
this.attachChild(i, child); | ||
} | ||
}; | ||
/** | ||
* Remove the specified child from the panel. | ||
* Attach a child widget to the parent's DOM node. | ||
* | ||
* @param child - The child widget to remove. | ||
* @param index - The index of the child in the layout. | ||
* | ||
* @param child - The child widget to attach to the parent. | ||
* | ||
* #### Notes | ||
* This method is called automatically as needed. It should not be | ||
* invoked directly by user code. | ||
*/ | ||
Panel.prototype.removeChild = function (child) { | ||
var i = arrays.remove(this._children, child); | ||
phosphor_messaging_1.sendMessage(this, new ChildIndexMessage('child-removed', child, i, -1)); | ||
}; | ||
/** | ||
* Dispose and clear all children of the panel. | ||
* This method is called automatically by the panel layout at the | ||
* appropriate time. It should not be called directly by user code. | ||
* | ||
* #### Notes | ||
* This method is called automatically as needed. It should not be | ||
* invoked directly by user code. | ||
* The default implementation adds the child's node to the parent's | ||
* node at the proper location, and sends an `'after-attach'` message | ||
* to the child if the parent is attached to the DOM. | ||
* | ||
* Subclasses may reimplement this method to control how the child's | ||
* node is added to the parent's node, but the reimplementation must | ||
* send an `'after-attach'` message to the child if the parent is | ||
* attached to the DOM. | ||
*/ | ||
Panel.prototype.disposeChildren = function () { | ||
while (this._children.length > 0) { | ||
this._children.pop().dispose(); | ||
} | ||
PanelLayout.prototype.attachChild = function (index, child) { | ||
var parent = this.parent; | ||
var ref = this.childAt(index + 1); | ||
parent.node.insertBefore(child.node, ref && ref.node); | ||
if (parent.isAttached) | ||
phosphor_messaging_1.sendMessage(child, widget_1.Widget.MsgAfterAttach); | ||
}; | ||
/** | ||
* A message handler invoked on a `'child-added'` message. | ||
* Move a child widget in the parent's DOM node. | ||
* | ||
* @param index - The index of the child in the layout. | ||
* | ||
* @param child - The child widget to detach from the parent. | ||
* | ||
* #### Notes | ||
* The default implementation adds the child node to the panel node | ||
* at the proper location and sends an `'after-attach'` message to | ||
* the child if the panel is attached to the DOM. | ||
* This method is called automatically by the panel layout at the | ||
* appropriate time. It should not be called directly by user code. | ||
* | ||
* Subclasses may reimplement this method to control how the child | ||
* node is added to the panel node, but a reimplementation must send | ||
* an `'after-attach'` message to the child if the panel is attached | ||
* to the DOM. | ||
* The default implementation moves the child's node to the proper | ||
* location in the parent's node and sends both a `'before-detach'` | ||
* and an `'after-attach'` message to the child if the parent is | ||
* attached to the DOM. | ||
* | ||
* Subclasses may reimplement this method to control how the child's | ||
* node is moved in the parent's node, but the reimplementation must | ||
* send both a `'before-detach'` and an `'after-attach'` message to | ||
* the child if the parent is attached to the DOM. | ||
*/ | ||
Panel.prototype.onChildAdded = function (msg) { | ||
var ref = this._children[msg.currentIndex + 1]; | ||
this.node.insertBefore(msg.child.node, ref && ref.node); | ||
if (this.isAttached) | ||
phosphor_messaging_1.sendMessage(msg.child, widget_1.Widget.MsgAfterAttach); | ||
PanelLayout.prototype.moveChild = function (fromIndex, toIndex, child) { | ||
var parent = this.parent; | ||
var ref = this.childAt(toIndex + 1); | ||
if (parent.isAttached) | ||
phosphor_messaging_1.sendMessage(child, widget_1.Widget.MsgBeforeDetach); | ||
parent.node.insertBefore(child.node, ref && ref.node); | ||
if (parent.isAttached) | ||
phosphor_messaging_1.sendMessage(child, widget_1.Widget.MsgAfterAttach); | ||
}; | ||
/** | ||
* A message handler invoked on a `'child-moved'` message. | ||
* Detach a child widget from the parent's DOM node. | ||
* | ||
* @param index - The index of the child in the layout. | ||
* | ||
* @param child - The child widget to detach from the parent. | ||
* | ||
* #### Notes | ||
* The default implementation moves the child node to the proper | ||
* location in the panel node and sends both `'before-detach'` and | ||
* `'after-attach'` message to the child if the panel is attached | ||
* to the DOM. | ||
* This method is called automatically by the panel layout at the | ||
* appropriate time. It should not be called directly by user code. | ||
* | ||
* Subclasses may reimplement this method to control how the child | ||
* node is moved in the panel node, but a reimplementation must send | ||
* both `'before-detach'` and `'after-attach'` message to the child | ||
* if the panel is attached to the DOM. | ||
* The default implementation removes the child's node from the | ||
* parent's node, and sends a `'before-detach'` message to the child | ||
* if the parent is attached to the DOM. | ||
* | ||
* Subclasses may reimplement this method to control how the child's | ||
* node is removed from the parent's node, but the reimplementation | ||
* must send a `'before-detach'` message to the child if the parent | ||
* is attached to the DOM. | ||
*/ | ||
Panel.prototype.onChildMoved = function (msg) { | ||
if (this.isAttached) | ||
phosphor_messaging_1.sendMessage(msg.child, widget_1.Widget.MsgBeforeDetach); | ||
var ref = this._children[msg.currentIndex + 1]; | ||
this.node.insertBefore(msg.child.node, ref && ref.node); | ||
if (this.isAttached) | ||
phosphor_messaging_1.sendMessage(msg.child, widget_1.Widget.MsgAfterAttach); | ||
PanelLayout.prototype.detachChild = function (index, child) { | ||
var parent = this.parent; | ||
if (parent.isAttached) | ||
phosphor_messaging_1.sendMessage(child, widget_1.Widget.MsgBeforeDetach); | ||
parent.node.removeChild(child.node); | ||
}; | ||
@@ -287,91 +418,23 @@ /** | ||
* #### Notes | ||
* The default implementation removes the child node from the panel | ||
* node and sends a `'before-detach'` message to the child if the | ||
* panel is attached to the DOM. | ||
* This will remove the child from the layout. | ||
* | ||
* Subclasses may reimplement this method to control how the child | ||
* node is removed from the panel node, but a reimplementation must | ||
* send a `'before-detach'` message to the child if the panel is | ||
* attached to the DOM. | ||
* Subclasses should **not** typically reimplement this method. | ||
*/ | ||
Panel.prototype.onChildRemoved = function (msg) { | ||
if (this.isAttached) | ||
phosphor_messaging_1.sendMessage(msg.child, widget_1.Widget.MsgBeforeDetach); | ||
this.node.removeChild(msg.child.node); | ||
PanelLayout.prototype.onChildRemoved = function (msg) { | ||
var i = arrays.remove(this._children, msg.child); | ||
if (i !== -1) | ||
this.detachChild(i, msg.child); | ||
}; | ||
return Panel; | ||
})(AbstractPanel); | ||
exports.Panel = Panel; | ||
/** | ||
* A message class for child messages with index information. | ||
*/ | ||
var ChildIndexMessage = (function (_super) { | ||
__extends(ChildIndexMessage, _super); | ||
/** | ||
* Construct a new child message. | ||
* A message handler invoked on a `'layout-request'` message. | ||
* | ||
* @param type - The message type. | ||
* #### Notes | ||
* The default implementation of this method is a no-op. | ||
* | ||
* @param child - The child widget for the message. | ||
* | ||
* @param previousIndex - The previous index of the child, or `-1`. | ||
* | ||
* @param currentIndex - The current index of the child, or `-1`. | ||
* Subclasses may reimplement this method as needed. | ||
*/ | ||
function ChildIndexMessage(type, child, previousIndex, currentIndex) { | ||
_super.call(this, type, child); | ||
this._currentIndex = currentIndex; | ||
this._previousIndex = previousIndex; | ||
} | ||
Object.defineProperty(ChildIndexMessage.prototype, "currentIndex", { | ||
/** | ||
* The current index of the child. | ||
* | ||
* #### Notes | ||
* This will be `-1` if the current index is unknown. | ||
* | ||
* This is a read-only property. | ||
*/ | ||
get: function () { | ||
return this._currentIndex; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ChildIndexMessage.prototype, "previousIndex", { | ||
/** | ||
* The previous index of the child. | ||
* | ||
* #### Notes | ||
* This will be `-1` if the previous index is unknown. | ||
* | ||
* This is a read-only property. | ||
*/ | ||
get: function () { | ||
return this._previousIndex; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return ChildIndexMessage; | ||
})(widget_1.ChildMessage); | ||
exports.ChildIndexMessage = ChildIndexMessage; | ||
/** | ||
* Send a message to all children of a panel. | ||
*/ | ||
function sendToChildren(panel, msg) { | ||
for (var i = 0; i < panel.childCount(); ++i) { | ||
phosphor_messaging_1.sendMessage(panel.childAt(i), msg); | ||
} | ||
} | ||
/** | ||
* Send a message to all non-hidden children of a panel. | ||
*/ | ||
function sendToNonHiddenChildren(panel, msg) { | ||
for (var i = 0; i < panel.childCount(); ++i) { | ||
var child = panel.childAt(i); | ||
if (!child.hidden) | ||
phosphor_messaging_1.sendMessage(child, msg); | ||
} | ||
} | ||
PanelLayout.prototype.onLayoutRequest = function (msg) { }; | ||
return PanelLayout; | ||
})(AbstractPanelLayout); | ||
exports.PanelLayout = PanelLayout; | ||
//# sourceMappingURL=panel.js.map |
import { IDisposable } from 'phosphor-disposable'; | ||
import { IMessageHandler, Message } from 'phosphor-messaging'; | ||
import { NodeWrapper } from 'phosphor-nodewrapper'; | ||
import { Property } from 'phosphor-properties'; | ||
import { Queue } from 'phosphor-queue'; | ||
import { ISignal, Signal } from 'phosphor-signaling'; | ||
import { Layout } from './layout'; | ||
import { ResizeMessage } from './messages'; | ||
import { Title } from './title'; | ||
/** | ||
@@ -12,3 +14,3 @@ * The base class of the Phosphor widget hierarchy. | ||
* This class will typically be subclassed in order to create a useful | ||
* widget. However, it can be used by itself to host externally created | ||
* widget. However, it can be used directly to host externally created | ||
* content. Simply instantiate an empty widget and add the DOM content | ||
@@ -19,111 +21,2 @@ * directly to the widget's `.node`. | ||
/** | ||
* A singleton `'update-request'` message. | ||
* | ||
* #### Notes | ||
* This message can be dispatched to supporting widgets in order to | ||
* update their content. Not all widgets will respond to messages of | ||
* this type. | ||
* | ||
* This message is typically used to update the position and size of | ||
* a widget's children, or to update a widget's content to reflect | ||
* the current widget state. | ||
* | ||
* Messages of this type are compressed by default. | ||
* | ||
* **See also:** [[update]], [[onUpdateRequest]] | ||
*/ | ||
static MsgUpdateRequest: Message; | ||
/** | ||
* A singleton `'layout-request'` message. | ||
* | ||
* #### Notes | ||
* This message can be dispatched to supporting widgets in order to | ||
* update their layout. Not all widgets will respond to messages of | ||
* this type. | ||
* | ||
* This message is typically used to update the size constraints of | ||
* a widget and to update the position and size of its children. | ||
* | ||
* Messages of this type are compressed by default. | ||
* | ||
* **See also:** [[onLayoutRequest]] | ||
*/ | ||
static MsgLayoutRequest: Message; | ||
/** | ||
* A singleton `'close-request'` message. | ||
* | ||
* #### Notes | ||
* This message should be dispatched to a widget when it should close | ||
* and remove itself from the widget hierarchy. | ||
* | ||
* Messages of this type are compressed by default. | ||
* | ||
* **See also:** [[close]], [[onCloseRequest]] | ||
*/ | ||
static MsgCloseRequest: Message; | ||
/** | ||
* 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. | ||
* | ||
* **See also:** [[isVisible]], [[onAfterShow]] | ||
*/ | ||
static MsgAfterShow: 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. | ||
* | ||
* **See also:** [[isVisible]], [[onBeforeHide]] | ||
*/ | ||
static MsgBeforeHide: Message; | ||
/** | ||
* A singleton `'after-attach'` message. | ||
* | ||
* #### Notes | ||
* This message is sent to a widget after it is attached to the DOM. | ||
* | ||
* **See also:** [[isAttached]], [[onAfterAttach]] | ||
*/ | ||
static MsgAfterAttach: Message; | ||
/** | ||
* A singleton `'before-detach'` message. | ||
* | ||
* #### Notes | ||
* This message is sent to a widget before it is detached from the DOM. | ||
* | ||
* **See also:** [[isAttached]], [[onBeforeDetach]] | ||
*/ | ||
static MsgBeforeDetach: Message; | ||
/** | ||
* A signal emitted when the widget is disposed. | ||
* | ||
* **See also:** [[disposed]], [[isDisposed]] | ||
*/ | ||
static disposedSignal: Signal<Widget, void>; | ||
/** | ||
* A property descriptor which controls the hidden state of a widget. | ||
* | ||
* #### Notes | ||
* This controls whether a widget is explicitly hidden. | ||
* | ||
* Hiding a widget will cause the widget and all of its descendants | ||
* to become not-visible. | ||
* | ||
* This will toggle the presence of `'p-mod-hidden'` on a widget. It | ||
* will also dispatch `'after-show'` and `'before-hide'` messages as | ||
* appropriate. | ||
* | ||
* The default value is `false`. | ||
* | ||
* **See also:** [[hidden]], [[isVisible]] | ||
*/ | ||
static hiddenProperty: Property<Widget, boolean>; | ||
/** | ||
* Construct a new widget. | ||
@@ -138,4 +31,3 @@ */ | ||
* | ||
* If this method is called more than once, all calls made after | ||
* the first will be a no-op. | ||
* All calls made to this method after the first are a no-op. | ||
*/ | ||
@@ -146,11 +38,19 @@ dispose(): void; | ||
* | ||
* #### Notes | ||
* This is a pure delegate to the [[disposedSignal]]. | ||
* **See also:** [[dispose]], [[disposed]] | ||
*/ | ||
disposed: ISignal<Widget, void>; | ||
/** | ||
* Test whether the widget has been disposed. | ||
* | ||
* #### Notes | ||
* This is a read-only property. | ||
* | ||
* **See also:** [[dispose]], [[disposed]] | ||
*/ | ||
isDisposed: boolean; | ||
/** | ||
* Test whether the widget's node is attached to the DOM. | ||
* | ||
* #### Notes | ||
* This is a read-only property which is always safe to access. | ||
* This is a read-only property. | ||
* | ||
@@ -161,10 +61,10 @@ * **See also:** [[attach]], [[detach]] | ||
/** | ||
* Test whether the widget has been disposed. | ||
* Test whether the widget is explicitly hidden. | ||
* | ||
* #### Notes | ||
* This is a read-only property which is always safe to access. | ||
* This is a read-only property. | ||
* | ||
* **See also:** [[disposed]] | ||
* **See also:** [[isVisible]], [[hide]], [[show]] | ||
*/ | ||
isDisposed: boolean; | ||
isHidden: boolean; | ||
/** | ||
@@ -177,41 +77,50 @@ * Test whether the widget is visible. | ||
* | ||
* This is a read-only property which is always safe to access. | ||
* This is a read-only property. | ||
* | ||
* **See also:** [[hidden]] | ||
* **See also:** [[isHidden]], [[hide]], [[show]] | ||
*/ | ||
isVisible: boolean; | ||
/** | ||
* Get whether the widget is explicitly hidden. | ||
* Get the title data object for the widget. | ||
* | ||
* #### Notes | ||
* This is a pure delegate to the [[hiddenProperty]]. | ||
* The title data is used by some container widgets when displaying | ||
* the widget along with a title, such as a tab panel or dock panel. | ||
* | ||
* **See also:** [[isVisible]] | ||
* Not all widgets will make use of the title data, so it is created | ||
* on-demand the first time it is accessed. | ||
*/ | ||
title: Title; | ||
/** | ||
* Set whether the widget is explicitly hidden. | ||
* Get the parent of the widget. | ||
* | ||
* #### Notes | ||
* This is a pure delegate to the [[hiddenProperty]]. | ||
* | ||
* **See also:** [[isVisible]] | ||
* This will be `null` if the widget does not have a parent. | ||
*/ | ||
hidden: boolean; | ||
/** | ||
* Get the parent of the widget. | ||
* Set the parent of the widget. | ||
* | ||
* #### Notes | ||
* This will be `null` if the widget does not have a parent. | ||
* The widget will be automatically removed from its current parent. | ||
* | ||
* This is a read-only property. | ||
* This is a no-op if there is no effective parent change. | ||
*/ | ||
parent: Widget; | ||
/** | ||
* Remove the widget from its current parent. | ||
* Get the layout for the widget. | ||
* | ||
* #### Notes | ||
* This is a no-op if the widget does not have a parent. | ||
* This will be `null` if the widget does not have a layout. | ||
*/ | ||
remove(): void; | ||
/** | ||
* 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; | ||
/** | ||
* Test whether a widget is a descendant of this widget. | ||
@@ -221,4 +130,3 @@ * | ||
* | ||
* @returns `true` if this widget is an ancestor of the given widget, | ||
* or `false` otherwise. | ||
* @returns `true` if the widget is a descendant, `false` otherwise. | ||
*/ | ||
@@ -229,5 +137,2 @@ contains(widget: Widget): boolean; | ||
* | ||
* #### Notes | ||
* This is a convenience method for posting the message to `this`. | ||
* | ||
* **See also:** [[MsgUpdateRequest]], [[onUpdateRequest]] | ||
@@ -239,5 +144,2 @@ */ | ||
* | ||
* #### Notes | ||
* This is a convenience method for sending the message to `this`. | ||
* | ||
* **See also:** [[MsgCloseRequest]], [[onCloseRequest]] | ||
@@ -247,2 +149,16 @@ */ | ||
/** | ||
* Show the widget and make it visible to its parent widget. | ||
* | ||
* #### Notes | ||
* This causes the [[isHidden]] property to be `false`. | ||
*/ | ||
show(): void; | ||
/** | ||
* Hide the widget and make it hidden to its parent widget. | ||
* | ||
* #### Notes | ||
* This causes the [[isHidden]] property to be `true`. | ||
*/ | ||
hide(): void; | ||
/** | ||
* Attach the widget to a host DOM node. | ||
@@ -252,10 +168,4 @@ * | ||
* | ||
* @throws Will throw an error if the widget is not a root widget, | ||
* if the widget is already attached to the DOM, or if the host | ||
* is not attached to the DOM. | ||
* | ||
* #### Notes | ||
* The function should be used in lieu of manual DOM attachment. It | ||
* ensures that an `'after-attach'` message is properly dispatched | ||
* to the widget hierarchy. | ||
* @throws 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. | ||
*/ | ||
@@ -266,20 +176,27 @@ attach(host: HTMLElement): void; | ||
* | ||
* @throws Will throw an error if the widget is not a root widget, | ||
* or if the widget is not attached to the DOM. | ||
* @throws An error if the widget is not a root widget, or if the | ||
* widget is not attached. | ||
*/ | ||
detach(): void; | ||
/** | ||
* Test whether the given widget flag is set. | ||
* | ||
* #### Notes | ||
* The function should be used in lieu of manual DOM detachment. It | ||
* ensures that a `'before-detach'` message is properly dispatched | ||
* to the widget hierarchy. | ||
* This will not typically be consumed directly by user code. | ||
*/ | ||
detach(): void; | ||
testFlag(flag: WidgetFlag): boolean; | ||
/** | ||
* Process a message sent to the widget. | ||
* Set the given widget flag. | ||
* | ||
* @param msg - The message sent to the widget. | ||
* #### Notes | ||
* This will not typically be consumed directly by user code. | ||
*/ | ||
setFlag(flag: WidgetFlag): void; | ||
/** | ||
* Clear the given widget flag. | ||
* | ||
* #### Notes | ||
* Subclasses may reimplement this method as needed. | ||
* This will not typically be consumed directly by user code. | ||
*/ | ||
processMessage(msg: Message): void; | ||
clearFlag(flag: WidgetFlag): void; | ||
/** | ||
@@ -297,3 +214,4 @@ * Compress a message posted to the widget. | ||
* #### Notes | ||
* The default implementation compresses `'update-request'`. | ||
* The default implementation compresses `'update-request'` and | ||
* `'layout-request'` messages. | ||
* | ||
@@ -304,44 +222,21 @@ * Subclasses may reimplement this method as needed. | ||
/** | ||
* Adopt the specified child and set its parent to this widget. | ||
* Process a message sent to the widget. | ||
* | ||
* @param child - The child widget to adopt. | ||
* @param msg - The message sent to the widget. | ||
* | ||
* #### Notes | ||
* This should be called by subclasses which support children in | ||
* order to update the parent reference when a child is added. | ||
* | ||
* This will set the parent reference to the specified child after | ||
* removing the child from its current parent. | ||
* Subclasses may reimplement this method as needed. | ||
*/ | ||
protected adoptChild(child: Widget): void; | ||
processMessage(msg: Message): void; | ||
/** | ||
* Remove the specified child from the widget. | ||
* Invoke the message processing routine of the widget's layout. | ||
* | ||
* #### Notes | ||
* This method **must** be reimplemented by subclasses which support | ||
* children, or undefined behavior will result. | ||
* @param msg - The message to dispatch to the layout. | ||
* | ||
* This method is called automatically as needed. It should not be | ||
* invoked directly by user code. | ||
* | ||
* The default implementation of this method is a no-op. | ||
*/ | ||
protected removeChild(child: Widget): void; | ||
/** | ||
* Dispose the children of the widget. | ||
* | ||
* #### Notes | ||
* This method **must** be reimplemented by subclasses which support | ||
* children, or undefined behavior will result. | ||
* This is a no-op if the widget does not have a layout. | ||
* | ||
* This is called by the `dispose` method at the point where child | ||
* widgets should be disposed. A subclass should call the `dispose` | ||
* method of each child and then clear the reference to the child. | ||
* | ||
* This method is called automatically as needed. It should not be | ||
* invoked directly by user code. | ||
* | ||
* The default implementation of this method is a no-op. | ||
* Subclasses may reimplement this method as needed. | ||
*/ | ||
protected disposeChildren(): void; | ||
protected notifyLayout(msg: Message): void; | ||
/** | ||
@@ -351,7 +246,4 @@ * A message handler invoked on a `'close-request'` message. | ||
* #### Notes | ||
* The default implementation of this handler will remove or detach | ||
* the widget as appropriate. | ||
* The default implementation of this handler detaches the widget. | ||
* | ||
* Subclasses may reimplement this handler for custom close behavior. | ||
* | ||
* **See also:** [[close]], [[MsgCloseRequest]] | ||
@@ -364,2 +256,4 @@ */ | ||
* The default implementation of this handler is a no-op. | ||
* | ||
* **See also:** [[ResizeMessage]] | ||
*/ | ||
@@ -376,10 +270,2 @@ protected onResize(msg: ResizeMessage): void; | ||
/** | ||
* A message handler invoked on a `'layout-request'` message. | ||
* | ||
* The default implementation of this handler is a no-op. | ||
* | ||
* **See also:** [[MsgLayoutRequest]] | ||
*/ | ||
protected onLayoutRequest(msg: Message): void; | ||
/** | ||
* A message handler invoked on an `'after-show'` message. | ||
@@ -416,76 +302,121 @@ * | ||
protected onBeforeDetach(msg: Message): void; | ||
/** | ||
* A message handler invoked on a `'child-shown'` message. | ||
* | ||
* The default implementation of this handler is a no-op. | ||
*/ | ||
protected onChildShown(msg: ChildMessage): void; | ||
/** | ||
* A message handler invoked on a `'child-hidden'` message. | ||
* | ||
* The default implementation of this handler is a no-op. | ||
*/ | ||
protected onChildHidden(msg: ChildMessage): void; | ||
private _flags; | ||
private _layout; | ||
private _parent; | ||
} | ||
/** | ||
* A message class for child related messages. | ||
* The namespace for the `Widget` class statics. | ||
*/ | ||
export declare class ChildMessage extends Message { | ||
export declare namespace Widget { | ||
/** | ||
* Construct a new child message. | ||
* A singleton `'update-request'` message. | ||
* | ||
* @param type - The message type. | ||
* #### Notes | ||
* This message can be dispatched to supporting widgets in order to | ||
* update their content. Not all widgets will respond to messages of | ||
* this type. | ||
* | ||
* @param child - The child widget for the message. | ||
* This message is typically used to update the widget's content to | ||
* reflect the current widget state. | ||
* | ||
* Messages of this type are compressed by default. | ||
* | ||
* **See also:** [[update]], [[onUpdateRequest]] | ||
*/ | ||
constructor(type: string, child: Widget); | ||
const MsgUpdateRequest: Message; | ||
/** | ||
* The child widget for the message. | ||
* A singleton `'layout-request'` message. | ||
* | ||
* #### Notes | ||
* This is a read-only property. | ||
* This message can be dispatched to supporting widgets in order to | ||
* update their layout. Not all widgets will respond to messages of | ||
* this type. | ||
* | ||
* This message is typically used to update the size constraints of | ||
* a widget and to update the position and size of its children. | ||
* | ||
* Messages of this type are compressed by default. | ||
* | ||
* **See also:** [[onLayoutRequest]] | ||
*/ | ||
child: Widget; | ||
private _child; | ||
} | ||
/** | ||
* A message class for `'resize'` messages. | ||
*/ | ||
export declare class ResizeMessage extends Message { | ||
const MsgLayoutRequest: Message; | ||
/** | ||
* A singleton `'resize'` message with an unknown size. | ||
* A singleton `'close-request'` message. | ||
* | ||
* #### Notes | ||
* This message should be dispatched to a widget when it should close | ||
* and remove itself from the widget hierarchy. | ||
* | ||
* Messages of this type are compressed by default. | ||
* | ||
* **See also:** [[close]], [[onCloseRequest]] | ||
*/ | ||
static UnknownSize: ResizeMessage; | ||
const MsgCloseRequest: Message; | ||
/** | ||
* Construct a new resize message. | ||
* A singleton `'after-show'` message. | ||
* | ||
* @param width - The **offset width** of the widget, or `-1` if | ||
* the width is not known. | ||
* #### Notes | ||
* This message is sent to a widget after it becomes visible. | ||
* | ||
* @param height - The **offset height** of the widget, or `-1` if | ||
* the height is not known. | ||
* This message is **not** sent when the widget is being attached. | ||
* | ||
* **See also:** [[isVisible]], [[onAfterShow]] | ||
*/ | ||
constructor(width: number, height: number); | ||
const MsgAfterShow: Message; | ||
/** | ||
* The offset width of the widget. | ||
* A singleton `'before-hide'` message. | ||
* | ||
* #### Notes | ||
* This will be `-1` if the width is unknown. | ||
* This message is sent to a widget before it becomes not-visible. | ||
* | ||
* This is a read-only property. | ||
* This message is **not** sent when the widget is being detached. | ||
* | ||
* **See also:** [[isVisible]], [[onBeforeHide]] | ||
*/ | ||
width: number; | ||
const MsgBeforeHide: Message; | ||
/** | ||
* The offset height of the widget. | ||
* A singleton `'after-attach'` message. | ||
* | ||
* #### Notes | ||
* This will be `-1` if the height is unknown. | ||
* This message is sent to a widget after it is attached. | ||
* | ||
* This is a read-only property. | ||
* **See also:** [[isAttached]], [[onAfterAttach]] | ||
*/ | ||
height: number; | ||
private _width; | ||
private _height; | ||
const MsgAfterAttach: Message; | ||
/** | ||
* A singleton `'before-detach'` message. | ||
* | ||
* #### Notes | ||
* This message is sent to a widget before it is detached. | ||
* | ||
* **See also:** [[isAttached]], [[onBeforeDetach]] | ||
*/ | ||
const MsgBeforeDetach: Message; | ||
/** | ||
* A signal emitted when the widget is disposed. | ||
* | ||
* **See also:** [[disposed]], [[isDisposed]] | ||
*/ | ||
const disposedSignal: Signal<Widget, void>; | ||
} | ||
/** | ||
* 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, | ||
} |
@@ -18,2 +18,5 @@ /*----------------------------------------------------------------------------- | ||
var phosphor_signaling_1 = require('phosphor-signaling'); | ||
var messages_1 = require('./messages'); | ||
var title_1 = require('./title'); | ||
// TODO - need better solution for storing these class names | ||
/** | ||
@@ -32,3 +35,3 @@ * The class name added to Widget instances. | ||
* This class will typically be subclassed in order to create a useful | ||
* widget. However, it can be used by itself to host externally created | ||
* widget. However, it can be used directly to host externally created | ||
* content. Simply instantiate an empty widget and add the DOM content | ||
@@ -45,2 +48,3 @@ * directly to the widget's `.node`. | ||
this._flags = 0; | ||
this._layout = null; | ||
this._parent = null; | ||
@@ -55,4 +59,3 @@ this.addClass(WIDGET_CLASS); | ||
* | ||
* If this method is called more than once, all calls made after | ||
* the first will be a no-op. | ||
* All calls made to this method after the first are a no-op. | ||
*/ | ||
@@ -65,7 +68,7 @@ Widget.prototype.dispose = function () { | ||
// Set the disposed flag and emit the disposed signal. | ||
this._flags |= 4 /* IsDisposed */; | ||
this.setFlag(WidgetFlag.IsDisposed); | ||
this.disposed.emit(void 0); | ||
// Remove or detach the widget if necessary. | ||
if (this.parent) { | ||
this.remove(); | ||
this.parent = null; | ||
} | ||
@@ -75,5 +78,8 @@ else if (this.isAttached) { | ||
} | ||
// Let a subclass dispose of its children. | ||
this.disposeChildren(); | ||
// Clear the extra data associated with the widget. | ||
// Dispose of the widget layout. | ||
if (this._layout) { | ||
this._layout.dispose(); | ||
this._layout = null; | ||
} | ||
// Clear the attached data associated with the widget. | ||
phosphor_signaling_1.clearSignalData(this); | ||
@@ -87,4 +93,3 @@ phosphor_messaging_1.clearMessageData(this); | ||
* | ||
* #### Notes | ||
* This is a pure delegate to the [[disposedSignal]]. | ||
* **See also:** [[dispose]], [[disposed]] | ||
*/ | ||
@@ -97,2 +102,17 @@ get: function () { | ||
}); | ||
Object.defineProperty(Widget.prototype, "isDisposed", { | ||
/** | ||
* Test whether the widget has been disposed. | ||
* | ||
* #### Notes | ||
* This is a read-only property. | ||
* | ||
* **See also:** [[dispose]], [[disposed]] | ||
*/ | ||
get: function () { | ||
return this.testFlag(WidgetFlag.IsDisposed); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Widget.prototype, "isAttached", { | ||
@@ -103,3 +123,3 @@ /** | ||
* #### Notes | ||
* This is a read-only property which is always safe to access. | ||
* This is a read-only property. | ||
* | ||
@@ -109,3 +129,3 @@ * **See also:** [[attach]], [[detach]] | ||
get: function () { | ||
return (this._flags & 1 /* IsAttached */) !== 0; | ||
return this.testFlag(WidgetFlag.IsAttached); | ||
}, | ||
@@ -115,13 +135,13 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(Widget.prototype, "isDisposed", { | ||
Object.defineProperty(Widget.prototype, "isHidden", { | ||
/** | ||
* Test whether the widget has been disposed. | ||
* Test whether the widget is explicitly hidden. | ||
* | ||
* #### Notes | ||
* This is a read-only property which is always safe to access. | ||
* This is a read-only property. | ||
* | ||
* **See also:** [[disposed]] | ||
* **See also:** [[isVisible]], [[hide]], [[show]] | ||
*/ | ||
get: function () { | ||
return (this._flags & 4 /* IsDisposed */) !== 0; | ||
return this.testFlag(WidgetFlag.IsHidden); | ||
}, | ||
@@ -139,8 +159,8 @@ enumerable: true, | ||
* | ||
* This is a read-only property which is always safe to access. | ||
* This is a read-only property. | ||
* | ||
* **See also:** [[hidden]] | ||
* **See also:** [[isHidden]], [[hide]], [[show]] | ||
*/ | ||
get: function () { | ||
return (this._flags & 2 /* IsVisible */) !== 0; | ||
return this.testFlag(WidgetFlag.IsVisible); | ||
}, | ||
@@ -150,24 +170,49 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(Widget.prototype, "hidden", { | ||
Object.defineProperty(Widget.prototype, "title", { | ||
/** | ||
* Get whether the widget is explicitly hidden. | ||
* Get the title data object for the widget. | ||
* | ||
* #### Notes | ||
* This is a pure delegate to the [[hiddenProperty]]. | ||
* The title data is used by some container widgets when displaying | ||
* the widget along with a title, such as a tab panel or dock panel. | ||
* | ||
* **See also:** [[isVisible]] | ||
* Not all widgets will make use of the title data, so it is created | ||
* on-demand the first time it is accessed. | ||
*/ | ||
get: function () { | ||
return Widget.hiddenProperty.get(this); | ||
return WidgetExtra.titleProperty.get(this); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Widget.prototype, "parent", { | ||
/** | ||
* Set whether the widget is explicitly hidden. | ||
* Get the parent of the widget. | ||
* | ||
* #### Notes | ||
* This is a pure delegate to the [[hiddenProperty]]. | ||
* This will be `null` if the widget does not have a parent. | ||
*/ | ||
get: function () { | ||
return this._parent; | ||
}, | ||
/** | ||
* Set the parent of the widget. | ||
* | ||
* **See also:** [[isVisible]] | ||
* #### Notes | ||
* The widget will be automatically removed from its current parent. | ||
* | ||
* This is a no-op if there is no effective parent change. | ||
*/ | ||
set: function (value) { | ||
Widget.hiddenProperty.set(this, value); | ||
value = value || null; | ||
if (this._parent === value) { | ||
return; | ||
} | ||
if (value && this.contains(value)) { | ||
throw new Error('Invalid parent widget.'); | ||
} | ||
if (this._parent && !this._parent.isDisposed) { | ||
phosphor_messaging_1.sendMessage(this._parent, new messages_1.ChildMessage('child-removed', this)); | ||
} | ||
this._parent = value; | ||
}, | ||
@@ -177,14 +222,37 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(Widget.prototype, "parent", { | ||
Object.defineProperty(Widget.prototype, "layout", { | ||
/** | ||
* Get the parent of the widget. | ||
* Get the layout for the widget. | ||
* | ||
* #### Notes | ||
* This will be `null` if the widget does not have a parent. | ||
* | ||
* This is a read-only property. | ||
* This will be `null` if the widget does not have a layout. | ||
*/ | ||
get: function () { | ||
return this._parent; | ||
return this._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. | ||
*/ | ||
set: function (value) { | ||
if (!value) { | ||
throw new Error('Cannot set widget layout to null.'); | ||
} | ||
if (this._layout === value) { | ||
return; | ||
} | ||
if (this._layout) { | ||
throw new Error('Cannot change widget layout.'); | ||
} | ||
if (value.parent) { | ||
throw new Error('Cannot change layout parent.'); | ||
} | ||
this._layout = value; | ||
value.parent = this; | ||
}, | ||
enumerable: true, | ||
@@ -194,14 +262,2 @@ configurable: true | ||
/** | ||
* Remove the widget from its current parent. | ||
* | ||
* #### Notes | ||
* This is a no-op if the widget does not have a parent. | ||
*/ | ||
Widget.prototype.remove = function () { | ||
var old = this._parent; | ||
this._parent = null; | ||
if (old && !old.isDisposed) | ||
old.removeChild(this); | ||
}; | ||
/** | ||
* Test whether a widget is a descendant of this widget. | ||
@@ -211,4 +267,3 @@ * | ||
* | ||
* @returns `true` if this widget is an ancestor of the given widget, | ||
* or `false` otherwise. | ||
* @returns `true` if the widget is a descendant, `false` otherwise. | ||
*/ | ||
@@ -227,5 +282,2 @@ Widget.prototype.contains = function (widget) { | ||
* | ||
* #### Notes | ||
* This is a convenience method for posting the message to `this`. | ||
* | ||
* **See also:** [[MsgUpdateRequest]], [[onUpdateRequest]] | ||
@@ -239,5 +291,2 @@ */ | ||
* | ||
* #### Notes | ||
* This is a convenience method for sending the message to `this`. | ||
* | ||
* **See also:** [[MsgCloseRequest]], [[onCloseRequest]] | ||
@@ -249,2 +298,40 @@ */ | ||
/** | ||
* Show the widget and make it visible to its parent widget. | ||
* | ||
* #### Notes | ||
* This causes the [[isHidden]] property to be `false`. | ||
*/ | ||
Widget.prototype.show = function () { | ||
if (!this.testFlag(WidgetFlag.IsHidden)) { | ||
return; | ||
} | ||
this.clearFlag(WidgetFlag.IsHidden); | ||
this.removeClass(HIDDEN_CLASS); | ||
if (this.isAttached && (!this.parent || this.parent.isVisible)) { | ||
phosphor_messaging_1.sendMessage(this, Widget.MsgAfterShow); | ||
} | ||
if (this.parent) { | ||
phosphor_messaging_1.sendMessage(this.parent, new messages_1.ChildMessage('child-shown', this)); | ||
} | ||
}; | ||
/** | ||
* Hide the widget and make it hidden to its parent widget. | ||
* | ||
* #### Notes | ||
* This causes the [[isHidden]] property to be `true`. | ||
*/ | ||
Widget.prototype.hide = function () { | ||
if (this.testFlag(WidgetFlag.IsHidden)) { | ||
return; | ||
} | ||
this.setFlag(WidgetFlag.IsHidden); | ||
if (this.isAttached && (!this.parent || this.parent.isVisible)) { | ||
phosphor_messaging_1.sendMessage(this, Widget.MsgBeforeHide); | ||
} | ||
this.addClass(HIDDEN_CLASS); | ||
if (this.parent) { | ||
phosphor_messaging_1.sendMessage(this.parent, new messages_1.ChildMessage('child-hidden', this)); | ||
} | ||
}; | ||
/** | ||
* Attach the widget to a host DOM node. | ||
@@ -254,20 +341,14 @@ * | ||
* | ||
* @throws Will throw an error if the widget is not a root widget, | ||
* if the widget is already attached to the DOM, or if the host | ||
* is not attached to the DOM. | ||
* | ||
* #### Notes | ||
* The function should be used in lieu of manual DOM attachment. It | ||
* ensures that an `'after-attach'` message is properly dispatched | ||
* to the widget hierarchy. | ||
* @throws 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. | ||
*/ | ||
Widget.prototype.attach = function (host) { | ||
if (this.parent) { | ||
throw new Error('Only a root widget can be attached to the DOM.'); | ||
throw new Error('Cannot attach child widget.'); | ||
} | ||
if (this.isAttached || document.body.contains(this.node)) { | ||
throw new Error('Widget is already attached to the DOM.'); | ||
throw new Error('Widget already attached.'); | ||
} | ||
if (!document.body.contains(host)) { | ||
throw new Error('Host is not attached to the DOM.'); | ||
throw new Error('Host not attached.'); | ||
} | ||
@@ -280,16 +361,11 @@ host.appendChild(this.node); | ||
* | ||
* @throws Will throw an error if the widget is not a root widget, | ||
* or if the widget is not attached to the DOM. | ||
* | ||
* #### Notes | ||
* The function should be used in lieu of manual DOM detachment. It | ||
* ensures that a `'before-detach'` message is properly dispatched | ||
* to the widget hierarchy. | ||
* @throws An error if the widget is not a root widget, or if the | ||
* widget is not attached. | ||
*/ | ||
Widget.prototype.detach = function () { | ||
if (this.parent) { | ||
throw new Error('Only a root widget can be detached from the DOM.'); | ||
throw new Error('Cannot detach child widget.'); | ||
} | ||
if (!this.isAttached || !document.body.contains(this.node)) { | ||
throw new Error('Widget is not attached to the DOM.'); | ||
throw new Error('Widget not attached.'); | ||
} | ||
@@ -300,2 +376,52 @@ phosphor_messaging_1.sendMessage(this, Widget.MsgBeforeDetach); | ||
/** | ||
* Test whether the given widget flag is set. | ||
* | ||
* #### Notes | ||
* This will not typically be consumed directly by user code. | ||
*/ | ||
Widget.prototype.testFlag = function (flag) { | ||
return (this._flags & flag) !== 0; | ||
}; | ||
/** | ||
* Set the given widget flag. | ||
* | ||
* #### Notes | ||
* This will not typically be consumed directly by user code. | ||
*/ | ||
Widget.prototype.setFlag = function (flag) { | ||
this._flags |= flag; | ||
}; | ||
/** | ||
* Clear the given widget flag. | ||
* | ||
* #### Notes | ||
* This will not typically be consumed directly by user code. | ||
*/ | ||
Widget.prototype.clearFlag = function (flag) { | ||
this._flags &= ~flag; | ||
}; | ||
/** | ||
* Compress a message posted to the widget. | ||
* | ||
* @param msg - The message posted to the widget. | ||
* | ||
* @param pending - The queue of pending messages for the widget. | ||
* | ||
* @returns `true` if the message was compressed and should be | ||
* dropped, or `false` if the message should be enqueued for | ||
* delivery as normal. | ||
* | ||
* #### Notes | ||
* The default implementation compresses `'update-request'` and | ||
* `'layout-request'` messages. | ||
* | ||
* Subclasses may reimplement this method as needed. | ||
*/ | ||
Widget.prototype.compressMessage = function (msg, pending) { | ||
if (msg.type === 'update-request' || msg.type === 'layout-request') { | ||
return pending.some(function (other) { return other.type === msg.type; }); | ||
} | ||
return false; | ||
}; | ||
/** | ||
* Process a message sent to the widget. | ||
@@ -311,126 +437,62 @@ * | ||
case 'resize': | ||
this.notifyLayout(msg); | ||
this.onResize(msg); | ||
break; | ||
case 'update-request': | ||
this.notifyLayout(msg); | ||
this.onUpdateRequest(msg); | ||
break; | ||
case 'layout-request': | ||
this.onLayoutRequest(msg); | ||
break; | ||
case 'after-show': | ||
this._flags |= 2 /* IsVisible */; | ||
this.setFlag(WidgetFlag.IsVisible); | ||
this.notifyLayout(msg); | ||
this.onAfterShow(msg); | ||
break; | ||
case 'before-hide': | ||
this.notifyLayout(msg); | ||
this.onBeforeHide(msg); | ||
this._flags &= ~2 /* IsVisible */; | ||
this.clearFlag(WidgetFlag.IsVisible); | ||
break; | ||
case 'after-attach': | ||
var visible = !this.hidden && (!this.parent || this.parent.isVisible); | ||
var visible = !this.isHidden && (!this.parent || this.parent.isVisible); | ||
if (visible) | ||
this._flags |= 2 /* IsVisible */; | ||
this._flags |= 1 /* IsAttached */; | ||
this.setFlag(WidgetFlag.IsVisible); | ||
this.setFlag(WidgetFlag.IsAttached); | ||
this.notifyLayout(msg); | ||
this.onAfterAttach(msg); | ||
break; | ||
case 'before-detach': | ||
this.notifyLayout(msg); | ||
this.onBeforeDetach(msg); | ||
this._flags &= ~2 /* IsVisible */; | ||
this._flags &= ~1 /* IsAttached */; | ||
this.clearFlag(WidgetFlag.IsVisible); | ||
this.clearFlag(WidgetFlag.IsAttached); | ||
break; | ||
case 'child-shown': | ||
this.onChildShown(msg); | ||
break; | ||
case 'child-hidden': | ||
this.onChildHidden(msg); | ||
break; | ||
case 'close-request': | ||
this.notifyLayout(msg); | ||
this.onCloseRequest(msg); | ||
break; | ||
default: | ||
this.notifyLayout(msg); | ||
break; | ||
} | ||
}; | ||
/** | ||
* Compress a message posted to the widget. | ||
* Invoke the message processing routine of the widget's layout. | ||
* | ||
* @param msg - The message posted to the widget. | ||
* @param msg - The message to dispatch to the layout. | ||
* | ||
* @param pending - The queue of pending messages for the widget. | ||
* | ||
* @returns `true` if the message was compressed and should be | ||
* dropped, or `false` if the message should be enqueued for | ||
* delivery as normal. | ||
* | ||
* #### Notes | ||
* The default implementation compresses `'update-request'`. | ||
* This is a no-op if the widget does not have a layout. | ||
* | ||
* Subclasses may reimplement this method as needed. | ||
*/ | ||
Widget.prototype.compressMessage = function (msg, pending) { | ||
if (msg.type === 'update-request') { | ||
return pending.some(function (other) { return other.type === 'update-request'; }); | ||
} | ||
if (msg.type === 'layout-request') { | ||
return pending.some(function (other) { return other.type === 'layout-request'; }); | ||
} | ||
return false; | ||
Widget.prototype.notifyLayout = function (msg) { | ||
if (this._layout) | ||
this._layout.processParentMessage(msg); | ||
}; | ||
/** | ||
* Adopt the specified child and set its parent to this widget. | ||
* | ||
* @param child - The child widget to adopt. | ||
* | ||
* #### Notes | ||
* This should be called by subclasses which support children in | ||
* order to update the parent reference when a child is added. | ||
* | ||
* This will set the parent reference to the specified child after | ||
* removing the child from its current parent. | ||
*/ | ||
Widget.prototype.adoptChild = function (child) { | ||
if (child.contains(this)) { | ||
throw new Error('Invalid child widget.'); | ||
} | ||
if (child._parent && child._parent !== this) { | ||
child.remove(); | ||
} | ||
child._parent = this; | ||
}; | ||
/** | ||
* Remove the specified child from the widget. | ||
* | ||
* #### Notes | ||
* This method **must** be reimplemented by subclasses which support | ||
* children, or undefined behavior will result. | ||
* | ||
* This method is called automatically as needed. It should not be | ||
* invoked directly by user code. | ||
* | ||
* The default implementation of this method is a no-op. | ||
*/ | ||
Widget.prototype.removeChild = function (child) { }; | ||
/** | ||
* Dispose the children of the widget. | ||
* | ||
* #### Notes | ||
* This method **must** be reimplemented by subclasses which support | ||
* children, or undefined behavior will result. | ||
* | ||
* This is called by the `dispose` method at the point where child | ||
* widgets should be disposed. A subclass should call the `dispose` | ||
* method of each child and then clear the reference to the child. | ||
* | ||
* This method is called automatically as needed. It should not be | ||
* invoked directly by user code. | ||
* | ||
* The default implementation of this method is a no-op. | ||
*/ | ||
Widget.prototype.disposeChildren = function () { }; | ||
/** | ||
* A message handler invoked on a `'close-request'` message. | ||
* | ||
* #### Notes | ||
* The default implementation of this handler will remove or detach | ||
* the widget as appropriate. | ||
* The default implementation of this handler detaches the widget. | ||
* | ||
* Subclasses may reimplement this handler for custom close behavior. | ||
* | ||
* **See also:** [[close]], [[MsgCloseRequest]] | ||
@@ -440,3 +502,3 @@ */ | ||
if (this.parent) { | ||
this.remove(); | ||
this.parent = null; | ||
} | ||
@@ -451,2 +513,4 @@ else if (this.isAttached) { | ||
* The default implementation of this handler is a no-op. | ||
* | ||
* **See also:** [[ResizeMessage]] | ||
*/ | ||
@@ -463,10 +527,2 @@ Widget.prototype.onResize = function (msg) { }; | ||
/** | ||
* A message handler invoked on a `'layout-request'` message. | ||
* | ||
* The default implementation of this handler is a no-op. | ||
* | ||
* **See also:** [[MsgLayoutRequest]] | ||
*/ | ||
Widget.prototype.onLayoutRequest = function (msg) { }; | ||
/** | ||
* A message handler invoked on an `'after-show'` message. | ||
@@ -503,15 +559,11 @@ * | ||
Widget.prototype.onBeforeDetach = function (msg) { }; | ||
return Widget; | ||
})(phosphor_nodewrapper_1.NodeWrapper); | ||
exports.Widget = Widget; | ||
/** | ||
* The namespace for the `Widget` class statics. | ||
*/ | ||
var Widget; | ||
(function (Widget) { | ||
/** | ||
* A message handler invoked on a `'child-shown'` message. | ||
* | ||
* The default implementation of this handler is a no-op. | ||
*/ | ||
Widget.prototype.onChildShown = function (msg) { }; | ||
/** | ||
* A message handler invoked on a `'child-hidden'` message. | ||
* | ||
* The default implementation of this handler is a no-op. | ||
*/ | ||
Widget.prototype.onChildHidden = function (msg) { }; | ||
/** | ||
* A singleton `'update-request'` message. | ||
@@ -524,5 +576,4 @@ * | ||
* | ||
* This message is typically used to update the position and size of | ||
* a widget's children, or to update a widget's content to reflect | ||
* the current widget state. | ||
* This message is typically used to update the widget's content to | ||
* reflect the current widget state. | ||
* | ||
@@ -588,3 +639,3 @@ * Messages of this type are compressed by default. | ||
* #### Notes | ||
* This message is sent to a widget after it is attached to the DOM. | ||
* This message is sent to a widget after it is attached. | ||
* | ||
@@ -598,3 +649,3 @@ * **See also:** [[isAttached]], [[onAfterAttach]] | ||
* #### Notes | ||
* This message is sent to a widget before it is detached from the DOM. | ||
* This message is sent to a widget before it is detached. | ||
* | ||
@@ -610,138 +661,38 @@ * **See also:** [[isAttached]], [[onBeforeDetach]] | ||
Widget.disposedSignal = new phosphor_signaling_1.Signal(); | ||
/** | ||
* A property descriptor which controls the hidden state of a widget. | ||
* | ||
* #### Notes | ||
* This controls whether a widget is explicitly hidden. | ||
* | ||
* Hiding a widget will cause the widget and all of its descendants | ||
* to become not-visible. | ||
* | ||
* This will toggle the presence of `'p-mod-hidden'` on a widget. It | ||
* will also dispatch `'after-show'` and `'before-hide'` messages as | ||
* appropriate. | ||
* | ||
* The default value is `false`. | ||
* | ||
* **See also:** [[hidden]], [[isVisible]] | ||
*/ | ||
Widget.hiddenProperty = new phosphor_properties_1.Property({ | ||
name: 'hidden', | ||
value: false, | ||
changed: onHiddenChanged, | ||
}); | ||
return Widget; | ||
})(phosphor_nodewrapper_1.NodeWrapper); | ||
exports.Widget = Widget; | ||
})(Widget = exports.Widget || (exports.Widget = {})); | ||
/** | ||
* A message class for child related messages. | ||
* An enum of widget bit flags. | ||
*/ | ||
var ChildMessage = (function (_super) { | ||
__extends(ChildMessage, _super); | ||
(function (WidgetFlag) { | ||
/** | ||
* Construct a new child message. | ||
* | ||
* @param type - The message type. | ||
* | ||
* @param child - The child widget for the message. | ||
* The widget has been disposed. | ||
*/ | ||
function ChildMessage(type, child) { | ||
_super.call(this, type); | ||
this._child = child; | ||
} | ||
Object.defineProperty(ChildMessage.prototype, "child", { | ||
/** | ||
* The child widget for the message. | ||
* | ||
* #### Notes | ||
* This is a read-only property. | ||
*/ | ||
get: function () { | ||
return this._child; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return ChildMessage; | ||
})(phosphor_messaging_1.Message); | ||
exports.ChildMessage = ChildMessage; | ||
/** | ||
* A message class for `'resize'` messages. | ||
*/ | ||
var ResizeMessage = (function (_super) { | ||
__extends(ResizeMessage, _super); | ||
WidgetFlag[WidgetFlag["IsDisposed"] = 1] = "IsDisposed"; | ||
/** | ||
* 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. | ||
* The widget is attached to the DOM. | ||
*/ | ||
function ResizeMessage(width, height) { | ||
_super.call(this, 'resize'); | ||
this._width = width; | ||
this._height = height; | ||
} | ||
Object.defineProperty(ResizeMessage.prototype, "width", { | ||
/** | ||
* The offset width of the widget. | ||
* | ||
* #### Notes | ||
* This will be `-1` if the width is unknown. | ||
* | ||
* This is a read-only property. | ||
*/ | ||
get: function () { | ||
return this._width; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ResizeMessage.prototype, "height", { | ||
/** | ||
* The offset height of the widget. | ||
* | ||
* #### Notes | ||
* This will be `-1` if the height is unknown. | ||
* | ||
* This is a read-only property. | ||
*/ | ||
get: function () { | ||
return this._height; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
WidgetFlag[WidgetFlag["IsAttached"] = 2] = "IsAttached"; | ||
/** | ||
* A singleton `'resize'` message with an unknown size. | ||
* The widget is hidden. | ||
*/ | ||
ResizeMessage.UnknownSize = new ResizeMessage(-1, -1); | ||
return ResizeMessage; | ||
})(phosphor_messaging_1.Message); | ||
exports.ResizeMessage = ResizeMessage; | ||
WidgetFlag[WidgetFlag["IsHidden"] = 4] = "IsHidden"; | ||
/** | ||
* The widget is visible. | ||
*/ | ||
WidgetFlag[WidgetFlag["IsVisible"] = 8] = "IsVisible"; | ||
})(exports.WidgetFlag || (exports.WidgetFlag = {})); | ||
var WidgetFlag = exports.WidgetFlag; | ||
/** | ||
* The change handler for the [[hiddenProperty]]. | ||
* The namespace for the widget extras. | ||
*/ | ||
function onHiddenChanged(owner, old, hidden) { | ||
if (hidden) { | ||
if (owner.isAttached && (!owner.parent || owner.parent.isVisible)) { | ||
phosphor_messaging_1.sendMessage(owner, Widget.MsgBeforeHide); | ||
} | ||
owner.addClass(HIDDEN_CLASS); | ||
if (owner.parent) { | ||
phosphor_messaging_1.sendMessage(owner.parent, new ChildMessage('child-hidden', owner)); | ||
} | ||
} | ||
else { | ||
owner.removeClass(HIDDEN_CLASS); | ||
if (owner.isAttached && (!owner.parent || owner.parent.isVisible)) { | ||
phosphor_messaging_1.sendMessage(owner, Widget.MsgAfterShow); | ||
} | ||
if (owner.parent) { | ||
phosphor_messaging_1.sendMessage(owner.parent, new ChildMessage('child-shown', owner)); | ||
} | ||
} | ||
} | ||
var WidgetExtra; | ||
(function (WidgetExtra) { | ||
/** | ||
* A property for the title data for a widget. | ||
*/ | ||
WidgetExtra.titleProperty = new phosphor_properties_1.Property({ | ||
name: 'title', | ||
create: function () { return new title_1.Title(); }, | ||
}); | ||
})(WidgetExtra || (WidgetExtra = {})); | ||
//# sourceMappingURL=widget.js.map |
{ | ||
"name": "phosphor-widget", | ||
"version": "1.0.0-beta.2", | ||
"version": "1.0.0-beta.3", | ||
"description": "The core Phosphor widget class.", | ||
@@ -8,9 +8,9 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"phosphor-arrays": "^1.0.5", | ||
"phosphor-disposable": "^1.0.4", | ||
"phosphor-messaging": "^1.0.5", | ||
"phosphor-arrays": "^1.0.6", | ||
"phosphor-disposable": "^1.0.5", | ||
"phosphor-messaging": "^1.0.6", | ||
"phosphor-nodewrapper": "^1.0.4", | ||
"phosphor-properties": "^2.0.0", | ||
"phosphor-queue": "^1.0.4", | ||
"phosphor-signaling": "^1.1.2" | ||
"phosphor-queue": "^1.0.5", | ||
"phosphor-signaling": "^1.2.0" | ||
}, | ||
@@ -66,2 +66,4 @@ "devDependencies": { | ||
"keywords": [ | ||
"layout", | ||
"panel", | ||
"ui", | ||
@@ -68,0 +70,0 @@ "widget" |
@@ -15,3 +15,3 @@ phosphor-widget | ||
establishes a live parent-child relationship. While this may seem trivial, | ||
it allows for the implementation of advanced message passing and notifcation | ||
it allows for the implementation of advanced message passing and notification | ||
behaviors, and provides a sane pattern for component reuse. | ||
@@ -196,7 +196,7 @@ | ||
The `Widget` class forms the foundation for building complex and custom | ||
widgets, while the `AbstractPanel` and `Panel` subclasses make it simple to | ||
create container widgets which cover a vast swath of use cases. The amount of | ||
flexibility offered by these base classes means the user can create nearly any | ||
application using content generated by nearly any framework. The PhosphorJS | ||
project provides several useful widgets and layout panels out of the box. | ||
widgets; while the `Layout`, `AbstractPanel` and `Panel` classes make it | ||
simple to create container widgets which cover a vast swath of use cases. The | ||
amount of flexibility offered by these base classes means the user can create | ||
nearly any application using content generated by nearly any framework. The | ||
PhosphorJS project provides several useful widgets and panels out of the box. | ||
Some of the more commonly used are: | ||
@@ -203,0 +203,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
93935
16
2564
Updatedphosphor-arrays@^1.0.6
Updatedphosphor-disposable@^1.0.5
Updatedphosphor-messaging@^1.0.6
Updatedphosphor-queue@^1.0.5
Updatedphosphor-signaling@^1.2.0