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

Changed: Downcast conversion will work with a block content always present in the table.

Maciej Gołaszewski 7 лет назад
Родитель
Сommit
c3efd1a7ec
23 измененных файлов с 306 добавлено и 875 удалено
  1. 1 1
      packages/ckeditor5-table/src/commands/inserttablecommand.js
  2. 4 4
      packages/ckeditor5-table/src/commands/removecolumncommand.js
  3. 4 4
      packages/ckeditor5-table/src/commands/removerowcommand.js
  4. 5 5
      packages/ckeditor5-table/src/commands/setheadercolumncommand.js
  5. 8 7
      packages/ckeditor5-table/src/commands/setheaderrowcommand.js
  6. 4 3
      packages/ckeditor5-table/src/commands/splitcellcommand.js
  7. 24 1
      packages/ckeditor5-table/src/converters/downcast.js
  8. 4 2
      packages/ckeditor5-table/src/tableutils.js
  9. 87 8
      packages/ckeditor5-table/tests/_utils/utils.js
  10. 4 56
      packages/ckeditor5-table/tests/commands/insertcolumncommand.js
  11. 4 56
      packages/ckeditor5-table/tests/commands/insertrowcommand.js
  12. 10 60
      packages/ckeditor5-table/tests/commands/inserttablecommand.js
  13. 16 64
      packages/ckeditor5-table/tests/commands/mergecellcommand.js
  14. 9 59
      packages/ckeditor5-table/tests/commands/removecolumncommand.js
  15. 9 59
      packages/ckeditor5-table/tests/commands/removerowcommand.js
  16. 5 62
      packages/ckeditor5-table/tests/commands/setheadercolumncommand.js
  17. 5 56
      packages/ckeditor5-table/tests/commands/setheaderrowcommand.js
  18. 6 56
      packages/ckeditor5-table/tests/commands/splitcellcommand.js
  19. 5 38
      packages/ckeditor5-table/tests/commands/utils.js
  20. 65 178
      packages/ckeditor5-table/tests/converters/downcast.js
  21. 16 23
      packages/ckeditor5-table/tests/tableediting.js
  22. 6 55
      packages/ckeditor5-table/tests/tableutils.js
  23. 5 18
      packages/ckeditor5-table/tests/tablewalker.js

+ 1 - 1
packages/ckeditor5-table/src/commands/inserttablecommand.js

@@ -62,7 +62,7 @@ export default class InsertTableCommand extends Command {
 		model.change( writer => {
 			const table = tableUtils.createTable( insertPosition, rows, columns );
 
-			writer.setSelection( Position.createAt( table.getChild( 0 ).getChild( 0 ) ) );
+			writer.setSelection( Position.createAt( table.getChild( 0 ).getChild( 0 ).getChild( 0 ) ) );
 		} );
 	}
 }

+ 4 - 4
packages/ckeditor5-table/src/commands/removecolumncommand.js

@@ -11,7 +11,7 @@ import Command from '@ckeditor/ckeditor5-core/src/command';
 
 import TableWalker from '../tablewalker';
 import TableUtils from '../tableutils';
-import { updateNumericAttribute } from './utils';
+import { getParentElement, updateNumericAttribute } from './utils';
 
 /**
  * The remove column command.
@@ -33,9 +33,9 @@ export default class RemoveColumnCommand extends Command {
 		const selection = editor.model.document.selection;
 		const tableUtils = editor.plugins.get( TableUtils );
 
-		const selectedElement = selection.getFirstPosition().parent;
+		const tableCell = getParentElement( 'tableCell', selection.getFirstPosition() );
 
-		this.isEnabled = selectedElement.is( 'tableCell' ) && tableUtils.getColumns( selectedElement.parent.parent ) > 1;
+		this.isEnabled = !!tableCell && tableUtils.getColumns( tableCell.parent.parent ) > 1;
 	}
 
 	/**
@@ -47,7 +47,7 @@ export default class RemoveColumnCommand extends Command {
 
 		const firstPosition = selection.getFirstPosition();
 
-		const tableCell = firstPosition.parent;
+		const tableCell = getParentElement( 'tableCell', firstPosition );
 		const tableRow = tableCell.parent;
 		const table = tableRow.parent;
 

+ 4 - 4
packages/ckeditor5-table/src/commands/removerowcommand.js

@@ -12,7 +12,7 @@ import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 
 import TableWalker from '../tablewalker';
-import { updateNumericAttribute } from './utils';
+import { getParentElement, updateNumericAttribute } from './utils';
 
 /**
  * The remove row command.
@@ -33,9 +33,9 @@ export default class RemoveRowCommand extends Command {
 		const model = this.editor.model;
 		const doc = model.document;
 
-		const element = doc.selection.getFirstPosition().parent;
+		const tableCell = getParentElement( 'tableCell', doc.selection.getFirstPosition() );
 
-		this.isEnabled = element.is( 'tableCell' ) && element.parent.parent.childCount > 1;
+		this.isEnabled = !!tableCell && tableCell.parent.parent.childCount > 1;
 	}
 
 	/**
@@ -46,7 +46,7 @@ export default class RemoveRowCommand extends Command {
 		const selection = model.document.selection;
 
 		const firstPosition = selection.getFirstPosition();
-		const tableCell = firstPosition.parent;
+		const tableCell = getParentElement( 'tableCell', firstPosition );
 		const tableRow = tableCell.parent;
 		const table = tableRow.parent;
 

+ 5 - 5
packages/ckeditor5-table/src/commands/setheadercolumncommand.js

@@ -9,7 +9,7 @@
 
 import Command from '@ckeditor/ckeditor5-core/src/command';
 
-import { getParentTable, updateNumericAttribute } from './utils';
+import { getParentElement, updateNumericAttribute } from './utils';
 
 /**
  * The header column command.
@@ -36,9 +36,9 @@ export default class SetHeaderColumnCommand extends Command {
 		const selection = doc.selection;
 
 		const position = selection.getFirstPosition();
-		const tableParent = getParentTable( position );
+		const tableCell = getParentElement( 'tableCell', position );
 
-		const isInTable = !!tableParent;
+		const isInTable = !!tableCell;
 
 		this.isEnabled = isInTable;
 
@@ -50,7 +50,7 @@ export default class SetHeaderColumnCommand extends Command {
 		 * @readonly
 		 * @member {Boolean} #value
 		 */
-		this.value = isInTable && this._isInHeading( position.parent, tableParent );
+		this.value = isInTable && this._isInHeading( tableCell, tableCell.parent.parent );
 	}
 
 	/**
@@ -69,7 +69,7 @@ export default class SetHeaderColumnCommand extends Command {
 		const tableUtils = this.editor.plugins.get( 'TableUtils' );
 
 		const position = selection.getFirstPosition();
-		const tableCell = position.parent;
+		const tableCell = getParentElement( 'tableCell', position.parent );
 		const tableRow = tableCell.parent;
 		const table = tableRow.parent;
 

+ 8 - 7
packages/ckeditor5-table/src/commands/setheaderrowcommand.js

@@ -10,7 +10,7 @@
 import Command from '@ckeditor/ckeditor5-core/src/command';
 import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 
-import { getParentTable, updateNumericAttribute } from './utils';
+import { getParentElement, updateNumericAttribute } from './utils';
 import TableWalker from '../tablewalker';
 
 /**
@@ -37,9 +37,8 @@ export default class SetHeaderRowCommand extends Command {
 		const selection = doc.selection;
 
 		const position = selection.getFirstPosition();
-		const tableParent = getParentTable( position );
-
-		const isInTable = !!tableParent;
+		const tableCell = getParentElement( 'tableCell', position );
+		const isInTable = !!tableCell;
 
 		this.isEnabled = isInTable;
 
@@ -51,7 +50,7 @@ export default class SetHeaderRowCommand extends Command {
 		 * @readonly
 		 * @member {Boolean} #value
 		 */
