Browse Source

Merge branch 'master' into t/ckeditor5/746

Maciej Gołaszewski 6 years ago
parent
commit
4566f3a2b4

File diff suppressed because it is too large
+ 1 - 3
packages/ckeditor5-editor-balloon/.travis.yml


+ 17 - 0
packages/ckeditor5-editor-balloon/CHANGELOG.md

@@ -1,6 +1,23 @@
 Changelog
 =========
 
+## [12.2.1](https://github.com/ckeditor/ckeditor5-editor-balloon/compare/v12.2.0...v12.2.1) (2019-07-10)
+
+Internal changes only (updated dependencies, documentation, etc.).
+
+
+## [12.2.0](https://github.com/ckeditor/ckeditor5-editor-balloon/compare/v12.1.1...v12.2.0) (2019-07-04)
+
+### Features
+
+* `BalloonEditor.create()` will throw an error, when textarea element is used. ([83552e2](https://github.com/ckeditor/ckeditor5-editor-balloon/commit/83552e2))
+
+
+## [12.1.1](https://github.com/ckeditor/ckeditor5-editor-balloon/compare/v12.1.0...v12.1.1) (2019-06-05)
+
+Internal changes only (updated dependencies, documentation, etc.).
+
+
 ## [12.1.0](https://github.com/ckeditor/ckeditor5-editor-balloon/compare/v12.0.0...v12.1.0) (2019-04-10)
 
 ### Features

+ 0 - 1
packages/ckeditor5-editor-balloon/README.md

@@ -4,7 +4,6 @@ CKEditor 5 balloon editor implementation
 [![Join the chat at https://gitter.im/ckeditor/ckeditor5](https://badges.gitter.im/ckeditor/ckeditor5.svg)](https://gitter.im/ckeditor/ckeditor5?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
 [![npm version](https://badge.fury.io/js/%40ckeditor%2Fckeditor5-editor-balloon.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-editor-balloon)
 [![Build Status](https://travis-ci.org/ckeditor/ckeditor5-editor-balloon.svg?branch=master)](https://travis-ci.org/ckeditor/ckeditor5-editor-balloon)
-[![BrowserStack Status](https://automate.browserstack.com/automate/badge.svg?badge_key=d3hvenZqQVZERFQ5d09FWXdyT0ozVXhLaVltRFRjTTUyZGpvQWNmWVhUUT0tLUZqNlJ1YWRUd0RvdEVOaEptM1B2Q0E9PQ==--c9d3dee40b9b4471ff3fb516d9ecf8d09292c7e0)](https://automate.browserstack.com/public-build/d3hvenZqQVZERFQ5d09FWXdyT0ozVXhLaVltRFRjTTUyZGpvQWNmWVhUUT0tLUZqNlJ1YWRUd0RvdEVOaEptM1B2Q0E9PQ==--c9d3dee40b9b4471ff3fb516d9ecf8d09292c7e0)
 [![Coverage Status](https://coveralls.io/repos/github/ckeditor/ckeditor5-editor-balloon/badge.svg?branch=master)](https://coveralls.io/github/ckeditor/ckeditor5-editor-balloon?branch=master)
 <br>
 [![Dependency Status](https://david-dm.org/ckeditor/ckeditor5-editor-balloon/status.svg)](https://david-dm.org/ckeditor/ckeditor5-editor-balloon)

+ 12 - 12
packages/ckeditor5-editor-balloon/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@ckeditor/ckeditor5-editor-balloon",
-  "version": "12.1.0",
+  "version": "12.2.1",
   "description": "Balloon editor implementation for CKEditor 5.",
   "keywords": [
     "ckeditor",
@@ -9,21 +9,21 @@
     "ckeditor5-editor"
   ],
   "dependencies": {
-    "@ckeditor/ckeditor5-core": "^12.1.0",
-    "@ckeditor/ckeditor5-engine": "^13.1.0",
-    "@ckeditor/ckeditor5-ui": "^12.1.0",
-    "@ckeditor/ckeditor5-utils": "^12.1.0",
+    "@ckeditor/ckeditor5-core": "^12.2.1",
+    "@ckeditor/ckeditor5-engine": "^13.2.1",
+    "@ckeditor/ckeditor5-ui": "^13.0.2",
+    "@ckeditor/ckeditor5-utils": "^13.0.1",
     "lodash-es": "^4.17.10"
   },
   "devDependencies": {
-    "@ckeditor/ckeditor5-basic-styles": "^11.1.0",
-    "@ckeditor/ckeditor5-enter": "^11.0.1",
-    "@ckeditor/ckeditor5-heading": "^11.0.1",
-    "@ckeditor/ckeditor5-paragraph": "^11.0.1",
-    "@ckeditor/ckeditor5-typing": "^12.0.1",
-    "@ckeditor/ckeditor5-undo": "^11.0.1",
+    "@ckeditor/ckeditor5-basic-styles": "^11.1.3",
+    "@ckeditor/ckeditor5-enter": "^11.0.4",
+    "@ckeditor/ckeditor5-heading": "^11.0.4",
+    "@ckeditor/ckeditor5-paragraph": "^11.0.4",
+    "@ckeditor/ckeditor5-typing": "^12.1.1",
+    "@ckeditor/ckeditor5-undo": "^11.0.4",
     "eslint": "^5.5.0",
-    "eslint-config-ckeditor5": "^1.0.11",
+    "eslint-config-ckeditor5": "^2.0.0",
     "husky": "^1.3.1",
     "lint-staged": "^7.0.0"
   },

+ 13 - 2
packages/ckeditor5-editor-balloon/src/ballooneditor.js

@@ -199,6 +199,16 @@ export default class BalloonEditor extends Editor {
 	 */
 	static create( sourceElementOrData, config = {} ) {
 		return new Promise( resolve => {
+			const isHTMLElement = isElement( sourceElementOrData );
+
+			if ( isHTMLElement && sourceElementOrData.tagName === 'TEXTAREA' ) {
+				// Documented in core/editor/editor.js
+				throw new CKEditorError(
+					'editor-wrong-element: This type of editor cannot be initialized inside <textarea> element.',
+					null
+				);
+			}
+
 			const editor = new this( sourceElementOrData, config );
 
 			resolve(
@@ -207,11 +217,12 @@ export default class BalloonEditor extends Editor {
 						editor.ui.init();
 					} )
 					.then( () => {
-						if ( !isElement( sourceElementOrData ) && config.initialData ) {
+						if ( !isHTMLElement && config.initialData ) {
 							// Documented in core/editor/editorconfig.jdoc.
 							throw new CKEditorError(
 								'editor-create-initial-data: ' +
-								'The config.initialData option cannot be used together with initial data passed in Editor.create().'
+								'The config.initialData option cannot be used together with initial data passed in Editor.create().',
+								null
 							);
 						}
 

+ 1 - 1
packages/ckeditor5-editor-balloon/src/ballooneditorui.js

@@ -65,7 +65,7 @@ export default class BalloonEditorUI extends EditorUI {
 
 		// Register the editable UI view in the editor. A single editor instance can aggregate multiple
 		// editable areas (roots) but the balloon editor has only one.
-		this._editableElements.set( editable.name, editableElement );
+		this.setEditableElement( editable.name, editableElement );
 
 		// Let the global focus tracker know that the editable UI element is focusable and
 		// belongs to the editor. From now on, the focus tracker will sustain the editor focus

+ 35 - 37
packages/ckeditor5-editor-balloon/tests/ballooneditor.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
-/* globals document, Event */
+/* globals document, console */
 
 import BalloonEditorUI from '../src/ballooneditorui';
 import BalloonEditorUIView from '../src/ballooneditoruiview';
@@ -21,10 +21,10 @@ import RootElement from '@ckeditor/ckeditor5-engine/src/model/rootelement';
 
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
-import log from '@ckeditor/ckeditor5-utils/src/log';
 
 import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
 import { describeMemoryUsage, testMemoryUsage } from '@ckeditor/ckeditor5-core/tests/_utils/memory';
+import { assertCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'BalloonEditor', () => {
 	let editor, editorElement;
@@ -37,7 +37,7 @@ describe( 'BalloonEditor', () => {
 
 		document.body.appendChild( editorElement );
 
-		testUtils.sinon.stub( log, 'warn' ).callsFake( () => {} );
+		testUtils.sinon.stub( console, 'warn' ).callsFake( () => {} );
 	} );
 
 	afterEach( () => {
@@ -76,37 +76,6 @@ describe( 'BalloonEditor', () => {
 			expect( editor.model.document.getRoot( 'main' ) ).to.instanceof( RootElement );
 		} );
 
-		it( 'handles form element', () => {
-			const form = document.createElement( 'form' );
-			const textarea = document.createElement( 'textarea' );
-			form.appendChild( textarea );
-			document.body.appendChild( form );
-
-			// Prevents page realods in Firefox ;|
-			form.addEventListener( 'submit', evt => {
-				evt.preventDefault();
-			} );
-
-			return BalloonEditor.create( textarea, {
-				plugins: [ Paragraph ]
-			} ).then( editor => {
-				expect( textarea.value ).to.equal( '' );
-
-				editor.setData( '<p>Foo</p>' );
-
-				form.dispatchEvent( new Event( 'submit', {
-					// We need to be able to do preventDefault() to prevent page reloads in Firefox.
-					cancelable: true
-				} ) );
-
-				expect( textarea.value ).to.equal( '<p>Foo</p>' );
-
-				return editor.destroy().then( () => {
-					form.remove();
-				} );
-			} );
-		} );
-
 		it( 'should have undefined the #sourceElement if editor was initialized with data', () => {
 			return BalloonEditor
 				.create( '<p>Foo.</p>', {
@@ -214,9 +183,21 @@ describe( 'BalloonEditor', () => {
 			BalloonEditor.create( '<p>Hello world!</p>', {
 				initialData: '<p>I am evil!</p>',
 				plugins: [ Paragraph ]
-			} ).catch( () => {
-				done();
-			} );
+			} )
+				.then(
+					() => {
+						expect.fail( 'Balloon editor should throw an error when both initial data are passed' );
+					},
+					err => {
+						assertCKEditorError( err,
+							// eslint-disable-next-line max-len
+							/^editor-create-initial-data: The config\.initialData option cannot be used together with initial data passed in Editor\.create\(\)\./,
+							null
+						);
+					}
+				)
+				.then( done )
+				.catch( done );
 		} );
 
 		// ckeditor/ckeditor5-editor-classic#53
@@ -245,6 +226,23 @@ describe( 'BalloonEditor', () => {
 					return newEditor.destroy();
 				} );
 		} );
+
+		it( 'throws an error when is initialized in textarea', done => {
+			BalloonEditor.create( document.createElement( 'textarea' ) )
+				.then(
+					() => {
+						expect.fail( 'Balloon editor should throw an error when is initialized in textarea.' );
+					},
+					err => {
+						assertCKEditorError( err,
+							/^editor-wrong-element: This type of editor cannot be initialized inside <textarea> element\./,
+							null
+						);
+					}
+				)
+				.then( done )
+				.catch( done );
+		} );
 	} );
 
 	describe( 'create - events', () => {

+ 2 - 2
packages/ckeditor5-editor-balloon/tests/ballooneditorui.js

@@ -14,7 +14,7 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 import { isElement } from 'lodash-es';
 
-import utils from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
+import { assertBinding } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
 describe( 'BalloonEditorUI', () => {
@@ -104,7 +104,7 @@ describe( 'BalloonEditorUI', () => {
 			} );
 
 			it( 'binds view.editable#isFocused', () => {
-				utils.assertBinding(
+				assertBinding(
 					view.editable,
 					{ isFocused: false },
 					[

+ 2 - 2
packages/ckeditor5-editor-balloon/tests/manual/ballooneditor.js

@@ -7,7 +7,7 @@
 
 import BalloonEditor from '../../src/ballooneditor';
 import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
-import testUtils from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
+import { createObserver } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 window.editors = {};
 window.editables = [];
@@ -33,7 +33,7 @@ function initEditors() {
 				window.editors[ selector ] = editor;
 				window.editables.push( editor.editing.view.document.getRoot() );
 
-				const observer = testUtils.createObserver();
+				const observer = createObserver();
 
 				observer.observe(
 					`${ selector }.ui.focusTracker`,

+ 7 - 7
packages/ckeditor5-editor-balloon/tests/manual/memory.js

@@ -3,13 +3,11 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
-/* globals console:false, document, window */
+/* globals console:false, document */
 
 import BalloonEditor from '../../src/ballooneditor';
 import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
 
-window.editors = {};
-
 /*
  * Memory-leak safe version of balloon editor manual test does not:
  * - define global variables (such as let editor; in main file scope)
@@ -17,6 +15,8 @@ window.editors = {};
  * - add event listeners with () => {} methods which reference other
  */
 function initEditors() {
+	const editors = {};
+
 	init( '#editor-1' );
 	init( '#editor-2' );
 
@@ -59,7 +59,7 @@ function initEditors() {
 				}
 			} )
 			.then( editor => {
-				window.editors[ selector ] = editor;
+				editors[ selector ] = editor;
 			} )
 			.catch( err => {
 				console.error( err.stack );
@@ -67,9 +67,9 @@ function initEditors() {
 	}
 
 	function destroyEditors() {
-		for ( const selector in window.editors ) {
-			window.editors[ selector ].destroy().then( () => {
-				window.editors[ selector ] = undefined;
+		for ( const selector in editors ) {
+			editors[ selector ].destroy().then( () => {
+				editors[ selector ] = undefined;
 			} );
 		}