Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 49 additions & 31 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { useHasBlockToolbar } from './use-has-block-toolbar';
import ChangeDesign from './change-design';
import SwitchSectionStyle from './switch-section-style';
import { unlock } from '../../lock-unlock';
import { deviceTypeKey } from '../../store/private-keys';
import BlockToolbarIcon from './block-toolbar-icon';

/**
Expand Down Expand Up @@ -75,6 +76,7 @@ export function PrivateBlockToolbar( {
showLockButtons,
showBlockVisibilityButton,
showSwitchSectionStyleButton,
areSelectedBlocksHiddenOnViewport,
} = useSelect( ( select ) => {
const {
getBlockName,
Expand All @@ -84,10 +86,12 @@ export function PrivateBlockToolbar( {
isBlockValid,
getBlockEditingMode,
getBlockAttributes,
getSettings,
getTemplateLock,
getParentSectionBlock,
isZoomOut,
isSectionBlock,
isBlockHiddenAtViewport,
} = unlock( select( blockEditorStore ) );
const selectedBlockClientIds = getSelectedBlockClientIds();
const selectedBlockClientId = selectedBlockClientIds[ 0 ];
Expand Down Expand Up @@ -119,6 +123,14 @@ export function PrivateBlockToolbar( {
const _isSectionBlock = isSectionBlock( selectedBlockClientId );
const _showSwitchSectionStyleButton = _isZoomOut || _isSectionBlock;

const _currentDeviceType =
getSettings()?.[ deviceTypeKey ]?.toLowerCase() || 'desktop';
const _areSelectedBlocksHiddenOnViewport =
selectedBlockClientIds.length > 0 &&
selectedBlockClientIds.every( ( id ) =>
isBlockHiddenAtViewport( id, _currentDeviceType )
);

return {
blockClientId: selectedBlockClientId,
blockClientIds: selectedBlockClientIds,
Expand Down Expand Up @@ -146,6 +158,8 @@ export function PrivateBlockToolbar( {
showLockButtons: ! _isZoomOut,
showBlockVisibilityButton: ! _isZoomOut,
showSwitchSectionStyleButton: _showSwitchSectionStyleButton,
areSelectedBlocksHiddenOnViewport:
_areSelectedBlocksHiddenOnViewport,
};
}, [] );

Expand Down Expand Up @@ -225,42 +239,46 @@ export function PrivateBlockToolbar( {
</ToolbarGroup>
</div>
) }
{ ! hasContentOnlyLocking &&
{ ! areSelectedBlocksHiddenOnViewport &&
! hasContentOnlyLocking &&
shouldShowVisualToolbar &&
isMultiToolbar &&
showGroupButtons && <BlockGroupToolbar /> }
{ showShuffleButton && (
{ ! areSelectedBlocksHiddenOnViewport && showShuffleButton && (
<ChangeDesign clientId={ blockClientIds[ 0 ] } />
) }
{ showSwitchSectionStyleButton && (
<SwitchSectionStyle clientId={ blockClientIds[ 0 ] } />
) }
{ shouldShowVisualToolbar && showSlots && (
<>
{ ! isSectionContainer && (
<>
<BlockControls.Slot
group="parent"
className="block-editor-block-toolbar__slot"
/>
<BlockControls.Slot
group="block"
className="block-editor-block-toolbar__slot"
/>
<BlockControls.Slot className="block-editor-block-toolbar__slot" />
<BlockControls.Slot
group="inline"
className="block-editor-block-toolbar__slot"
/>
</>
) }
<BlockControls.Slot
group="other"
className="block-editor-block-toolbar__slot"
/>
<__unstableBlockToolbarLastItem.Slot />
</>
) }
{ ! areSelectedBlocksHiddenOnViewport &&
showSwitchSectionStyleButton && (
<SwitchSectionStyle clientId={ blockClientIds[ 0 ] } />
) }
{ ! areSelectedBlocksHiddenOnViewport &&
shouldShowVisualToolbar &&
showSlots && (
<>
{ ! isSectionContainer && (
<>
<BlockControls.Slot
group="parent"
className="block-editor-block-toolbar__slot"
/>
<BlockControls.Slot
group="block"
className="block-editor-block-toolbar__slot"
/>
<BlockControls.Slot className="block-editor-block-toolbar__slot" />
<BlockControls.Slot
group="inline"
className="block-editor-block-toolbar__slot"
/>
</>
) }
<BlockControls.Slot
group="other"
className="block-editor-block-toolbar__slot"
/>
<__unstableBlockToolbarLastItem.Slot />
</>
) }
<BlockEditVisuallyButton clientIds={ blockClientIds } />
<BlockSettingsMenu clientIds={ blockClientIds } />
</div>
Expand Down
Loading