diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 7ded7911619439..311867738c12d0 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -32,6 +32,7 @@ import { import { Platform } from '@wordpress/element'; import { applyFilters } from '@wordpress/hooks'; import { symbol } from '@wordpress/icons'; +import { __ } from '@wordpress/i18n'; /** * A block selection object. @@ -1767,6 +1768,7 @@ export const getInserterItems = createSelector( */ export const getBlockTransformItems = createSelector( ( state, blocks, rootClientId = null ) => { + const [ sourceBlock ] = blocks; const buildBlockTypeTransformItem = buildBlockTypeItem( state, { buildScope: 'transform', } ); @@ -1780,20 +1782,32 @@ export const getBlockTransformItems = createSelector( blockTypeTransformItems, ( { name } ) => name ); + + // Consider unwraping the highest priority. + itemsByName[ '*' ] = { + frecency: +Infinity, + id: '*', + isDisabled: false, + name: '*', + title: __( 'Unwrap' ), + icon: itemsByName[ sourceBlock.name ]?.icon, + }; + const possibleTransforms = getPossibleBlockTransformations( blocks ).reduce( ( accumulator, block ) => { - if ( itemsByName[ block?.name ] ) { + if ( block === '*' ) { + accumulator.push( itemsByName[ '*' ] ); + } else if ( itemsByName[ block?.name ] ) { accumulator.push( itemsByName[ block.name ] ); } return accumulator; }, [] ); - const possibleBlockTransformations = orderBy( + return orderBy( possibleTransforms, ( block ) => itemsByName[ block.name ].frecency, 'desc' ); - return possibleBlockTransformations; }, ( state, rootClientId ) => [ state.blockListSettings[ rootClientId ], diff --git a/packages/block-library/src/quote/v2/transforms.js b/packages/block-library/src/quote/v2/transforms.js index da7e04c1d3b152..f5a6fbd4eb39a4 100644 --- a/packages/block-library/src/quote/v2/transforms.js +++ b/packages/block-library/src/quote/v2/transforms.js @@ -122,6 +122,19 @@ const transforms = { } ); }, }, + { + type: 'block', + blocks: [ '*' ], + transform: ( { attribution }, innerBlocks ) => + attribution + ? [ + ...innerBlocks, + createBlock( 'core/paragraph', { + content: attribution, + } ), + ] + : innerBlocks, + }, { type: 'block', blocks: [ 'core/group' ], diff --git a/packages/blocks/src/api/factory.js b/packages/blocks/src/api/factory.js index fbbfaaaf76f881..401c73715b1cf9 100644 --- a/packages/blocks/src/api/factory.js +++ b/packages/blocks/src/api/factory.js @@ -307,7 +307,9 @@ const getBlockTypesForPossibleToTransforms = ( blocks ) => { ); // Map block names to block types. - return blockNames.map( ( name ) => getBlockType( name ) ); + return blockNames.map( ( name ) => + name === '*' ? name : getBlockType( name ) + ); }; /** @@ -541,10 +543,9 @@ export function switchToBlockType( blocks, name ) { return null; } - const hasSwitchedBlock = some( - transformationResults, - ( result ) => result.name === name - ); + const hasSwitchedBlock = + name === '*' || + some( transformationResults, ( result ) => result.name === name ); // Ensure that at least one block object returned by the transformation has // the expected "destination" block type.