Ver código fonte

Internal: Changed code and tests after dropping StandardEditor class.

Oskar Wróbel 8 anos atrás
pai
commit
ef9e133250

+ 21 - 5
packages/ckeditor5-editor-inline/src/inlineeditor.js

@@ -7,11 +7,15 @@
  * @module editor-inline/inlineeditor
  */
 
-import StandardEditor from '@ckeditor/ckeditor5-core/src/editor/standardeditor';
+import Editor from '@ckeditor/ckeditor5-core/src/editor/editor';
+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 HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
 import InlineEditorUI from './inlineeditorui';
 import InlineEditorUIView from './inlineeditoruiview';
 import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement';
+import mix from '@ckeditor/ckeditor5-utils/src/mix';
 
 /**
  * The {@glink builds/guides/overview#Inline-editor inline editor} implementation.
@@ -35,9 +39,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-inline/inlineeditor~InlineEditor#create `InlineEditor.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 InlineEditor extends StandardEditor {
+export default class InlineEditor extends Editor {
 	/**
 	 * Creates an instance of the inline editor.
 	 *
@@ -50,10 +56,17 @@ export default class InlineEditor extends StandardEditor {
 	 * @param {module:core/editor/editorconfig~EditorConfig} config The editor configuration.
 	 */
 	constructor( element, config ) {
-		super( element, config );
+		super( config );
+
+		this.element = element;
 
 		this.data.processor = new HtmlDataProcessor();
+
+		this.model.document.createRoot();
+
 		this.ui = new InlineEditorUI( this, new InlineEditorUIView( this.locale, element ) );
+
+		attachToForm( this );
 	}
 
 	/**
@@ -124,7 +137,7 @@ export default class InlineEditor extends StandardEditor {
 						editor.ui.init();
 						editor.fire( 'uiReady' );
 					} )
-					.then( () => editor.loadDataFromEditorElement() )
+					.then( () => editor.loadDataFromElement() )
 					.then( () => {
 						editor.fire( 'dataReady' );
 						editor.fire( 'ready' );
@@ -134,3 +147,6 @@ export default class InlineEditor extends StandardEditor {
 		} );
 	}
 }
+
+mix( InlineEditor, DataInterface );
+mix( InlineEditor, ElementInterface );

+ 47 - 1
packages/ckeditor5-editor-inline/tests/inlineeditor.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-/* globals document */
+/* globals document, Event */
 
 import InlineEditorUI from '../src/inlineeditorui';
 import InlineEditorUIView from '../src/inlineeditoruiview';
@@ -16,6 +16,9 @@ import InlineEditor from '../src/inlineeditor';
 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 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';
 
@@ -48,6 +51,49 @@ describe( 'InlineEditor', () => {
 		it( 'uses HTMLDataProcessor', () => {
 			expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );
 		} );
+
+		it( 'has a Data Interface', () => {
+			testUtils.isMixed( InlineEditor, DataInterface );
+		} );
+
+		it( 'has a Element Interface', () => {
+			testUtils.isMixed( InlineEditor, 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 InlineEditor.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()', () => {