Skip to content

Commit

Permalink
Do nothing when the new parent is a grid, it seems to work better by …
Browse files Browse the repository at this point in the history
…leaving all attributes in place
  • Loading branch information
talldan committed Aug 5, 2024
1 parent 795a12b commit 8cf4899
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions packages/block-editor/src/components/grid/use-grid-layout-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,21 @@ export function useGridLayoutSync( { clientId: gridClientId } ) {
return;
}

// Check if the block is being moved to another grid.
// If so, do nothing and let the new grid parent handle
// the attributes.
const rootAttributes = getBlockAttributes( rootClientId );
const newLayoutIsGrid =
rootAttributes?.layout?.type === 'grid';
if ( rootAttributes?.layout?.type === 'grid' ) {
return;
}

const attributes = getBlockAttributes( clientId );
// If the block is moving from one grid layout to another,
// keep the span attributes for use in the target grid.
const attributesToUnset = newLayoutIsGrid
? [
[ 'style', 'layout', 'columnStart' ],
[ 'style', 'layout', 'rowStart' ],
]
: [
[ 'style', 'layout', 'columnStart' ],
[ 'style', 'layout', 'rowStart' ],
[ 'style', 'layout', 'columnSpan' ],
[ 'style', 'layout', 'rowSpan' ],
];
const attributesToUnset = [
[ 'style', 'layout', 'columnStart' ],
[ 'style', 'layout', 'rowStart' ],
[ 'style', 'layout', 'columnSpan' ],
[ 'style', 'layout', 'rowSpan' ],
];
const updatedAttributes = attributesToUnset.reduce(
( attrs, path ) =>
setImmutably( attrs, path, undefined ),
Expand Down

0 comments on commit 8cf4899

Please sign in to comment.