diff --git a/packages/block-editor/src/components/block-list/insertion-point.js b/packages/block-editor/src/components/block-list/insertion-point.js index 6b7145ebb78e20..a2657f747363c7 100644 --- a/packages/block-editor/src/components/block-list/insertion-point.js +++ b/packages/block-editor/src/components/block-list/insertion-point.js @@ -273,6 +273,7 @@ export default function useInsertionPoint( ref ) { selectedClientId, selectedRootClientId, getBlockListSettings, + isPopoverHidden, } = useSelect( ( select ) => { const { isMultiSelecting: _isMultiSelecting, @@ -280,6 +281,7 @@ export default function useInsertionPoint( ref ) { getBlockInsertionPoint, getBlockOrder, getBlockListSettings: _getBlockListSettings, + isInsertionPointPopoverHidden, } = select( blockEditorStore ); const insertionPoint = getBlockInsertionPoint(); @@ -291,6 +293,7 @@ export default function useInsertionPoint( ref ) { isInserterVisible: isBlockInsertionPointVisible(), selectedClientId: order[ insertionPoint.index - 1 ], selectedRootClientId: insertionPoint.rootClientId, + isPopoverHidden: isInsertionPointPopoverHidden(), }; }, [] ); @@ -399,7 +402,8 @@ export default function useInsertionPoint( ref ) { return ( ! isMultiSelecting && - isVisible && ( + isVisible && + ! isPopoverHidden && ( { const { getEditedEntityRecord, hasFinishedResolution } = select( coreStore ); - const { getBlocks } = select( blockEditorStore ); + const { + getBlocks, + isBlockSelected, + hasSelectedInnerBlock, + } = select( blockEditorStore ); const getEntityArgs = [ 'postType', @@ -69,6 +73,9 @@ export default function TemplatePartEdit( { isResolved: hasResolvedEntity, isMissing: hasResolvedEntity && ! entityRecord, area: entityRecord?.area, + isSelected: + isBlockSelected( clientId ) || + hasSelectedInnerBlock( clientId, true ), }; }, [ templatePartId, clientId ] @@ -157,6 +164,7 @@ export default function TemplatePartEdit( { ) } { isEntityAvailable && ( { const { getSettings } = select( blockEditorStore ); @@ -46,5 +48,27 @@ export default function TemplatePartInnerBlocks( { alignments: themeSupportsLayout ? alignments : undefined, }, } ); - return ; + + const [ isHovered, setIsHovered ] = useState( false ); + const { + hideInsertionPointPopover, + showInsertionPointPopover, + } = useDispatch( blockEditorStore ); + + useEffect( () => { + if ( isHovered && ! isSelected ) { + hideInsertionPointPopover(); + } else { + showInsertionPointPopover(); + } + }, [ isSelected, isHovered ] ); + + return ( +
setIsHovered( true ) } + onMouseLeave={ () => setIsHovered( false ) } + > + +
+ ); } diff --git a/packages/block-library/src/template-part/editor.scss b/packages/block-library/src/template-part/editor.scss index c61e0651ae7251..62492385df7be2 100644 --- a/packages/block-library/src/template-part/editor.scss +++ b/packages/block-library/src/template-part/editor.scss @@ -76,4 +76,19 @@ } } } + + &:not(.has-child-selected):not(.is-selected):not(.is-placeholder) { + * { + pointer-events: none; + user-select: none; // Stops text being inadvertently highlighted when selecting a template part + } + } + + &.is-selected:not(.is-placeholder) { + background: rgba(#007cba, 0.1); // todo: use var + } + + &.is-hovered:not(.is-selected) { + background: rgba($gray-900, 0.05); + } }