Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (table): PlainTableOutput and TableColumnResize compatibility #13265

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/ckeditor5-table/src/tablecolumnresize/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()`).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 <figure>', () => {
const table = modelTable(
[ [ 'Some', 'Data' ] ],
{ columnWidths: '80%,20%', tableWidth: '100%' }
);
setModelData( ptoEditor.model, table );

expect( ptoEditor.getData() ).to.equal(
'<table class="ck-table-resized" style="width:100%;">' +
'<colgroup>' +
'<col style="width:80%;">' +
'<col style="width:20%;">' +
'</colgroup>' +
'<tbody>' +
'<tr>' +
'<td>Some</td>' +
'<td>Data</td>' +
'</tr>' +
'</tbody>' +
'</table>'
);
} );
} );
} );

async function createEditor( configCustomization, additionalPlugins ) {
Expand Down