Skip to content

Commit

Permalink
Fix capturing toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jan 11, 2020
1 parent 327c04b commit 8f7eb28
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 54 deletions.

This file was deleted.

42 changes: 7 additions & 35 deletions packages/block-editor/src/components/block-list/block-popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { useViewportMatch } from '@wordpress/compose';
import BlockBreadcrumb from './breadcrumb';
import BlockContextualToolbar from './block-contextual-toolbar';
import Inserter from '../inserter';
import { ChildToolbar, ChildToolbarSlot } from './block-child-toolbar';

function selector( select ) {
const {
Expand All @@ -32,7 +31,6 @@ function selector( select ) {
getBlockRootClientId,
isBlockMultiSelected,
isAncestorMultiSelected,
hasSelectedInnerBlock,
getBlockParents,
getBlockListSettings,
__experimentalGetBlockListSettingsForBlocks,
Expand All @@ -43,12 +41,7 @@ function selector( select ) {
const clientId = getSelectedBlockClientId() || getFirstMultiSelectedBlockClientId();
const { name, attributes, isValid } = __unstableGetBlockWithoutInnerBlocks( clientId ) || {};

const checkDeep = true;

// "ancestor" is the more appropriate label due to "deep" check
const isAncestorOfSelectedBlock = hasSelectedInnerBlock( clientId, checkDeep );
const blockParentsClientIds = getBlockParents( clientId );
const currentBlockListSettings = getBlockListSettings( clientId );
const blockRootClientId = getBlockRootClientId( clientId );

const {
Expand All @@ -62,13 +55,11 @@ function selector( select ) {
// This will be the top most ancestor because getBlockParents() returns tree from top -> bottom
const topmostAncestorWithCaptureDescendantsToolbarsIndex = findIndex( ancestorBlockListSettings, [ '__experimentalCaptureToolbars', true ] );

// Boolean to indicate whether current Block has a parent with `captureDescendantsToolbars` set
const hasAncestorCapturingToolbars = topmostAncestorWithCaptureDescendantsToolbarsIndex !== -1 ? true : false;
let capturingBlockId = clientId;

// Is the *current* Block the one capturing all its descendant toolbars?
// If there is no `topmostAncestorWithCaptureDescendantsToolbarsIndex` then
// we're at the top of the tree
const isCapturingDescendantToolbars = isAncestorOfSelectedBlock && ( currentBlockListSettings && currentBlockListSettings.__experimentalCaptureToolbars ) && ! hasAncestorCapturingToolbars;
if ( topmostAncestorWithCaptureDescendantsToolbarsIndex !== -1 ) {
capturingBlockId = blockParentsClientIds[ topmostAncestorWithCaptureDescendantsToolbarsIndex ];
}

const { hasFixedToolbar } = getSettings();

Expand All @@ -83,11 +74,9 @@ function selector( select ) {
isEmptyDefaultBlock: name && isUnmodifiedDefaultBlock( { name, attributes } ),
rootClientId: getBlockRootClientId(),
isPartOfMultiSelection: isBlockMultiSelected( clientId ) || isAncestorMultiSelected( clientId ),
isCapturingDescendantToolbars,
hasAncestorCapturingToolbars,
hasFixedToolbar,
__experimentalMoverDirection,
blockNode: __unstableGetBlockNode( clientId ),
blockNode: __unstableGetBlockNode( capturingBlockId ),
};
}

Expand All @@ -103,8 +92,6 @@ function BlockPopover() {
isEmptyDefaultBlock,
rootClientId,
isPartOfMultiSelection,
isCapturingDescendantToolbars,
hasAncestorCapturingToolbars,
hasFixedToolbar,
__experimentalMoverDirection,
blockNode,
Expand Down Expand Up @@ -143,8 +130,7 @@ function BlockPopover() {
! shouldShowBreadcrumb &&
! shouldShowContextualToolbar &&
! isToolbarForced &&
! showEmptyBlockSideInserter &&
! isCapturingDescendantToolbars
! showEmptyBlockSideInserter
) {
return null;
}
Expand Down Expand Up @@ -196,21 +182,7 @@ function BlockPopover() {
__unstableAllowHorizontalSubpixelPosition={ __experimentalMoverDirection === 'horizontal' && blockNode }
onBlur={ () => setIsToolbarForced( false ) }
>
{ ! hasAncestorCapturingToolbars && ( shouldShowContextualToolbar || isToolbarForced ) && renderBlockContextualToolbar() }
{ ( 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.
<ChildToolbarSlot />
) }
{ hasAncestorCapturingToolbars && ( shouldShowContextualToolbar || isToolbarForced ) && (
// 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.
<ChildToolbar>
{ renderBlockContextualToolbar() }
</ChildToolbar>
) }
{ ( shouldShowContextualToolbar || isToolbarForced ) && renderBlockContextualToolbar() }
{ shouldShowBreadcrumb && (
<BlockBreadcrumb
clientId={ clientId }
Expand Down

0 comments on commit 8f7eb28

Please sign in to comment.