From fec385a312a771b09337964697e2d00fc5edd01d Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 11 Jan 2024 09:27:42 +0000 Subject: [PATCH 1/3] Show link preview on edit view --- .../src/components/link-control/index.js | 137 ++++++++++-------- 1 file changed, 74 insertions(+), 63 deletions(-) diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index a208fa20d242f..e4a029d0fb06c 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -330,8 +330,7 @@ function LinkControl( { const currentInputIsEmpty = ! currentUrlInputValue?.trim()?.length; - const shownUnlinkControl = - onRemove && value && ! isEditingLink && ! isCreatingPage; + const shownUnlinkControl = onRemove && value && ! isCreatingPage; const showActions = isEditingLink && hasLinkValue; @@ -356,6 +355,40 @@ function LinkControl( { ) } + { hasLinkValue && ! isCreatingPage && ( + setIsEditingLink( true ) } + hasRichPreviews={ hasRichPreviews } + hasUnlinkControl={ shownUnlinkControl } + additionalControls={ () => { + // Expose the "Opens in new tab" settings in the preview + // as it is the most common setting to change. + if ( + ! isEditing && + settings?.find( + ( setting ) => setting.id === 'opensInNewTab' + ) + ) { + return ( + id === 'opensInNewTab' + ) } + onChange={ onChange } + /> + ); + } + } } + onRemove={ () => { + onRemove(); + setIsEditingLink( true ); + } } + /> + ) } + { isEditing && ( <>
) } - - { ! showActions && ( -
-
+ { ! showActions && ( +
+
+ ) } + ) }
{ errorMessage && ( @@ -420,39 +464,6 @@ function LinkControl( { ) } - { value && ! isEditingLink && ! isCreatingPage && ( - setIsEditingLink( true ) } - hasRichPreviews={ hasRichPreviews } - hasUnlinkControl={ shownUnlinkControl } - additionalControls={ () => { - // Expose the "Opens in new tab" settings in the preview - // as it is the most common setting to change. - if ( - settings?.find( - ( setting ) => setting.id === 'opensInNewTab' - ) - ) { - return ( - id === 'opensInNewTab' - ) } - onChange={ onChange } - /> - ); - } - } } - onRemove={ () => { - onRemove(); - setIsEditingLink( true ); - } } - /> - ) } - { showSettings && (
{ ! currentInputIsEmpty && ( From 0dab64deb05c46785a1a960745e15d79d217423c Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 11 Jan 2024 09:37:08 +0000 Subject: [PATCH 2/3] Conditionally display Link field and Preview --- .../src/components/link-control/index.js | 15 +++++++++++++++ .../src/components/link-control/link-preview.js | 3 +++ .../src/components/link-control/style.scss | 1 + 3 files changed, 19 insertions(+) diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index e4a029d0fb06c..1476b47879a5a 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -334,6 +334,8 @@ function LinkControl( { const showActions = isEditingLink && hasLinkValue; + const showURLInput = hasLinkValue && ! value?.id; + // Only show text control once a URL value has been committed // and it isn't just empty whitespace. // See https://github.com/WordPress/gutenberg/pull/33849/#issuecomment-932194927. @@ -359,6 +361,7 @@ function LinkControl( { setIsEditingLink( true ) } hasRichPreviews={ hasRichPreviews } hasUnlinkControl={ shownUnlinkControl } @@ -398,6 +401,18 @@ function LinkControl( { 'has-actions': showActions, } ) } > + { showURLInput && ( + + ) } + { showTextControl && ( + { hasUnlinkControl && (
- ) } - + ) } { errorMessage && (