Skip to content

Commit

Permalink
Disallow dropping outside section root in Zoom Out mode (WordPress#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
2 people authored and bph committed Aug 31, 2024
1 parent f9fc112 commit 3e2b4a3
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 3e2b4a3

Please sign in to comment.