From 50fc9558812ab7675a60312ef682e3d257bab809 Mon Sep 17 00:00:00 2001 From: Ella van Durpe Date: Thu, 19 Dec 2019 14:56:07 +0100 Subject: [PATCH 01/10] Lighter block DOM: contextual toolbar in popover --- .../block-list/block-contextual-toolbar.js | 3 +- .../src/components/block-list/block.js | 52 +++--- .../src/components/block-list/breadcrumb.js | 4 +- .../src/components/block-list/style.scss | 68 ++++---- .../block-library/src/columns/editor.scss | 8 +- packages/components/src/popover/index.js | 12 +- packages/components/src/popover/utils.js | 154 +++++++++++++----- .../block-hierarchy-navigation.test.js | 8 +- .../various/keyboard-navigable-blocks.test.js | 3 +- .../edit-post/src/components/layout/index.js | 1 + 10 files changed, 207 insertions(+), 106 deletions(-) diff --git a/packages/block-editor/src/components/block-list/block-contextual-toolbar.js b/packages/block-editor/src/components/block-list/block-contextual-toolbar.js index ce9a1c8578084..a40c06b5f9fa4 100644 --- a/packages/block-editor/src/components/block-list/block-contextual-toolbar.js +++ b/packages/block-editor/src/components/block-list/block-contextual-toolbar.js @@ -9,13 +9,14 @@ import { __ } from '@wordpress/i18n'; import NavigableToolbar from '../navigable-toolbar'; import { BlockToolbar } from '../'; -function BlockContextualToolbar( { focusOnMount } ) { +function BlockContextualToolbar( { focusOnMount, ...props } ) { return ( diff --git a/packages/block-editor/src/components/block-list/block.js b/packages/block-editor/src/components/block-list/block.js index 294cb91e60b9e..ea64e0102a573 100644 --- a/packages/block-editor/src/components/block-list/block.js +++ b/packages/block-editor/src/components/block-list/block.js @@ -22,7 +22,7 @@ import { isUnmodifiedDefaultBlock, getUnregisteredTypeHandlerName, } from '@wordpress/blocks'; -import { KeyboardShortcuts, withFilters } from '@wordpress/components'; +import { KeyboardShortcuts, withFilters, Popover } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; import { withDispatch, @@ -522,6 +522,7 @@ function BlockListBlock( { // If the toolbar is being shown because of being forced // it should focus the toolbar right after the mount. focusOnMount={ isForcingContextualToolbar.current } + data-align={ wrapperProps ? wrapperProps[ 'data-align' ] : undefined } /> ); @@ -576,31 +577,44 @@ function BlockListBlock( { /> ) } { shouldRenderMovers && ( moverDirection === 'vertical' ) && blockMover } - { shouldShowBreadcrumb && ( - - ) } - { ( isCapturingDescendantToolbars ) && ( // A slot made available on all ancestors of the selected Block // to allow child Blocks to render their toolbars into the DOM // of the appropriate parent. ) } - - { ( ! ( hasAncestorCapturingToolbars ) ) && ( shouldShowContextualToolbar || isForcingContextualToolbar.current ) && renderBlockContextualToolbar() } - - { ( hasAncestorCapturingToolbars ) && ( shouldShowContextualToolbar || isForcingContextualToolbar.current ) && ( - // If the parent Block is set to consume toolbars of the child Blocks - // then render the child Block's toolbar into the Slot provided - // by the parent. - - { renderBlockContextualToolbar() } - + { ( shouldShowBreadcrumb || shouldShowContextualToolbar || isForcingContextualToolbar.current ) && ( + + { ! hasAncestorCapturingToolbars && ( shouldShowContextualToolbar || isForcingContextualToolbar.current ) && renderBlockContextualToolbar() } + { hasAncestorCapturingToolbars && ( shouldShowContextualToolbar || isForcingContextualToolbar.current ) && ( + // If the parent Block is set to consume toolbars of the child Blocks + // then render the child Block's toolbar into the Slot provided + // by the parent. + + { renderBlockContextualToolbar() } + + ) } + { shouldShowBreadcrumb && ( + + ) } + ) } - { ! isNavigationMode && ! shouldShowContextualToolbar && diff --git a/packages/block-editor/src/components/block-list/breadcrumb.js b/packages/block-editor/src/components/block-list/breadcrumb.js index 5d8d4517472cc..89c8f0e0c4c91 100644 --- a/packages/block-editor/src/components/block-list/breadcrumb.js +++ b/packages/block-editor/src/components/block-list/breadcrumb.js @@ -18,11 +18,11 @@ import BlockTitle from '../block-title'; * @param {string} props.clientId Client ID of block. * @return {WPComponent} The component to be rendered. */ -const BlockBreadcrumb = forwardRef( ( { clientId }, ref ) => { +const BlockBreadcrumb = forwardRef( ( { clientId, ...props }, ref ) => { const { setNavigationMode } = useDispatch( 'core/block-editor' ); return ( -
+