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

Image editing: batch editing in cropper component #23284

Merged
merged 9 commits into from
Jun 21, 2020
Prev Previous commit
Next Next commit
Reorg buttons
  • Loading branch information
ellatrix committed Jun 21, 2020
commit d0b20bfd8d5c878cbb33f6fe5a7241a1de197a68
15 changes: 3 additions & 12 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
BlockControls,
BlockIcon,
MediaPlaceholder,
MediaReplaceFlow,
__experimentalBlock as Block,
} from '@wordpress/block-editor';
import { useEffect, useRef } from '@wordpress/element';
Expand Down Expand Up @@ -223,17 +222,6 @@ export function ImageEdit( {
value={ align }
onChange={ updateAlignment }
/>
{ url && (
<MediaReplaceFlow
mediaId={ id }
mediaURL={ url }
allowedTypes={ ALLOWED_MEDIA_TYPES }
accept="image/*"
onSelect={ onSelectImage }
onSelectURL={ onSelectURL }
onError={ onUploadError }
/>
) }
</BlockControls>
);
const src = isExternal ? url : undefined;
Expand Down Expand Up @@ -283,6 +271,9 @@ export function ImageEdit( {
isSelected={ isSelected }
insertBlocksAfter={ insertBlocksAfter }
onReplace={ onReplace }
onSelectImage={ onSelectImage }
onSelectURL={ onSelectURL }
onUploadError={ onUploadError }
containerRef={ ref }
/>
) }
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/image/image-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ export default function ImageEditor( {
<ToolbarButton onClick={ apply } disabled={ inProgress }>
{ __( 'Apply' ) }
</ToolbarButton>
<ToolbarButton onClick={ () => setIsEditingImage( false ) }>
{ __( 'Cancel' ) }
</ToolbarButton>
</ToolbarGroup>
</BlockControls>
</>
Expand Down
39 changes: 26 additions & 13 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
RichText,
__experimentalImageSizeControl as ImageSizeControl,
__experimentalImageURLInputUI as ImageURLInputUI,
MediaReplaceFlow,
} from '@wordpress/block-editor';
import { useEffect, useState } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
Expand All @@ -42,7 +43,7 @@ import ImageEditor from './image-editor';
/**
* Module constants
*/
import { MIN_SIZE } from './constants';
import { MIN_SIZE, ALLOWED_MEDIA_TYPES } from './constants';

function getFilename( url ) {
const path = getPath( url );
Expand Down Expand Up @@ -72,6 +73,9 @@ export default function Image( {
isSelected,
insertBlocksAfter,
onReplace,
onSelectImage,
onSelectURL,
onUploadError,
containerRef,
} ) {
const image = useSelect(
Expand Down Expand Up @@ -183,6 +187,12 @@ export default function Image( {
}
}, [ isSelected ] );

const canEditImage =
__experimentalEnableRichImageEditing &&
id &&
naturalWidth &&
naturalHeight;

const controls = (
<>
<BlockControls>
Expand All @@ -200,17 +210,26 @@ export default function Image( {
/>
</ToolbarGroup>
) }
{ id && (
{ canEditImage && ! isEditingImage && (
<ToolbarGroup>
<ToolbarButton
onClick={ () =>
setIsEditingImage( ( value ) => ! value )
}
onClick={ () => setIsEditingImage( true ) }
>
{ isEditingImage ? __( 'Cancel' ) : __( 'Edit' ) }
{ __( 'Crop' ) }
</ToolbarButton>
</ToolbarGroup>
) }
{ ! isEditingImage && (
<MediaReplaceFlow
mediaId={ id }
mediaURL={ url }
allowedTypes={ ALLOWED_MEDIA_TYPES }
accept="image/*"
onSelect={ onSelectImage }
onSelectURL={ onSelectURL }
onError={ onUploadError }
/>
) }
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Image settings' ) }>
Expand Down Expand Up @@ -317,13 +336,7 @@ export default function Image( {
: naturalHeight;
}

if (
__experimentalEnableRichImageEditing &&
isEditingImage &&
id &&
naturalWidth &&
naturalHeight
) {
if ( canEditImage && isEditingImage ) {
img = (
<ImageEditor
id={ id }
Expand Down