Przeglądaj źródła

Changed: Added `Editor#conversion`.

Szymon Cofalik 7 lat temu
rodzic
commit
d5712cb622

+ 18 - 0
packages/ckeditor5-core/src/editor/editor.js

@@ -13,6 +13,7 @@ import PluginCollection from '../plugincollection';
 import CommandCollection from '../commandcollection';
 import Locale from '@ckeditor/ckeditor5-utils/src/locale';
 import DataController from '@ckeditor/ckeditor5-engine/src/controller/datacontroller';
+import Conversion from '@ckeditor/ckeditor5-engine/src/conversion/conversion';
 import Model from '@ckeditor/ckeditor5-engine/src/model/model';
 import EditingKeystrokeHandler from '../editingkeystrokehandler';
 
@@ -120,6 +121,23 @@ export default class Editor {
 		this.editing.view.bind( 'isReadOnly' ).to( this );
 
 		/**
+		 * Conversion manager to which conversion dispatchers are registered. Used to add converters to the editor.
+		 *
+		 * See {@link module:engine/conversion/conversion~Conversion#for} to learn how to use conversion helpers in order to
+		 * add converters to the editor.
+		 *
+		 * @readonly
+		 * @member {module:engine/conversion/conversion~Conversion}
+		 */
+		this.conversion = new Conversion();
+
+		this.conversion.register( 'downcast', [ this.editing.downcastDispatcher, this.data.downcastDispatcher ] );
+		this.conversion.register( 'editingDowncast', [ this.editing.downcastDispatcher ] );
+		this.conversion.register( 'dataDowncast', [ this.data.downcastDispatcher ] );
+
+		this.conversion.register( 'upcast', [ this.data.upcastDispatcher ] );
+
+		/**
 		 * Instance of the {@link module:core/editingkeystrokehandler~EditingKeystrokeHandler}.
 		 *
 		 * @readonly

+ 20 - 0
packages/ckeditor5-core/tests/editor/editor.js

@@ -200,6 +200,26 @@ describe( 'Editor', () => {
 		} );
 	} );
 
+	describe( 'conversion', () => {
+		it( 'should have conversion property', () => {
+			const editor = new Editor();
+
+			expect( editor ).to.have.property( 'conversion' );
+		} );
+
+		it( 'should have defined default conversion groups', () => {
+			const editor = new Editor();
+
+			expect( () => {
+				// Would throw if any of this group won't exist.
+				editor.conversion.for( 'downcast' );
+				editor.conversion.for( 'downcastEditing' );
+				editor.conversion.for( 'downcastData' );
+				editor.conversion.for( 'upcast' );
+			} ).not.to.throw();
+		} );
+	} );
+
 	describe( 'destroy()', () => {
 		it( 'should fire "destroy"', () => {
 			const editor = new Editor();