Skip to content

Commit

Permalink
Resize only to side that's not an edge
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed May 6, 2024
1 parent 4e66eae commit b140e88
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export function GridItemResizer( { clientId, onChange } ) {
} ),
};

const blockClientRect = blockElement.getBoundingClientRect();
const rootBlockClientRect = rootBlockElement.getBoundingClientRect();

/*
* The bounding element is equivalent to the root block element, but
* its bounding client rect is modified to account for the resizer
Expand All @@ -59,13 +62,11 @@ export function GridItemResizer( { clientId, onChange } ) {
offsetWidth: rootBlockElement.offsetWidth,
offsetHeight: rootBlockElement.offsetHeight,
getBoundingClientRect: () => {
const rootBlockClientRect =
rootBlockElement.getBoundingClientRect();
const resizerTop =
resizerDummyRef.current?.getBoundingClientRect()?.top;
// Fallback value of 60 to account for editor top bar height.
const heightDifference = resizerTop
? resizerTop - blockElement.getBoundingClientRect().top
? resizerTop - blockClientRect.top
: 60;
return {
bottom: rootBlockClientRect.bottom + heightDifference,
Expand All @@ -80,6 +81,15 @@ export function GridItemResizer( { clientId, onChange } ) {
},
};

/*
* Only enable resizing to a side if that side is not on the
* edge of the grid.
*/
const enableTop = blockClientRect.top > rootBlockClientRect.top;
const enableBottom = blockClientRect.bottom < rootBlockClientRect.bottom;
const enableLeft = blockClientRect.left > rootBlockClientRect.left;
const enableRight = blockClientRect.right < rootBlockClientRect.right;

return (
<BlockPopoverCover
className="block-editor-grid-item-resizer"
Expand All @@ -94,12 +104,12 @@ export function GridItemResizer( { clientId, onChange } ) {
height: '100%',
} }
enable={ {
bottom: true,
bottom: enableBottom,
bottomLeft: false,
bottomRight: false,
left: true,
right: true,
top: true,
left: enableLeft,
right: enableRight,
top: enableTop,
topLeft: false,
topRight: false,
} }
Expand Down

0 comments on commit b140e88

Please sign in to comment.