From 912eb71b19a65a76fe0720c9bebd4c1d81dd276c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Wed, 5 Feb 2020 10:28:46 +0100 Subject: [PATCH 01/15] TableProperties alignment conversion must consume attributes. --- src/tableproperties/tablepropertiesediting.js | 5 +++++ tests/tableproperties/tablepropertiesediting.js | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/tableproperties/tablepropertiesediting.js b/src/tableproperties/tablepropertiesediting.js index f3e0107b..51e4fefc 100644 --- a/src/tableproperties/tablepropertiesediting.js +++ b/src/tableproperties/tablepropertiesediting.js @@ -149,10 +149,15 @@ function enableAlignmentProperty( schema, conversion ) { value: viewElement => viewElement.getAttribute( 'align' ) } } ); + conversion.for( 'downcast' ).add( dispatcher => dispatcher.on( 'attribute:alignment:table', ( evt, data, conversionApi ) => { const { item, attributeNewValue } = data; const { mapper, writer } = conversionApi; + if ( !conversionApi.consumable.consume( data.item, evt.name ) ) { + return; + } + const table = [ ...mapper.toViewElement( item ).getChildren() ].find( child => child.is( 'table' ) ); if ( !attributeNewValue ) { diff --git a/tests/tableproperties/tablepropertiesediting.js b/tests/tableproperties/tablepropertiesediting.js index 555c7d89..fbf2ee7f 100644 --- a/tests/tableproperties/tablepropertiesediting.js +++ b/tests/tableproperties/tablepropertiesediting.js @@ -658,6 +658,15 @@ describe( 'table properties', () => { table = createEmptyTable(); } ); + it( 'should consume converted item', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:alignment:table', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); + } ); + it( 'should downcast right alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); From d004c26a52f7e08dce51cc3b0d0b81e59400c66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Wed, 5 Feb 2020 10:29:11 +0100 Subject: [PATCH 02/15] TableProperties alignment conversion must have higher priority converter. --- src/tableproperties/tablepropertiesediting.js | 2 +- .../tablepropertiesediting-integration.js | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tests/tableproperties/tablepropertiesediting-integration.js diff --git a/src/tableproperties/tablepropertiesediting.js b/src/tableproperties/tablepropertiesediting.js index 51e4fefc..da31368a 100644 --- a/src/tableproperties/tablepropertiesediting.js +++ b/src/tableproperties/tablepropertiesediting.js @@ -181,7 +181,7 @@ function enableAlignmentProperty( schema, conversion ) { } writer.setStyle( styles, table ); - } ) ); + }, { priority: 'high' } ) ); } // Enables conversion for an attribute for simple view-model mappings. diff --git a/tests/tableproperties/tablepropertiesediting-integration.js b/tests/tableproperties/tablepropertiesediting-integration.js new file mode 100644 index 00000000..571b0278 --- /dev/null +++ b/tests/tableproperties/tablepropertiesediting-integration.js @@ -0,0 +1,63 @@ +/** + * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license + */ + +import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor'; +import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; +import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model'; + +import TableEditing from '../../src/tableediting'; +import TablePropertiesEditing from '../../src/tableproperties/tablepropertiesediting'; + +import AlignmentEditing from '@ckeditor/ckeditor5-alignment/src/alignmentediting'; +import { assertTableStyle } from '../_utils/utils'; + +describe( 'table properties', () => { + describe( 'TablePropertiesEditing integration', () => { + let editor, model; + + afterEach( async () => { + await editor.destroy(); + } ); + + describe( 'Alignment', () => { + let table; + + beforeEach( async () => { + editor = await createEditorWithAdditionalPlugins( [ AlignmentEditing ] ); + + model = editor.model; + + table = createEmptyTable(); + } ); + + it( 'should properly downcast table with Alignment plugin enabled', () => { + model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); + + assertTableStyle( editor, 'margin-left:auto;margin-right:0;' ); + } ); + } ); + + function createEmptyTable() { + setModelData( + model, + '' + + '' + + '' + + 'foo' + + '' + + '' + + '
' + ); + + return model.document.getRoot().getNodeByPath( [ 0 ] ); + } + } ); + + function createEditorWithAdditionalPlugins( plugins ) { + return VirtualTestEditor.create( { + plugins: [ ...plugins, TablePropertiesEditing, Paragraph, TableEditing ] + } ); + } +} ); From 2163596b035b4aaba34e3cf513417c344b455233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Wed, 5 Feb 2020 11:08:21 +0100 Subject: [PATCH 03/15] Fix table properties downcast interoperability. --- src/converters/tableproperties.js | 4 + .../tableproperties/tablepropertiesediting.js | 131 ++++++++++++++++++ 2 files changed, 135 insertions(+) diff --git a/src/converters/tableproperties.js b/src/converters/tableproperties.js index 3e1dbf28..265fdac7 100644 --- a/src/converters/tableproperties.js +++ b/src/converters/tableproperties.js @@ -105,6 +105,10 @@ export function downcastTableAttribute( conversion, modelAttribute, styleName ) const { item, attributeNewValue } = data; const { mapper, writer } = conversionApi; + if ( !conversionApi.consumable.consume( data.item, evt.name ) ) { + return; + } + const table = [ ...mapper.toViewElement( item ).getChildren() ].find( child => child.is( 'table' ) ); if ( attributeNewValue ) { diff --git a/tests/tableproperties/tablepropertiesediting.js b/tests/tableproperties/tablepropertiesediting.js index fbf2ee7f..5ddada70 100644 --- a/tests/tableproperties/tablepropertiesediting.js +++ b/tests/tableproperties/tablepropertiesediting.js @@ -219,6 +219,26 @@ describe( 'table properties', () => { table = createEmptyTable(); } ); + it( 'should consume converted item borderColor attribute', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:borderColor:table', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'borderColor', '#f00', table ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:borderColor:table', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'borderColor', '#f00', table ) ); + + assertTableStyle( editor, '' ); + } ); + it( 'should downcast borderColor attribute (same top, right, bottom, left)', () => { model.change( writer => writer.setAttribute( 'borderColor', { top: '#f00', @@ -246,6 +266,26 @@ describe( 'table properties', () => { ); } ); + it( 'should consume converted item borderStyle attribute', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:borderStyle:table', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'borderStyle', 'solid', table ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:borderStyle:table', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'borderStyle', 'solid', table ) ); + + assertTableStyle( editor, '' ); + } ); + it( 'should downcast borderStyle attribute (same top, right, bottom, left)', () => { model.change( writer => writer.setAttribute( 'borderStyle', { top: 'solid', @@ -268,6 +308,26 @@ describe( 'table properties', () => { assertTableStyle( editor, 'border-bottom:dotted;border-left:dashed;border-right:ridge;border-top:solid;' ); } ); + it( 'should consume converted item borderWidth attribute', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:borderWidth:table', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'borderWidth', '2px', table ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:borderWidth:table', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'borderWidth', '2px', table ) ); + + assertTableStyle( editor, '' ); + } ); + it( 'should downcast borderWidth attribute (same top, right, bottom, left)', () => { model.change( writer => writer.setAttribute( 'borderWidth', { top: '42px', @@ -508,6 +568,26 @@ describe( 'table properties', () => { table = createEmptyTable(); } ); + it( 'should consume converted item', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:backgroundColor:table', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'backgroundColor', '#f00', table ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:backgroundColor:table', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'backgroundColor', '#f00', table ) ); + + assertTableStyle( editor, '' ); + } ); + it( 'should downcast backgroundColor', () => { model.change( writer => writer.setAttribute( 'backgroundColor', '#f00', table ) ); @@ -537,6 +617,26 @@ describe( 'table properties', () => { table = createEmptyTable(); } ); + it( 'should consume converted item', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:width:table', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'width', '400px', table ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:width:table', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'width', '400px', table ) ); + + assertTableStyle( editor, '' ); + } ); + it( 'should downcast width', () => { model.change( writer => writer.setAttribute( 'width', '1337px', table ) ); @@ -571,6 +671,26 @@ describe( 'table properties', () => { assertTableStyle( editor, 'height:1337px;' ); } ); + + it( 'should consume converted item', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:height:table', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'height', '400px', table ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:height:table', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'height', '400px', table ) ); + + assertTableStyle( editor, '' ); + } ); } ); } ); @@ -667,6 +787,17 @@ describe( 'table properties', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); } ); + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:alignment:table', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'highest' } ) ); + + model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); + + assertTableStyle( editor, '' ); + } ); + it( 'should downcast right alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); From 2b3511ca1e8a5afe7f0846370553a12cfd4bad65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Wed, 5 Feb 2020 15:09:23 +0100 Subject: [PATCH 04/15] Add tests for overriding table cell properties. --- .../tablecellpropertiesediting.js | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) diff --git a/tests/tablecellproperties/tablecellpropertiesediting.js b/tests/tablecellproperties/tablecellpropertiesediting.js index 8b6a5218..1e82e296 100644 --- a/tests/tablecellproperties/tablecellpropertiesediting.js +++ b/tests/tablecellproperties/tablecellpropertiesediting.js @@ -267,6 +267,26 @@ describe( 'table cell properties', () => { tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] ); } ); + it( 'should consume converted item borderColor attribute', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:borderColor:tableCell', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'borderColor', '#f00', tableCell ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:borderColor:tableCell', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'borderColor', '#f00', tableCell ) ); + + assertTableCellStyle( editor, '' ); + } ); + it( 'should downcast borderColor attribute (same top, right, bottom, left)', () => { model.change( writer => writer.setAttribute( 'borderColor', { top: '#f00', @@ -294,6 +314,26 @@ describe( 'table cell properties', () => { ); } ); + it( 'should consume converted item borderStyle attribute', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:borderStyle:tableCell', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'borderStyle', 'ridge', tableCell ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:borderStyle:tableCell', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'borderStyle', 'ridge', tableCell ) ); + + assertTableCellStyle( editor, '' ); + } ); + it( 'should downcast borderStyle attribute (same top, right, bottom, left)', () => { model.change( writer => writer.setAttribute( 'borderStyle', { top: 'solid', @@ -316,6 +356,26 @@ describe( 'table cell properties', () => { assertTableCellStyle( editor, 'border-bottom:dotted;border-left:dashed;border-right:ridge;border-top:solid;' ); } ); + it( 'should consume converted item borderWidth attribute', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:borderWidth:tableCell', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'borderWidth', '2px', tableCell ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:borderWidth:tableCell', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'borderWidth', '2px', tableCell ) ); + + assertTableCellStyle( editor, '' ); + } ); + it( 'should downcast borderWidth attribute (same top, right, bottom, left)', () => { model.change( writer => writer.setAttribute( 'borderWidth', { top: '42px', @@ -559,6 +619,26 @@ describe( 'table cell properties', () => { tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] ); } ); + it( 'should consume converted item backgroundColor attribute', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:backgroundColor:tableCell', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'backgroundColor', '#f00', tableCell ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:backgroundColor:tableCell', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'backgroundColor', '#f00', tableCell ) ); + + assertTableCellStyle( editor, '' ); + } ); + it( 'should downcast backgroundColor', () => { model.change( writer => writer.setAttribute( 'backgroundColor', '#f00', tableCell ) ); @@ -619,6 +699,26 @@ describe( 'table cell properties', () => { tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] ); } ); + it( 'should consume converted item horizontalAlignment attribute', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:horizontalAlignment:tableCell', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'horizontalAlignment', 'right', tableCell ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:horizontalAlignment:tableCell', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'horizontalAlignment', 'right', tableCell ) ); + + assertTableCellStyle( editor, '' ); + } ); + it( 'should downcast horizontalAlignment=left', () => { model.change( writer => writer.setAttribute( 'horizontalAlignment', 'left', tableCell ) ); @@ -676,6 +776,26 @@ describe( 'table cell properties', () => { tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] ); } ); + it( 'should consume converted item verticalAlignment attribute', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:verticalAlignment:tableCell', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'verticalAlignment', 'top', tableCell ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:verticalAlignment:tableCell', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'verticalAlignment', 'top', tableCell ) ); + + assertTableCellStyle( editor, '' ); + } ); + it( 'should downcast verticalAlignment', () => { model.change( writer => writer.setAttribute( 'verticalAlignment', 'middle', tableCell ) ); @@ -715,6 +835,26 @@ describe( 'table cell properties', () => { tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] ); } ); + it( 'should consume converted item borderColor attribute', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:padding:tableCell', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'padding', '1px', tableCell ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:padding:tableCell', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'padding', '1px', tableCell ) ); + + assertTableCellStyle( editor, '' ); + } ); + it( 'should downcast padding (same top, right, bottom, left)', () => { model.change( writer => writer.setAttribute( 'padding', { top: '2px', @@ -771,6 +911,26 @@ describe( 'table cell properties', () => { tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] ); } ); + it( 'should consume converted item width attribute', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:width:tableCell', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'width', '40px', tableCell ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:width:tableCell', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'width', '40px', tableCell ) ); + + assertTableCellStyle( editor, '' ); + } ); + it( 'should downcast width attribute', () => { model.change( writer => writer.setAttribute( 'width', '20px', tableCell ) ); @@ -814,6 +974,26 @@ describe( 'table cell properties', () => { tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] ); } ); + it( 'should consume converted item height attribute', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:height:tableCell', ( evt, data, conversionApi ) => { + expect( conversionApi.consumable.consume( data.item, evt.name ) ).to.be.false; + } ) ); + + model.change( writer => writer.setAttribute( 'height', '40px', tableCell ) ); + } ); + + it( 'should be overridable', () => { + editor.conversion.for( 'downcast' ) + .add( dispatcher => dispatcher.on( 'attribute:height:tableCell', ( evt, data, conversionApi ) => { + conversionApi.consumable.consume( data.item, evt.name ); + }, { priority: 'high' } ) ); + + model.change( writer => writer.setAttribute( 'height', '40px', tableCell ) ); + + assertTableCellStyle( editor, '' ); + } ); + it( 'should downcast height attribute', () => { model.change( writer => writer.setAttribute( 'height', '20px', tableCell ) ); From 9c7626a16854ed9e9280bec65c0da0385860c224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 6 Feb 2020 15:18:34 +0100 Subject: [PATCH 05/15] Change output styles for alignment attribute. --- src/tableproperties/tablepropertiesediting.js | 41 +++++++++++-------- tests/_utils/utils.js | 4 +- .../tableproperties/tablepropertiesediting.js | 32 ++++++++++++--- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/src/tableproperties/tablepropertiesediting.js b/src/tableproperties/tablepropertiesediting.js index f3e0107b..6726a154 100644 --- a/src/tableproperties/tablepropertiesediting.js +++ b/src/tableproperties/tablepropertiesediting.js @@ -12,7 +12,7 @@ import { addBorderRules } from '@ckeditor/ckeditor5-engine/src/view/styles/borde import { addBackgroundRules } from '@ckeditor/ckeditor5-engine/src/view/styles/background'; import TableEditing from './../tableediting'; -import { downcastTableAttribute, upcastStyleToAttribute, upcastBorderStyles } from './../converters/tableproperties'; +import { downcastTableAttribute, upcastBorderStyles, upcastStyleToAttribute } from './../converters/tableproperties'; import TableBackgroundColorCommand from './commands/tablebackgroundcolorcommand'; import TableBorderColorCommand from './commands/tablebordercolorcommand'; import TableBorderStyleCommand from './commands/tableborderstylecommand'; @@ -156,26 +156,10 @@ function enableAlignmentProperty( schema, conversion ) { const table = [ ...mapper.toViewElement( item ).getChildren() ].find( child => child.is( 'table' ) ); if ( !attributeNewValue ) { - writer.removeStyle( 'margin-left', table ); - writer.removeStyle( 'margin-right', table ); - return; } - const styles = { - 'margin-right': 'auto', - 'margin-left': 'auto' - }; - - if ( attributeNewValue == 'left' ) { - styles[ 'margin-left' ] = '0'; - } - - if ( attributeNewValue == 'right' ) { - styles[ 'margin-right' ] = '0'; - } - - writer.setStyle( styles, table ); + writer.setStyle( getAlignmentStylesForAttribute( attributeNewValue ), table ); } ) ); } @@ -192,3 +176,24 @@ function enableProperty( schema, conversion, modelAttribute, styleName ) { upcastStyleToAttribute( conversion, 'table', modelAttribute, styleName ); downcastTableAttribute( conversion, modelAttribute, styleName ); } + +function getAlignmentStylesForAttribute( attributeNewValue ) { + const styles = {}; + + if ( attributeNewValue == 'center' ) { + styles[ 'margin-left' ] = 'auto'; + styles[ 'margin-right' ] = 'auto'; + } + + if ( attributeNewValue == 'left' ) { + styles[ 'margin-left' ] = '0'; + styles.float = 'right'; + } + + if ( attributeNewValue == 'right' ) { + styles[ 'margin-right' ] = '0'; + styles.float = 'left'; + } + return styles; +} + diff --git a/tests/_utils/utils.js b/tests/_utils/utils.js index 20d5b379..c0b18335 100644 --- a/tests/_utils/utils.js +++ b/tests/_utils/utils.js @@ -297,9 +297,9 @@ export function assertTRBLAttribute( element, key, top, right = top, bottom = to * An assertion helper for testing the `` style attribute. * * @param {module:core/editor/editor~Editor} editor - * @param {String} tableStyle A style to assert on table. + * @param {String} [tableStyle=''] A style to assert on table. */ -export function assertTableStyle( editor, tableStyle ) { +export function assertTableStyle( editor, tableStyle = '' ) { const styleEntry = tableStyle ? ` style="${ tableStyle }"` : ''; assertEqualMarkup( editor.getData(), diff --git a/tests/tableproperties/tablepropertiesediting.js b/tests/tableproperties/tablepropertiesediting.js index 555c7d89..5bf928d6 100644 --- a/tests/tableproperties/tablepropertiesediting.js +++ b/tests/tableproperties/tablepropertiesediting.js @@ -574,7 +574,7 @@ describe( 'table properties', () => { } ); } ); - describe( 'alignment', () => { + describe.only( 'alignment', () => { it( 'should set proper schema rules', () => { expect( model.schema.checkAttribute( [ '$root', 'table' ], 'alignment' ) ).to.be.true; } ); @@ -661,13 +661,13 @@ describe( 'table properties', () => { it( 'should downcast right alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, 'margin-left:auto;margin-right:0;' ); + assertTableStyle( editor, 'float:left;margin-right:0;' ); } ); it( 'should downcast left alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'left', table ) ); - assertTableStyle( editor, 'margin-left:0;margin-right:auto;' ); + assertTableStyle( editor, 'float:right;margin-left:0;' ); } ); it( 'should downcast centered alignment', () => { @@ -676,17 +676,27 @@ describe( 'table properties', () => { assertTableStyle( editor, 'margin-left:auto;margin-right:auto;' ); } ); - it( 'should downcast changed alignment', () => { + it( 'should downcast changed alignment (center -> right)', () => { model.change( writer => writer.setAttribute( 'alignment', 'center', table ) ); assertTableStyle( editor, 'margin-left:auto;margin-right:auto;' ); model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, 'margin-left:auto;margin-right:0;' ); + assertTableStyle( editor, 'float:left;margin-right:0;' ); } ); - it( 'should downcast removed alignment', () => { + it( 'should downcast changed alignment (right -> center)', () => { + model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); + + assertTableStyle( editor, 'float:left;margin-right:0;' ); + + model.change( writer => writer.setAttribute( 'alignment', 'center', table ) ); + + assertTableStyle( editor, 'margin-left:auto;margin-right:auto;' ); + } ); + + it( 'should downcast removed alignment (from center)', () => { model.change( writer => writer.setAttribute( 'alignment', 'center', table ) ); assertTableStyle( editor, 'margin-left:auto;margin-right:auto;' ); @@ -695,6 +705,16 @@ describe( 'table properties', () => { assertTableStyle( editor ); } ); + + it( 'should downcast removed alignment (from right)', () => { + model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); + + assertTableStyle( editor, 'float:left;margin-right:0;' ); + + model.change( writer => writer.removeAttribute( 'alignment', table ) ); + + assertTableStyle( editor ); + } ); } ); } ); From a99d1868618cb4a070a81c6a0e9f8d9c0d80617a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 6 Feb 2020 15:34:39 +0100 Subject: [PATCH 06/15] Use downcast attributeToAttribute conversion helper for alignment attribute. --- src/tableproperties/tablepropertiesediting.js | 63 +++++++++---------- tests/_utils/utils.js | 14 +++-- .../tableproperties/tablepropertiesediting.js | 18 +++--- 3 files changed, 50 insertions(+), 45 deletions(-) diff --git a/src/tableproperties/tablepropertiesediting.js b/src/tableproperties/tablepropertiesediting.js index 6726a154..54287f36 100644 --- a/src/tableproperties/tablepropertiesediting.js +++ b/src/tableproperties/tablepropertiesediting.js @@ -149,18 +149,38 @@ function enableAlignmentProperty( schema, conversion ) { value: viewElement => viewElement.getAttribute( 'align' ) } } ); - conversion.for( 'downcast' ).add( dispatcher => dispatcher.on( 'attribute:alignment:table', ( evt, data, conversionApi ) => { - const { item, attributeNewValue } = data; - const { mapper, writer } = conversionApi; - const table = [ ...mapper.toViewElement( item ).getChildren() ].find( child => child.is( 'table' ) ); - - if ( !attributeNewValue ) { - return; - } - - writer.setStyle( getAlignmentStylesForAttribute( attributeNewValue ), table ); - } ) ); + conversion.for( 'downcast' ) + .attributeToAttribute( { + model: { + key: 'alignment', + values: [ 'left', 'center', 'right' ] + }, + view: { + left: { + key: 'style', + value: { + 'margin-left': '0', + float: 'right' + } + }, + center: { + key: 'style', + value: { + 'margin-right': 'auto', + 'margin-left': 'auto' + } + }, + right: { + key: 'style', + value: { + 'margin-right': '0', + float: 'left' + } + } + }, + converterPriority: 'high' + } ); } // Enables conversion for an attribute for simple view-model mappings. @@ -176,24 +196,3 @@ function enableProperty( schema, conversion, modelAttribute, styleName ) { upcastStyleToAttribute( conversion, 'table', modelAttribute, styleName ); downcastTableAttribute( conversion, modelAttribute, styleName ); } - -function getAlignmentStylesForAttribute( attributeNewValue ) { - const styles = {}; - - if ( attributeNewValue == 'center' ) { - styles[ 'margin-left' ] = 'auto'; - styles[ 'margin-right' ] = 'auto'; - } - - if ( attributeNewValue == 'left' ) { - styles[ 'margin-left' ] = '0'; - styles.float = 'right'; - } - - if ( attributeNewValue == 'right' ) { - styles[ 'margin-right' ] = '0'; - styles.float = 'left'; - } - return styles; -} - diff --git a/tests/_utils/utils.js b/tests/_utils/utils.js index c0b18335..ed14d59c 100644 --- a/tests/_utils/utils.js +++ b/tests/_utils/utils.js @@ -297,13 +297,19 @@ export function assertTRBLAttribute( element, key, top, right = top, bottom = to * An assertion helper for testing the `
` style attribute. * * @param {module:core/editor/editor~Editor} editor - * @param {String} [tableStyle=''] A style to assert on table. + * @param {String} [tableStyle=''] A style to assert on
. + * @param {String} [figureStyle=''] A style to assert on
. */ -export function assertTableStyle( editor, tableStyle = '' ) { - const styleEntry = tableStyle ? ` style="${ tableStyle }"` : ''; +export function assertTableStyle( editor, tableStyle, figureStyle ) { + const tableStyleEntry = tableStyle ? ` style="${ tableStyle }"` : ''; + const figureStyleEntry = figureStyle ? ` style="${ figureStyle }"` : ''; assertEqualMarkup( editor.getData(), - `
foo
` + `
` + + `` + + 'foo' + + '' + + '
' ); } diff --git a/tests/tableproperties/tablepropertiesediting.js b/tests/tableproperties/tablepropertiesediting.js index 5bf928d6..72c7ff88 100644 --- a/tests/tableproperties/tablepropertiesediting.js +++ b/tests/tableproperties/tablepropertiesediting.js @@ -661,45 +661,45 @@ describe( 'table properties', () => { it( 'should downcast right alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, 'float:left;margin-right:0;' ); + assertTableStyle( editor, null, 'float:left;margin-right:0;' ); } ); it( 'should downcast left alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'left', table ) ); - assertTableStyle( editor, 'float:right;margin-left:0;' ); + assertTableStyle( editor, null, 'float:right;margin-left:0;' ); } ); it( 'should downcast centered alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'center', table ) ); - assertTableStyle( editor, 'margin-left:auto;margin-right:auto;' ); + assertTableStyle( editor, null, 'margin-left:auto;margin-right:auto;' ); } ); it( 'should downcast changed alignment (center -> right)', () => { model.change( writer => writer.setAttribute( 'alignment', 'center', table ) ); - assertTableStyle( editor, 'margin-left:auto;margin-right:auto;' ); + assertTableStyle( editor, null, 'margin-left:auto;margin-right:auto;' ); model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, 'float:left;margin-right:0;' ); + assertTableStyle( editor, null, 'float:left;margin-right:0;' ); } ); it( 'should downcast changed alignment (right -> center)', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, 'float:left;margin-right:0;' ); + assertTableStyle( editor, null, 'float:left;margin-right:0;' ); model.change( writer => writer.setAttribute( 'alignment', 'center', table ) ); - assertTableStyle( editor, 'margin-left:auto;margin-right:auto;' ); + assertTableStyle( editor, null, 'margin-left:auto;margin-right:auto;' ); } ); it( 'should downcast removed alignment (from center)', () => { model.change( writer => writer.setAttribute( 'alignment', 'center', table ) ); - assertTableStyle( editor, 'margin-left:auto;margin-right:auto;' ); + assertTableStyle( editor, null, 'margin-left:auto;margin-right:auto;' ); model.change( writer => writer.removeAttribute( 'alignment', table ) ); @@ -709,7 +709,7 @@ describe( 'table properties', () => { it( 'should downcast removed alignment (from right)', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, 'float:left;margin-right:0;' ); + assertTableStyle( editor, null, 'float:left;margin-right:0;' ); model.change( writer => writer.removeAttribute( 'alignment', table ) ); From b3dbe3881785c33f22bf28c8bc2353e1d48c61d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 6 Feb 2020 16:36:51 +0100 Subject: [PATCH 07/15] Use conversion.attributeToAttribute() helper for alignment property. --- src/tableproperties/tablepropertiesediting.js | 55 ++++++------------- .../commands/tablealignmentcommand.js | 8 +-- .../tableproperties/tablepropertiesediting.js | 28 +++------- 3 files changed, 27 insertions(+), 64 deletions(-) diff --git a/src/tableproperties/tablepropertiesediting.js b/src/tableproperties/tablepropertiesediting.js index 54287f36..47ee207d 100644 --- a/src/tableproperties/tablepropertiesediting.js +++ b/src/tableproperties/tablepropertiesediting.js @@ -22,7 +22,6 @@ import TableHeightCommand from './commands/tableheightcommand'; import TableAlignmentCommand from './commands/tablealignmentcommand'; // RegExp used for matching margin style in converters. -const MARGIN_REG_EXP = /^(auto|0(%|[a-z]{2,4})?)$/; const ALIGN_VALUES_REG_EXP = /^(left|right|center)$/; /** @@ -111,48 +110,11 @@ function enableAlignmentProperty( schema, conversion ) { schema.extend( 'table', { allowAttributes: [ 'alignment' ] } ); - conversion.for( 'upcast' ) - .attributeToAttribute( { - view: { - styles: { - 'margin-right': MARGIN_REG_EXP, - 'margin-left': MARGIN_REG_EXP - } - }, - model: { - name: 'table', - key: 'alignment', - value: viewElement => { - // At this point we only have auto or 0 value (with a unit). - if ( viewElement.getStyle( 'margin-right' ) != 'auto' ) { - return 'right'; - } - - if ( viewElement.getStyle( 'margin-left' ) != 'auto' ) { - return 'left'; - } - return 'center'; - } - } - } ) - // Support for backwards compatibility and pasting from other sources. + conversion .attributeToAttribute( { - view: { - attributes: { - align: ALIGN_VALUES_REG_EXP - } - }, model: { name: 'table', - key: 'alignment', - value: viewElement => viewElement.getAttribute( 'align' ) - } - } ); - - conversion.for( 'downcast' ) - .attributeToAttribute( { - model: { key: 'alignment', values: [ 'left', 'center', 'right' ] }, @@ -181,6 +143,21 @@ function enableAlignmentProperty( schema, conversion ) { }, converterPriority: 'high' } ); + + conversion.for( 'upcast' ) + // Support for backwards compatibility and pasting from other sources. + .attributeToAttribute( { + view: { + attributes: { + align: ALIGN_VALUES_REG_EXP + } + }, + model: { + name: 'table', + key: 'alignment', + value: viewElement => viewElement.getAttribute( 'align' ) + } + } ); } // Enables conversion for an attribute for simple view-model mappings. diff --git a/tests/tableproperties/commands/tablealignmentcommand.js b/tests/tableproperties/commands/tablealignmentcommand.js index 07a0384e..d277761b 100644 --- a/tests/tableproperties/commands/tablealignmentcommand.js +++ b/tests/tableproperties/commands/tablealignmentcommand.js @@ -102,7 +102,7 @@ describe( 'table properties', () => { command.execute( { value: 'right' } ); - assertTableStyle( editor, 'margin-left:auto;margin-right:0;' ); + assertTableStyle( editor, null, 'float:left;margin-right:0;' ); } ); it( 'should change selected table alignment to a passed value', () => { @@ -110,7 +110,7 @@ describe( 'table properties', () => { command.execute( { value: 'right' } ); - assertTableStyle( editor, 'margin-left:auto;margin-right:0;' ); + assertTableStyle( editor, null, 'float:left;margin-right:0;' ); } ); it( 'should remove alignment from a selected table if no value is passed', () => { @@ -128,7 +128,7 @@ describe( 'table properties', () => { command.execute( { value: 'right' } ); - assertTableStyle( editor, 'margin-left:auto;margin-right:0;' ); + assertTableStyle( editor, null, 'float:left;margin-right:0;' ); } ); it( 'should change selected table alignment to a passed value', () => { @@ -136,7 +136,7 @@ describe( 'table properties', () => { command.execute( { value: 'right' } ); - assertTableStyle( editor, 'margin-left:auto;margin-right:0;' ); + assertTableStyle( editor, null, 'float:left;margin-right:0;' ); } ); it( 'should remove alignment from a selected table if no value is passed', () => { diff --git a/tests/tableproperties/tablepropertiesediting.js b/tests/tableproperties/tablepropertiesediting.js index 72c7ff88..f4ac9032 100644 --- a/tests/tableproperties/tablepropertiesediting.js +++ b/tests/tableproperties/tablepropertiesediting.js @@ -574,21 +574,21 @@ describe( 'table properties', () => { } ); } ); - describe.only( 'alignment', () => { + describe( 'alignment', () => { it( 'should set proper schema rules', () => { expect( model.schema.checkAttribute( [ '$root', 'table' ], 'alignment' ) ).to.be.true; } ); describe( 'upcast conversion', () => { - it( 'should upcast style="margin-left:auto;margin-right:0" to right value', () => { - editor.setData( '
foo
' ); + it( 'should upcast style="float:left;margin-right:0" to right value', () => { + editor.setData( '
foo
' ); const table = model.document.getRoot().getNodeByPath( [ 0 ] ); expect( table.getAttribute( 'alignment' ) ).to.equal( 'right' ); } ); - it( 'should upcast style="margin-left:0;margin-right:auto" to left value', () => { - editor.setData( '
foo
' ); + it( 'should upcast style="margin-left:0;float:right;" to left value', () => { + editor.setData( '
foo
' ); const table = model.document.getRoot().getNodeByPath( [ 0 ] ); expect( table.getAttribute( 'alignment' ) ).to.equal( 'left' ); @@ -601,22 +601,8 @@ describe( 'table properties', () => { expect( table.getAttribute( 'alignment' ) ).to.equal( 'center' ); } ); - it( 'should upcast style="margin-left:auto;margin-right:0pt" to right value', () => { - editor.setData( '
foo
' ); - const table = model.document.getRoot().getNodeByPath( [ 0 ] ); - - expect( table.getAttribute( 'alignment' ) ).to.equal( 'right' ); - } ); - - it( 'should upcast style="margin-left:auto;margin-right:0%" to right value', () => { - editor.setData( '
foo
' ); - const table = model.document.getRoot().getNodeByPath( [ 0 ] ); - - expect( table.getAttribute( 'alignment' ) ).to.equal( 'right' ); - } ); - - it( 'should not upcast style="margin-left:auto;margin-right:0.23pt" to right value', () => { - editor.setData( '
foo
' ); + it( 'should not upcast style="float:left;margin-right:23px" to right value (non-zero margin)', () => { + editor.setData( '
foo
' ); const table = model.document.getRoot().getNodeByPath( [ 0 ] ); expect( table.hasAttribute( 'alignment' ) ).to.be.false; From 6aea6e5aec69c1725a3c29018d9e8f42299bfbb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Mon, 10 Feb 2020 13:05:35 +0100 Subject: [PATCH 08/15] Fix floats in table alignment conversion. --- src/tableproperties/tablepropertiesediting.js | 4 ++-- .../tableproperties/tablepropertiesediting.js | 24 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/tableproperties/tablepropertiesediting.js b/src/tableproperties/tablepropertiesediting.js index 47ee207d..7a10ddc1 100644 --- a/src/tableproperties/tablepropertiesediting.js +++ b/src/tableproperties/tablepropertiesediting.js @@ -123,7 +123,7 @@ function enableAlignmentProperty( schema, conversion ) { key: 'style', value: { 'margin-left': '0', - float: 'right' + float: 'left' } }, center: { @@ -137,7 +137,7 @@ function enableAlignmentProperty( schema, conversion ) { key: 'style', value: { 'margin-right': '0', - float: 'left' + float: 'right' } } }, diff --git a/tests/tableproperties/tablepropertiesediting.js b/tests/tableproperties/tablepropertiesediting.js index 0a0f8181..dcb3f914 100644 --- a/tests/tableproperties/tablepropertiesediting.js +++ b/tests/tableproperties/tablepropertiesediting.js @@ -21,7 +21,7 @@ import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-util import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils'; import { assertTableStyle, assertTRBLAttribute } from '../_utils/utils'; -describe( 'table properties', () => { +describe.only( 'table properties', () => { describe( 'TablePropertiesEditing', () => { let editor, model; @@ -700,15 +700,15 @@ describe( 'table properties', () => { } ); describe( 'upcast conversion', () => { - it( 'should upcast style="float:left;margin-right:0" to right value', () => { - editor.setData( '
foo
' ); + it( 'should upcast style="float:right;margin-right:0" to right value', () => { + editor.setData( '
foo
' ); const table = model.document.getRoot().getNodeByPath( [ 0 ] ); expect( table.getAttribute( 'alignment' ) ).to.equal( 'right' ); } ); - it( 'should upcast style="margin-left:0;float:right;" to left value', () => { - editor.setData( '
foo
' ); + it( 'should upcast style="margin-left:0;float:left;" to left value', () => { + editor.setData( '
foo
' ); const table = model.document.getRoot().getNodeByPath( [ 0 ] ); expect( table.getAttribute( 'alignment' ) ).to.equal( 'left' ); @@ -721,8 +721,8 @@ describe( 'table properties', () => { expect( table.getAttribute( 'alignment' ) ).to.equal( 'center' ); } ); - it( 'should not upcast style="float:left;margin-right:23px" to right value (non-zero margin)', () => { - editor.setData( '
foo
' ); + it( 'should not upcast style="float:right;margin-right:23px" to right value (non-zero margin)', () => { + editor.setData( '
foo
' ); const table = model.document.getRoot().getNodeByPath( [ 0 ] ); expect( table.hasAttribute( 'alignment' ) ).to.be.false; @@ -787,13 +787,13 @@ describe( 'table properties', () => { it( 'should downcast right alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, null, 'float:left;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;margin-right:0;' ); } ); it( 'should downcast left alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'left', table ) ); - assertTableStyle( editor, null, 'float:right;margin-left:0;' ); + assertTableStyle( editor, null, 'float:left;margin-left:0;' ); } ); it( 'should downcast centered alignment', () => { @@ -809,13 +809,13 @@ describe( 'table properties', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, null, 'float:left;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;margin-right:0;' ); } ); it( 'should downcast changed alignment (right -> center)', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, null, 'float:left;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;margin-right:0;' ); model.change( writer => writer.setAttribute( 'alignment', 'center', table ) ); @@ -835,7 +835,7 @@ describe( 'table properties', () => { it( 'should downcast removed alignment (from right)', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, null, 'float:left;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;margin-right:0;' ); model.change( writer => writer.removeAttribute( 'alignment', table ) ); From 3634667ee7317a56b8810f1b016751b1b3a70034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Mon, 10 Feb 2020 13:19:31 +0100 Subject: [PATCH 09/15] Remove .only from tests. --- tests/tableproperties/tablepropertiesediting.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tableproperties/tablepropertiesediting.js b/tests/tableproperties/tablepropertiesediting.js index dcb3f914..dd19607d 100644 --- a/tests/tableproperties/tablepropertiesediting.js +++ b/tests/tableproperties/tablepropertiesediting.js @@ -21,7 +21,7 @@ import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-util import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils'; import { assertTableStyle, assertTRBLAttribute } from '../_utils/utils'; -describe.only( 'table properties', () => { +describe( 'table properties', () => { describe( 'TablePropertiesEditing', () => { let editor, model; From 5af78ecf7891f79f24da49d59cc580483cdfb198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Mon, 10 Feb 2020 14:18:25 +0100 Subject: [PATCH 10/15] Change test for table alignment - center should not be converted. --- .../tableproperties/tablepropertiesediting.js | 37 ++++++++----------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/tests/tableproperties/tablepropertiesediting.js b/tests/tableproperties/tablepropertiesediting.js index dd19607d..b44aded9 100644 --- a/tests/tableproperties/tablepropertiesediting.js +++ b/tests/tableproperties/tablepropertiesediting.js @@ -714,13 +714,6 @@ describe( 'table properties', () => { expect( table.getAttribute( 'alignment' ) ).to.equal( 'left' ); } ); - it( 'should upcast style="margin-left:auto;margin-right:auto" to center value', () => { - editor.setData( '
foo
' ); - const table = model.document.getRoot().getNodeByPath( [ 0 ] ); - - expect( table.getAttribute( 'alignment' ) ).to.equal( 'center' ); - } ); - it( 'should not upcast style="float:right;margin-right:23px" to right value (non-zero margin)', () => { editor.setData( '
foo
' ); const table = model.document.getRoot().getNodeByPath( [ 0 ] ); @@ -742,11 +735,11 @@ describe( 'table properties', () => { expect( table.getAttribute( 'alignment' ) ).to.equal( 'left' ); } ); - it( 'should upcast align=center attribute', () => { + it( 'should discard align=center attribute', () => { editor.setData( '
foo
' ); const table = model.document.getRoot().getNodeByPath( [ 0 ] ); - expect( table.getAttribute( 'alignment' ) ).to.equal( 'center' ); + expect( table.getAttribute( 'alignment' ) ).to.be.undefined; } ); it( 'should discard align=justify attribute', () => { @@ -784,48 +777,48 @@ describe( 'table properties', () => { assertTableStyle( editor, '' ); } ); - it( 'should downcast right alignment', () => { + it( 'should downcast "right" alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); assertTableStyle( editor, null, 'float:right;margin-right:0;' ); } ); - it( 'should downcast left alignment', () => { + it( 'should downcast "left" alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'left', table ) ); assertTableStyle( editor, null, 'float:left;margin-left:0;' ); } ); - it( 'should downcast centered alignment', () => { + it( 'should not downcast "center" alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'center', table ) ); - assertTableStyle( editor, null, 'margin-left:auto;margin-right:auto;' ); + assertTableStyle( editor, null, '' ); } ); - it( 'should downcast changed alignment (center -> right)', () => { - model.change( writer => writer.setAttribute( 'alignment', 'center', table ) ); + it( 'should downcast changed alignment (left -> right)', () => { + model.change( writer => writer.setAttribute( 'alignment', 'left', table ) ); - assertTableStyle( editor, null, 'margin-left:auto;margin-right:auto;' ); + assertTableStyle( editor, null, 'float:left;margin-left:0;' ); model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); assertTableStyle( editor, null, 'float:right;margin-right:0;' ); } ); - it( 'should downcast changed alignment (right -> center)', () => { + it( 'should downcast changed alignment (right -> left)', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); assertTableStyle( editor, null, 'float:right;margin-right:0;' ); - model.change( writer => writer.setAttribute( 'alignment', 'center', table ) ); + model.change( writer => writer.setAttribute( 'alignment', 'left', table ) ); - assertTableStyle( editor, null, 'margin-left:auto;margin-right:auto;' ); + assertTableStyle( editor, null, 'float:left;margin-left:0;' ); } ); - it( 'should downcast removed alignment (from center)', () => { - model.change( writer => writer.setAttribute( 'alignment', 'center', table ) ); + it( 'should downcast removed alignment (from left)', () => { + model.change( writer => writer.setAttribute( 'alignment', 'left', table ) ); - assertTableStyle( editor, null, 'margin-left:auto;margin-right:auto;' ); + assertTableStyle( editor, null, 'float:left;margin-left:0;' ); model.change( writer => writer.removeAttribute( 'alignment', table ) ); From 32491a48e0068918e02f792ca93d6b422b420440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Mon, 10 Feb 2020 14:22:05 +0100 Subject: [PATCH 11/15] Fix table alignment command tests. --- tests/tableproperties/commands/tablealignmentcommand.js | 8 ++++---- .../tableproperties/tablepropertiesediting-integration.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/tableproperties/commands/tablealignmentcommand.js b/tests/tableproperties/commands/tablealignmentcommand.js index d277761b..44b3e6fd 100644 --- a/tests/tableproperties/commands/tablealignmentcommand.js +++ b/tests/tableproperties/commands/tablealignmentcommand.js @@ -102,7 +102,7 @@ describe( 'table properties', () => { command.execute( { value: 'right' } ); - assertTableStyle( editor, null, 'float:left;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;margin-right:0;' ); } ); it( 'should change selected table alignment to a passed value', () => { @@ -110,7 +110,7 @@ describe( 'table properties', () => { command.execute( { value: 'right' } ); - assertTableStyle( editor, null, 'float:left;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;margin-right:0;' ); } ); it( 'should remove alignment from a selected table if no value is passed', () => { @@ -128,7 +128,7 @@ describe( 'table properties', () => { command.execute( { value: 'right' } ); - assertTableStyle( editor, null, 'float:left;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;margin-right:0;' ); } ); it( 'should change selected table alignment to a passed value', () => { @@ -136,7 +136,7 @@ describe( 'table properties', () => { command.execute( { value: 'right' } ); - assertTableStyle( editor, null, 'float:left;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;margin-right:0;' ); } ); it( 'should remove alignment from a selected table if no value is passed', () => { diff --git a/tests/tableproperties/tablepropertiesediting-integration.js b/tests/tableproperties/tablepropertiesediting-integration.js index 571b0278..7a77fb7d 100644 --- a/tests/tableproperties/tablepropertiesediting-integration.js +++ b/tests/tableproperties/tablepropertiesediting-integration.js @@ -35,7 +35,7 @@ describe( 'table properties', () => { it( 'should properly downcast table with Alignment plugin enabled', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, 'margin-left:auto;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;margin-right:0;' ); } ); } ); From 5d25bdd73037bfe976d237fb48e991a2e084e1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Mon, 10 Feb 2020 14:24:30 +0100 Subject: [PATCH 12/15] Table alignment property should not convert "center" value. --- src/tableproperties/tablepropertiesediting.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/tableproperties/tablepropertiesediting.js b/src/tableproperties/tablepropertiesediting.js index 7a10ddc1..b04d7e4d 100644 --- a/src/tableproperties/tablepropertiesediting.js +++ b/src/tableproperties/tablepropertiesediting.js @@ -22,7 +22,7 @@ import TableHeightCommand from './commands/tableheightcommand'; import TableAlignmentCommand from './commands/tablealignmentcommand'; // RegExp used for matching margin style in converters. -const ALIGN_VALUES_REG_EXP = /^(left|right|center)$/; +const ALIGN_VALUES_REG_EXP = /^(left|right)$/; /** * The table properties editing feature. @@ -116,7 +116,7 @@ function enableAlignmentProperty( schema, conversion ) { model: { name: 'table', key: 'alignment', - values: [ 'left', 'center', 'right' ] + values: [ 'left', 'right' ] }, view: { left: { @@ -126,13 +126,6 @@ function enableAlignmentProperty( schema, conversion ) { float: 'left' } }, - center: { - key: 'style', - value: { - 'margin-right': 'auto', - 'margin-left': 'auto' - } - }, right: { key: 'style', value: { From a54e15a67d815e332e2811e7c27f0a337363cc7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Tue, 11 Feb 2020 13:01:00 +0100 Subject: [PATCH 13/15] Make default alignment without value in the UI. --- src/tableproperties/tablepropertiesui.js | 2 +- src/tableproperties/ui/tablepropertiesview.js | 9 +++-- src/ui/utils.js | 9 +++-- .../tableproperties/tablepropertiesediting.js | 2 +- tests/tableproperties/tablepropertiesui.js | 2 +- .../tableproperties/ui/tablepropertiesview.js | 2 +- tests/ui/utils.js | 37 ++++++++++++++----- 7 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/tableproperties/tablepropertiesui.js b/src/tableproperties/tablepropertiesui.js index b6cbaabc..8b022830 100644 --- a/src/tableproperties/tablepropertiesui.js +++ b/src/tableproperties/tablepropertiesui.js @@ -25,7 +25,7 @@ import { import { debounce } from 'lodash-es'; const DEFAULT_BORDER_STYLE = 'none'; -const DEFAULT_ALIGNMENT = 'center'; +const DEFAULT_ALIGNMENT = ''; const ERROR_TEXT_TIMEOUT = 500; /** diff --git a/src/tableproperties/ui/tablepropertiesview.js b/src/tableproperties/ui/tablepropertiesview.js index 1b556e93..e1035b44 100644 --- a/src/tableproperties/ui/tablepropertiesview.js +++ b/src/tableproperties/ui/tablepropertiesview.js @@ -141,10 +141,10 @@ export default class TablePropertiesView extends View { * The value of the table alignment style. * * @observable - * @default 'center' + * @default '' * @member #alignment */ - alignment: 'center', + alignment: '' } ); /** @@ -574,7 +574,10 @@ export default class TablePropertiesView extends View { icons: ALIGNMENT_ICONS, toolbar: alignmentToolbar, labels: this._alignmentLabels, - propertyName: 'alignment' + propertyName: 'alignment', + nameToValue: name => { + return name === 'center' ? '' : name; + } } ); return { diff --git a/src/ui/utils.js b/src/ui/utils.js index 8475995f..b506fe6f 100644 --- a/src/ui/utils.js +++ b/src/ui/utils.js @@ -212,22 +212,23 @@ export function getBorderStyleDefinitions( view ) { * @param {module:ui/toolbar/toolbarview~ToolbarView} options.toolbar * @param {Object.} labels * @param {String} propertyName + * @param {Function} [nameToValue] Optional function that maps button name to value. By default names are the same as values. */ -export function fillToolbar( { view, icons, toolbar, labels, propertyName } ) { +export function fillToolbar( { view, icons, toolbar, labels, propertyName, nameToValue = name => name } ) { for ( const name in labels ) { const button = new ButtonView( view.locale ); button.set( { label: labels[ name ], - icon: icons[ name ], + icon: icons[ name ] } ); button.bind( 'isOn' ).to( view, propertyName, value => { - return value === name; + return value === nameToValue( name ); } ); button.on( 'execute', () => { - view[ propertyName ] = name; + view[ propertyName ] = nameToValue( name ); } ); toolbar.items.add( button ); diff --git a/tests/tableproperties/tablepropertiesediting.js b/tests/tableproperties/tablepropertiesediting.js index b44aded9..bf399d0a 100644 --- a/tests/tableproperties/tablepropertiesediting.js +++ b/tests/tableproperties/tablepropertiesediting.js @@ -792,7 +792,7 @@ describe( 'table properties', () => { it( 'should not downcast "center" alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'center', table ) ); - assertTableStyle( editor, null, '' ); + assertTableStyle( editor, null, null ); } ); it( 'should downcast changed alignment (left -> right)', () => { diff --git a/tests/tableproperties/tablepropertiesui.js b/tests/tableproperties/tablepropertiesui.js index 9f20f392..891433d5 100644 --- a/tests/tableproperties/tablepropertiesui.js +++ b/tests/tableproperties/tablepropertiesui.js @@ -512,7 +512,7 @@ describe( 'table properties', () => { backgroundColor: '', width: '', height: '', - alignment: 'center' + alignment: '' } ); } ); } ); diff --git a/tests/tableproperties/ui/tablepropertiesview.js b/tests/tableproperties/ui/tablepropertiesview.js index 3c9af010..d9dce431 100644 --- a/tests/tableproperties/ui/tablepropertiesview.js +++ b/tests/tableproperties/ui/tablepropertiesview.js @@ -50,7 +50,7 @@ describe( 'table properties', () => { backgroundColor: '', width: '', height: '', - alignment: 'center' + alignment: '' } ); } ); diff --git a/tests/ui/utils.js b/tests/ui/utils.js index d1191645..81c0b480 100644 --- a/tests/ui/utils.js +++ b/tests/ui/utils.js @@ -316,7 +316,7 @@ describe( 'UI Utils', () => { false, false, true, - false, + false ] ); } ); } ); @@ -326,12 +326,14 @@ describe( 'UI Utils', () => { const labels = { first: 'Do something', - second: 'Do something else' + second: 'Do something else', + third: 'Be default' }; const icons = { - first: '', - second: '' + first: '', + second: '', + third: '' }; beforeEach( () => { @@ -342,7 +344,8 @@ describe( 'UI Utils', () => { fillToolbar( { view, toolbar, icons, labels, - propertyName: 'someProperty' + propertyName: 'someProperty', + nameToValue: name => name === 'third' ? '' : name } ); } ); @@ -351,33 +354,45 @@ describe( 'UI Utils', () => { } ); it( 'should create buttons', () => { - expect( toolbar.items ).to.have.length( 2 ); + expect( toolbar.items ).to.have.length( 3 ); expect( toolbar.items.first ).to.be.instanceOf( ButtonView ); + expect( toolbar.items.get( 1 ) ).to.be.instanceOf( ButtonView ); expect( toolbar.items.last ).to.be.instanceOf( ButtonView ); } ); it( 'should set button labels', () => { expect( toolbar.items.first.label ).to.equal( 'Do something' ); - expect( toolbar.items.last.label ).to.equal( 'Do something else' ); + expect( toolbar.items.get( 1 ).label ).to.equal( 'Do something else' ); + expect( toolbar.items.last.label ).to.equal( 'Be default' ); } ); it( 'should set button icons', () => { expect( toolbar.items.first.icon ).to.equal( icons.first ); - expect( toolbar.items.last.icon ).to.equal( icons.second ); + expect( toolbar.items.get( 1 ).icon ).to.equal( icons.second ); + expect( toolbar.items.last.icon ).to.equal( icons.third ); } ); it( 'should bind button #isOn to an observable property', () => { expect( toolbar.items.first.isOn ).to.be.false; + expect( toolbar.items.get( 1 ).isOn ).to.be.false; expect( toolbar.items.last.isOn ).to.be.false; view.someProperty = 'first'; expect( toolbar.items.first.isOn ).to.be.true; + expect( toolbar.items.get( 1 ).isOn ).to.be.false; expect( toolbar.items.last.isOn ).to.be.false; view.someProperty = 'second'; expect( toolbar.items.first.isOn ).to.be.false; + expect( toolbar.items.get( 1 ).isOn ).to.be.true; + expect( toolbar.items.last.isOn ).to.be.false; + + view.someProperty = ''; + + expect( toolbar.items.first.isOn ).to.be.false; + expect( toolbar.items.get( 1 ).isOn ).to.be.false; expect( toolbar.items.last.isOn ).to.be.true; } ); @@ -386,9 +401,13 @@ describe( 'UI Utils', () => { expect( view.someProperty ).to.equal( 'first' ); - toolbar.items.last.fire( 'execute' ); + toolbar.items.get( 1 ).fire( 'execute' ); expect( view.someProperty ).to.equal( 'second' ); + + toolbar.items.last.fire( 'execute' ); + + expect( view.someProperty ).to.equal( '' ); } ); } ); } ); From 30375a16c90405029f635bfde3762f2feb58eb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Wed, 12 Feb 2020 12:45:34 +0100 Subject: [PATCH 14/15] Remove to margin left/right from table alignment converters. --- src/tableproperties/tablepropertiesediting.js | 3 -- .../commands/tablealignmentcommand.js | 8 ++--- .../tableproperties/tablepropertiesediting.js | 31 +++++++------------ 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/tableproperties/tablepropertiesediting.js b/src/tableproperties/tablepropertiesediting.js index 3e143b1f..39a1dca5 100644 --- a/src/tableproperties/tablepropertiesediting.js +++ b/src/tableproperties/tablepropertiesediting.js @@ -26,7 +26,6 @@ import TableWidthCommand from './commands/tablewidthcommand'; import TableHeightCommand from './commands/tableheightcommand'; import TableAlignmentCommand from './commands/tablealignmentcommand'; -// RegExp used for matching margin style in converters. const ALIGN_VALUES_REG_EXP = /^(left|right)$/; /** @@ -127,14 +126,12 @@ function enableAlignmentProperty( schema, conversion ) { left: { key: 'style', value: { - 'margin-left': '0', float: 'left' } }, right: { key: 'style', value: { - 'margin-right': '0', float: 'right' } } diff --git a/tests/tableproperties/commands/tablealignmentcommand.js b/tests/tableproperties/commands/tablealignmentcommand.js index 44b3e6fd..78a7b0e4 100644 --- a/tests/tableproperties/commands/tablealignmentcommand.js +++ b/tests/tableproperties/commands/tablealignmentcommand.js @@ -102,7 +102,7 @@ describe( 'table properties', () => { command.execute( { value: 'right' } ); - assertTableStyle( editor, null, 'float:right;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;' ); } ); it( 'should change selected table alignment to a passed value', () => { @@ -110,7 +110,7 @@ describe( 'table properties', () => { command.execute( { value: 'right' } ); - assertTableStyle( editor, null, 'float:right;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;' ); } ); it( 'should remove alignment from a selected table if no value is passed', () => { @@ -128,7 +128,7 @@ describe( 'table properties', () => { command.execute( { value: 'right' } ); - assertTableStyle( editor, null, 'float:right;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;' ); } ); it( 'should change selected table alignment to a passed value', () => { @@ -136,7 +136,7 @@ describe( 'table properties', () => { command.execute( { value: 'right' } ); - assertTableStyle( editor, null, 'float:right;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;' ); } ); it( 'should remove alignment from a selected table if no value is passed', () => { diff --git a/tests/tableproperties/tablepropertiesediting.js b/tests/tableproperties/tablepropertiesediting.js index 6353f481..a49237f9 100644 --- a/tests/tableproperties/tablepropertiesediting.js +++ b/tests/tableproperties/tablepropertiesediting.js @@ -768,27 +768,20 @@ describe( 'table properties', () => { } ); describe( 'upcast conversion', () => { - it( 'should upcast style="float:right;margin-right:0" to right value', () => { - editor.setData( '
foo
' ); + it( 'should upcast style="float:right" to right value', () => { + editor.setData( '
foo
' ); const table = model.document.getRoot().getNodeByPath( [ 0 ] ); expect( table.getAttribute( 'alignment' ) ).to.equal( 'right' ); } ); - it( 'should upcast style="margin-left:0;float:left;" to left value', () => { - editor.setData( '
foo
' ); + it( 'should upcast style="float:left;" to left value', () => { + editor.setData( '
foo
' ); const table = model.document.getRoot().getNodeByPath( [ 0 ] ); expect( table.getAttribute( 'alignment' ) ).to.equal( 'left' ); } ); - it( 'should not upcast style="float:right;margin-right:23px" to right value (non-zero margin)', () => { - editor.setData( '
foo
' ); - const table = model.document.getRoot().getNodeByPath( [ 0 ] ); - - expect( table.hasAttribute( 'alignment' ) ).to.be.false; - } ); - it( 'should upcast align=right attribute', () => { editor.setData( '
foo
' ); const table = model.document.getRoot().getNodeByPath( [ 0 ] ); @@ -848,13 +841,13 @@ describe( 'table properties', () => { it( 'should downcast "right" alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, null, 'float:right;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;' ); } ); it( 'should downcast "left" alignment', () => { model.change( writer => writer.setAttribute( 'alignment', 'left', table ) ); - assertTableStyle( editor, null, 'float:left;margin-left:0;' ); + assertTableStyle( editor, null, 'float:left;' ); } ); it( 'should not downcast "center" alignment', () => { @@ -866,27 +859,27 @@ describe( 'table properties', () => { it( 'should downcast changed alignment (left -> right)', () => { model.change( writer => writer.setAttribute( 'alignment', 'left', table ) ); - assertTableStyle( editor, null, 'float:left;margin-left:0;' ); + assertTableStyle( editor, null, 'float:left;' ); model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, null, 'float:right;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;' ); } ); it( 'should downcast changed alignment (right -> left)', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, null, 'float:right;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;' ); model.change( writer => writer.setAttribute( 'alignment', 'left', table ) ); - assertTableStyle( editor, null, 'float:left;margin-left:0;' ); + assertTableStyle( editor, null, 'float:left;' ); } ); it( 'should downcast removed alignment (from left)', () => { model.change( writer => writer.setAttribute( 'alignment', 'left', table ) ); - assertTableStyle( editor, null, 'float:left;margin-left:0;' ); + assertTableStyle( editor, null, 'float:left;' ); model.change( writer => writer.removeAttribute( 'alignment', table ) ); @@ -896,7 +889,7 @@ describe( 'table properties', () => { it( 'should downcast removed alignment (from right)', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, null, 'float:right;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;' ); model.change( writer => writer.removeAttribute( 'alignment', table ) ); From ea06fc762ac0ee6b1faca5def594f4dca0832f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Wed, 12 Feb 2020 12:49:52 +0100 Subject: [PATCH 15/15] Fix table properties integration tests. --- tests/tableproperties/tablepropertiesediting-integration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tableproperties/tablepropertiesediting-integration.js b/tests/tableproperties/tablepropertiesediting-integration.js index 7a77fb7d..9fea1124 100644 --- a/tests/tableproperties/tablepropertiesediting-integration.js +++ b/tests/tableproperties/tablepropertiesediting-integration.js @@ -35,7 +35,7 @@ describe( 'table properties', () => { it( 'should properly downcast table with Alignment plugin enabled', () => { model.change( writer => writer.setAttribute( 'alignment', 'right', table ) ); - assertTableStyle( editor, null, 'float:right;margin-right:0;' ); + assertTableStyle( editor, null, 'float:right;' ); } ); } );