From b54a42667640adf4477bd89a85285dbd583b633e Mon Sep 17 00:00:00 2001 From: Artemio Morales Date: Fri, 22 Mar 2024 14:37:21 -0400 Subject: [PATCH] Fix lightbox UI disallow editing (#59890) * Check that lightbox can be edited before rendering lightbox UI * Refactor to reduce duplicate code * Fix and clarify component rendering logic Fix issue wherein lightbox popover was rendering erroneously when a link had been configured. * Reset lightbox attributes when removing link * Show lightbox UI if block-level override differs from default In some cases, such as when lightbox settings already exist for a block when global lightbox settings in theme.json change, we should allow users to see the lightbox UI and change the settings if they conflict with the global settings, even if the lightbox UI is disabled globally. This prevents a block from getting stuck with legacy lightbox settings and allows users to reset the block-level lightbox settings if need be in these edge cases. Note: We do not display the UI if the block-level settings exist and match the global settings, as the block will behave as expected in those circumstances and showing the UI in those circumstances would likely just be confusing. * Handle edge case of removing existing link when lightbox is fully enabled * Fix focus loss preventing end-to-end test from passing * Add link to PR in comment Co-authored-by: artemiomorales Co-authored-by: michalczaplinski Co-authored-by: justintadlock Co-authored-by: annezazu Co-authored-by: gziolo Co-authored-by: t-hamano Co-authored-by: jeherve --- .../url-popover/image-url-input-ui.js | 119 ++++++++++-------- packages/block-library/src/image/image.js | 22 +++- 2 files changed, 89 insertions(+), 52 deletions(-) diff --git a/packages/block-editor/src/components/url-popover/image-url-input-ui.js b/packages/block-editor/src/components/url-popover/image-url-input-ui.js index ae59daa1f502b..a7b40b42f6dd7 100644 --- a/packages/block-editor/src/components/url-popover/image-url-input-ui.js +++ b/packages/block-editor/src/components/url-popover/image-url-input-ui.js @@ -46,6 +46,7 @@ const ImageURLInputUI = ( { showLightboxSetting, lightboxEnabled, onSetLightbox, + resetLightbox, } ) => { const [ isOpen, setIsOpen ] = useState( false ); // Use internal state instead of a ref to make sure that the component @@ -241,7 +242,9 @@ const ImageURLInputUI = ( { ); const linkEditorValue = urlInput !== null ? urlInput : url; - const showLinkEditor = ( ! linkEditorValue && ! lightboxEnabled ) === true; + const hideLightboxPanel = + ! lightboxEnabled || ( lightboxEnabled && ! showLightboxSetting ); + const showLinkEditor = ! linkEditorValue && hideLightboxPanel; const urlLabel = ( getLinkDestinations().find( @@ -249,6 +252,65 @@ const ImageURLInputUI = ( { ) || {} ).title; + const PopoverChildren = () => { + if ( + lightboxEnabled && + showLightboxSetting && + ! url && + ! isEditingLink + ) { + return ( +
+ +
+

{ __( 'Expand on click' ) }

+

+ { __( 'Scales the image with a lightbox effect' ) } +

+
+
+ ); + } else if ( ! url || isEditingLink ) { + return ( + + ); + } else if ( url && ! isEditingLink ) { + return ( + <> + +