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

Added: Support for heading cols in downcast conversion.

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

+ 4 - 1
packages/ckeditor5-table/src/converters.js

@@ -202,7 +202,10 @@ function isHead( tableCell ) {
 	const table = row.parent;
 	const rowIndex = table.getChildIndex( row );
 	const headingRows = table.getAttribute( 'headingRows' );
+	const headingColumns = table.getAttribute( 'headingColumns' );
 
-	return headingRows && headingRows > rowIndex;
+	const cellIndex = row.getChildIndex( tableCell );
+
+	return ( headingRows && headingRows > rowIndex ) || ( headingColumns && headingColumns > cellIndex );
 }
 

+ 1 - 1
packages/ckeditor5-table/src/tableediting.js

@@ -23,7 +23,7 @@ export default class TablesEditing extends Plugin {
 
 		schema.register( 'table', {
 			allowWhere: '$block',
-			allowAttributes: [ 'headingRows' ],
+			allowAttributes: [ 'headingRows', 'headingColumns' ],
 			isBlock: true,
 			isObject: true
 		} );

+ 39 - 1
packages/ckeditor5-table/tests/converters.js

@@ -26,7 +26,7 @@ describe( 'Table converters', () => {
 
 				schema.register( 'table', {
 					allowWhere: '$block',
-					allowAttributes: [ 'headingRows' ],
+					allowAttributes: [ 'headingRows', 'headingColumns' ],
 					isBlock: true,
 					isObject: true
 				} );
@@ -301,6 +301,44 @@ describe( 'Table converters', () => {
 			);
 		} );
 
+		it( 'should create table with headingColumns', () => {
+			setModelData( model,
+				'<table headingColumns="2">' +
+				'<tableRow><tableCell>11</tableCell><tableCell>12</tableCell><tableCell>13</tableCell></tableRow>' +
+				'<tableRow><tableCell>21</tableCell><tableCell>22</tableCell><tableCell>23</tableCell></tableRow>' +
+				'</table>'
+			);
+
+			expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
+				'<table>' +
+				'<tbody>' +
+				'<tr><th>11</th><th>12</th><td>13</td></tr>' +
+				'<tr><th>21</th><th>22</th><td>23</td></tr>' +
+				'</tbody>' +
+				'</table>'
+			);
+		} );
+
+		it( 'should create table with heading columns and rows', () => {
+			setModelData( model,
+				'<table headingColumns="2" headingRows="1">' +
+				'<tableRow><tableCell>11</tableCell><tableCell>12</tableCell><tableCell>13</tableCell></tableRow>' +
+				'<tableRow><tableCell>21</tableCell><tableCell>22</tableCell><tableCell>23</tableCell></tableRow>' +
+				'</table>'
+			);
+
+			expect( getViewData( viewDocument, { withoutSelection: true } ) ).to.equal(
+				'<table>' +
+				'<thead>' +
+				'<tr><th>11</th><th>12</th><th>13</th></tr>' +
+				'</thead>' +
+				'<tbody>' +
+				'<tr><th>21</th><th>22</th><td>23</td></tr>' +
+				'</tbody>' +
+				'</table>'
+			);
+		} );
+
 		it( 'should be possible to overwrite', () => {
 			editor.conversion.elementToElement( { model: 'tableRow', view: 'tr' } );
 			editor.conversion.for( 'downcast' ).add( dispatcher => {