Skip to main content
Version: 4.1

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>);
info

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;
info

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 least opt.type is required in order to identify which Widget type (among those specified in the widgets namespace) is to be created. If opt is a string, then it is understood to mean opt.type. The opt.type is converted to camelCase before this check; if no key in the widgets namespace matches the converted string, then the error Widget: 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 by opt.type. The keys of the refs objects are checked against the Widget type definition's references array, and if any of those is missing, then the error Widget: "${type}" missing dependency: ${invalidRefs.join(', ')} is thrown,
  • [optional] widgets is an object containing Widget type definitions, where the keys are understood as the type identifiers, and the values are the corresponding Widget type definitions.

Properties​

references​

references: Array<string>;
info

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.