-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Introduce TableTypeCommand
command.
#18109
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
Introduce TableTypeCommand
command.
#18109
Conversation
packages/ckeditor5-table/src/tablelayout/commands/settabletype.ts
Outdated
Show resolved
Hide resolved
packages/ckeditor5-table/src/tablelayout/commands/settabletype.ts
Outdated
Show resolved
Hide resolved
SetTableType
command.TableTypeCommand
command.
packages/ckeditor5-table/src/tablelayout/commands/tabletypecommand.ts
Outdated
Show resolved
Hide resolved
// 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 ); | ||
} | ||
} |
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.
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.
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.
Fixed in 91578b1.
|
||
import { getSelectionAffectedTable } from '../../utils/common.js'; | ||
|
||
export type TableType = 'layout' | 'content'; |
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.
Let's import this type from 👉 #18121 (comment) (when this PR will merged).
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.
Done in 130e16a.
// 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; | ||
} | ||
} | ||
} | ||
} | ||
} |
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 about some captions added to a layout table? Or a heading cols/rows set on it?
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.
Ok, let's leave it for a potential follow-up if such a case appears.
// 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; | ||
} | ||
} | ||
} | ||
} | ||
} |
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.
Ok, let's leave it for a potential follow-up if such a case appears.
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.