PluginCollection
Manages a list of CKEditor plugins, including loading, resolving dependencies and initialization.
Type parameters
TContext
Properties
_availablePlugins : Map<string, PluginConstructor<TContext>>privatemodule:core/plugincollection~PluginCollection#_availablePluginsA map of plugin constructors that can be retrieved by their names.
_context : TContextprivatemodule:core/plugincollection~PluginCollection#_context_contextPlugins : Map<PluginInterface | PluginConstructor<TContext>, PluginInterface | PluginConstructor<TContext>>privatemodule:core/plugincollection~PluginCollection#_contextPluginsMap of context plugins which can be retrieved by their constructors or instances.
_plugins : Map<string | PluginConstructor<TContext>, PluginInterface>privatemodule:core/plugincollection~PluginCollection#_plugins
Methods
constructor( context, availablePlugins, contextPlugins )module:core/plugincollection~PluginCollection#constructorCreates 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.
Type parameters
TContext
Parameters
context : TContextavailablePlugins : Iterable<PluginConstructor<TContext>>Plugins (constructors) which the collection will be able to use when
initis 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.pluginsorconfig.removePluginsby names.Defaults to
[]contextPlugins : Iterable<PluginEntry<TContext>>A list of already initialized plugins represented by a
[ PluginConstructor, pluginInstance ]pair.Defaults to
[]
Symbol.iterator() → IterableIterator<PluginEntry<TContext>>module:core/plugincollection~PluginCollection#Symbol.iteratorIterable interface.
Returns
[ PluginConstructor, pluginInstance ]pairs.Returns
IterableIterator<PluginEntry<TContext>>
delegate( events ) → EmitterMixinDelegateChaininheritedmodule:core/plugincollection~PluginCollection#delegateDelegates selected events to another
Emitter. For instance:emitterA.delegate( 'eventX' ).to( emitterB ); emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );Copy codethen
eventXis delegated (fired by)emitterBandemitterCalong withdata:emitterA.fire( 'eventX', data );Copy codeand
eventYis delegated (fired by)emitterCalong withdata:emitterA.fire( 'eventY', data );Copy codeParameters
events : Array<string>Event names that will be delegated to another emitter.
Returns
destroy() → Promise<unknown>module:core/plugincollection~PluginCollection#destroyfire( eventOrInfo, args ) → GetEventInfo<TEvent>[ 'return' ]inheritedmodule:core/plugincollection~PluginCollection#fireFires an event, executing all callbacks registered for it.
The first parameter passed to callbacks is an
EventInfoobject, followed by the optionalargsprovided in thefire()method call.Type parameters
Parameters
eventOrInfo : GetNameOrEventInfo<TEvent>The name of the event or
EventInfoobject if event is delegated.args : TEvent[ 'args' ]Additional arguments to be passed to the callbacks.
Returns
GetEventInfo<TEvent>[ 'return' ]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 ) → PluginsMap[ TName ]module:core/plugincollection~PluginCollection#getget( key ) → InstanceType<TConstructor>module:core/plugincollection~PluginCollection#getType parameters
TConstructor : extends PluginClassConstructor<TContext>
Parameters
key : TConstructor
Returns
InstanceType<TConstructor>
has( key ) → booleanmodule:core/plugincollection~PluginCollection#hasChecks 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' ); // ... }Copy codeParameters
key : string | PluginConstructor<TContext>The plugin constructor or name.
Returns
boolean
init( plugins, pluginsToRemove, pluginsSubstitutions ) → Promise<LoadedPlugins>module:core/plugincollection~PluginCollection#initInitializes a set of plugins and adds them to the collection.
Parameters
plugins : readonly Array<string | PluginConstructor<TContext>>An array of plugin constructors or plugin names.
pluginsToRemove : readonly Array<string | PluginConstructor<TContext>>Names of the plugins or plugin constructors that should not be loaded (despite being specified in the
pluginsarray).Defaults to
[]pluginsSubstitutions : readonly Array<PluginConstructor<TContext>>An array of plugin constructors that will be used to replace plugins of the same names that were passed in
pluginsor 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.
Defaults to
[]
Returns
Promise<LoadedPlugins>A promise which gets resolved once all plugins are loaded and available in the collection.
listenTo( emitter, event, callback, [ options ] ) → voidinheritedmodule:core/plugincollection~PluginCollection#listenTo:BASE_EMITTERRegisters 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' );Copy codeAn event callback can stop the event and set the return value of the
firemethod.Type parameters
Parameters
emitter : EmitterThe object that fires the event.
event : TEvent[ 'name' ]The name of the event.
callback : GetCallback<TEvent>The function to be called on event.
[ options ] : GetCallbackOptions<TEvent>Additional options.
Returns
void
off( event, callback ) → voidinheritedmodule:core/plugincollection~PluginCollection#offStops executing the callback on the given event. Shorthand for
this.stopListening( this, event, callback ).Parameters
event : stringThe name of the event.
callback : FunctionThe function to stop being called.
Returns
void
on( event, callback, [ options ] ) → voidinheritedmodule:core/plugincollection~PluginCollection#onRegisters 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).Type parameters
Parameters
event : TEvent[ 'name' ]The name of the event.
callback : GetCallback<TEvent>The function to be called on event.
[ options ] : GetCallbackOptions<TEvent>Additional options.
Returns
void
once( event, callback, [ options ] ) → voidinheritedmodule:core/plugincollection~PluginCollection#onceRegisters a callback function to be executed on the next time the event is fired only. This is similar to calling
onfollowed byoffin the callback.Type parameters
Parameters
event : TEvent[ 'name' ]The name of the event.
callback : GetCallback<TEvent>The function to be called on event.
[ options ] : GetCallbackOptions<TEvent>Additional options.
Returns
void
stopDelegating( [ event ], [ emitter ] ) → voidinheritedmodule:core/plugincollection~PluginCollection#stopDelegatingStops 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 ] : stringThe 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 ofeventto all emitters.
Returns
void
stopListening( [ emitter ], [ event ], [ callback ] ) → voidinheritedmodule:core/plugincollection~PluginCollection#stopListening:BASE_STOPStops 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 ] : EmitterThe 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.
Returns
void
_add( PluginConstructor, plugin ) → voidprivatemodule:core/plugincollection~PluginCollection#_addAdds the plugin to the collection. Exposed mainly for testing purposes.
Parameters
PluginConstructor : PluginConstructor<TContext>The plugin constructor.
plugin : PluginInterfaceThe instance of the plugin.
Returns
void