Ver código fonte

Normalizer should only work on value.

Maciej Gołaszewski 5 anos atrás
pai
commit
cea4ffffae

+ 5 - 10
packages/ckeditor5-engine/src/view/styles.js

@@ -313,26 +313,21 @@ export class StylesProcessor {
 	 * @param {Object} styles
 	 * @private
 	 */
-	toNormalizedForm( propertyName, value, styles ) {
-		if ( isObject( value ) ) {
-			appendStyleValue( styles, toPath( propertyName ), value );
+	toNormalizedForm( propertyName, propertyValue, styles ) {
+		if ( isObject( propertyValue ) ) {
+			appendStyleValue( styles, toPath( propertyName ), propertyValue );
 
 			return;
 		}
 
-		const data = {
-			path: propertyName,
-			value
-		};
-
 		if ( this._normalizers.has( propertyName ) ) {
 			const normalizer = this._normalizers.get( propertyName );
 
-			const { path, value } = normalizer( data );
+			const { path, value } = normalizer( propertyValue );
 
 			appendStyleValue( styles, path, value );
 		} else {
-			appendStyleValue( styles, propertyName, value );
+			appendStyleValue( styles, propertyName, propertyValue );
 		}
 	}
 

+ 3 - 3
packages/ckeditor5-engine/src/view/styles/backgroundstyles.js

@@ -11,7 +11,7 @@ import { isAttachment, isColor, isPosition, isRepeat, isURL } from './utils';
 
 export function addBackgroundStylesProcessor( stylesProcessor ) {
 	stylesProcessor.setNormalizer( 'background', normalizeBackground );
-	stylesProcessor.setNormalizer( 'background-color', data => ( { path: 'background.color', value: data.value } ) );
+	stylesProcessor.setNormalizer( 'background-color', value => ( { path: 'background.color', value } ) );
 	stylesProcessor.setReducer( 'background', data => {
 		const ret = [];
 
@@ -21,10 +21,10 @@ export function addBackgroundStylesProcessor( stylesProcessor ) {
 	} );
 }
 
-function normalizeBackground( data ) {
+function normalizeBackground( value ) {
 	const background = {};
 
-	const parts = data.value.split( ' ' );
+	const parts = value.split( ' ' );
 
 	for ( const part of parts ) {
 		if ( isRepeat( part ) ) {

+ 8 - 8
packages/ckeditor5-engine/src/view/styles/borderstyles.js

@@ -70,8 +70,8 @@ export function addBorderStylesProcessor( stylesProcessor ) {
 	stylesProcessor.setReducer( 'border', borderReducer );
 }
 
-function borderNormalizer( data ) {
-	const { color, style, width } = normalizeBorderShorthand( data.value );
+function borderNormalizer( value ) {
+	const { color, style, width } = normalizeBorderShorthand( value );
 
 	return {
 		path: 'border',
@@ -84,8 +84,8 @@ function borderNormalizer( data ) {
 }
 
 function getBorderPositionNormalizer( side ) {
-	return data => {
-		const { color, style, width } = normalizeBorderShorthand( data.value );
+	return value => {
+		const { color, style, width } = normalizeBorderShorthand( value );
 
 		const border = {};
 
@@ -109,10 +109,10 @@ function getBorderPositionNormalizer( side ) {
 }
 
 function getBorderPropertyNormalizer( propertyName ) {
-	return data => {
+	return value => {
 		return {
 			path: 'border',
-			value: toBorderPropertyShorthand( data.value, propertyName )
+			value: toBorderPropertyShorthand( value, propertyName )
 		};
 	};
 }
@@ -124,12 +124,12 @@ function toBorderPropertyShorthand( value, property ) {
 }
 
 function getBorderPropertyPositionNormalizer( property, side ) {
-	return data => {
+	return value => {
 		return {
 			path: 'border',
 			value: {
 				[ property ]: {
-					[ side ]: data.value
+					[ side ]: value
 				}
 			}
 		};

+ 4 - 4
packages/ckeditor5-engine/src/view/styles/marginstyles.js

@@ -12,10 +12,10 @@ import { getPositionShorthandNormalizer, getTopRightBottomLeftValueReducer } fro
 export function addMarginStylesProcessor( stylesProcessor ) {
 	stylesProcessor.setNormalizer( 'margin', getPositionShorthandNormalizer( 'margin' ) );
 
-	stylesProcessor.setNormalizer( 'margin-top', data => ( { path: 'margin.top', value: data.value } ) );
-	stylesProcessor.setNormalizer( 'margin-right', data => ( { path: 'margin.right', value: data.value } ) );
-	stylesProcessor.setNormalizer( 'margin-bottom', data => ( { path: 'margin.bottom', value: data.value } ) );
-	stylesProcessor.setNormalizer( 'margin-left', data => ( { path: 'margin.left', value: data.value } ) );
+	stylesProcessor.setNormalizer( 'margin-top', value => ( { path: 'margin.top', value } ) );
+	stylesProcessor.setNormalizer( 'margin-right', value => ( { path: 'margin.right', value } ) );
+	stylesProcessor.setNormalizer( 'margin-bottom', value => ( { path: 'margin.bottom', value } ) );
+	stylesProcessor.setNormalizer( 'margin-left', value => ( { path: 'margin.left', value } ) );
 
 	stylesProcessor.setReducer( 'margin', getTopRightBottomLeftValueReducer( 'margin' ) );
 }

+ 4 - 4
packages/ckeditor5-engine/src/view/styles/paddingstyles.js

@@ -11,10 +11,10 @@ import { getPositionShorthandNormalizer, getTopRightBottomLeftValueReducer } fro
 
 export function addPaddingStylesProcessor( stylesProcessor ) {
 	stylesProcessor.setNormalizer( 'padding', getPositionShorthandNormalizer( 'padding' ) );
-	stylesProcessor.setNormalizer( 'padding-top', data => ( { path: 'padding.top', value: data.value } ) );
-	stylesProcessor.setNormalizer( 'padding-right', data => ( { path: 'padding.right', value: data.value } ) );
-	stylesProcessor.setNormalizer( 'padding-bottom', data => ( { path: 'padding.bottom', value: data.value } ) );
-	stylesProcessor.setNormalizer( 'padding-left', data => ( { path: 'padding.left', value: data.value } ) );
+	stylesProcessor.setNormalizer( 'padding-top', value => ( { path: 'padding.top', value } ) );
+	stylesProcessor.setNormalizer( 'padding-right', value => ( { path: 'padding.right', value } ) );
+	stylesProcessor.setNormalizer( 'padding-bottom', value => ( { path: 'padding.bottom', value } ) );
+	stylesProcessor.setNormalizer( 'padding-left', value => ( { path: 'padding.left', value } ) );
 
 	stylesProcessor.setReducer( 'padding', getTopRightBottomLeftValueReducer( 'padding' ) );
 }

+ 2 - 2
packages/ckeditor5-engine/src/view/styles/utils.js

@@ -111,10 +111,10 @@ export function getTopRightBottomLeftShorthandValue( { left, right, top, bottom
 }
 
 export function getPositionShorthandNormalizer( longhand ) {
-	return data => {
+	return value => {
 		return {
 			path: longhand,
-			value: getTopRightBottomLeftValues( data.value )
+			value: getTopRightBottomLeftValues( value )
 		};
 	};
 }

+ 4 - 4
packages/ckeditor5-engine/tests/view/styles.js

@@ -14,13 +14,13 @@ describe( 'Styles', () => {
 		converter = new StylesProcessor();
 
 		// Define simple "foo" shorthand normalizers, similar to the "margin" shorthand normalizers, for testing purposes.
-		converter.setNormalizer( 'foo', data => ( {
+		converter.setNormalizer( 'foo', value => ( {
 			path: 'foo',
-			value: { top: data.value, right: data.value, bottom: data.value, left: data.value }
+			value: { top: value, right: value, bottom: value, left: value }
 		} ) );
-		converter.setNormalizer( 'foo-top', data => ( {
+		converter.setNormalizer( 'foo-top', value => ( {
 			path: 'foo',
-			value: { top: data.value }
+			value: { top: value }
 		} ) );
 
 		addPaddingStylesProcessor( converter );