@wordpress/format-library 5.32.0 → 5.32.1-next.ff1cebbba.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 (132) hide show
  1. package/build/bold/index.js +69 -58
  2. package/build/bold/index.js.map +7 -1
  3. package/build/code/index.js +62 -54
  4. package/build/code/index.js.map +7 -1
  5. package/build/default-formats.js +52 -24
  6. package/build/default-formats.js.map +7 -1
  7. package/build/image/index.js +185 -153
  8. package/build/image/index.js.map +7 -1
  9. package/build/index.js +28 -18
  10. package/build/index.js.map +7 -1
  11. package/build/italic/index.js +69 -58
  12. package/build/italic/index.js.map +7 -1
  13. package/build/keyboard/index.js +47 -36
  14. package/build/keyboard/index.js.map +7 -1
  15. package/build/language/index.js +145 -113
  16. package/build/language/index.js.map +7 -1
  17. package/build/link/css-classes-setting.js +81 -0
  18. package/build/link/css-classes-setting.js.map +7 -0
  19. package/build/link/index.js +162 -167
  20. package/build/link/index.js.map +7 -1
  21. package/build/link/inline.js +186 -174
  22. package/build/link/inline.js.map +7 -1
  23. package/build/link/use-link-instance-key.js +25 -19
  24. package/build/link/use-link-instance-key.js.map +7 -1
  25. package/build/link/utils.js +66 -115
  26. package/build/link/utils.js.map +7 -1
  27. package/build/lock-unlock.js +31 -15
  28. package/build/lock-unlock.js.map +7 -1
  29. package/build/non-breaking-space/index.js +44 -28
  30. package/build/non-breaking-space/index.js.map +7 -1
  31. package/build/strikethrough/index.js +57 -42
  32. package/build/strikethrough/index.js.map +7 -1
  33. package/build/subscript/index.js +47 -36
  34. package/build/subscript/index.js.map +7 -1
  35. package/build/superscript/index.js +47 -36
  36. package/build/superscript/index.js.map +7 -1
  37. package/build/text-color/index.js +102 -70
  38. package/build/text-color/index.js.map +7 -1
  39. package/build/text-color/inline.js +118 -116
  40. package/build/text-color/inline.js.map +7 -1
  41. package/build/underline/index.js +62 -40
  42. package/build/underline/index.js.map +7 -1
  43. package/build/unknown/index.js +51 -37
  44. package/build/unknown/index.js.map +7 -1
  45. package/build-module/bold/index.js +52 -52
  46. package/build-module/bold/index.js.map +7 -1
  47. package/build-module/code/index.js +41 -46
  48. package/build-module/code/index.js.map +7 -1
  49. package/build-module/default-formats.js +34 -19
  50. package/build-module/default-formats.js.map +7 -1
  51. package/build-module/image/index.js +174 -144
  52. package/build-module/image/index.js.map +7 -1
  53. package/build-module/index.js +6 -14
  54. package/build-module/index.js.map +7 -1
  55. package/build-module/italic/index.js +52 -52
  56. package/build-module/italic/index.js.map +7 -1
  57. package/build-module/keyboard/index.js +25 -30
  58. package/build-module/keyboard/index.js.map +7 -1
  59. package/build-module/language/index.js +128 -105
  60. package/build-module/language/index.js.map +7 -1
  61. package/build-module/link/css-classes-setting.js +67 -0
  62. package/build-module/link/css-classes-setting.js.map +7 -0
  63. package/build-module/link/index.js +128 -146
  64. package/build-module/link/index.js.map +7 -1
  65. package/build-module/link/inline.js +158 -154
  66. package/build-module/link/inline.js.map +7 -1
  67. package/build-module/link/use-link-instance-key.js +7 -14
  68. package/build-module/link/use-link-instance-key.js.map +7 -1
  69. package/build-module/link/utils.js +46 -101
  70. package/build-module/link/utils.js.map +7 -1
  71. package/build-module/lock-unlock.js +8 -7
  72. package/build-module/lock-unlock.js.map +7 -1
  73. package/build-module/non-breaking-space/index.js +22 -22
  74. package/build-module/non-breaking-space/index.js.map +7 -1
  75. package/build-module/strikethrough/index.js +38 -36
  76. package/build-module/strikethrough/index.js.map +7 -1
  77. package/build-module/subscript/index.js +25 -30
  78. package/build-module/subscript/index.js.map +7 -1
  79. package/build-module/superscript/index.js +25 -30
  80. package/build-module/superscript/index.js.map +7 -1
  81. package/build-module/text-color/index.js +72 -61
  82. package/build-module/text-color/index.js.map +7 -1
  83. package/build-module/text-color/inline.js +107 -106
  84. package/build-module/text-color/inline.js.map +7 -1
  85. package/build-module/underline/index.js +43 -34
  86. package/build-module/underline/index.js.map +7 -1
  87. package/build-module/unknown/index.js +26 -28
  88. package/build-module/unknown/index.js.map +7 -1
  89. package/build-style/style-rtl.css +0 -194
  90. package/build-style/style.css +0 -194
  91. package/package.json +21 -15
  92. package/src/image/style.scss +3 -0
  93. package/src/link/css-classes-setting.js +89 -0
  94. package/src/link/index.js +1 -0
  95. package/src/link/inline.js +19 -0
  96. package/src/link/style.scss +3 -0
  97. package/src/link/test/css-classes-setting.js +144 -0
  98. package/src/link/utils.js +8 -0
  99. package/src/style.scss +4 -4
  100. package/src/text-color/style.scss +2 -0
  101. package/build/default-formats.native.js +0 -16
  102. package/build/default-formats.native.js.map +0 -1
  103. package/build/link/index.native.js +0 -174
  104. package/build/link/index.native.js.map +0 -1
  105. package/build/link/modal-screens/link-picker-screen.native.js +0 -67
  106. package/build/link/modal-screens/link-picker-screen.native.js.map +0 -1
  107. package/build/link/modal-screens/link-settings-screen.native.js +0 -226
  108. package/build/link/modal-screens/link-settings-screen.native.js.map +0 -1
  109. package/build/link/modal-screens/screens.native.js +0 -11
  110. package/build/link/modal-screens/screens.native.js.map +0 -1
  111. package/build/link/modal.native.js +0 -53
  112. package/build/link/modal.native.js.map +0 -1
  113. package/build/text-color/index.native.js +0 -134
  114. package/build/text-color/index.native.js.map +0 -1
  115. package/build/text-color/inline.native.js +0 -150
  116. package/build/text-color/inline.native.js.map +0 -1
  117. package/build-module/default-formats.native.js +0 -10
  118. package/build-module/default-formats.native.js.map +0 -1
  119. package/build-module/link/index.native.js +0 -166
  120. package/build-module/link/index.native.js.map +0 -1
  121. package/build-module/link/modal-screens/link-picker-screen.native.js +0 -59
  122. package/build-module/link/modal-screens/link-picker-screen.native.js.map +0 -1
  123. package/build-module/link/modal-screens/link-settings-screen.native.js +0 -218
  124. package/build-module/link/modal-screens/link-settings-screen.native.js.map +0 -1
  125. package/build-module/link/modal-screens/screens.native.js +0 -5
  126. package/build-module/link/modal-screens/screens.native.js.map +0 -1
  127. package/build-module/link/modal.native.js +0 -45
  128. package/build-module/link/modal.native.js.map +0 -1
  129. package/build-module/text-color/index.native.js +0 -126
  130. package/build-module/text-color/index.native.js.map +0 -1
  131. package/build-module/text-color/inline.native.js +0 -142
  132. package/build-module/text-color/inline.native.js.map +0 -1
