Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Convert only top & bottom values for vertical-align.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Feb 13, 2020
1 parent 64206ae commit f166ba4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
34 changes: 33 additions & 1 deletion src/tablecellproperties/tablecellpropertiesediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class TableCellPropertiesEditing extends Plugin {
enableProperty( schema, conversion, 'backgroundColor', 'background-color' );
editor.commands.add( 'tableCellBackgroundColor', new TableCellBackgroundColorCommand( editor ) );

enableProperty( schema, conversion, 'verticalAlignment', 'vertical-align' );
enableVerticalAlignmentProperty( schema, conversion );
editor.commands.add( 'tableCellVerticalAlignment', new TableCellVerticalAlignmentCommand( editor ) );
}
}
Expand Down Expand Up @@ -150,6 +150,38 @@ function enableHorizontalAlignmentProperty( schema, conversion ) {
} );
}

// Enables the `'verticalAlignment'` attribute for table cells.
//
// @param {module:engine/model/schema~Schema} schema
// @param {module:engine/conversion/conversion~Conversion} conversion
function enableVerticalAlignmentProperty( schema, conversion ) {
schema.extend( 'tableCell', {
allowAttributes: [ 'verticalAlignment' ]
} );

conversion.attributeToAttribute( {
model: {
name: 'tableCell',
key: 'verticalAlignment',
values: [ 'top', 'bottom' ]
},
view: {
top: {
key: 'style',
value: {
'vertical-align': 'top'
}
},
bottom: {
key: 'style',
value: {
'vertical-align': 'bottom'
}
}
}
} );
}

// Enables conversion for an attribute for simple view-model mappings.
//
// @param {String} modelAttribute
Expand Down
20 changes: 17 additions & 3 deletions tests/tablecellproperties/tablecellpropertiesediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,12 +783,26 @@ describe( 'table cell properties', () => {
} );

describe( 'upcast conversion', () => {
it( 'should upcast vertical-align', () => {
it( 'should upcast "top" vertical-align', () => {
editor.setData( '<table><tr><td style="vertical-align:top">foo</td></tr></table>' );
const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );

expect( tableCell.getAttribute( 'verticalAlignment' ) ).to.equal( 'top' );
} );

it( 'should upcast "bottom" vertical-align', () => {
editor.setData( '<table><tr><td style="vertical-align:bottom">foo</td></tr></table>' );
const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );

expect( tableCell.getAttribute( 'verticalAlignment' ) ).to.equal( 'bottom' );
} );

it( 'should not upcast "middle" vertical-align', () => {
editor.setData( '<table><tr><td style="vertical-align:middle">foo</td></tr></table>' );
const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );

expect( tableCell.getAttribute( 'verticalAlignment' ) ).to.be.undefined;
} );
} );

describe( 'downcast conversion', () => {
Expand Down Expand Up @@ -829,9 +843,9 @@ describe( 'table cell properties', () => {
} );

it( 'should downcast verticalAlignment', () => {
model.change( writer => writer.setAttribute( 'verticalAlignment', 'middle', tableCell ) );
model.change( writer => writer.setAttribute( 'verticalAlignment', 'top', tableCell ) );

assertTableCellStyle( editor, 'vertical-align:middle;' );
assertTableCellStyle( editor, 'vertical-align:top;' );
} );
} );
} );
Expand Down

0 comments on commit f166ba4

Please sign in to comment.