Skip to content

Commit 2e4b8d8

Browse files
tellthemachinesramonjdtalldangetdavendiego
authored
Fix media placeholder to only activate for media objects. (#66986)
Co-authored-by: tellthemachines <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: talldan <[email protected]> Co-authored-by: getdave <[email protected]> Co-authored-by: ndiego <[email protected]> Co-authored-by: richtabor <[email protected]>
1 parent e7f0dc5 commit 2e4b8d8

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

packages/block-editor/src/components/inserter-draggable-blocks/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ const InserterDraggableBlocks = ( {
2929
blocks,
3030
};
3131

32+
const blocksContainMedia =
33+
blocks.filter(
34+
( block ) =>
35+
( block.name === 'core/image' ||
36+
block.name === 'core/audio' ||
37+
block.name === 'core/video' ) &&
38+
( block.attributes.url || block.attributes.src )
39+
).length > 0;
40+
3241
const blockTypeIcon = useSelect(
3342
( select ) => {
3443
const { getBlockType } = select( blocksStore );
@@ -63,7 +72,7 @@ const InserterDraggableBlocks = ( {
6372
? [ createBlock( 'core/block', { ref: pattern.id } ) ]
6473
: blocks;
6574
event.dataTransfer.setData(
66-
'text/html',
75+
blocksContainMedia ? 'default' : 'text/html',
6776
serialize( parsedBlocks )
6877
);
6978
} }

packages/block-editor/src/components/media-placeholder/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,10 @@ export function MediaPlaceholder( {
288288
}
289289
}
290290

291-
async function onHTMLDrop( HTML ) {
292-
const blocks = pasteHandler( { HTML } );
291+
async function onDrop( event ) {
292+
const blocks = pasteHandler( {
293+
HTML: event.dataTransfer?.getData( 'default' ),
294+
} );
293295
return await handleBlocksDrop( blocks );
294296
}
295297

@@ -379,9 +381,7 @@ export function MediaPlaceholder( {
379381
return null;
380382
}
381383

382-
return (
383-
<DropZone onFilesDrop={ onFilesUpload } onHTMLDrop={ onHTMLDrop } />
384-
);
384+
return <DropZone onFilesDrop={ onFilesUpload } onDrop={ onDrop } />;
385385
};
386386

387387
const renderCancelLink = () => {

test/e2e/specs/editor/blocks/image.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ test.describe( 'Image', () => {
545545
dummy.style.left = 0;
546546
dummy.draggable = 'true';
547547
dummy.addEventListener( 'dragstart', ( event ) => {
548-
event.dataTransfer.setData( 'text/html', _html );
548+
event.dataTransfer.setData( 'default', _html );
549549
setTimeout( () => {
550550
dummy.remove();
551551
}, 0 );

0 commit comments

Comments
 (0)