@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.
- package/build/bold/index.js +69 -58
- package/build/bold/index.js.map +7 -1
- package/build/code/index.js +62 -54
- package/build/code/index.js.map +7 -1
- package/build/default-formats.js +52 -24
- package/build/default-formats.js.map +7 -1
- package/build/image/index.js +185 -153
- package/build/image/index.js.map +7 -1
- package/build/index.js +28 -18
- package/build/index.js.map +7 -1
- package/build/italic/index.js +69 -58
- package/build/italic/index.js.map +7 -1
- package/build/keyboard/index.js +47 -36
- package/build/keyboard/index.js.map +7 -1
- package/build/language/index.js +145 -113
- package/build/language/index.js.map +7 -1
- package/build/link/css-classes-setting.js +81 -0
- package/build/link/css-classes-setting.js.map +7 -0
- package/build/link/index.js +162 -167
- package/build/link/index.js.map +7 -1
- package/build/link/inline.js +186 -174
- package/build/link/inline.js.map +7 -1
- package/build/link/use-link-instance-key.js +25 -19
- package/build/link/use-link-instance-key.js.map +7 -1
- package/build/link/utils.js +66 -115
- package/build/link/utils.js.map +7 -1
- package/build/lock-unlock.js +31 -15
- package/build/lock-unlock.js.map +7 -1
- package/build/non-breaking-space/index.js +44 -28
- package/build/non-breaking-space/index.js.map +7 -1
- package/build/strikethrough/index.js +57 -42
- package/build/strikethrough/index.js.map +7 -1
- package/build/subscript/index.js +47 -36
- package/build/subscript/index.js.map +7 -1
- package/build/superscript/index.js +47 -36
- package/build/superscript/index.js.map +7 -1
- package/build/text-color/index.js +102 -70
- package/build/text-color/index.js.map +7 -1
- package/build/text-color/inline.js +118 -116
- package/build/text-color/inline.js.map +7 -1
- package/build/underline/index.js +62 -40
- package/build/underline/index.js.map +7 -1
- package/build/unknown/index.js +51 -37
- package/build/unknown/index.js.map +7 -1
- package/build-module/bold/index.js +52 -52
- package/build-module/bold/index.js.map +7 -1
- package/build-module/code/index.js +41 -46
- package/build-module/code/index.js.map +7 -1
- package/build-module/default-formats.js +34 -19
- package/build-module/default-formats.js.map +7 -1
- package/build-module/image/index.js +174 -144
- package/build-module/image/index.js.map +7 -1
- package/build-module/index.js +6 -14
- package/build-module/index.js.map +7 -1
- package/build-module/italic/index.js +52 -52
- package/build-module/italic/index.js.map +7 -1
- package/build-module/keyboard/index.js +25 -30
- package/build-module/keyboard/index.js.map +7 -1
- package/build-module/language/index.js +128 -105
- package/build-module/language/index.js.map +7 -1
- package/build-module/link/css-classes-setting.js +67 -0
- package/build-module/link/css-classes-setting.js.map +7 -0
- package/build-module/link/index.js +128 -146
- package/build-module/link/index.js.map +7 -1
- package/build-module/link/inline.js +158 -154
- package/build-module/link/inline.js.map +7 -1
- package/build-module/link/use-link-instance-key.js +7 -14
- package/build-module/link/use-link-instance-key.js.map +7 -1
- package/build-module/link/utils.js +46 -101
- package/build-module/link/utils.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/non-breaking-space/index.js +22 -22
- package/build-module/non-breaking-space/index.js.map +7 -1
- package/build-module/strikethrough/index.js +38 -36
- package/build-module/strikethrough/index.js.map +7 -1
- package/build-module/subscript/index.js +25 -30
- package/build-module/subscript/index.js.map +7 -1
- package/build-module/superscript/index.js +25 -30
- package/build-module/superscript/index.js.map +7 -1
- package/build-module/text-color/index.js +72 -61
- package/build-module/text-color/index.js.map +7 -1
- package/build-module/text-color/inline.js +107 -106
- package/build-module/text-color/inline.js.map +7 -1
- package/build-module/underline/index.js +43 -34
- package/build-module/underline/index.js.map +7 -1
- package/build-module/unknown/index.js +26 -28
- package/build-module/unknown/index.js.map +7 -1
- package/build-style/style-rtl.css +0 -194
- package/build-style/style.css +0 -194
- package/package.json +21 -15
- package/src/image/style.scss +3 -0
- package/src/link/css-classes-setting.js +89 -0
- package/src/link/index.js +1 -0
- package/src/link/inline.js +19 -0
- package/src/link/style.scss +3 -0
- package/src/link/test/css-classes-setting.js +144 -0
- package/src/link/utils.js +8 -0
- package/src/style.scss +4 -4
- package/src/text-color/style.scss +2 -0
- package/build/default-formats.native.js +0 -16
- package/build/default-formats.native.js.map +0 -1
- package/build/link/index.native.js +0 -174
- package/build/link/index.native.js.map +0 -1
- package/build/link/modal-screens/link-picker-screen.native.js +0 -67
- package/build/link/modal-screens/link-picker-screen.native.js.map +0 -1
- package/build/link/modal-screens/link-settings-screen.native.js +0 -226
- package/build/link/modal-screens/link-settings-screen.native.js.map +0 -1
- package/build/link/modal-screens/screens.native.js +0 -11
- package/build/link/modal-screens/screens.native.js.map +0 -1
- package/build/link/modal.native.js +0 -53
- package/build/link/modal.native.js.map +0 -1
- package/build/text-color/index.native.js +0 -134
- package/build/text-color/index.native.js.map +0 -1
- package/build/text-color/inline.native.js +0 -150
- package/build/text-color/inline.native.js.map +0 -1
- package/build-module/default-formats.native.js +0 -10
- package/build-module/default-formats.native.js.map +0 -1
- package/build-module/link/index.native.js +0 -166
- package/build-module/link/index.native.js.map +0 -1
- package/build-module/link/modal-screens/link-picker-screen.native.js +0 -59
- package/build-module/link/modal-screens/link-picker-screen.native.js.map +0 -1
- package/build-module/link/modal-screens/link-settings-screen.native.js +0 -218
- package/build-module/link/modal-screens/link-settings-screen.native.js.map +0 -1
- package/build-module/link/modal-screens/screens.native.js +0 -5
- package/build-module/link/modal-screens/screens.native.js.map +0 -1
- package/build-module/link/modal.native.js +0 -45
- package/build-module/link/modal.native.js.map +0 -1
- package/build-module/text-color/index.native.js +0 -126
- package/build-module/text-color/index.native.js.map +0 -1
- package/build-module/text-color/inline.native.js +0 -142
- package/build-module/text-color/inline.native.js.map +0 -1
|
@@ -1,25 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, createInterpolateElement } from "@wordpress/element";
|
|
3
|
+
import { __, sprintf } from "@wordpress/i18n";
|
|
4
|
+
import { speak } from "@wordpress/a11y";
|
|
5
|
+
import { Popover } from "@wordpress/components";
|
|
6
|
+
import { prependHTTP } from "@wordpress/url";
|
|
7
|
+
import {
|
|
8
|
+
create,
|
|
9
|
+
insert,
|
|
10
|
+
isCollapsed,
|
|
11
|
+
applyFormat,
|
|
12
|
+
removeFormat,
|
|
13
|
+
slice,
|
|
14
|
+
replace,
|
|
15
|
+
split,
|
|
16
|
+
concat,
|
|
17
|
+
useAnchor
|
|
18
|
+
} from "@wordpress/rich-text";
|
|
19
|
+
import {
|
|
20
|
+
LinkControl,
|
|
21
|
+
store as blockEditorStore
|
|
22
|
+
} from "@wordpress/block-editor";
|
|
23
|
+
import { useDispatch, useSelect } from "@wordpress/data";
|
|
24
|
+
import { createLinkFormat, isValidHref, getFormatBoundary } from "./utils";
|
|
25
|
+
import { link as settings } from "./index";
|
|
26
|
+
import CSSClassesSettingComponent from "./css-classes-setting";
|
|
27
|
+
const LINK_SETTINGS = [
|
|
28
|
+
...LinkControl.DEFAULT_LINK_SETTINGS,
|
|
29
|
+
{
|
|
30
|
+
id: "nofollow",
|
|
31
|
+
title: __("Mark as nofollow")
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: "cssClasses",
|
|
35
|
+
title: __("Additional CSS class(es)"),
|
|
36
|
+
render: (setting, value, onChange) => {
|
|
37
|
+
return /* @__PURE__ */ jsx(
|
|
38
|
+
CSSClassesSettingComponent,
|
|
39
|
+
{
|
|
40
|
+
setting,
|
|
41
|
+
value,
|
|
42
|
+
onChange
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
];
|
|
23
48
|
function InlineLinkUI({
|
|
24
49
|
isActive,
|
|
25
50
|
activeAttributes,
|
|
@@ -31,47 +56,49 @@ function InlineLinkUI({
|
|
|
31
56
|
focusOnMount
|
|
32
57
|
}) {
|
|
33
58
|
const richLinkTextValue = getRichTextValueFromSelection(value, isActive);
|
|
34
|
-
|
|
35
|
-
// Get the text content minus any HTML tags.
|
|
36
59
|
const richTextText = richLinkTextValue.text;
|
|
37
|
-
const {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
const { selectionChange } = useDispatch(blockEditorStore);
|
|
61
|
+
const { createPageEntity, userCanCreatePages, selectionStart } = useSelect(
|
|
62
|
+
(select) => {
|
|
63
|
+
const { getSettings, getSelectionStart } = select(blockEditorStore);
|
|
64
|
+
const _settings = getSettings();
|
|
65
|
+
return {
|
|
66
|
+
createPageEntity: _settings.__experimentalCreatePageEntity,
|
|
67
|
+
userCanCreatePages: _settings.__experimentalUserCanCreatePages,
|
|
68
|
+
selectionStart: getSelectionStart()
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
[]
|
|
72
|
+
);
|
|
73
|
+
const linkValue = useMemo(
|
|
74
|
+
() => ({
|
|
75
|
+
url: activeAttributes.url,
|
|
76
|
+
type: activeAttributes.type,
|
|
77
|
+
id: activeAttributes.id,
|
|
78
|
+
opensInNewTab: activeAttributes.target === "_blank",
|
|
79
|
+
nofollow: activeAttributes.rel?.includes("nofollow"),
|
|
80
|
+
title: richTextText,
|
|
81
|
+
cssClasses: activeAttributes.class
|
|
82
|
+
}),
|
|
83
|
+
[
|
|
84
|
+
activeAttributes.class,
|
|
85
|
+
activeAttributes.id,
|
|
86
|
+
activeAttributes.rel,
|
|
87
|
+
activeAttributes.target,
|
|
88
|
+
activeAttributes.type,
|
|
89
|
+
activeAttributes.url,
|
|
90
|
+
richTextText
|
|
91
|
+
]
|
|
92
|
+
);
|
|
64
93
|
function removeLink() {
|
|
65
|
-
const newValue = removeFormat(value,
|
|
94
|
+
const newValue = removeFormat(value, "core/link");
|
|
66
95
|
onChange(newValue);
|
|
67
96
|
stopAddingLink();
|
|
68
|
-
speak(__(
|
|
97
|
+
speak(__("Link removed."), "assertive");
|
|
69
98
|
}
|
|
70
99
|
function onChangeLink(nextValue) {
|
|
71
100
|
const hasLink = linkValue?.url;
|
|
72
101
|
const isNewLink = !hasLink;
|
|
73
|
-
|
|
74
|
-
// Merge the next value with the current link value.
|
|
75
102
|
nextValue = {
|
|
76
103
|
...linkValue,
|
|
77
104
|
...nextValue
|
|
@@ -80,25 +107,23 @@ function InlineLinkUI({
|
|
|
80
107
|
const linkFormat = createLinkFormat({
|
|
81
108
|
url: newUrl,
|
|
82
109
|
type: nextValue.type,
|
|
83
|
-
id: nextValue.id !==
|
|
110
|
+
id: nextValue.id !== void 0 && nextValue.id !== null ? String(nextValue.id) : void 0,
|
|
84
111
|
opensInNewWindow: nextValue.opensInNewTab,
|
|
85
|
-
nofollow: nextValue.nofollow
|
|
112
|
+
nofollow: nextValue.nofollow,
|
|
113
|
+
cssClasses: nextValue.cssClasses
|
|
86
114
|
});
|
|
87
115
|
const newText = nextValue.title || newUrl;
|
|
88
|
-
|
|
89
|
-
// Scenario: we have any active text selection or an active format.
|
|
90
116
|
let newValue;
|
|
91
117
|
if (isCollapsed(value) && !isActive) {
|
|
92
|
-
// Scenario: we don't have any actively selected text or formats.
|
|
93
118
|
const inserted = insert(value, newText);
|
|
94
|
-
newValue = applyFormat(
|
|
119
|
+
newValue = applyFormat(
|
|
120
|
+
inserted,
|
|
121
|
+
linkFormat,
|
|
122
|
+
value.start,
|
|
123
|
+
value.start + newText.length
|
|
124
|
+
);
|
|
95
125
|
onChange(newValue);
|
|
96
|
-
|
|
97
|
-
// Close the Link UI.
|
|
98
126
|
stopAddingLink();
|
|
99
|
-
|
|
100
|
-
// Move the selection to the end of the inserted link outside of the format boundary
|
|
101
|
-
// so the user can continue typing after the link.
|
|
102
127
|
selectionChange({
|
|
103
128
|
clientId: selectionStart.clientId,
|
|
104
129
|
identifier: selectionStart.attributeKey,
|
|
@@ -108,58 +133,34 @@ function InlineLinkUI({
|
|
|
108
133
|
} else if (newText === richTextText) {
|
|
109
134
|
newValue = applyFormat(value, linkFormat);
|
|
110
135
|
} else {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
// Create new RichText value for the new text in order that we
|
|
114
|
-
// can apply formats to it.
|
|
115
|
-
newValue = create({
|
|
116
|
-
text: newText
|
|
117
|
-
});
|
|
118
|
-
// Apply the new Link format to this new text value.
|
|
136
|
+
newValue = create({ text: newText });
|
|
119
137
|
newValue = applyFormat(newValue, linkFormat, 0, newText.length);
|
|
120
|
-
|
|
121
|
-
// Get the boundaries of the active link format.
|
|
122
138
|
const boundary = getFormatBoundary(value, {
|
|
123
|
-
type:
|
|
139
|
+
type: "core/link"
|
|
124
140
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// which may not correspond correctly.
|
|
131
|
-
const [valBefore, valAfter] = split(value, boundary.start, boundary.start);
|
|
132
|
-
|
|
133
|
-
// Update the original (full) RichTextValue replacing the
|
|
134
|
-
// target text with the *new* RichTextValue containing:
|
|
135
|
-
// 1. The new text content.
|
|
136
|
-
// 2. The new link format.
|
|
137
|
-
// As "replace" will operate on the first match only, it is
|
|
138
|
-
// run only against the second half of the value which was
|
|
139
|
-
// split at the active format's boundary. This avoids a bug
|
|
140
|
-
// with incorrectly targeted replacements.
|
|
141
|
-
// See: https://github.com/WordPress/gutenberg/issues/41771.
|
|
142
|
-
// Note original formats will be lost when applying this change.
|
|
143
|
-
// That is expected behaviour.
|
|
144
|
-
// See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.
|
|
141
|
+
const [valBefore, valAfter] = split(
|
|
142
|
+
value,
|
|
143
|
+
boundary.start,
|
|
144
|
+
boundary.start
|
|
145
|
+
);
|
|
145
146
|
const newValAfter = replace(valAfter, richTextText, newValue);
|
|
146
147
|
newValue = concat(valBefore, newValAfter);
|
|
147
148
|
}
|
|
148
149
|
onChange(newValue);
|
|
149
|
-
|
|
150
|
-
// Focus should only be returned to the rich text on submit if this link is not
|
|
151
|
-
// being created for the first time. If it is then focus should remain within the
|
|
152
|
-
// Link UI because it should remain open for the user to modify the link they have
|
|
153
|
-
// just created.
|
|
154
150
|
if (!isNewLink) {
|
|
155
151
|
stopAddingLink();
|
|
156
152
|
}
|
|
157
153
|
if (!isValidHref(newUrl)) {
|
|
158
|
-
speak(
|
|
154
|
+
speak(
|
|
155
|
+
__(
|
|
156
|
+
"Warning: the link has been inserted but may have errors. Please test it."
|
|
157
|
+
),
|
|
158
|
+
"assertive"
|
|
159
|
+
);
|
|
159
160
|
} else if (isActive) {
|
|
160
|
-
speak(__(
|
|
161
|
+
speak(__("Link edited."), "assertive");
|
|
161
162
|
} else {
|
|
162
|
-
speak(__(
|
|
163
|
+
speak(__("Link inserted."), "assertive");
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
166
|
const popoverAnchor = useAnchor({
|
|
@@ -172,75 +173,78 @@ function InlineLinkUI({
|
|
|
172
173
|
async function handleCreate(pageTitle) {
|
|
173
174
|
const page = await createPageEntity({
|
|
174
175
|
title: pageTitle,
|
|
175
|
-
status:
|
|
176
|
+
status: "draft"
|
|
176
177
|
});
|
|
177
178
|
return {
|
|
178
179
|
id: page.id,
|
|
179
180
|
type: page.type,
|
|
180
181
|
title: page.title.rendered,
|
|
181
182
|
url: page.link,
|
|
182
|
-
kind:
|
|
183
|
+
kind: "post-type"
|
|
183
184
|
};
|
|
184
185
|
}
|
|
185
186
|
function createButtonText(searchTerm) {
|
|
186
|
-
return createInterpolateElement(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
return createInterpolateElement(
|
|
188
|
+
sprintf(
|
|
189
|
+
/* translators: %s: search term. */
|
|
190
|
+
__("Create page: <mark>%s</mark>"),
|
|
191
|
+
searchTerm
|
|
192
|
+
),
|
|
193
|
+
{ mark: /* @__PURE__ */ jsx("mark", {}) }
|
|
194
|
+
);
|
|
190
195
|
}
|
|
191
|
-
return
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
196
|
+
return /* @__PURE__ */ jsx(
|
|
197
|
+
Popover,
|
|
198
|
+
{
|
|
199
|
+
anchor: popoverAnchor,
|
|
200
|
+
animate: false,
|
|
201
|
+
onClose: stopAddingLink,
|
|
202
|
+
onFocusOutside,
|
|
203
|
+
placement: "bottom",
|
|
204
|
+
offset: 8,
|
|
205
|
+
shift: true,
|
|
206
|
+
focusOnMount,
|
|
207
|
+
constrainTabbing: true,
|
|
208
|
+
children: /* @__PURE__ */ jsx(
|
|
209
|
+
LinkControl,
|
|
210
|
+
{
|
|
211
|
+
value: linkValue,
|
|
212
|
+
onChange: onChangeLink,
|
|
213
|
+
onRemove: removeLink,
|
|
214
|
+
hasRichPreviews: true,
|
|
215
|
+
createSuggestion: createPageEntity && handleCreate,
|
|
216
|
+
withCreateSuggestion: userCanCreatePages,
|
|
217
|
+
createSuggestionButtonText: createButtonText,
|
|
218
|
+
hasTextControl: true,
|
|
219
|
+
settings: LINK_SETTINGS,
|
|
220
|
+
showInitialSuggestions: true,
|
|
221
|
+
suggestionsQuery: {
|
|
222
|
+
// always show Pages as initial suggestions
|
|
223
|
+
initialSuggestionsSearchOptions: {
|
|
224
|
+
type: "post",
|
|
225
|
+
subtype: "page",
|
|
226
|
+
perPage: 20
|
|
227
|
+
}
|
|
228
|
+
}
|
|
218
229
|
}
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
);
|
|
222
233
|
}
|
|
223
234
|
function getRichTextValueFromSelection(value, isActive) {
|
|
224
|
-
// Default to the selection ranges on the RichTextValue object.
|
|
225
235
|
let textStart = value.start;
|
|
226
236
|
let textEnd = value.end;
|
|
227
|
-
|
|
228
|
-
// If the format is currently active then the rich text value
|
|
229
|
-
// should always be taken from the bounds of the active format
|
|
230
|
-
// and not the selected text.
|
|
231
237
|
if (isActive) {
|
|
232
238
|
const boundary = getFormatBoundary(value, {
|
|
233
|
-
type:
|
|
239
|
+
type: "core/link"
|
|
234
240
|
});
|
|
235
241
|
textStart = boundary.start;
|
|
236
|
-
|
|
237
|
-
// Text *selection* always extends +1 beyond the edge of the format.
|
|
238
|
-
// We account for that here.
|
|
239
242
|
textEnd = boundary.end + 1;
|
|
240
243
|
}
|
|
241
|
-
|
|
242
|
-
// Get a RichTextValue containing the selected text content.
|
|
243
244
|
return slice(value, textStart, textEnd);
|
|
244
245
|
}
|
|
245
|
-
|
|
246
|
-
|
|
246
|
+
var inline_default = InlineLinkUI;
|
|
247
|
+
export {
|
|
248
|
+
inline_default as default
|
|
249
|
+
};
|
|
250
|
+
//# sourceMappingURL=inline.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","createInterpolateElement","__","sprintf","speak","Popover","prependHTTP","create","insert","isCollapsed","applyFormat","removeFormat","slice","replace","split","concat","useAnchor","LinkControl","store","blockEditorStore","useDispatch","useSelect","createLinkFormat","isValidHref","getFormatBoundary","link","settings","jsx","_jsx","LINK_SETTINGS","DEFAULT_LINK_SETTINGS","id","title","InlineLinkUI","isActive","activeAttributes","value","onChange","onFocusOutside","stopAddingLink","contentRef","focusOnMount","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","selectionChange","createPageEntity","userCanCreatePages","selectionStart","select","getSettings","getSelectionStart","_settings","__experimentalCreatePageEntity","__experimentalUserCanCreatePages","linkValue","url","type","opensInNewTab","target","nofollow","rel","includes","removeLink","newValue","onChangeLink","nextValue","hasLink","isNewLink","newUrl","linkFormat","undefined","String","opensInNewWindow","newText","inserted","start","length","clientId","identifier","attributeKey","boundary","valBefore","valAfter","newValAfter","popoverAnchor","editableContentElement","current","handleCreate","pageTitle","page","status","rendered","kind","createButtonText","searchTerm","mark","anchor","animate","onClose","placement","offset","shift","constrainTabbing","children","onRemove","hasRichPreviews","createSuggestion","withCreateSuggestion","createSuggestionButtonText","hasTextControl","showInitialSuggestions","suggestionsQuery","initialSuggestionsSearchOptions","subtype","perPage","textStart","textEnd","end"],"sources":["@wordpress/format-library/src/link/inline.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, createInterpolateElement } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { speak } from '@wordpress/a11y';\nimport { Popover } from '@wordpress/components';\nimport { prependHTTP } from '@wordpress/url';\nimport {\n\tcreate,\n\tinsert,\n\tisCollapsed,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\treplace,\n\tsplit,\n\tconcat,\n\tuseAnchor,\n} from '@wordpress/rich-text';\nimport {\n\tLinkControl,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { createLinkFormat, isValidHref, getFormatBoundary } from './utils';\nimport { link as settings } from './index';\n\nconst LINK_SETTINGS = [\n\t...LinkControl.DEFAULT_LINK_SETTINGS,\n\t{\n\t\tid: 'nofollow',\n\t\ttitle: __( 'Mark as nofollow' ),\n\t},\n];\n\nfunction InlineLinkUI( {\n\tisActive,\n\tactiveAttributes,\n\tvalue,\n\tonChange,\n\tonFocusOutside,\n\tstopAddingLink,\n\tcontentRef,\n\tfocusOnMount,\n} ) {\n\tconst richLinkTextValue = getRichTextValueFromSelection( value, isActive );\n\n\t// Get the text content minus any HTML tags.\n\tconst richTextText = richLinkTextValue.text;\n\n\tconst { selectionChange } = useDispatch( blockEditorStore );\n\n\tconst { createPageEntity, userCanCreatePages, selectionStart } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSettings, getSelectionStart } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst _settings = getSettings();\n\n\t\t\treturn {\n\t\t\t\tcreatePageEntity: _settings.__experimentalCreatePageEntity,\n\t\t\t\tuserCanCreatePages: _settings.__experimentalUserCanCreatePages,\n\t\t\t\tselectionStart: getSelectionStart(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst linkValue = useMemo(\n\t\t() => ( {\n\t\t\turl: activeAttributes.url,\n\t\t\ttype: activeAttributes.type,\n\t\t\tid: activeAttributes.id,\n\t\t\topensInNewTab: activeAttributes.target === '_blank',\n\t\t\tnofollow: activeAttributes.rel?.includes( 'nofollow' ),\n\t\t\ttitle: richTextText,\n\t\t} ),\n\t\t[\n\t\t\tactiveAttributes.id,\n\t\t\tactiveAttributes.rel,\n\t\t\tactiveAttributes.target,\n\t\t\tactiveAttributes.type,\n\t\t\tactiveAttributes.url,\n\t\t\trichTextText,\n\t\t]\n\t);\n\n\tfunction removeLink() {\n\t\tconst newValue = removeFormat( value, 'core/link' );\n\t\tonChange( newValue );\n\t\tstopAddingLink();\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\tfunction onChangeLink( nextValue ) {\n\t\tconst hasLink = linkValue?.url;\n\t\tconst isNewLink = ! hasLink;\n\n\t\t// Merge the next value with the current link value.\n\t\tnextValue = {\n\t\t\t...linkValue,\n\t\t\t...nextValue,\n\t\t};\n\n\t\tconst newUrl = prependHTTP( nextValue.url );\n\t\tconst linkFormat = createLinkFormat( {\n\t\t\turl: newUrl,\n\t\t\ttype: nextValue.type,\n\t\t\tid:\n\t\t\t\tnextValue.id !== undefined && nextValue.id !== null\n\t\t\t\t\t? String( nextValue.id )\n\t\t\t\t\t: undefined,\n\t\t\topensInNewWindow: nextValue.opensInNewTab,\n\t\t\tnofollow: nextValue.nofollow,\n\t\t} );\n\n\t\tconst newText = nextValue.title || newUrl;\n\n\t\t// Scenario: we have any active text selection or an active format.\n\t\tlet newValue;\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 inserted = insert( value, newText );\n\n\t\t\tnewValue = applyFormat(\n\t\t\t\tinserted,\n\t\t\t\tlinkFormat,\n\t\t\t\tvalue.start,\n\t\t\t\tvalue.start + newText.length\n\t\t\t);\n\n\t\t\tonChange( newValue );\n\n\t\t\t// Close the Link UI.\n\t\t\tstopAddingLink();\n\n\t\t\t// Move the selection to the end of the inserted link outside of the format boundary\n\t\t\t// so the user can continue typing after the link.\n\t\t\tselectionChange( {\n\t\t\t\tclientId: selectionStart.clientId,\n\t\t\t\tidentifier: selectionStart.attributeKey,\n\t\t\t\tstart: value.start + newText.length + 1,\n\t\t\t} );\n\n\t\t\treturn;\n\t\t} else if ( newText === richTextText ) {\n\t\t\tnewValue = applyFormat( value, linkFormat );\n\t\t} else {\n\t\t\t// Scenario: Editing an existing link.\n\n\t\t\t// Create new RichText value for the new text in order that we\n\t\t\t// can apply formats to it.\n\t\t\tnewValue = create( { text: newText } );\n\t\t\t// Apply the new Link format to this new text value.\n\t\t\tnewValue = applyFormat( newValue, linkFormat, 0, newText.length );\n\n\t\t\t// Get the boundaries of the active link format.\n\t\t\tconst boundary = getFormatBoundary( value, {\n\t\t\t\ttype: 'core/link',\n\t\t\t} );\n\n\t\t\t// Split the value at the start of the active link format.\n\t\t\t// Passing \"start\" as the 3rd parameter is required to ensure\n\t\t\t// the second half of the split value is split at the format's\n\t\t\t// start boundary and avoids relying on the value's \"end\" property\n\t\t\t// which may not correspond correctly.\n\t\t\tconst [ valBefore, valAfter ] = split(\n\t\t\t\tvalue,\n\t\t\t\tboundary.start,\n\t\t\t\tboundary.start\n\t\t\t);\n\n\t\t\t// Update the original (full) RichTextValue replacing the\n\t\t\t// target text with the *new* RichTextValue containing:\n\t\t\t// 1. The new text content.\n\t\t\t// 2. The new link format.\n\t\t\t// As \"replace\" will operate on the first match only, it is\n\t\t\t// run only against the second half of the value which was\n\t\t\t// split at the active format's boundary. This avoids a bug\n\t\t\t// with incorrectly targeted replacements.\n\t\t\t// See: https://github.com/WordPress/gutenberg/issues/41771.\n\t\t\t// Note original formats will be lost when applying this change.\n\t\t\t// That is expected behaviour.\n\t\t\t// See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.\n\t\t\tconst newValAfter = replace( valAfter, richTextText, newValue );\n\n\t\t\tnewValue = concat( valBefore, newValAfter );\n\t\t}\n\n\t\tonChange( newValue );\n\n\t\t// Focus should only be returned to the rich text on submit if this link is not\n\t\t// being created for the first time. If it is then focus should remain within the\n\t\t// Link UI because it should remain open for the user to modify the link they have\n\t\t// just created.\n\t\tif ( ! isNewLink ) {\n\t\t\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\t\t...settings,\n\t\t\tisActive,\n\t\t},\n\t} );\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\tanimate={ false }\n\t\t\tonClose={ stopAddingLink }\n\t\t\tonFocusOutside={ onFocusOutside }\n\t\t\tplacement=\"bottom\"\n\t\t\toffset={ 8 }\n\t\t\tshift\n\t\t\tfocusOnMount={ focusOnMount }\n\t\t\tconstrainTabbing\n\t\t>\n\t\t\t<LinkControl\n\t\t\t\tvalue={ linkValue }\n\t\t\t\tonChange={ onChangeLink }\n\t\t\t\tonRemove={ removeLink }\n\t\t\t\thasRichPreviews\n\t\t\t\tcreateSuggestion={ createPageEntity && handleCreate }\n\t\t\t\twithCreateSuggestion={ userCanCreatePages }\n\t\t\t\tcreateSuggestionButtonText={ createButtonText }\n\t\t\t\thasTextControl\n\t\t\t\tsettings={ LINK_SETTINGS }\n\t\t\t\tshowInitialSuggestions\n\t\t\t\tsuggestionsQuery={ {\n\t\t\t\t\t// always show Pages as initial suggestions\n\t\t\t\t\tinitialSuggestionsSearchOptions: {\n\t\t\t\t\t\ttype: 'post',\n\t\t\t\t\t\tsubtype: 'page',\n\t\t\t\t\t\tperPage: 20,\n\t\t\t\t\t},\n\t\t\t\t} }\n\t\t\t/>\n\t\t</Popover>\n\t);\n}\n\nfunction getRichTextValueFromSelection( value, isActive ) {\n\t// Default to the selection ranges on the RichTextValue object.\n\tlet textStart = value.start;\n\tlet textEnd = value.end;\n\n\t// If the format is currently active then the rich text value\n\t// should always be taken from the bounds of the active format\n\t// and not the selected text.\n\tif ( isActive ) {\n\t\tconst boundary = getFormatBoundary( value, {\n\t\t\ttype: 'core/link',\n\t\t} );\n\n\t\ttextStart = boundary.start;\n\n\t\t// Text *selection* always extends +1 beyond the edge of the format.\n\t\t// We account for that here.\n\t\ttextEnd = boundary.end + 1;\n\t}\n\n\t// Get a RichTextValue containing the selected text content.\n\treturn slice( value, textStart, textEnd );\n}\n\nexport default InlineLinkUI;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,wBAAwB,QAAQ,oBAAoB;AACtE,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,QAAQ,iBAAiB;AACvC,SAASC,OAAO,QAAQ,uBAAuB;AAC/C,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SACCC,MAAM,EACNC,MAAM,EACNC,WAAW,EACXC,WAAW,EACXC,YAAY,EACZC,KAAK,EACLC,OAAO,EACPC,KAAK,EACLC,MAAM,EACNC,SAAS,QACH,sBAAsB;AAC7B,SACCC,WAAW,EACXC,KAAK,IAAIC,gBAAgB,QACnB,yBAAyB;AAChC,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;;AAExD;AACA;AACA;AACA,SAASC,gBAAgB,EAAEC,WAAW,EAAEC,iBAAiB,QAAQ,SAAS;AAC1E,SAASC,IAAI,IAAIC,QAAQ,QAAQ,SAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE3C,MAAMC,aAAa,GAAG,CACrB,GAAGZ,WAAW,CAACa,qBAAqB,EACpC;EACCC,EAAE,EAAE,UAAU;EACdC,KAAK,EAAE9B,EAAE,CAAE,kBAAmB;AAC/B,CAAC,CACD;AAED,SAAS+B,YAAYA,CAAE;EACtBC,QAAQ;EACRC,gBAAgB;EAChBC,KAAK;EACLC,QAAQ;EACRC,cAAc;EACdC,cAAc;EACdC,UAAU;EACVC;AACD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,SAAW;MACnBnB,QAAQ,EAAG6B,YAAc;MACzBwC,QAAQ,EAAG1C,UAAY;MACvB2C,eAAe;MACfC,gBAAgB,EAAG7D,gBAAgB,IAAI0C,YAAc;MACrDoB,oBAAoB,EAAG7D,kBAAoB;MAC3C8D,0BAA0B,EAAGf,gBAAkB;MAC/CgB,cAAc;MACdrF,QAAQ,EAAGG,aAAe;MAC1BmF,sBAAsB;MACtBC,gBAAgB,EAAG;QAClB;QACAC,+BAA+B,EAAE;UAChCxD,IAAI,EAAE,MAAM;UACZyD,OAAO,EAAE,MAAM;UACfC,OAAO,EAAE;QACV;MACD;IAAG,CACH;EAAC,CACM,CAAC;AAEZ;AAEA,SAASzE,6BAA6BA,CAAEP,KAAK,EAAEF,QAAQ,EAAG;EACzD;EACA,IAAImF,SAAS,GAAGjF,KAAK,CAACyC,KAAK;EAC3B,IAAIyC,OAAO,GAAGlF,KAAK,CAACmF,GAAG;;EAEvB;EACA;EACA;EACA,IAAKrF,QAAQ,EAAG;IACf,MAAMgD,QAAQ,GAAG1D,iBAAiB,CAAEY,KAAK,EAAE;MAC1CsB,IAAI,EAAE;IACP,CAAE,CAAC;IAEH2D,SAAS,GAAGnC,QAAQ,CAACL,KAAK;;IAE1B;IACA;IACAyC,OAAO,GAAGpC,QAAQ,CAACqC,GAAG,GAAG,CAAC;EAC3B;;EAEA;EACA,OAAO3G,KAAK,CAAEwB,KAAK,EAAEiF,SAAS,EAAEC,OAAQ,CAAC;AAC1C;AAEA,eAAerF,YAAY","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/link/inline.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo, createInterpolateElement } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { speak } from '@wordpress/a11y';\nimport { Popover } from '@wordpress/components';\nimport { prependHTTP } from '@wordpress/url';\nimport {\n\tcreate,\n\tinsert,\n\tisCollapsed,\n\tapplyFormat,\n\tremoveFormat,\n\tslice,\n\treplace,\n\tsplit,\n\tconcat,\n\tuseAnchor,\n} from '@wordpress/rich-text';\nimport {\n\tLinkControl,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { createLinkFormat, isValidHref, getFormatBoundary } from './utils';\nimport { link as settings } from './index';\nimport CSSClassesSettingComponent from './css-classes-setting';\n\n// CSSClassesSettingComponent moved to its own file and imported above.\n\nconst LINK_SETTINGS = [\n\t...LinkControl.DEFAULT_LINK_SETTINGS,\n\t{\n\t\tid: 'nofollow',\n\t\ttitle: __( 'Mark as nofollow' ),\n\t},\n\t{\n\t\tid: 'cssClasses',\n\t\ttitle: __( 'Additional CSS class(es)' ),\n\t\trender: ( setting, value, onChange ) => {\n\t\t\treturn (\n\t\t\t\t<CSSClassesSettingComponent\n\t\t\t\t\tsetting={ setting }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t);\n\t\t},\n\t},\n];\n\nfunction InlineLinkUI( {\n\tisActive,\n\tactiveAttributes,\n\tvalue,\n\tonChange,\n\tonFocusOutside,\n\tstopAddingLink,\n\tcontentRef,\n\tfocusOnMount,\n} ) {\n\tconst richLinkTextValue = getRichTextValueFromSelection( value, isActive );\n\n\t// Get the text content minus any HTML tags.\n\tconst richTextText = richLinkTextValue.text;\n\n\tconst { selectionChange } = useDispatch( blockEditorStore );\n\n\tconst { createPageEntity, userCanCreatePages, selectionStart } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSettings, getSelectionStart } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\tconst _settings = getSettings();\n\n\t\t\treturn {\n\t\t\t\tcreatePageEntity: _settings.__experimentalCreatePageEntity,\n\t\t\t\tuserCanCreatePages: _settings.__experimentalUserCanCreatePages,\n\t\t\t\tselectionStart: getSelectionStart(),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst linkValue = useMemo(\n\t\t() => ( {\n\t\t\turl: activeAttributes.url,\n\t\t\ttype: activeAttributes.type,\n\t\t\tid: activeAttributes.id,\n\t\t\topensInNewTab: activeAttributes.target === '_blank',\n\t\t\tnofollow: activeAttributes.rel?.includes( 'nofollow' ),\n\t\t\ttitle: richTextText,\n\t\t\tcssClasses: activeAttributes.class,\n\t\t} ),\n\t\t[\n\t\t\tactiveAttributes.class,\n\t\t\tactiveAttributes.id,\n\t\t\tactiveAttributes.rel,\n\t\t\tactiveAttributes.target,\n\t\t\tactiveAttributes.type,\n\t\t\tactiveAttributes.url,\n\t\t\trichTextText,\n\t\t]\n\t);\n\n\tfunction removeLink() {\n\t\tconst newValue = removeFormat( value, 'core/link' );\n\t\tonChange( newValue );\n\t\tstopAddingLink();\n\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t}\n\n\tfunction onChangeLink( nextValue ) {\n\t\tconst hasLink = linkValue?.url;\n\t\tconst isNewLink = ! hasLink;\n\n\t\t// Merge the next value with the current link value.\n\t\tnextValue = {\n\t\t\t...linkValue,\n\t\t\t...nextValue,\n\t\t};\n\n\t\tconst newUrl = prependHTTP( nextValue.url );\n\t\tconst linkFormat = createLinkFormat( {\n\t\t\turl: newUrl,\n\t\t\ttype: nextValue.type,\n\t\t\tid:\n\t\t\t\tnextValue.id !== undefined && nextValue.id !== null\n\t\t\t\t\t? String( nextValue.id )\n\t\t\t\t\t: undefined,\n\t\t\topensInNewWindow: nextValue.opensInNewTab,\n\t\t\tnofollow: nextValue.nofollow,\n\t\t\tcssClasses: nextValue.cssClasses,\n\t\t} );\n\n\t\tconst newText = nextValue.title || newUrl;\n\n\t\t// Scenario: we have any active text selection or an active format.\n\t\tlet newValue;\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 inserted = insert( value, newText );\n\n\t\t\tnewValue = applyFormat(\n\t\t\t\tinserted,\n\t\t\t\tlinkFormat,\n\t\t\t\tvalue.start,\n\t\t\t\tvalue.start + newText.length\n\t\t\t);\n\n\t\t\tonChange( newValue );\n\n\t\t\t// Close the Link UI.\n\t\t\tstopAddingLink();\n\n\t\t\t// Move the selection to the end of the inserted link outside of the format boundary\n\t\t\t// so the user can continue typing after the link.\n\t\t\tselectionChange( {\n\t\t\t\tclientId: selectionStart.clientId,\n\t\t\t\tidentifier: selectionStart.attributeKey,\n\t\t\t\tstart: value.start + newText.length + 1,\n\t\t\t} );\n\n\t\t\treturn;\n\t\t} else if ( newText === richTextText ) {\n\t\t\tnewValue = applyFormat( value, linkFormat );\n\t\t} else {\n\t\t\t// Scenario: Editing an existing link.\n\n\t\t\t// Create new RichText value for the new text in order that we\n\t\t\t// can apply formats to it.\n\t\t\tnewValue = create( { text: newText } );\n\t\t\t// Apply the new Link format to this new text value.\n\t\t\tnewValue = applyFormat( newValue, linkFormat, 0, newText.length );\n\n\t\t\t// Get the boundaries of the active link format.\n\t\t\tconst boundary = getFormatBoundary( value, {\n\t\t\t\ttype: 'core/link',\n\t\t\t} );\n\n\t\t\t// Split the value at the start of the active link format.\n\t\t\t// Passing \"start\" as the 3rd parameter is required to ensure\n\t\t\t// the second half of the split value is split at the format's\n\t\t\t// start boundary and avoids relying on the value's \"end\" property\n\t\t\t// which may not correspond correctly.\n\t\t\tconst [ valBefore, valAfter ] = split(\n\t\t\t\tvalue,\n\t\t\t\tboundary.start,\n\t\t\t\tboundary.start\n\t\t\t);\n\n\t\t\t// Update the original (full) RichTextValue replacing the\n\t\t\t// target text with the *new* RichTextValue containing:\n\t\t\t// 1. The new text content.\n\t\t\t// 2. The new link format.\n\t\t\t// As \"replace\" will operate on the first match only, it is\n\t\t\t// run only against the second half of the value which was\n\t\t\t// split at the active format's boundary. This avoids a bug\n\t\t\t// with incorrectly targeted replacements.\n\t\t\t// See: https://github.com/WordPress/gutenberg/issues/41771.\n\t\t\t// Note original formats will be lost when applying this change.\n\t\t\t// That is expected behaviour.\n\t\t\t// See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.\n\t\t\tconst newValAfter = replace( valAfter, richTextText, newValue );\n\n\t\t\tnewValue = concat( valBefore, newValAfter );\n\t\t}\n\n\t\tonChange( newValue );\n\n\t\t// Focus should only be returned to the rich text on submit if this link is not\n\t\t// being created for the first time. If it is then focus should remain within the\n\t\t// Link UI because it should remain open for the user to modify the link they have\n\t\t// just created.\n\t\tif ( ! isNewLink ) {\n\t\t\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\t\t...settings,\n\t\t\tisActive,\n\t\t},\n\t} );\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\tanimate={ false }\n\t\t\tonClose={ stopAddingLink }\n\t\t\tonFocusOutside={ onFocusOutside }\n\t\t\tplacement=\"bottom\"\n\t\t\toffset={ 8 }\n\t\t\tshift\n\t\t\tfocusOnMount={ focusOnMount }\n\t\t\tconstrainTabbing\n\t\t>\n\t\t\t<LinkControl\n\t\t\t\tvalue={ linkValue }\n\t\t\t\tonChange={ onChangeLink }\n\t\t\t\tonRemove={ removeLink }\n\t\t\t\thasRichPreviews\n\t\t\t\tcreateSuggestion={ createPageEntity && handleCreate }\n\t\t\t\twithCreateSuggestion={ userCanCreatePages }\n\t\t\t\tcreateSuggestionButtonText={ createButtonText }\n\t\t\t\thasTextControl\n\t\t\t\tsettings={ LINK_SETTINGS }\n\t\t\t\tshowInitialSuggestions\n\t\t\t\tsuggestionsQuery={ {\n\t\t\t\t\t// always show Pages as initial suggestions\n\t\t\t\t\tinitialSuggestionsSearchOptions: {\n\t\t\t\t\t\ttype: 'post',\n\t\t\t\t\t\tsubtype: 'page',\n\t\t\t\t\t\tperPage: 20,\n\t\t\t\t\t},\n\t\t\t\t} }\n\t\t\t/>\n\t\t</Popover>\n\t);\n}\n\nfunction getRichTextValueFromSelection( value, isActive ) {\n\t// Default to the selection ranges on the RichTextValue object.\n\tlet textStart = value.start;\n\tlet textEnd = value.end;\n\n\t// If the format is currently active then the rich text value\n\t// should always be taken from the bounds of the active format\n\t// and not the selected text.\n\tif ( isActive ) {\n\t\tconst boundary = getFormatBoundary( value, {\n\t\t\ttype: 'core/link',\n\t\t} );\n\n\t\ttextStart = boundary.start;\n\n\t\t// Text *selection* always extends +1 beyond the edge of the format.\n\t\t// We account for that here.\n\t\ttextEnd = boundary.end + 1;\n\t}\n\n\t// Get a RichTextValue containing the selected text content.\n\treturn slice( value, textStart, textEnd );\n}\n\nexport default InlineLinkUI;\n"],
|
|
5
|
+
"mappings": "AA8CI;AA3CJ,SAAS,SAAS,gCAAgC;AAClD,SAAS,IAAI,eAAe;AAC5B,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B;AAAA,EACC;A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MACA,EAAE,MAAM,oBAAC,UAAK,EAAG;AAAA,IAClB;AAAA,EACD;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,QAAS;AAAA,MACT,SAAU;AAAA,MACV,SAAU;AAAA,MACV;AAAA,MACA,WAAU;AAAA,MACV,QAAS;AAAA,MACT,OAAK;AAAA,MACL;AAAA,MACA,kBAAgB;AAAA,MAEhB;AAAA,QAAC;AAAA;AAAA,UACA,OAAQ;AAAA,UACR,UAAW;AAAA,UACX,UAAW;AAAA,UACX,iBAAe;AAAA,UACf,kBAAmB,oBAAoB;AAAA,UACvC,sBAAuB;AAAA,UACvB,4BAA6B;AAAA,UAC7B,gBAAc;AAAA,UACd,UAAW;AAAA,UACX,wBAAsB;AAAA,UACtB,kBAAmB;AAAA;AAAA,YAElB,iCAAiC;AAAA,cAChC,MAAM;AAAA,cACN,SAAS;AAAA,cACT,SAAS;AAAA,YACV;AAAA,UACD;AAAA;AAAA,MACD;AAAA;AAAA,EACD;AAEF;AAEA,SAAS,8BAA+B,OAAO,UAAW;AAEzD,MAAI,YAAY,MAAM;AACtB,MAAI,UAAU,MAAM;AAKpB,MAAK,UAAW;AACf,UAAM,WAAW,kBAAmB,OAAO;AAAA,MAC1C,MAAM;AAAA,IACP,CAAE;AAEF,gBAAY,SAAS;AAIrB,cAAU,SAAS,MAAM;AAAA,EAC1B;AAGA,SAAO,MAAO,OAAO,WAAW,OAAQ;AACzC;AAEA,IAAO,iBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
const weakMap = new WeakMap();
|
|
3
|
-
|
|
4
|
-
// Incrementing zero-based ID value.
|
|
1
|
+
const weakMap = /* @__PURE__ */ new WeakMap();
|
|
5
2
|
let id = -1;
|
|
6
|
-
const prefix =
|
|
3
|
+
const prefix = "link-control-instance";
|
|
7
4
|
function getKey(_id) {
|
|
8
5
|
return `${prefix}-${_id}`;
|
|
9
6
|
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Builds a unique link control key for the given object reference.
|
|
13
|
-
*
|
|
14
|
-
* @param {Object} instance an unique object reference specific to this link control instance.
|
|
15
|
-
* @return {string | undefined} the unique key to use for this link control.
|
|
16
|
-
*/
|
|
17
7
|
function useLinkInstanceKey(instance) {
|
|
18
8
|
if (!instance) {
|
|
19
9
|
return;
|
|
@@ -25,5 +15,8 @@ function useLinkInstanceKey(instance) {
|
|
|
25
15
|
weakMap.set(instance, id);
|
|
26
16
|
return getKey(id);
|
|
27
17
|
}
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
var use_link_instance_key_default = useLinkInstanceKey;
|
|
19
|
+
export {
|
|
20
|
+
use_link_instance_key_default as default
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=use-link-instance-key.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/link/use-link-instance-key.js"],
|
|
4
|
+
"sourcesContent": ["// Weakly referenced map allows unused ids to be garbage collected.\nconst weakMap = new WeakMap();\n\n// Incrementing zero-based ID value.\nlet id = -1;\n\nconst prefix = 'link-control-instance';\n\nfunction getKey( _id ) {\n\treturn `${ prefix }-${ _id }`;\n}\n\n/**\n * Builds a unique link control key for the given object reference.\n *\n * @param {Object} instance an unique object reference specific to this link control instance.\n * @return {string | undefined} the unique key to use for this link control.\n */\nfunction useLinkInstanceKey( instance ) {\n\tif ( ! instance ) {\n\t\treturn;\n\t}\n\tif ( weakMap.has( instance ) ) {\n\t\treturn getKey( weakMap.get( instance ) );\n\t}\n\n\tid += 1;\n\n\tweakMap.set( instance, id );\n\n\treturn getKey( id );\n}\n\nexport default useLinkInstanceKey;\n"],
|
|
5
|
+
"mappings": "AACA,MAAM,UAAU,oBAAI,QAAQ;AAG5B,IAAI,KAAK;AAET,MAAM,SAAS;AAEf,SAAS,OAAQ,KAAM;AACtB,SAAO,GAAI,MAAO,IAAK,GAAI;AAC5B;AAQA,SAAS,mBAAoB,UAAW;AACvC,MAAK,CAAE,UAAW;AACjB;AAAA,EACD;AACA,MAAK,QAAQ,IAAK,QAAS,GAAI;AAC9B,WAAO,OAAQ,QAAQ,IAAK,QAAS,CAAE;AAAA,EACxC;AAEA,QAAM;AAEN,UAAQ,IAAK,UAAU,EAAG;AAE1B,SAAO,OAAQ,EAAG;AACnB;AAEA,IAAO,gCAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|