@fabwcie/free-drawing / plugins/Plugin
plugins/Plugin
Classes
abstract Plugin
Defined in: packages/free-drawing/src/plugins/Plugin.ts:24
Base of plugins: features added to a drawer by other developers (plugins drawer option). A plugin class has a static pluginName and may requires other plugins, created and initialized before it. Lifecycle:
- constructor: created with the drawer, before its toolbar:
addWidget,addTranslations(interface not created); init: drawer created (toolbar, menus...):addCommand,listenTo... a promise is waited before the next plugin (drawer.readywaits for every plugin);afterInit: every plugin initialized (links between plugins);destroy: listeners oflistenToremoved (drawer.plugins.destroy()).
Constructors
Constructor
new Plugin(
drawer):Plugin
Defined in: packages/free-drawing/src/plugins/Plugin.ts:45
Plugin of a drawer, created before its toolbar: add widgets and translations here, the rest in init
Parameters
drawer
Drawer of the plugin
Returns
Properties
drawer
readonlydrawer:Drawer
Defined in: packages/free-drawing/src/plugins/Plugin.ts:31
Drawer of the plugin
pluginName
readonlystaticpluginName:string=''
Defined in: packages/free-drawing/src/plugins/Plugin.ts:26
Unique name of the plugin (class names are changed by minification), required
requires
readonlystaticrequires: readonlyPluginRequirement[] =[]
Defined in: packages/free-drawing/src/plugins/Plugin.ts:28
Plugins required by this one: classes (added when missing) or names of plugins given to the drawer
Accessors
isEnabled
Get Signature
get isEnabled():
boolean
Defined in: packages/free-drawing/src/plugins/Plugin.ts:84
Plugin can modify the drawing: not in read only, nor disabled by forceDisabled
Returns
boolean
true while its widgets and commands modifying the drawing are available
isForceDisabled
Get Signature
get isForceDisabled():
boolean
Defined in: packages/free-drawing/src/plugins/Plugin.ts:92
Plugin disabled by forceDisabled, whatever read only
Returns
boolean
true while a reason disables it
name
Get Signature
get name():
string
Defined in: packages/free-drawing/src/plugins/Plugin.ts:55
Name of the plugin
Returns
string
static pluginName of its class
Methods
_changed()
private_changed():void
Defined in: packages/free-drawing/src/plugins/Plugin.ts:202
Enabled state changed: widgets of the plugin disabled or enabled, plugin.change triggered
Returns
void
_updateWidgets()
_updateWidgets():
void
Defined in: packages/free-drawing/src/plugins/Plugin.ts:210
Widgets of the plugin disabled while it is disabled (or in read only), also by the drawer when read only ends
Returns
void
addCommand()
addCommand(
command):void
Defined in: packages/free-drawing/src/plugins/Plugin.ts:177
Action of the plugin: command of the palette, shortcut (shown in help), item of the context menu. Call it in init: the context menu and help get the commands of plugins once they are initialized
Parameters
command
Id, label, shortcut, menu, availability and action of the command
Returns
void
addShapeType()
addShapeType(
type):void
Defined in: packages/free-drawing/src/plugins/Plugin.ts:168
Type of the shapes of the plugin: shapes having its name get its label (layers panel, screen readers) and its icon (layers panel), in the language of the drawer (a label attribute would be the name given by the user, in one language). Call it in the constructor. Shapes of plugins are shapes of the library (rectangles, groups, path shapes of PathShapeWidget...) with a name of the plugin: a drawer without the plugin shows them, with the name of the shape of the library
Parameters
type
Name of the shapes, label and icon
Returns
void
addTranslations()
addTranslations(
translations):void
Defined in: packages/free-drawing/src/plugins/Plugin.ts:144
Texts of the plugin, by language (its own keys; tools.<widget id> for the title of a widget). Add them in the constructor: titles of widgets are translated when the toolbar is created. The translations drawer option can replace them
Parameters
translations
Texts by language, English used for missing ones
Returns
void
addWidget()
addWidget(
id,widget):void
Defined in: packages/free-drawing/src/plugins/Plugin.ts:155
Widget added to the toolbar, at its place in the widgets and widgetGroups drawer options, else at the end. Call it in the constructor (the toolbar is created after plugins). Its title is the text of tools.<id>, its shortcut the one given to its class (a letter, also in help and command palette)
Parameters
id
string
Id of the widget, given to the constructor of BaseWidget by its class: unique
widget
Class of the widget (extends BaseWidget, ShapeWidget...), created by the toolbar
Returns
void
afterInit()
afterInit():
void|Promise<void>
Defined in: packages/free-drawing/src/plugins/Plugin.ts:69
Last step of the plugin, every plugin initialized. Nothing by default
Returns
void | Promise<void>
nothing, or a promise waited by drawer.ready
clearForceDisabled()
clearForceDisabled(
id):void
Defined in: packages/free-drawing/src/plugins/Plugin.ts:112
Remove a reason given to forceDisabled: enabled again once no reason is left
Parameters
id
string
Reason given to forceDisabled
Returns
void
destroy()
destroy():
void|Promise<void>
Defined in: packages/free-drawing/src/plugins/Plugin.ts:75
Remove listeners of listenTo (call it when overriding destroy)
Returns
void | Promise<void>
nothing, or a promise when overridden
forceDisabled()
forceDisabled(
id):void
Defined in: packages/free-drawing/src/plugins/Plugin.ts:101
Disable the plugin (its widgets, its commands modifying the drawing) for a reason, until clearForceDisabled with the same id. Several reasons disable it until all of them are cleared
Parameters
id
string
Reason disabling it (name of a feature...)
Returns
void
getOptions()
getOptions<
T>(defaults):T
Defined in: packages/free-drawing/src/plugins/Plugin.ts:124
Options of the plugin: defaults of the plugin replaced by the ones the app gives with its class in the plugins drawer option (plugins: [[StampsPlugin, { max: 20 }]])
Type Parameters
T
T extends object
options of the plugin
Parameters
defaults
T
Default value of every option
Returns
T
defaults with the options of the app (merged one level deep)
init()
init():
void|Promise<void>
Defined in: packages/free-drawing/src/plugins/Plugin.ts:63
Second step of the plugin, drawer created (toolbar, menus...): commands, listeners. Nothing by default
Returns
void | Promise<void>
nothing, or a promise waited before the next plugin and by drawer.ready
listenTo()
listenTo(
target,event,handler):void
Defined in: packages/free-drawing/src/plugins/Plugin.ts:188
Listen an event until the plugin is destroyed (nothing once destroyed: init still running): of the drawer (drawerEvents), of a konva node (stage, layers, shapes...) or of a DOM element
Parameters
target
Drawer, konva node or DOM element
event
string
Name of the event (several ones separated by spaces for the drawer and konva nodes)
handler
(...args) => unknown
Function called with the arguments of the event
Returns
void
t()
t(
key,params?):string
Defined in: packages/free-drawing/src/plugins/Plugin.ts:134
Text of a key in the language of the drawer: texts of the plugin (addTranslations), of the app or of the library
Parameters
key
string
Key of the text (e.g. stamps.insert)
params?
Values of {name} placeholders
Returns
string
text in current language, in English when missing, else the key