From 8f5133ff085c8232cc88e884be4de6d8f2fb9ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 6 Dec 2018 11:24:42 +0100 Subject: [PATCH 01/11] Enable images in table cells. --- src/tableediting.js | 4 ++-- tests/_utils/utils.js | 7 ------- tests/converters/upcasttable.js | 4 ++-- tests/tableediting.js | 4 ++-- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/tableediting.js b/src/tableediting.js index f5c73698..ccab6434 100644 --- a/src/tableediting.js +++ b/src/tableediting.js @@ -81,13 +81,13 @@ export default class TableEditing extends Plugin { } } ); - // Disallow image and media in table cell. + // Disallow media in table cell. schema.addChildCheck( ( context, childDefinition ) => { if ( !Array.from( context.getNames() ).includes( 'table' ) ) { return; } - if ( childDefinition.name == 'image' || childDefinition.name == 'media' ) { + if ( childDefinition.name == 'media' ) { return false; } } ); diff --git a/tests/_utils/utils.js b/tests/_utils/utils.js index d3562a5e..a3ffb08b 100644 --- a/tests/_utils/utils.js +++ b/tests/_utils/utils.js @@ -187,13 +187,6 @@ export function defaultSchema( schema, registerParagraph = true ) { } } ); - // Disallow image in table. - schema.addChildCheck( ( context, childDefinition ) => { - if ( childDefinition.name == 'image' && Array.from( context.getNames() ).includes( 'table' ) ) { - return false; - } - } ); - if ( registerParagraph ) { schema.register( 'paragraph', { inheritAllFrom: '$block' } ); } diff --git a/tests/converters/upcasttable.js b/tests/converters/upcasttable.js index dbd0c70a..f33278b7 100644 --- a/tests/converters/upcasttable.js +++ b/tests/converters/upcasttable.js @@ -457,7 +457,7 @@ describe( 'upcastTable()', () => { ] ) ); } ); - it( 'should upcast table with in table cell to empty table cell', () => { + it( 'should upcast table with in table cell', () => { editor.setData( '' + '' + @@ -469,7 +469,7 @@ describe( 'upcastTable()', () => { ); expectModel( modelTable( [ - [ '' ] + [ '' ] ] ) ); } ); } ); diff --git a/tests/tableediting.js b/tests/tableediting.js index fa5ad462..b68fc70d 100644 --- a/tests/tableediting.js +++ b/tests/tableediting.js @@ -74,7 +74,7 @@ describe( 'TableEditing', () => { expect( model.schema.checkChild( [ '$root', 'table', 'tableRow', 'tableCell' ], '$text' ) ).to.be.false; expect( model.schema.checkChild( [ '$root', 'table', 'tableRow', 'tableCell' ], '$block' ) ).to.be.true; expect( model.schema.checkChild( [ '$root', 'table', 'tableRow', 'tableCell' ], 'table' ) ).to.be.false; - expect( model.schema.checkChild( [ '$root', 'table', 'tableRow', 'tableCell' ], 'image' ) ).to.be.false; + expect( model.schema.checkChild( [ '$root', 'table', 'tableRow', 'tableCell' ], 'image' ) ).to.be.true; } ); it( 'adds insertTable command', () => { @@ -183,7 +183,7 @@ describe( 'TableEditing', () => { editor.setData( '
' ); expect( getModelData( model, { withoutSelection: true } ) ) - .to.equal( '
' ); + .to.equal( '
' ); } ); it( 'should convert table with media', () => { From c3fe64bf6be22923d184e37df265878226606511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 6 Dec 2018 11:27:44 +0100 Subject: [PATCH 02/11] Add image in block content manual test. --- tests/manual/tableblockcontent.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/manual/tableblockcontent.html b/tests/manual/tableblockcontent.html index 3eb4e628..13fec649 100644 --- a/tests/manual/tableblockcontent.html +++ b/tests/manual/tableblockcontent.html @@ -64,6 +64,13 @@

An h2 with justify alignment.

A quote with paragraph with right alignment

