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

Convert only top & bottom values for vertical-align.

Maciej Gołaszewski 6 лет назад
Родитель
Сommit
de3933272e

+ 33 - 1
packages/ckeditor5-table/src/tablecellproperties/tablecellpropertiesediting.js

@@ -92,7 +92,7 @@ export default class TableCellPropertiesEditing extends Plugin {
 		enableProperty( schema, conversion, 'backgroundColor', 'background-color' );
 		enableProperty( schema, conversion, 'backgroundColor', 'background-color' );
 		editor.commands.add( 'tableCellBackgroundColor', new TableCellBackgroundColorCommand( editor ) );
 		editor.commands.add( 'tableCellBackgroundColor', new TableCellBackgroundColorCommand( editor ) );
 
 
-		enableProperty( schema, conversion, 'verticalAlignment', 'vertical-align' );
+		enableVerticalAlignmentProperty( schema, conversion );
 		editor.commands.add( 'tableCellVerticalAlignment', new TableCellVerticalAlignmentCommand( editor ) );
 		editor.commands.add( 'tableCellVerticalAlignment', new TableCellVerticalAlignmentCommand( editor ) );
 	}
 	}
 }
 }
@@ -150,6 +150,38 @@ function enableHorizontalAlignmentProperty( schema, conversion ) {
 	} );
 	} );
 }
 }
 
 
+// Enables the `'verticalAlignment'` attribute for table cells.
+//
+// @param {module:engine/model/schema~Schema} schema
+// @param {module:engine/conversion/conversion~Conversion} conversion
+function enableVerticalAlignmentProperty( schema, conversion ) {
+	schema.extend( 'tableCell', {
+		allowAttributes: [ 'verticalAlignment' ]
+	} );
+
+	conversion.attributeToAttribute( {
+		model: {
+			name: 'tableCell',
+			key: 'verticalAlignment',
+			values: [ 'top', 'bottom' ]
+		},
+		view: {
+			top: {
+				key: 'style',
+				value: {
+					'vertical-align': 'top'
+				}
+			},
+			bottom: {
+				key: 'style',
+				value: {
+					'vertical-align': 'bottom'
+				}
+			}
+		}
+	} );
+}
+
 // Enables conversion for an attribute for simple view-model mappings.
 // Enables conversion for an attribute for simple view-model mappings.
 //
 //
 // @param {String} modelAttribute
 // @param {String} modelAttribute

+ 17 - 3
packages/ckeditor5-table/tests/tablecellproperties/tablecellpropertiesediting.js

@@ -783,12 +783,26 @@ describe( 'table cell properties', () => {
 			} );
 			} );
 
 
 			describe( 'upcast conversion', () => {
 			describe( 'upcast conversion', () => {
-				it( 'should upcast vertical-align', () => {
+				it( 'should upcast "top" vertical-align', () => {
 					editor.setData( '<table><tr><td style="vertical-align:top">foo</td></tr></table>' );
 					editor.setData( '<table><tr><td style="vertical-align:top">foo</td></tr></table>' );
 					const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
 					const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
 
 
 					expect( tableCell.getAttribute( 'verticalAlignment' ) ).to.equal( 'top' );
 					expect( tableCell.getAttribute( 'verticalAlignment' ) ).to.equal( 'top' );
 				} );
 				} );
+
+				it( 'should upcast "bottom" vertical-align', () => {
+					editor.setData( '<table><tr><td style="vertical-align:bottom">foo</td></tr></table>' );
+					const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
+
+					expect( tableCell.getAttribute( 'verticalAlignment' ) ).to.equal( 'bottom' );
+				} );
+
+				it( 'should not upcast "middle" vertical-align', () => {
+					editor.setData( '<table><tr><td style="vertical-align:middle">foo</td></tr></table>' );
+					const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
+
+					expect( tableCell.getAttribute( 'verticalAlignment' ) ).to.be.undefined;
+				} );
 			} );
 			} );
 
 
 			describe( 'downcast conversion', () => {
 			describe( 'downcast conversion', () => {
@@ -829,9 +843,9 @@ describe( 'table cell properties', () => {
 				} );
 				} );
 
 
 				it( 'should downcast verticalAlignment', () => {
 				it( 'should downcast verticalAlignment', () => {
-					model.change( writer => writer.setAttribute( 'verticalAlignment', 'middle', tableCell ) );
+					model.change( writer => writer.setAttribute( 'verticalAlignment', 'top', tableCell ) );
 
 
-					assertTableCellStyle( editor, 'vertical-align:middle;' );
+					assertTableCellStyle( editor, 'vertical-align:top;' );
 				} );
 				} );
 			} );
 			} );
 		} );
 		} );