Skip to content

Commit

Permalink
Disallow dropping outside section root in Zoom Out mode (#64500)
Browse files Browse the repository at this point in the history
* Conditionalise Zoom Out dragOver to account for section root

* Fix comment typo

Co-authored-by: Andrew Serong <[email protected]>

* Refactor to only call functions inside throttled callback

---------

Co-authored-by: Andrew Serong <[email protected]>
  • Loading branch information
getdave and andrewserong authored Aug 19, 2024
1 parent c1517ed commit 2862f2d
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions packages/block-editor/src/components/use-block-drop-zone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ export default function useBlockDropZone( {
getAllowedBlocks,
isDragging,
isGroupable,
getSettings,
isZoomOutMode,
} = unlock( useSelect( blockEditorStore ) );
const {
showInsertionPoint,
Expand Down Expand Up @@ -343,6 +345,7 @@ export default function useBlockDropZone( {
const targetBlockName = getBlockNamesByClientId( [
targetRootClientId,
] )[ 0 ];

const draggedBlockNames = getBlockNamesByClientId(
getDraggedBlockClientIds()
);
Expand All @@ -352,10 +355,23 @@ export default function useBlockDropZone( {
draggedBlockNames,
targetBlockName
);

if ( ! isBlockDroppingAllowed ) {
return;
}

const { sectionRootClientId } = unlock( getSettings() );

// In Zoom Out mode, if the target is not the section root provided by settings then
// do not allow dropping as the drop target is not within the root (that which is
// treated as "the content" by Zoom Out Mode).
if (
isZoomOutMode() &&
sectionRootClientId !== targetRootClientId
) {
return;
}

const blocks = getBlocks( targetRootClientId );

// The block list is empty, don't show the insertion point but still allow dropping.
Expand Down Expand Up @@ -470,6 +486,7 @@ export default function useBlockDropZone( {
} );
},
[
isDragging,
getAllowedBlocks,
targetRootClientId,
getBlockNamesByClientId,
Expand All @@ -481,13 +498,14 @@ export default function useBlockDropZone( {
parentBlockClientId,
getBlockIndex,
registry,
showInsertionPoint,
isDragging,
startDragging,
showInsertionPoint,
canInsertBlockType,
isGroupable,
getBlockVariations,
getGroupingBlockName,
isGroupable,
getSettings,
isZoomOutMode,
]
),
200
Expand Down

0 comments on commit 2862f2d

Please sign in to comment.