From d8c76a7b4060d4cae86d19fe047ceb45a1f7b776 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Thu, 12 Aug 2021 16:48:42 +0200 Subject: [PATCH] Expose conditionally general duotone and align block controls --- .../src/components/block-controls/hook.js | 12 +++++- .../src/components/block-toolbar/index.js | 14 +++---- .../src/components/inner-blocks/index.js | 39 +++++++++++++------ packages/block-editor/src/hooks/align.js | 26 +++++++------ packages/block-editor/src/hooks/duotone.js | 2 +- packages/block-library/src/buttons/block.json | 3 +- packages/block-library/src/buttons/edit.js | 1 - .../block-library/src/social-links/block.json | 3 +- .../block-library/src/social-links/edit.js | 1 - 9 files changed, 63 insertions(+), 38 deletions(-) diff --git a/packages/block-editor/src/components/block-controls/hook.js b/packages/block-editor/src/components/block-controls/hook.js index c71b711df1671c..0d8f20bfd1428a 100644 --- a/packages/block-editor/src/components/block-controls/hook.js +++ b/packages/block-editor/src/components/block-controls/hook.js @@ -1,6 +1,7 @@ /** * WordPress dependencies */ +import { store as blocksStore } from '@wordpress/blocks'; import { useSelect } from '@wordpress/data'; /** @@ -16,9 +17,18 @@ export default function useBlockControlsFill( group, exposeToChildren ) { const { clientId } = useBlockEditContext(); const isParentDisplayed = useSelect( ( select ) => { + const { getBlockName, hasSelectedInnerBlock } = select( + blockEditorStore + ); + const { hasBlockSupport } = select( blocksStore ); return ( exposeToChildren && - select( blockEditorStore ).hasSelectedInnerBlock( clientId ) + hasBlockSupport( + getBlockName( clientId ), + '__experimentalCaptureToolbars', + false + ) && + hasSelectedInnerBlock( clientId ) ); }, [ exposeToChildren, clientId ] diff --git a/packages/block-editor/src/components/block-toolbar/index.js b/packages/block-editor/src/components/block-toolbar/index.js index 7a18e4430fbb60..def5b425760d10 100644 --- a/packages/block-editor/src/components/block-toolbar/index.js +++ b/packages/block-editor/src/components/block-toolbar/index.js @@ -108,15 +108,7 @@ export default function BlockToolbar( { hideDragHandle } ) { return (
{ ! isMultiToolbar && ! displayHeaderToolbar && ( - <> - - { shouldShowVisualToolbar && ( - - ) } - + ) }
{ ( shouldShowVisualToolbar || isMultiToolbar ) && ( @@ -131,6 +123,10 @@ export default function BlockToolbar( { hideDragHandle } ) {
{ shouldShowVisualToolbar && ( <> + { export function useInnerBlocksProps( props = {}, options = {} ) { const { clientId } = useBlockEditContext(); const isSmallScreen = useViewportMatch( 'medium', '<' ); - const hasOverlay = useSelect( + const { __experimentalCaptureToolbars, hasOverlay } = useSelect( ( select ) => { const { getBlockName, @@ -145,13 +149,22 @@ export function useInnerBlocksProps( props = {}, options = {} ) { hasSelectedInnerBlock, isNavigationMode, } = select( blockEditorStore ); + const blockName = getBlockName( clientId ); const enableClickThrough = isNavigationMode() || isSmallScreen; - return ( - getBlockName( clientId ) !== 'core/template' && - ! isBlockSelected( clientId ) && - ! hasSelectedInnerBlock( clientId, true ) && - enableClickThrough - ); + return { + __experimentalCaptureToolbars: select( + blocksStore + ).hasBlockSupport( + blockName, + '__experimentalCaptureToolbars', + false + ), + hasOverlay: + blockName !== 'core/template' && + ! isBlockSelected( clientId ) && + ! hasSelectedInnerBlock( clientId, true ) && + enableClickThrough, + }; }, [ clientId, isSmallScreen ] ); @@ -162,11 +175,15 @@ export function useInnerBlocksProps( props = {}, options = {} ) { rootClientId: clientId, } ), ] ); + const innerBlocksProps = { + __experimentalCaptureToolbars, + ...options, + }; + const InnerBlocks = - options.value && options.onChange + innerBlocksProps.value && innerBlocksProps.onChange ? ControlledInnerBlocks : UncontrolledInnerBlocks; - return { ...props, ref, @@ -177,7 +194,7 @@ export function useInnerBlocksProps( props = {}, options = {} ) { 'has-overlay': hasOverlay, } ), - children: , + children: , }; } diff --git a/packages/block-editor/src/hooks/align.js b/packages/block-editor/src/hooks/align.js index 7cfd5f8b13fdef..b1e68b68bfe260 100644 --- a/packages/block-editor/src/hooks/align.js +++ b/packages/block-editor/src/hooks/align.js @@ -140,18 +140,20 @@ export const withToolbarControls = createHigherOrderComponent( props.setAttributes( { align: nextAlign } ); }; - return [ - validAlignments.length > 0 && props.isSelected && ( - - - - ), - , - ]; + return ( + <> + { validAlignments.length > 0 && ( + + + + ) } + + + ); }, 'withToolbarControls' ); diff --git a/packages/block-editor/src/hooks/duotone.js b/packages/block-editor/src/hooks/duotone.js index 46748fb04f3e6c..aa38c298ff228a 100644 --- a/packages/block-editor/src/hooks/duotone.js +++ b/packages/block-editor/src/hooks/duotone.js @@ -140,7 +140,7 @@ function DuotonePanel( { attributes, setAttributes } ) { } return ( - +