Procházet zdrojové kódy

Merge branch 'master' into t/ckeditor5-ui-default/12

Piotrek Koszuliński před 9 roky
rodič
revize
e5b06c1864

+ 1 - 1
package.json

@@ -51,7 +51,7 @@
     "gulp-sourcemaps": "^1.6.0",
     "gulp-svg-sprite": "^1.2.19",
     "gulp-util": "^3.0.7",
-    "gulp-watch": "^4.3.5",
+    "gulp-watch": "4.3.5",
     "guppy-pre-commit": "^0.3.0",
     "inquirer": "^0.11.0",
     "istanbul": "^0.4.1",

+ 14 - 13
src/command/attributecommand.js

@@ -6,17 +6,17 @@
 'use strict';
 
 import Command from './command.js';
-import TreeWalker from '../engine/treemodel/treewalker.js';
-import Range from '../engine/treemodel/range.js';
+import TreeWalker from '../engine/model/treewalker.js';
+import Range from '../engine/model/range.js';
 
 /**
  * An extension of basic {@link ckeditor5.command.Command} class, which provides utilities for a command that sets a single
- * attribute on a text or element with value `true`. AttributeCommand uses {@link engine.treeModel.Document#selection} to
+ * attribute on a text or element with value `true`. AttributeCommand uses {@link engine.model.Document#selection} to
  * decide which nodes (if any) should be changed, and applies or removes attributes from them.
- * See {@link engine.treeView.Converter#execute} for more.
+ * See {@link engine.view.Converter#execute} for more.
  *
- * The command checks {@link engine.treeModel.Document#schema} to decide if it should be enabled.
- * See {@link engine.treeView.Converter#checkSchema} for more.
+ * The command checks {@link engine.model.Document#schema} to decide if it should be enabled.
+ * See {@link engine.view.Converter#checkSchema} for more.
  *
  * @memberOf ckeditor5.command
  */
