From fcf3d748c9ac9a4becb3509a5cbd8702b73a6028 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 7 Sep 2023 12:07:13 +0100 Subject: [PATCH] Remove some editing-based conditionals --- .../src/components/link-control/index.js | 150 ++++++++---------- packages/format-library/src/link/inline.js | 2 +- 2 files changed, 64 insertions(+), 88 deletions(-) diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index c25ed5cd1187a..5a264d63ebeda 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -327,16 +327,15 @@ function LinkControl( { const shownUnlinkControl = onRemove && value && ! isEditingLink && ! isCreatingPage; - const showActions = isEditingLink && hasLinkValue; + const showActions = hasLinkValue; // 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. const showTextControl = hasLinkValue && hasTextControl; - const isEditing = ( isEditingLink || ! value ) && ! isCreatingPage; const isDisabled = ! valueHasChanges || currentInputIsEmpty; - const showSettings = !! settings?.length && isEditingLink && hasLinkValue; + const showSettings = !! settings?.length && hasLinkValue; return (
) } - { isEditing && ( - <> -
- { showTextControl && ( - - ) } - - { ! showActions && ( -
-
- ) } -
- { errorMessage && ( - - { errorMessage } - - ) } - - ) } - - { value && ! isEditingLink && ! isCreatingPage && ( + { 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 ( - settings?.find( - ( setting ) => setting.id === 'opensInNewTab' - ) - ) { - return ( - id === 'opensInNewTab' - ) } - onChange={ onChange } - /> - ); - } - } } onRemove={ () => { onRemove(); setIsEditingLink( true ); @@ -447,6 +363,66 @@ function LinkControl( { /> ) } +
+ + + { showTextControl && ( + + ) } + + { ! showActions && ( +
+
+ ) } +
+ { errorMessage && ( + + { errorMessage } + + ) } + { showSettings && (
{ ! currentInputIsEmpty && ( diff --git a/packages/format-library/src/link/inline.js b/packages/format-library/src/link/inline.js index f5f1b49deba34..0d0880e16347e 100644 --- a/packages/format-library/src/link/inline.js +++ b/packages/format-library/src/link/inline.js @@ -254,7 +254,7 @@ function InlineLinkUI( { value={ linkValue } onChange={ onChangeLink } onRemove={ removeLink } - forceIsEditingLink={ addingLink } + onCancel={ stopAddingLink } hasRichPreviews createSuggestion={ createPageEntity && handleCreate } withCreateSuggestion={ userCanCreatePages }