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

Fix media placeholder to only activate for media objects. #66986

Merged
merged 4 commits into from
Nov 15, 2024
Merged
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
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' ) &&
ramonjd marked this conversation as resolved.
Show resolved Hide resolved
( 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
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
Loading