diff --git a/packages/block-library/src/file/transforms.js b/packages/block-library/src/file/transforms.js index b925e80e59503..c381a62f78386 100644 --- a/packages/block-library/src/file/transforms.js +++ b/packages/block-library/src/file/transforms.js @@ -24,12 +24,32 @@ const transforms = { const blobURL = createBlobURL( file ); // File will be uploaded in componentDidMount() - blocks.push( - createBlock( 'core/file', { - blob: blobURL, - fileName: file.name, - } ) - ); + if ( file.type.startsWith( 'video/' ) ) { + blocks.push( + createBlock( 'core/video', { + blob: createBlobURL( file ), + } ) + ); + } else if ( file.type.startsWith( 'image/' ) ) { + blocks.push( + createBlock( 'core/image', { + blob: createBlobURL( file ), + } ) + ); + } else if ( file.type.startsWith( 'audio/' ) ) { + blocks.push( + createBlock( 'core/audio', { + blob: createBlobURL( file ), + } ) + ); + } else { + blocks.push( + createBlock( 'core/file', { + blob: blobURL, + fileName: file.name, + } ) + ); + } } ); return blocks; diff --git a/packages/block-library/src/image/transforms.js b/packages/block-library/src/image/transforms.js index 0e1dfb6ee9da4..347d240828017 100644 --- a/packages/block-library/src/image/transforms.js +++ b/packages/block-library/src/image/transforms.js @@ -3,9 +3,6 @@ */ import { createBlobURL, isBlobURL } from '@wordpress/blob'; import { createBlock, getBlockAttributes } from '@wordpress/blocks'; -import { dispatch } from '@wordpress/data'; -import { store as noticesStore } from '@wordpress/notices'; -import { __ } from '@wordpress/i18n'; export function stripFirstImage( attributes, { shortcode } ) { const { body } = document.implementation.createHTMLDocument( '' ); @@ -138,26 +135,6 @@ const transforms = { // creating a new gallery. type: 'files', isMatch( files ) { - // The following check is intended to catch non-image files when dropped together with images. - if ( - files.some( - ( file ) => file.type.indexOf( 'image/' ) === 0 - ) && - files.some( - ( file ) => file.type.indexOf( 'image/' ) !== 0 - ) - ) { - const { createErrorNotice } = dispatch( noticesStore ); - createErrorNotice( - __( - 'If uploading to a gallery all files need to be image formats' - ), - { - id: 'gallery-transform-invalid-file', - type: 'snackbar', - } - ); - } return files.every( ( file ) => file.type.indexOf( 'image/' ) === 0 );