@wordpress/format-library 4.15.0 → 4.17.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.
Files changed (109) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/bold/index.js +1 -10
  3. package/build/bold/index.js.map +1 -1
  4. package/build/code/index.js +3 -17
  5. package/build/code/index.js.map +1 -1
  6. package/build/default-formats.js +0 -14
  7. package/build/default-formats.js.map +1 -1
  8. package/build/default-formats.native.js +0 -6
  9. package/build/default-formats.native.js.map +1 -1
  10. package/build/image/index.js +5 -14
  11. package/build/image/index.js.map +1 -1
  12. package/build/index.js +1 -3
  13. package/build/index.js.map +1 -1
  14. package/build/italic/index.js +1 -10
  15. package/build/italic/index.js.map +1 -1
  16. package/build/keyboard/index.js +1 -10
  17. package/build/keyboard/index.js.map +1 -1
  18. package/build/language/index.js +1 -11
  19. package/build/language/index.js.map +1 -1
  20. package/build/link/index.js +5 -26
  21. package/build/link/index.js.map +1 -1
  22. package/build/link/index.native.js +14 -39
  23. package/build/link/index.native.js.map +1 -1
  24. package/build/link/inline.js +47 -84
  25. package/build/link/inline.js.map +1 -1
  26. package/build/link/modal-screens/link-picker-screen.native.js +1 -13
  27. package/build/link/modal-screens/link-picker-screen.native.js.map +1 -1
  28. package/build/link/modal-screens/link-settings-screen.native.js +9 -36
  29. package/build/link/modal-screens/link-settings-screen.native.js.map +1 -1
  30. package/build/link/modal-screens/screens.native.js.map +1 -1
  31. package/build/link/modal.native.js +1 -9
  32. package/build/link/modal.native.js.map +1 -1
  33. package/build/link/use-link-instance-key.js +3 -7
  34. package/build/link/use-link-instance-key.js.map +1 -1
  35. package/build/link/utils.js +23 -47
  36. package/build/link/utils.js.map +1 -1
  37. package/build/strikethrough/index.js +1 -9
  38. package/build/strikethrough/index.js.map +1 -1
  39. package/build/subscript/index.js +1 -10
  40. package/build/subscript/index.js.map +1 -1
  41. package/build/superscript/index.js +1 -10
  42. package/build/superscript/index.js.map +1 -1
  43. package/build/text-color/index.js +7 -25
  44. package/build/text-color/index.js.map +1 -1
  45. package/build/text-color/index.native.js +11 -34
  46. package/build/text-color/index.native.js.map +1 -1
  47. package/build/text-color/inline.js +5 -26
  48. package/build/text-color/inline.js.map +1 -1
  49. package/build/text-color/inline.native.js +9 -25
  50. package/build/text-color/inline.native.js.map +1 -1
  51. package/build/underline/index.js +1 -8
  52. package/build/underline/index.js.map +1 -1
  53. package/build/unknown/index.js +1 -11
  54. package/build/unknown/index.js.map +1 -1
  55. package/build-module/bold/index.js +0 -7
  56. package/build-module/bold/index.js.map +1 -1
  57. package/build-module/code/index.js +2 -14
  58. package/build-module/code/index.js.map +1 -1
  59. package/build-module/default-formats.js.map +1 -1
  60. package/build-module/default-formats.native.js.map +1 -1
  61. package/build-module/image/index.js +4 -10
  62. package/build-module/image/index.js.map +1 -1
  63. package/build-module/index.js +1 -1
  64. package/build-module/index.js.map +1 -1
  65. package/build-module/italic/index.js +0 -7
  66. package/build-module/italic/index.js.map +1 -1
  67. package/build-module/keyboard/index.js +0 -7
  68. package/build-module/keyboard/index.js.map +1 -1
  69. package/build-module/language/index.js +1 -8
  70. package/build-module/language/index.js.map +1 -1
  71. package/build-module/link/index.js +5 -17
  72. package/build-module/link/index.js.map +1 -1
  73. package/build-module/link/index.native.js +15 -30
  74. package/build-module/link/index.native.js.map +1 -1
  75. package/build-module/link/inline.js +45 -72
  76. package/build-module/link/inline.js.map +1 -1
  77. package/build-module/link/modal-screens/link-picker-screen.native.js +2 -8
  78. package/build-module/link/modal-screens/link-picker-screen.native.js.map +1 -1
  79. package/build-module/link/modal-screens/link-settings-screen.native.js +10 -28
  80. package/build-module/link/modal-screens/link-settings-screen.native.js.map +1 -1
  81. package/build-module/link/modal-screens/screens.native.js.map +1 -1
  82. package/build-module/link/modal.native.js +1 -4
  83. package/build-module/link/modal.native.js.map +1 -1
  84. package/build-module/link/use-link-instance-key.js +3 -7
  85. package/build-module/link/use-link-instance-key.js.map +1 -1
  86. package/build-module/link/utils.js +24 -43
  87. package/build-module/link/utils.js.map +1 -1
  88. package/build-module/strikethrough/index.js +0 -6
  89. package/build-module/strikethrough/index.js.map +1 -1
  90. package/build-module/subscript/index.js +0 -7
  91. package/build-module/subscript/index.js.map +1 -1
  92. package/build-module/superscript/index.js +0 -7
  93. package/build-module/superscript/index.js.map +1 -1
  94. package/build-module/text-color/index.js +7 -20
  95. package/build-module/text-color/index.js.map +1 -1
  96. package/build-module/text-color/index.native.js +12 -24
  97. package/build-module/text-color/index.native.js.map +1 -1
  98. package/build-module/text-color/inline.js +5 -20
  99. package/build-module/text-color/inline.js.map +1 -1
  100. package/build-module/text-color/inline.native.js +9 -21
  101. package/build-module/text-color/inline.native.js.map +1 -1
  102. package/build-module/underline/index.js +0 -6
  103. package/build-module/underline/index.js.map +1 -1
  104. package/build-module/unknown/index.js +0 -8
  105. package/build-module/unknown/index.js.map +1 -1
  106. package/package.json +13 -13
  107. package/src/link/inline.js +14 -37
  108. package/src/link/test/__snapshots__/modal.native.js.snap +372 -295
  109. package/src/text-color/test/index.native.js +4 -0
@@ -1,32 +1,20 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.link = void 0;
9
-
10
8
  var _element = require("@wordpress/element");
11
-
12
9
  var _i18n = require("@wordpress/i18n");
13
-
14
10
  var _richText = require("@wordpress/rich-text");
15
-
16
11
  var _url = require("@wordpress/url");
17
-
18
12
  var _blockEditor = require("@wordpress/block-editor");
19
-
20
13
  var _htmlEntities = require("@wordpress/html-entities");
21
-
22
14
  var _icons = require("@wordpress/icons");
23
-
24
15
  var _a11y = require("@wordpress/a11y");
