Interface

PluginInterface (core)

@ckeditor/ckeditor5-core/src/plugin

interface

The base interface for CKEditor plugins.

In its minimal form a plugin can be a simple function that accepts the editor as a parameter:

// A simple plugin that enables a data processor.
function MyPlugin( editor ) {
	editor.data.processor = new MyDataProcessor();
}

In most cases however, you will want to inherit from the Plugin class which implements the Observable and is, therefore, more convenient:

class MyPlugin extends Plugin {
	init() {
		// `listenTo()` and `editor` are available thanks to `Plugin`.
		// By using `listenTo()` you will ensure that the listener is removed when
		// the plugin is destroyed.
		this.listenTo( this.editor.data, 'ready', () => {
			// Do something when the data is ready.
		} );
	}
}

The plugin class can have pluginName and requires static members. See PluginStaticMembers for more details.

The plugin can also implement methods (e.g. init() or destroy()) which, when present, will be used to properly initialize and destroy the plugin.

Note: When defined as a plain function, the plugin acts as a constructor and will be called in parallel with other plugins' constructors. This means the code of that plugin will be executed before init() and afterInit() methods of other plugins and, for instance, you cannot use it to extend other plugins' schema rules as they are defined later on during the init() stage.

Filtering

Methods

  • afterInit() → undefined | null | void | Promise<unknown>

    The third (and last) stage of the plugin initialization. See also PluginConstructor and init.

    Note: This method is optional. A plugin instance does not need to have it defined.

    Returns

    undefined | null | void | Promise<unknown>
  • destroy() → undefined | null | void | Promise<unknown>

    Destroys the plugin.

    Note: This method is optional. A plugin instance does not need to have it defined.

    Returns

    undefined | null | void | Promise<unknown>
  • init() → undefined | null | void | Promise<unknown>

    The second stage (after plugin constructor) of the plugin initialization. Unlike the plugin constructor this method can be asynchronous.

    A plugin's init() method is called after its dependencies are initialized, so in the same order as the constructors of these plugins.

    Note: This method is optional. A plugin instance does not need to have it defined.

    Returns

    undefined | null | void | Promise<unknown>