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

Use model instead of the document in controllers.

Piotr Jasiun 8 лет назад
Родитель
Сommit
07f856e493

+ 8 - 8
packages/ckeditor5-engine/src/controller/datacontroller.js

@@ -44,15 +44,15 @@ export default class DataController {
 	/**
 	 * Creates data controller instance.
 	 *
-	 * @param {module:engine/model/document~Document} model Document model.
+	 * @param {module:engine/model/model~Model} model Data model.
 	 * @param {module:engine/dataprocessor/dataprocessor~DataProcessor} [dataProcessor] Data processor which should used by the controller.
 	 */
 	constructor( model, dataProcessor ) {
 		/**
-		 * Document model.
+		 * Data model.
 		 *
 		 * @readonly
-		 * @member {module:engine/model/document~Document}
+		 * @member {module:engine/model/model~Model}
 		 */
 		this.model = model;
 
@@ -86,7 +86,7 @@ export default class DataController {
 		 * @readonly
 		 * @member {module:engine/conversion/modelconversiondispatcher~ModelConversionDispatcher}
 		 */
-		this.modelToView = new ModelConversionDispatcher( this.model, {
+		this.modelToView = new ModelConversionDispatcher( this.model.document, {
 			mapper: this.mapper
 		} );
 		this.modelToView.on( 'insert:$text', insertText(), { priority: 'lowest' } );
@@ -130,7 +130,7 @@ export default class DataController {
 	 */
 	get( rootName = 'main' ) {
 		// Get model range.
-		return this.stringify( this.model.getRoot( rootName ) );
+		return this.stringify( this.model.document.getRoot( rootName ) );
 	}
 
 	/**
@@ -186,13 +186,13 @@ export default class DataController {
 	 */
 	set( data, rootName = 'main' ) {
 		// Save to model.
-		const modelRoot = this.model.getRoot( rootName );
+		const modelRoot = this.model.document.getRoot( rootName );
 
 		this.model.enqueueChanges( () => {
 			// Clearing selection is a workaround for ticket #569 (LiveRange loses position after removing data from document).
 			// After fixing it this code should be removed.
-			this.model.selection.removeAllRanges();
-			this.model.selection.clearAttributes();
+			this.model.document.selection.removeAllRanges();
+			this.model.document.selection.clearAttributes();
 
 			// Initial batch should be ignored by features like undo, etc.
 			const batch = this.model.batch( 'transparent' );

+ 8 - 8
packages/ckeditor5-engine/src/controller/editingcontroller.js

@@ -36,14 +36,14 @@ export default class EditingController {
 	/**
 	 * Creates editing controller instance.
 	 *
-	 * @param {module:engine/model/document~Document} model Document model.
+	 * @param {module:engine/model/model~Model} model Editing model.
 	 */
 	constructor( model ) {
 		/**
-		 * Document model.
+		 * Editing model.
 		 *
 		 * @readonly
-		 * @member {module:engine/model/document~Document}
+		 * @member {module:engine/model/model~Model}
 		 */
 		this.model = model;
 
@@ -78,18 +78,18 @@ export default class EditingController {
 		 * @readonly
 		 * @member {module:engine/conversion/modelconversiondispatcher~ModelConversionDispatcher} #modelToView
 		 */
-		this.modelToView = new ModelConversionDispatcher( this.model, {
+		this.modelToView = new ModelConversionDispatcher( this.model.document, {
 			mapper: this.mapper,
 			viewSelection: this.view.selection
 		} );
 
 		// Convert changes in model to view.
-		this.listenTo( this.model, 'change', ( evt, type, changes ) => {
+		this.listenTo( this.model.document, 'change', ( evt, type, changes ) => {
 			this.modelToView.convertChange( type, changes );
 		}, { priority: 'low' } );
 
 		// Convert model selection to view.
-		this.listenTo( this.model, 'changesDone', () => {
+		this.listenTo( this.model.document, 'changesDone', () => {
 			const selection = this.model.selection;
 
 			this.modelToView.convertSelection( selection );
@@ -106,7 +106,7 @@ export default class EditingController {
 		} );
 
 		// Convert view selection to model.
-		this.listenTo( this.view, 'selectionChange', convertSelectionChange( this.model, this.mapper ) );
+		this.listenTo( this.view, 'selectionChange', convertSelectionChange( this.model.document, this.mapper ) );
 
 		// Attach default content converters.
 		this.modelToView.on( 'insert:$text', insertText(), { priority: 'lowest' } );
@@ -139,7 +139,7 @@ export default class EditingController {
 	 */
 	createRoot( domRoot, name = 'main' ) {
 		const viewRoot = this.view.createRoot( domRoot, name );
-		const modelRoot = this.model.getRoot( name );
+		const modelRoot = this.model.document.getRoot( name );
 
 		this.mapper.bindElements( modelRoot, viewRoot );
 

+ 1 - 12
packages/ckeditor5-engine/src/model/document.js

@@ -47,7 +47,6 @@ export default class Document {
 	 * the {@link #graveyard graveyard root}).
 	 */
 	constructor( model ) {
-
 		this.model = model;
 
 		/**
@@ -108,7 +107,7 @@ export default class Document {
 		// Graveyard tree root. Document always have a graveyard root, which stores removed nodes.
 		this.createRoot( '$root', graveyardName );
 
-		this.listenTo( model, 'applyOperation', () => {
+		this.listenTo( model, 'applyOperation', ( evt, args ) => {
 			const operation = args[ 0 ];
 
 			if ( operation.isDocumentOperation && operation.baseVersion !== this.version ) {
@@ -145,16 +144,6 @@ export default class Document {
 		return this.getRoot( graveyardName );
 	}
 
-	/**
-	 * Creates a {@link module:engine/model/batch~Batch} instance which allows to change the document.
-	 *
-	 * @param {String} [type] Batch type. See {@link module:engine/model/batch~Batch#type}.
-	 * @returns {module:engine/model/batch~Batch} Batch instance.
-	 */
-	batch( type ) {
-		return new Batch( this, type );
-	}
-
 	/**
 	 * Creates a new top-level root.
 	 *

+ 2 - 1
packages/ckeditor5-engine/src/model/model.js

@@ -4,13 +4,14 @@
  */
 
 /**
- * @module engine/model
+ * @module engine/model/model
  */
 
 import Batch from './batch';
 import Schema from './schema';
 import Document from './document';
 import MarkerCollection from './markercollection';
+import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';