8
0
Просмотр исходного кода

Updated the font features' conversion to the newest API.

Aleksander Nowodzinski 8 лет назад
Родитель
Сommit
01a584ae95

+ 1 - 1
packages/ckeditor5-font/src/fontfamily.js

@@ -43,7 +43,7 @@ export default class FontFamily extends Plugin {
  * @property {String} title The user-readable title of the option.
  * @property {String} model Attribute's unique value in the model.
  * @property {module:engine/view/viewelementdefinition~ViewElementDefinition} view View element configuration.
- * @property {Array.<module:engine/view/viewelementdefinition~ViewElementDefinition>} [acceptsAlso] An array with all matched elements that
+ * @property {Array.<module:engine/view/viewelementdefinition~ViewElementDefinition>} [upcastAlso] An array with all matched elements that
  * view to model conversion should also accept.
  */
 

+ 8 - 16
packages/ckeditor5-font/src/fontfamily/fontfamilyediting.js

@@ -8,14 +8,13 @@
  */
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import {
-	modelAttributeToViewAttributeElement,
-	viewToModelAttribute
-} from '@ckeditor/ckeditor5-engine/src/conversion/definition-based-converters';
+import { attributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/two-way-converters';
 
 import FontFamilyCommand from './fontfamilycommand';
 import { normalizeOptions } from './utils';
 
+const FONT_FAMILY = 'fontFamily';
+
 /**
  * The Font Family Editing feature.
  *
@@ -29,7 +28,7 @@ export default class FontFamilyEditing extends Plugin {
 		super( editor );
 
 		// Define default configuration using font families shortcuts.
-		editor.config.define( 'fontFamily', {
+		editor.config.define( FONT_FAMILY, {
 			options: [
 				'default',
 				'Arial, Helvetica, sans-serif',
@@ -49,23 +48,16 @@ export default class FontFamilyEditing extends Plugin {
 	 */
 	init() {
 		const editor = this.editor;
-		const data = editor.data;
-		const editing = editor.editing;
 
 		// Allow fontFamily attribute on text nodes.
-		editor.model.schema.extend( '$text', { allowAttributes: 'fontFamily' } );
+		editor.model.schema.extend( '$text', { allowAttributes: FONT_FAMILY } );
 
 		// Get configured font family options without "default" option.
 		const options = normalizeOptions( editor.config.get( 'fontFamily.options' ) ).filter( item => item.model );
 
-		// Define view to model conversion.
-		for ( const option of options ) {
-			viewToModelAttribute( 'fontFamily', option, [ data.viewToModel ] );
-		}
-
-		// Define model to view conversion.
-		modelAttributeToViewAttributeElement( 'fontFamily', options, [ data.modelToView, editing.modelToView ] );
+		// Set-up the two-way conversion.
+		attributeToElement( editor.conversion, FONT_FAMILY, options );
 
-		editor.commands.add( 'fontFamily', new FontFamilyCommand( editor ) );
+		editor.commands.add( FONT_FAMILY, new FontFamilyCommand( editor ) );
 	}
 }

+ 1 - 1
packages/ckeditor5-font/src/fontsize.js

@@ -43,7 +43,7 @@ export default class FontSize extends Plugin {
  * @property {String} title The user-readable title of the option.
  * @property {String} model Attribute's unique value in the model.
  * @property {module:engine/view/viewelementdefinition~ViewElementDefinition} view View element configuration.
- * @property {Array.<module:engine/view/viewelementdefinition~ViewElementDefinition>} [acceptsAlso] An array with all matched elements that
+ * @property {Array.<module:engine/view/viewelementdefinition~ViewElementDefinition>} [upcastAlso] An array with all matched elements that
  * view to model conversion should also accept.
  */
 

+ 8 - 17
packages/ckeditor5-font/src/fontsize/fontsizeediting.js

@@ -8,14 +8,13 @@
  */
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import {
-	modelAttributeToViewAttributeElement,
-	viewToModelAttribute
-} from '@ckeditor/ckeditor5-engine/src/conversion/definition-based-converters';
+import { attributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/two-way-converters';
 
 import FontSizeCommand from './fontsizecommand';
 import { normalizeOptions } from './utils';
 
+const FONT_SIZE = 'fontSize';
+
 /**
  * The Font Size Editing feature.
  *
@@ -29,7 +28,7 @@ export default class FontSizeEditing extends Plugin {
 		super( editor );
 
 		// Define default configuration using named presets.
-		editor.config.define( 'fontSize', {
+		editor.config.define( FONT_SIZE, {
 			options: [
 				'tiny',
 				'small',
@@ -39,22 +38,14 @@ export default class FontSizeEditing extends Plugin {
 			]
 		} );
 
-		const data = editor.data;
-		const editing = editor.editing;
-
 		// Define view to model conversion.
 		const options = normalizeOptions( this.editor.config.get( 'fontSize.options' ) ).filter( item => item.model );
 
-		for ( const option of options ) {
-			// Covert view to model.
-			viewToModelAttribute( 'fontSize', option, [ data.viewToModel ] );
-		}
-
-		// Define model to view conversion.
-		modelAttributeToViewAttributeElement( 'fontSize', options, [ data.modelToView, editing.modelToView ] );
+		// Set-up the two-way conversion.
+		attributeToElement( editor.conversion, FONT_SIZE, options );
 
 		// Add FontSize command.
-		editor.commands.add( 'fontSize', new FontSizeCommand( editor ) );
+		editor.commands.add( FONT_SIZE, new FontSizeCommand( editor ) );
 	}
 
 	/**
@@ -64,6 +55,6 @@ export default class FontSizeEditing extends Plugin {
 		const editor = this.editor;
 
 		// Allow fontSize attribute on text nodes.
-		editor.model.schema.extend( '$text', { allowAttributes: 'fontSize' } );
+		editor.model.schema.extend( '$text', { allowAttributes: FONT_SIZE } );
 	}
 }

+ 2 - 2
packages/ckeditor5-font/tests/fontfamily/fontfamilyediting.js

@@ -139,10 +139,10 @@ describe( 'FontFamilyEditing', () => {
 									name: 'span',
 									class: [ 'text-complex' ]
 								},
-								acceptsAlso: [
+								upcastAlso: [
 									{ name: 'span', style: { 'font-family': 'Arial' } },
 									{ name: 'span', style: { 'font-family': 'Arial,sans-serif' } },
-									{ name: 'span', attributes: { 'data-font': 'Arial' } }
+									{ name: 'span', attribute: { 'data-font': 'Arial' } }
 								]
 							}
 						]

+ 2 - 2
packages/ckeditor5-font/tests/fontsize/fontsizeediting.js

@@ -132,9 +132,9 @@ describe( 'FontSizeEditing', () => {
 									name: 'span',
 									class: [ 'text-complex' ]
 								},
-								acceptsAlso: [
+								upcastAlso: [
 									{ name: 'span', style: { 'font-size': '77em' } },
-									{ name: 'span', attributes: { 'data-size': '77em' } }
+									{ name: 'span', attribute: { 'data-size': '77em' } }
 								]
 							}
 						]