From c8e07c393fa16ef077c97659a3f0a842e15ea8a1 Mon Sep 17 00:00:00 2001 From: Filip Sobol Date: Thu, 12 Jan 2023 15:49:46 +0100 Subject: [PATCH 1/2] Fix (table): Improve compability of PlainTableOutput and TableColumnResize plugins --- .../ckeditor5-table/src/tablecolumnresize/converters.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/ckeditor5-table/src/tablecolumnresize/converters.js b/packages/ckeditor5-table/src/tablecolumnresize/converters.js index 27165983a45..37fed81fdea 100644 --- a/packages/ckeditor5-table/src/tablecolumnresize/converters.js +++ b/packages/ckeditor5-table/src/tablecolumnresize/converters.js @@ -68,9 +68,11 @@ export function downcastTableColumnWidthsAttribute() { return dispatcher => dispatcher.on( 'attribute:columnWidths:table', ( evt, data, conversionApi ) => { const viewWriter = conversionApi.writer; const modelTable = data.item; + const viewElement = conversionApi.mapper.toViewElement( modelTable ); - const viewTable = [ ...conversionApi.mapper.toViewElement( modelTable ).getChildren() ] - .find( viewChild => viewChild.is( 'element', 'table' ) ); + const viewTable = viewElement.is( 'element', 'table' ) ? + viewElement : + Array.from( viewElement.getChildren() ).find( viewChild => viewChild.is( 'element', 'table' ) ); if ( data.attributeNewValue ) { // If new value is the same as the old, the operation is not applied (see the `writer.setAttributeOnItem()`). From 512f13a03f530f64ad5c39360854c207763c45ca Mon Sep 17 00:00:00 2001 From: Filip Sobol Date: Fri, 13 Jan 2023 13:32:34 +0100 Subject: [PATCH 2/2] Add tests --- .../tablecolumnresizeediting.js | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/packages/ckeditor5-table/tests/tablecolumnresize/tablecolumnresizeediting.js b/packages/ckeditor5-table/tests/tablecolumnresize/tablecolumnresizeediting.js index fce4079d901..504f00b7dfe 100644 --- a/packages/ckeditor5-table/tests/tablecolumnresize/tablecolumnresizeediting.js +++ b/packages/ckeditor5-table/tests/tablecolumnresize/tablecolumnresizeediting.js @@ -11,6 +11,7 @@ import TableCaption from '../../src/tablecaption'; import TableToolbar from '../../src/tabletoolbar'; import Table from '../../src/table'; import TableProperties from '../../src/tableproperties'; +import PlainTableOutput from '../../src/plaintableoutput'; // ClassicTestEditor can't be used, as it doesn't handle the focus, which is needed to test resizer visual cues. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'; @@ -2558,6 +2559,53 @@ describe( 'TableColumnResizeEditing', () => { expect( initialViewColumnWidthsPx ).to.deep.equal( finalViewColumnWidthsPx ); } ); } ); + + describe( 'PlainTableOutput', () => { + let ptoEditor; + + beforeEach( async () => { + ptoEditor = await createEditor( { + plugins: [ Table, TableColumnResize, Paragraph, PlainTableOutput ] + } ); + } ); + + afterEach( async () => { + await ptoEditor.destroy(); + } ); + + it( 'should not crash', () => { + const table = modelTable( + [ [ 'Some', 'Data' ] ], + { columnWidths: '80%,20%', tableWidth: '100%' } + ); + setModelData( ptoEditor.model, table ); + + expect( () => ptoEditor.getData() ).to.not.throw(); + } ); + + it( 'should produce table not wrapped in
', () => { + const table = modelTable( + [ [ 'Some', 'Data' ] ], + { columnWidths: '80%,20%', tableWidth: '100%' } + ); + setModelData( ptoEditor.model, table ); + + expect( ptoEditor.getData() ).to.equal( + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
SomeData
' + ); + } ); + } ); } ); async function createEditor( configCustomization, additionalPlugins ) {