Widget
The plugin implements a generic tool definition for the Toolbar component, which allows the user to interact with a JointJS diagram.
To learn more about the plugin, check out the Widgets section.
constructorβ
constructor(opt: mvc.ViewOptions<undefined>, refs?: Array<any>);
The Widget constructor is not intended to be used directly. It is used internally by the create()
static method.
Methodsβ
enable()β
enable(): void;
Enable the Widget. Example usage:
toolbar.getWidgetByName('undo').enable();
disable()β
disable(): void;
Disable the widget (make the Widget not to respond to user actions). Example usage:
toolbar.getWidgetByName('undo').disable();
isDisabled()β
isDisabled(): boolean;
Return true
if the Widget is currently disabled. Return false
otherwise. Example usage:
const canUndo = !toolbar.getWidgetByName('undo').isDisabled();
Static methodsβ
create()β
static create<T extends Widget>(
opt: { [key: string]: any } | string,
refs?: Array<any>,
widgets?: { [name: string]: Widget }
): T;
The create()
method is not intended to be used directly. It is used internally by the Toolbar constructor to create Widget instances. See the Widgets section for more information.
Return an instance of a Widget type taken from the widgets
namespace.
- [required]
opt
is an object containing properties to be set on the created Widget instance. At leastopt.type
is required in order to identify which Widget type (among those specified in thewidgets
namespace) is to be created. Ifopt
is a string, then it is understood to meanopt.type
. Theopt.type
is converted to camelCase before this check; if no key in thewidgets
namespace matches the converted string, then the errorWidget: unable to find widget: "${type}"
is thrown, - [optional]
refs
is an Array of Toolbar references required in order to create an instance of the Widget type identified byopt.type
. The keys of therefs
objects are checked against the Widget type definition'sreferences
array, and if any of those is missing, then the errorWidget: "${type}" missing dependency: ${invalidRefs.join(', ')}
is thrown, - [optional]
widgets
is an object containing Widget type definitions, where the keys are understood as thetype
identifiers, and the values are the corresponding Widget type definitions.
Propertiesβ
referencesβ
references: Array<string>;
The references
property is not intended to be accessed directly. It is used internally by the create()
static method.
An array of reference keys that the Widget type requires in order to work as expected. If a Widget type does not require any references, then its references
are an empty array ([]
).
For example, if a Widget type requires a reference to PaperScroller, its references
array contains the string 'paperScroller'
as an item, and if a Widget type requires a reference to CommandManager, its references
array contains the string 'commandManager'
as an item.
Eventsβ
Different Widget types trigger different events (if any), and the Toolbar may be used as a proxy for listening to events triggered by individual Widget instances. See the Toolbar events section for details.