UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 30.2 kB
{ "version": 3, "sources": ["../../../src/components/link-control/index.js"], "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tSpinner,\n\tNotice,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalInputControlSuffixWrapper as InputControlSuffixWrapper,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useRef, useState, useEffect, useMemo } from '@wordpress/element';\nimport { useInstanceId } from '@wordpress/compose';\nimport { focus } from '@wordpress/dom';\nimport { ENTER } from '@wordpress/keycodes';\nimport { isShallowEqualObjects } from '@wordpress/is-shallow-equal';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport { keyboardReturn, linkOff } from '@wordpress/icons';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport LinkControlSettingsDrawer from './settings-drawer';\nimport LinkControlSearchInput from './search-input';\nimport LinkPreview from './link-preview';\nimport LinkSettings from './settings';\nimport useCreatePage from './use-create-page';\nimport useInternalValue from './use-internal-value';\nimport { ViewerFill } from './viewer-slot';\nimport { DEFAULT_LINK_SETTINGS } from './constants';\n\n/**\n * Default properties associated with a link control value.\n *\n * @typedef WPLinkControlDefaultValue\n *\n * @property {string} url Link URL.\n * @property {string=} title Link title.\n * @property {boolean=} opensInNewTab Whether link should open in a new browser\n * tab. This value is only assigned if not\n * providing a custom `settings` prop.\n */\n\n/**\n * Custom settings values associated with a link.\n *\n * @typedef {{[setting:string]:any}} WPLinkControlSettingsValue\n */\n\n/**\n * Custom settings values associated with a link.\n *\n * @typedef WPLinkControlSetting\n *\n * @property {string} id Identifier to use as property for setting value.\n * @property {string} title Human-readable label to show in user interface.\n */\n\n/**\n * Properties associated with a link control value, composed as a union of the\n * default properties and any custom settings values.\n *\n * @typedef {WPLinkControlDefaultValue&WPLinkControlSettingsValue} WPLinkControlValue\n */\n\n/** @typedef {(nextValue:WPLinkControlValue)=>void} WPLinkControlOnChangeProp */\n\n/**\n * Properties associated with a search suggestion used within the LinkControl.\n *\n * @typedef WPLinkControlSuggestion\n *\n * @property {string} id Identifier to use to uniquely identify the suggestion.\n * @property {string} type Identifies the type of the suggestion (eg: `post`,\n * `page`, `url`...etc)\n * @property {string} title Human-readable label to show in user interface.\n * @property {string} url A URL for the suggestion.\n */\n\n/** @typedef {(title:string)=>WPLinkControlSuggestion} WPLinkControlCreateSuggestionProp */\n\n/**\n * @typedef WPLinkControlProps\n *\n * @property {(WPLinkControlSetting[])=} settings An array of settings objects. Each object will used to\n * render a `ToggleControl` for that setting.\n * @property {boolean=} forceIsEditingLink If passed as either `true` or `false`, controls the\n * internal editing state of the component to respective\n * show or not show the URL input field.\n * @property {WPLinkControlValue=} value Current link value.\n * @property {WPLinkControlOnChangeProp=} onChange Value change handler, called with the updated value if\n * the user selects a new link or updates settings.\n * @property {boolean=} noDirectEntry Whether to allow turning a URL-like search query directly into a link.\n * @property {boolean=} showSuggestions Whether to present suggestions when typing the URL.\n * @property {boolean=} showInitialSuggestions Whether to present initial suggestions immediately.\n * @property {boolean=} withCreateSuggestion Whether to allow creation of link value from suggestion.\n * @property {Object=} suggestionsQuery Query parameters to pass along to wp.blockEditor.__experimentalFetchLinkSuggestions.\n * @property {boolean=} noURLSuggestion Whether to add a fallback suggestion which treats the search query as a URL.\n * @property {boolean=} hasTextControl Whether to add a text field to the UI to update the value.title.\n * @property {string|Function|undefined} createSuggestionButtonText The text to use in the button that calls createSuggestion.\n * @property {Function} renderControlBottom Optional controls to be rendered at the bottom of the component.\n * @property {boolean=} handleEntities Whether to handle entity links (links with ID). When true and a link has an ID, the input will be disabled and show an unlink button.\n */\n\nconst noop = () => {};\n\nconst PREFERENCE_SCOPE = 'core/block-editor';\nconst PREFERENCE_KEY = 'linkControlSettingsDrawer';\n\n/**\n * Renders a link control. A link control is a controlled input which maintains\n * a value associated with a link (HTML anchor element) and relevant settings\n * for how that link is expected to behave.\n *\n * @param {WPLinkControlProps} props Component props.\n */\nfunction LinkControl( {\n\tsearchInputPlaceholder,\n\tvalue,\n\tsettings = DEFAULT_LINK_SETTINGS,\n\tonChange = noop,\n\tonRemove,\n\tonCancel,\n\tnoDirectEntry = false,\n\tshowSuggestions = true,\n\tshowInitialSuggestions,\n\tforceIsEditingLink,\n\tcreateSuggestion,\n\twithCreateSuggestion,\n\tinputValue: propInputValue = '',\n\tsuggestionsQuery = {},\n\tnoURLSuggestion = false,\n\tcreateSuggestionButtonText,\n\thasRichPreviews = false,\n\thasTextControl = false,\n\trenderControlBottom = null,\n\thandleEntities = false,\n} ) {\n\tif ( withCreateSuggestion === undefined && createSuggestion ) {\n\t\twithCreateSuggestion = true;\n\t}\n\n\tconst [ settingsOpen, setSettingsOpen ] = useState( false );\n\n\tconst { advancedSettingsPreference } = useSelect( ( select ) => {\n\t\tconst prefsStore = select( preferencesStore );\n\n\t\treturn {\n\t\t\tadvancedSettingsPreference:\n\t\t\t\tprefsStore.get( PREFERENCE_SCOPE, PREFERENCE_KEY ) ?? false,\n\t\t};\n\t}, [] );\n\n\tconst { set: setPreference } = useDispatch( preferencesStore );\n\n\t/**\n\t * Sets the open/closed state of the Advanced Settings Drawer,\n\t * optionlly persisting the state to the user's preferences.\n\t *\n\t * Note that Block Editor components can be consumed by non-WordPress\n\t * environments which may not have preferences setup.\n\t * Therefore a local state is also used as a fallback.\n\t *\n\t * @param {boolean} prefVal the open/closed state of the Advanced Settings Drawer.\n\t */\n\tconst setSettingsOpenWithPreference = ( prefVal ) => {\n\t\tif ( setPreference ) {\n\t\t\tsetPreference( PREFERENCE_SCOPE, PREFERENCE_KEY, prefVal );\n\t\t}\n\t\tsetSettingsOpen( prefVal );\n\t};\n\n\t// Block Editor components can be consumed by non-WordPress environments\n\t// which may not have these preferences setup.\n\t// Therefore a local state is used as a fallback.\n\tconst isSettingsOpen = advancedSettingsPreference || settingsOpen;\n\n\tconst isMountingRef = useRef( true );\n\tconst wrapperNode = useRef();\n\tconst textInputRef = useRef();\n\tconst searchInputRef = useRef();\n\t// TODO: Remove entityUrlFallbackRef and previewValue in favor of value prop after taxonomy entity binding\n\t// is stable and returns the correct URL instead of null while resolving when creating the entity.\n\t//\n\t// Preserve the URL from entity suggestions before binding overrides it\n\t// This is due to entity binding not being available immediately after the suggestion is selected.\n\t// The URL can return null, especially for taxonomy entities, while entity binding is being resolved.\n\t// To avoid unnecessary rerenders and focus loss, we preserve the URL from the suggestion and use it\n\t// as a fallback until the entity binding is available.\n\tconst entityUrlFallbackRef = useRef();\n\n\tconst settingsKeys = settings.map( ( { id } ) => id );\n\n\tconst [\n\t\tinternalControlValue,\n\t\tsetInternalControlValue,\n\t\tsetInternalURLInputValue,\n\t\tsetInternalTextInputValue,\n\t\tcreateSetInternalSettingValueHandler,\n\t] = useInternalValue( value );\n\n\t// Compute isEntity internally based on handleEntities prop and presence of ID\n\tconst isEntity = handleEntities && !! internalControlValue?.id;\n\n\t// Generate help text ID for accessibility association\n\tconst baseId = useInstanceId( LinkControl, 'link-control' );\n\tconst helpTextId = isEntity ? `${ baseId }__help` : null;\n\n\tconst valueHasChanges =\n\t\tvalue && ! isShallowEqualObjects( internalControlValue, value );\n\n\tconst [ isEditingLink, setIsEditingLink ] = useState(\n\t\tforceIsEditingLink !== undefined\n\t\t\t? forceIsEditingLink\n\t\t\t: ! value || ! value.url\n\t);\n\n\tconst { createPage, isCreatingPage, errorMessage } =\n\t\tuseCreatePage( createSuggestion );\n\n\tuseEffect( () => {\n\t\tif ( forceIsEditingLink === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsEditingLink( forceIsEditingLink );\n\t}, [ forceIsEditingLink ] );\n\n\tuseEffect( () => {\n\t\t// We don't auto focus into the Link UI on mount\n\t\t// because otherwise using the keyboard to select text\n\t\t// *within* the link format is not possible.\n\t\tif ( isMountingRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Scenario - when:\n\t\t// - switching between editable and non editable LinkControl\n\t\t// - clicking on a link\n\t\t// ...then move focus to the *first* element to avoid focus loss\n\t\t// and to ensure focus is *within* the Link UI.\n\t\tconst nextFocusTarget =\n\t\t\tfocus.focusable.find( wrapperNode.current )[ 0 ] ||\n\t\t\twrapperNode.current;\n\n\t\tnextFocusTarget.focus();\n\t}, [ isEditingLink, isCreatingPage ] );\n\n\t// The component mounting reference is maintained separately\n\t// to correctly reset values in `StrictMode`.\n\tuseEffect( () => {\n\t\tisMountingRef.current = false;\n\n\t\treturn () => {\n\t\t\tisMountingRef.current = true;\n\t\t};\n\t}, [] );\n\n\tconst hasLinkValue = value?.url?.trim()?.length > 0;\n\n\t/**\n\t * Cancels editing state.\n\t */\n\tconst stopEditing = () => {\n\t\tsetIsEditingLink( false );\n\t};\n\n\tconst handleSelectSuggestion = ( updatedValue ) => {\n\t\t// Preserve the URL for taxonomy entities before binding overrides it\n\t\tif ( updatedValue?.kind === 'taxonomy' && updatedValue?.url ) {\n\t\t\tentityUrlFallbackRef.current = updatedValue.url;\n\t\t}\n\n\t\t// Suggestions may contains \"settings\" values (e.g. `opensInNewTab`)\n\t\t// which should not override any existing settings values set by the\n\t\t// user. This filters out any settings values from the suggestion.\n\t\tconst nonSettingsChanges = Object.keys( updatedValue ).reduce(\n\t\t\t( acc, key ) => {\n\t\t\t\tif ( ! settingsKeys.includes( key ) ) {\n\t\t\t\t\tacc[ key ] = updatedValue[ key ];\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{}\n\t\t);\n\n\t\tonChange( {\n\t\t\t...internalControlValue,\n\t\t\t...nonSettingsChanges,\n\t\t\t// As title is not a setting, it must be manually applied\n\t\t\t// in such a way as to preserve the users changes over\n\t\t\t// any \"title\" value provided by the \"suggestion\".\n\t\t\ttitle: internalControlValue?.title || updatedValue?.title,\n\t\t} );\n\n\t\tstopEditing();\n\t};\n\n\tconst handleSubmit = () => {\n\t\tif ( valueHasChanges ) {\n\t\t\t// Submit the original value with new stored values applied\n\t\t\t// on top. URL is a special case as it may also be a prop.\n\t\t\tonChange( {\n\t\t\t\t...value,\n\t\t\t\t...internalControlValue,\n\t\t\t\turl: currentUrlInputValue,\n\t\t\t} );\n\t\t}\n\t\tstopEditing();\n\t};\n\n\tconst handleSubmitWithEnter = ( event ) => {\n\t\tconst { keyCode } = event;\n\n\t\tif (\n\t\t\tkeyCode === ENTER &&\n\t\t\t! currentInputIsEmpty // Disallow submitting empty values.\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t\thandleSubmit();\n\t\t}\n\t};\n\n\tconst resetInternalValues = () => {\n\t\tsetInternalControlValue( value );\n\t};\n\n\tconst handleCancel = ( event ) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\n\t\t// Ensure that any unsubmitted input changes are reset.\n\t\tresetInternalValues();\n\n\t\tif ( hasLinkValue ) {\n\t\t\t// If there is a link then exist editing mode and show preview.\n\t\t\tstopEditing();\n\t\t} else {\n\t\t\t// If there is no link value, then remove the link entirely.\n\t\t\tonRemove?.();\n\t\t}\n\n\t\tonCancel?.();\n\t};\n\n\tconst [ shouldFocusSearchInput, setShouldFocusSearchInput ] =\n\t\tuseState( false );\n\n\tconst handleUnlink = () => {\n\t\t// Clear the internal state to remove the ID and re-enable the field\n\t\t// Explicitly set id, kind, and type to undefined so they override\n\t\t// the original values when spread in handleSubmit. This ensures that\n\t\t// when the user types a custom URL and submits, the entity link is\n\t\t// properly severed (not just when selecting a different entity from suggestions).\n\t\tconst { id, kind, type, ...restValue } = internalControlValue;\n\t\tsetInternalControlValue( {\n\t\t\t...restValue,\n\t\t\tid: undefined,\n\t\t\tkind: undefined,\n\t\t\ttype: undefined,\n\t\t\turl: undefined,\n\t\t} );\n\n\t\t// Request focus after the component re-renders with the cleared state\n\t\t// We can't focus immediately because the input might still be disabled\n\t\tsetShouldFocusSearchInput( true );\n\t};\n\n\t// Focus the search input when requested, once the component has re-rendered\n\t// This ensures the input is enabled and ready to receive focus\n\tuseEffect( () => {\n\t\tif ( shouldFocusSearchInput ) {\n\t\t\tsearchInputRef.current?.focus();\n\t\t\tsetShouldFocusSearchInput( false );\n\t\t}\n\t}, [ shouldFocusSearchInput ] );\n\n\tconst currentUrlInputValue =\n\t\tpropInputValue || internalControlValue?.url || '';\n\n\tconst currentInputIsEmpty = ! currentUrlInputValue?.trim()?.length;\n\n\tconst shownUnlinkControl =\n\t\tonRemove && value && ! isEditingLink && ! isCreatingPage;\n\n\tconst showActions = isEditingLink && hasLinkValue;\n\n\t// Only show text control once a URL value has been committed\n\t// and it isn't just empty whitespace.\n\t// See https://github.com/WordPress/gutenberg/pull/33849/#issuecomment-932194927.\n\tconst showTextControl = hasLinkValue && hasTextControl;\n\n\tconst isEditing = ( isEditingLink || ! value ) && ! isCreatingPage;\n\tconst isDisabled = ! valueHasChanges || currentInputIsEmpty;\n\tconst showSettings = !! settings?.length && isEditingLink && hasLinkValue;\n\n\tconst previewValue = useMemo( () => {\n\t\t// There is a chance that the value is not yet set from the entity binding, so we use the preserved URL.\n\t\tif (\n\t\t\tvalue?.kind === 'taxonomy' &&\n\t\t\t! value?.url &&\n\t\t\tentityUrlFallbackRef.current\n\t\t) {\n\t\t\t// combine the value prop with the preserved URL from the suggestion\n\t\t\treturn {\n\t\t\t\t...value,\n\t\t\t\turl: entityUrlFallbackRef.current,\n\t\t\t};\n\t\t}\n\n\t\t// If we don't have a fallback URL, use the value prop.\n\t\treturn value;\n\t}, [ value ] );\n\n\treturn (\n\t\t<div\n\t\t\ttabIndex={ -1 }\n\t\t\tref={ wrapperNode }\n\t\t\tclassName=\"block-editor-link-control\"\n\t\t>\n\t\t\t{ isCreatingPage && (\n\t\t\t\t<div className=\"block-editor-link-control__loading\">\n\t\t\t\t\t<Spinner /> { __( 'Creating' ) }\u2026\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ isEditing && (\n\t\t\t\t<>\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={ clsx( {\n\t\t\t\t\t\t\t'block-editor-link-control__search-input-wrapper': true,\n\t\t\t\t\t\t\t'has-text-control': showTextControl,\n\t\t\t\t\t\t\t'has-actions': showActions,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ showTextControl && (\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\tref={ textInputRef }\n\t\t\t\t\t\t\t\tclassName=\"block-editor-link-control__field block-editor-link-control__text-content\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Text' ) }\n\t\t\t\t\t\t\t\tvalue={ internalControlValue?.title }\n\t\t\t\t\t\t\t\tonChange={ setInternalTextInputValue }\n\t\t\t\t\t\t\t\tonKeyDown={ handleSubmitWithEnter }\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<LinkControlSearchInput\n\t\t\t\t\t\t\tref={ searchInputRef }\n\t\t\t\t\t\t\tcurrentLink={ value }\n\t\t\t\t\t\t\tclassName=\"block-editor-link-control__field block-editor-link-control__search-input\"\n\t\t\t\t\t\t\tplaceholder={ searchInputPlaceholder }\n\t\t\t\t\t\t\tvalue={ currentUrlInputValue }\n\t\t\t\t\t\t\twithCreateSuggestion={ withCreateSuggestion }\n\t\t\t\t\t\t\tonCreateSuggestion={ createPage }\n\t\t\t\t\t\t\tonChange={ setInternalURLInputValue }\n\t\t\t\t\t\t\tonSelect={ handleSelectSuggestion }\n\t\t\t\t\t\t\tshowInitialSuggestions={ showInitialSuggestions }\n\t\t\t\t\t\t\tallowDirectEntry={ ! noDirectEntry }\n\t\t\t\t\t\t\tshowSuggestions={ showSuggestions }\n\t\t\t\t\t\t\tsuggestionsQuery={ suggestionsQuery }\n\t\t\t\t\t\t\twithURLSuggestion={ ! noURLSuggestion }\n\t\t\t\t\t\t\tcreateSuggestionButtonText={\n\t\t\t\t\t\t\t\tcreateSuggestionButtonText\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\thideLabelFromVision={ ! showTextControl }\n\t\t\t\t\t\t\tisEntity={ isEntity }\n\t\t\t\t\t\t\tsuffix={\n\t\t\t\t\t\t\t\t<SearchSuffixControl\n\t\t\t\t\t\t\t\t\tisEntity={ isEntity }\n\t\t\t\t\t\t\t\t\tshowActions={ showActions }\n\t\t\t\t\t\t\t\t\tisDisabled={ isDisabled }\n\t\t\t\t\t\t\t\t\tonUnlink={ handleUnlink }\n\t\t\t\t\t\t\t\t\tonSubmit={ handleSubmit }\n\t\t\t\t\t\t\t\t\thelpTextId={ helpTextId }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ isEntity && helpTextId && (\n\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\tid={ helpTextId }\n\t\t\t\t\t\t\t\tclassName=\"block-editor-link-control__help\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t\t\t/* translators: %s: entity type (e.g., page, post) */\n\t\t\t\t\t\t\t\t\t__( 'Synced with the selected %s.' ),\n\t\t\t\t\t\t\t\t\tinternalControlValue?.type || 'item'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</div>\n\t\t\t\t\t{ errorMessage && (\n\t\t\t\t\t\t<Notice\n\t\t\t\t\t\t\tclassName=\"block-editor-link-control__search-error\"\n\t\t\t\t\t\t\tstatus=\"error\"\n\t\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ errorMessage }\n\t\t\t\t\t\t</Notice>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\n\t\t\t{ value && ! isEditingLink && ! isCreatingPage && (\n\t\t\t\t<LinkPreview\n\t\t\t\t\tkey={ previewValue?.url } // force remount when URL changes to avoid race conditions for rich previews\n\t\t\t\t\tvalue={ previewValue }\n\t\t\t\t\tonEditClick={ () => setIsEditingLink( true ) }\n\t\t\t\t\thasRichPreviews={ hasRichPreviews }\n\t\t\t\t\thasUnlinkControl={ shownUnlinkControl }\n\t\t\t\t\tonRemove={ () => {\n\t\t\t\t\t\tonRemove();\n\t\t\t\t\t\tsetIsEditingLink( true );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t{ showSettings && (\n\t\t\t\t<div className=\"block-editor-link-control__tools\">\n\t\t\t\t\t{ ! currentInputIsEmpty && (\n\t\t\t\t\t\t<LinkControlSettingsDrawer\n\t\t\t\t\t\t\tsettingsOpen={ isSettingsOpen }\n\t\t\t\t\t\t\tsetSettingsOpen={ setSettingsOpenWithPreference }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<LinkSettings\n\t\t\t\t\t\t\t\tvalue={ internalControlValue }\n\t\t\t\t\t\t\t\tsettings={ settings }\n\t\t\t\t\t\t\t\tonChange={ createSetInternalSettingValueHandler(\n\t\t\t\t\t\t\t\t\tsettingsKeys\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</LinkControlSettingsDrawer>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ showActions && (\n\t\t\t\t<HStack\n\t\t\t\t\tjustify=\"right\"\n\t\t\t\t\tclassName=\"block-editor-link-control__search-actions\"\n\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ handleCancel }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ isDisabled ? noop : handleSubmit }\n\t\t\t\t\t\tclassName=\"block-editor-link-control__search-submit\"\n\t\t\t\t\t\taria-disabled={ isDisabled }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Apply' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t) }\n\n\t\t\t{ ! isCreatingPage && renderControlBottom && renderControlBottom() }\n\t\t</div>\n\t);\n}\n\n/**\n * Suffix control component for LinkControl search input.\n * Handles the display of unlink button for entities and submit button for regular links.\n *\n * @param {Object} props - Component props\n * @param {boolean} props.isEntity - Whether the link is bound to an entity\n * @param {boolean} props.showActions - Whether to show action buttons\n * @param {boolean} props.isDisabled - Whether the submit button should be disabled\n * @param {Function} props.onUnlink - Callback when unlink button is clicked\n * @param {Function} props.onSubmit - Callback when submit button is clicked\n * @param {string} props.helpTextId - ID of the help text element for accessibility\n */\nfunction SearchSuffixControl( {\n\tisEntity,\n\tshowActions,\n\tisDisabled,\n\tonUnlink,\n\tonSubmit,\n\thelpTextId,\n} ) {\n\tif ( isEntity ) {\n\t\treturn (\n\t\t\t<Button\n\t\t\t\ticon={ linkOff }\n\t\t\t\tonClick={ onUnlink }\n\t\t\t\taria-describedby={ helpTextId }\n\t\t\t\tshowTooltip\n\t\t\t\tlabel={ __( 'Unsync and edit' ) }\n\t\t\t\t__next40pxDefaultSize\n\t\t\t/>\n\t\t);\n\t}\n\n\tif ( showActions ) {\n\t\treturn undefined;\n\t}\n\n\treturn (\n\t\t<InputControlSuffixWrapper variant=\"control\">\n\t\t\t<Button\n\t\t\t\tonClick={ isDisabled ? noop : onSubmit }\n\t\t\t\tlabel={ __( 'Submit' ) }\n\t\t\t\ticon={ keyboardReturn }\n\t\t\t\tclassName=\"block-editor-link-control__search-submit\"\n\t\t\t\taria-disabled={ isDisabled }\n\t\t\t\tsize=\"small\"\n\t\t\t/>\n\t\t</InputControlSuffixWrapper>\n\t);\n}\n\nLinkControl.ViewerFill = ViewerFill;\nLinkControl.DEFAULT_LINK_SETTINGS = DEFAULT_LINK_SETTINGS;\n\nconst DeprecatedExperimentalLinkControl = ( props ) => {\n\tdeprecated( 'wp.blockEditor.__experimentalLinkControl', {\n\t\tsince: '6.8',\n\t\talternative: 'wp.blockEditor.LinkControl',\n\t} );\n\n\treturn <LinkControl { ...props } />;\n};\n\nDeprecatedExperimentalLinkControl.ViewerFill = LinkControl.ViewerFill;\nDeprecatedExperimentalLinkControl.DEFAULT_LINK_SETTINGS =\n\tLinkControl.DEFAULT_LINK_SETTINGS;\n\nexport { DeprecatedExperimentalLinkControl };\nexport default LinkControl;\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,wBAOO;AACP,kBAA4B;AAC5B,qBAAqD;AACrD,qBAA8B;AAC9B,iBAAsB;AACtB,sBAAsB;AACtB,8BAAsC;AACtC,kBAAuC;AACvC,yBAA0C;AAC1C,mBAAwC;AACxC,wBAAuB;AAKvB,6BAAsC;AACtC,0BAAmC;AACnC,0BAAwB;AACxB,sBAAyB;AACzB,6BAA0B;AAC1B,gCAA6B;AAC7B,yBAA2B;AAC3B,uBAAsC;AAwYlC;AA7TJ,IAAM,OAAO,MAAM;AAAC;AAEpB,IAAM,mBAAmB;AACzB,IAAM,iBAAiB;AASvB,SAAS,YAAa;AAAA,EACrB;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY,iBAAiB;AAAA,EAC7B,mBAAmB,CAAC;AAAA,EACpB,kBAAkB;AAAA,EAClB;AAAA,EACA,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,sBAAsB;AAAA,EACtB,iBAAiB;AAClB,GAAI;AACH,MAAK,yBAAyB,UAAa,kBAAmB;AAC7D,2BAAuB;AAAA,EACxB;AAEA,QAAM,CAAE,cAAc,eAAgB,QAAI,yBAA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,SAAS,oBAAqB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,MAAK,UAAW;AACf,WACC;AAAA,MAAC;AAAA;AAAA,QACA,MAAO;AAAA,QACP,SAAU;AAAA,QACV,oBAAmB;AAAA,QACnB,aAAW;AAAA,QACX,WAAQ,gBAAI,iBAAkB;AAAA,QAC9B,uBAAqB;AAAA;AAAA,IACtB;AAAA,EAEF;AAEA,MAAK,aAAc;AAClB,WAAO;AAAA,EACR;AAEA,SACC,4CAAC,kBAAAC,yCAAA,EAA0B,SAAQ,WAClC;AAAA,IAAC;AAAA;AAAA,MACA,SAAU,aAAa,OAAO;AAAA,MAC9B,WAAQ,gBAAI,QAAS;AAAA,MACrB,MAAO;AAAA,MACP,WAAU;AAAA,MACV,iBAAgB;AAAA,MAChB,MAAK;AAAA;AAAA,EACN,GACD;AAEF;AAEA,YAAY,aAAa;AACzB,YAAY,wBAAwB;AAEpC,IAAM,oCAAoC,CAAE,UAAW;AACtD,wBAAAC,SAAY,4CAA4C;AAAA,IACvD,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AAEF,SAAO,4CAAC,eAAc,GAAG,OAAQ;AAClC;AAEA,kCAAkC,aAAa,YAAY;AAC3D,kCAAkC,wBACjC,YAAY;AAGb,IAAO,uBAAQ;", "names": ["preferencesStore", "useInternalValue", "useCreatePage", "clsx", "LinkControlSearchInput", "LinkPreview", "LinkControlSettingsDrawer", "LinkSettings", "HStack", "InputControlSuffixWrapper", "deprecated"] }