Skip to content
40 changes: 11 additions & 29 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { isExternalImage } from './edit';
import { Caption } from '../utils/caption';
import { MediaControl } from '../utils/media-control';
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';
import { useOpenImageMediaEditorModal } from './use-open-image-media-editor-modal';
import {
MIN_SIZE,
ALLOWED_MEDIA_TYPES,
Expand All @@ -70,12 +71,9 @@ import {
} from './constants';
import { evalAspectRatio, mediaPosition } from './utils';

const {
DimensionsTool,
ResolutionTool,
mediaEditKey,
openMediaEditorModalKey,
} = unlock( blockEditorPrivateApis );
const { DimensionsTool, ResolutionTool, mediaEditKey } = unlock(
blockEditorPrivateApis
);

const scaleOptions = [
{
Expand Down Expand Up @@ -381,20 +379,10 @@ export default function Image( {
[ clientId ]
);
const { getBlock, getSettings } = useSelect( blockEditorStore );
const settings = getSettings();
const openMediaEditorModal = settings[ openMediaEditorModalKey ];

const handleMediaUpdate = useCallback(
Comment on lines -384 to -387

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 Makes sense to move this into the new hook

( { id: newId, url: newUrl } ) => {
if ( typeof newId === 'number' && newId !== id ) {
setAttributes( {
id: newId,
url: newUrl ?? url,
} );
}
},
[ id, url, setAttributes ]
);
const openImageMediaEditorModal = useOpenImageMediaEditorModal( {
attributes,
setAttributes,
} );

const {
replaceBlocks,
Expand Down Expand Up @@ -858,18 +846,12 @@ export default function Image( {
{ allowCrop && (
<ToolbarButton
onClick={
openMediaEditorModal && id
? () =>
openMediaEditorModal( {
id,
onUpdate: handleMediaUpdate,
} )
openImageMediaEditorModal
? openImageMediaEditorModal
: () => setIsEditingImage( true )
}
aria-haspopup={
openMediaEditorModal && id
? 'dialog'
: undefined
openImageMediaEditorModal ? 'dialog' : undefined
}
icon={ crop }
label={ __( 'Crop' ) }
Expand Down
Loading
Loading