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

TableLayout plugin. #17931

Open
wants to merge 18 commits into
base: ck/epic/email-editing
Choose a base branch
from
Open

Conversation

pszczesniak
Copy link
Contributor

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.

@pszczesniak pszczesniak marked this pull request as ready for review February 19, 2025 15:12
mmotyczynska

This comment was marked as outdated.

* editor.execute( 'insertTableLayout', { rows: 20, columns: 5 } );
* ```
*/
export default class InsertTableLayoutCommand extends InsertTableCommand {
Copy link
Contributor

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 );
Copy link
Contributor

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.

Comment on lines +181 to +182
writer.setAttribute( 'tableWidth', '100%', table );
writer.setAttribute( 'tableType', 'layout', table );
Copy link
Contributor

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 {
Copy link
Contributor

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() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
conversion.for( 'upcast' ).add( upcastTableOverride() );
conversion.for( 'upcast' ).add( upcastLayoutTable() );

Comment on lines +202 to +205
*
* @internal
*/
function scanTable( viewTable: ViewElement ) {
export function scanTable( viewTable: ViewElement ): { headingRows: number; headingColumns: number; rows: Array<ViewElement> } {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed.

Comment on lines +111 to +115
export function isTableTypeContent( selectedCells: Array<Element> ): boolean {
const table = selectedCells[ 0 ].findAncestor( 'table' )!;

return table.getAttribute( 'tableType' ) !== 'layout';
}
Copy link
Contributor

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.

Comment on lines +49 to +53
let isContentTable = true;

if ( isInTable ) {
isContentTable = isTableTypeContent( selectedCells );
}
Copy link
Contributor

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.

Comment on lines +53 to +57
let isContentTable = true;

if ( isInTable ) {
isContentTable = isTableTypeContent( selectedCells );
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in rows.

Comment on lines +65 to +70
// Copy table type attribute if present.
const sourceTableType = sourceTable.getAttribute( 'tableType' );

if ( sourceTableType ) {
writer.setAttribute( 'tableType', sourceTableType, croppedTable );
}
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants