Class

PluginCollection (core)

@ckeditor/ckeditor5-core/src/plugincollection

class

Manages a list of CKEditor plugins, including loading, resolving dependencies and initialization.

Filtering

Properties

  • _availablePlugins : Map.&lt(String|Function), function()>

    protected

    A map of plugin constructors that can be retrieved by their names.

  • _context : Editor | Context

    protected

  • _contextPlugins : Map.<Function, function()>

    protected

    Map of context plugins which can be retrieved by their constructors or instances.

  • _plugins : Map

    protected

Methods

  • constructor( context, [ availablePlugins ], contextPlugins )

    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 in config.plugins or config.removePlugins by names.

    contextPlugins : Iterable.<Array>

    A list of already initialized plugins represented by a [ PluginConstructor, pluginInstance ] pair.

  • Symbol.iterator() → Iterable.<Array>

    Iterable interface.

    Returns [ PluginConstructor, pluginInstance ] pairs.

    Returns

    Iterable.<Array>
  • delegate( events ) → EmitterMixinDelegateChain

    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 and emitterC along with data:

    emitterA.fire( 'eventX', data );
    

    and eventY is delegated (fired by) emitterC along with data:

    emitterA.fire( 'eventY', data );

    Parameters

    events : String

    Event names that will be delegated to another emitter.

    Returns

    EmitterMixinDelegateChain
  • destroy() → Promise

    Destroys all loaded plugins.

    Returns

    Promise
  • fire( eventOrInfo, [ args ] ) → *

    mixed

    Fires an event, executing all callbacks registered for it.

    The first parameter passed to callbacks is an EventInfo object, followed by the optional args provided in the fire() 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 the evt.return's property (the event info is the first param of every callback).

  • get( key ) → PluginInterface

    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

    PluginInterface
  • has( key ) → Boolean

    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>

    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] } )

    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 )

    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] } )

    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] } )

    mixed

    Registers a callback function to be executed on the next time the event is fired only. This is similar to calling on followed by off 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 ] )

    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 of event to all emitters.

  • stopListening( [ emitter ], [ event ], [ callback ] )

    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 from emitter.

    [ callback ] : function

    (Requires the event) The function to be removed from the call list for the given event.

  • _add( PluginConstructor, plugin )

    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] } )

    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 )

    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.