8
0
Просмотр исходного кода

Internal: Changed code and tests after dropping StandardEditor class.

Oskar Wróbel 8 лет назад
Родитель
Сommit
4fed1e78af

+ 21 - 5
packages/ckeditor5-editor-balloon/src/ballooneditor.js

@@ -7,12 +7,16 @@
  * @module editor-balloon/ballooneditor
  */
 
-import StandardEditor from '@ckeditor/ckeditor5-core/src/editor/standardeditor';
+import Editor from '@ckeditor/ckeditor5-core/src/editor/editor';
 import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
 import ContextualToolbar from '@ckeditor/ckeditor5-ui/src/toolbar/contextual/contextualtoolbar';
 import BalloonEditorUI from './ballooneditorui';
 import BalloonEditorUIView from './ballooneditoruiview';
 import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement';
+import DataInterface from '@ckeditor/ckeditor5-core/src/editor/utils/datainterface';
+import ElementInterface from '@ckeditor/ckeditor5-core/src/editor/utils/elementinterface';
+import attachToForm from '@ckeditor/ckeditor5-core/src/editor/utils/attachtoform';
+import mix from '@ckeditor/ckeditor5-utils/src/mix';
 
 /**
  * The {@glink builds/guides/overview#Balloon-editor balloon editor} implementation (Medium-like editor).
@@ -36,9 +40,11 @@ import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement
  * Read more about initializing the editor from source or as a build in
  * {@link module:editor-balloon/ballooneditor~BalloonEditor#create `BalloonEditor.create()`}.
  *
- * @extends module:core/editor/standardeditor~StandardEditor
+ * @mixes module:core/editor/utils/datainterface~DataInterface
+ * @mixes module:core/editor/utils/elementinterface~ElementInterface
+ * @extends module:core/editor/editor~Editor
  */
-export default class BalloonEditor extends StandardEditor {
+export default class BalloonEditor extends Editor {
 	/**
 	 * Creates an instance of the balloon editor.
 	 *
@@ -51,13 +57,20 @@ export default class BalloonEditor extends StandardEditor {
 	 * @param {module:core/editor/editorconfig~EditorConfig} config The editor configuration.
 	 */
 	constructor( element, config ) {
-		super( element, config );
+		super( config );
+
+		this.element = element;
 
 		this.config.get( 'plugins' ).push( ContextualToolbar );
 		this.config.define( 'contextualToolbar', this.config.get( 'toolbar' ) );
 
 		this.data.processor = new HtmlDataProcessor();
+
+		this.model.document.createRoot();
+
 		this.ui = new BalloonEditorUI( this, new BalloonEditorUIView( this.locale, element ) );
+
+		attachToForm( this );
 	}
 
 	/**
@@ -128,7 +141,7 @@ export default class BalloonEditor extends StandardEditor {
 						editor.ui.init();
 						editor.fire( 'uiReady' );
 					} )
-					.then( () => editor.loadDataFromEditorElement() )
+					.then( () => editor.loadDataFromElement() )
 					.then( () => {
 						editor.fire( 'dataReady' );
 						editor.fire( 'ready' );
@@ -138,3 +151,6 @@ export default class BalloonEditor extends StandardEditor {
 		} );
 	}
 }
+
+mix( BalloonEditor, DataInterface );
+mix( BalloonEditor, ElementInterface );

+ 47 - 1
packages/ckeditor5-editor-balloon/tests/ballooneditor.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-/* globals document */
+/* globals document, Event */
 
 import BalloonEditorUI from '../src/ballooneditorui';
 import BalloonEditorUIView from '../src/ballooneditoruiview';
@@ -17,6 +17,9 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
 import ContextualToolbar from '@ckeditor/ckeditor5-ui/src/toolbar/contextual/contextualtoolbar';
+import DataInterface from '@ckeditor/ckeditor5-core/src/editor/utils/datainterface';
+import ElementInterface from '@ckeditor/ckeditor5-core/src/editor/utils/elementinterface';
+import RootElement from '@ckeditor/ckeditor5-engine/src/model/rootelement';
 
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
@@ -55,6 +58,49 @@ describe( 'BalloonEditor', () => {
 		it( 'uses HTMLDataProcessor', () => {
 			expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );
 		} );
+
+		it( 'has a Data Interface', () => {
+			testUtils.isMixed( BalloonEditor, DataInterface );
+		} );
+
+		it( 'has a Element Interface', () => {
+			testUtils.isMixed( BalloonEditor, ElementInterface );
+		} );
+
+		it( 'creates main root element', () => {
+			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();
+				} );
+			} );
+		} );
 	} );
 
 	describe( 'create()', () => {