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

Grid: Unset the rowStart and columnStart attributes when a block is removed from a manual layout #64186

Merged
merged 13 commits into from
Aug 6, 2024
Merged
Next Next commit
Unset the rowStart and columnStart attributes when a block is removed…
… from the grid
  • Loading branch information
talldan committed Aug 5, 2024
commit 2ad70dff7e4d48f04c275d1ca67c15bdba0cad24
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { usePrevious } from '@wordpress/compose';
import { store as blockEditorStore } from '../../store';
import { GridRect } from './utils';

const UNSET_GRID_ATTRIBUTES = {
style: { layout: { rowStart: undefined, columnStart: undefined } },
};

export function useGridLayoutSync( { clientId: gridClientId } ) {
const { gridLayout, blockOrder, selectedBlockLayout } = useSelect(
( select ) => {
Expand Down Expand Up @@ -40,6 +44,7 @@ export function useGridLayoutSync( { clientId: gridClientId } ) {
const previousIsManualPlacement = usePrevious(
gridLayout.isManualPlacement
);
const previousBlockOrder = usePrevious( blockOrder );

useEffect( () => {
const updates = {};
Expand Down Expand Up @@ -123,6 +128,14 @@ export function useGridLayoutSync( { clientId: gridClientId } ) {
},
};
}

// Unset the columnStart/rowStart attributes for blocks removed
// from the grid.
previousBlockOrder?.forEach( ( clientId ) => {
talldan marked this conversation as resolved.
Show resolved Hide resolved
if ( ! blockOrder.includes( clientId ) ) {
updates[ clientId ] = UNSET_GRID_ATTRIBUTES;
}
} );
} else {
// Remove all of the columnStart and rowStart values
// when switching from manual to auto mode,
Expand Down Expand Up @@ -166,6 +179,7 @@ export function useGridLayoutSync( { clientId: gridClientId } ) {
// Actual deps to sync:
gridClientId,
gridLayout,
previousBlockOrder,
blockOrder,
previouslySelectedBlockRect,
previousIsManualPlacement,
Expand Down