Description
The time has come when some of our plugins evolved so much that they can be used outside of the editor. Such plugins have to stay compatible with the editor (like it was before) but also have to be ready to be used without the editor, or even with multiple editors at once.
After some researches and discussions, we decided to introduce a Context
class, that's gonna be an environment for the plugins used outside of the editor. Also, a new type of plugin, a ContextPlugin
will be introduced to represents plugins compatible with the context and the editor. The current Plugin
class will be compatible only with the editor like it was before.
Context API will be similar to the editor API but will be limited only to some properties:
Context.plugins
Context.config
Context.locale
Scenarios
Single editor usage
For the single editor, not much change. Editor, when created, initialize additional property editor.context
, with an empty context used only by this editor. There are no changes in the editor API for basic usage.
Shared editor usage
Assume that the Comments
plugin requires the Sidebar
plugin.
const context = async Context.create( {
plugins: [ Sidebar ],
sidebar: {
container: sidebarElement
}
} );
const editor1 = async ClassicEditor.create( editorElement1, {
context: context,
plugins: [ ArticlePlugins, Comments ]
} );
const editor2 = async ClassicEditor.create( editorElement2, {
context: context,
plugins: [ ArticlePlugins, Comments ]
} );
If the context
property is passed to the editor it means that:
context.plugins
(instances) should be added to the editor plugins,editor.config
should be extended by thecontext.config
,editor.locale
should usecontext.locale
.
Note, that this way, both editors will share the same Sidebar
plugin. When any of these editors use editor.plugins.get( 'Sidebar' )
they will get the same instance.
When it comes to dependencies:
- it should be possible, for the context plugins to requires another context plugins,
- it should be possible, for the editor plugins to requires context plugins,
- it should NOT be possible, for the context plugins to require editor plugins.