Plugin
The Plugin
interface manages a collection of plugins. It allows plugins to be added and loaded into an Editor instance, and it handles the initialization and unmounting of those plugins.
Note
The constructor is not directly accessible. Instead, you can access its methods via the Editor.plugin object.
Example:
Editor.plugin.add('logger', (editor) => {
console.log('Logger plugin initialized');
return () => console.log('Logger plugin unloaded');
});
Instance methods
add()
Registers a plugin using a name as the key.
Parameters:
name
A string that specifies the name of the plugin to add.
plugin
A function for initializing the plugin. This function must match the InitializePlugin type.
Return value:
None.
Example:
Editor.plugin.add('myPlugin', (editor) => {
console.log('myPlugin initialized.');
});
loadAll()
Loads all registered plugins.
Parameters:
editor
An Editor object where plugins should be loaded.
Return value:
A map containing the names of plugins and their corresponding UnmountPlugin functions that will be used to clean up the plugin.
Example:
// Load plugins
const unmountMap = Editor.plugin.loadAll(editor);
// Unmount all loaded plugins
unmountMap.forEach((unmount) => unmount());