Browse Source

Disabled a media in a table.

Kamil Piechaczek 7 years ago
parent
commit
44db1f6d28

+ 1 - 0
packages/ckeditor5-table/package.json

@@ -21,6 +21,7 @@
     "@ckeditor/ckeditor5-editor-classic": "^11.0.0",
     "@ckeditor/ckeditor5-image": "^10.2.0",
     "@ckeditor/ckeditor5-list": "^11.0.1",
+    "@ckeditor/ckeditor5-media-embed": "^0.0.1",
     "@ckeditor/ckeditor5-paragraph": "^10.0.2",
     "@ckeditor/ckeditor5-undo": "^10.0.2",
     "@ckeditor/ckeditor5-utils": "^10.2.0",

+ 6 - 2
packages/ckeditor5-table/src/tableediting.js

@@ -81,9 +81,13 @@ export default class TableEditing extends Plugin {
 			}
 		} );
 
-		// Disallow image in table cell.
+		// Disallow image and media in table cell.
 		schema.addChildCheck( ( context, childDefinition ) => {
-			if ( childDefinition.name == 'image' && Array.from( context.getNames() ).includes( 'table' ) ) {
+			if ( !Array.from( context.getNames() ).includes( 'table' ) ) {
+				return;
+			}
+
+			if ( childDefinition.name == 'image' || childDefinition.name == 'media' ) {
 				return false;
 			}
 		} );

+ 0 - 1
packages/ckeditor5-table/tests/manual/tableblockcontent.md

@@ -6,7 +6,6 @@
     * List
     * Heading
     * Block Quote (with inner paragraph)
-    * Image
 
 2. The third column consist blocks with text alignment.
     * Paragraph - should be rendered was `<p>` when alignment is set (apart from default) for single paragraph.

+ 11 - 1
packages/ckeditor5-table/tests/tableediting.js

@@ -20,6 +20,7 @@ import SplitCellCommand from '../src/commands/splitcellcommand';
 import MergeCellCommand from '../src/commands/mergecellcommand';
 import SetHeaderRowCommand from '../src/commands/setheaderrowcommand';
 import SetHeaderColumnCommand from '../src/commands/setheadercolumncommand';
+import MediaEmbedEditing from '@ckeditor/ckeditor5-media-embed/src/mediaembedediting';
 
 describe( 'TableEditing', () => {
 	let editor, model;
@@ -27,7 +28,7 @@ describe( 'TableEditing', () => {
 	beforeEach( () => {
 		return VirtualTestEditor
 			.create( {
-				plugins: [ TableEditing, Paragraph, ImageEditing ]
+				plugins: [ TableEditing, Paragraph, ImageEditing, MediaEmbedEditing ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -184,6 +185,15 @@ describe( 'TableEditing', () => {
 				expect( getModelData( model, { withoutSelection: true } ) )
 					.to.equal( '<table><tableRow><tableCell><paragraph></paragraph></tableCell></tableRow></table>' );
 			} );
+
+			it( 'should convert table with media', () => {
+				editor.setData(
+					'<table><tbody><tr><td><oembed url="https://www.youtube.com/watch?v=H08tGjXNHO4"></oembed></td></tr></tbody></table>'
+				);
+
+				expect( getModelData( model, { withoutSelection: true } ) )
+					.to.equal( '<table><tableRow><tableCell><paragraph></paragraph></tableCell></tableRow></table>' );
+			} );
 		} );
 	} );