Parcourir la source

Fixing after changes introduced in t/ckeditor5-engine/1236

Szymon Cofalik il y a 7 ans
Parent
commit
71dbdeae9a

+ 4 - 13
packages/ckeditor5-paragraph/src/paragraph.js

@@ -10,8 +10,7 @@
 import ParagraphCommand from './paragraphcommand';
 
 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 { elementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/two-way-converters';
 import { SchemaContext } from '@ckeditor/ckeditor5-engine/src/model/schema';
 import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 import Range from '@ckeditor/ckeditor5-engine/src/model/range';
@@ -44,21 +43,13 @@ export default class Paragraph extends Plugin {
 		// Schema.
 		model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
 
-		// Build converter from model to view for data and editing pipelines.
-		buildModelConverter().for( data.modelToView, editing.modelToView )
-			.fromElement( 'paragraph' )
-			.toElement( 'p' );
-
-		// Build converter from view to model for data pipeline.
-		buildViewConverter().for( data.viewToModel )
-			.fromElement( 'p' )
-			.toElement( 'paragraph' );
+		elementToElement( editor.conversion, { model: 'paragraph', view: 'p' } );
 
 		// Content autoparagraphing. --------------------------------------------------
 
 		// Handles elements not converted by plugins and checks if would be converted if
 		// we wraps them by a paragraph or changes them to a paragraph.
-		data.viewToModel.on( 'element', ( evt, data, conversionApi ) => {
+		data.upcastDispatcher.on( 'element', ( evt, data, conversionApi ) => {
 			// When element is already consumed by higher priority converters then do nothing.
 			if ( !conversionApi.consumable.test( data.viewItem, { name: data.viewItem.name } ) ) {
 				return;
@@ -101,7 +92,7 @@ export default class Paragraph extends Plugin {
 		}, { priority: 'low' } );
 
 		// Handles not converted text nodes and checks if would be converted if we wraps then by a paragraph.
-		data.viewToModel.on( 'text', ( evt, data, conversionApi ) => {
+		data.upcastDispatcher.on( 'text', ( evt, data, conversionApi ) => {
 			// When node is already converted then do nothing.
 			if ( data.modelRange ) {
 				return;

+ 16 - 17
packages/ckeditor5-paragraph/tests/paragraph.js

@@ -13,8 +13,8 @@ import {
 } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 
-import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
-import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
+import { downcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
+import { upcastElementToElement, upcastElementToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
 
 import ModelDocumentFragment from '@ckeditor/ckeditor5-engine/src/model/documentfragment';
 import ModelText from '@ckeditor/ckeditor5-engine/src/model/text';
@@ -82,8 +82,8 @@ describe( 'Paragraph feature', () => {
 				editor.model.schema.register( 'span', { allowWhere: '$text' } );
 				editor.model.schema.extend( '$text', { allowIn: 'span' } );
 
-				buildModelConverter().for( editor.editing.modelToView, editor.data.modelToView ).fromElement( 'span' ).toElement( 'span' );
-				buildViewConverter().for( editor.data.viewToModel ).fromElement( 'span' ).toElement( 'span' );
+				editor.conversion.for( 'downcast' ).add( downcastElementToElement( { model: 'span', view: 'span' } ) );
+				editor.conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'span', view: 'span' } ) );
 
 				editor.setData( '<span>foo</span>' );
 
@@ -109,7 +109,8 @@ describe( 'Paragraph feature', () => {
 
 			it( 'should autoparagraph text next to allowed element', () => {
 				model.schema.register( 'heading1', { inheritAllFrom: '$block' } );
-				buildViewConverter().for( editor.data.viewToModel ).fromElement( 'h1' ).toElement( 'heading1' );
+
+				editor.conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'heading1', view: 'h1' } ) );
 
 				const modelFragment = editor.data.parse( '<h1>foo</h1>bar<p>bom</p>' );
 
@@ -136,7 +137,7 @@ describe( 'Paragraph feature', () => {
 				model.schema.extend( 'div', { allowIn: '$root' } );
 				model.schema.extend( 'paragraph', { allowIn: 'div' } );
 
-				buildViewConverter().for( editor.data.viewToModel ).fromElement( 'div' ).toElement( 'div' );
+				editor.conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'div', view: 'div' } ) );
 
 				const modelFragment = editor.data.parse( '<div>foo</div><div>bom<p>bim</p></div>' );
 
@@ -149,7 +150,8 @@ describe( 'Paragraph feature', () => {
 
 			it( 'should autoparagraph text inside disallowed element next to allowed element', () => {
 				model.schema.register( 'heading1', { inheritAllFrom: '$block' } );
-				buildViewConverter().for( editor.data.viewToModel ).fromElement( 'h1' ).toElement( 'heading1' );
+
+				editor.conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'heading1', view: 'h1' } ) );
 
 				const modelFragment = editor.data.parse( '<div><h1>foo</h1>bar</div>' );
 
@@ -159,7 +161,8 @@ describe( 'Paragraph feature', () => {
 
 			it( 'should not autoparagraph text in disallowed element', () => {
 				model.schema.register( 'heading1', { inheritAllFrom: '$block' } );
-				buildViewConverter().for( editor.data.viewToModel ).fromElement( 'h1' ).toElement( 'heading1' );
+
+				editor.conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'heading1', view: 'h1' } ) );
 
 				const modelFragment = editor.data.parse( '<h1><b>foo</b>bar</h1>' );
 
@@ -189,7 +192,7 @@ describe( 'Paragraph feature', () => {
 
 			// This test was taken from the list package.
 			it( 'does not break when some converter returns nothing', () => {
-				editor.data.viewToModel.on( 'element:li', ( evt, data, conversionApi ) => {
+				editor.data.upcastDispatcher.on( 'element:li', ( evt, data, conversionApi ) => {
 					conversionApi.consumable.consume( data.input, { name: true } );
 				}, { priority: 'highest' } );
 
@@ -202,9 +205,7 @@ describe( 'Paragraph feature', () => {
 				beforeEach( () => {
 					model.schema.extend( '$text', { allowAttributes: 'bold' } );
 
-					buildViewConverter().for( editor.data.viewToModel )
-						.fromElement( 'b' )
-						.toAttribute( 'bold', true );
+					editor.conversion.for( 'upcast' ).add( upcastElementToAttribute( { view: 'b', model: 'bold' } ) );
 				} );
 
 				it( 'inside document fragment', () => {
@@ -217,7 +218,7 @@ describe( 'Paragraph feature', () => {
 					model.schema.register( 'blockQuote', { allowIn: '$root' } );
 					model.schema.extend( '$block', { allowIn: 'blockQuote' } );
 
-					buildViewConverter().for( editor.data.viewToModel ).fromElement( 'blockquote' ).toElement( 'blockQuote' );
+					editor.conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'blockQuote', view: 'blockquote' } ) );
 
 					const modelFragment = editor.data.parse( '<blockquote>foo<b>bar</b>bom</blockquote>' );
 
@@ -255,7 +256,7 @@ describe( 'Paragraph feature', () => {
 				model.schema.extend( 'div', { allowIn: 'specialRoot' } );
 				model.schema.extend( '$text', { allowIn: 'div' } );
 
-				buildViewConverter().for( editor.data.viewToModel ).fromElement( 'div' ).toElement( 'div' );
+				editor.conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'div', view: 'div' } ) );
 
 				const modelFragment = editor.data.parse( '<h1>foo</h1><h2>bar</h2><div>bom</div>', [ 'specialRoot' ] );
 
@@ -300,8 +301,6 @@ describe( 'Paragraph feature', () => {
 					.to.equal( '<paragraph>a</paragraph><paragraph>b</paragraph>' );
 			} );
 
-			// "b" is not autoparagraphed because clipboard holder allows text nodes.
-			// There's a similar integrational test what's going to happen when pasting in paragraph-integration.js.
 			it( 'should convert ul>li>p,text (in clipboard holder)', () => {
 				const modelFragment = editor.data.parse( '<ul><li><p>a</p>b</li></ul>', [ '$clipboardHolder' ] );
 
@@ -333,7 +332,7 @@ describe( 'Paragraph feature', () => {
 				model.schema.extend( 'div', { allowIn: '$root' } );
 				model.schema.extend( 'paragraph', { allowIn: 'div' } );
 
-				buildViewConverter().for( editor.data.viewToModel ).fromElement( 'div' ).toElement( 'div' );
+				editor.conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'div', view: 'div' } ) );
 
 				const modelFragment = editor.data.parse( '<div><ul><li>foo</li><li>bar</li></ul></div><div>bom<p>bim</p></div>' );