@wordpress/format-library 4.15.0 → 4.16.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 CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.16.0 (2023-08-10)
6
+
5
7
  ## 4.15.0 (2023-07-20)
6
8
 
7
9
  ## 4.14.0 (2023-07-05)
@@ -11,6 +11,8 @@ var _element = require("@wordpress/element");
11
11
 
12
12
  var _i18n = require("@wordpress/i18n");
13
13
 
14
+ var _a11y = require("@wordpress/a11y");
15
+
14
16
  var _components = require("@wordpress/components");
15
17
 
16
18
  var _url = require("@wordpress/url");
@@ -40,7 +42,6 @@ function InlineLinkUI({
40
42
  addingLink,
41
43
  value,
42
44
  onChange,
43
- speak,
44
45
  stopAddingLink,
45
46
  contentRef
46
47
  }) {
@@ -85,7 +86,7 @@ function InlineLinkUI({
85
86
  const newValue = (0, _richText.removeFormat)(value, 'core/link');
86
87
  onChange(newValue);
87
88
  stopAddingLink();
88
- speak((0, _i18n.__)('Link removed.'), 'assertive');
89
+ (0, _a11y.speak)((0, _i18n.__)('Link removed.'), 'assertive');
89
90
  }
90
91
 
91
92
  function onChangeLink(nextValue) {
@@ -177,11 +178,11 @@ function InlineLinkUI({
177
178
  }
178
179
 
179
180
  if (!(0, _utils.isValidHref)(newUrl)) {
180
- speak((0, _i18n.__)('Warning: the link has been inserted but may have errors. Please test it.'), 'assertive');
181
+ (0, _a11y.speak)((0, _i18n.__)('Warning: the link has been inserted but may have errors. Please test it.'), 'assertive');
181
182
  } else if (isActive) {
182
- speak((0, _i18n.__)('Link edited.'), 'assertive');
183
+ (0, _a11y.speak)((0, _i18n.__)('Link edited.'), 'assertive');
183
184
  } else {
184
- speak((0, _i18n.__)('Link inserted.'), 'assertive');
185
+ (0, _a11y.speak)((0, _i18n.__)('Link inserted.'), 'assertive');
185
186
  }
186
187
  }
187
188
 
@@ -262,7 +263,6 @@ function getRichTextValueFromSelection(value, isActive) {
262
263
  return (0, _richText.slice)(value, textStart, textEnd);
263
264
  }
264
265
 
265
- var _default = (0, _components.withSpokenMessages)(InlineLinkUI);
266
-
266
+ var _default = InlineLinkUI;
267
267
  exports.default = _default;
268
268
  //# sourceMappingURL=inline.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/link/inline.js"],"names":["InlineLinkUI","isActive","activeAttributes","addingLink","value","onChange","speak","stopAddingLink","contentRef","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","nextLinkValue","setNextLinkValue","createPageEntity","userCanCreatePages","select","getSettings","blockEditorStore","_settings","__experimentalCreatePageEntity","__experimentalUserCanCreatePages","linkValue","url","type","id","opensInNewTab","target","title","removeLink","newValue","onChangeLink","nextValue","didToggleSetting","didToggleSettingForNewLink","undefined","newUrl","linkFormat","String","opensInNewWindow","newText","toInsert","length","boundary","valBefore","valAfter","start","newValAfter","end","activeFormats","popoverAnchor","editableContentElement","current","settings","forceRemountKey","focusOnMount","handleCreate","pageTitle","page","status","rendered","link","kind","createButtonText","searchTerm","mark","textStart","textEnd"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAYA;;AAIA;;AAKA;;AACA;;AACA;;AA9BA;AACA;AACA;;AAuBA;AACA;AACA;AAKA,SAASA,YAAT,CAAuB;AACtBC,EAAAA,QADsB;AAEtBC,EAAAA,gBAFsB;AAGtBC,EAAAA,UAHsB;AAItBC,EAAAA,KAJsB;AAKtBC,EAAAA,QALsB;AAMtBC,EAAAA,KANsB;AAOtBC,EAAAA,cAPsB;AAQtBC,EAAAA;AARsB,CAAvB,EASI;AACH,QAAMC,iBAAiB,GAAGC,6BAA6B,CAAEN,KAAF,EAASH,QAAT,CAAvD,CADG,CAGH;;AACA,QAAMU,YAAY,GAAGF,iBAAiB,CAACG,IAAvC;AAEA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;;AACC,QAAM,CAAEC,aAAF,EA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MANhB;AAOC,IAAA,gBAAgB,EAAGY,gBAAgB,IAAI0C,YAPxC;AAQC,IAAA,oBAAoB,EAAGzC,kBARxB;AASC,IAAA,0BAA0B,EAAGgD,gBAT9B;AAUC,IAAA,cAAc;AAVf,IARD,CADD;AAuBA;;AAED,SAAStD,6BAAT,CAAwCN,KAAxC,EAA+CH,QAA/C,EAA0D;AACzD;AACA,MAAIkE,SAAS,GAAG/D,KAAK,CAAC2C,KAAtB;AACA,MAAIqB,OAAO,GAAGhE,KAAK,CAAC6C,GAApB,CAHyD,CAKzD;AACA;AACA;;AACA,MAAKhD,QAAL,EAAgB;AACf,UAAM2C,QAAQ,GAAG,8BAAmBxC,KAAnB,EAA0B;AAC1CqB,MAAAA,IAAI,EAAE;AADoC,KAA1B,CAAjB;AAIA0C,IAAAA,SAAS,GAAGvB,QAAQ,CAACG,KAArB,CALe,CAOf;AACA;;AACAqB,IAAAA,OAAO,GAAGxB,QAAQ,CAACK,GAAT,GAAe,CAAzB;AACA,GAlBwD,CAoBzD;;;AACA,SAAO,qBAAO7C,KAAP,EAAc+D,SAAd,EAAyBC,OAAzB,CAAP;AACA;;eAEc,oCAAoBpE,YAApB,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useRef, createInterpolateElement } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { withSpokenMessages, 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\nfunction InlineLinkUI( {\n\tisActive,\n\tactiveAttributes,\n\taddingLink,\n\tvalue,\n\tonChange,\n\tspeak,\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\t/**\n\t * Pending settings to be applied to the next link. When inserting a new\n\t * link, toggle values cannot be applied immediately, because there is not\n\t * yet a link for them to apply to. Thus, they are maintained in a state\n\t * value until the time that the link can be inserted or edited.\n\t *\n\t * @type {[Object|undefined,Function]}\n\t */\n\tconst [ nextLinkValue, setNextLinkValue ] = useState();\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\ttitle: richTextText,\n\t\t...nextLinkValue,\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// Merge with values from state, both for the purpose of assigning the\n\t\t// next state value, and for use in constructing the new link format if\n\t\t// the link is ready to be applied.\n\t\tnextValue = {\n\t\t\t...nextLinkValue,\n\t\t\t...nextValue,\n\t\t};\n\n\t\t// LinkControl calls `onChange` immediately upon the toggling a setting.\n\t\tconst didToggleSetting =\n\t\t\tlinkValue.opensInNewTab !== nextValue.opensInNewTab &&\n\t\t\tlinkValue.url === nextValue.url;\n\n\t\t// If change handler was called as a result of a settings change during\n\t\t// link insertion, it must be held in state until the link is ready to\n\t\t// be applied.\n\t\tconst didToggleSettingForNewLink =\n\t\t\tdidToggleSetting && nextValue.url === undefined;\n\n\t\t// If link will be assigned, the state value can be considered flushed.\n\t\t// Otherwise, persist the pending changes.\n\t\tsetNextLinkValue( didToggleSettingForNewLink ? nextValue : undefined );\n\n\t\tif ( didToggleSettingForNewLink ) {\n\t\t\treturn;\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} );\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\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/>\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 withSpokenMessages( InlineLinkUI );\n"]}
1
+ {"version":3,"sources":["@wordpress/format-library/src/link/inline.js"],"names":["InlineLinkUI","isActive","activeAttributes","addingLink","value","onChange","stopAddingLink","contentRef","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","nextLinkValue","setNextLinkValue","createPageEntity","userCanCreatePages","select","getSettings","blockEditorStore","_settings","__experimentalCreatePageEntity","__experimentalUserCanCreatePages","linkValue","url","type","id","opensInNewTab","target","title","removeLink","newValue","onChangeLink","nextValue","didToggleSetting","didToggleSettingForNewLink","undefined","newUrl","linkFormat","String","opensInNewWindow","newText","toInsert","length","boundary","valBefore","valAfter","start","newValAfter","end","activeFormats","popoverAnchor","editableContentElement","current","settings","forceRemountKey","focusOnMount","handleCreate","pageTitle","page","status","rendered","link","kind","createButtonText","searchTerm","mark","textStart","textEnd"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAYA;;AAIA;;AAKA;;AACA;;AACA;;AA/BA;AACA;AACA;;AAwBA;AACA;AACA;AAKA,SAASA,YAAT,CAAuB;AACtBC,EAAAA,QADsB;AAEtBC,EAAAA,gBAFsB;AAGtBC,EAAAA,UAHsB;AAItBC,EAAAA,KAJsB;AAKtBC,EAAAA,QALsB;AAMtBC,EAAAA,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P;AAEC,IAAA,KAAK,EAAGhC,SAFT;AAGC,IAAA,QAAQ,EAAGS,YAHZ;AAIC,IAAA,QAAQ,EAAGF,UAJZ;AAKC,IAAA,kBAAkB,EAAG1B,UALtB;AAMC,IAAA,eAAe,MANhB;AAOC,IAAA,gBAAgB,EAAGW,gBAAgB,IAAI0C,YAPxC;AAQC,IAAA,oBAAoB,EAAGzC,kBARxB;AASC,IAAA,0BAA0B,EAAGgD,gBAT9B;AAUC,IAAA,cAAc;AAVf,IARD,CADD;AAuBA;;AAED,SAAStD,6BAAT,CAAwCL,KAAxC,EAA+CH,QAA/C,EAA0D;AACzD;AACA,MAAIiE,SAAS,GAAG9D,KAAK,CAAC0C,KAAtB;AACA,MAAIqB,OAAO,GAAG/D,KAAK,CAAC4C,GAApB,CAHyD,CAKzD;AACA;AACA;;AACA,MAAK/C,QAAL,EAAgB;AACf,UAAM0C,QAAQ,GAAG,8BAAmBvC,KAAnB,EAA0B;AAC1CoB,MAAAA,IAAI,EAAE;AADoC,KAA1B,CAAjB;AAIA0C,IAAAA,SAAS,GAAGvB,QAAQ,CAACG,KAArB,CALe,CAOf;AACA;;AACAqB,IAAAA,OAAO,GAAGxB,QAAQ,CAACK,GAAT,GAAe,CAAzB;AACA,GAlBwD,CAoBzD;;;AACA,SAAO,qBAAO5C,KAAP,EAAc8D,SAAd,EAAyBC,OAAzB,CAAP;AACA;;eAEcnE,Y","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, 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\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\t/**\n\t * Pending settings to be applied to the next link. When inserting a new\n\t * link, toggle values cannot be applied immediately, because there is not\n\t * yet a link for them to apply to. Thus, they are maintained in a state\n\t * value until the time that the link can be inserted or edited.\n\t *\n\t * @type {[Object|undefined,Function]}\n\t */\n\tconst [ nextLinkValue, setNextLinkValue ] = useState();\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\ttitle: richTextText,\n\t\t...nextLinkValue,\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// Merge with values from state, both for the purpose of assigning the\n\t\t// next state value, and for use in constructing the new link format if\n\t\t// the link is ready to be applied.\n\t\tnextValue = {\n\t\t\t...nextLinkValue,\n\t\t\t...nextValue,\n\t\t};\n\n\t\t// LinkControl calls `onChange` immediately upon the toggling a setting.\n\t\tconst didToggleSetting =\n\t\t\tlinkValue.opensInNewTab !== nextValue.opensInNewTab &&\n\t\t\tlinkValue.url === nextValue.url;\n\n\t\t// If change handler was called as a result of a settings change during\n\t\t// link insertion, it must be held in state until the link is ready to\n\t\t// be applied.\n\t\tconst didToggleSettingForNewLink =\n\t\t\tdidToggleSetting && nextValue.url === undefined;\n\n\t\t// If link will be assigned, the state value can be considered flushed.\n\t\t// Otherwise, persist the pending changes.\n\t\tsetNextLinkValue( didToggleSettingForNewLink ? nextValue : undefined );\n\n\t\tif ( didToggleSettingForNewLink ) {\n\t\t\treturn;\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} );\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\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/>\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"]}
@@ -5,7 +5,8 @@ import { createElement } from "@wordpress/element";
5
5
  */
6
6
  import { useState, useRef, createInterpolateElement } from '@wordpress/element';
7
7
  import { __, sprintf } from '@wordpress/i18n';
8
- import { withSpokenMessages, Popover } from '@wordpress/components';
8
+ import { speak } from '@wordpress/a11y';
9
+ import { Popover } from '@wordpress/components';
9
10
  import { prependHTTP } from '@wordpress/url';
10
11
  import { create, insert, isCollapsed, applyFormat, useAnchor, removeFormat, slice, replace, split, concat } from '@wordpress/rich-text';
11
12
  import { __experimentalLinkControl as LinkControl, store as blockEditorStore } from '@wordpress/block-editor';
@@ -24,7 +25,6 @@ function InlineLinkUI({
24
25
  addingLink,
25
26
  value,
26
27
  onChange,
27
- speak,
28
28
  stopAddingLink,
29
29
  contentRef
30
30
  }) {
@@ -246,5 +246,5 @@ function getRichTextValueFromSelection(value, isActive) {
246
246
  return slice(value, textStart, textEnd);
247
247
  }
248
248
 
249
- export default withSpokenMessages(InlineLinkUI);
249
+ export default InlineLinkUI;
250
250
  //# sourceMappingURL=inline.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/link/inline.js"],"names":["useState","useRef","createInterpolateElement","__","sprintf","withSpokenMessages","Popover","prependHTTP","create","insert","isCollapsed","applyFormat","useAnchor","removeFormat","slice","replace","split","concat","__experimentalLinkControl","LinkControl","store","blockEditorStore","useSelect","createLinkFormat","isValidHref","getFormatBoundary","link","settings","useLinkInstanceKey","InlineLinkUI","isActive","activeAttributes","addingLink","value","onChange","speak","stopAddingLink","contentRef","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","nextLinkValue","setNextLinkValue","createPageEntity","userCanCreatePages","select","getSettings","_settings","__experimentalCreatePageEntity","__experimentalUserCanCreatePages","linkValue","url","type","id","opensInNewTab","target","title","removeLink","newValue","onChangeLink","nextValue","didToggleSetting","didToggleSettingForNewLink","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","textStart","textEnd"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,MAAnB,EAA2BC,wBAA3B,QAA2D,oBAA3D;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,kBAAT,EAA6BC,OAA7B,QAA4C,uBAA5C;AACA,SAASC,WAAT,QAA4B,gBAA5B;AACA,SACCC,MADD,EAECC,MAFD,EAGCC,WAHD,EAICC,WAJD,EAKCC,SALD,EAMCC,YAND,EAOCC,KAPD,EAQCC,OARD,EASCC,KATD,EAUCC,MAVD,QAWO,sBAXP;AAYA,SACCC,yBAAyB,IAAIC,WAD9B,EAECC,KAAK,IAAIC,gBAFV,QAGO,yBAHP;AAIA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,EAA2BC,WAA3B,EAAwCC,iBAAxC,QAA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AAS,GAAGrB,QAAQ,CAACG,KAArB,CALe,CAOf;AACA;;AACAmB,IAAAA,OAAO,GAAGtB,QAAQ,CAACK,GAAT,GAAe,CAAzB;AACA,GAlBwD,CAoBzD;;;AACA,SAAO/D,KAAK,CAAEmB,KAAF,EAAS4D,SAAT,EAAoBC,OAApB,CAAZ;AACA;;AAED,eAAezF,kBAAkB,CAAEwB,YAAF,CAAjC","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useRef, createInterpolateElement } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { withSpokenMessages, 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\nfunction InlineLinkUI( {\n\tisActive,\n\tactiveAttributes,\n\taddingLink,\n\tvalue,\n\tonChange,\n\tspeak,\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\t/**\n\t * Pending settings to be applied to the next link. When inserting a new\n\t * link, toggle values cannot be applied immediately, because there is not\n\t * yet a link for them to apply to. Thus, they are maintained in a state\n\t * value until the time that the link can be inserted or edited.\n\t *\n\t * @type {[Object|undefined,Function]}\n\t */\n\tconst [ nextLinkValue, setNextLinkValue ] = useState();\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\ttitle: richTextText,\n\t\t...nextLinkValue,\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// Merge with values from state, both for the purpose of assigning the\n\t\t// next state value, and for use in constructing the new link format if\n\t\t// the link is ready to be applied.\n\t\tnextValue = {\n\t\t\t...nextLinkValue,\n\t\t\t...nextValue,\n\t\t};\n\n\t\t// LinkControl calls `onChange` immediately upon the toggling a setting.\n\t\tconst didToggleSetting =\n\t\t\tlinkValue.opensInNewTab !== nextValue.opensInNewTab &&\n\t\t\tlinkValue.url === nextValue.url;\n\n\t\t// If change handler was called as a result of a settings change during\n\t\t// link insertion, it must be held in state until the link is ready to\n\t\t// be applied.\n\t\tconst didToggleSettingForNewLink =\n\t\t\tdidToggleSetting && nextValue.url === undefined;\n\n\t\t// If link will be assigned, the state value can be considered flushed.\n\t\t// Otherwise, persist the pending changes.\n\t\tsetNextLinkValue( didToggleSettingForNewLink ? nextValue : undefined );\n\n\t\tif ( didToggleSettingForNewLink ) {\n\t\t\treturn;\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} );\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\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/>\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 withSpokenMessages( InlineLinkUI );\n"]}
1
+ {"version":3,"sources":["@wordpress/format-library/src/link/inline.js"],"names":["useState","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","InlineLinkUI","isActive","activeAttributes","addingLink","value","onChange","stopAddingLink","contentRef","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","nextLinkValue","setNextLinkValue","createPageEntity","userCanCreatePages","select","getSettings","_settings","__experimentalCreatePageEntity","__experimentalUserCanCreatePages","linkValue","url","type","id","opensInNewTab","target","title","removeLink","newValue","onChangeLink","nextValue","didToggleSetting","didToggleSettingForNewLink","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","textStart","textEnd"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,MAAnB,EAA2BC,wBAA3B,QAA2D,oBAA3D;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,KAAT,QAAsB,iBAAtB;AACA,SAASC,OAAT,QAAwB,uBAAxB;AACA,SAASC,WAAT,QAA4B,gBAA5B;AACA,SACCC,MADD,EAECC,MAFD,EAGCC,WAHD,EAICC,WAJD,EAKCC,SALD,EAMCC,YAND,EAOCC,KAPD,EAQCC,OARD,EASCC,KATD,EAUCC,MAVD,QAWO,sBAXP;AAYA,SACCC,yBAAyB,IAAIC,WAD9B,EAECC,KAAK,IAAIC,gBAFV,QAGO,yBAHP;AAIA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,EAA2BC,WAA3B,EAAwCC,iBAAxC,QAAiE,SAAjE;AACA,SAASC,IAAI,IAAIC,QAA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AO,GAAGtB,QAAQ,CAACK,GAAT,GAAe,CAAzB;AACA,GAlBwD,CAoBzD;;;AACA,SAAO9D,KAAK,CAAEmB,KAAF,EAAS2D,SAAT,EAAoBC,OAApB,CAAZ;AACA;;AAED,eAAehE,YAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, 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\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\t/**\n\t * Pending settings to be applied to the next link. When inserting a new\n\t * link, toggle values cannot be applied immediately, because there is not\n\t * yet a link for them to apply to. Thus, they are maintained in a state\n\t * value until the time that the link can be inserted or edited.\n\t *\n\t * @type {[Object|undefined,Function]}\n\t */\n\tconst [ nextLinkValue, setNextLinkValue ] = useState();\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\ttitle: richTextText,\n\t\t...nextLinkValue,\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// Merge with values from state, both for the purpose of assigning the\n\t\t// next state value, and for use in constructing the new link format if\n\t\t// the link is ready to be applied.\n\t\tnextValue = {\n\t\t\t...nextLinkValue,\n\t\t\t...nextValue,\n\t\t};\n\n\t\t// LinkControl calls `onChange` immediately upon the toggling a setting.\n\t\tconst didToggleSetting =\n\t\t\tlinkValue.opensInNewTab !== nextValue.opensInNewTab &&\n\t\t\tlinkValue.url === nextValue.url;\n\n\t\t// If change handler was called as a result of a settings change during\n\t\t// link insertion, it must be held in state until the link is ready to\n\t\t// be applied.\n\t\tconst didToggleSettingForNewLink =\n\t\t\tdidToggleSetting && nextValue.url === undefined;\n\n\t\t// If link will be assigned, the state value can be considered flushed.\n\t\t// Otherwise, persist the pending changes.\n\t\tsetNextLinkValue( didToggleSettingForNewLink ? nextValue : undefined );\n\n\t\tif ( didToggleSettingForNewLink ) {\n\t\t\treturn;\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} );\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\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/>\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/format-library",
3
- "version": "4.15.0",
3
+ "version": "4.16.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,17 +26,17 @@
26
26
  "react-native": "src/index",
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.16.0",
29
- "@wordpress/a11y": "^3.38.0",
30
- "@wordpress/block-editor": "^12.6.0",
31
- "@wordpress/components": "^25.4.0",
32
- "@wordpress/compose": "^6.15.0",
33
- "@wordpress/data": "^9.8.0",
34
- "@wordpress/element": "^5.15.0",
35
- "@wordpress/html-entities": "^3.38.0",
36
- "@wordpress/i18n": "^4.38.0",
37
- "@wordpress/icons": "^9.29.0",
38
- "@wordpress/rich-text": "^6.15.0",
39
- "@wordpress/url": "^3.39.0"
29
+ "@wordpress/a11y": "^3.39.0",
30
+ "@wordpress/block-editor": "^12.7.0",
31
+ "@wordpress/components": "^25.5.0",
32
+ "@wordpress/compose": "^6.16.0",
33
+ "@wordpress/data": "^9.9.0",
34
+ "@wordpress/element": "^5.16.0",
35
+ "@wordpress/html-entities": "^3.39.0",
36
+ "@wordpress/i18n": "^4.39.0",
37
+ "@wordpress/icons": "^9.30.0",
38
+ "@wordpress/rich-text": "^6.16.0",
39
+ "@wordpress/url": "^3.40.0"
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": "6f14d11ed4cb59df110a28ebaa23ecba95eb673a"
48
+ "gitHead": "b898cf1dc8e70841d1647ea0994ac6278acc18a7"
49
49
  }
@@ -3,7 +3,8 @@
3
3
  */
4
4
  import { useState, useRef, createInterpolateElement } from '@wordpress/element';
5
5
  import { __, sprintf } from '@wordpress/i18n';
6
- import { withSpokenMessages, Popover } from '@wordpress/components';
6
+ import { speak } from '@wordpress/a11y';
7
+ import { Popover } from '@wordpress/components';
7
8
  import { prependHTTP } from '@wordpress/url';
8
9
  import {
9
10
  create,
@@ -36,7 +37,6 @@ function InlineLinkUI( {
36
37
  addingLink,
37
38
  value,
38
39
  onChange,
39
- speak,
40
40
  stopAddingLink,
41
41
  contentRef,
42
42
  } ) {
@@ -299,4 +299,4 @@ function getRichTextValueFromSelection( value, isActive ) {
299
299
  return slice( value, textStart, textEnd );
300
300
  }
301
301
 
302
- export default withSpokenMessages( InlineLinkUI );
302
+ export default InlineLinkUI;
@@ -44,13 +44,18 @@ exports[`LinksUI LinksUI renders 1`] = `
44
44
  }
45
45
  >
46
46
  <View
47
- style={
48
- [
49
- undefined,
50
- {
47
+ animatedStyle={
48
+ {
49
+ "value": {
51
50
  "height": 1,
52
51
  },
53
- ]
52
+ }
53
+ }
54
+ collapsable={false}
55
+ style={
56
+ {
57
+ "height": 1,
58
+ }
54
59
  }
55
60
  >
56
61
  <RNGestureHandlerRootView
@@ -61,213 +66,248 @@ exports[`LinksUI LinksUI renders 1`] = `
61
66
  }
62
67
  >
63
68
  <View
64
- onLayout={[Function]}
65
69
  style={
66
- {
67
- "flex": 1,
68
- }
70
+ [
71
+ {
72
+ "backgroundColor": undefined,
73
+ "flex": 1,
74
+ },
75
+ undefined,
76
+ ]
69
77
  }
70
78
  >
71
79
  <View
72
- pointerEvents="box-none"
80
+ onLayout={[Function]}
73
81
  style={
74
82
  {
75
- "bottom": 0,
76
- "left": 0,
77
- "position": "absolute",
78
- "right": 0,
79
- "top": 0,
83
+ "flex": 1,
80
84
  }
81
85
  }
82
86
  >
83
87
  <View
84
88
  collapsable={false}
85
- style={
86
- {
87
- "opacity": 1,
88
- }
89
- }
90
- />
91
- <View
92
- accessibilityElementsHidden={false}
93
- closing={false}
94
- gestureVelocityImpact={0.3}
95
- importantForAccessibility="auto"
96
- onClose={[Function]}
97
- onGestureBegin={[Function]}
98
- onGestureCanceled={[Function]}
99
- onOpen={[Function]}
100
- onTransitionStart={[Function]}
89
+ forwardedRef={[Function]}
101
90
  pointerEvents="box-none"
102
91
  style={
103
92
  {
104
93
  "bottom": 0,
94
+ "display": "flex",
105
95
  "left": 0,
106
96
  "position": "absolute",
107
97
  "right": 0,
108
98
  "top": 0,
109
99
  }
110
100
  }
111
- transitionSpec={
112
- {
113
- "close": {
114
- "animation": "timing",
115
- "config": {
116
- "duration": 200,
117
- "easing": [Function],
118
- },
119
- },
120
- "open": {
121
- "animation": "timing",
122
- "config": {
123
- "duration": 200,
124
- "easing": [Function],
125
- },
126
- },
127
- }
128
- }
129
101
  >
130
102
  <View
131
- pointerEvents="box-none"
103
+ collapsable={false}
132
104
  style={
133
105
  {
134
- "bottom": 0,
135
- "left": 0,
136
- "position": "absolute",
137
- "right": 0,
138
- "top": 0,
106
+ "opacity": 1,
139
107
  }
140
108
  }
141
109
  />
142
110
  <View
143
- collapsable={false}
111
+ accessibilityElementsHidden={false}
112
+ closing={false}
113
+ gestureVelocityImpact={0.3}
114
+ importantForAccessibility="auto"
115
+ onClose={[Function]}
116
+ onGestureBegin={[Function]}
117
+ onGestureCanceled={[Function]}
118
+ onGestureEnd={[Function]}
119
+ onOpen={[Function]}
120
+ onTransition={[Function]}
144
121
  pointerEvents="box-none"
145
122
  style={
123
+ [
124
+ {
125
+ "display": "flex",
126
+ "overflow": undefined,
127
+ },
128
+ {
129
+ "bottom": 0,
130
+ "left": 0,
131
+ "position": "absolute",
132
+ "right": 0,
133
+ "top": 0,
134
+ },
135
+ ]
136
+ }
137
+ transitionSpec={
146
138
  {
147
- "flex": 1,
139
+ "close": {
140
+ "animation": "timing",
141
+ "config": {
142
+ "duration": 200,
143
+ "easing": [Function],
144
+ },
145
+ },
146
+ "open": {
147
+ "animation": "timing",
148
+ "config": {
149
+ "duration": 200,
150
+ "easing": [Function],
151
+ },
152
+ },
148
153
  }
149
154
  }
150
155
  >
156
+ <View
157
+ pointerEvents="box-none"
158
+ style={
159
+ {
160
+ "bottom": 0,
161
+ "left": 0,
162
+ "position": "absolute",
163
+ "right": 0,
164
+ "top": 0,
165
+ }
166
+ }
167
+ />
151
168
  <View
152
169
  collapsable={false}
153
- forwardedRef={[Function]}
154
- handlerTag={1}
155
- handlerType="PanGestureHandler"
156
- onGestureHandlerEvent={[Function]}
157
- onGestureHandlerStateChange={[Function]}
170
+ pointerEvents="box-none"
158
171
  style={
159
172
  {
160
173
  "flex": 1,
161
- "opacity": 1,
162
174
  }
163
175
  }
164
176
  >
165
177
  <View
178
+ collapsable={false}
179
+ forwardedRef={[Function]}
180
+ handlerTag={1}
181
+ handlerType="PanGestureHandler"
182
+ needsOffscreenAlphaCompositing={true}
183
+ onGestureHandlerEvent={[Function]}
184
+ onGestureHandlerStateChange={[Function]}
166
185
  style={
167
- [
168
- {
169
- "flex": 1,
170
- "overflow": "hidden",
171
- },
172
- [
173
- {
174
- "backgroundColor": undefined,
175
- },
176
- undefined,
177
- ],
178
- ]
186
+ {
187
+ "flex": 1,
188
+ "opacity": 1,
189
+ }
179
190
  }
180
191
  >
181
192
  <View
193
+ pointerEvents="box-none"
182
194
  style={
183
- {
184
- "flex": 1,
185
- "flexDirection": "column-reverse",
186
- }
195
+ [
196
+ {
197
+ "flex": 1,
198
+ "overflow": "hidden",
199
+ },
200
+ [
201
+ {
202
+ "backgroundColor": undefined,
203
+ },
204
+ undefined,
205
+ ],
206
+ ]
187
207
  }
188
208
  >
189
209
  <View
190
210
  style={
191
211
  {
192
212
  "flex": 1,
213
+ "flexDirection": "column-reverse",
193
214
  }
194
215
  }
195
216
  >
196
- <RCTScrollView
197
- automaticallyAdjustContentInsets={false}
198
- bounces={false}
199
- contentContainerStyle={
200
- [
201
- {
202
- "paddingLeft": 8,
203
- "paddingRight": 8,
204
- },
205
- undefined,
206
- {},
207
- false,
208
- ]
209
- }
210
- disableScrollViewPanResponder={true}
211
- onScroll={[Function]}
212
- safeAreaBottomInset={0}
213
- scrollEnabled={true}
214
- scrollEventThrottle={16}
217
+ <View
215
218
  style={
216
219
  {
217
- "maxHeight": 787.06,
220
+ "flex": 1,
218
221
  }
219
222
  }
220
223
  >
221
- <View>
222
- <View
223
- accessible={false}
224
- focusable={false}
225
- onClick={[Function]}
226
- onResponderGrant={[Function]}
227
- onResponderMove={[Function]}
228
- onResponderRelease={[Function]}
229
- onResponderTerminate={[Function]}
230
- onResponderTerminationRequest={[Function]}
231
- onStartShouldSetResponder={[Function]}
232
- >
224
+ <RCTScrollView
225
+ automaticallyAdjustContentInsets={false}
226
+ bounces={false}
227
+ contentContainerStyle={
228
+ [
229
+ {
230
+ "paddingLeft": 8,
231
+ "paddingRight": 8,
232
+ },
233
+ undefined,
234
+ {},
235
+ false,
236
+ ]
237
+ }
238
+ disableScrollViewPanResponder={true}
239
+ onScroll={[Function]}
240
+ safeAreaBottomInset={0}
241
+ scrollEnabled={true}
242
+ scrollEventThrottle={16}
243
+ style={
244
+ {
245
+ "maxHeight": 787.06,
246
+ }
247
+ }
248
+ >
249
+ <View>
233
250
  <View
234
- onLayout={[Function]}
235
- testID="navigation-screen-linkSettings"
251
+ accessibilityValue={
252
+ {
253
+ "max": undefined,
254
+ "min": undefined,
255
+ "now": undefined,
256
+ "text": undefined,
257
+ }
258
+ }
259
+ accessible={false}
260
+ focusable={false}
261
+ onClick={[Function]}
262
+ onResponderGrant={[Function]}
263
+ onResponderMove={[Function]}
264
+ onResponderRelease={[Function]}
265
+ onResponderTerminate={[Function]}
266
+ onResponderTerminationRequest={[Function]}
267
+ onStartShouldSetResponder={[Function]}
236
268
  >
237
269
  <View
238
- accessibilityLabel="Link to, Search or type URL"
239
- accessibilityRole="button"
240
- accessibilityState={
241
- {
242
- "disabled": false,
243
- }
244
- }
245
- accessible={true}
246
- collapsable={false}
247
- focusable={true}
248
- onClick={[Function]}
249
- onResponderGrant={[Function]}
250
- onResponderMove={[Function]}
251
- onResponderRelease={[Function]}
252
- onResponderTerminate={[Function]}
253
- onResponderTerminationRequest={[Function]}
254
- onStartShouldSetResponder={[Function]}
255
- style={
256
- {
257
- "opacity": 1,
258
- }
259
- }
270
+ onLayout={[Function]}
271
+ testID="navigation-screen-linkSettings"
260
272
  >
261
273
  <View
262
- pointerEvents="auto"
274
+ accessibilityLabel="Link to, Search or type URL"
275
+ accessibilityRole="button"
276
+ accessibilityState={
277
+ {
278
+ "busy": undefined,
279
+ "checked": undefined,
280
+ "disabled": false,
281
+ "expanded": undefined,
282
+ "selected": undefined,
283
+ }
284
+ }
285
+ accessibilityValue={
286
+ {
287
+ "max": undefined,
288
+ "min": undefined,
289
+ "now": undefined,
290
+ "text": undefined,
291
+ }
292
+ }
293
+ accessible={true}
294
+ collapsable={false}
295
+ focusable={true}
296
+ onClick={[Function]}
297
+ onResponderGrant={[Function]}
298
+ onResponderMove={[Function]}
299
+ onResponderRelease={[Function]}
300
+ onResponderTerminate={[Function]}
301
+ onResponderTerminationRequest={[Function]}
302
+ onStartShouldSetResponder={[Function]}
263
303
  style={
264
- [
265
- undefined,
266
- {},
267
- ]
304
+ {
305
+ "opacity": 1,
306
+ }
268
307
  }
269
308
  >
270
309
  <View
310
+ pointerEvents="auto"
271
311
  style={
272
312
  [
273
313
  undefined,
@@ -275,109 +315,121 @@ exports[`LinksUI LinksUI renders 1`] = `
275
315
  ]
276
316
  }
277
317
  >
278
- <View>
279
- <View
280
- style={
281
- [
282
- undefined,
283
- undefined,
284
- ]
285
- }
286
- >
287
- <Svg
288
- height={24}
289
- lock={true}
290
- style={{}}
291
- viewBox="0 0 24 24"
292
- width={24}
293
- xmlns="http://www.w3.org/2000/svg"
318
+ <View
319
+ style={
320
+ [
321
+ undefined,
322
+ {},
323
+ ]
324
+ }
325
+ >
326
+ <View>
327
+ <View
328
+ style={
329
+ [
330
+ undefined,
331
+ undefined,
332
+ ]
333
+ }
294
334
  >
295
- Path
296
- </Svg>
297
- <View />
335
+ <Svg
336
+ height={24}
337
+ lock={true}
338
+ style={{}}
339
+ viewBox="0 0 24 24"
340
+ width={24}
341
+ xmlns="http://www.w3.org/2000/svg"
342
+ >
343
+ Path
344
+ </Svg>
345
+ <View />
346
+ </View>
347
+ <Text
348
+ style={
349
+ [
350
+ undefined,
351
+ {},
352
+ ]
353
+ }
354
+ >
355
+ Link to
356
+ </Text>
298
357
  </View>
299
- <Text
300
- style={
301
- [
302
- undefined,
303
- {},
304
- ]
358
+ </View>
359
+ <Text
360
+ ellipsizeMode="middle"
361
+ numberOfLines={1}
362
+ style={
363
+ {
364
+ "color": "gray",
305
365
  }
366
+ }
367
+ >
368
+ Search or type URL
369
+ </Text>
370
+ <View
371
+ pointerEvents="auto"
372
+ style={
373
+ [
374
+ false,
375
+ undefined,
376
+ ]
377
+ }
378
+ >
379
+ <Svg
380
+ height={24}
381
+ style={{}}
382
+ viewBox="0 0 24 24"
383
+ width={24}
384
+ xmlns="http://www.w3.org/2000/svg"
306
385
  >
307
- Link to
308
- </Text>
386
+ Path
387
+ </Svg>
309
388
  </View>
310
389
  </View>
311
- <Text
312
- ellipsizeMode="middle"
313
- numberOfLines={1}
314
- style={
315
- {
316
- "color": "gray",
317
- }
318
- }
319
- >
320
- Search or type URL
321
- </Text>
322
390
  <View
323
- pointerEvents="auto"
324
- style={
325
- [
326
- false,
327
- undefined,
328
- ]
329
- }
330
- >
331
- <Svg
332
- height={24}
333
- style={{}}
334
- viewBox="0 0 24 24"
335
- width={24}
336
- xmlns="http://www.w3.org/2000/svg"
337
- >
338
- Path
339
- </Svg>
340
- </View>
391
+ style={{}}
392
+ />
341
393
  </View>
342
394
  <View
343
- style={{}}
344
- />
345
- </View>
346
- <View
347
- accessibilityHint="Double tap to edit this value"
348
- accessibilityLabel="Link text. Empty"
349
- accessibilityRole="button"
350
- accessibilityState={
351
- {
352
- "disabled": false,
395
+ accessibilityHint="Double tap to edit this value"
396
+ accessibilityLabel="Link text. Empty"
397
+ accessibilityRole="button"
398
+ accessibilityState={
399
+ {
400
+ "busy": undefined,
401
+ "checked": undefined,
402
+ "disabled": false,
403
+ "expanded": undefined,
404
+ "selected": undefined,
405
+ }
353
406
  }
354
- }
355
- accessible={true}
356
- collapsable={false}
357
- focusable={true}
358
- onClick={[Function]}
359
- onResponderGrant={[Function]}
360
- onResponderMove={[Function]}
361
- onResponderRelease={[Function]}
362
- onResponderTerminate={[Function]}
363
- onResponderTerminationRequest={[Function]}
364
- onStartShouldSetResponder={[Function]}
365
- style={
366
- {
367
- "opacity": 1,
407
+ accessibilityValue={
408
+ {
409
+ "max": undefined,
410
+ "min": undefined,
411
+ "now": undefined,
412
+ "text": undefined,
413
+ }
368
414
  }
369
- }
370
- >
371
- <View
372
- pointerEvents="auto"
415
+ accessible={true}
416
+ collapsable={false}
417
+ focusable={true}
418
+ onClick={[Function]}
419
+ onResponderGrant={[Function]}
420
+ onResponderMove={[Function]}
421
+ onResponderRelease={[Function]}
422
+ onResponderTerminate={[Function]}
423
+ onResponderTerminationRequest={[Function]}
424
+ onStartShouldSetResponder={[Function]}
373
425
  style={
374
- [
375
- undefined,
376
- {},
377
- ]
426
+ {
427
+ "opacity": 1,
428
+ }
378
429
  }
379
430
  >
380
431
  <View
432
+ pointerEvents="auto"
381
433
  style={
382
434
  [
383
435
  undefined,
@@ -385,88 +437,113 @@ exports[`LinksUI LinksUI renders 1`] = `
385
437
  ]
386
438
  }
387
439
  >
388
- <View>
389
- <View
390
- style={
391
- [
392
- undefined,
393
- undefined,
394
- ]
395
- }
396
- >
397
- <Svg
398
- height={24}
399
- lock={true}
400
- style={{}}
401
- viewBox="0 0 24 24"
402
- width={24}
403
- xmlns="http://www.w3.org/2000/svg"
440
+ <View
441
+ style={
442
+ [
443
+ undefined,
444
+ {},
445
+ ]
446
+ }
447
+ >
448
+ <View>
449
+ <View
450
+ style={
451
+ [
452
+ undefined,
453
+ undefined,
454
+ ]
455
+ }
404
456
  >
405
- Path
406
- </Svg>
407
- <View />
457
+ <Svg
458
+ height={24}
459
+ lock={true}
460
+ style={{}}
461
+ viewBox="0 0 24 24"
462
+ width={24}
463
+ xmlns="http://www.w3.org/2000/svg"
464
+ >
465
+ Path
466
+ </Svg>
467
+ <View />
468
+ </View>
469
+ <Text
470
+ style={
471
+ [
472
+ undefined,
473
+ {},
474
+ ]
475
+ }
476
+ >
477
+ Link text
478
+ </Text>
408
479
  </View>
409
- <Text
410
- style={
411
- [
412
- undefined,
413
- {},
414
- ]
415
- }
416
- >
417
- Link text
418
- </Text>
419
480
  </View>
481
+ <TextInput
482
+ disabled={false}
483
+ editable={true}
484
+ keyboardType="default"
485
+ numberOfLines={1}
486
+ onBlur={[Function]}
487
+ onChangeText={[Function]}
488
+ onFocus={[Function]}
489
+ onSubmitEditing={[Function]}
490
+ placeholder="Add link text"
491
+ placeholderTextColor="gray"
492
+ pointerEvents="none"
493
+ preferredColorScheme="light"
494
+ style={{}}
495
+ value=""
496
+ />
497
+ <View
498
+ pointerEvents="auto"
499
+ style={
500
+ [
501
+ false,
502
+ undefined,
503
+ ]
504
+ }
505
+ />
420
506
  </View>
421
- <TextInput
422
- disabled={false}
423
- editable={true}
424
- keyboardType="default"
425
- numberOfLines={1}
426
- onBlur={[Function]}
427
- onChangeText={[Function]}
428
- onFocus={[Function]}
429
- onSubmitEditing={[Function]}
430
- placeholder="Add link text"
431
- placeholderTextColor="gray"
432
- pointerEvents="none"
433
- preferredColorScheme="light"
434
- style={{}}
435
- value=""
436
- />
437
- <View
438
- pointerEvents="auto"
439
- style={
440
- [
441
- false,
442
- undefined,
443
- ]
444
- }
445
- />
507
+ <View />
446
508
  </View>
447
- <View />
448
- </View>
449
- <View
450
- style={
451
- {
452
- "height": 20,
509
+ <View
510
+ style={
511
+ {
512
+ "height": 20,
513
+ }
453
514
  }
454
- }
455
- />
515
+ />
516
+ </View>
456
517
  </View>
457
518
  </View>
458
- </View>
459
- </RCTScrollView>
519
+ </RCTScrollView>
520
+ </View>
521
+ <View
522
+ collapsable={false}
523
+ pointerEvents="box-none"
524
+ style={{}}
525
+ />
460
526
  </View>
461
- <View
462
- pointerEvents="box-none"
463
- />
464
527
  </View>
465
528
  </View>
466
529
  </View>
467
530
  </View>
468
531
  </View>
469
532
  </View>
533
+ <View
534
+ collapsable={false}
535
+ pointerEvents="box-none"
536
+ style={
537
+ {
538
+ "height": 56,
539
+ "left": 0,
540
+ "position": "absolute",
541
+ "right": 0,
542
+ "top": 0,
543
+ "zIndex": 1,
544
+ }
545
+ }
546
+ />
470
547
  </View>
471
548
  </RNGestureHandlerRootView>
472
549
  </View>
@@ -83,6 +83,10 @@ describe( 'Text color', () => {
83
83
  const pinkColorButton = await screen.findByA11yHint( COLOR_PINK );
84
84
  expect( pinkColorButton ).toBeDefined();
85
85
  fireEvent.press( pinkColorButton );
86
+ // TODO(jest-console): Fix the warning and remove the expect below.
87
+ expect( console ).toHaveWarnedWith(
88
+ `Non-serializable values were found in the navigation state. Check:\n\ntext-color > Palette > params.onColorChange (Function)\n\nThis can break usage such as persisting and restoring state. This might happen if you passed non-serializable values such as function, class instances etc. in params. If you need to use components with callbacks in your options, you can use 'navigation.setOptions' instead. See https://reactnavigation.org/docs/troubleshooting#i-get-the-warning-non-serializable-values-were-found-in-the-navigation-state for more details.`
89
+ );
86
90
 
87
91
  expect( getEditorHtml() ).toMatchSnapshot();
88
92
  } );