Skip to content

Commit

Permalink
Restore Unquote button
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 26, 2023
1 parent d81637e commit 8d9a173
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { __ } from '@wordpress/i18n';
import { MenuGroup, MenuItem } from '@wordpress/components';
import {
getBlockMenuDefaultClassName,
getBlockType,
switchToBlockType,
} from '@wordpress/blocks';
import { useState, useMemo } from '@wordpress/element';
Expand All @@ -15,6 +16,7 @@ import { useState, useMemo } from '@wordpress/element';
import BlockIcon from '../block-icon';
import PreviewBlockPopover from './preview-block-popover';
import BlockVariationTransformations from './block-variation-transformations';
import { useConvertToGroupButtonProps } from '../convert-to-group-buttons';

/**
* Helper hook to group transformations to display them in a specific order in the UI.
Expand Down Expand Up @@ -76,6 +78,8 @@ const BlockTransformationsMenu = ( {

const { priorityTextTransformations, restTransformations } =
useGroupedTransforms( possibleBlockTransformations );
const selectedClientIds = blocks.map( ( { clientId } ) => clientId );
const { onUngroup } = useConvertToGroupButtonProps( selectedClientIds );
// We have to check if both content transformations(priority and rest) are set
// in order to create a separate MenuGroup for them.
const hasBothContentTransformations =
Expand All @@ -87,8 +91,24 @@ const BlockTransformationsMenu = ( {
setHoveredTransformItemName={ setHoveredTransformItemName }
/>
);
const [ firstSelectedBlock ] = blocks;
const { name: firstSelectedBlockName } = firstSelectedBlock;
const { name, icon } = getBlockType( firstSelectedBlockName );
return (
<>
{ onUngroup && (
<MenuGroup className={ className }>
<MenuItem
className={ getBlockMenuDefaultClassName( name ) }
onClick={ () => {
onUngroup();
} }
>
<BlockIcon icon={ icon } showColors />
{ onUngroup.__experimentalLabel || __( 'Ungroup' ) }
</MenuItem>
</MenuGroup>
) }
<MenuGroup label={ __( 'Transform to' ) } className={ className }>
{ hoveredTransformItemName && (
<PreviewBlockPopover
Expand Down
24 changes: 15 additions & 9 deletions packages/block-library/src/quote/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
* WordPress dependencies
*/
import { createBlock } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';

function ungroup( { citation }, innerBlocks ) {
return citation
? [
...innerBlocks,
createBlock( 'core/paragraph', {
content: citation,
} ),
]
: innerBlocks;
}

ungroup.__experimentalLabel = __( 'Unquote' );

const transforms = {
from: [
Expand Down Expand Up @@ -127,15 +141,7 @@ const transforms = {
),
},
],
ungroup: ( { citation }, innerBlocks ) =>
citation
? [
...innerBlocks,
createBlock( 'core/paragraph', {
content: citation,
} ),
]
: innerBlocks,
ungroup,
};

export default transforms;

0 comments on commit 8d9a173

Please sign in to comment.