Explorar el Código

Merge branch 'master' into t/ckeditor5/513-external

Aleksander Nowodzinski hace 8 años
padre
commit
48cdec42b9

+ 1 - 1
packages/ckeditor5-ui/package.json

@@ -6,12 +6,12 @@
     "CKEditor"
   ],
   "dependencies": {
+    "@ckeditor/ckeditor5-core": "^0.9.0",
     "@ckeditor/ckeditor5-theme-lark": "^0.9.0",
     "@ckeditor/ckeditor5-utils": "^0.10.0"
   },
   "devDependencies": {
     "@ckeditor/ckeditor5-basic-styles": "^0.9.0",
-    "@ckeditor/ckeditor5-core": "^0.9.0",
     "@ckeditor/ckeditor5-dev-lint": "^3.1.0",
     "@ckeditor/ckeditor5-editor-classic": "^0.8.0",
     "@ckeditor/ckeditor5-engine": "^0.11.0",

+ 13 - 5
packages/ckeditor5-ui/src/componentfactory.js

@@ -61,7 +61,7 @@ export default class ComponentFactory {
 	 * i.e. to set attribute values, create attribute bindings, etc.
 	 */
 	add( name, callback ) {
-		if ( this._components.get( name ) ) {
+		if ( this.has( name ) ) {
 			/**
 			 * The item already exists in the component factory.
 			 *
@@ -83,9 +83,7 @@ export default class ComponentFactory {
 	 * @returns {module:ui/view~View} The instantiated component view.
 	 */
 	create( name ) {
-		const component = this._components.get( name );
-
-		if ( !component ) {
+		if ( !this.has( name ) ) {
 			/**
 			 * There is no such UI component in the factory.
 			 *
@@ -97,6 +95,16 @@ export default class ComponentFactory {
 			);
 		}
 
-		return component( this.editor.locale );
+		return this._components.get( name )( this.editor.locale );
+	}
+
+	/**
+	 * Checks if a component of a given name is registered in the factory.
+	 *
+	 * @param {String} name The name of the component.
+	 * @returns {Boolean}
+	 */
+	has( name ) {
+		return this._components.has( name );
 	}
 }

+ 24 - 3
packages/ckeditor5-ui/src/toolbar/toolbarview.js

@@ -14,6 +14,7 @@ import FocusCycler from '../focuscycler';
 import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
 import ToolbarSeparatorView from './toolbarseparatorview';
 import preventDefault from '../bindings/preventdefault.js';
+import log from '@ckeditor/ckeditor5-utils/src/log';
 
 /**
  * The toolbar view class.
@@ -126,9 +127,29 @@ export default class ToolbarView extends View {
 		}
 
 		config.map( name => {
-			const component = name == '|' ? new ToolbarSeparatorView() : factory.create( name );
-
-			this.items.add( component );
+			if ( name == '|' ) {
+				this.items.add( new ToolbarSeparatorView() );
+			} else if ( factory.has( name ) ) {
+				this.items.add( factory.create( name ) );
+			} else {
+				/**
+				 * There was a problem processing the configuration of the toolbar. The item with the given
+				 * name does not exist so it was omitted when rendering the toolbar.
+				 *
+				 * This warning usually shows up when the {@link module:core/plugin~Plugin} which is supposed
+				 * to provide a toolbar item has not been loaded or there is a typo in the configuration.
+				 *
+				 * Make sure the plugin responsible for this toolbar item is loaded and the toolbar configuration
+				 * is correct, e.g. {@link module:basic-styles/bold~Bold} is loaded for the `'bold'` toolbar item.
+				 *
+				 * @error toolbarview-item-unavailable
+				 * @param {String} name The name of the component.
+				 */
+				log.warn(
+					'toolbarview-item-unavailable: The requested toolbar item is unavailable.',
+					{ name }
+				);
+			}
 		} );
 	}
 }

+ 11 - 0
packages/ckeditor5-ui/tests/componentfactory.js

@@ -70,4 +70,15 @@ describe( 'ComponentFactory', () => {
 			expect( instance.locale ).to.equal( locale );
 		} );
 	} );