+ + image + + sample image + + + From ebde44a94963550b76123fb3b4443a58cdd5b928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 6 Dec 2018 11:53:59 +0100 Subject: [PATCH 03/11] Remove redundant plugins from block content manual test. --- tests/manual/tableblockcontent.html | 1 + tests/manual/tableblockcontent.js | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/manual/tableblockcontent.html b/tests/manual/tableblockcontent.html index 13fec649..a090be2c 100644 --- a/tests/manual/tableblockcontent.html +++ b/tests/manual/tableblockcontent.html @@ -67,6 +67,7 @@

An h2 with justify alignment.

image +

A paragraph with default alignment

sample image diff --git a/tests/manual/tableblockcontent.js b/tests/manual/tableblockcontent.js index 9047f3cd..1f25db73 100644 --- a/tests/manual/tableblockcontent.js +++ b/tests/manual/tableblockcontent.js @@ -7,13 +7,11 @@ import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'; import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset'; -import Table from '../../src/table'; -import TableToolbar from '../../src/tabletoolbar'; import Alignment from '@ckeditor/ckeditor5-alignment/src/alignment'; ClassicEditor .create( document.querySelector( '#editor' ), { - plugins: [ ArticlePluginSet, Table, TableToolbar, Alignment ], + plugins: [ ArticlePluginSet, Alignment ], toolbar: [ 'heading', '|', 'insertTable', '|', 'bold', 'italic', 'bulletedList', 'numberedList', 'blockQuote', 'alignment', '|', 'undo', 'redo' From 906c6e80d99e9a323a714edd707fe3c3ab8deb81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 6 Dec 2018 11:54:46 +0100 Subject: [PATCH 04/11] Remove redundant plugins from table manual test. --- tests/manual/table.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/manual/table.js b/tests/manual/table.js index d76977e2..82a5ddca 100644 --- a/tests/manual/table.js +++ b/tests/manual/table.js @@ -7,13 +7,10 @@ import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'; import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset'; -import Table from '../../src/table'; -import TableToolbar from '../../src/tabletoolbar'; -import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote'; ClassicEditor .create( document.querySelector( '#editor' ), { - plugins: [ ArticlePluginSet, Table, TableToolbar, BlockQuote ], + plugins: [ ArticlePluginSet ], toolbar: [ 'heading', '|', 'insertTable', '|', 'bold', 'italic', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ], From 5717f6012d6eb4291c1d0e89ac241292c3f281f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 6 Dec 2018 16:35:10 +0100 Subject: [PATCH 05/11] Add image toolbar configuration for table block content test. --- tests/manual/tableblockcontent.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/manual/tableblockcontent.js b/tests/manual/tableblockcontent.js index 1f25db73..7e2b27c5 100644 --- a/tests/manual/tableblockcontent.js +++ b/tests/manual/tableblockcontent.js @@ -16,6 +16,9 @@ ClassicEditor 'heading', '|', 'insertTable', '|', 'bold', 'italic', 'bulletedList', 'numberedList', 'blockQuote', 'alignment', '|', 'undo', 'redo' ], + image: { + toolbar: [ 'imageStyle:full', 'imageStyle:side' ] + }, table: { contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ] } From 56adacf1c89fafcc941936fccdcd786db01d629f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 6 Dec 2018 17:44:55 +0100 Subject: [PATCH 06/11] Do not show table toolbar when other widget is selected inside table. --- src/utils.js | 5 ++++- tests/tabletoolbar.js | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index 89e523d7..f1d1fcab 100644 --- a/src/utils.js +++ b/src/utils.js @@ -57,7 +57,10 @@ export function isTableWidgetSelected( selection ) { * @returns {Boolean} */ export function isTableContentSelected( selection ) { + const selectedElement = selection.getSelectedElement(); + const isInnerWidgetSelected = selectedElement && isWidget( selectedElement ); + const parentTable = findAncestor( 'table', selection.getFirstPosition() ); - return !!( parentTable && isTableWidget( parentTable.parent ) ); + return !isInnerWidgetSelected && !!( parentTable && isTableWidget( parentTable.parent ) ); } diff --git a/tests/tabletoolbar.js b/tests/tabletoolbar.js index 006edf2d..d992d840 100644 --- a/tests/tabletoolbar.js +++ b/tests/tabletoolbar.js @@ -16,6 +16,9 @@ import View from '@ckeditor/ckeditor5-ui/src/view'; import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model'; import WidgetToolbarRepository from '@ckeditor/ckeditor5-widget/src/widgettoolbarrepository'; import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; +import ImageToolbar from '@ckeditor/ckeditor5-image/src/imagetoolbar'; +import Image from '@ckeditor/ckeditor5-image/src/image'; +import ImageStyle from '@ckeditor/ckeditor5-image/src/imagestyle'; describe( 'TableToolbar', () => { testUtils.createSinonSandbox(); @@ -29,7 +32,10 @@ describe( 'TableToolbar', () => { return ClassicTestEditor .create( editorElement, { - plugins: [ Paragraph, Table, TableToolbar, FakeButton ], + plugins: [ Paragraph, Image, ImageStyle, ImageToolbar, Table, TableToolbar, FakeButton ], + image: { + toolbar: [ 'imageStyle:full', 'imageStyle:side' ] + }, table: { contentToolbar: [ 'fake_button' ] } @@ -154,6 +160,36 @@ describe( 'TableToolbar', () => { expect( balloon.visibleView ).to.equal( toolbar ); } ); + it( 'should not show the toolbar on ui#update when the image inside table is selected', () => { + setData( + model, + '[foo]' + + 'foo
' + ); + + expect( balloon.visibleView ).to.be.null; + + const imageToolbar = widgetToolbarRepository._toolbars.get( 'image' ).view; + + model.change( writer => { + // Select the [] + const nodeByPath = doc.getRoot().getNodeByPath( [ 1, 0, 0, 1 ] ); + + writer.setSelection( nodeByPath, 'on' ); + } ); + + expect( balloon.visibleView ).to.equal( imageToolbar ); + + model.change( writer => { + // Select the [] + writer.setSelection( + writer.createPositionAt( doc.getRoot().getNodeByPath( [ 1, 0, 0, 0 ] ), 0 ) + ); + } ); + + expect( balloon.visibleView ).to.equal( toolbar ); + } ); + it( 'should not engage when the toolbar is in the balloon yet invisible', () => { setData( model, 'x[y]z
' ); From 7a35aa30a5a863fa053f8361b634d752d016376c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 6 Dec 2018 18:20:07 +0100 Subject: [PATCH 07/11] Add tests for TAB handling in table when target cell contains an image. --- tests/tableediting.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/tableediting.js b/tests/tableediting.js index b68fc70d..a9abec91 100644 --- a/tests/tableediting.js +++ b/tests/tableediting.js @@ -312,6 +312,20 @@ describe( 'TableEditing', () => { ] ) ); } ); + it( 'should move to next cell with an image', () => { + setModelData( model, modelTable( [ + [ '11[]', 'foo' ] + ] ) ); + + editor.editing.view.document.fire( 'keydown', domEvtDataStub ); + + sinon.assert.calledOnce( domEvtDataStub.preventDefault ); + sinon.assert.calledOnce( domEvtDataStub.stopPropagation ); + expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [ + [ '11', '[]' ] + ] ) ); + } ); + it( 'should listen with lower priority then its children', () => { // Cancel TAB event. editor.keystrokes.set( 'Tab', ( data, cancel ) => cancel() ); From 19f960a5382421145d2cec1298eb456e5ae5a63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Fri, 7 Dec 2018 10:23:03 +0100 Subject: [PATCH 08/11] Fix TAB handling test. --- tests/tableediting.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tableediting.js b/tests/tableediting.js index a9abec91..b99f960a 100644 --- a/tests/tableediting.js +++ b/tests/tableediting.js @@ -322,7 +322,7 @@ describe( 'TableEditing', () => { sinon.assert.calledOnce( domEvtDataStub.preventDefault ); sinon.assert.calledOnce( domEvtDataStub.stopPropagation ); expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [ - [ '11', '[]' ] + [ '11', '[foo]' ] ] ) ); } ); From 0e5c90c4244ed76e7374609091ce6fc8eef78f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Fri, 7 Dec 2018 11:40:48 +0100 Subject: [PATCH 09/11] Add tests for blockQuote in table handling on TAB caret movement. --- tests/tableediting.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/tableediting.js b/tests/tableediting.js index b99f960a..ec756b7d 100644 --- a/tests/tableediting.js +++ b/tests/tableediting.js @@ -326,6 +326,28 @@ describe( 'TableEditing', () => { ] ) ); } ); + it( 'should move to next cell with an blockQuote', () => { + model.schema.register( 'blockQuote', { + allowWhere: '$block', + allowContentOf: '$root', + isObject: true, + isBlock: true + } ); + editor.conversion.elementToElement( { model: 'blockQuote', view: 'blockquote' } ); + + setModelData( model, modelTable( [ + [ '11[]', '
foo
' ] + ] ) ); + + editor.editing.view.document.fire( 'keydown', domEvtDataStub ); + + sinon.assert.calledOnce( domEvtDataStub.preventDefault ); + sinon.assert.calledOnce( domEvtDataStub.stopPropagation ); + expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [ + [ '11', '
[foo]
' ] + ] ) ); + } ); + it( 'should listen with lower priority then its children', () => { // Cancel TAB event. editor.keystrokes.set( 'Tab', ( data, cancel ) => cancel() ); @@ -475,6 +497,20 @@ describe( 'TableEditing', () => { ], ] ) ); } ); + + it( 'should move to previous cell with an image', () => { + setModelData( model, modelTable( [ + [ 'foo', 'bar[]' ] + ] ) ); + + editor.editing.view.document.fire( 'keydown', domEvtDataStub ); + + sinon.assert.calledOnce( domEvtDataStub.preventDefault ); + sinon.assert.calledOnce( domEvtDataStub.stopPropagation ); + expect( formatTable( getModelData( model ) ) ).to.equal( formattedModelTable( [ + [ '[foo]', 'bar' ] + ] ) ); + } ); } ); } ); From 06a10988c0134d7fdef5dee3243b95700c3df23f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Fri, 7 Dec 2018 12:30:43 +0100 Subject: [PATCH 10/11] Update blockQuote schema definition in keyboard navigation tests. --- tests/tableediting.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/tableediting.js b/tests/tableediting.js index ec756b7d..141a1bbb 100644 --- a/tests/tableediting.js +++ b/tests/tableediting.js @@ -329,9 +329,7 @@ describe( 'TableEditing', () => { it( 'should move to next cell with an blockQuote', () => { model.schema.register( 'blockQuote', { allowWhere: '$block', - allowContentOf: '$root', - isObject: true, - isBlock: true + allowContentOf: '$root' } ); editor.conversion.elementToElement( { model: 'blockQuote', view: 'blockquote' } ); From 57e9554011471641d66823d1e3029457ea495aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Fri, 7 Dec 2018 13:09:38 +0100 Subject: [PATCH 11/11] Update block content manual test description & data. --- tests/manual/tableblockcontent.html | 8 ++++++-- tests/manual/tableblockcontent.md | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/manual/tableblockcontent.html b/tests/manual/tableblockcontent.html index a090be2c..6c1e105a 100644 --- a/tests/manual/tableblockcontent.html +++ b/tests/manual/tableblockcontent.html @@ -67,10 +67,14 @@

An h2 with justify alignment.

image -

A paragraph with default alignment

sample image - + +

An image aligned to right:

+
+ sample image +
+ diff --git a/tests/manual/tableblockcontent.md b/tests/manual/tableblockcontent.md index ca992e4d..50f4f2f3 100644 --- a/tests/manual/tableblockcontent.md +++ b/tests/manual/tableblockcontent.md @@ -6,6 +6,7 @@ * List * Heading * Block Quote (with inner paragraph) + * Image 2. The third column consist blocks with text alignment. * Paragraph - should be rendered was `

` when alignment is set (apart from default) for single paragraph.