Sfoglia il codice sorgente

Align code to the new conversion API, introduced in t/1236.

Piotr Jasiun 7 anni fa
parent
commit
daadca0bba
1 ha cambiato i file con 11 aggiunte e 15 eliminazioni
  1. 11 15
      packages/ckeditor5-link/src/linkengine.js

+ 11 - 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,20 @@ 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: viewElement => ( {
+					key: 'linkHref',
+					value: viewElement.getAttribute( 'href' )
+				} )
 			} ) );
 
 		// Create linking commands.