+
+	describe( 'has()', () => {
+		it( 'checks if the factory contains a component of a given name', () => {
+			factory.add( 'foo', () => {} );
+			factory.add( 'bar', () => {} );
+
+			expect( factory.has( 'foo' ) ).to.be.true;
+			expect( factory.has( 'bar' ) ).to.be.true;
+			expect( factory.has( 'baz' ) ).to.be.false;
+		} );
+	} );
 } );

+ 2 - 2
packages/ckeditor5-ui/tests/manual/contextualballoon/contextualballoon.js

@@ -6,13 +6,13 @@
 /* globals window, document, console:false */
 
 import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
-import ArticlePresets from '@ckeditor/ckeditor5-presets/src/article';
+import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
 import ContextualToolbar from '@ckeditor/ckeditor5-ui/src/toolbar/contextual/contextualtoolbar';
 
 // Finally the editor.
 ClassicEditor
 	.create( document.querySelector( '#editor' ), {
-		plugins: [ ArticlePresets, ContextualToolbar ],
+		plugins: [ ArticlePluginSet, ContextualToolbar ],
 		toolbar: [ 'bold', 'link' ],
 		contextualToolbar: [ 'bold', 'link' ]
 	} )

+ 3 - 3
packages/ckeditor5-ui/tests/manual/contextualballoon/externalchanges.js

@@ -7,7 +7,7 @@
 
 import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
 import ContextualToolbar from '@ckeditor/ckeditor5-ui/src/toolbar/contextual/contextualtoolbar';
-import ArticlePresets from '@ckeditor/ckeditor5-presets/src/article';
+import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
 
 import Element from '@ckeditor/ckeditor5-engine/src/model/element';
 import Text from '@ckeditor/ckeditor5-engine/src/model/text';
@@ -17,7 +17,7 @@ import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 // Editor for the external insert.
 ClassicEditor
 	.create( document.querySelector( '#editor-insert' ), {
-		plugins: [ ArticlePresets, ContextualToolbar ],
+		plugins: [ ArticlePluginSet, ContextualToolbar ],
 		toolbar: [ 'bold', 'link' ],
 		contextualToolbar: [ 'bold', 'link' ]
 	} )
@@ -34,7 +34,7 @@ ClassicEditor
 // Editor for the external delete.
 ClassicEditor
 	.create( document.querySelector( '#editor-delete' ), {
-		plugins: [ ArticlePresets, ContextualToolbar ],
+		plugins: [ ArticlePluginSet, ContextualToolbar ],
 		toolbar: [ 'bold', 'link' ],
 		contextualToolbar: [ 'bold', 'link' ]
 	} )

+ 2 - 2
packages/ckeditor5-ui/tests/manual/contextualtoolbar/contextualtoolbar.js

@@ -6,13 +6,13 @@
 /* globals window, document, console:false */
 
 import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
-import ArticlePresets from '@ckeditor/ckeditor5-presets/src/article';
+import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
 import ContextualToolbar from '../../../src/toolbar/contextual/contextualtoolbar';
 import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 
 ClassicEditor
 	.create( document.querySelector( '#editor' ), {
-		plugins: [ ArticlePresets, ContextualToolbar ],
+		plugins: [ ArticlePluginSet, ContextualToolbar ],
 		toolbar: [ 'bold', 'italic', 'link', 'undo', 'redo' ],
 		contextualToolbar: [ 'bold', 'italic', 'link' ]
 	} )

+ 3 - 3
packages/ckeditor5-ui/tests/manual/tickets/170/1.js

@@ -6,7 +6,7 @@
 /* globals window, document, console:false */
 
 import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
-import ArticlePresets from '@ckeditor/ckeditor5-presets/src/article';
+import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
 import BalloonPanelView from '../../../../src/panel/balloon/balloonpanelview';
 
 // Set initial scroll for the outer container element.