@@ -40,6 +40,7 @@ export default class AttributeCommand extends Command {
 		 * Flag indicating whether command is active. For collapsed selection it means that typed characters will have
 		 * the command's attribute set. For range selection it means that all nodes inside have the attribute applied.
 		 *
+		 * @observable
 		 * @member {Boolean} ckeditor5.command.AttributeCommand#value
 		 */
 		this.set( 'value', false );
@@ -50,7 +51,7 @@ export default class AttributeCommand extends Command {
 	}
 
 	/**
-	 * Checks {@link engine.treeModel.Document#schema} to decide if the command should be enabled:
+	 * Checks {@link engine.model.Document#schema} to decide if the command should be enabled:
 	 * * if selection is on range, the command is enabled if any of nodes in that range can have bold,
 	 * * if selection is collapsed, the command is enabled if text with bold is allowed in that node.
 	 *
@@ -75,7 +76,7 @@ export default class AttributeCommand extends Command {
 
 				// Walk the range.
 				while ( !step.done ) {
-					// If returned item does not have name property, it is a treeModel.TextFragment.
+					// If returned item does not have name property, it is a model.TextFragment.
 					const name = step.value.item.name || '$text';
 
 					if ( schema.check( { name: name, inside: last, attributes: this.attributeKey } ) ) {
@@ -98,10 +99,10 @@ export default class AttributeCommand extends Command {
 	 *
 	 * If the command is active (`value == true`), it will remove attributes. Otherwise, it will set attributes.
 	 *
-	 * The execution result differs, depending on the {@link engine.treeModel.Document#selection}:
+	 * The execution result differs, depending on the {@link engine.model.Document#selection}:
 	 * * if selection is on a range, the command applies the attribute on all nodes in that ranges
-	 * (if they are allowed to have this attribute by the{@link engine.treeModel.Schema schema}),
-	 * * if selection is collapsed in non-empty node, the command applies attribute to the {@link engine.treeModel.Document#selection}
+	 * (if they are allowed to have this attribute by the{@link engine.model.Schema schema}),
+	 * * if selection is collapsed in non-empty node, the command applies attribute to the {@link engine.model.Document#selection}
 	 * itself (note that typed characters copy attributes from selection),
 	 * * if selection is collapsed in empty node, the command applies attribute to the parent node of selection (note
 	 * that selection inherits all attributes from a node if it is in empty node).
@@ -147,8 +148,8 @@ export default class AttributeCommand extends Command {
 	 * attribute set. This is done by breaking a range in two and omitting the not allowed part.
 	 *
 	 * @private
-	 * @param {Array.<engine.treeModel.Range>} ranges Ranges to be validated.
-	 * @returns {Array.<engine.treeModel.Range>} Ranges without invalid parts.
+	 * @param {Array.<engine.model.Range>} ranges Ranges to be validated.
+	 * @returns {Array.<engine.model.Range>} Ranges without invalid parts.
 	 */
 	_getSchemaValidRanges( ranges ) {
 		const validRanges = [];

+ 2 - 1
src/command/command.js

@@ -40,6 +40,7 @@ export default class Command {
 		 * Flag indicating whether a command is enabled or disabled.
 		 * A disabled command should do nothing upon it's execution.
 		 *
+		 * @observable
 		 * @member {Boolean} ckeditor5.command.Command#isEnabled
 		 */
 		this.set( 'isEnabled', true );
@@ -121,7 +122,7 @@ export default class Command {
 	 *
 	 * @protected
 	 * @method ckeditor5.command.Command#_checkEnabled
-	 * @returns {Boolean} `true` if command should be enabled according to {@link engine.treeModel.Document#schema}. `false` otherwise.
+	 * @returns {Boolean} `true` if command should be enabled according to {@link engine.model.Document#schema}. `false` otherwise.
 	 */
 }
 

+ 12 - 10
src/creator/standardcreator.js

@@ -7,10 +7,10 @@
 
 import Creator from './creator.js';
 
-import Document from '../engine/treemodel/document.js';
-import DataController from '../engine/treecontroller/datacontroller.js';
-import EditingController from '../engine/treecontroller/editingcontroller.js';
-
+import Document from '../engine/model/document.js';
+import DataController from '../engine/datacontroller.js';
+import EditingController from '../engine/editingcontroller.js';
+import HtmlDataProcessor from '../engine/dataprocessor/htmldataprocessor.js';
 /**
  * Standard creator for browser environment.
  *
@@ -19,14 +19,16 @@ import EditingController from '../engine/treecontroller/editingcontroller.js';
  */
 export default class StandardCreator extends Creator {
 	/**
-	 * Creates an instance of the standard creator. Initializes the engine ({@link engine.treeModel.Document document},
-	 * {@link engine.treeController.EditingController editing controller} and
-	 * {@link engine.treeController.DataController data controller}).
+	 * Creates an instance of the standard creator. Initializes the engine ({@link engine.model.Document document},
+	 * {@link engine.EditingController editing controller} and
+	 * {@link engine.DataController data controller}).
 	 *
-	 * @param {ckeditor5.Editor} The editor instance.
-	 * @param {engine.dataProcessor.DataProcessor} The data processor to use.
+	 * @param {ckeditor5.Editor} editor The editor instance.
+	 * @param {engine.dataProcessor.DataProcessor} [dataProcessor=engine.dataProcessor.HtmlDataProcessor] The data
+	 * processor to use. If no data processor is provided {@link engine.dataProcessor.HtmlDataProcessor HtmlDataProcessor}
+	 * will be used.
 	 */
-	constructor( editor, dataProcessor ) {
+	constructor( editor, dataProcessor = new HtmlDataProcessor() ) {
 		super( editor );
 
 		editor.document = new Document();

+ 2 - 2
src/editable.js

@@ -7,7 +7,7 @@
 
 import mix from './utils/mix.js';
 import ObservableMixin from './utils/observablemixin.js';
-import FocusObserver from './engine/treeview/observer/focusobserver.js';
+import FocusObserver from './engine/view/observer/focusobserver.js';
 
 /**
  * Class representing a single editable element. It combines the {@link ckeditor5.Editable#viewElement editable view}
@@ -68,7 +68,7 @@ export default class Editable {
 		 * The view element which holds this editable.
 		 *
 		 * @readonly
-		 * @member {engine.treeView.Element} ckeditor5.Editable#viewElement
+		 * @member {engine.view.Element} ckeditor5.Editable#viewElement
 		 */
 	}
 

+ 6 - 6
src/editor.js

@@ -101,25 +101,25 @@ export default class Editor {
 		 * This property is set by the {@link ckeditor5.creator.Creator}.
 		 *
 		 * @readonly
-		 * @member {engine.treeModel.Document} ckeditor5.Editor#document
+		 * @member {engine.model.Document} ckeditor5.Editor#document
 		 */
 
 		/**
-		 * Instance of the {@link engine.treecontroller.EditingController editing controller}.
+		 * Instance of the {@link engine.EditingController editing controller}.
 		 *
 		 * This property is set by the {@link ckeditor5.creator.Creator}.
 		 *
 		 * @readonly
-		 * @member {engine.treecontroller.EditingController} ckeditor5.Editor#editing
+		 * @member {engine.EditingController} ckeditor5.Editor#editing
 		 */
 
 		/**
-		 * Instance of the {@link engine.treecontroller.DataController data controller}.
+		 * Instance of the {@link engine.DataController data controller}.
 		 *
 		 * This property is set by the {@link ckeditor5.creator.Creator}.
 		 *
 		 * @readonly
-		 * @member {engine.treecontroller.DataController} ckeditor5.Editor#data
+		 * @member {engine.DataController} ckeditor5.Editor#data
 		 */
 
 		/**
@@ -258,7 +258,7 @@ export default class Editor {
 			throw new CKEditorError( 'editor-no-datacontroller: Data controller has not been defined yet.' );
 		}
 
-		this.data.set( editableRootName || this._getDefaultRootName(), data );
+		this.data.set( data, editableRootName || this._getDefaultRootName() );
 	}
 
 	/**

+ 5 - 5
tests/command/attributecommand.js

@@ -6,12 +6,12 @@
 'use strict';
 
 import Editor from '/ckeditor5/editor.js';
-import Document from '/ckeditor5/engine/treemodel/document.js';
+import Document from '/ckeditor5/engine/model/document.js';
 import AttributeCommand from '/ckeditor5/command/attributecommand.js';
-import Text from '/ckeditor5/engine/treemodel/text.js';
-import Range from '/ckeditor5/engine/treemodel/range.js';
-import Position from '/ckeditor5/engine/treemodel/position.js';
-import Element from '/ckeditor5/engine/treemodel/element.js';
+import Text from '/ckeditor5/engine/model/text.js';
+import Range from '/ckeditor5/engine/model/range.js';
+import Position from '/ckeditor5/engine/model/position.js';
+import Element from '/ckeditor5/engine/model/element.js';
 
 let editor, command, modelDoc, root;
 

+ 0 - 15
tests/creator/manual/_utils/creator/inlinecreator.js

@@ -29,9 +29,6 @@ export default class InlineCreator extends StandardCreator {
 		this._createEditable();
 
 		createEditorUI( editor, BoxlessEditorUI, EditorUIView );
-
-		// Data controller mock.
-		this._mockDataController();
 	}
 
 	create() {
@@ -90,16 +87,4 @@ export default class InlineCreator extends StandardCreator {
 		this.editor.ui.add( 'body', toolbar1 );
 		this.editor.ui.add( 'body', toolbar2 );
 	}
-
-	_mockDataController() {
-		const editor = this.editor;
-
-		editor.data.get = ( rootName ) => {
-			return editor.editables.get( rootName ).domElement.innerHTML + `<p>getData( '${ rootName }' )</p>`;
-		};
-
-		this.editor.data.set = ( rootName, data ) => {
-			editor.editables.get( rootName ).domElement.innerHTML = data + `<p>setData( '${ rootName }' )</p>`;
-		};
-	}
 }

+ 0 - 15
tests/creator/manual/_utils/creator/legacycreator.js

@@ -32,9 +32,6 @@ export default class LegacyCreator extends StandardCreator {
 
 		// UI.
 		createEditorUI( editor, BoxedEditorUI, BoxedEditorUIView );
-
-		// Data controller mock.
-		this._mockDataController();
 	}
 
 	create() {
@@ -76,16 +73,4 @@ export default class LegacyCreator extends StandardCreator {
 
 		this.editor.ui.add( 'top', toolbar );
 	}
-
-	_mockDataController() {
-		const editor = this.editor;
-
-		editor.data.get = ( rootName ) => {
-			return editor.editables.get( rootName ).domElement.innerHTML + `<p>getData( '${ rootName }' )</p>`;
-		};
-
-		this.editor.data.set = ( rootName, data ) => {
-			editor.editables.get( rootName ).domElement.innerHTML = data + `<p>setData( '${ rootName }' )</p>`;
-		};
-	}
 }

+ 0 - 15
tests/creator/manual/_utils/creator/multicreator.js

@@ -31,9 +31,6 @@ export default class MultiCreator extends StandardCreator {
 
 		// UI.
 		createEditorUI( editor, BoxedEditorUI, BoxedEditorUIView );
-
-		// Data controller mock.
-		this._mockDataController();
 	}
 
 	create() {
@@ -91,16 +88,4 @@ export default class MultiCreator extends StandardCreator {
 
 		this.editor.ui.add( 'top', toolbar );
 	}
-
-	_mockDataController() {
-		const editor = this.editor;
-
-		editor.data.get = ( rootName ) => {
-			return editor.editables.get( rootName ).domElement.innerHTML + `<p>getData( '${ rootName }' )</p>`;
-		};
-
-		this.editor.data.set = ( rootName, data ) => {
-			editor.editables.get( rootName ).domElement.innerHTML = data + `<p>setData( '${ rootName }' )</p>`;
-		};
-	}
 }

+ 9 - 3
tests/creator/standardcreator.js

@@ -12,9 +12,9 @@ import Creator from '/ckeditor5/creator/creator.js';
 import StandardCreator from '/ckeditor5/creator/standardcreator.js';
 import Editor from '/ckeditor5/editor.js';
 import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
-import Document from '/ckeditor5/engine/treemodel/document.js';
-import EditingController from '/ckeditor5/engine/treecontroller/editingcontroller.js';
-import DataController from '/ckeditor5/engine/treecontroller/datacontroller.js';
+import Document from '/ckeditor5/engine/model/document.js';
+import EditingController from '/ckeditor5/engine/editingcontroller.js';
+import DataController from '/ckeditor5/engine/datacontroller.js';
 
 testUtils.createSinonSandbox();
 
@@ -43,6 +43,12 @@ describe( 'Creator', () => {
 			expect( editor.data ).to.be.instanceof( DataController );
 			expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );
 		} );
+
+		it( 'uses HtmlDataProcessor if no processor is provided in constructor', () => {
+			creator = new StandardCreator( editor );
+
+			expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor );
+		} );
 	} );
 
 	describe( 'create', () => {

+ 2 - 2
tests/editable.js

@@ -9,8 +9,8 @@
 
 import Editor from '/ckeditor5/editor.js';
 import Editable from '/ckeditor5/editable.js';
-import EditingController from '/ckeditor5/engine/treecontroller/editingcontroller.js';
-import ViewElement from '/ckeditor5/engine/treeview/element.js';
+import EditingController from '/ckeditor5/engine/editingcontroller.js';
+import ViewElement from '/ckeditor5/engine/view/element.js';
 
 describe( 'Editable', () => {
 	const ELEMENT_NAME = 'h1';

+ 56 - 3
tests/editor/baseeditor.js

@@ -11,7 +11,10 @@ import Editor from '/ckeditor5/editor.js';
 import Command from '/ckeditor5/command/command.js';
 import Locale from '/ckeditor5/utils/locale.js';
 import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
-import Document from '/ckeditor5/engine/treemodel/document.js';
+import Document from '/ckeditor5/engine/model/document.js';
+import DataController from '/ckeditor5/engine/datacontroller.js';
+import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
+import { getData, setData } from '/tests/engine/_utils/model.js';
 
 describe( 'Editor', () => {
 	describe( 'locale', () => {
@@ -86,14 +89,14 @@ describe( 'Editor', () => {
 			editor.setData( 'foo' );
 
 			expect( editor.data.set.calledOnce ).to.be.true;
-			expect( editor.data.set.calledWithExactly( 'firstRoot', 'foo' ) ).to.be.true;
+			expect( editor.data.set.calledWithExactly( 'foo', 'firstRoot' ) ).to.be.true;
 		} );
 
 		it( 'should set data of the specified root', () => {
 			editor.setData( 'foo', 'someRoot' );
 
 			expect( editor.data.set.calledOnce ).to.be.true;
-			expect( editor.data.set.calledWithExactly( 'someRoot', 'foo' ) ).to.be.true;
+			expect( editor.data.set.calledWithExactly( 'foo', 'someRoot' ) ).to.be.true;
 		} );
 
 		it( 'should throw when no roots', () => {
@@ -118,6 +121,31 @@ describe( 'Editor', () => {
 				editor.setData( 'foo' );
 			} ).to.throw( CKEditorError, /^editor-no-datacontroller:/ );
 		} );
+
+		describe( 'integrational tests', () => {
+			beforeEach( () => {
+				editor.data = new DataController( editor.document, new HtmlDataProcessor() );
+
+				editor.document.schema.allow( { name: '$text', inside: '$root' } );
+			} );
+
+			it( 'should set data of the first root', () => {
+				editor.document.createRoot( 'firstRoot', 'div' );
+
+				editor.setData( 'foo' );
+
+				expect( getData( editor.document, { rootName: 'firstRoot', withoutSelection: true } ) ).to.equal( 'foo' );
+			} );
+
+			it( 'should set data of the specified root', () => {
+				editor.document.createRoot( 'firstRoot', 'div' );
+				editor.document.createRoot( 'secondRoot', 'div' );
+
+				editor.setData( 'foo', 'secondRoot' );
+
+				expect( getData( editor.document, { rootName: 'secondRoot', withoutSelection: true } ) ).to.equal( 'foo' );
+			} );
+		} );
 	} );
 
 	describe( 'getData', () => {
@@ -166,5 +194,30 @@ describe( 'Editor', () => {
 				editor.getData();
 			} ).to.throw( CKEditorError, /^editor-no-datacontroller:/ );
 		} );
+
+		describe( 'integrational tests', () => {
+			beforeEach( () => {
+				editor.data = new DataController( editor.document, new HtmlDataProcessor() );
+
+				editor.document.schema.allow( { name: '$text', inside: '$root' } );
+			} );
+
+			it( 'should set data of the first root', () => {
+				editor.document.createRoot( 'firstRoot', 'div' );
+
+				setData( editor.document, 'foo', { rootName: 'firstRoot' } );
+
+				expect( editor.getData() ).to.equal( 'foo' );
+			} );
+
+			it( 'should set data of the specified root', () => {
+				editor.document.createRoot( 'firstRoot', 'div' );
+				editor.document.createRoot( 'secondRoot', 'div' );
+
+				setData( editor.document, 'foo', { rootName: 'secondRoot' } );
+
+				expect( editor.getData( 'secondRoot' ) ).to.equal( 'foo' );
+			} );
+		} );
 	} );
 } );