Skip to content

Commit

Permalink
Merge pull request #11 from Travelopia/WP-70/fix-merging
Browse files Browse the repository at this point in the history
WP-70 Fix Unequal length row/column merge and conflict with thead/tfoot
  • Loading branch information
junaidbhura authored May 2, 2024
2 parents 03656e6 + fe5e091 commit 06e9605
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/blocks/table-column/toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );

Expand Down

0 comments on commit 06e9605

Please sign in to comment.