Selaa lähdekoodia

Removed StandardEditor class.

Oskar Wróbel 8 vuotta sitten
vanhempi
sitoutus
5439d121ea

+ 0 - 151
packages/ckeditor5-core/src/editor/standardeditor.js

@@ -1,151 +0,0 @@
-/**
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/**
- * @module core/editor/standardeditor
- */
-
-import Editor from './editor';
-import isFunction from '@ckeditor/ckeditor5-utils/src/lib/lodash/isFunction';
-
-import getDataFromElement from '@ckeditor/ckeditor5-utils/src/dom/getdatafromelement';
-import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement';
-
-/**
- * The standard editor class, extending base editor by adding methods needed in the typical
- * editor implementations: editor with a single editable area created based on the DOM element.
- * It provides base API to manage data and to integrate the editor with the form when it is
- * initialized on the textarea element.
- *
- * @extends module:core/editor/editor~Editor
- */
-export default class StandardEditor extends Editor {
-	/**
-	 * Creates a new instance of the standard editor.
-	 *
-	 * @param {HTMLElement} element The DOM element that will be the source
-	 * for the created editor.
-	 * @param {Object} config The editor config.
-	 */
-	constructor( element, config ) {
-		super( config );
-
-		/**
-		 * The element on which the editor has been initialized.
-		 *
-		 * @readonly
-		 * @member {HTMLElement}
-		 */
-		this.element = element;
-
-		/**
-		 * Editor UI instance.
-		 *
-		 * This property is set by more specialized editor constructors. However, it's required
-		 * for plugins to work (their UI-related part will try to interact with editor UI),
-		 * so every editor class which is meant to work with default plugins should set this property.
-		 *
-		 * @readonly
-		 * @member {module:core/editor/editorui~EditorUI} #ui
-		 */
-
-		this._attachToForm();
-	}
-
-	/**
-	 * Sets the data in the editor's main root.
-	 *
-	 * @param {*} data The data to load.
-	 */
-	setData( data ) {
-		this.data.set( data );
-	}
-
-	/**
-	 * Gets the data from the editor's main root.
-	 */
-	getData() {
-		return this.data.get();
-	}
-
-	/**
-	 * Updates the {@link #element editor element}'s content with the data.
-	 */
-	updateEditorElement() {
-		setDataInElement( this.element, this.getData() );
-	}
-
-	/**
-	 * Loads the data from the {@link #element editor element} to the main root.
-	 */
-	loadDataFromEditorElement() {
-		this.setData( getDataFromElement( this.element ) );
-	}
-
-	/**
-	 * Checks if editor is initialized on textarea element that belongs to a form. If yes - updates editor's element
-	 * contents before submitting the form.
-	 *
-	 * @private
-	 */
-	_attachToForm() {
-		const element = this.element;
-
-		// Only when replacing a textarea which is inside of a form element.
-		if ( element && element.tagName.toLowerCase() === 'textarea' && element.form ) {
-			let originalSubmit;
-			const form = element.form;
-			const onSubmit = () => this.updateEditorElement();
-
-			// Replace the original form#submit() to call a custom submit function first.
-			// Check if #submit is a function because the form might have an input named "submit".
-			if ( isFunction( form.submit ) ) {
-				originalSubmit = form.submit;
-
-				form.submit = () => {
-					onSubmit();
-					originalSubmit.apply( form );
-				};
-			}
-
-			// Update the replaced textarea with data before each form#submit event.
-			form.addEventListener( 'submit', onSubmit );
-
-			// Remove the submit listener and revert the original submit method on
-			// editor#destroy.
-			this.on( 'destroy', () => {
-				form.removeEventListener( 'submit', onSubmit );
-
-				if ( originalSubmit ) {
-					form.submit = originalSubmit;
-				}
-			} );
-		}
-	}
-
-	/**
-	 * Creates a standard editor instance.
-	 *
-	 * @param {HTMLElement} element See {@link module:core/editor/standardeditor~StandardEditor}'s param.
-	 * @param {Object} config The editor config. You can find the list of config options in
-	 * {@link module:core/editor/editorconfig~EditorConfig}.
-	 * @returns {Promise} Promise resolved once editor is ready.
-	 * @returns {module:core/editor/standardeditor~StandardEditor} return.editor The editor instance.
-	 */
-	static create( element, config ) {
-		return new Promise( resolve => {
-			const editor = new this( element, config );
-
-			resolve(
-				editor.initPlugins()
-					.then( () => {
-						editor.fire( 'dataReady' );
-						editor.fire( 'ready' );
-					} )
-					.then( () => editor )
-			);
-		} );
-	}
-}

