Parcourir la source

Merge branch t/ckeditor5-engine/1236

Internal: Align code to the new conversion API, introduced in engine t/1236.
Piotr Jasiun il y a 7 ans
Parent
commit
095bf96f9a

+ 16 - 15
packages/ckeditor5-link/src/linkengine.js

@@ -8,8 +8,8 @@
  */
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
-import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
+import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
+import { upcastElementToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
 import LinkCommand from './linkcommand';
 import UnlinkCommand from './unlinkcommand';
 import { createLinkElement } from './utils';
@@ -27,24 +27,25 @@ export default class LinkEngine extends Plugin {
 	 */
 	init() {
 		const editor = this.editor;
-		const data = editor.data;
-		const editing = editor.editing;
 
 		// Allow link attribute on all inline nodes.
 		editor.model.schema.extend( '$text', { allowAttributes: 'linkHref' } );
 
-		// Build converter from model to view for data and editing pipelines.
-		buildModelConverter().for( data.modelToView, editing.modelToView )
-			.fromAttribute( 'linkHref' )
-			.toElement( linkHref => createLinkElement( linkHref ) );
+		editor.conversion.for( 'downcast' )
+			.add( downcastAttributeToElement( 'linkHref', { view: linkHref => createLinkElement( linkHref ) } ) );
 
-		// Build converter from view to model for data pipeline.
-		buildViewConverter().for( data.viewToModel )
-			// Convert <a> with href (value doesn't matter).
-			.from( { name: 'a', attribute: { href: true } } )
-			.toAttribute( viewElement => ( {
-				key: 'linkHref',
-				value: viewElement.getAttribute( 'href' )
+		editor.conversion.for( 'upcast' )
+			.add( upcastElementToAttribute( {
+				view: {
+					name: 'a',
+					attribute: {
+						href: true
+					}
+				},
+				model: {
+					key: 'linkHref',
+					value: viewElement => viewElement.getAttribute( 'href' )
+				}
 			} ) );
 
 		// Create linking commands.

+ 2 - 4
packages/ckeditor5-link/tests/linkengine.js

@@ -13,7 +13,7 @@ import { getData as getModelData, setData as setModelData } from '@ckeditor/cked
 import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 import { isLinkElement } from '../src/utils';
 
-import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
+import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
 
 describe( 'LinkEngine', () => {
 	let editor, model;
@@ -110,9 +110,7 @@ describe( 'LinkEngine', () => {
 		it( 'should should set priority for `linkHref` higher than all other attribute elements', () => {
 			model.schema.extend( '$text', { allowAttributes: 'foo' } );
 
-			buildModelConverter().for( editor.data.modelToView )
-				.fromAttribute( 'foo' )
-				.toElement( 'f' );
+			editor.conversion.for( 'downcast' ).add( downcastAttributeToElement( 'foo', { view: 'f' } ) );
 
 			setModelData( model,
 				'<paragraph>' +