25
-
26
16
  var _inline = _interopRequireDefault(require("./inline"));
27
-
28
17
  var _utils = require("./utils");
29
-
30
18
  /**
31
19
  * WordPress dependencies
32
20
  */
@@ -34,9 +22,9 @@ var _utils = require("./utils");
34
22
  /**
35
23
  * Internal dependencies
36
24
  */
25
+
37
26
  const name = 'core/link';
38
27
  const title = (0, _i18n.__)('Link');
39
-
40
28
  function Edit({
41
29
  isActive,
42
30
  activeAttributes,
@@ -46,10 +34,8 @@ function Edit({
46
34
  contentRef
47
35
  }) {
48
36
  const [addingLink, setAddingLink] = (0, _element.useState)(false);
49
-
50
37
  function addLink() {
51
38
  const text = (0, _richText.getTextContent)((0, _richText.slice)(value));
52
-
53
39
  if (text && (0, _url.isURL)(text) && (0, _utils.isValidHref)(text)) {
54
40
  onChange((0, _richText.applyFormat)(value, {
55
41
  type: name,
@@ -68,20 +54,16 @@ function Edit({
68
54
  setAddingLink(true);
69
55
  }
70
56
  }
71
-
72
57
  function stopAddingLink(returnFocus = true) {
73
58
  setAddingLink(false);
74
-
75
59
  if (returnFocus) {
76
60
  onFocus();
77
61
  }
78
62
  }
79
-
80
63
  function onRemoveFormat() {
81
64
  onChange((0, _richText.removeFormat)(value, name));
82
65
  (0, _a11y.speak)((0, _i18n.__)('Link removed.'), 'assertive');
83
66
  }
84
-
85
67
  return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_blockEditor.RichTextShortcut, {
86
68
  type: "primary",
87
69
  character: "k",
@@ -116,7 +98,6 @@ function Edit({
116
98
  contentRef: contentRef
117
99
  }));
118
100
  }
119
-
120
101
  const link = {
121
102
  name,
122
103
  title,
@@ -128,7 +109,6 @@ const link = {
128
109
  id: 'data-id',
129
110
  target: 'target'
130
111
  },
131
-
132
112
  __unstablePasteRule(value, {
133
113
  html,
134
114
  plainText
@@ -136,14 +116,14 @@ const link = {
136
116
  if ((0, _richText.isCollapsed)(value)) {
137
117
  return value;
138
118
  }
119
+ const pastedText = (html || plainText).replace(/<[^>]+>/g, '').trim();
139
120
 
140
- const pastedText = (html || plainText).replace(/<[^>]+>/g, '').trim(); // A URL was pasted, turn the selection into a link.
141
-
121
+ // A URL was pasted, turn the selection into a link.
142
122
  if (!(0, _url.isURL)(pastedText)) {
143
123
  return value;
144
- } // Allows us to ask for this information when we get a report.
145
-
124
+ }
146
125
 
126
+ // Allows us to ask for this information when we get a report.
147
127
  window.console.log('Created link:\n\n', pastedText);
148
128
  return (0, _richText.applyFormat)(value, {
149
129
  type: name,
@@ -152,7 +132,6 @@ const link = {
152
132
  }
153
133
  });
154
134
  },
155
-
156
135
  edit: Edit
157
136
  };
158
137
  exports.link = link;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/link/index.js"],"names":["name","title","Edit","isActive","activeAttributes","value","onChange","onFocus","contentRef","addingLink","setAddingLink","addLink","text","type","attributes","url","stopAddingLink","returnFocus","onRemoveFormat","linkOff","linkIcon","link","tagName","className","id","target","__unstablePasteRule","html","plainText","pastedText","replace","trim","window","console","log","edit"],"mappings":";;;;;;;;;AAIA;;AADA;;AAEA;;AAOA;;AACA;;AAIA;;AACA;;AACA;;AAKA;;AACA;;AAzBA;AACA;AACA;;AAmBA;AACA;AACA;AAIA,MAAMA,IAAI,GAAG,WAAb;AACA,MAAMC,KAAK,GAAG,cAAI,MAAJ,CAAd;;AAEA,SAASC,IAAT,CAAe;AACdC,EAAAA,QADc;AAEdC,EAAAA,gBAFc;AAGdC,EAAAA,KAHc;AAIdC,EAAAA,QAJc;AAKdC,EAAAA,OALc;AAMdC,EAAAA;AANc,CAAf,EAOI;AACH,QAAM,CAAEC,UAAF,EAAcC,aAAd,IAAgC,uBAAU,KAAV,CAAtC;;AAEA,WAASC,OAAT,GAAmB;AAClB,UAAMC,IAAI,GAAG,8BAAgB,qBAAOP,KAAP,CAAhB,CAAb;;AAEA,QAAKO,IAAI,IAAI,gBAAOA,IAAP,CAAR,IAAyB,wBAAaA,IAAb,CAA9B,EAAoD;AACnDN,MAAAA,QAAQ,CACP,2BAAaD,KAAb,EAAoB;AACnBQ,QAAAA,IAAI,EAAEb,IADa;AAEnBc,QAAAA,UAAU,EAAE;AAAEC,UAAAA,GAAG,EAAEH;AAAP;AAFO,OAApB,CADO,C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AAb,EAAoB;AAC1BQ,MAAAA,IAAI,EAAEb,IADoB;AAE1Bc,MAAAA,UAAU,EAAE;AACXC,QAAAA,GAAG,EAAE,kCAAgBc,UAAhB;AADM;AAFc,KAApB,CAAP;AAMA,GAlCkB;;AAmCnBM,EAAAA,IAAI,EAAEjC;AAnCa,CAAb","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport {\n\tgetTextContent,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\tisCollapsed,\n} from '@wordpress/rich-text';\nimport { isURL, isEmail } from '@wordpress/url';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n} from '@wordpress/block-editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { link as linkIcon, linkOff } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport InlineLinkUI from './inline';\nimport { isValidHref } from './utils';\n\nconst name = 'core/link';\nconst title = __( 'Link' );\n\nfunction Edit( {\n\tisActive,\n\tactiveAttributes,\n\tvalue,\n\tonChange,\n\tonFocus,\n\tcontentRef,\n} ) {\n\tconst [ addingLink, setAddingLink ] = useState( false );\n\n\tfunction addLink() {\n\t\tconst text = getTextContent( slice( value ) );\n\n\t\tif ( text && isURL( text ) && isValidHref( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: text },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else if ( text && isEmail( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: `mailto:${ text }` },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else {\n\t\t\tsetAddingLink( true );\n\t\t}\n\t}\n\n\tfunction stopAddingLink( returnFocus = true ) {\n\t\tsetAddingLink( false );\n\t\tif ( returnFocus ) {\n\t\t\tonFocus();\n\t\t}\n\t}\n\n\tfunction onRemoveFormat() {\n\t\tonChange( removeFormat( value, name ) );\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<RichTextShortcut type=\"primary\" character=\"k\" onUse={ addLink } />\n\t\t\t<RichTextShortcut\n\t\t\t\ttype=\"primaryShift\"\n\t\t\t\tcharacter=\"k\"\n\t\t\t\tonUse={ onRemoveFormat }\n\t\t\t/>\n\t\t\t{ isActive && (\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"link\"\n\t\t\t\t\ticon={ linkOff }\n\t\t\t\t\ttitle={ __( 'Unlink' ) }\n\t\t\t\t\tonClick={ onRemoveFormat }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primaryShift\"\n\t\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! isActive && (\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"link\"\n\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ addLink }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ( addingLink || isActive ) && (\n\t\t\t\t<InlineLinkUI\n\t\t\t\t\taddingLink={ addingLink }\n\t\t\t\t\tstopAddingLink={ stopAddingLink }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const link = {\n\tname,\n\ttitle,\n\ttagName: 'a',\n\tclassName: null,\n\tattributes: {\n\t\turl: 'href',\n\t\ttype: 'data-type',\n\t\tid: 'data-id',\n\t\ttarget: 'target',\n\t},\n\t__unstablePasteRule( value, { html, plainText } ) {\n\t\tif ( isCollapsed( value ) ) {\n\t\t\treturn value;\n\t\t}\n\n\t\tconst pastedText = ( html || plainText )\n\t\t\t.replace( /<[^>]+>/g, '' )\n\t\t\t.trim();\n\n\t\t// A URL was pasted, turn the selection into a link.\n\t\tif ( ! isURL( pastedText ) ) {\n\t\t\treturn value;\n\t\t}\n\n\t\t// Allows us to ask for this information when we get a report.\n\t\twindow.console.log( 'Created link:\\n\\n', pastedText );\n\n\t\treturn applyFormat( value, {\n\t\t\ttype: name,\n\t\t\tattributes: {\n\t\t\t\turl: decodeEntities( pastedText ),\n\t\t\t},\n\t\t} );\n\t},\n\tedit: Edit,\n};\n"]}
1
+ {"version":3,"names":["_element","require","_i18n","_richText","_url","_blockEditor","_htmlEntities","_icons","_a11y","_inline","_interopRequireDefault","_utils","name","title","__","Edit","isActive","activeAttributes","value","onChange","onFocus","contentRef","addingLink","setAddingLink","useState","addLink","text","getTextContent","slice","isURL","isValidHref","applyFormat","type","attributes","url","isEmail","stopAddingLink","returnFocus","onRemoveFormat","removeFormat","speak","createElement","Fragment","RichTextShortcut","character","onUse","RichTextToolbarButton","icon","linkOff","onClick","shortcutType","shortcutCharacter","linkIcon","default","link","tagName","className","id","target","__unstablePasteRule","html","plainText","isCollapsed","pastedText","replace","trim","window","console","log","decodeEntities","edit","exports"],"sources":["@wordpress/format-library/src/link/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport {\n\tgetTextContent,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\tisCollapsed,\n} from '@wordpress/rich-text';\nimport { isURL, isEmail } from '@wordpress/url';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n} from '@wordpress/block-editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { link as linkIcon, linkOff } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport InlineLinkUI from './inline';\nimport { isValidHref } from './utils';\n\nconst name = 'core/link';\nconst title = __( 'Link' );\n\nfunction Edit( {\n\tisActive,\n\tactiveAttributes,\n\tvalue,\n\tonChange,\n\tonFocus,\n\tcontentRef,\n} ) {\n\tconst [ addingLink, setAddingLink ] = useState( false );\n\n\tfunction addLink() {\n\t\tconst text = getTextContent( slice( value ) );\n\n\t\tif ( text && isURL( text ) && isValidHref( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: text },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else if ( text && isEmail( text ) ) {\n\t\t\tonChange(\n\t\t\t\tapplyFormat( value, {\n\t\t\t\t\ttype: name,\n\t\t\t\t\tattributes: { url: `mailto:${ text }` },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else {\n\t\t\tsetAddingLink( true );\n\t\t}\n\t}\n\n\tfunction stopAddingLink( returnFocus = true ) {\n\t\tsetAddingLink( false );\n\t\tif ( returnFocus ) {\n\t\t\tonFocus();\n\t\t}\n\t}\n\n\tfunction onRemoveFormat() {\n\t\tonChange( removeFormat( value, name ) );\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<RichTextShortcut type=\"primary\" character=\"k\" onUse={ addLink } />\n\t\t\t<RichTextShortcut\n\t\t\t\ttype=\"primaryShift\"\n\t\t\t\tcharacter=\"k\"\n\t\t\t\tonUse={ onRemoveFormat }\n\t\t\t/>\n\t\t\t{ isActive && (\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"link\"\n\t\t\t\t\ticon={ linkOff }\n\t\t\t\t\ttitle={ __( 'Unlink' ) }\n\t\t\t\t\tonClick={ onRemoveFormat }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primaryShift\"\n\t\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ! isActive && (\n\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\tname=\"link\"\n\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\tonClick={ addLink }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ ( addingLink || isActive ) && (\n\t\t\t\t<InlineLinkUI\n\t\t\t\t\taddingLink={ addingLink }\n\t\t\t\t\tstopAddingLink={ stopAddingLink }\n\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tcontentRef={ contentRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport const link = {\n\tname,\n\ttitle,\n\ttagName: 'a',\n\tclassName: null,\n\tattributes: {\n\t\turl: 'href',\n\t\ttype: 'data-type',\n\t\tid: 'data-id',\n\t\ttarget: 'target',\n\t},\n\t__unstablePasteRule( value, { html, plainText } ) {\n\t\tif ( isCollapsed( value ) ) {\n\t\t\treturn value;\n\t\t}\n\n\t\tconst pastedText = ( html || plainText )\n\t\t\t.replace( /<[^>]+>/g, '' )\n\t\t\t.trim();\n\n\t\t// A URL was pasted, turn the selection into a link.\n\t\tif ( ! isURL( pastedText ) ) {\n\t\t\treturn value;\n\t\t}\n\n\t\t// Allows us to ask for this information when we get a report.\n\t\twindow.console.log( 'Created link:\\n\\n', pastedText );\n\n\t\treturn applyFormat( value, {\n\t\t\ttype: name,\n\t\t\tattributes: {\n\t\t\t\turl: decodeEntities( pastedText ),\n\t\t\t},\n\t\t} );\n\t},\n\tedit: Edit,\n};\n"],"mappings":";;;;;;;AAIA,IAAAA,QAAA,GAAAC,OAAA;AADA,IAAAC,KAAA,GAAAD,OAAA;AAE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AE,CAAC;EACJ,CAAC;EACDO,IAAI,EAAEvD;AACP,CAAC;AAACwD,OAAA,CAAAjB,IAAA,GAAAA,IAAA"}
@@ -1,32 +1,20 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.link = void 0;
9
-
10
8
  var _element = require("@wordpress/element");
11
-
12
9
  var _clipboard = _interopRequireDefault(require("@react-native-clipboard/clipboard"));
13
-
14
10
  var _i18n = require("@wordpress/i18n");
15
-
16
11
  var _components = require("@wordpress/components");
17
-
18
12
  var _blockEditor = require("@wordpress/block-editor");
19
-
20
13
  var _richText = require("@wordpress/rich-text");
21
-
22
14
  var _url = require("@wordpress/url");
23
-
24
15
  var _icons = require("@wordpress/icons");
25
-
26
16
  var _modal = _interopRequireDefault(require("./modal"));
27
-
28
17
  var _utils = require("./utils");
29
-
30
18
  /**
31
19
  * External dependencies
32
20
  */
@@ -38,6 +26,7 @@ var _utils = require("./utils");
38
26
  /**
39
27
  * Internal dependencies
40
28
  */
29
+
41
30
  const name = 'core/link';
42
31
  const link = {
43
32
  name,
@@ -60,14 +49,12 @@ const link = {
60
49
  addingLink: false
61
50
  };
62
51
  }
63
-
64
52
  addLink() {
65
53
  const {
66
54
  value,
67
55
  onChange
68
56
  } = this.props;
69
57
  const text = (0, _richText.getTextContent)((0, _richText.slice)(value));
70
-
71
58
  if (text && (0, _url.isURL)(text) && (0, _utils.isValidHref)(text)) {
72
59
  const newValue = (0, _richText.applyFormat)(value, {
73
60
  type: name,
@@ -77,7 +64,8 @@ const link = {
77
64
  });
78
65
  newValue.start = newValue.end;
79
66
  newValue.activeFormats = [];
80
- onChange({ ...newValue,
67
+ onChange({
68
+ ...newValue,
81
69
  needsSelectionUpdate: true
82
70
  });
83
71
  } else {
@@ -87,91 +75,79 @@ const link = {
87
75
  this.getURLFromClipboard();
88
76
  }
89
77
  }
90
-
91
78
  stopAddingLink() {
92
79
  this.setState({
93
80
  addingLink: false,
94
81
  clipboardURL: undefined
95
82
  });
96
83
  }
97
-
98
84
  getLinkSelection() {
99
85
  const {
100
86
  value,
101
87
  isActive
102
88
  } = this.props;
103
- const startFormat = (0, _richText.getActiveFormat)(value, 'core/link'); // If the link isn't selected, get the link manually by looking around the cursor
104
- // TODO: handle partly selected links.
89
+ const startFormat = (0, _richText.getActiveFormat)(value, 'core/link');
105
90
 
91
+ // If the link isn't selected, get the link manually by looking around the cursor
92
+ // TODO: handle partly selected links.
106
93
  if (startFormat && (0, _richText.isCollapsed)(value) && isActive) {
107
94
  let startIndex = value.start;
108
95
  let endIndex = value.end;
109
-
110
96
  while (value.formats[startIndex]?.find(format => format?.type === startFormat.type)) {
111
97
  startIndex--;
112
98
  }
113
-
114
99
  endIndex++;
115
-
116
100
  while (value.formats[endIndex]?.find(format => format?.type === startFormat.type)) {
117
101
  endIndex++;
118
102
  }
119
-
120
- return { ...value,
103
+ return {
104
+ ...value,
121
105
  start: startIndex + 1,
122
106
  end: endIndex
123
107
  };
124
108
  }
125
-
126
109
  return value;
127
110
  }
128
-
129
111
  onRemoveFormat() {
130
112
  const {
131
113
  onChange,
132
114
  speak,
133
115
  value
134
116
  } = this.props;
135
- const startFormat = (0, _richText.getActiveFormat)(value, 'core/link'); // Before we try to remove anything we check if there is something at the caret position to remove.
117
+ const startFormat = (0, _richText.getActiveFormat)(value, 'core/link');
136
118
 
119
+ // Before we try to remove anything we check if there is something at the caret position to remove.
137
120
  if ((0, _richText.isCollapsed)(value) && startFormat === undefined) {
138
121
  return;
139
122
  }
140
-
141
123
  const linkSelection = this.getLinkSelection();
142
124
  onChange((0, _richText.removeFormat)(linkSelection, name));
143
125
  speak((0, _i18n.__)('Link removed.'), 'assertive');
144
126
  }
145
-
146
127
  async getURLFromClipboard() {
147
128
  const clipboardText = await _clipboard.default.getString();
148
-
149
129
  if (!clipboardText) {
150
130
  return;
151
- } // Check if pasted text is URL.
152
-
153
-
131
+ }
132
+ // Check if pasted text is URL.
154
133
  if (!(0, _url.isURL)(clipboardText)) {
155
134
  return;
156
135
  }
157
-
158
136
  this.setState({
159
137
  clipboardURL: clipboardText
160
138
  });
161
139
  }
162
-
163
140
  render() {
164
141
  const {
165
142
  isActive,
166
143
  activeAttributes,
167
144
  onChange
168
145
  } = this.props;
169
- const linkSelection = this.getLinkSelection(); // If no URL is set and we have a clipboard URL let's use it.
170
-
146
+ const linkSelection = this.getLinkSelection();
147
+ // If no URL is set and we have a clipboard URL let's use it.
171
148
  if (!activeAttributes.url && this.state.clipboardURL) {
172
149
  activeAttributes.url = this.state.clipboardURL;
173
150
  }
174
-
175
151
  return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_modal.default, {
176
152
  isVisible: this.state.addingLink,
177
153
  isActive: isActive,
@@ -190,7 +166,6 @@ const link = {
190
166
  shortcutCharacter: "k"
191
167
  }));
192
168
  }
193
-
194
169
  })
195
170
  };
196
171
  exports.link = link;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/format-library/src/link/index.native.js"],"names":["name","link","title","tagName","className","attributes","url","target","rel","edit","LinkEdit","Component","constructor","arguments","addLink","bind","stopAddingLink","onRemoveFormat","getURLFromClipboard","state","addingLink","value","onChange","props","text","newValue","type","start","end","activeFormats","needsSelectionUpdate","setState","clipboardURL","undefined","getLinkSelection","isActive","startFormat","startIndex","endIndex","formats","find","format","speak","linkSelection","clipboardText","Clipboard","getString","render","activeAttributes","linkIcon"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AAQA;;AACA;;AAKA;;AACA;;AA3BA;AACA;AACA;;AAGA;AACA;AACA;;AAgBA;AACA;AACA;AAIA,MAAMA,IAAI,GAAG,WAAb;AAEO,MAAMC,IAAI,GAAG;AACnBD,EAAAA,IADmB;AAEnBE,EAAAA,KAAK,EAAE,cAAI,MAAJ,CAFY;AAGnBC,EAAAA,OAAO,EAAE,GAHU;AAIn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;AAOC,QAAA,KAAK,EAAG0B;AAPT,QADD,EAUC,4BAAC,kCAAD;AACC,QAAA,IAAI,EAAC,MADN;AAEC,QAAA,IAAI,EAAGM,WAFR;AAGC,QAAA,KAAK,EAAG,cAAI,MAAJ,CAHT;AAIC,QAAA,OAAO,EAAG,KAAKnC,OAJhB;AAKC,QAAA,QAAQ,EAAGqB,QALZ;AAMC,QAAA,YAAY,EAAC,SANd;AAOC,QAAA,iBAAiB,EAAC;AAPnB,QAVD,CADD;AAsBA;;AAlI+B,GAD5B;AAVa,CAAb","sourcesContent":["/**\n * External dependencies\n */\nimport Clipboard from '@react-native-clipboard/clipboard';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Component } from '@wordpress/element';\nimport { withSpokenMessages } from '@wordpress/components';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport {\n\tapplyFormat,\n\tgetActiveFormat,\n\tgetTextContent,\n\tisCollapsed,\n\tremoveFormat,\n\tslice,\n} from '@wordpress/rich-text';\nimport { isURL } from '@wordpress/url';\nimport { link as linkIcon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport ModalLinkUI from './modal';\nimport { isValidHref } from './utils';\n\nconst name = 'core/link';\n\nexport const link = {\n\tname,\n\ttitle: __( 'Link' ),\n\ttagName: 'a',\n\tclassName: null,\n\tattributes: {\n\t\turl: 'href',\n\t\ttarget: 'target',\n\t\trel: 'rel',\n\t},\n\tedit: withSpokenMessages(\n\t\tclass LinkEdit extends Component {\n\t\t\tconstructor() {\n\t\t\t\tsuper( ...arguments );\n\n\t\t\t\tthis.addLink = this.addLink.bind( this );\n\t\t\t\tthis.stopAddingLink = this.stopAddingLink.bind( this );\n\t\t\t\tthis.onRemoveFormat = this.onRemoveFormat.bind( this );\n\t\t\t\tthis.getURLFromClipboard =\n\t\t\t\t\tthis.getURLFromClipboard.bind( this );\n\t\t\t\tthis.state = {\n\t\t\t\t\taddingLink: false,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\taddLink() {\n\t\t\t\tconst { value, onChange } = this.props;\n\t\t\t\tconst text = getTextContent( slice( value ) );\n\n\t\t\t\tif ( text && isURL( text ) && isValidHref( text ) ) {\n\t\t\t\t\tconst newValue = applyFormat( value, {\n\t\t\t\t\t\ttype: name,\n\t\t\t\t\t\tattributes: { url: text },\n\t\t\t\t\t} );\n\t\t\t\t\tnewValue.start = newValue.end;\n\t\t\t\t\tnewValue.activeFormats = [];\n\t\t\t\t\tonChange( { ...newValue, needsSelectionUpdate: true } );\n\t\t\t\t} else {\n\t\t\t\t\tthis.setState( { addingLink: true } );\n\t\t\t\t\tthis.getURLFromClipboard();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstopAddingLink() {\n\t\t\t\tthis.setState( { addingLink: false, clipboardURL: undefined } );\n\t\t\t}\n\n\t\t\tgetLinkSelection() {\n\t\t\t\tconst { value, isActive } = this.props;\n\t\t\t\tconst startFormat = getActiveFormat( value, 'core/link' );\n\n\t\t\t\t// If the link isn't selected, get the link manually by looking around the cursor\n\t\t\t\t// TODO: handle partly selected links.\n\t\t\t\tif ( startFormat && isCollapsed( value ) && isActive ) {\n\t\t\t\t\tlet startIndex = value.start;\n\t\t\t\t\tlet endIndex = value.end;\n\n\t\t\t\t\twhile (\n\t\t\t\t\t\tvalue.formats[ startIndex ]?.find(\n\t\t\t\t\t\t\t( format ) => format?.type === startFormat.type\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tstartIndex--;\n\t\t\t\t\t}\n\n\t\t\t\t\tendIndex++;\n\n\t\t\t\t\twhile (\n\t\t\t\t\t\tvalue.formats[ endIndex ]?.find(\n\t\t\t\t\t\t\t( format ) => format?.type === startFormat.type\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tendIndex++;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...value,\n\t\t\t\t\t\tstart: startIndex + 1,\n\t\t\t\t\t\tend: endIndex,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tonRemoveFormat() {\n\t\t\t\tconst { onChange, speak, value } = this.props;\n\t\t\t\tconst startFormat = getActiveFormat( value, 'core/link' );\n\n\t\t\t\t// Before we try to remove anything we check if there is something at the caret position to remove.\n\t\t\t\tif ( isCollapsed( value ) && startFormat === undefined ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst linkSelection = this.getLinkSelection();\n\n\t\t\t\tonChange( removeFormat( linkSelection, name ) );\n\t\t\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t\t\t}\n\n\t\t\tasync getURLFromClipboard() {\n\t\t\t\tconst clipboardText = await Clipboard.getString();\n\t\t\t\tif ( ! clipboardText ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Check if pasted text is URL.\n\t\t\t\tif ( ! isURL( clipboardText ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.setState( { clipboardURL: clipboardText } );\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\tconst { isActive, activeAttributes, onChange } = this.props;\n\t\t\t\tconst linkSelection = this.getLinkSelection();\n\t\t\t\t// If no URL is set and we have a clipboard URL let's use it.\n\t\t\t\tif ( ! activeAttributes.url && this.state.clipboardURL ) {\n\t\t\t\t\tactiveAttributes.url = this.state.clipboardURL;\n\t\t\t\t}\n\t\t\t\treturn (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<ModalLinkUI\n\t\t\t\t\t\t\tisVisible={ this.state.addingLink }\n\t\t\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\t\t\tonClose={ this.stopAddingLink }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\tonRemove={ this.onRemoveFormat }\n\t\t\t\t\t\t\tvalue={ linkSelection }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\t\tonClick={ this.addLink }\n\t\t\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t),\n};\n"]}
1
+ {"version":3,"names":["_element","require","_clipboard","_interopRequireDefault","_i18n","_components","_blockEditor","_richText","_url","_icons","_modal","_utils","name","link","title","__","tagName","className","attributes","url","target","rel","edit","withSpokenMessages","LinkEdit","Component","constructor","arguments","addLink","bind","stopAddingLink","onRemoveFormat","getURLFromClipboard","state","addingLink","value","onChange","props","text","getTextContent","slice","isURL","isValidHref","newValue","applyFormat","type","start","end","activeFormats","needsSelectionUpdate","setState","clipboardURL","undefined","getLinkSelection","isActive","startFormat","getActiveFormat","isCollapsed","startIndex","endIndex","formats","find","format","speak","linkSelection","removeFormat","clipboardText","Clipboard","getString","render","activeAttributes","createElement","Fragment","default","isVisible","onClose","onRemove","RichTextToolbarButton","icon","linkIcon","onClick","shortcutType","shortcutCharacter","exports"],"sources":["@wordpress/format-library/src/link/index.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport Clipboard from '@react-native-clipboard/clipboard';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Component } from '@wordpress/element';\nimport { withSpokenMessages } from '@wordpress/components';\nimport { RichTextToolbarButton } from '@wordpress/block-editor';\nimport {\n\tapplyFormat,\n\tgetActiveFormat,\n\tgetTextContent,\n\tisCollapsed,\n\tremoveFormat,\n\tslice,\n} from '@wordpress/rich-text';\nimport { isURL } from '@wordpress/url';\nimport { link as linkIcon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport ModalLinkUI from './modal';\nimport { isValidHref } from './utils';\n\nconst name = 'core/link';\n\nexport const link = {\n\tname,\n\ttitle: __( 'Link' ),\n\ttagName: 'a',\n\tclassName: null,\n\tattributes: {\n\t\turl: 'href',\n\t\ttarget: 'target',\n\t\trel: 'rel',\n\t},\n\tedit: withSpokenMessages(\n\t\tclass LinkEdit extends Component {\n\t\t\tconstructor() {\n\t\t\t\tsuper( ...arguments );\n\n\t\t\t\tthis.addLink = this.addLink.bind( this );\n\t\t\t\tthis.stopAddingLink = this.stopAddingLink.bind( this );\n\t\t\t\tthis.onRemoveFormat = this.onRemoveFormat.bind( this );\n\t\t\t\tthis.getURLFromClipboard =\n\t\t\t\t\tthis.getURLFromClipboard.bind( this );\n\t\t\t\tthis.state = {\n\t\t\t\t\taddingLink: false,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\taddLink() {\n\t\t\t\tconst { value, onChange } = this.props;\n\t\t\t\tconst text = getTextContent( slice( value ) );\n\n\t\t\t\tif ( text && isURL( text ) && isValidHref( text ) ) {\n\t\t\t\t\tconst newValue = applyFormat( value, {\n\t\t\t\t\t\ttype: name,\n\t\t\t\t\t\tattributes: { url: text },\n\t\t\t\t\t} );\n\t\t\t\t\tnewValue.start = newValue.end;\n\t\t\t\t\tnewValue.activeFormats = [];\n\t\t\t\t\tonChange( { ...newValue, needsSelectionUpdate: true } );\n\t\t\t\t} else {\n\t\t\t\t\tthis.setState( { addingLink: true } );\n\t\t\t\t\tthis.getURLFromClipboard();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstopAddingLink() {\n\t\t\t\tthis.setState( { addingLink: false, clipboardURL: undefined } );\n\t\t\t}\n\n\t\t\tgetLinkSelection() {\n\t\t\t\tconst { value, isActive } = this.props;\n\t\t\t\tconst startFormat = getActiveFormat( value, 'core/link' );\n\n\t\t\t\t// If the link isn't selected, get the link manually by looking around the cursor\n\t\t\t\t// TODO: handle partly selected links.\n\t\t\t\tif ( startFormat && isCollapsed( value ) && isActive ) {\n\t\t\t\t\tlet startIndex = value.start;\n\t\t\t\t\tlet endIndex = value.end;\n\n\t\t\t\t\twhile (\n\t\t\t\t\t\tvalue.formats[ startIndex ]?.find(\n\t\t\t\t\t\t\t( format ) => format?.type === startFormat.type\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tstartIndex--;\n\t\t\t\t\t}\n\n\t\t\t\t\tendIndex++;\n\n\t\t\t\t\twhile (\n\t\t\t\t\t\tvalue.formats[ endIndex ]?.find(\n\t\t\t\t\t\t\t( format ) => format?.type === startFormat.type\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tendIndex++;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...value,\n\t\t\t\t\t\tstart: startIndex + 1,\n\t\t\t\t\t\tend: endIndex,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tonRemoveFormat() {\n\t\t\t\tconst { onChange, speak, value } = this.props;\n\t\t\t\tconst startFormat = getActiveFormat( value, 'core/link' );\n\n\t\t\t\t// Before we try to remove anything we check if there is something at the caret position to remove.\n\t\t\t\tif ( isCollapsed( value ) && startFormat === undefined ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst linkSelection = this.getLinkSelection();\n\n\t\t\t\tonChange( removeFormat( linkSelection, name ) );\n\t\t\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t\t\t}\n\n\t\t\tasync getURLFromClipboard() {\n\t\t\t\tconst clipboardText = await Clipboard.getString();\n\t\t\t\tif ( ! clipboardText ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Check if pasted text is URL.\n\t\t\t\tif ( ! isURL( clipboardText ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.setState( { clipboardURL: clipboardText } );\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\tconst { isActive, activeAttributes, onChange } = this.props;\n\t\t\t\tconst linkSelection = this.getLinkSelection();\n\t\t\t\t// If no URL is set and we have a clipboard URL let's use it.\n\t\t\t\tif ( ! activeAttributes.url && this.state.clipboardURL ) {\n\t\t\t\t\tactiveAttributes.url = this.state.clipboardURL;\n\t\t\t\t}\n\t\t\t\treturn (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<ModalLinkUI\n\t\t\t\t\t\t\tisVisible={ this.state.addingLink }\n\t\t\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\t\t\tactiveAttributes={ activeAttributes }\n\t\t\t\t\t\t\tonClose={ this.stopAddingLink }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\tonRemove={ this.onRemoveFormat }\n\t\t\t\t\t\t\tvalue={ linkSelection }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<RichTextToolbarButton\n\t\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\t\tonClick={ this.addLink }\n\t\t\t\t\t\t\tisActive={ isActive }\n\t\t\t\t\t\t\tshortcutType=\"primary\"\n\t\t\t\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t),\n};\n"],"mappings":";;;;;;;AASA,IAAAA,QAAA,GAAAC,OAAA;AANA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AAKA,IAAAG,KAAA,GAAAH,OAAA;AAEA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAQA,IAAAO,IAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AAKA,IAAAS,MAAA,GAAAP,sBAAA,CAAAF,OAAA;AACA,IAAAU,MAAA,GAAAV,OAAA;AA3BA;AACA;AACA;;AAGA;AACA;AACA;;AAgBA;AACA;A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AA,CAAAwE,QAAA,QACC,IAAAxE,QAAA,CAAAuE,aAAA,EAAC7D,MAAA,CAAA+D,OAAW;QACXC,SAAS,EAAG,IAAI,CAACzC,KAAK,CAACC,UAAY;QACnCoB,QAAQ,EAAGA,QAAU;QACrBgB,gBAAgB,EAAGA,gBAAkB;QACrCK,OAAO,EAAG,IAAI,CAAC7C,cAAgB;QAC/BM,QAAQ,EAAGA,QAAU;QACrBwC,QAAQ,EAAG,IAAI,CAAC7C,cAAgB;QAChCI,KAAK,EAAG6B;MAAe,CACvB,CAAC,EACF,IAAAhE,QAAA,CAAAuE,aAAA,EAACjE,YAAA,CAAAuE,qBAAqB;QACrBjE,IAAI,EAAC,MAAM;QACXkE,IAAI,EAAGC,WAAU;QACjBjE,KAAK,EAAG,IAAAC,QAAE,EAAE,MAAO,CAAG;QACtBiE,OAAO,EAAG,IAAI,CAACpD,OAAS;QACxB0B,QAAQ,EAAGA,QAAU;QACrB2B,YAAY,EAAC,SAAS;QACtBC,iBAAiB,EAAC;MAAG,CACrB,CACA,CAAC;IAEL;EACD,CACD;AACD,CAAC;AAACC,OAAA,CAAAtE,IAAA,GAAAA,IAAA"}
@@ -1,32 +1,21 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _element = require("@wordpress/element");
11
-
12
9
  var _i18n = require("@wordpress/i18n");
13
-
10
+ var _a11y = require("@wordpress/a11y");
14
11
  var _components = require("@wordpress/components");
15
-
16
12
  var _url = require("@wordpress/url");
17
-
18
13
  var _richText = require("@wordpress/rich-text");
19
-
20
14
  var _blockEditor = require("@wordpress/block-editor");
21
-
22
15
  var _data = require("@wordpress/data");
23
-
24
16
  var _utils = require("./utils");
25
-
26
17
  var _index = require("./index");
27
-
28
18
  var _useLinkInstanceKey = _interopRequireDefault(require("./use-link-instance-key"));
29
-
30
19
  /**
31
20
  * WordPress dependencies
32
21
  */
@@ -34,29 +23,20 @@ var _useLinkInstanceKey = _interopRequireDefault(require("./use-link-instance-ke
34
23
  /**
35
24
  * Internal dependencies
36
25
  */
26
+
37
27
  function InlineLinkUI({
38
28
  isActive,
39
29
  activeAttributes,
40
30
  addingLink,
41
31
  value,
42
32
  onChange,
43
- speak,
44
33
  stopAddingLink,
45
34
  contentRef
46
35
  }) {
47
- const richLinkTextValue = getRichTextValueFromSelection(value, isActive); // Get the text content minus any HTML tags.
36
+ const richLinkTextValue = getRichTextValueFromSelection(value, isActive);
48
37
 
38
+ // Get the text content minus any HTML tags.
49
39
  const richTextText = richLinkTextValue.text;
50
- /**
51
- * Pending settings to be applied to the next link. When inserting a new
52
- * link, toggle values cannot be applied immediately, because there is not
53
- * yet a link for them to apply to. Thus, they are maintained in a state
54
- * value until the time that the link can be inserted or edited.
55
- *
56
- * @type {[Object|undefined,Function]}
57
- */
58
-
59
- const [nextLinkValue, setNextLinkValue] = (0, _element.useState)();
60
40
  const {
61
41
  createPageEntity,
62
42
  userCanCreatePages
@@ -64,9 +44,7 @@ function InlineLinkUI({
64
44
  const {
65
45
  getSettings
66
46
  } = select(_blockEditor.store);
67
-
68
47
  const _settings = getSettings();
69
-
70
48
  return {
71
49
  createPageEntity: _settings.__experimentalCreatePageEntity,
72
50
  userCanCreatePages: _settings.__experimentalUserCanCreatePages
@@ -77,38 +55,25 @@ function InlineLinkUI({
77
55
  type: activeAttributes.type,
78
56
  id: activeAttributes.id,
79
57
  opensInNewTab: activeAttributes.target === '_blank',
80
- title: richTextText,
81
- ...nextLinkValue
58
+ title: richTextText
82
59
  };
83
-
84
60
  function removeLink() {
85
61
  const newValue = (0, _richText.removeFormat)(value, 'core/link');
86
62
  onChange(newValue);
87
63
  stopAddingLink();
88
- speak((0, _i18n.__)('Link removed.'), 'assertive');
64
+ (0, _a11y.speak)((0, _i18n.__)('Link removed.'), 'assertive');
89
65
  }
90
-
91
66
  function onChangeLink(nextValue) {
92
- // Merge with values from state, both for the purpose of assigning the
93
- // next state value, and for use in constructing the new link format if
94
- // the link is ready to be applied.
95
- nextValue = { ...nextLinkValue,
67
+ // LinkControl calls `onChange` immediately upon the toggling a setting.
68
+ // Before merging the next value with the current link value, check if
69
+ // the setting was toggled.
70
+ const didToggleSetting = linkValue.opensInNewTab !== nextValue.opensInNewTab && nextValue.url === undefined;
71
+
72
+ // Merge the next value with the current link value.
73
+ nextValue = {
74
+ ...linkValue,
96
75
  ...nextValue
97
- }; // LinkControl calls `onChange` immediately upon the toggling a setting.
98
-
99
- const didToggleSetting = linkValue.opensInNewTab !== nextValue.opensInNewTab && linkValue.url === nextValue.url; // If change handler was called as a result of a settings change during
100
- // link insertion, it must be held in state until the link is ready to
101
- // be applied.
102
-
103
- const didToggleSettingForNewLink = didToggleSetting && nextValue.url === undefined; // If link will be assigned, the state value can be considered flushed.
104
- // Otherwise, persist the pending changes.
105
-
106
- setNextLinkValue(didToggleSettingForNewLink ? nextValue : undefined);
107
-
108
- if (didToggleSettingForNewLink) {
109
- return;
110
- }
111
-
76
+ };
112
77
  const newUrl = (0, _url.prependHTTP)(nextValue.url);
113
78
  const linkFormat = (0, _utils.createLinkFormat)({
114
79
  url: newUrl,
@@ -117,7 +82,6 @@ function InlineLinkUI({
117
82
  opensInNewWindow: nextValue.opensInNewTab
118
83
  });
119
84
  const newText = nextValue.title || newUrl;
120
-
121
85
  if ((0, _richText.isCollapsed)(value) && !isActive) {
122
86
  // Scenario: we don't have any actively selected text or formats.
123
87
  const toInsert = (0, _richText.applyFormat)((0, _richText.create)({
@@ -127,7 +91,6 @@ function InlineLinkUI({
127
91
  } else {
128
92
  // Scenario: we have any active text selection or an active format.
129
93
  let newValue;
130
-
131
94
  if (newText === richTextText) {
132
95
  // If we're not updating the text then ignore.
133
96
  newValue = (0, _richText.applyFormat)(value, linkFormat);
@@ -136,19 +99,24 @@ function InlineLinkUI({
136
99
  // can apply formats to it.
137
100
  newValue = (0, _richText.create)({
138
101
  text: newText
139
- }); // Apply the new Link format to this new text value.
102
+ });
140
103
 
141
- newValue = (0, _richText.applyFormat)(newValue, linkFormat, 0, newText.length); // Get the boundaries of the active link format.
104
+ // Apply the new Link format to this new text value.
105
+ newValue = (0, _richText.applyFormat)(newValue, linkFormat, 0, newText.length);
142
106
 
107
+ // Get the boundaries of the active link format.
143
108
  const boundary = (0, _utils.getFormatBoundary)(value, {
144
109
  type: 'core/link'
145
- }); // Split the value at the start of the active link format.
110
+ });
111
+
112
+ // Split the value at the start of the active link format.
146
113
  // Passing "start" as the 3rd parameter is required to ensure
147
114
  // the second half of the split value is split at the format's
148
115
  // start boundary and avoids relying on the value's "end" property
149
116
  // which may not correspond correctly.
117
+ const [valBefore, valAfter] = (0, _richText.split)(value, boundary.start, boundary.start);
150
118
 
151
- const [valBefore, valAfter] = (0, _richText.split)(value, boundary.start, boundary.start); // Update the original (full) RichTextValue replacing the
119
+ // Update the original (full) RichTextValue replacing the
152
120
  // target text with the *new* RichTextValue containing:
153
121
  // 1. The new text content.
154
122
  // 2. The new link format.
@@ -160,44 +128,43 @@ function InlineLinkUI({
160
128
  // Note original formats will be lost when applying this change.
161
129
  // That is expected behaviour.
162
130
  // See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.
163
-
164
131
  const newValAfter = (0, _richText.replace)(valAfter, richTextText, newValue);
165
132
  newValue = (0, _richText.concat)(valBefore, newValAfter);
166
133
  }
167
-
168
134
  newValue.start = newValue.end;
135
+
136
+ // Hides the Link UI.
169
137
  newValue.activeFormats = [];
170
138
  onChange(newValue);
171
- } // Focus should only be shifted back to the formatted segment when the
172
- // URL is submitted.
173
-
139
+ }
174
140
 
141
+ // Focus should only be shifted back to the formatted segment when the
142
+ // URL is submitted.
175
143
  if (!didToggleSetting) {
176
144
  stopAddingLink();
177
145
  }
178
-
179
146
  if (!(0, _utils.isValidHref)(newUrl)) {
180
- speak((0, _i18n.__)('Warning: the link has been inserted but may have errors. Please test it.'), 'assertive');
147
+ (0, _a11y.speak)((0, _i18n.__)('Warning: the link has been inserted but may have errors. Please test it.'), 'assertive');
181
148
  } else if (isActive) {
182
- speak((0, _i18n.__)('Link edited.'), 'assertive');
149
+ (0, _a11y.speak)((0, _i18n.__)('Link edited.'), 'assertive');
183
150
  } else {
184
- speak((0, _i18n.__)('Link inserted.'), 'assertive');
151
+ (0, _a11y.speak)((0, _i18n.__)('Link inserted.'), 'assertive');
185
152
  }
186
153
  }
187
-
188
154
  const popoverAnchor = (0, _richText.useAnchor)({
189
155
  editableContentElement: contentRef.current,
190
156
  settings: _index.link
191
- }); // Generate a string based key that is unique to this anchor reference.
157
+ });
158
+
159
+ // Generate a string based key that is unique to this anchor reference.
192
160
  // This is used to force re-mount the LinkControl component to avoid
193
161
  // potential stale state bugs caused by the component not being remounted
194
162
  // See https://github.com/WordPress/gutenberg/pull/34742.
163
+ const forceRemountKey = (0, _useLinkInstanceKey.default)(popoverAnchor);
195
164
 
196
- const forceRemountKey = (0, _useLinkInstanceKey.default)(popoverAnchor); // The focusOnMount prop shouldn't evolve during render of a Popover
165
+ // The focusOnMount prop shouldn't evolve during render of a Popover
197
166
  // otherwise it causes a render of the content.
198
-
199
167
  const focusOnMount = (0, _element.useRef)(addingLink ? 'firstElement' : false);
200
-
201
168
  async function handleCreate(pageTitle) {
202
169
  const page = await createPageEntity({
203
170
  title: pageTitle,
@@ -211,15 +178,12 @@ function InlineLinkUI({
211
178
  kind: 'post-type'
212
179
  };
213
180
  }
214
-
215
181
  function createButtonText(searchTerm) {
216
- return (0, _element.createInterpolateElement)((0, _i18n.sprintf)(
217
- /* translators: %s: search term. */
182
+ return (0, _element.createInterpolateElement)((0, _i18n.sprintf)( /* translators: %s: search term. */
218
183
  (0, _i18n.__)('Create page: <mark>%s</mark>'), searchTerm), {
219
184
  mark: (0, _element.createElement)("mark", null)
220
185
  });
221
186
  }
222
-
223
187
  return (0, _element.createElement)(_components.Popover, {
224
188
  anchor: popoverAnchor,
225
189
  focusOnMount: focusOnMount.current,
@@ -240,29 +204,28 @@ function InlineLinkUI({
240
204
  hasTextControl: true
241
205
  }));
242
206
  }
243
-
244
207
  function getRichTextValueFromSelection(value, isActive) {
245
208
  // Default to the selection ranges on the RichTextValue object.
246
209
  let textStart = value.start;
247
- let textEnd = value.end; // If the format is currently active then the rich text value
210
+ let textEnd = value.end;
211
+
212
+ // If the format is currently active then the rich text value
248
213
  // should always be taken from the bounds of the active format
249
214
  // and not the selected text.
250
-
251
215
  if (isActive) {
252
216
  const boundary = (0, _utils.getFormatBoundary)(value, {
253
217
  type: 'core/link'
254
218
  });
255
- textStart = boundary.start; // Text *selection* always extends +1 beyond the edge of the format.
256
- // We account for that here.
219
+ textStart = boundary.start;
257
220
 
221
+ // Text *selection* always extends +1 beyond the edge of the format.
222
+ // We account for that here.
258
223
  textEnd = boundary.end + 1;
259
- } // Get a RichTextValue containing the selected text content.
260
-
224
+ }
261
225
 
226
+ // Get a RichTextValue containing the selected text content.
262
227
  return (0, _richText.slice)(value, textStart, textEnd);
263
228
  }
264
-
265
- var _default = (0, _components.withSpokenMessages)(InlineLinkUI);
266
-
229
+ var _default = InlineLinkUI;
267
230
  exports.default = _default;
268
231
  //# sourceMappingURL=inline.js.map