Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Nov 26, 2024
1 parent 5b9a72a commit 883830f
Showing 1 changed file with 5 additions and 27 deletions.
32 changes: 5 additions & 27 deletions packages/block-editor/src/components/media-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,30 +229,15 @@ export function MediaPlaceholder( {
} );
};

async function handleBlocksDrop( blocks ) {
if ( ! blocks || ! Array.isArray( blocks ) ) {
return;
}

function recursivelyFindMediaFromBlocks( _blocks ) {
return _blocks.flatMap( ( block ) =>
( block.name === 'core/image' ||
block.name === 'core/audio' ||
block.name === 'core/video' ) &&
( block.attributes.url || block.attributes.src )
? [ block ]
: recursivelyFindMediaFromBlocks( block.innerBlocks )
);
}

const mediaBlocks = recursivelyFindMediaFromBlocks( blocks );
async function handleBlocksDrop( event ) {
const { blocks } = parseDropEvent( event );

if ( ! mediaBlocks.length ) {
if ( ! blocks || ! blocks.length ) {
return;
}

const uploadedMediaList = await Promise.all(
mediaBlocks.map( ( block ) => {
blocks.map( ( block ) => {
const blockType = block.name.split( '/' )[ 1 ];
if ( block.attributes.id ) {
block.attributes.type = blockType;
Expand Down Expand Up @@ -292,13 +277,6 @@ export function MediaPlaceholder( {
}
}

function onDrop( event ) {
const { blocks } = parseDropEvent( event );
if ( blocks ) {
handleBlocksDrop( blocks );
}
}

const onUpload = ( event ) => {
onFilesUpload( event.target.files );
};
Expand Down Expand Up @@ -388,7 +366,7 @@ export function MediaPlaceholder( {
return (
<DropZone
onFilesDrop={ onFilesUpload }
onDrop={ onDrop }
onDrop={ handleBlocksDrop }
isEligible={ ( dataTransfer ) => {
const prefix = 'wp-block:core/';
const types = [];
Expand Down

0 comments on commit 883830f

Please sign in to comment.