Skip to content

Commit

Permalink
hide block appender in exploded/navigation modes
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed May 27, 2022
1 parent 607a731 commit cc54d33
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions packages/block-editor/src/components/block-list-appender/index.js
Expand Up @@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { withSelect } from '@wordpress/data';
import { useSelect } from '@wordpress/data';
import { getDefaultBlockName } from '@wordpress/blocks';

/**
Expand All @@ -18,14 +18,38 @@ import { store as blockEditorStore } from '../../store';

function BlockListAppender( {
rootClientId,
canInsertDefaultBlock,
isLocked,
renderAppender: CustomAppender,
className,
selectedBlockClientId,
tagName: TagName = 'div',
} ) {
if ( isLocked || CustomAppender === false ) {
const {
hideInserter,
canInsertDefaultBlock,
selectedBlockClientId,
} = useSelect(
( select ) => {
const {
canInsertBlockType,
getTemplateLock,
getSelectedBlockClientId,
__unstableGetEditorMode,
} = select( blockEditorStore );

return {
hideInserter:
!! getTemplateLock( rootClientId ) ||
__unstableGetEditorMode() !== 'edit',
canInsertDefaultBlock: canInsertBlockType(
getDefaultBlockName(),
rootClientId
),
selectedBlockClientId: getSelectedBlockClientId(),
};
},
[ rootClientId ]
);

if ( hideInserter || CustomAppender === false ) {
return null;
}

Expand Down Expand Up @@ -92,19 +116,4 @@ function BlockListAppender( {
);
}

export default withSelect( ( select, { rootClientId } ) => {
const {
canInsertBlockType,
getTemplateLock,
getSelectedBlockClientId,
} = select( blockEditorStore );

return {
isLocked: !! getTemplateLock( rootClientId ),
canInsertDefaultBlock: canInsertBlockType(
getDefaultBlockName(),
rootClientId
),
selectedBlockClientId: getSelectedBlockClientId(),
};
} )( BlockListAppender );
export default BlockListAppender;

0 comments on commit cc54d33

Please sign in to comment.