diff --git a/src/blocks/table-column/toolbar.tsx b/src/blocks/table-column/toolbar.tsx index 3caaa4a..84c3c7c 100644 --- a/src/blocks/table-column/toolbar.tsx +++ b/src/blocks/table-column/toolbar.tsx @@ -307,6 +307,12 @@ export default function Toolbar( { return false; } + // Avoid merging thead/tfoot column with tbody column. + const currentRowContainerBlockAttributes = getBlockAttributes( currentRowContainerBlock.clientId ); + if ( currentRowContainerBlockAttributes?.type !== rowContainerBlock?.attributes?.type ) { + return false; + } + return currentRowContainerBlock.innerBlocks.some( ( rowBlock, index ): boolean => { // Get current row. const rowNumber: number = index + 1; @@ -369,6 +375,12 @@ export default function Toolbar( { return false; } + // Avoid merging thead/tfoot column with tbody column. + const currentRowContainerBlockAttributes = getBlockAttributes( currentRowContainerBlock.clientId ); + if ( currentRowContainerBlockAttributes?.type !== rowContainerBlock?.attributes?.type ) { + return false; + } + return currentRowContainerBlock.innerBlocks.some( ( rowBlock, index ): boolean => { // Get current row. const rowNumber: number = index + 1; @@ -435,6 +447,12 @@ export default function Toolbar( { return false; } + // Avoid merging thead/tfoot row with tbody row. + const currentRowContainerBlockAttributes = getBlockAttributes( currentRowContainerBlock.clientId ); + if ( currentRowContainerBlockAttributes?.type !== rowContainerBlock?.attributes?.type ) { + return false; + } + return currentRowContainerBlock.innerBlocks.some( ( rowBlock, rowIndex ): boolean => { // Get current row. const rowNumber: number = rowIndex + 1; @@ -497,6 +515,12 @@ export default function Toolbar( { return false; } + // Avoid merging thead/tfoot row with tbody row. + const currentRowContainerBlockAttributes = getBlockAttributes( currentRowContainerBlock.clientId ); + if ( currentRowContainerBlockAttributes?.type !== rowContainerBlock?.attributes?.type ) { + return false; + } + return currentRowContainerBlock.innerBlocks.some( ( rowBlock, rowIndex ): boolean => { // Get current row. const rowNumber: number = rowIndex + 1; @@ -547,6 +571,16 @@ export default function Toolbar( { // Get colspans. const mergeIntoAttributes = getBlockAttributes( toColumn.clientId ); const mergeFromAttributes = getBlockAttributes( fromColumn.clientId ); + + // Get rowspans. + const mergeIntoRowspan: number = parseInt( mergeIntoAttributes?.rowSpan ?? 1 ); + const mergeFromRowspan: number = parseInt( mergeFromAttributes?.rowSpan ?? 1 ); + + // Invalid merge. + if ( mergeIntoRowspan !== mergeFromRowspan ) { + return; + } + const mergeIntoColspan: number = parseInt( mergeIntoAttributes?.colSpan ?? 1 ); const mergeFromColspan: number = parseInt( mergeFromAttributes?.colSpan ?? 1 ); @@ -574,6 +608,16 @@ export default function Toolbar( { // Get rowspans. const mergeIntoAttributes = getBlockAttributes( toColumn.clientId ); const mergeFromAttributes = getBlockAttributes( fromColumn.clientId ); + + // Get colspans. + const mergeIntoColspan: number = parseInt( mergeIntoAttributes?.colSpan ?? 1 ); + const mergeFromColspan: number = parseInt( mergeFromAttributes?.colSpan ?? 1 ); + + // Invalid merge. + if ( mergeIntoColspan !== mergeFromColspan ) { + return; + } + const mergeIntoRowspan: number = parseInt( mergeIntoAttributes?.rowSpan ?? 1 ); const mergeFromRowspan: number = parseInt( mergeFromAttributes?.rowSpan ?? 1 );