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

WP-70 Fix Unequal length row/column merge and conflict with thead/tfoot #11

Merged
merged 3 commits into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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