@wordpress/format-library 4.26.0 → 4.27.0
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 +2 -0
- package/build/link/inline.js +29 -21
- package/build/link/inline.js.map +1 -1
- package/build-module/link/inline.js +31 -22
- package/build-module/link/inline.js.map +1 -1
- package/build-style/style-rtl.css +1 -1
- package/build-style/style.css +1 -1
- package/package.json +14 -14
- package/src/link/inline.js +30 -22
package/CHANGELOG.md
CHANGED
package/build/link/inline.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -16,7 +15,6 @@ var _blockEditor = require("@wordpress/block-editor");
|
|
|
16
15
|
var _data = require("@wordpress/data");
|
|
17
16
|
var _utils = require("./utils");
|
|
18
17
|
var _index = require("./index");
|
|
19
|
-
var _useLinkInstanceKey = _interopRequireDefault(require("./use-link-instance-key"));
|
|
20
18
|
/**
|
|
21
19
|
* WordPress dependencies
|
|
22
20
|
*/
|
|
@@ -70,10 +68,9 @@ function InlineLinkUI({
|
|
|
70
68
|
(0, _a11y.speak)((0, _i18n.__)('Link removed.'), 'assertive');
|
|
71
69
|
}
|
|
72
70
|
function onChangeLink(nextValue) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const didToggleSetting = linkValue.opensInNewTab !== nextValue.opensInNewTab && nextValue.url === undefined;
|
|
71
|
+
const hasLink = linkValue?.url;
|
|
72
|
+
const isNewLink = !hasLink;
|
|
73
|
+
|
|
77
74
|
// Merge the next value with the current link value.
|
|
78
75
|
nextValue = {
|
|
79
76
|
...linkValue,
|
|
@@ -137,17 +134,16 @@ function InlineLinkUI({
|
|
|
137
134
|
const newValAfter = (0, _richText.replace)(valAfter, richTextText, newValue);
|
|
138
135
|
newValue = (0, _richText.concat)(valBefore, newValAfter);
|
|
139
136
|
}
|
|
140
|
-
newValue.start = newValue.end;
|
|
141
|
-
|
|
142
|
-
// Hides the Link UI.
|
|
143
|
-
newValue.activeFormats = [];
|
|
144
137
|
onChange(newValue);
|
|
145
138
|
}
|
|
146
139
|
|
|
147
|
-
// Focus should only be
|
|
148
|
-
//
|
|
149
|
-
|
|
150
|
-
|
|
140
|
+
// Focus should only be returned to the rich text on submit if this link is not
|
|
141
|
+
// being created for the first time. If it is then focus should remain within the
|
|
142
|
+
// Link UI because it should remain open for the user to modify the link they have
|
|
143
|
+
// just created.
|
|
144
|
+
if (!isNewLink) {
|
|
145
|
+
const returnFocusToRichText = true;
|
|
146
|
+
stopAddingLink(returnFocusToRichText);
|
|
151
147
|
}
|
|
152
148
|
if (!(0, _utils.isValidHref)(newUrl)) {
|
|
153
149
|
(0, _a11y.speak)((0, _i18n.__)('Warning: the link has been inserted but may have errors. Please test it.'), 'assertive');
|
|
@@ -162,11 +158,14 @@ function InlineLinkUI({
|
|
|
162
158
|
settings: _index.link
|
|
163
159
|
});
|
|
164
160
|
|
|
165
|
-
//
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
|
|
161
|
+
// As you change the link by interacting with the Link UI
|
|
162
|
+
// the return value of document.getSelection jumps to the field you're editing,
|
|
163
|
+
// not the highlighted text. Given that useAnchor uses document.getSelection,
|
|
164
|
+
// it will return null, since it can't find the <mark> element within the Link UI.
|
|
165
|
+
// This caches the last truthy value of the selection anchor reference.
|
|
166
|
+
// This ensures the Popover is positioned correctly on initial submission of the link.
|
|
167
|
+
const cachedRect = (0, _blockEditor.useCachedTruthy)(popoverAnchor.getBoundingClientRect());
|
|
168
|
+
popoverAnchor.getBoundingClientRect = () => cachedRect;
|
|
170
169
|
|
|
171
170
|
// Focus should only be moved into the Popover when the Link is being created or edited.
|
|
172
171
|
// When the Link is in "preview" mode focus should remain on the rich text because at
|
|
@@ -200,9 +199,9 @@ function InlineLinkUI({
|
|
|
200
199
|
onClose: stopAddingLink,
|
|
201
200
|
onFocusOutside: () => stopAddingLink(false),
|
|
202
201
|
placement: "bottom",
|
|
202
|
+
offset: 10,
|
|
203
203
|
shift: true
|
|
204
204
|
}, (0, _react.createElement)(_blockEditor.__experimentalLinkControl, {
|
|
205
|
-
key: forceRemountKey,
|
|
206
205
|
value: linkValue,
|
|
207
206
|
onChange: onChangeLink,
|
|
208
207
|
onRemove: removeLink,
|
|
@@ -212,7 +211,16 @@ function InlineLinkUI({
|
|
|
212
211
|
withCreateSuggestion: userCanCreatePages,
|
|
213
212
|
createSuggestionButtonText: createButtonText,
|
|
214
213
|
hasTextControl: true,
|
|
215
|
-
settings: LINK_SETTINGS
|
|
214
|
+
settings: LINK_SETTINGS,
|
|
215
|
+
showInitialSuggestions: true,
|
|
216
|
+
suggestionsQuery: {
|
|
217
|
+
// always show Pages as initial suggestions
|
|
218
|
+
initialSuggestionsSearchOptions: {
|
|
219
|
+
type: 'post',
|
|
220
|
+
subtype: 'page',
|
|
221
|
+
perPage: 20
|
|
222
|
+
}
|
|
223
|
+
}
|
|
216
224
|
}));
|
|
217
225
|
}
|
|
218
226
|
function getRichTextValueFromSelection(value, isActive) {
|
package/build/link/inline.js.map
CHANGED
|
@@ -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","__","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","_react","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,EAAIC,MAAM,IAAM;IACzE,MAAM;MAAEC;IAAY,CAAC,GAAGD,MAAM,CAAEE,kBAAiB,CAAC;IAClD,MAAMC,SAAS,GAAGF,WAAW,C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AoB,EAAGrF,kBAAoB;IAC3CsF,0BAA0B,EAAGpB,gBAAkB;IAC/CqB,cAAc;IACdjC,QAAQ,EAAGzE;EAAe,CAC1B,CACO,CAAC;AAEZ;AAEA,SAASe,6BAA6BA,CAAEL,KAAK,EAAEH,QAAQ,EAAG;EACzD;EACA,IAAIoG,SAAS,GAAGjG,KAAK,CAACoD,KAAK;EAC3B,IAAI8C,OAAO,GAAGlG,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;IAEH6E,SAAS,GAAGlD,QAAQ,CAACK,KAAK;;IAE1B;IACA;IACA8C,OAAO,GAAGnD,QAAQ,CAACS,GAAG,GAAG,CAAC;EAC3B;;EAEA;EACA,OAAO,IAAA2C,eAAK,EAAEnG,KAAK,EAAEiG,SAAS,EAAEC,OAAQ,CAAC;AAC1C;AAAC,IAAAE,QAAA,GAEcxG,YAAY;AAAAyG,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
1
|
+
{"version":3,"names":["_element","require","_i18n","_a11y","_components","_url","_richText","_blockEditor","_data","_utils","_index","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","hasLink","isNewLink","newUrl","prependHTTP","linkFormat","createLinkFormat","undefined","String","opensInNewWindow","newText","isCollapsed","toInsert","applyFormat","create","length","insert","boundary","getFormatBoundary","valBefore","valAfter","split","start","newValAfter","replace","concat","returnFocusToRichText","isValidHref","popoverAnchor","useAnchor","editableContentElement","current","settings","cachedRect","useCachedTruthy","getBoundingClientRect","focusOnMount","useRef","handleCreate","pageTitle","page","status","rendered","link","kind","createButtonText","searchTerm","createInterpolateElement","sprintf","mark","_react","createElement","Popover","anchor","onClose","onFocusOutside","placement","offset","shift","__experimentalLinkControl","onRemove","forceIsEditingLink","hasRichPreviews","createSuggestion","withCreateSuggestion","createSuggestionButtonText","hasTextControl","showInitialSuggestions","suggestionsQuery","initialSuggestionsSearchOptions","subtype","perPage","textStart","textEnd","end","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\tremoveFormat,\n\tslice,\n\treplace,\n\tsplit,\n\tconcat,\n\tuseAnchor,\n} from '@wordpress/rich-text';\nimport {\n\t__experimentalLinkControl as LinkControl,\n\tstore as blockEditorStore,\n\tuseCachedTruthy,\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';\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\tconst hasLink = linkValue?.url;\n\t\tconst isNewLink = ! hasLink;\n\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\tonChange( newValue );\n\t\t}\n\n\t\t// Focus should only be returned to the rich text on submit if this link is not\n\t\t// being created for the first time. If it is then focus should remain within the\n\t\t// Link UI because it should remain open for the user to modify the link they have\n\t\t// just created.\n\t\tif ( ! isNewLink ) {\n\t\t\tconst returnFocusToRichText = true;\n\t\t\tstopAddingLink( returnFocusToRichText );\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// As you change the link by interacting with the Link UI\n\t// the return value of document.getSelection jumps to the field you're editing,\n\t// not the highlighted text. Given that useAnchor uses document.getSelection,\n\t// it will return null, since it can't find the <mark> element within the Link UI.\n\t// This caches the last truthy value of the selection anchor reference.\n\t// This ensures the Popover is positioned correctly on initial submission of the link.\n\tconst cachedRect = useCachedTruthy( popoverAnchor.getBoundingClientRect() );\n\tpopoverAnchor.getBoundingClientRect = () => cachedRect;\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\toffset={ 10 }\n\t\t\tshift\n\t\t>\n\t\t\t<LinkControl\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\tshowInitialSuggestions={ true }\n\t\t\t\tsuggestionsQuery={ {\n\t\t\t\t\t// always show Pages as initial suggestions\n\t\t\t\t\tinitialSuggestionsSearchOptions: {\n\t\t\t\t\t\ttype: 'post',\n\t\t\t\t\t\tsubtype: 'page',\n\t\t\t\t\t\tperPage: 20,\n\t\t\t\t\t},\n\t\t\t\t} }\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;AAKA,IAAAO,KAAA,GAAAP,OAAA;AAKA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,MAAA,GAAAT,OAAA;AA/BA;AACA;AACA;;AAyBA;AACA;AACA;;AAIA,MAAMU,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,EAAIC,MAAM,IAAM;IAC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Y;IACjC8F,eAAe;IACfC,gBAAgB,EAAGtF,gBAAgB,IAAI6D,YAAc;IACrD0B,oBAAoB,EAAGtF,kBAAoB;IAC3CuF,0BAA0B,EAAGpB,gBAAkB;IAC/CqB,cAAc;IACdlC,QAAQ,EAAGzE,aAAe;IAC1B4G,sBAAsB,EAAG,IAAM;IAC/BC,gBAAgB,EAAG;MAClB;MACAC,+BAA+B,EAAE;QAChChF,IAAI,EAAE,MAAM;QACZiF,OAAO,EAAE,MAAM;QACfC,OAAO,EAAE;MACV;IACD;EAAG,CACH,CACO,CAAC;AAEZ;AAEA,SAASjG,6BAA6BA,CAAEL,KAAK,EAAEH,QAAQ,EAAG;EACzD;EACA,IAAI0G,SAAS,GAAGvG,KAAK,CAACqD,KAAK;EAC3B,IAAImD,OAAO,GAAGxG,KAAK,CAACyG,GAAG;;EAEvB;EACA;EACA;EACA,IAAK5G,QAAQ,EAAG;IACf,MAAMmD,QAAQ,GAAG,IAAAC,wBAAiB,EAAEjD,KAAK,EAAE;MAC1CoB,IAAI,EAAE;IACP,CAAE,CAAC;IAEHmF,SAAS,GAAGvD,QAAQ,CAACK,KAAK;;IAE1B;IACA;IACAmD,OAAO,GAAGxD,QAAQ,CAACyD,GAAG,GAAG,CAAC;EAC3B;;EAEA;EACA,OAAO,IAAAC,eAAK,EAAE1G,KAAK,EAAEuG,SAAS,EAAEC,OAAQ,CAAC;AAC1C;AAAC,IAAAG,QAAA,GAEc/G,YAAY;AAAAgH,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -7,8 +7,8 @@ import { __, sprintf } from '@wordpress/i18n';
|
|
|
7
7
|
import { speak } from '@wordpress/a11y';
|
|
8
8
|
import { Popover } from '@wordpress/components';
|
|
9
9
|
import { prependHTTP } from '@wordpress/url';
|
|
10
|
-
import { create, insert, isCollapsed, applyFormat,
|
|
11
|
-
import { __experimentalLinkControl as LinkControl, store as blockEditorStore } from '@wordpress/block-editor';
|
|
10
|
+
import { create, insert, isCollapsed, applyFormat, removeFormat, slice, replace, split, concat, useAnchor } from '@wordpress/rich-text';
|
|
11
|
+
import { __experimentalLinkControl as LinkControl, store as blockEditorStore, useCachedTruthy } from '@wordpress/block-editor';
|
|
12
12
|
import { useSelect } from '@wordpress/data';
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -16,7 +16,6 @@ import { useSelect } from '@wordpress/data';
|
|
|
16
16
|
*/
|
|
17
17
|
import { createLinkFormat, isValidHref, getFormatBoundary } from './utils';
|
|
18
18
|
import { link as settings } from './index';
|
|
19
|
-
import useLinkInstanceKey from './use-link-instance-key';
|
|
20
19
|
const LINK_SETTINGS = [...LinkControl.DEFAULT_LINK_SETTINGS, {
|
|
21
20
|
id: 'nofollow',
|
|
22
21
|
title: __('Mark as nofollow')
|
|
@@ -62,10 +61,9 @@ function InlineLinkUI({
|
|
|
62
61
|
speak(__('Link removed.'), 'assertive');
|
|
63
62
|
}
|
|
64
63
|
function onChangeLink(nextValue) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const didToggleSetting = linkValue.opensInNewTab !== nextValue.opensInNewTab && nextValue.url === undefined;
|
|
64
|
+
const hasLink = linkValue?.url;
|
|
65
|
+
const isNewLink = !hasLink;
|
|
66
|
+
|
|
69
67
|
// Merge the next value with the current link value.
|
|
70
68
|
nextValue = {
|
|
71
69
|
...linkValue,
|
|
@@ -129,17 +127,16 @@ function InlineLinkUI({
|
|
|
129
127
|
const newValAfter = replace(valAfter, richTextText, newValue);
|
|
130
128
|
newValue = concat(valBefore, newValAfter);
|
|
131
129
|
}
|
|
132
|
-
newValue.start = newValue.end;
|
|
133
|
-
|
|
134
|
-
// Hides the Link UI.
|
|
135
|
-
newValue.activeFormats = [];
|
|
136
130
|
onChange(newValue);
|
|
137
131
|
}
|
|
138
132
|
|
|
139
|
-
// Focus should only be
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
|
|
133
|
+
// Focus should only be returned to the rich text on submit if this link is not
|
|
134
|
+
// being created for the first time. If it is then focus should remain within the
|
|
135
|
+
// Link UI because it should remain open for the user to modify the link they have
|
|
136
|
+
// just created.
|
|
137
|
+
if (!isNewLink) {
|
|
138
|
+
const returnFocusToRichText = true;
|
|
139
|
+
stopAddingLink(returnFocusToRichText);
|
|
143
140
|
}
|
|
144
141
|
if (!isValidHref(newUrl)) {
|
|
145
142
|
speak(__('Warning: the link has been inserted but may have errors. Please test it.'), 'assertive');
|
|
@@ -154,11 +151,14 @@ function InlineLinkUI({
|
|
|
154
151
|
settings
|
|
155
152
|
});
|
|
156
153
|
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
|
|
154
|
+
// As you change the link by interacting with the Link UI
|
|
155
|
+
// the return value of document.getSelection jumps to the field you're editing,
|
|
156
|
+
// not the highlighted text. Given that useAnchor uses document.getSelection,
|
|
157
|
+
// it will return null, since it can't find the <mark> element within the Link UI.
|
|
158
|
+
// This caches the last truthy value of the selection anchor reference.
|
|
159
|
+
// This ensures the Popover is positioned correctly on initial submission of the link.
|
|
160
|
+
const cachedRect = useCachedTruthy(popoverAnchor.getBoundingClientRect());
|
|
161
|
+
popoverAnchor.getBoundingClientRect = () => cachedRect;
|
|
162
162
|
|
|
163
163
|
// Focus should only be moved into the Popover when the Link is being created or edited.
|
|
164
164
|
// When the Link is in "preview" mode focus should remain on the rich text because at
|
|
@@ -192,9 +192,9 @@ function InlineLinkUI({
|
|
|
192
192
|
onClose: stopAddingLink,
|
|
193
193
|
onFocusOutside: () => stopAddingLink(false),
|
|
194
194
|
placement: "bottom",
|
|
195
|
+
offset: 10,
|
|
195
196
|
shift: true
|
|
196
197
|
}, createElement(LinkControl, {
|
|
197
|
-
key: forceRemountKey,
|
|
198
198
|
value: linkValue,
|
|
199
199
|
onChange: onChangeLink,
|
|
200
200
|
onRemove: removeLink,
|
|
@@ -204,7 +204,16 @@ function InlineLinkUI({
|
|
|
204
204
|
withCreateSuggestion: userCanCreatePages,
|
|
205
205
|
createSuggestionButtonText: createButtonText,
|
|
206
206
|
hasTextControl: true,
|
|
207
|
-
settings: LINK_SETTINGS
|
|
207
|
+
settings: LINK_SETTINGS,
|
|
208
|
+
showInitialSuggestions: true,
|
|
209
|
+
suggestionsQuery: {
|
|
210
|
+
// always show Pages as initial suggestions
|
|
211
|
+
initialSuggestionsSearchOptions: {
|
|
212
|
+
type: 'post',
|
|
213
|
+
subtype: 'page',
|
|
214
|
+
perPage: 20
|
|
215
|
+
}
|
|
216
|
+
}
|
|
208
217
|
}));
|
|
209
218
|
}
|
|
210
219
|
function getRichTextValueFromSelection(value, isActive) {
|
|
@@ -1 +1 @@
|
|
|
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,WA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B,KAAK,EAAEuE,SAAS,EAAEC,OAAQ,CAAC;AAC1C;AAEA,eAAe5E,YAAY"}
|
|
1
|
+
{"version":3,"names":["useMemo","useRef","createInterpolateElement","__","sprintf","speak","Popover","prependHTTP","create","insert","isCollapsed","applyFormat","removeFormat","slice","replace","split","concat","useAnchor","__experimentalLinkControl","LinkControl","store","blockEditorStore","useCachedTruthy","useSelect","createLinkFormat","isValidHref","getFormatBoundary","link","settings","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","hasLink","isNewLink","newUrl","linkFormat","undefined","String","opensInNewWindow","newText","toInsert","length","boundary","valBefore","valAfter","start","newValAfter","returnFocusToRichText","popoverAnchor","editableContentElement","current","cachedRect","getBoundingClientRect","focusOnMount","handleCreate","pageTitle","page","status","rendered","kind","createButtonText","searchTerm","mark","createElement","anchor","onClose","onFocusOutside","placement","offset","shift","onRemove","forceIsEditingLink","hasRichPreviews","createSuggestion","withCreateSuggestion","createSuggestionButtonText","hasTextControl","showInitialSuggestions","suggestionsQuery","initialSuggestionsSearchOptions","subtype","perPage","textStart","textEnd","end"],"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\tremoveFormat,\n\tslice,\n\treplace,\n\tsplit,\n\tconcat,\n\tuseAnchor,\n} from '@wordpress/rich-text';\nimport {\n\t__experimentalLinkControl as LinkControl,\n\tstore as blockEditorStore,\n\tuseCachedTruthy,\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';\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\tconst hasLink = linkValue?.url;\n\t\tconst isNewLink = ! hasLink;\n\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\tonChange( newValue );\n\t\t}\n\n\t\t// Focus should only be returned to the rich text on submit if this link is not\n\t\t// being created for the first time. If it is then focus should remain within the\n\t\t// Link UI because it should remain open for the user to modify the link they have\n\t\t// just created.\n\t\tif ( ! isNewLink ) {\n\t\t\tconst returnFocusToRichText = true;\n\t\t\tstopAddingLink( returnFocusToRichText );\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// As you change the link by interacting with the Link UI\n\t// the return value of document.getSelection jumps to the field you're editing,\n\t// not the highlighted text. Given that useAnchor uses document.getSelection,\n\t// it will return null, since it can't find the <mark> element within the Link UI.\n\t// This caches the last truthy value of the selection anchor reference.\n\t// This ensures the Popover is positioned correctly on initial submission of the link.\n\tconst cachedRect = useCachedTruthy( popoverAnchor.getBoundingClientRect() );\n\tpopoverAnchor.getBoundingClientRect = () => cachedRect;\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\toffset={ 10 }\n\t\t\tshift\n\t\t>\n\t\t\t<LinkControl\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\tshowInitialSuggestions={ true }\n\t\t\t\tsuggestionsQuery={ {\n\t\t\t\t\t// always show Pages as initial suggestions\n\t\t\t\t\tinitialSuggestionsSearchOptions: {\n\t\t\t\t\t\ttype: 'post',\n\t\t\t\t\t\tsubtype: 'page',\n\t\t\t\t\t\tperPage: 20,\n\t\t\t\t\t},\n\t\t\t\t} }\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,YAAY,EACZC,KAAK,EACLC,OAAO,EACP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AO,GAAGzC,QAAQ,CAAC0C,GAAG,GAAG,CAAC;EAC3B;;EAEA;EACA,OAAOvG,KAAK,CAAEwB,KAAK,EAAE6E,SAAS,EAAEC,OAAQ,CAAC;AAC1C;AAEA,eAAelF,YAAY"}
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
--wp-block-synced-color: #7a00df;
|
|
98
98
|
--wp-block-synced-color--rgb: 122, 0, 223;
|
|
99
99
|
}
|
|
100
|
-
@media (
|
|
100
|
+
@media (min-resolution: 192dpi) {
|
|
101
101
|
:root {
|
|
102
102
|
--wp-admin-border-width-focus: 1.5px;
|
|
103
103
|
}
|
package/build-style/style.css
CHANGED
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
--wp-block-synced-color: #7a00df;
|
|
98
98
|
--wp-block-synced-color--rgb: 122, 0, 223;
|
|
99
99
|
}
|
|
100
|
-
@media (
|
|
100
|
+
@media (min-resolution: 192dpi) {
|
|
101
101
|
:root {
|
|
102
102
|
--wp-admin-border-width-focus: 1.5px;
|
|
103
103
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/format-library",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.27.0",
|
|
4
4
|
"description": "Format library for the WordPress editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -26,18 +26,18 @@
|
|
|
26
26
|
"react-native": "src/index",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@babel/runtime": "^7.16.0",
|
|
29
|
-
"@wordpress/a11y": "^3.
|
|
30
|
-
"@wordpress/block-editor": "^12.
|
|
31
|
-
"@wordpress/components": "^25.
|
|
32
|
-
"@wordpress/compose": "^6.
|
|
33
|
-
"@wordpress/data": "^9.
|
|
34
|
-
"@wordpress/element": "^5.
|
|
35
|
-
"@wordpress/html-entities": "^3.
|
|
36
|
-
"@wordpress/i18n": "^4.
|
|
37
|
-
"@wordpress/icons": "^9.
|
|
38
|
-
"@wordpress/private-apis": "^0.
|
|
39
|
-
"@wordpress/rich-text": "^6.
|
|
40
|
-
"@wordpress/url": "^3.
|
|
29
|
+
"@wordpress/a11y": "^3.50.0",
|
|
30
|
+
"@wordpress/block-editor": "^12.18.0",
|
|
31
|
+
"@wordpress/components": "^25.16.0",
|
|
32
|
+
"@wordpress/compose": "^6.27.0",
|
|
33
|
+
"@wordpress/data": "^9.20.0",
|
|
34
|
+
"@wordpress/element": "^5.27.0",
|
|
35
|
+
"@wordpress/html-entities": "^3.50.0",
|
|
36
|
+
"@wordpress/i18n": "^4.50.0",
|
|
37
|
+
"@wordpress/icons": "^9.41.0",
|
|
38
|
+
"@wordpress/private-apis": "^0.32.0",
|
|
39
|
+
"@wordpress/rich-text": "^6.27.0",
|
|
40
|
+
"@wordpress/url": "^3.51.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": "^18.0.0",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "45de2cb4212fed7f2763e95f10300d1ff9d0ec08"
|
|
50
50
|
}
|
package/src/link/inline.js
CHANGED
|
@@ -11,16 +11,17 @@ import {
|
|
|
11
11
|
insert,
|
|
12
12
|
isCollapsed,
|
|
13
13
|
applyFormat,
|
|
14
|
-
useAnchor,
|
|
15
14
|
removeFormat,
|
|
16
15
|
slice,
|
|
17
16
|
replace,
|
|
18
17
|
split,
|
|
19
18
|
concat,
|
|
19
|
+
useAnchor,
|
|
20
20
|
} from '@wordpress/rich-text';
|
|
21
21
|
import {
|
|
22
22
|
__experimentalLinkControl as LinkControl,
|
|
23
23
|
store as blockEditorStore,
|
|
24
|
+
useCachedTruthy,
|
|
24
25
|
} from '@wordpress/block-editor';
|
|
25
26
|
import { useSelect } from '@wordpress/data';
|
|
26
27
|
|
|
@@ -29,7 +30,6 @@ import { useSelect } from '@wordpress/data';
|
|
|
29
30
|
*/
|
|
30
31
|
import { createLinkFormat, isValidHref, getFormatBoundary } from './utils';
|
|
31
32
|
import { link as settings } from './index';
|
|
32
|
-
import useLinkInstanceKey from './use-link-instance-key';
|
|
33
33
|
|
|
34
34
|
const LINK_SETTINGS = [
|
|
35
35
|
...LinkControl.DEFAULT_LINK_SETTINGS,
|
|
@@ -90,12 +90,9 @@ function InlineLinkUI( {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
function onChangeLink( nextValue ) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const didToggleSetting =
|
|
97
|
-
linkValue.opensInNewTab !== nextValue.opensInNewTab &&
|
|
98
|
-
nextValue.url === undefined;
|
|
93
|
+
const hasLink = linkValue?.url;
|
|
94
|
+
const isNewLink = ! hasLink;
|
|
95
|
+
|
|
99
96
|
// Merge the next value with the current link value.
|
|
100
97
|
nextValue = {
|
|
101
98
|
...linkValue,
|
|
@@ -178,17 +175,16 @@ function InlineLinkUI( {
|
|
|
178
175
|
newValue = concat( valBefore, newValAfter );
|
|
179
176
|
}
|
|
180
177
|
|
|
181
|
-
newValue.start = newValue.end;
|
|
182
|
-
|
|
183
|
-
// Hides the Link UI.
|
|
184
|
-
newValue.activeFormats = [];
|
|
185
178
|
onChange( newValue );
|
|
186
179
|
}
|
|
187
180
|
|
|
188
|
-
// Focus should only be
|
|
189
|
-
//
|
|
190
|
-
|
|
191
|
-
|
|
181
|
+
// Focus should only be returned to the rich text on submit if this link is not
|
|
182
|
+
// being created for the first time. If it is then focus should remain within the
|
|
183
|
+
// Link UI because it should remain open for the user to modify the link they have
|
|
184
|
+
// just created.
|
|
185
|
+
if ( ! isNewLink ) {
|
|
186
|
+
const returnFocusToRichText = true;
|
|
187
|
+
stopAddingLink( returnFocusToRichText );
|
|
192
188
|
}
|
|
193
189
|
|
|
194
190
|
if ( ! isValidHref( newUrl ) ) {
|
|
@@ -210,11 +206,14 @@ function InlineLinkUI( {
|
|
|
210
206
|
settings,
|
|
211
207
|
} );
|
|
212
208
|
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
|
|
209
|
+
// As you change the link by interacting with the Link UI
|
|
210
|
+
// the return value of document.getSelection jumps to the field you're editing,
|
|
211
|
+
// not the highlighted text. Given that useAnchor uses document.getSelection,
|
|
212
|
+
// it will return null, since it can't find the <mark> element within the Link UI.
|
|
213
|
+
// This caches the last truthy value of the selection anchor reference.
|
|
214
|
+
// This ensures the Popover is positioned correctly on initial submission of the link.
|
|
215
|
+
const cachedRect = useCachedTruthy( popoverAnchor.getBoundingClientRect() );
|
|
216
|
+
popoverAnchor.getBoundingClientRect = () => cachedRect;
|
|
218
217
|
|
|
219
218
|
// Focus should only be moved into the Popover when the Link is being created or edited.
|
|
220
219
|
// When the Link is in "preview" mode focus should remain on the rich text because at
|
|
@@ -257,10 +256,10 @@ function InlineLinkUI( {
|
|
|
257
256
|
onClose={ stopAddingLink }
|
|
258
257
|
onFocusOutside={ () => stopAddingLink( false ) }
|
|
259
258
|
placement="bottom"
|
|
259
|
+
offset={ 10 }
|
|
260
260
|
shift
|
|
261
261
|
>
|
|
262
262
|
<LinkControl
|
|
263
|
-
key={ forceRemountKey }
|
|
264
263
|
value={ linkValue }
|
|
265
264
|
onChange={ onChangeLink }
|
|
266
265
|
onRemove={ removeLink }
|
|
@@ -271,6 +270,15 @@ function InlineLinkUI( {
|
|
|
271
270
|
createSuggestionButtonText={ createButtonText }
|
|
272
271
|
hasTextControl
|
|
273
272
|
settings={ LINK_SETTINGS }
|
|
273
|
+
showInitialSuggestions={ true }
|
|
274
|
+
suggestionsQuery={ {
|
|
275
|
+
// always show Pages as initial suggestions
|
|
276
|
+
initialSuggestionsSearchOptions: {
|
|
277
|
+
type: 'post',
|
|
278
|
+
subtype: 'page',
|
|
279
|
+
perPage: 20,
|
|
280
|
+
},
|
|
281
|
+
} }
|
|
274
282
|
/>
|
|
275
283
|
</Popover>
|
|
276
284
|
);
|