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

Zoom out: don't allow dropping outside section root #61512

Merged
merged 1 commit into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really related but we can avoid attaching all the drop related event handlers.

] );

const innerBlocksProps = {
Expand Down
Loading