@@ -15,7 +15,7 @@ document.querySelector( '.container-outer' ).scrollTop = 450;
 // Init editor with balloon attached to the target element.
 ClassicEditor
 	.create( document.querySelector( '#editor-attach' ), {
-		plugins: [ ArticlePresets ],
+		plugins: [ ArticlePluginSet ],
 		toolbar: [ 'bold', 'italic', 'undo', 'redo' ]
 	} )
 	.then( editor => {
@@ -41,7 +41,7 @@ ClassicEditor
 // Init editor with balloon sticked to the target element.
 ClassicEditor
 	.create( document.querySelector( '#editor-stick' ), {
-		plugins: [ ArticlePresets ],
+		plugins: [ ArticlePluginSet ],
 		toolbar: [ 'bold', 'italic', 'undo', 'redo' ]
 	} )
 	.then( editor => {

+ 3 - 3
packages/ckeditor5-ui/tests/manual/tickets/198/1.js

@@ -6,7 +6,7 @@
 /* globals console:false, document, setTimeout */
 
 import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
-import ArticlePresets from '@ckeditor/ckeditor5-presets/src/article';
+import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
 import ContextualToolbar from '../../../../src/toolbar/contextual/contextualtoolbar';
 
 import Element from '@ckeditor/ckeditor5-engine/src/model/element';
@@ -17,7 +17,7 @@ import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 // Editor for the external insert.
 ClassicEditor
 	.create( document.querySelector( '#editor-insert' ), {
-		plugins: [ ArticlePresets, ContextualToolbar ],
+		plugins: [ ArticlePluginSet, ContextualToolbar ],
 		toolbar: [ 'undo', 'redo' ],
 		contextualToolbar: [ 'bold', 'italic' ]
 	} )
@@ -34,7 +34,7 @@ ClassicEditor
 // Editor for the external delete.
 ClassicEditor
 	.create( document.querySelector( '#editor-delete' ), {
-		plugins: [ ArticlePresets, ContextualToolbar ],
+		plugins: [ ArticlePluginSet, ContextualToolbar ],
 		toolbar: [ 'undo', 'redo' ],
 		contextualToolbar: [ 'bold', 'italic' ]
 	} )

+ 2 - 2
packages/ckeditor5-ui/tests/manual/tickets/228/1.js

@@ -6,11 +6,11 @@
 /* globals document, console:false */
 
 import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
-import ArticlePresets from '@ckeditor/ckeditor5-presets/src/article';
+import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
 
 ClassicEditor
 	.create( document.querySelector( '#editor' ), {
-		plugins: [ ArticlePresets ],
+		plugins: [ ArticlePluginSet ],
 		toolbar: [ 'headings' ],
 	} )
 	.catch( err => console.error( err.stack ) );

+ 21 - 0
packages/ckeditor5-ui/tests/toolbar/toolbarview.js

@@ -13,11 +13,15 @@ import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
 import FocusCycler from '../../src/focuscycler';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 import ViewCollection from '../../src/viewcollection';
+import log from '@ckeditor/ckeditor5-utils/src/log';
 import View from '../../src/view';
+import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
 describe( 'ToolbarView', () => {
 	let locale, view;
 
+	testUtils.createSinonSandbox();
+
 	beforeEach( () => {
 		locale = {};
 		view = new ToolbarView( locale );
@@ -247,6 +251,23 @@ describe( 'ToolbarView', () => {
 			expect( items.get( 2 ) ).to.be.instanceOf( ToolbarSeparatorView );
 			expect( items.get( 3 ).name ).to.equal( 'foo' );
 		} );
+
+		it( 'warns if there is no such component in the factory', () => {
+			const items = view.items;
+			testUtils.sinon.stub( log, 'warn' );
+
+			view.fillFromConfig( [ 'foo', 'bar', 'baz' ], factory );
+
+			expect( items ).to.have.length( 2 );
+			expect( items.get( 0 ).name ).to.equal( 'foo' );
+			expect( items.get( 1 ).name ).to.equal( 'bar' );
+
+			sinon.assert.calledOnce( log.warn );
+			sinon.assert.calledWithExactly( log.warn,
+				sinon.match( /^toolbarview-item-unavailable/ ),
+				{ name: 'baz' }
+			);
+		} );
 	} );
 } );