PluginCollection (core)
@ckeditor/ckeditor5-core/src/plugincollection
Manages a list of CKEditor plugins, including loading, resolving dependencies and initialization.
Filtering
Properties
-
_availablePlugins : Map.<(String|Function), function()>
module:core/plugincollection~PluginCollection#_availablePlugins
protected
A map of plugin constructors that can be retrieved by their names.
-
-
_contextPlugins : Map.<Function, function()>
module:core/plugincollection~PluginCollection#_contextPlugins
protected
Map of context plugins which can be retrieved by their constructors or instances.
-
_plugins : Map
module:core/plugincollection~PluginCollection#_plugins
protected
Methods
-
constructor( context, [ availablePlugins ], contextPlugins )
module:core/plugincollection~PluginCollection#constructor
Creates an instance of the plugin collection class. Allows loading and initializing plugins and their dependencies. Allows providing a list of already loaded plugins. These plugins will not be destroyed along with this collection.
Parameters
context : Editor | Context
[ availablePlugins ] : Array.<Function>
Plugins (constructors) which the collection will be able to use when
init
is used with the plugin names (strings, instead of constructors). Usually, the editor will pass its built-in plugins to the collection so they can later be used inconfig.plugins
orconfig.removePlugins
by names.contextPlugins : Iterable.<Array>
A list of already initialized plugins represented by a
[ PluginConstructor, pluginInstance ]
pair.
-
Symbol.iterator() → Iterable.<Array>
module:core/plugincollection~PluginCollection#Symbol.iterator
Iterable interface.
Returns
[ PluginConstructor, pluginInstance ]
pairs.Returns
Iterable.<Array>
-
delegate( events ) → EmitterMixinDelegateChain
module:core/plugincollection~PluginCollection#delegate
mixed
Delegates selected events to another
Emitter
. For instance:emitterA.delegate( 'eventX' ).to( emitterB ); emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );
then
eventX
is delegated (fired by)emitterB
andemitterC
along withdata
:emitterA.fire( 'eventX', data );
and
eventY
is delegated (fired by)emitterC
along withdata
:emitterA.fire( 'eventY', data );
Parameters
events : String
Event names that will be delegated to another emitter.
Returns
-
destroy() → Promise
module:core/plugincollection~PluginCollection#destroy
Destroys all loaded plugins.
Returns
Promise
-
fire( eventOrInfo, [ args ] ) → *
module:core/plugincollection~PluginCollection#fire
mixed
Fires an event, executing all callbacks registered for it.
The first parameter passed to callbacks is an
EventInfo
object, followed by the optionalargs
provided in thefire()
method call.Parameters
eventOrInfo : String | EventInfo
The name of the event or
EventInfo
object if event is delegated.[ args ] : *
Additional arguments to be passed to the callbacks.
Returns
*
By default the method returns
undefined
. However, the return value can be changed by listeners through modification of theevt.return
's property (the event info is the first param of every callback).
-
get( key ) → PluginInterface
module:core/plugincollection~PluginCollection#get
Gets the plugin instance by its constructor or name.
// Check if 'Clipboard' plugin was loaded. if ( editor.plugins.has( 'ClipboardPipeline' ) ) { // Get clipboard plugin instance const clipboard = editor.plugins.get( 'ClipboardPipeline' ); this.listenTo( clipboard, 'inputTransformation', ( evt, data ) => { // Do something on clipboard input. } ); }
Note: This method will throw an error if a plugin is not loaded. Use
editor.plugins.has()
to check if a plugin is available.Parameters
key : function | String
The plugin constructor or name.
Returns
-
has( key ) → Boolean
module:core/plugincollection~PluginCollection#has
Checks if a plugin is loaded.
// Check if the 'Clipboard' plugin was loaded. if ( editor.plugins.has( 'ClipboardPipeline' ) ) { // Now use the clipboard plugin instance: const clipboard = editor.plugins.get( 'ClipboardPipeline' ); // ... }
Parameters
key : function | String
The plugin constructor or name.
Returns
Boolean
-
init( plugins, [ pluginsToRemove ], [ pluginsSubstitutions ] ) → Promise.<LoadedPlugins>
module:core/plugincollection~PluginCollection#init
Initializes a set of plugins and adds them to the collection.
Parameters
plugins : Array.<(Function | String)>
An array of plugin constructors or plugin names.
[ pluginsToRemove ] : Array.<(String | Function)>
Names of the plugins or plugin constructors that should not be loaded (despite being specified in the
plugins
array).[ pluginsSubstitutions ] : Array.<Function>
An array of plugin constructors that will be used to replace plugins of the same names that were passed in
plugins
or that are in their dependency tree. A useful option for replacing built-in plugins while creating tests (for mocking their APIs). Plugins that will be replaced must follow these rules:- The new plugin must be a class.
- The new plugin must be named.
- Both plugins must not depend on other plugins.
Returns
Promise.<LoadedPlugins>
A promise which gets resolved once all plugins are loaded and available in the collection.
-
listenTo( emitter, event, callback, [ options ] = { [options.priority] } )
module:core/plugincollection~PluginCollection#listenTo
mixed
Registers a callback function to be executed when an event is fired in a specific (emitter) object.
Events can be grouped in namespaces using
:
. When namespaced event is fired, it additionally fires all callbacks for that namespace.// myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ). myEmitter.on( 'myGroup', genericCallback ); myEmitter.on( 'myGroup:myEvent', specificCallback ); // genericCallback is fired. myEmitter.fire( 'myGroup' ); // both genericCallback and specificCallback are fired. myEmitter.fire( 'myGroup:myEvent' ); // genericCallback is fired even though there are no callbacks for "foo". myEmitter.fire( 'myGroup:foo' );
An event callback can stop the event and set the return value of the
fire
method.Parameters
emitter : Emitter
The object that fires the event.
event : String
The name of the event.
callback : function
The function to be called on event.
[ options ] : Object
Additional options.
Properties[ options.priority ] : PriorityString | Number
The priority of this event callback. The higher the priority value the sooner the callback will be fired. Events having the same priority are called in the order they were added.
Defaults to
'normal'
Defaults to
{}
-
off( event, callback )
module:core/plugincollection~PluginCollection#off
mixed
Stops executing the callback on the given event. Shorthand for
this.stopListening( this, event, callback )
.Parameters
event : String
The name of the event.
callback : function
The function to stop being called.
-
on( event, callback, [ options ] = { [options.priority] } )
module:core/plugincollection~PluginCollection#on
mixed
Registers a callback function to be executed when an event is fired.
Shorthand for
this.listenTo( this, event, callback, options )
(it makes the emitter listen on itself).Parameters
event : String
The name of the event.
callback : function
The function to be called on event.
[ options ] : Object
Additional options.
Properties[ options.priority ] : PriorityString | Number
The priority of this event callback. The higher the priority value the sooner the callback will be fired. Events having the same priority are called in the order they were added.
Defaults to
'normal'
Defaults to
{}
-
once( event, callback, [ options ] = { [options.priority] } )
module:core/plugincollection~PluginCollection#once
mixed
Registers a callback function to be executed on the next time the event is fired only. This is similar to calling
on
followed byoff
in the callback.Parameters
event : String
The name of the event.
callback : function
The function to be called on event.
[ options ] : Object
Additional options.
Properties[ options.priority ] : PriorityString | Number
The priority of this event callback. The higher the priority value the sooner the callback will be fired. Events having the same priority are called in the order they were added.
Defaults to
'normal'
Defaults to
{}
-
stopDelegating( [ event ], [ emitter ] )
module:core/plugincollection~PluginCollection#stopDelegating
mixed
Stops delegating events. It can be used at different levels:
- To stop delegating all events.
- To stop delegating a specific event to all emitters.
- To stop delegating a specific event to a specific emitter.
Parameters
[ event ] : String
The name of the event to stop delegating. If omitted, stops it all delegations.
[ emitter ] : Emitter
(requires
event
) The object to stop delegating a particular event to. If omitted, stops delegation ofevent
to all emitters.
-
stopListening( [ emitter ], [ event ], [ callback ] )
module:core/plugincollection~PluginCollection#stopListening
mixed
Stops listening for events. It can be used at different levels:
- To stop listening to a specific callback.
- To stop listening to a specific event.
- To stop listening to all events fired by a specific object.
- To stop listening to all events fired by all objects.
Parameters
[ emitter ] : Emitter
The object to stop listening to. If omitted, stops it for all objects.
[ event ] : String
(Requires the
emitter
) The name of the event to stop listening to. If omitted, stops it for all events fromemitter
.[ callback ] : function
(Requires the
event
) The function to be removed from the call list for the givenevent
.
-
_add( PluginConstructor, plugin )
module:core/plugincollection~PluginCollection#_add
protected
Adds the plugin to the collection. Exposed mainly for testing purposes.
Parameters
PluginConstructor : function
The plugin constructor.
plugin : PluginInterface
The instance of the plugin.
-
_addEventListener( event, callback, [ options ] = { [options.priority] } )
module:core/plugincollection~PluginCollection#_addEventListener
protected mixed
Adds callback to emitter for given event.
Parameters
event : String
The name of the event.
callback : function
The function to be called on event.
[ options ] : Object
Additional options.
Properties[ options.priority ] : PriorityString | Number
The priority of this event callback. The higher the priority value the sooner the callback will be fired. Events having the same priority are called in the order they were added.
Defaults to
'normal'
Defaults to
{}
-
_removeEventListener( event, callback )
module:core/plugincollection~PluginCollection#_removeEventListener
protected mixed
Removes callback from emitter for given event.
Parameters
event : String
The name of the event.
callback : function
The function to stop being called.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.