8
0
Prechádzať zdrojové kódy

Update row height and column width conversion.

Maciej Gołaszewski 6 rokov pred
rodič
commit
65fc06e332

+ 4 - 6
packages/ckeditor5-table/src/tablecolumnrowproperites.js

@@ -28,16 +28,14 @@ export default class TableColumnRowProperties extends Plugin {
 	 */
 	afterInit() {
 		const editor = this.editor;
-		const model = editor.model;
-		const schema = model.schema;
+		const schema = editor.model.schema;
 		const conversion = editor.conversion;
 
-		// Table row attributes.
-		schema.extend( 'tableRow', {
+		schema.extend( 'tableCell', {
 			allowAttributes: [ 'height' ]
 		} );
-		upcastAttribute( conversion, 'tableRow', 'height', 'height' );
-		downcastToStyle( conversion, 'tableRow', 'height', 'height' );
+		upcastAttribute( conversion, 'tableCell', 'height', 'height' );
+		downcastToStyle( conversion, 'tableCell', 'height', 'height' );
 
 		schema.extend( 'tableCell', {
 			allowAttributes: [ 'width' ]

+ 57 - 15
packages/ckeditor5-table/tests/tablecolumnrowproperties.js

@@ -12,7 +12,7 @@ import TableColumnRowProperties from '../src/tablecolumnrowproperites';
 import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
-describe( 'TableColumnRowProperties', () => {
+describe.only( 'TableColumnRowProperties', () => {
 	let editor, model;
 
 	beforeEach( () => {
@@ -35,23 +35,65 @@ describe( 'TableColumnRowProperties', () => {
 		expect( TableColumnRowProperties.pluginName ).to.equal( 'TableColumnRowProperties' );
 	} );
 
-	it( 'should set proper schema rules', () => {
-		// expect( model.schema.checkAttribute( [ '$root', 'tableCell' ], 'width' ) ).to.be.true;
-		// expect( model.schema.checkAttribute( [ '$root', 'tableCell' ], 'height' ) ).to.be.true;
+	describe( 'column width', () => {
+		it( 'should set proper schema rules', () => {
+			expect( model.schema.checkAttribute( [ '$root', 'tableCell' ], 'width' ) ).to.be.true;
+		} );
+
+		describe( 'upcast conversion', () => {
+			it( 'should upcast width attribute on table cell', () => {
+				editor.setData( '<table><tr><td style="width:20px">foo</td></tr></table>' );
+				const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
+
+				expect( tableCell.getAttribute( 'width' ) ).to.equal( '20px' );
+			} );
+		} );
+
+		describe( 'downcast conversion', () => {
+			let tableCell;
+
+			beforeEach( () => {
+				setModelData(
+					model,
+					'<table headingRows="0" headingColumns="0">' +
+					'<tableRow>' +
+					'<tableCell>' +
+					'<paragraph>foo</paragraph>' +
+					'</tableCell>' +
+					'</tableRow>' +
+					'</table>'
+				);
+
+				tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
+			} );
+
+			it( 'should downcast width attribute', () => {
+				model.change( writer => writer.setAttribute( 'width', '20px', tableCell ) );
+
+				assertEqualMarkup(
+					editor.getData(),
+					'<figure class="table"><table><tbody><tr><td style="width:20px;">foo</td></tr></tbody></table></figure>'
+				);
+			} );
+		} );
 	} );
 
-	describe( 'conversion', () => {
-		describe( 'upcast', () => {
-			it( 'should upcast height attribute', () => {
-				editor.setData( '<table><tr style="height:20px"><td>foo</td></tr></table>' );
-				const tableRow = model.document.getRoot().getNodeByPath( [ 0, 0 ] );
+	describe( 'row height', () => {
+		it( 'should set proper schema rules', () => {
+			expect( model.schema.checkAttribute( [ '$root', 'tableCell' ], 'height' ) ).to.be.true;
+		} );
+
+		describe( 'upcast conversion', () => {
+			it( 'should upcast height attribute on table cell', () => {
+				editor.setData( '<table><tr><td style="height:20px">foo</td></tr></table>' );
+				const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
 
-				expect( tableRow.getAttribute( 'height' ) ).to.equal( '20px' );
+				expect( tableCell.getAttribute( 'height' ) ).to.equal( '20px' );
 			} );
 		} );
 
-		describe( 'downcast', () => {
-			let tableRow;
+		describe( 'downcast conversion', () => {
+			let tableCell;
 
 			beforeEach( () => {
 				setModelData(
@@ -65,15 +107,15 @@ describe( 'TableColumnRowProperties', () => {
 					'</table>'
 				);
 
-				tableRow = model.document.getRoot().getNodeByPath( [ 0, 0 ] );
+				tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );
 			} );
 
 			it( 'should downcast height attribute', () => {
-				model.change( writer => writer.setAttribute( 'height', '20px', tableRow ) );
+				model.change( writer => writer.setAttribute( 'height', '20px', tableCell ) );
 
 				assertEqualMarkup(
 					editor.getData(),
-					'<figure class="table"><table><tbody><tr style="height:20px;"><td>foo</td></tr></tbody></table></figure>'
+					'<figure class="table"><table><tbody><tr><td style="height:20px;">foo</td></tr></tbody></table></figure>'
 				);
 			} );
 		} );