Skip to content

Commit

Permalink
Check using possible block transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jul 1, 2021
1 parent 17eb15f commit d2bbbfb
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export default function Image( {
} ) {
const captionRef = useRef();
const prevUrl = usePrevious( url );
const { getBlock } = useSelect( blockEditorStore );
const { image, multiImageSelection } = useSelect(
( select ) => {
const { getMedia } = select( coreStore );
Expand All @@ -109,19 +108,26 @@ export default function Image( {
);
const {
canInsertCover,
getBlock,
imageEditing,
imageSizes,
maxWidth,
mediaUpload,
} = useSelect(
( select ) => {
const {
canInsertBlockType,
getBlock: _getBlock,
getBlockRootClientId,
getBlockTransformItems,
getSettings,
} = select( blockEditorStore );

const block = _getBlock( clientId );
const rootClientId = getBlockRootClientId( clientId );
const transformations = getBlockTransformItems(
[ block ],
rootClientId
);
const settings = pick( getSettings(), [
'imageEditing',
'imageSizes',
Expand All @@ -131,10 +137,12 @@ export default function Image( {

return {
...settings,
canInsertCover: canInsertBlockType(
'core/cover',
rootClientId
),
getBlock: _getBlock,
canInsertCover:
transformations?.length &&
!! transformations.find(
( { name } ) => name === 'core/cover'
),
};
},
[ clientId ]
Expand Down

0 comments on commit d2bbbfb

Please sign in to comment.