Skip to content

Commit

Permalink
Zoom out: don't allow dropping outside section root
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 9, 2024
1 parent d6a5e87 commit 66f7291
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions packages/block-editor/src/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ export function useInnerBlocksProps( props = {}, options = {} ) {
} = useBlockEditContext();
const selected = useSelect(
( select ) => {
if ( ! clientId ) {
return {};
}

const {
getBlockName,
isBlockSelected,
Expand All @@ -205,8 +201,19 @@ export function useInnerBlocksProps( props = {}, options = {} ) {
getBlockSettings,
isDragging,
getSettings,
getBlockOrder,
} = unlock( select( blockEditorStore ) );
let _isDropZoneDisabled;
// In zoom out mode, we want to disable the drop zone for the sections.
// The inner blocks belonging to the section drop zone is
// already disabled by the blocks themselves being disabled.
if ( __unstableGetEditorMode() === 'zoom-out' ) {
const { sectionRootClientId } = unlock( getSettings() );
_isDropZoneDisabled = clientId !== sectionRootClientId;
}
if ( ! clientId ) {
return { isDropZoneDisabled: _isDropZoneDisabled };
}

const { hasBlockSupport, getBlockType } = select( blocksStore );
const blockName = getBlockName( clientId );
const enableClickThrough =
Expand All @@ -215,14 +222,8 @@ export function useInnerBlocksProps( props = {}, options = {} ) {
const parentClientId = getBlockRootClientId( clientId );
const [ defaultLayout ] = getBlockSettings( clientId, 'layout' );

// In zoom out mode, we want to disable the drop zone for the sections.
// The inner blocks belonging to the section drop zone is
// already disabled by the blocks themselves being disabled.
let _isDropZoneDisabled = blockEditingMode === 'disabled';
if ( __unstableGetEditorMode() === 'zoom-out' ) {
const { sectionRootClientId } = unlock( getSettings() );
const sectionsClientIds = getBlockOrder( sectionRootClientId );
_isDropZoneDisabled = sectionsClientIds?.includes( clientId );
if ( _isDropZoneDisabled !== undefined ) {
_isDropZoneDisabled = blockEditingMode === 'disabled';
}

return {
Expand Down Expand Up @@ -262,12 +263,13 @@ export function useInnerBlocksProps( props = {}, options = {} ) {
dropZoneElement,
rootClientId: clientId,
parentClientId,
isDisabled: isDropZoneDisabled,
} );

const ref = useMergeRefs( [
props.ref,
__unstableDisableDropZone ? null : blockDropZoneRef,
__unstableDisableDropZone || isDropZoneDisabled
? null
: blockDropZoneRef,
] );

const innerBlocksProps = {
Expand Down

0 comments on commit 66f7291

Please sign in to comment.