Преглед изворни кода

Change how hasStyle() is checked due to table border converter issues.

Maciej Gołaszewski пре 6 година
родитељ
комит
ec5ca96baf

+ 14 - 20
packages/ckeditor5-table/src/tableproperties/utils.js

@@ -24,29 +24,23 @@ export function upcastAttribute( conversion, modelElement, modelAttribute, style
 
 export function upcastBorderStyles( conversion, viewElement ) {
 	conversion.for( 'upcast' ).add( dispatcher => dispatcher.on( 'element:' + viewElement, ( evt, data, conversionApi ) => {
-		let matcherPattern;
+		// TODO: this is counter-intuitive: ie.: if only `border-top` is defined then `hasStyle( 'border' )` also returns true.
+		// TODO: this might needs to be fixed in styles normalizer.
+		const stylesToConsume = [
+			'border-top',
+			'border-right',
+			'border-bottom',
+			'border-left'
+		].filter( styleName => data.viewItem.hasStyle( styleName ) );
 
-		if ( data.viewItem.hasStyle( 'border' ) ) {
-			matcherPattern = {
-				styles: [ 'border' ]
-			};
-		} else {
-			const stylesToConsume = [
-				'border-top',
-				'border-right',
-				'border-bottom',
-				'border-left'
-			].filter( styleName => data.viewItem.hasStyle( styleName ) );
-
-			if ( stylesToConsume.length ) {
-				matcherPattern = {
-					styles: stylesToConsume
-				};
-			} else {
-				return;
-			}
+		if ( !stylesToConsume.length ) {
+			return;
 		}
 
+		const matcherPattern = {
+			styles: stylesToConsume
+		};
+
 		// Try to consume appropriate values from consumable values list.
 		const toMatch = matcherPattern;
 

+ 12 - 0
packages/ckeditor5-table/tests/tablecellproperties.js

@@ -120,6 +120,18 @@ describe( 'TableCellProperties', () => {
 				assertTRBLAttribute( tableCell, 'borderWidth', null, null, null, '1px' );
 			} );
 
+			it( 'should upcast mixed shorthands', () => {
+				editor.setData(
+					'<table><tr><td style="border-top:1px solid #f00;border-bottom:2em ridge rgba(255,0,0,1)">foo</td></tr></table>'
+				);
+
+				const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
+
+				assertTRBLAttribute( tableCell, 'borderColor', '#f00', null, 'rgba(255, 0, 0, 1)', null );
+				assertTRBLAttribute( tableCell, 'borderStyle', 'solid', null, 'ridge', null );
+				assertTRBLAttribute( tableCell, 'borderWidth', '1px', null, '2em', null );
+			} );
+
 			it( 'should upcast border-top-* styles', () => {
 				editor.setData(
 					'<table><tr><td style="border-top-width:1px;border-top-style:solid;border-top-color:#f00">foo</td></tr></table>'