+ 0 - 330
packages/ckeditor5-core/tests/editor/standardeditor.js

@@ -1,330 +0,0 @@
-/**
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/* globals document, Event */
-
-import Editor from '../../src/editor/editor';
-import StandardEditor from '../../src/editor/standardeditor';
-import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
-import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-
-import Plugin from '../../src/plugin';
-
-describe( 'StandardEditor', () => {
-	let editorElement;
-
-	beforeEach( () => {
-		editorElement = document.createElement( 'div' );
-		document.body.appendChild( editorElement );
-	} );
-
-	describe( 'constructor()', () => {
-		it( 'sets all properties', () => {
-			const editor = new StandardEditor( editorElement, { foo: 1 } );
-
-			expect( editor ).to.have.property( 'element', editorElement );
-		} );
-
-		it( 'sets config', () => {
-			const editor = new StandardEditor( editorElement, { foo: 1 } );
-
-			expect( editor.config.get( 'foo' ) ).to.equal( 1 );
-		} );
-	} );
-
-	describe( 'destroy()', () => {
-		it( 'returns a Promise', () => {
-			const editor = new StandardEditor( editorElement, { foo: 1 } );
-
-			expect( editor.destroy() ).to.be.an.instanceof( Promise );
-		} );
-
-		it( 'destroys the parent', () => {
-			const editor = new StandardEditor( editorElement, { foo: 1 } );
-			const spy = sinon.spy( Editor.prototype, 'destroy' );
-
-			sinon.assert.notCalled( spy );
-
-			return editor.destroy()
-				.then( () => {
-					sinon.assert.calledOnce( spy );
-				} );
-		} );
-	} );
-
-	describe( 'create()', () => {
-		it( 'initializes editor with plugins and config', () => {
-			class PluginFoo extends Plugin {}
-
-			return StandardEditor.create( editorElement, { foo: 1, plugins: [ PluginFoo ] } )
-				.then( editor => {
-					expect( editor ).to.be.instanceof( StandardEditor );
-
-					expect( editor.config.get( 'foo' ) ).to.equal( 1 );
-					expect( editor ).to.have.property( 'element', editorElement );
-
-					expect( editor.plugins.get( PluginFoo ) ).to.be.instanceof( PluginFoo );
-				} );
-		} );
-
-		it( 'fires all events in the right order', () => {
-			const fired = [];
-
-			function spy( evt ) {
-				fired.push( evt.name );
-			}
-
-			class EventWatcher extends Plugin {
-				init() {
-					this.editor.on( 'pluginsReady', spy );
-					this.editor.on( 'dataReady', spy );
-					this.editor.on( 'ready', spy );
-				}
-			}
-
-			return StandardEditor.create( editorElement, { plugins: [ EventWatcher ] } )
-				.then( () => {
-					expect( fired ).to.deep.equal( [ 'pluginsReady', 'dataReady', 'ready' ] );
-				} );
-		} );
-	} );
-
-	describe( 'setData()', () => {
-		let editor;
-
-		beforeEach( () => {
-			return StandardEditor.create( editorElement )
-				.then( newEditor => {
-					editor = newEditor;
-
-					editor.data.processor = new HtmlDataProcessor();
-
-					editor.model.schema.extend( '$text', { allowIn: '$root' } );
-				} );
-		} );
-
-		it( 'should set data of the first root', () => {
-			editor.model.document.createRoot( '$root', 'secondRoot' );
-
-			editor.setData( 'foo' );
-
-			expect( getData( editor.model, { rootName: 'main', withoutSelection: true } ) ).to.equal( 'foo' );
-		} );
-	} );
-
-	describe( 'getData()', () => {
-		let editor;
-
-		beforeEach( () => {
-			return StandardEditor.create( editorElement )
-				.then( newEditor => {
-					editor = newEditor;
-
-					editor.data.processor = new HtmlDataProcessor();
-
-					editor.model.schema.extend( '$text', { allowIn: '$root' } );
-				} );
-		} );
-
-		it( 'should get data of the first root', () => {
-			editor.model.document.createRoot( '$root', 'secondRoot' );
-
-			setData( editor.model, 'foo' );
-
-			expect( editor.getData() ).to.equal( 'foo' );
-		} );
-	} );
-
-	describe( 'updateEditorElement()', () => {
-		it( 'sets data to editor element', () => {
-			const editor = new StandardEditor( editorElement );
-
-			editor.data.get = () => '<p>foo</p>';
-
-			editor.updateEditorElement();
-
-			expect( editorElement.innerHTML ).to.equal( '<p>foo</p>' );
-		} );
-	} );
-
-	describe( 'loadDataFromEditorElement()', () => {
-		it( 'sets data to editor element', () => {
-			const editor = new StandardEditor( editorElement );
-
-			sinon.stub( editor.data, 'set' );
-			editorElement.innerHTML = '<p>foo</p>';
-
-			editor.loadDataFromEditorElement();
-
-			expect( editor.data.set.calledWithExactly( '<p>foo</p>' ) ).to.be.true;
-		} );
-	} );
-
-	describe( 'attaching to a form', () => {
-		let editor, form, textarea, submitStub;
-
-		beforeEach( () => {
-			form = document.createElement( 'form' );
-			textarea = document.createElement( 'textarea' );
-			form.appendChild( textarea );
-			document.body.appendChild( form );
-			submitStub = sinon.stub( form, 'submit' );
-
-			// Prevents page realods in Firefox ;|
-			form.addEventListener( 'submit', evt => {
-				evt.preventDefault();
-			} );
-		} );
-
-		afterEach( () => {
-			submitStub.restore();
-			form.remove();
-		} );
-
-		it( 'should update editor#element after calling the submit() method', () => {
-			return createEditor( textarea )
-				.then( editor => {
-					expect( textarea.value ).to.equal( '' );
-
-					// Submit method is replaced by our implementation.
-					expect( form.submit ).to.not.equal( submitStub );
-					form.submit();
-
-					expect( textarea.value ).to.equal( '<p>foo</p>' );
-					sinon.assert.calledOnce( submitStub );
-
-					// Check if original function was called in correct context.
-					sinon.assert.calledOn( submitStub, form );
-
-					return editor.destroy();
-				} );
-		} );
-
-		it( 'should update editor#element after the "submit" event', () => {
-			return createEditor( textarea )
-				.then( editor => {
-					expect( textarea.value ).to.equal( '' );
-
-					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();
-				} );
-		} );
-
-		it( 'should not update editor#element if it is not a textarea in a form', () => {
-			const element = document.createElement( 'div' );
-			form.appendChild( element );
-
-			return createEditor( element )
-				.then( editor => {
-					expect( textarea.value ).to.equal( '' );
-
-					// Submit method is not replaced by our implementation.
-					expect( form.submit ).to.equal( submitStub );
-					form.submit();
-
-					expect( textarea.value ).to.equal( '' );
-
-					return editor.destroy();
-				} )
-				.then( () => {
-					element.remove();
-				} );
-		} );
-
-		it( 'should not update editor#element not belonging to a form', () => {
-			const textarea = document.createElement( 'textarea' );
-			document.body.appendChild( textarea );
-
-			return createEditor( textarea )
-				.then( editor => {
-					expect( textarea.value ).to.equal( '' );
-
-					// Submit method is not replaced by our implementation.
-					expect( form.submit ).to.equal( submitStub );
-					form.submit();
-
-					expect( textarea.value ).to.equal( '' );
-
-					return editor.destroy();
-				} )
-				.then( () => {
-					textarea.remove();
-				} );
-		} );
-
-		it( 'should not update editor#element after destruction of the editor - form.submit()', () => {
-			return createEditor( textarea )
-				.then( editor => editor.destroy() )
-				.then( () => {
-					expect( textarea.value ).to.equal( '' );
-
-					// Submit method is no longer replaced by our implementation.
-					expect( form.submit ).to.equal( submitStub );
-					form.submit();
-
-					expect( textarea.value ).to.equal( '' );
-				} );
-		} );
-
-		it( 'should not update the editor#element after destruction of the editor - "submit" event', () => {
-			return createEditor( textarea )
-				.then( editor => editor.destroy() )
-				.then( () => {
-					expect( textarea.value ).to.equal( '' );
-
-					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( '' );
-				} );
-		} );
-
-		it( 'should not replace submit() method when one of the elements in a form is named "submit"', () => {
-			// Restore stub since we want to mask submit function with input with name="submit".
-			submitStub.restore();
-
-			const input = document.createElement( 'input' );
-			input.setAttribute( 'name', 'submit' );
-			form.appendChild( input );
-
-			return createEditor( textarea )
-				.then( () => {
-					expect( form.submit ).to.equal( input );
-					expect( textarea.value ).to.equal( '' );
-
-					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( () => {
-					expect( form.submit ).to.equal( input );
-					input.remove();
-				} );
-		} );
-
-		function createEditor( element ) {
-			return StandardEditor.create( element )
-				.then( newEditor => {
-					editor = newEditor;
-					editor.data.get = () => '<p>foo</p>';
-
-					return editor;
-				} );
-		}
-	} );
-} );