Skip to content

Commit

Permalink
Separate into a different lockHrefControls
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Feb 6, 2024
1 parent 44a3486 commit 34df026
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ export default function Image( {

const {
lockUrlControls = false,
lockHrefControls = false,
lockAltControls = false,
lockTitleControls = false,
} = useSelect(
Expand All @@ -416,15 +417,20 @@ export default function Image( {
unlock( select( blockEditorStore ) );
const {
url: urlBinding,
href: hrefBinding,
alt: altBinding,
title: titleBinding,
} = metadata?.bindings || {};
const hasParentPattern =
getBlockParentsByBlockName( clientId, 'core/block' ).length > 0;
return {
lockUrlControls:
( !! urlBinding &&
getBlockBindingsSource( urlBinding?.source )
!! urlBinding &&
getBlockBindingsSource( urlBinding?.source )
?.lockAttributesEditing === true,
lockHrefControls:
( !! hrefBinding &&
getBlockBindingsSource( hrefBinding?.source )
?.lockAttributesEditing === true ) ||
// Disable editing the link of the URL if the image is inside a pattern instance.
// This is a temporary solution until we support overriding the link on the frontend.
Expand All @@ -445,21 +451,23 @@ export default function Image( {
const controls = (
<>
<BlockControls group="block">
{ isSingleSelected && ! isEditingImage && ! lockUrlControls && (
<ImageURLInputUI
url={ href || '' }
onChangeUrl={ onSetHref }
linkDestination={ linkDestination }
mediaUrl={ ( image && image.source_url ) || url }
mediaLink={ image && image.link }
linkTarget={ linkTarget }
linkClass={ linkClass }
rel={ rel }
showLightboxSetting={ showLightboxSetting }
lightboxEnabled={ lightboxChecked }
onSetLightbox={ onSetLightbox }
/>
) }
{ isSingleSelected &&
! isEditingImage &&
! lockHrefControls && (
<ImageURLInputUI
url={ href || '' }
onChangeUrl={ onSetHref }
linkDestination={ linkDestination }
mediaUrl={ ( image && image.source_url ) || url }
mediaLink={ image && image.link }
linkTarget={ linkTarget }
linkClass={ linkClass }
rel={ rel }
showLightboxSetting={ showLightboxSetting }
lightboxEnabled={ lightboxChecked }
onSetLightbox={ onSetLightbox }
/>
) }
{ allowCrop && (
<ToolbarButton
onClick={ () => setIsEditingImage( true ) }
Expand Down

0 comments on commit 34df026

Please sign in to comment.