-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
TableLayout
plugin.
#17931
base: ck/epic/email-editing
Are you sure you want to change the base?
TableLayout
plugin.
#17931
Conversation
Internal (table): Fix missing tableType attribute in cropTableToDimensions output.
packages/ckeditor5-table/src/commands/setheadercolumncommand.ts
Outdated
Show resolved
Hide resolved
* editor.execute( 'insertTableLayout', { rows: 20, columns: 5 } ); | ||
* ``` | ||
*/ | ||
export default class InsertTableLayoutCommand extends InsertTableCommand { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest extending a Command
and copy-paste the refresh()
method as it is extremely simple and we do not use anything else from the base command.
const tableUtils: TableUtils = editor.plugins.get( 'TableUtils' ); | ||
|
||
model.change( writer => { | ||
const table = tableUtils.createTableLayout( writer, options ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this helper is needed.
writer.setAttribute( 'tableWidth', '100%', table ); | ||
writer.setAttribute( 'tableType', 'layout', table ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the table width height attribute is unknown to the feature as it is not added to the editor? I'd remove this method.
/** | ||
* The table layout editing plugin. | ||
*/ | ||
export default class TableLayoutEditing extends Plugin { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should require the plugin that handles tableWidth
and tableHeight
. As I can see we have 2 plugins handling this attribute so maybe we should just check if that attribute is registered in the schema and warn if not?
const { editor } = this; | ||
const { conversion } = editor; | ||
|
||
conversion.for( 'upcast' ).add( upcastTableOverride() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conversion.for( 'upcast' ).add( upcastTableOverride() ); | |
conversion.for( 'upcast' ).add( upcastLayoutTable() ); |
* | ||
* @internal | ||
*/ | ||
function scanTable( viewTable: ViewElement ) { | ||
export function scanTable( viewTable: ViewElement ): { headingRows: number; headingColumns: number; rows: Array<ViewElement> } { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed.
export function isTableTypeContent( selectedCells: Array<Element> ): boolean { | ||
const table = selectedCells[ 0 ].findAncestor( 'table' )!; | ||
|
||
return table.getAttribute( 'tableType' ) !== 'layout'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks a bit overcomplicated for a single-purpose helper. Please use other common helpers or inline attribute checks where needed.
let isContentTable = true; | ||
|
||
if ( isInTable ) { | ||
isContentTable = isTableTypeContent( selectedCells ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check if schema allows headingRows
attribute instead of coupling those features.
let isContentTable = true; | ||
|
||
if ( isInTable ) { | ||
isContentTable = isTableTypeContent( selectedCells ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as in rows.
// Copy table type attribute if present. | ||
const sourceTableType = sourceTable.getAttribute( 'tableType' ); | ||
|
||
if ( sourceTableType ) { | ||
writer.setAttribute( 'tableType', sourceTableType, croppedTable ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a tight coupling. What should happen with tableWidth
attribute?
Suggested merge commit message (convention)
Internal: Implementation of
TableLayout
plugin.Additional information
For example – encountered issues, assumptions you had to make, other affected tickets, etc.