: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
const partialRight = (fn, ...partialArgs) => (...args) => fn(...args, ...partialArgs);
const defaultTo = d => v => {
return v === null || v === undefined || v !== v ? d : v;
* Prepares a URL for display in the UI.
* - filters it (removes protocol, www, etc.).
* - truncates it if necessary.
* - adds a leading slash.
* @param {string} url the url.
* @return {string} the processed url to display.
function getURLForDisplay(url) {
return (0,external_wp_compose_namespaceObject.pipe)(external_wp_url_namespaceObject.safeDecodeURI, external_wp_url_namespaceObject.getPath, defaultTo(''), partialRight(external_wp_url_namespaceObject.filterURLForDisplay, 24), removeTrailingSlash, addLeadingSlash)(url);
const LinkControlSearchItem = ({
const info = isURL ? (0,external_wp_i18n_namespaceObject.__)('Press ENTER to add this link') : getURLForDisplay(suggestion.url);
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.MenuItem, {
icon: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(SearchItemIcon, {
shortcut: shouldShowType && getVisualTypeName(suggestion),
className: "block-editor-link-control__search-item",
children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.TextHighlight
// The component expects a plain text string.
text: (0,external_wp_dom_namespaceObject.__unstableStripHTML)(suggestion.title),
function getVisualTypeName(suggestion) {
if (suggestion.isFrontPage) {
if (suggestion.isBlogHome) {
// Rename 'post_tag' to 'tag'. Ideally, the API would return the localised CPT or taxonomy label.
return suggestion.type === 'post_tag' ? 'tag' : suggestion.type;
/* harmony default export */ const search_item = (LinkControlSearchItem);
;// CONCATENATED MODULE: ./node_modules/@wordpress/block-editor/build-module/components/link-control/constants.js
// Used as a unique identifier for the "Create" option within search results.
// Used to help distinguish the "Create" suggestion within the search results in
// order to handle it as a unique case.
const CREATE_TYPE = '__CREATE__';
const MAILTO_TYPE = 'mailto';
const INTERNAL_TYPE = 'internal';
const LINK_ENTRY_TYPES = [URL_TYPE, MAILTO_TYPE, TEL_TYPE, INTERNAL_TYPE];
const DEFAULT_LINK_SETTINGS = [{
title: (0,external_wp_i18n_namespaceObject.__)('Open in new tab')
;// CONCATENATED MODULE: ./node_modules/@wordpress/block-editor/build-module/components/link-control/search-results.js
function LinkControlSearchResults({
buildSuggestionItemProps,
createSuggestionButtonText,
const resultsListClasses = dist_clsx('block-editor-link-control__search-results', {
const isSingleDirectEntryResult = suggestions.length === 1 && LINK_ENTRY_TYPES.includes(suggestions[0].type);
const shouldShowCreateSuggestion = withCreateSuggestion && !isSingleDirectEntryResult && !isInitialSuggestions;
// If the query has a specified type, then we can skip showing them in the result. See #24839.
const shouldShowSuggestionsTypes = !suggestionsQuery?.type;
// According to guidelines aria-label should be added if the label
// itself is not visible.
// See: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role
const searchResultsLabelId = `block-editor-link-control-search-results-label-${instanceId}`;
const labelText = isInitialSuggestions ? (0,external_wp_i18n_namespaceObject.__)('Suggestions') : (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: search term. */
(0,external_wp_i18n_namespaceObject.__)('Search results for "%s"'), currentInputValue);
const searchResultsLabel = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.VisuallyHidden, {
id: searchResultsLabelId,
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
className: "block-editor-link-control__search-results-wrapper",
children: [searchResultsLabel, /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
className: resultsListClasses,
"aria-labelledby": searchResultsLabelId,
children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.MenuGroup, {
children: suggestions.map((suggestion, index) => {
if (shouldShowCreateSuggestion && CREATE_TYPE === suggestion.type) {
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(search_create_button, {
searchTerm: currentInputValue,
buttonText: createSuggestionButtonText,
onClick: () => handleSuggestionClick(suggestion)
// Intentionally only using `type` here as
// the constant is enough to uniquely
// identify the single "CREATE" suggestion.
itemProps: buildSuggestionItemProps(suggestion, index),
isSelected: index === selectedSuggestion
// If we're not handling "Create" suggestions above then
// we don't want them in the main results so exit early.
if (CREATE_TYPE === suggestion.type) {
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(search_item, {
itemProps: buildSuggestionItemProps(suggestion, index),
handleSuggestionClick(suggestion);
isSelected: index === selectedSuggestion,
isURL: LINK_ENTRY_TYPES.includes(suggestion.type),
searchTerm: currentInputValue,
shouldShowType: shouldShowSuggestionsTypes,
isFrontPage: suggestion?.isFrontPage,
isBlogHome: suggestion?.isBlogHome
}, `${suggestion.id}-${suggestion.type}`);
;// CONCATENATED MODULE: ./node_modules/@wordpress/block-editor/build-module/components/link-control/is-url-like.js
* Determines whether a given value could be a URL. Note this does not
* guarantee the value is a URL only that it looks like it might be one. For
* example, just because a string has `www.` in it doesn't make it a URL,
* but it does make it highly likely that it will be so in the context of
* creating a link it makes sense to treat it like one.
* @param {string} val the candidate for being URL-like (or not).
* @return {boolean} whether or not the value is potentially a URL.
function isURLLike(val) {
const hasSpaces = val.includes(' ');
const protocol = (0,external_wp_url_namespaceObject.getProtocol)(val);
const protocolIsValid = (0,external_wp_url_namespaceObject.isValidProtocol)(protocol);
const mayBeTLD = hasPossibleTLD(val);
const isWWW = val?.startsWith('www.');
const isInternal = val?.startsWith('#') && (0,external_wp_url_namespaceObject.isValidFragment)(val);
return protocolIsValid || isWWW || isInternal || mayBeTLD;
* Checks if a given URL has a valid Top-Level Domain (TLD).
* @param {string} url - The URL to check.
* @param {number} maxLength - The maximum length of the TLD.
* @return {boolean} Returns true if the URL has a valid TLD, false otherwise.
function hasPossibleTLD(url, maxLength = 6) {
// Clean the URL by removing anything after the first occurrence of "?" or "#".
const cleanedURL = url.split(/[?#]/)[0];
// Regular expression explanation:
// - (?<=\S) : Positive lookbehind assertion to ensure there is at least one non-whitespace character before the TLD
// - \. : Matches a literal dot (.)
// - [a-zA-Z_]{2,maxLength} : Matches 2 to maxLength letters or underscores, representing the TLD
// - (?:\/|$) : Non-capturing group that matches either a forward slash (/) or the end of the string
const regex = new RegExp(`(?<=\\S)\\.(?:[a-zA-Z_]{2,${maxLength}})(?:\\/|$)`);
return regex.test(cleanedURL);
;// CONCATENATED MODULE: ./node_modules/@wordpress/block-editor/build-module/components/link-control/use-search-handler.js
const handleNoop = () => Promise.resolve([]);
const handleDirectEntry = val => {
const protocol = (0,external_wp_url_namespaceObject.getProtocol)(val) || '';
if (protocol.includes('mailto')) {
if (protocol.includes('tel')) {
if (val?.startsWith('#')) {
return Promise.resolve([{
url: type === 'URL' ? (0,external_wp_url_namespaceObject.prependHTTP)(val) : val,
const handleEntitySearch = async (val, suggestionsQuery, fetchSearchSuggestions, withCreateSuggestion, pageOnFront, pageForPosts) => {
const results = await fetchSearchSuggestions(val, suggestionsQuery);
// Identify front page and update type to match.
if (Number(result.id) === pageOnFront) {
result.isFrontPage = true;
} else if (Number(result.id) === pageForPosts) {
result.isBlogHome = true;
// If displaying initial suggestions just return plain results.
if (isInitialSuggestions) {
// Here we append a faux suggestion to represent a "CREATE" option. This
// is detected in the rendering of the search results and handled as a
// special case. This is currently necessary because the suggestions
// dropdown will only appear if there are valid suggestions and
// therefore unless the create option is a suggestion it will not
// display in scenarios where there are no results returned from the
// API. In addition promoting CREATE to a first class suggestion affords
// the a11y benefits afforded by `URLInput` to all suggestions (eg:
// keyboard handling, ARIA roles...etc).
// Note also that the value of the `title` and `url` properties must correspond
// to the text value of the `<input>`. This is because `title` is used
// when creating the suggestion. Similarly `url` is used when using keyboard to select
// the suggestion (the <form> `onSubmit` handler falls-back to `url`).
return isURLLike(val) || !withCreateSuggestion ? results : results.concat({
// the `id` prop is intentionally ommitted here because it
// is never exposed as part of the component's public API.
// see: https://github.com/WordPress/gutenberg/pull/19775#discussion_r378931316.
// Must match the existing `<input>`s text value.
// Must match the existing `<input>`s text value.
function useSearchHandler(suggestionsQuery, allowDirectEntry, withCreateSuggestion) {
} = (0,external_wp_data_namespaceObject.useSelect)(select => {
pageOnFront: getSettings().pageOnFront,
pageForPosts: getSettings().pageForPosts,
fetchSearchSuggestions: getSettings().__experimentalFetchLinkSuggestions
const directEntryHandler = allowDirectEntry ? handleDirectEntry : handleNoop;
return (0,external_wp_element_namespaceObject.useCallback)((val, {
return isURLLike(val) ? directEntryHandler(val, {
}) : handleEntitySearch(val, {
}, fetchSearchSuggestions, withCreateSuggestion, pageOnFront, pageForPosts);
}, [directEntryHandler, fetchSearchSuggestions, pageOnFront, pageForPosts, suggestionsQuery, withCreateSuggestion]);
;// CONCATENATED MODULE: ./node_modules/@wordpress/block-editor/build-module/components/link-control/search-input.js
// Must be a function as otherwise URLInput will default
// to the fetchLinkSuggestions passed in block editor settings
// which will cause an unintended http request.
const noopSearchHandler = () => Promise.resolve([]);
const LinkControlSearchInput = (0,external_wp_element_namespaceObject.forwardRef)(({
withCreateSuggestion = false,
onCreateSuggestion = noop,
renderSuggestions = props => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(LinkControlSearchResults, {
showInitialSuggestions = false,
withURLSuggestion = true,
createSuggestionButtonText,
hideLabelFromVision = false
const genericSearchHandler = useSearchHandler(suggestionsQuery, allowDirectEntry, withCreateSuggestion, withURLSuggestion);
const searchHandler = showSuggestions ? fetchSuggestions || genericSearchHandler : noopSearchHandler;
const instanceId = (0,external_wp_compose_namespaceObject.useInstanceId)(LinkControlSearchInput);
const [focusedSuggestion, setFocusedSuggestion] = (0,external_wp_element_namespaceObject.useState)();
* Handles the user moving between different suggestions. Does not handle
* choosing an individual item.
* @param {string} selection the url of the selected suggestion.
* @param {Object} suggestion the suggestion object.
const onInputChange = (selection, suggestion) => {
setFocusedSuggestion(suggestion);
const handleRenderSuggestions = props => renderSuggestions({
createSuggestionButtonText,
handleSuggestionClick: suggestion => {
if (props.handleSuggestionClick) {
props.handleSuggestionClick(suggestion);
onSuggestionSelected(suggestion);
const onSuggestionSelected = async selectedSuggestion => {
let suggestion = selectedSuggestion;
if (CREATE_TYPE === selectedSuggestion.type) {
// Create a new page and call onSelect with the output from the onCreateSuggestion callback.
suggestion = await onCreateSuggestion(selectedSuggestion.title);
if (allowDirectEntry || suggestion && Object.keys(suggestion).length >= 1) {
} = currentLink !== null && currentLink !== void 0 ? currentLink : {};
// Some direct entries don't have types or IDs, and we still need to clear the previous ones.
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
className: "block-editor-link-control__search-input-container",
children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(url_input, {
disableSuggestions: currentLink?.url === value,
__nextHasNoMarginBottom: true,
label: (0,external_wp_i18n_namespaceObject.__)('Link'),
hideLabelFromVision: hideLabelFromVision,
placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : (0,external_wp_i18n_namespaceObject.__)('Search or type URL'),
__experimentalRenderSuggestions: showSuggestions ? handleRenderSuggestions : null,
__experimentalFetchLinkSuggestions: searchHandler,
__experimentalHandleURLSuggestions: true,
__experimentalShowInitialSuggestions: showInitialSuggestions,
onSubmit: (suggestion, event) => {
const hasSuggestion = suggestion || focusedSuggestion;
// If there is no suggestion and the value (ie: any manually entered URL) is empty
// then don't allow submission otherwise we get empty links.
if (!hasSuggestion && !value?.trim()?.length) {
onSuggestionSelected(hasSuggestion || {
/* harmony default export */ const search_input = (LinkControlSearchInput);
;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/info.js
const info = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
xmlns: "http://www.w3.org/2000/svg",
children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
d: "M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"
/* harmony default export */ const library_info = (info);
;// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/pencil.js
const pencil = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
xmlns: "http://www.w3.org/2000/svg",