8
0
Pārlūkot izejas kodu

Other: Split `Editor.build` into `Editor.builtinPlugins` and `Editor.defaultConfig`. Closes #140.

BREAKING CHANGE: `Editor.build` was split to `Editor.builtinPlugins` and `Editor.defaultConfig`.
Piotrek Koszuliński 7 gadi atpakaļ
vecāks
revīzija
bfbd58723c

+ 72 - 9
packages/ckeditor5-core/src/editor/editor.js

@@ -51,7 +51,7 @@ export default class Editor {
 	 * @param {Object} config The editor config.
 	 */
 	constructor( config ) {
-		const availablePlugins = this.constructor.build && this.constructor.build.plugins;
+		const availablePlugins = this.constructor.builtinPlugins;
 
 		/**
 		 * Holds all configurations specific to this editor instance.
@@ -62,7 +62,7 @@ export default class Editor {
 		 * @readonly
 		 * @member {module:utils/config~Config}
 		 */
-		this.config = new Config( config, this.constructor.build && this.constructor.build.config );
+		this.config = new Config( config, this.constructor.defaultConfig );
 
 		this.config.define( 'plugins', availablePlugins );
 
@@ -348,15 +348,78 @@ mix( Editor, ObservableMixin );
  */
 
 /**
- * Additional data built into the editor class. It's used while bundling the editor in order to provide
- * the default set of plugins and config options which are later used during editor initialization.
+ * An array of plugins built into this editor class.
+ * It is used in CKEditor 5 builds to provide a list of plugins which are later automatically initialized
+ * during the editor initialization.
  *
- * Two properties are supported:
+ * They will be automatically initialized by the editor, unless listed in `config.removePlugins` and
+ * unless `config.plugins` is passed.
  *
- * * `plugins` – an array of plugin constructors. They will be automatically initialized by the editor, unless listed
- * in `config.removePlugins` or unless `config.plugins` is passed.
- * * `config` – the defalt config options.
+ *		// Build some plugins into the editor class first.
+ *		ClassicEditor.builtinPlugins = [ FooPlugin, BarPlugin ];
+ *
+ *		// Normally, you need to define config.plugins, but since ClassicEditor.builtinPlugins was
+ *		// defined, now you can call create() without any configuration.
+ *		ClassicEditor
+ *			.create( sourceElement )
+ *			.then( editor => {
+ *				editor.plugins.get( FooPlugin ); // -> instance of the Foo plugin
+ *				editor.plugins.get( BarPlugin ); // -> instance of the Bar plugin
+ *			} );
+ *
+ *		ClassicEditor
+ *			.create( sourceElement, {
+ *				// Don't initialize this plugins (note: it's defined by a string):
+ *				removePlugins: [ 'Foo' ]
+ *			} )
+ *			.then( editor => {
+ *				editor.plugins.get( FooPlugin ); // -> undefined
+ *				editor.config.get( BarPlugin ); // -> instance of the Bar plugin
+ *			} );
+ *
+ *		ClassicEditor
+ *			.create( sourceElement, {
+ *				// Load only this plugin. Can also be define by a string if
+ *				// this plugin was built into the editor class.
+ *				plugins: [ FooPlugin ]
+ *			} )
+ *			.then( editor => {
+ *				editor.plugins.get( FooPlugin ); // -> instance of the Foo plugin
+ *				editor.config.get( BarPlugin ); // -> undefined
+ *			} );
+ *
+ * See also {@link module:core/editor/editor~Editor.defaultConfig}.
+ *
+ * @static
+ * @member {Array.<Function>} module:core/editor/editor~Editor.builtinPlugins
+ */
+
+/**
+ * The default config which is built into the editor class.
+ * It is used in CKEditor 5 builds to provide the default config options which are later used during editor initialization.
+ *
+ *		ClassicEditor.defaultConfig = {
+ *			foo: 1,
+ *			bar: 2
+ *		};
+ *
+ *		ClassicEditor
+ *			.create( sourceElement )
+ *			.then( editor => {
+ *				editor.config.get( 'foo' ); // -> 1
+ *				editor.config.get( 'bar' ); // -> 2
+ *			} );
+ *
+ *		// The default options can be overridden by the config passed to create().
+ *		ClassicEditor
+ *			.create( sourceElement, { bar: 3 } )
+ *			.then( editor => {
+ *				editor.config.get( 'foo' ); // -> 1
+ *				editor.config.get( 'bar' ); // -> 3
+ *			} );
+ *
+ * See also {@link module:core/editor/editor~Editor.builtinPlugins}.
  *
  * @static
- * @member {Object} module:core/editor/editor~Editor.build
+ * @member {Object} module:core/editor/editor~Editor.defaultConfig
  */

+ 1 - 1
packages/ckeditor5-core/src/editor/editorconfig.jsdoc

@@ -42,7 +42,7 @@
  *
  * You can check the list of plugins available in a build using this snippet:
  *
- *		ClassicEditor.build.plugins.map( plugin => plugin.pluginName );
+ *		ClassicEditor.builtinPlugins.map( plugin => plugin.pluginName );
  *
  * If you use an editor creator directly (imported from a package like `@ckeditor/ckeditor5-editor-classic`) or you
  * want to load additional plugins which were not included in a build you use, then you need to specify

+ 1 - 1
packages/ckeditor5-core/src/plugincollection.js

@@ -106,7 +106,7 @@ export default class PluginCollection {
 			 * Some plugins are not available and could not be loaded.
 			 *
 			 * Plugin classes (constructors) need to be provided to the editor before they can be loaded by name.
-			 * This is usually done by the builder by setting the {@link module:core/editor/editor~Editor.build}
+			 * This is usually done in CKEditor 5 builds by setting the {@link module:core/editor/editor~Editor.builtinPlugins}
 			 * property.
 			 *
 			 * **If you see this warning when using one of the {@glink builds/index CKEditor 5 Builds}**, it means

+ 13 - 28
packages/ckeditor5-core/tests/editor/editor.js

@@ -96,7 +96,8 @@ class PluginF {
 
 describe( 'Editor', () => {
 	afterEach( () => {
-		delete Editor.build;
+		delete Editor.builtinPlugins;
+		delete Editor.defaultConfig;
 	} );
 
 	it( 'imports the version helper', () => {
@@ -117,12 +118,10 @@ describe( 'Editor', () => {
 		} );
 
 		it( 'should extend an editor configuration using built in config', () => {
-			Editor.build = {
-				config: {
-					foo: {
-						a: 1,
-						b: 2
-					}
+			Editor.defaultConfig = {
+				foo: {
+					a: 1,
+					b: 2
 				}
 			};
 
@@ -533,9 +532,7 @@ describe( 'Editor', () => {
 		} );
 
 		it( 'should load plugins built in the Editor even if the passed config is empty', () => {
-			Editor.build = {
-				plugins: [ PluginA, PluginB, PluginC ]
-			};
+			Editor.builtinPlugins = [ PluginA, PluginB, PluginC ];
 
 			const editor = new Editor();
 
@@ -550,9 +547,7 @@ describe( 'Editor', () => {
 		} );
 
 		it( 'should load plugins provided in the config and should ignore plugins built in the Editor', () => {
-			Editor.build = {
-				plugins: [ PluginA, PluginB, PluginC, PluginD ]
-			};
+			Editor.builtinPlugins = [ PluginA, PluginB, PluginC, PluginD ];
 
 			const editor = new Editor( {
 				plugins: [
@@ -571,9 +566,7 @@ describe( 'Editor', () => {
 		it( 'should load plugins built in the Editor using their names', () => {
 			class PrivatePlugin extends Plugin {}
 
-			Editor.build = {
-				plugins: [ PluginA, PluginB, PluginC, PluginD ]
-			};
+			Editor.builtinPlugins = [ PluginA, PluginB, PluginC, PluginD ];
 
 			const editor = new Editor( {
 				plugins: [
@@ -596,9 +589,7 @@ describe( 'Editor', () => {
 		} );
 
 		it( 'should load plugins inherited from the base Editor', () => {
-			Editor.build = {
-				plugins: [ PluginA, PluginB, PluginC, PluginD ]
-			};
+			Editor.builtinPlugins = [ PluginA, PluginB, PluginC, PluginD ];
 
 			class CustomEditor extends Editor {}
 
@@ -621,9 +612,7 @@ describe( 'Editor', () => {
 		it( 'should load plugins build into Editor\'s subclass', () => {
 			class CustomEditor extends Editor {}
 
-			CustomEditor.build = {
-				plugins: [ PluginA, PluginB, PluginC, PluginD ]
-			};
+			CustomEditor.builtinPlugins = [ PluginA, PluginB, PluginC, PluginD ];
 
 			const editor = new CustomEditor( {
 				plugins: [
@@ -655,9 +644,7 @@ describe( 'Editor', () => {
 		} );
 
 		it( 'should not load plugins built in the Editor when "removePlugins" option is specified', () => {
-			Editor.build = {
-				plugins: [ PluginA, PluginD ]
-			};
+			Editor.builtinPlugins = [ PluginA, PluginD ];
 
 			const editor = new Editor( {
 				removePlugins: [ 'D' ]
@@ -673,9 +660,7 @@ describe( 'Editor', () => {
 		it( 'should not load plugins build into Editor\'s subclass when "removePlugins" option is specified', () => {
 			class CustomEditor extends Editor {}
 
-			CustomEditor.build = {
-				plugins: [ PluginA, PluginD ]
-			};
+			CustomEditor.builtinPlugins = [ PluginA, PluginD ];
 
 			const editor = new CustomEditor( {
 				removePlugins: [ 'D' ]