Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom out: restore trash button #66288

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
46 changes: 31 additions & 15 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import clsx from 'clsx';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { useRef } from '@wordpress/element';
import { useViewportMatch } from '@wordpress/compose';
import {
Expand All @@ -17,6 +17,7 @@ import {
isTemplatePart,
} from '@wordpress/blocks';
import { ToolbarGroup, ToolbarButton } from '@wordpress/components';
import { trash } from '@wordpress/icons';

/**
* Internal dependencies
Expand Down Expand Up @@ -48,13 +49,15 @@ import { unlock } from '../../lock-unlock';
* @param {boolean} props.focusOnMount Focus the toolbar when mounted.
* @param {number} props.__experimentalInitialIndex The initial index of the toolbar item to focus.
* @param {Function} props.__experimentalOnIndexChange Callback function to be called when the index of the focused toolbar item changes.
* @param {Object} props.__unstableContentRef Ref object for the content area.
* @param {string} props.variant Style variant of the toolbar, also passed to the Dropdowns rendered from Block Toolbar Buttons.
*/
export function PrivateBlockToolbar( {
hideDragHandle,
focusOnMount,
__experimentalInitialIndex,
__experimentalOnIndexChange,
__unstableContentRef,
variant = 'unstyled',
} ) {
const {
Expand All @@ -68,10 +71,8 @@ export function PrivateBlockToolbar( {
isUsingBindings,
hasParentPattern,
hasContentOnlyLocking,
showShuffleButton,
showSlots,
showGroupButtons,
showLockButtons,
isZoomOutMode,
canRemove,
} = useSelect( ( select ) => {
const {
getBlockName,
Expand All @@ -85,6 +86,7 @@ export function PrivateBlockToolbar( {
getTemplateLock,
getParentSectionBlock,
isZoomOut,
canRemoveBlock,
} = unlock( select( blockEditorStore ) );
const selectedBlockClientIds = getSelectedBlockClientIds();
const selectedBlockClientId = selectedBlockClientIds[ 0 ];
Expand Down Expand Up @@ -117,6 +119,7 @@ export function PrivateBlockToolbar( {
const _hasTemplateLock = selectedBlockClientIds.some(
( id ) => getTemplateLock( id ) === 'contentOnly'
);
const _isZoomOut = isZoomOut();
return {
blockClientId: selectedBlockClientId,
blockClientIds: selectedBlockClientIds,
Expand All @@ -125,7 +128,7 @@ export function PrivateBlockToolbar( {
shouldShowVisualToolbar: isValid && isVisual,
toolbarKey: `${ selectedBlockClientId }${ parentClientId }`,
showParentSelector:
! isZoomOut() &&
! _isZoomOut &&
parentBlockType &&
getBlockEditingMode( parentClientId ) !== 'disabled' &&
hasBlockSupport(
Expand All @@ -137,12 +140,11 @@ export function PrivateBlockToolbar( {
isUsingBindings: _isUsingBindings,
hasParentPattern: _hasParentPattern,
hasContentOnlyLocking: _hasTemplateLock,
showShuffleButton: isZoomOut(),
showSlots: ! isZoomOut(),
showGroupButtons: ! isZoomOut(),
showLockButtons: ! isZoomOut(),
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
isZoomOutMode: _isZoomOut,
canRemove: canRemoveBlock( selectedBlockClientId ),
};
}, [] );
const { removeBlock } = useDispatch( blockEditorStore );

const toolbarWrapperRef = useRef( null );

Expand Down Expand Up @@ -203,7 +205,7 @@ export function PrivateBlockToolbar( {
<BlockSwitcher clientIds={ blockClientIds } />
{ ! isMultiToolbar &&
isDefaultEditingMode &&
showLockButtons && (
! isZoomOutMode && (
<BlockLockToolbar
clientId={ blockClientId }
/>
Expand All @@ -218,16 +220,28 @@ export function PrivateBlockToolbar( {
{ ! hasContentOnlyLocking &&
shouldShowVisualToolbar &&
isMultiToolbar &&
showGroupButtons && <BlockGroupToolbar /> }
{ showShuffleButton && (
! isZoomOutMode && <BlockGroupToolbar /> }
{ isZoomOutMode && (
<ToolbarGroup>
<Shuffle
clientId={ blockClientIds[ 0 ] }
as={ ToolbarButton }
/>
</ToolbarGroup>
) }
{ shouldShowVisualToolbar && showSlots && (
{ isZoomOutMode &&
canRemove &&
! isTemplatePart( blockType ) && (
<ToolbarButton
icon={ trash }
label={ __( 'Delete' ) }
onClick={ () => {
removeBlock( blockClientId );
__unstableContentRef.current?.focus();
} }
/>
) }
{ shouldShowVisualToolbar && ! isZoomOutMode && (
<>
<BlockControls.Slot
group="parent"
Expand All @@ -254,7 +268,9 @@ export function PrivateBlockToolbar( {
</>
) }
<BlockEditVisuallyButton clientIds={ blockClientIds } />
<BlockSettingsMenu clientIds={ blockClientIds } />
{ ! isZoomOutMode && (
<BlockSettingsMenu clientIds={ blockClientIds } />
) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I wonder if we should instead keep the blockSettingsMenu and try to figure why the default "trash" button is not visible there instead of forking the experience in zoom-out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default delete button is there:
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably that all the other buttons should be removed, so that Delete is the only thing left, is which case the more toggle shouldn't be there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we want to remove "duplicate" for instance?

Also, if we want to remove the dropdown if there's only one button, should this behavior be built-in into the toolbar or specific to zoom-out?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I don't mind the current PR but I would like us to remove from special cases and if conditions as much as possible.

</div>
</NavigableToolbar>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default function BlockToolbarPopover( {
__experimentalOnIndexChange={ ( index ) => {
initialToolbarItemIndexRef.current = index;
} }
__unstableContentRef={ __unstableContentRef }
variant="toolbar"
/>
</BlockPopover>
Expand Down
Loading