Skip to content
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
8 changes: 8 additions & 0 deletions packages/block-library/src/cover/edit/cover-placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { BlockIcon, MediaPlaceholder } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { cover as icon } from '@wordpress/icons';
import { createBlobURL } from '@wordpress/blob';

/**
* Internal dependencies
Expand All @@ -18,6 +19,12 @@ export default function CoverPlaceholder( {
style,
toggleUseFeaturedImage,
} ) {
const onFilesPreUpload = ( files ) => {
if ( files.length === 1 ) {
onSelectMedia( { url: createBlobURL( files[ 0 ] ) } );
}
};

return (
<MediaPlaceholder
icon={ <BlockIcon icon={ icon } /> }
Expand All @@ -28,6 +35,7 @@ export default function CoverPlaceholder( {
allowedTypes={ ALLOWED_MEDIA_TYPES }
disableMediaButtons={ disableMediaButtons }
onToggleFeaturedImage={ toggleUseFeaturedImage }
onFilesPreUpload={ onFilesPreUpload }
onError={ onError }
style={ style }
>
Expand Down
8 changes: 8 additions & 0 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export function ImageEdit( {
const { createErrorNotice } = useDispatch( noticesStore );
function onUploadError( message ) {
createErrorNotice( message, { type: 'snackbar' } );
setTemporaryURL();
setAttributes( {
src: undefined,
id: undefined,
Expand All @@ -167,6 +168,12 @@ export function ImageEdit( {
} );
}

function onFilesPreUpload( files ) {
if ( files.length === 1 ) {
setTemporaryURL( createBlobURL( files[ 0 ] ) );
}
}

function onSelectImagesList( images ) {
const win = containerRef.current?.ownerDocument.defaultView;

Expand Down Expand Up @@ -479,6 +486,7 @@ export function ImageEdit( {
icon={ <BlockIcon icon={ icon } /> }
onSelect={ onSelectImage }
onSelectURL={ onSelectURL }
onFilesPreUpload={ onFilesPreUpload }
onError={ onUploadError }
placeholder={ placeholder }
allowedTypes={ ALLOWED_MEDIA_TYPES }
Expand Down
9 changes: 8 additions & 1 deletion packages/block-library/src/media-text/media-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { __ } from '@wordpress/i18n';
import { useViewportMatch } from '@wordpress/compose';
import { useDispatch } from '@wordpress/data';
import { forwardRef } from '@wordpress/element';
import { isBlobURL } from '@wordpress/blob';
import { createBlobURL, isBlobURL } from '@wordpress/blob';
import { store as noticesStore } from '@wordpress/notices';
import { media as icon } from '@wordpress/icons';

Expand Down Expand Up @@ -82,6 +82,12 @@ function PlaceholderContainer( {
createErrorNotice( message, { type: 'snackbar' } );
};

const onFilesPreUpload = ( files ) => {
if ( files.length === 1 ) {
onSelectMedia( { url: createBlobURL( files[ 0 ] ) } );
}
};

return (
<MediaPlaceholder
icon={ <BlockIcon icon={ icon } /> }
Expand All @@ -92,6 +98,7 @@ function PlaceholderContainer( {
onSelect={ onSelectMedia }
onToggleFeaturedImage={ toggleUseFeaturedImage }
allowedTypes={ ALLOWED_MEDIA_TYPES }
onFilesPreUpload={ onFilesPreUpload }
onError={ onUploadError }
disableMediaButtons={ mediaUrl }
/>
Expand Down
Loading