We can add support for styling table cells.
In this case it doesn't seem reasonable to approach the problem with our usual "closed set of styles" (like image "full" and "aside" styles). Instead, we need a full flavored option.
One way to imagine it would be a button "cell properties" in a table toolbar. It would open a bigger panel where you could choose border style, border width, cell size, alignment (v and h), background color, border color.
If you'd like to see this feature implemented, please react with 👍 to this ticket.
There are two distinctive requirements:
border: solid 1px red to 3 separate values in the model.Styles applied to <td>:
Styles applied to <table> itself:
<figure>)<figure>)border vs border-left vs border-left-styleModel:
table[border] = { left: {style,width,color}, top, ... } (object)Upcasting:
<table style="border: solid; border-left-width:23px; border-top:solid 2px blue; border-width: 10px; border-style: solid;">extractBorderStyles( tableViewElement ) → { left, top, ... }Downcasting:
border-left, border-top, border-bottom, border-rightborder, or if all 4 colors are identical and then output border-color.config.table.supportedProperties = [ ]; (conversion and UI)Ideally, it should be possible to write your own plugin which will add its option to e.g. cell properties panel. It's not necessarily MVP material, but if it will turn out that this is easily doable, it'll be perfect.
Could be done like this:
editor.plugins.get( 'TableCellPropertiesUI' ).addProperty( {
ui: sth, // some way to specify how the input will be displayed,
onSave: sth, // a callback doing something on save,
order: 100 // place on the list,
} );
This is oversimplified, because I don't know what's the best option to load the data into the UI and save it back. Especially in col/row cases when you have to read data from multiple items.
Perhaps, the simplest option is callback based.
const input = LabeledInputView( { label: 'Padding' } );
editor.plugins.get( 'TableCellPropertiesUI' ).addProperty( {
ui: ( cell ) => {
input.value = cell.getAttribute( 'padding' );
return input;
},
onSave: () => {
editor.execute( 'tableCellPadding', { value: cleanupValue( input.value ) } );
},
order: 100
} );
BTW, I'm totally unsure what to do with commands here. Separate commands for all those options? There will be many of them, but perhaps there's no other way.
First steps:
Just to confirm - the table/tableCell/tableRow properties should be prefixed with model element name?
tableCell:tableCellBorderWidth, tableCellBorderColor, tableCellBorderStyle,tableCellBackgroundColortableCellPaddingtableCellVerticalAlignmenttableColumnWidth (also should be on every cell or just in the first in column - might be hard if column is spanned on top)tableRowtableRowHeighttabletableBorderWidth, tableBorderColor, tableBorderStyletableBackgroundColortableWidthtableHeightModel for
tableRow
tableRowHeigh
I think this is still a table cell's setting. As the spec says:
For each cell in col/row apply these styles
BTW, I did you skip the alignment (of a table, but also a horizontal alignment of a table cell) on purpose when listing those attributes?
I've might just miss them. The other thing is that at least MS Word places the alignment on paragraphs so this works out of the box and I wonder what we should do there.
OK I see that prefixing those attributes doesn't make any sense - we have width on Image element already and table has headingRows not tableHadingRows.
OK guys, to sum up current work status I've concluded this list to track progress to finish MVP in a step 1 form - retention of as much pasted content as possible without adding table styles support in Paste From Office. I've extracted this from @Reinmar's comment with only relevant parts.
border vs border-left vs border-left-style to single normalized object (border - table[border] = { left: {style,width,color}, top, ... } )view/Element level - existing methods)view/Element level - new method) using "extracting" process to read from complex structures (border for now). You can read border-color object from border object.view/Element - different features might set similar properties and the output will always be normalized (string value) in a repeatable and predictable way in a process called "reducing" (or "inlining").ViewConsumable support for handling style shorthands (also make it pluggable as below)border, or if all 4 colors are identical and then output border-color. Note: already done for padding and margin should be fairly easy to add it for border though.border, background , margin and paddingIndent - yay 1 converter lessFont - also worksTableCellPropertiesTableColumnRowProperties handles table cell height / widthTablePropertiesbackgroundColor)borderColor, borderSyle, borderWidthwidth, heightverticalAlignmenttext-alignpaddingbackgroundColor<figure>) as width, height<figure>) - controviersial - do not use align attribute but margin-right=0;margin-left:auto as described on mdn. If so what with margin-right:23px;margin-left:auto - should this work with BlockIndent? (it could by consuming only auto values)ps.: this comment might be updated with more steps but ATM I think that's all what's needed for MVP step 1.
when this can be on prod?
when this can be on prod?
In two weeks 🤞
Most helpful comment
In two weeks 🤞