Parcourir la source

Add support for margin shorthand.

Maciej Gołaszewski il y a 6 ans
Parent
commit
b882ad5c78

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

@@ -179,6 +179,8 @@ function parseRule( key, value, styleObject ) {
 			bottom: { width: bottom },
 			left: { width: left }
 		} );
+	} else if ( key === 'margin' ) {
+		addStyle( styleObject, 'margin', getTopRightBottomLeftValues( value ) );
 	} else {
 		addStyle( styleObject, key, value );
 	}

+ 46 - 0
packages/ckeditor5-engine/tests/view/styles.js

@@ -238,6 +238,52 @@ describe( 'Styles', () => {
 			} );
 		} );
 
+		describe( 'margin', () => {
+			it( 'should set all margins (1 value defined)', () => {
+				styleProxy.setStyle( 'margin:1px;' );
+
+				expect( styleProxy.getModel( 'margin' ) ).to.deep.equal( {
+					top: '1px',
+					right: '1px',
+					bottom: '1px',
+					left: '1px'
+				} );
+			} );
+
+			it( 'should set all margins (2 values defined)', () => {
+				styleProxy.setStyle( 'margin:1px .34cm;' );
+
+				expect( styleProxy.getModel( 'margin' ) ).to.deep.equal( {
+					top: '1px',
+					right: '.34cm',
+					bottom: '1px',
+					left: '.34cm'
+				} );
+			} );
+
+			it( 'should set all margins (3 values defined)', () => {
+				styleProxy.setStyle( 'margin:1px .34cm 90.1rem;' );
+
+				expect( styleProxy.getModel( 'margin' ) ).to.deep.equal( {
+					top: '1px',
+					right: '.34cm',
+					bottom: '90.1rem',
+					left: '.34cm'
+				} );
+			} );
+
+			it( 'should set all margins (4 values defined)', () => {
+				styleProxy.setStyle( 'margin:1px .34cm 90.1rem thick;' );
+
+				expect( styleProxy.getModel( 'margin' ) ).to.deep.equal( {
+					top: '1px',
+					right: '.34cm',
+					bottom: '90.1rem',
+					left: 'thick'
+				} );
+			} );
+		} );
+
 		describe( 'unknown rules', () => {
 			it( 'should left rules untouched', () => {
 				styleProxy.setStyle( 'foo-bar:baz 1px abc;baz: 2px 3em;' );