-		this.value = isInTable && this._isInHeading( position.parent, tableParent );
+		this.value = isInTable && this._isInHeading( tableCell, tableCell.parent.parent );
 	}
 
 	/**
@@ -69,7 +68,7 @@ export default class SetHeaderRowCommand extends Command {
 		const selection = doc.selection;
 
 		const position = selection.getFirstPosition();
-		const tableCell = position.parent;
+		const tableCell = getParentElement( 'tableCell', position );
 		const tableRow = tableCell.parent;
 		const table = tableRow.parent;
 
@@ -173,7 +172,9 @@ function splitHorizontally( tableCell, headingRows, writer ) {
 		if ( columnIndex !== undefined && columnIndex === column && row === endRow ) {
 			const tableRow = table.getChild( row );
 
-			writer.insertElement( 'tableCell', attributes, Position.createFromParentAndOffset( tableRow, cellIndex ) );
+			const newCell = writer.createElement( 'tableCell', attributes );
+			writer.insert( newCell, Position.createFromParentAndOffset( tableRow, cellIndex ) );
+			writer.insertElement( 'paragraph', Position.createAt( newCell, 0 ) );
 		}
 	}
 

+ 4 - 3
packages/ckeditor5-table/src/commands/splitcellcommand.js

@@ -9,6 +9,7 @@
 
 import Command from '@ckeditor/ckeditor5-core/src/command';
 import TableUtils from '../tableutils';
+import { getParentElement } from './utils';
 
 /**
  * The split cell command.
@@ -49,9 +50,9 @@ export default class SplitCellCommand extends Command {
 		const model = this.editor.model;
 		const doc = model.document;
 
-		const element = doc.selection.getFirstPosition().parent;
+		const tableCell = getParentElement( 'tableCell', doc.selection.getFirstPosition() );
 
-		this.isEnabled = element.is( 'tableCell' );
+		this.isEnabled = !!tableCell;
 	}
 
 	/**
@@ -63,7 +64,7 @@ export default class SplitCellCommand extends Command {
 		const selection = document.selection;
 
 		const firstPosition = selection.getFirstPosition();
-		const tableCell = firstPosition.parent;
+		const tableCell = getParentElement( 'tableCell', firstPosition );
 
 		const isHorizontally = this.direction === 'horizontally';
 

+ 24 - 1
packages/ckeditor5-table/src/converters/downcast.js

@@ -368,8 +368,31 @@ function createViewTableCellElement( tableWalkerValue, tableAttributes, insertPo
 
 	const tableCell = tableWalkerValue.cell;
 
-	conversionApi.mapper.bindElements( tableCell, cellElement );
+	const isSingleParagraph = tableCell.childCount === 1 && tableCell.getChild( 0 ).name === 'paragraph';
+
 	conversionApi.writer.insert( insertPosition, cellElement );
+
+	if ( isSingleParagraph ) {
+		const innerParagraph = tableCell.getChild( 0 );
+		const paragraphInsertPosition = ViewPosition.createAt( cellElement, 'end' );
+
+		conversionApi.consumable.consume( innerParagraph, 'insert' );
+
+		if ( options.asWidget ) {
+			const fakeParagraph = conversionApi.writer.createContainerElement( 'span' );
+
+			conversionApi.mapper.bindElements( innerParagraph, fakeParagraph );
+			conversionApi.writer.insert( paragraphInsertPosition, fakeParagraph );
+
+			conversionApi.mapper.bindElements( tableCell, cellElement );
+		} else {
+			// TODO: binding two to one seems supspicious...
+			conversionApi.mapper.bindElements( tableCell, cellElement );
+			conversionApi.mapper.bindElements( innerParagraph, cellElement );
+		}
+	} else {
+		conversionApi.mapper.bindElements( tableCell, cellElement );
+	}
 }
 
 // Creates or returns an existing `<tr>` element from the view.

+ 4 - 2
packages/ckeditor5-table/src/tableutils.js

@@ -480,7 +480,7 @@ export default class TableUtils extends Plugin {
 					if ( isAfterSplitCell && isOnSameColumn && isInEvenlySplitRow ) {
 						const position = Position.createFromParentAndOffset( table.getChild( row ), cellIndex );
 
-						writer.insertElement( 'tableCell', newCellsAttributes, position );
+						createCells( 1, writer, position, newCellsAttributes );
 					}
 				}
 			}
@@ -569,7 +569,9 @@ function createEmptyRows( writer, table, insertAt, rows, tableCellToInsert, attr
 // @param {module:engine/model/position~Position} insertPosition
 function createCells( cells, writer, insertPosition, attributes = {} ) {
 	for ( let i = 0; i < cells; i++ ) {
-		writer.insertElement( 'tableCell', attributes, insertPosition );
+		const tableCell = writer.createElement( 'tableCell', attributes );
+		writer.insert( tableCell, insertPosition );
+		writer.insertElement( 'paragraph', Position.createAt( tableCell ) );
 	}
 }
 

+ 87 - 8
packages/ckeditor5-table/tests/_utils/utils.js

@@ -3,6 +3,16 @@
  * For licensing, see LICENSE.md.
  */
 
+import {
+	downcastInsertCell,
+	downcastInsertRow,
+	downcastInsertTable,
+	downcastRemoveRow,
+	downcastTableHeadingColumnsChange,
+	downcastTableHeadingRowsChange
+} from '../../src/converters/downcast';
+import upcastTable, { upcastTableCell } from '../../src/converters/upcasttable';
+
 /**
  * Returns a model representation of a table shorthand notation:
  *
@@ -31,7 +41,13 @@
  * @returns {String}
  */
 export function modelTable( tableData, attributes ) {
-	const tableRows = makeRows( tableData, 'tableCell', 'tableRow', 'tableCell' );
+	const tableRows = makeRows( tableData, {
+		cellElement: 'tableCell',
+		rowElement: 'tableRow',
+		headingElement: 'tableCell',
+		wrappingElement: 'paragraph',
+		enforceWrapping: true
+	} );
 
 	return `<table${ formatAttributes( attributes ) }>${ tableRows }</table>`;
 }
