@wordpress/format-library 4.18.1-next.5a1d1283.0 → 4.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.19.0 (2023-09-20)
6
+
5
7
  ## 4.18.0 (2023-08-31)
6
8
 
7
9
  ## 4.17.0 (2023-08-16)
@@ -26,9 +26,7 @@ var _useLinkInstanceKey = _interopRequireDefault(require("./use-link-instance-ke
26
26
 
27
27
  const LINK_SETTINGS = [..._blockEditor.__experimentalLinkControl.DEFAULT_LINK_SETTINGS, {
28
28
  id: 'nofollow',
29
- title: (0, _element.createInterpolateElement)((0, _i18n.__)('Mark as <code>nofollow</code>'), {
30
- code: (0, _element.createElement)("code", null)
31
- })
29
+ title: (0, _i18n.__)('Mark as nofollow')
32
30
  }];
33
31
  function InlineLinkUI({
34
32
  isActive,
@@ -56,14 +54,14 @@ function InlineLinkUI({
56
54
  userCanCreatePages: _settings.__experimentalUserCanCreatePages
57
55
  };
58
56
  }, []);
59
- const linkValue = {
57
+ const linkValue = (0, _element.useMemo)(() => ({
60
58
  url: activeAttributes.url,
61
59
  type: activeAttributes.type,
62
60
  id: activeAttributes.id,
63
61
  opensInNewTab: activeAttributes.target === '_blank',
64
62
  nofollow: activeAttributes.rel?.includes('nofollow'),
65
63
  title: richTextText
66
- };
64
+ }), [activeAttributes.id, activeAttributes.rel, activeAttributes.target, activeAttributes.type, activeAttributes.url, richTextText]);
67
65
  function removeLink() {
68
66
  const newValue = (0, _richText.removeFormat)(value, 'core/link');
69
67
  onChange(newValue);
@@ -169,7 +167,11 @@ function InlineLinkUI({
169
167
  // See https://github.com/WordPress/gutenberg/pull/34742.
170
168
  const forceRemountKey = (0, _useLinkInstanceKey.default)(popoverAnchor);
171
169
 
172
- // The focusOnMount prop shouldn't evolve during render of a Popover
170
+ // Focus should only be moved into the Popover when the Link is being created or edited.
171
+ // When the Link is in "preview" mode focus should remain on the rich text because at
172
+ // this point the Link dialog is informational only and thus the user should be able to
173
+ // continue editing the rich text.
174
+ // Ref used because the focusOnMount prop shouldn't evolve during render of a Popover
173
175
  // otherwise it causes a render of the content.
174
176
  const focusOnMount = (0, _element.useRef)(addingLink ? 'firstElement' : false);
175
177
  async function handleCreate(pageTitle) {
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_i18n","_a11y","_components","_url","_richText","_blockEditor","_data","_utils","_index","_useLinkInstanceKey","_interopRequireDefault","LINK_SETTINGS","LinkControl","DEFAULT_LINK_SETTINGS","id","title","createInterpolateElement","__","code","createElement","InlineLinkUI","isActive","activeAttributes","addingLink","value","onChange","stopAddingLink","contentRef","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","createPageEntity","userCanCreatePages","useSelect","select","getSettings","blockEditorStore","_settings","__experimentalCreatePageEntity","__experimentalUserCanCreatePages","linkValue","url","type","opensInNewTab","target","nofollow","rel","includes","removeLink","newValue","removeFormat","speak","onChangeLink","nextValue","didToggleSetting","undefined","newUrl","prependHTTP","linkFormat","createLinkFormat","String","opensInNewWindow","newText","isCollapsed","toInsert","applyFormat","create","length","insert","boundary","getFormatBoundary","valBefore","valAfter","split","start","newValAfter","replace","concat","end","activeFormats","isValidHref","popoverAnchor","useAnchor","editableContentElement","current","settings","forceRemountKey","useLinkInstanceKey","focusOnMount","useRef","handleCreate","pageTitle","page","status","rendered","link","kind","createButtonText","searchTerm","sprintf","mark","Popover","anchor","onClose","onFocusOutside","placement","shift","__experimentalLinkControl","key","onRemove","forceIsEditingLink","hasRichPreviews","createSuggestion","withCreateSuggestion","createSuggestionButtonText","hasTextControl","textStart","textEnd","slice","_default","exports","default"],"sources":["@wordpress/format-library/src/link/inline.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, createInterpolateElement } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { speak } from '@wordpress/a11y';\nimport { Popover } from '@wordpress/components';\nimport { prependHTTP } from '@wordpress/url';\nimport {\n\tcreate,\n\tinsert,\n\tisCollapsed,\n\tapplyFormat,\n\tuseAnchor,\n\tremoveFormat,\n\tslice,\n\treplace,\n\tsplit,\n\tconcat,\n} from '@wordpress/rich-text';\nimport {\n\t__experimentalLinkControl as LinkControl,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { createLinkFormat, isValidHref, getFormatBoundary } from './utils';\nimport { link as settings } from './index';\nimport useLinkInstanceKey from './use-link-instance-key';\n\nconst LINK_SETTINGS = [\n\t...LinkControl.DEFAULT_LINK_SETTINGS,\n\t{\n\t\tid: 'nofollow',\n\t\ttitle: createInterpolateElement(\n\t\t\t__( 'Mark as <code>nofollow</code>' ),\n\t\t\t{ code: <code /> }\n\t\t),\n\t},\n];\n\nfunction InlineLinkUI( {\n\tisActive,\n\tactiveAttributes,\n\taddingLink,\n\tvalue,\n\tonChange,\n\tstopAddingLink,\n\tcontentRef,\n} ) {\n\tconst richLinkTextValue = getRichTextValueFromSelection( value, isActive );\n\n\t// Get the text content minus any HTML tags.\n\tconst richTextText = richLinkTextValue.text;\n\n\tconst { createPageEntity, userCanCreatePages } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst _settings = getSettings();\n\n\t\treturn {\n\t\t\tcreatePageEntity: _settings.__experimentalCreatePageEntity,\n\t\t\tuserCanCreatePages: _settings.__experimentalUserCanCreatePages,\n\t\t};\n\t}, [] );\n\n\tconst linkValue = {\n\t\turl: activeAttributes.url,\n\t\ttype: activeAttributes.type,\n\t\tid: activeAttributes.id,\n\t\topensInNewTab: activeAttributes.target === '_blank',\n\t\tnofollow: activeAttributes.rel?.includes( 'nofollow' ),\n\t\ttitle: richTextText,\n\t};\n\n\tfunction removeLink() {\n\t\tconst newValue = removeFormat( value, 'core/link' );\n\t\tonChange( newValue );\n\t\tstopAddingLink();\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\tfunction onChangeLink( nextValue ) {\n\t\t// LinkControl calls `onChange` immediately upon the toggling a setting.\n\t\t// Before merging the next value with the current link value, check if\n\t\t// the setting was toggled.\n\t\tconst didToggleSetting =\n\t\t\tlinkValue.opensInNewTab !== nextValue.opensInNewTab &&\n\t\t\tnextValue.url === undefined;\n\t\t// Merge the next value with the current link value.\n\t\tnextValue = {\n\t\t\t...linkValue,\n\t\t\t...nextValue,\n\t\t};\n\n\t\tconst newUrl = prependHTTP( nextValue.url );\n\t\tconst linkFormat = createLinkFormat( {\n\t\t\turl: newUrl,\n\t\t\ttype: nextValue.type,\n\t\t\tid:\n\t\t\t\tnextValue.id !== undefined && nextValue.id !== null\n\t\t\t\t\t? String( nextValue.id )\n\t\t\t\t\t: undefined,\n\t\t\topensInNewWindow: nextValue.opensInNewTab,\n\t\t\tnofollow: nextValue.nofollow,\n\t\t} );\n\n\t\tconst newText = nextValue.title || newUrl;\n\n\t\tif ( isCollapsed( value ) && ! isActive ) {\n\t\t\t// Scenario: we don't have any actively selected text or formats.\n\t\t\tconst toInsert = applyFormat(\n\t\t\t\tcreate( { text: newText } ),\n\t\t\t\tlinkFormat,\n\t\t\t\t0,\n\t\t\t\tnewText.length\n\t\t\t);\n\t\t\tonChange( insert( value, toInsert ) );\n\t\t} else {\n\t\t\t// Scenario: we have any active text selection or an active format.\n\t\t\tlet newValue;\n\n\t\t\tif ( newText === richTextText ) {\n\t\t\t\t// If we're not updating the text then ignore.\n\t\t\t\tnewValue = applyFormat( value, linkFormat );\n\t\t\t} else {\n\t\t\t\t// Create new RichText value for the new text in order that we\n\t\t\t\t// can apply formats to it.\n\t\t\t\tnewValue = create( { text: newText } );\n\n\t\t\t\t// Apply the new Link format to this new text value.\n\t\t\t\tnewValue = applyFormat(\n\t\t\t\t\tnewValue,\n\t\t\t\t\tlinkFormat,\n\t\t\t\t\t0,\n\t\t\t\t\tnewText.length\n\t\t\t\t);\n\n\t\t\t\t// Get the boundaries of the active link format.\n\t\t\t\tconst boundary = getFormatBoundary( value, {\n\t\t\t\t\ttype: 'core/link',\n\t\t\t\t} );\n\n\t\t\t\t// Split the value at the start of the active link format.\n\t\t\t\t// Passing \"start\" as the 3rd parameter is required to ensure\n\t\t\t\t// the second half of the split value is split at the format's\n\t\t\t\t// start boundary and avoids relying on the value's \"end\" property\n\t\t\t\t// which may not correspond correctly.\n\t\t\t\tconst [ valBefore, valAfter ] = split(\n\t\t\t\t\tvalue,\n\t\t\t\t\tboundary.start,\n\t\t\t\t\tboundary.start\n\t\t\t\t);\n\n\t\t\t\t// Update the original (full) RichTextValue replacing the\n\t\t\t\t// target text with the *new* RichTextValue containing:\n\t\t\t\t// 1. The new text content.\n\t\t\t\t// 2. The new link format.\n\t\t\t\t// As \"replace\" will operate on the first match only, it is\n\t\t\t\t// run only against the second half of the value which was\n\t\t\t\t// split at the active format's boundary. This avoids a bug\n\t\t\t\t// with incorrectly targetted replacements.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/issues/41771.\n\t\t\t\t// Note original formats will be lost when applying this change.\n\t\t\t\t// That is expected behaviour.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.\n\t\t\t\tconst newValAfter = replace( valAfter, richTextText, newValue );\n\n\t\t\t\tnewValue = concat( valBefore, newValAfter );\n\t\t\t}\n\n\t\t\tnewValue.start = newValue.end;\n\n\t\t\t// Hides the Link UI.\n\t\t\tnewValue.activeFormats = [];\n\t\t\tonChange( newValue );\n\t\t}\n\n\t\t// Focus should only be shifted back to the formatted segment when the\n\t\t// URL is submitted.\n\t\tif ( ! didToggleSetting ) {\n\t\t\tstopAddingLink();\n\t\t}\n\n\t\tif ( ! isValidHref( newUrl ) ) {\n\t\t\tspeak(\n\t\t\t\t__(\n\t\t\t\t\t'Warning: the link has been inserted but may have errors. Please test it.'\n\t\t\t\t),\n\t\t\t\t'assertive'\n\t\t\t);\n\t\t} else if ( isActive ) {\n\t\t\tspeak( __( 'Link edited.' ), 'assertive' );\n\t\t} else {\n\t\t\tspeak( __( 'Link inserted.' ), 'assertive' );\n\t\t}\n\t}\n\n\tconst popoverAnchor = useAnchor( {\n\t\teditableContentElement: contentRef.current,\n\t\tsettings,\n\t} );\n\n\t// Generate a string based key that is unique to this anchor reference.\n\t// This is used to force re-mount the LinkControl component to avoid\n\t// potential stale state bugs caused by the component not being remounted\n\t// See https://github.com/WordPress/gutenberg/pull/34742.\n\tconst forceRemountKey = useLinkInstanceKey( popoverAnchor );\n\n\t// The focusOnMount prop shouldn't evolve during render of a Popover\n\t// otherwise it causes a render of the content.\n\tconst focusOnMount = useRef( addingLink ? 'firstElement' : false );\n\n\tasync function handleCreate( pageTitle ) {\n\t\tconst page = await createPageEntity( {\n\t\t\ttitle: pageTitle,\n\t\t\tstatus: 'draft',\n\t\t} );\n\n\t\treturn {\n\t\t\tid: page.id,\n\t\t\ttype: page.type,\n\t\t\ttitle: page.title.rendered,\n\t\t\turl: page.link,\n\t\t\tkind: 'post-type',\n\t\t};\n\t}\n\n\tfunction createButtonText( searchTerm ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %s: search term. */\n\t\t\t\t__( 'Create page: <mark>%s</mark>' ),\n\t\t\t\tsearchTerm\n\t\t\t),\n\t\t\t{ mark: <mark /> }\n\t\t);\n\t}\n\n\treturn (\n\t\t<Popover\n\t\t\tanchor={ popoverAnchor }\n\t\t\tfocusOnMount={ focusOnMount.current }\n\t\t\tonClose={ stopAddingLink }\n\t\t\tonFocusOutside={ () => stopAddingLink( false ) }\n\t\t\tplacement=\"bottom\"\n\t\t\tshift\n\t\t>\n\t\t\t<LinkControl\n\t\t\t\tkey={ forceRemountKey }\n\t\t\t\tvalue={ linkValue }\n\t\t\t\tonChange={ onChangeLink }\n\t\t\t\tonRemove={ removeLink }\n\t\t\t\tforceIsEditingLink={ addingLink }\n\t\t\t\thasRichPreviews\n\t\t\t\tcreateSuggestion={ createPageEntity && handleCreate }\n\t\t\t\twithCreateSuggestion={ userCanCreatePages }\n\t\t\t\tcreateSuggestionButtonText={ createButtonText }\n\t\t\t\thasTextControl\n\t\t\t\tsettings={ LINK_SETTINGS }\n\t\t\t/>\n\t\t</Popover>\n\t);\n}\n\nfunction getRichTextValueFromSelection( value, isActive ) {\n\t// Default to the selection ranges on the RichTextValue object.\n\tlet textStart = value.start;\n\tlet textEnd = value.end;\n\n\t// If the format is currently active then the rich text value\n\t// should always be taken from the bounds of the active format\n\t// and not the selected text.\n\tif ( isActive ) {\n\t\tconst boundary = getFormatBoundary( value, {\n\t\t\ttype: 'core/link',\n\t\t} );\n\n\t\ttextStart = boundary.start;\n\n\t\t// Text *selection* always extends +1 beyond the edge of the format.\n\t\t// We account for that here.\n\t\ttextEnd = boundary.end + 1;\n\t}\n\n\t// Get a RichTextValue containing the selected text content.\n\treturn slice( value, textStart, textEnd );\n}\n\nexport default InlineLinkUI;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AAYA,IAAAM,YAAA,GAAAN,OAAA;AAIA,IAAAO,KAAA,GAAAP,OAAA;AAKA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,MAAA,GAAAT,OAAA;AACA,IAAAU,mBAAA,GAAAC,sBAAA,CAAAX,OAAA;AA/BA;AACA;AACA;;AAwBA;AACA;AACA;;AAKA,MAAMY,aAAa,GAAG,CACrB,GAAGC,sCAAW,CAACC,qBAAqB,EACpC;EACCC,EAAE,EAAE,UAAU;EACdC,KAAK,EAAE,IAAAC,iCAAwB,EAC9B,IAAAC,QAAE,EAAE,+BAAgC,CAAC,EACrC;IAAEC,IAAI,EAAE,IAAApB,QAAA,CAAAqB,aAAA,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EAACd,YAAA,CAAAuG,yBAAW;IACXC,GAAG,EAAGtB,eAAiB;IACvB/D,KAAK,EAAGiB,SAAW;IACnBhB,QAAQ,EAAG4B,YAAc;IACzByD,QAAQ,EAAG7D,UAAY;IACvB8D,kBAAkB,EAAGxF,UAAY;IACjCyF,eAAe;IACfC,gBAAgB,EAAGjF,gBAAgB,IAAI2D,YAAc;IACrDuB,oBAAoB,EAAGjF,kBAAoB;IAC3CkF,0BAA0B,EAAGjB,gBAAkB;IAC/CkB,cAAc;IACd9B,QAAQ,EAAG3E;EAAe,CAC1B,CACO,CAAC;AAEZ;AAEA,SAASkB,6BAA6BA,CAAEL,KAAK,EAAEH,QAAQ,EAAG;EACzD;EACA,IAAIgG,SAAS,GAAG7F,KAAK,CAACmD,KAAK;EAC3B,IAAI2C,OAAO,GAAG9F,KAAK,CAACuD,GAAG;;EAEvB;EACA;EACA;EACA,IAAK1D,QAAQ,EAAG;IACf,MAAMiD,QAAQ,GAAG,IAAAC,wBAAiB,EAAE/C,KAAK,EAAE;MAC1CmB,IAAI,EAAE;IACP,CAAE,CAAC;IAEH0E,SAAS,GAAG/C,QAAQ,CAACK,KAAK;;IAE1B;IACA;IACA2C,OAAO,GAAGhD,QAAQ,CAACS,GAAG,GAAG,CAAC;EAC3B;;EAEA;EACA,OAAO,IAAAwC,eAAK,EAAE/F,KAAK,EAAE6F,SAAS,EAAEC,OAAQ,CAAC;AAC1C;AAAC,IAAAE,QAAA,GAEcpG,YAAY;AAAAqG,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
1
+ {"version":3,"names":["_element","require","_i18n","_a11y","_components","_url","_richText","_blockEditor","_data","_utils","_index","_useLinkInstanceKey","_interopRequireDefault","LINK_SETTINGS","LinkControl","DEFAULT_LINK_SETTINGS","id","title","__","InlineLinkUI","isActive","activeAttributes","addingLink","value","onChange","stopAddingLink","contentRef","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","createPageEntity","userCanCreatePages","useSelect","select","getSettings","blockEditorStore","_settings","__experimentalCreatePageEntity","__experimentalUserCanCreatePages","linkValue","useMemo","url","type","opensInNewTab","target","nofollow","rel","includes","removeLink","newValue","removeFormat","speak","onChangeLink","nextValue","didToggleSetting","undefined","newUrl","prependHTTP","linkFormat","createLinkFormat","String","opensInNewWindow","newText","isCollapsed","toInsert","applyFormat","create","length","insert","boundary","getFormatBoundary","valBefore","valAfter","split","start","newValAfter","replace","concat","end","activeFormats","isValidHref","popoverAnchor","useAnchor","editableContentElement","current","settings","forceRemountKey","useLinkInstanceKey","focusOnMount","useRef","handleCreate","pageTitle","page","status","rendered","link","kind","createButtonText","searchTerm","createInterpolateElement","sprintf","mark","createElement","Popover","anchor","onClose","onFocusOutside","placement","shift","__experimentalLinkControl","key","onRemove","forceIsEditingLink","hasRichPreviews","createSuggestion","withCreateSuggestion","createSuggestionButtonText","hasTextControl","textStart","textEnd","slice","_default","exports","default"],"sources":["@wordpress/format-library/src/link/inline.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useRef, createInterpolateElement } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { speak } from '@wordpress/a11y';\nimport { Popover } from '@wordpress/components';\nimport { prependHTTP } from '@wordpress/url';\nimport {\n\tcreate,\n\tinsert,\n\tisCollapsed,\n\tapplyFormat,\n\tuseAnchor,\n\tremoveFormat,\n\tslice,\n\treplace,\n\tsplit,\n\tconcat,\n} from '@wordpress/rich-text';\nimport {\n\t__experimentalLinkControl as LinkControl,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { createLinkFormat, isValidHref, getFormatBoundary } from './utils';\nimport { link as settings } from './index';\nimport useLinkInstanceKey from './use-link-instance-key';\n\nconst LINK_SETTINGS = [\n\t...LinkControl.DEFAULT_LINK_SETTINGS,\n\t{\n\t\tid: 'nofollow',\n\t\ttitle: __( 'Mark as nofollow' ),\n\t},\n];\n\nfunction InlineLinkUI( {\n\tisActive,\n\tactiveAttributes,\n\taddingLink,\n\tvalue,\n\tonChange,\n\tstopAddingLink,\n\tcontentRef,\n} ) {\n\tconst richLinkTextValue = getRichTextValueFromSelection( value, isActive );\n\n\t// Get the text content minus any HTML tags.\n\tconst richTextText = richLinkTextValue.text;\n\n\tconst { createPageEntity, userCanCreatePages } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst _settings = getSettings();\n\n\t\treturn {\n\t\t\tcreatePageEntity: _settings.__experimentalCreatePageEntity,\n\t\t\tuserCanCreatePages: _settings.__experimentalUserCanCreatePages,\n\t\t};\n\t}, [] );\n\n\tconst linkValue = useMemo(\n\t\t() => ( {\n\t\t\turl: activeAttributes.url,\n\t\t\ttype: activeAttributes.type,\n\t\t\tid: activeAttributes.id,\n\t\t\topensInNewTab: activeAttributes.target === '_blank',\n\t\t\tnofollow: activeAttributes.rel?.includes( 'nofollow' ),\n\t\t\ttitle: richTextText,\n\t\t} ),\n\t\t[\n\t\t\tactiveAttributes.id,\n\t\t\tactiveAttributes.rel,\n\t\t\tactiveAttributes.target,\n\t\t\tactiveAttributes.type,\n\t\t\tactiveAttributes.url,\n\t\t\trichTextText,\n\t\t]\n\t);\n\n\tfunction removeLink() {\n\t\tconst newValue = removeFormat( value, 'core/link' );\n\t\tonChange( newValue );\n\t\tstopAddingLink();\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\tfunction onChangeLink( nextValue ) {\n\t\t// LinkControl calls `onChange` immediately upon the toggling a setting.\n\t\t// Before merging the next value with the current link value, check if\n\t\t// the setting was toggled.\n\t\tconst didToggleSetting =\n\t\t\tlinkValue.opensInNewTab !== nextValue.opensInNewTab &&\n\t\t\tnextValue.url === undefined;\n\t\t// Merge the next value with the current link value.\n\t\tnextValue = {\n\t\t\t...linkValue,\n\t\t\t...nextValue,\n\t\t};\n\n\t\tconst newUrl = prependHTTP( nextValue.url );\n\t\tconst linkFormat = createLinkFormat( {\n\t\t\turl: newUrl,\n\t\t\ttype: nextValue.type,\n\t\t\tid:\n\t\t\t\tnextValue.id !== undefined && nextValue.id !== null\n\t\t\t\t\t? String( nextValue.id )\n\t\t\t\t\t: undefined,\n\t\t\topensInNewWindow: nextValue.opensInNewTab,\n\t\t\tnofollow: nextValue.nofollow,\n\t\t} );\n\n\t\tconst newText = nextValue.title || newUrl;\n\n\t\tif ( isCollapsed( value ) && ! isActive ) {\n\t\t\t// Scenario: we don't have any actively selected text or formats.\n\t\t\tconst toInsert = applyFormat(\n\t\t\t\tcreate( { text: newText } ),\n\t\t\t\tlinkFormat,\n\t\t\t\t0,\n\t\t\t\tnewText.length\n\t\t\t);\n\t\t\tonChange( insert( value, toInsert ) );\n\t\t} else {\n\t\t\t// Scenario: we have any active text selection or an active format.\n\t\t\tlet newValue;\n\n\t\t\tif ( newText === richTextText ) {\n\t\t\t\t// If we're not updating the text then ignore.\n\t\t\t\tnewValue = applyFormat( value, linkFormat );\n\t\t\t} else {\n\t\t\t\t// Create new RichText value for the new text in order that we\n\t\t\t\t// can apply formats to it.\n\t\t\t\tnewValue = create( { text: newText } );\n\n\t\t\t\t// Apply the new Link format to this new text value.\n\t\t\t\tnewValue = applyFormat(\n\t\t\t\t\tnewValue,\n\t\t\t\t\tlinkFormat,\n\t\t\t\t\t0,\n\t\t\t\t\tnewText.length\n\t\t\t\t);\n\n\t\t\t\t// Get the boundaries of the active link format.\n\t\t\t\tconst boundary = getFormatBoundary( value, {\n\t\t\t\t\ttype: 'core/link',\n\t\t\t\t} );\n\n\t\t\t\t// Split the value at the start of the active link format.\n\t\t\t\t// Passing \"start\" as the 3rd parameter is required to ensure\n\t\t\t\t// the second half of the split value is split at the format's\n\t\t\t\t// start boundary and avoids relying on the value's \"end\" property\n\t\t\t\t// which may not correspond correctly.\n\t\t\t\tconst [ valBefore, valAfter ] = split(\n\t\t\t\t\tvalue,\n\t\t\t\t\tboundary.start,\n\t\t\t\t\tboundary.start\n\t\t\t\t);\n\n\t\t\t\t// Update the original (full) RichTextValue replacing the\n\t\t\t\t// target text with the *new* RichTextValue containing:\n\t\t\t\t// 1. The new text content.\n\t\t\t\t// 2. The new link format.\n\t\t\t\t// As \"replace\" will operate on the first match only, it is\n\t\t\t\t// run only against the second half of the value which was\n\t\t\t\t// split at the active format's boundary. This avoids a bug\n\t\t\t\t// with incorrectly targetted replacements.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/issues/41771.\n\t\t\t\t// Note original formats will be lost when applying this change.\n\t\t\t\t// That is expected behaviour.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.\n\t\t\t\tconst newValAfter = replace( valAfter, richTextText, newValue );\n\n\t\t\t\tnewValue = concat( valBefore, newValAfter );\n\t\t\t}\n\n\t\t\tnewValue.start = newValue.end;\n\n\t\t\t// Hides the Link UI.\n\t\t\tnewValue.activeFormats = [];\n\t\t\tonChange( newValue );\n\t\t}\n\n\t\t// Focus should only be shifted back to the formatted segment when the\n\t\t// URL is submitted.\n\t\tif ( ! didToggleSetting ) {\n\t\t\tstopAddingLink();\n\t\t}\n\n\t\tif ( ! isValidHref( newUrl ) ) {\n\t\t\tspeak(\n\t\t\t\t__(\n\t\t\t\t\t'Warning: the link has been inserted but may have errors. Please test it.'\n\t\t\t\t),\n\t\t\t\t'assertive'\n\t\t\t);\n\t\t} else if ( isActive ) {\n\t\t\tspeak( __( 'Link edited.' ), 'assertive' );\n\t\t} else {\n\t\t\tspeak( __( 'Link inserted.' ), 'assertive' );\n\t\t}\n\t}\n\n\tconst popoverAnchor = useAnchor( {\n\t\teditableContentElement: contentRef.current,\n\t\tsettings,\n\t} );\n\n\t// Generate a string based key that is unique to this anchor reference.\n\t// This is used to force re-mount the LinkControl component to avoid\n\t// potential stale state bugs caused by the component not being remounted\n\t// See https://github.com/WordPress/gutenberg/pull/34742.\n\tconst forceRemountKey = useLinkInstanceKey( popoverAnchor );\n\n\t// Focus should only be moved into the Popover when the Link is being created or edited.\n\t// When the Link is in \"preview\" mode focus should remain on the rich text because at\n\t// this point the Link dialog is informational only and thus the user should be able to\n\t// continue editing the rich text.\n\t// Ref used because the focusOnMount prop shouldn't evolve during render of a Popover\n\t// otherwise it causes a render of the content.\n\tconst focusOnMount = useRef( addingLink ? 'firstElement' : false );\n\n\tasync function handleCreate( pageTitle ) {\n\t\tconst page = await createPageEntity( {\n\t\t\ttitle: pageTitle,\n\t\t\tstatus: 'draft',\n\t\t} );\n\n\t\treturn {\n\t\t\tid: page.id,\n\t\t\ttype: page.type,\n\t\t\ttitle: page.title.rendered,\n\t\t\turl: page.link,\n\t\t\tkind: 'post-type',\n\t\t};\n\t}\n\n\tfunction createButtonText( searchTerm ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %s: search term. */\n\t\t\t\t__( 'Create page: <mark>%s</mark>' ),\n\t\t\t\tsearchTerm\n\t\t\t),\n\t\t\t{ mark: <mark /> }\n\t\t);\n\t}\n\n\treturn (\n\t\t<Popover\n\t\t\tanchor={ popoverAnchor }\n\t\t\tfocusOnMount={ focusOnMount.current }\n\t\t\tonClose={ stopAddingLink }\n\t\t\tonFocusOutside={ () => stopAddingLink( false ) }\n\t\t\tplacement=\"bottom\"\n\t\t\tshift\n\t\t>\n\t\t\t<LinkControl\n\t\t\t\tkey={ forceRemountKey }\n\t\t\t\tvalue={ linkValue }\n\t\t\t\tonChange={ onChangeLink }\n\t\t\t\tonRemove={ removeLink }\n\t\t\t\tforceIsEditingLink={ addingLink }\n\t\t\t\thasRichPreviews\n\t\t\t\tcreateSuggestion={ createPageEntity && handleCreate }\n\t\t\t\twithCreateSuggestion={ userCanCreatePages }\n\t\t\t\tcreateSuggestionButtonText={ createButtonText }\n\t\t\t\thasTextControl\n\t\t\t\tsettings={ LINK_SETTINGS }\n\t\t\t/>\n\t\t</Popover>\n\t);\n}\n\nfunction getRichTextValueFromSelection( value, isActive ) {\n\t// Default to the selection ranges on the RichTextValue object.\n\tlet textStart = value.start;\n\tlet textEnd = value.end;\n\n\t// If the format is currently active then the rich text value\n\t// should always be taken from the bounds of the active format\n\t// and not the selected text.\n\tif ( isActive ) {\n\t\tconst boundary = getFormatBoundary( value, {\n\t\t\ttype: 'core/link',\n\t\t} );\n\n\t\ttextStart = boundary.start;\n\n\t\t// Text *selection* always extends +1 beyond the edge of the format.\n\t\t// We account for that here.\n\t\ttextEnd = boundary.end + 1;\n\t}\n\n\t// Get a RichTextValue containing the selected text content.\n\treturn slice( value, textStart, textEnd );\n}\n\nexport default InlineLinkUI;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AAYA,IAAAM,YAAA,GAAAN,OAAA;AAIA,IAAAO,KAAA,GAAAP,OAAA;AAKA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,MAAA,GAAAT,OAAA;AACA,IAAAU,mBAAA,GAAAC,sBAAA,CAAAX,OAAA;AA/BA;AACA;AACA;;AAwBA;AACA;AACA;;AAKA,MAAMY,aAAa,GAAG,CACrB,GAAGC,sCAAW,CAACC,qBAAqB,EACpC;EACCC,EAAE,EAAE,UAAU;EACdC,KAAK,EAAE,IAAAC,QAAE,EAAE,kBAAmB;AAC/B,CAAC,CACD;AAED,SAASC,YAAYA,CAAE;EACtBC,QAAQ;EACRC,gBAAgB;EAChBC,UAAU;EACVC,KAAK;EACLC,QAAQ;EACRC,cAAc;EACdC;AACD,CAAC,EAAG;EACH,MAAMC,iBAAiB,GAAGC,6BAA6B,CAAEL,KAAK,EAAEH,QAAS,CAAC;;EAE1E;EACA,MAAMS,YAAY,GAAGF,iBAAiB,CAACG,IAAI;EAE3C,MAAM;IAAEC,gBAAgB;IAAEC;EAAmB,CAAC,GAAG,IAAAC,eAAS,EAAI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Q,EAAG/D,UAAY;IACvBgE,kBAAkB,EAAG3F,UAAY;IACjC4F,eAAe;IACfC,gBAAgB,EAAGpF,gBAAgB,IAAI4D,YAAc;IACrDyB,oBAAoB,EAAGpF,kBAAoB;IAC3CqF,0BAA0B,EAAGnB,gBAAkB;IAC/CoB,cAAc;IACdhC,QAAQ,EAAGzE;EAAe,CAC1B,CACO,CAAC;AAEZ;AAEA,SAASe,6BAA6BA,CAAEL,KAAK,EAAEH,QAAQ,EAAG;EACzD;EACA,IAAImG,SAAS,GAAGhG,KAAK,CAACoD,KAAK;EAC3B,IAAI6C,OAAO,GAAGjG,KAAK,CAACwD,GAAG;;EAEvB;EACA;EACA;EACA,IAAK3D,QAAQ,EAAG;IACf,MAAMkD,QAAQ,GAAG,IAAAC,wBAAiB,EAAEhD,KAAK,EAAE;MAC1CoB,IAAI,EAAE;IACP,CAAE,CAAC;IAEH4E,SAAS,GAAGjD,QAAQ,CAACK,KAAK;;IAE1B;IACA;IACA6C,OAAO,GAAGlD,QAAQ,CAACS,GAAG,GAAG,CAAC;EAC3B;;EAEA;EACA,OAAO,IAAA0C,eAAK,EAAElG,KAAK,EAAEgG,SAAS,EAAEC,OAAQ,CAAC;AAC1C;AAAC,IAAAE,QAAA,GAEcvG,YAAY;AAAAwG,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
@@ -2,7 +2,7 @@ import { createElement } from "@wordpress/element";
2
2
  /**
3
3
  * WordPress dependencies
4
4
  */
5
- import { useRef, createInterpolateElement } from '@wordpress/element';
5
+ import { useMemo, useRef, createInterpolateElement } from '@wordpress/element';
6
6
  import { __, sprintf } from '@wordpress/i18n';
7
7
  import { speak } from '@wordpress/a11y';
8
8
  import { Popover } from '@wordpress/components';
@@ -19,9 +19,7 @@ import { link as settings } from './index';
19
19
  import useLinkInstanceKey from './use-link-instance-key';
20
20
  const LINK_SETTINGS = [...LinkControl.DEFAULT_LINK_SETTINGS, {
21
21
  id: 'nofollow',
22
- title: createInterpolateElement(__('Mark as <code>nofollow</code>'), {
23
- code: createElement("code", null)
24
- })
22
+ title: __('Mark as nofollow')
25
23
  }];
26
24
  function InlineLinkUI({
27
25
  isActive,
@@ -49,14 +47,14 @@ function InlineLinkUI({
49
47
  userCanCreatePages: _settings.__experimentalUserCanCreatePages
50
48
  };
51
49
  }, []);
52
- const linkValue = {
50
+ const linkValue = useMemo(() => ({
53
51
  url: activeAttributes.url,
54
52
  type: activeAttributes.type,
55
53
  id: activeAttributes.id,
56
54
  opensInNewTab: activeAttributes.target === '_blank',
57
55
  nofollow: activeAttributes.rel?.includes('nofollow'),
58
56
  title: richTextText
59
- };
57
+ }), [activeAttributes.id, activeAttributes.rel, activeAttributes.target, activeAttributes.type, activeAttributes.url, richTextText]);
60
58
  function removeLink() {
61
59
  const newValue = removeFormat(value, 'core/link');
62
60
  onChange(newValue);
@@ -162,7 +160,11 @@ function InlineLinkUI({
162
160
  // See https://github.com/WordPress/gutenberg/pull/34742.
163
161
  const forceRemountKey = useLinkInstanceKey(popoverAnchor);
164
162
 
165
- // The focusOnMount prop shouldn't evolve during render of a Popover
163
+ // Focus should only be moved into the Popover when the Link is being created or edited.
164
+ // When the Link is in "preview" mode focus should remain on the rich text because at
165
+ // this point the Link dialog is informational only and thus the user should be able to
166
+ // continue editing the rich text.
167
+ // Ref used because the focusOnMount prop shouldn't evolve during render of a Popover
166
168
  // otherwise it causes a render of the content.
167
169
  const focusOnMount = useRef(addingLink ? 'firstElement' : false);
168
170
  async function handleCreate(pageTitle) {
@@ -1 +1 @@
1
- {"version":3,"names":["useRef","createInterpolateElement","__","sprintf","speak","Popover","prependHTTP","create","insert","isCollapsed","applyFormat","useAnchor","removeFormat","slice","replace","split","concat","__experimentalLinkControl","LinkControl","store","blockEditorStore","useSelect","createLinkFormat","isValidHref","getFormatBoundary","link","settings","useLinkInstanceKey","LINK_SETTINGS","DEFAULT_LINK_SETTINGS","id","title","code","createElement","InlineLinkUI","isActive","activeAttributes","addingLink","value","onChange","stopAddingLink","contentRef","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","createPageEntity","userCanCreatePages","select","getSettings","_settings","__experimentalCreatePageEntity","__experimentalUserCanCreatePages","linkValue","url","type","opensInNewTab","target","nofollow","rel","includes","removeLink","newValue","onChangeLink","nextValue","didToggleSetting","undefined","newUrl","linkFormat","String","opensInNewWindow","newText","toInsert","length","boundary","valBefore","valAfter","start","newValAfter","end","activeFormats","popoverAnchor","editableContentElement","current","forceRemountKey","focusOnMount","handleCreate","pageTitle","page","status","rendered","kind","createButtonText","searchTerm","mark","anchor","onClose","onFocusOutside","placement","shift","key","onRemove","forceIsEditingLink","hasRichPreviews","createSuggestion","withCreateSuggestion","createSuggestionButtonText","hasTextControl","textStart","textEnd"],"sources":["@wordpress/format-library/src/link/inline.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, createInterpolateElement } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { speak } from '@wordpress/a11y';\nimport { Popover } from '@wordpress/components';\nimport { prependHTTP } from '@wordpress/url';\nimport {\n\tcreate,\n\tinsert,\n\tisCollapsed,\n\tapplyFormat,\n\tuseAnchor,\n\tremoveFormat,\n\tslice,\n\treplace,\n\tsplit,\n\tconcat,\n} from '@wordpress/rich-text';\nimport {\n\t__experimentalLinkControl as LinkControl,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { createLinkFormat, isValidHref, getFormatBoundary } from './utils';\nimport { link as settings } from './index';\nimport useLinkInstanceKey from './use-link-instance-key';\n\nconst LINK_SETTINGS = [\n\t...LinkControl.DEFAULT_LINK_SETTINGS,\n\t{\n\t\tid: 'nofollow',\n\t\ttitle: createInterpolateElement(\n\t\t\t__( 'Mark as <code>nofollow</code>' ),\n\t\t\t{ code: <code /> }\n\t\t),\n\t},\n];\n\nfunction InlineLinkUI( {\n\tisActive,\n\tactiveAttributes,\n\taddingLink,\n\tvalue,\n\tonChange,\n\tstopAddingLink,\n\tcontentRef,\n} ) {\n\tconst richLinkTextValue = getRichTextValueFromSelection( value, isActive );\n\n\t// Get the text content minus any HTML tags.\n\tconst richTextText = richLinkTextValue.text;\n\n\tconst { createPageEntity, userCanCreatePages } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst _settings = getSettings();\n\n\t\treturn {\n\t\t\tcreatePageEntity: _settings.__experimentalCreatePageEntity,\n\t\t\tuserCanCreatePages: _settings.__experimentalUserCanCreatePages,\n\t\t};\n\t}, [] );\n\n\tconst linkValue = {\n\t\turl: activeAttributes.url,\n\t\ttype: activeAttributes.type,\n\t\tid: activeAttributes.id,\n\t\topensInNewTab: activeAttributes.target === '_blank',\n\t\tnofollow: activeAttributes.rel?.includes( 'nofollow' ),\n\t\ttitle: richTextText,\n\t};\n\n\tfunction removeLink() {\n\t\tconst newValue = removeFormat( value, 'core/link' );\n\t\tonChange( newValue );\n\t\tstopAddingLink();\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\tfunction onChangeLink( nextValue ) {\n\t\t// LinkControl calls `onChange` immediately upon the toggling a setting.\n\t\t// Before merging the next value with the current link value, check if\n\t\t// the setting was toggled.\n\t\tconst didToggleSetting =\n\t\t\tlinkValue.opensInNewTab !== nextValue.opensInNewTab &&\n\t\t\tnextValue.url === undefined;\n\t\t// Merge the next value with the current link value.\n\t\tnextValue = {\n\t\t\t...linkValue,\n\t\t\t...nextValue,\n\t\t};\n\n\t\tconst newUrl = prependHTTP( nextValue.url );\n\t\tconst linkFormat = createLinkFormat( {\n\t\t\turl: newUrl,\n\t\t\ttype: nextValue.type,\n\t\t\tid:\n\t\t\t\tnextValue.id !== undefined && nextValue.id !== null\n\t\t\t\t\t? String( nextValue.id )\n\t\t\t\t\t: undefined,\n\t\t\topensInNewWindow: nextValue.opensInNewTab,\n\t\t\tnofollow: nextValue.nofollow,\n\t\t} );\n\n\t\tconst newText = nextValue.title || newUrl;\n\n\t\tif ( isCollapsed( value ) && ! isActive ) {\n\t\t\t// Scenario: we don't have any actively selected text or formats.\n\t\t\tconst toInsert = applyFormat(\n\t\t\t\tcreate( { text: newText } ),\n\t\t\t\tlinkFormat,\n\t\t\t\t0,\n\t\t\t\tnewText.length\n\t\t\t);\n\t\t\tonChange( insert( value, toInsert ) );\n\t\t} else {\n\t\t\t// Scenario: we have any active text selection or an active format.\n\t\t\tlet newValue;\n\n\t\t\tif ( newText === richTextText ) {\n\t\t\t\t// If we're not updating the text then ignore.\n\t\t\t\tnewValue = applyFormat( value, linkFormat );\n\t\t\t} else {\n\t\t\t\t// Create new RichText value for the new text in order that we\n\t\t\t\t// can apply formats to it.\n\t\t\t\tnewValue = create( { text: newText } );\n\n\t\t\t\t// Apply the new Link format to this new text value.\n\t\t\t\tnewValue = applyFormat(\n\t\t\t\t\tnewValue,\n\t\t\t\t\tlinkFormat,\n\t\t\t\t\t0,\n\t\t\t\t\tnewText.length\n\t\t\t\t);\n\n\t\t\t\t// Get the boundaries of the active link format.\n\t\t\t\tconst boundary = getFormatBoundary( value, {\n\t\t\t\t\ttype: 'core/link',\n\t\t\t\t} );\n\n\t\t\t\t// Split the value at the start of the active link format.\n\t\t\t\t// Passing \"start\" as the 3rd parameter is required to ensure\n\t\t\t\t// the second half of the split value is split at the format's\n\t\t\t\t// start boundary and avoids relying on the value's \"end\" property\n\t\t\t\t// which may not correspond correctly.\n\t\t\t\tconst [ valBefore, valAfter ] = split(\n\t\t\t\t\tvalue,\n\t\t\t\t\tboundary.start,\n\t\t\t\t\tboundary.start\n\t\t\t\t);\n\n\t\t\t\t// Update the original (full) RichTextValue replacing the\n\t\t\t\t// target text with the *new* RichTextValue containing:\n\t\t\t\t// 1. The new text content.\n\t\t\t\t// 2. The new link format.\n\t\t\t\t// As \"replace\" will operate on the first match only, it is\n\t\t\t\t// run only against the second half of the value which was\n\t\t\t\t// split at the active format's boundary. This avoids a bug\n\t\t\t\t// with incorrectly targetted replacements.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/issues/41771.\n\t\t\t\t// Note original formats will be lost when applying this change.\n\t\t\t\t// That is expected behaviour.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.\n\t\t\t\tconst newValAfter = replace( valAfter, richTextText, newValue );\n\n\t\t\t\tnewValue = concat( valBefore, newValAfter );\n\t\t\t}\n\n\t\t\tnewValue.start = newValue.end;\n\n\t\t\t// Hides the Link UI.\n\t\t\tnewValue.activeFormats = [];\n\t\t\tonChange( newValue );\n\t\t}\n\n\t\t// Focus should only be shifted back to the formatted segment when the\n\t\t// URL is submitted.\n\t\tif ( ! didToggleSetting ) {\n\t\t\tstopAddingLink();\n\t\t}\n\n\t\tif ( ! isValidHref( newUrl ) ) {\n\t\t\tspeak(\n\t\t\t\t__(\n\t\t\t\t\t'Warning: the link has been inserted but may have errors. Please test it.'\n\t\t\t\t),\n\t\t\t\t'assertive'\n\t\t\t);\n\t\t} else if ( isActive ) {\n\t\t\tspeak( __( 'Link edited.' ), 'assertive' );\n\t\t} else {\n\t\t\tspeak( __( 'Link inserted.' ), 'assertive' );\n\t\t}\n\t}\n\n\tconst popoverAnchor = useAnchor( {\n\t\teditableContentElement: contentRef.current,\n\t\tsettings,\n\t} );\n\n\t// Generate a string based key that is unique to this anchor reference.\n\t// This is used to force re-mount the LinkControl component to avoid\n\t// potential stale state bugs caused by the component not being remounted\n\t// See https://github.com/WordPress/gutenberg/pull/34742.\n\tconst forceRemountKey = useLinkInstanceKey( popoverAnchor );\n\n\t// The focusOnMount prop shouldn't evolve during render of a Popover\n\t// otherwise it causes a render of the content.\n\tconst focusOnMount = useRef( addingLink ? 'firstElement' : false );\n\n\tasync function handleCreate( pageTitle ) {\n\t\tconst page = await createPageEntity( {\n\t\t\ttitle: pageTitle,\n\t\t\tstatus: 'draft',\n\t\t} );\n\n\t\treturn {\n\t\t\tid: page.id,\n\t\t\ttype: page.type,\n\t\t\ttitle: page.title.rendered,\n\t\t\turl: page.link,\n\t\t\tkind: 'post-type',\n\t\t};\n\t}\n\n\tfunction createButtonText( searchTerm ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %s: search term. */\n\t\t\t\t__( 'Create page: <mark>%s</mark>' ),\n\t\t\t\tsearchTerm\n\t\t\t),\n\t\t\t{ mark: <mark /> }\n\t\t);\n\t}\n\n\treturn (\n\t\t<Popover\n\t\t\tanchor={ popoverAnchor }\n\t\t\tfocusOnMount={ focusOnMount.current }\n\t\t\tonClose={ stopAddingLink }\n\t\t\tonFocusOutside={ () => stopAddingLink( false ) }\n\t\t\tplacement=\"bottom\"\n\t\t\tshift\n\t\t>\n\t\t\t<LinkControl\n\t\t\t\tkey={ forceRemountKey }\n\t\t\t\tvalue={ linkValue }\n\t\t\t\tonChange={ onChangeLink }\n\t\t\t\tonRemove={ removeLink }\n\t\t\t\tforceIsEditingLink={ addingLink }\n\t\t\t\thasRichPreviews\n\t\t\t\tcreateSuggestion={ createPageEntity && handleCreate }\n\t\t\t\twithCreateSuggestion={ userCanCreatePages }\n\t\t\t\tcreateSuggestionButtonText={ createButtonText }\n\t\t\t\thasTextControl\n\t\t\t\tsettings={ LINK_SETTINGS }\n\t\t\t/>\n\t\t</Popover>\n\t);\n}\n\nfunction getRichTextValueFromSelection( value, isActive ) {\n\t// Default to the selection ranges on the RichTextValue object.\n\tlet textStart = value.start;\n\tlet textEnd = value.end;\n\n\t// If the format is currently active then the rich text value\n\t// should always be taken from the bounds of the active format\n\t// and not the selected text.\n\tif ( isActive ) {\n\t\tconst boundary = getFormatBoundary( value, {\n\t\t\ttype: 'core/link',\n\t\t} );\n\n\t\ttextStart = boundary.start;\n\n\t\t// Text *selection* always extends +1 beyond the edge of the format.\n\t\t// We account for that here.\n\t\ttextEnd = boundary.end + 1;\n\t}\n\n\t// Get a RichTextValue containing the selected text content.\n\treturn slice( value, textStart, textEnd );\n}\n\nexport default InlineLinkUI;\n"],"mappings":";AAAA;AACA;AACA;AACA,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;IACAgC,OAAO,GAAGnC,QAAQ,CAACK,GAAG,GAAG,CAAC;EAC3B;;EAEA;EACA,OAAOlE,KAAK,CAAEyB,KAAK,EAAEsE,SAAS,EAAEC,OAAQ,CAAC;AAC1C;AAEA,eAAe3E,YAAY"}
1
+ {"version":3,"names":["useMemo","useRef","createInterpolateElement","__","sprintf","speak","Popover","prependHTTP","create","insert","isCollapsed","applyFormat","useAnchor","removeFormat","slice","replace","split","concat","__experimentalLinkControl","LinkControl","store","blockEditorStore","useSelect","createLinkFormat","isValidHref","getFormatBoundary","link","settings","useLinkInstanceKey","LINK_SETTINGS","DEFAULT_LINK_SETTINGS","id","title","InlineLinkUI","isActive","activeAttributes","addingLink","value","onChange","stopAddingLink","contentRef","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","createPageEntity","userCanCreatePages","select","getSettings","_settings","__experimentalCreatePageEntity","__experimentalUserCanCreatePages","linkValue","url","type","opensInNewTab","target","nofollow","rel","includes","removeLink","newValue","onChangeLink","nextValue","didToggleSetting","undefined","newUrl","linkFormat","String","opensInNewWindow","newText","toInsert","length","boundary","valBefore","valAfter","start","newValAfter","end","activeFormats","popoverAnchor","editableContentElement","current","forceRemountKey","focusOnMount","handleCreate","pageTitle","page","status","rendered","kind","createButtonText","searchTerm","mark","createElement","anchor","onClose","onFocusOutside","placement","shift","key","onRemove","forceIsEditingLink","hasRichPreviews","createSuggestion","withCreateSuggestion","createSuggestionButtonText","hasTextControl","textStart","textEnd"],"sources":["@wordpress/format-library/src/link/inline.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useRef, createInterpolateElement } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { speak } from '@wordpress/a11y';\nimport { Popover } from '@wordpress/components';\nimport { prependHTTP } from '@wordpress/url';\nimport {\n\tcreate,\n\tinsert,\n\tisCollapsed,\n\tapplyFormat,\n\tuseAnchor,\n\tremoveFormat,\n\tslice,\n\treplace,\n\tsplit,\n\tconcat,\n} from '@wordpress/rich-text';\nimport {\n\t__experimentalLinkControl as LinkControl,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { createLinkFormat, isValidHref, getFormatBoundary } from './utils';\nimport { link as settings } from './index';\nimport useLinkInstanceKey from './use-link-instance-key';\n\nconst LINK_SETTINGS = [\n\t...LinkControl.DEFAULT_LINK_SETTINGS,\n\t{\n\t\tid: 'nofollow',\n\t\ttitle: __( 'Mark as nofollow' ),\n\t},\n];\n\nfunction InlineLinkUI( {\n\tisActive,\n\tactiveAttributes,\n\taddingLink,\n\tvalue,\n\tonChange,\n\tstopAddingLink,\n\tcontentRef,\n} ) {\n\tconst richLinkTextValue = getRichTextValueFromSelection( value, isActive );\n\n\t// Get the text content minus any HTML tags.\n\tconst richTextText = richLinkTextValue.text;\n\n\tconst { createPageEntity, userCanCreatePages } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst _settings = getSettings();\n\n\t\treturn {\n\t\t\tcreatePageEntity: _settings.__experimentalCreatePageEntity,\n\t\t\tuserCanCreatePages: _settings.__experimentalUserCanCreatePages,\n\t\t};\n\t}, [] );\n\n\tconst linkValue = useMemo(\n\t\t() => ( {\n\t\t\turl: activeAttributes.url,\n\t\t\ttype: activeAttributes.type,\n\t\t\tid: activeAttributes.id,\n\t\t\topensInNewTab: activeAttributes.target === '_blank',\n\t\t\tnofollow: activeAttributes.rel?.includes( 'nofollow' ),\n\t\t\ttitle: richTextText,\n\t\t} ),\n\t\t[\n\t\t\tactiveAttributes.id,\n\t\t\tactiveAttributes.rel,\n\t\t\tactiveAttributes.target,\n\t\t\tactiveAttributes.type,\n\t\t\tactiveAttributes.url,\n\t\t\trichTextText,\n\t\t]\n\t);\n\n\tfunction removeLink() {\n\t\tconst newValue = removeFormat( value, 'core/link' );\n\t\tonChange( newValue );\n\t\tstopAddingLink();\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\tfunction onChangeLink( nextValue ) {\n\t\t// LinkControl calls `onChange` immediately upon the toggling a setting.\n\t\t// Before merging the next value with the current link value, check if\n\t\t// the setting was toggled.\n\t\tconst didToggleSetting =\n\t\t\tlinkValue.opensInNewTab !== nextValue.opensInNewTab &&\n\t\t\tnextValue.url === undefined;\n\t\t// Merge the next value with the current link value.\n\t\tnextValue = {\n\t\t\t...linkValue,\n\t\t\t...nextValue,\n\t\t};\n\n\t\tconst newUrl = prependHTTP( nextValue.url );\n\t\tconst linkFormat = createLinkFormat( {\n\t\t\turl: newUrl,\n\t\t\ttype: nextValue.type,\n\t\t\tid:\n\t\t\t\tnextValue.id !== undefined && nextValue.id !== null\n\t\t\t\t\t? String( nextValue.id )\n\t\t\t\t\t: undefined,\n\t\t\topensInNewWindow: nextValue.opensInNewTab,\n\t\t\tnofollow: nextValue.nofollow,\n\t\t} );\n\n\t\tconst newText = nextValue.title || newUrl;\n\n\t\tif ( isCollapsed( value ) && ! isActive ) {\n\t\t\t// Scenario: we don't have any actively selected text or formats.\n\t\t\tconst toInsert = applyFormat(\n\t\t\t\tcreate( { text: newText } ),\n\t\t\t\tlinkFormat,\n\t\t\t\t0,\n\t\t\t\tnewText.length\n\t\t\t);\n\t\t\tonChange( insert( value, toInsert ) );\n\t\t} else {\n\t\t\t// Scenario: we have any active text selection or an active format.\n\t\t\tlet newValue;\n\n\t\t\tif ( newText === richTextText ) {\n\t\t\t\t// If we're not updating the text then ignore.\n\t\t\t\tnewValue = applyFormat( value, linkFormat );\n\t\t\t} else {\n\t\t\t\t// Create new RichText value for the new text in order that we\n\t\t\t\t// can apply formats to it.\n\t\t\t\tnewValue = create( { text: newText } );\n\n\t\t\t\t// Apply the new Link format to this new text value.\n\t\t\t\tnewValue = applyFormat(\n\t\t\t\t\tnewValue,\n\t\t\t\t\tlinkFormat,\n\t\t\t\t\t0,\n\t\t\t\t\tnewText.length\n\t\t\t\t);\n\n\t\t\t\t// Get the boundaries of the active link format.\n\t\t\t\tconst boundary = getFormatBoundary( value, {\n\t\t\t\t\ttype: 'core/link',\n\t\t\t\t} );\n\n\t\t\t\t// Split the value at the start of the active link format.\n\t\t\t\t// Passing \"start\" as the 3rd parameter is required to ensure\n\t\t\t\t// the second half of the split value is split at the format's\n\t\t\t\t// start boundary and avoids relying on the value's \"end\" property\n\t\t\t\t// which may not correspond correctly.\n\t\t\t\tconst [ valBefore, valAfter ] = split(\n\t\t\t\t\tvalue,\n\t\t\t\t\tboundary.start,\n\t\t\t\t\tboundary.start\n\t\t\t\t);\n\n\t\t\t\t// Update the original (full) RichTextValue replacing the\n\t\t\t\t// target text with the *new* RichTextValue containing:\n\t\t\t\t// 1. The new text content.\n\t\t\t\t// 2. The new link format.\n\t\t\t\t// As \"replace\" will operate on the first match only, it is\n\t\t\t\t// run only against the second half of the value which was\n\t\t\t\t// split at the active format's boundary. This avoids a bug\n\t\t\t\t// with incorrectly targetted replacements.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/issues/41771.\n\t\t\t\t// Note original formats will be lost when applying this change.\n\t\t\t\t// That is expected behaviour.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.\n\t\t\t\tconst newValAfter = replace( valAfter, richTextText, newValue );\n\n\t\t\t\tnewValue = concat( valBefore, newValAfter );\n\t\t\t}\n\n\t\t\tnewValue.start = newValue.end;\n\n\t\t\t// Hides the Link UI.\n\t\t\tnewValue.activeFormats = [];\n\t\t\tonChange( newValue );\n\t\t}\n\n\t\t// Focus should only be shifted back to the formatted segment when the\n\t\t// URL is submitted.\n\t\tif ( ! didToggleSetting ) {\n\t\t\tstopAddingLink();\n\t\t}\n\n\t\tif ( ! isValidHref( newUrl ) ) {\n\t\t\tspeak(\n\t\t\t\t__(\n\t\t\t\t\t'Warning: the link has been inserted but may have errors. Please test it.'\n\t\t\t\t),\n\t\t\t\t'assertive'\n\t\t\t);\n\t\t} else if ( isActive ) {\n\t\t\tspeak( __( 'Link edited.' ), 'assertive' );\n\t\t} else {\n\t\t\tspeak( __( 'Link inserted.' ), 'assertive' );\n\t\t}\n\t}\n\n\tconst popoverAnchor = useAnchor( {\n\t\teditableContentElement: contentRef.current,\n\t\tsettings,\n\t} );\n\n\t// Generate a string based key that is unique to this anchor reference.\n\t// This is used to force re-mount the LinkControl component to avoid\n\t// potential stale state bugs caused by the component not being remounted\n\t// See https://github.com/WordPress/gutenberg/pull/34742.\n\tconst forceRemountKey = useLinkInstanceKey( popoverAnchor );\n\n\t// Focus should only be moved into the Popover when the Link is being created or edited.\n\t// When the Link is in \"preview\" mode focus should remain on the rich text because at\n\t// this point the Link dialog is informational only and thus the user should be able to\n\t// continue editing the rich text.\n\t// Ref used because the focusOnMount prop shouldn't evolve during render of a Popover\n\t// otherwise it causes a render of the content.\n\tconst focusOnMount = useRef( addingLink ? 'firstElement' : false );\n\n\tasync function handleCreate( pageTitle ) {\n\t\tconst page = await createPageEntity( {\n\t\t\ttitle: pageTitle,\n\t\t\tstatus: 'draft',\n\t\t} );\n\n\t\treturn {\n\t\t\tid: page.id,\n\t\t\ttype: page.type,\n\t\t\ttitle: page.title.rendered,\n\t\t\turl: page.link,\n\t\t\tkind: 'post-type',\n\t\t};\n\t}\n\n\tfunction createButtonText( searchTerm ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %s: search term. */\n\t\t\t\t__( 'Create page: <mark>%s</mark>' ),\n\t\t\t\tsearchTerm\n\t\t\t),\n\t\t\t{ mark: <mark /> }\n\t\t);\n\t}\n\n\treturn (\n\t\t<Popover\n\t\t\tanchor={ popoverAnchor }\n\t\t\tfocusOnMount={ focusOnMount.current }\n\t\t\tonClose={ stopAddingLink }\n\t\t\tonFocusOutside={ () => stopAddingLink( false ) }\n\t\t\tplacement=\"bottom\"\n\t\t\tshift\n\t\t>\n\t\t\t<LinkControl\n\t\t\t\tkey={ forceRemountKey }\n\t\t\t\tvalue={ linkValue }\n\t\t\t\tonChange={ onChangeLink }\n\t\t\t\tonRemove={ removeLink }\n\t\t\t\tforceIsEditingLink={ addingLink }\n\t\t\t\thasRichPreviews\n\t\t\t\tcreateSuggestion={ createPageEntity && handleCreate }\n\t\t\t\twithCreateSuggestion={ userCanCreatePages }\n\t\t\t\tcreateSuggestionButtonText={ createButtonText }\n\t\t\t\thasTextControl\n\t\t\t\tsettings={ LINK_SETTINGS }\n\t\t\t/>\n\t\t</Popover>\n\t);\n}\n\nfunction getRichTextValueFromSelection( value, isActive ) {\n\t// Default to the selection ranges on the RichTextValue object.\n\tlet textStart = value.start;\n\tlet textEnd = value.end;\n\n\t// If the format is currently active then the rich text value\n\t// should always be taken from the bounds of the active format\n\t// and not the selected text.\n\tif ( isActive ) {\n\t\tconst boundary = getFormatBoundary( value, {\n\t\t\ttype: 'core/link',\n\t\t} );\n\n\t\ttextStart = boundary.start;\n\n\t\t// Text *selection* always extends +1 beyond the edge of the format.\n\t\t// We account for that here.\n\t\ttextEnd = boundary.end + 1;\n\t}\n\n\t// Get a RichTextValue containing the selected text content.\n\treturn slice( value, textStart, textEnd );\n}\n\nexport default InlineLinkUI;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,MAAM,EAAEC,wBAAwB,QAAQ,oBAAoB;AAC9E,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SAASC,OAAO,QAAQ,uBAAuB;AAC/C,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SACCC,MAAM,EACNC,MAAM,EACNC,WAAW,EACXC,WAAW,EACXC,SAAS,EACTC,YAAY,EACZC,KAAK,EACLC,OAAO,EACPC,KAAK,EACLC,MAAM,QACA,sBAAsB;AAC7B,SACCC,yBAAyB,IAAIC,WAAW,EACxCC,KAAK,IAAIC,gBAAgB,QACnB,yBAAyB;AAChC,SAASC,SAAS,QAAQ,iBAAiB;;AAE3C;AACA;AACA;AACA,SAASC,gBAAgB,EAAEC,WAAW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AAY,EAAGA,YAAY,CAACF,OAAS;IACrCc,OAAO,EAAGzD,cAAgB;IAC1B0D,cAAc,EAAGA,CAAA,KAAM1D,cAAc,CAAE,KAAM,CAAG;IAChD2D,SAAS,EAAC,QAAQ;IAClBC,KAAK;EAAA,GAELL,aAAA,CAAC3E,WAAW;IACXiF,GAAG,EAAGjB,eAAiB;IACvB9C,KAAK,EAAGe,SAAW;IACnBd,QAAQ,EAAGwB,YAAc;IACzBuC,QAAQ,EAAGzC,UAAY;IACvB0C,kBAAkB,EAAGlE,UAAY;IACjCmE,eAAe;IACfC,gBAAgB,EAAG3D,gBAAgB,IAAIwC,YAAc;IACrDoB,oBAAoB,EAAG3D,kBAAoB;IAC3C4D,0BAA0B,EAAGf,gBAAkB;IAC/CgB,cAAc;IACdhF,QAAQ,EAAGE;EAAe,CAC1B,CACO,CAAC;AAEZ;AAEA,SAASa,6BAA6BA,CAAEL,KAAK,EAAEH,QAAQ,EAAG;EACzD;EACA,IAAI0E,SAAS,GAAGvE,KAAK,CAACuC,KAAK;EAC3B,IAAIiC,OAAO,GAAGxE,KAAK,CAACyC,GAAG;;EAEvB;EACA;EACA;EACA,IAAK5C,QAAQ,EAAG;IACf,MAAMuC,QAAQ,GAAGhD,iBAAiB,CAAEY,KAAK,EAAE;MAC1CiB,IAAI,EAAE;IACP,CAAE,CAAC;IAEHsD,SAAS,GAAGnC,QAAQ,CAACG,KAAK;;IAE1B;IACA;IACAiC,OAAO,GAAGpC,QAAQ,CAACK,GAAG,GAAG,CAAC;EAC3B;;EAEA;EACA,OAAOhE,KAAK,CAAEuB,KAAK,EAAEuE,SAAS,EAAEC,OAAQ,CAAC;AAC1C;AAEA,eAAe5E,YAAY"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/format-library",
3
- "version": "4.18.1-next.5a1d1283.0",
3
+ "version": "4.19.1",
4
4
  "description": "Format library for the WordPress editor.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -26,17 +26,17 @@
26
26
  "react-native": "src/index",
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.16.0",
29
- "@wordpress/a11y": "^3.41.1-next.5a1d1283.0",
30
- "@wordpress/block-editor": "^12.9.1-next.5a1d1283.0",
31
- "@wordpress/components": "^26.0.1-next.5a1d1283.0",
32
- "@wordpress/compose": "^6.18.1-next.5a1d1283.0",
33
- "@wordpress/data": "^9.11.1-next.5a1d1283.0",
34
- "@wordpress/element": "^5.18.1-next.5a1d1283.0",
35
- "@wordpress/html-entities": "^3.41.1-next.5a1d1283.0",
36
- "@wordpress/i18n": "^4.41.1-next.5a1d1283.0",
37
- "@wordpress/icons": "^9.32.1-next.5a1d1283.0",
38
- "@wordpress/rich-text": "^6.18.1-next.5a1d1283.0",
39
- "@wordpress/url": "^3.42.1-next.5a1d1283.0"
29
+ "@wordpress/a11y": "^3.42.1",
30
+ "@wordpress/block-editor": "^12.10.1",
31
+ "@wordpress/components": "^25.8.1",
32
+ "@wordpress/compose": "^6.19.1",
33
+ "@wordpress/data": "^9.12.1",
34
+ "@wordpress/element": "^5.19.1",
35
+ "@wordpress/html-entities": "^3.42.1",
36
+ "@wordpress/i18n": "^4.42.1",
37
+ "@wordpress/icons": "^9.33.1",
38
+ "@wordpress/rich-text": "^6.19.1",
39
+ "@wordpress/url": "^3.43.1"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "react": "^18.0.0",
@@ -45,5 +45,5 @@
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "fa0b66987dab5a15f38663e06036d09bccffaa4b"
48
+ "gitHead": "4987d16acb5c41b62704dc4f88225acb97ddd698"
49
49
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { useRef, createInterpolateElement } from '@wordpress/element';
4
+ import { useMemo, useRef, createInterpolateElement } from '@wordpress/element';
5
5
  import { __, sprintf } from '@wordpress/i18n';
6
6
  import { speak } from '@wordpress/a11y';
7
7
  import { Popover } from '@wordpress/components';
@@ -35,10 +35,7 @@ const LINK_SETTINGS = [
35
35
  ...LinkControl.DEFAULT_LINK_SETTINGS,
36
36
  {
37
37
  id: 'nofollow',
38
- title: createInterpolateElement(
39
- __( 'Mark as <code>nofollow</code>' ),
40
- { code: <code /> }
41
- ),
38
+ title: __( 'Mark as nofollow' ),
42
39
  },
43
40
  ];
44
41
 
@@ -66,14 +63,24 @@ function InlineLinkUI( {
66
63
  };
67
64
  }, [] );
68
65
 
69
- const linkValue = {
70
- url: activeAttributes.url,
71
- type: activeAttributes.type,
72
- id: activeAttributes.id,
73
- opensInNewTab: activeAttributes.target === '_blank',
74
- nofollow: activeAttributes.rel?.includes( 'nofollow' ),
75
- title: richTextText,
76
- };
66
+ const linkValue = useMemo(
67
+ () => ( {
68
+ url: activeAttributes.url,
69
+ type: activeAttributes.type,
70
+ id: activeAttributes.id,
71
+ opensInNewTab: activeAttributes.target === '_blank',
72
+ nofollow: activeAttributes.rel?.includes( 'nofollow' ),
73
+ title: richTextText,
74
+ } ),
75
+ [
76
+ activeAttributes.id,
77
+ activeAttributes.rel,
78
+ activeAttributes.target,
79
+ activeAttributes.type,
80
+ activeAttributes.url,
81
+ richTextText,
82
+ ]
83
+ );
77
84
 
78
85
  function removeLink() {
79
86
  const newValue = removeFormat( value, 'core/link' );
@@ -209,7 +216,11 @@ function InlineLinkUI( {
209
216
  // See https://github.com/WordPress/gutenberg/pull/34742.
210
217
  const forceRemountKey = useLinkInstanceKey( popoverAnchor );
211
218
 
212
- // The focusOnMount prop shouldn't evolve during render of a Popover
219
+ // Focus should only be moved into the Popover when the Link is being created or edited.
220
+ // When the Link is in "preview" mode focus should remain on the rich text because at
221
+ // this point the Link dialog is informational only and thus the user should be able to
222
+ // continue editing the rich text.
223
+ // Ref used because the focusOnMount prop shouldn't evolve during render of a Popover
213
224
  // otherwise it causes a render of the content.
214
225
  const focusOnMount = useRef( addingLink ? 'firstElement' : false );
215
226