Skip to content

Commit

Permalink
Fix media placeholder to only activate for media objects. (#66986)
Browse files Browse the repository at this point in the history
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>
Co-authored-by: ndiego <ndiego@git.wordpress.org>
Co-authored-by: richtabor <richtabor@git.wordpress.org>
  • Loading branch information
7 people authored Nov 15, 2024
1 parent e7f0dc5 commit 2e4b8d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ const InserterDraggableBlocks = ( {
blocks,
};

const blocksContainMedia =
blocks.filter(
( block ) =>
( block.name === 'core/image' ||
block.name === 'core/audio' ||
block.name === 'core/video' ) &&
( block.attributes.url || block.attributes.src )
).length > 0;

const blockTypeIcon = useSelect(
( select ) => {
const { getBlockType } = select( blocksStore );
Expand Down Expand Up @@ -63,7 +72,7 @@ const InserterDraggableBlocks = ( {
? [ createBlock( 'core/block', { ref: pattern.id } ) ]
: blocks;
event.dataTransfer.setData(
'text/html',
blocksContainMedia ? 'default' : 'text/html',
serialize( parsedBlocks )
);
} }
Expand Down
10 changes: 5 additions & 5 deletions packages/block-editor/src/components/media-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ export function MediaPlaceholder( {
}
}

async function onHTMLDrop( HTML ) {
const blocks = pasteHandler( { HTML } );
async function onDrop( event ) {
const blocks = pasteHandler( {
HTML: event.dataTransfer?.getData( 'default' ),
} );
return await handleBlocksDrop( blocks );
}

Expand Down Expand Up @@ -379,9 +381,7 @@ export function MediaPlaceholder( {
return null;
}

return (
<DropZone onFilesDrop={ onFilesUpload } onHTMLDrop={ onHTMLDrop } />
);
return <DropZone onFilesDrop={ onFilesUpload } onDrop={ onDrop } />;
};

const renderCancelLink = () => {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/image.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ test.describe( 'Image', () => {
dummy.style.left = 0;
dummy.draggable = 'true';
dummy.addEventListener( 'dragstart', ( event ) => {
event.dataTransfer.setData( 'text/html', _html );
event.dataTransfer.setData( 'default', _html );
setTimeout( () => {
dummy.remove();
}, 0 );
Expand Down

0 comments on commit 2e4b8d8

Please sign in to comment.