Explorar el Código

Feature: Implemented the `extraPlugins` editor configuration.

Aleksander Nowodzinski hace 7 años
padre
commit
aa4449c3d3

+ 2 - 1
packages/ckeditor5-core/src/editor/editor.js

@@ -232,8 +232,9 @@ export default class Editor {
 		function loadPlugins() {
 			const plugins = config.get( 'plugins' ) || [];
 			const removePlugins = config.get( 'removePlugins' ) || [];
+			const extraPlugins = config.get( 'extraPlugins' ) || [];
 
-			return that.plugins.load( plugins, removePlugins );
+			return that.plugins.load( plugins.concat( extraPlugins ), removePlugins );
 		}
 
 		function initPlugins( loadedPlugins, method ) {

+ 20 - 0
packages/ckeditor5-core/src/editor/editorconfig.jsdoc

@@ -57,9 +57,29 @@
  *			plugins: [ Essentials, Bold ]
  *		};
  *
+ * **Note:** To load additional plugins, you should use the {@link #extraPlugins `extraPlugins`} configuration.
+ * To narrow the list of loaded plugins, use the {@link #removePlugins `removePlugins`} configuration.
+ *
  * @member {Array.<String|Function>} module:core/editor/editorconfig~EditorConfig#plugins
  */
 
+/**
+ * The list of additional plugins to load along those already available in the
+ * {@glink builds/guides/overview editor build}. It extends the {@link #plugins `plugins`} configuration.
+ *
+ *		import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
+ *		import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
+ *
+ *		const config = {
+ *			extraPlugins: [ Highlight, Underline ]
+ *		};
+ *
+ * **Note:** Make sure you include the new features in you toolbar configuration. Learn more
+ * about {@glink builds/guides/integration/configuration#toolbar-setup toolbar setup}.
+ *
+ * @member {Array.<Function>} module:core/editor/editorconfig~EditorConfig#extraPlugins
+ */
+
 /**
  * The list of plugins which should not be loaded despite being available in an {@glink builds/guides/overview editor build}.
  *

+ 86 - 26
packages/ckeditor5-core/tests/editor/editor.js

@@ -630,47 +630,107 @@ describe( 'Editor', () => {
 				} );
 		} );
 
-		it( 'should not load plugins specified in the config as "removePlugins"', () => {
-			const editor = new Editor( {
-				plugins: [ PluginA, PluginD ],
-				removePlugins: [ PluginD ]
+		describe( '"removePlugins" config', () => {
+			it( 'should prevent plugins from being loaded', () => {
+				const editor = new Editor( {
+					plugins: [ PluginA, PluginD ],
+					removePlugins: [ PluginD ]
+				} );
+
+				return editor.initPlugins()
+					.then( () => {
+						expect( getPlugins( editor ).length ).to.equal( 1 );
+						expect( editor.plugins.get( PluginA ) ).to.be.an.instanceof( Plugin );
+					} );
 			} );
 
-			return editor.initPlugins()
-				.then( () => {
-					expect( getPlugins( editor ).length ).to.equal( 1 );
-					expect( editor.plugins.get( PluginA ) ).to.be.an.instanceof( Plugin );
+			it( 'should not load plugins built in the Editor', () => {
+				Editor.builtinPlugins = [ PluginA, PluginD ];
+
+				const editor = new Editor( {
+					removePlugins: [ 'D' ]
 				} );
+
+				return editor.initPlugins()
+					.then( () => {
+						expect( getPlugins( editor ).length ).to.equal( 1 );
+						expect( editor.plugins.get( PluginA ) ).to.be.an.instanceof( Plugin );
+					} );
+			} );
+
+			it( 'should not load plugins build into Editor\'s subclass', () => {
+				class CustomEditor extends Editor {}
+
+				CustomEditor.builtinPlugins = [ PluginA, PluginD ];
+
+				const editor = new CustomEditor( {
+					removePlugins: [ 'D' ]
+				} );
+
+				return editor.initPlugins()
+					.then( () => {
+						expect( getPlugins( editor ).length ).to.equal( 1 );
+						expect( editor.plugins.get( PluginA ) ).to.not.be.undefined;
+					} );
+			} );
 		} );
 
-		it( 'should not load plugins built in the Editor when "removePlugins" option is specified', () => {
-			Editor.builtinPlugins = [ PluginA, PluginD ];
+		describe( '"extraPlugins" config', () => {
+			it( 'should load additional plugins', () => {
+				const editor = new Editor( {
+					plugins: [ PluginA, PluginC ],
+					extraPlugins: [ PluginB ]
+				} );
 
-			const editor = new Editor( {
-				removePlugins: [ 'D' ]
+				return editor.initPlugins()
+					.then( () => {
+						expect( getPlugins( editor ).length ).to.equal( 3 );
+						expect( editor.plugins.get( PluginB ) ).to.be.an.instanceof( Plugin );
+					} );
 			} );
 
-			return editor.initPlugins()
-				.then( () => {
-					expect( getPlugins( editor ).length ).to.equal( 1 );
-					expect( editor.plugins.get( PluginA ) ).to.be.an.instanceof( Plugin );
+			it( 'should not duplicate plugins', () => {
+				const editor = new Editor( {
+					plugins: [ PluginA, PluginB ],
+					extraPlugins: [ PluginB ]
 				} );
-		} );
 
-		it( 'should not load plugins build into Editor\'s subclass when "removePlugins" option is specified', () => {
-			class CustomEditor extends Editor {}
+				return editor.initPlugins()
+					.then( () => {
+						expect( getPlugins( editor ).length ).to.equal( 2 );
+						expect( editor.plugins.get( PluginB ) ).to.be.an.instanceof( Plugin );
+					} );
+			} );
 
-			CustomEditor.builtinPlugins = [ PluginA, PluginD ];
+			it( 'should not duplicate plugins built in the Editor', () => {
+				Editor.builtinPlugins = [ PluginA, PluginB ];
 
-			const editor = new CustomEditor( {
-				removePlugins: [ 'D' ]
+				const editor = new Editor( {
+					extraPlugins: [ 'B' ]
+				} );
+
+				return editor.initPlugins()
+					.then( () => {
+						expect( getPlugins( editor ).length ).to.equal( 2 );
+						expect( editor.plugins.get( PluginB ) ).to.be.an.instanceof( Plugin );
+					} );
 			} );
 
-			return editor.initPlugins()
-				.then( () => {
-					expect( getPlugins( editor ).length ).to.equal( 1 );
-					expect( editor.plugins.get( PluginA ) ).to.not.be.undefined;
+			it( 'should not duplicate plugins build into Editor\'s subclass', () => {
+				class CustomEditor extends Editor {}
+
+				CustomEditor.builtinPlugins = [ PluginA, PluginB ];
+
+				const editor = new CustomEditor( {
+					extraPlugins: [ 'B' ]
 				} );
+
+				return editor.initPlugins()
+					.then( () => {
+						expect( getPlugins( editor ).length ).to.equal( 2 );
+						expect( editor.plugins.get( PluginB ) ).to.be.an.instanceof( Plugin );
+					} );
+			} );
 		} );
 
 		it( 'should not call "afterInit" method if plugin does not have this method', () => {