Skip to content

Conversation

pszczesniak
Copy link
Contributor

@pszczesniak pszczesniak commented Mar 12, 2025

Suggested merge commit message (convention)

Internal: Introduce TableTypeCommand command. See #18131.


Additional information

For example – encountered issues, assumptions you had to make, other affected tickets, etc.

@pszczesniak pszczesniak changed the title Introduce SetTableType command. Introduce TableTypeCommand command. Mar 14, 2025
@pszczesniak pszczesniak marked this pull request as ready for review March 14, 2025 09:03
@pszczesniak pszczesniak assigned Mati365 and unassigned Mati365 Mar 14, 2025
@pszczesniak pszczesniak requested a review from Mati365 March 14, 2025 09:39
Comment on lines +72 to +77
// Check if all children are allowed for the new table type.
for ( const child of tableChildren ) {
if ( !model.schema.checkChild( table, child ) ) {
writer.remove( child );
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a post-fixer to ensure that some other feature won't break the model structure? I wonder if TC suggestion could alter the structure in an unexpected way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 91578b1.


import { getSelectionAffectedTable } from '../../utils/common.js';

export type TableType = 'layout' | 'content';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's import this type from 👉 #18121 (comment) (when this PR will merged).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 130e16a.

@pszczesniak pszczesniak requested a review from niegowski March 17, 2025 15:59
Comment on lines +168 to +186
// Remove disallowed attributes and children for layout tables
// when `tableType` attribute has been changed by `TableTypeCommand`.
if ( entry.type == 'attribute' && entry.attributeKey == 'tableType' ) {
for ( const item of entry.range.getItems() ) {
if ( item.is( 'element', 'table' ) ) {
editor.model.schema.removeDisallowedAttributes( [ item ], writer );

const tableChildren = item.getChildren();

// Check if all children are allowed for the new table type.
for ( const child of tableChildren ) {
if ( !editor.model.schema.checkChild( item, child ) ) {
writer.remove( child );
hasChanged = true;
}
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What about some captions added to a layout table? Or a heading cols/rows set on it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, let's leave it for a potential follow-up if such a case appears.

Comment on lines +168 to +186
// Remove disallowed attributes and children for layout tables
// when `tableType` attribute has been changed by `TableTypeCommand`.
if ( entry.type == 'attribute' && entry.attributeKey == 'tableType' ) {
for ( const item of entry.range.getItems() ) {
if ( item.is( 'element', 'table' ) ) {
editor.model.schema.removeDisallowedAttributes( [ item ], writer );

const tableChildren = item.getChildren();

// Check if all children are allowed for the new table type.
for ( const child of tableChildren ) {
if ( !editor.model.schema.checkChild( item, child ) ) {
writer.remove( child );
hasChanged = true;
}
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, let's leave it for a potential follow-up if such a case appears.

@pszczesniak pszczesniak merged commit 2b4d43a into ck/epic/email-editing Mar 18, 2025
7 checks passed
@pszczesniak pszczesniak deleted the ck/set-table-type-command branch March 18, 2025 13:58
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