@@ -68,14 +84,25 @@ export function modelTable( tableData, attributes ) {
 export function viewTable( tableData, attributes = {} ) {
 	const headingRows = attributes.headingRows || 0;
 
-	const thead = headingRows > 0 ? `<thead>${ makeRows( tableData.slice( 0, headingRows ), 'th', 'tr' ) }</thead>` : '';
-	const tbody = tableData.length > headingRows ? `<tbody>${ makeRows( tableData.slice( headingRows ), 'td', 'tr' ) }</tbody>` : '';
+	const thead = headingRows > 0 ? `<thead>${ makeRows( tableData.slice( 0, headingRows ), {
+		cellElement: 'th',
+		rowElement: 'tr',
+		headingElement: 'th',
+		wrappingElement: 'p'
+	} ) }</thead>` : '';
+	const tbody = tableData.length > headingRows ?
+		`<tbody>${ makeRows( tableData.slice( headingRows ), {
+			cellElement: 'td',
+			rowElement: 'tr',
+			headingElement: 'th',
+			wrappingElement: 'p'
+		} ) }</tbody>` : '';
 
 	return `<figure class="table"><table>${ thead }${ tbody }</table></figure>`;
 }
 
 /**
- * Formats model or view table - useful for chai assertions debuging.
+ * Formats model or view table - useful for chai assertions debugging.
  *
  * @param {String} tableString
  * @returns {String}
@@ -118,6 +145,51 @@ export function formattedViewTable( tableData, attributes ) {
 	return formatTable( viewTable( tableData, attributes ) );
 }
 
+export function defaultSchema( schema ) {
+	schema.register( 'table', {
+		allowWhere: '$block',
+		allowAttributes: [ 'headingRows', 'headingColumns' ],
+		isObject: true
+	} );
+
+	schema.register( 'tableRow', { allowIn: 'table' } );
+
+	schema.register( 'tableCell', {
+		allowIn: 'tableRow',
+		allowContentOf: '$block',
+		allowAttributes: [ 'colspan', 'rowspan' ],
+		isLimit: true
+	} );
+
+	schema.extend( '$block', { allowIn: 'tableCell' } );
+	schema.register( 'paragraph', { inheritAllFrom: '$block' } );
+}
+
+export function defaultConversion( conversion, asWidget = false ) {
+	conversion.elementToElement( { model: 'paragraph', view: 'p' } );
+
+	// Table conversion.
+	conversion.for( 'upcast' ).add( upcastTable() );
+	conversion.for( 'downcast' ).add( downcastInsertTable( { asWidget } ) );
+
+	// Table row conversion.
+	conversion.for( 'downcast' ).add( downcastInsertRow( { asWidget } ) );
+	conversion.for( 'downcast' ).add( downcastRemoveRow( { asWidget } ) );
+
+	// Table cell conversion.
+	conversion.for( 'downcast' ).add( downcastInsertCell( { asWidget } ) );
+	conversion.for( 'upcast' ).add( upcastTableCell() );
+	// conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
+	// conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'th' } ) );
+
+	// Table attributes conversion.
+	conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
+	conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
+
+	conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange( { asWidget } ) );
+	conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange( { asWidget } ) );
+}
+
 // Formats table cell attributes
 //
 // @param {Object} attributes Attributes of a cell.
@@ -135,19 +207,22 @@ function formatAttributes( attributes ) {
 }
 
 // Formats passed table data to a set of table rows.
-function makeRows( tableData, cellElement, rowElement, headingElement = 'th' ) {
+function makeRows( tableData, options ) {
+	const { cellElement, rowElement, headingElement, wrappingElement, enforceWrapping } = options;
+
 	return tableData
 		.reduce( ( previousRowsString, tableRow ) => {
 			const tableRowString = tableRow.reduce( ( tableRowString, tableCellData ) => {
-				let tableCell = tableCellData;
+				let contents = tableCellData;
 
 				const isObject = typeof tableCellData === 'object';
 
 				let resultingCellElement = cellElement;
 
 				if ( isObject ) {
-					tableCell = tableCellData.contents;
+					contents = tableCellData.contents;
 
+					// TODO: check...
 					if ( tableCellData.isHeading ) {
 						resultingCellElement = headingElement;
 					}
@@ -156,8 +231,12 @@ function makeRows( tableData, cellElement, rowElement, headingElement = 'th' ) {
 					delete tableCellData.isHeading;
 				}
 
+				if ( !( contents.replace( '[', '' ).replace( ']', '' ).startsWith( '<' ) ) && enforceWrapping ) {
+					contents = `<${ wrappingElement }>${ contents }</${ wrappingElement }>`;
+				}
+
 				const formattedAttributes = formatAttributes( isObject ? tableCellData : '' );
-				tableRowString += `<${ resultingCellElement }${ formattedAttributes }>${ tableCell }</${ resultingCellElement }>`;
+				tableRowString += `<${ resultingCellElement }${ formattedAttributes }>${ contents }</${ resultingCellElement }>`;
 
 				return tableRowString;
 			}, '' );

+ 4 - 56
packages/ckeditor5-table/tests/commands/insertcolumncommand.js

@@ -4,20 +4,10 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
-import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
+import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 import InsertColumnCommand from '../../src/commands/insertcolumncommand';
-import {
-	downcastInsertCell,
-	downcastInsertRow,
-	downcastInsertTable,
-	downcastRemoveRow,
-	downcastTableHeadingColumnsChange,
-	downcastTableHeadingRowsChange
-} from '../../src/converters/downcast';
-import upcastTable from '../../src/converters/upcasttable';
-import { formatTable, formattedModelTable, modelTable } from '../_utils/utils';
+import { defaultConversion, defaultSchema, formatTable, formattedModelTable, modelTable } from '../_utils/utils';
 import TableUtils from '../../src/tableutils';
 
 describe( 'InsertColumnCommand', () => {
@@ -32,50 +22,8 @@ describe( 'InsertColumnCommand', () => {
 				editor = newEditor;
 				model = editor.model;
 
-				const conversion = editor.conversion;
-				const schema = model.schema;
-
-				schema.register( 'table', {
-					allowWhere: '$block',
-					allowAttributes: [ 'headingRows' ],
-					isObject: true
-				} );
-
-				schema.register( 'tableRow', { allowIn: 'table' } );
-
-				schema.register( 'tableCell', {
-					allowIn: 'tableRow',
-					allowContentOf: '$block',
-					allowAttributes: [ 'colspan', 'rowspan' ],
-					isLimit: true
-				} );
-
-				schema.extend( '$block', { allowIn: 'tableCell' } );
-
-				model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
-
-				// Table conversion.
-				conversion.for( 'upcast' ).add( upcastTable() );
-				conversion.for( 'downcast' ).add( downcastInsertTable() );
-
-				// Insert row conversion.
-				conversion.for( 'downcast' ).add( downcastInsertRow() );
-
-				// Remove row conversion.
-				conversion.for( 'downcast' ).add( downcastRemoveRow() );
-
-				// Table cell conversion.
-				conversion.for( 'downcast' ).add( downcastInsertCell() );
-
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'th' } ) );
-
-				// Table attributes conversion.
-				conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-				conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
-
-				conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange() );
-				conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange() );
+				defaultSchema( model.schema );
+				defaultConversion( editor.conversion );
 			} );
 	} );
 

+ 4 - 56
packages/ckeditor5-table/tests/commands/insertrowcommand.js

@@ -4,20 +4,10 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
-import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
+import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 import InsertRowCommand from '../../src/commands/insertrowcommand';
-import {
-	downcastInsertCell,
-	downcastInsertRow,
-	downcastInsertTable,
-	downcastRemoveRow,
-	downcastTableHeadingColumnsChange,
-	downcastTableHeadingRowsChange
-} from '../../src/converters/downcast';
-import upcastTable from '../../src/converters/upcasttable';
-import { formatTable, formattedModelTable, modelTable } from '../_utils/utils';
+import { defaultConversion, defaultSchema, formatTable, formattedModelTable, modelTable } from '../_utils/utils';
 import TableUtils from '../../src/tableutils';
 
 describe( 'InsertRowCommand', () => {
@@ -32,50 +22,8 @@ describe( 'InsertRowCommand', () => {
 				editor = newEditor;
 				model = editor.model;
 
-				const conversion = editor.conversion;
-				const schema = model.schema;
-
-				schema.register( 'table', {
-					allowWhere: '$block',
-					allowAttributes: [ 'headingRows' ],
-					isObject: true
-				} );
-
-				schema.register( 'tableRow', { allowIn: 'table' } );
-
-				schema.register( 'tableCell', {
-					allowIn: 'tableRow',
-					allowContentOf: '$block',
-					allowAttributes: [ 'colspan', 'rowspan' ],
-					isLimit: true
-				} );
-
-				schema.extend( '$block', { allowIn: 'tableCell' } );
-
-				model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
-
-				// Table conversion.
-				conversion.for( 'upcast' ).add( upcastTable() );
-				conversion.for( 'downcast' ).add( downcastInsertTable() );
-
-				// Insert row conversion.
-				conversion.for( 'downcast' ).add( downcastInsertRow() );
-
-				// Remove row conversion.
-				conversion.for( 'downcast' ).add( downcastRemoveRow() );
-
-				// Table cell conversion.
-				conversion.for( 'downcast' ).add( downcastInsertCell() );
-
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'th' } ) );
-
-				// Table attributes conversion.
-				conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-				conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
-
-				conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange() );
-				conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange() );
+				defaultSchema( model.schema );
+				defaultConversion( editor.conversion );
 			} );
 	} );
 

+ 10 - 60
packages/ckeditor5-table/tests/commands/inserttablecommand.js

@@ -4,22 +4,12 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
-import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
+import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 import InsertTableCommand from '../../src/commands/inserttablecommand';
-import {
-	downcastInsertCell,
-	downcastInsertRow,
-	downcastInsertTable,
-	downcastRemoveRow,
-	downcastTableHeadingColumnsChange,
-	downcastTableHeadingRowsChange
-} from '../../src/converters/downcast';
-import upcastTable from '../../src/converters/upcasttable';
 import TableUtils from '../../src/tableutils';
 
-import { formatTable, formattedModelTable } from '../_utils/utils';
+import { defaultConversion, defaultSchema, formatTable, formattedModelTable } from '../_utils/utils';
 
 describe( 'InsertTableCommand', () => {
 	let editor, model, command;
@@ -34,48 +24,8 @@ describe( 'InsertTableCommand', () => {
 				model = editor.model;
 				command = new InsertTableCommand( editor );
 
-				const conversion = editor.conversion;
-				const schema = model.schema;
-
-				schema.register( 'table', {
-					allowWhere: '$block',
-					allowAttributes: [ 'headingRows' ],
-					isObject: true
-				} );
-
-				schema.register( 'tableRow', { allowIn: 'table' } );
-
-				schema.register( 'tableCell', {
-					allowIn: 'tableRow',
-					allowContentOf: '$block',
-					allowAttributes: [ 'colspan', 'rowspan' ],
-					isLimit: true
-				} );
-
-				model.schema.register( 'p', { inheritAllFrom: '$block' } );
-
-				// Table conversion.
-				conversion.for( 'upcast' ).add( upcastTable() );
-				conversion.for( 'downcast' ).add( downcastInsertTable() );
-
-				// Insert row conversion.
-				conversion.for( 'downcast' ).add( downcastInsertRow() );
-
-				// Remove row conversion.
-				conversion.for( 'downcast' ).add( downcastRemoveRow() );
-
-				// Table cell conversion.
-				conversion.for( 'downcast' ).add( downcastInsertCell() );
-
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'th' } ) );
-
-				// Table attributes conversion.
-				conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-				conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
-
-				conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange() );
-				conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange() );
+				defaultSchema( model.schema );
+				defaultConversion( editor.conversion );
 			} );
 	} );
 
@@ -86,7 +36,7 @@ describe( 'InsertTableCommand', () => {
 	describe( 'isEnabled', () => {
 		describe( 'when selection is collapsed', () => {
 			it( 'should be true if in paragraph', () => {
-				setData( model, '<p>foo[]</p>' );
+				setData( model, '<paragraph>foo[]</paragraph>' );
 				expect( command.isEnabled ).to.be.true;
 			} );
 
@@ -99,7 +49,7 @@ describe( 'InsertTableCommand', () => {
 
 	describe( 'execute()', () => {
 		it( 'should create a single batch', () => {
-			setData( model, '<p>foo[]</p>' );
+			setData( model, '<paragraph>foo[]</paragraph>' );
 
 			const spy = sinon.spy();
 
@@ -123,12 +73,12 @@ describe( 'InsertTableCommand', () => {
 			} );
 
 			it( 'should insert table with two rows and two columns after non-empty paragraph', () => {
-				setData( model, '<p>foo[]</p>' );
+				setData( model, '<paragraph>foo[]</paragraph>' );
 
 				command.execute();
 
 				expect( formatTable( getData( model ) ) ).to.equal(
-					'<p>foo</p>' +
+					'<paragraph>foo</paragraph>' +
 					formattedModelTable( [
 						[ '[]', '' ],
 						[ '', '' ]
@@ -137,12 +87,12 @@ describe( 'InsertTableCommand', () => {
 			} );
 
 			it( 'should insert table with given rows and columns after non-empty paragraph', () => {
-				setData( model, '<p>foo[]</p>' );
+				setData( model, '<paragraph>foo[]</paragraph>' );
 
 				command.execute( { rows: 3, columns: 4 } );
 
 				expect( formatTable( getData( model ) ) ).to.equal(
-					'<p>foo</p>' +
+					'<paragraph>foo</paragraph>' +
 					formattedModelTable( [
 						[ '[]', '', '', '' ],
 						[ '', '', '', '' ],

+ 16 - 64
packages/ckeditor5-table/tests/commands/mergecellcommand.js

@@ -5,19 +5,9 @@
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
 
 import MergeCellCommand from '../../src/commands/mergecellcommand';
-import {
-	downcastInsertCell,
-	downcastInsertRow,
-	downcastInsertTable,
-	downcastRemoveRow,
-	downcastTableHeadingColumnsChange,
-	downcastTableHeadingRowsChange
-} from '../../src/converters/downcast';
-import upcastTable from '../../src/converters/upcasttable';
-import { formatTable, formattedModelTable, modelTable } from '../_utils/utils';
+import { defaultConversion, defaultSchema, formatTable, formattedModelTable, modelTable } from '../_utils/utils';
 import TableUtils from '../../src/tableutils';
 
 describe( 'MergeCellCommand', () => {
@@ -33,50 +23,8 @@ describe( 'MergeCellCommand', () => {
 				model = editor.model;
 				root = model.document.getRoot( 'main' );
 
-				const conversion = editor.conversion;
-				const schema = model.schema;
-
-				schema.register( 'table', {
-					allowWhere: '$block',
-					allowAttributes: [ 'headingRows' ],
-					isObject: true
-				} );
-
-				schema.register( 'tableRow', { allowIn: 'table' } );
-
-				schema.register( 'tableCell', {
-					allowIn: 'tableRow',
-					allowContentOf: '$block',
-					allowAttributes: [ 'colspan', 'rowspan' ],
-					isLimit: true
-				} );
-
-				schema.extend( '$block', { allowIn: 'tableCell' } );
-
-				model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
-
-				// Table conversion.
-				conversion.for( 'upcast' ).add( upcastTable() );
-				conversion.for( 'downcast' ).add( downcastInsertTable() );
-
-				// Insert row conversion.
-				conversion.for( 'downcast' ).add( downcastInsertRow() );
-
-				// Remove row conversion.
-				conversion.for( 'downcast' ).add( downcastRemoveRow() );
-
-				// Table cell conversion.
-				conversion.for( 'downcast' ).add( downcastInsertCell() );
-
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'th' } ) );
-
-				// Table attributes conversion.
-				conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-				conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
-
-				conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange() );
-				conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange() );
+				defaultSchema( model.schema );
+				defaultConversion( editor.conversion );
 			} );
 	} );
 
@@ -204,7 +152,7 @@ describe( 'MergeCellCommand', () => {
 				command.execute();
 
 				expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
-					[ { colspan: 2, contents: '[0001]' } ]
+					[ { colspan: 2, contents: '[<paragraph>00</paragraph><paragraph>01</paragraph>]' } ]
 				] ) );
 			} );
 		} );
@@ -330,7 +278,7 @@ describe( 'MergeCellCommand', () => {
 				command.execute();
 
 				expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
-					[ { colspan: 2, contents: '[0001]' } ]
+					[ { colspan: 2, contents: '[<paragraph>00</paragraph><paragraph>01</paragraph>]' } ]
 				] ) );
 			} );
 		} );
@@ -458,7 +406,7 @@ describe( 'MergeCellCommand', () => {
 				command.execute();
 
 				expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
-					[ '00', { rowspan: 2, contents: '[0111]' } ],
+					[ '00', { rowspan: 2, contents: '[<paragraph>01</paragraph><paragraph>11</paragraph>]' } ],
 					[ '10' ]
 				] ) );
 			} );
@@ -473,7 +421,7 @@ describe( 'MergeCellCommand', () => {
 				command.execute();
 
 				expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
-					[ '00', '[0111]', { rowspan: 2, contents: '02' } ],
+					[ '00', '[<paragraph>01</paragraph><paragraph>11</paragraph>]', { rowspan: 2, contents: '02' } ],
 					[ '20', '21' ]
 				] ) );
 			} );
@@ -492,7 +440,7 @@ describe( 'MergeCellCommand', () => {
 				expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
 					[ { rowspan: 2, contents: '00' }, '01', '02' ],
 					[ '11', '12' ],
-					[ '20', '[2131]', { rowspan: 2, contents: '22' } ],
+					[ '20', '[<paragraph>21</paragraph><paragraph>31</paragraph>]', { rowspan: 2, contents: '22' } ],
 					[ '40', '41' ]
 				] ) );
 			} );
@@ -632,7 +580,7 @@ describe( 'MergeCellCommand', () => {
 				command.execute();
 
 				expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
-					[ '00', { rowspan: 2, contents: '[0111]' } ],
+					[ '00', { rowspan: 2, contents: '[<paragraph>01</paragraph><paragraph>11</paragraph>]' } ],
 					[ '10' ]
 				] ) );
 			} );
@@ -649,7 +597,11 @@ describe( 'MergeCellCommand', () => {
 
 				expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
 					[ { rowspan: 3, contents: '00' }, '11', '12', '13' ],
-					[ { rowspan: 2, contents: '21' }, '22', { rowspan: 3, contents: '[2333]' } ],
+					[
+						{ rowspan: 2, contents: '21' },
+						'22',
+						{ rowspan: 3, contents: '[<paragraph>23</paragraph><paragraph>33</paragraph>]' }
+					],
 					[ '32' ],
 					[ { colspan: 2, contents: '40' }, '42' ]
 				] ) );
@@ -665,7 +617,7 @@ describe( 'MergeCellCommand', () => {
 				command.execute();
 
 				expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
-					[ '00', '[0111]', { rowspan: 2, contents: '02' } ],
+					[ '00', '[<paragraph>01</paragraph><paragraph>11</paragraph>]', { rowspan: 2, contents: '02' } ],
 					[ '20', '21' ]
 				] ) );
 			} );
@@ -684,7 +636,7 @@ describe( 'MergeCellCommand', () => {
 				expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
 					[ { rowspan: 2, contents: '00' }, '01', '02' ],
 					[ '11', '12' ],
-					[ '20', '[2131]', { rowspan: 2, contents: '22' } ],
+					[ '20', '[<paragraph>21</paragraph><paragraph>31</paragraph>]', { rowspan: 2, contents: '22' } ],
 					[ '40', '41' ]
 				] ) );
 			} );

+ 9 - 59
packages/ckeditor5-table/tests/commands/removecolumncommand.js

@@ -4,20 +4,10 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
-import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
+import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 import RemoveColumnCommand from '../../src/commands/removecolumncommand';
-import {
-	downcastInsertCell,
-	downcastInsertRow,
-	downcastInsertTable,
-	downcastRemoveRow,
-	downcastTableHeadingColumnsChange,
-	downcastTableHeadingRowsChange
-} from '../../src/converters/downcast';
-import upcastTable from '../../src/converters/upcasttable';
-import { formatTable, formattedModelTable, modelTable } from '../_utils/utils';
+import { defaultConversion, defaultSchema, formatTable, formattedModelTable, modelTable } from '../_utils/utils';
 import TableUtils from '../../src/tableutils';
 
 describe( 'RemoveColumnCommand', () => {
@@ -33,48 +23,8 @@ describe( 'RemoveColumnCommand', () => {
 				model = editor.model;
 				command = new RemoveColumnCommand( editor );
 
-				const conversion = editor.conversion;
-				const schema = model.schema;
-
-				schema.register( 'table', {
-					allowWhere: '$block',
-					allowAttributes: [ 'headingRows', 'headingColumns' ],
-					isObject: true
-				} );
-
-				schema.register( 'tableRow', { allowIn: 'table' } );
-
-				schema.register( 'tableCell', {
-					allowIn: 'tableRow',
-					allowContentOf: '$block',
-					allowAttributes: [ 'colspan', 'rowspan' ],
-					isLimit: true
-				} );
-
-				model.schema.register( 'p', { inheritAllFrom: '$block' } );
-
-				// Table conversion.
-				conversion.for( 'upcast' ).add( upcastTable() );
-				conversion.for( 'downcast' ).add( downcastInsertTable() );
-
-				// Insert row conversion.
-				conversion.for( 'downcast' ).add( downcastInsertRow() );
-
-				// Remove row conversion.
-				conversion.for( 'downcast' ).add( downcastRemoveRow() );
-
-				// Table cell conversion.
-				conversion.for( 'downcast' ).add( downcastInsertCell() );
-
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'th' } ) );
-
-				// Table attributes conversion.
-				conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-				conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
-
-				conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange() );
-				conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange() );
+				defaultSchema( model.schema );
+				defaultConversion( editor.conversion );
 			} );
 	} );
 
@@ -103,7 +53,7 @@ describe( 'RemoveColumnCommand', () => {
 		} );
 
 		it( 'should be false if selection is outside a table', () => {
-			setData( model, '<p>11[]</p>' );
+			setData( model, '<paragraph>11[]</paragraph>' );
 
 			expect( command.isEnabled ).to.be.false;
 		} );
@@ -121,7 +71,7 @@ describe( 'RemoveColumnCommand', () => {
 
 			expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
 				[ '00', '02' ],
-				[ '10[]', '12' ],
+				[ '<paragraph>10</paragraph>[]', '12' ],
 				[ '20', '22' ]
 			] ) );
 		} );
@@ -136,7 +86,7 @@ describe( 'RemoveColumnCommand', () => {
 			command.execute();
 
 			expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
-				[ '[]01' ],
+				[ '[]<paragraph>01</paragraph>' ],
 				[ '11' ],
 				[ '21' ]
 			] ) );
@@ -153,7 +103,7 @@ describe( 'RemoveColumnCommand', () => {
 
 			expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
 				[ '01' ],
-				[ '[]11' ],
+				[ '[]<paragraph>11</paragraph>' ],
 				[ '21' ]
 			], { headingColumns: 1 } ) );
 		} );
@@ -172,7 +122,7 @@ describe( 'RemoveColumnCommand', () => {
 			expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
 				[ { colspan: 3, contents: '00' }, '03' ],
 				[ { colspan: 2, contents: '10' }, '13' ],
-				[ { colspan: 2, contents: '20[]' }, '23' ],
+				[ { colspan: 2, contents: '<paragraph>20</paragraph>[]' }, '23' ],
 				[ '30', '31', '33' ],
 				[ '40', '41', '43' ]
 

+ 9 - 59
packages/ckeditor5-table/tests/commands/removerowcommand.js

@@ -4,20 +4,10 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
-import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
+import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 import RemoveRowCommand from '../../src/commands/removerowcommand';
-import {
-	downcastInsertCell,
-	downcastInsertRow,
-	downcastInsertTable,
-	downcastRemoveRow,
-	downcastTableHeadingColumnsChange,
-	downcastTableHeadingRowsChange
-} from '../../src/converters/downcast';
-import upcastTable from '../../src/converters/upcasttable';
-import { formatTable, formattedModelTable, modelTable } from '../_utils/utils';
+import { defaultConversion, defaultSchema, formatTable, formattedModelTable, modelTable } from '../_utils/utils';
 
 describe( 'RemoveRowCommand', () => {
 	let editor, model, command;
@@ -29,48 +19,8 @@ describe( 'RemoveRowCommand', () => {
 				model = editor.model;
 				command = new RemoveRowCommand( editor );
 
-				const conversion = editor.conversion;
-				const schema = model.schema;
-
-				schema.register( 'table', {
-					allowWhere: '$block',
-					allowAttributes: [ 'headingRows' ],
-					isObject: true
-				} );
-
-				schema.register( 'tableRow', { allowIn: 'table' } );
-
-				schema.register( 'tableCell', {
-					allowIn: 'tableRow',
-					allowContentOf: '$block',
-					allowAttributes: [ 'colspan', 'rowspan' ],
-					isLimit: true
-				} );
-
-				model.schema.register( 'p', { inheritAllFrom: '$block' } );
-
-				// Table conversion.
-				conversion.for( 'upcast' ).add( upcastTable() );
-				conversion.for( 'downcast' ).add( downcastInsertTable() );
-
-				// Insert row conversion.
-				conversion.for( 'downcast' ).add( downcastInsertRow() );
-
-				// Remove row conversion.
-				conversion.for( 'downcast' ).add( downcastRemoveRow() );
-
-				// Table cell conversion.
-				conversion.for( 'downcast' ).add( downcastInsertCell() );
-
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'th' } ) );
-
-				// Table attributes conversion.
-				conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-				conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
-
-				conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange() );
-				conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange() );
+				defaultSchema( model.schema );
+				defaultConversion( editor.conversion );
 			} );
 	} );
 
@@ -97,7 +47,7 @@ describe( 'RemoveRowCommand', () => {
 		} );
 
 		it( 'should be false if selection is outside a table', () => {
-			setData( model, '<p>11[]</p>' );
+			setData( model, '<paragraph>11[]</paragraph>' );
 
 			expect( command.isEnabled ).to.be.false;
 		} );
@@ -114,7 +64,7 @@ describe( 'RemoveRowCommand', () => {
 			command.execute();
 
 			expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
-				[ '00', '01[]' ],
+				[ '00', '<paragraph>01</paragraph>[]' ],
 				[ '20', '21' ]
 			] ) );
 		} );
@@ -129,7 +79,7 @@ describe( 'RemoveRowCommand', () => {
 			command.execute();
 
 			expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
-				[ '[]10', '11' ],
+				[ '[]<paragraph>10</paragraph>', '11' ],
 				[ '20', '21' ]
 			] ) );
 		} );
@@ -144,7 +94,7 @@ describe( 'RemoveRowCommand', () => {
 			command.execute();
 
 			expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
-				[ '00', '01[]' ],
+				[ '00', '<paragraph>01</paragraph>[]' ],
 				[ '20', '21' ]
 			], { headingRows: 1 } ) );
 		} );
@@ -161,7 +111,7 @@ describe( 'RemoveRowCommand', () => {
 
 			expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
 				[ { rowspan: 3, contents: '00' }, { rowspan: 2, contents: '01' }, { rowspan: 2, contents: '02' }, '03', '04' ],
-				[ '13', '14[]' ],
+				[ '13', '<paragraph>14</paragraph>[]' ],
 				[ '30', '31', '32', '33', '34' ]
 			] ) );
 		} );

+ 5 - 62
packages/ckeditor5-table/tests/commands/setheadercolumncommand.js

@@ -4,20 +4,10 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
-import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
+import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 import SetHeaderColumnCommand from '../../src/commands/setheadercolumncommand';
-import {
-	downcastInsertCell,
-	downcastInsertRow,
-	downcastInsertTable,
-	downcastRemoveRow,
-	downcastTableHeadingColumnsChange,
-	downcastTableHeadingRowsChange
-} from '../../src/converters/downcast';
-import upcastTable from '../../src/converters/upcasttable';
-import { formatTable, formattedModelTable, modelTable } from '../_utils/utils';
+import { defaultConversion, defaultSchema, formatTable, formattedModelTable, modelTable } from '../_utils/utils';
 import TableUtils from '../../src/tableutils';
 
 describe( 'HeaderColumnCommand', () => {
@@ -33,55 +23,8 @@ describe( 'HeaderColumnCommand', () => {
 				model = editor.model;
 				command = new SetHeaderColumnCommand( editor );
 
-				const conversion = editor.conversion;
-				const schema = model.schema;
-
-				schema.register( 'table', {
-					allowWhere: '$block',
-					allowAttributes: [ 'headingRows' ],
-					isBlock: true,
-					isObject: true
-				} );
-
-				schema.register( 'tableRow', {
-					allowIn: 'table',
-					allowAttributes: [],
-					isBlock: true,
-					isLimit: true
-				} );
-
-				schema.register( 'tableCell', {
-					allowIn: 'tableRow',
-					allowContentOf: '$block',
-					allowAttributes: [ 'colspan', 'rowspan' ],
-					isBlock: true,
-					isLimit: true
-				} );
-
-				model.schema.register( 'p', { inheritAllFrom: '$block' } );
-
-				// Table conversion.
-				conversion.for( 'upcast' ).add( upcastTable() );
-				conversion.for( 'downcast' ).add( downcastInsertTable() );
-
-				// Insert row conversion.
-				conversion.for( 'downcast' ).add( downcastInsertRow() );
-
-				// Remove row conversion.
-				conversion.for( 'downcast' ).add( downcastRemoveRow() );
-
-				// Table cell conversion.
-				conversion.for( 'downcast' ).add( downcastInsertCell() );
-
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'th' } ) );
-
-				// Table attributes conversion.
-				conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-				conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
-
-				conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange() );
-				conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange() );
+				defaultSchema( model.schema );
+				defaultConversion( editor.conversion );
 			} );
 	} );
 
@@ -91,7 +34,7 @@ describe( 'HeaderColumnCommand', () => {
 
 	describe( 'isEnabled', () => {
 		it( 'should be false if selection is not in a table', () => {
-			setData( model, '<p>foo[]</p>' );
+			setData( model, '<paragraph>foo[]</paragraph>' );
 			expect( command.isEnabled ).to.be.false;
 		} );
 

+ 5 - 56
packages/ckeditor5-table/tests/commands/setheaderrowcommand.js

@@ -4,20 +4,9 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
-import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
+import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import SetHeaderRowCommand from '../../src/commands/setheaderrowcommand';
-
-import {
-	downcastInsertCell,
-	downcastInsertRow,
-	downcastInsertTable,
-	downcastRemoveRow,
-	downcastTableHeadingColumnsChange,
-	downcastTableHeadingRowsChange
-} from '../../src/converters/downcast';
-import upcastTable from '../../src/converters/upcasttable';
-import { formatTable, formattedModelTable, modelTable } from '../_utils/utils';
+import { defaultConversion, defaultSchema, formatTable, formattedModelTable, modelTable } from '../_utils/utils';
 import TableUtils from '../../src/tableutils';
 
 describe( 'HeaderRowCommand', () => {
@@ -33,48 +22,8 @@ describe( 'HeaderRowCommand', () => {
 				model = editor.model;
 				command = new SetHeaderRowCommand( editor );
 
-				const conversion = editor.conversion;
-				const schema = model.schema;
-
-				schema.register( 'table', {
-					allowWhere: '$block',
-					allowAttributes: [ 'headingRows' ],
-					isObject: true
-				} );
-
-				schema.register( 'tableRow', { allowIn: 'table' } );
-
-				schema.register( 'tableCell', {
-					allowIn: 'tableRow',
-					allowContentOf: '$block',
-					allowAttributes: [ 'colspan', 'rowspan' ],
-					isLimit: true
-				} );
-
-				model.schema.register( 'p', { inheritAllFrom: '$block' } );
-
-				// Table conversion.
-				conversion.for( 'upcast' ).add( upcastTable() );
-				conversion.for( 'downcast' ).add( downcastInsertTable() );
-
-				// Insert row conversion.
-				conversion.for( 'downcast' ).add( downcastInsertRow() );
-
-				// Remove row conversion.
-				conversion.for( 'downcast' ).add( downcastRemoveRow() );
-
-				// Table cell conversion.
-				conversion.for( 'downcast' ).add( downcastInsertCell() );
-
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'th' } ) );
-
-				// Table attributes conversion.
-				conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-				conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
-
-				conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange() );
-				conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange() );
+				defaultSchema( model.schema );
+				defaultConversion( editor.conversion );
 			} );
 	} );
 
@@ -84,7 +33,7 @@ describe( 'HeaderRowCommand', () => {
 
 	describe( 'isEnabled', () => {
 		it( 'should be false if selection is not in a table', () => {
-			setData( model, '<p>foo[]</p>' );
+			setData( model, '<paragraph>foo[]</paragraph>' );
 			expect( command.isEnabled ).to.be.false;
 		} );
 

+ 6 - 56
packages/ckeditor5-table/tests/commands/splitcellcommand.js

@@ -4,20 +4,10 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
-import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
+import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 import SplitCellCommand from '../../src/commands/splitcellcommand';
-import {
-	downcastInsertCell,
-	downcastInsertRow,
-	downcastInsertTable,
-	downcastRemoveRow,
-	downcastTableHeadingColumnsChange,
-	downcastTableHeadingRowsChange
-} from '../../src/converters/downcast';
-import upcastTable from '../../src/converters/upcasttable';
-import { formatTable, formattedModelTable, modelTable } from '../_utils/utils';
+import { defaultConversion, defaultSchema, formatTable, formattedModelTable, modelTable } from '../_utils/utils';
 import TableUtils from '../../src/tableutils';
 
 describe( 'SplitCellCommand', () => {
@@ -33,48 +23,8 @@ describe( 'SplitCellCommand', () => {
 				model = editor.model;
 				command = new SplitCellCommand( editor );
 
-				const conversion = editor.conversion;
-				const schema = model.schema;
-
-				schema.register( 'table', {
-					allowWhere: '$block',
-					allowAttributes: [ 'headingRows' ],
-					isObject: true
-				} );
-
-				schema.register( 'tableRow', { allowIn: 'table' } );
-
-				schema.register( 'tableCell', {
-					allowIn: 'tableRow',
-					allowContentOf: '$block',
-					allowAttributes: [ 'colspan', 'rowspan' ],
-					isLimit: true
-				} );
-
-				model.schema.register( 'p', { inheritAllFrom: '$block' } );
-
-				// Table conversion.
-				conversion.for( 'upcast' ).add( upcastTable() );
-				conversion.for( 'downcast' ).add( downcastInsertTable() );
-
-				// Insert row conversion.
-				conversion.for( 'downcast' ).add( downcastInsertRow() );
-
-				// Remove row conversion.
-				conversion.for( 'downcast' ).add( downcastRemoveRow() );
-
-				// Table cell conversion.
-				conversion.for( 'downcast' ).add( downcastInsertCell() );
-
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'th' } ) );
-
-				// Table attributes conversion.
-				conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-				conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
-
-				conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange() );
-				conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange() );
+				defaultSchema( model.schema );
+				defaultConversion( editor.conversion );
 			} );
 	} );
 
@@ -97,7 +47,7 @@ describe( 'SplitCellCommand', () => {
 			} );
 
 			it( 'should be false if not in cell', () => {
-				setData( model, '<p>11[]</p>' );
+				setData( model, '<paragraph>11[]</paragraph>' );
 
 				expect( command.isEnabled ).to.be.false;
 			} );
@@ -201,7 +151,7 @@ describe( 'SplitCellCommand', () => {
 			} );
 
 			it( 'should be false if not in cell', () => {
-				setData( model, '<p>11[]</p>' );
+				setData( model, '<paragraph>11[]</paragraph>' );
 
 				expect( command.isEnabled ).to.be.false;
 			} );

+ 5 - 38
packages/ckeditor5-table/tests/commands/utils.js

@@ -5,11 +5,9 @@
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
 
-import { downcastInsertTable } from '../../src/converters/downcast';
-import upcastTable from '../../src/converters/upcasttable';
-import { modelTable } from '../_utils/utils';
+import { defaultConversion, defaultSchema, modelTable } from '../_utils/utils';
+
 import { getParentTable } from '../../src/commands/utils';
 
 describe( 'commands utils', () => {
@@ -21,39 +19,8 @@ describe( 'commands utils', () => {
 				editor = newEditor;
 				model = editor.model;
 
-				const conversion = editor.conversion;
-				const schema = model.schema;
-
-				schema.register( 'table', {
-					allowWhere: '$block',
-					allowAttributes: [ 'headingRows' ],
-					isObject: true
-				} );
-
-				schema.register( 'tableRow', { allowIn: 'table' } );
-
-				schema.register( 'tableCell', {
-					allowIn: 'tableRow',
-					allowContentOf: '$block',
-					allowAttributes: [ 'colspan', 'rowspan' ],
-					isLimit: true
-				} );
-
-				model.schema.register( 'p', { inheritAllFrom: '$block' } );
-
-				// Table conversion.
-				conversion.for( 'upcast' ).add( upcastTable() );
-				conversion.for( 'downcast' ).add( downcastInsertTable() );
-
-				// Table row upcast only since downcast conversion is done in `downcastTable()`.
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableRow', view: 'tr' } ) );
-
-				// Table cell conversion.
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
-				conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'th' } ) );
-
-				conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-				conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
+				defaultSchema( model.schema );
+				defaultConversion( editor.conversion );
 			} );
 	} );
 
@@ -63,7 +30,7 @@ describe( 'commands utils', () => {
 
 	describe( 'getParentTable()', () => {
 		it( 'should return undefined if not in table', () => {
-			setData( model, '<p>foo[]</p>' );
+			setData( model, '<paragraph>foo[]</paragraph>' );
 
 			expect( getParentTable( model.document.selection.focus ) ).to.be.undefined;
 		} );

+ 65 - 178
packages/ckeditor5-table/tests/converters/downcast.js

@@ -7,15 +7,7 @@ import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtest
 import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
-import {
-	downcastInsertCell,
-	downcastInsertRow,
-	downcastInsertTable,
-	downcastRemoveRow,
-	downcastTableHeadingColumnsChange,
-	downcastTableHeadingRowsChange
-} from '../../src/converters/downcast';
-import { formatTable, formattedViewTable, modelTable } from '../_utils/utils';
+import { defaultConversion, defaultSchema, formatTable, formattedViewTable, modelTable } from '../_utils/utils';
 import env from '@ckeditor/ckeditor5-utils/src/env';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
@@ -36,36 +28,8 @@ describe( 'downcast converters', () => {
 				root = doc.getRoot( 'main' );
 				viewDocument = editor.editing.view;
 
-				const conversion = editor.conversion;
-				const schema = model.schema;
-
-				schema.register( 'table', {
-					allowWhere: '$block',
-					allowAttributes: [ 'headingRows', 'headingColumns' ],
-					isObject: true
-				} );
-
-				schema.register( 'tableRow', { allowIn: 'table' } );
-
-				schema.register( 'tableCell', {
-					allowIn: 'tableRow',
-					allowContentOf: '$block',
-					allowAttributes: [ 'colspan', 'rowspan' ],
-					isLimit: true
-				} );
-
-				conversion.for( 'downcast' ).add( downcastInsertTable() );
-				conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-				conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
-
-				// Insert conversion
-				conversion.for( 'downcast' ).add( downcastInsertRow() );
-				conversion.for( 'downcast' ).add( downcastInsertCell() );
-
-				conversion.for( 'downcast' ).add( downcastRemoveRow() );
-
-				conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange() );
-				conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange() );
+				defaultSchema( model.schema );
+				defaultConversion( editor.conversion );
 			} );
 	} );
 
@@ -142,6 +106,25 @@ describe( 'downcast converters', () => {
 			) );
 		} );
 
+		it( 'should create table with block content', () => {
+			setModelData( model, modelTable( [
+				[ '<paragraph>00</paragraph><paragraph>foo</paragraph>', '01' ]
+			] ) );
+
+			expect( formatTable( getViewData( viewDocument, { withoutSelection: true } ) ) ).to.equal( formatTable(
+				'<figure class="table">' +
+					'<table>' +
+						'<tbody>' +
+							'<tr>' +
+								'<td><p>00</p><p>foo</p></td>' +
+								'<td>01</td>' +
+							'</tr>' +
+						'</tbody>' +
+					'</table>' +
+				'</figure>'
+			) );
+		} );
+
 		it( 'should be possible to overwrite', () => {
 			editor.conversion.elementToElement( { model: 'tableRow', view: 'tr', converterPriority: 'high' } );
 			editor.conversion.elementToElement( { model: 'tableCell', view: 'td', converterPriority: 'high' } );
@@ -161,7 +144,7 @@ describe( 'downcast converters', () => {
 
 			expect( formatTable( getViewData( viewDocument, { withoutSelection: true } ) ) ).to.equal( formatTable(
 				'<table foo="bar">' +
-					'<tr><td></td></tr>' +
+					'<tr><td><p></p></td></tr>' +
 				'</table>'
 			) );
 		} );
@@ -240,7 +223,7 @@ describe( 'downcast converters', () => {
 			} );
 		} );
 
-		describe( 'asWidget', () => {
+		describe( 'options.asWidget=true', () => {
 			beforeEach( () => {
 				return VirtualTestEditor.create()
 					.then( newEditor => {
@@ -250,30 +233,8 @@ describe( 'downcast converters', () => {
 						root = doc.getRoot( 'main' );
 						viewDocument = editor.editing.view;
 
-						const conversion = editor.conversion;
-						const schema = model.schema;
-
-						schema.register( 'table', {
-							allowWhere: '$block',
-							allowAttributes: [ 'headingRows', 'headingColumns' ],
-							isObject: true
-						} );
-
-						schema.register( 'tableRow', { allowIn: 'table' } );
-
-						schema.register( 'tableCell', {
-							allowIn: 'tableRow',
-							allowContentOf: '$block',
-							allowAttributes: [ 'colspan', 'rowspan' ],
-							isLimit: true
-						} );
-
-						conversion.for( 'downcast' ).add( downcastInsertTable( { asWidget: true } ) );
-						conversion.for( 'downcast' ).add( downcastInsertRow( { asWidget: true } ) );
-						conversion.for( 'downcast' ).add( downcastInsertCell( { asWidget: true } ) );
-
-						conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-						conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
+						defaultSchema( model.schema );
+						defaultConversion( editor.conversion, true );
 					} );
 			} );
 
@@ -285,7 +246,9 @@ describe( 'downcast converters', () => {
 					'<div class="ck ck-widget__selection-handler"></div>' +
 						'<table>' +
 							'<tbody>' +
-								'<tr><td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true"></td></tr>' +
+								'<tr>' +
+									'<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true"><span></span></td>' +
+								'</tr>' +
 							'</tbody>' +
 						'</table>' +
 					'</figure>'
@@ -483,7 +446,7 @@ describe( 'downcast converters', () => {
 			] ) );
 		} );
 
-		describe( 'asWidget', () => {
+		describe( 'options.asWidget=true', () => {
 			beforeEach( () => {
 				return VirtualTestEditor.create()
 					.then( newEditor => {
@@ -493,30 +456,8 @@ describe( 'downcast converters', () => {
 						root = doc.getRoot( 'main' );
 						viewDocument = editor.editing.view;
 
-						const conversion = editor.conversion;
-						const schema = model.schema;
-
-						schema.register( 'table', {
-							allowWhere: '$block',
-							allowAttributes: [ 'headingRows', 'headingColumns' ],
-							isObject: true
-						} );
-
-						schema.register( 'tableRow', { allowIn: 'table' } );
-
-						schema.register( 'tableCell', {
-							allowIn: 'tableRow',
-							allowContentOf: '$block',
-							allowAttributes: [ 'colspan', 'rowspan' ],
-							isLimit: true
-						} );
-
-						conversion.for( 'downcast' ).add( downcastInsertTable( { asWidget: true } ) );
-						conversion.for( 'downcast' ).add( downcastInsertRow( { asWidget: true } ) );
-						conversion.for( 'downcast' ).add( downcastInsertCell( { asWidget: true } ) );
-
-						conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-						conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
+						defaultSchema( model.schema );
+						defaultConversion( editor.conversion, true );
 					} );
 			} );
 
@@ -532,13 +473,21 @@ describe( 'downcast converters', () => {
 					writer.insert( writer.createElement( 'tableCell' ), firstRow, 'end' );
 				} );
 
-				expect( formatTable( getViewData( viewDocument, { withoutSelection: true } ) ) ).to.equal( formatTable(
+				// TODO check span always?
+				expect( formatTable(
+					getViewData( viewDocument, { withoutSelection: true } ) ) ).to.equal( formatTable(
 					'<figure class="ck-widget ck-widget_selectable table" contenteditable="false">' +
 						'<div class="ck ck-widget__selection-handler"></div>' +
 						'<table>' +
 							'<tbody>' +
-								'<tr><td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">00</td></tr>' +
-								'<tr><td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true"></td></tr>' +
+								'<tr>' +
+									'<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
+										'<span>00</span>' +
+									'</td>' +
+								'</tr>' +
+								'<tr>' +
+									'<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true"></td>' +
+								'</tr>' +
 							'</tbody>' +
 						'</table>' +
 					'</figure>'
@@ -646,7 +595,7 @@ describe( 'downcast converters', () => {
 			] ) );
 		} );
 
-		describe( 'asWidget', () => {
+		describe( 'options.asWidget=true', () => {
 			beforeEach( () => {
 				return VirtualTestEditor.create()
 					.then( newEditor => {
@@ -656,30 +605,8 @@ describe( 'downcast converters', () => {
 						root = doc.getRoot( 'main' );
 						viewDocument = editor.editing.view;
 
-						const conversion = editor.conversion;
-						const schema = model.schema;
-
-						schema.register( 'table', {
-							allowWhere: '$block',
-							allowAttributes: [ 'headingRows', 'headingColumns' ],
-							isObject: true
-						} );
-
-						schema.register( 'tableRow', { allowIn: 'table' } );
-
-						schema.register( 'tableCell', {
-							allowIn: 'tableRow',
-							allowContentOf: '$block',
-							allowAttributes: [ 'colspan', 'rowspan' ],
-							isLimit: true
-						} );
-
-						conversion.for( 'downcast' ).add( downcastInsertTable( { asWidget: true } ) );
-						conversion.for( 'downcast' ).add( downcastInsertRow( { asWidget: true } ) );
-						conversion.for( 'downcast' ).add( downcastInsertCell( { asWidget: true } ) );
-
-						conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-						conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
+						defaultSchema( model.schema );
+						defaultConversion( editor.conversion, true );
 					} );
 			} );
 
@@ -700,7 +627,9 @@ describe( 'downcast converters', () => {
 						'<table>' +
 							'<tbody>' +
 								'<tr>' +
-									'<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">00</td>' +
+					'<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
+					'<span>00</span>' +
+					'</td>' +
 									'<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true"></td>' +
 								'</tr>' +
 							'</tbody>' +
@@ -845,7 +774,7 @@ describe( 'downcast converters', () => {
 			] ) );
 		} );
 
-		describe( 'asWidget', () => {
+		describe( 'options.asWidget=true', () => {
 			beforeEach( () => {
 				return VirtualTestEditor.create()
 					.then( newEditor => {
@@ -855,33 +784,8 @@ describe( 'downcast converters', () => {
 						root = doc.getRoot( 'main' );
 						viewDocument = editor.editing.view;
 
-						const conversion = editor.conversion;
-						const schema = model.schema;
-
-						schema.register( 'table', {
-							allowWhere: '$block',
-							allowAttributes: [ 'headingRows', 'headingColumns' ],
-							isObject: true
-						} );
-
-						schema.register( 'tableRow', { allowIn: 'table' } );
-
-						schema.register( 'tableCell', {
-							allowIn: 'tableRow',
-							allowContentOf: '$block',
-							allowAttributes: [ 'colspan', 'rowspan' ],
-							isLimit: true
-						} );
-
-						conversion.for( 'downcast' ).add( downcastInsertTable( { asWidget: true } ) );
-						conversion.for( 'downcast' ).add( downcastInsertRow( { asWidget: true } ) );
-						conversion.for( 'downcast' ).add( downcastInsertCell( { asWidget: true } ) );
-
-						conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange( { asWidget: true } ) );
-						conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange( { asWidget: true } ) );
-
-						conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-						conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
+						defaultSchema( model.schema );
+						defaultConversion( editor.conversion, true );
 					} );
 			} );
 
@@ -899,7 +803,11 @@ describe( 'downcast converters', () => {
 					'<div class="ck ck-widget__selection-handler"></div>' +
 						'<table>' +
 							'<thead>' +
-								'<tr><th class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">00</th></tr>' +
+								'<tr>' +
+									'<th class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
+										'<span>00</span>' +
+									'</th>' +
+								'</tr>' +
 							'</thead>' +
 						'</table>' +
 					'</figure>'
@@ -1053,7 +961,7 @@ describe( 'downcast converters', () => {
 			], { headingRows: 2 } ) );
 		} );
 
-		describe( 'asWidget', () => {
+		describe( 'options.asWidget=true', () => {
 			beforeEach( () => {
 				return VirtualTestEditor.create()
 					.then( newEditor => {
@@ -1063,33 +971,8 @@ describe( 'downcast converters', () => {
 						root = doc.getRoot( 'main' );
 						viewDocument = editor.editing.view;
 
-						const conversion = editor.conversion;
-						const schema = model.schema;
-
-						schema.register( 'table', {
-							allowWhere: '$block',
-							allowAttributes: [ 'headingRows', 'headingColumns' ],
-							isObject: true
-						} );
-
-						schema.register( 'tableRow', { allowIn: 'table' } );
-
-						schema.register( 'tableCell', {
-							allowIn: 'tableRow',
-							allowContentOf: '$block',
-							allowAttributes: [ 'colspan', 'rowspan' ],
-							isLimit: true
-						} );
-
-						conversion.for( 'downcast' ).add( downcastInsertTable( { asWidget: true } ) );
-						conversion.for( 'downcast' ).add( downcastInsertRow( { asWidget: true } ) );
-						conversion.for( 'downcast' ).add( downcastInsertCell( { asWidget: true } ) );
-
-						conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange( { asWidget: true } ) );
-						conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange( { asWidget: true } ) );
-
-						conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-						conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
+						defaultSchema( model.schema );
+						defaultConversion( editor.conversion, true );
 					} );
 			} );
 
@@ -1107,7 +990,11 @@ describe( 'downcast converters', () => {
 					'<div class="ck ck-widget__selection-handler"></div>' +
 						'<table>' +
 							'<tbody>' +
-								'<tr><th class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">00</th></tr>' +
+								'<tr>' +
+									'<th class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
+										'<span>00</span>' +
+									'</th>' +
+								'</tr>' +
 							'</tbody>' +
 						'</table>' +
 					'</figure>'

+ 16 - 23
packages/ckeditor5-table/tests/tableediting.js

@@ -243,7 +243,7 @@ describe( 'TableEditing', () => {
 				sinon.assert.calledOnce( domEvtDataStub.preventDefault );
 				sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
 				expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
-					[ '11', '[12]' ]
+					[ '11', '[<paragraph>12</paragraph>]' ]
 				] ) );
 			} );
 
@@ -256,7 +256,7 @@ describe( 'TableEditing', () => {
 
 				expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
 					[ '11', '12' ],
-					[ '[]', '' ]
+					[ '[<paragraph></paragraph>]', '' ]
 				] ) );
 			} );
 
@@ -270,7 +270,7 @@ describe( 'TableEditing', () => {
 
 				expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
 					[ '11', '12' ],
-					[ '[21]', '22' ]
+					[ '[<paragraph>21</paragraph>]', '22' ]
 				] ) );
 			} );
 
@@ -282,7 +282,11 @@ describe( 'TableEditing', () => {
 				editor.editing.view.document.fire( 'keydown', domEvtDataStub );
 
 				expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
-					[ '11', '<paragraph>12</paragraph><paragraph>foo</paragraph><paragraph>bar</paragraph>', '[13]' ],
+					[
+						'11',
+						'<paragraph>12</paragraph><paragraph>foo</paragraph><paragraph>bar</paragraph>',
+						'[<paragraph>13</paragraph>]'
+					],
 				] ) );
 			} );
 
@@ -312,7 +316,7 @@ describe( 'TableEditing', () => {
 					sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
 
 					expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
-						[ '[11]', '12' ]
+						[ '[<paragraph>11</paragraph>]', '12' ]
 					] ) );
 
 					// Should cancel event - so no other tab handler is called.
@@ -371,7 +375,7 @@ describe( 'TableEditing', () => {
 				sinon.assert.calledOnce( domEvtDataStub.preventDefault );
 				sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
 				expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
-					[ '[11]', '12' ]
+					[ '[<paragraph>11</paragraph>]', '12' ]
 				] ) );
 			} );
 
@@ -396,7 +400,7 @@ describe( 'TableEditing', () => {
 				editor.editing.view.document.fire( 'keydown', domEvtDataStub );
 
 				expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
-					[ '11', '[12]' ],
+					[ '11', '[<paragraph>12</paragraph>]' ],
 					[ '21', '22' ]
 				] ) );
 			} );
@@ -409,7 +413,11 @@ describe( 'TableEditing', () => {
 				editor.editing.view.document.fire( 'keydown', domEvtDataStub );
 
 				expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
-					[ '[11]', '<paragraph>12</paragraph><paragraph>foo</paragraph><paragraph>bar</paragraph>', '13' ],
+					[
+						'[<paragraph>11</paragraph>]',
+						'<paragraph>12</paragraph><paragraph>foo</paragraph><paragraph>bar</paragraph>',
+						'13'
+					],
 				] ) );
 			} );
 		} );
@@ -487,20 +495,5 @@ describe( 'TableEditing', () => {
 				[ '[]11' ]
 			] ) );
 		} );
-
-		it( 'should wrap table cell in paragraph and set selection', () => {
-			setModelData( model, modelTable( [
-				[ '[]11' ]
-			] ) );
-
-			viewDocument.fire( 'enter', evtDataStub );
-
-			sinon.assert.calledOnce( editor.execute );
-			sinon.assert.calledWithExactly( editor.execute, 'enter' );
-
-			expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [
-				[ '<paragraph>[]11</paragraph>' ]
-			] ) );
-		} );
 	} );
 } );

+ 6 - 55
packages/ckeditor5-table/tests/tableutils.js

@@ -4,19 +4,10 @@
  */
 
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
-import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
-
-import {
-	downcastInsertCell,
-	downcastInsertRow,
-	downcastInsertTable,
-	downcastRemoveRow,
-	downcastTableHeadingColumnsChange,
-	downcastTableHeadingRowsChange
-} from '../src/converters/downcast';
-import upcastTable from '../src/converters/upcasttable';
-import { formatTable, formattedModelTable, modelTable } from './_utils/utils';
+import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+
+import { defaultConversion, defaultSchema, formatTable, formattedModelTable, modelTable } from './_utils/utils';
+
 import TableUtils from '../src/tableutils';
 
 describe( 'TableUtils', () => {
@@ -31,48 +22,8 @@ describe( 'TableUtils', () => {
 			root = model.document.getRoot( 'main' );
 			tableUtils = editor.plugins.get( TableUtils );
 
-			const conversion = editor.conversion;
-			const schema = model.schema;
-
-			schema.register( 'table', {
-				allowWhere: '$block',
-				allowAttributes: [ 'headingRows' ],
-				isObject: true
-			} );
-
-			schema.register( 'tableRow', { allowIn: 'table' } );
-
-			schema.register( 'tableCell', {
-				allowIn: 'tableRow',
-				allowContentOf: '$block',
-				allowAttributes: [ 'colspan', 'rowspan' ],
-				isLimit: true
-			} );
-
-			model.schema.register( 'p', { inheritAllFrom: '$block' } );
-
-			// Table conversion.
-			conversion.for( 'upcast' ).add( upcastTable() );
-			conversion.for( 'downcast' ).add( downcastInsertTable() );
-
-			// Insert row conversion.
-			conversion.for( 'downcast' ).add( downcastInsertRow() );
-
-			// Remove row conversion.
-			conversion.for( 'downcast' ).add( downcastRemoveRow() );
-
-			// Table cell conversion.
-			conversion.for( 'downcast' ).add( downcastInsertCell() );
-
-			conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'td' } ) );
-			conversion.for( 'upcast' ).add( upcastElementToElement( { model: 'tableCell', view: 'th' } ) );
-
-			// Table attributes conversion.
-			conversion.attributeToAttribute( { model: 'colspan', view: 'colspan' } );
-			conversion.attributeToAttribute( { model: 'rowspan', view: 'rowspan' } );
-
-			conversion.for( 'downcast' ).add( downcastTableHeadingColumnsChange() );
-			conversion.for( 'downcast' ).add( downcastTableHeadingRowsChange() );
+			defaultSchema( model.schema );
+			defaultConversion( editor.conversion );
 		} );
 	} );
 

+ 5 - 18
packages/ckeditor5-table/tests/tablewalker.js

@@ -5,7 +5,8 @@
 
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
-import { modelTable } from './_utils/utils';
+
+import { defaultConversion, defaultSchema, modelTable } from './_utils/utils';
 
 import TableWalker from '../src/tablewalker';
 
@@ -20,22 +21,8 @@ describe( 'TableWalker', () => {
 				doc = model.document;
 				root = doc.getRoot( 'main' );
 
-				const schema = model.schema;
-
-				schema.register( 'table', {
-					allowWhere: '$block',
-					allowAttributes: [ 'headingRows', 'headingColumns' ],
-					isObject: true
-				} );
-
-				schema.register( 'tableRow', { allowIn: 'table' } );
-
-				schema.register( 'tableCell', {
-					allowIn: 'tableRow',
-					allowContentOf: '$block',
-					allowAttributes: [ 'colspan', 'rowspan' ],
-					isLimit: true
-				} );
+				defaultSchema( model.schema );
+				defaultConversion( editor.conversion );
 			} );
 	} );
 
@@ -53,7 +40,7 @@ describe( 'TableWalker', () => {
 		const formattedResult = result.map( ( { row, column, cell, cellIndex } ) => ( {
 			row,
 			column,
-			data: cell && cell.getChild( 0 ).data,
+			data: cell && cell.getChild( 0 ).getChild( 0 ).data,
 			index: cellIndex
 		} ) );