@@ -1,27 +1,30 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { __ } from '@wordpress/i18n';
5
- import { useState, useLayoutEffect, useEffect } from '@wordpress/element';
6
- import { getTextContent, applyFormat, removeFormat, slice, isCollapsed, insert, create } from '@wordpress/rich-text';
7
- import { isURL, isEmail, isPhoneNumber } from '@wordpress/url';
8
- import { RichTextToolbarButton, RichTextShortcut, privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
9
- import { decodeEntities } from '@wordpress/html-entities';
10
- import { link as linkIcon } from '@wordpress/icons';
11
- import { speak } from '@wordpress/a11y';
12
-
13
- /**
14
- * Internal dependencies
15
- */
16
- import InlineLinkUI from './inline';
17
- import { isValidHref } from './utils';
18
- import { unlock } from '../lock-unlock';
19
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
20
- const {
21
- essentialFormatKey
22
- } = unlock(blockEditorPrivateApis);
23
- const name = 'core/link';
24
- const title = __('Link');
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { __ } from "@wordpress/i18n";
3
+ import { useState, useLayoutEffect, useEffect } from "@wordpress/element";
4
+ import {
5
+ getTextContent,
6
+ applyFormat,
7
+ removeFormat,
8
+ slice,
9
+ isCollapsed,
10
+ insert,
11
+ create
12
+ } from "@wordpress/rich-text";
13
+ import { isURL, isEmail, isPhoneNumber } from "@wordpress/url";
14
+ import {
15
+ RichTextToolbarButton,
16
+ RichTextShortcut,
17
+ privateApis as blockEditorPrivateApis
18
+ } from "@wordpress/block-editor";
19
+ import { decodeEntities } from "@wordpress/html-entities";
20
+ import { link as linkIcon } from "@wordpress/icons";
21
+ import { speak } from "@wordpress/a11y";
22
+ import InlineLinkUI from "./inline";
23
+ import { isValidHref } from "./utils";
24
+ import { unlock } from "../lock-unlock";
25
+ const { essentialFormatKey } = unlock(blockEditorPrivateApis);
26
+ const name = "core/link";
27
+ const title = __("Link");
25
28
  function Edit({
26
29
  isActive,
27
30
  activeAttributes,
@@ -31,13 +34,8 @@ function Edit({
31
34
  contentRef
32
35
  }) {
33
36
  const [addingLink, setAddingLink] = useState(false);
34
-
35
- // We only need to store the button element that opened the popover. We can ignore the other states, as they will be handled by the onFocus prop to return to the rich text field.
36
37
  const [openedBy, setOpenedBy] = useState(null);
37
38
  useEffect(() => {
38
- // When the link becomes inactive (i.e. isActive is false), reset the editingLink state
39
- // and the creatingLink state. This means that if the Link UI is displayed and the link
40
- // becomes inactive (e.g. used arrow keys to move cursor outside of link bounds), the UI will close.
41
39
  if (!isActive) {
42
40
  setAddingLink(false);
43
41
  }
@@ -48,169 +46,144 @@ function Edit({
48
46
  return;
49
47
  }
50
48
  function handleClick(event) {
51
- // There is a situation whereby there is an existing link in the rich text
52
- // and the user clicks on the leftmost edge of that link and fails to activate
53
- // the link format, but the click event still fires on the `<a>` element.
54
- // This causes the `editingLink` state to be set to `true` and the link UI
55
- // to be rendered in "creating" mode. We need to check isActive to see if
56
- // we have an active link format.
57
- const link = event.target.closest('[contenteditable] a');
58
- if (!link ||
59
- // other formats (e.g. bold) may be nested within the link.
49
+ const link2 = event.target.closest("[contenteditable] a");
50
+ if (!link2 || // other formats (e.g. bold) may be nested within the link.
60
51
  !isActive) {
61
52
  return;
62
53
  }
63
54
  setAddingLink(true);
64
55
  setOpenedBy({
65
- el: link,
66
- action: 'click'
56
+ el: link2,
57
+ action: "click"
67
58
  });
68
59
  }
69
- editableContentElement.addEventListener('click', handleClick);
60
+ editableContentElement.addEventListener("click", handleClick);
70
61
  return () => {
71
- editableContentElement.removeEventListener('click', handleClick);
62
+ editableContentElement.removeEventListener("click", handleClick);
72
63
  };
73
64
  }, [contentRef, isActive]);
74
65
  function addLink(target) {
75
66
  const text = getTextContent(slice(value));
76
67
  if (!isActive && text && isURL(text) && isValidHref(text)) {
77
- onChange(applyFormat(value, {
78
- type: name,
79
- attributes: {
80
- url: text
81
- }
82
- }));
68
+ onChange(
69
+ applyFormat(value, {
70
+ type: name,
71
+ attributes: { url: text }
72
+ })
73
+ );
83
74
  } else if (!isActive && text && isEmail(text)) {
84
- onChange(applyFormat(value, {
85
- type: name,
86
- attributes: {
87
- url: `mailto:${text}`
88
- }
89
- }));
75
+ onChange(
76
+ applyFormat(value, {
77
+ type: name,
78
+ attributes: { url: `mailto:${text}` }
79
+ })
80
+ );
90
81
  } else if (!isActive && text && isPhoneNumber(text)) {
91
- onChange(applyFormat(value, {
92
- type: name,
93
- attributes: {
94
- url: `tel:${text.replace(/\D/g, '')}`
95
- }
96
- }));
82
+ onChange(
83
+ applyFormat(value, {
84
+ type: name,
85
+ attributes: { url: `tel:${text.replace(/\D/g, "")}` }
86
+ })
87
+ );
97
88
  } else {
98
89
  if (target) {
99
90
  setOpenedBy({
100
91
  el: target,
101
- action: null // We don't need to distinguish between click or keyboard here
92
+ action: null
93
+ // We don't need to distinguish between click or keyboard here
102
94
  });
103
95
  }
104
96
  setAddingLink(true);
105
97
  }
106
98
  }
107
-
108
- /**
109
- * Runs when the popover is closed via escape keypress, unlinking the selected text,
110
- * but _not_ on a click outside the popover. onFocusOutside handles that.
111
- */
112
99
  function stopAddingLink() {
113
- // Don't let the click handler on the toolbar button trigger again.
114
-
115
- // There are two places for us to return focus to on Escape keypress:
116
- // 1. The rich text field.
117
- // 2. The toolbar button.
118
-
119
- // The toolbar button is the only one we need to handle returning focus to.
120
- // Otherwise, we rely on the passed in onFocus to return focus to the rich text field.
121
-
122
- // Close the popover
123
100
  setAddingLink(false);
124
-
125
- // Return focus to the toolbar button or the rich text field
126
- if (openedBy?.el?.tagName === 'BUTTON') {
101
+ if (openedBy?.el?.tagName === "BUTTON") {
127
102
  openedBy.el.focus();
128
103
  } else {
129
104
  onFocus();
130
105
  }
131
- // Remove the openedBy state
132
106
  setOpenedBy(null);
133
107
  }
134
-
135
- // Test for this:
136
- // 1. Click on the link button
137
- // 2. Click the Options button in the top right of header
138
- // 3. Focus should be in the dropdown of the Options button
139
- // 4. Press Escape
140
- // 5. Focus should be on the Options button
141
108
  function onFocusOutside() {
142
109
  setAddingLink(false);
143
110
  setOpenedBy(null);
144
111
  }
145
112
  function onRemoveFormat() {
146
113
  onChange(removeFormat(value, name));
147
- speak(__('Link removed.'), 'assertive');
114
+ speak(__("Link removed."), "assertive");
148
115
  }
149
-
150
- // Only autofocus if we have clicked a link within the editor
151
- const shouldAutoFocus = !(openedBy?.el?.tagName === 'A' && openedBy?.action === 'click');
116
+ const shouldAutoFocus = !(openedBy?.el?.tagName === "A" && openedBy?.action === "click");
152
117
  const hasSelection = !isCollapsed(value);
153
- return /*#__PURE__*/_jsxs(_Fragment, {
154
- children: [hasSelection && /*#__PURE__*/_jsx(RichTextShortcut, {
155
- type: "primary",
156
- character: "k",
157
- onUse: addLink
158
- }), /*#__PURE__*/_jsx(RichTextShortcut, {
159
- type: "primaryShift",
160
- character: "k",
161
- onUse: onRemoveFormat
162
- }), /*#__PURE__*/_jsx(RichTextToolbarButton, {
163
- name: "link",
164
- icon: linkIcon,
165
- title: isActive ? __('Link') : title,
166
- onClick: event => {
167
- addLink(event.currentTarget);
168
- },
169
- isActive: isActive || addingLink,
170
- shortcutType: "primary",
171
- shortcutCharacter: "k",
172
- "aria-haspopup": "true",
173
- "aria-expanded": addingLink
174
- }), addingLink && /*#__PURE__*/_jsx(InlineLinkUI, {
175
- stopAddingLink: stopAddingLink,
176
- onFocusOutside: onFocusOutside,
177
- isActive: isActive,
178
- activeAttributes: activeAttributes,
179
- value: value,
180
- onChange: onChange,
181
- contentRef: contentRef,
182
- focusOnMount: shouldAutoFocus ? 'firstElement' : false
183
- })]
184
- });
118
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
119
+ hasSelection && /* @__PURE__ */ jsx(
120
+ RichTextShortcut,
121
+ {
122
+ type: "primary",
123
+ character: "k",
124
+ onUse: addLink
125
+ }
126
+ ),
127
+ /* @__PURE__ */ jsx(
128
+ RichTextShortcut,
129
+ {
130
+ type: "primaryShift",
131
+ character: "k",
132
+ onUse: onRemoveFormat
133
+ }
134
+ ),
135
+ /* @__PURE__ */ jsx(
136
+ RichTextToolbarButton,
137
+ {
138
+ name: "link",
139
+ icon: linkIcon,
140
+ title: isActive ? __("Link") : title,
141
+ onClick: (event) => {
142
+ addLink(event.currentTarget);
143
+ },
144
+ isActive: isActive || addingLink,
145
+ shortcutType: "primary",
146
+ shortcutCharacter: "k",
147
+ "aria-haspopup": "true",
148
+ "aria-expanded": addingLink
149
+ }
150
+ ),
151
+ addingLink && /* @__PURE__ */ jsx(
152
+ InlineLinkUI,
153
+ {
154
+ stopAddingLink,
155
+ onFocusOutside,
156
+ isActive,
157
+ activeAttributes,
158
+ value,
159
+ onChange,
160
+ contentRef,
161
+ focusOnMount: shouldAutoFocus ? "firstElement" : false
162
+ }
163
+ )
164
+ ] });
185
165
  }
186
- export const link = {
166
+ const link = {
187
167
  name,
188
168
  title,
189
- tagName: 'a',
169
+ tagName: "a",
190
170
  className: null,
191
171
  attributes: {
192
- url: 'href',
193
- type: 'data-type',
194
- id: 'data-id',
195
- _id: 'id',
196
- target: 'target',
197
- rel: 'rel'
172
+ url: "href",
173
+ type: "data-type",
174
+ id: "data-id",
175
+ _id: "id",
176
+ target: "target",
177
+ rel: "rel",
178
+ class: "class"
198
179
  },
199
180
  [essentialFormatKey]: true,
200
- __unstablePasteRule(value, {
201
- html,
202
- plainText
203
- }) {
204
- const pastedText = (html || plainText).replace(/<[^>]+>/g, '').trim();
205
-
206
- // A URL was pasted, turn the selection into a link.
207
- // For the link pasting feature, allow only http(s) protocols.
181
+ __unstablePasteRule(value, { html, plainText }) {
182
+ const pastedText = (html || plainText).replace(/<[^>]+>/g, "").trim();
208
183
  if (!isURL(pastedText) || !/^https?:/.test(pastedText)) {
209
184
  return value;
210
185
  }
211
-
212
- // Allows us to ask for this information when we get a report.
213
- window.console.log('Created link:\n\n', pastedText);
186
+ window.console.log("Created link:\n\n", pastedText);
214
187
  const format = {
215
188
  type: name,
216
189
  attributes: {
@@ -218,12 +191,21 @@ export const link = {
218
191
  }
219
192
  };
220
193
  if (isCollapsed(value)) {
221
- return insert(value, applyFormat(create({
222
- text: plainText
223
- }), format, 0, plainText.length));
194
+ return insert(
195
+ value,
196
+ applyFormat(
197
+ create({ text: plainText }),
198
+ format,
199
+ 0,
200
+ plainText.length
201
+ )
202
+ );
224
203
  }
225
204
  return applyFormat(value, format);
226
205
  },
227
206
  edit: Edit
228
207
  };
229
- //# sourceMappingURL=index.js.map
208
+ export {
209
+ link
210
+ };
211
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["__","useState","useLayoutEffect","useEffect","getTextContent","applyFormat","removeFormat","slice","isCollapsed","insert","create","isURL","isEmail","isPhoneNumber","RichTextToolbarButton","RichTextShortcut","privateApis","blockEditorPrivateApis","decodeEntities","link","linkIcon","speak","InlineLinkUI","isValidHref","unlock","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","essentialFormatKey","name","title","Edit","isActive","activeAttributes","value","onChange","onFocus","contentRef","addingLink","setAddingLink","openedBy","setOpenedBy","editableContentElement","current","handleClick","event","target","closest","el","action","addEventListener","removeEventListener","addLink","text","type","attributes","url","replace","stopAddingLink","tagName","focus","onFocusOutside","onRemoveFormat","shouldAutoFocus","hasSelection","children","character","onUse","icon","onClick","currentTarget","shortcutType","shortcutCharacter","focusOnMount","className","id","_id","rel","__unstablePasteRule","html","plainText","pastedText","trim","test","window","console","log","format","length","edit"],"sources":["@wordpress/format-library/src/link/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState, useLayoutEffect, useEffect } from '@wordpress/element';\nimport {\n\tgetTextContent,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\tisCollapsed,\n\tinsert,\n\tcreate,\n} from '@wordpress/rich-text';\nimport { isURL, isEmail, isPhoneNumber } from '@wordpress/url';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { link as linkIcon } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport InlineLinkUI from './inline';\nimport { isValidHref } from './utils';\nimport { unlock } from '../lock-unlock';\n\nconst { essentialFormatKey } = unlock( blockEditorPrivateApis );\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\t// We only need to store the button element that opened the popover. We can ignore the other states, as they will be handled by the onFocus prop to return to the rich text field.\n\tconst [ openedBy, setOpenedBy ] = useState( null );\n\n\tuseEffect( () => {\n\t\t// When the link becomes inactive (i.e. isActive is false), reset the editingLink state\n\t\t// and the creatingLink state. This means that if the Link UI is displayed and the link\n\t\t// becomes inactive (e.g. used arrow keys to move cursor outside of link bounds), the UI will close.\n\t\tif ( ! isActive ) {\n\t\t\tsetAddingLink( false );\n\t\t}\n\t}, [ isActive ] );\n\n\tuseLayoutEffect( () => {\n\t\tconst editableContentElement = contentRef.current;\n\t\tif ( ! editableContentElement ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfunction handleClick( event ) {\n\t\t\t// There is a situation whereby there is an existing link in the rich text\n\t\t\t// and the user clicks on the leftmost edge of that link and fails to activate\n\t\t\t// the link format, but the click event still fires on the `<a>` element.\n\t\t\t// This causes the `editingLink` state to be set to `true` and the link UI\n\t\t\t// to be rendered in \"creating\" mode. We need to check isActive to see if\n\t\t\t// we have an active link format.\n\t\t\tconst link = event.target.closest( '[contenteditable] a' );\n\t\t\tif (\n\t\t\t\t! link || // other formats (e.g. bold) may be nested within the link.\n\t\t\t\t! isActive\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetAddingLink( true );\n\t\t\tsetOpenedBy( {\n\t\t\t\tel: link,\n\t\t\t\taction: 'click',\n\t\t\t} );\n\t\t}\n\n\t\teditableContentElement.addEventListener( 'click', handleClick );\n\n\t\treturn () => {\n\t\t\teditableContentElement.removeEventListener( 'click', handleClick );\n\t\t};\n\t}, [ contentRef, isActive ] );\n\n\tfunction addLink( target ) {\n\t\tconst text = getTextContent( slice( value ) );\n\n\t\tif ( ! isActive && 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 ( ! isActive && 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 if ( ! isActive && text && isPhoneNumber( 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: `tel:${ text.replace( /\\D/g, '' ) }` },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else {\n\t\t\tif ( target ) {\n\t\t\t\tsetOpenedBy( {\n\t\t\t\t\tel: target,\n\t\t\t\t\taction: null, // We don't need to distinguish between click or keyboard here\n\t\t\t\t} );\n\t\t\t}\n\t\t\tsetAddingLink( true );\n\t\t}\n\t}\n\n\t/**\n\t * Runs when the popover is closed via escape keypress, unlinking the selected text,\n\t * but _not_ on a click outside the popover. onFocusOutside handles that.\n\t */\n\tfunction stopAddingLink() {\n\t\t// Don't let the click handler on the toolbar button trigger again.\n\n\t\t// There are two places for us to return focus to on Escape keypress:\n\t\t// 1. The rich text field.\n\t\t// 2. The toolbar button.\n\n\t\t// The toolbar button is the only one we need to handle returning focus to.\n\t\t// Otherwise, we rely on the passed in onFocus to return focus to the rich text field.\n\n\t\t// Close the popover\n\t\tsetAddingLink( false );\n\n\t\t// Return focus to the toolbar button or the rich text field\n\t\tif ( openedBy?.el?.tagName === 'BUTTON' ) {\n\t\t\topenedBy.el.focus();\n\t\t} else {\n\t\t\tonFocus();\n\t\t}\n\t\t// Remove the openedBy state\n\t\tsetOpenedBy( null );\n\t}\n\n\t// Test for this:\n\t// 1. Click on the link button\n\t// 2. Click the Options button in the top right of header\n\t// 3. Focus should be in the dropdown of the Options button\n\t// 4. Press Escape\n\t// 5. Focus should be on the Options button\n\tfunction onFocusOutside() {\n\t\tsetAddingLink( false );\n\t\tsetOpenedBy( null );\n\t}\n\n\tfunction onRemoveFormat() {\n\t\tonChange( removeFormat( value, name ) );\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\t// Only autofocus if we have clicked a link within the editor\n\tconst shouldAutoFocus = ! (\n\t\topenedBy?.el?.tagName === 'A' && openedBy?.action === 'click'\n\t);\n\n\tconst hasSelection = ! isCollapsed( value );\n\n\treturn (\n\t\t<>\n\t\t\t{ hasSelection && (\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"k\"\n\t\t\t\t\tonUse={ addLink }\n\t\t\t\t/>\n\t\t\t) }\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<RichTextToolbarButton\n\t\t\t\tname=\"link\"\n\t\t\t\ticon={ linkIcon }\n\t\t\t\ttitle={ isActive ? __( 'Link' ) : title }\n\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\taddLink( event.currentTarget );\n\t\t\t\t} }\n\t\t\t\tisActive={ isActive || addingLink }\n\t\t\t\tshortcutType=\"primary\"\n\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\taria-haspopup=\"true\"\n\t\t\t\taria-expanded={ addingLink }\n\t\t\t/>\n\t\t\t{ addingLink && (\n\t\t\t\t<InlineLinkUI\n\t\t\t\t\tstopAddingLink={ stopAddingLink }\n\t\t\t\t\tonFocusOutside={ onFocusOutside }\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\tfocusOnMount={ shouldAutoFocus ? 'firstElement' : false }\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\t_id: 'id',\n\t\ttarget: 'target',\n\t\trel: 'rel',\n\t},\n\t[ essentialFormatKey ]: true,\n\t__unstablePasteRule( value, { html, plainText } ) {\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\t// For the link pasting feature, allow only http(s) protocols.\n\t\tif ( ! isURL( pastedText ) || ! /^https?:/.test( 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\tconst format = {\n\t\t\ttype: name,\n\t\t\tattributes: {\n\t\t\t\turl: decodeEntities( pastedText ),\n\t\t\t},\n\t\t};\n\n\t\tif ( isCollapsed( value ) ) {\n\t\t\treturn insert(\n\t\t\t\tvalue,\n\t\t\t\tapplyFormat(\n\t\t\t\t\tcreate( { text: plainText } ),\n\t\t\t\t\tformat,\n\t\t\t\t\t0,\n\t\t\t\t\tplainText.length\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn applyFormat( value, format );\n\t},\n\tedit: Edit,\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC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,IAAI;EACfnB,UAAU,EAAE;IACXC,GAAG,EAAE,MAAM;IACXF,IAAI,EAAE,WAAW;IACjBqB,EAAE,EAAE,SAAS;IACbC,GAAG,EAAE,IAAI;IACT9B,MAAM,EAAE,QAAQ;IAChB+B,GAAG,EAAE;EACN,CAAC;EACD,CAAEjD,kBAAkB,GAAI,IAAI;EAC5BkD,mBAAmBA,CAAE5C,KAAK,EAAE;IAAE6C,IAAI;IAAEC;EAAU,CAAC,EAAG;IACjD,MAAMC,UAAU,GAAG,CAAEF,IAAI,IAAIC,SAAS,EACpCvB,OAAO,CAAE,UAAU,EAAE,EAAG,CAAC,CACzByB,IAAI,CAAC,CAAC;;IAER;IACA;IACA,IAAK,CAAE1E,KAAK,CAAEyE,UAAW,CAAC,IAAI,CAAE,UAAU,CAACE,IAAI,CAAEF,UAAW,CAAC,EAAG;MAC/D,OAAO/C,KAAK;IACb;;IAEA;IACAkD,MAAM,CAACC,OAAO,CAACC,GAAG,CAAE,mBAAmB,EAAEL,UAAW,CAAC;IAErD,MAAMM,MAAM,GAAG;MACdjC,IAAI,EAAEzB,IAAI;MACV0B,UAAU,EAAE;QACXC,GAAG,EAAEzC,cAAc,CAAEkE,UAAW;MACjC;IACD,CAAC;IAED,IAAK5E,WAAW,CAAE6B,KAAM,CAAC,EAAG;MAC3B,OAAO5B,MAAM,CACZ4B,KAAK,EACLhC,WAAW,CACVK,MAAM,CAAE;QAAE8C,IAAI,EAAE2B;MAAU,CAAE,CAAC,EAC7BO,MAAM,EACN,CAAC,EACDP,SAAS,CAACQ,MACX,CACD,CAAC;IACF;IAEA,OAAOtF,WAAW,CAAEgC,KAAK,EAAEqD,MAAO,CAAC;EACpC,CAAC;EACDE,IAAI,EAAE1D;AACP,CAAC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/link/index.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState, useLayoutEffect, useEffect } from '@wordpress/element';\nimport {\n\tgetTextContent,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\tisCollapsed,\n\tinsert,\n\tcreate,\n} from '@wordpress/rich-text';\nimport { isURL, isEmail, isPhoneNumber } from '@wordpress/url';\nimport {\n\tRichTextToolbarButton,\n\tRichTextShortcut,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { link as linkIcon } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport InlineLinkUI from './inline';\nimport { isValidHref } from './utils';\nimport { unlock } from '../lock-unlock';\n\nconst { essentialFormatKey } = unlock( blockEditorPrivateApis );\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\t// We only need to store the button element that opened the popover. We can ignore the other states, as they will be handled by the onFocus prop to return to the rich text field.\n\tconst [ openedBy, setOpenedBy ] = useState( null );\n\n\tuseEffect( () => {\n\t\t// When the link becomes inactive (i.e. isActive is false), reset the editingLink state\n\t\t// and the creatingLink state. This means that if the Link UI is displayed and the link\n\t\t// becomes inactive (e.g. used arrow keys to move cursor outside of link bounds), the UI will close.\n\t\tif ( ! isActive ) {\n\t\t\tsetAddingLink( false );\n\t\t}\n\t}, [ isActive ] );\n\n\tuseLayoutEffect( () => {\n\t\tconst editableContentElement = contentRef.current;\n\t\tif ( ! editableContentElement ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfunction handleClick( event ) {\n\t\t\t// There is a situation whereby there is an existing link in the rich text\n\t\t\t// and the user clicks on the leftmost edge of that link and fails to activate\n\t\t\t// the link format, but the click event still fires on the `<a>` element.\n\t\t\t// This causes the `editingLink` state to be set to `true` and the link UI\n\t\t\t// to be rendered in \"creating\" mode. We need to check isActive to see if\n\t\t\t// we have an active link format.\n\t\t\tconst link = event.target.closest( '[contenteditable] a' );\n\t\t\tif (\n\t\t\t\t! link || // other formats (e.g. bold) may be nested within the link.\n\t\t\t\t! isActive\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetAddingLink( true );\n\t\t\tsetOpenedBy( {\n\t\t\t\tel: link,\n\t\t\t\taction: 'click',\n\t\t\t} );\n\t\t}\n\n\t\teditableContentElement.addEventListener( 'click', handleClick );\n\n\t\treturn () => {\n\t\t\teditableContentElement.removeEventListener( 'click', handleClick );\n\t\t};\n\t}, [ contentRef, isActive ] );\n\n\tfunction addLink( target ) {\n\t\tconst text = getTextContent( slice( value ) );\n\n\t\tif ( ! isActive && 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 ( ! isActive && 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 if ( ! isActive && text && isPhoneNumber( 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: `tel:${ text.replace( /\\D/g, '' ) }` },\n\t\t\t\t} )\n\t\t\t);\n\t\t} else {\n\t\t\tif ( target ) {\n\t\t\t\tsetOpenedBy( {\n\t\t\t\t\tel: target,\n\t\t\t\t\taction: null, // We don't need to distinguish between click or keyboard here\n\t\t\t\t} );\n\t\t\t}\n\t\t\tsetAddingLink( true );\n\t\t}\n\t}\n\n\t/**\n\t * Runs when the popover is closed via escape keypress, unlinking the selected text,\n\t * but _not_ on a click outside the popover. onFocusOutside handles that.\n\t */\n\tfunction stopAddingLink() {\n\t\t// Don't let the click handler on the toolbar button trigger again.\n\n\t\t// There are two places for us to return focus to on Escape keypress:\n\t\t// 1. The rich text field.\n\t\t// 2. The toolbar button.\n\n\t\t// The toolbar button is the only one we need to handle returning focus to.\n\t\t// Otherwise, we rely on the passed in onFocus to return focus to the rich text field.\n\n\t\t// Close the popover\n\t\tsetAddingLink( false );\n\n\t\t// Return focus to the toolbar button or the rich text field\n\t\tif ( openedBy?.el?.tagName === 'BUTTON' ) {\n\t\t\topenedBy.el.focus();\n\t\t} else {\n\t\t\tonFocus();\n\t\t}\n\t\t// Remove the openedBy state\n\t\tsetOpenedBy( null );\n\t}\n\n\t// Test for this:\n\t// 1. Click on the link button\n\t// 2. Click the Options button in the top right of header\n\t// 3. Focus should be in the dropdown of the Options button\n\t// 4. Press Escape\n\t// 5. Focus should be on the Options button\n\tfunction onFocusOutside() {\n\t\tsetAddingLink( false );\n\t\tsetOpenedBy( null );\n\t}\n\n\tfunction onRemoveFormat() {\n\t\tonChange( removeFormat( value, name ) );\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\t// Only autofocus if we have clicked a link within the editor\n\tconst shouldAutoFocus = ! (\n\t\topenedBy?.el?.tagName === 'A' && openedBy?.action === 'click'\n\t);\n\n\tconst hasSelection = ! isCollapsed( value );\n\n\treturn (\n\t\t<>\n\t\t\t{ hasSelection && (\n\t\t\t\t<RichTextShortcut\n\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\tcharacter=\"k\"\n\t\t\t\t\tonUse={ addLink }\n\t\t\t\t/>\n\t\t\t) }\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<RichTextToolbarButton\n\t\t\t\tname=\"link\"\n\t\t\t\ticon={ linkIcon }\n\t\t\t\ttitle={ isActive ? __( 'Link' ) : title }\n\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\taddLink( event.currentTarget );\n\t\t\t\t} }\n\t\t\t\tisActive={ isActive || addingLink }\n\t\t\t\tshortcutType=\"primary\"\n\t\t\t\tshortcutCharacter=\"k\"\n\t\t\t\taria-haspopup=\"true\"\n\t\t\t\taria-expanded={ addingLink }\n\t\t\t/>\n\t\t\t{ addingLink && (\n\t\t\t\t<InlineLinkUI\n\t\t\t\t\tstopAddingLink={ stopAddingLink }\n\t\t\t\t\tonFocusOutside={ onFocusOutside }\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\tfocusOnMount={ shouldAutoFocus ? 'firstElement' : false }\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\t_id: 'id',\n\t\ttarget: 'target',\n\t\trel: 'rel',\n\t\tclass: 'class',\n\t},\n\t[ essentialFormatKey ]: true,\n\t__unstablePasteRule( value, { html, plainText } ) {\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\t// For the link pasting feature, allow only http(s) protocols.\n\t\tif ( ! isURL( pastedText ) || ! /^https?:/.test( 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\tconst format = {\n\t\t\ttype: name,\n\t\t\tattributes: {\n\t\t\t\turl: decodeEntities( pastedText ),\n\t\t\t},\n\t\t};\n\n\t\tif ( isCollapsed( value ) ) {\n\t\t\treturn insert(\n\t\t\t\tvalue,\n\t\t\t\tapplyFormat(\n\t\t\t\t\tcreate( { text: plainText } ),\n\t\t\t\t\tformat,\n\t\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