瀏覽代碼

Merge branch 'master' into t/152

Aleksander Nowodzinski 8 年之前
父節點
當前提交
ffc914c4f0

+ 1 - 2
packages/ckeditor5-ui/.travis.yml

@@ -15,8 +15,7 @@ before_install:
   - export DISPLAY=:99.0
   - sh -e /etc/init.d/xvfb start
 install:
-  - npm install gulp mgit2 lerna codeclimate-test-reporter
-  - npm install @ckeditor/ckeditor5-dev-tests @ckeditor/ckeditor5-dev-lint
+  - npm install @ckeditor/ckeditor5-dev-tests
   - ckeditor5-dev-tests-install-dependencies
 script:
   - ckeditor5-dev-tests-travis

+ 0 - 25
packages/ckeditor5-ui/CHANGES.md

@@ -1,25 +0,0 @@
-CKEditor 5 UI Framework Changelog
-========================================
-
-## CKEditor 5 UI Framework 0.0.2
-
-**Major|Minor|Patch Release** – Build Date: yyyy-mm-dd
-
-New Features:
-
-* [#Issue Number](http://issue/url): Item 1.
-* Item 2
-
-Fixed Issues:
-
-* [#Issue Number](http://issue/url): Item 1.
-* Item 2
-
-Other Changes:
-
-* Item 1
-* Item 2
-
-## CKEditor 5 UI Framework 0.0.1
-
-...

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

@@ -1,6 +1,6 @@
 {
   "name": "@ckeditor/ckeditor5-ui",
-  "version": "0.6.0",
+  "version": "0.7.0",
   "description": "The UI framework of CKEditor 5.",
   "keywords": [
     "CKEditor"

+ 0 - 1
packages/ckeditor5-ui/src/editableui/inline/inlineeditableuiview.js

@@ -46,7 +46,6 @@ export default class InlineEditableUIView extends EditableUIView {
 			attributes: {
 				role: 'textbox',
 				'aria-label': bind.to( 'name', getLabel ),
-				title: bind.to( 'name', getLabel ),
 				class: 'ck-editor__editable_inline'
 			}
 		} );

+ 27 - 1
packages/ckeditor5-ui/src/template.js

@@ -17,6 +17,7 @@ import View from './view';
 import ViewCollection from './viewcollection';
 import cloneDeepWith from '@ckeditor/ckeditor5-utils/src/lib/lodash/cloneDeepWith';
 import isObject from '@ckeditor/ckeditor5-utils/src/lib/lodash/isObject';
+import log from '@ckeditor/ckeditor5-utils/src/log';
 
 const xhtmlNs = 'http://www.w3.org/1999/xhtml';
 
@@ -56,6 +57,16 @@ export default class Template {
 		Object.assign( this, normalize( clone( def ) ) );
 
 		/**
+		 * Indicates whether this particular Template instance has been
+		 * {@link #render rendered}.
+		 *
+		 * @readonly
+		 * @protected
+		 * @member {Boolean}
+		 */
+		this._isRendered = false;
+
+		/**
 		 * Tag of this template, i.e. `div`, indicating that the instance will render
 		 * to an HTMLElement.
 		 *
@@ -113,9 +124,13 @@ export default class Template {
 	 * @returns {HTMLElement|Text}
 	 */
 	render() {
-		return this._renderNode( {
+		const node = this._renderNode( {
 			intoFragment: true
 		} );
+
+		this._isRendered = true;
+
+		return node;
 	}
 
 	/**
@@ -289,6 +304,17 @@ export default class Template {
 	 * @param {module:ui/template~TemplateDefinition} def An extension to existing an template instance.
 	 */
 	static extend( template, def ) {
+		if ( template._isRendered ) {
+			/**
+			 * Extending a template after rendering may not work as expected. To make sure
+			 * the {@link #extend extending} works for the rendered element, perform it
+			 * before {@link #render} is called.
+			 *
+			 * @error template-extend-render
+			 */
+			log.warn( 'template-extend-render: Attempting to extend a template which has already been rendered.' );
+		}
+
 		extendTemplate( template, normalize( clone( def ) ) );
 	}
 

+ 0 - 4
packages/ckeditor5-ui/tests/editableui/inline/inlineeditableuiview.js

@@ -53,10 +53,6 @@ describe( 'InlineEditableUIView', () => {
 			expect( view.element.getAttribute( 'aria-label' ) ).to.equal( ariaLabel );
 		} );
 
-		it( 'has proper title', () => {
-			expect( view.element.getAttribute( 'title' ) ).to.equal( ariaLabel );
-		} );
-
 		it( 'has proper class name', () => {
 			expect( view.element.classList.contains( 'ck-editor__editable' ) ).to.be.true;
 			expect( view.element.classList.contains( 'ck-editor__editable_inline' ) ).to.be.true;

+ 40 - 0
packages/ckeditor5-ui/tests/template.js

@@ -16,6 +16,7 @@ import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
 import DomEmitterMixin from '@ckeditor/ckeditor5-utils/src/dom/emittermixin';
 import Collection from '@ckeditor/ckeditor5-utils/src/collection';
 import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
+import log from '@ckeditor/ckeditor5-utils/src/log';
 
 testUtils.createSinonSandbox();
 
@@ -23,6 +24,10 @@ let el, text;
 
 describe( 'Template', () => {
 	describe( 'constructor()', () => {
+		it( 'sets #_isRendered property', () => {
+			expect( new Template( { tag: 'p' } )._isRendered ).to.be.false;
+		} );
+
 		it( 'accepts and normalizes the definition', () => {
 			const bind = Template.bind( new Model( {} ), Object.create( DomEmitterMixin ) );
 			const tpl = new Template( {
@@ -133,6 +138,16 @@ describe( 'Template', () => {
 			} ).to.throw( CKEditorError, /ui-template-wrong-syntax/ );
 		} );
 
+		it( 'sets #_isRendered true', () => {
+			const tpl = new Template( { tag: 'p' } );
+
+			expect( tpl._isRendered ).to.be.false;
+
+			tpl.render();
+
+			expect( tpl._isRendered ).to.be.true;
+		} );
+
 		describe( 'DOM Node', () => {
 			it( 'creates HTMLElement', () => {
 				const el = new Template( {
@@ -2188,6 +2203,31 @@ describe( 'Template', () => {
 			expect( tpl.attributes.b[ 0 ] ).to.equal( 'bar' );
 		} );
 
+		it( 'logs a warning if an element has already been rendered', () => {
+			const spy = testUtils.sinon.spy( log, 'warn' );
+
+			const tpl = new Template( {
+				tag: 'p'
+			} );
+
+			Template.extend( tpl, {
+				attributes: {
+					class: 'foo'
+				}
+			} );
+
+			tpl.render();
+
+			Template.extend( tpl, {
+				attributes: {
+					class: 'bar'
+				}
+			} );
+
+			sinon.assert.calledOnce( spy );
+			sinon.assert.calledWithExactly( spy, sinon.match( /^template-extend-render/ ) );
+		} );
+
 		describe( 'attributes', () => {
 			it( 'extends existing - simple', () => {
 				extensionTest(