Selaa lähdekoodia

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

Piotr Jasiun 7 vuotta sitten
vanhempi
commit
0fa27ca25e

+ 8 - 12
packages/ckeditor5-basic-styles/src/boldengine.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, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
 import AttributeCommand from './attributecommand';
 
 const BOLD = 'bold';
@@ -28,23 +28,19 @@ export default class BoldEngine extends Plugin {
 	 */
 	init() {
 		const editor = this.editor;
-		const data = editor.data;
-		const editing = editor.editing;
 
 		// Allow bold attribute on text nodes.
 		editor.model.schema.extend( '$text', { allowAttributes: BOLD } );
 
 		// Build converter from model to view for data and editing pipelines.
-		buildModelConverter().for( data.modelToView, editing.modelToView )
-			.fromAttribute( BOLD )
-			.toElement( 'strong' );
+		editor.conversion.for( 'downcast' )
+			.add( downcastAttributeToElement( BOLD, { view: 'strong' } ) );
 
 		// Build converter from view to model for data pipeline.
-		buildViewConverter().for( data.viewToModel )
-			.fromElement( 'strong' )
-			.fromElement( 'b' )
-			.fromAttribute( 'style', { 'font-weight': 'bold' } )
-			.toAttribute( BOLD, true );
+		editor.conversion.for( 'upcast' )
+			.add( upcastElementToAttribute( { view: 'b', model: BOLD } ) )
+			.add( upcastElementToAttribute( { view: 'strong', model: BOLD } ) )
+			.add( upcastAttributeToAttribute( { view: { style: { 'font-weight': 'bold' } }, model: BOLD } ) );
 
 		// Create bold command.
 		editor.commands.add( BOLD, new AttributeCommand( editor, BOLD ) );

+ 7 - 11
packages/ckeditor5-basic-styles/src/codeengine.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, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
 import AttributeCommand from './attributecommand';
 
 const CODE = 'code';
@@ -28,22 +28,18 @@ export default class CodeEngine extends Plugin {
 	 */
 	init() {
 		const editor = this.editor;
-		const data = editor.data;
-		const editing = editor.editing;
 
 		// Allow code attribute on text nodes.
 		editor.model.schema.extend( '$text', { allowAttributes: CODE } );
 
 		// Build converter from model to view for data and editing pipelines.
-		buildModelConverter().for( data.modelToView, editing.modelToView )
-			.fromAttribute( CODE )
-			.toElement( 'code' );
+		editor.conversion.for( 'downcast' )
+			.add( downcastAttributeToElement( CODE, { view: 'code' } ) );
 
 		// Build converter from view to model for data pipeline.
-		buildViewConverter().for( data.viewToModel )
-			.fromElement( 'code' )
-			.fromAttribute( 'style', { 'word-wrap': 'break-word' } )
-			.toAttribute( CODE, true );
+		editor.conversion.for( 'upcast' )
+			.add( upcastElementToAttribute( { view: 'code', model: CODE } ) )
+			.add( upcastAttributeToAttribute( { view: { style: { 'word-wrap': 'break-word' } }, model: CODE } ) );
 
 		// Create code command.
 		editor.commands.add( CODE, new AttributeCommand( editor, CODE ) );

+ 8 - 12
packages/ckeditor5-basic-styles/src/italicengine.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, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
 import AttributeCommand from './attributecommand';
 
 const ITALIC = 'italic';
@@ -28,23 +28,19 @@ export default class ItalicEngine extends Plugin {
 	 */
 	init() {
 		const editor = this.editor;
-		const data = editor.data;
-		const editing = editor.editing;
 
 		// Allow italic attribute on text nodes.
 		editor.model.schema.extend( '$text', { allowAttributes: ITALIC } );
 
 		// Build converter from model to view for data and editing pipelines.
-		buildModelConverter().for( data.modelToView, editing.modelToView )
-			.fromAttribute( ITALIC )
-			.toElement( 'i' );
+		editor.conversion.for( 'downcast' )
+			.add( downcastAttributeToElement( ITALIC, { view: 'i' } ) );
 
 		// Build converter from view to model for data pipeline.
-		buildViewConverter().for( data.viewToModel )
-			.fromElement( 'em' )
-			.fromElement( 'i' )
-			.fromAttribute( 'style', { 'font-style': 'italic' } )
-			.toAttribute( ITALIC, true );
+		editor.conversion.for( 'upcast' )
+			.add( upcastElementToAttribute( { view: 'em', model: ITALIC } ) )
+			.add( upcastElementToAttribute( { view: 'i', model: ITALIC } ) )
+			.add( upcastAttributeToAttribute( { view: { style: { 'font-style': 'italic' } }, model: ITALIC } ) );
 
 		// Create italic command.
 		editor.commands.add( ITALIC, new AttributeCommand( editor, ITALIC ) );

+ 9 - 13
packages/ckeditor5-basic-styles/src/strikethroughengine.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, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
 import AttributeCommand from './attributecommand';
 
 const STRIKETHROUGH = 'strikethrough';
@@ -29,24 +29,20 @@ export default class StrikethroughEngine extends Plugin {
 	 */
 	init() {
 		const editor = this.editor;
-		const data = editor.data;
-		const editing = editor.editing;
 
 		// Allow strikethrough attribute on text nodes.
 		editor.model.schema.extend( '$text', { allowAttributes: STRIKETHROUGH } );
 
 		// Build converter from model to view for data and editing pipelines.
-		buildModelConverter().for( data.modelToView, editing.modelToView )
-			.fromAttribute( STRIKETHROUGH )
-			.toElement( 's' );
+		editor.conversion.for( 'downcast' )
+			.add( downcastAttributeToElement( STRIKETHROUGH, { view: 's' } ) );
 
 		// Build converter from view to model for data pipeline.
-		buildViewConverter().for( data.viewToModel )
-			.fromElement( 's' )
-			.fromElement( 'del' )
-			.fromElement( 'strike' )
-			.fromAttribute( 'style', { 'text-decoration': 'line-through' } )
-			.toAttribute( STRIKETHROUGH, true );
+		editor.conversion.for( 'upcast' )
+			.add( upcastElementToAttribute( { view: 's', model: STRIKETHROUGH } ) )
+			.add( upcastElementToAttribute( { view: 'del', model: STRIKETHROUGH } ) )
+			.add( upcastElementToAttribute( { view: 'strike', model: STRIKETHROUGH } ) )
+			.add( upcastAttributeToAttribute( { view: { style: { 'text-decoration': 'line-through' } }, model: STRIKETHROUGH } ) );
 
 		// Create strikethrough command.
 		editor.commands.add( STRIKETHROUGH, new AttributeCommand( editor, STRIKETHROUGH ) );

+ 7 - 11
packages/ckeditor5-basic-styles/src/underlineengine.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, upcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
 import AttributeCommand from './attributecommand';
 
 const UNDERLINE = 'underline';
@@ -28,22 +28,18 @@ export default class UnderlineEngine extends Plugin {
 	 */
 	init() {
 		const editor = this.editor;
-		const data = editor.data;
-		const editing = editor.editing;
 
 		// Allow strikethrough attribute on text nodes.
 		editor.model.schema.extend( '$text', { allowAttributes: UNDERLINE } );
 
 		// Build converter from model to view for data and editing pipelines.
-		buildModelConverter().for( data.modelToView, editing.modelToView )
-			.fromAttribute( UNDERLINE )
-			.toElement( 'u' );
+		editor.conversion.for( 'downcast' )
+			.add( downcastAttributeToElement( UNDERLINE, { view: 'u' } ) );
 
 		// Build converter from view to model for data pipeline.
-		buildViewConverter().for( data.viewToModel )
-			.fromElement( 'u' )
-			.fromAttribute( 'style', { 'text-decoration': 'underline' } )
-			.toAttribute( UNDERLINE, true );
+		editor.conversion.for( 'upcast' )
+			.add( upcastElementToAttribute( { view: 'u', model: UNDERLINE } ) )
+			.add( upcastAttributeToAttribute( { view: { style: { 'text-decoration': 'underline' } }, model: UNDERLINE } ) );
 
 		// Create underline command.
 		editor.commands.add( UNDERLINE, new AttributeCommand( editor, UNDERLINE ) );